From aa41b2ba55d825fe203c50542ecd767917224612 Mon Sep 17 00:00:00 2001 From: Patrick Hornecker Date: Fri, 5 Mar 2010 18:21:34 +0100 Subject: tex source and bug fixes --- friendfinder/crypto.c | 3 +- friendfinder/draw_user.c | 3 ++ friendfinder/e_smart_map.c | 1 + friendfinder/handler.c | 14 +++++- friendfinder/receiver.c | 107 ++++++++++++++++++++++++++------------------- friendfinder/sender.c | 87 ++++++++++++++++++++---------------- 6 files changed, 131 insertions(+), 84 deletions(-) (limited to 'friendfinder') diff --git a/friendfinder/crypto.c b/friendfinder/crypto.c index 854ac09..d97144c 100644 --- a/friendfinder/crypto.c +++ b/friendfinder/crypto.c @@ -81,7 +81,8 @@ int to_base64(char *in, int inlen, char *out, int maxlen) return -1; } - memcpy(out, bptr->data, bptr->length-1); + //memcpy(out, bptr->data, bptr->length-1); + memmove(out, bptr->data, bptr->length-1); // XXX: we don't teminate b64 buffer as string // XXX: user gets length so wtf ;) out[bptr->length-1] = '\0'; diff --git a/friendfinder/draw_user.c b/friendfinder/draw_user.c index f03fb06..2ed13f7 100644 --- a/friendfinder/draw_user.c +++ b/friendfinder/draw_user.c @@ -58,6 +58,9 @@ void draw_user(struct position *pos) } } + free(pos->lat); + free(pos->lon); + free(pos->nick); free(pos); } diff --git a/friendfinder/e_smart_map.c b/friendfinder/e_smart_map.c index 4e9f070..4a35892 100644 --- a/friendfinder/e_smart_map.c +++ b/friendfinder/e_smart_map.c @@ -60,6 +60,7 @@ static struct bubble *create_text_bubble(struct smart_map *smart, char *info, ch evas_object_size_hint_align_set(bubble->object.obj, 0.0, 0.0); bubble->av = elm_entry_add(smart->win); + printf("%s \n", text); elm_entry_entry_set(bubble->av, text); elm_entry_line_wrap_set(bubble->av, 0); evas_object_size_hint_weight_set(bubble->av, 1.0, 1.0); diff --git a/friendfinder/handler.c b/friendfinder/handler.c index 88c2ca3..b8dea19 100644 --- a/friendfinder/handler.c +++ b/friendfinder/handler.c @@ -33,9 +33,15 @@ void init_receiver_thread(char *from) { if (receiver_start == 0) { + char* receiver_from = (char*) malloc(sizeof(from)); + memcpy(receiver_from, from, strlen(from)); + if (pthread_create(&receiver_thread, NULL, receiver_main, (void*) from) == 0) + { + pthread_detach(receiver_thread); printf("HANDLER: receiver thread init...\n"); - + } + else { printf("HANDLER: receiver thread init failure...\n"); @@ -51,8 +57,14 @@ void init_sender_thread(char *from) { if (sender_start == 0) { + char* sender_from = (char*) malloc(sizeof(from)); + memcpy(sender_from, from, strlen(from)); + if (pthread_create(&sender_thread, NULL, sender_main, (void*) from) == 0) + { + pthread_detach(sender_thread); printf("HANDLER: sender thread init...\n"); + } else { diff --git a/friendfinder/receiver.c b/friendfinder/receiver.c index 73a0409..8bf24d3 100644 --- a/friendfinder/receiver.c +++ b/friendfinder/receiver.c @@ -10,7 +10,7 @@ #include "receiver.h" #include "cryptossl.h" -static irc_session_t *session; +static irc_session_t *session_receiver; irc_callbacks_t callbacks; char *username, *own_nickname, *sender_name; @@ -24,6 +24,13 @@ int s_sender_size; BF_KEY key; +int count_ack = 0; +int is_init = 0; +char* sender_base64; + +#define CRYPT_LENGTH 10 +#define BASE64_LENGTH 60 + void receiver_set_ip(char *_ip) { receiver_server_ip = _ip; @@ -38,8 +45,8 @@ int init_connection_receiver(char* server_ip, char* user) { printf("RECEIVER: initialising connection...\n"); - session = irc_create_session(&callbacks); - int con = irc_connect(session, server_ip, 6666, NULL, user, "receiver", "receiver"); + session_receiver = irc_create_session(&callbacks); + int con = irc_connect(session_receiver, server_ip, 6666, NULL, user, "receiver", "receiver"); if (con != 0) { printf("RECEIVER: connection error-code: %i \n", con); @@ -47,7 +54,7 @@ int init_connection_receiver(char* server_ip, char* user) return 1; } - if (irc_is_connected(session) == 1) + if (irc_is_connected(session_receiver) == 1) { printf("RECEIVER: connected...\n"); @@ -58,8 +65,8 @@ int init_connection_receiver(char* server_ip, char* user) void disconnect_receiver() { //irc_destroy_session(session); - irc_disconnect(session); - irc_destroy_session(session); + irc_disconnect(session_receiver); + irc_destroy_session(session_receiver); for (int i = 0; i < s_sender_size; i++) { @@ -83,7 +90,6 @@ void disconnect_receiver() free(s_sender[i]->lon_second); free(s_sender[i]); - } free(s_sender); @@ -227,24 +233,33 @@ void repair_position(struct sender *_sender, unsigned char *decrypted) void dump_data(char* lat, char* lon, char* nick) { struct position *pos = (struct position*) malloc(sizeof(struct position)); - pos->lat = lat; - pos->lon = lon; - pos->nick = nick; + pos->lat = (char*) malloc(strlen(lat) + 1); + pos->lon = (char*) malloc(strlen(lon) + 1); + pos->nick = (char*) malloc(strlen(nick) + 1); + + memcpy(pos->lat, lat, strlen(lat)); + memcpy(pos->lon, lon, strlen(lon)); + memcpy(pos->nick, nick, strlen(nick)); + + pos->lat[strlen(lat)] = '\0'; + pos->lon[strlen(lon)] = '\0'; + pos->nick[strlen(nick)] = '\0'; + draw_user(pos); } -void get_position(irc_session_t * session, const char * event, const char * origin, const unsigned char ** params, unsigned int count) +void get_position(irc_session_t * session_receiver, const char * event, const char * origin, const unsigned char ** params, unsigned int count) { unsigned char *decrypted; unsigned char *encrypted_base64; char *sender_org = (char*) malloc(username_length + 1); - char *own_sender_nickname = (char*) malloc(username_length + 3); + char *own_sender_nickname = (char*) malloc(strlen(own_nickname) + 3); sender_name = (char*) malloc(sizeof(char) * 50); memcpy(own_sender_nickname, own_nickname, strlen(own_nickname)); - strcat(own_sender_nickname, "_s"); + strcat(own_sender_nickname, "_s\0"); irc_target_get_nick(origin, sender_name, sizeof(sender_name)); strncpy(sender_org, sender_name, username_length); @@ -256,10 +271,10 @@ void get_position(irc_session_t * session, const char * event, const char * orig if (s_sender[pos]->lat_set == 0) { - encrypted_base64 = (char*) malloc(sizeof(char) *60); - decrypted = (char*) malloc(sizeof(char) * 8); + encrypted_base64 = (char*) malloc(sizeof(char) * BASE64_LENGTH); + decrypted = (char*) malloc(sizeof(char) * 9); - from_base64(params[1], strlen(params[1]), encrypted_base64, 60); + from_base64(params[1], strlen(params[1]), encrypted_base64, BASE64_LENGTH); BF_ecb_encrypt(encrypted_base64, decrypted, &key, BF_DECRYPT); decrypted[strlen(decrypted)] = '\0'; @@ -274,10 +289,10 @@ void get_position(irc_session_t * session, const char * event, const char * orig else if (s_sender[pos]->lon_set == 0) { - encrypted_base64 = (char*) malloc(sizeof(char) * 60); - decrypted = (char*) malloc(sizeof(char) * 8); + encrypted_base64 = (char*) malloc(sizeof(char) * BASE64_LENGTH); + decrypted = (char*) malloc(sizeof(char) * 9); - from_base64(params[1], strlen(params[1]), encrypted_base64, 60); + from_base64(params[1], strlen(params[1]), encrypted_base64, BASE64_LENGTH); BF_ecb_encrypt(encrypted_base64, decrypted, &key, BF_DECRYPT); decrypted[strlen(decrypted)] = '\0'; @@ -324,22 +339,21 @@ void get_position(irc_session_t * session, const char * event, const char * orig } } -int count_ack = 0; -int is_init = 0; -char* sender_base64; void send_acknowledgement(char *sender) { if (is_init == 0 && count_ack == 0) { - sender_base64 = (char*) malloc(sizeof(char) * 60); - char* sender_crypted = (char*) malloc(sizeof(char) * 30); + sender_base64 = (char*) malloc(sizeof(char) * BASE64_LENGTH); + char* sender_crypted = (char*) malloc(sizeof(char) * CRYPT_LENGTH); BF_ecb_encrypt(sender, sender_crypted, &key, BF_ENCRYPT); - - to_base64(sender_crypted, strlen(sender_crypted), sender_base64, 60); - irc_cmd_msg(session, "#test", sender_base64); + sender_crypted[strlen(sender_crypted)] = '\0'; + + to_base64(sender_crypted, CRYPT_LENGTH, sender_base64, BASE64_LENGTH); + + irc_cmd_msg(session_receiver, "#test", sender_base64); free(sender_crypted); is_init = 1; @@ -350,7 +364,7 @@ void send_acknowledgement(char *sender) if (is_init == 1 && count_ack < 3) { - irc_cmd_msg(session, "#test", sender_base64); + irc_cmd_msg(session_receiver, "#test", sender_base64); count_ack++; return; @@ -358,7 +372,7 @@ void send_acknowledgement(char *sender) if (is_init == 1 && count_ack == 3) { - irc_cmd_msg(session, "#test", sender_base64); + irc_cmd_msg(session_receiver, "#test", sender_base64); count_ack = 0; is_init = 0; @@ -372,10 +386,10 @@ int check_message(char *msg, char *sender) { if (sender[strlen(sender) - 1] == 's') { - char* ack_base64 = (char*) malloc(sizeof(char) * 60); + char* ack_base64 = (char*) malloc(sizeof(char) * BASE64_LENGTH); char* ack_decrypted = (char*) malloc(sizeof(char) * 20); - from_base64(msg, strlen(msg), ack_base64, 60); + from_base64(msg, strlen(msg), ack_base64, BASE64_LENGTH); BF_ecb_encrypt(ack_base64, ack_decrypted, &key, BF_DECRYPT); if (strcmp(sender, ack_decrypted) == 0) @@ -398,7 +412,7 @@ int check_message(char *msg, char *sender) } } -void on_connect_receiver(irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count) +void on_connect_receiver(irc_session_t * session_receiver, const char * event, const char * origin, const char ** params, unsigned int count) { printf("RECEIVER: on_connect_receiver \n"); @@ -410,8 +424,8 @@ void on_connect_receiver(irc_session_t * session, const char * event, const char init_sender_struct(_sender_count); - irc_cmd_join(session, "#test", NULL); -// irc_cmd_msg(session, "#test", "connected"); + irc_cmd_join(session_receiver, "#test", NULL); +// irc_cmd_msg(session_receiver, "#test", "connected"); free(keyd->key); free(keyd); @@ -423,26 +437,31 @@ void receiver_main(void *user) callbacks.event_channel = get_position; callbacks.event_connect = on_connect_receiver; - - username = (char*) malloc(sizeof(char) * sizeof(user)); - own_nickname = (char*) malloc(sizeof(char) * sizeof(user)); - memcpy(username, user, sizeof(user)); - memcpy(own_nickname, user, sizeof(user)); - - printf("%s \n", username); + char* _user = (char*) user; + int len = strlen(_user) + 1; + + username = (char*) malloc(len + 2); + own_nickname = (char*) malloc(len + 2); + + memcpy(username, user, len); + memcpy(own_nickname, user, len); + + own_nickname[strlen(own_nickname)] = '\0'; username_length = strlen(username); if (receiver_server_ip != NULL && user != NULL) { - strcat(username, "_r"); - printf("%s \n", username); + strcat(username, "_r\0"); + + printf("%s %s \n", username, own_nickname); + if (init_connection_receiver(receiver_server_ip, username) == 0) { printf("RECEIVER: connection succesfull...\n"); - irc_run(session); + irc_run(session_receiver); } } diff --git a/friendfinder/sender.c b/friendfinder/sender.c index a81acc0..012df12 100644 --- a/friendfinder/sender.c +++ b/friendfinder/sender.c @@ -9,7 +9,7 @@ #include "read_file.h" #include "cryptossl.h" -static irc_session_t *session; +static irc_session_t *session_sender; irc_callbacks_t callbacks; int lat_first_set = 0; @@ -25,6 +25,9 @@ int first_send = 0; BF_KEY key; +#define CRYPT_LENGTH 10 +#define BASE64_LENGTH 60 + void sender_set_ip(char *_sender_server_ip) { sender_server_ip = _sender_server_ip; @@ -34,10 +37,10 @@ int init_connection_sender(char* server_ip, char* user) { printf("SENDER: initialising connection...\n"); - session = irc_create_session(&callbacks); - int con = irc_connect(session, server_ip, 6669, NULL, user, user, user); + session_sender = irc_create_session(&callbacks); + int con = irc_connect(session_sender, server_ip, 6669, NULL, user, user, user); - if (irc_is_connected(session) == 1) + if (irc_is_connected(session_sender) == 1) { printf("SENDER: connected... \n"); return 0; @@ -52,8 +55,8 @@ int init_connection_sender(char* server_ip, char* user) void disconnect_sender() { - irc_disconnect(session); - irc_destroy_session(session); + irc_disconnect(session_sender); + irc_destroy_session(session_sender); printf("SENDER: disconnected...\n"); } @@ -124,17 +127,17 @@ struct sender_data* prepare_position(const unsigned char* lat, const unsigned ch return pos; } -void send_position(irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count) +void send_position(irc_session_t *session_sender, const char * event, const char * origin, const char ** params, unsigned int count) { - unsigned char *crypted_lat_first = (char*) malloc(sizeof(char) * 9); - unsigned char *crypted_lat_second = (char*) malloc(sizeof(char) * 9); - unsigned char *crypted_lon_first = (char*) malloc(sizeof(char) * 9); - unsigned char *crypted_lon_second = (char*) malloc(sizeof(char) * 9); + unsigned char *crypted_lat_first = (char*) malloc(sizeof(char) * CRYPT_LENGTH); + unsigned char *crypted_lat_second = (char*) malloc(sizeof(char) * CRYPT_LENGTH); + unsigned char *crypted_lon_first = (char*) malloc(sizeof(char) * CRYPT_LENGTH); + unsigned char *crypted_lon_second = (char*) malloc(sizeof(char) * CRYPT_LENGTH); - unsigned char *crypted_lat_first_base64 = (char*) malloc(sizeof(char) * 60); - unsigned char *crypted_lat_second_base64 = (char*) malloc(sizeof(char) * 60); - unsigned char *crypted_lon_first_base64 = (char*) malloc(sizeof(char) * 60); - unsigned char *crypted_lon_second_base64 = (char*) malloc(sizeof(char) * 60); + unsigned char *crypted_lat_first_base64 = (char*) malloc(sizeof(char) * BASE64_LENGTH); + unsigned char *crypted_lat_second_base64 = (char*) malloc(sizeof(char) * BASE64_LENGTH); + unsigned char *crypted_lon_first_base64 = (char*) malloc(sizeof(char) * BASE64_LENGTH); + unsigned char *crypted_lon_second_base64 = (char*) malloc(sizeof(char) * BASE64_LENGTH); @@ -146,8 +149,8 @@ void send_position(irc_session_t * session, const char * event, const char * ori BF_set_key(&key, keyd->key_length, keyd->key); - irc_cmd_join(session, "#test", NULL); - irc_cmd_msg(session, "#test", "connected"); + irc_cmd_join(session_sender, "#test", NULL); + irc_cmd_msg(session_sender, "#test", "connected"); first_send = 1; @@ -170,26 +173,31 @@ void send_position(irc_session_t * session, const char * event, const char * ori BF_ecb_encrypt(pos->lon_first, crypted_lon_first, &key, BF_ENCRYPT); BF_ecb_encrypt(pos->lon_second, crypted_lon_second, &key, BF_ENCRYPT); + +/* crypted_lat_first[CRYPT_LENGTH] = '\0'; + crypted_lat_second[CRYPT_LENGTH] = '\0'; + crypted_lon_first[CRYPT_LENGTH] = '\0'; + crypted_lon_second[CRYPT_LENGTH] = '\0';*/ - to_base64(crypted_lat_first, strlen(crypted_lat_first), crypted_lat_first_base64, 60); - to_base64(crypted_lat_second, strlen(crypted_lat_second), crypted_lat_second_base64, 60); + to_base64(crypted_lat_first, CRYPT_LENGTH, crypted_lat_first_base64, BASE64_LENGTH); + to_base64(crypted_lat_second, CRYPT_LENGTH, crypted_lat_second_base64, BASE64_LENGTH); - to_base64(crypted_lon_first, strlen(crypted_lon_first), crypted_lon_first_base64, 60); - to_base64(crypted_lon_second, strlen(crypted_lon_second), crypted_lon_second_base64, 60); + to_base64(crypted_lon_first, CRYPT_LENGTH, crypted_lon_first_base64, BASE64_LENGTH); + to_base64(crypted_lon_second, CRYPT_LENGTH, crypted_lon_second_base64, BASE64_LENGTH); - irc_cmd_msg(session, "#test", crypted_lat_first_base64); + irc_cmd_msg(session_sender, "#test", crypted_lat_first_base64); - irc_cmd_msg(session, "#test", crypted_lat_second_base64); + irc_cmd_msg(session_sender, "#test", crypted_lat_second_base64); - irc_cmd_msg(session, "#test", crypted_lon_first_base64); + irc_cmd_msg(session_sender, "#test", crypted_lon_first_base64); - irc_cmd_msg(session, "#test", crypted_lon_second_base64); + irc_cmd_msg(session_sender, "#test", crypted_lon_second_base64); msg_count = msg_count + 4; if (resend == 1) { - get_acknowledge(session, event, origin, params, count); + get_acknowledge(session_sender, event, origin, params, count); resend = 0; ack_count = 0; } @@ -210,18 +218,18 @@ void send_position(irc_session_t * session, const char * event, const char * ori free(pos); } -void get_acknowledge(irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count) +void get_acknowledge(irc_session_t * session_sender, const char * event, const char * origin, const char ** params, unsigned int count) { char* ack = (char*) malloc(sizeof(char) * 20); - char* ack_base64 = (char*) malloc(sizeof(char) * 60); + char* ack_base64 = (char*) malloc(sizeof(char) * BASE64_LENGTH); char *sender_name = (char*) malloc(sizeof(char) * 50); - char *own_receiver_name = (char*) malloc(sizeof(username) + 2); + char *own_receiver_name = (char*) malloc(strlen(username) + 3); memcpy(own_receiver_name, username, strlen(username)); - strcat(own_receiver_name, "_r"); + strcat(own_receiver_name, "_r\0"); - from_base64(params[1], strlen(params[1]), ack_base64, 60); + from_base64(params[1], strlen(params[1]), ack_base64, BASE64_LENGTH); BF_ecb_encrypt(ack_base64, ack, &key, BF_DECRYPT); @@ -242,7 +250,7 @@ void get_acknowledge(irc_session_t * session, const char * event, const char * o sleep(3); - send_position(session, event, origin, params, count); + send_position(session_sender, event, origin, params, count); } } } @@ -253,21 +261,24 @@ void sender_main(void *user) callbacks.event_connect = send_position; callbacks.event_channel = get_acknowledge; + + char* _user = (char*) user; + int len = strlen(_user) + 1; - username = (char*) malloc(sizeof(char) * sizeof(user)); - suffix_username = (char*) malloc(sizeof(char) * sizeof(user)); + username = (char*) malloc(len + 2); + suffix_username = (char*) malloc(len + 2); - memcpy(username, user, strlen(user)); - suffix_username = (char*) user; + memcpy(username, user, len); + memcpy(suffix_username, user, len); if (sender_server_ip != NULL) { strcat(suffix_username, "_s"); - printf("%s \n", suffix_username); + if (init_connection_sender(sender_server_ip, suffix_username) == 0) { printf("SENDER: connection succesfull...\n"); - irc_run(session); + irc_run(session_sender); } } -- cgit v1.2.3-55-g7522