Commit 3d9d616a authored by Richard Bayerle's avatar Richard Bayerle
Browse files

Add 'enable' for 'IM's to API

In libpurple-speak, 'IM' is a conversation just between two people.
parent 88f3821c
......@@ -2,13 +2,14 @@
#include <glib.h>
#include <purple.h>
#include "jabber.h"
#include "axc.h"
#include "libomemo.h"
#include "libomemo_storage.h"
#include "lurch_util.h"
#define MODULE_NAME "lurch-api"
void lurch_api_id_show_handler(PurpleAccount * acc_p, void (*cb)(int32_t err, uint32_t id, void * user_data_p), void * user_data_p) {
int ret_val = 0;
int32_t err = 0;
......@@ -20,14 +21,14 @@ void lurch_api_id_show_handler(PurpleAccount * acc_p, void (*cb)(int32_t err, ui
ret_val = lurch_util_axc_get_init_ctx(uname, &axc_ctx_p);
if (ret_val) {
purple_debug_error("lurch-api", "Failed to create axc ctx.\n");
purple_debug_error(MODULE_NAME, "Failed to create axc ctx.\n");
err = ret_val;
goto cleanup;
}
ret_val = axc_get_device_id(axc_ctx_p, &id);
if (ret_val) {
purple_debug_error("lurch-api", "Failed to access axc db %s. Does the path seem correct?", axc_context_get_db_fn(axc_ctx_p));
purple_debug_error(MODULE_NAME, "Failed to access axc db %s. Does the path seem correct?", axc_context_get_db_fn(axc_ctx_p));
err = ret_val;
goto cleanup;
}
......@@ -51,10 +52,14 @@ void lurch_api_id_list_handler(PurpleAccount * acc_p, void (*cb)(int32_t err, GL
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);
purple_debug_error(MODULE_NAME, "Failed to access OMEMO DB %s.", db_fn_omemo);
}
cb(ret_val, omemo_devicelist_get_id_list(dl_p), user_data_p);
id_list = omemo_devicelist_get_id_list(dl_p);
//TODO: somehow make clear which is the own ID, maybe sort the list so that the own ID is always the first?
cb(ret_val, id_list, user_data_p);
g_free(uname);
g_free(db_fn_omemo);
......@@ -62,6 +67,28 @@ void lurch_api_id_list_handler(PurpleAccount * acc_p, void (*cb)(int32_t err, GL
g_list_free_full(id_list, free);
}
void lurch_api_enable_im_handler(PurpleAccount * acc_p, const char * contact_bare_jid, void (*cb)(int32_t err, void * user_data_p), void * user_data_p) {
int32_t ret_val = 0;
char * uname = (void *) 0;
char * db_fn_omemo = (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_chatlist_delete(contact_bare_jid, db_fn_omemo);
if (ret_val) {
purple_debug_error(MODULE_NAME, "Failed to delete %s from the blacklist in OMEMO DB %s.", contact_bare_jid, db_fn_omemo);
}
cb(ret_val, user_data_p);
g_free(uname);
g_free(db_fn_omemo);
}
// const char * signals[2] = {"lurch-id-show", "lurch-id-list"};
// const void * handlers[2] = {lurch_api_id_show_handler, lurch_api_id_list_handler};
void lurch_api_init() {
void * plugins_handle_p = purple_plugins_get_handle();
......@@ -82,7 +109,19 @@ void lurch_api_init() {
purple_marshal_VOID__POINTER_POINTER_POINTER,
NULL,
3,
purple_value_new (PURPLE_TYPE_SUBTYPE, PURPLE_SUBTYPE_ACCOUNT),
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-enable-im",
purple_marshal_VOID__POINTER_POINTER_POINTER_POINTER,
NULL,
4,
purple_value_new(PURPLE_TYPE_SUBTYPE, PURPLE_SUBTYPE_ACCOUNT),
purple_value_new(PURPLE_TYPE_STRING),
purple_value_new(PURPLE_TYPE_POINTER),
purple_value_new(PURPLE_TYPE_POINTER)
);
......@@ -90,7 +129,7 @@ void lurch_api_init() {
purple_signal_connect(
plugins_handle_p,
"lurch-id-show",
"lurch-api",
MODULE_NAME,
PURPLE_CALLBACK(lurch_api_id_show_handler),
NULL
);
......@@ -98,28 +137,45 @@ void lurch_api_init() {
purple_signal_connect(
plugins_handle_p,
"lurch-id-list",
"lurch-api",
MODULE_NAME,
PURPLE_CALLBACK(lurch_api_id_list_handler),
NULL
);
purple_signal_connect(
plugins_handle_p,
"lurch-enable-im",
MODULE_NAME,
PURPLE_CALLBACK(lurch_api_enable_im_handler),
NULL
);
}
void lurch_api_unload() {
void * plugins_handle_p = purple_plugins_get_handle();
purple_signal_disconnect(
purple_plugins_get_handle(),
plugins_handle_p,
"lurch-id-show",
"lurch-api",
MODULE_NAME,
PURPLE_CALLBACK(lurch_api_id_show_handler)
);
purple_signal_disconnect(
purple_plugins_get_handle(),
plugins_handle_p,
"lurch-id-list",
"lurch-api",
MODULE_NAME,
PURPLE_CALLBACK(lurch_api_id_list_handler)
);
purple_signal_disconnect(
plugins_handle_p,
"lurch-enable-im",
MODULE_NAME,
PURPLE_CALLBACK(lurch_api_enable_im_handler)
);
purple_signal_unregister(purple_plugins_get_handle(), "lurch-id-show");
purple_signal_unregister(purple_plugins_get_handle(), "lurch-id-list");
purple_signal_unregister(purple_plugins_get_handle(), "lurch-enable-im");
}
\ No newline at end of file
......@@ -2,6 +2,8 @@
#include <glib.h>
#include <purple.h>
#include "jutil.h"
#include "libomemo.h"
static void lurch_cmd_print(PurpleConversation * conv_p, const char * msg) {
......@@ -76,29 +78,51 @@ void lurch_id_list_print(int32_t err, GList * id_list, void * user_data_p) {
g_free(temp_msg_1);
}
void lurch_enable_print(int32_t err, void * user_data_p) {
PurpleConversation * conv_p = (PurpleConversation *) user_data_p;
if (err) {
lurch_cmd_print_err(conv_p, "Failed to enable OMEMO for this conversation.");
return;
}
purple_conversation_autoset_title(conv_p);
lurch_cmd_print(conv_p, "Successfully enabled OMEMO.");
}
static void lurch_cmd_id(PurpleConversation * conv_p, const char * arg) {
char * msg = (void *) 0;
char * err_msg = (void *) 0;
PurpleAccount * acc_p = purple_conversation_get_account(conv_p);
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);
purple_signal_emit(purple_plugins_get_handle(), "lurch-id-show", acc_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);
purple_signal_emit(purple_plugins_get_handle(), "lurch-id-list", acc_p, lurch_id_list_print, conv_p);
} else {
msg = g_strdup("Valid arguments for 'id' are 'show' or 'list'.");
lurch_cmd_print(conv_p, "Valid arguments for 'id' are 'show' or 'list'.");
}
}
if (err_msg) {
lurch_cmd_print_err(conv_p, err_msg);
} else if (msg) {
lurch_cmd_print(conv_p, msg);
static void lurch_cmd_enable(PurpleConversation * conv_p) {
PurpleConversationType conv_type = purple_conversation_get_type(conv_p);
char * conv_bare_jid = jabber_get_bare_jid(purple_conversation_get_name(conv_p));
if (conv_type == PURPLE_CONV_TYPE_IM) {
purple_signal_emit(purple_plugins_get_handle(), "lurch-enable-im", purple_conversation_get_account(conv_p), conv_bare_jid, lurch_enable_print, conv_p);
}
free(msg);
free(err_msg);
g_free(conv_bare_jid);
}
typedef void (*LurchIdShowCallback)(uint32_t id, void * data_p);
static void lurch_cmd_disable(PurpleConversation * conv_p) {
PurpleConversationType conv_type = purple_conversation_get_type(conv_p);
char * conv_bare_jid = jabber_get_bare_jid(purple_conversation_get_name(conv_p));
if (conv_type == PURPLE_CONV_TYPE_IM) {
}
g_free(conv_bare_jid);
}
PurpleCmdRet lurch_cmd_func_v2(PurpleConversation * conv_p,
const gchar * cmd,
......@@ -109,6 +133,9 @@ PurpleCmdRet lurch_cmd_func_v2(PurpleConversation * conv_p,
if (!g_strcmp0(command, "help")) {
lurch_cmd_help(conv_p);
} else if (!g_strcmp0(command, "enable")) {
lurch_cmd_enable(conv_p);
} else if (!g_strcmp0(command, "disable")) {
} else if (!g_strcmp0(command, "id")) {
lurch_cmd_id(conv_p, args[1]);
} else {
......
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