Commit ed3af540 authored by Richard Bayerle's avatar Richard Bayerle
Browse files

Add 'disable' for chats to API

parent e98b2199
......@@ -204,6 +204,24 @@ void lurch_api_enable_chat_handler(PurpleAccount * acc_p, const char * full_conv
g_free(db_fn_omemo);
}
void lurch_api_disable_chat_handler(PurpleAccount * acc_p, const char * full_conversation_name, 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(full_conversation_name, db_fn_omemo);
if (ret_val) {
purple_debug_error(MODULE_NAME, "Failed to disable OMEMO for chat %s using DB %s.\n", full_conversation_name, db_fn_omemo);
}
cb(ret_val, user_data_p);
g_free(uname);
g_free(db_fn_omemo);
}
void lurch_api_fp_get_handler(PurpleAccount * acc_p, void (*cb)(int32_t err, const char * fp_printable, void * user_data_p), void * user_data_p) {
int32_t ret_val = 0;
......@@ -462,7 +480,7 @@ typedef enum {
* When adding a new signal: increase this number and add the name, handler function, and handler function type
* to the respective array.
*/
#define NUM_OF_SIGNALS 9
#define NUM_OF_SIGNALS 10
const char * signal_names[NUM_OF_SIGNALS] = {
"lurch-id-list",
......@@ -470,6 +488,7 @@ const char * signal_names[NUM_OF_SIGNALS] = {
"lurch-enable-im",
"lurch-disable-im",
"lurch-enable-chat",
"lurch-disable-chat",
"lurch-fp-get",
"lurch-fp-list",
"lurch-fp-other",
......@@ -482,6 +501,7 @@ const void * signal_handlers[NUM_OF_SIGNALS] = {
lurch_api_enable_im_handler,
lurch_api_disable_im_handler,
lurch_api_enable_chat_handler,
lurch_api_disable_chat_handler,
lurch_api_fp_get_handler,
lurch_api_fp_list_handler,
lurch_api_fp_other_handler,
......@@ -494,6 +514,7 @@ const lurch_api_handler_t signal_handler_types[NUM_OF_SIGNALS] = {
LURCH_API_HANDLER_ACC_JID_CB_DATA,
LURCH_API_HANDLER_ACC_JID_CB_DATA,
LURCH_API_HANDLER_ACC_JID_CB_DATA,
LURCH_API_HANDLER_ACC_JID_CB_DATA,
LURCH_API_HANDLER_ACC_CB_DATA,
LURCH_API_HANDLER_ACC_CB_DATA,
LURCH_API_HANDLER_ACC_JID_CB_DATA,
......
......@@ -81,6 +81,13 @@ void lurch_api_disable_im_handler(PurpleAccount * acc_p, const char * contact_ba
*/
void lurch_api_enable_chat_handler(PurpleAccount * acc_p, const char * full_conversation_name, void (*cb)(int32_t err, void * user_data_p), void * user_data_p);
/**
* SIGNAL: lurch-disable-chat
*
* Disables OMEMO for the specified chat.
*/
void lurch_api_disable_chat_handler(PurpleAccount * acc_p, const char * full_conversation_name, void (*cb)(int32_t err, void * user_data_p), void * user_data_p);
/**
* SIGNAL: lurch-fp-get
*
......
......@@ -200,30 +200,42 @@ static void lurch_cmd_enable(PurpleConversation * conv_p) {
const char * conv_name = purple_conversation_get_name(conv_p);
switch (conv_type) {
case PURPLE_CONV_TYPE_IM:
bare_jid = jabber_get_bare_jid(conv_name);
purple_signal_emit(plugins_handle, "lurch-enable-im", acc_p, bare_jid, lurch_enable_print, conv_p);
break;
case PURPLE_CONV_TYPE_CHAT:
purple_signal_emit(plugins_handle, "lurch-enable-chat", acc_p, conv_name, lurch_enable_print, conv_p);
break;
default:
lurch_cmd_print_err(conv_p, "Conversation type not supported.");
break;
case PURPLE_CONV_TYPE_IM:
bare_jid = jabber_get_bare_jid(conv_name);
purple_signal_emit(plugins_handle, "lurch-enable-im", acc_p, bare_jid, lurch_enable_print, conv_p);
break;
case PURPLE_CONV_TYPE_CHAT:
purple_signal_emit(plugins_handle, "lurch-enable-chat", acc_p, conv_name, lurch_enable_print, conv_p);
break;
default:
lurch_cmd_print_err(conv_p, "Conversation type not supported.");
break;
}
g_free(bare_jid);
}
static void lurch_cmd_disable(PurpleConversation * conv_p) {
char * bare_jid = (void *) 0;
void * plugins_handle = purple_plugins_get_handle();
PurpleConversationType conv_type = purple_conversation_get_type(conv_p);
char * conv_bare_jid = jabber_get_bare_jid(purple_conversation_get_name(conv_p));
PurpleAccount * acc_p = purple_conversation_get_account(conv_p);
const char * conv_name = purple_conversation_get_name(conv_p);
if (conv_type == PURPLE_CONV_TYPE_IM) {
purple_signal_emit(purple_plugins_get_handle(), "lurch-disable-im", purple_conversation_get_account(conv_p), conv_bare_jid, lurch_disable_print, conv_p);
switch (conv_type) {
case PURPLE_CONV_TYPE_IM:
bare_jid = jabber_get_bare_jid(conv_name);
purple_signal_emit(plugins_handle, "lurch-disable-im", acc_p, bare_jid, lurch_disable_print, conv_p);
break;
case PURPLE_CONV_TYPE_CHAT:
purple_signal_emit(plugins_handle, "lurch-disable-chat", acc_p, conv_name, lurch_disable_print, conv_p);
break;
default:
lurch_cmd_print_err(conv_p, "Conversation type not supported.");
break;
}
g_free(conv_bare_jid);
g_free(bare_jid);
}
static void lurch_cmd_fp(PurpleConversation * conv_p, const char * arg) {
......
......@@ -289,7 +289,7 @@ static void test_lurch_api_id_remove_handler_id_not_in_list(void ** state) {
lurch_api_id_remove_handler((void *) "ignored", 7331, lurch_api_id_remove_handler_cb_mock, test_user_data);
}
static void lurch_api_enable_handler_cb_mock(int32_t err, void * user_data_p) {
static void lurch_api_enable_disable_handler_cb_mock(int32_t err, void * user_data_p) {
check_expected(err);
check_expected(user_data_p);
}
......@@ -308,10 +308,10 @@ static void test_lurch_api_enable_im_handler(void ** state) {
will_return(__wrap_omemo_storage_chatlist_delete, EXIT_SUCCESS);
char * test_user_data = "TEST USER DATA";
expect_value(lurch_api_enable_handler_cb_mock, err, EXIT_SUCCESS);
expect_value(lurch_api_enable_handler_cb_mock, user_data_p, test_user_data);
expect_value(lurch_api_enable_disable_handler_cb_mock, err, EXIT_SUCCESS);
expect_value(lurch_api_enable_disable_handler_cb_mock, user_data_p, test_user_data);
lurch_api_enable_im_handler((void *) "ignored", contact_bare_jid, lurch_api_enable_handler_cb_mock, test_user_data);
lurch_api_enable_im_handler((void *) "ignored", contact_bare_jid, lurch_api_enable_disable_handler_cb_mock, test_user_data);
}
/**
......@@ -328,10 +328,10 @@ static void test_lurch_api_enable_im_handler_err(void ** state) {
will_return(__wrap_omemo_storage_chatlist_delete, EXIT_FAILURE);
char * test_user_data = "TEST USER DATA";
expect_value(lurch_api_enable_handler_cb_mock, err, EXIT_FAILURE);
expect_value(lurch_api_enable_handler_cb_mock, user_data_p, test_user_data);
expect_value(lurch_api_enable_disable_handler_cb_mock, err, EXIT_FAILURE);
expect_value(lurch_api_enable_disable_handler_cb_mock, user_data_p, test_user_data);
lurch_api_enable_im_handler((void *) "ignored", contact_bare_jid, lurch_api_enable_handler_cb_mock, test_user_data);
lurch_api_enable_im_handler((void *) "ignored", contact_bare_jid, lurch_api_enable_disable_handler_cb_mock, test_user_data);
}
/**
......@@ -348,10 +348,10 @@ static void test_lurch_api_enable_chat_handler(void ** state) {
will_return(__wrap_omemo_storage_chatlist_save, EXIT_SUCCESS);
char * test_user_data = "TEST USER DATA";
expect_value(lurch_api_enable_handler_cb_mock, err, EXIT_SUCCESS);
expect_value(lurch_api_enable_handler_cb_mock, user_data_p, test_user_data);
expect_value(lurch_api_enable_disable_handler_cb_mock, err, EXIT_SUCCESS);
expect_value(lurch_api_enable_disable_handler_cb_mock, user_data_p, test_user_data);
lurch_api_enable_chat_handler((void *) "ignored", conv_name, lurch_api_enable_handler_cb_mock, test_user_data);
lurch_api_enable_chat_handler((void *) "ignored", conv_name, lurch_api_enable_disable_handler_cb_mock, test_user_data);
}
/**
......@@ -368,15 +368,10 @@ static void test_lurch_api_enable_chat_handler_err(void ** state) {
will_return(__wrap_omemo_storage_chatlist_save, EXIT_FAILURE);
char * test_user_data = "TEST USER DATA";
expect_value(lurch_api_enable_handler_cb_mock, err, EXIT_FAILURE);
expect_value(lurch_api_enable_handler_cb_mock, user_data_p, test_user_data);
expect_value(lurch_api_enable_disable_handler_cb_mock, err, EXIT_FAILURE);
expect_value(lurch_api_enable_disable_handler_cb_mock, user_data_p, test_user_data);
lurch_api_enable_chat_handler((void *) "ignored", conv_name, lurch_api_enable_handler_cb_mock, test_user_data);
}
static void lurch_api_disable_im_handler_cb_mock(int32_t err, void * user_data_p) {
check_expected(err);
check_expected(user_data_p);
lurch_api_enable_chat_handler((void *) "ignored", conv_name, lurch_api_enable_disable_handler_cb_mock, test_user_data);
}
/**
......@@ -393,10 +388,10 @@ static void test_lurch_api_disable_im_handler(void ** state) {
will_return(__wrap_omemo_storage_chatlist_save, EXIT_SUCCESS);
char * test_user_data = "TEST USER DATA";
expect_value(lurch_api_disable_im_handler_cb_mock, err, EXIT_SUCCESS);
expect_value(lurch_api_disable_im_handler_cb_mock, user_data_p, test_user_data);
expect_value(lurch_api_enable_disable_handler_cb_mock, err, EXIT_SUCCESS);
expect_value(lurch_api_enable_disable_handler_cb_mock, user_data_p, test_user_data);
lurch_api_disable_im_handler((void *) "ignored", contact_bare_jid, lurch_api_disable_im_handler_cb_mock, test_user_data);
lurch_api_disable_im_handler((void *) "ignored", contact_bare_jid, lurch_api_enable_disable_handler_cb_mock, test_user_data);
}
/**
......@@ -413,10 +408,50 @@ static void test_lurch_api_disable_im_handler_err(void ** state) {
will_return(__wrap_omemo_storage_chatlist_save, 12345);
char * test_user_data = "TEST USER DATA";
expect_value(lurch_api_disable_im_handler_cb_mock, err, 12345);
expect_value(lurch_api_disable_im_handler_cb_mock, user_data_p, test_user_data);
expect_value(lurch_api_enable_disable_handler_cb_mock, err, 12345);
expect_value(lurch_api_enable_disable_handler_cb_mock, user_data_p, test_user_data);
lurch_api_disable_im_handler((void *) "ignored", contact_bare_jid, lurch_api_enable_disable_handler_cb_mock, test_user_data);
}
/**
* Removes the specified conversation name from 'the list' to disable OMEMO for it.
*/
static void test_lurch_api_disable_chat_handler(void ** state) {
(void) state;
const char * conv_name = "conversation name";
const char * user_jid = "me-testing@test.org/resource";
will_return(__wrap_purple_account_get_username, user_jid);
expect_string(__wrap_omemo_storage_chatlist_delete, chat, conv_name);
will_return(__wrap_omemo_storage_chatlist_delete, EXIT_SUCCESS);
char * test_user_data = "TEST USER DATA";
expect_value(lurch_api_enable_disable_handler_cb_mock, err, EXIT_SUCCESS);
expect_value(lurch_api_enable_disable_handler_cb_mock, user_data_p, test_user_data);
lurch_api_disable_chat_handler((void *) "ignoed", conv_name, lurch_api_enable_disable_handler_cb_mock, test_user_data);
}
/**
* Calls the callback with a non-zero return value as well.
*/
static void test_lurch_api_disable_chat_handler_err(void ** state) {
(void) state;
const char * conv_name = "conversation name";
const char * user_jid = "me-testing@test.org/resource";
will_return(__wrap_purple_account_get_username, user_jid);
expect_string(__wrap_omemo_storage_chatlist_delete, chat, conv_name);
will_return(__wrap_omemo_storage_chatlist_delete, EXIT_FAILURE);
char * test_user_data = "TEST USER DATA";
expect_value(lurch_api_enable_disable_handler_cb_mock, err, EXIT_FAILURE);
expect_value(lurch_api_enable_disable_handler_cb_mock, user_data_p, test_user_data);
lurch_api_disable_im_handler((void *) "ignored", contact_bare_jid, lurch_api_disable_im_handler_cb_mock, test_user_data);
lurch_api_disable_chat_handler((void *) "ignoed", conv_name, lurch_api_enable_disable_handler_cb_mock, test_user_data);
}
void lurch_api_fp_get_handler_cb_mock(int32_t err, const char * fp_printable, void * user_data_p) {
......@@ -893,7 +928,7 @@ static void test_lurch_api_init(void ** state) {
(void) state;
// currently, there are 9 signals
size_t signals = 9;
size_t signals = 10;
for (int i = 0; i < signals; i++) {
expect_function_call(__wrap_purple_signal_register);
......@@ -909,7 +944,7 @@ static void test_lurch_api_init(void ** state) {
static void test_lurch_api_unload(void ** state) {
(void) state;
size_t signals = 9;
size_t signals = 10;
for (int i = 0; i < signals; i++) {
expect_function_call(__wrap_purple_signal_disconnect);
......@@ -931,6 +966,8 @@ int main(void) {
cmocka_unit_test(test_lurch_api_enable_chat_handler_err),
cmocka_unit_test(test_lurch_api_disable_im_handler),
cmocka_unit_test(test_lurch_api_disable_im_handler_err),
cmocka_unit_test(test_lurch_api_disable_chat_handler),
cmocka_unit_test(test_lurch_api_disable_chat_handler_err),
cmocka_unit_test(test_lurch_api_fp_get_handler),
cmocka_unit_test(test_lurch_api_fp_get_handler_err),
cmocka_unit_test(test_lurch_api_fp_list_handler),
......
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