comparison plugins/gaim-remote/remote.c @ 10005:c892b6dbc341

[gaim-migrate @ 10922] Dear everyone: export CFLAGS=-Wall make 1> /dev/null committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Fri, 10 Sep 2004 02:51:22 +0000
parents 33431f91e4a8
children a38881ec9c0f
comparison
equal deleted inserted replaced
10004:690ef036f297 10005:c892b6dbc341
34 #include "conversation.h" 34 #include "conversation.h"
35 #include "core.h" 35 #include "core.h"
36 #include "debug.h" 36 #include "debug.h"
37 #include "prpl.h" 37 #include "prpl.h"
38 #include "notify.h" 38 #include "notify.h"
39 #include "util.h"
39 #include "version.h" 40 #include "version.h"
40 41
41 /* XXX */ 42 /* XXX */
42 #include "gtkconv.h" 43 #include "gtkconv.h"
43 #include "gtkplugin.h" 44 #include "gtkplugin.h"
372 { 373 {
373 guint id; 374 guint id;
374 GaimAccount *account; 375 GaimAccount *account;
375 376
376 switch (subtype) { 377 switch (subtype) {
377 /* 378 /*
378 case CUI_USER_LIST: 379 case CUI_USER_LIST:
379 break; 380 break;
380 case CUI_USER_ADD: 381 case CUI_USER_ADD:
381 break; 382 break;
382 case CUI_USER_REMOVE: 383 case CUI_USER_REMOVE:
383 break; 384 break;
384 case CUI_USER_MODIFY: 385 case CUI_USER_MODIFY:
385 break; 386 break;
386 */ 387 */
388
387 case CUI_USER_SIGNON: 389 case CUI_USER_SIGNON:
388 if (!data) 390 if (!data)
389 return; 391 return;
390 memcpy(&id, data, sizeof(id)); 392 memcpy(&id, data, sizeof(id));
391 account = g_list_nth_data(gaim_accounts_get_all(), id); 393 account = g_list_nth_data(gaim_accounts_get_all(), id);
392 if (account) 394 if (account)
393 gaim_account_connect(account); 395 gaim_account_connect(account);
394 /* don't need to do anything here because the UI will get updates from other handlers */ 396 /* don't need to do anything here because the UI will get updates from other handlers */
395 break; 397 break;
398
396 #if 0 /* STATUS */ 399 #if 0 /* STATUS */
397 case CUI_USER_AWAY: 400 case CUI_USER_AWAY:
398 { 401 {
399 GSList* l; 402 GSList* l;
400 const char* default_away_name = gaim_prefs_get_string("/core/away/default_message"); 403 const char* default_away_name = gaim_prefs_get_string("/core/away/default_message");
401 404
402 for(l = away_messages; l; l = l->next) { 405 for (l = away_messages; l; l = l->next) {
403 if(!strcmp(default_away_name, ((struct away_message *)l->data)->name)) { 406 if (!strcmp(default_away_name, ((struct away_message *)l->data)->name)) {
404 do_away_message(NULL, l->data); 407 do_away_message(NULL, l->data);
405 break; 408 break;
406 } 409 }
407 } 410 }
408 } 411 }
409 break; 412 break;
410 case CUI_USER_BACK: 413
411 do_im_back(NULL, NULL); 414 case CUI_USER_BACK:
412 break; 415 do_im_back(NULL, NULL);
416 break;
417
413 #endif /* STATUS */ 418 #endif /* STATUS */
414 default: 419 default:
415 gaim_debug_warning("cui", "Unhandled user subtype %d\n", subtype); 420 gaim_debug_warning("cui", "Unhandled user subtype %d\n", subtype);
416 break; 421 break;
417 } 422 }
490 static void 495 static void
491 remote_handler(struct UI *ui, guchar subtype, gchar *data, int len) 496 remote_handler(struct UI *ui, guchar subtype, gchar *data, int len)
492 { 497 {
493 const char *resp; 498 const char *resp;
494 char *send; 499 char *send;
495
496 GList *c = gaim_connections_get_all(); 500 GList *c = gaim_connections_get_all();
497 GaimConnection *gc; 501 GaimConnection *gc;
498 GaimAccount *account; 502 GaimAccount *account;
499 503
500 switch (subtype) { 504 switch (subtype) {
502 break; 506 break;
503 case CUI_REMOTE_SEND: 507 case CUI_REMOTE_SEND:
504 if (!data) 508 if (!data)
505 return; 509 return;
506 { 510 {
507 guint id;
508 GaimConnection *gc;
509 GaimConversation *conv; 511 GaimConversation *conv;
510 guint tlen,len,len2,quiet; 512 guint tlen, len, len2, quiet;
511 char *who, *msg; 513 char *who, *msg;
512 char *tmp, *from, *proto; 514 char *tmp, *from, *proto;
513 gint flags;
514 int pos = 0; 515 int pos = 0;
515 GList *c = gaim_connections_get_all();
516 516
517 gaim_debug_info("cui", "Got `gaim-remote send` packet\n",data); 517 gaim_debug_info("cui", "Got `gaim-remote send` packet\n",data);
518 gaim_debug_info("cui", "g-r>%s;\n",data); 518 gaim_debug_info("cui", "g-r>%s;\n",data);
519 519
520 tmp = g_strndup(data + pos, 4); 520 tmp = g_strndup(data + pos, 4);
521 tlen=atoi(tmp); 521 tlen = atoi(tmp);
522 pos+=4; 522 pos += 4;
523 523
524 who=g_strndup(data+pos, tlen); 524 who = g_strndup(data+pos, tlen);
525 pos+=tlen; 525 pos += tlen;
526 526
527 tmp = g_strndup(data + pos, 4); 527 tmp = g_strndup(data + pos, 4);
528 tlen=atoi(tmp); len=tlen; /*length for 'from' compare*/ 528 tlen = atoi(tmp); len=tlen; /* length for 'from' compare */
529 pos+=4; 529 pos += 4;
530 530
531 from=g_strndup(data+pos, tlen); 531 from = g_strndup(data+pos, tlen);
532 pos+=tlen; 532 pos += tlen;
533 533
534 tmp = g_strndup(data + pos, 4); 534 tmp = g_strndup(data + pos, 4);
535 tlen=atoi(tmp); len2=tlen; /*length for 'proto' compare*/ 535 tlen = atoi(tmp); len2=tlen; /* length for 'proto' compare */
536 pos+=4; 536 pos += 4;
537 537
538 proto=g_strndup(data+pos, tlen); 538 proto = g_strndup(data+pos, tlen);
539 pos+=tlen; 539 pos += tlen;
540 540
541 tmp = g_strndup(data + pos, 4); 541 tmp = g_strndup(data + pos, 4);
542 tlen=atoi(tmp); 542 tlen = atoi(tmp);
543 pos+=4; 543 pos += 4;
544 544
545 msg=g_strndup(data+pos, tlen); 545 msg = g_strndup(data+pos, tlen);
546 pos+=tlen; 546 pos += tlen;
547 547
548 tmp = g_strndup(data + pos, 1); 548 tmp = g_strndup(data + pos, 1);
549 quiet=atoi(tmp); /*quiet flag - not in use yet*/ 549 quiet = atoi(tmp); /* quiet flag - not in use yet */
550 550
551 /*find acct*/ 551 /* find acct */
552 while (c) { 552 while (c) {
553 gc = c->data; 553 gc = c->data;
554 account=gaim_connection_get_account(gc); 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)) ) 555 if ((!gaim_utf8_strcasecmp(from, gaim_account_get_username(account))) && (!g_ascii_strncasecmp(proto, gaim_account_get_protocol_id(account), len2)) )
556 break; 556 break;
557 c = c->next; 557 c = c->next;
558 } 558 }
559 if (!gc) 559 if (!gc)
560 return; 560 return;
561 /*end acct find*/ 561 /* end acct find */
562 562
563 /*gaim_debug_info("cui", "g-r>To: %s; From: %s; Protocol: %s; Message: %s; Quiet: %d\n",who,from,proto,msg,quiet);*/ 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); 564 conv = gaim_conversation_new(GAIM_CONV_IM, gaim_connection_get_account(gc), who);
565 gaim_conv_im_send(GAIM_CONV_IM(conv), msg); 565 gaim_conv_im_send(GAIM_CONV_IM(conv), msg);
566 566
567 /*likely to be used for quiet: 567 /* likely to be used for quiet:
568 serv_send_im(gc, who, msg, -1, 0); 568 serv_send_im(gc, who, msg, -1, 0);
569 */ 569 */
570 570
571 g_free(who); 571 g_free(who);
572 g_free(msg); 572 g_free(msg);
573 g_free(from); 573 g_free(from);
574 g_free(tmp); 574 g_free(tmp);
575 } 575 }
581 send[len] = 0; 581 send[len] = 0;
582 resp = gaim_remote_handle_uri(send); 582 resp = gaim_remote_handle_uri(send);
583 g_free(send); 583 g_free(send);
584 /* report error */ 584 /* report error */
585 break; 585 break;
586
586 default: 587 default:
587 gaim_debug_warning("cui", "Unhandled remote subtype %d\n", subtype); 588 gaim_debug_warning("cui", "Unhandled remote subtype %d\n", subtype);
588 break; 589 break;
589 } 590 }
590 } 591 }
591 592
592 static gboolean 593 static gboolean
593 UI_readable(GIOChannel *source, GIOCondition cond, gpointer data) 594 UI_readable(GIOChannel *source, GIOCondition cond, gpointer data)
594 { 595 {
595 struct UI *ui = data; 596 struct UI *ui = data;
596
597 gchar type; 597 gchar type;
598 gchar subtype; 598 gchar subtype;
599 gint len; 599 gint len;
600
601 GError *error = NULL; 600 GError *error = NULL;
602
603 gchar *in; 601 gchar *in;
604 602
605 /* no byte order worries! this'll change if we go to TCP */ 603 /* no byte order worries! this'll change if we go to TCP */
606 if (gaim_recv(source, &type, sizeof(type)) != sizeof(type)) { 604 if (gaim_recv(source, &type, sizeof(type)) != sizeof(type)) {
607 gaim_debug_error("cui", "UI has abandoned us!\n"); 605 gaim_debug_error("cui", "UI has abandoned us!\n");
683 /* 681 /*
684 case CUI_TYPE_CHAT: 682 case CUI_TYPE_CHAT:
685 chat_handler(ui, subtype, in); 683 chat_handler(ui, subtype, in);
686 break; 684 break;
687 */ 685 */
688 case CUI_TYPE_REMOTE: 686 case CUI_TYPE_REMOTE:
689 remote_handler(ui, subtype, in, len); 687 remote_handler(ui, subtype, in, len);
690 break; 688 break;
691 default: 689 default:
692 gaim_debug_warning("cui", "Unhandled type %d\n", type); 690 gaim_debug_warning("cui", "Unhandled type %d\n", type);
693 break; 691 break;
694 } 692 }
695 693
696 if (in) 694 if (in)
833 NULL, 831 NULL,
834 NULL 832 NULL
835 }; 833 };
836 834
837 static void 835 static void
838 __init_plugin(GaimPlugin *plugin) 836 _init_plugin(GaimPlugin *plugin)
839 { 837 {
840 } 838 }
841 839
842 /* This may be horribly wrong. Oh the mayhem! */ 840 /* This may be horribly wrong. Oh the mayhem! */
843 GAIM_INIT_PLUGIN(remote, __init_plugin, info) 841 GAIM_INIT_PLUGIN(remote, _init_plugin, info)