summaryrefslogtreecommitdiffstats
path: root/friendfinder/sender.c
diff options
context:
space:
mode:
Diffstat (limited to 'friendfinder/sender.c')
-rw-r--r--friendfinder/sender.c87
1 files changed, 49 insertions, 38 deletions
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);
}
}