Thu, 13 Feb 2020 20:57:31 -0600
Move the libidn check to jabber/meson.build as it needs specific functions of the library
| 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 | ||
|
8792
b0645c9dc276
[gaim-migrate @ 9554]
Christian Hammond <chipx86@chipx86.com>
parents:
7475
diff
changeset
|
12 | #include "internal.h" |
| 10867 | 13 | #ifdef WIN32 |
| 14 | #include <winsock2.h> | |
| 15 | ||
| 16 | #ifndef ZEPHYR_USES_KERBEROS | |
| 17 | int gettimeofday(struct timeval* p, struct timezone* tz ){ | |
| 18 | union { | |
| 19 | long long ns100; /*time since 1 Jan 1601 in 100ns units */ | |
| 20 | FILETIME ft; | |
| 21 | } _now; | |
| 22 | ||
| 23 | GetSystemTimeAsFileTime( &(_now.ft) ); | |
| 24 | p->tv_usec=(long)((_now.ns100 / 10LL) % 1000000LL ); | |
| 25 | p->tv_sec= (long)((_now.ns100-(116444736000000000LL))/10000000LL); | |
| 26 | return 0; | |
| 27 | } | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
28 | #endif |
| 10867 | 29 | |
| 30 | #else | |
| 2086 | 31 | #include <arpa/inet.h> |
| 32 | #include <sys/socket.h> | |
| 10867 | 33 | #endif |
| 2086 | 34 | |
| 35 | int __Zephyr_fd = -1; | |
| 36 | int __Zephyr_open; | |
| 37 | int __Zephyr_port = -1; | |
| 2419 | 38 | struct in_addr __My_addr; |
| 2086 | 39 | int __Q_CompleteLength; |
| 40 | int __Q_Size; | |
| 41 | struct _Z_InputQ *__Q_Head, *__Q_Tail; | |
| 42 | struct sockaddr_in __HM_addr; | |
| 43 | struct sockaddr_in __HM_addr_real; | |
| 44 | int __HM_set; | |
| 45 | int __Zephyr_server; | |
| 46 | ZLocations_t *__locate_list; | |
| 47 | int __locate_num; | |
| 48 | int __locate_next; | |
| 49 | ZSubscription_t *__subscriptions_list; | |
| 50 | int __subscriptions_num; | |
| 51 | int __subscriptions_next; | |
| 2419 | 52 | int Z_discarded_packets = 0; |
| 2086 | 53 | |
| 54 | #ifdef ZEPHYR_USES_KERBEROS | |
| 55 | C_Block __Zephyr_session; | |
| 2419 | 56 | #endif |
| 2086 | 57 | char __Zephyr_realm[REALM_SZ]; |
| 58 | ||
| 59 | #ifdef Z_DEBUG | |
|
39829
ce056c64e426
zephyr: Remove support for compilers without __STDC__.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39828
diff
changeset
|
60 | void (*__Z_debug_print)(const char *fmt, va_list args, void *closure); |
| 2086 | 61 | void *__Z_debug_print_closure; |
| 62 | #endif | |
| 63 | ||
|
39829
ce056c64e426
zephyr: Remove support for compilers without __STDC__.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39828
diff
changeset
|
64 | 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
|
65 | static int find_or_insert_uid(ZUnique_Id_t *uid, ZNotice_Kind_t kind); |
| 2086 | 66 | |
| 67 | /* Find or insert uid in the old uids buffer. The buffer is a sorted | |
| 68 | * circular queue. We make the assumption that most packets arrive in | |
| 69 | * order, so we can usually search for a uid or insert it into the buffer | |
| 70 | * by looking back just a few entries from the end. Since this code is | |
| 71 | * 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
|
72 | static int |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
73 | find_or_insert_uid(ZUnique_Id_t *uid, ZNotice_Kind_t kind) |
| 2086 | 74 | { |
| 75 | static struct _filter { | |
| 76 | ZUnique_Id_t uid; | |
| 77 | ZNotice_Kind_t kind; | |
| 78 | time_t t; | |
| 79 | } *buffer; | |
| 80 | static long size; | |
| 81 | static long start; | |
| 82 | static long num; | |
| 83 | ||
| 84 | time_t now; | |
| 85 | struct _filter *new; | |
| 86 | long i, j, new_size; | |
| 87 | int result; | |
| 88 | ||
| 89 | /* Initialize the uid buffer if it hasn't been done already. */ | |
| 90 | if (!buffer) { | |
| 91 | size = Z_INITFILTERSIZE; | |
| 92 | buffer = (struct _filter *) malloc(size * sizeof(*buffer)); | |
| 93 | if (!buffer) | |
| 94 | return 0; | |
| 95 | } | |
| 96 | ||
| 97 | /* Age the uid buffer, discarding any uids older than the clock skew. */ | |
| 98 | time(&now); | |
| 99 | while (num && (now - buffer[start % size].t) > CLOCK_SKEW) | |
| 100 | start++, num--; | |
| 101 | start %= size; | |
| 102 | ||
| 103 | /* Make room for a new uid, since we'll probably have to insert one. */ | |
| 104 | if (num == size) { | |
| 105 | new_size = size * 2 + 2; | |
| 106 | new = (struct _filter *) malloc(new_size * sizeof(*new)); | |
| 107 | if (!new) | |
| 108 | return 0; | |
| 109 | for (i = 0; i < num; i++) | |
| 110 | new[i] = buffer[(start + i) % size]; | |
| 111 | free(buffer); | |
| 112 | buffer = new; | |
| 113 | size = new_size; | |
| 114 | start = 0; | |
| 115 | } | |
| 116 | ||
| 117 | /* Search for this uid in the buffer, starting from the end. */ | |
| 118 | for (i = start + num - 1; i >= start; i--) { | |
| 119 | result = memcmp(uid, &buffer[i % size].uid, sizeof(*uid)); | |
| 120 | if (result == 0 && buffer[i % size].kind == kind) | |
| 121 | return 1; | |
| 122 | if (result > 0) | |
| 123 | break; | |
| 124 | } | |
| 125 | ||
| 126 | /* We didn't find it; insert the uid into the buffer after i. */ | |
| 127 | i++; | |
| 128 | for (j = start + num; j > i; j--) | |
| 129 | buffer[j % size] = buffer[(j - 1) % size]; | |
| 130 | buffer[i % size].uid = *uid; | |
| 131 | buffer[i % size].kind = kind; | |
| 132 | buffer[i % size].t = now; | |
| 133 | num++; | |
| 134 | ||
| 135 | return 0; | |
| 136 | } | |
| 137 | ||
| 138 | ||
| 139 | /* Return 1 if there is a packet waiting, 0 otherwise */ | |
| 140 | ||
|
22104
56970903b8e9
Probe for -Wstrict-prototypes to get some more warnings. I then cleaned up
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
141 | static int Z_PacketWaiting(void) |
| 2086 | 142 | { |
| 143 | struct timeval tv; | |
| 144 | fd_set read; | |
| 145 | ||
| 146 | tv.tv_sec = tv.tv_usec = 0; | |
| 147 | FD_ZERO(&read); | |
| 148 | FD_SET(ZGetFD(), &read); | |
| 149 | return (select(ZGetFD() + 1, &read, NULL, NULL, &tv)); | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
150 | } |
| 2086 | 151 | |
| 152 | ||
| 153 | /* Wait for a complete notice to become available */ | |
| 154 | ||
|
22104
56970903b8e9
Probe for -Wstrict-prototypes to get some more warnings. I then cleaned up
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
155 | Code_t Z_WaitForComplete(void) |
| 2086 | 156 | { |
| 157 | Code_t retval; | |
| 158 | ||
| 159 | if (__Q_CompleteLength) | |
| 160 | return (Z_ReadEnqueue()); | |
| 161 | ||
| 162 | while (!__Q_CompleteLength) | |
| 163 | if ((retval = Z_ReadWait()) != ZERR_NONE) | |
| 164 | return (retval); | |
| 165 | ||
| 166 | return (ZERR_NONE); | |
| 167 | } | |
| 168 | ||
| 169 | ||
| 170 | /* Read any available packets and enqueue them */ | |
| 171 | ||
|
40166
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
172 | Code_t |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
173 | Z_ReadEnqueue(void) |
| 2086 | 174 | { |
| 175 | Code_t retval; | |
| 176 | ||
| 177 | if (ZGetFD() < 0) | |
| 178 | return (ZERR_NOPORT); | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
179 | |
| 2086 | 180 | while (Z_PacketWaiting()) |
| 181 | if ((retval = Z_ReadWait()) != ZERR_NONE) | |
| 182 | return (retval); | |
| 183 | ||
| 184 | return (ZERR_NONE); | |
| 185 | } | |
| 186 | ||
| 187 | ||
| 188 | /* | |
| 189 | * Search the queue for a notice with the proper multiuid - remove any | |
| 190 | * notices that haven't been touched in a while | |
| 191 | */ | |
| 192 | ||
|
22104
56970903b8e9
Probe for -Wstrict-prototypes to get some more warnings. I then cleaned up
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
193 | static struct _Z_InputQ *Z_SearchQueue(ZUnique_Id_t *uid, ZNotice_Kind_t kind) |
| 2086 | 194 | { |
| 195 | register struct _Z_InputQ *qptr; | |
| 196 | struct _Z_InputQ *next; | |
| 197 | struct timeval tv; | |
| 198 | ||
| 199 | (void) gettimeofday(&tv, (struct timezone *)0); | |
| 200 | ||
| 201 | qptr = __Q_Head; | |
| 202 | ||
| 203 | while (qptr) { | |
| 204 | if (ZCompareUID(uid, &qptr->uid) && qptr->kind == kind) | |
| 205 | return (qptr); | |
| 206 | next = qptr->next; | |
|
36256
a437550a9308
Remove -Wno-sign-compare and backport fixes from default.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
36040
diff
changeset
|
207 | if (qptr->timep && ((time_t)qptr->timep+Z_NOTICETIMELIMIT < tv.tv_sec)) |
| 2086 | 208 | Z_RemQueue(qptr); |
| 209 | qptr = next; | |
| 210 | } | |
| 211 | return (NULL); | |
| 212 | } | |
| 213 | ||
| 214 | /* | |
| 215 | * Now we delve into really convoluted queue handling and | |
| 216 | * fragmentation reassembly algorithms and other stuff you probably | |
| 217 | * don't want to look at... | |
| 218 | * | |
| 219 | * This routine does NOT guarantee a complete packet will be ready when it | |
| 220 | * returns. | |
| 221 | */ | |
| 222 | ||
|
40166
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
223 | Code_t |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
224 | Z_ReadWait(void) |
| 2086 | 225 | { |
| 226 | register struct _Z_InputQ *qptr; | |
| 227 | ZNotice_t notice; | |
| 228 | ZPacket_t packet; | |
| 229 | struct sockaddr_in olddest, from; | |
|
11318
13fa1d5134f3
[gaim-migrate @ 13521]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11105
diff
changeset
|
230 | int packet_len, zvlen, part, partof; |
|
13fa1d5134f3
[gaim-migrate @ 13521]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11105
diff
changeset
|
231 | socklen_t from_len; |
| 2086 | 232 | char *slash; |
| 233 | Code_t retval; | |
| 2419 | 234 | fd_set fds; |
| 235 | struct timeval tv; | |
| 2086 | 236 | |
| 237 | if (ZGetFD() < 0) | |
| 238 | return (ZERR_NOPORT); | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
239 | |
| 2419 | 240 | FD_ZERO(&fds); |
| 241 | FD_SET(ZGetFD(), &fds); | |
| 242 | tv.tv_sec = 60; | |
| 243 | tv.tv_usec = 0; | |
| 244 | ||
| 245 | if (select(ZGetFD() + 1, &fds, NULL, NULL, &tv) < 0) | |
| 246 | return (errno); | |
| 247 | if (!FD_ISSET(ZGetFD(), &fds)) | |
| 248 | return ETIMEDOUT; | |
| 249 | ||
| 2086 | 250 | from_len = sizeof(struct sockaddr_in); |
| 251 | ||
|
35992
34a67264df99
Fix some CWE-476 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
32016
diff
changeset
|
252 | packet_len = recvfrom(ZGetFD(), packet, sizeof(packet) - 1, 0, |
| 2086 | 253 | (struct sockaddr *)&from, &from_len); |
| 254 | ||
| 255 | if (packet_len < 0) | |
|
37941
5c9865516e99
Make some indentation more consistent.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37389
diff
changeset
|
256 | return (errno); |
| 2086 | 257 | |
| 258 | if (!packet_len) | |
|
37941
5c9865516e99
Make some indentation more consistent.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37389
diff
changeset
|
259 | return (ZERR_EOF); |
| 2086 | 260 | |
| 38213 | 261 | packet[packet_len] = '\0'; |
|
35992
34a67264df99
Fix some CWE-476 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
32016
diff
changeset
|
262 | |
| 2419 | 263 | /* Ignore obviously non-Zephyr packets. */ |
| 264 | zvlen = sizeof(ZVERSIONHDR) - 1; | |
| 265 | if (packet_len < zvlen || memcmp(packet, ZVERSIONHDR, zvlen) != 0) { | |
| 266 | Z_discarded_packets++; | |
| 267 | return (ZERR_NONE); | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
268 | } |
| 2086 | 269 | |
| 270 | /* Parse the notice */ | |
| 271 | if ((retval = ZParseNotice(packet, packet_len, ¬ice)) != ZERR_NONE) | |
| 272 | return (retval); | |
| 273 | ||
| 274 | /* | |
| 275 | * If we're not a server and the notice is of an appropriate kind, | |
| 276 | * send back a CLIENTACK to whoever sent it to say we got it. | |
| 277 | */ | |
| 278 | if (!__Zephyr_server) { | |
| 279 | if (notice.z_kind != HMACK && notice.z_kind != SERVACK && | |
| 280 | notice.z_kind != SERVNAK && notice.z_kind != CLIENTACK) { | |
| 281 | ZNotice_t tmpnotice; | |
| 282 | ZPacket_t pkt; | |
| 283 | int len; | |
| 284 | ||
| 285 | tmpnotice = notice; | |
| 286 | tmpnotice.z_kind = CLIENTACK; | |
| 287 | tmpnotice.z_message_len = 0; | |
| 288 | olddest = __HM_addr; | |
| 289 | __HM_addr = from; | |
| 290 | if ((retval = ZFormatSmallRawNotice(&tmpnotice, pkt, &len)) | |
| 291 | != ZERR_NONE) | |
| 292 | return(retval); | |
| 293 | if ((retval = ZSendPacket(pkt, len, 0)) != ZERR_NONE) | |
| 294 | return (retval); | |
| 295 | __HM_addr = olddest; | |
| 296 | } | |
| 297 | if (find_or_insert_uid(¬ice.z_uid, notice.z_kind)) | |
| 298 | return(ZERR_NONE); | |
| 299 | ||
| 300 | /* Check authentication on the notice. */ | |
| 301 | notice.z_checked_auth = ZCheckAuthentication(¬ice, &from); | |
| 302 | } | |
| 303 | ||
| 304 | ||
| 305 | /* | |
| 306 | * Parse apart the z_multinotice field - if the field is blank for | |
| 307 | * some reason, assume this packet stands by itself. | |
| 308 | */ | |
| 309 | slash = strchr(notice.z_multinotice, '/'); | |
| 310 | if (slash) { | |
| 311 | part = atoi(notice.z_multinotice); | |
| 312 | partof = atoi(slash+1); | |
| 313 | if (part > partof || partof == 0) { | |
| 314 | part = 0; | |
| 315 | partof = notice.z_message_len; | |
| 316 | } | |
| 317 | } | |
| 318 | else { | |
| 319 | part = 0; | |
| 320 | partof = notice.z_message_len; | |
| 321 | } | |
| 322 | ||
| 323 | /* Too big a packet...just ignore it! */ | |
| 324 | if (partof > Z_MAXNOTICESIZE) | |
| 325 | return (ZERR_NONE); | |
| 326 | ||
| 327 | /* | |
| 328 | * If we aren't a server and we can find a notice in the queue | |
| 329 | * with the same multiuid field, insert the current fragment as | |
| 330 | * appropriate. | |
| 331 | */ | |
| 332 | switch (notice.z_kind) { | |
| 333 | case SERVACK: | |
| 334 | case SERVNAK: | |
| 335 | /* The SERVACK and SERVNAK replies shouldn't be reassembled | |
| 336 | (they have no parts). Instead, we should hold on to the reply | |
| 337 | ONLY if it's the first part of a fragmented message, i.e. | |
| 338 | multi_uid == uid. This allows programs to wait for the uid | |
| 339 | of the first packet, and get a response when that notice | |
| 340 | arrives. Acknowledgements of the other fragments are discarded | |
| 341 | (XXX we assume here that they all carry the same information | |
| 342 | regarding failure/success) | |
| 343 | */ | |
| 344 | if (!__Zephyr_server && | |
| 345 | !ZCompareUID(¬ice.z_multiuid, ¬ice.z_uid)) | |
| 346 | /* they're not the same... throw away this packet. */ | |
| 347 | return(ZERR_NONE); | |
| 348 | /* fall thru & process it */ | |
| 349 | default: | |
| 350 | /* for HMACK types, we assume no packet loss (local loopback | |
| 351 | connections). The other types can be fragmented and MUST | |
| 352 | run through this code. */ | |
| 353 | if (!__Zephyr_server && (qptr = Z_SearchQueue(¬ice.z_multiuid, | |
| 354 | notice.z_kind))) { | |
| 355 | /* | |
| 356 | * If this is the first fragment, and we haven't already | |
| 357 | * gotten a first fragment, grab the header from it. | |
| 358 | */ | |
| 359 | if (part == 0 && !qptr->header) { | |
| 360 | qptr->header_len = packet_len-notice.z_message_len; | |
| 361 | qptr->header = (char *) malloc((unsigned) qptr->header_len); | |
| 362 | if (!qptr->header) | |
| 363 | return (ENOMEM); | |
| 364 | (void) memcpy(qptr->header, packet, qptr->header_len); | |
| 365 | } | |
| 366 | return (Z_AddNoticeToEntry(qptr, ¬ice, part)); | |
| 367 | } | |
| 368 | } | |
| 369 | ||
| 370 | /* | |
| 371 | * We'll have to create a new entry...make sure the queue isn't | |
| 372 | * going to get too big. | |
| 373 | */ | |
| 374 | if (__Q_Size+(__Zephyr_server ? notice.z_message_len : partof) > Z_MAXQUEUESIZE) | |
| 375 | return (ZERR_NONE); | |
| 376 | ||
| 377 | /* | |
| 378 | * This is a notice we haven't heard of, so create a new queue | |
| 379 | * entry for it and zero it out. | |
| 380 | */ | |
| 381 | qptr = (struct _Z_InputQ *)malloc(sizeof(struct _Z_InputQ)); | |
| 382 | if (!qptr) | |
| 383 | return (ENOMEM); | |
| 384 | (void) memset((char *)qptr, 0, sizeof(struct _Z_InputQ)); | |
| 385 | ||
| 386 | /* Insert the entry at the end of the queue */ | |
| 387 | qptr->next = NULL; | |
| 388 | qptr->prev = __Q_Tail; | |
| 389 | if (__Q_Tail) | |
| 390 | __Q_Tail->next = qptr; | |
| 391 | __Q_Tail = qptr; | |
| 392 | ||
| 393 | if (!__Q_Head) | |
| 394 | __Q_Head = qptr; | |
| 395 | ||
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
396 | |
| 2086 | 397 | /* Copy the from field, multiuid, kind, and checked authentication. */ |
| 398 | qptr->from = from; | |
| 399 | qptr->uid = notice.z_multiuid; | |
| 400 | qptr->kind = notice.z_kind; | |
| 401 | qptr->auth = notice.z_checked_auth; | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
402 | |
| 2086 | 403 | /* |
| 404 | * If this is the first part of the notice, we take the header | |
| 405 | * from it. We only take it if this is the first fragment so that | |
| 406 | * the Unique ID's will be predictable. | |
| 407 | * | |
| 408 | * If a Zephyr Server, we always take the header. | |
| 409 | */ | |
| 410 | if (__Zephyr_server || part == 0) { | |
| 411 | qptr->header_len = packet_len-notice.z_message_len; | |
| 412 | qptr->header = (char *) malloc((unsigned) qptr->header_len); | |
| 413 | if (!qptr->header) | |
| 414 | return ENOMEM; | |
| 415 | (void) memcpy(qptr->header, packet, qptr->header_len); | |
| 416 | } | |
| 417 | ||
| 418 | /* | |
| 419 | * If this is not a fragmented notice, then don't bother with a | |
| 420 | * hole list. | |
| 421 | * If we are a Zephyr server, all notices are treated as complete. | |
| 422 | */ | |
| 423 | if (__Zephyr_server || (part == 0 && notice.z_message_len == partof)) { | |
| 424 | __Q_CompleteLength++; | |
| 425 | qptr->holelist = (struct _Z_Hole *) 0; | |
| 426 | qptr->complete = 1; | |
| 427 | /* allocate a msg buf for this piece */ | |
| 428 | if (notice.z_message_len == 0) | |
| 429 | qptr->msg = 0; | |
| 430 | else if (!(qptr->msg = (char *) malloc((unsigned) notice.z_message_len))) | |
| 431 | return(ENOMEM); | |
| 432 | else | |
| 433 | (void) memcpy(qptr->msg, notice.z_message, notice.z_message_len); | |
| 434 | qptr->msg_len = notice.z_message_len; | |
| 435 | __Q_Size += notice.z_message_len; | |
| 436 | qptr->packet_len = qptr->header_len+qptr->msg_len; | |
| 437 | if (!(qptr->packet = (char *) malloc((unsigned) qptr->packet_len))) | |
| 438 | return (ENOMEM); | |
| 439 | (void) memcpy(qptr->packet, qptr->header, qptr->header_len); | |
| 440 | if(qptr->msg) | |
| 441 | (void) memcpy(qptr->packet+qptr->header_len, qptr->msg, | |
| 442 | qptr->msg_len); | |
| 443 | return (ZERR_NONE); | |
| 444 | } | |
| 445 | ||
| 446 | /* | |
| 447 | * We know how long the message is going to be (this is better | |
| 448 | * than IP fragmentation...), so go ahead and allocate it all. | |
| 449 | */ | |
| 450 | if (!(qptr->msg = (char *) malloc((unsigned) partof)) && partof) | |
| 451 | return (ENOMEM); | |
| 452 | qptr->msg_len = partof; | |
| 453 | __Q_Size += partof; | |
| 454 | ||
| 455 | /* | |
| 456 | * Well, it's a fragmented notice...allocate a hole list and | |
| 457 | * initialize it to the full packet size. Then insert the | |
| 458 | * current fragment. | |
| 459 | */ | |
| 460 | if (!(qptr->holelist = (struct _Z_Hole *) | |
| 461 | malloc(sizeof(struct _Z_Hole)))) | |
| 462 | return (ENOMEM); | |
| 463 | qptr->holelist->next = (struct _Z_Hole *) 0; | |
| 464 | qptr->holelist->first = 0; | |
| 465 | qptr->holelist->last = partof-1; | |
| 466 | return (Z_AddNoticeToEntry(qptr, ¬ice, part)); | |
| 467 | } | |
| 468 | ||
| 469 | ||
| 470 | /* Fragment management routines - compliments, more or less, of RFC815 */ | |
| 471 | ||
|
40166
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
472 | Code_t |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
473 | Z_AddNoticeToEntry(struct _Z_InputQ *qptr, ZNotice_t *notice, int part) |
| 2086 | 474 | { |
| 475 | int last, oldfirst, oldlast; | |
| 476 | struct _Z_Hole *hole, *lasthole; | |
| 477 | struct timeval tv; | |
| 478 | ||
| 479 | /* Incorporate this notice's checked authentication. */ | |
| 480 | if (notice->z_checked_auth == ZAUTH_FAILED) | |
| 481 | qptr->auth = ZAUTH_FAILED; | |
| 482 | else if (notice->z_checked_auth == ZAUTH_NO && qptr->auth != ZAUTH_FAILED) | |
| 483 | qptr->auth = ZAUTH_NO; | |
| 484 | ||
| 485 | (void) gettimeofday(&tv, (struct timezone *)0); | |
| 486 | qptr->timep = tv.tv_sec; | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
487 | |
| 2086 | 488 | last = part+notice->z_message_len-1; |
| 489 | ||
| 490 | hole = qptr->holelist; | |
| 491 | lasthole = (struct _Z_Hole *) 0; | |
| 492 | ||
| 493 | /* copy in the message body */ | |
| 494 | (void) memcpy(qptr->msg+part, notice->z_message, notice->z_message_len); | |
| 495 | ||
| 496 | /* Search for a hole that overlaps with the current fragment */ | |
| 497 | while (hole) { | |
| 498 | if (part <= hole->last && last >= hole->first) | |
| 499 | break; | |
| 500 | lasthole = hole; | |
| 501 | hole = hole->next; | |
| 502 | } | |
| 503 | ||
| 504 | /* If we found one, delete it and reconstruct a new hole */ | |
| 505 | if (hole) { | |
| 506 | oldfirst = hole->first; | |
| 507 | oldlast = hole->last; | |
| 508 | if (lasthole) | |
| 509 | lasthole->next = hole->next; | |
| 510 | else | |
| 511 | qptr->holelist = hole->next; | |
| 512 | free((char *)hole); | |
| 513 | /* | |
| 514 | * Now create a new hole that is the original hole without the | |
| 515 | * current fragment. | |
| 516 | */ | |
| 517 | if (part > oldfirst) { | |
| 518 | /* Search for the end of the hole list */ | |
| 519 | hole = qptr->holelist; | |
| 520 | lasthole = (struct _Z_Hole *) 0; | |
| 521 | while (hole) { | |
| 522 | lasthole = hole; | |
| 523 | hole = hole->next; | |
| 524 | } | |
| 525 | if (lasthole) { | |
|
36040
8f2d69e2b8b5
Backport better zephyr coverity fix from default
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36037
diff
changeset
|
526 | struct _Z_InputQ *inputq = malloc(sizeof(struct _Z_InputQ)); |
|
8f2d69e2b8b5
Backport better zephyr coverity fix from default
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36037
diff
changeset
|
527 | if (!inputq) |
| 2086 | 528 | return (ENOMEM); |
|
36040
8f2d69e2b8b5
Backport better zephyr coverity fix from default
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36037
diff
changeset
|
529 | lasthole->next = (struct _Z_Hole *)inputq; |
| 2086 | 530 | hole = lasthole->next; |
| 531 | } | |
| 532 | else { | |
|
36040
8f2d69e2b8b5
Backport better zephyr coverity fix from default
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36037
diff
changeset
|
533 | struct _Z_InputQ *inputq = malloc(sizeof(struct _Z_InputQ)); |
|
8f2d69e2b8b5
Backport better zephyr coverity fix from default
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36037
diff
changeset
|
534 | if (!inputq) |
| 2086 | 535 | return (ENOMEM); |
|
36040
8f2d69e2b8b5
Backport better zephyr coverity fix from default
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36037
diff
changeset
|
536 | qptr->holelist = (struct _Z_Hole *)inputq; |
| 2086 | 537 | hole = qptr->holelist; |
| 538 | } | |
| 539 | hole->next = NULL; | |
| 540 | hole->first = oldfirst; | |
| 541 | hole->last = part-1; | |
| 542 | } | |
| 543 | if (last < oldlast) { | |
| 544 | /* Search for the end of the hole list */ | |
| 545 | hole = qptr->holelist; | |
| 546 | lasthole = (struct _Z_Hole *) 0; | |
| 547 | while (hole) { | |
| 548 | lasthole = hole; | |
| 549 | hole = hole->next; | |
| 550 | } | |
| 551 | if (lasthole) { | |
|
36040
8f2d69e2b8b5
Backport better zephyr coverity fix from default
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36037
diff
changeset
|
552 | struct _Z_InputQ *inputq = malloc(sizeof(struct _Z_InputQ)); |
|
8f2d69e2b8b5
Backport better zephyr coverity fix from default
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36037
diff
changeset
|
553 | if (!inputq) |
| 2086 | 554 | return (ENOMEM); |
|
36040
8f2d69e2b8b5
Backport better zephyr coverity fix from default
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36037
diff
changeset
|
555 | lasthole->next = (struct _Z_Hole *)inputq; |
| 2086 | 556 | hole = lasthole->next; |
| 557 | } | |
| 558 | else { | |
|
36040
8f2d69e2b8b5
Backport better zephyr coverity fix from default
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36037
diff
changeset
|
559 | struct _Z_InputQ *inputq = malloc(sizeof(struct _Z_InputQ)); |
|
8f2d69e2b8b5
Backport better zephyr coverity fix from default
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36037
diff
changeset
|
560 | if (!inputq) |
| 2086 | 561 | return (ENOMEM); |
|
36040
8f2d69e2b8b5
Backport better zephyr coverity fix from default
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36037
diff
changeset
|
562 | qptr->holelist = (struct _Z_Hole *)inputq; |
| 2086 | 563 | hole = qptr->holelist; |
| 564 | } | |
| 565 | hole->next = (struct _Z_Hole *) 0; | |
| 566 | hole->first = last+1; | |
| 567 | hole->last = oldlast; | |
| 568 | } | |
| 569 | } | |
| 570 | ||
| 571 | if (!qptr->holelist) { | |
| 572 | if (!qptr->complete) | |
| 573 | __Q_CompleteLength++; | |
| 574 | qptr->complete = 1; | |
| 575 | qptr->timep = 0; /* don't time out anymore */ | |
| 576 | qptr->packet_len = qptr->header_len+qptr->msg_len; | |
| 577 | if (!(qptr->packet = (char *) malloc((unsigned) qptr->packet_len))) | |
| 578 | return (ENOMEM); | |
| 579 | (void) memcpy(qptr->packet, qptr->header, qptr->header_len); | |
| 580 | (void) memcpy(qptr->packet+qptr->header_len, qptr->msg, | |
| 581 | qptr->msg_len); | |
| 582 | } | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
583 | |
| 2086 | 584 | return (ZERR_NONE); |
| 585 | } | |
| 586 | ||
|
40166
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
587 | Code_t |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
588 | 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
|
589 | Z_AuthProc cert_routine) |
| 2086 | 590 | { |
| 591 | Code_t retval; | |
| 592 | static char version[BUFSIZ]; /* default init should be all \0 */ | |
| 593 | struct sockaddr_in name; | |
|
11318
13fa1d5134f3
[gaim-migrate @ 13521]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11105
diff
changeset
|
594 | socklen_t namelen = sizeof(name); |
| 2086 | 595 | |
| 596 | if (!notice->z_sender) | |
| 597 | notice->z_sender = ZGetSender(); | |
| 598 | ||
| 599 | if (notice->z_port == 0) { | |
| 600 | if (ZGetFD() < 0) { | |
|
7475
987384816492
[gaim-migrate @ 8088]
Mark Doliner <markdoliner@pidgin.im>
parents:
5136
diff
changeset
|
601 | retval = ZOpenPort((unsigned short *)0); |
| 2086 | 602 | if (retval != ZERR_NONE) |
| 603 | return (retval); | |
| 604 | } | |
| 605 | retval = getsockname(ZGetFD(), (struct sockaddr *) &name, &namelen); | |
| 606 | if (retval != 0) | |
| 607 | return (retval); | |
| 608 | notice->z_port = name.sin_port; | |
| 609 | } | |
| 610 | ||
| 611 | notice->z_multinotice = ""; | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
612 | |
| 2086 | 613 | (void) gettimeofday(¬ice->z_uid.tv, (struct timezone *)0); |
|
7475
987384816492
[gaim-migrate @ 8088]
Mark Doliner <markdoliner@pidgin.im>
parents:
5136
diff
changeset
|
614 | notice->z_uid.tv.tv_sec = htonl((unsigned long) notice->z_uid.tv.tv_sec); |
|
987384816492
[gaim-migrate @ 8088]
Mark Doliner <markdoliner@pidgin.im>
parents:
5136
diff
changeset
|
615 | 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
|
616 | |
| 2419 | 617 | (void) memcpy(¬ice->z_uid.zuid_addr, &__My_addr, sizeof(__My_addr)); |
| 2086 | 618 | |
| 619 | notice->z_multiuid = notice->z_uid; | |
| 620 | ||
| 621 | if (!version[0]) | |
| 622 | (void) sprintf(version, "%s%d.%d", ZVERSIONHDR, ZVERSIONMAJOR, | |
| 623 | ZVERSIONMINOR); | |
| 624 | notice->z_version = version; | |
| 625 | ||
| 626 | return Z_FormatAuthHeader(notice, buffer, buffer_len, len, cert_routine); | |
| 627 | } | |
| 628 | ||
|
40166
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
629 | Code_t |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
630 | 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
|
631 | Z_AuthProc cert_routine) |
| 2086 | 632 | { |
| 633 | if (!cert_routine) { | |
| 634 | notice->z_auth = 0; | |
| 635 | notice->z_authent_len = 0; | |
| 636 | notice->z_ascii_authent = ""; | |
| 637 | notice->z_checksum = 0; | |
| 638 | return (Z_FormatRawHeader(notice, buffer, buffer_len, | |
| 639 | len, NULL, NULL)); | |
| 640 | } | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
641 | |
| 2086 | 642 | return ((*cert_routine)(notice, buffer, buffer_len, len)); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
643 | } |
|
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
644 | |
|
40166
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
645 | Code_t |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
646 | 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
|
647 | char **cstart, char **cend) |
| 2086 | 648 | { |
| 649 | char newrecip[BUFSIZ]; | |
| 650 | char *ptr, *end; | |
| 651 | int i; | |
| 652 | ||
| 653 | if (!notice->z_class) | |
| 654 | notice->z_class = ""; | |
| 655 | ||
| 656 | if (!notice->z_class_inst) | |
| 657 | notice->z_class_inst = ""; | |
| 658 | ||
| 659 | if (!notice->z_opcode) | |
| 660 | notice->z_opcode = ""; | |
| 661 | ||
| 662 | if (!notice->z_recipient) | |
| 663 | notice->z_recipient = ""; | |
| 664 | ||
| 665 | if (!notice->z_default_format) | |
| 666 | notice->z_default_format = ""; | |
| 667 | ||
| 668 | ptr = buffer; | |
| 669 | end = buffer+buffer_len; | |
| 670 | ||
| 671 | if (buffer_len < strlen(notice->z_version)+1) | |
| 672 | return (ZERR_HEADERLEN); | |
| 673 | ||
|
31954
e5631d5590cc
Replace numerous strcpy() invocations with strlcpy() in Zephyr.
Ethan Blanton <elb@pidgin.im>
parents:
31363
diff
changeset
|
674 | g_strlcpy(ptr, notice->z_version, buffer_len); |
| 2086 | 675 | ptr += strlen(ptr)+1; |
| 676 | ||
| 677 | if (ZMakeAscii32(ptr, end-ptr, Z_NUMFIELDS + notice->z_num_other_fields) | |
| 678 | == ZERR_FIELDLEN) | |
| 679 | return (ZERR_HEADERLEN); | |
| 680 | ptr += strlen(ptr)+1; | |
| 681 | ||
| 682 | if (ZMakeAscii32(ptr, end-ptr, notice->z_kind) == ZERR_FIELDLEN) | |
| 683 | return (ZERR_HEADERLEN); | |
| 684 | ptr += strlen(ptr)+1; | |
| 685 | ||
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
686 | if (ZMakeAscii(ptr, end-ptr, (unsigned char *)¬ice->z_uid, |
| 2086 | 687 | sizeof(ZUnique_Id_t)) == ZERR_FIELDLEN) |
| 688 | return (ZERR_HEADERLEN); | |
| 689 | ptr += strlen(ptr)+1; | |
| 690 | ||
| 691 | if (ZMakeAscii16(ptr, end-ptr, ntohs(notice->z_port)) == ZERR_FIELDLEN) | |
| 692 | return (ZERR_HEADERLEN); | |
| 693 | ptr += strlen(ptr)+1; | |
| 694 | ||
| 695 | if (ZMakeAscii32(ptr, end-ptr, notice->z_auth) == ZERR_FIELDLEN) | |
| 696 | return (ZERR_HEADERLEN); | |
| 697 | ptr += strlen(ptr)+1; | |
| 698 | ||
| 699 | if (ZMakeAscii32(ptr, end-ptr, notice->z_authent_len) == ZERR_FIELDLEN) | |
| 700 | return (ZERR_HEADERLEN); | |
| 701 | ptr += strlen(ptr)+1; | |
| 702 | ||
| 703 | if (Z_AddField(&ptr, notice->z_ascii_authent, end)) | |
| 704 | return (ZERR_HEADERLEN); | |
| 705 | if (Z_AddField(&ptr, notice->z_class, end)) | |
| 706 | return (ZERR_HEADERLEN); | |
| 707 | if (Z_AddField(&ptr, notice->z_class_inst, end)) | |
| 708 | return (ZERR_HEADERLEN); | |
| 709 | if (Z_AddField(&ptr, notice->z_opcode, end)) | |
| 710 | return (ZERR_HEADERLEN); | |
| 711 | if (Z_AddField(&ptr, notice->z_sender, end)) | |
| 712 | return (ZERR_HEADERLEN); | |
| 713 | if (strchr(notice->z_recipient, '@') || !*notice->z_recipient) { | |
| 714 | if (Z_AddField(&ptr, notice->z_recipient, end)) | |
| 715 | return (ZERR_HEADERLEN); | |
| 716 | } | |
| 717 | else { | |
| 718 | if (strlen(notice->z_recipient) + strlen(__Zephyr_realm) + 2 > | |
| 2419 | 719 | sizeof(newrecip)) |
| 720 | return (ZERR_HEADERLEN); | |
| 2086 | 721 | (void) sprintf(newrecip, "%s@%s", notice->z_recipient, __Zephyr_realm); |
| 722 | if (Z_AddField(&ptr, newrecip, end)) | |
| 723 | return (ZERR_HEADERLEN); | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
724 | } |
| 2086 | 725 | if (Z_AddField(&ptr, notice->z_default_format, end)) |
| 726 | return (ZERR_HEADERLEN); | |
| 727 | ||
| 728 | /* copy back the end pointer location for crypto checksum */ | |
| 729 | if (cstart) | |
| 730 | *cstart = ptr; | |
| 731 | if (ZMakeAscii32(ptr, end-ptr, notice->z_checksum) == ZERR_FIELDLEN) | |
| 732 | return (ZERR_HEADERLEN); | |
| 733 | ptr += strlen(ptr)+1; | |
| 734 | if (cend) | |
| 735 | *cend = ptr; | |
| 736 | ||
| 737 | if (Z_AddField(&ptr, notice->z_multinotice, end)) | |
| 738 | return (ZERR_HEADERLEN); | |
| 739 | ||
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
740 | if (ZMakeAscii(ptr, end-ptr, (unsigned char *)¬ice->z_multiuid, |
| 2086 | 741 | sizeof(ZUnique_Id_t)) == ZERR_FIELDLEN) |
| 742 | return (ZERR_HEADERLEN); | |
| 743 | ptr += strlen(ptr)+1; | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
744 | |
| 2086 | 745 | for (i=0;i<notice->z_num_other_fields;i++) |
| 746 | if (Z_AddField(&ptr, notice->z_other_fields[i], end)) | |
| 747 | return (ZERR_HEADERLEN); | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
748 | |
| 2086 | 749 | *len = ptr-buffer; |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
750 | |
| 2086 | 751 | return (ZERR_NONE); |
| 752 | } | |
| 753 | ||
| 754 | static int | |
| 5136 | 755 | Z_AddField(char **ptr, const char *field, char *end) |
| 2086 | 756 | { |
| 757 | register int len; | |
| 758 | ||
| 759 | len = field ? strlen (field) + 1 : 1; | |
| 760 | ||
| 761 | if (*ptr+len > end) | |
| 762 | return 1; | |
| 763 | if (field) | |
|
32016
b1662f03fa07
Fix some un-fixes in the Zephyr strlcpy changes
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
764 | strcpy(*ptr, field); |
| 2086 | 765 | else |
|
31954
e5631d5590cc
Replace numerous strcpy() invocations with strlcpy() in Zephyr.
Ethan Blanton <elb@pidgin.im>
parents:
31363
diff
changeset
|
766 | **ptr = '\0'; |
| 2086 | 767 | *ptr += len; |
| 768 | ||
| 769 | return 0; | |
| 770 | } | |
| 771 | ||
|
40166
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
772 | struct _Z_InputQ * |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
773 | Z_GetFirstComplete(void) |
| 2086 | 774 | { |
| 775 | struct _Z_InputQ *qptr; | |
| 776 | ||
| 777 | qptr = __Q_Head; | |
| 778 | ||
| 779 | while (qptr) { | |
| 780 | if (qptr->complete) | |
| 781 | return (qptr); | |
| 782 | qptr = qptr->next; | |
| 783 | } | |
| 784 | ||
| 785 | return ((struct _Z_InputQ *)0); | |
| 786 | } | |
| 787 | ||
|
40166
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
788 | struct _Z_InputQ * |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
789 | Z_GetNextComplete(struct _Z_InputQ *qptr) |
| 2086 | 790 | { |
| 791 | qptr = qptr->next; | |
| 792 | while (qptr) { | |
| 793 | if (qptr->complete) | |
| 794 | return (qptr); | |
| 795 | qptr = qptr->next; | |
| 796 | } | |
| 797 | ||
| 798 | return ((struct _Z_InputQ *)0); | |
| 799 | } | |
| 800 | ||
|
40166
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
801 | void |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
802 | Z_RemQueue(struct _Z_InputQ *qptr) |
| 2086 | 803 | { |
| 804 | struct _Z_Hole *hole, *nexthole; | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
805 | |
| 2086 | 806 | if (qptr->complete) |
| 807 | __Q_CompleteLength--; | |
| 808 | ||
| 809 | __Q_Size -= qptr->msg_len; | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
810 | |
|
37389
7240fd8e3462
free() and g_free() are specified to be NULL-safe. Remove NULL checks.
Michael McConville <mmcconville@mykolab.com>
parents:
36257
diff
changeset
|
811 | free(qptr->header); |
|
7240fd8e3462
free() and g_free() are specified to be NULL-safe. Remove NULL checks.
Michael McConville <mmcconville@mykolab.com>
parents:
36257
diff
changeset
|
812 | free(qptr->msg); |
|
7240fd8e3462
free() and g_free() are specified to be NULL-safe. Remove NULL checks.
Michael McConville <mmcconville@mykolab.com>
parents:
36257
diff
changeset
|
813 | free(qptr->packet); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
814 | |
| 2086 | 815 | hole = qptr->holelist; |
| 816 | while (hole) { | |
| 817 | nexthole = hole->next; | |
| 818 | free((char *)hole); | |
| 819 | hole = nexthole; | |
| 820 | } | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
821 | |
| 2086 | 822 | if (qptr == __Q_Head && __Q_Head == __Q_Tail) { |
| 823 | free ((char *)qptr); | |
| 824 | __Q_Head = (struct _Z_InputQ *)0; | |
| 825 | __Q_Tail = (struct _Z_InputQ *)0; | |
| 826 | return; | |
| 827 | } | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
828 | |
| 2086 | 829 | if (qptr == __Q_Head) { |
| 830 | __Q_Head = qptr->next; | |
| 831 | __Q_Head->prev = (struct _Z_InputQ *)0; | |
| 832 | free ((char *)qptr); | |
| 833 | return; | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
834 | } |
| 2086 | 835 | if (qptr == __Q_Tail) { |
| 836 | __Q_Tail = qptr->prev; | |
| 837 | __Q_Tail->next = (struct _Z_InputQ *)0; | |
| 838 | free ((char *)qptr); | |
| 839 | return; | |
| 840 | } | |
| 841 | qptr->prev->next = qptr->next; | |
| 842 | qptr->next->prev = qptr->prev; | |
| 843 | free ((char *)qptr); | |
| 844 | } | |
| 845 | ||
|
40166
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
846 | Code_t |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
847 | 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
|
848 | Z_SendProc send_func) |
| 2086 | 849 | { |
| 850 | ZNotice_t partnotice; | |
| 851 | ZPacket_t buffer; | |
| 852 | char multi[64]; | |
| 853 | int offset, hdrsize, fragsize, ret_len, message_len, waitforack; | |
| 854 | Code_t retval; | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
855 | |
| 2086 | 856 | hdrsize = len-notice->z_message_len; |
| 857 | fragsize = Z_MAXPKTLEN-hdrsize-Z_FRAGFUDGE; | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
858 | |
| 2086 | 859 | offset = 0; |
| 860 | ||
| 861 | waitforack = ((notice->z_kind == UNACKED || notice->z_kind == ACKED) | |
| 862 | && !__Zephyr_server); | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
863 | |
| 2086 | 864 | partnotice = *notice; |
| 865 | ||
| 866 | while (offset < notice->z_message_len || !notice->z_message_len) { | |
| 867 | (void) sprintf(multi, "%d/%d", offset, notice->z_message_len); | |
| 868 | partnotice.z_multinotice = multi; | |
| 869 | if (offset > 0) { | |
| 870 | (void) gettimeofday(&partnotice.z_uid.tv, | |
| 871 | (struct timezone *)0); | |
| 872 | partnotice.z_uid.tv.tv_sec = | |
|
7475
987384816492
[gaim-migrate @ 8088]
Mark Doliner <markdoliner@pidgin.im>
parents:
5136
diff
changeset
|
873 | htonl((unsigned long) partnotice.z_uid.tv.tv_sec); |
| 2086 | 874 | partnotice.z_uid.tv.tv_usec = |
|
7475
987384816492
[gaim-migrate @ 8088]
Mark Doliner <markdoliner@pidgin.im>
parents:
5136
diff
changeset
|
875 | htonl((unsigned long) partnotice.z_uid.tv.tv_usec); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
22104
diff
changeset
|
876 | (void) memcpy((char *)&partnotice.z_uid.zuid_addr, &__My_addr, |
| 2419 | 877 | sizeof(__My_addr)); |
| 2086 | 878 | } |
|
39828
7372deed606c
zephyr: Use GLib's min/max macros.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
38240
diff
changeset
|
879 | message_len = MIN(notice->z_message_len - offset, fragsize); |
|
15018
7ce510403b58
[gaim-migrate @ 17735]
Luke Schierer <lschiere@pidgin.im>
parents:
14254
diff
changeset
|
880 | partnotice.z_message = (char*)notice->z_message+offset; |
| 2086 | 881 | partnotice.z_message_len = message_len; |
| 882 | if ((retval = Z_FormatAuthHeader(&partnotice, buffer, Z_MAXHEADERLEN, | |
| 883 | &ret_len, cert_func)) != ZERR_NONE) { | |
| 884 | return (retval); | |
| 885 | } | |
| 886 | memcpy(buffer + ret_len, partnotice.z_message, message_len); | |
| 887 | if ((retval = (*send_func)(&partnotice, buffer, ret_len+message_len, | |
| 888 | waitforack)) != ZERR_NONE) { | |
| 889 | return (retval); | |
| 890 | } | |
| 891 | offset += fragsize; | |
| 892 | if (!notice->z_message_len) | |
| 893 | break; | |
| 894 | } | |
| 895 | ||
| 896 | return (ZERR_NONE); | |
| 897 | } | |
| 898 | ||
| 899 | /*ARGSUSED*/ | |
|
40166
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
900 | Code_t |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
901 | Z_XmitFragment(ZNotice_t *notice, char *buf, int len, int wait) |
| 2086 | 902 | { |
| 903 | return(ZSendPacket(buf, len, wait)); | |
| 904 | } | |
| 905 | ||
| 906 | #ifdef Z_DEBUG | |
| 907 | /* For debugging printing */ | |
| 908 | const char *const ZNoticeKinds[] = { | |
| 909 | "UNSAFE", "UNACKED", "ACKED", "HMACK", "HMCTL", "SERVACK", "SERVNAK", | |
| 910 | "CLIENTACK", "STAT" | |
| 911 | }; | |
| 912 | #endif | |
| 913 | ||
| 914 | #ifdef Z_DEBUG | |
| 915 | ||
| 916 | #undef Z_debug | |
| 917 | void Z_debug (const char *format, ...) | |
| 918 | { | |
| 919 | va_list pvar; | |
| 920 | if (!__Z_debug_print) | |
| 921 | return; | |
| 922 | va_start (pvar, format); | |
| 923 | (*__Z_debug_print) (format, pvar, __Z_debug_print_closure); | |
| 924 | va_end (pvar); | |
| 925 | } | |
| 926 | ||
|
40166
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
927 | void |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
928 | Z_debug_stderr(const char *format, va_list args, void *closure) |
| 2086 | 929 | { |
| 930 | vfprintf (stderr, format, args); | |
| 931 | putc ('\n', stderr); | |
| 932 | } | |
| 933 | ||
| 934 | #undef ZGetFD | |
|
40166
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
935 | int |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
936 | ZGetFD(void) |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
937 | { |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
938 | return __Zephyr_fd; |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
939 | } |
| 2086 | 940 | |
| 941 | #undef ZQLength | |
|
40166
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
942 | int |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
943 | ZQLength(void) |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
944 | { |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
945 | return __Q_CompleteLength; |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
946 | } |
| 2086 | 947 | |
| 948 | #undef ZGetDestAddr | |
|
40166
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
949 | struct sockaddr_in |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
950 | ZGetDestAddr(void) |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
951 | { |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
952 | return __HM_addr; |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
953 | } |
| 2086 | 954 | |
| 955 | #undef ZGetRealm | |
|
40166
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
956 | Zconst char * |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
957 | ZGetRealm(void) |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
958 | { |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
959 | return __Zephyr_realm; |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
960 | } |
| 2086 | 961 | |
| 962 | #undef ZSetDebug | |
|
40166
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
963 | void |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40131
diff
changeset
|
964 | ZSetDebug(void (*proc)(const char *, va_list, void *), char *arg) |
| 2086 | 965 | { |
| 966 | __Z_debug_print = proc; | |
| 967 | __Z_debug_print_closure = arg; | |
| 968 | } | |
| 969 | #endif /* Z_DEBUG */ | |
| 970 |