Mercurial > pidgin
annotate plugins/yay/yay.c @ 1090:79cdc86ef4c6
[gaim-migrate @ 1100]
necessary checks
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Mon, 13 Nov 2000 02:59:23 +0000 |
parents | f0f5c10cce63 |
children | c1dcba9f3a3a |
rev | line source |
---|---|
1054 | 1 /* |
2 * gaim | |
3 * | |
4 * Some code copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
5 * libfaim code copyright 1998, 1999 Adam Fritzler <afritz@auk.cx> | |
6 * | |
7 * This program is free software; you can redistribute it and/or modify | |
8 * it under the terms of the GNU General Public License as published by | |
9 * the Free Software Foundation; either version 2 of the License, or | |
10 * (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, | |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 * GNU General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License | |
18 * along with this program; if not, write to the Free Software | |
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
20 * | |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include "../config.h" | |
25 #endif | |
26 | |
27 | |
28 #include <netdb.h> | |
29 #include <gtk/gtk.h> | |
30 #include <unistd.h> | |
31 #include <errno.h> | |
32 #include <netinet/in.h> | |
33 #include <arpa/inet.h> | |
34 #include <string.h> | |
35 #include <stdlib.h> | |
36 #include <stdio.h> | |
37 #include <time.h> | |
38 #include <sys/socket.h> | |
39 #include <sys/stat.h> | |
40 #include "multi.h" | |
41 #include "prpl.h" | |
42 #include "gaim.h" | |
43 #include "libyahoo.h" | |
44 | |
45 struct yahoo_data { | |
46 struct yahoo_context *ctxt; | |
47 }; | |
48 | |
49 static char *yahoo_name() { | |
50 return "Yahoo"; | |
51 } | |
52 | |
53 char *name() { | |
54 return "Yahoo"; | |
55 } | |
56 | |
57 char *description() { | |
58 return "Allows gaim to use the Yahoo protocol"; | |
59 } | |
60 | |
61 static void process_packet_status(struct gaim_connection *gc, struct yahoo_packet *pkt) { | |
62 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
63 int i; | |
64 | |
65 if (pkt->service == YAHOO_SERVICE_LOGOFF && !strcasecmp(pkt->active_id, gc->username)) { | |
66 signoff(gc); | |
67 return; | |
68 } | |
69 | |
70 for (i = 0; i < pkt->idstatus_count; i++) { | |
71 struct group *g; | |
72 struct buddy *b; | |
73 struct yahoo_idstatus *rec = pkt->idstatus[i]; | |
74 | |
75 b = find_buddy(gc, rec->id); | |
76 if (!b) { | |
77 struct yahoo_buddy **buddy; | |
78 for (buddy = yd->ctxt->buddies; *buddy; buddy++) { | |
79 struct yahoo_buddy *bud = *buddy; | |
80 | |
81 if (!strcasecmp(rec->id, bud->id)) | |
82 b = add_buddy(gc, bud->group, bud->id, bud->id); | |
83 } | |
84 } | |
85 if (pkt->service == YAHOO_SERVICE_LOGOFF) | |
86 serv_got_update(gc, b->name, 0, 0, 0, 0, 0, 0); | |
87 else | |
88 serv_got_update(gc, b->name, 1, 0, 0, 0, rec->status, 0); | |
89 } | |
90 } | |
91 | |
92 static void process_packet_message(struct gaim_connection *gc, struct yahoo_packet *pkt) { | |
93 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
94 | |
95 if (pkt->msg) { | |
96 if (pkt->msgtype == YAHOO_MSGTYPE_BOUNCE) | |
97 do_error_dialog("Your message did not get received.", "Error"); | |
98 else | |
99 serv_got_im(gc, pkt->msg_id, pkt->msg, pkt->msg_timestamp ? 1 : 0); | |
100 } | |
101 } | |
102 | |
103 static void process_packet_conf_invite(struct gaim_connection *gc, struct yahoo_packet *pkt) { | |
104 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
105 } | |
106 | |
107 static void process_packet_conf_add_invite(struct gaim_connection *gc, struct yahoo_packet *pkt) { | |
108 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
109 } | |
110 | |
111 static void process_packet_conf_msg(struct gaim_connection *gc, struct yahoo_packet *pkt) { | |
112 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
113 } | |
114 | |
115 static void process_packet_conf_logon(struct gaim_connection *gc, struct yahoo_packet *pkt) { | |
116 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
117 } | |
118 | |
119 static void process_packet_conf_logoff(struct gaim_connection *gc, struct yahoo_packet *pkt) { | |
120 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
121 } | |
122 | |
123 static void process_packet_newmail(struct gaim_connection *gc, struct yahoo_packet *pkt) { | |
124 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
125 char buf[2048]; | |
126 | |
127 if (pkt->mail_status) { | |
128 if (pkt->service == YAHOO_SERVICE_NEWMAIL) | |
129 g_snprintf(buf, sizeof buf, "%s has %d new message%s on Yahoo Mail.", | |
130 gc->username, pkt->mail_status, | |
131 pkt->mail_status == 1 ? "" : "s"); | |
132 else | |
133 g_snprintf(buf, sizeof buf, "%s has %d new personal message%s on Yahoo Mail.", | |
134 gc->username, pkt->mail_status, | |
135 pkt->mail_status == 1 ? "" : "s"); | |
136 do_error_dialog(buf, "New Mail!"); | |
137 } | |
138 } | |
139 | |
140 static void yahoo_callback(gpointer data, gint source, GdkInputCondition condition) { | |
141 struct gaim_connection *gc = (struct gaim_connection *)data; | |
142 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
143 | |
144 struct yahoo_rawpacket *rawpkt; | |
145 struct yahoo_packet *pkt; | |
146 | |
147 if (!yahoo_getdata(yd->ctxt)) { | |
148 signoff(gc); | |
149 } | |
150 | |
151 while ((rawpkt = yahoo_getpacket(yd->ctxt)) != NULL) { | |
152 pkt = yahoo_parsepacket(yd->ctxt, rawpkt); | |
153 | |
154 switch (pkt->service) { | |
155 case YAHOO_SERVICE_USERSTAT: | |
156 case YAHOO_SERVICE_CHATLOGON: | |
157 case YAHOO_SERVICE_CHATLOGOFF: | |
158 case YAHOO_SERVICE_LOGON: | |
159 case YAHOO_SERVICE_LOGOFF: | |
160 case YAHOO_SERVICE_ISAWAY: | |
161 case YAHOO_SERVICE_ISBACK: | |
162 process_packet_status(gc, pkt); | |
163 break; | |
164 case YAHOO_SERVICE_MESSAGE: | |
165 case YAHOO_SERVICE_CHATMSG: | |
166 case YAHOO_SERVICE_SYSMESSAGE: | |
167 process_packet_message(gc, pkt); | |
168 break; | |
169 case YAHOO_SERVICE_CONFINVITE: | |
170 process_packet_conf_invite(gc, pkt); | |
171 break; | |
172 case YAHOO_SERVICE_CONFADDINVITE: | |
173 process_packet_conf_add_invite(gc, pkt); | |
174 break; | |
175 case YAHOO_SERVICE_CONFMSG: | |
176 process_packet_conf_msg(gc, pkt); | |
177 break; | |
178 case YAHOO_SERVICE_CONFLOGON: | |
179 process_packet_conf_logon(gc, pkt); | |
180 break; | |
181 case YAHOO_SERVICE_CONFLOGOFF: | |
182 process_packet_conf_logoff(gc, pkt); | |
183 break; | |
184 case YAHOO_SERVICE_NEWMAIL: | |
185 case YAHOO_SERVICE_NEWPERSONALMAIL: | |
186 process_packet_newmail(gc, pkt); | |
187 break; | |
188 default: | |
189 debug_printf("Unhandled packet type %s\n", | |
190 yahoo_get_service_string(pkt->service)); | |
191 break; | |
192 } | |
193 yahoo_free_packet(pkt); | |
194 yahoo_free_rawpacket(rawpkt); | |
195 } | |
196 } | |
197 | |
198 static void yahoo_login(struct aim_user *user) { | |
1089
f0f5c10cce63
[gaim-migrate @ 1099]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
199 struct gaim_connection *gc = new_gaim_conn(user); |
1054 | 200 struct yahoo_data *yd = gc->proto_data = g_new0(struct yahoo_data, 1); |
201 int i; | |
202 | |
203 struct yahoo_options opt; | |
204 struct yahoo_context *ctxt; | |
205 opt.connect_mode = YAHOO_CONNECT_NORMAL; | |
206 opt.proxy_host = NULL; | |
207 ctxt = yahoo_init(user->username, user->password, &opt); | |
208 yd->ctxt = ctxt; | |
209 | |
210 set_login_progress(gc, 1, "Connecting"); | |
211 while (gtk_events_pending()) | |
212 gtk_main_iteration(); | |
1090
79cdc86ef4c6
[gaim-migrate @ 1100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1089
diff
changeset
|
213 if (!g_slist_find(connections, gc)) |
79cdc86ef4c6
[gaim-migrate @ 1100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1089
diff
changeset
|
214 return; |
1054 | 215 |
216 if (!ctxt || !yahoo_connect(ctxt)) { | |
217 debug_printf("Yahoo: Unable to connect\n"); | |
218 hide_login_progress(gc, "Unable to connect"); | |
219 destroy_gaim_conn(gc); | |
220 return; | |
221 } | |
222 | |
223 debug_printf("Yahoo: connected\n"); | |
224 | |
225 set_login_progress(gc, 3, "Getting Config"); | |
226 while (gtk_events_pending()) | |
227 gtk_main_iteration(); | |
1090
79cdc86ef4c6
[gaim-migrate @ 1100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1089
diff
changeset
|
228 if (!g_slist_find(connections, gc)) |
79cdc86ef4c6
[gaim-migrate @ 1100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1089
diff
changeset
|
229 return; |
1054 | 230 |
231 yahoo_get_config(ctxt); | |
232 | |
233 if (yahoo_cmd_logon(ctxt, YAHOO_STATUS_AVAILABLE)) { | |
234 debug_printf("Yahoo: Unable to login\n"); | |
235 hide_login_progress(gc, "Unable to login"); | |
236 destroy_gaim_conn(gc); | |
237 return; | |
238 } | |
239 | |
240 if (ctxt->buddies) { | |
241 struct yahoo_buddy **buddies; | |
242 | |
243 for (buddies = ctxt->buddies; *buddies; buddies++) { | |
244 struct yahoo_buddy *bud = *buddies; | |
245 struct buddy *b; | |
246 struct group *g; | |
247 | |
248 b = find_buddy(gc, bud->id); | |
249 if (!b) add_buddy(gc, bud->group, bud->id, bud->id); | |
250 } | |
251 } | |
252 | |
253 debug_printf("Yahoo: logged in %s\n", gc->username); | |
1089
f0f5c10cce63
[gaim-migrate @ 1099]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
254 account_online(gc); |
1054 | 255 serv_finish_login(gc); |
256 | |
257 gc->inpa = gdk_input_add(ctxt->sockfd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, | |
258 yahoo_callback, gc); | |
259 } | |
260 | |
261 static void yahoo_close(struct gaim_connection *gc) { | |
262 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
263 if (gc->inpa) | |
264 gdk_input_remove(gc->inpa); | |
265 gc->inpa = -1; | |
266 yahoo_cmd_logoff(yd->ctxt); | |
267 g_free(yd); | |
268 } | |
269 | |
270 static void yahoo_send_im(struct gaim_connection *gc, char *who, char *message, int away) { | |
271 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
272 | |
273 yahoo_cmd_msg(yd->ctxt, gc->username, who, message); | |
274 } | |
275 | |
276 static void yahoo_set_idle(struct gaim_connection *gc, int idle) { | |
277 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
278 | |
279 if (idle) | |
280 yahoo_cmd_set_away_mode(yd->ctxt, YAHOO_STATUS_IDLE, NULL); | |
281 else | |
282 yahoo_cmd_set_back_mode(yd->ctxt, YAHOO_STATUS_AVAILABLE, NULL); | |
283 } | |
284 | |
285 static void yahoo_keepalive(struct gaim_connection *gc) { | |
286 yahoo_cmd_ping(((struct yahoo_data *)gc->proto_data)->ctxt); | |
287 } | |
288 | |
289 static void gyahoo_add_buddy(struct gaim_connection *gc, char *name) { | |
290 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
291 struct yahoo_buddy *tmpbuddy; | |
292 struct group *g = find_group_by_buddy(gc, name); | |
293 char *group = NULL; | |
294 | |
295 if (g) { | |
296 group = g->name; | |
297 } else if (yd->ctxt && yd->ctxt->buddies[0]) { | |
298 tmpbuddy = yd->ctxt->buddies[0]; | |
299 group = tmpbuddy->group; | |
300 } | |
301 | |
302 if (group) | |
303 yahoo_add_buddy(yd->ctxt, name, gc->username, group, ""); | |
304 } | |
305 | |
306 static struct prpl *my_protocol = NULL; | |
307 | |
308 void Yahoo_init(struct prpl *ret) { | |
309 /* the NULL's aren't required but they're nice to have */ | |
310 ret->protocol = PROTO_YAHOO; | |
311 ret->name = yahoo_name; | |
312 ret->list_icon = NULL; | |
313 ret->action_menu = NULL; | |
314 ret->login = yahoo_login; | |
315 ret->close = yahoo_close; | |
316 ret->send_im = yahoo_send_im; | |
317 ret->set_info = NULL; | |
318 ret->get_info = NULL; | |
319 ret->set_away = NULL; | |
320 ret->get_away_msg = NULL; | |
321 ret->set_dir = NULL; | |
322 ret->get_dir = NULL; | |
323 ret->dir_search = NULL; | |
324 ret->set_idle = yahoo_set_idle; | |
325 ret->change_passwd = NULL; | |
326 ret->add_buddy = gyahoo_add_buddy; | |
327 ret->add_buddies = NULL; | |
328 ret->remove_buddy = NULL; | |
329 ret->add_permit = NULL; | |
330 ret->add_deny = NULL; | |
331 ret->rem_permit = NULL; | |
332 ret->rem_deny = NULL; | |
333 ret->set_permit_deny = NULL; | |
334 ret->warn = NULL; | |
335 ret->accept_chat = NULL; | |
336 ret->join_chat = NULL; | |
337 ret->chat_invite = NULL; | |
338 ret->chat_leave = NULL; | |
339 ret->chat_whisper = NULL; | |
340 ret->chat_send = NULL; | |
341 ret->keepalive = yahoo_keepalive; | |
342 | |
343 my_protocol = ret; | |
344 } | |
345 | |
346 char *gaim_plugin_init(GModule *handle) { | |
347 load_protocol(Yahoo_init); | |
348 return NULL; | |
349 } | |
350 | |
351 void gaim_plugin_remove() { | |
352 struct prpl *p = find_prpl(PROTO_YAHOO); | |
353 if (p == my_protocol) | |
354 unload_protocol(p); | |
355 } |