Class: PurpleRuby
- Inherits:
-
Object
- Object
- PurpleRuby
- Defined in:
- ext/purple_ruby.c
Defined Under Namespace
Classes: Account
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
- .init(debug, path) ⇒ Object
- .list_protocols ⇒ Object
- .login(protocol, username, password) ⇒ Object
- .main_loop_run ⇒ Object
- .main_loop_stop ⇒ Object
- .watch_connection_error ⇒ Object
- .watch_incoming_im ⇒ Object
- .watch_incoming_ipc(serverip, port) ⇒ Object
- .watch_new_buddy ⇒ Object
- .watch_notify_message ⇒ Object
- .watch_request ⇒ Object
- .watch_signed_on_event ⇒ Object
- .watch_timer(delay) ⇒ Object
Class Method Details
.init(debug, path) ⇒ Object
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 |
# File 'ext/purple_ruby.c', line 369 static VALUE init(VALUE self, VALUE debug, VALUE path) { signal(SIGCHLD, SIG_IGN); signal(SIGPIPE, SIG_IGN); signal(SIGINT, sighandler); data_hash_table = g_hash_table_new(NULL, NULL); fd_hash_table = g_hash_table_new(NULL, NULL); purple_debug_set_enabled((debug == Qnil || debug == Qfalse) ? FALSE : TRUE); if (path != Qnil) { purple_util_set_user_dir(RSTRING(path)->ptr); } 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_protocols ⇒ Object
684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 |
# File 'ext/purple_ruby.c', line 684 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
589 590 591 592 593 594 595 596 597 598 599 600 601 602 |
# File 'ext/purple_ruby.c', line 589 static VALUE login(VALUE self, VALUE protocol, VALUE username, VALUE password) { PurpleAccount* account = purple_account_new(RSTRING(username)->ptr, RSTRING(protocol)->ptr); if (NULL == account || NULL == account->presence) { rb_raise(rb_eRuntimeError, "No able to create account: %s", RSTRING(protocol)->ptr); } purple_account_set_password(account, RSTRING(password)->ptr); 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_run ⇒ Object
604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 |
# File 'ext/purple_ruby.c', line 604 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 (connection_error_handler == Qnil) rb_gc_unregister_address(&connection_error_handler); if ( == Qnil) rb_gc_unregister_address(&); 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_stop ⇒ Object
627 628 629 630 631 |
# File 'ext/purple_ruby.c', line 627 static VALUE main_loop_stop(VALUE self) { g_main_loop_quit(main_loop); return Qnil; } |
.watch_connection_error ⇒ Object
449 450 451 452 453 454 455 456 457 458 459 460 |
# File 'ext/purple_ruby.c', line 449 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_im ⇒ Object
404 405 406 407 408 409 |
# File 'ext/purple_ruby.c', line 404 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
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 |
# File 'ext/purple_ruby.c', line 527 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(serverip)->ptr); 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_buddy ⇒ Object
425 426 427 428 429 430 |
# File 'ext/purple_ruby.c', line 425 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_message ⇒ Object
411 412 413 414 415 416 |
# File 'ext/purple_ruby.c', line 411 static VALUE (VALUE self) { purple_notify_set_ui_ops(¬ify_ops); set_callback(&, "notify_message_handler"); return ; } |
.watch_request ⇒ Object
418 419 420 421 422 423 |
# File 'ext/purple_ruby.c', line 418 static VALUE watch_request(VALUE self) { purple_request_set_ui_ops(&request_ops); set_callback(&request_handler, "request_handler"); return request_handler; } |
.watch_signed_on_event ⇒ Object
440 441 442 443 444 445 446 447 |
# File 'ext/purple_ruby.c', line 440 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
580 581 582 583 584 585 586 587 |
# File 'ext/purple_ruby.c', line 580 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; } |