Mercurial > pidgin
annotate src/protocols/zephyr/ZLocations.c @ 10868:4a56b48dbaa6
[gaim-migrate @ 12555]
Don't try to send if charset conversion isn't successful. This is entirely untested.
committer: Tailor Script <tailor@pidgin.im>
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Mon, 25 Apr 2005 03:41:16 +0000 |
parents | 5727afad0fb8 |
children | 04cb7363260d |
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 |
10867 | 23 #ifndef WIN32 |
2086 | 24 #include <pwd.h> |
10867 | 25 #endif |
2086 | 26 |
27 extern char *getenv(); | |
28 extern int errno; | |
29 | |
30 Code_t ZSetLocation(exposure) | |
31 char *exposure; | |
32 { | |
33 return (Z_SendLocation(LOGIN_CLASS, exposure, ZAUTH, | |
34 "$sender logged in to $1 on $3 at $2")); | |
35 } | |
36 | |
37 Code_t ZUnsetLocation() | |
38 { | |
39 return (Z_SendLocation(LOGIN_CLASS, LOGIN_USER_LOGOUT, ZNOAUTH, | |
40 "$sender logged out of $1 on $3 at $2")); | |
41 } | |
42 | |
43 Code_t ZFlushMyLocations() | |
44 { | |
45 return (Z_SendLocation(LOGIN_CLASS, LOGIN_USER_FLUSH, ZAUTH, "")); | |
46 } | |
47 | |
48 static char host[MAXHOSTNAMELEN], mytty[MAXPATHLEN]; | |
49 static int reenter = 0; | |
50 | |
51 Code_t Z_SendLocation(class, opcode, auth, format) | |
52 char *class; | |
53 char *opcode; | |
54 Z_AuthProc auth; | |
55 char *format; | |
56 { | |
57 int retval; | |
58 time_t ourtime; | |
59 ZNotice_t notice, retnotice; | |
10867 | 60 char *bptr[3]; |
2086 | 61 #ifndef X_DISPLAY_MISSING |
62 char *display; | |
63 #endif | |
10867 | 64 #ifndef WIN32 |
2086 | 65 char *ttyp; |
10867 | 66 char *p; |
67 #endif | |
2086 | 68 struct hostent *hent; |
69 short wg_port = ZGetWGPort(); | |
70 | |
71 (void) memset((char *)¬ice, 0, sizeof(notice)); | |
72 notice.z_kind = ACKED; | |
7475 | 73 notice.z_port = (unsigned short) ((wg_port == -1) ? 0 : wg_port); |
2086 | 74 notice.z_class = class; |
75 notice.z_class_inst = ZGetSender(); | |
76 notice.z_opcode = opcode; | |
77 notice.z_sender = 0; | |
78 notice.z_recipient = ""; | |
79 notice.z_num_other_fields = 0; | |
80 notice.z_default_format = format; | |
81 | |
82 /* | |
83 keep track of what we said before so that we can be consistent | |
84 when changing location information. | |
85 This is done mainly for the sake of the WindowGram client. | |
86 */ | |
87 | |
88 if (!reenter) { | |
89 if (gethostname(host, MAXHOSTNAMELEN) < 0) | |
90 return (errno); | |
91 | |
92 hent = gethostbyname(host); | |
93 if (hent) { | |
94 (void) strncpy(host, hent->h_name, sizeof(host)); | |
95 host[sizeof(host) - 1] = '\0'; | |
96 } | |
97 #ifndef X_DISPLAY_MISSING | |
98 if ((display = getenv("DISPLAY")) && *display) { | |
10328 | 99 (void) strncpy(mytty, display, sizeof(mytty)); |
10326 | 100 mytty[sizeof(mytty)-1] = '\0'; |
2086 | 101 } else { |
102 #endif | |
10867 | 103 #ifdef WIN32 |
104 strcpy(mytty,"WinGaim"); | |
105 #else | |
2086 | 106 ttyp = ttyname(0); |
2419
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
107 if (ttyp && *ttyp) { |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
108 p = strchr(ttyp + 1, '/'); |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
109 strcpy(mytty, (p) ? p + 1 : ttyp); |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
110 } else { |
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
111 strcpy(mytty, "unknown"); |
2086 | 112 } |
10867 | 113 #endif |
2086 | 114 #ifndef X_DISPLAY_MISSING |
115 } | |
116 #endif | |
117 reenter = 1; | |
118 } | |
119 | |
120 ourtime = time((time_t *)0); | |
2419
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
121 bptr[0] = host; |
2086 | 122 bptr[1] = ctime(&ourtime); |
123 bptr[1][strlen(bptr[1])-1] = '\0'; | |
2419
7ba69b8e0de5
[gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
124 bptr[2] = mytty; |
2086 | 125 |
126 | |
127 if ((retval = ZSendList(¬ice, bptr, 3, auth)) != ZERR_NONE) | |
128 return (retval); | |
129 | |
130 retval = Z_WaitForNotice (&retnotice, ZCompareUIDPred, ¬ice.z_uid, | |
131 SRV_TIMEOUT); | |
132 if (retval != ZERR_NONE) | |
133 return retval; | |
134 | |
135 if (retnotice.z_kind == SERVNAK) { | |
136 if (!retnotice.z_message_len) { | |
137 ZFreeNotice(&retnotice); | |
138 return (ZERR_SERVNAK); | |
139 } | |
140 if (!strcmp(retnotice.z_message, ZSRVACK_NOTSENT)) { | |
141 ZFreeNotice(&retnotice); | |
142 return (ZERR_AUTHFAIL); | |
143 } | |
144 if (!strcmp(retnotice.z_message, ZSRVACK_FAIL)) { | |
145 ZFreeNotice(&retnotice); | |
146 return (ZERR_LOGINFAIL); | |
147 } | |
148 ZFreeNotice(&retnotice); | |
149 return (ZERR_SERVNAK); | |
150 } | |
151 | |
152 if (retnotice.z_kind != SERVACK) { | |
153 ZFreeNotice(&retnotice); | |
154 return (ZERR_INTERNAL); | |
155 } | |
156 | |
157 if (!retnotice.z_message_len) { | |
158 ZFreeNotice(&retnotice); | |
159 return (ZERR_INTERNAL); | |
160 } | |
161 | |
162 if (strcmp(retnotice.z_message, ZSRVACK_SENT) && | |
163 strcmp(retnotice.z_message, ZSRVACK_NOTSENT)) { | |
164 ZFreeNotice(&retnotice); | |
165 return (ZERR_INTERNAL); | |
166 } | |
167 | |
168 ZFreeNotice(&retnotice); | |
169 | |
170 return (ZERR_NONE); | |
171 } |