39
39
#define EMPTY_PARAMETER_STRING "___EmptyParameterString___"
42
* Convert an device_link_service_error_t value to an mobilesync_error_t value.
42
* Convert an #device_link_service_error_t value to an #mobilesync_error_t value.
43
43
* Used internally to get correct error codes when using device_link_service stuff.
45
* @param err An device_link_service_error_t error code
45
* @param err A #device_link_service_error_t error code
47
* @return A matching mobilesync_error_t error code,
47
* @return A matching #mobilesync_error_t error code,
48
48
* MOBILESYNC_E_UNKNOWN_ERROR otherwise.
50
50
static mobilesync_error_t mobilesync_error(device_link_service_error_t err)
70
70
* Connects to the mobilesync service on the specified device.
72
72
* @param device The device to connect to.
73
* @param port Destination port (usually given by lockdownd_start_service).
73
* @param port Destination port (usually given by lockdownd_start_service()).
74
74
* @param client Pointer that will be set to a newly allocated
75
* mobilesync_client_t upon successful return.
75
* #mobilesync_client_t upon successful return.
77
* @return MOBILESYNC_E_SUCCESS on success, MOBILESYNC_E_INVALID ARG if one
78
* or more parameters are invalid, or DEVICE_LINK_SERVICE_E_BAD_VERSION if
79
* the mobilesync version on the device is newer.
77
* @retval MOBILESYNC_E_SUCCESS on success
78
* @retval MOBILESYNC_E_INVALID_ARG if one or more parameters are invalid
79
* @retval DEVICE_LINK_SERVICE_E_BAD_VERSION if the mobilesync version on
80
* the device is newer.
81
82
mobilesync_error_t mobilesync_client_new(idevice_t device, uint16_t port,
82
83
mobilesync_client_t * client)
115
116
* @param client The mobilesync client to disconnect and free.
117
* @return MOBILESYNC_E_SUCCESS on success, or MOBILESYNC_E_INVALID_ARG
118
* @retval MOBILESYNC_E_SUCCESS on success
119
* @retval MOBILESYNC_E_INVALID_ARG if \a client is NULL.
120
121
mobilesync_error_t mobilesync_client_free(mobilesync_client_t client)
123
124
return MOBILESYNC_E_INVALID_ARG;
124
device_link_service_disconnect(client->parent);
125
device_link_service_disconnect(client->parent, "All done, thanks for the memories");
125
126
mobilesync_error_t err = mobilesync_error(device_link_service_client_free(client->parent));
173
174
* @param sync_type A pointer to store the sync type reported by the device_anchor
174
175
* @param device_data_class_version The version of the data class storage on the device
176
* @return MOBILESYNC_E_SUCCESS on success, MOBILESYNC_E_INVALID_ARG if
177
* one of the parameters is invalid, MOBILESYNC_E_PLIST_ERROR if
178
* the received plist is not of valid form, MOBILESYNC_E_SYNC_REFUSED if the
179
* device refused to sync or MOBILESYNC_E_CANCELLED if the device explicitly
180
* cancelled the sync request
177
* @retval MOBILESYNC_E_SUCCESS on success
178
* @retval MOBILESYNC_E_INVALID_ARG if one of the parameters is invalid
179
* @retval MOBILESYNC_E_PLIST_ERROR if the received plist is not of valid form
180
* @retval MOBILESYNC_E_SYNC_REFUSED if the device refused to sync
181
* @retval MOBILESYNC_E_CANCELLED if the device explicitly cancelled the
182
184
mobilesync_error_t mobilesync_start(mobilesync_client_t client, const char *data_class, mobilesync_anchors_t anchors, uint64_t computer_data_class_version, mobilesync_sync_type_t *sync_type, uint64_t *device_data_class_version)
314
316
* @param client The mobilesync client
316
* @return MOBILESYNC_E_SUCCESS on success, MOBILESYNC_E_INVALID_ARG if
317
* one of the parameters is invalid, MOBILESYNC_E_PLIST_ERROR if
318
* the received plist is not of valid form
318
* @retval MOBILESYNC_E_SUCCESS on success
319
* @retval MOBILESYNC_E_INVALID_ARG if one of the parameters is invalid
320
* @retval MOBILESYNC_E_PLIST_ERROR if the received plist is not of valid
320
323
mobilesync_error_t mobilesync_finish(mobilesync_client_t client)
410
413
* @param client The mobilesync client
412
* @return MOBILESYNC_E_SUCCESS on success, MOBILESYNC_E_INVALID_ARG if
413
* one of the parameters is invalid
415
* @retval MOBILESYNC_E_SUCCESS on success
416
* @retval MOBILESYNC_E_INVALID_ARG if one of the parameters is invalid
415
418
mobilesync_error_t mobilesync_get_all_records_from_device(mobilesync_client_t client)
425
428
* @param client The mobilesync client
427
* @return MOBILESYNC_E_SUCCESS on success, MOBILESYNC_E_INVALID_ARG if
428
* one of the parameters is invalid
430
* @retval MOBILESYNC_E_SUCCESS on success
431
* @retval MOBILESYNC_E_INVALID_ARG if one of the parameters is invalid
430
433
mobilesync_error_t mobilesync_get_changes_from_device(mobilesync_client_t client)
438
441
* @param client The mobilesync client
439
442
* @param entities A pointer to store the changed entity records as a PLIST_DICT
440
* @param is_last_record A pointer to store a flag indiciating if this submission is the last one
443
* @param is_last_record A pointer to store a flag indicating if this submission is the last one
441
444
* @param actions A pointer to additional flags the device is sending or NULL to ignore
443
* @return MOBILESYNC_E_SUCCESS on success, MOBILESYNC_E_INVALID_ARG if
444
* one of the parameters is invalid, MOBILESYNC_E_CANCELLED if the device
445
* explicitly cancelled the session
446
* @retval MOBILESYNC_E_SUCCESS on success
447
* @retval MOBILESYNC_E_INVALID_ARG if one of the parameters is invalid
448
* @retval MOBILESYNC_E_CANCELLED if the device explicitly cancelled the
447
451
mobilesync_error_t mobilesync_receive_changes(mobilesync_client_t client, plist_t *entities, uint8_t *is_last_record, plist_t *actions)
519
* Requests the device to delete all records of the current data class
521
* @note The operation must be called after starting synchronization.
523
* @param client The mobilesync client
525
* @retval MOBILESYNC_E_SUCCESS on success
526
* @retval MOBILESYNC_E_INVALID_ARG if one of the parameters is invalid
527
* @retval MOBILESYNC_E_PLIST_ERROR if the received plist is not of valid form
529
mobilesync_error_t mobilesync_clear_all_records_on_device(mobilesync_client_t client)
531
if (!client || !client->data_class) {
532
return MOBILESYNC_E_INVALID_ARG;
535
mobilesync_error_t err = MOBILESYNC_E_UNKNOWN_ERROR;
537
plist_t response_type_node = NULL;
538
char *response_type = NULL;
540
msg = plist_new_array();
541
plist_array_append_item(msg, plist_new_string("SDMessageClearAllRecordsOnDevice"));
542
plist_array_append_item(msg, plist_new_string(client->data_class));
543
plist_array_append_item(msg, plist_new_string(EMPTY_PARAMETER_STRING));
545
err = mobilesync_send(client, msg);
547
if (err != MOBILESYNC_E_SUCCESS) {
554
err = mobilesync_receive(client, &msg);
556
if (err != MOBILESYNC_E_SUCCESS) {
560
response_type_node = plist_array_get_item(msg, 0);
561
if (!response_type_node) {
562
err = MOBILESYNC_E_PLIST_ERROR;
566
plist_get_string_val(response_type_node, &response_type);
567
if (!response_type) {
568
err = MOBILESYNC_E_PLIST_ERROR;
572
if (!strcmp(response_type, "SDMessageCancelSession")) {
574
err = MOBILESYNC_E_CANCELLED;
575
plist_get_string_val(plist_array_get_item(msg, 2), &reason);
576
debug_info("Device cancelled: %s", reason);
581
if (strcmp(response_type, "SDMessageDeviceWillClearAllRecords")) {
582
err = MOBILESYNC_E_PLIST_ERROR;
588
response_type = NULL;
515
599
* Acknowledges to the device that the changes have been merged on the computer
517
601
* @param client The mobilesync client
519
* @return MOBILESYNC_E_SUCCESS on success, MOBILESYNC_E_INVALID_ARG if
520
* one of the parameters is invalid
603
* @retval MOBILESYNC_E_SUCCESS on success
604
* @retval MOBILESYNC_E_INVALID_ARG if one of the parameters is invalid
522
606
mobilesync_error_t mobilesync_acknowledge_changes_from_device(mobilesync_client_t client)
561
645
* @param client The mobilesync client
563
* @return MOBILESYNC_E_SUCCESS on success, MOBILESYNC_E_INVALID_ARG if
564
* one of the parameters is invalid, MOBILESYNC_E_PLIST_ERROR if
565
* the received plist is not of valid form, MOBILESYNC_E_WRONG_DIRECTION if the
566
* current sync direction does not permit this call, MOBILESYNC_E_CANCELLED if
567
* the device explicitly cancelled the session or MOBILESYNC_E_NOT_READY if the
568
* device is not ready to start receiving any changes
647
* @retval MOBILESYNC_E_SUCCESS on success
648
* @retval MOBILESYNC_E_INVALID_ARG if one of the parameters is invalid
649
* @retval MOBILESYNC_E_PLIST_ERROR if the received plist is not of valid form
650
* @retval MOBILESYNC_E_WRONG_DIRECTION if the current sync direction does
651
* not permit this call
652
* @retval MOBILESYNC_E_CANCELLED if the device explicitly cancelled the
654
* @retval MOBILESYNC_E_NOT_READY if the device is not ready to start
655
* receiving any changes
570
657
mobilesync_error_t mobilesync_ready_to_send_changes_from_computer(mobilesync_client_t client)
634
* Sends changed entitites of the currently set data class to the device
725
* Sends changed entities of the currently set data class to the device
636
727
* @param client The mobilesync client
637
728
* @param entities The changed entity records as a PLIST_DICT
638
* @param is_last_record A flag indiciating if this submission is the last one
729
* @param is_last_record A flag indicating if this submission is the last one
639
730
* @param actions Additional actions for the device created with mobilesync_actions_new()
640
731
* or NULL if no actions should be passed
642
* @return MOBILESYNC_E_SUCCESS on success, MOBILESYNC_E_INVALID_ARG if
643
* one of the parameters is invalid, MOBILESYNC_E_WRONG_DIRECTION if the
644
* current sync direction does not permit this call
733
* @retval MOBILESYNC_E_SUCCESS on success
734
* @retval MOBILESYNC_E_INVALID_ARG if one of the parameters is invalid,
735
* @retval MOBILESYNC_E_WRONG_DIRECTION if the current sync direction does
736
* not permit this call
646
738
mobilesync_error_t mobilesync_send_changes(mobilesync_client_t client, plist_t entities, uint8_t is_last_record, plist_t actions)
677
769
* @param client The mobilesync client
678
770
* @param mapping A pointer to an array plist containing a dict of identifier remappings
680
* @return MOBILESYNC_E_SUCCESS on success, MOBILESYNC_E_INVALID_ARG if
681
* one of the parameters is invalid, MOBILESYNC_E_PLIST_ERROR if
682
* the received plist is not of valid form, MOBILESYNC_E_WRONG_DIRECTION if the
683
* current sync direction does not permit this call or MOBILESYNC_E_CANCELLED if
684
* the device explicitly cancelled the session
772
* @retval MOBILESYNC_E_SUCCESS on success
773
* @retval MOBILESYNC_E_INVALID_ARG if one of the parameters is invalid
774
* @retval MOBILESYNC_E_PLIST_ERROR if the received plist is not of valid
776
* @retval MOBILESYNC_E_WRONG_DIRECTION if the current sync direction does
777
* not permit this call
778
* @retval MOBILESYNC_E_CANCELLED if the device explicitly cancelled the
686
781
mobilesync_error_t mobilesync_remap_identifiers(mobilesync_client_t client, plist_t *mapping)
756
* Cancells a running synchronization session with a device at any time.
851
* Cancels a running synchronization session with a device at any time.
758
853
* @param client The mobilesync client
759
854
* @param reason The reason to supply to the device for cancelling
761
* @return MOBILESYNC_E_SUCCESS on success, MOBILESYNC_E_INVALID_ARG if
762
* one of the parameters is invalid
856
* @retval MOBILESYNC_E_SUCCESS on success
857
* @retval MOBILESYNC_E_INVALID_ARG if one of the parameters is invalid
764
859
mobilesync_error_t mobilesync_cancel(mobilesync_client_t client, const char* reason)
794
889
* if none is known yet which for instance is true on first synchronization.
795
890
* @param computer_anchor An arbitrary string to use as anchor for the computer.
797
* @return A new mobilesync_anchors_t struct. Must be freed using mobilesync_anchors_free().
892
* @return A new #mobilesync_anchors_t struct. Must be freed using mobilesync_anchors_free().
799
894
mobilesync_anchors_t mobilesync_anchors_new(const char *device_anchor, const char *computer_anchor)
851
946
* @note The known keys so far are "SyncDeviceLinkEntityNamesKey" which expects
852
947
* an array of entity names, followed by a count paramter as well as
853
948
* "SyncDeviceLinkAllRecordsOfPulledEntityTypeSentKey" which expects an
854
* integer to use as a boolean value indiciating that the device should
949
* integer to use as a boolean value indicating that the device should
855
950
* link submitted changes and report remapped identifiers.
857
952
void mobilesync_actions_add(plist_t actions, ...)