Mon, 22 Aug 2022 21:40:04 -0500
Inline pidgin_make_scrollable
We need to change it for GTK4, and there are few enough that it can be inlined. Eventually, that code might be a `.ui` anyway.
Testing Done:
Compile only.
Reviewed at https://reviews.imfreedom.org/r/1615/
| 2086 | 1 | /* This file is part of the Project Athena Zephyr Notification System. |
| 2 | * It contains source for the internal Zephyr routines. | |
| 3 | * | |
| 4 | * Created by: Robert French | |
| 5 | * | |
| 6 | * Copyright (c) 1987,1988,1991 by the Massachusetts Institute of | |
| 7 | * Technology. | |
| 8 | * For copying and distribution information, see the file | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
9 | * "mit-copyright.h". |
| 2086 | 10 | */ |
| 11 | ||
|
40643
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
12 | #include <purple.h> |
|
40756
3a58ef28ee44
Implement mitigation for GHSL-2021-045
Gary Kramlich <grim@reaperworld.com>
parents:
40653
diff
changeset
|
13 | #include "libpurple/glibcompat.h" |
|
40643
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
14 | |
|
8792
b0645c9dc276
[gaim-migrate @ 9554]
Christian Hammond <chipx86@chipx86.com>
parents:
7475
diff
changeset
|
15 | #include "internal.h" |
| 10867 | 16 | #ifdef WIN32 |
| 17 | #include <winsock2.h> | |
| 18 | #else | |
| 2086 | 19 | #include <arpa/inet.h> |
| 20 | #include <sys/socket.h> | |
| 10867 | 21 | #endif |
| 2086 | 22 | |
|
40643
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
23 | GSocket *__Zephyr_socket = NULL; |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
24 | gint __Zephyr_port = -1; |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
25 | guint32 __My_addr; |
| 2086 | 26 | int __Q_CompleteLength; |
| 27 | int __Q_Size; | |
|
40628
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
28 | GQueue Z_input_queue = G_QUEUE_INIT; |
|
40643
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
29 | GSocketAddress *__HM_addr; |
| 2086 | 30 | ZLocations_t *__locate_list; |
| 31 | int __locate_num; | |
| 32 | int __locate_next; | |
| 33 | ZSubscription_t *__subscriptions_list; | |
| 34 | int __subscriptions_num; | |
| 35 | int __subscriptions_next; | |
| 2419 | 36 | int Z_discarded_packets = 0; |
| 2086 | 37 | |
| 38 | #ifdef ZEPHYR_USES_KERBEROS | |
| 39 | C_Block __Zephyr_session; | |
| 2419 | 40 | #endif |
| 2086 | 41 | char __Zephyr_realm[REALM_SZ]; |
| 42 | ||
|
39829
ce056c64e426
zephyr: Remove support for compilers without __STDC__.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39828
diff
changeset
|
43 | static int Z_AddField(char **ptr, const char *field, char *end); |
|
ce056c64e426
zephyr: Remove support for compilers without __STDC__.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39828
diff
changeset
|
44 | static int find_or_insert_uid(ZUnique_Id_t *uid, ZNotice_Kind_t kind); |
| 2086 | 45 | |
| 46 | /* Find or insert uid in the old uids buffer. The buffer is a sorted | |
| 47 | * circular queue. We make the assumption that most packets arrive in | |
| 48 | * order, so we can usually search for a uid or insert it into the buffer | |
| 49 | * by looking back just a few entries from the end. Since this code is | |
| 50 | * only executed by the client, the implementation isn't microoptimized. */ | |
|
40166
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
51 | static int |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
52 | find_or_insert_uid(ZUnique_Id_t *uid, ZNotice_Kind_t kind) |
| 2086 | 53 | { |
| 54 | static struct _filter { | |
| 55 | ZUnique_Id_t uid; | |
| 56 | ZNotice_Kind_t kind; | |
| 57 | time_t t; | |
| 58 | } *buffer; | |
| 59 | static long size; | |
| 60 | static long start; | |
| 61 | static long num; | |
| 62 | ||
| 63 | time_t now; | |
| 64 | struct _filter *new; | |
| 65 | long i, j, new_size; | |
| 66 | int result; | |
| 67 | ||
| 68 | /* Initialize the uid buffer if it hasn't been done already. */ | |
| 69 | if (!buffer) { | |
| 70 | size = Z_INITFILTERSIZE; | |
| 71 | buffer = (struct _filter *) malloc(size * sizeof(*buffer)); | |
| 72 | if (!buffer) | |
| 73 | return 0; | |
| 74 | } | |
| 75 | ||
| 76 | /* Age the uid buffer, discarding any uids older than the clock skew. */ | |
| 77 | time(&now); | |
| 78 | while (num && (now - buffer[start % size].t) > CLOCK_SKEW) | |
| 79 | start++, num--; | |
| 80 | start %= size; | |
| 81 | ||
| 82 | /* Make room for a new uid, since we'll probably have to insert one. */ | |
| 83 | if (num == size) { | |
| 84 | new_size = size * 2 + 2; | |
| 85 | new = (struct _filter *) malloc(new_size * sizeof(*new)); | |
| 86 | if (!new) | |
| 87 | return 0; | |
| 88 | for (i = 0; i < num; i++) | |
| 89 | new[i] = buffer[(start + i) % size]; | |
| 90 | free(buffer); | |
| 91 | buffer = new; | |
| 92 | size = new_size; | |
| 93 | start = 0; | |
| 94 | } | |
| 95 | ||
| 96 | /* Search for this uid in the buffer, starting from the end. */ | |
| 97 | for (i = start + num - 1; i >= start; i--) { | |
| 98 | result = memcmp(uid, &buffer[i % size].uid, sizeof(*uid)); | |
| 99 | if (result == 0 && buffer[i % size].kind == kind) | |
| 100 | return 1; | |
| 101 | if (result > 0) | |
| 102 | break; | |
| 103 | } | |
| 104 | ||
| 105 | /* We didn't find it; insert the uid into the buffer after i. */ | |
| 106 | i++; | |
| 107 | for (j = start + num; j > i; j--) | |
| 108 | buffer[j % size] = buffer[(j - 1) % size]; | |
| 109 | buffer[i % size].uid = *uid; | |
| 110 | buffer[i % size].kind = kind; | |
| 111 | buffer[i % size].t = now; | |
| 112 | num++; | |
| 113 | ||
| 114 | return 0; | |
| 115 | } | |
| 116 | ||
| 117 | /* Wait for a complete notice to become available */ | |
| 118 | ||
|
22104
56970903b8e9
Probe for -Wstrict-prototypes to get some more warnings. I then cleaned up
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
119 | Code_t Z_WaitForComplete(void) |
| 2086 | 120 | { |
| 121 | Code_t retval; | |
| 122 | ||
| 123 | if (__Q_CompleteLength) | |
| 124 | return (Z_ReadEnqueue()); | |
| 125 | ||
| 126 | while (!__Q_CompleteLength) | |
| 127 | if ((retval = Z_ReadWait()) != ZERR_NONE) | |
| 128 | return (retval); | |
| 129 | ||
| 130 | return (ZERR_NONE); | |
| 131 | } | |
| 132 | ||
| 133 | ||
| 134 | /* Read any available packets and enqueue them */ | |
| 135 | ||
|
40166
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
136 | Code_t |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
137 | Z_ReadEnqueue(void) |
| 2086 | 138 | { |
|
40643
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
139 | if (ZGetSocket() == NULL) { |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
140 | return ZERR_NOPORT; |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
141 | } |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
142 | |
|
40643
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
143 | while (g_socket_condition_check(ZGetSocket(), G_IO_IN)) { |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
144 | Code_t retval = Z_ReadWait(); |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
145 | if (retval != ZERR_NONE) { |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
146 | return retval; |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
147 | } |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
148 | } |
| 2086 | 149 | |
|
40643
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
150 | return ZERR_NONE; |
| 2086 | 151 | } |
| 152 | ||
| 153 | ||
| 154 | /* | |
| 155 | * Search the queue for a notice with the proper multiuid - remove any | |
| 156 | * notices that haven't been touched in a while | |
| 157 | */ | |
| 158 | ||
|
40628
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
159 | static Z_InputQ * |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
160 | Z_SearchQueue(ZUnique_Id_t *uid, ZNotice_Kind_t kind) |
| 2086 | 161 | { |
|
40628
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
162 | register GList *list; |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
163 | GList *next; |
|
40623
6260f39c7c65
zephyr: Replace gettimeofday by GLib functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40166
diff
changeset
|
164 | gint64 now; |
| 2086 | 165 | |
|
40623
6260f39c7c65
zephyr: Replace gettimeofday by GLib functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40166
diff
changeset
|
166 | now = g_get_monotonic_time(); |
| 2086 | 167 | |
|
40628
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
168 | list = Z_input_queue.head; |
| 2086 | 169 | |
|
40628
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
170 | while (list) { |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
171 | Z_InputQ *qptr = (Z_InputQ *)list->data; |
|
40623
6260f39c7c65
zephyr: Replace gettimeofday by GLib functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40166
diff
changeset
|
172 | if (ZCompareUID(uid, &qptr->uid) && qptr->kind == kind) { |
|
6260f39c7c65
zephyr: Replace gettimeofday by GLib functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40166
diff
changeset
|
173 | return qptr; |
|
6260f39c7c65
zephyr: Replace gettimeofday by GLib functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40166
diff
changeset
|
174 | } |
|
40628
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
175 | next = list->next; |
|
40623
6260f39c7c65
zephyr: Replace gettimeofday by GLib functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40166
diff
changeset
|
176 | if (qptr->time && qptr->time + Z_NOTICETIMELIMIT < now) { |
|
6260f39c7c65
zephyr: Replace gettimeofday by GLib functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40166
diff
changeset
|
177 | Z_RemQueue(qptr); |
|
6260f39c7c65
zephyr: Replace gettimeofday by GLib functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40166
diff
changeset
|
178 | } |
|
40628
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
179 | list = next; |
|
40623
6260f39c7c65
zephyr: Replace gettimeofday by GLib functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40166
diff
changeset
|
180 | } |
|
6260f39c7c65
zephyr: Replace gettimeofday by GLib functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40166
diff
changeset
|
181 | return NULL; |
| 2086 | 182 | } |
| 183 | ||
| 184 | /* | |
| 185 | * Now we delve into really convoluted queue handling and | |
| 186 | * fragmentation reassembly algorithms and other stuff you probably | |
| 187 | * don't want to look at... | |
| 188 | * | |
| 189 | * This routine does NOT guarantee a complete packet will be ready when it | |
| 190 | * returns. | |
| 191 | */ | |
| 192 | ||
|
40166
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
193 | Code_t |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
194 | Z_ReadWait(void) |
| 2086 | 195 | { |
|
40628
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
196 | register Z_InputQ *qptr; |
|
40625
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
197 | Z_Hole *hole = NULL; |
| 2086 | 198 | ZNotice_t notice; |
| 199 | ZPacket_t packet; | |
|
40643
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
200 | GSocketAddress *from = NULL; |
|
11318
13fa1d5134f3
[gaim-migrate @ 13521]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11105
diff
changeset
|
201 | int packet_len, zvlen, part, partof; |
| 2086 | 202 | char *slash; |
| 203 | Code_t retval; | |
|
40643
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
204 | GError *error = NULL; |
| 2086 | 205 | |
|
40643
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
206 | if (ZGetSocket() == NULL) { |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
207 | return ZERR_NOPORT; |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
208 | } |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
209 | |
|
40643
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
210 | if (!g_socket_condition_timed_wait(ZGetSocket(), G_IO_IN, |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
211 | 60 * G_USEC_PER_SEC, NULL, &error)) { |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
212 | gint ret = ZERR_INTERNAL; |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
213 | if (error->code == G_IO_ERROR_TIMED_OUT) { |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
214 | ret = ETIMEDOUT; |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
215 | } |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
216 | g_error_free(error); |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
217 | return ret; |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
218 | } |
| 2086 | 219 | |
|
40643
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
220 | packet_len = g_socket_receive_from(ZGetSocket(), &from, packet, |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
221 | sizeof(packet) - 1, NULL, &error); |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
222 | if (packet_len < 0) { |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
223 | purple_debug_error("zephyr", "Unable to receive from socket: %s", |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
224 | error->message); |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
225 | g_error_free(error); |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
226 | return ZERR_INTERNAL; |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
227 | } |
| 2086 | 228 | |
|
40643
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
229 | if (packet_len == 0) { |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
230 | return ZERR_EOF; |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
231 | } |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
232 | |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
233 | packet[packet_len] = '\0'; |
|
35992
34a67264df99
Fix some CWE-476 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
32016
diff
changeset
|
234 | |
|
40643
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
235 | /* Ignore obviously non-Zephyr packets. */ |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
236 | zvlen = sizeof(ZVERSIONHDR) - 1; |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
237 | if (packet_len < zvlen || memcmp(packet, ZVERSIONHDR, zvlen) != 0) { |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
238 | Z_discarded_packets++; |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
239 | g_object_unref(from); |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
240 | return ZERR_NONE; |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
241 | } |
| 2086 | 242 | |
|
40624
6f7bbd42d36c
Delete a bunch of unused zephyr stuff
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40623
diff
changeset
|
243 | /* Parse the notice */ |
|
6f7bbd42d36c
Delete a bunch of unused zephyr stuff
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40623
diff
changeset
|
244 | if ((retval = ZParseNotice(packet, packet_len, ¬ice)) != ZERR_NONE) { |
|
40643
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
245 | g_object_unref(from); |
|
40624
6f7bbd42d36c
Delete a bunch of unused zephyr stuff
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40623
diff
changeset
|
246 | return retval; |
|
6f7bbd42d36c
Delete a bunch of unused zephyr stuff
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40623
diff
changeset
|
247 | } |
| 2086 | 248 | |
|
40624
6f7bbd42d36c
Delete a bunch of unused zephyr stuff
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40623
diff
changeset
|
249 | /* If the notice is of an appropriate kind, send back a CLIENTACK to |
|
6f7bbd42d36c
Delete a bunch of unused zephyr stuff
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40623
diff
changeset
|
250 | * whoever sent it to say we got it. */ |
| 2086 | 251 | if (notice.z_kind != HMACK && notice.z_kind != SERVACK && |
|
40624
6f7bbd42d36c
Delete a bunch of unused zephyr stuff
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40623
diff
changeset
|
252 | notice.z_kind != SERVNAK && notice.z_kind != CLIENTACK) { |
|
40643
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
253 | GSocketAddress *olddest = NULL; |
|
40624
6f7bbd42d36c
Delete a bunch of unused zephyr stuff
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40623
diff
changeset
|
254 | ZNotice_t tmpnotice; |
|
6f7bbd42d36c
Delete a bunch of unused zephyr stuff
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40623
diff
changeset
|
255 | ZPacket_t pkt; |
|
6f7bbd42d36c
Delete a bunch of unused zephyr stuff
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40623
diff
changeset
|
256 | int len; |
| 2086 | 257 | |
|
40624
6f7bbd42d36c
Delete a bunch of unused zephyr stuff
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40623
diff
changeset
|
258 | tmpnotice = notice; |
|
6f7bbd42d36c
Delete a bunch of unused zephyr stuff
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40623
diff
changeset
|
259 | tmpnotice.z_kind = CLIENTACK; |
|
6f7bbd42d36c
Delete a bunch of unused zephyr stuff
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40623
diff
changeset
|
260 | tmpnotice.z_message_len = 0; |
|
6f7bbd42d36c
Delete a bunch of unused zephyr stuff
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40623
diff
changeset
|
261 | olddest = __HM_addr; |
|
6f7bbd42d36c
Delete a bunch of unused zephyr stuff
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40623
diff
changeset
|
262 | __HM_addr = from; |
|
6f7bbd42d36c
Delete a bunch of unused zephyr stuff
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40623
diff
changeset
|
263 | if ((retval = ZFormatSmallRawNotice(&tmpnotice, pkt, &len)) != ZERR_NONE) { |
|
40643
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
264 | __HM_addr = olddest; |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
265 | g_object_unref(from); |
|
40624
6f7bbd42d36c
Delete a bunch of unused zephyr stuff
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40623
diff
changeset
|
266 | return retval; |
|
6f7bbd42d36c
Delete a bunch of unused zephyr stuff
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40623
diff
changeset
|
267 | } |
|
6f7bbd42d36c
Delete a bunch of unused zephyr stuff
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40623
diff
changeset
|
268 | if ((retval = ZSendPacket(pkt, len, 0)) != ZERR_NONE) { |
|
40643
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
269 | __HM_addr = olddest; |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
270 | g_object_unref(from); |
|
40624
6f7bbd42d36c
Delete a bunch of unused zephyr stuff
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40623
diff
changeset
|
271 | return retval; |
|
6f7bbd42d36c
Delete a bunch of unused zephyr stuff
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40623
diff
changeset
|
272 | } |
|
6f7bbd42d36c
Delete a bunch of unused zephyr stuff
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40623
diff
changeset
|
273 | __HM_addr = olddest; |
| 2086 | 274 | } |
|
40624
6f7bbd42d36c
Delete a bunch of unused zephyr stuff
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40623
diff
changeset
|
275 | if (find_or_insert_uid(¬ice.z_uid, notice.z_kind)) { |
|
40643
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
276 | g_object_unref(from); |
|
40624
6f7bbd42d36c
Delete a bunch of unused zephyr stuff
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40623
diff
changeset
|
277 | return ZERR_NONE; |
|
6f7bbd42d36c
Delete a bunch of unused zephyr stuff
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40623
diff
changeset
|
278 | } |
| 2086 | 279 | |
| 280 | /* Check authentication on the notice. */ | |
|
40643
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
281 | notice.z_checked_auth = ZCheckAuthentication(¬ice); |
| 2086 | 282 | |
| 283 | /* | |
| 284 | * Parse apart the z_multinotice field - if the field is blank for | |
| 285 | * some reason, assume this packet stands by itself. | |
| 286 | */ | |
| 287 | slash = strchr(notice.z_multinotice, '/'); | |
| 288 | if (slash) { | |
| 289 | part = atoi(notice.z_multinotice); | |
| 290 | partof = atoi(slash+1); | |
| 291 | if (part > partof || partof == 0) { | |
| 292 | part = 0; | |
| 293 | partof = notice.z_message_len; | |
| 294 | } | |
| 295 | } | |
| 296 | else { | |
| 297 | part = 0; | |
| 298 | partof = notice.z_message_len; | |
| 299 | } | |
| 300 | ||
|
40643
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
301 | /* Too big a packet...just ignore it! */ |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
302 | if (partof > Z_MAXNOTICESIZE) { |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
303 | g_object_unref(from); |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
304 | return ZERR_NONE; |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
305 | } |
| 2086 | 306 | |
|
40624
6f7bbd42d36c
Delete a bunch of unused zephyr stuff
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40623
diff
changeset
|
307 | /* If we can find a notice in the queue with the same multiuid field, |
|
6f7bbd42d36c
Delete a bunch of unused zephyr stuff
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40623
diff
changeset
|
308 | * insert the current fragment as appropriate. */ |
| 2086 | 309 | switch (notice.z_kind) { |
| 310 | case SERVACK: | |
| 311 | case SERVNAK: | |
| 312 | /* The SERVACK and SERVNAK replies shouldn't be reassembled | |
| 313 | (they have no parts). Instead, we should hold on to the reply | |
| 314 | ONLY if it's the first part of a fragmented message, i.e. | |
| 315 | multi_uid == uid. This allows programs to wait for the uid | |
| 316 | of the first packet, and get a response when that notice | |
| 317 | arrives. Acknowledgements of the other fragments are discarded | |
| 318 | (XXX we assume here that they all carry the same information | |
| 319 | regarding failure/success) | |
| 320 | */ | |
|
40624
6f7bbd42d36c
Delete a bunch of unused zephyr stuff
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40623
diff
changeset
|
321 | if (!ZCompareUID(¬ice.z_multiuid, ¬ice.z_uid)) { |
|
40643
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
322 | /* they're not the same... throw away this packet. */ |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
323 | g_object_unref(from); |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
324 | return ZERR_NONE; |
|
40624
6f7bbd42d36c
Delete a bunch of unused zephyr stuff
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40623
diff
changeset
|
325 | } |
| 2086 | 326 | /* fall thru & process it */ |
| 327 | default: | |
| 328 | /* for HMACK types, we assume no packet loss (local loopback | |
| 329 | connections). The other types can be fragmented and MUST | |
| 330 | run through this code. */ | |
|
40624
6f7bbd42d36c
Delete a bunch of unused zephyr stuff
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40623
diff
changeset
|
331 | if ((qptr = Z_SearchQueue(¬ice.z_multiuid, notice.z_kind)) != NULL) { |
|
40628
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
332 | /* If this is the first fragment, and we haven't already gotten |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
333 | * a first fragment, grab the header from it. */ |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
334 | if (part == 0 && qptr->header == NULL) { |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
335 | qptr->header_len = packet_len - notice.z_message_len; |
|
40756
3a58ef28ee44
Implement mitigation for GHSL-2021-045
Gary Kramlich <grim@reaperworld.com>
parents:
40653
diff
changeset
|
336 | qptr->header = g_memdup2(packet, qptr->header_len); |
|
40628
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
337 | } |
|
40643
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
338 | g_object_unref(from); |
|
40628
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
339 | return Z_AddNoticeToEntry(qptr, ¬ice, part); |
| 2086 | 340 | } |
| 341 | } | |
| 342 | ||
|
40624
6f7bbd42d36c
Delete a bunch of unused zephyr stuff
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40623
diff
changeset
|
343 | /* We'll have to create a new entry...make sure the queue isn't going |
|
6f7bbd42d36c
Delete a bunch of unused zephyr stuff
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40623
diff
changeset
|
344 | * to get too big. */ |
|
6f7bbd42d36c
Delete a bunch of unused zephyr stuff
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40623
diff
changeset
|
345 | if (__Q_Size + partof > Z_MAXQUEUESIZE) { |
|
40643
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
346 | g_object_unref(from); |
|
40624
6f7bbd42d36c
Delete a bunch of unused zephyr stuff
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40623
diff
changeset
|
347 | return ZERR_NONE; |
|
6f7bbd42d36c
Delete a bunch of unused zephyr stuff
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40623
diff
changeset
|
348 | } |
| 2086 | 349 | |
|
40628
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
350 | /* This is a notice we haven't heard of, so create a new queue entry |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
351 | * for it and zero it out. */ |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
352 | qptr = g_new0(Z_InputQ, 1); |
| 2086 | 353 | |
|
40628
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
354 | /* Insert the entry at the end of the queue */ |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
355 | g_queue_push_tail(&Z_input_queue, qptr); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
356 | |
|
40643
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
357 | /* Copy the from field, multiuid, kind, and checked authentication. */ |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
358 | qptr->from = from; |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
359 | qptr->uid = notice.z_multiuid; |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
360 | qptr->kind = notice.z_kind; |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
361 | qptr->auth = notice.z_checked_auth; |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
362 | |
|
40628
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
363 | /* If this is the first part of the notice, we take the header from it. |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
364 | * We only take it if this is the first fragment so that the Unique |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
365 | * ID's will be predictable. */ |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
366 | if (part == 0) { |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
367 | qptr->header_len = packet_len - notice.z_message_len; |
|
40756
3a58ef28ee44
Implement mitigation for GHSL-2021-045
Gary Kramlich <grim@reaperworld.com>
parents:
40653
diff
changeset
|
368 | qptr->header = g_memdup2(packet, qptr->header_len); |
|
40628
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
369 | } |
| 2086 | 370 | |
|
40628
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
371 | /* If this is not a fragmented notice, then don't bother with a hole |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
372 | * list. */ |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
373 | if (part == 0 && notice.z_message_len == partof) { |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
374 | __Q_CompleteLength++; |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
375 | qptr->holelist = NULL; |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
376 | qptr->complete = TRUE; |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
377 | /* allocate a msg buf for this piece */ |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
378 | if (notice.z_message_len == 0) { |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
379 | qptr->msg = NULL; |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
380 | } else { |
|
40756
3a58ef28ee44
Implement mitigation for GHSL-2021-045
Gary Kramlich <grim@reaperworld.com>
parents:
40653
diff
changeset
|
381 | qptr->msg = g_memdup2(notice.z_message, notice.z_message_len); |
|
40628
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
382 | } |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
383 | qptr->msg_len = notice.z_message_len; |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
384 | __Q_Size += notice.z_message_len; |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
385 | qptr->packet_len = qptr->header_len + qptr->msg_len; |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
386 | qptr->packet = g_new(gchar, qptr->packet_len); |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
387 | memcpy(qptr->packet, qptr->header, qptr->header_len); |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
388 | if (qptr->msg) { |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
389 | memcpy(qptr->packet + qptr->header_len, qptr->msg, qptr->msg_len); |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
390 | } |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
391 | return ZERR_NONE; |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
392 | } |
| 2086 | 393 | |
|
40628
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
394 | /* We know how long the message is going to be (this is better than IP |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
395 | * fragmentation...), so go ahead and allocate it all. */ |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
396 | qptr->msg = g_new0(gchar, partof); |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
397 | qptr->msg_len = partof; |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
398 | __Q_Size += partof; |
| 2086 | 399 | |
|
40625
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
400 | /* |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
401 | * Well, it's a fragmented notice...allocate a hole list and |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
402 | * initialize it to the full packet size. Then insert the |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
403 | * current fragment. |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
404 | */ |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
405 | hole = g_new0(Z_Hole, 1); |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
406 | if (hole == NULL) { |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
407 | return ENOMEM; |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
408 | } |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
409 | hole->first = 0; |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
410 | hole->last = partof - 1; |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
411 | qptr->holelist = g_slist_prepend(qptr->holelist, hole); |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
412 | return Z_AddNoticeToEntry(qptr, ¬ice, part); |
| 2086 | 413 | } |
| 414 | ||
| 415 | ||
| 416 | /* Fragment management routines - compliments, more or less, of RFC815 */ | |
| 417 | ||
|
40625
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
418 | static gint |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
419 | find_hole(gconstpointer element, gconstpointer data) |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
420 | { |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
421 | Z_Hole *thishole = (Z_Hole *)element; |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
422 | Z_Hole *tofind = (Z_Hole *)data; |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
423 | |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
424 | if (tofind->first <= thishole->last && tofind->last >= thishole->first) { |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
425 | return 0; |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
426 | } |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
427 | |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
428 | return 1; |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
429 | } |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
430 | |
|
40166
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
431 | Code_t |
|
40628
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
432 | Z_AddNoticeToEntry(Z_InputQ *qptr, ZNotice_t *notice, int part) |
| 2086 | 433 | { |
|
40625
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
434 | GSList *thishole; |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
435 | Z_Hole *hole; |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
436 | gint last; |
| 2086 | 437 | |
|
40623
6260f39c7c65
zephyr: Replace gettimeofday by GLib functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40166
diff
changeset
|
438 | /* Incorporate this notice's checked authentication. */ |
|
6260f39c7c65
zephyr: Replace gettimeofday by GLib functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40166
diff
changeset
|
439 | if (notice->z_checked_auth == ZAUTH_FAILED) { |
|
6260f39c7c65
zephyr: Replace gettimeofday by GLib functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40166
diff
changeset
|
440 | qptr->auth = ZAUTH_FAILED; |
|
6260f39c7c65
zephyr: Replace gettimeofday by GLib functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40166
diff
changeset
|
441 | } else if (notice->z_checked_auth == ZAUTH_NO && qptr->auth != ZAUTH_FAILED) { |
|
6260f39c7c65
zephyr: Replace gettimeofday by GLib functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40166
diff
changeset
|
442 | qptr->auth = ZAUTH_NO; |
|
6260f39c7c65
zephyr: Replace gettimeofday by GLib functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40166
diff
changeset
|
443 | } |
| 2086 | 444 | |
|
40623
6260f39c7c65
zephyr: Replace gettimeofday by GLib functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40166
diff
changeset
|
445 | qptr->time = g_get_monotonic_time(); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
446 | |
|
40625
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
447 | last = part + notice->z_message_len - 1; |
| 2086 | 448 | |
|
40625
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
449 | /* copy in the message body */ |
|
40628
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
450 | memcpy(qptr->msg + part, notice->z_message, notice->z_message_len); |
| 2086 | 451 | |
|
40625
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
452 | /* Search for a hole that overlaps with the current fragment */ |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
453 | hole = g_new(Z_Hole, 1); |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
454 | hole->first = part; |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
455 | hole->last = last; |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
456 | thishole = g_slist_find_custom(qptr->holelist, hole, find_hole); |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
457 | g_free(hole); |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
458 | |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
459 | /* If we found one, delete it and reconstruct a new hole */ |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
460 | if (thishole) { |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
461 | gint oldfirst, oldlast; |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
462 | |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
463 | hole = (Z_Hole *)thishole->data; |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
464 | oldfirst = hole->first; |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
465 | oldlast = hole->last; |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
466 | qptr->holelist = g_slist_delete_link(qptr->holelist, thishole); |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
467 | g_free(hole); |
| 2086 | 468 | |
|
40625
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
469 | /* |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
470 | * Now create a new hole that is the original hole without the |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
471 | * current fragment. |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
472 | */ |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
473 | if (part > oldfirst) { |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
474 | hole = g_new0(Z_Hole, 1); |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
475 | qptr->holelist = g_slist_prepend(qptr->holelist, hole); |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
476 | hole->first = oldfirst; |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
477 | hole->last = part - 1; |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
478 | } |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
479 | if (last < oldlast) { |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
480 | hole = g_new0(Z_Hole, 1); |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
481 | qptr->holelist = g_slist_prepend(qptr->holelist, hole); |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
482 | hole->first = last + 1; |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
483 | hole->last = oldlast; |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
484 | } |
| 2086 | 485 | } |
|
40625
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
486 | |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
487 | /* If there are no more holes, the packet is complete. */ |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
488 | if (qptr->holelist == NULL) { |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
489 | if (!qptr->complete) { |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
490 | __Q_CompleteLength++; |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
491 | } |
|
40628
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
492 | qptr->complete = TRUE; |
|
40625
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
493 | qptr->time = 0; /* don't time out anymore */ |
|
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
494 | qptr->packet_len = qptr->header_len + qptr->msg_len; |
|
40628
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
495 | qptr->packet = g_new(gchar, qptr->packet_len); |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
496 | memcpy(qptr->packet, qptr->header, qptr->header_len); |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
497 | memcpy(qptr->packet + qptr->header_len, qptr->msg, qptr->msg_len); |
| 2086 | 498 | } |
| 499 | ||
|
40625
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
500 | return ZERR_NONE; |
| 2086 | 501 | } |
| 502 | ||
|
40166
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
503 | Code_t |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
504 | Z_FormatHeader(ZNotice_t *notice, char *buffer, int buffer_len, int *len, |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
505 | Z_AuthProc cert_routine) |
| 2086 | 506 | { |
|
40643
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
507 | static char version[BUFSIZ]; /* default init should be all \0 */ |
|
40623
6260f39c7c65
zephyr: Replace gettimeofday by GLib functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40166
diff
changeset
|
508 | gint64 realtime; |
| 2086 | 509 | |
|
40643
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
510 | if (!notice->z_sender) { |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
511 | notice->z_sender = ZGetSender(); |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
512 | } |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
513 | |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
514 | if (notice->z_port == 0) { |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
515 | GSocketAddress *addr = NULL; |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
516 | GError *error = NULL; |
| 2086 | 517 | |
|
40643
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
518 | if (ZGetSocket() == NULL) { |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
519 | Code_t retval = ZOpenPort(NULL); |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
520 | if (retval != ZERR_NONE) { |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
521 | return retval; |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
522 | } |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
523 | } |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
524 | |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
525 | addr = g_socket_get_local_address(ZGetSocket(), &error); |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
526 | if (addr == NULL) { |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
527 | purple_debug_error("zephyr", |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
528 | "Unable to determine socket local address: %s", |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
529 | error->message); |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
530 | g_error_free(error); |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
531 | return ZERR_INTERNAL; |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
532 | } |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
533 | notice->z_port = |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
534 | g_inet_socket_address_get_port(G_INET_SOCKET_ADDRESS(addr)); |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
535 | g_object_unref(addr); |
| 2086 | 536 | } |
| 537 | ||
|
40643
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
538 | notice->z_multinotice = ""; |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
539 | |
|
40623
6260f39c7c65
zephyr: Replace gettimeofday by GLib functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40166
diff
changeset
|
540 | realtime = g_get_real_time(); |
|
6260f39c7c65
zephyr: Replace gettimeofday by GLib functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40166
diff
changeset
|
541 | notice->z_uid.tv.tv_sec = realtime / G_USEC_PER_SEC; |
|
6260f39c7c65
zephyr: Replace gettimeofday by GLib functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40166
diff
changeset
|
542 | notice->z_uid.tv.tv_usec = |
|
6260f39c7c65
zephyr: Replace gettimeofday by GLib functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40166
diff
changeset
|
543 | realtime - notice->z_uid.tv.tv_sec * G_USEC_PER_SEC; |
|
40653
503cfa50c8c3
Use GLib's byte-order macros.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40643
diff
changeset
|
544 | notice->z_uid.tv.tv_sec = GUINT64_TO_BE((guint64)notice->z_uid.tv.tv_sec); |
|
503cfa50c8c3
Use GLib's byte-order macros.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40643
diff
changeset
|
545 | notice->z_uid.tv.tv_usec = GUINT64_TO_BE((guint64)notice->z_uid.tv.tv_usec); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
546 | |
|
40628
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
547 | memcpy(¬ice->z_uid.zuid_addr, &__My_addr, sizeof(__My_addr)); |
| 2086 | 548 | |
|
40643
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
549 | notice->z_multiuid = notice->z_uid; |
| 2086 | 550 | |
|
40643
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
551 | if (!version[0]) { |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
552 | sprintf(version, "%s%d.%d", ZVERSIONHDR, ZVERSIONMAJOR, ZVERSIONMINOR); |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
553 | } |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
554 | notice->z_version = version; |
| 2086 | 555 | |
|
40643
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
556 | return Z_FormatAuthHeader(notice, buffer, buffer_len, len, cert_routine); |
| 2086 | 557 | } |
| 558 | ||
|
40166
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
559 | Code_t |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
560 | Z_FormatAuthHeader(ZNotice_t *notice, char *buffer, int buffer_len, int *len, |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
561 | Z_AuthProc cert_routine) |
| 2086 | 562 | { |
| 563 | if (!cert_routine) { | |
| 564 | notice->z_auth = 0; | |
| 565 | notice->z_authent_len = 0; | |
| 566 | notice->z_ascii_authent = ""; | |
| 567 | notice->z_checksum = 0; | |
| 568 | return (Z_FormatRawHeader(notice, buffer, buffer_len, | |
| 569 | len, NULL, NULL)); | |
| 570 | } | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
571 | |
| 2086 | 572 | return ((*cert_routine)(notice, buffer, buffer_len, len)); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
573 | } |
|
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
574 | |
|
40166
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
575 | Code_t |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
576 | Z_FormatRawHeader(ZNotice_t *notice, char *buffer, gsize buffer_len, int *len, |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
577 | char **cstart, char **cend) |
| 2086 | 578 | { |
| 579 | char newrecip[BUFSIZ]; | |
| 580 | char *ptr, *end; | |
| 581 | int i; | |
| 582 | ||
| 583 | if (!notice->z_class) | |
| 584 | notice->z_class = ""; | |
| 585 | ||
| 586 | if (!notice->z_class_inst) | |
| 587 | notice->z_class_inst = ""; | |
| 588 | ||
| 589 | if (!notice->z_opcode) | |
| 590 | notice->z_opcode = ""; | |
| 591 | ||
| 592 | if (!notice->z_recipient) | |
| 593 | notice->z_recipient = ""; | |
| 594 | ||
| 595 | if (!notice->z_default_format) | |
| 596 | notice->z_default_format = ""; | |
| 597 | ||
| 598 | ptr = buffer; | |
| 599 | end = buffer+buffer_len; | |
| 600 | ||
| 601 | if (buffer_len < strlen(notice->z_version)+1) | |
| 602 | return (ZERR_HEADERLEN); | |
| 603 | ||
|
31954
e5631d5590cc
Replace numerous strcpy() invocations with strlcpy() in Zephyr.
Ethan Blanton <elb@pidgin.im>
parents:
31363
diff
changeset
|
604 | g_strlcpy(ptr, notice->z_version, buffer_len); |
| 2086 | 605 | ptr += strlen(ptr)+1; |
| 606 | ||
| 607 | if (ZMakeAscii32(ptr, end-ptr, Z_NUMFIELDS + notice->z_num_other_fields) | |
| 608 | == ZERR_FIELDLEN) | |
| 609 | return (ZERR_HEADERLEN); | |
| 610 | ptr += strlen(ptr)+1; | |
| 611 | ||
| 612 | if (ZMakeAscii32(ptr, end-ptr, notice->z_kind) == ZERR_FIELDLEN) | |
| 613 | return (ZERR_HEADERLEN); | |
| 614 | ptr += strlen(ptr)+1; | |
| 615 | ||
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
616 | if (ZMakeAscii(ptr, end-ptr, (unsigned char *)¬ice->z_uid, |
| 2086 | 617 | sizeof(ZUnique_Id_t)) == ZERR_FIELDLEN) |
| 618 | return (ZERR_HEADERLEN); | |
| 619 | ptr += strlen(ptr)+1; | |
| 620 | ||
|
40653
503cfa50c8c3
Use GLib's byte-order macros.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40643
diff
changeset
|
621 | if (ZMakeAscii16(ptr, end-ptr, g_ntohs(notice->z_port)) == ZERR_FIELDLEN) |
| 2086 | 622 | return (ZERR_HEADERLEN); |
| 623 | ptr += strlen(ptr)+1; | |
| 624 | ||
| 625 | if (ZMakeAscii32(ptr, end-ptr, notice->z_auth) == ZERR_FIELDLEN) | |
| 626 | return (ZERR_HEADERLEN); | |
| 627 | ptr += strlen(ptr)+1; | |
| 628 | ||
| 629 | if (ZMakeAscii32(ptr, end-ptr, notice->z_authent_len) == ZERR_FIELDLEN) | |
| 630 | return (ZERR_HEADERLEN); | |
| 631 | ptr += strlen(ptr)+1; | |
| 632 | ||
| 633 | if (Z_AddField(&ptr, notice->z_ascii_authent, end)) | |
| 634 | return (ZERR_HEADERLEN); | |
| 635 | if (Z_AddField(&ptr, notice->z_class, end)) | |
| 636 | return (ZERR_HEADERLEN); | |
| 637 | if (Z_AddField(&ptr, notice->z_class_inst, end)) | |
| 638 | return (ZERR_HEADERLEN); | |
| 639 | if (Z_AddField(&ptr, notice->z_opcode, end)) | |
| 640 | return (ZERR_HEADERLEN); | |
| 641 | if (Z_AddField(&ptr, notice->z_sender, end)) | |
| 642 | return (ZERR_HEADERLEN); | |
| 643 | if (strchr(notice->z_recipient, '@') || !*notice->z_recipient) { | |
| 644 | if (Z_AddField(&ptr, notice->z_recipient, end)) | |
| 645 | return (ZERR_HEADERLEN); | |
| 646 | } | |
| 647 | else { | |
| 648 | if (strlen(notice->z_recipient) + strlen(__Zephyr_realm) + 2 > | |
| 2419 | 649 | sizeof(newrecip)) |
| 650 | return (ZERR_HEADERLEN); | |
| 2086 | 651 | (void) sprintf(newrecip, "%s@%s", notice->z_recipient, __Zephyr_realm); |
| 652 | if (Z_AddField(&ptr, newrecip, end)) | |
| 653 | return (ZERR_HEADERLEN); | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
654 | } |
| 2086 | 655 | if (Z_AddField(&ptr, notice->z_default_format, end)) |
| 656 | return (ZERR_HEADERLEN); | |
| 657 | ||
| 658 | /* copy back the end pointer location for crypto checksum */ | |
| 659 | if (cstart) | |
| 660 | *cstart = ptr; | |
| 661 | if (ZMakeAscii32(ptr, end-ptr, notice->z_checksum) == ZERR_FIELDLEN) | |
| 662 | return (ZERR_HEADERLEN); | |
| 663 | ptr += strlen(ptr)+1; | |
| 664 | if (cend) | |
| 665 | *cend = ptr; | |
| 666 | ||
| 667 | if (Z_AddField(&ptr, notice->z_multinotice, end)) | |
| 668 | return (ZERR_HEADERLEN); | |
| 669 | ||
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
670 | if (ZMakeAscii(ptr, end-ptr, (unsigned char *)¬ice->z_multiuid, |
| 2086 | 671 | sizeof(ZUnique_Id_t)) == ZERR_FIELDLEN) |
| 672 | return (ZERR_HEADERLEN); | |
| 673 | ptr += strlen(ptr)+1; | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
674 | |
| 2086 | 675 | for (i=0;i<notice->z_num_other_fields;i++) |
| 676 | if (Z_AddField(&ptr, notice->z_other_fields[i], end)) | |
| 677 | return (ZERR_HEADERLEN); | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
678 | |
| 2086 | 679 | *len = ptr-buffer; |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
680 | |
| 2086 | 681 | return (ZERR_NONE); |
| 682 | } | |
| 683 | ||
| 684 | static int | |
| 5136 | 685 | Z_AddField(char **ptr, const char *field, char *end) |
| 2086 | 686 | { |
| 687 | register int len; | |
| 688 | ||
| 689 | len = field ? strlen (field) + 1 : 1; | |
| 690 | ||
| 691 | if (*ptr+len > end) | |
| 692 | return 1; | |
| 693 | if (field) | |
|
32016
b1662f03fa07
Fix some un-fixes in the Zephyr strlcpy changes
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
694 | strcpy(*ptr, field); |
| 2086 | 695 | else |
|
31954
e5631d5590cc
Replace numerous strcpy() invocations with strlcpy() in Zephyr.
Ethan Blanton <elb@pidgin.im>
parents:
31363
diff
changeset
|
696 | **ptr = '\0'; |
| 2086 | 697 | *ptr += len; |
| 698 | ||
| 699 | return 0; | |
| 700 | } | |
| 701 | ||
|
40628
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
702 | static gint |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
703 | find_complete_input(gconstpointer a, G_GNUC_UNUSED gconstpointer b) |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
704 | { |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
705 | Z_InputQ *qptr = (Z_InputQ *)a; |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
706 | return qptr->complete ? 0 : 1; |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
707 | } |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
708 | |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
709 | Z_InputQ * |
|
40166
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
710 | Z_GetFirstComplete(void) |
| 2086 | 711 | { |
|
40628
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
712 | GList *list; |
| 2086 | 713 | |
|
40628
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
714 | list = g_queue_find_custom(&Z_input_queue, NULL, find_complete_input); |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
715 | return list ? (Z_InputQ *)list->data : NULL; |
| 2086 | 716 | } |
| 717 | ||
|
40628
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
718 | Z_InputQ * |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
719 | Z_GetNextComplete(Z_InputQ *qptr) |
| 2086 | 720 | { |
|
40628
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
721 | GList *list = g_queue_find(&Z_input_queue, qptr); |
| 2086 | 722 | |
|
40628
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
723 | if (list) { |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
724 | list = list->next; |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
725 | list = g_list_find_custom(list, NULL, find_complete_input); |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
726 | } |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
727 | |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
728 | return list ? (Z_InputQ *)list->data : NULL; |
| 2086 | 729 | } |
| 730 | ||
|
40166
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
731 | void |
|
40628
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
732 | Z_RemQueue(Z_InputQ *qptr) |
| 2086 | 733 | { |
|
40628
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
734 | if (qptr->complete) { |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
735 | __Q_CompleteLength--; |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
736 | } |
| 2086 | 737 | |
|
40628
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
738 | __Q_Size -= qptr->msg_len; |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
739 | |
|
40628
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
740 | g_free(qptr->header); |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
741 | g_free(qptr->msg); |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
742 | g_free(qptr->packet); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
743 | |
|
40643
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
744 | g_clear_object(&qptr->from); |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
745 | |
|
40625
56e1a1a5af0b
Use a GSList for Zephyr hole list.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40624
diff
changeset
|
746 | g_slist_free_full(qptr->holelist, g_free); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
747 | |
|
40628
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
748 | g_queue_remove(&Z_input_queue, qptr); |
|
4266008a7791
Use a GQueue for zephyr plus related cleanup
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40625
diff
changeset
|
749 | g_free(qptr); |
| 2086 | 750 | } |
| 751 | ||
|
40166
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
752 | Code_t |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
753 | Z_SendFragmentedNotice(ZNotice_t *notice, int len, Z_AuthProc cert_func, |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
754 | Z_SendProc send_func) |
| 2086 | 755 | { |
| 756 | ZNotice_t partnotice; | |
| 757 | ZPacket_t buffer; | |
| 758 | char multi[64]; | |
| 759 | int offset, hdrsize, fragsize, ret_len, message_len, waitforack; | |
| 760 | Code_t retval; | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
761 | |
| 2086 | 762 | hdrsize = len-notice->z_message_len; |
| 763 | fragsize = Z_MAXPKTLEN-hdrsize-Z_FRAGFUDGE; | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
764 | |
| 2086 | 765 | offset = 0; |
| 766 | ||
|
40624
6f7bbd42d36c
Delete a bunch of unused zephyr stuff
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40623
diff
changeset
|
767 | waitforack = (notice->z_kind == UNACKED || notice->z_kind == ACKED); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
768 | |
| 2086 | 769 | partnotice = *notice; |
| 770 | ||
| 771 | while (offset < notice->z_message_len || !notice->z_message_len) { | |
| 772 | (void) sprintf(multi, "%d/%d", offset, notice->z_message_len); | |
| 773 | partnotice.z_multinotice = multi; | |
| 774 | if (offset > 0) { | |
|
40623
6260f39c7c65
zephyr: Replace gettimeofday by GLib functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40166
diff
changeset
|
775 | gint64 realtime = g_get_real_time(); |
|
6260f39c7c65
zephyr: Replace gettimeofday by GLib functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40166
diff
changeset
|
776 | partnotice.z_uid.tv.tv_sec = realtime / G_USEC_PER_SEC; |
|
6260f39c7c65
zephyr: Replace gettimeofday by GLib functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40166
diff
changeset
|
777 | partnotice.z_uid.tv.tv_usec = |
|
6260f39c7c65
zephyr: Replace gettimeofday by GLib functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40166
diff
changeset
|
778 | realtime - partnotice.z_uid.tv.tv_sec * G_USEC_PER_SEC; |
|
6260f39c7c65
zephyr: Replace gettimeofday by GLib functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40166
diff
changeset
|
779 | partnotice.z_uid.tv.tv_sec = |
|
40653
503cfa50c8c3
Use GLib's byte-order macros.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40643
diff
changeset
|
780 | GUINT64_TO_BE((guint64)partnotice.z_uid.tv.tv_sec); |
|
40623
6260f39c7c65
zephyr: Replace gettimeofday by GLib functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40166
diff
changeset
|
781 | partnotice.z_uid.tv.tv_usec = |
|
40653
503cfa50c8c3
Use GLib's byte-order macros.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40643
diff
changeset
|
782 | GUINT64_TO_BE((guint64)partnotice.z_uid.tv.tv_usec); |
|
40643
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40628
diff
changeset
|
783 | memcpy(&partnotice.z_uid.zuid_addr, &__My_addr, sizeof(__My_addr)); |
| 2086 | 784 | } |
|
39828
7372deed606c
zephyr: Use GLib's min/max macros.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
38240
diff
changeset
|
785 | message_len = MIN(notice->z_message_len - offset, fragsize); |
|
15018
7ce510403b58
[gaim-migrate @ 17735]
Luke Schierer <lschiere@pidgin.im>
parents:
14254
diff
changeset
|
786 | partnotice.z_message = (char*)notice->z_message+offset; |
| 2086 | 787 | partnotice.z_message_len = message_len; |
| 788 | if ((retval = Z_FormatAuthHeader(&partnotice, buffer, Z_MAXHEADERLEN, | |
| 789 | &ret_len, cert_func)) != ZERR_NONE) { | |
| 790 | return (retval); | |
| 791 | } | |
| 792 | memcpy(buffer + ret_len, partnotice.z_message, message_len); | |
| 793 | if ((retval = (*send_func)(&partnotice, buffer, ret_len+message_len, | |
| 794 | waitforack)) != ZERR_NONE) { | |
| 795 | return (retval); | |
| 796 | } | |
| 797 | offset += fragsize; | |
| 798 | if (!notice->z_message_len) | |
| 799 | break; | |
| 800 | } | |
| 801 | ||
| 802 | return (ZERR_NONE); | |
| 803 | } | |
| 804 | ||
| 805 | /*ARGSUSED*/ | |
|
40166
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
806 | Code_t |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
807 | Z_XmitFragment(ZNotice_t *notice, char *buf, int len, int wait) |
| 2086 | 808 | { |
| 809 | return(ZSendPacket(buf, len, wait)); | |
| 810 | } |