summaryrefslogtreecommitdiffstats
path: root/include/libimobiledevice/service.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/libimobiledevice/service.h')
-rw-r--r--include/libimobiledevice/service.h202
1 files changed, 202 insertions, 0 deletions
diff --git a/include/libimobiledevice/service.h b/include/libimobiledevice/service.h
new file mode 100644
index 0000000..f31ada4
--- /dev/null
+++ b/include/libimobiledevice/service.h
@@ -0,0 +1,202 @@
1/**
2 * @file libimobiledevice/service.h
3 * @brief Generic basic service implementation to inherit.
4 * \internal
5 *
6 * Copyright (c) 2013-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 ISERVICE_H
24#define ISERVICE_H
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30#include <libimobiledevice/libimobiledevice.h>
31#include <libimobiledevice/lockdown.h>
32
33/** Error Codes */
34typedef enum {
35 SERVICE_E_SUCCESS = 0,
36 SERVICE_E_INVALID_ARG = -1,
37 SERVICE_E_MUX_ERROR = -3,
38 SERVICE_E_SSL_ERROR = -4,
39 SERVICE_E_START_SERVICE_ERROR = -5,
40 SERVICE_E_NOT_ENOUGH_DATA = -6,
41 SERVICE_E_TIMEOUT = -7,
42 SERVICE_E_UNKNOWN_ERROR = -256
43} service_error_t;
44
45typedef struct service_client_private service_client_private; /**< \private */
46typedef service_client_private* service_client_t; /**< The client handle. */
47
48/** service constructor cast */
49#define SERVICE_CONSTRUCTOR(x) (int32_t (*)(idevice_t, lockdownd_service_descriptor_t, void**))(x)
50
51/* Interface */
52
53/**
54 * Creates a new service for the specified service descriptor.
55 *
56 * @param device The device to connect to.
57 * @param service The service descriptor returned by lockdownd_start_service.
58 * @param client Pointer that will be set to a newly allocated
59 * service_client_t upon successful return.
60 *
61 * @return SERVICE_E_SUCCESS on success,
62 * SERVICE_E_INVALID_ARG when one of the arguments is invalid,
63 * or SERVICE_E_MUX_ERROR when connecting to the device failed.
64 */
65LIBIMOBILEDEVICE_API service_error_t service_client_new(idevice_t device, lockdownd_service_descriptor_t service, service_client_t *client);
66
67/**
68 * Starts a new service on the specified device with given name and
69 * connects to it.
70 *
71 * @param device The device to connect to.
72 * @param service_name The name of the service to start.
73 * @param client Pointer that will point to a newly allocated service_client_t
74 * upon successful return. Must be freed using service_client_free() after
75 * use.
76 * @param label The label to use for communication. Usually the program name.
77 * Pass NULL to disable sending the label in requests to lockdownd.
78 * @param constructor_func Constructor function for the service client to create (e.g. afc_client_new())
79 * @param error_code Pointer to an int32_t that will receive the service start error code.
80 *
81 * @return SERVICE_E_SUCCESS on success, or a SERVICE_E_* error code
82 * otherwise.
83 */
84LIBIMOBILEDEVICE_API service_error_t service_client_factory_start_service(idevice_t device, const char* service_name, void **client, const char* label, int32_t (*constructor_func)(idevice_t, lockdownd_service_descriptor_t, void**), int32_t *error_code);
85
86/**
87 * Frees a service instance.
88 *
89 * @param client The service instance to free.
90 *
91 * @return SERVICE_E_SUCCESS on success,
92 * SERVICE_E_INVALID_ARG when client is invalid, or a
93 * SERVICE_E_UNKNOWN_ERROR when another error occurred.
94 */
95LIBIMOBILEDEVICE_API service_error_t service_client_free(service_client_t client);
96
97
98/**
99 * Sends data using the given service client.
100 *
101 * @param client The service client to use for sending.
102 * @param data Data to send
103 * @param size Size of the data to send
104 * @param sent Number of bytes sent (can be NULL to ignore)
105 *
106 * @return SERVICE_E_SUCCESS on success,
107 * SERVICE_E_INVALID_ARG when one or more parameters are
108 * invalid, or SERVICE_E_UNKNOWN_ERROR when an unspecified
109 * error occurs.
110 */
111LIBIMOBILEDEVICE_API service_error_t service_send(service_client_t client, const char *data, uint32_t size, uint32_t *sent);
112
113/**
114 * Receives data using the given service client with specified timeout.
115 *
116 * @param client The service client to use for receiving
117 * @param data Buffer that will be filled with the data received
118 * @param size Number of bytes to receive
119 * @param received Number of bytes received (can be NULL to ignore)
120 * @param timeout Maximum time in milliseconds to wait for data.
121 *
122 * @return SERVICE_E_SUCCESS on success,
123 * SERVICE_E_INVALID_ARG when one or more parameters are
124 * invalid, SERVICE_E_MUX_ERROR when a communication error
125 * occurs, or SERVICE_E_UNKNOWN_ERROR when an unspecified
126 * error occurs.
127 */
128LIBIMOBILEDEVICE_API service_error_t service_receive_with_timeout(service_client_t client, char *data, uint32_t size, uint32_t *received, unsigned int timeout);
129
130/**
131 * Receives data using the given service client.
132 *
133 * @param client The service client to use for receiving
134 * @param data Buffer that will be filled with the data received
135 * @param size Number of bytes to receive
136 * @param received Number of bytes received (can be NULL to ignore)
137 *
138 * @return SERVICE_E_SUCCESS on success,
139 * SERVICE_E_INVALID_ARG when one or more parameters are
140 * invalid, SERVICE_E_NOT_ENOUGH_DATA when not enough data
141 * received, SERVICE_E_TIMEOUT when the connection times out,
142 * SERVICE_E_MUX_ERROR when a communication error
143 * occurs, or SERVICE_E_UNKNOWN_ERROR when an unspecified
144 * error occurs.
145 */
146LIBIMOBILEDEVICE_API service_error_t service_receive(service_client_t client, char *data, uint32_t size, uint32_t *received);
147
148
149/**
150 * Enable SSL for the given service client.
151 *
152 * @param client The connected service client for that SSL should be enabled.
153 *
154 * @return SERVICE_E_SUCCESS on success,
155 * SERVICE_E_INVALID_ARG if client or client->connection is
156 * NULL, SERVICE_E_NOT_ENOUGH_DATA when not enough data
157 * received, SERVICE_E_TIMEOUT when the connection times out,
158 * SERVICE_E_SSL_ERROR when SSL could not be enabled,
159 * or SERVICE_E_UNKNOWN_ERROR otherwise.
160 */
161LIBIMOBILEDEVICE_API service_error_t service_enable_ssl(service_client_t client);
162
163/**
164 * Disable SSL for the given service client.
165 *
166 * @param client The connected service client for which SSL should be disabled.
167 *
168 * @return SERVICE_E_SUCCESS on success,
169 * SERVICE_E_INVALID_ARG if client or client->connection is
170 * NULL, or SERVICE_E_UNKNOWN_ERROR otherwise.
171 */
172LIBIMOBILEDEVICE_API service_error_t service_disable_ssl(service_client_t client);
173
174/**
175 * Disable SSL for the given service client, optionally without sending SSL terminate messages.
176 *
177 * @param client The connected service client for which SSL should be disabled.
178 * @param sslBypass A boolean value indicating wether to disable SSL with a proper
179 * SSL shutdown (0), or bypass the shutdown (1).
180 *
181 * @return SERVICE_E_SUCCESS on success,
182 * SERVICE_E_INVALID_ARG if client or client->connection is
183 * NULL, or SERVICE_E_UNKNOWN_ERROR otherwise.
184 */
185LIBIMOBILEDEVICE_API service_error_t service_disable_bypass_ssl(service_client_t client, uint8_t sslBypass);
186
187/**
188 * Return a handle to the parent #idevice_connection_t of the given service client.
189 *
190 * @param client The service client
191 * @param connection Pointer to be assigned to the #idevice_connection_t.
192 *
193 * @return SERVICE_E_SUCCESS on success,
194 * SERVICE_E_INVALID_ARG if one or more of the arguments are invalid.
195 */
196LIBIMOBILEDEVICE_API service_error_t service_get_connection(service_client_t client, idevice_connection_t *connection);
197
198#ifdef __cplusplus
199}
200#endif
201
202#endif