Thu, 01 Jul 2004 15:57:38 +0000
[gaim-migrate @ 10256]
this patch had some little discussion, so the original comments about it
don't make too much sense now.
it makes the log viewwer further collapse things into months for things
older than the current month. for relatively short logs this might not be
wonderful, but it should help with very long logs. see patch #963827
oh and thanks to Cole Kowalski for this
committer: Luke Schierer <lschiere@pidgin.im>
| 2086 | 1 | /* This file is part of the Project Athena Zephyr Notification System. |
| 2 | * It contains source for asynchronous location functions. | |
| 3 | * | |
| 4 | * Created by: Marc Horowitz | |
| 5 | * | |
| 6 | * $Source$ | |
|
8791
655f64e6d1e2
[gaim-migrate @ 9553]
Christian Hammond <chipx86@chipx86.com>
parents:
7475
diff
changeset
|
7 | * $Author: chipx86 $ |
| 2086 | 8 | * |
| 9 | * Copyright (c) 1990,1991 by the Massachusetts Institute of Technology. | |
| 10 | * For copying and distribution information, see the file | |
| 11 | * "mit-copyright.h". | |
| 12 | */ | |
| 13 | /* $Header$ */ | |
| 14 | ||
|
8791
655f64e6d1e2
[gaim-migrate @ 9553]
Christian Hammond <chipx86@chipx86.com>
parents:
7475
diff
changeset
|
15 | #include "internal.h" |
| 2086 | 16 | |
| 17 | #ifndef lint | |
|
8791
655f64e6d1e2
[gaim-migrate @ 9553]
Christian Hammond <chipx86@chipx86.com>
parents:
7475
diff
changeset
|
18 | static const char rcsid_ZAsyncLocate_c[] = "$Id: ZAsyncLocate.c 9553 2004-04-24 09:00:37Z chipx86 $"; |
| 2086 | 19 | #endif |
| 20 | ||
| 21 | Code_t ZRequestLocations(user, zald, kind, auth) | |
| 7261 | 22 | const char *user; |
| 2086 | 23 | register ZAsyncLocateData_t *zald; |
| 24 | ZNotice_Kind_t kind; /* UNSAFE, UNACKED, or ACKED */ | |
| 25 | Z_AuthProc auth; | |
| 26 | { | |
| 27 | int retval; | |
| 28 | ZNotice_t notice; | |
| 29 | ||
| 30 | if (ZGetFD() < 0) | |
|
7475
987384816492
[gaim-migrate @ 8088]
Mark Doliner <markdoliner@pidgin.im>
parents:
7261
diff
changeset
|
31 | if ((retval = ZOpenPort((unsigned short *)0)) != ZERR_NONE) |
| 2086 | 32 | return (retval); |
| 33 | ||
| 34 | (void) memset((char *)¬ice, 0, sizeof(notice)); | |
| 35 | notice.z_kind = kind; | |
| 36 | notice.z_port = __Zephyr_port; | |
| 37 | notice.z_class = LOCATE_CLASS; | |
| 38 | notice.z_class_inst = user; | |
| 39 | notice.z_opcode = LOCATE_LOCATE; | |
| 40 | notice.z_sender = 0; | |
| 41 | notice.z_recipient = ""; | |
| 42 | notice.z_default_format = ""; | |
| 43 | notice.z_message_len = 0; | |
| 44 | ||
| 45 | if ((retval = ZSendNotice(¬ice, auth)) != ZERR_NONE) | |
| 46 | return(retval); | |
| 47 | ||
| 48 | if ((zald->user = (char *) malloc(strlen(user)+1)) == NULL) { | |
| 49 | return(ENOMEM); | |
| 50 | } | |
| 51 | if ((zald->version = (char *) malloc(strlen(notice.z_version)+1)) == NULL) { | |
| 52 | free(zald->user); | |
| 53 | return(ENOMEM); | |
| 54 | } | |
| 55 | zald->uid = notice.z_multiuid; | |
| 56 | strcpy(zald->user,user); | |
| 57 | strcpy(zald->version,notice.z_version); | |
| 58 | ||
| 59 | return(ZERR_NONE); | |
| 60 | } | |
| 61 | ||
| 62 | Code_t ZParseLocations(notice,zald,nlocs,user) | |
| 63 | register ZNotice_t *notice; | |
| 64 | register ZAsyncLocateData_t *zald; | |
| 65 | int *nlocs; | |
| 66 | char **user; | |
| 67 | { | |
| 68 | char *ptr, *end; | |
| 69 | int i; | |
| 70 | ||
| 71 | ZFlushLocations(); /* This never fails (this function is part of the | |
| 72 | library, so it is allowed to know this). */ | |
| 73 | ||
| 74 | /* non-matching protocol version numbers means the | |
| 75 | server is probably an older version--must punt */ | |
| 76 | ||
| 77 | if (zald && strcmp(notice->z_version, zald->version)) | |
| 78 | return(ZERR_VERS); | |
| 79 | ||
| 80 | if (notice->z_kind == SERVNAK) | |
| 81 | return (ZERR_SERVNAK); | |
| 82 | ||
| 83 | /* flag ACKs as special */ | |
| 84 | if (notice->z_kind == SERVACK && | |
| 85 | !strcmp(notice->z_opcode, LOCATE_LOCATE)) { | |
| 86 | *nlocs = -1; | |
| 87 | return(ZERR_NONE); | |
| 88 | } | |
| 89 | ||
| 90 | if (notice->z_kind != ACKED) | |
| 91 | return (ZERR_INTERNAL); | |
| 92 | ||
| 93 | end = notice->z_message+notice->z_message_len; | |
| 94 | ||
| 95 | __locate_num = 0; | |
| 96 | ||
| 97 | for (ptr=notice->z_message;ptr<end;ptr++) | |
| 98 | if (!*ptr) | |
| 99 | __locate_num++; | |
| 100 | ||
| 101 | __locate_num /= 3; | |
| 102 | ||
| 103 | if (__locate_num) | |
| 104 | { | |
| 105 | __locate_list = (ZLocations_t *)malloc((unsigned)__locate_num* | |
| 106 | sizeof(ZLocations_t)); | |
| 107 | if (!__locate_list) | |
| 108 | return (ENOMEM); | |
| 109 | } else { | |
| 110 | __locate_list = 0; | |
| 111 | } | |
| 112 | ||
| 113 | for (ptr=notice->z_message, i=0; i<__locate_num; i++) { | |
| 114 | unsigned int len; | |
| 115 | ||
| 116 | len = strlen (ptr) + 1; | |
| 117 | __locate_list[i].host = (char *) malloc(len); | |
| 118 | if (!__locate_list[i].host) | |
| 119 | return (ENOMEM); | |
| 120 | (void) strcpy(__locate_list[i].host, ptr); | |
| 121 | ptr += len; | |
| 122 | ||
| 123 | len = strlen (ptr) + 1; | |
| 124 | __locate_list[i].time = (char *) malloc(len); | |
| 125 | if (!__locate_list[i].time) | |
| 126 | return (ENOMEM); | |
| 127 | (void) strcpy(__locate_list[i].time, ptr); | |
| 128 | ptr += len; | |
| 129 | ||
| 130 | len = strlen (ptr) + 1; | |
| 131 | __locate_list[i].tty = (char *) malloc(len); | |
| 132 | if (!__locate_list[i].tty) | |
| 133 | return (ENOMEM); | |
| 134 | (void) strcpy(__locate_list[i].tty, ptr); | |
| 135 | ptr += len; | |
| 136 | } | |
| 137 | ||
| 138 | __locate_next = 0; | |
| 139 | *nlocs = __locate_num; | |
| 140 | if (user) { | |
| 141 | if (zald) { | |
| 142 | if ((*user = (char *) malloc(strlen(zald->user)+1)) == NULL) | |
| 143 | return(ENOMEM); | |
| 144 | strcpy(*user,zald->user); | |
| 145 | } else { | |
| 146 | if ((*user = (char *) malloc(strlen(notice->z_class_inst)+1)) == NULL) | |
| 147 | return(ENOMEM); | |
| 148 | strcpy(*user,notice->z_class_inst); | |
| 149 | } | |
| 150 | } | |
| 151 | return (ZERR_NONE); | |
| 152 | } | |
| 153 | ||
| 154 | int ZCompareALDPred(notice, zald) | |
| 155 | ZNotice_t *notice; | |
| 156 | void *zald; | |
| 157 | { | |
| 158 | return(ZCompareUID(&(notice->z_multiuid), | |
| 159 | &(((ZAsyncLocateData_t *) zald)->uid))); | |
| 160 | } | |
| 161 | ||
| 162 | void ZFreeALD(zald) | |
| 163 | register ZAsyncLocateData_t *zald; | |
| 164 | { | |
| 165 | if (!zald) return; | |
| 166 | ||
| 167 | if (zald->user) free(zald->user); | |
| 168 | if (zald->version) free(zald->version); | |
| 169 | (void) memset(zald, 0, sizeof(*zald)); | |
| 170 | } |