summaryrefslogtreecommitdiffstats
path: root/include/libimobiledevice
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2014-06-21 01:53:31 +0200
committerGravatar Martin Szulecki2014-09-19 15:49:07 +0200
commit85f3680622da0eb3529e042793d4fbf9b0d41110 (patch)
tree80c6b55d18596bffa305fbb081707fa6b1466e8c /include/libimobiledevice
parent643b47f43e11ed59d674d943b913ad13c7cbaab1 (diff)
downloadlibimobiledevice-85f3680622da0eb3529e042793d4fbf9b0d41110.tar.gz
libimobiledevice-85f3680622da0eb3529e042793d4fbf9b0d41110.tar.bz2
Add protocol implementation for debugserver service
Diffstat (limited to 'include/libimobiledevice')
-rw-r--r--include/libimobiledevice/debugserver.h235
1 files changed, 235 insertions, 0 deletions
diff --git a/include/libimobiledevice/debugserver.h b/include/libimobiledevice/debugserver.h
new file mode 100644
index 0000000..aa62746
--- /dev/null
+++ b/include/libimobiledevice/debugserver.h
@@ -0,0 +1,235 @@
1/**
2 * @file libimobiledevice/debugserver.h
3 * @brief Communicate with debugserver on the device.
4 * \internal
5 *
6 * Copyright (c) 2014 Martin Szulecki All Rights Reserved.
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#ifndef IDEBUGSERVER_H
24#define IDEBUGSERVER_H
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30#include <libimobiledevice/libimobiledevice.h>
31#include <libimobiledevice/lockdown.h>
32
33#define DEBUGSERVER_SERVICE_NAME "com.apple.debugserver"
34
35/** @name Error Codes */
36/*@{*/
37#define DEBUGSERVER_E_SUCCESS 0
38#define DEBUGSERVER_E_INVALID_ARG -1
39#define DEBUGSERVER_E_MUX_ERROR -2
40#define DEBUGSERVER_E_SSL_ERROR -3
41#define DEBUGSERVER_E_RESPONSE_ERROR -4
42#define DEBUGSERVER_E_UNKNOWN_ERROR -256
43/*@}*/
44
45/** Represents an error code. */
46typedef int16_t debugserver_error_t;
47
48typedef struct debugserver_client_private debugserver_client_private;
49typedef debugserver_client_private *debugserver_client_t; /**< The client handle. */
50
51typedef struct debugserver_command_private debugserver_command_private;
52typedef debugserver_command_private *debugserver_command_t; /**< The command handle. */
53
54/* Interface */
55
56/**
57 * Connects to the debugserver service on the specified device.
58 *
59 * @param device The device to connect to.
60 * @param service The service descriptor returned by lockdownd_start_service.
61 * @param client Pointer that will point to a newly allocated
62 * debugserver_client_t upon successful return. Must be freed using
63 * debugserver_client_free() after use.
64 *
65 * @return DEBUGSERVER_E_SUCCESS on success, DEBUGSERVER_E_INVALID_ARG when
66 * client is NULL, or an DEBUGSERVER_E_* error code otherwise.
67 */
68debugserver_error_t debugserver_client_new(idevice_t device, lockdownd_service_descriptor_t service, debugserver_client_t * client);
69
70/**
71 * Starts a new debugserver service on the specified device and connects to it.
72 *
73 * @param device The device to connect to.
74 * @param client Pointer that will point to a newly allocated
75 * debugserver_client_t upon successful return. Must be freed using
76 * debugserver_client_free() after use.
77 * @param label The label to use for communication. Usually the program name.
78 * Pass NULL to disable sending the label in requests to lockdownd.
79 *
80 * @return DEBUGSERVER_E_SUCCESS on success, or an DEBUGSERVER_E_* error
81 * code otherwise.
82 */
83debugserver_error_t debugserver_client_start_service(idevice_t device, debugserver_client_t * client, const char* label);
84
85/**
86 * Disconnects a debugserver client from the device and frees up the
87 * debugserver client data.
88 *
89 * @param client The debugserver client to disconnect and free.
90 *
91 * @return DEBUGSERVER_E_SUCCESS on success, DEBUGSERVER_E_INVALID_ARG when
92 * client is NULL, or an DEBUGSERVER_E_* error code otherwise.
93 */
94debugserver_error_t debugserver_client_free(debugserver_client_t client);
95
96/**
97 * Sends raw data using the given debugserver service client.
98 *
99 * @param client The debugserver client to use for sending
100 * @param data Data to send
101 * @param size Size of the data to send
102 * @param sent Number of bytes sent (can be NULL to ignore)
103 *
104 * @return DEBUGSERVER_E_SUCCESS on success,
105 * DEBUGSERVER_E_INVALID_ARG when one or more parameters are
106 * invalid, or DEBUGSERVER_E_UNKNOWN_ERROR when an unspecified
107 * error occurs.
108 */
109debugserver_error_t debugserver_client_send(debugserver_client_t client, const char* data, uint32_t size, uint32_t *sent);
110
111/**
112 * Receives raw data using the given debugserver client with specified timeout.
113 *
114 * @param client The debugserver client to use for receiving
115 * @param data Buffer that will be filled with the data received
116 * @param size Number of bytes to receive
117 * @param received Number of bytes received (can be NULL to ignore)
118 * @param timeout Maximum time in milliseconds to wait for data.
119 *
120 * @return DEBUGSERVER_E_SUCCESS on success,
121 * DEBUGSERVER_E_INVALID_ARG when one or more parameters are
122 * invalid, DEBUGSERVER_E_MUX_ERROR when a communication error
123 * occurs, or DEBUGSERVER_E_UNKNOWN_ERROR when an unspecified
124 * error occurs.
125 */
126debugserver_error_t debugserver_client_receive_with_timeout(debugserver_client_t client, char *data, uint32_t size, uint32_t *received, unsigned int timeout);
127
128/**
129 * Receives raw data from the debugserver service.
130 *
131 * @param client The debugserver client
132 * @param data Buffer that will be filled with the data received
133 * @param size Number of bytes to receive
134 * @param received Number of bytes received (can be NULL to ignore)
135 * @note The default read timeout is 10 seconds.
136 *
137 * @return DEBUGSERVER_E_SUCCESS on success,
138 * DEBUGSERVER_E_INVALID_ARG when client or plist is NULL
139 */
140debugserver_error_t debugserver_client_receive(debugserver_client_t client, char *data, uint32_t size, uint32_t *received);
141
142/**
143 * Sends a command to the debugserver service.
144 *
145 * @param client The debugserver client
146 * @param command Command to process and send
147 * @param response Response received for the command (can be NULL to ignore)
148 *
149 * @return DEBUGSERVER_E_SUCCESS on success,
150 * DEBUGSERVER_E_INVALID_ARG when client or command is NULL
151 */
152debugserver_error_t debugserver_client_send_command(debugserver_client_t client, debugserver_command_t command, char** response);
153
154/**
155 * Receives and parses response of debugserver service.
156 *
157 * @param client The debugserver client
158 * @param response Response received for last command (can be NULL to ignore)
159 *
160 * @return DEBUGSERVER_E_SUCCESS on success,
161 * DEBUGSERVER_E_INVALID_ARG when client is NULL
162 */
163debugserver_error_t debugserver_client_receive_response(debugserver_client_t client, char** response);
164
165/**
166 * Sets the argv which launches an app.
167 *
168 * @param client The debugserver client
169 * @param argc Number of arguments
170 * @param argv Array starting with the executable to be run followed by it's arguments
171 * @param response Response received for the command (can be NULL to ignore)
172 *
173 * @return DEBUGSERVER_E_SUCCESS on success,
174 * DEBUGSERVER_E_INVALID_ARG when client is NULL
175 */
176debugserver_error_t debugserver_client_set_argv(debugserver_client_t client, int argc, char* argv[], char** response);
177
178/**
179 * Adds or sets an environment variable.
180 *
181 * @param client The debugserver client
182 * @param env The environment variable in "KEY=VALUE" notation
183 * @param response Response received for the command (can be NULL to ignore)
184 *
185 * @return DEBUGSERVER_E_SUCCESS on success,
186 * DEBUGSERVER_E_INVALID_ARG when client is NULL
187 */
188debugserver_error_t debugserver_client_set_environment_hex_encoded(debugserver_client_t client, const char* env, char** response);
189
190/**
191 * Creates and initializes a new command object.
192 *
193 * @param name The name of the command which is sent in plain text
194 * @param argv Array of tokens for the command ment to be encoded
195 * @param argc Number of items in the token array
196 * @param command New command object
197 *
198 * @return DEBUGSERVER_E_SUCCESS on success,
199 * DEBUGSERVER_E_INVALID_ARG when name or command is NULL
200 */
201debugserver_error_t debugserver_command_new(const char* name, int argc, const char* argv[], debugserver_command_t* command);
202
203/**
204 * Frees memory of command object.
205 *
206 * @param command The command object
207 *
208 * @return DEBUGSERVER_E_SUCCESS on success,
209 * DEBUGSERVER_E_INVALID_ARG when command is NULL
210 */
211debugserver_error_t debugserver_command_free(debugserver_command_t command);
212
213/**
214 * Encodes a string into hex notation.
215 *
216 * @param buffer String to encode into hex notiation
217 * @param encoded_buffer The buffer receives a hex encoded string
218 * @param encoded_length Length of the hex encoded string
219 */
220void debugserver_encode_string(const char* buffer, char** encoded_buffer, uint32_t* encoded_length);
221
222/**
223 * Decodes a hex encoded string.
224 *
225 * @param encoded_buffer The buffer with a hex encoded string
226 * @param encoded_length Length of the encoded buffer
227 * @param buffer Decoded string to be freed by the caller
228 */
229void debugserver_decode_string(const char *encoded_buffer, size_t encoded_length, char** buffer);
230
231#ifdef __cplusplus
232}
233#endif
234
235#endif