summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/libimobiledevice/syslog_relay.h24
-rw-r--r--src/syslog_relay.c39
2 files changed, 60 insertions, 3 deletions
diff --git a/include/libimobiledevice/syslog_relay.h b/include/libimobiledevice/syslog_relay.h
index ea7b649..89d9489 100644
--- a/include/libimobiledevice/syslog_relay.h
+++ b/include/libimobiledevice/syslog_relay.h
@@ -3,7 +3,8 @@
3 * @brief Capture the syslog output from a device. 3 * @brief Capture the syslog output from a device.
4 * \internal 4 * \internal
5 * 5 *
6 * Copyright (c) 2013-2014 Martin Szulecki All Rights Reserved. 6 * Copyright (c) 2019-2020 Nikias Bassen, All Rights Reserved.
7 * Copyright (c) 2013-2014 Martin Szulecki, All Rights Reserved.
7 * 8 *
8 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public 10 * modify it under the terms of the GNU Lesser General Public
@@ -109,6 +110,27 @@ syslog_relay_error_t syslog_relay_client_free(syslog_relay_client_t client);
109syslog_relay_error_t syslog_relay_start_capture(syslog_relay_client_t client, syslog_relay_receive_cb_t callback, void* user_data); 110syslog_relay_error_t syslog_relay_start_capture(syslog_relay_client_t client, syslog_relay_receive_cb_t callback, void* user_data);
110 111
111/** 112/**
113 * Starts capturing the *raw* syslog of the device using a callback.
114 * This function is like syslog_relay_start_capture with the difference that
115 * it will neither check nor process the received data before passing it to
116 * the callback function.
117 *
118 * Use syslog_relay_stop_capture() to stop receiving the syslog.
119 *
120 * @note Use syslog_relay_start_capture for a safer implementation.
121 *
122 * @param client The syslog_relay client to use
123 * @param callback Callback to receive each character from the syslog.
124 * @param user_data Custom pointer passed to the callback function.
125 *
126 * @return SYSLOG_RELAY_E_SUCCESS on success,
127 * SYSLOG_RELAY_E_INVALID_ARG when one or more parameters are
128 * invalid or SYSLOG_RELAY_E_UNKNOWN_ERROR when an unspecified
129 * error occurs or a syslog capture has already been started.
130 */
131syslog_relay_error_t syslog_relay_start_capture_raw(syslog_relay_client_t client, syslog_relay_receive_cb_t callback, void* user_data);
132
133/**
112 * Stops capturing the syslog of the device. 134 * Stops capturing the syslog of the device.
113 * 135 *
114 * Use syslog_relay_start_capture() to start receiving the syslog. 136 * Use syslog_relay_start_capture() to start receiving the syslog.
diff --git a/src/syslog_relay.c b/src/syslog_relay.c
index 579908c..c137297 100644
--- a/src/syslog_relay.c
+++ b/src/syslog_relay.c
@@ -2,7 +2,8 @@
2 * syslog_relay.c 2 * syslog_relay.c
3 * com.apple.syslog_relay service implementation. 3 * com.apple.syslog_relay service implementation.
4 * 4 *
5 * Copyright (c) 2013 Martin Szulecki All Rights Reserved. 5 * Copyright (c) 2019-2020 Nikias Bassen, All Rights Reserved.
6 * Copyright (c) 2013-2015 Martin Szulecki, All Rights Reserved.
6 * 7 *
7 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public 9 * modify it under the terms of the GNU Lesser General Public
@@ -33,6 +34,7 @@ struct syslog_relay_worker_thread {
33 syslog_relay_client_t client; 34 syslog_relay_client_t client;
34 syslog_relay_receive_cb_t cbfunc; 35 syslog_relay_receive_cb_t cbfunc;
35 void *user_data; 36 void *user_data;
37 int is_raw;
36}; 38};
37 39
38/** 40/**
@@ -156,8 +158,12 @@ void *syslog_relay_worker(void *arg)
156 debug_info("Connection to syslog relay interrupted"); 158 debug_info("Connection to syslog relay interrupted");
157 break; 159 break;
158 } 160 }
159 if(c != 0) { 161 if (srwt->is_raw) {
160 srwt->cbfunc(c, srwt->user_data); 162 srwt->cbfunc(c, srwt->user_data);
163 } else {
164 if (c != 0) {
165 srwt->cbfunc(c, srwt->user_data);
166 }
161 } 167 }
162 } 168 }
163 169
@@ -188,6 +194,35 @@ LIBIMOBILEDEVICE_API syslog_relay_error_t syslog_relay_start_capture(syslog_rela
188 srwt->client = client; 194 srwt->client = client;
189 srwt->cbfunc = callback; 195 srwt->cbfunc = callback;
190 srwt->user_data = user_data; 196 srwt->user_data = user_data;
197 srwt->is_raw = 0;
198
199 if (thread_new(&client->worker, syslog_relay_worker, srwt) == 0) {
200 res = SYSLOG_RELAY_E_SUCCESS;
201 }
202 }
203
204 return res;
205}
206
207LIBIMOBILEDEVICE_API syslog_relay_error_t syslog_relay_start_capture_raw(syslog_relay_client_t client, syslog_relay_receive_cb_t callback, void* user_data)
208{
209 if (!client || !callback)
210 return SYSLOG_RELAY_E_INVALID_ARG;
211
212 syslog_relay_error_t res = SYSLOG_RELAY_E_UNKNOWN_ERROR;
213
214 if (client->worker) {
215 debug_info("Another syslog capture thread appears to be running already.");
216 return res;
217 }
218
219 /* start worker thread */
220 struct syslog_relay_worker_thread *srwt = (struct syslog_relay_worker_thread*)malloc(sizeof(struct syslog_relay_worker_thread));
221 if (srwt) {
222 srwt->client = client;
223 srwt->cbfunc = callback;
224 srwt->user_data = user_data;
225 srwt->is_raw = 1;
191 226
192 if (thread_new(&client->worker, syslog_relay_worker, srwt) == 0) { 227 if (thread_new(&client->worker, syslog_relay_worker, srwt) == 0) {
193 res = SYSLOG_RELAY_E_SUCCESS; 228 res = SYSLOG_RELAY_E_SUCCESS;