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