diff options
Diffstat (limited to 'include/libimobiledevice/heartbeat.h')
-rw-r--r-- | include/libimobiledevice/heartbeat.h | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/include/libimobiledevice/heartbeat.h b/include/libimobiledevice/heartbeat.h new file mode 100644 index 0000000..4074b8b --- /dev/null +++ b/include/libimobiledevice/heartbeat.h | |||
@@ -0,0 +1,137 @@ | |||
1 | /** | ||
2 | * @file libimobiledevice/heartbeat.h | ||
3 | * @brief Send "heartbeat" to device to allow service connections over network. | ||
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 IHEARTBEAT_H | ||
24 | #define IHEARTBEAT_H | ||
25 | |||
26 | #ifdef __cplusplus | ||
27 | extern "C" { | ||
28 | #endif | ||
29 | |||
30 | #include <libimobiledevice/libimobiledevice.h> | ||
31 | #include <libimobiledevice/lockdown.h> | ||
32 | |||
33 | /** Service identifier passed to lockdownd_start_service() to start the heartbeat service */ | ||
34 | #define HEARTBEAT_SERVICE_NAME "com.apple.mobile.heartbeat" | ||
35 | |||
36 | /** Error Codes */ | ||
37 | typedef enum { | ||
38 | HEARTBEAT_E_SUCCESS = 0, | ||
39 | HEARTBEAT_E_INVALID_ARG = -1, | ||
40 | HEARTBEAT_E_PLIST_ERROR = -2, | ||
41 | HEARTBEAT_E_MUX_ERROR = -3, | ||
42 | HEARTBEAT_E_SSL_ERROR = -4, | ||
43 | HEARTBEAT_E_NOT_ENOUGH_DATA = -5, | ||
44 | HEARTBEAT_E_TIMEOUT = -6, | ||
45 | HEARTBEAT_E_UNKNOWN_ERROR = -256 | ||
46 | } heartbeat_error_t; | ||
47 | |||
48 | typedef struct heartbeat_client_private heartbeat_client_private; /**< \private */ | ||
49 | typedef heartbeat_client_private *heartbeat_client_t; /**< The client handle. */ | ||
50 | |||
51 | /** | ||
52 | * Connects to the heartbeat service on the specified device. | ||
53 | * | ||
54 | * @param device The device to connect to. | ||
55 | * @param service The service descriptor returned by lockdownd_start_service. | ||
56 | * @param client Pointer that will point to a newly allocated | ||
57 | * heartbeat_client_t upon successful return. Must be freed using | ||
58 | * heartbeat_client_free() after use. | ||
59 | * | ||
60 | * @return HEARTBEAT_E_SUCCESS on success, HEARTBEAT_E_INVALID_ARG when | ||
61 | * client is NULL, or an HEARTBEAT_E_* error code otherwise. | ||
62 | */ | ||
63 | LIBIMOBILEDEVICE_API heartbeat_error_t heartbeat_client_new(idevice_t device, lockdownd_service_descriptor_t service, heartbeat_client_t * client); | ||
64 | |||
65 | /** | ||
66 | * Starts a new heartbeat service on the specified device and connects to it. | ||
67 | * | ||
68 | * @param device The device to connect to. | ||
69 | * @param client Pointer that will point to a newly allocated | ||
70 | * heartbeat_client_t upon successful return. Must be freed using | ||
71 | * heartbeat_client_free() after use. | ||
72 | * @param label The label to use for communication. Usually the program name. | ||
73 | * Pass NULL to disable sending the label in requests to lockdownd. | ||
74 | * | ||
75 | * @return HEARTBEAT_E_SUCCESS on success, or an HEARTBEAT_E_* error | ||
76 | * code otherwise. | ||
77 | */ | ||
78 | LIBIMOBILEDEVICE_API heartbeat_error_t heartbeat_client_start_service(idevice_t device, heartbeat_client_t * client, const char* label); | ||
79 | |||
80 | /** | ||
81 | * Disconnects a heartbeat client from the device and frees up the | ||
82 | * heartbeat client data. | ||
83 | * | ||
84 | * @param client The heartbeat client to disconnect and free. | ||
85 | * | ||
86 | * @return HEARTBEAT_E_SUCCESS on success, HEARTBEAT_E_INVALID_ARG when | ||
87 | * client is NULL, or an HEARTBEAT_E_* error code otherwise. | ||
88 | */ | ||
89 | LIBIMOBILEDEVICE_API heartbeat_error_t heartbeat_client_free(heartbeat_client_t client); | ||
90 | |||
91 | |||
92 | /** | ||
93 | * Sends a plist to the service. | ||
94 | * | ||
95 | * @param client The heartbeat client | ||
96 | * @param plist The plist to send | ||
97 | * | ||
98 | * @return HEARTBEAT_E_SUCCESS on success, | ||
99 | * HEARTBEAT_E_INVALID_ARG when client or plist is NULL | ||
100 | */ | ||
101 | LIBIMOBILEDEVICE_API heartbeat_error_t heartbeat_send(heartbeat_client_t client, plist_t plist); | ||
102 | |||
103 | /** | ||
104 | * Receives a plist from the service. | ||
105 | * | ||
106 | * @param client The heartbeat client | ||
107 | * @param plist The plist to store the received data | ||
108 | * | ||
109 | * @return HEARTBEAT_E_SUCCESS on success, | ||
110 | * HEARTBEAT_E_INVALID_ARG when client or plist is NULL | ||
111 | */ | ||
112 | LIBIMOBILEDEVICE_API heartbeat_error_t heartbeat_receive(heartbeat_client_t client, plist_t * plist); | ||
113 | |||
114 | /** | ||
115 | * Receives a plist using the given heartbeat client. | ||
116 | * | ||
117 | * @param client The heartbeat client to use for receiving | ||
118 | * @param plist pointer to a plist_t that will point to the received plist | ||
119 | * upon successful return | ||
120 | * @param timeout_ms Maximum time in milliseconds to wait for data. | ||
121 | * | ||
122 | * @return HEARTBEAT_E_SUCCESS on success, | ||
123 | * HEARTBEAT_E_INVALID_ARG when client or *plist is NULL, | ||
124 | * HEARTBEAT_E_NOT_ENOUGH_DATA when not enough data | ||
125 | * received, HEARTBEAT_E_TIMEOUT when the connection times out, | ||
126 | * HEARTBEAT_E_PLIST_ERROR when the received data cannot be | ||
127 | * converted to a plist, HEARTBEAT_E_MUX_ERROR when a | ||
128 | * communication error occurs, or HEARTBEAT_E_UNKNOWN_ERROR | ||
129 | * when an unspecified error occurs. | ||
130 | */ | ||
131 | LIBIMOBILEDEVICE_API heartbeat_error_t heartbeat_receive_with_timeout(heartbeat_client_t client, plist_t * plist, uint32_t timeout_ms); | ||
132 | |||
133 | #ifdef __cplusplus | ||
134 | } | ||
135 | #endif | ||
136 | |||
137 | #endif | ||