summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2010-03-16 03:13:38 +0100
committerGravatar Martin Szulecki2010-03-16 03:13:38 +0100
commit08d2af5d611319748afba2aaba5e6c8a99f1b396 (patch)
tree8bf4a3533f2acf11368dc37a9c653689ace99b77 /src
parent3e0c5021100c879ff7d0776d4c7bb4f0ec88e0d7 (diff)
downloadlibimobiledevice-08d2af5d611319748afba2aaba5e6c8a99f1b396.tar.gz
libimobiledevice-08d2af5d611319748afba2aaba5e6c8a99f1b396.tar.bz2
Complete documentation of public interface and fix a lot of bogus comments
This change unifies the documentation comment syntax, fixes a few bad documentation comments and completes documentation where it was missing.
Diffstat (limited to 'src')
-rw-r--r--src/afc.c213
-rw-r--r--src/afc.h58
-rw-r--r--src/device_link_service.h3
-rw-r--r--src/idevice.c17
-rw-r--r--src/lockdown.c247
-rw-r--r--src/mobilebackup.c31
-rw-r--r--src/mobilesync.c31
-rw-r--r--src/sbservices.c2
-rw-r--r--src/screenshotr.h2
-rw-r--r--src/userpref.c44
10 files changed, 416 insertions, 232 deletions
diff --git a/src/afc.c b/src/afc.c
index e966fa5..5def00c 100644
--- a/src/afc.c
+++ b/src/afc.c
@@ -27,10 +27,11 @@
27#include "idevice.h" 27#include "idevice.h"
28#include "debug.h" 28#include "debug.h"
29 29
30// This is the maximum size an AFC data packet can be 30/** The maximum size an AFC data packet can be */
31static const int MAXIMUM_PACKET_SIZE = (2 << 15); 31static const int MAXIMUM_PACKET_SIZE = (2 << 15);
32 32
33/** Locks an AFC client, done for thread safety stuff 33/**
34 * Locks an AFC client, done for thread safety stuff
34 * 35 *
35 * @param client The AFC client connection to lock 36 * @param client The AFC client connection to lock
36 */ 37 */
@@ -40,7 +41,8 @@ static void afc_lock(afc_client_t client)
40 g_mutex_lock(client->mutex); 41 g_mutex_lock(client->mutex);
41} 42}
42 43
43/** Unlocks an AFC client, done for thread safety stuff. 44/**
45 * Unlocks an AFC client, done for thread safety stuff.
44 * 46 *
45 * @param client The AFC 47 * @param client The AFC
46 */ 48 */
@@ -50,7 +52,8 @@ static void afc_unlock(afc_client_t client)
50 g_mutex_unlock(client->mutex); 52 g_mutex_unlock(client->mutex);
51} 53}
52 54
53/** Makes a connection to the AFC service on the phone. 55/**
56 * Makes a connection to the AFC service on the phone.
54 * 57 *
55 * @param device The device to connect to. 58 * @param device The device to connect to.
56 * @param port The destination port. 59 * @param port The destination port.
@@ -118,14 +121,15 @@ afc_error_t afc_client_free(afc_client_t client)
118 return AFC_E_SUCCESS; 121 return AFC_E_SUCCESS;
119} 122}
120 123
121/** Dispatches an AFC packet over a client. 124/**
125 * Dispatches an AFC packet over a client.
122 * 126 *
123 * @param client The client to send data through. 127 * @param client The client to send data through.
124 * @param data The data to send. 128 * @param data The data to send.
125 * @param length The length to send. 129 * @param length The length to send.
126 * @param bytes_sent The number of bytes actually sent. 130 * @param bytes_sent The number of bytes actually sent.
127 * 131 *
128 * @return AFC_E_SUCCESS on success, or an AFC_E_* error value on error. 132 * @return AFC_E_SUCCESS on success or an AFC_E_* error value.
129 * 133 *
130 * @warning set client->afc_packet->this_length and 134 * @warning set client->afc_packet->this_length and
131 * client->afc_packet->entire_length to 0 before calling this. The 135 * client->afc_packet->entire_length to 0 before calling this. The
@@ -153,9 +157,9 @@ static afc_error_t afc_dispatch_packet(afc_client_t client, const char *data, ui
153 if (!client->afc_packet->this_length) { 157 if (!client->afc_packet->this_length) {
154 client->afc_packet->this_length = sizeof(AFCPacket); 158 client->afc_packet->this_length = sizeof(AFCPacket);
155 } 159 }
156 // We want to send two segments; buffer+sizeof(AFCPacket) to 160 /* We want to send two segments; buffer+sizeof(AFCPacket) to this_length
157 // this_length is the parameters 161 is the parameters and everything beyond that is the next packet.
158 // And everything beyond that is the next packet. (for writing) 162 (for writing) */
159 if (client->afc_packet->this_length != client->afc_packet->entire_length) { 163 if (client->afc_packet->this_length != client->afc_packet->entire_length) {
160 offset = client->afc_packet->this_length - sizeof(AFCPacket); 164 offset = client->afc_packet->this_length - sizeof(AFCPacket);
161 165
@@ -222,14 +226,14 @@ static afc_error_t afc_dispatch_packet(afc_client_t client, const char *data, ui
222 return AFC_E_INTERNAL_ERROR; 226 return AFC_E_INTERNAL_ERROR;
223} 227}
224 228
225/** Receives data through an AFC client and sets a variable to the received data. 229/**
230 * Receives data through an AFC client and sets a variable to the received data.
226 * 231 *
227 * @param client The client to receive data on. 232 * @param client The client to receive data on.
228 * @param dump_here The char* to point to the newly-received data. 233 * @param dump_here The char* to point to the newly-received data.
229 * @param bytes_recv How much data was received. 234 * @param bytes_recv How much data was received.
230 * 235 *
231 * @return AFC_E_SUCCESS when data has been received, or an AFC_E_* error value 236 * @return AFC_E_SUCCESS on success or an AFC_E_* error value.
232 * when an error occured.
233 */ 237 */
234static afc_error_t afc_receive_data(afc_client_t client, char **dump_here, uint32_t *bytes_recv) 238static afc_error_t afc_receive_data(afc_client_t client, char **dump_here, uint32_t *bytes_recv)
235{ 239{
@@ -371,6 +375,9 @@ static afc_error_t afc_receive_data(afc_client_t client, char **dump_here, uint3
371 return AFC_E_SUCCESS; 375 return AFC_E_SUCCESS;
372} 376}
373 377
378/**
379 * Returns counts of null characters within a string.
380 */
374static uint32_t count_nullspaces(char *string, uint32_t number) 381static uint32_t count_nullspaces(char *string, uint32_t number)
375{ 382{
376 uint32_t i = 0, nulls = 0; 383 uint32_t i = 0, nulls = 0;
@@ -412,13 +419,15 @@ static char **make_strings_list(char *tokens, uint32_t length)
412 return list; 419 return list;
413} 420}
414 421
415/** Gets a directory listing of the directory requested. 422/**
423 * Gets a directory listing of the directory requested.
416 * 424 *
417 * @param client The client to get a directory listing from. 425 * @param client The client to get a directory listing from.
418 * @param dir The directory to list. (must be a fully-qualified path) 426 * @param dir The directory to list. (must be a fully-qualified path)
427 * @param list A char list of files in that directory, terminated by an empty
428 * string or NULL if there was an error.
419 * 429 *
420 * @return A char ** list of files in that directory, terminated by an empty 430 * @return AFC_E_SUCCESS on success or an AFC_E_* error value.
421 * string for now or NULL if there was an error.
422 */ 431 */
423afc_error_t afc_read_directory(afc_client_t client, const char *dir, char ***list) 432afc_error_t afc_read_directory(afc_client_t client, const char *dir, char ***list)
424{ 433{
@@ -431,7 +440,7 @@ afc_error_t afc_read_directory(afc_client_t client, const char *dir, char ***lis
431 440
432 afc_lock(client); 441 afc_lock(client);
433 442
434 // Send the command 443 /* Send the command */
435 client->afc_packet->operation = AFC_OP_READ_DIR; 444 client->afc_packet->operation = AFC_OP_READ_DIR;
436 client->afc_packet->entire_length = 0; 445 client->afc_packet->entire_length = 0;
437 client->afc_packet->this_length = 0; 446 client->afc_packet->this_length = 0;
@@ -440,13 +449,13 @@ afc_error_t afc_read_directory(afc_client_t client, const char *dir, char ***lis
440 afc_unlock(client); 449 afc_unlock(client);
441 return AFC_E_NOT_ENOUGH_DATA; 450 return AFC_E_NOT_ENOUGH_DATA;
442 } 451 }
443 // Receive the data 452 /* Receive the data */
444 ret = afc_receive_data(client, &data, &bytes); 453 ret = afc_receive_data(client, &data, &bytes);
445 if (ret != AFC_E_SUCCESS) { 454 if (ret != AFC_E_SUCCESS) {
446 afc_unlock(client); 455 afc_unlock(client);
447 return ret; 456 return ret;
448 } 457 }
449 // Parse the data 458 /* Parse the data */
450 list_loc = make_strings_list(data, bytes); 459 list_loc = make_strings_list(data, bytes);
451 if (data) 460 if (data)
452 free(data); 461 free(data);
@@ -457,12 +466,16 @@ afc_error_t afc_read_directory(afc_client_t client, const char *dir, char ***lis
457 return ret; 466 return ret;
458} 467}
459 468
460/** Get device info for a client connection to phone. (free space on disk, etc.) 469/**
470 * Get device info for a client connection to phone. The device information
471 * returned is the device model as well as the free space, the total capacity
472 * and blocksize on the accessed disk partition.
461 * 473 *
462 * @param client The client to get device info for. 474 * @param client The client to get device info for.
475 * @param infos A char ** list of parameters as given by AFC or NULL if there
476 * was an error.
463 * 477 *
464 * @return A char ** list of parameters as given by AFC or NULL if there was an 478 * @return AFC_E_SUCCESS on success or an AFC_E_* error value.
465 * error.
466 */ 479 */
467afc_error_t afc_get_device_info(afc_client_t client, char ***infos) 480afc_error_t afc_get_device_info(afc_client_t client, char ***infos)
468{ 481{
@@ -475,7 +488,7 @@ afc_error_t afc_get_device_info(afc_client_t client, char ***infos)
475 488
476 afc_lock(client); 489 afc_lock(client);
477 490
478 // Send the command 491 /* Send the command */
479 client->afc_packet->operation = AFC_OP_GET_DEVINFO; 492 client->afc_packet->operation = AFC_OP_GET_DEVINFO;
480 client->afc_packet->entire_length = client->afc_packet->this_length = 0; 493 client->afc_packet->entire_length = client->afc_packet->this_length = 0;
481 ret = afc_dispatch_packet(client, NULL, 0, &bytes); 494 ret = afc_dispatch_packet(client, NULL, 0, &bytes);
@@ -483,13 +496,13 @@ afc_error_t afc_get_device_info(afc_client_t client, char ***infos)
483 afc_unlock(client); 496 afc_unlock(client);
484 return AFC_E_NOT_ENOUGH_DATA; 497 return AFC_E_NOT_ENOUGH_DATA;
485 } 498 }
486 // Receive the data 499 /* Receive the data */
487 ret = afc_receive_data(client, &data, &bytes); 500 ret = afc_receive_data(client, &data, &bytes);
488 if (ret != AFC_E_SUCCESS) { 501 if (ret != AFC_E_SUCCESS) {
489 afc_unlock(client); 502 afc_unlock(client);
490 return ret; 503 return ret;
491 } 504 }
492 // Parse the data 505 /* Parse the data */
493 list = make_strings_list(data, bytes); 506 list = make_strings_list(data, bytes);
494 if (data) 507 if (data)
495 free(data); 508 free(data);
@@ -501,7 +514,8 @@ afc_error_t afc_get_device_info(afc_client_t client, char ***infos)
501 return ret; 514 return ret;
502} 515}
503 516
504/** Get a specific key of the device info list for a client connection. 517/**
518 * Get a specific key of the device info list for a client connection.
505 * Known key values are: Model, FSTotalBytes, FSFreeBytes and FSBlockSize. 519 * Known key values are: Model, FSTotalBytes, FSFreeBytes and FSBlockSize.
506 * This is a helper function for afc_get_device_info(). 520 * This is a helper function for afc_get_device_info().
507 * 521 *
@@ -536,7 +550,8 @@ afc_error_t afc_get_device_info_key(afc_client_t client, const char *key, char *
536 return ret; 550 return ret;
537} 551}
538 552
539/** Deletes a file or directory. 553/**
554 * Deletes a file or directory.
540 * 555 *
541 * @param client The client to use. 556 * @param client The client to use.
542 * @param path The path to delete. (must be a fully-qualified path) 557 * @param path The path to delete. (must be a fully-qualified path)
@@ -554,7 +569,7 @@ afc_error_t afc_remove_path(afc_client_t client, const char *path)
554 569
555 afc_lock(client); 570 afc_lock(client);
556 571
557 // Send command 572 /* Send command */
558 client->afc_packet->this_length = client->afc_packet->entire_length = 0; 573 client->afc_packet->this_length = client->afc_packet->entire_length = 0;
559 client->afc_packet->operation = AFC_OP_REMOVE_PATH; 574 client->afc_packet->operation = AFC_OP_REMOVE_PATH;
560 ret = afc_dispatch_packet(client, path, strlen(path)+1, &bytes); 575 ret = afc_dispatch_packet(client, path, strlen(path)+1, &bytes);
@@ -562,7 +577,7 @@ afc_error_t afc_remove_path(afc_client_t client, const char *path)
562 afc_unlock(client); 577 afc_unlock(client);
563 return AFC_E_NOT_ENOUGH_DATA; 578 return AFC_E_NOT_ENOUGH_DATA;
564 } 579 }
565 // Receive response 580 /* Receive response */
566 ret = afc_receive_data(client, &response, &bytes); 581 ret = afc_receive_data(client, &response, &bytes);
567 if (response) 582 if (response)
568 free(response); 583 free(response);
@@ -576,7 +591,8 @@ afc_error_t afc_remove_path(afc_client_t client, const char *path)
576 return ret; 591 return ret;
577} 592}
578 593
579/** Renames a file or directory on the phone. 594/**
595 * Renames a file or directory on the phone.
580 * 596 *
581 * @param client The client to have rename. 597 * @param client The client to have rename.
582 * @param from The name to rename from. (must be a fully-qualified path) 598 * @param from The name to rename from. (must be a fully-qualified path)
@@ -596,7 +612,7 @@ afc_error_t afc_rename_path(afc_client_t client, const char *from, const char *t
596 612
597 afc_lock(client); 613 afc_lock(client);
598 614
599 // Send command 615 /* Send command */
600 memcpy(send, from, strlen(from) + 1); 616 memcpy(send, from, strlen(from) + 1);
601 memcpy(send + strlen(from) + 1, to, strlen(to) + 1); 617 memcpy(send + strlen(from) + 1, to, strlen(to) + 1);
602 client->afc_packet->entire_length = client->afc_packet->this_length = 0; 618 client->afc_packet->entire_length = client->afc_packet->this_length = 0;
@@ -607,7 +623,7 @@ afc_error_t afc_rename_path(afc_client_t client, const char *from, const char *t
607 afc_unlock(client); 623 afc_unlock(client);
608 return AFC_E_NOT_ENOUGH_DATA; 624 return AFC_E_NOT_ENOUGH_DATA;
609 } 625 }
610 // Receive response 626 /* Receive response */
611 ret = afc_receive_data(client, &response, &bytes); 627 ret = afc_receive_data(client, &response, &bytes);
612 if (response) 628 if (response)
613 free(response); 629 free(response);
@@ -617,7 +633,8 @@ afc_error_t afc_rename_path(afc_client_t client, const char *from, const char *t
617 return ret; 633 return ret;
618} 634}
619 635
620/** Creates a directory on the phone. 636/**
637 * Creates a directory on the phone.
621 * 638 *
622 * @param client The client to use to make a directory. 639 * @param client The client to use to make a directory.
623 * @param dir The directory's path. (must be a fully-qualified path, I assume 640 * @param dir The directory's path. (must be a fully-qualified path, I assume
@@ -636,7 +653,7 @@ afc_error_t afc_make_directory(afc_client_t client, const char *dir)
636 653
637 afc_lock(client); 654 afc_lock(client);
638 655
639 // Send command 656 /* Send command */
640 client->afc_packet->operation = AFC_OP_MAKE_DIR; 657 client->afc_packet->operation = AFC_OP_MAKE_DIR;
641 client->afc_packet->this_length = client->afc_packet->entire_length = 0; 658 client->afc_packet->this_length = client->afc_packet->entire_length = 0;
642 ret = afc_dispatch_packet(client, dir, strlen(dir)+1, &bytes); 659 ret = afc_dispatch_packet(client, dir, strlen(dir)+1, &bytes);
@@ -644,7 +661,7 @@ afc_error_t afc_make_directory(afc_client_t client, const char *dir)
644 afc_unlock(client); 661 afc_unlock(client);
645 return AFC_E_NOT_ENOUGH_DATA; 662 return AFC_E_NOT_ENOUGH_DATA;
646 } 663 }
647 // Receive response 664 /* Receive response */
648 ret = afc_receive_data(client, &response, &bytes); 665 ret = afc_receive_data(client, &response, &bytes);
649 if (response) 666 if (response)
650 free(response); 667 free(response);
@@ -654,7 +671,8 @@ afc_error_t afc_make_directory(afc_client_t client, const char *dir)
654 return ret; 671 return ret;
655} 672}
656 673
657/** Gets information about a specific file. 674/**
675 * Gets information about a specific file.
658 * 676 *
659 * @param client The client to use to get the information of the file. 677 * @param client The client to use to get the information of the file.
660 * @param path The fully-qualified path to the file. 678 * @param path The fully-qualified path to the file.
@@ -662,8 +680,7 @@ afc_error_t afc_make_directory(afc_client_t client, const char *dir)
662 * list of strings with the file information. 680 * list of strings with the file information.
663 * Set to NULL before calling this function. 681 * Set to NULL before calling this function.
664 * 682 *
665 * @return AFC_E_SUCCESS on success or an AFC_E_* error value 683 * @return AFC_E_SUCCESS on success or an AFC_E_* error value.
666 * when something went wrong.
667 */ 684 */
668afc_error_t afc_get_file_info(afc_client_t client, const char *path, char ***infolist) 685afc_error_t afc_get_file_info(afc_client_t client, const char *path, char ***infolist)
669{ 686{
@@ -676,7 +693,7 @@ afc_error_t afc_get_file_info(afc_client_t client, const char *path, char ***inf
676 693
677 afc_lock(client); 694 afc_lock(client);
678 695
679 // Send command 696 /* Send command */
680 client->afc_packet->operation = AFC_OP_GET_FILE_INFO; 697 client->afc_packet->operation = AFC_OP_GET_FILE_INFO;
681 client->afc_packet->entire_length = client->afc_packet->this_length = 0; 698 client->afc_packet->entire_length = client->afc_packet->this_length = 0;
682 ret = afc_dispatch_packet(client, path, strlen(path)+1, &bytes); 699 ret = afc_dispatch_packet(client, path, strlen(path)+1, &bytes);
@@ -685,7 +702,7 @@ afc_error_t afc_get_file_info(afc_client_t client, const char *path, char ***inf
685 return AFC_E_NOT_ENOUGH_DATA; 702 return AFC_E_NOT_ENOUGH_DATA;
686 } 703 }
687 704
688 // Receive data 705 /* Receive data */
689 ret = afc_receive_data(client, &received, &bytes); 706 ret = afc_receive_data(client, &received, &bytes);
690 if (received) { 707 if (received) {
691 *infolist = make_strings_list(received, bytes); 708 *infolist = make_strings_list(received, bytes);
@@ -697,7 +714,8 @@ afc_error_t afc_get_file_info(afc_client_t client, const char *path, char ***inf
697 return ret; 714 return ret;
698} 715}
699 716
700/** Opens a file on the phone. 717/**
718 * Opens a file on the phone.
701 * 719 *
702 * @param client The client to use to open the file. 720 * @param client The client to use to open the file.
703 * @param filename The file to open. (must be a fully-qualified path) 721 * @param filename The file to open. (must be a fully-qualified path)
@@ -707,7 +725,7 @@ afc_error_t afc_get_file_info(afc_client_t client, const char *path, char ***inf
707 * destroying anything previously there. 725 * destroying anything previously there.
708 * @param handle Pointer to a uint64_t that will hold the handle of the file 726 * @param handle Pointer to a uint64_t that will hold the handle of the file
709 * 727 *
710 * @return AFC_E_SUCCESS on success or an AFC_E_* error on failure. 728 * @return AFC_E_SUCCESS on success or an AFC_E_* error value.
711 */ 729 */
712idevice_error_t 730idevice_error_t
713afc_file_open(afc_client_t client, const char *filename, 731afc_file_open(afc_client_t client, const char *filename,
@@ -718,7 +736,7 @@ afc_file_open(afc_client_t client, const char *filename,
718 char *data = (char *) malloc(sizeof(char) * (8 + strlen(filename) + 1)); 736 char *data = (char *) malloc(sizeof(char) * (8 + strlen(filename) + 1));
719 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 737 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
720 738
721 // set handle to 0 so in case an error occurs, the handle is invalid 739 /* set handle to 0 so in case an error occurs, the handle is invalid */
722 *handle = 0; 740 *handle = 0;
723 741
724 if (!client || !client->connection || !client->afc_packet) 742 if (!client || !client->connection || !client->afc_packet)
@@ -726,7 +744,7 @@ afc_file_open(afc_client_t client, const char *filename,
726 744
727 afc_lock(client); 745 afc_lock(client);
728 746
729 // Send command 747 /* Send command */
730 memcpy(data, &file_mode_loc, 8); 748 memcpy(data, &file_mode_loc, 8);
731 memcpy(data + 8, filename, strlen(filename)); 749 memcpy(data + 8, filename, strlen(filename));
732 data[8 + strlen(filename)] = '\0'; 750 data[8 + strlen(filename)] = '\0';
@@ -740,12 +758,12 @@ afc_file_open(afc_client_t client, const char *filename,
740 afc_unlock(client); 758 afc_unlock(client);
741 return AFC_E_NOT_ENOUGH_DATA; 759 return AFC_E_NOT_ENOUGH_DATA;
742 } 760 }
743 // Receive the data 761 /* Receive the data */
744 ret = afc_receive_data(client, &data, &bytes); 762 ret = afc_receive_data(client, &data, &bytes);
745 if ((ret == AFC_E_SUCCESS) && (bytes > 0) && data) { 763 if ((ret == AFC_E_SUCCESS) && (bytes > 0) && data) {
746 afc_unlock(client); 764 afc_unlock(client);
747 765
748 // Get the file handle 766 /* Get the file handle */
749 memcpy(handle, data, sizeof(uint64_t)); 767 memcpy(handle, data, sizeof(uint64_t));
750 free(data); 768 free(data);
751 return ret; 769 return ret;
@@ -758,7 +776,8 @@ afc_file_open(afc_client_t client, const char *filename,
758 return ret; 776 return ret;
759} 777}
760 778
761/** Attempts to the read the given number of bytes from the given file. 779/**
780 * Attempts to the read the given number of bytes from the given file.
762 * 781 *
763 * @param client The relevant AFC client 782 * @param client The relevant AFC client
764 * @param handle File handle of a previously opened file 783 * @param handle File handle of a previously opened file
@@ -766,7 +785,7 @@ afc_file_open(afc_client_t client, const char *filename,
766 * @param length The number of bytes to read 785 * @param length The number of bytes to read
767 * @param bytes_read The number of bytes actually read. 786 * @param bytes_read The number of bytes actually read.
768 * 787 *
769 * @return AFC_E_SUCCESS on success or an AFC_E_* error value on error. 788 * @return AFC_E_SUCCESS on success or an AFC_E_* error value.
770 */ 789 */
771idevice_error_t 790idevice_error_t
772afc_file_read(afc_client_t client, uint64_t handle, char *data, uint32_t length, uint32_t *bytes_read) 791afc_file_read(afc_client_t client, uint64_t handle, char *data, uint32_t length, uint32_t *bytes_read)
@@ -782,12 +801,12 @@ afc_file_read(afc_client_t client, uint64_t handle, char *data, uint32_t length,
782 801
783 afc_lock(client); 802 afc_lock(client);
784 803
785 // Looping here to get around the maximum amount of data that 804 /* Looping here to get around the maximum amount of data that
786 // afc_receive_data can handle 805 afc_receive_data can handle */
787 while (current_count < length) { 806 while (current_count < length) {
788 debug_info("current count is %i but length is %i", current_count, length); 807 debug_info("current count is %i but length is %i", current_count, length);
789 808
790 // Send the read command 809 /* Send the read command */
791 AFCFilePacket *packet = (AFCFilePacket *) malloc(sizeof(AFCFilePacket)); 810 AFCFilePacket *packet = (AFCFilePacket *) malloc(sizeof(AFCFilePacket));
792 packet->filehandle = handle; 811 packet->filehandle = handle;
793 packet->size = GUINT64_TO_LE(((length - current_count) < MAXIMUM_READ_SIZE) ? (length - current_count) : MAXIMUM_READ_SIZE); 812 packet->size = GUINT64_TO_LE(((length - current_count) < MAXIMUM_READ_SIZE) ? (length - current_count) : MAXIMUM_READ_SIZE);
@@ -800,7 +819,7 @@ afc_file_read(afc_client_t client, uint64_t handle, char *data, uint32_t length,
800 afc_unlock(client); 819 afc_unlock(client);
801 return AFC_E_NOT_ENOUGH_DATA; 820 return AFC_E_NOT_ENOUGH_DATA;
802 } 821 }
803 // Receive the data 822 /* Receive the data */
804 ret = afc_receive_data(client, &input, &bytes_loc); 823 ret = afc_receive_data(client, &input, &bytes_loc);
805 debug_info("afc_receive_data returned error: %d", ret); 824 debug_info("afc_receive_data returned error: %d", ret);
806 debug_info("bytes returned: %i", bytes_loc); 825 debug_info("bytes returned: %i", bytes_loc);
@@ -831,7 +850,8 @@ afc_file_read(afc_client_t client, uint64_t handle, char *data, uint32_t length,
831 return ret; 850 return ret;
832} 851}
833 852
834/** Writes a given number of bytes to a file. 853/**
854 * Writes a given number of bytes to a file.
835 * 855 *
836 * @param client The client to use to write to the file. 856 * @param client The client to use to write to the file.
837 * @param handle File handle of previously opened file. 857 * @param handle File handle of previously opened file.
@@ -839,7 +859,7 @@ afc_file_read(afc_client_t client, uint64_t handle, char *data, uint32_t length,
839 * @param length How much data to write. 859 * @param length How much data to write.
840 * @param bytes_written The number of bytes actually written to the file. 860 * @param bytes_written The number of bytes actually written to the file.
841 * 861 *
842 * @return AFC_E_SUCCESS on success, or an AFC_E_* error value on error. 862 * @return AFC_E_SUCCESS on success or an AFC_E_* error value.
843 */ 863 */
844idevice_error_t 864idevice_error_t
845afc_file_write(afc_client_t client, uint64_t handle, const char *data, uint32_t length, uint32_t *bytes_written) 865afc_file_write(afc_client_t client, uint64_t handle, const char *data, uint32_t length, uint32_t *bytes_written)
@@ -859,9 +879,9 @@ afc_file_write(afc_client_t client, uint64_t handle, const char *data, uint32_t
859 879
860 debug_info("Write length: %i", length); 880 debug_info("Write length: %i", length);
861 881
862 // Divide the file into segments. 882 /* Divide the file into segments. */
863 for (i = 0; i < segments; i++) { 883 for (i = 0; i < segments; i++) {
864 // Send the segment 884 /* Send the segment */
865 client->afc_packet->this_length = sizeof(AFCPacket) + 8; 885 client->afc_packet->this_length = sizeof(AFCPacket) + 8;
866 client->afc_packet->entire_length = client->afc_packet->this_length + MAXIMUM_WRITE_SIZE; 886 client->afc_packet->entire_length = client->afc_packet->this_length + MAXIMUM_WRITE_SIZE;
867 client->afc_packet->operation = AFC_OP_WRITE; 887 client->afc_packet->operation = AFC_OP_WRITE;
@@ -886,10 +906,9 @@ afc_file_write(afc_client_t client, uint64_t handle, const char *data, uint32_t
886 } 906 }
887 } 907 }
888 908
889 // By this point, we should be at the end. i.e. the last segment that 909 /* By this point, we should be at the end. i.e. the last segment that didn't
890 // didn't get sent in the for loop 910 get sent in the for loop. This length is fine because it's always
891 // this length is fine because it's always sizeof(AFCPacket) + 8, but 911 sizeof(AFCPacket) + 8, but to be sure we do it again */
892 // to be sure we do it again
893 if (current_count == length) { 912 if (current_count == length) {
894 afc_unlock(client); 913 afc_unlock(client);
895 *bytes_written = current_count; 914 *bytes_written = current_count;
@@ -925,7 +944,8 @@ afc_file_write(afc_client_t client, uint64_t handle, const char *data, uint32_t
925 return ret; 944 return ret;
926} 945}
927 946
928/** Closes a file on the phone. 947/**
948 * Closes a file on the phone.
929 * 949 *
930 * @param client The client to close the file with. 950 * @param client The client to close the file with.
931 * @param handle File handle of a previously opened file. 951 * @param handle File handle of a previously opened file.
@@ -943,7 +963,7 @@ afc_error_t afc_file_close(afc_client_t client, uint64_t handle)
943 963
944 debug_info("File handle %i", handle); 964 debug_info("File handle %i", handle);
945 965
946 // Send command 966 /* Send command */
947 memcpy(buffer, &handle, sizeof(uint64_t)); 967 memcpy(buffer, &handle, sizeof(uint64_t));
948 client->afc_packet->operation = AFC_OP_FILE_CLOSE; 968 client->afc_packet->operation = AFC_OP_FILE_CLOSE;
949 client->afc_packet->entire_length = client->afc_packet->this_length = 0; 969 client->afc_packet->entire_length = client->afc_packet->this_length = 0;
@@ -956,7 +976,7 @@ afc_error_t afc_file_close(afc_client_t client, uint64_t handle)
956 return AFC_E_UNKNOWN_ERROR; 976 return AFC_E_UNKNOWN_ERROR;
957 } 977 }
958 978
959 // Receive the response 979 /* Receive the response */
960 ret = afc_receive_data(client, &buffer, &bytes); 980 ret = afc_receive_data(client, &buffer, &bytes);
961 if (buffer) 981 if (buffer)
962 free(buffer); 982 free(buffer);
@@ -966,7 +986,8 @@ afc_error_t afc_file_close(afc_client_t client, uint64_t handle)
966 return ret; 986 return ret;
967} 987}
968 988
969/** Locks or unlocks a file on the phone. 989/**
990 * Locks or unlocks a file on the phone.
970 * 991 *
971 * makes use of flock on the device, see 992 * makes use of flock on the device, see
972 * http://developer.apple.com/documentation/Darwin/Reference/ManPages/man2/flock.2.html 993 * http://developer.apple.com/documentation/Darwin/Reference/ManPages/man2/flock.2.html
@@ -991,7 +1012,7 @@ afc_error_t afc_file_lock(afc_client_t client, uint64_t handle, afc_lock_op_t op
991 1012
992 debug_info("file handle %i", handle); 1013 debug_info("file handle %i", handle);
993 1014
994 // Send command 1015 /* Send command */
995 memcpy(buffer, &handle, sizeof(uint64_t)); 1016 memcpy(buffer, &handle, sizeof(uint64_t));
996 memcpy(buffer + 8, &op, 8); 1017 memcpy(buffer + 8, &op, 8);
997 1018
@@ -1006,7 +1027,7 @@ afc_error_t afc_file_lock(afc_client_t client, uint64_t handle, afc_lock_op_t op
1006 debug_info("could not send lock command"); 1027 debug_info("could not send lock command");
1007 return AFC_E_UNKNOWN_ERROR; 1028 return AFC_E_UNKNOWN_ERROR;
1008 } 1029 }
1009 // Receive the response 1030 /* Receive the response */
1010 ret = afc_receive_data(client, &buffer, &bytes); 1031 ret = afc_receive_data(client, &buffer, &bytes);
1011 if (buffer) { 1032 if (buffer) {
1012 debug_buffer(buffer, bytes); 1033 debug_buffer(buffer, bytes);
@@ -1017,14 +1038,15 @@ afc_error_t afc_file_lock(afc_client_t client, uint64_t handle, afc_lock_op_t op
1017 return ret; 1038 return ret;
1018} 1039}
1019 1040
1020/** Seeks to a given position of a pre-opened file on the phone. 1041/**
1042 * Seeks to a given position of a pre-opened file on the phone.
1021 * 1043 *
1022 * @param client The client to use to seek to the position. 1044 * @param client The client to use to seek to the position.
1023 * @param handle File handle of a previously opened. 1045 * @param handle File handle of a previously opened.
1024 * @param offset Seek offset. 1046 * @param offset Seek offset.
1025 * @param whence Seeking direction, one of SEEK_SET, SEEK_CUR, or SEEK_END. 1047 * @param whence Seeking direction, one of SEEK_SET, SEEK_CUR, or SEEK_END.
1026 * 1048 *
1027 * @return AFC_E_SUCCESS on success, AFC_E_NOT_ENOUGH_DATA on failure. 1049 * @return AFC_E_SUCCESS on success or an AFC_E_* error value.
1028 */ 1050 */
1029afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset, int whence) 1051afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset, int whence)
1030{ 1052{
@@ -1039,10 +1061,10 @@ afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset,
1039 1061
1040 afc_lock(client); 1062 afc_lock(client);
1041 1063
1042 // Send the command 1064 /* Send the command */
1043 memcpy(buffer, &handle, sizeof(uint64_t)); // handle 1065 memcpy(buffer, &handle, sizeof(uint64_t)); /* handle */
1044 memcpy(buffer + 8, &whence_loc, sizeof(uint64_t)); // fromwhere 1066 memcpy(buffer + 8, &whence_loc, sizeof(uint64_t)); /* fromwhere */
1045 memcpy(buffer + 16, &offset_loc, sizeof(uint64_t)); // offset 1067 memcpy(buffer + 16, &offset_loc, sizeof(uint64_t)); /* offset */
1046 client->afc_packet->operation = AFC_OP_FILE_SEEK; 1068 client->afc_packet->operation = AFC_OP_FILE_SEEK;
1047 client->afc_packet->this_length = client->afc_packet->entire_length = 0; 1069 client->afc_packet->this_length = client->afc_packet->entire_length = 0;
1048 ret = afc_dispatch_packet(client, buffer, 24, &bytes); 1070 ret = afc_dispatch_packet(client, buffer, 24, &bytes);
@@ -1053,7 +1075,7 @@ afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset,
1053 afc_unlock(client); 1075 afc_unlock(client);
1054 return AFC_E_NOT_ENOUGH_DATA; 1076 return AFC_E_NOT_ENOUGH_DATA;
1055 } 1077 }
1056 // Receive response 1078 /* Receive response */
1057 ret = afc_receive_data(client, &buffer, &bytes); 1079 ret = afc_receive_data(client, &buffer, &bytes);
1058 if (buffer) 1080 if (buffer)
1059 free(buffer); 1081 free(buffer);
@@ -1063,13 +1085,14 @@ afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset,
1063 return ret; 1085 return ret;
1064} 1086}
1065 1087
1066/** Returns current position in a pre-opened file on the phone. 1088/**
1089 * Returns current position in a pre-opened file on the phone.
1067 * 1090 *
1068 * @param client The client to use. 1091 * @param client The client to use.
1069 * @param handle File handle of a previously opened file. 1092 * @param handle File handle of a previously opened file.
1070 * @param position Position in bytes of indicator 1093 * @param position Position in bytes of indicator
1071 * 1094 *
1072 * @return AFC_E_SUCCESS on success, AFC_E_NOT_ENOUGH_DATA on failure. 1095 * @return AFC_E_SUCCESS on success or an AFC_E_* error value.
1073 */ 1096 */
1074afc_error_t afc_file_tell(afc_client_t client, uint64_t handle, uint64_t *position) 1097afc_error_t afc_file_tell(afc_client_t client, uint64_t handle, uint64_t *position)
1075{ 1098{
@@ -1082,8 +1105,8 @@ afc_error_t afc_file_tell(afc_client_t client, uint64_t handle, uint64_t *positi
1082 1105
1083 afc_lock(client); 1106 afc_lock(client);
1084 1107
1085 // Send the command 1108 /* Send the command */
1086 memcpy(buffer, &handle, sizeof(uint64_t)); // handle 1109 memcpy(buffer, &handle, sizeof(uint64_t)); /* handle */
1087 client->afc_packet->operation = AFC_OP_FILE_TELL; 1110 client->afc_packet->operation = AFC_OP_FILE_TELL;
1088 client->afc_packet->this_length = client->afc_packet->entire_length = 0; 1111 client->afc_packet->this_length = client->afc_packet->entire_length = 0;
1089 ret = afc_dispatch_packet(client, buffer, 8, &bytes); 1112 ret = afc_dispatch_packet(client, buffer, 8, &bytes);
@@ -1095,7 +1118,7 @@ afc_error_t afc_file_tell(afc_client_t client, uint64_t handle, uint64_t *positi
1095 return AFC_E_NOT_ENOUGH_DATA; 1118 return AFC_E_NOT_ENOUGH_DATA;
1096 } 1119 }
1097 1120
1098 // Receive the data 1121 /* Receive the data */
1099 ret = afc_receive_data(client, &buffer, &bytes); 1122 ret = afc_receive_data(client, &buffer, &bytes);
1100 if (bytes > 0 && buffer) { 1123 if (bytes > 0 && buffer) {
1101 /* Get the position */ 1124 /* Get the position */
@@ -1110,13 +1133,14 @@ afc_error_t afc_file_tell(afc_client_t client, uint64_t handle, uint64_t *positi
1110 return ret; 1133 return ret;
1111} 1134}
1112 1135
1113/** Sets the size of a file on the phone. 1136/**
1137 * Sets the size of a file on the phone.
1114 * 1138 *
1115 * @param client The client to use to set the file size. 1139 * @param client The client to use to set the file size.
1116 * @param handle File handle of a previously opened file. 1140 * @param handle File handle of a previously opened file.
1117 * @param newsize The size to set the file to. 1141 * @param newsize The size to set the file to.
1118 * 1142 *
1119 * @return 0 on success, -1 on failure. 1143 * @return AFC_E_SUCCESS on success or an AFC_E_* error value.
1120 * 1144 *
1121 * @note This function is more akin to ftruncate than truncate, and truncate 1145 * @note This function is more akin to ftruncate than truncate, and truncate
1122 * calls would have to open the file before calling this, sadly. 1146 * calls would have to open the file before calling this, sadly.
@@ -1133,9 +1157,9 @@ afc_error_t afc_file_truncate(afc_client_t client, uint64_t handle, uint64_t new
1133 1157
1134 afc_lock(client); 1158 afc_lock(client);
1135 1159
1136 // Send command 1160 /* Send command */
1137 memcpy(buffer, &handle, sizeof(uint64_t)); // handle 1161 memcpy(buffer, &handle, sizeof(uint64_t)); /* handle */
1138 memcpy(buffer + 8, &newsize_loc, sizeof(uint64_t)); // newsize 1162 memcpy(buffer + 8, &newsize_loc, sizeof(uint64_t)); /* newsize */
1139 client->afc_packet->operation = AFC_OP_FILE_SET_SIZE; 1163 client->afc_packet->operation = AFC_OP_FILE_SET_SIZE;
1140 client->afc_packet->this_length = client->afc_packet->entire_length = 0; 1164 client->afc_packet->this_length = client->afc_packet->entire_length = 0;
1141 ret = afc_dispatch_packet(client, buffer, 16, &bytes); 1165 ret = afc_dispatch_packet(client, buffer, 16, &bytes);
@@ -1146,7 +1170,7 @@ afc_error_t afc_file_truncate(afc_client_t client, uint64_t handle, uint64_t new
1146 afc_unlock(client); 1170 afc_unlock(client);
1147 return AFC_E_NOT_ENOUGH_DATA; 1171 return AFC_E_NOT_ENOUGH_DATA;
1148 } 1172 }
1149 // Receive response 1173 /* Receive response */
1150 ret = afc_receive_data(client, &buffer, &bytes); 1174 ret = afc_receive_data(client, &buffer, &bytes);
1151 if (buffer) 1175 if (buffer)
1152 free(buffer); 1176 free(buffer);
@@ -1156,7 +1180,8 @@ afc_error_t afc_file_truncate(afc_client_t client, uint64_t handle, uint64_t new
1156 return ret; 1180 return ret;
1157} 1181}
1158 1182
1159/** Sets the size of a file on the phone without prior opening it. 1183/**
1184 * Sets the size of a file on the phone without prior opening it.
1160 * 1185 *
1161 * @param client The client to use to set the file size. 1186 * @param client The client to use to set the file size.
1162 * @param path The path of the file to be truncated. 1187 * @param path The path of the file to be truncated.
@@ -1177,7 +1202,7 @@ afc_error_t afc_truncate(afc_client_t client, const char *path, uint64_t newsize
1177 1202
1178 afc_lock(client); 1203 afc_lock(client);
1179 1204
1180 // Send command 1205 /* Send command */
1181 memcpy(send, &size_requested, 8); 1206 memcpy(send, &size_requested, 8);
1182 memcpy(send + 8, path, strlen(path) + 1); 1207 memcpy(send + 8, path, strlen(path) + 1);
1183 client->afc_packet->entire_length = client->afc_packet->this_length = 0; 1208 client->afc_packet->entire_length = client->afc_packet->this_length = 0;
@@ -1188,7 +1213,7 @@ afc_error_t afc_truncate(afc_client_t client, const char *path, uint64_t newsize
1188 afc_unlock(client); 1213 afc_unlock(client);
1189 return AFC_E_NOT_ENOUGH_DATA; 1214 return AFC_E_NOT_ENOUGH_DATA;
1190 } 1215 }
1191 // Receive response 1216 /* Receive response */
1192 ret = afc_receive_data(client, &response, &bytes); 1217 ret = afc_receive_data(client, &response, &bytes);
1193 if (response) 1218 if (response)
1194 free(response); 1219 free(response);
@@ -1198,10 +1223,11 @@ afc_error_t afc_truncate(afc_client_t client, const char *path, uint64_t newsize
1198 return ret; 1223 return ret;
1199} 1224}
1200 1225
1201/** Creates a hard link or symbolic link on the device. 1226/**
1227 * Creates a hard link or symbolic link on the device.
1202 * 1228 *
1203 * @param client The client to use for making a link 1229 * @param client The client to use for making a link
1204 * @param type 1 = hard link, 2 = symlink 1230 * @param linktype 1 = hard link, 2 = symlink
1205 * @param target The file to be linked. 1231 * @param target The file to be linked.
1206 * @param linkname The name of link. 1232 * @param linkname The name of link.
1207 * 1233 *
@@ -1224,7 +1250,7 @@ afc_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, const c
1224 debug_info("target: %s, length:%d", target, strlen(target)); 1250 debug_info("target: %s, length:%d", target, strlen(target));
1225 debug_info("linkname: %s, length:%d", linkname, strlen(linkname)); 1251 debug_info("linkname: %s, length:%d", linkname, strlen(linkname));
1226 1252
1227 // Send command 1253 /* Send command */
1228 memcpy(send, &type, 8); 1254 memcpy(send, &type, 8);
1229 memcpy(send + 8, target, strlen(target) + 1); 1255 memcpy(send + 8, target, strlen(target) + 1);
1230 memcpy(send + 8 + strlen(target) + 1, linkname, strlen(linkname) + 1); 1256 memcpy(send + 8 + strlen(target) + 1, linkname, strlen(linkname) + 1);
@@ -1236,7 +1262,7 @@ afc_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, const c
1236 afc_unlock(client); 1262 afc_unlock(client);
1237 return AFC_E_NOT_ENOUGH_DATA; 1263 return AFC_E_NOT_ENOUGH_DATA;
1238 } 1264 }
1239 // Receive response 1265 /* Receive response */
1240 ret = afc_receive_data(client, &response, &bytes); 1266 ret = afc_receive_data(client, &response, &bytes);
1241 if (response) 1267 if (response)
1242 free(response); 1268 free(response);
@@ -1246,7 +1272,8 @@ afc_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, const c
1246 return ret; 1272 return ret;
1247} 1273}
1248 1274
1249/** Sets the modification time of a file on the phone. 1275/**
1276 * Sets the modification time of a file on the phone.
1250 * 1277 *
1251 * @param client The client to use to set the file size. 1278 * @param client The client to use to set the file size.
1252 * @param path Path of the file for which the modification time should be set. 1279 * @param path Path of the file for which the modification time should be set.
@@ -1267,7 +1294,7 @@ afc_error_t afc_set_file_time(afc_client_t client, const char *path, uint64_t mt
1267 1294
1268 afc_lock(client); 1295 afc_lock(client);
1269 1296
1270 // Send command 1297 /* Send command */
1271 memcpy(send, &mtime_loc, 8); 1298 memcpy(send, &mtime_loc, 8);
1272 memcpy(send + 8, path, strlen(path) + 1); 1299 memcpy(send + 8, path, strlen(path) + 1);
1273 client->afc_packet->entire_length = client->afc_packet->this_length = 0; 1300 client->afc_packet->entire_length = client->afc_packet->this_length = 0;
@@ -1278,7 +1305,7 @@ afc_error_t afc_set_file_time(afc_client_t client, const char *path, uint64_t mt
1278 afc_unlock(client); 1305 afc_unlock(client);
1279 return AFC_E_NOT_ENOUGH_DATA; 1306 return AFC_E_NOT_ENOUGH_DATA;
1280 } 1307 }
1281 // Receive response 1308 /* Receive response */
1282 ret = afc_receive_data(client, &response, &bytes); 1309 ret = afc_receive_data(client, &response, &bytes);
1283 if (response) 1310 if (response)
1284 free(response); 1311 free(response);
diff --git a/src/afc.h b/src/afc.h
index abf38e3..cde85b4 100644
--- a/src/afc.h
+++ b/src/afc.h
@@ -62,34 +62,34 @@ struct afc_client_private {
62 62
63/* AFC Operations */ 63/* AFC Operations */
64enum { 64enum {
65 AFC_OP_STATUS = 0x00000001, // Status 65 AFC_OP_STATUS = 0x00000001, /* Status */
66 AFC_OP_DATA = 0x00000002, // Data 66 AFC_OP_DATA = 0x00000002, /* Data */
67 AFC_OP_READ_DIR = 0x00000003, // ReadDir 67 AFC_OP_READ_DIR = 0x00000003, /* ReadDir */
68 AFC_OP_READ_FILE = 0x00000004, // ReadFile 68 AFC_OP_READ_FILE = 0x00000004, /* ReadFile */
69 AFC_OP_WRITE_FILE = 0x00000005, // WriteFile 69 AFC_OP_WRITE_FILE = 0x00000005, /* WriteFile */
70 AFC_OP_WRITE_PART = 0x00000006, // WritePart 70 AFC_OP_WRITE_PART = 0x00000006, /* WritePart */
71 AFC_OP_TRUNCATE = 0x00000007, // TruncateFile 71 AFC_OP_TRUNCATE = 0x00000007, /* TruncateFile */
72 AFC_OP_REMOVE_PATH = 0x00000008, // RemovePath 72 AFC_OP_REMOVE_PATH = 0x00000008, /* RemovePath */
73 AFC_OP_MAKE_DIR = 0x00000009, // MakeDir 73 AFC_OP_MAKE_DIR = 0x00000009, /* MakeDir */
74 AFC_OP_GET_FILE_INFO = 0x0000000a, // GetFileInfo 74 AFC_OP_GET_FILE_INFO = 0x0000000a, /* GetFileInfo */
75 AFC_OP_GET_DEVINFO = 0x0000000b, // GetDeviceInfo 75 AFC_OP_GET_DEVINFO = 0x0000000b, /* GetDeviceInfo */
76 AFC_OP_WRITE_FILE_ATOM = 0x0000000c, // WriteFileAtomic (tmp file+rename) 76 AFC_OP_WRITE_FILE_ATOM = 0x0000000c, /* WriteFileAtomic (tmp file+rename) */
77 AFC_OP_FILE_OPEN = 0x0000000d, // FileRefOpen 77 AFC_OP_FILE_OPEN = 0x0000000d, /* FileRefOpen */
78 AFC_OP_FILE_OPEN_RES = 0x0000000e, // FileRefOpenResult 78 AFC_OP_FILE_OPEN_RES = 0x0000000e, /* FileRefOpenResult */
79 AFC_OP_READ = 0x0000000f, // FileRefRead 79 AFC_OP_READ = 0x0000000f, /* FileRefRead */
80 AFC_OP_WRITE = 0x00000010, // FileRefWrite 80 AFC_OP_WRITE = 0x00000010, /* FileRefWrite */
81 AFC_OP_FILE_SEEK = 0x00000011, // FileRefSeek 81 AFC_OP_FILE_SEEK = 0x00000011, /* FileRefSeek */
82 AFC_OP_FILE_TELL = 0x00000012, // FileRefTell 82 AFC_OP_FILE_TELL = 0x00000012, /* FileRefTell */
83 AFC_OP_FILE_TELL_RES = 0x00000013, // FileRefTellResult 83 AFC_OP_FILE_TELL_RES = 0x00000013, /* FileRefTellResult */
84 AFC_OP_FILE_CLOSE = 0x00000014, // FileRefClose 84 AFC_OP_FILE_CLOSE = 0x00000014, /* FileRefClose */
85 AFC_OP_FILE_SET_SIZE = 0x00000015, // FileRefSetFileSize (ftruncate) 85 AFC_OP_FILE_SET_SIZE = 0x00000015, /* FileRefSetFileSize (ftruncate) */
86 AFC_OP_GET_CON_INFO = 0x00000016, // GetConnectionInfo 86 AFC_OP_GET_CON_INFO = 0x00000016, /* GetConnectionInfo */
87 AFC_OP_SET_CON_OPTIONS = 0x00000017, // SetConnectionOptions 87 AFC_OP_SET_CON_OPTIONS = 0x00000017, /* SetConnectionOptions */
88 AFC_OP_RENAME_PATH = 0x00000018, // RenamePath 88 AFC_OP_RENAME_PATH = 0x00000018, /* RenamePath */
89 AFC_OP_SET_FS_BS = 0x00000019, // SetFSBlockSize (0x800000) 89 AFC_OP_SET_FS_BS = 0x00000019, /* SetFSBlockSize (0x800000) */
90 AFC_OP_SET_SOCKET_BS = 0x0000001A, // SetSocketBlockSize (0x800000) 90 AFC_OP_SET_SOCKET_BS = 0x0000001A, /* SetSocketBlockSize (0x800000) */
91 AFC_OP_FILE_LOCK = 0x0000001B, // FileRefLock 91 AFC_OP_FILE_LOCK = 0x0000001B, /* FileRefLock */
92 AFC_OP_MAKE_LINK = 0x0000001C, // MakeLink 92 AFC_OP_MAKE_LINK = 0x0000001C, /* MakeLink */
93 AFC_OP_SET_FILE_TIME = 0x0000001E // set st_mtime 93 AFC_OP_SET_FILE_TIME = 0x0000001E /* set st_mtime */
94}; 94};
95 95
diff --git a/src/device_link_service.h b/src/device_link_service.h
index c80686d..8b58ccf 100644
--- a/src/device_link_service.h
+++ b/src/device_link_service.h
@@ -32,12 +32,13 @@
32 32
33#define DEVICE_LINK_SERVICE_E_UNKNOWN_ERROR -256 33#define DEVICE_LINK_SERVICE_E_UNKNOWN_ERROR -256
34 34
35/** Represents an error code. */
36typedef int16_t device_link_service_error_t;
35 37
36struct device_link_service_client_private { 38struct device_link_service_client_private {
37 property_list_service_client_t parent; 39 property_list_service_client_t parent;
38}; 40};
39 41
40typedef int16_t device_link_service_error_t;
41typedef struct device_link_service_client_private *device_link_service_client_t; 42typedef struct device_link_service_client_private *device_link_service_client_t;
42 43
43device_link_service_error_t device_link_service_client_new(idevice_t device, uint16_t port, device_link_service_client_t *client); 44device_link_service_error_t device_link_service_client_new(idevice_t device, uint16_t port, device_link_service_client_t *client);
diff --git a/src/idevice.c b/src/idevice.c
index 0bdf3f5..b72b623 100644
--- a/src/idevice.c
+++ b/src/idevice.c
@@ -172,7 +172,8 @@ idevice_error_t idevice_new(idevice_t * device, const char *uuid)
172 return IDEVICE_E_NO_DEVICE; 172 return IDEVICE_E_NO_DEVICE;
173} 173}
174 174
175/** Cleans up an idevice structure, then frees the structure itself. 175/**
176 * Cleans up an idevice structure, then frees the structure itself.
176 * This is a library-level function; deals directly with the device to tear 177 * This is a library-level function; deals directly with the device to tear
177 * down relations, but otherwise is mostly internal. 178 * down relations, but otherwise is mostly internal.
178 * 179 *
@@ -422,6 +423,9 @@ idevice_error_t idevice_connection_receive(idevice_connection_t connection, char
422 return internal_connection_receive(connection, data, len, recv_bytes); 423 return internal_connection_receive(connection, data, len, recv_bytes);
423} 424}
424 425
426/**
427 * Gets the handle of the device. Depends on the connection type.
428 */
425idevice_error_t idevice_get_handle(idevice_t device, uint32_t *handle) 429idevice_error_t idevice_get_handle(idevice_t device, uint32_t *handle)
426{ 430{
427 if (!device) 431 if (!device)
@@ -436,6 +440,9 @@ idevice_error_t idevice_get_handle(idevice_t device, uint32_t *handle)
436 return IDEVICE_E_UNKNOWN_ERROR; 440 return IDEVICE_E_UNKNOWN_ERROR;
437} 441}
438 442
443/**
444 * Gets the unique id for the device.
445 */
439idevice_error_t idevice_get_uuid(idevice_t device, char **uuid) 446idevice_error_t idevice_get_uuid(idevice_t device, char **uuid)
440{ 447{
441 if (!device) 448 if (!device)
@@ -469,10 +476,10 @@ static ssize_t internal_ssl_read(gnutls_transport_ptr_t transport, char *buffer,
469 } 476 }
470 debug_info("post-read we got %i bytes", bytes); 477 debug_info("post-read we got %i bytes", bytes);
471 478
472 // increase read count 479 /* increase read count */
473 tbytes += bytes; 480 tbytes += bytes;
474 481
475 // fill the buffer with what we got right now 482 /* fill the buffer with what we got right now */
476 memcpy(buffer + pos_start_fill, recv_buffer, bytes); 483 memcpy(buffer + pos_start_fill, recv_buffer, bytes);
477 pos_start_fill += bytes; 484 pos_start_fill += bytes;
478 485
@@ -538,7 +545,7 @@ idevice_error_t idevice_connection_enable_ssl(idevice_connection_t connection)
538 545
539 ssl_data_t ssl_data_loc = (ssl_data_t)malloc(sizeof(struct ssl_data_private)); 546 ssl_data_t ssl_data_loc = (ssl_data_t)malloc(sizeof(struct ssl_data_private));
540 547
541 // Set up GnuTLS... 548 /* Set up GnuTLS... */
542 debug_info("enabling SSL mode"); 549 debug_info("enabling SSL mode");
543 errno = 0; 550 errno = 0;
544 gnutls_global_init(); 551 gnutls_global_init();
@@ -558,7 +565,7 @@ idevice_error_t idevice_connection_enable_ssl(idevice_connection_t connection)
558 gnutls_protocol_set_priority(ssl_data_loc->session, protocol_priority); 565 gnutls_protocol_set_priority(ssl_data_loc->session, protocol_priority);
559 gnutls_mac_set_priority(ssl_data_loc->session, mac_priority); 566 gnutls_mac_set_priority(ssl_data_loc->session, mac_priority);
560 } 567 }
561 gnutls_credentials_set(ssl_data_loc->session, GNUTLS_CRD_CERTIFICATE, ssl_data_loc->certificate); // this part is killing me. 568 gnutls_credentials_set(ssl_data_loc->session, GNUTLS_CRD_CERTIFICATE, ssl_data_loc->certificate); /* this part is killing me. */
562 569
563 debug_info("GnuTLS step 1..."); 570 debug_info("GnuTLS step 1...");
564 gnutls_transport_set_ptr(ssl_data_loc->session, (gnutls_transport_ptr_t)connection); 571 gnutls_transport_set_ptr(ssl_data_loc->session, (gnutls_transport_ptr_t)connection);
diff --git a/src/lockdown.c b/src/lockdown.c
index 25a6c6a..515c58e 100644
--- a/src/lockdown.c
+++ b/src/lockdown.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * lockdown.c 2 * lockdown.c
3 * libimobiledevice built-in lockdownd client 3 * com.apple.mobile.lockdownd service implementation.
4 * 4 *
5 * Copyright (c) 2008 Zach C. All Rights Reserved. 5 * Copyright (c) 2008 Zach C. All Rights Reserved.
6 * 6 *
@@ -124,15 +124,14 @@ static void plist_dict_add_label(plist_t plist, const char *label)
124} 124}
125 125
126/** 126/**
127 * Closes the lockdownd communication session, by sending the StopSession 127 * Closes the lockdownd session by sending the StopSession request.
128 * Request to the device.
129 * 128 *
130 * @see lockdownd_start_session 129 * @see lockdownd_start_session
131 * 130 *
132 * @param control The lockdown client 131 * @param client The lockdown client
133 * @param session_id The id of a running session 132 * @param session_id The id of a running session
134 * 133 *
135 * @return an error code (LOCKDOWN_E_SUCCESS on success) 134 * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when client is NULL
136 */ 135 */
137lockdownd_error_t lockdownd_stop_session(lockdownd_client_t client, const char *session_id) 136lockdownd_error_t lockdownd_stop_session(lockdownd_client_t client, const char *session_id)
138{ 137{
@@ -178,11 +177,13 @@ lockdownd_error_t lockdownd_stop_session(lockdownd_client_t client, const char *
178 return ret; 177 return ret;
179} 178}
180 179
181/** Closes the lockdownd client and does the necessary housekeeping. 180/**
181 * Closes the lockdownd client session if one is running and frees up the
182 * lockdownd_client struct.
182 * 183 *
183 * @param client The lockdown client 184 * @param client The lockdown client
184 * 185 *
185 * @return an error code (LOCKDOWN_E_SUCCESS on success) 186 * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when client is NULL
186 */ 187 */
187lockdownd_error_t lockdownd_client_free(lockdownd_client_t client) 188lockdownd_error_t lockdownd_client_free(lockdownd_client_t client)
188{ 189{
@@ -229,12 +230,14 @@ void lockdownd_client_set_label(lockdownd_client_t client, const char *label)
229 } 230 }
230} 231}
231 232
232/** Polls the device for lockdownd data. 233/**
234 * Receives a plist from lockdownd.
233 * 235 *
234 * @param control The lockdownd client 236 * @param client The lockdownd client
235 * @param plist The plist to store the received data 237 * @param plist The plist to store the received data
236 * 238 *
237 * @return an error code (LOCKDOWN_E_SUCCESS on success) 239 * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when client or
240 * plist is NULL
238 */ 241 */
239lockdownd_error_t lockdownd_receive(lockdownd_client_t client, plist_t *plist) 242lockdownd_error_t lockdownd_receive(lockdownd_client_t client, plist_t *plist)
240{ 243{
@@ -254,7 +257,8 @@ lockdownd_error_t lockdownd_receive(lockdownd_client_t client, plist_t *plist)
254 return ret; 257 return ret;
255} 258}
256 259
257/** Sends lockdownd data to the device 260/**
261 * Sends a plist to lockdownd.
258 * 262 *
259 * @note This function is low-level and should only be used if you need to send 263 * @note This function is low-level and should only be used if you need to send
260 * a new type of message. 264 * a new type of message.
@@ -262,7 +266,8 @@ lockdownd_error_t lockdownd_receive(lockdownd_client_t client, plist_t *plist)
262 * @param client The lockdownd client 266 * @param client The lockdownd client
263 * @param plist The plist to send 267 * @param plist The plist to send
264 * 268 *
265 * @return an error code (LOCKDOWN_E_SUCCESS on success) 269 * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when client or
270 * plist is NULL
266 */ 271 */
267lockdownd_error_t lockdownd_send(lockdownd_client_t client, plist_t plist) 272lockdownd_error_t lockdownd_send(lockdownd_client_t client, plist_t plist)
268{ 273{
@@ -279,13 +284,14 @@ lockdownd_error_t lockdownd_send(lockdownd_client_t client, plist_t plist)
279 return ret; 284 return ret;
280} 285}
281 286
282/** Query the type of the service daemon. Depending on whether the device is 287/**
288 * Query the type of the service daemon. Depending on whether the device is
283 * queried in normal mode or restore mode, different types will be returned. 289 * queried in normal mode or restore mode, different types will be returned.
284 * 290 *
285 * @param client The lockdownd client 291 * @param client The lockdownd client
286 * @param type The type returned by the service daemon. Can be NULL to ignore. 292 * @param type The type returned by the service daemon. Pass NULL to ignore.
287 * 293 *
288 * @return an error code (LOCKDOWN_E_SUCCESS on success) 294 * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when client is NULL
289 */ 295 */
290lockdownd_error_t lockdownd_query_type(lockdownd_client_t client, char **type) 296lockdownd_error_t lockdownd_query_type(lockdownd_client_t client, char **type)
291{ 297{
@@ -325,14 +331,15 @@ lockdownd_error_t lockdownd_query_type(lockdownd_client_t client, char **type)
325 return ret; 331 return ret;
326} 332}
327 333
328/** Retrieves a preferences plist using an optional domain and/or key name. 334/**
335 * Retrieves a preferences plist using an optional domain and/or key name.
329 * 336 *
330 * @param client an initialized lockdownd client. 337 * @param client An initialized lockdownd client.
331 * @param domain the domain to query on or NULL for global domain 338 * @param domain The domain to query on or NULL for global domain
332 * @param key the key name to request or NULL to query for all keys 339 * @param key The key name to request or NULL to query for all keys
333 * @param value a plist node representing the result value node 340 * @param value A plist node representing the result value node
334 * 341 *
335 * @return an error code (LOCKDOWN_E_SUCCESS on success) 342 * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when client is NULL
336 */ 343 */
337lockdownd_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain, const char *key, plist_t *value) 344lockdownd_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain, const char *key, plist_t *value)
338{ 345{
@@ -387,14 +394,16 @@ lockdownd_error_t lockdownd_get_value(lockdownd_client_t client, const char *dom
387 return ret; 394 return ret;
388} 395}
389 396
390/** Sets a preferences value using a plist and optional domain and/or key name. 397/**
398 * Sets a preferences value using a plist and optional by domain and/or key name.
391 * 399 *
392 * @param client an initialized lockdownd client. 400 * @param client an initialized lockdownd client.
393 * @param domain the domain to query on or NULL for global domain 401 * @param domain the domain to query on or NULL for global domain
394 * @param key the key name to set the value or NULL to set a value dict plist 402 * @param key the key name to set the value or NULL to set a value dict plist
395 * @param value a plist node of any node type representing the value to set 403 * @param value a plist node of any node type representing the value to set
396 * 404 *
397 * @return an error code (LOCKDOWN_E_SUCCESS on success) 405 * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when client or
406 * value is NULL
398 */ 407 */
399lockdownd_error_t lockdownd_set_value(lockdownd_client_t client, const char *domain, const char *key, plist_t value) 408lockdownd_error_t lockdownd_set_value(lockdownd_client_t client, const char *domain, const char *key, plist_t value)
400{ 409{
@@ -444,15 +453,16 @@ lockdownd_error_t lockdownd_set_value(lockdownd_client_t client, const char *dom
444 return ret; 453 return ret;
445} 454}
446 455
447/** Removes a preference node on the device by domain and/or key name 456/**
457 * Removes a preference node by domain and/or key name.
448 * 458 *
449 * @note: Use with caution as this could remove vital information on the device 459 * @note: Use with caution as this could remove vital information on the device
450 * 460 *
451 * @param client an initialized lockdownd client. 461 * @param client An initialized lockdownd client.
452 * @param domain the domain to query on or NULL for global domain 462 * @param domain The domain to query on or NULL for global domain
453 * @param key the key name to remove or NULL remove all keys for the current domain 463 * @param key The key name to remove or NULL remove all keys for the current domain
454 * 464 *
455 * @return an error code (LOCKDOWN_E_SUCCESS on success) 465 * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when client is NULL
456 */ 466 */
457lockdownd_error_t lockdownd_remove_value(lockdownd_client_t client, const char *domain, const char *key) 467lockdownd_error_t lockdownd_remove_value(lockdownd_client_t client, const char *domain, const char *key)
458{ 468{
@@ -501,9 +511,14 @@ lockdownd_error_t lockdownd_remove_value(lockdownd_client_t client, const char *
501 return ret; 511 return ret;
502} 512}
503 513
504/** Asks for the device's unique id. Part of the lockdownd handshake. 514/**
515 * Returns the unique id of the device from lockdownd.
505 * 516 *
506 * @return an error code (LOCKDOWN_E_SUCCESS on success) 517 * @param client An initialized lockdownd client.
518 * @param uuid Holds the unique id of the device. The caller is responsible
519 * for freeing the memory.
520 *
521 * @return LOCKDOWN_E_SUCCESS on success
507 */ 522 */
508lockdownd_error_t lockdownd_get_device_uuid(lockdownd_client_t client, char **uuid) 523lockdownd_error_t lockdownd_get_device_uuid(lockdownd_client_t client, char **uuid)
509{ 524{
@@ -521,9 +536,14 @@ lockdownd_error_t lockdownd_get_device_uuid(lockdownd_client_t client, char **uu
521 return ret; 536 return ret;
522} 537}
523 538
524/** Askes for the device's public key. Part of the lockdownd handshake. 539/**
540 * Retrieves the public key of the device from lockdownd.
525 * 541 *
526 * @return an error code (LOCKDOWN_E_SUCCESS on success) 542 * @param client An initialized lockdownd client.
543 * @param public_key Holds the public key of the device. The caller is
544 * responsible for freeing the memory.
545 *
546 * @return LOCKDOWN_E_SUCCESS on success
527 */ 547 */
528lockdownd_error_t lockdownd_get_device_public_key(lockdownd_client_t client, gnutls_datum_t * public_key) 548lockdownd_error_t lockdownd_get_device_public_key(lockdownd_client_t client, gnutls_datum_t * public_key)
529{ 549{
@@ -546,12 +566,14 @@ lockdownd_error_t lockdownd_get_device_public_key(lockdownd_client_t client, gnu
546 return ret; 566 return ret;
547} 567}
548 568
549/** Askes for the device's name. 569/**
550 * 570 * Retrieves the name of the device from lockdownd set by the user.
551 * @param client The pointer to the location of the new lockdownd_client
552 * 571 *
572 * @param client An initialized lockdownd client.
573 * @param device_name Holds the name of the device. The caller is
574 * responsible for freeing the memory.
553 * 575 *
554 * @return an error code (LOCKDOWN_E_SUCCESS on success) 576 * @return LOCKDOWN_E_SUCCESS on success
555 */ 577 */
556lockdownd_error_t lockdownd_get_device_name(lockdownd_client_t client, char **device_name) 578lockdownd_error_t lockdownd_get_device_name(lockdownd_client_t client, char **device_name)
557{ 579{
@@ -570,13 +592,17 @@ lockdownd_error_t lockdownd_get_device_name(lockdownd_client_t client, char **de
570 return ret; 592 return ret;
571} 593}
572 594
573/** Creates a lockdownd client for the device. 595/**
596 * Creates a new lockdownd client for the device.
574 * 597 *
575 * @param phone The device to create a lockdownd client for 598 * @note This function does not pair with the device or start a session. This
599 * has to be done manually by the caller after the client is created.
600 *
601 * @param device The device to create a lockdownd client for
576 * @param client The pointer to the location of the new lockdownd_client 602 * @param client The pointer to the location of the new lockdownd_client
577 * @param label The label to use for communication. Usually the program name 603 * @param label The label to use for communication. Usually the program name.
578 * 604 *
579 * @return an error code (LOCKDOWN_E_SUCCESS on success) 605 * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when client is NULL
580 */ 606 */
581lockdownd_error_t lockdownd_client_new(idevice_t device, lockdownd_client_t *client, const char *label) 607lockdownd_error_t lockdownd_client_new(idevice_t device, lockdownd_client_t *client, const char *label)
582{ 608{
@@ -609,15 +635,18 @@ lockdownd_error_t lockdownd_client_new(idevice_t device, lockdownd_client_t *cli
609 return ret; 635 return ret;
610} 636}
611 637
612/** Creates a lockdownd client for the device and starts initial handshake. 638/**
613 * The handshake consists of query_type, validate_pair, pair and 639 * Creates a new lockdownd client for the device and starts initial handshake.
614 * start_session calls. 640 * The handshake consists out of query_type, validate_pair, pair and
641 * start_session calls. It uses the internal pairing record management.
615 * 642 *
616 * @param phone The device to create a lockdownd client for 643 * @param device The device to create a lockdownd client for
617 * @param client The pointer to the location of the new lockdownd_client 644 * @param client The pointer to the location of the new lockdownd_client
618 * @param label The label to use for communication. Usually the program name 645 * @param label The label to use for communication. Usually the program name.
646 * Pass NULL to disable sending the label in requests to lockdownd.
619 * 647 *
620 * @return an error code (LOCKDOWN_E_SUCCESS on success) 648 * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when client is NULL,
649 * LOCKDOWN_E_INVALID_CONF if configuration data is wrong
621 */ 650 */
622lockdownd_error_t lockdownd_client_new_with_handshake(idevice_t device, lockdownd_client_t *client, const char *label) 651lockdownd_error_t lockdownd_client_new_with_handshake(idevice_t device, lockdownd_client_t *client, const char *label)
623{ 652{
@@ -690,6 +719,14 @@ lockdownd_error_t lockdownd_client_new_with_handshake(idevice_t device, lockdown
690 return ret; 719 return ret;
691} 720}
692 721
722/**
723 * Returns a new plist from the supplied lockdownd pair record. The caller is
724 * responsible for freeing the plist.
725 *
726 * @param pair_record The pair record to create a plist from.
727 *
728 * @return A pair record plist from the device, NULL if pair_record is not set
729 */
693static plist_t lockdownd_pair_record_to_plist(lockdownd_pair_record_t pair_record) 730static plist_t lockdownd_pair_record_to_plist(lockdownd_pair_record_t pair_record)
694{ 731{
695 if (!pair_record) 732 if (!pair_record)
@@ -712,6 +749,17 @@ static plist_t lockdownd_pair_record_to_plist(lockdownd_pair_record_t pair_recor
712 return dict; 749 return dict;
713} 750}
714 751
752/**
753 * Generates a new pairing record plist and required certificates for the
754 * supplied public key of the device and the host_id of the caller's host
755 * computer.
756 *
757 * @param public_key The public key of the device.
758 * @param host_id The HostID to use for the pair record plist.
759 * @param pair_record_plist Holds the generated pair record.
760 *
761 * @return LOCKDOWN_E_SUCCESS on success
762 */
715static lockdownd_error_t generate_pair_record_plist(gnutls_datum_t public_key, char *host_id, plist_t *pair_record_plist) 763static lockdownd_error_t generate_pair_record_plist(gnutls_datum_t public_key, char *host_id, plist_t *pair_record_plist)
716{ 764{
717 lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; 765 lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
@@ -743,7 +791,8 @@ static lockdownd_error_t generate_pair_record_plist(gnutls_datum_t public_key, c
743 return ret; 791 return ret;
744} 792}
745 793
746/** Function used internally by lockdownd_pair() and lockdownd_validate_pair() 794/**
795 * Function used internally by lockdownd_pair() and lockdownd_validate_pair()
747 * 796 *
748 * @param client The lockdown client to pair with. 797 * @param client The lockdown client to pair with.
749 * @param pair_record The pair record to use for pairing. If NULL is passed, then 798 * @param pair_record The pair record to use for pairing. If NULL is passed, then
@@ -751,10 +800,17 @@ static lockdownd_error_t generate_pair_record_plist(gnutls_datum_t public_key, c
751 * generated automatically when pairing is done for the first time. 800 * generated automatically when pairing is done for the first time.
752 * @param verb This is either "Pair", "ValidatePair" or "Unpair". 801 * @param verb This is either "Pair", "ValidatePair" or "Unpair".
753 * 802 *
754 * @return an error code (LOCKDOWN_E_SUCCESS on success) 803 * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when client is NULL,
804 * LOCKDOWN_E_PLIST_ERROR if the pair_record certificates are wrong,
805 * LOCKDOWN_E_PAIRING_FAILED if the pairing failed,
806 * LOCKDOWN_E_PASSWORD_PROTECTED if the device is password protected,
807 * LOCKDOWN_E_INVALID_HOST_ID if the device does not know the caller's host id
755 */ 808 */
756static lockdownd_error_t lockdownd_do_pair(lockdownd_client_t client, lockdownd_pair_record_t pair_record, const char *verb) 809static lockdownd_error_t lockdownd_do_pair(lockdownd_client_t client, lockdownd_pair_record_t pair_record, const char *verb)
757{ 810{
811 if (!client)
812 return LOCKDOWN_E_INVALID_ARG;
813
758 lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; 814 lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
759 plist_t dict = NULL; 815 plist_t dict = NULL;
760 plist_t dict_record = NULL; 816 plist_t dict_record = NULL;
@@ -855,15 +911,18 @@ static lockdownd_error_t lockdownd_do_pair(lockdownd_client_t client, lockdownd_
855} 911}
856 912
857/** 913/**
858 * Pairs the device with the given HostID. 914 * Pairs the device using the supplied pair record.
859 * It's part of the lockdownd handshake.
860 * 915 *
861 * @param client The lockdown client to pair with. 916 * @param client The lockdown client to pair with.
862 * @param pair_record The pair record to use for pairing. If NULL is passed, then 917 * @param pair_record The pair record to use for pairing. If NULL is passed, then
863 * the pair records from the current machine are used. New records will be 918 * the pair records from the current machine are used. New records will be
864 * generated automatically when pairing is done for the first time. 919 * generated automatically when pairing is done for the first time.
865 * 920 *
866 * @return an error code (LOCKDOWN_E_SUCCESS on success) 921 * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when client is NULL,
922 * LOCKDOWN_E_PLIST_ERROR if the pair_record certificates are wrong,
923 * LOCKDOWN_E_PAIRING_FAILED if the pairing failed,
924 * LOCKDOWN_E_PASSWORD_PROTECTED if the device is password protected,
925 * LOCKDOWN_E_INVALID_HOST_ID if the device does not know the caller's host id
867 */ 926 */
868lockdownd_error_t lockdownd_pair(lockdownd_client_t client, lockdownd_pair_record_t pair_record) 927lockdownd_error_t lockdownd_pair(lockdownd_client_t client, lockdownd_pair_record_t pair_record)
869{ 928{
@@ -871,17 +930,21 @@ lockdownd_error_t lockdownd_pair(lockdownd_client_t client, lockdownd_pair_recor
871} 930}
872 931
873/** 932/**
874 * Pairs the device with the given HostID. The difference to lockdownd_pair() 933 * Validates if the device is paired with the given HostID. If succeeded them
875 * is that the specified host will become trusted host of the device. 934 * specified host will become trusted host of the device indicated by the
876 * It's part of the lockdownd handshake. 935 * lockdownd preference named TrustedHostAttached. Otherwise the host must because
936 * paired using lockdownd_pair() first.
877 * 937 *
878 * @param client The lockdown client to pair with. 938 * @param client The lockdown client to pair with.
879 * @param pair_record The pair record to validate pairing with. If NULL is 939 * @param pair_record The pair record to validate pairing with. If NULL is
880 * passed, then the pair records from the current machine are used. 940 * passed, then the pair record is read from the internal pairing record
881 * New records will be generated automatically when pairing is done 941 * management.
882 * for the first time.
883 * 942 *
884 * @return an error code (LOCKDOWN_E_SUCCESS on success) 943 * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when client is NULL,
944 * LOCKDOWN_E_PLIST_ERROR if the pair_record certificates are wrong,
945 * LOCKDOWN_E_PAIRING_FAILED if the pairing failed,
946 * LOCKDOWN_E_PASSWORD_PROTECTED if the device is password protected,
947 * LOCKDOWN_E_INVALID_HOST_ID if the device does not know the caller's host id
885 */ 948 */
886lockdownd_error_t lockdownd_validate_pair(lockdownd_client_t client, lockdownd_pair_record_t pair_record) 949lockdownd_error_t lockdownd_validate_pair(lockdownd_client_t client, lockdownd_pair_record_t pair_record)
887{ 950{
@@ -890,13 +953,17 @@ lockdownd_error_t lockdownd_validate_pair(lockdownd_client_t client, lockdownd_p
890 953
891/** 954/**
892 * Unpairs the device with the given HostID and removes the pairing records 955 * Unpairs the device with the given HostID and removes the pairing records
893 * from the device and host. 956 * from the device and host if the internal pairing record management is used.
894 * 957 *
895 * @param client The lockdown client to pair with. 958 * @param client The lockdown client to pair with.
896 * @param pair_record The pair record to use for unpair. If NULL is passed, then 959 * @param pair_record The pair record to use for unpair. If NULL is passed, then
897 * the pair records from the current machine are used. 960 * the pair records from the current machine are used.
898 * 961 *
899 * @return an error code (LOCKDOWN_E_SUCCESS on success) 962 * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when client is NULL,
963 * LOCKDOWN_E_PLIST_ERROR if the pair_record certificates are wrong,
964 * LOCKDOWN_E_PAIRING_FAILED if the pairing failed,
965 * LOCKDOWN_E_PASSWORD_PROTECTED if the device is password protected,
966 * LOCKDOWN_E_INVALID_HOST_ID if the device does not know the caller's host id
900 */ 967 */
901lockdownd_error_t lockdownd_unpair(lockdownd_client_t client, lockdownd_pair_record_t pair_record) 968lockdownd_error_t lockdownd_unpair(lockdownd_client_t client, lockdownd_pair_record_t pair_record)
902{ 969{
@@ -908,7 +975,7 @@ lockdownd_error_t lockdownd_unpair(lockdownd_client_t client, lockdownd_pair_rec
908 * 975 *
909 * @param client The lockdown client 976 * @param client The lockdown client
910 * 977 *
911 * @return an error code (LOCKDOWN_E_SUCCESS on success) 978 * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when client is NULL
912 */ 979 */
913lockdownd_error_t lockdownd_enter_recovery(lockdownd_client_t client) 980lockdownd_error_t lockdownd_enter_recovery(lockdownd_client_t client)
914{ 981{
@@ -939,12 +1006,12 @@ lockdownd_error_t lockdownd_enter_recovery(lockdownd_client_t client)
939} 1006}
940 1007
941/** 1008/**
942 * Performs the Goodbye Request to tell the device the communication 1009 * Sends the Goodbye request to lockdownd signaling the end of communication.
943 * session is now closed.
944 * 1010 *
945 * @param client The lockdown client 1011 * @param client The lockdown client
946 * 1012 *
947 * @return an error code (LOCKDOWN_E_SUCCESS on success) 1013 * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when client is NULL,
1014 * LOCKDOWN_E_PLIST_ERROR if the device did not acknowledge the request
948 */ 1015 */
949lockdownd_error_t lockdownd_goodbye(lockdownd_client_t client) 1016lockdownd_error_t lockdownd_goodbye(lockdownd_client_t client)
950{ 1017{
@@ -978,10 +1045,18 @@ lockdownd_error_t lockdownd_goodbye(lockdownd_client_t client)
978 return ret; 1045 return ret;
979} 1046}
980 1047
981/** Generates the device certificate from the public key as well as the host 1048/**
982 * and root certificates. 1049 * Generates the device certificate from the public key as well as the host
1050 * and root certificates.
983 * 1051 *
984 * @return an error code (LOCKDOWN_E_SUCCESS on success) 1052 * @param public_key The public key of the device to use for generation.
1053 * @param odevice_cert Holds the generated device certificate.
1054 * @param ohost_cert Holds the generated host certificate.
1055 * @param oroot_cert Holds the generated root certificate.
1056 *
1057 * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when a parameter is NULL,
1058 * LOCKDOWN_E_INVALID_CONF if the internal configuration system failed,
1059 * LOCKDOWN_E_SSL_ERROR if the certificates could not be generated
985 */ 1060 */
986lockdownd_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t * odevice_cert, 1061lockdownd_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t * odevice_cert,
987 gnutls_datum_t * ohost_cert, gnutls_datum_t * oroot_cert) 1062 gnutls_datum_t * ohost_cert, gnutls_datum_t * oroot_cert)
@@ -1116,15 +1191,18 @@ lockdownd_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datu
1116 return ret; 1191 return ret;
1117} 1192}
1118 1193
1119/** Starts communication with lockdownd after the device has been paired, 1194/**
1120 * and if the device requires it, switches to SSL mode. 1195 * Opens a session with lockdownd and switches to SSL mode if device wants it.
1121 * 1196 *
1122 * @param client The lockdownd client 1197 * @param client The lockdownd client
1123 * @param host_id The HostID of the computer 1198 * @param host_id The HostID of the computer
1124 * @param session_id The session_id of the created session 1199 * @param session_id The new session_id of the created session
1125 * @param ssl_enabled Whether SSL communication is used in the session 1200 * @param ssl_enabled Whether SSL communication is used in the session
1126 * 1201 *
1127 * @return an error code (LOCKDOWN_E_SUCCESS on success) 1202 * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when a client or
1203 * host_id is NULL, LOCKDOWN_E_PLIST_ERROR if the response plist had errors,
1204 * LOCKDOWN_E_INVALID_HOST_ID if the device does not know the supplied HostID,
1205 * LOCKDOWN_E_SSL_ERROR if enabling SSL communication failed
1128 */ 1206 */
1129lockdownd_error_t lockdownd_start_session(lockdownd_client_t client, const char *host_id, char **session_id, int *ssl_enabled) 1207lockdownd_error_t lockdownd_start_session(lockdownd_client_t client, const char *host_id, char **session_id, int *ssl_enabled)
1130{ 1208{
@@ -1212,13 +1290,17 @@ lockdownd_error_t lockdownd_start_session(lockdownd_client_t client, const char
1212 return ret; 1290 return ret;
1213} 1291}
1214 1292
1215/** Command to start the desired service 1293/**
1294 * Requests to start a service and retrieve it's port on success.
1216 * 1295 *
1217 * @param client The lockdownd client 1296 * @param client The lockdownd client
1218 * @param service The name of the service to start 1297 * @param service The name of the service to start
1219 * @param port The port number the service was started on 1298 * @param port The port number the service was started on
1220 1299
1221 * @return an error code (LOCKDOWN_E_SUCCESS on success) 1300 * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG if a parameter
1301 * is NULL, LOCKDOWN_E_INVALID_SERVICE if the requested service is not known
1302 * by the device, LOCKDOWN_E_START_SERVICE_FAILED if the service could not because
1303 * started by the device
1222 */ 1304 */
1223lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char *service, uint16_t *port) 1305lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char *service, uint16_t *port)
1224{ 1306{
@@ -1300,10 +1382,15 @@ lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char
1300 * 1382 *
1301 * @see http://iphone-docs.org/doku.php?id=docs:protocols:activation 1383 * @see http://iphone-docs.org/doku.php?id=docs:protocols:activation
1302 * 1384 *
1303 * @param control The lockdown client 1385 * @param client The lockdown client
1304 * @param activation_record The activation record plist dictionary 1386 * @param activation_record The activation record plist dictionary
1305 * 1387 *
1306 * @return an error code (LOCKDOWN_E_SUCCESS on success) 1388 * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when client or
1389 * activation_record is NULL, LOCKDOWN_E_NO_RUNNING_SESSION if no session is
1390 * open, LOCKDOWN_E_PLIST_ERROR if the received plist is broken,
1391 * LOCKDOWN_E_ACTIVATION_FAILED if the activation failed,
1392 * LOCKDOWN_E_INVALID_ACTIVATION_RECORD if the device reports that the
1393 * activation_record is invalid
1307 */ 1394 */
1308lockdownd_error_t lockdownd_activate(lockdownd_client_t client, plist_t activation_record) 1395lockdownd_error_t lockdownd_activate(lockdownd_client_t client, plist_t activation_record)
1309{ 1396{
@@ -1357,12 +1444,14 @@ lockdownd_error_t lockdownd_activate(lockdownd_client_t client, plist_t activati
1357} 1444}
1358 1445
1359/** 1446/**
1360 * Deactivates the device, returning it to the locked 1447 * Deactivates the device, returning it to the locked “Activate with iTunes”
1361 * “Activate with iTunes” screen. 1448 * screen.
1362 * 1449 *
1363 * @param control The lockdown client 1450 * @param client The lockdown client
1364 * 1451 *
1365 * @return an error code (LOCKDOWN_E_SUCCESS on success) 1452 * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when client is NULL,
1453 * LOCKDOWN_E_NO_RUNNING_SESSION if no session is open,
1454 * LOCKDOWN_E_PLIST_ERROR if the received plist is broken
1366 */ 1455 */
1367lockdownd_error_t lockdownd_deactivate(lockdownd_client_t client) 1456lockdownd_error_t lockdownd_deactivate(lockdownd_client_t client)
1368{ 1457{
diff --git a/src/mobilebackup.c b/src/mobilebackup.c
index c5f0a84..15da0a1 100644
--- a/src/mobilebackup.c
+++ b/src/mobilebackup.c
@@ -59,6 +59,18 @@ static mobilebackup_error_t mobilebackup_error(device_link_service_error_t err)
59 return MOBILEBACKUP_E_UNKNOWN_ERROR; 59 return MOBILEBACKUP_E_UNKNOWN_ERROR;
60} 60}
61 61
62/**
63 * Connects to the mobilebackup service on the specified device.
64 *
65 * @param device The device to connect to.
66 * @param port Destination port (usually given by lockdownd_start_service).
67 * @param client Pointer that will be set to a newly allocated
68 * mobilebackup_client_t upon successful return.
69 *
70 * @return MOBILEBACKUP_E_SUCCESS on success, MOBILEBACKUP_E_INVALID ARG if one
71 * or more parameters are invalid, or DEVICE_LINK_SERVICE_E_BAD_VERSION if
72 * the mobilebackup version on the device is newer.
73 */
62mobilebackup_error_t mobilebackup_client_new(idevice_t device, uint16_t port, 74mobilebackup_error_t mobilebackup_client_new(idevice_t device, uint16_t port,
63 mobilebackup_client_t * client) 75 mobilebackup_client_t * client)
64{ 76{
@@ -87,6 +99,15 @@ mobilebackup_error_t mobilebackup_client_new(idevice_t device, uint16_t port,
87 return ret; 99 return ret;
88} 100}
89 101
102/**
103 * Disconnects a mobilebackup client from the device and frees up the
104 * mobilebackup client data.
105 *
106 * @param client The mobilebackup client to disconnect and free.
107 *
108 * @return MOBILEBACKUP_E_SUCCESS on success, or MOBILEBACKUP_E_INVALID_ARG
109 * if client is NULL.
110 */
90mobilebackup_error_t mobilebackup_client_free(mobilebackup_client_t client) 111mobilebackup_error_t mobilebackup_client_free(mobilebackup_client_t client)
91{ 112{
92 if (!client) 113 if (!client)
@@ -97,9 +118,10 @@ mobilebackup_error_t mobilebackup_client_free(mobilebackup_client_t client)
97 return err; 118 return err;
98} 119}
99 120
100/** Polls the device for MobileBackup data. 121/**
122 * Polls the device for mobilebackup data.
101 * 123 *
102 * @param client The MobileBackup client 124 * @param client The mobilebackup client
103 * @param plist A pointer to the location where the plist should be stored 125 * @param plist A pointer to the location where the plist should be stored
104 * 126 *
105 * @return an error code 127 * @return an error code
@@ -112,12 +134,13 @@ mobilebackup_error_t mobilebackup_receive(mobilebackup_client_t client, plist_t
112 return ret; 134 return ret;
113} 135}
114 136
115/** Sends MobileBackup data to the device 137/**
138 * Sends mobilebackup data to the device
116 * 139 *
117 * @note This function is low-level and should only be used if you need to send 140 * @note This function is low-level and should only be used if you need to send
118 * a new type of message. 141 * a new type of message.
119 * 142 *
120 * @param client The MobileBackup client 143 * @param client The mobilebackup client
121 * @param plist The location of the plist to send 144 * @param plist The location of the plist to send
122 * 145 *
123 * @return an error code 146 * @return an error code
diff --git a/src/mobilesync.c b/src/mobilesync.c
index 88d8497..47fcfdf 100644
--- a/src/mobilesync.c
+++ b/src/mobilesync.c
@@ -59,6 +59,18 @@ static mobilesync_error_t mobilesync_error(device_link_service_error_t err)
59 return MOBILESYNC_E_UNKNOWN_ERROR; 59 return MOBILESYNC_E_UNKNOWN_ERROR;
60} 60}
61 61
62/**
63 * Connects to the mobilesync service on the specified device.
64 *
65 * @param device The device to connect to.
66 * @param port Destination port (usually given by lockdownd_start_service).
67 * @param client Pointer that will be set to a newly allocated
68 * mobilesync_client_t upon successful return.
69 *
70 * @return MOBILESYNC_E_SUCCESS on success, MOBILESYNC_E_INVALID ARG if one
71 * or more parameters are invalid, or DEVICE_LINK_SERVICE_E_BAD_VERSION if
72 * the mobilesync version on the device is newer.
73 */
62mobilesync_error_t mobilesync_client_new(idevice_t device, uint16_t port, 74mobilesync_error_t mobilesync_client_new(idevice_t device, uint16_t port,
63 mobilesync_client_t * client) 75 mobilesync_client_t * client)
64{ 76{
@@ -87,6 +99,15 @@ mobilesync_error_t mobilesync_client_new(idevice_t device, uint16_t port,
87 return ret; 99 return ret;
88} 100}
89 101
102/**
103 * Disconnects a mobilesync client from the device and frees up the
104 * mobilesync client data.
105 *
106 * @param client The mobilesync client to disconnect and free.
107 *
108 * @return MOBILESYNC_E_SUCCESS on success, or MOBILESYNC_E_INVALID_ARG
109 * if client is NULL.
110 */
90mobilesync_error_t mobilesync_client_free(mobilesync_client_t client) 111mobilesync_error_t mobilesync_client_free(mobilesync_client_t client)
91{ 112{
92 if (!client) 113 if (!client)
@@ -97,9 +118,10 @@ mobilesync_error_t mobilesync_client_free(mobilesync_client_t client)
97 return err; 118 return err;
98} 119}
99 120
100/** Polls the device for MobileSync data. 121/**
122 * Polls the device for mobilesync data.
101 * 123 *
102 * @param client The MobileSync client 124 * @param client The mobilesync client
103 * @param plist A pointer to the location where the plist should be stored 125 * @param plist A pointer to the location where the plist should be stored
104 * 126 *
105 * @return an error code 127 * @return an error code
@@ -112,12 +134,13 @@ mobilesync_error_t mobilesync_receive(mobilesync_client_t client, plist_t * plis
112 return ret; 134 return ret;
113} 135}
114 136
115/** Sends MobileSync data to the device 137/**
138 * Sends mobilesync data to the device
116 * 139 *
117 * @note This function is low-level and should only be used if you need to send 140 * @note This function is low-level and should only be used if you need to send
118 * a new type of message. 141 * a new type of message.
119 * 142 *
120 * @param client The MobileSync client 143 * @param client The mobilesync client
121 * @param plist The location of the plist to send 144 * @param plist The location of the plist to send
122 * 145 *
123 * @return an error code 146 * @return an error code
diff --git a/src/sbservices.c b/src/sbservices.c
index 91f4b9c..076e25d 100644
--- a/src/sbservices.c
+++ b/src/sbservices.c
@@ -208,7 +208,7 @@ sbservices_error_t sbservices_set_icon_state(sbservices_client_t client, plist_t
208 if (res != SBSERVICES_E_SUCCESS) { 208 if (res != SBSERVICES_E_SUCCESS) {
209 debug_info("could not send plist, error %d", res); 209 debug_info("could not send plist, error %d", res);
210 } 210 }
211 // NO RESPONSE 211 /* NO RESPONSE */
212 212
213 if (dict) { 213 if (dict) {
214 plist_free(dict); 214 plist_free(dict);
diff --git a/src/screenshotr.h b/src/screenshotr.h
index 5ba93b0..df6774a 100644
--- a/src/screenshotr.h
+++ b/src/screenshotr.h
@@ -1,4 +1,4 @@
1/* 1/*
2 * screenshotr.h 2 * screenshotr.h
3 * com.apple.mobile.screenshotr service header file. 3 * com.apple.mobile.screenshotr service header file.
4 * 4 *
diff --git a/src/userpref.c b/src/userpref.c
index 3a8a9d6..59c61b6 100644
--- a/src/userpref.c
+++ b/src/userpref.c
@@ -42,7 +42,8 @@
42#define LIBIMOBILEDEVICE_HOST_CERTIF "HostCertificate.pem" 42#define LIBIMOBILEDEVICE_HOST_CERTIF "HostCertificate.pem"
43 43
44 44
45/** Creates a freedesktop compatible configuration directory. 45/**
46 * Creates a freedesktop compatible configuration directory.
46 */ 47 */
47static void userpref_create_config_dir(void) 48static void userpref_create_config_dir(void)
48{ 49{
@@ -60,7 +61,8 @@ static int get_rand(int min, int max)
60 return retval; 61 return retval;
61} 62}
62 63
63/** Generates a valid HostID (which is actually a UUID). 64/**
65 * Generates a valid HostID (which is actually a UUID).
64 * 66 *
65 * @return A null terminated string containing a valid HostID. 67 * @return A null terminated string containing a valid HostID.
66 */ 68 */
@@ -85,7 +87,8 @@ static char *userpref_generate_host_id()
85 return hostid; 87 return hostid;
86} 88}
87 89
88/** Store HostID in config file. 90/**
91 * Store HostID in config file.
89 * 92 *
90 * @param host_id A null terminated string containing a valid HostID. 93 * @param host_id A null terminated string containing a valid HostID.
91 */ 94 */
@@ -123,7 +126,8 @@ static int userpref_set_host_id(const char *host_id)
123 return 1; 126 return 1;
124} 127}
125 128
126/** Reads the HostID from a previously generated configuration file. 129/**
130 * Reads the HostID from a previously generated configuration file.
127 * 131 *
128 * @note It is the responsibility of the calling function to free the returned host_id 132 * @note It is the responsibility of the calling function to free the returned host_id
129 * 133 *
@@ -158,7 +162,8 @@ void userpref_get_host_id(char **host_id)
158 debug_info("Using %s as HostID", *host_id); 162 debug_info("Using %s as HostID", *host_id);
159} 163}
160 164
161/** Determines whether this device has been connected to this system before. 165/**
166 * Determines whether this device has been connected to this system before.
162 * 167 *
163 * @param uid The device uid as given by the device. 168 * @param uid The device uid as given by the device.
164 * 169 *
@@ -180,8 +185,9 @@ int userpref_has_device_public_key(const char *uuid)
180 return ret; 185 return ret;
181} 186}
182 187
183/** Mark the device (as represented by the key) as having connected to this 188/**
184 * configuration. 189 * Mark the device (as represented by the key) as having connected to this
190 * configuration.
185 * 191 *
186 * @param public_key The public key given by the device 192 * @param public_key The public key given by the device
187 * 193 *
@@ -213,7 +219,8 @@ userpref_error_t userpref_set_device_public_key(const char *uuid, gnutls_datum_t
213 return USERPREF_E_SUCCESS; 219 return USERPREF_E_SUCCESS;
214} 220}
215 221
216/** Remove the public key stored for the device with uuid from this host. 222/**
223 * Remove the public key stored for the device with uuid from this host.
217 * 224 *
218 * @param uuid The uuid of the device 225 * @param uuid The uuid of the device
219 * 226 *
@@ -237,7 +244,8 @@ userpref_error_t userpref_remove_device_public_key(const char *uuid)
237 return USERPREF_E_SUCCESS; 244 return USERPREF_E_SUCCESS;
238} 245}
239 246
240/** Private function which reads the given file into a gnutls structure. 247/**
248 * Private function which reads the given file into a gnutls structure.
241 * 249 *
242 * @param file The filename of the file to read 250 * @param file The filename of the file to read
243 * @param data The pointer at which to store the data. 251 * @param data The pointer at which to store the data.
@@ -266,7 +274,8 @@ static int userpref_get_file_contents(const char *file, gnutls_datum_t * data)
266 return success; 274 return success;
267} 275}
268 276
269/** Private function which generate private keys and certificates. 277/**
278 * Private function which generate private keys and certificates.
270 * 279 *
271 * @return 1 if keys were successfully generated, 0 otherwise 280 * @return 1 if keys were successfully generated, 0 otherwise
272 */ 281 */
@@ -365,7 +374,8 @@ static userpref_error_t userpref_gen_keys_and_cert(void)
365 return ret; 374 return ret;
366} 375}
367 376
368/** Private function which import the given key into a gnutls structure. 377/**
378 * Private function which import the given key into a gnutls structure.
369 * 379 *
370 * @param key_name The filename of the private key to import. 380 * @param key_name The filename of the private key to import.
371 * @param key the gnutls key structure. 381 * @param key the gnutls key structure.
@@ -387,7 +397,8 @@ static userpref_error_t userpref_import_key(const char* key_name, gnutls_x509_pr
387 return ret; 397 return ret;
388} 398}
389 399
390/** Private function which import the given certificate into a gnutls structure. 400/**
401 * Private function which import the given certificate into a gnutls structure.
391 * 402 *
392 * @param crt_name The filename of the certificate to import. 403 * @param crt_name The filename of the certificate to import.
393 * @param cert the gnutls certificate structure. 404 * @param cert the gnutls certificate structure.
@@ -409,7 +420,8 @@ static userpref_error_t userpref_import_crt(const char* crt_name, gnutls_x509_cr
409 return ret; 420 return ret;
410} 421}
411 422
412/** Function to retrieve host keys and certificates. 423/**
424 * Function to retrieve host keys and certificates.
413 * This function trigger key generation if they do not exists yet or are invalid. 425 * This function trigger key generation if they do not exists yet or are invalid.
414 * 426 *
415 * @note This function can take few seconds to complete (typically 5 seconds) 427 * @note This function can take few seconds to complete (typically 5 seconds)
@@ -459,7 +471,8 @@ userpref_error_t userpref_get_keys_and_certs(gnutls_x509_privkey_t root_privkey,
459 return ret; 471 return ret;
460} 472}
461 473
462/** Function to retrieve certificates encoded in PEM format. 474/**
475 * Function to retrieve certificates encoded in PEM format.
463 * 476 *
464 * @param pem_root_cert The root certificate. 477 * @param pem_root_cert The root certificate.
465 * @param pem_host_cert The host certificate. 478 * @param pem_host_cert The host certificate.
@@ -480,7 +493,8 @@ userpref_error_t userpref_get_certs_as_pem(gnutls_datum_t *pem_root_cert, gnutls
480 return USERPREF_E_INVALID_CONF; 493 return USERPREF_E_INVALID_CONF;
481} 494}
482 495
483/** Create and save a configuration file containing the given data. 496/**
497 * Create and save a configuration file containing the given data.
484 * 498 *
485 * @note: All fields must specified and be non-null 499 * @note: All fields must specified and be non-null
486 * 500 *