diff options
author | Sean Qureshi <stqism@risingstormgames.com> | 2013-08-08 03:07:41 -0700 |
---|---|---|
committer | Sean Qureshi <stqism@risingstormgames.com> | 2013-08-08 03:07:41 -0700 |
commit | 4d0cce2f69b4a4f99b694e65d6c5ccaf38ef57b8 (patch) | |
tree | e300f13a4a0b86e9d1670c0ebc75bbeebc09fa02 | |
parent | 1bbdd9d2dbbb0a0a7ae056699c487df00c55579e (diff) | |
parent | 225f74e844299c405b744a9d03f4fcc0430b430a (diff) |
Merge https://github.com/irungentoo/ProjectTox-Core
-rwxr-xr-x | auto_tests/friends_test.c | 8 | ||||
-rw-r--r-- | auto_tests/messenger_test.c | 22 | ||||
-rw-r--r-- | core/Messenger.c | 172 | ||||
-rw-r--r-- | core/Messenger.h | 63 | ||||
-rw-r--r-- | testing/nTox.c | 8 | ||||
-rw-r--r-- | testing/nTox_win32.c | 14 | ||||
-rw-r--r-- | testing/nTox_win32.h | 2 | ||||
-rw-r--r-- | testing/toxic/chat.c | 2 | ||||
-rw-r--r-- | testing/toxic/friendlist.c | 4 | ||||
-rw-r--r-- | testing/toxic/prompt.c | 20 |
10 files changed, 165 insertions, 150 deletions
diff --git a/auto_tests/friends_test.c b/auto_tests/friends_test.c index 4f777ab5..11c6bf29 100755 --- a/auto_tests/friends_test.c +++ b/auto_tests/friends_test.c | |||
@@ -65,7 +65,7 @@ void parent_confirm_message(int num, uint8_t *data, uint16_t length) | |||
65 | request_flags |= SECOND_FLAG; | 65 | request_flags |= SECOND_FLAG; |
66 | } | 66 | } |
67 | 67 | ||
68 | void parent_confirm_status(int num, USERSTATUS_KIND status, uint8_t *data, uint16_t length) | 68 | void parent_confirm_status(int num, uint8_t *data, uint16_t length) |
69 | { | 69 | { |
70 | puts("OK"); | 70 | puts("OK"); |
71 | request_flags |= FIRST_FLAG; | 71 | request_flags |= FIRST_FLAG; |
@@ -110,7 +110,7 @@ void child_got_request(uint8_t *public_key, uint8_t *data, uint16_t length) | |||
110 | request_flags |= FIRST_FLAG; | 110 | request_flags |= FIRST_FLAG; |
111 | } | 111 | } |
112 | 112 | ||
113 | void child_got_statuschange(int friend_num, USERSTATUS_KIND status, uint8_t *string, uint16_t length) | 113 | void child_got_statuschange(int friend_num, uint8_t *string, uint16_t length) |
114 | { | 114 | { |
115 | request_flags |= SECOND_FLAG; | 115 | request_flags |= SECOND_FLAG; |
116 | } | 116 | } |
@@ -169,7 +169,7 @@ int main(int argc, char *argv[]) | |||
169 | msync(child_id, crypto_box_PUBLICKEYBYTES, MS_SYNC); | 169 | msync(child_id, crypto_box_PUBLICKEYBYTES, MS_SYNC); |
170 | 170 | ||
171 | m_callback_friendrequest(child_got_request); | 171 | m_callback_friendrequest(child_got_request); |
172 | m_callback_userstatus(child_got_statuschange); | 172 | m_callback_statusmessage(child_got_statuschange); |
173 | 173 | ||
174 | /* wait on the friend request */ | 174 | /* wait on the friend request */ |
175 | while(!(request_flags & FIRST_FLAG)) | 175 | while(!(request_flags & FIRST_FLAG)) |
@@ -196,7 +196,7 @@ int main(int argc, char *argv[]) | |||
196 | } | 196 | } |
197 | 197 | ||
198 | msync(parent_id, crypto_box_PUBLICKEYBYTES, MS_SYNC); | 198 | msync(parent_id, crypto_box_PUBLICKEYBYTES, MS_SYNC); |
199 | m_callback_userstatus(parent_confirm_status); | 199 | m_callback_statusmessage(parent_confirm_status); |
200 | m_callback_friendmessage(parent_confirm_message); | 200 | m_callback_friendmessage(parent_confirm_message); |
201 | 201 | ||
202 | /* hacky way to give the child time to set up */ | 202 | /* hacky way to give the child time to set up */ |
diff --git a/auto_tests/messenger_test.c b/auto_tests/messenger_test.c index deed498f..cc624ab6 100644 --- a/auto_tests/messenger_test.c +++ b/auto_tests/messenger_test.c | |||
@@ -62,16 +62,16 @@ END_TEST | |||
62 | START_TEST(test_m_get_userstatus_size) | 62 | START_TEST(test_m_get_userstatus_size) |
63 | { | 63 | { |
64 | int rc = 0; | 64 | int rc = 0; |
65 | ck_assert_msg((m_get_userstatus_size(-1) == -1), | 65 | ck_assert_msg((m_get_statusmessage_size(-1) == -1), |
66 | "m_get_userstatus_size did NOT catch an argument of -1"); | 66 | "m_get_statusmessage_size did NOT catch an argument of -1"); |
67 | ck_assert_msg((m_get_userstatus_size(REALLY_BIG_NUMBER) == -1), | 67 | ck_assert_msg((m_get_statusmessage_size(REALLY_BIG_NUMBER) == -1), |
68 | "m_get_userstatus_size did NOT catch the following argument: %d\n", | 68 | "m_get_statusmessage_size did NOT catch the following argument: %d\n", |
69 | REALLY_BIG_NUMBER); | 69 | REALLY_BIG_NUMBER); |
70 | rc = m_get_userstatus_size(friend_id_num); | 70 | rc = m_get_statusmessage_size(friend_id_num); |
71 | 71 | ||
72 | /* this WILL error if the original m_addfriend_norequest() failed */ | 72 | /* this WILL error if the original m_addfriend_norequest() failed */ |
73 | ck_assert_msg((rc > 0 && rc <= MAX_USERSTATUS_LENGTH), | 73 | ck_assert_msg((rc > 0 && rc <= MAX_STATUSMESSAGE_LENGTH), |
74 | "m_get_userstatus_size is returning out of range values!\n" | 74 | "m_get_statusmessage_size is returning out of range values!\n" |
75 | "(this can be caused by the error of m_addfriend_norequest" | 75 | "(this can be caused by the error of m_addfriend_norequest" |
76 | " in the beginning of the suite)\n"); | 76 | " in the beginning of the suite)\n"); |
77 | } | 77 | } |
@@ -83,15 +83,13 @@ START_TEST(test_m_set_userstatus) | |||
83 | uint16_t good_length = strlen(status); | 83 | uint16_t good_length = strlen(status); |
84 | uint16_t bad_length = REALLY_BIG_NUMBER; | 84 | uint16_t bad_length = REALLY_BIG_NUMBER; |
85 | 85 | ||
86 | if(m_set_userstatus(USERSTATUS_KIND_ONLINE, | 86 | if(m_set_statusmessage((uint8_t *)status, bad_length) != -1) |
87 | (uint8_t *)status, bad_length) != -1) | ||
88 | ck_abort_msg("m_set_userstatus did NOT catch the following length: %d\n", | 87 | ck_abort_msg("m_set_userstatus did NOT catch the following length: %d\n", |
89 | REALLY_BIG_NUMBER); | 88 | REALLY_BIG_NUMBER); |
90 | 89 | ||
91 | if((m_set_userstatus(USERSTATUS_KIND_RETAIN, | 90 | if((m_set_statusmessage((uint8_t *)status, good_length)) != 0) |
92 | (uint8_t *)status, good_length)) != 0) | ||
93 | ck_abort_msg("m_set_userstatus did NOT return 0 on the following length: %d\n" | 91 | ck_abort_msg("m_set_userstatus did NOT return 0 on the following length: %d\n" |
94 | "MAX_USERSTATUS_LENGTH: %d\n", good_length, MAX_USERSTATUS_LENGTH); | 92 | "MAX_STATUSMESSAGE_LENGTH: %d\n", good_length, MAX_STATUSMESSAGE_LENGTH); |
95 | } | 93 | } |
96 | END_TEST | 94 | END_TEST |
97 | 95 | ||
diff --git a/core/Messenger.c b/core/Messenger.c index b29bd1f1..3d991e63 100644 --- a/core/Messenger.c +++ b/core/Messenger.c | |||
@@ -32,10 +32,11 @@ typedef struct { | |||
32 | uint8_t info[MAX_DATA_SIZE]; /* the data that is sent during the friend requests we do */ | 32 | uint8_t info[MAX_DATA_SIZE]; /* the data that is sent during the friend requests we do */ |
33 | uint8_t name[MAX_NAME_LENGTH]; | 33 | uint8_t name[MAX_NAME_LENGTH]; |
34 | uint8_t name_sent; /* 0 if we didn't send our name to this friend 1 if we have. */ | 34 | uint8_t name_sent; /* 0 if we didn't send our name to this friend 1 if we have. */ |
35 | uint8_t *userstatus; | 35 | uint8_t *statusmessage; |
36 | uint16_t userstatus_length; | 36 | uint16_t statusmessage_length; |
37 | uint8_t statusmessage_sent; | ||
38 | USERSTATUS userstatus; | ||
37 | uint8_t userstatus_sent; | 39 | uint8_t userstatus_sent; |
38 | USERSTATUS_KIND userstatus_kind; | ||
39 | uint16_t info_size; /* length of the info */ | 40 | uint16_t info_size; /* length of the info */ |
40 | uint32_t message_id; /* a semi-unique id used in read receipts */ | 41 | uint32_t message_id; /* a semi-unique id used in read receipts */ |
41 | uint8_t receives_read_receipts; /* shall we send read receipts to this person? */ | 42 | uint8_t receives_read_receipts; /* shall we send read receipts to this person? */ |
@@ -46,9 +47,9 @@ uint8_t self_public_key[crypto_box_PUBLICKEYBYTES]; | |||
46 | static uint8_t self_name[MAX_NAME_LENGTH]; | 47 | static uint8_t self_name[MAX_NAME_LENGTH]; |
47 | static uint16_t self_name_length; | 48 | static uint16_t self_name_length; |
48 | 49 | ||
49 | static uint8_t *self_userstatus; | 50 | static uint8_t *self_statusmessage; |
50 | static uint16_t self_userstatus_len; | 51 | static uint16_t self_statusmessage_len; |
51 | static USERSTATUS_KIND self_userstatus_kind; | 52 | static USERSTATUS self_userstatus; |
52 | 53 | ||
53 | #define MAX_NUM_FRIENDS 256 | 54 | #define MAX_NUM_FRIENDS 256 |
54 | 55 | ||
@@ -125,9 +126,9 @@ int m_addfriend(uint8_t *client_id, uint8_t *data, uint16_t length) | |||
125 | friendlist[i].crypt_connection_id = -1; | 126 | friendlist[i].crypt_connection_id = -1; |
126 | friendlist[i].friend_request_id = -1; | 127 | friendlist[i].friend_request_id = -1; |
127 | memcpy(friendlist[i].client_id, client_id, CLIENT_ID_SIZE); | 128 | memcpy(friendlist[i].client_id, client_id, CLIENT_ID_SIZE); |
128 | friendlist[i].userstatus = calloc(1, 1); | 129 | friendlist[i].statusmessage = calloc(1, 1); |
129 | friendlist[i].userstatus_length = 1; | 130 | friendlist[i].statusmessage_length = 1; |
130 | friendlist[i].userstatus_kind = USERSTATUS_KIND_OFFLINE; | 131 | friendlist[i].userstatus = USERSTATUS_NONE; |
131 | memcpy(friendlist[i].info, data, length); | 132 | memcpy(friendlist[i].info, data, length); |
132 | friendlist[i].info_size = length; | 133 | friendlist[i].info_size = length; |
133 | friendlist[i].message_id = 0; | 134 | friendlist[i].message_id = 0; |
@@ -152,8 +153,9 @@ int m_addfriend_norequest(uint8_t * client_id) | |||
152 | friendlist[i].crypt_connection_id = -1; | 153 | friendlist[i].crypt_connection_id = -1; |
153 | friendlist[i].friend_request_id = -1; | 154 | friendlist[i].friend_request_id = -1; |
154 | memcpy(friendlist[i].client_id, client_id, CLIENT_ID_SIZE); | 155 | memcpy(friendlist[i].client_id, client_id, CLIENT_ID_SIZE); |
155 | friendlist[i].userstatus = calloc(1, 1); | 156 | friendlist[i].statusmessage = calloc(1, 1); |
156 | friendlist[i].userstatus_length = 1; | 157 | friendlist[i].statusmessage_length = 1; |
158 | friendlist[i].userstatus = USERSTATUS_NONE; | ||
157 | friendlist[i].message_id = 0; | 159 | friendlist[i].message_id = 0; |
158 | friendlist[i].receives_read_receipts = 1; /* default: YES */ | 160 | friendlist[i].receives_read_receipts = 1; /* default: YES */ |
159 | numfriends++; | 161 | numfriends++; |
@@ -173,7 +175,7 @@ int m_delfriend(int friendnumber) | |||
173 | 175 | ||
174 | DHT_delfriend(friendlist[friendnumber].client_id); | 176 | DHT_delfriend(friendlist[friendnumber].client_id); |
175 | crypto_kill(friendlist[friendnumber].crypt_connection_id); | 177 | crypto_kill(friendlist[friendnumber].crypt_connection_id); |
176 | free(friendlist[friendnumber].userstatus); | 178 | free(friendlist[friendnumber].statusmessage); |
177 | memset(&friendlist[friendnumber], 0, sizeof(Friend)); | 179 | memset(&friendlist[friendnumber], 0, sizeof(Friend)); |
178 | uint32_t i; | 180 | uint32_t i; |
179 | 181 | ||
@@ -290,33 +292,28 @@ int getname(int friendnumber, uint8_t * name) | |||
290 | return 0; | 292 | return 0; |
291 | } | 293 | } |
292 | 294 | ||
293 | int m_set_userstatus(USERSTATUS_KIND kind, uint8_t *status, uint16_t length) | 295 | int m_set_statusmessage(uint8_t *status, uint16_t length) |
294 | { | 296 | { |
295 | if (length > MAX_USERSTATUS_LENGTH) | 297 | if (length > MAX_STATUSMESSAGE_LENGTH) |
296 | return -1; | 298 | return -1; |
297 | if (kind != USERSTATUS_KIND_RETAIN) { | ||
298 | self_userstatus_kind = kind; | ||
299 | } | ||
300 | uint8_t *newstatus = calloc(length, 1); | 299 | uint8_t *newstatus = calloc(length, 1); |
301 | memcpy(newstatus, status, length); | 300 | memcpy(newstatus, status, length); |
302 | free(self_userstatus); | 301 | free(self_statusmessage); |
303 | self_userstatus = newstatus; | 302 | self_statusmessage = newstatus; |
304 | self_userstatus_len = length; | 303 | self_statusmessage_len = length; |
305 | 304 | ||
306 | uint32_t i; | 305 | uint32_t i; |
307 | for (i = 0; i < numfriends; ++i) | 306 | for (i = 0; i < numfriends; ++i) |
308 | friendlist[i].userstatus_sent = 0; | 307 | friendlist[i].statusmessage_sent = 0; |
309 | return 0; | 308 | return 0; |
310 | } | 309 | } |
311 | 310 | ||
312 | int m_set_userstatus_kind(USERSTATUS_KIND kind) { | 311 | int m_set_userstatus(USERSTATUS status) |
313 | if (kind >= USERSTATUS_KIND_INVALID) { | 312 | { |
313 | if (status >= USERSTATUS_INVALID) { | ||
314 | return -1; | 314 | return -1; |
315 | } | 315 | } |
316 | if (kind == USERSTATUS_KIND_RETAIN) { | 316 | self_userstatus = status; |
317 | return 0; | ||
318 | } | ||
319 | self_userstatus_kind = kind; | ||
320 | uint32_t i; | 317 | uint32_t i; |
321 | for (i = 0; i < numfriends; ++i) | 318 | for (i = 0; i < numfriends; ++i) |
322 | friendlist[i].userstatus_sent = 0; | 319 | friendlist[i].userstatus_sent = 0; |
@@ -324,72 +321,83 @@ int m_set_userstatus_kind(USERSTATUS_KIND kind) { | |||
324 | } | 321 | } |
325 | 322 | ||
326 | /* return the size of friendnumber's user status | 323 | /* return the size of friendnumber's user status |
327 | guaranteed to be at most MAX_USERSTATUS_LENGTH */ | 324 | guaranteed to be at most MAX_STATUSMESSAGE_LENGTH */ |
328 | int m_get_userstatus_size(int friendnumber) | 325 | int m_get_statusmessage_size(int friendnumber) |
329 | { | 326 | { |
330 | if (friendnumber >= numfriends || friendnumber < 0) | 327 | if (friendnumber >= numfriends || friendnumber < 0) |
331 | return -1; | 328 | return -1; |
332 | return friendlist[friendnumber].userstatus_length; | 329 | return friendlist[friendnumber].statusmessage_length; |
333 | } | 330 | } |
334 | 331 | ||
335 | /* copy the user status of friendnumber into buf, truncating if needed to maxlen | 332 | /* copy the user status of friendnumber into buf, truncating if needed to maxlen |
336 | bytes, use m_get_userstatus_size to find out how much you need to allocate */ | 333 | bytes, use m_get_statusmessage_size to find out how much you need to allocate */ |
337 | int m_copy_userstatus(int friendnumber, uint8_t * buf, uint32_t maxlen) | 334 | int m_copy_statusmessage(int friendnumber, uint8_t * buf, uint32_t maxlen) |
338 | { | 335 | { |
339 | if (friendnumber >= numfriends || friendnumber < 0) | 336 | if (friendnumber >= numfriends || friendnumber < 0) |
340 | return -1; | 337 | return -1; |
341 | memset(buf, 0, maxlen); | 338 | memset(buf, 0, maxlen); |
342 | memcpy(buf, friendlist[friendnumber].userstatus, MIN(maxlen, MAX_USERSTATUS_LENGTH) - 1); | 339 | memcpy(buf, friendlist[friendnumber].statusmessage, MIN(maxlen, MAX_STATUSMESSAGE_LENGTH) - 1); |
343 | return 0; | 340 | return 0; |
344 | } | 341 | } |
345 | 342 | ||
346 | int m_copy_self_userstatus(uint8_t * buf, uint32_t maxlen) | 343 | int m_copy_self_statusmessage(uint8_t * buf, uint32_t maxlen) |
347 | { | 344 | { |
348 | memset(buf, 0, maxlen); | 345 | memset(buf, 0, maxlen); |
349 | memcpy(buf, self_userstatus, MIN(maxlen, MAX_USERSTATUS_LENGTH) - 1); | 346 | memcpy(buf, self_statusmessage, MIN(maxlen, MAX_STATUSMESSAGE_LENGTH) - 1); |
350 | return 0; | 347 | return 0; |
351 | } | 348 | } |
352 | 349 | ||
353 | USERSTATUS_KIND m_get_userstatus_kind(int friendnumber) { | 350 | USERSTATUS m_get_userstatus(int friendnumber) |
351 | { | ||
354 | if (friendnumber >= numfriends || friendnumber < 0) | 352 | if (friendnumber >= numfriends || friendnumber < 0) |
355 | return USERSTATUS_KIND_INVALID; | 353 | return USERSTATUS_INVALID; |
356 | USERSTATUS_KIND uk = friendlist[friendnumber].userstatus_kind; | 354 | USERSTATUS status = friendlist[friendnumber].userstatus; |
357 | if (uk >= USERSTATUS_KIND_INVALID) { | 355 | if (status >= USERSTATUS_INVALID) { |
358 | uk = USERSTATUS_KIND_ONLINE; | 356 | status = USERSTATUS_NONE; |
359 | } | 357 | } |
360 | return uk; | 358 | return status; |
361 | } | 359 | } |
362 | 360 | ||
363 | USERSTATUS_KIND m_get_self_userstatus_kind(void) { | 361 | USERSTATUS m_get_self_userstatus(void) |
364 | return self_userstatus_kind; | 362 | { |
363 | return self_userstatus; | ||
365 | } | 364 | } |
366 | 365 | ||
367 | static int send_userstatus(int friendnumber, uint8_t * status, uint16_t length) | 366 | static int send_statusmessage(int friendnumber, uint8_t * status, uint16_t length) |
368 | { | 367 | { |
369 | uint8_t *thepacket = malloc(length + 2); | 368 | uint8_t *thepacket = malloc(length + 1); |
370 | memcpy(thepacket + 2, status, length); | 369 | memcpy(thepacket + 1, status, length); |
370 | thepacket[0] = PACKET_ID_STATUSMESSAGE; | ||
371 | int written = write_cryptpacket(friendlist[friendnumber].crypt_connection_id, thepacket, length + 1); | ||
372 | free(thepacket); | ||
373 | return written; | ||
374 | } | ||
375 | |||
376 | static int send_userstatus(int friendnumber, USERSTATUS status) | ||
377 | { | ||
378 | uint8_t *thepacket = malloc(1 + 1); | ||
379 | memcpy(thepacket + 1, &status, 1); | ||
371 | thepacket[0] = PACKET_ID_USERSTATUS; | 380 | thepacket[0] = PACKET_ID_USERSTATUS; |
372 | thepacket[1] = self_userstatus_kind; | 381 | int written = write_cryptpacket(friendlist[friendnumber].crypt_connection_id, thepacket, 1 + 1); |
373 | int written = write_cryptpacket(friendlist[friendnumber].crypt_connection_id, thepacket, length + 2); | ||
374 | free(thepacket); | 382 | free(thepacket); |
375 | return written; | 383 | return written; |
376 | } | 384 | } |
377 | 385 | ||
378 | static int set_friend_userstatus(int friendnumber, uint8_t * status, uint16_t length) | 386 | static int set_friend_statusmessage(int friendnumber, uint8_t * status, uint16_t length) |
379 | { | 387 | { |
380 | if (friendnumber >= numfriends || friendnumber < 0) | 388 | if (friendnumber >= numfriends || friendnumber < 0) |
381 | return -1; | 389 | return -1; |
382 | uint8_t *newstatus = calloc(length, 1); | 390 | uint8_t *newstatus = calloc(length, 1); |
383 | memcpy(newstatus, status, length); | 391 | memcpy(newstatus, status, length); |
384 | free(friendlist[friendnumber].userstatus); | 392 | free(friendlist[friendnumber].statusmessage); |
385 | friendlist[friendnumber].userstatus = newstatus; | 393 | friendlist[friendnumber].statusmessage = newstatus; |
386 | friendlist[friendnumber].userstatus_length = length; | 394 | friendlist[friendnumber].statusmessage_length = length; |
387 | return 0; | 395 | return 0; |
388 | } | 396 | } |
389 | 397 | ||
390 | static void set_friend_userstatus_kind(int friendnumber, USERSTATUS_KIND k) | 398 | static void set_friend_userstatus(int friendnumber, USERSTATUS status) |
391 | { | 399 | { |
392 | friendlist[friendnumber].userstatus_kind = k; | 400 | friendlist[friendnumber].userstatus = status; |
393 | } | 401 | } |
394 | 402 | ||
395 | /* Sets whether we send read receipts for friendnumber. */ | 403 | /* Sets whether we send read receipts for friendnumber. */ |
@@ -428,12 +436,20 @@ void m_callback_namechange(void (*function)(int, uint8_t *, uint16_t)) | |||
428 | friend_namechange_isset = 1; | 436 | friend_namechange_isset = 1; |
429 | } | 437 | } |
430 | 438 | ||
431 | static void (*friend_statuschange)(int, USERSTATUS_KIND, uint8_t *, uint16_t); | 439 | static void (*friend_statusmessagechange)(int, uint8_t *, uint16_t); |
432 | static uint8_t friend_statuschange_isset = 0; | 440 | static uint8_t friend_statusmessagechange_isset = 0; |
433 | void m_callback_userstatus(void (*function)(int, USERSTATUS_KIND, uint8_t *, uint16_t)) | 441 | void m_callback_statusmessage(void (*function)(int, uint8_t *, uint16_t)) |
434 | { | 442 | { |
435 | friend_statuschange = function; | 443 | friend_statusmessagechange = function; |
436 | friend_statuschange_isset = 1; | 444 | friend_statusmessagechange_isset = 1; |
445 | } | ||
446 | |||
447 | static void (*friend_userstatuschange)(int, USERSTATUS); | ||
448 | static uint8_t friend_userstatuschange_isset = 0; | ||
449 | void m_callback_userstatus(void (*function)(int, USERSTATUS)) | ||
450 | { | ||
451 | friend_userstatuschange = function; | ||
452 | friend_userstatuschange_isset = 1; | ||
437 | } | 453 | } |
438 | 454 | ||
439 | static void (*read_receipt)(int, uint32_t); | 455 | static void (*read_receipt)(int, uint32_t); |
@@ -449,7 +465,7 @@ void m_callback_read_receipt(void (*function)(int, uint32_t)) | |||
449 | int initMessenger(void) | 465 | int initMessenger(void) |
450 | { | 466 | { |
451 | new_keys(); | 467 | new_keys(); |
452 | m_set_userstatus(USERSTATUS_KIND_ONLINE, (uint8_t*)"Online", sizeof("Online")); | 468 | m_set_statusmessage((uint8_t*)"Online", sizeof("Online")); |
453 | initNetCrypto(); | 469 | initNetCrypto(); |
454 | IP ip; | 470 | IP ip; |
455 | ip.i = 0; | 471 | ip.i = 0; |
@@ -504,8 +520,12 @@ static void doFriends(void) | |||
504 | if (m_sendname(i, self_name, self_name_length)) | 520 | if (m_sendname(i, self_name, self_name_length)) |
505 | friendlist[i].name_sent = 1; | 521 | friendlist[i].name_sent = 1; |
506 | } | 522 | } |
523 | if (friendlist[i].statusmessage_sent == 0) { | ||
524 | if (send_statusmessage(i, self_statusmessage, self_statusmessage_len)) | ||
525 | friendlist[i].statusmessage_sent = 1; | ||
526 | } | ||
507 | if (friendlist[i].userstatus_sent == 0) { | 527 | if (friendlist[i].userstatus_sent == 0) { |
508 | if (send_userstatus(i, self_userstatus, self_userstatus_len)) | 528 | if (send_userstatus(i, self_userstatus)) |
509 | friendlist[i].userstatus_sent = 1; | 529 | friendlist[i].userstatus_sent = 1; |
510 | } | 530 | } |
511 | len = read_cryptpacket(friendlist[i].crypt_connection_id, temp); | 531 | len = read_cryptpacket(friendlist[i].crypt_connection_id, temp); |
@@ -520,18 +540,24 @@ static void doFriends(void) | |||
520 | friendlist[i].name[len - 2] = 0; /* make sure the NULL terminator is present. */ | 540 | friendlist[i].name[len - 2] = 0; /* make sure the NULL terminator is present. */ |
521 | break; | 541 | break; |
522 | } | 542 | } |
543 | case PACKET_ID_STATUSMESSAGE: { | ||
544 | if (len < 2) | ||
545 | break; | ||
546 | uint8_t *status = calloc(MIN(len - 1, MAX_STATUSMESSAGE_LENGTH), 1); | ||
547 | memcpy(status, temp + 1, MIN(len - 1, MAX_STATUSMESSAGE_LENGTH)); | ||
548 | if (friend_statusmessagechange_isset) | ||
549 | friend_statusmessagechange(i, status, MIN(len - 1, MAX_STATUSMESSAGE_LENGTH)); | ||
550 | set_friend_statusmessage(i, status, MIN(len - 1, MAX_STATUSMESSAGE_LENGTH)); | ||
551 | free(status); | ||
552 | break; | ||
553 | } | ||
523 | case PACKET_ID_USERSTATUS: { | 554 | case PACKET_ID_USERSTATUS: { |
524 | if (len > 2) { | 555 | if (len != 2) |
525 | uint8_t *status = calloc(MIN(len - 2, MAX_USERSTATUS_LENGTH), 1); | 556 | break; |
526 | memcpy(status, temp + 2, MIN(len - 2, MAX_USERSTATUS_LENGTH)); | 557 | USERSTATUS status = temp[1]; |
527 | if (friend_statuschange_isset) | 558 | if (friend_userstatuschange_isset) |
528 | friend_statuschange(i, temp[1], status, MIN(len - 2, MAX_USERSTATUS_LENGTH)); | 559 | friend_userstatuschange(i, status); |
529 | set_friend_userstatus(i, status, MIN(len - 2, MAX_USERSTATUS_LENGTH)); | 560 | set_friend_userstatus(i, status); |
530 | free(status); | ||
531 | } else if (friend_statuschange_isset) { | ||
532 | friend_statuschange(i, temp[1], friendlist[i].userstatus, friendlist[i].userstatus_length); | ||
533 | } | ||
534 | set_friend_userstatus_kind(i, temp[1]); | ||
535 | break; | 561 | break; |
536 | } | 562 | } |
537 | case PACKET_ID_MESSAGE: { | 563 | case PACKET_ID_MESSAGE: { |
@@ -694,7 +720,7 @@ int Messenger_load(uint8_t * data, uint32_t length) | |||
694 | if(temp[i].status != 0) { | 720 | if(temp[i].status != 0) { |
695 | int fnum = m_addfriend_norequest(temp[i].client_id); | 721 | int fnum = m_addfriend_norequest(temp[i].client_id); |
696 | setfriendname(fnum, temp[i].name); | 722 | setfriendname(fnum, temp[i].name); |
697 | /* set_friend_userstatus(fnum, temp[i].userstatus, temp[i].userstatus_length); */ | 723 | /* set_friend_statusmessage(fnum, temp[i].statusmessage, temp[i].statusmessage_length); */ |
698 | } | 724 | } |
699 | } | 725 | } |
700 | free(temp); | 726 | free(temp); |
diff --git a/core/Messenger.h b/core/Messenger.h index f0444b91..d2fa8945 100644 --- a/core/Messenger.h +++ b/core/Messenger.h | |||
@@ -36,10 +36,11 @@ extern "C" { | |||
36 | #endif | 36 | #endif |
37 | 37 | ||
38 | #define MAX_NAME_LENGTH 128 | 38 | #define MAX_NAME_LENGTH 128 |
39 | #define MAX_USERSTATUS_LENGTH 128 | 39 | #define MAX_STATUSMESSAGE_LENGTH 128 |
40 | 40 | ||
41 | #define PACKET_ID_NICKNAME 48 | 41 | #define PACKET_ID_NICKNAME 48 |
42 | #define PACKET_ID_USERSTATUS 49 | 42 | #define PACKET_ID_STATUSMESSAGE 49 |
43 | #define PACKET_ID_USERSTATUS 50 | ||
43 | #define PACKET_ID_RECEIPT 65 | 44 | #define PACKET_ID_RECEIPT 65 |
44 | #define PACKET_ID_MESSAGE 64 | 45 | #define PACKET_ID_MESSAGE 64 |
45 | 46 | ||
@@ -58,24 +59,18 @@ extern "C" { | |||
58 | #define FAERR_ALREADYSENT -4 | 59 | #define FAERR_ALREADYSENT -4 |
59 | #define FAERR_UNKNOWN -5 | 60 | #define FAERR_UNKNOWN -5 |
60 | 61 | ||
61 | /* don't assume MAX_USERSTATUS_LENGTH will stay at 128, it may be increased | 62 | /* don't assume MAX_STATUSMESSAGE_LENGTH will stay at 128, it may be increased |
62 | to an absurdly large number later */ | 63 | to an absurdly large number later */ |
63 | 64 | ||
64 | /* USERSTATUS_KIND | 65 | /* USERSTATUS |
65 | * Represents the different kinds of userstatus | 66 | * Represents userstatuses someone can have. */ |
66 | * someone can have. | ||
67 | * More on this later... */ | ||
68 | 67 | ||
69 | typedef enum { | 68 | typedef enum { |
70 | USERSTATUS_KIND_RETAIN = (uint8_t)0, /* This is a special value that must not be returned by | 69 | USERSTATUS_NONE, |
71 | * m_get_userstatus_kind. You can pass it into m_set_userstatus | 70 | USERSTATUS_AWAY, |
72 | * to keep the current USERSTATUS_KIND. */ | 71 | USERSTATUS_BUSY, |
73 | USERSTATUS_KIND_ONLINE, /* Recommended representation: Green. */ | 72 | USERSTATUS_INVALID |
74 | USERSTATUS_KIND_AWAY, /* Recommended representation: Orange, or yellow. */ | 73 | } USERSTATUS; |
75 | USERSTATUS_KIND_BUSY, /* Recommended representation: Red. */ | ||
76 | USERSTATUS_KIND_OFFLINE, /* Recommended representation: Grey, semi-transparent. */ | ||
77 | USERSTATUS_KIND_INVALID, | ||
78 | } USERSTATUS_KIND; | ||
79 | 74 | ||
80 | /* | 75 | /* |
81 | * add a friend | 76 | * add a friend |
@@ -150,26 +145,26 @@ int getname(int friendnumber, uint8_t *name); | |||
150 | /* set our user status | 145 | /* set our user status |
151 | you are responsible for freeing status after | 146 | you are responsible for freeing status after |
152 | returns 0 on success, -1 on failure */ | 147 | returns 0 on success, -1 on failure */ |
153 | int m_set_userstatus(USERSTATUS_KIND kind, uint8_t *status, uint16_t length); | 148 | int m_set_statusmessage(uint8_t *status, uint16_t length); |
154 | int m_set_userstatus_kind(USERSTATUS_KIND kind); | 149 | int m_set_userstatus(USERSTATUS status); |
155 | 150 | ||
156 | /* return the length of friendnumber's user status, | 151 | /* return the length of friendnumber's status message, |
157 | including null | 152 | including null |
158 | pass it into malloc */ | 153 | pass it into malloc */ |
159 | int m_get_userstatus_size(int friendnumber); | 154 | int m_get_statusmessage_size(int friendnumber); |
160 | 155 | ||
161 | /* copy friendnumber's userstatus into buf, truncating if size is over maxlen | 156 | /* copy friendnumber's status message into buf, truncating if size is over maxlen |
162 | get the size you need to allocate from m_get_userstatus_size | 157 | get the size you need to allocate from m_get_statusmessage_size |
163 | The self variant will copy our own userstatus. */ | 158 | The self variant will copy our own status message. */ |
164 | int m_copy_userstatus(int friendnumber, uint8_t *buf, uint32_t maxlen); | 159 | int m_copy_statusmessage(int friendnumber, uint8_t *buf, uint32_t maxlen); |
165 | int m_copy_self_userstatus(uint8_t *buf, uint32_t maxlen); | 160 | int m_copy_self_statusmessage(uint8_t *buf, uint32_t maxlen); |
166 | 161 | ||
167 | /* Return one of USERSTATUS_KIND values, except USERSTATUS_KIND_RETAIN. | 162 | /* Return one of USERSTATUS values. |
168 | * Values unknown to your application should be represented as USERSTATUS_KIND_ONLINE. | 163 | * Values unknown to your application should be represented as USERSTATUS_NONE. |
169 | * As above, the self variant will return our own USERSTATUS_KIND. | 164 | * As above, the self variant will return our own USERSTATUS. |
170 | * If friendnumber is invalid, this shall return USERSTATUS_KIND_INVALID. */ | 165 | * If friendnumber is invalid, this shall return USERSTATUS_INVALID. */ |
171 | USERSTATUS_KIND m_get_userstatus_kind(int friendnumber); | 166 | USERSTATUS m_get_userstatus(int friendnumber); |
172 | USERSTATUS_KIND m_get_self_userstatus_kind(void); | 167 | USERSTATUS m_get_self_userstatus(void); |
173 | 168 | ||
174 | /* Sets whether we send read receipts for friendnumber. | 169 | /* Sets whether we send read receipts for friendnumber. |
175 | * This function is not lazy, and it will fail if yesno is not (0 or 1).*/ | 170 | * This function is not lazy, and it will fail if yesno is not (0 or 1).*/ |
@@ -188,10 +183,10 @@ void m_callback_friendmessage(void (*function)(int, uint8_t *, uint16_t)); | |||
188 | you are not responsible for freeing newname */ | 183 | you are not responsible for freeing newname */ |
189 | void m_callback_namechange(void (*function)(int, uint8_t *, uint16_t)); | 184 | void m_callback_namechange(void (*function)(int, uint8_t *, uint16_t)); |
190 | 185 | ||
191 | /* set the callback for user status changes | 186 | /* set the callback for status message changes |
192 | function(int friendnumber, USERSTATUS_KIND kind, uint8_t *newstatus, uint16_t length) | 187 | function(int friendnumber, uint8_t *newstatus, uint16_t length) |
193 | you are not responsible for freeing newstatus */ | 188 | you are not responsible for freeing newstatus */ |
194 | void m_callback_userstatus(void (*function)(int, USERSTATUS_KIND, uint8_t *, uint16_t)); | 189 | void m_callback_statusmessage(void (*function)(int, uint8_t *, uint16_t)); |
195 | 190 | ||
196 | /* set the callback for read receipts | 191 | /* set the callback for read receipts |
197 | function(int friendnumber, uint32_t receipt) | 192 | function(int friendnumber, uint32_t receipt) |
diff --git a/testing/nTox.c b/testing/nTox.c index ecdba1e3..ee4d7de4 100644 --- a/testing/nTox.c +++ b/testing/nTox.c | |||
@@ -220,7 +220,7 @@ void line_eval(char *line) | |||
220 | print_friendlist(); | 220 | print_friendlist(); |
221 | } | 221 | } |
222 | else if (inpt_command == 's') { | 222 | else if (inpt_command == 's') { |
223 | uint8_t status[MAX_USERSTATUS_LENGTH]; | 223 | uint8_t status[MAX_STATUSMESSAGE_LENGTH]; |
224 | int i = 0; | 224 | int i = 0; |
225 | size_t len = strlen(line); | 225 | size_t len = strlen(line); |
226 | for (i = 3; i < len; i++) { | 226 | for (i = 3; i < len; i++) { |
@@ -228,7 +228,7 @@ void line_eval(char *line) | |||
228 | status[i-3] = line[i]; | 228 | status[i-3] = line[i]; |
229 | } | 229 | } |
230 | status[i-3] = 0; | 230 | status[i-3] = 0; |
231 | m_set_userstatus(USERSTATUS_KIND_ONLINE, status, strlen((char*)status) + 1); | 231 | m_set_statusmessage(status, strlen((char*)status) + 1); |
232 | char numstring[100]; | 232 | char numstring[100]; |
233 | sprintf(numstring, "[i] changed status to %s", (char*)status); | 233 | sprintf(numstring, "[i] changed status to %s", (char*)status); |
234 | new_lines(numstring); | 234 | new_lines(numstring); |
@@ -364,7 +364,7 @@ void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) | |||
364 | } | 364 | } |
365 | } | 365 | } |
366 | 366 | ||
367 | void print_statuschange(int friendnumber, USERSTATUS_KIND kind, uint8_t *string, uint16_t length) | 367 | void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) |
368 | { | 368 | { |
369 | char name[MAX_NAME_LENGTH]; | 369 | char name[MAX_NAME_LENGTH]; |
370 | if(getname(friendnumber, (uint8_t*)name) != -1) { | 370 | if(getname(friendnumber, (uint8_t*)name) != -1) { |
@@ -464,7 +464,7 @@ int main(int argc, char *argv[]) | |||
464 | m_callback_friendrequest(print_request); | 464 | m_callback_friendrequest(print_request); |
465 | m_callback_friendmessage(print_message); | 465 | m_callback_friendmessage(print_message); |
466 | m_callback_namechange(print_nickchange); | 466 | m_callback_namechange(print_nickchange); |
467 | m_callback_userstatus(print_statuschange); | 467 | m_callback_statusmessage(print_statuschange); |
468 | 468 | ||
469 | initscr(); | 469 | initscr(); |
470 | noecho(); | 470 | noecho(); |
diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c index e4489f13..d9d695a5 100644 --- a/testing/nTox_win32.c +++ b/testing/nTox_win32.c | |||
@@ -86,7 +86,7 @@ void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) | |||
86 | printf(msg); | 86 | printf(msg); |
87 | } | 87 | } |
88 | 88 | ||
89 | void print_statuschange(int friendnumber,USERSTATUS_KIND kind, uint8_t *string, uint16_t length) | 89 | void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) |
90 | { | 90 | { |
91 | char name[MAX_NAME_LENGTH]; | 91 | char name[MAX_NAME_LENGTH]; |
92 | getname(friendnumber, (uint8_t*)name); | 92 | getname(friendnumber, (uint8_t*)name); |
@@ -263,7 +263,7 @@ void change_nickname() | |||
263 | 263 | ||
264 | void change_status(int savetofile) | 264 | void change_status(int savetofile) |
265 | { | 265 | { |
266 | uint8_t status[MAX_USERSTATUS_LENGTH]; | 266 | uint8_t status[MAX_STATUSMESSAGE_LENGTH]; |
267 | int i = 0; | 267 | int i = 0; |
268 | size_t len = strlen(line); | 268 | size_t len = strlen(line); |
269 | 269 | ||
@@ -275,7 +275,7 @@ void change_status(int savetofile) | |||
275 | } | 275 | } |
276 | 276 | ||
277 | status[i-3] = 0; | 277 | status[i-3] = 0; |
278 | m_set_userstatus(USERSTATUS_KIND_RETAIN, status, strlen((char*)status)); | 278 | m_set_statusmessage(status, strlen((char*)status)); |
279 | char numstring[100]; | 279 | char numstring[100]; |
280 | sprintf(numstring, "\n[i] changed status to %s\n\n", (char*)status); | 280 | sprintf(numstring, "\n[i] changed status to %s\n\n", (char*)status); |
281 | printf(numstring); | 281 | printf(numstring); |
@@ -403,11 +403,11 @@ int main(int argc, char *argv[]) | |||
403 | FILE* status_file = NULL; | 403 | FILE* status_file = NULL; |
404 | status_file = fopen("statusfile.txt", "r"); | 404 | status_file = fopen("statusfile.txt", "r"); |
405 | if(status_file) { | 405 | if(status_file) { |
406 | uint8_t status[MAX_USERSTATUS_LENGTH]; | 406 | uint8_t status[MAX_STATUSMESSAGE_LENGTH]; |
407 | while (fgets(line, MAX_USERSTATUS_LENGTH, status_file) != NULL) { | 407 | while (fgets(line, MAX_STATUSMESSAGE_LENGTH, status_file) != NULL) { |
408 | sscanf(line, "%s", (char*)status); | 408 | sscanf(line, "%s", (char*)status); |
409 | } | 409 | } |
410 | m_set_userstatus(USERSTATUS_KIND_RETAIN, status, strlen((char*)status)+1); | 410 | m_set_statusmessage(status, strlen((char*)status)+1); |
411 | statusloaded = 1; | 411 | statusloaded = 1; |
412 | printf("%s\n", status); | 412 | printf("%s\n", status); |
413 | fclose(status_file); | 413 | fclose(status_file); |
@@ -416,7 +416,7 @@ int main(int argc, char *argv[]) | |||
416 | m_callback_friendrequest(print_request); | 416 | m_callback_friendrequest(print_request); |
417 | m_callback_friendmessage(print_message); | 417 | m_callback_friendmessage(print_message); |
418 | m_callback_namechange(print_nickchange); | 418 | m_callback_namechange(print_nickchange); |
419 | m_callback_userstatus(print_statuschange); | 419 | m_callback_statusmessae(print_statuschange); |
420 | char idstring1[PUB_KEY_BYTES][5]; | 420 | char idstring1[PUB_KEY_BYTES][5]; |
421 | char idstring2[PUB_KEY_BYTES][5]; | 421 | char idstring2[PUB_KEY_BYTES][5]; |
422 | int i; | 422 | int i; |
diff --git a/testing/nTox_win32.h b/testing/nTox_win32.h index 36d5df1f..03641a5d 100644 --- a/testing/nTox_win32.h +++ b/testing/nTox_win32.h | |||
@@ -32,7 +32,7 @@ | |||
32 | void do_header(); | 32 | void do_header(); |
33 | void print_message(int friendnumber, uint8_t * string, uint16_t length); | 33 | void print_message(int friendnumber, uint8_t * string, uint16_t length); |
34 | void print_nickchange(int friendnumber, uint8_t *string, uint16_t length); | 34 | void print_nickchange(int friendnumber, uint8_t *string, uint16_t length); |
35 | void print_statuschange(int friendnumber,USERSTATUS_KIND kind, uint8_t *string, uint16_t length); | 35 | void print_statuschange(int friendnumber, uint8_t *string, uint16_t length); |
36 | void load_key(); | 36 | void load_key(); |
37 | void add_friend(); | 37 | void add_friend(); |
38 | void list_friends(); | 38 | void list_friends(); |
diff --git a/testing/toxic/chat.c b/testing/toxic/chat.c index b870e9c2..28c5de6c 100644 --- a/testing/toxic/chat.c +++ b/testing/toxic/chat.c | |||
@@ -161,7 +161,7 @@ void execute(ToxWindow *self, ChatContext *ctx, char *cmd) | |||
161 | return; | 161 | return; |
162 | } | 162 | } |
163 | msg++; | 163 | msg++; |
164 | m_set_userstatus(USERSTATUS_KIND_RETAIN, (uint8_t*) msg, strlen(msg)+1); | 164 | m_set_statusmessage((uint8_t*) msg, strlen(msg)+1); |
165 | wprintw(ctx->history, "Status set to: %s\n", msg); | 165 | wprintw(ctx->history, "Status set to: %s\n", msg); |
166 | } | 166 | } |
167 | 167 | ||
diff --git a/testing/toxic/friendlist.c b/testing/toxic/friendlist.c index f03914e6..159217b1 100644 --- a/testing/toxic/friendlist.c +++ b/testing/toxic/friendlist.c | |||
@@ -20,7 +20,7 @@ extern int active_window; | |||
20 | 20 | ||
21 | typedef struct { | 21 | typedef struct { |
22 | uint8_t name[MAX_NAME_LENGTH]; | 22 | uint8_t name[MAX_NAME_LENGTH]; |
23 | uint8_t status[MAX_USERSTATUS_LENGTH]; | 23 | uint8_t status[MAX_STATUSMESSAGE_LENGTH]; |
24 | int num; | 24 | int num; |
25 | int chatwin; | 25 | int chatwin; |
26 | } friend_t; | 26 | } friend_t; |
@@ -74,7 +74,7 @@ void friendlist_onNickChange(ToxWindow *self, int num, uint8_t *str, uint16_t le | |||
74 | 74 | ||
75 | void friendlist_onStatusChange(ToxWindow *self, int num, uint8_t *str, uint16_t len) | 75 | void friendlist_onStatusChange(ToxWindow *self, int num, uint8_t *str, uint16_t len) |
76 | { | 76 | { |
77 | if (len >= MAX_USERSTATUS_LENGTH || num >= num_friends) | 77 | if (len >= MAX_STATUSMESSAGE_LENGTH || num >= num_friends) |
78 | return; | 78 | return; |
79 | 79 | ||
80 | memcpy((char*) &friends[num].status, (char*) str, len); | 80 | memcpy((char*) &friends[num].status, (char*) str, len); |
diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c index 486273d3..661d881f 100644 --- a/testing/toxic/prompt.c +++ b/testing/toxic/prompt.c | |||
@@ -193,27 +193,22 @@ static void execute(ToxWindow *self, char *u_cmd) | |||
193 | return; | 193 | return; |
194 | } | 194 | } |
195 | status++; | 195 | status++; |
196 | USERSTATUS_KIND status_kind; | 196 | USERSTATUS status_kind; |
197 | if (!strncmp(status, "online", strlen("online"))) { | 197 | if (!strncmp(status, "online", strlen("online"))) { |
198 | status_kind = USERSTATUS_KIND_ONLINE; | 198 | status_kind = USERSTATUS_NONE; |
199 | status_text = "ONLINE"; | 199 | status_text = "ONLINE"; |
200 | } | 200 | } |
201 | 201 | ||
202 | else if (!strncmp(status, "away", strlen("away"))) { | 202 | else if (!strncmp(status, "away", strlen("away"))) { |
203 | status_kind = USERSTATUS_KIND_AWAY; | 203 | status_kind = USERSTATUS_AWAY; |
204 | status_text = "AWAY"; | 204 | status_text = "AWAY"; |
205 | } | 205 | } |
206 | 206 | ||
207 | else if (!strncmp(status, "busy", strlen("busy"))) { | 207 | else if (!strncmp(status, "busy", strlen("busy"))) { |
208 | status_kind = USERSTATUS_KIND_BUSY; | 208 | status_kind = USERSTATUS_BUSY; |
209 | status_text = "BUSY"; | 209 | status_text = "BUSY"; |
210 | } | 210 | } |
211 | 211 | ||
212 | else if (!strncmp(status, "offline", strlen("offline"))) { | ||
213 | status_kind = USERSTATUS_KIND_OFFLINE; | ||
214 | status_text = "OFFLINE"; | ||
215 | } | ||
216 | |||
217 | else | 212 | else |
218 | { | 213 | { |
219 | wprintw(self->window, "Invalid status.\n"); | 214 | wprintw(self->window, "Invalid status.\n"); |
@@ -222,12 +217,13 @@ static void execute(ToxWindow *self, char *u_cmd) | |||
222 | 217 | ||
223 | msg = strchr(status, ' '); | 218 | msg = strchr(status, ' '); |
224 | if (msg == NULL) { | 219 | if (msg == NULL) { |
225 | m_set_userstatus_kind(status_kind); | 220 | m_set_userstatus(status_kind); |
226 | wprintw(self->window, "Status set to: %s\n", status_text); | 221 | wprintw(self->window, "Status set to: %s\n", status_text); |
227 | } | 222 | } |
228 | else { | 223 | else { |
229 | msg++; | 224 | msg++; |
230 | m_set_userstatus(status_kind, (uint8_t*) msg, strlen(msg)+1); | 225 | m_set_userstatus(status_kind); |
226 | m_set_statusmessage((uint8_t*) msg, strlen(msg)+1); | ||
231 | wprintw(self->window, "Status set to: %s, %s\n", status_text, msg); | 227 | wprintw(self->window, "Status set to: %s, %s\n", status_text, msg); |
232 | } | 228 | } |
233 | } | 229 | } |
@@ -239,7 +235,7 @@ static void execute(ToxWindow *self, char *u_cmd) | |||
239 | return; | 235 | return; |
240 | } | 236 | } |
241 | msg++; | 237 | msg++; |
242 | m_set_userstatus(USERSTATUS_KIND_RETAIN, (uint8_t*) msg, strlen(msg)+1); | 238 | m_set_statusmessage((uint8_t*) msg, strlen(msg)+1); |
243 | wprintw(self->window, "Status set to: %s\n", msg); | 239 | wprintw(self->window, "Status set to: %s\n", msg); |
244 | } | 240 | } |
245 | 241 | ||