--- a/libpurple/protocols/zephyr/zephyr.c Mon Dec 14 17:49:08 2020 -0600
+++ b/libpurple/protocols/zephyr/zephyr.c Mon Dec 14 23:55:58 2020 -0600
@@ -70,6 +70,8 @@
typedef struct _zephyr_account zephyr_account;
typedef struct _parse_tree parse_tree;
+typedef gssize (*PollableInputStreamReadFunc)(GPollableInputStream *stream, void *bufcur, GError **error); PURPLE_ZEPHYR_NONE, /* Non-kerberized ZEPH0.2 */
PURPLE_ZEPHYR_KRB4, /* ZEPH0.2 w/ KRB4 support */
@@ -1115,21 +1117,20 @@
-static parse_tree *read_from_tzc(zephyr_account* zephyr){
+read_from_tzc(zephyr_account *zephyr, PollableInputStreamReadFunc read_func) GPollableInputStream *stream = G_POLLABLE_INPUT_STREAM(zephyr->tzc_stdout);
gchar *buf = g_new(gchar, bufsize);
gboolean selected = FALSE;
- parse_tree *incoming_msg;
- if (g_pollable_input_stream_read_nonblocking(stream, bufcur, 1, NULL,
- if (error->code == G_IO_ERROR_WOULD_BLOCK) {
+ if (read_func(stream, bufcur, &error) < 0) { + if (error->code == G_IO_ERROR_WOULD_BLOCK || + error->code == G_IO_ERROR_TIMED_OUT) { @@ -1153,18 +1154,31 @@
- incoming_msg = parse_buffer(buf,TRUE);
+pollable_input_stream_read(GPollableInputStream *stream, void *bufcur, GError **error) + return g_pollable_input_stream_read_nonblocking(stream, bufcur, 1, NULL, error); static gint check_notify_tzc(gpointer data)
PurpleConnection *gc = (PurpleConnection *)data;
zephyr_account* zephyr = purple_connection_get_protocol_data(gc);
- parse_tree *newparsetree = read_from_tzc(zephyr);
+ parse_tree *newparsetree = NULL; + gchar *buf = read_from_tzc(zephyr, pollable_input_stream_read); + newparsetree = parse_buffer(buf, TRUE); if (newparsetree != NULL) {
if ( (spewtype = tree_child(find_node(newparsetree,"tzcspew"),2)->contents) ) {
@@ -1603,9 +1617,9 @@
pollable_input_stream_read_with_timeout(GPollableInputStream *stream,
- void *bufcur, gint64 timeout,
+ void *bufcur, GError **error) + const gint64 timeout = 10 * G_USEC_PER_SEC; gint64 now = g_get_monotonic_time();
while (g_get_monotonic_time() < now + timeout) {
@@ -1670,8 +1684,6 @@
gboolean found_ps = FALSE;
gchar **tzc_cmd_array = NULL;
- GPollableInputStream *stream = NULL;
@@ -1735,42 +1747,12 @@
zephyr->tzc_stdin = g_subprocess_get_stdin_pipe(zephyr->tzc_proc);
zephyr->tzc_stdout = g_subprocess_get_stdout_pipe(zephyr->tzc_proc);
- stream = G_POLLABLE_INPUT_STREAM(zephyr->tzc_stdout);
- buf = g_new(gchar, bufsize);
purple_debug_info("zephyr", "about to read from tzc");
- if (pollable_input_stream_read_with_timeout(
- stream, bufcur, 10 * G_USEC_PER_SEC, &error) < 0) {
- if (error->code == G_IO_ERROR_WOULD_BLOCK ||
- error->code == G_IO_ERROR_TIMED_OUT) {
- purple_debug_error("zephyr", "couldn't read: %s",
- purple_connection_error(gc,
- PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
- if ((bufcur - buf) > (bufsize - 1)) {
- if ((buf = g_realloc(buf, bufsize * 2)) == NULL) {
- bufcur = buf + bufsize;
+ buf = read_from_tzc(zephyr, pollable_input_stream_read_with_timeout);
+ bufcur = buf + strlen(buf); /* ignore all tzcoutput till we've received the first (*/