diff options
Diffstat (limited to 'src/webinspector.c')
| -rw-r--r-- | src/webinspector.c | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/webinspector.c b/src/webinspector.c index c3d57cc..eb12d4d 100644 --- a/src/webinspector.c +++ b/src/webinspector.c | |||
| @@ -62,7 +62,7 @@ static webinspector_error_t webinspector_error(property_list_service_error_t err | |||
| 62 | * Connects to the webinspector service on the specified device. | 62 | * Connects to the webinspector service on the specified device. |
| 63 | * | 63 | * |
| 64 | * @param device The device to connect to. | 64 | * @param device The device to connect to. |
| 65 | * @param port Destination port (usually given by lockdownd_start_service). | 65 | * @param service The service descriptor returned by lockdownd_start_service. |
| 66 | * @param client Pointer that will point to a newly allocated | 66 | * @param client Pointer that will point to a newly allocated |
| 67 | * webinspector_client_t upon successful return. Must be freed using | 67 | * webinspector_client_t upon successful return. Must be freed using |
| 68 | * webinspector_client_free() after use. | 68 | * webinspector_client_free() after use. |
| @@ -70,19 +70,19 @@ static webinspector_error_t webinspector_error(property_list_service_error_t err | |||
| 70 | * @return WEBINSPECTOR_E_SUCCESS on success, WEBINSPECTOR_E_INVALID_ARG when | 70 | * @return WEBINSPECTOR_E_SUCCESS on success, WEBINSPECTOR_E_INVALID_ARG when |
| 71 | * client is NULL, or an WEBINSPECTOR_E_* error code otherwise. | 71 | * client is NULL, or an WEBINSPECTOR_E_* error code otherwise. |
| 72 | */ | 72 | */ |
| 73 | webinspector_error_t webinspector_client_new(idevice_t device, uint16_t port, webinspector_client_t * client) | 73 | webinspector_error_t webinspector_client_new(idevice_t device, lockdownd_service_descriptor_t service, webinspector_client_t * client) |
| 74 | { | 74 | { |
| 75 | *client = NULL; | 75 | *client = NULL; |
| 76 | 76 | ||
| 77 | debug_info("Creating webinspector_client, port = %d.", port); | 77 | debug_info("Creating webinspector_client, port = %d.", service->port); |
| 78 | 78 | ||
| 79 | if (!device || port == 0 || !client || *client) { | 79 | if (!device || service->port == 0 || !client || *client) { |
| 80 | debug_info("Incorrect parameter passed to webinspector_client_new."); | 80 | debug_info("Incorrect parameter passed to webinspector_client_new."); |
| 81 | return WEBINSPECTOR_E_INVALID_ARG; | 81 | return WEBINSPECTOR_E_INVALID_ARG; |
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | property_list_service_client_t plclient = NULL; | 84 | property_list_service_client_t plclient = NULL; |
| 85 | webinspector_error_t ret = webinspector_error(property_list_service_client_new(device, port, &plclient)); | 85 | webinspector_error_t ret = webinspector_error(property_list_service_client_new(device, service, &plclient)); |
| 86 | if (ret != WEBINSPECTOR_E_SUCCESS) { | 86 | if (ret != WEBINSPECTOR_E_SUCCESS) { |
| 87 | debug_info("Creating a property list client failed. Error: %i", ret); | 87 | debug_info("Creating a property list client failed. Error: %i", ret); |
| 88 | return ret; | 88 | return ret; |
| @@ -118,22 +118,27 @@ webinspector_error_t webinspector_start_service(idevice_t device, webinspector_c | |||
| 118 | debug_info("Could not create a lockdown client."); | 118 | debug_info("Could not create a lockdown client."); |
| 119 | return WEBINSPECTOR_E_UNKNOWN_ERROR; | 119 | return WEBINSPECTOR_E_UNKNOWN_ERROR; |
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | uint16_t port = 0; | 122 | lockdownd_service_descriptor_t service = NULL; |
| 123 | lockdownd_start_service(lckd, WEBINSPECTOR_SERVICE_NAME, &port); | 123 | lockdownd_start_service(lckd, WEBINSPECTOR_SERVICE_NAME, &service); |
| 124 | lockdownd_client_free(lckd); | 124 | lockdownd_client_free(lckd); |
| 125 | 125 | ||
| 126 | if (port <= 0) { | 126 | if (service->port <= 0) { |
| 127 | debug_info("Could not start webinspector service!"); | 127 | debug_info("Could not start webinspector service!"); |
| 128 | return WEBINSPECTOR_E_UNKNOWN_ERROR; | 128 | return WEBINSPECTOR_E_UNKNOWN_ERROR; |
| 129 | } | 129 | } |
| 130 | 130 | ||
| 131 | webinspector_error_t res = webinspector_client_new(device, port, client); | 131 | webinspector_error_t res = webinspector_client_new(device, service, client); |
| 132 | if (res != WEBINSPECTOR_E_SUCCESS) { | 132 | if (res != WEBINSPECTOR_E_SUCCESS) { |
| 133 | debug_info("Could not connect to webinspector! Port: %i, error: %i", port, res); | 133 | debug_info("Could not connect to webinspector! Port: %i, error: %i", service->port, res); |
| 134 | return res; | 134 | return res; |
| 135 | } | 135 | } |
| 136 | 136 | ||
| 137 | if (service) { | ||
| 138 | lockdownd_service_descriptor_free(service); | ||
| 139 | service = NULL; | ||
| 140 | } | ||
| 141 | |||
| 137 | return WEBINSPECTOR_E_SUCCESS; | 142 | return WEBINSPECTOR_E_SUCCESS; |
| 138 | } | 143 | } |
| 139 | 144 | ||
