diff options
author | AZ Huang <aitjcize@gmail.com> | 2013-11-29 18:26:09 +0800 |
---|---|---|
committer | AZ Huang <aitjcize@gmail.com> | 2013-11-29 18:26:09 +0800 |
commit | eec31edb1c6fe5d0ffdc79f6b38a89f6a4a9b20d (patch) | |
tree | 2ea2900d1996c54751b3d1ada9c204036ccc5b22 /toxcore/Messenger.c | |
parent | 3d5a1d96181e7cd92f673fc1bdf575baf81b8d12 (diff) |
Fix return code inconsistency.
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r-- | toxcore/Messenger.c | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 5e9758dd..a3295170 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -1185,28 +1185,28 @@ int new_filesender(Messenger *m, int friendnumber, uint64_t filesize, uint8_t *f | |||
1185 | /* Send a file control request. | 1185 | /* Send a file control request. |
1186 | * send_receive is 0 if we want the control packet to target a sending file, 1 if it targets a receiving file. | 1186 | * send_receive is 0 if we want the control packet to target a sending file, 1 if it targets a receiving file. |
1187 | * | 1187 | * |
1188 | * return 1 on success | 1188 | * return 0 on success |
1189 | * return 0 on failure | 1189 | * return -1 on failure |
1190 | */ | 1190 | */ |
1191 | int file_control(Messenger *m, int friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id, | 1191 | int file_control(Messenger *m, int friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id, |
1192 | uint8_t *data, uint16_t length) | 1192 | uint8_t *data, uint16_t length) |
1193 | { | 1193 | { |
1194 | if (length > MAX_DATA_SIZE - 3) | 1194 | if (length > MAX_DATA_SIZE - 3) |
1195 | return 0; | 1195 | return -1; |
1196 | 1196 | ||
1197 | if (friend_not_valid(m, friendnumber)) | 1197 | if (friend_not_valid(m, friendnumber)) |
1198 | return 0; | 1198 | return -1; |
1199 | 1199 | ||
1200 | if (send_receive == 1) { | 1200 | if (send_receive == 1) { |
1201 | if (m->friendlist[friendnumber].file_receiving[filenumber].status == FILESTATUS_NONE) | 1201 | if (m->friendlist[friendnumber].file_receiving[filenumber].status == FILESTATUS_NONE) |
1202 | return 0; | 1202 | return -1; |
1203 | } else { | 1203 | } else { |
1204 | if (m->friendlist[friendnumber].file_sending[filenumber].status == FILESTATUS_NONE) | 1204 | if (m->friendlist[friendnumber].file_sending[filenumber].status == FILESTATUS_NONE) |
1205 | return 0; | 1205 | return -1; |
1206 | } | 1206 | } |
1207 | 1207 | ||
1208 | if (send_receive > 1) | 1208 | if (send_receive > 1) |
1209 | return 0; | 1209 | return -1; |
1210 | 1210 | ||
1211 | uint8_t packet[MAX_DATA_SIZE]; | 1211 | uint8_t packet[MAX_DATA_SIZE]; |
1212 | packet[0] = send_receive; | 1212 | packet[0] = send_receive; |
@@ -1216,7 +1216,7 @@ int file_control(Messenger *m, int friendnumber, uint8_t send_receive, uint8_t f | |||
1216 | 1216 | ||
1217 | if (message_id == FILECONTROL_RESUME_BROKEN) { | 1217 | if (message_id == FILECONTROL_RESUME_BROKEN) { |
1218 | if (length != sizeof(uint64_t)) | 1218 | if (length != sizeof(uint64_t)) |
1219 | return 0; | 1219 | return -1; |
1220 | 1220 | ||
1221 | uint8_t remaining[sizeof(uint64_t)]; | 1221 | uint8_t remaining[sizeof(uint64_t)]; |
1222 | memcpy(remaining, data, sizeof(uint64_t)); | 1222 | memcpy(remaining, data, sizeof(uint64_t)); |
@@ -1264,32 +1264,32 @@ int file_control(Messenger *m, int friendnumber, uint8_t send_receive, uint8_t f | |||
1264 | break; | 1264 | break; |
1265 | } | 1265 | } |
1266 | 1266 | ||
1267 | return 1; | ||
1268 | } else { | ||
1269 | return 0; | 1267 | return 0; |
1268 | } else { | ||
1269 | return -1; | ||
1270 | } | 1270 | } |
1271 | } | 1271 | } |
1272 | 1272 | ||
1273 | #define MIN_SLOTS_FREE 4 | 1273 | #define MIN_SLOTS_FREE 4 |
1274 | /* Send file data. | 1274 | /* Send file data. |
1275 | * | 1275 | * |
1276 | * return 1 on success | 1276 | * return 0 on success |
1277 | * return 0 on failure | 1277 | * return -1 on failure |
1278 | */ | 1278 | */ |
1279 | int file_data(Messenger *m, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length) | 1279 | int file_data(Messenger *m, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length) |
1280 | { | 1280 | { |
1281 | if (length > MAX_DATA_SIZE - 1) | 1281 | if (length > MAX_DATA_SIZE - 1) |
1282 | return 0; | 1282 | return -1; |
1283 | 1283 | ||
1284 | if (friend_not_valid(m, friendnumber)) | 1284 | if (friend_not_valid(m, friendnumber)) |
1285 | return 0; | 1285 | return -1; |
1286 | 1286 | ||
1287 | if (m->friendlist[friendnumber].file_sending[filenumber].status != FILESTATUS_TRANSFERRING) | 1287 | if (m->friendlist[friendnumber].file_sending[filenumber].status != FILESTATUS_TRANSFERRING) |
1288 | return 0; | 1288 | return -1; |
1289 | 1289 | ||
1290 | /* Prevent file sending from filling up the entire buffer preventing messages from being sent. */ | 1290 | /* Prevent file sending from filling up the entire buffer preventing messages from being sent. */ |
1291 | if (crypto_num_free_sendqueue_slots(m->net_crypto, m->friendlist[friendnumber].crypt_connection_id) < MIN_SLOTS_FREE) | 1291 | if (crypto_num_free_sendqueue_slots(m->net_crypto, m->friendlist[friendnumber].crypt_connection_id) < MIN_SLOTS_FREE) |
1292 | return 0; | 1292 | return -1; |
1293 | 1293 | ||
1294 | uint8_t packet[MAX_DATA_SIZE]; | 1294 | uint8_t packet[MAX_DATA_SIZE]; |
1295 | packet[0] = filenumber; | 1295 | packet[0] = filenumber; |
@@ -1297,10 +1297,10 @@ int file_data(Messenger *m, int friendnumber, uint8_t filenumber, uint8_t *data, | |||
1297 | 1297 | ||
1298 | if (write_cryptpacket_id(m, friendnumber, PACKET_ID_FILE_DATA, packet, length + 1)) { | 1298 | if (write_cryptpacket_id(m, friendnumber, PACKET_ID_FILE_DATA, packet, length + 1)) { |
1299 | m->friendlist[friendnumber].file_sending[filenumber].transferred += length; | 1299 | m->friendlist[friendnumber].file_sending[filenumber].transferred += length; |
1300 | return 1; | 1300 | return 0; |
1301 | } | 1301 | } |
1302 | 1302 | ||
1303 | return 0; | 1303 | return -1; |
1304 | 1304 | ||
1305 | } | 1305 | } |
1306 | 1306 | ||
@@ -1309,22 +1309,22 @@ int file_data(Messenger *m, int friendnumber, uint8_t filenumber, uint8_t *data, | |||
1309 | * send_receive is 0 if we want the sending files, 1 if we want the receiving. | 1309 | * send_receive is 0 if we want the sending files, 1 if we want the receiving. |
1310 | * | 1310 | * |
1311 | * return number of bytes remaining to be sent/received on success | 1311 | * return number of bytes remaining to be sent/received on success |
1312 | * return 0 on failure | 1312 | * return -1 on failure |
1313 | */ | 1313 | */ |
1314 | uint64_t file_dataremaining(Messenger *m, int friendnumber, uint8_t filenumber, uint8_t send_receive) | 1314 | uint64_t file_dataremaining(Messenger *m, int friendnumber, uint8_t filenumber, uint8_t send_receive) |
1315 | { | 1315 | { |
1316 | if (friend_not_valid(m, friendnumber)) | 1316 | if (friend_not_valid(m, friendnumber)) |
1317 | return 0; | 1317 | return -1; |
1318 | 1318 | ||
1319 | if (send_receive == 0) { | 1319 | if (send_receive == 0) { |
1320 | if (m->friendlist[friendnumber].file_sending[filenumber].status == FILESTATUS_NONE) | 1320 | if (m->friendlist[friendnumber].file_sending[filenumber].status == FILESTATUS_NONE) |
1321 | return 0; | 1321 | return -1; |
1322 | 1322 | ||
1323 | return m->friendlist[friendnumber].file_sending[filenumber].size - | 1323 | return m->friendlist[friendnumber].file_sending[filenumber].size - |
1324 | m->friendlist[friendnumber].file_sending[filenumber].transferred; | 1324 | m->friendlist[friendnumber].file_sending[filenumber].transferred; |
1325 | } else { | 1325 | } else { |
1326 | if (m->friendlist[friendnumber].file_receiving[filenumber].status == FILESTATUS_NONE) | 1326 | if (m->friendlist[friendnumber].file_receiving[filenumber].status == FILESTATUS_NONE) |
1327 | return 0; | 1327 | return -1; |
1328 | 1328 | ||
1329 | return m->friendlist[friendnumber].file_receiving[filenumber].size - | 1329 | return m->friendlist[friendnumber].file_receiving[filenumber].size - |
1330 | m->friendlist[friendnumber].file_receiving[filenumber].transferred; | 1330 | m->friendlist[friendnumber].file_receiving[filenumber].transferred; |