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

Change 'id list' to definitely return the own device ID first

Also remove the now superfluous 'id show' command
And clean up the 'status' output a bit
parent ccb3bac5
......@@ -39,10 +39,6 @@
#define LURCH_ACC_SETTING_INITIALIZED "lurch_initialised"
#define LURCH_ERR -1000000
#define LURCH_ERR_NOMEM -1000001
#define LURCH_ERR_NO_BUNDLE -1000010
#define LURCH_ERR_STRING_ENCRYPT "There was an error encrypting the message and it was not sent. " \
"You can try again, or try to find the problem by looking at the debug log."
#define LURCH_ERR_STRING_DECRYPT "There was an error decrypting an OMEMO message addressed to this device. " \
......
......@@ -13,58 +13,61 @@
#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) {
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;
axc_context * axc_ctx_p = (void *) 0;
uint32_t id = 0;
uint32_t own_id = 0;
GList * id_list = (void *) 0;
uint32_t * id_p = (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(MODULE_NAME, "Failed to access OMEMO DB %s.", db_fn_omemo);
goto cleanup;
}
ret_val = lurch_util_axc_get_init_ctx(uname, &axc_ctx_p);
if (ret_val) {
purple_debug_error(MODULE_NAME, "Failed to create axc ctx.\n");
purple_debug_error(MODULE_NAME, "Failed to create axc ctx.");
goto cleanup;
}
ret_val = axc_get_device_id(axc_ctx_p, &id);
ret_val = axc_get_device_id(axc_ctx_p, &own_id);
if (ret_val) {
purple_debug_error(MODULE_NAME, "Failed to access axc db %s. Does the path seem correct?", axc_context_get_db_fn(axc_ctx_p));
goto cleanup;
}
cleanup:
cb(ret_val, id, user_data_p);
axc_context_destroy_all(axc_ctx_p);
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);
ret_val = omemo_devicelist_remove(dl_p, own_id);
if (ret_val) {
purple_debug_error(MODULE_NAME, "Failed to access OMEMO DB %s.", db_fn_omemo);
purple_debug_error(MODULE_NAME, "Failed to remove the ID from the devicelist.");
goto cleanup;
}
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?
//TODO: then probably merge this with "id show", no one needs two of those
id_p = malloc(sizeof(uint32_t));
if (!id_p) {
ret_val = LURCH_ERR_NOMEM;
goto cleanup;
}
*id_p = own_id;
id_list = g_list_prepend(id_list, id_p);
cleanup:
cb(ret_val, id_list, user_data_p);
g_free(uname);
g_free(db_fn_omemo);
omemo_devicelist_destroy(dl_p);
axc_context_destroy_all(axc_ctx_p);
g_list_free_full(id_list, free);
}
......@@ -271,10 +274,9 @@ 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 7
#define NUM_OF_SIGNALS 6
const char * signal_names[NUM_OF_SIGNALS] = {
"lurch-id-show",
"lurch-id-list",
"lurch-id-remove",
"lurch-enable-im",
......@@ -284,7 +286,6 @@ const char * signal_names[NUM_OF_SIGNALS] = {
};
const void * signal_handlers[NUM_OF_SIGNALS] = {
lurch_api_id_show_handler,
lurch_api_id_list_handler,
lurch_api_id_remove_handler,
lurch_api_enable_im_handler,
......@@ -294,7 +295,6 @@ const void * signal_handlers[NUM_OF_SIGNALS] = {
};
const lurch_api_handler_t signal_handler_types[NUM_OF_SIGNALS] = {
LURCH_API_HANDLER_ACC_CB_DATA,
LURCH_API_HANDLER_ACC_CB_DATA,
LURCH_API_HANDLER_ACC_DID_CB_DATA,
LURCH_API_HANDLER_ACC_JID_CB_DATA,
......
#pragma once
#define LURCH_ERR -1000000
#define LURCH_ERR_NOMEM -1000001
#define LURCH_ERR_NO_BUNDLE -1000010
#define LURCH_ERR_DEVICE_NOT_IN_LIST -1000100
/**
......
......@@ -21,38 +21,21 @@ static void lurch_cmd_help(PurpleConversation * conv_p) {
"The following commands exist to interact with the lurch plugin:\n\n"
" - '/lurch enable': Enables OMEMO encryption for this conversation. On by default for regular conversations, off for group chats.\n"
" - '/lurch disable': Disables OMEMO encryption for this conversation.\n"
" - '/lurch id show': Displays this device's ID.\n"
" - '/lurch id list': Displays this account's device list.\n"
" - '/lurch id remove <id>': Removes the device ID <id> from this account's device list.\n"
" - '/lurch fp show': Displays this device's key fingerprint.\n"
" - '/lurch fp conv': Displays the fingerprints of all devices participating in this conversation.\n"
//TODO: add "status"
" - '/lurch status': Shows the OMEMO status of this conversation.\n"
" - '/lurch help': Displays this message.\n"
" - '/lurch uninstall': Uninstalls this device from OMEMO by removing its device ID from the devicelist.";
lurch_cmd_print(conv_p, help_message);
}
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_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_1 = g_strdup_printf("\nYour devicelist is:\n%i (this device)\n", omemo_devicelist_list_data(id_list));
char * temp_msg_2 = (void *) 0;
char * temp_msg_3 = (void *) 0;
......@@ -63,8 +46,9 @@ void lurch_id_list_print(int32_t err, GList * id_list, void * user_data_p) {
return;
}
for (curr_p = id_list; curr_p; curr_p = curr_p->next) {
for (curr_p = id_list->next; 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);
......@@ -141,17 +125,16 @@ void lurch_status_im_print(int32_t err, lurch_status_t status, void * user_data_
switch (status) {
case LURCH_STATUS_DISABLED:
msg = g_strdup_printf("You disabled OMEMO for this conversation. return is %i", status);
msg = "You disabled OMEMO for this conversation. Type '/lurch enable' to switch it back on.";
break;
case LURCH_STATUS_NOT_SUPPORTED:
msg = "Your contact does not support OMEMO.";
msg = "Your contact does not support OMEMO. No devicelist could be found.";
break;
case LURCH_STATUS_NO_SESSION:
msg = "Your contact supports OMEMO, but you have not established a session yet. Just start messaging!";
break;
case LURCH_STATUS_OK:
// msg = "OMEMO is enabled for this conversation.";
msg = g_strdup_printf("You enabled OMEMO for this conversation. return is %i", status);
msg = "OMEMO is enabled for this conversation. You can turn it off by typing '/lurch disable'.";
break;
default:
msg = "Received unknown status code.";
......@@ -164,9 +147,7 @@ static void lurch_cmd_id(PurpleConversation * conv_p, const char * arg, const ch
PurpleAccount * acc_p = purple_conversation_get_account(conv_p);
void * plugins_handle = purple_plugins_get_handle();
if (!g_strcmp0(arg, "show")) {
purple_signal_emit(plugins_handle, "lurch-id-show", acc_p, lurch_id_show_print, conv_p);
} else if (!g_strcmp0(arg, "list")) {
if (!g_strcmp0(arg, "list")) {
purple_signal_emit(plugins_handle, "lurch-id-list", acc_p, lurch_id_list_print, conv_p);
} else if (!g_strcmp0(arg, "remove")) {
if (!param) {
......@@ -175,7 +156,7 @@ static void lurch_cmd_id(PurpleConversation * conv_p, const char * arg, const ch
purple_signal_emit(plugins_handle, "lurch-id-remove", acc_p, strtol(param, (void *) 0, 10), lurch_id_remove_print, conv_p);
}
} else {
lurch_cmd_print(conv_p, "Valid arguments for 'id' are 'show', 'list', and 'remove <id>'.");
lurch_cmd_print(conv_p, "Valid arguments for 'id' are list' and 'remove <id>'.");
}
}
......
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