From b8e0a9d70cd8709055bdda209a19a92c6ef6e2c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Pettersson?= Date: Mon, 8 Sep 2014 03:01:29 +0200 Subject: [PATCH] Fixed identity initialization. --- src/tox-weechat-tox.c | 33 ++++++++++++--------------------- src/tox-weechat-tox.h | 3 ++- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/src/tox-weechat-tox.c b/src/tox-weechat-tox.c index 514059e..476e3ff 100644 --- a/src/tox-weechat-tox.c +++ b/src/tox-weechat-tox.c @@ -285,13 +285,7 @@ tox_weechat_bootstrap(char *address, uint16_t port, char *public_key) void tox_weechat_tox_init() { - struct t_tox_weechat_identity *identity = malloc(sizeof(*identity)); - identity->name = strdup("tox"); - identity->data_path = tox_weechat_default_data_path("tox"); - - tox_weechat_init_identity(identity); - - tox_weechat_identities = identity; + tox_weechat_identity_new("tox"); } struct t_tox_weechat_identity * @@ -299,12 +293,21 @@ tox_weechat_identity_new(const char *name) { struct t_tox_weechat_identity *identity = malloc(sizeof(*identity)); identity->name = strdup(name); + identity->data_path = tox_weechat_default_data_path("tox"); // TODO: add close callback identity->buffer = weechat_buffer_new(identity->name, NULL, NULL, NULL, NULL); identity->tox = tox_new(NULL); + // try loading Tox saved data + if (tox_weechat_load_file(identity->tox, identity->data_path) == -1) + { + // couldn't load Tox, set a default name + tox_set_name(identity->tox, + (uint8_t *)INITIAL_NAME, strlen(INITIAL_NAME)); + } + identity->prev_identity= tox_weechat_last_identity; identity->next_identity = NULL; @@ -315,20 +318,6 @@ tox_weechat_identity_new(const char *name) tox_weechat_last_identity = identity; - return identity; -} - -void -tox_weechat_init_identity(struct t_tox_weechat_identity *identity) -{ - // try loading Tox saved data - if (tox_weechat_load_file(identity->tox, identity->data_path) == -1) - { - // couldn't load Tox, set a default name - tox_set_name(identity->tox, - (uint8_t *)INITIAL_NAME, strlen(INITIAL_NAME)); - } - // bootstrap DHT tox_weechat_bootstrap_tox(identity->tox, BOOTSTRAP_ADDRESS, BOOTSTRAP_PORT, @@ -345,6 +334,8 @@ tox_weechat_init_identity(struct t_tox_weechat_identity *identity) tox_callback_user_status(identity->tox, tox_weechat_user_status_callback, identity); tox_callback_status_message(identity->tox, tox_weechat_status_message_callback, identity); tox_callback_friend_request(identity->tox, tox_weechat_callback_friend_request, identity); + + return identity; } struct t_tox_weechat_identity * diff --git a/src/tox-weechat-tox.h b/src/tox-weechat-tox.h index de552ae..a97bae3 100644 --- a/src/tox-weechat-tox.h +++ b/src/tox-weechat-tox.h @@ -36,7 +36,8 @@ void tox_weechat_tox_init(); struct t_tox_weechat_identity *tox_weechat_identity_for_buffer(struct t_gui_buffer *buffer); -void tox_weechat_init_identity(struct t_tox_weechat_identity *identity); +struct t_tox_weechat_identity * +tox_weechat_identity_new(const char *name); /** * Bootstrap DHT using an inet address, port and a Tox address.