summaryrefslogtreecommitdiffstats
path: root/include/libimobiledevice/syslog_relay.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/libimobiledevice/syslog_relay.h')
-rw-r--r--include/libimobiledevice/syslog_relay.h184
1 files changed, 184 insertions, 0 deletions
diff --git a/include/libimobiledevice/syslog_relay.h b/include/libimobiledevice/syslog_relay.h
new file mode 100644
index 0000000..0f6487a
--- /dev/null
+++ b/include/libimobiledevice/syslog_relay.h
@@ -0,0 +1,184 @@
1/**
2 * @file libimobiledevice/syslog_relay.h
3 * @brief Capture the syslog output from a device.
4 * \internal
5 *
6 * Copyright (c) 2019-2020 Nikias Bassen, All Rights Reserved.
7 * Copyright (c) 2013-2014 Martin Szulecki, All Rights Reserved.
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#ifndef ISYSLOG_RELAY_H
25#define ISYSLOG_RELAY_H
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31#include <libimobiledevice/libimobiledevice.h>
32#include <libimobiledevice/lockdown.h>
33
34/** Service identifier passed to lockdownd_start_service() to start the syslog relay service */
35#define SYSLOG_RELAY_SERVICE_NAME "com.apple.syslog_relay"
36
37/** Error Codes */
38typedef enum {
39 SYSLOG_RELAY_E_SUCCESS = 0,
40 SYSLOG_RELAY_E_INVALID_ARG = -1,
41 SYSLOG_RELAY_E_MUX_ERROR = -2,
42 SYSLOG_RELAY_E_SSL_ERROR = -3,
43 SYSLOG_RELAY_E_NOT_ENOUGH_DATA = -4,
44 SYSLOG_RELAY_E_TIMEOUT = -5,
45 SYSLOG_RELAY_E_UNKNOWN_ERROR = -256
46} syslog_relay_error_t;
47
48typedef struct syslog_relay_client_private syslog_relay_client_private; /**< \private */
49typedef syslog_relay_client_private *syslog_relay_client_t; /**< The client handle. */
50
51/** Receives each character received from the device. */
52typedef void (*syslog_relay_receive_cb_t)(char c, void *user_data);
53
54/* Interface */
55
56/**
57 * Connects to the syslog_relay 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 * syslog_relay_client_t upon successful return. Must be freed using
63 * syslog_relay_client_free() after use.
64 *
65 * @return SYSLOG_RELAY_E_SUCCESS on success, SYSLOG_RELAY_E_INVALID_ARG when
66 * client is NULL, or an SYSLOG_RELAY_E_* error code otherwise.
67 */
68LIBIMOBILEDEVICE_API syslog_relay_error_t syslog_relay_client_new(idevice_t device, lockdownd_service_descriptor_t service, syslog_relay_client_t * client);
69
70/**
71 * Starts a new syslog_relay 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 * syslog_relay_client_t upon successful return. Must be freed using
76 * syslog_relay_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 SYSLOG_RELAY_E_SUCCESS on success, or an SYSLOG_RELAY_E_* error
81 * code otherwise.
82 */
83LIBIMOBILEDEVICE_API syslog_relay_error_t syslog_relay_client_start_service(idevice_t device, syslog_relay_client_t * client, const char* label);
84
85/**
86 * Disconnects a syslog_relay client from the device and frees up the
87 * syslog_relay client data.
88 *
89 * @param client The syslog_relay client to disconnect and free.
90 *
91 * @return SYSLOG_RELAY_E_SUCCESS on success, SYSLOG_RELAY_E_INVALID_ARG when
92 * client is NULL, or an SYSLOG_RELAY_E_* error code otherwise.
93 */
94LIBIMOBILEDEVICE_API syslog_relay_error_t syslog_relay_client_free(syslog_relay_client_t client);
95
96
97/**
98 * Starts capturing the syslog of the device using a callback.
99 *
100 * Use syslog_relay_stop_capture() to stop receiving the syslog.
101 *
102 * @param client The syslog_relay client to use
103 * @param callback Callback to receive each character from the syslog.
104 * @param user_data Custom pointer passed to the callback function.
105 *
106 * @return SYSLOG_RELAY_E_SUCCESS on success,
107 * SYSLOG_RELAY_E_INVALID_ARG when one or more parameters are
108 * invalid or SYSLOG_RELAY_E_UNKNOWN_ERROR when an unspecified
109 * error occurs or a syslog capture has already been started.
110 */
111LIBIMOBILEDEVICE_API syslog_relay_error_t syslog_relay_start_capture(syslog_relay_client_t client, syslog_relay_receive_cb_t callback, void* user_data);
112
113/**
114 * Starts capturing the *raw* syslog of the device using a callback.
115 * This function is like syslog_relay_start_capture with the difference that
116 * it will neither check nor process the received data before passing it to
117 * the callback function.
118 *
119 * Use syslog_relay_stop_capture() to stop receiving the syslog.
120 *
121 * @note Use syslog_relay_start_capture for a safer implementation.
122 *
123 * @param client The syslog_relay client to use
124 * @param callback Callback to receive each character from the syslog.
125 * @param user_data Custom pointer passed to the callback function.
126 *
127 * @return SYSLOG_RELAY_E_SUCCESS on success,
128 * SYSLOG_RELAY_E_INVALID_ARG when one or more parameters are
129 * invalid or SYSLOG_RELAY_E_UNKNOWN_ERROR when an unspecified
130 * error occurs or a syslog capture has already been started.
131 */
132LIBIMOBILEDEVICE_API syslog_relay_error_t syslog_relay_start_capture_raw(syslog_relay_client_t client, syslog_relay_receive_cb_t callback, void* user_data);
133
134/**
135 * Stops capturing the syslog of the device.
136 *
137 * Use syslog_relay_start_capture() to start receiving the syslog.
138 *
139 * @param client The syslog_relay client to use
140 *
141 * @return SYSLOG_RELAY_E_SUCCESS on success,
142 * SYSLOG_RELAY_E_INVALID_ARG when one or more parameters are
143 * invalid or SYSLOG_RELAY_E_UNKNOWN_ERROR when an unspecified
144 * error occurs or a syslog capture has already been started.
145 */
146LIBIMOBILEDEVICE_API syslog_relay_error_t syslog_relay_stop_capture(syslog_relay_client_t client);
147
148/* Receiving */
149
150/**
151 * Receives data using the given syslog_relay client with specified timeout.
152 *
153 * @param client The syslog_relay client to use for receiving
154 * @param data Buffer that will be filled with the data received
155 * @param size Number of bytes to receive
156 * @param received Number of bytes received (can be NULL to ignore)
157 * @param timeout Maximum time in milliseconds to wait for data.
158 *
159 * @return SYSLOG_RELAY_E_SUCCESS on success,
160 * SYSLOG_RELAY_E_INVALID_ARG when one or more parameters are
161 * invalid, SYSLOG_RELAY_E_MUX_ERROR when a communication error
162 * occurs, or SYSLOG_RELAY_E_UNKNOWN_ERROR when an unspecified
163 * error occurs.
164 */
165LIBIMOBILEDEVICE_API syslog_relay_error_t syslog_relay_receive_with_timeout(syslog_relay_client_t client, char *data, uint32_t size, uint32_t *received, unsigned int timeout);
166
167/**
168 * Receives data from the service.
169 *
170 * @param client The syslog_relay client
171 * @param data Buffer that will be filled with the data received
172 * @param size Number of bytes to receive
173 * @param received Number of bytes received (can be NULL to ignore)
174 *
175 * @return SYSLOG_RELAY_E_SUCCESS on success,
176 * SYSLOG_RELAY_E_INVALID_ARG when client or plist is NULL
177 */
178LIBIMOBILEDEVICE_API syslog_relay_error_t syslog_relay_receive(syslog_relay_client_t client, char *data, uint32_t size, uint32_t *received);
179
180#ifdef __cplusplus
181}
182#endif
183
184#endif