From 9b55f2dec0ea27a9ce4856e303425e12f866cea2 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Tue, 7 Jul 2020 09:43:28 +0200 Subject: Apply coding style Regards https://github.com/profanity-im/profanity/issues/1396 --- src/otr/otr.c | 162 +++++++++++++++--------------- src/otr/otr.h | 40 ++++---- src/otr/otrlib.h | 16 +-- src/otr/otrlibv3.c | 46 ++++----- src/otr/otrlibv4.c | 287 ++++++++++++++++++++++++++--------------------------- 5 files changed, 274 insertions(+), 277 deletions(-) (limited to 'src/otr') diff --git a/src/otr/otr.c b/src/otr/otr.c index 5c9f11be..855b9443 100644 --- a/src/otr/otr.c +++ b/src/otr/otr.c @@ -33,34 +33,34 @@ * */ -#include -#include +#include #include +#include +#include #include -#include -#include "log.h" -#include "database.h" -#include "config/preferences.h" #include "config/files.h" +#include "config/preferences.h" +#include "database.h" +#include "log.h" #include "otr/otr.h" #include "otr/otrlib.h" #include "ui/ui.h" #include "ui/window_list.h" #include "xmpp/chat_session.h" -#include "xmpp/roster_list.h" #include "xmpp/contact.h" +#include "xmpp/roster_list.h" #include "xmpp/xmpp.h" -#define PRESENCE_ONLINE 1 +#define PRESENCE_ONLINE 1 #define PRESENCE_OFFLINE 0 #define PRESENCE_UNKNOWN -1 static OtrlUserState user_state; static OtrlMessageAppOps ops; -static char *jid; +static char* jid; static gboolean data_loaded; -static GHashTable *smp_initiators; +static GHashTable* smp_initiators; OtrlUserState otr_userstate(void) @@ -82,13 +82,13 @@ otr_smpinitators(void) // ops callbacks static OtrlPolicy -cb_policy(void *opdata, ConnContext *context) +cb_policy(void* opdata, ConnContext* context) { return otrlib_policy(); } static int -cb_is_logged_in(void *opdata, const char *accountname, const char *protocol, const char *recipient) +cb_is_logged_in(void* opdata, const char* accountname, const char* protocol, const char* recipient) { jabber_conn_status_t conn_status = connection_get_status(); if (conn_status != JABBER_CONNECTED) { @@ -116,20 +116,20 @@ cb_is_logged_in(void *opdata, const char *accountname, const char *protocol, con } static void -cb_inject_message(void *opdata, const char *accountname, - const char *protocol, const char *recipient, const char *message) +cb_inject_message(void* opdata, const char* accountname, + const char* protocol, const char* recipient, const char* message) { - char *id = message_send_chat_otr(recipient, message, FALSE, NULL); + char* id = message_send_chat_otr(recipient, message, FALSE, NULL); free(id); } static void -cb_write_fingerprints(void *opdata) +cb_write_fingerprints(void* opdata) { gcry_error_t err = 0; - gchar *otr_dir = files_get_account_data_path(DIR_OTR, jid); + gchar* otr_dir = files_get_account_data_path(DIR_OTR, jid); - GString *fpsfilename = g_string_new(otr_dir); + GString* fpsfilename = g_string_new(otr_dir); g_string_append(fpsfilename, "/fingerprints.txt"); err = otrl_privkey_write_fingerprints(user_state, fpsfilename->str); @@ -143,11 +143,11 @@ cb_write_fingerprints(void *opdata) } static void -cb_gone_secure(void *opdata, ConnContext *context) +cb_gone_secure(void* opdata, ConnContext* context) { - ProfChatWin *chatwin = wins_get_chat(context->username); + ProfChatWin* chatwin = wins_get_chat(context->username); if (!chatwin) { - chatwin = (ProfChatWin*) wins_new_chat(context->username); + chatwin = (ProfChatWin*)wins_new_chat(context->username); } chatwin_otr_secured(chatwin, otr_is_trusted(context->username)); @@ -202,7 +202,7 @@ otr_poll(void) } void -otr_on_connect(ProfAccount *account) +otr_on_connect(ProfAccount* account) { if (jid) { free(jid); @@ -210,7 +210,7 @@ otr_on_connect(ProfAccount *account) jid = strdup(account->jid); log_info("Loading OTR key for %s", jid); - gchar *otr_dir = files_get_account_data_path(DIR_OTR, jid); + gchar* otr_dir = files_get_account_data_path(DIR_OTR, jid); if (!mkdir_recursive(otr_dir)) { log_error("Could not create %s for account %s.", otr_dir, jid); @@ -226,7 +226,7 @@ otr_on_connect(ProfAccount *account) gcry_error_t err = 0; - GString *keysfilename = g_string_new(otr_dir); + GString* keysfilename = g_string_new(otr_dir); g_string_append(keysfilename, "/keys.txt"); if (!g_file_test(keysfilename->str, G_FILE_TEST_IS_REGULAR)) { log_info("No OTR private key file found %s", keysfilename->str); @@ -254,7 +254,7 @@ otr_on_connect(ProfAccount *account) data_loaded = TRUE; } - GString *fpsfilename = g_string_new(otr_dir); + GString* fpsfilename = g_string_new(otr_dir); g_string_append(fpsfilename, "/fingerprints.txt"); if (!g_file_test(fpsfilename->str, G_FILE_TEST_IS_REGULAR)) { log_info("No OTR fingerprints file found %s", fpsfilename->str); @@ -285,10 +285,10 @@ otr_on_connect(ProfAccount *account) } char* -otr_on_message_recv(const char *const barejid, const char *const resource, const char *const message, gboolean *decrypted) +otr_on_message_recv(const char* const barejid, const char* const resource, const char* const message, gboolean* decrypted) { prof_otrpolicy_t policy = otr_get_policy(barejid); - char *whitespace_base = strstr(message, OTRL_MESSAGE_TAG_BASE); + char* whitespace_base = strstr(message, OTRL_MESSAGE_TAG_BASE); //check for OTR whitespace (opportunistic or always) if (policy == PROF_OTRPOLICY_OPPORTUNISTIC || policy == PROF_OTRPOLICY_ALWAYS) { @@ -300,24 +300,24 @@ otr_on_message_recv(const char *const barejid, const char *const resource, const if (strstr(message, OTRL_MESSAGE_TAG_V2) && strstr(message, OTRL_MESSAGE_TAG_V1)) { tag_length = 32; } - memmove(whitespace_base, whitespace_base+tag_length, tag_length); - char *otr_query_message = otr_start_query(); + memmove(whitespace_base, whitespace_base + tag_length, tag_length); + char* otr_query_message = otr_start_query(); cons_show("OTR Whitespace pattern detected. Attempting to start OTR session..."); - char *id = message_send_chat_otr(barejid, otr_query_message, FALSE, NULL); + char* id = message_send_chat_otr(barejid, otr_query_message, FALSE, NULL); free(id); } } } - char *newmessage = otr_decrypt_message(barejid, message, decrypted); + char* newmessage = otr_decrypt_message(barejid, message, decrypted); if (!newmessage) { // internal OTR message return NULL; } if (policy == PROF_OTRPOLICY_ALWAYS && *decrypted == FALSE && !whitespace_base) { - char *otr_query_message = otr_start_query(); + char* otr_query_message = otr_start_query(); cons_show("Attempting to start OTR session..."); - char *id = message_send_chat_otr(barejid, otr_query_message, FALSE, NULL); + char* id = message_send_chat_otr(barejid, otr_query_message, FALSE, NULL); free(id); } @@ -325,14 +325,14 @@ otr_on_message_recv(const char *const barejid, const char *const resource, const } gboolean -otr_on_message_send(ProfChatWin *chatwin, const char *const message, gboolean request_receipt, const char *const replace_id) +otr_on_message_send(ProfChatWin* chatwin, const char* const message, gboolean request_receipt, const char* const replace_id) { - char *id = NULL; + char* id = NULL; prof_otrpolicy_t policy = otr_get_policy(chatwin->barejid); // Send encrypted message if (otr_is_secure(chatwin->barejid)) { - char *encrypted = otr_encrypt_message(chatwin->barejid, message); + char* encrypted = otr_encrypt_message(chatwin->barejid, message); if (encrypted) { id = message_send_chat_otr(chatwin->barejid, encrypted, request_receipt, replace_id); chat_log_otr_msg_out(chatwin->barejid, message, NULL); @@ -355,7 +355,7 @@ otr_on_message_send(ProfChatWin *chatwin, const char *const message, gboolean re // tag and send for policy opportunistic if (policy == PROF_OTRPOLICY_OPPORTUNISTIC) { - char *otr_tagged_msg = otr_tag_message(message); + char* otr_tagged_msg = otr_tag_message(message); id = message_send_chat_otr(chatwin->barejid, otr_tagged_msg, request_receipt, replace_id); chatwin_outgoing_msg(chatwin, message, id, PROF_MSG_ENC_NONE, request_receipt, replace_id); chat_log_msg_out(chatwin->barejid, message, NULL); @@ -368,7 +368,7 @@ otr_on_message_send(ProfChatWin *chatwin, const char *const message, gboolean re } void -otr_keygen(ProfAccount *account) +otr_keygen(ProfAccount* account) { if (data_loaded) { cons_show("OTR key already generated."); @@ -379,7 +379,7 @@ otr_keygen(ProfAccount *account) jid = strdup(account->jid); log_info("Generating OTR key for %s", jid); - gchar *otr_dir = files_get_account_data_path(DIR_OTR, jid); + gchar* otr_dir = files_get_account_data_path(DIR_OTR, jid); if (!mkdir_recursive(otr_dir)) { log_error("Could not create %s for account %s.", otr_dir, jid); @@ -390,7 +390,7 @@ otr_keygen(ProfAccount *account) gcry_error_t err = 0; - GString *keysfilename = g_string_new(otr_dir); + GString* keysfilename = g_string_new(otr_dir); g_string_append(keysfilename, "/keys.txt"); log_debug("Generating private key file %s for %s", keysfilename->str, jid); cons_show("Generating private key, this may take some time."); @@ -408,7 +408,7 @@ otr_keygen(ProfAccount *account) cons_show(""); cons_show("Private key generation complete."); - GString *fpsfilename = g_string_new(otr_dir); + GString* fpsfilename = g_string_new(otr_dir); g_string_append(fpsfilename, "/fingerprints.txt"); log_debug("Generating fingerprints file %s for %s", fpsfilename->str, jid); err = otrl_privkey_write_fingerprints(user_state, fpsfilename->str); @@ -454,21 +454,21 @@ otr_key_loaded(void) } char* -otr_tag_message(const char *const msg) +otr_tag_message(const char* const msg) { - GString *otr_message = g_string_new(msg); + GString* otr_message = g_string_new(msg); g_string_append(otr_message, OTRL_MESSAGE_TAG_BASE); g_string_append(otr_message, OTRL_MESSAGE_TAG_V2); - char *result = otr_message->str; + char* result = otr_message->str; g_string_free(otr_message, FALSE); return result; } gboolean -otr_is_secure(const char *const recipient) +otr_is_secure(const char* const recipient) { - ConnContext *context = otrlib_context_find(user_state, recipient, jid); + ConnContext* context = otrlib_context_find(user_state, recipient, jid); if (context == NULL) { return FALSE; @@ -482,9 +482,9 @@ otr_is_secure(const char *const recipient) } gboolean -otr_is_trusted(const char *const recipient) +otr_is_trusted(const char* const recipient) { - ConnContext *context = otrlib_context_find(user_state, recipient, jid); + ConnContext* context = otrlib_context_find(user_state, recipient, jid); if (context == NULL) { return FALSE; @@ -508,9 +508,9 @@ otr_is_trusted(const char *const recipient) } void -otr_trust(const char *const recipient) +otr_trust(const char* const recipient) { - ConnContext *context = otrlib_context_find(user_state, recipient, jid); + ConnContext* context = otrlib_context_find(user_state, recipient, jid); if (context == NULL) { return; @@ -532,9 +532,9 @@ otr_trust(const char *const recipient) } void -otr_untrust(const char *const recipient) +otr_untrust(const char* const recipient) { - ConnContext *context = otrlib_context_find(user_state, recipient, jid); + ConnContext* context = otrlib_context_find(user_state, recipient, jid); if (context == NULL) { return; @@ -556,9 +556,9 @@ otr_untrust(const char *const recipient) } void -otr_smp_secret(const char *const recipient, const char *secret) +otr_smp_secret(const char* const recipient, const char* secret) { - ConnContext *context = otrlib_context_find(user_state, recipient, jid); + ConnContext* context = otrlib_context_find(user_state, recipient, jid); if (context == NULL) { return; @@ -569,7 +569,7 @@ otr_smp_secret(const char *const recipient, const char *secret) } // if recipient initiated SMP, send response, else initialise - ProfChatWin *chatwin = wins_get_chat(recipient); + ProfChatWin* chatwin = wins_get_chat(recipient); if (g_hash_table_contains(smp_initiators, recipient)) { otrl_message_respond_smp(user_state, &ops, NULL, context, (const unsigned char*)secret, strlen(secret)); if (chatwin) { @@ -585,9 +585,9 @@ otr_smp_secret(const char *const recipient, const char *secret) } void -otr_smp_question(const char *const recipient, const char *question, const char *answer) +otr_smp_question(const char* const recipient, const char* question, const char* answer) { - ConnContext *context = otrlib_context_find(user_state, recipient, jid); + ConnContext* context = otrlib_context_find(user_state, recipient, jid); if (context == NULL) { return; @@ -598,16 +598,16 @@ otr_smp_question(const char *const recipient, const char *question, const char * } otrl_message_initiate_smp_q(user_state, &ops, NULL, context, question, (const unsigned char*)answer, strlen(answer)); - ProfChatWin *chatwin = wins_get_chat(recipient); + ProfChatWin* chatwin = wins_get_chat(recipient); if (chatwin) { chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_AUTH_WAIT, NULL); } } void -otr_smp_answer(const char *const recipient, const char *answer) +otr_smp_answer(const char* const recipient, const char* answer) { - ConnContext *context = otrlib_context_find(user_state, recipient, jid); + ConnContext* context = otrlib_context_find(user_state, recipient, jid); if (context == NULL) { return; @@ -622,7 +622,7 @@ otr_smp_answer(const char *const recipient, const char *answer) } void -otr_end_session(const char *const recipient) +otr_end_session(const char* const recipient) { otrlib_end_session(user_state, recipient, jid, &ops); } @@ -632,18 +632,18 @@ otr_get_my_fingerprint(void) { char fingerprint[45]; otrl_privkey_fingerprint(user_state, fingerprint, jid, "xmpp"); - char *result = strdup(fingerprint); + char* result = strdup(fingerprint); return result; } char* -otr_get_their_fingerprint(const char *const recipient) +otr_get_their_fingerprint(const char* const recipient) { - ConnContext *context = otrlib_context_find(user_state, recipient, jid); + ConnContext* context = otrlib_context_find(user_state, recipient, jid); if (context) { - Fingerprint *fingerprint = context->active_fingerprint; + Fingerprint* fingerprint = context->active_fingerprint; char readable[45]; otrl_privkey_hash_to_human(readable, fingerprint->fingerprint); return strdup(readable); @@ -653,10 +653,10 @@ otr_get_their_fingerprint(const char *const recipient) } prof_otrpolicy_t -otr_get_policy(const char *const recipient) +otr_get_policy(const char* const recipient) { - char *account_name = session_get_account_name(); - ProfAccount *account = accounts_get_account(account_name); + char* account_name = session_get_account_name(); + ProfAccount* account = accounts_get_account(account_name); // check contact specific setting if (g_list_find_custom(account->otr_manual, recipient, (GCompareFunc)g_strcmp0)) { account_free(account); @@ -689,7 +689,7 @@ otr_get_policy(const char *const recipient) account_free(account); // check global setting - char *pref_otr_policy = prefs_get_string(PREF_OTR_POLICY); + char* pref_otr_policy = prefs_get_string(PREF_OTR_POLICY); // pref defaults to manual prof_otrpolicy_t result = PROF_OTRPOLICY_MANUAL; @@ -706,9 +706,9 @@ otr_get_policy(const char *const recipient) } char* -otr_encrypt_message(const char *const to, const char *const message) +otr_encrypt_message(const char* const to, const char* const message) { - char *newmessage = NULL; + char* newmessage = NULL; gcry_error_t err = otrlib_encrypt_message(user_state, &ops, jid, to, message, &newmessage); if (err != 0) { @@ -719,7 +719,7 @@ otr_encrypt_message(const char *const to, const char *const message) } static void -_otr_tlv_free(OtrlTLV *tlvs) +_otr_tlv_free(OtrlTLV* tlvs) { if (tlvs) { otrl_tlv_free(tlvs); @@ -727,23 +727,23 @@ _otr_tlv_free(OtrlTLV *tlvs) } char* -otr_decrypt_message(const char *const from, const char *const message, gboolean *decrypted) +otr_decrypt_message(const char* const from, const char* const message, gboolean* decrypted) { - char *newmessage = NULL; - OtrlTLV *tlvs = NULL; + char* newmessage = NULL; + OtrlTLV* tlvs = NULL; int result = otrlib_decrypt_message(user_state, &ops, jid, from, message, &newmessage, &tlvs); // internal libotr message if (result == 1) { - ConnContext *context = otrlib_context_find(user_state, from, jid); + ConnContext* context = otrlib_context_find(user_state, from, jid); // common tlv handling - OtrlTLV *tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED); + OtrlTLV* tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED); if (tlv) { if (context) { otrl_context_force_plaintext(context); - ProfChatWin *chatwin = wins_get_chat(from); + ProfChatWin* chatwin = wins_get_chat(from); if (chatwin) { chatwin_otr_unsecured(chatwin); } @@ -756,7 +756,7 @@ otr_decrypt_message(const char *const from, const char *const message, gboolean return NULL; - // message was processed, return to user + // message was processed, return to user } else if (newmessage) { _otr_tlv_free(tlvs); if (g_str_has_prefix(message, "?OTR:")) { @@ -764,7 +764,7 @@ otr_decrypt_message(const char *const from, const char *const message, gboolean } return newmessage; - // normal non OTR message + // normal non OTR message } else { _otr_tlv_free(tlvs); *decrypted = FALSE; @@ -773,7 +773,7 @@ otr_decrypt_message(const char *const from, const char *const message, gboolean } void -otr_free_message(char *message) +otr_free_message(char* message) { otrl_message_free(message); } diff --git a/src/otr/otr.h b/src/otr/otr.h index 58b6decf..4583e79c 100644 --- a/src/otr/otr.h +++ b/src/otr/otr.h @@ -36,8 +36,8 @@ #ifndef OTR_OTR_H #define OTR_OTR_H -#include #include +#include #include "config/accounts.h" #include "ui/win_types.h" @@ -70,37 +70,37 @@ void otr_shutdown(void); char* otr_libotr_version(void); char* otr_start_query(void); void otr_poll(void); -void otr_on_connect(ProfAccount *account); +void otr_on_connect(ProfAccount* account); -char* otr_on_message_recv(const char *const barejid, const char *const resource, const char *const message, gboolean *decrypted); -gboolean otr_on_message_send(ProfChatWin *chatwin, const char *const message, gboolean request_receipt, const char *const replace_id); +char* otr_on_message_recv(const char* const barejid, const char* const resource, const char* const message, gboolean* decrypted); +gboolean otr_on_message_send(ProfChatWin* chatwin, const char* const message, gboolean request_receipt, const char* const replace_id); -void otr_keygen(ProfAccount *account); +void otr_keygen(ProfAccount* account); -char* otr_tag_message(const char *const msg); +char* otr_tag_message(const char* const msg); gboolean otr_key_loaded(void); -gboolean otr_is_secure(const char *const recipient); +gboolean otr_is_secure(const char* const recipient); -gboolean otr_is_trusted(const char *const recipient); -void otr_trust(const char *const recipient); -void otr_untrust(const char *const recipient); +gboolean otr_is_trusted(const char* const recipient); +void otr_trust(const char* const recipient); +void otr_untrust(const char* const recipient); -void otr_smp_secret(const char *const recipient, const char *secret); -void otr_smp_question(const char *const recipient, const char *question, const char *answer); -void otr_smp_answer(const char *const recipient, const char *answer); +void otr_smp_secret(const char* const recipient, const char* secret); +void otr_smp_question(const char* const recipient, const char* question, const char* answer); +void otr_smp_answer(const char* const recipient, const char* answer); -void otr_end_session(const char *const recipient); +void otr_end_session(const char* const recipient); char* otr_get_my_fingerprint(void); -char* otr_get_their_fingerprint(const char *const recipient); +char* otr_get_their_fingerprint(const char* const recipient); -char* otr_encrypt_message(const char *const to, const char *const message); -char* otr_decrypt_message(const char *const from, const char *const message, - gboolean *decrypted); +char* otr_encrypt_message(const char* const to, const char* const message); +char* otr_decrypt_message(const char* const from, const char* const message, + gboolean* decrypted); -void otr_free_message(char *message); +void otr_free_message(char* message); -prof_otrpolicy_t otr_get_policy(const char *const recipient); +prof_otrpolicy_t otr_get_policy(const char* const recipient); #endif diff --git a/src/otr/otrlib.h b/src/otr/otrlib.h index 3c6e02f8..454013e3 100644 --- a/src/otr/otrlib.h +++ b/src/otr/otrlib.h @@ -40,21 +40,21 @@ OtrlPolicy otrlib_policy(void); char* otrlib_start_query(void); -void otrlib_init_ops(OtrlMessageAppOps *ops); +void otrlib_init_ops(OtrlMessageAppOps* ops); void otrlib_init_timer(void); void otrlib_poll(void); -ConnContext* otrlib_context_find(OtrlUserState user_state, const char *const recipient, char *jid); +ConnContext* otrlib_context_find(OtrlUserState user_state, const char* const recipient, char* jid); -void otrlib_end_session(OtrlUserState user_state, const char *const recipient, char *jid, OtrlMessageAppOps *ops); +void otrlib_end_session(OtrlUserState user_state, const char* const recipient, char* jid, OtrlMessageAppOps* ops); -gcry_error_t otrlib_encrypt_message(OtrlUserState user_state, OtrlMessageAppOps *ops, char *jid, const char *const to, - const char *const message, char **newmessage); +gcry_error_t otrlib_encrypt_message(OtrlUserState user_state, OtrlMessageAppOps* ops, char* jid, const char* const to, + const char* const message, char** newmessage); -int otrlib_decrypt_message(OtrlUserState user_state, OtrlMessageAppOps *ops, char *jid, const char *const from, - const char *const message, char **decrypted, OtrlTLV **tlvs); +int otrlib_decrypt_message(OtrlUserState user_state, OtrlMessageAppOps* ops, char* jid, const char* const from, + const char* const message, char** decrypted, OtrlTLV** tlvs); -void otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext *context, OtrlTLV *tlvs, GHashTable *smp_initiators); +void otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps* ops, ConnContext* context, OtrlTLV* tlvs, GHashTable* smp_initiators); #endif diff --git a/src/otr/otrlibv3.c b/src/otr/otrlibv3.c index 2628b728..0416ad80 100644 --- a/src/otr/otrlibv3.c +++ b/src/otr/otrlibv3.c @@ -32,9 +32,9 @@ * source files in the program, then also delete it here. * */ -#include -#include #include +#include +#include #include "otr/otr.h" #include "otr/otrlib.h" @@ -44,7 +44,7 @@ OtrlPolicy otrlib_policy(void) { - return OTRL_POLICY_ALLOW_V1 | OTRL_POLICY_ALLOW_V2 ; + return OTRL_POLICY_ALLOW_V1 | OTRL_POLICY_ALLOW_V2; } void @@ -64,30 +64,30 @@ otrlib_start_query(void) } static int -cb_display_otr_message(void *opdata, const char *accountname, - const char *protocol, const char *username, const char *msg) +cb_display_otr_message(void* opdata, const char* accountname, + const char* protocol, const char* username, const char* msg) { cons_show_error("%s", msg); return 0; } void -otrlib_init_ops(OtrlMessageAppOps *ops) +otrlib_init_ops(OtrlMessageAppOps* ops) { ops->display_otr_message = cb_display_otr_message; } ConnContext* -otrlib_context_find(OtrlUserState user_state, const char *const recipient, char *jid) +otrlib_context_find(OtrlUserState user_state, const char* const recipient, char* jid) { return otrl_context_find(user_state, recipient, jid, "xmpp", 0, NULL, NULL, NULL); } void -otrlib_end_session(OtrlUserState user_state, const char *const recipient, char *jid, OtrlMessageAppOps *ops) +otrlib_end_session(OtrlUserState user_state, const char* const recipient, char* jid, OtrlMessageAppOps* ops) { - ConnContext *context = otrl_context_find(user_state, recipient, jid, "xmpp", - 0, NULL, NULL, NULL); + ConnContext* context = otrl_context_find(user_state, recipient, jid, "xmpp", + 0, NULL, NULL, NULL); if (context) { otrl_message_disconnect(user_state, ops, NULL, jid, "xmpp", recipient); @@ -95,8 +95,8 @@ otrlib_end_session(OtrlUserState user_state, const char *const recipient, char * } gcry_error_t -otrlib_encrypt_message(OtrlUserState user_state, OtrlMessageAppOps *ops, char *jid, const char *const to, - const char *const message, char **newmessage) +otrlib_encrypt_message(OtrlUserState user_state, OtrlMessageAppOps* ops, char* jid, const char* const to, + const char* const message, char** newmessage) { gcry_error_t err; err = otrl_message_sending( @@ -116,8 +116,8 @@ otrlib_encrypt_message(OtrlUserState user_state, OtrlMessageAppOps *ops, char *j } int -otrlib_decrypt_message(OtrlUserState user_state, OtrlMessageAppOps *ops, char *jid, const char *const from, - const char *const message, char **decrypted, OtrlTLV **tlvs) +otrlib_decrypt_message(OtrlUserState user_state, OtrlMessageAppOps* ops, char* jid, const char* const from, + const char* const message, char** decrypted, OtrlTLV** tlvs) { return otrl_message_receiving( user_state, @@ -134,15 +134,15 @@ otrlib_decrypt_message(OtrlUserState user_state, OtrlMessageAppOps *ops, char *j } void -otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext *context, OtrlTLV *tlvs, GHashTable *smp_initiators) +otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps* ops, ConnContext* context, OtrlTLV* tlvs, GHashTable* smp_initiators) { NextExpectedSMP nextMsg = context->smstate->nextExpected; - OtrlTLV *tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP1); + OtrlTLV* tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP1); if (tlv) { if (nextMsg != OTRL_SMP_EXPECT1) { otrl_message_abort_smp(user_state, ops, NULL, context); } else { - ProfChatWin *chatwin = wins_get_chat(context->username); + ProfChatWin* chatwin = wins_get_chat(context->username); if (chatwin) { chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_INIT, NULL); } @@ -154,10 +154,10 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext if (nextMsg != OTRL_SMP_EXPECT1) { otrl_message_abort_smp(user_state, ops, NULL, context); } else { - ProfChatWin *chatwin = wins_get_chat(context->username); + ProfChatWin* chatwin = wins_get_chat(context->username); if (chatwin) { - char *question = (char *)tlv->data; - char *eoq = memchr(question, '\0', tlv->len); + char* question = (char*)tlv->data; + char* eoq = memchr(question, '\0', tlv->len); if (eoq) { chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_INIT_Q, question); } @@ -178,7 +178,7 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext otrl_message_abort_smp(user_state, ops, NULL, context); } else { context->smstate->nextExpected = OTRL_SMP_EXPECT1; - ProfChatWin *chatwin = wins_get_chat(context->username); + ProfChatWin* chatwin = wins_get_chat(context->username); if (chatwin) { if (context->smstate->received_question == 0) { if (context->active_fingerprint->trust && (context->active_fingerprint->trust[0] != '\0')) { @@ -204,7 +204,7 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext otrl_message_abort_smp(user_state, ops, NULL, context); } else { context->smstate->nextExpected = OTRL_SMP_EXPECT1; - ProfChatWin *chatwin = wins_get_chat(context->username); + ProfChatWin* chatwin = wins_get_chat(context->username); if (chatwin) { if (context->active_fingerprint->trust && (context->active_fingerprint->trust[0] != '\0')) { chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_SUCCESS, NULL); @@ -219,7 +219,7 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP_ABORT); if (tlv) { context->smstate->nextExpected = OTRL_SMP_EXPECT1; - ProfChatWin *chatwin = wins_get_chat(context->username); + ProfChatWin* chatwin = wins_get_chat(context->username); if (chatwin) { chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_ABORT, NULL); chatwin_otr_untrust(chatwin); diff --git a/src/otr/otrlibv4.c b/src/otr/otrlibv4.c index fbe24a47..a02e62d9 100644 --- a/src/otr/otrlibv4.c +++ b/src/otr/otrlibv4.c @@ -33,9 +33,9 @@ * */ -#include -#include #include +#include +#include #include "log.h" #include "otr/otr.h" @@ -43,7 +43,7 @@ #include "ui/ui.h" #include "ui/window_list.h" -static GTimer *timer; +static GTimer* timer; static unsigned int current_interval; OtrlPolicy @@ -67,7 +67,7 @@ otrlib_poll(void) if (current_interval != 0 && elapsed > current_interval) { OtrlUserState user_state = otr_userstate(); - OtrlMessageAppOps *ops = otr_messageops(); + OtrlMessageAppOps* ops = otr_messageops(); otrl_message_poll(user_state, ops, NULL); g_timer_start(timer); } @@ -80,172 +80,169 @@ otrlib_start_query(void) } static const char* -cb_otr_error_message(void *opdata, ConnContext *context, OtrlErrorCode err_code) +cb_otr_error_message(void* opdata, ConnContext* context, OtrlErrorCode err_code) { - switch(err_code) - { - case OTRL_ERRCODE_ENCRYPTION_ERROR: - return strdup("OTR Error: occurred while encrypting a message"); - case OTRL_ERRCODE_MSG_NOT_IN_PRIVATE: - return strdup("OTR Error: Sent encrypted message to somebody who is not in a mutual OTR session"); - case OTRL_ERRCODE_MSG_UNREADABLE: - return strdup("OTR Error: sent an unreadable encrypted message"); - case OTRL_ERRCODE_MSG_MALFORMED: - return strdup("OTR Error: message sent is malformed"); - default: - return strdup("OTR Error: unknown"); + switch (err_code) { + case OTRL_ERRCODE_ENCRYPTION_ERROR: + return strdup("OTR Error: occurred while encrypting a message"); + case OTRL_ERRCODE_MSG_NOT_IN_PRIVATE: + return strdup("OTR Error: Sent encrypted message to somebody who is not in a mutual OTR session"); + case OTRL_ERRCODE_MSG_UNREADABLE: + return strdup("OTR Error: sent an unreadable encrypted message"); + case OTRL_ERRCODE_MSG_MALFORMED: + return strdup("OTR Error: message sent is malformed"); + default: + return strdup("OTR Error: unknown"); } } static void -cb_otr_error_message_free(void *opdata, const char *err_msg) +cb_otr_error_message_free(void* opdata, const char* err_msg) { - free((char *)err_msg); + free((char*)err_msg); } static void -cb_timer_control(void *opdata, unsigned int interval) +cb_timer_control(void* opdata, unsigned int interval) { current_interval = interval; } static void -cb_handle_msg_event(void *opdata, OtrlMessageEvent msg_event, - ConnContext *context, const char *message, - gcry_error_t err) +cb_handle_msg_event(void* opdata, OtrlMessageEvent msg_event, + ConnContext* context, const char* message, + gcry_error_t err) { - GString *err_msg; - switch (msg_event) - { - case OTRL_MSGEVENT_ENCRYPTION_REQUIRED: - ui_handle_otr_error(context->username, "OTR: Policy requires encryption, but attempting to send an unencrypted message."); - break; - case OTRL_MSGEVENT_ENCRYPTION_ERROR: - ui_handle_otr_error(context->username, "OTR: Error occurred while encrypting a message, message not sent."); - break; - case OTRL_MSGEVENT_CONNECTION_ENDED: - ui_handle_otr_error(context->username, "OTR: Message not sent because contact has ended the private conversation."); - break; - case OTRL_MSGEVENT_SETUP_ERROR: - ui_handle_otr_error(context->username, "OTR: A private conversation could not be set up."); - break; - case OTRL_MSGEVENT_MSG_REFLECTED: - ui_handle_otr_error(context->username, "OTR: Received our own OTR message."); - break; - case OTRL_MSGEVENT_MSG_RESENT: - ui_handle_otr_error(context->username, "OTR: The previous message was resent."); - break; - case OTRL_MSGEVENT_RCVDMSG_NOT_IN_PRIVATE: - ui_handle_otr_error(context->username, "OTR: Received an encrypted message but no private connection established."); - break; - case OTRL_MSGEVENT_RCVDMSG_UNREADABLE: - ui_handle_otr_error(context->username, "OTR: Cannot read the received message."); - break; - case OTRL_MSGEVENT_RCVDMSG_MALFORMED: - ui_handle_otr_error(context->username, "OTR: The message received contains malformed data."); - break; - case OTRL_MSGEVENT_RCVDMSG_GENERAL_ERR: - err_msg = g_string_new("OTR: Received error: "); - g_string_append(err_msg, message); - g_string_append(err_msg, "."); - ui_handle_otr_error(context->username, err_msg->str); - g_string_free(err_msg, TRUE); - break; - case OTRL_MSGEVENT_RCVDMSG_UNENCRYPTED: - err_msg = g_string_new("OTR: Received an unencrypted message: "); - g_string_append(err_msg, message); - ui_handle_otr_error(context->username, err_msg->str); - g_string_free(err_msg, TRUE); - break; - case OTRL_MSGEVENT_RCVDMSG_UNRECOGNIZED: - ui_handle_otr_error(context->username, "OTR: Cannot recognize the type of message received."); - break; - case OTRL_MSGEVENT_RCVDMSG_FOR_OTHER_INSTANCE: - ui_handle_otr_error(context->username, "OTR: Received and discarded a message intended for another instance."); - break; - default: - break; + GString* err_msg; + switch (msg_event) { + case OTRL_MSGEVENT_ENCRYPTION_REQUIRED: + ui_handle_otr_error(context->username, "OTR: Policy requires encryption, but attempting to send an unencrypted message."); + break; + case OTRL_MSGEVENT_ENCRYPTION_ERROR: + ui_handle_otr_error(context->username, "OTR: Error occurred while encrypting a message, message not sent."); + break; + case OTRL_MSGEVENT_CONNECTION_ENDED: + ui_handle_otr_error(context->username, "OTR: Message not sent because contact has ended the private conversation."); + break; + case OTRL_MSGEVENT_SETUP_ERROR: + ui_handle_otr_error(context->username, "OTR: A private conversation could not be set up."); + break; + case OTRL_MSGEVENT_MSG_REFLECTED: + ui_handle_otr_error(context->username, "OTR: Received our own OTR message."); + break; + case OTRL_MSGEVENT_MSG_RESENT: + ui_handle_otr_error(context->username, "OTR: The previous message was resent."); + break; + case OTRL_MSGEVENT_RCVDMSG_NOT_IN_PRIVATE: + ui_handle_otr_error(context->username, "OTR: Received an encrypted message but no private connection established."); + break; + case OTRL_MSGEVENT_RCVDMSG_UNREADABLE: + ui_handle_otr_error(context->username, "OTR: Cannot read the received message."); + break; + case OTRL_MSGEVENT_RCVDMSG_MALFORMED: + ui_handle_otr_error(context->username, "OTR: The message received contains malformed data."); + break; + case OTRL_MSGEVENT_RCVDMSG_GENERAL_ERR: + err_msg = g_string_new("OTR: Received error: "); + g_string_append(err_msg, message); + g_string_append(err_msg, "."); + ui_handle_otr_error(context->username, err_msg->str); + g_string_free(err_msg, TRUE); + break; + case OTRL_MSGEVENT_RCVDMSG_UNENCRYPTED: + err_msg = g_string_new("OTR: Received an unencrypted message: "); + g_string_append(err_msg, message); + ui_handle_otr_error(context->username, err_msg->str); + g_string_free(err_msg, TRUE); + break; + case OTRL_MSGEVENT_RCVDMSG_UNRECOGNIZED: + ui_handle_otr_error(context->username, "OTR: Cannot recognize the type of message received."); + break; + case OTRL_MSGEVENT_RCVDMSG_FOR_OTHER_INSTANCE: + ui_handle_otr_error(context->username, "OTR: Received and discarded a message intended for another instance."); + break; + default: + break; } } static void -cb_handle_smp_event(void *opdata, OtrlSMPEvent smp_event, - ConnContext *context, unsigned short progress_percent, - char *question) +cb_handle_smp_event(void* opdata, OtrlSMPEvent smp_event, + ConnContext* context, unsigned short progress_percent, + char* question) { NextExpectedSMP nextMsg = context->smstate->nextExpected; OtrlUserState user_state = otr_userstate(); - OtrlMessageAppOps *ops = otr_messageops(); - GHashTable *smp_initiators = otr_smpinitators(); - - ProfChatWin *chatwin = wins_get_chat(context->username); - - switch(smp_event) - { - case OTRL_SMPEVENT_ASK_FOR_SECRET: - if (chatwin) { - chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_INIT, NULL); + OtrlMessageAppOps* ops = otr_messageops(); + GHashTable* smp_initiators = otr_smpinitators(); + + ProfChatWin* chatwin = wins_get_chat(context->username); + + switch (smp_event) { + case OTRL_SMPEVENT_ASK_FOR_SECRET: + if (chatwin) { + chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_INIT, NULL); + } + g_hash_table_insert(smp_initiators, strdup(context->username), strdup(context->username)); + break; + + case OTRL_SMPEVENT_ASK_FOR_ANSWER: + if (chatwin) { + chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_INIT_Q, question); + } + break; + + case OTRL_SMPEVENT_SUCCESS: + if (chatwin) { + if (context->smstate->received_question == 0) { + chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_SUCCESS, NULL); + chatwin_otr_trust(chatwin); + } else { + chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_SUCCESS_Q, NULL); } - g_hash_table_insert(smp_initiators, strdup(context->username), strdup(context->username)); - break; - - case OTRL_SMPEVENT_ASK_FOR_ANSWER: - if (chatwin) { - chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_INIT_Q, question); - } - break; - - case OTRL_SMPEVENT_SUCCESS: - if (chatwin) { - if (context->smstate->received_question == 0) { - chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_SUCCESS, NULL); - chatwin_otr_trust(chatwin); - } else { - chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_SUCCESS_Q, NULL); - } - } - break; - - case OTRL_SMPEVENT_FAILURE: - if (chatwin) { - if (context->smstate->received_question == 0) { - if (nextMsg == OTRL_SMP_EXPECT3) { - chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_SENDER_FAIL, NULL); - } else if (nextMsg == OTRL_SMP_EXPECT4) { - chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_RECEIVER_FAIL, NULL); - } - chatwin_otr_untrust(chatwin); - } else { - chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_FAIL_Q, NULL); + } + break; + + case OTRL_SMPEVENT_FAILURE: + if (chatwin) { + if (context->smstate->received_question == 0) { + if (nextMsg == OTRL_SMP_EXPECT3) { + chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_SENDER_FAIL, NULL); + } else if (nextMsg == OTRL_SMP_EXPECT4) { + chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_RECEIVER_FAIL, NULL); } + chatwin_otr_untrust(chatwin); + } else { + chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_FAIL_Q, NULL); } - break; + } + break; - case OTRL_SMPEVENT_ERROR: - otrl_message_abort_smp(user_state, ops, NULL, context); - break; + case OTRL_SMPEVENT_ERROR: + otrl_message_abort_smp(user_state, ops, NULL, context); + break; - case OTRL_SMPEVENT_CHEATED: - otrl_message_abort_smp(user_state, ops, NULL, context); - break; + case OTRL_SMPEVENT_CHEATED: + otrl_message_abort_smp(user_state, ops, NULL, context); + break; - case OTRL_SMPEVENT_ABORT: - if (chatwin) { - chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_ABORT, NULL); - chatwin_otr_untrust(chatwin); - } - break; + case OTRL_SMPEVENT_ABORT: + if (chatwin) { + chatwin_otr_smp_event(chatwin, PROF_OTR_SMP_ABORT, NULL); + chatwin_otr_untrust(chatwin); + } + break; - case OTRL_SMPEVENT_IN_PROGRESS: - break; + case OTRL_SMPEVENT_IN_PROGRESS: + break; - default: - break; + default: + break; } } void -otrlib_init_ops(OtrlMessageAppOps *ops) +otrlib_init_ops(OtrlMessageAppOps* ops) { ops->otr_error_message = cb_otr_error_message; ops->otr_error_message_free = cb_otr_error_message_free; @@ -255,16 +252,16 @@ otrlib_init_ops(OtrlMessageAppOps *ops) } ConnContext* -otrlib_context_find(OtrlUserState user_state, const char *const recipient, char *jid) +otrlib_context_find(OtrlUserState user_state, const char* const recipient, char* jid) { return otrl_context_find(user_state, recipient, jid, "xmpp", OTRL_INSTAG_MASTER, 0, NULL, NULL, NULL); } void -otrlib_end_session(OtrlUserState user_state, const char *const recipient, char *jid, OtrlMessageAppOps *ops) +otrlib_end_session(OtrlUserState user_state, const char* const recipient, char* jid, OtrlMessageAppOps* ops) { - ConnContext *context = otrl_context_find(user_state, recipient, jid, "xmpp", - OTRL_INSTAG_MASTER, 0, NULL, NULL, NULL); + ConnContext* context = otrl_context_find(user_state, recipient, jid, "xmpp", + OTRL_INSTAG_MASTER, 0, NULL, NULL, NULL); if (context) { otrl_message_disconnect(user_state, ops, NULL, jid, "xmpp", recipient, 0); @@ -272,8 +269,8 @@ otrlib_end_session(OtrlUserState user_state, const char *const recipient, char * } gcry_error_t -otrlib_encrypt_message(OtrlUserState user_state, OtrlMessageAppOps *ops, char *jid, const char *const to, - const char *const message, char **newmessage) +otrlib_encrypt_message(OtrlUserState user_state, OtrlMessageAppOps* ops, char* jid, const char* const to, + const char* const message, char** newmessage) { gcry_error_t err; @@ -297,8 +294,8 @@ otrlib_encrypt_message(OtrlUserState user_state, OtrlMessageAppOps *ops, char *j } int -otrlib_decrypt_message(OtrlUserState user_state, OtrlMessageAppOps *ops, char *jid, const char *const from, - const char *const message, char **decrypted, OtrlTLV **tlvs) +otrlib_decrypt_message(OtrlUserState user_state, OtrlMessageAppOps* ops, char* jid, const char* const from, + const char* const message, char** decrypted, OtrlTLV** tlvs) { return otrl_message_receiving( user_state, @@ -316,6 +313,6 @@ otrlib_decrypt_message(OtrlUserState user_state, OtrlMessageAppOps *ops, char *j } void -otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext *context, OtrlTLV *tlvs, GHashTable *smp_initiators) +otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps* ops, ConnContext* context, OtrlTLV* tlvs, GHashTable* smp_initiators) { } -- cgit 1.4.1-2-gfad0