diff options
Diffstat (limited to 'src/afc.c')
-rw-r--r-- | src/afc.c | 34 |
1 files changed, 19 insertions, 15 deletions
@@ -229,7 +229,9 @@ static afc_error_t afc_receive_data(afc_client_t client, char **bytes, uint32_t | |||
229 | if (recv_len == 0) { | 229 | if (recv_len == 0) { |
230 | debug_info("Just didn't get enough."); | 230 | debug_info("Just didn't get enough."); |
231 | return AFC_E_MUX_ERROR; | 231 | return AFC_E_MUX_ERROR; |
232 | } else if (recv_len < sizeof(AFCPacket)) { | 232 | } |
233 | |||
234 | if (recv_len < sizeof(AFCPacket)) { | ||
233 | debug_info("Did not even get the AFCPacket header"); | 235 | debug_info("Did not even get the AFCPacket header"); |
234 | return AFC_E_MUX_ERROR; | 236 | return AFC_E_MUX_ERROR; |
235 | } | 237 | } |
@@ -250,14 +252,14 @@ static afc_error_t afc_receive_data(afc_client_t client, char **bytes, uint32_t | |||
250 | if (header.this_length < sizeof(AFCPacket)) { | 252 | if (header.this_length < sizeof(AFCPacket)) { |
251 | debug_info("Invalid AFCPacket header received!"); | 253 | debug_info("Invalid AFCPacket header received!"); |
252 | return AFC_E_OP_HEADER_INVALID; | 254 | return AFC_E_OP_HEADER_INVALID; |
253 | } else if ((header.this_length == header.entire_length) | 255 | } |
254 | && header.entire_length == sizeof(AFCPacket)) { | 256 | if ((header.this_length == header.entire_length) |
257 | && header.entire_length == sizeof(AFCPacket)) { | ||
255 | debug_info("Empty AFCPacket received!"); | 258 | debug_info("Empty AFCPacket received!"); |
256 | if (header.operation == AFC_OP_DATA) { | 259 | if (header.operation == AFC_OP_DATA) { |
257 | return AFC_E_SUCCESS; | 260 | return AFC_E_SUCCESS; |
258 | } else { | ||
259 | return AFC_E_IO_ERROR; | ||
260 | } | 261 | } |
262 | return AFC_E_IO_ERROR; | ||
261 | } | 263 | } |
262 | 264 | ||
263 | debug_info("received AFC packet, full len=%lld, this len=%lld, operation=0x%llx", header.entire_length, header.this_length, header.operation); | 265 | debug_info("received AFC packet, full len=%lld, this len=%lld, operation=0x%llx", header.entire_length, header.this_length, header.operation); |
@@ -273,7 +275,8 @@ static afc_error_t afc_receive_data(afc_client_t client, char **bytes, uint32_t | |||
273 | free(buf); | 275 | free(buf); |
274 | debug_info("Did not get packet contents!"); | 276 | debug_info("Did not get packet contents!"); |
275 | return AFC_E_NOT_ENOUGH_DATA; | 277 | return AFC_E_NOT_ENOUGH_DATA; |
276 | } else if (recv_len < this_len) { | 278 | } |
279 | if (recv_len < this_len) { | ||
277 | free(buf); | 280 | free(buf); |
278 | debug_info("Could not receive this_len=%d bytes", this_len); | 281 | debug_info("Could not receive this_len=%d bytes", this_len); |
279 | return AFC_E_NOT_ENOUGH_DATA; | 282 | return AFC_E_NOT_ENOUGH_DATA; |
@@ -749,22 +752,23 @@ LIBIMOBILEDEVICE_API afc_error_t afc_file_read(afc_client_t client, uint64_t han | |||
749 | if (ret != AFC_E_SUCCESS) { | 752 | if (ret != AFC_E_SUCCESS) { |
750 | afc_unlock(client); | 753 | afc_unlock(client); |
751 | return ret; | 754 | return ret; |
752 | } else if (bytes_loc == 0) { | 755 | } |
756 | if (bytes_loc == 0) { | ||
753 | if (input) | 757 | if (input) |
754 | free(input); | 758 | free(input); |
755 | afc_unlock(client); | 759 | afc_unlock(client); |
756 | *bytes_read = current_count; | 760 | *bytes_read = current_count; |
757 | /* FIXME: check that's actually a success */ | 761 | /* FIXME: check that's actually a success */ |
758 | return ret; | 762 | return ret; |
759 | } else { | ||
760 | if (input) { | ||
761 | debug_info("%d", bytes_loc); | ||
762 | memcpy(data + current_count, input, (bytes_loc > length) ? length : bytes_loc); | ||
763 | free(input); | ||
764 | input = NULL; | ||
765 | current_count += (bytes_loc > length) ? length : bytes_loc; | ||
766 | } | ||
767 | } | 763 | } |
764 | if (input) { | ||
765 | debug_info("%d", bytes_loc); | ||
766 | memcpy(data + current_count, input, (bytes_loc > length) ? length : bytes_loc); | ||
767 | free(input); | ||
768 | input = NULL; | ||
769 | current_count += (bytes_loc > length) ? length : bytes_loc; | ||
770 | } | ||
771 | |||
768 | afc_unlock(client); | 772 | afc_unlock(client); |
769 | *bytes_read = current_count; | 773 | *bytes_read = current_count; |
770 | return ret; | 774 | return ret; |