Mercurial > pidgin
comparison src/oscar.c @ 1:2846a03bda67
[gaim-migrate @ 10]
The other missing files :)
committer: Tailor Script <tailor@pidgin.im>
author | Rob Flynn <gaim@robflynn.com> |
---|---|
date | Thu, 23 Mar 2000 03:13:54 +0000 |
parents | |
children | 34db9f242899 |
comparison
equal
deleted
inserted
replaced
0:a5ace2e037bc | 1:2846a03bda67 |
---|---|
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 USE_OSCAR | |
24 | |
25 #include <netdb.h> | |
26 #include <gtk/gtk.h> | |
27 #include <unistd.h> | |
28 #include <errno.h> | |
29 #include <netinet/in.h> | |
30 #include <arpa/inet.h> | |
31 #include <string.h> | |
32 #include <stdlib.h> | |
33 #include <stdio.h> | |
34 #include <time.h> | |
35 #include <sys/socket.h> | |
36 #include <sys/stat.h> | |
37 #include "gaim.h" | |
38 #include <aim.h> | |
39 #include "gnome_applet_mgr.h" | |
40 | |
41 struct aim_conn_t *gaim_conn = NULL; | |
42 static int inpa = -1; | |
43 | |
44 int gaim_auth_failure(struct command_rx_struct *command, ...); | |
45 int gaim_auth_success(struct command_rx_struct *command, ...); | |
46 int gaim_serverready_handle(struct command_rx_struct *command, ...); | |
47 int gaim_redirect_handle(struct command_rx_struct *command, ...); | |
48 int gaim_im_handle(struct command_rx_struct *command, ...); | |
49 | |
50 rxcallback_t gaim_callbacks[] = { | |
51 gaim_im_handle, /* incoming IM */ | |
52 NULL,/*gaim_buddy_coming, oncoming buddy */ | |
53 NULL,/*gaim_buddy_going, offgoing buddy */ | |
54 NULL, /* last IM was missed 1 */ | |
55 NULL, /* last IM was missed 2 */ | |
56 NULL, /* UNUSED */ | |
57 NULL, /* UNUSED */ | |
58 NULL, /* UNUSED */ | |
59 gaim_serverready_handle, /* server ready */ | |
60 NULL, /* UNUSED */ | |
61 NULL, /* UNUSED */ | |
62 NULL, /* UNUSED */ | |
63 NULL, /* UNUSED */ | |
64 NULL, /* UNUSED */ | |
65 NULL, /* UNUSED */ | |
66 gaim_redirect_handle, /* redirect */ | |
67 NULL, /* last command bad */ | |
68 NULL, /* missed some messages */ | |
69 NULL, /* completely unknown command */ | |
70 NULL, /*gaim_userinfo_handler, User Info Response */ | |
71 NULL, /* Address search response */ | |
72 NULL, /* Name search response */ | |
73 NULL, /* User Search fail */ | |
74 gaim_auth_failure, /* auth error */ | |
75 gaim_auth_success, /* auth success */ | |
76 NULL, /* auth server ready */ | |
77 NULL, /* ? */ | |
78 NULL, /* password change done */ | |
79 gaim_serverready_handle, /* server ready */ | |
80 0x00 | |
81 }; | |
82 | |
83 struct client_info_s cinfo; | |
84 | |
85 | |
86 void oscar_close() | |
87 { | |
88 #ifdef USE_APPLET | |
89 setUserState(offline); | |
90 #endif /* USE_APPLET */ | |
91 set_state(STATE_OFFLINE); | |
92 aim_conn_close(gaim_conn); | |
93 if (inpa > 0) | |
94 gdk_input_remove(inpa); | |
95 inpa=-1; | |
96 } | |
97 | |
98 | |
99 void oscar_callback(gpointer data, gint source, GdkInputCondition condition) | |
100 { | |
101 if (aim_get_command() < 0) { | |
102 signoff(); | |
103 hide_login_progress("Connection Closed"); | |
104 return; | |
105 } else | |
106 aim_rxdispatch(); | |
107 | |
108 } | |
109 | |
110 int oscar_login(char *username, char *password) | |
111 { | |
112 char buf[256]; | |
113 struct timeval timeout; | |
114 time_t lastcycle=0; | |
115 | |
116 aim_connrst(); | |
117 aim_register_callbacks(gaim_callbacks); | |
118 | |
119 aim_conn_getnext()->fd = STDIN_FILENO; | |
120 | |
121 set_login_progress(1, "Looking up " login_host); | |
122 | |
123 gaim_conn = aim_newconn(AIM_CONN_TYPE_AUTH, login_host); | |
124 | |
125 if (!gaim_conn) { | |
126 #ifdef USE_APPLET | |
127 setUserState(offline); | |
128 #endif /* USE_APPLET */ | |
129 set_state(STATE_OFFLINE); | |
130 hide_login_progress("Unable to login to AIM"); | |
131 return -1; | |
132 } else if (gaim_conn->fd == -1) { | |
133 #ifdef USE_APPLET | |
134 setUserState(offline); | |
135 #endif /* USE_APPLET */ | |
136 set_state(STATE_OFFLINE); | |
137 | |
138 if (gaim_conn->status & AIM_CONN_STATUS_RESOLVERR) { | |
139 hide_login_progress("Unable to lookup " login_host); | |
140 } else if (gaim_conn->status & AIM_CONN_STATUS_CONNERR) { | |
141 hide_login_progress("Unable to connect to " login_host); | |
142 } | |
143 return -1; | |
144 } | |
145 | |
146 g_snprintf(buf, sizeof(buf), "Signon: %s",username); | |
147 | |
148 set_login_progress(2, buf); | |
149 | |
150 strcpy(cinfo.clientstring, "libfaim/GAIM, jimduchek@ou.edu, see at http://www.marko.net/gaim"); | |
151 cinfo.major = 0; | |
152 cinfo.minor = 9; | |
153 cinfo.build = 7; | |
154 strcpy(cinfo.country, "us"); | |
155 strcpy(cinfo.lang, "en"); | |
156 | |
157 aim_send_login(gaim_conn, username, password, &cinfo); | |
158 | |
159 if (!current_user) { | |
160 current_user = g_new0(struct aim_user, 1); | |
161 g_snprintf(current_user->username, sizeof(current_user->username), DEFAULT_INFO); | |
162 aim_users = g_list_append(aim_users, current_user); | |
163 } | |
164 | |
165 g_snprintf(current_user->username, sizeof(current_user->username), "%s", username); | |
166 g_snprintf(current_user->password, sizeof(current_user->password), "%s", password); | |
167 | |
168 save_prefs(); | |
169 | |
170 inpa = gdk_input_add(gaim_conn->fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, oscar_callback, NULL); | |
171 | |
172 return 0; | |
173 } | |
174 | |
175 int gaim_auth_success(struct command_rx_struct *command, ...) | |
176 { | |
177 va_list ap; | |
178 struct login_phase1_struct *logininfo; | |
179 struct aim_conn_t *bosconn = NULL; | |
180 char buf[128]; | |
181 | |
182 va_start(ap, command); | |
183 logininfo = va_arg(ap, struct login_phase1_struct *); | |
184 va_end(ap); | |
185 | |
186 g_snprintf(buf, sizeof(buf), "Auth successful, logging in to %s:", logininfo->BOSIP); | |
187 set_login_progress(3, buf); | |
188 | |
189 printf(" Screen name: %s\n", logininfo->screen_name); | |
190 printf(" Email addresss: %s\n", logininfo->email); | |
191 printf(" Registration status: %02i\n", logininfo->regstatus); | |
192 printf("Connecting to %s, closing auth connection.\n", | |
193 logininfo->BOSIP); | |
194 | |
195 aim_conn_close(command->conn); | |
196 | |
197 gdk_input_remove(inpa); | |
198 | |
199 if ((bosconn = aim_newconn(AIM_CONN_TYPE_BOS, logininfo->BOSIP)) | |
200 == NULL) { | |
201 #ifdef USE_APPLET | |
202 setUserState(offline); | |
203 #endif /* USE_APPLET */ | |
204 set_state(STATE_OFFLINE); | |
205 | |
206 hide_login_progress("Could not connect to BOS: internal error"); | |
207 return(-1); | |
208 } else if (bosconn->status != 0) { | |
209 #ifdef USE_APPLET | |
210 setUserState(offline); | |
211 #endif /* USE_APPLET */ | |
212 set_state(STATE_OFFLINE); | |
213 | |
214 hide_login_progress("Could not connect to BOS"); | |
215 return(-1); | |
216 } else { | |
217 aim_auth_sendcookie(bosconn, logininfo->cookie); | |
218 inpa = gdk_input_add(bosconn->fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, oscar_callback, NULL); | |
219 set_login_progress(4, "BOS connection established, cookie sent."); | |
220 return(1); | |
221 } | |
222 } | |
223 | |
224 int gaim_auth_failure(struct command_rx_struct *command, ...) | |
225 { | |
226 va_list ap; | |
227 struct login_phase1_struct *logininfo; | |
228 char *errorurl; | |
229 short errorcode; | |
230 | |
231 va_start(ap, command); | |
232 logininfo = va_arg(ap, struct login_phase1_struct *); | |
233 printf("Screen name: %s\n", logininfo->screen_name); | |
234 errorurl = va_arg(ap, char *); | |
235 printf("Error URL: %s\n", errorurl); | |
236 errorcode = va_arg(ap, short); | |
237 printf("Error code: 0x%02x\n", errorcode); | |
238 va_end(ap); | |
239 #ifdef USE_APPLET | |
240 setUserState(offline); | |
241 #endif /* USE_APPLET */ | |
242 set_state(STATE_OFFLINE); | |
243 hide_login_progress("Authentication Failed"); | |
244 | |
245 aim_conn_close(aim_getconn_type(AIM_CONN_TYPE_AUTH)); | |
246 | |
247 return 1; | |
248 } | |
249 | |
250 int gaim_serverready_handle(struct command_rx_struct *command, ...) | |
251 { | |
252 switch (command->conn->type) { | |
253 case AIM_CONN_TYPE_BOS: | |
254 aim_bos_reqrate(command->conn); | |
255 aim_bos_ackrateresp(command->conn); | |
256 aim_bos_setprivacyflags(command->conn, 0x00000003); | |
257 aim_bos_reqservice(command->conn, AIM_CONN_TYPE_ADS); | |
258 aim_bos_setgroupperm(NULL, 0x1f); | |
259 break; | |
260 case AIM_CONN_TYPE_CHATNAV: | |
261 break; | |
262 default: | |
263 printf("Unknown connection type on serverready\n"); | |
264 break; | |
265 } | |
266 return(1); | |
267 | |
268 } | |
269 | |
270 int gaim_redirect_handle(struct command_rx_struct *command, ...) | |
271 { | |
272 va_list ap; | |
273 int serviceid; | |
274 char *ip, *cookie; | |
275 | |
276 va_start(ap, command); | |
277 serviceid = va_arg(ap, int); | |
278 ip = va_arg(ap, char *); | |
279 cookie = va_arg(ap, char *); | |
280 va_end(ap); | |
281 | |
282 switch(serviceid) { | |
283 case 0x0005: { | |
284 char *buf; | |
285 char *buf2; | |
286 char *first = g_malloc(64); | |
287 char file[1024]; | |
288 FILE *f; | |
289 | |
290 g_snprintf(file, sizeof(file), "%s/.gaimbuddy", getenv("HOME")); | |
291 | |
292 if (!(f = fopen(file,"r"))) { | |
293 } else { | |
294 buf = g_malloc(BUF_LONG); | |
295 fread(buf, BUF_LONG, 1, f); | |
296 | |
297 parse_toc_buddy_list(buf); | |
298 | |
299 build_edit_tree(); | |
300 build_permit_tree(); | |
301 | |
302 | |
303 g_free(buf); | |
304 } | |
305 | |
306 | |
307 | |
308 aim_bos_clientready(command->conn); | |
309 | |
310 set_login_progress(5, "Logged in.\n"); | |
311 #ifdef USE_APPLET | |
312 if (applet_buddy_auto_show) { | |
313 show_buddy_list(); | |
314 refresh_buddy_window(); | |
315 } else { | |
316 } | |
317 | |
318 set_applet_draw_closed(); | |
319 setUserState(online); | |
320 #else | |
321 gtk_widget_hide(mainwindow); | |
322 show_buddy_list(); | |
323 refresh_buddy_window(); | |
324 #endif | |
325 serv_finish_login(); | |
326 gaim_conn = command->conn; | |
327 | |
328 break; | |
329 } | |
330 case 0x0007: { | |
331 struct aim_conn_t *tstconn; | |
332 | |
333 tstconn = aim_newconn(AIM_CONN_TYPE_AUTH, ip); | |
334 if ((tstconn == NULL) || | |
335 (tstconn->status >= AIM_CONN_STATUS_RESOLVERR)) { | |
336 #ifdef USE_APPLET | |
337 setUserState(offline); | |
338 #endif /* USE_APPLET */ | |
339 set_state(STATE_OFFLINE); | |
340 hide_login_progress("Unable to reconnect to authorizer"); | |
341 } else | |
342 aim_auth_sendcookie(tstconn, cookie); | |
343 break; | |
344 } | |
345 case 0x000d: { | |
346 struct aim_conn_t *tstconn; | |
347 | |
348 tstconn = aim_newconn(AIM_CONN_TYPE_CHATNAV, ip); | |
349 if ((tstconn == NULL) || | |
350 (tstconn->status >= AIM_CONN_STATUS_RESOLVERR)) | |
351 printf("Unable to connect to chatnav server\n"); | |
352 else | |
353 aim_auth_sendcookie( | |
354 aim_getconn_type(AIM_CONN_TYPE_CHATNAV), | |
355 cookie); | |
356 break; | |
357 } | |
358 case 0x000e: | |
359 printf("CHAT is not yet supported :(\n"); | |
360 break; | |
361 default: | |
362 printf("Unknown redirect %#04X\n", serviceid); | |
363 break; | |
364 } | |
365 return(1); | |
366 | |
367 } | |
368 | |
369 | |
370 | |
371 int gaim_im_handle(struct command_rx_struct *command, ...) | |
372 { | |
373 time_t t = 0; | |
374 char *screenname, *msg; | |
375 int warninglevel, class, idletime, isautoreply; | |
376 ulong membersince, onsince; | |
377 va_list ap; | |
378 | |
379 va_start(ap, command); | |
380 screenname = va_arg(ap, char *); | |
381 msg = va_arg(ap, char *); | |
382 warninglevel = va_arg(ap, int); | |
383 class = va_arg(ap, int); | |
384 membersince = va_arg(ap, ulong); | |
385 onsince = va_arg(ap, ulong); | |
386 idletime = va_arg(ap, int); | |
387 isautoreply = va_arg(ap, int); | |
388 va_end(ap); | |
389 | |
390 printf("'%s'\n", msg); | |
391 | |
392 serv_got_im(screenname, msg, isautoreply); | |
393 | |
394 return(1); | |
395 | |
396 | |
397 } | |
398 | |
399 #endif |