diff options
author | Sebastian Stal <stal@pyboard.net> | 2013-07-18 13:58:03 -0700 |
---|---|---|
committer | Sebastian Stal <stal@pyboard.net> | 2013-07-18 13:58:03 -0700 |
commit | 0de611627d7c5eb666e05d4cb2fd2de990e4d01b (patch) | |
tree | 096115b2fe9f31d44a3f2f4f593d3d448b29e62b | |
parent | 01a9fb8f5bb46927cdf3cdd9fdf387d9013099d5 (diff) |
Move packet IDs to Messenger.h.
-rw-r--r-- | core/Messenger.c | 12 | ||||
-rw-r--r-- | core/Messenger.h | 5 |
2 files changed, 11 insertions, 6 deletions
diff --git a/core/Messenger.c b/core/Messenger.c index 2b9644a3..09cd0e9f 100644 --- a/core/Messenger.c +++ b/core/Messenger.c | |||
@@ -223,7 +223,7 @@ int m_sendmessage(int friendnumber, uint8_t * message, uint32_t length) | |||
223 | return 0; | 223 | return 0; |
224 | } | 224 | } |
225 | uint8_t temp[MAX_DATA_SIZE]; | 225 | uint8_t temp[MAX_DATA_SIZE]; |
226 | temp[0] = 64; | 226 | temp[0] = PACKET_ID_MESSAGE; |
227 | memcpy(temp + 1, message, length); | 227 | memcpy(temp + 1, message, length); |
228 | return write_cryptpacket(friendlist[friendnumber].crypt_connection_id, temp, length + 1); | 228 | return write_cryptpacket(friendlist[friendnumber].crypt_connection_id, temp, length + 1); |
229 | } | 229 | } |
@@ -233,7 +233,7 @@ static int m_sendname(int friendnumber, uint8_t * name) | |||
233 | { | 233 | { |
234 | uint8_t temp[MAX_NAME_LENGTH + 1]; | 234 | uint8_t temp[MAX_NAME_LENGTH + 1]; |
235 | memcpy(temp + 1, name, MAX_NAME_LENGTH); | 235 | memcpy(temp + 1, name, MAX_NAME_LENGTH); |
236 | temp[0] = 48; | 236 | temp[0] = PACKET_ID_NICKNAME; |
237 | return write_cryptpacket(friendlist[friendnumber].crypt_connection_id, temp, MAX_NAME_LENGTH + 1); | 237 | return write_cryptpacket(friendlist[friendnumber].crypt_connection_id, temp, MAX_NAME_LENGTH + 1); |
238 | } | 238 | } |
239 | 239 | ||
@@ -334,7 +334,7 @@ static int send_userstatus(int friendnumber, uint8_t * status, uint16_t length) | |||
334 | { | 334 | { |
335 | uint8_t *thepacket = malloc(length + 1); | 335 | uint8_t *thepacket = malloc(length + 1); |
336 | memcpy(thepacket + 1, status, length); | 336 | memcpy(thepacket + 1, status, length); |
337 | thepacket[0] = 49; | 337 | thepacket[0] = PACKET_ID_USERSTATUS; |
338 | int written = write_cryptpacket(friendlist[friendnumber].crypt_connection_id, thepacket, length + 1); | 338 | int written = write_cryptpacket(friendlist[friendnumber].crypt_connection_id, thepacket, length + 1); |
339 | free(thepacket); | 339 | free(thepacket); |
340 | return written; | 340 | return written; |
@@ -456,14 +456,14 @@ static void doFriends() | |||
456 | if(len > 0) | 456 | if(len > 0) |
457 | { | 457 | { |
458 | switch(temp[0]) { | 458 | switch(temp[0]) { |
459 | case 48: { | 459 | case PACKET_ID_NICKNAME: { |
460 | if (len != MAX_NAME_LENGTH + 1) break; | 460 | if (len != MAX_NAME_LENGTH + 1) break; |
461 | friend_namechange(i, temp + 1, MAX_NAME_LENGTH); // todo: use the actual length | 461 | friend_namechange(i, temp + 1, MAX_NAME_LENGTH); // todo: use the actual length |
462 | memcpy(friendlist[i].name, temp + 1, MAX_NAME_LENGTH); | 462 | memcpy(friendlist[i].name, temp + 1, MAX_NAME_LENGTH); |
463 | friendlist[i].name[MAX_NAME_LENGTH - 1] = 0;//make sure the NULL terminator is present. | 463 | friendlist[i].name[MAX_NAME_LENGTH - 1] = 0;//make sure the NULL terminator is present. |
464 | break; | 464 | break; |
465 | } | 465 | } |
466 | case 49: { | 466 | case PACKET_ID_USERSTATUS: { |
467 | uint8_t *status = calloc(MIN(len - 1, MAX_USERSTATUS_LENGTH), 1); | 467 | uint8_t *status = calloc(MIN(len - 1, MAX_USERSTATUS_LENGTH), 1); |
468 | memcpy(status, temp + 1, MIN(len - 1, MAX_USERSTATUS_LENGTH)); | 468 | memcpy(status, temp + 1, MIN(len - 1, MAX_USERSTATUS_LENGTH)); |
469 | friend_statuschange(i, status, MIN(len - 1, MAX_USERSTATUS_LENGTH)); | 469 | friend_statuschange(i, status, MIN(len - 1, MAX_USERSTATUS_LENGTH)); |
@@ -471,7 +471,7 @@ static void doFriends() | |||
471 | free(status); | 471 | free(status); |
472 | break; | 472 | break; |
473 | } | 473 | } |
474 | case 64: { | 474 | case PACKET_ID_MESSAGE: { |
475 | (*friend_message)(i, temp + 1, len - 1); | 475 | (*friend_message)(i, temp + 1, len - 1); |
476 | break; | 476 | break; |
477 | } | 477 | } |
diff --git a/core/Messenger.h b/core/Messenger.h index c89d0f52..3ba74d39 100644 --- a/core/Messenger.h +++ b/core/Messenger.h | |||
@@ -32,6 +32,11 @@ | |||
32 | 32 | ||
33 | #define MAX_NAME_LENGTH 128 | 33 | #define MAX_NAME_LENGTH 128 |
34 | #define MAX_USERSTATUS_LENGTH 128 | 34 | #define MAX_USERSTATUS_LENGTH 128 |
35 | |||
36 | #define PACKET_ID_NICKNAME 48 | ||
37 | #define PACKET_ID_USERSTATUS 49 | ||
38 | #define PACKET_ID_MESSAGE 64 | ||
39 | |||
35 | // don't assume MAX_USERSTATUS_LENGTH will stay at 128, it may be increased | 40 | // don't assume MAX_USERSTATUS_LENGTH will stay at 128, it may be increased |
36 | // to an absurdly large number later | 41 | // to an absurdly large number later |
37 | 42 | ||