From 542ef4711ff6f321014e2465264159245e5f3c51 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Mon, 8 Jun 2020 00:43:36 +0200 Subject: Rename "compproxy" names to "companion_proxy" in all related code This now matches how other services are named as we try to use the lockdownd provided name or otherwise a more readable one even if it is longer. --- include/libimobiledevice/companion_proxy.h | 152 ++++++++++++------------ src/companion_proxy.c | 182 ++++++++++++++--------------- src/companion_proxy.h | 2 +- 3 files changed, 168 insertions(+), 168 deletions(-) diff --git a/include/libimobiledevice/companion_proxy.h b/include/libimobiledevice/companion_proxy.h index aaf7661..19c88eb 100644 --- a/include/libimobiledevice/companion_proxy.h +++ b/include/libimobiledevice/companion_proxy.h @@ -30,109 +30,109 @@ extern "C" { #include #include -#define COMPPROXY_SERVICE_NAME "com.apple.companion_proxy" +#define COMPANION_PROXY_SERVICE_NAME "com.apple.companion_proxy" /** Error Codes */ typedef enum { - COMPPROXY_E_SUCCESS = 0, - COMPPROXY_E_INVALID_ARG = -1, - COMPPROXY_E_PLIST_ERROR = -2, - COMPPROXY_E_MUX_ERROR = -3, - COMPPROXY_E_SSL_ERROR = -4, - COMPPROXY_E_NOT_ENOUGH_DATA = -5, - COMPPROXY_E_TIMEOUT = -6, - COMPPROXY_E_OP_IN_PROGRESS = -7, - COMPPROXY_E_NO_DEVICES = -100, - COMPPROXY_E_UNSUPPORTED_KEY = -101, - COMPPROXY_E_TIMEOUT_REPLY = -102, - COMPPROXY_E_UNKNOWN_ERROR = -256 -} compproxy_error_t; - -typedef struct compproxy_client_private compproxy_client_private; -typedef compproxy_client_private *compproxy_client_t; /**< The client handle. */ - -typedef void (*compproxy_device_event_cb_t) (plist_t event, void* userdata); + COMPANION_PROXY_E_SUCCESS = 0, + COMPANION_PROXY_E_INVALID_ARG = -1, + COMPANION_PROXY_E_PLIST_ERROR = -2, + COMPANION_PROXY_E_MUX_ERROR = -3, + COMPANION_PROXY_E_SSL_ERROR = -4, + COMPANION_PROXY_E_NOT_ENOUGH_DATA = -5, + COMPANION_PROXY_E_TIMEOUT = -6, + COMPANION_PROXY_E_OP_IN_PROGRESS = -7, + COMPANION_PROXY_E_NO_DEVICES = -100, + COMPANION_PROXY_E_UNSUPPORTED_KEY = -101, + COMPANION_PROXY_E_TIMEOUT_REPLY = -102, + COMPANION_PROXY_E_UNKNOWN_ERROR = -256 +} companion_proxy_error_t; + +typedef struct companion_proxy_client_private companion_proxy_client_private; +typedef companion_proxy_client_private *companion_proxy_client_t; /**< The client handle. */ + +typedef void (*companion_proxy_device_event_cb_t) (plist_t event, void* userdata); /** - * Connects to the compproxy service on the specified device. + * Connects to the companion_proxy service on the specified device. * * @param device The device to connect to. * @param service The service descriptor returned by lockdownd_start_service. * @param client Pointer that will point to a newly allocated - * compproxy_client_t upon successful return. Must be freed using - * compproxy_client_free() after use. + * companion_proxy_client_t upon successful return. Must be freed using + * companion_proxy_client_free() after use. * - * @return COMPPROXY_E_SUCCESS on success, COMPPROXY_E_INVALID_ARG when - * the arguments are invalid, or an COMPPROXY_E_* error code otherwise. + * @return COMPANION_PROXY_E_SUCCESS on success, COMPANION_PROXY_E_INVALID_ARG when + * the arguments are invalid, or an COMPANION_PROXY_E_* error code otherwise. */ -compproxy_error_t compproxy_client_new(idevice_t device, lockdownd_service_descriptor_t service, compproxy_client_t* client); +companion_proxy_error_t companion_proxy_client_new(idevice_t device, lockdownd_service_descriptor_t service, companion_proxy_client_t* client); /** - * Starts a new compproxy service on the specified device and connects to it. + * Starts a new companion_proxy service on the specified device and connects to it. * * @param device The device to connect to. * @param client Pointer that will point to a newly allocated - * compproxy_client_t upon successful return. Must be freed using - * compproxy_client_free() after use. + * companion_proxy_client_t upon successful return. Must be freed using + * companion_proxy_client_free() after use. * @param label The label to use for communication. Usually the program name. * Pass NULL to disable sending the label in requests to lockdownd. * - * @return COMPPROXY_E_SUCCESS on success, or an COMPPROXY_E_* error + * @return COMPANION_PROXY_E_SUCCESS on success, or an COMPANION_PROXY_E_* error * code otherwise. */ -compproxy_error_t compproxy_client_start_service(idevice_t device, compproxy_client_t* client, const char* label); +companion_proxy_error_t companion_proxy_client_start_service(idevice_t device, companion_proxy_client_t* client, const char* label); /** - * Disconnects a compproxy client from the device and frees up the - * compproxy client data. + * Disconnects a companion_proxy client from the device and frees up the + * companion_proxy client data. * - * @param client The compproxy client to disconnect and free. + * @param client The companion_proxy client to disconnect and free. * - * @return COMPPROXY_E_SUCCESS on success, COMPPROXY_E_INVALID_ARG when - * client is NULL, or an COMPPROXY_E_* error code otherwise. + * @return COMPANION_PROXY_E_SUCCESS on success, COMPANION_PROXY_E_INVALID_ARG when + * client is NULL, or an COMPANION_PROXY_E_* error code otherwise. */ -compproxy_error_t compproxy_client_free(compproxy_client_t client); +companion_proxy_error_t companion_proxy_client_free(companion_proxy_client_t client); /** * Sends a plist to the service. * - * @param client The compproxy client + * @param client The companion_proxy client * @param plist The plist to send * - * @return COMPPROXY_E_SUCCESS on success, - * COMPPROXY_E_INVALID_ARG when client or plist is NULL + * @return COMPANION_PROXY_E_SUCCESS on success, + * COMPANION_PROXY_E_INVALID_ARG when client or plist is NULL */ -compproxy_error_t compproxy_send(compproxy_client_t client, plist_t plist); +companion_proxy_error_t companion_proxy_send(companion_proxy_client_t client, plist_t plist); /** * Receives a plist from the service. * - * @param client The compproxy client + * @param client The companion_proxy client * @param plist The plist to store the received data * - * @return COMPPROXY_E_SUCCESS on success, - * COMPPROXY_E_INVALID_ARG when client or plist is NULL + * @return COMPANION_PROXY_E_SUCCESS on success, + * COMPANION_PROXY_E_INVALID_ARG when client or plist is NULL */ -compproxy_error_t compproxy_receive(compproxy_client_t client, plist_t * plist); +companion_proxy_error_t companion_proxy_receive(companion_proxy_client_t client, plist_t * plist); /** * Retrieves a list of paired devices. * - * @param client The compproxy client + * @param client The companion_proxy client * @param devices Point that will receive a PLIST_ARRAY with paired device UDIDs * * @note The device closes the connection after sending the reply. * - * @return COMPPROXY_E_SUCCESS on success, - * COMPPROXY_E_NO_DEVICES if no devices are paired, - * or a COMPPROXY_E_* error code otherwise. + * @return COMPANION_PROXY_E_SUCCESS on success, + * COMPANION_PROXY_E_NO_DEVICES if no devices are paired, + * or a COMPANION_PROXY_E_* error code otherwise. */ -compproxy_error_t compproxy_get_device_registry(compproxy_client_t client, plist_t* paired_devices); +companion_proxy_error_t companion_proxy_get_device_registry(companion_proxy_client_t client, plist_t* paired_devices); /** * Starts listening for paired devices. * - * @param client The compproxy client + * @param client The companion_proxy client * @param callback Callback function that will be called when a new device is detected * @param userdata Pointer that that will be passed to the callback function * @@ -140,66 +140,66 @@ compproxy_error_t compproxy_get_device_registry(compproxy_client_t client, plist * freed internally after returning from the callback. The consumer needs * to make a copy if required. * - * @return COMPPROXY_E_SUCCESS on success, - * or a COMPPROXY_E_* error code otherwise. + * @return COMPANION_PROXY_E_SUCCESS on success, + * or a COMPANION_PROXY_E_* error code otherwise. */ -compproxy_error_t compproxy_start_listening_for_devices(compproxy_client_t client, compproxy_device_event_cb_t callback, void* userdata); +companion_proxy_error_t companion_proxy_start_listening_for_devices(companion_proxy_client_t client, companion_proxy_device_event_cb_t callback, void* userdata); /** * Stops listening for paired devices * - * @param client The compproxy client + * @param client The companion_proxy client * - * @return COMPPROXY_E_SUCCESS on success, - * or a COMPPROXY_E_* error code otherwise. + * @return COMPANION_PROXY_E_SUCCESS on success, + * or a COMPANION_PROXY_E_* error code otherwise. */ -compproxy_error_t compproxy_stop_listening_for_devices(compproxy_client_t client); +companion_proxy_error_t companion_proxy_stop_listening_for_devices(companion_proxy_client_t client); /** * Returns a value for the given key. * - * @param client The compproxy client - * @param companion_udid UDID of the (paired) watch + * @param client The companion_proxy client + * @param companion_udid UDID of the (paired) companion device * @param key The key to retrieve the value for * * @note The device closes the connection after sending the reply. * - * @return COMPPROXY_E_SUCCESS on success, - * COMPPROXY_E_INVALID_ARG when client or paired_devices is invalid, - * COMPPROXY_E_UNSUPPORTED_KEY if the watch doesn't support the given key, - * or a COMPPROXY_E_* error code otherwise. + * @return COMPANION_PROXY_E_SUCCESS on success, + * COMPANION_PROXY_E_INVALID_ARG when client or paired_devices is invalid, + * COMPANION_PROXY_E_UNSUPPORTED_KEY if the companion device doesn't support the given key, + * or a COMPANION_PROXY_E_* error code otherwise. */ -compproxy_error_t compproxy_get_value_from_registry(compproxy_client_t client, const char* companion_udid, const char* key, plist_t* value); +companion_proxy_error_t companion_proxy_get_value_from_registry(companion_proxy_client_t client, const char* companion_udid, const char* key, plist_t* value); /** - * Start forwarding a service port on the watch to a port on the idevice. + * Start forwarding a service port on the companion device to a port on the idevice. * - * @see compproxy_stop_forwarding_service_port + * @see companion_proxy_stop_forwarding_service_port * - * @param client The compproxy client + * @param client The companion_proxy client * @param remote_port remote port * @param service_name The name of the service that shall be forwarded * @param forward_port Pointer that will receive the newly-assigned port accessible via USB/Network on the idevice * @param options PLIST_DICT with additional options. Currently known are * IsServiceLowPriority (boolean) and PreferWifi (boolean). * - * @return COMPPROXY_E_SUCCESS on success, - * or a COMPPROXY_E_* error code otherwise. + * @return COMPANION_PROXY_E_SUCCESS on success, + * or a COMPANION_PROXY_E_* error code otherwise. */ -compproxy_error_t compproxy_start_forwarding_service_port(compproxy_client_t client, uint16_t remote_port, const char* service_name, uint16_t* forward_port, plist_t options); +companion_proxy_error_t companion_proxy_start_forwarding_service_port(companion_proxy_client_t client, uint16_t remote_port, const char* service_name, uint16_t* forward_port, plist_t options); /** - * Stop forwarding a service port between watch and idevice. + * Stop forwarding a service port between companion device and idevice. * - * @see compproxy_start_forwarding_service_port + * @see companion_proxy_start_forwarding_service_port * - * @param client The compproxy client + * @param client The companion_proxy client * @param remote_port remote port * - * @return COMPPROXY_E_SUCCESS on success, - * or a COMPPROXY_E_* error code otherwise. + * @return COMPANION_PROXY_E_SUCCESS on success, + * or a COMPANION_PROXY_E_* error code otherwise. */ -compproxy_error_t compproxy_stop_forwarding_service_port(compproxy_client_t client, uint16_t remote_port); +companion_proxy_error_t companion_proxy_stop_forwarding_service_port(companion_proxy_client_t client, uint16_t remote_port); #ifdef __cplusplus } diff --git a/src/companion_proxy.c b/src/companion_proxy.c index edce500..f09b416 100644 --- a/src/companion_proxy.c +++ b/src/companion_proxy.c @@ -32,76 +32,76 @@ #include "common/thread.h" /** - * Convert a property_list_service_error_t value to a compproxy_error_t value. + * Convert a property_list_service_error_t value to a companion_proxy_error_t value. * Used internally to get correct error codes. * * @param err An property_list_service_error_t error code * - * @return A matching compproxy_error_t error code, - * COMPPROXY_E_UNKNOWN_ERROR otherwise. + * @return A matching companion_proxy_error_t error code, + * COMPANION_PROXY_E_UNKNOWN_ERROR otherwise. */ -static compproxy_error_t compproxy_error(property_list_service_error_t err) +static companion_proxy_error_t companion_proxy_error(property_list_service_error_t err) { switch (err) { case PROPERTY_LIST_SERVICE_E_SUCCESS: - return COMPPROXY_E_SUCCESS; + return COMPANION_PROXY_E_SUCCESS; case PROPERTY_LIST_SERVICE_E_INVALID_ARG: - return COMPPROXY_E_INVALID_ARG; + return COMPANION_PROXY_E_INVALID_ARG; case PROPERTY_LIST_SERVICE_E_PLIST_ERROR: - return COMPPROXY_E_PLIST_ERROR; + return COMPANION_PROXY_E_PLIST_ERROR; case PROPERTY_LIST_SERVICE_E_MUX_ERROR: - return COMPPROXY_E_MUX_ERROR; + return COMPANION_PROXY_E_MUX_ERROR; case PROPERTY_LIST_SERVICE_E_SSL_ERROR: - return COMPPROXY_E_SSL_ERROR; + return COMPANION_PROXY_E_SSL_ERROR; case PROPERTY_LIST_SERVICE_E_NOT_ENOUGH_DATA: - return COMPPROXY_E_NOT_ENOUGH_DATA; + return COMPANION_PROXY_E_NOT_ENOUGH_DATA; case PROPERTY_LIST_SERVICE_E_RECEIVE_TIMEOUT: - return COMPPROXY_E_TIMEOUT; + return COMPANION_PROXY_E_TIMEOUT; default: break; } - return COMPPROXY_E_UNKNOWN_ERROR; + return COMPANION_PROXY_E_UNKNOWN_ERROR; } -LIBIMOBILEDEVICE_API compproxy_error_t compproxy_client_new(idevice_t device, lockdownd_service_descriptor_t service, compproxy_client_t * client) +LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_client_new(idevice_t device, lockdownd_service_descriptor_t service, companion_proxy_client_t * client) { *client = NULL; if (!device || !service || service->port == 0 || !client || *client) { - debug_info("Incorrect parameter passed to compproxy_client_new."); - return COMPPROXY_E_INVALID_ARG; + debug_info("Incorrect parameter passed to companion_proxy_client_new."); + return COMPANION_PROXY_E_INVALID_ARG; } - debug_info("Creating compproxy_client, port = %d.", service->port); + debug_info("Creating companion_proxy_client, port = %d.", service->port); property_list_service_client_t plclient = NULL; - compproxy_error_t ret = compproxy_error(property_list_service_client_new(device, service, &plclient)); - if (ret != COMPPROXY_E_SUCCESS) { + companion_proxy_error_t ret = companion_proxy_error(property_list_service_client_new(device, service, &plclient)); + if (ret != COMPANION_PROXY_E_SUCCESS) { debug_info("Creating a property list client failed. Error: %i", ret); return ret; } - compproxy_client_t client_loc = (compproxy_client_t) malloc(sizeof(struct compproxy_client_private)); + companion_proxy_client_t client_loc = (companion_proxy_client_t) malloc(sizeof(struct companion_proxy_client_private)); client_loc->parent = plclient; client_loc->event_thread = THREAD_T_NULL; *client = client_loc; - debug_info("compproxy_client successfully created."); - return COMPPROXY_E_SUCCESS; + debug_info("Created companion_proxy_client successfully."); + return COMPANION_PROXY_E_SUCCESS; } -LIBIMOBILEDEVICE_API compproxy_error_t compproxy_client_start_service(idevice_t device, compproxy_client_t * client, const char* label) +LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_client_start_service(idevice_t device, companion_proxy_client_t * client, const char* label) { - compproxy_error_t err = COMPPROXY_E_UNKNOWN_ERROR; - service_client_factory_start_service(device, COMPPROXY_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(compproxy_client_new), &err); + companion_proxy_error_t err = COMPANION_PROXY_E_UNKNOWN_ERROR; + service_client_factory_start_service(device, COMPANION_PROXY_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(companion_proxy_client_new), &err); return err; } -LIBIMOBILEDEVICE_API compproxy_error_t compproxy_client_free(compproxy_client_t client) +LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_client_free(companion_proxy_client_t client) { if (!client) - return COMPPROXY_E_INVALID_ARG; + return COMPANION_PROXY_E_INVALID_ARG; property_list_service_client_t parent = client->parent; client->parent = NULL; @@ -111,18 +111,18 @@ LIBIMOBILEDEVICE_API compproxy_error_t compproxy_client_free(compproxy_client_t thread_free(client->event_thread); client->event_thread = THREAD_T_NULL; } - compproxy_error_t err = compproxy_error(property_list_service_client_free(parent)); + companion_proxy_error_t err = companion_proxy_error(property_list_service_client_free(parent)); free(client); return err; } -LIBIMOBILEDEVICE_API compproxy_error_t compproxy_send(compproxy_client_t client, plist_t plist) +LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_send(companion_proxy_client_t client, plist_t plist) { - compproxy_error_t res = COMPPROXY_E_UNKNOWN_ERROR; + companion_proxy_error_t res = COMPANION_PROXY_E_UNKNOWN_ERROR; - res = compproxy_error(property_list_service_send_binary_plist(client->parent, plist)); - if (res != COMPPROXY_E_SUCCESS) { + res = companion_proxy_error(property_list_service_send_binary_plist(client->parent, plist)); + if (res != COMPANION_PROXY_E_SUCCESS) { debug_info("Sending plist failed with error %d", res); return res; } @@ -130,53 +130,53 @@ LIBIMOBILEDEVICE_API compproxy_error_t compproxy_send(compproxy_client_t client, return res; } -LIBIMOBILEDEVICE_API compproxy_error_t compproxy_receive(compproxy_client_t client, plist_t * plist) +LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_receive(companion_proxy_client_t client, plist_t * plist) { - compproxy_error_t res = COMPPROXY_E_UNKNOWN_ERROR; + companion_proxy_error_t res = COMPANION_PROXY_E_UNKNOWN_ERROR; plist_t outplist = NULL; - res = compproxy_error(property_list_service_receive_plist_with_timeout(client->parent, &outplist, 10000)); - if (res != COMPPROXY_E_SUCCESS && res != COMPPROXY_E_TIMEOUT) { + res = companion_proxy_error(property_list_service_receive_plist_with_timeout(client->parent, &outplist, 10000)); + if (res != COMPANION_PROXY_E_SUCCESS && res != COMPANION_PROXY_E_TIMEOUT) { debug_info("Could not receive plist, error %d", res); plist_free(outplist); - } else if (res == COMPPROXY_E_SUCCESS) { + } else if (res == COMPANION_PROXY_E_SUCCESS) { *plist = outplist; } return res; } -LIBIMOBILEDEVICE_API compproxy_error_t compproxy_get_device_registry(compproxy_client_t client, plist_t* paired_devices) +LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_get_device_registry(companion_proxy_client_t client, plist_t* paired_devices) { if (!client || !paired_devices) { - return COMPPROXY_E_INVALID_ARG; + return COMPANION_PROXY_E_INVALID_ARG; } plist_t dict = plist_new_dict(); plist_dict_set_item(dict, "Command", plist_new_string("GetDeviceRegistry")); - compproxy_error_t res = compproxy_send(client, dict); + companion_proxy_error_t res = companion_proxy_send(client, dict); plist_free(dict); dict = NULL; - if (res != COMPPROXY_E_SUCCESS) { + if (res != COMPANION_PROXY_E_SUCCESS) { return res; } - res = compproxy_receive(client, &dict); - if (res != COMPPROXY_E_SUCCESS) { + res = companion_proxy_receive(client, &dict); + if (res != COMPANION_PROXY_E_SUCCESS) { return res; } if (!dict || !PLIST_IS_DICT(dict)) { - return COMPPROXY_E_PLIST_ERROR; + return COMPANION_PROXY_E_PLIST_ERROR; } plist_t val = plist_dict_get_item(dict, "PairedDevicesArray"); if (val) { *paired_devices = plist_copy(val); - res = COMPPROXY_E_SUCCESS; + res = COMPANION_PROXY_E_SUCCESS; } else { - res = COMPPROXY_E_UNKNOWN_ERROR; + res = COMPANION_PROXY_E_UNKNOWN_ERROR; val = plist_dict_get_item(dict, "Error"); if (val) { if (plist_string_val_compare(val, "NoPairedWatches")) { - res = COMPPROXY_E_NO_DEVICES; + res = COMPANION_PROXY_E_NO_DEVICES; } } } @@ -184,24 +184,24 @@ LIBIMOBILEDEVICE_API compproxy_error_t compproxy_get_device_registry(compproxy_c return res; } -struct compproxy_cb_data { - compproxy_client_t client; - compproxy_device_event_cb_t cbfunc; +struct companion_proxy_cb_data { + companion_proxy_client_t client; + companion_proxy_device_event_cb_t cbfunc; void* user_data; }; -static void* compproxy_event_thread(void* arg) +static void* companion_proxy_event_thread(void* arg) { - struct compproxy_cb_data* data = (struct compproxy_cb_data*)arg; - compproxy_client_t client = data->client; - compproxy_error_t res; + struct companion_proxy_cb_data* data = (struct companion_proxy_cb_data*)arg; + companion_proxy_client_t client = data->client; + companion_proxy_error_t res; plist_t command = plist_new_dict(); plist_dict_set_item(command, "Command", plist_new_string("StartListeningForDevices")); - res = compproxy_send(client, command); + res = companion_proxy_send(client, command); plist_free(command); - if (res != COMPPROXY_E_SUCCESS) { + if (res != COMPANION_PROXY_E_SUCCESS) { free(data); client->event_thread = THREAD_T_NULL; return NULL; @@ -209,8 +209,8 @@ static void* compproxy_event_thread(void* arg) while (client && client->parent) { plist_t node = NULL; - res = compproxy_error(property_list_service_receive_plist_with_timeout(client->parent, &node, 1000)); - if (res != COMPPROXY_E_SUCCESS && res != COMPPROXY_E_TIMEOUT) { + res = companion_proxy_error(property_list_service_receive_plist_with_timeout(client->parent, &node, 1000)); + if (res != COMPANION_PROXY_E_SUCCESS && res != COMPANION_PROXY_E_TIMEOUT) { debug_info("could not receive plist, error %d", res); break; } @@ -227,25 +227,25 @@ static void* compproxy_event_thread(void* arg) return NULL; } -LIBIMOBILEDEVICE_API compproxy_error_t compproxy_start_listening_for_devices(compproxy_client_t client, compproxy_device_event_cb_t callback, void* userdata) +LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_start_listening_for_devices(companion_proxy_client_t client, companion_proxy_device_event_cb_t callback, void* userdata) { if (!client || !client->parent || !callback) { - return COMPPROXY_E_INVALID_ARG; + return COMPANION_PROXY_E_INVALID_ARG; } if (client->event_thread) { - return COMPPROXY_E_OP_IN_PROGRESS; + return COMPANION_PROXY_E_OP_IN_PROGRESS; } - compproxy_error_t res = COMPPROXY_E_UNKNOWN_ERROR; - struct compproxy_cb_data *data = (struct compproxy_cb_data*)malloc(sizeof(struct compproxy_cb_data)); + companion_proxy_error_t res = COMPANION_PROXY_E_UNKNOWN_ERROR; + struct companion_proxy_cb_data *data = (struct companion_proxy_cb_data*)malloc(sizeof(struct companion_proxy_cb_data)); if (data) { data->client = client; data->cbfunc = callback; data->user_data = userdata; - if (thread_new(&client->event_thread, compproxy_event_thread, data) == 0) { - res = COMPPROXY_E_SUCCESS; + if (thread_new(&client->event_thread, companion_proxy_event_thread, data) == 0) { + res = COMPANION_PROXY_E_SUCCESS; } else { free(data); } @@ -253,7 +253,7 @@ LIBIMOBILEDEVICE_API compproxy_error_t compproxy_start_listening_for_devices(com return res; } -LIBIMOBILEDEVICE_API compproxy_error_t compproxy_stop_listening_for_devices(compproxy_client_t client) +LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_stop_listening_for_devices(companion_proxy_client_t client) { property_list_service_client_t parent = client->parent; client->parent = NULL; @@ -264,13 +264,13 @@ LIBIMOBILEDEVICE_API compproxy_error_t compproxy_stop_listening_for_devices(comp client->event_thread = THREAD_T_NULL; } client->parent = parent; - return COMPPROXY_E_SUCCESS; + return COMPANION_PROXY_E_SUCCESS; } -LIBIMOBILEDEVICE_API compproxy_error_t compproxy_get_value_from_registry(compproxy_client_t client, const char* companion_udid, const char* key, plist_t* value) +LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_get_value_from_registry(companion_proxy_client_t client, const char* companion_udid, const char* key, plist_t* value) { if (!client || !companion_udid || !key || !value) { - return COMPPROXY_E_INVALID_ARG; + return COMPANION_PROXY_E_INVALID_ARG; } plist_t dict = plist_new_dict(); @@ -278,32 +278,32 @@ LIBIMOBILEDEVICE_API compproxy_error_t compproxy_get_value_from_registry(comppro plist_dict_set_item(dict, "GetValueGizmoUDIDKey", plist_new_string(companion_udid)); plist_dict_set_item(dict, "GetValueKeyKey", plist_new_string(key)); - compproxy_error_t res = compproxy_send(client, dict); + companion_proxy_error_t res = companion_proxy_send(client, dict); plist_free(dict); dict = NULL; - if (res != COMPPROXY_E_SUCCESS) { + if (res != COMPANION_PROXY_E_SUCCESS) { return res; } - res = compproxy_receive(client, &dict); - if (res != COMPPROXY_E_SUCCESS) { + res = companion_proxy_receive(client, &dict); + if (res != COMPANION_PROXY_E_SUCCESS) { return res; } if (!dict || !PLIST_IS_DICT(dict)) { - return COMPPROXY_E_PLIST_ERROR; + return COMPANION_PROXY_E_PLIST_ERROR; } plist_t val = plist_dict_get_item(dict, "RetrievedValueDictionary"); if (val) { *value = plist_copy(val); - res = COMPPROXY_E_SUCCESS; + res = COMPANION_PROXY_E_SUCCESS; } else { - res = COMPPROXY_E_UNKNOWN_ERROR; + res = COMPANION_PROXY_E_UNKNOWN_ERROR; val = plist_dict_get_item(dict, "Error"); if (val) { if (!plist_string_val_compare(val, "UnsupportedWatchKey")) { - res = COMPPROXY_E_UNSUPPORTED_KEY; + res = COMPANION_PROXY_E_UNSUPPORTED_KEY; } else if (plist_string_val_compare(val, "TimeoutReply")) { - res = COMPPROXY_E_TIMEOUT_REPLY; + res = COMPANION_PROXY_E_TIMEOUT_REPLY; } } } @@ -311,10 +311,10 @@ LIBIMOBILEDEVICE_API compproxy_error_t compproxy_get_value_from_registry(comppro return res; } -LIBIMOBILEDEVICE_API compproxy_error_t compproxy_start_forwarding_service_port(compproxy_client_t client, uint16_t remote_port, const char* service_name, uint16_t* forward_port, plist_t options) +LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_start_forwarding_service_port(companion_proxy_client_t client, uint16_t remote_port, const char* service_name, uint16_t* forward_port, plist_t options) { if (!client) { - return COMPPROXY_E_INVALID_ARG; + return COMPANION_PROXY_E_INVALID_ARG; } plist_t dict = plist_new_dict(); @@ -329,15 +329,15 @@ LIBIMOBILEDEVICE_API compproxy_error_t compproxy_start_forwarding_service_port(c plist_dict_merge(dict, options); } - compproxy_error_t res = compproxy_send(client, dict); + companion_proxy_error_t res = companion_proxy_send(client, dict); plist_free(dict); dict = NULL; - if (res != COMPPROXY_E_SUCCESS) { + if (res != COMPANION_PROXY_E_SUCCESS) { return res; } - res = compproxy_receive(client, &dict); - if (res != COMPPROXY_E_SUCCESS) { + res = companion_proxy_receive(client, &dict); + if (res != COMPANION_PROXY_E_SUCCESS) { return res; } plist_t val = plist_dict_get_item(dict, "CompanionProxyServicePort"); @@ -345,34 +345,34 @@ LIBIMOBILEDEVICE_API compproxy_error_t compproxy_start_forwarding_service_port(c uint64_t u64val = 0; plist_get_uint_val(val, &u64val); *forward_port = (uint16_t)u64val; - res = COMPPROXY_E_SUCCESS; + res = COMPANION_PROXY_E_SUCCESS; } else { - res = COMPPROXY_E_UNKNOWN_ERROR; + res = COMPANION_PROXY_E_UNKNOWN_ERROR; } plist_free(dict); return res; } -LIBIMOBILEDEVICE_API compproxy_error_t compproxy_stop_forwarding_service_port(compproxy_client_t client, uint16_t remote_port) +LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_stop_forwarding_service_port(companion_proxy_client_t client, uint16_t remote_port) { if (!client) { - return COMPPROXY_E_INVALID_ARG; + return COMPANION_PROXY_E_INVALID_ARG; } plist_t dict = plist_new_dict(); plist_dict_set_item(dict, "Command", plist_new_string("StopForwardingServicePort")); plist_dict_set_item(dict, "GizmoRemotePortNumber", plist_new_uint(remote_port)); - compproxy_error_t res = compproxy_send(client, dict); + companion_proxy_error_t res = companion_proxy_send(client, dict); plist_free(dict); dict = NULL; - if (res != COMPPROXY_E_SUCCESS) { + if (res != COMPANION_PROXY_E_SUCCESS) { return res; } - res = compproxy_receive(client, &dict); - if (res != COMPPROXY_E_SUCCESS) { + res = companion_proxy_receive(client, &dict); + if (res != COMPANION_PROXY_E_SUCCESS) { return res; } plist_free(dict); diff --git a/src/companion_proxy.h b/src/companion_proxy.h index 33c4a80..0314b67 100644 --- a/src/companion_proxy.h +++ b/src/companion_proxy.h @@ -26,7 +26,7 @@ #include "property_list_service.h" #include "common/thread.h" -struct compproxy_client_private { +struct companion_proxy_client_private { property_list_service_client_t parent; THREAD_T event_thread; }; -- cgit v1.1-32-gdbae