int _notify(MCONTACT hContact, BYTE type, TCHAR *message, TCHAR *origmessage) { char *tmp, *tmporig; TCHAR msg[MAX_BUFFER_LENGTH]; mir_sntprintf(msg, MAX_BUFFER_LENGTH, message, CONTACT_NAME(hContact)); if (_getOptB("LogActions", defaultLogActions)) { tmp = mir_u2a(msg); tmporig = mir_u2a(origmessage); LogToSystemHistory(tmp, origmessage ? tmporig : NULL); mir_free(tmp); mir_free(tmporig); } if (_NOTIFYP) { if (type == POPUP_BLOCKED) { if (_getOptB("NotifyPopupBlocked", defaultNotifyPopupBlocked)) ShowPopup(hContact, type, NULL, msg); } else if (type == POPUP_APPROVED) { if (_getOptB("NotifyPopupApproved", defaultNotifyPopupApproved)) ShowPopup(hContact, type, NULL, msg); } else if (type == POPUP_CHALLENGE) { if (_getOptB("NotifyPopupChallenge", defaultNotifyPopupChallenge)) ShowPopup(hContact, type, NULL, msg); } else { ShowPopup(hContact, type, NULL, msg); } } return 0; }
BOOL _regmatch(TCHAR* str, TCHAR* strSearch) { BOOL ret; pcre *re; const char *error; int erroroffs, rc; char *regex, *regexp, *data, *mod; int opts = 0; char regex_parse[] = "^/(.*)/([igsm]*)"; int ovector[9]; re = pcre_compile(regex_parse, 0, &error, &erroroffs, NULL); if (!re) return FALSE; // [TODO] and log some error regex = mir_u2a(strSearch); rc = pcre_exec(re, NULL, regex, (int)strlen(regex), 0, 0, ovector, 9); if (rc != 3) { mir_free(regex); return FALSE; // [TODO] and log some error (better check for valid regex on options save) } regexp = regex + ovector[2]; regexp[ovector[3]-ovector[2]] = 0; mod = regex + ovector[4]; mod[ovector[5]-ovector[4]] = 0; pcre_free(re); data = mir_u2a(str); if (strstr(mod, "i")) opts |= PCRE_CASELESS; if (strstr(mod, "m")) opts |= PCRE_MULTILINE; if (strstr(mod, "s")) opts |= PCRE_DOTALL; re = pcre_compile(regexp, opts, &error, &erroroffs, NULL); if (!re) { mir_free(regex); mir_free(data); return FALSE; } rc = pcre_exec(re, NULL, data, (int)strlen(data), 0, 0, NULL, 0); if (rc < 0) { ret = FALSE; } else { ret = TRUE; } if (re) pcre_free(re); if (regex) mir_free(regex); if (data) mir_free(data); return ret; }
int get_response_id(const TCHAR* strvar) { int ret; pcre *re; const char *error; int erroroffs, rc; char *_str, *_strvar; int opts = 0; char regex[] = "^%response([#-_]([0-9]+))?%$"; int ovector[9]; re = pcre_compile(regex, 0, &error, &erroroffs, NULL); if (!re) return FALSE; // [TODO] and log some error _strvar = mir_u2a(strvar); rc = pcre_exec(re, NULL, _strvar, (int)strlen(_strvar), 0, 0, ovector, 9); if (rc < 0) { ret = -1; } else if (rc == 3) { _str = _strvar + ovector[4]; _str[ovector[5]-ovector[4]] = 0; ret = atoi(_str); } else ret = 0; if (re) pcre_free(re); if (_strvar) mir_free(_strvar); return ret; }
BOOL _isregex(TCHAR* strSearch) { BOOL ret = FALSE; pcre *re; const char *error; int erroroffs, rc; char *regex; char regex_parse[] = "/(.*)/([igsm]*)"; int ovector[9]; re = pcre_compile(regex_parse, 0, &error, &erroroffs, NULL); if (!re) return FALSE; regex = mir_u2a(strSearch); rc = pcre_exec(re, NULL, regex, (int)strlen(regex), 0, 0, ovector, 9); if (rc == 3) ret = TRUE; if (re) pcre_free(re); if (regex) mir_free(regex); return ret; }
const char * Protocol::GetDescription() { if (description.empty()) { PROTOACCOUNT *acc = ProtoGetAccount(name.c_str()); if (acc == NULL || acc->tszAccountName == NULL || acc->tszAccountName[0] == 0) { char tmp[1024]; Call(PS_GETNAME, sizeof(tmp), (LPARAM) tmp); description = tmp; } else { if (mir_is_unicode()) { char *tmp = mir_u2a((const wchar_t *) acc->tszAccountName); description = tmp; mir_free(tmp); } else { description = acc->tszAccountName; } } } return description.c_str(); }
MCONTACT CSteamProto::AddToList(int, PROTOSEARCHRESULT* psr) { MCONTACT hContact = NULL; ptrA steamId(mir_u2a(psr->id.t)); if (psr->cbSize == sizeof(PROTOSEARCHRESULT)) { if (!FindContact(steamId)) { //hContact = AddContact(steamId, true); //ForkThread(&CSteamProto::UpdateContactsThread, (void*)mir_strdup(steamId)); ptrA token(getStringA("TokenSecret")); PushRequest( new GetUserSummariesRequest(token, steamId), &CSteamProto::OnGotUserSummaries); } } else if (psr->cbSize == sizeof(STEAM_SEARCH_RESULT)) { STEAM_SEARCH_RESULT *ssr = (STEAM_SEARCH_RESULT*)psr; hContact = AddContact(steamId, true); UpdateContact(hContact, ssr->data); } return hContact; }
bool CSteamProto::Relogin() { ptrA token(getStringA("TokenSecret")); if (mir_strlen(token) <= 0) return false; HttpRequest *request = new LogonRequest(token); HttpResponse *response = request->Send(m_hNetlibUser); bool success = false; if (CheckResponse(response)) { JSONROOT root(response->pData); if (root != NULL) { JSONNode *node = json_get(root, "error"); ptrT error(json_as_string(node)); if (!mir_tstrcmpi(error, _T("OK"))) { node = json_get(root, "umqid"); setString("UMQID", ptrA(mir_u2a(ptrT(json_as_string(node))))); node = json_get(root, "message"); setDword("MessageID", json_as_int(node)); success = true; } } } delete request; delete response; return success; }
// преобразуем текст из чистого UTF8 в формат миранды LPSTR utf8_to_miranda(LPCSTR szUtfMsg, DWORD& flags) { LPSTR szNewMsg; if( iCoreVersion < 0x00060000 ) { flags &= ~(PREF_UTF|PREF_UNICODE); LPWSTR wszMsg = exp->utf8decode(szUtfMsg); LPSTR szMsg = mir_u2a(wszMsg); if( bCoreUnicode ) { flags |= PREF_UNICODE; int olen = (int)wcslen((LPWSTR)wszMsg)+1; int nlen = olen*(sizeof(WCHAR)+1); szNewMsg = (LPSTR) mir_alloc(nlen); memcpy(szNewMsg,szMsg,olen); memcpy(szNewMsg+olen,wszMsg,olen*sizeof(WCHAR)); mir_free(szMsg); } else { szNewMsg = szMsg; } } else { flags &= ~PREF_UNICODE; flags |= PREF_UTF; szNewMsg = (LPSTR) mir_strdup(szUtfMsg); } return szNewMsg; }
char* contact_get_id(MCONTACT hContact, bool bNameOnError) { ptrW pszUniqueID(Contact_GetInfo(CNF_UNIQUEID, hContact)); if (!pszUniqueID && bNameOnError) pszUniqueID = mir_wstrdup(Clist_GetContactDisplayName(hContact)); return mir_u2a(pszUniqueID); }
MCONTACT CAimProto::AddToList(int flags, PROTOSEARCHRESULT* psr) { if (state != 1) return 0; TCHAR *id = psr->id ? psr->id : psr->nick; char *sn = psr->flags & PSR_UNICODE ? mir_u2a((wchar_t*)id) : mir_strdup((char*)id); MCONTACT hContact = contact_from_sn(sn, true, (flags & PALF_TEMPORARY) != 0); mir_free(sn); return hContact; //See authrequest for serverside addition }
void CSteamProto::OnLoggedOn(const HttpResponse *response) { if (!CheckResponse(response)) { if (response && response->resultCode == HTTP_CODE_UNAUTHORIZED) { // Probably expired TokenSecret HandleTokenExpired(); return; } // Probably timeout or no connection, we can do nothing here ShowNotification(_T("Steam"), TranslateT("Unknown login error.")); SetStatus(ID_STATUS_OFFLINE); return; } JSONROOT root(response->pData); JSONNode *node = json_get(root, "error"); ptrT error(json_as_string(node)); if (mir_tstrcmpi(error, _T("OK"))) { // Probably expired TokenSecret HandleTokenExpired(); return; } node = json_get(root, "umqid"); setString("UMQID", ptrA(mir_u2a(ptrT(json_as_string(node))))); node = json_get(root, "message"); setDword("MessageID", json_as_int(node)); if (m_lastMessageTS <= 0) { node = json_get(root, "utc_timestamp"); time_t timestamp = _ttoi64(ptrT(json_as_string(node))); setDword("LastMessageTS", timestamp); } // load contact list ptrA token(getStringA("TokenSecret")); ptrA steamId(getStringA("SteamID")); PushRequest( new GetFriendListRequest(token, steamId), &CSteamProto::OnGotFriendList); // start polling thread m_hPollingThread = ForkThreadEx(&CSteamProto::PollingThread, 0, NULL); // go to online now ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, m_iStatus = m_iDesiredStatus); }
void Start(void* param) { NETLIBOPENCONNECTION nloc = { sizeof(nloc) }; char *tmp = (char*)mir_u2a(gbHost); nloc.szHost = tmp; nloc.timeout = 5; nloc.flags = NLOCF_V2; nloc.wPort = gbPort; Connected = FALSE; ghConnection = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)ghNetlibUser, (LPARAM)&nloc); if(ghConnection) ghPacketReciever = (HANDLE)CallService(MS_NETLIB_CREATEPACKETRECVER,(WPARAM)ghConnection,2048); }
static INT_PTR GetStatusModeDescription(WPARAM wParam, LPARAM lParam) { TCHAR* buf1 = cli.pfnGetStatusModeDescription(wParam, lParam); if (!(lParam & GSMDF_TCHAR)) { static char szMode[64]; char *buf2 = mir_u2a(buf1); strncpy_s(szMode, buf2, _TRUNCATE); mir_free(buf2); return (INT_PTR)szMode; } return (INT_PTR)buf1; }
static INT_PTR GetStatusModeDescription(WPARAM wParam, LPARAM lParam) { TCHAR* buf1 = cli.pfnGetStatusModeDescription(wParam, lParam); if (!(lParam & GSMDF_TCHAR)) { static char szMode[64]; char *buf2 = mir_u2a(buf1); mir_snprintf(szMode, SIZEOF(szMode), "%s", buf2); mir_free(buf2); return (INT_PTR)szMode; } return (INT_PTR)buf1; }
MIRANDA_HOOK_EVENT(ME_DB_EVENT_ADDED, wParam, lParam) { UNREFERENCED_PARAMETER(wParam); MEVENT hDbEvent = (MEVENT)lParam; DBEVENTINFO dbei = { 0 }; dbei.cbSize = sizeof(dbei); dbei.cbBlob = db_event_getBlobSize(hDbEvent); if (-1 == dbei.cbBlob) return 0; mir_ptr<BYTE> blob((LPBYTE)mir_alloc(dbei.cbBlob)); dbei.pBlob = blob; db_event_get(hDbEvent, &dbei); // if event is in protocol that is not despammed if (plSets->ProtoDisabled(dbei.szModule)) return 0; // event is an auth request if (!(dbei.flags & DBEF_SENT) && !(dbei.flags & DBEF_READ) && dbei.eventType == EVENTTYPE_AUTHREQUEST) { MCONTACT hcntct = DbGetAuthEventContact(&dbei); // if request is from unknown or not marked Answered contact //and if I don't sent message to this contact if (db_get_b(hcntct, "CList", "NotOnList", 0) && !db_get_b(hcntct, pluginName, answeredSetting, 0) && !IsExistMyMessage(hcntct)) { if (!plSets->HandleAuthReq.Get()) { char *buf = mir_utf8encodeW(variables_parse(plSets->AuthRepl.Get(), hcntct).c_str()); CallContactService(hcntct, PSS_MESSAGE, 0, (LPARAM)buf); mir_free(buf); } // ...send message char *AuthRepl = mir_u2a(variables_parse(plSets->AuthRepl.Get(), hcntct).c_str()); CallProtoService(dbei.szModule, PS_AUTHDENY, hDbEvent, (LPARAM)AuthRepl); mir_free(AuthRepl); db_set_b(hcntct, "CList", "NotOnList", 1); db_set_b(hcntct, "CList", "Hidden", 1); if (!plSets->HistLog.Get()) db_event_delete(0, hDbEvent); return 1; } } return 0; }
void LogSpamToFile(HANDLE hContact, tstring message) { if (!gbLogToFile) return; tstring LogStrW, LogTime, LogProtocol, LogContactId, LogContactName; tstring filename; std::fstream file; TCHAR pszName[MAX_PATH]; if (hStopSpamLogDirH) FoldersGetCustomPathT(hStopSpamLogDirH, pszName, MAX_PATH, _T("")); else lstrcpyn(pszName, VARST( _T("%miranda_logpath%")), SIZEOF(pszName)); filename = pszName; filename = filename + _T("\\stopspam_mod.log"); file.open(filename.c_str(),std::ios::out |std::ios::app); // Time Log line time_t time_now; tm *TimeNow; time(&time_now); TimeNow = localtime(&time_now); LogTime=_wasctime( TimeNow ); // Time Log line // Name, UID and Protocol Log line LogProtocol=DBGetContactSettingStringPAN(hContact,"Protocol","p",_T("")); LogContactName=(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM) hContact, GCDNF_TCHAR); LogContactId=(LogProtocol==_T(""))?_T(""):GetContactUid(hContact,LogProtocol); // Name, UID and Protocol Log line LogStrW=_T("[")+LogTime.substr(0,LogTime.length()-1)+_T("] ")+ LogContactId+_T(" - ")+ LogContactName+_T(" (")+ LogProtocol+_T("): ")+ message+_T("\n"); char * buf=mir_u2a(LogStrW.c_str()); file.write(buf,LogStrW.length()); mir_free(buf); file.close(); }
/** * name: CLineBuffer::operator + * desc: appends the specified unicode string to the class's _pVal member * param: wszVal - string to add * * return: length of the string, added **/ size_t CLineBuffer::operator + (const WCHAR *wszVal) { if (wszVal) { size_t cbLength = mir_wstrlen(wszVal); CHAR* szVal = mir_u2a(wszVal); if (szVal) { size_t cbLength = mir_strlen(szVal); if (_resizeBuf(cbLength)) { memcpy(_pVal + _cbUsed, szVal, cbLength); _cbUsed += cbLength; return cbLength; } } } return 0; }
BOOL _isvalidregex(TCHAR* strSearch) { BOOL ret; pcre *re; const char *error; int erroroffs, rc; char *regex, *regexp, *mod; int opts = 0; char regex_parse[] = "/(.*)/([igsm]*)"; int ovector[9]; re = pcre_compile(regex_parse, 0, &error, &erroroffs, NULL); if (!re) return FALSE; regex = mir_u2a(strSearch); rc = pcre_exec(re, NULL, regex, (int)strlen(regex), 0, 0, ovector, 9); pcre_free(re); if (rc == 3) { regexp = regex + ovector[2]; regexp[ovector[3]-ovector[2]] = 0; mod = regex + ovector[4]; mod[ovector[5]-ovector[4]] = 0; if (strstr(mod, "i")) opts |= PCRE_CASELESS; if (strstr(mod, "m")) opts |= PCRE_MULTILINE; if (strstr(mod, "s")) opts |= PCRE_DOTALL; re = pcre_compile(regexp, opts, &error, &erroroffs, NULL); ret = (re) ? TRUE : FALSE; } if (re) pcre_free(re); if (regex) mir_free(regex); return ret; }
double get_msg_score(TCHAR *msg) { char *message, *token; double spam_prob, ham_prob, tmp1 = 1, tmp2 = 1; double *scores = NULL; int spam_msgcount, ham_msgcount, n = 0, i; if (bayesdb == NULL) return 0; message = mir_u2a(msg); spam_msgcount = get_msg_count(SPAM); ham_msgcount = get_msg_count(HAM); token = strtok(message, DELIMS); while (token) { if (!is_token_valid(token)) { token = strtok(NULL, DELIMS); continue; } scores = (double*)realloc(scores, sizeof(double)*(n + 1)); spam_prob = spam_msgcount == 0 ? 0 : (double)get_token_score(SPAM, token) / (double)spam_msgcount; ham_prob = ham_msgcount == 0 ? 0 : (double)get_token_score(HAM, token) / (double)ham_msgcount; if (ham_prob == 0 && spam_prob == 0) { spam_prob = 0.4; ham_prob = 0.6; } spam_prob = spam_prob > 1.0 ? 1.0 : (spam_prob < 0.01 ? 0.01 : spam_prob); ham_prob = ham_prob > 1.0 ? 1.0 : (ham_prob < 0.01 ? 0.01 : ham_prob); scores[n++] = spam_prob / (spam_prob + ham_prob); token = strtok(NULL, DELIMS); } for (i = 0; i < n; i++) { tmp1 *= scores[i]; tmp2 *= 1-scores[i]; } mir_free(message); free(scores); return tmp1 / (tmp1 + tmp2); }
int GetValueA(MCONTACT hContact, const char *module, const char *setting, char *value, int length) { DBVARIANT dbv = { 0 }; if (!module || !setting || !value) return 0; if (length >= 10 && !db_get_s(hContact, module, setting, &dbv, 0)) { switch (dbv.type) { case DBVT_ASCIIZ: mir_strncpy(value, dbv.pszVal, length); break; case DBVT_DWORD: case DBVT_WORD: case DBVT_BYTE: _ultoa(getNumericValue(&dbv), value, 10); break; case DBVT_WCHAR: mir_strncpy(value, ptrA(mir_u2a(dbv.pwszVal)), length); break; case DBVT_UTF8: mir_strncpy(value, ptrA(mir_utf8decodeA(dbv.pszVal)), length); break; case DBVT_DELETED: value[0] = 0; return 0; } int type = dbv.type; db_free(&dbv); return type; } value[0] = 0; return 0; }
char *IEEmbed::GetHTMLDoc() { CComPtr<IDispatch> spDispDoc; char *pszRet = NULL; if (SUCCEEDED(pWebBrowser->get_Document(&spDispDoc))) { CComPtr<IHTMLDocument3> spDoc; if (SUCCEEDED(spDispDoc->QueryInterface(IID_IHTMLDocument3, (void**)&spDoc))) { CComPtr<IHTMLElement> spRootElement; if (SUCCEEDED(spDoc->get_documentElement(&spRootElement))) { BSTR bstrDoc; if (SUCCEEDED(spRootElement->get_outerHTML(&bstrDoc))) { pszRet = mir_u2a(bstrDoc); SysFreeString(bstrDoc); } } } } return pszRet; }
void * AddTempGroup(HWND hwnd,struct ClcData *dat,const TCHAR *szName,DWORD flags,int groupId,int calcTotalMembers) { int i=0; int f=0; TCHAR * szGroupName; DWORD groupFlags; #ifdef UNICODE char *mbuf=mir_u2a((TCHAR *)szName); #else char *mbuf=mir_strdup((char *)szName); #endif if (wildcmp(mbuf,"-@-HIDDEN-GROUP-@-",0)) { mir_free_and_nill(mbuf); return NULL; } mir_free_and_nill(mbuf); for(i=1;;i++) { szGroupName = pcli->pfnGetGroupName(i,&groupFlags); if(szGroupName==NULL) break; if (!mir_tstrcmpi(szGroupName,szName)) f=1; } if (!f) { char buf[20]; TCHAR b2[255]; void * res=NULL; mir_snprintf(buf,SIZEOF(buf),"%d",(i-1)); mir_sntprintf(b2,SIZEOF(b2),_T("#%s"),szName); b2[0]=1|GROUPF_EXPANDED; ModernWriteSettingTString(NULL,"CListGroups",buf,b2); pcli->pfnGetGroupName(i,&groupFlags); res=cli_AddGroup(hwnd,dat,szName,groupFlags,i,0); return res; } return NULL; }
void queue_message(MCONTACT hContact, DWORD msgtime, TCHAR *message) { char *tmp; sqlite3_stmt *stmt; if (!_getOptB("BayesAutolearnApproved", defaultBayesAutolearnApproved) && !_getOptB("BayesAutolearnNotApproved", defaultBayesAutolearnNotApproved)) return; if (_getOptB("BayesEnabled", defaultBayesEnabled) == 0) return; if (bayesdb == NULL) OpenBayes(); sqlite3_prepare_v2(bayesdb, "INSERT INTO queue VALUES(?,?,?)", -1, &stmt, NULL); sqlite3_bind_int(stmt, 1, (DWORD)hContact); sqlite3_bind_int(stmt, 2, msgtime); tmp = mir_u2a(message); sqlite3_bind_text(stmt, 3, tmp, (int)mir_strlen(tmp), NULL); sqlite3_step(stmt); mir_free(tmp); sqlite3_finalize(stmt); }
/* Learn one message as either SPAM or HAM as specified in type parameter */ void learn(int type, TCHAR *msg) { char *tok, *message; BYTE digest[16]; char sql_select[200], sql_update[200], sql_insert[200], sql_counter[200]; sqlite3_stmt *stmt; #ifdef _DEBUG sqlite3_stmt *stmtdbg; #endif if (_getOptB("BayesEnabled", defaultBayesEnabled) == 0) return; if (bayesdb == NULL) OpenBayes(); message = mir_u2a(msg); tok = strtok(message, DELIMS); mir_snprintf(sql_counter, "UPDATE stats SET value=value+1 WHERE key='%s'", type == SPAM ? "spam_msgcount" : "ham_msgcount"); mir_snprintf(sql_select, "SELECT 1 FROM %s WHERE token=?", type == SPAM ? "spam" : "ham"); mir_snprintf(sql_update, "UPDATE %s SET num=num+1 WHERE token=?", type ? "spam" : "ham"); mir_snprintf(sql_insert, "INSERT INTO %s VALUES(?, 1)", type ? "spam" : "ham"); #ifdef _DEBUG sqlite3_exec(bayesdbg, "BEGIN", NULL, NULL, NULL); #endif sqlite3_exec(bayesdb, "BEGIN", NULL, NULL, NULL); while (tok) { if (!is_token_valid(tok)) { tok = strtok(NULL, DELIMS); continue; } tokenhash(tok, digest); sqlite3_prepare_v2(bayesdb, sql_select, -1, &stmt, NULL); sqlite3_bind_blob(stmt, 1, digest, 16, SQLITE_STATIC); if (SQLITE_ROW == sqlite3_step(stmt)) { sqlite3_finalize(stmt); sqlite3_prepare_v2(bayesdb, sql_update, -1, &stmt, NULL); } else { sqlite3_finalize(stmt); sqlite3_prepare_v2(bayesdb, sql_insert, -1, &stmt, NULL); } sqlite3_bind_blob(stmt, 1, digest, 16, SQLITE_STATIC); sqlite3_step(stmt); sqlite3_finalize(stmt); #ifdef _DEBUG sqlite3_prepare_v2(bayesdbg, sql_select, -1, &stmtdbg, NULL); sqlite3_bind_text(stmtdbg, 1, tok, (int)mir_strlen(tok), NULL); if (SQLITE_ROW == sqlite3_step(stmtdbg)) { sqlite3_finalize(stmtdbg); sqlite3_prepare_v2(bayesdbg, sql_update, -1, &stmtdbg, NULL); } else { sqlite3_finalize(stmtdbg); sqlite3_prepare_v2(bayesdbg, sql_insert, -1, &stmtdbg, NULL); } sqlite3_bind_text(stmtdbg, 1, tok, (int)mir_strlen(tok), SQLITE_STATIC); sqlite3_step(stmtdbg); sqlite3_finalize(stmtdbg); #endif tok = strtok(NULL, DELIMS); } sqlite3_exec(bayesdb, sql_counter, NULL, NULL, NULL); sqlite3_exec(bayesdb, "COMMIT", NULL, NULL, NULL); #ifdef _DEBUG sqlite3_exec(bayesdbg, "COMMIT", NULL, NULL, NULL); #endif mir_free(message); }
static int MO_RegisterIcon( PMO_IntMenuItem pmi, void* ) { char *uname, *descr; uname = pmi->UniqName; if ( uname == NULL ) #ifdef UNICODE uname = mir_u2a(pmi->CustomName); descr = mir_u2a(pmi->mi.ptszName); #else uname = pmi->CustomName; descr = pmi->mi.pszName; #endif if ( !uname && !descr ) return FALSE; if ( !pmi->hIcolibItem ) { HICON hIcon = ImageList_GetIcon( pmi->parent->m_hMenuIcons, pmi->iconId, 0 ); char* buf = NEWSTR_ALLOCA( descr ); char sectionName[256], iconame[256]; mir_snprintf( sectionName, sizeof(sectionName), "Menu Icons/%s", pmi->parent->Name ); // remove '&' char* start = buf; while ( start ) { if (( start = strchr( start, '&' )) == NULL ) break; memmove(start,start+1,strlen(start+1)+1); if (*start!='\0') start++; else break; } mir_snprintf(iconame, sizeof(iconame), "genmenu_%s_%s", pmi->parent->Name, uname && *uname ? uname : descr); SKINICONDESC sid={0}; sid.cbSize = sizeof(sid); sid.cx = 16; sid.cy = 16; sid.pszSection = sectionName; sid.pszName = iconame; sid.pszDefaultFile = NULL; sid.pszDescription = buf; sid.hDefaultIcon = hIcon; pmi->hIcolibItem = ( HANDLE )CallService(MS_SKIN2_ADDICON, 0, (LPARAM)&sid); Safe_DestroyIcon( hIcon ); if ( hIcon = ( HICON )CallService( MS_SKIN2_GETICON, 0, (LPARAM)iconame )) { ImageList_ReplaceIcon( pmi->parent->m_hMenuIcons, pmi->iconId, hIcon ); IconLib_ReleaseIcon( hIcon, 0 ); } } #ifdef UNICODE if ( !pmi->UniqName ) mir_free( uname ); mir_free( descr ); #endif return FALSE; }
void MirandaUtils::setStatusOnAccount(ActionThreadArgStruct* args) { logger->log(L"MirandaUtils::setStatusOnAccount: start"); int status = CallProtoService(args->accountSzModuleName, PS_GETSTATUS, 0, 0); logger->log_p(L"SSOA: on account: [%S] targetHandle = [" SCNuPTR L"] at status = [%d]", args->accountSzModuleName, args->targetHandle, status); int result = -1; if (!(CallProtoService(args->accountSzModuleName, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_INDIVMODEMSG)){ result = CallProtoService(args->accountSzModuleName, PS_SETAWAYMSGW, (WPARAM)status, (LPARAM)args->userActionSelection); if (result == CALLSERVICE_NOTFOUND){ char *szMsg = mir_u2a(args->userActionSelection); result = CallProtoService(args->accountSzModuleName, PS_SETAWAYMSG, (WPARAM)status, (LPARAM)szMsg); mir_free(szMsg); } } MirandaAccount* mirandaAccount = args->mirfoxDataPtr->getMirandaAccountPtrBySzModuleName(args->accountSzModuleName); TCHAR* tszAccountName = NULL; if (mirandaAccount){ tszAccountName = mirandaAccount->tszAccountName; } wchar_t* buffer = new wchar_t[1024 * sizeof(wchar_t)]; if(result == 0){ if (tszAccountName != NULL){ logger->log_p(L"SSOA: Status message set on [%s]", tszAccountName); mir_sntprintf(buffer, 1024, TranslateT("Status message set on %s"), tszAccountName); } else { logger->log(L"SSOA: Status message set"); buffer = mir_wstrdup(TranslateT("Status message set")); } if(ServiceExists(MS_POPUP_ADDPOPUPCLASS)) { ShowClassPopupT("MirFox_Notify", TranslateT("MirFox"), buffer); } else { PUShowMessageT(buffer, SM_NOTIFY); } } else { if (tszAccountName != NULL){ logger->log_p(L"SSOA: ERROR - Cannot set status message 2 on [%s] - result = [%d] ", tszAccountName, result); mir_sntprintf(buffer, 1024, TranslateT("Cannot set status message on %s"), tszAccountName); } else { logger->log_p(L"SSOA: ERROR - Cannot set status message 2 - result = [%d] ", result); buffer = mir_wstrdup(TranslateT("Cannot set status message")); } if(ServiceExists(MS_POPUP_ADDPOPUPCLASS)) { ShowClassPopupT("MirFox_Error", TranslateT("MirFox error"), buffer); } else { PUShowMessageT(buffer, SM_WARNING); } } delete buffer; }
void CDropbox::RequestAccountInfo() { HttpRequest *request = new HttpRequest(hNetlibUser, REQUEST_GET, DROPBOX_API_URL "/account/info"); request->AddBearerAuthHeader(db_get_sa(NULL, MODULE, "TokenSecret")); mir_ptr<NETLIBHTTPREQUEST> response(request->Send()); delete request; MCONTACT hContact = CDropbox::GetDefaultContact(); if (response && response->resultCode == HTTP_STATUS_OK) { JSONROOT root(response->pData); if (root) { JSONNODE *node = json_get(root, "referral_link"); if (node) { ptrW referral_link = ptrW(json_as_string(node)); db_set_ws(hContact, MODULE, "Homepage", referral_link); } node = json_get(root, "display_name"); if (node) { ptrW display_name = ptrW(json_as_string(node)); wchar_t *sep = wcsrchr(display_name, L' '); if (sep) { db_set_ws(hContact, MODULE, "LastName", sep + 1); display_name[wcslen(display_name) - wcslen(sep)] = '\0'; db_set_ws(hContact, MODULE, "FirstName", display_name); } else { db_set_ws(hContact, MODULE, "FirstName", display_name); db_unset(hContact, MODULE, "LastName"); } } node = json_get(root, "country"); if (node) { ptrW isocodeW(json_as_string(node)); ptrA isocode(mir_u2a(isocodeW)); if (!strlen(isocode)) db_unset(hContact, MODULE, "Country"); else { char *country = (char *)CallService(MS_UTILS_GETCOUNTRYBYISOCODE, (WPARAM)isocode, 0); db_set_s(hContact, MODULE, "Country", country); } } node = json_get(root, "quota_info"); JSONNODE *nroot = json_as_node(node); if (nroot) { node = json_get(nroot, "shared"); if (node) db_set_dw(hContact, MODULE, "SharedQuota", json_as_int(node)); node = json_get(nroot, "normal"); if (node) db_set_dw(hContact, MODULE, "NormalQuota", json_as_int(node)); node = json_get(nroot, "quota"); if (node) db_set_dw(hContact, MODULE, "TotalQuota", json_as_int(node)); } } } HandleHttpResponseError(hNetlibUser, response); }
int OnDBEventFilterAdd(WPARAM wParam, LPARAM lParam) { HANDLE hContact = (HANDLE)wParam; DBEVENTINFO *dbei = (DBEVENTINFO *)lParam; char *msgblob; POPUPDATA ppdp = {0}; DBTIMETOSTRING tts = {0}; char protoOption[256] = {0}; char *response, *tmp, *challenge; int buflen = MAX_BUFFER_LENGTH; TCHAR buf[MAX_BUFFER_LENGTH]; TCHAR *message = NULL, *challengeW = NULL, *tmpW = NULL; TCHAR *whitelist = NULL, *ptok; TCHAR mexpr[64]; int maxmsglen = 0, a, b, i; BOOL bayesEnabled = _getOptB("BayesEnabled", defaultBayesEnabled); BOOL bCorrectResponse = FALSE; // get hContact from DBEVENTINFO as icq_proto.c doesn't pass hContact the usual way for some reason. if (dbei->eventType == EVENTTYPE_AUTHREQUEST) hContact = *((PHANDLE)(dbei->pBlob+sizeof(DWORD))); // get maximum length of the message a protocol supports maxmsglen = CallProtoService(dbei->szModule, PS_GETCAPS, PFLAG_MAXLENOFMESSAGE, (LPARAM)hContact); /*** Dequeue and learn messages ***/ if (bayesEnabled && _getOptB("BayesAutolearnNotApproved", defaultBayesAutolearnNotApproved)) if (time(NULL) - last_queue_check > 4*3600) { // dequeue every 4 hours dequeue_messages(); last_queue_check = time(NULL); } /*** Check for conditional and unconditional approval ***/ // Pass-through if protocol is not enabled strcat(protoOption, "proto_"); strcat(protoOption, dbei->szModule); if (_getOptB(protoOption, 0) == 0) // Protocol is not handled by Spam-o-tron return 0; // Pass-through if the event is not of type EVENTTYPE_MESSAGE or EVENTTYPE_AUTHREQUEST if (dbei->eventType != EVENTTYPE_MESSAGE && dbei->eventType != EVENTTYPE_AUTHREQUEST) return 0; // Pass-through if contact is already verified. if (_getCOptB(hContact, "Verified", 0) == 1) return 0; // Pass-through if the event is already read. if (dbei->flags & DBEF_READ) return 0; // Pass-through if event is from a contact that is already in the list. if (db_get_b(hContact, "CList", "NotOnList", 1) == 0) // Already in the list return 0; // Pass-through if event is from a contact that is already in the server-side contact list if (db_get_w(hContact, dbei->szModule, "ServerId", 0)) return 0; // Pass-through if contact is a MetaContact if (db_get_dw(hContact, "MetaContacts", "NumContacts", 0)) return 0; // Pass-through and approve if outgoing event. if (dbei->flags & DBEF_SENT) { if (_getOptB("ApproveOnMsgOut", 0)) { _setCOptB(hContact, "Verified", 1); if (_getOptB("AddPermanently", defaultAddPermanently)) db_unset(hContact, "CList", "NotOnList"); db_unset(hContact, "CList", "Delete"); } return 0; } // Hide the contact until verified if option set. if (_getOptB("HideUnverified", defaultHideUnverified)) db_set_b(hContact, "CList", "Hidden", 1); // Fetch the incoming message body if (dbei->eventType == EVENTTYPE_MESSAGE) { msgblob = (char *)dbei->pBlob; } else if (dbei->eventType == EVENTTYPE_AUTHREQUEST) { msgblob = (char *)(dbei->pBlob + sizeof(DWORD) + sizeof(HANDLE)); for(a=4;a>0;a--) msgblob += strlen(msgblob)+1; } if (dbei->flags & DBEF_UTF) message = mir_utf8decodeW(msgblob); else message = mir_a2u(msgblob); /*** Check for words in white-list ***/ if (_getOptB("ApproveOnMsgIn", defaultApproveOnMsgIn)) { whitelist = (TCHAR*)malloc(2048 * sizeof(TCHAR)); if (whitelist != NULL) { _getOptS(whitelist, 2048, "ApproveOnMsgInWordlist", defaultApproveOnMsgInWordlist); if (_isregex(whitelist)) { if (_regmatch(message, whitelist)) bCorrectResponse = TRUE; } else { ptok = _tcstok(whitelist, L" "); while (ptok != NULL) { if (_tcsstr(message, ptok)) { bCorrectResponse = TRUE; break; } ptok = _tcstok(NULL, L" "); } } free(whitelist); if (bCorrectResponse) { _setCOptB(hContact, "Verified", 1); if (_getOptB("HideUnverified", defaultHideUnverified)) db_unset(hContact, "CList", "Hidden"); if (_getOptB("AddPermanently", defaultAddPermanently)) db_unset(hContact, "CList", "NotOnList"); db_unset(hContact, "CList", "Delete"); if (_getOptB("ReplyOnSuccess", defaultReplyOnSuccess) && (_getCOptB(hContact, "MsgSent", 0))) { tmp = mir_u2a(_getOptS(buf, buflen, "SuccessResponse", defaultSuccessResponse)); response = mir_utf8encode(tmp); mir_free(tmp); CallContactService(hContact, PSS_MESSAGE, PREF_UTF, (LPARAM)response); mir_free(response); } return 0; } } } /*** Check for correct answer ***/ switch (_getOptB("Mode", defaultMode)) { case SPAMOTRON_MODE_ROTATE: case SPAMOTRON_MODE_RANDOM: get_response(buf, buflen, _getCOptD(hContact, "ResponseNum", 0)); if (_isregex(buf)) { if (_regmatch(message, buf)) bCorrectResponse = TRUE; } else { if (_tcsstr_cc(message, buf, _getOptB("ResponseCC", defaultResponseCC)) && (_tcslen(message) == _tcslen(buf))) bCorrectResponse = TRUE; } break; case SPAMOTRON_MODE_PLAIN: _getOptS(buf, buflen, "Response", defaultResponse); i = get_response_num(buf); while (i-- > 0) { get_response(buf, buflen, i-1); if (_isregex(buf)) { if (_regmatch(message, buf)) { bCorrectResponse = TRUE; break; } } else { if (_tcsstr_cc(message, buf, _getOptB("ResponseCC", defaultResponseCC)) && (_tcslen(message) == _tcslen(buf))) { bCorrectResponse = TRUE; break; } } } break; case SPAMOTRON_MODE_MATH: if (message == NULL) break; _itot(_getCOptD(hContact, "ResponseMath", -1), buf, 10); if (_tcsstr(message, buf) && (_tcslen(buf) == _tcslen(message))) { bCorrectResponse = TRUE; } break; } if (bCorrectResponse) { _setCOptB(hContact, "Verified", 1); if (_getOptB("HideUnverified", defaultHideUnverified)) db_unset(hContact, "CList", "Hidden"); if (_getOptB("AddPermanently", defaultAddPermanently)) db_unset(hContact, "CList", "NotOnList"); db_unset(hContact, "CList", "Delete"); db_unset(hContact, "CList", "ResponseNum"); if (_getOptB("ReplyOnSuccess", defaultReplyOnSuccess)) { tmp = mir_u2a(_getOptS(buf, buflen, "SuccessResponse", defaultSuccessResponse)); response = mir_utf8encode(tmp); mir_free(tmp); CallContactService(hContact, PSS_MESSAGE, PREF_UTF, (LPARAM)response); mir_free(response); } _notify(hContact, POPUP_APPROVED, TranslateT("Contact %s approved."), NULL); // Resubmit pending authorization request if (_getCOptB(hContact, "AuthEventPending", FALSE)) { DBVARIANT _dbv; TCHAR AuthEventModule[100]; char* szAuthEventModule; if (db_get(hContact, PLUGIN_NAME, "AuthEvent", &_dbv) == 0) { DBEVENTINFO *_dbei = (DBEVENTINFO *)malloc(sizeof(DBEVENTINFO)); if (_dbei != NULL) { memcpy(&_dbei->cbBlob, _dbv.pbVal, sizeof(DWORD)); _dbei->eventType = EVENTTYPE_AUTHREQUEST; _getCOptS(AuthEventModule, 100, hContact, "AuthEventModule", _T("ICQ")); szAuthEventModule = mir_u2a(AuthEventModule); _dbei->szModule = szAuthEventModule; _dbei->timestamp = dbei->timestamp; _dbei->flags = 0; _dbei->cbSize = sizeof(DBEVENTINFO); _dbei->pBlob = _dbv.pbVal + sizeof(DWORD); db_event_add(hContact,_dbei); db_unset(hContact, PLUGIN_NAME, "AuthEvent"); db_unset(hContact, PLUGIN_NAME, "AuthEventPending"); db_unset(hContact, PLUGIN_NAME, "AuthEventModule"); mir_free(szAuthEventModule); free(_dbei); } db_free(&_dbv); } } // User approved, learn from previous messages if (bayesEnabled && _getOptB("BayesAutolearnApproved", defaultBayesAutolearnApproved)) bayes_approve_contact(hContact); // Mark previous messages unread if option set if (_getOptB("KeepBlockedMsg", defaultKeepBlockedMsg) && _getOptB("MarkMsgUnreadOnApproval", defaultMarkMsgUnreadOnApproval) && hContact != NULL) { // We will mark unread all blocked messages for the most recent day MarkUnread(hContact); } return 1; } /*** Check for rejection ***/ // Completely reject if challenge was already sent today for MaxMsgContactCountPerDay times // and the option is turned on. if (isOneDay(dbei->timestamp, _getCOptD(hContact, "MsgSentTime", 0)) && _getOptD("MaxMsgContactCountPerDay", defaultMaxMsgContactCountPerDay) > 0 && _getCOptD(hContact, "MsgSent", 0) >= _getOptD("MaxMsgContactCountPerDay", defaultMaxMsgContactCountPerDay)) { _notify(hContact, POPUP_BLOCKED, TranslateT("Message from %s rejected because it reached a maximum for challenge requests per day."), message); if (bayesEnabled) queue_message(hContact, dbei->timestamp, message); return 1; } // Completely reject if duplicate incoming message found if (_getOptD("MaxSameMsgCountPerDay", defaultMaxSameMsgCountPerDay) > 0 && _getCOptD(hContact, "SameMsgCount", 0) >= _getOptD("MaxSameMsgCountPerDay", defaultMaxSameMsgCountPerDay) && _tcscmp(message, _getCOptS(buf, buflen, hContact, "LastInMsg", _T(""))) == 0) { _notify(hContact, POPUP_BLOCKED, TranslateT("Message from %s rejected because it reached a maximum for same responses per day."), message); if (bayesEnabled) queue_message(hContact, dbei->timestamp, message); return 1; } // Completely reject if incoming message contains any word from DontReplyMsgWordlist option if (_getOptB("DontReplyMsg", defaultDontReplyMsg) && Contains(message, _getOptS(buf, buflen, "DontReplyMsgWordlist", defaultDontReplyMsgWordlist))) { _notify(hContact, POPUP_BLOCKED, TranslateT("Message from %s dropped because it has a word from black list."), message); return 1; } /*** Bayes checks ***/ // Drop if score > spam score if (bayesEnabled && _getOptB("BayesBlockMsg", defaultBayesBlockMsg)) if (get_msg_score(message) >= (double)_getOptD("BayesSpamScore", defaultBayesSpamScore) * SCORE_C) { _notify(hContact, POPUP_BLOCKED, TranslateT("Message from %s dropped because of high spam score."), message); if (bayesEnabled && _getOptB("BayesAutolearnNotApproved", defaultBayesAutolearnNotApproved)) queue_message(hContact, dbei->timestamp, message); return 1; } // Accept if score < ham score if (bayesEnabled && _getOptB("BayesAutoApprove", defaultBayesAutoApprove)) if (get_msg_score(message) <= (double)_getOptD("BayesHamScore", defaultBayesHamScore) * SCORE_C) { _notify(hContact, POPUP_APPROVED, TranslateT("Contact %s approved."), message); _setCOptB(hContact, "Verified", 1); if (_getOptB("HideUnverified", defaultHideUnverified)) db_unset(hContact, "CList", "Hidden"); if (_getOptB("AddPermanently", defaultAddPermanently)) db_unset(hContact, "CList", "NotOnList"); db_unset(hContact, "CList", "Delete"); if (bayesEnabled && _getOptB("BayesAutolearnApproved", defaultBayesAutolearnApproved) && _getOptB("BayesAutolearnAutoApproved", defaultBayesAutolearnAutoApproved)) { queue_message(hContact, dbei->timestamp, message); bayes_approve_contact(hContact); } return 0; } // Accept if event is EVENTTYPE_AUTHREQUEST and ReplyOnAuth is NOT set if (dbei->eventType == EVENTTYPE_AUTHREQUEST && !_getOptB("ReplyOnAuth", defaultReplyOnAuth)) return 0; // Accept if event is EVENTTYPE_MESSAGE and ReplyOnMsg is NOT set if (dbei->eventType == EVENTTYPE_MESSAGE && !_getOptB("ReplyOnMsg", defaultReplyOnMsg)) return 0; /*** Send Challenge ***/ challengeW = (TCHAR *)malloc(maxmsglen*sizeof(TCHAR)); tmpW = (TCHAR *)malloc(maxmsglen*sizeof(TCHAR)); switch (_getOptB("Mode", defaultMode)) { case SPAMOTRON_MODE_PLAIN: if (dbei->eventType == EVENTTYPE_AUTHREQUEST) _getOptS(challengeW, maxmsglen, "AuthChallenge", defaultAuthChallenge); else _getOptS(challengeW, maxmsglen, "Challenge", defaultChallenge); ReplaceVars(challengeW, maxmsglen); tmp = mir_u2a(challengeW); challenge = mir_utf8encode(tmp); mir_free(tmp); CallContactService(hContact, PSS_MESSAGE, PREF_UTF, (LPARAM)challenge); mir_free(challenge); _notify(hContact, POPUP_CHALLENGE, TranslateT("Sending plain challenge to %s."), message); break; case SPAMOTRON_MODE_ROTATE: if (dbei->eventType == EVENTTYPE_AUTHREQUEST) _getOptS(challengeW, maxmsglen, "AuthChallenge", defaultAuthChallenge); else _getOptS(challengeW, maxmsglen, "Challenge", defaultChallenge); _getOptS(buf, buflen, "Response", defaultResponse); if (_getCOptD(hContact, "ResponseNum", 0) >= (unsigned int)(get_response_num(buf)-1)) { _setCOptD(hContact, "ResponseNum", -1); } _setCOptD(hContact, "ResponseNum", _getCOptD(hContact, "ResponseNum", -1) + 1); ReplaceVarsNum(challengeW, maxmsglen, _getCOptD(hContact, "ResponseNum", 0)); tmp = mir_u2a(challengeW); challenge = mir_utf8encode(tmp); mir_free(tmp); CallContactService(hContact, PSS_MESSAGE, PREF_UTF, (LPARAM)challenge); mir_free(challenge); _notify(hContact, POPUP_CHALLENGE, TranslateT("Sending round-robin challenge to %s."), message); break; case SPAMOTRON_MODE_RANDOM: if (dbei->eventType == EVENTTYPE_AUTHREQUEST) _getOptS(challengeW, maxmsglen, "AuthChallenge", defaultAuthChallenge); else _getOptS(challengeW, maxmsglen, "Challenge", defaultChallenge); _getOptS(buf, buflen, "Response", defaultResponse); srand(time(NULL)); _setCOptD(hContact, "ResponseNum", rand() % get_response_num(buf)); ReplaceVarsNum(challengeW, maxmsglen, _getCOptD(hContact, "ResponseNum", 0)); tmp = mir_u2a(challengeW); challenge = mir_utf8encode(tmp); mir_free(tmp); CallContactService(hContact, PSS_MESSAGE, PREF_UTF, (LPARAM)challenge); mir_free(challenge); _notify(hContact, POPUP_CHALLENGE, TranslateT("Sending random challenge to %s."), message); break; case SPAMOTRON_MODE_MATH: a = (rand() % 10) + 1; b = (rand() % 10) + 1; mir_sntprintf(mexpr, sizeof(mexpr), _T("%d + %d"), a, b); if (dbei->eventType == EVENTTYPE_AUTHREQUEST) _getOptS(challengeW, maxmsglen, "AuthChallengeMath", defaultAuthChallengeMath); else _getOptS(challengeW, maxmsglen, "ChallengeMath", defaultChallengeMath); ReplaceVar(challengeW, maxmsglen, _T("%mathexpr%"), mexpr); _setCOptD(hContact, "ResponseMath", a + b); tmp = mir_u2a(challengeW); challenge = mir_utf8encode(tmp); mir_free(tmp); CallContactService(hContact, PSS_MESSAGE, PREF_UTF, (LPARAM)challenge); mir_free(challenge); _notify(hContact, POPUP_CHALLENGE, TranslateT("Sending math expression challenge to %s."), message); break; } free(challengeW); free(tmpW); // As a workaround for temporary NotOnList contact not being deleted from server-side list // (which was added by the ICQ server itself upon first outgoing challenge request message) // we need to set Delete setting, so that contacts gets deleted on next restart/connect. db_set_b(hContact, "CList", "Delete", 1); // Queue user message in Bayes db if (bayesEnabled && message != NULL) queue_message(hContact, dbei->timestamp, message); /*** Do any post-send procedures we need to do ***/ // Increment MsgSent if it was sent the same day. Otherwise set it to 1. if (isOneDay(dbei->timestamp, _getCOptD(hContact, "MsgSentTime",0))) _setCOptD(hContact, "MsgSent", _getCOptD(hContact, "MsgSent", 0)+1); else _setCOptD(hContact, "MsgSent", 1); _setCOptD(hContact, "MsgSentTime", dbei->timestamp); // Save Last Msg and update SameMsgCount if (message != NULL) { if (_tcscmp(_getCOptS(buf, buflen, hContact, "LastInMsg", _T("")), message) == 0) _setCOptD(hContact, "SameMsgCount", 1+_getCOptD(hContact, "SameMsgCount", 0)); else _setCOptD(hContact, "SameMsgCount", 1); _setCOptTS(hContact, "LastInMsg", message); } if (message != NULL) mir_free(message); // Finally silently save the message to contact history if corresponding option is set if (_getOptB("KeepBlockedMsg", defaultKeepBlockedMsg)) { if (dbei->eventType == EVENTTYPE_AUTHREQUEST) { // Save the request to database so that it can be automatically submitted on user approval PBYTE eventdata = (PBYTE)malloc(sizeof(DWORD) + dbei->cbBlob); if (eventdata != NULL && dbei->cbBlob > 0) { memcpy(eventdata, &dbei->cbBlob, sizeof(DWORD)); memcpy(eventdata + sizeof(DWORD), dbei->pBlob, dbei->cbBlob); db_set_blob(hContact, PLUGIN_NAME, "AuthEvent", eventdata, sizeof(DWORD) + dbei->cbBlob); _setCOptS(hContact, "AuthEventModule", dbei->szModule); _setCOptB(hContact, "AuthEventPending", TRUE); free(eventdata); } } else { if (_getOptB("MarkMsgUnreadOnApproval", defaultMarkMsgUnreadOnApproval)) { DBVARIANT _dbv; DWORD dbei_size = 3*sizeof(DWORD) + sizeof(WORD) + dbei->cbBlob + (DWORD)strlen(dbei->szModule)+1; PBYTE eventdata = (PBYTE)malloc(dbei_size); PBYTE pos = eventdata; if (eventdata != NULL && dbei->cbBlob > 0) { if (db_get(hContact, PLUGIN_NAME, "LastMsgEvents", &_dbv) == 0) { eventdata = (PBYTE)realloc(eventdata, dbei_size + _dbv.cpbVal); pos = eventdata; memcpy(eventdata, _dbv.pbVal, _dbv.cpbVal); pos += _dbv.cpbVal; db_free(&_dbv); } memcpy(pos, &dbei->eventType, sizeof(WORD)); memcpy(pos+sizeof(WORD), &dbei->flags, sizeof(DWORD)); memcpy(pos+sizeof(WORD)+sizeof(DWORD), &dbei->timestamp, sizeof(DWORD)); memcpy(pos+sizeof(WORD)+sizeof(DWORD)*2, dbei->szModule, strlen(dbei->szModule)+1); memcpy(pos+sizeof(WORD)+sizeof(DWORD)*2+strlen(dbei->szModule)+1, &dbei->cbBlob, sizeof(DWORD)); memcpy(pos+sizeof(WORD)+sizeof(DWORD)*3+strlen(dbei->szModule)+1, dbei->pBlob, dbei->cbBlob); db_set_blob(hContact, PLUGIN_NAME, "LastMsgEvents", eventdata, (pos - eventdata) + dbei_size); free(eventdata); } } else { dbei->flags |= DBEF_READ; db_event_add(hContact, dbei); } } } return 1; }
TCHAR* ReplaceVarsNum(TCHAR *dst, unsigned int len, int num) { TCHAR response[2048]; int ret, i = 1; pcre *re; const char *error; int erroroffs, rc; char *_str, *tmp; TCHAR **r; TCHAR *ttmp, *dstcopy; int opts = 0; char regex[] = "%response([#-_]([0-9]+))?%"; int ovector[9]; re = pcre_compile(regex, 0, &error, &erroroffs, NULL); if (!re) return FALSE; // [TODO] and log some error _getOptS(response, 2048, "Response", defaultResponse); r = (TCHAR**)malloc(sizeof(char*)); ttmp = _tcstok(response, L"\r\n"); r[0] = ttmp; while(ttmp) { ttmp = _tcstok(NULL, L"\r\n"); if (ttmp != NULL) { r = (TCHAR**)realloc(r, (i+1)*sizeof(TCHAR*)); r[i++] = ttmp; } } do { _str = mir_u2a(dst); dstcopy = (TCHAR*)malloc((_tcslen(dst)+1)*sizeof(TCHAR)); _tcscpy(dstcopy, dst); rc = pcre_exec(re, NULL, _str, (int)strlen(_str), 0, 0, ovector, 9); if (rc < 0) { ret = -1; } else if (rc == 3) { ttmp = dstcopy + ovector[0]; ttmp[ovector[1]-ovector[0]] = 0; tmp = _str + ovector[4]; tmp[ovector[5]-ovector[4]] = 0; ret = atoi(tmp); } else { ttmp = dstcopy + ovector[0]; ttmp[ovector[1]-ovector[0]] = 0; ret = 0; } if (ret >= 0) { if (ret > i) ReplaceVar(dst, len, ttmp, r[0]); else if (ret == 0 && num > 0 && num < i) ReplaceVar(dst, len, ttmp, r[num]); else ReplaceVar(dst, len, ttmp, r[ret == 0 ? 0 : ret-1]); } if (_str) mir_free(_str); if (dstcopy) free(dstcopy); } while (rc >= 0); if (re) pcre_free(re); return dst; }
INT_PTR StatusMenuCheckService(WPARAM wParam, LPARAM) { PCheckProcParam pcpp = (PCheckProcParam)wParam; if (!pcpp) return TRUE; PMO_IntMenuItem timi = MO_GetIntMenuItem(pcpp->MenuItemHandle); if (!timi) return TRUE; StatusMenuExecParam *smep = (StatusMenuExecParam*)pcpp->MenuItemOwnerData; if (smep && !smep->status && smep->custom) { if (wildcmp(smep->svc, "*XStatus*")) { int XStatus; CUSTOM_STATUS cs = { sizeof(cs) }; cs.flags = CSSF_MASK_STATUS; cs.status = &XStatus; if (CallProtoServiceInt(NULL, smep->proto, PS_GETCUSTOMSTATUSEX, 0, (LPARAM)&cs) != 0) XStatus = 0; char buf[255]; mir_snprintf(buf, SIZEOF(buf), "*XStatus%d", XStatus); bool check = wildcmp(smep->svc, buf) != 0; bool reset = wildcmp(smep->svc, "*XStatus0") != 0; if (check) timi->mi.flags |= CMIF_CHECKED; else timi->mi.flags &= ~CMIF_CHECKED; if (reset || check) { PMO_IntMenuItem timiParent = MO_GetIntMenuItem(timi->mi.root); if (timiParent) { CLISTMENUITEM mi2 = { sizeof(mi2) }; mi2.flags = CMIM_NAME | CMIF_TCHAR; mi2.ptszName = TranslateTH(timi->mi.hLangpack, timi->mi.hIcon ? timi->mi.ptszName : LPGENT("Custom status")); timiParent = MO_GetIntMenuItem(timi->mi.root); MenuItemData it = { 0 }; if (FindMenuHandleByGlobalID(hStatusMenu, timiParent, &it)) { MENUITEMINFO mi = { 0 }; TCHAR d[100]; GetMenuString(it.OwnerMenu, it.position, d, SIZEOF(d), MF_BYPOSITION); mi.cbSize = sizeof(mi); mi.fMask = MIIM_STRING | MIIM_STATE; if (timi->iconId != -1) { mi.fMask |= MIIM_BITMAP; if (IsWinVerVistaPlus() && IsThemeActive()) { if (timi->hBmp == NULL) timi->hBmp = ConvertIconToBitmap(NULL, timi->parent->m_hMenuIcons, timi->iconId); mi.hbmpItem = timi->hBmp; } else mi.hbmpItem = HBMMENU_CALLBACK; } mi.fState |= (check && !reset ? MFS_CHECKED : MFS_UNCHECKED); mi.dwTypeData = mi2.ptszName; SetMenuItemInfo(it.OwnerMenu, it.position, TRUE, &mi); } Menu_ModifyItem(timi->mi.root, &mi2); timiParent->iconId = timi->iconId; if (timiParent->hBmp) DeleteObject(timiParent->hBmp); timiParent->hBmp = NULL; } } } } else if (smep && smep->status && !smep->custom) { int curProtoStatus = (smep->proto) ? CallProtoServiceInt(NULL, smep->proto, PS_GETSTATUS, 0, 0) : cli.pfnGetAverageMode(NULL); if (smep->status == curProtoStatus) timi->mi.flags |= CMIF_CHECKED; else timi->mi.flags &= ~CMIF_CHECKED; } else if ((!smep || smep->proto) && timi->mi.pszName) { int curProtoStatus = 0; BOOL IconNeedDestroy = FALSE; char* prot; if (smep) prot = smep->proto; else { char *prn = mir_u2a(timi->mi.ptszName); prot = NEWSTR_ALLOCA(prn); if (prn) mir_free(prn); } if (Proto_GetAccount(prot) == NULL) return TRUE; if ((curProtoStatus = CallProtoServiceInt(NULL, prot, PS_GETSTATUS, 0, 0)) == CALLSERVICE_NOTFOUND) curProtoStatus = 0; if (curProtoStatus >= ID_STATUS_OFFLINE && curProtoStatus < ID_STATUS_IDLE) timi->mi.hIcon = LoadSkinProtoIcon(prot, curProtoStatus); else { timi->mi.hIcon = (HICON)CallProtoServiceInt(NULL, prot, PS_LOADICON, PLI_PROTOCOL | PLIF_SMALL, 0); if (timi->mi.hIcon == (HICON)CALLSERVICE_NOTFOUND) timi->mi.hIcon = NULL; else IconNeedDestroy = TRUE; } if (timi->mi.hIcon) { timi->mi.flags |= CMIM_ICON; MO_ModifyMenuItem(timi, &timi->mi); if (IconNeedDestroy) { DestroyIcon(timi->mi.hIcon); timi->mi.hIcon = NULL; } else IcoLib_ReleaseIcon(timi->mi.hIcon, 0); } } return TRUE; }