Mercurial > pidgin
comparison src/toc.c @ 960:fa681641643d
[gaim-migrate @ 970]
*** MULTIPLE-CONNECTIONS ***
committer: Tailor Script <tailor@pidgin.im>
| author | Eric Warmenhoven <eric@warmenhoven.org> |
|---|---|
| date | Tue, 10 Oct 2000 00:02:02 +0000 |
| parents | 9fca1293f871 |
| children | 2cd7b73e2c9a |
comparison
equal
deleted
inserted
replaced
| 959:034d5d1d53eb | 960:fa681641643d |
|---|---|
| 33 #include <string.h> | 33 #include <string.h> |
| 34 #include <stdlib.h> | 34 #include <stdlib.h> |
| 35 #include <stdio.h> | 35 #include <stdio.h> |
| 36 #include <time.h> | 36 #include <time.h> |
| 37 #include <sys/socket.h> | 37 #include <sys/socket.h> |
| 38 #include "multi.h" | |
| 38 #include "gaim.h" | 39 #include "gaim.h" |
| 39 #include "gnome_applet_mgr.h" | 40 #include "gnome_applet_mgr.h" |
| 40 | 41 |
| 41 | 42 #define REVISION "gaim:$Revision: 970 $" |
| 42 | 43 |
| 43 /* descriptor for talking to TOC */ | 44 |
| 44 static int toc_fd; | |
| 45 static int seqno; | |
| 46 static unsigned int peer_ver=0; | 45 static unsigned int peer_ver=0; |
| 47 static int state; | |
| 48 static int inpa=-1; | |
| 49 #ifdef _WIN32 | 46 #ifdef _WIN32 |
| 50 static int win32_r; | 47 static int win32_r; |
| 51 #endif | 48 #endif |
| 52 | 49 |
| 53 int toc_signon(char *username, char *password); | 50 static int toc_signon(struct gaim_connection *); |
| 54 | 51 |
| 55 | 52 |
| 56 | 53 |
| 57 int toc_login(char *username, char *password) | 54 /* ok. this function used to take username/password, and return 0 on success. |
| 55 * now, it takes username/password, and returns NULL on error or a new gaim_connection | |
| 56 * on success. FIXME: should this modify the UI? or just sign in? */ | |
| 57 struct gaim_connection *toc_login(char *username, char *password) | |
| 58 { | 58 { |
| 59 char *config; | 59 char *config; |
| 60 struct in_addr *sin; | 60 struct in_addr *sin; |
| 61 struct aim_user *u; | 61 struct aim_user *u; |
| 62 struct gaim_connection *gc; | |
| 62 char buf[80]; | 63 char buf[80]; |
| 63 char buf2[2048]; | 64 char buf2[2048]; |
| 64 | 65 |
| 65 g_snprintf(buf, sizeof(buf), "Looking up %s", aim_host); | 66 g_snprintf(buf, sizeof(buf), "Looking up %s", aim_host); |
| 66 set_login_progress(1, buf); | 67 set_login_progress(1, buf); |
| 69 if (!sin) { | 70 if (!sin) { |
| 70 | 71 |
| 71 #ifdef USE_APPLET | 72 #ifdef USE_APPLET |
| 72 set_user_state(offline); | 73 set_user_state(offline); |
| 73 #endif /* USE_APPLET */ | 74 #endif /* USE_APPLET */ |
| 74 set_state(STATE_OFFLINE); | |
| 75 g_snprintf(buf, sizeof(buf), "Unable to lookup %s", aim_host); | 75 g_snprintf(buf, sizeof(buf), "Unable to lookup %s", aim_host); |
| 76 hide_login_progress(buf); | 76 hide_login_progress(buf); |
| 77 return -1; | 77 return NULL; |
| 78 } | 78 } |
| 79 | 79 |
| 80 g_snprintf(toc_addy, sizeof(toc_addy), "%s", inet_ntoa(*sin)); | 80 g_snprintf(toc_addy, sizeof(toc_addy), "%s", inet_ntoa(*sin)); |
| 81 g_snprintf(buf, sizeof(buf), "Connecting to %s", inet_ntoa(*sin)); | 81 g_snprintf(buf, sizeof(buf), "Connecting to %s", inet_ntoa(*sin)); |
| 82 | 82 |
| 83 set_login_progress(2, buf); | 83 set_login_progress(2, buf); |
| 84 | 84 |
| 85 | 85 |
| 86 | 86 gc = new_gaim_conn(PROTO_TOC, username, password); |
| 87 toc_fd = connect_address(sin->s_addr, aim_port); | 87 |
| 88 | 88 gc->toc_fd = connect_address(sin->s_addr, aim_port); |
| 89 if (toc_fd < 0) { | 89 |
| 90 if (gc->toc_fd < 0) { | |
| 90 #ifdef USE_APPLET | 91 #ifdef USE_APPLET |
| 91 set_user_state(offline); | 92 set_user_state(offline); |
| 92 #endif /* USE_APPLET */ | 93 #endif /* USE_APPLET */ |
| 93 set_state(STATE_OFFLINE); | |
| 94 g_snprintf(buf, sizeof(buf), "Connect to %s failed", | 94 g_snprintf(buf, sizeof(buf), "Connect to %s failed", |
| 95 inet_ntoa(*sin)); | 95 inet_ntoa(*sin)); |
| 96 hide_login_progress(buf); | 96 hide_login_progress(buf); |
| 97 return -1; | 97 destroy_gaim_conn(gc); |
| 98 return NULL; | |
| 98 } | 99 } |
| 99 | 100 |
| 100 g_free(sin); | 101 g_free(sin); |
| 101 | 102 |
| 102 g_snprintf(buf, sizeof(buf), "Signon: %s",username); | 103 g_snprintf(buf, sizeof(buf), "Signon: %s",username); |
| 103 | 104 |
| 104 set_login_progress(3, buf); | 105 set_login_progress(3, buf); |
| 105 | 106 |
| 106 if (toc_signon(username, password) < 0) { | 107 if (toc_signon(gc) < 0) { |
| 107 #ifdef USE_APPLET | 108 #ifdef USE_APPLET |
| 108 set_user_state(offline); | 109 set_user_state(offline); |
| 109 #endif /* USE_APPLET */ | 110 #endif /* USE_APPLET */ |
| 110 set_state(STATE_OFFLINE); | |
| 111 hide_login_progress("Disconnected."); | 111 hide_login_progress("Disconnected."); |
| 112 return -1; | 112 destroy_gaim_conn(gc); |
| 113 return NULL; | |
| 113 } | 114 } |
| 114 | 115 |
| 115 g_snprintf(buf, sizeof(buf), "Waiting for reply..."); | 116 g_snprintf(buf, sizeof(buf), "Waiting for reply..."); |
| 116 set_login_progress(4, buf); | 117 set_login_progress(4, buf); |
| 117 if (toc_wait_signon() < 0) { | 118 if (toc_wait_signon(gc) < 0) { |
| 118 #ifdef USE_APPLET | 119 #ifdef USE_APPLET |
| 119 set_user_state(offline); | 120 set_user_state(offline); |
| 120 #endif /* USE_APPLET */ | 121 #endif /* USE_APPLET */ |
| 121 set_state(STATE_OFFLINE); | |
| 122 hide_login_progress("Authentication Failed"); | 122 hide_login_progress("Authentication Failed"); |
| 123 return -1; | 123 destroy_gaim_conn(gc); |
| 124 return NULL; | |
| 124 } | 125 } |
| 125 | 126 |
| 126 u = find_user(username); | 127 u = find_user(username); |
| 127 | 128 sprintf(gc->user_info, "%s", u->user_info); |
| 128 if (!u) { | 129 gc->options = u->options; |
| 129 u = g_new0(struct aim_user, 1); | |
| 130 g_snprintf(u->user_info, sizeof(u->user_info), DEFAULT_INFO); | |
| 131 aim_users = g_list_append(aim_users, u); | |
| 132 } | |
| 133 | |
| 134 current_user = u; | |
| 135 | |
| 136 g_snprintf(current_user->username, sizeof(current_user->username), "%s", username); | |
| 137 g_snprintf(current_user->password, sizeof(current_user->password), "%s", password); | |
| 138 | |
| 139 save_prefs(); | 130 save_prefs(); |
| 140 | 131 |
| 141 g_snprintf(buf, sizeof(buf), "Retrieving config..."); | 132 g_snprintf(buf, sizeof(buf), "Retrieving config..."); |
| 142 set_login_progress(5, buf); | 133 set_login_progress(5, buf); |
| 143 config = toc_wait_config(); | 134 config = toc_wait_config(gc); |
| 144 state = STATE_ONLINE; | 135 gc->state = STATE_ONLINE; |
| 145 | 136 |
| 146 gtk_widget_hide(mainwindow); | 137 gtk_widget_hide(mainwindow); |
| 147 show_buddy_list(); | 138 show_buddy_list(); |
| 148 #ifdef USE_APPLET | 139 #ifdef USE_APPLET |
| 149 if (general_options & OPT_GEN_APP_BUDDY_SHOW) { | 140 if (general_options & OPT_GEN_APP_BUDDY_SHOW) { |
| 158 set_user_state(online); | 149 set_user_state(online); |
| 159 #else | 150 #else |
| 160 refresh_buddy_window(); | 151 refresh_buddy_window(); |
| 161 #endif | 152 #endif |
| 162 if (config != NULL) | 153 if (config != NULL) |
| 163 parse_toc_buddy_list(config, 0); | 154 parse_toc_buddy_list(gc, config, 0); |
| 164 else | 155 else |
| 165 do_import(0, 0); | 156 do_import(0, gc); |
| 166 | 157 |
| 167 setup_buddy_chats(); | 158 setup_buddy_chats(); |
| 168 | 159 |
| 169 g_snprintf(buf2, sizeof(buf2), "toc_init_done"); | 160 g_snprintf(buf2, sizeof(buf2), "toc_init_done"); |
| 170 sflap_send(buf2, -1, TYPE_DATA); | 161 sflap_send(gc, buf2, -1, TYPE_DATA); |
| 171 | 162 |
| 172 g_snprintf(buf2, sizeof(buf2), "toc_set_caps %s %s %s %s %s", | 163 g_snprintf(buf2, sizeof(buf2), "toc_set_caps %s %s %s %s %s", |
| 173 FILE_SEND_UID, FILE_GET_UID, B_ICON_UID, IMAGE_UID, | 164 FILE_SEND_UID, FILE_GET_UID, B_ICON_UID, IMAGE_UID, |
| 174 VOICE_UID); | 165 VOICE_UID); |
| 175 sflap_send(buf2, -1, TYPE_DATA); | 166 sflap_send(gc, buf2, -1, TYPE_DATA); |
| 176 | 167 |
| 177 if (keepalv < 0) | 168 if (gc->keepalive < 0) |
| 178 update_keepalive(general_options & OPT_GEN_KEEPALIVE); | 169 update_keepalive(gc, gc->options & OPT_USR_KEEPALV); |
| 179 | 170 |
| 180 serv_finish_login(); | 171 serv_finish_login(gc); |
| 172 gaim_setup(gc); | |
| 181 return 0; | 173 return 0; |
| 182 } | 174 } |
| 183 | 175 |
| 184 void toc_close() | 176 void toc_close(struct gaim_connection *gc) |
| 185 { | 177 { |
| 178 if (gc->protocol != PROTO_TOC) return; /* how did this happen? */ | |
| 186 #ifdef USE_APPLET | 179 #ifdef USE_APPLET |
| 187 set_user_state(offline); | 180 set_user_state(offline); |
| 188 #endif /* USE_APPLET */ | 181 #endif /* USE_APPLET */ |
| 189 seqno = 0; | 182 if (gc->inpa > 0) |
| 190 state = STATE_OFFLINE; | 183 gdk_input_remove(gc->inpa); |
| 191 if (inpa > 0) | 184 gc->inpa = -1; |
| 192 gdk_input_remove(inpa); | 185 close(gc->toc_fd); |
| 193 close(toc_fd); | |
| 194 toc_fd=-1; | |
| 195 inpa=-1; | |
| 196 } | 186 } |
| 197 | 187 |
| 198 unsigned char *roast_password(char *pass) | 188 unsigned char *roast_password(char *pass) |
| 199 { | 189 { |
| 200 /* Trivial "encryption" */ | 190 /* Trivial "encryption" */ |
| 232 printf("%c ", buf[x]); | 222 printf("%c ", buf[x]); |
| 233 printf("]\n"); | 223 printf("]\n"); |
| 234 #endif | 224 #endif |
| 235 } | 225 } |
| 236 | 226 |
| 237 int sflap_send(char *buf, int olen, int type) | 227 int sflap_send(struct gaim_connection *gc, char *buf, int olen, int type) |
| 238 { | 228 { |
| 239 int len; | 229 int len; |
| 240 int slen=0; | 230 int slen=0; |
| 241 struct sflap_hdr hdr; | 231 struct sflap_hdr hdr; |
| 242 char obuf[MSG_LEN]; | 232 char obuf[MSG_LEN]; |
| 259 len = escape_message(buf); | 249 len = escape_message(buf); |
| 260 else | 250 else |
| 261 len = olen; | 251 len = olen; |
| 262 hdr.ast = '*'; | 252 hdr.ast = '*'; |
| 263 hdr.type = type; | 253 hdr.type = type; |
| 264 hdr.seqno = htons(seqno++ & 0xffff); | 254 hdr.seqno = htons(gc->seqno++ & 0xffff); |
| 265 hdr.len = htons(len + (type == TYPE_SIGNON ? 0 : 1)); | 255 hdr.len = htons(len + (type == TYPE_SIGNON ? 0 : 1)); |
| 266 | 256 |
| 267 sprintf(debug_buff,"Escaped message is '%s'\n",buf); | 257 sprintf(debug_buff,"Escaped message is '%s'\n",buf); |
| 268 debug_print(debug_buff); | 258 debug_print(debug_buff); |
| 269 | 259 |
| 275 obuf[slen]='\0'; | 265 obuf[slen]='\0'; |
| 276 slen += 1; | 266 slen += 1; |
| 277 } | 267 } |
| 278 print_buffer(obuf, slen); | 268 print_buffer(obuf, slen); |
| 279 | 269 |
| 280 return write(toc_fd, obuf, slen); | 270 return write(gc->toc_fd, obuf, slen); |
| 281 } | 271 } |
| 282 | 272 |
| 283 | 273 |
| 284 int wait_reply(char *buffer, size_t buflen) | 274 static int wait_reply(struct gaim_connection *gc, char *buffer, size_t buflen) |
| 285 { | 275 { |
| 286 size_t res=-1; | 276 size_t res=-1; |
| 287 int read_rv = -1; | 277 int read_rv = -1; |
| 288 struct sflap_hdr *hdr=(struct sflap_hdr *)buffer; | 278 struct sflap_hdr *hdr=(struct sflap_hdr *)buffer; |
| 289 char *c; | 279 char *c; |
| 290 | 280 |
| 291 if(buflen < sizeof(struct sflap_hdr)) { | 281 if(buflen < sizeof(struct sflap_hdr)) { |
| 292 do_error_dialog("Buffer too small", "Gaim - Error (internal)"); | 282 do_error_dialog(_("Unable to read from server: Buffer too small"), |
| 283 _("Gaim - Error (internal)")); | |
| 293 return -1; | 284 return -1; |
| 294 } | 285 } |
| 295 | 286 |
| 296 while((read_rv = read(toc_fd, buffer, 1))) { | 287 while((read_rv = read(gc->toc_fd, buffer, 1))) { |
| 297 if (read_rv < 0 || read_rv > 1) | 288 if (read_rv < 0 || read_rv > 1) |
| 298 return -1; | 289 return -1; |
| 299 if (buffer[0] == '*') | 290 if (buffer[0] == '*') |
| 300 break; | 291 break; |
| 301 | 292 |
| 302 } | 293 } |
| 303 | 294 |
| 304 read_rv = read(toc_fd, buffer+1, sizeof(struct sflap_hdr) - 1); | 295 read_rv = read(gc->toc_fd, buffer+1, sizeof(struct sflap_hdr) - 1); |
| 305 | 296 |
| 306 if (read_rv < 0) | 297 if (read_rv < 0) |
| 307 return read_rv; | 298 return read_rv; |
| 308 | 299 |
| 309 res = read_rv + 1; | 300 res = read_rv + 1; |
| 312 sprintf(debug_buff, "Rcv: %s %s\n",print_header(buffer), ""); | 303 sprintf(debug_buff, "Rcv: %s %s\n",print_header(buffer), ""); |
| 313 debug_print(debug_buff); | 304 debug_print(debug_buff); |
| 314 | 305 |
| 315 | 306 |
| 316 if(buflen < sizeof(struct sflap_hdr) + ntohs(hdr->len) + 1) { | 307 if(buflen < sizeof(struct sflap_hdr) + ntohs(hdr->len) + 1) { |
| 317 do_error_dialog("Buffer too small", "Gaim - Error (internal)"); | 308 do_error_dialog(_("Unable to read from server: Too much information"), |
| 309 _("Gaim - Error (internal)")); | |
| 318 return -1; | 310 return -1; |
| 319 } | 311 } |
| 320 | 312 |
| 321 while (res < (sizeof(struct sflap_hdr) + ntohs(hdr->len))) { | 313 while (res < (sizeof(struct sflap_hdr) + ntohs(hdr->len))) { |
| 322 read_rv = read(toc_fd, buffer + res, (ntohs(hdr->len) + sizeof(struct sflap_hdr)) - res); | 314 read_rv = read(gc->toc_fd, buffer + res, (ntohs(hdr->len) + sizeof(struct sflap_hdr)) - res); |
| 323 if(read_rv < 0) return read_rv; | 315 if(read_rv < 0) return read_rv; |
| 324 res += read_rv; | 316 res += read_rv; |
| 317 /* my feeling is this will kill us. if there's data pending then we'll come right back | |
| 318 * to where we are now. possible workarounds are to remove the input watcher until | |
| 319 * we're done with this part | |
| 325 while(gtk_events_pending()) | 320 while(gtk_events_pending()) |
| 326 gtk_main_iteration(); | 321 gtk_main_iteration(); |
| 322 */ | |
| 327 } | 323 } |
| 328 | 324 |
| 329 if (res >= sizeof(struct sflap_hdr)) | 325 if (res >= sizeof(struct sflap_hdr)) |
| 330 buffer[res]='\0'; | 326 buffer[res]='\0'; |
| 331 else | 327 else |
| 333 | 329 |
| 334 switch(hdr->type) { | 330 switch(hdr->type) { |
| 335 case TYPE_SIGNON: | 331 case TYPE_SIGNON: |
| 336 memcpy(&peer_ver, buffer + sizeof(struct sflap_hdr), 4); | 332 memcpy(&peer_ver, buffer + sizeof(struct sflap_hdr), 4); |
| 337 peer_ver = ntohl(peer_ver); | 333 peer_ver = ntohl(peer_ver); |
| 338 seqno = ntohs(hdr->seqno); | 334 gc->seqno = ntohs(hdr->seqno); |
| 339 state = STATE_SIGNON_REQUEST; | 335 gc->state = STATE_SIGNON_REQUEST; |
| 340 break; | 336 break; |
| 341 case TYPE_DATA: | 337 case TYPE_DATA: |
| 342 if (!strncasecmp(buffer + sizeof(struct sflap_hdr), "SIGN_ON:", strlen("SIGN_ON:"))) | 338 if (!strncasecmp(buffer + sizeof(struct sflap_hdr), "SIGN_ON:", strlen("SIGN_ON:"))) |
| 343 state = STATE_SIGNON_ACK; | 339 gc->state = STATE_SIGNON_ACK; |
| 344 else if (!strncasecmp(buffer + sizeof(struct sflap_hdr), "CONFIG:", strlen("CONFIG:"))) { | 340 else if (!strncasecmp(buffer + sizeof(struct sflap_hdr), "CONFIG:", strlen("CONFIG:"))) { |
| 345 state = STATE_CONFIG; | 341 gc->state = STATE_CONFIG; |
| 346 } else if (!strncasecmp(buffer + sizeof(struct sflap_hdr), "ERROR:", strlen("ERROR:"))) { | 342 } else if (!strncasecmp(buffer + sizeof(struct sflap_hdr), "ERROR:", strlen("ERROR:"))) { |
| 347 c = strtok(buffer + sizeof(struct sflap_hdr) + strlen("ERROR:"), ":"); | 343 c = strtok(buffer + sizeof(struct sflap_hdr) + strlen("ERROR:"), ":"); |
| 348 show_error_dialog(c); | 344 show_error_dialog(c); |
| 349 } | 345 } |
| 350 | 346 |
| 366 GdkInputCondition condition ) | 362 GdkInputCondition condition ) |
| 367 { | 363 { |
| 368 char *buf; | 364 char *buf; |
| 369 char *c; | 365 char *c; |
| 370 char *l; | 366 char *l; |
| 367 struct gaim_connection *gc = (struct gaim_connection *)data; | |
| 371 | 368 |
| 372 buf = g_malloc(2 * BUF_LONG); | 369 buf = g_malloc(2 * BUF_LONG); |
| 373 if (wait_reply(buf, 2 * BUF_LONG) < 0) { | 370 if (wait_reply(gc, buf, 2 * BUF_LONG) < 0) { |
| 374 signoff(); | 371 signoff(gc); /* this will free gc for us */ |
| 375 hide_login_progress("Connection Closed"); | 372 hide_login_progress("Connection Closed"); |
| 376 g_free(buf); | 373 g_free(buf); |
| 377 return; | 374 return; |
| 378 } | 375 } |
| 379 | 376 |
| 438 serv_got_update(c, logged, evil, signon, time_idle, type, 0); | 435 serv_got_update(c, logged, evil, signon, time_idle, type, 0); |
| 439 | 436 |
| 440 } else if (!strcasecmp(c, "CONFIG")) { | 437 } else if (!strcasecmp(c, "CONFIG")) { |
| 441 /* do we want to load the buddy list again here? */ | 438 /* do we want to load the buddy list again here? */ |
| 442 c = strtok(NULL,":"); | 439 c = strtok(NULL,":"); |
| 443 parse_toc_buddy_list(c, 0); | 440 parse_toc_buddy_list(gc, c, 0); |
| 444 } else if (!strcasecmp(c, "ERROR")) { | 441 } else if (!strcasecmp(c, "ERROR")) { |
| 445 /* This should be handled by wait_reply | 442 /* This should be handled by wait_reply |
| 446 c = strtok(NULL,":"); | 443 c = strtok(NULL,":"); |
| 447 show_error_dialog(c); | 444 show_error_dialog(c); |
| 448 */ | 445 */ |
| 449 } else if (!strcasecmp(c, "NICK")) { | 446 } else if (!strcasecmp(c, "NICK")) { |
| 450 c = strtok(NULL,":"); | 447 c = strtok(NULL,":"); |
| 451 g_snprintf(current_user->username, sizeof(current_user->username), "%s", c); | 448 g_snprintf(gc->username, sizeof(gc->username), "%s", c); |
| 452 } else if (!strcasecmp(c, "IM_IN")) { | 449 } else if (!strcasecmp(c, "IM_IN")) { |
| 453 char *away, *message; | 450 char *away, *message; |
| 454 int a = 0; | 451 int a = 0; |
| 455 | 452 |
| 456 c = strtok(NULL,":"); | 453 c = strtok(NULL,":"); |
| 463 | 460 |
| 464 message++; | 461 message++; |
| 465 | 462 |
| 466 if (!strncasecmp(away, "T", 1)) | 463 if (!strncasecmp(away, "T", 1)) |
| 467 a = 1; | 464 a = 1; |
| 468 serv_got_im(c, message, a); | 465 serv_got_im(gc, c, message, a); |
| 469 | 466 |
| 470 } else if (!strcasecmp(c, "GOTO_URL")) { | 467 } else if (!strcasecmp(c, "GOTO_URL")) { |
| 471 char *name; | 468 char *name; |
| 472 char *url; | 469 char *url; |
| 473 | 470 |
| 693 debug_print(debug_buff); | 690 debug_print(debug_buff); |
| 694 tmp = g_malloc(BUF_LEN); | 691 tmp = g_malloc(BUF_LEN); |
| 695 name = frombase64(cookie); | 692 name = frombase64(cookie); |
| 696 snprintf(tmp, BUF_LEN, "toc_rvous_cancel %s %s %s", | 693 snprintf(tmp, BUF_LEN, "toc_rvous_cancel %s %s %s", |
| 697 user, name, uuid); | 694 user, name, uuid); |
| 698 sflap_send(tmp, strlen(tmp), TYPE_DATA); | 695 sflap_send(gc, tmp, strlen(tmp), TYPE_DATA); |
| 699 free(name); | 696 free(name); |
| 700 free(tmp); | 697 free(tmp); |
| 701 } | 698 } |
| 702 } else { | 699 } else { |
| 703 sprintf(debug_buff,"don't know what to do with %s\n", c); | 700 sprintf(debug_buff,"don't know what to do with %s\n", c); |
| 705 } | 702 } |
| 706 g_free(buf); | 703 g_free(buf); |
| 707 } | 704 } |
| 708 | 705 |
| 709 | 706 |
| 710 int toc_signon(char *username, char *password) | 707 int toc_signon(struct gaim_connection *gc) |
| 711 { | 708 { |
| 712 char buf[BUF_LONG]; | 709 char buf[BUF_LONG]; |
| 713 int res; | 710 int res; |
| 714 struct signon so; | 711 struct signon so; |
| 715 | 712 |
| 716 sprintf(debug_buff,"State = %d\n", state); | 713 sprintf(debug_buff,"State = %d\n", gc->state); |
| 717 debug_print(debug_buff); | 714 debug_print(debug_buff); |
| 718 | 715 |
| 719 if ((res = write(toc_fd, FLAPON, strlen(FLAPON))) < 0) | 716 if ((res = write(gc->toc_fd, FLAPON, strlen(FLAPON))) < 0) |
| 720 return res; | 717 return res; |
| 721 /* Wait for signon packet */ | 718 /* Wait for signon packet */ |
| 722 | 719 |
| 723 state = STATE_FLAPON; | 720 gc->state = STATE_FLAPON; |
| 724 | 721 |
| 725 if ((res = wait_reply(buf, sizeof(buf)) < 0)) | 722 if ((res = wait_reply(gc, buf, sizeof(buf)) < 0)) |
| 726 return res; | 723 return res; |
| 727 | 724 |
| 728 if (state != STATE_SIGNON_REQUEST) { | 725 if (gc->state != STATE_SIGNON_REQUEST) { |
| 729 sprintf(debug_buff, "State should be %d, but is %d instead\n", STATE_SIGNON_REQUEST, state); | 726 sprintf(debug_buff, "State should be %d, but is %d instead\n", STATE_SIGNON_REQUEST, gc->state); |
| 730 debug_print(debug_buff); | 727 debug_print(debug_buff); |
| 731 return -1; | 728 return -1; |
| 732 } | 729 } |
| 733 | 730 |
| 734 /* Compose a response */ | 731 /* Compose a response */ |
| 735 | 732 |
| 736 g_snprintf(so.username, sizeof(so.username), "%s", username); | 733 g_snprintf(so.username, sizeof(so.username), "%s", gc->username); |
| 737 so.ver = ntohl(1); | 734 so.ver = ntohl(1); |
| 738 so.tag = ntohs(1); | 735 so.tag = ntohs(1); |
| 739 so.namelen = htons(strlen(so.username)); | 736 so.namelen = htons(strlen(so.username)); |
| 740 | 737 |
| 741 sflap_send((char *)&so, ntohs(so.namelen) + 8, TYPE_SIGNON); | 738 sflap_send(gc, (char *)&so, ntohs(so.namelen) + 8, TYPE_SIGNON); |
| 742 | 739 |
| 743 g_snprintf(buf, sizeof(buf), | 740 g_snprintf(buf, sizeof(buf), |
| 744 "toc_signon %s %d %s %s %s \"%s\"", | 741 "toc_signon %s %d %s %s %s \"%s\"", |
| 745 login_host, login_port, normalize(username), roast_password(password), LANGUAGE, REVISION); | 742 login_host, login_port, normalize(gc->username), roast_password(gc->password), LANGUAGE, REVISION); |
| 746 | 743 |
| 747 sprintf(debug_buff,"Send: %s\n", buf); | 744 sprintf(debug_buff,"Send: %s\n", buf); |
| 748 debug_print(debug_buff); | 745 debug_print(debug_buff); |
| 749 | 746 |
| 750 return sflap_send(buf, -1, TYPE_DATA); | 747 return sflap_send(gc, buf, -1, TYPE_DATA); |
| 751 } | 748 } |
| 752 | 749 |
| 753 int toc_wait_signon() | 750 int toc_wait_signon(struct gaim_connection *gc) |
| 754 { | 751 { |
| 755 /* Wait for the SIGNON to be approved */ | 752 /* Wait for the SIGNON to be approved */ |
| 756 char buf[BUF_LONG]; | 753 char buf[BUF_LONG]; |
| 757 int res; | 754 int res; |
| 758 res = wait_reply(buf, sizeof(buf)); | 755 res = wait_reply(gc, buf, sizeof(buf)); |
| 759 if (res < 0) | 756 if (res < 0) |
| 760 return res; | 757 return res; |
| 761 if (state != STATE_SIGNON_ACK) { | 758 if (gc->state != STATE_SIGNON_ACK) { |
| 762 sprintf(debug_buff, "State should be %d, but is %d instead\n",STATE_SIGNON_ACK, state); | 759 sprintf(debug_buff, "State should be %d, but is %d instead\n",STATE_SIGNON_ACK, gc->state); |
| 763 debug_print(debug_buff); | 760 debug_print(debug_buff); |
| 764 return -1; | 761 return -1; |
| 765 } | 762 } |
| 766 return 0; | 763 return 0; |
| 767 } | 764 } |
| 790 return TRUE; | 787 return TRUE; |
| 791 } | 788 } |
| 792 #endif | 789 #endif |
| 793 | 790 |
| 794 | 791 |
| 795 char *toc_wait_config() | 792 char *toc_wait_config(struct gaim_connection *gc) |
| 796 { | 793 { |
| 797 /* Waits for configuration packet, returning the contents of the packet */ | 794 /* Waits for configuration packet, returning the contents of the packet */ |
| 798 static char buf[BUF_LONG]; | 795 static char buf[BUF_LONG]; |
| 799 int res; | 796 int res; |
| 800 res = wait_reply(buf, sizeof(buf)); | 797 res = wait_reply(gc, buf, sizeof(buf)); |
| 801 if (res < 0) | 798 if (res < 0) |
| 802 return NULL; | 799 return NULL; |
| 803 /* Apparently, the toc_config is optional. *VERY* Optional | 800 /* Apparently, the toc_config is optional. *VERY* Optional |
| 804 */ | 801 */ |
| 805 if (state != STATE_CONFIG) { | 802 if (gc->state != STATE_CONFIG) { |
| 806 res = 0; | 803 res = 0; |
| 807 } else { | 804 } else { |
| 808 res = 1; | 805 res = 1; |
| 809 } | 806 } |
| 810 /* At this point, it's time to setup automatic handling of incoming packets */ | 807 /* At this point, it's time to setup automatic handling of incoming packets */ |
| 811 state = STATE_ONLINE; | 808 gc->state = STATE_ONLINE; |
| 812 #ifdef _WIN32 | 809 #ifdef _WIN32 |
| 813 win32_r = gtk_timeout_add(1000, (GtkFunction)win32_read, NULL); | 810 win32_r = gtk_timeout_add(1000, (GtkFunction)win32_read, NULL); |
| 814 #else | 811 #else |
| 815 inpa = gdk_input_add(toc_fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, toc_callback, NULL); | 812 gc->inpa = gdk_input_add(gc->toc_fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, toc_callback, gc); |
| 816 #endif | 813 #endif |
| 817 if (res) | 814 if (res) |
| 818 return buf; | 815 return buf; |
| 819 else | 816 else |
| 820 return NULL; | 817 return NULL; |
| 857 pos += g_snprintf(&s[pos], len - pos, "d %s\n", (char *)dlist->data); | 854 pos += g_snprintf(&s[pos], len - pos, "d %s\n", (char *)dlist->data); |
| 858 dlist=dlist->next; | 855 dlist=dlist->next; |
| 859 } | 856 } |
| 860 } | 857 } |
| 861 | 858 |
| 862 void parse_toc_buddy_list(char *config, int from_do_import) | 859 void parse_toc_buddy_list(struct gaim_connection *gc, char *config, int from_do_import) |
| 863 { | 860 { |
| 864 char *c; | 861 char *c; |
| 865 char current[256]; | 862 char current[256]; |
| 866 char *name; | 863 char *name; |
| 867 GList *bud; | 864 GList *bud; |
| 868 int how_many = 0; | 865 int how_many = 0; |
| 869 | 866 |
| 870 bud = NULL; | 867 bud = NULL; |
| 871 | 868 |
| 872 /* skip "CONFIG:" (if it exists)*/ | |
| 873 | |
| 874 if (config != NULL) { | 869 if (config != NULL) { |
| 875 | 870 |
| 871 /* skip "CONFIG:" (if it exists)*/ | |
| 876 c = strncmp(config + sizeof(struct sflap_hdr),"CONFIG:",strlen("CONFIG:"))? | 872 c = strncmp(config + sizeof(struct sflap_hdr),"CONFIG:",strlen("CONFIG:"))? |
| 877 strtok(config, "\n"): | 873 strtok(config, "\n"): |
| 878 strtok(config + sizeof(struct sflap_hdr)+strlen("CONFIG:"), "\n"); | 874 strtok(config + sizeof(struct sflap_hdr)+strlen("CONFIG:"), "\n"); |
| 879 do { | 875 do { |
| 880 if (c == NULL) | 876 if (c == NULL) |
| 954 | 950 |
| 955 /* perhaps the server dropped the buddy list, try importing from | 951 /* perhaps the server dropped the buddy list, try importing from |
| 956 cache */ | 952 cache */ |
| 957 | 953 |
| 958 if ( how_many == 0 && !from_do_import ) { | 954 if ( how_many == 0 && !from_do_import ) { |
| 959 do_import( (GtkWidget *) NULL, 0 ); | 955 do_import( (GtkWidget *) NULL, gc ); |
| 960 } else if ( bud_list_cache_exists() == FALSE ) { | 956 } else if ( gc && (bud_list_cache_exists(gc) == FALSE) ) { |
| 961 do_export( (GtkWidget *) NULL, 0 ); | 957 do_export( (GtkWidget *) NULL, 0 ); |
| 962 } | 958 } |
| 963 } | 959 } |
