Sun, 10 Nov 2019 05:20:10 -0500
zephyr: Modernize K&R function prototypes.
| 2086 | 1 | /* This file is part of the Project Athena Zephyr Notification System. |
| 2 | * It contains source for the ZParseNotice function. | |
| 3 | * | |
| 4 | * Created by: Robert French | |
| 5 | * | |
| 6 | * Copyright (c) 1987,1991 by the Massachusetts Institute of Technology. | |
| 7 | * For copying and distribution information, see the file | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
8 | * "mit-copyright.h". |
| 2086 | 9 | */ |
| 10 | ||
|
8792
b0645c9dc276
[gaim-migrate @ 9554]
Christian Hammond <chipx86@chipx86.com>
parents:
7475
diff
changeset
|
11 | #include "internal.h" |
| 2086 | 12 | |
| 13 | /* Assume that strlen is efficient on this machine... */ | |
| 14 | #define next_field(ptr) ptr += strlen (ptr) + 1 | |
| 15 | ||
| 16 | #if defined (__GNUC__) && defined (__vax__) | |
| 17 | #undef next_field | |
| 18 | static __inline__ char * Istrend (char *str) { | |
| 19 | /* | |
| 20 | * This should be faster on VAX models outside the 2 series. Don't | |
| 21 | * use it if you are using MicroVAX 2 servers. If you are using a | |
| 22 | * VS2 server, use something like | |
| 23 | * #define next_field(ptr) while(*ptr++) | |
| 24 | * instead of this code. | |
| 25 | * | |
| 26 | * This requires use of GCC to get the optimized code, but | |
| 27 | * everybody uses GCC, don't they? :-) | |
| 28 | */ | |
| 29 | register char *str2 asm ("r1"); | |
| 30 | /* Assumes that no field is longer than 64K.... */ | |
| 31 | asm ("locc $0,$65535,(%1)" : "=r" (str2) : "r" (str) : "r0"); | |
| 32 | return str2; | |
| 33 | } | |
| 34 | #define next_field(ptr) ptr = Istrend (ptr) + 1 | |
| 35 | #endif | |
| 36 | ||
| 37 | #ifdef mips | |
| 38 | #undef next_field | |
| 39 | /* | |
| 40 | * The compiler doesn't optimize this macro as well as it does the | |
| 41 | * following function. | |
| 42 | */ | |
| 43 | #define next_fieldXXX(ptr) do{register unsigned c1,c2;c1= *ptr; \ | |
| 44 | while((ptr++,c2= *ptr,c1)&&(ptr++,c1= *ptr,c2));}while(0) | |
| 45 | static char *next_field_1 (s) char *s; { | |
| 46 | /* | |
| 47 | * Calling overhead is still present, but this routine is faster | |
| 48 | * than strlen, and doesn't bother with some of the other math | |
| 49 | * that we'd just have to undo later anyways. | |
| 50 | */ | |
| 51 | register unsigned c1 = *s, c2; | |
| 52 | while (1) { | |
| 53 | s++; c2 = *s; if (c1 == 0) break; | |
| 54 | s++; c1 = *s; if (c2 == 0) break; | |
| 55 | s++; c2 = *s; if (c1 == 0) break; | |
| 56 | s++; c1 = *s; if (c2 == 0) break; | |
| 57 | } | |
| 58 | return s; | |
| 59 | } | |
| 60 | #define next_field(ptr) ptr=next_field_1(ptr) | |
| 61 | #endif | |
| 62 | ||
|
40166
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33892
diff
changeset
|
63 | Code_t |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33892
diff
changeset
|
64 | ZParseNotice(char *buffer, int len, ZNotice_t *notice) |
| 2086 | 65 | { |
| 66 | char *ptr, *end; | |
| 67 | unsigned long temp; | |
| 68 | int maj, numfields, i; | |
| 69 | ||
| 70 | #ifdef __LINE__ | |
| 71 | int lineno; | |
| 72 | /* Note: This definition of BAD eliminates lint and compiler | |
| 73 | * complains about the "while (0)", but require that the macro not | |
| 74 | * be used as the "then" part of an "if" statement that also has | |
| 75 | * an "else" clause. | |
| 76 | */ | |
| 77 | #define BAD_PACKET {lineno=__LINE__;goto badpkt;} | |
| 78 | /* This one gets lint/compiler complaints. */ | |
| 79 | /*#define BAD do{lineno=__LINE__;goto badpkt;}while(0)*/ | |
| 80 | #else | |
| 81 | #define BAD_PACKET goto badpkt | |
| 82 | #endif | |
| 83 | ||
| 84 | (void) memset((char *)notice, 0, sizeof(ZNotice_t)); | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
85 | |
| 2086 | 86 | ptr = buffer; |
| 87 | end = buffer+len; | |
| 88 | ||
| 89 | notice->z_packet = buffer; | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
90 | |
| 2086 | 91 | notice->z_version = ptr; |
| 92 | if (strncmp(ptr, ZVERSIONHDR, sizeof(ZVERSIONHDR) - 1)) | |
| 93 | return (ZERR_VERS); | |
| 94 | ptr += sizeof(ZVERSIONHDR) - 1; | |
| 95 | if (!*ptr) { | |
| 96 | #ifdef Z_DEBUG | |
| 97 | Z_debug ("ZParseNotice: null version string"); | |
| 98 | #endif | |
| 99 | return ZERR_BADPKT; | |
| 100 | } | |
| 101 | maj = atoi(ptr); | |
| 102 | if (maj != ZVERSIONMAJOR) | |
| 103 | return (ZERR_VERS); | |
| 104 | next_field (ptr); | |
| 105 | ||
| 106 | if (ZReadAscii32(ptr, end-ptr, &temp) == ZERR_BADFIELD) | |
| 107 | BAD_PACKET; | |
| 108 | numfields = temp; | |
| 109 | next_field (ptr); | |
| 110 | ||
| 111 | /*XXX 3 */ | |
| 112 | numfields -= 2; /* numfields, version, and checksum */ | |
| 113 | if (numfields < 0) { | |
| 114 | #ifdef __LINE__ | |
| 115 | lineno = __LINE__; | |
| 116 | badpkt: | |
| 117 | #ifdef Z_DEBUG | |
| 118 | Z_debug ("ZParseNotice: bad packet from %s/%d (line %d)", | |
| 119 | inet_ntoa (notice->z_uid.zuid_addr.s_addr), | |
| 120 | notice->z_port, lineno); | |
|
33892
ef97228bc5f0
Fix most of warnings for gtk2 and linux
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
31294
diff
changeset
|
121 | #else |
|
ef97228bc5f0
Fix most of warnings for gtk2 and linux
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
31294
diff
changeset
|
122 | /* We won't use lineno anywhere else, so let's silence a warning. */ |
|
ef97228bc5f0
Fix most of warnings for gtk2 and linux
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
31294
diff
changeset
|
123 | (void)lineno; |
| 2086 | 124 | #endif |
| 125 | #else | |
| 126 | badpkt: | |
| 127 | #ifdef Z_DEBUG | |
| 128 | Z_debug ("ZParseNotice: bad packet from %s/%d", | |
| 129 | inet_ntoa (notice->z_uid.zuid_addr.s_addr), | |
| 130 | notice->z_port); | |
| 131 | #endif | |
| 132 | #endif | |
| 133 | return ZERR_BADPKT; | |
| 134 | } | |
| 135 | ||
| 136 | if (numfields) { | |
| 137 | if (ZReadAscii32(ptr, end-ptr, &temp) == ZERR_BADFIELD) | |
| 138 | BAD_PACKET; | |
| 139 | notice->z_kind = temp; | |
| 140 | numfields--; | |
| 141 | next_field (ptr); | |
| 142 | } | |
| 143 | else | |
| 144 | BAD_PACKET; | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
145 | |
| 2086 | 146 | if (numfields) { |
| 147 | if (ZReadAscii(ptr, end-ptr, (unsigned char *)¬ice->z_uid, | |
| 148 | sizeof(ZUnique_Id_t)) == ZERR_BADFIELD) | |
| 149 | BAD_PACKET; | |
|
7475
987384816492
[gaim-migrate @ 8088]
Mark Doliner <markdoliner@pidgin.im>
parents:
2086
diff
changeset
|
150 | notice->z_time.tv_sec = ntohl((unsigned long) notice->z_uid.tv.tv_sec); |
|
987384816492
[gaim-migrate @ 8088]
Mark Doliner <markdoliner@pidgin.im>
parents:
2086
diff
changeset
|
151 | notice->z_time.tv_usec = ntohl((unsigned long) notice->z_uid.tv.tv_usec); |
| 2086 | 152 | numfields--; |
| 153 | next_field (ptr); | |
| 154 | } | |
| 155 | else | |
| 156 | BAD_PACKET; | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
157 | |
| 2086 | 158 | if (numfields) { |
| 159 | if (ZReadAscii16(ptr, end-ptr, ¬ice->z_port) == ZERR_BADFIELD) | |
| 160 | BAD_PACKET; | |
| 161 | notice->z_port = htons(notice->z_port); | |
| 162 | numfields--; | |
| 163 | next_field (ptr); | |
| 164 | } | |
| 165 | else | |
| 166 | BAD_PACKET; | |
| 167 | ||
| 168 | if (numfields) { | |
| 169 | if (ZReadAscii32(ptr, end-ptr, &temp) == ZERR_BADFIELD) | |
| 170 | BAD_PACKET; | |
| 171 | notice->z_auth = temp; | |
| 172 | numfields--; | |
| 173 | next_field (ptr); | |
| 174 | } | |
| 175 | else | |
| 176 | BAD_PACKET; | |
| 177 | notice->z_checked_auth = ZAUTH_UNSET; | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
178 | |
| 2086 | 179 | if (numfields) { |
| 180 | if (ZReadAscii32(ptr, end-ptr, &temp) == ZERR_BADFIELD) | |
| 181 | BAD_PACKET; | |
| 182 | notice->z_authent_len = temp; | |
| 183 | numfields--; | |
| 184 | next_field (ptr); | |
| 185 | } | |
| 186 | else | |
| 187 | BAD_PACKET; | |
| 188 | ||
| 189 | if (numfields) { | |
| 190 | notice->z_ascii_authent = ptr; | |
| 191 | numfields--; | |
| 192 | next_field (ptr); | |
| 193 | } | |
| 194 | else | |
| 195 | BAD_PACKET; | |
| 196 | ||
| 197 | if (numfields) { | |
| 198 | notice->z_class = ptr; | |
| 199 | numfields--; | |
| 200 | next_field (ptr); | |
| 201 | } | |
| 202 | else | |
| 203 | notice->z_class = ""; | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
204 | |
| 2086 | 205 | if (numfields) { |
| 206 | notice->z_class_inst = ptr; | |
| 207 | numfields--; | |
| 208 | next_field (ptr); | |
| 209 | } | |
| 210 | else | |
| 211 | notice->z_class_inst = ""; | |
| 212 | ||
| 213 | if (numfields) { | |
| 214 | notice->z_opcode = ptr; | |
| 215 | numfields--; | |
| 216 | next_field (ptr); | |
| 217 | } | |
| 218 | else | |
| 219 | notice->z_opcode = ""; | |
| 220 | ||
| 221 | if (numfields) { | |
| 222 | notice->z_sender = ptr; | |
| 223 | numfields--; | |
| 224 | next_field (ptr); | |
| 225 | } | |
| 226 | else | |
| 227 | notice->z_sender = ""; | |
| 228 | ||
| 229 | if (numfields) { | |
| 230 | notice->z_recipient = ptr; | |
| 231 | numfields--; | |
| 232 | next_field (ptr); | |
| 233 | } | |
| 234 | else | |
| 235 | notice->z_recipient = ""; | |
| 236 | ||
| 237 | if (numfields) { | |
| 238 | notice->z_default_format = ptr; | |
| 239 | numfields--; | |
| 240 | next_field (ptr); | |
| 241 | } | |
| 242 | else | |
| 243 | notice->z_default_format = ""; | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
244 | |
| 2086 | 245 | /*XXX*/ |
| 246 | if (ZReadAscii32(ptr, end-ptr, &temp) == ZERR_BADFIELD) | |
| 247 | BAD_PACKET; | |
| 248 | notice->z_checksum = temp; | |
| 249 | numfields--; | |
| 250 | next_field (ptr); | |
| 251 | ||
| 252 | if (numfields) { | |
| 253 | notice->z_multinotice = ptr; | |
| 254 | numfields--; | |
| 255 | next_field (ptr); | |
| 256 | } | |
| 257 | else | |
| 258 | notice->z_multinotice = ""; | |
| 259 | ||
| 260 | if (numfields) { | |
| 261 | if (ZReadAscii(ptr, end-ptr, (unsigned char *)¬ice->z_multiuid, | |
| 262 | sizeof(ZUnique_Id_t)) == ZERR_BADFIELD) | |
| 263 | BAD_PACKET; | |
|
7475
987384816492
[gaim-migrate @ 8088]
Mark Doliner <markdoliner@pidgin.im>
parents:
2086
diff
changeset
|
264 | notice->z_time.tv_sec = ntohl((unsigned long) notice->z_multiuid.tv.tv_sec); |
|
987384816492
[gaim-migrate @ 8088]
Mark Doliner <markdoliner@pidgin.im>
parents:
2086
diff
changeset
|
265 | notice->z_time.tv_usec = ntohl((unsigned long) notice->z_multiuid.tv.tv_usec); |
| 2086 | 266 | numfields--; |
| 267 | next_field (ptr); | |
| 268 | } | |
| 269 | else | |
| 270 | notice->z_multiuid = notice->z_uid; | |
| 271 | ||
| 272 | for (i=0;i<Z_MAXOTHERFIELDS && numfields;i++,numfields--) { | |
| 273 | notice->z_other_fields[i] = ptr; | |
| 274 | next_field (ptr); | |
| 275 | } | |
| 276 | notice->z_num_other_fields = i; | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
277 | |
| 2086 | 278 | for (i=0;i<numfields;i++) |
| 279 | next_field (ptr); | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
280 | |
|
7475
987384816492
[gaim-migrate @ 8088]
Mark Doliner <markdoliner@pidgin.im>
parents:
2086
diff
changeset
|
281 | notice->z_message = (void *)ptr; |
| 2086 | 282 | notice->z_message_len = len-(ptr-buffer); |
| 283 | ||
| 284 | return (ZERR_NONE); | |
| 285 | } |