summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/libimobiledevice/afc.h2
-rw-r--r--src/afc.c69
2 files changed, 33 insertions, 38 deletions
diff --git a/include/libimobiledevice/afc.h b/include/libimobiledevice/afc.h
index 790df3d..d800d19 100644
--- a/include/libimobiledevice/afc.h
+++ b/include/libimobiledevice/afc.h
@@ -37,7 +37,7 @@ extern "C" {
37#define AFC_E_READ_ERROR 4 37#define AFC_E_READ_ERROR 4
38#define AFC_E_WRITE_ERROR 5 38#define AFC_E_WRITE_ERROR 5
39#define AFC_E_UNKNOWN_PACKET_TYPE 6 39#define AFC_E_UNKNOWN_PACKET_TYPE 6
40#define AFC_E_INVALID_ARGUMENT 7 40#define AFC_E_INVALID_ARG 7
41#define AFC_E_OBJECT_NOT_FOUND 8 41#define AFC_E_OBJECT_NOT_FOUND 8
42#define AFC_E_OBJECT_IS_DIR 9 42#define AFC_E_OBJECT_IS_DIR 9
43#define AFC_E_PERM_DENIED 10 43#define AFC_E_PERM_DENIED 10
diff --git a/src/afc.c b/src/afc.c
index f872ed9..e2e84e2 100644
--- a/src/afc.c
+++ b/src/afc.c
@@ -57,9 +57,9 @@ static void afc_unlock(afc_client_t client)
57 * @param client Pointer that will be set to a newly allocated afc_client_t 57 * @param client Pointer that will be set to a newly allocated afc_client_t
58 * upon successful return. 58 * upon successful return.
59 * 59 *
60 * @return AFC_E_SUCCESS on success, AFC_E_INVALID_ARGUMENT when device or port 60 * @return AFC_E_SUCCESS on success, AFC_E_INVALID_ARG when device or port is
61 * is invalid, AFC_E_MUX_ERROR when the connection failed, or AFC_E_NO_MEM 61 * invalid, AFC_E_MUX_ERROR when the connection failed, or AFC_E_NO_MEM if
62 * when there's a memory allocation problem. 62 * there is a memory allocation problem.
63 */ 63 */
64afc_error_t afc_client_new(idevice_t device, uint16_t port, afc_client_t * client) 64afc_error_t afc_client_new(idevice_t device, uint16_t port, afc_client_t * client)
65{ 65{
@@ -68,7 +68,7 @@ afc_error_t afc_client_new(idevice_t device, uint16_t port, afc_client_t * clien
68 g_thread_init(NULL); 68 g_thread_init(NULL);
69 69
70 if (!device || port==0) 70 if (!device || port==0)
71 return AFC_E_INVALID_ARGUMENT; 71 return AFC_E_INVALID_ARG;
72 72
73 /* attempt connection */ 73 /* attempt connection */
74 idevice_connection_t connection = NULL; 74 idevice_connection_t connection = NULL;
@@ -99,14 +99,15 @@ afc_error_t afc_client_new(idevice_t device, uint16_t port, afc_client_t * clien
99 return AFC_E_SUCCESS; 99 return AFC_E_SUCCESS;
100} 100}
101 101
102/** Disconnects an AFC client from the phone. 102/**
103 * Disconnects an AFC client from the phone.
103 * 104 *
104 * @param client The client to disconnect. 105 * @param client The client to disconnect.
105 */ 106 */
106afc_error_t afc_client_free(afc_client_t client) 107afc_error_t afc_client_free(afc_client_t client)
107{ 108{
108 if (!client || !client->connection || !client->afc_packet) 109 if (!client || !client->connection || !client->afc_packet)
109 return AFC_E_INVALID_ARGUMENT; 110 return AFC_E_INVALID_ARG;
110 111
111 idevice_disconnect(client->connection); 112 idevice_disconnect(client->connection);
112 free(client->afc_packet); 113 free(client->afc_packet);
@@ -137,7 +138,7 @@ static afc_error_t afc_dispatch_packet(afc_client_t client, const char *data, ui
137 uint32_t sent = 0; 138 uint32_t sent = 0;
138 139
139 if (!client || !client->connection || !client->afc_packet) 140 if (!client || !client->connection || !client->afc_packet)
140 return AFC_E_INVALID_ARGUMENT; 141 return AFC_E_INVALID_ARG;
141 142
142 *bytes_sent = 0; 143 *bytes_sent = 0;
143 144
@@ -416,7 +417,7 @@ afc_error_t afc_read_directory(afc_client_t client, const char *dir, char ***lis
416 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 417 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
417 418
418 if (!client || !dir || !list || (list && *list)) 419 if (!client || !dir || !list || (list && *list))
419 return AFC_E_INVALID_ARGUMENT; 420 return AFC_E_INVALID_ARG;
420 421
421 afc_lock(client); 422 afc_lock(client);
422 423
@@ -460,7 +461,7 @@ afc_error_t afc_get_device_info(afc_client_t client, char ***infos)
460 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 461 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
461 462
462 if (!client || !infos) 463 if (!client || !infos)
463 return AFC_E_INVALID_ARGUMENT; 464 return AFC_E_INVALID_ARG;
464 465
465 afc_lock(client); 466 afc_lock(client);
466 467
@@ -507,7 +508,7 @@ afc_error_t afc_get_device_info_key(afc_client_t client, const char *key, char *
507 508
508 *value = NULL; 509 *value = NULL;
509 if (key == NULL) 510 if (key == NULL)
510 return AFC_E_INVALID_ARGUMENT; 511 return AFC_E_INVALID_ARG;
511 512
512 ret = afc_get_device_info(client, &kvps); 513 ret = afc_get_device_info(client, &kvps);
513 if (ret != AFC_E_SUCCESS) 514 if (ret != AFC_E_SUCCESS)
@@ -530,8 +531,7 @@ afc_error_t afc_get_device_info_key(afc_client_t client, const char *key, char *
530 * @param client The client to use. 531 * @param client The client to use.
531 * @param path The path to delete. (must be a fully-qualified path) 532 * @param path The path to delete. (must be a fully-qualified path)
532 * 533 *
533 * @return AFC_E_SUCCESS if everythong went well, AFC_E_INVALID_ARGUMENT 534 * @return AFC_E_SUCCESS on success or an AFC_E_* error value.
534 * if arguments are NULL or invalid, AFC_E_NOT_ENOUGH_DATA otherwise.
535 */ 535 */
536afc_error_t afc_remove_path(afc_client_t client, const char *path) 536afc_error_t afc_remove_path(afc_client_t client, const char *path)
537{ 537{
@@ -540,7 +540,7 @@ afc_error_t afc_remove_path(afc_client_t client, const char *path)
540 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 540 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
541 541
542 if (!client || !path || !client->afc_packet || !client->connection) 542 if (!client || !path || !client->afc_packet || !client->connection)
543 return AFC_E_INVALID_ARGUMENT; 543 return AFC_E_INVALID_ARG;
544 544
545 afc_lock(client); 545 afc_lock(client);
546 546
@@ -572,8 +572,7 @@ afc_error_t afc_remove_path(afc_client_t client, const char *path)
572 * @param from The name to rename from. (must be a fully-qualified path) 572 * @param from The name to rename from. (must be a fully-qualified path)
573 * @param to The new name. (must also be a fully-qualified path) 573 * @param to The new name. (must also be a fully-qualified path)
574 * 574 *
575 * @return AFC_E_SUCCESS if everythong went well, AFC_E_INVALID_ARGUMENT 575 * @return AFC_E_SUCCESS on success or an AFC_E_* error value.
576 * if arguments are NULL or invalid, AFC_E_NOT_ENOUGH_DATA otherwise.
577 */ 576 */
578afc_error_t afc_rename_path(afc_client_t client, const char *from, const char *to) 577afc_error_t afc_rename_path(afc_client_t client, const char *from, const char *to)
579{ 578{
@@ -583,7 +582,7 @@ afc_error_t afc_rename_path(afc_client_t client, const char *from, const char *t
583 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 582 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
584 583
585 if (!client || !from || !to || !client->afc_packet || !client->connection) 584 if (!client || !from || !to || !client->afc_packet || !client->connection)
586 return AFC_E_INVALID_ARGUMENT; 585 return AFC_E_INVALID_ARG;
587 586
588 afc_lock(client); 587 afc_lock(client);
589 588
@@ -614,8 +613,7 @@ afc_error_t afc_rename_path(afc_client_t client, const char *from, const char *t
614 * @param dir The directory's path. (must be a fully-qualified path, I assume 613 * @param dir The directory's path. (must be a fully-qualified path, I assume
615 * all other mkdir restrictions apply as well) 614 * all other mkdir restrictions apply as well)
616 * 615 *
617 * @return AFC_E_SUCCESS if everythong went well, AFC_E_INVALID_ARGUMENT 616 * @return AFC_E_SUCCESS on success or an AFC_E_* error value.
618 * if arguments are NULL or invalid, AFC_E_NOT_ENOUGH_DATA otherwise.
619 */ 617 */
620afc_error_t afc_make_directory(afc_client_t client, const char *dir) 618afc_error_t afc_make_directory(afc_client_t client, const char *dir)
621{ 619{
@@ -624,7 +622,7 @@ afc_error_t afc_make_directory(afc_client_t client, const char *dir)
624 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 622 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
625 623
626 if (!client) 624 if (!client)
627 return AFC_E_INVALID_ARGUMENT; 625 return AFC_E_INVALID_ARG;
628 626
629 afc_lock(client); 627 afc_lock(client);
630 628
@@ -664,7 +662,7 @@ afc_error_t afc_get_file_info(afc_client_t client, const char *path, char ***inf
664 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 662 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
665 663
666 if (!client || !path || !infolist) 664 if (!client || !path || !infolist)
667 return AFC_E_INVALID_ARGUMENT; 665 return AFC_E_INVALID_ARG;
668 666
669 afc_lock(client); 667 afc_lock(client);
670 668
@@ -714,7 +712,7 @@ afc_file_open(afc_client_t client, const char *filename,
714 *handle = 0; 712 *handle = 0;
715 713
716 if (!client || !client->connection || !client->afc_packet) 714 if (!client || !client->connection || !client->afc_packet)
717 return AFC_E_INVALID_ARGUMENT; 715 return AFC_E_INVALID_ARG;
718 716
719 afc_lock(client); 717 afc_lock(client);
720 718
@@ -769,7 +767,7 @@ afc_file_read(afc_client_t client, uint64_t handle, char *data, uint32_t length,
769 afc_error_t ret = AFC_E_SUCCESS; 767 afc_error_t ret = AFC_E_SUCCESS;
770 768
771 if (!client || !client->afc_packet || !client->connection || handle == 0) 769 if (!client || !client->afc_packet || !client->connection || handle == 0)
772 return AFC_E_INVALID_ARGUMENT; 770 return AFC_E_INVALID_ARG;
773 debug_info("called for length %i", length); 771 debug_info("called for length %i", length);
774 772
775 afc_lock(client); 773 afc_lock(client);
@@ -845,7 +843,7 @@ afc_file_write(afc_client_t client, uint64_t handle, const char *data, uint32_t
845 afc_error_t ret = AFC_E_SUCCESS; 843 afc_error_t ret = AFC_E_SUCCESS;
846 844
847 if (!client || !client->afc_packet || !client->connection || !bytes_written || (handle == 0)) 845 if (!client || !client->afc_packet || !client->connection || !bytes_written || (handle == 0))
848 return AFC_E_INVALID_ARGUMENT; 846 return AFC_E_INVALID_ARG;
849 847
850 afc_lock(client); 848 afc_lock(client);
851 849
@@ -929,7 +927,7 @@ afc_error_t afc_file_close(afc_client_t client, uint64_t handle)
929 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 927 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
930 928
931 if (!client || (handle == 0)) 929 if (!client || (handle == 0))
932 return AFC_E_INVALID_ARGUMENT; 930 return AFC_E_INVALID_ARG;
933 931
934 afc_lock(client); 932 afc_lock(client);
935 933
@@ -977,7 +975,7 @@ afc_error_t afc_file_lock(afc_client_t client, uint64_t handle, afc_lock_op_t op
977 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 975 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
978 976
979 if (!client || (handle == 0)) 977 if (!client || (handle == 0))
980 return AFC_E_INVALID_ARGUMENT; 978 return AFC_E_INVALID_ARG;
981 979
982 afc_lock(client); 980 afc_lock(client);
983 981
@@ -1027,7 +1025,7 @@ afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset,
1027 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 1025 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
1028 1026
1029 if (!client || (handle == 0)) 1027 if (!client || (handle == 0))
1030 return AFC_E_INVALID_ARGUMENT; 1028 return AFC_E_INVALID_ARG;
1031 1029
1032 afc_lock(client); 1030 afc_lock(client);
1033 1031
@@ -1070,7 +1068,7 @@ afc_error_t afc_file_tell(afc_client_t client, uint64_t handle, uint64_t *positi
1070 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 1068 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
1071 1069
1072 if (!client || (handle == 0)) 1070 if (!client || (handle == 0))
1073 return AFC_E_INVALID_ARGUMENT; 1071 return AFC_E_INVALID_ARG;
1074 1072
1075 afc_lock(client); 1073 afc_lock(client);
1076 1074
@@ -1121,7 +1119,7 @@ afc_error_t afc_file_truncate(afc_client_t client, uint64_t handle, uint64_t new
1121 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 1119 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
1122 1120
1123 if (!client || (handle == 0)) 1121 if (!client || (handle == 0))
1124 return AFC_E_INVALID_ARGUMENT; 1122 return AFC_E_INVALID_ARG;
1125 1123
1126 afc_lock(client); 1124 afc_lock(client);
1127 1125
@@ -1154,8 +1152,7 @@ afc_error_t afc_file_truncate(afc_client_t client, uint64_t handle, uint64_t new
1154 * @param path The path of the file to be truncated. 1152 * @param path The path of the file to be truncated.
1155 * @param newsize The size to set the file to. 1153 * @param newsize The size to set the file to.
1156 * 1154 *
1157 * @return AFC_E_SUCCESS if everything went well, AFC_E_INVALID_ARGUMENT 1155 * @return AFC_E_SUCCESS on success or an AFC_E_* error value.
1158 * if arguments are NULL or invalid, AFC_E_NOT_ENOUGH_DATA otherwise.
1159 */ 1156 */
1160afc_error_t afc_truncate(afc_client_t client, const char *path, uint64_t newsize) 1157afc_error_t afc_truncate(afc_client_t client, const char *path, uint64_t newsize)
1161{ 1158{
@@ -1166,7 +1163,7 @@ afc_error_t afc_truncate(afc_client_t client, const char *path, uint64_t newsize
1166 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 1163 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
1167 1164
1168 if (!client || !path || !client->afc_packet || !client->connection) 1165 if (!client || !path || !client->afc_packet || !client->connection)
1169 return AFC_E_INVALID_ARGUMENT; 1166 return AFC_E_INVALID_ARG;
1170 1167
1171 afc_lock(client); 1168 afc_lock(client);
1172 1169
@@ -1198,8 +1195,7 @@ afc_error_t afc_truncate(afc_client_t client, const char *path, uint64_t newsize
1198 * @param target The file to be linked. 1195 * @param target The file to be linked.
1199 * @param linkname The name of link. 1196 * @param linkname The name of link.
1200 * 1197 *
1201 * @return AFC_E_SUCCESS if everything went well, AFC_E_INVALID_ARGUMENT 1198 * @return AFC_E_SUCCESS on success or an AFC_E_* error value.
1202 * if arguments are NULL or invalid, AFC_E_NOT_ENOUGH_DATA otherwise.
1203 */ 1199 */
1204afc_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, const char *target, const char *linkname) 1200afc_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, const char *target, const char *linkname)
1205{ 1201{
@@ -1210,7 +1206,7 @@ afc_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, const c
1210 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 1206 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
1211 1207
1212 if (!client || !target || !linkname || !client->afc_packet || !client->connection) 1208 if (!client || !target || !linkname || !client->afc_packet || !client->connection)
1213 return AFC_E_INVALID_ARGUMENT; 1209 return AFC_E_INVALID_ARG;
1214 1210
1215 afc_lock(client); 1211 afc_lock(client);
1216 1212
@@ -1246,8 +1242,7 @@ afc_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, const c
1246 * @param path Path of the file for which the modification time should be set. 1242 * @param path Path of the file for which the modification time should be set.
1247 * @param mtime The modification time to set in nanoseconds since epoch. 1243 * @param mtime The modification time to set in nanoseconds since epoch.
1248 * 1244 *
1249 * @return AFC_E_SUCCESS if everything went well, AFC_E_INVALID_ARGUMENT 1245 * @return AFC_E_SUCCESS on success or an AFC_E_* error value.
1250 * if arguments are NULL or invalid, AFC_E_NOT_ENOUGH_DATA otherwise.
1251 */ 1246 */
1252afc_error_t afc_set_file_time(afc_client_t client, const char *path, uint64_t mtime) 1247afc_error_t afc_set_file_time(afc_client_t client, const char *path, uint64_t mtime)
1253{ 1248{
@@ -1258,7 +1253,7 @@ afc_error_t afc_set_file_time(afc_client_t client, const char *path, uint64_t mt
1258 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 1253 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
1259 1254
1260 if (!client || !path || !client->afc_packet || !client->connection) 1255 if (!client || !path || !client->afc_packet || !client->connection)
1261 return AFC_E_INVALID_ARGUMENT; 1256 return AFC_E_INVALID_ARG;
1262 1257
1263 afc_lock(client); 1258 afc_lock(client);
1264 1259