コード例 #1
0
ファイル: openurl.cpp プロジェクト: martok/miranda-ng
static void OpenURLThread(void *arg)
{
	TOpenUrlInfo *hUrlInfo = (TOpenUrlInfo*)arg;

	// wack a protocol on it
	CMString tszUrl;
	if ((isalpha(hUrlInfo->szUrl[0]) && hUrlInfo->szUrl[1] == ':') || hUrlInfo->szUrl[0] == '\\')
		tszUrl.Format(_T("file:///%s"), hUrlInfo->szUrl);
	else {
		int i;
		for (i = 0; _istalpha(hUrlInfo->szUrl[i]); i++);
		if (hUrlInfo->szUrl[i] == ':')
			tszUrl = hUrlInfo->szUrl;
		else if (!_tcsnicmp(hUrlInfo->szUrl, _T("ftp."), 4))
			tszUrl.Format(_T("ftp://%s"), hUrlInfo->szUrl);
		else
			tszUrl.Format(_T("http://%s"), hUrlInfo->szUrl);
	}

	// check user defined browser for opening urls
	ptrT tszBrowser(db_get_tsa(NULL, "Miranda", "OpenUrlBrowser"));
	if (tszBrowser)
		ShellExecute(NULL, _T("open"), tszBrowser, tszUrl, NULL, (hUrlInfo->newWindow) ? SW_NORMAL : SW_SHOWDEFAULT);
	else
		ShellExecute(NULL, _T("open"), tszUrl, NULL, NULL, (hUrlInfo->newWindow) ? SW_NORMAL : SW_SHOWDEFAULT);

	delete hUrlInfo;
}
コード例 #2
0
ファイル: jabber_misc.cpp プロジェクト: 0xmono/miranda-ng
void CJabberProto::FormatMirVer(pResourceStatus &resource, CMString &res)
{
	res.Empty();
	if (resource == NULL)
		return;

	// jabber:iq:version info requested and exists?
	if (resource->m_dwVersionRequestTime && resource->m_tszSoftware) {
		debugLog(_T("JabberUpdateMirVer: for iq:version rc %s: %s"), resource->m_tszResourceName, resource->m_tszSoftware);
		if (!resource->m_tszSoftwareVersion || _tcsstr(resource->m_tszSoftware, resource->m_tszSoftwareVersion))
			res = resource->m_tszSoftware;
		else
			res.Format(_T("%s %s"), resource->m_tszSoftware, resource->m_tszSoftwareVersion);
	}
	// no version info and no caps info? set MirVer = resource name
	else if (!resource->m_tszCapsNode || !resource->m_tszCapsVer) {
		debugLog(_T("JabberUpdateMirVer: for rc %s: %s"), resource->m_tszResourceName, resource->m_tszResourceName);
		if (resource->m_tszResourceName)
			res = resource->m_tszResourceName;
	}
	// XEP-0115 caps mode
	else {
		debugLog(_T("JabberUpdateMirVer: for rc %s: %s#%s"), resource->m_tszResourceName, resource->m_tszCapsNode, resource->m_tszCapsVer);

		int i;

		// search through known software list
		for (i = 0; i < SIZEOF(sttCapsNodeToName_Map); i++)
			if (_tcsstr(resource->m_tszCapsNode, sttCapsNodeToName_Map[i].node)) {
				res.Format(_T("%s %s"), sttCapsNodeToName_Map[i].name, resource->m_tszCapsVer);
				break;
			}

		// unknown software
		if (i == SIZEOF(sttCapsNodeToName_Map))
			res.Format(_T("%s %s"), resource->m_tszCapsNode, resource->m_tszCapsVer);
	}

	// attach additional info for fingerprint plguin
	if (resource->m_tszCapsExt && _tcsstr(resource->m_tszCapsExt, JABBER_EXT_PLATFORMX86) && !_tcsstr(res, _T("x86")))
		res.Append(_T(" x86"));

	if (resource->m_tszCapsExt && _tcsstr(resource->m_tszCapsExt, JABBER_EXT_PLATFORMX64) && !_tcsstr(res, _T("x64")))
		res.Append(_T(" x64"));

	if (resource->m_tszCapsExt && _tcsstr(resource->m_tszCapsExt, JABBER_EXT_SECUREIM) && !_tcsstr(res, _T("(SecureIM)")))
		res.Append(_T(" (SecureIM)"));

	if (resource->m_tszCapsExt && _tcsstr(resource->m_tszCapsExt, JABBER_EXT_MIROTR) && !_tcsstr(res, _T("(MirOTR)")))
		res.Append(_T(" (MirOTR)"));

	if (resource->m_tszCapsExt && _tcsstr(resource->m_tszCapsExt, JABBER_EXT_NEWGPG) && !_tcsstr(res, _T("(New_GPG)")))
		res.Append(_T(" (New_GPG)"));

	if (resource->m_tszResourceName && !_tcsstr(res, resource->m_tszResourceName))
		if (_tcsstr(res, _T("Miranda IM")) || _tcsstr(res, _T("Miranda NG")) || m_options.ShowForeignResourceInMirVer)
			res.AppendFormat(_T(" [%s]"), resource->m_tszResourceName);
}
コード例 #3
0
//打电话
void CMGlobal::MakeCall(const CMString& sNumber)
{
    //PHONEMAKECALLINFO makeCallInfo;
    //makeCallInfo.cbSize=sizeof(PHONEMAKECALLINFO);
    //makeCallInfo.dwFlags=PMCF_PROMPTBEFORECALLING;
    //makeCallInfo.pszComment=(const WCHAR*)sNumber;
    //makeCallInfo.pszAppName=NULL;
    //makeCallInfo.pszCalledParty=NULL;
    //makeCallInfo.pszComment=NULL;
    //PhoneMakeCall(&makeCallInfo);

    SHELLEXECUTEINFO info;
    memset(&info,0,sizeof(SHELLEXECUTEINFO));
    info.cbSize = sizeof(info);
    info.fMask = SEE_MASK_FLAG_NO_UI;
    info.hwnd = NULL;
    info.lpVerb = _T("open");
    info.lpFile = _T("\\windows\\cprog.exe");
    CMString sParam;
    sParam.Format(L"-n -url tel:%s", (const WCHAR*)sNumber); //
    info.lpParameters = (const WCHAR*)sParam;
    info.lpDirectory = _T("");
    info.nShow = SW_SHOWNORMAL;
    info.hInstApp = NULL;
    ShellExecuteEx(&info); 
}
コード例 #4
0
void SetSRMMIcon(MCONTACT hContact, SRMM_ICON_TYPE type, time_t time)
{
	if (hContact && arMonitoredWindows.getIndex((HANDLE)hContact) != -1)
	{
		StatusIconData sid = { sizeof(sid) };
		sid.szModule = MODULENAME;
		sid.dwId = 1;
		sid.flags = MBF_TCHAR;

		switch (type)
		{
		case ICON_HIDDEN:
			{
				sid.flags |= MBF_HIDDEN;
				break;
			}
		case ICON_READ:
			{
				sid.hIcon = IcoLib_GetIcon("read_icon");
				CMString tooltip;
				if (db_get_dw(hContact, MODULENAME, DBKEY_MESSAGE_READ_TIME_TYPE, -1) == MRD_TYPE_READTIME)
				{
					TCHAR ttime[64];
					_locale_t locale = _create_locale(LC_ALL, "");
					_tcsftime_l(ttime, _countof(ttime), _T("%X %x"), localtime(&time), locale);
					_free_locale(locale);
					tooltip.Format(L"%s %s", TranslateT("Last message read at"), ttime);
				}
				else
				{
					tooltip = TranslateT("Last message read (unknown time)");
				}
				sid.tszTooltip = tooltip.Detach();
				break;
			}
		case ICON_UNREAD:
			{
				sid.hIcon = IcoLib_GetIcon("unread_icon");
				sid.tszTooltip = TranslateT("Last message is not read");
				break;
			}
		case ICON_FAILED:
			{
				sid.hIcon = IcoLib_GetIcon("fail_icon");
				sid.tszTooltip = TranslateT("Last message was not sent.");
				break;
			}
		case ICON_NOSENT:
			{
				sid.hIcon = IcoLib_GetIcon("nosent_icon");
				sid.tszTooltip = TranslateT("Sending...");
				break;
			}
		default:
			return;
		}

		Srmm_ModifyIcon(hContact, &sid);
	}
}
コード例 #5
0
ファイル: jabber_notes.cpp プロジェクト: 0xmono/miranda-ng
void CJabberDlgNoteItem::OnInitDialog()
{
	CSuper::OnInitDialog();
	WindowSetIcon(m_hwnd, m_proto, "notes");

	if (m_fnProcess) {
		CMString buf;
		if (m_fnProcess == &CJabberProto::ProcessIncomingNote)
			buf.Format(TranslateT("Incoming note from %s"), m_pNote->GetFrom());
		else
			buf.Format(TranslateT("Send note to %s"), m_pNote->GetFrom());

		SetWindowText(m_hwnd, buf);
	}

	m_txtTitle.SetText(m_pNote->GetTitle());
	m_txtText.SetText(m_pNote->GetText());
	m_txtTags.SetText(m_pNote->GetTagsStr());
}
コード例 #6
0
ファイル: vk_chats.cpp プロジェクト: MrtsComputers/miranda-ng
CVkChatInfo* CVkProto::AppendChat(int id, JSONNODE *pDlg)
{
	if (id == 0)
		return NULL;

	CVkChatInfo *c = m_chats.find((CVkChatInfo*)&id);
	if (c != NULL)
		return c;

	ptrT tszTitle;
	c = new CVkChatInfo(id);
	if (pDlg != NULL) {
		tszTitle = json_as_string(json_get(pDlg, "title"));
		c->m_tszTopic = mir_tstrdup((tszTitle != NULL) ? tszTitle : _T(""));
	}

	CMString sid; sid.Format(_T("%S_%d"), m_szModuleName, id);
	c->m_tszId = mir_tstrdup(sid);

	GCSESSION gcw = { sizeof(gcw) };
	gcw.iType = GCW_CHATROOM;
	gcw.pszModule = m_szModuleName;
	gcw.ptszName = tszTitle;
	gcw.ptszID = sid;
	CallServiceSync(MS_GC_NEWSESSION, NULL, (LPARAM)&gcw);

	GC_INFO gci = { 0 };
	gci.pszModule = m_szModuleName;
	gci.pszID = sid;
	gci.Flags = BYID | HCONTACT;
	CallServiceSync(MS_GC_GETINFO, 0, (LPARAM)&gci);
	c->m_hContact = gci.hContact;

	setTString(gci.hContact, "Nick", tszTitle);
	m_chats.insert(c);

	GCDEST gcd = { m_szModuleName, sid, GC_EVENT_ADDGROUP };
	GCEVENT gce = { sizeof(gce), &gcd };
	for (int i = SIZEOF(sttStatuses)-1; i >= 0; i--) {
		gce.ptszStatus = TranslateTS(sttStatuses[i]);
		CallServiceSync(MS_GC_EVENT, NULL, (LPARAM)&gce);
	}

	gcd.iType = GC_EVENT_CONTROL;
	gce.ptszStatus = 0;
	CallServiceSync(MS_GC_EVENT, (m_bHideChats) ? WINDOW_HIDDEN : SESSION_INITDONE, (LPARAM)&gce);
	CallServiceSync(MS_GC_EVENT, SESSION_ONLINE, (LPARAM)&gce);

	RetrieveChatInfo(c);
	return c;
}
コード例 #7
0
//发短信
void CMGlobal::OpenSMSG(const CMString& sNumber)
{
    SHELLEXECUTEINFO sheci = {0};
    sheci.cbSize = sizeof(sheci);
    sheci.fMask = SEE_MASK_FLAG_NO_UI;
    sheci.hwnd = NULL;
    sheci.lpVerb = TEXT("OPEN");
    sheci.nShow = SW_SHOW;
    sheci.lpFile = _T("\\Windows\\tmail.exe");
    CMString sParam;
    sParam.Format(L"-service \"SMS\" -to \"%s\"", (const WCHAR*)sNumber);
    sheci.lpParameters =  (const WCHAR*)sParam;

    ShellExecuteEx(&sheci);
}
コード例 #8
0
static int FAV_OnContactMenuBuild(WPARAM hContact, LPARAM)
{
	BYTE bContactRate = db_get_b(hContact, "CList", "Rate", 0);
	if (bContactRate > _countof(rates) - 1)
		bContactRate = _countof(rates) - 1;

	CMString tszName;
	if (!bContactRate)
		tszName = FAVMENUROOTNAME;
	else
		tszName.Format(_T("%s (%s)"), TranslateTS(FAVMENUROOTNAME), TranslateTS(rates[bContactRate]));
	Menu_ModifyItem(hFavoriteContactMenu, tszName);

	for (int i = 0; i < _countof(rates); i++)
		Menu_SetChecked(hFavoriteContactMenuItems[i], bContactRate == i);

	Menu_SetChecked(hShowIfOflineItem, db_get_b(hContact, "CList", "noOffline", 0) != 0);
	return 0;
}
コード例 #9
0
ファイル: vk_status.cpp プロジェクト: wyrover/miranda-ng
INT_PTR __cdecl CVkProto::SvcSetListeningTo(WPARAM, LPARAM lParam)
{
	debugLogA("CVkProto::SvcSetListeningTo");
	if (m_vkOptions.iMusicSendMetod == MusicSendMetod::sendNone)
		return 1;

	LISTENINGTOINFO *pliInfo = (LISTENINGTOINFO*)lParam;
	CMString tszListeningTo;
	if (pliInfo == NULL || pliInfo->cbSize != sizeof(LISTENINGTOINFO))
		db_unset(NULL, m_szModuleName, "ListeningTo");
	else if (pliInfo->dwFlags & LTI_UNICODE) {
		if (ServiceExists(MS_LISTENINGTO_GETPARSEDTEXT))
			tszListeningTo = ptrT((LPWSTR)CallService(MS_LISTENINGTO_GETPARSEDTEXT, (WPARAM)_T("%artist% - %title%"), (LPARAM)pliInfo));
		else
			tszListeningTo.Format(_T("%s - %s"),
			pliInfo->ptszArtist ? pliInfo->ptszArtist : _T(""),
			pliInfo->ptszTitle ? pliInfo->ptszTitle : _T(""));
		setTString("ListeningTo", tszListeningTo);
	}
	RetrieveStatusMusic(tszListeningTo);
	return 0;
}
コード例 #10
0
void CMHttpSNotify::OnRecv(UINT32 nCode, INT32 nLen)
{
    if (nCode == MER_OK)
    {
        //是不是请求头
        INT32 nTmp = nLen;
        if (!m_cReqHeader.Parse(m_pHeadBuf, nTmp))
        {
            m_nHeadPos += nLen;
            if (nTmp == -1 && m_nHeadPos < REQ_HEAD_MAX_LEN)
            {
                //可能头还没收全,继续收
                CM_LOGP(CM_LOGL_DEBUG, "CMHttpSNotify::OnRecv header part %d",  nLen);
                m_pSocketC->Recv(m_pHeadBuf + m_nHeadPos , REQ_HEAD_MAX_LEN - m_nHeadPos);
                return;
            }
            CM_LOGP(CM_LOGL_DEBUG, "CMHttpSNotify::OnRecv header failed is %s", (const CHAR*)CMString((const CHAR*)m_pHeadBuf, nLen));
            return;
        }

        CMString sRange;
        m_cReqHeader.GetValue(HH_RANGER, sRange);

        //是外部请求,构造CMHttp请求
        m_rUrl = m_pHttpS->ToRemote(m_cReqHeader.GetUrl());
        if (!m_rUrl.Url().IsEmpty())
        {
            CMHTTPReqHeader header;
            header.CreateDefault();

            if (sRange.IsEmpty())
            {
				if(CMNetConnMgr::Instance().CurrentType() == CMNetConnMgr::CMWAP)
	            {
    	            sRange.Format(L"bytes = 0-%d", REQ_SIZE - 1);
                    header.AddValue(HH_RANGER, sRange);
	            }
	            else
                {
                    //请求没有指定range,不发送此参数	
                }
            }
            else
            {
                //暂时此流程不支持
                ASSERT(FALSE);
             //   if(CMGlobal::TheOne().NetConnMgr().CurrentType() == CMNetConnMgr::CMWAP)
	            //{
             //       //如果请求包含range信息,对于跨CMWAP网关也需要处理
             //       UINT32 nStart = 0;
             //       UINT32 nEnd = 0;

             //       INT32 nPos1 = sRange.Find(L"-");
             //       if (nPos1 > 0)
             //       {
             //           INT32 nPos2 = sRange.Find(L"=");
             //           nStart= _mwtoi((const WCHAR*)sRange.Mid(nPos2 + 2, nPos1 - nPos2 - 2));
             //           INT32 nLen = sRange.GetLength();
             //           if (nLen > nPos1 + 1)
             //           {
             //               nEnd = _mwtoi((const WCHAR*)sRange.Mid(nPos2 + 1, nLen - 1));
             //           }
             //       }

             //       if (nEnd != 0)
             //       {
             //           m_nSendSize = nEnd - nStart + 1;
             //       }
             //       else
             //       {
             //           m_nSendSize = m_pFile->GetLength() - nStart;
             //           nEnd = nStart + m_nSendSize - 1;
             //       }
             //   }
             //   else
             //       header.AddValue(HH_RANGER, sRange);
            }

            header.SetUrl(m_rUrl);
            m_pHttpC->Request(header);
            m_nStatus = 1;
            return;
        }

        //是本地文件请求,构造发送信息
        //const CMString* pFile = m_pHttpS->GetFile(m_cReqHeader.GetUrl());
        //if (pFile)
        //{
        //    if (!m_pFile)
        //    {
        //        m_pFile = new CMFile();
        //    }
        //    if (!m_pFile->Open(*pFile, CMFile::OPEN_R_EXIST, CMFile::SHARE_R))
        //    {
        //        //打开失败
        //        CM_ERRP("CMHttpSNotify::OnRecv Open file  %s not exist", (const CHAR*)CMString(*pFile));
        //        return;
        //    }

        //    UINT32 nStart = 0;
        //    UINT32 nEnd = 0;
        //    if (!sRange.IsEmpty())
        //    {
        //        INT32 nPos1 = sRange.Find(L"-");
        //        if (nPos1 > 0)
        //        {
        //            INT32 nPos2 = sRange.Find(L"=");
        //            nStart= _mwtoi((const WCHAR*)sRange.Mid(nPos2 + 2, nPos1 - nPos2 - 2));
        //            INT32 nLen = sRange.GetLength();
        //            if (nLen > nPos1 + 1)
        //            {
        //                nEnd = _mwtoi((const WCHAR*)sRange.Mid(nPos2 + 1, nLen - 1));
        //            }
        //        }
        //    }

        //    if (nStart != 0)
        //        m_pFile->Seek(nStart);
        //    if (nEnd != 0)
        //    {
        //        m_nSendSize = nEnd - nStart + 1;
        //    }
        //    else
        //    {
        //        m_nSendSize = m_pFile->GetLength() - nStart;
        //        nEnd = nStart + m_nSendSize - 1;
        //    }

        //    //获取成功,返回响应头结果到Socket处
        //    CMHTTPRspHeader resp;
        //    resp.SetRet(200, CMString("OK"));
        //    if (!sRange.IsEmpty())
        //    {
        //        //如果有range,就要返回range,  bytes 0-2668566/2668567
        //        CMString sSendRange;
        //        sSendRange.Format(L"bytes %d-%d/%d", nStart, nEnd, m_nSendSize);
        //        resp.AddValue(HH_CRANGE, sSendRange);
        //    }
        //    else
        //    {
        //        //否则返回content-lengthW
        //        CMString sSendSize;
        //        sSendSize.Format(L"%d", m_nSendSize);
        //        resp.AddValue(HH_CLENGTH, sSendSize);
        //    }
        //    resp.AddValue(HH_CTYPE, L"application/x-shockwave-flash");
        //    CMString sHeader = resp.ToString();
        //    CM_LOGP(CM_LOGL_DEBUG, "%s", (const CHAR*)sHeader);

        //    m_pSocketC->Send((const INT8*)(const CHAR*)sHeader, sHeader.GetLength());

        //    m_nStatus = 3;
        //    return;
        //}
    }
    else
    {
        CM_ERRP("CMHttpSNotify::OnRecv ret %d error", nCode);
    }
err:
    //未成功获取信息,清理,等待下次获取

    m_bInService = FALSE;
    m_nSize = 0;

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

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

}
コード例 #11
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();
}
コード例 #12
0
void CMHttpSNotify::OnSend(UINT32 nCode, INT32 nLen)
{
    if (nCode == MER_OK)
    {
        switch(m_nStatus)
        {
        case 1:
            if (m_nSize != 0)
            {
                nLen = m_nSize; //重用nLen
                if (m_nSize > BUF_SIZE)
                {
                    nLen = BUF_SIZE;
                }

                m_pHttpC->Read(m_pBuf, nLen);

                m_nStatus = 2;
            }
            else
            {
                //m_nSize为0表示有错误,中止继续操作
                CM_ERR("CMHttpSNotify::OnSend 0");
                m_pSocketC->Close();
            }
            break;
        case 2:
            if (nLen < m_nSendSize)
            {
                m_nPos += nLen;
                m_nSendSize -= nLen;
                m_pSocketC->Send(m_pBuf + m_nPos, m_nSendSize);
            }
            else
            {
                //判断是否完成
                if (m_nSize > 0)
                {
                    //还有剩余,继续请求
                    nLen = m_nSize;  //nLen无意义了,复用下
                    if (m_nSize > BUF_SIZE)
                    {
                        nLen = BUF_SIZE;
                    }
                    m_pHttpC->Read(m_pBuf, nLen);
                }
                else if (m_nTotalSize > 0 && m_nEnd < m_nTotalSize - 1)
                {
                    //仅当前http请求完毕,
                    CMHTTPReqHeader header;
                    header.CreateDefault();

                    CMString sRange;
                    if (m_nEnd + REQ_SIZE < m_nTotalSize - 1)
                        sRange.Format(L"bytes = %d-%d", m_nEnd + 1, m_nEnd + REQ_SIZE);
                    else
                        sRange.Format(L"bytes = %d-", m_nEnd + 1);
                    header.AddValue(HH_RANGER, sRange);
                    header.SetUrl(m_rUrl);
                    m_pHttpC->Request(header);
                }
                else
                {
                    //已完成,开始等待后续接收
                    Start();
                    //m_bInService = FALSE;
                    //m_pSocketC->Close();
                    //m_pHttpC->Cancel();
                }
            }
            break;
        case 3:

            if (m_nSendSize > BUF_SIZE)
            {
                nLen = BUF_SIZE;
            }
            else
            {
                nLen = m_nSendSize;
            }
            //if (m_pBuf)
            //{
            //    delete m_pBuf;
            //    m_pBuf = NULL;
            //}
            //m_pBuf = new INT8[nLen + 1];
            m_nPos = 0;
            m_pFile->Read((CHAR*)m_pBuf, nLen);
            m_pSocketC->Send(m_pBuf, nLen);
            m_nStatus = 4;
            break;
        case 4:
            if (nLen < m_nSendSize && m_nPos + nLen < BUF_SIZE)   
            {
                //没有发送完
                m_nPos += nLen;
                m_nSendSize -= nLen;
                m_pSocketC->Send(m_pBuf + m_nPos, m_nSendSize);
            }
            else
            {
                m_nSendSize -= nLen;
                if (m_nSendSize > 0)
                {
                    nLen = m_nSendSize;
                    if (m_nSendSize > BUF_SIZE)
                    {
                        nLen = BUF_SIZE;
                    }
                    m_nPos = 0;
                    m_pFile->Read((CHAR*)m_pBuf, nLen);
                    m_pSocketC->Send(m_pBuf, nLen);
                }
                else
                {
                    //已完成,开始等待后续接收
                    Start();
                    //m_bInService = FALSE;
                    //m_pHttpC->Cancel();
                }
            }
            break;
        default:
            CM_ERR("CMHttpSNotify::OnSend status 0");
        }

        return;
    }

    CM_ERRP("CMHttpSNotify::OnSend ret %d error", nCode);
    m_bInService = FALSE;
    m_pSocketC->Close();
    m_pHttpC->Cancel();

}
コード例 #13
0
ファイル: jabber_menu.cpp プロジェクト: Seldom/miranda-ng
int CJabberProto::OnPrebuildContactMenu(WPARAM hContact, LPARAM)
{
    if (hContact == NULL)
        return 0;

    bool bIsChatRoom = isChatRoom(hContact);
    bool bIsTransport = getBool(hContact, "IsTransport", false);

    if ((bIsChatRoom == GCW_CHATROOM) || bIsChatRoom == 0) {
        if (ptrT(getTStringA(hContact, bIsChatRoom ? (char*)"ChatRoomID" : (char*)"jid")) != NULL) {
            Menu_ShowItem(g_hMenuConvert, TRUE);
            Menu_ModifyItem(g_hMenuConvert, bIsChatRoom ? LPGENT("&Convert to Contact") : LPGENT("&Convert to Chat Room"));
        }
    }

    if (!m_bJabberOnline)
        return 0;

    Menu_ShowItem(g_hMenuDirectPresence[0], TRUE);
    for (int i = 0; i < _countof(PresenceModeArray); i++)
        Menu_ModifyItem(g_hMenuDirectPresence[i + 1], NULL, Skin_LoadProtoIcon(m_szModuleName, PresenceModeArray[i].mode));

    if (bIsChatRoom) {
        ptrT roomid(getTStringA(hContact, "ChatRoomID"));
        if (roomid != NULL) {
            Menu_ShowItem(g_hMenuRosterAdd, FALSE);

            if (ListGetItemPtr(LIST_BOOKMARK, roomid) == NULL)
                if (m_ThreadInfo && m_ThreadInfo->jabberServerCaps & JABBER_CAPS_PRIVATE_STORAGE)
                    Menu_ShowItem(g_hMenuAddBookmark, TRUE);
        }
    }

    if (bIsChatRoom == GCW_CHATROOM)
        return 0;

    if (bIsTransport) {
        Menu_ShowItem(g_hMenuLogin, TRUE);
        Menu_ShowItem(g_hMenuRefresh, TRUE);
    }

    ptrT jid(getTStringA(hContact, "jid"));
    if (jid == NULL)
        return 0;

    JabberCapsBits jcb = GetTotalJidCapabilites(jid);
    JABBER_LIST_ITEM *item = ListGetItemPtr(LIST_ROSTER, jid);
    if (item == NULL)
        return 0;

    bool bCtrlPressed = (GetKeyState(VK_CONTROL) & 0x8000) != 0;
    Menu_ShowItem(g_hMenuRequestAuth, item->subscription == SUB_FROM || item->subscription == SUB_NONE || bCtrlPressed);
    Menu_ShowItem(g_hMenuGrantAuth, bCtrlPressed);
    Menu_ShowItem(g_hMenuRevokeAuth, item->subscription == SUB_FROM || item->subscription == SUB_BOTH || bCtrlPressed);
    Menu_ShowItem(g_hMenuCommands, ((jcb & JABBER_CAPS_COMMANDS) != 0) || bCtrlPressed);
    Menu_ShowItem(g_hMenuSendNote, TRUE);

    if (item->arResources.getCount() == 0)
        return 0;

    Menu_ShowItem(g_hMenuResourcesRoot, TRUE);
    Menu_ModifyItem(g_hMenuResourcesRoot, NULL, m_hProtoIcon);
    Menu_ModifyItem(g_hMenuResourcesActive, NULL, m_hProtoIcon, (item->resourceMode == RSMODE_LASTSEEN) ? CMIF_CHECKED : 0);
    Menu_ModifyItem(g_hMenuResourcesServer, NULL, m_hProtoIcon, (item->resourceMode == RSMODE_SERVER) ? CMIF_CHECKED : 0);

    int nMenuResourceItemsNew = m_nMenuResourceItems;
    if (m_nMenuResourceItems < item->arResources.getCount()) {
        m_phMenuResourceItems = (HGENMENU*)mir_realloc(m_phMenuResourceItems, item->arResources.getCount() * sizeof(HGENMENU));
        nMenuResourceItemsNew = item->arResources.getCount();
    }

    char text[256];
    CMenuItem mi;
    mi.pszService = text;

    CMString szTmp;
    for (int i = 0; i < nMenuResourceItemsNew; i++) {
        mir_snprintf(text, "/UseResource_%d", i);
        if (i >= m_nMenuResourceItems) {
            CreateProtoServiceParam(text, &CJabberProto::OnMenuHandleResource, MENUITEM_RESOURCES + i);
            mi.name.a = "";
            mi.position = i;
            mi.root = g_hMenuResourcesRoot;
            m_phMenuResourceItems[i] = Menu_AddContactMenuItem(&mi, m_szModuleName);
        }
        if (i < item->arResources.getCount()) {
            pResourceStatus r(item->arResources[i]);

            HICON hIcon = (HICON)INVALID_HANDLE_VALUE;
            Menu_SetChecked(m_phMenuResourceItems[i], item->resourceMode == RSMODE_MANUAL && item->m_pManualResource == r);

            if (ServiceExists(MS_FP_GETCLIENTICONT)) {
                FormatMirVer(r, szTmp);
                hIcon = Finger_GetClientIcon(szTmp, 0);
            }
            szTmp.Format(_T("%s [%s, %d]"), r->m_tszResourceName, pcli->pfnGetStatusModeDescription(r->m_iStatus, 0), r->m_iPriority);
            Menu_ModifyItem(m_phMenuResourceItems[i], szTmp, hIcon);
            DestroyIcon(hIcon);
        }
        else Menu_ShowItem(m_phMenuResourceItems[i], FALSE);
    }

    m_nMenuResourceItems = nMenuResourceItemsNew;
    return 0;
}