summaryrefslogtreecommitdiff
path: root/plugins/SecureIM/crypt_check.cpp
diff options
context:
space:
mode:
authorVadim Dashevskiy <watcherhd@gmail.com>2012-05-15 10:38:20 +0000
committerVadim Dashevskiy <watcherhd@gmail.com>2012-05-15 10:38:20 +0000
commit48540940b6c28bb4378abfeb500ec45a625b37b6 (patch)
tree2ef294c0763e802f91d868bdef4229b6868527de /plugins/SecureIM/crypt_check.cpp
parent5c350913f011e119127baeb32a6aedeb4f0d33bc (diff)
initial commit
git-svn-id: http://svn.miranda-ng.org/main/trunk@2 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/SecureIM/crypt_check.cpp')
-rw-r--r--plugins/SecureIM/crypt_check.cpp267
1 files changed, 267 insertions, 0 deletions
diff --git a/plugins/SecureIM/crypt_check.cpp b/plugins/SecureIM/crypt_check.cpp
new file mode 100644
index 0000000000..a8e3ba573f
--- /dev/null
+++ b/plugins/SecureIM/crypt_check.cpp
@@ -0,0 +1,267 @@
+#include "commonheaders.h"
+
+
+int getContactStatus(HANDLE hContact) {
+
+ pSupPro ptr = getSupPro(hContact);
+ if (ptr)
+ return DBGetContactSettingWord(hContact, ptr->name, "Status", ID_STATUS_OFFLINE);
+
+ return -1;
+}
+
+
+BOOL isSecureProtocol(HANDLE hContact) {
+
+ pSupPro ptr = getSupPro(hContact);
+ if(!ptr) return false;
+
+ return ptr->inspecting;
+}
+
+
+BYTE isContactSecured(HANDLE hContact) {
+ // нужна проверка на Offline и в этом случае другие статусы
+ if (!clist_cnt) return 0;
+
+ BYTE r=0;
+ if( isProtoMetaContacts(hContact) )
+ hContact = getMostOnline(hContact); // возьмем тот, через который пойдет сообщение
+
+ for(int j=0;j<clist_cnt;j++) {
+ if( clist[j].hContact == hContact ) {
+ if( !clist[j].proto->inspecting ) break;
+ DBVARIANT dbv;
+ r=clist[j].mode;
+ switch(r) {
+ case MODE_NATIVE:
+ if(cpp_keyx(clist[j].cntx)!=0) r|=SECURED;
+ break;
+ case MODE_PGP:
+ DBGetContactSetting(hContact,szModuleName,"pgp",&dbv);
+ if( dbv.type!=0 ) r|=SECURED;
+ DBFreeVariant(&dbv);
+ break;
+ case MODE_GPG:
+ DBGetContactSetting(hContact,szModuleName,"gpg",&dbv);
+ if( dbv.type!=0 ) r|=SECURED;
+ DBFreeVariant(&dbv);
+ break;
+ case MODE_RSAAES:
+ if(exp->rsa_get_state(clist[j].cntx)==7) r|=SECURED;
+ break;
+ case MODE_RSA:
+ if(clist[j].cntx) r|=SECURED;
+ break;
+ }
+ break;
+ }
+ }
+ return r; // (mode&SECURED) - проверка на EST/DIS
+}
+
+
+BOOL isClientMiranda(pUinKey ptr, BOOL emptyMirverAsMiranda) {
+
+ if( !bMCD ) return true;
+ if( !ptr->proto->inspecting ) return false;
+
+ BOOL isMiranda = true;
+ LPSTR mirver = myDBGetString(ptr->hContact,ptr->proto->name,"MirVer");
+ if( mirver ) {
+ isMiranda = (emptyMirverAsMiranda && !*mirver) || (strstr(mirver,"Miranda")!=NULL);
+ mir_free(mirver);
+ }
+ return isMiranda;
+}
+
+
+BOOL isClientMiranda(HANDLE hContact, BOOL emptyMirverAsMiranda) {
+
+ if( !bMCD ) return true;
+ if( !clist_cnt ) return false;
+
+ for(int j=0;j<clist_cnt;j++) {
+ if( clist[j].hContact == hContact ) {
+ return isClientMiranda(&clist[j],emptyMirverAsMiranda);
+ }
+ }
+ return false;
+}
+
+
+BOOL isProtoSmallPackets(HANDLE hContact) {
+
+ if (!clist_cnt) return false;
+ for(int j=0;j<clist_cnt;j++) {
+ if( clist[j].hContact == hContact ) {
+ if( !clist[j].proto->inspecting ) break;
+ return strstr(clist[j].proto->name,"IRC")!=NULL ||
+ strstr(clist[j].proto->name,"WinPopup")!=NULL ||
+ strstr(clist[j].proto->name,"VyChat")!=NULL;
+ }
+ }
+ return false;
+}
+
+
+BOOL isContactInvisible(HANDLE hContact) {
+
+ if( !DBGetContactSettingByte(hContact,"CList","Hidden",0) ) {
+ if( !clist_cnt ) return false;
+ for(int j=0;j<clist_cnt;j++) {
+ if( clist[j].hContact == hContact ) {
+ if( !clist[j].proto->inspecting ) return false;
+ if( clist[j].waitForExchange ) return false;
+ switch( (int)DBGetContactSettingWord(hContact,clist[j].proto->name,"ApparentMode",0) ) {
+ case 0:
+ return (CallProtoService(clist[j].proto->name,PS_GETSTATUS,0,0)==ID_STATUS_INVISIBLE);
+ case ID_STATUS_ONLINE:
+ return false;
+ case ID_STATUS_OFFLINE:
+ return true;
+ } //switch
+ break;
+ }
+ }// for
+ }
+ return true;
+}
+
+
+BOOL isNotOnList(HANDLE hContact) {
+ return DBGetContactSettingByte(hContact, "CList", "NotOnList", 0);
+}
+
+
+BOOL isContactNewPG(HANDLE hContact) {
+
+ if (!clist_cnt) return false;
+ for(int j=0;j<clist_cnt;j++) {
+ if (clist[j].hContact == hContact) {
+ if( !clist[j].proto->inspecting ) break;
+ if( !clist[j].cntx ) break;
+ return (clist[j].features & CPP_FEATURES_NEWPG) != 0;
+ }
+ }
+ return false;
+}
+
+
+BOOL isContactPGP(HANDLE hContact) {
+
+ if(!bPGPloaded || (!bPGPkeyrings && !bPGPprivkey)) return false;
+ if (!clist_cnt) return false;
+ for(int j=0;j<clist_cnt;j++) {
+ if (clist[j].hContact == hContact) {
+ if( !clist[j].proto->inspecting ) break;
+ if( clist[j].mode!=MODE_PGP ) break;
+ DBVARIANT dbv;
+ DBGetContactSetting(hContact,szModuleName,"pgp",&dbv);
+ BOOL r=(dbv.type!=0);
+ DBFreeVariant(&dbv);
+ return r;
+ }
+ }
+ return false;
+}
+
+
+BOOL isContactGPG(HANDLE hContact) {
+
+ if(!bGPGloaded || !bGPGkeyrings) return false;
+ if (!clist_cnt) return false;
+ for(int j=0;j<clist_cnt;j++) {
+ if (clist[j].hContact == hContact) {
+ if( !clist[j].proto->inspecting ) break;
+ if( clist[j].mode!=MODE_GPG ) break;
+ DBVARIANT dbv;
+ DBGetContactSetting(hContact,szModuleName,"gpg",&dbv);
+ BOOL r=(dbv.type!=0);
+ DBFreeVariant(&dbv);
+ return r;
+ }
+ }
+ return false;
+}
+
+
+BOOL isContactRSAAES(HANDLE hContact) {
+
+ if (!clist_cnt) return false;
+ for(int j=0;j<clist_cnt;j++) {
+ if (clist[j].hContact == hContact) {
+ if( !clist[j].proto->inspecting ) break;
+ if( clist[j].mode!=MODE_RSAAES ) break;
+ return true;
+ }
+ }
+ return false;
+}
+
+
+BOOL isContactRSA(HANDLE hContact) {
+
+ if (!clist_cnt) return false;
+ for(int j=0;j<clist_cnt;j++) {
+ if (clist[j].hContact == hContact) {
+ if( !clist[j].proto->inspecting ) break;
+ if( clist[j].mode!=MODE_RSA ) break;
+ return true;
+ }
+ }
+ return false;
+}
+
+
+BOOL isChatRoom(HANDLE hContact) {
+
+ if (!clist_cnt) return false;
+ for(int j=0;j<clist_cnt;j++) {
+ if( clist[j].hContact == hContact ) {
+ if( !clist[j].proto->inspecting ) break;
+ return (DBGetContactSettingByte(hContact,clist[j].proto->name,"ChatRoom",0)!=0);
+ }
+ }
+ return false;
+}
+
+
+BOOL isFileExist(LPCSTR filename) {
+ return (GetFileAttributes(filename)!=(UINT)-1);
+}
+
+
+BOOL isSecureIM(pUinKey ptr, BOOL emptyMirverAsSecureIM) {
+
+ if( !bAIP ) return false;
+ if( !ptr->proto->inspecting ) return false;
+
+ BOOL isSecureIM = false;
+ if( bNOL && DBGetContactSettingByte(ptr->hContact,"CList","NotOnList",0) ) {
+ return false;
+ }
+ LPSTR mirver = myDBGetString(ptr->hContact,ptr->proto->name,"MirVer");
+ if( mirver ) {
+ isSecureIM = (emptyMirverAsSecureIM && !*mirver) || (strstr(mirver,"SecureIM")!=NULL) || (strstr(mirver,"secureim")!=NULL);
+ mir_free(mirver);
+ }
+ return isSecureIM;
+}
+
+
+BOOL isSecureIM(HANDLE hContact, BOOL emptyMirverAsSecureIM) {
+
+ if( !bAIP ) return false;
+ if( !clist_cnt ) return false;
+
+ for(int j=0;j<clist_cnt;j++) {
+ if (clist[j].hContact == hContact) {
+ return isSecureIM(&clist[j],emptyMirverAsSecureIM);
+ }
+ }
+ return false;
+}
+
+
+// EOF