diff options
Diffstat (limited to 'src/screenshotr.c')
-rw-r--r-- | src/screenshotr.c | 80 |
1 files changed, 28 insertions, 52 deletions
diff --git a/src/screenshotr.c b/src/screenshotr.c index 0c4c9b2..c3cc9ba 100644 --- a/src/screenshotr.c +++ b/src/screenshotr.c @@ -1,33 +1,36 @@ /* - * screenshotr.c + * screenshotr.c * com.apple.mobile.screenshotr service implementation. - * - * Copyright (c) 2010 Nikias Bassen All Rights Reserved. + * + * Copyright (c) 2010-2019 Nikias Bassen, All Rights Reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif #include <plist/plist.h> #include <string.h> #include <stdlib.h> #include "screenshotr.h" #include "device_link_service.h" -#include "debug.h" +#include "common/debug.h" -#define SCREENSHOTR_VERSION_INT1 100 +#define SCREENSHOTR_VERSION_INT1 400 #define SCREENSHOTR_VERSION_INT2 0 /** @@ -50,6 +53,10 @@ static screenshotr_error_t screenshotr_error(device_link_service_error_t err) return SCREENSHOTR_E_PLIST_ERROR; case DEVICE_LINK_SERVICE_E_MUX_ERROR: return SCREENSHOTR_E_MUX_ERROR; + case DEVICE_LINK_SERVICE_E_SSL_ERROR: + return SCREENSHOTR_E_SSL_ERROR; + case DEVICE_LINK_SERVICE_E_RECEIVE_TIMEOUT: + return SCREENSHOTR_E_RECEIVE_TIMEOUT; case DEVICE_LINK_SERVICE_E_BAD_VERSION: return SCREENSHOTR_E_BAD_VERSION; default: @@ -58,29 +65,14 @@ static screenshotr_error_t screenshotr_error(device_link_service_error_t err) return SCREENSHOTR_E_UNKNOWN_ERROR; } -/** - * Connects to the screenshotr service on the specified device. - * - * @param device The device to connect to. - * @param port Destination port (usually given by lockdownd_start_service). - * @param client Pointer that will be set to a newly allocated - * screenshotr_client_t upon successful return. - * - * @note This service is only available if a developer disk image has been - * mounted. - * - * @return SCREENSHOTR_E_SUCCESS on success, SCREENSHOTR_E_INVALID ARG if one - * or more parameters are invalid, or SCREENSHOTR_E_CONN_FAILED if the - * connection to the device could not be established. - */ -screenshotr_error_t screenshotr_client_new(idevice_t device, uint16_t port, +screenshotr_error_t screenshotr_client_new(idevice_t device, lockdownd_service_descriptor_t service, screenshotr_client_t * client) { - if (!device || port == 0 || !client || *client) + if (!device || !service || service->port == 0 || !client || *client) return SCREENSHOTR_E_INVALID_ARG; device_link_service_client_t dlclient = NULL; - screenshotr_error_t ret = screenshotr_error(device_link_service_client_new(device, port, &dlclient)); + screenshotr_error_t ret = screenshotr_error(device_link_service_client_new(device, service, &dlclient)); if (ret != SCREENSHOTR_E_SUCCESS) { return ret; } @@ -101,39 +93,23 @@ screenshotr_error_t screenshotr_client_new(idevice_t device, uint16_t port, return ret; } -/** - * Disconnects a screenshotr client from the device and frees up the - * screenshotr client data. - * - * @param client The screenshotr client to disconnect and free. - * - * @return SCREENSHOTR_E_SUCCESS on success, or SCREENSHOTR_E_INVALID_ARG - * if client is NULL. - */ +screenshotr_error_t screenshotr_client_start_service(idevice_t device, screenshotr_client_t * client, const char* label) +{ + screenshotr_error_t err = SCREENSHOTR_E_UNKNOWN_ERROR; + service_client_factory_start_service(device, SCREENSHOTR_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(screenshotr_client_new), &err); + return err; +} + screenshotr_error_t screenshotr_client_free(screenshotr_client_t client) { if (!client) return SCREENSHOTR_E_INVALID_ARG; - device_link_service_disconnect(client->parent); + device_link_service_disconnect(client->parent, NULL); screenshotr_error_t err = screenshotr_error(device_link_service_client_free(client->parent)); free(client); return err; } -/** - * Get a screen shot from the connected device. - * - * @param client The connection screenshotr service client. - * @param imgdata Pointer that will point to a newly allocated buffer - * containing TIFF image data upon successful return. It is up to the - * caller to free the memory. - * @param imgsize Pointer to a uint64_t that will be set to the size of the - * buffer imgdata points to upon successful return. - * - * @return SCREENSHOTR_E_SUCCESS on success, SCREENSHOTR_E_INVALID_ARG if - * one or more parameters are invalid, or another error code if an - * error occured. - */ screenshotr_error_t screenshotr_take_screenshot(screenshotr_client_t client, char **imgdata, uint64_t *imgsize) { if (!client || !client->parent || !imgdata) @@ -142,7 +118,7 @@ screenshotr_error_t screenshotr_take_screenshot(screenshotr_client_t client, cha screenshotr_error_t res = SCREENSHOTR_E_UNKNOWN_ERROR; plist_t dict = plist_new_dict(); - plist_dict_insert_item(dict, "MessageType", plist_new_string("ScreenShotRequest")); + plist_dict_set_item(dict, "MessageType", plist_new_string("ScreenShotRequest")); res = screenshotr_error(device_link_service_send_process_message(client->parent, dict)); plist_free(dict); @@ -166,7 +142,7 @@ screenshotr_error_t screenshotr_take_screenshot(screenshotr_client_t client, cha plist_t node = plist_dict_get_item(dict, "MessageType"); char *strval = NULL; plist_get_string_val(node, &strval); - if (!strval || strcmp(strval, "ScreenShotReply")) { + if (!strval || strcmp(strval, "ScreenShotReply") != 0) { debug_info("invalid screenshot data received!"); res = SCREENSHOTR_E_PLIST_ERROR; goto leave; |