Mercurial > pidgin
annotate plugins/zephyr/zephyr.c @ 1724:4104a30264b7
[gaim-migrate @ 1734]
another of mid's patches. this one is so jabber can send/accept chat invites.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Wed, 18 Apr 2001 00:10:59 +0000 |
parents | 5800449e7ecc |
children | 004725b3a851 |
rev | line source |
---|---|
1700 | 1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ |
2 /* | |
3 * gaim | |
4 * | |
5 * Copyright (C) 1998-2001, Mark Spencer <markster@marko.net> | |
6 * Some code borrowed from GtkZephyr, by | |
7 * Jag/Sean Dilda <agrajag@linuxpower.org>/<smdilda@unity.ncsu.edu> | |
8 * http://gtkzephyr.linuxpower.org/ | |
9 * | |
10 * This program is free software; you can redistribute it and/or modify | |
11 * it under the terms of the GNU General Public License as published by | |
12 * the Free Software Foundation; either version 2 of the License, or | |
13 * (at your option) any later version. | |
14 * | |
15 * This program is distributed in the hope that it will be useful, | |
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 * GNU General Public License for more details. | |
19 * | |
20 * You should have received a copy of the GNU General Public License | |
21 * along with this program; if not, write to the Free Software | |
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
23 * | |
24 */ | |
25 | |
26 #ifdef HAVE_CONFIG_H | |
27 #include "config.h" | |
28 #endif | |
29 | |
30 #include <gtk/gtk.h> | |
31 #include <string.h> | |
32 #include "gaim.h" | |
33 #include "prpl.h" | |
34 #include "zephyr/zephyr.h" | |
35 | |
36 char *name() | |
37 { | |
38 return "Zephyr"; | |
39 } | |
40 | |
41 char *description() | |
42 { | |
43 return "Allows gaim to use the Zephyr protocol"; | |
44 } | |
45 | |
46 static char *zephyr_name() | |
47 { | |
48 return "Zephyr"; | |
49 } | |
50 | |
51 #define z_call(func) if (func != ZERR_NONE)\ | |
52 return; | |
53 #define z_call_r(func) if (func != ZERR_NONE)\ | |
54 return TRUE; | |
55 #define z_call_s(func, err) if (func != ZERR_NONE) {\ | |
56 hide_login_progress(zgc, err);\ | |
57 signoff(zgc);\ | |
58 return;\ | |
59 } | |
60 | |
61 /* this is so bad, and if Zephyr weren't so fucked up to begin with I | |
62 * wouldn't do this. but it is so i will. */ | |
63 static guint32 nottimer = 0; | |
64 static guint32 loctimer = 0; | |
65 struct gaim_connection *zgc = NULL; | |
1719
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
66 static GList *pending_zloc_names = NULL; |
1700 | 67 |
68 /* just for debugging | |
69 static void handle_unknown(ZNotice_t notice) | |
70 { | |
71 g_print("z_packet: %s\n", notice.z_packet); | |
72 g_print("z_version: %s\n", notice.z_version); | |
73 g_print("z_kind: %d\n", notice.z_kind); | |
74 g_print("z_class: %s\n", notice.z_class); | |
75 g_print("z_class_inst: %s\n", notice.z_class_inst); | |
76 g_print("z_opcode: %s\n", notice.z_opcode); | |
77 g_print("z_sender: %s\n", notice.z_sender); | |
78 g_print("z_recipient: %s\n", notice.z_recipient); | |
79 g_print("z_message: %s\n", notice.z_message); | |
80 g_print("z_message_len: %d\n", notice.z_message_len); | |
81 g_print("\n"); | |
82 } | |
83 */ | |
84 | |
1719
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
85 static char *zephyr_normalize(const char *orig) |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
86 { |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
87 static char buf[80]; |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
88 if (strchr(orig, '@')) { |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
89 g_snprintf(buf, 80, "%s", orig); |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
90 } else { |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
91 g_snprintf(buf, 80, "%s@%s", orig, ZGetRealm()); |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
92 } |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
93 return buf; |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
94 } |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
95 |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
96 static gboolean pending_zloc(char *who) |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
97 { |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
98 GList *curr; |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
99 for (curr = pending_zloc_names; curr != NULL; curr = curr->next) { |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
100 if (!g_strcasecmp(who, (char*)curr->data)) { |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
101 g_free((char*)curr->data); |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
102 pending_zloc_names = g_list_remove(pending_zloc_names, curr->data); |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
103 return TRUE; |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
104 } |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
105 } |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
106 return FALSE; |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
107 } |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
108 |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
109 static void zephyr_zloc(struct gaim_connection *gc, char *who) |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
110 { |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
111 ZAsyncLocateData_t ald; |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
112 |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
113 if (ZRequestLocations(zephyr_normalize(who), &ald, UNACKED, ZAUTH) |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
114 != ZERR_NONE) { |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
115 return; |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
116 } |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
117 pending_zloc_names = g_list_append(pending_zloc_names, |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
118 g_strdup(zephyr_normalize(who))); |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
119 } |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
120 |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
121 static void info_callback(GtkObject *obj, char *who) |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
122 { |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
123 zephyr_zloc(gtk_object_get_user_data(obj), who); |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
124 } |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
125 |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
126 static void zephyr_buddy_menu(GtkWidget *menu, struct gaim_connection *gc, char *who) |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
127 { |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
128 GtkWidget *button; |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
129 |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
130 button = gtk_menu_item_new_with_label(_("ZLocate")); |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
131 gtk_signal_connect(GTK_OBJECT(button), "activate", |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
132 GTK_SIGNAL_FUNC(info_callback), who); |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
133 gtk_object_set_user_data(GTK_OBJECT(button), gc); |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
134 gtk_menu_append(GTK_MENU(menu), button); |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
135 gtk_widget_show(button); |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
136 } |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
137 |
1700 | 138 static void handle_message(ZNotice_t notice, struct sockaddr_in from) |
139 { | |
140 if (!g_strcasecmp(notice.z_class, LOGIN_CLASS)) { | |
141 /* well, we'll be updating in 2 seconds anyway, might as well ignore this. */ | |
142 } else if (!g_strcasecmp(notice.z_class, LOCATE_CLASS)) { | |
143 if (!g_strcasecmp(notice.z_opcode, LOCATE_LOCATE)) { | |
144 int nlocs; | |
145 char *user; | |
146 struct buddy *b; | |
147 | |
148 if (ZParseLocations(¬ice, NULL, &nlocs, &user) != ZERR_NONE) | |
149 return; | |
150 if ((b = find_buddy(zgc, user)) == NULL) { | |
151 char *e = strchr(user, '@'); | |
152 if (e) *e = '\0'; | |
153 b = find_buddy(zgc, user); | |
154 } | |
155 if (!b) { | |
156 free(user); | |
157 return; | |
158 } | |
1719
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
159 if (pending_zloc(b->name)) { |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
160 ZLocations_t locs; |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
161 int one = 1; |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
162 GString *str = g_string_new(""); |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
163 g_string_sprintfa(str, "<b>User:</b> %s<br>" |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
164 "<b>Alias:</b> %s<br>", |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
165 b->name, b->show); |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
166 if (!nlocs) { |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
167 g_string_sprintfa(str, "<br>Hidden or not logged-in"); |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
168 } |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
169 for (; nlocs > 0; nlocs--) { |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
170 ZGetLocations(&locs, &one); |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
171 g_string_sprintfa(str, "<br>At %s since %s", locs.host, |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
172 locs.time); |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
173 } |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
174 g_show_info_text(str->str); |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
175 g_string_free(str, TRUE); |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
176 } |
1700 | 177 serv_got_update(zgc, b->name, nlocs, 0, 0, 0, 0, 0); |
178 | |
179 free(user); | |
180 } | |
181 } else if (!g_strcasecmp(notice.z_class, "MESSAGE")) { | |
182 char buf[BUF_LONG]; | |
183 char *ptr = notice.z_message + strlen(notice.z_message) + 1; | |
184 int len = notice.z_message_len - (ptr - notice.z_message); | |
185 if (len > 0) { | |
186 g_snprintf(buf, len + 1, "%s", ptr); | |
187 g_strchomp(buf); | |
188 serv_got_im(zgc, notice.z_sender, buf, 0); | |
189 } | |
190 } else { | |
191 /* yes. */ | |
192 } | |
193 } | |
194 | |
195 static gint check_notify(gpointer data) | |
196 { | |
197 while (ZPending()) { | |
198 ZNotice_t notice; | |
199 struct sockaddr_in from; | |
200 z_call_r(ZReceiveNotice(¬ice, &from)); | |
201 | |
202 switch (notice.z_kind) { | |
203 case UNSAFE: | |
204 case UNACKED: | |
205 case ACKED: | |
206 handle_message(notice, from); | |
207 break; | |
208 default: | |
209 /* we'll just ignore things for now */ | |
210 debug_printf("ZEPHYR: Unhandled Notice\n"); | |
211 break; | |
212 } | |
213 | |
214 ZFreeNotice(¬ice); | |
215 } | |
216 | |
217 return TRUE; | |
218 } | |
219 | |
220 static gint check_loc(gpointer data) | |
221 { | |
222 GSList *gr, *m; | |
223 ZAsyncLocateData_t ald; | |
224 | |
225 ald.user = NULL; | |
226 memset(&(ald.uid), 0, sizeof(ZUnique_Id_t)); | |
227 ald.version = NULL; | |
228 | |
229 gr = zgc->groups; | |
230 while (gr) { | |
231 struct group *g = gr->data; | |
232 m = g->members; | |
233 while (m) { | |
234 struct buddy *b = m->data; | |
235 char *chk; | |
1719
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
236 chk = g_strdup(zephyr_normalize(b->name)); |
1700 | 237 /* doesn't matter if this fails or not; we'll just move on to the next one */ |
238 ZRequestLocations(chk, &ald, UNACKED, ZAUTH); | |
239 g_free(chk); | |
240 m = m->next; | |
241 } | |
242 gr = gr->next; | |
243 } | |
244 | |
245 return TRUE; | |
246 } | |
247 | |
248 static char *get_exposure_level() | |
249 { | |
250 char *exposure = ZGetVariable("exposure"); | |
251 | |
252 if (!exposure) | |
253 return EXPOSE_REALMVIS; | |
254 if (!g_strcasecmp(exposure, EXPOSE_NONE)) | |
255 return EXPOSE_NONE; | |
256 if (!g_strcasecmp(exposure, EXPOSE_OPSTAFF)) | |
257 return EXPOSE_OPSTAFF; | |
258 if (!g_strcasecmp(exposure, EXPOSE_REALMANN)) | |
259 return EXPOSE_REALMANN; | |
260 if (!g_strcasecmp(exposure, EXPOSE_NETVIS)) | |
261 return EXPOSE_NETVIS; | |
262 if (!g_strcasecmp(exposure, EXPOSE_NETANN)) | |
263 return EXPOSE_NETANN; | |
264 return EXPOSE_REALMVIS; | |
265 } | |
266 | |
267 static void strip_comments(char *str) | |
268 { | |
269 char *tmp = strchr(str, '#'); | |
270 if (tmp) | |
271 *tmp = '\0'; | |
272 g_strchug(str); | |
273 g_strchomp(str); | |
274 } | |
275 | |
1719
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
276 static void process_zsubs() |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
277 { |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
278 FILE *f; |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
279 gchar *fname; |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
280 gchar buff[BUFSIZ]; |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
281 |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
282 fname = g_strdup_printf("%s/.zephyr.subs", g_getenv("HOME")); |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
283 f = fopen(fname, "r"); |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
284 if (f) { |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
285 char **triple; |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
286 ZSubscription_t sub; |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
287 char *recip; |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
288 while (fgets(buff, BUFSIZ, f)) { |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
289 strip_comments(buff); |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
290 if (buff[0]) { |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
291 triple = g_strsplit(buff, ",", 3); |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
292 if (triple[0] && triple[1] && triple[2]) { |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
293 sub.zsub_class = triple[0]; |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
294 sub.zsub_classinst = triple[1]; |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
295 if (!g_strcasecmp(triple[2], "%me%")) { |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
296 recip = g_strdup_printf("%s@%s", g_getenv("USER"), |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
297 ZGetRealm()); |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
298 } else if (!g_strcasecmp(triple[2], "*")) { |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
299 /* wildcard */ |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
300 recip = g_strdup_printf("@%s", ZGetRealm()); |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
301 } else { |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
302 recip = g_strdup(triple[2]); |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
303 } |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
304 sub.zsub_recipient = recip; |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
305 if (ZSubscribeTo(&sub, 1, 0) != ZERR_NONE) { |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
306 debug_printf("Zephyr: Couldn't subscribe to %s, %s, " |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
307 "%s\n", |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
308 sub.zsub_class, |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
309 sub.zsub_classinst, |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
310 sub.zsub_recipient); |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
311 } |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
312 g_free(recip); |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
313 } |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
314 g_strfreev(triple); |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
315 } |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
316 } |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
317 } |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
318 } |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
319 |
1700 | 320 static void process_anyone() |
321 { | |
322 FILE *fd; | |
323 gchar buff[BUFSIZ], *filename; | |
324 | |
325 filename = g_strconcat(g_get_home_dir(), "/.anyone", NULL); | |
326 if ((fd = fopen(filename, "r")) != NULL) { | |
327 while (fgets(buff, BUFSIZ, fd)) { | |
328 strip_comments(buff); | |
329 if (buff[0]) | |
330 add_buddy(zgc, "Anyone", buff, buff); | |
331 } | |
332 fclose(fd); | |
333 } | |
334 g_free(filename); | |
335 } | |
336 | |
337 static void zephyr_login(struct aim_user *user) | |
338 { | |
339 ZSubscription_t sub; | |
340 | |
341 if (zgc) { | |
342 do_error_dialog("Already logged in with Zephyr", "Zephyr"); | |
343 return; | |
344 } | |
345 | |
346 zgc = new_gaim_conn(user); | |
347 | |
348 z_call_s(ZInitialize(), "Couldn't initialize zephyr"); | |
349 z_call_s(ZOpenPort(NULL), "Couldn't open port"); | |
350 z_call_s(ZSetLocation(get_exposure_level()), "Couldn't set location"); | |
351 | |
352 sub.zsub_class = "MESSAGE"; | |
353 sub.zsub_classinst = "PERSONAL"; | |
354 sub.zsub_recipient = ZGetSender(); | |
355 | |
356 /* we don't care if this fails. i'm lying right now. */ | |
1719
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
357 if (ZSubscribeTo(&sub, 1, 0) != ZERR_NONE) { |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
358 debug_printf("Zephyr: Couldn't subscribe to messages!\n"); |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
359 } |
1700 | 360 |
361 account_online(zgc); | |
362 serv_finish_login(zgc); | |
363 | |
364 if (bud_list_cache_exists(zgc)) | |
365 do_import(NULL, zgc); | |
366 process_anyone(); | |
1719
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
367 /* call process_zsubs to subscribe. still commented out since I don't know |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
368 * how you want to handle incoming msgs from subs. |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
369 process_zsubs(); */ |
1700 | 370 |
371 nottimer = gtk_timeout_add(100, check_notify, NULL); | |
372 loctimer = gtk_timeout_add(2000, check_loc, NULL); | |
373 } | |
374 | |
375 static void zephyr_close(struct gaim_connection *gc) | |
376 { | |
1719
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
377 g_list_foreach(pending_zloc_names, (GFunc)g_free, NULL); |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
378 g_list_free(pending_zloc_names); |
1700 | 379 /* should probably write .anyone, but eh. we all use gaim exclusively, right? :-P */ |
380 if (nottimer) | |
381 gtk_timeout_remove(nottimer); | |
382 nottimer = 0; | |
383 if (loctimer) | |
384 gtk_timeout_remove(loctimer); | |
385 loctimer = 0; | |
386 zgc = NULL; | |
387 z_call(ZCancelSubscriptions(0)); | |
388 z_call(ZUnsetLocation()); | |
389 z_call(ZClosePort()); | |
390 } | |
391 | |
392 static void zephyr_add_buddy(struct gaim_connection *gc, char *buddy) { } | |
393 static void zephyr_remove_buddy(struct gaim_connection *gc, char *buddy) { } | |
394 | |
395 static void zephyr_send_im(struct gaim_connection *gc, char *who, char *im, int away) { | |
396 ZNotice_t notice; | |
1719
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
397 char *buf; |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
398 char *sig; |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
399 |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
400 sig = ZGetVariable("zwrite-signature"); |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
401 if (!sig) { |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
402 sig = g_get_real_name(); |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
403 } |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
404 buf = g_strdup_printf("%s%c%s", sig, '\0', im); |
1700 | 405 |
406 bzero((char *)¬ice, sizeof(notice)); | |
407 notice.z_kind = ACKED; | |
408 notice.z_port = 0; | |
409 notice.z_opcode = ""; | |
410 notice.z_class = "MESSAGE"; | |
411 notice.z_class_inst = "PERSONAL"; | |
412 notice.z_sender = 0; | |
413 notice.z_recipient = who; | |
414 notice.z_default_format = | |
1719
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
415 "Class $class, Instance $instance:\n" |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
416 "To: @bold($recipient) at $time $date\n" |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
417 "From: @bold($1) <$sender>\n\n$2"; |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
418 notice.z_message_len = strlen(im) + strlen(sig) + 4; |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
419 notice.z_message = buf; |
1700 | 420 ZSendNotice(¬ice, ZAUTH); |
1719
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
421 g_free(buf); |
1700 | 422 } |
423 | |
424 static struct prpl *my_protocol = NULL; | |
425 | |
426 void zephyr_init(struct prpl *ret) | |
427 { | |
428 ret->protocol = PROTO_ZEPHYR; | |
429 ret->name = zephyr_name; | |
430 ret->login = zephyr_login; | |
431 ret->close = zephyr_close; | |
432 ret->add_buddy = zephyr_add_buddy; | |
433 ret->remove_buddy = zephyr_remove_buddy; | |
434 ret->send_im = zephyr_send_im; | |
1719
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
435 ret->get_info = zephyr_zloc; |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
436 ret->normalize = zephyr_normalize; |
5800449e7ecc
[gaim-migrate @ 1729]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1700
diff
changeset
|
437 ret->buddy_menu = zephyr_buddy_menu; |
1700 | 438 |
439 my_protocol = ret; | |
440 } | |
441 | |
442 char *gaim_plugin_init(GModule *handle) | |
443 { | |
444 load_protocol(zephyr_init, sizeof(struct prpl)); | |
445 return NULL; | |
446 } | |
447 | |
448 void gaim_plugin_remove() | |
449 { | |
450 struct prpl *p = find_prpl(PROTO_ZEPHYR); | |
451 if (p == my_protocol) | |
452 unload_protocol(p); | |
453 } |