| 10 */ |
10 */ |
| 11 |
11 |
| 12 #include "internal.h" |
12 #include "internal.h" |
| 13 #ifdef WIN32 |
13 #ifdef WIN32 |
| 14 #include <winsock2.h> |
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 } |
|
| 28 #endif |
|
| 29 |
|
| 30 #else |
15 #else |
| 31 #include <arpa/inet.h> |
16 #include <arpa/inet.h> |
| 32 #include <sys/socket.h> |
17 #include <sys/socket.h> |
| 33 #endif |
18 #endif |
| 34 |
19 |
| 190 * notices that haven't been touched in a while |
175 * notices that haven't been touched in a while |
| 191 */ |
176 */ |
| 192 |
177 |
| 193 static struct _Z_InputQ *Z_SearchQueue(ZUnique_Id_t *uid, ZNotice_Kind_t kind) |
178 static struct _Z_InputQ *Z_SearchQueue(ZUnique_Id_t *uid, ZNotice_Kind_t kind) |
| 194 { |
179 { |
| 195 register struct _Z_InputQ *qptr; |
180 register struct _Z_InputQ *qptr; |
| 196 struct _Z_InputQ *next; |
181 struct _Z_InputQ *next; |
| 197 struct timeval tv; |
182 gint64 now; |
| 198 |
183 |
| 199 (void) gettimeofday(&tv, (struct timezone *)0); |
184 now = g_get_monotonic_time(); |
| 200 |
185 |
| 201 qptr = __Q_Head; |
186 qptr = __Q_Head; |
| 202 |
187 |
| 203 while (qptr) { |
188 while (qptr) { |
| 204 if (ZCompareUID(uid, &qptr->uid) && qptr->kind == kind) |
189 if (ZCompareUID(uid, &qptr->uid) && qptr->kind == kind) { |
| 205 return (qptr); |
190 return qptr; |
| 206 next = qptr->next; |
191 } |
| 207 if (qptr->timep && ((time_t)qptr->timep+Z_NOTICETIMELIMIT < tv.tv_sec)) |
192 next = qptr->next; |
| 208 Z_RemQueue(qptr); |
193 if (qptr->time && qptr->time + Z_NOTICETIMELIMIT < now) { |
| 209 qptr = next; |
194 Z_RemQueue(qptr); |
| 210 } |
195 } |
| 211 return (NULL); |
196 qptr = next; |
| |
197 } |
| |
198 return NULL; |
| 212 } |
199 } |
| 213 |
200 |
| 214 /* |
201 /* |
| 215 * Now we delve into really convoluted queue handling and |
202 * Now we delve into really convoluted queue handling and |
| 216 * fragmentation reassembly algorithms and other stuff you probably |
203 * fragmentation reassembly algorithms and other stuff you probably |
| 472 Code_t |
459 Code_t |
| 473 Z_AddNoticeToEntry(struct _Z_InputQ *qptr, ZNotice_t *notice, int part) |
460 Z_AddNoticeToEntry(struct _Z_InputQ *qptr, ZNotice_t *notice, int part) |
| 474 { |
461 { |
| 475 int last, oldfirst, oldlast; |
462 int last, oldfirst, oldlast; |
| 476 struct _Z_Hole *hole, *lasthole; |
463 struct _Z_Hole *hole, *lasthole; |
| 477 struct timeval tv; |
464 |
| 478 |
465 /* Incorporate this notice's checked authentication. */ |
| 479 /* Incorporate this notice's checked authentication. */ |
466 if (notice->z_checked_auth == ZAUTH_FAILED) { |
| 480 if (notice->z_checked_auth == ZAUTH_FAILED) |
467 qptr->auth = ZAUTH_FAILED; |
| 481 qptr->auth = ZAUTH_FAILED; |
468 } else if (notice->z_checked_auth == ZAUTH_NO && qptr->auth != ZAUTH_FAILED) { |
| 482 else if (notice->z_checked_auth == ZAUTH_NO && qptr->auth != ZAUTH_FAILED) |
469 qptr->auth = ZAUTH_NO; |
| 483 qptr->auth = ZAUTH_NO; |
470 } |
| 484 |
471 |
| 485 (void) gettimeofday(&tv, (struct timezone *)0); |
472 qptr->time = g_get_monotonic_time(); |
| 486 qptr->timep = tv.tv_sec; |
|
| 487 |
473 |
| 488 last = part+notice->z_message_len-1; |
474 last = part+notice->z_message_len-1; |
| 489 |
475 |
| 490 hole = qptr->holelist; |
476 hole = qptr->holelist; |
| 491 lasthole = (struct _Z_Hole *) 0; |
477 lasthole = (struct _Z_Hole *) 0; |
| 570 |
556 |
| 571 if (!qptr->holelist) { |
557 if (!qptr->holelist) { |
| 572 if (!qptr->complete) |
558 if (!qptr->complete) |
| 573 __Q_CompleteLength++; |
559 __Q_CompleteLength++; |
| 574 qptr->complete = 1; |
560 qptr->complete = 1; |
| 575 qptr->timep = 0; /* don't time out anymore */ |
561 qptr->time = 0; /* don't time out anymore */ |
| 576 qptr->packet_len = qptr->header_len+qptr->msg_len; |
562 qptr->packet_len = qptr->header_len+qptr->msg_len; |
| 577 if (!(qptr->packet = (char *) malloc((unsigned) qptr->packet_len))) |
563 if (!(qptr->packet = (char *) malloc((unsigned) qptr->packet_len))) |
| 578 return (ENOMEM); |
564 return (ENOMEM); |
| 579 (void) memcpy(qptr->packet, qptr->header, qptr->header_len); |
565 (void) memcpy(qptr->packet, qptr->header, qptr->header_len); |
| 580 (void) memcpy(qptr->packet+qptr->header_len, qptr->msg, |
566 (void) memcpy(qptr->packet+qptr->header_len, qptr->msg, |
| 588 Z_FormatHeader(ZNotice_t *notice, char *buffer, int buffer_len, int *len, |
574 Z_FormatHeader(ZNotice_t *notice, char *buffer, int buffer_len, int *len, |
| 589 Z_AuthProc cert_routine) |
575 Z_AuthProc cert_routine) |
| 590 { |
576 { |
| 591 Code_t retval; |
577 Code_t retval; |
| 592 static char version[BUFSIZ]; /* default init should be all \0 */ |
578 static char version[BUFSIZ]; /* default init should be all \0 */ |
| |
579 gint64 realtime; |
| 593 struct sockaddr_in name; |
580 struct sockaddr_in name; |
| 594 socklen_t namelen = sizeof(name); |
581 socklen_t namelen = sizeof(name); |
| 595 |
582 |
| 596 if (!notice->z_sender) |
583 if (!notice->z_sender) |
| 597 notice->z_sender = ZGetSender(); |
584 notice->z_sender = ZGetSender(); |
| 608 notice->z_port = name.sin_port; |
595 notice->z_port = name.sin_port; |
| 609 } |
596 } |
| 610 |
597 |
| 611 notice->z_multinotice = ""; |
598 notice->z_multinotice = ""; |
| 612 |
599 |
| 613 (void) gettimeofday(¬ice->z_uid.tv, (struct timezone *)0); |
600 realtime = g_get_real_time(); |
| 614 notice->z_uid.tv.tv_sec = htonl((unsigned long) notice->z_uid.tv.tv_sec); |
601 notice->z_uid.tv.tv_sec = realtime / G_USEC_PER_SEC; |
| 615 notice->z_uid.tv.tv_usec = htonl((unsigned long) notice->z_uid.tv.tv_usec); |
602 notice->z_uid.tv.tv_usec = |
| |
603 realtime - notice->z_uid.tv.tv_sec * G_USEC_PER_SEC; |
| |
604 notice->z_uid.tv.tv_sec = htonl((unsigned long)notice->z_uid.tv.tv_sec); |
| |
605 notice->z_uid.tv.tv_usec = htonl((unsigned long)notice->z_uid.tv.tv_usec); |
| 616 |
606 |
| 617 (void) memcpy(¬ice->z_uid.zuid_addr, &__My_addr, sizeof(__My_addr)); |
607 (void) memcpy(¬ice->z_uid.zuid_addr, &__My_addr, sizeof(__My_addr)); |
| 618 |
608 |
| 619 notice->z_multiuid = notice->z_uid; |
609 notice->z_multiuid = notice->z_uid; |
| 620 |
610 |
| 865 |
855 |
| 866 while (offset < notice->z_message_len || !notice->z_message_len) { |
856 while (offset < notice->z_message_len || !notice->z_message_len) { |
| 867 (void) sprintf(multi, "%d/%d", offset, notice->z_message_len); |
857 (void) sprintf(multi, "%d/%d", offset, notice->z_message_len); |
| 868 partnotice.z_multinotice = multi; |
858 partnotice.z_multinotice = multi; |
| 869 if (offset > 0) { |
859 if (offset > 0) { |
| 870 (void) gettimeofday(&partnotice.z_uid.tv, |
860 gint64 realtime = g_get_real_time(); |
| 871 (struct timezone *)0); |
861 partnotice.z_uid.tv.tv_sec = realtime / G_USEC_PER_SEC; |
| 872 partnotice.z_uid.tv.tv_sec = |
862 partnotice.z_uid.tv.tv_usec = |
| 873 htonl((unsigned long) partnotice.z_uid.tv.tv_sec); |
863 realtime - partnotice.z_uid.tv.tv_sec * G_USEC_PER_SEC; |
| 874 partnotice.z_uid.tv.tv_usec = |
864 partnotice.z_uid.tv.tv_sec = |
| 875 htonl((unsigned long) partnotice.z_uid.tv.tv_usec); |
865 htonl((unsigned long)partnotice.z_uid.tv.tv_sec); |
| |
866 partnotice.z_uid.tv.tv_usec = |
| |
867 htonl((unsigned long)partnotice.z_uid.tv.tv_usec); |
| 876 (void) memcpy((char *)&partnotice.z_uid.zuid_addr, &__My_addr, |
868 (void) memcpy((char *)&partnotice.z_uid.zuid_addr, &__My_addr, |
| 877 sizeof(__My_addr)); |
869 sizeof(__My_addr)); |
| 878 } |
870 } |
| 879 message_len = MIN(notice->z_message_len - offset, fragsize); |
871 message_len = MIN(notice->z_message_len - offset, fragsize); |
| 880 partnotice.z_message = (char*)notice->z_message+offset; |
872 partnotice.z_message = (char*)notice->z_message+offset; |