static INT_PTR GetContactSetting(WPARAM wParam, LPARAM lParam) { DBCONTACTGETSETTING* dgs = ( DBCONTACTGETSETTING* )lParam; dgs->pValue->type = 0; if ( GetContactSettingWorker(( HANDLE )wParam, dgs, 0 )) return 1; if ( dgs->pValue->type == DBVT_UTF8 ) { WCHAR* tmp = NULL; char* p = NEWSTR_ALLOCA(dgs->pValue->pszVal); if ( mir_utf8decode( p, &tmp ) != NULL ) { BOOL bUsed = FALSE; int result = WideCharToMultiByte( mirCp, WC_NO_BEST_FIT_CHARS, tmp, -1, NULL, 0, NULL, &bUsed ); mir_free( dgs->pValue->pszVal ); if ( bUsed || result == 0 ) { dgs->pValue->type = DBVT_WCHAR; dgs->pValue->pwszVal = tmp; } else { dgs->pValue->type = DBVT_ASCIIZ; dgs->pValue->pszVal = mir_alloc( result ); WideCharToMultiByte( mirCp, WC_NO_BEST_FIT_CHARS, tmp, -1, dgs->pValue->pszVal, result, NULL, NULL ); mir_free( tmp ); } } else { dgs->pValue->type = DBVT_ASCIIZ; mir_free( tmp ); } } return 0; }
STDMETHODIMP_(BOOL) CDb3Mmap::GetContactSetting(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv) { dbv->type = 0; if (GetContactSettingWorker(contactID, szModule, szSetting, dbv, 0)) return 1; if (dbv->type == DBVT_UTF8) { WCHAR *tmp = NULL; char *p = NEWSTR_ALLOCA(dbv->pszVal); if (mir_utf8decode(p, &tmp) != NULL) { BOOL bUsed = FALSE; int result = WideCharToMultiByte(m_codePage, WC_NO_BEST_FIT_CHARS, tmp, -1, NULL, 0, NULL, &bUsed); mir_free(dbv->pszVal); if (bUsed || result == 0) { dbv->type = DBVT_WCHAR; dbv->pwszVal = tmp; } else { dbv->type = DBVT_ASCIIZ; dbv->pszVal = (char *)mir_alloc(result); WideCharToMultiByte(m_codePage, WC_NO_BEST_FIT_CHARS, tmp, -1, dbv->pszVal, result, NULL, NULL); mir_free(tmp); } } else { dbv->type = DBVT_ASCIIZ; mir_free(tmp); } } return 0; }
static INT_PTR GetContactSettingStr(WPARAM wParam, LPARAM lParam) { DBCONTACTGETSETTING* dgs = (DBCONTACTGETSETTING*)lParam; int iSaveType = dgs->pValue->type; if ( GetContactSettingWorker(( HANDLE )wParam, dgs, 0 )) return 1; if ( iSaveType == 0 || iSaveType == dgs->pValue->type ) return 0; if ( dgs->pValue->type != DBVT_ASCIIZ && dgs->pValue->type != DBVT_UTF8 ) return 1; if ( iSaveType == DBVT_WCHAR ) { if ( dgs->pValue->type != DBVT_UTF8 ) { int len = MultiByteToWideChar( CP_ACP, 0, dgs->pValue->pszVal, -1, NULL, 0 ); wchar_t* wszResult = ( wchar_t* )mir_alloc(( len+1 )*sizeof( wchar_t )); if ( wszResult == NULL ) return 1; MultiByteToWideChar( CP_ACP, 0, dgs->pValue->pszVal, -1, wszResult, len ); wszResult[ len ] = 0; mir_free( dgs->pValue->pszVal ); dgs->pValue->pwszVal = wszResult; } else { char* savePtr = NEWSTR_ALLOCA(dgs->pValue->pszVal); mir_free( dgs->pValue->pszVal ); if ( !mir_utf8decode( savePtr, &dgs->pValue->pwszVal )) return 1; } } else if ( iSaveType == DBVT_UTF8 ) { char* tmpBuf = mir_utf8encode( dgs->pValue->pszVal ); if ( tmpBuf == NULL ) return 1; mir_free( dgs->pValue->pszVal ); dgs->pValue->pszVal = tmpBuf; } else if ( iSaveType == DBVT_ASCIIZ ) mir_utf8decode( dgs->pValue->pszVal, NULL ); dgs->pValue->type = iSaveType; return 0; }
STDMETHODIMP_(BOOL) CDb3Mmap::GetContactSettingStr(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv) { int iSaveType = dbv->type; if (GetContactSettingWorker(contactID, szModule, szSetting, dbv, 0)) return 1; if (iSaveType == 0 || iSaveType == dbv->type) return 0; if (dbv->type != DBVT_ASCIIZ && dbv->type != DBVT_UTF8) return 1; if (iSaveType == DBVT_WCHAR) { if (dbv->type != DBVT_UTF8) { int len = MultiByteToWideChar(CP_ACP, 0, dbv->pszVal, -1, NULL, 0); wchar_t* wszResult = (wchar_t*)mir_alloc((len + 1)*sizeof(wchar_t)); if (wszResult == NULL) return 1; MultiByteToWideChar(CP_ACP, 0, dbv->pszVal, -1, wszResult, len); wszResult[len] = 0; mir_free(dbv->pszVal); dbv->pwszVal = wszResult; } else { char* savePtr = NEWSTR_ALLOCA(dbv->pszVal); mir_free(dbv->pszVal); if (!mir_utf8decode(savePtr, &dbv->pwszVal)) return 1; } } else if (iSaveType == DBVT_UTF8) { char* tmpBuf = mir_utf8encode(dbv->pszVal); if (tmpBuf == NULL) return 1; mir_free(dbv->pszVal); dbv->pszVal = tmpBuf; } else if (iSaveType == DBVT_ASCIIZ) mir_utf8decode(dbv->pszVal, NULL); dbv->type = iSaveType; return 0; }
STDMETHODIMP_(BOOL) CDb3Mmap::GetContactSettingStatic(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv) { if (GetContactSettingWorker(contactID, szModule, szSetting, dbv, 1)) return 1; if (dbv->type == DBVT_UTF8) { mir_utf8decode(dbv->pszVal, NULL); dbv->type = DBVT_ASCIIZ; } return 0; }
INT_PTR GetContactSettingStatic(WPARAM wParam, LPARAM lParam) { DBCONTACTGETSETTING* dgs = (DBCONTACTGETSETTING*)lParam; if ( GetContactSettingWorker(( HANDLE )wParam, dgs, 1 )) return 1; if ( dgs->pValue->type == DBVT_UTF8 ) { mir_utf8decode( dgs->pValue->pszVal, NULL ); dgs->pValue->type = DBVT_ASCIIZ; } return 0; }
TCHAR* CJabberProto::JGetStringCrypt( HANDLE hContact, char* valueName ) { DBVARIANT dbv; if (DBGetContactSettingString( hContact, m_szModuleName, valueName, &dbv )) return NULL; sttCryptString(dbv.pszVal); #ifdef UNICODE WCHAR *res = mir_utf8decodeW(dbv.pszVal); #else mir_utf8decode(dbv.pszVal, NULL); char *res = mir_strdup(dbv.pszVal); #endif DBFreeVariant(&dbv); return res; }
MIRANDA_HOOK_EVENT(ME_DB_EVENT_FILTER_ADD, w, l) { MCONTACT hContact = (MCONTACT)w; if (!l) //fix potential DEP crash return 0; DBEVENTINFO * dbei = (DBEVENTINFO*)l; // if event is in protocol that is not despammed if (!ProtoInList(dbei->szModule)) { // ...let the event go its way return 0; } //do not check excluded contact if (db_get_b(hContact, pluginName, "Answered", 0)) return 0; if (db_get_b(hContact, pluginName, "Excluded", 0)) { if (!db_get_b(hContact, "CList", "NotOnList", 0)) db_unset(hContact, pluginName, "Excluded"); return 0; } //we want block not only messages, i seen many types other eventtype flood if (dbei->flags & DBEF_READ) // ...let the event go its way return 0; //mark contact which we trying to contact for exclude from check if ((dbei->flags & DBEF_SENT) && db_get_b(hContact, "CList", "NotOnList", 0) && (!gbMaxQuestCount || db_get_dw(hContact, pluginName, "QuestionCount", 0) < gbMaxQuestCount) && gbExclude) { db_set_b(hContact, pluginName, "Excluded", 1); return 0; } // if message is from known or marked Answered contact if (!db_get_b(hContact, "CList", "NotOnList", 0)) // ...let the event go its way return 0; // if message is corrupted or empty it cannot be an answer. if (!dbei->cbBlob || !dbei->pBlob) // reject processing of the event return 1; tstring message; if (dbei->flags & DBEF_UTF) { wchar_t* msg_u; char* msg_a = mir_strdup((char*)dbei->pBlob); mir_utf8decode(msg_a, &msg_u); message = msg_u; } else message = mir_a2u((char*)(dbei->pBlob)); // if message contains right answer... boost::algorithm::erase_all(message, "\r"); boost::algorithm::erase_all(message, "\n"); bool bSendMsg = true; if (gbInvisDisable) { if (CallProtoService(dbei->szModule, PS_GETSTATUS, 0, 0) == ID_STATUS_INVISIBLE) bSendMsg = false; else if (db_get_w(hContact, dbei->szModule, "ApparentMode", 0) == ID_STATUS_OFFLINE) bSendMsg = false; //is it useful ? } bool answered = false; if (gbMathExpression) { if (boost::algorithm::all(message, boost::is_digit())) { int num = _ttoi(message.c_str()); int math_answer = db_get_dw(hContact, pluginName, "MathAnswer", 0); if (num && math_answer) answered = (num == math_answer); } } else if (!gbRegexMatch) answered = gbCaseInsensitive ? (!Stricmp(message.c_str(), (variables_parse(gbAnswer, hContact).c_str()))) : (!mir_tstrcmp(message.c_str(), (variables_parse(gbAnswer, hContact).c_str()))); else { if (gbCaseInsensitive) { std::string check(toUTF8(variables_parse(gbAnswer, hContact))), msg(toUTF8(message)); boost::algorithm::to_upper(check); boost::algorithm::to_upper(msg); boost::regex expr(check); answered = boost::regex_search(msg.begin(), msg.end(), expr); } else { std::string check(toUTF8(variables_parse(gbAnswer, hContact))), msg(toUTF8(message)); boost::regex expr(check); answered = boost::regex_search(msg.begin(), msg.end(), expr); } } if (answered) { // unhide contact db_unset(hContact, "CList", "Hidden"); db_unset(hContact, pluginName, "MathAnswer"); // mark contact as Answered db_set_b(hContact, pluginName, "Answered", 1); //add contact permanently if (gbAddPermanent) //do not use this ) db_unset(hContact, "CList", "NotOnList"); // send congratulation if (bSendMsg) { tstring prot = DBGetContactSettingStringPAN(NULL, dbei->szModule, "AM_BaseProto", _T("")); // for notICQ protocols or disable auto auth. reqwest if ((Stricmp(_T("ICQ"), prot.c_str())) || (!gbAutoReqAuth)) { char * buf = mir_utf8encodeW(variables_parse(gbCongratulation, hContact).c_str()); CallContactService(hContact, PSS_MESSAGE, 0, (LPARAM)buf); mir_free(buf); } // Note: For ANSI can be not work if (!Stricmp(_T("ICQ"), prot.c_str())) { // grand auth. if (gbAutoAuth) CallProtoService(dbei->szModule, "/GrantAuth", w, 0); // add contact to server list and local group if (gbAutoAddToServerList) { db_set_ws(hContact, "CList", "Group", gbAutoAuthGroup.c_str()); CallProtoService(dbei->szModule, "/AddServerContact", w, 0); db_unset(hContact, "CList", "NotOnList"); }; // auto auth. reqwest with send congratulation if (gbAutoReqAuth) CallContactService(hContact, PSS_AUTHREQUEST, 0, (LPARAM)variables_parse(gbCongratulation, hContact).c_str()); } } return 0; } // URL contains check bSendMsg = (bSendMsg && gbIgnoreURL) ? (!IsUrlContains((TCHAR *)message.c_str())) : bSendMsg; // if message message does not contain infintite talk protection prefix // and question count for this contact is less then maximum if (bSendMsg) { if ((!gbInfTalkProtection || tstring::npos == message.find(_T("StopSpam automatic message:\r\n"))) && (!gbMaxQuestCount || db_get_dw(hContact, pluginName, "QuestionCount", 0) < gbMaxQuestCount)) { // send question tstring q; if (gbInfTalkProtection) q += _T("StopSpam automatic message:\r\n"); if (gbMathExpression) { //parse math expression in question tstring tmp_question = gbQuestion; std::list<int> args; std::list<TCHAR> actions; tstring::size_type p1 = gbQuestion.find(_T("X")), p2 = 0; const tstring expr_chars = _T("X+-/*"), expr_acts = _T("+-/*"); while (p1 < gbQuestion.length() && p1 != tstring::npos && expr_chars.find(gbQuestion[p1]) != tstring::npos) { std::string arg; p2 = p1; for (p1 = gbQuestion.find(_T("X"), p1); (p1 < gbQuestion.length()) && (gbQuestion[p1] == L'X'); ++p1) arg += get_random_num(1); tmp_question.replace(p2, arg.size(), toUTF16(arg)); args.push_back(atoi(arg.c_str())); if ((p1 < gbQuestion.length()) && (p1 != tstring::npos) && (expr_acts.find(gbQuestion[p1]) != tstring::npos)) actions.push_back(gbQuestion[p1]); ++p1; } int math_answer = 0; math_answer = args.front(); args.pop_front(); while (!args.empty()) { if (!actions.empty()) { switch (actions.front()) { case _T('+'): { math_answer += args.front(); args.pop_front(); } break; case _T('-'): { math_answer -= args.front(); args.pop_front(); } break; case _T('/'): { math_answer /= args.front(); args.pop_front(); } break; case _T('*'): { math_answer *= args.front(); args.pop_front(); } break; } actions.pop_front(); } else break; } db_set_dw(hContact, pluginName, "MathAnswer", math_answer); q += variables_parse(tmp_question, hContact); } else q += variables_parse(gbQuestion, hContact); CallContactService(hContact, PSS_MESSAGE, 0, ptrA(mir_utf8encodeW(q.c_str()))); // increment question count DWORD questCount = db_get_dw(hContact, pluginName, "QuestionCount", 0); db_set_dw(hContact, pluginName, "QuestionCount", questCount + 1); } else { if (gbIgnoreContacts) db_set_dw(hContact, "Ignore", "Mask1", 0x0000007F); } } if (gbHideContacts) db_set_b(hContact, "CList", "Hidden", 1); if (gbSpecialGroup) db_set_ws(hContact, "CList", "Group", gbSpammersGroup.c_str()); db_set_b(hContact, "CList", "NotOnList", 1); // save first message from contact if (db_get_dw(hContact, pluginName, "QuestionCount", 0) < 2) { dbei->flags |= DBEF_READ; db_event_add(hContact, dbei); }; // reject processing of the event LogSpamToFile(hContact, message); return 1; }
TCHAR* DoRtfToTags( char* pszText, SESSION_INFO* si) { char *p1; int* pIndex; int i, iRemoveChars; char InsertThis[50]; BOOL bJustRemovedRTF = TRUE; BOOL bTextHasStarted = FALSE; #if defined(_UNICODE) TCHAR *ptszResult; #endif int iUcMode = 0; if ( !pszText ) return FALSE; // create an index of colors in the module and map them to // corresponding colors in the RTF color table pIndex = mir_alloc(sizeof(int) * MM_FindModule(si->pszModule)->nColorCount); for(i = 0; i < MM_FindModule(si->pszModule)->nColorCount ; i++) pIndex[i] = -1; CreateColorMap( pszText, pIndex, si ); // scan the file for rtf commands and remove or parse them p1 = strstr( pszText, "\\pard" ); if ( p1 == NULL ) { mir_free(pIndex); return FALSE; } p1 += 5; MoveMemory( pszText, p1, lstrlenA( p1 ) + 1 ); p1 = pszText; // iterate through all characters, if rtf control character found then take action while ( *p1 != '\0' ) { InsertThis[0] = 0; iRemoveChars = 0; switch (*p1) { case '\\': if ( !memcmp(p1, "\\cf", 3 )) { // foreground color int iCol, iInd; iRemoveChars = 3 + ReadInteger(p1+3, &iCol); iInd = RTFColorToIndex(pIndex, iCol, si); bJustRemovedRTF = TRUE; if (bTextHasStarted || iInd >= 0) mir_snprintf( InsertThis, SIZEOF(InsertThis), ( iInd >= 0 ) ? "%%c%02u" : "%%C", iInd); } else if ( !memcmp(p1, "\\highlight", 10 )) { //background color int iCol, iInd; iRemoveChars = 10 + ReadInteger(p1+10, &iCol); iInd = RTFColorToIndex(pIndex, iCol, si); bJustRemovedRTF = TRUE; if (bTextHasStarted || iInd >= 0) mir_snprintf( InsertThis, SIZEOF(InsertThis), ( iInd >= 0 ) ? "%%f%02u" : "%%F", iInd); } else if ( !memcmp(p1, "\\lang", 5 )) { // language id bTextHasStarted = bJustRemovedRTF = TRUE; iRemoveChars = 5 + ReadInteger( p1+5, NULL ); } else if ( !memcmp(p1, "\\par", 4 )) { // newline bTextHasStarted = bJustRemovedRTF = TRUE; iRemoveChars = 4; strcpy(InsertThis, "\n" ); } else if ( !memcmp(p1, "\\line", 5 )) { // newline bTextHasStarted = bJustRemovedRTF = TRUE; iRemoveChars = 5; strcpy(InsertThis, "\n" ); } else if (!memcmp(p1, "\\bullet", 7)) { bTextHasStarted = TRUE; bJustRemovedRTF = TRUE; iRemoveChars = 7; #if defined(_UNICODE) strcpy(InsertThis, "\xE2\x80\xA2"); #else strcpy(InsertThis, "\x95"); #endif } else if ( !memcmp(p1, "\\b", 2 )) { //bold bTextHasStarted = bJustRemovedRTF = TRUE; iRemoveChars = (p1[2] != '0')?2:3; mir_snprintf(InsertThis, SIZEOF(InsertThis), (p1[2] != '0') ? "%%b": "%%B" ); } else if ( !memcmp(p1, "\\i", 2 )) { // italics bTextHasStarted = bJustRemovedRTF = TRUE; iRemoveChars = (p1[2] != '0')?2:3; mir_snprintf(InsertThis, SIZEOF(InsertThis), (p1[2] != '0') ? "%%i" : "%%I" ); } else if ( !memcmp(p1, "\\uc", 3 )) { // number of Unicode chars bTextHasStarted = bJustRemovedRTF = TRUE; iUcMode = p1[3] - '0'; iRemoveChars = 4; } else if ( !memcmp(p1, "\\ul", 3 )) { // underlined bTextHasStarted = bJustRemovedRTF = TRUE; if (p1[3] == 'n') iRemoveChars = 7; else if (p1[3] == '0') iRemoveChars = 4; else iRemoveChars = 3; mir_snprintf(InsertThis, SIZEOF(InsertThis), (p1[3] != '0' && p1[3] != 'n') ? "%%u" : "%%U" ); } else if ( p1[1] == 'f' && isdigit( p1[2] )) { // unicode char bTextHasStarted = bJustRemovedRTF = TRUE; iRemoveChars = 2 + ReadInteger( p1+2, NULL ); } else if ( !memcmp(p1, "\\tab", 4 )) { // tab bTextHasStarted = TRUE; bJustRemovedRTF = TRUE; iRemoveChars = 4; strcpy(InsertThis, " " ); } else if (!memcmp(p1, "\\endash", 7)) { bTextHasStarted = TRUE; bJustRemovedRTF = TRUE; iRemoveChars = 7; #if defined(_UNICODE) strcpy(InsertThis, "\xE2\x80\x93"); #else strcpy(InsertThis, "\x96"); #endif } else if (!memcmp(p1, "\\emdash", 7)) { bTextHasStarted = TRUE; bJustRemovedRTF = TRUE; iRemoveChars = 7; #if defined(_UNICODE) strcpy(InsertThis, "\xE2\x80\x94"); #else strcpy(InsertThis, "\x97"); #endif } else if (!memcmp(p1, "\\lquote",7)) { bTextHasStarted = TRUE; bJustRemovedRTF = TRUE; iRemoveChars = 7; #if defined(_UNICODE) strcpy(InsertThis, "\xE2\x80\x98"); #else strcpy(InsertThis, "\x91"); #endif } else if (!memcmp(p1, "\\rquote",7)) { bTextHasStarted = TRUE; bJustRemovedRTF = TRUE; iRemoveChars = 7; #if defined(_UNICODE) strcpy(InsertThis, "\xE2\x80\x99"); #else strcpy(InsertThis, "\x92"); #endif } else if (!memcmp(p1, "\\ldblquote",10)) { bTextHasStarted = TRUE; bJustRemovedRTF = TRUE; iRemoveChars = 10; #if defined(_UNICODE) strcpy(InsertThis, "\xe2\x80\x9c"); #else strcpy(InsertThis, "\""); #endif } else if (!memcmp(p1, "\\rdblquote",10)) { bTextHasStarted = TRUE; bJustRemovedRTF = TRUE; iRemoveChars = 10; #if defined(_UNICODE) strcpy(InsertThis, "\xe2\x80\x9d"); #else strcpy(InsertThis, "\""); #endif } else if ( p1[1] == '\\' || p1[1] == '{' || p1[1] == '}' ) { // escaped characters bTextHasStarted = TRUE; bJustRemovedRTF = FALSE; iRemoveChars = 2; mir_snprintf(InsertThis, SIZEOF(InsertThis), "%c", p1[1]); } else if ( p1[1] == '~' ) { // non-breaking space bTextHasStarted = TRUE; bJustRemovedRTF = FALSE; iRemoveChars = 2; #if defined(_UNICODE) strcpy(InsertThis, "\xC2\xA0"); #else strcpy(InsertThis, "\xA0"); #endif } else if ( p1[1] == '\'' ) { // special character char tmp[4], *p3 = tmp; bTextHasStarted = TRUE; bJustRemovedRTF = FALSE; if (p1[2] != ' ' && p1[2] != '\\') { *p3++ = p1[2]; iRemoveChars = 3; if ( p1[3] != ' ' && p1[3] != '\\') { *p3++ = p1[3]; iRemoveChars++; } *p3 = 0; sscanf( tmp, "%x", InsertThis ); InsertThis[1] = 0; } else iRemoveChars = 2; } else if ( bJustRemovedRTF ) { // remove unknown RTF command int j = 1; bJustRemovedRTF = TRUE; while(p1[j] != ' ' && p1[j] != '\\' && p1[j] != '\0') j++; iRemoveChars = j; } break; case '{': // other RTF control characters case '}': iRemoveChars = 1; break; case '\r': case '\n': bTextHasStarted = TRUE; bJustRemovedRTF = FALSE; iRemoveChars = 1; break; case '%': // escape chat -> protocol control character bTextHasStarted = TRUE; bJustRemovedRTF = FALSE; iRemoveChars = 1; mir_snprintf(InsertThis, SIZEOF(InsertThis), "%%%%" ); break; case ' ': // remove spaces following a RTF command if (bJustRemovedRTF) iRemoveChars = 1; bJustRemovedRTF = FALSE; bTextHasStarted = TRUE; break; default: // other text that should not be touched bTextHasStarted = TRUE; bJustRemovedRTF = FALSE; break; } // move the memory and paste in new commands instead of the old RTF if ( InsertThis[0] || iRemoveChars ) { MoveMemory(p1 + lstrlenA(InsertThis) , p1 + iRemoveChars, lstrlenA(p1) - iRemoveChars +1 ); CopyMemory(p1, InsertThis, lstrlenA(InsertThis)); p1 += lstrlenA(InsertThis); } else p1++; } mir_free(pIndex); #if !defined( _UNICODE ) return pszText; #else mir_utf8decode(pszText, &ptszResult); return ptszResult; #endif }
unsigned int CSettings::ReadSetting(TDBTSetting & Setting, TDBTSettingHandle hSetting) { CBlockManager * file = &m_BlockManagerPri; if (hSetting & cSettingsFileFlag) { file = &m_BlockManagerSet; hSetting = hSetting & ~cSettingsFileFlag; } uint32_t sig = cSettingSignature; uint32_t size = 0; if (hSetting == 0) return DBT_INVALIDPARAM; CBlockManager::ReadTransaction trans(*file); TSetting * setting = file->ReadBlock<TSetting>(hSetting, size, sig); if (!setting) return DBT_INVALIDPARAM; uint8_t* str = reinterpret_cast<uint8_t*>(setting + 1) + setting->NameLength + 1; if (Setting.Type == 0) { Setting.Type = setting->Type; if (setting->Type & DBT_STF_VariableLength) { Setting.Value.Length = setting->BlobLength; switch (setting->Type) { case DBT_ST_WCHAR: { Setting.Value.Length = setting->BlobLength / sizeof(wchar_t); Setting.Value.pWide = (wchar_t*) mir_realloc(Setting.Value.pWide, sizeof(wchar_t) * Setting.Value.Length); memcpy(Setting.Value.pWide, str, setting->BlobLength); Setting.Value.pWide[Setting.Value.Length - 1] = 0; } break; case DBT_ST_ANSI: case DBT_ST_UTF8: { Setting.Value.Length = setting->BlobLength; Setting.Value.pAnsi = (char *) mir_realloc(Setting.Value.pAnsi, setting->BlobLength); memcpy(Setting.Value.pAnsi, str, setting->BlobLength); Setting.Value.pAnsi[Setting.Value.Length - 1] = 0; } break; default: { Setting.Value.Length = setting->BlobLength; Setting.Value.pBlob = (uint8_t *) mir_realloc(Setting.Value.pBlob, setting->BlobLength); memcpy(Setting.Value.pBlob, str, setting->BlobLength); } break; } } else { Setting.Value.QWord = setting->Value.QWord; } } else { switch (setting->Type) { case DBT_ST_BYTE: case DBT_ST_WORD: case DBT_ST_DWORD: case DBT_ST_QWORD: { switch (Setting.Type) { case DBT_ST_BYTE: Setting.Value.Byte = (uint8_t) setting->Value.QWord; break; case DBT_ST_WORD: Setting.Value.Word = (uint16_t) setting->Value.QWord; break; case DBT_ST_DWORD: Setting.Value.DWord = (uint32_t) setting->Value.QWord; break; case DBT_ST_QWORD: Setting.Value.QWord = (uint64_t) setting->Value.QWord; break; case DBT_ST_CHAR: Setting.Value.Char = ( int8_t) setting->Value.QWord; break; case DBT_ST_SHORT: Setting.Value.Short = ( int16_t) setting->Value.QWord; break; case DBT_ST_INT: Setting.Value.Int = ( int32_t) setting->Value.QWord; break; case DBT_ST_INT64: Setting.Value.Int64 = ( int64_t) setting->Value.QWord; break; case DBT_ST_BOOL: Setting.Value.Bool = setting->Value.QWord != 0; break; case DBT_ST_ANSI: case DBT_ST_UTF8: { char buffer[24]; buffer[0] = 0; Setting.Value.Length = 1 + sprintf_s(buffer, "%llu", setting->Value.QWord); Setting.Value.pAnsi = (char *) mir_realloc(Setting.Value.pAnsi, Setting.Value.Length); memcpy(Setting.Value.pAnsi, buffer, Setting.Value.Length); } break; case DBT_ST_WCHAR: { wchar_t buffer[24]; buffer[0] = 0; Setting.Value.Length = 1 + swprintf_s(buffer, L"%llu", setting->Value.QWord); Setting.Value.pWide = (wchar_t *) mir_realloc(Setting.Value.pWide, Setting.Value.Length * sizeof(wchar_t)); memcpy(Setting.Value.pWide, buffer, Setting.Value.Length * sizeof(wchar_t)); } break; case DBT_ST_BLOB: { Setting.Value.Length = 0; switch (setting->Type) { case DBT_ST_BYTE: Setting.Value.Length = 1; break; case DBT_ST_WORD: Setting.Value.Length = 2; break; case DBT_ST_DWORD: Setting.Value.Length = 4; break; case DBT_ST_QWORD: Setting.Value.Length = 8; break; } Setting.Value.pBlob = (uint8_t *) mir_realloc(Setting.Value.pBlob, Setting.Value.Length); memcpy(Setting.Value.pBlob, &setting->Value, Setting.Value.Length); } break; } } break; case DBT_ST_CHAR: case DBT_ST_SHORT: case DBT_ST_INT: case DBT_ST_INT64: { int64_t val = 0; switch (setting->Type) { case DBT_ST_CHAR: val = setting->Value.Char; break; case DBT_ST_SHORT: val = setting->Value.Short; break; case DBT_ST_INT: val = setting->Value.Int; break; case DBT_ST_INT64: val = setting->Value.Int64; break; } switch (Setting.Type) { case DBT_ST_BYTE: Setting.Value.Byte = (uint8_t) val; break; case DBT_ST_WORD: Setting.Value.Word = (uint16_t) val; break; case DBT_ST_DWORD: Setting.Value.DWord = (uint32_t) val; break; case DBT_ST_QWORD: Setting.Value.QWord = (uint64_t) val; break; case DBT_ST_CHAR: Setting.Value.Char = ( int8_t) val; break; case DBT_ST_SHORT: Setting.Value.Short = ( int16_t) val; break; case DBT_ST_INT: Setting.Value.Int = ( int32_t) val; break; case DBT_ST_INT64: Setting.Value.Int64 = ( int64_t) val; break; case DBT_ST_BOOL: Setting.Value.Bool = val != 0; break; case DBT_ST_ANSI: case DBT_ST_UTF8: { char buffer[24]; buffer[0] = 0; Setting.Value.Length = 1 + sprintf_s(buffer, "%lli", val); Setting.Value.pAnsi = (char *) mir_realloc(Setting.Value.pAnsi, Setting.Value.Length); memcpy(Setting.Value.pAnsi, buffer, Setting.Value.Length); } break; case DBT_ST_WCHAR: { wchar_t buffer[24]; buffer[0] = 0; Setting.Value.Length = 1 + swprintf_s(buffer, L"%lli", val); Setting.Value.pWide = (wchar_t *) mir_realloc(Setting.Value.pWide, Setting.Value.Length * sizeof(wchar_t)); memcpy(Setting.Value.pWide, buffer, Setting.Value.Length * sizeof(wchar_t)); } break; case DBT_ST_BLOB: { Setting.Value.Length = 0; switch (setting->Type) { case DBT_ST_CHAR: Setting.Value.Length = 1; break; case DBT_ST_SHORT: Setting.Value.Length = 2; break; case DBT_ST_INT: Setting.Value.Length = 4; break; case DBT_ST_INT64: Setting.Value.Length = 8; break; } Setting.Value.pBlob = (unsigned char *) mir_realloc(Setting.Value.pBlob, Setting.Value.Length); memcpy(Setting.Value.pBlob, &setting->Value, Setting.Value.Length); } break; } } break; case DBT_ST_FLOAT: case DBT_ST_DOUBLE: { double val = 0; if (setting->Type == DBT_ST_DOUBLE) val = setting->Value.Double; else val = setting->Value.Float; switch (Setting.Type) { case DBT_ST_BYTE: Setting.Value.Byte = (uint8_t) floor(val); break; case DBT_ST_WORD: Setting.Value.Word = (uint16_t) floor(val); break; case DBT_ST_DWORD: Setting.Value.DWord = (uint32_t) floor(val); break; case DBT_ST_QWORD: Setting.Value.QWord = (uint64_t) floor(val); break; case DBT_ST_CHAR: Setting.Value.Char = ( int8_t) floor(val); break; case DBT_ST_SHORT: Setting.Value.Short = ( int16_t) floor(val); break; case DBT_ST_INT: Setting.Value.Int = ( int32_t) floor(val); break; case DBT_ST_INT64: Setting.Value.Int64 = ( int64_t) floor(val); break; case DBT_ST_BOOL: Setting.Value.Bool = val != 0; break; case DBT_ST_ANSI: case DBT_ST_UTF8: { char buffer[128]; buffer[0] = 0; Setting.Value.Length = 1 + sprintf_s(buffer, "%lf", setting->Value.QWord); Setting.Value.pAnsi = (char *) mir_realloc(Setting.Value.pAnsi, Setting.Value.Length); memcpy(Setting.Value.pAnsi, buffer, Setting.Value.Length); } break; case DBT_ST_WCHAR: { wchar_t buffer[128]; buffer[0] = 0; Setting.Value.Length = 1 + swprintf_s(buffer, L"%lf", setting->Value.QWord); Setting.Value.pWide = (wchar_t *) mir_realloc(Setting.Value.pWide, Setting.Value.Length * sizeof(wchar_t)); memcpy(Setting.Value.pWide, buffer, Setting.Value.Length * sizeof(wchar_t)); } break; case DBT_ST_BLOB: { Setting.Value.Length = 4; if (setting->Type == DBT_ST_DOUBLE) Setting.Value.Length = 8; Setting.Value.pBlob = (uint8_t*) mir_realloc(Setting.Value.pBlob, Setting.Value.Length); memcpy(Setting.Value.pBlob, &setting->Value, Setting.Value.Length); } break; } } break; case DBT_ST_BOOL: { switch (Setting.Type) { case DBT_ST_BYTE: case DBT_ST_WORD: case DBT_ST_DWORD: case DBT_ST_QWORD: case DBT_ST_CHAR: case DBT_ST_SHORT: case DBT_ST_INT: case DBT_ST_INT64: { if (setting->Value.Bool) Setting.Value.QWord = 1; else Setting.Value.QWord = 0; } break; case DBT_ST_FLOAT: { if (setting->Value.Bool) Setting.Value.Float = 1; else Setting.Value.Float = 0; } break; case DBT_ST_DOUBLE: { if (setting->Value.Bool) Setting.Value.Double = 1; else Setting.Value.Double = 0; } break; case DBT_ST_ANSI: case DBT_ST_UTF8: { char * buffer = "false"; Setting.Value.Length = 5; if (setting->Value.Bool) { buffer = "true"; Setting.Value.Length = 4; } Setting.Value.pAnsi = (char *) mir_realloc(Setting.Value.pAnsi, Setting.Value.Length); memcpy(Setting.Value.pAnsi, buffer, Setting.Value.Length); } break; case DBT_ST_WCHAR: { wchar_t * buffer = L"false"; Setting.Value.Length = 5; if (setting->Value.Bool) { buffer = L"true"; Setting.Value.Length = 4; } Setting.Value.pWide = (wchar_t *) mir_realloc(Setting.Value.pWide, Setting.Value.Length * sizeof(wchar_t)); memcpy(Setting.Value.pWide, buffer, Setting.Value.Length * sizeof(wchar_t)); } break; case DBT_ST_BLOB: { Setting.Value.pBlob = (uint8_t*) mir_realloc(Setting.Value.pBlob, sizeof(bool)); (*((bool*)Setting.Value.pBlob)) = setting->Value.Bool; Setting.Value.Length = sizeof(bool); } break; } } break; case DBT_ST_ANSI: { str[setting->BlobLength - 1] = 0; switch (Setting.Type) { case DBT_ST_BYTE: case DBT_ST_WORD: case DBT_ST_DWORD: case DBT_ST_QWORD: case DBT_ST_BOOL: case DBT_ST_CHAR: case DBT_ST_SHORT: case DBT_ST_INT: case DBT_ST_INT64: { Setting.Value.QWord = 0; } break; case DBT_ST_ANSI: { Setting.Value.Length = setting->BlobLength; Setting.Value.pAnsi = (char *) mir_realloc(Setting.Value.pAnsi, setting->BlobLength); memcpy(Setting.Value.pAnsi, str, setting->BlobLength); } break; case DBT_ST_UTF8: { Setting.Value.pUTF8 = mir_utf8encode((char*)str); Setting.Value.Length = static_cast<uint32_t>(strlen(Setting.Value.pUTF8) + 1); } break; case DBT_ST_WCHAR: { Setting.Value.pWide = mir_a2u((char*)str); Setting.Value.Length = static_cast<uint32_t>(wcslen(Setting.Value.pWide) + 1); } break; case DBT_ST_BLOB: { Setting.Value.Length = setting->BlobLength; Setting.Value.pBlob = (uint8_t *) mir_realloc(Setting.Value.pBlob, setting->BlobLength); memcpy(Setting.Value.pBlob, str, setting->BlobLength); } break; } } break; case DBT_ST_UTF8: { str[setting->BlobLength - 1] = 0; switch (Setting.Type) { case DBT_ST_BYTE: case DBT_ST_WORD: case DBT_ST_DWORD: case DBT_ST_QWORD: case DBT_ST_BOOL: case DBT_ST_CHAR: case DBT_ST_SHORT: case DBT_ST_INT: case DBT_ST_INT64: { Setting.Value.QWord = 0; } break; case DBT_ST_ANSI: { mir_utf8decode((char*)str, NULL); Setting.Value.Length = static_cast<uint32_t>(strlen((char*)str) + 1); Setting.Value.pAnsi = (char *) mir_realloc(Setting.Value.pAnsi, Setting.Value.Length); memcpy(Setting.Value.pAnsi, str, Setting.Value.Length); } break; case DBT_ST_UTF8: { Setting.Value.Length = setting->BlobLength; Setting.Value.pUTF8 = (char *) mir_realloc(Setting.Value.pUTF8, setting->BlobLength); memcpy(Setting.Value.pUTF8, str, setting->BlobLength); } break; case DBT_ST_WCHAR: { Setting.Value.pWide = mir_utf8decodeW((char*)str); if (Setting.Value.pWide) { Setting.Value.Length = static_cast<uint32_t>(wcslen(Setting.Value.pWide) + 1); } else { Setting.Value.Length = 0; Setting.Type = 0; } } break; case DBT_ST_BLOB: { Setting.Value.pBlob = (uint8_t *) mir_realloc(Setting.Value.pBlob, setting->BlobLength); memcpy(Setting.Value.pBlob, str, setting->BlobLength); Setting.Value.Length = setting->BlobLength; } break; } } break; case DBT_ST_WCHAR: { ((wchar_t*)str)[setting->BlobLength / sizeof(wchar_t) - 1] = 0; switch (Setting.Type) { case DBT_ST_BYTE: case DBT_ST_WORD: case DBT_ST_DWORD: case DBT_ST_QWORD: case DBT_ST_BOOL: case DBT_ST_CHAR: case DBT_ST_SHORT: case DBT_ST_INT: case DBT_ST_INT64: { Setting.Value.QWord = 0; } break; case DBT_ST_ANSI: { Setting.Value.pAnsi = mir_u2a((wchar_t*)str); Setting.Value.Length = static_cast<uint32_t>(strlen(Setting.Value.pAnsi) + 1); } break; case DBT_ST_UTF8: { Setting.Value.pUTF8 = mir_utf8encodeW((wchar_t*)str); Setting.Value.Length = static_cast<uint32_t>(strlen(Setting.Value.pUTF8) + 1); } break; case DBT_ST_WCHAR: { Setting.Value.Length = setting->BlobLength / sizeof(wchar_t); Setting.Value.pWide = (wchar_t*) mir_realloc(Setting.Value.pWide, Setting.Value.Length * sizeof(wchar_t)); memcpy(Setting.Value.pWide, str, Setting.Value.Length * sizeof(wchar_t)); } break; case DBT_ST_BLOB: { Setting.Value.pBlob = (uint8_t *) mir_realloc(Setting.Value.pBlob, setting->BlobLength); memcpy(Setting.Value.pBlob, str, setting->BlobLength); Setting.Value.Length = setting->BlobLength; } break; } } break; case DBT_ST_BLOB: { switch (Setting.Type) { case DBT_ST_BYTE: case DBT_ST_WORD: case DBT_ST_DWORD: case DBT_ST_QWORD: case DBT_ST_BOOL: case DBT_ST_CHAR: case DBT_ST_SHORT: case DBT_ST_INT: case DBT_ST_INT64: { Setting.Value.QWord = 0; } break; case DBT_ST_ANSI: case DBT_ST_WCHAR: case DBT_ST_UTF8: { Setting.Value.Length = 0; if (Setting.Value.pBlob) mir_free(Setting.Value.pBlob); Setting.Value.pBlob = NULL; } break; case DBT_ST_BLOB: { Setting.Value.pBlob = (uint8_t *) mir_realloc(Setting.Value.pBlob, setting->BlobLength); memcpy(Setting.Value.pBlob, str, setting->BlobLength); Setting.Value.Length = setting->BlobLength; } break; } } break; } } if (Setting.Descriptor) { Setting.Descriptor->Entity = setting->Entity; Setting.Descriptor->FoundInEntity = setting->Entity; Setting.Descriptor->pszSettingName = (char *) mir_realloc(Setting.Descriptor->pszSettingName, setting->NameLength + 1); memcpy(Setting.Descriptor->pszSettingName, setting + 1, setting->NameLength + 1); Setting.Descriptor->pszSettingName[setting->NameLength] = 0; } return setting->Type; }
static TTBButton* MakeTBButton(lua_State *L) { TTBButton *tbb = (TTBButton*)mir_calloc(sizeof(TTBButton)); lua_pushliteral(L, "Name"); lua_gettable(L, -2); tbb->name = mir_utf8decode((char*)luaL_checkstring(L, -1), NULL); lua_pop(L, 1); lua_pushliteral(L, "Service"); lua_gettable(L, -2); tbb->pszService = (char*)lua_tostring(L, -1); lua_pop(L, 1); lua_pushliteral(L, "Flags"); lua_gettable(L, -2); tbb->dwFlags = lua_tointeger(L, -1); lua_pop(L, 1); // up state lua_pushliteral(L, "IconUp"); lua_gettable(L, -2); tbb->hIconHandleUp = (HANDLE)lua_touserdata(L, -1); lua_pop(L, 1); lua_pushliteral(L, "TooltipUp"); lua_gettable(L, -2); tbb->pszTooltipUp = mir_utf8decode((char*)lua_tostring(L, -1), NULL); lua_pop(L, 1); lua_pushliteral(L, "wParamUp"); lua_gettable(L, -2); tbb->wParamUp = luaM_towparam(L, -1); lua_pop(L, 1); lua_pushliteral(L, "lParamUp"); lua_gettable(L, -2); tbb->lParamUp = luaM_tolparam(L, -1); lua_pop(L, 1); // dn state lua_pushliteral(L, "IconDown"); lua_gettable(L, -2); tbb->hIconHandleDn = (HANDLE)lua_touserdata(L, -1); lua_pop(L, 1); lua_pushliteral(L, "TooltipDown"); lua_gettable(L, -2); tbb->pszTooltipDn = mir_utf8decode((char*)lua_tostring(L, -1), NULL); lua_pop(L, 1); lua_pushliteral(L, "wParamDown"); lua_gettable(L, -2); tbb->wParamDown = luaM_towparam(L, -1); lua_pop(L, 1); lua_pushliteral(L, "lParamDown"); lua_gettable(L, -2); tbb->lParamDown = luaM_tolparam(L, -1); lua_pop(L, 1); return tbb; }
STDMETHODIMP_(BOOL) CDataBase::GetContactSettingStatic(HANDLE hContact, DBCONTACTGETSETTING *dbcgs) { char namebuf[512]; namebuf[0] = 0; if (dbcgs->szModule) strcpy_s(namebuf, dbcgs->szModule); strcat_s(namebuf, "/"); if (dbcgs->szSetting) strcat_s(namebuf, dbcgs->szSetting); TDBTSettingDescriptor desc = {0,0,0,0,0,0,0,0}; TDBTSetting set = {0,0,0,0}; desc.cbSize = sizeof(desc); desc.Entity = (WPARAM)hContact; desc.pszSettingName = namebuf; set.cbSize = sizeof(set); set.Descriptor = &desc; if (DBSettingRead(reinterpret_cast<WPARAM>(&set), 0) == DBT_INVALIDPARAM) return -1; if ((set.Type & DBT_STF_VariableLength) ^ (dbcgs->pValue->type & DBVTF_VARIABLELENGTH)) { if (set.Type & DBT_STF_VariableLength) mir_free(set.Value.pBlob); return -1; } switch (set.Type) { case DBT_ST_ANSI: if (dbcgs->pValue->cchVal < set.Value.Length) { memcpy(dbcgs->pValue->pszVal, set.Value.pAnsi, dbcgs->pValue->cchVal); dbcgs->pValue->pszVal[dbcgs->pValue->cchVal - 1] = 0; } else memcpy(dbcgs->pValue->pszVal, set.Value.pAnsi, set.Value.Length); dbcgs->pValue->type = DBVT_ASCIIZ; dbcgs->pValue->cchVal = set.Value.Length - 1; if (isEncrypted(dbcgs->szModule, dbcgs->szSetting)) DecodeString(dbcgs->pValue->pszVal); mir_free(set.Value.pAnsi); break; case DBT_ST_UTF8: set.Value.pUTF8 = mir_utf8decode(set.Value.pUTF8, NULL); set.Value.Length = static_cast<uint32_t>(strlen(set.Value.pUTF8)); if (dbcgs->pValue->cchVal < set.Value.Length) { memcpy(dbcgs->pValue->pszVal, set.Value.pUTF8, dbcgs->pValue->cchVal); dbcgs->pValue->pszVal[dbcgs->pValue->cchVal - 1] = 0; } else memcpy(dbcgs->pValue->pszVal, set.Value.pUTF8, set.Value.Length); dbcgs->pValue->type = DBVT_ASCIIZ; dbcgs->pValue->cchVal = set.Value.Length - 1; if (isEncrypted(dbcgs->szModule, dbcgs->szSetting)) DecodeString(dbcgs->pValue->pszVal); mir_free(set.Value.pUTF8); break; case DBT_ST_WCHAR: { char *tmp = mir_u2a(set.Value.pWide); WORD l = static_cast<WORD>(strlen(tmp)); mir_free(set.Value.pWide); if (dbcgs->pValue->cchVal < l + 1) { memcpy(dbcgs->pValue->pszVal, tmp, dbcgs->pValue->cchVal); dbcgs->pValue->pszVal[l] = 0; } else memcpy(dbcgs->pValue->pszVal, tmp, l + 1); dbcgs->pValue->type = DBVT_ASCIIZ; dbcgs->pValue->cchVal = l; if (isEncrypted(dbcgs->szModule, dbcgs->szSetting)) DecodeString(dbcgs->pValue->pszVal); mir_free(tmp); } break; case DBT_ST_BLOB: if (dbcgs->pValue->cchVal < set.Value.Length) memcpy(dbcgs->pValue->pbVal, set.Value.pBlob, dbcgs->pValue->cchVal); else memcpy(dbcgs->pValue->pbVal, set.Value.pBlob, set.Value.Length); dbcgs->pValue->type = DBVT_BLOB; dbcgs->pValue->cchVal = set.Value.Length; mir_free(set.Value.pBlob); break; case DBT_ST_BOOL: dbcgs->pValue->type = DBVT_BYTE; dbcgs->pValue->bVal = set.Value.Bool ? TRUE : FALSE; break; case DBT_ST_BYTE: case DBT_ST_CHAR: dbcgs->pValue->type = DBVT_BYTE; dbcgs->pValue->bVal = set.Value.Byte; break; case DBT_ST_SHORT: case DBT_ST_WORD: dbcgs->pValue->type = DBVT_WORD; dbcgs->pValue->wVal = set.Value.Word; break; case DBT_ST_INT: case DBT_ST_DWORD: dbcgs->pValue->type = DBVT_DWORD; dbcgs->pValue->dVal = set.Value.DWord; break; default: return -1; } return 0; }