diff options
-rw-r--r-- | core/Messenger.c | 30 | ||||
-rw-r--r-- | testing/nTox.c | 34 | ||||
-rw-r--r-- | testing/nTox_win32.c | 10 | ||||
-rw-r--r-- | testing/toxic/prompt.c | 8 |
4 files changed, 48 insertions, 34 deletions
diff --git a/core/Messenger.c b/core/Messenger.c index 49f638df..f8a794ce 100644 --- a/core/Messenger.c +++ b/core/Messenger.c | |||
@@ -94,25 +94,31 @@ int getclient_id(int friend_id, uint8_t *client_id) | |||
94 | return -1; | 94 | return -1; |
95 | } | 95 | } |
96 | 96 | ||
97 | /* add a friend | 97 | /* |
98 | set the data that will be sent along with friend request | 98 | * add a friend |
99 | client_id is the client id of the friend | 99 | * set the data that will be sent along with friend request |
100 | data is the data and length is the length | 100 | * client_id is the client id of the friend |
101 | returns the friend number if success | 101 | * data is the data and length is the length |
102 | return -1 if message length is too long | 102 | * returns the friend number if success |
103 | return -2 if user's own key | 103 | * return -1 if message length is too long |
104 | return -3 if already a friend | 104 | * return -2 if no message (message length must be >= 1 byte) |
105 | return -4 for other*/ | 105 | * return -3 if user's own key |
106 | * return -4 if friend request already sent or already a friend | ||
107 | * return -5 for unknown error | ||
108 | */ | ||
106 | int m_addfriend(uint8_t *client_id, uint8_t *data, uint16_t length) | 109 | int m_addfriend(uint8_t *client_id, uint8_t *data, uint16_t length) |
107 | { | 110 | { |
108 | if (length >= (MAX_DATA_SIZE - crypto_box_PUBLICKEYBYTES | 111 | if (length >= (MAX_DATA_SIZE - crypto_box_PUBLICKEYBYTES |
109 | - crypto_box_NONCEBYTES - crypto_box_BOXZEROBYTES | 112 | - crypto_box_NONCEBYTES - crypto_box_BOXZEROBYTES |
110 | + crypto_box_ZEROBYTES)) | 113 | + crypto_box_ZEROBYTES)) |
111 | return -1; | 114 | return -1; |
112 | if (memcmp(client_id, self_public_key, crypto_box_PUBLICKEYBYTES) == 0) | 115 | if (length < 1) |
113 | return -2; | 116 | return -2; |
114 | if (getfriend_id(client_id) != -1) | 117 | if (memcmp(client_id, self_public_key, crypto_box_PUBLICKEYBYTES) == 0) |
115 | return -3; | 118 | return -3; |
119 | if (getfriend_id(client_id) != -1) | ||
120 | return -4; | ||
121 | |||
116 | uint32_t i; | 122 | uint32_t i; |
117 | for (i = 0; i <= numfriends; ++i) { /*TODO: dynamic memory allocation, this will segfault if there are more than MAX_NUM_FRIENDS*/ | 123 | for (i = 0; i <= numfriends; ++i) { /*TODO: dynamic memory allocation, this will segfault if there are more than MAX_NUM_FRIENDS*/ |
118 | if(friendlist[i].status == 0) { | 124 | if(friendlist[i].status == 0) { |
@@ -130,7 +136,7 @@ int m_addfriend(uint8_t *client_id, uint8_t *data, uint16_t length) | |||
130 | return i; | 136 | return i; |
131 | } | 137 | } |
132 | } | 138 | } |
133 | return -4; | 139 | return -5; |
134 | } | 140 | } |
135 | 141 | ||
136 | int m_addfriend_norequest(uint8_t * client_id) | 142 | int m_addfriend_norequest(uint8_t * client_id) |
diff --git a/testing/nTox.c b/testing/nTox.c index 17f4b0e7..f7d929f2 100644 --- a/testing/nTox.c +++ b/testing/nTox.c | |||
@@ -106,24 +106,28 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) | |||
106 | char temp_id[128]; | 106 | char temp_id[128]; |
107 | for (i = 0; i < 128; i++) | 107 | for (i = 0; i < 128; i++) |
108 | temp_id[i] = line[i+prompt_offset]; | 108 | temp_id[i] = line[i+prompt_offset]; |
109 | |||
109 | int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); | 110 | int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); |
110 | char numstring[100]; | 111 | char numstring[100]; |
111 | switch (num) { | 112 | switch (num) { |
112 | case -1: | 113 | case -1: |
113 | sprintf(numstring, "[i] Incorrect key length"); | 114 | sprintf(numstring, "[i] Message is too long."); |
114 | break; | 115 | break; |
115 | case -2: | 116 | case -2: |
116 | sprintf(numstring, "[i] That appears to be your own key"); | 117 | sprintf(numstring, "[i] Please add a message to your request."); |
117 | break; | 118 | break; |
118 | case -3: | 119 | case -3: |
119 | sprintf(numstring, "[i] Friend request already sent"); | 120 | sprintf(numstring, "[i] That appears to be your own ID."); |
120 | break; | 121 | break; |
121 | case -4: | 122 | case -4: |
122 | sprintf(numstring, "[i] Could not add friend"); | 123 | sprintf(numstring, "[i] Friend request already sent."); |
123 | break; | 124 | break; |
124 | default: | 125 | case -5: |
125 | sprintf(numstring, "[i] Added friend %d", num); | 126 | sprintf(numstring, "[i] Undefined error when adding friend."); |
126 | break; | 127 | break; |
128 | default: | ||
129 | sprintf(numstring, "[i] Added friend as %d.", num); | ||
130 | break; | ||
127 | } | 131 | } |
128 | new_lines(numstring); | 132 | new_lines(numstring); |
129 | do_refresh(); | 133 | do_refresh(); |
diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c index b9208d4f..8d9f3547 100644 --- a/testing/nTox_win32.c +++ b/testing/nTox_win32.c | |||
@@ -132,13 +132,15 @@ void line_eval(char* line) | |||
132 | printf(numstring); | 132 | printf(numstring); |
133 | } | 133 | } |
134 | else if (num == -1) | 134 | else if (num == -1) |
135 | printf("\nWrong key size\n\n"); | 135 | printf("\n[i] Message is too long.\n\n"); |
136 | else if (num == -2) | 136 | else if (num == -2) |
137 | printf("\nYou can't add yourself\n\n"); | 137 | printf("\n[i] Please add a message to your friend request.\n\n"); |
138 | else if (num == -3) | 138 | else if (num == -3) |
139 | printf("\nYou already have this person added\n\n"); | 139 | printf("\n[i] That appears to be your own ID.\n\n"); |
140 | else if (num == -4) | 140 | else if (num == -4) |
141 | printf("\nUndefined error when adding friend"); | 141 | printf("\n[i] Friend request already sent.\n\n"); |
142 | else if (num == -5) | ||
143 | printf("\n[i] Undefined error when adding friend\n\n"); | ||
142 | } | 144 | } |
143 | 145 | ||
144 | else if (inpt_command == 'r') { | 146 | else if (inpt_command == 'r') { |
diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c index 6970441f..21c1f52a 100644 --- a/testing/toxic/prompt.c +++ b/testing/toxic/prompt.c | |||
@@ -138,13 +138,15 @@ static void execute(ToxWindow* self, char* cmd) { | |||
138 | wprintw(self->window, "Message is too long.\n"); | 138 | wprintw(self->window, "Message is too long.\n"); |
139 | break; | 139 | break; |
140 | case -2: | 140 | case -2: |
141 | wprintw(self->window, "Please add a message to your request.\n"); | ||
142 | case -3: | ||
141 | wprintw(self->window, "That appears to be your own ID.\n"); | 143 | wprintw(self->window, "That appears to be your own ID.\n"); |
142 | break; | 144 | break; |
143 | case -3: | 145 | case -4: |
144 | wprintw(self->window, "Friend request already sent.\n"); | 146 | wprintw(self->window, "Friend request already sent.\n"); |
145 | break; | 147 | break; |
146 | case -4: | 148 | case -5: |
147 | wprintw(self->window, "Invalid ID.\n"); | 149 | wprintw(self->window, "[i] Undefined error when adding friend.\n"); |
148 | break; | 150 | break; |
149 | default: | 151 | default: |
150 | wprintw(self->window, "Friend added as %d.\n", num); | 152 | wprintw(self->window, "Friend added as %d.\n", num); |