Commit 88f3821c authored by Richard Bayerle's avatar Richard Bayerle
Browse files

Add devicelist getter to API.

parent f5c648d2
......@@ -2609,7 +2609,7 @@ cleanup:
static gboolean lurch_plugin_unload(PurplePlugin * plugin_p) {
purple_cmd_unregister(lurch_cmd_handle_id);
//TODO: disconnect all signal handlers
lurch_api_unload();
omemo_default_crypto_teardown();
......
#include <inttypes.h>
#include <glib.h>
#include <purple.h>
#include "jabber.h"
#include "axc.h"
#include "libomemo.h"
#include "libomemo_storage.h"
#include "lurch_util.h"
......@@ -36,23 +39,87 @@ cleanup:
g_free(uname);
}
void lurch_api_id_list_handler(PurpleAccount * acc_p, void (*cb)(int32_t err, GList * id_list, void * user_data_p), void * user_data_p) {
int32_t ret_val = 0;
char * uname = (void *) 0;
char * db_fn_omemo = (void *) 0;
omemo_devicelist * dl_p = (void *) 0;
GList * id_list = (void *) 0;
uname = lurch_util_uname_strip(purple_account_get_username(acc_p));
db_fn_omemo = lurch_util_uname_get_db_fn(uname, LURCH_DB_NAME_OMEMO);
ret_val = omemo_storage_user_devicelist_retrieve(uname, db_fn_omemo, &dl_p);
if (ret_val) {
purple_debug_error("Failed to access omemo db %s.", db_fn_omemo);
}
cb(ret_val, omemo_devicelist_get_id_list(dl_p), user_data_p);
g_free(uname);
g_free(db_fn_omemo);
omemo_devicelist_destroy(dl_p);
g_list_free_full(id_list, free);
}
void lurch_api_init() {
purple_signal_register(
purple_plugins_get_handle(),
"lurch-id-show",
purple_marshal_VOID__POINTER_POINTER_POINTER,
NULL,
3,
purple_value_new(PURPLE_TYPE_SUBTYPE, PURPLE_SUBTYPE_ACCOUNT),
purple_value_new(PURPLE_TYPE_POINTER),
purple_value_new(PURPLE_TYPE_POINTER)
);
purple_signal_connect(
purple_plugins_get_handle(),
"lurch-id-show",
"lurch-api",
PURPLE_CALLBACK(lurch_api_id_show_handler),
NULL
);
void * plugins_handle_p = purple_plugins_get_handle();
purple_signal_register(
plugins_handle_p,
"lurch-id-show",
purple_marshal_VOID__POINTER_POINTER_POINTER,
NULL,
3,
purple_value_new(PURPLE_TYPE_SUBTYPE, PURPLE_SUBTYPE_ACCOUNT),
purple_value_new(PURPLE_TYPE_POINTER),
purple_value_new(PURPLE_TYPE_POINTER)
);
purple_signal_register(
plugins_handle_p,
"lurch-id-list",
purple_marshal_VOID__POINTER_POINTER_POINTER,
NULL,
3,
purple_value_new (PURPLE_TYPE_SUBTYPE, PURPLE_SUBTYPE_ACCOUNT),
purple_value_new(PURPLE_TYPE_POINTER),
purple_value_new(PURPLE_TYPE_POINTER)
);
purple_signal_connect(
plugins_handle_p,
"lurch-id-show",
"lurch-api",
PURPLE_CALLBACK(lurch_api_id_show_handler),
NULL
);
purple_signal_connect(
plugins_handle_p,
"lurch-id-list",
"lurch-api",
PURPLE_CALLBACK(lurch_api_id_list_handler),
NULL
);
}
void lurch_api_unload() {
purple_signal_disconnect(
purple_plugins_get_handle(),
"lurch-id-show",
"lurch-api",
PURPLE_CALLBACK(lurch_api_id_show_handler)
);
purple_signal_disconnect(
purple_plugins_get_handle(),
"lurch-id-list",
"lurch-api",
PURPLE_CALLBACK(lurch_api_id_list_handler)
);
purple_signal_unregister(purple_plugins_get_handle(), "lurch-id-show");
purple_signal_unregister(purple_plugins_get_handle(), "lurch-id-list");
}
\ No newline at end of file
......@@ -5,4 +5,7 @@
*/
void lurch_api_init();
//TODO: unregister everything
\ No newline at end of file
/**
* Unregisters the signals and disconnects the signal handlers.
*/
void lurch_api_unload();
\ No newline at end of file
......@@ -2,6 +2,8 @@
#include <glib.h>
#include <purple.h>
#include "libomemo.h"
static void lurch_cmd_print(PurpleConversation * conv_p, const char * msg) {
purple_conversation_write(conv_p, "lurch", msg, PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG, time((void *) 0));
}
......@@ -30,11 +32,48 @@ static void lurch_cmd_help(PurpleConversation * conv_p) {
void lurch_id_show_print(int32_t err, uint32_t id, void * user_data_p) {
PurpleConversation * conv_p = (PurpleConversation *) user_data_p;
char * msg = (void *) 0;
if (err) {
lurch_cmd_print(conv_p, "An error occured when trying to retrieve this device's ID. Check the debug log for details.");
} else {
lurch_cmd_print(conv_p, g_strdup_printf("id from callback is %i", id));
lurch_cmd_print_err(conv_p, "An error occured when trying to retrieve this device's ID. Check the debug log for details.");
return;
}
msg = g_strdup_printf("This device's ID is %i", id);
lurch_cmd_print(conv_p, msg);
g_free(msg);
}
void lurch_id_list_print(int32_t err, GList * id_list, void * user_data_p) {
PurpleConversation * conv_p = (PurpleConversation *) user_data_p;
char * temp_msg_1 = g_strdup("Your devicelist is:\n");
char * temp_msg_2 = (void *) 0;
char * temp_msg_3 = (void *) 0;
GList * curr_p = (void *) 0;
if (err) {
lurch_cmd_print_err(conv_p, "An error occured when trying to retrieve your ID list. Check the debug log for details.");
return;
}
for (curr_p = id_list; curr_p; curr_p = curr_p->next) {
temp_msg_2 = g_strdup_printf("%i\n", omemo_devicelist_list_data(curr_p));
temp_msg_3 = g_strconcat(temp_msg_1, temp_msg_2, NULL);
g_free(temp_msg_1);
temp_msg_1 = temp_msg_3;
g_free(temp_msg_2);
temp_msg_2 = (void *) 0;
temp_msg_3 = (void *) 0;
}
lurch_cmd_print(conv_p, temp_msg_1);
g_free(temp_msg_1);
}
static void lurch_cmd_id(PurpleConversation * conv_p, const char * arg) {
......@@ -43,8 +82,10 @@ static void lurch_cmd_id(PurpleConversation * conv_p, const char * arg) {
if (!g_strcmp0(arg, "show")) {
purple_signal_emit(purple_plugins_get_handle(), "lurch-id-show", purple_conversation_get_account(conv_p), lurch_id_show_print, conv_p);
} else if (!g_strcmp0(arg, "list")) {
purple_signal_emit(purple_plugins_get_handle(), "lurch-id-list", purple_conversation_get_account(conv_p), lurch_id_list_print, conv_p);
} else {
msg = g_strdup("Valid argument for 'id' is 'show'.");
msg = g_strdup("Valid arguments for 'id' are 'show' or 'list'.");
}
if (err_msg) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment