diff options
author | George Hazan <ghazan@miranda.im> | 2019-02-28 20:00:53 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2019-02-28 20:00:53 +0300 |
commit | 2e9d13165b4fd765d95f88d26282be022e708b0d (patch) | |
tree | d9b65c84d86a5c1c74dbd944c08350c0c781dc95 | |
parent | 62116c7d1c0d4def03c0331688a63ee6144f8363 (diff) |
MirOTR:
- fix for Unicode file names;
- fix for reading utf8 strings from Windows GUI;
- contact_get_id: unused second parameter removed;
- contact_get_id: result is encoded in utf8, thus preventing from errors;
-rw-r--r-- | plugins/MirOTR/libotr/src/instag.c | 12 | ||||
-rw-r--r-- | plugins/MirOTR/libotr/src/instag.h | 6 | ||||
-rw-r--r-- | plugins/MirOTR/libotr/src/privkey.c | 20 | ||||
-rw-r--r-- | plugins/MirOTR/libotr/src/privkey.h | 10 | ||||
-rw-r--r-- | plugins/MirOTR/src/dialogs.cpp | 41 | ||||
-rw-r--r-- | plugins/MirOTR/src/options.cpp | 12 | ||||
-rw-r--r-- | plugins/MirOTR/src/otr.cpp | 6 | ||||
-rw-r--r-- | plugins/MirOTR/src/otrlextensions.c | 6 | ||||
-rw-r--r-- | plugins/MirOTR/src/otrlextensions.h | 4 | ||||
-rw-r--r-- | plugins/MirOTR/src/utils.cpp | 154 | ||||
-rw-r--r-- | plugins/MirOTR/src/utils.h | 5 |
11 files changed, 143 insertions, 133 deletions
diff --git a/plugins/MirOTR/libotr/src/instag.c b/plugins/MirOTR/libotr/src/instag.c index a1142239a4..602e6c5fa9 100644 --- a/plugins/MirOTR/libotr/src/instag.c +++ b/plugins/MirOTR/libotr/src/instag.c @@ -70,13 +70,13 @@ OtrlInsTag * otrl_instag_find(OtrlUserState us, const char *accountname, /* Read our instance tag from a file on disk into the given * OtrlUserState. */ -gcry_error_t otrl_instag_read(OtrlUserState us, const char *filename) +gcry_error_t otrl_instag_read(OtrlUserState us, const wchar_t *filename) { gcry_error_t err; FILE *instf; /* Open the instance tag file. */ - instf = fopen(filename, "rb"); + instf = _wfopen(filename, L"rb"); if (!instf) { return gcry_error_from_errno(errno); } @@ -183,14 +183,14 @@ gcry_error_t otrl_instag_read_FILEp(OtrlUserState us, FILE *instf) } /* Generate a new instance tag for the given account and write to file */ -gcry_error_t otrl_instag_generate(OtrlUserState us, const char *filename, +gcry_error_t otrl_instag_generate(OtrlUserState us, const wchar_t *filename, const char *accountname, const char *protocol) { gcry_error_t err; FILE *instf; /* Open the instance tag file. */ - instf = fopen(filename, "wb"); + instf = _wfopen(filename, L"wb"); if (!instf) { return gcry_error_from_errno(errno); } @@ -243,13 +243,13 @@ gcry_error_t otrl_instag_generate_FILEp(OtrlUserState us, FILE *instf, } /* Write our instance tags to a file on disk. */ -gcry_error_t otrl_instag_write(OtrlUserState us, const char *filename) +gcry_error_t otrl_instag_write(OtrlUserState us, const wchar_t *filename) { gcry_error_t err; FILE *instf; /* Open the instance tag file. */ - instf = fopen(filename, "wb"); + instf = _wfopen(filename, L"wb"); if (!instf) { return gcry_error_from_errno(errno); } diff --git a/plugins/MirOTR/libotr/src/instag.h b/plugins/MirOTR/libotr/src/instag.h index c8aabb324f..e5524aa63c 100644 --- a/plugins/MirOTR/libotr/src/instag.h +++ b/plugins/MirOTR/libotr/src/instag.h @@ -61,7 +61,7 @@ OtrlInsTag * otrl_instag_find(OtrlUserState us, const char *accountname, /* Read our instance tag from a file on disk into the given * OtrlUserState. */ -gcry_error_t otrl_instag_read(OtrlUserState us, const char *filename); +gcry_error_t otrl_instag_read(OtrlUserState us, const wchar_t *filename); /* Read our instance tag from a file on disk into the given * OtrlUserState. The FILE* must be open for reading. */ @@ -71,7 +71,7 @@ gcry_error_t otrl_instag_read_FILEp(OtrlUserState us, FILE *instf); otrl_instag_t otrl_instag_get_new(); /* Get a new instance tag for the given account and write to file*/ -gcry_error_t otrl_instag_generate(OtrlUserState us, const char *filename, +gcry_error_t otrl_instag_generate(OtrlUserState us, const wchar_t *filename, const char *accountname, const char *protocol); /* Get a new instance tag for the given account and write to file @@ -80,7 +80,7 @@ gcry_error_t otrl_instag_generate_FILEp(OtrlUserState us, FILE *instf, const char *accountname, const char *protocol); /* Write our instance tags to a file on disk. */ -gcry_error_t otrl_instag_write(OtrlUserState us, const char *filename); +gcry_error_t otrl_instag_write(OtrlUserState us, const wchar_t *filename); /* Write our instance tags to a file on disk. * The FILE* must be open for writing. */ diff --git a/plugins/MirOTR/libotr/src/privkey.c b/plugins/MirOTR/libotr/src/privkey.c index 6e4bbe40fc..d6890f48d5 100644 --- a/plugins/MirOTR/libotr/src/privkey.c +++ b/plugins/MirOTR/libotr/src/privkey.c @@ -177,7 +177,7 @@ static gcry_error_t make_pubkey(unsigned char **pubbufp, size_t *publenp, /* Read a sets of private DSA keys from a file on disk into the given * OtrlUserState. */ -gcry_error_t otrl_privkey_read(OtrlUserState us, const char *filename) +gcry_error_t otrl_privkey_read(OtrlUserState us, const wchar_t *filename) { FILE *privf; gcry_error_t err; @@ -185,7 +185,7 @@ gcry_error_t otrl_privkey_read(OtrlUserState us, const char *filename) /* Open the privkey file. We use rb mode so that on WIN32, fread() * reads the same number of bytes that fstat() indicates are in the * file. */ - privf = fopen(filename, "rb"); + privf = _wfopen(filename, L"rb"); if (!privf) { err = gcry_error_from_errno(errno); return err; @@ -526,7 +526,7 @@ gcry_error_t otrl_privkey_generate_calculate(void *newkey) return gcry_error(GPG_ERR_NO_ERROR); } -static FILE* privkey_fopen(const char *filename, gcry_error_t *errp) +static FILE* privkey_fopen(const wchar_t *filename, gcry_error_t *errp) { FILE *privf; #ifndef WIN32 @@ -536,7 +536,7 @@ static FILE* privkey_fopen(const char *filename, gcry_error_t *errp) #ifndef WIN32 oldmask = umask(077); #endif - privf = fopen(filename, "w+b"); + privf = _wfopen(filename, L"w+b"); if (!privf && errp) { *errp = gcry_error_from_errno(errno); } @@ -568,7 +568,7 @@ void otrl_privkey_generate_cancelled(OtrlUserState us, void *newkey) /* Call this from the main thread only. It will write the newly created * private key into the given file and store it in the OtrlUserState. */ gcry_error_t otrl_privkey_generate_finish(OtrlUserState us, - void *newkey, const char *filename) + void *newkey, const wchar_t *filename) { gcry_error_t err; FILE *privf = privkey_fopen(filename, &err); @@ -623,7 +623,7 @@ gcry_error_t otrl_privkey_generate_finish_FILEp(OtrlUserState us, /* Generate a private DSA key for a given account, storing it into a * file on disk, and loading it into the given OtrlUserState. Overwrite any * previously generated keys for that account in that OtrlUserState. */ -gcry_error_t otrl_privkey_generate(OtrlUserState us, const char *filename, +gcry_error_t otrl_privkey_generate(OtrlUserState us, const wchar_t *filename, const char *accountname, const char *protocol) { gcry_error_t err; @@ -670,14 +670,14 @@ static unsigned int ctoh(char c) * OtrlUserState. Use add_app_data to add application data to each * ConnContext so created. */ gcry_error_t otrl_privkey_read_fingerprints(OtrlUserState us, - const char *filename, + const wchar_t*filename, void (*add_app_data)(void *data, ConnContext *context), void *data) { gcry_error_t err; FILE *storef; - storef = fopen(filename, "rb"); + storef = _wfopen(filename, L"rb"); if (!storef) { err = gcry_error_from_errno(errno); return err; @@ -765,12 +765,12 @@ gcry_error_t otrl_privkey_read_fingerprints_FILEp(OtrlUserState us, /* Write the fingerprint store from a given OtrlUserState to a file on disk. */ gcry_error_t otrl_privkey_write_fingerprints(OtrlUserState us, - const char *filename) + const wchar_t *filename) { gcry_error_t err; FILE *storef; - storef = fopen(filename, "wb"); + storef = _wfopen(filename, L"wb"); if (!storef) { err = gcry_error_from_errno(errno); return err; diff --git a/plugins/MirOTR/libotr/src/privkey.h b/plugins/MirOTR/libotr/src/privkey.h index 3b2c1735e3..a3389d736d 100644 --- a/plugins/MirOTR/libotr/src/privkey.h +++ b/plugins/MirOTR/libotr/src/privkey.h @@ -49,7 +49,7 @@ unsigned char *otrl_privkey_fingerprint_raw(OtrlUserState us, /* Read a sets of private DSA keys from a file on disk into the given * OtrlUserState. */ -gcry_error_t otrl_privkey_read(OtrlUserState us, const char *filename); +gcry_error_t otrl_privkey_read(OtrlUserState us, const wchar_t *filename); /* Read a sets of private DSA keys from a FILE* into the given * OtrlUserState. The FILE* must be open for reading. */ @@ -76,7 +76,7 @@ gcry_error_t otrl_privkey_generate_calculate(void *newkey); /* Call this from the main thread only. It will write the newly created * private key into the given file and store it in the OtrlUserState. */ gcry_error_t otrl_privkey_generate_finish(OtrlUserState us, - void *newkey, const char *filename); + void *newkey, const wchar_t *filename); /* Call this from the main thread only. It will write the newly created * private key into the given FILE* (which must be open for reading and @@ -92,7 +92,7 @@ void otrl_privkey_generate_cancelled(OtrlUserState us, void *newkey); /* Generate a private DSA key for a given account, storing it into a * file on disk, and loading it into the given OtrlUserState. Overwrite any * previously generated keys for that account in that OtrlUserState. */ -gcry_error_t otrl_privkey_generate(OtrlUserState us, const char *filename, +gcry_error_t otrl_privkey_generate(OtrlUserState us, const wchar_t *filename, const char *accountname, const char *protocol); /* Generate a private DSA key for a given account, storing it into a @@ -106,7 +106,7 @@ gcry_error_t otrl_privkey_generate_FILEp(OtrlUserState us, FILE *privf, * OtrlUserState. Use add_app_data to add application data to each * ConnContext so created. */ gcry_error_t otrl_privkey_read_fingerprints(OtrlUserState us, - const char *filename, + const wchar_t *filename, void (*add_app_data)(void *data, ConnContext *context), void *data); @@ -120,7 +120,7 @@ gcry_error_t otrl_privkey_read_fingerprints_FILEp(OtrlUserState us, /* Write the fingerprint store from a given OtrlUserState to a file on disk. */ gcry_error_t otrl_privkey_write_fingerprints(OtrlUserState us, - const char *filename); + const wchar_t *filename); /* Write the fingerprint store from a given OtrlUserState to a FILE*. * The FILE* must be open for writing. */ diff --git a/plugins/MirOTR/src/dialogs.cpp b/plugins/MirOTR/src/dialogs.cpp index 2244b644e0..56e7b72feb 100644 --- a/plugins/MirOTR/src/dialogs.cpp +++ b/plugins/MirOTR/src/dialogs.cpp @@ -258,17 +258,11 @@ static INT_PTR CALLBACK DlgSMPResponseProc(HWND hwndDlg, UINT msg, WPARAM wParam case IDOK: SMPInitUpdateDialog(context, true); { - int len = SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD2, WM_GETTEXTLENGTH, 0, 0); - wchar_t *answer = new wchar_t[len + 1]; - GetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD2, answer, len + 1); - - T2Utf ans(answer); - otr_continue_smp(context, (const unsigned char *)ans, mir_strlen(ans)); - delete[] answer; - - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, NULL); - DestroyWindow(hwndDlg); + ptrA ans(GetDlgItemTextUtf(hwndDlg, IDC_EDT_SMP_FIELD2)); + otr_continue_smp(context, (const unsigned char *)ans.get(), mir_strlen(ans)); } + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, NULL); + DestroyWindow(hwndDlg); break; case IDCANCEL: @@ -397,20 +391,11 @@ static INT_PTR CALLBACK DlgProcSMPInitProc(HWND hwndDlg, UINT msg, WPARAM wParam ShowError(szMsg); } else { - int len = SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD1, WM_GETTEXTLENGTH, 0, 0); - wchar_t *question = new wchar_t[len + 1]; - GetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD1, question, len + 1); - T2Utf quest(question); - delete[] question; - - len = SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD2, WM_GETTEXTLENGTH, 0, 0); - wchar_t *answer = new wchar_t[len + 1]; - GetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD2, answer, len + 1); - T2Utf ans(answer); - delete[] answer; + ptrA quest(GetDlgItemTextUtf(hwndDlg, IDC_EDT_SMP_FIELD1)); + ptrA ans(GetDlgItemTextUtf(hwndDlg, IDC_EDT_SMP_FIELD2)); SMPInitUpdateDialog(context, false); - otr_start_smp(context, quest, (const unsigned char*)ans, mir_strlen(ans)); + otr_start_smp(context, quest, (const unsigned char*)ans.get(), mir_strlen(ans)); } } @@ -420,14 +405,10 @@ static INT_PTR CALLBACK DlgProcSMPInitProc(HWND hwndDlg, UINT msg, WPARAM wParam ShowError(szMsg); } else { - int len = SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD2, WM_GETTEXTLENGTH, 0, 0); - wchar_t *answer = new wchar_t[len + 1]; - GetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD2, answer, len + 1); - T2Utf ans(answer); - delete[] answer; + ptrA ans(GetDlgItemTextUtf(hwndDlg, IDC_EDT_SMP_FIELD2)); SMPInitUpdateDialog(context, false); - otr_start_smp(context, nullptr, (const unsigned char*)ans, mir_strlen(ans)); + otr_start_smp(context, nullptr, (const unsigned char*)ans.get(), mir_strlen(ans)); } } @@ -455,8 +436,10 @@ static INT_PTR CALLBACK DlgProcSMPInitProc(HWND hwndDlg, UINT msg, WPARAM wParam DestroyWindow(hwndDlg); return TRUE; } + BOOL trusted = false; - if (fp->trust && fp->trust[0] != '\0') trusted = true; + if (fp->trust && fp->trust[0] != '\0') + trusted = true; wchar_t buff[512]; GetDlgItemText(hwndDlg, IDC_CBO_SMP_CHOOSE, buff, 255); diff --git a/plugins/MirOTR/src/options.cpp b/plugins/MirOTR/src/options.cpp index 00d94dbb36..82e210f0b4 100644 --- a/plugins/MirOTR/src/options.cpp +++ b/plugins/MirOTR/src/options.cpp @@ -122,9 +122,9 @@ void ReadPrivkeyFiles() DEBUGOUTA("READ privkey"); mir_cslock lck(lib_cs); - otrl_privkey_read(otr_user_state, _T2A(g_private_key_filename)); - otrl_privkey_read_fingerprints(otr_user_state, _T2A(g_fingerprint_store_filename), set_context_contact, nullptr); - otrl_instag_read(otr_user_state, _T2A(g_instag_filename)); + otrl_privkey_read(otr_user_state, g_private_key_filename); + otrl_privkey_read_fingerprints(otr_user_state, g_fingerprint_store_filename, set_context_contact, nullptr); + otrl_instag_read(otr_user_state, g_instag_filename); } static INT_PTR CALLBACK DlgProcMirOTROpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) @@ -418,7 +418,7 @@ static INT_PTR CALLBACK DlgProcMirOTROptsProto(HWND hwndDlg, UINT msg, WPARAM wP OtrlPrivKey *key = otrl_privkey_find(otr_user_state, proto, proto); if (key) { otrl_privkey_forget(key); - otrl_privkey_write(otr_user_state, _T2A(g_private_key_filename)); + otrl_privkey_write(otr_user_state, g_private_key_filename); ListView_SetItemText(GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS), sel, 2, L""); } } @@ -683,13 +683,13 @@ static INT_PTR CALLBACK DlgProcMirOTROptsFinger(HWND hwndDlg, UINT msg, WPARAM w // items. lvI.mask = LVIF_TEXT | LVIF_PARAM;// | LVIF_NORECOMPUTE;// | LVIF_IMAGE; - wchar_t *user, hash[45] = { 0 }; for (ConnContext *context = otr_user_state->context_root; context; context = context->next) { if (context->app_data) { - user = (wchar_t*)contact_get_nameT((UINT_PTR)context->app_data); + wchar_t *user = (wchar_t*)contact_get_nameT((UINT_PTR)context->app_data); if (user) { PROTOACCOUNT *pa = Proto_GetAccount(context->protocol); + wchar_t hash[45]; for (Fingerprint *fp = context->fingerprint_root.next; fp; fp = fp->next) { otrl_privkey_hash_to_humanT(hash, fp->fingerprint); lvI.iSubItem = 0; diff --git a/plugins/MirOTR/src/otr.cpp b/plugins/MirOTR/src/otr.cpp index a668ba63e9..bd0b7839be 100644 --- a/plugins/MirOTR/src/otr.cpp +++ b/plugins/MirOTR/src/otr.cpp @@ -39,7 +39,7 @@ static unsigned int CALLBACK generate_key_thread(void* param) { Thread_Push(nullptr); GenKeyData *data = (GenKeyData *)param; - otrl_privkey_generate(otr_user_state, _T2A(g_private_key_filename), data->proto, data->proto); + otrl_privkey_generate(otr_user_state, g_private_key_filename, data->proto, data->proto); PostMessage(data->dialog, WMU_ENDDIALOG, 0, 0); mir_free(data); Thread_Pop(); @@ -158,7 +158,7 @@ extern "C" { //CloseHandle((HANDLE)_beginthreadex(0, 0, trust_fp_thread, (void *)fp, 0, 0)); otrl_context_set_trust(fp, nullptr); - otrl_privkey_write_fingerprints(otr_user_state, _T2A(g_fingerprint_store_filename)); + otrl_privkey_write_fingerprints(otr_user_state, g_fingerprint_store_filename); } /* The list of known fingerprints has changed. Write them to disk. */ @@ -166,7 +166,7 @@ extern "C" { void otr_gui_write_fingerprints(void *) { DEBUGOUTA("OTR_GUI_WRITE_FINGERPRINTS\n"); //if(MessageBox(0, Translate("Would you like to save the current fingerprint list?"), Translate(MODULE), MB_YESNO) == IDYES) - otrl_privkey_write_fingerprints(otr_user_state, _T2A(g_fingerprint_store_filename)); + otrl_privkey_write_fingerprints(otr_user_state, g_fingerprint_store_filename); } /* A ConnContext has entered a secure state. */ diff --git a/plugins/MirOTR/src/otrlextensions.c b/plugins/MirOTR/src/otrlextensions.c index da68e73354..ddf0248bb7 100644 --- a/plugins/MirOTR/src/otrlextensions.c +++ b/plugins/MirOTR/src/otrlextensions.c @@ -55,7 +55,7 @@ static gcry_error_t account_write(FILE* privf, const char* accountname, const char* protocol, gcry_sexp_t privkey) { gcry_error_t err; - gcry_sexp_t names, protos; + gcry_sexp_t names, protos = 0; fprintf(privf, " (account\n"); @@ -97,7 +97,7 @@ gcry_error_t otrl_privkey_write_FILEp(OtrlUserState us, FILE* privf) } /* Store all keys of an OtrlUserState. */ -gcry_error_t otrl_privkey_write(OtrlUserState us, const char* filename) +gcry_error_t otrl_privkey_write(OtrlUserState us, const wchar_t *filename) { gcry_error_t err; FILE* privf; @@ -108,7 +108,7 @@ gcry_error_t otrl_privkey_write(OtrlUserState us, const char* filename) #ifndef WIN32 oldmask = umask(077); #endif - privf = fopen(filename, "w+b"); + privf = _wfopen(filename, L"w+b"); if (!privf) { #ifndef WIN32 umask(oldmask); diff --git a/plugins/MirOTR/src/otrlextensions.h b/plugins/MirOTR/src/otrlextensions.h index c0fa75c673..b53680b22a 100644 --- a/plugins/MirOTR/src/otrlextensions.h +++ b/plugins/MirOTR/src/otrlextensions.h @@ -26,10 +26,10 @@ #include <userstate.h> /* Store all keys of an OtrlUserState. */ -gcry_error_t otrl_privkey_write(OtrlUserState us, const char* filename); +gcry_error_t otrl_privkey_write(OtrlUserState us, const wchar_t *filename); /* Store all keys of an OtrlUserState. * The FILE* must be open for reading and writing. */ -gcry_error_t otrl_privkey_write_FILEp(OtrlUserState us, FILE* privf); +gcry_error_t otrl_privkey_write_FILEp(OtrlUserState us, FILE *privf); #endif diff --git a/plugins/MirOTR/src/utils.cpp b/plugins/MirOTR/src/utils.cpp index 3ef32fa1e8..cde933ab73 100644 --- a/plugins/MirOTR/src/utils.cpp +++ b/plugins/MirOTR/src/utils.cpp @@ -50,14 +50,16 @@ TrustLevel otr_context_get_trust(ConnContext *context) } /* Set verification of fingerprint */ -void VerifyFingerprint(ConnContext *context, bool verify) { +void VerifyFingerprint(ConnContext *context, bool verify) +{ lib_cs_lock(); - otrl_context_set_trust(context->active_fingerprint, (verify)?"verified":nullptr); - otrl_privkey_write_fingerprints(otr_user_state, _T2A(g_fingerprint_store_filename)); + otrl_context_set_trust(context->active_fingerprint, (verify) ? "verified" : nullptr); + otrl_privkey_write_fingerprints(otr_user_state, g_fingerprint_store_filename); VerifyFingerprintMessage(context, verify); } -void VerifyFingerprintMessage(ConnContext *context, bool verify) { +void VerifyFingerprintMessage(ConnContext *context, bool verify) +{ MCONTACT hContact = (UINT_PTR)context->app_data; wchar_t msg[1024]; @@ -72,71 +74,84 @@ void otrl_privkey_hash_to_humanT(wchar_t human[45], const unsigned char hash[20] int word, byte; wchar_t *p = human; - for(word=0; word<5; ++word) { - for(byte=0; byte<4; ++byte) { - swprintf(p, L"%02X", hash[word*4+byte]); //!!!!!!!!!!!!!! - p += 2; - } - *(p++) = ' '; + for (word = 0; word < 5; ++word) { + for (byte = 0; byte < 4; ++byte) { + swprintf(p, L"%02X", hash[word * 4 + byte]); + p += 2; + } + *(p++) = ' '; } /* Change that last ' ' to a '\0' */ --p; *p = '\0'; } -char* contact_get_id(MCONTACT hContact, bool bNameOnError) +char* contact_get_id(MCONTACT hContact) { ptrW pszUniqueID(Contact_GetInfo(CNF_UNIQUEID, hContact)); - if (!pszUniqueID && bNameOnError) + if (!pszUniqueID) pszUniqueID = mir_wstrdup(Clist_GetContactDisplayName(hContact)); - return mir_u2a(pszUniqueID); + return mir_utf8encodeW(pszUniqueID); } -__inline const wchar_t* contact_get_nameT(MCONTACT hContact) { +__inline const wchar_t* contact_get_nameT(MCONTACT hContact) +{ return Clist_GetContactDisplayName(hContact); } +char* GetDlgItemTextUtf(HWND hwndDlg, int ctrlId) +{ + wchar_t buf[1024]; + int len = GetDlgItemTextW(hwndDlg, ctrlId, buf, _countof(buf)); + buf[len] = 0; + return mir_utf8encodeW(buf); +} + wchar_t* ProtoGetNickname(const char* proto) { wchar_t *p = Contact_GetInfo(CNF_NICK, NULL, proto); return (p != nullptr) ? p : mir_wstrdup(L""); } -void ShowPopup(const wchar_t* line1, const wchar_t* line2, int timeout, const MCONTACT hContact) { - if(Miranda_IsTerminated()) return; +void ShowPopup(const wchar_t* line1, const wchar_t* line2, int timeout, const MCONTACT hContact) +{ + if (Miranda_IsTerminated()) return; - if ( !options.bHavePopups) { + if (!options.bHavePopups) { wchar_t title[256]; mir_snwprintf(title, L"%s Message", _A2W(MODULENAME)); - if(line1 && line2) { + if (line1 && line2) { int size = int(mir_wstrlen(line1) + mir_wstrlen(line2) + 3); wchar_t *message = new wchar_t[size]; // newline and null terminator mir_snwprintf(message, size, L"%s\r\n%s", line1, line2); - MessageBox( nullptr, message, title, MB_OK | MB_ICONINFORMATION ); + MessageBox(nullptr, message, title, MB_OK | MB_ICONINFORMATION); delete[] message; - } else if(line1) { - MessageBox( nullptr, line1, title, MB_OK | MB_ICONINFORMATION ); - } else if(line2) { - MessageBox( nullptr, line2, title, MB_OK | MB_ICONINFORMATION ); + } + else if (line1) { + MessageBox(nullptr, line1, title, MB_OK | MB_ICONINFORMATION); + } + else if (line2) { + MessageBox(nullptr, line2, title, MB_OK | MB_ICONINFORMATION); } return; } - POPUPDATAW ppd = {0}; + POPUPDATAW ppd = { 0 }; //memset((void *)&ppd, 0, sizeof(POPUPDATAW)); ppd.lchContact = hContact; ppd.lchIcon = nullptr; - if(line1 && line2) { - wcsncpy( ppd.lpwzContactName, line1, MAX_CONTACTNAME-1 ); - wcsncpy( ppd.lpwzText, line2, MAX_SECONDLINE-1 ); - } else if(line1) - wcsncpy( ppd.lpwzText, line1, MAX_SECONDLINE-1 ); - else if(line2) - wcsncpy( ppd.lpwzText, line2, MAX_SECONDLINE-1 ); + if (line1 && line2) { + wcsncpy(ppd.lpwzContactName, line1, MAX_CONTACTNAME - 1); + wcsncpy(ppd.lpwzText, line2, MAX_SECONDLINE - 1); + } + else if (line1) + wcsncpy(ppd.lpwzText, line1, MAX_SECONDLINE - 1); + else if (line2) + wcsncpy(ppd.lpwzText, line2, MAX_SECONDLINE - 1); ppd.iSeconds = timeout; @@ -147,16 +162,17 @@ void ShowPopup(const wchar_t* line1, const wchar_t* line2, int timeout, const MC } -void ShowWarning(wchar_t *msg) { +void ShowWarning(wchar_t *msg) +{ wchar_t buffer[512]; ErrorDisplay disp = options.err_method; // funny logic :) ... try to avoid message boxes // if want popups but no popups, try baloons - if(disp == ED_POP && !options.bHavePopups) + if (disp == ED_POP && !options.bHavePopups) disp = ED_BAL; mir_snwprintf(buffer, L"%s Warning", _A2W(MODULENAME)); - + switch (disp) { case ED_POP: { @@ -176,12 +192,13 @@ void ShowWarning(wchar_t *msg) { } } -void ShowError(wchar_t *msg) { +void ShowError(wchar_t *msg) +{ wchar_t buffer[512]; ErrorDisplay disp = options.err_method; // funny logic :) ... try to avoid message boxes // if want popups but no popups, try baloons - if(disp == ED_POP && !options.bHavePopups) + if (disp == ED_POP && !options.bHavePopups) disp = ED_BAL; mir_snwprintf(buffer, L"%s Error", _A2W(MODULENAME)); @@ -207,7 +224,8 @@ void ShowError(wchar_t *msg) { } -void ShowPopupUtf(const char* line1, const char* line2, int timeout, const MCONTACT hContact) { +void ShowPopupUtf(const char* line1, const char* line2, int timeout, const MCONTACT hContact) +{ wchar_t* l1 = (line1) ? mir_utf8decodeW(line1) : nullptr; wchar_t* l2 = (line2) ? mir_utf8decodeW(line2) : nullptr; ShowPopup(l1, l2, timeout, hContact); @@ -215,71 +233,79 @@ void ShowPopupUtf(const char* line1, const char* line2, int timeout, const MCONT if (l2) mir_free(l2); } -void ShowWarningUtf(char* msg) { +void ShowWarningUtf(char* msg) +{ wchar_t* m = (msg) ? mir_utf8decodeW(msg) : nullptr; ShowWarning(m); if (m) mir_free(m); } -void ShowErrorUtf(char* msg) { +void ShowErrorUtf(char* msg) +{ wchar_t* m = (msg) ? mir_utf8decodeW(msg) : nullptr; ShowError(m); if (m) mir_free(m); } -void ShowMessageInline(const MCONTACT hContact, const wchar_t *msg) { +void ShowMessageInline(const MCONTACT hContact, const wchar_t *msg) +{ wchar_t buff[1024]; mir_snwprintf(buff, L"%s%s", _A2W(LANG_INLINE_PREFIX), msg); T2Utf utf(buff); - PROTORECVEVENT pre = {0}; + PROTORECVEVENT pre = { 0 }; pre.timestamp = time(0); pre.szMessage = utf; pre.flags = PREF_BYPASS_OTR; - ProtoChainRecvMsg(hContact, &pre); + ProtoChainRecvMsg(hContact, &pre); } -void ShowMessageInlineUtf(const MCONTACT hContact, const char *msg) { +void ShowMessageInlineUtf(const MCONTACT hContact, const char *msg) +{ char buff[1024]; mir_snprintf(buff, "%s%s", LANG_INLINE_PREFIX, msg); - PROTORECVEVENT pre = {0}; + PROTORECVEVENT pre = { 0 }; pre.timestamp = time(0); pre.szMessage = buff; pre.flags = PREF_BYPASS_OTR; ProtoChainRecvMsg(hContact, &pre); } -void ShowMessageUtf(const MCONTACT hContact, const char *msg) { - if(options.msg_inline) +void ShowMessageUtf(const MCONTACT hContact, const char *msg) +{ + if (options.msg_inline) ShowMessageInlineUtf(hContact, msg); - if(options.msg_popup) + if (options.msg_popup) ShowPopupUtf(Translate(LANG_OTR_INFO), msg, 0, hContact); } -void ShowMessage(const MCONTACT hContact, const wchar_t *msg) { - if(options.msg_inline) +void ShowMessage(const MCONTACT hContact, const wchar_t *msg) +{ + if (options.msg_inline) ShowMessageInline(hContact, msg); - if(options.msg_popup) + if (options.msg_popup) ShowPopup(TranslateT(LANG_OTR_INFO), msg, 0, hContact); } -const wchar_t *policy_to_string(OtrlPolicy policy) { +const wchar_t *policy_to_string(OtrlPolicy policy) +{ switch (policy) { - case OTRL_POLICY_NEVER: - return TranslateW(LANG_POLICY_NEVER); - case OTRL_POLICY_OPPORTUNISTIC: - return TranslateW(LANG_POLICY_OPP); - case OTRL_POLICY_MANUAL: - case OTRL_POLICY_MANUAL_MOD: - return TranslateW(LANG_POLICY_MANUAL); - case OTRL_POLICY_ALWAYS: - return TranslateW(LANG_POLICY_ALWAYS); - default: - return TranslateW(LANG_POLICY_DEFAULT); + case OTRL_POLICY_NEVER: + return TranslateW(LANG_POLICY_NEVER); + case OTRL_POLICY_OPPORTUNISTIC: + return TranslateW(LANG_POLICY_OPP); + case OTRL_POLICY_MANUAL: + case OTRL_POLICY_MANUAL_MOD: + return TranslateW(LANG_POLICY_MANUAL); + case OTRL_POLICY_ALWAYS: + return TranslateW(LANG_POLICY_ALWAYS); + default: + return TranslateW(LANG_POLICY_DEFAULT); } } -OtrlPolicy policy_from_string(const wchar_t *polstring) { +OtrlPolicy policy_from_string(const wchar_t *polstring) +{ if (mir_wstrcmp(polstring, TranslateW(LANG_POLICY_NEVER)) == 0) return OTRL_POLICY_NEVER; else if (mir_wstrcmp(polstring, TranslateW(LANG_POLICY_OPP)) == 0) @@ -288,6 +314,6 @@ OtrlPolicy policy_from_string(const wchar_t *polstring) { return OTRL_POLICY_MANUAL_MOD; else if (mir_wstrcmp(polstring, TranslateW(LANG_POLICY_ALWAYS)) == 0) return OTRL_POLICY_ALWAYS; - else + else return CONTACT_DEFAULT_POLICY; } diff --git a/plugins/MirOTR/src/utils.h b/plugins/MirOTR/src/utils.h index 52d6f0775d..17dc74d758 100644 --- a/plugins/MirOTR/src/utils.h +++ b/plugins/MirOTR/src/utils.h @@ -19,12 +19,13 @@ void VerifyFingerprintMessage(ConnContext *context, bool verify); void otrl_privkey_hash_to_humanT(wchar_t human[45], const unsigned char hash[20]); -char* contact_get_id(MCONTACT hContact, bool bNameOnError=true); -__inline const char* contact_get_account(MCONTACT hContact); +char* contact_get_id(MCONTACT hContact); extern __inline const wchar_t* contact_get_nameT(MCONTACT hContact); wchar_t* ProtoGetNickname(const char* proto); +char* GetDlgItemTextUtf(HWND hwndDlg, int ctrlId); + void ShowPopup(const wchar_t* line1, const wchar_t* line2, int timeout, const MCONTACT hContact = NULL); void ShowWarning(wchar_t* msg); void ShowError(wchar_t* msg); |