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 asynchronous location functions. | |
| 3 | * | |
| 4 | * Created by: Marc Horowitz | |
| 5 | * | |
| 6 | * Copyright (c) 1990,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 | ||
|
8791
655f64e6d1e2
[gaim-migrate @ 9553]
Christian Hammond <chipx86@chipx86.com>
parents:
7475
diff
changeset
|
11 | #include "internal.h" |
|
38258
9a6551eba09c
Replace !strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents:
31955
diff
changeset
|
12 | #include "util.h" |
| 2086 | 13 | |
|
40166
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
38358
diff
changeset
|
14 | Code_t |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
38358
diff
changeset
|
15 | ZRequestLocations(const char *user, ZAsyncLocateData_t *zald, |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
38358
diff
changeset
|
16 | ZNotice_Kind_t kind, /* UNSAFE, UNACKED, or ACKED */ |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
38358
diff
changeset
|
17 | Z_AuthProc auth) |
| 2086 | 18 | { |
| 19 | int retval; | |
| 20 | ZNotice_t notice; | |
|
31955
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
21 | size_t userlen, versionlen; |
| 2086 | 22 | |
| 23 | if (ZGetFD() < 0) | |
|
7475
987384816492
[gaim-migrate @ 8088]
Mark Doliner <markdoliner@pidgin.im>
parents:
7261
diff
changeset
|
24 | if ((retval = ZOpenPort((unsigned short *)0)) != ZERR_NONE) |
| 2086 | 25 | return (retval); |
| 26 | ||
| 27 | (void) memset((char *)¬ice, 0, sizeof(notice)); | |
| 28 | notice.z_kind = kind; | |
| 29 | notice.z_port = __Zephyr_port; | |
| 30 | notice.z_class = LOCATE_CLASS; | |
| 31 | notice.z_class_inst = user; | |
| 32 | notice.z_opcode = LOCATE_LOCATE; | |
| 33 | notice.z_sender = 0; | |
| 34 | notice.z_recipient = ""; | |
| 35 | notice.z_default_format = ""; | |
| 36 | notice.z_message_len = 0; | |
| 37 | ||
| 38 | if ((retval = ZSendNotice(¬ice, auth)) != ZERR_NONE) | |
| 39 | return(retval); | |
| 40 | ||
|
31955
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
41 | userlen = strlen(user) + 1; |
|
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
42 | versionlen = strlen(notice.z_version) + 1; |
|
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
43 | if ((zald->user = (char *) malloc(userlen)) == NULL) { |
| 2086 | 44 | return(ENOMEM); |
| 45 | } | |
|
31955
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
46 | if ((zald->version = (char *) malloc(versionlen)) == NULL) { |
| 2086 | 47 | free(zald->user); |
| 48 | return(ENOMEM); | |
| 49 | } | |
| 50 | zald->uid = notice.z_multiuid; | |
|
31955
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
51 | g_strlcpy(zald->user,user,userlen); |
|
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
52 | g_strlcpy(zald->version,notice.z_version,versionlen); |
| 2086 | 53 | |
| 54 | return(ZERR_NONE); | |
| 55 | } | |
| 56 | ||
|
40166
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
38358
diff
changeset
|
57 | Code_t |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
38358
diff
changeset
|
58 | ZParseLocations(ZNotice_t *notice, ZAsyncLocateData_t *zald, int *nlocs, |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
38358
diff
changeset
|
59 | char **user) |
| 2086 | 60 | { |
| 61 | char *ptr, *end; | |
| 62 | int i; | |
| 63 | ||
| 64 | ZFlushLocations(); /* This never fails (this function is part of the | |
| 65 | library, so it is allowed to know this). */ | |
| 66 | ||
| 67 | /* non-matching protocol version numbers means the | |
| 68 | server is probably an older version--must punt */ | |
| 69 | ||
|
38259
c593fc9f5438
Replace strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents:
38258
diff
changeset
|
70 | if (zald && !purple_strequal(notice->z_version, zald->version)) |
| 2086 | 71 | return(ZERR_VERS); |
| 72 | ||
| 73 | if (notice->z_kind == SERVNAK) | |
| 74 | return (ZERR_SERVNAK); | |
| 75 | ||
| 76 | /* flag ACKs as special */ | |
| 77 | if (notice->z_kind == SERVACK && | |
|
38258
9a6551eba09c
Replace !strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents:
31955
diff
changeset
|
78 | purple_strequal(notice->z_opcode, LOCATE_LOCATE)) { |
| 2086 | 79 | *nlocs = -1; |
| 80 | return(ZERR_NONE); | |
| 81 | } | |
| 82 | ||
| 83 | if (notice->z_kind != ACKED) | |
| 84 | return (ZERR_INTERNAL); | |
| 85 | ||
| 86 | end = notice->z_message+notice->z_message_len; | |
| 87 | ||
| 88 | __locate_num = 0; | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
89 | |
| 2086 | 90 | for (ptr=notice->z_message;ptr<end;ptr++) |
| 91 | if (!*ptr) | |
| 92 | __locate_num++; | |
| 93 | ||
| 94 | __locate_num /= 3; | |
| 95 | ||
| 96 | if (__locate_num) | |
| 97 | { | |
| 98 | __locate_list = (ZLocations_t *)malloc((unsigned)__locate_num* | |
| 99 | sizeof(ZLocations_t)); | |
| 100 | if (!__locate_list) | |
| 101 | return (ENOMEM); | |
| 102 | } else { | |
|
37390
209a1350d87f
Assign pointers to NULL rather than 0.
Michael McConville <mmcconville@mykolab.com>
parents:
37389
diff
changeset
|
103 | __locate_list = NULL; |
| 2086 | 104 | } |
| 105 | ||
| 106 | for (ptr=notice->z_message, i=0; i<__locate_num; i++) { | |
| 107 | unsigned int len; | |
| 108 | ||
| 109 | len = strlen (ptr) + 1; | |
| 110 | __locate_list[i].host = (char *) malloc(len); | |
| 111 | if (!__locate_list[i].host) | |
| 112 | return (ENOMEM); | |
|
31954
e5631d5590cc
Replace numerous strcpy() invocations with strlcpy() in Zephyr.
Ethan Blanton <elb@pidgin.im>
parents:
31294
diff
changeset
|
113 | g_strlcpy(__locate_list[i].host, ptr,len); |
| 2086 | 114 | ptr += len; |
| 115 | ||
| 116 | len = strlen (ptr) + 1; | |
| 117 | __locate_list[i].time = (char *) malloc(len); | |
| 118 | if (!__locate_list[i].time) | |
| 119 | return (ENOMEM); | |
|
31954
e5631d5590cc
Replace numerous strcpy() invocations with strlcpy() in Zephyr.
Ethan Blanton <elb@pidgin.im>
parents:
31294
diff
changeset
|
120 | g_strlcpy(__locate_list[i].time, ptr,len); |
| 2086 | 121 | ptr += len; |
| 122 | ||
| 123 | len = strlen (ptr) + 1; | |
| 124 | __locate_list[i].tty = (char *) malloc(len); | |
| 125 | if (!__locate_list[i].tty) | |
| 126 | return (ENOMEM); | |
|
31954
e5631d5590cc
Replace numerous strcpy() invocations with strlcpy() in Zephyr.
Ethan Blanton <elb@pidgin.im>
parents:
31294
diff
changeset
|
127 | g_strlcpy(__locate_list[i].tty, ptr,len); |
| 2086 | 128 | ptr += len; |
| 129 | } | |
| 130 | ||
| 131 | __locate_next = 0; | |
| 132 | *nlocs = __locate_num; | |
| 133 | if (user) { | |
|
38258
9a6551eba09c
Replace !strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents:
31955
diff
changeset
|
134 | size_t len; |
| 2086 | 135 | if (zald) { |
|
31955
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
136 | len = strlen(zald->user) + 1; |
|
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
137 | if ((*user = (char *) malloc(len)) == NULL) |
| 2086 | 138 | return(ENOMEM); |
|
31955
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
139 | g_strlcpy(*user,zald->user,len); |
| 2086 | 140 | } else { |
|
31955
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
141 | len = strlen(notice->z_class_inst) + 1; |
|
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
142 | if ((*user = (char *) malloc(len)) == NULL) |
| 2086 | 143 | return(ENOMEM); |
|
31955
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
144 | g_strlcpy(*user,notice->z_class_inst,len); |
| 2086 | 145 | } |
| 146 | } | |
| 147 | return (ZERR_NONE); | |
| 148 | } | |
| 149 | ||
|
40166
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
38358
diff
changeset
|
150 | int |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
38358
diff
changeset
|
151 | ZCompareALDPred(ZNotice_t *notice, void *zald) |
| 2086 | 152 | { |
| 153 | return(ZCompareUID(&(notice->z_multiuid), | |
| 154 | &(((ZAsyncLocateData_t *) zald)->uid))); | |
| 155 | } | |
| 156 | ||
|
40166
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
38358
diff
changeset
|
157 | void |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
38358
diff
changeset
|
158 | ZFreeALD(ZAsyncLocateData_t *zald) |
| 2086 | 159 | { |
| 160 | if (!zald) return; | |
| 161 | ||
|
37389
7240fd8e3462
free() and g_free() are specified to be NULL-safe. Remove NULL checks.
Michael McConville <mmcconville@mykolab.com>
parents:
31955
diff
changeset
|
162 | free(zald->user); |
|
7240fd8e3462
free() and g_free() are specified to be NULL-safe. Remove NULL checks.
Michael McConville <mmcconville@mykolab.com>
parents:
31955
diff
changeset
|
163 | free(zald->version); |
| 2086 | 164 | (void) memset(zald, 0, sizeof(*zald)); |
| 165 | } |