~ubuntu-branches/ubuntu/quantal/libimobiledevice/quantal-updates

« back to all changes in this revision

Viewing changes to src/mobilesync.c

  • Committer: Bazaar Package Importer
  • Author(s): Julien Lavergne
  • Date: 2011-04-30 13:28:43 UTC
  • mfrom: (2.1.10 experimental)
  • Revision ID: james.westby@ubuntu.com-20110430132843-hivpq380w8x0h1x0
Tags: 1.1.1-1
* New upstream release.
* debian/changelog: Fix typo in previous entry.
* debian/patches:
 - 90_fix_4.3_iOS.patch: Merged upstream.
* debian/libimobiledevice-utils.manpages:
 - Add man page for idevicebackup2.
 - Add man page for idevicedate.
 - Add upstream man pages for ideviceenterrecovery and idevicepair.
* debian/control:
 - Remove Conflitcs of libimobiledevice2 to make it installable with
   libimobiledevice1 (Closes: #620065).
 - Add Conflicts/Replaces also on libimobiledevice0-dbg (LP: #693895)
 - Remove python-support from Build-Depends.
 - Increase required python-all-dev package version to 2.6.6-3~.
 - Remove XB-Python-Version fields.
 - Add X-Python-Version field.
 - Bump Standards-Version to 3.9.2.0 (no change needed).
* debian/copyright:
 - Update copyright years.
* debian/libimobiledevice2.symbols:
 - Update with new symbols.
* debian/rules:
 - Use --with python2.
 - Pass --no-guessing-versions to dh_python2 to build only with default
   python version.
* debian/pycompat:
 - Removed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
#define EMPTY_PARAMETER_STRING "___EmptyParameterString___"
40
40
 
41
41
/**
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.
44
44
 *
45
 
 * @param err An device_link_service_error_t error code
 
45
 * @param err A #device_link_service_error_t error code
46
46
 *
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.
49
49
 */
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.
71
71
 *
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.
76
76
 *
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.
80
81
 */
81
82
mobilesync_error_t mobilesync_client_new(idevice_t device, uint16_t port,
82
83
                                                   mobilesync_client_t * client)
114
115
 *
115
116
 * @param client The mobilesync client to disconnect and free.
116
117
 *
117
 
 * @return MOBILESYNC_E_SUCCESS on success, or MOBILESYNC_E_INVALID_ARG
118
 
 *     if client is NULL.
 
118
 * @retval MOBILESYNC_E_SUCCESS on success
 
119
 * @retval MOBILESYNC_E_INVALID_ARG if \a client is NULL.
119
120
 */
120
121
mobilesync_error_t mobilesync_client_free(mobilesync_client_t client)
121
122
{
122
123
        if (!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));
126
127
        free(client);
127
128
        return err;
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
175
176
 *
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
 * sync request
181
183
 */
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)
183
185
{
313
315
 *
314
316
 * @param client The mobilesync client
315
317
 *
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
 
321
 * form
319
322
 */
320
323
mobilesync_error_t mobilesync_finish(mobilesync_client_t client)
321
324
{
409
412
 *
410
413
 * @param client The mobilesync client
411
414
 *
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
414
417
 */
415
418
mobilesync_error_t mobilesync_get_all_records_from_device(mobilesync_client_t client)
416
419
{
424
427
 *
425
428
 * @param client The mobilesync client
426
429
 *
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
429
432
 */
430
433
mobilesync_error_t mobilesync_get_changes_from_device(mobilesync_client_t client)
431
434
{
437
440
 *
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
442
445
 *
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
 
449
 * session
446
450
 */
447
451
mobilesync_error_t mobilesync_receive_changes(mobilesync_client_t client, plist_t *entities, uint8_t *is_last_record, plist_t *actions)
448
452
{
512
516
}
513
517
 
514
518
/**
 
519
 * Requests the device to delete all records of the current data class
 
520
 *
 
521
 * @note The operation must be called after starting synchronization.
 
522
 *
 
523
 * @param client The mobilesync client
 
524
 *
 
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
 
528
 */
 
529
mobilesync_error_t mobilesync_clear_all_records_on_device(mobilesync_client_t client)
 
530
{
 
531
        if (!client || !client->data_class) {
 
532
                return MOBILESYNC_E_INVALID_ARG;
 
533
        }
 
534
 
 
535
        mobilesync_error_t err = MOBILESYNC_E_UNKNOWN_ERROR;
 
536
        plist_t msg = NULL;
 
537
        plist_t response_type_node = NULL;
 
538
        char *response_type = NULL;
 
539
 
 
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));
 
544
 
 
545
        err = mobilesync_send(client, msg);
 
546
 
 
547
        if (err != MOBILESYNC_E_SUCCESS) {
 
548
                goto out;
 
549
        }
 
550
 
 
551
        plist_free(msg);
 
552
        msg = NULL;
 
553
 
 
554
        err = mobilesync_receive(client, &msg);
 
555
 
 
556
        if (err != MOBILESYNC_E_SUCCESS) {
 
557
                goto out;
 
558
        }
 
559
 
 
560
        response_type_node = plist_array_get_item(msg, 0);
 
561
        if (!response_type_node) {
 
562
                err = MOBILESYNC_E_PLIST_ERROR;
 
563
                goto out;
 
564
        }
 
565
 
 
566
        plist_get_string_val(response_type_node, &response_type);
 
567
        if (!response_type) {
 
568
                err = MOBILESYNC_E_PLIST_ERROR;
 
569
                goto out;
 
570
        }
 
571
 
 
572
        if (!strcmp(response_type, "SDMessageCancelSession")) {
 
573
                char *reason = NULL;
 
574
                err = MOBILESYNC_E_CANCELLED;
 
575
                plist_get_string_val(plist_array_get_item(msg, 2), &reason);
 
576
                debug_info("Device cancelled: %s", reason);
 
577
                free(reason);
 
578
                goto out;
 
579
        }
 
580
 
 
581
        if (strcmp(response_type, "SDMessageDeviceWillClearAllRecords")) {
 
582
                err = MOBILESYNC_E_PLIST_ERROR;
 
583
        }
 
584
 
 
585
        out:
 
586
        if (response_type) {
 
587
                free(response_type);
 
588
                response_type = NULL;
 
589
        }
 
590
        if (msg) {
 
591
                plist_free(msg);
 
592
                msg = NULL;
 
593
        }
 
594
 
 
595
        return err;
 
596
}
 
597
 
 
598
/**
515
599
 * Acknowledges to the device that the changes have been merged on the computer
516
600
 *
517
601
 * @param client The mobilesync client
518
602
 *
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
521
605
 */
522
606
mobilesync_error_t mobilesync_acknowledge_changes_from_device(mobilesync_client_t client)
523
607
{
560
644
 *
561
645
 * @param client The mobilesync client
562
646
 *
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
 
653
 * session
 
654
 * @retval MOBILESYNC_E_NOT_READY if the device is not ready to start
 
655
 * receiving any changes
569
656
 */
570
657
mobilesync_error_t mobilesync_ready_to_send_changes_from_computer(mobilesync_client_t client)
571
658
{
622
709
        err = MOBILESYNC_E_SUCCESS;
623
710
 
624
711
        out:
 
712
        if (response_type) {
 
713
                free(response_type);
 
714
                response_type = NULL;
 
715
        }
625
716
        if (msg) {
626
717
                plist_free(msg);
627
718
                msg = NULL;
631
722
}
632
723
 
633
724
/**
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
635
726
 *
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
641
732
 *
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
645
737
 */
646
738
mobilesync_error_t mobilesync_send_changes(mobilesync_client_t client, plist_t entities, uint8_t is_last_record, plist_t actions)
647
739
{
677
769
 * @param client The mobilesync client
678
770
 * @param mapping A pointer to an array plist containing a dict of identifier remappings
679
771
 *
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
 
775
 * form
 
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
 
779
 * session
685
780
 */
686
781
mobilesync_error_t mobilesync_remap_identifiers(mobilesync_client_t client, plist_t *mapping)
687
782
{
753
848
}
754
849
 
755
850
/**
756
 
 * Cancells a running synchronization session with a device at any time.
 
851
 * Cancels a running synchronization session with a device at any time.
757
852
 *
758
853
 * @param client The mobilesync client
759
854
 * @param reason The reason to supply to the device for cancelling
760
855
 *
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
763
858
 */
764
859
mobilesync_error_t mobilesync_cancel(mobilesync_client_t client, const char* reason)
765
860
{
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.
796
891
 * 
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().
798
893
 */
799
894
mobilesync_anchors_t mobilesync_anchors_new(const char *device_anchor, const char *computer_anchor)
800
895
{
816
911
/**
817
912
 * Free memory used by anchors.
818
913
 *
819
 
 * @param anchors The anchors free.
 
914
 * @param anchors The anchors to free.
820
915
 */
821
916
void mobilesync_anchors_free(mobilesync_anchors_t anchors)
822
917
{
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.
856
951
 */
857
952
void mobilesync_actions_add(plist_t actions, ...)