From 9a52204dd8b4dc4a051f468584736d2eff2d002a Mon Sep 17 00:00:00 2001 From: "Dmitriy A. Gerasimov" <dmitriy.gerasimov@demlabs.net> Date: Tue, 29 Oct 2019 17:06:04 +0700 Subject: [PATCH] [-] db common functions --- CMakeLists.txt | 32 +---- auth/CMakeLists.txt | 14 -- dap_server_http_db_auth.c | 162 ----------------------- dap_server_http_db_auth.h | 40 ------ db/CMakeLists.txt | 15 --- db/db_core.c | 82 ------------ db/db_core.h | 17 --- db/db_http.c | 74 ----------- db/db_http.h | 10 -- db/db_http_file.c | 250 ------------------------------------ db/db_http_file.h | 10 -- auth/db_auth.c => db_auth.c | 0 {auth => include}/db_auth.h | 0 13 files changed, 7 insertions(+), 699 deletions(-) delete mode 100755 auth/CMakeLists.txt delete mode 100755 dap_server_http_db_auth.c delete mode 100644 dap_server_http_db_auth.h delete mode 100755 db/CMakeLists.txt delete mode 100755 db/db_core.c delete mode 100755 db/db_core.h delete mode 100755 db/db_http.c delete mode 100755 db/db_http.h delete mode 100755 db/db_http_file.c delete mode 100755 db/db_http_file.h rename auth/db_auth.c => db_auth.c (100%) rename {auth => include}/db_auth.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 199a838..ae3fef2 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,29 +1,11 @@ -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 3.0) project (dap_server_http_db_auth) + +set(AUTH_SRCS db_auth.c) -# fix implicit declaration warnings -add_definitions ("-D_GNU_SOURCE") +add_library(${PROJECT_NAME} STATIC ${AUTH_SRCS}) -set(CMAKE_C_FLAGS "-std=c11 -Wall -Wextra") +target_link_libraries(${PROJECT_NAME} dap_core + dap_crypto dap_http_server dap_enc_server + dap_stream dap_http_server_db ) - -#find_package(PkgConfig) -#pkg_check_modules(MONGO REQUIRED libmongoc-1.0) -#pkg_check_modules(BSON REQUIRED libbson-1.0) -# -#add_subdirectory(db) -#add_subdirectory(auth) - - -file(GLOB FILE_SOURCES *.c) -file(GLOB FILE_HEADERS *.h) - -add_library(${PROJECT_NAME} STATIC ${FILE_SOURCES} ${FILE_HEADERS}) - -#target_link_libraries(${PROJECT_NAME} dap_core dap_crypto dap_auth dap_db) -target_link_libraries(${PROJECT_NAME} dap_core dap_crypto dap_chain dap_chain_wallet) -target_include_directories(${PROJECT_NAME} INTERFACE .) - - -#set(${PROJECT_NAME}_DEFINITIONS CACHE INTERNAL "${PROJECT_NAME}: Definitions" FORCE) -#set(${PROJECT_NAME}_INCLUDE_DIRS ${PROJECT_SOURCE_DIR} CACHE INTERNAL "${PROJECT_NAME}: Include Directories" FORCE) \ No newline at end of file diff --git a/auth/CMakeLists.txt b/auth/CMakeLists.txt deleted file mode 100755 index cf70903..0000000 --- a/auth/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.0) -project (dap_auth) - -set(AUTH_SRCS db_auth.c) - -add_library(${PROJECT_NAME} STATIC ${AUTH_SRCS}) - -target_link_libraries(dap_auth dap_core - dap_crypto dap_http_server dap_enc_server - dap_stream ${MONGO_LIBRARIES}) - -target_include_directories(dap_auth - INTERFACE . - PRIVATE ${MONGO_INCLUDE_DIRS}) diff --git a/dap_server_http_db_auth.c b/dap_server_http_db_auth.c deleted file mode 100755 index f691864..0000000 --- a/dap_server_http_db_auth.c +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Authors: - * Dmitriy A. Gearasimov <gerasimov.dmitriy@demlabs.net> - * Aleksandr Lysikov <alexander.lysikov@demlabs.net> - * DeM Labs Inc. https://demlabs.net - * Kelvin Project https://github.com/kelvinblockchain - * Copyright (c) 2019 - * All rights reserved. - - This file is part of DAP (Deus Applications Prototypes) the open source project - - DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - DAP is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <string.h> -#include <stddef.h> - -#include <dap_common.h> -#include "dap_config.h" -#include "dap_enc_key.h" -#include "dap_strfuncs.h" -#include "dap_hash.h" - -#include "dap_chain_common.h" -#include "dap_chain_sign.h" -#include "dap_chain_wallet.h" - -#include "dap_server_http_db_auth.h" - -/** - * Parse a_service_key from service client - * a_addr_base58[out] - address - * a_sign_hash[out] - hash of sign - */ -bool dap_server_http_db_auth_parse_service_key(const char *a_service_key, char **a_addr_base58, char **a_sign_hash) -{ - bool l_ret = false; - // format a_service_key = "a_addr_base58;a_sign_hash" - if(!a_service_key) - return false; - char **l_str = dap_strsplit(a_service_key, ";", -1); - if(dap_str_countv(l_str) == 2) { - if(a_addr_base58) - *a_addr_base58 = strdup(l_str[0]); - if(a_sign_hash) - *a_sign_hash = strdup(l_str[1]); - l_ret = true; - } - dap_strfreev(l_str); - return l_ret; -} - -/** - * Create new service_key - */ -char* dap_server_http_db_auth_create_service_key(const char *a_wallet_name) -{ - char *l_addr_base58 = NULL; - char *l_sign_hash_str = dap_server_http_db_auth_create_key_hash(a_wallet_name, &l_addr_base58); - char *l_ret_str = NULL; - - if(l_sign_hash_str && l_addr_base58) { - l_ret_str = dap_strdup_printf("%s;%s", l_addr_base58, l_sign_hash_str); - } - DAP_DELETE(l_addr_base58); - DAP_DELETE(l_sign_hash_str); - return l_ret_str; -} - -/** - * Create new key hash - */ -char* dap_server_http_db_auth_create_key_hash(const char *a_wallet_name, char **a_addr_base58) -{ - const char *c_wallets_path = dap_config_get_item_str(g_config, "general", "wallets_path"); - dap_chain_wallet_t * l_wallet = dap_chain_wallet_open(a_wallet_name, c_wallets_path); - if(!l_wallet) - return NULL; - dap_enc_key_t *l_key = dap_chain_wallet_get_key(l_wallet, 0); - const dap_chain_addr_t *l_addr = dap_chain_wallet_get_addr(l_wallet); - char *l_addr_base58 = dap_chain_addr_to_str(l_addr); - if(!l_addr_base58) - return NULL; - - // make signature - const void *l_data = l_addr_base58; - const size_t l_data_size = strlen(l_data); - dap_chain_sign_t *l_chain_sign = dap_chain_sign_create(l_key, l_data, l_data_size, 0); - size_t l_chain_sign_size = dap_chain_sign_get_size(l_chain_sign); - - dap_chain_wallet_close(l_wallet); - if(a_addr_base58) - *a_addr_base58 = l_addr_base58; - else - DAP_DELETE(l_addr_base58); - - // make dap_chain_sign_t hash - dap_chain_hash_fast_t l_sign_hash; - if(!dap_hash_fast(l_chain_sign, l_chain_sign_size, &l_sign_hash) ) { - return NULL; - } - - // hash to str - const size_t cl_str_ret_size = sizeof(dap_chain_hash_fast_t) * 2 + 1; - char *l_str_ret = DAP_NEW_Z_SIZE(char, sizeof(dap_chain_hash_fast_t) * 2 + 1); - dap_chain_hash_fast_to_str(&l_sign_hash, l_str_ret, cl_str_ret_size); - return l_str_ret; -} - -/** - * Checking service_key from service client - */ -bool dap_server_http_db_auth_check_key(char *a_addr_base58, const char *a_sign_hash_str) -{ - //exist_user_in_db("da"); - if(!a_addr_base58 || !a_sign_hash_str) - return false; - - /* // create l_chain_sign for check a_sign - dap_chain_sign_t *l_chain_sign = DAP_NEW_Z_SIZE(dap_chain_sign_t, - sizeof(dap_chain_sign_t) + a_sign_size + l_pkey_size); - l_chain_sign->header.type = l_sig_type; - l_chain_sign->header.sign_size = l_pkey_size; - l_chain_sign->header.sign_pkey_size = l_pkey_size; - // write serialized public key to dap_chain_sign_t - memcpy(l_chain_sign->pkey_n_sign, l_pkey, l_pkey_size); - // write serialized signature to dap_chain_sign_t - memcpy(l_chain_sign->pkey_n_sign + l_pkey_size, a_sign, a_sign_size); - - // check signature - if(dap_chain_sign_verify(l_chain_sign, a_sign, a_sign_size) != 1) { - // invalid signature - return 0; - }*/ - - // TODO add find l_wallet_name by a_addr_base58 - const char *l_wallet_name = "w_picnic"; - // Create new hash - char *l_sign_hash_str = dap_server_http_db_auth_create_key_hash(l_wallet_name, NULL); - size_t l_sign_hash_str_len = (l_sign_hash_str) ? strlen(l_sign_hash_str) : 0; - - // compare l_sign_hash_str and a_sign_hash_str - if(!l_sign_hash_str_len || l_sign_hash_str_len != strlen(a_sign_hash_str)) { - return false; - } - if(memcmp(l_sign_hash_str, a_sign_hash_str, l_sign_hash_str_len)) { - return false; - } - - return true; -} diff --git a/dap_server_http_db_auth.h b/dap_server_http_db_auth.h deleted file mode 100644 index 0064a1c..0000000 --- a/dap_server_http_db_auth.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Authors: - * Dmitriy A. Gearasimov <gerasimov.dmitriy@demlabs.net> - * Aleksandr Lysikov <alexander.lysikov@demlabs.net> - * DeM Labs Inc. https://demlabs.net - * Kelvin Project https://github.com/kelvinblockchain - * Copyright (c) 2019 - * All rights reserved. - - This file is part of DAP (Deus Applications Prototypes) the open source project - - DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - DAP is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. - */ - -#pragma once - -#include <stdint.h> -#include <stdbool.h> - -// Parse a_service_key from service client -bool dap_server_http_db_auth_parse_service_key(const char *a_service_key, char **a_addr_base58, char **a_sign_hash); -// Create new service_key -char* dap_server_http_db_auth_create_service_key(const char *a_wallet_name); - -// Create new key hash -char* dap_server_http_db_auth_create_key_hash(const char *a_wallet_name, char **a_addr_base58); -// Checking service_key from service client -bool dap_server_http_db_auth_check_key(char *a_addr_base58, const char *a_sign_hash_str); - diff --git a/db/CMakeLists.txt b/db/CMakeLists.txt deleted file mode 100755 index 483c09b..0000000 --- a/db/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -cmake_minimum_required(VERSION 2.8) -project (dap_db) - -set(DB_SRCS db_core.c db_http.c db_http_file.c) - -add_library(${PROJECT_NAME} STATIC ${DB_SRCS}) - -target_link_libraries(dap_db - dap_core dap_crypto - dap_http_server dap_enc_server - ${BSON_LIBRARIES} ${MONGO_LIBRARIES}) - -target_include_directories(dap_db - INTERFACE . - PUBLIC ${BSON_INCLUDE_DIRS} ${MONGO_INCLUDE_DIRS}) diff --git a/db/db_core.c b/db/db_core.c deleted file mode 100755 index 2f00a7f..0000000 --- a/db/db_core.c +++ /dev/null @@ -1,82 +0,0 @@ -/* - Copyright (c) 2017-2018 (c) Project "DeM Labs Inc" https://github.com/demlabsinc - All rights reserved. - - This file is part of DAP (Deus Applications Prototypes) the open source project - - DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - DAP is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include <string.h> -#include <bson.h> -#include <bcon.h> -#include <mongoc.h> -#include "dap_common.h" -#include "db_core.h" -#define LOG_TAG "db" - -mongoc_client_t *mongo_client = NULL, - *traffick_track_db_client = NULL; - -int db_core_init(const char *db_path) -{ - mongoc_init(); - - mongo_client = mongoc_client_new (db_path); - traffick_track_db_client = mongoc_client_new (db_path); - log_it(L_DEBUG, "Checking connection to database..."); - if(!mongoc_client_get_server_status(mongo_client, NULL, NULL, NULL)) - { - log_it(L_ERROR, "Can't connect to database"); - return -1; - } - - return 0; -} - -void db_core_deinit() -{ - if(mongo_client) - mongoc_client_destroy(mongo_client); - if(traffick_track_db_client) - mongoc_client_destroy(traffick_track_db_client); - - mongoc_cleanup (); -} - -void db_core_refresh() -{ - -} - - -int db_input_validation(const char * str) -{ - // The compiler will stack "multiple" "strings" "end" "to" "end" - // into "multiplestringsendtoend", so we don't need one giant line. - static const char *nospecial="0123456789" - "abcdefghijklmnopqrstuvwxyz" - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - ".=@?_!#$%"; - - while(*str) // Loop until (*url) == 0. (*url) is about equivalent to url[0]. - { - // Can we find the character at *url in the string 'nospecial'? - // If not, it's a special character and we should return 0. - if(strchr(nospecial, *str) == NULL) return(0); - str++; // Jump to the next character. Adding one to a pointer moves it ahead one element. - } - - return(1); // Return 1 for success. -} diff --git a/db/db_core.h b/db/db_core.h deleted file mode 100755 index dd1af60..0000000 --- a/db/db_core.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef _DATABASE_H_ -#define _DATABASE_H_ - -#include <stddef.h> -#include <mongoc.h> - -extern int db_core_init(const char *db_path); -extern void db_core_deinit(); - -extern void db_core_refresh(); - -extern int db_input_validation(const char * str); - -extern mongoc_client_t *mongo_client, *traffick_track_db_client; - - -#endif diff --git a/db/db_http.c b/db/db_http.c deleted file mode 100755 index ac0f011..0000000 --- a/db/db_http.c +++ /dev/null @@ -1,74 +0,0 @@ -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include "utlist.h" - -#include "dap_common.h" - -#include "dap_client_remote.h" -#include "dap_http_client.h" -#include "dap_http_simple.h" - -#include "db_http.h" - -#include "../auth/db_auth.h" -#include "http_status_code.h" - -#include "dap_enc_http.h" - -#define LOG_TAG "db_http" - -#define LAST_USE_KEY(key) ((rsa_key_t*)key->internal)->last_time_use_key - -void db_http_proc(dap_http_simple_t * cl_st, void * arg ); - -int db_http_init() -{ - log_it(L_NOTICE, "Init content manager"); - return 0; -} - -void db_http_deinit() -{ - log_it(L_NOTICE, "Deinit content manager"); -} - - -void db_http_add_proc(struct dap_http * sh, const char * url) -{ - dap_http_simple_proc_add(sh,url,1000000,db_http_proc); -} - -/** - * @brief content_proc Process content list request - * @param sh HTTP simple client instance - * @param arg Return if ok - */ -void db_http_proc(dap_http_simple_t * cl_st, void * arg ) -{ - http_status_code_t * return_code = (http_status_code_t*)arg; - enc_http_delegate_t * dg; - strcpy(cl_st->reply_mime,"application/octet-stream"); - - dg=enc_http_request_decode(cl_st); - if(dg){ - if(strcmp(dg->url_path,"auth")==0){ - db_auth_http_proc(dg, arg); - } else { - - if(dg->url_path) - log_it(L_ERROR,"Wrong DB request %s",dg->url_path); - else - log_it(L_ERROR,"Wrong DB request: nothing after / "); - - *return_code = Http_Status_BadRequest; - } - - enc_http_reply_encode(cl_st,dg); - enc_http_delegate_delete(dg); - }else{ - *return_code = Http_Status_Unauthorized; - log_it(L_WARNING,"No KeyID in the request"); - } -} - diff --git a/db/db_http.h b/db/db_http.h deleted file mode 100755 index bba8dc9..0000000 --- a/db/db_http.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef _DB_HTTP_H_ -#define _DB_HTTP_H_ - -#include "dap_enc_ks.h" -#include "dap_enc_key.h" - -int db_http_init(void); -void db_http_deinit(void); -void db_http_add_proc(struct dap_http * sh, const char * url); -#endif diff --git a/db/db_http_file.c b/db/db_http_file.c deleted file mode 100755 index a4c2841..0000000 --- a/db/db_http_file.c +++ /dev/null @@ -1,250 +0,0 @@ -#include <sys/stat.h> -#include <stdio.h> -#include <unistd.h> -#include <string.h> -#include <errno.h> - -#include "dap_common.h" - -//#include "db_content.h" - -#include "dap_http.h" -#include "dap_http_client.h" - -#include "dap_enc.h" -#include "dap_enc_key.h" -#include "dap_enc_ks.h" - -#include "dap_client_remote.h" - -#define LOG_TAG "db_http_file" - -#define AES_BLOCK_SIZE 16 - -typedef struct db_http_file{ - FILE * fd; - size_t file_size; - dap_enc_key_t * key; - size_t position; - char path[4096]; - dap_http_client_t * client; -} db_http_file_t; - -#define DB_HTTP_FILE(a) ((db_http_file_t*) (a)->_internal ) - - -void db_http_file_headers_read(dap_http_client_t * cl_ht, void * arg); -void db_http_file_headers_write(dap_http_client_t * cl_ht, void * arg); -void db_http_file_data_read(dap_http_client_t * cl_ht, void * arg); -void db_http_file_data_write(dap_http_client_t * cl_ht, void * arg); - -static const char *_contents_path; - -int db_http_file_init(const char* content_path) -{ - _contents_path = strdup(content_path); - return 0; -} - -void db_http_file_deinit() -{ - free((char*)_contents_path); -} - -void db_http_file_proc_add(struct dap_http *sh, const char * url_path) -{ - dap_http_add_proc(sh,url_path,NULL,NULL,NULL,db_http_file_headers_read,db_http_file_headers_write, - db_http_file_data_read,db_http_file_data_write,NULL); -} - - - -/** - * @brief db_http_file_headers_read Signal thats HTTP client is now going to output the data - * @param cl_ht HTTP client instance - * @param arg Not used - */ -void db_http_file_headers_read(dap_http_client_t * cl_ht, void * arg) -{ - (void) arg; - cl_ht->state_write=DAP_HTTP_CLIENT_STATE_START; - cl_ht->state_read=cl_ht->keep_alive?DAP_HTTP_CLIENT_STATE_START:DAP_HTTP_CLIENT_STATE_NONE; - dap_client_remote_ready_to_write(cl_ht->client,true); - dap_client_remote_ready_to_read(cl_ht->client,cl_ht->keep_alive); -} - -/** - * @brief db_http_file_headers Prepare response HTTP headers for file folder request - * @param cl_ht HTTP client instane - * @param arg Not used - */ -void db_http_file_headers_write(dap_http_client_t * cl_ht, void * arg) -{ - (void) arg; - - dap_enc_key_t * key= dap_enc_ks_find_http(cl_ht); - if(key){ - uint8_t buf[sizeof(cl_ht->url_path)]; - size_t buf_size=0; - size_t url_path_size=strlen(cl_ht->url_path); - - if(url_path_size){ - if(url_path_size>sizeof(cl_ht->url_path)){ - log_it(L_WARNING, "Too big URL path %lu bytes, shrinking to %lu",url_path_size,sizeof(cl_ht->url_path)); - url_path_size=sizeof(cl_ht->url_path); - } - buf_size=dap_enc_decode(key,cl_ht->url_path,url_path_size,buf,sizeof(cl_ht->url_path), DAP_ENC_DATA_TYPE_B64); - - uint8_t file_variant=0; - if(strcmp(buf,"poster_small")==0){ - file_variant=1; - }else if(strcmp(buf,"poster_big")==0){ - file_variant=2; - } - if(file_variant){ - size_t in_query_string_length=strlen(cl_ht->in_query_string); - - if(in_query_string_length){ - long long cnt_id; - buf_size=dap_enc_decode(key,cl_ht->in_query_string,in_query_string_length,buf,sizeof(cl_ht->url_path),DAP_ENC_DATA_TYPE_B64); - if(sscanf(buf,"id=%lld",&cnt_id)==1){ - char buf2[255]; - snprintf(buf2,sizeof(buf2)-1,"id=%lld",cnt_id); - // db_content_t * cnt=db_content_select(buf2); //erase - void * cnt = NULL; - if(cnt){ - // Produce local path for file to open - char * file_path=NULL; - - /* ERASE */ - /* - if(file_variant==1) - file_path=cnt->poster_small; - else if( file_variant==2) - file_path=cnt->poster_big;*/ - - if(file_path){ - // Init specific file response data for HTTP client instance - cl_ht->_internal=(db_http_file_t *) calloc (1,sizeof(db_http_file_t)); - db_http_file_t* cl_ht_file=DB_HTTP_FILE(cl_ht); - cl_ht_file->client=cl_ht; - cl_ht_file->key=key; - - - snprintf(cl_ht_file->path,sizeof(cl_ht_file->path),"%s/%s", _contents_path, file_path ); - - log_it(L_DEBUG, "Check %s file", cl_ht_file->path); - - struct stat file_stat; - if(stat(cl_ht_file->path,&file_stat)==0){ - cl_ht->out_last_modified=file_stat.st_mtime; - cl_ht->out_content_length=(file_stat.st_size%AES_BLOCK_SIZE )? - (file_stat.st_size +(AES_BLOCK_SIZE- (file_stat.st_size%AES_BLOCK_SIZE) )): - file_stat.st_size; - cl_ht_file->file_size=file_stat.st_size; - cl_ht_file->fd=fopen(cl_ht_file->path,"r"); - if(cl_ht_file->fd == NULL){ - log_it(L_ERROR, "Can't open %s: %s",cl_ht_file->path,strerror(errno)); - cl_ht->reply_status_code=404; - strncpy(cl_ht->reply_reason_phrase,"Not Found",sizeof(cl_ht->reply_reason_phrase)); - }else{ - log_it(L_NOTICE, "Open %s file (%lu bytes raw, %lu bytes encrypted )",cl_ht_file->path,cl_ht_file->file_size,cl_ht->out_content_length); - cl_ht->reply_status_code=200; - dap_client_remote_ready_to_write(cl_ht->client,true); - strncpy(cl_ht->reply_reason_phrase,"OK",sizeof(cl_ht->reply_reason_phrase)); - } - - }else{ - log_it(L_WARNING, "Can't get file info: %s",strerror(errno)); - cl_ht->reply_status_code=404; - strncpy(cl_ht->reply_reason_phrase,"Not Found",sizeof(cl_ht->reply_reason_phrase)); - } - }else{ - log_it(L_WARNING, "Unknown file variant %uc",file_variant); - cl_ht->reply_status_code=404; - strncpy(cl_ht->reply_reason_phrase,"Not Found",sizeof(cl_ht->reply_reason_phrase)); - } - }else{ - log_it(L_WARNING, "Can't find id %lld in database",cnt_id); - cl_ht->reply_status_code=404; - strncpy(cl_ht->reply_reason_phrase,"Not Found",sizeof(cl_ht->reply_reason_phrase)); - } - }else{ - log_it(L_WARNING, "Can't parse decoded in query string '%s'",buf); - cl_ht->reply_status_code=500; - strncpy(cl_ht->reply_reason_phrase,"Not Found",sizeof(cl_ht->reply_reason_phrase)); - } - }else{ - log_it(L_WARNING, "Empty in query string"); - cl_ht->reply_status_code=404; - strncpy(cl_ht->reply_reason_phrase,"Not Found",sizeof(cl_ht->reply_reason_phrase)); - } - }else{ - log_it(L_WARNING, "Wrong path request (decoded string '%s' )", buf ); - cl_ht->reply_status_code=500; - strncpy(cl_ht->reply_reason_phrase,"ERROR",sizeof(cl_ht->reply_reason_phrase)); - } - }else{ - - log_it(L_WARNING, "Empty url path"); - cl_ht->reply_status_code=500; - strncpy(cl_ht->reply_reason_phrase,"ERROR",sizeof(cl_ht->reply_reason_phrase)); - } - }else{ - log_it(L_WARNING, "No KeyID in request"); - cl_ht->reply_status_code=500; - strncpy(cl_ht->reply_reason_phrase,"ERROR",sizeof(cl_ht->reply_reason_phrase)); - } -} - -/** - * @brief db_http_file_read HTTP client callback for reading function for the folder processing - * @param cl_ht HTTP client instance - * @param arg Pointer to int with return bytes number - */ -void db_http_file_data_read(dap_http_client_t * cl_ht, void * arg) -{ - int * bytes_return = (int*) arg; // Return number of read bytes - //Do nothing - *bytes_return=cl_ht->client->buf_in_size; -} - -/** - * @brief db_http_folder_write HTTP client callback for writting function for the folder processing - * @param cl_ht HTTP client instance - * @param arg - */ -void db_http_file_data_write(dap_http_client_t * cl_ht, void * arg) -{ - (void) arg; - db_http_file_t * cl_ht_file= DB_HTTP_FILE(cl_ht); - - uint8_t buf[AES_BLOCK_SIZE*200]; // We thing that its dividing on AES_BLOCKSIZE to have no trailing zeros in encrypted block - size_t buf_size_max=sizeof(buf); - if(cl_ht_file->file_size- cl_ht_file->position<buf_size_max) - buf_size_max=(cl_ht_file->file_size- cl_ht_file->position); - - if(buf_size_max){ - size_t buf_size=0; - buf_size+=fread(buf+buf_size,1,buf_size_max-buf_size,cl_ht_file->fd); - - cl_ht_file->position+=buf_size; - cl_ht->client->buf_out_size=dap_enc_code(cl_ht_file->key, buf,buf_size,cl_ht->client->buf_out,DAP_CLIENT_REMOTE_BUF, DAP_ENC_DATA_TYPE_RAW); - // log_it(L_DEBUG, "Have read %lu bytes from the file (ecrypted size %lu total size %lu expecting %lu)",buf_size,cl_ht->client->buf_out_size,cl_ht_file->position, cl_ht_file->client->out_content_length); - if(feof(cl_ht_file->fd)!=0){ - log_it(L_INFO, "All the file %s is sent out (%lu bytes)",cl_ht_file->path,cl_ht_file->position); - //strncat(cl_ht->client->buf_out+cl_ht->client->buf_out_size,"\r\n",sizeof(cl_ht->client->buf_out)); - fclose(cl_ht_file->fd); - dap_client_remote_ready_to_write(cl_ht->client,false); - cl_ht->client->signal_close=!cl_ht->keep_alive; - cl_ht->state_write=DAP_HTTP_CLIENT_STATE_NONE; - } - }else{ - log_it(L_INFO, "All the file %s is sent out (%lu bytes)",cl_ht_file->path,cl_ht_file->position); - fclose(cl_ht_file->fd); - dap_client_remote_ready_to_write(cl_ht->client,false); - cl_ht->client->signal_close=!cl_ht->keep_alive; - cl_ht->state_write=DAP_HTTP_CLIENT_STATE_NONE; - } -} - diff --git a/db/db_http_file.h b/db/db_http_file.h deleted file mode 100755 index d0d9a2e..0000000 --- a/db/db_http_file.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef _DB_HTTP_FILE_H_ -#define _DB_HTTP_FILE_H_ -struct dap_http; - -extern int db_http_file_init(); -extern void db_http_file_deinit(); - -extern void db_http_file_proc_add(struct dap_http *sh, const char * url_path); - -#endif diff --git a/auth/db_auth.c b/db_auth.c similarity index 100% rename from auth/db_auth.c rename to db_auth.c diff --git a/auth/db_auth.h b/include/db_auth.h similarity index 100% rename from auth/db_auth.h rename to include/db_auth.h -- GitLab