]> git.feebdaed.xyz Git - socialize.git/commitdiff
fix missing return for run cli, change name
authorseantywork <seantywork@gmail.com>
Fri, 21 Feb 2025 04:47:32 +0000 (13:47 +0900)
committerseantywork <seantywork@gmail.com>
Fri, 21 Feb 2025 04:47:32 +0000 (13:47 +0900)
21 files changed:
Makefile
README.md
cmd/cli/main.c
cmd/engine/main.c
include/chat/cli/cli.h [deleted file]
include/chat/core.h [deleted file]
include/chat/ctl.h [deleted file]
include/chat/front/front.h [deleted file]
include/chat/sock/sock.h [deleted file]
include/chat/utils.h [deleted file]
include/socialize/cli/cli.h [new file with mode: 0644]
include/socialize/core.h [new file with mode: 0644]
include/socialize/ctl.h [new file with mode: 0644]
include/socialize/front/front.h [new file with mode: 0644]
include/socialize/sock/sock.h [new file with mode: 0644]
include/socialize/utils.h [new file with mode: 0644]
src/cli/cli.c
src/ctl.c
src/front/front.c
src/sock/sock.c
src/utils.c

index ac2f3e0462b2033b6723b38031276a4338a2ff97..ab8477795eb77acb23446f185c35de52411feb05 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -31,7 +31,7 @@ DEP_OBJS += cJSON.o
 
 all: 
 
-       @echo "chat: dev, release"
+       @echo "socialize: dev, release"
 
 
 deps:
index c717fb6e045403fddcf438376eb3b771541637c7..a75a5d6b077406590575b11718f7e1b21784a329 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,3 +1,3 @@
-# chat
+# socialize
 
-chat on terminal is the only way to truly socialize
\ No newline at end of file
+I socialize on terminal
\ No newline at end of file
index 007376ce21bcdb5f292329696abeff3eb40ac36a..03afa37bc9afc712fb615bb1868996ad4ac9a003 100644 (file)
@@ -1,5 +1,5 @@
-#include "chat/cli/cli.h"
-#include "chat/utils.h"
+#include "socialize/cli/cli.h"
+#include "socialize/utils.h"
 
 int cli_done = 0;
 int TEST_CASE = -1;
@@ -25,9 +25,11 @@ int main(int argc, char **argv){
 
     signal(SIGINT, signal_handler);
 
+    int ret;
+
     if(argc == 2){
 
-        run_cli(argv[1]);
+        ret = run_cli(argv[1]);
 
 
     } else {
@@ -36,13 +38,13 @@ int main(int argc, char **argv){
 
             TEST_CASE = 1;
 
-            run_cli(argv[1]);
+            ret = run_cli(argv[1]);
 
         } else if (strcmp(argv[2], "2") == 0){
 
             TEST_CASE = 2;
 
-            run_cli(argv[1]);
+            ret = run_cli(argv[1]);
 
         } else {
 
@@ -54,5 +56,5 @@ int main(int argc, char **argv){
 
     }
 
-    return 0;
+    return ret;
 }
\ No newline at end of file
index 85f805eceac51de4b8480cbcf1132212b7260d92..2b0846a293c373f35a731934aa3102b672509b61 100644 (file)
@@ -1,8 +1,8 @@
 
-#include "chat/sock/sock.h"
-#include "chat/front/front.h"
+#include "socialize/sock/sock.h"
+#include "socialize/front/front.h"
 
-#include "chat/utils.h"
+#include "socialize/utils.h"
 FILE* LOGFP;
 
 pthread_mutex_t G_MTX;
diff --git a/include/chat/cli/cli.h b/include/chat/cli/cli.h
deleted file mode 100644 (file)
index bb55e87..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-#ifndef _FRANK_CLI_H_
-#define _FRANK_CLI_H_
-
-#include "chat/core.h"
-
-
-#ifndef VERIFICATION_LOCATION
-# define VERIFICATION_LOCATION "tls/ca.crt.pem"
-#endif
-
-
-# define ASSERT(x) { \
-  if(!(x)) { \
-    fprintf(stderr, "Assertion: %s: function %s, line %d\n", (char*)(__FILE__), (char*)(__func__), (int)__LINE__); \
-    exit(SIGTRAP); \
-  } \
-}
-
-
-
-
-void run_cli(char* addr);
-
-
-void run_cli_test(char* addr, int tc);
-
-
-int connect_to_engine(char* addr, long timeout);
-
-int auth();
-
-int join();
-
-void chat();
-
-void* reader();
-
-
-
-int verify_callback(int preverify, X509_STORE_CTX* x509_ctx);
-
-void init_openssl_library(void);
-void print_cn_name(const char* label, X509_NAME* const name);
-void print_san_name(const char* label, X509* const cert);
-void print_error_string(unsigned long err, const char* const label);
-
-extern int cli_done;
-extern char* PREFERRED_CIPHERS;
-
-
-extern int TEST_CASE;
-
-extern SSL_CTX* ctx;
-extern SSL *ssl ;
-
-extern uint8_t header[HUB_HEADER_BYTELEN];
-extern uint8_t body_len[HUB_BODY_BYTELEN];
-extern uint64_t body_len_new;
-extern uint8_t *body;
-
-#endif 
diff --git a/include/chat/core.h b/include/chat/core.h
deleted file mode 100644 (file)
index e06668f..0000000
+++ /dev/null
@@ -1,279 +0,0 @@
-#ifndef _FRANK_HUB_H_
-#define _FRANK_HUB_H_
-
-
-
-#include <stdio.h> 
-#include <netinet/in.h> 
-#include <stdlib.h> 
-#include <string.h> 
-#include <stdint.h>
-#include <sys/types.h>
-#include <sys/socket.h>  
-#include <unistd.h> 
-#include <time.h>
-#include <endian.h>
-#include <pthread.h>
-#include <stdarg.h>
-#include <sys/time.h>
-#include <poll.h>
-#include <signal.h>
-#include <fcntl.h>
-#include <sys/epoll.h>
-#include <errno.h>
-#include <arpa/inet.h>
-#include <netdb.h> 
-
-#include <openssl/ssl.h>
-#include <openssl/err.h>
-#include <openssl/bio.h>
-#include <openssl/pem.h>
-#include <openssl/conf.h>
-#include <openssl/x509.h>
-#include <openssl/buffer.h>
-#include <openssl/x509v3.h>
-#include <openssl/opensslconf.h>
-
-#include "mongoose/mongoose.h"
-#include "cJSON/cJSON.h"
-
-#define DEBUG_THIS 0
-
-#define HUB_WORD           8
-#define HUB_HEADER_BYTELEN HUB_WORD * 3
-#define HUB_BODY_BYTELEN   HUB_WORD * 1
-#define HUB_BODY_BYTEMAX   HUB_WORD * 1280 //10KB
-#define HUB_TIMEOUT_MS 5000
-
-#define HUB_HEADER_AUTHSOCK "AUTHSOCK"
-#define HUB_HEADER_REGSOCK_CREATE "REGSOCK_CREATE"
-#define HUB_HEADER_REGSOCK_JOIN "REGSOCK_JOIN"
-
-
-#define HUB_HEADER_AUTHFRONT "AUTHFRONT"
-#define HUB_HEADER_AUTHFRANK "AUTHFRANK"
-#define HUB_HEADER_SENDSOCK "SENDSOCK"
-#define HUB_HEADER_RECVSOCK "RECVSOCK"
-#define HUB_HEADER_SENDFRONT "SENDFRONT"
-#define HUB_HEADER_RECVFRONT "RECVFRONT"
-#define HUB_HEADER_SENDFRANK "SENDFRANK"
-#define HUB_HEADER_RECVFRANK "RECVFRANK"
-
-
-
-#define TRUE 1
-#define FALSE 0
-#define MAX_BUFF HUB_BODY_BYTEMAX
-#define MAX_CONN 80
-#define MAX_ID_LEN 1024
-#define MAX_PW_LEN 4096
-#define PORT_FRONT 3000
-#define PORT_SOCK 3001 
-
-
-#define ISSOCK 1
-#define ISFRONT 2
-#define CHAN_ISSOCK 3
-#define CHAN_ISFRONT 4
-
-
-
-#define MAX_DEVICE_NAME 40
-#define MAX_EVENTS_NO 400
-#define MAX_EVENT_TEXT_SIZE 10
-#define EVENTS_PER_PAGE 20
-
-#define MAX_USER_NAME 1024
-#define MAX_USER_PASS 2048
-#define MAX_USER_ACCESS_TOKEN 1024
-
-#define MAX_COOKIE_LEN 1024
-#define MAX_COOKIE_KEYLEN 32
-
-#define MAX_USERS 10
-
-#define MAX_PUBLIC_URI_LEN 512
-
-#define MAX_REQUEST_URI_LEN 1024 * 10
-#define MAX_CLIENT_ID_LEN 1024
-#define MAX_CLIENT_SECRET_LEN 1024
-#define MAX_POST_FIELDS_LEN 1024 * 10
-
-#define MAX_CODELEN 256
-#define GOAUTH_TOKENLEN 512
-
-#define MAX_REST_BUFF 1024 * 10
-#define MAX_WS_BUFF 1024 * 10
-
-#define WS_MAX_COMMAND_LEN 32
-#define WS_MAX_COMMAND_DATA_LEN WS_MAX_COMMAND_LEN * 8
-#define WS_MAX_COMMAND_RECV_LEN WS_MAX_COMMAND_LEN * 8 * 8
-
-#define WS_COMMAND_REQ_KEY "reqkey"
-#define WS_COMMAND_ROUNDTRIP "roundtrip"
-
-#define DEFAULT_RANDLEN 64
-
-
-
-#ifndef HTTP_URL
-#define HTTP_URL "http://0.0.0.0:3000"
-#endif
-
-
-#ifndef HTTPS_URL
-#define HTTPS_URL "https://0.0.0.0:3443"
-#endif
-
-
-#define IS_BIG_ENDIAN (!*(unsigned char *)&(uint16_t){1})
-
-#if __BIG_ENDIAN__
-# define htonll(x) (x)
-# define ntohll(x) (x)
-#else
-# define htonll(x) (((uint64_t)htonl((x) & 0xFFFFFFFF) << 32) | htonl((x) >> 32))
-# define ntohll(x) (((uint64_t)ntohl((x) & 0xFFFFFFFF) << 32) | ntohl((x) >> 32))
-#endif
-
-#ifndef SERVER_KEY
-# define SERVER_KEY "tls/server_priv.pem"
-#endif
-
-#ifndef SERVER_CERT
-# define SERVER_CERT "tls/server.crt.pem"
-#endif
-
-#ifndef HUB_CA_CERT
-# define HUB_CA_CERT "tls/ca.crt.pem"
-#endif
-
-#ifndef HUB_CA_PRIV
-# define HUB_CA_PRIV "tls/ca_priv.pem"
-#endif
-
-#ifndef HUB_CA_PUB
-# define HUB_CA_PUB "tls/ca_pub.pem"
-#endif
-
-
-#ifndef SUB1_CERT
-# define SUB1_CERT "tls/sub1.crt.pem"
-#endif
-
-
-#ifndef SUB2_CERT
-# define SUB2_CERT "tls/sub2.crt.pem"
-#endif
-
-
-#define DEFAULT_RANDLEN 64
-//#define WAIT 7   
-
-
-
-
-
-struct user {
-    char name[MAX_USER_NAME];
-    char pass[MAX_USER_PASS];
-};
-
-
-struct CHANNEL_CONTEXT {
-    int allocated;
-    int sockfd;
-    int frontfd;
-    char id[MAX_ID_LEN];
-    char pw[MAX_PW_LEN];
-    SSL *ssl;
-    SSL_CTX *ctx;
-    int fd_ptr;
-    int fds[MAX_CONN];
-
-};
-
-struct SOCK_CONTEXT {
-    int allocated;
-    int sockfd;
-    SSL *ssl;
-    SSL_CTX *ctx;
-    int auth;
-    char id[MAX_ID_LEN];
-    int chan_idx;
-};
-
-
-
-
-struct HUB_PACKET {
-
-    int ctx_type;
-    char id[MAX_ID_LEN];
-    int fd;
-    uint8_t header[HUB_HEADER_BYTELEN];
-    uint64_t body_len;
-    uint8_t wbuff[MAX_BUFF];
-    uint8_t* rbuff;
-
-    int flag;
-
-};
-
-struct settings {
-    bool log_enabled;
-    int log_level;
-    long brightness;
-    char *device_name;
-  };
-
-
-
-extern char CA_CERT[MAX_PW_LEN];
-
-extern char CA_PRIV[MAX_PW_LEN];
-
-extern char CA_PUB[MAX_PW_LEN];
-
-
-extern int s_sig_num;
-
-
-extern struct settings s_settings;
-
-extern uint64_t s_boot_timestamp; 
-
-extern char *s_json_header;
-
-extern struct mg_mgr mgr;
-
-
-extern struct CHANNEL_CONTEXT CHAN_CTX[MAX_CONN];
-
-extern struct SOCK_CONTEXT SOCK_CTX[MAX_CONN];
-
-
-
-extern FILE* LOGFP;
-extern pthread_mutex_t G_MTX;
-
-extern int SOCK_FD;
-extern int SOCK_SERVLEN;
-extern int SOCK_EPLFD;
-extern struct epoll_event SOCK_EVENT;
-extern struct epoll_event *SOCK_EVENTARRAY;
-
-
-extern int FRONT_FD;
-extern int FRONT_SERVLEN;
-extern int FRONT_EPLFD;
-extern struct epoll_event FRONT_EVENT;
-extern struct epoll_event *FRONT_EVENTARRAY;
-
-extern int MAX_SD;
-
-extern int OPT;
-
-
-
-#endif
\ No newline at end of file
diff --git a/include/chat/ctl.h b/include/chat/ctl.h
deleted file mode 100644 (file)
index a767331..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-#ifndef _FRANK_HUB_CTL_H_
-#define _FRANK_HUB_CTL_H_
-
-#include "chat/core.h"
-
-int make_socket_non_blocking (int sfd);
-
-SSL_CTX *create_context();
-
-void configure_context(SSL_CTX *ctx);
-
-
-int sig_verify(const char* cert_pem, const char* intermediate_pem);
-
-int extract_common_name(uint8_t* common_name, const char* cert);
-
-int idpw_verify(char* idpw);
-
-int update_chanctx_from_userinfo(char* id, char* pw);
-
-int update_chanctx_from_sockctx(int fd, char* id);
-
-
-
-
-int set_sockctx_by_fd(int fd);
-
-int get_sockctx_by_fd(int fd);
-
-int set_sockctx_id_by_fd(int fd, char* id);
-
-int get_sockctx_id_by_fd(int fd, char* id);
-
-int set_chanctx_by_id(char* id, int create, int fd);
-
-int get_chanctx_by_id(char* id);
-
-int set_sockctx_chan_id_by_fd(int fd, int chan_id);
-
-int get_sockctx_chan_id_by_fd(int fd);
-
-
-
-int calloc_chanctx();
-
-int free_chanctx(int idx);
-
-int calloc_sockctx();
-
-int free_sockctx(int idx, int memfree);
-
-
-
-
-int chanctx_write(int type, char* id, int write_len, uint8_t* wbuff);
-
-int chanctx_read(int type, char* id, int read_len, uint8_t* rbuff);
-
-int sockctx_write(int fd, int write_len, uint8_t* wbuff);
-
-int sockctx_read(int fd, int read_len, uint8_t* rbuff);
-
-
-
-
-void ctx_write_packet(struct HUB_PACKET* hp);
-
-
-void ctx_read_packet(struct HUB_PACKET* hp);
-
-
-
-
-#endif
\ No newline at end of file
diff --git a/include/chat/front/front.h b/include/chat/front/front.h
deleted file mode 100644 (file)
index 31659b1..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-#ifndef _FRANK_HUB_FRONT_H_
-#define _FRANK_HUB_FRONT_H_
-
-#include "chat/core.h"
-
-
-
-
-
-
-void* front_listen_and_serve(void* varg);
-
-
-void sntp_fn(struct mg_connection *c, int ev, void *ev_data);
-
-void timer_sntp_fn(void *param);
-
-void route(struct mg_connection *c, int ev, void *ev_data);
-
-
-void front_handler(struct mg_connection *c, struct mg_ws_message *wm);
-
-
-void handle_healtiness_probe(struct mg_connection *c, struct mg_http_message *hm);
-
-
-int front_authenticate(struct mg_connection* c, struct mg_ws_message *wm, int* initial, char* command, char* data);
-
-void front_communicate(int chan_idx, char* command, char* data);
-
-
-
-
-
-
-#endif
\ No newline at end of file
diff --git a/include/chat/sock/sock.h b/include/chat/sock/sock.h
deleted file mode 100644 (file)
index b7813fa..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-#ifndef _FRANK_HUB_SOCK_H_
-#define _FRANK_HUB_SOCK_H_
-
-
-
-#include "chat/core.h"
-
-
-
-void sock_listen_and_serve(void* varg);
-
-
-void sock_handle_conn();
-
-
-void sock_handle_client(int cfd);
-
-void sock_authenticate(int cfd);
-
-void sock_register(int cfd);
-
-void sock_communicate(int chan_idx, int sock_idx);
-
-#endif
\ No newline at end of file
diff --git a/include/chat/utils.h b/include/chat/utils.h
deleted file mode 100644 (file)
index c7aceb7..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-#ifndef _FRANK_HUB_UTILS_H_
-#define _FRANK_HUB_UTILS_H_
-
-
-
-#include "chat/core.h"
-
-
-#define MAX_TIMESTR_LEN 80
-#define MAX_LOG_TXT_LEN 1024 
-#define MAX_FMT_ARG_LEN 128
-
-
-int read_file_to_buffer(uint8_t* buff, int max_buff_len, char* file_path);
-
-int gen_random_bytestream(uint8_t* bytes, size_t num_bytes);
-
-int bin2hex(uint8_t* hexarray, int arrlen, uint8_t* bytearray);
-
-
-
-
-int get_host_port(char* hostname, int* port, char* addr);
-
-
-
-void get_current_time_string(char* tstr);
-
-void sleepms(long ms);
-
-void fmt_logln(FILE *fp, char* fmt_out, ...);
-
-
-#endif
diff --git a/include/socialize/cli/cli.h b/include/socialize/cli/cli.h
new file mode 100644 (file)
index 0000000..f778763
--- /dev/null
@@ -0,0 +1,58 @@
+#ifndef _SOCIALIZE_CLI_H_
+#define _SOCIALIZE_CLI_H_
+
+#include "socialize/core.h"
+
+
+#ifndef VERIFICATION_LOCATION
+# define VERIFICATION_LOCATION "tls/ca.crt.pem"
+#endif
+
+
+# define ASSERT(x) { \
+  if(!(x)) { \
+    fprintf(stderr, "Assertion: %s: function %s, line %d\n", (char*)(__FILE__), (char*)(__func__), (int)__LINE__); \
+    exit(SIGTRAP); \
+  } \
+}
+
+
+
+
+int run_cli(char* addr);
+
+
+int connect_to_engine(char* addr, long timeout);
+
+int auth();
+
+int join();
+
+void socialize();
+
+void* reader();
+
+
+
+int verify_callback(int preverify, X509_STORE_CTX* x509_ctx);
+
+void init_openssl_library(void);
+void print_cn_name(const char* label, X509_NAME* const name);
+void print_san_name(const char* label, X509* const cert);
+void print_error_string(unsigned long err, const char* const label);
+
+extern int cli_done;
+extern char* PREFERRED_CIPHERS;
+
+
+extern int TEST_CASE;
+
+extern SSL_CTX* ctx;
+extern SSL *ssl ;
+
+extern uint8_t header[HUB_HEADER_BYTELEN];
+extern uint8_t body_len[HUB_BODY_BYTELEN];
+extern uint64_t body_len_new;
+extern uint8_t *body;
+
+#endif 
diff --git a/include/socialize/core.h b/include/socialize/core.h
new file mode 100644 (file)
index 0000000..b5297d2
--- /dev/null
@@ -0,0 +1,279 @@
+#ifndef _SOCIALIZE_CORE_H_
+#define _SOCIALIZE_CORE_H_
+
+
+
+#include <stdio.h> 
+#include <netinet/in.h> 
+#include <stdlib.h> 
+#include <string.h> 
+#include <stdint.h>
+#include <sys/types.h>
+#include <sys/socket.h>  
+#include <unistd.h> 
+#include <time.h>
+#include <endian.h>
+#include <pthread.h>
+#include <stdarg.h>
+#include <sys/time.h>
+#include <poll.h>
+#include <signal.h>
+#include <fcntl.h>
+#include <sys/epoll.h>
+#include <errno.h>
+#include <arpa/inet.h>
+#include <netdb.h> 
+
+#include <openssl/ssl.h>
+#include <openssl/err.h>
+#include <openssl/bio.h>
+#include <openssl/pem.h>
+#include <openssl/conf.h>
+#include <openssl/x509.h>
+#include <openssl/buffer.h>
+#include <openssl/x509v3.h>
+#include <openssl/opensslconf.h>
+
+#include "mongoose/mongoose.h"
+#include "cJSON/cJSON.h"
+
+#define DEBUG_THIS 0
+
+#define HUB_WORD           8
+#define HUB_HEADER_BYTELEN HUB_WORD * 3
+#define HUB_BODY_BYTELEN   HUB_WORD * 1
+#define HUB_BODY_BYTEMAX   HUB_WORD * 1280 //10KB
+#define HUB_TIMEOUT_MS 5000
+
+#define HUB_HEADER_AUTHSOCK "AUTHSOCK"
+#define HUB_HEADER_REGSOCK_CREATE "REGSOCK_CREATE"
+#define HUB_HEADER_REGSOCK_JOIN "REGSOCK_JOIN"
+
+
+#define HUB_HEADER_AUTHFRONT "AUTHFRONT"
+#define HUB_HEADER_AUTHFRANK "AUTHFRANK"
+#define HUB_HEADER_SENDSOCK "SENDSOCK"
+#define HUB_HEADER_RECVSOCK "RECVSOCK"
+#define HUB_HEADER_SENDFRONT "SENDFRONT"
+#define HUB_HEADER_RECVFRONT "RECVFRONT"
+#define HUB_HEADER_SENDFRANK "SENDFRANK"
+#define HUB_HEADER_RECVFRANK "RECVFRANK"
+
+
+
+#define TRUE 1
+#define FALSE 0
+#define MAX_BUFF HUB_BODY_BYTEMAX
+#define MAX_CONN 80
+#define MAX_ID_LEN 1024
+#define MAX_PW_LEN 4096
+#define PORT_FRONT 3000
+#define PORT_SOCK 3001 
+
+
+#define ISSOCK 1
+#define ISFRONT 2
+#define CHAN_ISSOCK 3
+#define CHAN_ISFRONT 4
+
+
+
+#define MAX_DEVICE_NAME 40
+#define MAX_EVENTS_NO 400
+#define MAX_EVENT_TEXT_SIZE 10
+#define EVENTS_PER_PAGE 20
+
+#define MAX_USER_NAME 1024
+#define MAX_USER_PASS 2048
+#define MAX_USER_ACCESS_TOKEN 1024
+
+#define MAX_COOKIE_LEN 1024
+#define MAX_COOKIE_KEYLEN 32
+
+#define MAX_USERS 10
+
+#define MAX_PUBLIC_URI_LEN 512
+
+#define MAX_REQUEST_URI_LEN 1024 * 10
+#define MAX_CLIENT_ID_LEN 1024
+#define MAX_CLIENT_SECRET_LEN 1024
+#define MAX_POST_FIELDS_LEN 1024 * 10
+
+#define MAX_CODELEN 256
+#define GOAUTH_TOKENLEN 512
+
+#define MAX_REST_BUFF 1024 * 10
+#define MAX_WS_BUFF 1024 * 10
+
+#define WS_MAX_COMMAND_LEN 32
+#define WS_MAX_COMMAND_DATA_LEN WS_MAX_COMMAND_LEN * 8
+#define WS_MAX_COMMAND_RECV_LEN WS_MAX_COMMAND_LEN * 8 * 8
+
+#define WS_COMMAND_REQ_KEY "reqkey"
+#define WS_COMMAND_ROUNDTRIP "roundtrip"
+
+#define DEFAULT_RANDLEN 64
+
+
+
+#ifndef HTTP_URL
+#define HTTP_URL "http://0.0.0.0:3000"
+#endif
+
+
+#ifndef HTTPS_URL
+#define HTTPS_URL "https://0.0.0.0:3443"
+#endif
+
+
+#define IS_BIG_ENDIAN (!*(unsigned char *)&(uint16_t){1})
+
+#if __BIG_ENDIAN__
+# define htonll(x) (x)
+# define ntohll(x) (x)
+#else
+# define htonll(x) (((uint64_t)htonl((x) & 0xFFFFFFFF) << 32) | htonl((x) >> 32))
+# define ntohll(x) (((uint64_t)ntohl((x) & 0xFFFFFFFF) << 32) | ntohl((x) >> 32))
+#endif
+
+#ifndef SERVER_KEY
+# define SERVER_KEY "tls/server_priv.pem"
+#endif
+
+#ifndef SERVER_CERT
+# define SERVER_CERT "tls/server.crt.pem"
+#endif
+
+#ifndef HUB_CA_CERT
+# define HUB_CA_CERT "tls/ca.crt.pem"
+#endif
+
+#ifndef HUB_CA_PRIV
+# define HUB_CA_PRIV "tls/ca_priv.pem"
+#endif
+
+#ifndef HUB_CA_PUB
+# define HUB_CA_PUB "tls/ca_pub.pem"
+#endif
+
+
+#ifndef SUB1_CERT
+# define SUB1_CERT "tls/sub1.crt.pem"
+#endif
+
+
+#ifndef SUB2_CERT
+# define SUB2_CERT "tls/sub2.crt.pem"
+#endif
+
+
+#define DEFAULT_RANDLEN 64
+//#define WAIT 7   
+
+
+
+
+
+struct user {
+    char name[MAX_USER_NAME];
+    char pass[MAX_USER_PASS];
+};
+
+
+struct CHANNEL_CONTEXT {
+    int allocated;
+    int sockfd;
+    int frontfd;
+    char id[MAX_ID_LEN];
+    char pw[MAX_PW_LEN];
+    SSL *ssl;
+    SSL_CTX *ctx;
+    int fd_ptr;
+    int fds[MAX_CONN];
+
+};
+
+struct SOCK_CONTEXT {
+    int allocated;
+    int sockfd;
+    SSL *ssl;
+    SSL_CTX *ctx;
+    int auth;
+    char id[MAX_ID_LEN];
+    int chan_idx;
+};
+
+
+
+
+struct HUB_PACKET {
+
+    int ctx_type;
+    char id[MAX_ID_LEN];
+    int fd;
+    uint8_t header[HUB_HEADER_BYTELEN];
+    uint64_t body_len;
+    uint8_t wbuff[MAX_BUFF];
+    uint8_t* rbuff;
+
+    int flag;
+
+};
+
+struct settings {
+    bool log_enabled;
+    int log_level;
+    long brightness;
+    char *device_name;
+  };
+
+
+
+extern char CA_CERT[MAX_PW_LEN];
+
+extern char CA_PRIV[MAX_PW_LEN];
+
+extern char CA_PUB[MAX_PW_LEN];
+
+
+extern int s_sig_num;
+
+
+extern struct settings s_settings;
+
+extern uint64_t s_boot_timestamp; 
+
+extern char *s_json_header;
+
+extern struct mg_mgr mgr;
+
+
+extern struct CHANNEL_CONTEXT CHAN_CTX[MAX_CONN];
+
+extern struct SOCK_CONTEXT SOCK_CTX[MAX_CONN];
+
+
+
+extern FILE* LOGFP;
+extern pthread_mutex_t G_MTX;
+
+extern int SOCK_FD;
+extern int SOCK_SERVLEN;
+extern int SOCK_EPLFD;
+extern struct epoll_event SOCK_EVENT;
+extern struct epoll_event *SOCK_EVENTARRAY;
+
+
+extern int FRONT_FD;
+extern int FRONT_SERVLEN;
+extern int FRONT_EPLFD;
+extern struct epoll_event FRONT_EVENT;
+extern struct epoll_event *FRONT_EVENTARRAY;
+
+extern int MAX_SD;
+
+extern int OPT;
+
+
+
+#endif
\ No newline at end of file
diff --git a/include/socialize/ctl.h b/include/socialize/ctl.h
new file mode 100644 (file)
index 0000000..7d3bebf
--- /dev/null
@@ -0,0 +1,74 @@
+#ifndef _SOCIALIZE_CTL_H_
+#define _SOCIALIZE_CTL_H_
+
+#include "socialize/core.h"
+
+int make_socket_non_blocking (int sfd);
+
+SSL_CTX *create_context();
+
+void configure_context(SSL_CTX *ctx);
+
+
+int sig_verify(const char* cert_pem, const char* intermediate_pem);
+
+int extract_common_name(uint8_t* common_name, const char* cert);
+
+int idpw_verify(char* idpw);
+
+int update_chanctx_from_userinfo(char* id, char* pw);
+
+int update_chanctx_from_sockctx(int fd, char* id);
+
+
+
+
+int set_sockctx_by_fd(int fd);
+
+int get_sockctx_by_fd(int fd);
+
+int set_sockctx_id_by_fd(int fd, char* id);
+
+int get_sockctx_id_by_fd(int fd, char* id);
+
+int set_chanctx_by_id(char* id, int create, int fd);
+
+int get_chanctx_by_id(char* id);
+
+int set_sockctx_chan_id_by_fd(int fd, int chan_id);
+
+int get_sockctx_chan_id_by_fd(int fd);
+
+
+
+int calloc_chanctx();
+
+int free_chanctx(int idx);
+
+int calloc_sockctx();
+
+int free_sockctx(int idx, int memfree);
+
+
+
+
+int chanctx_write(int type, char* id, int write_len, uint8_t* wbuff);
+
+int chanctx_read(int type, char* id, int read_len, uint8_t* rbuff);
+
+int sockctx_write(int fd, int write_len, uint8_t* wbuff);
+
+int sockctx_read(int fd, int read_len, uint8_t* rbuff);
+
+
+
+
+void ctx_write_packet(struct HUB_PACKET* hp);
+
+
+void ctx_read_packet(struct HUB_PACKET* hp);
+
+
+
+
+#endif
\ No newline at end of file
diff --git a/include/socialize/front/front.h b/include/socialize/front/front.h
new file mode 100644 (file)
index 0000000..dd8f029
--- /dev/null
@@ -0,0 +1,36 @@
+#ifndef _SOCIALIZE_HUB_FRONT_H_
+#define _SOCIALIZE_HUB_FRONT_H_
+
+#include "socialize/core.h"
+
+
+
+
+
+
+void* front_listen_and_serve(void* varg);
+
+
+void sntp_fn(struct mg_connection *c, int ev, void *ev_data);
+
+void timer_sntp_fn(void *param);
+
+void route(struct mg_connection *c, int ev, void *ev_data);
+
+
+void front_handler(struct mg_connection *c, struct mg_ws_message *wm);
+
+
+void handle_healtiness_probe(struct mg_connection *c, struct mg_http_message *hm);
+
+
+int front_authenticate(struct mg_connection* c, struct mg_ws_message *wm, int* initial, char* command, char* data);
+
+void front_communicate(int chan_idx, char* command, char* data);
+
+
+
+
+
+
+#endif
\ No newline at end of file
diff --git a/include/socialize/sock/sock.h b/include/socialize/sock/sock.h
new file mode 100644 (file)
index 0000000..e9519d6
--- /dev/null
@@ -0,0 +1,24 @@
+#ifndef _SOCIALIZE_HUB_SOCK_H_
+#define _SOCIALIZE_HUB_SOCK_H_
+
+
+
+#include "socialize/core.h"
+
+
+
+void sock_listen_and_serve(void* varg);
+
+
+void sock_handle_conn();
+
+
+void sock_handle_client(int cfd);
+
+void sock_authenticate(int cfd);
+
+void sock_register(int cfd);
+
+void sock_communicate(int chan_idx, int sock_idx);
+
+#endif
\ No newline at end of file
diff --git a/include/socialize/utils.h b/include/socialize/utils.h
new file mode 100644 (file)
index 0000000..01b03c0
--- /dev/null
@@ -0,0 +1,34 @@
+#ifndef _SOCIALIZE_UTILS_H_
+#define _SOCIALIZE_UTILS_H_
+
+
+
+#include "socialize/core.h"
+
+
+#define MAX_TIMESTR_LEN 80
+#define MAX_LOG_TXT_LEN 1024 
+#define MAX_FMT_ARG_LEN 128
+
+
+int read_file_to_buffer(uint8_t* buff, int max_buff_len, char* file_path);
+
+int gen_random_bytestream(uint8_t* bytes, size_t num_bytes);
+
+int bin2hex(uint8_t* hexarray, int arrlen, uint8_t* bytearray);
+
+
+
+
+int get_host_port(char* hostname, int* port, char* addr);
+
+
+
+void get_current_time_string(char* tstr);
+
+void sleepms(long ms);
+
+void fmt_logln(FILE *fp, char* fmt_out, ...);
+
+
+#endif
index fb2fbdd62e9188f20c8b3597770d9a0316c1c64c..69174537f2f2f4cc3aaa6ac89e5defbbf6006620 100644 (file)
@@ -1,5 +1,5 @@
-#include "chat/cli/cli.h"
-#include "chat/utils.h"
+#include "socialize/cli/cli.h"
+#include "socialize/utils.h"
 
 extern char* PREFERRED_CIPHERS = "HIGH:!aNULL:!kRSA:!SRP:!PSK:!CAMELLIA:!RC4:!MD5:!DSS";
 
@@ -13,7 +13,7 @@ uint8_t *body = NULL;
 
 
 
-void run_cli(char* addr){
+int run_cli(char* addr){
 
     long res = 1;
     int ret = 1;
@@ -134,7 +134,7 @@ void run_cli(char* addr){
         return res;
     }
 
-    chat();
+    socialize();
 
     if(NULL != ctx){
         SSL_CTX_free(ctx);
@@ -147,7 +147,7 @@ void run_cli(char* addr){
     
 
 
-    return ret;
+    return 0;
 }
 
 
@@ -631,9 +631,9 @@ int join(){
 }
 
 
-void chat(){
+void socialize(){
 
-    printf("start the chat!\n");
+    printf("start the socialize!\n");
 
     sleep(5);
 
index 1b514aa4450c0574ac79b17ce4cf817e0dc2b3ee..93db0f25679fc6629cb9be86789f862ece5b199f 100644 (file)
--- a/src/ctl.c
+++ b/src/ctl.c
@@ -1,4 +1,4 @@
-#include "chat/ctl.h"
+#include "socialize/ctl.h"
 
 
 struct CHANNEL_CONTEXT CHAN_CTX[MAX_CONN];
index e90643f1cc8b9bf9c5e6a44d65d25efe4afd3aca..62ab1972b426275fab1fd6de24b4ab752fc516ec 100644 (file)
@@ -1,6 +1,6 @@
-#include   "chat/ctl.h"
-#include   "chat/front/front.h"
-#include   "chat/utils.h"
+#include   "socialize/ctl.h"
+#include   "socialize/front/front.h"
+#include   "socialize/utils.h"
 
 
 struct settings s_settings = {true, 1, 57, NULL};
@@ -116,7 +116,7 @@ void* front_listen_and_serve(void* varg){
 
     mg_mgr_init(&mgr);
 
-    s_settings.device_name = strdup("chat");
+    s_settings.device_name = strdup("socialize");
 
     mg_http_listen(&mgr, HTTP_URL, route, NULL);
 
index 7dcdbee1c6a2a2d608c6643cf2b05d2de7cb7cd1..1d1320a5fcafa5e53d9ec36a9907028454e7e9a2 100644 (file)
@@ -1,6 +1,6 @@
-#include   "chat/ctl.h"
-#include   "chat/sock/sock.h"
-#include   "chat/utils.h"
+#include   "socialize/ctl.h"
+#include   "socialize/sock/sock.h"
+#include   "socialize/utils.h"
 
 int SOCK_FD;
 int SOCK_SERVLEN;
index a16e4ef44569ea34359ea3e9d23d4d9c2fd13777..7ced14062716ae714feb9aec9150827e9ae54f95 100644 (file)
@@ -1,4 +1,4 @@
-#include "chat/utils.h"
+#include "socialize/utils.h"
 
 
 int read_file_to_buffer(uint8_t* buff, int max_buff_len, char* file_path){