Open an explorer.exe window at the location of the file when clicking
[pidgin-git.git] / libpurple / protocols / zephyr / ZAsyncLocate.c
blobd46fd6666b4e774ef84fe080ec3d9116b3cc22d4
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
8 * "mit-copyright.h".
9 */
11 #include "internal.h"
13 Code_t ZRequestLocations(user, zald, kind, auth)
14 const char *user;
15 ZAsyncLocateData_t *zald;
16 ZNotice_Kind_t kind; /* UNSAFE, UNACKED, or ACKED */
17 Z_AuthProc auth;
19 int retval;
20 ZNotice_t notice;
21 size_t userlen, versionlen;
23 if (ZGetFD() < 0)
24 if ((retval = ZOpenPort((unsigned short *)0)) != ZERR_NONE)
25 return (retval);
27 (void) memset((char *)&notice, 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;
38 if ((retval = ZSendNotice(&notice, auth)) != ZERR_NONE)
39 return(retval);
41 userlen = strlen(user) + 1;
42 versionlen = strlen(notice.z_version) + 1;
43 if ((zald->user = (char *) malloc(userlen)) == NULL) {
44 return(ENOMEM);
46 if ((zald->version = (char *) malloc(versionlen)) == NULL) {
47 free(zald->user);
48 return(ENOMEM);
50 zald->uid = notice.z_multiuid;
51 g_strlcpy(zald->user,user,userlen);
52 g_strlcpy(zald->version,notice.z_version,versionlen);
54 return(ZERR_NONE);
57 Code_t ZParseLocations(notice,zald,nlocs,user)
58 ZNotice_t *notice;
59 ZAsyncLocateData_t *zald;
60 int *nlocs;
61 char **user;
63 char *ptr, *end;
64 int i;
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))
73 return(ZERR_VERS);
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)) {
81 *nlocs = -1;
82 return(ZERR_NONE);
85 if (notice->z_kind != ACKED)
86 return (ZERR_INTERNAL);
88 end = notice->z_message+notice->z_message_len;
90 __locate_num = 0;
92 for (ptr=notice->z_message;ptr<end;ptr++)
93 if (!*ptr)
94 __locate_num++;
96 __locate_num /= 3;
98 if (__locate_num)
100 __locate_list = (ZLocations_t *)malloc((unsigned)__locate_num*
101 sizeof(ZLocations_t));
102 if (!__locate_list)
103 return (ENOMEM);
104 } else {
105 __locate_list = 0;
108 for (ptr=notice->z_message, i=0; i<__locate_num; i++) {
109 unsigned int len;
111 len = strlen (ptr) + 1;
112 __locate_list[i].host = (char *) malloc(len);
113 if (!__locate_list[i].host)
114 return (ENOMEM);
115 g_strlcpy(__locate_list[i].host, ptr,len);
116 ptr += len;
118 len = strlen (ptr) + 1;
119 __locate_list[i].time = (char *) malloc(len);
120 if (!__locate_list[i].time)
121 return (ENOMEM);
122 g_strlcpy(__locate_list[i].time, ptr,len);
123 ptr += len;
125 len = strlen (ptr) + 1;
126 __locate_list[i].tty = (char *) malloc(len);
127 if (!__locate_list[i].tty)
128 return (ENOMEM);
129 g_strlcpy(__locate_list[i].tty, ptr,len);
130 ptr += len;
133 __locate_next = 0;
134 *nlocs = __locate_num;
135 if (user) {
136 size_t len;
137 if (zald) {
138 len = strlen(zald->user) + 1;
139 if ((*user = (char *) malloc(len)) == NULL)
140 return(ENOMEM);
141 g_strlcpy(*user,zald->user,len);
142 } else {
143 len = strlen(notice->z_class_inst) + 1;
144 if ((*user = (char *) malloc(len)) == NULL)
145 return(ENOMEM);
146 g_strlcpy(*user,notice->z_class_inst,len);
149 return (ZERR_NONE);
152 int ZCompareALDPred(notice, zald)
153 ZNotice_t *notice;
154 void *zald;
156 return(ZCompareUID(&(notice->z_multiuid),
157 &(((ZAsyncLocateData_t *) zald)->uid)));
160 void ZFreeALD(zald)
161 ZAsyncLocateData_t *zald;
163 if (!zald) return;
165 if (zald->user) free(zald->user);
166 if (zald->version) free(zald->version);
167 (void) memset(zald, 0, sizeof(*zald));