LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain, const char *key, plist_t *value) { if (!client) return LOCKDOWN_E_INVALID_ARG; plist_t dict = NULL; lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; /* setup request plist */ dict = plist_new_dict(); plist_dict_add_label(dict, client->label); if (domain) { plist_dict_set_item(dict,"Domain", plist_new_string(domain)); } if (key) { plist_dict_set_item(dict,"Key", plist_new_string(key)); } plist_dict_set_item(dict,"Request", plist_new_string("GetValue")); /* send to device */ ret = lockdownd_send(client, dict); plist_free(dict); dict = NULL; if (ret != LOCKDOWN_E_SUCCESS) return ret; /* Now get device's answer */ ret = lockdownd_receive(client, &dict); if (ret != LOCKDOWN_E_SUCCESS) return ret; ret = lockdown_check_result(dict, "GetValue"); if (ret == LOCKDOWN_E_SUCCESS) { debug_info("success"); } if (ret != LOCKDOWN_E_SUCCESS) { plist_free(dict); return ret; } plist_t value_node = plist_dict_get_item(dict, "Value"); if (value_node) { debug_info("has a value"); *value = plist_copy(value_node); } plist_free(dict); return ret; }
LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_stop_session(lockdownd_client_t client, const char *session_id) { if (!client) return LOCKDOWN_E_INVALID_ARG; if (!session_id) { debug_info("no session_id given, cannot stop session"); return LOCKDOWN_E_INVALID_ARG; } lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; plist_t dict = plist_new_dict(); plist_dict_add_label(dict, client->label); plist_dict_set_item(dict,"Request", plist_new_string("StopSession")); plist_dict_set_item(dict,"SessionID", plist_new_string(session_id)); debug_info("stopping session %s", session_id); ret = lockdownd_send(client, dict); plist_free(dict); dict = NULL; ret = lockdownd_receive(client, &dict); if (!dict) { debug_info("LOCKDOWN_E_PLIST_ERROR"); return LOCKDOWN_E_PLIST_ERROR; } ret = LOCKDOWN_E_UNKNOWN_ERROR; if (lockdown_check_result(dict, "StopSession") == RESULT_SUCCESS) { debug_info("success"); ret = LOCKDOWN_E_SUCCESS; } plist_free(dict); dict = NULL; if (client->session_id) { free(client->session_id); client->session_id = NULL; } if (client->ssl_enabled) { property_list_service_disable_ssl(client->parent); client->ssl_enabled = 0; } return ret; }
LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_activate(lockdownd_client_t client, plist_t activation_record) { if (!client) return LOCKDOWN_E_INVALID_ARG; if (!client->session_id) return LOCKDOWN_E_NO_RUNNING_SESSION; if (!activation_record) return LOCKDOWN_E_INVALID_ARG; lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; plist_t dict = plist_new_dict(); plist_dict_add_label(dict, client->label); plist_dict_set_item(dict,"Request", plist_new_string("Activate")); plist_dict_set_item(dict,"ActivationRecord", plist_copy(activation_record)); ret = lockdownd_send(client, dict); plist_free(dict); dict = NULL; ret = lockdownd_receive(client, &dict); if (!dict) { debug_info("LOCKDOWN_E_PLIST_ERROR"); return LOCKDOWN_E_PLIST_ERROR; } ret = LOCKDOWN_E_ACTIVATION_FAILED; if (lockdown_check_result(dict, "Activate") == RESULT_SUCCESS) { debug_info("success"); ret = LOCKDOWN_E_SUCCESS; } else { plist_t error_node = plist_dict_get_item(dict, "Error"); if (error_node && PLIST_STRING == plist_get_node_type(error_node)) { char *error = NULL; plist_get_string_val(error_node, &error); if (!strcmp(error, "InvalidActivationRecord")) { ret = LOCKDOWN_E_INVALID_ACTIVATION_RECORD; } free(error); } } plist_free(dict); dict = NULL; return ret; }
/** * Sends a notification to the device's notification_proxy. * * @param client The client to send to * @param notification The notification message to send * * @return NP_E_SUCCESS on success, or an error returned by np_plist_send */ np_error_t np_post_notification(np_client_t client, const char *notification) { if (!client || !notification) { return NP_E_INVALID_ARG; } np_lock(client); plist_t dict = plist_new_dict(); plist_dict_set_item(dict,"Command", plist_new_string("PostNotification")); plist_dict_set_item(dict,"Name", plist_new_string(notification)); np_error_t res = np_error(property_list_service_send_xml_plist(client->parent, dict)); plist_free(dict); dict = plist_new_dict(); plist_dict_set_item(dict,"Command", plist_new_string("Shutdown")); res = np_error(property_list_service_send_xml_plist(client->parent, dict)); plist_free(dict); if (res != NP_E_SUCCESS) { debug_info("Error sending XML plist to device!"); } // try to read an answer, we just ignore errors here dict = NULL; property_list_service_receive_plist(client->parent, &dict); if (dict) { #ifndef STRIP_DEBUG_CODE char *cmd_value = NULL; plist_t cmd_value_node = plist_dict_get_item(dict, "Command"); if (plist_get_node_type(cmd_value_node) == PLIST_STRING) { plist_get_string_val(cmd_value_node, &cmd_value); } if (cmd_value && !strcmp(cmd_value, "ProxyDeath")) { // this is the expected answer } else { debug_plist(dict); } if (cmd_value) { free(cmd_value); } #endif plist_free(dict); } np_unlock(client); return res; }
LIBIMOBILEDEVICE_API instproxy_error_t instproxy_lookup_archives(instproxy_client_t client, plist_t client_options, plist_t *result) { instproxy_error_t res = INSTPROXY_E_UNKNOWN_ERROR; plist_t command = plist_new_dict(); plist_dict_set_item(command, "Command", plist_new_string("LookupArchives")); if (client_options) plist_dict_set_item(command, "ClientOptions", plist_copy(client_options)); res = instproxy_perform_command(client, command, INSTPROXY_COMMAND_TYPE_SYNC, instproxy_copy_lookup_result_cb, (void*)result); plist_free(command); return res; }
/** * Returns a new plist from the supplied lockdownd pair record. The caller is * responsible for freeing the plist. * * @param pair_record The pair record to create a plist from. * * @return A pair record plist from the device, NULL if pair_record is not set */ static plist_t lockdownd_pair_record_to_plist(lockdownd_pair_record_t pair_record) { if (!pair_record) return NULL; /* setup request plist */ plist_t dict = plist_new_dict(); plist_dict_set_item(dict, "DeviceCertificate", plist_new_data(pair_record->device_certificate, strlen(pair_record->device_certificate))); plist_dict_set_item(dict, "HostCertificate", plist_new_data(pair_record->host_certificate, strlen(pair_record->host_certificate))); plist_dict_set_item(dict, "HostID", plist_new_string(pair_record->host_id)); plist_dict_set_item(dict, "RootCertificate", plist_new_data(pair_record->root_certificate, strlen(pair_record->root_certificate))); plist_dict_set_item(dict, "SystemBUID", plist_new_string(pair_record->system_buid)); return dict; }
LIBIMOBILEDEVICE_API diagnostics_relay_error_t diagnostics_relay_sleep(diagnostics_relay_client_t client) { if (!client) return DIAGNOSTICS_RELAY_E_INVALID_ARG; diagnostics_relay_error_t ret = DIAGNOSTICS_RELAY_E_UNKNOWN_ERROR; plist_t dict = plist_new_dict(); plist_dict_set_item(dict,"Request", plist_new_string("Sleep")); ret = diagnostics_relay_send(client, dict); plist_free(dict); dict = NULL; ret = diagnostics_relay_receive(client, &dict); if (!dict) { return DIAGNOSTICS_RELAY_E_PLIST_ERROR; } int check = diagnostics_relay_check_result(dict); if (check == RESULT_SUCCESS) { ret = DIAGNOSTICS_RELAY_E_SUCCESS; } else if (check == RESULT_UNKNOWN_REQUEST) { ret = DIAGNOSTICS_RELAY_E_UNKNOWN_REQUEST; } else { ret = DIAGNOSTICS_RELAY_E_UNKNOWN_ERROR; } plist_free(dict); return ret; }
LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_enter_recovery(lockdownd_client_t client) { if (!client) return LOCKDOWN_E_INVALID_ARG; lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; plist_t dict = plist_new_dict(); plist_dict_add_label(dict, client->label); plist_dict_set_item(dict,"Request", plist_new_string("EnterRecovery")); debug_info("telling device to enter recovery mode"); ret = lockdownd_send(client, dict); plist_free(dict); dict = NULL; ret = lockdownd_receive(client, &dict); if (lockdown_check_result(dict, "EnterRecovery") == RESULT_SUCCESS) { debug_info("success"); ret = LOCKDOWN_E_SUCCESS; } plist_free(dict); dict = NULL; return ret; }
/** * Hangs up the connection to the mobile_image_mounter service. * This functions has to be called before freeing up a mobile_image_mounter * instance. If not, errors appear in the device's syslog. * * @param client The client to hang up * * @return MOBILE_IMAGE_MOUNTER_E_SUCCESS on success, * MOBILE_IMAGE_MOUNTER_E_INVALID_ARG if client is invalid, * or another error code otherwise. */ mobile_image_mounter_error_t mobile_image_mounter_hangup(mobile_image_mounter_client_t client) { if (!client) { return MOBILE_IMAGE_MOUNTER_E_INVALID_ARG; } mobile_image_mounter_lock(client); plist_t dict = plist_new_dict(); plist_dict_set_item(dict, "Command", plist_new_string("Hangup")); mobile_image_mounter_error_t res = mobile_image_mounter_error(property_list_service_send_xml_plist(client->parent, dict)); plist_free(dict); if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) { debug_info("%s: Error sending XML plist to device!", __func__); goto leave_unlock; } dict = NULL; res = mobile_image_mounter_error(property_list_service_receive_plist(client->parent, &dict)); if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) { debug_info("%s: Error receiving response from device!", __func__); } if (dict) { debug_plist(dict); plist_free(dict); } leave_unlock: mobile_image_mounter_unlock(client); return res; }
LIBIMOBILEDEVICE_API sbservices_error_t sbservices_get_home_screen_wallpaper_pngdata(sbservices_client_t client, char **pngdata, uint64_t *pngsize) { if (!client || !client->parent || !pngdata) return SBSERVICES_E_INVALID_ARG; sbservices_error_t res = SBSERVICES_E_UNKNOWN_ERROR; plist_t dict = plist_new_dict(); plist_dict_set_item(dict, "command", plist_new_string("getHomeScreenWallpaperPNGData")); sbservices_lock(client); res = sbservices_error(property_list_service_send_binary_plist(client->parent, dict)); if (res != SBSERVICES_E_SUCCESS) { debug_info("could not send plist, error %d", res); goto leave_unlock; } plist_free(dict); dict = NULL; res = sbservices_error(property_list_service_receive_plist(client->parent, &dict)); if (res == SBSERVICES_E_SUCCESS) { plist_t node = plist_dict_get_item(dict, "pngData"); if (node) { plist_get_data_val(node, pngdata, pngsize); } } leave_unlock: if (dict) { plist_free(dict); } sbservices_unlock(client); return res; }
LIBIMOBILEDEVICE_API restored_error_t restored_goodbye(restored_client_t client) { if (!client) return RESTORE_E_INVALID_ARG; restored_error_t ret = RESTORE_E_UNKNOWN_ERROR; plist_t dict = plist_new_dict(); plist_dict_add_label(dict, client->label); plist_dict_set_item(dict,"Request", plist_new_string("Goodbye")); debug_info("called"); ret = restored_send(client, dict); plist_free(dict); dict = NULL; ret = restored_receive(client, &dict); if (!dict) { debug_info("did not get goodbye response back"); return RESTORE_E_PLIST_ERROR; } if (restored_check_result(dict) == RESULT_SUCCESS) { debug_info("success"); ret = RESTORE_E_SUCCESS; } plist_free(dict); dict = NULL; return ret; }
LIBIMOBILEDEVICE_API restored_error_t restored_reboot(restored_client_t client) { if (!client) return RESTORE_E_INVALID_ARG; plist_t dict = NULL; restored_error_t ret = RESTORE_E_UNKNOWN_ERROR; dict = plist_new_dict(); plist_dict_add_label(dict, client->label); plist_dict_set_item(dict,"Request", plist_new_string("Reboot")); /* send to device */ ret = restored_send(client, dict); plist_free(dict); dict = NULL; if (RESTORE_E_SUCCESS != ret) return ret; ret = restored_receive(client, &dict); if (RESTORE_E_SUCCESS != ret) return ret; if (!dict) return RESTORE_E_PLIST_ERROR; plist_free(dict); dict = NULL; return ret; }
static int send_result(struct mux_client *client, uint32_t tag, uint32_t result) { int res = -1; if (client->proto_version == 1) { /* XML plist packet */ plist_t dict = plist_new_dict(); plist_dict_set_item(dict, "MessageType", plist_new_string("Result")); plist_dict_set_item(dict, "Number", plist_new_uint(result)); res = send_plist_pkt(client, tag, dict); plist_free(dict); } else { /* binary packet */ res = send_pkt(client, tag, MESSAGE_RESULT, &result, sizeof(uint32_t)); } return res; }
LIBIMOBILEDEVICE_API instproxy_error_t instproxy_upgrade(instproxy_client_t client, const char *pkg_path, plist_t client_options, instproxy_status_cb_t status_cb, void *user_data) { instproxy_error_t res = INSTPROXY_E_UNKNOWN_ERROR; plist_t command = plist_new_dict(); plist_dict_set_item(command, "Command", plist_new_string("Upgrade")); if (client_options) plist_dict_set_item(command, "ClientOptions", plist_copy(client_options)); plist_dict_set_item(command, "PackagePath", plist_new_string(pkg_path)); res = instproxy_perform_command(client, command, INSTPROXY_COMMAND_TYPE_ASYNC, status_cb, user_data); plist_free(command); return res; }
/** * Adds a label key with the passed value to a plist dict node. * * @param plist The plist to add the key to * @param label The value for the label key * */ static void plist_dict_add_label(plist_t plist, const char *label) { if (plist && label) { if (plist_get_node_type(plist) == PLIST_DICT) plist_dict_set_item(plist, "Label", plist_new_string(label)); } }
/** * Sends a backup message plist. * * @param client The connected MobileBackup client to use. * @param message The message to send. This will be inserted into the request * plist as value for BackupMessageTypeKey. If this parameter is NULL, * the plist passed in the options parameter will be sent directly. * @param options Additional options as PLIST_DICT to add to the request. * The BackupMessageTypeKey with the value passed in the message parameter * will be inserted into this plist before sending it. This parameter * can be NULL if message is not NULL. */ static mobilebackup_error_t mobilebackup_send_message(mobilebackup_client_t client, const char *message, plist_t options) { if (!client || !client->parent || (!message && !options)) return MOBILEBACKUP_E_INVALID_ARG; if (options && (plist_get_node_type(options) != PLIST_DICT)) { return MOBILEBACKUP_E_INVALID_ARG; } mobilebackup_error_t err; if (message) { plist_t dict = NULL; if (options) { dict = plist_copy(options); } else { dict = plist_new_dict(); } plist_dict_set_item(dict, "BackupMessageTypeKey", plist_new_string(message)); /* send it as DLMessageProcessMessage */ err = mobilebackup_error(device_link_service_send_process_message(client->parent, dict)); plist_free(dict); } else { err = mobilebackup_error(device_link_service_send_process_message(client->parent, options)); } if (err != MOBILEBACKUP_E_SUCCESS) { debug_info("ERROR: Could not send message '%s' (%d)!", message, err); } return err; }
static int notify_device_remove(struct mux_client *client, uint32_t device_id) { int res = -1; if (client->proto_version == 1) { /* XML plist packet */ plist_t dict = plist_new_dict(); plist_dict_set_item(dict, "MessageType", plist_new_string("Detached")); plist_dict_set_item(dict, "DeviceID", plist_new_uint(device_id)); res = send_plist_pkt(client, 0, dict); plist_free(dict); } else { /* binary packet */ res = send_pkt(client, 0, MESSAGE_DEVICE_REMOVE, &device_id, sizeof(uint32_t)); } return res; }
static int send_device_list(struct mux_client *client, uint32_t tag) { int res = -1; plist_t dict = plist_new_dict(); plist_t devices = plist_new_array(); struct device_info *devs = NULL; struct device_info *dev; int i; int count = device_get_list(0, &devs); dev = devs; for (i = 0; devs && i < count; i++) { plist_t device = create_device_attached_plist(dev++); if (device) { plist_array_append_item(devices, device); } } if (devs) free(devs); plist_dict_set_item(dict, "DeviceList", devices); res = send_plist_pkt(client, tag, dict); plist_free(dict); return res; }
LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_deactivate(lockdownd_client_t client) { if (!client) return LOCKDOWN_E_INVALID_ARG; if (!client->session_id) return LOCKDOWN_E_NO_RUNNING_SESSION; lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; plist_t dict = plist_new_dict(); plist_dict_add_label(dict, client->label); plist_dict_set_item(dict,"Request", plist_new_string("Deactivate")); ret = lockdownd_send(client, dict); plist_free(dict); dict = NULL; ret = lockdownd_receive(client, &dict); if (!dict) { debug_info("LOCKDOWN_E_PLIST_ERROR"); return LOCKDOWN_E_PLIST_ERROR; } ret = LOCKDOWN_E_UNKNOWN_ERROR; if (lockdown_check_result(dict, "Deactivate") == RESULT_SUCCESS) { debug_info("success"); ret = LOCKDOWN_E_SUCCESS; } plist_free(dict); dict = NULL; return ret; }
LIBIMOBILEDEVICE_API instproxy_error_t instproxy_remove_archive(instproxy_client_t client, const char *appid, plist_t client_options, instproxy_status_cb_t status_cb, void *user_data) { instproxy_error_t res = INSTPROXY_E_UNKNOWN_ERROR; plist_t command = plist_new_dict(); plist_dict_set_item(command, "Command", plist_new_string("RemoveArchive")); if (client_options) plist_dict_set_item(command, "ClientOptions", plist_copy(client_options)); plist_dict_set_item(command, "ApplicationIdentifier", plist_new_string(appid)); res = instproxy_perform_command(client, command, INSTPROXY_COMMAND_TYPE_ASYNC, status_cb, user_data); plist_free(command); return res; }
int tss_request_add_common_tags(plist_t request, plist_t parameters, plist_t overrides) { plist_t node = NULL; /* ApECID */ node = plist_dict_get_item(parameters, "ApECID"); if (!node || plist_get_node_type(node) != PLIST_UINT) { error("ERROR: Unable to find required ApECID in parameters\n"); return -1; } plist_dict_set_item(request, "ApECID", plist_copy(node)); node = NULL; /* UniqueBuildID */ node = plist_dict_get_item(parameters, "UniqueBuildID"); if (node) { plist_dict_set_item(request, "UniqueBuildID", plist_copy(node)); } node = NULL; /* ApChipID */ node = plist_dict_get_item(parameters, "ApChipID"); if (node) { plist_dict_set_item(request, "ApChipID", plist_copy(node)); } node = NULL; /* ApBoardID */ node = plist_dict_get_item(parameters, "ApBoardID"); if (node) { plist_dict_set_item(request, "ApBoardID", plist_copy(node)); } node = NULL; /* ApSecurityDomain */ node = plist_dict_get_item(parameters, "ApSecurityDomain"); if (node) { plist_dict_set_item(request, "ApSecurityDomain", plist_copy(node)); } node = NULL; /* apply overrides */ if (overrides) { plist_dict_merge(&request, overrides); } return 0; }
/** * Removes a preference node by domain and/or key name. * * @note: Use with caution as this could remove vital information on the device * * @param client An initialized lockdownd client. * @param domain The domain to query on or NULL for global domain * @param key The key name to remove or NULL remove all keys for the current domain * * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when client is NULL */ lockdownd_error_t lockdownd_remove_value(lockdownd_client_t client, const char *domain, const char *key) { if (!client) return LOCKDOWN_E_INVALID_ARG; plist_t dict = NULL; lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; /* setup request plist */ dict = plist_new_dict(); plist_dict_add_label(dict, client->label); if (domain) { plist_dict_set_item(dict,"Domain", plist_new_string(domain)); } if (key) { plist_dict_set_item(dict,"Key", plist_new_string(key)); } plist_dict_set_item(dict,"Request", plist_new_string("RemoveValue")); /* send to device */ ret = lockdownd_send(client, dict); plist_free(dict); dict = NULL; if (ret != LOCKDOWN_E_SUCCESS) return ret; /* Now get device's answer */ ret = lockdownd_receive(client, &dict); if (ret != LOCKDOWN_E_SUCCESS) return ret; if (lockdown_check_result(dict, "RemoveValue") == RESULT_SUCCESS) { debug_info("success"); ret = LOCKDOWN_E_SUCCESS; } if (ret != LOCKDOWN_E_SUCCESS) { plist_free(dict); return ret; } plist_free(dict); return ret; }
LIBIMOBILEDEVICE_API instproxy_error_t instproxy_lookup(instproxy_client_t client, const char** appids, plist_t client_options, plist_t *result) { instproxy_error_t res = INSTPROXY_E_UNKNOWN_ERROR; int i = 0; plist_t lookup_result = NULL; plist_t command = NULL; plist_t appid_array = NULL; plist_t node = NULL; if (!client || !client->parent || !result) return INSTPROXY_E_INVALID_ARG; command = plist_new_dict(); plist_dict_set_item(command, "Command", plist_new_string("Lookup")); if (client_options) { node = plist_copy(client_options); } else if (appids) { node = plist_new_dict(); } /* add bundle identifiers to client options */ if (appids) { appid_array = plist_new_array(); while (appids[i]) { plist_array_append_item(appid_array, plist_new_string(appids[i])); i++; } plist_dict_set_item(node, "BundleIDs", appid_array); } if (node) { plist_dict_set_item(command, "ClientOptions", node); } res = instproxy_perform_command(client, command, INSTPROXY_COMMAND_TYPE_SYNC, instproxy_copy_lookup_result_cb, (void*)&lookup_result); if (res == INSTPROXY_E_SUCCESS) { *result = lookup_result; } else { plist_free(lookup_result); } plist_free(command); return res; }
LIBIMOBILEDEVICE_API restored_error_t restored_query_type(restored_client_t client, char **type, uint64_t *version) { if (!client) return RESTORE_E_INVALID_ARG; restored_error_t ret = RESTORE_E_UNKNOWN_ERROR; plist_t dict = plist_new_dict(); plist_dict_add_label(dict, client->label); plist_dict_set_item(dict,"Request", plist_new_string("QueryType")); debug_info("called"); ret = restored_send(client, dict); plist_free(dict); dict = NULL; ret = restored_receive(client, &dict); if (RESTORE_E_SUCCESS != ret) return ret; ret = RESTORE_E_UNKNOWN_ERROR; plist_t type_node = plist_dict_get_item(dict, "Type"); if (type_node && (plist_get_node_type(type_node) == PLIST_STRING)) { char* typestr = NULL; /* save our device information info */ client->info = dict; plist_get_string_val(type_node, &typestr); debug_info("success with type %s", typestr); /* return the type if requested */ if (type) { *type = typestr; } else { free(typestr); } /* fetch the restore protocol version */ if (version) { plist_t version_node = plist_dict_get_item(dict, "RestoreProtocolVersion"); if (version_node && PLIST_UINT == plist_get_node_type(version_node)) { plist_get_uint_val(version_node, version); debug_info("restored protocol version %llu", *version); } else { return RESTORE_E_UNKNOWN_ERROR; } } ret = RESTORE_E_SUCCESS; } else { debug_info("hmm. QueryType response does not contain a type?!"); debug_plist(dict); plist_free(dict); } return ret; }
static mobileactivation_error_t mobileactivation_send_command(mobileactivation_client_t client, const char* command, plist_t value, plist_t *result) { if (!client || !command || !result) return MOBILEACTIVATION_E_INVALID_ARG; mobileactivation_error_t ret = MOBILEACTIVATION_E_UNKNOWN_ERROR; *result = NULL; plist_t dict = plist_new_dict(); plist_dict_set_item(dict, "Command", plist_new_string(command)); if (value) { plist_dict_set_item(dict, "Value", plist_copy(value)); } ret = mobileactivation_send_command_plist(client, dict, result); plist_free(dict); return ret; }
LIBIMOBILEDEVICE_API instproxy_error_t instproxy_browse_with_callback(instproxy_client_t client, plist_t client_options, instproxy_status_cb_t status_cb, void *user_data) { if (!client || !client->parent || !status_cb) return INSTPROXY_E_INVALID_ARG; instproxy_error_t res = INSTPROXY_E_UNKNOWN_ERROR; plist_t command = plist_new_dict(); plist_dict_set_item(command, "Command", plist_new_string("Browse")); if (client_options) plist_dict_set_item(command, "ClientOptions", plist_copy(client_options)); res = instproxy_perform_command(client, command, INSTPROXY_COMMAND_TYPE_ASYNC, status_cb, (void*)user_data); plist_free(command); return res; }
LIBIMOBILEDEVICE_API mobilebackup2_error_t mobilebackup2_version_exchange(mobilebackup2_client_t client, double local_versions[], char count, double *remote_version) { int i; if (!client || !client->parent) return MOBILEBACKUP2_E_INVALID_ARG; plist_t dict = plist_new_dict(); plist_t array = plist_new_array(); for (i = 0; i < count; i++) { plist_array_append_item(array, plist_new_real(local_versions[i])); } plist_dict_set_item(dict, "SupportedProtocolVersions", array); mobilebackup2_error_t err = mobilebackup2_send_message(client, "Hello", dict); plist_free(dict); if (err != MOBILEBACKUP2_E_SUCCESS) goto leave; dict = NULL; err = internal_mobilebackup2_receive_message(client, "Response", &dict); if (err != MOBILEBACKUP2_E_SUCCESS) goto leave; /* check if we received an error */ plist_t node = plist_dict_get_item(dict, "ErrorCode"); if (!node || (plist_get_node_type(node) != PLIST_UINT)) { err = MOBILEBACKUP2_E_PLIST_ERROR; goto leave; } uint64_t val = 0; plist_get_uint_val(node, &val); if (val != 0) { if (val == 1) { err = MOBILEBACKUP2_E_NO_COMMON_VERSION; } else { err = MOBILEBACKUP2_E_REPLY_NOT_OK; } goto leave; } /* retrieve the protocol version of the device */ node = plist_dict_get_item(dict, "ProtocolVersion"); if (!node || (plist_get_node_type(node) != PLIST_REAL)) { err = MOBILEBACKUP2_E_PLIST_ERROR; goto leave; } *remote_version = 0.0; plist_get_real_val(node, remote_version); leave: if (dict) plist_free(dict); return err; }
LIBIMOBILEDEVICE_API diagnostics_relay_error_t diagnostics_relay_query_ioregistry_entry(diagnostics_relay_client_t client, const char* name, const char* _class, plist_t* result) { if (!client || (name == NULL && _class == NULL) || result == NULL) return DIAGNOSTICS_RELAY_E_INVALID_ARG; diagnostics_relay_error_t ret = DIAGNOSTICS_RELAY_E_UNKNOWN_ERROR; plist_t dict = plist_new_dict(); if (name) plist_dict_set_item(dict,"EntryName", plist_new_string(name)); if (_class) plist_dict_set_item(dict,"EntryClass", plist_new_string(_class)); plist_dict_set_item(dict,"Request", plist_new_string("IORegistry")); ret = diagnostics_relay_send(client, dict); plist_free(dict); dict = NULL; ret = diagnostics_relay_receive(client, &dict); if (!dict) { return DIAGNOSTICS_RELAY_E_PLIST_ERROR; } int check = diagnostics_relay_check_result(dict); if (check == RESULT_SUCCESS) { ret = DIAGNOSTICS_RELAY_E_SUCCESS; } else if (check == RESULT_UNKNOWN_REQUEST) { ret = DIAGNOSTICS_RELAY_E_UNKNOWN_REQUEST; } else { ret = DIAGNOSTICS_RELAY_E_UNKNOWN_ERROR; } if (ret != DIAGNOSTICS_RELAY_E_SUCCESS) { plist_free(dict); return ret; } plist_t value_node = plist_dict_get_item(dict, "Diagnostics"); if (value_node) { *result = plist_copy(value_node); } plist_free(dict); return ret; }
static plist_t create_device_attached_plist(struct device_info *dev) { plist_t dict = plist_new_dict(); plist_dict_set_item(dict, "MessageType", plist_new_string("Attached")); plist_dict_set_item(dict, "DeviceID", plist_new_uint(dev->id)); plist_t props = plist_new_dict(); plist_dict_set_item(props, "ConnectionSpeed", plist_new_uint(dev->speed)); plist_dict_set_item(props, "ConnectionType", plist_new_string("USB")); plist_dict_set_item(props, "DeviceID", plist_new_uint(dev->id)); plist_dict_set_item(props, "LocationID", plist_new_uint(dev->location)); plist_dict_set_item(props, "ProductID", plist_new_uint(dev->pid)); plist_dict_set_item(props, "SerialNumber", plist_new_string(dev->serial)); plist_dict_set_item(dict, "Properties", props); return dict; }
/** * Send a command to the connected house_arrest service. * Calls house_arrest_send_request() internally. * * @param client The house_arrest client to use. * @param command The command to send. Currently, only VendContainer and * VendDocuments are known. * @param appid The application identifier to pass along with the . * * @note If this function returns HOUSE_ARREST_E_SUCCESS it does not mean * that the command was successful. To check for success or failure you * need to call house_arrest_get_result(). * @see house_arrest_get_result * * @return HOUSE_ARREST_E_SUCCESS if the command was successfully sent, * HOUSE_ARREST_E_INVALID_ARG if client, command, or appid is invalid, * HOUSE_ARREST_E_INVALID_MODE if the client is not in the correct mode, * or HOUSE_ARREST_E_CONN_FAILED if a connection error occured. */ house_arrest_error_t house_arrest_send_command(house_arrest_client_t client, const char *command, const char *appid) { if (!client || !client->parent || !command || !appid) return HOUSE_ARREST_E_INVALID_ARG; if (client->mode != HOUSE_ARREST_CLIENT_MODE_NORMAL) return HOUSE_ARREST_E_INVALID_MODE; house_arrest_error_t res = HOUSE_ARREST_E_UNKNOWN_ERROR; plist_t dict = plist_new_dict(); plist_dict_set_item(dict, "Command", plist_new_string(command)); plist_dict_set_item(dict, "Identifier", plist_new_string(appid)); res = house_arrest_send_request(client, dict); plist_free(dict); return res; }