service_error_t service_client_new(idevice_t device, lockdownd_service_descriptor_t service, service_client_t *client) { if (!device || !service || service->port == 0 || !client || *client) return SERVICE_E_INVALID_ARG; /* Attempt connection */ idevice_connection_t connection = NULL; if (idevice_connect(device, service->port, &connection) != IDEVICE_E_SUCCESS) { return SERVICE_E_MUX_ERROR; } /* create client object */ service_client_t client_loc = (service_client_t)malloc(sizeof(struct service_client_private)); client_loc->connection = connection; /* enable SSL if requested */ if (service->ssl_enabled == 1) { service_error_t result = service_enable_ssl(client_loc); if (SERVICE_E_SUCCESS != result) { service_client_free(client_loc); return result; } } /* all done, return success */ *client = client_loc; return SERVICE_E_SUCCESS; }
debugserver_error_t debugserver_client_free(debugserver_client_t client) { if (!client) return DEBUGSERVER_E_INVALID_ARG; debugserver_error_t err = debugserver_error(service_client_free(client->parent)); client->parent = NULL; free(client); return err; }
LIBIMOBILEDEVICE_API property_list_service_error_t property_list_service_client_free(property_list_service_client_t client) { if (!client) return PROPERTY_LIST_SERVICE_E_INVALID_ARG; property_list_service_error_t err = service_to_property_list_service_error(service_client_free(client->parent)); free(client); client = NULL; return err; }
/** * Frees up an AFC client. If the connection was created by the * client itself, the connection will be closed. * * @param client The client to free. */ afc_error_t afc_client_free(afc_client_t client) { if (!client || !client->afc_packet) return AFC_E_INVALID_ARG; if (client->free_parent && client->parent) { service_client_free(client->parent); client->parent = NULL; } free(client->afc_packet); mutex_destroy(&client->mutex); free(client); return AFC_E_SUCCESS; }
LIBIMOBILEDEVICE_API syslog_relay_error_t syslog_relay_client_free(syslog_relay_client_t client) { if (!client) return SYSLOG_RELAY_E_INVALID_ARG; syslog_relay_error_t err = syslog_relay_error(service_client_free(client->parent)); client->parent = NULL; if (client->worker) { debug_info("Joining syslog capture callback worker thread"); thread_join(client->worker); } free(client); return err; }
/** * Frees up an AFC client. If the connection was created by the * client itself, the connection will be closed. * * @param client The client to free. */ afc_error_t afc_client_free(afc_client_t client) { if (!client || !client->afc_packet) return AFC_E_INVALID_ARG; if (client->free_parent && client->parent) { service_client_free(client->parent); client->parent = NULL; } free(client->afc_packet); #ifdef WIN32 DeleteCriticalSection(&client->mutex); #else pthread_mutex_destroy(&client->mutex); #endif free(client); return AFC_E_SUCCESS; }
/** * Makes a connection to the AFC service on the device. * * @param device The device to connect to. * @param service The service descriptor returned by lockdownd_start_service. * @param client Pointer that will be set to a newly allocated afc_client_t * upon successful return. * * @return AFC_E_SUCCESS on success, AFC_E_INVALID_ARG if device or port is * invalid, AFC_E_MUX_ERROR if the connection cannot be established, * or AFC_E_NO_MEM if there is a memory allocation problem. */ afc_error_t afc_client_new(idevice_t device, lockdownd_service_descriptor_t service, afc_client_t * client) { if (!device || service->port == 0) return AFC_E_INVALID_ARG; service_client_t parent = NULL; if (service_client_new(device, service, &parent) != SERVICE_E_SUCCESS) { return AFC_E_MUX_ERROR; } afc_error_t err = afc_client_new_with_service_client(parent, client); if (err != AFC_E_SUCCESS) { service_client_free(parent); } else { (*client)->free_parent = 1; } return err; }