virtual RegexMatch search(const char* data, size_t size) { const char* range = rangePrepare(data, size); RegexMatch result = rangeSearch(range, size); rangeFinalize(range); return result ? RegexMatch(result.data - range + data, result.size) : RegexMatch(); }
// 检测浮点数 // "+73.24745e-363" BOOL CStringChecker::CheckDouble( LPCTSTR cStr ) { char str[] = "^([\\+\\-])?\\d+(\\.\\d+)?([Ee][\\+\\-]?\\d+)?$"; CString strTemp(cStr); strTemp.Trim(' '); BOOL b = RegexMatch(strTemp, str); //BOOL b = RegexMatch(cStr, str); if(!b) { SetLastErr(TYPE_DOUBLE); return FALSE; //"浮点数不合规则"; } std::stringstream ss; double n; ss << cStr; ss >> n; if(ss.fail()) { SetLastErr("浮点数越界"); return FALSE; } else if(n == numeric_limits<double>::infinity() || n == -numeric_limits<double>::infinity()) { SetLastErr("浮点数越界"); return FALSE; } return TRUE; //""; }
virtual RegexMatch rangeSearch(const char* data, size_t size) { size_t offset = 0; if (matcher) { offset = matcher->match(data, size); assert(offset <= size); if (offset == size) return RegexMatch(); } re2::StringPiece p(data, size); re2::StringPiece match; if (re->Match(p, offset, size, re2::RE2::UNANCHORED, &match, 1)) return RegexMatch(match.data(), match.size()); return RegexMatch(); }
// 6.版本号命名不合规则 BOOL CStringChecker::CheckVersion( LPCTSTR cStr ) { {//正则匹配法 char str[] = "^([Vv]?\\d+(.\\d+)*)?$"; BOOL b = RegexMatch(cStr, str); if(!b) { SetLastErr(TYPE_VERSION); return FALSE; } return TRUE; } // CString cStrRet = CheckLength(cStr, 20); // if(!cStrRet.IsEmpty()) return cStrRet; // // bool bCheckSuccess = true; // // int nLength = cStr.GetLength(); // // // for(int i = 0; i < nLength; i++) // { // if(cStr[i] != '.' && (cStr[i] < '0' || cStr[i] >'9')) // {//字符过滤 // bCheckSuccess = false; // break; // } // // if(i > 0 && cStr[i - 1] == '.' && cStr[i] == '.') // {//连续dot过滤 // bCheckSuccess = false; // break; // } // } // // if(nLength != 0) // {//首尾验证 // if(cStr[0] == '.' || cStr[nLength - 1] == '.') // { // bCheckSuccess = false; // } // } // // if(!bCheckSuccess) // { // return "命名不合规则"; // } // // return ""; }
int main(int argc, char **argv) { char buf[128], buf2[128]; char *msg; Regex *re; char *fpos, *epos; FILE *f = stdin; int i = 1; #ifdef USE_M17N wtf_init(WC_CES_EUC_JP, WC_CES_EUC_JP); #endif #ifdef REGEX_DEBUG for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-v") == 0) verbose = 1; else break; } #endif if (argc > i) f = fopen(argv[i], "r"); if (f == NULL) { fprintf(stderr, "Can't open %s\n", argv[i]); exit(1); } while (fscanf(f, "%s%s", buf, buf2) == 2) { re = newRegex(buf, 0, NULL, &msg); if (re == NULL) { printf("Error on regexp /%s/: %s\n", buf, msg); exit(1); } if (RegexMatch(re, buf2, -1, 1)) { printf("/%s/\t\"%s\"\t\"", buf, buf2); MatchedPosition(re, &fpos, &epos); while (fpos < epos) putchar(*(fpos++)); putchar('"'); } else printf("/%s/\t\"%s\"\tno_match", buf, buf2); putchar('\n'); } /* notreatched */ return 0; }
// 检测整数 BOOL CStringChecker::CheckIntNumber(CString cStr) { char str[] = "^[\\-]?([1-9]\\d*)|0$"; CString strTemp(cStr); strTemp.Trim(' '); BOOL b = RegexMatch(strTemp, str); //BOOL b = RegexMatch(cStr, str); if(!b) { SetLastErr(TYPE_INT); return FALSE;//"整数不合规则"; } CString sInt(cStr); if (sInt == "-0") { SetLastErr(TYPE_INT); return FALSE; } return TRUE;//""; }
/*----------------------------------------------------------------------------- -----------------------------------------------------------------------------*/ void CWinInetEvents::OnHttpSendRequest(HINTERNET hRequest, CString &headers, LPVOID lpOptional, DWORD dwOptionalLength) { // update the activity time if( active ) { EnterCriticalSection(&cs); CWinInetRequest * r = NULL; winInetRequests.Lookup(hRequest, r); LeaveCriticalSection(&cs); if( r ) { ATLTRACE(_T("[Pagetest] - *** (0x%08X) 0x%p - OnHttpSendRequest: %s%s\n"), GetCurrentThreadId(), hRequest, r->host, r->object); } else { ATLTRACE(_T("[Pagetest] - *** (0x%08X) 0x%p - OnHttpSendRequest\n"), GetCurrentThreadId(), hRequest); } if( headers.GetLength() ) { ATLTRACE(_T("[Pagetest] - Headers:\n%s"), (LPCTSTR)headers); } // modify the user agent string if it was passed as a custom header (IE8) if( !userAgent.IsEmpty() ) { CString lcase = headers; lcase.MakeLower(); int offset = lcase.Find(_T("user-agent")); if( offset >= 0 ) { offset = lcase.Find(_T(":"), offset); if( offset >= 0 ) { int end = lcase.Find(_T('\n'), offset); if( end >= -1 ) { // insert it in the middle of the string headers = headers.Left(offset + 2) + userAgent + headers.Mid(end); } } } } else if( script_modifyUserAgent && !keepua ) { CString agent; agent.Format(_T("; PTST 2.%d"), build); if( headers.Find(agent) == -1 ) { CString lcase = headers; lcase.MakeLower(); int offset = lcase.Find(_T("user-agent")); if( offset >= 0 ) { int end = lcase.Find(_T('\n'), offset); if( end >= -1 ) { // now scan backwards for the end parenthesis CString left = lcase.Left(end); int end2 = left.ReverseFind(_T(')')); if( end2 >= 0 ) end = end2; // insert it in the middle of the string headers = headers.Left(end) + agent + headers.Mid(end); } } } } // add any custom headers POSITION pos = headersAdd.GetHeadPosition(); while(pos) { CAddHeader header = headersAdd.GetNext(pos); CString h = header.header; if( h.GetLength() && RegexMatch(r->host, header.filter) ) { h = h + _T("\r\n"); HttpAddRequestHeaders( hRequest, h, h.GetLength(), HTTP_ADDREQ_FLAG_ADD ); } } // override any headers specified pos = headersSet.GetHeadPosition(); while(pos) { CString h = headersSet.GetNext(pos); if( h.GetLength() ) { h = h + _T("\r\n"); HttpAddRequestHeaders( hRequest, h, h.GetLength(), HTTP_ADDREQ_FLAG_ADD | HTTP_ADDREQ_FLAG_REPLACE ); // remove the header if it is passed in in the current headers int i = h.Find(_T(':')); if( i > 0 ) { CString key = h.Left(i).Trim(); do { i = headers.Find(key); if( i >= 0 ) { int e = headers.Find(_T('\n'), i); if( e > i) headers = headers.Left(i) + headers.Mid(e + 1); else headers = headers.Left(i); } }while(i >= 0); } } } OverrideHost(r); // tweak the SSL options if we are ignoring cert errors if( r && r->secure && ignoreSSL ) { DWORD flags = 0; DWORD len = sizeof(flags); if( InternetQueryOption(r->hRequest, INTERNET_OPTION_SECURITY_FLAGS, &flags, &len) ) { flags |= SECURITY_FLAG_IGNORE_CERT_CN_INVALID | SECURITY_FLAG_IGNORE_CERT_DATE_INVALID | SECURITY_FLAG_IGNORE_REDIRECT_TO_HTTP | SECURITY_FLAG_IGNORE_REDIRECT_TO_HTTPS | SECURITY_FLAG_IGNORE_REVOCATION | SECURITY_FLAG_IGNORE_UNKNOWN_CA | SECURITY_FLAG_IGNORE_WRONG_USAGE; InternetSetOption(r->hRequest, INTERNET_OPTION_SECURITY_FLAGS, &flags, len); } } if( r && !r->ignore ) QueryPerformanceCounter((LARGE_INTEGER *)&lastActivity); } ATLTRACE(_T("[Pagetest] - *** (0x%08X) 0x%p - OnHttpSendRequest - complete\n"), GetCurrentThreadId(), hRequest); }
/* * regexMatch: match regular expression */ int regexMatch(char *str, int len, int firstp) { return RegexMatch(&DefaultRegex, str, len, firstp); }
BOOL CStringChecker::CheckParamName( LPCTSTR cStr ) { { CString sCheckString(cStr); if (sCheckString.Find("双击添加参数") != -1) { SetLastErr(CStringCheckerConfig::CheckErrorParamCustom); return FALSE; } } BOOL b = TRUE; LPCTSTR p = cStr; int nlenth =0; unsigned char c = *p; nlenth = strlen(cStr); if (cStr[0]==0x20||cStr[nlenth-1]==0x20) { SetLastErr(CStringCheckerConfig::CheckErrorParam); return FALSE; } { char str[] = "^\\d+$"; CString strTemp(cStr); //空格,点和斜杠不能和纯数字一起用 strTemp.Replace(' ', '1'); strTemp.Replace('.', '1'); strTemp.Replace('\\', '1'); //strTemp.Replace('-', '1'); b = !RegexMatch(strTemp, str); } if(!b) { } else while(c = *p++) { if((c < '0' || c > '9') && (c < 'a' || c > 'z') && (c < 'A' || c > 'Z') && \ (c != '_')&& (c!='\\') && (c!='.') &&(c!=' ') &&(c!='-') )//允许参数名含有减号、.和\。 { if( (c >= 0xB0 && c<= 0xF7 && UCHAR(*p) >= 0xA1 && UCHAR(*p) <= 0xFE) || (c == 0xA6 && UCHAR(*p) >= 0xA1 && UCHAR(*p) <= 0xFE)) {//属于汉字范围(16-87区)或希腊字母(6区) p++; continue; } b = FALSE; break; } } if(!b) { SetLastErr(CStringCheckerConfig::CheckErrorParam); return b; } b = CheckEmpty(cStr); if(!b) return b; b = CheckLength(cStr, 50); return b; }
//检查12345 BOOL CStringChecker::CheckNodeName( LPCTSTR cStr ) { // BOOL b; // b = CheckEmpty(cStr); // if(!b) return b; // b = CheckWindowsRuler(cStr); // if(!b) return b; // b = CheckSpacePoint(cStr); // if(!b) return b; // b = CheckFirstNumber(cStr); // if(!b) return b; // b = CheckLength(cStr, 50); // return b; //char str[] = "^[a-zA-Z_\\xB0-\\xF7\\xA1-\\xFE][a-zA-Z0-9_\\xB0-\\xF7\\xA1-\\xFE]*$"; //BOOL b = RegexMatch(cStr, str); BOOL b = TRUE; LPCTSTR p = cStr; unsigned char c = *p; //if(c >= '0' && c <= '9') b =FALSE; //if(CheckIntNumber(cStr))b = FALSE; { char str[] = "^\\d+$"; CString strTemp(cStr); //strTemp.Replace('-', '1'); b = !RegexMatch(strTemp, str); } if(!b ) { } else while(c = *p++) { if((c < '0' || c > '9') && (c < 'a' || c > 'z') && (c < 'A' || c > 'Z') && c != '_' && c != '-') //允许参数名含有减号 //if((c < '0' || c > '9') && (c < 'a' || c > 'z') && (c < 'A' || c > 'Z') && c != '_' ) { if( (c >= 0xB0 && c<= 0xF7 && UCHAR(*p) >= 0xA1 && UCHAR(*p) <= 0xFE) || (c == 0xA6 && UCHAR(*p) >= 0xA1 && UCHAR(*p) <= 0xFE) ) {//属于汉字范围(16-87区)或希腊字母(6区) p++; continue; } b = FALSE; break; } } if(CString(cStr).FindOneOf(CStringCheckerConfig::CheckFilter) != -1) {//字符查找 b = FALSE; } if(!b) { SetLastErr(CStringCheckerConfig::CheckErrorNode); return b; } b = CheckEmpty(cStr); if(!b) return b; b = CheckLength(cStr, 50); return b; }