mirror of
https://github.com/fumiama/simple-dict.git
synced 2026-06-12 14:10:50 +08:00
remove warnings
This commit is contained in:
@@ -3,7 +3,7 @@ project(simple-dict-server C)
|
|||||||
SET(CMAKE_BUILD_TYPE "Release")
|
SET(CMAKE_BUILD_TYPE "Release")
|
||||||
|
|
||||||
add_definitions(-DLISTEN_ON_IPV6)
|
add_definitions(-DLISTEN_ON_IPV6)
|
||||||
# add_definitions(-DDEBUG)
|
add_definitions(-DDEBUG)
|
||||||
IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||||
add_definitions("-DCPUBIT64")
|
add_definitions("-DCPUBIT64")
|
||||||
ELSE()
|
ELSE()
|
||||||
|
|||||||
9
client.c
9
client.c
@@ -11,6 +11,7 @@
|
|||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include "crypto.h"
|
#include "crypto.h"
|
||||||
|
|
||||||
#if !__APPLE__
|
#if !__APPLE__
|
||||||
@@ -83,7 +84,7 @@ void getMessage(void *p) {
|
|||||||
} else {
|
} else {
|
||||||
offset += c;
|
offset += c;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("[handle] Get %zd bytes, total: %zd.\n", c, offset);
|
printf("[handle] Get %d bytes, total: %d.\n", c, offset);
|
||||||
#endif
|
#endif
|
||||||
if(offset < CMDPACKET_HEAD_LEN) break;
|
if(offset < CMDPACKET_HEAD_LEN) break;
|
||||||
if(offset < CMDPACKET_HEAD_LEN+cp->datalen) {
|
if(offset < CMDPACKET_HEAD_LEN+cp->datalen) {
|
||||||
@@ -92,14 +93,14 @@ void getMessage(void *p) {
|
|||||||
else {
|
else {
|
||||||
offset += c;
|
offset += c;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("[handle] Get %zd bytes, total: %zd.\n", c, offset);
|
printf("[handle] Get %d bytes, total: %d.\n", c, offset);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c = CMDPACKET_HEAD_LEN+cp->datalen; // 暂存 packet len
|
c = CMDPACKET_HEAD_LEN+cp->datalen; // 暂存 packet len
|
||||||
if(offset < c) break;
|
if(offset < c) break;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("[handle] Decrypt %zd bytes data...\n", cp->datalen);
|
printf("[handle] Decrypt %d bytes data...\n", (int)cp->datalen);
|
||||||
#endif
|
#endif
|
||||||
if(cmdpacket_decrypt(cp, 0, pwd)) {
|
if(cmdpacket_decrypt(cp, 0, pwd)) {
|
||||||
cp->data[cp->datalen] = 0;
|
cp->data[cp->datalen] = 0;
|
||||||
@@ -119,7 +120,7 @@ void getMessage(void *p) {
|
|||||||
c = 0;
|
c = 0;
|
||||||
} else offset = 0;
|
} else offset = 0;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("offset after analyzing packet: %zd\n", offset);
|
printf("offset after analyzing packet: %d\n", offset);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2
crypto.c
2
crypto.c
@@ -162,7 +162,7 @@ int cmdpacket_decrypt(CMDPACKET* p, int index, const char pwd[64]) {
|
|||||||
printf("decrypt md5: ");
|
printf("decrypt md5: ");
|
||||||
for(int i = 0; i < 16; i++) printf("%02x", datamd5[i]);
|
for(int i = 0; i < 16; i++) printf("%02x", datamd5[i]);
|
||||||
putchar('\n');
|
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]);
|
for(int i = 0; i < tout->len; i++) printf("%02x", tout->data[i]);
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
1
dict.c
1
dict.c
@@ -1,6 +1,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include <simplecrypto.h>
|
#include <simplecrypto.h>
|
||||||
#include "dict.h"
|
#include "dict.h"
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
|
|||||||
18
server.c
18
server.c
@@ -149,10 +149,10 @@ static int send_all(THREADTIMER *timer) {
|
|||||||
if(buf) {
|
if(buf) {
|
||||||
if(fread(buf, file_size, 1, fp) == 1) {
|
if(fread(buf, file_size, 1, fp) == 1) {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("Get dict file size: %zu\n", file_size);
|
printf("Get dict file size: %u\n", (unsigned int)file_size);
|
||||||
#endif
|
#endif
|
||||||
char* encbuf = raw_encrypt(buf, &file_size, timer->index, cfg->pwd);
|
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);
|
//printf("Get encrypted file size: %s\n", timer->dat);
|
||||||
//FILE* fp = fopen("raw_after_enc", "wb+");
|
//FILE* fp = fopen("raw_after_enc", "wb+");
|
||||||
//fwrite(encbuf, file_size, 1, fp);
|
//fwrite(encbuf, file_size, 1, fp);
|
||||||
@@ -181,11 +181,11 @@ static void init_dict_pool(FILE *fp) {
|
|||||||
DICT* dnew = (DICT*)malloc(sizeof(DICT));
|
DICT* dnew = (DICT*)malloc(sizeof(DICT));
|
||||||
memcpy(dnew, d, 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;
|
char* dp = digest;
|
||||||
int p = ((*((uint32_t*)digest))>>(8*sizeof(uint32_t)-DICTPOOLBIT))&DICTPOOLSZ;
|
int p = ((*((uint32_t*)digest))>>(8*sizeof(uint32_t)-DICTPOOLBIT))&DICTPOOLSZ;
|
||||||
uint32_t c = 16-DICTPOOLSZ/8;
|
uint32_t c = 16-DICTPOOLSZ/8;
|
||||||
char* slot;
|
DICT* slot;
|
||||||
|
|
||||||
while((slot=dict_pool[p]) && c--) {
|
while((slot=dict_pool[p]) && c--) {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@@ -214,7 +214,7 @@ static int s1_get(THREADTIMER *timer) {
|
|||||||
int ch;
|
int ch;
|
||||||
timer->lock_type = DICT_LOCK_SH;
|
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;
|
char* dp = digest;
|
||||||
int p = ((*((uint32_t*)digest))>>(8*sizeof(uint32_t)-DICTPOOLBIT))&DICTPOOLSZ;
|
int p = ((*((uint32_t*)digest))>>(8*sizeof(uint32_t)-DICTPOOLBIT))&DICTPOOLSZ;
|
||||||
if(!dict_pool[p]) return close_and_send(timer, "null", 4);
|
if(!dict_pool[p]) return close_and_send(timer, "null", 4);
|
||||||
@@ -246,7 +246,7 @@ static int s2_set(THREADTIMER *timer) {
|
|||||||
if(fp) {
|
if(fp) {
|
||||||
timer->lock_type = DICT_LOCK_EX;
|
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;
|
char* dp = digest;
|
||||||
int p = ((*((uint32_t*)digest))>>(8*sizeof(uint32_t)-DICTPOOLBIT))&DICTPOOLSZ;
|
int p = ((*((uint32_t*)digest))>>(8*sizeof(uint32_t)-DICTPOOLBIT))&DICTPOOLSZ;
|
||||||
|
|
||||||
@@ -357,7 +357,7 @@ static int s4_del(THREADTIMER *timer) {
|
|||||||
char ret[4];
|
char ret[4];
|
||||||
timer->lock_type = DICT_LOCK_EX;
|
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;
|
char* dp = digest;
|
||||||
int p = ((*((uint32_t*)digest))>>(8*sizeof(uint32_t)-DICTPOOLBIT))&DICTPOOLSZ;
|
int p = ((*((uint32_t*)digest))>>(8*sizeof(uint32_t)-DICTPOOLBIT))&DICTPOOLSZ;
|
||||||
uint32_t c = 16-DICTPOOLSZ/8;
|
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)) {
|
while(accept_threads[index] && !pthread_kill(accept_threads[index], 0)) {
|
||||||
sleep(MAXWAITSEC / 4);
|
sleep(MAXWAITSEC / 4);
|
||||||
time_t waitsec = time(NULL) - timer->touch;
|
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;
|
if(waitsec > MAXWAITSEC) break;
|
||||||
}
|
}
|
||||||
puts("Call kill thread");
|
puts("Call kill thread");
|
||||||
@@ -474,7 +474,7 @@ static void handle_accept(void *p) {
|
|||||||
numbytes = CMDPACKET_HEAD_LEN+cp->datalen; // 暂存 packet len
|
numbytes = CMDPACKET_HEAD_LEN+cp->datalen; // 暂存 packet len
|
||||||
if(offset < numbytes) break;
|
if(offset < numbytes) break;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("[handle] Decrypt %zd bytes data...\n", cp->datalen);
|
printf("[handle] Decrypt %d bytes data...\n", (int)cp->datalen);
|
||||||
#endif
|
#endif
|
||||||
if(cp->cmd < 5) {
|
if(cp->cmd < 5) {
|
||||||
if(cmdpacket_decrypt(cp, index, cfg->pwd)) {
|
if(cmdpacket_decrypt(cp, index, cfg->pwd)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user