Esempio n. 1
0
int NFAReferenceUNode::match(const CMString & str, WCMatcher * matcher, const int curInd) const
{
	int len = matcher->ends[gi] - matcher->starts[gi];
	int ni = -1;
	if (gi < 1 || matcher->ends[gi] < matcher->starts[gi] || len == 0)   ni = curInd;
	else if (curInd + len > (int)str.GetLength())                        return -1;
	else if (str.Mid(curInd, len) != str.Mid(matcher->starts[gi], len))  return -1;
	else                                                                 ni = curInd + len;

	return next->match(str, matcher, ni);
}
Esempio n. 2
0
CVKNewsItem* CVkProto::GetVkNotificationsItem(const JSONNode &jnItem, OBJLIST<CVkUserInfo> &vkUsers)
{
    debugLogA("CVkProto::GetVkNotificationsItem");
    if (!jnItem)
        return NULL;

    CMString tszType(jnItem["type"].as_mstring());
    VKObjType vkFeedbackType = vkNull, vkParentType = vkNull;
    CMString tszNotificationTranslate = SpanVKNotificationType(tszType, vkFeedbackType, vkParentType);

    const JSONNode &jnFeedback = jnItem["feedback"];
    const JSONNode &jnParent = jnItem["parent"];

    if (!jnFeedback || !jnParent)
        return NULL;

    CVkUserInfo *vkUser = NULL;
    CMString tszFeedback = GetVkFeedback(jnFeedback, vkFeedbackType, vkUsers, vkUser);
    CVKNewsItem* vkNotification = GetVkParent(jnParent, vkParentType);

    if (!vkNotification)
        return NULL;

    if (vkNotification && !tszFeedback.IsEmpty()) {
        CMString tszNotificaton;
        tszNotificaton.AppendFormat(tszFeedback, tszNotificationTranslate, vkNotification->tszText);
        vkNotification->tszText = tszNotificaton;

        tszFeedback = RemoveBBC(tszFeedback);
        int idx = tszFeedback.Find(_T(" %s %s"));

        vkNotification->tszPopupTitle.AppendFormat(_T("%s %s"), tszFeedback.Mid(0, idx), tszNotificationTranslate);
        if (tszFeedback.GetLength() > idx + 7) {
            if (!vkNotification->tszPopupText.IsEmpty())
                vkNotification->tszPopupText += _T("\n>> ");
            vkNotification->tszPopupText += tszFeedback.Mid(idx + 7, tszFeedback.GetLength() - idx - 7);
        }

        vkNotification->tszType = tszType;
        vkNotification->tDate = jnItem["date"].as_int();
        vkNotification->vkFeedbackType = vkFeedbackType;
        vkNotification->vkParentType = vkParentType;
        vkNotification->vkUser = vkUser;
        return vkNotification;
    }

    delete vkNotification;
    return NULL;
}
Esempio n. 3
0
CMString WCPattern::replace(const CMString & str, const CMString & replacementText)
{
	int li = 0;
	CMString ret;

	matcher->setString(str);
	while (matcher->findNextMatch()) {
		ret += str.Mid(li, matcher->getStartingIndex() - li);
		ret += matcher->replaceWithGroups(replacementText);
		li = matcher->getEndingIndex();
	}
	ret += str.Mid(li);

	return ret;
}
Esempio n. 4
0
int NFALookBehindUNode::match(const CMString & str, WCMatcher * matcher, const int curInd) const
{
	if (pos) {
		if (curInd < mStr.GetLength())
			return -1;
		if (str.Mid(curInd - mStr.GetLength(), mStr.GetLength()) == mStr)
			return next->match(str, matcher, curInd);
	}
	else {
		if (curInd < mStr.GetLength())
			return next->match(str, matcher, curInd);
		if (str.Mid(curInd - mStr.GetLength(), mStr.GetLength()) == mStr)
			return -1;
		return next->match(str, matcher, curInd);
	}
	return -1;
}
Esempio n. 5
0
void SmileyCategoryListType::AddAllProtocolsAsCategory(void)
{
	CMString displayName = TranslateT("Standard");
	CMString tname = _T("Standard");
	AddCategory(tname, displayName, smcStd);

	const CMString &defaultFile = GetSmileyCategory(tname)->GetFilename();

	PROTOCOLDESCRIPTOR **proto;
	int protoCount = 0;
	Proto_EnumProtocols(&protoCount, &proto);

	for (int i = 0; i < protoCount; i++) {
		PROTOCOLDESCRIPTOR *pd = proto[i];
		if (pd->type == PROTOTYPE_PROTOCOL && pd->cbSize == sizeof(*pd))
			AddProtoAsCategory(pd->szName, defaultFile);
	}

	PROTOACCOUNT **accList;
	Proto_EnumAccounts(&protoCount, &accList);
	for (int i = 0; i < protoCount; i++)
		AddAccountAsCategory(accList[i], defaultFile);

	for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact))
		AddContactTransportAsCategory(hContact, defaultFile);

	CMString cats;
	opt.ReadCustomCategories(cats);

	int cppv = 0;
	for (;;) {
		int cp = cats.Find('#', cppv);
		if (cp == -1)
			break;

		displayName = cats.Mid(cppv, cp - cppv);
		AddCategory(displayName, displayName, smcCustom, defaultFile);
		cppv = cp + 1;
	}

	if (cppv != cats.GetLength()) {
		displayName = cats.Mid(cppv);
		AddCategory(displayName, displayName, smcCustom, defaultFile);
	}
}
Esempio n. 6
0
CMString WCPattern::parseEscape(bool & inv, bool & quo)
{
	wchar_t ch = pattern[curInd++];
	CMString classes;

	if (curInd > pattern.GetLength()) {
		raiseError();
		return "";
	}

	quo = 0;
	inv = 0;
	switch (ch) {
		case 'p': classes = parsePosix();                                                         break;
		case 'P': classes = L"!!"; classes += parsePosix();                                        break;
		case 'd': classes = L"0123456789";                                                         break;
		case 'D': classes = L"!!0123456789";                                                       break;
		case 's': classes = L" \t\r\n\f";                                                          break;
		case 'S': classes = L"!! \t\r\n\f";                                                        break;
		case 'w': classes = L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";    break;
		case 'W': classes = L"!!abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";  break;
		case '0': classes = parseOctal(); break;
		case 'x': classes = parseHex();   break;
		  
		case 'Q': quo = 1;        break;
		case 't': classes = L"\t"; break;
		case 'r': classes = L"\r"; break;
		case 'n': classes = L"\n"; break;
		case 'f': classes = L"\f"; break;
		case 'a': classes = L"\a"; break;
		case 'e': classes = L"\r"; break;
		default:  classes.AppendChar(ch); break;
	}

	if (classes.Mid(0, 2) == L"!!") {
		classes = classes.Mid(2);
		inv = 1;
	}
	return classes;
}
Esempio n. 7
0
std::vector<CMString> WCPattern::split(const CMString & str, const bool keepEmptys, const unsigned long limit)
{
	unsigned long lim = (limit == 0 ? MAX_QMATCH : limit);
	int li = 0;
	std::vector<CMString> ret;

	matcher->setString(str);

	while (matcher->findNextMatch() && ret.size() < lim) {
		if (matcher->getStartingIndex() == 0 && keepEmptys) ret.push_back(L"");
		if ((matcher->getStartingIndex() != matcher->getEndingIndex()) || keepEmptys) {
			if (li != matcher->getStartingIndex() || keepEmptys)
				ret.push_back(str.Mid(li, matcher->getStartingIndex() - li));

			li = matcher->getEndingIndex();
		}
	}

	if (li < str.GetLength())
		ret.push_back(str.Mid(li));

	return ret;
}
Esempio n. 8
0
int NFAEndOfInputUNode::match(const CMString & str, WCMatcher * matcher, const int curInd) const
{
	int len = str.GetLength();
	if (curInd == len) return next->match(str, matcher, curInd);
	else if (term)
	{
		if (curInd == len - 1 && (str[curInd] == '\r' || str[curInd] == '\n'))
		{
			return next->match(str, matcher, curInd);
		}
		else if (curInd == len - 2 && str.Mid(curInd, 2) == L"\r\n")
		{
			return next->match(str, matcher, curInd);
		}
	}
	return -1;
}
Esempio n. 9
0
INT_PTR CALLBACK DlgProcOptionsPage(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch(uMsg) {
	case WM_INITDIALOG:
		{
			char key[64];
			int count = 0;
			CMString replies;

			TranslateDialogDefault(hwndDlg);
			variables_skin_helpbutton(hwndDlg, IDC_VARIABLES);
			ShowWindow(GetDlgItem(hwndDlg, IDC_VARIABLES_HINT), ServiceExists(MS_VARS_FORMATSTRING));

			mir_subclassWindow(GetDlgItem(hwndDlg, IDC_REPLIES), MessageEditSubclassProc);

			mir_snprintf(key, _countof(key), "ImmediatelySend_%x", iNumber);
			CheckDlgButton(hwndDlg, IDC_IMMEDIATELY, db_get_w(NULL, MODULE, key, 1) ? BST_CHECKED : BST_UNCHECKED);

			mir_snprintf(key, _countof(key), "RepliesCount_%x", iNumber);
			count = db_get_w(NULL, MODULE, key, 0);

			for (int i = 0; i < count; i++)
			{
				mir_snprintf(key, _countof(key), "Reply_%x_%x", iNumber, i);
				wchar_t *value = db_get_wsa(NULL, MODULE, key);
				if (value)
				{
					replies.Append(value);
					replies.Append(_T("\r\n"));
				}
				mir_free(value);
			}
			SetDlgItemText(hwndDlg, IDC_REPLIES, replies.GetBuffer());
		}
		return TRUE;

	case WM_COMMAND:
		if (HIWORD(wParam) == BN_CLICKED) {
			switch(LOWORD(wParam)) {
			case IDC_VARIABLES:
				variables_showhelp(hwndDlg, IDC_REPLIES, VHF_SIMPLEDLG, NULL, NULL);
				break;

			case IDC_IMMEDIATELY:
				SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
				break;
			}
		}
		break;

	case WM_NOTIFY:
		{
			NMHDR *p = ((LPNMHDR)lParam);

			switch (p->code) {
			case PSN_APPLY:
				{
					char key[64];
					int count = 0;
					wchar_t *tszReplies;

					mir_snprintf(key, _countof(key), "RepliesCount_%x", iNumber);
					count = db_get_b(NULL, MODULE, key, 0);

					for (int i = 0; i < count; i++)
					{
						mir_snprintf(key, _countof(key), "Reply_%x_%x", iNumber, i);
						db_unset(NULL, MODULE, key);
					}

					int length = SendDlgItemMessage(hwndDlg, IDC_REPLIES, WM_GETTEXTLENGTH, 0, 0);
					tszReplies = (wchar_t*)mir_alloc(sizeof(wchar_t)* (length + 1));
					GetDlgItemText(hwndDlg, IDC_REPLIES, tszReplies, length + 1);
					tszReplies[length] = '\0';
					{
						CMString replies = tszReplies;
						if (replies.Right(2) != _T("\r\n"))
							replies.Append(_T("\r\n"));

						count = 0;
						int pos = -1, prev = 0;
						while ((pos = replies.Find(_T("\r\n"), prev)) != -1)
						{
							mir_snprintf(key, _countof(key), "Reply_%x_%x", iNumber, count++);
							db_set_ws(NULL, MODULE, key, replies.Mid(prev, pos - prev).GetBuffer());
							prev = pos + 2;
						}
					}
					mir_free(tszReplies);

					mir_snprintf(key, _countof(key), "RepliesCount_%x", iNumber);
					db_set_w(NULL, MODULE, key, count);

					mir_snprintf(key, _countof(key), "ImmediatelySend_%x", iNumber);
					db_set_b(NULL, MODULE, key, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_IMMEDIATELY));

					return TRUE;
				}
				break;
			}
		}
		break;
	}

	if (HIWORD(wParam) == EN_CHANGE && GetFocus() == (HWND)lParam)
		SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);

	return FALSE;
}
Esempio n. 10
0
int NFACIQuoteUNode::match(const CMString & str, WCMatcher * matcher, const int curInd) const
{
	if (curInd + qStr.GetLength() > str.GetLength()) return -1;
	if (str_icmp(str.Mid(curInd, qStr.GetLength()).c_str(), qStr.c_str())) return -1;
	return next->match(str, matcher, qStr.GetLength());
}
Esempio n. 11
0
int NFAQuoteUNode::match(const CMString & str, WCMatcher * matcher, const int curInd) const
{
	if (curInd + qStr.GetLength() > str.GetLength()) return -1;
	if (str.Mid(curInd, qStr.GetLength()) != qStr) return -1;
	return next->match(str, matcher, curInd + qStr.GetLength());
}
Esempio n. 12
0
void CMWebImage::FormatFilePath(const char* sUrl)
{
	m_sFilePath.Empty();
	CMString url = sUrl;
    INT32 pos = url.ReverseFind(L"/");
    if(pos < 0)
        return;
	m_sFilePath = CMPath(CMPath::TEMP_PATH).String() + CMFile::GetTempFileName(url, L"") + "@2x." + CMFile::GetFileExt(url.Mid(pos+1));
}
Esempio n. 13
0
void CMHttpSNotify::OnResponse(UINT32 nCode, const CMHTTPRspHeader* pRespHeader)
{
    UINT32 nRet = MER_OK;
    if (nCode == MER_OK)
    {
        ASSERT(pRespHeader != NULL);

        UINT32 httpRet = pRespHeader->GetHttpReturn();

        if (httpRet == 200 || httpRet == 206)
        {
            CMString sVal;

            //判断是否wap网关的无聊返回,如果是则继续请求一次
            if (pRespHeader->GetValue(HH_CTYPE, sVal))
            {
                if (sVal.Find(L"text/vnd.wap.wml") >= 0)
                {
                    m_pHttpC->Request();
                    return;
                }
            }            

            sVal.Empty();
            pRespHeader->GetValue(HH_CRANGE, sVal);

            sVal.Trim();

            CMHTTPRspHeader header;
            header.SetRet(200, CMString("OK"));
            header.AddValue(HH_CTYPE, L"application/x-shockwave-flash");

            if (!sVal.IsEmpty())
            {
                INT32 nPos1 = sVal.Find(L" ");
                INT32 nPos2 = sVal.Find(L"-");
                INT32 nPos3 = sVal.Find(L"/");
                if (nPos1 <= 0 || nPos2 <= 0 || nPos3 <= 0)
                {
                    CM_ERRP("CMHttpSNotify::OnResponse wrong content-range %s", (const CHAR*)sVal);
                    goto err;
                }

                m_nStart= _mwtoi((const WCHAR*)sVal.Mid(nPos1 + 1, nPos2 - nPos1 - 1));
                m_nEnd = _mwtoi((const WCHAR*)sVal.Mid(nPos2 + 1, nPos3 - nPos2 - 1));
                m_nSize = m_nEnd - m_nStart + 1;

                if (m_nTotalSize == 0)
                {
                    //对于第一次http返回,需要返回结果给socket
                    m_nTotalSize = _mwtoi((const WCHAR*)sVal.Mid(nPos3 + 1));
                    CMString sSendSize;
                    sSendSize.Format(L"%d", m_nTotalSize);
                    header.AddValue(HH_CLENGTH, sSendSize);
                    CMString sHeader = header.ToString();

                    CM_LOGP(CM_LOGL_INFO, "%s", (const CHAR*)sHeader);

                    m_pSocketC->Send((INT8*)(const CHAR*)sHeader, sHeader.GetLength());
                }
                else
                {
                    ASSERT(m_nTotalSize == _mwtoi((const WCHAR*)sVal.Mid(nPos3 + 1)));
                    ASSERT(m_nStatus == 2);
                    ASSERT(m_nEnd - m_nStart < REQ_SIZE);

                    UINT32 nLen = m_nSize;
                    if (m_nSize > BUF_SIZE)
                    {
                        nLen = BUF_SIZE;
                    }
                    m_pHttpC->Read(m_pBuf, nLen);
                }
            }
            else
            {
                if (!pRespHeader->GetValue(HH_CLENGTH, sVal))
                {
                    CM_ERR("CMHttpSNotify::OnResponse no content-length");
                    goto err;
                }

                m_nTotalSize = 0;  //此值无效
                m_nSize = _mwtoi(sVal);

                //获取响应头成功,返回结果到Socket处
                CMString sSendSize;
                sSendSize.Format(L"%d", m_nSize);
                header.AddValue(HH_CLENGTH, sSendSize);
                CMString sHeader = header.ToString();

                CM_LOGP(CM_LOGL_INFO, "%s", (const CHAR*)sHeader);

                m_pSocketC->Send((INT8*)(const CHAR*)sHeader, sHeader.GetLength());
            }
           
            return;
        }
        else
        {
            CM_ERRP("CMHttpSNotify::OnResponse http ret %d error", httpRet);
            nRet = httpRet;
        }
    }
    else
    {
        CM_ERRP("CMHttpSNotify::OnResponse ret %d error", nCode);
        nRet = nCode;
    }

err:
    //未成功获取信息,清理,等待下次获取
    //if (m_pBuf)
    //{
    //    delete m_pBuf;
    //    m_pBuf = NULL;
    //}

    m_bInService = FALSE;

    //if (nCode == MERN_TIMEOUT)
    //{
    //    m_pSocketC->Close();
    //}
    //else
    //{
        char response[] = "HTTP/1.1 404 NOT FOUND\r\n\r\n";
        m_nSize = 0;
        m_pSocketC->Send((INT8*)response, strlen(response));
    //}

    //重置http
    m_pHttpC->Cancel();
}