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 * Copyright (c) 1990,1991 by the Massachusetts Institute of Technology.
7 * For copying and distribution information, see the file
13 Code_t
ZRequestLocations(user
, zald
, kind
, auth
)
15 ZAsyncLocateData_t
*zald
;
16 ZNotice_Kind_t kind
; /* UNSAFE, UNACKED, or ACKED */
21 size_t userlen
, versionlen
;
24 if ((retval
= ZOpenPort((unsigned short *)0)) != ZERR_NONE
)
27 (void) memset((char *)¬ice
, 0, sizeof(notice
));
29 notice
.z_port
= __Zephyr_port
;
30 notice
.z_class
= LOCATE_CLASS
;
31 notice
.z_class_inst
= user
;
32 notice
.z_opcode
= LOCATE_LOCATE
;
34 notice
.z_recipient
= "";
35 notice
.z_default_format
= "";
36 notice
.z_message_len
= 0;
38 if ((retval
= ZSendNotice(¬ice
, auth
)) != ZERR_NONE
)
41 userlen
= strlen(user
) + 1;
42 versionlen
= strlen(notice
.z_version
) + 1;
43 if ((zald
->user
= (char *) malloc(userlen
)) == NULL
) {
46 if ((zald
->version
= (char *) malloc(versionlen
)) == NULL
) {
50 zald
->uid
= notice
.z_multiuid
;
51 g_strlcpy(zald
->user
,user
,userlen
);
52 g_strlcpy(zald
->version
,notice
.z_version
,versionlen
);
57 Code_t
ZParseLocations(notice
,zald
,nlocs
,user
)
59 ZAsyncLocateData_t
*zald
;
66 ZFlushLocations(); /* This never fails (this function is part of the
67 library, so it is allowed to know this). */
69 /* non-matching protocol version numbers means the
70 server is probably an older version--must punt */
72 if (zald
&& strcmp(notice
->z_version
, zald
->version
))
75 if (notice
->z_kind
== SERVNAK
)
76 return (ZERR_SERVNAK
);
78 /* flag ACKs as special */
79 if (notice
->z_kind
== SERVACK
&&
80 !strcmp(notice
->z_opcode
, LOCATE_LOCATE
)) {
85 if (notice
->z_kind
!= ACKED
)
86 return (ZERR_INTERNAL
);
88 end
= notice
->z_message
+notice
->z_message_len
;
92 for (ptr
=notice
->z_message
;ptr
<end
;ptr
++)
100 __locate_list
= (ZLocations_t
*)malloc((unsigned)__locate_num
*
101 sizeof(ZLocations_t
));
108 for (ptr
=notice
->z_message
, i
=0; i
<__locate_num
; i
++) {
111 len
= strlen (ptr
) + 1;
112 __locate_list
[i
].host
= (char *) malloc(len
);
113 if (!__locate_list
[i
].host
)
115 g_strlcpy(__locate_list
[i
].host
, ptr
,len
);
118 len
= strlen (ptr
) + 1;
119 __locate_list
[i
].time
= (char *) malloc(len
);
120 if (!__locate_list
[i
].time
)
122 g_strlcpy(__locate_list
[i
].time
, ptr
,len
);
125 len
= strlen (ptr
) + 1;
126 __locate_list
[i
].tty
= (char *) malloc(len
);
127 if (!__locate_list
[i
].tty
)
129 g_strlcpy(__locate_list
[i
].tty
, ptr
,len
);
134 *nlocs
= __locate_num
;
138 len
= strlen(zald
->user
) + 1;
139 if ((*user
= (char *) malloc(len
)) == NULL
)
141 g_strlcpy(*user
,zald
->user
,len
);
143 len
= strlen(notice
->z_class_inst
) + 1;
144 if ((*user
= (char *) malloc(len
)) == NULL
)
146 g_strlcpy(*user
,notice
->z_class_inst
,len
);
152 int ZCompareALDPred(notice
, zald
)
156 return(ZCompareUID(&(notice
->z_multiuid
),
157 &(((ZAsyncLocateData_t
*) zald
)->uid
)));
161 ZAsyncLocateData_t
*zald
;
165 if (zald
->user
) free(zald
->user
);
166 if (zald
->version
) free(zald
->version
);
167 (void) memset(zald
, 0, sizeof(*zald
));