summaryrefslogtreecommitdiffstats
path: root/friendfinder
diff options
context:
space:
mode:
authorPatrick Hornecker2010-02-11 18:06:06 +0100
committerPatrick Hornecker2010-02-11 18:06:06 +0100
commit1428440cfffe73e75320dde46d8afb3afe9fced5 (patch)
tree41e91c24b50e7227fe6d3fe6b0e1e768de5f55f5 /friendfinder
parentkey bugs... (diff)
downloadfriendfinder-1428440cfffe73e75320dde46d8afb3afe9fced5.tar.gz
friendfinder-1428440cfffe73e75320dde46d8afb3afe9fced5.tar.xz
friendfinder-1428440cfffe73e75320dde46d8afb3afe9fced5.zip
tex source
Diffstat (limited to 'friendfinder')
-rwxr-xr-xfriendfinder/guibin201737 -> 202829 bytes
-rw-r--r--friendfinder/msg_sender.c2
-rw-r--r--friendfinder/read_file.c5
-rw-r--r--friendfinder/receiver.c92
-rw-r--r--friendfinder/receiver.h11
-rw-r--r--friendfinder/sender.c116
-rw-r--r--friendfinder/sender.h8
7 files changed, 187 insertions, 47 deletions
diff --git a/friendfinder/gui b/friendfinder/gui
index 5a5630c..c4046d5 100755
--- a/friendfinder/gui
+++ b/friendfinder/gui
Binary files differ
diff --git a/friendfinder/msg_sender.c b/friendfinder/msg_sender.c
index 6f722c7..05d0010 100644
--- a/friendfinder/msg_sender.c
+++ b/friendfinder/msg_sender.c
@@ -192,7 +192,7 @@ void on_connect(irc_session_t * session, const char * event, const char * origin
irc_cmd_join(session, "#msg", NULL);
irc_cmd_msg(session, "#msg", "connected");
- printf("keyd->key %s :: keyd->key_length %i \n", keyd->key, keyd->key_length);
+// printf("keyd->key %s :: keyd->key_length %i \n", keyd->key, keyd->key_length);
BF_set_key(&key, keyd->key_length - 1, keyd->key);
}
diff --git a/friendfinder/read_file.c b/friendfinder/read_file.c
index 1ed9ec4..8cd0bd4 100644
--- a/friendfinder/read_file.c
+++ b/friendfinder/read_file.c
@@ -35,8 +35,9 @@ struct key_data* read_key()
keyd->key_length = i - 1;
fclose(fr);
-// printf("READ_KEY: %s \n", key);
- printf("keyd->key %s :: keyd->key_length %i \n", keyd->key, keyd->key_length);
+
+ //printf("keyd->key %s :: keyd->key_length %i \n", keyd->key, keyd->key_length);
+
return keyd;
}
/*
diff --git a/friendfinder/receiver.c b/friendfinder/receiver.c
index 8d27a89..e1ab333 100644
--- a/friendfinder/receiver.c
+++ b/friendfinder/receiver.c
@@ -7,6 +7,7 @@
#include "openssl/blowfish.h"
#include "draw_user.h"
#include "read_file.h"
+#include "receiver.h"
static irc_session_t *session;
irc_callbacks_t callbacks;
@@ -74,6 +75,59 @@ int get_sender_array_pos(char* nick)
}
}
+void repair_position(struct sender *_sender, unsigned char *decrypted)
+{
+ if (decrypted[5] == 'a')
+ {
+ _sender->lat_first = decrypted;
+ _sender->lat_first[5] = '\0';
+ _sender->lat_first_set = 1;
+
+ // return;
+ }
+
+ if (decrypted[4] == 'b')
+ {
+ _sender->lat_second = decrypted;
+ _sender->lat_second[4] = '\0';
+ _sender->lat_second_set = 1;
+
+ // return;
+ }
+
+ if (decrypted[5] == 'c')
+ {
+ _sender->lon_first = decrypted;
+ _sender->lon_first[5] = '\0';
+ _sender->lon_first_set = 1;
+
+ // return;
+ }
+
+ if (decrypted[4] == 'd')
+ {
+ _sender->lon_second = decrypted;
+ _sender->lon_second[4] = '\0';
+ _sender->lon_second_set = 1;
+
+ // return;
+ }
+
+ if (_sender->lat_first_set == 1 && _sender->lat_second_set == 1)
+ {
+ _sender->lat = _sender->lat_first;
+ strcat(_sender->lat, _sender->lat_second);
+ _sender->lat_set = 1;
+ }
+
+ if (_sender->lon_first_set == 1 && _sender->lon_second_set == 1)
+ {
+ _sender->lon = _sender->lon_first;
+ strcat(_sender->lon, _sender->lon_second);
+ _sender->lon_set = 1;
+ }
+}
+
void dump_data(char* lat, char* lon, char* nick)
{
struct position *pos = (struct position*) malloc(sizeof(struct position));
@@ -84,9 +138,9 @@ void dump_data(char* lat, char* lon, char* nick)
draw_user(pos);
}
-void get_position(irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count)
+void get_position(irc_session_t * session, const char * event, const char * origin, const unsigned char ** params, unsigned int count)
{
- char *decrypted;
+ unsigned char *decrypted;
char *sender_org = (char*) malloc(username_length + 1);
@@ -101,20 +155,29 @@ void get_position(irc_session_t * session, const char * event, const char * orig
if (s_sender[pos]->lat_set == 0)
{
- decrypted = (char*) malloc(sizeof(char) * 8);
+ decrypted = (char*) malloc(sizeof(char) * 5);
+
BF_ecb_encrypt(params[1], decrypted, &key, BF_DECRYPT);
- s_sender[pos]->lat = decrypted;
- // printf("s_sender[%i]->lat: %s \n", pos, s_sender[pos]->lat);
- s_sender[pos]->lat_set = 1;
+ decrypted[strlen(decrypted)] = '\0';
+
+ printf("decrypted %s \n", decrypted);
+
+ repair_position(s_sender[pos], decrypted);
+
+ free(decrypted);
}
else if (s_sender[pos]->lon_set == 0)
{
- decrypted = (char*) malloc(sizeof(char) * 8);
+ decrypted = (char*) malloc(sizeof(char) * 5);
BF_ecb_encrypt(params[1], decrypted, &key, BF_DECRYPT);
- s_sender[pos]->lon = decrypted;
- // printf("s_sender[%i]->lon: %s \n", pos, s_sender[pos]->lon);
- s_sender[pos]->lon_set = 1;
+ decrypted[strlen(decrypted)] = '\0';
+
+ printf("decrypted %s \n", decrypted);
+
+ repair_position(s_sender[pos], decrypted);
+
+ free(decrypted);
}
if(s_sender[pos]->lon_set == 1 && s_sender[pos]->lat_set == 1)// && lon != NULL && lat != NULL)
@@ -136,7 +199,6 @@ void get_position(irc_session_t * session, const char * event, const char * orig
s_sender[pos]->lon_set = 0;
s_sender[pos]->lat_set = 0;
- free(decrypted);
free(sender_org);
}
@@ -165,6 +227,14 @@ void init_sender_struct(int number)
s_sender[i]->lon_set = (int) malloc(sizeof(int));
s_sender[i]->lon_set = 0;
+
+
+ s_sender[i]->lat_first = (char*) malloc(sizeof(char) * 5);
+ s_sender[i]->lat_second = (char*) malloc(sizeof(char) * 5);
+
+ s_sender[i]->lon_first = (char*) malloc(sizeof(char) * 5);
+ s_sender[i]->lon_second = (char*) malloc(sizeof(char) * 5);
+
}
}
diff --git a/friendfinder/receiver.h b/friendfinder/receiver.h
index f964677..7b8f1be 100644
--- a/friendfinder/receiver.h
+++ b/friendfinder/receiver.h
@@ -13,9 +13,20 @@ struct sender
char *nick;
char *lat;
char *lon;
+
int is_init;
int lat_set;
int lon_set;
+
+ char* lat_first;
+ char* lat_second;
+ char* lon_first;
+ char* lon_second;
+
+ int lat_first_set;
+ int lat_second_set;
+ int lon_first_set;
+ int lon_second_set;
};
/* calls main for receiver */
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)
diff --git a/friendfinder/sender.h b/friendfinder/sender.h
index 7ac89d3..57435bb 100644
--- a/friendfinder/sender.h
+++ b/friendfinder/sender.h
@@ -1,6 +1,14 @@
#ifndef __SENDER_H_
#define __SENDER_H_
+struct sender_data
+{
+ char* lat_first;
+ char* lat_second;
+ char* lon_first;
+ char* lon_second;
+};
+
/* inits sender */
void sender_main(void *user);