plugins/gaim-remote/remote.c

changeset 10003
8340e9f5f191
parent 9993
ae32679a8892
child 10005
1d711ab1de4e
equal deleted inserted replaced
10002:1f8c7c1f95f9 10003:8340e9f5f191
68 GString *str; 68 GString *str;
69 GList *conn; 69 GList *conn;
70 GaimConnection *gc = NULL; 70 GaimConnection *gc = NULL;
71 GaimAccount *account; 71 GaimAccount *account;
72 72
73 gaim_debug(GAIM_DEBUG_INFO, "gaim_remote_handle_uri", "Handling URI: %s\n", uri); 73 gaim_debug_info("gaim_remote_handle_uri", "Handling URI: %s\n", uri);
74 74
75 /* Well, we'd better check to make sure we have at least one 75 /* Well, we'd better check to make sure we have at least one
76 AIM account connected. */ 76 AIM account connected. */
77 for (conn = gaim_connections_get_all(); conn != NULL; conn = conn->next) { 77 for (conn = gaim_connections_get_all(); conn != NULL; conn = conn->next) {
78 gc = conn->data; 78 gc = conn->data;
156 } 156 }
157 group = g_strdup(str->str); 157 group = g_strdup(str->str);
158 g_string_free(str, TRUE); 158 g_string_free(str, TRUE);
159 } 159 }
160 160
161 gaim_debug(GAIM_DEBUG_MISC, "gaim_remote_handle_uri", "who: %s\n", who); 161 gaim_debug_misc("gaim_remote_handle_uri", "who: %s\n", who);
162 gaim_blist_request_add_buddy(gc->account, who, group, NULL); 162 gaim_blist_request_add_buddy(gc->account, who, group, NULL);
163 g_free(who); 163 g_free(who);
164 if (group) 164 if (group)
165 g_free(group); 165 g_free(group);
166 } else if (!g_ascii_strncasecmp(uri, "aim:gochat?", strlen("aim:gochat?"))) { 166 } else if (!g_ascii_strncasecmp(uri, "aim:gochat?", strlen("aim:gochat?"))) {
328 gaim_remote_session_send_packet(g_io_channel_unix_get_fd(ui->channel), 328 gaim_remote_session_send_packet(g_io_channel_unix_get_fd(ui->channel),
329 p); 329 p);
330 gaim_remote_packet_free(p); 330 gaim_remote_packet_free(p);
331 break; 331 break;
332 default: 332 default:
333 gaim_debug(GAIM_DEBUG_WARNING, "cui", 333 gaim_debug_warning("cui", "Unhandled meta subtype %d\n", subtype);
334 "Unhandled meta subtype %d\n", subtype);
335 break; 334 break;
336 } 335 }
337 336
338 if(error) 337 if(error)
339 g_error_free(error); 338 g_error_free(error);
360 if (p) { 359 if (p) {
361 gaim_plugin_unload(p); 360 gaim_plugin_unload(p);
362 } 361 }
363 break; 362 break;
364 default: 363 default:
365 gaim_debug(GAIM_DEBUG_WARNING, "cui", 364 gaim_debug_warning("cui", "Unhandled plugin subtype %d\n", subtype);
366 "Unhandled plugin subtype %d\n", subtype);
367 break; 365 break;
368 } 366 }
369 #endif 367 #endif
370 } 368 }
371 369
412 case CUI_USER_BACK: 410 case CUI_USER_BACK:
413 do_im_back(NULL, NULL); 411 do_im_back(NULL, NULL);
414 break; 412 break;
415 #endif /* STATUS */ 413 #endif /* STATUS */
416 default: 414 default:
417 gaim_debug(GAIM_DEBUG_WARNING, "cui", 415 gaim_debug_warning("cui", "Unhandled user subtype %d\n", subtype);
418 "Unhandled user subtype %d\n", subtype);
419 break; 416 break;
420 } 417 }
421 } 418 }
422 419
423 static void 420 static void
461 } 458 }
462 break; 459 break;
463 case CUI_MESSAGE_RECV: 460 case CUI_MESSAGE_RECV:
464 break; 461 break;
465 default: 462 default:
466 gaim_debug(GAIM_DEBUG_WARNING, "cui", 463 gaim_debug_warning("cui", "Unhandled message subtype %d\n", subtype);
467 "Unhandled message subtype %d\n", subtype);
468 break; 464 break;
469 } 465 }
470 } 466 }
471 467
472 static gint 468 static gint
494 static void 490 static void
495 remote_handler(struct UI *ui, guchar subtype, gchar *data, int len) 491 remote_handler(struct UI *ui, guchar subtype, gchar *data, int len)
496 { 492 {
497 const char *resp; 493 const char *resp;
498 char *send; 494 char *send;
495
496 GList *c = gaim_connections_get_all();
497 GaimConnection *gc;
498 GaimAccount *account;
499
499 switch (subtype) { 500 switch (subtype) {
500 case CUI_REMOTE_CONNECTIONS: 501 case CUI_REMOTE_CONNECTIONS:
501 break; 502 break;
503 case CUI_REMOTE_SEND:
504 if (!data)
505 return;
506 {
507 guint id;
508 GaimConnection *gc;
509 GaimConversation *conv;
510 guint tlen,len,len2,quiet;
511 char *who, *msg;
512 char *tmp, *from, *proto;
513 gint flags;
514 int pos = 0;
515 GList *c = gaim_connections_get_all();
516
517 gaim_debug_info("cui", "Got `gaim-remote send` packet\n",data);
518 gaim_debug_info("cui", "g-r>%s;\n",data);
519
520 tmp = g_strndup(data + pos, 4);
521 tlen=atoi(tmp);
522 pos+=4;
523
524 who=g_strndup(data+pos, tlen);
525 pos+=tlen;
526
527 tmp = g_strndup(data + pos, 4);
528 tlen=atoi(tmp); len=tlen; /*length for 'from' compare*/
529 pos+=4;
530
531 from=g_strndup(data+pos, tlen);
532 pos+=tlen;
533
534 tmp = g_strndup(data + pos, 4);
535 tlen=atoi(tmp); len2=tlen; /*length for 'proto' compare*/
536 pos+=4;
537
538 proto=g_strndup(data+pos, tlen);
539 pos+=tlen;
540
541 tmp = g_strndup(data + pos, 4);
542 tlen=atoi(tmp);
543 pos+=4;
544
545 msg=g_strndup(data+pos, tlen);
546 pos+=tlen;
547
548 tmp = g_strndup(data + pos, 1);
549 quiet=atoi(tmp); /*quiet flag - not in use yet*/
550
551 /*find acct*/
552 while (c) {
553 gc = c->data;
554 account=gaim_connection_get_account(gc);
555 if ((!gaim_utf8_strcasecmp(from, gaim_account_get_username(account))) && (!g_ascii_strncasecmp(proto, gaim_account_get_protocol_id(account), len2)) )
556 break;
557 c = c->next;
558 }
559 if (!gc)
560 return;
561 /*end acct find*/
562
563 /*gaim_debug_info("cui", "g-r>To: %s; From: %s; Protocol: %s; Message: %s; Quiet: %d\n",who,from,proto,msg,quiet);*/
564 conv = gaim_conversation_new(GAIM_CONV_IM, gaim_connection_get_account(gc), who);
565 gaim_conv_im_send(GAIM_CONV_IM(conv), msg);
566
567 /*likely to be used for quiet:
568 serv_send_im(gc, who, msg, -1, 0);
569 */
570
571 g_free(who);
572 g_free(msg);
573 g_free(from);
574 g_free(tmp);
575 }
576 break;
577
502 case CUI_REMOTE_URI: 578 case CUI_REMOTE_URI:
503 send = g_malloc(len + 1); 579 send = g_malloc(len + 1);
504 memcpy(send, data, len); 580 memcpy(send, data, len);
505 send[len] = 0; 581 send[len] = 0;
506 resp = gaim_remote_handle_uri(send); 582 resp = gaim_remote_handle_uri(send);
507 g_free(send); 583 g_free(send);
508 /* report error */ 584 /* report error */
509 break; 585 break;
510 default: 586 default:
511 gaim_debug(GAIM_DEBUG_WARNING, "cui", 587 gaim_debug_warning("cui", "Unhandled remote subtype %d\n", subtype);
512 "Unhandled remote subtype %d\n", subtype);
513 break; 588 break;
514 } 589 }
515 } 590 }
516 591
517 static gboolean 592 static gboolean
527 602
528 gchar *in; 603 gchar *in;
529 604
530 /* no byte order worries! this'll change if we go to TCP */ 605 /* no byte order worries! this'll change if we go to TCP */
531 if (gaim_recv(source, &type, sizeof(type)) != sizeof(type)) { 606 if (gaim_recv(source, &type, sizeof(type)) != sizeof(type)) {
532 gaim_debug(GAIM_DEBUG_ERROR, "cui", "UI has abandoned us!\n"); 607 gaim_debug_error("cui", "UI has abandoned us!\n");
533 uis = g_slist_remove(uis, ui); 608 uis = g_slist_remove(uis, ui);
534 g_io_channel_shutdown(ui->channel, TRUE, &error); 609 g_io_channel_shutdown(ui->channel, TRUE, &error);
535 if(error) { 610 if(error) {
536 g_error_free(error); 611 g_error_free(error);
537 error = NULL; 612 error = NULL;
540 g_free(ui); 615 g_free(ui);
541 return FALSE; 616 return FALSE;
542 } 617 }
543 618
544 if (gaim_recv(source, &subtype, sizeof(subtype)) != sizeof(subtype)) { 619 if (gaim_recv(source, &subtype, sizeof(subtype)) != sizeof(subtype)) {
545 gaim_debug(GAIM_DEBUG_ERROR, "cui", "UI has abandoned us!\n"); 620 gaim_debug_error("cui", "UI has abandoned us!\n");
546 uis = g_slist_remove(uis, ui); 621 uis = g_slist_remove(uis, ui);
547 g_io_channel_shutdown(ui->channel, TRUE, &error); 622 g_io_channel_shutdown(ui->channel, TRUE, &error);
548 if(error) { 623 if(error) {
549 g_error_free(error); 624 g_error_free(error);
550 error = NULL; 625 error = NULL;
553 g_free(ui); 628 g_free(ui);
554 return FALSE; 629 return FALSE;
555 } 630 }
556 631
557 if (gaim_recv(source, (gchar *)&len, sizeof(len)) != sizeof(len)) { 632 if (gaim_recv(source, (gchar *)&len, sizeof(len)) != sizeof(len)) {
558 gaim_debug(GAIM_DEBUG_ERROR, "cui", "UI has abandoned us!\n"); 633 gaim_debug_error("cui", "UI has abandoned us!\n");
559 uis = g_slist_remove(uis, ui); 634 uis = g_slist_remove(uis, ui);
560 g_io_channel_shutdown(ui->channel, TRUE, &error); 635 g_io_channel_shutdown(ui->channel, TRUE, &error);
561 if(error) { 636 if(error) {
562 g_error_free(error); 637 g_error_free(error);
563 error = NULL; 638 error = NULL;
568 } 643 }
569 644
570 if (len) { 645 if (len) {
571 in = g_new0(gchar, len); 646 in = g_new0(gchar, len);
572 if (gaim_recv(source, in, len) != len) { 647 if (gaim_recv(source, in, len) != len) {
573 gaim_debug(GAIM_DEBUG_ERROR, "cui", "UI has abandoned us!\n"); 648 gaim_debug_error("cui", "UI has abandoned us!\n");
574 uis = g_slist_remove(uis, ui); 649 uis = g_slist_remove(uis, ui);
575 g_io_channel_shutdown(ui->channel, TRUE, &error); 650 g_io_channel_shutdown(ui->channel, TRUE, &error);
576 if(error) { 651 if(error) {
577 g_error_free(error); 652 g_error_free(error);
578 error = NULL; 653 error = NULL;
612 */ 687 */
613 case CUI_TYPE_REMOTE: 688 case CUI_TYPE_REMOTE:
614 remote_handler(ui, subtype, in, len); 689 remote_handler(ui, subtype, in, len);
615 break; 690 break;
616 default: 691 default:
617 gaim_debug(GAIM_DEBUG_WARNING, "cui", 692 gaim_debug_warning("cui", "Unhandled type %d\n", type);
618 "Unhandled type %d\n", type);
619 break; 693 break;
620 } 694 }
621 695
622 if (in) 696 if (in)
623 g_free(in); 697 g_free(in);
641 715
642 ui->channel = g_io_channel_unix_new(fd); 716 ui->channel = g_io_channel_unix_new(fd);
643 ui->inpa = g_io_add_watch(ui->channel, G_IO_IN | G_IO_HUP | G_IO_ERR, UI_readable, ui); 717 ui->inpa = g_io_add_watch(ui->channel, G_IO_IN | G_IO_HUP | G_IO_ERR, UI_readable, ui);
644 g_io_channel_unref(ui->channel); 718 g_io_channel_unref(ui->channel);
645 719
646 gaim_debug(GAIM_DEBUG_MISC, "cui", "Got one\n"); 720 gaim_debug_misc("cui", "Got one\n");
647 return TRUE; 721 return TRUE;
648 } 722 }
649 723
650 static gint 724 static gint
651 open_socket(char **error) 725 open_socket(char **error)
654 gint fd; 728 gint fd;
655 729
656 while (gaim_remote_session_exists(gaim_session)) 730 while (gaim_remote_session_exists(gaim_session))
657 gaim_session++; 731 gaim_session++;
658 732
659 gaim_debug(GAIM_DEBUG_MISC, "cui", "Session: %d\n", gaim_session); 733 gaim_debug_misc("cui", "Session: %d\n", gaim_session);
660 734
661 if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) != -1) { 735 if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) != -1) {
662 mode_t m = umask(0177); 736 mode_t m = umask(0177);
663 saddr.sun_family = AF_UNIX; 737 saddr.sun_family = AF_UNIX;
664 738
718 g_snprintf(buf, sizeof(buf), "%s" G_DIR_SEPARATOR_S "gaim_%s.%d", 792 g_snprintf(buf, sizeof(buf), "%s" G_DIR_SEPARATOR_S "gaim_%s.%d",
719 g_get_tmp_dir(), g_get_user_name(), gaim_session); 793 g_get_tmp_dir(), g_get_user_name(), gaim_session);
720 794
721 unlink(buf); 795 unlink(buf);
722 796
723 gaim_debug(GAIM_DEBUG_MISC, "core", "Removed core\n"); 797 gaim_debug_misc("core", "Removed core\n");
724 798
725 return TRUE; 799 return TRUE;
726 #else 800 #else
727 return FALSE; 801 return FALSE;
728 #endif 802 #endif

mercurial