Mercurial > pidgin.yaz
comparison plugins/zephyr/ZLocations.c @ 1700:1e0fa7e130d0
[gaim-migrate @ 1710]
Zephyr.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Thu, 12 Apr 2001 09:21:16 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1699:644056e095f1 | 1700:1e0fa7e130d0 |
---|---|
1 /* This file is part of the Project Athena Zephyr Notification System. | |
2 * It contains source for the ZSetLocation, ZUnsetLocation, and | |
3 * ZFlushMyLocations functions. | |
4 * | |
5 * Created by: Robert French | |
6 * | |
7 * $Source$ | |
8 * $Author: warmenhoven $ | |
9 * | |
10 * Copyright (c) 1987,1988,1991 by the Massachusetts Institute of Technology. | |
11 * For copying and distribution information, see the file | |
12 * "mit-copyright.h". | |
13 */ | |
14 /* $Header$ */ | |
15 | |
16 #ifndef lint | |
17 static char rcsid_ZLocations_c[] = | |
18 "$Zephyr: /afs/athena.mit.edu/astaff/project/zephyr/src/lib/RCS/ZLocations.c,v 1.30 90/12/20 03:04:39 raeburn Exp $"; | |
19 #endif | |
20 | |
21 #include <internal.h> | |
22 | |
23 #include <pwd.h> | |
24 | |
25 extern char *getenv(); | |
26 extern int errno; | |
27 | |
28 Code_t ZSetLocation(exposure) | |
29 char *exposure; | |
30 { | |
31 return (Z_SendLocation(LOGIN_CLASS, exposure, ZAUTH, | |
32 "$sender logged in to $1 on $3 at $2")); | |
33 } | |
34 | |
35 Code_t ZUnsetLocation() | |
36 { | |
37 return (Z_SendLocation(LOGIN_CLASS, LOGIN_USER_LOGOUT, ZNOAUTH, | |
38 "$sender logged out of $1 on $3 at $2")); | |
39 } | |
40 | |
41 Code_t ZFlushMyLocations() | |
42 { | |
43 return (Z_SendLocation(LOGIN_CLASS, LOGIN_USER_FLUSH, ZAUTH, "")); | |
44 } | |
45 | |
46 static char host[MAXHOSTNAMELEN], mytty[MAXPATHLEN]; | |
47 static int reenter = 0; | |
48 | |
49 Code_t Z_SendLocation(class, opcode, auth, format) | |
50 char *class; | |
51 char *opcode; | |
52 Z_AuthProc auth; | |
53 char *format; | |
54 { | |
55 int retval; | |
56 time_t ourtime; | |
57 ZNotice_t notice, retnotice; | |
58 char *bptr[3]; | |
59 #ifndef X_DISPLAY_MISSING | |
60 char *display; | |
61 #endif | |
62 char *ttyp; | |
63 struct hostent *hent; | |
64 short wg_port = ZGetWGPort(); | |
65 | |
66 (void) memset((char *)¬ice, 0, sizeof(notice)); | |
67 notice.z_kind = ACKED; | |
68 notice.z_port = (u_short) ((wg_port == -1) ? 0 : wg_port); | |
69 notice.z_class = class; | |
70 notice.z_class_inst = ZGetSender(); | |
71 notice.z_opcode = opcode; | |
72 notice.z_sender = 0; | |
73 notice.z_recipient = ""; | |
74 notice.z_num_other_fields = 0; | |
75 notice.z_default_format = format; | |
76 | |
77 /* | |
78 keep track of what we said before so that we can be consistent | |
79 when changing location information. | |
80 This is done mainly for the sake of the WindowGram client. | |
81 */ | |
82 | |
83 if (!reenter) { | |
84 if (gethostname(host, MAXHOSTNAMELEN) < 0) | |
85 return (errno); | |
86 | |
87 hent = gethostbyname(host); | |
88 if (hent) { | |
89 (void) strncpy(host, hent->h_name, sizeof(host)); | |
90 host[sizeof(host) - 1] = '\0'; | |
91 } | |
92 bptr[0] = host; | |
93 #ifndef X_DISPLAY_MISSING | |
94 if ((display = getenv("DISPLAY")) && *display) { | |
95 (void) strcpy(mytty, display); | |
96 bptr[2] = mytty; | |
97 } else { | |
98 #endif | |
99 ttyp = ttyname(0); | |
100 if (ttyp) { | |
101 bptr[2] = strrchr(ttyp, '/'); | |
102 if (bptr[2]) | |
103 bptr[2]++; | |
104 else | |
105 bptr[2] = ttyp; | |
106 } | |
107 else | |
108 bptr[2] = "unknown"; | |
109 (void) strcpy(mytty, bptr[2]); | |
110 #ifndef X_DISPLAY_MISSING | |
111 } | |
112 #endif | |
113 reenter = 1; | |
114 } else { | |
115 bptr[0] = host; | |
116 bptr[2] = mytty; | |
117 } | |
118 | |
119 ourtime = time((time_t *)0); | |
120 bptr[1] = ctime(&ourtime); | |
121 bptr[1][strlen(bptr[1])-1] = '\0'; | |
122 | |
123 | |
124 if ((retval = ZSendList(¬ice, bptr, 3, auth)) != ZERR_NONE) | |
125 return (retval); | |
126 | |
127 retval = Z_WaitForNotice (&retnotice, ZCompareUIDPred, ¬ice.z_uid, | |
128 SRV_TIMEOUT); | |
129 if (retval != ZERR_NONE) | |
130 return retval; | |
131 | |
132 if (retnotice.z_kind == SERVNAK) { | |
133 if (!retnotice.z_message_len) { | |
134 ZFreeNotice(&retnotice); | |
135 return (ZERR_SERVNAK); | |
136 } | |
137 if (!strcmp(retnotice.z_message, ZSRVACK_NOTSENT)) { | |
138 ZFreeNotice(&retnotice); | |
139 return (ZERR_AUTHFAIL); | |
140 } | |
141 if (!strcmp(retnotice.z_message, ZSRVACK_FAIL)) { | |
142 ZFreeNotice(&retnotice); | |
143 return (ZERR_LOGINFAIL); | |
144 } | |
145 ZFreeNotice(&retnotice); | |
146 return (ZERR_SERVNAK); | |
147 } | |
148 | |
149 if (retnotice.z_kind != SERVACK) { | |
150 ZFreeNotice(&retnotice); | |
151 return (ZERR_INTERNAL); | |
152 } | |
153 | |
154 if (!retnotice.z_message_len) { | |
155 ZFreeNotice(&retnotice); | |
156 return (ZERR_INTERNAL); | |
157 } | |
158 | |
159 if (strcmp(retnotice.z_message, ZSRVACK_SENT) && | |
160 strcmp(retnotice.z_message, ZSRVACK_NOTSENT)) { | |
161 ZFreeNotice(&retnotice); | |
162 return (ZERR_INTERNAL); | |
163 } | |
164 | |
165 ZFreeNotice(&retnotice); | |
166 | |
167 return (ZERR_NONE); | |
168 } |