示例#1
0
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);
}
示例#2
0
static void CALLBACK timerProc(HWND, UINT, UINT_PTR, DWORD)
{
	WaitForSingleObject(g_hMutexIm, 3000);
	const time_t ts = time(NULL) - 10;
	if (lastmodule && ts > laststamp) {
		FreeLibrary(lastmodule);
		lastmodule = NULL;
		lastdllname.Empty();
	}

	for (int i=g_imagecache.getCount()-1; i >= 0; i--)
		g_imagecache[i].ProcessTimerTick(ts);

	if (g_imagecache.getCount() == 0) {
		g_imagecache.destroy();
		if (timerId && (timerId+1) && lastmodule == NULL) {
			KillTimer(NULL, timerId);
			timerId = 0;
		}
	}

	ReleaseMutex(g_hMutexIm);
}
示例#3
0
INT_PTR CALLBACK DlgPluginOpt(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);
		timerID = 0;
		{
			HWND hwndList = GetDlgItem(hwndDlg, IDC_PLUGLIST);
			mir_subclassWindow(hwndList, PluginListWndProc);

			HIMAGELIST hIml = ImageList_Create(16, 16, ILC_MASK | ILC_COLOR32, 4, 0);
			ImageList_AddIcon_IconLibLoaded(hIml, SKINICON_OTHER_UNICODE);
			ImageList_AddIcon_IconLibLoaded(hIml, SKINICON_OTHER_ANSI);
			ImageList_AddIcon_IconLibLoaded(hIml, SKINICON_OTHER_LOADED);
			ImageList_AddIcon_IconLibLoaded(hIml, SKINICON_OTHER_NOTLOADED);
			ImageList_AddIcon_IconLibLoaded(hIml, SKINICON_OTHER_LOADEDGRAY);
			ImageList_AddIcon_IconLibLoaded(hIml, SKINICON_OTHER_NOTLOADEDGRAY);
			ListView_SetImageList(hwndList, hIml, LVSIL_SMALL);

			LVCOLUMN col;
			col.mask = LVCF_TEXT | LVCF_WIDTH;
			col.pszText = _T("");
			col.cx = 40;
			ListView_InsertColumn(hwndList, 0, &col);

			col.pszText = TranslateT("Plugin");
			col.cx = 180;
			ListView_InsertColumn(hwndList, 1, &col);

			col.pszText = TranslateT("Name");
			col.cx = 180;//max = 220;
			ListView_InsertColumn(hwndList, 2, &col);

			col.pszText = TranslateT("Version");
			col.cx = 75;
			ListView_InsertColumn(hwndList, 3, &col);

			ListView_SetExtendedListViewStyleEx(hwndList, 0, LVS_EX_SUBITEMIMAGES | LVS_EX_CHECKBOXES | LVS_EX_LABELTIP | LVS_EX_FULLROWSELECT);
			// scan the plugin dir for plugins, cos
			arPluginList.destroy();
			szFilter.Empty();
			enumPlugins(dialogListPlugins, (WPARAM)hwndDlg, (LPARAM)hwndList);
			// sort out the headers

			ListView_SetColumnWidth(hwndList, 1, LVSCW_AUTOSIZE); // dll name
			int w = ListView_GetColumnWidth(hwndList, 1);
			if (w > 110) {
				ListView_SetColumnWidth(hwndList, 1, w = 110);
			}
			int max = w < 110 ? 189 + 110 - w : 189;
			ListView_SetColumnWidth(hwndList, 3, LVSCW_AUTOSIZE); // short name
			w = ListView_GetColumnWidth(hwndList, 2);
			if (w > max)
				ListView_SetColumnWidth(hwndList, 2, max);

			ListView_SortItems(hwndList, SortPlugins, (LPARAM)hwndDlg);
		}
		return TRUE;

	case WM_NOTIFY:
		if (lParam) {
			NMLISTVIEW *hdr = (NMLISTVIEW *)lParam;
			if (hdr->hdr.code == LVN_ITEMCHANGED && IsWindowVisible(hdr->hdr.hwndFrom)) {
				if (hdr->uOldState != 0 && (hdr->uNewState == 0x1000 || hdr->uNewState == 0x2000)) {
					HWND hwndList = GetDlgItem(hwndDlg, IDC_PLUGLIST);

					LVITEM it;
					it.mask = LVIF_PARAM | LVIF_STATE;
					it.iItem = hdr->iItem;
					if (!ListView_GetItem(hwndList, &it))
						break;

					PluginListItemData *dat = (PluginListItemData*)it.lParam;
					if (dat->flags & STATIC_PLUGIN) {
						ListView_SetItemState(hwndList, hdr->iItem, 0x3000, LVIS_STATEIMAGEMASK);
						return FALSE;
					}
					// find all another standard plugins by mask and disable them
					if ((hdr->uNewState == 0x2000) && dat->stdPlugin != 0) {
						for (int iRow = 0; iRow != -1; iRow = ListView_GetNextItem(hwndList, iRow, LVNI_ALL)) {
							if (iRow != hdr->iItem) { // skip the plugin we're standing on
								LVITEM dt;
								dt.mask = LVIF_PARAM;
								dt.iItem = iRow;
								if (ListView_GetItem(hwndList, &dt)) {
									PluginListItemData *dat2 = (PluginListItemData*)dt.lParam;
									if (dat2->stdPlugin & dat->stdPlugin) {// mask differs
										// the lParam is unset, so when the check is unset the clist block doesnt trigger
										int iSave = dat2->stdPlugin;
										dat2->stdPlugin = 0;
										ListView_SetItemState(hwndList, iRow, 0x1000, LVIS_STATEIMAGEMASK);
										dat2->stdPlugin = iSave;
									}
								}
							}
						}
					}

					if (bOldMode)
						ShowWindow(GetDlgItem(hwndDlg, IDC_RESTART), TRUE); // this here only in "ghazan mode"
					SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
					break;
				}

				if (hdr->iItem != -1) {
					int sel = hdr->uNewState & LVIS_SELECTED;
					HWND hwndList = GetDlgItem(hwndDlg, IDC_PLUGLIST);
					LVITEM lvi = { 0 };
					lvi.mask = LVIF_PARAM;
					lvi.iItem = hdr->iItem;
					if (ListView_GetItem(hwndList, &lvi)) {
						PluginListItemData *dat = (PluginListItemData*)lvi.lParam;

						TCHAR buf[1024];
						ListView_GetItemText(hwndList, hdr->iItem, 2, buf, _countof(buf));
						SetDlgItemText(hwndDlg, IDC_PLUGININFOFRAME, sel ? buf : _T(""));

						ptrT tszAuthor(latin2t(sel ? dat->author : NULL));
						SetDlgItemText(hwndDlg, IDC_PLUGINAUTHOR, tszAuthor);

						ptrT tszEmail(latin2t(sel ? dat->authorEmail : NULL));
						SetDlgItemText(hwndDlg, IDC_PLUGINEMAIL, tszEmail);

						ptrT p(Langpack_PcharToTchar(dat->description));
						SetDlgItemText(hwndDlg, IDC_PLUGINLONGINFO, sel ? p : _T(""));

						ptrT tszCopyright(latin2t(sel ? dat->copyright : NULL));
						SetDlgItemText(hwndDlg, IDC_PLUGINCPYR, tszCopyright);

						ptrT tszUrl(latin2t(sel ? dat->homepage : NULL));
						SetDlgItemText(hwndDlg, IDC_PLUGINURL, tszUrl);

						if (!equalUUID(miid_last, dat->uuid)) {
							char szUID[128];
							uuidToString(dat->uuid, szUID, sizeof(szUID));
							SetDlgItemTextA(hwndDlg, IDC_PLUGINPID, sel ? szUID : "");
						}
						else SetDlgItemText(hwndDlg, IDC_PLUGINPID, sel ? TranslateT("<none>") : _T(""));
					}
				}
			}

			if (hdr->hdr.code == PSN_APPLY) {
				bool needRestart = false;
				TCHAR bufRestart[1024];
				int bufLen = mir_sntprintf(bufRestart, _T("%s\n"), TranslateT("Miranda NG must be restarted to apply changes for these plugins:"));

				HWND hwndList = GetDlgItem(hwndDlg, IDC_PLUGLIST);
				for (int iRow = 0; iRow != -1;) {
					TCHAR buf[1024];
					ListView_GetItemText(hwndList, iRow, 1, buf, _countof(buf));
					int iState = ListView_GetItemState(hwndList, iRow, LVIS_STATEIMAGEMASK);
					SetPluginOnWhiteList(buf, (iState & 0x2000) ? 1 : 0);

					if (!bOldMode && iState != 0x3000) {
						LVITEM lvi = { 0 };
						lvi.mask = LVIF_IMAGE | LVIF_PARAM;
						lvi.stateMask = -1;
						lvi.iItem = iRow;
						lvi.iSubItem = 0;
						if (ListView_GetItem(hwndList, &lvi)) {
							lvi.mask = LVIF_IMAGE;

							PluginListItemData *dat = (PluginListItemData*)lvi.lParam;
							if (iState == 0x2000) {
								// enabling plugin
								if (lvi.iImage == 3 || lvi.iImage == 5) {
									if (lvi.iImage == 3 && LoadPluginDynamically(dat)) {
										lvi.iImage = 2;
										ListView_SetItem(hwndList, &lvi);
									}
									else {
										bufLen += mir_sntprintf(bufRestart + bufLen, _countof(bufRestart) - bufLen, _T(" - %s\n"), buf);
										needRestart = true;
									}
								}
							}
							else {
								// disabling plugin
								if (lvi.iImage == 2 || lvi.iImage == 4) {
									if (lvi.iImage == 2 && UnloadPluginDynamically(dat)) {
										lvi.iImage = 3;
										ListView_SetItem(hwndList, &lvi);
									}
									else {
										bufLen += mir_sntprintf(bufRestart + bufLen, _countof(bufRestart) - bufLen, _T(" - %s\n"), buf);
										needRestart = true;
									}
								}
							}
						}
					}

					iRow = ListView_GetNextItem(hwndList, iRow, LVNI_ALL);
				}
				LoadStdPlugins();

				ShowWindow(GetDlgItem(hwndDlg, IDC_RESTART), needRestart);
				if (needRestart) {
					mir_sntprintf(bufRestart + bufLen, _countof(bufRestart) - bufLen, _T("\n%s"), TranslateT("Do you want to restart it now?"));
					if (MessageBox(NULL, bufRestart, _T("Miranda NG"), MB_ICONWARNING | MB_YESNO) == IDYES)
						CallService(MS_SYSTEM_RESTART, 1, 0);
				}
			}
		}
		break;

	case WM_COMMAND:
		if (HIWORD(wParam) == STN_CLICKED) {
			switch (LOWORD(wParam)) {
			case IDC_GETMOREPLUGINS:
				Utils_OpenUrl("http://miranda-ng.org/downloads/");
				break;

			case IDC_PLUGINEMAIL:
			case IDC_PLUGINURL:
				char buf[512];
				char *p = &buf[7];
				mir_strcpy(buf, "mailto:");
				if (GetDlgItemTextA(hwndDlg, LOWORD(wParam), p, _countof(buf) - 7))
					Utils_OpenUrl(LOWORD(wParam) == IDC_PLUGINEMAIL ? buf : p);
				break;
			}
		}
		break;

	case WM_DESTROY:
		arPluginList.destroy();
		RemoveAllItems(GetDlgItem(hwndDlg, IDC_PLUGLIST));
		break;
	}
	return FALSE;
}
示例#4
0
static LRESULT CALLBACK PluginListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg) {
	case WM_CHAR:
		if (wParam == '\b') {
			if (szFilter.GetLength() > 0)
				szFilter.Truncate(szFilter.GetLength() - 1);
		}
		else {
			szFilter.AppendChar(wParam);

			for (int i = 0; i < arPluginList.getCount(); i++) {
				PluginListItemData *p = arPluginList[i];
				if (!_tcsnicmp(szFilter, p->fileName, szFilter.GetLength())) {
					LVFINDINFO lvfi;
					lvfi.flags = LVFI_PARAM;
					lvfi.lParam = (LPARAM)p;
					int idx = ListView_FindItem(hwnd, 0, &lvfi);
					if (idx != -1) {
						ListView_SetItemState(hwnd, idx, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
						ListView_EnsureVisible(hwnd, idx, FALSE);
						if (timerID != 0)
							KillTimer(hwnd, timerID);
						timerID = SetTimer(hwnd, 1, 1500, 0);
						return TRUE;
					}
				}
			}

			szFilter.Truncate(szFilter.GetLength() - 1);
			MessageBeep((UINT)-1);
		}
		return TRUE;

	case WM_TIMER:
		if (wParam == 1) {
			KillTimer(hwnd, timerID);
			timerID = 0;
			szFilter.Empty();
		}
		break;

	case WM_LBUTTONDOWN:
		LVHITTESTINFO hi;
		hi.pt.x = LOWORD(lParam);
		hi.pt.y = HIWORD(lParam);
		ListView_SubItemHitTest(hwnd, &hi);
		// Dynamically load/unload a plugin
		if ((hi.iSubItem == 0) && (hi.flags & LVHT_ONITEMICON)) {
			LVITEM lvi = { 0 };
			lvi.mask = LVIF_IMAGE | LVIF_PARAM;
			lvi.stateMask = -1;
			lvi.iItem = hi.iItem;
			lvi.iSubItem = 0;
			if (ListView_GetItem(hwnd, &lvi)) {
				lvi.mask = LVIF_IMAGE;
				PluginListItemData *dat = (PluginListItemData*)lvi.lParam;
				if (lvi.iImage == 3) {
					// load plugin
					if (LoadPluginDynamically(dat)) {
						lvi.iImage = 2;
						ListView_SetItem(hwnd, &lvi);
					}
				}
				else if (lvi.iImage == 2) {
					// unload plugin
					if (UnloadPluginDynamically(dat)) {
						lvi.iImage = 3;
						ListView_SetItem(hwnd, &lvi);
					}
				}
				LoadStdPlugins();
			}
		}
	}

	return mir_callNextSubclass(hwnd, PluginListWndProc, msg, wParam, lParam);
}
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();
}