Class: PurpleRuby

Inherits:
Object
  • Object
show all
Defined in:
ext/purple_ruby.c

Defined Under Namespace

Classes: Account, ConnectionError

Constant Summary collapse

NOTIFY_MSG_ERROR =
INT2NUM(PURPLE_NOTIFY_MSG_ERROR)
NOTIFY_MSG_WARNING =
INT2NUM(PURPLE_NOTIFY_MSG_WARNING)
NOTIFY_MSG_INFO =
INT2NUM(PURPLE_NOTIFY_MSG_INFO)

Class Method Summary collapse

Class Method Details

.init(*args) ⇒ Object



380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
# File 'ext/purple_ruby.c', line 380

static VALUE init(int argc, VALUE* argv, VALUE self)
{
  VALUE debug, path;
  rb_scan_args(argc, argv, "02", &debug, &path);

  signal(SIGCHLD, SIG_IGN);
  signal(SIGPIPE, SIG_IGN);
  signal(SIGINT, sighandler);
  signal(SIGQUIT, sighandler);
  signal(SIGTERM, sighandler);

  data_hash_table = g_hash_table_new(NULL, NULL);
  fd_hash_table = g_hash_table_new(NULL, NULL);

  purple_debug_set_enabled((NIL_P(debug) || debug == Qfalse) ? FALSE : TRUE);

  if (!NIL_P(path)) {
    Check_Type(path, T_STRING);   
		purple_util_set_user_dir(RSTRING_PTR(path));
	}

  purple_core_set_ui_ops(&core_uiops);
  purple_eventloop_set_ui_ops(&glib_eventloops);
  
  if (!purple_core_init(UI_ID)) {
		rb_raise(rb_eRuntimeError, "libpurple initialization failed");
	}

  /* Create and load the buddylist. */
  purple_set_blist(purple_blist_new());
  purple_blist_load();

  /* Load the preferences. */
  purple_prefs_load();

  /* Load the pounces. */
  purple_pounces_load();

  return Qnil;
}

.list_protocolsObject



751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
# File 'ext/purple_ruby.c', line 751

static VALUE list_protocols(VALUE self)
{
  VALUE array = rb_ary_new();
  
  GList *iter = purple_plugins_get_protocols();
  int i;
	for (i = 0; iter; iter = iter->next) {
		PurplePlugin *plugin = iter->data;
		PurplePluginInfo *info = plugin->info;
		if (info && info->name) {
		  char s[256];
			snprintf(s, sizeof(s) -1, "%s %s", info->id, info->name);
			rb_ary_push(array, rb_str_new2(s));
		}
	}
  
  return array;
}

.login(protocol, username, password) ⇒ Object



623
624
625
626
627
628
629
630
631
632
633
634
635
636
# File 'ext/purple_ruby.c', line 623

static VALUE login(VALUE self, VALUE protocol, VALUE username, VALUE password)
{
  PurpleAccount* account = purple_account_new(RSTRING_PTR(username), RSTRING_PTR(protocol));
  if (NULL == account || NULL == account->presence) {
    rb_raise(rb_eRuntimeError, "No able to create account: %s", RSTRING_PTR(protocol));
  }
  purple_account_set_password(account, RSTRING_PTR(password));
  purple_account_set_remember_password(account, TRUE);
  purple_account_set_enabled(account, UI_ID, TRUE);
  PurpleSavedStatus *status = purple_savedstatus_new(NULL, PURPLE_STATUS_AVAILABLE);
	purple_savedstatus_activate(status);
	
	return Data_Wrap_Struct(cAccount, NULL, NULL, account);
}

.main_loop_runObject



647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
# File 'ext/purple_ruby.c', line 647

static VALUE main_loop_run(VALUE self)
{
  main_loop = g_main_loop_new(NULL, FALSE);
  g_main_loop_run(main_loop);
  
#ifdef DEBUG_MEM_LEAK
  printf("QUIT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
  purple_core_quit();
  if (im_handler == Qnil) rb_gc_unregister_address(&im_handler);
  if (signed_on_handler == Qnil) rb_gc_unregister_address(&signed_on_handler);
  if (signed_off_handler == Qnil) rb_gc_unregister_address(&signed_off_handler);
  if (connection_error_handler == Qnil) rb_gc_unregister_address(&connection_error_handler);
  if (notify_message_handler == Qnil) rb_gc_unregister_address(&notify_message_handler);
  if (request_handler == Qnil) rb_gc_unregister_address(&request_handler);
  if (ipc_handler == Qnil) rb_gc_unregister_address(&ipc_handler);
  if (timer_timeout != 0) g_source_remove(timer_timeout);
  if (timer_handler == Qnil) rb_gc_unregister_address(&timer_handler);
  if (new_buddy_handler == Qnil) rb_gc_unregister_address(&new_buddy_handler);
  rb_gc_start();
#endif
  
  return Qnil;
}

.main_loop_stopObject



671
672
673
674
675
# File 'ext/purple_ruby.c', line 671

static VALUE main_loop_stop(VALUE self)
{
  g_main_loop_quit(main_loop);
  return Qnil;
}

.watch_connection_errorObject



483
484
485
486
487
488
489
490
491
492
493
494
# File 'ext/purple_ruby.c', line 483

static VALUE watch_connection_error(VALUE self)
{
  finch_connections_init();
  purple_connections_set_ui_ops(&connection_ops);
  
  set_callback(&connection_error_handler, "connection_error_handler");
  
  /*int handle;
	purple_signal_connect(purple_connections_get_handle(), "connection-error", &handle,
				PURPLE_CALLBACK(connection_error), NULL);*/
  return connection_error_handler;
}

.watch_incoming_imObject



421
422
423
424
425
426
# File 'ext/purple_ruby.c', line 421

static VALUE watch_incoming_im(VALUE self)
{
  purple_conversations_set_ui_ops(&conv_uiops);
  set_callback(&im_handler, "im_handler");
  return im_handler;
}

.watch_incoming_ipc(serverip, port) ⇒ Object



561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
# File 'ext/purple_ruby.c', line 561

static VALUE watch_incoming_ipc(VALUE self, VALUE serverip, VALUE port)
{
	struct sockaddr_in my_addr;
	int soc;
	int on = 1;

	/* Open a listening socket for incoming conversations */
	if ((soc = socket(PF_INET, SOCK_STREAM, 0)) < 0)
	{
		rb_raise(rb_eRuntimeError, "Cannot open socket: %s\n", g_strerror(errno));
		return Qnil;
	}

	if (setsockopt(soc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0)
	{
		rb_raise(rb_eRuntimeError, "SO_REUSEADDR failed: %s\n", g_strerror(errno));
		return Qnil;
	}

	memset(&my_addr, 0, sizeof(struct sockaddr_in));
	my_addr.sin_family = AF_INET;
	my_addr.sin_addr.s_addr = inet_addr(RSTRING_PTR(serverip));
	my_addr.sin_port = htons(FIX2INT(port));
	if (bind(soc, (struct sockaddr*)&my_addr, sizeof(struct sockaddr)) != 0)
	{
		rb_raise(rb_eRuntimeError, "Unable to bind to port %d: %s\n", (int)FIX2INT(port), g_strerror(errno));
		return Qnil;
	}

	/* Attempt to listen on the bound socket */
	if (listen(soc, 10) != 0)
	{
		rb_raise(rb_eRuntimeError, "Cannot listen on socket: %s\n", g_strerror(errno));
		return Qnil;
	}

  set_callback(&ipc_handler, "ipc_handler");
  
	/* Open a watcher in the socket we have just opened */
	purple_input_add(soc, PURPLE_INPUT_READ, _accept_socket_handler, NULL);
	
	return port;
}

.watch_new_buddyObject



442
443
444
445
446
447
# File 'ext/purple_ruby.c', line 442

static VALUE watch_new_buddy(VALUE self)
{
  purple_accounts_set_ui_ops(&account_ops);
  set_callback(&new_buddy_handler, "new_buddy_handler");
  return new_buddy_handler;
}

.watch_notify_messageObject



428
429
430
431
432
433
# File 'ext/purple_ruby.c', line 428

static VALUE watch_notify_message(VALUE self)
{
  purple_notify_set_ui_ops(&notify_ops);
  set_callback(&notify_message_handler, "notify_message_handler");
  return notify_message_handler;
}

.watch_requestObject



435
436
437
438
439
440
# File 'ext/purple_ruby.c', line 435

static VALUE watch_request(VALUE self)
{
  purple_request_set_ui_ops(&request_ops);
  set_callback(&request_handler, "request_handler");
  return request_handler;
}

.watch_signed_off_eventObject



474
475
476
477
478
479
480
481
# File 'ext/purple_ruby.c', line 474

static  VALUE watch_signed_off_event(VALUE self)
{
  set_callback(&signed_off_handler, "signed_off_handler");
  int handle;
	purple_signal_connect(purple_connections_get_handle(), "signed-off", &handle,
				PURPLE_CALLBACK(signed_off), NULL);
  return signed_off_handler;
}

.watch_signed_on_eventObject



465
466
467
468
469
470
471
472
# File 'ext/purple_ruby.c', line 465

static VALUE watch_signed_on_event(VALUE self)
{
  set_callback(&signed_on_handler, "signed_on_handler");
  int handle;
	purple_signal_connect(purple_connections_get_handle(), "signed-on", &handle,
				PURPLE_CALLBACK(signed_on), NULL);
  return signed_on_handler;
}

.watch_timer(delay) ⇒ Object



614
615
616
617
618
619
620
621
# File 'ext/purple_ruby.c', line 614

static VALUE watch_timer(VALUE self, VALUE delay)
{
	set_callback(&timer_handler, "timer_handler");
	if (timer_timeout != 0)
		g_source_remove(timer_timeout);
	timer_timeout = g_timeout_add(delay, do_timeout, timer_handler);
	return delay;
}