VVirtualHost *VVirtualHostManager::RetainMatchingVirtualHost (const VHTTPRequest& inRequest) { VVirtualHost * virtualHost = NULL; XBOX::VTaskLock lock (&fLock); #if HTTP_SERVER_USE_PROJECT_PATTERNS // Try first to find a VirtualHost matching both host header & project application keyword (if any) for (VVirtualHostMap::const_iterator it = fURLPatternsMap.begin(); it != fURLPatternsMap.end(); ++it) { if (MatchRegex (it->first, inRequest.GetURL())) { if (it->second->MatchHostPattern (inRequest.GetHost())) { virtualHost = it->second; break; } } } #endif if ((NULL == virtualHost) && (fVirtualHosts.size() > 0)) { // We have one VirtualHost only... OK it's the easiest case --> just return it (no matter what host header contains) if (fVirtualHosts.size() == 1) { virtualHost = fVirtualHosts.at (0); } else { // Try to find a Virtual Host matching the port (no matter what address the request match) #if WITH_DEPRECATED_IPV4_API virtualHost = _FindMatchingVirtualHost (fHostPatternsMap, 0, inRequest.GetLocalPort()); #else virtualHost = _FindMatchingVirtualHost (fHostPatternsMap, STRING_EMPTY, inRequest.GetLocalPort()); #endif // Other else try to find a VirtualHost matching the Host if (NULL == virtualHost) virtualHost = _FindMatchingVirtualHost (fHostPatternsMap, inRequest.GetHost()); } } if (NULL != virtualHost) virtualHost->Retain(); return virtualHost; }
bool FeedFilter::Term::MatchValue(const char* szStrValue, long long iIntValue) { double fFloatValue = (double)iIntValue; char szIntBuf[100]; if (m_eCommand < fcEqual && !szStrValue) { snprintf(szIntBuf, 100, "%lld", iIntValue); szIntBuf[100-1] = '\0'; szStrValue = szIntBuf; } else if (m_eCommand >= fcEqual && szStrValue) { fFloatValue = atof(szStrValue); iIntValue = (long long)fFloatValue; } switch (m_eCommand) { case fcText: return MatchText(szStrValue); case fcRegex: return MatchRegex(szStrValue); case fcEqual: return m_bFloat ? fFloatValue == m_fFloatParam : iIntValue == m_iIntParam; case fcLess: return m_bFloat ? fFloatValue < m_fFloatParam : iIntValue < m_iIntParam; case fcLessEqual: return m_bFloat ? fFloatValue <= m_fFloatParam : iIntValue <= m_iIntParam; case fcGreater: return m_bFloat ? fFloatValue > m_fFloatParam : iIntValue > m_iIntParam; case fcGreaterEqual: return m_bFloat ? fFloatValue >= m_fFloatParam : iIntValue >= m_iIntParam; default: return false; } }
void ShapeFile::SubsetRegex_( // select shapes matching regex const char* sregex) // in: regex string, NULL or "" to match any { if (sregex && sregex[0]) { const regex re(CompileRegex(sregex)); int j = 0; for (int i = 0; i < nshapes_; i++) if (MatchRegex(bases_[i], re)) { shapes_[j] = shapes_[i]; bases_ [j] = bases_ [i]; bits_ [j] = bits_ [i]; j++; } if (j == 0) Err("No shapes in %s match \"%s\"", shapepath_, sregex); shapes_.resize(j); nshapes_ = j; } }
void ADVBConfig::ListUsers(AList& list) const { AHash users(10); AList userpatterns; AString filepattern = GetUserPatternsPattern(); AString filepattern_parsed = ParseRegex(filepattern); AString _users = GetConfigItem("users"); AStdFile fp; uint_t i, n = _users.CountColumns(); //debug("Reading users from config %s\n", config.GetFilename().str()); for (i = 0; i < n; i++) { AString user = _users.Column(i).Words(0); if (!users.Exists(user)) { users.Insert(user, 0); list.Add(new AString(user)); } } if (fp.open(GetPatternsFile())) { AString line; while (line.ReadLn(fp) >= 0) { AString user; int p; if ((p = line.PosNoCase(" user:="******"user:=") == 0) user = line.Mid(6).Word(0).DeQuotify(); if (user.Valid() && !users.Exists(user)) { users.Insert(user, 0); list.Add(new AString(user)); } } fp.close(); } ::CollectFiles(filepattern.PathPart(), filepattern.FilePart(), 0, userpatterns); const AString *file = AString::Cast(userpatterns.First()); while (file) { AString user; ADataList regions; if (MatchRegex(*file, filepattern_parsed, regions)) { const REGEXREGION *region = (const REGEXREGION *)regions[0]; if (region) { user = file->Mid(region->pos, region->len); if (!users.Exists(user)) { users.Insert(user, 0); list.Add(new AString(user)); } } } file = file->Next(); } list.Sort(&AString::AlphaCompareCase); }