Class: StropheRuby::Stanza
- Inherits:
-
Object
- Object
- StropheRuby::Stanza
- Defined in:
- ext/strophe_ruby.c
Class Method Summary collapse
-
.new ⇒ Object
Create a new stanza.
Instance Method Summary collapse
-
#add_child(rb_child) ⇒ Object
Add a child element to a stanza (hint: message stanzas have a body element…).
-
#attribute(rb_attribute) ⇒ Object
Get the attribute of a stanza.
-
#child_by_name(rb_name) ⇒ Object
Get the child of a stanza by its name.
-
#children ⇒ Object
Get the children of the stanza.
-
#clone ⇒ Object
Clone a stanza.
-
#copy ⇒ Object
Copy a stanza.
-
#id ⇒ Object
Get the id of a stanza.
-
#id=(rb_id) ⇒ Object
Set the id of a stanza.
-
#name ⇒ Object
Get the name of a stanza (message, presence, iq).
-
#name=(rb_name) ⇒ Object
Set the name of a stanza (message, presence, iq).
-
#next ⇒ Object
TODO: Test this!.
-
#ns ⇒ Object
Get the namespace of a stanza TODO: Test this!.
-
#ns=(rb_ns) ⇒ Object
Set the namespace of a stanza.
-
#set_attribute(rb_attribute, rb_val) ⇒ Object
Set the value of a stanza attribute (eg. stanza.set_attribute(“to”,“[email protected]”).
-
#text ⇒ Object
Get the text of a stanza.
-
#text=(rb_text) ⇒ Object
Set the text of a stanza.
-
#to_s ⇒ Object
Convert Stanza to String.
-
#type ⇒ Object
Get the type of a stanza.
-
#type=(rb_type) ⇒ Object
Set the type of a stanza.
Class Method Details
.new ⇒ Object
Create a new stanza
391 392 393 394 395 396 397 398 399 |
# File 'ext/strophe_ruby.c', line 391
VALUE t_xmpp_stanza_new(VALUE class) {
//Get the context in a format that C can understand
xmpp_ctx_t *ctx;
VALUE rb_conn = rb_gv_get("rb_conn");
Data_Get_Struct(rb_iv_get(rb_conn,"@ctx"), xmpp_ctx_t, ctx);
xmpp_stanza_t *stanza = xmpp_stanza_new(ctx);
VALUE tdata = Data_Wrap_Struct(class, 0, t_xmpp_stanza_release, stanza);
}
|
Instance Method Details
#add_child(rb_child) ⇒ Object
Add a child element to a stanza (hint: message stanzas have a body element…)
611 612 613 614 615 616 617 618 619 |
# File 'ext/strophe_ruby.c', line 611
static VALUE t_xmpp_stanza_add_child(VALUE self, VALUE rb_child) {
xmpp_stanza_t *stanza;
Data_Get_Struct(self, xmpp_stanza_t, stanza);
xmpp_stanza_t *child;
Data_Get_Struct(rb_child, xmpp_stanza_t, child);
int res = xmpp_stanza_add_child(stanza,child);
return INT2FIX(res);
}
|
#attribute(rb_attribute) ⇒ Object
Get the attribute of a stanza. eg. message_stanza.child_by_name(“body”).text
468 469 470 471 472 473 474 |
# File 'ext/strophe_ruby.c', line 468
static VALUE t_xmpp_stanza_get_attribute(VALUE self, VALUE rb_attribute) {
xmpp_stanza_t *stanza;
Data_Get_Struct(self, xmpp_stanza_t, stanza);
char *val = xmpp_stanza_get_attribute(stanza,StringValuePtr(rb_attribute));
return rb_str_new2(val);
}
|
#child_by_name(rb_name) ⇒ Object
Get the child of a stanza by its name. eg. body_stanza = message_stanza.child_by_name(“body”)
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 |
# File 'ext/strophe_ruby.c', line 439
static VALUE t_xmpp_stanza_get_child_by_name(VALUE self, VALUE rb_name) {
xmpp_stanza_t *stanza;
xmpp_stanza_t *child;
Data_Get_Struct(self, xmpp_stanza_t, stanza);
char *name = StringValuePtr(rb_name);
child = xmpp_stanza_get_child_by_name(stanza, name);
if(child) {
VALUE rb_child = Data_Wrap_Struct(cStanza, 0, t_xmpp_stanza_release, child);
return rb_child;
} else {
return Qnil;
}
}
|
#children ⇒ Object
Get the children of the stanza. For example, message stanzas have a “body” child that contains another stanza that contains the actual message. If you have the top level stanza you can do something like : body_stanza = message_stanza.children
424 425 426 427 428 429 430 431 432 433 434 435 436 |
# File 'ext/strophe_ruby.c', line 424
static VALUE t_xmpp_stanza_get_children(VALUE self) {
xmpp_stanza_t *stanza;
xmpp_stanza_t *children;
Data_Get_Struct(self, xmpp_stanza_t, stanza);
children = xmpp_stanza_get_children(stanza);
if(children) {
VALUE tdata = Data_Wrap_Struct(cStanza, 0, t_xmpp_stanza_release, children);
return tdata;
}
else
return Qnil;
}
|
#clone ⇒ Object
Clone a stanza. TODO: Test this!
402 403 404 405 406 407 408 409 |
# File 'ext/strophe_ruby.c', line 402 static VALUE t_xmpp_stanza_clone(VALUE self) { xmpp_stanza_t *stanza; xmpp_stanza_t *new_stanza; Data_Get_Struct(self, xmpp_stanza_t, stanza); new_stanza = xmpp_stanza_clone(stanza); VALUE tdata = Data_Wrap_Struct(cStanza, 0, t_xmpp_stanza_release, new_stanza); return tdata; } |
#copy ⇒ Object
Copy a stanza. TODO: Test this!
412 413 414 415 416 417 418 419 |
# File 'ext/strophe_ruby.c', line 412 static VALUE t_xmpp_stanza_copy(VALUE self) { xmpp_stanza_t *stanza; xmpp_stanza_t *new_stanza; Data_Get_Struct(self, xmpp_stanza_t, stanza); new_stanza = xmpp_stanza_copy(stanza); VALUE tdata = Data_Wrap_Struct(cStanza, 0, t_xmpp_stanza_release, new_stanza); return tdata; } |
#id ⇒ Object
Get the id of a stanza. TODO:Test this!
521 522 523 524 525 526 527 |
# File 'ext/strophe_ruby.c', line 521 static VALUE t_xmpp_stanza_get_id(VALUE self) { xmpp_stanza_t *stanza; Data_Get_Struct(self, xmpp_stanza_t, stanza); char *id = xmpp_stanza_get_id(stanza); return rb_str_new2(id); } |
#id=(rb_id) ⇒ Object
Set the id of a stanza. TODO:Test this!
600 601 602 603 604 605 606 607 608 |
# File 'ext/strophe_ruby.c', line 600
static VALUE t_xmpp_stanza_set_id(VALUE self, VALUE rb_id) {
xmpp_stanza_t *stanza;
Data_Get_Struct(self, xmpp_stanza_t, stanza);
char *id = StringValuePtr(rb_id);
xmpp_stanza_set_id(stanza, id);
return Qtrue;
}
|
#name ⇒ Object
Get the name of a stanza (message, presence, iq)
499 500 501 502 503 504 505 |
# File 'ext/strophe_ruby.c', line 499 static VALUE t_xmpp_stanza_get_name(VALUE self) { xmpp_stanza_t *stanza; Data_Get_Struct(self, xmpp_stanza_t, stanza); char *name = xmpp_stanza_get_name(stanza); return rb_str_new2(name); } |
#name=(rb_name) ⇒ Object
Set the name of a stanza (message, presence, iq)
578 579 580 581 582 583 584 585 586 |
# File 'ext/strophe_ruby.c', line 578
static VALUE t_xmpp_stanza_set_name(VALUE self, VALUE rb_name) {
xmpp_stanza_t *stanza;
Data_Get_Struct(self, xmpp_stanza_t, stanza);
char *name = StringValuePtr(rb_name);
xmpp_stanza_set_name(stanza, name);
return Qtrue;
}
|
#next ⇒ Object
TODO: Test this!
456 457 458 459 460 461 462 463 464 465 |
# File 'ext/strophe_ruby.c', line 456
static VALUE t_xmpp_stanza_get_next(VALUE self) {
xmpp_stanza_t *stanza;
xmpp_stanza_t *next;
Data_Get_Struct(self, xmpp_stanza_t, stanza);
next = xmpp_stanza_get_next(stanza);
VALUE tdata = Data_Wrap_Struct(cStanza, 0, t_xmpp_stanza_release, next);
return tdata;
}
|
#ns ⇒ Object
Get the namespace of a stanza TODO: Test this!
477 478 479 480 481 482 483 |
# File 'ext/strophe_ruby.c', line 477 static VALUE t_xmpp_stanza_get_ns(VALUE self) { xmpp_stanza_t *stanza; Data_Get_Struct(self, xmpp_stanza_t, stanza); char *ns = xmpp_stanza_get_ns(stanza); return rb_str_new2(ns); } |
#ns=(rb_ns) ⇒ Object
Set the namespace of a stanza. TODO:Test this!
542 543 544 545 546 547 548 549 550 |
# File 'ext/strophe_ruby.c', line 542
static VALUE t_xmpp_stanza_set_ns(VALUE self, VALUE rb_ns) {
xmpp_stanza_t *stanza;
Data_Get_Struct(self, xmpp_stanza_t, stanza);
char *ns = StringValuePtr(rb_ns);
xmpp_stanza_set_ns(stanza, ns);
return Qtrue;
}
|
#set_attribute(rb_attribute, rb_val) ⇒ Object
Set the value of a stanza attribute (eg. stanza.set_attribute(“to”,“[email protected]”)
530 531 532 533 534 535 536 537 538 539 |
# File 'ext/strophe_ruby.c', line 530
static VALUE t_xmpp_stanza_set_attribute(VALUE self, VALUE rb_attribute, VALUE rb_val) {
xmpp_stanza_t *stanza;
Data_Get_Struct(self, xmpp_stanza_t, stanza);
char *attribute = StringValuePtr(rb_attribute);
char *val = StringValuePtr(rb_val);
xmpp_stanza_set_attribute(stanza, attribute, val);
return Qtrue;
}
|
#text ⇒ Object
Get the text of a stanza.
486 487 488 489 490 491 492 493 494 495 496 |
# File 'ext/strophe_ruby.c', line 486
static VALUE t_xmpp_stanza_get_text(VALUE self) {
xmpp_stanza_t *stanza;
Data_Get_Struct(self, xmpp_stanza_t, stanza);
char *text = xmpp_stanza_get_text(stanza);
if(text)
return rb_str_new2(text);
else
return rb_str_new2("");
}
|
#text=(rb_text) ⇒ Object
Set the text of a stanza
567 568 569 570 571 572 573 574 575 |
# File 'ext/strophe_ruby.c', line 567
static VALUE t_xmpp_stanza_set_text(VALUE self, VALUE rb_text) {
xmpp_stanza_t *stanza;
Data_Get_Struct(self, xmpp_stanza_t, stanza);
char *text = StringValuePtr(rb_text);
xmpp_stanza_set_text(stanza, text);
return rb_text;
}
|
#to_s ⇒ Object
Convert Stanza to String
553 554 555 556 557 558 559 560 561 562 563 564 |
# File 'ext/strophe_ruby.c', line 553
static VALUE t_xmpp_stanza_to_text(VALUE self) {
xmpp_stanza_t *stanza;
Data_Get_Struct(self, xmpp_stanza_t, stanza);
char* buffer;
size_t len;
xmpp_stanza_to_text(stanza, &buffer, &len);
if (NULL == buffer)
return rb_str_new(0, 0);
else
return rb_str_buf_new2(buffer);
}
|
#type ⇒ Object
Get the type of a stanza. For example, if the name is ‘message’, type can be ‘chat’, ‘normal’ and so on
508 509 510 511 512 513 514 515 516 517 518 |
# File 'ext/strophe_ruby.c', line 508
static VALUE t_xmpp_stanza_get_type(VALUE self) {
xmpp_stanza_t *stanza;
Data_Get_Struct(self, xmpp_stanza_t, stanza);
char *type = xmpp_stanza_get_type(stanza);
if(type)
return rb_str_new2(type);
else
return Qnil;
}
|
#type=(rb_type) ⇒ Object
Set the type of a stanza. For example if the name is ‘message’, the type can be ‘chat’, ‘normal’ and so on
589 590 591 592 593 594 595 596 597 |
# File 'ext/strophe_ruby.c', line 589
static VALUE t_xmpp_stanza_set_type(VALUE self, VALUE rb_type) {
xmpp_stanza_t *stanza;
Data_Get_Struct(self, xmpp_stanza_t, stanza);
char *type = StringValuePtr(rb_type);
xmpp_stanza_set_type(stanza, type);
return Qtrue;
}
|