diff --git a/CMakeLists.txt b/CMakeLists.txt index b8405a5..37c4fbc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ project(simple-dict-server C) SET(CMAKE_BUILD_TYPE "Release") add_definitions(-DLISTEN_ON_IPV6) -# add_definitions(-DDEBUG) +add_definitions(-DDEBUG) IF(CMAKE_SIZEOF_VOID_P EQUAL 8) add_definitions("-DCPUBIT64") ELSE() diff --git a/client.c b/client.c index 4115006..e8c10c4 100644 --- a/client.c +++ b/client.c @@ -11,6 +11,7 @@ #include #include #include +#include #include "crypto.h" #if !__APPLE__ @@ -83,7 +84,7 @@ void getMessage(void *p) { } else { offset += c; #ifdef DEBUG - printf("[handle] Get %zd bytes, total: %zd.\n", c, offset); + printf("[handle] Get %d bytes, total: %d.\n", c, offset); #endif if(offset < CMDPACKET_HEAD_LEN) break; if(offset < CMDPACKET_HEAD_LEN+cp->datalen) { @@ -92,14 +93,14 @@ void getMessage(void *p) { else { offset += c; #ifdef DEBUG - printf("[handle] Get %zd bytes, total: %zd.\n", c, offset); + printf("[handle] Get %d bytes, total: %d.\n", c, offset); #endif } } c = CMDPACKET_HEAD_LEN+cp->datalen; // 暂存 packet len if(offset < c) break; #ifdef DEBUG - printf("[handle] Decrypt %zd bytes data...\n", cp->datalen); + printf("[handle] Decrypt %d bytes data...\n", (int)cp->datalen); #endif if(cmdpacket_decrypt(cp, 0, pwd)) { cp->data[cp->datalen] = 0; @@ -119,7 +120,7 @@ void getMessage(void *p) { c = 0; } else offset = 0; #ifdef DEBUG - printf("offset after analyzing packet: %zd\n", offset); + printf("offset after analyzing packet: %d\n", offset); #endif } } diff --git a/crypto.c b/crypto.c index 6144dc3..a7c8fbf 100644 --- a/crypto.c +++ b/crypto.c @@ -162,7 +162,7 @@ int cmdpacket_decrypt(CMDPACKET* p, int index, const char pwd[64]) { printf("decrypt md5: "); for(int i = 0; i < 16; i++) printf("%02x", datamd5[i]); putchar('\n'); - printf("decrypted data len: %d, data: ", tout->len); + printf("decrypted data len: %u, data: ", (unsigned int)tout->len); for(int i = 0; i < tout->len; i++) printf("%02x", tout->data[i]); putchar('\n'); #endif diff --git a/dict.c b/dict.c index 8a76491..0e7be99 100644 --- a/dict.c +++ b/dict.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include "dict.h" #include "server.h" diff --git a/server.c b/server.c index b2f3ebe..4b33a53 100644 --- a/server.c +++ b/server.c @@ -149,10 +149,10 @@ static int send_all(THREADTIMER *timer) { if(buf) { if(fread(buf, file_size, 1, fp) == 1) { #ifdef DEBUG - printf("Get dict file size: %zu\n", file_size); + printf("Get dict file size: %u\n", (unsigned int)file_size); #endif char* encbuf = raw_encrypt(buf, &file_size, timer->index, cfg->pwd); - sprintf(timer->dat, "%zu$", file_size); + sprintf(timer->dat, "%u$", (unsigned int)file_size); //printf("Get encrypted file size: %s\n", timer->dat); //FILE* fp = fopen("raw_after_enc", "wb+"); //fwrite(encbuf, file_size, 1, fp); @@ -181,11 +181,11 @@ static void init_dict_pool(FILE *fp) { DICT* dnew = (DICT*)malloc(sizeof(DICT)); memcpy(dnew, d, sizeof(DICT)); - char* digest = md5(d->key, strlen(d->key)+1); + char* digest = (char*)md5((uint8_t *)d->key, strlen(d->key)+1); char* dp = digest; int p = ((*((uint32_t*)digest))>>(8*sizeof(uint32_t)-DICTPOOLBIT))&DICTPOOLSZ; uint32_t c = 16-DICTPOOLSZ/8; - char* slot; + DICT* slot; while((slot=dict_pool[p]) && c--) { #ifdef DEBUG @@ -214,7 +214,7 @@ static int s1_get(THREADTIMER *timer) { int ch; timer->lock_type = DICT_LOCK_SH; - char* digest = md5(timer->dat, strlen(timer->dat)+1); + char* digest = (char*)md5((uint8_t*)timer->dat, strlen(timer->dat)+1); char* dp = digest; int p = ((*((uint32_t*)digest))>>(8*sizeof(uint32_t)-DICTPOOLBIT))&DICTPOOLSZ; if(!dict_pool[p]) return close_and_send(timer, "null", 4); @@ -246,7 +246,7 @@ static int s2_set(THREADTIMER *timer) { if(fp) { timer->lock_type = DICT_LOCK_EX; - char* digest = md5(timer->dat, strlen(timer->dat)+1); + char* digest = (char*)md5((uint8_t*)timer->dat, strlen(timer->dat)+1); char* dp = digest; int p = ((*((uint32_t*)digest))>>(8*sizeof(uint32_t)-DICTPOOLBIT))&DICTPOOLSZ; @@ -357,7 +357,7 @@ static int s4_del(THREADTIMER *timer) { char ret[4]; timer->lock_type = DICT_LOCK_EX; - char* digest = md5(timer->dat, strlen(timer->dat)+1); + char* digest = (char*)md5((uint8_t*)timer->dat, strlen(timer->dat)+1); char* dp = digest; int p = ((*((uint32_t*)digest))>>(8*sizeof(uint32_t)-DICTPOOLBIT))&DICTPOOLSZ; uint32_t c = 16-DICTPOOLSZ/8; @@ -395,7 +395,7 @@ static void accept_timer(void *p) { while(accept_threads[index] && !pthread_kill(accept_threads[index], 0)) { sleep(MAXWAITSEC / 4); time_t waitsec = time(NULL) - timer->touch; - printf("Wait sec: %u, max: %u\n", waitsec, MAXWAITSEC); + printf("Wait sec: %u, max: %u\n", (unsigned int)waitsec, MAXWAITSEC); if(waitsec > MAXWAITSEC) break; } puts("Call kill thread"); @@ -474,7 +474,7 @@ static void handle_accept(void *p) { numbytes = CMDPACKET_HEAD_LEN+cp->datalen; // 暂存 packet len if(offset < numbytes) break; #ifdef DEBUG - printf("[handle] Decrypt %zd bytes data...\n", cp->datalen); + printf("[handle] Decrypt %d bytes data...\n", (int)cp->datalen); #endif if(cp->cmd < 5) { if(cmdpacket_decrypt(cp, index, cfg->pwd)) {