| 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?"))) { |
| 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; |
| 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 |