Mon, 24 Apr 2000 01:47:24 +0000
[gaim-migrate @ 163]
This should be interesting. We'll see how well this works. I can't explain
why, but I have a bad feeling about this one.
| 1 | 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 | ||
|
74
3c0d42030507
[gaim-migrate @ 84]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
10
diff
changeset
|
121 | spintf(buf, "Looking up %s", login_host); |
|
3c0d42030507
[gaim-migrate @ 84]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
10
diff
changeset
|
122 | set_login_progress(1, buf); |
| 1 | 123 | |
| 124 | gaim_conn = aim_newconn(AIM_CONN_TYPE_AUTH, login_host); | |
| 125 | ||
| 126 | if (!gaim_conn) { | |
| 127 | #ifdef USE_APPLET | |
| 128 | setUserState(offline); | |
| 129 | #endif /* USE_APPLET */ | |
| 130 | set_state(STATE_OFFLINE); | |
| 131 | hide_login_progress("Unable to login to AIM"); | |
| 132 | return -1; | |
| 133 | } else if (gaim_conn->fd == -1) { | |
| 134 | #ifdef USE_APPLET | |
| 135 | setUserState(offline); | |
| 136 | #endif /* USE_APPLET */ | |
| 137 | set_state(STATE_OFFLINE); | |
| 138 | ||
| 139 | if (gaim_conn->status & AIM_CONN_STATUS_RESOLVERR) { | |
|
74
3c0d42030507
[gaim-migrate @ 84]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
10
diff
changeset
|
140 | sprintf(buf, "Unable to lookup %s", login_host); |
|
3c0d42030507
[gaim-migrate @ 84]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
10
diff
changeset
|
141 | hide_login_progress(buf); |
| 1 | 142 | } else if (gaim_conn->status & AIM_CONN_STATUS_CONNERR) { |
|
74
3c0d42030507
[gaim-migrate @ 84]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
10
diff
changeset
|
143 | sprintf(buf, "Unable to connect to %s", login_host); |
|
3c0d42030507
[gaim-migrate @ 84]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
10
diff
changeset
|
144 | hide_login_progress(buf); |
| 1 | 145 | } |
| 146 | return -1; | |
| 147 | } | |
| 148 | ||
| 149 | g_snprintf(buf, sizeof(buf), "Signon: %s",username); | |
| 150 | ||
| 151 | set_login_progress(2, buf); | |
| 152 | ||
| 153 | strcpy(cinfo.clientstring, "libfaim/GAIM, jimduchek@ou.edu, see at http://www.marko.net/gaim"); | |
| 154 | cinfo.major = 0; | |
| 155 | cinfo.minor = 9; | |
| 156 | cinfo.build = 7; | |
| 157 | strcpy(cinfo.country, "us"); | |
| 158 | strcpy(cinfo.lang, "en"); | |
| 159 | ||
| 160 | aim_send_login(gaim_conn, username, password, &cinfo); | |
| 161 | ||
| 162 | if (!current_user) { | |
| 163 | current_user = g_new0(struct aim_user, 1); | |
| 164 | g_snprintf(current_user->username, sizeof(current_user->username), DEFAULT_INFO); | |
| 165 | aim_users = g_list_append(aim_users, current_user); | |
| 166 | } | |
| 167 | ||
| 168 | g_snprintf(current_user->username, sizeof(current_user->username), "%s", username); | |
| 169 | g_snprintf(current_user->password, sizeof(current_user->password), "%s", password); | |
| 170 | ||
| 171 | save_prefs(); | |
| 172 | ||
| 173 | inpa = gdk_input_add(gaim_conn->fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, oscar_callback, NULL); | |
| 174 | ||
| 175 | return 0; | |
| 176 | } | |
| 177 | ||
| 178 | int gaim_auth_success(struct command_rx_struct *command, ...) | |
| 179 | { | |
| 180 | va_list ap; | |
| 181 | struct login_phase1_struct *logininfo; | |
| 182 | struct aim_conn_t *bosconn = NULL; | |
| 183 | char buf[128]; | |
| 184 | ||
| 185 | va_start(ap, command); | |
| 186 | logininfo = va_arg(ap, struct login_phase1_struct *); | |
| 187 | va_end(ap); | |
| 188 | ||
| 189 | g_snprintf(buf, sizeof(buf), "Auth successful, logging in to %s:", logininfo->BOSIP); | |
| 190 | set_login_progress(3, buf); | |
| 191 | ||
| 192 | printf(" Screen name: %s\n", logininfo->screen_name); | |
| 193 | printf(" Email addresss: %s\n", logininfo->email); | |
| 194 | printf(" Registration status: %02i\n", logininfo->regstatus); | |
| 195 | printf("Connecting to %s, closing auth connection.\n", | |
| 196 | logininfo->BOSIP); | |
| 197 | ||
| 198 | aim_conn_close(command->conn); | |
| 199 | ||
| 200 | gdk_input_remove(inpa); | |
| 201 | ||
| 202 | if ((bosconn = aim_newconn(AIM_CONN_TYPE_BOS, logininfo->BOSIP)) | |
| 203 | == NULL) { | |
| 204 | #ifdef USE_APPLET | |
| 205 | setUserState(offline); | |
| 206 | #endif /* USE_APPLET */ | |
| 207 | set_state(STATE_OFFLINE); | |
| 208 | ||
| 209 | hide_login_progress("Could not connect to BOS: internal error"); | |
| 210 | return(-1); | |
| 211 | } else if (bosconn->status != 0) { | |
| 212 | #ifdef USE_APPLET | |
| 213 | setUserState(offline); | |
| 214 | #endif /* USE_APPLET */ | |
| 215 | set_state(STATE_OFFLINE); | |
| 216 | ||
| 217 | hide_login_progress("Could not connect to BOS"); | |
| 218 | return(-1); | |
| 219 | } else { | |
| 220 | aim_auth_sendcookie(bosconn, logininfo->cookie); | |
| 221 | inpa = gdk_input_add(bosconn->fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, oscar_callback, NULL); | |
| 222 | set_login_progress(4, "BOS connection established, cookie sent."); | |
| 223 | return(1); | |
| 224 | } | |
| 225 | } | |
| 226 | ||
| 227 | int gaim_auth_failure(struct command_rx_struct *command, ...) | |
| 228 | { | |
| 229 | va_list ap; | |
| 230 | struct login_phase1_struct *logininfo; | |
| 231 | char *errorurl; | |
| 232 | short errorcode; | |
| 233 | ||
| 234 | va_start(ap, command); | |
| 235 | logininfo = va_arg(ap, struct login_phase1_struct *); | |
| 236 | printf("Screen name: %s\n", logininfo->screen_name); | |
| 237 | errorurl = va_arg(ap, char *); | |
| 238 | printf("Error URL: %s\n", errorurl); | |
| 239 | errorcode = va_arg(ap, short); | |
| 240 | printf("Error code: 0x%02x\n", errorcode); | |
| 241 | va_end(ap); | |
| 242 | #ifdef USE_APPLET | |
| 243 | setUserState(offline); | |
| 244 | #endif /* USE_APPLET */ | |
| 245 | set_state(STATE_OFFLINE); | |
| 246 | hide_login_progress("Authentication Failed"); | |
| 247 | ||
| 248 | aim_conn_close(aim_getconn_type(AIM_CONN_TYPE_AUTH)); | |
| 249 | ||
| 250 | return 1; | |
| 251 | } | |
| 252 | ||
| 253 | int gaim_serverready_handle(struct command_rx_struct *command, ...) | |
| 254 | { | |
| 255 | switch (command->conn->type) { | |
| 256 | case AIM_CONN_TYPE_BOS: | |
| 257 | aim_bos_reqrate(command->conn); | |
| 258 | aim_bos_ackrateresp(command->conn); | |
| 259 | aim_bos_setprivacyflags(command->conn, 0x00000003); | |
| 260 | aim_bos_reqservice(command->conn, AIM_CONN_TYPE_ADS); | |
| 261 | aim_bos_setgroupperm(NULL, 0x1f); | |
| 262 | break; | |
| 263 | case AIM_CONN_TYPE_CHATNAV: | |
| 264 | break; | |
| 265 | default: | |
| 266 | printf("Unknown connection type on serverready\n"); | |
| 267 | break; | |
| 268 | } | |
| 269 | return(1); | |
| 270 | ||
| 271 | } | |
| 272 | ||
| 273 | int gaim_redirect_handle(struct command_rx_struct *command, ...) | |
| 274 | { | |
| 275 | va_list ap; | |
| 276 | int serviceid; | |
| 277 | char *ip, *cookie; | |
| 278 | ||
| 279 | va_start(ap, command); | |
| 280 | serviceid = va_arg(ap, int); | |
| 281 | ip = va_arg(ap, char *); | |
| 282 | cookie = va_arg(ap, char *); | |
| 283 | va_end(ap); | |
| 284 | ||
| 285 | switch(serviceid) { | |
| 286 | case 0x0005: { | |
| 287 | char *buf; | |
| 288 | char *buf2; | |
| 289 | char file[1024]; | |
| 290 | FILE *f; | |
| 291 | ||
| 292 | g_snprintf(file, sizeof(file), "%s/.gaimbuddy", getenv("HOME")); | |
| 293 | ||
| 294 | if (!(f = fopen(file,"r"))) { | |
| 295 | } else { | |
| 296 | buf = g_malloc(BUF_LONG); | |
| 297 | fread(buf, BUF_LONG, 1, f); | |
| 298 | ||
| 299 | parse_toc_buddy_list(buf); | |
| 300 | ||
| 301 | build_edit_tree(); | |
| 302 | build_permit_tree(); | |
| 303 | ||
| 304 | ||
| 305 | g_free(buf); | |
| 306 | } | |
| 307 | ||
| 308 | ||
| 309 | ||
| 310 | aim_bos_clientready(command->conn); | |
| 311 | ||
| 312 | set_login_progress(5, "Logged in.\n"); | |
| 313 | #ifdef USE_APPLET | |
|
74
3c0d42030507
[gaim-migrate @ 84]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
10
diff
changeset
|
314 | if (general_options & OPT_GEN_APP_BUDDY_SHOW) { |
| 1 | 315 | show_buddy_list(); |
| 316 | refresh_buddy_window(); | |
| 317 | } else { | |
| 318 | } | |
| 319 | ||
| 320 | set_applet_draw_closed(); | |
| 321 | setUserState(online); | |
| 322 | #else | |
| 323 | gtk_widget_hide(mainwindow); | |
| 324 | show_buddy_list(); | |
| 325 | refresh_buddy_window(); | |
| 326 | #endif | |
| 327 | serv_finish_login(); | |
| 328 | gaim_conn = command->conn; | |
| 329 | ||
| 330 | break; | |
| 331 | } | |
| 332 | case 0x0007: { | |
| 333 | struct aim_conn_t *tstconn; | |
| 334 | ||
| 335 | tstconn = aim_newconn(AIM_CONN_TYPE_AUTH, ip); | |
| 336 | if ((tstconn == NULL) || | |
| 337 | (tstconn->status >= AIM_CONN_STATUS_RESOLVERR)) { | |
| 338 | #ifdef USE_APPLET | |
| 339 | setUserState(offline); | |
| 340 | #endif /* USE_APPLET */ | |
| 341 | set_state(STATE_OFFLINE); | |
| 342 | hide_login_progress("Unable to reconnect to authorizer"); | |
| 343 | } else | |
| 344 | aim_auth_sendcookie(tstconn, cookie); | |
| 345 | break; | |
| 346 | } | |
| 347 | case 0x000d: { | |
| 348 | struct aim_conn_t *tstconn; | |
| 349 | ||
| 350 | tstconn = aim_newconn(AIM_CONN_TYPE_CHATNAV, ip); | |
| 351 | if ((tstconn == NULL) || | |
| 352 | (tstconn->status >= AIM_CONN_STATUS_RESOLVERR)) | |
| 353 | printf("Unable to connect to chatnav server\n"); | |
| 354 | else | |
| 355 | aim_auth_sendcookie( | |
| 356 | aim_getconn_type(AIM_CONN_TYPE_CHATNAV), | |
| 357 | cookie); | |
| 358 | break; | |
| 359 | } | |
| 360 | case 0x000e: | |
| 361 | printf("CHAT is not yet supported :(\n"); | |
| 362 | break; | |
| 363 | default: | |
| 364 | printf("Unknown redirect %#04X\n", serviceid); | |
| 365 | break; | |
| 366 | } | |
| 367 | return(1); | |
| 368 | ||
| 369 | } | |
| 370 | ||
| 371 | ||
| 372 | ||
| 373 | int gaim_im_handle(struct command_rx_struct *command, ...) | |
| 374 | { | |
| 375 | time_t t = 0; | |
| 376 | char *screenname, *msg; | |
| 377 | int warninglevel, class, idletime, isautoreply; | |
| 378 | ulong membersince, onsince; | |
| 379 | va_list ap; | |
| 380 | ||
| 381 | va_start(ap, command); | |
| 382 | screenname = va_arg(ap, char *); | |
| 383 | msg = va_arg(ap, char *); | |
| 384 | warninglevel = va_arg(ap, int); | |
| 385 | class = va_arg(ap, int); | |
| 386 | membersince = va_arg(ap, ulong); | |
| 387 | onsince = va_arg(ap, ulong); | |
| 388 | idletime = va_arg(ap, int); | |
| 389 | isautoreply = va_arg(ap, int); | |
| 390 | va_end(ap); | |
| 391 | ||
| 392 | printf("'%s'\n", msg); | |
| 393 | ||
| 394 | serv_got_im(screenname, msg, isautoreply); | |
| 395 | ||
| 396 | return(1); | |
| 397 | ||
| 398 | ||
| 399 | } | |
| 400 | ||
| 401 | #endif |