From 1428440cfffe73e75320dde46d8afb3afe9fced5 Mon Sep 17 00:00:00 2001 From: Patrick Hornecker Date: Thu, 11 Feb 2010 18:06:06 +0100 Subject: tex source --- friendfinder/sender.c | 116 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 83 insertions(+), 33 deletions(-) (limited to 'friendfinder/sender.c') diff --git a/friendfinder/sender.c b/friendfinder/sender.c index 31d5b0d..edb5b61 100644 --- a/friendfinder/sender.c +++ b/friendfinder/sender.c @@ -59,14 +59,67 @@ void set_sender_position(double lat, double lon) { own_lat = lat; own_lon = lon; + printf("%f || %f \n", lat, lon); +} + +struct sender_data* prepare_position(const unsigned char* lat, const unsigned char* lon) +{ + struct sender_data *pos = (struct sender_data*) malloc(sizeof(struct sender_data)); + + pos->lat_first = (char*) malloc(sizeof(char) * 5); + pos->lat_second = (char*) malloc(sizeof(char) * 5); + + pos->lon_first = (char*) malloc(sizeof(char) * 5); + pos->lon_second = (char*) malloc(sizeof(char) * 5); + + for (int i = 0; i < 9; i++) + { + if (i < 5) + *(pos->lat_first + i) = *(lat + i); + + if (i >= 5 && i < 9) + *(pos->lat_second + i - 5) = *(lat + i); + } + +//TODO: variable position mit strlen einfügen und fehler fixen das manchmal nichts drangehängt wird + pos->lat_first[5] = 'a'; + pos->lat_first[6] = '\0'; + + pos->lat_second[4] = 'b'; + pos->lat_second[5] = '\0'; + + + for (int j = 0; j < 9; j++) + { + if (j < 5) + *(pos->lon_first + j) = *(lon + j); + + if (j >=5 && j < 9) + *(pos->lon_second + j - 5) = *(lon + j); + } + +//TODO: variable position mit strlen einfügen + pos->lon_first[5] = 'c'; + pos->lon_first[6] = '\0'; + + pos->lon_second[4] = 'd'; + pos->lon_second[5] = '\0'; + + + printf(" %s %s \n", pos->lat_first, pos->lat_second); + printf(" %s %s \n", pos->lon_first, pos->lon_second); + + + return pos; } void send_position(irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count) { -// unsigned char crypted_lat[64]; - unsigned char *crypted_lat = (char*) malloc(sizeof(char) * 9); -// unsigned char crypted_lon[64]; - unsigned char *crypted_lon = (char*) malloc(sizeof(char) * 9); + unsigned char *crypted_lat_first = (char*) malloc(sizeof(char) * 8); + unsigned char *crypted_lat_second = (char*) malloc(sizeof(char) * 8); + + unsigned char *crypted_lon_first = (char*) malloc(sizeof(char) * 8); + unsigned char *crypted_lon_second = (char*) malloc(sizeof(char) * 8); if (first_send == 0) { @@ -80,43 +133,36 @@ void send_position(irc_session_t * session, const char * event, const char * ori irc_cmd_msg(session, "#test", "connected"); first_send = 1; - - //free(key); } -// unsigned char lat_char[16]; - unsigned char *lat_char = (char*) malloc(sizeof(char) * 9); + const unsigned char *lat_char = (char*) malloc(sizeof(char) * 9); sprintf(lat_char, "%f", own_lat); -// unsigned char lon_char[16]; - unsigned char *lon_char = (char*) malloc(sizeof(char) * 9); + const unsigned char *lon_char = (char*) malloc(sizeof(char) * 9); sprintf(lon_char, "%f", own_lon); - BF_ecb_encrypt(lat_char, crypted_lat, &key, BF_ENCRYPT); - BF_ecb_encrypt(lon_char, crypted_lon, &key, BF_ENCRYPT); + struct sender_data *pos = (struct sender_data*) malloc(sizeof(struct sender_data)); + + pos = prepare_position(lat_char, lon_char); + + BF_ecb_encrypt(pos->lat_first, crypted_lat_first, &key, BF_ENCRYPT); + BF_ecb_encrypt(pos->lat_second, crypted_lat_second, &key, BF_ENCRYPT); + + BF_ecb_encrypt(pos->lon_first, crypted_lon_first, &key, BF_ENCRYPT); + BF_ecb_encrypt(pos->lon_second, crypted_lon_second, &key, BF_ENCRYPT); - int _x = NULL; - _x = irc_cmd_msg(session, "#test", crypted_lat); - int _y = NULL; - _y = irc_cmd_msg(session, "#test", crypted_lon); + irc_cmd_msg(session, "#test", crypted_lat_first); + sleep(1); + irc_cmd_msg(session, "#test", crypted_lat_second); + sleep(1); + + irc_cmd_msg(session, "#test", crypted_lon_first); + sleep(1); + irc_cmd_msg(session, "#test", crypted_lon_second); + sleep(1); //increase counter variable, which counts number of send positions! msg_count = msg_count + 2; - - if (_x == 0 && _y == 0) - { - // printf("SENDER: send succesfull %s %s \n", lat_char, lon_char); - } - - if (_y != 0) - { - printf("SENDER: error code due sending: %i \n", _y); - } - - if (_x != 0) - { - printf("SENDER: error code due sending: %i \n", _x); - } if(resend == 1) { @@ -127,8 +173,12 @@ void send_position(irc_session_t * session, const char * event, const char * ori free(lat_char); free(lon_char); - free(crypted_lat); - free(crypted_lon); + + free(crypted_lat_first); + free(crypted_lat_second); + + free(crypted_lon_first); + free(crypted_lon_second); } void get_aknowledge(irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count) -- cgit v1.2.3-55-g7522