From e0855bf8ffc69f5145e9f15ae427044ea54321f7 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Mon, 2 Jul 2018 21:43:16 +0200 Subject: [PATCH] remove prefix from class members; this is not really needed for C and sort of redundant. prefer readability. --- cmdline/cmdline.c | 86 ++--- cmdline/main.c | 2 +- cmdline/stress.c | 36 +- src/dc_aheader.c | 46 +-- src/dc_aheader.h | 6 +- src/dc_apeerstate.c | 302 +++++++-------- src/dc_apeerstate.h | 28 +- src/dc_array.c | 90 ++--- src/dc_array.h | 10 +- src/dc_chat.c | 164 ++++---- src/dc_chat.h | 22 +- src/dc_chatlist.c | 124 +++--- src/dc_chatlist.h | 8 +- src/dc_configure.c | 408 ++++++++++---------- src/dc_contact.c | 100 ++--- src/dc_contact.h | 16 +- src/dc_context.c | 884 +++++++++++++++++++++---------------------- src/dc_context.h | 84 ++-- src/dc_dehtml.c | 75 ++-- src/dc_e2ee.c | 116 +++--- src/dc_imap.c | 570 ++++++++++++++-------------- src/dc_imap.h | 64 ++-- src/dc_imex.c | 154 ++++---- src/dc_job.c | 310 +++++++-------- src/dc_job.h | 10 +- src/dc_key.c | 48 +-- src/dc_key.h | 6 +- src/dc_keyring.c | 18 +- src/dc_keyring.h | 6 +- src/dc_log.c | 20 +- src/dc_loginparam.c | 86 ++--- src/dc_loginparam.h | 20 +- src/dc_lot.c | 94 ++--- src/dc_lot.h | 20 +- src/dc_mimefactory.c | 330 ++++++++-------- src/dc_mimefactory.h | 34 +- src/dc_mimeparser.c | 312 +++++++-------- src/dc_mimeparser.h | 42 +- src/dc_msg.c | 254 ++++++------- src/dc_msg.h | 54 ++- src/dc_param.c | 26 +- src/dc_param.h | 2 +- src/dc_pgp.c | 36 +- src/dc_qr.c | 58 +-- src/dc_receive_imf.c | 166 ++++---- src/dc_saxparser.c | 22 +- src/dc_saxparser.h | 8 +- src/dc_securejoin.c | 154 ++++---- src/dc_simplify.c | 28 +- src/dc_simplify.h | 6 +- src/dc_smtp.c | 136 +++---- src/dc_smtp.h | 12 +- src/dc_sqlite3.c | 48 +-- src/dc_sqlite3.h | 4 +- src/dc_stock.c | 4 +- src/dc_strbuilder.c | 50 +-- src/dc_strbuilder.h | 8 +- src/dc_token.c | 12 +- src/dc_tools.c | 18 +- src/deltachat.h | 8 +- 60 files changed, 2930 insertions(+), 2935 deletions(-) diff --git a/cmdline/cmdline.c b/cmdline/cmdline.c index f7006cb7..82554d52 100644 --- a/cmdline/cmdline.c +++ b/cmdline/cmdline.c @@ -42,38 +42,38 @@ your library */ */ int dc_reset_tables(dc_context_t* context, int bits) { - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC ) { return 0; } dc_log_info(context, 0, "Resetting tables (%i)...", bits); if( bits & 1 ) { - dc_sqlite3_execute(context->m_sql, "DELETE FROM jobs;"); + dc_sqlite3_execute(context->sql, "DELETE FROM jobs;"); dc_log_info(context, 0, "(1) Jobs reset."); } if( bits & 2 ) { - dc_sqlite3_execute(context->m_sql, "DELETE FROM acpeerstates;"); + dc_sqlite3_execute(context->sql, "DELETE FROM acpeerstates;"); dc_log_info(context, 0, "(2) Peerstates reset."); } if( bits & 4 ) { - dc_sqlite3_execute(context->m_sql, "DELETE FROM keypairs;"); + dc_sqlite3_execute(context->sql, "DELETE FROM keypairs;"); dc_log_info(context, 0, "(4) Private keypairs reset."); } if( bits & 8 ) { - dc_sqlite3_execute(context->m_sql, "DELETE FROM contacts WHERE id>" DC_STRINGIFY(DC_CONTACT_ID_LAST_SPECIAL) ";"); /* the other IDs are reserved - leave these rows to make sure, the IDs are not used by normal contacts*/ - dc_sqlite3_execute(context->m_sql, "DELETE FROM chats WHERE id>" DC_STRINGIFY(DC_CHAT_ID_LAST_SPECIAL) ";"); - dc_sqlite3_execute(context->m_sql, "DELETE FROM chats_contacts;"); - dc_sqlite3_execute(context->m_sql, "DELETE FROM msgs WHERE id>" DC_STRINGIFY(DC_MSG_ID_LAST_SPECIAL) ";"); - dc_sqlite3_execute(context->m_sql, "DELETE FROM config WHERE keyname LIKE 'imap.%' OR keyname LIKE 'configured%';"); - dc_sqlite3_execute(context->m_sql, "DELETE FROM leftgrps;"); + dc_sqlite3_execute(context->sql, "DELETE FROM contacts WHERE id>" DC_STRINGIFY(DC_CONTACT_ID_LAST_SPECIAL) ";"); /* the other IDs are reserved - leave these rows to make sure, the IDs are not used by normal contacts*/ + dc_sqlite3_execute(context->sql, "DELETE FROM chats WHERE id>" DC_STRINGIFY(DC_CHAT_ID_LAST_SPECIAL) ";"); + dc_sqlite3_execute(context->sql, "DELETE FROM chats_contacts;"); + dc_sqlite3_execute(context->sql, "DELETE FROM msgs WHERE id>" DC_STRINGIFY(DC_MSG_ID_LAST_SPECIAL) ";"); + dc_sqlite3_execute(context->sql, "DELETE FROM config WHERE keyname LIKE 'imap.%' OR keyname LIKE 'configured%';"); + dc_sqlite3_execute(context->sql, "DELETE FROM leftgrps;"); dc_log_info(context, 0, "(8) Rest but server config reset."); } - context->m_cb(context, DC_EVENT_MSGS_CHANGED, 0, 0); + context->cb(context, DC_EVENT_MSGS_CHANGED, 0, 0); return 1; } @@ -91,13 +91,13 @@ int dc_reset_tables(dc_context_t* context, int bits) */ static int dc_cleanup_contacts(dc_context_t* context) { - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC ) { return 0; } dc_log_info(context, 0, "Cleaning up contacts ..."); - dc_sqlite3_execute(context->m_sql, "DELETE FROM contacts WHERE id>" DC_STRINGIFY(DC_CONTACT_ID_LAST_SPECIAL) " AND blocked=0 AND NOT EXISTS (SELECT contact_id FROM chats_contacts where contacts.id = chats_contacts.contact_id) AND NOT EXISTS (select from_id from msgs WHERE msgs.from_id = contacts.id);"); + dc_sqlite3_execute(context->sql, "DELETE FROM contacts WHERE id>" DC_STRINGIFY(DC_CONTACT_ID_LAST_SPECIAL) " AND blocked=0 AND NOT EXISTS (SELECT contact_id FROM chats_contacts where contacts.id = chats_contacts.contact_id) AND NOT EXISTS (select from_id from msgs WHERE msgs.from_id = contacts.id);"); return 1; } @@ -109,7 +109,7 @@ static int dc_poke_eml_file(dc_context_t* context, const char* filename) char* data = NULL; size_t data_bytes; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC ) { return 0; } @@ -140,22 +140,22 @@ static int poke_public_key(dc_context_t* mailbox, const char* addr, const char* } /* create a fake autocrypt header */ - header->m_addr = dc_strdup(addr); - header->m_prefer_encrypt = DC_PE_MUTUAL; - if( !dc_key_set_from_file(header->m_public_key, public_key_file, mailbox) - || !dc_pgp_is_valid_key(mailbox, header->m_public_key) ) { + header->addr = dc_strdup(addr); + header->prefer_encrypt = DC_PE_MUTUAL; + if( !dc_key_set_from_file(header->public_key, public_key_file, mailbox) + || !dc_pgp_is_valid_key(mailbox, header->public_key) ) { dc_log_warning(mailbox, 0, "No valid key found in \"%s\".", public_key_file); goto cleanup; } /* update/create peerstate */ - if( dc_apeerstate_load_by_addr(peerstate, mailbox->m_sql, addr) ) { + if( dc_apeerstate_load_by_addr(peerstate, mailbox->sql, addr) ) { dc_apeerstate_apply_header(peerstate, header, time(NULL)); - dc_apeerstate_save_to_db(peerstate, mailbox->m_sql, 0); + dc_apeerstate_save_to_db(peerstate, mailbox->sql, 0); } else { dc_apeerstate_init_from_header(peerstate, header, time(NULL)); - dc_apeerstate_save_to_db(peerstate, mailbox->m_sql, 1); + dc_apeerstate_save_to_db(peerstate, mailbox->sql, 1); } success = 1; @@ -194,7 +194,7 @@ static int poke_spec(dc_context_t* mailbox, const char* spec) return 0; } - if( !dc_sqlite3_is_open(mailbox->m_sql) ) { + if( !dc_sqlite3_is_open(mailbox->sql) ) { dc_log_error(mailbox, 0, "Import: Database not opened."); goto cleanup; } @@ -203,10 +203,10 @@ static int poke_spec(dc_context_t* mailbox, const char* spec) if( spec ) { real_spec = dc_strdup(spec); - dc_sqlite3_set_config(mailbox->m_sql, "import_spec", real_spec); + dc_sqlite3_set_config(mailbox->sql, "import_spec", real_spec); } else { - real_spec = dc_sqlite3_get_config(mailbox->m_sql, "import_spec", NULL); /* may still NULL */ + real_spec = dc_sqlite3_get_config(mailbox->sql, "import_spec", NULL); /* may still NULL */ if( real_spec == NULL ) { dc_log_error(mailbox, 0, "Import: No file or folder given."); goto cleanup; @@ -255,7 +255,7 @@ static int poke_spec(dc_context_t* mailbox, const char* spec) dc_log_info(mailbox, 0, "Import: %i items read from \"%s\".", read_cnt, real_spec); if( read_cnt > 0 ) { - mailbox->m_cb(mailbox, DC_EVENT_MSGS_CHANGED, 0, 0); /* even if read_cnt>0, the number of messages added to the database may be 0. While we regard this issue using IMAP, we ignore it here. */ + mailbox->cb(mailbox, DC_EVENT_MSGS_CHANGED, 0, 0); /* even if read_cnt>0, the number of messages added to the database may be 0. While we regard this issue using IMAP, we ignore it here. */ } success = 1; @@ -335,14 +335,14 @@ static void log_contactlist(dc_context_t* mailbox, dc_array_t* contacts) int verified_state = dc_contact_is_verified(contact); const char* verified_str = verified_state? (verified_state==2? " √√":" √"): ""; line = dc_mprintf("%s%s <%s>", (name&&name[0])? name : "", verified_str, (addr&&addr[0])? addr : "addr unset"); - int peerstate_ok = dc_apeerstate_load_by_addr(peerstate, mailbox->m_sql, addr); + int peerstate_ok = dc_apeerstate_load_by_addr(peerstate, mailbox->sql, addr); if( peerstate_ok && contact_id != DC_CONTACT_ID_SELF ) { char* pe = NULL; - switch( peerstate->m_prefer_encrypt ) { + switch( peerstate->prefer_encrypt ) { case DC_PE_MUTUAL: pe = dc_strdup("mutual"); break; case DC_PE_NOPREFERENCE: pe = dc_strdup("no-preference"); break; case DC_PE_RESET: pe = dc_strdup("reset"); break; - default: pe = dc_mprintf("unknown-value (%i)", peerstate->m_prefer_encrypt); break; + default: pe = dc_mprintf("unknown-value (%i)", peerstate->prefer_encrypt); break; } line2 = dc_mprintf(", prefer-encrypt=%s", pe); free(pe); @@ -374,8 +374,8 @@ void dc_cmdline_skip_auth() static const char* chat_prefix(const dc_chat_t* chat) { - if( chat->m_type == DC_CHAT_TYPE_GROUP ) { return "Group"; } - else if( chat->m_type == DC_CHAT_TYPE_VERIFIED_GROUP ) { return "VerifiedGroup"; } + if( chat->type == DC_CHAT_TYPE_GROUP ) { return "Group"; } + else if( chat->type == DC_CHAT_TYPE_VERIFIED_GROUP ) { return "VerifiedGroup"; } else { return "Single"; } } @@ -393,8 +393,8 @@ char* dc_cmdline(dc_context_t* mailbox, const char* cmdline) goto cleanup; } - if( mailbox->m_cmdline_sel_chat_id ) { - sel_chat = dc_get_chat(mailbox, mailbox->m_cmdline_sel_chat_id); + if( mailbox->cmdline_sel_chat_id ) { + sel_chat = dc_get_chat(mailbox, mailbox->cmdline_sel_chat_id); } /* split commandline into command and first argument @@ -567,14 +567,14 @@ char* dc_cmdline(dc_context_t* mailbox, const char* cmdline) } else if( strcmp(cmd, "has-backup")==0 ) { - ret = dc_imex_has_backup(mailbox, mailbox->m_blobdir); + ret = dc_imex_has_backup(mailbox, mailbox->blobdir); if( ret == NULL ) { ret = dc_strdup("No backup found."); } } else if( strcmp(cmd, "export-backup")==0 ) { - dc_imex(mailbox, DC_IMEX_EXPORT_BACKUP, mailbox->m_blobdir, NULL); + dc_imex(mailbox, DC_IMEX_EXPORT_BACKUP, mailbox->blobdir, NULL); ret = COMMAND_SUCCEEDED; } else if( strcmp(cmd, "import-backup")==0 ) @@ -589,18 +589,18 @@ char* dc_cmdline(dc_context_t* mailbox, const char* cmdline) } else if( strcmp(cmd, "export-keys")==0 ) { - dc_imex(mailbox, DC_IMEX_EXPORT_SELF_KEYS, mailbox->m_blobdir, NULL); + dc_imex(mailbox, DC_IMEX_EXPORT_SELF_KEYS, mailbox->blobdir, NULL); ret = COMMAND_SUCCEEDED; } else if( strcmp(cmd, "import-keys")==0 ) { - dc_imex(mailbox, DC_IMEX_IMPORT_SELF_KEYS, mailbox->m_blobdir, NULL); + dc_imex(mailbox, DC_IMEX_IMPORT_SELF_KEYS, mailbox->blobdir, NULL); ret = COMMAND_SUCCEEDED; } else if( strcmp(cmd, "export-setup")==0 ) { char* setup_code = dc_create_setup_code(mailbox); - char* file_name = dc_mprintf("%s/autocrypt-setup-message.html", mailbox->m_blobdir); + char* file_name = dc_mprintf("%s/autocrypt-setup-message.html", mailbox->blobdir); char* file_content = NULL; if( (file_content=dc_render_setup_file(mailbox, setup_code)) != NULL && dc_write_file(file_name, file_content, strlen(file_content), mailbox) ) { @@ -739,10 +739,10 @@ char* dc_cmdline(dc_context_t* mailbox, const char* cmdline) if( arg1 && arg1[0] ) { /* select a chat (argument 1 = ID of chat to select) */ if( sel_chat ) { dc_chat_unref(sel_chat); sel_chat = NULL; } - mailbox->m_cmdline_sel_chat_id = atoi(arg1); - sel_chat = dc_get_chat(mailbox, mailbox->m_cmdline_sel_chat_id); /* may be NULL */ + mailbox->cmdline_sel_chat_id = atoi(arg1); + sel_chat = dc_get_chat(mailbox, mailbox->cmdline_sel_chat_id); /* may be NULL */ if( sel_chat==NULL ) { - mailbox->m_cmdline_sel_chat_id = 0; + mailbox->cmdline_sel_chat_id = 0; } } @@ -1170,7 +1170,7 @@ char* dc_cmdline(dc_context_t* mailbox, const char* cmdline) } dc_chatlist_unref(chatlist); - ret = strbuilder.m_buf; + ret = strbuilder.buf; } else { ret = dc_strdup("ERROR: Argument missing."); @@ -1203,7 +1203,7 @@ char* dc_cmdline(dc_context_t* mailbox, const char* cmdline) { if( arg1 ) { dc_lot_t* res = dc_check_qr(mailbox, arg1); - ret = dc_mprintf("state=%i, id=%i, text1=%s, text2=%s", (int)res->m_state, res->m_id, res->m_text1? res->m_text1:"", res->m_text2? res->m_text2:""); + ret = dc_mprintf("state=%i, id=%i, text1=%s, text2=%s", (int)res->state, res->id, res->text1? res->text1:"", res->text2? res->text2:""); dc_lot_unref(res); } else { @@ -1214,7 +1214,7 @@ char* dc_cmdline(dc_context_t* mailbox, const char* cmdline) { if( arg1 ) { int event = atoi(arg1); - uintptr_t r = mailbox->m_cb(mailbox, event, 0, 0); + uintptr_t r = mailbox->cb(mailbox, event, 0, 0); ret = dc_mprintf("Sending event %i, received value %i.", (int)event, (int)r); } else { diff --git a/cmdline/main.c b/cmdline/main.c index d0d24881..dfd06a9a 100644 --- a/cmdline/main.c +++ b/cmdline/main.c @@ -72,7 +72,7 @@ static uintptr_t receive_event(dc_context_t* mailbox, int event, uintptr_t data1 case DC_EVENT_HTTP_GET: { char* ret = NULL; - char* tempFile = dc_get_fine_pathNfilename(mailbox->m_blobdir, "curl.result"); + char* tempFile = dc_get_fine_pathNfilename(mailbox->blobdir, "curl.result"); char* cmd = dc_mprintf("curl --silent --location --fail --insecure %s > %s", (char*)data1, tempFile); /* --location = follow redirects */ int error = system(cmd); if( error == 0 ) { /* -1=system() error, !0=curl errors forced by -f, 0=curl success */ diff --git a/cmdline/stress.c b/cmdline/stress.c index cf73299b..13317f7e 100644 --- a/cmdline/stress.c +++ b/cmdline/stress.c @@ -248,7 +248,7 @@ void stress_functions(dc_context_t* context) **************************************************************************/ { - dc_mimeparser_t* mimeparser = dc_mimeparser_new(context->m_blobdir, context); + dc_mimeparser_t* mimeparser = dc_mimeparser_new(context->blobdir, context); const char* raw = "Content-Type: multipart/mixed; boundary=\"==break==\";\n" @@ -271,7 +271,7 @@ void stress_functions(dc_context_t* context) dc_mimeparser_parse(mimeparser, raw, strlen(raw)); - assert( strcmp(mimeparser->m_subject, "inner-subject")==0 ); + assert( strcmp(mimeparser->subject, "inner-subject")==0 ); struct mailimf_optional_field* of = dc_mimeparser_lookup_optional_field(mimeparser, "X-Special-A"); assert( strcmp(of->fld_value, "special-a")==0 ); @@ -282,7 +282,7 @@ void stress_functions(dc_context_t* context) of = dc_mimeparser_lookup_optional_field(mimeparser, "Chat-Version"); assert( strcmp(of->fld_value, "1.0")==0 ); - assert( carray_count(mimeparser->m_parts) == 1 ); + assert( carray_count(mimeparser->parts) == 1 ); dc_mimeparser_unref(mimeparser); } @@ -573,14 +573,14 @@ void stress_functions(dc_context_t* context) dc_param_set_int(p1, 'b', 2); dc_param_set (p1, 'c', NULL); dc_param_set_int(p1, 'd', 4); - assert( strcmp(p1->m_packed, "a=foo\nb=2\nd=4")==0 ); + assert( strcmp(p1->packed, "a=foo\nb=2\nd=4")==0 ); dc_param_set (p1, 'b', NULL); - assert( strcmp(p1->m_packed, "a=foo\nd=4")==0 ); + assert( strcmp(p1->packed, "a=foo\nd=4")==0 ); dc_param_set (p1, 'a', NULL); dc_param_set (p1, 'd', NULL); - assert( strcmp(p1->m_packed, "")==0 ); + assert( strcmp(p1->packed, "")==0 ); dc_param_unref(p1); } @@ -595,24 +595,24 @@ void stress_functions(dc_context_t* context) ah_ok = dc_aheader_set_from_string(ah, "addr=a@b.example.org; prefer-encrypt=mutual; keydata=RGVsdGEgQ2hhdA=="); assert( ah_ok == 1 ); - assert( ah->m_addr && strcmp(ah->m_addr, "a@b.example.org")==0 ); - assert( ah->m_public_key->m_bytes==10 && strncmp((char*)ah->m_public_key->m_binary, "Delta Chat", 10)==0 ); - assert( ah->m_prefer_encrypt==DC_PE_MUTUAL ); + assert( ah->addr && strcmp(ah->addr, "a@b.example.org")==0 ); + assert( ah->public_key->bytes==10 && strncmp((char*)ah->public_key->binary, "Delta Chat", 10)==0 ); + assert( ah->prefer_encrypt==DC_PE_MUTUAL ); rendered = dc_aheader_render(ah); assert( rendered && strcmp(rendered, "addr=a@b.example.org; prefer-encrypt=mutual; keydata= RGVsdGEgQ2hhdA==")==0 ); ah_ok = dc_aheader_set_from_string(ah, " _foo; __FOO=BAR ;;; addr = a@b.example.org ;\r\n prefer-encrypt = mutual ; keydata = RG VsdGEgQ\r\n2hhdA=="); assert( ah_ok == 1 ); - assert( ah->m_addr && strcmp(ah->m_addr, "a@b.example.org")==0 ); - assert( ah->m_public_key->m_bytes==10 && strncmp((char*)ah->m_public_key->m_binary, "Delta Chat", 10)==0 ); - assert( ah->m_prefer_encrypt==DC_PE_MUTUAL ); + assert( ah->addr && strcmp(ah->addr, "a@b.example.org")==0 ); + assert( ah->public_key->bytes==10 && strncmp((char*)ah->public_key->binary, "Delta Chat", 10)==0 ); + assert( ah->prefer_encrypt==DC_PE_MUTUAL ); ah_ok = dc_aheader_set_from_string(ah, "addr=a@b.example.org; prefer-encrypt=ignoreUnknownValues; keydata=RGVsdGEgQ2hhdA=="); assert( ah_ok == 1 ); /* only "yes" or "no" are valid for prefer-encrypt ... */ ah_ok = dc_aheader_set_from_string(ah, "addr=a@b.example.org; keydata=RGVsdGEgQ2hhdA=="); - assert( ah_ok == 1 && ah->m_prefer_encrypt==DC_PE_NOPREFERENCE ); /* ... "nopreference" is use if the attribute is missing (see Autocrypt-Level0) */ + assert( ah_ok == 1 && ah->prefer_encrypt==DC_PE_NOPREFERENCE ); /* ... "nopreference" is use if the attribute is missing (see Autocrypt-Level0) */ ah_ok = dc_aheader_set_from_string(ah, ""); assert( ah_ok == 0 ); @@ -774,8 +774,8 @@ void stress_functions(dc_context_t* context) dc_pgp_create_keypair(context, "foo@bar.de", public_key, private_key); assert( dc_pgp_is_valid_key(context, public_key) ); assert( dc_pgp_is_valid_key(context, private_key) ); - //{char *t1=dc_key_render_asc(public_key); printf("%s",t1);dc_write_file("/home/bpetersen/temp/stress-public.asc", t1,strlen(t1),mailbox);dc_write_file("/home/bpetersen/temp/stress-public.der", public_key->m_binary, public_key->m_bytes, mailbox);free(t1);} - //{char *t1=dc_key_render_asc(private_key);printf("%s",t1);dc_write_file("/home/bpetersen/temp/stress-private.asc",t1,strlen(t1),mailbox);dc_write_file("/home/bpetersen/temp/stress-private.der",private_key->m_binary,private_key->m_bytes,mailbox);free(t1);} + //{char *t1=dc_key_render_asc(public_key); printf("%s",t1);dc_write_file("/home/bpetersen/temp/stress-public.asc", t1,strlen(t1),mailbox);dc_write_file("/home/bpetersen/temp/stress-public.der", public_key->binary, public_key->bytes, mailbox);free(t1);} + //{char *t1=dc_key_render_asc(private_key);printf("%s",t1);dc_write_file("/home/bpetersen/temp/stress-private.asc",t1,strlen(t1),mailbox);dc_write_file("/home/bpetersen/temp/stress-private.der",private_key->binary,private_key->bytes,mailbox);free(t1);} { dc_key_t *test_key = dc_key_new(); @@ -909,15 +909,15 @@ void stress_functions(dc_context_t* context) dc_lot_t* res = dc_check_qr(context, qr); assert( res ); - assert( res->m_state == DC_QR_ASK_VERIFYCONTACT || res->m_state == DC_QR_FPR_MISMATCH || res->m_state == DC_QR_FPR_WITHOUT_ADDR ); + assert( res->state == DC_QR_ASK_VERIFYCONTACT || res->state == DC_QR_FPR_MISMATCH || res->state == DC_QR_FPR_WITHOUT_ADDR ); dc_lot_unref(res); free(qr); res = dc_check_qr(context, "BEGIN:VCARD\nVERSION:3.0\nN:Last;First\nEMAIL;TYPE=INTERNET:stress@test.local\nEND:VCARD"); assert( res ); - assert( res->m_state == DC_QR_ADDR ); - assert( res->m_id != 0 ); + assert( res->state == DC_QR_ADDR ); + assert( res->id != 0 ); dc_lot_unref(res); } } diff --git a/src/dc_aheader.c b/src/dc_aheader.c index cbd4b573..89acf43d 100644 --- a/src/dc_aheader.c +++ b/src/dc_aheader.c @@ -42,14 +42,14 @@ void dc_aheader_empty(dc_aheader_t* aheader) return; } - aheader->m_prefer_encrypt = 0; + aheader->prefer_encrypt = 0; - free(aheader->m_addr); - aheader->m_addr = NULL; + free(aheader->addr); + aheader->addr = NULL; - if( aheader->m_public_key->m_binary ) { - dc_key_unref(aheader->m_public_key); - aheader->m_public_key = dc_key_new(); + if( aheader->public_key->binary ) { + dc_key_unref(aheader->public_key); + aheader->public_key = dc_key_new(); } } @@ -69,15 +69,15 @@ char* dc_aheader_render(const dc_aheader_t* aheader) dc_strbuilder_t ret; dc_strbuilder_init(&ret, 0); - if( aheader==NULL || aheader->m_addr==NULL || aheader->m_public_key->m_binary==NULL || aheader->m_public_key->m_type!=DC_KEY_PUBLIC ) { + if( aheader==NULL || aheader->addr==NULL || aheader->public_key->binary==NULL || aheader->public_key->type!=DC_KEY_PUBLIC ) { goto cleanup; } dc_strbuilder_cat(&ret, "addr="); - dc_strbuilder_cat(&ret, aheader->m_addr); + dc_strbuilder_cat(&ret, aheader->addr); dc_strbuilder_cat(&ret, "; "); - if( aheader->m_prefer_encrypt==DC_PE_MUTUAL ) { + if( aheader->prefer_encrypt==DC_PE_MUTUAL ) { dc_strbuilder_cat(&ret, "prefer-encrypt=mutual; "); } @@ -85,7 +85,7 @@ char* dc_aheader_render(const dc_aheader_t* aheader) /* adds a whitespace every 78 characters, this allows libEtPan to wrap the lines according to RFC 5322 (which may insert a linebreak before every whitespace) */ - if( (keybase64_wrapped = dc_key_render_base64(aheader->m_public_key, 78, " ", 0/*no checksum*/)) == NULL ) { + if( (keybase64_wrapped = dc_key_render_base64(aheader->public_key, 78, " ", 0/*no checksum*/)) == NULL ) { goto cleanup; } @@ -94,9 +94,9 @@ char* dc_aheader_render(const dc_aheader_t* aheader) success = 1; cleanup: - if( !success ) { free(ret.m_buf); ret.m_buf = NULL; } + if( !success ) { free(ret.buf); ret.buf = NULL; } free(keybase64_wrapped); - return ret.m_buf; /* NULL on errors, this may happen for various reasons */ + return ret.buf; /* NULL on errors, this may happen for various reasons */ } @@ -112,10 +112,10 @@ static int add_attribute(dc_aheader_t* aheader, const char* name, const char* va { if( value == NULL || strlen(value) < 3 || strchr(value, '@')==NULL || strchr(value, '.')==NULL /* rough check if email-address is valid */ - || aheader->m_addr /* email already given */ ) { + || aheader->addr /* email already given */ ) { return 0; } - aheader->m_addr = dc_normalize_addr(value); + aheader->addr = dc_normalize_addr(value); return 1; } #if 0 /* autocrypt 11/2017 no longer uses the type attribute and it will make the autocrypt header invalid */ @@ -133,7 +133,7 @@ static int add_attribute(dc_aheader_t* aheader, const char* name, const char* va else if( strcasecmp(name, "prefer-encrypt")==0 ) { if( value && strcasecmp(value, "mutual")==0 ) { - aheader->m_prefer_encrypt = DC_PE_MUTUAL; + aheader->prefer_encrypt = DC_PE_MUTUAL; return 1; } return 1; /* An Autocrypt level 0 client that sees the attribute with any other value (or that does not see the attribute at all) should interpret the value as nopreference.*/ @@ -141,10 +141,10 @@ static int add_attribute(dc_aheader_t* aheader, const char* name, const char* va else if( strcasecmp(name, "keydata")==0 ) { if( value == NULL - || aheader->m_public_key->m_binary || aheader->m_public_key->m_bytes ) { + || aheader->public_key->binary || aheader->public_key->bytes ) { return 0; /* there is already a k*/ } - return dc_key_set_from_base64(aheader->m_public_key, value, DC_KEY_PUBLIC); + return dc_key_set_from_base64(aheader->public_key, value, DC_KEY_PUBLIC); } else if( name[0]=='_' ) { @@ -178,7 +178,7 @@ int dc_aheader_set_from_string(dc_aheader_t* aheader, const char* header_str__) goto cleanup; } - aheader->m_prefer_encrypt = DC_PE_NOPREFERENCE; /* value to use if the prefer-encrypted header is missing */ + aheader->prefer_encrypt = DC_PE_NOPREFERENCE; /* value to use if the prefer-encrypted header is missing */ header_str = dc_strdup(header_str__); p = header_str; @@ -218,7 +218,7 @@ int dc_aheader_set_from_string(dc_aheader_t* aheader, const char* header_str__) } /* all needed data found? */ - if( aheader->m_addr && aheader->m_public_key->m_binary ) { + if( aheader->addr && aheader->public_key->binary ) { success = 1; } @@ -245,7 +245,7 @@ dc_aheader_t* dc_aheader_new() exit(37); /* cannot allocate little memory, unrecoverable error */ } - aheader->m_public_key = dc_key_new(); + aheader->public_key = dc_key_new(); return aheader; } @@ -260,8 +260,8 @@ void dc_aheader_unref(dc_aheader_t* aheader) return; } - free(aheader->m_addr); - dc_key_unref(aheader->m_public_key); + free(aheader->addr); + dc_key_unref(aheader->public_key); free(aheader); } @@ -289,7 +289,7 @@ dc_aheader_t* dc_aheader_new_from_imffields(const char* wanted_from, const struc /* header found, check if it is valid and matched the wanted address */ dc_aheader_t* test = dc_aheader_new(); if( !dc_aheader_set_from_string(test, optional_field->fld_value) - || strcasecmp(test->m_addr, wanted_from)!=0 ) { + || strcasecmp(test->addr, wanted_from)!=0 ) { dc_aheader_unref(test); test = NULL; } diff --git a/src/dc_aheader.h b/src/dc_aheader.h index 486a9cce..421b929c 100644 --- a/src/dc_aheader.h +++ b/src/dc_aheader.h @@ -35,9 +35,9 @@ extern "C" { */ typedef struct dc_aheader_t { - char* m_addr; - dc_key_t* m_public_key; /* != NULL */ - int m_prefer_encrypt; /* YES, NO or NOPREFERENCE if attribute is missing */ + char* addr; + dc_key_t* public_key; /* != NULL */ + int prefer_encrypt; /* YES, NO or NOPREFERENCE if attribute is missing */ } dc_aheader_t; diff --git a/src/dc_apeerstate.c b/src/dc_apeerstate.c index cf9cf16b..9ce0f97b 100644 --- a/src/dc_apeerstate.c +++ b/src/dc_apeerstate.c @@ -37,72 +37,72 @@ static void dc_apeerstate_empty(dc_apeerstate_t* peerstate) return; } - peerstate->m_last_seen = 0; - peerstate->m_last_seen_autocrypt = 0; - peerstate->m_prefer_encrypt = 0; - peerstate->m_to_save = 0; + peerstate->last_seen = 0; + peerstate->last_seen_autocrypt = 0; + peerstate->prefer_encrypt = 0; + peerstate->to_save = 0; - free(peerstate->m_addr); - peerstate->m_addr = NULL; + free(peerstate->addr); + peerstate->addr = NULL; - free(peerstate->m_public_key_fingerprint); - peerstate->m_public_key_fingerprint = NULL; + free(peerstate->public_key_fingerprint); + peerstate->public_key_fingerprint = NULL; - free(peerstate->m_gossip_key_fingerprint); - peerstate->m_gossip_key_fingerprint = NULL; + free(peerstate->gossip_key_fingerprint); + peerstate->gossip_key_fingerprint = NULL; - free(peerstate->m_verified_key_fingerprint); - peerstate->m_verified_key_fingerprint = NULL; + free(peerstate->verified_key_fingerprint); + peerstate->verified_key_fingerprint = NULL; - if( peerstate->m_public_key ) { - dc_key_unref(peerstate->m_public_key); - peerstate->m_public_key = NULL; + if( peerstate->public_key ) { + dc_key_unref(peerstate->public_key); + peerstate->public_key = NULL; } - peerstate->m_gossip_timestamp = 0; + peerstate->gossip_timestamp = 0; - if( peerstate->m_gossip_key ) { - dc_key_unref(peerstate->m_gossip_key); - peerstate->m_gossip_key = NULL; + if( peerstate->gossip_key ) { + dc_key_unref(peerstate->gossip_key); + peerstate->gossip_key = NULL; } - if( peerstate->m_verified_key ) { - dc_key_unref(peerstate->m_verified_key); - peerstate->m_verified_key = NULL; + if( peerstate->verified_key ) { + dc_key_unref(peerstate->verified_key); + peerstate->verified_key = NULL; } - peerstate->m_degrade_event = 0; + peerstate->degrade_event = 0; } static void dc_apeerstate_set_from_stmt__(dc_apeerstate_t* peerstate, sqlite3_stmt* stmt) { #define PEERSTATE_FIELDS "addr, last_seen, last_seen_autocrypt, prefer_encrypted, public_key, gossip_timestamp, gossip_key, public_key_fingerprint, gossip_key_fingerprint, verified_key, verified_key_fingerprint" - peerstate->m_addr = dc_strdup((char*)sqlite3_column_text (stmt, 0)); - peerstate->m_last_seen = sqlite3_column_int64 (stmt, 1); - peerstate->m_last_seen_autocrypt = sqlite3_column_int64 (stmt, 2); - peerstate->m_prefer_encrypt = sqlite3_column_int (stmt, 3); + peerstate->addr = dc_strdup((char*)sqlite3_column_text (stmt, 0)); + peerstate->last_seen = sqlite3_column_int64 (stmt, 1); + peerstate->last_seen_autocrypt = sqlite3_column_int64 (stmt, 2); + peerstate->prefer_encrypt = sqlite3_column_int (stmt, 3); #define PUBLIC_KEY_COL 4 - peerstate->m_gossip_timestamp = sqlite3_column_int (stmt, 5); + peerstate->gossip_timestamp = sqlite3_column_int (stmt, 5); #define GOSSIP_KEY_COL 6 - peerstate->m_public_key_fingerprint = dc_strdup((char*)sqlite3_column_text (stmt, 7)); - peerstate->m_gossip_key_fingerprint = dc_strdup((char*)sqlite3_column_text (stmt, 8)); + peerstate->public_key_fingerprint = dc_strdup((char*)sqlite3_column_text (stmt, 7)); + peerstate->gossip_key_fingerprint = dc_strdup((char*)sqlite3_column_text (stmt, 8)); #define VERIFIED_KEY_COL 9 - peerstate->m_verified_key_fingerprint = dc_strdup((char*)sqlite3_column_text(stmt, 10)); + peerstate->verified_key_fingerprint = dc_strdup((char*)sqlite3_column_text(stmt, 10)); if( sqlite3_column_type(stmt, PUBLIC_KEY_COL)!=SQLITE_NULL ) { - peerstate->m_public_key = dc_key_new(); - dc_key_set_from_stmt(peerstate->m_public_key, stmt, PUBLIC_KEY_COL, DC_KEY_PUBLIC); + peerstate->public_key = dc_key_new(); + dc_key_set_from_stmt(peerstate->public_key, stmt, PUBLIC_KEY_COL, DC_KEY_PUBLIC); } if( sqlite3_column_type(stmt, GOSSIP_KEY_COL)!=SQLITE_NULL ) { - peerstate->m_gossip_key = dc_key_new(); - dc_key_set_from_stmt(peerstate->m_gossip_key, stmt, GOSSIP_KEY_COL, DC_KEY_PUBLIC); + peerstate->gossip_key = dc_key_new(); + dc_key_set_from_stmt(peerstate->gossip_key, stmt, GOSSIP_KEY_COL, DC_KEY_PUBLIC); } if( sqlite3_column_type(stmt, VERIFIED_KEY_COL)!=SQLITE_NULL ) { - peerstate->m_verified_key = dc_key_new(); - dc_key_set_from_stmt(peerstate->m_verified_key, stmt, VERIFIED_KEY_COL, DC_KEY_PUBLIC); + peerstate->verified_key = dc_key_new(); + dc_key_set_from_stmt(peerstate->verified_key, stmt, VERIFIED_KEY_COL, DC_KEY_PUBLIC); } } @@ -174,50 +174,50 @@ int dc_apeerstate_save_to_db(const dc_apeerstate_t* peerstate, dc_sqlite3_t* sql int success = 0; sqlite3_stmt* stmt = NULL; - if( peerstate==NULL || sql==NULL || peerstate->m_addr==NULL ) { + if( peerstate==NULL || sql==NULL || peerstate->addr==NULL ) { return 0; } if( create ) { stmt = dc_sqlite3_prepare(sql, "INSERT INTO acpeerstates (addr) VALUES(?);"); - sqlite3_bind_text(stmt, 1, peerstate->m_addr, -1, SQLITE_STATIC); + sqlite3_bind_text(stmt, 1, peerstate->addr, -1, SQLITE_STATIC); sqlite3_step(stmt); sqlite3_finalize(stmt); stmt = NULL; } - if( (peerstate->m_to_save&DC_SAVE_ALL) || create ) + if( (peerstate->to_save&DC_SAVE_ALL) || create ) { stmt = dc_sqlite3_prepare(sql, "UPDATE acpeerstates " " SET last_seen=?, last_seen_autocrypt=?, prefer_encrypted=?, " " public_key=?, gossip_timestamp=?, gossip_key=?, public_key_fingerprint=?, gossip_key_fingerprint=?, verified_key=?, verified_key_fingerprint=? " " WHERE addr=?;"); - sqlite3_bind_int64(stmt, 1, peerstate->m_last_seen); - sqlite3_bind_int64(stmt, 2, peerstate->m_last_seen_autocrypt); - sqlite3_bind_int64(stmt, 3, peerstate->m_prefer_encrypt); - sqlite3_bind_blob (stmt, 4, peerstate->m_public_key? peerstate->m_public_key->m_binary : NULL/*results in sqlite3_bind_null()*/, peerstate->m_public_key? peerstate->m_public_key->m_bytes : 0, SQLITE_STATIC); - sqlite3_bind_int64(stmt, 5, peerstate->m_gossip_timestamp); - sqlite3_bind_blob (stmt, 6, peerstate->m_gossip_key? peerstate->m_gossip_key->m_binary : NULL/*results in sqlite3_bind_null()*/, peerstate->m_gossip_key? peerstate->m_gossip_key->m_bytes : 0, SQLITE_STATIC); - sqlite3_bind_text (stmt, 7, peerstate->m_public_key_fingerprint, -1, SQLITE_STATIC); - sqlite3_bind_text (stmt, 8, peerstate->m_gossip_key_fingerprint, -1, SQLITE_STATIC); - sqlite3_bind_blob (stmt, 9, peerstate->m_verified_key? peerstate->m_verified_key->m_binary : NULL/*results in sqlite3_bind_null()*/, peerstate->m_verified_key? peerstate->m_verified_key->m_bytes : 0, SQLITE_STATIC); - sqlite3_bind_text (stmt,10, peerstate->m_verified_key_fingerprint, -1, SQLITE_STATIC); - sqlite3_bind_text (stmt,11, peerstate->m_addr, -1, SQLITE_STATIC); + sqlite3_bind_int64(stmt, 1, peerstate->last_seen); + sqlite3_bind_int64(stmt, 2, peerstate->last_seen_autocrypt); + sqlite3_bind_int64(stmt, 3, peerstate->prefer_encrypt); + sqlite3_bind_blob (stmt, 4, peerstate->public_key? peerstate->public_key->binary : NULL/*results in sqlite3_bind_null()*/, peerstate->public_key? peerstate->public_key->bytes : 0, SQLITE_STATIC); + sqlite3_bind_int64(stmt, 5, peerstate->gossip_timestamp); + sqlite3_bind_blob (stmt, 6, peerstate->gossip_key? peerstate->gossip_key->binary : NULL/*results in sqlite3_bind_null()*/, peerstate->gossip_key? peerstate->gossip_key->bytes : 0, SQLITE_STATIC); + sqlite3_bind_text (stmt, 7, peerstate->public_key_fingerprint, -1, SQLITE_STATIC); + sqlite3_bind_text (stmt, 8, peerstate->gossip_key_fingerprint, -1, SQLITE_STATIC); + sqlite3_bind_blob (stmt, 9, peerstate->verified_key? peerstate->verified_key->binary : NULL/*results in sqlite3_bind_null()*/, peerstate->verified_key? peerstate->verified_key->bytes : 0, SQLITE_STATIC); + sqlite3_bind_text (stmt,10, peerstate->verified_key_fingerprint, -1, SQLITE_STATIC); + sqlite3_bind_text (stmt,11, peerstate->addr, -1, SQLITE_STATIC); if( sqlite3_step(stmt) != SQLITE_DONE ) { goto cleanup; } sqlite3_finalize(stmt); stmt = NULL; } - else if( peerstate->m_to_save&DC_SAVE_TIMESTAMPS ) + else if( peerstate->to_save&DC_SAVE_TIMESTAMPS ) { stmt = dc_sqlite3_prepare(sql, "UPDATE acpeerstates SET last_seen=?, last_seen_autocrypt=?, gossip_timestamp=? WHERE addr=?;"); - sqlite3_bind_int64(stmt, 1, peerstate->m_last_seen); - sqlite3_bind_int64(stmt, 2, peerstate->m_last_seen_autocrypt); - sqlite3_bind_int64(stmt, 3, peerstate->m_gossip_timestamp); - sqlite3_bind_text (stmt, 4, peerstate->m_addr, -1, SQLITE_STATIC); + sqlite3_bind_int64(stmt, 1, peerstate->last_seen); + sqlite3_bind_int64(stmt, 2, peerstate->last_seen_autocrypt); + sqlite3_bind_int64(stmt, 3, peerstate->gossip_timestamp); + sqlite3_bind_text (stmt, 4, peerstate->addr, -1, SQLITE_STATIC); if( sqlite3_step(stmt) != SQLITE_DONE ) { goto cleanup; } @@ -246,7 +246,7 @@ dc_apeerstate_t* dc_apeerstate_new(dc_context_t* context) exit(43); /* cannot allocate little memory, unrecoverable error */ } - peerstate->m_context = context; + peerstate->context = context; return peerstate; } @@ -258,16 +258,16 @@ void dc_apeerstate_unref(dc_apeerstate_t* peerstate) return; } - free(peerstate->m_addr); - dc_key_unref(peerstate->m_public_key); - dc_key_unref(peerstate->m_gossip_key); + free(peerstate->addr); + dc_key_unref(peerstate->public_key); + dc_key_unref(peerstate->gossip_key); free(peerstate); } /** * Render an Autocrypt-Gossip header value. The contained key is either - * m_public_key or m_gossip_key if m_public_key is NULL. + * public_key or gossip_key if public_key is NULL. * * @memberof dc_apeerstate_t * @@ -282,13 +282,13 @@ char* dc_apeerstate_render_gossip_header(const dc_apeerstate_t* peerstate, int m char* ret = NULL; dc_aheader_t* autocryptheader = dc_aheader_new(); - if( peerstate == NULL || peerstate->m_addr == NULL ) { + if( peerstate == NULL || peerstate->addr == NULL ) { goto cleanup; } - autocryptheader->m_prefer_encrypt = DC_PE_NOPREFERENCE; /* the spec says, we SHOULD NOT gossip this flag */ - autocryptheader->m_addr = dc_strdup(peerstate->m_addr); - autocryptheader->m_public_key = dc_key_ref(dc_apeerstate_peek_key(peerstate, min_verified)); /* may be NULL */ + autocryptheader->prefer_encrypt = DC_PE_NOPREFERENCE; /* the spec says, we SHOULD NOT gossip this flag */ + autocryptheader->addr = dc_strdup(peerstate->addr); + autocryptheader->public_key = dc_key_ref(dc_apeerstate_peek_key(peerstate, min_verified)); /* may be NULL */ ret = dc_aheader_render(autocryptheader); @@ -299,7 +299,7 @@ cleanup: /** - * Return either m_public_key or m_gossip_key if m_public_key is null or not verified. + * Return either public_key or gossip_key if public_key is null or not verified. * The function does not check if the keys are valid but the caller can assume * the returned key has data. * @@ -313,29 +313,29 @@ cleanup: * Typically either DC_NOT_VERIFIED (0) if there is no need for the key being verified * or DC_BIDIRECT_VERIFIED (2) for bidirectional verification requirement. * - * @return m_public_key or m_gossip_key, NULL if nothing is available. + * @return public_key or gossip_key, NULL if nothing is available. * the returned pointer MUST NOT be unref()'d. */ dc_key_t* dc_apeerstate_peek_key(const dc_apeerstate_t* peerstate, int min_verified) { if( peerstate == NULL - || (peerstate->m_public_key && (peerstate->m_public_key->m_binary==NULL || peerstate->m_public_key->m_bytes<=0)) - || (peerstate->m_gossip_key && (peerstate->m_gossip_key->m_binary==NULL || peerstate->m_gossip_key->m_bytes<=0)) - || (peerstate->m_verified_key && (peerstate->m_verified_key->m_binary==NULL || peerstate->m_verified_key->m_bytes<=0)) ) { + || (peerstate->public_key && (peerstate->public_key->binary==NULL || peerstate->public_key->bytes<=0)) + || (peerstate->gossip_key && (peerstate->gossip_key->binary==NULL || peerstate->gossip_key->bytes<=0)) + || (peerstate->verified_key && (peerstate->verified_key->binary==NULL || peerstate->verified_key->bytes<=0)) ) { return NULL; } if( min_verified ) { - return peerstate->m_verified_key; + return peerstate->verified_key; } - if( peerstate->m_public_key ) + if( peerstate->public_key ) { - return peerstate->m_public_key; + return peerstate->public_key; } - return peerstate->m_gossip_key; + return peerstate->gossip_key; } @@ -351,14 +351,14 @@ int dc_apeerstate_init_from_header(dc_apeerstate_t* peerstate, const dc_aheader_ } dc_apeerstate_empty(peerstate); - peerstate->m_addr = dc_strdup(header->m_addr); - peerstate->m_last_seen = message_time; - peerstate->m_last_seen_autocrypt = message_time; - peerstate->m_to_save = DC_SAVE_ALL; - peerstate->m_prefer_encrypt = header->m_prefer_encrypt; + peerstate->addr = dc_strdup(header->addr); + peerstate->last_seen = message_time; + peerstate->last_seen_autocrypt = message_time; + peerstate->to_save = DC_SAVE_ALL; + peerstate->prefer_encrypt = header->prefer_encrypt; - peerstate->m_public_key = dc_key_new(); - dc_key_set_from_key(peerstate->m_public_key, header->m_public_key); + peerstate->public_key = dc_key_new(); + dc_key_set_from_key(peerstate->public_key, header->public_key); dc_apeerstate_recalc_fingerprint(peerstate); return 1; @@ -372,12 +372,12 @@ int dc_apeerstate_init_from_gossip(dc_apeerstate_t* peerstate, const dc_aheader_ } dc_apeerstate_empty(peerstate); - peerstate->m_addr = dc_strdup(gossip_header->m_addr); - peerstate->m_gossip_timestamp = message_time; - peerstate->m_to_save = DC_SAVE_ALL; + peerstate->addr = dc_strdup(gossip_header->addr); + peerstate->gossip_timestamp = message_time; + peerstate->to_save = DC_SAVE_ALL; - peerstate->m_gossip_key = dc_key_new(); - dc_key_set_from_key(peerstate->m_gossip_key, gossip_header->m_public_key); + peerstate->gossip_key = dc_key_new(); + dc_key_set_from_key(peerstate->gossip_key, gossip_header->public_key); dc_apeerstate_recalc_fingerprint(peerstate); return 1; @@ -390,13 +390,13 @@ int dc_apeerstate_degrade_encryption(dc_apeerstate_t* peerstate, time_t message_ return 0; } - if( peerstate->m_prefer_encrypt == DC_PE_MUTUAL ) { - peerstate->m_degrade_event |= DC_DE_ENCRYPTION_PAUSED; + if( peerstate->prefer_encrypt == DC_PE_MUTUAL ) { + peerstate->degrade_event |= DC_DE_ENCRYPTION_PAUSED; } - peerstate->m_prefer_encrypt = DC_PE_RESET; - peerstate->m_last_seen = message_time; /*last_seen_autocrypt is not updated as there was not Autocrypt:-header seen*/ - peerstate->m_to_save = DC_SAVE_ALL; + peerstate->prefer_encrypt = DC_PE_RESET; + peerstate->last_seen = message_time; /*last_seen_autocrypt is not updated as there was not Autocrypt:-header seen*/ + peerstate->to_save = DC_SAVE_ALL; return 1; } @@ -405,38 +405,38 @@ int dc_apeerstate_degrade_encryption(dc_apeerstate_t* peerstate, time_t message_ void dc_apeerstate_apply_header(dc_apeerstate_t* peerstate, const dc_aheader_t* header, time_t message_time) { if( peerstate==NULL || header==NULL - || peerstate->m_addr==NULL - || header->m_addr==NULL || header->m_public_key->m_binary==NULL - || strcasecmp(peerstate->m_addr, header->m_addr)!=0 ) { + || peerstate->addr==NULL + || header->addr==NULL || header->public_key->binary==NULL + || strcasecmp(peerstate->addr, header->addr)!=0 ) { return; } - if( message_time > peerstate->m_last_seen_autocrypt ) + if( message_time > peerstate->last_seen_autocrypt ) { - peerstate->m_last_seen = message_time; - peerstate->m_last_seen_autocrypt = message_time; - peerstate->m_to_save |= DC_SAVE_TIMESTAMPS; + peerstate->last_seen = message_time; + peerstate->last_seen_autocrypt = message_time; + peerstate->to_save |= DC_SAVE_TIMESTAMPS; - if( (header->m_prefer_encrypt==DC_PE_MUTUAL || header->m_prefer_encrypt==DC_PE_NOPREFERENCE) /*this also switches from DC_PE_RESET to DC_PE_NOPREFERENCE, which is just fine as the function is only called _if_ the Autocrypt:-header is preset at all */ - && header->m_prefer_encrypt != peerstate->m_prefer_encrypt ) + if( (header->prefer_encrypt==DC_PE_MUTUAL || header->prefer_encrypt==DC_PE_NOPREFERENCE) /*this also switches from DC_PE_RESET to DC_PE_NOPREFERENCE, which is just fine as the function is only called _if_ the Autocrypt:-header is preset at all */ + && header->prefer_encrypt != peerstate->prefer_encrypt ) { - if( peerstate->m_prefer_encrypt == DC_PE_MUTUAL && header->m_prefer_encrypt != DC_PE_MUTUAL ) { - peerstate->m_degrade_event |= DC_DE_ENCRYPTION_PAUSED; + if( peerstate->prefer_encrypt == DC_PE_MUTUAL && header->prefer_encrypt != DC_PE_MUTUAL ) { + peerstate->degrade_event |= DC_DE_ENCRYPTION_PAUSED; } - peerstate->m_prefer_encrypt = header->m_prefer_encrypt; - peerstate->m_to_save |= DC_SAVE_ALL; + peerstate->prefer_encrypt = header->prefer_encrypt; + peerstate->to_save |= DC_SAVE_ALL; } - if( peerstate->m_public_key == NULL ) { - peerstate->m_public_key = dc_key_new(); + if( peerstate->public_key == NULL ) { + peerstate->public_key = dc_key_new(); } - if( !dc_key_equals(peerstate->m_public_key, header->m_public_key) ) + if( !dc_key_equals(peerstate->public_key, header->public_key) ) { - dc_key_set_from_key(peerstate->m_public_key, header->m_public_key); + dc_key_set_from_key(peerstate->public_key, header->public_key); dc_apeerstate_recalc_fingerprint(peerstate); - peerstate->m_to_save |= DC_SAVE_ALL; + peerstate->to_save |= DC_SAVE_ALL; } } } @@ -445,26 +445,26 @@ void dc_apeerstate_apply_header(dc_apeerstate_t* peerstate, const dc_aheader_t* void dc_apeerstate_apply_gossip(dc_apeerstate_t* peerstate, const dc_aheader_t* gossip_header, time_t message_time) { if( peerstate==NULL || gossip_header==NULL - || peerstate->m_addr==NULL - || gossip_header->m_addr==NULL || gossip_header->m_public_key->m_binary==NULL - || strcasecmp(peerstate->m_addr, gossip_header->m_addr)!=0 ) { + || peerstate->addr==NULL + || gossip_header->addr==NULL || gossip_header->public_key->binary==NULL + || strcasecmp(peerstate->addr, gossip_header->addr)!=0 ) { return; } - if( message_time > peerstate->m_gossip_timestamp ) + if( message_time > peerstate->gossip_timestamp ) { - peerstate->m_gossip_timestamp = message_time; - peerstate->m_to_save |= DC_SAVE_TIMESTAMPS; + peerstate->gossip_timestamp = message_time; + peerstate->to_save |= DC_SAVE_TIMESTAMPS; - if( peerstate->m_gossip_key == NULL ) { - peerstate->m_gossip_key = dc_key_new(); + if( peerstate->gossip_key == NULL ) { + peerstate->gossip_key = dc_key_new(); } - if( !dc_key_equals(peerstate->m_gossip_key, gossip_header->m_public_key) ) + if( !dc_key_equals(peerstate->gossip_key, gossip_header->public_key) ) { - dc_key_set_from_key(peerstate->m_gossip_key, gossip_header->m_public_key); + dc_key_set_from_key(peerstate->gossip_key, gossip_header->public_key); dc_apeerstate_recalc_fingerprint(peerstate); - peerstate->m_to_save |= DC_SAVE_ALL; + peerstate->to_save |= DC_SAVE_ALL; } } } @@ -488,40 +488,40 @@ int dc_apeerstate_recalc_fingerprint(dc_apeerstate_t* peerstate) goto cleanup; } - if( peerstate->m_public_key ) + if( peerstate->public_key ) { - old_public_fingerprint = peerstate->m_public_key_fingerprint; - peerstate->m_public_key_fingerprint = dc_key_get_fingerprint(peerstate->m_public_key); /* returns the empty string for errors, however, this should be saved as well as it represents an erroneous key */ + old_public_fingerprint = peerstate->public_key_fingerprint; + peerstate->public_key_fingerprint = dc_key_get_fingerprint(peerstate->public_key); /* returns the empty string for errors, however, this should be saved as well as it represents an erroneous key */ if( old_public_fingerprint == NULL || old_public_fingerprint[0] == 0 - || peerstate->m_public_key_fingerprint == NULL - || peerstate->m_public_key_fingerprint[0] == 0 - || strcasecmp(old_public_fingerprint, peerstate->m_public_key_fingerprint) != 0 ) + || peerstate->public_key_fingerprint == NULL + || peerstate->public_key_fingerprint[0] == 0 + || strcasecmp(old_public_fingerprint, peerstate->public_key_fingerprint) != 0 ) { - peerstate->m_to_save |= DC_SAVE_ALL; + peerstate->to_save |= DC_SAVE_ALL; if( old_public_fingerprint && old_public_fingerprint[0] ) { // no degrade event when we recveive just the initial fingerprint - peerstate->m_degrade_event |= DC_DE_FINGERPRINT_CHANGED; + peerstate->degrade_event |= DC_DE_FINGERPRINT_CHANGED; } } } - if( peerstate->m_gossip_key ) + if( peerstate->gossip_key ) { - old_gossip_fingerprint = peerstate->m_gossip_key_fingerprint; - peerstate->m_gossip_key_fingerprint = dc_key_get_fingerprint(peerstate->m_gossip_key); /* returns the empty string for errors, however, this should be saved as well as it represents an erroneous key */ + old_gossip_fingerprint = peerstate->gossip_key_fingerprint; + peerstate->gossip_key_fingerprint = dc_key_get_fingerprint(peerstate->gossip_key); /* returns the empty string for errors, however, this should be saved as well as it represents an erroneous key */ if( old_gossip_fingerprint == NULL || old_gossip_fingerprint[0] == 0 - || peerstate->m_gossip_key_fingerprint == NULL - || peerstate->m_gossip_key_fingerprint[0] == 0 - || strcasecmp(old_gossip_fingerprint, peerstate->m_gossip_key_fingerprint) != 0 ) + || peerstate->gossip_key_fingerprint == NULL + || peerstate->gossip_key_fingerprint[0] == 0 + || strcasecmp(old_gossip_fingerprint, peerstate->gossip_key_fingerprint) != 0 ) { - peerstate->m_to_save |= DC_SAVE_ALL; + peerstate->to_save |= DC_SAVE_ALL; if( old_gossip_fingerprint && old_gossip_fingerprint[0] ) { // no degrade event when we recveive just the initial fingerprint - peerstate->m_degrade_event |= DC_DE_FINGERPRINT_CHANGED; + peerstate->degrade_event |= DC_DE_FINGERPRINT_CHANGED; } } } @@ -566,26 +566,26 @@ int dc_apeerstate_set_verified(dc_apeerstate_t* peerstate, int which_key, const } if( which_key == DC_PS_PUBLIC_KEY - && peerstate->m_public_key_fingerprint != NULL - && peerstate->m_public_key_fingerprint[0] != 0 + && peerstate->public_key_fingerprint != NULL + && peerstate->public_key_fingerprint[0] != 0 && fingerprint[0] != 0 - && strcasecmp(peerstate->m_public_key_fingerprint, fingerprint) == 0 ) + && strcasecmp(peerstate->public_key_fingerprint, fingerprint) == 0 ) { - peerstate->m_to_save |= DC_SAVE_ALL; - peerstate->m_verified_key = dc_key_ref(peerstate->m_public_key); - peerstate->m_verified_key_fingerprint = dc_strdup(peerstate->m_public_key_fingerprint); + peerstate->to_save |= DC_SAVE_ALL; + peerstate->verified_key = dc_key_ref(peerstate->public_key); + peerstate->verified_key_fingerprint = dc_strdup(peerstate->public_key_fingerprint); success = 1; } if( which_key == DC_PS_GOSSIP_KEY - && peerstate->m_gossip_key_fingerprint != NULL - && peerstate->m_gossip_key_fingerprint[0] != 0 + && peerstate->gossip_key_fingerprint != NULL + && peerstate->gossip_key_fingerprint[0] != 0 && fingerprint[0] != 0 - && strcasecmp(peerstate->m_gossip_key_fingerprint, fingerprint) == 0 ) + && strcasecmp(peerstate->gossip_key_fingerprint, fingerprint) == 0 ) { - peerstate->m_to_save |= DC_SAVE_ALL; - peerstate->m_verified_key = dc_key_ref(peerstate->m_gossip_key); - peerstate->m_verified_key_fingerprint = dc_strdup(peerstate->m_gossip_key_fingerprint); + peerstate->to_save |= DC_SAVE_ALL; + peerstate->verified_key = dc_key_ref(peerstate->gossip_key); + peerstate->verified_key_fingerprint = dc_strdup(peerstate->gossip_key_fingerprint); success = 1; } @@ -600,9 +600,9 @@ int dc_apeerstate_has_verified_key(const dc_apeerstate_t* peerstate, const dc_ha return 0; } - if( peerstate->m_verified_key - && peerstate->m_verified_key_fingerprint - && dc_hash_find_str(fingerprints, peerstate->m_verified_key_fingerprint) ) { + if( peerstate->verified_key + && peerstate->verified_key_fingerprint + && dc_hash_find_str(fingerprints, peerstate->verified_key_fingerprint) ) { return 1; } diff --git a/src/dc_apeerstate.h b/src/dc_apeerstate.h index b53dbf28..bc74eca4 100644 --- a/src/dc_apeerstate.h +++ b/src/dc_apeerstate.h @@ -44,34 +44,34 @@ typedef struct dc_aheader_t dc_aheader_t; typedef struct dc_apeerstate_t { /** @privatesection */ - dc_context_t* m_context; + dc_context_t* context; - char* m_addr; - time_t m_last_seen; /* may be 0 if the peer was created by gossipping */ + char* addr; + time_t last_seen; /* may be 0 if the peer was created by gossipping */ - time_t m_last_seen_autocrypt; - int m_prefer_encrypt; + time_t last_seen_autocrypt; + int prefer_encrypt; #define DC_NOT_VERIFIED 0 #define DC_BIDIRECT_VERIFIED 2 - dc_key_t* m_public_key; /* may be NULL, however, in the database, either public_key or gossip_key is set */ - char* m_public_key_fingerprint; + dc_key_t* public_key; /* may be NULL, however, in the database, either public_key or gossip_key is set */ + char* public_key_fingerprint; - dc_key_t* m_gossip_key; /* may be NULL */ - time_t m_gossip_timestamp; - char* m_gossip_key_fingerprint; + dc_key_t* gossip_key; /* may be NULL */ + time_t gossip_timestamp; + char* gossip_key_fingerprint; - dc_key_t* m_verified_key; // may be NULL - char* m_verified_key_fingerprint; + dc_key_t* verified_key; // may be NULL + char* verified_key_fingerprint; #define DC_SAVE_TIMESTAMPS 0x01 #define DC_SAVE_ALL 0x02 - int m_to_save; + int to_save; #define DC_DE_ENCRYPTION_PAUSED 0x01 // recoverable by an incoming encrypted mail #define DC_DE_FINGERPRINT_CHANGED 0x02 // recoverable by a new verify - int m_degrade_event; + int degrade_event; } dc_apeerstate_t; diff --git a/src/dc_array.c b/src/dc_array.c index 9862347a..365c8b79 100644 --- a/src/dc_array.c +++ b/src/dc_array.c @@ -45,12 +45,12 @@ dc_array_t* dc_array_new(dc_context_t* context, size_t initsize) exit(47); } - array->m_magic = DC_ARRAY_MAGIC; - array->m_context = context; - array->m_count = 0; - array->m_allocated = initsize < 1? 1 : initsize; - array->m_array = malloc(array->m_allocated * sizeof(uintptr_t)); - if( array->m_array==NULL ) { + array->magic = DC_ARRAY_MAGIC; + array->context = context; + array->count = 0; + array->allocated = initsize < 1? 1 : initsize; + array->array = malloc(array->allocated * sizeof(uintptr_t)); + if( array->array==NULL ) { exit(48); } @@ -70,12 +70,12 @@ dc_array_t* dc_array_new(dc_context_t* context, size_t initsize) */ void dc_array_unref(dc_array_t* array) { - if( array==NULL || array->m_magic != DC_ARRAY_MAGIC ) { + if( array==NULL || array->magic != DC_ARRAY_MAGIC ) { return; } - free(array->m_array); - array->m_magic = 0; + free(array->array); + array->magic = 0; free(array); } @@ -95,13 +95,13 @@ void dc_array_free_ptr(dc_array_t* array) { size_t i; - if( array==NULL || array->m_magic != DC_ARRAY_MAGIC ) { + if( array==NULL || array->magic != DC_ARRAY_MAGIC ) { return; } - for( i = 0; i < array->m_count; i++ ) { - free((void*)array->m_array[i]); - array->m_array[i] = 0; + for( i = 0; i < array->count; i++ ) { + free((void*)array->array[i]); + array->array[i] = 0; } } @@ -121,13 +121,13 @@ dc_array_t* dc_array_duplicate(const dc_array_t* array) { dc_array_t* ret = NULL; - if( array==NULL || array->m_magic != DC_ARRAY_MAGIC ) { + if( array==NULL || array->magic != DC_ARRAY_MAGIC ) { return NULL; } - ret = dc_array_new(array->m_context, array->m_allocated); - ret->m_count = array->m_count; - memcpy(ret->m_array, array->m_array, array->m_count * sizeof(uintptr_t)); + ret = dc_array_new(array->context, array->allocated); + ret->count = array->count; + memcpy(ret->array, array->array, array->count * sizeof(uintptr_t)); return ret; } @@ -152,10 +152,10 @@ static int cmp_intptr_t(const void* p1, const void* p2) */ void dc_array_sort_ids(dc_array_t* array) { - if( array == NULL || array->m_magic != DC_ARRAY_MAGIC || array->m_count <= 1 ) { + if( array == NULL || array->magic != DC_ARRAY_MAGIC || array->count <= 1 ) { return; } - qsort(array->m_array, array->m_count, sizeof(uintptr_t), cmp_intptr_t); + qsort(array->array, array->count, sizeof(uintptr_t), cmp_intptr_t); } @@ -179,10 +179,10 @@ static int cmp_strings_t(const void* p1, const void* p2) */ void dc_array_sort_strings(dc_array_t* array) { - if( array == NULL || array->m_magic != DC_ARRAY_MAGIC || array->m_count <= 1 ) { + if( array == NULL || array->magic != DC_ARRAY_MAGIC || array->count <= 1 ) { return; } - qsort(array->m_array, array->m_count, sizeof(char*), cmp_strings_t); + qsort(array->array, array->count, sizeof(char*), cmp_strings_t); } @@ -197,11 +197,11 @@ void dc_array_sort_strings(dc_array_t* array) */ void dc_array_empty(dc_array_t* array) { - if( array == NULL || array->m_magic != DC_ARRAY_MAGIC ) { + if( array == NULL || array->magic != DC_ARRAY_MAGIC ) { return; } - array->m_count = 0; + array->count = 0; } @@ -218,20 +218,20 @@ void dc_array_empty(dc_array_t* array) */ void dc_array_add_uint(dc_array_t* array, uintptr_t item) { - if( array == NULL || array->m_magic != DC_ARRAY_MAGIC ) { + if( array == NULL || array->magic != DC_ARRAY_MAGIC ) { return; } - if( array->m_count == array->m_allocated ) { - int newsize = (array->m_allocated * 2) + 10; - if( (array->m_array=realloc(array->m_array, newsize*sizeof(uintptr_t)))==NULL ) { + if( array->count == array->allocated ) { + int newsize = (array->allocated * 2) + 10; + if( (array->array=realloc(array->array, newsize*sizeof(uintptr_t)))==NULL ) { exit(49); } - array->m_allocated = newsize; + array->allocated = newsize; } - array->m_array[array->m_count] = item; - array->m_count++; + array->array[array->count] = item; + array->count++; } @@ -280,11 +280,11 @@ void dc_array_add_ptr(dc_array_t* array, void* item) */ size_t dc_array_get_cnt(const dc_array_t* array) { - if( array == NULL || array->m_magic != DC_ARRAY_MAGIC ) { + if( array == NULL || array->magic != DC_ARRAY_MAGIC ) { return 0; } - return array->m_count; + return array->count; } @@ -301,11 +301,11 @@ size_t dc_array_get_cnt(const dc_array_t* array) */ uintptr_t dc_array_get_uint(const dc_array_t* array, size_t index) { - if( array == NULL || array->m_magic != DC_ARRAY_MAGIC || index < 0 || index >= array->m_count ) { + if( array == NULL || array->magic != DC_ARRAY_MAGIC || index < 0 || index >= array->count ) { return 0; } - return array->m_array[index]; + return array->array[index]; } @@ -321,11 +321,11 @@ uintptr_t dc_array_get_uint(const dc_array_t* array, size_t index) */ uint32_t dc_array_get_id(const dc_array_t* array, size_t index) { - if( array == NULL || array->m_magic != DC_ARRAY_MAGIC || index < 0 || index >= array->m_count ) { + if( array == NULL || array->magic != DC_ARRAY_MAGIC || index < 0 || index >= array->count ) { return 0; } - return (uint32_t)array->m_array[index]; + return (uint32_t)array->array[index]; } @@ -341,11 +341,11 @@ uint32_t dc_array_get_id(const dc_array_t* array, size_t index) */ void* dc_array_get_ptr(const dc_array_t* array, size_t index) { - if( array == NULL || array->m_magic != DC_ARRAY_MAGIC || index < 0 || index >= array->m_count ) { + if( array == NULL || array->magic != DC_ARRAY_MAGIC || index < 0 || index >= array->count ) { return 0; } - return (void*)array->m_array[index]; + return (void*)array->array[index]; } @@ -362,12 +362,12 @@ void* dc_array_get_ptr(const dc_array_t* array, size_t index) */ int dc_array_search_id(const dc_array_t* array, uint32_t needle, size_t* ret_index) { - if( array == NULL || array->m_magic != DC_ARRAY_MAGIC ) { + if( array == NULL || array->magic != DC_ARRAY_MAGIC ) { return 0; } - uintptr_t* data = array->m_array; - size_t i, cnt = array->m_count; + uintptr_t* data = array->array; + size_t i, cnt = array->count; for( i=0; im_magic != DC_ARRAY_MAGIC ) { + if( array == NULL || array->magic != DC_ARRAY_MAGIC ) { return NULL; } - return array->m_array; + return array->array; } @@ -435,11 +435,11 @@ char* dc_array_get_string(const dc_array_t* array, const char* sep) { char* ret = NULL; - if( array == NULL || array->m_magic != DC_ARRAY_MAGIC || sep==NULL ) { + if( array == NULL || array->magic != DC_ARRAY_MAGIC || sep==NULL ) { return dc_strdup(""); } - INT_ARR_TO_STR(array->m_array, array->m_count); + INT_ARR_TO_STR(array->array, array->count); return ret; } diff --git a/src/dc_array.h b/src/dc_array.h index fecdcb0c..5554f0c5 100644 --- a/src/dc_array.h +++ b/src/dc_array.h @@ -32,11 +32,11 @@ struct _dc_array { /** @privatesection */ - uint32_t m_magic; - dc_context_t* m_context; /**< The context the array belongs to. May be NULL when NULL is given to dc_array_new(). */ - size_t m_allocated; /**< The number of allocated items. Initially ~ 200. */ - size_t m_count; /**< The number of used items. Initially 0. */ - uintptr_t* m_array; /**< The data items, can be used between m_data[0] and m_data[m_cnt-1]. Never NULL. */ + uint32_t magic; + dc_context_t* context; /**< The context the array belongs to. May be NULL when NULL is given to dc_array_new(). */ + size_t allocated; /**< The number of allocated items. Initially ~ 200. */ + size_t count; /**< The number of used items. Initially 0. */ + uintptr_t* array; /**< The data items, can be used between data[0] and data[cnt-1]. Never NULL. */ }; diff --git a/src/dc_chat.c b/src/dc_chat.c index 1609a92f..0dab62ed 100644 --- a/src/dc_chat.c +++ b/src/dc_chat.c @@ -47,10 +47,10 @@ dc_chat_t* dc_chat_new(dc_context_t* context) exit(14); /* cannot allocate little memory, unrecoverable error */ } - chat->m_magic = DC_CHAT_MAGIC; - chat->m_context = context; - chat->m_type = DC_CHAT_TYPE_UNDEFINED; - chat->m_param = dc_param_new(); + chat->magic = DC_CHAT_MAGIC; + chat->context = context; + chat->type = DC_CHAT_TYPE_UNDEFINED; + chat->param = dc_param_new(); return chat; } @@ -67,13 +67,13 @@ dc_chat_t* dc_chat_new(dc_context_t* context) */ void dc_chat_unref(dc_chat_t* chat) { - if( chat==NULL || chat->m_magic != DC_CHAT_MAGIC ) { + if( chat==NULL || chat->magic != DC_CHAT_MAGIC ) { return; } dc_chat_empty(chat); - dc_param_unref(chat->m_param); - chat->m_magic = 0; + dc_param_unref(chat->param); + chat->magic = 0; free(chat); } @@ -89,27 +89,27 @@ void dc_chat_unref(dc_chat_t* chat) */ void dc_chat_empty(dc_chat_t* chat) { - if( chat == NULL || chat->m_magic != DC_CHAT_MAGIC ) { + if( chat == NULL || chat->magic != DC_CHAT_MAGIC ) { return; } - free(chat->m_name); - chat->m_name = NULL; + free(chat->name); + chat->name = NULL; - chat->m_draft_timestamp = 0; + chat->draft_timestamp = 0; - free(chat->m_draft_text); - chat->m_draft_text = NULL; + free(chat->draft_text); + chat->draft_text = NULL; - chat->m_type = DC_CHAT_TYPE_UNDEFINED; - chat->m_id = 0; + chat->type = DC_CHAT_TYPE_UNDEFINED; + chat->id = 0; - free(chat->m_grpid); - chat->m_grpid = NULL; + free(chat->grpid); + chat->grpid = NULL; - chat->m_blocked = 0; + chat->blocked = 0; - dc_param_set_packed(chat->m_param, NULL); + dc_param_set_packed(chat->param, NULL); } @@ -136,11 +136,11 @@ void dc_chat_empty(dc_chat_t* chat) */ uint32_t dc_chat_get_id(dc_chat_t* chat) { - if( chat == NULL || chat->m_magic != DC_CHAT_MAGIC ) { + if( chat == NULL || chat->magic != DC_CHAT_MAGIC ) { return 0; } - return chat->m_id; + return chat->id; } @@ -151,7 +151,7 @@ uint32_t dc_chat_get_id(dc_chat_t* chat) * * - DC_CHAT_TYPE_SINGLE (100) - a normal chat is a chat with a single contact, * chats_contacts contains one record for the user. DC_CONTACT_ID_SELF - * (see dc_contact_t::m_id) is added _only_ for a self talk. + * (see dc_contact_t::id) is added _only_ for a self talk. * * - DC_CHAT_TYPE_GROUP (120) - a group chat, chats_contacts conain all group * members, incl. DC_CONTACT_ID_SELF @@ -167,10 +167,10 @@ uint32_t dc_chat_get_id(dc_chat_t* chat) */ int dc_chat_get_type(dc_chat_t* chat) { - if( chat == NULL || chat->m_magic != DC_CHAT_MAGIC ) { + if( chat == NULL || chat->magic != DC_CHAT_MAGIC ) { return DC_CHAT_TYPE_UNDEFINED; } - return chat->m_type; + return chat->type; } @@ -191,11 +191,11 @@ int dc_chat_get_type(dc_chat_t* chat) */ char* dc_chat_get_name(dc_chat_t* chat) { - if( chat == NULL || chat->m_magic != DC_CHAT_MAGIC ) { + if( chat == NULL || chat->magic != DC_CHAT_MAGIC ) { return dc_strdup("Err"); } - return dc_strdup(chat->m_name); + return dc_strdup(chat->name); } @@ -216,22 +216,22 @@ char* dc_chat_get_subtitle(dc_chat_t* chat) /* returns either the address or the number of chat members */ char* ret = NULL; - if( chat == NULL || chat->m_magic != DC_CHAT_MAGIC ) { + if( chat == NULL || chat->magic != DC_CHAT_MAGIC ) { return dc_strdup("Err"); } - if( chat->m_type == DC_CHAT_TYPE_SINGLE && dc_param_exists(chat->m_param, DC_PARAM_SELFTALK) ) + if( chat->type == DC_CHAT_TYPE_SINGLE && dc_param_exists(chat->param, DC_PARAM_SELFTALK) ) { - ret = dc_stock_str(chat->m_context, DC_STR_SELFTALK_SUBTITLE); + ret = dc_stock_str(chat->context, DC_STR_SELFTALK_SUBTITLE); } - else if( chat->m_type == DC_CHAT_TYPE_SINGLE ) + else if( chat->type == DC_CHAT_TYPE_SINGLE ) { int r; - sqlite3_stmt* stmt = dc_sqlite3_prepare(chat->m_context->m_sql, + sqlite3_stmt* stmt = dc_sqlite3_prepare(chat->context->sql, "SELECT c.addr FROM chats_contacts cc " " LEFT JOIN contacts c ON c.id=cc.contact_id " " WHERE cc.chat_id=?;"); - sqlite3_bind_int(stmt, 1, chat->m_id); + sqlite3_bind_int(stmt, 1, chat->id); r = sqlite3_step(stmt); if( r == SQLITE_ROW ) { @@ -240,17 +240,17 @@ char* dc_chat_get_subtitle(dc_chat_t* chat) sqlite3_finalize(stmt); } - else if( DC_CHAT_TYPE_IS_MULTI(chat->m_type) ) + else if( DC_CHAT_TYPE_IS_MULTI(chat->type) ) { int cnt = 0; - if( chat->m_id == DC_CHAT_ID_DEADDROP ) + if( chat->id == DC_CHAT_ID_DEADDROP ) { - ret = dc_stock_str(chat->m_context, DC_STR_DEADDROP); /* typically, the subtitle for the deaddropn is not displayed at all */ + ret = dc_stock_str(chat->context, DC_STR_DEADDROP); /* typically, the subtitle for the deaddropn is not displayed at all */ } else { - cnt = dc_get_chat_contact_count(chat->m_context, chat->m_id); - ret = dc_stock_str_repl_pl(chat->m_context, DC_STR_MEMBER, cnt /*SELF is included in group chats (if not removed)*/); + cnt = dc_get_chat_contact_count(chat->context, chat->id); + ret = dc_stock_str_repl_pl(chat->context, DC_STR_MEMBER, cnt /*SELF is included in group chats (if not removed)*/); } } @@ -272,11 +272,11 @@ char* dc_chat_get_subtitle(dc_chat_t* chat) */ char* dc_chat_get_profile_image(dc_chat_t* chat) { - if( chat == NULL || chat->m_magic != DC_CHAT_MAGIC ) { + if( chat == NULL || chat->magic != DC_CHAT_MAGIC ) { return NULL; } - return dc_param_get(chat->m_param, DC_PARAM_PROFILE_IMAGE, NULL); + return dc_param_get(chat->param, DC_PARAM_PROFILE_IMAGE, NULL); } @@ -295,10 +295,10 @@ char* dc_chat_get_profile_image(dc_chat_t* chat) */ char* dc_chat_get_draft(dc_chat_t* chat) { - if( chat == NULL || chat->m_magic != DC_CHAT_MAGIC ) { + if( chat == NULL || chat->magic != DC_CHAT_MAGIC ) { return NULL; } - return dc_strdup_keep_null(chat->m_draft_text); /* may be NULL */ + return dc_strdup_keep_null(chat->draft_text); /* may be NULL */ } @@ -316,10 +316,10 @@ char* dc_chat_get_draft(dc_chat_t* chat) */ time_t dc_chat_get_draft_timestamp(dc_chat_t* chat) { - if( chat == NULL || chat->m_magic != DC_CHAT_MAGIC ) { + if( chat == NULL || chat->magic != DC_CHAT_MAGIC ) { return 0; } - return chat->m_draft_timestamp; + return chat->draft_timestamp; } @@ -342,10 +342,10 @@ time_t dc_chat_get_draft_timestamp(dc_chat_t* chat) */ int dc_chat_get_archived(dc_chat_t* chat) { - if( chat == NULL || chat->m_magic != DC_CHAT_MAGIC ) { + if( chat == NULL || chat->magic != DC_CHAT_MAGIC ) { return 0; } - return chat->m_archived; + return chat->archived; } @@ -366,10 +366,10 @@ int dc_chat_get_archived(dc_chat_t* chat) */ int dc_chat_is_unpromoted(dc_chat_t* chat) { - if( chat == NULL || chat->m_magic != DC_CHAT_MAGIC ) { + if( chat == NULL || chat->magic != DC_CHAT_MAGIC ) { return 0; } - return dc_param_get_int(chat->m_param, DC_PARAM_UNPROMOTED, 0); + return dc_param_get_int(chat->param, DC_PARAM_UNPROMOTED, 0); } @@ -386,10 +386,10 @@ int dc_chat_is_unpromoted(dc_chat_t* chat) */ int dc_chat_is_verified(dc_chat_t* chat) { - if( chat == NULL || chat->m_magic != DC_CHAT_MAGIC ) { + if( chat == NULL || chat->magic != DC_CHAT_MAGIC ) { return 0; } - return (chat->m_type==DC_CHAT_TYPE_VERIFIED_GROUP); + return (chat->type==DC_CHAT_TYPE_VERIFIED_GROUP); } @@ -405,10 +405,10 @@ int dc_chat_is_verified(dc_chat_t* chat) */ int dc_chat_is_self_talk(dc_chat_t* chat) { - if( chat == NULL || chat->m_magic != DC_CHAT_MAGIC ) { + if( chat == NULL || chat->magic != DC_CHAT_MAGIC ) { return 0; } - return dc_param_exists(chat->m_param, DC_PARAM_SELFTALK); + return dc_param_exists(chat->param, DC_PARAM_SELFTALK); } @@ -420,10 +420,10 @@ int dc_chat_is_self_talk(dc_chat_t* chat) int dc_chat_update_param(dc_chat_t* chat) { int success = 0; - sqlite3_stmt* stmt = dc_sqlite3_prepare(chat->m_context->m_sql, + sqlite3_stmt* stmt = dc_sqlite3_prepare(chat->context->sql, "UPDATE chats SET param=? WHERE id=?"); - sqlite3_bind_text(stmt, 1, chat->m_param->m_packed, -1, SQLITE_STATIC); - sqlite3_bind_int (stmt, 2, chat->m_id); + sqlite3_bind_text(stmt, 1, chat->param->packed, -1, SQLITE_STATIC); + sqlite3_bind_int (stmt, 2, chat->id); success = (sqlite3_step(stmt)==SQLITE_DONE)? 1 : 0; sqlite3_finalize(stmt); return success; @@ -435,50 +435,50 @@ static int dc_chat_set_from_stmt(dc_chat_t* chat, sqlite3_stmt* row) int row_offset = 0; const char* draft_text = NULL; - if( chat == NULL || chat->m_magic != DC_CHAT_MAGIC || row == NULL ) { + if( chat == NULL || chat->magic != DC_CHAT_MAGIC || row == NULL ) { return 0; } dc_chat_empty(chat); #define CHAT_FIELDS " c.id,c.type,c.name, c.draft_timestamp,c.draft_txt,c.grpid,c.param,c.archived, c.blocked " - chat->m_id = sqlite3_column_int (row, row_offset++); /* the columns are defined in CHAT_FIELDS */ - chat->m_type = sqlite3_column_int (row, row_offset++); - chat->m_name = dc_strdup((char*)sqlite3_column_text (row, row_offset++)); - chat->m_draft_timestamp = sqlite3_column_int64(row, row_offset++); + chat->id = sqlite3_column_int (row, row_offset++); /* the columns are defined in CHAT_FIELDS */ + chat->type = sqlite3_column_int (row, row_offset++); + chat->name = dc_strdup((char*)sqlite3_column_text (row, row_offset++)); + chat->draft_timestamp = sqlite3_column_int64(row, row_offset++); draft_text = (const char*)sqlite3_column_text (row, row_offset++); - chat->m_grpid = dc_strdup((char*)sqlite3_column_text (row, row_offset++)); - dc_param_set_packed(chat->m_param, (char*)sqlite3_column_text (row, row_offset++)); - chat->m_archived = sqlite3_column_int (row, row_offset++); - chat->m_blocked = sqlite3_column_int (row, row_offset++); + chat->grpid = dc_strdup((char*)sqlite3_column_text (row, row_offset++)); + dc_param_set_packed(chat->param, (char*)sqlite3_column_text (row, row_offset++)); + chat->archived = sqlite3_column_int (row, row_offset++); + chat->blocked = sqlite3_column_int (row, row_offset++); /* We leave a NULL-pointer for the very usual situation of "no draft". - Also make sure, m_draft_text and m_draft_timestamp are set together */ - if( chat->m_draft_timestamp && draft_text && draft_text[0] ) { - chat->m_draft_text = dc_strdup(draft_text); + Also make sure, draft_text and draft_timestamp are set together */ + if( chat->draft_timestamp && draft_text && draft_text[0] ) { + chat->draft_text = dc_strdup(draft_text); } else { - chat->m_draft_timestamp = 0; + chat->draft_timestamp = 0; } /* correct the title of some special groups */ - if( chat->m_id == DC_CHAT_ID_DEADDROP ) { - free(chat->m_name); - chat->m_name = dc_stock_str(chat->m_context, DC_STR_DEADDROP); + if( chat->id == DC_CHAT_ID_DEADDROP ) { + free(chat->name); + chat->name = dc_stock_str(chat->context, DC_STR_DEADDROP); } - else if( chat->m_id == DC_CHAT_ID_ARCHIVED_LINK ) { - free(chat->m_name); - char* tempname = dc_stock_str(chat->m_context, DC_STR_ARCHIVEDCHATS); - chat->m_name = dc_mprintf("%s (%i)", tempname, dc_get_archived_count(chat->m_context)); + else if( chat->id == DC_CHAT_ID_ARCHIVED_LINK ) { + free(chat->name); + char* tempname = dc_stock_str(chat->context, DC_STR_ARCHIVEDCHATS); + chat->name = dc_mprintf("%s (%i)", tempname, dc_get_archived_count(chat->context)); free(tempname); } - else if( chat->m_id == DC_CHAT_ID_STARRED ) { - free(chat->m_name); - chat->m_name = dc_stock_str(chat->m_context, DC_STR_STARREDMSGS); + else if( chat->id == DC_CHAT_ID_STARRED ) { + free(chat->name); + chat->name = dc_stock_str(chat->context, DC_STR_STARREDMSGS); } - else if( dc_param_exists(chat->m_param, DC_PARAM_SELFTALK) ) { - free(chat->m_name); - chat->m_name = dc_stock_str(chat->m_context, DC_STR_SELF); + else if( dc_param_exists(chat->param, DC_PARAM_SELFTALK) ) { + free(chat->name); + chat->name = dc_stock_str(chat->context, DC_STR_SELF); } return row_offset; /* success, return the next row offset */ @@ -504,13 +504,13 @@ int dc_chat_load_from_db(dc_chat_t* chat, uint32_t chat_id) int success = 0; sqlite3_stmt* stmt = NULL; - if( chat==NULL || chat->m_magic != DC_CHAT_MAGIC ) { + if( chat==NULL || chat->magic != DC_CHAT_MAGIC ) { goto cleanup; } dc_chat_empty(chat); - stmt = dc_sqlite3_prepare(chat->m_context->m_sql, + stmt = dc_sqlite3_prepare(chat->context->sql, "SELECT " CHAT_FIELDS " FROM chats c WHERE c.id=?;"); sqlite3_bind_int(stmt, 1, chat_id); diff --git a/src/dc_chat.h b/src/dc_chat.h index d0d01ba1..df8b6a04 100644 --- a/src/dc_chat.h +++ b/src/dc_chat.h @@ -37,17 +37,17 @@ extern "C" { struct _dc_chat { /** @privatesection */ - uint32_t m_magic; - uint32_t m_id; - int m_type; /**< Chat type. Use dc_chat_get_type() to access this field. */ - char* m_name; /**< Name of the chat. Use dc_chat_get_name() to access this field. NULL if unset. */ - char* m_draft_text; /**< Draft text. NULL if there is no draft. */ - time_t m_draft_timestamp; /**< Timestamp of the draft. 0 if there is no draft. */ - int m_archived; /**< Archived state. Better use dc_chat_get_archived() to access this object. */ - dc_context_t* m_context; /**< The context object the chat belongs to. */ - char* m_grpid; /**< Group ID that is used by all clients. Only used if the chat is a group. NULL if unset */ - int m_blocked; /**< One of DC_CHAT_*_BLOCKED */ - dc_param_t* m_param; /**< Additional parameters for a chat. Should not be used directly. */ + uint32_t magic; + uint32_t id; + int type; /**< Chat type. Use dc_chat_get_type() to access this field. */ + char* name; /**< Name of the chat. Use dc_chat_get_name() to access this field. NULL if unset. */ + char* draft_text; /**< Draft text. NULL if there is no draft. */ + time_t draft_timestamp; /**< Timestamp of the draft. 0 if there is no draft. */ + int archived; /**< Archived state. Better use dc_chat_get_archived() to access this object. */ + dc_context_t* context; /**< The context object the chat belongs to. */ + char* grpid; /**< Group ID that is used by all clients. Only used if the chat is a group. NULL if unset */ + int blocked; /**< One of DC_CHAT_*_BLOCKED */ + dc_param_t* param; /**< Additional parameters for a chat. Should not be used directly. */ }; diff --git a/src/dc_chatlist.c b/src/dc_chatlist.c index b7d4a8b8..ebc90e0e 100644 --- a/src/dc_chatlist.c +++ b/src/dc_chatlist.c @@ -43,9 +43,9 @@ dc_chatlist_t* dc_chatlist_new(dc_context_t* context) exit(20); } - chatlist->m_magic = DC_CHATLIST_MAGIC; - chatlist->m_context = context; - if( (chatlist->m_chatNlastmsg_ids=dc_array_new(context, 128))==NULL ) { + chatlist->magic = DC_CHATLIST_MAGIC; + chatlist->context = context; + if( (chatlist->chatNlastmsg_ids=dc_array_new(context, 128))==NULL ) { exit(32); } @@ -65,13 +65,13 @@ dc_chatlist_t* dc_chatlist_new(dc_context_t* context) */ void dc_chatlist_unref(dc_chatlist_t* chatlist) { - if( chatlist==NULL || chatlist->m_magic != DC_CHATLIST_MAGIC ) { + if( chatlist==NULL || chatlist->magic != DC_CHATLIST_MAGIC ) { return; } dc_chatlist_empty(chatlist); - dc_array_unref(chatlist->m_chatNlastmsg_ids); - chatlist->m_magic = 0; + dc_array_unref(chatlist->chatNlastmsg_ids); + chatlist->magic = 0; free(chatlist); } @@ -87,12 +87,12 @@ void dc_chatlist_unref(dc_chatlist_t* chatlist) */ void dc_chatlist_empty(dc_chatlist_t* chatlist) { - if( chatlist == NULL || chatlist->m_magic != DC_CHATLIST_MAGIC ) { + if( chatlist == NULL || chatlist->magic != DC_CHATLIST_MAGIC ) { return; } - chatlist->m_cnt = 0; - dc_array_empty(chatlist->m_chatNlastmsg_ids); + chatlist->cnt = 0; + dc_array_empty(chatlist->chatNlastmsg_ids); } @@ -107,11 +107,11 @@ void dc_chatlist_empty(dc_chatlist_t* chatlist) */ size_t dc_chatlist_get_cnt(dc_chatlist_t* chatlist) { - if( chatlist == NULL || chatlist->m_magic != DC_CHATLIST_MAGIC ) { + if( chatlist == NULL || chatlist->magic != DC_CHATLIST_MAGIC ) { return 0; } - return chatlist->m_cnt; + return chatlist->cnt; } @@ -131,11 +131,11 @@ size_t dc_chatlist_get_cnt(dc_chatlist_t* chatlist) */ uint32_t dc_chatlist_get_chat_id(dc_chatlist_t* chatlist, size_t index) { - if( chatlist == NULL || chatlist->m_magic != DC_CHATLIST_MAGIC || chatlist->m_chatNlastmsg_ids == NULL || index >= chatlist->m_cnt ) { + if( chatlist == NULL || chatlist->magic != DC_CHATLIST_MAGIC || chatlist->chatNlastmsg_ids == NULL || index >= chatlist->cnt ) { return 0; } - return dc_array_get_id(chatlist->m_chatNlastmsg_ids, index*DC_CHATLIST_IDS_PER_RESULT); + return dc_array_get_id(chatlist->chatNlastmsg_ids, index*DC_CHATLIST_IDS_PER_RESULT); } @@ -155,11 +155,11 @@ uint32_t dc_chatlist_get_chat_id(dc_chatlist_t* chatlist, size_t index) */ uint32_t dc_chatlist_get_msg_id(dc_chatlist_t* chatlist, size_t index) { - if( chatlist == NULL || chatlist->m_magic != DC_CHATLIST_MAGIC || chatlist->m_chatNlastmsg_ids == NULL || index >= chatlist->m_cnt ) { + if( chatlist == NULL || chatlist->magic != DC_CHATLIST_MAGIC || chatlist->chatNlastmsg_ids == NULL || index >= chatlist->cnt ) { return 0; } - return dc_array_get_id(chatlist->m_chatNlastmsg_ids, index*DC_CHATLIST_IDS_PER_RESULT+1); + return dc_array_get_id(chatlist->chatNlastmsg_ids, index*DC_CHATLIST_IDS_PER_RESULT+1); } @@ -168,19 +168,19 @@ uint32_t dc_chatlist_get_msg_id(dc_chatlist_t* chatlist, size_t index) * * The summary is returned by a dc_lot_t object with the following fields: * - * - dc_lot_t::m_text1: contains the username or the strings "Me", "Draft" and so on. - * The string may be colored by having a look at m_text1_meaning. + * - dc_lot_t::text1: contains the username or the strings "Me", "Draft" and so on. + * The string may be colored by having a look at text1_meaning. * If there is no such name or it should not be displayed, the element is NULL. * - * - dc_lot_t::m_text1_meaning: one of DC_TEXT1_USERNAME, DC_TEXT1_SELF or DC_TEXT1_DRAFT. - * Typically used to show dc_lot_t::m_text1 with different colors. 0 if not applicable. + * - dc_lot_t::text1_meaning: one of DC_TEXT1_USERNAME, DC_TEXT1_SELF or DC_TEXT1_DRAFT. + * Typically used to show dc_lot_t::text1 with different colors. 0 if not applicable. * - * - dc_lot_t::m_text2: contains an excerpt of the message text or strings as + * - dc_lot_t::text2: contains an excerpt of the message text or strings as * "No messages". May be NULL of there is no such text (eg. for the archive link) * - * - dc_lot_t::m_timestamp: the timestamp of the message. 0 if not applicable. + * - dc_lot_t::timestamp: the timestamp of the message. 0 if not applicable. * - * - dc_lot_t::m_state: The state of the message as one of the DC_STATE_* constants (see #dc_msg_get_state()). 0 if not applicable. + * - dc_lot_t::state: The state of the message as one of the DC_STATE_* constants (see #dc_msg_get_state()). 0 if not applicable. * * @memberof dc_chatlist_t * @@ -205,18 +205,18 @@ dc_lot_t* dc_chatlist_get_summary(dc_chatlist_t* chatlist, size_t index, dc_chat dc_contact_t* lastcontact = NULL; dc_chat_t* chat_to_delete = NULL; - if( chatlist == NULL || chatlist->m_magic != DC_CHATLIST_MAGIC || index >= chatlist->m_cnt ) { - ret->m_text2 = dc_strdup("ErrBadChatlistIndex"); + if( chatlist == NULL || chatlist->magic != DC_CHATLIST_MAGIC || index >= chatlist->cnt ) { + ret->text2 = dc_strdup("ErrBadChatlistIndex"); goto cleanup; } - lastmsg_id = dc_array_get_id(chatlist->m_chatNlastmsg_ids, index*DC_CHATLIST_IDS_PER_RESULT+1); + lastmsg_id = dc_array_get_id(chatlist->chatNlastmsg_ids, index*DC_CHATLIST_IDS_PER_RESULT+1); if( chat==NULL ) { - chat = dc_chat_new(chatlist->m_context); + chat = dc_chat_new(chatlist->context); chat_to_delete = chat; - if( !dc_chat_load_from_db(chat, dc_array_get_id(chatlist->m_chatNlastmsg_ids, index*DC_CHATLIST_IDS_PER_RESULT)) ) { - ret->m_text2 = dc_strdup("ErrCannotReadChat"); + if( !dc_chat_load_from_db(chat, dc_array_get_id(chatlist->chatNlastmsg_ids, index*DC_CHATLIST_IDS_PER_RESULT)) ) { + ret->text2 = dc_strdup("ErrCannotReadChat"); goto cleanup; } } @@ -224,41 +224,41 @@ dc_lot_t* dc_chatlist_get_summary(dc_chatlist_t* chatlist, size_t index, dc_chat if( lastmsg_id ) { lastmsg = dc_msg_new(); - dc_msg_load_from_db(lastmsg, chatlist->m_context, lastmsg_id); + dc_msg_load_from_db(lastmsg, chatlist->context, lastmsg_id); - if( lastmsg->m_from_id != DC_CONTACT_ID_SELF && DC_CHAT_TYPE_IS_MULTI(chat->m_type) ) + if( lastmsg->from_id != DC_CONTACT_ID_SELF && DC_CHAT_TYPE_IS_MULTI(chat->type) ) { - lastcontact = dc_contact_new(chatlist->m_context); - dc_contact_load_from_db(lastcontact, chatlist->m_context->m_sql, lastmsg->m_from_id); + lastcontact = dc_contact_new(chatlist->context); + dc_contact_load_from_db(lastcontact, chatlist->context->sql, lastmsg->from_id); } } - if( chat->m_id == DC_CHAT_ID_ARCHIVED_LINK ) + if( chat->id == DC_CHAT_ID_ARCHIVED_LINK ) { - ret->m_text2 = dc_strdup(NULL); + ret->text2 = dc_strdup(NULL); } - else if( chat->m_draft_timestamp - && chat->m_draft_text - && (lastmsg==NULL || chat->m_draft_timestamp>lastmsg->m_timestamp) ) + else if( chat->draft_timestamp + && chat->draft_text + && (lastmsg==NULL || chat->draft_timestamp>lastmsg->timestamp) ) { /* show the draft as the last message */ - ret->m_text1 = dc_stock_str(chatlist->m_context, DC_STR_DRAFT); - ret->m_text1_meaning = DC_TEXT1_DRAFT; + ret->text1 = dc_stock_str(chatlist->context, DC_STR_DRAFT); + ret->text1_meaning = DC_TEXT1_DRAFT; - ret->m_text2 = dc_strdup(chat->m_draft_text); - dc_truncate_n_unwrap_str(ret->m_text2, DC_SUMMARY_CHARACTERS, 1/*unwrap*/); + ret->text2 = dc_strdup(chat->draft_text); + dc_truncate_n_unwrap_str(ret->text2, DC_SUMMARY_CHARACTERS, 1/*unwrap*/); - ret->m_timestamp = chat->m_draft_timestamp; + ret->timestamp = chat->draft_timestamp; } - else if( lastmsg == NULL || lastmsg->m_from_id == 0 ) + else if( lastmsg == NULL || lastmsg->from_id == 0 ) { /* no messages */ - ret->m_text2 = dc_stock_str(chatlist->m_context, DC_STR_NOMESSAGES); + ret->text2 = dc_stock_str(chatlist->context, DC_STR_NOMESSAGES); } else { /* show the last message */ - dc_lot_fill(ret, lastmsg, chat, lastcontact, chatlist->m_context); + dc_lot_fill(ret, lastmsg, chat, lastcontact, chatlist->context); } cleanup: @@ -280,10 +280,10 @@ cleanup: */ dc_context_t* dc_chatlist_get_context(dc_chatlist_t* chatlist) { - if( chatlist == NULL || chatlist->m_magic != DC_CHATLIST_MAGIC ) { + if( chatlist == NULL || chatlist->magic != DC_CHATLIST_MAGIC ) { return NULL; } - return chatlist->m_context; + return chatlist->context; } @@ -303,7 +303,7 @@ int dc_chatlist_load_from_db(dc_chatlist_t* chatlist, int listflags, const char* sqlite3_stmt* stmt = NULL; char* strLikeCmd = NULL, *query = NULL; - if( chatlist == NULL || chatlist->m_magic != DC_CHATLIST_MAGIC || chatlist->m_context == NULL ) { + if( chatlist == NULL || chatlist->magic != DC_CHATLIST_MAGIC || chatlist->context == NULL ) { goto cleanup; } @@ -325,29 +325,29 @@ int dc_chatlist_load_from_db(dc_chatlist_t* chatlist, int listflags, const char* if( query_contact_id ) { // show chats shared with a given contact - stmt = dc_sqlite3_prepare(chatlist->m_context->m_sql, + stmt = dc_sqlite3_prepare(chatlist->context->sql, QUR1 " AND c.id IN(SELECT chat_id FROM chats_contacts WHERE contact_id=?) " QUR2); sqlite3_bind_int(stmt, 1, query_contact_id); } else if( listflags & DC_GCL_ARCHIVED_ONLY ) { /* show archived chats */ - stmt = dc_sqlite3_prepare(chatlist->m_context->m_sql, + stmt = dc_sqlite3_prepare(chatlist->context->sql, QUR1 " AND c.archived=1 " QUR2); } else if( query__==NULL ) { /* show normal chatlist */ if( !(listflags & DC_GCL_NO_SPECIALS) ) { - uint32_t last_deaddrop_fresh_msg_id = dc_get_last_deaddrop_fresh_msg(chatlist->m_context); + uint32_t last_deaddrop_fresh_msg_id = dc_get_last_deaddrop_fresh_msg(chatlist->context); if( last_deaddrop_fresh_msg_id > 0 ) { - dc_array_add_id(chatlist->m_chatNlastmsg_ids, DC_CHAT_ID_DEADDROP); /* show deaddrop with the last fresh message */ - dc_array_add_id(chatlist->m_chatNlastmsg_ids, last_deaddrop_fresh_msg_id); + dc_array_add_id(chatlist->chatNlastmsg_ids, DC_CHAT_ID_DEADDROP); /* show deaddrop with the last fresh message */ + dc_array_add_id(chatlist->chatNlastmsg_ids, last_deaddrop_fresh_msg_id); } add_archived_link_item = 1; } - stmt = dc_sqlite3_prepare(chatlist->m_context->m_sql, + stmt = dc_sqlite3_prepare(chatlist->context->sql, QUR1 " AND c.archived=0 " QUR2); } else @@ -360,28 +360,28 @@ int dc_chatlist_load_from_db(dc_chatlist_t* chatlist, int listflags, const char* goto cleanup; } strLikeCmd = dc_mprintf("%%%s%%", query); - stmt = dc_sqlite3_prepare(chatlist->m_context->m_sql, + stmt = dc_sqlite3_prepare(chatlist->context->sql, QUR1 " AND c.name LIKE ? " QUR2); sqlite3_bind_text(stmt, 1, strLikeCmd, -1, SQLITE_STATIC); } while( sqlite3_step(stmt) == SQLITE_ROW ) { - dc_array_add_id(chatlist->m_chatNlastmsg_ids, sqlite3_column_int(stmt, 0)); - dc_array_add_id(chatlist->m_chatNlastmsg_ids, sqlite3_column_int(stmt, 1)); + dc_array_add_id(chatlist->chatNlastmsg_ids, sqlite3_column_int(stmt, 0)); + dc_array_add_id(chatlist->chatNlastmsg_ids, sqlite3_column_int(stmt, 1)); } - if( add_archived_link_item && dc_get_archived_count(chatlist->m_context)>0 ) + if( add_archived_link_item && dc_get_archived_count(chatlist->context)>0 ) { - dc_array_add_id(chatlist->m_chatNlastmsg_ids, DC_CHAT_ID_ARCHIVED_LINK); - dc_array_add_id(chatlist->m_chatNlastmsg_ids, 0); + dc_array_add_id(chatlist->chatNlastmsg_ids, DC_CHAT_ID_ARCHIVED_LINK); + dc_array_add_id(chatlist->chatNlastmsg_ids, 0); } - chatlist->m_cnt = dc_array_get_cnt(chatlist->m_chatNlastmsg_ids)/DC_CHATLIST_IDS_PER_RESULT; + chatlist->cnt = dc_array_get_cnt(chatlist->chatNlastmsg_ids)/DC_CHATLIST_IDS_PER_RESULT; success = 1; cleanup: - //dc_log_info(chatlist->m_context, 0, "Chatlist for search \"%s\" created in %.3f ms.", query__?query__:"", (double)(clock()-start)*1000.0/CLOCKS_PER_SEC); + //dc_log_info(chatlist->context, 0, "Chatlist for search \"%s\" created in %.3f ms.", query__?query__:"", (double)(clock()-start)*1000.0/CLOCKS_PER_SEC); sqlite3_finalize(stmt); free(query); free(strLikeCmd); diff --git a/src/dc_chatlist.h b/src/dc_chatlist.h index 96c6ccf3..6e362e7c 100644 --- a/src/dc_chatlist.h +++ b/src/dc_chatlist.h @@ -31,11 +31,11 @@ extern "C" { struct _dc_chatlist { /** @privatesection */ - uint32_t m_magic; - dc_context_t* m_context; /**< The context, the chatlist belongs to */ + uint32_t magic; + dc_context_t* context; /**< The context, the chatlist belongs to */ #define DC_CHATLIST_IDS_PER_RESULT 2 - size_t m_cnt; - dc_array_t* m_chatNlastmsg_ids; + size_t cnt; + dc_array_t* chatNlastmsg_ids; }; diff --git a/src/dc_configure.c b/src/dc_configure.c index 7bbb9c7d..6389717c 100644 --- a/src/dc_configure.c +++ b/src/dc_configure.c @@ -39,7 +39,7 @@ static char* read_autoconf_file(dc_context_t* context, const char* url) { char* filecontent = NULL; dc_log_info(context, 0, "Testing %s ...", url); - filecontent = (char*)context->m_cb(context, DC_EVENT_HTTP_GET, (uintptr_t)url, 0); + filecontent = (char*)context->cb(context, DC_EVENT_HTTP_GET, (uintptr_t)url, 0); if( filecontent == NULL ) { dc_log_info(context, 0, "Can't read file."); /* this is not a warning or an error, we're just testing */ return NULL; @@ -58,12 +58,13 @@ static char* read_autoconf_file(dc_context_t* context, const char* url) typedef struct moz_autoconfigure_t { - const dc_loginparam_t* m_in; - char* m_in_emaildomain; - char* m_in_emaillocalpart; + const dc_loginparam_t* in; + char* in_emaildomain; + char* in_emaillocalpart; - dc_loginparam_t* m_out; - int m_out_imap_set, m_out_smtp_set; + dc_loginparam_t* out; + int out_imap_set; + int out_smtp_set; /* currently, we assume there is only one emailProvider tag in the file, see example at https://wiki.mozilla.org/Thunderbird:Autoconfiguration:ConfigFileFormat @@ -73,13 +74,13 @@ typedef struct moz_autoconfigure_t #define MOZ_SERVER_IMAP 1 #define MOZ_SERVER_SMTP 2 - int m_tag_server; + int tag_server; #define MOZ_HOSTNAME 10 #define MOZ_PORT 11 #define MOZ_USERNAME 12 #define MOZ_SOCKETTYPE 13 - int m_tag_config; + int tag_config; } moz_autoconfigure_t; @@ -90,17 +91,17 @@ static void moz_autoconfigure_starttag_cb(void* userdata, const char* tag, char* const char* p1; if( strcmp(tag, "incomingserver")==0 ) { - moz_ac->m_tag_server = (moz_ac->m_out_imap_set==0 && (p1=dc_attr_find(attr, "type"))!=NULL && strcasecmp(p1, "imap")==0)? MOZ_SERVER_IMAP : 0; - moz_ac->m_tag_config = 0; + moz_ac->tag_server = (moz_ac->out_imap_set==0 && (p1=dc_attr_find(attr, "type"))!=NULL && strcasecmp(p1, "imap")==0)? MOZ_SERVER_IMAP : 0; + moz_ac->tag_config = 0; } else if( strcmp(tag, "outgoingserver") == 0 ) { - moz_ac->m_tag_server = moz_ac->m_out_smtp_set==0? MOZ_SERVER_SMTP : 0; - moz_ac->m_tag_config = 0; + moz_ac->tag_server = moz_ac->out_smtp_set==0? MOZ_SERVER_SMTP : 0; + moz_ac->tag_config = 0; } - else if( strcmp(tag, "hostname") == 0 ) { moz_ac->m_tag_config = MOZ_HOSTNAME; } - else if( strcmp(tag, "port") == 0 ) { moz_ac->m_tag_config = MOZ_PORT; } - else if( strcmp(tag, "sockettype") == 0 ) { moz_ac->m_tag_config = MOZ_SOCKETTYPE; } - else if( strcmp(tag, "username") == 0 ) { moz_ac->m_tag_config = MOZ_USERNAME; } + else if( strcmp(tag, "hostname") == 0 ) { moz_ac->tag_config = MOZ_HOSTNAME; } + else if( strcmp(tag, "port") == 0 ) { moz_ac->tag_config = MOZ_PORT; } + else if( strcmp(tag, "sockettype") == 0 ) { moz_ac->tag_config = MOZ_SOCKETTYPE; } + else if( strcmp(tag, "username") == 0 ) { moz_ac->tag_config = MOZ_USERNAME; } } @@ -110,31 +111,31 @@ static void moz_autoconfigure_text_cb(void* userdata, const char* text, int len) char* val = dc_strdup(text); dc_trim(val); - dc_str_replace(&val, "%EMAILADDRESS%", moz_ac->m_in->m_addr); - dc_str_replace(&val, "%EMAILLOCALPART%", moz_ac->m_in_emaillocalpart); - dc_str_replace(&val, "%EMAILDOMAIN%", moz_ac->m_in_emaildomain); + dc_str_replace(&val, "%EMAILADDRESS%", moz_ac->in->addr); + dc_str_replace(&val, "%EMAILLOCALPART%", moz_ac->in_emaillocalpart); + dc_str_replace(&val, "%EMAILDOMAIN%", moz_ac->in_emaildomain); - if( moz_ac->m_tag_server == MOZ_SERVER_IMAP ) { - switch( moz_ac->m_tag_config ) { - case MOZ_HOSTNAME: free(moz_ac->m_out->m_mail_server); moz_ac->m_out->m_mail_server = val; val = NULL; break; - case MOZ_PORT: moz_ac->m_out->m_mail_port = atoi(val); break; - case MOZ_USERNAME: free(moz_ac->m_out->m_mail_user); moz_ac->m_out->m_mail_user = val; val = NULL; break; + if( moz_ac->tag_server == MOZ_SERVER_IMAP ) { + switch( moz_ac->tag_config ) { + case MOZ_HOSTNAME: free(moz_ac->out->mail_server); moz_ac->out->mail_server = val; val = NULL; break; + case MOZ_PORT: moz_ac->out->mail_port = atoi(val); break; + case MOZ_USERNAME: free(moz_ac->out->mail_user); moz_ac->out->mail_user = val; val = NULL; break; case MOZ_SOCKETTYPE: - if( strcasecmp(val, "ssl")==0 ) { moz_ac->m_out->m_server_flags |=DC_LP_IMAP_SOCKET_SSL; } - if( strcasecmp(val, "starttls")==0 ) { moz_ac->m_out->m_server_flags |=DC_LP_IMAP_SOCKET_STARTTLS; } - if( strcasecmp(val, "plain")==0 ) { moz_ac->m_out->m_server_flags |=DC_LP_IMAP_SOCKET_PLAIN; } + if( strcasecmp(val, "ssl")==0 ) { moz_ac->out->server_flags |=DC_LP_IMAP_SOCKET_SSL; } + if( strcasecmp(val, "starttls")==0 ) { moz_ac->out->server_flags |=DC_LP_IMAP_SOCKET_STARTTLS; } + if( strcasecmp(val, "plain")==0 ) { moz_ac->out->server_flags |=DC_LP_IMAP_SOCKET_PLAIN; } break; } } - else if( moz_ac->m_tag_server == MOZ_SERVER_SMTP ) { - switch( moz_ac->m_tag_config ) { - case MOZ_HOSTNAME: free(moz_ac->m_out->m_send_server); moz_ac->m_out->m_send_server = val; val = NULL; break; - case MOZ_PORT: moz_ac->m_out->m_send_port = atoi(val); break; - case MOZ_USERNAME: free(moz_ac->m_out->m_send_user); moz_ac->m_out->m_send_user = val; val = NULL; break; + else if( moz_ac->tag_server == MOZ_SERVER_SMTP ) { + switch( moz_ac->tag_config ) { + case MOZ_HOSTNAME: free(moz_ac->out->send_server); moz_ac->out->send_server = val; val = NULL; break; + case MOZ_PORT: moz_ac->out->send_port = atoi(val); break; + case MOZ_USERNAME: free(moz_ac->out->send_user); moz_ac->out->send_user = val; val = NULL; break; case MOZ_SOCKETTYPE: - if( strcasecmp(val, "ssl")==0 ) { moz_ac->m_out->m_server_flags |=DC_LP_SMTP_SOCKET_SSL; } - if( strcasecmp(val, "starttls")==0 ) { moz_ac->m_out->m_server_flags |=DC_LP_SMTP_SOCKET_STARTTLS; } - if( strcasecmp(val, "plain")==0 ) { moz_ac->m_out->m_server_flags |=DC_LP_SMTP_SOCKET_PLAIN; } + if( strcasecmp(val, "ssl")==0 ) { moz_ac->out->server_flags |=DC_LP_SMTP_SOCKET_SSL; } + if( strcasecmp(val, "starttls")==0 ) { moz_ac->out->server_flags |=DC_LP_SMTP_SOCKET_STARTTLS; } + if( strcasecmp(val, "plain")==0 ) { moz_ac->out->server_flags |=DC_LP_SMTP_SOCKET_PLAIN; } break; } } @@ -148,17 +149,17 @@ static void moz_autoconfigure_endtag_cb(void* userdata, const char* tag) moz_autoconfigure_t* moz_ac = (moz_autoconfigure_t*)userdata; if( strcmp(tag, "incomingserver")==0 ) { - moz_ac->m_tag_server = 0; - moz_ac->m_tag_config = 0; - moz_ac->m_out_imap_set = 1; + moz_ac->tag_server = 0; + moz_ac->tag_config = 0; + moz_ac->out_imap_set = 1; } else if( strcmp(tag, "outgoingserver")==0 ) { - moz_ac->m_tag_server = 0; - moz_ac->m_tag_config = 0; - moz_ac->m_out_smtp_set = 1; + moz_ac->tag_server = 0; + moz_ac->tag_config = 0; + moz_ac->out_smtp_set = 1; } else { - moz_ac->m_tag_config = 0; + moz_ac->tag_config = 0; } } @@ -174,10 +175,10 @@ static dc_loginparam_t* moz_autoconfigure(dc_context_t* context, const char* url goto cleanup; } - moz_ac.m_in = param_in; - moz_ac.m_in_emaillocalpart = dc_strdup(param_in->m_addr); char* p = strchr(moz_ac.m_in_emaillocalpart, '@'); if( p == NULL ) { goto cleanup; } *p = 0; - moz_ac.m_in_emaildomain = dc_strdup(p+1); - moz_ac.m_out = dc_loginparam_new(); + moz_ac.in = param_in; + moz_ac.in_emaillocalpart = dc_strdup(param_in->addr); char* p = strchr(moz_ac.in_emaillocalpart, '@'); if( p == NULL ) { goto cleanup; } *p = 0; + moz_ac.in_emaildomain = dc_strdup(p+1); + moz_ac.out = dc_loginparam_new(); dc_saxparser_t saxparser; dc_saxparser_init (&saxparser, &moz_ac); @@ -185,23 +186,23 @@ static dc_loginparam_t* moz_autoconfigure(dc_context_t* context, const char* url dc_saxparser_set_text_handler(&saxparser, moz_autoconfigure_text_cb); dc_saxparser_parse (&saxparser, xml_raw); - if( moz_ac.m_out->m_mail_server == NULL - || moz_ac.m_out->m_mail_port == 0 - || moz_ac.m_out->m_send_server == NULL - || moz_ac.m_out->m_send_port == 0 ) + if( moz_ac.out->mail_server == NULL + || moz_ac.out->mail_port == 0 + || moz_ac.out->send_server == NULL + || moz_ac.out->send_port == 0 ) { - { char* r = dc_loginparam_get_readable(moz_ac.m_out); dc_log_warning(context, 0, "Bad or incomplete autoconfig: %s", r); free(r); } + { char* r = dc_loginparam_get_readable(moz_ac.out); dc_log_warning(context, 0, "Bad or incomplete autoconfig: %s", r); free(r); } - dc_loginparam_unref(moz_ac.m_out); /* autoconfig failed for the given URL */ - moz_ac.m_out = NULL; + dc_loginparam_unref(moz_ac.out); /* autoconfig failed for the given URL */ + moz_ac.out = NULL; goto cleanup; } cleanup: free(xml_raw); - free(moz_ac.m_in_emaildomain); - free(moz_ac.m_in_emaillocalpart); - return moz_ac.m_out; /* may be NULL */ + free(moz_ac.in_emaildomain); + free(moz_ac.in_emaillocalpart); + return moz_ac.out; /* may be NULL */ } @@ -212,10 +213,11 @@ cleanup: typedef struct outlk_autodiscover_t { - const dc_loginparam_t* m_in; + const dc_loginparam_t* in; - dc_loginparam_t* m_out; - int m_out_imap_set, m_out_smtp_set; + dc_loginparam_t* out; + int out_imap_set; + int out_smtp_set; /* file format: https://msdn.microsoft.com/en-us/library/bb204278(v=exchg.80).aspx */ #define OUTLK_TYPE 1 @@ -224,10 +226,10 @@ typedef struct outlk_autodiscover_t #define OUTLK_SSL 4 #define OUTLK_REDIRECTURL 5 #define _OUTLK_COUNT_ 6 - int m_tag_config; + int tag_config; - char* m_config[_OUTLK_COUNT_]; - char* m_redirect; + char* config[_OUTLK_COUNT_]; + char* redirect; } outlk_autodiscover_t; @@ -236,8 +238,8 @@ static void outlk_clean_config(outlk_autodiscover_t* outlk_ad) { int i; for( i = 0; i < _OUTLK_COUNT_; i++ ) { - free(outlk_ad->m_config[i]); - outlk_ad->m_config[i] = NULL; + free(outlk_ad->config[i]); + outlk_ad->config[i] = NULL; } } @@ -247,11 +249,11 @@ static void outlk_autodiscover_starttag_cb(void* userdata, const char* tag, char outlk_autodiscover_t* outlk_ad = (outlk_autodiscover_t*)userdata; if( strcmp(tag, "protocol") == 0 ) { outlk_clean_config(outlk_ad); } /* this also cleans "redirecturl", however, this is not problem as the protocol block is only valid for action "settings". */ - else if( strcmp(tag, "type") == 0 ) { outlk_ad->m_tag_config = OUTLK_TYPE; } - else if( strcmp(tag, "server") == 0 ) { outlk_ad->m_tag_config = OUTLK_SERVER; } - else if( strcmp(tag, "port") == 0 ) { outlk_ad->m_tag_config = OUTLK_PORT; } - else if( strcmp(tag, "ssl") == 0 ) { outlk_ad->m_tag_config = OUTLK_SSL; } - else if( strcmp(tag, "redirecturl") == 0 ) { outlk_ad->m_tag_config = OUTLK_REDIRECTURL; } + else if( strcmp(tag, "type") == 0 ) { outlk_ad->tag_config = OUTLK_TYPE; } + else if( strcmp(tag, "server") == 0 ) { outlk_ad->tag_config = OUTLK_SERVER; } + else if( strcmp(tag, "port") == 0 ) { outlk_ad->tag_config = OUTLK_PORT; } + else if( strcmp(tag, "ssl") == 0 ) { outlk_ad->tag_config = OUTLK_SSL; } + else if( strcmp(tag, "redirecturl") == 0 ) { outlk_ad->tag_config = OUTLK_REDIRECTURL; } } @@ -262,8 +264,8 @@ static void outlk_autodiscover_text_cb(void* userdata, const char* text, int len char* val = dc_strdup(text); dc_trim(val); - free(outlk_ad->m_config[outlk_ad->m_tag_config]); - outlk_ad->m_config[outlk_ad->m_tag_config] = val; + free(outlk_ad->config[outlk_ad->tag_config]); + outlk_ad->config[outlk_ad->tag_config] = val; } @@ -273,32 +275,32 @@ static void outlk_autodiscover_endtag_cb(void* userdata, const char* tag) if( strcmp(tag, "protocol")==0 ) { - /* copy collected confituration to m_out (we have to delay this as we do not know when the tag appears in the sax-stream) */ - if( outlk_ad->m_config[OUTLK_TYPE] ) + /* copy collected confituration to out (we have to delay this as we do not know when the tag appears in the sax-stream) */ + if( outlk_ad->config[OUTLK_TYPE] ) { - int port = dc_atoi_null_is_0(outlk_ad->m_config[OUTLK_PORT]), - ssl_on = (outlk_ad->m_config[OUTLK_SSL] && strcasecmp(outlk_ad->m_config[OUTLK_SSL], "on" )==0), - ssl_off = (outlk_ad->m_config[OUTLK_SSL] && strcasecmp(outlk_ad->m_config[OUTLK_SSL], "off")==0); + int port = dc_atoi_null_is_0(outlk_ad->config[OUTLK_PORT]), + ssl_on = (outlk_ad->config[OUTLK_SSL] && strcasecmp(outlk_ad->config[OUTLK_SSL], "on" )==0), + ssl_off = (outlk_ad->config[OUTLK_SSL] && strcasecmp(outlk_ad->config[OUTLK_SSL], "off")==0); - if( strcasecmp(outlk_ad->m_config[OUTLK_TYPE], "imap")==0 && outlk_ad->m_out_imap_set==0 ) { - outlk_ad->m_out->m_mail_server = dc_strdup_keep_null(outlk_ad->m_config[OUTLK_SERVER]); - outlk_ad->m_out->m_mail_port = port; - if( ssl_on ) { outlk_ad->m_out->m_server_flags |= DC_LP_IMAP_SOCKET_SSL; } - else if( ssl_off ) { outlk_ad->m_out->m_server_flags |= DC_LP_IMAP_SOCKET_PLAIN; } - outlk_ad->m_out_imap_set = 1; + if( strcasecmp(outlk_ad->config[OUTLK_TYPE], "imap")==0 && outlk_ad->out_imap_set==0 ) { + outlk_ad->out->mail_server = dc_strdup_keep_null(outlk_ad->config[OUTLK_SERVER]); + outlk_ad->out->mail_port = port; + if( ssl_on ) { outlk_ad->out->server_flags |= DC_LP_IMAP_SOCKET_SSL; } + else if( ssl_off ) { outlk_ad->out->server_flags |= DC_LP_IMAP_SOCKET_PLAIN; } + outlk_ad->out_imap_set = 1; } - else if( strcasecmp(outlk_ad->m_config[OUTLK_TYPE], "smtp")==0 && outlk_ad->m_out_smtp_set==0 ) { - outlk_ad->m_out->m_send_server = dc_strdup_keep_null(outlk_ad->m_config[OUTLK_SERVER]); - outlk_ad->m_out->m_send_port = port; - if( ssl_on ) { outlk_ad->m_out->m_server_flags |= DC_LP_SMTP_SOCKET_SSL; } - else if( ssl_off ) { outlk_ad->m_out->m_server_flags |= DC_LP_SMTP_SOCKET_PLAIN; } - outlk_ad->m_out_smtp_set = 1; + else if( strcasecmp(outlk_ad->config[OUTLK_TYPE], "smtp")==0 && outlk_ad->out_smtp_set==0 ) { + outlk_ad->out->send_server = dc_strdup_keep_null(outlk_ad->config[OUTLK_SERVER]); + outlk_ad->out->send_port = port; + if( ssl_on ) { outlk_ad->out->server_flags |= DC_LP_SMTP_SOCKET_SSL; } + else if( ssl_off ) { outlk_ad->out->server_flags |= DC_LP_SMTP_SOCKET_PLAIN; } + outlk_ad->out_smtp_set = 1; } } outlk_clean_config(outlk_ad); } - outlk_ad->m_tag_config = 0; + outlk_ad->tag_config = 0; } @@ -316,8 +318,8 @@ static dc_loginparam_t* outlk_autodiscover(dc_context_t* context, const char* ur goto cleanup; } - outlk_ad.m_in = param_in; - outlk_ad.m_out = dc_loginparam_new(); + outlk_ad.in = param_in; + outlk_ad.out = dc_loginparam_new(); dc_saxparser_t saxparser; dc_saxparser_init (&saxparser, &outlk_ad); @@ -325,10 +327,10 @@ static dc_loginparam_t* outlk_autodiscover(dc_context_t* context, const char* ur dc_saxparser_set_text_handler(&saxparser, outlk_autodiscover_text_cb); dc_saxparser_parse (&saxparser, xml_raw); - if( outlk_ad.m_config[OUTLK_REDIRECTURL] && outlk_ad.m_config[OUTLK_REDIRECTURL][0] ) { + if( outlk_ad.config[OUTLK_REDIRECTURL] && outlk_ad.config[OUTLK_REDIRECTURL][0] ) { free(url); - url = dc_strdup(outlk_ad.m_config[OUTLK_REDIRECTURL]); - dc_loginparam_unref(outlk_ad.m_out); + url = dc_strdup(outlk_ad.config[OUTLK_REDIRECTURL]); + dc_loginparam_unref(outlk_ad.out); outlk_clean_config(&outlk_ad); free(xml_raw); xml_raw = NULL; } @@ -337,14 +339,14 @@ static dc_loginparam_t* outlk_autodiscover(dc_context_t* context, const char* ur } } - if( outlk_ad.m_out->m_mail_server == NULL - || outlk_ad.m_out->m_mail_port == 0 - || outlk_ad.m_out->m_send_server == NULL - || outlk_ad.m_out->m_send_port == 0 ) + if( outlk_ad.out->mail_server == NULL + || outlk_ad.out->mail_port == 0 + || outlk_ad.out->send_server == NULL + || outlk_ad.out->send_port == 0 ) { - { char* r = dc_loginparam_get_readable(outlk_ad.m_out); dc_log_warning(context, 0, "Bad or incomplete autoconfig: %s", r); free(r); } - dc_loginparam_unref(outlk_ad.m_out); /* autoconfig failed for the given URL */ - outlk_ad.m_out = NULL; + { char* r = dc_loginparam_get_readable(outlk_ad.out); dc_log_warning(context, 0, "Bad or incomplete autoconfig: %s", r); free(r); } + dc_loginparam_unref(outlk_ad.out); /* autoconfig failed for the given URL */ + outlk_ad.out = NULL; goto cleanup; } @@ -352,7 +354,7 @@ cleanup: free(url); free(xml_raw); outlk_clean_config(&outlk_ad); - return outlk_ad.m_out; /* may be NULL */ + return outlk_ad.out; /* may be NULL */ } @@ -371,7 +373,7 @@ void dc_job_do_DC_JOB_CONFIGURE_IMAP(dc_context_t* context, dc_job_t* job) char* param_addr_urlencoded = NULL; dc_loginparam_t* param_autoconfig = NULL; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC ) { goto cleanup; } @@ -381,28 +383,28 @@ void dc_job_do_DC_JOB_CONFIGURE_IMAP(dc_context_t* context, dc_job_t* job) ongoing_allocated_here = 1; #define PROGRESS(p) \ - if( context->m_shall_stop_ongoing ) { goto cleanup; } \ - context->m_cb(context, DC_EVENT_CONFIGURE_PROGRESS, (p)<1? 1 : ((p)>999? 999 : (p)), 0); + if( context->shall_stop_ongoing ) { goto cleanup; } \ + context->cb(context, DC_EVENT_CONFIGURE_PROGRESS, (p)<1? 1 : ((p)>999? 999 : (p)), 0); - if( !dc_sqlite3_is_open(context->m_sql) ) { + if( !dc_sqlite3_is_open(context->sql) ) { dc_log_error(context, 0, "Cannot configure, database not opened."); goto cleanup; } /* disconnect */ - dc_imap_disconnect(context->m_imap); - dc_smtp_disconnect(context->m_smtp); + dc_imap_disconnect(context->imap); + dc_smtp_disconnect(context->smtp); - //dc_sqlite3_set_config_int__(context->m_sql, "configured", 0); -- NO: we do _not_ reset this flag if it was set once; otherwise the user won't get back to his chats (as an alternative, we could change the UI). Moreover, and not changeable in the UI, we use this flag to check if we shall search for backups. - context->m_smtp->m_log_connect_errors = 1; - context->m_imap->m_log_connect_errors = 1; + //dc_sqlite3_set_config_int__(context->sql, "configured", 0); -- NO: we do _not_ reset this flag if it was set once; otherwise the user won't get back to his chats (as an alternative, we could change the UI). Moreover, and not changeable in the UI, we use this flag to check if we shall search for backups. + context->smtp->log_connect_errors = 1; + context->imap->log_connect_errors = 1; dc_log_info(context, 0, "Configure ..."); PROGRESS(0) - if( context->m_cb(context, DC_EVENT_IS_OFFLINE, 0, 0)!=0 ) { + if( context->cb(context, DC_EVENT_IS_OFFLINE, 0, 0)!=0 ) { dc_log_error(context, DC_ERROR_NO_NETWORK, NULL); goto cleanup; } @@ -414,27 +416,27 @@ void dc_job_do_DC_JOB_CONFIGURE_IMAP(dc_context_t* context, dc_job_t* job) param = dc_loginparam_new(); - dc_loginparam_read(param, context->m_sql, ""); + dc_loginparam_read(param, context->sql, ""); - if( param->m_addr == NULL ) { + if( param->addr == NULL ) { dc_log_error(context, 0, "Please enter the email address."); goto cleanup; } - dc_trim(param->m_addr); + dc_trim(param->addr); - param_domain = strchr(param->m_addr, '@'); + param_domain = strchr(param->addr, '@'); if( param_domain==NULL || param_domain[0]==0 ) { dc_log_error(context, 0, "Bad email-address."); goto cleanup; } param_domain++; - param_addr_urlencoded = dc_urlencode(param->m_addr); + param_addr_urlencoded = dc_urlencode(param->addr); /* if no password is given, assume an empty password. (in general, unset values are NULL, not the empty string, this allows to use eg. empty user names or empty passwords) */ - if( param->m_mail_pw == NULL ) { - param->m_mail_pw = dc_strdup(NULL); + if( param->mail_pw == NULL ) { + param->mail_pw = dc_strdup(NULL); } PROGRESS(200) @@ -443,14 +445,14 @@ void dc_job_do_DC_JOB_CONFIGURE_IMAP(dc_context_t* context, dc_job_t* job) /* 2. Autoconfig **************************************************************************/ - if( param->m_mail_server == NULL - && param->m_mail_port == 0 - /*&¶m->m_mail_user == NULL -- the user can enter a loginname which is used by autoconfig then */ - && param->m_send_server == NULL - && param->m_send_port == 0 - && param->m_send_user == NULL - /*&¶m->m_send_pw == NULL -- the password cannot be auto-configured and is no criterion for autoconfig or not */ - && param->m_server_flags == 0 ) + if( param->mail_server == NULL + && param->mail_port == 0 + /*&¶m->mail_user == NULL -- the user can enter a loginname which is used by autoconfig then */ + && param->send_server == NULL + && param->send_port == 0 + && param->send_user == NULL + /*&¶m->send_pw == NULL -- the password cannot be auto-configured and is no criterion for autoconfig or not */ + && param->server_flags == 0 ) { /* A. Search configurations from the domain used in the email-address */ for( i = 0; i <= 1; i++ ) { @@ -494,16 +496,16 @@ void dc_job_do_DC_JOB_CONFIGURE_IMAP(dc_context_t* context, dc_job_t* job) { { char* r = dc_loginparam_get_readable(param_autoconfig); dc_log_info(context, 0, "Got autoconfig: %s", r); free(r); } - if( param_autoconfig->m_mail_user ) { - free(param->m_mail_user); - param->m_mail_user= dc_strdup_keep_null(param_autoconfig->m_mail_user); + if( param_autoconfig->mail_user ) { + free(param->mail_user); + param->mail_user= dc_strdup_keep_null(param_autoconfig->mail_user); } - param->m_mail_server = dc_strdup_keep_null(param_autoconfig->m_mail_server); /* all other values are always NULL when entering autoconfig */ - param->m_mail_port = param_autoconfig->m_mail_port; - param->m_send_server = dc_strdup_keep_null(param_autoconfig->m_send_server); - param->m_send_port = param_autoconfig->m_send_port; - param->m_send_user = dc_strdup_keep_null(param_autoconfig->m_send_user); - param->m_server_flags = param_autoconfig->m_server_flags; + param->mail_server = dc_strdup_keep_null(param_autoconfig->mail_server); /* all other values are always NULL when entering autoconfig */ + param->mail_port = param_autoconfig->mail_port; + param->send_server = dc_strdup_keep_null(param_autoconfig->send_server); + param->send_port = param_autoconfig->send_port; + param->send_user = dc_strdup_keep_null(param_autoconfig->send_user); + param->server_flags = param_autoconfig->server_flags; /* althoug param_autoconfig's data are no longer needed from, it is important to keep the object as we may enter "deep guessing" if we could not read a configuration */ @@ -518,7 +520,7 @@ void dc_job_do_DC_JOB_CONFIGURE_IMAP(dc_context_t* context, dc_job_t* job) { /* NB: Checking GMa'l too often (<10 Minutes) may result in blocking, says https://github.com/itprojects/InboxPager/blob/HEAD/README.md#gmail-configuration Also note https://www.google.com/settings/security/lesssecureapps */ - param->m_server_flags |= DC_LP_AUTH_XOAUTH2 | DC_NO_EXTRA_IMAP_UPLOAD | DC_NO_MOVE_TO_CHATS; + param->server_flags |= DC_LP_AUTH_XOAUTH2 | DC_NO_EXTRA_IMAP_UPLOAD | DC_NO_MOVE_TO_CHATS; } @@ -532,69 +534,69 @@ void dc_job_do_DC_JOB_CONFIGURE_IMAP(dc_context_t* context, dc_job_t* job) #define TYPICAL_SMTP_STARTTLS_PORT 587 /* also used very often, SSL:STARTTLS is maybe 50:50 */ #define TYPICAL_SMTP_PLAIN_PORT 25 - if( param->m_mail_server == NULL ) { - param->m_mail_server = dc_mprintf("imap.%s", param_domain); + if( param->mail_server == NULL ) { + param->mail_server = dc_mprintf("imap.%s", param_domain); } - if( param->m_mail_port == 0 ) { - param->m_mail_port = (param->m_server_flags&(DC_LP_IMAP_SOCKET_STARTTLS|DC_LP_IMAP_SOCKET_PLAIN))? TYPICAL_IMAP_STARTTLS_PORT : TYPICAL_IMAP_SSL_PORT; + if( param->mail_port == 0 ) { + param->mail_port = (param->server_flags&(DC_LP_IMAP_SOCKET_STARTTLS|DC_LP_IMAP_SOCKET_PLAIN))? TYPICAL_IMAP_STARTTLS_PORT : TYPICAL_IMAP_SSL_PORT; } - if( param->m_mail_user == NULL ) { - param->m_mail_user = dc_strdup(param->m_addr); + if( param->mail_user == NULL ) { + param->mail_user = dc_strdup(param->addr); } - if( param->m_send_server == NULL && param->m_mail_server ) { - param->m_send_server = dc_strdup(param->m_mail_server); - if( strncmp(param->m_send_server, "imap.", 5)==0 ) { - memcpy(param->m_send_server, "smtp", 4); + if( param->send_server == NULL && param->mail_server ) { + param->send_server = dc_strdup(param->mail_server); + if( strncmp(param->send_server, "imap.", 5)==0 ) { + memcpy(param->send_server, "smtp", 4); } } - if( param->m_send_port == 0 ) { - param->m_send_port = (param->m_server_flags&DC_LP_SMTP_SOCKET_STARTTLS)? TYPICAL_SMTP_STARTTLS_PORT : - ((param->m_server_flags&DC_LP_SMTP_SOCKET_PLAIN)? TYPICAL_SMTP_PLAIN_PORT : TYPICAL_SMTP_SSL_PORT); + if( param->send_port == 0 ) { + param->send_port = (param->server_flags&DC_LP_SMTP_SOCKET_STARTTLS)? TYPICAL_SMTP_STARTTLS_PORT : + ((param->server_flags&DC_LP_SMTP_SOCKET_PLAIN)? TYPICAL_SMTP_PLAIN_PORT : TYPICAL_SMTP_SSL_PORT); } - if( param->m_send_user == NULL && param->m_mail_user ) { - param->m_send_user = dc_strdup(param->m_mail_user); + if( param->send_user == NULL && param->mail_user ) { + param->send_user = dc_strdup(param->mail_user); } - if( param->m_send_pw == NULL && param->m_mail_pw ) { - param->m_send_pw = dc_strdup(param->m_mail_pw); + if( param->send_pw == NULL && param->mail_pw ) { + param->send_pw = dc_strdup(param->mail_pw); } - if( !dc_exactly_one_bit_set(param->m_server_flags&DC_LP_AUTH_FLAGS) ) + if( !dc_exactly_one_bit_set(param->server_flags&DC_LP_AUTH_FLAGS) ) { - param->m_server_flags &= ~DC_LP_AUTH_FLAGS; - param->m_server_flags |= DC_LP_AUTH_NORMAL; + param->server_flags &= ~DC_LP_AUTH_FLAGS; + param->server_flags |= DC_LP_AUTH_NORMAL; } - if( !dc_exactly_one_bit_set(param->m_server_flags&DC_LP_IMAP_SOCKET_FLAGS) ) + if( !dc_exactly_one_bit_set(param->server_flags&DC_LP_IMAP_SOCKET_FLAGS) ) { - param->m_server_flags &= ~DC_LP_IMAP_SOCKET_FLAGS; - param->m_server_flags |= (param->m_send_port==TYPICAL_IMAP_STARTTLS_PORT? DC_LP_IMAP_SOCKET_STARTTLS : DC_LP_IMAP_SOCKET_SSL); + param->server_flags &= ~DC_LP_IMAP_SOCKET_FLAGS; + param->server_flags |= (param->send_port==TYPICAL_IMAP_STARTTLS_PORT? DC_LP_IMAP_SOCKET_STARTTLS : DC_LP_IMAP_SOCKET_SSL); } - if( !dc_exactly_one_bit_set(param->m_server_flags&DC_LP_SMTP_SOCKET_FLAGS) ) + if( !dc_exactly_one_bit_set(param->server_flags&DC_LP_SMTP_SOCKET_FLAGS) ) { - param->m_server_flags &= ~DC_LP_SMTP_SOCKET_FLAGS; - param->m_server_flags |= ( param->m_send_port==TYPICAL_SMTP_STARTTLS_PORT? DC_LP_SMTP_SOCKET_STARTTLS : - (param->m_send_port==TYPICAL_SMTP_PLAIN_PORT? DC_LP_SMTP_SOCKET_PLAIN: DC_LP_SMTP_SOCKET_SSL) ); + param->server_flags &= ~DC_LP_SMTP_SOCKET_FLAGS; + param->server_flags |= ( param->send_port==TYPICAL_SMTP_STARTTLS_PORT? DC_LP_SMTP_SOCKET_STARTTLS : + (param->send_port==TYPICAL_SMTP_PLAIN_PORT? DC_LP_SMTP_SOCKET_PLAIN: DC_LP_SMTP_SOCKET_SSL) ); } /* do we have a complete configuration? */ - if( param->m_addr == NULL - || param->m_mail_server == NULL - || param->m_mail_port == 0 - || param->m_mail_user == NULL - || param->m_mail_pw == NULL - || param->m_send_server == NULL - || param->m_send_port == 0 - || param->m_send_user == NULL - || param->m_send_pw == NULL - || param->m_server_flags == 0 ) + if( param->addr == NULL + || param->mail_server == NULL + || param->mail_port == 0 + || param->mail_user == NULL + || param->mail_pw == NULL + || param->send_server == NULL + || param->send_port == 0 + || param->send_user == NULL + || param->send_pw == NULL + || param->server_flags == 0 ) { dc_log_error(context, 0, "Account settings incomplete."); goto cleanup; @@ -605,7 +607,7 @@ void dc_job_do_DC_JOB_CONFIGURE_IMAP(dc_context_t* context, dc_job_t* job) /* try to connect to IMAP */ { char* r = dc_loginparam_get_readable(param); dc_log_info(context, 0, "Trying: %s", r); free(r); } - if( !dc_imap_connect(context->m_imap, param) ) { + if( !dc_imap_connect(context->imap, param) ) { goto cleanup; } @@ -614,19 +616,19 @@ void dc_job_do_DC_JOB_CONFIGURE_IMAP(dc_context_t* context, dc_job_t* job) PROGRESS(800) /* try to connect to SMTP - if we did not got an autoconfig, the first try was SSL-465 and we do a second try with STARTTLS-587 */ - if( !dc_smtp_connect(context->m_smtp, param) ) { + if( !dc_smtp_connect(context->smtp, param) ) { if( param_autoconfig ) { goto cleanup; } PROGRESS(850) - param->m_server_flags &= ~DC_LP_SMTP_SOCKET_FLAGS; - param->m_server_flags |= DC_LP_SMTP_SOCKET_STARTTLS; - param->m_send_port = TYPICAL_SMTP_STARTTLS_PORT; + param->server_flags &= ~DC_LP_SMTP_SOCKET_FLAGS; + param->server_flags |= DC_LP_SMTP_SOCKET_STARTTLS; + param->send_port = TYPICAL_SMTP_STARTTLS_PORT; { char* r = dc_loginparam_get_readable(param); dc_log_info(context, 0, "Trying: %s", r); free(r); } - if( !dc_smtp_connect(context->m_smtp, param) ) { + if( !dc_smtp_connect(context->smtp, param) ) { goto cleanup; } } @@ -637,8 +639,8 @@ void dc_job_do_DC_JOB_CONFIGURE_IMAP(dc_context_t* context, dc_job_t* job) /* configuration success - write back the configured parameters with the "configured_" prefix; also write the "configured"-flag */ - dc_loginparam_write(param, context->m_sql, "configured_" /*the trailing underscore is correct*/); - dc_sqlite3_set_config_int(context->m_sql, "configured", 1); + dc_loginparam_write(param, context->sql, "configured_" /*the trailing underscore is correct*/); + dc_sqlite3_set_config_int(context->sql, "configured", 1); PROGRESS(920) @@ -653,23 +655,23 @@ void dc_job_do_DC_JOB_CONFIGURE_IMAP(dc_context_t* context, dc_job_t* job) PROGRESS(940) cleanup: - context->m_cb(context, DC_EVENT_CONFIGURE_PROGRESS, 950, 0); + context->cb(context, DC_EVENT_CONFIGURE_PROGRESS, 950, 0); - if( imap_connected_here ) { dc_imap_disconnect(context->m_imap); } - context->m_cb(context, DC_EVENT_CONFIGURE_PROGRESS, 960, 0); + if( imap_connected_here ) { dc_imap_disconnect(context->imap); } + context->cb(context, DC_EVENT_CONFIGURE_PROGRESS, 960, 0); - if( smtp_connected_here ) { dc_smtp_disconnect(context->m_smtp); } - context->m_cb(context, DC_EVENT_CONFIGURE_PROGRESS, 970, 0); + if( smtp_connected_here ) { dc_smtp_disconnect(context->smtp); } + context->cb(context, DC_EVENT_CONFIGURE_PROGRESS, 970, 0); dc_loginparam_unref(param); dc_loginparam_unref(param_autoconfig); free(param_addr_urlencoded); if( ongoing_allocated_here ) { dc_free_ongoing(context); } - context->m_cb(context, DC_EVENT_CONFIGURE_PROGRESS, 980, 0); + context->cb(context, DC_EVENT_CONFIGURE_PROGRESS, 980, 0); - context->m_cb(context, DC_EVENT_CONFIGURE_PROGRESS, 990, 0); + context->cb(context, DC_EVENT_CONFIGURE_PROGRESS, 990, 0); - context->m_cb(context, DC_EVENT_CONFIGURE_PROGRESS, success? 1000 : 0, 0); + context->cb(context, DC_EVENT_CONFIGURE_PROGRESS, success? 1000 : 0, 0); } @@ -723,15 +725,15 @@ void dc_configure(dc_context_t* context) */ int dc_is_configured(dc_context_t* context) { - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC ) { return 0; } - if( dc_imap_is_connected(context->m_imap) ) { /* if we're connected, we're also configured. this check will speed up the check as no database is involved */ + if( dc_imap_is_connected(context->imap) ) { /* if we're connected, we're also configured. this check will speed up the check as no database is involved */ return 1; } - return dc_sqlite3_get_config_int(context->m_sql, "configured", 0)? 1 : 0; + return dc_sqlite3_get_config_int(context->sql, "configured", 0)? 1 : 0; } @@ -741,17 +743,17 @@ int dc_is_configured(dc_context_t* context) */ int dc_alloc_ongoing(dc_context_t* context) { - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC ) { return 0; } - if( context->m_ongoing_running || context->m_shall_stop_ongoing == 0 ) { + if( context->ongoing_running || context->shall_stop_ongoing == 0 ) { dc_log_warning(context, 0, "There is already another ongoing process running."); return 0; } - context->m_ongoing_running = 1; - context->m_shall_stop_ongoing = 0; + context->ongoing_running = 1; + context->shall_stop_ongoing = 0; return 1; } @@ -762,12 +764,12 @@ int dc_alloc_ongoing(dc_context_t* context) */ void dc_free_ongoing(dc_context_t* context) { - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC ) { return; } - context->m_ongoing_running = 0; - context->m_shall_stop_ongoing = 1; /* avoids dc_stop_ongoing_process() to stop the thread */ + context->ongoing_running = 0; + context->shall_stop_ongoing = 1; /* avoids dc_stop_ongoing_process() to stop the thread */ } @@ -797,14 +799,14 @@ void dc_free_ongoing(dc_context_t* context) */ void dc_stop_ongoing_process(dc_context_t* context) { - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC ) { return; } - if( context->m_ongoing_running && context->m_shall_stop_ongoing==0 ) + if( context->ongoing_running && context->shall_stop_ongoing==0 ) { dc_log_info(context, 0, "Signaling the ongoing process to stop ASAP."); - context->m_shall_stop_ongoing = 1; + context->shall_stop_ongoing = 1; } else { diff --git a/src/dc_contact.c b/src/dc_contact.c index 323a0835..fac2539b 100644 --- a/src/dc_contact.c +++ b/src/dc_contact.c @@ -45,8 +45,8 @@ dc_contact_t* dc_contact_new(dc_context_t* context) exit(19); /* cannot allocate little memory, unrecoverable error */ } - contact->m_magic = DC_CONTACT_MAGIC; - contact->m_context = context; + contact->magic = DC_CONTACT_MAGIC; + contact->context = context; return contact; } @@ -63,12 +63,12 @@ dc_contact_t* dc_contact_new(dc_context_t* context) */ void dc_contact_unref(dc_contact_t* contact) { - if( contact==NULL || contact->m_magic != DC_CONTACT_MAGIC ) { + if( contact==NULL || contact->magic != DC_CONTACT_MAGIC ) { return; } dc_contact_empty(contact); - contact->m_magic = 0; + contact->magic = 0; free(contact); } @@ -86,23 +86,23 @@ void dc_contact_unref(dc_contact_t* contact) */ void dc_contact_empty(dc_contact_t* contact) { - if( contact == NULL || contact->m_magic != DC_CONTACT_MAGIC ) { + if( contact == NULL || contact->magic != DC_CONTACT_MAGIC ) { return; } - contact->m_id = 0; + contact->id = 0; - free(contact->m_name); /* it is safe to call free(NULL) */ - contact->m_name = NULL; + free(contact->name); /* it is safe to call free(NULL) */ + contact->name = NULL; - free(contact->m_authname); - contact->m_authname = NULL; + free(contact->authname); + contact->authname = NULL; - free(contact->m_addr); - contact->m_addr = NULL; + free(contact->addr); + contact->addr = NULL; - contact->m_origin = 0; - contact->m_blocked = 0; + contact->origin = 0; + contact->blocked = 0; } @@ -122,10 +122,10 @@ void dc_contact_empty(dc_contact_t* contact) */ uint32_t dc_contact_get_id(const dc_contact_t* contact) { - if( contact == NULL || contact->m_magic != DC_CONTACT_MAGIC ) { + if( contact == NULL || contact->magic != DC_CONTACT_MAGIC ) { return 0; } - return contact->m_id; + return contact->id; } @@ -140,11 +140,11 @@ uint32_t dc_contact_get_id(const dc_contact_t* contact) */ char* dc_contact_get_addr(const dc_contact_t* contact) { - if( contact == NULL || contact->m_magic != DC_CONTACT_MAGIC ) { + if( contact == NULL || contact->magic != DC_CONTACT_MAGIC ) { return dc_strdup(NULL); } - return dc_strdup(contact->m_addr); + return dc_strdup(contact->addr); } @@ -164,11 +164,11 @@ char* dc_contact_get_addr(const dc_contact_t* contact) */ char* dc_contact_get_name(const dc_contact_t* contact) { - if( contact == NULL || contact->m_magic != DC_CONTACT_MAGIC ) { + if( contact == NULL || contact->magic != DC_CONTACT_MAGIC ) { return dc_strdup(NULL); } - return dc_strdup(contact->m_name); + return dc_strdup(contact->name); } @@ -187,15 +187,15 @@ char* dc_contact_get_name(const dc_contact_t* contact) */ char* dc_contact_get_display_name(const dc_contact_t* contact) { - if( contact == NULL || contact->m_magic != DC_CONTACT_MAGIC ) { + if( contact == NULL || contact->magic != DC_CONTACT_MAGIC ) { return dc_strdup(NULL); } - if( contact->m_name && contact->m_name[0] ) { - return dc_strdup(contact->m_name); + if( contact->name && contact->name[0] ) { + return dc_strdup(contact->name); } - return dc_strdup(contact->m_addr); + return dc_strdup(contact->addr); } @@ -218,15 +218,15 @@ char* dc_contact_get_display_name(const dc_contact_t* contact) */ char* dc_contact_get_name_n_addr(const dc_contact_t* contact) { - if( contact == NULL || contact->m_magic != DC_CONTACT_MAGIC ) { + if( contact == NULL || contact->magic != DC_CONTACT_MAGIC ) { return dc_strdup(NULL); } - if( contact->m_name && contact->m_name[0] ) { - return dc_mprintf("%s (%s)", contact->m_name, contact->m_addr); + if( contact->name && contact->name[0] ) { + return dc_mprintf("%s (%s)", contact->name, contact->addr); } - return dc_strdup(contact->m_addr); + return dc_strdup(contact->addr); } @@ -243,15 +243,15 @@ char* dc_contact_get_name_n_addr(const dc_contact_t* contact) */ char* dc_contact_get_first_name(const dc_contact_t* contact) { - if( contact == NULL || contact->m_magic != DC_CONTACT_MAGIC ) { + if( contact == NULL || contact->magic != DC_CONTACT_MAGIC ) { return dc_strdup(NULL); } - if( contact->m_name && contact->m_name[0] ) { - return dc_get_first_name(contact->m_name); + if( contact->name && contact->name[0] ) { + return dc_get_first_name(contact->name); } - return dc_strdup(contact->m_addr); + return dc_strdup(contact->addr); } @@ -268,10 +268,10 @@ char* dc_contact_get_first_name(const dc_contact_t* contact) */ int dc_contact_is_blocked(const dc_contact_t* contact) { - if( contact == NULL || contact->m_magic != DC_CONTACT_MAGIC ) { + if( contact == NULL || contact->magic != DC_CONTACT_MAGIC ) { return 0; } - return contact->m_blocked; + return contact->blocked; } @@ -279,16 +279,16 @@ int dc_contact_n_peerstate_are_verified(const dc_contact_t* contact, const dc_ap { int contact_verified = DC_NOT_VERIFIED; - if( contact == NULL || contact->m_magic != DC_CONTACT_MAGIC ) { + if( contact == NULL || contact->magic != DC_CONTACT_MAGIC ) { goto cleanup; } - if( contact->m_id == DC_CONTACT_ID_SELF ) { + if( contact->id == DC_CONTACT_ID_SELF ) { contact_verified = DC_BIDIRECT_VERIFIED; goto cleanup; // we're always sort of secured-verified as we could verify the key on this device any time with the key on this device } - contact_verified = peerstate->m_verified_key? DC_BIDIRECT_VERIFIED : 0; + contact_verified = peerstate->verified_key? DC_BIDIRECT_VERIFIED : 0; cleanup: return contact_verified; @@ -313,13 +313,13 @@ int dc_contact_is_verified(const dc_contact_t* contact) int contact_verified = DC_NOT_VERIFIED; dc_apeerstate_t* peerstate = NULL; - if( contact == NULL || contact->m_magic != DC_CONTACT_MAGIC ) { + if( contact == NULL || contact->magic != DC_CONTACT_MAGIC ) { goto cleanup; } - peerstate = dc_apeerstate_new(contact->m_context); + peerstate = dc_apeerstate_new(contact->context); - if( !dc_apeerstate_load_by_addr(peerstate, contact->m_context->m_sql, contact->m_addr) ) { + if( !dc_apeerstate_load_by_addr(peerstate, contact->context->sql, contact->addr) ) { goto cleanup; } @@ -459,7 +459,7 @@ int dc_contact_load_from_db(dc_contact_t* contact, dc_sqlite3_t* sql, uint32_t c int success = 0; sqlite3_stmt* stmt = NULL; - if( contact == NULL || contact->m_magic != DC_CONTACT_MAGIC || sql == NULL ) { + if( contact == NULL || contact->magic != DC_CONTACT_MAGIC || sql == NULL ) { goto cleanup; } @@ -467,9 +467,9 @@ int dc_contact_load_from_db(dc_contact_t* contact, dc_sqlite3_t* sql, uint32_t c if( contact_id == DC_CONTACT_ID_SELF ) { - contact->m_id = contact_id; - contact->m_name = dc_stock_str(contact->m_context, DC_STR_SELF); - contact->m_addr = dc_sqlite3_get_config(sql, "configured_addr", ""); + contact->id = contact_id; + contact->name = dc_stock_str(contact->context, DC_STR_SELF); + contact->addr = dc_sqlite3_get_config(sql, "configured_addr", ""); } else { @@ -482,12 +482,12 @@ int dc_contact_load_from_db(dc_contact_t* contact, dc_sqlite3_t* sql, uint32_t c goto cleanup; } - contact->m_id = contact_id; - contact->m_name = dc_strdup((char*)sqlite3_column_text (stmt, 0)); - contact->m_addr = dc_strdup((char*)sqlite3_column_text (stmt, 1)); - contact->m_origin = sqlite3_column_int (stmt, 2); - contact->m_blocked = sqlite3_column_int (stmt, 3); - contact->m_authname = dc_strdup((char*)sqlite3_column_text (stmt, 4)); + contact->id = contact_id; + contact->name = dc_strdup((char*)sqlite3_column_text (stmt, 0)); + contact->addr = dc_strdup((char*)sqlite3_column_text (stmt, 1)); + contact->origin = sqlite3_column_int (stmt, 2); + contact->blocked = sqlite3_column_int (stmt, 3); + contact->authname = dc_strdup((char*)sqlite3_column_text (stmt, 4)); } success = 1; diff --git a/src/dc_contact.h b/src/dc_contact.h index 3796bb45..8818ec45 100644 --- a/src/dc_contact.h +++ b/src/dc_contact.h @@ -36,8 +36,8 @@ struct _dc_contact { /** @privatesection */ - uint32_t m_magic; - dc_context_t* m_context; + uint32_t magic; + dc_context_t* context; /** * The contact ID. @@ -47,12 +47,12 @@ struct _dc_contact * * Normal contact IDs are larger than these special ones (larger than DC_CONTACT_ID_LAST_SPECIAL). */ - uint32_t m_id; - char* m_name; /**< Contact name. It is recommended to use dc_contact_get_name(), dc_contact_get_display_name() or dc_contact_get_name_n_addr() to access this field. May be NULL or empty, initially set to #m_authname. */ - char* m_authname; /**< Name authorized by the contact himself. Only this name may be spread to others, e.g. in To:-lists. May be NULL or empty. It is recommended to use dc_contact_get_name(), dc_contact_get_display_name() or dc_contact_get_name_n_addr() to access this field. */ - char* m_addr; /**< E-Mail-Address of the contact. It is recommended to use dc_contact_get_addr() to access this field. May be NULL. */ - int m_blocked; /**< Blocked state. Use dc_contact_is_blocked() to access this field. */ - int m_origin; /**< The origin/source of the contact. One of the DC_ORIGIN_* constants. */ + uint32_t id; + char* name; /**< Contact name. It is recommended to use dc_contact_get_name(), dc_contact_get_display_name() or dc_contact_get_name_n_addr() to access this field. May be NULL or empty, initially set to #authname. */ + char* authname; /**< Name authorized by the contact himself. Only this name may be spread to others, e.g. in To:-lists. May be NULL or empty. It is recommended to use dc_contact_get_name(), dc_contact_get_display_name() or dc_contact_get_name_n_addr() to access this field. */ + char* addr; /**< E-Mail-Address of the contact. It is recommended to use dc_contact_get_addr() to access this field. May be NULL. */ + int blocked; /**< Blocked state. Use dc_contact_is_blocked() to access this field. */ + int origin; /**< The origin/source of the contact. One of the DC_ORIGIN_* constants. */ }; diff --git a/src/dc_context.c b/src/dc_context.c index f58c7be7..5afa8d1b 100644 --- a/src/dc_context.c +++ b/src/dc_context.c @@ -49,21 +49,21 @@ static uintptr_t cb_dummy(dc_context_t* context, int event, uintptr_t data1, uin static char* cb_get_config(dc_imap_t* imap, const char* key, const char* def) { - dc_context_t* context = (dc_context_t*)imap->m_userData; - return dc_sqlite3_get_config(context->m_sql, key, def); + dc_context_t* context = (dc_context_t*)imap->userData; + return dc_sqlite3_get_config(context->sql, key, def); } static void cb_set_config(dc_imap_t* imap, const char* key, const char* value) { - dc_context_t* context = (dc_context_t*)imap->m_userData; - dc_sqlite3_set_config(context->m_sql, key, value); + dc_context_t* context = (dc_context_t*)imap->userData; + dc_sqlite3_set_config(context->sql, key, value); } static void cb_receive_imf(dc_imap_t* imap, const char* imf_raw_not_terminated, size_t imf_raw_bytes, const char* server_folder, uint32_t server_uid, uint32_t flags) { - dc_context_t* context = (dc_context_t*)imap->m_userData; + dc_context_t* context = (dc_context_t*)imap->userData; dc_receive_imf(context, imf_raw_not_terminated, imf_raw_bytes, server_folder, server_uid, flags); } @@ -101,22 +101,22 @@ dc_context_t* dc_context_new(dc_callback_t cb, void* userdata, const char* os_na exit(23); /* cannot allocate little memory, unrecoverable error */ } - pthread_mutex_init(&context->m_smear_critical, NULL); - pthread_mutex_init(&context->m_bobs_qr_critical, NULL); - pthread_mutex_init(&context->m_log_ringbuf_critical, NULL); - pthread_mutex_init(&context->m_imapidle_condmutex, NULL); - pthread_mutex_init(&context->m_smtpidle_condmutex, NULL); - pthread_cond_init(&context->m_smtpidle_cond, NULL); + pthread_mutex_init(&context->smear_critical, NULL); + pthread_mutex_init(&context->bobs_qr_critical, NULL); + pthread_mutex_init(&context->log_ringbuf_critical, NULL); + pthread_mutex_init(&context->imapidle_condmutex, NULL); + pthread_mutex_init(&context->smtpidle_condmutex, NULL); + pthread_cond_init(&context->smtpidle_cond, NULL); - context->m_magic = DC_CONTEXT_MAGIC; - context->m_sql = dc_sqlite3_new(context); - context->m_cb = cb? cb : cb_dummy; - context->m_userdata = userdata; - context->m_imap = dc_imap_new(cb_get_config, cb_set_config, cb_receive_imf, (void*)context, context); - context->m_smtp = dc_smtp_new(context); - context->m_os_name = dc_strdup_keep_null(os_name); + context->magic = DC_CONTEXT_MAGIC; + context->sql = dc_sqlite3_new(context); + context->cb = cb? cb : cb_dummy; + context->userdata = userdata; + context->imap = dc_imap_new(cb_get_config, cb_set_config, cb_receive_imf, (void*)context, context); + context->smtp = dc_smtp_new(context); + context->os_name = dc_strdup_keep_null(os_name); - context->m_shall_stop_ongoing = 1; /* the value 1 avoids dc_stop_ongoing_process() from stopping already stopped threads */ + context->shall_stop_ongoing = 1; /* the value 1 avoids dc_stop_ongoing_process() from stopping already stopped threads */ dc_pgp_init(context); @@ -148,7 +148,7 @@ dc_context_t* dc_context_new(dc_callback_t cb, void* userdata, const char* os_na */ void dc_context_unref(dc_context_t* context) { - if( context==NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context==NULL || context->magic != DC_CONTEXT_MAGIC ) { return; } @@ -158,23 +158,23 @@ void dc_context_unref(dc_context_t* context) dc_close(context); } - dc_imap_unref(context->m_imap); - dc_smtp_unref(context->m_smtp); - dc_sqlite3_unref(context->m_sql); + dc_imap_unref(context->imap); + dc_smtp_unref(context->smtp); + dc_sqlite3_unref(context->sql); - pthread_mutex_destroy(&context->m_smear_critical); - pthread_mutex_destroy(&context->m_bobs_qr_critical); - pthread_mutex_destroy(&context->m_log_ringbuf_critical); - pthread_mutex_destroy(&context->m_imapidle_condmutex); - pthread_cond_destroy(&context->m_smtpidle_cond); - pthread_mutex_destroy(&context->m_smtpidle_condmutex); + pthread_mutex_destroy(&context->smear_critical); + pthread_mutex_destroy(&context->bobs_qr_critical); + pthread_mutex_destroy(&context->log_ringbuf_critical); + pthread_mutex_destroy(&context->imapidle_condmutex); + pthread_cond_destroy(&context->smtpidle_cond); + pthread_mutex_destroy(&context->smtpidle_condmutex); for( int i = 0; i < DC_LOG_RINGBUF_SIZE; i++ ) { - free(context->m_log_ringbuf[i]); + free(context->log_ringbuf[i]); } - free(context->m_os_name); - context->m_magic = 0; + free(context->os_name); + context->magic = 0; free(context); } @@ -188,17 +188,17 @@ void dc_context_unref(dc_context_t* context) */ void* dc_get_userdata(dc_context_t* context) { - if( context==NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context==NULL || context->magic != DC_CONTEXT_MAGIC ) { return NULL; } - return context->m_userdata; + return context->userdata; } static void update_config_cache(dc_context_t* context, const char* key) { if( key==NULL || strcmp(key, "e2ee_enabled")==0 ) { - context->m_e2ee_enabled = dc_sqlite3_get_config_int(context->m_sql, "e2ee_enabled", DC_E2EE_DEFAULT_ENABLED); + context->e2ee_enabled = dc_sqlite3_get_config_int(context->sql, "e2ee_enabled", DC_E2EE_DEFAULT_ENABLED); } } @@ -221,7 +221,7 @@ int dc_open(dc_context_t* context, const char* dbfile, const char* blobdir) { int success = 0; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || dbfile == NULL ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || dbfile == NULL ) { goto cleanup; } @@ -229,21 +229,21 @@ int dc_open(dc_context_t* context, const char* dbfile, const char* blobdir) from which all configuration is read/written to. */ /* Create/open sqlite database */ - if( !dc_sqlite3_open__(context->m_sql, dbfile, 0) ) { + if( !dc_sqlite3_open__(context->sql, dbfile, 0) ) { goto cleanup; } /* backup dbfile name */ - context->m_dbfile = dc_strdup(dbfile); + context->dbfile = dc_strdup(dbfile); /* set blob-directory (to avoid double slashed, the given directory should not end with an slash) */ if( blobdir && blobdir[0] ) { - context->m_blobdir = dc_strdup(blobdir); + context->blobdir = dc_strdup(blobdir); } else { - context->m_blobdir = dc_mprintf("%s-blobs", dbfile); - dc_create_folder(context->m_blobdir, context); + context->blobdir = dc_mprintf("%s-blobs", dbfile); + dc_create_folder(context->blobdir, context); } update_config_cache(context, NULL); @@ -252,8 +252,8 @@ int dc_open(dc_context_t* context, const char* dbfile, const char* blobdir) cleanup: if( !success ) { - if( dc_sqlite3_is_open(context->m_sql) ) { - dc_sqlite3_close__(context->m_sql); + if( dc_sqlite3_is_open(context->sql) ) { + dc_sqlite3_close__(context->sql); } } @@ -270,22 +270,22 @@ cleanup: */ void dc_close(dc_context_t* context) { - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC ) { return; } - dc_imap_disconnect(context->m_imap); - dc_smtp_disconnect(context->m_smtp); + dc_imap_disconnect(context->imap); + dc_smtp_disconnect(context->smtp); - if( dc_sqlite3_is_open(context->m_sql) ) { - dc_sqlite3_close__(context->m_sql); + if( dc_sqlite3_is_open(context->sql) ) { + dc_sqlite3_close__(context->sql); } - free(context->m_dbfile); - context->m_dbfile = NULL; + free(context->dbfile); + context->dbfile = NULL; - free(context->m_blobdir); - context->m_blobdir = NULL; + free(context->blobdir); + context->blobdir = NULL; } @@ -298,11 +298,11 @@ void dc_close(dc_context_t* context) */ int dc_is_open(const dc_context_t* context) { - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC ) { return 0; /* error - database not opened */ } - return dc_sqlite3_is_open(context->m_sql); + return dc_sqlite3_is_open(context->sql); } @@ -316,10 +316,10 @@ int dc_is_open(const dc_context_t* context) */ char* dc_get_blobdir(dc_context_t* context) { - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC ) { return dc_strdup(NULL); } - return dc_strdup(context->m_blobdir); + return dc_strdup(context->blobdir); } @@ -355,11 +355,11 @@ int dc_set_config(dc_context_t* context, const char* key, const char* value) { int ret; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || key == NULL ) { /* "value" may be NULL */ + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || key == NULL ) { /* "value" may be NULL */ return 0; } - ret = dc_sqlite3_set_config(context->m_sql, key, value); + ret = dc_sqlite3_set_config(context->sql, key, value); update_config_cache(context, key); return ret; @@ -378,11 +378,11 @@ int dc_set_config(dc_context_t* context, const char* key, const char* value) */ char* dc_get_config(dc_context_t* context, const char* key, const char* def) { - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || key == NULL ) { /* "def" may be NULL */ + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || key == NULL ) { /* "def" may be NULL */ return dc_strdup_keep_null(def); } - return dc_sqlite3_get_config(context->m_sql, key, def); + return dc_sqlite3_get_config(context->sql, key, def); } @@ -396,11 +396,11 @@ int dc_set_config_int(dc_context_t* context, const char* key, int32_t value) { int ret; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || key == NULL ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || key == NULL ) { return 0; } - ret = dc_sqlite3_set_config_int(context->m_sql, key, value); + ret = dc_sqlite3_set_config_int(context->sql, key, value); update_config_cache(context, key); return ret; @@ -414,11 +414,11 @@ int dc_set_config_int(dc_context_t* context, const char* key, int32_t value) */ int32_t dc_get_config_int(dc_context_t* context, const char* key, int32_t def) { - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || key == NULL ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || key == NULL ) { return def; } - return dc_sqlite3_get_config_int(context->m_sql, key, def); + return dc_sqlite3_get_config_int(context->sql, key, def); } @@ -453,7 +453,7 @@ char* dc_get_info(dc_context_t* context) dc_strbuilder_t ret; dc_strbuilder_init(&ret, 0); - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC ) { return dc_strdup("ErrBadPtr"); } @@ -461,35 +461,35 @@ char* dc_get_info(dc_context_t* context) l = dc_loginparam_new(); l2 = dc_loginparam_new(); - dc_loginparam_read(l, context->m_sql, ""); - dc_loginparam_read(l2, context->m_sql, "configured_" /*the trailing underscore is correct*/); + dc_loginparam_read(l, context->sql, ""); + dc_loginparam_read(l2, context->sql, "configured_" /*the trailing underscore is correct*/); - displayname = dc_sqlite3_get_config(context->m_sql, "displayname", NULL); + displayname = dc_sqlite3_get_config(context->sql, "displayname", NULL); chats = dc_get_chat_cnt(context); real_msgs = dc_get_real_msg_cnt(context); deaddrop_msgs = dc_get_deaddrop_msg_cnt(context); contacts = dc_get_real_contact_cnt(context); - is_configured = dc_sqlite3_get_config_int(context->m_sql, "configured", 0); + is_configured = dc_sqlite3_get_config_int(context->sql, "configured", 0); - dbversion = dc_sqlite3_get_config_int(context->m_sql, "dbversion", 0); + dbversion = dc_sqlite3_get_config_int(context->sql, "dbversion", 0); - e2ee_enabled = context->m_e2ee_enabled; + e2ee_enabled = context->e2ee_enabled; - mdns_enabled = dc_sqlite3_get_config_int(context->m_sql, "mdns_enabled", DC_MDNS_DEFAULT_ENABLED); + mdns_enabled = dc_sqlite3_get_config_int(context->sql, "mdns_enabled", DC_MDNS_DEFAULT_ENABLED); - sqlite3_stmt* stmt = dc_sqlite3_prepare(context->m_sql, "SELECT COUNT(*) FROM keypairs;"); + sqlite3_stmt* stmt = dc_sqlite3_prepare(context->sql, "SELECT COUNT(*) FROM keypairs;"); sqlite3_step(stmt); prv_key_count = sqlite3_column_int(stmt, 0); sqlite3_finalize(stmt); - stmt = dc_sqlite3_prepare(context->m_sql, "SELECT COUNT(*) FROM acpeerstates;"); + stmt = dc_sqlite3_prepare(context->sql, "SELECT COUNT(*) FROM acpeerstates;"); sqlite3_step(stmt); pub_key_count = sqlite3_column_int(stmt, 0); sqlite3_finalize(stmt); - if( dc_key_load_self_public(self_public, l2->m_addr, context->m_sql) ) { + if( dc_key_load_self_public(self_public, l2->addr, context->sql) ) { fingerprint_str = dc_key_get_formatted_fingerprint(self_public); } else { @@ -525,7 +525,7 @@ char* dc_get_info(dc_context_t* context) /* In the frontends, additional software hints may follow here. */ , chats, real_msgs, deaddrop_msgs, contacts - , context->m_dbfile? context->m_dbfile : unset, dbversion, context->m_blobdir? context->m_blobdir : unset + , context->dbfile? context->dbfile : unset, dbversion, context->blobdir? context->blobdir : unset , displayname? displayname : unset , is_configured @@ -547,19 +547,19 @@ char* dc_get_info(dc_context_t* context) free(temp); /* add log excerpt */ - pthread_mutex_lock(&context->m_log_ringbuf_critical); /*take care not to log here! */ + pthread_mutex_lock(&context->log_ringbuf_critical); /*take care not to log here! */ for( int i = 0; i < DC_LOG_RINGBUF_SIZE; i++ ) { - int j = (context->m_log_ringbuf_pos+i) % DC_LOG_RINGBUF_SIZE; - if( context->m_log_ringbuf[j] ) { + int j = (context->log_ringbuf_pos+i) % DC_LOG_RINGBUF_SIZE; + if( context->log_ringbuf[j] ) { struct tm wanted_struct; - memcpy(&wanted_struct, localtime(&context->m_log_ringbuf_times[j]), sizeof(struct tm)); + memcpy(&wanted_struct, localtime(&context->log_ringbuf_times[j]), sizeof(struct tm)); temp = dc_mprintf("\n%02i:%02i:%02i ", (int)wanted_struct.tm_hour, (int)wanted_struct.tm_min, (int)wanted_struct.tm_sec); dc_strbuilder_cat(&ret, temp); - dc_strbuilder_cat(&ret, context->m_log_ringbuf[j]); + dc_strbuilder_cat(&ret, context->log_ringbuf[j]); free(temp); } } - pthread_mutex_unlock(&context->m_log_ringbuf_critical); + pthread_mutex_unlock(&context->log_ringbuf_critical); /* free data */ dc_loginparam_unref(l); @@ -569,7 +569,7 @@ char* dc_get_info(dc_context_t* context) free(l2_readable_str); free(fingerprint_str); dc_key_unref(self_public); - return ret.m_buf; /* must be freed by the caller */ + return ret.buf; /* must be freed by the caller */ } @@ -581,7 +581,7 @@ char* dc_get_info(dc_context_t* context) int dc_get_archived_count(dc_context_t* context) { int ret = 0; - sqlite3_stmt* stmt = dc_sqlite3_prepare(context->m_sql, + sqlite3_stmt* stmt = dc_sqlite3_prepare(context->sql, "SELECT COUNT(*) FROM chats WHERE blocked=0 AND archived=1;"); if( sqlite3_step(stmt) == SQLITE_ROW ) { ret = sqlite3_column_int(stmt, 0); @@ -617,7 +617,7 @@ dc_chatlist_t* dc_get_chatlist(dc_context_t* context, int listflags, const char* int success = 0; dc_chatlist_t* obj = dc_chatlist_new(context); - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC ) { goto cleanup; } @@ -656,7 +656,7 @@ dc_chat_t* dc_get_chat(dc_context_t* context, uint32_t chat_id) int success = 0; dc_chat_t* obj = dc_chat_new(context); - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC ) { goto cleanup; } @@ -694,11 +694,11 @@ void dc_marknoticed_chat(dc_context_t* context, uint32_t chat_id) "noticed" messages are not counted as being unread but are still waiting for being marked as "seen" using dc_markseen_msgs() */ sqlite3_stmt* stmt; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC ) { return; } - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "UPDATE msgs SET state=" DC_STRINGIFY(DC_STATE_IN_NOTICED) " WHERE chat_id=? AND state=" DC_STRINGIFY(DC_STATE_IN_FRESH) ";"); sqlite3_bind_int(stmt, 1, chat_id); sqlite3_step(stmt); @@ -722,7 +722,7 @@ uint32_t dc_get_chat_id_by_contact_id(dc_context_t* context, uint32_t contact_id uint32_t chat_id = 0; int chat_id_blocked = 0; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC ) { return 0; } @@ -744,7 +744,7 @@ uint32_t dc_get_chat_id_by_grpid(dc_context_t* context, const char* grpid, int* goto cleanup; } - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT id, blocked, type FROM chats WHERE grpid=?;"); sqlite3_bind_text (stmt, 1, grpid, -1, SQLITE_STATIC); if( sqlite3_step(stmt)==SQLITE_ROW ) { @@ -780,7 +780,7 @@ uint32_t dc_create_chat_by_contact_id(dc_context_t* context, uint32_t contact_id int chat_blocked = 0; int send_event = 0; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC ) { return 0; } @@ -807,7 +807,7 @@ uint32_t dc_create_chat_by_contact_id(dc_context_t* context, uint32_t contact_id cleanup: if( send_event ) { - context->m_cb(context, DC_EVENT_MSGS_CHANGED, 0, 0); + context->cb(context, DC_EVENT_MSGS_CHANGED, 0, 0); } return chat_id; @@ -846,30 +846,30 @@ uint32_t dc_create_chat_by_msg_id(dc_context_t* context, uint32_t msg_id) dc_msg_t* msg = dc_msg_new(); dc_chat_t* chat = dc_chat_new(context); - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC ) { goto cleanup; } if( !dc_msg_load_from_db(msg, context, msg_id) - || !dc_chat_load_from_db(chat, msg->m_chat_id) - || chat->m_id <= DC_CHAT_ID_LAST_SPECIAL ) { + || !dc_chat_load_from_db(chat, msg->chat_id) + || chat->id <= DC_CHAT_ID_LAST_SPECIAL ) { goto cleanup; } - chat_id = chat->m_id; + chat_id = chat->id; - if( chat->m_blocked ) { - dc_unblock_chat(context, chat->m_id); + if( chat->blocked ) { + dc_unblock_chat(context, chat->id); send_event = 1; } - dc_scaleup_contact_origin(context, msg->m_from_id, DC_ORIGIN_CREATE_CHAT); + dc_scaleup_contact_origin(context, msg->from_id, DC_ORIGIN_CREATE_CHAT); cleanup: dc_msg_unref(msg); dc_chat_unref(chat); if( send_event ) { - context->m_cb(context, DC_EVENT_MSGS_CHANGED, 0, 0); + context->cb(context, DC_EVENT_MSGS_CHANGED, 0, 0); } return chat_id; } @@ -889,13 +889,13 @@ cleanup: */ dc_array_t* dc_get_chat_media(dc_context_t* context, uint32_t chat_id, int msg_type, int or_msg_type) { - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC ) { return NULL; } dc_array_t* ret = dc_array_new(context, 100); - sqlite3_stmt* stmt = dc_sqlite3_prepare(context->m_sql, + sqlite3_stmt* stmt = dc_sqlite3_prepare(context->sql, "SELECT id FROM msgs WHERE chat_id=? AND (type=? OR type=?) ORDER BY timestamp, id;"); sqlite3_bind_int(stmt, 1, chat_id); sqlite3_bind_int(stmt, 2, msg_type); @@ -930,7 +930,7 @@ uint32_t dc_get_next_media(dc_context_t* context, uint32_t curr_msg_id, int dir) dc_array_t* list = NULL; int i, cnt; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC ) { goto cleanup; } @@ -938,7 +938,7 @@ uint32_t dc_get_next_media(dc_context_t* context, uint32_t curr_msg_id, int dir) goto cleanup; } - if( (list=dc_get_chat_media(context, msg->m_chat_id, msg->m_type, 0))==NULL ) { + if( (list=dc_get_chat_media(context, msg->chat_id, msg->type, 0))==NULL ) { goto cleanup; } @@ -995,7 +995,7 @@ dc_array_t* dc_get_chat_contacts(dc_context_t* context, uint32_t chat_id) dc_array_t* ret = dc_array_new(context, 100); sqlite3_stmt* stmt = NULL; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC ) { goto cleanup; } @@ -1003,7 +1003,7 @@ dc_array_t* dc_get_chat_contacts(dc_context_t* context, uint32_t chat_id) goto cleanup; /* we could also create a list for all contacts in the deaddrop by searching contacts belonging to chats with chats.blocked=2, however, currently this is not needed */ } - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT cc.contact_id FROM chats_contacts cc" " LEFT JOIN contacts c ON c.id=cc.contact_id" " WHERE cc.chat_id=?" @@ -1033,13 +1033,13 @@ dc_array_t* dc_get_fresh_msgs(dc_context_t* context) dc_array_t* ret = dc_array_new(context, 128); sqlite3_stmt* stmt = NULL; - if( context==NULL || context->m_magic != DC_CONTEXT_MAGIC || ret == NULL ) { + if( context==NULL || context->magic != DC_CONTEXT_MAGIC || ret == NULL ) { goto cleanup; } - show_deaddrop = 0;//dc_sqlite3_get_config_int__(context->m_sql, "show_deaddrop", 0); + show_deaddrop = 0;//dc_sqlite3_get_config_int__(context->sql, "show_deaddrop", 0); - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT m.id" " FROM msgs m" " LEFT JOIN contacts ct ON m.from_id=ct.id" @@ -1097,13 +1097,13 @@ dc_array_t* dc_get_chat_msgs(dc_context_t* context, uint32_t chat_id, uint32_t f long cnv_to_local = dc_gm2local_offset(); #define SECONDS_PER_DAY 86400 - if( context==NULL || context->m_magic != DC_CONTEXT_MAGIC || ret == NULL ) { + if( context==NULL || context->magic != DC_CONTEXT_MAGIC || ret == NULL ) { goto cleanup; } if( chat_id == DC_CHAT_ID_DEADDROP ) { - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT m.id, m.timestamp" " FROM msgs m" " LEFT JOIN chats ON m.chat_id=chats.id" @@ -1116,7 +1116,7 @@ dc_array_t* dc_get_chat_msgs(dc_context_t* context, uint32_t chat_id, uint32_t f } else if( chat_id == DC_CHAT_ID_STARRED ) { - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT m.id, m.timestamp" " FROM msgs m" " LEFT JOIN contacts ct ON m.from_id=ct.id" @@ -1127,7 +1127,7 @@ dc_array_t* dc_get_chat_msgs(dc_context_t* context, uint32_t chat_id, uint32_t f } else { - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT m.id, m.timestamp" " FROM msgs m" //" LEFT JOIN contacts ct ON m.from_id=ct.id" @@ -1205,7 +1205,7 @@ dc_array_t* dc_search_msgs(dc_context_t* context, uint32_t chat_id, const char* char* strLikeInText = NULL, *strLikeBeg=NULL, *real_query = NULL; sqlite3_stmt* stmt = NULL; - if( context==NULL || context->m_magic != DC_CONTEXT_MAGIC || ret == NULL || query == NULL ) { + if( context==NULL || context->magic != DC_CONTEXT_MAGIC || ret == NULL || query == NULL ) { goto cleanup; } @@ -1226,7 +1226,7 @@ dc_array_t* dc_search_msgs(dc_context_t* context, uint32_t chat_id, const char* this must be updated all the time and probably consumes more time than we can save in tenthousands of searches. For now, we just expect the following query to be fast enough :-) */ if( chat_id ) { - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT m.id, m.timestamp FROM msgs m" " LEFT JOIN contacts ct ON m.from_id=ct.id" " WHERE m.chat_id=? " @@ -1238,8 +1238,8 @@ dc_array_t* dc_search_msgs(dc_context_t* context, uint32_t chat_id, const char* sqlite3_bind_text(stmt, 3, strLikeBeg, -1, SQLITE_STATIC); } else { - int show_deaddrop = 0;//dc_sqlite3_get_config_int__(context->m_sql, "show_deaddrop", 0); - stmt = dc_sqlite3_prepare(context->m_sql, + int show_deaddrop = 0;//dc_sqlite3_get_config_int__(context->sql, "show_deaddrop", 0); + stmt = dc_sqlite3_prepare(context->sql, "SELECT m.id, m.timestamp FROM msgs m" " LEFT JOIN contacts ct ON m.from_id=ct.id" " LEFT JOIN chats c ON m.chat_id=c.id" @@ -1295,7 +1295,7 @@ void dc_set_draft(dc_context_t* context, uint32_t chat_id, const char* msg) sqlite3_stmt* stmt = NULL; dc_chat_t* chat = NULL; - if (context==NULL || context->m_magic!=DC_CONTEXT_MAGIC) { + if (context==NULL || context->magic!=DC_CONTEXT_MAGIC) { goto cleanup; } @@ -1307,29 +1307,29 @@ void dc_set_draft(dc_context_t* context, uint32_t chat_id, const char* msg) msg = NULL; // an empty draft is no draft } - if (chat->m_draft_text==NULL && msg==NULL - && chat->m_draft_timestamp==0) { + if (chat->draft_text==NULL && msg==NULL + && chat->draft_timestamp==0) { goto cleanup; // nothing to do - there is no old and no new draft } - if (chat->m_draft_timestamp && chat->m_draft_text && msg && strcmp(chat->m_draft_text, msg)==0) { + if (chat->draft_timestamp && chat->draft_text && msg && strcmp(chat->draft_text, msg)==0) { goto cleanup; // for equal texts, we do not update the timestamp } // save draft in object - NULL or empty: clear draft - free(chat->m_draft_text); - chat->m_draft_text = msg? dc_strdup(msg) : NULL; - chat->m_draft_timestamp = msg? time(NULL) : 0; + free(chat->draft_text); + chat->draft_text = msg? dc_strdup(msg) : NULL; + chat->draft_timestamp = msg? time(NULL) : 0; // save draft in database - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "UPDATE chats SET draft_timestamp=?, draft_txt=? WHERE id=?;"); - sqlite3_bind_int64(stmt, 1, chat->m_draft_timestamp); - sqlite3_bind_text (stmt, 2, chat->m_draft_text? chat->m_draft_text : "", -1, SQLITE_STATIC); - sqlite3_bind_int (stmt, 3, chat->m_id); + sqlite3_bind_int64(stmt, 1, chat->draft_timestamp); + sqlite3_bind_text (stmt, 2, chat->draft_text? chat->draft_text : "", -1, SQLITE_STATIC); + sqlite3_bind_int (stmt, 3, chat->id); sqlite3_step(stmt); - context->m_cb(context, DC_EVENT_MSGS_CHANGED, 0, 0); + context->cb(context, DC_EVENT_MSGS_CHANGED, 0, 0); cleanup: sqlite3_finalize(stmt); @@ -1342,7 +1342,7 @@ uint32_t dc_get_last_deaddrop_fresh_msg(dc_context_t* context) uint32_t ret = 0; sqlite3_stmt* stmt = NULL; - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT m.id " " FROM msgs m " " LEFT JOIN chats c ON c.id=m.chat_id " @@ -1368,11 +1368,11 @@ size_t dc_get_chat_cnt(dc_context_t* context) size_t ret = 0; sqlite3_stmt* stmt = NULL; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || context->m_sql->m_cobj==NULL ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || context->sql->cobj==NULL ) { goto cleanup; /* no database, no chats - this is no error (needed eg. for information) */ } - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT COUNT(*) FROM chats WHERE id>" DC_STRINGIFY(DC_CHAT_ID_LAST_SPECIAL) " AND blocked=0;"); if( sqlite3_step(stmt) != SQLITE_ROW ) { goto cleanup; @@ -1394,11 +1394,11 @@ void dc_lookup_real_nchat_by_contact_id(dc_context_t* context, uint32_t contact_ if( ret_chat_id ) { *ret_chat_id = 0; } if( ret_chat_blocked ) { *ret_chat_blocked = 0; } - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || context->m_sql->m_cobj==NULL ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || context->sql->cobj==NULL ) { return; /* no database, no chats - this is no error (needed eg. for information) */ } - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT c.id, c.blocked" " FROM chats c" " INNER JOIN chats_contacts j ON c.id=j.chat_id" @@ -1424,7 +1424,7 @@ void dc_create_or_lookup_nchat_by_contact_id(dc_context_t* context, uint32_t con if( ret_chat_id ) { *ret_chat_id = 0; } if( ret_chat_blocked ) { *ret_chat_blocked = 0; } - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || context->m_sql->m_cobj==NULL ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || context->sql->cobj==NULL ) { return; /* database not opened - error */ } @@ -1441,17 +1441,17 @@ void dc_create_or_lookup_nchat_by_contact_id(dc_context_t* context, uint32_t con /* get fine chat name */ contact = dc_contact_new(context); - if( !dc_contact_load_from_db(contact, context->m_sql, contact_id) ) { + if( !dc_contact_load_from_db(contact, context->sql, contact_id) ) { goto cleanup; } - chat_name = (contact->m_name&&contact->m_name[0])? contact->m_name : contact->m_addr; + chat_name = (contact->name&&contact->name[0])? contact->name : contact->addr; /* create chat record; the grpid is only used to make dc_sqlite3_get_rowid() work (we cannot use last_insert_id() due multi-threading) */ q = sqlite3_mprintf("INSERT INTO chats (type, name, param, blocked, grpid) VALUES(%i, %Q, %Q, %i, %Q)", DC_CHAT_TYPE_SINGLE, chat_name, - contact_id==DC_CONTACT_ID_SELF? "K=1" : "", create_blocked, contact->m_addr); + contact_id==DC_CONTACT_ID_SELF? "K=1" : "", create_blocked, contact->addr); assert( DC_PARAM_SELFTALK == 'K' ); - stmt = dc_sqlite3_prepare(context->m_sql, q); + stmt = dc_sqlite3_prepare(context->sql, q); if( stmt == NULL) { goto cleanup; } @@ -1460,7 +1460,7 @@ void dc_create_or_lookup_nchat_by_contact_id(dc_context_t* context, uint32_t con goto cleanup; } - chat_id = dc_sqlite3_get_rowid(context->m_sql, "chats", "grpid", contact->m_addr); + chat_id = dc_sqlite3_get_rowid(context->sql, "chats", "grpid", contact->addr); sqlite3_free(q); q = NULL; @@ -1469,7 +1469,7 @@ void dc_create_or_lookup_nchat_by_contact_id(dc_context_t* context, uint32_t con /* add contact IDs to the new chat record (may be replaced by dc_add_to_chat_contacts_table()) */ q = sqlite3_mprintf("INSERT INTO chats_contacts (chat_id, contact_id) VALUES(%i, %i)", chat_id, contact_id); - stmt = dc_sqlite3_prepare(context->m_sql, q); + stmt = dc_sqlite3_prepare(context->sql, q); if( sqlite3_step(stmt) != SQLITE_DONE ) { goto cleanup; @@ -1492,7 +1492,7 @@ cleanup: void dc_unarchive_chat(dc_context_t* context, uint32_t chat_id) { - sqlite3_stmt* stmt = dc_sqlite3_prepare(context->m_sql, + sqlite3_stmt* stmt = dc_sqlite3_prepare(context->sql, "UPDATE chats SET archived=0 WHERE id=?"); sqlite3_bind_int (stmt, 1, chat_id); sqlite3_step(stmt); @@ -1514,11 +1514,11 @@ int dc_get_total_msg_count(dc_context_t* context, uint32_t chat_id) int ret = 0; sqlite3_stmt* stmt = NULL; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC ) { goto cleanup; } - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT COUNT(*) FROM msgs WHERE chat_id=?;"); sqlite3_bind_int(stmt, 1, chat_id); if( sqlite3_step(stmt) != SQLITE_ROW ) { @@ -1547,11 +1547,11 @@ int dc_get_fresh_msg_count(dc_context_t* context, uint32_t chat_id) int ret = 0; sqlite3_stmt* stmt = NULL; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC ) { goto cleanup; } - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT COUNT(*) FROM msgs " " WHERE state=" DC_STRINGIFY(DC_STATE_IN_FRESH) " AND hidden=0 " @@ -1590,18 +1590,18 @@ cleanup: */ void dc_archive_chat(dc_context_t* context, uint32_t chat_id, int archive) { - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || chat_id <= DC_CHAT_ID_LAST_SPECIAL || (archive!=0 && archive!=1) ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || chat_id <= DC_CHAT_ID_LAST_SPECIAL || (archive!=0 && archive!=1) ) { return; } - sqlite3_stmt* stmt = dc_sqlite3_prepare(context->m_sql, + sqlite3_stmt* stmt = dc_sqlite3_prepare(context->sql, "UPDATE chats SET archived=? WHERE id=?;"); sqlite3_bind_int (stmt, 1, archive); sqlite3_bind_int (stmt, 2, chat_id); sqlite3_step(stmt); sqlite3_finalize(stmt); - context->m_cb(context, DC_EVENT_MSGS_CHANGED, 0, 0); + context->cb(context, DC_EVENT_MSGS_CHANGED, 0, 0); } @@ -1643,7 +1643,7 @@ void dc_delete_chat(dc_context_t* context, uint32_t chat_id) dc_chat_t* obj = dc_chat_new(context); char* q3 = NULL; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || chat_id <= DC_CHAT_ID_LAST_SPECIAL ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || chat_id <= DC_CHAT_ID_LAST_SPECIAL ) { goto cleanup; } @@ -1651,44 +1651,44 @@ void dc_delete_chat(dc_context_t* context, uint32_t chat_id) goto cleanup; } - dc_sqlite3_begin_transaction(context->m_sql); + dc_sqlite3_begin_transaction(context->sql); pending_transaction = 1; q3 = sqlite3_mprintf("DELETE FROM msgs_mdns WHERE msg_id IN (SELECT id FROM msgs WHERE chat_id=%i);", chat_id); - if( !dc_sqlite3_execute(context->m_sql, q3) ) { + if( !dc_sqlite3_execute(context->sql, q3) ) { goto cleanup; } sqlite3_free(q3); q3 = NULL; q3 = sqlite3_mprintf("DELETE FROM msgs WHERE chat_id=%i;", chat_id); - if( !dc_sqlite3_execute(context->m_sql, q3) ) { + if( !dc_sqlite3_execute(context->sql, q3) ) { goto cleanup; } sqlite3_free(q3); q3 = NULL; q3 = sqlite3_mprintf("DELETE FROM chats_contacts WHERE chat_id=%i;", chat_id); - if( !dc_sqlite3_execute(context->m_sql, q3) ) { + if( !dc_sqlite3_execute(context->sql, q3) ) { goto cleanup; } sqlite3_free(q3); q3 = NULL; q3 = sqlite3_mprintf("DELETE FROM chats WHERE id=%i;", chat_id); - if( !dc_sqlite3_execute(context->m_sql, q3) ) { + if( !dc_sqlite3_execute(context->sql, q3) ) { goto cleanup; } sqlite3_free(q3); q3 = NULL; - dc_sqlite3_commit(context->m_sql); + dc_sqlite3_commit(context->sql); pending_transaction = 0; - context->m_cb(context, DC_EVENT_MSGS_CHANGED, 0, 0); + context->cb(context, DC_EVENT_MSGS_CHANGED, 0, 0); cleanup: - if( pending_transaction ) { dc_sqlite3_rollback(context->m_sql); } + if( pending_transaction ) { dc_sqlite3_rollback(context->sql); } dc_chat_unref(obj); sqlite3_free(q3); } @@ -1727,61 +1727,61 @@ static uint32_t dc_send_msg_raw(dc_context_t* context, dc_chat_t* chat, const dc sqlite3_stmt* stmt = NULL; uint32_t msg_id = 0, to_id = 0; - if( !DC_CHAT_TYPE_CAN_SEND(chat->m_type) ) { - dc_log_error(context, 0, "Cannot send to chat type #%i.", chat->m_type); + if( !DC_CHAT_TYPE_CAN_SEND(chat->type) ) { + dc_log_error(context, 0, "Cannot send to chat type #%i.", chat->type); goto cleanup; } - if( DC_CHAT_TYPE_IS_MULTI(chat->m_type) && !dc_is_contact_in_chat(context, chat->m_id, DC_CONTACT_ID_SELF) ) { + if( DC_CHAT_TYPE_IS_MULTI(chat->type) && !dc_is_contact_in_chat(context, chat->id, DC_CONTACT_ID_SELF) ) { dc_log_error(context, DC_ERROR_SELF_NOT_IN_GROUP, NULL); goto cleanup; } { - char* from = dc_sqlite3_get_config(context->m_sql, "configured_addr", NULL); + char* from = dc_sqlite3_get_config(context->sql, "configured_addr", NULL); if( from == NULL ) { dc_log_error(context, 0, "Cannot send message, not configured."); goto cleanup; } - rfc724_mid = dc_create_outgoing_rfc724_mid(DC_CHAT_TYPE_IS_MULTI(chat->m_type)? chat->m_grpid : NULL, from); + rfc724_mid = dc_create_outgoing_rfc724_mid(DC_CHAT_TYPE_IS_MULTI(chat->type)? chat->grpid : NULL, from); free(from); } - if( chat->m_type == DC_CHAT_TYPE_SINGLE ) + if( chat->type == DC_CHAT_TYPE_SINGLE ) { - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT contact_id FROM chats_contacts WHERE chat_id=?;"); - sqlite3_bind_int(stmt, 1, chat->m_id); + sqlite3_bind_int(stmt, 1, chat->id); if( sqlite3_step(stmt) != SQLITE_ROW ) { - dc_log_error(context, 0, "Cannot send message, contact for chat #%i not found.", chat->m_id); + dc_log_error(context, 0, "Cannot send message, contact for chat #%i not found.", chat->id); goto cleanup; } to_id = sqlite3_column_int(stmt, 0); sqlite3_finalize(stmt); stmt = NULL; } - else if( DC_CHAT_TYPE_IS_MULTI(chat->m_type) ) + else if( DC_CHAT_TYPE_IS_MULTI(chat->type) ) { - if( dc_param_get_int(chat->m_param, DC_PARAM_UNPROMOTED, 0)==1 ) { + if( dc_param_get_int(chat->param, DC_PARAM_UNPROMOTED, 0)==1 ) { /* mark group as being no longer unpromoted */ - dc_param_set(chat->m_param, DC_PARAM_UNPROMOTED, NULL); + dc_param_set(chat->param, DC_PARAM_UNPROMOTED, NULL); dc_chat_update_param(chat); } } /* check if we can guarantee E2EE for this message. If we can, we won't send the message without E2EE later (because of a reset, changed settings etc. - messages may be delayed significally if there is no network present) */ int do_guarantee_e2ee = 0; - if( context->m_e2ee_enabled && dc_param_get_int(msg->m_param, DC_PARAM_FORCE_PLAINTEXT, 0)==0 ) + if( context->e2ee_enabled && dc_param_get_int(msg->param, DC_PARAM_FORCE_PLAINTEXT, 0)==0 ) { int can_encrypt = 1, all_mutual = 1; /* be optimistic */ - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT ps.prefer_encrypted " " FROM chats_contacts cc " " LEFT JOIN contacts c ON cc.contact_id=c.id " " LEFT JOIN acpeerstates ps ON c.addr=ps.addr " " WHERE cc.chat_id=? " /* take care that this statement returns NULL rows if there is no peerstates for a chat member! */ " AND cc.contact_id>" DC_STRINGIFY(DC_CONTACT_ID_LAST_SPECIAL) ";"); /* for DC_PARAM_SELFTALK this statement does not return any row */ - sqlite3_bind_int(stmt, 1, chat->m_id); + sqlite3_bind_int(stmt, 1, chat->id); while( sqlite3_step(stmt) == SQLITE_ROW ) { if( sqlite3_column_type(stmt, 0)==SQLITE_NULL ) { @@ -1805,7 +1805,7 @@ static uint32_t dc_send_msg_raw(dc_context_t* context, dc_chat_t* chat, const dc do_guarantee_e2ee = 1; } else { - if( last_msg_in_chat_encrypted(context->m_sql, chat->m_id) ) { + if( last_msg_in_chat_encrypted(context->sql, chat->id) ) { do_guarantee_e2ee = 1; } } @@ -1813,29 +1813,29 @@ static uint32_t dc_send_msg_raw(dc_context_t* context, dc_chat_t* chat, const dc } if( do_guarantee_e2ee ) { - dc_param_set_int(msg->m_param, DC_PARAM_GUARANTEE_E2EE, 1); + dc_param_set_int(msg->param, DC_PARAM_GUARANTEE_E2EE, 1); } - dc_param_set(msg->m_param, DC_PARAM_ERRONEOUS_E2EE, NULL); /* reset eg. on forwarding */ + dc_param_set(msg->param, DC_PARAM_ERRONEOUS_E2EE, NULL); /* reset eg. on forwarding */ /* add message to the database */ - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "INSERT INTO msgs (rfc724_mid,chat_id,from_id,to_id, timestamp,type,state, txt,param,hidden) VALUES (?,?,?,?, ?,?,?, ?,?,?);"); sqlite3_bind_text (stmt, 1, rfc724_mid, -1, SQLITE_STATIC); - sqlite3_bind_int (stmt, 2, chat->m_id); + sqlite3_bind_int (stmt, 2, chat->id); sqlite3_bind_int (stmt, 3, DC_CONTACT_ID_SELF); sqlite3_bind_int (stmt, 4, to_id); sqlite3_bind_int64(stmt, 5, timestamp); - sqlite3_bind_int (stmt, 6, msg->m_type); + sqlite3_bind_int (stmt, 6, msg->type); sqlite3_bind_int (stmt, 7, DC_STATE_OUT_PENDING); - sqlite3_bind_text (stmt, 8, msg->m_text? msg->m_text : "", -1, SQLITE_STATIC); - sqlite3_bind_text (stmt, 9, msg->m_param->m_packed, -1, SQLITE_STATIC); - sqlite3_bind_int (stmt, 10, msg->m_hidden); + sqlite3_bind_text (stmt, 8, msg->text? msg->text : "", -1, SQLITE_STATIC); + sqlite3_bind_text (stmt, 9, msg->param->packed, -1, SQLITE_STATIC); + sqlite3_bind_int (stmt, 10, msg->hidden); if( sqlite3_step(stmt) != SQLITE_DONE ) { - dc_log_error(context, 0, "Cannot send message, cannot insert to database.", chat->m_id); + dc_log_error(context, 0, "Cannot send message, cannot insert to database.", chat->id); goto cleanup; } - msg_id = dc_sqlite3_get_rowid(context->m_sql, "msgs", "rfc724_mid", rfc724_mid); + msg_id = dc_sqlite3_get_rowid(context->sql, "msgs", "rfc724_mid", rfc724_mid); dc_job_add(context, DC_JOB_SEND_MSG_TO_SMTP, msg_id, NULL, 0); cleanup: @@ -1870,20 +1870,20 @@ uint32_t dc_send_msg_object(dc_context_t* context, uint32_t chat_id, dc_msg_t* m char* pathNfilename = NULL; dc_chat_t* chat = NULL; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || msg == NULL || chat_id <= DC_CHAT_ID_LAST_SPECIAL ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || msg == NULL || chat_id <= DC_CHAT_ID_LAST_SPECIAL ) { return 0; } - msg->m_id = 0; - msg->m_context = context; + msg->id = 0; + msg->context = context; - if( msg->m_type == DC_MSG_TEXT ) + if( msg->type == DC_MSG_TEXT ) { ; /* the caller should check if the message text is empty */ } - else if( DC_MSG_NEEDS_ATTACHMENT(msg->m_type) ) + else if( DC_MSG_NEEDS_ATTACHMENT(msg->type) ) { - pathNfilename = dc_param_get(msg->m_param, DC_PARAM_FILE, NULL); + pathNfilename = dc_param_get(msg->param, DC_PARAM_FILE, NULL); if( pathNfilename ) { /* Got an attachment. Take care, the file may not be ready in this moment! @@ -1891,7 +1891,7 @@ uint32_t dc_send_msg_object(dc_context_t* context, uint32_t chat_id, dc_msg_t* m In this case, the user should create an `.increation`; when the file is deleted later on, the message is sent. (we do not use a state in the database as this would make eg. forwarding such messages much more complicated) */ - if( msg->m_type == DC_MSG_FILE || msg->m_type == DC_MSG_IMAGE ) + if( msg->type == DC_MSG_FILE || msg->type == DC_MSG_IMAGE ) { /* Correct the type, take care not to correct already very special formats as GIF or VOICE. Typical conversions: @@ -1901,74 +1901,74 @@ uint32_t dc_send_msg_object(dc_context_t* context, uint32_t chat_id, dc_msg_t* m char* better_mime = NULL; dc_msg_guess_msgtype_from_suffix(pathNfilename, &better_type, &better_mime); if( better_type ) { - msg->m_type = better_type; - dc_param_set(msg->m_param, DC_PARAM_MIMETYPE, better_mime); + msg->type = better_type; + dc_param_set(msg->param, DC_PARAM_MIMETYPE, better_mime); } free(better_mime); } - if( (msg->m_type == DC_MSG_IMAGE || msg->m_type == DC_MSG_GIF) - && (dc_param_get_int(msg->m_param, DC_PARAM_WIDTH, 0)<=0 || dc_param_get_int(msg->m_param, DC_PARAM_HEIGHT, 0)<=0) ) { + if( (msg->type == DC_MSG_IMAGE || msg->type == DC_MSG_GIF) + && (dc_param_get_int(msg->param, DC_PARAM_WIDTH, 0)<=0 || dc_param_get_int(msg->param, DC_PARAM_HEIGHT, 0)<=0) ) { /* set width/height of images, if not yet done */ unsigned char* buf = NULL; size_t buf_bytes; uint32_t w, h; - if( dc_read_file(pathNfilename, (void**)&buf, &buf_bytes, msg->m_context) ) { + if( dc_read_file(pathNfilename, (void**)&buf, &buf_bytes, msg->context) ) { if( dc_get_filemeta(buf, buf_bytes, &w, &h) ) { - dc_param_set_int(msg->m_param, DC_PARAM_WIDTH, w); - dc_param_set_int(msg->m_param, DC_PARAM_HEIGHT, h); + dc_param_set_int(msg->param, DC_PARAM_WIDTH, w); + dc_param_set_int(msg->param, DC_PARAM_HEIGHT, h); } } free(buf); } - dc_log_info(context, 0, "Attaching \"%s\" for message type #%i.", pathNfilename, (int)msg->m_type); + dc_log_info(context, 0, "Attaching \"%s\" for message type #%i.", pathNfilename, (int)msg->type); - if( msg->m_text ) { free(msg->m_text); } - if( msg->m_type == DC_MSG_AUDIO ) { + if( msg->text ) { free(msg->text); } + if( msg->type == DC_MSG_AUDIO ) { char* filename = dc_get_filename(pathNfilename); - char* author = dc_param_get(msg->m_param, DC_PARAM_AUTHORNAME, ""); - char* title = dc_param_get(msg->m_param, DC_PARAM_TRACKNAME, ""); - msg->m_text = dc_mprintf("%s %s %s", filename, author, title); /* for outgoing messages, also add the mediainfo. For incoming messages, this is not needed as the filename is build from these information */ + char* author = dc_param_get(msg->param, DC_PARAM_AUTHORNAME, ""); + char* title = dc_param_get(msg->param, DC_PARAM_TRACKNAME, ""); + msg->text = dc_mprintf("%s %s %s", filename, author, title); /* for outgoing messages, also add the mediainfo. For incoming messages, this is not needed as the filename is build from these information */ free(filename); free(author); free(title); } - else if( DC_MSG_MAKE_FILENAME_SEARCHABLE(msg->m_type) ) { - msg->m_text = dc_get_filename(pathNfilename); + else if( DC_MSG_MAKE_FILENAME_SEARCHABLE(msg->type) ) { + msg->text = dc_get_filename(pathNfilename); } - else if( DC_MSG_MAKE_SUFFIX_SEARCHABLE(msg->m_type) ) { - msg->m_text = dc_get_filesuffix_lc(pathNfilename); + else if( DC_MSG_MAKE_SUFFIX_SEARCHABLE(msg->type) ) { + msg->text = dc_get_filesuffix_lc(pathNfilename); } } else { - dc_log_error(context, 0, "Attachment missing for message of type #%i.", (int)msg->m_type); /* should not happen */ + dc_log_error(context, 0, "Attachment missing for message of type #%i.", (int)msg->type); /* should not happen */ goto cleanup; } } else { - dc_log_error(context, 0, "Cannot send messages of type #%i.", (int)msg->m_type); /* should not happen */ + dc_log_error(context, 0, "Cannot send messages of type #%i.", (int)msg->type); /* should not happen */ goto cleanup; } dc_unarchive_chat(context, chat_id); - context->m_smtp->m_log_connect_errors = 1; + context->smtp->log_connect_errors = 1; chat = dc_chat_new(context); if( dc_chat_load_from_db(chat, chat_id) ) { - msg->m_id = dc_send_msg_raw(context, chat, msg, dc_create_smeared_timestamp(context)); - if( msg ->m_id == 0 ) { + msg->id = dc_send_msg_raw(context, chat, msg, dc_create_smeared_timestamp(context)); + if( msg ->id == 0 ) { goto cleanup; /* error already logged */ } } - context->m_cb(context, DC_EVENT_MSGS_CHANGED, chat_id, msg->m_id); + context->cb(context, DC_EVENT_MSGS_CHANGED, chat_id, msg->id); cleanup: dc_chat_unref(chat); free(pathNfilename); - return msg->m_id; + return msg->id; } @@ -1993,12 +1993,12 @@ uint32_t dc_send_text_msg(dc_context_t* context, uint32_t chat_id, const char* t dc_msg_t* msg = dc_msg_new(); uint32_t ret = 0; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || chat_id <= DC_CHAT_ID_LAST_SPECIAL || text_to_send == NULL ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || chat_id <= DC_CHAT_ID_LAST_SPECIAL || text_to_send == NULL ) { goto cleanup; } - msg->m_type = DC_MSG_TEXT; - msg->m_text = dc_strdup(text_to_send); + msg->type = DC_MSG_TEXT; + msg->text = dc_strdup(text_to_send); ret = dc_send_msg_object(context, chat_id, msg); @@ -2032,14 +2032,14 @@ uint32_t dc_send_image_msg(dc_context_t* context, uint32_t chat_id, const char* dc_msg_t* msg = dc_msg_new(); uint32_t ret = 0; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || chat_id <= DC_CHAT_ID_LAST_SPECIAL || file == NULL ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || chat_id <= DC_CHAT_ID_LAST_SPECIAL || file == NULL ) { goto cleanup; } - msg->m_type = DC_MSG_IMAGE; - dc_param_set (msg->m_param, DC_PARAM_FILE, file); - dc_param_set_int(msg->m_param, DC_PARAM_WIDTH, width); /* set in sending job, if 0 */ - dc_param_set_int(msg->m_param, DC_PARAM_HEIGHT, height); /* set in sending job, if 0 */ + msg->type = DC_MSG_IMAGE; + dc_param_set (msg->param, DC_PARAM_FILE, file); + dc_param_set_int(msg->param, DC_PARAM_WIDTH, width); /* set in sending job, if 0 */ + dc_param_set_int(msg->param, DC_PARAM_HEIGHT, height); /* set in sending job, if 0 */ ret = dc_send_msg_object(context, chat_id, msg); @@ -2075,16 +2075,16 @@ uint32_t dc_send_video_msg(dc_context_t* context, uint32_t chat_id, const char* dc_msg_t* msg = dc_msg_new(); uint32_t ret = 0; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || chat_id <= DC_CHAT_ID_LAST_SPECIAL || file == NULL ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || chat_id <= DC_CHAT_ID_LAST_SPECIAL || file == NULL ) { goto cleanup; } - msg->m_type = DC_MSG_VIDEO; - dc_param_set (msg->m_param, DC_PARAM_FILE, file); - dc_param_set (msg->m_param, DC_PARAM_MIMETYPE, filemime); - dc_param_set_int(msg->m_param, DC_PARAM_WIDTH, width); - dc_param_set_int(msg->m_param, DC_PARAM_HEIGHT, height); - dc_param_set_int(msg->m_param, DC_PARAM_DURATION, duration); + msg->type = DC_MSG_VIDEO; + dc_param_set (msg->param, DC_PARAM_FILE, file); + dc_param_set (msg->param, DC_PARAM_MIMETYPE, filemime); + dc_param_set_int(msg->param, DC_PARAM_WIDTH, width); + dc_param_set_int(msg->param, DC_PARAM_HEIGHT, height); + dc_param_set_int(msg->param, DC_PARAM_DURATION, duration); ret = dc_send_msg_object(context, chat_id, msg); @@ -2117,14 +2117,14 @@ uint32_t dc_send_voice_msg(dc_context_t* context, uint32_t chat_id, const char* dc_msg_t* msg = dc_msg_new(); uint32_t ret = 0; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || chat_id <= DC_CHAT_ID_LAST_SPECIAL || file == NULL ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || chat_id <= DC_CHAT_ID_LAST_SPECIAL || file == NULL ) { goto cleanup; } - msg->m_type = DC_MSG_VOICE; - dc_param_set (msg->m_param, DC_PARAM_FILE, file); - dc_param_set (msg->m_param, DC_PARAM_MIMETYPE, filemime); - dc_param_set_int(msg->m_param, DC_PARAM_DURATION, duration); + msg->type = DC_MSG_VOICE; + dc_param_set (msg->param, DC_PARAM_FILE, file); + dc_param_set (msg->param, DC_PARAM_MIMETYPE, filemime); + dc_param_set_int(msg->param, DC_PARAM_DURATION, duration); ret = dc_send_msg_object(context, chat_id, msg); @@ -2158,16 +2158,16 @@ uint32_t dc_send_audio_msg(dc_context_t* context, uint32_t chat_id, const char* dc_msg_t* msg = dc_msg_new(); uint32_t ret = 0; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || chat_id <= DC_CHAT_ID_LAST_SPECIAL || file == NULL ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || chat_id <= DC_CHAT_ID_LAST_SPECIAL || file == NULL ) { goto cleanup; } - msg->m_type = DC_MSG_AUDIO; - dc_param_set (msg->m_param, DC_PARAM_FILE, file); - dc_param_set (msg->m_param, DC_PARAM_MIMETYPE, filemime); - dc_param_set_int(msg->m_param, DC_PARAM_DURATION, duration); - dc_param_set (msg->m_param, DC_PARAM_AUTHORNAME, author); - dc_param_set (msg->m_param, DC_PARAM_TRACKNAME, trackname); + msg->type = DC_MSG_AUDIO; + dc_param_set (msg->param, DC_PARAM_FILE, file); + dc_param_set (msg->param, DC_PARAM_MIMETYPE, filemime); + dc_param_set_int(msg->param, DC_PARAM_DURATION, duration); + dc_param_set (msg->param, DC_PARAM_AUTHORNAME, author); + dc_param_set (msg->param, DC_PARAM_TRACKNAME, trackname); ret = dc_send_msg_object(context, chat_id, msg); @@ -2198,13 +2198,13 @@ uint32_t dc_send_file_msg(dc_context_t* context, uint32_t chat_id, const char* f dc_msg_t* msg = dc_msg_new(); uint32_t ret = 0; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || chat_id <= DC_CHAT_ID_LAST_SPECIAL || file == NULL ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || chat_id <= DC_CHAT_ID_LAST_SPECIAL || file == NULL ) { goto cleanup; } - msg->m_type = DC_MSG_FILE; - dc_param_set(msg->m_param, DC_PARAM_FILE, file); - dc_param_set(msg->m_param, DC_PARAM_MIMETYPE, filemime); + msg->type = DC_MSG_FILE; + dc_param_set(msg->param, DC_PARAM_FILE, file); + dc_param_set(msg->param, DC_PARAM_MIMETYPE, filemime); ret = dc_send_msg_object(context, chat_id, msg); @@ -2241,7 +2241,7 @@ uint32_t dc_send_vcard_msg(dc_context_t* context, uint32_t chat_id, uint32_t con dc_contact_t* contact = NULL; char* text_to_send = NULL; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || chat_id <= DC_CHAT_ID_LAST_SPECIAL ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || chat_id <= DC_CHAT_ID_LAST_SPECIAL ) { goto cleanup; } @@ -2249,11 +2249,11 @@ uint32_t dc_send_vcard_msg(dc_context_t* context, uint32_t chat_id, uint32_t con goto cleanup; } - if( contact->m_authname && contact->m_authname[0] ) { - text_to_send = dc_mprintf("%s: %s", contact->m_authname, contact->m_addr); + if( contact->authname && contact->authname[0] ) { + text_to_send = dc_mprintf("%s: %s", contact->authname, contact->addr); } else { - text_to_send = dc_strdup(contact->m_addr); + text_to_send = dc_strdup(contact->addr); } ret = dc_send_text_msg(context, chat_id, text_to_send); @@ -2277,11 +2277,11 @@ void dc_add_device_msg(dc_context_t* context, uint32_t chat_id, const char* text sqlite3_stmt* stmt = NULL; char* rfc724_mid = dc_create_outgoing_rfc724_mid(NULL, "@device"); - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || text == NULL ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || text == NULL ) { goto cleanup; } - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "INSERT INTO msgs (chat_id,from_id,to_id, timestamp,type,state, txt,rfc724_mid) VALUES (?,?,?, ?,?,?, ?,?);"); sqlite3_bind_int (stmt, 1, chat_id); sqlite3_bind_int (stmt, 2, DC_CONTACT_ID_DEVICE); @@ -2294,8 +2294,8 @@ void dc_add_device_msg(dc_context_t* context, uint32_t chat_id, const char* text if( sqlite3_step(stmt) != SQLITE_DONE ) { goto cleanup; } - msg_id = dc_sqlite3_get_rowid(context->m_sql, "msgs", "rfc724_mid", rfc724_mid); - context->m_cb(context, DC_EVENT_MSGS_CHANGED, chat_id, msg_id); + msg_id = dc_sqlite3_get_rowid(context->sql, "msgs", "rfc724_mid", rfc724_mid); + context->cb(context, DC_EVENT_MSGS_CHANGED, chat_id, msg_id); cleanup: free(rfc724_mid); @@ -2309,12 +2309,12 @@ cleanup: #define IS_SELF_IN_GROUP (dc_is_contact_in_chat(context, chat_id, DC_CONTACT_ID_SELF)==1) -#define DO_SEND_STATUS_MAILS (dc_param_get_int(chat->m_param, DC_PARAM_UNPROMOTED, 0)==0) +#define DO_SEND_STATUS_MAILS (dc_param_get_int(chat->param, DC_PARAM_UNPROMOTED, 0)==0) int dc_is_group_explicitly_left(dc_context_t* context, const char* grpid) { - sqlite3_stmt* stmt = dc_sqlite3_prepare(context->m_sql, "SELECT id FROM leftgrps WHERE grpid=?;"); + sqlite3_stmt* stmt = dc_sqlite3_prepare(context->sql, "SELECT id FROM leftgrps WHERE grpid=?;"); sqlite3_bind_text (stmt, 1, grpid, -1, SQLITE_STATIC); int ret = (sqlite3_step(stmt)==SQLITE_ROW); sqlite3_finalize(stmt); @@ -2326,7 +2326,7 @@ void dc_set_group_explicitly_left(dc_context_t* context, const char* grpid) { if( !dc_is_group_explicitly_left(context, grpid) ) { - sqlite3_stmt* stmt = dc_sqlite3_prepare(context->m_sql, "INSERT INTO leftgrps (grpid) VALUES(?);"); + sqlite3_stmt* stmt = dc_sqlite3_prepare(context->sql, "INSERT INTO leftgrps (grpid) VALUES(?);"); sqlite3_bind_text (stmt, 1, grpid, -1, SQLITE_STATIC); sqlite3_step(stmt); sqlite3_finalize(stmt); @@ -2340,12 +2340,12 @@ static int dc_real_group_exists(dc_context_t* context, uint32_t chat_id) sqlite3_stmt* stmt = NULL; int ret = 0; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || context->m_sql->m_cobj==NULL + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || context->sql->cobj==NULL || chat_id <= DC_CHAT_ID_LAST_SPECIAL ) { return 0; } - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT id FROM chats " " WHERE id=? " " AND (type=" DC_STRINGIFY(DC_CHAT_TYPE_GROUP) " OR type=" DC_STRINGIFY(DC_CHAT_TYPE_VERIFIED_GROUP) ");"); @@ -2363,7 +2363,7 @@ int dc_add_to_chat_contacts_table(dc_context_t* context, uint32_t chat_id, uint3 { /* add a contact to a chat; the function does not check the type or if any of the record exist or are already added to the chat! */ int ret = 0; - sqlite3_stmt* stmt = dc_sqlite3_prepare(context->m_sql, + sqlite3_stmt* stmt = dc_sqlite3_prepare(context->sql, "INSERT INTO chats_contacts (chat_id, contact_id) VALUES(?, ?)"); sqlite3_bind_int(stmt, 1, chat_id); sqlite3_bind_int(stmt, 2, contact_id); @@ -2402,14 +2402,14 @@ uint32_t dc_create_group_chat(dc_context_t* context, int verified, const char* c char* draft_txt = NULL, *grpid = NULL; sqlite3_stmt* stmt = NULL; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || chat_name==NULL || chat_name[0]==0 ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || chat_name==NULL || chat_name[0]==0 ) { return 0; } draft_txt = dc_stock_str_repl_string(context, DC_STR_NEWGROUPDRAFT, chat_name); grpid = dc_create_id(); - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "INSERT INTO chats (type, name, draft_timestamp, draft_txt, grpid, param) VALUES(?, ?, ?, ?, ?, 'U=1');" /*U=DC_PARAM_UNPROMOTED*/ ); sqlite3_bind_int (stmt, 1, verified? DC_CHAT_TYPE_VERIFIED_GROUP : DC_CHAT_TYPE_GROUP); sqlite3_bind_text (stmt, 2, chat_name, -1, SQLITE_STATIC); @@ -2420,7 +2420,7 @@ uint32_t dc_create_group_chat(dc_context_t* context, int verified, const char* c goto cleanup; } - if( (chat_id=dc_sqlite3_get_rowid(context->m_sql, "chats", "grpid", grpid)) == 0 ) { + if( (chat_id=dc_sqlite3_get_rowid(context->sql, "chats", "grpid", grpid)) == 0 ) { goto cleanup; } @@ -2434,7 +2434,7 @@ cleanup: free(grpid); if( chat_id ) { - context->m_cb(context, DC_EVENT_MSGS_CHANGED, 0, 0); + context->cb(context, DC_EVENT_MSGS_CHANGED, 0, 0); } return chat_id; @@ -2463,7 +2463,7 @@ int dc_set_chat_name(dc_context_t* context, uint32_t chat_id, const char* new_na dc_msg_t* msg = dc_msg_new(); char* q3 = NULL; - if( context==NULL || context->m_magic != DC_CONTEXT_MAGIC || new_name==NULL || new_name[0]==0 || chat_id <= DC_CHAT_ID_LAST_SPECIAL ) { + if( context==NULL || context->magic != DC_CONTEXT_MAGIC || new_name==NULL || new_name[0]==0 || chat_id <= DC_CHAT_ID_LAST_SPECIAL ) { goto cleanup; } @@ -2472,7 +2472,7 @@ int dc_set_chat_name(dc_context_t* context, uint32_t chat_id, const char* new_na goto cleanup; } - if( strcmp(chat->m_name, new_name)==0 ) { + if( strcmp(chat->name, new_name)==0 ) { success = 1; goto cleanup; /* name not modified */ } @@ -2483,20 +2483,20 @@ int dc_set_chat_name(dc_context_t* context, uint32_t chat_id, const char* new_na } q3 = sqlite3_mprintf("UPDATE chats SET name=%Q WHERE id=%i;", new_name, chat_id); - if( !dc_sqlite3_execute(context->m_sql, q3) ) { + if( !dc_sqlite3_execute(context->sql, q3) ) { goto cleanup; } /* send a status mail to all group members, also needed for outself to allow multi-client */ if( DO_SEND_STATUS_MAILS ) { - msg->m_type = DC_MSG_TEXT; - msg->m_text = dc_stock_str_repl_string2(context, DC_STR_MSGGRPNAME, chat->m_name, new_name); - dc_param_set_int(msg->m_param, DC_PARAM_CMD, DC_CMD_GROUPNAME_CHANGED); - msg->m_id = dc_send_msg_object(context, chat_id, msg); - context->m_cb(context, DC_EVENT_MSGS_CHANGED, chat_id, msg->m_id); + msg->type = DC_MSG_TEXT; + msg->text = dc_stock_str_repl_string2(context, DC_STR_MSGGRPNAME, chat->name, new_name); + dc_param_set_int(msg->param, DC_PARAM_CMD, DC_CMD_GROUPNAME_CHANGED); + msg->id = dc_send_msg_object(context, chat_id, msg); + context->cb(context, DC_EVENT_MSGS_CHANGED, chat_id, msg->id); } - context->m_cb(context, DC_EVENT_CHAT_MODIFIED, chat_id, 0); + context->cb(context, DC_EVENT_CHAT_MODIFIED, chat_id, 0); success = 1; @@ -2531,7 +2531,7 @@ int dc_set_chat_profile_image(dc_context_t* context, uint32_t chat_id, const cha dc_chat_t* chat = dc_chat_new(context); dc_msg_t* msg = dc_msg_new(); - if( context==NULL || context->m_magic != DC_CONTEXT_MAGIC || chat_id <= DC_CHAT_ID_LAST_SPECIAL ) { + if( context==NULL || context->magic != DC_CONTEXT_MAGIC || chat_id <= DC_CHAT_ID_LAST_SPECIAL ) { goto cleanup; } @@ -2545,7 +2545,7 @@ int dc_set_chat_profile_image(dc_context_t* context, uint32_t chat_id, const cha goto cleanup; /* we shoud respect this - whatever we send to the group, it gets discarded anyway! */ } - dc_param_set(chat->m_param, DC_PARAM_PROFILE_IMAGE, new_image/*may be NULL*/); + dc_param_set(chat->param, DC_PARAM_PROFILE_IMAGE, new_image/*may be NULL*/); if( !dc_chat_update_param(chat) ) { goto cleanup; } @@ -2553,14 +2553,14 @@ int dc_set_chat_profile_image(dc_context_t* context, uint32_t chat_id, const cha /* send a status mail to all group members, also needed for outself to allow multi-client */ if( DO_SEND_STATUS_MAILS ) { - dc_param_set_int(msg->m_param, DC_PARAM_CMD, DC_CMD_GROUPIMAGE_CHANGED); - dc_param_set (msg->m_param, DC_PARAM_CMD_ARG, new_image); - msg->m_type = DC_MSG_TEXT; - msg->m_text = dc_stock_str(context, new_image? DC_STR_MSGGRPIMGCHANGED : DC_STR_MSGGRPIMGDELETED); - msg->m_id = dc_send_msg_object(context, chat_id, msg); - context->m_cb(context, DC_EVENT_MSGS_CHANGED, chat_id, msg->m_id); + dc_param_set_int(msg->param, DC_PARAM_CMD, DC_CMD_GROUPIMAGE_CHANGED); + dc_param_set (msg->param, DC_PARAM_CMD_ARG, new_image); + msg->type = DC_MSG_TEXT; + msg->text = dc_stock_str(context, new_image? DC_STR_MSGGRPIMGCHANGED : DC_STR_MSGGRPIMGDELETED); + msg->id = dc_send_msg_object(context, chat_id, msg); + context->cb(context, DC_EVENT_MSGS_CHANGED, chat_id, msg->id); } - context->m_cb(context, DC_EVENT_CHAT_MODIFIED, chat_id, 0); + context->cb(context, DC_EVENT_CHAT_MODIFIED, chat_id, 0); success = 1; @@ -2574,7 +2574,7 @@ cleanup: int dc_get_chat_contact_count(dc_context_t* context, uint32_t chat_id) { int ret = 0; - sqlite3_stmt* stmt = dc_sqlite3_prepare(context->m_sql, + sqlite3_stmt* stmt = dc_sqlite3_prepare(context->sql, "SELECT COUNT(*) FROM chats_contacts WHERE chat_id=?;"); sqlite3_bind_int(stmt, 1, chat_id); if( sqlite3_step(stmt) == SQLITE_ROW ) { @@ -2602,11 +2602,11 @@ int dc_is_contact_in_chat(dc_context_t* context, uint32_t chat_id, uint32_t cont int ret = 0; sqlite3_stmt* stmt = NULL; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC ) { goto cleanup; } - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT contact_id FROM chats_contacts WHERE chat_id=? AND contact_id=?;"); sqlite3_bind_int(stmt, 1, chat_id); sqlite3_bind_int(stmt, 2, contact_id); @@ -2627,7 +2627,7 @@ int dc_add_contact_to_chat_ex(dc_context_t* context, uint32_t chat_id, uint32_t dc_msg_t* msg = dc_msg_new(); char* self_addr = NULL; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || contact == NULL || chat_id <= DC_CHAT_ID_LAST_SPECIAL ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || contact == NULL || chat_id <= DC_CHAT_ID_LAST_SPECIAL ) { goto cleanup; } @@ -2642,14 +2642,14 @@ int dc_add_contact_to_chat_ex(dc_context_t* context, uint32_t chat_id, uint32_t goto cleanup; /* we shoud respect this - whatever we send to the group, it gets discarded anyway! */ } - if( (flags&DC_FROM_HANDSHAKE) && dc_param_get_int(chat->m_param, DC_PARAM_UNPROMOTED, 0)==1 ) { + if( (flags&DC_FROM_HANDSHAKE) && dc_param_get_int(chat->param, DC_PARAM_UNPROMOTED, 0)==1 ) { // after a handshake, force sending the `Chat-Group-Member-Added` message - dc_param_set(chat->m_param, DC_PARAM_UNPROMOTED, NULL); + dc_param_set(chat->param, DC_PARAM_UNPROMOTED, NULL); dc_chat_update_param(chat); } - self_addr = dc_sqlite3_get_config(context->m_sql, "configured_addr", ""); - if( strcasecmp(contact->m_addr, self_addr)==0 ) { + self_addr = dc_sqlite3_get_config(context->sql, "configured_addr", ""); + if( strcasecmp(contact->addr, self_addr)==0 ) { goto cleanup; /* ourself is added using DC_CONTACT_ID_SELF, do not add it explicitly. if SELF is not in the group, members cannot be added at all. */ } @@ -2663,9 +2663,9 @@ int dc_add_contact_to_chat_ex(dc_context_t* context, uint32_t chat_id, uint32_t } else { - if( chat->m_type == DC_CHAT_TYPE_VERIFIED_GROUP ) + if( chat->type == DC_CHAT_TYPE_VERIFIED_GROUP ) { - if( !dc_apeerstate_load_by_addr(peerstate, context->m_sql, contact->m_addr) + if( !dc_apeerstate_load_by_addr(peerstate, context->sql, contact->addr) || dc_contact_n_peerstate_are_verified(contact, peerstate) != DC_BIDIRECT_VERIFIED ) { dc_log_error(context, 0, "Only bidirectional verified contacts can be added to verfied groups."); goto cleanup; @@ -2680,15 +2680,15 @@ int dc_add_contact_to_chat_ex(dc_context_t* context, uint32_t chat_id, uint32_t /* send a status mail to all group members */ if( DO_SEND_STATUS_MAILS ) { - msg->m_type = DC_MSG_TEXT; - msg->m_text = dc_stock_str_repl_string(context, DC_STR_MSGADDMEMBER, (contact->m_authname&&contact->m_authname[0])? contact->m_authname : contact->m_addr); - dc_param_set_int(msg->m_param, DC_PARAM_CMD, DC_CMD_MEMBER_ADDED_TO_GROUP); - dc_param_set (msg->m_param, DC_PARAM_CMD_ARG ,contact->m_addr); - dc_param_set_int(msg->m_param, DC_PARAM_CMD_ARG2,flags); // combine the Secure-Join protocol headers with the Chat-Group-Member-Added header - msg->m_id = dc_send_msg_object(context, chat_id, msg); - context->m_cb(context, DC_EVENT_MSGS_CHANGED, chat_id, msg->m_id); + msg->type = DC_MSG_TEXT; + msg->text = dc_stock_str_repl_string(context, DC_STR_MSGADDMEMBER, (contact->authname&&contact->authname[0])? contact->authname : contact->addr); + dc_param_set_int(msg->param, DC_PARAM_CMD, DC_CMD_MEMBER_ADDED_TO_GROUP); + dc_param_set (msg->param, DC_PARAM_CMD_ARG ,contact->addr); + dc_param_set_int(msg->param, DC_PARAM_CMD_ARG2,flags); // combine the Secure-Join protocol headers with the Chat-Group-Member-Added header + msg->id = dc_send_msg_object(context, chat_id, msg); + context->cb(context, DC_EVENT_MSGS_CHANGED, chat_id, msg->id); } - context->m_cb(context, DC_EVENT_CHAT_MODIFIED, chat_id, 0); + context->cb(context, DC_EVENT_CHAT_MODIFIED, chat_id, 0); success = 1; @@ -2746,7 +2746,7 @@ int dc_remove_contact_from_chat(dc_context_t* context, uint32_t chat_id, uint32_ dc_msg_t* msg = dc_msg_new(); char* q3 = NULL; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || chat_id <= DC_CHAT_ID_LAST_SPECIAL || (contact_id<=DC_CONTACT_ID_LAST_SPECIAL && contact_id!=DC_CONTACT_ID_SELF) ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || chat_id <= DC_CHAT_ID_LAST_SPECIAL || (contact_id<=DC_CONTACT_ID_LAST_SPECIAL && contact_id!=DC_CONTACT_ID_SELF) ) { goto cleanup; /* we do not check if "contact_id" exists but just delete all records with the id from chats_contacts */ } /* this allows to delete pending references to deleted contacts. Of course, this should _not_ happen. */ @@ -2766,27 +2766,27 @@ int dc_remove_contact_from_chat(dc_context_t* context, uint32_t chat_id, uint32_ { if( DO_SEND_STATUS_MAILS ) { - msg->m_type = DC_MSG_TEXT; - if( contact->m_id == DC_CONTACT_ID_SELF ) { - dc_set_group_explicitly_left(context, chat->m_grpid); - msg->m_text = dc_stock_str(context, DC_STR_MSGGROUPLEFT); + msg->type = DC_MSG_TEXT; + if( contact->id == DC_CONTACT_ID_SELF ) { + dc_set_group_explicitly_left(context, chat->grpid); + msg->text = dc_stock_str(context, DC_STR_MSGGROUPLEFT); } else { - msg->m_text = dc_stock_str_repl_string(context, DC_STR_MSGDELMEMBER, (contact->m_authname&&contact->m_authname[0])? contact->m_authname : contact->m_addr); + msg->text = dc_stock_str_repl_string(context, DC_STR_MSGDELMEMBER, (contact->authname&&contact->authname[0])? contact->authname : contact->addr); } - dc_param_set_int(msg->m_param, DC_PARAM_CMD, DC_CMD_MEMBER_REMOVED_FROM_GROUP); - dc_param_set (msg->m_param, DC_PARAM_CMD_ARG, contact->m_addr); - msg->m_id = dc_send_msg_object(context, chat_id, msg); - context->m_cb(context, DC_EVENT_MSGS_CHANGED, chat_id, msg->m_id); + dc_param_set_int(msg->param, DC_PARAM_CMD, DC_CMD_MEMBER_REMOVED_FROM_GROUP); + dc_param_set (msg->param, DC_PARAM_CMD_ARG, contact->addr); + msg->id = dc_send_msg_object(context, chat_id, msg); + context->cb(context, DC_EVENT_MSGS_CHANGED, chat_id, msg->id); } } q3 = sqlite3_mprintf("DELETE FROM chats_contacts WHERE chat_id=%i AND contact_id=%i;", chat_id, contact_id); - if( !dc_sqlite3_execute(context->m_sql, q3) ) { + if( !dc_sqlite3_execute(context->sql, q3) ) { goto cleanup; } - context->m_cb(context, DC_EVENT_CHAT_MODIFIED, chat_id, 0); + context->cb(context, DC_EVENT_CHAT_MODIFIED, chat_id, 0); success = 1; @@ -2809,12 +2809,12 @@ int dc_real_contact_exists(dc_context_t* context, uint32_t contact_id) sqlite3_stmt* stmt = NULL; int ret = 0; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || context->m_sql->m_cobj==NULL + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || context->sql->cobj==NULL || contact_id <= DC_CONTACT_ID_LAST_SPECIAL ) { goto cleanup; } - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT id FROM contacts WHERE id=?;"); sqlite3_bind_int(stmt, 1, contact_id); @@ -2833,11 +2833,11 @@ size_t dc_get_real_contact_cnt(dc_context_t* context) size_t ret = 0; sqlite3_stmt* stmt = NULL; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || context->m_sql->m_cobj==NULL ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || context->sql->cobj==NULL ) { goto cleanup; } - stmt = dc_sqlite3_prepare(context->m_sql, "SELECT COUNT(*) FROM contacts WHERE id>?;"); + stmt = dc_sqlite3_prepare(context->sql, "SELECT COUNT(*) FROM contacts WHERE id>?;"); sqlite3_bind_int(stmt, 1, DC_CONTACT_ID_LAST_SPECIAL); if( sqlite3_step(stmt) != SQLITE_ROW ) { goto cleanup; @@ -2873,7 +2873,7 @@ uint32_t dc_add_or_lookup_contact( dc_context_t* context, *sth_modified = 0; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || addr__ == NULL || origin <= 0 ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || addr__ == NULL || origin <= 0 ) { goto cleanup; } @@ -2889,7 +2889,7 @@ uint32_t dc_add_or_lookup_contact( dc_context_t* context, /* insert email-address to database or modify the record with the given email-address. we treat all email-addresses case-insensitive. */ - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT id, name, addr, origin, authname FROM contacts WHERE addr=? COLLATE NOCASE;"); sqlite3_bind_text(stmt, 1, (const char*)addr, -1, SQLITE_STATIC); if( sqlite3_step(stmt) == SQLITE_ROW ) @@ -2926,7 +2926,7 @@ uint32_t dc_add_or_lookup_contact( dc_context_t* context, if( update_name || update_authname || update_addr || origin>row_origin ) { - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "UPDATE contacts SET name=?, addr=?, origin=?, authname=? WHERE id=?;"); sqlite3_bind_text(stmt, 1, update_name? name : row_name, -1, SQLITE_STATIC); sqlite3_bind_text(stmt, 2, update_addr? addr : row_addr, -1, SQLITE_STATIC); @@ -2941,7 +2941,7 @@ uint32_t dc_add_or_lookup_contact( dc_context_t* context, { /* Update the contact name also if it is used as a group name. This is one of the few duplicated data, however, getting the chat list is easier this way.*/ - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "UPDATE chats SET name=? WHERE type=? AND id IN(SELECT chat_id FROM chats_contacts WHERE contact_id=?);"); sqlite3_bind_text(stmt, 1, name, -1, SQLITE_STATIC); sqlite3_bind_int (stmt, 2, DC_CHAT_TYPE_SINGLE); @@ -2957,14 +2957,14 @@ uint32_t dc_add_or_lookup_contact( dc_context_t* context, sqlite3_finalize (stmt); stmt = NULL; - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "INSERT INTO contacts (name, addr, origin) VALUES(?, ?, ?);"); sqlite3_bind_text(stmt, 1, name? name : "", -1, SQLITE_STATIC); /* avoid NULL-fields in column */ sqlite3_bind_text(stmt, 2, addr, -1, SQLITE_STATIC); sqlite3_bind_int (stmt, 3, origin); if( sqlite3_step(stmt) == SQLITE_DONE ) { - row_id = dc_sqlite3_get_rowid(context->m_sql, "contacts", "addr", addr); + row_id = dc_sqlite3_get_rowid(context->sql, "contacts", "addr", addr); *sth_modified = CONTACT_CREATED; } else @@ -2985,11 +2985,11 @@ cleanup: void dc_scaleup_contact_origin(dc_context_t* context, uint32_t contact_id, int origin) { - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC ) { return; } - sqlite3_stmt* stmt = dc_sqlite3_prepare(context->m_sql, + sqlite3_stmt* stmt = dc_sqlite3_prepare(context->sql, "UPDATE contacts SET origin=? WHERE id=? AND originm_sql, contact_id) ) { - if( contact->m_blocked ) { + if( dc_contact_load_from_db(contact, context->sql, contact_id) ) { + if( contact->blocked ) { is_blocked = 1; } } @@ -3023,16 +3023,16 @@ int dc_get_contact_origin(dc_context_t* context, uint32_t contact_id, int* ret_b *ret_blocked = 0; - if( !dc_contact_load_from_db(contact, context->m_sql, contact_id) ) { /* we could optimize this by loading only the needed fields */ + if( !dc_contact_load_from_db(contact, context->sql, contact_id) ) { /* we could optimize this by loading only the needed fields */ goto cleanup; } - if( contact->m_blocked ) { + if( contact->blocked ) { *ret_blocked = 1; goto cleanup; } - ret = contact->m_origin; + ret = contact->origin; cleanup: dc_contact_unref(contact); @@ -3066,7 +3066,7 @@ uint32_t dc_create_contact(dc_context_t* context, const char* name, const char* int sth_modified = 0; int blocked = 0; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || addr == NULL || addr[0]==0 ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || addr == NULL || addr[0]==0 ) { goto cleanup; } @@ -3074,7 +3074,7 @@ uint32_t dc_create_contact(dc_context_t* context, const char* name, const char* blocked = dc_is_contact_blocked(context, contact_id); - context->m_cb(context, DC_EVENT_CONTACTS_CHANGED, sth_modified==CONTACT_CREATED? contact_id : 0, 0); + context->cb(context, DC_EVENT_CONTACTS_CHANGED, sth_modified==CONTACT_CREATED? contact_id : 0, 0); if( blocked ) { dc_block_contact(context, contact_id, 0); @@ -3110,7 +3110,7 @@ int dc_add_address_book(dc_context_t* context, const char* adr_book) /* format: size_t i, iCnt; int sth_modified, modify_cnt = 0; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || adr_book == NULL ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || adr_book == NULL ) { goto cleanup; } @@ -3118,7 +3118,7 @@ int dc_add_address_book(dc_context_t* context, const char* adr_book) /* format: goto cleanup; } - dc_sqlite3_begin_transaction(context->m_sql); + dc_sqlite3_begin_transaction(context->sql); iCnt = carray_count(lines); for( i = 0; i+1 < iCnt; i += 2 ) { @@ -3131,7 +3131,7 @@ int dc_add_address_book(dc_context_t* context, const char* adr_book) /* format: } } - dc_sqlite3_commit(context->m_sql); + dc_sqlite3_commit(context->sql); cleanup: dc_free_splitted_lines(lines); @@ -3166,18 +3166,18 @@ dc_array_t* dc_get_contacts(dc_context_t* context, uint32_t listflags, const cha char* s3strLikeCmd = NULL; sqlite3_stmt* stmt = NULL; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC ) { goto cleanup; } - self_addr = dc_sqlite3_get_config(context->m_sql, "configured_addr", ""); /* we add DC_CONTACT_ID_SELF explicitly; so avoid doubles if the address is present as a normal entry for some case */ + self_addr = dc_sqlite3_get_config(context->sql, "configured_addr", ""); /* we add DC_CONTACT_ID_SELF explicitly; so avoid doubles if the address is present as a normal entry for some case */ if( (listflags&DC_GCL_VERIFIED_ONLY) || query ) { if( (s3strLikeCmd=sqlite3_mprintf("%%%s%%", query? query : ""))==NULL ) { goto cleanup; } - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT c.id FROM contacts c" " LEFT JOIN acpeerstates ps ON c.addr=ps.addr " " WHERE c.addr!=? AND c.id>" DC_STRINGIFY(DC_CONTACT_ID_LAST_SPECIAL) " AND c.origin>=" DC_STRINGIFY(DC_ORIGIN_MIN_CONTACT_LIST) " AND c.blocked=0 AND (c.name LIKE ? OR c.addr LIKE ?)" /* see comments in dc_search_msgs() about the LIKE operator */ @@ -3188,7 +3188,7 @@ dc_array_t* dc_get_contacts(dc_context_t* context, uint32_t listflags, const cha sqlite3_bind_text(stmt, 3, s3strLikeCmd, -1, SQLITE_STATIC); sqlite3_bind_int (stmt, 4, (listflags&DC_GCL_VERIFIED_ONLY)? 0/*force checking for verified_key*/ : 1/*force statement being always true*/); - self_name = dc_sqlite3_get_config(context->m_sql, "displayname", ""); + self_name = dc_sqlite3_get_config(context->sql, "displayname", ""); self_name2 = dc_stock_str(context, DC_STR_SELF); if( query==NULL || dc_str_contains(self_addr, query) || dc_str_contains(self_name, query) || dc_str_contains(self_name2, query) ) { add_self = 1; @@ -3196,7 +3196,7 @@ dc_array_t* dc_get_contacts(dc_context_t* context, uint32_t listflags, const cha } else { - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT id FROM contacts" " WHERE addr!=? AND id>" DC_STRINGIFY(DC_CONTACT_ID_LAST_SPECIAL) " AND origin>=" DC_STRINGIFY(DC_ORIGIN_MIN_CONTACT_LIST) " AND blocked=0" " ORDER BY LOWER(name||addr),id;"); @@ -3237,11 +3237,11 @@ dc_array_t* dc_get_blocked_contacts(dc_context_t* context) dc_array_t* ret = dc_array_new(context, 100); sqlite3_stmt* stmt = NULL; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC ) { goto cleanup; } - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT id FROM contacts" " WHERE id>? AND blocked!=0" " ORDER BY LOWER(name||addr),id;"); @@ -3268,11 +3268,11 @@ int dc_get_blocked_count(dc_context_t* context) int ret = 0; sqlite3_stmt* stmt = NULL; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC ) { goto cleanup; } - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT COUNT(*) FROM contacts" " WHERE id>? AND blocked!=0"); sqlite3_bind_int(stmt, 1, DC_CONTACT_ID_LAST_SPECIAL); @@ -3304,7 +3304,7 @@ dc_contact_t* dc_get_contact(dc_context_t* context, uint32_t contact_id) { dc_contact_t* ret = dc_contact_new(context); - if( !dc_contact_load_from_db(ret, context->m_sql, contact_id) ) { + if( !dc_contact_load_from_db(ret, context->sql, contact_id) ) { dc_contact_unref(ret); ret = NULL; } @@ -3325,11 +3325,11 @@ dc_contact_t* dc_get_contact(dc_context_t* context, uint32_t contact_id) */ void dc_marknoticed_contact(dc_context_t* context, uint32_t contact_id) { - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC ) { return; } - sqlite3_stmt* stmt = dc_sqlite3_prepare(context->m_sql, + sqlite3_stmt* stmt = dc_sqlite3_prepare(context->sql, "UPDATE msgs SET state=" DC_STRINGIFY(DC_STATE_IN_NOTICED) " WHERE from_id=? AND state=" DC_STRINGIFY(DC_STATE_IN_FRESH) ";"); sqlite3_bind_int(stmt, 1, contact_id); sqlite3_step(stmt); @@ -3341,11 +3341,11 @@ void dc_block_chat(dc_context_t* context, uint32_t chat_id, int new_blocking) { sqlite3_stmt* stmt = NULL; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC ) { return; } - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "UPDATE chats SET blocked=? WHERE id=?;"); sqlite3_bind_int(stmt, 1, new_blocking); sqlite3_bind_int(stmt, 2, chat_id); @@ -3376,14 +3376,14 @@ void dc_block_contact(dc_context_t* context, uint32_t contact_id, int new_blocki dc_contact_t* contact = dc_contact_new(context); sqlite3_stmt* stmt = NULL; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || contact_id <= DC_CONTACT_ID_LAST_SPECIAL ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || contact_id <= DC_CONTACT_ID_LAST_SPECIAL ) { goto cleanup; } - if( dc_contact_load_from_db(contact, context->m_sql, contact_id) - && contact->m_blocked != new_blocking ) + if( dc_contact_load_from_db(contact, context->sql, contact_id) + && contact->blocked != new_blocking ) { - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "UPDATE contacts SET blocked=? WHERE id=?;"); sqlite3_bind_int(stmt, 1, new_blocking); sqlite3_bind_int(stmt, 2, contact_id); @@ -3397,7 +3397,7 @@ void dc_block_contact(dc_context_t* context, uint32_t contact_id, int new_blocki (Maybe, beside normal chats (type=100) we should also block group chats with only this user. However, I'm not sure about this point; it may be confusing if the user wants to add other people; this would result in recreating the same group...) */ - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "UPDATE chats SET blocked=? WHERE type=? AND id IN (SELECT chat_id FROM chats_contacts WHERE contact_id=?);"); sqlite3_bind_int(stmt, 1, new_blocking); sqlite3_bind_int(stmt, 2, DC_CHAT_TYPE_SINGLE); @@ -3413,7 +3413,7 @@ void dc_block_contact(dc_context_t* context, uint32_t contact_id, int new_blocki } if( send_event ) { - context->m_cb(context, DC_EVENT_CONTACTS_CHANGED, 0, 0); + context->cb(context, DC_EVENT_CONTACTS_CHANGED, 0, 0); } cleanup: @@ -3463,30 +3463,30 @@ char* dc_get_contact_encrinfo(dc_context_t* context, uint32_t contact_id) char* fingerprint_other_unverified = NULL; char* p = NULL; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC ) { goto cleanup; } dc_strbuilder_t ret; dc_strbuilder_init(&ret, 0); - if( !dc_contact_load_from_db(contact, context->m_sql, contact_id) ) { + if( !dc_contact_load_from_db(contact, context->sql, contact_id) ) { goto cleanup; } - dc_apeerstate_load_by_addr(peerstate, context->m_sql, contact->m_addr); - dc_loginparam_read(loginparam, context->m_sql, "configured_"); + dc_apeerstate_load_by_addr(peerstate, context->sql, contact->addr); + dc_loginparam_read(loginparam, context->sql, "configured_"); - dc_key_load_self_public(self_key, loginparam->m_addr, context->m_sql); + dc_key_load_self_public(self_key, loginparam->addr, context->sql); if( dc_apeerstate_peek_key(peerstate, DC_NOT_VERIFIED) ) { // E2E available :) - p = dc_stock_str(context, peerstate->m_prefer_encrypt == DC_PE_MUTUAL? DC_STR_E2E_PREFERRED : DC_STR_E2E_AVAILABLE); dc_strbuilder_cat(&ret, p); free(p); + p = dc_stock_str(context, peerstate->prefer_encrypt == DC_PE_MUTUAL? DC_STR_E2E_PREFERRED : DC_STR_E2E_AVAILABLE); dc_strbuilder_cat(&ret, p); free(p); - if( self_key->m_binary == NULL ) { - dc_pgp_rand_seed(context, peerstate->m_addr, strlen(peerstate->m_addr) /*just some random data*/); + if( self_key->binary == NULL ) { + dc_pgp_rand_seed(context, peerstate->addr, strlen(peerstate->addr) /*just some random data*/); dc_ensure_secret_key_exists(context); - dc_key_load_self_public(self_key, loginparam->m_addr, context->m_sql); + dc_key_load_self_public(self_key, loginparam->addr, context->sql); } dc_strbuilder_cat(&ret, " "); @@ -3497,20 +3497,20 @@ char* dc_get_contact_encrinfo(dc_context_t* context, uint32_t contact_id) fingerprint_other_verified = dc_key_get_formatted_fingerprint(dc_apeerstate_peek_key(peerstate, DC_BIDIRECT_VERIFIED)); fingerprint_other_unverified = dc_key_get_formatted_fingerprint(dc_apeerstate_peek_key(peerstate, DC_NOT_VERIFIED)); - if( strcmp(loginparam->m_addr, peerstate->m_addr)<0 ) { - cat_fingerprint(&ret, loginparam->m_addr, fingerprint_self, NULL); - cat_fingerprint(&ret, peerstate->m_addr, fingerprint_other_verified, fingerprint_other_unverified); + if( strcmp(loginparam->addr, peerstate->addr)<0 ) { + cat_fingerprint(&ret, loginparam->addr, fingerprint_self, NULL); + cat_fingerprint(&ret, peerstate->addr, fingerprint_other_verified, fingerprint_other_unverified); } else { - cat_fingerprint(&ret, peerstate->m_addr, fingerprint_other_verified, fingerprint_other_unverified); - cat_fingerprint(&ret, loginparam->m_addr, fingerprint_self, NULL); + cat_fingerprint(&ret, peerstate->addr, fingerprint_other_verified, fingerprint_other_unverified); + cat_fingerprint(&ret, loginparam->addr, fingerprint_self, NULL); } } else { // No E2E available - if( !(loginparam->m_server_flags&DC_LP_IMAP_SOCKET_PLAIN) - && !(loginparam->m_server_flags&DC_LP_SMTP_SOCKET_PLAIN) ) + if( !(loginparam->server_flags&DC_LP_IMAP_SOCKET_PLAIN) + && !(loginparam->server_flags&DC_LP_SMTP_SOCKET_PLAIN) ) { p = dc_stock_str(context, DC_STR_ENCR_TRANSP); dc_strbuilder_cat(&ret, p); free(p); } @@ -3528,7 +3528,7 @@ cleanup: free(fingerprint_self); free(fingerprint_other_verified); free(fingerprint_other_unverified); - return ret.m_buf; + return ret.buf; } @@ -3548,13 +3548,13 @@ int dc_delete_contact(dc_context_t* context, uint32_t contact_id) int success = 0; sqlite3_stmt* stmt = NULL; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || contact_id <= DC_CONTACT_ID_LAST_SPECIAL ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || contact_id <= DC_CONTACT_ID_LAST_SPECIAL ) { goto cleanup; } /* we can only delete contacts that are not in use anywhere; this function is mainly for the user who has just created an contact manually and wants to delete it a moment later */ - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT COUNT(*) FROM chats_contacts WHERE contact_id=?;"); sqlite3_bind_int(stmt, 1, contact_id); if( sqlite3_step(stmt) != SQLITE_ROW || sqlite3_column_int(stmt, 0) >= 1 ) { @@ -3563,7 +3563,7 @@ int dc_delete_contact(dc_context_t* context, uint32_t contact_id) sqlite3_finalize(stmt); stmt = NULL; - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT COUNT(*) FROM msgs WHERE from_id=? OR to_id=?;"); sqlite3_bind_int(stmt, 1, contact_id); sqlite3_bind_int(stmt, 2, contact_id); @@ -3573,14 +3573,14 @@ int dc_delete_contact(dc_context_t* context, uint32_t contact_id) sqlite3_finalize(stmt); stmt = NULL; - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "DELETE FROM contacts WHERE id=?;"); sqlite3_bind_int(stmt, 1, contact_id); if( sqlite3_step(stmt) != SQLITE_DONE ) { goto cleanup; } - context->m_cb(context, DC_EVENT_CONTACTS_CHANGED, 0, 0); + context->cb(context, DC_EVENT_CONTACTS_CHANGED, 0, 0); success = 1; @@ -3595,9 +3595,9 @@ int dc_contact_addr_equals(dc_context_t* context, uint32_t contact_id, const cha int addr_are_equal = 0; if( other_addr ) { dc_contact_t* contact = dc_contact_new(context); - if( dc_contact_load_from_db(contact, context->m_sql, contact_id) ) { - if( contact->m_addr ) { - if( strcasecmp(contact->m_addr, other_addr)==0 ) { + if( dc_contact_load_from_db(contact, context->sql, contact_id) ) { + if( contact->addr ) { + if( strcasecmp(contact->addr, other_addr)==0 ) { addr_are_equal = 1; } } @@ -3615,7 +3615,7 @@ int dc_contact_addr_equals(dc_context_t* context, uint32_t contact_id, const cha void dc_update_msg_chat_id(dc_context_t* context, uint32_t msg_id, uint32_t chat_id) { - sqlite3_stmt* stmt = dc_sqlite3_prepare(context->m_sql, + sqlite3_stmt* stmt = dc_sqlite3_prepare(context->sql, "UPDATE msgs SET chat_id=? WHERE id=?;"); sqlite3_bind_int(stmt, 1, chat_id); sqlite3_bind_int(stmt, 2, msg_id); @@ -3626,7 +3626,7 @@ void dc_update_msg_chat_id(dc_context_t* context, uint32_t msg_id, uint32_t chat void dc_update_msg_state(dc_context_t* context, uint32_t msg_id, int state) { - sqlite3_stmt* stmt = dc_sqlite3_prepare(context->m_sql, + sqlite3_stmt* stmt = dc_sqlite3_prepare(context->sql, "UPDATE msgs SET state=? WHERE id=?;"); sqlite3_bind_int(stmt, 1, state); sqlite3_bind_int(stmt, 2, msg_id); @@ -3640,11 +3640,11 @@ size_t dc_get_real_msg_cnt(dc_context_t* context) sqlite3_stmt* stmt = NULL; size_t ret = 0; - if( context->m_sql->m_cobj==NULL ) { + if( context->sql->cobj==NULL ) { goto cleanup; } - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT COUNT(*) " " FROM msgs m " " LEFT JOIN chats c ON c.id=m.chat_id " @@ -3652,7 +3652,7 @@ size_t dc_get_real_msg_cnt(dc_context_t* context) " AND m.chat_id>" DC_STRINGIFY(DC_CHAT_ID_LAST_SPECIAL) " AND c.blocked=0;"); if( sqlite3_step(stmt) != SQLITE_ROW ) { - dc_sqlite3_log_error(context->m_sql, "dc_get_real_msg_cnt() failed."); + dc_sqlite3_log_error(context->sql, "dc_get_real_msg_cnt() failed."); goto cleanup; } @@ -3669,11 +3669,11 @@ size_t dc_get_deaddrop_msg_cnt(dc_context_t* context) sqlite3_stmt* stmt = NULL; size_t ret = 0; - if( context==NULL || context->m_magic != DC_CONTEXT_MAGIC || context->m_sql->m_cobj==NULL ) { + if( context==NULL || context->magic != DC_CONTEXT_MAGIC || context->sql->cobj==NULL ) { goto cleanup; } - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT COUNT(*) FROM msgs m LEFT JOIN chats c ON c.id=m.chat_id WHERE c.blocked=2;"); if( sqlite3_step(stmt) != SQLITE_ROW ) { goto cleanup; @@ -3693,11 +3693,11 @@ int dc_rfc724_mid_cnt(dc_context_t* context, const char* rfc724_mid) int ret = 0; sqlite3_stmt* stmt = NULL; - if( context==NULL || context->m_magic != DC_CONTEXT_MAGIC || context->m_sql->m_cobj==NULL ) { + if( context==NULL || context->magic != DC_CONTEXT_MAGIC || context->sql->cobj==NULL ) { goto cleanup; } - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT COUNT(*) FROM msgs WHERE rfc724_mid=?;"); sqlite3_bind_text(stmt, 1, rfc724_mid, -1, SQLITE_STATIC); if( sqlite3_step(stmt) != SQLITE_ROW ) { @@ -3717,7 +3717,7 @@ so, we should even keep unuseful messages in the database (we can leave the othe uint32_t dc_rfc724_mid_exists__(dc_context_t* context, const char* rfc724_mid, char** ret_server_folder, uint32_t* ret_server_uid) { uint32_t ret = 0; - sqlite3_stmt* stmt = dc_sqlite3_prepare(context->m_sql, + sqlite3_stmt* stmt = dc_sqlite3_prepare(context->sql, "SELECT server_folder, server_uid, id FROM msgs WHERE rfc724_mid=?;"); sqlite3_bind_text(stmt, 1, rfc724_mid, -1, SQLITE_STATIC); if( sqlite3_step(stmt) != SQLITE_ROW ) { @@ -3738,7 +3738,7 @@ cleanup: void dc_update_server_uid(dc_context_t* context, const char* rfc724_mid, const char* server_folder, uint32_t server_uid) { - sqlite3_stmt* stmt = dc_sqlite3_prepare(context->m_sql, + sqlite3_stmt* stmt = dc_sqlite3_prepare(context->sql, "UPDATE msgs SET server_folder=?, server_uid=? WHERE rfc724_mid=?;"); /* we update by "rfc724_mid" instead of "id" as there may be several db-entries refering to the same "rfc724_mid" */ sqlite3_bind_text(stmt, 1, server_folder, -1, SQLITE_STATIC); sqlite3_bind_int (stmt, 2, server_uid); @@ -3763,7 +3763,7 @@ dc_msg_t* dc_get_msg(dc_context_t* context, uint32_t msg_id) int success = 0; dc_msg_t* obj = dc_msg_new(); - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC ) { goto cleanup; } @@ -3810,14 +3810,14 @@ char* dc_get_msg_info(dc_context_t* context, uint32_t msg_id) char *rawtxt = NULL, *p; dc_strbuilder_init(&ret, 0); - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC ) { goto cleanup; } dc_msg_load_from_db(msg, context, msg_id); - dc_contact_load_from_db(contact_from, context->m_sql, msg->m_from_id); + dc_contact_load_from_db(contact_from, context->sql, msg->from_id); - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT txt_raw FROM msgs WHERE id=?;"); sqlite3_bind_int(stmt, 1, msg_id); if( sqlite3_step(stmt) != SQLITE_ROW ) { @@ -3847,18 +3847,18 @@ char* dc_get_msg_info(dc_context_t* context, uint32_t msg_id) p = dc_timestamp_to_str(dc_msg_get_timestamp(msg)); dc_strbuilder_cat(&ret, p); free(p); dc_strbuilder_cat(&ret, "\n"); - if( msg->m_from_id != DC_CONTACT_ID_SELF ) { + if( msg->from_id != DC_CONTACT_ID_SELF ) { dc_strbuilder_cat(&ret, "Received: "); - p = dc_timestamp_to_str(msg->m_timestamp_rcvd? msg->m_timestamp_rcvd : msg->m_timestamp); dc_strbuilder_cat(&ret, p); free(p); + p = dc_timestamp_to_str(msg->timestamp_rcvd? msg->timestamp_rcvd : msg->timestamp); dc_strbuilder_cat(&ret, p); free(p); dc_strbuilder_cat(&ret, "\n"); } - if( msg->m_from_id == DC_CONTACT_ID_DEVICE || msg->m_to_id == DC_CONTACT_ID_DEVICE ) { + if( msg->from_id == DC_CONTACT_ID_DEVICE || msg->to_id == DC_CONTACT_ID_DEVICE ) { goto cleanup; // device-internal message, no further details needed } /* add mdn's time and readers */ - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT contact_id, timestamp_sent FROM msgs_mdns WHERE msg_id=?;"); sqlite3_bind_int (stmt, 1, msg_id); while( sqlite3_step(stmt) == SQLITE_ROW ) { @@ -3867,7 +3867,7 @@ char* dc_get_msg_info(dc_context_t* context, uint32_t msg_id) dc_strbuilder_cat(&ret, " by "); dc_contact_t* contact = dc_contact_new(context); - dc_contact_load_from_db(contact, context->m_sql, sqlite3_column_int64(stmt, 0)); + dc_contact_load_from_db(contact, context->sql, sqlite3_column_int64(stmt, 0)); p = dc_contact_get_display_name(contact); dc_strbuilder_cat(&ret, p); free(p); dc_contact_unref(contact); dc_strbuilder_cat(&ret, "\n"); @@ -3877,7 +3877,7 @@ char* dc_get_msg_info(dc_context_t* context, uint32_t msg_id) /* add state */ p = NULL; - switch( msg->m_state ) { + switch( msg->state ) { case DC_STATE_IN_FRESH: p = dc_strdup("Fresh"); break; case DC_STATE_IN_NOTICED: p = dc_strdup("Noticed"); break; case DC_STATE_IN_SEEN: p = dc_strdup("Seen"); break; @@ -3885,19 +3885,19 @@ char* dc_get_msg_info(dc_context_t* context, uint32_t msg_id) case DC_STATE_OUT_ERROR: p = dc_strdup("Error"); break; case DC_STATE_OUT_MDN_RCVD: p = dc_strdup("Read"); break; case DC_STATE_OUT_PENDING: p = dc_strdup("Pending"); break; - default: p = dc_mprintf("%i", msg->m_state); break; + default: p = dc_mprintf("%i", msg->state); break; } dc_strbuilder_catf(&ret, "State: %s", p); free(p); p = NULL; int e2ee_errors; - if( (e2ee_errors=dc_param_get_int(msg->m_param, DC_PARAM_ERRONEOUS_E2EE, 0)) ) { + if( (e2ee_errors=dc_param_get_int(msg->param, DC_PARAM_ERRONEOUS_E2EE, 0)) ) { if( e2ee_errors&DC_E2EE_NO_VALID_SIGNATURE ) { p = dc_strdup("Encrypted, no valid signature"); } } - else if( dc_param_get_int(msg->m_param, DC_PARAM_GUARANTEE_E2EE, 0) ) { + else if( dc_param_get_int(msg->param, DC_PARAM_GUARANTEE_E2EE, 0) ) { p = dc_strdup("Encrypted"); } @@ -3915,32 +3915,32 @@ char* dc_get_msg_info(dc_context_t* context, uint32_t msg_id) } /* add file info */ - char* file = dc_param_get(msg->m_param, DC_PARAM_FILE, NULL); + char* file = dc_param_get(msg->param, DC_PARAM_FILE, NULL); if( file ) { p = dc_mprintf("\nFile: %s, %i bytes\n", file, (int)dc_get_filebytes(file)); dc_strbuilder_cat(&ret, p); free(p); } - if( msg->m_type != DC_MSG_TEXT ) { + if( msg->type != DC_MSG_TEXT ) { p = NULL; - switch( msg->m_type ) { + switch( msg->type ) { case DC_MSG_AUDIO: p = dc_strdup("Audio"); break; case DC_MSG_FILE: p = dc_strdup("File"); break; case DC_MSG_GIF: p = dc_strdup("GIF"); break; case DC_MSG_IMAGE: p = dc_strdup("Image"); break; case DC_MSG_VIDEO: p = dc_strdup("Video"); break; case DC_MSG_VOICE: p = dc_strdup("Voice"); break; - default: p = dc_mprintf("%i", msg->m_type); break; + default: p = dc_mprintf("%i", msg->type); break; } dc_strbuilder_catf(&ret, "Type: %s\n", p); free(p); } - int w = dc_param_get_int(msg->m_param, DC_PARAM_WIDTH, 0), h = dc_param_get_int(msg->m_param, DC_PARAM_HEIGHT, 0); + int w = dc_param_get_int(msg->param, DC_PARAM_WIDTH, 0), h = dc_param_get_int(msg->param, DC_PARAM_HEIGHT, 0); if( w != 0 || h != 0 ) { p = dc_mprintf("Dimension: %i x %i\n", w, h); dc_strbuilder_cat(&ret, p); free(p); } - int duration = dc_param_get_int(msg->m_param, DC_PARAM_DURATION, 0); + int duration = dc_param_get_int(msg->param, DC_PARAM_DURATION, 0); if( duration != 0 ) { p = dc_mprintf("Duration: %i ms\n", duration); dc_strbuilder_cat(&ret, p); free(p); } @@ -3957,12 +3957,12 @@ char* dc_get_msg_info(dc_context_t* context, uint32_t msg_id) dc_strbuilder_cat(&ret, ""); #endif - if( msg->m_rfc724_mid && msg->m_rfc724_mid[0] ) { - dc_strbuilder_catf(&ret, "\nMessage-ID: %s", msg->m_rfc724_mid); + if( msg->rfc724_mid && msg->rfc724_mid[0] ) { + dc_strbuilder_catf(&ret, "\nMessage-ID: %s", msg->rfc724_mid); } - if( msg->m_server_folder && msg->m_server_folder[0] ) { - dc_strbuilder_catf(&ret, "\nLast seen as: %s/%i", msg->m_server_folder, (int)msg->m_server_uid); + if( msg->server_folder && msg->server_folder[0] ) { + dc_strbuilder_catf(&ret, "\nLast seen as: %s/%i", msg->server_folder, (int)msg->server_uid); } #ifdef __ANDROID__ @@ -3974,7 +3974,7 @@ cleanup: dc_msg_unref(msg); dc_contact_unref(contact_from); free(rawtxt); - return ret.m_buf; + return ret.buf; } @@ -3999,16 +3999,16 @@ void dc_forward_msgs(dc_context_t* context, const uint32_t* msg_ids, int msg_cnt sqlite3_stmt* stmt = NULL; time_t curr_timestamp; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || msg_ids==NULL || msg_cnt <= 0 || chat_id <= DC_CHAT_ID_LAST_SPECIAL ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || msg_ids==NULL || msg_cnt <= 0 || chat_id <= DC_CHAT_ID_LAST_SPECIAL ) { goto cleanup; } - dc_sqlite3_begin_transaction(context->m_sql); + dc_sqlite3_begin_transaction(context->sql); transaction_pending = 1; dc_unarchive_chat(context, chat_id); - context->m_smtp->m_log_connect_errors = 1; + context->smtp->log_connect_errors = 1; if( !dc_chat_load_from_db(chat, chat_id) ) { goto cleanup; @@ -4018,7 +4018,7 @@ void dc_forward_msgs(dc_context_t* context, const uint32_t* msg_ids, int msg_cnt idsstr = dc_arr_to_string(msg_ids, msg_cnt); q3 = sqlite3_mprintf("SELECT id FROM msgs WHERE id IN(%s) ORDER BY timestamp,id", idsstr); - stmt = dc_sqlite3_prepare(context->m_sql, q3); + stmt = dc_sqlite3_prepare(context->sql, q3); while( sqlite3_step(stmt)==SQLITE_ROW ) { int src_msg_id = sqlite3_column_int(stmt, 0); @@ -4026,24 +4026,24 @@ void dc_forward_msgs(dc_context_t* context, const uint32_t* msg_ids, int msg_cnt goto cleanup; } - dc_param_set_int(msg->m_param, DC_PARAM_FORWARDED, 1); - dc_param_set (msg->m_param, DC_PARAM_GUARANTEE_E2EE, NULL); - dc_param_set (msg->m_param, DC_PARAM_FORCE_PLAINTEXT, NULL); + dc_param_set_int(msg->param, DC_PARAM_FORWARDED, 1); + dc_param_set (msg->param, DC_PARAM_GUARANTEE_E2EE, NULL); + dc_param_set (msg->param, DC_PARAM_FORCE_PLAINTEXT, NULL); uint32_t new_msg_id = dc_send_msg_raw(context, chat, msg, curr_timestamp++); carray_add(created_db_entries, (void*)(uintptr_t)chat_id, NULL); carray_add(created_db_entries, (void*)(uintptr_t)new_msg_id, NULL); } - dc_sqlite3_commit(context->m_sql); + dc_sqlite3_commit(context->sql); transaction_pending = 0; cleanup: - if( transaction_pending ) { dc_sqlite3_rollback(context->m_sql); } + if( transaction_pending ) { dc_sqlite3_rollback(context->sql); } if( created_db_entries ) { size_t i, icnt = carray_count(created_db_entries); for( i = 0; i < icnt; i += 2 ) { - context->m_cb(context, DC_EVENT_MSGS_CHANGED, (uintptr_t)carray_get(created_db_entries, i), (uintptr_t)carray_get(created_db_entries, i+1)); + context->cb(context, DC_EVENT_MSGS_CHANGED, (uintptr_t)carray_get(created_db_entries, i), (uintptr_t)carray_get(created_db_entries, i+1)); } carray_free(created_db_entries); } @@ -4072,13 +4072,13 @@ void dc_star_msgs(dc_context_t* context, const uint32_t* msg_ids, int msg_cnt, i { int i; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || msg_ids == NULL || msg_cnt <= 0 || (star!=0 && star!=1) ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || msg_ids == NULL || msg_cnt <= 0 || (star!=0 && star!=1) ) { return; } - dc_sqlite3_begin_transaction(context->m_sql); + dc_sqlite3_begin_transaction(context->sql); - sqlite3_stmt* stmt = dc_sqlite3_prepare(context->m_sql, + sqlite3_stmt* stmt = dc_sqlite3_prepare(context->sql, "UPDATE msgs SET starred=? WHERE id=?;"); for( i = 0; i < msg_cnt; i++ ) { @@ -4089,7 +4089,7 @@ void dc_star_msgs(dc_context_t* context, const uint32_t* msg_ids, int msg_cnt, i } sqlite3_finalize(stmt); - dc_sqlite3_commit(context->m_sql); + dc_sqlite3_commit(context->sql); } @@ -4112,11 +4112,11 @@ void dc_delete_msgs(dc_context_t* context, const uint32_t* msg_ids, int msg_cnt) { int i; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || msg_ids == NULL || msg_cnt <= 0 ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || msg_ids == NULL || msg_cnt <= 0 ) { return; } - dc_sqlite3_begin_transaction(context->m_sql); + dc_sqlite3_begin_transaction(context->sql); for( i = 0; i < msg_cnt; i++ ) { @@ -4124,7 +4124,7 @@ void dc_delete_msgs(dc_context_t* context, const uint32_t* msg_ids, int msg_cnt) dc_job_add(context, DC_JOB_DELETE_MSG_ON_IMAP, msg_ids[i], NULL, 0); } - dc_sqlite3_commit(context->m_sql); + dc_sqlite3_commit(context->sql); } @@ -4154,14 +4154,14 @@ void dc_markseen_msgs(dc_context_t* context, const uint32_t* msg_ids, int msg_cn int curr_blocked = 0; sqlite3_stmt* stmt = NULL; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || msg_ids == NULL || msg_cnt <= 0 ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || msg_ids == NULL || msg_cnt <= 0 ) { goto cleanup; } - dc_sqlite3_begin_transaction(context->m_sql); + dc_sqlite3_begin_transaction(context->sql); transaction_pending = 1; - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT m.state, c.blocked " " FROM msgs m " " LEFT JOIN chats c ON c.id=m.chat_id " @@ -4194,16 +4194,16 @@ void dc_markseen_msgs(dc_context_t* context, const uint32_t* msg_ids, int msg_cn } } - dc_sqlite3_commit(context->m_sql); + dc_sqlite3_commit(context->sql); transaction_pending = 0; /* the event is needed eg. to remove the deaddrop from the chatlist */ if( send_event ) { - context->m_cb(context, DC_EVENT_MSGS_CHANGED, 0, 0); + context->cb(context, DC_EVENT_MSGS_CHANGED, 0, 0); } cleanup: - if( transaction_pending ) { dc_sqlite3_rollback(context->m_sql); } + if( transaction_pending ) { dc_sqlite3_rollback(context->sql); } sqlite3_finalize(stmt); } @@ -4214,12 +4214,12 @@ int dc_mdn_from_ext(dc_context_t* context, uint32_t from_id, const char* rfc724_ int read_by_all = 0; sqlite3_stmt* stmt = NULL; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || from_id <= DC_CONTACT_ID_LAST_SPECIAL || rfc724_mid == NULL || ret_chat_id==NULL || ret_msg_id==NULL + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || from_id <= DC_CONTACT_ID_LAST_SPECIAL || rfc724_mid == NULL || ret_chat_id==NULL || ret_msg_id==NULL || *ret_chat_id != 0 || *ret_msg_id != 0 ) { goto cleanup; } - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT m.id, c.id, c.type, m.state FROM msgs m " " LEFT JOIN chats c ON m.chat_id=c.id " " WHERE rfc724_mid=? AND from_id=1 " @@ -4240,7 +4240,7 @@ int dc_mdn_from_ext(dc_context_t* context, uint32_t from_id, const char* rfc724_ } // collect receipt senders, we do this also for normal chats as we may want to show the timestamp - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT contact_id FROM msgs_mdns WHERE msg_id=? AND contact_id=?;"); sqlite3_bind_int(stmt, 1, *ret_msg_id); sqlite3_bind_int(stmt, 2, from_id); @@ -4249,7 +4249,7 @@ int dc_mdn_from_ext(dc_context_t* context, uint32_t from_id, const char* rfc724_ stmt = NULL; if( !mdn_already_in_table ) { - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "INSERT INTO msgs_mdns (msg_id, contact_id, timestamp_sent) VALUES (?, ?, ?);"); sqlite3_bind_int (stmt, 1, *ret_msg_id); sqlite3_bind_int (stmt, 2, from_id); @@ -4267,7 +4267,7 @@ int dc_mdn_from_ext(dc_context_t* context, uint32_t from_id, const char* rfc724_ } // Group chat: get the number of receipt senders - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT COUNT(*) FROM msgs_mdns WHERE msg_id=?;"); sqlite3_bind_int(stmt, 1, *ret_msg_id); if( sqlite3_step(stmt) != SQLITE_ROW ) { diff --git a/src/dc_context.h b/src/dc_context.h index 9f2147ca..8c84eccb 100644 --- a/src/dc_context.h +++ b/src/dc_context.h @@ -60,62 +60,62 @@ struct _dc_context { /** @privatesection */ #define DC_CONTEXT_MAGIC 0x11a11807 - uint32_t m_magic; /**< @private */ + uint32_t magic; /**< @private */ - void* m_userdata; /**< Use data, may be used for any purpose. The same pointer as given to dc_context_new(), may be used by the caller for any purpose. */ + void* userdata; /**< Use data, may be used for any purpose. The same pointer as given to dc_context_new(), may be used by the caller for any purpose. */ - char* m_dbfile; /**< The database file. This is the file given to dc_context_new(). */ - char* m_blobdir; /**< Full path of the blob directory. This is the directory given to dc_context_new() or a directory in the same directory as dc_context_t::m_dbfile. */ + char* dbfile; /**< The database file. This is the file given to dc_context_new(). */ + char* blobdir; /**< Full path of the blob directory. This is the directory given to dc_context_new() or a directory in the same directory as dc_context_t::dbfile. */ - dc_sqlite3_t* m_sql; /**< Internal SQL object, never NULL */ + dc_sqlite3_t* sql; /**< Internal SQL object, never NULL */ - dc_imap_t* m_imap; /**< Internal IMAP object, never NULL */ - pthread_mutex_t m_imapidle_condmutex; - int m_perform_imap_jobs_needed; + dc_imap_t* imap; /**< Internal IMAP object, never NULL */ + pthread_mutex_t imapidle_condmutex; + int perform_imap_jobs_needed; - dc_smtp_t* m_smtp; /**< Internal SMTP object, never NULL */ - pthread_cond_t m_smtpidle_cond; - pthread_mutex_t m_smtpidle_condmutex; - int m_smtpidle_condflag; - int m_smtpidle_suspend; - int m_smtpidle_in_idleing; + dc_smtp_t* smtp; /**< Internal SMTP object, never NULL */ + pthread_cond_t smtpidle_cond; + pthread_mutex_t smtpidle_condmutex; + int smtpidle_condflag; + int smtpidle_suspend; + int smtpidle_in_idleing; #define DC_JOBS_NEEDED_AT_ONCE 1 #define DC_JOBS_NEEDED_AVOID_DOS 2 - int m_perform_smtp_jobs_needed; + int perform_smtp_jobs_needed; - dc_callback_t m_cb; /**< Internal */ + dc_callback_t cb; /**< Internal */ - char* m_os_name; /**< Internal, may be NULL */ + char* os_name; /**< Internal, may be NULL */ - uint32_t m_cmdline_sel_chat_id; /**< Internal */ + uint32_t cmdline_sel_chat_id; /**< Internal */ - int m_e2ee_enabled; /**< Internal */ + int e2ee_enabled; /**< Internal */ #define DC_LOG_RINGBUF_SIZE 200 - pthread_mutex_t m_log_ringbuf_critical; /**< Internal */ - char* m_log_ringbuf[DC_LOG_RINGBUF_SIZE]; + pthread_mutex_t log_ringbuf_critical; /**< Internal */ + char* log_ringbuf[DC_LOG_RINGBUF_SIZE]; /**< Internal */ - time_t m_log_ringbuf_times[DC_LOG_RINGBUF_SIZE]; + time_t log_ringbuf_times[DC_LOG_RINGBUF_SIZE]; /**< Internal */ - int m_log_ringbuf_pos; /**< Internal. The oldest position resp. the position that is overwritten next */ + int log_ringbuf_pos; /**< Internal. The oldest position resp. the position that is overwritten next */ // QR code scanning (view from Bob, the joiner) - #define DC_VC_AUTH_REQUIRED 2 - #define DC_VC_CONTACT_CONFIRM 6 - int m_bob_expects; - #define DC_BOB_ERROR 0 - #define DC_BOB_SUCCESS 1 - int m_bobs_status; - dc_lot_t* m_bobs_qr_scan; - pthread_mutex_t m_bobs_qr_critical; + #define DC_VC_AUTH_REQUIRED 2 + #define DC_VC_CONTACT_CONFIRM 6 + int bob_expects; + #define DC_BOB_ERROR 0 + #define DC_BOB_SUCCESS 1 + int bobs_status; + dc_lot_t* bobs_qr_scan; + pthread_mutex_t bobs_qr_critical; // time smearing - to keep messages in order, we may modify the time by some seconds - time_t m_last_smeared_timestamp; - pthread_mutex_t m_smear_critical; + time_t last_smeared_timestamp; + pthread_mutex_t smear_critical; // handling ongoing processes initiated by the user - int m_ongoing_running; - int m_shall_stop_ongoing; + int ongoing_running; + int shall_stop_ongoing; }; @@ -174,13 +174,13 @@ uint32_t dc_get_chat_id_by_grpid (dc_context_t*, const typedef struct dc_e2ee_helper_t { // encryption - int m_encryption_successfull; - void* m_cdata_to_free; + int encryption_successfull; + void* cdata_to_free; // decryption - int m_encrypted; // encrypted without problems - dc_hash_t* m_signatures; // fingerprints of valid signatures - dc_hash_t* m_gossipped_addr; + int encrypted; // encrypted without problems + dc_hash_t* signatures; // fingerprints of valid signatures + dc_hash_t* gossipped_addr; } dc_e2ee_helper_t; @@ -197,8 +197,8 @@ extern int dc_shall_stop_ongoing; int dc_alloc_ongoing (dc_context_t*); void dc_free_ongoing (dc_context_t*); -#define dc_is_online(m) ((m)->m_cb((m), DC_EVENT_IS_OFFLINE, 0, 0)==0) -#define dc_is_offline(m) ((m)->m_cb((m), DC_EVENT_IS_OFFLINE, 0, 0)!=0) +#define dc_is_online(m) ((m)->cb((m), DC_EVENT_IS_OFFLINE, 0, 0)==0) +#define dc_is_offline(m) ((m)->cb((m), DC_EVENT_IS_OFFLINE, 0, 0)!=0) /* library private: secure-join */ diff --git a/src/dc_dehtml.c b/src/dc_dehtml.c index c8748def..e8eb8d40 100644 --- a/src/dc_dehtml.c +++ b/src/dc_dehtml.c @@ -32,13 +32,14 @@ typedef struct dehtml_t { - dc_strbuilder_t m_strbuilder; + dc_strbuilder_t strbuilder; - #define DO_NOT_ADD 0 - #define DO_ADD_REMOVE_LINEENDS 1 - #define DO_ADD_PRESERVE_LINEENDS 2 - int m_add_text; - char* m_last_href; + #define DO_NOT_ADD 0 + #define DO_ADD_REMOVE_LINEENDS 1 + #define DO_ADD_PRESERVE_LINEENDS 2 + int add_text; + + char* last_href; } dehtml_t; @@ -49,38 +50,38 @@ static void dehtml_starttag_cb(void* userdata, const char* tag, char** attr) if( strcmp(tag, "p")==0 || strcmp(tag, "div")==0 || strcmp(tag, "table")==0 || strcmp(tag, "td")==0 ) { - dc_strbuilder_cat(&dehtml->m_strbuilder, "\n\n"); - dehtml->m_add_text = DO_ADD_REMOVE_LINEENDS; + dc_strbuilder_cat(&dehtml->strbuilder, "\n\n"); + dehtml->add_text = DO_ADD_REMOVE_LINEENDS; } else if( strcmp(tag, "br")==0 ) { - dc_strbuilder_cat(&dehtml->m_strbuilder, "\n"); - dehtml->m_add_text = DO_ADD_REMOVE_LINEENDS; + dc_strbuilder_cat(&dehtml->strbuilder, "\n"); + dehtml->add_text = DO_ADD_REMOVE_LINEENDS; } else if( strcmp(tag, "style")==0 || strcmp(tag, "script")==0 || strcmp(tag, "title")==0 ) { - dehtml->m_add_text = DO_NOT_ADD; + dehtml->add_text = DO_NOT_ADD; } else if( strcmp(tag, "pre")==0 ) { - dc_strbuilder_cat(&dehtml->m_strbuilder, "\n\n"); - dehtml->m_add_text = DO_ADD_PRESERVE_LINEENDS; + dc_strbuilder_cat(&dehtml->strbuilder, "\n\n"); + dehtml->add_text = DO_ADD_PRESERVE_LINEENDS; } else if( strcmp(tag, "a")==0 ) { - free(dehtml->m_last_href); - dehtml->m_last_href = dc_strdup_keep_null(dc_attr_find(attr, "href")); - if( dehtml->m_last_href ) { - dc_strbuilder_cat(&dehtml->m_strbuilder, "["); + free(dehtml->last_href); + dehtml->last_href = dc_strdup_keep_null(dc_attr_find(attr, "href")); + if( dehtml->last_href ) { + dc_strbuilder_cat(&dehtml->strbuilder, "["); } } else if( strcmp(tag, "b")==0 || strcmp(tag, "strong")==0 ) { - dc_strbuilder_cat(&dehtml->m_strbuilder, "*"); + dc_strbuilder_cat(&dehtml->strbuilder, "*"); } else if( strcmp(tag, "i")==0 || strcmp(tag, "em")==0 ) { - dc_strbuilder_cat(&dehtml->m_strbuilder, "_"); + dc_strbuilder_cat(&dehtml->strbuilder, "_"); } } @@ -89,18 +90,18 @@ static void dehtml_text_cb(void* userdata, const char* text, int len) { dehtml_t* dehtml = (dehtml_t*)userdata; - if( dehtml->m_add_text != DO_NOT_ADD ) + if( dehtml->add_text != DO_NOT_ADD ) { - char* last_added = dc_strbuilder_cat(&dehtml->m_strbuilder, text); + char* last_added = dc_strbuilder_cat(&dehtml->strbuilder, text); - if( dehtml->m_add_text==DO_ADD_REMOVE_LINEENDS ) + if( dehtml->add_text==DO_ADD_REMOVE_LINEENDS ) { unsigned char* p = (unsigned char*)last_added; while( *p ) { if( *p=='\n' ) { int last_is_lineend = 1; /* avoid converting `text1
\ntext2` to `text1\n text2` (`\r` is removed later) */ const unsigned char* p2 = p-1; - while( p2>=(const unsigned char*)dehtml->m_strbuilder.m_buf ) { + while( p2>=(const unsigned char*)dehtml->strbuilder.buf ) { if( *p2 == '\r' ) { } else if( *p2 == '\n' ) { @@ -129,26 +130,26 @@ static void dehtml_endtag_cb(void* userdata, const char* tag) || strcmp(tag, "style")==0 || strcmp(tag, "script")==0 || strcmp(tag, "title")==0 || strcmp(tag, "pre")==0 ) { - dc_strbuilder_cat(&dehtml->m_strbuilder, "\n\n"); /* do not expect an starting block element (which, of course, should come right now) */ - dehtml->m_add_text = DO_ADD_REMOVE_LINEENDS; + dc_strbuilder_cat(&dehtml->strbuilder, "\n\n"); /* do not expect an starting block element (which, of course, should come right now) */ + dehtml->add_text = DO_ADD_REMOVE_LINEENDS; } else if( strcmp(tag, "a")==0 ) { - if( dehtml->m_last_href ) { - dc_strbuilder_cat(&dehtml->m_strbuilder, "]("); - dc_strbuilder_cat(&dehtml->m_strbuilder, dehtml->m_last_href); - dc_strbuilder_cat(&dehtml->m_strbuilder, ")"); - free(dehtml->m_last_href); - dehtml->m_last_href = NULL; + if( dehtml->last_href ) { + dc_strbuilder_cat(&dehtml->strbuilder, "]("); + dc_strbuilder_cat(&dehtml->strbuilder, dehtml->last_href); + dc_strbuilder_cat(&dehtml->strbuilder, ")"); + free(dehtml->last_href); + dehtml->last_href = NULL; } } else if( strcmp(tag, "b")==0 || strcmp(tag, "strong")==0 ) { - dc_strbuilder_cat(&dehtml->m_strbuilder, "*"); + dc_strbuilder_cat(&dehtml->strbuilder, "*"); } else if( strcmp(tag, "i")==0 || strcmp(tag, "em")==0 ) { - dc_strbuilder_cat(&dehtml->m_strbuilder, "_"); + dc_strbuilder_cat(&dehtml->strbuilder, "_"); } } @@ -164,16 +165,16 @@ char* dc_dehtml(char* buf_terminated) dc_saxparser_t saxparser; memset(&dehtml, 0, sizeof(dehtml_t)); - dehtml.m_add_text = DO_ADD_REMOVE_LINEENDS; - dc_strbuilder_init(&dehtml.m_strbuilder, strlen(buf_terminated)); + dehtml.add_text = DO_ADD_REMOVE_LINEENDS; + dc_strbuilder_init(&dehtml.strbuilder, strlen(buf_terminated)); dc_saxparser_init(&saxparser, &dehtml); dc_saxparser_set_tag_handler(&saxparser, dehtml_starttag_cb, dehtml_endtag_cb); dc_saxparser_set_text_handler(&saxparser, dehtml_text_cb); dc_saxparser_parse(&saxparser, buf_terminated); - free(dehtml.m_last_href); - return dehtml.m_strbuilder.m_buf; + free(dehtml.last_href); + return dehtml.strbuilder.buf; } } diff --git a/src/dc_e2ee.c b/src/dc_e2ee.c index 3137fdc1..8a974d1a 100644 --- a/src/dc_e2ee.c +++ b/src/dc_e2ee.c @@ -198,11 +198,11 @@ static int load_or_generate_self_public_key__(dc_context_t* context, dc_key_t* p int key_created = 0; int success = 0, key_creation_here = 0; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || public_key == NULL ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || public_key == NULL ) { goto cleanup; } - if( !dc_key_load_self_public(public_key, self_addr, context->m_sql) ) + if( !dc_key_load_self_public(public_key, self_addr, context->sql) ) { /* create the keypair - this may take a moment, however, as this is in a thread, this is no big deal */ if( s_in_key_creation ) { goto cleanup; } @@ -255,7 +255,7 @@ static int load_or_generate_self_public_key__(dc_context_t* context, dc_key_t* p goto cleanup; } - if( !dc_key_save_self_keypair(public_key, private_key, self_addr, 1/*set default*/, context->m_sql) ) { + if( !dc_key_save_self_keypair(public_key, private_key, self_addr, 1/*set default*/, context->sql) ) { dc_log_warning(context, 0, "Cannot save keypair."); goto cleanup; } @@ -282,11 +282,11 @@ int dc_ensure_secret_key_exists(dc_context_t* context) dc_key_t* public_key = dc_key_new(); char* self_addr = NULL; - if( context==NULL || context->m_magic != DC_CONTEXT_MAGIC || public_key==NULL ) { + if( context==NULL || context->magic != DC_CONTEXT_MAGIC || public_key==NULL ) { goto cleanup; } - if( (self_addr=dc_sqlite3_get_config(context->m_sql, "configured_addr", NULL))==NULL ) { + if( (self_addr=dc_sqlite3_get_config(context->sql, "configured_addr", NULL))==NULL ) { dc_log_warning(context, 0, "Cannot ensure secret key if context is not configured."); goto cleanup; } @@ -327,29 +327,29 @@ void dc_e2ee_encrypt(dc_context_t* context, const clist* recipients_addr, if( helper ) { memset(helper, 0, sizeof(dc_e2ee_helper_t)); } - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || recipients_addr == NULL || in_out_message == NULL + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || recipients_addr == NULL || in_out_message == NULL || in_out_message->mm_parent /* libEtPan's pgp_encrypt_mime() takes the parent as the new root. We just expect the root as being given to this function. */ || autocryptheader == NULL || keyring==NULL || sign_key==NULL || plain == NULL || helper == NULL ) { goto cleanup; } /* init autocrypt header from db */ - autocryptheader->m_prefer_encrypt = DC_PE_NOPREFERENCE; - if( context->m_e2ee_enabled ) { - autocryptheader->m_prefer_encrypt = DC_PE_MUTUAL; + autocryptheader->prefer_encrypt = DC_PE_NOPREFERENCE; + if( context->e2ee_enabled ) { + autocryptheader->prefer_encrypt = DC_PE_MUTUAL; } - autocryptheader->m_addr = dc_sqlite3_get_config(context->m_sql, "configured_addr", NULL); - if( autocryptheader->m_addr == NULL ) { + autocryptheader->addr = dc_sqlite3_get_config(context->sql, "configured_addr", NULL); + if( autocryptheader->addr == NULL ) { goto cleanup; } - if( !load_or_generate_self_public_key__(context, autocryptheader->m_public_key, autocryptheader->m_addr, in_out_message/*only for random-seed*/) ) { + if( !load_or_generate_self_public_key__(context, autocryptheader->public_key, autocryptheader->addr, in_out_message/*only for random-seed*/) ) { goto cleanup; } /* load peerstate information etc. */ - if( autocryptheader->m_prefer_encrypt==DC_PE_MUTUAL || e2ee_guaranteed ) + if( autocryptheader->prefer_encrypt==DC_PE_MUTUAL || e2ee_guaranteed ) { do_encrypt = 1; clistiter* iter1; @@ -357,13 +357,13 @@ void dc_e2ee_encrypt(dc_context_t* context, const clist* recipients_addr, const char* recipient_addr = clist_content(iter1); dc_apeerstate_t* peerstate = dc_apeerstate_new(context); dc_key_t* key_to_use = NULL; - if( strcasecmp(recipient_addr, autocryptheader->m_addr) == 0 ) + if( strcasecmp(recipient_addr, autocryptheader->addr) == 0 ) { ; // encrypt to SELF, this key is added below } - else if( dc_apeerstate_load_by_addr(peerstate, context->m_sql, recipient_addr) + else if( dc_apeerstate_load_by_addr(peerstate, context->sql, recipient_addr) && (key_to_use=dc_apeerstate_peek_key(peerstate, min_verified)) != NULL - && (peerstate->m_prefer_encrypt==DC_PE_MUTUAL || e2ee_guaranteed) ) + && (peerstate->prefer_encrypt==DC_PE_MUTUAL || e2ee_guaranteed) ) { dc_keyring_add(keyring, key_to_use); /* we always add all recipients (even on IMAP upload) as otherwise forwarding may fail */ dc_array_add_ptr(peerstates, peerstate); @@ -378,8 +378,8 @@ void dc_e2ee_encrypt(dc_context_t* context, const clist* recipients_addr, } if( do_encrypt ) { - dc_keyring_add(keyring, autocryptheader->m_public_key); /* we always add ourself as otherwise forwarded messages are not readable */ - if( !dc_key_load_self_private(sign_key, autocryptheader->m_addr, context->m_sql) ) { + dc_keyring_add(keyring, autocryptheader->public_key); /* we always add ourself as otherwise forwarded messages are not readable */ + if( !dc_key_load_self_private(sign_key, autocryptheader->addr, context->sql) ) { do_encrypt = 0; } } @@ -462,7 +462,7 @@ void dc_e2ee_encrypt(dc_context_t* context, const clist* recipients_addr, if( !dc_pgp_pk_encrypt(context, plain->str, plain->len, keyring, sign_key, 1/*use_armor*/, (void**)&ctext, &ctext_bytes) ) { goto cleanup; } - helper->m_cdata_to_free = ctext; + helper->cdata_to_free = ctext; //char* t2=dc_null_terminate(ctext,ctext_bytes);printf("ENCRYPTED:\n%s\n",t2);free(t2); // DEBUG OUTPUT /* create MIME-structure that will contain the encrypted text */ @@ -484,7 +484,7 @@ void dc_e2ee_encrypt(dc_context_t* context, const clist* recipients_addr, mailmime_free(message_to_encrypt); //MMAPString* t3=mmap_string_new("");mailmime_write_mem(t3,&col,in_out_message);char* t4=dc_null_terminate(t3->str,t3->len); printf("ENCRYPTED+MIME_ENCODED:\n%s\n",t4);free(t4);mmap_string_free(t3); // DEBUG OUTPUT - helper->m_encryption_successfull = 1; + helper->encryption_successfull = 1; } char* p = dc_aheader_render(autocryptheader); @@ -510,21 +510,21 @@ void dc_e2ee_thanks(dc_e2ee_helper_t* helper) return; } - free(helper->m_cdata_to_free); - helper->m_cdata_to_free = NULL; + free(helper->cdata_to_free); + helper->cdata_to_free = NULL; - if( helper->m_gossipped_addr ) + if( helper->gossipped_addr ) { - dc_hash_clear(helper->m_gossipped_addr); - free(helper->m_gossipped_addr); - helper->m_gossipped_addr = NULL; + dc_hash_clear(helper->gossipped_addr); + free(helper->gossipped_addr); + helper->gossipped_addr = NULL; } - if( helper->m_signatures ) + if( helper->signatures ) { - dc_hash_clear(helper->m_signatures); - free(helper->m_signatures); - helper->m_signatures = NULL; + dc_hash_clear(helper->signatures); + free(helper->signatures); + helper->signatures = NULL; } } @@ -739,27 +739,27 @@ static dc_hash_t* update_gossip_peerstates(dc_context_t* context, time_t message { dc_aheader_t* gossip_header = dc_aheader_new(); if( dc_aheader_set_from_string(gossip_header, optional_field->fld_value) - && dc_pgp_is_valid_key(context, gossip_header->m_public_key) ) + && dc_pgp_is_valid_key(context, gossip_header->public_key) ) { /* found an Autocrypt-Gossip entry, create recipents list and check if addr matches */ if( recipients == NULL ) { recipients = mailimf_get_recipients(imffields); } - if( dc_hash_find(recipients, gossip_header->m_addr, strlen(gossip_header->m_addr)) ) + if( dc_hash_find(recipients, gossip_header->addr, strlen(gossip_header->addr)) ) { /* valid recipient: update peerstate */ dc_apeerstate_t* peerstate = dc_apeerstate_new(context); - if( !dc_apeerstate_load_by_addr(peerstate, context->m_sql, gossip_header->m_addr) ) { + if( !dc_apeerstate_load_by_addr(peerstate, context->sql, gossip_header->addr) ) { dc_apeerstate_init_from_gossip(peerstate, gossip_header, message_time); - dc_apeerstate_save_to_db(peerstate, context->m_sql, 1/*create*/); + dc_apeerstate_save_to_db(peerstate, context->sql, 1/*create*/); } else { dc_apeerstate_apply_gossip(peerstate, gossip_header, message_time); - dc_apeerstate_save_to_db(peerstate, context->m_sql, 0/*do not create*/); + dc_apeerstate_save_to_db(peerstate, context->sql, 0/*do not create*/); } - if( peerstate->m_degrade_event ) { + if( peerstate->degrade_event ) { dc_handle_degrade_event(context, peerstate); } @@ -771,11 +771,11 @@ static dc_hash_t* update_gossip_peerstates(dc_context_t* context, time_t message gossipped_addr = malloc(sizeof(dc_hash_t)); dc_hash_init(gossipped_addr, DC_HASH_STRING, 1/*copy key*/); } - dc_hash_insert(gossipped_addr, gossip_header->m_addr, strlen(gossip_header->m_addr), (void*)1); + dc_hash_insert(gossipped_addr, gossip_header->addr, strlen(gossip_header->addr), (void*)1); } else { - dc_log_info(context, 0, "Ignoring gossipped \"%s\" as the address is not in To/Cc list.", gossip_header->m_addr); + dc_log_info(context, 0, "Ignoring gossipped \"%s\" as the address is not in To/Cc list.", gossip_header->addr); } } dc_aheader_unref(gossip_header); @@ -808,7 +808,7 @@ void dc_e2ee_decrypt(dc_context_t* context, struct mailmime* in_out_message, if( helper ) { memset(helper, 0, sizeof(dc_e2ee_helper_t)); } - if( context==NULL || context->m_magic != DC_CONTEXT_MAGIC || in_out_message==NULL + if( context==NULL || context->magic != DC_CONTEXT_MAGIC || in_out_message==NULL || helper == NULL || imffields==NULL ) { goto cleanup; } @@ -838,7 +838,7 @@ void dc_e2ee_decrypt(dc_context_t* context, struct mailmime* in_out_message, autocryptheader = dc_aheader_new_from_imffields(from, imffields); if( autocryptheader ) { - if( !dc_pgp_is_valid_key(context, autocryptheader->m_public_key) ) { + if( !dc_pgp_is_valid_key(context, autocryptheader->public_key) ) { dc_aheader_unref(autocryptheader); autocryptheader = NULL; } @@ -850,67 +850,67 @@ void dc_e2ee_decrypt(dc_context_t* context, struct mailmime* in_out_message, if( message_time > 0 && from ) { - if( dc_apeerstate_load_by_addr(peerstate, context->m_sql, from) ) { + if( dc_apeerstate_load_by_addr(peerstate, context->sql, from) ) { if( autocryptheader ) { dc_apeerstate_apply_header(peerstate, autocryptheader, message_time); - dc_apeerstate_save_to_db(peerstate, context->m_sql, 0/*no not create*/); + dc_apeerstate_save_to_db(peerstate, context->sql, 0/*no not create*/); } else { - if( message_time > peerstate->m_last_seen_autocrypt + if( message_time > peerstate->last_seen_autocrypt && !contains_report(in_out_message) /*reports are ususally not encrpyted; do not degrade decryption then*/ ){ dc_apeerstate_degrade_encryption(peerstate, message_time); - dc_apeerstate_save_to_db(peerstate, context->m_sql, 0/*no not create*/); + dc_apeerstate_save_to_db(peerstate, context->sql, 0/*no not create*/); } } } else if( autocryptheader ) { dc_apeerstate_init_from_header(peerstate, autocryptheader, message_time); - dc_apeerstate_save_to_db(peerstate, context->m_sql, 1/*create*/); + dc_apeerstate_save_to_db(peerstate, context->sql, 1/*create*/); } } /* load private key for decryption */ - if( (self_addr=dc_sqlite3_get_config(context->m_sql, "configured_addr", NULL))==NULL ) { + if( (self_addr=dc_sqlite3_get_config(context->sql, "configured_addr", NULL))==NULL ) { goto cleanup; } - if( !dc_keyring_load_self_private_for_decrypting(private_keyring, self_addr, context->m_sql) ) { + if( !dc_keyring_load_self_private_for_decrypting(private_keyring, self_addr, context->sql) ) { goto cleanup; } /* if not yet done, load peer with public key for verification (should be last as the peer may be modified above) */ - if( peerstate->m_last_seen == 0 ) { - dc_apeerstate_load_by_addr(peerstate, context->m_sql, from); + if( peerstate->last_seen == 0 ) { + dc_apeerstate_load_by_addr(peerstate, context->sql, from); } - if( peerstate->m_degrade_event ) { + if( peerstate->degrade_event ) { dc_handle_degrade_event(context, peerstate); } // offer both, gossip and public, for signature validation. // the caller may check the signature fingerprints as needed later. - dc_keyring_add(public_keyring_for_validate, peerstate->m_gossip_key); - dc_keyring_add(public_keyring_for_validate, peerstate->m_public_key); + dc_keyring_add(public_keyring_for_validate, peerstate->gossip_key); + dc_keyring_add(public_keyring_for_validate, peerstate->public_key); /* finally, decrypt. If sth. was decrypted, decrypt_recursive() returns "true" and we start over to decrypt maybe just added parts. */ - helper->m_signatures = malloc(sizeof(dc_hash_t)); - dc_hash_init(helper->m_signatures, DC_HASH_STRING, 1/*copy key*/); + helper->signatures = malloc(sizeof(dc_hash_t)); + dc_hash_init(helper->signatures, DC_HASH_STRING, 1/*copy key*/); int iterations = 0; while( iterations < 10 ) { int has_unencrypted_parts = 0; if( !decrypt_recursive(context, in_out_message, private_keyring, public_keyring_for_validate, - helper->m_signatures, &gossip_headers, &has_unencrypted_parts) ) { + helper->signatures, &gossip_headers, &has_unencrypted_parts) ) { break; } // if we're here, sth. was encrypted. if we're on top-level, and there are no // additional unencrypted parts in the message the encryption was fine - // (signature is handled separately and returned as m_signatures) + // (signature is handled separately and returned as `signatures`) if( iterations == 0 && !has_unencrypted_parts ) { - helper->m_encrypted = 1; + helper->encrypted = 1; } iterations++; @@ -918,7 +918,7 @@ void dc_e2ee_decrypt(dc_context_t* context, struct mailmime* in_out_message, /* check for Autocrypt-Gossip */ if( gossip_headers ) { - helper->m_gossipped_addr = update_gossip_peerstates(context, message_time, imffields, gossip_headers); + helper->gossipped_addr = update_gossip_peerstates(context, message_time, imffields, gossip_headers); } //mailmime_print(in_out_message); diff --git a/src/dc_imap.c b/src/dc_imap.c index 5997bd73..ab03c2e2 100644 --- a/src/dc_imap.c +++ b/src/dc_imap.c @@ -52,8 +52,8 @@ static int is_error(dc_imap_t* imap, int code) if( code == MAILIMAP_ERROR_STREAM /*4*/ || code == MAILIMAP_ERROR_PARSE /*5*/ ) { - dc_log_info(imap->m_context, 0, "IMAP stream lost; we'll reconnect soon."); - imap->m_should_reconnect = 1; + dc_log_info(imap->context, 0, "IMAP stream lost; we'll reconnect soon."); + imap->should_reconnect = 1; } return 1; @@ -66,7 +66,7 @@ static void get_config_lastseenuid(dc_imap_t* imap, const char* folder, uint32_t *lastseenuid = 0; char* key = dc_mprintf("imap.mailbox.%s", folder); - char* val1 = imap->m_get_config(imap, key, NULL), *val2 = NULL, *val3 = NULL; + char* val1 = imap->get_config(imap, key, NULL), *val2 = NULL, *val3 = NULL; if( val1 ) { /* the entry has the format `imap.mailbox.=:` */ @@ -92,7 +92,7 @@ static void set_config_lastseenuid(dc_imap_t* imap, const char* folder, uint32_t { char* key = dc_mprintf("imap.mailbox.%s", folder); char* val = dc_mprintf("%lu:%lu", uidvalidity, lastseenuid); - imap->m_set_config(imap, key, val); + imap->set_config(imap, key, val); free(val); free(key); } @@ -113,10 +113,10 @@ static int get_folder_meaning(const dc_imap_t* imap, struct mailimap_mbx_list_fl char* lower = NULL; int ret_meaning = MEANING_NORMAL; - if( !force_fallback && (imap->m_has_xlist || flags != NULL) ) + if( !force_fallback && (imap->has_xlist || flags != NULL) ) { /* We check for flags if we get some (LIST may also return some, see https://tools.ietf.org/html/rfc6154 ) - or if m_has_xlist is set. However, we also allow a NULL-pointer for "no flags" if m_has_xlist is true. */ + or if has_xlist is set. However, we also allow a NULL-pointer for "no flags" if has_xlist is true. */ if( flags && flags->mbf_oflags ) { clistiter* iter2; @@ -192,9 +192,9 @@ static int get_folder_meaning(const dc_imap_t* imap, struct mailimap_mbx_list_fl typedef struct dc_imapfolder_t { - char* m_name_to_select; - char* m_name_utf8; - int m_meaning; + char* name_to_select; + char* name_utf8; + int meaning; } dc_imapfolder_t; @@ -205,39 +205,39 @@ static clist* list_folders__(dc_imap_t* imap) clist * ret_list = clist_new(); int r, xlist_works = 0; - if( imap==NULL || imap->m_hEtpan==NULL ) { + if( imap==NULL || imap->hEtpan==NULL ) { goto cleanup; } /* the "*" not only gives us the folders from the main directory, but also all subdirectories; so the resulting foldernames may contain delimiters as "folder/subdir/subsubdir" etc. However, as we do not really use folders, this is just fine (otherwise we'd implement this functinon recursively. */ - if( imap->m_has_xlist ) { - r = mailimap_xlist(imap->m_hEtpan, "", "*", &imap_list); + if( imap->has_xlist ) { + r = mailimap_xlist(imap->hEtpan, "", "*", &imap_list); } else { - r = mailimap_list(imap->m_hEtpan, "", "*", &imap_list); + r = mailimap_list(imap->hEtpan, "", "*", &imap_list); } if( is_error(imap, r) || imap_list==NULL ) { imap_list = NULL; - dc_log_warning(imap->m_context, 0, "Cannot get folder list."); + dc_log_warning(imap->context, 0, "Cannot get folder list."); goto cleanup; } if( clist_count(imap_list)<=0 ) { - dc_log_warning(imap->m_context, 0, "Folder list is empty."); + dc_log_warning(imap->context, 0, "Folder list is empty."); goto cleanup; } //default IMAP delimiter if none is returned by the list command - imap->m_imap_delimiter = '.'; + imap->imap_delimiter = '.'; for( iter1 = clist_begin(imap_list); iter1 != NULL ; iter1 = clist_next(iter1) ) { struct mailimap_mailbox_list* imap_folder = (struct mailimap_mailbox_list*)clist_content(iter1); if (imap_folder->mb_delimiter) { /* Set IMAP delimiter */ - imap->m_imap_delimiter = imap_folder->mb_delimiter; + imap->imap_delimiter = imap_folder->mb_delimiter; } dc_imapfolder_t* ret_folder = calloc(1, sizeof(dc_imapfolder_t)); @@ -245,16 +245,16 @@ static clist* list_folders__(dc_imap_t* imap) if( strcasecmp(imap_folder->mb_name, "INBOX")==0 ) { /* Force upper case INBOX as we also use it directly this way; a unified name is needed as we use the folder name to remember the last uid. Servers may return any case, however, all variants MUST lead to the same INBOX, see RFC 3501 5.1 */ - ret_folder->m_name_to_select = dc_strdup("INBOX"); + ret_folder->name_to_select = dc_strdup("INBOX"); } else { - ret_folder->m_name_to_select = dc_strdup(imap_folder->mb_name); + ret_folder->name_to_select = dc_strdup(imap_folder->mb_name); } - ret_folder->m_name_utf8 = dc_decode_modified_utf7(imap_folder->mb_name, 0); - ret_folder->m_meaning = get_folder_meaning(imap, imap_folder->mb_flag, ret_folder->m_name_utf8, false); + ret_folder->name_utf8 = dc_decode_modified_utf7(imap_folder->mb_name, 0); + ret_folder->meaning = get_folder_meaning(imap, imap_folder->mb_flag, ret_folder->name_utf8, false); - if( ret_folder->m_meaning == MEANING_IGNORE || ret_folder->m_meaning == MEANING_SENT_OBJECTS /*MEANING_INBOX is no hint for a working XLIST*/ ) { + if( ret_folder->meaning == MEANING_IGNORE || ret_folder->meaning == MEANING_SENT_OBJECTS /*MEANING_INBOX is no hint for a working XLIST*/ ) { xlist_works = 1; } @@ -267,7 +267,7 @@ static clist* list_folders__(dc_imap_t* imap) for( iter1 = clist_begin(ret_list); iter1 != NULL ; iter1 = clist_next(iter1) ) { dc_imapfolder_t* ret_folder = (struct dc_imapfolder_t*)clist_content(iter1); - ret_folder->m_meaning = get_folder_meaning(imap, NULL, ret_folder->m_name_utf8, true); + ret_folder->meaning = get_folder_meaning(imap, NULL, ret_folder->name_utf8, true); } } @@ -285,8 +285,8 @@ static void free_folders(clist* folders) clistiter* iter1; for( iter1 = clist_begin(folders); iter1 != NULL ; iter1 = clist_next(iter1) ) { dc_imapfolder_t* ret_folder = (struct dc_imapfolder_t*)clist_content(iter1); - free(ret_folder->m_name_to_select); - free(ret_folder->m_name_utf8); + free(ret_folder->name_to_select); + free(ret_folder->name_utf8); free(ret_folder); } clist_free(folders); @@ -301,80 +301,80 @@ static int init_chat_folders__(dc_imap_t* imap) clistiter* iter1; char *normal_folder = NULL, *sent_folder = NULL, *chats_folder = NULL; - if( imap==NULL || imap->m_hEtpan==NULL ) { + if( imap==NULL || imap->hEtpan==NULL ) { goto cleanup; } - if( imap->m_sent_folder && imap->m_sent_folder[0] ) { + if( imap->sent_folder && imap->sent_folder[0] ) { success = 1; goto cleanup; } - free(imap->m_sent_folder); - imap->m_sent_folder = NULL; + free(imap->sent_folder); + imap->sent_folder = NULL; - free(imap->m_moveto_folder); - imap->m_moveto_folder = NULL; - //this sets imap->m_imap_delimiter as side-effect + free(imap->moveto_folder); + imap->moveto_folder = NULL; + //this sets imap->imap_delimiter as side-effect folder_list = list_folders__(imap); //as a fallback, the chats_folder is created under INBOX as required e.g. for DomainFactory char fallback_folder[64]; - snprintf(fallback_folder, sizeof(fallback_folder), "INBOX%c%s", imap->m_imap_delimiter, DC_CHATS_FOLDER); + snprintf(fallback_folder, sizeof(fallback_folder), "INBOX%c%s", imap->imap_delimiter, DC_CHATS_FOLDER); for( iter1 = clist_begin(folder_list); iter1 != NULL ; iter1 = clist_next(iter1) ) { dc_imapfolder_t* folder = (struct dc_imapfolder_t*)clist_content(iter1); - if( strcmp(folder->m_name_utf8, DC_CHATS_FOLDER)==0 || strcmp(folder->m_name_utf8, fallback_folder)==0 ) { - chats_folder = dc_strdup(folder->m_name_to_select); + if( strcmp(folder->name_utf8, DC_CHATS_FOLDER)==0 || strcmp(folder->name_utf8, fallback_folder)==0 ) { + chats_folder = dc_strdup(folder->name_to_select); break; } - else if( folder->m_meaning == MEANING_SENT_OBJECTS ) { - sent_folder = dc_strdup(folder->m_name_to_select); + else if( folder->meaning == MEANING_SENT_OBJECTS ) { + sent_folder = dc_strdup(folder->name_to_select); } - else if( folder->m_meaning == MEANING_NORMAL && normal_folder == NULL ) { - normal_folder = dc_strdup(folder->m_name_to_select); + else if( folder->meaning == MEANING_NORMAL && normal_folder == NULL ) { + normal_folder = dc_strdup(folder->name_to_select); } } - if( chats_folder == NULL && (imap->m_server_flags&DC_NO_MOVE_TO_CHATS)==0 ) { - dc_log_info(imap->m_context, 0, "Creating IMAP-folder \"%s\"...", DC_CHATS_FOLDER); - int r = mailimap_create(imap->m_hEtpan, DC_CHATS_FOLDER); + if( chats_folder == NULL && (imap->server_flags&DC_NO_MOVE_TO_CHATS)==0 ) { + dc_log_info(imap->context, 0, "Creating IMAP-folder \"%s\"...", DC_CHATS_FOLDER); + int r = mailimap_create(imap->hEtpan, DC_CHATS_FOLDER); if( is_error(imap, r) ) { - dc_log_warning(imap->m_context, 0, "Cannot create IMAP-folder, using trying INBOX subfolder."); - r = mailimap_create(imap->m_hEtpan, fallback_folder); + dc_log_warning(imap->context, 0, "Cannot create IMAP-folder, using trying INBOX subfolder."); + r = mailimap_create(imap->hEtpan, fallback_folder); if( is_error(imap, r) ) { /* continue on errors, we'll just use a different folder then */ - dc_log_warning(imap->m_context, 0, "Cannot create IMAP-folder, using default."); + dc_log_warning(imap->context, 0, "Cannot create IMAP-folder, using default."); } else { chats_folder = dc_strdup(fallback_folder); - dc_log_info(imap->m_context, 0, "IMAP-folder created (inbox subfolder)."); + dc_log_info(imap->context, 0, "IMAP-folder created (inbox subfolder)."); } } else { chats_folder = dc_strdup(DC_CHATS_FOLDER); - dc_log_info(imap->m_context, 0, "IMAP-folder created."); + dc_log_info(imap->context, 0, "IMAP-folder created."); } } /* Subscribe to the created folder. Otherwise, although a top-level folder, if clients use LSUB for listing, the created folder may be hidden. (we could also do this directly after creation, however, we forgot this in versions m_get_config(imap, "imap.subscribedToChats", NULL)==NULL ) { - mailimap_subscribe(imap->m_hEtpan, chats_folder); - imap->m_set_config(imap, "imap.subscribedToChats", "1"); + if( chats_folder && imap->get_config(imap, "imap.subscribedToChats", NULL)==NULL ) { + mailimap_subscribe(imap->hEtpan, chats_folder); + imap->set_config(imap, "imap.subscribedToChats", "1"); } if( chats_folder ) { - imap->m_moveto_folder = dc_strdup(chats_folder); - imap->m_sent_folder = dc_strdup(chats_folder); + imap->moveto_folder = dc_strdup(chats_folder); + imap->sent_folder = dc_strdup(chats_folder); success = 1; } else if( sent_folder ) { - imap->m_sent_folder = dc_strdup(sent_folder); + imap->sent_folder = dc_strdup(sent_folder); success = 1; } else if( normal_folder ) { - imap->m_sent_folder = dc_strdup(normal_folder); + imap->sent_folder = dc_strdup(normal_folder); success = 1; } @@ -393,38 +393,38 @@ static int select_folder__(dc_imap_t* imap, const char* folder /*may be NULL*/) return 0; } - if( imap->m_hEtpan==NULL ) { - imap->m_selected_folder[0] = 0; - imap->m_selected_folder_needs_expunge = 0; + if( imap->hEtpan==NULL ) { + imap->selected_folder[0] = 0; + imap->selected_folder_needs_expunge = 0; return 0; } /* if there is a new folder and the new folder is equal to the selected one, there's nothing to do. if there is _no_ new folder, we continue as we might want to expunge below. */ - if( folder && strcmp(imap->m_selected_folder, folder)==0 ) { + if( folder && strcmp(imap->selected_folder, folder)==0 ) { return 1; } /* deselect existing folder, if needed (it's also done implicitly by SELECT, however, without EXPUNGE then) */ - if( imap->m_selected_folder_needs_expunge ) { - if( imap->m_selected_folder[0] ) { - dc_log_info(imap->m_context, 0, "Expunge messages in \"%s\".", imap->m_selected_folder); - mailimap_close(imap->m_hEtpan); /* a CLOSE-SELECT is considerably faster than an EXPUNGE-SELECT, see https://tools.ietf.org/html/rfc3501#section-6.4.2 */ + if( imap->selected_folder_needs_expunge ) { + if( imap->selected_folder[0] ) { + dc_log_info(imap->context, 0, "Expunge messages in \"%s\".", imap->selected_folder); + mailimap_close(imap->hEtpan); /* a CLOSE-SELECT is considerably faster than an EXPUNGE-SELECT, see https://tools.ietf.org/html/rfc3501#section-6.4.2 */ } - imap->m_selected_folder_needs_expunge = 0; + imap->selected_folder_needs_expunge = 0; } /* select new folder */ if( folder ) { - int r = mailimap_select(imap->m_hEtpan, folder); - if( is_error(imap, r) || imap->m_hEtpan->imap_selection_info == NULL ) { - imap->m_selected_folder[0] = 0; + int r = mailimap_select(imap->hEtpan, folder); + if( is_error(imap, r) || imap->hEtpan->imap_selection_info == NULL ) { + imap->selected_folder[0] = 0; return 0; } } - free(imap->m_selected_folder); - imap->m_selected_folder = dc_strdup(folder); + free(imap->selected_folder); + imap->selected_folder = dc_strdup(folder); return 1; } @@ -441,9 +441,9 @@ static uint32_t search_uid__(dc_imap_t* imap, const char* message_id) for( cur = clist_begin(folders); cur != NULL ; cur = clist_next(cur) ) { dc_imapfolder_t* folder = (dc_imapfolder_t*)clist_content(cur); - if( select_folder__(imap, folder->m_name_to_select) ) + if( select_folder__(imap, folder->name_to_select) ) { - int r = mailimap_uid_search(imap->m_hEtpan, "utf-8", key, &search_result); + int r = mailimap_uid_search(imap->hEtpan, "utf-8", key, &search_result); if( !is_error(imap, r) && search_result ) { if( (cur2=clist_begin(search_result)) != NULL ) { uint32_t* ptr_uid = (uint32_t *)clist_content(cur2); @@ -644,39 +644,39 @@ static int fetch_single_msg(dc_imap_t* imap, const char* folder, uint32_t server goto cleanup; } - if( imap->m_hEtpan==NULL ) { + if( imap->hEtpan==NULL ) { goto cleanup; } { struct mailimap_set* set = mailimap_set_new_single(server_uid); - r = mailimap_uid_fetch(imap->m_hEtpan, set, imap->m_fetch_type_body, &fetch_result); + r = mailimap_uid_fetch(imap->hEtpan, set, imap->fetch_type_body, &fetch_result); mailimap_set_free(set); } if( is_error(imap, r) || fetch_result == NULL ) { fetch_result = NULL; - dc_log_warning(imap->m_context, 0, "Error #%i on fetching message #%i from folder \"%s\"; retry=%i.", (int)r, (int)server_uid, folder, (int)imap->m_should_reconnect); - if( imap->m_should_reconnect ) { + dc_log_warning(imap->context, 0, "Error #%i on fetching message #%i from folder \"%s\"; retry=%i.", (int)r, (int)server_uid, folder, (int)imap->should_reconnect); + if( imap->should_reconnect ) { retry_later = 1; /* maybe we should also retry on other errors, however, we should check this carefully, as this may result in a dead lock! */ } goto cleanup; /* this is an error that should be recovered; the caller should try over later to fetch the message again (if there is no such message, we simply get an empty result) */ } if( (cur=clist_begin(fetch_result)) == NULL ) { - dc_log_warning(imap->m_context, 0, "Message #%i does not exist in folder \"%s\".", (int)server_uid, folder); + dc_log_warning(imap->context, 0, "Message #%i does not exist in folder \"%s\".", (int)server_uid, folder); goto cleanup; /* server response is fine, however, there is no such message, do not try to fetch the message again */ } struct mailimap_msg_att* msg_att = (struct mailimap_msg_att*)clist_content(cur); peek_body(msg_att, &msg_content, &msg_bytes, &flags, &deleted); if( msg_content == NULL || msg_bytes <= 0 || deleted ) { - /* dc_log_warning(imap->m_context, 0, "Message #%i in folder \"%s\" is empty or deleted.", (int)server_uid, folder); -- this is a quite usual situation, do not print a warning */ + /* dc_log_warning(imap->context, 0, "Message #%i in folder \"%s\" is empty or deleted.", (int)server_uid, folder); -- this is a quite usual situation, do not print a warning */ goto cleanup; } - imap->m_receive_imf(imap, msg_content, msg_bytes, folder, server_uid, flags); + imap->receive_imf(imap, msg_content, msg_bytes, folder, server_uid, flags); cleanup: @@ -701,45 +701,45 @@ static int fetch_from_single_folder(dc_imap_t* imap, const char* folder) goto cleanup; } - if( imap->m_hEtpan==NULL ) { - dc_log_info(imap->m_context, 0, "Cannot fetch from \"%s\" - not connected.", folder); + if( imap->hEtpan==NULL ) { + dc_log_info(imap->context, 0, "Cannot fetch from \"%s\" - not connected.", folder); goto cleanup; } if( select_folder__(imap, folder)==0 ) { - dc_log_warning(imap->m_context, 0, "Cannot select folder \"%s\".", folder); + dc_log_warning(imap->context, 0, "Cannot select folder \"%s\".", folder); goto cleanup; } /* compare last seen UIDVALIDITY against the current one */ get_config_lastseenuid(imap, folder, &uidvalidity, &lastseenuid); - if( uidvalidity != imap->m_hEtpan->imap_selection_info->sel_uidvalidity ) + if( uidvalidity != imap->hEtpan->imap_selection_info->sel_uidvalidity ) { /* first time this folder is selected or UIDVALIDITY has changed, init lastseenuid and save it to config */ - if( imap->m_hEtpan->imap_selection_info->sel_uidvalidity <= 0 ) { - dc_log_error(imap->m_context, 0, "Cannot get UIDVALIDITY for folder \"%s\".", folder); + if( imap->hEtpan->imap_selection_info->sel_uidvalidity <= 0 ) { + dc_log_error(imap->context, 0, "Cannot get UIDVALIDITY for folder \"%s\".", folder); goto cleanup; } - if( imap->m_hEtpan->imap_selection_info->sel_has_exists ) { - if( imap->m_hEtpan->imap_selection_info->sel_exists <= 0 ) { - dc_log_info(imap->m_context, 0, "Folder \"%s\" is empty.", folder); + if( imap->hEtpan->imap_selection_info->sel_has_exists ) { + if( imap->hEtpan->imap_selection_info->sel_exists <= 0 ) { + dc_log_info(imap->context, 0, "Folder \"%s\" is empty.", folder); goto cleanup; } /* `FETCH (UID)` */ - set = mailimap_set_new_single(imap->m_hEtpan->imap_selection_info->sel_exists); + set = mailimap_set_new_single(imap->hEtpan->imap_selection_info->sel_exists); } else { /* `FETCH * (UID)` - according to RFC 3501, `*` represents the largest message sequence number; if the mailbox is empty, an error resp. an empty list is returned. */ - dc_log_info(imap->m_context, 0, "EXISTS is missing for folder \"%s\", using fallback.", folder); + dc_log_info(imap->context, 0, "EXISTS is missing for folder \"%s\", using fallback.", folder); set = mailimap_set_new_single(0); } - r = mailimap_fetch(imap->m_hEtpan, set, imap->m_fetch_type_uid, &fetch_result); + r = mailimap_fetch(imap->hEtpan, set, imap->fetch_type_uid, &fetch_result); mailimap_set_free(set); if( is_error(imap, r) || fetch_result==NULL || (cur=clist_begin(fetch_result))==NULL ) { - dc_log_info(imap->m_context, 0, "Empty result returned for folder \"%s\".", folder); + dc_log_info(imap->context, 0, "Empty result returned for folder \"%s\".", folder); goto cleanup; /* this might happen if the mailbox is empty an EXISTS does not work */ } @@ -748,7 +748,7 @@ static int fetch_from_single_folder(dc_imap_t* imap, const char* folder) mailimap_fetch_list_free(fetch_result); fetch_result = NULL; if( lastseenuid <= 0 ) { - dc_log_error(imap->m_context, 0, "Cannot get largest UID for folder \"%s\"", folder); + dc_log_error(imap->context, 0, "Cannot get largest UID for folder \"%s\"", folder); goto cleanup; } @@ -758,23 +758,23 @@ static int fetch_from_single_folder(dc_imap_t* imap, const char* folder) } /* store calculated uidvalidity/lastseenuid */ - uidvalidity = imap->m_hEtpan->imap_selection_info->sel_uidvalidity; + uidvalidity = imap->hEtpan->imap_selection_info->sel_uidvalidity; set_config_lastseenuid(imap, folder, uidvalidity, lastseenuid); } /* fetch messages with larger UID than the last one seen (`UID FETCH lastseenuid+1:*)`, see RFC 4549 */ set = mailimap_set_new_interval(lastseenuid+1, 0); - r = mailimap_uid_fetch(imap->m_hEtpan, set, imap->m_fetch_type_uid, &fetch_result); + r = mailimap_uid_fetch(imap->hEtpan, set, imap->fetch_type_uid, &fetch_result); mailimap_set_free(set); if( is_error(imap, r) || fetch_result == NULL ) { fetch_result = NULL; if( r == MAILIMAP_ERROR_PROTOCOL ) { - dc_log_info(imap->m_context, 0, "Folder \"%s\" is empty", folder); + dc_log_info(imap->context, 0, "Folder \"%s\" is empty", folder); goto cleanup; /* the folder is simply empty, this is no error */ } - dc_log_warning(imap->m_context, 0, "Cannot fetch message list from folder \"%s\".", folder); + dc_log_warning(imap->context, 0, "Cannot fetch message list from folder \"%s\".", folder); goto cleanup; } @@ -805,10 +805,10 @@ static int fetch_from_single_folder(dc_imap_t* imap, const char* folder) cleanup: if( read_errors ) { - dc_log_warning(imap->m_context, 0, "%i mails read from \"%s\" with %i errors.", (int)read_cnt, folder, (int)read_errors); + dc_log_warning(imap->context, 0, "%i mails read from \"%s\" with %i errors.", (int)read_cnt, folder, (int)read_errors); } else { - dc_log_info(imap->m_context, 0, "%i mails read from \"%s\".", (int)read_cnt, folder); + dc_log_info(imap->context, 0, "%i mails read from \"%s\".", (int)read_cnt, folder); } if( fetch_result ) { @@ -832,19 +832,19 @@ static int fetch_from_all_folders(dc_imap_t* imap) for( cur = clist_begin(folder_list); cur != NULL ; cur = clist_next(cur) ) { dc_imapfolder_t* folder = (dc_imapfolder_t*)clist_content(cur); - if( folder->m_meaning == MEANING_INBOX ) { - total_cnt += fetch_from_single_folder(imap, folder->m_name_to_select); + if( folder->meaning == MEANING_INBOX ) { + total_cnt += fetch_from_single_folder(imap, folder->name_to_select); } } for( cur = clist_begin(folder_list); cur != NULL ; cur = clist_next(cur) ) { dc_imapfolder_t* folder = (dc_imapfolder_t*)clist_content(cur); - if( folder->m_meaning == MEANING_IGNORE ) { - dc_log_info(imap->m_context, 0, "Ignoring \"%s\".", folder->m_name_utf8); + if( folder->meaning == MEANING_IGNORE ) { + dc_log_info(imap->context, 0, "Ignoring \"%s\".", folder->name_utf8); } - else if( folder->m_meaning != MEANING_INBOX ) { - total_cnt += fetch_from_single_folder(imap, folder->m_name_to_select); + else if( folder->meaning != MEANING_INBOX ) { + total_cnt += fetch_from_single_folder(imap, folder->name_to_select); } } @@ -861,7 +861,7 @@ static int fetch_from_all_folders(dc_imap_t* imap) int dc_imap_fetch(dc_imap_t* imap) { - if( imap==NULL || !imap->m_connected ) { + if( imap==NULL || !imap->connected ) { return 0; } @@ -869,9 +869,9 @@ int dc_imap_fetch(dc_imap_t* imap) #define FULL_FETCH_EVERY_SECONDS (22*60) - if( time(NULL) - imap->m_last_fullread_time > FULL_FETCH_EVERY_SECONDS ) { + if( time(NULL) - imap->last_fullread_time > FULL_FETCH_EVERY_SECONDS ) { fetch_from_all_folders(imap); - imap->m_last_fullread_time = time(NULL); + imap->last_fullread_time = time(NULL); } // as during the fetch commands, new messages may arrive, we fetch until we do not @@ -892,28 +892,28 @@ static void fake_idle(dc_imap_t* imap) time_t fake_idle_start_time = time(NULL), seconds_to_wait; - dc_log_info(imap->m_context, 0, "IMAP-fake-IDLEing..."); + dc_log_info(imap->context, 0, "IMAP-fake-IDLEing..."); int do_fake_idle = 1; while( do_fake_idle ) { // wait a moment: every 5 seconds in the first 3 minutes after a new message, after that every 60 seconds seconds_to_wait = (time(NULL)-fake_idle_start_time < 3*60)? 5 : 60; - pthread_mutex_lock(&imap->m_watch_condmutex); + pthread_mutex_lock(&imap->watch_condmutex); int r = 0; struct timespec wakeup_at; memset(&wakeup_at, 0, sizeof(wakeup_at)); wakeup_at.tv_sec = time(NULL)+seconds_to_wait; - while( imap->m_watch_condflag == 0 && r == 0 ) { - r = pthread_cond_timedwait(&imap->m_watch_cond, &imap->m_watch_condmutex, &wakeup_at); /* unlock mutex -> wait -> lock mutex */ - if( imap->m_watch_condflag ) { + while( imap->watch_condflag == 0 && r == 0 ) { + r = pthread_cond_timedwait(&imap->watch_cond, &imap->watch_condmutex, &wakeup_at); /* unlock mutex -> wait -> lock mutex */ + if( imap->watch_condflag ) { do_fake_idle = 0; } } - imap->m_watch_condflag = 0; + imap->watch_condflag = 0; - pthread_mutex_unlock(&imap->m_watch_condmutex); + pthread_mutex_unlock(&imap->watch_condmutex); if( do_fake_idle == 0 ) { return; @@ -941,29 +941,29 @@ void dc_imap_idle(dc_imap_t* imap) { int r, r2; - if( imap->m_can_idle ) + if( imap->can_idle ) { setup_handle_if_needed__(imap); - if( imap->m_idle_set_up==0 && imap->m_hEtpan && imap->m_hEtpan->imap_stream ) { - r = mailstream_setup_idle(imap->m_hEtpan->imap_stream); + if( imap->idle_set_up==0 && imap->hEtpan && imap->hEtpan->imap_stream ) { + r = mailstream_setup_idle(imap->hEtpan->imap_stream); if( is_error(imap, r) ) { - dc_log_warning(imap->m_context, 0, "IMAP-IDLE: Cannot setup."); + dc_log_warning(imap->context, 0, "IMAP-IDLE: Cannot setup."); fake_idle(imap); return; } - imap->m_idle_set_up = 1; + imap->idle_set_up = 1; } - if( !imap->m_idle_set_up || !select_folder__(imap, "INBOX") ) { - dc_log_warning(imap->m_context, 0, "IMAP-IDLE not setup."); + if( !imap->idle_set_up || !select_folder__(imap, "INBOX") ) { + dc_log_warning(imap->context, 0, "IMAP-IDLE not setup."); fake_idle(imap); return; } - r = mailimap_idle(imap->m_hEtpan); + r = mailimap_idle(imap->hEtpan); if( is_error(imap, r) ) { - dc_log_warning(imap->m_context, 0, "IMAP-IDLE: Cannot start."); + dc_log_warning(imap->context, 0, "IMAP-IDLE: Cannot start."); fake_idle(imap); return; } @@ -973,24 +973,24 @@ void dc_imap_idle(dc_imap_t* imap) // we use a shorter delay to let failed jobs run again from time to time. #define IDLE_DELAY_SECONDS (1*60) - r = mailstream_wait_idle(imap->m_hEtpan->imap_stream, IDLE_DELAY_SECONDS); - r2 = mailimap_idle_done(imap->m_hEtpan); + r = mailstream_wait_idle(imap->hEtpan->imap_stream, IDLE_DELAY_SECONDS); + r2 = mailimap_idle_done(imap->hEtpan); if( r == MAILSTREAM_IDLE_ERROR /*0*/ || r==MAILSTREAM_IDLE_CANCELLED /*4*/ ) { - dc_log_info(imap->m_context, 0, "IMAP-IDLE wait cancelled, r=%i, r2=%i; we'll reconnect soon.", r, r2); - imap->m_should_reconnect = 1; + dc_log_info(imap->context, 0, "IMAP-IDLE wait cancelled, r=%i, r2=%i; we'll reconnect soon.", r, r2); + imap->should_reconnect = 1; } else if( r == MAILSTREAM_IDLE_INTERRUPTED /*1*/ ) { - dc_log_info(imap->m_context, 0, "IMAP-IDLE interrupted."); + dc_log_info(imap->context, 0, "IMAP-IDLE interrupted."); } else if( r == MAILSTREAM_IDLE_HASDATA /*2*/ ) { - dc_log_info(imap->m_context, 0, "IMAP-IDLE has data."); + dc_log_info(imap->context, 0, "IMAP-IDLE has data."); } else if( r == MAILSTREAM_IDLE_TIMEOUT /*3*/ ) { - dc_log_info(imap->m_context, 0, "IMAP-IDLE timeout."); + dc_log_info(imap->context, 0, "IMAP-IDLE timeout."); } else { - dc_log_warning(imap->m_context, 0, "IMAP-IDLE returns unknown value r=%i, r2=%i.", r, r2); + dc_log_warning(imap->context, 0, "IMAP-IDLE returns unknown value r=%i, r2=%i.", r, r2); } } else @@ -1002,23 +1002,23 @@ void dc_imap_idle(dc_imap_t* imap) void dc_imap_interrupt_idle(dc_imap_t* imap) { - if( imap==NULL ) { // imap->m_hEtPan may be NULL - dc_log_warning(imap->m_context, 0, "Interrupt IMAP-IDLE: Bad parameter."); + if( imap==NULL ) { // imap->hEtPan may be NULL + dc_log_warning(imap->context, 0, "Interrupt IMAP-IDLE: Bad parameter."); return; } - if( imap->m_can_idle ) + if( imap->can_idle ) { - if( imap && imap->m_hEtpan && imap->m_hEtpan->imap_stream ) { - mailstream_interrupt_idle(imap->m_hEtpan->imap_stream); + if( imap && imap->hEtpan && imap->hEtpan->imap_stream ) { + mailstream_interrupt_idle(imap->hEtpan->imap_stream); } } // always signal the fake-idle as it may be used if the real-idle is not available for any reasons (no network ...) - pthread_mutex_lock(&imap->m_watch_condmutex); - imap->m_watch_condflag = 1; - pthread_cond_signal(&imap->m_watch_cond); - pthread_mutex_unlock(&imap->m_watch_condmutex); + pthread_mutex_lock(&imap->watch_condmutex); + imap->watch_condflag = 1; + pthread_cond_signal(&imap->watch_cond); + pthread_mutex_unlock(&imap->watch_condmutex); } @@ -1031,62 +1031,62 @@ static int setup_handle_if_needed__(dc_imap_t* imap) { int r, success = 0; - if( imap==NULL || imap->m_imap_server==NULL ) { + if( imap==NULL || imap->imap_server==NULL ) { goto cleanup; } - if( imap->m_should_reconnect ) { + if( imap->should_reconnect ) { unsetup_handle__(imap); } - if( imap->m_hEtpan ) { + if( imap->hEtpan ) { success = 1; goto cleanup; } - if( imap->m_context->m_cb(imap->m_context, DC_EVENT_IS_OFFLINE, 0, 0)!=0 ) { - dc_log_error_if(&imap->m_log_connect_errors, imap->m_context, DC_ERROR_NO_NETWORK, NULL); + if( imap->context->cb(imap->context, DC_EVENT_IS_OFFLINE, 0, 0)!=0 ) { + dc_log_error_if(&imap->log_connect_errors, imap->context, DC_ERROR_NO_NETWORK, NULL); goto cleanup; } - imap->m_hEtpan = mailimap_new(0, NULL); + imap->hEtpan = mailimap_new(0, NULL); - mailimap_set_timeout(imap->m_hEtpan, DC_IMAP_TIMEOUT_SEC); + mailimap_set_timeout(imap->hEtpan, DC_IMAP_TIMEOUT_SEC); - if( imap->m_server_flags&(DC_LP_IMAP_SOCKET_STARTTLS|DC_LP_IMAP_SOCKET_PLAIN) ) + if( imap->server_flags&(DC_LP_IMAP_SOCKET_STARTTLS|DC_LP_IMAP_SOCKET_PLAIN) ) { - r = mailimap_socket_connect(imap->m_hEtpan, imap->m_imap_server, imap->m_imap_port); + r = mailimap_socket_connect(imap->hEtpan, imap->imap_server, imap->imap_port); if( is_error(imap, r) ) { - dc_log_error_if(&imap->m_log_connect_errors, imap->m_context, 0, "Could not connect to IMAP-server %s:%i. (Error #%i)", imap->m_imap_server, (int)imap->m_imap_port, (int)r); + dc_log_error_if(&imap->log_connect_errors, imap->context, 0, "Could not connect to IMAP-server %s:%i. (Error #%i)", imap->imap_server, (int)imap->imap_port, (int)r); goto cleanup; } - if( imap->m_server_flags&DC_LP_IMAP_SOCKET_STARTTLS ) + if( imap->server_flags&DC_LP_IMAP_SOCKET_STARTTLS ) { - r = mailimap_socket_starttls(imap->m_hEtpan); + r = mailimap_socket_starttls(imap->hEtpan); if( is_error(imap, r) ) { - dc_log_error_if(&imap->m_log_connect_errors, imap->m_context, 0, "Could not connect to IMAP-server %s:%i using STARTTLS. (Error #%i)", imap->m_imap_server, (int)imap->m_imap_port, (int)r); + dc_log_error_if(&imap->log_connect_errors, imap->context, 0, "Could not connect to IMAP-server %s:%i using STARTTLS. (Error #%i)", imap->imap_server, (int)imap->imap_port, (int)r); goto cleanup; } - dc_log_info(imap->m_context, 0, "IMAP-server %s:%i STARTTLS-connected.", imap->m_imap_server, (int)imap->m_imap_port); + dc_log_info(imap->context, 0, "IMAP-server %s:%i STARTTLS-connected.", imap->imap_server, (int)imap->imap_port); } else { - dc_log_info(imap->m_context, 0, "IMAP-server %s:%i connected.", imap->m_imap_server, (int)imap->m_imap_port); + dc_log_info(imap->context, 0, "IMAP-server %s:%i connected.", imap->imap_server, (int)imap->imap_port); } } else { - r = mailimap_ssl_connect(imap->m_hEtpan, imap->m_imap_server, imap->m_imap_port); + r = mailimap_ssl_connect(imap->hEtpan, imap->imap_server, imap->imap_port); if( is_error(imap, r) ) { - dc_log_error_if(&imap->m_log_connect_errors, imap->m_context, 0, "Could not connect to IMAP-server %s:%i using SSL. (Error #%i)", imap->m_imap_server, (int)imap->m_imap_port, (int)r); + dc_log_error_if(&imap->log_connect_errors, imap->context, 0, "Could not connect to IMAP-server %s:%i using SSL. (Error #%i)", imap->imap_server, (int)imap->imap_port, (int)r); goto cleanup; } - dc_log_info(imap->m_context, 0, "IMAP-server %s:%i SSL-connected.", imap->m_imap_server, (int)imap->m_imap_port); + dc_log_info(imap->context, 0, "IMAP-server %s:%i SSL-connected.", imap->imap_server, (int)imap->imap_port); } /* TODO: There are more authorisation types, see mailcore2/MCIMAPSession.cpp, however, I'm not sure of they are really all needed */ - /*if( imap->m_server_flags&DC_LP_AUTH_XOAUTH2 ) + /*if( imap->server_flags&DC_LP_AUTH_XOAUTH2 ) { //TODO: Support XOAUTH2, we "just" need to get the token someway. If we do so, there is no more need for the user to enable //https://www.google.com/settings/security/lesssecureapps - however, maybe this is also not needed if the user had enabled 2-factor-authorisation. @@ -1094,21 +1094,21 @@ static int setup_handle_if_needed__(dc_imap_t* imap) r = MAILIMAP_ERROR_STREAM; } else { - r = mailimap_oauth2_authenticate(imap->m_hEtpan, imap->m_imap_use, mOAuth2Token); + r = mailimap_oauth2_authenticate(imap->hEtpan, imap->imap_use, mOAuth2Token); } } else*/ { /* DC_LP_AUTH_NORMAL or no auth flag set */ - r = mailimap_login(imap->m_hEtpan, imap->m_imap_user, imap->m_imap_pw); + r = mailimap_login(imap->hEtpan, imap->imap_user, imap->imap_pw); } if( is_error(imap, r) ) { - dc_log_error_if(&imap->m_log_connect_errors, imap->m_context, 0, "Could not login as %s: %s (Error #%i)", imap->m_imap_user, imap->m_hEtpan->imap_response? imap->m_hEtpan->imap_response : "Unknown error.", (int)r); + dc_log_error_if(&imap->log_connect_errors, imap->context, 0, "Could not login as %s: %s (Error #%i)", imap->imap_user, imap->hEtpan->imap_response? imap->hEtpan->imap_response : "Unknown error.", (int)r); goto cleanup; } - dc_log_info(imap->m_context, 0, "IMAP-login as %s ok.", imap->m_imap_user); + dc_log_info(imap->context, 0, "IMAP-login as %s ok.", imap->imap_user); success = 1; @@ -1117,7 +1117,7 @@ cleanup: unsetup_handle__(imap); } - imap->m_should_reconnect = 0; + imap->should_reconnect = 0; return success; } @@ -1128,27 +1128,27 @@ static void unsetup_handle__(dc_imap_t* imap) return; } - if( imap->m_hEtpan ) + if( imap->hEtpan ) { - if( imap->m_idle_set_up ) { - mailstream_unsetup_idle(imap->m_hEtpan->imap_stream); - imap->m_idle_set_up = 0; + if( imap->idle_set_up ) { + mailstream_unsetup_idle(imap->hEtpan->imap_stream); + imap->idle_set_up = 0; } - if( imap->m_hEtpan->imap_stream != NULL ) { - mailstream_close(imap->m_hEtpan->imap_stream); /* not sure, if this is really needed, however, mailcore2 does the same */ - imap->m_hEtpan->imap_stream = NULL; + if( imap->hEtpan->imap_stream != NULL ) { + mailstream_close(imap->hEtpan->imap_stream); /* not sure, if this is really needed, however, mailcore2 does the same */ + imap->hEtpan->imap_stream = NULL; } - mailimap_free(imap->m_hEtpan); - imap->m_hEtpan = NULL; + mailimap_free(imap->hEtpan); + imap->hEtpan = NULL; - dc_log_info(imap->m_context, 0, "IMAP disconnected."); + dc_log_info(imap->context, 0, "IMAP disconnected."); } - imap->m_selected_folder[0] = 0; + imap->selected_folder[0] = 0; - /* we leave m_sent_folder set; normally this does not change in a normal reconnect; we'll update this folder if we get errors */ + /* we leave sent_folder set; normally this does not change in a normal reconnect; we'll update this folder if we get errors */ } @@ -1159,26 +1159,26 @@ static void unsetup_handle__(dc_imap_t* imap) static void free_connect_param__(dc_imap_t* imap) { - free(imap->m_imap_server); - imap->m_imap_server = NULL; + free(imap->imap_server); + imap->imap_server = NULL; - free(imap->m_imap_user); - imap->m_imap_user = NULL; + free(imap->imap_user); + imap->imap_user = NULL; - free(imap->m_imap_pw); - imap->m_imap_pw = NULL; + free(imap->imap_pw); + imap->imap_pw = NULL; - imap->m_selected_folder[0] = 0; + imap->selected_folder[0] = 0; - free(imap->m_moveto_folder); - imap->m_moveto_folder = NULL; + free(imap->moveto_folder); + imap->moveto_folder = NULL; - free(imap->m_sent_folder); - imap->m_sent_folder = NULL; + free(imap->sent_folder); + imap->sent_folder = NULL; - imap->m_imap_port = 0; - imap->m_can_idle = 0; - imap->m_has_xlist = 0; + imap->imap_port = 0; + imap->can_idle = 0; + imap->has_xlist = 0; } @@ -1186,42 +1186,42 @@ int dc_imap_connect(dc_imap_t* imap, const dc_loginparam_t* lp) { int success = 0; - if( imap==NULL || lp==NULL || lp->m_mail_server==NULL || lp->m_mail_user==NULL || lp->m_mail_pw==NULL ) { + if( imap==NULL || lp==NULL || lp->mail_server==NULL || lp->mail_user==NULL || lp->mail_pw==NULL ) { return 0; } - if( imap->m_connected ) { + if( imap->connected ) { success = 1; goto cleanup; } - imap->m_imap_server = dc_strdup(lp->m_mail_server); - imap->m_imap_port = lp->m_mail_port; - imap->m_imap_user = dc_strdup(lp->m_mail_user); - imap->m_imap_pw = dc_strdup(lp->m_mail_pw); - imap->m_server_flags = lp->m_server_flags; + imap->imap_server = dc_strdup(lp->mail_server); + imap->imap_port = lp->mail_port; + imap->imap_user = dc_strdup(lp->mail_user); + imap->imap_pw = dc_strdup(lp->mail_pw); + imap->server_flags = lp->server_flags; if( !setup_handle_if_needed__(imap) ) { goto cleanup; } /* we set the following flags here and not in setup_handle_if_needed__() as they must not change during connection */ - imap->m_can_idle = mailimap_has_idle(imap->m_hEtpan); - imap->m_has_xlist = mailimap_has_xlist(imap->m_hEtpan); + imap->can_idle = mailimap_has_idle(imap->hEtpan); + imap->has_xlist = mailimap_has_xlist(imap->hEtpan); #ifdef __APPLE__ - imap->m_can_idle = 0; // HACK to force iOS not to work IMAP-IDLE which does not work for now, see also (*) + imap->can_idle = 0; // HACK to force iOS not to work IMAP-IDLE which does not work for now, see also (*) #endif - if( !imap->m_skip_log_capabilities - && imap->m_hEtpan->imap_connection_info && imap->m_hEtpan->imap_connection_info->imap_capability ) + if( !imap->skip_log_capabilities + && imap->hEtpan->imap_connection_info && imap->hEtpan->imap_connection_info->imap_capability ) { /* just log the whole capabilities list (the mailimap_has_*() function also use this list, so this is a good overview on problems) */ - imap->m_skip_log_capabilities = 1; + imap->skip_log_capabilities = 1; dc_strbuilder_t capinfostr; dc_strbuilder_init(&capinfostr, 0); - clist* list = imap->m_hEtpan->imap_connection_info->imap_capability->cap_list; + clist* list = imap->hEtpan->imap_connection_info->imap_capability->cap_list; if( list ) { clistiter* cur; for(cur = clist_begin(list) ; cur != NULL ; cur = clist_next(cur)) { @@ -1232,11 +1232,11 @@ int dc_imap_connect(dc_imap_t* imap, const dc_loginparam_t* lp) } } } - dc_log_info(imap->m_context, 0, "IMAP-capabilities:%s", capinfostr.m_buf); - free(capinfostr.m_buf); + dc_log_info(imap->context, 0, "IMAP-capabilities:%s", capinfostr.buf); + free(capinfostr.buf); } - imap->m_connected = 1; + imap->connected = 1; success = 1; cleanup: @@ -1254,18 +1254,18 @@ void dc_imap_disconnect(dc_imap_t* imap) return; } - if( imap->m_connected ) + if( imap->connected ) { unsetup_handle__(imap); free_connect_param__(imap); - imap->m_connected = 0; + imap->connected = 0; } } int dc_imap_is_connected(dc_imap_t* imap) { - return (imap && imap->m_connected); /* we do not use a LOCK - otherwise, the check may take seconds and is not sufficient for some GUI state updates. */ + return (imap && imap->connected); /* we do not use a LOCK - otherwise, the check may take seconds and is not sufficient for some GUI state updates. */ } @@ -1282,44 +1282,44 @@ dc_imap_t* dc_imap_new(dc_get_config_t get_config, dc_set_config_t set_config, d exit(25); /* cannot allocate little memory, unrecoverable error */ } - imap->m_log_connect_errors = 1; + imap->log_connect_errors = 1; - imap->m_context = context; - imap->m_get_config = get_config; - imap->m_set_config = set_config; - imap->m_receive_imf = receive_imf; - imap->m_userData = userData; + imap->context = context; + imap->get_config = get_config; + imap->set_config = set_config; + imap->receive_imf = receive_imf; + imap->userData = userData; - pthread_mutex_init(&imap->m_watch_condmutex, NULL); - pthread_cond_init(&imap->m_watch_cond, NULL); + pthread_mutex_init(&imap->watch_condmutex, NULL); + pthread_cond_init(&imap->watch_cond, NULL); - //imap->m_enter_watch_wait_time = 0; + //imap->enter_watch_wait_time = 0; - imap->m_selected_folder = calloc(1, 1); - imap->m_moveto_folder = NULL; - imap->m_sent_folder = NULL; + imap->selected_folder = calloc(1, 1); + imap->moveto_folder = NULL; + imap->sent_folder = NULL; /* create some useful objects */ - imap->m_fetch_type_uid = mailimap_fetch_type_new_fetch_att_list_empty(); /* object to fetch the ID */ - mailimap_fetch_type_new_fetch_att_list_add(imap->m_fetch_type_uid, mailimap_fetch_att_new_uid()); + imap->fetch_type_uid = mailimap_fetch_type_new_fetch_att_list_empty(); /* object to fetch the ID */ + mailimap_fetch_type_new_fetch_att_list_add(imap->fetch_type_uid, mailimap_fetch_att_new_uid()); - imap->m_fetch_type_message_id = mailimap_fetch_type_new_fetch_att_list_empty(); - mailimap_fetch_type_new_fetch_att_list_add(imap->m_fetch_type_message_id, mailimap_fetch_att_new_envelope()); + imap->fetch_type_message_id = mailimap_fetch_type_new_fetch_att_list_empty(); + mailimap_fetch_type_new_fetch_att_list_add(imap->fetch_type_message_id, mailimap_fetch_att_new_envelope()); /*clist* hdrlist = clist_new(); clist_append(hdrlist, strdup("Message-ID")); struct mailimap_header_list* imap_hdrlist = mailimap_header_list_new(hdrlist); struct mailimap_section* section = mailimap_section_new_header_fields(imap_hdrlist); struct mailimap_fetch_att* fetch_att = mailimap_fetch_att_new_body_peek_section(section); - mailimap_fetch_type_new_fetch_att_list_add(imap->m_fetch_type_message_id, fetch_att);*/ + mailimap_fetch_type_new_fetch_att_list_add(imap->fetch_type_message_id, fetch_att);*/ - imap->m_fetch_type_body = mailimap_fetch_type_new_fetch_att_list_empty(); /* object to fetch flags+body */ - mailimap_fetch_type_new_fetch_att_list_add(imap->m_fetch_type_body, mailimap_fetch_att_new_flags()); - mailimap_fetch_type_new_fetch_att_list_add(imap->m_fetch_type_body, mailimap_fetch_att_new_body_peek_section(mailimap_section_new(NULL))); + imap->fetch_type_body = mailimap_fetch_type_new_fetch_att_list_empty(); /* object to fetch flags+body */ + mailimap_fetch_type_new_fetch_att_list_add(imap->fetch_type_body, mailimap_fetch_att_new_flags()); + mailimap_fetch_type_new_fetch_att_list_add(imap->fetch_type_body, mailimap_fetch_att_new_body_peek_section(mailimap_section_new(NULL))); - imap->m_fetch_type_flags = mailimap_fetch_type_new_fetch_att_list_empty(); /* object to fetch flags only */ - mailimap_fetch_type_new_fetch_att_list_add(imap->m_fetch_type_flags, mailimap_fetch_att_new_flags()); + imap->fetch_type_flags = mailimap_fetch_type_new_fetch_att_list_empty(); /* object to fetch flags only */ + mailimap_fetch_type_new_fetch_att_list_add(imap->fetch_type_flags, mailimap_fetch_att_new_flags()); return imap; } @@ -1333,14 +1333,14 @@ void dc_imap_unref(dc_imap_t* imap) dc_imap_disconnect(imap); - pthread_cond_destroy(&imap->m_watch_cond); - pthread_mutex_destroy(&imap->m_watch_condmutex); + pthread_cond_destroy(&imap->watch_cond); + pthread_mutex_destroy(&imap->watch_condmutex); - free(imap->m_selected_folder); + free(imap->selected_folder); - if( imap->m_fetch_type_uid ) { mailimap_fetch_type_free(imap->m_fetch_type_uid); } - if( imap->m_fetch_type_body ) { mailimap_fetch_type_free(imap->m_fetch_type_body); } - if( imap->m_fetch_type_flags ){ mailimap_fetch_type_free(imap->m_fetch_type_flags);} + if( imap->fetch_type_uid ) { mailimap_fetch_type_free(imap->fetch_type_uid); } + if( imap->fetch_type_body ) { mailimap_fetch_type_free(imap->fetch_type_body); } + if( imap->fetch_type_flags ){ mailimap_fetch_type_free(imap->fetch_type_flags);} free(imap); } @@ -1359,20 +1359,20 @@ int dc_imap_append_msg(dc_imap_t* imap, time_t timestamp, const char* data_not_t goto cleanup; } - if( imap->m_hEtpan==NULL ) { + if( imap->hEtpan==NULL ) { goto cleanup; } - dc_log_info(imap->m_context, 0, "Appending message to IMAP-server..."); + dc_log_info(imap->context, 0, "Appending message to IMAP-server..."); if( !init_chat_folders__(imap) ) { - dc_log_error_if(&imap->m_log_connect_errors, imap->m_context, 0, "Cannot find out IMAP-sent-folder."); + dc_log_error_if(&imap->log_connect_errors, imap->context, 0, "Cannot find out IMAP-sent-folder."); goto cleanup; } - if( !select_folder__(imap, imap->m_sent_folder) ) { - dc_log_error_if(&imap->m_log_connect_errors, imap->m_context, 0, "Cannot select IMAP-folder \"%s\".", imap->m_sent_folder); - imap->m_sent_folder[0] = 0; /* force re-init */ + if( !select_folder__(imap, imap->sent_folder) ) { + dc_log_error_if(&imap->log_connect_errors, imap->context, 0, "Cannot select IMAP-folder \"%s\".", imap->sent_folder); + imap->sent_folder[0] = 0; /* force re-init */ goto cleanup; } @@ -1381,19 +1381,19 @@ int dc_imap_append_msg(dc_imap_t* imap, time_t timestamp, const char* data_not_t imap_date = dc_timestamp_to_mailimap_date_time(timestamp); if( imap_date == NULL ) { - dc_log_error(imap->m_context, 0, "Bad date."); + dc_log_error(imap->context, 0, "Bad date."); goto cleanup; } - r = mailimap_uidplus_append(imap->m_hEtpan, imap->m_sent_folder, flag_list, imap_date, data_not_terminated, data_bytes, &ret_uidvalidity, ret_server_uid); + r = mailimap_uidplus_append(imap->hEtpan, imap->sent_folder, flag_list, imap_date, data_not_terminated, data_bytes, &ret_uidvalidity, ret_server_uid); if( is_error(imap, r) ) { - dc_log_error_if(&imap->m_log_connect_errors, imap->m_context, 0, "Cannot append message to \"%s\", error #%i.", imap->m_sent_folder, (int)r); + dc_log_error_if(&imap->log_connect_errors, imap->context, 0, "Cannot append message to \"%s\", error #%i.", imap->sent_folder, (int)r); goto cleanup; } - *ret_server_folder = dc_strdup(imap->m_sent_folder); + *ret_server_folder = dc_strdup(imap->sent_folder); - dc_log_info(imap->m_context, 0, "Message appended to \"%s\".", imap->m_sent_folder); + dc_log_info(imap->context, 0, "Message appended to \"%s\".", imap->sent_folder); success = 1; @@ -1418,7 +1418,7 @@ static int add_flag__(dc_imap_t* imap, uint32_t server_uid, struct mailimap_flag struct mailimap_store_att_flags* store_att_flags = NULL; struct mailimap_set* set = mailimap_set_new_single(server_uid); - if( imap==NULL || imap->m_hEtpan==NULL ) { + if( imap==NULL || imap->hEtpan==NULL ) { goto cleanup; } @@ -1427,7 +1427,7 @@ static int add_flag__(dc_imap_t* imap, uint32_t server_uid, struct mailimap_flag store_att_flags = mailimap_store_att_flags_new_add_flags(flag_list); /* FLAGS.SILENT does not return the new value */ - r = mailimap_uid_store(imap->m_hEtpan, set, store_att_flags); + r = mailimap_uid_store(imap->hEtpan, set, store_att_flags); if( is_error(imap, r) ) { goto cleanup; } @@ -1439,7 +1439,7 @@ cleanup: if( set ) { mailimap_set_free(set); } - return imap->m_should_reconnect? 0 : 1; /* all non-connection states are treated as success - the mail may already be deleted or moved away on the server */ + return imap->should_reconnect? 0 : 1; /* all non-connection states are treated as success - the mail may already be deleted or moved away on the server */ } @@ -1460,32 +1460,32 @@ int dc_imap_markseen_msg(dc_imap_t* imap, const char* folder, uint32_t server_ui goto cleanup; } - if( imap->m_hEtpan==NULL ) { + if( imap->hEtpan==NULL ) { goto cleanup; } - dc_log_info(imap->m_context, 0, "Marking message %s/%i as seen...", folder, (int)server_uid); + dc_log_info(imap->context, 0, "Marking message %s/%i as seen...", folder, (int)server_uid); if( select_folder__(imap, folder)==0 ) { - dc_log_warning(imap->m_context, 0, "Cannot select folder."); + dc_log_warning(imap->context, 0, "Cannot select folder."); goto cleanup; } if( add_flag__(imap, server_uid, mailimap_flag_new_seen())==0 ) { - dc_log_warning(imap->m_context, 0, "Cannot mark message as seen."); + dc_log_warning(imap->context, 0, "Cannot mark message as seen."); goto cleanup; } - dc_log_info(imap->m_context, 0, "Message marked as seen."); + dc_log_info(imap->context, 0, "Message marked as seen."); if( (ms_flags&DC_MS_SET_MDNSent_FLAG) - && imap->m_hEtpan->imap_selection_info!=NULL && imap->m_hEtpan->imap_selection_info->sel_perm_flags!=NULL ) + && imap->hEtpan->imap_selection_info!=NULL && imap->hEtpan->imap_selection_info->sel_perm_flags!=NULL ) { /* Check if the folder can handle the `$MDNSent` flag (see RFC 3503). If so, and not set: set the flags and return this information. If the folder cannot handle the `$MDNSent` flag, we risk duplicated MDNs; it's up to the receiving MUA to handle this then (eg. Delta Chat has no problem with this). */ int can_create_flag = 0; clistiter* iter; - for( iter=clist_begin(imap->m_hEtpan->imap_selection_info->sel_perm_flags); iter!=NULL; iter=clist_next(iter) ) + for( iter=clist_begin(imap->hEtpan->imap_selection_info->sel_perm_flags); iter!=NULL; iter=clist_next(iter) ) { struct mailimap_flag_perm* fp = (struct mailimap_flag_perm*)clist_content(iter); if( fp ) { @@ -1506,7 +1506,7 @@ int dc_imap_markseen_msg(dc_imap_t* imap, const char* folder, uint32_t server_ui if( can_create_flag ) { clist* fetch_result = NULL; - r = mailimap_uid_fetch(imap->m_hEtpan, set, imap->m_fetch_type_flags, &fetch_result); + r = mailimap_uid_fetch(imap->hEtpan, set, imap->fetch_type_flags, &fetch_result); if( !is_error(imap, r) && fetch_result ) { clistiter* cur=clist_begin(fetch_result); if( cur ) { @@ -1517,49 +1517,49 @@ int dc_imap_markseen_msg(dc_imap_t* imap, const char* folder, uint32_t server_ui } mailimap_fetch_list_free(fetch_result); } - dc_log_info(imap->m_context, 0, ((*ret_ms_flags)&DC_MS_MDNSent_JUST_SET)? "$MDNSent just set and MDN will be sent." : "$MDNSent already set and MDN already sent."); + dc_log_info(imap->context, 0, ((*ret_ms_flags)&DC_MS_MDNSent_JUST_SET)? "$MDNSent just set and MDN will be sent." : "$MDNSent already set and MDN already sent."); } else { *ret_ms_flags |= DC_MS_MDNSent_JUST_SET; - dc_log_info(imap->m_context, 0, "Cannot store $MDNSent flags, risk sending duplicate MDN."); + dc_log_info(imap->context, 0, "Cannot store $MDNSent flags, risk sending duplicate MDN."); } } - if( (ms_flags&DC_MS_ALSO_MOVE) && (imap->m_server_flags&DC_NO_MOVE_TO_CHATS)==0 ) + if( (ms_flags&DC_MS_ALSO_MOVE) && (imap->server_flags&DC_NO_MOVE_TO_CHATS)==0 ) { init_chat_folders__(imap); - if( imap->m_moveto_folder && strcmp(folder, imap->m_moveto_folder)==0 ) + if( imap->moveto_folder && strcmp(folder, imap->moveto_folder)==0 ) { - dc_log_info(imap->m_context, 0, "Message %s/%i is already in %s...", folder, (int)server_uid, imap->m_moveto_folder); + dc_log_info(imap->context, 0, "Message %s/%i is already in %s...", folder, (int)server_uid, imap->moveto_folder); /* avoid deadlocks as moving messages in the same folder may be result in a new server_uid and the state "fresh" - we will catch these messages again on the next poll, try to move them away and so on, see also (***) in dc_receive_imf.c */ } - else if( imap->m_moveto_folder ) + else if( imap->moveto_folder ) { - dc_log_info(imap->m_context, 0, "Moving message %s/%i to %s...", folder, (int)server_uid, imap->m_moveto_folder); + dc_log_info(imap->context, 0, "Moving message %s/%i to %s...", folder, (int)server_uid, imap->moveto_folder); /* TODO/TOCHECK: MOVE may not be supported on servers, if this is often the case, we should fallback to a COPY/DELETE implementation. Same for the UIDPLUS extension (if in doubt, we can find out the resulting UID using "imap_selection_info->sel_uidnext" then). */ uint32_t res_uid = 0; struct mailimap_set* res_setsrc = NULL; struct mailimap_set* res_setdest = NULL; - r = mailimap_uidplus_uid_move(imap->m_hEtpan, set, imap->m_moveto_folder, &res_uid, &res_setsrc, &res_setdest); /* the correct folder is already selected in add_flag__() above */ + r = mailimap_uidplus_uid_move(imap->hEtpan, set, imap->moveto_folder, &res_uid, &res_setsrc, &res_setdest); /* the correct folder is already selected in add_flag__() above */ if( is_error(imap, r) ) { - dc_log_info(imap->m_context, 0, "Cannot move message, fallback to COPY/DELETE %s/%i to %s...", folder, (int)server_uid, imap->m_moveto_folder); - r = mailimap_uidplus_uid_copy(imap->m_hEtpan, set, imap->m_moveto_folder, &res_uid, &res_setsrc, &res_setdest); + dc_log_info(imap->context, 0, "Cannot move message, fallback to COPY/DELETE %s/%i to %s...", folder, (int)server_uid, imap->moveto_folder); + r = mailimap_uidplus_uid_copy(imap->hEtpan, set, imap->moveto_folder, &res_uid, &res_setsrc, &res_setdest); if (is_error(imap, r)) { - dc_log_info(imap->m_context, 0, "Cannot copy message. Leaving in INBOX"); + dc_log_info(imap->context, 0, "Cannot copy message. Leaving in INBOX"); goto cleanup; } else { - dc_log_info(imap->m_context, 0, "Deleting msg ..."); + dc_log_info(imap->context, 0, "Deleting msg ..."); if( add_flag__(imap, server_uid, mailimap_flag_new_deleted())==0 ) { - dc_log_warning(imap->m_context, 0, "Cannot mark message as \"Deleted\".");/* maybe the message is already deleted */ + dc_log_warning(imap->context, 0, "Cannot mark message as \"Deleted\".");/* maybe the message is already deleted */ } /* force an EXPUNGE resp. CLOSE for the selected folder */ - imap->m_selected_folder_needs_expunge = 1; + imap->selected_folder_needs_expunge = 1; } } @@ -1574,7 +1574,7 @@ int dc_imap_markseen_msg(dc_imap_t* imap, const char* folder, uint32_t server_ui struct mailimap_set_item* item; item = clist_content(cur); *ret_server_uid = item->set_first; - *ret_server_folder = dc_strdup(imap->m_moveto_folder); + *ret_server_folder = dc_strdup(imap->moveto_folder); } mailimap_set_free(res_setdest); } @@ -1582,7 +1582,7 @@ int dc_imap_markseen_msg(dc_imap_t* imap, const char* folder, uint32_t server_ui // TODO: If the new UID is equal to lastuid.Chats, we should increase lastuid.Chats by one // (otherwise, we'll download the mail in moment again from the chats folder ...) - dc_log_info(imap->m_context, 0, "Message moved."); + dc_log_info(imap->context, 0, "Message moved."); } } @@ -1590,7 +1590,7 @@ cleanup: if( set ) { mailimap_set_free(set); } - return imap->m_should_reconnect? 0 : 1; + return imap->should_reconnect? 0 : 1; } @@ -1606,10 +1606,10 @@ int dc_imap_delete_msg(dc_imap_t* imap, const char* rfc724_mid, const char* fold goto cleanup; } - dc_log_info(imap->m_context, 0, "Marking message \"%s\", %s/%i for deletion...", rfc724_mid, folder, (int)server_uid); + dc_log_info(imap->context, 0, "Marking message \"%s\", %s/%i for deletion...", rfc724_mid, folder, (int)server_uid); if( select_folder__(imap, folder)==0 ) { - dc_log_warning(imap->m_context, 0, "Cannot select folder \"%s\".", folder); /* maybe the folder does no longer exist */ + dc_log_warning(imap->context, 0, "Cannot select folder \"%s\".", folder); /* maybe the folder does no longer exist */ goto cleanup; } @@ -1622,7 +1622,7 @@ int dc_imap_delete_msg(dc_imap_t* imap, const char* rfc724_mid, const char* fold clistiter* cur = NULL; const char* is_quoted_rfc724_mid = NULL; struct mailimap_set* set = mailimap_set_new_single(server_uid); - r = mailimap_uid_fetch(imap->m_hEtpan, set, imap->m_fetch_type_message_id, &fetch_result); + r = mailimap_uid_fetch(imap->hEtpan, set, imap->fetch_type_message_id, &fetch_result); mailimap_set_free(set); if( is_error(imap, r) || fetch_result == NULL || (cur=clist_begin(fetch_result)) == NULL @@ -1630,7 +1630,7 @@ int dc_imap_delete_msg(dc_imap_t* imap, const char* rfc724_mid, const char* fold || (is_rfc724_mid=unquote_rfc724_mid(is_quoted_rfc724_mid))==NULL || strcmp(is_rfc724_mid, rfc724_mid)!=0 ) { - dc_log_warning(imap->m_context, 0, "UID not found in the given folder or does not match Message-ID."); + dc_log_warning(imap->context, 0, "UID not found in the given folder or does not match Message-ID."); server_uid = 0; } } @@ -1638,23 +1638,23 @@ int dc_imap_delete_msg(dc_imap_t* imap, const char* rfc724_mid, const char* fold /* server_uid is 0 now if it was not given or if it does not match the given message id; try to search for it in all folders (the message may be moved by another MUA to a folder we do not sync or the sync is a moment ago) */ if( server_uid == 0 ) { - dc_log_info(imap->m_context, 0, "Searching UID by Message-ID \"%s\"...", rfc724_mid); + dc_log_info(imap->context, 0, "Searching UID by Message-ID \"%s\"...", rfc724_mid); if( (server_uid=search_uid__(imap, rfc724_mid))==0 ) { - dc_log_warning(imap->m_context, 0, "Message-ID \"%s\" not found in any folder, cannot delete message.", rfc724_mid); + dc_log_warning(imap->context, 0, "Message-ID \"%s\" not found in any folder, cannot delete message.", rfc724_mid); goto cleanup; } - dc_log_info(imap->m_context, 0, "Message-ID \"%s\" found in %s/%i", rfc724_mid, imap->m_selected_folder, server_uid); + dc_log_info(imap->context, 0, "Message-ID \"%s\" found in %s/%i", rfc724_mid, imap->selected_folder, server_uid); } /* mark the message for deletion */ if( add_flag__(imap, server_uid, mailimap_flag_new_deleted())==0 ) { - dc_log_warning(imap->m_context, 0, "Cannot mark message as \"Deleted\"."); /* maybe the message is already deleted */ + dc_log_warning(imap->context, 0, "Cannot mark message as \"Deleted\"."); /* maybe the message is already deleted */ goto cleanup; } /* force an EXPUNGE resp. CLOSE for the selected folder */ - imap->m_selected_folder_needs_expunge = 1; + imap->selected_folder_needs_expunge = 1; success = 1; diff --git a/src/dc_imap.h b/src/dc_imap.h index 0b8566de..4eed6fe0 100644 --- a/src/dc_imap.h +++ b/src/dc_imap.h @@ -50,47 +50,45 @@ typedef struct dc_imap_t { /** @privatesection */ - char* m_imap_server; - int m_imap_port; - char* m_imap_user; - char* m_imap_pw; - int m_server_flags; + char* imap_server; + int imap_port; + char* imap_user; + char* imap_pw; + int server_flags; - int m_connected; - mailimap* m_hEtpan; /* normally, if connected, m_hEtpan is also set; however, if a reconnection is required, we may lost this handle */ + int connected; + mailimap* hEtpan; /* normally, if connected, hEtpan is also set; however, if a reconnection is required, we may lost this handle */ - time_t m_last_fullread_time; + time_t last_fullread_time; - int m_idle_set_up; - char* m_selected_folder; - int m_selected_folder_needs_expunge; - int m_should_reconnect; + int idle_set_up; + char* selected_folder; + int selected_folder_needs_expunge; + int should_reconnect; - int m_can_idle; - int m_has_xlist; - char* m_moveto_folder;// Folder, where reveived chat messages should go to. Normally DC_CHATS_FOLDER, may be NULL to leave them in the INBOX - char* m_sent_folder; // Folder, where send messages should go to. Normally DC_CHATS_FOLDER. - char m_imap_delimiter;/* IMAP Path separator. Set as a side-effect in list_folders__ */ + int can_idle; + int has_xlist; + char* moveto_folder;// Folder, where reveived chat messages should go to. Normally DC_CHATS_FOLDER, may be NULL to leave them in the INBOX + char* sent_folder; // Folder, where send messages should go to. Normally DC_CHATS_FOLDER. + char imap_delimiter;/* IMAP Path separator. Set as a side-effect in list_folders__ */ - pthread_cond_t m_watch_cond; - pthread_mutex_t m_watch_condmutex; - int m_watch_condflag; + pthread_cond_t watch_cond; + pthread_mutex_t watch_condmutex; + int watch_condflag; - //time_t m_enter_watch_wait_time; + struct mailimap_fetch_type* fetch_type_uid; + struct mailimap_fetch_type* fetch_type_message_id; + struct mailimap_fetch_type* fetch_type_body; + struct mailimap_fetch_type* fetch_type_flags; - struct mailimap_fetch_type* m_fetch_type_uid; - struct mailimap_fetch_type* m_fetch_type_message_id; - struct mailimap_fetch_type* m_fetch_type_body; - struct mailimap_fetch_type* m_fetch_type_flags; + dc_get_config_t get_config; + dc_set_config_t set_config; + dc_receive_imf_t receive_imf; + void* userData; + dc_context_t* context; - dc_get_config_t m_get_config; - dc_set_config_t m_set_config; - dc_receive_imf_t m_receive_imf; - void* m_userData; - dc_context_t* m_context; - - int m_log_connect_errors; - int m_skip_log_capabilities; + int log_connect_errors; + int skip_log_capabilities; } dc_imap_t; diff --git a/src/dc_imex.c b/src/dc_imex.c index cacb9051..ab7142d0 100644 --- a/src/dc_imex.c +++ b/src/dc_imex.c @@ -119,7 +119,7 @@ char* dc_render_setup_file(dc_context_t* context, const char* passphrase) char* ret_setupfilecontent = NULL; - if( context==NULL || context->m_magic != DC_CONTEXT_MAGIC || passphrase==NULL + if( context==NULL || context->magic != DC_CONTEXT_MAGIC || passphrase==NULL || strlen(passphrase)<2 || curr_private_key==NULL ) { goto cleanup; } @@ -134,10 +134,10 @@ char* dc_render_setup_file(dc_context_t* context, const char* passphrase) } { - self_addr = dc_sqlite3_get_config(context->m_sql, "configured_addr", NULL); - dc_key_load_self_private(curr_private_key, self_addr, context->m_sql); + self_addr = dc_sqlite3_get_config(context->sql, "configured_addr", NULL); + dc_key_load_self_private(curr_private_key, self_addr, context->sql); - char* payload_key_asc = dc_key_render_asc(curr_private_key, context->m_e2ee_enabled? "Autocrypt-Prefer-Encrypt: mutual\r\n" : NULL); + char* payload_key_asc = dc_key_render_asc(curr_private_key, context->e2ee_enabled? "Autocrypt-Prefer-Encrypt: mutual\r\n" : NULL); if( payload_key_asc == NULL ) { goto cleanup; } @@ -379,7 +379,7 @@ char* dc_create_setup_code(dc_context_t* context) dc_strbuilder_catf(&ret, "%s%04i", i?"-":"", (int)random_val); } - return ret.m_buf; + return ret.buf; } @@ -398,7 +398,7 @@ char* dc_normalize_setup_code(dc_context_t* context, const char* in) while( *p1 ) { if( *p1 >= '0' && *p1 <= '9' ) { dc_strbuilder_catf(&out, "%c", *p1); - outlen = strlen(out.m_buf); + outlen = strlen(out.buf); if( outlen==4 || outlen==9 || outlen==14 || outlen==19 || outlen==24 || outlen == 29 || outlen == 34 || outlen == 39 ) { dc_strbuilder_cat(&out, "-"); } @@ -406,7 +406,7 @@ char* dc_normalize_setup_code(dc_context_t* context, const char* in) p1++; } - return out.m_buf; + return out.buf; } @@ -468,7 +468,7 @@ char* dc_initiate_key_transfer(dc_context_t* context) if( !dc_alloc_ongoing(context) ) { return 0; /* no cleanup as this would call dc_free_ongoing() */ } - #define CHECK_EXIT if( context->m_shall_stop_ongoing ) { goto cleanup; } + #define CHECK_EXIT if( context->shall_stop_ongoing ) { goto cleanup; } if( (setup_code=dc_create_setup_code(context)) == NULL ) { /* this may require a keypair to be created. this may take a second ... */ goto cleanup; @@ -482,7 +482,7 @@ char* dc_initiate_key_transfer(dc_context_t* context) CHECK_EXIT - if( (setup_file_name=dc_get_fine_pathNfilename(context->m_blobdir, "autocrypt-setup-message.html")) == NULL + if( (setup_file_name=dc_get_fine_pathNfilename(context->blobdir, "autocrypt-setup-message.html")) == NULL || !dc_write_file(setup_file_name, setup_file_content, strlen(setup_file_content), context) ) { goto cleanup; } @@ -492,11 +492,11 @@ char* dc_initiate_key_transfer(dc_context_t* context) } msg = dc_msg_new(); - msg->m_type = DC_MSG_FILE; - dc_param_set (msg->m_param, DC_PARAM_FILE, setup_file_name); - dc_param_set (msg->m_param, DC_PARAM_MIMETYPE, "application/autocrypt-setup"); - dc_param_set_int(msg->m_param, DC_PARAM_CMD, DC_CMD_AUTOCRYPT_SETUP_MESSAGE); - dc_param_set_int(msg->m_param, DC_PARAM_FORCE_PLAINTEXT, DC_FP_NO_AUTOCRYPT_HEADER); + msg->type = DC_MSG_FILE; + dc_param_set (msg->param, DC_PARAM_FILE, setup_file_name); + dc_param_set (msg->param, DC_PARAM_MIMETYPE, "application/autocrypt-setup"); + dc_param_set_int(msg->param, DC_PARAM_CMD, DC_CMD_AUTOCRYPT_SETUP_MESSAGE); + dc_param_set_int(msg->param, DC_PARAM_FORCE_PLAINTEXT, DC_FP_NO_AUTOCRYPT_HEADER); CHECK_EXIT @@ -563,19 +563,19 @@ static int set_self_key(dc_context_t* context, const char* armored, int set_defa } /* add keypair; before this, delete other keypairs with the same binary key and reset defaults */ - stmt = dc_sqlite3_prepare(context->m_sql, "DELETE FROM keypairs WHERE public_key=? OR private_key=?;"); - sqlite3_bind_blob (stmt, 1, public_key->m_binary, public_key->m_bytes, SQLITE_STATIC); - sqlite3_bind_blob (stmt, 2, private_key->m_binary, private_key->m_bytes, SQLITE_STATIC); + stmt = dc_sqlite3_prepare(context->sql, "DELETE FROM keypairs WHERE public_key=? OR private_key=?;"); + sqlite3_bind_blob (stmt, 1, public_key->binary, public_key->bytes, SQLITE_STATIC); + sqlite3_bind_blob (stmt, 2, private_key->binary, private_key->bytes, SQLITE_STATIC); sqlite3_step(stmt); sqlite3_finalize(stmt); stmt = NULL; if( set_default ) { - dc_sqlite3_execute(context->m_sql, "UPDATE keypairs SET is_default=0;"); /* if the new key should be the default key, all other should not */ + dc_sqlite3_execute(context->sql, "UPDATE keypairs SET is_default=0;"); /* if the new key should be the default key, all other should not */ } - self_addr = dc_sqlite3_get_config(context->m_sql, "configured_addr", NULL); - if( !dc_key_save_self_keypair(public_key, private_key, self_addr, set_default, context->m_sql) ) { + self_addr = dc_sqlite3_get_config(context->sql, "configured_addr", NULL); + if( !dc_key_save_self_keypair(public_key, private_key, self_addr, set_default, context->sql) ) { dc_log_error(context, 0, "Cannot save keypair."); goto cleanup; } @@ -632,7 +632,7 @@ int dc_continue_key_transfer(dc_context_t* context, uint32_t msg_id, const char* char* armored_key = NULL; char* norm_sc = NULL; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || msg_id <= DC_MSG_ID_LAST_SPECIAL || setup_code == NULL ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || msg_id <= DC_MSG_ID_LAST_SPECIAL || setup_code == NULL ) { goto cleanup; } @@ -642,7 +642,7 @@ int dc_continue_key_transfer(dc_context_t* context, uint32_t msg_id, const char* goto cleanup; } - if( !dc_read_file(filename, (void**)&filecontent, &filebytes, msg->m_context) || filecontent == NULL || filebytes <= 0 ) { + if( !dc_read_file(filename, (void**)&filecontent, &filebytes, msg->context) || filecontent == NULL || filebytes <= 0 ) { dc_log_error(context, 0, "Cannot read Autocrypt Setup Message file."); goto cleanup; } @@ -682,15 +682,15 @@ static void export_key_to_asc_file(dc_context_t* context, const char* dir, int i { char* file_name; if( is_default ) { - file_name = dc_mprintf("%s/%s-key-default.asc", dir, key->m_type==DC_KEY_PUBLIC? "public" : "private"); + file_name = dc_mprintf("%s/%s-key-default.asc", dir, key->type==DC_KEY_PUBLIC? "public" : "private"); } else { - file_name = dc_mprintf("%s/%s-key-%i.asc", dir, key->m_type==DC_KEY_PUBLIC? "public" : "private", id); + file_name = dc_mprintf("%s/%s-key-%i.asc", dir, key->type==DC_KEY_PUBLIC? "public" : "private", id); } dc_log_info(context, 0, "Exporting key %s", file_name); dc_delete_file(file_name, context); if( dc_key_render_asc_to_file(key, file_name, context) ) { - context->m_cb(context, DC_EVENT_IMEX_FILE_WRITTEN, (uintptr_t)file_name, 0); + context->cb(context, DC_EVENT_IMEX_FILE_WRITTEN, (uintptr_t)file_name, 0); dc_log_error(context, 0, "Cannot write key to %s", file_name); } free(file_name); @@ -705,7 +705,7 @@ static int export_self_keys(dc_context_t* context, const char* dir) dc_key_t* public_key = dc_key_new(); dc_key_t* private_key = dc_key_new(); - if( (stmt=dc_sqlite3_prepare(context->m_sql, "SELECT id, public_key, private_key, is_default FROM keypairs;"))==NULL ) { + if( (stmt=dc_sqlite3_prepare(context->sql, "SELECT id, public_key, private_key, is_default FROM keypairs;"))==NULL ) { goto cleanup; } @@ -754,7 +754,7 @@ static int import_self_keys(dc_context_t* context, const char* dir_name) char* buf2 = NULL; const char* buf2_headerline; // a pointer inside buf2, MUST NOT be free()'d - if( context==NULL || context->m_magic != DC_CONTEXT_MAGIC || dir_name==NULL ) { + if( context==NULL || context->magic != DC_CONTEXT_MAGIC || dir_name==NULL ) { goto cleanup; } if( (dir_handle=opendir(dir_name))==NULL ) { @@ -835,7 +835,7 @@ The macro avoids weird values of 0% or 100% while still working. */ int permille = (processed_files_count*1000)/total_files_count; \ if( permille < 10 ) { permille = 10; } \ if( permille > 990 ) { permille = 990; } \ - context->m_cb(context, DC_EVENT_IMEX_PROGRESS, permille, 0); + context->cb(context, DC_EVENT_IMEX_PROGRESS, permille, 0); static int export_backup(dc_context_t* context, const char* dir) @@ -869,15 +869,15 @@ static int export_backup(dc_context_t* context, const char* dir) } /* temporary lock and close the source (we just make a copy of the whole file, this is the fastest and easiest approach) */ - dc_sqlite3_close__(context->m_sql); + dc_sqlite3_close__(context->sql); closed = 1; - dc_log_info(context, 0, "Backup \"%s\" to \"%s\".", context->m_dbfile, dest_pathNfilename); - if( !dc_copy_file(context->m_dbfile, dest_pathNfilename, context) ) { + dc_log_info(context, 0, "Backup \"%s\" to \"%s\".", context->dbfile, dest_pathNfilename); + if( !dc_copy_file(context->dbfile, dest_pathNfilename, context) ) { goto cleanup; /* error already logged */ } - dc_sqlite3_open__(context->m_sql, context->m_dbfile, 0); + dc_sqlite3_open__(context->sql, context->dbfile, 0); closed = 0; /* add all files as blobs to the database copy (this does not require the source to be locked, neigher the destination as it is used only here) */ @@ -894,8 +894,8 @@ static int export_backup(dc_context_t* context, const char* dir) /* scan directory, pass 1: collect file info */ total_files_count = 0; - if( (dir_handle=opendir(context->m_blobdir))==NULL ) { - dc_log_error(context, 0, "Backup: Cannot get info for blob-directory \"%s\".", context->m_blobdir); + if( (dir_handle=opendir(context->blobdir))==NULL ) { + dc_log_error(context, 0, "Backup: Cannot get info for blob-directory \"%s\".", context->blobdir); goto cleanup; } @@ -909,15 +909,15 @@ static int export_backup(dc_context_t* context, const char* dir) if( total_files_count>0 ) { /* scan directory, pass 2: copy files */ - if( (dir_handle=opendir(context->m_blobdir))==NULL ) { - dc_log_error(context, 0, "Backup: Cannot copy from blob-directory \"%s\".", context->m_blobdir); + if( (dir_handle=opendir(context->blobdir))==NULL ) { + dc_log_error(context, 0, "Backup: Cannot copy from blob-directory \"%s\".", context->blobdir); goto cleanup; } stmt = dc_sqlite3_prepare(dest_sql, "INSERT INTO backup_blobs (file_name, file_content) VALUES (?, ?);"); while( (dir_entry=readdir(dir_handle))!=NULL ) { - if( context->m_shall_stop_ongoing ) { + if( context->shall_stop_ongoing ) { delete_dest_file = 1; goto cleanup; } @@ -935,7 +935,7 @@ static int export_backup(dc_context_t* context, const char* dir) //dc_log_info(context, 0, "Backup \"%s\".", name); free(curr_pathNfilename); - curr_pathNfilename = dc_mprintf("%s/%s", context->m_blobdir, name); + curr_pathNfilename = dc_mprintf("%s/%s", context->blobdir, name); free(buf); if( !dc_read_file(curr_pathNfilename, &buf, &buf_bytes, context) || buf==NULL || buf_bytes<=0 ) { continue; @@ -952,19 +952,19 @@ static int export_backup(dc_context_t* context, const char* dir) } else { - dc_log_info(context, 0, "Backup: No files to copy.", context->m_blobdir); + dc_log_info(context, 0, "Backup: No files to copy.", context->blobdir); } /* done - set some special config values (do this last to avoid importing crashed backups) */ dc_sqlite3_set_config_int(dest_sql, "backup_time", now); - dc_sqlite3_set_config (dest_sql, "backup_for", context->m_blobdir); + dc_sqlite3_set_config (dest_sql, "backup_for", context->blobdir); - context->m_cb(context, DC_EVENT_IMEX_FILE_WRITTEN, (uintptr_t)dest_pathNfilename, 0); + context->cb(context, DC_EVENT_IMEX_FILE_WRITTEN, (uintptr_t)dest_pathNfilename, 0); success = 1; cleanup: if( dir_handle ) { closedir(dir_handle); } - if( closed ) { dc_sqlite3_open__(context->m_sql, context->m_dbfile, 0); } + if( closed ) { dc_sqlite3_open__(context->sql, context->dbfile, 0); } sqlite3_finalize(stmt); dc_sqlite3_close__(dest_sql); @@ -1008,7 +1008,7 @@ static int import_backup(dc_context_t* context, const char* backup_to_import) char* repl_from = NULL; char* repl_to = NULL; - dc_log_info(context, 0, "Import \"%s\" to \"%s\".", backup_to_import, context->m_dbfile); + dc_log_info(context, 0, "Import \"%s\" to \"%s\".", backup_to_import, context->dbfile); if( dc_is_configured(context) ) { dc_log_error(context, 0, "Cannot import backups to accounts in use."); @@ -1017,41 +1017,41 @@ static int import_backup(dc_context_t* context, const char* backup_to_import) /* close and delete the original file - FIXME: we should import to a .bak file and rename it on success. however, currently it is not clear it the import exists in the long run (may be replaced by a restore-from-imap) */ -//dc_sqlite3_lock(context->m_sql); // TODO: check if this works while threads running +//dc_sqlite3_lock(context->sql); // TODO: check if this works while threads running //locked = 1; - if( dc_sqlite3_is_open(context->m_sql) ) { - dc_sqlite3_close__(context->m_sql); + if( dc_sqlite3_is_open(context->sql) ) { + dc_sqlite3_close__(context->sql); } - dc_delete_file(context->m_dbfile, context); + dc_delete_file(context->dbfile, context); - if( dc_file_exist(context->m_dbfile) ) { + if( dc_file_exist(context->dbfile) ) { dc_log_error(context, 0, "Cannot import backups: Cannot delete the old file."); goto cleanup; } /* copy the database file */ - if( !dc_copy_file(backup_to_import, context->m_dbfile, context) ) { + if( !dc_copy_file(backup_to_import, context->dbfile, context) ) { goto cleanup; /* error already logged */ } /* re-open copied database file */ - if( !dc_sqlite3_open__(context->m_sql, context->m_dbfile, 0) ) { + if( !dc_sqlite3_open__(context->sql, context->dbfile, 0) ) { goto cleanup; } /* copy all blobs to files */ - stmt = dc_sqlite3_prepare(context->m_sql, "SELECT COUNT(*) FROM backup_blobs;"); + stmt = dc_sqlite3_prepare(context->sql, "SELECT COUNT(*) FROM backup_blobs;"); sqlite3_step(stmt); total_files_count = sqlite3_column_int(stmt, 0); sqlite3_finalize(stmt); stmt = NULL; - stmt = dc_sqlite3_prepare(context->m_sql, "SELECT file_name, file_content FROM backup_blobs ORDER BY id;"); + stmt = dc_sqlite3_prepare(context->sql, "SELECT file_name, file_content FROM backup_blobs ORDER BY id;"); while( sqlite3_step(stmt) == SQLITE_ROW ) { - if( context->m_shall_stop_ongoing ) { + if( context->shall_stop_ongoing ) { goto cleanup; } @@ -1063,7 +1063,7 @@ static int import_backup(dc_context_t* context, const char* backup_to_import) if( file_bytes > 0 && file_content ) { free(pathNfilename); - pathNfilename = dc_mprintf("%s/%s", context->m_blobdir, file_name); + pathNfilename = dc_mprintf("%s/%s", context->blobdir, file_name); if( !dc_write_file(pathNfilename, file_content, file_bytes, context) ) { dc_log_error(context, 0, "Storage full? Cannot write file %s with %i bytes.", pathNfilename, file_bytes); goto cleanup; /* otherwise the user may believe the stuff is imported correctly, but there are files missing ... */ @@ -1075,15 +1075,15 @@ static int import_backup(dc_context_t* context, const char* backup_to_import) sqlite3_finalize(stmt); stmt = 0; - dc_sqlite3_execute(context->m_sql, "DROP TABLE backup_blobs;"); - dc_sqlite3_execute(context->m_sql, "VACUUM;"); + dc_sqlite3_execute(context->sql, "DROP TABLE backup_blobs;"); + dc_sqlite3_execute(context->sql, "VACUUM;"); /* rewrite references to the blobs */ - repl_from = dc_sqlite3_get_config(context->m_sql, "backup_for", NULL); - if( repl_from && strlen(repl_from)>1 && context->m_blobdir && strlen(context->m_blobdir)>1 ) + repl_from = dc_sqlite3_get_config(context->sql, "backup_for", NULL); + if( repl_from && strlen(repl_from)>1 && context->blobdir && strlen(context->blobdir)>1 ) { ensure_no_slash(repl_from); - repl_to = dc_strdup(context->m_blobdir); + repl_to = dc_strdup(context->blobdir); ensure_no_slash(repl_to); dc_log_info(context, 0, "Rewriting paths from '%s' to '%s' ...", repl_from, repl_to); @@ -1092,15 +1092,15 @@ static int import_backup(dc_context_t* context, const char* backup_to_import) assert( 'i' == DC_PARAM_PROFILE_IMAGE ); char* q3 = sqlite3_mprintf("UPDATE msgs SET param=replace(param, 'f=%q/', 'f=%q/');", repl_from, repl_to); /* cannot use dc_mprintf() because of "%q" */ - dc_sqlite3_execute(context->m_sql, q3); + dc_sqlite3_execute(context->sql, q3); sqlite3_free(q3); q3 = sqlite3_mprintf("UPDATE chats SET param=replace(param, 'i=%q/', 'i=%q/');", repl_from, repl_to); - dc_sqlite3_execute(context->m_sql, q3); + dc_sqlite3_execute(context->sql, q3); sqlite3_free(q3); q3 = sqlite3_mprintf("UPDATE contacts SET param=replace(param, 'i=%q/', 'i=%q/');", repl_from, repl_to); - dc_sqlite3_execute(context->m_sql, q3); + dc_sqlite3_execute(context->sql, q3); sqlite3_free(q3); } @@ -1112,7 +1112,7 @@ cleanup: free(repl_to); sqlite3_finalize(stmt); -// if( locked ) { dc_sqlite3_unlock(context->m_sql); } // TODO: check if this works while threads running +// if( locked ) { dc_sqlite3_unlock(context->sql); } // TODO: check if this works while threads running return success; } @@ -1177,7 +1177,7 @@ void dc_imex(dc_context_t* context, int what, const char* param1, const char* pa dc_param_set (param, DC_PARAM_CMD_ARG2, param2); dc_job_kill_actions(context, DC_JOB_IMEX_IMAP, 0); - dc_job_add(context, DC_JOB_IMEX_IMAP, 0, param->m_packed, 0); // results in a call to dc_job_do_DC_JOB_IMEX_IMAP() + dc_job_add(context, DC_JOB_IMEX_IMAP, 0, param->packed, 0); // results in a call to dc_job_do_DC_JOB_IMEX_IMAP() dc_param_unref(param); } @@ -1191,7 +1191,7 @@ void dc_job_do_DC_JOB_IMEX_IMAP(dc_context_t* context, dc_job_t* job) char* param1 = NULL; char* param2 = NULL; - if( context==NULL || context->m_magic != DC_CONTEXT_MAGIC || context->m_sql==NULL ) { + if( context==NULL || context->magic != DC_CONTEXT_MAGIC || context->sql==NULL ) { goto cleanup; } @@ -1200,9 +1200,9 @@ void dc_job_do_DC_JOB_IMEX_IMAP(dc_context_t* context, dc_job_t* job) } ongoing_allocated_here = 1; - what = dc_param_get_int(job->m_param, DC_PARAM_CMD, 0); - param1 = dc_param_get (job->m_param, DC_PARAM_CMD_ARG, NULL); - param2 = dc_param_get (job->m_param, DC_PARAM_CMD_ARG2, NULL); + what = dc_param_get_int(job->param, DC_PARAM_CMD, 0); + param1 = dc_param_get (job->param, DC_PARAM_CMD_ARG, NULL); + param2 = dc_param_get (job->param, DC_PARAM_CMD_ARG2, NULL); if( param1 == NULL ) { dc_log_error(context, 0, "No Import/export dir/file given."); @@ -1210,9 +1210,9 @@ void dc_job_do_DC_JOB_IMEX_IMAP(dc_context_t* context, dc_job_t* job) } dc_log_info(context, 0, "Import/export process started."); - context->m_cb(context, DC_EVENT_IMEX_PROGRESS, 10, 0); + context->cb(context, DC_EVENT_IMEX_PROGRESS, 10, 0); - if( !dc_sqlite3_is_open(context->m_sql) ) { + if( !dc_sqlite3_is_open(context->sql) ) { dc_log_error(context, 0, "Import/export: Database not opened."); goto cleanup; } @@ -1267,7 +1267,7 @@ cleanup: if( ongoing_allocated_here ) { dc_free_ongoing(context); } - context->m_cb(context, DC_EVENT_IMEX_PROGRESS, success? 1000 : 0, 0); + context->cb(context, DC_EVENT_IMEX_PROGRESS, success? 1000 : 0, 0); } @@ -1330,7 +1330,7 @@ char* dc_imex_has_backup(dc_context_t* context, const char* dir_name) char* curr_pathNfilename = NULL; dc_sqlite3_t* test_sql = NULL; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC ) { return NULL; } @@ -1391,21 +1391,21 @@ int dc_check_password(dc_context_t* context, const char* test_pw) dc_loginparam_t* loginparam = dc_loginparam_new(); int success = 0; - if( context==NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context==NULL || context->magic != DC_CONTEXT_MAGIC ) { goto cleanup; } - dc_loginparam_read(loginparam, context->m_sql, "configured_"); + dc_loginparam_read(loginparam, context->sql, "configured_"); - if( (loginparam->m_mail_pw==NULL || loginparam->m_mail_pw[0]==0) && (test_pw==NULL || test_pw[0]==0) ) { + if( (loginparam->mail_pw==NULL || loginparam->mail_pw[0]==0) && (test_pw==NULL || test_pw[0]==0) ) { /* both empty or unset */ success = 1; } - else if( loginparam->m_mail_pw==NULL || test_pw==NULL ) { + else if( loginparam->mail_pw==NULL || test_pw==NULL ) { /* one set, the other not */ success = 0; } - else if( strcmp(loginparam->m_mail_pw, test_pw)==0 ) { + else if( strcmp(loginparam->mail_pw, test_pw)==0 ) { /* string-compared passwords are equal */ success = 1; } diff --git a/src/dc_job.c b/src/dc_job.c index 58c16cf0..37a5f4d8 100644 --- a/src/dc_job.c +++ b/src/dc_job.c @@ -43,24 +43,24 @@ static int connect_to_imap(dc_context_t* context, dc_job_t* job /*may be NULL if int ret_connected = NOT_CONNECTED; dc_loginparam_t* param = dc_loginparam_new(); - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || context->m_imap == NULL ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || context->imap == NULL ) { dc_log_warning(context, 0, "Cannot connect to IMAP: Bad parameters."); goto cleanup; } - if( dc_imap_is_connected(context->m_imap) ) { + if( dc_imap_is_connected(context->imap) ) { ret_connected = ALREADY_CONNECTED; goto cleanup; } - if( dc_sqlite3_get_config_int(context->m_sql, "configured", 0) == 0 ) { + if( dc_sqlite3_get_config_int(context->sql, "configured", 0) == 0 ) { dc_log_warning(context, 0, "Not configured, cannot connect."); // this is no error, connect() is called eg. when the screen is switched on, it's okay if the caller does not check all circumstances here goto cleanup; } - dc_loginparam_read(param, context->m_sql, "configured_" /*the trailing underscore is correct*/); + dc_loginparam_read(param, context->sql, "configured_" /*the trailing underscore is correct*/); - if( !dc_imap_connect(context->m_imap, param) ) { + if( !dc_imap_connect(context->imap, param) ) { dc_job_try_again_later(job, DC_STANDARD_DELAY); goto cleanup; } @@ -82,17 +82,17 @@ static void dc_job_do_DC_JOB_SEND_MSG_TO_IMAP(dc_context_t* context, dc_job_t* j dc_mimefactory_init(&mimefactory, context); /* connect to IMAP-server */ - if( !dc_imap_is_connected(context->m_imap) ) { + if( !dc_imap_is_connected(context->imap) ) { connect_to_imap(context, NULL); - if( !dc_imap_is_connected(context->m_imap) ) { + if( !dc_imap_is_connected(context->imap) ) { dc_job_try_again_later(job, DC_STANDARD_DELAY); goto cleanup; } } /* create message */ - if( dc_mimefactory_load_msg(&mimefactory, job->m_foreign_id)==0 - || mimefactory.m_from_addr == NULL ) { + if( dc_mimefactory_load_msg(&mimefactory, job->foreign_id)==0 + || mimefactory.from_addr == NULL ) { goto cleanup; /* should not happen as we've sent the message to the SMTP server before */ } @@ -100,12 +100,12 @@ static void dc_job_do_DC_JOB_SEND_MSG_TO_IMAP(dc_context_t* context, dc_job_t* j goto cleanup; /* should not happen as we've sent the message to the SMTP server before */ } - if( !dc_imap_append_msg(context->m_imap, mimefactory.m_msg->m_timestamp, mimefactory.m_out->str, mimefactory.m_out->len, &server_folder, &server_uid) ) { + if( !dc_imap_append_msg(context->imap, mimefactory.msg->timestamp, mimefactory.out->str, mimefactory.out->len, &server_folder, &server_uid) ) { dc_job_try_again_later(job, DC_AT_ONCE); goto cleanup; } else { - dc_update_server_uid(context, mimefactory.m_msg->m_rfc724_mid, server_folder, server_uid); + dc_update_server_uid(context, mimefactory.msg->rfc724_mid, server_folder, server_uid); } cleanup: @@ -120,12 +120,12 @@ static void dc_job_do_DC_JOB_DELETE_MSG_ON_IMAP(dc_context_t* context, dc_job_t* dc_msg_t* msg = dc_msg_new(); sqlite3_stmt* stmt = NULL; - if( !dc_msg_load_from_db(msg, context, job->m_foreign_id) - || msg->m_rfc724_mid == NULL || msg->m_rfc724_mid[0] == 0 /* eg. device messages have no Message-ID */ ) { + if( !dc_msg_load_from_db(msg, context, job->foreign_id) + || msg->rfc724_mid == NULL || msg->rfc724_mid[0] == 0 /* eg. device messages have no Message-ID */ ) { goto cleanup; } - if( dc_rfc724_mid_cnt(context, msg->m_rfc724_mid) != 1 ) { + if( dc_rfc724_mid_cnt(context, msg->rfc724_mid) != 1 ) { dc_log_info(context, 0, "The message is deleted from the server when all parts are deleted."); delete_from_server = 0; } @@ -133,15 +133,15 @@ static void dc_job_do_DC_JOB_DELETE_MSG_ON_IMAP(dc_context_t* context, dc_job_t* /* if this is the last existing part of the message, we delete the message from the server */ if( delete_from_server ) { - if( !dc_imap_is_connected(context->m_imap) ) { + if( !dc_imap_is_connected(context->imap) ) { connect_to_imap(context, NULL); - if( !dc_imap_is_connected(context->m_imap) ) { + if( !dc_imap_is_connected(context->imap) ) { dc_job_try_again_later(job, DC_STANDARD_DELAY); goto cleanup; } } - if( !dc_imap_delete_msg(context->m_imap, msg->m_rfc724_mid, msg->m_server_folder, msg->m_server_uid) ) + if( !dc_imap_delete_msg(context->imap, msg->rfc724_mid, msg->server_folder, msg->server_uid) ) { dc_job_try_again_later(job, DC_AT_ONCE); goto cleanup; @@ -152,26 +152,26 @@ static void dc_job_do_DC_JOB_DELETE_MSG_ON_IMAP(dc_context_t* context, dc_job_t* - if the message is successfully removed from the server - or if there are other parts of the message in the database (in this case we have not deleted if from the server) (As long as the message is not removed from the IMAP-server, we need at least one database entry to avoid a re-download) */ - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "DELETE FROM msgs WHERE id=?;"); - sqlite3_bind_int(stmt, 1, msg->m_id); + sqlite3_bind_int(stmt, 1, msg->id); sqlite3_step(stmt); sqlite3_finalize(stmt); stmt = NULL; - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "DELETE FROM msgs_mdns WHERE msg_id=?;"); - sqlite3_bind_int(stmt, 1, msg->m_id); + sqlite3_bind_int(stmt, 1, msg->id); sqlite3_step(stmt); sqlite3_finalize(stmt); stmt = NULL; - char* pathNfilename = dc_param_get(msg->m_param, DC_PARAM_FILE, NULL); + char* pathNfilename = dc_param_get(msg->param, DC_PARAM_FILE, NULL); if( pathNfilename ) { - if( strncmp(context->m_blobdir, pathNfilename, strlen(context->m_blobdir))==0 ) + if( strncmp(context->blobdir, pathNfilename, strlen(context->blobdir))==0 ) { char* strLikeFilename = dc_mprintf("%%f=%s%%", pathNfilename); - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT id FROM msgs WHERE type!=? AND param LIKE ?;"); /* if this gets too slow, an index over "type" should help. */ sqlite3_bind_int (stmt, 1, DC_MSG_TEXT); sqlite3_bind_text(stmt, 2, strLikeFilename, -1, SQLITE_STATIC); @@ -189,13 +189,13 @@ static void dc_job_do_DC_JOB_DELETE_MSG_ON_IMAP(dc_context_t* context, dc_job_t* free(increation_file); char* filenameOnly = dc_get_filename(pathNfilename); - if( msg->m_type==DC_MSG_VOICE ) { - char* waveform_file = dc_mprintf("%s/%s.waveform", context->m_blobdir, filenameOnly); + if( msg->type==DC_MSG_VOICE ) { + char* waveform_file = dc_mprintf("%s/%s.waveform", context->blobdir, filenameOnly); dc_delete_file(waveform_file, context); free(waveform_file); } - else if( msg->m_type==DC_MSG_VIDEO ) { - char* preview_file = dc_mprintf("%s/%s-preview.jpg", context->m_blobdir, filenameOnly); + else if( msg->type==DC_MSG_VIDEO ) { + char* preview_file = dc_mprintf("%s/%s-preview.jpg", context->blobdir, filenameOnly); dc_delete_file(preview_file, context); free(preview_file); } @@ -219,41 +219,41 @@ static void dc_job_do_DC_JOB_MARKSEEN_MSG_ON_IMAP(dc_context_t* context, dc_job_ int in_ms_flags = 0; int out_ms_flags = 0; - if( !dc_imap_is_connected(context->m_imap) ) { + if( !dc_imap_is_connected(context->imap) ) { connect_to_imap(context, NULL); - if( !dc_imap_is_connected(context->m_imap) ) { + if( !dc_imap_is_connected(context->imap) ) { dc_job_try_again_later(job, DC_STANDARD_DELAY); goto cleanup; } } - if( !dc_msg_load_from_db(msg, context, job->m_foreign_id) ) { + if( !dc_msg_load_from_db(msg, context, job->foreign_id) ) { goto cleanup; } /* add an additional job for sending the MDN (here in a thread for fast ui resonses) (an extra job as the MDN has a lower priority) */ - if( dc_param_get_int(msg->m_param, DC_PARAM_WANTS_MDN, 0) /* DC_PARAM_WANTS_MDN is set only for one part of a multipart-message */ - && dc_sqlite3_get_config_int(context->m_sql, "mdns_enabled", DC_MDNS_DEFAULT_ENABLED) ) { + if( dc_param_get_int(msg->param, DC_PARAM_WANTS_MDN, 0) /* DC_PARAM_WANTS_MDN is set only for one part of a multipart-message */ + && dc_sqlite3_get_config_int(context->sql, "mdns_enabled", DC_MDNS_DEFAULT_ENABLED) ) { in_ms_flags |= DC_MS_SET_MDNSent_FLAG; } - if( msg->m_is_msgrmsg ) { + if( msg->is_msgrmsg ) { in_ms_flags |= DC_MS_ALSO_MOVE; } - if( dc_imap_markseen_msg(context->m_imap, msg->m_server_folder, msg->m_server_uid, + if( dc_imap_markseen_msg(context->imap, msg->server_folder, msg->server_uid, in_ms_flags, &new_server_folder, &new_server_uid, &out_ms_flags) != 0 ) { if( (new_server_folder && new_server_uid) || out_ms_flags&DC_MS_MDNSent_JUST_SET ) { if( new_server_folder && new_server_uid ) { - dc_update_server_uid(context, msg->m_rfc724_mid, new_server_folder, new_server_uid); + dc_update_server_uid(context, msg->rfc724_mid, new_server_folder, new_server_uid); } if( out_ms_flags&DC_MS_MDNSent_JUST_SET ) { - dc_job_add(context, DC_JOB_SEND_MDN, msg->m_id, NULL, 0); + dc_job_add(context, DC_JOB_SEND_MDN, msg->id, NULL, 0); } } } @@ -270,21 +270,21 @@ cleanup: static void dc_job_do_DC_JOB_MARKSEEN_MDN_ON_IMAP(dc_context_t* context, dc_job_t* job) { - char* server_folder = dc_param_get (job->m_param, DC_PARAM_SERVER_FOLDER, NULL); - uint32_t server_uid = dc_param_get_int(job->m_param, DC_PARAM_SERVER_UID, 0); + char* server_folder = dc_param_get (job->param, DC_PARAM_SERVER_FOLDER, NULL); + uint32_t server_uid = dc_param_get_int(job->param, DC_PARAM_SERVER_UID, 0); char* new_server_folder = NULL; uint32_t new_server_uid = 0; int out_ms_flags = 0; - if( !dc_imap_is_connected(context->m_imap) ) { + if( !dc_imap_is_connected(context->imap) ) { connect_to_imap(context, NULL); - if( !dc_imap_is_connected(context->m_imap) ) { + if( !dc_imap_is_connected(context->imap) ) { dc_job_try_again_later(job, DC_STANDARD_DELAY); goto cleanup; } } - if( dc_imap_markseen_msg(context->m_imap, server_folder, server_uid, DC_MS_ALSO_MOVE, &new_server_folder, &new_server_uid, &out_ms_flags) == 0 ) { + if( dc_imap_markseen_msg(context->imap, server_folder, server_uid, DC_MS_ALSO_MOVE, &new_server_folder, &new_server_uid, &out_ms_flags) == 0 ) { dc_job_try_again_later(job, DC_AT_ONCE); } @@ -305,8 +305,8 @@ static void mark_as_error(dc_context_t* context, dc_msg_t* msg) return; } - dc_update_msg_state(context, msg->m_id, DC_STATE_OUT_ERROR); - context->m_cb(context, DC_EVENT_MSGS_CHANGED, msg->m_chat_id, 0); + dc_update_msg_state(context, msg->id, DC_STATE_OUT_ERROR); + context->cb(context, DC_EVENT_MSGS_CHANGED, msg->chat_id, 0); } @@ -316,10 +316,10 @@ static void dc_job_do_DC_JOB_SEND_MSG_TO_SMTP(dc_context_t* context, dc_job_t* j dc_mimefactory_init(&mimefactory, context); /* connect to SMTP server, if not yet done */ - if( !dc_smtp_is_connected(context->m_smtp) ) { + if( !dc_smtp_is_connected(context->smtp) ) { dc_loginparam_t* loginparam = dc_loginparam_new(); - dc_loginparam_read(loginparam, context->m_sql, "configured_"); - int connected = dc_smtp_connect(context->m_smtp, loginparam); + dc_loginparam_read(loginparam, context->sql, "configured_"); + int connected = dc_smtp_connect(context->smtp, loginparam); dc_loginparam_unref(loginparam); if( !connected ) { dc_job_try_again_later(job, DC_STANDARD_DELAY); @@ -328,75 +328,75 @@ static void dc_job_do_DC_JOB_SEND_MSG_TO_SMTP(dc_context_t* context, dc_job_t* j } /* load message data */ - if( !dc_mimefactory_load_msg(&mimefactory, job->m_foreign_id) - || mimefactory.m_from_addr == NULL ) { + if( !dc_mimefactory_load_msg(&mimefactory, job->foreign_id) + || mimefactory.from_addr == NULL ) { dc_log_warning(context, 0, "Cannot load data to send, maybe the message is deleted in between."); goto cleanup; /* no redo, no IMAP - there won't be more recipients next time (as the data does not exist, there is no need in calling mark_as_error()) */ } /* check if the message is ready (normally, only video files may be delayed this way) */ - if( mimefactory.m_increation ) { + if( mimefactory.increation ) { dc_log_info(context, 0, "File is in creation, retrying later."); dc_job_try_again_later(job, DC_INCREATION_POLL); goto cleanup; } /* send message - it's okay if there are no recipients, this is a group with only OURSELF; we only upload to IMAP in this case */ - if( clist_count(mimefactory.m_recipients_addr) > 0 ) { + if( clist_count(mimefactory.recipients_addr) > 0 ) { if( !dc_mimefactory_render(&mimefactory) ) { - mark_as_error(context, mimefactory.m_msg); + mark_as_error(context, mimefactory.msg); dc_log_error(context, 0, "Empty message."); /* should not happen */ goto cleanup; /* no redo, no IMAP - there won't be more recipients next time. */ } /* have we guaranteed encryption but cannot fulfill it for any reason? Do not send the message then.*/ - if( dc_param_get_int(mimefactory.m_msg->m_param, DC_PARAM_GUARANTEE_E2EE, 0) && !mimefactory.m_out_encrypted ) { - mark_as_error(context, mimefactory.m_msg); + if( dc_param_get_int(mimefactory.msg->param, DC_PARAM_GUARANTEE_E2EE, 0) && !mimefactory.out_encrypted ) { + mark_as_error(context, mimefactory.msg); dc_log_error(context, 0, "End-to-end-encryption unavailable unexpectedly."); goto cleanup; /* unrecoverable */ } - if( !dc_smtp_send_msg(context->m_smtp, mimefactory.m_recipients_addr, mimefactory.m_out->str, mimefactory.m_out->len) ) { - dc_smtp_disconnect(context->m_smtp); + if( !dc_smtp_send_msg(context->smtp, mimefactory.recipients_addr, mimefactory.out->str, mimefactory.out->len) ) { + dc_smtp_disconnect(context->smtp); dc_job_try_again_later(job, DC_AT_ONCE); /* DC_AT_ONCE is only the _initial_ delay, if the second try failes, the delay gets larger */ goto cleanup; } } /* done */ - dc_sqlite3_begin_transaction(context->m_sql); + dc_sqlite3_begin_transaction(context->sql); /* debug print? */ - if( dc_sqlite3_get_config_int(context->m_sql, "save_eml", 0) ) { - char* emlname = dc_mprintf("%s/to-smtp-%i.eml", context->m_blobdir, (int)mimefactory.m_msg->m_id); + if( dc_sqlite3_get_config_int(context->sql, "save_eml", 0) ) { + char* emlname = dc_mprintf("%s/to-smtp-%i.eml", context->blobdir, (int)mimefactory.msg->id); FILE* emlfileob = fopen(emlname, "w"); if( emlfileob ) { - if( mimefactory.m_out ) { - fwrite(mimefactory.m_out->str, 1, mimefactory.m_out->len, emlfileob); + if( mimefactory.out ) { + fwrite(mimefactory.out->str, 1, mimefactory.out->len, emlfileob); } fclose(emlfileob); } free(emlname); } - dc_update_msg_state(context, mimefactory.m_msg->m_id, DC_STATE_OUT_DELIVERED); - if( mimefactory.m_out_encrypted && dc_param_get_int(mimefactory.m_msg->m_param, DC_PARAM_GUARANTEE_E2EE, 0)==0 ) { - dc_param_set_int(mimefactory.m_msg->m_param, DC_PARAM_GUARANTEE_E2EE, 1); /* can upgrade to E2EE - fine! */ - dc_msg_save_param_to_disk(mimefactory.m_msg); + dc_update_msg_state(context, mimefactory.msg->id, DC_STATE_OUT_DELIVERED); + if( mimefactory.out_encrypted && dc_param_get_int(mimefactory.msg->param, DC_PARAM_GUARANTEE_E2EE, 0)==0 ) { + dc_param_set_int(mimefactory.msg->param, DC_PARAM_GUARANTEE_E2EE, 1); /* can upgrade to E2EE - fine! */ + dc_msg_save_param_to_disk(mimefactory.msg); } - if( (context->m_imap->m_server_flags&DC_NO_EXTRA_IMAP_UPLOAD)==0 - && dc_param_get(mimefactory.m_chat->m_param, DC_PARAM_SELFTALK, 0)==0 - && dc_param_get_int(mimefactory.m_msg->m_param, DC_PARAM_CMD, 0)!=DC_CMD_SECUREJOIN_MESSAGE ) { - dc_job_add(context, DC_JOB_SEND_MSG_TO_IMAP, mimefactory.m_msg->m_id, NULL, 0); /* send message to IMAP in another job */ + if( (context->imap->server_flags&DC_NO_EXTRA_IMAP_UPLOAD)==0 + && dc_param_get(mimefactory.chat->param, DC_PARAM_SELFTALK, 0)==0 + && dc_param_get_int(mimefactory.msg->param, DC_PARAM_CMD, 0)!=DC_CMD_SECUREJOIN_MESSAGE ) { + dc_job_add(context, DC_JOB_SEND_MSG_TO_IMAP, mimefactory.msg->id, NULL, 0); /* send message to IMAP in another job */ } // TODO: add to keyhistory dc_add_to_keyhistory__(context, NULL, 0, NULL, NULL); - dc_sqlite3_commit(context->m_sql); + dc_sqlite3_commit(context->sql); - context->m_cb(context, DC_EVENT_MSG_DELIVERED, mimefactory.m_msg->m_chat_id, mimefactory.m_msg->m_id); + context->cb(context, DC_EVENT_MSG_DELIVERED, mimefactory.msg->chat_id, mimefactory.msg->id); cleanup: dc_mimefactory_empty(&mimefactory); @@ -408,16 +408,16 @@ static void dc_job_do_DC_JOB_SEND_MDN(dc_context_t* context, dc_job_t* job) dc_mimefactory_t mimefactory; dc_mimefactory_init(&mimefactory, context); - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || job == NULL ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || job == NULL ) { return; } /* connect to SMTP server, if not yet done */ - if( !dc_smtp_is_connected(context->m_smtp) ) + if( !dc_smtp_is_connected(context->smtp) ) { dc_loginparam_t* loginparam = dc_loginparam_new(); - dc_loginparam_read(loginparam, context->m_sql, "configured_"); - int connected = dc_smtp_connect(context->m_smtp, loginparam); + dc_loginparam_read(loginparam, context->sql, "configured_"); + int connected = dc_smtp_connect(context->smtp, loginparam); dc_loginparam_unref(loginparam); if( !connected ) { dc_job_try_again_later(job, DC_STANDARD_DELAY); @@ -425,15 +425,15 @@ static void dc_job_do_DC_JOB_SEND_MDN(dc_context_t* context, dc_job_t* job) } } - if( !dc_mimefactory_load_mdn(&mimefactory, job->m_foreign_id) + if( !dc_mimefactory_load_mdn(&mimefactory, job->foreign_id) || !dc_mimefactory_render(&mimefactory) ) { goto cleanup; } - //char* t1=dc_null_terminate(mimefactory.m_out->str,mimefactory.m_out->len);printf("~~~~~MDN~~~~~\n%s\n~~~~~/MDN~~~~~",t1);free(t1); // DEBUG OUTPUT + //char* t1=dc_null_terminate(mimefactory.out->str,mimefactory.out->len);printf("~~~~~MDN~~~~~\n%s\n~~~~~/MDN~~~~~",t1);free(t1); // DEBUG OUTPUT - if( !dc_smtp_send_msg(context->m_smtp, mimefactory.m_recipients_addr, mimefactory.m_out->str, mimefactory.m_out->len) ) { - dc_smtp_disconnect(context->m_smtp); + if( !dc_smtp_send_msg(context->smtp, mimefactory.recipients_addr, mimefactory.out->str, mimefactory.out->len) ) { + dc_smtp_disconnect(context->smtp); dc_job_try_again_later(job, DC_AT_ONCE); /* DC_AT_ONCE is only the _initial_ delay, if the second try failes, the delay gets larger */ goto cleanup; } @@ -445,9 +445,9 @@ cleanup: static void dc_suspend_smtp_thread(dc_context_t* context, int suspend) { - pthread_mutex_lock(&context->m_smtpidle_condmutex); - context->m_smtpidle_suspend = suspend; - pthread_mutex_unlock(&context->m_smtpidle_condmutex); + pthread_mutex_lock(&context->smtpidle_condmutex); + context->smtpidle_suspend = suspend; + pthread_mutex_unlock(&context->smtpidle_condmutex); // the smtp-thread may be in perform_jobs() when this function is called, // wait until we arrive in idle(). for simplicity, we do this by polling a variable @@ -455,13 +455,13 @@ static void dc_suspend_smtp_thread(dc_context_t* context, int suspend) if( suspend ) { while( 1 ) { - pthread_mutex_lock(&context->m_smtpidle_condmutex); - if( context->m_smtpidle_in_idleing ) { - context->m_perform_smtp_jobs_needed = 0; - pthread_mutex_unlock(&context->m_smtpidle_condmutex); + pthread_mutex_lock(&context->smtpidle_condmutex); + if( context->smtpidle_in_idleing ) { + context->perform_smtp_jobs_needed = 0; + pthread_mutex_unlock(&context->smtpidle_condmutex); return; } - pthread_mutex_unlock(&context->m_smtpidle_condmutex); + pthread_mutex_unlock(&context->smtpidle_condmutex); usleep(300*1000); } } @@ -489,7 +489,7 @@ void dc_job_add(dc_context_t* context, int action, int foreign_id, const char* p return; } - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "INSERT INTO jobs (added_timestamp, thread, action, foreign_id, param, desired_timestamp) VALUES (?,?,?,?,?,?);"); sqlite3_bind_int64(stmt, 1, timestamp); sqlite3_bind_int (stmt, 2, thread); @@ -515,7 +515,7 @@ void dc_job_try_again_later(dc_job_t* job, int try_again) return; } - job->m_try_again = try_again; + job->try_again = try_again; } @@ -525,7 +525,7 @@ void dc_job_kill_actions(dc_context_t* context, int action1, int action2) return; } - sqlite3_stmt* stmt = dc_sqlite3_prepare(context->m_sql, + sqlite3_stmt* stmt = dc_sqlite3_prepare(context->sql, "DELETE FROM jobs WHERE action=? OR action=?;"); sqlite3_bind_int(stmt, 1, action1); sqlite3_bind_int(stmt, 2, action2); @@ -539,34 +539,34 @@ static void dc_job_perform(dc_context_t* context, int thread) sqlite3_stmt* select_stmt = NULL; dc_job_t job; #define THREAD_STR (thread==DC_IMAP_THREAD? "IMAP" : "SMTP") - #define IS_EXCLUSIVE_JOB (DC_JOB_CONFIGURE_IMAP==job.m_action || DC_JOB_IMEX_IMAP==job.m_action) + #define IS_EXCLUSIVE_JOB (DC_JOB_CONFIGURE_IMAP==job.action || DC_JOB_IMEX_IMAP==job.action) memset(&job, 0, sizeof(dc_job_t)); - job.m_param = dc_param_new(); + job.param = dc_param_new(); - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC ) { goto cleanup; } - select_stmt = dc_sqlite3_prepare(context->m_sql, + select_stmt = dc_sqlite3_prepare(context->sql, "SELECT id, action, foreign_id, param FROM jobs WHERE thread=? AND desired_timestamp<=? ORDER BY action DESC, added_timestamp;"); sqlite3_bind_int64(select_stmt, 1, thread); sqlite3_bind_int64(select_stmt, 2, time(NULL)); while( sqlite3_step(select_stmt) == SQLITE_ROW ) { - job.m_job_id = sqlite3_column_int (select_stmt, 0); - job.m_action = sqlite3_column_int (select_stmt, 1); - job.m_foreign_id = sqlite3_column_int (select_stmt, 2); - dc_param_set_packed(job.m_param, (char*)sqlite3_column_text(select_stmt, 3)); + job.job_id = sqlite3_column_int (select_stmt, 0); + job.action = sqlite3_column_int (select_stmt, 1); + job.foreign_id = sqlite3_column_int (select_stmt, 2); + dc_param_set_packed(job.param, (char*)sqlite3_column_text(select_stmt, 3)); - dc_log_info(context, 0, "%s-job #%i, action %i started...", THREAD_STR, (int)job.m_job_id, (int)job.m_action); + dc_log_info(context, 0, "%s-job #%i, action %i started...", THREAD_STR, (int)job.job_id, (int)job.action); // some configuration jobs are "exclusive": // - they are always executed in the imap-thread and the smtp-thread is suspended during execution // - they may change the database handle change the database handle; we do not keep old pointers therefore // - they can be re-executed one time AT_ONCE, but they are not save in the database for later execution if (IS_EXCLUSIVE_JOB) { - dc_job_kill_actions(context, job.m_action, 0); + dc_job_kill_actions(context, job.action, 0); sqlite3_finalize(select_stmt); select_stmt = NULL; dc_suspend_smtp_thread(context, 1); @@ -574,9 +574,9 @@ static void dc_job_perform(dc_context_t* context, int thread) for( int tries = 0; tries <= 1; tries++ ) { - job.m_try_again = DC_DONT_TRY_AGAIN; // this can be modified by a job using dc_job_try_again_later() + job.try_again = DC_DONT_TRY_AGAIN; // this can be modified by a job using dc_job_try_again_later() - switch( job.m_action ) { + switch( job.action ) { case DC_JOB_SEND_MSG_TO_SMTP: dc_job_do_DC_JOB_SEND_MSG_TO_SMTP (context, &job); break; case DC_JOB_SEND_MSG_TO_IMAP: dc_job_do_DC_JOB_SEND_MSG_TO_IMAP (context, &job); break; case DC_JOB_DELETE_MSG_ON_IMAP: dc_job_do_DC_JOB_DELETE_MSG_ON_IMAP (context, &job); break; @@ -587,7 +587,7 @@ static void dc_job_perform(dc_context_t* context, int thread) case DC_JOB_IMEX_IMAP: dc_job_do_DC_JOB_IMEX_IMAP (context, &job); break; } - if( job.m_try_again != DC_AT_ONCE ) { + if( job.try_again != DC_AT_ONCE ) { break; } } @@ -596,23 +596,23 @@ static void dc_job_perform(dc_context_t* context, int thread) dc_suspend_smtp_thread(context, 0); goto cleanup; } - else if( job.m_try_again == DC_INCREATION_POLL ) + else if( job.try_again == DC_INCREATION_POLL ) { // just try over next loop unconditionally, the ui typically interrupts idle when the file (video) is ready - dc_log_info(context, 0, "%s-job #%i not yet ready and will be delayed.", THREAD_STR, (int)job.m_job_id); + dc_log_info(context, 0, "%s-job #%i not yet ready and will be delayed.", THREAD_STR, (int)job.job_id); } - else if( job.m_try_again == DC_AT_ONCE || job.m_try_again == DC_STANDARD_DELAY ) + else if( job.try_again == DC_AT_ONCE || job.try_again == DC_STANDARD_DELAY ) { - int tries = dc_param_get_int(job.m_param, DC_PARAM_TIMES, 0) + 1; - dc_param_set_int(job.m_param, DC_PARAM_TIMES, tries); + int tries = dc_param_get_int(job.param, DC_PARAM_TIMES, 0) + 1; + dc_param_set_int(job.param, DC_PARAM_TIMES, tries); - sqlite3_stmt* update_stmt = dc_sqlite3_prepare(context->m_sql, + sqlite3_stmt* update_stmt = dc_sqlite3_prepare(context->sql, "UPDATE jobs SET desired_timestamp=0, param=? WHERE id=?;"); - sqlite3_bind_text (update_stmt, 1, job.m_param->m_packed, -1, SQLITE_STATIC); - sqlite3_bind_int (update_stmt, 2, job.m_job_id); + sqlite3_bind_text (update_stmt, 1, job.param->packed, -1, SQLITE_STATIC); + sqlite3_bind_int (update_stmt, 2, job.job_id); sqlite3_step(update_stmt); sqlite3_finalize(update_stmt); - dc_log_info(context, 0, "%s-job #%i not succeeded, trying again asap.", THREAD_STR, (int)job.m_job_id); + dc_log_info(context, 0, "%s-job #%i not succeeded, trying again asap.", THREAD_STR, (int)job.job_id); // if the job did not succeeded AND this is a smtp-job AND we're online, try over after a mini-delay of one second. // if we're not online, the ui calls interrupt idle as soon as we're online again. @@ -620,23 +620,23 @@ static void dc_job_perform(dc_context_t* context, int thread) if( thread == DC_SMTP_THREAD && dc_is_online(context) ) { - pthread_mutex_lock(&context->m_smtpidle_condmutex); - context->m_perform_smtp_jobs_needed = DC_JOBS_NEEDED_AVOID_DOS; - pthread_mutex_unlock(&context->m_smtpidle_condmutex); + pthread_mutex_lock(&context->smtpidle_condmutex); + context->perform_smtp_jobs_needed = DC_JOBS_NEEDED_AVOID_DOS; + pthread_mutex_unlock(&context->smtpidle_condmutex); } } else { - sqlite3_stmt* delete_stmt = dc_sqlite3_prepare(context->m_sql, + sqlite3_stmt* delete_stmt = dc_sqlite3_prepare(context->sql, "DELETE FROM jobs WHERE id=?;"); - sqlite3_bind_int(delete_stmt, 1, job.m_job_id); + sqlite3_bind_int(delete_stmt, 1, job.job_id); sqlite3_step(delete_stmt); sqlite3_finalize(delete_stmt); } } cleanup: - dc_param_unref(job.m_param); + dc_param_unref(job.param); sqlite3_finalize(select_stmt); } @@ -661,9 +661,9 @@ void dc_perform_imap_jobs(dc_context_t* context) { dc_log_info(context, 0, "IMAP-jobs started..."); - pthread_mutex_lock(&context->m_imapidle_condmutex); - context->m_perform_imap_jobs_needed = 0; - pthread_mutex_unlock(&context->m_imapidle_condmutex); + pthread_mutex_lock(&context->imapidle_condmutex); + context->perform_imap_jobs_needed = 0; + pthread_mutex_unlock(&context->imapidle_condmutex); dc_job_perform(context, DC_IMAP_THREAD); @@ -692,13 +692,13 @@ void dc_perform_imap_fetch(dc_context_t* context) dc_log_info(context, 0, "IMAP-fetch started..."); - dc_imap_fetch(context->m_imap); + dc_imap_fetch(context->imap); - if( context->m_imap->m_should_reconnect - && context->m_cb(context, DC_EVENT_IS_OFFLINE, 0, 0)==0 ) + if( context->imap->should_reconnect + && context->cb(context, DC_EVENT_IS_OFFLINE, 0, 0)==0 ) { dc_log_info(context, 0, "IMAP-fetch aborted, starting over..."); - dc_imap_fetch(context->m_imap); + dc_imap_fetch(context->imap); } dc_log_info(context, 0, "IMAP-fetch done in %.0f ms.", (double)(clock()-start)*1000.0/CLOCKS_PER_SEC); @@ -722,17 +722,17 @@ void dc_perform_imap_idle(dc_context_t* context) { connect_to_imap(context, NULL); // also idle if connection fails because of not-configured, no-network, whatever. dc_imap_idle() will handle this by the fake-idle and log a warning - pthread_mutex_lock(&context->m_imapidle_condmutex); - if( context->m_perform_imap_jobs_needed ) { + pthread_mutex_lock(&context->imapidle_condmutex); + if( context->perform_imap_jobs_needed ) { dc_log_info(context, 0, "IMAP-IDLE will not be started because of waiting jobs."); - pthread_mutex_unlock(&context->m_imapidle_condmutex); + pthread_mutex_unlock(&context->imapidle_condmutex); return; } - pthread_mutex_unlock(&context->m_imapidle_condmutex); + pthread_mutex_unlock(&context->imapidle_condmutex); dc_log_info(context, 0, "IMAP-IDLE started..."); - dc_imap_idle(context->m_imap); + dc_imap_idle(context->imap); dc_log_info(context, 0, "IMAP-IDLE ended."); } @@ -774,21 +774,21 @@ void dc_perform_imap_idle(dc_context_t* context) */ void dc_interrupt_imap_idle(dc_context_t* context) { - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || context->m_imap == NULL ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || context->imap == NULL ) { dc_log_warning(context, 0, "Interrupt IMAP-IDLE: Bad parameters."); return; } dc_log_info(context, 0, "Interrupting IMAP-IDLE..."); - pthread_mutex_lock(&context->m_imapidle_condmutex); + pthread_mutex_lock(&context->imapidle_condmutex); // when this function is called, it might be that the idle-thread is in // perform_idle_jobs() instead of idle(). if so, added jobs will be performed after the _next_ idle-jobs loop. // setting the flag perform_imap_jobs_needed makes sure, idle() returns immediately in this case. - context->m_perform_imap_jobs_needed = 1; - pthread_mutex_unlock(&context->m_imapidle_condmutex); + context->perform_imap_jobs_needed = 1; + pthread_mutex_unlock(&context->imapidle_condmutex); - dc_imap_interrupt_idle(context->m_imap); + dc_imap_interrupt_idle(context->imap); } @@ -812,9 +812,9 @@ void dc_perform_smtp_jobs(dc_context_t* context) { dc_log_info(context, 0, "SMTP-jobs started..."); - pthread_mutex_lock(&context->m_smtpidle_condmutex); - context->m_perform_smtp_jobs_needed = 0; - pthread_mutex_unlock(&context->m_smtpidle_condmutex); + pthread_mutex_lock(&context->smtpidle_condmutex); + context->perform_smtp_jobs_needed = 0; + pthread_mutex_unlock(&context->smtpidle_condmutex); dc_job_perform(context, DC_SMTP_THREAD); @@ -835,38 +835,38 @@ void dc_perform_smtp_jobs(dc_context_t* context) */ void dc_perform_smtp_idle(dc_context_t* context) { - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC ) { dc_log_warning(context, 0, "Cannot perform SMTP-idle: Bad parameters."); return; } dc_log_info(context, 0, "SMTP-idle started..."); - pthread_mutex_lock(&context->m_smtpidle_condmutex); + pthread_mutex_lock(&context->smtpidle_condmutex); - if( context->m_perform_smtp_jobs_needed == DC_JOBS_NEEDED_AT_ONCE ) + if( context->perform_smtp_jobs_needed == DC_JOBS_NEEDED_AT_ONCE ) { dc_log_info(context, 0, "SMTP-idle will not be started because of waiting jobs."); } else { - context->m_smtpidle_in_idleing = 1; // checked in suspend(), for idle-interruption the pthread-condition below is used + context->smtpidle_in_idleing = 1; // checked in suspend(), for idle-interruption the pthread-condition below is used do { int r = 0; struct timespec wakeup_at; memset(&wakeup_at, 0, sizeof(wakeup_at)); - wakeup_at.tv_sec = time(NULL) + ((context->m_perform_smtp_jobs_needed==DC_JOBS_NEEDED_AVOID_DOS)? 2 : DC_SMTP_IDLE_SEC); - while (context->m_smtpidle_condflag==0 && r==0) { - r = pthread_cond_timedwait(&context->m_smtpidle_cond, &context->m_smtpidle_condmutex, &wakeup_at); // unlock mutex -> wait -> lock mutex + wakeup_at.tv_sec = time(NULL) + ((context->perform_smtp_jobs_needed==DC_JOBS_NEEDED_AVOID_DOS)? 2 : DC_SMTP_IDLE_SEC); + while (context->smtpidle_condflag==0 && r==0) { + r = pthread_cond_timedwait(&context->smtpidle_cond, &context->smtpidle_condmutex, &wakeup_at); // unlock mutex -> wait -> lock mutex } - } while (context->m_smtpidle_suspend); - context->m_smtpidle_condflag = 0; + } while (context->smtpidle_suspend); + context->smtpidle_condflag = 0; - context->m_smtpidle_in_idleing = 0; + context->smtpidle_in_idleing = 0; } - pthread_mutex_unlock(&context->m_smtpidle_condmutex); + pthread_mutex_unlock(&context->smtpidle_condmutex); dc_log_info(context, 0, "SMTP-idle ended."); } @@ -906,22 +906,22 @@ void dc_perform_smtp_idle(dc_context_t* context) */ void dc_interrupt_smtp_idle(dc_context_t* context) { - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC ) { dc_log_warning(context, 0, "Interrupt SMTP-idle: Bad parameters."); return; } dc_log_info(context, 0, "Interrupting SMTP-idle..."); - pthread_mutex_lock(&context->m_smtpidle_condmutex); + pthread_mutex_lock(&context->smtpidle_condmutex); // when this function is called, it might be that the smtp-thread is in // perform_smtp_jobs(). if so, added jobs will be performed after the _next_ idle-jobs loop. // setting the flag perform_smtp_jobs_needed makes sure, idle() returns immediately in this case. - context->m_perform_smtp_jobs_needed = DC_JOBS_NEEDED_AT_ONCE; + context->perform_smtp_jobs_needed = DC_JOBS_NEEDED_AT_ONCE; - context->m_smtpidle_condflag = 1; - pthread_cond_signal(&context->m_smtpidle_cond); + context->smtpidle_condflag = 1; + pthread_cond_signal(&context->smtpidle_cond); - pthread_mutex_unlock(&context->m_smtpidle_condmutex); + pthread_mutex_unlock(&context->smtpidle_condmutex); } diff --git a/src/dc_job.h b/src/dc_job.h index 99cbd79a..344becf8 100644 --- a/src/dc_job.h +++ b/src/dc_job.h @@ -65,11 +65,11 @@ typedef struct dc_job_t { /** @privatesection */ - uint32_t m_job_id; - int m_action; - uint32_t m_foreign_id; - dc_param_t* m_param; - int m_try_again; + uint32_t job_id; + int action; + uint32_t foreign_id; + dc_param_t* param; + int try_again; } dc_job_t; diff --git a/src/dc_key.c b/src/dc_key.c index 16e27a0b..6ec993c9 100644 --- a/src/dc_key.c +++ b/src/dc_key.c @@ -50,14 +50,14 @@ static void dc_key_empty(dc_key_t* key) /* only use before calling setters; take return; } - if( key->m_type==DC_KEY_PRIVATE ) { - dc_wipe_secret_mem(key->m_binary, key->m_bytes); + if( key->type==DC_KEY_PRIVATE ) { + dc_wipe_secret_mem(key->binary, key->bytes); } - free(key->m_binary); - key->m_binary = NULL; - key->m_bytes = 0; - key->m_type = DC_KEY_PUBLIC; + free(key->binary); + key->binary = NULL; + key->bytes = 0; + key->type = DC_KEY_PUBLIC; } @@ -105,13 +105,13 @@ int dc_key_set_from_binary(dc_key_t* key, const void* data, int bytes, int type) if( key==NULL || data==NULL || bytes <= 0 ) { return 0; } - key->m_binary = malloc(bytes); - if( key->m_binary == NULL ) { + key->binary = malloc(bytes); + if( key->binary == NULL ) { exit(40); } - memcpy(key->m_binary, data, bytes); - key->m_bytes = bytes; - key->m_type = type; + memcpy(key->binary, data, bytes); + key->bytes = bytes; + key->type = type; return 1; } @@ -122,7 +122,7 @@ int dc_key_set_from_key(dc_key_t* key, const dc_key_t* o) if( key==NULL || o==NULL ) { return 0; } - return dc_key_set_from_binary(key, o->m_binary, o->m_bytes, o->m_type); + return dc_key_set_from_binary(key, o->binary, o->bytes, o->type); } @@ -209,19 +209,19 @@ cleanup: int dc_key_equals(const dc_key_t* key, const dc_key_t* o) { if( key==NULL || o==NULL - || key->m_binary==NULL || key->m_bytes<=0 || o->m_binary==NULL || o->m_bytes<=0 ) { + || key->binary==NULL || key->bytes<=0 || o->binary==NULL || o->bytes<=0 ) { return 0; /*error*/ } - if( key->m_bytes != o->m_bytes ) { + if( key->bytes != o->bytes ) { return 0; /*different size -> the keys cannot be equal*/ } - if( key->m_type != o->m_type ) { + if( key->type != o->type ) { return 0; /* cannot compare public with private keys */ } - return memcmp(key->m_binary, o->m_binary, o->m_bytes)==0? 1 : 0; + return memcmp(key->binary, o->binary, o->bytes)==0? 1 : 0; } @@ -236,7 +236,7 @@ int dc_key_save_self_keypair(const dc_key_t* public_key, const dc_key_t* private sqlite3_stmt* stmt = NULL; if( public_key==NULL || private_key==NULL || addr==NULL || sql==NULL - || public_key->m_binary==NULL || private_key->m_binary==NULL ) { + || public_key->binary==NULL || private_key->binary==NULL ) { goto cleanup; } @@ -244,8 +244,8 @@ int dc_key_save_self_keypair(const dc_key_t* public_key, const dc_key_t* private "INSERT INTO keypairs (addr, is_default, public_key, private_key, created) VALUES (?,?,?,?,?);"); sqlite3_bind_text (stmt, 1, addr, -1, SQLITE_STATIC); sqlite3_bind_int (stmt, 2, is_default); - sqlite3_bind_blob (stmt, 3, public_key->m_binary, public_key->m_bytes, SQLITE_STATIC); - sqlite3_bind_blob (stmt, 4, private_key->m_binary, private_key->m_bytes, SQLITE_STATIC); + sqlite3_bind_blob (stmt, 3, public_key->binary, public_key->bytes, SQLITE_STATIC); + sqlite3_bind_blob (stmt, 4, private_key->binary, private_key->bytes, SQLITE_STATIC); sqlite3_bind_int64(stmt, 5, time(NULL)); if( sqlite3_step(stmt) != SQLITE_DONE ) { goto cleanup; @@ -389,7 +389,7 @@ char* dc_key_render_base64(const dc_key_t* key, int break_every, const char* bre if( key==NULL ) { return NULL; } - return dc_render_base64(key->m_binary, key->m_bytes, break_every, break_chars, add_checksum); + return dc_render_base64(key->binary, key->bytes, break_every, break_chars, add_checksum); } @@ -407,10 +407,10 @@ char* dc_key_render_asc(const dc_key_t* key, const char* add_header_lines /*must } ret = dc_mprintf("-----BEGIN PGP %s KEY BLOCK-----\r\n%s\r\n%s\r\n-----END PGP %s KEY BLOCK-----\r\n", - key->m_type==DC_KEY_PUBLIC? "PUBLIC" : "PRIVATE", + key->type==DC_KEY_PUBLIC? "PUBLIC" : "PRIVATE", add_header_lines? add_header_lines : "", base64, - key->m_type==DC_KEY_PUBLIC? "PUBLIC" : "PRIVATE"); + key->type==DC_KEY_PUBLIC? "PUBLIC" : "PRIVATE"); cleanup: free(base64); @@ -463,7 +463,7 @@ char* dc_format_fingerprint(const char* fingerprint) } } - return ret.m_buf; + return ret.buf; } @@ -486,7 +486,7 @@ char* dc_normalize_fingerprint(const char* in) p1++; } - return out.m_buf; + return out.buf; } diff --git a/src/dc_key.h b/src/dc_key.h index db2bbda6..be50fedb 100644 --- a/src/dc_key.h +++ b/src/dc_key.h @@ -39,9 +39,9 @@ typedef struct sqlite3_stmt sqlite3_stmt; */ typedef struct dc_key_t { - void* m_binary; - int m_bytes; - int m_type; + void* binary; + int bytes; + int type; /** @privatesection */ int _m_heap_refcnt; /* !=0 for objects created with dc_key_new(), 0 for stack objects */ diff --git a/src/dc_keyring.c b/src/dc_keyring.c index b839c788..5a455c17 100644 --- a/src/dc_keyring.c +++ b/src/dc_keyring.c @@ -50,10 +50,10 @@ void dc_keyring_unref(dc_keyring_t* keyring) return; } - for( i = 0; i < keyring->m_count; i++ ) { - dc_key_unref(keyring->m_keys[i]); + for( i = 0; i < keyring->count; i++ ) { + dc_key_unref(keyring->keys[i]); } - free(keyring->m_keys); + free(keyring->keys); free(keyring); } @@ -65,16 +65,16 @@ void dc_keyring_add(dc_keyring_t* keyring, dc_key_t* to_add) } /* expand array, if needed */ - if( keyring->m_count == keyring->m_allocated ) { - int newsize = (keyring->m_allocated * 2) + 10; - if( (keyring->m_keys=realloc(keyring->m_keys, newsize*sizeof(dc_key_t*)))==NULL ) { + if( keyring->count == keyring->allocated ) { + int newsize = (keyring->allocated * 2) + 10; + if( (keyring->keys=realloc(keyring->keys, newsize*sizeof(dc_key_t*)))==NULL ) { exit(41); } - keyring->m_allocated = newsize; + keyring->allocated = newsize; } - keyring->m_keys[keyring->m_count] = dc_key_ref(to_add); - keyring->m_count++; + keyring->keys[keyring->count] = dc_key_ref(to_add); + keyring->count++; } diff --git a/src/dc_keyring.h b/src/dc_keyring.h index ab70a1af..cc73aac6 100644 --- a/src/dc_keyring.h +++ b/src/dc_keyring.h @@ -37,9 +37,9 @@ typedef struct dc_keyring_t { /** @privatesection */ - dc_key_t** m_keys; /**< Keys in the keyring. Only pointers to keys, the caller is responsible for freeing them and should make sure, the pointers are valid as long as the keyring is valid. */ - int m_count; - int m_allocated; + dc_key_t** keys; /**< Keys in the keyring. Only pointers to keys, the caller is responsible for freeing them and should make sure, the pointers are valid as long as the keyring is valid. */ + int count; + int allocated; } dc_keyring_t; dc_keyring_t* dc_keyring_new (); diff --git a/src/dc_log.c b/src/dc_log.c index 7526df07..216f992a 100644 --- a/src/dc_log.c +++ b/src/dc_log.c @@ -43,7 +43,7 @@ static void log_vprintf(dc_context_t* context, int event, int code, const char* { char* msg = NULL; - if( context==NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context==NULL || context->magic != DC_CONTEXT_MAGIC ) { return; } @@ -72,15 +72,15 @@ static void log_vprintf(dc_context_t* context, int event, int code, const char* } /* finally, log */ - context->m_cb(context, event, (uintptr_t)code, (uintptr_t)msg); + context->cb(context, event, (uintptr_t)code, (uintptr_t)msg); /* remember the last N log entries */ - pthread_mutex_lock(&context->m_log_ringbuf_critical); - free(context->m_log_ringbuf[context->m_log_ringbuf_pos]); - context->m_log_ringbuf[context->m_log_ringbuf_pos] = msg; - context->m_log_ringbuf_times[context->m_log_ringbuf_pos] = time(NULL); - context->m_log_ringbuf_pos = (context->m_log_ringbuf_pos+1) % DC_LOG_RINGBUF_SIZE; - pthread_mutex_unlock(&context->m_log_ringbuf_critical); + pthread_mutex_lock(&context->log_ringbuf_critical); + free(context->log_ringbuf[context->log_ringbuf_pos]); + context->log_ringbuf[context->log_ringbuf_pos] = msg; + context->log_ringbuf_times[context->log_ringbuf_pos] = time(NULL); + context->log_ringbuf_pos = (context->log_ringbuf_pos+1) % DC_LOG_RINGBUF_SIZE; + pthread_mutex_unlock(&context->log_ringbuf_critical); } @@ -114,7 +114,7 @@ void dc_log_error(dc_context_t* context, int code, const char* msg, ...) void dc_log_error_if(int* condition, dc_context_t* context, int code, const char* msg, ...) { - if( condition == NULL || context==NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( condition == NULL || context==NULL || context->magic != DC_CONTEXT_MAGIC ) { return; } @@ -122,7 +122,7 @@ void dc_log_error_if(int* condition, dc_context_t* context, int code, const char va_start(va, msg); if( *condition ) { /* pop-up error, if we're offline, force a "not connected" error (the function is not used for other cases) */ - if( context->m_cb(context, DC_EVENT_IS_OFFLINE, 0, 0)!=0 ) { + if( context->cb(context, DC_EVENT_IS_OFFLINE, 0, 0)!=0 ) { log_vprintf(context, DC_EVENT_ERROR, DC_ERROR_NO_NETWORK, NULL, va); } else { diff --git a/src/dc_loginparam.c b/src/dc_loginparam.c index 8afdc653..869f8044 100644 --- a/src/dc_loginparam.c +++ b/src/dc_loginparam.c @@ -58,16 +58,16 @@ void dc_loginparam_empty(dc_loginparam_t* loginparam) return; /* ok, but nothing to do */ } - free(loginparam->m_addr); loginparam->m_addr = NULL; - free(loginparam->m_mail_server); loginparam->m_mail_server = NULL; - loginparam->m_mail_port = 0; - free(loginparam->m_mail_user); loginparam->m_mail_user = NULL; - free(loginparam->m_mail_pw); loginparam->m_mail_pw = NULL; - free(loginparam->m_send_server); loginparam->m_send_server = NULL; - loginparam->m_send_port = 0; - free(loginparam->m_send_user); loginparam->m_send_user = NULL; - free(loginparam->m_send_pw); loginparam->m_send_pw = NULL; - loginparam->m_server_flags= 0; + free(loginparam->addr); loginparam->addr = NULL; + free(loginparam->mail_server); loginparam->mail_server = NULL; + loginparam->mail_port = 0; + free(loginparam->mail_user); loginparam->mail_user = NULL; + free(loginparam->mail_pw); loginparam->mail_pw = NULL; + free(loginparam->send_server); loginparam->send_server = NULL; + loginparam->send_port = 0; + free(loginparam->send_user); loginparam->send_user = NULL; + free(loginparam->send_pw); loginparam->send_pw = NULL; + loginparam->server_flags= 0; } @@ -78,19 +78,19 @@ void dc_loginparam_read(dc_loginparam_t* loginparam, dc_sqlite3_t* sql, const ch dc_loginparam_empty(loginparam); - LP_PREFIX("addr"); loginparam->m_addr = dc_sqlite3_get_config (sql, key, NULL); + LP_PREFIX("addr"); loginparam->addr = dc_sqlite3_get_config (sql, key, NULL); - LP_PREFIX("mail_server"); loginparam->m_mail_server = dc_sqlite3_get_config (sql, key, NULL); - LP_PREFIX("mail_port"); loginparam->m_mail_port = dc_sqlite3_get_config_int (sql, key, 0); - LP_PREFIX("mail_user"); loginparam->m_mail_user = dc_sqlite3_get_config (sql, key, NULL); - LP_PREFIX("mail_pw"); loginparam->m_mail_pw = dc_sqlite3_get_config (sql, key, NULL); + LP_PREFIX("mail_server"); loginparam->mail_server = dc_sqlite3_get_config (sql, key, NULL); + LP_PREFIX("mail_port"); loginparam->mail_port = dc_sqlite3_get_config_int (sql, key, 0); + LP_PREFIX("mail_user"); loginparam->mail_user = dc_sqlite3_get_config (sql, key, NULL); + LP_PREFIX("mail_pw"); loginparam->mail_pw = dc_sqlite3_get_config (sql, key, NULL); - LP_PREFIX("send_server"); loginparam->m_send_server = dc_sqlite3_get_config (sql, key, NULL); - LP_PREFIX("send_port"); loginparam->m_send_port = dc_sqlite3_get_config_int (sql, key, 0); - LP_PREFIX("send_user"); loginparam->m_send_user = dc_sqlite3_get_config (sql, key, NULL); - LP_PREFIX("send_pw"); loginparam->m_send_pw = dc_sqlite3_get_config (sql, key, NULL); + LP_PREFIX("send_server"); loginparam->send_server = dc_sqlite3_get_config (sql, key, NULL); + LP_PREFIX("send_port"); loginparam->send_port = dc_sqlite3_get_config_int (sql, key, 0); + LP_PREFIX("send_user"); loginparam->send_user = dc_sqlite3_get_config (sql, key, NULL); + LP_PREFIX("send_pw"); loginparam->send_pw = dc_sqlite3_get_config (sql, key, NULL); - LP_PREFIX("server_flags");loginparam->m_server_flags= dc_sqlite3_get_config_int (sql, key, 0); + LP_PREFIX("server_flags");loginparam->server_flags= dc_sqlite3_get_config_int (sql, key, 0); sqlite3_free(key); } @@ -100,19 +100,19 @@ void dc_loginparam_write(const dc_loginparam_t* loginparam, dc_sqlite3_t* sql, c { char* key = NULL; - LP_PREFIX("addr"); dc_sqlite3_set_config (sql, key, loginparam->m_addr); + LP_PREFIX("addr"); dc_sqlite3_set_config (sql, key, loginparam->addr); - LP_PREFIX("mail_server"); dc_sqlite3_set_config (sql, key, loginparam->m_mail_server); - LP_PREFIX("mail_port"); dc_sqlite3_set_config_int (sql, key, loginparam->m_mail_port); - LP_PREFIX("mail_user"); dc_sqlite3_set_config (sql, key, loginparam->m_mail_user); - LP_PREFIX("mail_pw"); dc_sqlite3_set_config (sql, key, loginparam->m_mail_pw); + LP_PREFIX("mail_server"); dc_sqlite3_set_config (sql, key, loginparam->mail_server); + LP_PREFIX("mail_port"); dc_sqlite3_set_config_int (sql, key, loginparam->mail_port); + LP_PREFIX("mail_user"); dc_sqlite3_set_config (sql, key, loginparam->mail_user); + LP_PREFIX("mail_pw"); dc_sqlite3_set_config (sql, key, loginparam->mail_pw); - LP_PREFIX("send_server"); dc_sqlite3_set_config (sql, key, loginparam->m_send_server); - LP_PREFIX("send_port"); dc_sqlite3_set_config_int (sql, key, loginparam->m_send_port); - LP_PREFIX("send_user"); dc_sqlite3_set_config (sql, key, loginparam->m_send_user); - LP_PREFIX("send_pw"); dc_sqlite3_set_config (sql, key, loginparam->m_send_pw); + LP_PREFIX("send_server"); dc_sqlite3_set_config (sql, key, loginparam->send_server); + LP_PREFIX("send_port"); dc_sqlite3_set_config_int (sql, key, loginparam->send_port); + LP_PREFIX("send_user"); dc_sqlite3_set_config (sql, key, loginparam->send_user); + LP_PREFIX("send_pw"); dc_sqlite3_set_config (sql, key, loginparam->send_pw); - LP_PREFIX("server_flags"); dc_sqlite3_set_config_int (sql, key, loginparam->m_server_flags); + LP_PREFIX("server_flags"); dc_sqlite3_set_config_int (sql, key, loginparam->server_flags); sqlite3_free(key); } @@ -150,9 +150,9 @@ static char* get_readable_flags(int flags) } } - if( strbuilder.m_buf[0]==0 ) { dc_strbuilder_cat(&strbuilder, "0"); } - dc_trim(strbuilder.m_buf); - return strbuilder.m_buf; + if( strbuilder.buf[0]==0 ) { dc_strbuilder_cat(&strbuilder, "0"); } + dc_trim(strbuilder.buf); + return strbuilder.buf; } @@ -165,20 +165,20 @@ char* dc_loginparam_get_readable(const dc_loginparam_t* loginparam) return dc_strdup(NULL); } - char* flags_readable = get_readable_flags(loginparam->m_server_flags); + char* flags_readable = get_readable_flags(loginparam->server_flags); char* ret = dc_mprintf("%s %s:%s:%s:%i %s:%s:%s:%i %s", - loginparam->m_addr? loginparam->m_addr : unset, + loginparam->addr? loginparam->addr : unset, - loginparam->m_mail_user? loginparam->m_mail_user : unset, - loginparam->m_mail_pw? pw : unset, - loginparam->m_mail_server? loginparam->m_mail_server : unset, - loginparam->m_mail_port, + loginparam->mail_user? loginparam->mail_user : unset, + loginparam->mail_pw? pw : unset, + loginparam->mail_server? loginparam->mail_server : unset, + loginparam->mail_port, - loginparam->m_send_user? loginparam->m_send_user : unset, - loginparam->m_send_pw? pw : unset, - loginparam->m_send_server? loginparam->m_send_server : unset, - loginparam->m_send_port, + loginparam->send_user? loginparam->send_user : unset, + loginparam->send_pw? pw : unset, + loginparam->send_server? loginparam->send_server : unset, + loginparam->send_port, flags_readable); diff --git a/src/dc_loginparam.h b/src/dc_loginparam.h index 4f89cbe1..0d71c98f 100644 --- a/src/dc_loginparam.h +++ b/src/dc_loginparam.h @@ -35,17 +35,17 @@ typedef struct dc_loginparam_t /** @privatesection */ /* IMAP/POP3 - all pointers may be NULL if unset, public read */ - char* m_addr; - char* m_mail_server; - char* m_mail_user; - char* m_mail_pw; - uint16_t m_mail_port; + char* addr; + char* mail_server; + char* mail_user; + char* mail_pw; + uint16_t mail_port; /* SMTP - all pointers may be NULL if unset, public read */ - char* m_send_server; - char* m_send_user; - char* m_send_pw; - int m_send_port; + char* send_server; + char* send_user; + char* send_pw; + int send_port; /* Server options*/ #define DC_LP_AUTH_XOAUTH2 0x2 @@ -65,7 +65,7 @@ typedef struct dc_loginparam_t #define DC_NO_EXTRA_IMAP_UPLOAD 0x2000000 #define DC_NO_MOVE_TO_CHATS 0x4000000 - int m_server_flags; + int server_flags; } dc_loginparam_t; diff --git a/src/dc_lot.c b/src/dc_lot.c index 177f84a1..d52ff8e2 100644 --- a/src/dc_lot.c +++ b/src/dc_lot.c @@ -34,8 +34,8 @@ dc_lot_t* dc_lot_new() exit(27); /* cannot allocate little memory, unrecoverable error */ } - lot->m_magic = DC_LOT_MAGIC; - lot->m_text1_meaning = 0; + lot->magic = DC_LOT_MAGIC; + lot->text1_meaning = 0; return lot; } @@ -53,41 +53,41 @@ dc_lot_t* dc_lot_new() */ void dc_lot_unref(dc_lot_t* set) { - if( set==NULL || set->m_magic != DC_LOT_MAGIC ) { + if( set==NULL || set->magic != DC_LOT_MAGIC ) { return; } dc_lot_empty(set); - set->m_magic = 0; + set->magic = 0; free(set); } void dc_lot_empty(dc_lot_t* lot) { - if( lot == NULL || lot->m_magic != DC_LOT_MAGIC ) { + if( lot == NULL || lot->magic != DC_LOT_MAGIC ) { return; } - free(lot->m_text1); - lot->m_text1 = NULL; - lot->m_text1_meaning = 0; + free(lot->text1); + lot->text1 = NULL; + lot->text1_meaning = 0; - free(lot->m_text2); - lot->m_text2 = NULL; + free(lot->text2); + lot->text2 = NULL; - free(lot->m_fingerprint); - lot->m_fingerprint = NULL; + free(lot->fingerprint); + lot->fingerprint = NULL; - free(lot->m_invitenumber); - lot->m_invitenumber = NULL; + free(lot->invitenumber); + lot->invitenumber = NULL; - free(lot->m_auth); - lot->m_auth = NULL; + free(lot->auth); + lot->auth = NULL; - lot->m_timestamp = 0; - lot->m_state = 0; - lot->m_id = 0; + lot->timestamp = 0; + lot->state = 0; + lot->id = 0; } @@ -100,10 +100,10 @@ void dc_lot_empty(dc_lot_t* lot) */ char* dc_lot_get_text1(dc_lot_t* lot) { - if( lot == NULL || lot->m_magic != DC_LOT_MAGIC ) { + if( lot == NULL || lot->magic != DC_LOT_MAGIC ) { return NULL; } - return dc_strdup_keep_null(lot->m_text1); + return dc_strdup_keep_null(lot->text1); } @@ -118,10 +118,10 @@ char* dc_lot_get_text1(dc_lot_t* lot) */ char* dc_lot_get_text2(dc_lot_t* lot) { - if( lot == NULL || lot->m_magic != DC_LOT_MAGIC ) { + if( lot == NULL || lot->magic != DC_LOT_MAGIC ) { return NULL; } - return dc_strdup_keep_null(lot->m_text2); + return dc_strdup_keep_null(lot->text2); } @@ -136,10 +136,10 @@ char* dc_lot_get_text2(dc_lot_t* lot) */ int dc_lot_get_text1_meaning(dc_lot_t* lot) { - if( lot == NULL || lot->m_magic != DC_LOT_MAGIC ) { + if( lot == NULL || lot->magic != DC_LOT_MAGIC ) { return 0; } - return lot->m_text1_meaning; + return lot->text1_meaning; } @@ -154,10 +154,10 @@ int dc_lot_get_text1_meaning(dc_lot_t* lot) */ int dc_lot_get_state(dc_lot_t* lot) { - if( lot == NULL || lot->m_magic != DC_LOT_MAGIC ) { + if( lot == NULL || lot->magic != DC_LOT_MAGIC ) { return 0; } - return lot->m_state; + return lot->state; } @@ -170,10 +170,10 @@ int dc_lot_get_state(dc_lot_t* lot) */ uint32_t dc_lot_get_id(dc_lot_t* lot) { - if( lot == NULL || lot->m_magic != DC_LOT_MAGIC ) { + if( lot == NULL || lot->magic != DC_LOT_MAGIC ) { return 0; } - return lot->m_id; + return lot->id; } @@ -188,48 +188,48 @@ uint32_t dc_lot_get_id(dc_lot_t* lot) */ time_t dc_lot_get_timestamp(dc_lot_t* lot) { - if( lot == NULL || lot->m_magic != DC_LOT_MAGIC ) { + if( lot == NULL || lot->magic != DC_LOT_MAGIC ) { return 0; } - return lot->m_timestamp; + return lot->timestamp; } void dc_lot_fill(dc_lot_t* lot, const dc_msg_t* msg, const dc_chat_t* chat, const dc_contact_t* contact, dc_context_t* context) { - if( lot == NULL || lot->m_magic != DC_LOT_MAGIC || msg == NULL ) { + if( lot == NULL || lot->magic != DC_LOT_MAGIC || msg == NULL ) { return; } - if( msg->m_from_id == DC_CONTACT_ID_SELF ) + if( msg->from_id == DC_CONTACT_ID_SELF ) { if( dc_msg_is_info(msg) ) { - lot->m_text1 = NULL; - lot->m_text1_meaning = 0; + lot->text1 = NULL; + lot->text1_meaning = 0; } else { - lot->m_text1 = dc_stock_str(context, DC_STR_SELF); - lot->m_text1_meaning = DC_TEXT1_SELF; + lot->text1 = dc_stock_str(context, DC_STR_SELF); + lot->text1_meaning = DC_TEXT1_SELF; } } else if( chat == NULL ) { - lot->m_text1 = NULL; - lot->m_text1_meaning = 0; + lot->text1 = NULL; + lot->text1_meaning = 0; } - else if( DC_CHAT_TYPE_IS_MULTI(chat->m_type) ) + else if( DC_CHAT_TYPE_IS_MULTI(chat->type) ) { if( dc_msg_is_info(msg) || contact==NULL ) { - lot->m_text1 = NULL; - lot->m_text1_meaning = 0; + lot->text1 = NULL; + lot->text1_meaning = 0; } else { - lot->m_text1 = dc_contact_get_first_name(contact); - lot->m_text1_meaning = DC_TEXT1_USERNAME; + lot->text1 = dc_contact_get_first_name(contact); + lot->text1_meaning = DC_TEXT1_USERNAME; } } - lot->m_text2 = dc_msg_get_summarytext_by_raw(msg->m_type, msg->m_text, msg->m_param, DC_SUMMARY_CHARACTERS, context); - lot->m_timestamp = dc_msg_get_timestamp(msg); - lot->m_state = msg->m_state; + lot->text2 = dc_msg_get_summarytext_by_raw(msg->type, msg->text, msg->param, DC_SUMMARY_CHARACTERS, context); + lot->timestamp = dc_msg_get_timestamp(msg); + lot->state = msg->state; } diff --git a/src/dc_lot.h b/src/dc_lot.h index 4f753ec1..34329161 100644 --- a/src/dc_lot.h +++ b/src/dc_lot.h @@ -31,18 +31,18 @@ extern "C" { struct _dc_lot { /** @privatesection */ - uint32_t m_magic; /**< The magic is used to avoid passing structures of different types. */ - int m_text1_meaning; /**< The meaning of this value is defined by the creator of the object. 0 if not applicable. */ - char* m_text1; /**< The meaning of this string is defined by the creator of the object. The string is freed with dc_lot_unref(). NULL if not applicable. */ - char* m_text2; /**< The meaning of this string is defined by the creator of the object. The string is freed with dc_lot_unref(). NULL if not applicable. */ - time_t m_timestamp; /**< The meaning of this value is defined by the creator of the object. 0 if not applicable. */ - int m_state; /**< The meaning of this value is defined by the creator of the object. 0 if not applicable. */ + uint32_t magic; /**< The magic is used to avoid passing structures of different types. */ + int text1_meaning; /**< The meaning of this value is defined by the creator of the object. 0 if not applicable. */ + char* text1; /**< The meaning of this string is defined by the creator of the object. The string is freed with dc_lot_unref(). NULL if not applicable. */ + char* text2; /**< The meaning of this string is defined by the creator of the object. The string is freed with dc_lot_unref(). NULL if not applicable. */ + time_t timestamp; /**< The meaning of this value is defined by the creator of the object. 0 if not applicable. */ + int state; /**< The meaning of this value is defined by the creator of the object. 0 if not applicable. */ - uint32_t m_id; /**< The meaning of this value is defined by the creator of the object. 0 if not applicable. */ + uint32_t id; /**< The meaning of this value is defined by the creator of the object. 0 if not applicable. */ - char* m_fingerprint; /**< used for qr code scanning only */ - char* m_invitenumber; /**< used for qr code scanning only */ - char* m_auth; /**< used for qr code scanning only */ + char* fingerprint; /**< used for qr code scanning only */ + char* invitenumber; /**< used for qr code scanning only */ + char* auth; /**< used for qr code scanning only */ }; diff --git a/src/dc_mimefactory.c b/src/dc_mimefactory.c index d12eedd1..cd43a6e1 100644 --- a/src/dc_mimefactory.c +++ b/src/dc_mimefactory.c @@ -41,7 +41,7 @@ void dc_mimefactory_init(dc_mimefactory_t* factory, dc_context_t* context) } memset(factory, 0, sizeof(dc_mimefactory_t)); - factory->m_context = context; + factory->context = context; } @@ -51,52 +51,52 @@ void dc_mimefactory_empty(dc_mimefactory_t* factory) return; } - free(factory->m_from_addr); - factory->m_from_addr = NULL; + free(factory->from_addr); + factory->from_addr = NULL; - free(factory->m_from_displayname); - factory->m_from_displayname = NULL; + free(factory->from_displayname); + factory->from_displayname = NULL; - free(factory->m_selfstatus); - factory->m_selfstatus = NULL; + free(factory->selfstatus); + factory->selfstatus = NULL; - if( factory->m_recipients_names ) { - clist_free_content(factory->m_recipients_names); - clist_free(factory->m_recipients_names); - factory->m_recipients_names = NULL; + if( factory->recipients_names ) { + clist_free_content(factory->recipients_names); + clist_free(factory->recipients_names); + factory->recipients_names = NULL; } - if( factory->m_recipients_addr ) { - clist_free_content(factory->m_recipients_addr); - clist_free(factory->m_recipients_addr); - factory->m_recipients_addr = NULL; + if( factory->recipients_addr ) { + clist_free_content(factory->recipients_addr); + clist_free(factory->recipients_addr); + factory->recipients_addr = NULL; } - dc_msg_unref(factory->m_msg); - factory->m_msg = NULL; + dc_msg_unref(factory->msg); + factory->msg = NULL; - dc_chat_unref(factory->m_chat); - factory->m_chat = NULL; + dc_chat_unref(factory->chat); + factory->chat = NULL; - if( factory->m_out ) { - mmap_string_free(factory->m_out); - factory->m_out = NULL; + if( factory->out ) { + mmap_string_free(factory->out); + factory->out = NULL; } - factory->m_out_encrypted = 0; - factory->m_loaded = DC_MF_NOTHING_LOADED; + factory->out_encrypted = 0; + factory->loaded = DC_MF_NOTHING_LOADED; - factory->m_timestamp = 0; + factory->timestamp = 0; } static void load_from__(dc_mimefactory_t* factory) { - factory->m_from_addr = dc_sqlite3_get_config(factory->m_context->m_sql, "configured_addr", NULL); - factory->m_from_displayname = dc_sqlite3_get_config(factory->m_context->m_sql, "displayname", NULL); + factory->from_addr = dc_sqlite3_get_config(factory->context->sql, "configured_addr", NULL); + factory->from_displayname = dc_sqlite3_get_config(factory->context->sql, "displayname", NULL); - factory->m_selfstatus = dc_sqlite3_get_config(factory->m_context->m_sql, "selfstatus", NULL); - if( factory->m_selfstatus == NULL ) { - factory->m_selfstatus = dc_stock_str(factory->m_context, DC_STR_STATUSLINE); + factory->selfstatus = dc_sqlite3_get_config(factory->context->sql, "selfstatus", NULL); + if( factory->selfstatus == NULL ) { + factory->selfstatus = dc_stock_str(factory->context, DC_STR_STATUSLINE); } } @@ -107,61 +107,61 @@ int dc_mimefactory_load_msg(dc_mimefactory_t* factory, uint32_t msg_id) sqlite3_stmt* stmt = NULL; if( factory == NULL || msg_id <= DC_MSG_ID_LAST_SPECIAL - || factory->m_context == NULL - || factory->m_msg /*call empty() before */ ) { + || factory->context == NULL + || factory->msg /*call empty() before */ ) { goto cleanup; } - dc_context_t* context = factory->m_context; + dc_context_t* context = factory->context; - factory->m_recipients_names = clist_new(); - factory->m_recipients_addr = clist_new(); - factory->m_msg = dc_msg_new(); - factory->m_chat = dc_chat_new(context); + factory->recipients_names = clist_new(); + factory->recipients_addr = clist_new(); + factory->msg = dc_msg_new(); + factory->chat = dc_chat_new(context); - if( dc_msg_load_from_db(factory->m_msg, context, msg_id) - && dc_chat_load_from_db(factory->m_chat, factory->m_msg->m_chat_id) ) + if( dc_msg_load_from_db(factory->msg, context, msg_id) + && dc_chat_load_from_db(factory->chat, factory->msg->chat_id) ) { load_from__(factory); - factory->m_req_mdn = 0; + factory->req_mdn = 0; - if( dc_chat_is_self_talk(factory->m_chat) ) + if( dc_chat_is_self_talk(factory->chat) ) { - clist_append(factory->m_recipients_names, (void*)dc_strdup_keep_null(factory->m_from_displayname)); - clist_append(factory->m_recipients_addr, (void*)dc_strdup(factory->m_from_addr)); + clist_append(factory->recipients_names, (void*)dc_strdup_keep_null(factory->from_displayname)); + clist_append(factory->recipients_addr, (void*)dc_strdup(factory->from_addr)); } else { - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT c.authname, c.addr " " FROM chats_contacts cc " " LEFT JOIN contacts c ON cc.contact_id=c.id " " WHERE cc.chat_id=? AND cc.contact_id>" DC_STRINGIFY(DC_CONTACT_ID_LAST_SPECIAL) ";"); - sqlite3_bind_int(stmt, 1, factory->m_msg->m_chat_id); + sqlite3_bind_int(stmt, 1, factory->msg->chat_id); while( sqlite3_step(stmt) == SQLITE_ROW ) { const char* authname = (const char*)sqlite3_column_text(stmt, 0); const char* addr = (const char*)sqlite3_column_text(stmt, 1); - if( clist_search_string_nocase(factory->m_recipients_addr, addr)==0 ) + if( clist_search_string_nocase(factory->recipients_addr, addr)==0 ) { - clist_append(factory->m_recipients_names, (void*)((authname&&authname[0])? dc_strdup(authname) : NULL)); - clist_append(factory->m_recipients_addr, (void*)dc_strdup(addr)); + clist_append(factory->recipients_names, (void*)((authname&&authname[0])? dc_strdup(authname) : NULL)); + clist_append(factory->recipients_addr, (void*)dc_strdup(addr)); } } sqlite3_finalize(stmt); stmt = NULL; - int command = dc_param_get_int(factory->m_msg->m_param, DC_PARAM_CMD, 0); + int command = dc_param_get_int(factory->msg->param, DC_PARAM_CMD, 0); if( command==DC_CMD_MEMBER_REMOVED_FROM_GROUP /* for added members, the list is just fine */) { - char* email_to_remove = dc_param_get(factory->m_msg->m_param, DC_PARAM_CMD_ARG, NULL); - char* self_addr = dc_sqlite3_get_config(context->m_sql, "configured_addr", ""); + char* email_to_remove = dc_param_get(factory->msg->param, DC_PARAM_CMD_ARG, NULL); + char* self_addr = dc_sqlite3_get_config(context->sql, "configured_addr", ""); if( email_to_remove && strcasecmp(email_to_remove, self_addr)!=0 ) { - if( clist_search_string_nocase(factory->m_recipients_addr, email_to_remove)==0 ) + if( clist_search_string_nocase(factory->recipients_addr, email_to_remove)==0 ) { - clist_append(factory->m_recipients_names, NULL); - clist_append(factory->m_recipients_addr, (void*)email_to_remove); + clist_append(factory->recipients_names, NULL); + clist_append(factory->recipients_addr, (void*)email_to_remove); } } free(self_addr); @@ -169,8 +169,8 @@ int dc_mimefactory_load_msg(dc_mimefactory_t* factory, uint32_t msg_id) if( command!=DC_CMD_AUTOCRYPT_SETUP_MESSAGE && command!=DC_CMD_SECUREJOIN_MESSAGE - && dc_sqlite3_get_config_int(context->m_sql, "mdns_enabled", DC_MDNS_DEFAULT_ENABLED) ) { - factory->m_req_mdn = 1; + && dc_sqlite3_get_config_int(context->sql, "mdns_enabled", DC_MDNS_DEFAULT_ENABLED) ) { + factory->req_mdn = 1; } } @@ -186,12 +186,12 @@ int dc_mimefactory_load_msg(dc_mimefactory_t* factory, uint32_t msg_id) Finally, maybe the Predecessor/In-Reply-To header is not needed for all answers but only to the first ones - or after the sender has changes its email address. */ - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT rfc724_mid FROM msgs WHERE timestamp=(SELECT max(timestamp) FROM msgs WHERE chat_id=? AND from_id!=?);"); - sqlite3_bind_int (stmt, 1, factory->m_msg->m_chat_id); + sqlite3_bind_int (stmt, 1, factory->msg->chat_id); sqlite3_bind_int (stmt, 2, DC_CONTACT_ID_SELF); if( sqlite3_step(stmt) == SQLITE_ROW ) { - factory->m_predecessor = dc_strdup_keep_null((const char*)sqlite3_column_text(stmt, 0)); + factory->predecessor = dc_strdup_keep_null((const char*)sqlite3_column_text(stmt, 0)); } sqlite3_finalize(stmt); stmt = NULL; @@ -204,10 +204,10 @@ int dc_mimefactory_load_msg(dc_mimefactory_t* factory, uint32_t msg_id) however one could also see this as a feature :) (there may be different contextes on different clients) (also, the References-header is not the most important thing, and, at least for now, we do not want to make things too complicated. */ time_t prev_msg_time = 0; - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT max(timestamp) FROM msgs WHERE chat_id=? AND id!=?"); - sqlite3_bind_int (stmt, 1, factory->m_msg->m_chat_id); - sqlite3_bind_int (stmt, 2, factory->m_msg->m_id); + sqlite3_bind_int (stmt, 1, factory->msg->chat_id); + sqlite3_bind_int (stmt, 2, factory->msg->id); if( sqlite3_step(stmt) == SQLITE_ROW ) { prev_msg_time = sqlite3_column_int64(stmt, 0); } @@ -215,24 +215,24 @@ int dc_mimefactory_load_msg(dc_mimefactory_t* factory, uint32_t msg_id) stmt = NULL; #define NEW_THREAD_THRESHOLD 24*60*60 - if( prev_msg_time != 0 && factory->m_msg->m_timestamp - prev_msg_time < NEW_THREAD_THRESHOLD ) { - factory->m_references = dc_param_get(factory->m_chat->m_param, DC_PARAM_REFERENCES, NULL); + if( prev_msg_time != 0 && factory->msg->timestamp - prev_msg_time < NEW_THREAD_THRESHOLD ) { + factory->references = dc_param_get(factory->chat->param, DC_PARAM_REFERENCES, NULL); } - if( factory->m_references == NULL ) { - factory->m_references = dc_create_dummy_references_mid(); - dc_param_set(factory->m_chat->m_param, DC_PARAM_REFERENCES, factory->m_references); - dc_chat_update_param(factory->m_chat); + if( factory->references == NULL ) { + factory->references = dc_create_dummy_references_mid(); + dc_param_set(factory->chat->param, DC_PARAM_REFERENCES, factory->references); + dc_chat_update_param(factory->chat); } success = 1; - factory->m_loaded = DC_MF_MSG_LOADED; - factory->m_timestamp = factory->m_msg->m_timestamp; - factory->m_rfc724_mid = dc_strdup(factory->m_msg->m_rfc724_mid); + factory->loaded = DC_MF_MSG_LOADED; + factory->timestamp = factory->msg->timestamp; + factory->rfc724_mid = dc_strdup(factory->msg->rfc724_mid); } if( success ) { - factory->m_increation = dc_msg_is_increation(factory->m_msg); + factory->increation = dc_msg_is_increation(factory->msg); } cleanup: @@ -244,46 +244,46 @@ cleanup: int dc_mimefactory_load_mdn(dc_mimefactory_t* factory, uint32_t msg_id) { int success = 0; - dc_contact_t* contact = dc_contact_new(factory->m_context); + dc_contact_t* contact = dc_contact_new(factory->context); if( factory == NULL ) { goto cleanup; } - dc_context_t* context = factory->m_context; + dc_context_t* context = factory->context; - factory->m_recipients_names = clist_new(); - factory->m_recipients_addr = clist_new(); - factory->m_msg = dc_msg_new(); + factory->recipients_names = clist_new(); + factory->recipients_addr = clist_new(); + factory->msg = dc_msg_new(); - if( !dc_sqlite3_get_config_int(context->m_sql, "mdns_enabled", DC_MDNS_DEFAULT_ENABLED) ) { + if( !dc_sqlite3_get_config_int(context->sql, "mdns_enabled", DC_MDNS_DEFAULT_ENABLED) ) { goto cleanup; /* MDNs not enabled - check this is late, in the job. the use may have changed its choice while offline ... */ } - if( !dc_msg_load_from_db(factory->m_msg, context, msg_id) - || !dc_contact_load_from_db(contact, context->m_sql, factory->m_msg->m_from_id) ) { + if( !dc_msg_load_from_db(factory->msg, context, msg_id) + || !dc_contact_load_from_db(contact, context->sql, factory->msg->from_id) ) { goto cleanup; } - if( contact->m_blocked - || factory->m_msg->m_chat_id<=DC_CHAT_ID_LAST_SPECIAL/* Do not send MDNs trash etc.; chats.blocked is already checked by the caller in dc_markseen_msgs() */ ) { + if( contact->blocked + || factory->msg->chat_id<=DC_CHAT_ID_LAST_SPECIAL/* Do not send MDNs trash etc.; chats.blocked is already checked by the caller in dc_markseen_msgs() */ ) { goto cleanup; } - if( factory->m_msg->m_from_id <= DC_CONTACT_ID_LAST_SPECIAL ) { + if( factory->msg->from_id <= DC_CONTACT_ID_LAST_SPECIAL ) { goto cleanup; } - clist_append(factory->m_recipients_names, (void*)((contact->m_authname&&contact->m_authname[0])? dc_strdup(contact->m_authname) : NULL)); - clist_append(factory->m_recipients_addr, (void*)dc_strdup(contact->m_addr)); + clist_append(factory->recipients_names, (void*)((contact->authname&&contact->authname[0])? dc_strdup(contact->authname) : NULL)); + clist_append(factory->recipients_addr, (void*)dc_strdup(contact->addr)); load_from__(factory); - factory->m_timestamp = dc_create_smeared_timestamp(context); - factory->m_rfc724_mid = dc_create_outgoing_rfc724_mid(NULL, factory->m_from_addr); + factory->timestamp = dc_create_smeared_timestamp(context); + factory->rfc724_mid = dc_create_outgoing_rfc724_mid(NULL, factory->from_addr); success = 1; - factory->m_loaded = DC_MF_MDN_LOADED; + factory->loaded = DC_MF_MDN_LOADED; cleanup: return success; @@ -319,8 +319,8 @@ static struct mailmime* build_body_file(const dc_msg_t* msg, const char* base_na struct mailmime* mime_sub = NULL; struct mailmime_content* content; - char* pathNfilename = dc_param_get(msg->m_param, DC_PARAM_FILE, NULL); - char* mimetype = dc_param_get(msg->m_param, DC_PARAM_MIMETYPE, NULL); + char* pathNfilename = dc_param_get(msg->param, DC_PARAM_FILE, NULL); + char* mimetype = dc_param_get(msg->param, DC_PARAM_MIMETYPE, NULL); char* suffix = dc_get_filesuffix_lc(pathNfilename); char* filename_to_send = NULL; char* filename_encoded = NULL; @@ -330,17 +330,17 @@ static struct mailmime* build_body_file(const dc_msg_t* msg, const char* base_na } /* get file name to use for sending (for privacy purposes, we do not transfer the original filenames eg. for images; these names are normally not needed and contain timesamps, running numbers etc.) */ - if( msg->m_type == DC_MSG_VOICE ) { + if( msg->type == DC_MSG_VOICE ) { struct tm wanted_struct; - memcpy(&wanted_struct, localtime(&msg->m_timestamp), sizeof(struct tm)); + memcpy(&wanted_struct, localtime(&msg->timestamp), sizeof(struct tm)); filename_to_send = dc_mprintf("voice-message_%04i-%02i-%02i_%02i-%02i-%02i.%s", (int)wanted_struct.tm_year+1900, (int)wanted_struct.tm_mon+1, (int)wanted_struct.tm_mday, (int)wanted_struct.tm_hour, (int)wanted_struct.tm_min, (int)wanted_struct.tm_sec, suffix? suffix : "dat"); } - else if( msg->m_type == DC_MSG_AUDIO ) { - char* author = dc_param_get(msg->m_param, DC_PARAM_AUTHORNAME, NULL); - char* title = dc_param_get(msg->m_param, DC_PARAM_TRACKNAME, NULL); + else if( msg->type == DC_MSG_AUDIO ) { + char* author = dc_param_get(msg->param, DC_PARAM_AUTHORNAME, NULL); + char* title = dc_param_get(msg->param, DC_PARAM_TRACKNAME, NULL); if( author && author[0] && title && title[0] && suffix ) { filename_to_send = dc_mprintf("%s - %s.%s", author, title, suffix); /* the separator ` - ` is used on the receiver's side to construct the information; we avoid using ID3-scanners for security purposes */ } @@ -350,13 +350,13 @@ static struct mailmime* build_body_file(const dc_msg_t* msg, const char* base_na free(author); free(title); } - else if( msg->m_type == DC_MSG_IMAGE || msg->m_type == DC_MSG_GIF ) { + else if( msg->type == DC_MSG_IMAGE || msg->type == DC_MSG_GIF ) { if( base_name == NULL ) { base_name = "image"; } filename_to_send = dc_mprintf("%s.%s", base_name, suffix? suffix : "dat"); } - else if( msg->m_type == DC_MSG_VIDEO ) { + else if( msg->type == DC_MSG_VIDEO ) { filename_to_send = dc_mprintf("video.%s", suffix? suffix : "dat"); } else { @@ -436,17 +436,17 @@ cleanup: static char* get_subject(const dc_chat_t* chat, const dc_msg_t* msg, int afwd_email) { - dc_context_t* context = chat? chat->m_context : NULL; - char *ret, *raw_subject = dc_msg_get_summarytext_by_raw(msg->m_type, msg->m_text, msg->m_param, DC_APPROX_SUBJECT_CHARS, context); + dc_context_t* context = chat? chat->context : NULL; + char *ret, *raw_subject = dc_msg_get_summarytext_by_raw(msg->type, msg->text, msg->param, DC_APPROX_SUBJECT_CHARS, context); const char* fwd = afwd_email? "Fwd: " : ""; - if( dc_param_get_int(msg->m_param, DC_PARAM_CMD, 0) == DC_CMD_AUTOCRYPT_SETUP_MESSAGE ) + if( dc_param_get_int(msg->param, DC_PARAM_CMD, 0) == DC_CMD_AUTOCRYPT_SETUP_MESSAGE ) { ret = dc_stock_str(context, DC_STR_AC_SETUP_MSG_SUBJECT); /* do not add the "Chat:" prefix for setup messages */ } - else if( DC_CHAT_TYPE_IS_MULTI(chat->m_type) ) + else if( DC_CHAT_TYPE_IS_MULTI(chat->type) ) { - ret = dc_mprintf(DC_CHAT_PREFIX " %s: %s%s", chat->m_name, fwd, raw_subject); + ret = dc_mprintf(DC_CHAT_PREFIX " %s: %s%s", chat->name, fwd, raw_subject); } else { @@ -461,8 +461,8 @@ static char* get_subject(const dc_chat_t* chat, const dc_msg_t* msg, int afwd_em int dc_mimefactory_render(dc_mimefactory_t* factory) { if( factory == NULL - || factory->m_loaded == DC_MF_NOTHING_LOADED - || factory->m_out/*call empty() before*/ ) { + || factory->loaded == DC_MF_NOTHING_LOADED + || factory->out/*call empty() before*/ ) { return 0; } @@ -487,13 +487,13 @@ int dc_mimefactory_render(dc_mimefactory_t* factory) { struct mailimf_mailbox_list* from = mailimf_mailbox_list_new_empty(); - mailimf_mailbox_list_add(from, mailimf_mailbox_new(factory->m_from_displayname? dc_encode_header_words(factory->m_from_displayname) : NULL, dc_strdup(factory->m_from_addr))); + mailimf_mailbox_list_add(from, mailimf_mailbox_new(factory->from_displayname? dc_encode_header_words(factory->from_displayname) : NULL, dc_strdup(factory->from_addr))); struct mailimf_address_list* to = NULL; - if( factory->m_recipients_names && factory->m_recipients_addr && clist_count(factory->m_recipients_addr)>0 ) { + if( factory->recipients_names && factory->recipients_addr && clist_count(factory->recipients_addr)>0 ) { clistiter *iter1, *iter2; to = mailimf_address_list_new_empty(); - for( iter1=clist_begin(factory->m_recipients_names),iter2=clist_begin(factory->m_recipients_addr); iter1!=NULL&&iter2!=NULL; iter1=clist_next(iter1),iter2=clist_next(iter2)) { + for( iter1=clist_begin(factory->recipients_names),iter2=clist_begin(factory->recipients_addr); iter1!=NULL&&iter2!=NULL; iter1=clist_next(iter1),iter2=clist_next(iter2)) { const char* name = clist_content(iter1); const char* addr = clist_content(iter2); mailimf_address_list_add(to, mailimf_address_new(MAILIMF_ADDRESS_MAILBOX, mailimf_mailbox_new(name? dc_encode_header_words(name) : NULL, dc_strdup(addr)), NULL)); @@ -501,14 +501,14 @@ int dc_mimefactory_render(dc_mimefactory_t* factory) } clist* references_list = NULL; - if( factory->m_references ) { + if( factory->references ) { references_list = clist_new(); - clist_append(references_list, (void*)dc_strdup(factory->m_references)); + clist_append(references_list, (void*)dc_strdup(factory->references)); } - imf_fields = mailimf_fields_new_with_data_all(mailimf_get_date(factory->m_timestamp), from, + imf_fields = mailimf_fields_new_with_data_all(mailimf_get_date(factory->timestamp), from, NULL /* sender */, NULL /* reply-to */, - to, NULL /* cc */, NULL /* bcc */, dc_strdup(factory->m_rfc724_mid), NULL /* in-reply-to */, + to, NULL /* cc */, NULL /* bcc */, dc_strdup(factory->rfc724_mid), NULL /* in-reply-to */, references_list /* references */, NULL /* subject set later */); @@ -517,71 +517,71 @@ int dc_mimefactory_render(dc_mimefactory_t* factory) mailimf_fields_add(imf_fields, mailimf_field_new_custom(strdup("X-Mailer"), dc_mprintf("Delta Chat %s%s%s", DC_VERSION_STR, - factory->m_context->m_os_name? " for " : "", - factory->m_context->m_os_name? factory->m_context->m_os_name : ""))); + factory->context->os_name? " for " : "", + factory->context->os_name? factory->context->os_name : ""))); mailimf_fields_add(imf_fields, mailimf_field_new_custom(strdup("Chat-Version"), strdup("1.0"))); /* mark message as being sent by a messenger */ - if( factory->m_predecessor ) { - mailimf_fields_add(imf_fields, mailimf_field_new_custom(strdup("Chat-Predecessor"), strdup(factory->m_predecessor))); + if( factory->predecessor ) { + mailimf_fields_add(imf_fields, mailimf_field_new_custom(strdup("Chat-Predecessor"), strdup(factory->predecessor))); } - if( factory->m_req_mdn ) { + if( factory->req_mdn ) { /* we use "Chat-Disposition-Notification-To" as replies to "Disposition-Notification-To" are weired in many cases, are just freetext and/or do not follow any standard. */ - mailimf_fields_add(imf_fields, mailimf_field_new_custom(strdup("Chat-Disposition-Notification-To"), strdup(factory->m_from_addr))); + mailimf_fields_add(imf_fields, mailimf_field_new_custom(strdup("Chat-Disposition-Notification-To"), strdup(factory->from_addr))); } message = mailmime_new_message_data(NULL); mailmime_set_imf_fields(message, imf_fields); } - if( factory->m_loaded == DC_MF_MSG_LOADED ) + if( factory->loaded == DC_MF_MSG_LOADED ) { /* Render a normal message *********************************************************************/ - dc_chat_t* chat = factory->m_chat; - dc_msg_t* msg = factory->m_msg; + dc_chat_t* chat = factory->chat; + dc_msg_t* msg = factory->msg; struct mailmime* meta_part = NULL; char* placeholdertext = NULL; - if( chat->m_type == DC_CHAT_TYPE_VERIFIED_GROUP ) { + if( chat->type == DC_CHAT_TYPE_VERIFIED_GROUP ) { mailimf_fields_add(imf_fields, mailimf_field_new_custom(strdup("Chat-Verified"), strdup("1"))); force_plaintext = 0; e2ee_guaranteed = 1; min_verified = DC_BIDIRECT_VERIFIED; } else { - if( (force_plaintext = dc_param_get_int(factory->m_msg->m_param, DC_PARAM_FORCE_PLAINTEXT, 0)) == 0 ) { - e2ee_guaranteed = dc_param_get_int(factory->m_msg->m_param, DC_PARAM_GUARANTEE_E2EE, 0); + if( (force_plaintext = dc_param_get_int(factory->msg->param, DC_PARAM_FORCE_PLAINTEXT, 0)) == 0 ) { + e2ee_guaranteed = dc_param_get_int(factory->msg->param, DC_PARAM_GUARANTEE_E2EE, 0); } } /* build header etc. */ - int command = dc_param_get_int(msg->m_param, DC_PARAM_CMD, 0); - if( DC_CHAT_TYPE_IS_MULTI(chat->m_type) ) + int command = dc_param_get_int(msg->param, DC_PARAM_CMD, 0); + if( DC_CHAT_TYPE_IS_MULTI(chat->type) ) { - mailimf_fields_add(imf_fields, mailimf_field_new_custom(strdup("Chat-Group-ID"), dc_strdup(chat->m_grpid))); - mailimf_fields_add(imf_fields, mailimf_field_new_custom(strdup("Chat-Group-Name"), dc_encode_header_words(chat->m_name))); + mailimf_fields_add(imf_fields, mailimf_field_new_custom(strdup("Chat-Group-ID"), dc_strdup(chat->grpid))); + mailimf_fields_add(imf_fields, mailimf_field_new_custom(strdup("Chat-Group-Name"), dc_encode_header_words(chat->name))); if( command == DC_CMD_MEMBER_REMOVED_FROM_GROUP ) { - char* email_to_remove = dc_param_get(msg->m_param, DC_PARAM_CMD_ARG, NULL); + char* email_to_remove = dc_param_get(msg->param, DC_PARAM_CMD_ARG, NULL); if( email_to_remove ) { mailimf_fields_add(imf_fields, mailimf_field_new_custom(strdup("Chat-Group-Member-Removed"), email_to_remove)); } } else if( command == DC_CMD_MEMBER_ADDED_TO_GROUP ) { - char* email_to_add = dc_param_get(msg->m_param, DC_PARAM_CMD_ARG, NULL); + char* email_to_add = dc_param_get(msg->param, DC_PARAM_CMD_ARG, NULL); if( email_to_add ) { mailimf_fields_add(imf_fields, mailimf_field_new_custom(strdup("Chat-Group-Member-Added"), email_to_add)); - grpimage = dc_param_get(chat->m_param, DC_PARAM_PROFILE_IMAGE, NULL); + grpimage = dc_param_get(chat->param, DC_PARAM_PROFILE_IMAGE, NULL); } - if( dc_param_get_int(msg->m_param, DC_PARAM_CMD_ARG2, 0)&DC_FROM_HANDSHAKE ) { - dc_log_info(msg->m_context, 0, "sending secure-join message '%s' >>>>>>>>>>>>>>>>>>>>>>>>>", "vg-member-added"); + if( dc_param_get_int(msg->param, DC_PARAM_CMD_ARG2, 0)&DC_FROM_HANDSHAKE ) { + dc_log_info(msg->context, 0, "sending secure-join message '%s' >>>>>>>>>>>>>>>>>>>>>>>>>", "vg-member-added"); mailimf_fields_add(imf_fields, mailimf_field_new_custom(strdup("Secure-Join"), strdup("vg-member-added"))); } } @@ -591,7 +591,7 @@ int dc_mimefactory_render(dc_mimefactory_t* factory) } else if( command == DC_CMD_GROUPIMAGE_CHANGED ) { - grpimage = dc_param_get(msg->m_param, DC_PARAM_CMD_ARG, NULL); + grpimage = dc_param_get(msg->param, DC_PARAM_CMD_ARG, NULL); if( grpimage==NULL ) { mailimf_fields_add(imf_fields, mailimf_field_new_custom(strdup("Chat-Group-Image"), dc_strdup("0"))); } @@ -600,16 +600,16 @@ int dc_mimefactory_render(dc_mimefactory_t* factory) if( command == DC_CMD_AUTOCRYPT_SETUP_MESSAGE ) { mailimf_fields_add(imf_fields, mailimf_field_new_custom(strdup("Autocrypt-Setup-Message"), strdup("v1"))); - placeholdertext = dc_stock_str(factory->m_context, DC_STR_AC_SETUP_MSG_BODY); + placeholdertext = dc_stock_str(factory->context, DC_STR_AC_SETUP_MSG_BODY); } if( command == DC_CMD_SECUREJOIN_MESSAGE ) { - char* step = dc_param_get(msg->m_param, DC_PARAM_CMD_ARG, NULL); + char* step = dc_param_get(msg->param, DC_PARAM_CMD_ARG, NULL); if( step ) { - dc_log_info(msg->m_context, 0, "sending secure-join message '%s' >>>>>>>>>>>>>>>>>>>>>>>>>", step); + dc_log_info(msg->context, 0, "sending secure-join message '%s' >>>>>>>>>>>>>>>>>>>>>>>>>", step); mailimf_fields_add(imf_fields, mailimf_field_new_custom(strdup("Secure-Join"), step/*mailimf takes ownership of string*/)); - char* param2 = dc_param_get(msg->m_param, DC_PARAM_CMD_ARG2, NULL); + char* param2 = dc_param_get(msg->param, DC_PARAM_CMD_ARG2, NULL); if( param2 ) { mailimf_fields_add(imf_fields, mailimf_field_new_custom( (strcmp(step, "vg-request-with-auth")==0 || strcmp(step, "vc-request-with-auth")==0)? @@ -617,14 +617,14 @@ int dc_mimefactory_render(dc_mimefactory_t* factory) param2/*mailimf takes ownership of string*/)); } - char* fingerprint = dc_param_get(msg->m_param, DC_PARAM_CMD_ARG3, NULL); + char* fingerprint = dc_param_get(msg->param, DC_PARAM_CMD_ARG3, NULL); if( fingerprint ) { mailimf_fields_add(imf_fields, mailimf_field_new_custom( strdup("Secure-Join-Fingerprint"), fingerprint/*mailimf takes ownership of string*/)); } - char* grpid = dc_param_get(msg->m_param, DC_PARAM_CMD_ARG4, NULL); + char* grpid = dc_param_get(msg->param, DC_PARAM_CMD_ARG4, NULL); if( grpid ) { mailimf_fields_add(imf_fields, mailimf_field_new_custom( strdup("Secure-Join-Group"), @@ -636,8 +636,8 @@ int dc_mimefactory_render(dc_mimefactory_t* factory) if( grpimage ) { dc_msg_t* meta = dc_msg_new(); - meta->m_type = DC_MSG_IMAGE; - dc_param_set(meta->m_param, DC_PARAM_FILE, grpimage); + meta->type = DC_MSG_IMAGE; + dc_param_set(meta->param, DC_PARAM_FILE, grpimage); char* filename_as_sent = NULL; if( (meta_part=build_body_file(meta, "group-image", &filename_as_sent))!=NULL ) { mailimf_fields_add(imf_fields, mailimf_field_new_custom(strdup("Chat-Group-Image"), filename_as_sent/*takes ownership*/)); @@ -645,13 +645,13 @@ int dc_mimefactory_render(dc_mimefactory_t* factory) dc_msg_unref(meta); } - if( msg->m_type == DC_MSG_VOICE || msg->m_type == DC_MSG_AUDIO || msg->m_type == DC_MSG_VIDEO ) + if( msg->type == DC_MSG_VOICE || msg->type == DC_MSG_AUDIO || msg->type == DC_MSG_VIDEO ) { - if( msg->m_type == DC_MSG_VOICE ) { + if( msg->type == DC_MSG_VOICE ) { mailimf_fields_add(imf_fields, mailimf_field_new_custom(strdup("Chat-Voice-Message"), strdup("1"))); } - int duration_ms = dc_param_get_int(msg->m_param, DC_PARAM_DURATION, 0); + int duration_ms = dc_param_get_int(msg->param, DC_PARAM_DURATION, 0); if( duration_ms > 0 ) { mailimf_fields_add(imf_fields, mailimf_field_new_custom(strdup("Chat-Duration"), dc_mprintf("%i", (int)duration_ms))); } @@ -661,21 +661,21 @@ int dc_mimefactory_render(dc_mimefactory_t* factory) - some Apps have problems with Non-text in the main part (eg. "Mail" from stock Android) - we can add "forward hints" this way - it looks better */ - afwd_email = dc_param_exists(msg->m_param, DC_PARAM_FORWARDED); + afwd_email = dc_param_exists(msg->param, DC_PARAM_FORWARDED); char* fwdhint = NULL; if( afwd_email ) { fwdhint = dc_strdup("---------- Forwarded message ----------" LINEEND "From: Delta Chat" LINEEND LINEEND); /* do not chage this! expected this way in the simplifier to detect forwarding! */ } const char* final_text = NULL; - if( msg->m_type==DC_MSG_TEXT && msg->m_text && msg->m_text[0] ) { /* m_text may also contain data otherwise, eg. the filename of attachments */ - final_text = msg->m_text; + if( msg->type==DC_MSG_TEXT && msg->text && msg->text[0] ) { /* `text` may also contain data otherwise, eg. the filename of attachments */ + final_text = msg->text; } else if( placeholdertext ) { final_text = placeholdertext; } - char* footer = factory->m_selfstatus; + char* footer = factory->selfstatus; message_text = dc_mprintf("%s%s%s%s%s", fwdhint? fwdhint : "", final_text? final_text : "", @@ -690,7 +690,7 @@ int dc_mimefactory_render(dc_mimefactory_t* factory) free(placeholdertext); /* add attachment part */ - if( DC_MSG_NEEDS_ATTACHMENT(msg->m_type) ) { + if( DC_MSG_NEEDS_ATTACHMENT(msg->type) ) { struct mailmime* file_part = build_body_file(msg, NULL, NULL); if( file_part ) { mailmime_smart_add_part(message, file_part); @@ -707,7 +707,7 @@ int dc_mimefactory_render(dc_mimefactory_t* factory) parts++; } } - else if( factory->m_loaded == DC_MF_MDN_LOADED ) + else if( factory->loaded == DC_MF_MDN_LOADED ) { /* Render a MDN *********************************************************************/ @@ -719,13 +719,13 @@ int dc_mimefactory_render(dc_mimefactory_t* factory) /* first body part: always human-readable, always REQUIRED by RFC 6522 */ char *p1 = NULL, *p2 = NULL; - if( dc_param_get_int(factory->m_msg->m_param, DC_PARAM_GUARANTEE_E2EE, 0) ) { - p1 = dc_stock_str(factory->m_context, DC_STR_ENCRYPTEDMSG); /* we SHOULD NOT spread encrypted subjects, date etc. in potentially unencrypted MDNs */ + if( dc_param_get_int(factory->msg->param, DC_PARAM_GUARANTEE_E2EE, 0) ) { + p1 = dc_stock_str(factory->context, DC_STR_ENCRYPTEDMSG); /* we SHOULD NOT spread encrypted subjects, date etc. in potentially unencrypted MDNs */ } else { - p1 = dc_msg_get_summarytext(factory->m_msg, DC_APPROX_SUBJECT_CHARS); + p1 = dc_msg_get_summarytext(factory->msg, DC_APPROX_SUBJECT_CHARS); } - p2 = dc_stock_str_repl_string(factory->m_context, DC_STR_READRCPT_MAILBODY, p1); + p2 = dc_stock_str_repl_string(factory->context, DC_STR_READRCPT_MAILBODY, p1); message_text = dc_mprintf("%s" LINEEND, p2); free(p2); free(p1); @@ -742,9 +742,9 @@ int dc_mimefactory_render(dc_mimefactory_t* factory) "Original-Message-ID: <%s>" LINEEND "Disposition: manual-action/MDN-sent-automatically; displayed" LINEEND, /* manual-action: the user has configured the MUA to send MDNs (automatic-action implies the receipts cannot be disabled) */ DC_VERSION_STR, - factory->m_from_addr, - factory->m_from_addr, - factory->m_msg->m_rfc724_mid); + factory->from_addr, + factory->from_addr, + factory->msg->rfc724_mid); struct mailmime_content* content_type = mailmime_content_new_with_str("message/disposition-notification"); struct mailmime_fields* mime_fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT); @@ -772,27 +772,27 @@ int dc_mimefactory_render(dc_mimefactory_t* factory) /* Encrypt the message *************************************************************************/ - if( factory->m_loaded==DC_MF_MDN_LOADED ) { - char* e = dc_stock_str(factory->m_context, DC_STR_READRCPT); subject_str = dc_mprintf(DC_CHAT_PREFIX " %s", e); free(e); + if( factory->loaded==DC_MF_MDN_LOADED ) { + char* e = dc_stock_str(factory->context, DC_STR_READRCPT); subject_str = dc_mprintf(DC_CHAT_PREFIX " %s", e); free(e); } else { - subject_str = get_subject(factory->m_chat, factory->m_msg, afwd_email); + subject_str = get_subject(factory->chat, factory->msg, afwd_email); } struct mailimf_subject* subject = mailimf_subject_new(dc_encode_header_words(subject_str)); mailimf_fields_add(imf_fields, mailimf_field_new(MAILIMF_FIELD_SUBJECT, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, subject, NULL, NULL, NULL)); if( force_plaintext != DC_FP_NO_AUTOCRYPT_HEADER ) { - dc_e2ee_encrypt(factory->m_context, factory->m_recipients_addr, force_plaintext, e2ee_guaranteed, min_verified, message, &e2ee_helper); + dc_e2ee_encrypt(factory->context, factory->recipients_addr, force_plaintext, e2ee_guaranteed, min_verified, message, &e2ee_helper); } - if( e2ee_helper.m_encryption_successfull ) { - factory->m_out_encrypted = 1; + if( e2ee_helper.encryption_successfull ) { + factory->out_encrypted = 1; } /* create the full mail and return */ - factory->m_out = mmap_string_new(""); - mailmime_write_mem(factory->m_out, &col, message); + factory->out = mmap_string_new(""); + mailmime_write_mem(factory->out, &col, message); //{char* t4=dc_null_terminate(ret->str,ret->len); printf("MESSAGE:\n%s\n",t4);free(t4);} diff --git a/src/dc_mimefactory.h b/src/dc_mimefactory.h index ddff84e7..5a8bfb7d 100644 --- a/src/dc_mimefactory.h +++ b/src/dc_mimefactory.h @@ -51,30 +51,30 @@ typedef struct dc_mimefactory_t { /** @privatesection */ /* in: parameters, set eg. by dc_mimefactory_load_msg() */ - char* m_from_addr; - char* m_from_displayname; - char* m_selfstatus; - clist* m_recipients_names; - clist* m_recipients_addr; - time_t m_timestamp; - char* m_rfc724_mid; + char* from_addr; + char* from_displayname; + char* selfstatus; + clist* recipients_names; + clist* recipients_addr; + time_t timestamp; + char* rfc724_mid; /* what is loaded? */ - dc_mimefactory_loaded_t m_loaded; + dc_mimefactory_loaded_t loaded; - dc_msg_t* m_msg; - dc_chat_t* m_chat; - int m_increation; - char* m_predecessor; - char* m_references; - int m_req_mdn; + dc_msg_t* msg; + dc_chat_t* chat; + int increation; + char* predecessor; + char* references; + int req_mdn; /* out: after a successfull dc_mimefactory_render(), here's the data */ - MMAPString* m_out; - int m_out_encrypted; + MMAPString* out; + int out_encrypted; /* private */ - dc_context_t* m_context; + dc_context_t* context; } dc_mimefactory_t; diff --git a/src/dc_mimeparser.c b/src/dc_mimeparser.c index d13d156a..e4ab434a 100644 --- a/src/dc_mimeparser.c +++ b/src/dc_mimeparser.c @@ -792,8 +792,8 @@ static dc_mimepart_t* dc_mimepart_new(void) exit(33); } - mimepart->m_type = DC_MSG_UNDEFINED; - mimepart->m_param = dc_param_new(); + mimepart->type = DC_MSG_UNDEFINED; + mimepart->param = dc_param_new(); return mimepart; } @@ -805,17 +805,17 @@ static void dc_mimepart_unref(dc_mimepart_t* mimepart) return; } - if( mimepart->m_msg ) { - free(mimepart->m_msg); - mimepart->m_msg = NULL; + if( mimepart->msg ) { + free(mimepart->msg); + mimepart->msg = NULL; } - if( mimepart->m_msg_raw ) { - free(mimepart->m_msg_raw); - mimepart->m_msg_raw = NULL; + if( mimepart->msg_raw ) { + free(mimepart->msg_raw); + mimepart->msg_raw = NULL; } - dc_param_unref(mimepart->m_param); + dc_param_unref(mimepart->param); free(mimepart); } @@ -843,13 +843,13 @@ dc_mimeparser_t* dc_mimeparser_new(const char* blobdir, dc_context_t* context) exit(30); } - mimeparser->m_context = context; - mimeparser->m_parts = carray_new(16); - mimeparser->m_blobdir = blobdir; /* no need to copy the string at the moment */ - mimeparser->m_reports = carray_new(16); - mimeparser->m_e2ee_helper = calloc(1, sizeof(dc_e2ee_helper_t)); + mimeparser->context = context; + mimeparser->parts = carray_new(16); + mimeparser->blobdir = blobdir; /* no need to copy the string at the moment */ + mimeparser->reports = carray_new(16); + mimeparser->e2ee_helper = calloc(1, sizeof(dc_e2ee_helper_t)); - dc_hash_init(&mimeparser->m_header, DC_HASH_STRING, 0/* do not copy key */); + dc_hash_init(&mimeparser->header, DC_HASH_STRING, 0/* do not copy key */); return mimeparser; } @@ -873,9 +873,9 @@ void dc_mimeparser_unref(dc_mimeparser_t* mimeparser) } dc_mimeparser_empty(mimeparser); - if( mimeparser->m_parts ) { carray_free(mimeparser->m_parts); } - if( mimeparser->m_reports ) { carray_free(mimeparser->m_reports); } - free(mimeparser->m_e2ee_helper); + if( mimeparser->parts ) { carray_free(mimeparser->parts); } + if( mimeparser->reports ) { carray_free(mimeparser->reports); } + free(mimeparser->e2ee_helper); free(mimeparser); } @@ -898,60 +898,60 @@ void dc_mimeparser_empty(dc_mimeparser_t* mimeparser) return; } - if( mimeparser->m_parts ) + if( mimeparser->parts ) { - int i, cnt = carray_count(mimeparser->m_parts); + int i, cnt = carray_count(mimeparser->parts); for( i = 0; i < cnt; i++ ) { - dc_mimepart_t* part = (dc_mimepart_t*)carray_get(mimeparser->m_parts, i); + dc_mimepart_t* part = (dc_mimepart_t*)carray_get(mimeparser->parts, i); if( part ) { dc_mimepart_unref(part); } } - carray_set_size(mimeparser->m_parts, 0); + carray_set_size(mimeparser->parts, 0); } - mimeparser->m_header_root = NULL; /* a pointer somewhere to the MIME data, must NOT be freed */ - dc_hash_clear(&mimeparser->m_header); + mimeparser->header_root = NULL; /* a pointer somewhere to the MIME data, must NOT be freed */ + dc_hash_clear(&mimeparser->header); - if( mimeparser->m_header_protected ) { - mailimf_fields_free(mimeparser->m_header_protected); /* allocated as needed, MUST be freed */ - mimeparser->m_header_protected = NULL; + if( mimeparser->header_protected ) { + mailimf_fields_free(mimeparser->header_protected); /* allocated as needed, MUST be freed */ + mimeparser->header_protected = NULL; } - mimeparser->m_is_send_by_messenger = 0; - mimeparser->m_is_system_message = 0; + mimeparser->is_send_by_messenger = 0; + mimeparser->is_system_message = 0; - free(mimeparser->m_subject); - mimeparser->m_subject = NULL; + free(mimeparser->subject); + mimeparser->subject = NULL; - if( mimeparser->m_mimeroot ) + if( mimeparser->mimeroot ) { - mailmime_free(mimeparser->m_mimeroot); - mimeparser->m_mimeroot = NULL; + mailmime_free(mimeparser->mimeroot); + mimeparser->mimeroot = NULL; } - mimeparser->m_is_forwarded = 0; + mimeparser->is_forwarded = 0; - if( mimeparser->m_reports ) { - carray_set_size(mimeparser->m_reports, 0); + if( mimeparser->reports ) { + carray_set_size(mimeparser->reports, 0); } - mimeparser->m_decrypting_failed = 0; + mimeparser->decrypting_failed = 0; - dc_e2ee_thanks(mimeparser->m_e2ee_helper); + dc_e2ee_thanks(mimeparser->e2ee_helper); } static void do_add_single_part(dc_mimeparser_t* parser, dc_mimepart_t* part) { /* add a single part to the list of parts, the parser takes the ownership of the part, so you MUST NOT unref it after calling this function. */ - if( parser->m_e2ee_helper->m_encrypted && dc_hash_count(parser->m_e2ee_helper->m_signatures)>0 ) { - dc_param_set_int(part->m_param, DC_PARAM_GUARANTEE_E2EE, 1); + if( parser->e2ee_helper->encrypted && dc_hash_count(parser->e2ee_helper->signatures)>0 ) { + dc_param_set_int(part->param, DC_PARAM_GUARANTEE_E2EE, 1); } - else if( parser->m_e2ee_helper->m_encrypted ) { - dc_param_set_int(part->m_param, DC_PARAM_ERRONEOUS_E2EE, DC_E2EE_NO_VALID_SIGNATURE); + else if( parser->e2ee_helper->encrypted ) { + dc_param_set_int(part->param, DC_PARAM_ERRONEOUS_E2EE, DC_E2EE_NO_VALID_SIGNATURE); } - carray_add(parser->m_parts, (void*)part, NULL); + carray_add(parser->parts, (void*)part, NULL); } @@ -963,32 +963,32 @@ static void do_add_single_file_part(dc_mimeparser_t* parser, int msg_type, int m char* pathNfilename = NULL; /* create a free file name to use */ - if( (pathNfilename=dc_get_fine_pathNfilename(parser->m_blobdir, desired_filename)) == NULL ) { + if( (pathNfilename=dc_get_fine_pathNfilename(parser->blobdir, desired_filename)) == NULL ) { goto cleanup; } /* copy data to file */ - if( dc_write_file(pathNfilename, decoded_data, decoded_data_bytes, parser->m_context)==0 ) { + if( dc_write_file(pathNfilename, decoded_data, decoded_data_bytes, parser->context)==0 ) { goto cleanup; } part = dc_mimepart_new(); - part->m_type = msg_type; - part->m_int_mimetype = mime_type; - part->m_bytes = decoded_data_bytes; - dc_param_set(part->m_param, DC_PARAM_FILE, pathNfilename); + part->type = msg_type; + part->int_mimetype = mime_type; + part->bytes = decoded_data_bytes; + dc_param_set(part->param, DC_PARAM_FILE, pathNfilename); if( DC_MSG_MAKE_FILENAME_SEARCHABLE(msg_type) ) { - part->m_msg = dc_get_filename(pathNfilename); + part->msg = dc_get_filename(pathNfilename); } else if( DC_MSG_MAKE_SUFFIX_SEARCHABLE(msg_type) ) { - part->m_msg = dc_get_filesuffix_lc(pathNfilename); + part->msg = dc_get_filesuffix_lc(pathNfilename); } if( mime_type == DC_MIMETYPE_IMAGE ) { uint32_t w = 0, h = 0; if( dc_get_filemeta(decoded_data, decoded_data_bytes, &w, &h) ) { - dc_param_set_int(part->m_param, DC_PARAM_WIDTH, w); - dc_param_set_int(part->m_param, DC_PARAM_HEIGHT, h); + dc_param_set_int(part->param, DC_PARAM_WIDTH, w); + dc_param_set_int(part->param, DC_PARAM_HEIGHT, h); } } @@ -996,8 +996,8 @@ static void do_add_single_file_part(dc_mimeparser_t* parser, int msg_type, int m if( msg_type == DC_MSG_AUDIO ) { char* author = NULL, *title = NULL; dc_msg_get_authorNtitle_from_filename(desired_filename, &author, &title); - dc_param_set(part->m_param, DC_PARAM_AUTHORNAME, author); - dc_param_set(part->m_param, DC_PARAM_TRACKNAME, title); + dc_param_set(part->param, DC_PARAM_AUTHORNAME, author); + dc_param_set(part->param, DC_PARAM_TRACKNAME, title); free(author); free(title); } @@ -1014,7 +1014,7 @@ cleanup: static int dc_mimeparser_add_single_part_if_known(dc_mimeparser_t* mimeparser, struct mailmime* mime) { dc_mimepart_t* part = NULL; - int old_part_count = carray_count(mimeparser->m_parts); + int old_part_count = carray_count(mimeparser->parts); int mime_type; struct mailmime_data* mime_data; @@ -1065,7 +1065,7 @@ static int dc_mimeparser_add_single_part_if_known(dc_mimeparser_t* mimeparser, s size_t ret_bytes = 0; int r = charconv_buffer("utf-8", charset, decoded_data, decoded_data_bytes, &charset_buffer, &ret_bytes); if( r != MAIL_CHARCONV_NO_ERROR ) { - dc_log_warning(mimeparser->m_context, 0, "Cannot convert %i bytes from \"%s\" to \"utf-8\"; errorcode is %i.", /* if this warning comes up for usual character sets, maybe libetpan is compiled without iconv? */ + dc_log_warning(mimeparser->context, 0, "Cannot convert %i bytes from \"%s\" to \"utf-8\"; errorcode is %i.", /* if this warning comes up for usual character sets, maybe libetpan is compiled without iconv? */ (int)decoded_data_bytes, charset, (int)r); /* continue, however */ } else if( charset_buffer==NULL || ret_bytes <= 0 ) { @@ -1110,10 +1110,10 @@ static int dc_mimeparser_add_single_part_if_known(dc_mimeparser_t* mimeparser, s if( simplified_txt && simplified_txt[0] ) { part = dc_mimepart_new(); - part->m_type = DC_MSG_TEXT; - part->m_int_mimetype = mime_type; - part->m_msg = simplified_txt; - part->m_msg_raw = strndup(decoded_data, decoded_data_bytes); + part->type = DC_MSG_TEXT; + part->int_mimetype = mime_type; + part->msg = simplified_txt; + part->msg_raw = strndup(decoded_data, decoded_data_bytes); do_add_single_part(mimeparser, part); part = NULL; } @@ -1122,8 +1122,8 @@ static int dc_mimeparser_add_single_part_if_known(dc_mimeparser_t* mimeparser, s free(simplified_txt); } - if( simplifier->m_is_forwarded ) { - mimeparser->m_is_forwarded = 1; + if( simplifier->is_forwarded ) { + mimeparser->is_forwarded = 1; } } break; @@ -1171,12 +1171,12 @@ static int dc_mimeparser_add_single_part_if_known(dc_mimeparser_t* mimeparser, s } } - if( strlen(filename_parts.m_buf) ) { + if( strlen(filename_parts.buf) ) { free(desired_filename); - desired_filename = dc_decode_ext_header(filename_parts.m_buf); + desired_filename = dc_decode_ext_header(filename_parts.buf); } - free(filename_parts.m_buf); + free(filename_parts.buf); /* try to get file name from `Content-Type: ... name=...` */ if( desired_filename==NULL ) { @@ -1215,7 +1215,7 @@ cleanup: free(desired_filename); dc_mimepart_unref(part); - return carray_count(mimeparser->m_parts)>old_part_count? 1 : 0; /* any part added? */ + return carray_count(mimeparser->parts)>old_part_count? 1 : 0; /* any part added? */ } @@ -1235,19 +1235,19 @@ static int dc_mimeparser_parse_mime_recursive(dc_mimeparser_t* mimeparser, struc && mime->mm_content_type->ct_type->tp_data.tp_discrete_type->dt_type==MAILMIME_DISCRETE_TYPE_TEXT && mime->mm_content_type->ct_subtype && strcmp(mime->mm_content_type->ct_subtype, "rfc822-headers")==0 ) { - dc_log_info(mimeparser->m_context, 0, "Protected headers found in text/rfc822-headers attachment: Will be ignored."); /* we want the protected headers in the normal header of the payload */ + dc_log_info(mimeparser->context, 0, "Protected headers found in text/rfc822-headers attachment: Will be ignored."); /* we want the protected headers in the normal header of the payload */ return 0; } - if( mimeparser->m_header_protected==NULL ) { /* use the most outer protected header - this is typically created in sync with the normal, unprotected header */ + if( mimeparser->header_protected==NULL ) { /* use the most outer protected header - this is typically created in sync with the normal, unprotected header */ size_t dummy = 0; - if( mailimf_envelope_and_optional_fields_parse(mime->mm_mime_start, mime->mm_length, &dummy, &mimeparser->m_header_protected)!=MAILIMF_NO_ERROR - || mimeparser->m_header_protected==NULL ) { - dc_log_warning(mimeparser->m_context, 0, "Protected headers parsing error."); + if( mailimf_envelope_and_optional_fields_parse(mime->mm_mime_start, mime->mm_length, &dummy, &mimeparser->header_protected)!=MAILIMF_NO_ERROR + || mimeparser->header_protected==NULL ) { + dc_log_warning(mimeparser->context, 0, "Protected headers parsing error."); } } else { - dc_log_info(mimeparser->m_context, 0, "Protected headers found in MIME header: Will be ignored as we already found an outer one."); + dc_log_info(mimeparser->context, 0, "Protected headers found in MIME header: Will be ignored as we already found an outer one."); } } @@ -1304,15 +1304,15 @@ static int dc_mimeparser_parse_mime_recursive(dc_mimeparser_t* mimeparser, struc case DC_MIMETYPE_MP_NOT_DECRYPTABLE: { dc_mimepart_t* part = dc_mimepart_new(); - part->m_type = DC_MSG_TEXT; + part->type = DC_MSG_TEXT; - char* msg_body = dc_stock_str(mimeparser->m_context, DC_STR_CANTDECRYPT_MSG_BODY); - part->m_msg = dc_mprintf(DC_EDITORIAL_OPEN "%s" DC_EDITORIAL_CLOSE, msg_body); + char* msg_body = dc_stock_str(mimeparser->context, DC_STR_CANTDECRYPT_MSG_BODY); + part->msg = dc_mprintf(DC_EDITORIAL_OPEN "%s" DC_EDITORIAL_CLOSE, msg_body); free(msg_body); - carray_add(mimeparser->m_parts, (void*)part, NULL); + carray_add(mimeparser->parts, (void*)part, NULL); any_part_added = 1; - mimeparser->m_decrypting_failed = 1; + mimeparser->decrypting_failed = 1; } break; @@ -1335,7 +1335,7 @@ static int dc_mimeparser_parse_mime_recursive(dc_mimeparser_t* mimeparser, struc if( report_type && report_type->pa_value && strcmp(report_type->pa_value, "disposition-notification") == 0 ) { - carray_add(mimeparser->m_reports, (void*)mime, NULL); + carray_add(mimeparser->reports, (void*)mime, NULL); } else { @@ -1365,7 +1365,7 @@ static int dc_mimeparser_parse_mime_recursive(dc_mimeparser_t* mimeparser, struc } } if( plain_cnt==1 && html_cnt==1 ) { - dc_log_warning(mimeparser->m_context, 0, "HACK: multipart/mixed message found with PLAIN and HTML, we'll skip the HTML part as this seems to be unwanted."); + dc_log_warning(mimeparser->context, 0, "HACK: multipart/mixed message found with PLAIN and HTML, we'll skip the HTML part as this seems to be unwanted."); skip_part = html_part; } } @@ -1385,9 +1385,9 @@ static int dc_mimeparser_parse_mime_recursive(dc_mimeparser_t* mimeparser, struc break; case MAILMIME_MESSAGE: - if( mimeparser->m_header_root == NULL ) + if( mimeparser->header_root == NULL ) { - mimeparser->m_header_root = mime->mm_data.mm_message.mm_fields; + mimeparser->header_root = mime->mm_data.mm_message.mm_fields; } if( mime->mm_data.mm_message.mm_msg_mime ) @@ -1484,98 +1484,98 @@ void dc_mimeparser_parse(dc_mimeparser_t* mimeparser, const char* body_not_termi dc_mimeparser_empty(mimeparser); /* parse body */ - r = mailmime_parse(body_not_terminated, body_bytes, &index, &mimeparser->m_mimeroot); - if(r != MAILIMF_NO_ERROR || mimeparser->m_mimeroot == NULL ) { + r = mailmime_parse(body_not_terminated, body_bytes, &index, &mimeparser->mimeroot); + if(r != MAILIMF_NO_ERROR || mimeparser->mimeroot == NULL ) { goto cleanup; } - //printf("before decryption:\n"); mailmime_print(mimeparser->m_mimeroot); + //printf("before decryption:\n"); mailmime_print(mimeparser->mimeroot); /* decrypt, if possible; handle Autocrypt:-header (decryption may modifiy the given object) */ - dc_e2ee_decrypt(mimeparser->m_context, mimeparser->m_mimeroot, mimeparser->m_e2ee_helper); + dc_e2ee_decrypt(mimeparser->context, mimeparser->mimeroot, mimeparser->e2ee_helper); - //printf("after decryption:\n"); mailmime_print(mimeparser->m_mimeroot); + //printf("after decryption:\n"); mailmime_print(mimeparser->mimeroot); - /* recursively check, whats parsed, this also sets up m_header_old */ - dc_mimeparser_parse_mime_recursive(mimeparser, mimeparser->m_mimeroot); + /* recursively check, whats parsed, this also sets up header_old */ + dc_mimeparser_parse_mime_recursive(mimeparser, mimeparser->mimeroot); // TOCHECK: text parts may be moved to the beginning of the list - either here or in do_add_single_part() // usecase: eg. the Buchungsbestätigungen of Deutsch Bahn have the PDF before the explaining text. // may also be handy for extracting binaries from uuencoded text and just add the rest text after the binaries. /* setup header */ - hash_header(&mimeparser->m_header, mimeparser->m_header_root, mimeparser->m_context); - hash_header(&mimeparser->m_header, mimeparser->m_header_protected, mimeparser->m_context); /* overwrite the original header with the protected one */ + hash_header(&mimeparser->header, mimeparser->header_root, mimeparser->context); + hash_header(&mimeparser->header, mimeparser->header_protected, mimeparser->context); /* overwrite the original header with the protected one */ /* set some basic data */ { struct mailimf_field* field = dc_mimeparser_lookup_field(mimeparser, "Subject"); if( field && field->fld_type == MAILIMF_FIELD_SUBJECT ) { - mimeparser->m_subject = dc_decode_header_words(field->fld_data.fld_subject->sbj_value); + mimeparser->subject = dc_decode_header_words(field->fld_data.fld_subject->sbj_value); } } if( dc_mimeparser_lookup_optional_field2(mimeparser, "Chat-Version", "X-MrMsg") ) { - mimeparser->m_is_send_by_messenger = 1; + mimeparser->is_send_by_messenger = 1; } if( dc_mimeparser_lookup_field(mimeparser, "Autocrypt-Setup-Message") ) { /* Autocrypt-Setup-Message header found - check if there is an application/autocrypt-setup part */ int i, has_setup_file = 0; - for( i = 0; i < carray_count(mimeparser->m_parts); i++ ) { - dc_mimepart_t* part = (dc_mimepart_t*)carray_get(mimeparser->m_parts, i); - if( part->m_int_mimetype==DC_MIMETYPE_AC_SETUP_FILE ) { + for( i = 0; i < carray_count(mimeparser->parts); i++ ) { + dc_mimepart_t* part = (dc_mimepart_t*)carray_get(mimeparser->parts, i); + if( part->int_mimetype==DC_MIMETYPE_AC_SETUP_FILE ) { has_setup_file = 1; } } if( has_setup_file ) { /* delete all parts but the application/autocrypt-setup part */ - mimeparser->m_is_system_message = DC_CMD_AUTOCRYPT_SETUP_MESSAGE; - for( i = 0; i < carray_count(mimeparser->m_parts); i++ ) { - dc_mimepart_t* part = (dc_mimepart_t*)carray_get(mimeparser->m_parts, i); - if( part->m_int_mimetype!=DC_MIMETYPE_AC_SETUP_FILE ) { + mimeparser->is_system_message = DC_CMD_AUTOCRYPT_SETUP_MESSAGE; + for( i = 0; i < carray_count(mimeparser->parts); i++ ) { + dc_mimepart_t* part = (dc_mimepart_t*)carray_get(mimeparser->parts, i); + if( part->int_mimetype!=DC_MIMETYPE_AC_SETUP_FILE ) { dc_mimepart_unref(part); - carray_delete_slow(mimeparser->m_parts, i); + carray_delete_slow(mimeparser->parts, i); i--; /* start over with the same index */ } } } - mimeparser->m_is_send_by_messenger = 0; /* do not treat a setup message as a messenger message (eg. do not move setup messages to the Chats-folder; there may be a 3rd device that wants to handle it) */ + mimeparser->is_send_by_messenger = 0; /* do not treat a setup message as a messenger message (eg. do not move setup messages to the Chats-folder; there may be a 3rd device that wants to handle it) */ } /* prepend subject to message? */ - if( mimeparser->m_subject ) + if( mimeparser->subject ) { int prepend_subject = 1; - if( !mimeparser->m_decrypting_failed /* if decryption has failed, we always prepend the subject as this may contain cleartext hints from non-Delta MUAs. */ ) + if( !mimeparser->decrypting_failed /* if decryption has failed, we always prepend the subject as this may contain cleartext hints from non-Delta MUAs. */ ) { - char* p = strchr(mimeparser->m_subject, ':'); - if( (p-mimeparser->m_subject) == 2 /*Re: etc.*/ - || (p-mimeparser->m_subject) == 3 /*Fwd: etc.*/ - || mimeparser->m_is_send_by_messenger - || strstr(mimeparser->m_subject, DC_CHAT_PREFIX)!=NULL ) { + char* p = strchr(mimeparser->subject, ':'); + if( (p-mimeparser->subject) == 2 /*Re: etc.*/ + || (p-mimeparser->subject) == 3 /*Fwd: etc.*/ + || mimeparser->is_send_by_messenger + || strstr(mimeparser->subject, DC_CHAT_PREFIX)!=NULL ) { prepend_subject = 0; } } if( prepend_subject ) { - char* subj = dc_strdup(mimeparser->m_subject); + char* subj = dc_strdup(mimeparser->subject); char* p = strchr(subj, '['); /* do not add any tags as "[checked by XYZ]" */ if( p ) { *p = 0; } dc_trim(subj); if( subj[0] ) { - int i, icnt = carray_count(mimeparser->m_parts); /* should be at least one - maybe empty - part */ + int i, icnt = carray_count(mimeparser->parts); /* should be at least one - maybe empty - part */ for( i = 0; i < icnt; i++ ) { - dc_mimepart_t* part = (dc_mimepart_t*)carray_get(mimeparser->m_parts, i); - if( part->m_type == DC_MSG_TEXT ) { + dc_mimepart_t* part = (dc_mimepart_t*)carray_get(mimeparser->parts, i); + if( part->type == DC_MSG_TEXT ) { #define DC_NDASH "\xE2\x80\x93" - char* new_txt = dc_mprintf("%s " DC_NDASH " %s", subj, part->m_msg); - free(part->m_msg); - part->m_msg = new_txt; + char* new_txt = dc_mprintf("%s " DC_NDASH " %s", subj, part->msg); + free(part->msg); + part->msg = new_txt; break; } } @@ -1585,35 +1585,35 @@ void dc_mimeparser_parse(dc_mimeparser_t* mimeparser, const char* body_not_termi } /* add forward information to every part */ - if( mimeparser->m_is_forwarded ) { - int i, icnt = carray_count(mimeparser->m_parts); /* should be at least one - maybe empty - part */ + if( mimeparser->is_forwarded ) { + int i, icnt = carray_count(mimeparser->parts); /* should be at least one - maybe empty - part */ for( i = 0; i < icnt; i++ ) { - dc_mimepart_t* part = (dc_mimepart_t*)carray_get(mimeparser->m_parts, i); - dc_param_set_int(part->m_param, DC_PARAM_FORWARDED, 1); + dc_mimepart_t* part = (dc_mimepart_t*)carray_get(mimeparser->parts, i); + dc_param_set_int(part->param, DC_PARAM_FORWARDED, 1); } } - if( carray_count(mimeparser->m_parts)==1 ) + if( carray_count(mimeparser->parts)==1 ) { /* mark audio as voice message, if appropriate (we have to do this on global level as we do not know the global header in the recursice parse). and read some additional parameters */ - dc_mimepart_t* part = (dc_mimepart_t*)carray_get(mimeparser->m_parts, 0); - if( part->m_type == DC_MSG_AUDIO ) { + dc_mimepart_t* part = (dc_mimepart_t*)carray_get(mimeparser->parts, 0); + if( part->type == DC_MSG_AUDIO ) { if( dc_mimeparser_lookup_optional_field2(mimeparser, "Chat-Voice-Message", "X-MrVoiceMessage") ) { - free(part->m_msg); - part->m_msg = strdup("ogg"); /* DC_MSG_AUDIO adds sets the whole filename which is useless. however, the extension is useful. */ - part->m_type = DC_MSG_VOICE; - dc_param_set(part->m_param, DC_PARAM_AUTHORNAME, NULL); /* remove unneeded information */ - dc_param_set(part->m_param, DC_PARAM_TRACKNAME, NULL); + free(part->msg); + part->msg = strdup("ogg"); /* DC_MSG_AUDIO adds sets the whole filename which is useless. however, the extension is useful. */ + part->type = DC_MSG_VOICE; + dc_param_set(part->param, DC_PARAM_AUTHORNAME, NULL); /* remove unneeded information */ + dc_param_set(part->param, DC_PARAM_TRACKNAME, NULL); } } - if( part->m_type == DC_MSG_AUDIO || part->m_type == DC_MSG_VOICE || part->m_type == DC_MSG_VIDEO ) { + if( part->type == DC_MSG_AUDIO || part->type == DC_MSG_VOICE || part->type == DC_MSG_VIDEO ) { const struct mailimf_optional_field* field = dc_mimeparser_lookup_optional_field2(mimeparser, "Chat-Duration", "X-MrDurationMs"); if( field ) { int duration_ms = atoi(field->fld_value); if( duration_ms > 0 && duration_ms < 24*60*60*1000 ) { - dc_param_set_int(part->m_param, DC_PARAM_DURATION, duration_ms); + dc_param_set_int(part->param, DC_PARAM_DURATION, duration_ms); } } } @@ -1621,21 +1621,21 @@ void dc_mimeparser_parse(dc_mimeparser_t* mimeparser, const char* body_not_termi /* some special system message? */ if( dc_mimeparser_lookup_field(mimeparser, "Chat-Group-Image") - && carray_count(mimeparser->m_parts)>=1 ) { - dc_mimepart_t* textpart = (dc_mimepart_t*)carray_get(mimeparser->m_parts, 0); - if( textpart->m_type == DC_MSG_TEXT ) { - dc_param_set_int(textpart->m_param, DC_PARAM_CMD, DC_CMD_GROUPIMAGE_CHANGED); - if( carray_count(mimeparser->m_parts)>=2 ) { - dc_mimepart_t* imgpart = (dc_mimepart_t*)carray_get(mimeparser->m_parts, 1); - if( imgpart->m_type == DC_MSG_IMAGE ) { - imgpart->m_is_meta = 1; + && carray_count(mimeparser->parts)>=1 ) { + dc_mimepart_t* textpart = (dc_mimepart_t*)carray_get(mimeparser->parts, 0); + if( textpart->type == DC_MSG_TEXT ) { + dc_param_set_int(textpart->param, DC_PARAM_CMD, DC_CMD_GROUPIMAGE_CHANGED); + if( carray_count(mimeparser->parts)>=2 ) { + dc_mimepart_t* imgpart = (dc_mimepart_t*)carray_get(mimeparser->parts, 1); + if( imgpart->type == DC_MSG_IMAGE ) { + imgpart->is_meta = 1; } } } } /* check, if the message asks for a MDN */ - if( !mimeparser->m_decrypting_failed ) + if( !mimeparser->decrypting_failed ) { const struct mailimf_optional_field* dn_field = dc_mimeparser_lookup_optional_field(mimeparser, "Chat-Disposition-Notification-To"); /* we use "Chat-Disposition-Notification-To" as replies to "Disposition-Notification-To" are weired in many cases, are just freetext and/or do not follow any standard. */ if( dn_field && dc_mimeparser_get_last_nonmeta(mimeparser)/*just check if the mail is not empty*/ ) @@ -1660,7 +1660,7 @@ void dc_mimeparser_parse(dc_mimeparser_t* mimeparser, const char* body_not_termi Moreover the last one is handy as it is the one typically displayed if the message is larger) */ dc_mimepart_t* part = dc_mimeparser_get_last_nonmeta(mimeparser); if( part ) { - dc_param_set_int(part->m_param, DC_PARAM_WANTS_MDN, 1); + dc_param_set_int(part->param, DC_PARAM_WANTS_MDN, 1); } } free(from_addr); @@ -1675,11 +1675,11 @@ void dc_mimeparser_parse(dc_mimeparser_t* mimeparser, const char* body_not_termi /* Cleanup - and try to create at least an empty part if there are no parts yet */ cleanup: - if( !dc_mimeparser_has_nonmeta(mimeparser) && carray_count(mimeparser->m_reports)==0 ) { + if( !dc_mimeparser_has_nonmeta(mimeparser) && carray_count(mimeparser->reports)==0 ) { dc_mimepart_t* part = dc_mimepart_new(); - part->m_type = DC_MSG_TEXT; - part->m_msg = dc_strdup(mimeparser->m_subject? mimeparser->m_subject : "Empty message"); - carray_add(mimeparser->m_parts, (void*)part, NULL); + part->type = DC_MSG_TEXT; + part->msg = dc_strdup(mimeparser->subject? mimeparser->subject : "Empty message"); + carray_add(mimeparser->parts, (void*)part, NULL); } } @@ -1698,7 +1698,7 @@ cleanup: */ struct mailimf_field* dc_mimeparser_lookup_field(dc_mimeparser_t* mimeparser, const char* field_name) { - return (struct mailimf_field*)dc_hash_find_str(&mimeparser->m_header, field_name); + return (struct mailimf_field*)dc_hash_find_str(&mimeparser->header, field_name); } @@ -1718,7 +1718,7 @@ struct mailimf_field* dc_mimeparser_lookup_field(dc_mimeparser_t* mimeparser, co */ struct mailimf_optional_field* dc_mimeparser_lookup_optional_field(dc_mimeparser_t* mimeparser, const char* field_name) { - struct mailimf_field* field = dc_hash_find_str(&mimeparser->m_header, field_name); + struct mailimf_field* field = dc_hash_find_str(&mimeparser->header, field_name); if( field && field->fld_type == MAILIMF_FIELD_OPTIONAL_FIELD ) { return field->fld_data.fld_optional_field; } @@ -1738,7 +1738,7 @@ struct mailimf_optional_field* dc_mimeparser_lookup_optional_field2(dc_mimeparse /** - * Gets the _last_ part _not_ flagged with m_is_meta. + * Gets the _last_ part _not_ flagged with is_meta. * * If you just want to check if there is a non-meta part preset, you can also * use the macro dc_mimeparser_has_nonmeta(). @@ -1747,16 +1747,16 @@ struct mailimf_optional_field* dc_mimeparser_lookup_optional_field2(dc_mimeparse * * @param mimeparser The MIME-parser object. * - * @return The last part that is not flagged with m_is_meta. The returned value + * @return The last part that is not flagged with is_meta. The returned value * must not be freed. If there is no such part, NULL is returned. */ dc_mimepart_t* dc_mimeparser_get_last_nonmeta(dc_mimeparser_t* mimeparser) { - if( mimeparser && mimeparser->m_parts ) { - int i, icnt = carray_count(mimeparser->m_parts); + if( mimeparser && mimeparser->parts ) { + int i, icnt = carray_count(mimeparser->parts); for( i = icnt-1; i >= 0; i-- ) { - dc_mimepart_t* part = (dc_mimepart_t*)carray_get(mimeparser->m_parts, i); - if( part && !part->m_is_meta ) { + dc_mimepart_t* part = (dc_mimepart_t*)carray_get(mimeparser->parts, i); + if( part && !part->is_meta ) { return part; } } @@ -1861,12 +1861,12 @@ int dc_mimeparser_sender_equals_recipient(dc_mimeparser_t* mimeparser) char* from_addr_norm = NULL; dc_hash_t* recipients = NULL; - if( mimeparser == NULL || mimeparser->m_header_root == NULL ) { + if( mimeparser == NULL || mimeparser->header_root == NULL ) { goto cleanup; } /* get From: and check there is exactly one sender */ - if( (fld=mailimf_find_field(mimeparser->m_header_root, MAILIMF_FIELD_FROM)) == NULL + if( (fld=mailimf_find_field(mimeparser->header_root, MAILIMF_FIELD_FROM)) == NULL || (fld_from=fld->fld_data.fld_from) == NULL || fld_from->frm_mb_list == NULL || fld_from->frm_mb_list->mb_list == NULL @@ -1882,7 +1882,7 @@ int dc_mimeparser_sender_equals_recipient(dc_mimeparser_t* mimeparser) from_addr_norm = dc_normalize_addr(mb->mb_addr_spec); /* get To:/Cc: and check there is exactly one recipent */ - recipients = mailimf_get_recipients(mimeparser->m_header_root); + recipients = mailimf_get_recipients(mimeparser->header_root); if( dc_hash_count(recipients) != 1 ) { goto cleanup; } diff --git a/src/dc_mimeparser.h b/src/dc_mimeparser.h index 7eadeb4e..bd647307 100644 --- a/src/dc_mimeparser.h +++ b/src/dc_mimeparser.h @@ -42,13 +42,13 @@ typedef struct dc_e2ee_helper_t dc_e2ee_helper_t; typedef struct dc_mimepart_t { /** @privatesection */ - int m_type; /*one of DC_MSG_* */ - int m_is_meta; /*meta parts contain eg. profile or group images and are only present if there is at least one "normal" part*/ - int m_int_mimetype; - char* m_msg; - char* m_msg_raw; - int m_bytes; - dc_param_t* m_param; + int type; /*one of DC_MSG_* */ + int is_meta; /*meta parts contain eg. profile or group images and are only present if there is at least one "normal" part*/ + int int_mimetype; + char* msg; + char* msg_raw; + int bytes; + dc_param_t* param; } dc_mimepart_t; @@ -58,29 +58,29 @@ typedef struct dc_mimeparser_t /** @privatesection */ /* data, read-only, must not be free()'d (it is free()'d when the dc_mimeparser_t object gets destructed) */ - carray* m_parts; /* array of dc_mimepart_t objects */ - struct mailmime* m_mimeroot; + carray* parts; /* array of dc_mimepart_t objects */ + struct mailmime* mimeroot; - dc_hash_t m_header; /* memoryhole-compliant header */ - struct mailimf_fields* m_header_root; /* must NOT be freed, do not use for query, merged into m_header, a pointer somewhere to the MIME data*/ - struct mailimf_fields* m_header_protected; /* MUST be freed, do not use for query, merged into m_header */ + dc_hash_t header; /* memoryhole-compliant header */ + struct mailimf_fields* header_root; /* must NOT be freed, do not use for query, merged into header, a pointer somewhere to the MIME data*/ + struct mailimf_fields* header_protected; /* MUST be freed, do not use for query, merged into header */ - char* m_subject; - int m_is_send_by_messenger; + char* subject; + int is_send_by_messenger; - int m_decrypting_failed; /* set, if there are multipart/encrypted parts left after decryption */ + int decrypting_failed; /* set, if there are multipart/encrypted parts left after decryption */ - dc_e2ee_helper_t* m_e2ee_helper; + dc_e2ee_helper_t* e2ee_helper; - const char* m_blobdir; + const char* blobdir; - int m_is_forwarded; + int is_forwarded; - dc_context_t* m_context; + dc_context_t* context; - carray* m_reports; /* array of mailmime objects */ + carray* reports; /* array of mailmime objects */ - int m_is_system_message; + int is_system_message; } dc_mimeparser_t; diff --git a/src/dc_msg.c b/src/dc_msg.c index 7bc8b96e..925c4818 100644 --- a/src/dc_msg.c +++ b/src/dc_msg.c @@ -47,10 +47,10 @@ dc_msg_t* dc_msg_new() exit(15); /* cannot allocate little memory, unrecoverable error */ } - msg->m_magic = DC_MSG_MAGIC; - msg->m_type = DC_MSG_UNDEFINED; - msg->m_state = DC_STATE_UNDEFINED; - msg->m_param = dc_param_new(); + msg->magic = DC_MSG_MAGIC; + msg->type = DC_MSG_UNDEFINED; + msg->state = DC_STATE_UNDEFINED; + msg->param = dc_param_new(); return msg; } @@ -65,13 +65,13 @@ dc_msg_t* dc_msg_new() */ void dc_msg_unref(dc_msg_t* msg) { - if( msg==NULL || msg->m_magic != DC_MSG_MAGIC ) { + if( msg==NULL || msg->magic != DC_MSG_MAGIC ) { return; } dc_msg_empty(msg); - dc_param_unref(msg->m_param); - msg->m_magic = 0; + dc_param_unref(msg->param); + msg->magic = 0; free(msg); } @@ -85,24 +85,24 @@ void dc_msg_unref(dc_msg_t* msg) */ void dc_msg_empty(dc_msg_t* msg) { - if( msg == NULL || msg->m_magic != DC_MSG_MAGIC ) { + if( msg == NULL || msg->magic != DC_MSG_MAGIC ) { return; } - free(msg->m_text); - msg->m_text = NULL; + free(msg->text); + msg->text = NULL; - free(msg->m_rfc724_mid); - msg->m_rfc724_mid = NULL; + free(msg->rfc724_mid); + msg->rfc724_mid = NULL; - free(msg->m_server_folder); - msg->m_server_folder = NULL; + free(msg->server_folder); + msg->server_folder = NULL; - dc_param_set_packed(msg->m_param, NULL); + dc_param_set_packed(msg->param, NULL); - msg->m_context = NULL; + msg->context = NULL; - msg->m_hidden = 0; + msg->hidden = 0; } @@ -120,10 +120,10 @@ void dc_msg_empty(dc_msg_t* msg) */ uint32_t dc_msg_get_id(const dc_msg_t* msg) { - if( msg == NULL || msg->m_magic != DC_MSG_MAGIC ) { + if( msg == NULL || msg->magic != DC_MSG_MAGIC ) { return 0; } - return msg->m_id; + return msg->id; } @@ -143,10 +143,10 @@ uint32_t dc_msg_get_id(const dc_msg_t* msg) */ uint32_t dc_msg_get_from_id(const dc_msg_t* msg) { - if( msg == NULL || msg->m_magic != DC_MSG_MAGIC ) { + if( msg == NULL || msg->magic != DC_MSG_MAGIC ) { return 0; } - return msg->m_from_id; + return msg->from_id; } @@ -162,10 +162,10 @@ uint32_t dc_msg_get_from_id(const dc_msg_t* msg) */ uint32_t dc_msg_get_chat_id(const dc_msg_t* msg) { - if( msg == NULL || msg->m_magic != DC_MSG_MAGIC ) { + if( msg == NULL || msg->magic != DC_MSG_MAGIC ) { return 0; } - return msg->m_chat_blocked? DC_CHAT_ID_DEADDROP : msg->m_chat_id; + return msg->chat_blocked? DC_CHAT_ID_DEADDROP : msg->chat_id; } @@ -180,10 +180,10 @@ uint32_t dc_msg_get_chat_id(const dc_msg_t* msg) */ int dc_msg_get_type(const dc_msg_t* msg) { - if( msg == NULL || msg->m_magic != DC_MSG_MAGIC ) { + if( msg == NULL || msg->magic != DC_MSG_MAGIC ) { return DC_MSG_UNDEFINED; } - return msg->m_type; + return msg->type; } @@ -216,10 +216,10 @@ int dc_msg_get_type(const dc_msg_t* msg) */ int dc_msg_get_state(const dc_msg_t* msg) { - if( msg == NULL || msg->m_magic != DC_MSG_MAGIC ) { + if( msg == NULL || msg->magic != DC_MSG_MAGIC ) { return DC_STATE_UNDEFINED; } - return msg->m_state; + return msg->state; } @@ -235,11 +235,11 @@ int dc_msg_get_state(const dc_msg_t* msg) */ time_t dc_msg_get_timestamp(const dc_msg_t* msg) { - if( msg == NULL || msg->m_magic != DC_MSG_MAGIC ) { + if( msg == NULL || msg->magic != DC_MSG_MAGIC ) { return 0; } - return msg->m_timestamp_sent? msg->m_timestamp_sent : msg->m_timestamp; + return msg->timestamp_sent? msg->timestamp_sent : msg->timestamp; } @@ -266,11 +266,11 @@ char* dc_msg_get_text(const dc_msg_t* msg) { char* ret; - if( msg == NULL || msg->m_magic != DC_MSG_MAGIC ) { + if( msg == NULL || msg->magic != DC_MSG_MAGIC ) { return dc_strdup(NULL); } - ret = dc_strdup(msg->m_text); + ret = dc_strdup(msg->text); dc_truncate_str(ret, DC_MAX_GET_TEXT_LEN); /* we do not do this on load: (1) for speed reasons (2) we may decide to process the full text on other places */ return ret; } @@ -293,11 +293,11 @@ char* dc_msg_get_file(const dc_msg_t* msg) { char* ret = NULL; - if( msg == NULL || msg->m_magic != DC_MSG_MAGIC ) { + if( msg == NULL || msg->magic != DC_MSG_MAGIC ) { goto cleanup; } - ret = dc_param_get(msg->m_param, DC_PARAM_FILE, NULL); + ret = dc_param_get(msg->param, DC_PARAM_FILE, NULL); cleanup: return ret? ret : dc_strdup(NULL); @@ -318,11 +318,11 @@ char* dc_msg_get_filename(const dc_msg_t* msg) { char* ret = NULL, *pathNfilename = NULL; - if( msg == NULL || msg->m_magic != DC_MSG_MAGIC ) { + if( msg == NULL || msg->magic != DC_MSG_MAGIC ) { goto cleanup; } - pathNfilename = dc_param_get(msg->m_param, DC_PARAM_FILE, NULL); + pathNfilename = dc_param_get(msg->param, DC_PARAM_FILE, NULL); if( pathNfilename == NULL ) { goto cleanup; } @@ -349,13 +349,13 @@ char* dc_msg_get_filemime(const dc_msg_t* msg) char* ret = NULL; char* file = NULL; - if( msg == NULL || msg->m_magic != DC_MSG_MAGIC ) { + if( msg == NULL || msg->magic != DC_MSG_MAGIC ) { goto cleanup; } - ret = dc_param_get(msg->m_param, DC_PARAM_MIMETYPE, NULL); + ret = dc_param_get(msg->param, DC_PARAM_MIMETYPE, NULL); if( ret == NULL ) { - file = dc_param_get(msg->m_param, DC_PARAM_FILE, NULL); + file = dc_param_get(msg->param, DC_PARAM_FILE, NULL); if( file == NULL ) { goto cleanup; } @@ -387,11 +387,11 @@ uint64_t dc_msg_get_filebytes(const dc_msg_t* msg) uint64_t ret = 0; char* file = NULL; - if( msg == NULL || msg->m_magic != DC_MSG_MAGIC ) { + if( msg == NULL || msg->magic != DC_MSG_MAGIC ) { goto cleanup; } - file = dc_param_get(msg->m_param, DC_PARAM_FILE, NULL); + file = dc_param_get(msg->param, DC_PARAM_FILE, NULL); if( file == NULL ) { goto cleanup; } @@ -409,9 +409,9 @@ cleanup: * * The information is returned by a dc_lot_t object with the following fields: * - * - dc_lot_t::m_text1: Author of the media. For voice messages, this is the sender. + * - dc_lot_t::text1: Author of the media. For voice messages, this is the sender. * For music messages, the information are read from the filename. NULL if unknown. - * - dc_lot_t::m_text2: Title of the media. For voice messages, this is the date. + * - dc_lot_t::text2: Title of the media. For voice messages, this is the date. * For music messages, the information are read from the filename. NULL if unknown. * * Currently, we do not read ID3 and such at this stage, the needed libraries are too complicated and oversized. @@ -427,35 +427,35 @@ dc_lot_t* dc_msg_get_mediainfo(const dc_msg_t* msg) char* pathNfilename = NULL; dc_contact_t* contact = NULL; - if( msg == NULL || msg->m_magic != DC_MSG_MAGIC || msg->m_context == NULL ) { + if( msg == NULL || msg->magic != DC_MSG_MAGIC || msg->context == NULL ) { goto cleanup; } - if( msg->m_type == DC_MSG_VOICE ) + if( msg->type == DC_MSG_VOICE ) { - if( (contact = dc_get_contact(msg->m_context, msg->m_from_id))==NULL ) { + if( (contact = dc_get_contact(msg->context, msg->from_id))==NULL ) { goto cleanup; } - ret->m_text1 = dc_strdup((contact->m_name&&contact->m_name[0])? contact->m_name : contact->m_addr); - ret->m_text2 = dc_stock_str(msg->m_context, DC_STR_VOICEMESSAGE); + ret->text1 = dc_strdup((contact->name&&contact->name[0])? contact->name : contact->addr); + ret->text2 = dc_stock_str(msg->context, DC_STR_VOICEMESSAGE); } else { - ret->m_text1 = dc_param_get(msg->m_param, DC_PARAM_AUTHORNAME, NULL); - ret->m_text2 = dc_param_get(msg->m_param, DC_PARAM_TRACKNAME, NULL); - if( ret->m_text1 && ret->m_text1[0] && ret->m_text2 && ret->m_text2[0] ) { + ret->text1 = dc_param_get(msg->param, DC_PARAM_AUTHORNAME, NULL); + ret->text2 = dc_param_get(msg->param, DC_PARAM_TRACKNAME, NULL); + if( ret->text1 && ret->text1[0] && ret->text2 && ret->text2[0] ) { goto cleanup; } - free(ret->m_text1); ret->m_text1 = NULL; - free(ret->m_text2); ret->m_text2 = NULL; + free(ret->text1); ret->text1 = NULL; + free(ret->text2); ret->text2 = NULL; - pathNfilename = dc_param_get(msg->m_param, DC_PARAM_FILE, NULL); + pathNfilename = dc_param_get(msg->param, DC_PARAM_FILE, NULL); if( pathNfilename == NULL ) { goto cleanup; } - dc_msg_get_authorNtitle_from_filename(pathNfilename, &ret->m_text1, &ret->m_text2); - if( ret->m_text1 == NULL && ret->m_text2 != NULL ) { - ret->m_text1 = dc_stock_str(msg->m_context, DC_STR_AUDIO); + dc_msg_get_authorNtitle_from_filename(pathNfilename, &ret->text1, &ret->text2); + if( ret->text1 == NULL && ret->text2 != NULL ) { + ret->text1 = dc_stock_str(msg->context, DC_STR_AUDIO); } } @@ -482,10 +482,10 @@ cleanup: */ int dc_msg_get_width(const dc_msg_t* msg) { - if( msg == NULL || msg->m_magic != DC_MSG_MAGIC ) { + if( msg == NULL || msg->magic != DC_MSG_MAGIC ) { return 0; } - return dc_param_get_int(msg->m_param, DC_PARAM_WIDTH, 0); + return dc_param_get_int(msg->param, DC_PARAM_WIDTH, 0); } @@ -505,10 +505,10 @@ int dc_msg_get_width(const dc_msg_t* msg) */ int dc_msg_get_height(const dc_msg_t* msg) { - if( msg == NULL || msg->m_magic != DC_MSG_MAGIC ) { + if( msg == NULL || msg->magic != DC_MSG_MAGIC ) { return 0; } - return dc_param_get_int(msg->m_param, DC_PARAM_HEIGHT, 0); + return dc_param_get_int(msg->param, DC_PARAM_HEIGHT, 0); } @@ -525,10 +525,10 @@ int dc_msg_get_height(const dc_msg_t* msg) */ int dc_msg_get_duration(const dc_msg_t* msg) { - if( msg == NULL || msg->m_magic != DC_MSG_MAGIC ) { + if( msg == NULL || msg->magic != DC_MSG_MAGIC ) { return 0; } - return dc_param_get_int(msg->m_param, DC_PARAM_DURATION, 0); + return dc_param_get_int(msg->param, DC_PARAM_DURATION, 0); } @@ -544,21 +544,21 @@ int dc_msg_get_showpadlock(const dc_msg_t* msg) /* a padlock guarantees that the message is e2ee _and_ answers will be as well */ int show_encryption_state = 0; - if( msg == NULL || msg->m_magic != DC_MSG_MAGIC || msg->m_context == NULL ) { + if( msg == NULL || msg->magic != DC_MSG_MAGIC || msg->context == NULL ) { return 0; } - if( msg->m_context->m_e2ee_enabled ) { + if( msg->context->e2ee_enabled ) { show_encryption_state = 1; } else { - dc_chat_t* chat = dc_get_chat(msg->m_context, msg->m_chat_id); + dc_chat_t* chat = dc_get_chat(msg->context, msg->chat_id); show_encryption_state = dc_chat_is_verified(chat); dc_chat_unref(chat); } if( show_encryption_state ) { - if( dc_param_get_int(msg->m_param, DC_PARAM_GUARANTEE_E2EE, 0) != 0 ) { + if( dc_param_get_int(msg->param, DC_PARAM_GUARANTEE_E2EE, 0) != 0 ) { return 1; } } @@ -572,14 +572,14 @@ int dc_msg_get_showpadlock(const dc_msg_t* msg) * * The summary is returned by a dc_lot_t object with the following fields: * - * - dc_lot_t::m_text1: contains the username or the string "Me". - * The string may be colored by having a look at m_text1_meaning. + * - dc_lot_t::text1: contains the username or the string "Me". + * The string may be colored by having a look at text1_meaning. * If the name should not be displayed, the element is NULL. - * - dc_lot_t::m_text1_meaning: one of DC_TEXT1_USERNAME or DC_TEXT1_SELF. - * Typically used to show dc_lot_t::m_text1 with different colors. 0 if not applicable. - * - dc_lot_t::m_text2: contains an excerpt of the message text. - * - dc_lot_t::m_timestamp: the timestamp of the message. - * - dc_lot_t::m_state: The state of the message as one of the DC_STATE_* constants (see #dc_msg_get_state()). + * - dc_lot_t::text1_meaning: one of DC_TEXT1_USERNAME or DC_TEXT1_SELF. + * Typically used to show dc_lot_t::text1 with different colors. 0 if not applicable. + * - dc_lot_t::text2: contains an excerpt of the message text. + * - dc_lot_t::timestamp: the timestamp of the message. + * - dc_lot_t::state: The state of the message as one of the DC_STATE_* constants (see #dc_msg_get_state()). * * Typically used to display a search result. See also dc_chatlist_get_summary() to display a list of chats. * @@ -595,22 +595,22 @@ dc_lot_t* dc_msg_get_summary(const dc_msg_t* msg, const dc_chat_t* chat) dc_contact_t* contact = NULL; dc_chat_t* chat_to_delete = NULL; - if( msg==NULL || msg->m_magic != DC_MSG_MAGIC ) { + if( msg==NULL || msg->magic != DC_MSG_MAGIC ) { goto cleanup; } if( chat == NULL ) { - if( (chat_to_delete=dc_get_chat(msg->m_context, msg->m_chat_id)) == NULL ) { + if( (chat_to_delete=dc_get_chat(msg->context, msg->chat_id)) == NULL ) { goto cleanup; } chat = chat_to_delete; } - if( msg->m_from_id != DC_CONTACT_ID_SELF && DC_CHAT_TYPE_IS_MULTI(chat->m_type) ) { - contact = dc_get_contact(chat->m_context, msg->m_from_id); + if( msg->from_id != DC_CONTACT_ID_SELF && DC_CHAT_TYPE_IS_MULTI(chat->type) ) { + contact = dc_get_contact(chat->context, msg->from_id); } - dc_lot_fill(ret, msg, chat, contact, msg->m_context); + dc_lot_fill(ret, msg, chat, contact, msg->context); cleanup: dc_contact_unref(contact); @@ -631,11 +631,11 @@ cleanup: */ char* dc_msg_get_summarytext(const dc_msg_t* msg, int approx_characters) { - if( msg==NULL || msg->m_magic != DC_MSG_MAGIC ) { + if( msg==NULL || msg->magic != DC_MSG_MAGIC ) { return dc_strdup(NULL); } - return dc_msg_get_summarytext_by_raw(msg->m_type, msg->m_text, msg->m_param, approx_characters, msg->m_context); + return dc_msg_get_summarytext_by_raw(msg->type, msg->text, msg->param, approx_characters, msg->context); } @@ -651,10 +651,10 @@ char* dc_msg_get_summarytext(const dc_msg_t* msg, int approx_characters) */ int dc_msg_is_sent(const dc_msg_t* msg) { - if( msg == NULL || msg->m_magic != DC_MSG_MAGIC ) { + if( msg == NULL || msg->magic != DC_MSG_MAGIC ) { return 0; } - return (msg->m_state >= DC_STATE_OUT_DELIVERED)? 1 : 0; + return (msg->state >= DC_STATE_OUT_DELIVERED)? 1 : 0; } @@ -672,10 +672,10 @@ int dc_msg_is_sent(const dc_msg_t* msg) */ int dc_msg_is_starred(const dc_msg_t* msg) { - if( msg == NULL || msg->m_magic != DC_MSG_MAGIC ) { + if( msg == NULL || msg->magic != DC_MSG_MAGIC ) { return 0; } - return msg->m_starred? 1 : 0; + return msg->starred? 1 : 0; } @@ -697,10 +697,10 @@ int dc_msg_is_starred(const dc_msg_t* msg) */ int dc_msg_is_forwarded(const dc_msg_t* msg) { - if( msg == NULL || msg->m_magic != DC_MSG_MAGIC ) { + if( msg == NULL || msg->magic != DC_MSG_MAGIC ) { return 0; } - return dc_param_get_int(msg->m_param, DC_PARAM_FORWARDED, 0)? 1 : 0; + return dc_param_get_int(msg->param, DC_PARAM_FORWARDED, 0)? 1 : 0; } @@ -722,14 +722,14 @@ int dc_msg_is_forwarded(const dc_msg_t* msg) */ int dc_msg_is_info(const dc_msg_t* msg) { - if( msg == NULL || msg->m_magic != DC_MSG_MAGIC ) { + if( msg == NULL || msg->magic != DC_MSG_MAGIC ) { return 0; } - int cmd = dc_param_get_int(msg->m_param, DC_PARAM_CMD, 0); + int cmd = dc_param_get_int(msg->param, DC_PARAM_CMD, 0); - if( msg->m_from_id == DC_CONTACT_ID_DEVICE - || msg->m_to_id == DC_CONTACT_ID_DEVICE + if( msg->from_id == DC_CONTACT_ID_DEVICE + || msg->to_id == DC_CONTACT_ID_DEVICE || (cmd && cmd != DC_CMD_AUTOCRYPT_SETUP_MESSAGE) ) { return 1; } @@ -754,11 +754,11 @@ int dc_msg_is_info(const dc_msg_t* msg) */ int dc_msg_is_setupmessage(const dc_msg_t* msg) { - if( msg == NULL || msg->m_magic != DC_MSG_MAGIC || msg->m_type != DC_MSG_FILE ) { + if( msg == NULL || msg->magic != DC_MSG_MAGIC || msg->type != DC_MSG_FILE ) { return 0; } - return dc_param_get_int(msg->m_param, DC_PARAM_CMD, 0)==DC_CMD_AUTOCRYPT_SETUP_MESSAGE? 1 : 0; + return dc_param_get_int(msg->param, DC_PARAM_CMD, 0)==DC_CMD_AUTOCRYPT_SETUP_MESSAGE? 1 : 0; } @@ -793,7 +793,7 @@ char* dc_msg_get_setupcodebegin(const dc_msg_t* msg) goto cleanup; } - if( !dc_read_file(filename, (void**)&buf, &buf_bytes, msg->m_context) || buf == NULL || buf_bytes <= 0 ) { + if( !dc_read_file(filename, (void**)&buf, &buf_bytes, msg->context) || buf == NULL || buf_bytes <= 0 ) { goto cleanup; } @@ -825,30 +825,30 @@ static int dc_msg_set_from_stmt(dc_msg_t* msg, sqlite3_stmt* row, int row_offset { dc_msg_empty(msg); - msg->m_id = (uint32_t)sqlite3_column_int (row, row_offset++); - msg->m_rfc724_mid = dc_strdup((char*)sqlite3_column_text (row, row_offset++)); - msg->m_server_folder= dc_strdup((char*)sqlite3_column_text (row, row_offset++)); - msg->m_server_uid = (uint32_t)sqlite3_column_int (row, row_offset++); - msg->m_chat_id = (uint32_t)sqlite3_column_int (row, row_offset++); + msg->id = (uint32_t)sqlite3_column_int (row, row_offset++); + msg->rfc724_mid = dc_strdup((char*)sqlite3_column_text (row, row_offset++)); + msg->server_folder= dc_strdup((char*)sqlite3_column_text (row, row_offset++)); + msg->server_uid = (uint32_t)sqlite3_column_int (row, row_offset++); + msg->chat_id = (uint32_t)sqlite3_column_int (row, row_offset++); - msg->m_from_id = (uint32_t)sqlite3_column_int (row, row_offset++); - msg->m_to_id = (uint32_t)sqlite3_column_int (row, row_offset++); - msg->m_timestamp = (time_t)sqlite3_column_int64(row, row_offset++); - msg->m_timestamp_sent = (time_t)sqlite3_column_int64(row, row_offset++); - msg->m_timestamp_rcvd = (time_t)sqlite3_column_int64(row, row_offset++); + msg->from_id = (uint32_t)sqlite3_column_int (row, row_offset++); + msg->to_id = (uint32_t)sqlite3_column_int (row, row_offset++); + msg->timestamp = (time_t)sqlite3_column_int64(row, row_offset++); + msg->timestamp_sent = (time_t)sqlite3_column_int64(row, row_offset++); + msg->timestamp_rcvd = (time_t)sqlite3_column_int64(row, row_offset++); - msg->m_type = sqlite3_column_int (row, row_offset++); - msg->m_state = sqlite3_column_int (row, row_offset++); - msg->m_is_msgrmsg = sqlite3_column_int (row, row_offset++); - msg->m_text = dc_strdup((char*)sqlite3_column_text (row, row_offset++)); + msg->type = sqlite3_column_int (row, row_offset++); + msg->state = sqlite3_column_int (row, row_offset++); + msg->is_msgrmsg = sqlite3_column_int (row, row_offset++); + msg->text = dc_strdup((char*)sqlite3_column_text (row, row_offset++)); - dc_param_set_packed( msg->m_param, (char*)sqlite3_column_text (row, row_offset++)); - msg->m_starred = sqlite3_column_int (row, row_offset++); - msg->m_hidden = sqlite3_column_int (row, row_offset++); - msg->m_chat_blocked = sqlite3_column_int (row, row_offset++); + dc_param_set_packed( msg->param, (char*)sqlite3_column_text (row, row_offset++)); + msg->starred = sqlite3_column_int (row, row_offset++); + msg->hidden = sqlite3_column_int (row, row_offset++); + msg->chat_blocked = sqlite3_column_int (row, row_offset++); - if( msg->m_chat_blocked == 2 ) { - dc_truncate_n_unwrap_str(msg->m_text, 256 /* 256 characters is about a half screen on a 5" smartphone display */, + if( msg->chat_blocked == 2 ) { + dc_truncate_n_unwrap_str(msg->text, 256 /* 256 characters is about a half screen on a 5" smartphone display */, 0/*unwrap*/); } @@ -867,11 +867,11 @@ int dc_msg_load_from_db(dc_msg_t* msg, dc_context_t* context, uint32_t id) int success = 0; sqlite3_stmt* stmt = NULL; - if( msg==NULL || msg->m_magic != DC_MSG_MAGIC || context==NULL || context->m_sql==NULL ) { + if( msg==NULL || msg->magic != DC_MSG_MAGIC || context==NULL || context->sql==NULL ) { goto cleanup; } - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT " DC_MSG_FIELDS " FROM msgs m LEFT JOIN chats c ON c.id=m.chat_id" " WHERE m.id=?;"); @@ -885,7 +885,7 @@ int dc_msg_load_from_db(dc_msg_t* msg, dc_context_t* context, uint32_t id) goto cleanup; } - msg->m_context = context; + msg->context = context; success = 1; @@ -1053,13 +1053,13 @@ int dc_msg_is_increation(const dc_msg_t* msg) /* surrounds dc_msg_is_increation() with locking and error checking */ int is_increation = 0; - if( msg==NULL || msg->m_magic!=DC_MSG_MAGIC || msg->m_context==NULL ) { + if( msg==NULL || msg->magic!=DC_MSG_MAGIC || msg->context==NULL ) { return 0; } - if( DC_MSG_NEEDS_ATTACHMENT(msg->m_type) ) + if( DC_MSG_NEEDS_ATTACHMENT(msg->type) ) { - char* pathNfilename = dc_param_get(msg->m_param, DC_PARAM_FILE, NULL); + char* pathNfilename = dc_param_get(msg->param, DC_PARAM_FILE, NULL); if( pathNfilename ) { char* totest = dc_mprintf("%s.increation", pathNfilename); if( dc_file_exist(totest) ) { @@ -1076,14 +1076,14 @@ int dc_msg_is_increation(const dc_msg_t* msg) void dc_msg_save_param_to_disk(dc_msg_t* msg) { - if( msg == NULL || msg->m_magic != DC_MSG_MAGIC || msg->m_context == NULL || msg->m_context->m_sql == NULL ) { + if( msg == NULL || msg->magic != DC_MSG_MAGIC || msg->context == NULL || msg->context->sql == NULL ) { return; } - sqlite3_stmt* stmt = dc_sqlite3_prepare(msg->m_context->m_sql, + sqlite3_stmt* stmt = dc_sqlite3_prepare(msg->context->sql, "UPDATE msgs SET param=? WHERE id=?;"); - sqlite3_bind_text(stmt, 1, msg->m_param->m_packed, -1, SQLITE_STATIC); - sqlite3_bind_int (stmt, 2, msg->m_id); + sqlite3_bind_text(stmt, 1, msg->param->packed, -1, SQLITE_STATIC); + sqlite3_bind_int (stmt, 2, msg->id); sqlite3_step(stmt); sqlite3_finalize(stmt); } @@ -1112,20 +1112,20 @@ void dc_msg_save_param_to_disk(dc_msg_t* msg) */ void dc_msg_latefiling_mediasize(dc_msg_t* msg, int width, int height, int duration) { - if( msg == NULL || msg->m_magic != DC_MSG_MAGIC ) { + if( msg == NULL || msg->magic != DC_MSG_MAGIC ) { goto cleanup; } if( width > 0 ) { - dc_param_set_int(msg->m_param, DC_PARAM_WIDTH, width); + dc_param_set_int(msg->param, DC_PARAM_WIDTH, width); } if( height > 0 ) { - dc_param_set_int(msg->m_param, DC_PARAM_HEIGHT, height); + dc_param_set_int(msg->param, DC_PARAM_HEIGHT, height); } if( duration > 0 ) { - dc_param_set_int(msg->m_param, DC_PARAM_DURATION, duration); + dc_param_set_int(msg->param, DC_PARAM_DURATION, duration); } dc_msg_save_param_to_disk(msg); diff --git a/src/dc_msg.h b/src/dc_msg.h index 8f9b5b11..52066e78 100644 --- a/src/dc_msg.h +++ b/src/dc_msg.h @@ -36,61 +36,55 @@ struct _dc_msg { /** @privatesection */ - uint32_t m_magic; + uint32_t magic; /** * Message ID. Never 0. */ - uint32_t m_id; + uint32_t id; /** - * Contact ID of the sender. Never 0. See dc_contact_t::m_id for special IDs. + * Contact ID of the sender. Never 0. See dc_contact_t::id for special IDs. * Use dc_get_contact() to load details about this contact. */ - uint32_t m_from_id; + uint32_t from_id; /** - * Contact ID of the recipient. Never 0. See dc_contact_t::m_id for special IDs. + * Contact ID of the recipient. Never 0. See dc_contact_t::id for special IDs. * Use dc_get_contact() to load details about this contact. */ - uint32_t m_to_id; + uint32_t to_id; /** - * Chat ID the message belongs to. Never 0. See dc_chat_t::m_id for special IDs. + * Chat ID the message belongs to. Never 0. See dc_chat_t::id for special IDs. * Use dc_get_chat() to load details about the chat. */ - uint32_t m_chat_id; + uint32_t chat_id; - /* - * The mailbox object the chat belongs to. Never NULL. - */ - //dc_context_t* m_context; + int type; /**< Message type. It is recommended to use dc_msg_set_type() and dc_msg_get_type() to access this field. */ + int state; /**< Message state. It is recommended to use dc_msg_get_state() to access this field. */ - int m_type; /**< Message type. It is recommended to use dc_msg_set_type() and dc_msg_get_type() to access this field. */ + int hidden; /**< Used eg. for handshaking messages. */ - int m_state; /**< Message state. It is recommended to use dc_msg_get_state() to access this field. */ + time_t timestamp; /**< Unix time for sorting. 0 if unset. */ + time_t timestamp_sent; /**< Unix time the message was sent. 0 if unset. */ + time_t timestamp_rcvd; /**< Unix time the message was recveived. 0 if unset. */ - int m_hidden; /**< Used eg. for handshaking messages. */ + char* text; /**< Message text. NULL if unset. It is recommended to use dc_msg_set_text() and dc_msg_get_text() to access this field. */ - time_t m_timestamp; /**< Unix time for sorting. 0 if unset. */ - time_t m_timestamp_sent; /**< Unix time the message was sent. 0 if unset. */ - time_t m_timestamp_rcvd; /**< Unix time the message was recveived. 0 if unset. */ - - char* m_text; /**< Message text. NULL if unset. It is recommended to use dc_msg_set_text() and dc_msg_get_text() to access this field. */ - - dc_context_t* m_context; /**< may be NULL, set on loading from database and on sending */ - char* m_rfc724_mid; /**< The RFC-742 Message-ID */ - char* m_server_folder; /**< Folder where the message was last seen on the server */ - uint32_t m_server_uid; /**< UID last seen on the server for this message */ - int m_is_msgrmsg; /**< Set to 1 if the message was sent by another messenger. 0 otherwise. */ - int m_starred; /**< Starred-state of the message. 0=no, 1=yes. */ - int m_chat_blocked; /**< Internal */ - dc_param_t* m_param; /**< Additional paramter for the message. Never a NULL-pointer. It is recommended to use setters and getters instead of accessing this field directly. */ + dc_context_t* context; /**< may be NULL, set on loading from database and on sending */ + char* rfc724_mid; /**< The RFC-742 Message-ID */ + char* server_folder; /**< Folder where the message was last seen on the server */ + uint32_t server_uid; /**< UID last seen on the server for this message */ + int is_msgrmsg; /**< Set to 1 if the message was sent by another messenger. 0 otherwise. */ + int starred; /**< Starred-state of the message. 0=no, 1=yes. */ + int chat_blocked; /**< Internal */ + dc_param_t* param; /**< Additional paramter for the message. Never a NULL-pointer. It is recommended to use setters and getters instead of accessing this field directly. */ }; @@ -102,7 +96,7 @@ void dc_msg_guess_msgtype_from_suffix (const char* pathNfilename void dc_msg_get_authorNtitle_from_filename (const char* pathNfilename, char** ret_author, char** ret_title); #define DC_MSG_NEEDS_ATTACHMENT(a) ((a)==DC_MSG_IMAGE || (a)==DC_MSG_GIF || (a)==DC_MSG_AUDIO || (a)==DC_MSG_VOICE || (a)==DC_MSG_VIDEO || (a)==DC_MSG_FILE) -#define DC_MSG_MAKE_FILENAME_SEARCHABLE(a) ((a)==DC_MSG_AUDIO || (a)==DC_MSG_FILE || (a)==DC_MSG_VIDEO ) /* add filename.ext (without path) to m_text? this is needed for the fulltext search. The extension is useful to get all PDF, all MP3 etc. */ +#define DC_MSG_MAKE_FILENAME_SEARCHABLE(a) ((a)==DC_MSG_AUDIO || (a)==DC_MSG_FILE || (a)==DC_MSG_VIDEO ) /* add filename.ext (without path) to text? this is needed for the fulltext search. The extension is useful to get all PDF, all MP3 etc. */ #define DC_MSG_MAKE_SUFFIX_SEARCHABLE(a) ((a)==DC_MSG_IMAGE || (a)==DC_MSG_GIF || (a)==DC_MSG_VOICE) #define DC_APPROX_SUBJECT_CHARS 32 /* as we do not cut inside words, this results in about 32-42 characters. diff --git a/src/dc_param.c b/src/dc_param.c index 127948e6..d896e4f4 100644 --- a/src/dc_param.c +++ b/src/dc_param.c @@ -74,7 +74,7 @@ dc_param_t* dc_param_new() exit(28); /* cannot allocate little memory, unrecoverable error */ } - param->m_packed = calloc(1, 1); + param->packed = calloc(1, 1); return param; } @@ -93,7 +93,7 @@ void dc_param_unref(dc_param_t* param) } dc_param_empty(param); - free(param->m_packed); + free(param->packed); free(param); } @@ -111,7 +111,7 @@ void dc_param_empty(dc_param_t* param) return; } - param->m_packed[0] = 0; + param->packed[0] = 0; } @@ -135,8 +135,8 @@ void dc_param_set_packed(dc_param_t* param, const char* packed) dc_param_empty(param); if( packed ) { - free(param->m_packed); - param->m_packed = dc_strdup(packed); + free(param->packed); + param->packed = dc_strdup(packed); } } @@ -154,9 +154,9 @@ void dc_param_set_urlencoded(dc_param_t* param, const char* urlencoded) dc_param_empty(param); if( urlencoded ) { - free(param->m_packed); - param->m_packed = dc_strdup(urlencoded); - dc_str_replace(¶m->m_packed, "&", "\n"); + free(param->packed); + param->packed = dc_strdup(urlencoded); + dc_str_replace(¶m->packed, "&", "\n"); } } @@ -177,7 +177,7 @@ int dc_param_exists(dc_param_t* param, int key) return 0; } - return find_param(param->m_packed, key, &p2)? 1 : 0; + return find_param(param->packed, key, &p2)? 1 : 0; } @@ -198,7 +198,7 @@ char* dc_param_get(dc_param_t* param, int key, const char* def) return def? dc_strdup(def) : NULL; } - p1 = find_param(param->m_packed, key, &p2); + p1 = find_param(param->packed, key, &p2); if( p1 == NULL ) { return def? dc_strdup(def) : NULL; } @@ -256,7 +256,7 @@ void dc_param_set(dc_param_t* param, int key, const char* value) return; } - old1 = param->m_packed; + old1 = param->packed; old2 = NULL; /* remove existing parameter from packed string, if any */ @@ -295,8 +295,8 @@ void dc_param_set(dc_param_t* param, int key, const char* value) old2? old2 : ""); } - free(param->m_packed); - param->m_packed = new1; + free(param->packed); + param->packed = new1; } diff --git a/src/dc_param.h b/src/dc_param.h index c1835937..a8a2197f 100644 --- a/src/dc_param.h +++ b/src/dc_param.h @@ -39,7 +39,7 @@ extern "C" { typedef struct dc_param_t { /** @privatesection */ - char* m_packed; /**< Always set, never NULL. */ + char* packed; /**< Always set, never NULL. */ } dc_param_t; diff --git a/src/dc_pgp.c b/src/dc_pgp.c index db81f1ec..aa56b59c 100644 --- a/src/dc_pgp.c +++ b/src/dc_pgp.c @@ -419,18 +419,18 @@ int dc_pgp_is_valid_key(dc_context_t* context, const dc_key_t* raw_key) pgp_memory_t* keysmem = pgp_memory_new(); if( context==NULL || raw_key==NULL - || raw_key->m_binary == NULL || raw_key->m_bytes <= 0 + || raw_key->binary == NULL || raw_key->bytes <= 0 || public_keys==NULL || private_keys==NULL || keysmem==NULL ) { goto cleanup; } - pgp_memory_add(keysmem, raw_key->m_binary, raw_key->m_bytes); + pgp_memory_add(keysmem, raw_key->binary, raw_key->bytes); pgp_filter_keys_from_mem(&s_io, public_keys, private_keys, NULL, 0, keysmem); /* function returns 0 on any error in any packet - this does not mean, we cannot use the key. We check the details below therefore. */ - if( raw_key->m_type == DC_KEY_PUBLIC && public_keys->keyc >= 1 ) { + if( raw_key->type == DC_KEY_PUBLIC && public_keys->keyc >= 1 ) { key_is_valid = 1; } - else if( raw_key->m_type == DC_KEY_PRIVATE && private_keys->keyc >= 1 ) { + else if( raw_key->type == DC_KEY_PRIVATE && private_keys->keyc >= 1 ) { key_is_valid = 1; } @@ -450,15 +450,15 @@ int dc_pgp_calc_fingerprint(const dc_key_t* raw_key, uint8_t** ret_fingerprint, pgp_memory_t* keysmem = pgp_memory_new(); if( raw_key==NULL || ret_fingerprint==NULL || *ret_fingerprint!=NULL || ret_fingerprint_bytes==NULL || *ret_fingerprint_bytes!=0 - || raw_key->m_binary == NULL || raw_key->m_bytes <= 0 + || raw_key->binary == NULL || raw_key->bytes <= 0 || public_keys==NULL || private_keys==NULL || keysmem==NULL ) { goto cleanup; } - pgp_memory_add(keysmem, raw_key->m_binary, raw_key->m_bytes); + pgp_memory_add(keysmem, raw_key->binary, raw_key->bytes); pgp_filter_keys_from_mem(&s_io, public_keys, private_keys, NULL, 0, keysmem); - if( raw_key->m_type != DC_KEY_PUBLIC || public_keys->keyc <= 0 ) { + if( raw_key->type != DC_KEY_PUBLIC || public_keys->keyc <= 0 ) { goto cleanup; } @@ -496,10 +496,10 @@ int dc_pgp_split_key(dc_context_t* context, const dc_key_t* private_in, dc_key_t goto cleanup; } - pgp_memory_add(keysmem, private_in->m_binary, private_in->m_bytes); + pgp_memory_add(keysmem, private_in->binary, private_in->bytes); pgp_filter_keys_from_mem(&s_io, public_keys, private_keys, NULL, 0, keysmem); - if( private_in->m_type!=DC_KEY_PRIVATE || private_keys->keyc <= 0 ) { + if( private_in->type!=DC_KEY_PRIVATE || private_keys->keyc <= 0 ) { dc_log_warning(context, 0, "Split key: Given key is no private key."); goto cleanup; } @@ -551,7 +551,7 @@ int dc_pgp_pk_encrypt( dc_context_t* context, int i, success = 0; if( context==NULL || plain_text==NULL || plain_bytes==0 || ret_ctext==NULL || ret_ctext_bytes==NULL - || raw_public_keys_for_encryption==NULL || raw_public_keys_for_encryption->m_count<=0 + || raw_public_keys_for_encryption==NULL || raw_public_keys_for_encryption->count<=0 || keysmem==NULL || public_keys==NULL || private_keys==NULL || dummy_keys==NULL ) { goto cleanup; } @@ -560,9 +560,9 @@ int dc_pgp_pk_encrypt( dc_context_t* context, *ret_ctext_bytes = 0; /* setup keys (the keys may come from pgp_filter_keys_fileread(), see also pgp_keyring_add(rcpts, key)) */ - for( i = 0; i < raw_public_keys_for_encryption->m_count; i++ ) { + for( i = 0; i < raw_public_keys_for_encryption->count; i++ ) { pgp_memory_clear(keysmem); - pgp_memory_add(keysmem, raw_public_keys_for_encryption->m_keys[i]->m_binary, raw_public_keys_for_encryption->m_keys[i]->m_bytes); + pgp_memory_add(keysmem, raw_public_keys_for_encryption->keys[i]->binary, raw_public_keys_for_encryption->keys[i]->bytes); pgp_filter_keys_from_mem(&s_io, public_keys, private_keys/*should stay empty*/, NULL, 0, keysmem); } @@ -579,7 +579,7 @@ int dc_pgp_pk_encrypt( dc_context_t* context, if( raw_private_key_for_signing ) { pgp_memory_clear(keysmem); - pgp_memory_add(keysmem, raw_private_key_for_signing->m_binary, raw_private_key_for_signing->m_bytes); + pgp_memory_add(keysmem, raw_private_key_for_signing->binary, raw_private_key_for_signing->bytes); pgp_filter_keys_from_mem(&s_io, dummy_keys, private_keys, NULL, 0, keysmem); if( private_keys->keyc <= 0 ) { dc_log_warning(context, 0, "No key for signing found."); @@ -645,7 +645,7 @@ int dc_pgp_pk_decrypt( dc_context_t* context, int i, success = 0; if( context==NULL || ctext==NULL || ctext_bytes==0 || ret_plain==NULL || ret_plain_bytes==NULL - || raw_private_keys_for_decryption==NULL || raw_private_keys_for_decryption->m_count<=0 + || raw_private_keys_for_decryption==NULL || raw_private_keys_for_decryption->count<=0 || vresult==NULL || keysmem==NULL || public_keys==NULL || private_keys==NULL ) { goto cleanup; } @@ -654,9 +654,9 @@ int dc_pgp_pk_decrypt( dc_context_t* context, *ret_plain_bytes = 0; /* setup keys (the keys may come from pgp_filter_keys_fileread(), see also pgp_keyring_add(rcpts, key)) */ - for( i = 0; i < raw_private_keys_for_decryption->m_count; i++ ) { + for( i = 0; i < raw_private_keys_for_decryption->count; i++ ) { pgp_memory_clear(keysmem); /* a simple concatenate of private binary keys fails (works for public keys, however, we don't do it there either) */ - pgp_memory_add(keysmem, raw_private_keys_for_decryption->m_keys[i]->m_binary, raw_private_keys_for_decryption->m_keys[i]->m_bytes); + pgp_memory_add(keysmem, raw_private_keys_for_decryption->keys[i]->binary, raw_private_keys_for_decryption->keys[i]->bytes); pgp_filter_keys_from_mem(&s_io, dummy_keys/*should stay empty*/, private_keys, NULL, 0, keysmem); } @@ -666,9 +666,9 @@ int dc_pgp_pk_decrypt( dc_context_t* context, } if( raw_public_keys_for_validation ) { - for( i = 0; i < raw_public_keys_for_validation->m_count; i++ ) { + for( i = 0; i < raw_public_keys_for_validation->count; i++ ) { pgp_memory_clear(keysmem); - pgp_memory_add(keysmem, raw_public_keys_for_validation->m_keys[i]->m_binary, raw_public_keys_for_validation->m_keys[i]->m_bytes); + pgp_memory_add(keysmem, raw_public_keys_for_validation->keys[i]->binary, raw_public_keys_for_validation->keys[i]->bytes); pgp_filter_keys_from_mem(&s_io, public_keys, dummy_keys/*should stay empty*/, NULL, 0, keysmem); } } diff --git a/src/dc_qr.c b/src/dc_qr.c index 4a642216..5c7bb4c5 100644 --- a/src/dc_qr.c +++ b/src/dc_qr.c @@ -57,9 +57,9 @@ dc_lot_t* dc_check_qr(dc_context_t* context, const char* qr) char* grpid = NULL; char* grpname = NULL; - qr_parsed->m_state = 0; + qr_parsed->state = 0; - if( context==NULL || context->m_magic!=DC_CONTEXT_MAGIC || qr==NULL ) { + if( context==NULL || context->magic!=DC_CONTEXT_MAGIC || qr==NULL ) { goto cleanup; } @@ -140,8 +140,8 @@ dc_lot_t* dc_check_qr(dc_context_t* context, const char* qr) if( semicolon ) { *semicolon = 0; } } else { - qr_parsed->m_state = DC_QR_ERROR; - qr_parsed->m_text1 = dc_strdup("Bad e-mail address."); + qr_parsed->state = DC_QR_ERROR; + qr_parsed->text1 = dc_strdup("Bad e-mail address."); goto cleanup; } } @@ -179,16 +179,16 @@ dc_lot_t* dc_check_qr(dc_context_t* context, const char* qr) temp = dc_normalize_addr(addr); free(addr); addr = temp; if( strlen(addr) < 3 || strchr(addr, '@')==NULL || strchr(addr, '.')==NULL ) { - qr_parsed->m_state = DC_QR_ERROR; - qr_parsed->m_text1 = dc_strdup("Bad e-mail address."); + qr_parsed->state = DC_QR_ERROR; + qr_parsed->text1 = dc_strdup("Bad e-mail address."); goto cleanup; } } if( fingerprint ) { if( strlen(fingerprint) != 40 ) { - qr_parsed->m_state = DC_QR_ERROR; - qr_parsed->m_text1 = dc_strdup("Bad fingerprint length in QR code."); + qr_parsed->state = DC_QR_ERROR; + qr_parsed->text1 = dc_strdup("Bad fingerprint length in QR code."); goto cleanup; } } @@ -204,16 +204,16 @@ dc_lot_t* dc_check_qr(dc_context_t* context, const char* qr) { // _only_ fingerprint set ... // (we could also do this before/instead of a secure-join, however, this may require complicated questions in the ui) - if( dc_apeerstate_load_by_fingerprint(peerstate, context->m_sql, fingerprint) ) { - qr_parsed->m_state = DC_QR_FPR_OK; - qr_parsed->m_id = dc_add_or_lookup_contact(context, NULL, peerstate->m_addr, DC_ORIGIN_UNHANDLED_QR_SCAN, NULL); + if( dc_apeerstate_load_by_fingerprint(peerstate, context->sql, fingerprint) ) { + qr_parsed->state = DC_QR_FPR_OK; + qr_parsed->id = dc_add_or_lookup_contact(context, NULL, peerstate->addr, DC_ORIGIN_UNHANDLED_QR_SCAN, NULL); - dc_create_or_lookup_nchat_by_contact_id(context, qr_parsed->m_id, DC_CHAT_DEADDROP_BLOCKED, &chat_id, NULL); - device_msg = dc_mprintf("%s verified.", peerstate->m_addr); + dc_create_or_lookup_nchat_by_contact_id(context, qr_parsed->id, DC_CHAT_DEADDROP_BLOCKED, &chat_id, NULL); + device_msg = dc_mprintf("%s verified.", peerstate->addr); } else { - qr_parsed->m_text1 = dc_format_fingerprint(fingerprint); - qr_parsed->m_state = DC_QR_FPR_WITHOUT_ADDR; + qr_parsed->text1 = dc_format_fingerprint(fingerprint); + qr_parsed->state = DC_QR_FPR_WITHOUT_ADDR; } } else @@ -222,34 +222,34 @@ dc_lot_t* dc_check_qr(dc_context_t* context, const char* qr) // do not comapre the fingerprint already - it may have changed - errors are catched later more proberly. // (theroretically, there is also the state "addr=set, fingerprint=set, invitenumber=0", however, currently, we won't get into this state) if( grpid && grpname ) { - qr_parsed->m_state = DC_QR_ASK_VERIFYGROUP; - qr_parsed->m_text1 = dc_strdup(grpname); - qr_parsed->m_text2 = dc_strdup(grpid); + qr_parsed->state = DC_QR_ASK_VERIFYGROUP; + qr_parsed->text1 = dc_strdup(grpname); + qr_parsed->text2 = dc_strdup(grpid); } else { - qr_parsed->m_state = DC_QR_ASK_VERIFYCONTACT; + qr_parsed->state = DC_QR_ASK_VERIFYCONTACT; } - qr_parsed->m_id = dc_add_or_lookup_contact(context, name, addr, DC_ORIGIN_UNHANDLED_QR_SCAN, NULL); - qr_parsed->m_fingerprint = dc_strdup(fingerprint); - qr_parsed->m_invitenumber = dc_strdup(invitenumber); - qr_parsed->m_auth = dc_strdup(auth); + qr_parsed->id = dc_add_or_lookup_contact(context, name, addr, DC_ORIGIN_UNHANDLED_QR_SCAN, NULL); + qr_parsed->fingerprint = dc_strdup(fingerprint); + qr_parsed->invitenumber = dc_strdup(invitenumber); + qr_parsed->auth = dc_strdup(auth); } } else if( addr ) { - qr_parsed->m_state = DC_QR_ADDR; - qr_parsed->m_id = dc_add_or_lookup_contact(context, name, addr, DC_ORIGIN_UNHANDLED_QR_SCAN, NULL); + qr_parsed->state = DC_QR_ADDR; + qr_parsed->id = dc_add_or_lookup_contact(context, name, addr, DC_ORIGIN_UNHANDLED_QR_SCAN, NULL); } else if( strstr(qr, "http://")==qr || strstr(qr, "https://")==qr ) { - qr_parsed->m_state = DC_QR_URL; - qr_parsed->m_text1 = dc_strdup(qr); + qr_parsed->state = DC_QR_URL; + qr_parsed->text1 = dc_strdup(qr); } else { - qr_parsed->m_state = DC_QR_TEXT; - qr_parsed->m_text1 = dc_strdup(qr); + qr_parsed->state = DC_QR_TEXT; + qr_parsed->text1 = dc_strdup(qr); } if( device_msg ) { diff --git a/src/dc_receive_imf.c b/src/dc_receive_imf.c index ce053a90..f29cbd30 100644 --- a/src/dc_receive_imf.c +++ b/src/dc_receive_imf.c @@ -42,13 +42,13 @@ static void add_or_lookup_contact_by_addr__(dc_context_t* context, const char* d int dummy; if( check_self == NULL ) { check_self = &dummy; } - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || addr_spec == NULL ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || addr_spec == NULL ) { return; } *check_self = 0; - char* self_addr = dc_sqlite3_get_config(context->m_sql, "configured_addr", ""); + char* self_addr = dc_sqlite3_get_config(context->sql, "configured_addr", ""); if( strcasecmp(self_addr, addr_spec)==0 ) { *check_self = 1; } @@ -81,7 +81,7 @@ static void dc_add_or_lookup_contacts_by_mailbox_list__(dc_context_t* context, c { clistiter* cur; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || mb_list == NULL ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || mb_list == NULL ) { return; } @@ -98,7 +98,7 @@ static void dc_add_or_lookup_contacts_by_address_list__(dc_context_t* context, c { clistiter* cur; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || adr_list == NULL /*may be NULL eg. if bcc is given as `Bcc: \n` in the header */ ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || adr_list == NULL /*may be NULL eg. if bcc is given as `Bcc: \n` in the header */ ) { return; } @@ -131,7 +131,7 @@ static int is_known_rfc724_mid(dc_context_t* context, const char* rfc724_mid) { int is_known = 0; if( rfc724_mid ) { - sqlite3_stmt* stmt = dc_sqlite3_prepare(context->m_sql, + sqlite3_stmt* stmt = dc_sqlite3_prepare(context->sql, "SELECT m.id FROM msgs m " " LEFT JOIN chats c ON m.chat_id=c.id " " WHERE m.rfc724_mid=? " @@ -211,7 +211,7 @@ static int is_msgrmsg_rfc724_mid__(dc_context_t* context, const char* rfc724_mid { int is_msgrmsg = 0; if( rfc724_mid ) { - sqlite3_stmt* stmt = dc_sqlite3_prepare(context->m_sql, + sqlite3_stmt* stmt = dc_sqlite3_prepare(context->sql, "SELECT id FROM msgs " " WHERE rfc724_mid=? " " AND msgrmsg!=0 " @@ -299,7 +299,7 @@ static void calc_timestamps(dc_context_t* context, uint32_t chat_id, uint32_t fr (we do this check only for fresh messages, other messages may pop up whereever, this may happen eg. when restoring old messages or synchronizing different clients) */ if( is_fresh_msg ) { - sqlite3_stmt* stmt = dc_sqlite3_prepare(context->m_sql, + sqlite3_stmt* stmt = dc_sqlite3_prepare(context->sql, "SELECT MAX(timestamp) FROM msgs WHERE chat_id=? and from_id!=? AND timestamp>=?"); sqlite3_bind_int (stmt, 1, chat_id); sqlite3_bind_int (stmt, 2, from_id); @@ -333,7 +333,7 @@ static dc_array_t* search_chat_ids_by_contact_ids(dc_context_t* context, const d char* contact_ids_str = NULL, *q3 = NULL; dc_array_t* chat_ids = dc_array_new(context, 23); - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC ) { goto cleanup; } @@ -368,7 +368,7 @@ static dc_array_t* search_chat_ids_by_contact_ids(dc_context_t* context, const d " AND cc.contact_id!=" DC_STRINGIFY(DC_CONTACT_ID_SELF) /* ignore SELF, we've also removed it above - if the user has left the group, it is still the same group */ " ORDER BY cc.chat_id, cc.contact_id;", contact_ids_str); - stmt = dc_sqlite3_prepare(context->m_sql, q3); + stmt = dc_sqlite3_prepare(context->sql, q3); { uint32_t last_chat_id = 0, matches = 0, mismatches = 0; @@ -429,8 +429,8 @@ static char* create_adhoc_grp_id__(dc_context_t* context, dc_array_t* member_ids /* collect all addresses and sort them */ q3 = sqlite3_mprintf("SELECT addr FROM contacts WHERE id IN(%s) AND id!=" DC_STRINGIFY(DC_CONTACT_ID_SELF), member_ids_str); - stmt = dc_sqlite3_prepare(context->m_sql, q3); - addr = dc_sqlite3_get_config(context->m_sql, "configured_addr", "no-self"); + stmt = dc_sqlite3_prepare(context->sql, q3); + addr = dc_sqlite3_get_config(context->sql, "configured_addr", "no-self"); dc_strlower_in_place(addr); dc_array_add_ptr(member_addrs, addr); while( sqlite3_step(stmt)==SQLITE_ROW ) { @@ -452,7 +452,7 @@ static char* create_adhoc_grp_id__(dc_context_t* context, dc_array_t* member_ids pgp_hash_t hasher; pgp_hash_sha256(&hasher); hasher.init(&hasher); - hasher.add(&hasher, (const uint8_t*)member_cs.m_buf, strlen(member_cs.m_buf)); + hasher.add(&hasher, (const uint8_t*)member_cs.buf, strlen(member_cs.buf)); binary_hash = malloc(hasher.size); hasher.finish(&hasher, binary_hash); } @@ -470,7 +470,7 @@ static char* create_adhoc_grp_id__(dc_context_t* context, dc_array_t* member_ids free(binary_hash); sqlite3_finalize(stmt); sqlite3_free(q3); - free(member_cs.m_buf); + free(member_cs.buf); return ret; } @@ -480,7 +480,7 @@ static uint32_t create_group_record(dc_context_t* context, const char* grpid, co uint32_t chat_id = 0; sqlite3_stmt* stmt = NULL; - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "INSERT INTO chats (type, name, grpid, blocked) VALUES(?, ?, ?, ?);"); sqlite3_bind_int (stmt, 1, create_verified? DC_CHAT_TYPE_VERIFIED_GROUP : DC_CHAT_TYPE_GROUP); sqlite3_bind_text(stmt, 2, grpname, -1, SQLITE_STATIC); @@ -489,7 +489,7 @@ static uint32_t create_group_record(dc_context_t* context, const char* grpid, co if( sqlite3_step(stmt)!=SQLITE_DONE ) { goto cleanup; } - chat_id = dc_sqlite3_get_rowid(context->m_sql, "chats", "grpid", grpid); + chat_id = dc_sqlite3_get_rowid(context->sql, "chats", "grpid", grpid); cleanup: sqlite3_finalize(stmt); @@ -539,7 +539,7 @@ static void create_or_lookup_adhoc_group__(dc_context_t* context, dc_mimeparser_ " ORDER BY m.timestamp DESC, m.id DESC " " LIMIT 1;", chat_ids_str); - stmt = dc_sqlite3_prepare(context->m_sql, q3); + stmt = dc_sqlite3_prepare(context->sql, q3); if( sqlite3_step(stmt)==SQLITE_ROW ) { chat_id = sqlite3_column_int(stmt, 0); chat_id_blocked = sqlite3_column_int(stmt, 1); @@ -557,8 +557,8 @@ static void create_or_lookup_adhoc_group__(dc_context_t* context, dc_mimeparser_ } /* use subject as initial chat name */ - if( mime_parser->m_subject && mime_parser->m_subject[0] ) { - grpname = dc_strdup(mime_parser->m_subject); + if( mime_parser->subject && mime_parser->subject[0] ) { + grpname = dc_strdup(mime_parser->subject); } else { grpname = dc_stock_str_repl_pl(context, DC_STR_MEMBER, dc_array_get_cnt(member_ids)); @@ -571,7 +571,7 @@ static void create_or_lookup_adhoc_group__(dc_context_t* context, dc_mimeparser_ dc_add_to_chat_contacts_table(context, chat_id, dc_array_get_id(member_ids, i)); } - context->m_cb(context, DC_EVENT_CHAT_MODIFIED, chat_id, 0); + context->cb(context, DC_EVENT_CHAT_MODIFIED, chat_id, 0); cleanup: dc_array_unref(member_ids); @@ -597,21 +597,21 @@ static int check_verified_properties__(dc_context_t* context, dc_mimeparser_t* m sqlite3_stmt* stmt = NULL; // ensure, the contact is verified - if( !dc_contact_load_from_db(contact, context->m_sql, from_id) - || !dc_apeerstate_load_by_addr(peerstate, context->m_sql, contact->m_addr) + if( !dc_contact_load_from_db(contact, context->sql, from_id) + || !dc_apeerstate_load_by_addr(peerstate, context->sql, contact->addr) || dc_contact_n_peerstate_are_verified(contact, peerstate) < DC_BIDIRECT_VERIFIED ) { dc_log_warning(context, 0, "Cannot verifiy group; sender is not verified."); goto cleanup; } // ensure, the message is encrypted - if( !mimeparser->m_e2ee_helper->m_encrypted ) { + if( !mimeparser->e2ee_helper->encrypted ) { dc_log_warning(context, 0, "Cannot verifiy group; message is not encrypted properly."); goto cleanup; } // ensure, the message is signed with a verified key of the sender - if( !dc_apeerstate_has_verified_key(peerstate, mimeparser->m_e2ee_helper->m_signatures) ) { + if( !dc_apeerstate_has_verified_key(peerstate, mimeparser->e2ee_helper->signatures) ) { dc_log_warning(context, 0, "Cannot verifiy group; message is not signed properly."); goto cleanup; } @@ -624,14 +624,14 @@ static int check_verified_properties__(dc_context_t* context, dc_mimeparser_t* m " LEFT JOIN acpeerstates ps ON c.addr=ps.addr " " WHERE c.id IN(%s) ", to_ids_str); - stmt = dc_sqlite3_prepare(context->m_sql, q3); + stmt = dc_sqlite3_prepare(context->sql, q3); while( sqlite3_step(stmt)==SQLITE_ROW ) { const char* to_addr = (const char*)sqlite3_column_text(stmt, 0); int is_verified = sqlite3_column_int (stmt, 1); - if( dc_hash_find_str(mimeparser->m_e2ee_helper->m_gossipped_addr, to_addr) - && dc_apeerstate_load_by_addr(peerstate, context->m_sql, to_addr) ) + if( dc_hash_find_str(mimeparser->e2ee_helper->gossipped_addr, to_addr) + && dc_apeerstate_load_by_addr(peerstate, context->sql, to_addr) ) { // if we're here, we know the gossip key is verified: // - use the gossip-key as verified-key if there is no verified-key @@ -639,12 +639,12 @@ static int check_verified_properties__(dc_context_t* context, dc_mimeparser_t* m // (otherwise a verified key can _only_ be updated through QR scan which might be annoying, // see https://github.com/nextleap-project/countermitm/issues/46 for a discussion about this point) if( !is_verified - || (strcmp(peerstate->m_verified_key_fingerprint, peerstate->m_public_key_fingerprint)!=0 - && strcmp(peerstate->m_verified_key_fingerprint, peerstate->m_gossip_key_fingerprint)!=0) ) + || (strcmp(peerstate->verified_key_fingerprint, peerstate->public_key_fingerprint)!=0 + && strcmp(peerstate->verified_key_fingerprint, peerstate->gossip_key_fingerprint)!=0) ) { - dc_log_info(context, 0, "Marking gossipped key %s as verified due to verified %s.", to_addr, contact->m_addr); - dc_apeerstate_set_verified(peerstate, DC_PS_GOSSIP_KEY, peerstate->m_gossip_key_fingerprint, DC_BIDIRECT_VERIFIED); - dc_apeerstate_save_to_db(peerstate, context->m_sql, 0); + dc_log_info(context, 0, "Marking gossipped key %s as verified due to verified %s.", to_addr, contact->addr); + dc_apeerstate_set_verified(peerstate, DC_PS_GOSSIP_KEY, peerstate->gossip_key_fingerprint, DC_BIDIRECT_VERIFIED); + dc_apeerstate_save_to_db(peerstate, context->sql, 0); is_verified = 1; } } @@ -753,19 +753,19 @@ static void create_or_lookup_group__(dc_context_t* context, dc_mimeparser_t* mim if( (optional_field=dc_mimeparser_lookup_optional_field2(mime_parser, "Chat-Group-Member-Removed", "X-MrRemoveFromGrp"))!=NULL ) { X_MrRemoveFromGrp = optional_field->fld_value; - mime_parser->m_is_system_message = DC_CMD_MEMBER_REMOVED_FROM_GROUP; + mime_parser->is_system_message = DC_CMD_MEMBER_REMOVED_FROM_GROUP; } else if( (optional_field=dc_mimeparser_lookup_optional_field2(mime_parser, "Chat-Group-Member-Added", "X-MrAddToGrp"))!=NULL ) { X_MrAddToGrp = optional_field->fld_value; - mime_parser->m_is_system_message = DC_CMD_MEMBER_ADDED_TO_GROUP; + mime_parser->is_system_message = DC_CMD_MEMBER_ADDED_TO_GROUP; } else if( (optional_field=dc_mimeparser_lookup_optional_field2(mime_parser, "Chat-Group-Name-Changed", "X-MrGrpNameChanged"))!=NULL ) { X_MrGrpNameChanged = 1; - mime_parser->m_is_system_message = DC_CMD_GROUPNAME_CHANGED; + mime_parser->is_system_message = DC_CMD_GROUPNAME_CHANGED; } else if( (optional_field=dc_mimeparser_lookup_optional_field(mime_parser, "Chat-Group-Image"))!=NULL ) { X_MrGrpImageChanged = 1; - mime_parser->m_is_system_message = DC_CMD_GROUPIMAGE_CHANGED; + mime_parser->is_system_message = DC_CMD_GROUPIMAGE_CHANGED; } } @@ -794,7 +794,7 @@ static void create_or_lookup_group__(dc_context_t* context, dc_mimeparser_t* mim /* check if the group does not exist but should be created */ int group_explicitly_left = dc_is_group_explicitly_left(context, grpid); - self_addr = dc_sqlite3_get_config(context->m_sql, "configured_addr", ""); + self_addr = dc_sqlite3_get_config(context->sql, "configured_addr", ""); if( chat_id == 0 && !dc_mimeparser_is_mailinglist_message(mime_parser) && grpid @@ -835,25 +835,25 @@ static void create_or_lookup_group__(dc_context_t* context, dc_mimeparser_t* mim } else if( X_MrGrpNameChanged && grpname && strlen(grpname) < 200 ) { - stmt = dc_sqlite3_prepare(context->m_sql, "UPDATE chats SET name=? WHERE id=?;"); + stmt = dc_sqlite3_prepare(context->sql, "UPDATE chats SET name=? WHERE id=?;"); sqlite3_bind_text(stmt, 1, grpname, -1, SQLITE_STATIC); sqlite3_bind_int (stmt, 2, chat_id); sqlite3_step(stmt); sqlite3_finalize(stmt); - context->m_cb(context, DC_EVENT_CHAT_MODIFIED, chat_id, 0); + context->cb(context, DC_EVENT_CHAT_MODIFIED, chat_id, 0); } if( X_MrGrpImageChanged ) { int ok = 0; char* grpimage = NULL; - if( carray_count(mime_parser->m_parts)>=1 ) { - dc_mimepart_t* textpart = (dc_mimepart_t*)carray_get(mime_parser->m_parts, 0); - if( textpart->m_type == DC_MSG_TEXT ) { - if( carray_count(mime_parser->m_parts)>=2 ) { - dc_mimepart_t* imgpart = (dc_mimepart_t*)carray_get(mime_parser->m_parts, 1); - if( imgpart->m_type == DC_MSG_IMAGE ) { - grpimage = dc_param_get(imgpart->m_param, DC_PARAM_FILE, NULL); + if( carray_count(mime_parser->parts)>=1 ) { + dc_mimepart_t* textpart = (dc_mimepart_t*)carray_get(mime_parser->parts, 0); + if( textpart->type == DC_MSG_TEXT ) { + if( carray_count(mime_parser->parts)>=2 ) { + dc_mimepart_t* imgpart = (dc_mimepart_t*)carray_get(mime_parser->parts, 1); + if( imgpart->type == DC_MSG_IMAGE ) { + grpimage = dc_param_get(imgpart->param, DC_PARAM_FILE, NULL); ok = 1; } } @@ -867,7 +867,7 @@ static void create_or_lookup_group__(dc_context_t* context, dc_mimeparser_t* mim dc_chat_t* chat = dc_chat_new(context); dc_log_info(context, 0, "New group image set to %s.", grpimage? "DELETED" : grpimage); dc_chat_load_from_db(chat, chat_id); - dc_param_set(chat->m_param, DC_PARAM_PROFILE_IMAGE, grpimage/*may be NULL*/); + dc_param_set(chat->param, DC_PARAM_PROFILE_IMAGE, grpimage/*may be NULL*/); dc_chat_update_param(chat); dc_chat_unref(chat); free(grpimage); @@ -881,7 +881,7 @@ static void create_or_lookup_group__(dc_context_t* context, dc_mimeparser_t* mim { const char* skip = X_MrRemoveFromGrp? X_MrRemoveFromGrp : NULL; - stmt = dc_sqlite3_prepare(context->m_sql, "DELETE FROM chats_contacts WHERE chat_id=?;"); + stmt = dc_sqlite3_prepare(context->sql, "DELETE FROM chats_contacts WHERE chat_id=?;"); sqlite3_bind_int (stmt, 1, chat_id); sqlite3_step(stmt); sqlite3_finalize(stmt); @@ -909,12 +909,12 @@ static void create_or_lookup_group__(dc_context_t* context, dc_mimeparser_t* mim } if( send_EVENT_CHAT_MODIFIED ) { - context->m_cb(context, DC_EVENT_CHAT_MODIFIED, chat_id, 0); + context->cb(context, DC_EVENT_CHAT_MODIFIED, chat_id, 0); } /* check the number of receivers - the only critical situation is if the user hits "Reply" instead of "Reply all" in a non-messenger-client */ - if( to_ids_cnt == 1 && mime_parser->m_is_send_by_messenger==0 ) { + if( to_ids_cnt == 1 && mime_parser->is_send_by_messenger==0 ) { int is_contact_cnt = dc_get_chat_contact_count(context, chat_id); if( is_contact_cnt > 3 /* to_ids_cnt==1 may be "From: A, To: B, SELF" as SELF is not counted in to_ids_cnt. So everything up to 3 is no error. */ ) { chat_id = 0; @@ -963,7 +963,7 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s time_t sort_timestamp = DC_INVALID_TIMESTAMP; time_t sent_timestamp = DC_INVALID_TIMESTAMP; time_t rcvd_timestamp = DC_INVALID_TIMESTAMP; - dc_mimeparser_t* mime_parser = dc_mimeparser_new(context->m_blobdir, context); + dc_mimeparser_t* mime_parser = dc_mimeparser_new(context->blobdir, context); int transaction_pending = 0; const struct mailimf_field* field; @@ -995,7 +995,7 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s we use mailmime_parse() through dc_mimeparser (both call mailimf_struct_multiple_parse() somewhen, I did not found out anything that speaks against this approach yet) */ dc_mimeparser_parse(mime_parser, imf_raw_not_terminated, imf_raw_bytes); - if( dc_hash_count(&mime_parser->m_header)==0 ) { + if( dc_hash_count(&mime_parser->header)==0 ) { dc_log_info(context, 0, "No header."); goto cleanup; /* Error - even adding an empty record won't help as we do not know the message ID */ } @@ -1017,7 +1017,7 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s } } - dc_sqlite3_begin_transaction(context->m_sql); + dc_sqlite3_begin_transaction(context->sql); transaction_pending = 1; /* get From: and check if it is known (for known From:'s we add the other To:/Cc: in the 3rd pass) @@ -1108,7 +1108,7 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s uint32_t old_server_uid = 0; if( dc_rfc724_mid_exists__(context, rfc724_mid, &old_server_folder, &old_server_uid) ) { if( strcmp(old_server_folder, server_folder)!=0 || old_server_uid!=server_uid ) { - dc_sqlite3_rollback(context->m_sql); + dc_sqlite3_rollback(context->sql); transaction_pending = 0; dc_update_server_uid(context, rfc724_mid, server_folder, server_uid); } @@ -1130,12 +1130,12 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s // handshake messages must be processed before chats are crated (eg. contacs may be marked as verified) assert( chat_id == 0 ); if( dc_mimeparser_lookup_field(mime_parser, "Secure-Join") ) { - dc_sqlite3_commit(context->m_sql); + dc_sqlite3_commit(context->sql); if( dc_handle_securejoin_handshake(context, mime_parser, from_id) == DC_IS_HANDSHAKE_STOP_NORMAL_PROCESSING ) { hidden = 1; state = DC_STATE_IN_SEEN; } - dc_sqlite3_begin_transaction(context->m_sql); + dc_sqlite3_begin_transaction(context->sql); } /* test if there is a normal chat with the sender - if so, this allows us to create groups in the next step */ @@ -1201,7 +1201,7 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s (the latter may be removed if we run into spam problems, currently this is fine) (noticed messages do count as being unread; therefore, the deaddrop will not popup in the chatlist) */ if( chat_id_blocked && state == DC_STATE_IN_FRESH ) { - if( incoming_originm_is_send_by_messenger==0 ) { + if( incoming_originis_send_by_messenger==0 ) { state = DC_STATE_IN_NOTICED; } } @@ -1224,7 +1224,7 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s if( chat_id == 0 ) { - int create_blocked = (mime_parser->m_is_send_by_messenger && !dc_is_contact_blocked(context, to_id))? DC_CHAT_NOT_BLOCKED : DC_CHAT_DEADDROP_BLOCKED; + int create_blocked = (mime_parser->is_send_by_messenger && !dc_is_contact_blocked(context, to_id))? DC_CHAT_NOT_BLOCKED : DC_CHAT_DEADDROP_BLOCKED; dc_create_or_lookup_nchat_by_contact_id(context, to_id, create_blocked, &chat_id, &chat_id_blocked); if( chat_id && chat_id_blocked && !create_blocked ) { dc_unblock_chat(context, chat_id); @@ -1259,7 +1259,7 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s /* if the message is not sent by a messenger, check if it is sent at least as a reply to a messenger message (later, we move these replies to the folder used for DeltaChat messages) */ - int msgrmsg = mime_parser->m_is_send_by_messenger; /* 1 or 0 for yes/no */ + int msgrmsg = mime_parser->is_send_by_messenger; /* 1 or 0 for yes/no */ if( msgrmsg ) { dc_log_info(context, 0, "Message sent by another messenger."); @@ -1276,23 +1276,23 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s /* fine, so far. now, split the message into simple parts usable as "short messages" and add them to the database (mails sent by other messenger clients should result into only one message; mails sent by other clients may result in several messages (eg. one per attachment)) */ - icnt = carray_count(mime_parser->m_parts); /* should be at least one - maybe empty - part */ - stmt = dc_sqlite3_prepare(context->m_sql, + icnt = carray_count(mime_parser->parts); /* should be at least one - maybe empty - part */ + stmt = dc_sqlite3_prepare(context->sql, "INSERT INTO msgs (rfc724_mid,server_folder,server_uid,chat_id,from_id, to_id,timestamp,timestamp_sent,timestamp_rcvd,type, state,msgrmsg,txt,txt_raw,param, bytes,hidden)" " VALUES (?,?,?,?,?, ?,?,?,?,?, ?,?,?,?,?, ?,?);"); for( i = 0; i < icnt; i++ ) { - dc_mimepart_t* part = (dc_mimepart_t*)carray_get(mime_parser->m_parts, i); - if( part->m_is_meta ) { + dc_mimepart_t* part = (dc_mimepart_t*)carray_get(mime_parser->parts, i); + if( part->is_meta ) { continue; } - if( part->m_type == DC_MSG_TEXT ) { - txt_raw = dc_mprintf("%s\n\n%s", mime_parser->m_subject? mime_parser->m_subject : "", part->m_msg_raw); + if( part->type == DC_MSG_TEXT ) { + txt_raw = dc_mprintf("%s\n\n%s", mime_parser->subject? mime_parser->subject : "", part->msg_raw); } - if( mime_parser->m_is_system_message ) { - dc_param_set_int(part->m_param, DC_PARAM_CMD, mime_parser->m_is_system_message); + if( mime_parser->is_system_message ) { + dc_param_set_int(part->param, DC_PARAM_CMD, mime_parser->is_system_message); } sqlite3_reset(stmt); @@ -1305,13 +1305,13 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s sqlite3_bind_int64(stmt, 7, sort_timestamp); sqlite3_bind_int64(stmt, 8, sent_timestamp); sqlite3_bind_int64(stmt, 9, rcvd_timestamp); - sqlite3_bind_int (stmt, 10, part->m_type); + sqlite3_bind_int (stmt, 10, part->type); sqlite3_bind_int (stmt, 11, state); sqlite3_bind_int (stmt, 12, msgrmsg); - sqlite3_bind_text (stmt, 13, part->m_msg? part->m_msg : "", -1, SQLITE_STATIC); + sqlite3_bind_text (stmt, 13, part->msg? part->msg : "", -1, SQLITE_STATIC); sqlite3_bind_text (stmt, 14, txt_raw? txt_raw : "", -1, SQLITE_STATIC); - sqlite3_bind_text (stmt, 15, part->m_param->m_packed, -1, SQLITE_STATIC); - sqlite3_bind_int (stmt, 16, part->m_bytes); + sqlite3_bind_text (stmt, 15, part->param->packed, -1, SQLITE_STATIC); + sqlite3_bind_int (stmt, 16, part->bytes); sqlite3_bind_int (stmt, 17, hidden); if( sqlite3_step(stmt) != SQLITE_DONE ) { dc_log_info(context, 0, "Cannot write DB."); @@ -1322,7 +1322,7 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s txt_raw = NULL; if( first_dblocal_id == 0 ) { - first_dblocal_id = dc_sqlite3_get_rowid(context->m_sql, "msgs", "rfc724_mid", rfc724_mid); // rfc724_mid is unique only for the first insert + first_dblocal_id = dc_sqlite3_get_rowid(context->sql, "msgs", "rfc724_mid", rfc724_mid); // rfc724_mid is unique only for the first insert } carray_add(created_db_entries, (void*)(uintptr_t)chat_id, NULL); @@ -1343,7 +1343,7 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s } else if( chat_id_blocked ) { create_event_to_send = DC_EVENT_MSGS_CHANGED; - /*if( dc_sqlite3_get_config_int__(context->m_sql, "show_deaddrop", 0)!=0 ) { + /*if( dc_sqlite3_get_config_int__(context->sql, "show_deaddrop", 0)!=0 ) { create_event_to_send = DC_EVENT_INCOMING_MSG; }*/ } @@ -1361,18 +1361,18 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s } - if( carray_count(mime_parser->m_reports) > 0 ) + if( carray_count(mime_parser->reports) > 0 ) { /****************************************************************** * Handle reports (mainly MDNs) *****************************************************************/ - int mdns_enabled = dc_sqlite3_get_config_int(context->m_sql, "mdns_enabled", DC_MDNS_DEFAULT_ENABLED); - icnt = carray_count(mime_parser->m_reports); + int mdns_enabled = dc_sqlite3_get_config_int(context->sql, "mdns_enabled", DC_MDNS_DEFAULT_ENABLED); + icnt = carray_count(mime_parser->reports); for( i = 0; i < icnt; i++ ) { int mdn_consumed = 0; - struct mailmime* report_root = carray_get(mime_parser->m_reports, i); + struct mailmime* report_root = carray_get(mime_parser->reports, i); struct mailmime_parameter* report_type = mailmime_find_ct_parameter(report_root, "report-type"); if( report_root==NULL || report_type==NULL || report_type->pa_value==NULL ) { continue; @@ -1440,7 +1440,7 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s CAVE: we rely on dc_imap_markseen_msg() not to move messages that are already in the correct folder. otherwise, the moved message get a new server_uid and is "fresh" again and we will be here again to move it away - a classical deadlock, see also (***) in dc_imap.c */ - if( mime_parser->m_is_send_by_messenger || mdn_consumed ) { + if( mime_parser->is_send_by_messenger || mdn_consumed ) { char* jobparam = dc_mprintf("%c=%s\n%c=%lu", DC_PARAM_SERVER_FOLDER, server_folder, DC_PARAM_SERVER_UID, server_uid); dc_job_add(context, DC_JOB_MARKSEEN_MDN_ON_IMAP, 0, jobparam, 0); free(jobparam); @@ -1452,8 +1452,8 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s } /* debug print? */ - if( dc_sqlite3_get_config_int(context->m_sql, "save_eml", 0) ) { - char* emlname = dc_mprintf("%s/%s-%i.eml", context->m_blobdir, server_folder, (int)first_dblocal_id /*may be 0 for MDNs*/); + if( dc_sqlite3_get_config_int(context->sql, "save_eml", 0) ) { + char* emlname = dc_mprintf("%s/%s-%i.eml", context->blobdir, server_folder, (int)first_dblocal_id /*may be 0 for MDNs*/); FILE* emlfileob = fopen(emlname, "w"); if( emlfileob ) { fwrite(imf_raw_not_terminated, 1, imf_raw_bytes, emlfileob); @@ -1463,11 +1463,11 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s } - dc_sqlite3_commit(context->m_sql); + dc_sqlite3_commit(context->sql); transaction_pending = 0; cleanup: - if( transaction_pending ) { dc_sqlite3_rollback(context->m_sql); } + if( transaction_pending ) { dc_sqlite3_rollback(context->sql); } dc_mimeparser_unref(mime_parser); free(rfc724_mid); @@ -1477,7 +1477,7 @@ cleanup: if( create_event_to_send ) { size_t i, icnt = carray_count(created_db_entries); for( i = 0; i < icnt; i += 2 ) { - context->m_cb(context, create_event_to_send, (uintptr_t)carray_get(created_db_entries, i), (uintptr_t)carray_get(created_db_entries, i+1)); + context->cb(context, create_event_to_send, (uintptr_t)carray_get(created_db_entries, i), (uintptr_t)carray_get(created_db_entries, i+1)); } } carray_free(created_db_entries); @@ -1486,7 +1486,7 @@ cleanup: if( rr_event_to_send ) { size_t i, icnt = carray_count(rr_event_to_send); for( i = 0; i < icnt; i += 2 ) { - context->m_cb(context, DC_EVENT_MSG_READ, (uintptr_t)carray_get(rr_event_to_send, i), (uintptr_t)carray_get(rr_event_to_send, i+1)); + context->cb(context, DC_EVENT_MSG_READ, (uintptr_t)carray_get(rr_event_to_send, i), (uintptr_t)carray_get(rr_event_to_send, i+1)); } carray_free(rr_event_to_send); } diff --git a/src/dc_saxparser.c b/src/dc_saxparser.c index a1248a6e..513c6e7b 100644 --- a/src/dc_saxparser.c +++ b/src/dc_saxparser.c @@ -247,7 +247,7 @@ static void call_text_cb(dc_saxparser_t* saxparser, char* text, size_t len, char text[len] = '\0'; text_new = xml_decode(text, type); - saxparser->m_text_cb(saxparser->m_userdata, text_new, len); + saxparser->text_cb(saxparser->userdata, text_new, len); if( text != text_new ) { free(text_new); } text[len] = bak; @@ -294,10 +294,10 @@ const char* dc_attr_find(char** attr, const char* key) void dc_saxparser_init(dc_saxparser_t* saxparser, void* userdata) { - saxparser->m_userdata = userdata; - saxparser->m_starttag_cb = def_starttag_cb; - saxparser->m_endtag_cb = def_endtag_cb; - saxparser->m_text_cb = def_text_cb; + saxparser->userdata = userdata; + saxparser->starttag_cb = def_starttag_cb; + saxparser->endtag_cb = def_endtag_cb; + saxparser->text_cb = def_text_cb; } @@ -307,8 +307,8 @@ void dc_saxparser_set_tag_handler(dc_saxparser_t* saxparser, dc_saxparser_startt return; } - saxparser->m_starttag_cb = starttag_cb? starttag_cb : def_starttag_cb; - saxparser->m_endtag_cb = endtag_cb? endtag_cb : def_endtag_cb; + saxparser->starttag_cb = starttag_cb? starttag_cb : def_starttag_cb; + saxparser->endtag_cb = endtag_cb? endtag_cb : def_endtag_cb; } @@ -318,7 +318,7 @@ void dc_saxparser_set_text_handler (dc_saxparser_t* saxparser, dc_saxparser_text return; } - saxparser->m_text_cb = text_cb? text_cb : def_text_cb; + saxparser->text_cb = text_cb? text_cb : def_text_cb; } @@ -418,7 +418,7 @@ void dc_saxparser_parse(dc_saxparser_t* saxparser, const char* buf_start__) bak = *p; *p = '\0'; /* null-terminate tag name temporary, eg. a covered `>` may get important downwards */ dc_strlower_in_place(beg_tag_name); - saxparser->m_endtag_cb(saxparser->m_userdata, beg_tag_name); + saxparser->endtag_cb(saxparser->userdata, beg_tag_name); *p = bak; } } @@ -520,7 +520,7 @@ void dc_saxparser_parse(dc_saxparser_t* saxparser, const char* buf_start__) char bak = *after_tag_name; /* backup the character as it may be `/` or `>` which gets important downwards */ *after_tag_name = 0; dc_strlower_in_place(beg_tag_name); - saxparser->m_starttag_cb(saxparser->m_userdata, beg_tag_name, attr); + saxparser->starttag_cb(saxparser->userdata, beg_tag_name, attr); *after_tag_name = bak; /* self-closing tag */ @@ -529,7 +529,7 @@ void dc_saxparser_parse(dc_saxparser_t* saxparser, const char* buf_start__) { p++; *after_tag_name = 0; - saxparser->m_endtag_cb(saxparser->m_userdata, beg_tag_name); /* already lowercase from starttag_cb()-call */ + saxparser->endtag_cb(saxparser->userdata, beg_tag_name); /* already lowercase from starttag_cb()-call */ } } diff --git a/src/dc_saxparser.h b/src/dc_saxparser.h index f445dc5c..e27122ba 100644 --- a/src/dc_saxparser.h +++ b/src/dc_saxparser.h @@ -34,10 +34,10 @@ typedef void (*dc_saxparser_text_cb_t) (void* userdata, const char* text, in typedef struct dc_saxparser_t { - dc_saxparser_starttag_cb_t m_starttag_cb; - dc_saxparser_endtag_cb_t m_endtag_cb; - dc_saxparser_text_cb_t m_text_cb; - void* m_userdata; + dc_saxparser_starttag_cb_t starttag_cb; + dc_saxparser_endtag_cb_t endtag_cb; + dc_saxparser_text_cb_t text_cb; + void* userdata; } dc_saxparser_t; diff --git a/src/dc_securejoin.c b/src/dc_securejoin.c index 9673e264..f693237a 100644 --- a/src/dc_securejoin.c +++ b/src/dc_securejoin.c @@ -31,8 +31,8 @@ #include "dc_token.h" -#define LOCK { pthread_mutex_lock(&context->m_bobs_qr_critical); locked = 1; } -#define UNLOCK if( locked ) { pthread_mutex_unlock(&context->m_bobs_qr_critical); locked = 0; } +#define LOCK { pthread_mutex_lock(&context->bobs_qr_critical); locked = 1; } +#define UNLOCK if( locked ) { pthread_mutex_unlock(&context->bobs_qr_critical); locked = 0; } /******************************************************************************* @@ -56,10 +56,10 @@ void dc_handle_degrade_event(dc_context_t* context, dc_apeerstate_t* peerstate) // with things they cannot fix, so the user is just kicked from the verified group // (and he will know this and can fix this) - if( peerstate->m_degrade_event & DC_DE_FINGERPRINT_CHANGED ) + if( peerstate->degrade_event & DC_DE_FINGERPRINT_CHANGED ) { - stmt = dc_sqlite3_prepare(context->m_sql, "SELECT id FROM contacts WHERE addr=?;"); - sqlite3_bind_text(stmt, 1, peerstate->m_addr, -1, SQLITE_STATIC); + stmt = dc_sqlite3_prepare(context->sql, "SELECT id FROM contacts WHERE addr=?;"); + sqlite3_bind_text(stmt, 1, peerstate->addr, -1, SQLITE_STATIC); sqlite3_step(stmt); contact_id = sqlite3_column_int(stmt, 0); sqlite3_finalize(stmt); @@ -70,10 +70,10 @@ void dc_handle_degrade_event(dc_context_t* context, dc_apeerstate_t* peerstate) dc_create_or_lookup_nchat_by_contact_id(context, contact_id, DC_CHAT_DEADDROP_BLOCKED, &contact_chat_id, NULL); - char* msg = dc_mprintf("Changed setup for %s", peerstate->m_addr); + char* msg = dc_mprintf("Changed setup for %s", peerstate->addr); dc_add_device_msg(context, contact_chat_id, msg); free(msg); - context->m_cb(context, DC_EVENT_CHAT_MODIFIED, contact_chat_id, 0); + context->cb(context, DC_EVENT_CHAT_MODIFIED, contact_chat_id, 0); } cleanup: @@ -88,23 +88,23 @@ cleanup: static int encrypted_and_signed(dc_mimeparser_t* mimeparser, const char* expected_fingerprint) { - if( !mimeparser->m_e2ee_helper->m_encrypted ) { - dc_log_warning(mimeparser->m_context, 0, "Message not encrypted."); + if( !mimeparser->e2ee_helper->encrypted ) { + dc_log_warning(mimeparser->context, 0, "Message not encrypted."); return 0; } - if( dc_hash_count(mimeparser->m_e2ee_helper->m_signatures)<=0 ) { - dc_log_warning(mimeparser->m_context, 0, "Message not signed."); + if( dc_hash_count(mimeparser->e2ee_helper->signatures)<=0 ) { + dc_log_warning(mimeparser->context, 0, "Message not signed."); return 0; } if( expected_fingerprint == NULL ) { - dc_log_warning(mimeparser->m_context, 0, "Fingerprint for comparison missing."); + dc_log_warning(mimeparser->context, 0, "Fingerprint for comparison missing."); return 0; } - if( dc_hash_find_str(mimeparser->m_e2ee_helper->m_signatures, expected_fingerprint) == NULL ) { - dc_log_warning(mimeparser->m_context, 0, "Message does not match expected fingerprint %s.", expected_fingerprint); + if( dc_hash_find_str(mimeparser->e2ee_helper->signatures, expected_fingerprint) == NULL ) { + dc_log_warning(mimeparser->context, 0, "Message does not match expected fingerprint %s.", expected_fingerprint); return 0; } @@ -118,8 +118,8 @@ static char* get_self_fingerprint(dc_context_t* context) dc_key_t* self_key = dc_key_new(); char* fingerprint = NULL; - if( (self_addr = dc_sqlite3_get_config(context->m_sql, "configured_addr", NULL)) == NULL - || !dc_key_load_self_public(self_key, self_addr, context->m_sql) ) { + if( (self_addr = dc_sqlite3_get_config(context->sql, "configured_addr", NULL)) == NULL + || !dc_key_load_self_public(self_key, self_addr, context->sql) ) { goto cleanup; } @@ -163,14 +163,14 @@ static int fingerprint_equals_sender(dc_context_t* context, const char* fingerpr goto cleanup; } - if( !dc_contact_load_from_db(contact, context->m_sql, dc_array_get_id(contacts, 0)) - || !dc_apeerstate_load_by_addr(peerstate, context->m_sql, contact->m_addr) ) { + if( !dc_contact_load_from_db(contact, context->sql, dc_array_get_id(contacts, 0)) + || !dc_apeerstate_load_by_addr(peerstate, context->sql, contact->addr) ) { goto cleanup; } fingerprint_normalized = dc_normalize_fingerprint(fingerprint); - if( strcasecmp(fingerprint_normalized, peerstate->m_public_key_fingerprint) == 0 ) { + if( strcasecmp(fingerprint_normalized, peerstate->public_key_fingerprint) == 0 ) { fingerprint_equal = 1; } @@ -187,7 +187,7 @@ static int mark_peer_as_verified(dc_context_t* context, const char* fingerprint) int success = 0; dc_apeerstate_t* peerstate = dc_apeerstate_new(context); - if( !dc_apeerstate_load_by_fingerprint(peerstate, context->m_sql, fingerprint) ) { + if( !dc_apeerstate_load_by_fingerprint(peerstate, context->sql, fingerprint) ) { goto cleanup; } @@ -198,10 +198,10 @@ static int mark_peer_as_verified(dc_context_t* context, const char* fingerprint) // set MUTUAL as an out-of-band-verification is a strong hint that encryption is wanted. // the state may be corrected by the Autocrypt headers as usual later; // maybe it is a good idea to add the prefer-encrypt-state to the QR code. - peerstate->m_prefer_encrypt = DC_PE_MUTUAL; - peerstate->m_to_save |= DC_SAVE_ALL; + peerstate->prefer_encrypt = DC_PE_MUTUAL; + peerstate->to_save |= DC_SAVE_ALL; - dc_apeerstate_save_to_db(peerstate, context->m_sql, 0); + dc_apeerstate_save_to_db(peerstate, context->sql, 0); success = 1; cleanup: @@ -226,29 +226,29 @@ static void send_handshake_msg(dc_context_t* context, uint32_t contact_chat_id, { dc_msg_t* msg = dc_msg_new(); - msg->m_type = DC_MSG_TEXT; - msg->m_text = dc_mprintf("Secure-Join: %s", step); - msg->m_hidden = 1; - dc_param_set_int(msg->m_param, DC_PARAM_CMD, DC_CMD_SECUREJOIN_MESSAGE); - dc_param_set (msg->m_param, DC_PARAM_CMD_ARG, step); + msg->type = DC_MSG_TEXT; + msg->text = dc_mprintf("Secure-Join: %s", step); + msg->hidden = 1; + dc_param_set_int(msg->param, DC_PARAM_CMD, DC_CMD_SECUREJOIN_MESSAGE); + dc_param_set (msg->param, DC_PARAM_CMD_ARG, step); if( param2 ) { - dc_param_set(msg->m_param, DC_PARAM_CMD_ARG2, param2); // depening on step, this goes either to Secure-Join-Invitenumber or Secure-Join-Auth in mrmimefactory.c + dc_param_set(msg->param, DC_PARAM_CMD_ARG2, param2); // depening on step, this goes either to Secure-Join-Invitenumber or Secure-Join-Auth in mrmimefactory.c } if( fingerprint ) { - dc_param_set(msg->m_param, DC_PARAM_CMD_ARG3, fingerprint); + dc_param_set(msg->param, DC_PARAM_CMD_ARG3, fingerprint); } if( grpid ) { - dc_param_set(msg->m_param, DC_PARAM_CMD_ARG4, grpid); + dc_param_set(msg->param, DC_PARAM_CMD_ARG4, grpid); } if( strcmp(step, "vg-request")==0 || strcmp(step, "vc-request")==0 ) { - dc_param_set_int(msg->m_param, DC_PARAM_FORCE_PLAINTEXT, DC_FP_ADD_AUTOCRYPT_HEADER); // the request message MUST NOT be encrypted - it may be that the key has changed and the message cannot be decrypted otherwise + dc_param_set_int(msg->param, DC_PARAM_FORCE_PLAINTEXT, DC_FP_ADD_AUTOCRYPT_HEADER); // the request message MUST NOT be encrypted - it may be that the key has changed and the message cannot be decrypted otherwise } else { - dc_param_set_int(msg->m_param, DC_PARAM_GUARANTEE_E2EE, 1); /* all but the first message MUST be encrypted */ + dc_param_set_int(msg->param, DC_PARAM_GUARANTEE_E2EE, 1); /* all but the first message MUST be encrypted */ } dc_send_msg_object(context, contact_chat_id, msg); @@ -261,7 +261,7 @@ static void could_not_establish_secure_connection(dc_context_t* context, uint32_ { uint32_t contact_id = chat_id_2_contact_id(context, contact_chat_id); dc_contact_t* contact = dc_get_contact(context, contact_id); - char* msg = dc_mprintf("Could not establish secure connection to %s.", contact? contact->m_addr : "?"); + char* msg = dc_mprintf("Could not establish secure connection to %s.", contact? contact->addr : "?"); dc_add_device_msg(context, contact_chat_id, msg); @@ -276,12 +276,12 @@ static void secure_connection_established(dc_context_t* context, uint32_t contac { uint32_t contact_id = chat_id_2_contact_id(context, contact_chat_id); dc_contact_t* contact = dc_get_contact(context, contact_id); - char* msg = dc_mprintf("Secure connection to %s established.", contact? contact->m_addr : "?"); + char* msg = dc_mprintf("Secure connection to %s established.", contact? contact->addr : "?"); dc_add_device_msg(context, contact_chat_id, msg); // in addition to DC_EVENT_MSGS_CHANGED (sent by dc_add_device_msg()), also send DC_EVENT_CHAT_MODIFIED to update all views - context->m_cb(context, DC_EVENT_CHAT_MODIFIED, contact_chat_id, 0); + context->cb(context, DC_EVENT_CHAT_MODIFIED, contact_chat_id, 0); free(msg); dc_contact_unref(contact); @@ -290,7 +290,7 @@ static void secure_connection_established(dc_context_t* context, uint32_t contac static void end_bobs_joining(dc_context_t* context, int status) { - context->m_bobs_status = status; + context->bobs_status = status; dc_stop_ongoing_process(context); } @@ -335,7 +335,7 @@ char* dc_get_securejoin_qr(dc_context_t* context, uint32_t group_chat_id) char* group_name = NULL; char* group_name_urlencoded= NULL; - if( context == NULL || context->m_magic!=DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic!=DC_CONTEXT_MAGIC ) { goto cleanup; } @@ -354,12 +354,12 @@ char* dc_get_securejoin_qr(dc_context_t* context, uint32_t group_chat_id) dc_token_save__(context, DC_TOKEN_AUTH, group_chat_id, auth); } - if( (self_addr = dc_sqlite3_get_config(context->m_sql, "configured_addr", NULL)) == NULL ) { + if( (self_addr = dc_sqlite3_get_config(context->sql, "configured_addr", NULL)) == NULL ) { dc_log_error(context, 0, "Not configured, cannot generate QR code."); goto cleanup; } - self_name = dc_sqlite3_get_config(context->m_sql, "displayname", ""); + self_name = dc_sqlite3_get_config(context->sql, "displayname", ""); if( (fingerprint=get_self_fingerprint(context)) == NULL ) { goto cleanup; @@ -372,13 +372,13 @@ char* dc_get_securejoin_qr(dc_context_t* context, uint32_t group_chat_id) { // parameters used: a=g=x=i=s= chat = dc_get_chat(context, group_chat_id); - if( chat == NULL || chat->m_type != DC_CHAT_TYPE_VERIFIED_GROUP ) { + if( chat == NULL || chat->type != DC_CHAT_TYPE_VERIFIED_GROUP ) { dc_log_error(context, 0, "Secure join is only available for verified groups."); goto cleanup; } group_name = dc_chat_get_name(chat); group_name_urlencoded = dc_urlencode(group_name); - qr = dc_mprintf(DC_OPENPGP4FPR_SCHEME "%s#a=%s&g=%s&x=%s&i=%s&s=%s", fingerprint, self_addr_urlencoded, group_name_urlencoded, chat->m_grpid, invitenumber, auth); + qr = dc_mprintf(DC_OPENPGP4FPR_SCHEME "%s#a=%s&g=%s&x=%s&i=%s&s=%s", fingerprint, self_addr_urlencoded, group_name_urlencoded, chat->grpid, invitenumber, auth); } else { @@ -404,7 +404,7 @@ cleanup: /** * Join an out-of-band-verification initiated on another device with dc_get_securejoin_qr(). * This function is typically called when dc_check_qr() returns - * lot.m_state=DC_QR_ASK_VERIFYCONTACT or lot.m_state=DC_QR_ASK_VERIFYGROUP. + * lot.state=DC_QR_ASK_VERIFYCONTACT or lot.state=DC_QR_ASK_VERIFYGROUP. * * This function takes some time and sends and receives several messages. * You should call it in a separate thread; if you want to abort it, you should @@ -433,7 +433,7 @@ uint32_t dc_join_securejoin(dc_context_t* context, const char* qr) int ret_chat_id = 0; int ongoing_allocated = 0; - #define CHECK_EXIT if( context->m_shall_stop_ongoing ) { goto cleanup; } + #define CHECK_EXIT if( context->shall_stop_ongoing ) { goto cleanup; } uint32_t contact_chat_id = 0; dc_lot_t* qr_scan = NULL; int join_vg = 0; @@ -448,46 +448,46 @@ uint32_t dc_join_securejoin(dc_context_t* context, const char* qr) } if( ((qr_scan=dc_check_qr(context, qr))==NULL) - || (qr_scan->m_state!=DC_QR_ASK_VERIFYCONTACT && qr_scan->m_state!=DC_QR_ASK_VERIFYGROUP) ) { + || (qr_scan->state!=DC_QR_ASK_VERIFYCONTACT && qr_scan->state!=DC_QR_ASK_VERIFYGROUP) ) { dc_log_error(context, 0, "Unknown QR code."); goto cleanup; } - if( (contact_chat_id=dc_create_chat_by_contact_id(context, qr_scan->m_id)) == 0 ) { + if( (contact_chat_id=dc_create_chat_by_contact_id(context, qr_scan->id)) == 0 ) { dc_log_error(context, 0, "Unknown contact."); goto cleanup; } CHECK_EXIT - if( context->m_cb(context, DC_EVENT_IS_OFFLINE, 0, 0)!=0 ) { + if( context->cb(context, DC_EVENT_IS_OFFLINE, 0, 0)!=0 ) { dc_log_error(context, DC_ERROR_NO_NETWORK, NULL); goto cleanup; } CHECK_EXIT - join_vg = (qr_scan->m_state==DC_QR_ASK_VERIFYGROUP); + join_vg = (qr_scan->state==DC_QR_ASK_VERIFYGROUP); - context->m_bobs_status = 0; + context->bobs_status = 0; LOCK - context->m_bobs_qr_scan = qr_scan; + context->bobs_qr_scan = qr_scan; UNLOCK - if( fingerprint_equals_sender(context, qr_scan->m_fingerprint, contact_chat_id) ) { + if( fingerprint_equals_sender(context, qr_scan->fingerprint, contact_chat_id) ) { // the scanned fingerprint matches Alice's key, we can proceed to step 4b) directly and save two mails dc_log_info(context, 0, "Taking protocol shortcut."); - context->m_bob_expects = DC_VC_CONTACT_CONFIRM; - context->m_cb(context, DC_EVENT_SECUREJOIN_JOINER_PROGRESS, chat_id_2_contact_id(context, contact_chat_id), 4); + context->bob_expects = DC_VC_CONTACT_CONFIRM; + context->cb(context, DC_EVENT_SECUREJOIN_JOINER_PROGRESS, chat_id_2_contact_id(context, contact_chat_id), 4); char* own_fingerprint = get_self_fingerprint(context); send_handshake_msg(context, contact_chat_id, join_vg? "vg-request-with-auth" : "vc-request-with-auth", - qr_scan->m_auth, own_fingerprint, join_vg? qr_scan->m_text2 : NULL); // Bob -> Alice + qr_scan->auth, own_fingerprint, join_vg? qr_scan->text2 : NULL); // Bob -> Alice free(own_fingerprint); } else { - context->m_bob_expects = DC_VC_AUTH_REQUIRED; + context->bob_expects = DC_VC_AUTH_REQUIRED; send_handshake_msg(context, contact_chat_id, join_vg? "vg-request" : "vc-request", - qr_scan->m_invitenumber, NULL, NULL); // Bob -> Alice + qr_scan->invitenumber, NULL, NULL); // Bob -> Alice } while( 1 ) { @@ -497,11 +497,11 @@ uint32_t dc_join_securejoin(dc_context_t* context, const char* qr) } cleanup: - context->m_bob_expects = 0; + context->bob_expects = 0; - if( context->m_bobs_status == DC_BOB_SUCCESS ) { + if( context->bobs_status == DC_BOB_SUCCESS ) { if( join_vg ) { - ret_chat_id = dc_get_chat_id_by_grpid(context, qr_scan->m_text2, NULL, NULL); + ret_chat_id = dc_get_chat_id_by_grpid(context, qr_scan->text2, NULL, NULL); } else { ret_chat_id = contact_chat_id; @@ -509,7 +509,7 @@ cleanup: } LOCK - context->m_bobs_qr_scan = NULL; + context->bobs_qr_scan = NULL; UNLOCK dc_lot_unref(qr_scan); @@ -575,7 +575,7 @@ int dc_handle_securejoin_handshake(dc_context_t* context, dc_mimeparser_t* mimep dc_log_info(context, 0, "Secure-join requested."); - context->m_cb(context, DC_EVENT_SECUREJOIN_INVITER_PROGRESS, contact_id, 3); + context->cb(context, DC_EVENT_SECUREJOIN_INVITER_PROGRESS, contact_id, 3); send_handshake_msg(context, contact_chat_id, join_vg? "vg-auth-required" : "vc-auth-required", NULL, NULL, NULL); // Alice -> Bob @@ -589,21 +589,21 @@ int dc_handle_securejoin_handshake(dc_context_t* context, dc_mimeparser_t* mimep // verify that Alice's Autocrypt key and fingerprint matches the QR-code LOCK - if ( context->m_bobs_qr_scan==NULL - || context->m_bob_expects!=DC_VC_AUTH_REQUIRED - || (join_vg && context->m_bobs_qr_scan->m_state!=DC_QR_ASK_VERIFYGROUP) ) { + if ( context->bobs_qr_scan==NULL + || context->bob_expects!=DC_VC_AUTH_REQUIRED + || (join_vg && context->bobs_qr_scan->state!=DC_QR_ASK_VERIFYGROUP) ) { dc_log_warning(context, 0, "auth-required message out of sync."); goto cleanup; // no error, just aborted somehow or a mail from another handshake } - scanned_fingerprint_of_alice = dc_strdup(context->m_bobs_qr_scan->m_fingerprint); - auth = dc_strdup(context->m_bobs_qr_scan->m_auth); + scanned_fingerprint_of_alice = dc_strdup(context->bobs_qr_scan->fingerprint); + auth = dc_strdup(context->bobs_qr_scan->auth); if( join_vg ) { - grpid = dc_strdup(context->m_bobs_qr_scan->m_text2); + grpid = dc_strdup(context->bobs_qr_scan->text2); } UNLOCK if( !encrypted_and_signed(mimeparser, scanned_fingerprint_of_alice) ) { - could_not_establish_secure_connection(context, contact_chat_id, mimeparser->m_e2ee_helper->m_encrypted? "No valid signature." : "Not encrypted."); + could_not_establish_secure_connection(context, contact_chat_id, mimeparser->e2ee_helper->encrypted? "No valid signature." : "Not encrypted."); end_bobs_joining(context, DC_BOB_ERROR); goto cleanup; } @@ -619,9 +619,9 @@ int dc_handle_securejoin_handshake(dc_context_t* context, dc_mimeparser_t* mimep own_fingerprint = get_self_fingerprint(context); - context->m_cb(context, DC_EVENT_SECUREJOIN_JOINER_PROGRESS, contact_id, 4); + context->cb(context, DC_EVENT_SECUREJOIN_JOINER_PROGRESS, contact_id, 4); - context->m_bob_expects = DC_VC_CONTACT_CONFIRM; + context->bob_expects = DC_VC_CONTACT_CONFIRM; send_handshake_msg(context, contact_chat_id, join_vg? "vg-request-with-auth" : "vc-request-with-auth", auth, own_fingerprint, grpid); // Bob -> Alice } @@ -676,8 +676,8 @@ int dc_handle_securejoin_handshake(dc_context_t* context, dc_mimeparser_t* mimep secure_connection_established(context, contact_chat_id); - context->m_cb(context, DC_EVENT_CONTACTS_CHANGED, contact_id/*selected contact*/, 0); - context->m_cb(context, DC_EVENT_SECUREJOIN_INVITER_PROGRESS, contact_id, 6); + context->cb(context, DC_EVENT_CONTACTS_CHANGED, contact_id/*selected contact*/, 0); + context->cb(context, DC_EVENT_SECUREJOIN_INVITER_PROGRESS, contact_id, 6); if( join_vg ) { // the vg-member-added message is special: this is a normal Chat-Group-Member-Added message with an additional Secure-Join header @@ -708,7 +708,7 @@ int dc_handle_securejoin_handshake(dc_context_t* context, dc_mimeparser_t* mimep ret = DC_IS_HANDSHAKE_CONTINUE_NORMAL_PROCESSING; } - if (context->m_bob_expects!=DC_VC_CONTACT_CONFIRM) { + if (context->bob_expects!=DC_VC_CONTACT_CONFIRM) { if( join_vg ) { dc_log_info(context, 0, "vg-member-added received as broadcast."); } @@ -719,11 +719,11 @@ int dc_handle_securejoin_handshake(dc_context_t* context, dc_mimeparser_t* mimep } LOCK - if (context->m_bobs_qr_scan==NULL || (join_vg && context->m_bobs_qr_scan->m_state!=DC_QR_ASK_VERIFYGROUP)) { + if (context->bobs_qr_scan==NULL || (join_vg && context->bobs_qr_scan->state!=DC_QR_ASK_VERIFYGROUP)) { dc_log_warning(context, 0, "Message out of sync or belongs to a different handshake."); goto cleanup; } - scanned_fingerprint_of_alice = dc_strdup(context->m_bobs_qr_scan->m_fingerprint); + scanned_fingerprint_of_alice = dc_strdup(context->bobs_qr_scan->fingerprint); UNLOCK if( !encrypted_and_signed(mimeparser, scanned_fingerprint_of_alice) ) { @@ -743,9 +743,9 @@ int dc_handle_securejoin_handshake(dc_context_t* context, dc_mimeparser_t* mimep secure_connection_established(context, contact_chat_id); - context->m_cb(context, DC_EVENT_CONTACTS_CHANGED, 0/*no select event*/, 0); + context->cb(context, DC_EVENT_CONTACTS_CHANGED, 0/*no select event*/, 0); - context->m_bob_expects = 0; + context->bob_expects = 0; end_bobs_joining(context, DC_BOB_SUCCESS); } diff --git a/src/dc_simplify.c b/src/dc_simplify.c index ae18c77d..d41cddae 100644 --- a/src/dc_simplify.c +++ b/src/dc_simplify.c @@ -134,19 +134,19 @@ static char* dc_simplify_simplify_plain_text(dc_simplify_t* simplify, const char int footer_mark = 0; for( l = l_first; l <= l_last; l++ ) { - /* hide standard footer, "-- " - we do not set m_is_cut_at_end if we find this mark */ + /* hide standard footer, "-- " - we do not set is_cut_at_end if we find this mark */ line = (char*)carray_get(lines, l); if( strcmp(line, "-- ")==0 || strcmp(line, "-- ")==0 ) { /* quoted-printable may encode `-- ` to `-- =20` which is converted back to `-- ` ... */ footer_mark = 1; } - /* also hide some non-standard footers - they got m_is_cut_at_end set, however */ + /* also hide some non-standard footers - they got is_cut_at_end set, however */ if( strcmp(line, "--")==0 || strcmp(line, "---")==0 || strcmp(line, "----")==0 ) { footer_mark = 1; - simplify->m_is_cut_at_end = 1; + simplify->is_cut_at_end = 1; } if( footer_mark ) { @@ -165,7 +165,7 @@ static char* dc_simplify_simplify_plain_text(dc_simplify_t* simplify, const char && strncmp(line1, "From: ", 6)==0 && line2[0] == 0 ) { - simplify->m_is_forwarded = 1; /* nothing is cutted, the forward state should displayed explicitly in the ui */ + simplify->is_forwarded = 1; /* nothing is cutted, the forward state should displayed explicitly in the ui */ l_first += 3; } } @@ -182,7 +182,7 @@ static char* dc_simplify_simplify_plain_text(dc_simplify_t* simplify, const char || strncmp(line, "~~~~~", 5)==0 ) { l_last = l - 1; /* if l_last is -1, there are no lines */ - simplify->m_is_cut_at_end = 1; + simplify->is_cut_at_end = 1; break; /* done */ } } @@ -204,7 +204,7 @@ static char* dc_simplify_simplify_plain_text(dc_simplify_t* simplify, const char if( l_lastQuotedLine != -1 ) { l_last = l_lastQuotedLine-1; /* if l_last is -1, there are no lines */ - simplify->m_is_cut_at_end = 1; + simplify->is_cut_at_end = 1; if( l_last > 0 ) { if( is_empty_line((char*)carray_get(lines, l_last)) ) { /* allow one empty line between quote and quote headline (eg. mails from Jürgen) */ @@ -244,7 +244,7 @@ static char* dc_simplify_simplify_plain_text(dc_simplify_t* simplify, const char if( l_lastQuotedLine != -1 ) { l_first = l_lastQuotedLine + 1; - simplify->m_is_cut_at_begin = 1; + simplify->is_cut_at_begin = 1; } } @@ -252,7 +252,7 @@ static char* dc_simplify_simplify_plain_text(dc_simplify_t* simplify, const char dc_strbuilder_t ret; dc_strbuilder_init(&ret, strlen(buf_terminated)); - if( simplify->m_is_cut_at_begin ) { + if( simplify->is_cut_at_begin ) { dc_strbuilder_cat(&ret, DC_EDITORIAL_ELLIPSE " "); } @@ -284,14 +284,14 @@ static char* dc_simplify_simplify_plain_text(dc_simplify_t* simplify, const char } } - if( simplify->m_is_cut_at_end - && (!simplify->m_is_cut_at_begin || content_lines_added) /* avoid two `[...]` without content */ ) { + if( simplify->is_cut_at_end + && (!simplify->is_cut_at_begin || content_lines_added) /* avoid two `[...]` without content */ ) { dc_strbuilder_cat(&ret, " " DC_EDITORIAL_ELLIPSE); } dc_free_splitted_lines(lines); - return ret.m_buf; + return ret.buf; } @@ -309,9 +309,9 @@ char* dc_simplify_simplify(dc_simplify_t* simplify, const char* in_unterminated, return dc_strdup(""); } - simplify->m_is_forwarded = 0; - simplify->m_is_cut_at_begin = 0; - simplify->m_is_cut_at_end = 0; + simplify->is_forwarded = 0; + simplify->is_cut_at_begin = 0; + simplify->is_cut_at_end = 0; out = strndup((char*)in_unterminated, in_bytes); /* strndup() makes sure, the string is null-terminated */ if( out == NULL ) { diff --git a/src/dc_simplify.h b/src/dc_simplify.h index 5ac71638..198986af 100644 --- a/src/dc_simplify.h +++ b/src/dc_simplify.h @@ -31,9 +31,9 @@ extern "C" { typedef struct dc_simplify_t { - int m_is_forwarded; - int m_is_cut_at_begin; - int m_is_cut_at_end; + int is_forwarded; + int is_cut_at_begin; + int is_cut_at_end; } dc_simplify_t; diff --git a/src/dc_smtp.c b/src/dc_smtp.c index 2159f1e3..f9c68f98 100644 --- a/src/dc_smtp.c +++ b/src/dc_smtp.c @@ -43,9 +43,9 @@ dc_smtp_t* dc_smtp_new(dc_context_t* context) exit(29); } - smtp->m_log_connect_errors = 1; + smtp->log_connect_errors = 1; - smtp->m_context = context; /* should be used for logging only */ + smtp->context = context; /* should be used for logging only */ return smtp; } @@ -56,7 +56,7 @@ void dc_smtp_unref(dc_smtp_t* smtp) return; } dc_smtp_disconnect(smtp); - free(smtp->m_from); + free(smtp->from); free(smtp); } @@ -68,7 +68,7 @@ void dc_smtp_unref(dc_smtp_t* smtp) int dc_smtp_is_connected(const dc_smtp_t* smtp) { - return (smtp && smtp->m_hEtpan)? 1 : 0; + return (smtp && smtp->hEtpan)? 1 : 0; } @@ -100,132 +100,132 @@ int dc_smtp_connect(dc_smtp_t* smtp, const dc_loginparam_t* lp) return 0; } - if( smtp->m_context->m_cb(smtp->m_context, DC_EVENT_IS_OFFLINE, 0, 0)!=0 ) { - dc_log_error_if(&smtp->m_log_connect_errors, smtp->m_context, DC_ERROR_NO_NETWORK, NULL); + if( smtp->context->cb(smtp->context, DC_EVENT_IS_OFFLINE, 0, 0)!=0 ) { + dc_log_error_if(&smtp->log_connect_errors, smtp->context, DC_ERROR_NO_NETWORK, NULL); goto cleanup; } - if( smtp->m_hEtpan ) { - dc_log_warning(smtp->m_context, 0, "SMTP already connected."); + if( smtp->hEtpan ) { + dc_log_warning(smtp->context, 0, "SMTP already connected."); success = 1; /* otherwise, the handle would get deleted */ goto cleanup; } - if( lp->m_addr == NULL || lp->m_send_server == NULL || lp->m_send_port == 0 ) { - dc_log_error_if(&smtp->m_log_connect_errors, smtp->m_context, 0, "SMTP bad parameters."); + if( lp->addr == NULL || lp->send_server == NULL || lp->send_port == 0 ) { + dc_log_error_if(&smtp->log_connect_errors, smtp->context, 0, "SMTP bad parameters."); goto cleanup; } - free(smtp->m_from); - smtp->m_from = dc_strdup(lp->m_addr); + free(smtp->from); + smtp->from = dc_strdup(lp->addr); - smtp->m_hEtpan = mailsmtp_new(0, NULL); - if( smtp->m_hEtpan == NULL ) { - dc_log_error(smtp->m_context, 0, "SMTP-object creation failed."); + smtp->hEtpan = mailsmtp_new(0, NULL); + if( smtp->hEtpan == NULL ) { + dc_log_error(smtp->context, 0, "SMTP-object creation failed."); goto cleanup; } - mailsmtp_set_timeout(smtp->m_hEtpan, DC_SMTP_TIMEOUT_SEC); - mailsmtp_set_progress_callback(smtp->m_hEtpan, body_progress, smtp); + mailsmtp_set_timeout(smtp->hEtpan, DC_SMTP_TIMEOUT_SEC); + mailsmtp_set_progress_callback(smtp->hEtpan, body_progress, smtp); #if DEBUG_SMTP - mailsmtp_set_logger(smtp->m_hEtpan, logger, smtp); + mailsmtp_set_logger(smtp->hEtpan, logger, smtp); #endif /* connect to SMTP server */ - if( lp->m_server_flags&(DC_LP_SMTP_SOCKET_STARTTLS|DC_LP_SMTP_SOCKET_PLAIN) ) + if( lp->server_flags&(DC_LP_SMTP_SOCKET_STARTTLS|DC_LP_SMTP_SOCKET_PLAIN) ) { - if( (r=mailsmtp_socket_connect(smtp->m_hEtpan, lp->m_send_server, lp->m_send_port)) != MAILSMTP_NO_ERROR ) { - dc_log_error_if(&smtp->m_log_connect_errors, smtp->m_context, 0, "SMTP-Socket connection to %s:%i failed (%s)", lp->m_send_server, (int)lp->m_send_port, mailsmtp_strerror(r)); + if( (r=mailsmtp_socket_connect(smtp->hEtpan, lp->send_server, lp->send_port)) != MAILSMTP_NO_ERROR ) { + dc_log_error_if(&smtp->log_connect_errors, smtp->context, 0, "SMTP-Socket connection to %s:%i failed (%s)", lp->send_server, (int)lp->send_port, mailsmtp_strerror(r)); goto cleanup; } } else { - if( (r=mailsmtp_ssl_connect(smtp->m_hEtpan, lp->m_send_server, lp->m_send_port)) != MAILSMTP_NO_ERROR ) { - dc_log_error_if(&smtp->m_log_connect_errors, smtp->m_context, 0, "SMPT-SSL connection to %s:%i failed (%s)", lp->m_send_server, (int)lp->m_send_port, mailsmtp_strerror(r)); + if( (r=mailsmtp_ssl_connect(smtp->hEtpan, lp->send_server, lp->send_port)) != MAILSMTP_NO_ERROR ) { + dc_log_error_if(&smtp->log_connect_errors, smtp->context, 0, "SMPT-SSL connection to %s:%i failed (%s)", lp->send_server, (int)lp->send_port, mailsmtp_strerror(r)); goto cleanup; } } try_esmtp = 1; - smtp->m_esmtp = 0; - if( try_esmtp && (r=mailesmtp_ehlo(smtp->m_hEtpan))==MAILSMTP_NO_ERROR ) { - smtp->m_esmtp = 1; + smtp->esmtp = 0; + if( try_esmtp && (r=mailesmtp_ehlo(smtp->hEtpan))==MAILSMTP_NO_ERROR ) { + smtp->esmtp = 1; } else if( !try_esmtp || r==MAILSMTP_ERROR_NOT_IMPLEMENTED ) { - r = mailsmtp_helo(smtp->m_hEtpan); + r = mailsmtp_helo(smtp->hEtpan); } if( r != MAILSMTP_NO_ERROR ) { - dc_log_error_if(&smtp->m_log_connect_errors, smtp->m_context, 0, "SMTP-helo failed (%s)", mailsmtp_strerror(r)); + dc_log_error_if(&smtp->log_connect_errors, smtp->context, 0, "SMTP-helo failed (%s)", mailsmtp_strerror(r)); goto cleanup; } - if( lp->m_server_flags&DC_LP_SMTP_SOCKET_STARTTLS ) + if( lp->server_flags&DC_LP_SMTP_SOCKET_STARTTLS ) { - if( (r=mailsmtp_socket_starttls(smtp->m_hEtpan)) != MAILSMTP_NO_ERROR ) { - dc_log_error_if(&smtp->m_log_connect_errors, smtp->m_context, 0, "SMTP-STARTTLS failed (%s)", mailsmtp_strerror(r)); + if( (r=mailsmtp_socket_starttls(smtp->hEtpan)) != MAILSMTP_NO_ERROR ) { + dc_log_error_if(&smtp->log_connect_errors, smtp->context, 0, "SMTP-STARTTLS failed (%s)", mailsmtp_strerror(r)); goto cleanup; } - smtp->m_esmtp = 0; - if( try_esmtp && (r=mailesmtp_ehlo(smtp->m_hEtpan))==MAILSMTP_NO_ERROR ) { - smtp->m_esmtp = 1; + smtp->esmtp = 0; + if( try_esmtp && (r=mailesmtp_ehlo(smtp->hEtpan))==MAILSMTP_NO_ERROR ) { + smtp->esmtp = 1; } else if( !try_esmtp || r==MAILSMTP_ERROR_NOT_IMPLEMENTED ) { - r = mailsmtp_helo(smtp->m_hEtpan); + r = mailsmtp_helo(smtp->hEtpan); } if (r != MAILSMTP_NO_ERROR) { - dc_log_error_if(&smtp->m_log_connect_errors, smtp->m_context, 0, "SMTP-helo failed (%s)", mailsmtp_strerror(r)); + dc_log_error_if(&smtp->log_connect_errors, smtp->context, 0, "SMTP-helo failed (%s)", mailsmtp_strerror(r)); goto cleanup; } - dc_log_info(smtp->m_context, 0, "SMTP-server %s:%i STARTTLS-connected.", lp->m_send_server, (int)lp->m_send_port); + dc_log_info(smtp->context, 0, "SMTP-server %s:%i STARTTLS-connected.", lp->send_server, (int)lp->send_port); } - else if( lp->m_server_flags&DC_LP_SMTP_SOCKET_PLAIN ) + else if( lp->server_flags&DC_LP_SMTP_SOCKET_PLAIN ) { - dc_log_info(smtp->m_context, 0, "SMTP-server %s:%i connected.", lp->m_send_server, (int)lp->m_send_port); + dc_log_info(smtp->context, 0, "SMTP-server %s:%i connected.", lp->send_server, (int)lp->send_port); } else { - dc_log_info(smtp->m_context, 0, "SMTP-server %s:%i SSL-connected.", lp->m_send_server, (int)lp->m_send_port); + dc_log_info(smtp->context, 0, "SMTP-server %s:%i SSL-connected.", lp->send_server, (int)lp->send_port); } - if( lp->m_send_user ) + if( lp->send_user ) { - if((r=mailsmtp_auth(smtp->m_hEtpan, lp->m_send_user, lp->m_send_pw))!=MAILSMTP_NO_ERROR ) { + if((r=mailsmtp_auth(smtp->hEtpan, lp->send_user, lp->send_pw))!=MAILSMTP_NO_ERROR ) { /* * There are some Mailservers which do not correclty implement PLAIN auth (hMail) * So here we try a workaround. See https://github.com/deltachat/deltachat-android/issues/67 */ - if (smtp->m_hEtpan->auth & MAILSMTP_AUTH_PLAIN) { - dc_log_info(smtp->m_context, 0, "Trying SMTP-Login workaround \"%s\"...", lp->m_send_user); + if (smtp->hEtpan->auth & MAILSMTP_AUTH_PLAIN) { + dc_log_info(smtp->context, 0, "Trying SMTP-Login workaround \"%s\"...", lp->send_user); int err; char hostname[513]; err = gethostname(hostname, sizeof(hostname)); if (err < 0) { - dc_log_error(smtp->m_context, 0, "SMTP-Login: Cannot get hostname."); + dc_log_error(smtp->context, 0, "SMTP-Login: Cannot get hostname."); goto cleanup; } - r = mailesmtp_auth_sasl(smtp->m_hEtpan, "PLAIN", hostname, NULL, NULL, NULL, lp->m_send_user, lp->m_send_pw, NULL); + r = mailesmtp_auth_sasl(smtp->hEtpan, "PLAIN", hostname, NULL, NULL, NULL, lp->send_user, lp->send_pw, NULL); } if (r != MAILSMTP_NO_ERROR) { - dc_log_error_if(&smtp->m_log_connect_errors, smtp->m_context, 0, "SMTP-login failed for user %s (%s)", lp->m_send_user, mailsmtp_strerror(r)); + dc_log_error_if(&smtp->log_connect_errors, smtp->context, 0, "SMTP-login failed for user %s (%s)", lp->send_user, mailsmtp_strerror(r)); goto cleanup; } } - dc_log_info(smtp->m_context, 0, "SMTP-login as %s ok.", lp->m_send_user); + dc_log_info(smtp->context, 0, "SMTP-login as %s ok.", lp->send_user); } success = 1; cleanup: if( !success ) { - if( smtp->m_hEtpan ) { - mailsmtp_free(smtp->m_hEtpan); - smtp->m_hEtpan = NULL; + if( smtp->hEtpan ) { + mailsmtp_free(smtp->hEtpan); + smtp->hEtpan = NULL; } } @@ -239,10 +239,10 @@ void dc_smtp_disconnect(dc_smtp_t* smtp) return; } - if( smtp->m_hEtpan ) { - //mailsmtp_quit(smtp->m_hEtpan); -- ? - mailsmtp_free(smtp->m_hEtpan); - smtp->m_hEtpan = NULL; + if( smtp->hEtpan ) { + //mailsmtp_quit(smtp->hEtpan); -- ? + mailsmtp_free(smtp->hEtpan); + smtp->hEtpan = NULL; } } @@ -265,42 +265,42 @@ int dc_smtp_send_msg(dc_smtp_t* smtp, const clist* recipients, const char* data_ return 1; /* "null message" send */ } - if( smtp->m_hEtpan==NULL ) { + if( smtp->hEtpan==NULL ) { goto cleanup; } /* set source */ - if( (r=(smtp->m_esmtp? - mailesmtp_mail(smtp->m_hEtpan, smtp->m_from, 1, "etPanSMTPTest") : - mailsmtp_mail(smtp->m_hEtpan, smtp->m_from))) != MAILSMTP_NO_ERROR ) + if( (r=(smtp->esmtp? + mailesmtp_mail(smtp->hEtpan, smtp->from, 1, "etPanSMTPTest") : + mailsmtp_mail(smtp->hEtpan, smtp->from))) != MAILSMTP_NO_ERROR ) { // this error is very usual - we've simply lost the server connection and reconnect as soon as possible. // so, we do not log the first time this happens - dc_log_error_if(&smtp->m_log_usual_error, smtp->m_context, 0, "mailsmtp_mail: %s, %s (%i)", smtp->m_from, mailsmtp_strerror(r), (int)r); - smtp->m_log_usual_error = 1; + dc_log_error_if(&smtp->log_usual_error, smtp->context, 0, "mailsmtp_mail: %s, %s (%i)", smtp->from, mailsmtp_strerror(r), (int)r); + smtp->log_usual_error = 1; goto cleanup; } - smtp->m_log_usual_error = 0; + smtp->log_usual_error = 0; /* set recipients */ for( iter=clist_begin(recipients); iter!=NULL; iter=clist_next(iter)) { const char* rcpt = clist_content(iter); - if( (r = (smtp->m_esmtp? - mailesmtp_rcpt(smtp->m_hEtpan, rcpt, MAILSMTP_DSN_NOTIFY_FAILURE|MAILSMTP_DSN_NOTIFY_DELAY, NULL) : - mailsmtp_rcpt(smtp->m_hEtpan, rcpt))) != MAILSMTP_NO_ERROR) { - dc_log_error_if(&smtp->m_log_connect_errors, smtp->m_context, 0, "mailsmtp_rcpt: %s: %s", rcpt, mailsmtp_strerror(r)); + if( (r = (smtp->esmtp? + mailesmtp_rcpt(smtp->hEtpan, rcpt, MAILSMTP_DSN_NOTIFY_FAILURE|MAILSMTP_DSN_NOTIFY_DELAY, NULL) : + mailsmtp_rcpt(smtp->hEtpan, rcpt))) != MAILSMTP_NO_ERROR) { + dc_log_error_if(&smtp->log_connect_errors, smtp->context, 0, "mailsmtp_rcpt: %s: %s", rcpt, mailsmtp_strerror(r)); goto cleanup; } } /* message */ - if ((r = mailsmtp_data(smtp->m_hEtpan)) != MAILSMTP_NO_ERROR) { + if ((r = mailsmtp_data(smtp->hEtpan)) != MAILSMTP_NO_ERROR) { fprintf(stderr, "mailsmtp_data: %s\n", mailsmtp_strerror(r)); goto cleanup; } - if ((r = mailsmtp_data_message(smtp->m_hEtpan, data_not_terminated, data_bytes)) != MAILSMTP_NO_ERROR) { + if ((r = mailsmtp_data_message(smtp->hEtpan, data_not_terminated, data_bytes)) != MAILSMTP_NO_ERROR) { fprintf(stderr, "mailsmtp_data_message: %s\n", mailsmtp_strerror(r)); goto cleanup; } diff --git a/src/dc_smtp.h b/src/dc_smtp.h index 4d65615e..a9667e46 100644 --- a/src/dc_smtp.h +++ b/src/dc_smtp.h @@ -34,14 +34,14 @@ extern "C" { typedef struct dc_smtp_t { - mailsmtp* m_hEtpan; - char* m_from; - int m_esmtp; + mailsmtp* hEtpan; + char* from; + int esmtp; - int m_log_connect_errors; - int m_log_usual_error; + int log_connect_errors; + int log_usual_error; - dc_context_t* m_context; /* only for logging! */ + dc_context_t* context; /* only for logging! */ } dc_smtp_t; dc_smtp_t* dc_smtp_new (dc_context_t*); diff --git a/src/dc_sqlite3.c b/src/dc_sqlite3.c index 8d730aa2..de6b56fe 100644 --- a/src/dc_sqlite3.c +++ b/src/dc_sqlite3.c @@ -59,8 +59,8 @@ void dc_sqlite3_log_error(dc_sqlite3_t* sql, const char* msg_format, ...) va_list va; va_start(va, msg_format); - msg = sqlite3_vmprintf(msg_format, va); if( msg == NULL ) { dc_log_error(sql->m_context, 0, "Bad log format string \"%s\".", msg_format); } - dc_log_error(sql->m_context, 0, "%s SQLite says: %s", msg, sql->m_cobj? sqlite3_errmsg(sql->m_cobj) : notSetUp); + msg = sqlite3_vmprintf(msg_format, va); if( msg == NULL ) { dc_log_error(sql->context, 0, "Bad log format string \"%s\".", msg_format); } + dc_log_error(sql->context, 0, "%s SQLite says: %s", msg, sql->cobj? sqlite3_errmsg(sql->cobj) : notSetUp); sqlite3_free(msg); va_end(va); } @@ -70,11 +70,11 @@ sqlite3_stmt* dc_sqlite3_prepare(dc_sqlite3_t* sql, const char* querystr) { sqlite3_stmt* stmt = NULL; - if( sql == NULL || querystr == NULL || sql->m_cobj == NULL ) { + if( sql == NULL || querystr == NULL || sql->cobj == NULL ) { return NULL; } - if( sqlite3_prepare_v2(sql->m_cobj, + if( sqlite3_prepare_v2(sql->cobj, querystr, -1 /*read `querystr` up to the first null-byte*/, &stmt, NULL /*tail not interesting, we use only single statements*/) != SQLITE_OK ) @@ -142,7 +142,7 @@ dc_sqlite3_t* dc_sqlite3_new(dc_context_t* context) exit(24); /* cannot allocate little memory, unrecoverable error */ } - sql->m_context = context; + sql->context = context; return sql; } @@ -154,7 +154,7 @@ void dc_sqlite3_unref(dc_sqlite3_t* sql) return; } - if( sql->m_cobj ) { + if( sql->cobj ) { dc_sqlite3_close__(sql); } @@ -169,12 +169,12 @@ int dc_sqlite3_open__(dc_sqlite3_t* sql, const char* dbfile, int flags) } if( sqlite3_threadsafe() == 0 ) { - dc_log_error(sql->m_context, 0, "Sqlite3 compiled thread-unsafe; this is not supported."); + dc_log_error(sql->context, 0, "Sqlite3 compiled thread-unsafe; this is not supported."); goto cleanup; } - if( sql->m_cobj ) { - dc_log_error(sql->m_context, 0, "Cannot open, database \"%s\" already opened.", dbfile); + if( sql->cobj ) { + dc_log_error(sql->context, 0, "Cannot open, database \"%s\" already opened.", dbfile); goto cleanup; } @@ -187,7 +187,7 @@ int dc_sqlite3_open__(dc_sqlite3_t* sql, const char* dbfile, int flags) // files, caching is not that important; we rely on the system defaults here // (normally 2 MB cache, 1 KB page size on sqlite < 3.12.0, 4 KB for newer // versions) - if( sqlite3_open_v2(dbfile, &sql->m_cobj, + if( sqlite3_open_v2(dbfile, &sql->cobj, SQLITE_OPEN_FULLMUTEX | ((flags&DC_OPEN_READONLY)? SQLITE_OPEN_READONLY : (SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)), NULL) != SQLITE_OK ) { dc_sqlite3_log_error(sql, "Cannot open database \"%s\".", dbfile); /* ususally, even for errors, the pointer is set up (if not, this is also checked by dc_sqlite3_log_error()) */ @@ -199,7 +199,7 @@ int dc_sqlite3_open__(dc_sqlite3_t* sql, const char* dbfile, int flags) // and try over until it gets write access or the given timeout is elapsed. // If the second process does not get write access within the given timeout, sqlite3_step() will return the error SQLITE_BUSY. // (without a busy_timeout, sqlite3_step() would return SQLITE_BUSY at once) - sqlite3_busy_timeout(sql->m_cobj, 10*1000); + sqlite3_busy_timeout(sql->cobj, 10*1000); if( !(flags&DC_OPEN_READONLY) ) { @@ -208,7 +208,7 @@ int dc_sqlite3_open__(dc_sqlite3_t* sql, const char* dbfile, int flags) /* Init tables to dbversion=0 */ if( !dc_sqlite3_table_exists__(sql, "config") ) { - dc_log_info(sql->m_context, 0, "First time init: creating tables in \"%s\".", dbfile); + dc_log_info(sql->context, 0, "First time init: creating tables in \"%s\".", dbfile); // the row with the type `INTEGER PRIMARY KEY` is an alias to the 64-bit-ROWID present in every table // we re-use this ID for our own purposes. @@ -463,7 +463,7 @@ int dc_sqlite3_open__(dc_sqlite3_t* sql, const char* dbfile, int flags) { sqlite3_stmt* stmt = dc_sqlite3_prepare(sql, "SELECT addr FROM acpeerstates;"); while( sqlite3_step(stmt) == SQLITE_ROW ) { - dc_apeerstate_t* peerstate = dc_apeerstate_new(sql->m_context); + dc_apeerstate_t* peerstate = dc_apeerstate_new(sql->context); if( dc_apeerstate_load_by_addr(peerstate, sql, (const char*)sqlite3_column_text(stmt, 0)) && dc_apeerstate_recalc_fingerprint(peerstate) ) { dc_apeerstate_save_to_db(peerstate, sql, 0/*don't create*/); @@ -474,7 +474,7 @@ int dc_sqlite3_open__(dc_sqlite3_t* sql, const char* dbfile, int flags) } } - dc_log_info(sql->m_context, 0, "Opened \"%s\".", dbfile); + dc_log_info(sql->context, 0, "Opened \"%s\".", dbfile); return 1; cleanup: @@ -489,19 +489,19 @@ void dc_sqlite3_close__(dc_sqlite3_t* sql) return; } - if( sql->m_cobj ) + if( sql->cobj ) { - sqlite3_close(sql->m_cobj); - sql->m_cobj = NULL; + sqlite3_close(sql->cobj); + sql->cobj = NULL; } - dc_log_info(sql->m_context, 0, "Database closed."); /* We log the information even if not real closing took place; this is to detect logic errors. */ + dc_log_info(sql->context, 0, "Database closed."); /* We log the information even if not real closing took place; this is to detect logic errors. */ } int dc_sqlite3_is_open(const dc_sqlite3_t* sql) { - if( sql == NULL || sql->m_cobj == NULL ) { + if( sql == NULL || sql->cobj == NULL ) { return 0; } return 1; @@ -516,7 +516,7 @@ int dc_sqlite3_table_exists__(dc_sqlite3_t* sql, const char* name) int sqlState; if( (querystr=sqlite3_mprintf("PRAGMA table_info(%s)", name)) == NULL ) { /* this statement cannot be used with binded variables */ - dc_log_error(sql->m_context, 0, "dc_sqlite3_table_exists_(): Out of memory."); + dc_log_error(sql->context, 0, "dc_sqlite3_table_exists_(): Out of memory."); goto cleanup; } @@ -557,12 +557,12 @@ int dc_sqlite3_set_config(dc_sqlite3_t* sql, const char* key, const char* value) sqlite3_stmt* stmt; if( key == NULL ) { - dc_log_error(sql->m_context, 0, "dc_sqlite3_set_config(): Bad parameter."); + dc_log_error(sql->context, 0, "dc_sqlite3_set_config(): Bad parameter."); return 0; } if( !dc_sqlite3_is_open(sql) ) { - dc_log_error(sql->m_context, 0, "dc_sqlite3_set_config(): Database not ready."); + dc_log_error(sql->context, 0, "dc_sqlite3_set_config(): Database not ready."); return 0; } @@ -590,7 +590,7 @@ int dc_sqlite3_set_config(dc_sqlite3_t* sql, const char* key, const char* value) sqlite3_finalize(stmt); } else { - dc_log_error(sql->m_context, 0, "dc_sqlite3_set_config(): Cannot read value."); + dc_log_error(sql->context, 0, "dc_sqlite3_set_config(): Cannot read value."); return 0; } } @@ -604,7 +604,7 @@ int dc_sqlite3_set_config(dc_sqlite3_t* sql, const char* key, const char* value) } if( state != SQLITE_DONE ) { - dc_log_error(sql->m_context, 0, "dc_sqlite3_set_config(): Cannot change value."); + dc_log_error(sql->context, 0, "dc_sqlite3_set_config(): Cannot change value."); return 0; } diff --git a/src/dc_sqlite3.h b/src/dc_sqlite3.h index b2660f8e..7f36cef3 100644 --- a/src/dc_sqlite3.h +++ b/src/dc_sqlite3.h @@ -45,8 +45,8 @@ extern "C" { typedef struct dc_sqlite3_t { /** @privatesection */ - sqlite3* m_cobj; /**< is the database given as dbfile to Open() */ - dc_context_t* m_context; /**< used for logging and to acquire wakelocks, there may be N dc_sqlite3_t objects per context! In practise, we use 2 on backup, 1 otherwise. */ + sqlite3* cobj; /**< is the database given as dbfile to Open() */ + dc_context_t* context; /**< used for logging and to acquire wakelocks, there may be N dc_sqlite3_t objects per context! In practise, we use 2 on backup, 1 otherwise. */ } dc_sqlite3_t; diff --git a/src/dc_stock.c b/src/dc_stock.c index 74dd22c3..eefeccba 100644 --- a/src/dc_stock.c +++ b/src/dc_stock.c @@ -81,7 +81,7 @@ char* dc_stock_str(dc_context_t* context, int id) /* get the string with the giv { char* ret = NULL; if( context ) { - ret = (char*)context->m_cb(context, DC_EVENT_GET_STRING, id, 0); + ret = (char*)context->cb(context, DC_EVENT_GET_STRING, id, 0); } if( ret == NULL ) { ret = default_string(id, 0); @@ -120,7 +120,7 @@ char* dc_stock_str_repl_pl(dc_context_t* context, int id, int cnt) { char* ret = NULL; if( context ) { - ret = (char*)context->m_cb(context, DC_EVENT_GET_QUANTITY_STRING, id, cnt); + ret = (char*)context->cb(context, DC_EVENT_GET_QUANTITY_STRING, id, cnt); } if( ret == NULL ) { ret = default_string(id, cnt); diff --git a/src/dc_strbuilder.c b/src/dc_strbuilder.c index 12df5188..fc1dd913 100644 --- a/src/dc_strbuilder.c +++ b/src/dc_strbuilder.c @@ -32,7 +32,7 @@ * dc_strbuilder_catf() - the buffer is reallocated as needed. * * When you're done with string building, the ready-to-use, null-terminates - * string can be found at dc_strbuilder_t::m_buf, you can do whatever you like + * string can be found at dc_strbuilder_t::buf, you can do whatever you like * with this buffer, however, never forget to call free() when done. * * @param strbuilder The object to initialze. @@ -48,16 +48,16 @@ void dc_strbuilder_init(dc_strbuilder_t* strbuilder, int init_bytes) return; } - strbuilder->m_allocated = DC_MAX(init_bytes, 128); /* use a small default minimum, we may use _many_ of these objects at the same time */ - strbuilder->m_buf = malloc(strbuilder->m_allocated); + strbuilder->allocated = DC_MAX(init_bytes, 128); /* use a small default minimum, we may use _many_ of these objects at the same time */ + strbuilder->buf = malloc(strbuilder->allocated); - if( strbuilder->m_buf==NULL ) { + if( strbuilder->buf==NULL ) { exit(38); } - strbuilder->m_buf[0] = 0; - strbuilder->m_free = strbuilder->m_allocated - 1 /*the nullbyte! */; - strbuilder->m_eos = strbuilder->m_buf; + strbuilder->buf[0] = 0; + strbuilder->free = strbuilder->allocated - 1 /*the nullbyte! */; + strbuilder->eos = strbuilder->buf; } @@ -70,9 +70,9 @@ void dc_strbuilder_init(dc_strbuilder_t* strbuilder, int init_bytes) * dc_strbuilder_init(). * @param text Null-terminated string to add to the end of the string-builder-string. * @return Returns a pointer to the copy of the given text. - * The returned pointer is a pointer inside dc_strbuilder_t::m_buf and MUST NOT + * The returned pointer is a pointer inside dc_strbuilder_t::buf and MUST NOT * be freed. If the string-builder was empty before, the returned - * pointer is equal to dc_strbuilder_t::m_buf. + * pointer is equal to dc_strbuilder_t::buf. * If the given text is NULL, NULL is returned and the string-builder-object is not modified. */ char* dc_strbuilder_cat(dc_strbuilder_t* strbuilder, const char* text) @@ -84,26 +84,26 @@ char* dc_strbuilder_cat(dc_strbuilder_t* strbuilder, const char* text) int len = strlen(text); - if( len > strbuilder->m_free ) { - int add_bytes = DC_MAX(len, strbuilder->m_allocated); - int old_offset = (int)(strbuilder->m_eos - strbuilder->m_buf); + if( len > strbuilder->free ) { + int add_bytes = DC_MAX(len, strbuilder->allocated); + int old_offset = (int)(strbuilder->eos - strbuilder->buf); - strbuilder->m_allocated = strbuilder->m_allocated + add_bytes; - strbuilder->m_buf = realloc(strbuilder->m_buf, strbuilder->m_allocated+add_bytes); + strbuilder->allocated = strbuilder->allocated + add_bytes; + strbuilder->buf = realloc(strbuilder->buf, strbuilder->allocated+add_bytes); - if( strbuilder->m_buf==NULL ) { + if( strbuilder->buf==NULL ) { exit(39); } - strbuilder->m_free = strbuilder->m_free + add_bytes; - strbuilder->m_eos = strbuilder->m_buf + old_offset; + strbuilder->free = strbuilder->free + add_bytes; + strbuilder->eos = strbuilder->buf + old_offset; } - char* ret = strbuilder->m_eos; + char* ret = strbuilder->eos; - strcpy(strbuilder->m_eos, text); - strbuilder->m_eos += len; - strbuilder->m_free -= len; + strcpy(strbuilder->eos, text); + strbuilder->eos += len; + strbuilder->free -= len; return ret; } @@ -157,7 +157,7 @@ void dc_strbuilder_catf(dc_strbuilder_t* strbuilder, const char* format, ...) /** * Set the string to a lenght of 0. This does not free the buffer; - * if you want to free the buffer, you have to call free() on dc_strbuilder_t::m_buf. + * if you want to free the buffer, you have to call free() on dc_strbuilder_t::buf. * * @param strbuilder The object to initialze. Must be initialized with * dc_strbuilder_init(). @@ -165,7 +165,7 @@ void dc_strbuilder_catf(dc_strbuilder_t* strbuilder, const char* format, ...) */ void dc_strbuilder_empty(dc_strbuilder_t* strbuilder) { - strbuilder->m_buf[0] = 0; - strbuilder->m_free = strbuilder->m_allocated - 1 /*the nullbyte! */; - strbuilder->m_eos = strbuilder->m_buf; + strbuilder->buf[0] = 0; + strbuilder->free = strbuilder->allocated - 1 /*the nullbyte! */; + strbuilder->eos = strbuilder->buf; } diff --git a/src/dc_strbuilder.h b/src/dc_strbuilder.h index 6b84586d..e1ae6442 100644 --- a/src/dc_strbuilder.h +++ b/src/dc_strbuilder.h @@ -29,10 +29,10 @@ extern "C" { typedef struct dc_strbuilder_t { - char* m_buf; - int m_allocated; - int m_free; - char* m_eos; + char* buf; + int allocated; + int free; + char* eos; } dc_strbuilder_t; diff --git a/src/dc_token.c b/src/dc_token.c index 22e0bc11..fb6bb679 100644 --- a/src/dc_token.c +++ b/src/dc_token.c @@ -28,11 +28,11 @@ void dc_token_save__(dc_context_t* context, dc_tokennamespc_t namespc, uint32_t { sqlite3_stmt* stmt = NULL; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || token == NULL ) { // foreign_id may be 0 + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || token == NULL ) { // foreign_id may be 0 goto cleanup; } - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "INSERT INTO tokens (namespc, foreign_id, token, timestamp) VALUES (?, ?, ?, ?);"); sqlite3_bind_int (stmt, 1, (int)namespc); sqlite3_bind_int (stmt, 2, (int)foreign_id); @@ -50,11 +50,11 @@ char* dc_token_lookup__(dc_context_t* context, dc_tokennamespc_t namespc, uint32 char* token = NULL; sqlite3_stmt* stmt = NULL; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC ) { goto cleanup; } - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT token FROM tokens WHERE namespc=? AND foreign_id=?;"); sqlite3_bind_int (stmt, 1, (int)namespc); sqlite3_bind_int (stmt, 2, (int)foreign_id); @@ -73,11 +73,11 @@ int dc_token_exists__(dc_context_t* context, dc_tokennamespc_t namespc, const ch int exists = 0; sqlite3_stmt* stmt = NULL; - if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC || token == NULL ) { + if( context == NULL || context->magic != DC_CONTEXT_MAGIC || token == NULL ) { goto cleanup; } - stmt = dc_sqlite3_prepare(context->m_sql, + stmt = dc_sqlite3_prepare(context->sql, "SELECT id FROM tokens WHERE namespc=? AND token=?;"); sqlite3_bind_int (stmt, 1, (int)namespc); sqlite3_bind_text(stmt, 2, token, -1, SQLITE_STATIC); diff --git a/src/dc_tools.c b/src/dc_tools.c index 608e3866..e7cbdea5 100644 --- a/src/dc_tools.c +++ b/src/dc_tools.c @@ -761,8 +761,8 @@ struct mailimap_date_time* dc_timestamp_to_mailimap_date_time(time_t timeval) #define DC_MAX_SECONDS_TO_LEND_FROM_FUTURE 5 -#define SMEAR_LOCK { pthread_mutex_lock(&context->m_smear_critical); } -#define SMEAR_UNLOCK { pthread_mutex_unlock(&context->m_smear_critical); } +#define SMEAR_LOCK { pthread_mutex_lock(&context->smear_critical); } +#define SMEAR_UNLOCK { pthread_mutex_unlock(&context->smear_critical); } time_t dc_create_smeared_timestamp(dc_context_t* context) @@ -770,13 +770,13 @@ time_t dc_create_smeared_timestamp(dc_context_t* context) time_t now = time(NULL); time_t ret = now; SMEAR_LOCK - if( ret <= context->m_last_smeared_timestamp ) { - ret = context->m_last_smeared_timestamp+1; + if( ret <= context->last_smeared_timestamp ) { + ret = context->last_smeared_timestamp+1; if( (ret-now) > DC_MAX_SECONDS_TO_LEND_FROM_FUTURE ) { ret = now + DC_MAX_SECONDS_TO_LEND_FROM_FUTURE; } } - context->m_last_smeared_timestamp = ret; + context->last_smeared_timestamp = ret; SMEAR_UNLOCK return ret; } @@ -788,8 +788,8 @@ time_t dc_create_smeared_timestamps(dc_context_t* context, int count) time_t now = time(NULL); time_t start = now + DC_MIN(count, DC_MAX_SECONDS_TO_LEND_FROM_FUTURE) - count; SMEAR_LOCK - start = DC_MAX(context->m_last_smeared_timestamp+1, start); - context->m_last_smeared_timestamp = start+(count-1); + start = DC_MAX(context->last_smeared_timestamp+1, start); + context->last_smeared_timestamp = start+(count-1); SMEAR_UNLOCK return start; } @@ -800,8 +800,8 @@ time_t dc_smeared_time(dc_context_t* context) /* function returns a corrected time(NULL) */ time_t now = time(NULL); SMEAR_LOCK - if( context->m_last_smeared_timestamp >= now ) { - now = context->m_last_smeared_timestamp+1; + if( context->last_smeared_timestamp >= now ) { + now = context->last_smeared_timestamp+1; } SMEAR_UNLOCK return now; diff --git a/src/deltachat.h b/src/deltachat.h index 165e39a0..c6b18270 100644 --- a/src/deltachat.h +++ b/src/deltachat.h @@ -448,12 +448,12 @@ typedef struct _dc_msg dc_msg_t; #define DC_MSG_UNDEFINED 0 #define DC_MSG_TEXT 10 -#define DC_MSG_IMAGE 20 // m_param may contain FILE, WIDTH, HEIGHT +#define DC_MSG_IMAGE 20 // param may contain FILE, WIDTH, HEIGHT #define DC_MSG_GIF 21 // - " - -#define DC_MSG_AUDIO 40 // m_param may contain FILE, DURATION +#define DC_MSG_AUDIO 40 // param may contain FILE, DURATION #define DC_MSG_VOICE 41 // - " - -#define DC_MSG_VIDEO 50 // m_param may contain FILE, WIDTH, HEIGHT, DURATION -#define DC_MSG_FILE 60 // m_param may contain FILE +#define DC_MSG_VIDEO 50 // param may contain FILE, WIDTH, HEIGHT, DURATION +#define DC_MSG_FILE 60 // param may contain FILE #define DC_STATE_UNDEFINED 0