diff options
| author | 2009-07-25 03:46:13 +0200 | |
|---|---|---|
| committer | 2009-07-25 03:46:13 +0200 | |
| commit | 8415e1f13dfc8c31fe4d1ff695af26189297795b (patch) | |
| tree | 6bf3444c4e267aa0b4bc04a22f0af4a0687e4973 /src | |
| parent | 50be30047dbb0d38fd8d61763c13ec75d2b52543 (diff) | |
| download | libimobiledevice-8415e1f13dfc8c31fe4d1ff695af26189297795b.tar.gz libimobiledevice-8415e1f13dfc8c31fe4d1ff695af26189297795b.tar.bz2 | |
Remove AFC to errno conversion and make afc_receive_data() return AFC errors
Diffstat (limited to 'src')
| -rw-r--r-- | src/AFC.c | 242 | ||||
| -rw-r--r-- | src/AFC.h | 2 |
2 files changed, 81 insertions, 163 deletions
| @@ -21,7 +21,6 @@ | |||
| 21 | 21 | ||
| 22 | #include <stdio.h> | 22 | #include <stdio.h> |
| 23 | #include <stdlib.h> | 23 | #include <stdlib.h> |
| 24 | #include <errno.h> | ||
| 25 | #include <unistd.h> | 24 | #include <unistd.h> |
| 26 | 25 | ||
| 27 | #include "AFC.h" | 26 | #include "AFC.h" |
| @@ -112,91 +111,7 @@ afc_error_t afc_client_free(afc_client_t client) | |||
| 112 | g_mutex_free(client->mutex); | 111 | g_mutex_free(client->mutex); |
| 113 | } | 112 | } |
| 114 | free(client); | 113 | free(client); |
| 115 | return IPHONE_E_SUCCESS; | 114 | return AFC_E_SUCCESS; |
| 116 | } | ||
| 117 | |||
| 118 | /** | ||
| 119 | * Returns the AFC error code that has been sent by the device if | ||
| 120 | * an error occured (set inside receive_AFC_data) | ||
| 121 | * | ||
| 122 | * @param client AFC client for that the error value is to be retrieved. | ||
| 123 | * | ||
| 124 | * @return AFC error code or -1 on error. | ||
| 125 | */ | ||
| 126 | int afc_get_afcerror(afc_client_t client) | ||
| 127 | { | ||
| 128 | int res = -1; | ||
| 129 | if (client) { | ||
| 130 | afc_lock(client); | ||
| 131 | res = client->afcerror; | ||
| 132 | afc_unlock(client); | ||
| 133 | } | ||
| 134 | return res; | ||
| 135 | } | ||
| 136 | |||
| 137 | /** | ||
| 138 | * Tries to convert the AFC error value into a meaningful errno value. | ||
| 139 | * Internally used by afc_get_errno. | ||
| 140 | * | ||
| 141 | * @param afcerror AFC error value to convert | ||
| 142 | * | ||
| 143 | * @return errno value or -1 if the errno could not be determined. | ||
| 144 | * | ||
| 145 | * @see afc_get_errno | ||
| 146 | */ | ||
| 147 | static int afcerror_to_errno(int afcerror) | ||
| 148 | { | ||
| 149 | int res = -1; | ||
| 150 | switch (afcerror) { | ||
| 151 | case 0: // ERROR_SUCCESS, this means no error. | ||
| 152 | res = 0; | ||
| 153 | break; | ||
| 154 | case 4: // occurs if you try to open a file as directory | ||
| 155 | res = ENOTDIR; | ||
| 156 | break; | ||
| 157 | case 7: // occurs e.g. if you try to close a file handle that | ||
| 158 | // does not belong to an open file | ||
| 159 | res = EINVAL; | ||
| 160 | break; | ||
| 161 | case 8: // occurs if you try to open a non-existent file | ||
| 162 | res = ENOENT; | ||
| 163 | break; | ||
| 164 | case 9: // occurs if you try to open a directory as file | ||
| 165 | res = EISDIR; | ||
| 166 | break; | ||
| 167 | case 10: // occurs if you try to open a file without permission | ||
| 168 | res = EPERM; | ||
| 169 | break; | ||
| 170 | case 19: // occurs if you try to lock an already locked file | ||
| 171 | res = EWOULDBLOCK; | ||
| 172 | break; | ||
| 173 | default: // we'll assume it's an errno value, but report it | ||
| 174 | log_debug_msg("WARNING: unknown AFC error %d, perhaps it's '%s'?\n", afcerror, strerror(afcerror)); | ||
| 175 | res = afcerror; | ||
| 176 | break; | ||
| 177 | } | ||
| 178 | |||
| 179 | log_debug_msg("Mapped AFC error %d to errno %d: %s\n", afcerror, res, strerror(res)); | ||
| 180 | |||
| 181 | return res; | ||
| 182 | } | ||
| 183 | |||
| 184 | /** | ||
| 185 | * Returns the client's AFC error code converted to an errno value. | ||
| 186 | * | ||
| 187 | * @param client AFC client for that the errno value is to be retrieved. | ||
| 188 | * | ||
| 189 | * @return errno value or -1 on error. | ||
| 190 | */ | ||
| 191 | int afc_get_errno(afc_client_t client) | ||
| 192 | { | ||
| 193 | int res = -1; | ||
| 194 | if (client) { | ||
| 195 | afc_lock(client); | ||
| 196 | res = afcerror_to_errno(client->afcerror); | ||
| 197 | afc_unlock(client); | ||
| 198 | } | ||
| 199 | return res; | ||
| 200 | } | 115 | } |
| 201 | 116 | ||
| 202 | /** Dispatches an AFC packet over a client. | 117 | /** Dispatches an AFC packet over a client. |
| @@ -294,28 +209,26 @@ static int afc_dispatch_packet(afc_client_t client, const char *data, uint64_t l | |||
| 294 | * received raised a non-trivial error condition (i.e. non-zero with | 209 | * received raised a non-trivial error condition (i.e. non-zero with |
| 295 | * AFC_ERROR operation) | 210 | * AFC_ERROR operation) |
| 296 | */ | 211 | */ |
| 297 | static int receive_AFC_data(afc_client_t client, char **dump_here) | 212 | static afc_error_t afc_receive_data(afc_client_t client, char **dump_here, int *bytes) |
| 298 | { | 213 | { |
| 299 | AFCPacket header; | 214 | AFCPacket header; |
| 300 | int bytes = 0; | ||
| 301 | uint32_t entire_len = 0; | 215 | uint32_t entire_len = 0; |
| 302 | uint32_t this_len = 0; | 216 | uint32_t this_len = 0; |
| 303 | uint32_t current_count = 0; | 217 | uint32_t current_count = 0; |
| 304 | uint64_t param1 = -1; | 218 | uint64_t param1 = -1; |
| 305 | 219 | ||
| 306 | // reset internal afc error value | 220 | *bytes = 0; |
| 307 | client->afcerror = 0; | ||
| 308 | 221 | ||
| 309 | // first, read the AFC header | 222 | /* first, read the AFC header */ |
| 310 | usbmuxd_recv(client->sfd, (char*)&header, sizeof(AFCPacket), (uint32_t*)&bytes); | 223 | usbmuxd_recv(client->sfd, (char*)&header, sizeof(AFCPacket), (uint32_t*)bytes); |
| 311 | if (bytes <= 0) { | 224 | if (*bytes <= 0) { |
| 312 | log_debug_msg("%s: Just didn't get enough.\n", __func__); | 225 | log_debug_msg("%s: Just didn't get enough.\n", __func__); |
| 313 | *dump_here = NULL; | 226 | *dump_here = NULL; |
| 314 | return -1; | 227 | return AFC_E_MUX_ERROR; |
| 315 | } else if ((uint32_t)bytes < sizeof(AFCPacket)) { | 228 | } else if ((uint32_t)*bytes < sizeof(AFCPacket)) { |
| 316 | log_debug_msg("%s: Did not even get the AFCPacket header\n", __func__); | 229 | log_debug_msg("%s: Did not even get the AFCPacket header\n", __func__); |
| 317 | *dump_here = NULL; | 230 | *dump_here = NULL; |
| 318 | return -1; | 231 | return AFC_E_MUX_ERROR; |
| 319 | } | 232 | } |
| 320 | 233 | ||
| 321 | /* check if it's a valid AFC header */ | 234 | /* check if it's a valid AFC header */ |
| @@ -328,23 +241,23 @@ static int receive_AFC_data(afc_client_t client, char **dump_here) | |||
| 328 | /* otherwise print a warning but do not abort */ | 241 | /* otherwise print a warning but do not abort */ |
| 329 | log_debug_msg("%s: ERROR: Unexpected packet number (%lld != %lld) aborting.\n", __func__, header.packet_num, client->afc_packet->packet_num); | 242 | log_debug_msg("%s: ERROR: Unexpected packet number (%lld != %lld) aborting.\n", __func__, header.packet_num, client->afc_packet->packet_num); |
| 330 | *dump_here = NULL; | 243 | *dump_here = NULL; |
| 331 | return -1; | 244 | return AFC_E_OP_HEADER_INVALID; |
| 332 | } | 245 | } |
| 333 | 246 | ||
| 334 | /* then, read the attached packet */ | 247 | /* then, read the attached packet */ |
| 335 | if (header.this_length < sizeof(AFCPacket)) { | 248 | if (header.this_length < sizeof(AFCPacket)) { |
| 336 | log_debug_msg("%s: Invalid AFCPacket header received!\n", __func__); | 249 | log_debug_msg("%s: Invalid AFCPacket header received!\n", __func__); |
| 337 | *dump_here = NULL; | 250 | *dump_here = NULL; |
| 338 | return -1; | 251 | return AFC_E_OP_HEADER_INVALID; |
| 339 | } else if ((header.this_length == header.entire_length) | 252 | } else if ((header.this_length == header.entire_length) |
| 340 | && header.entire_length == sizeof(AFCPacket)) { | 253 | && header.entire_length == sizeof(AFCPacket)) { |
| 341 | log_debug_msg("%s: Empty AFCPacket received!\n", __func__); | 254 | log_debug_msg("%s: Empty AFCPacket received!\n", __func__); |
| 342 | *dump_here = NULL; | 255 | *dump_here = NULL; |
| 256 | *bytes = 0; | ||
| 343 | if (header.operation == AFC_OP_DATA) { | 257 | if (header.operation == AFC_OP_DATA) { |
| 344 | return 0; | 258 | return AFC_E_SUCCESS; |
| 345 | } else { | 259 | } else { |
| 346 | client->afcerror = EIO; | 260 | return AFC_E_IO_ERROR; |
| 347 | return -1; | ||
| 348 | } | 261 | } |
| 349 | } | 262 | } |
| 350 | 263 | ||
| @@ -360,17 +273,17 @@ static int receive_AFC_data(afc_client_t client, char **dump_here) | |||
| 360 | 273 | ||
| 361 | *dump_here = (char*)malloc(entire_len); | 274 | *dump_here = (char*)malloc(entire_len); |
| 362 | if (this_len > 0) { | 275 | if (this_len > 0) { |
| 363 | usbmuxd_recv(client->sfd, *dump_here, this_len, (uint32_t*)&bytes); | 276 | usbmuxd_recv(client->sfd, *dump_here, this_len, (uint32_t*)bytes); |
| 364 | if (bytes <= 0) { | 277 | if (*bytes <= 0) { |
| 365 | free(*dump_here); | 278 | free(*dump_here); |
| 366 | *dump_here = NULL; | 279 | *dump_here = NULL; |
| 367 | log_debug_msg("%s: Did not get packet contents!\n", __func__); | 280 | log_debug_msg("%s: Did not get packet contents!\n", __func__); |
| 368 | return -1; | 281 | return AFC_E_NOT_ENOUGH_DATA; |
| 369 | } else if ((uint32_t)bytes < this_len) { | 282 | } else if ((uint32_t)*bytes < this_len) { |
| 370 | free(*dump_here); | 283 | free(*dump_here); |
| 371 | *dump_here = NULL; | 284 | *dump_here = NULL; |
| 372 | log_debug_msg("%s: Could not receive this_len=%d bytes\n", __func__, this_len); | 285 | log_debug_msg("%s: Could not receive this_len=%d bytes\n", __func__, this_len); |
| 373 | return -1; | 286 | return AFC_E_NOT_ENOUGH_DATA; |
| 374 | } | 287 | } |
| 375 | } | 288 | } |
| 376 | 289 | ||
| @@ -378,12 +291,12 @@ static int receive_AFC_data(afc_client_t client, char **dump_here) | |||
| 378 | 291 | ||
| 379 | if (entire_len > this_len) { | 292 | if (entire_len > this_len) { |
| 380 | while (current_count < entire_len) { | 293 | while (current_count < entire_len) { |
| 381 | usbmuxd_recv(client->sfd, (*dump_here)+current_count, entire_len - current_count, (uint32_t*)&bytes); | 294 | usbmuxd_recv(client->sfd, (*dump_here)+current_count, entire_len - current_count, (uint32_t*)bytes); |
| 382 | if (bytes <= 0) { | 295 | if (*bytes <= 0) { |
| 383 | log_debug_msg("%s: Error receiving data (recv returned %d)\n", __func__, bytes); | 296 | log_debug_msg("%s: Error receiving data (recv returned %d)\n", __func__, *bytes); |
| 384 | break; | 297 | break; |
| 385 | } | 298 | } |
| 386 | current_count += bytes; | 299 | current_count += *bytes; |
| 387 | } | 300 | } |
| 388 | if (current_count < entire_len) { | 301 | if (current_count < entire_len) { |
| 389 | log_debug_msg("%s: WARNING: could not receive full packet (read %s, size %d)\n", __func__, current_count, entire_len); | 302 | log_debug_msg("%s: WARNING: could not receive full packet (read %s, size %d)\n", __func__, current_count, entire_len); |
| @@ -394,39 +307,42 @@ static int receive_AFC_data(afc_client_t client, char **dump_here) | |||
| 394 | param1 = *(uint64_t*)(*dump_here); | 307 | param1 = *(uint64_t*)(*dump_here); |
| 395 | } | 308 | } |
| 396 | 309 | ||
| 397 | // check for errors | 310 | log_debug_msg("%s: packet data size = %i\n", __func__, current_count); |
| 398 | if (header.operation == AFC_OP_DATA) { | 311 | log_debug_msg("%s: packet data follows\n", __func__); |
| 399 | // we got a positive response! | 312 | log_debug_buffer(*dump_here, current_count); |
| 400 | log_debug_msg("%s: got a success response\n", __func__); | 313 | |
| 401 | } else if (header.operation == AFC_OP_FILE_OPEN_RES) { | 314 | /* check operation types */ |
| 402 | // we got a file handle response | 315 | if (header.operation == AFC_OP_STATUS) { |
| 403 | log_debug_msg("%s: got a file handle response, handle=%lld\n", __func__, param1); | 316 | /* status response */ |
| 404 | } else if (header.operation == AFC_OP_STATUS) { | 317 | log_debug_msg("%s: got a status response, code=%lld\n", __func__, param1); |
| 405 | // error message received | 318 | |
| 406 | if (param1 == 0) { | 319 | if (param1 != AFC_E_SUCCESS) { |
| 407 | // ERROR_SUCCESS, this is not an error! | 320 | /* error status */ |
| 408 | log_debug_msg("%s: ERROR_SUCCESS\n", __func__); | 321 | /* free buffer */ |
| 409 | } else { | ||
| 410 | // but this is an error! | ||
| 411 | log_debug_msg("%s: ERROR %lld\n", __func__, param1); | ||
| 412 | free(*dump_here); | 322 | free(*dump_here); |
| 413 | *dump_here = NULL; | 323 | *dump_here = NULL; |
| 414 | // store error value | 324 | return (afc_error_t)param1; |
| 415 | client->afcerror = (int)param1; | ||
| 416 | afcerror_to_errno(client->afcerror); | ||
| 417 | return -1; | ||
| 418 | } | 325 | } |
| 326 | } else if (header.operation == AFC_OP_DATA) { | ||
| 327 | /* data response */ | ||
| 328 | log_debug_msg("%s: got a data response\n", __func__); | ||
| 329 | } else if (header.operation == AFC_OP_FILE_OPEN_RES) { | ||
| 330 | /* file handle response */ | ||
| 331 | log_debug_msg("%s: got a file handle response, handle=%lld\n", __func__, param1); | ||
| 419 | } else { | 332 | } else { |
| 420 | /* unknown operation code received */ | 333 | /* unknown operation code received */ |
| 421 | free(*dump_here); | 334 | free(*dump_here); |
| 422 | *dump_here = NULL; | 335 | *dump_here = NULL; |
| 336 | *bytes = 0; | ||
| 423 | 337 | ||
| 424 | log_debug_msg("%s: WARNING: Unknown operation code received 0x%llx param1=%lld\n", __func__, header.operation, param1); | 338 | log_debug_msg("%s: WARNING: Unknown operation code received 0x%llx param1=%lld\n", __func__, header.operation, param1); |
| 425 | fprintf(stderr, "%s: WARNING: Unknown operation code received 0x%llx param1=%lld\n", __func__, header.operation, param1); | 339 | fprintf(stderr, "%s: WARNING: Unknown operation code received 0x%llx param1=%lld\n", __func__, header.operation, param1); |
| 426 | 340 | ||
| 427 | return -1; | 341 | return AFC_E_OP_NOT_SUPPORTED; |
| 428 | } | 342 | } |
| 429 | return current_count; | 343 | |
| 344 | *bytes = current_count; | ||
| 345 | return AFC_E_SUCCESS; | ||
| 430 | } | 346 | } |
| 431 | 347 | ||
| 432 | static int count_nullspaces(char *string, int number) | 348 | static int count_nullspaces(char *string, int number) |
| @@ -489,15 +405,13 @@ afc_error_t afc_read_directory(afc_client_t client, const char *dir, char ***lis | |||
| 489 | return AFC_E_NOT_ENOUGH_DATA; | 405 | return AFC_E_NOT_ENOUGH_DATA; |
| 490 | } | 406 | } |
| 491 | // Receive the data | 407 | // Receive the data |
| 492 | bytes = receive_AFC_data(client, &data); | 408 | ret = afc_receive_data(client, &data, &bytes); |
| 493 | if (bytes < 0) { | 409 | if (ret != AFC_E_SUCCESS) { |
| 494 | afc_unlock(client); | 410 | afc_unlock(client); |
| 495 | return IPHONE_E_AFC_ERROR; | 411 | return ret; |
| 496 | } | 412 | } |
| 497 | // Parse the data | 413 | // Parse the data |
| 498 | list_loc = make_strings_list(data, bytes); | 414 | list_loc = make_strings_list(data, bytes); |
| 499 | if (list_loc) | ||
| 500 | ret = IPHONE_E_SUCCESS; | ||
| 501 | if (data) | 415 | if (data) |
| 502 | free(data); | 416 | free(data); |
| 503 | 417 | ||
| @@ -534,10 +448,10 @@ afc_error_t afc_get_device_info(afc_client_t client, char ***infos) | |||
| 534 | return AFC_E_NOT_ENOUGH_DATA; | 448 | return AFC_E_NOT_ENOUGH_DATA; |
| 535 | } | 449 | } |
| 536 | // Receive the data | 450 | // Receive the data |
| 537 | bytes = receive_AFC_data(client, &data); | 451 | ret = afc_receive_data(client, &data, &bytes); |
| 538 | if (bytes < 0) { | 452 | if (ret != AFC_E_SUCCESS) { |
| 539 | afc_unlock(client); | 453 | afc_unlock(client); |
| 540 | return IPHONE_E_AFC_ERROR; | 454 | return ret; |
| 541 | } | 455 | } |
| 542 | // Parse the data | 456 | // Parse the data |
| 543 | list = make_strings_list(data, bytes); | 457 | list = make_strings_list(data, bytes); |
| @@ -579,7 +493,7 @@ afc_error_t afc_remove_path(afc_client_t client, const char *path) | |||
| 579 | return AFC_E_NOT_ENOUGH_DATA; | 493 | return AFC_E_NOT_ENOUGH_DATA; |
| 580 | } | 494 | } |
| 581 | // Receive response | 495 | // Receive response |
| 582 | bytes = receive_AFC_data(client, &response); | 496 | ret = afc_receive_data(client, &response, &bytes); |
| 583 | if (response) | 497 | if (response) |
| 584 | free(response); | 498 | free(response); |
| 585 | 499 | ||
| @@ -621,7 +535,7 @@ afc_error_t afc_rename_path(afc_client_t client, const char *from, const char *t | |||
| 621 | return AFC_E_NOT_ENOUGH_DATA; | 535 | return AFC_E_NOT_ENOUGH_DATA; |
| 622 | } | 536 | } |
| 623 | // Receive response | 537 | // Receive response |
| 624 | bytes = receive_AFC_data(client, &response); | 538 | ret = afc_receive_data(client, &response, &bytes); |
| 625 | if (response) | 539 | if (response) |
| 626 | free(response); | 540 | free(response); |
| 627 | 541 | ||
| @@ -659,7 +573,7 @@ afc_error_t afc_make_directory(afc_client_t client, const char *dir) | |||
| 659 | return AFC_E_NOT_ENOUGH_DATA; | 573 | return AFC_E_NOT_ENOUGH_DATA; |
| 660 | } | 574 | } |
| 661 | // Receive response | 575 | // Receive response |
| 662 | bytes = receive_AFC_data(client, &response); | 576 | ret = afc_receive_data(client, &response, &bytes); |
| 663 | if (response) | 577 | if (response) |
| 664 | free(response); | 578 | free(response); |
| 665 | 579 | ||
| @@ -696,14 +610,12 @@ afc_error_t afc_get_file_info(afc_client_t client, const char *path, char ***inf | |||
| 696 | afc_dispatch_packet(client, path, strlen(path)+1); | 610 | afc_dispatch_packet(client, path, strlen(path)+1); |
| 697 | 611 | ||
| 698 | // Receive data | 612 | // Receive data |
| 699 | length = receive_AFC_data(client, &received); | 613 | ret = afc_receive_data(client, &received, &bytes); |
| 700 | if (received) { | 614 | if (received) { |
| 701 | *infolist = make_strings_list(received, bytes); | 615 | *infolist = make_strings_list(received, bytes); |
| 702 | free(received); | 616 | free(received); |
| 703 | } | 617 | } |
| 704 | 618 | ||
| 705 | log_debug_msg("%s: Didn't get any further data\n", __func__); | ||
| 706 | |||
| 707 | afc_unlock(client); | 619 | afc_unlock(client); |
| 708 | 620 | ||
| 709 | return ret; | 621 | return ret; |
| @@ -754,8 +666,8 @@ afc_file_open(afc_client_t client, const char *filename, | |||
| 754 | return AFC_E_NOT_ENOUGH_DATA; | 666 | return AFC_E_NOT_ENOUGH_DATA; |
| 755 | } | 667 | } |
| 756 | // Receive the data | 668 | // Receive the data |
| 757 | length = receive_AFC_data(client, &data); | 669 | ret = afc_receive_data(client, &data, &bytes); |
| 758 | if (length > 0 && data) { | 670 | if ((ret == AFC_E_SUCCESS) && (bytes > 0) && data) { |
| 759 | afc_unlock(client); | 671 | afc_unlock(client); |
| 760 | 672 | ||
| 761 | // Get the file handle | 673 | // Get the file handle |
| @@ -764,6 +676,8 @@ afc_file_open(afc_client_t client, const char *filename, | |||
| 764 | return ret; | 676 | return ret; |
| 765 | } | 677 | } |
| 766 | 678 | ||
| 679 | log_debug_msg("%s: Didn't get any further data\n", __func__); | ||
| 680 | |||
| 767 | afc_unlock(client); | 681 | afc_unlock(client); |
| 768 | 682 | ||
| 769 | return ret; | 683 | return ret; |
| @@ -811,9 +725,10 @@ afc_file_read(afc_client_t client, uint64_t handle, char *data, int length, uint | |||
| 811 | return AFC_E_NOT_ENOUGH_DATA; | 725 | return AFC_E_NOT_ENOUGH_DATA; |
| 812 | } | 726 | } |
| 813 | // Receive the data | 727 | // Receive the data |
| 814 | bytes_loc = receive_AFC_data(client, &input); | 728 | ret = afc_receive_data(client, &input, &bytes_loc); |
| 815 | log_debug_msg("%s: bytes returned: %i\n", __func__, bytes_loc); | 729 | log_debug_msg("%s: afc_receive_data returned error: %d\n", __func__, ret); |
| 816 | if (bytes_loc < 0) { | 730 | log_debug_msg("%s: bytes returned: %i\n", __func__, bytes_loc); |
| 731 | if (ret != AFC_E_SUCCESS) { | ||
| 817 | afc_unlock(client); | 732 | afc_unlock(client); |
| 818 | return ret; | 733 | return ret; |
| 819 | } else if (bytes_loc == 0) { | 734 | } else if (bytes_loc == 0) { |
| @@ -887,8 +802,8 @@ afc_file_write(afc_client_t client, uint64_t handle, | |||
| 887 | out_buffer = NULL; | 802 | out_buffer = NULL; |
| 888 | 803 | ||
| 889 | current_count += bytes_loc; | 804 | current_count += bytes_loc; |
| 890 | bytes_loc = receive_AFC_data(client, &acknowledgement); | 805 | ret = afc_receive_data(client, &acknowledgement, &bytes_loc); |
| 891 | if (bytes_loc < 0) { | 806 | if (ret != AFC_E_SUCCESS) { |
| 892 | afc_unlock(client); | 807 | afc_unlock(client); |
| 893 | return ret; | 808 | return ret; |
| 894 | } else { | 809 | } else { |
| @@ -925,9 +840,9 @@ afc_file_write(afc_client_t client, uint64_t handle, | |||
| 925 | } | 840 | } |
| 926 | 841 | ||
| 927 | zero = bytes_loc; | 842 | zero = bytes_loc; |
| 928 | bytes_loc = receive_AFC_data(client, &acknowledgement); | 843 | ret = afc_receive_data(client, &acknowledgement, &bytes_loc); |
| 929 | afc_unlock(client); | 844 | afc_unlock(client); |
| 930 | if (bytes_loc < 0) { | 845 | if (ret != AFC_E_SUCCESS) { |
| 931 | log_debug_msg("%s: uh oh?\n", __func__); | 846 | log_debug_msg("%s: uh oh?\n", __func__); |
| 932 | } else { | 847 | } else { |
| 933 | free(acknowledgement); | 848 | free(acknowledgement); |
| @@ -968,7 +883,7 @@ afc_error_t afc_file_close(afc_client_t client, uint64_t handle) | |||
| 968 | } | 883 | } |
| 969 | 884 | ||
| 970 | // Receive the response | 885 | // Receive the response |
| 971 | bytes = receive_AFC_data(client, &buffer); | 886 | ret = afc_receive_data(client, &buffer, &bytes); |
| 972 | if (buffer) | 887 | if (buffer) |
| 973 | free(buffer); | 888 | free(buffer); |
| 974 | 889 | ||
| @@ -1018,7 +933,7 @@ afc_error_t afc_file_lock(afc_client_t client, uint64_t handle, afc_lock_op_t op | |||
| 1018 | return AFC_E_UNKNOWN_ERROR; | 933 | return AFC_E_UNKNOWN_ERROR; |
| 1019 | } | 934 | } |
| 1020 | // Receive the response | 935 | // Receive the response |
| 1021 | bytes = receive_AFC_data(client, &buffer); | 936 | ret = afc_receive_data(client, &buffer, &bytes); |
| 1022 | if (buffer) { | 937 | if (buffer) { |
| 1023 | log_debug_buffer(buffer, bytes); | 938 | log_debug_buffer(buffer, bytes); |
| 1024 | free(buffer); | 939 | free(buffer); |
| @@ -1065,7 +980,7 @@ afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset, | |||
| 1065 | return AFC_E_NOT_ENOUGH_DATA; | 980 | return AFC_E_NOT_ENOUGH_DATA; |
| 1066 | } | 981 | } |
| 1067 | // Receive response | 982 | // Receive response |
| 1068 | bytes = receive_AFC_data(client, &buffer); | 983 | ret = afc_receive_data(client, &buffer, &bytes); |
| 1069 | if (buffer) | 984 | if (buffer) |
| 1070 | free(buffer); | 985 | free(buffer); |
| 1071 | 986 | ||
| @@ -1074,7 +989,12 @@ afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset, | |||
| 1074 | if (bytes < 0) { | 989 | if (bytes < 0) { |
| 1075 | return IPHONE_E_AFC_ERROR; | 990 | return IPHONE_E_AFC_ERROR; |
| 1076 | } | 991 | } |
| 1077 | return IPHONE_E_SUCCESS; | 992 | if (buffer) |
| 993 | free(buffer); | ||
| 994 | |||
| 995 | afc_unlock(client); | ||
| 996 | |||
| 997 | return ret; | ||
| 1078 | } | 998 | } |
| 1079 | 999 | ||
| 1080 | /** Sets the size of a file on the phone. | 1000 | /** Sets the size of a file on the phone. |
| @@ -1113,7 +1033,7 @@ afc_error_t afc_file_truncate(afc_client_t client, uint64_t handle, uint64_t new | |||
| 1113 | return AFC_E_NOT_ENOUGH_DATA; | 1033 | return AFC_E_NOT_ENOUGH_DATA; |
| 1114 | } | 1034 | } |
| 1115 | // Receive response | 1035 | // Receive response |
| 1116 | bytes = receive_AFC_data(client, &buffer); | 1036 | ret = afc_receive_data(client, &buffer, &bytes); |
| 1117 | if (buffer) | 1037 | if (buffer) |
| 1118 | free(buffer); | 1038 | free(buffer); |
| 1119 | 1039 | ||
| @@ -1156,7 +1076,7 @@ afc_error_t afc_truncate(afc_client_t client, const char *path, off_t newsize) | |||
| 1156 | return AFC_E_NOT_ENOUGH_DATA; | 1076 | return AFC_E_NOT_ENOUGH_DATA; |
| 1157 | } | 1077 | } |
| 1158 | // Receive response | 1078 | // Receive response |
| 1159 | bytes = receive_AFC_data(client, &response); | 1079 | ret = afc_receive_data(client, &response, &bytes); |
| 1160 | if (response) | 1080 | if (response) |
| 1161 | free(response); | 1081 | free(response); |
| 1162 | 1082 | ||
| @@ -1205,7 +1125,7 @@ afc_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, const c | |||
| 1205 | return AFC_E_NOT_ENOUGH_DATA; | 1125 | return AFC_E_NOT_ENOUGH_DATA; |
| 1206 | } | 1126 | } |
| 1207 | // Receive response | 1127 | // Receive response |
| 1208 | bytes = receive_AFC_data(client, &response); | 1128 | ret = afc_receive_data(client, &response, &bytes); |
| 1209 | if (response) | 1129 | if (response) |
| 1210 | free(response); | 1130 | free(response); |
| 1211 | 1131 | ||
| @@ -50,7 +50,6 @@ struct afc_client_int { | |||
| 50 | AFCPacket *afc_packet; | 50 | AFCPacket *afc_packet; |
| 51 | int file_handle; | 51 | int file_handle; |
| 52 | int lock; | 52 | int lock; |
| 53 | int afcerror; | ||
| 54 | GMutex *mutex; | 53 | GMutex *mutex; |
| 55 | }; | 54 | }; |
| 56 | 55 | ||
| @@ -86,4 +85,3 @@ enum { | |||
| 86 | AFC_OP_MAKE_LINK = 0x0000001C // MakeLink | 85 | AFC_OP_MAKE_LINK = 0x0000001C // MakeLink |
| 87 | }; | 86 | }; |
| 88 | 87 | ||
| 89 | static int afcerror_to_errno(int afcerror); | ||
