@@ -134,7 +134,7 @@ int start_session(std::string& device_identifier)
134
134
{
135
135
const DeviceInfo* device_info = devices[device_identifier].device_info ;
136
136
UNLOCK_MUTEX_AND_RETURN_IF_FAILED_RESULT (AMDeviceConnect (device_info), start_session_mutex);
137
- assert (AMDeviceIsPaired (device_info));
137
+ assert (AMDeviceIsPaired (device_info));
138
138
UNLOCK_MUTEX_AND_RETURN_IF_FAILED_RESULT (AMDeviceValidatePairing (device_info), start_session_mutex);
139
139
UNLOCK_MUTEX_AND_RETURN_IF_FAILED_RESULT (AMDeviceStartSession (device_info), start_session_mutex);
140
140
}
@@ -371,55 +371,55 @@ std::mutex start_service_mutex;
371
371
372
372
ServiceInfo start_secure_service (std::string device_identifier, const char * service_name, std::string method_id, bool should_log_error, bool skip_cache)
373
373
{
374
- start_service_mutex.lock ();
374
+ start_service_mutex.lock ();
375
375
ServiceInfo serviceInfoResult = {};
376
- if (!devices.count (device_identifier))
377
- {
378
- if (should_log_error)
379
- print_error (" Device not found" , device_identifier, method_id, kAMDNotFoundError );
380
-
381
- start_service_mutex.unlock ();
382
- return serviceInfoResult;
383
- }
384
-
385
- if (!skip_cache && devices[device_identifier].services .count (service_name))
386
- {
387
- start_service_mutex.unlock ();
388
- return devices[device_identifier].services [service_name];
389
- }
390
-
391
- PRINT_ERROR_AND_RETURN_VALUE_IF_FAILED_RESULT (start_session (device_identifier), " Could not start device session" , device_identifier, method_id, serviceInfoResult);
392
- CFStringRef cf_service_name = create_CFString (service_name);
393
-
394
- ServiceConnRef connection;
395
- unsigned result = AMDeviceSecureStartService (devices[device_identifier].device_info , cf_service_name, NULL , &connection);
396
- service_conn_t socket = (void *)AMDServiceConnectionGetSocket (connection);
397
-
398
- stop_session (device_identifier);
399
- CFRelease (cf_service_name);
400
- if (result)
401
- {
402
- std::string message (" Could not start service " );
403
- message += service_name;
404
- if (should_log_error)
405
- print_error (message.c_str (), device_identifier, method_id, result);
406
-
407
- start_service_mutex.unlock ();
408
- return serviceInfoResult;
409
- }
410
-
411
- serviceInfoResult.socket = socket;
412
- serviceInfoResult.connection = connection;
413
- serviceInfoResult.connection_id = nextServiceConnectionId;
414
- serviceConnections[nextServiceConnectionId] = connection;
415
- nextServiceConnectionId++;
416
-
417
- if (!skip_cache) {
418
- devices[device_identifier].services [service_name] = serviceInfoResult;
419
- }
420
-
421
- start_service_mutex.unlock ();
422
- return serviceInfoResult;
376
+ if (!devices.count (device_identifier))
377
+ {
378
+ if (should_log_error)
379
+ print_error (" Device not found" , device_identifier, method_id, kAMDNotFoundError );
380
+
381
+ start_service_mutex.unlock ();
382
+ return serviceInfoResult;
383
+ }
384
+
385
+ if (!skip_cache && devices[device_identifier].services .count (service_name))
386
+ {
387
+ start_service_mutex.unlock ();
388
+ return devices[device_identifier].services [service_name];
389
+ }
390
+
391
+ PRINT_ERROR_AND_RETURN_VALUE_IF_FAILED_RESULT (start_session (device_identifier), " Could not start device session" , device_identifier, method_id, serviceInfoResult);
392
+ CFStringRef cf_service_name = create_CFString (service_name);
393
+
394
+ ServiceConnRef connection;
395
+ unsigned result = AMDeviceSecureStartService (devices[device_identifier].device_info , cf_service_name, NULL , &connection);
396
+ service_conn_t socket = (void *)AMDServiceConnectionGetSocket (connection);
397
+
398
+ stop_session (device_identifier);
399
+ CFRelease (cf_service_name);
400
+ if (result)
401
+ {
402
+ std::string message (" Could not start service " );
403
+ message += service_name;
404
+ if (should_log_error)
405
+ print_error (message.c_str (), device_identifier, method_id, result);
406
+
407
+ start_service_mutex.unlock ();
408
+ return serviceInfoResult;
409
+ }
410
+
411
+ serviceInfoResult.socket = socket;
412
+ serviceInfoResult.connection = connection;
413
+ serviceInfoResult.connection_id = nextServiceConnectionId;
414
+ serviceConnections[nextServiceConnectionId] = connection;
415
+ nextServiceConnectionId++;
416
+
417
+ if (!skip_cache) {
418
+ devices[device_identifier].services [service_name] = serviceInfoResult;
419
+ }
420
+
421
+ start_service_mutex.unlock ();
422
+ return serviceInfoResult;
423
423
}
424
424
425
425
@@ -431,19 +431,19 @@ AFCConnectionRef start_house_arrest(std::string device_identifier, const char* a
431
431
return NULL ;
432
432
}
433
433
434
- AFCConnectionRef persistedHouseArrestService = devices[device_identifier].apps_cache [application_identifier].afc_connection ;
434
+ AFCConnectionRef persistedHouseArrestService = devices[device_identifier].apps_cache [application_identifier].afc_connection ;
435
435
if (persistedHouseArrestService)
436
436
{
437
- return persistedHouseArrestService;
437
+ return persistedHouseArrestService;
438
438
}
439
439
440
440
AFCConnectionRef conn = NULL ;
441
441
start_session (device_identifier);
442
442
CFStringRef cf_application_identifier = create_CFString (application_identifier);
443
- unsigned result = AMDeviceCreateHouseArrestService (devices[device_identifier].device_info , cf_application_identifier, 0 , &conn);
444
-
443
+ unsigned result = AMDeviceCreateHouseArrestService (devices[device_identifier].device_info , cf_application_identifier, 0 , &conn);
444
+
445
445
stop_session (device_identifier);
446
- CFRelease (cf_application_identifier);
446
+ CFRelease (cf_application_identifier);
447
447
448
448
if (result)
449
449
{
@@ -454,7 +454,7 @@ AFCConnectionRef start_house_arrest(std::string device_identifier, const char* a
454
454
}
455
455
456
456
devices[device_identifier].apps_cache [application_identifier].afc_connection = conn;
457
-
457
+
458
458
return conn;
459
459
}
460
460
@@ -479,7 +479,7 @@ AFCConnectionRef get_afc_connection(std::string& device_identifier, const char*
479
479
return devices[device_identifier].apps_cache [application_identifier].afc_connection ;
480
480
}
481
481
482
-
482
+
483
483
AFCConnectionRef con_ref = start_house_arrest (device_identifier, application_identifier, method_id);
484
484
if (!con_ref)
485
485
{
@@ -931,40 +931,40 @@ void get_application_infos(std::string device_identifier, std::string method_id)
931
931
{
932
932
return ;
933
933
}
934
-
935
- CFStringRef cf_bundle_id_key = create_CFString (" CFBundleIdentifier" );
936
- CFStringRef cf_config_key = create_CFString (" configuration" );
937
- const void * cf_return_attributes[] = { cf_bundle_id_key, cf_config_key };
938
- const CFArrayRef cf_return_attributes_array = CFArrayCreate (NULL , cf_return_attributes, 2 , NULL );
939
-
940
- CFStringRef cf_app_type_key = create_CFString (" ApplicationType" );
941
- CFStringRef cf_return_attrs_key = create_CFString (" ReturnAttributes" );
942
- const void *client_opts_keys_arr[] = { cf_app_type_key, cf_return_attrs_key };
943
-
944
-
945
- CFStringRef cf_user_value = create_CFString (" User" );
946
- const void *client_opts_values_arr[] = { cf_user_value, cf_return_attributes_array };
947
- CFDictionaryRef clinet_opts_dict = CFDictionaryCreate (NULL , client_opts_keys_arr, client_opts_values_arr, 2 , NULL , NULL );
948
-
949
- CFStringRef cf_command_key = create_CFString (" Command" );
950
- CFStringRef cf_client_options_key = create_CFString (" ClientOptions" );
951
- const void *keys_arr[] = { cf_command_key, cf_client_options_key };
952
- CFStringRef cf_browse_value = create_CFString (" Browse" );
953
- const void *values_arr[] = { cf_browse_value, clinet_opts_dict };
954
- CFDictionaryRef dict_command = CFDictionaryCreate (NULL , keys_arr, values_arr, 2 , NULL , NULL );
934
+
935
+ CFStringRef cf_bundle_id_key = create_CFString (" CFBundleIdentifier" );
936
+ CFStringRef cf_config_key = create_CFString (" configuration" );
937
+ const void * cf_return_attributes[] = { cf_bundle_id_key, cf_config_key };
938
+ const CFArrayRef cf_return_attributes_array = CFArrayCreate (NULL , cf_return_attributes, 2 , NULL );
939
+
940
+ CFStringRef cf_app_type_key = create_CFString (" ApplicationType" );
941
+ CFStringRef cf_return_attrs_key = create_CFString (" ReturnAttributes" );
942
+ const void *client_opts_keys_arr[] = { cf_app_type_key, cf_return_attrs_key };
943
+
944
+
945
+ CFStringRef cf_user_value = create_CFString (" User" );
946
+ const void *client_opts_values_arr[] = { cf_user_value, cf_return_attributes_array };
947
+ CFDictionaryRef clinet_opts_dict = CFDictionaryCreate (NULL , client_opts_keys_arr, client_opts_values_arr, 2 , NULL , NULL );
948
+
949
+ CFStringRef cf_command_key = create_CFString (" Command" );
950
+ CFStringRef cf_client_options_key = create_CFString (" ClientOptions" );
951
+ const void *keys_arr[] = { cf_command_key, cf_client_options_key };
952
+ CFStringRef cf_browse_value = create_CFString (" Browse" );
953
+ const void *values_arr[] = { cf_browse_value, clinet_opts_dict };
954
+ CFDictionaryRef dict_command = CFDictionaryCreate (NULL , keys_arr, values_arr, 2 , NULL , NULL );
955
955
956
956
send_con_message (serviceInfo.connection , dict_command);
957
- CFRelease (cf_bundle_id_key);
958
- CFRelease (cf_config_key);
959
- CFRelease (cf_return_attributes_array);
960
- CFRelease (cf_app_type_key);
961
- CFRelease (cf_return_attrs_key);
962
- CFRelease (cf_user_value);
963
- CFRelease (clinet_opts_dict);
964
- CFRelease (cf_command_key);
965
- CFRelease (cf_client_options_key);
966
- CFRelease (cf_browse_value);
967
- CFRelease (dict_command);
957
+ CFRelease (cf_bundle_id_key);
958
+ CFRelease (cf_config_key);
959
+ CFRelease (cf_return_attributes_array);
960
+ CFRelease (cf_app_type_key);
961
+ CFRelease (cf_return_attrs_key);
962
+ CFRelease (cf_user_value);
963
+ CFRelease (clinet_opts_dict);
964
+ CFRelease (cf_command_key);
965
+ CFRelease (cf_client_options_key);
966
+ CFRelease (cf_browse_value);
967
+ CFRelease (dict_command);
968
968
969
969
std::vector<json> livesync_app_infos;
970
970
while (true )
@@ -1092,10 +1092,10 @@ void device_log(std::string device_identifier, std::string method_id)
1092
1092
1093
1093
char *buffer = new char [kDeviceLogBytesToRead ];
1094
1094
int bytes_read;
1095
-
1096
- // inspired by: https://github.com/DerekSelander/mobdevim/blob/a457f119f1576b85e9f8f89be8713f018ee97f59/mobdevim/console.temp_caseinsensitive_rename.m#L27
1095
+
1096
+ // inspired by: https://github.com/DerekSelander/mobdevim/blob/a457f119f1576b85e9f8f89be8713f018ee97f59/mobdevim/console.temp_caseinsensitive_rename.m#L27
1097
1097
while ((bytes_read = AMDServiceConnectionReceive (serviceInfo.connection , buffer, kDeviceLogBytesToRead )) > 0 )
1098
- {
1098
+ {
1099
1099
json message;
1100
1100
message[kDeviceId ] = device_identifier;
1101
1101
message[kMessage ] = std::string (buffer, bytes_read);
@@ -1108,41 +1108,41 @@ void device_log(std::string device_identifier, std::string method_id)
1108
1108
1109
1109
void post_notification (std::string device_identifier, PostNotificationInfo post_notification_info, std::string method_id)
1110
1110
{
1111
- ServiceInfo info = start_secure_service (device_identifier, kNotificationProxy , method_id, true , true );
1111
+ ServiceInfo info = start_secure_service (device_identifier, kNotificationProxy , method_id, true , true );
1112
1112
if (!info.socket )
1113
1113
{
1114
1114
return ;
1115
1115
}
1116
-
1117
- CFStringRef cf_command_key = create_CFString (" Command" );
1118
- CFStringRef cf_command_value = create_CFString (post_notification_info.command_type .c_str ());
1119
- CFStringRef cf_name_key = create_CFString (" Name" );
1120
- CFStringRef cf_name_value = create_CFString (post_notification_info.notification_name .c_str ());
1121
- CFStringRef cf_client_options_key = create_CFString (" ClientOptions" );
1122
- CFStringRef cf_client_options_value = create_CFString (" " );
1123
- const void *keys_arr[] = { cf_command_key, cf_name_key, cf_client_options_key };
1124
- const void *values_arr[] = { cf_command_value, cf_name_value, cf_client_options_value };
1125
- CFDictionaryRef dict_command = CFDictionaryCreate (NULL , keys_arr, values_arr, 3 , NULL , NULL );
1126
-
1127
- send_con_message (info.connection , dict_command);
1128
- CFRelease (cf_command_key);
1129
- CFRelease (cf_command_value);
1130
- CFRelease (cf_name_key);
1131
- CFRelease (cf_name_value);
1132
- CFRelease (cf_client_options_key);
1133
- CFRelease (cf_client_options_value);
1134
- CFRelease (dict_command);
1135
-
1116
+
1117
+ CFStringRef cf_command_key = create_CFString (" Command" );
1118
+ CFStringRef cf_command_value = create_CFString (post_notification_info.command_type .c_str ());
1119
+ CFStringRef cf_name_key = create_CFString (" Name" );
1120
+ CFStringRef cf_name_value = create_CFString (post_notification_info.notification_name .c_str ());
1121
+ CFStringRef cf_client_options_key = create_CFString (" ClientOptions" );
1122
+ CFStringRef cf_client_options_value = create_CFString (" " );
1123
+ const void *keys_arr[] = { cf_command_key, cf_name_key, cf_client_options_key };
1124
+ const void *values_arr[] = { cf_command_value, cf_name_value, cf_client_options_value };
1125
+ CFDictionaryRef dict_command = CFDictionaryCreate (NULL , keys_arr, values_arr, 3 , NULL , NULL );
1126
+
1127
+ send_con_message (info.connection , dict_command);
1128
+ CFRelease (cf_command_key);
1129
+ CFRelease (cf_command_value);
1130
+ CFRelease (cf_name_key);
1131
+ CFRelease (cf_name_value);
1132
+ CFRelease (cf_client_options_key);
1133
+ CFRelease (cf_client_options_value);
1134
+ CFRelease (dict_command);
1135
+
1136
1136
print (json ({ { kResponse , info.connection_id }, { kId , method_id }, { kDeviceId , device_identifier } }));
1137
1137
}
1138
1138
1139
1139
void await_notification_response (std::string device_identifier, AwaitNotificationResponseInfo await_notification_response_info, std::string method_id)
1140
1140
{
1141
- ServiceConnRef connection = serviceConnections[(int )await_notification_response_info.socket ];
1142
- std::string invalid_connection_error_message = " Invalid connectionId: " + std::to_string (await_notification_response_info.socket );
1143
- PRINT_ERROR_AND_RETURN_IF_FAILED_RESULT (connection == nullptr , invalid_connection_error_message.c_str (), device_identifier, method_id);
1144
-
1145
- ServiceInfo currentNotificationProxy = devices[device_identifier].services [kNotificationProxy ];
1141
+ ServiceConnRef connection = serviceConnections[(int )await_notification_response_info.socket ];
1142
+ std::string invalid_connection_error_message = " Invalid connectionId: " + std::to_string (await_notification_response_info.socket );
1143
+ PRINT_ERROR_AND_RETURN_IF_FAILED_RESULT (connection == nullptr , invalid_connection_error_message.c_str (), device_identifier, method_id);
1144
+
1145
+ ServiceInfo currentNotificationProxy = devices[device_identifier].services [kNotificationProxy ];
1146
1146
std::map<std::string, boost::any> response = receive_con_message (connection);
1147
1147
if (response.size ())
1148
1148
{
0 commit comments