1 /* This file is part of the Project Athena Zephyr Notification System.
2 * It contains source for asynchronous location functions.
4 * Created by: Marc Horowitz
6 * $Id: ZAsyncLocate.c,v 1.6 1999/01/22 23:19:02 ghudson Exp $
8 * Copyright (c) 1990,1991 by the Massachusetts Institute of Technology.
9 * For copying and distribution information, see the file
16 static const char rcsid_ZAsyncLocate_c[] = "$Id: ZAsyncLocate.c,v 1.6 1999/01/22 23:19:02 ghudson Exp $";
19 Code_t ZRequestLocations(user, zald, kind, auth)
21 register ZAsyncLocateData_t *zald;
22 ZNotice_Kind_t kind; /* UNSAFE, UNACKED, or ACKED */
29 if ((retval = ZOpenPort((u_short *)0)) != ZERR_NONE)
32 (void) memset((char *)¬ice, 0, sizeof(notice));
34 notice.z_port = __Zephyr_port;
35 notice.z_class = LOCATE_CLASS;
36 notice.z_class_inst = user;
37 notice.z_opcode = LOCATE_LOCATE;
39 notice.z_recipient = "";
40 notice.z_default_format = "";
41 notice.z_message_len = 0;
43 if ((retval = ZSendNotice(¬ice, auth)) != ZERR_NONE)
46 if ((zald->user = (char *) malloc(strlen(user)+1)) == NULL) {
49 if ((zald->version = (char *) malloc(strlen(notice.z_version)+1)) == NULL) {
53 zald->uid = notice.z_multiuid;
54 strcpy(zald->user,user);
55 strcpy(zald->version,notice.z_version);
60 Code_t ZParseLocations(notice,zald,nlocs,user)
61 register ZNotice_t *notice;
62 register ZAsyncLocateData_t *zald;
69 ZFlushLocations(); /* This never fails (this function is part of the
70 library, so it is allowed to know this). */
72 /* non-matching protocol version numbers means the
73 server is probably an older version--must punt */
75 if (zald && strcmp(notice->z_version, zald->version))
78 if (notice->z_kind == SERVNAK)
79 return (ZERR_SERVNAK);
81 /* flag ACKs as special */
82 if (notice->z_kind == SERVACK &&
83 !strcmp(notice->z_opcode, LOCATE_LOCATE)) {
88 if (notice->z_kind != ACKED)
89 return (ZERR_INTERNAL);
91 end = notice->z_message+notice->z_message_len;
95 for (ptr=notice->z_message;ptr<end;ptr++)
103 __locate_list = (ZLocations_t *)malloc((unsigned)__locate_num*
104 sizeof(ZLocations_t));
111 for (ptr=notice->z_message, i=0; i<__locate_num; i++) {
114 len = strlen (ptr) + 1;
115 __locate_list[i].host = (char *) malloc(len);
116 if (!__locate_list[i].host)
118 (void) strcpy(__locate_list[i].host, ptr);
121 len = strlen (ptr) + 1;
122 __locate_list[i].time = (char *) malloc(len);
123 if (!__locate_list[i].time)
125 (void) strcpy(__locate_list[i].time, ptr);
128 len = strlen (ptr) + 1;
129 __locate_list[i].tty = (char *) malloc(len);
130 if (!__locate_list[i].tty)
132 (void) strcpy(__locate_list[i].tty, ptr);
137 *nlocs = __locate_num;
140 if ((*user = (char *) malloc(strlen(zald->user)+1)) == NULL)
142 strcpy(*user,zald->user);
144 if ((*user = (char *) malloc(strlen(notice->z_class_inst)+1)) == NULL)
146 strcpy(*user,notice->z_class_inst);
152 int ZCompareALDPred(notice, zald)
156 return(ZCompareUID(&(notice->z_multiuid),
157 &(((ZAsyncLocateData_t *) zald)->uid)));
161 register ZAsyncLocateData_t *zald;
165 if (zald->user) free(zald->user);
166 if (zald->version) free(zald->version);
167 (void) memset(zald, 0, sizeof(*zald));