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
7 * $Author: warmenhoven $
9 * Copyright (c) 1990,1991 by the Massachusetts Institute of Technology.
10 * For copying and distribution information, see the file
18 static const char rcsid_ZAsyncLocate_c
[] = "$Id: ZAsyncLocate.c 2096 2001-07-31 01:00:39Z warmenhoven $";
21 Code_t
ZRequestLocations(user
, zald
, kind
, auth
)
23 register ZAsyncLocateData_t
*zald
;
24 ZNotice_Kind_t kind
; /* UNSAFE, UNACKED, or ACKED */
31 if ((retval
= ZOpenPort((u_short
*)0)) != ZERR_NONE
)
34 (void) memset((char *)¬ice
, 0, sizeof(notice
));
36 notice
.z_port
= __Zephyr_port
;
37 notice
.z_class
= LOCATE_CLASS
;
38 notice
.z_class_inst
= user
;
39 notice
.z_opcode
= LOCATE_LOCATE
;
41 notice
.z_recipient
= "";
42 notice
.z_default_format
= "";
43 notice
.z_message_len
= 0;
45 if ((retval
= ZSendNotice(¬ice
, auth
)) != ZERR_NONE
)
48 if ((zald
->user
= (char *) malloc(strlen(user
)+1)) == NULL
) {
51 if ((zald
->version
= (char *) malloc(strlen(notice
.z_version
)+1)) == NULL
) {
55 zald
->uid
= notice
.z_multiuid
;
56 strcpy(zald
->user
,user
);
57 strcpy(zald
->version
,notice
.z_version
);
62 Code_t
ZParseLocations(notice
,zald
,nlocs
,user
)
63 register ZNotice_t
*notice
;
64 register ZAsyncLocateData_t
*zald
;
71 ZFlushLocations(); /* This never fails (this function is part of the
72 library, so it is allowed to know this). */
74 /* non-matching protocol version numbers means the
75 server is probably an older version--must punt */
77 if (zald
&& strcmp(notice
->z_version
, zald
->version
))
80 if (notice
->z_kind
== SERVNAK
)
81 return (ZERR_SERVNAK
);
83 /* flag ACKs as special */
84 if (notice
->z_kind
== SERVACK
&&
85 !strcmp(notice
->z_opcode
, LOCATE_LOCATE
)) {
90 if (notice
->z_kind
!= ACKED
)
91 return (ZERR_INTERNAL
);
93 end
= notice
->z_message
+notice
->z_message_len
;
97 for (ptr
=notice
->z_message
;ptr
<end
;ptr
++)
105 __locate_list
= (ZLocations_t
*)malloc((unsigned)__locate_num
*
106 sizeof(ZLocations_t
));
113 for (ptr
=notice
->z_message
, i
=0; i
<__locate_num
; i
++) {
116 len
= strlen (ptr
) + 1;
117 __locate_list
[i
].host
= (char *) malloc(len
);
118 if (!__locate_list
[i
].host
)
120 (void) strcpy(__locate_list
[i
].host
, ptr
);
123 len
= strlen (ptr
) + 1;
124 __locate_list
[i
].time
= (char *) malloc(len
);
125 if (!__locate_list
[i
].time
)
127 (void) strcpy(__locate_list
[i
].time
, ptr
);
130 len
= strlen (ptr
) + 1;
131 __locate_list
[i
].tty
= (char *) malloc(len
);
132 if (!__locate_list
[i
].tty
)
134 (void) strcpy(__locate_list
[i
].tty
, ptr
);
139 *nlocs
= __locate_num
;
142 if ((*user
= (char *) malloc(strlen(zald
->user
)+1)) == NULL
)
144 strcpy(*user
,zald
->user
);
146 if ((*user
= (char *) malloc(strlen(notice
->z_class_inst
)+1)) == NULL
)
148 strcpy(*user
,notice
->z_class_inst
);
154 int ZCompareALDPred(notice
, zald
)
158 return(ZCompareUID(&(notice
->z_multiuid
),
159 &(((ZAsyncLocateData_t
*) zald
)->uid
)));
163 register ZAsyncLocateData_t
*zald
;
167 if (zald
->user
) free(zald
->user
);
168 if (zald
->version
) free(zald
->version
);
169 (void) memset(zald
, 0, sizeof(*zald
));