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
14 Code_t
ZRequestLocations(user
, zald
, kind
, auth
)
16 ZAsyncLocateData_t
*zald
;
17 ZNotice_Kind_t kind
; /* UNSAFE, UNACKED, or ACKED */
22 size_t userlen
, versionlen
;
25 if ((retval
= ZOpenPort((unsigned short *)0)) != ZERR_NONE
)
28 (void) memset((char *)¬ice
, 0, sizeof(notice
));
30 notice
.z_port
= __Zephyr_port
;
31 notice
.z_class
= LOCATE_CLASS
;
32 notice
.z_class_inst
= user
;
33 notice
.z_opcode
= LOCATE_LOCATE
;
35 notice
.z_recipient
= "";
36 notice
.z_default_format
= "";
37 notice
.z_message_len
= 0;
39 if ((retval
= ZSendNotice(¬ice
, auth
)) != ZERR_NONE
)
42 userlen
= strlen(user
) + 1;
43 versionlen
= strlen(notice
.z_version
) + 1;
44 if ((zald
->user
= (char *) malloc(userlen
)) == NULL
) {
47 if ((zald
->version
= (char *) malloc(versionlen
)) == NULL
) {
51 zald
->uid
= notice
.z_multiuid
;
52 g_strlcpy(zald
->user
,user
,userlen
);
53 g_strlcpy(zald
->version
,notice
.z_version
,versionlen
);
58 Code_t
ZParseLocations(notice
,zald
,nlocs
,user
)
60 ZAsyncLocateData_t
*zald
;
67 ZFlushLocations(); /* This never fails (this function is part of the
68 library, so it is allowed to know this). */
70 /* non-matching protocol version numbers means the
71 server is probably an older version--must punt */
73 if (zald
&& !purple_strequal(notice
->z_version
, zald
->version
))
76 if (notice
->z_kind
== SERVNAK
)
77 return (ZERR_SERVNAK
);
79 /* flag ACKs as special */
80 if (notice
->z_kind
== SERVACK
&&
81 purple_strequal(notice
->z_opcode
, LOCATE_LOCATE
)) {
86 if (notice
->z_kind
!= ACKED
)
87 return (ZERR_INTERNAL
);
89 end
= notice
->z_message
+notice
->z_message_len
;
93 for (ptr
=notice
->z_message
;ptr
<end
;ptr
++)
101 __locate_list
= (ZLocations_t
*)malloc((unsigned)__locate_num
*
102 sizeof(ZLocations_t
));
106 __locate_list
= NULL
;
109 for (ptr
=notice
->z_message
, i
=0; i
<__locate_num
; i
++) {
112 len
= strlen (ptr
) + 1;
113 __locate_list
[i
].host
= (char *) malloc(len
);
114 if (!__locate_list
[i
].host
)
116 g_strlcpy(__locate_list
[i
].host
, ptr
,len
);
119 len
= strlen (ptr
) + 1;
120 __locate_list
[i
].time
= (char *) malloc(len
);
121 if (!__locate_list
[i
].time
)
123 g_strlcpy(__locate_list
[i
].time
, ptr
,len
);
126 len
= strlen (ptr
) + 1;
127 __locate_list
[i
].tty
= (char *) malloc(len
);
128 if (!__locate_list
[i
].tty
)
130 g_strlcpy(__locate_list
[i
].tty
, ptr
,len
);
135 *nlocs
= __locate_num
;
139 len
= strlen(zald
->user
) + 1;
140 if ((*user
= (char *) malloc(len
)) == NULL
)
142 g_strlcpy(*user
,zald
->user
,len
);
144 len
= strlen(notice
->z_class_inst
) + 1;
145 if ((*user
= (char *) malloc(len
)) == NULL
)
147 g_strlcpy(*user
,notice
->z_class_inst
,len
);
153 int ZCompareALDPred(notice
, zald
)
157 return(ZCompareUID(&(notice
->z_multiuid
),
158 &(((ZAsyncLocateData_t
*) zald
)->uid
)));
162 ZAsyncLocateData_t
*zald
;
168 (void) memset(zald
, 0, sizeof(*zald
));