CStringA CUrlParser::BuildUrl() { CStringA strNewUrl; strNewUrl = m_strProtocol+"://"+m_strHost+m_strPath; if (m_ParamList.size() > 0) { strNewUrl+="?"; } for (ParamListPtr it = m_ParamList.begin();it!=m_ParamList.end();it++) { strNewUrl+=it->strParamName+"="+it->strParamValue+"&"; } strNewUrl.Delete(strNewUrl.GetLength()-1); return strNewUrl; }
void CSendFile::OnBnClickedButton1() { // TODO: 在此添加控件通知处理程序代码 UpdateData(TRUE); //发送请求 //获取文件名 CStringA filename = CW2A(m_strFilePath.GetBuffer(), CP_THREAD_ACP); int i = 0; while (i != -1) { i = filename.Find("\\"); filename.Delete(0, i + 1); } m_strFileName = filename; filename += L":" + m_fid; m_client->Send(FILETRANS, filename.GetBuffer(), 1); }
CStringA HeadingCounter::GetHeadingNumber(struct tree_node_t *node) { CStringA result; char tmp[1024]; // collect the numbers as a string (in reverse order) MapValue value; while (m_Map.Lookup(node, value)) { result.Insert(0, _itoa(value.m_nSelfNumber, tmp, 10)); result.Insert(0, "."); node = tree_get_parent(node); } // remove the leading '.' ASSERT(result.IsEmpty() == false); if (!result.IsEmpty()) result.Delete(0); return result; }
void CStretchDlg::OnBnClickedButtonStretchInvert() { if (!m_bValid) return; CStringA str; unsigned int pos = 0; while (pos < m_iStretchMap.size()) { int x = m_iStretchMap[pos++]; int y = 0; while (m_iStretchMap[pos] == 0) { if (pos >= m_iStretchMap.size()) break; ++pos; ++y; } AppendFormatA(str, " %d", y + 1); for (int i = 0; i < x - 1; ++i) AppendFormatA(str, " %d", 0); } str.Delete(0); SetDlgItemTextW(IDC_EDIT_STRETCH_MAP, conv::to_wide(str).data()); }
int CIPFilter::AddFromFile(LPCTSTR pszFilePath, bool bShowResponse) { DWORD dwStart = GetTickCount(); FILE* readFile = _tfsopen(pszFilePath, _T("r"), _SH_DENYWR); if (readFile != NULL) { enum EIPFilterFileType { Unknown = 0, FilterDat = 1, // ipfilter.dat/ip.prefix format PeerGuardian = 2, // PeerGuardian text format PeerGuardian2 = 3 // PeerGuardian binary format } eFileType = Unknown; setvbuf(readFile, NULL, _IOFBF, 32768); TCHAR szNam[_MAX_FNAME]; TCHAR szExt[_MAX_EXT]; _tsplitpath(pszFilePath, NULL, NULL, szNam, szExt); if (_tcsicmp(szExt, _T(".p2p")) == 0 || (_tcsicmp(szNam, _T("guarding.p2p")) == 0 && _tcsicmp(szExt, _T(".txt")) == 0)) eFileType = PeerGuardian; else if (_tcsicmp(szExt, _T(".prefix")) == 0) eFileType = FilterDat; else { VERIFY( _setmode(fileno(readFile), _O_BINARY) != -1 ); static const BYTE _aucP2Bheader[] = "\xFF\xFF\xFF\xFFP2B"; BYTE aucHeader[sizeof _aucP2Bheader - 1]; if (fread(aucHeader, sizeof aucHeader, 1, readFile) == 1) { if (memcmp(aucHeader, _aucP2Bheader, sizeof _aucP2Bheader - 1)==0) eFileType = PeerGuardian2; else { (void)fseek(readFile, 0, SEEK_SET); VERIFY( _setmode(fileno(readFile), _O_TEXT) != -1 ); // ugly! } } } int iFoundRanges = 0; int iLine = 0; if (eFileType == PeerGuardian2) { // Version 1: strings are ISO-8859-1 encoded // Version 2: strings are UTF-8 encoded uint8 nVersion; if (fread(&nVersion, sizeof nVersion, 1, readFile)==1 && (nVersion==1 || nVersion==2)) { while (!feof(readFile)) { CHAR szName[256]; int iLen = 0; for (;;) // read until NUL or EOF { int iChar = getc(readFile); if (iChar == EOF) break; if (iLen < sizeof szName - 1) szName[iLen++] = (CHAR)iChar; if (iChar == '\0') break; } szName[iLen] = '\0'; uint32 uStart; if (fread(&uStart, sizeof uStart, 1, readFile) != 1) break; uStart = ntohl(uStart); uint32 uEnd; if (fread(&uEnd, sizeof uEnd, 1, readFile) != 1) break; uEnd = ntohl(uEnd); iLine++; // (nVersion == 2) ? OptUtf8ToStr(szName, iLen) : AddIPRange(uStart, uEnd, DFLT_FILTER_LEVEL, CStringA(szName, iLen)); iFoundRanges++; } } } else { CStringA sbuffer; CHAR szBuffer[1024]; while (fgets(szBuffer, _countof(szBuffer), readFile) != NULL) { iLine++; sbuffer = szBuffer; // ignore comments & too short lines if (sbuffer.GetAt(0) == '#' || sbuffer.GetAt(0) == '/' || sbuffer.GetLength() < 5) { sbuffer.Trim(" \t\r\n"); DEBUG_ONLY( (!sbuffer.IsEmpty()) ? TRACE("IP filter: ignored line %u\n", iLine) : 0 ); continue; } if (eFileType == Unknown) { // looks like html if (sbuffer.Find('>') > -1 && sbuffer.Find('<') > -1) sbuffer.Delete(0, sbuffer.ReverseFind('>') + 1); // check for <IP> - <IP> at start of line UINT u1, u2, u3, u4, u5, u6, u7, u8; if (sscanf(sbuffer, "%u.%u.%u.%u - %u.%u.%u.%u", &u1, &u2, &u3, &u4, &u5, &u6, &u7, &u8) == 8) { eFileType = FilterDat; } else { // check for <description> ':' <IP> '-' <IP> int iColon = sbuffer.Find(':'); if (iColon > -1) { CStringA strIPRange = sbuffer.Mid(iColon + 1); UINT u1, u2, u3, u4, u5, u6, u7, u8; if (sscanf(strIPRange, "%u.%u.%u.%u - %u.%u.%u.%u", &u1, &u2, &u3, &u4, &u5, &u6, &u7, &u8) == 8) { eFileType = PeerGuardian; } } } } bool bValid = false; uint32 start = 0; uint32 end = 0; UINT level = 0; CStringA desc; if (eFileType == FilterDat) bValid = ParseFilterLine1(sbuffer, start, end, level, desc); else if (eFileType == PeerGuardian) bValid = ParseFilterLine2(sbuffer, start, end, level, desc); // add a filter if (bValid) { AddIPRange(start, end, level, desc); iFoundRanges++; } else { sbuffer.Trim(" \t\r\n"); DEBUG_ONLY( (!sbuffer.IsEmpty()) ? TRACE("IP filter: ignored line %u\n", iLine) : 0 ); } } } fclose(readFile); // sort the IP filter list by IP range start addresses qsort(m_iplist.GetData(), m_iplist.GetCount(), sizeof(m_iplist[0]), CmpSIPFilterByStartAddr); // merge overlapping and adjacent filter ranges int iDuplicate = 0; int iMerged = 0; if (m_iplist.GetCount() >= 2) { // On large IP-filter lists there is a noticeable performance problem when merging the list. // The 'CIPFilterArray::RemoveAt' call is way too expensive to get called during the merging, // thus we use temporary helper arrays to copy only the entries into the final list which // are not get deleted. // Reserve a byte array (its used as a boolean array actually) as large as the current // IP-filter list, so we can set a 'to delete' flag for each entry in the current IP-filter list. char* pcToDelete = new char[m_iplist.GetCount()]; memset(pcToDelete, 0, m_iplist.GetCount()); int iNumToDelete = 0; SIPFilter* pPrv = m_iplist[0]; int i = 1; while (i < m_iplist.GetCount()) { SIPFilter* pCur = m_iplist[i]; if ( pCur->start >= pPrv->start && pCur->start <= pPrv->end // overlapping || pCur->start == pPrv->end+1 && pCur->level == pPrv->level) // adjacent { if (pCur->start != pPrv->start || pCur->end != pPrv->end) // don't merge identical entries { //TODO: not yet handled, overlapping entries with different 'level' if (pCur->end > pPrv->end) pPrv->end = pCur->end; //pPrv->desc += _T("; ") + pCur->desc; // this may create a very very long description string... iMerged++; } else { // if we have identical entries, use the lowest 'level' if (pCur->level < pPrv->level) pPrv->level = pCur->level; iDuplicate++; } delete pCur; //m_iplist.RemoveAt(i); // way too expensive (read above) pcToDelete[i] = 1; // mark this entry as 'to delete' iNumToDelete++; i++; continue; } pPrv = pCur; i++; } // Create new IP-filter list which contains only the entries from the original IP-filter list // which are not to be deleted. if (iNumToDelete > 0) { CIPFilterArray newList; newList.SetSize(m_iplist.GetCount() - iNumToDelete); int iNewListIndex = 0; for (int i = 0; i < m_iplist.GetCount(); i++) { if (!pcToDelete[i]) newList[iNewListIndex++] = m_iplist[i]; } ASSERT( iNewListIndex == newList.GetSize() ); // Replace current list with new list. Dump, but still fast enough (only 1 memcpy) m_iplist.RemoveAll(); m_iplist.Append(newList); newList.RemoveAll(); m_bModified = true; } delete[] pcToDelete; } if (thePrefs.GetVerbose()) { DWORD dwEnd = GetTickCount(); AddDebugLogLine(false, _T("Loaded IP filters from \"%s\""), pszFilePath); AddDebugLogLine(false, _T("Parsed lines/entries:%u Found IP ranges:%u Duplicate:%u Merged:%u Time:%s"), iLine, iFoundRanges, iDuplicate, iMerged, CastSecondsToHM((dwEnd-dwStart+500)/1000)); } AddLogLine(bShowResponse, GetResString(IDS_IPFILTERLOADED), m_iplist.GetCount()); } return m_iplist.GetCount(); }
static bool fixLinks(CStringA& rtf, uidToTitleMap_t *uidToTitleMapPtr) { // quick check, quick exit if (rtf.Find("\\lnkd\\protect") == -1) return false; int clrTableIndex = getColorTableIndex(rtf); if (clrTableIndex == -1) { // something bad happened return false; } // get code page unsigned codepage = CP_ACP; int cpgPos = rtf.Find("\\ansicpg"); if (cpgPos != -1) codepage = atoi((LPCSTR)rtf + cpgPos + sizeof("\\ansicpg")-1); // for each pattern of // \lnkd\protect[<space>]<text>\protect0\lnkd0 // replace with "out", where out is: // sprintf(out, _linkRTF, <nodeurl>, clrTableIndex, <text>) // where <nodeurl> is: // lookupNode(stripRTF(<text>)) int pos, ofs = 0; while ( (pos = rtf.Find("\\lnkd\\protect", ofs)) != -1 ) { // ofs2 points to start of text int ofs2 = pos + sizeof("\\lnkd\\protect")-1; // check if the \protect had a ' ' delimiter, eat it if so if (rtf[ofs2] == ' ') ofs2++; // locate the end tag int pos2 = rtf.Find("\\protect0\\lnkd0", ofs2); ASSERT(pos2 != -1); if (pos2 == -1) return false; // get the text inbetween // here is the link (title of page).. CStringA rtfLink = rtf.Mid(ofs2, pos2-ofs2); CString link = stripRTF(rtfLink, codepage); // look it up CStringA url; if (isURL(link)) { // points to a URL itself (http://, https://, ftp:// etc..) url = escapeRTF(link); // There appears to be a strange bug with the rich edit control, in that if // the hyperlink and the text are exacly the same, the hyperlink effect goes // off. As a workaround, add a space after the URL (this is ignore in our // EN_LINK handler). url += " "; } else { uint32 nodeUid = 0; if (uidToTitleMapPtr->Lookup(link, nodeUid)) // matched a node url.Format("node://./%u", nodeUid); else // unmatched node, we'll handle this later url.Format("oldlink://./%s", escapeRTF(link)); } // make the replacement CStringA replacement; replacement.Format(_linkRTF, url, clrTableIndex, escapeRTF(link)); // delete [pos, pos2+15] rtf.Delete(pos, pos2+15-pos); rtf.Insert(pos, replacement); // repositon to just after the replacement ofs = pos + replacement.GetLength(); } return true; }
// 根据字符串获取键盘码 void CDuiObject::ParseKeyCode(LPCTSTR lpszValue, UINT& nChar, UINT& nFlag) { CStringA strValue; strValue = lpszValue; nChar = 0; nFlag = 0; strValue.Trim(); strValue.MakeUpper(); CStringA strFlag = ""; CStringA strChar = strValue; int nPos = strValue.Find("+"); if(nPos != -1) { strFlag = strValue.Left(nPos); strValue.Delete(0, nPos+1); strChar = strValue; strFlag.Trim(); strChar.Trim(); } if(strChar.IsEmpty()) { return; } if(strFlag == "CTRL") { nFlag |= VK_CONTROL; }else if(strFlag == "ALT") { nFlag |= VK_MENU; }else if(strFlag == "SHIFT") { nFlag |= VK_SHIFT; } if(strChar == "RETURN") { nChar = VK_RETURN; }else if(strChar == "ESC") { nChar = VK_ESCAPE; }else if(strChar == "BACK") { nChar = VK_BACK; }else if(strChar == "TAB") { nChar = VK_TAB; }else if(strChar == "SPACE") { nChar = VK_SPACE; }else if(strChar == "PRIOR") { nChar = VK_PRIOR; }else if(strChar == "NEXT") { nChar = VK_NEXT; }else if(strChar == "END") { nChar = VK_END; }else if(strChar == "HOME") { nChar = VK_HOME; }else if(strChar == "LEFT") { nChar = VK_LEFT; }else if(strChar == "UP") { nChar = VK_UP; }else if(strChar == "RIGHT") { nChar = VK_RIGHT; }else if(strChar == "DOWN") { nChar = VK_DOWN; }else if(strChar == "SELECT") { nChar = VK_SELECT; }else if(strChar == "PRINT") { nChar = VK_PRINT; }else if(strChar == "INSERT") { nChar = VK_INSERT; }else if(strChar == "DELETE") { nChar = VK_DELETE; }else if(strChar == "F1") { nChar = VK_F1; }else if(strChar == "F2") { nChar = VK_F2; }else if(strChar == "F3") { nChar = VK_F3; }else if(strChar == "F4") { nChar = VK_F4; }else if(strChar == "F5") { nChar = VK_F5; }else if(strChar == "F6") { nChar = VK_F6; }else if(strChar == "F7") { nChar = VK_F7; }else if(strChar == "F8") { nChar = VK_F8; }else if(strChar == "F9") { nChar = VK_F9; }else if(strChar == "F10") { nChar = VK_F10; }else if(strChar == "F11") { nChar = VK_F11; }else if(strChar == "F12") { nChar = VK_F12; }else { char ch = strChar[0]; if(((ch >= '0') && (ch < '9')) || ((ch >= 'A') && (ch < 'Z'))) { nChar = ch; } } }