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 @@ | |||
1 | /* | 1 | /* |
2 | * screenshotr.c | 2 | * screenshotr.c |
3 | * com.apple.mobile.screenshotr service implementation. | 3 | * com.apple.mobile.screenshotr service implementation. |
4 | * | 4 | * |
5 | * Copyright (c) 2010 Nikias Bassen All Rights Reserved. | 5 | * Copyright (c) 2010-2019 Nikias Bassen, All Rights Reserved. |
6 | * | 6 | * |
7 | * This library is free software; you can redistribute it and/or | 7 | * This library is free software; you can redistribute it and/or |
8 | * modify it under the terms of the GNU Lesser General Public | 8 | * modify it under the terms of the GNU Lesser General Public |
9 | * License as published by the Free Software Foundation; either | 9 | * License as published by the Free Software Foundation; either |
10 | * version 2.1 of the License, or (at your option) any later version. | 10 | * version 2.1 of the License, or (at your option) any later version. |
11 | * | 11 | * |
12 | * This library is distributed in the hope that it will be useful, | 12 | * This library is distributed in the hope that it will be useful, |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | * Lesser General Public License for more details. | 15 | * Lesser General Public License for more details. |
16 | * | 16 | * |
17 | * You should have received a copy of the GNU Lesser General Public | 17 | * You should have received a copy of the GNU Lesser General Public |
18 | * License along with this library; if not, write to the Free Software | 18 | * License along with this library; if not, write to the Free Software |
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #ifdef HAVE_CONFIG_H | ||
23 | #include <config.h> | ||
24 | #endif | ||
22 | #include <plist/plist.h> | 25 | #include <plist/plist.h> |
23 | #include <string.h> | 26 | #include <string.h> |
24 | #include <stdlib.h> | 27 | #include <stdlib.h> |
25 | 28 | ||
26 | #include "screenshotr.h" | 29 | #include "screenshotr.h" |
27 | #include "device_link_service.h" | 30 | #include "device_link_service.h" |
28 | #include "debug.h" | 31 | #include "common/debug.h" |
29 | 32 | ||
30 | #define SCREENSHOTR_VERSION_INT1 100 | 33 | #define SCREENSHOTR_VERSION_INT1 400 |
31 | #define SCREENSHOTR_VERSION_INT2 0 | 34 | #define SCREENSHOTR_VERSION_INT2 0 |
32 | 35 | ||
33 | /** | 36 | /** |
@@ -50,6 +53,10 @@ static screenshotr_error_t screenshotr_error(device_link_service_error_t err) | |||
50 | return SCREENSHOTR_E_PLIST_ERROR; | 53 | return SCREENSHOTR_E_PLIST_ERROR; |
51 | case DEVICE_LINK_SERVICE_E_MUX_ERROR: | 54 | case DEVICE_LINK_SERVICE_E_MUX_ERROR: |
52 | return SCREENSHOTR_E_MUX_ERROR; | 55 | return SCREENSHOTR_E_MUX_ERROR; |
56 | case DEVICE_LINK_SERVICE_E_SSL_ERROR: | ||
57 | return SCREENSHOTR_E_SSL_ERROR; | ||
58 | case DEVICE_LINK_SERVICE_E_RECEIVE_TIMEOUT: | ||
59 | return SCREENSHOTR_E_RECEIVE_TIMEOUT; | ||
53 | case DEVICE_LINK_SERVICE_E_BAD_VERSION: | 60 | case DEVICE_LINK_SERVICE_E_BAD_VERSION: |
54 | return SCREENSHOTR_E_BAD_VERSION; | 61 | return SCREENSHOTR_E_BAD_VERSION; |
55 | default: | 62 | default: |
@@ -58,29 +65,14 @@ static screenshotr_error_t screenshotr_error(device_link_service_error_t err) | |||
58 | return SCREENSHOTR_E_UNKNOWN_ERROR; | 65 | return SCREENSHOTR_E_UNKNOWN_ERROR; |
59 | } | 66 | } |
60 | 67 | ||
61 | /** | 68 | screenshotr_error_t screenshotr_client_new(idevice_t device, lockdownd_service_descriptor_t service, |
62 | * Connects to the screenshotr service on the specified device. | ||
63 | * | ||
64 | * @param device The device to connect to. | ||
65 | * @param port Destination port (usually given by lockdownd_start_service). | ||
66 | * @param client Pointer that will be set to a newly allocated | ||
67 | * screenshotr_client_t upon successful return. | ||
68 | * | ||
69 | * @note This service is only available if a developer disk image has been | ||
70 | * mounted. | ||
71 | * | ||
72 | * @return SCREENSHOTR_E_SUCCESS on success, SCREENSHOTR_E_INVALID ARG if one | ||
73 | * or more parameters are invalid, or SCREENSHOTR_E_CONN_FAILED if the | ||
74 | * connection to the device could not be established. | ||
75 | */ | ||
76 | screenshotr_error_t screenshotr_client_new(idevice_t device, uint16_t port, | ||
77 | screenshotr_client_t * client) | 69 | screenshotr_client_t * client) |
78 | { | 70 | { |
79 | if (!device || port == 0 || !client || *client) | 71 | if (!device || !service || service->port == 0 || !client || *client) |
80 | return SCREENSHOTR_E_INVALID_ARG; | 72 | return SCREENSHOTR_E_INVALID_ARG; |
81 | 73 | ||
82 | device_link_service_client_t dlclient = NULL; | 74 | device_link_service_client_t dlclient = NULL; |
83 | screenshotr_error_t ret = screenshotr_error(device_link_service_client_new(device, port, &dlclient)); | 75 | screenshotr_error_t ret = screenshotr_error(device_link_service_client_new(device, service, &dlclient)); |
84 | if (ret != SCREENSHOTR_E_SUCCESS) { | 76 | if (ret != SCREENSHOTR_E_SUCCESS) { |
85 | return ret; | 77 | return ret; |
86 | } | 78 | } |
@@ -101,39 +93,23 @@ screenshotr_error_t screenshotr_client_new(idevice_t device, uint16_t port, | |||
101 | return ret; | 93 | return ret; |
102 | } | 94 | } |
103 | 95 | ||
104 | /** | 96 | screenshotr_error_t screenshotr_client_start_service(idevice_t device, screenshotr_client_t * client, const char* label) |
105 | * Disconnects a screenshotr client from the device and frees up the | 97 | { |
106 | * screenshotr client data. | 98 | screenshotr_error_t err = SCREENSHOTR_E_UNKNOWN_ERROR; |
107 | * | 99 | service_client_factory_start_service(device, SCREENSHOTR_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(screenshotr_client_new), &err); |
108 | * @param client The screenshotr client to disconnect and free. | 100 | return err; |
109 | * | 101 | } |
110 | * @return SCREENSHOTR_E_SUCCESS on success, or SCREENSHOTR_E_INVALID_ARG | 102 | |
111 | * if client is NULL. | ||
112 | */ | ||
113 | screenshotr_error_t screenshotr_client_free(screenshotr_client_t client) | 103 | screenshotr_error_t screenshotr_client_free(screenshotr_client_t client) |
114 | { | 104 | { |
115 | if (!client) | 105 | if (!client) |
116 | return SCREENSHOTR_E_INVALID_ARG; | 106 | return SCREENSHOTR_E_INVALID_ARG; |
117 | device_link_service_disconnect(client->parent); | 107 | device_link_service_disconnect(client->parent, NULL); |
118 | screenshotr_error_t err = screenshotr_error(device_link_service_client_free(client->parent)); | 108 | screenshotr_error_t err = screenshotr_error(device_link_service_client_free(client->parent)); |
119 | free(client); | 109 | free(client); |
120 | return err; | 110 | return err; |
121 | } | 111 | } |
122 | 112 | ||
123 | /** | ||
124 | * Get a screen shot from the connected device. | ||
125 | * | ||
126 | * @param client The connection screenshotr service client. | ||
127 | * @param imgdata Pointer that will point to a newly allocated buffer | ||
128 | * containing TIFF image data upon successful return. It is up to the | ||
129 | * caller to free the memory. | ||
130 | * @param imgsize Pointer to a uint64_t that will be set to the size of the | ||
131 | * buffer imgdata points to upon successful return. | ||
132 | * | ||
133 | * @return SCREENSHOTR_E_SUCCESS on success, SCREENSHOTR_E_INVALID_ARG if | ||
134 | * one or more parameters are invalid, or another error code if an | ||
135 | * error occured. | ||
136 | */ | ||
137 | screenshotr_error_t screenshotr_take_screenshot(screenshotr_client_t client, char **imgdata, uint64_t *imgsize) | 113 | screenshotr_error_t screenshotr_take_screenshot(screenshotr_client_t client, char **imgdata, uint64_t *imgsize) |
138 | { | 114 | { |
139 | if (!client || !client->parent || !imgdata) | 115 | if (!client || !client->parent || !imgdata) |
@@ -142,7 +118,7 @@ screenshotr_error_t screenshotr_take_screenshot(screenshotr_client_t client, cha | |||
142 | screenshotr_error_t res = SCREENSHOTR_E_UNKNOWN_ERROR; | 118 | screenshotr_error_t res = SCREENSHOTR_E_UNKNOWN_ERROR; |
143 | 119 | ||
144 | plist_t dict = plist_new_dict(); | 120 | plist_t dict = plist_new_dict(); |
145 | plist_dict_insert_item(dict, "MessageType", plist_new_string("ScreenShotRequest")); | 121 | plist_dict_set_item(dict, "MessageType", plist_new_string("ScreenShotRequest")); |
146 | 122 | ||
147 | res = screenshotr_error(device_link_service_send_process_message(client->parent, dict)); | 123 | res = screenshotr_error(device_link_service_send_process_message(client->parent, dict)); |
148 | plist_free(dict); | 124 | plist_free(dict); |
@@ -166,7 +142,7 @@ screenshotr_error_t screenshotr_take_screenshot(screenshotr_client_t client, cha | |||
166 | plist_t node = plist_dict_get_item(dict, "MessageType"); | 142 | plist_t node = plist_dict_get_item(dict, "MessageType"); |
167 | char *strval = NULL; | 143 | char *strval = NULL; |
168 | plist_get_string_val(node, &strval); | 144 | plist_get_string_val(node, &strval); |
169 | if (!strval || strcmp(strval, "ScreenShotReply")) { | 145 | if (!strval || strcmp(strval, "ScreenShotReply") != 0) { |
170 | debug_info("invalid screenshot data received!"); | 146 | debug_info("invalid screenshot data received!"); |
171 | res = SCREENSHOTR_E_PLIST_ERROR; | 147 | res = SCREENSHOTR_E_PLIST_ERROR; |
172 | goto leave; | 148 | goto leave; |