From 4c295056845ee79e1594c0514da1704b4ed0d272 Mon Sep 17 00:00:00 2001
From: "Dmitriy A. Gerasimov" <dmitriy.gerasimov@demlabs.net>
Date: Tue, 29 Oct 2019 17:34:25 +0700
Subject: [PATCH] [*] Refactored some

---
 CMakeLists.txt             | 12 +++++++-----
 include/db_auth.h          | 36 ++++++++++++++++--------------------
 db_auth.c => src/db_auth.c |  4 ++--
 3 files changed, 25 insertions(+), 27 deletions(-)
 rename db_auth.c => src/db_auth.c (99%)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index ae3fef2..6e54282 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,11 +1,13 @@
 cmake_minimum_required(VERSION 3.0)
 project (dap_server_http_db_auth)
   
-set(AUTH_SRCS db_auth.c)
+file(GLOB DAP_SERVER_HTTP_DB_AUTH_SOURCES src/*.c)
+file(GLOB DAP_SERVER_HTTP_DB_AUTH_HEADERS include/*.h)
 
-add_library(${PROJECT_NAME} STATIC ${AUTH_SRCS})
+add_library(${PROJECT_NAME} STATIC ${DAP_SERVER_HTTP_DB_AUTH_SOURCES} ${DAP_SERVER_HTTP_DB_AUTH_HEADERS})
 
-target_link_libraries(${PROJECT_NAME} dap_core
-    dap_crypto dap_http_server dap_enc_server
-    dap_stream dap_http_server_db )
+target_link_libraries(${PROJECT_NAME} dap_crypto dap_stream dap_server_http_db )
+
+target_include_directories(${PROJECT_NAME} PUBLIC include)
+target_include_directories(${PROJECT_NAME} PRIVATE src)
 
diff --git a/include/db_auth.h b/include/db_auth.h
index 8884b58..ac0d6ad 100755
--- a/include/db_auth.h
+++ b/include/db_auth.h
@@ -1,5 +1,5 @@
 /*
- Copyright (c) 2017-2018 (c) Project "DeM Labs Inc" https://github.com/demlabsinc
+ Copyright (c) 2017-2019 (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
@@ -18,9 +18,7 @@
     along with any DAP based project.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-
-#ifndef STREAM_AUTH_H
-#define STREAM_AUTH_H
+#pragma once
 #include <stdint.h>
 #include <pthread.h>
 #include "uthash.h"
@@ -46,41 +44,39 @@ typedef struct db_auth_info{
     UT_hash_handle hh; // makes this structure hashable with UTHASH library
 } db_auth_info_t;
 
-extern int db_auth_init(const char* db_name);
-extern void db_auth_deinit(void);
+int db_auth_init(const char* db_name);
+void db_auth_deinit(void);
 
 
-extern db_auth_info_t* db_auth_info_by_cookie(const char * cookie);
-extern db_auth_info_t* db_search_cookie_in_db(const char * cookie);
+db_auth_info_t* db_auth_info_by_cookie(const char * cookie);
+db_auth_info_t* db_search_cookie_in_db(const char * cookie);
 
-extern int db_auth_login(const char* login, const char* password,
+int db_auth_login(const char* login, const char* password,
                               const char* domain, db_auth_info_t** ai);
 
-extern db_auth_info_t * db_auth_register(const char *user,const char *password,
+db_auth_info_t * db_auth_register(const char *user,const char *password,
                                          const char *domain, const char * first_name,
                                          const char* last_name, const char * email,
                                          const char * device_type, const char *app_version,
                                          const char *hostaddr, const char *sys_uuid);
 
-extern db_auth_info_t * db_auth_register_channel(const char* name_channel, const char* domain,
+db_auth_info_t * db_auth_register_channel(const char* name_channel, const char* domain,
                                                  const char* password);
-extern bool exist_user_in_db(const char* user);
-
-extern bool db_auth_user_change_password(const char* user, const char* password,
+bool exist_user_in_db(const char* user);
+bool db_auth_user_change_password(const char* user, const char* password,
                                   const char* new_password);
 
-extern bool db_auth_change_password(const char *user, const char* new_password);
+bool db_auth_change_password(const char *user, const char* new_password);
 
-extern bool check_user_password(const char* user, const char* password);
+bool check_user_password(const char* user, const char* password);
 
-extern void db_auth_http_proc(enc_http_delegate_t *dg, void * arg);
+void db_auth_http_proc(enc_http_delegate_t *dg, void * arg);
 
-extern void db_auth_traffic_track_callback(dap_server_t *srv);
+void db_auth_traffic_track_callback(dap_server_t *srv);
 
 /// Check user data for correct input.
 /// @param before_parsing Line size before parsing.
 /// @param after_parsing Line size after parsing.
 /// @return Returns true if user data is entered correctly
 /// (there are 2 separator spaces), otherwise false.
-extern inline bool check_user_data_for_space(size_t before_parsing, size_t after_parsing);
-#endif
+inline bool check_user_data_for_space(size_t before_parsing, size_t after_parsing);
diff --git a/db_auth.c b/src/db_auth.c
similarity index 99%
rename from db_auth.c
rename to src/db_auth.c
index 9e61f21..470a088 100755
--- a/db_auth.c
+++ b/src/db_auth.c
@@ -36,10 +36,10 @@
 #include "dap_enc_http.h"
 #include "dap_enc_base64.h"
 #include "dap_server.h"
-#include "../db/db_core.h"
+#include "db_core.h"
 #include "db_auth.h"
 #include "http_status_code.h"
-#include "mongoc.h"
+#include <mongoc.h>
 
 
 #define LOG_TAG "db_auth"
-- 
GitLab