diff options
Diffstat (limited to 'MirOTR/utils.cpp')
-rw-r--r-- | MirOTR/utils.cpp | 204 |
1 files changed, 102 insertions, 102 deletions
diff --git a/MirOTR/utils.cpp b/MirOTR/utils.cpp index 6fe6dde..3d3a505 100644 --- a/MirOTR/utils.cpp +++ b/MirOTR/utils.cpp @@ -1,24 +1,24 @@ -#include "stdafx.h" -#include "utils.h" - -CRITICAL_SECTION lib_cs; - -void InitUtils() { - InitializeCriticalSection(&lib_cs); -} -void DeinitUtils() { - DeleteCriticalSection(&lib_cs); -} - +#include "stdafx.h"
+#include "utils.h"
+
+CRITICAL_SECTION lib_cs;
+
+void InitUtils() {
+ InitializeCriticalSection(&lib_cs);
+}
+void DeinitUtils() {
+ DeleteCriticalSection(&lib_cs);
+}
+
void lib_cs_lock() {
EnterCriticalSection(&lib_cs);
}
void lib_cs_unlock() {
LeaveCriticalSection(&lib_cs);
-} - -HANDLE find_contact(const char* userid, const char* protocol) { +}
+
+HANDLE find_contact(const char* userid, const char* protocol) {
HANDLE hContact = ( HANDLE )CallService( MS_DB_CONTACT_FINDFIRST, 0, 0 );
while ( hContact != NULL )
{
@@ -34,79 +34,79 @@ HANDLE find_contact(const char* userid, const char* protocol) { hContact = ( HANDLE )CallService( MS_DB_CONTACT_FINDNEXT,( WPARAM )hContact, 0 );
}
- return 0; -} - -/* Look up a connection context by hContact from the given -* OtrlUserState. If add_if_missing is true, allocate and return a new -* context if one does not currently exist. In that event, call -* add_app_data(data, context) so that app_data and app_data_free can be -* filled in by the application, and set *addedp to 1. */ -ConnContext * otrl_context_find_miranda(OtrlUserState us, HANDLE hContact) -{ - ConnContext ** curp; - if (!hContact) return NULL; - for (curp = &(us->context_root); *curp; curp = &((*curp)->next)) { - if ((*curp)->app_data == hContact ) return *curp; - } - return NULL; -} - -/* What level of trust do we have in the privacy of this ConnContext? */ -TrustLevel otr_context_get_trust(ConnContext *context) -{ - TrustLevel level = TRUST_NOT_PRIVATE; - - if (context && context->msgstate == OTRL_MSGSTATE_ENCRYPTED) { - if (context->active_fingerprint->trust && - context->active_fingerprint->trust[0] != '\0') { - level = TRUST_PRIVATE; - } else { - level = TRUST_UNVERIFIED; - } - } else if (context && context->msgstate == OTRL_MSGSTATE_FINISHED) { - level = TRUST_FINISHED; - } - - return level; -} - -/* Set verification of fingerprint */ + return 0;
+}
+
+/* Look up a connection context by hContact from the given
+* OtrlUserState. If add_if_missing is true, allocate and return a new
+* context if one does not currently exist. In that event, call
+* add_app_data(data, context) so that app_data and app_data_free can be
+* filled in by the application, and set *addedp to 1. */
+ConnContext * otrl_context_find_miranda(OtrlUserState us, HANDLE hContact)
+{
+ ConnContext ** curp;
+ if (!hContact) return NULL;
+ for (curp = &(us->context_root); *curp; curp = &((*curp)->next)) {
+ if ((*curp)->app_data == hContact ) return *curp;
+ }
+ return NULL;
+}
+
+/* What level of trust do we have in the privacy of this ConnContext? */
+TrustLevel otr_context_get_trust(ConnContext *context)
+{
+ TrustLevel level = TRUST_NOT_PRIVATE;
+
+ if (context && context->msgstate == OTRL_MSGSTATE_ENCRYPTED) {
+ if (context->active_fingerprint->trust &&
+ context->active_fingerprint->trust[0] != '\0') {
+ level = TRUST_PRIVATE;
+ } else {
+ level = TRUST_UNVERIFIED;
+ }
+ } else if (context && context->msgstate == OTRL_MSGSTATE_FINISHED) {
+ level = TRUST_FINISHED;
+ }
+
+ return level;
+}
+
+/* Set verification of fingerprint */
void VerifyFingerprint(ConnContext *context, bool verify) {
lib_cs_lock();
otrl_context_set_trust(context->active_fingerprint, (verify)?"verified":NULL);
otrl_privkey_write_fingerprints(otr_user_state, g_fingerprint_store_filename);
lib_cs_unlock();
VerifyFingerprintMessage(context, verify);
-} - -void VerifyFingerprintMessage(ConnContext *context, bool verify) { - TCHAR msg[1024]; +}
+
+void VerifyFingerprintMessage(ConnContext *context, bool verify) {
+ TCHAR msg[1024];
mir_sntprintf(msg, 1024, (verify)?TranslateT(LANG_FINGERPRINT_VERIFIED):TranslateT(LANG_FINGERPRINT_NOT_VERIFIED), contact_get_nameT((HANDLE)context->app_data));
msg[1023] = '\0';
ShowMessage((HANDLE)context->app_data, msg);
- SetEncryptionStatus(context->app_data, otr_context_get_trust(context)); -} - -/* Convert a 20-byte hash value to a 45-byte human-readable value */ -void otrl_privkey_hash_to_humanT(TCHAR human[45], const unsigned char hash[20]) -{ - int word, byte; - TCHAR *p = human; - - for(word=0; word<5; ++word) { - for(byte=0; byte<4; ++byte) { - _stprintf(p, _T("%02X"), hash[word*4+byte]); - p += 2; - } - *(p++) = ' '; - } - /* Change that last ' ' to a '\0' */ - --p; - *p = '\0'; -} - -char* contact_get_id(HANDLE hContact, bool bNameOnError) { + SetEncryptionStatus(context->app_data, otr_context_get_trust(context));
+}
+
+/* Convert a 20-byte hash value to a 45-byte human-readable value */
+void otrl_privkey_hash_to_humanT(TCHAR human[45], const unsigned char hash[20])
+{
+ int word, byte;
+ TCHAR *p = human;
+
+ for(word=0; word<5; ++word) {
+ for(byte=0; byte<4; ++byte) {
+ _stprintf(p, _T("%02X"), hash[word*4+byte]);
+ p += 2;
+ }
+ *(p++) = ' ';
+ }
+ /* Change that last ' ' to a '\0' */
+ --p;
+ *p = '\0';
+}
+
+char* contact_get_id(HANDLE hContact, bool bNameOnError) {
char* pszUniqueID = NULL;
CONTACTINFO ci;
ZeroMemory(&ci, sizeof(ci));
@@ -131,29 +131,29 @@ char* contact_get_id(HANDLE hContact, bool bNameOnError) { if (pszUniqueID)
mir_snprintf(pszUniqueID, 15, ("%u"), ci.bVal);
}
- } - if (!pszUniqueID && bNameOnError) { - char *name = (char *)CallService( MS_CLIST_GETCONTACTDISPLAYNAME, ( WPARAM )hContact, 0 ); - if (name) pszUniqueID = mir_strdup(name); - } - return pszUniqueID; -} - -__inline const TCHAR* contact_get_nameT(HANDLE hContact) { - return (TCHAR*)CallService( MS_CLIST_GETCONTACTDISPLAYNAME, ( WPARAM )hContact, GCDNF_TCHAR ); -} - -__inline const char* contact_get_proto(HANDLE hContact) { - char *uproto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0); - return uproto; -} - -__inline const char* contact_get_account(HANDLE hContact) { - char *uacc = (char *)CallService(MS_PROTO_GETCONTACTBASEACCOUNT, (WPARAM)hContact, 0); - return uacc; -} - -void ShowPopup(const TCHAR* line1, const TCHAR* line2, int timeout, const HANDLE hContact) { + }
+ if (!pszUniqueID && bNameOnError) {
+ char *name = (char *)CallService( MS_CLIST_GETCONTACTDISPLAYNAME, ( WPARAM )hContact, 0 );
+ if (name) pszUniqueID = mir_strdup(name);
+ }
+ return pszUniqueID;
+}
+
+__inline const TCHAR* contact_get_nameT(HANDLE hContact) {
+ return (TCHAR*)CallService( MS_CLIST_GETCONTACTDISPLAYNAME, ( WPARAM )hContact, GCDNF_TCHAR );
+}
+
+__inline const char* contact_get_proto(HANDLE hContact) {
+ char *uproto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0);
+ return uproto;
+}
+
+__inline const char* contact_get_account(HANDLE hContact) {
+ char *uacc = (char *)CallService(MS_PROTO_GETCONTACTBASEACCOUNT, (WPARAM)hContact, 0);
+ return uacc;
+}
+
+void ShowPopup(const TCHAR* line1, const TCHAR* line2, int timeout, const HANDLE hContact) {
if(CallService(MS_SYSTEM_TERMINATED, 0, 0)) return;
if ( !options.bHavePopups) {
|