Archived
1
0
Fork 0

Implement Tox#id

This commit is contained in:
Braiden Vasco 2015-09-12 16:16:30 +00:00
parent e14be05aa0
commit 6d0c675377
2 changed files with 22 additions and 0 deletions

View file

@ -9,5 +9,6 @@ have_library LIBTOXCORE, 'tox_options_default'
have_library LIBTOXCORE, 'tox_new' have_library LIBTOXCORE, 'tox_new'
have_library LIBTOXCORE, 'tox_get_savedata_size' have_library LIBTOXCORE, 'tox_get_savedata_size'
have_library LIBTOXCORE, 'tox_get_savedata' have_library LIBTOXCORE, 'tox_get_savedata'
have_library LIBTOXCORE, 'tox_self_get_address'
create_makefile "#{NAME}/#{NAME}" create_makefile "#{NAME}/#{NAME}"

View file

@ -13,6 +13,7 @@ static VALUE cTox_alloc(VALUE klass);
static void cTox_free(void *ptr); static void cTox_free(void *ptr);
static VALUE cTox_initialize(VALUE self, VALUE options); static VALUE cTox_initialize(VALUE self, VALUE options);
static VALUE cTox_savedata(VALUE self); static VALUE cTox_savedata(VALUE self);
static VALUE cTox_id(VALUE self);
typedef struct Tox_Options cTox_cOptions_; typedef struct Tox_Options cTox_cOptions_;
@ -28,6 +29,7 @@ void Init_tox()
rb_define_alloc_func(cTox, cTox_alloc); rb_define_alloc_func(cTox, cTox_alloc);
rb_define_method(cTox, "initialize", cTox_initialize, 1); rb_define_method(cTox, "initialize", cTox_initialize, 1);
rb_define_method(cTox, "savedata", cTox_savedata, 0); rb_define_method(cTox, "savedata", cTox_savedata, 0);
rb_define_method(cTox, "id", cTox_id, 0);
cTox_cOptions = rb_define_class_under(cTox, "Options", rb_cObject); cTox_cOptions = rb_define_class_under(cTox, "Options", rb_cObject);
rb_define_alloc_func(cTox_cOptions, cTox_cOptions_alloc); rb_define_alloc_func(cTox_cOptions, cTox_cOptions_alloc);
@ -92,6 +94,25 @@ VALUE cTox_savedata(const VALUE self)
return rb_str_new(data, data_size); return rb_str_new(data, data_size);
} }
VALUE cTox_id(const VALUE self)
{
cTox_ *tox;
char address[TOX_ADDRESS_SIZE];
char id[2 * TOX_ADDRESS_SIZE];
unsigned long i;
Data_Get_Struct(self, cTox_, tox);
tox_self_get_address(tox->tox, (uint8_t*)address);
for (i = 0; i < TOX_ADDRESS_SIZE; ++i)
sprintf(&id[2 * i], "%02X", address[i] & 0xFF);
return rb_str_new(id, 2 * TOX_ADDRESS_SIZE);
}
/****************************************************************************** /******************************************************************************
* Tox::Options * Tox::Options
******************************************************************************/ ******************************************************************************/