Mercurial > pidgin
annotate src/protocols/zephyr/ZLocations.c @ 10678:210e38f53b7b
[gaim-migrate @ 12221]
19:40:11 <deryni> About ctrl-z I'm thinking minimize should probably more properly be a wm thing, and so the user can bind a wm action if they want it and we shouldn't grab it.
committer: Tailor Script <tailor@pidgin.im>
author | Etan Reisner <pidgin@unreliablesource.net> |
---|---|
date | Wed, 09 Mar 2005 00:52:59 +0000 |
parents | 0e9be9a1d68d |
children | 5727afad0fb8 |
rev | line source |
---|---|
2086 | 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$ | |
10328 | 8 * $Author: thekingant $ |
2086 | 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 | |
8792
43d6c08d7e96
[gaim-migrate @ 9554]
Christian Hammond <chipx86@chipx86.com>
parents:
7475
diff
changeset
|
21 #include "internal.h" |
2086 | 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; | |
2419
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
58 char *bptr[3], *p; |
2086 | 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; | |
7475 | 68 notice.z_port = (unsigned short) ((wg_port == -1) ? 0 : wg_port); |
2086 | 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 #ifndef X_DISPLAY_MISSING | |
93 if ((display = getenv("DISPLAY")) && *display) { | |
10328 | 94 (void) strncpy(mytty, display, sizeof(mytty)); |
10326 | 95 mytty[sizeof(mytty)-1] = '\0'; |
2086 | 96 } else { |
97 #endif | |
98 ttyp = ttyname(0); | |
2419
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
99 if (ttyp && *ttyp) { |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
100 p = strchr(ttyp + 1, '/'); |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
101 strcpy(mytty, (p) ? p + 1 : ttyp); |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
102 } else { |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
103 strcpy(mytty, "unknown"); |
2086 | 104 } |
105 #ifndef X_DISPLAY_MISSING | |
106 } | |
107 #endif | |
108 reenter = 1; | |
109 } | |
110 | |
111 ourtime = time((time_t *)0); | |
2419
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
112 bptr[0] = host; |
2086 | 113 bptr[1] = ctime(&ourtime); |
114 bptr[1][strlen(bptr[1])-1] = '\0'; | |
2419
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
115 bptr[2] = mytty; |
2086 | 116 |
117 | |
118 if ((retval = ZSendList(¬ice, bptr, 3, auth)) != ZERR_NONE) | |
119 return (retval); | |
120 | |
121 retval = Z_WaitForNotice (&retnotice, ZCompareUIDPred, ¬ice.z_uid, | |
122 SRV_TIMEOUT); | |
123 if (retval != ZERR_NONE) | |
124 return retval; | |
125 | |
126 if (retnotice.z_kind == SERVNAK) { | |
127 if (!retnotice.z_message_len) { | |
128 ZFreeNotice(&retnotice); | |
129 return (ZERR_SERVNAK); | |
130 } | |
131 if (!strcmp(retnotice.z_message, ZSRVACK_NOTSENT)) { | |
132 ZFreeNotice(&retnotice); | |
133 return (ZERR_AUTHFAIL); | |
134 } | |
135 if (!strcmp(retnotice.z_message, ZSRVACK_FAIL)) { | |
136 ZFreeNotice(&retnotice); | |
137 return (ZERR_LOGINFAIL); | |
138 } | |
139 ZFreeNotice(&retnotice); | |
140 return (ZERR_SERVNAK); | |
141 } | |
142 | |
143 if (retnotice.z_kind != SERVACK) { | |
144 ZFreeNotice(&retnotice); | |
145 return (ZERR_INTERNAL); | |
146 } | |
147 | |
148 if (!retnotice.z_message_len) { | |
149 ZFreeNotice(&retnotice); | |
150 return (ZERR_INTERNAL); | |
151 } | |
152 | |
153 if (strcmp(retnotice.z_message, ZSRVACK_SENT) && | |
154 strcmp(retnotice.z_message, ZSRVACK_NOTSENT)) { | |
155 ZFreeNotice(&retnotice); | |
156 return (ZERR_INTERNAL); | |
157 } | |
158 | |
159 ZFreeNotice(&retnotice); | |
160 | |
161 return (ZERR_NONE); | |
162 } |