diff --git a/ext/tox/extconf.rb b/ext/tox/extconf.rb index 541b667..3d4e464 100755 --- a/ext/tox/extconf.rb +++ b/ext/tox/extconf.rb @@ -36,5 +36,8 @@ have_library LIBTOXCORE, 'tox_group_peernumber_is_ours' and have_library LIBTOXCORE, 'tox_self_get_name_size' and have_library LIBTOXCORE, 'tox_self_get_name' and have_library LIBTOXCORE, 'tox_self_set_name' and +have_library LIBTOXCORE, 'tox_self_get_status_message_size' and +have_library LIBTOXCORE, 'tox_self_get_status_message' and +have_library LIBTOXCORE, 'tox_self_set_status_message' and create_makefile "#{NAME}/#{NAME}" or exit(1) diff --git a/ext/tox/tox.c b/ext/tox/tox.c index 5b63d9f..ea7bec1 100644 --- a/ext/tox/tox.c +++ b/ext/tox/tox.c @@ -45,6 +45,8 @@ static VALUE cTox_group_message_send(VALUE self, VALUE group_number, VALUE text) static VALUE cTox_group_peernumber_is_ours(VALUE self, VALUE group_number, VALUE peer_number); static VALUE cTox_name(VALUE self); static VALUE cTox_name_ASSIGN(VALUE self, VALUE name); +static VALUE cTox_status_message(VALUE self); +static VALUE cTox_status_message_ASSIGN(VALUE self, VALUE text); static void on_friend_request( Tox *tox, @@ -108,6 +110,8 @@ void Init_tox() rb_define_method(cTox, "group_peernumber_is_ours", cTox_group_peernumber_is_ours, 2); rb_define_method(cTox, "name", cTox_name, 0); rb_define_method(cTox, "name=", cTox_name_ASSIGN, 1); + rb_define_method(cTox, "status_message", cTox_status_message, 0); + rb_define_method(cTox, "status_message=", cTox_status_message_ASSIGN, 1); cTox_cOptions = rb_define_class_under(cTox, "Options", rb_cObject); rb_define_alloc_func(cTox_cOptions, cTox_cOptions_alloc); @@ -412,6 +416,42 @@ VALUE cTox_name_ASSIGN(const VALUE self, const VALUE name) return Qtrue; } +VALUE cTox_status_message(const VALUE self) +{ + cTox_ *tox; + + char text[TOX_MAX_STATUS_MESSAGE_LENGTH]; + size_t text_size; + + Data_Get_Struct(self, cTox_, tox); + + text_size = tox_self_get_status_message_size(tox->tox); + + if (text_size > 0) + tox_self_get_status_message(tox->tox, (uint8_t*)text); + + return rb_str_new(text, text_size); +} + +VALUE cTox_status_message_ASSIGN(const VALUE self, const VALUE text) +{ + cTox_ *tox; + + bool result; + TOX_ERR_SET_INFO error; + + Check_Type(text, T_STRING); + + Data_Get_Struct(self, cTox_, tox); + + result = tox_self_set_status_message(tox->tox, (uint8_t*)RSTRING_PTR(text), RSTRING_LEN(text), &error); + + if (error != TOX_ERR_SET_INFO_OK || !result) + return Qfalse; + else + return Qtrue; +} + void on_friend_request( Tox *const tox, const uint8_t *const key,