// decode message LPSTR decodeMsg(pUinKey ptr, LPARAM lParam, LPSTR szEncMsg) { CCSDATA *pccsd = (CCSDATA *)lParam; PROTORECVEVENT *ppre = (PROTORECVEVENT *)pccsd->lParam; LPSTR szNewMsg = NULL; LPSTR szOldMsg = (ppre->flags&PREF_UTF)?cpp_decodeU(ptr->cntx,szEncMsg):cpp_decode(ptr->cntx,szEncMsg); if(szOldMsg == NULL) { ptr->decoded=false; switch(cpp_get_error(ptr->cntx)) { case CPP_ERROR_BAD_LEN: szNewMsg = mir_strdup(Translate(sim102)); break; case CPP_ERROR_BAD_CRC: szNewMsg = mir_strdup(Translate(sim103)); break; default: { ptr->decoded=true; szNewMsg = mir_strdup(Translate(sim101)); } break; } ppre->flags &= ~(PREF_UNICODE|PREF_UTF); pccsd->wParam &= ~(PREF_UNICODE|PREF_UTF); } else { ptr->decoded=true; if( ppre->flags & PREF_UTF ) { // если протокол поддерживает utf8 - тогда отправляем в utf8 int olen = strlen(szOldMsg)+1; szNewMsg = (LPSTR) mir_alloc(olen); memcpy(szNewMsg,szOldMsg,olen); } else { int olen = (strlen(szOldMsg)+1)*(sizeof(WCHAR)+1); szNewMsg = (LPSTR) mir_alloc(olen); memcpy(szNewMsg,szOldMsg,olen); ppre->flags |= PREF_UNICODE; pccsd->wParam |= PREF_UNICODE; } } ppre->szMessage = szNewMsg; return szNewMsg; }
// store KeyB into context int InitKeyB(pUinKey ptr,LPCSTR key) { Sent_NetLog("InitKeyB: %s", key); if (!ptr->cntx) ptr->cntx = cpp_create_context(isProtoSmallPackets(ptr->hContact)?CPP_MODE_BASE64:0); if (!cpp_keyp(ptr->cntx)) { char *tmp = db_get_sa(ptr->hContact,MODULENAME,"PSK"); if (tmp) { cpp_init_keyp(ptr->cntx,tmp); // make pre-shared key from password mir_free(tmp); } } cpp_init_keyb(ptr->cntx,key); ptr->features = cpp_get_features(ptr->cntx); return cpp_get_error(ptr->cntx); }
// store KeyB into context int InitKeyB(pUinKey ptr,LPCSTR key) { #if defined(_DEBUG) || defined(NETLIB_LOG) Sent_NetLog("InitKeyB: %s", key); #endif if(!ptr->cntx) ptr->cntx = cpp_create_context(isProtoSmallPackets(ptr->hContact)?CPP_MODE_BASE64:0); if(!cpp_keyp(ptr->cntx)) { char *tmp = myDBGetString(ptr->hContact,szModuleName,"PSK"); if(tmp) { cpp_init_keyp(ptr->cntx,tmp); // make pre-shared key from password mir_free(tmp); } } cpp_init_keyb(ptr->cntx,key); ptr->features = cpp_get_features(ptr->cntx); return cpp_get_error(ptr->cntx); }