void HelpViewer::showHelp(const String& org_url, String entry) { String url = org_url; String fragment; if (url.has('#')) { url = url.before("#"); fragment = org_url.after("#"); } QUrl qurl = QUrl::fromLocalFile((base_dir_ + url).c_str()); if (fragment != "") qurl.setFragment(fragment.c_str()); browser_->setSource(qurl); QTextCursor ct = browser_->textCursor(); if (!ct.atStart()) { ct.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor); browser_->setTextCursor(ct); } if (entry != "") browser_->find(entry.c_str(), QTextDocument::FindCaseSensitively); if (!isVisible()) { show(); setFloating(true); showMaximized(); } }
void NaughtyFilter::checkPICSagainstoption(String s, const char *l, int opt, std::string m) { if (s.indexOf(l) != -1) { // if the rating contains the label then: int i = 0; // get the rating label value s = s.after(l); if (s.indexOf(" ") != -1) { //remove anything after it s = s.before(" "); } // sanity checking if (s.length() > 0) { i = s.toInteger(); // convert the value in a String to an integer if (opt < i) { // check its value against the option in config file isItNaughty = true; // must be over limit whatIsNaughty = m + " "; message_no = 1000; whatIsNaughty += o.language_list.getTranslation(1000); // PICS labeling level exceeded on the above site. whatIsNaughtyCategories = "PICS"; whatIsNaughtyLog = whatIsNaughty; } } } }
int HTTPHandler::sendGetRequest(String url) { std::string ip; String request; String host; #if 0 /* get the host and url */ if(url.contains("/")) { host = url.before("/"); url = url.after("/"); } else { host = url; url = ""; } if(!url.empty()) { request = "GET " + url + " HTTP 1.0\r\n"; request += "Host: " + host + "\r\n\r\n"; } else { } #else if(url.contains("/")) { host = url.before("/"); } else { host = url; } request = "GET http://" + url + " HTTP/1.0\r\n\r\n"; #endif /* get the ip addr */ hostname_to_ip(host,ip); mpSocket = new Socket(ip,80); return mpSocket->write(request); }
// get hostname from string as url String String::getHostname() { String hostname; hostname = this->substr(0); if (hostname.contains("://")) hostname = hostname.after("://"); if (hostname.contains("/")) hostname = hostname.before("/"); if (hostname.contains("@")) // Contains a username:password combo hostname = hostname.after("@"); return hostname; }
bool INIFile::appendLine(const String& sectionName, const String& line) { String section_name(sectionName); if (section_name == "") { SectionIterator it(sections_.end()); it--; section_name = it->getName(); } if (!hasSection(section_name) || line[0] == '[') { Log.error() << "In INIFile " << filename_ << " , error while appending line: " << line << " . Illegal section-name: " << sectionName << endl; return false; } Section& section(*getSection(section_name)); // key? if (line.hasSubstring("=", 1)) { String key(line.before("=")); key.trim(); if (section.key_map_.has(key) && check_duplicate_keys_) { Log.error() << "In INIFile " << filename_ << " , error while appending line: " << line << " . Key '" << key << "' already exists in section." << endl; return false; } section.lines_.push_back(line); list<String >::iterator line_it(section.lines_.end()); line_it--; section.key_map_[key] = line_it; return true; } section.lines_.push_back(line); return true; }
void HelpViewer::onNotify(Message *message) { #ifdef BALL_VIEW_DEBUG Log.error() << "HelpViewer" << this << "onNotify " << message << std::endl; #endif if (RTTI::isKindOf<RegisterHelpSystemMessage>(message)) { RegisterHelpSystemMessage* msg = RTTI::castTo<RegisterHelpSystemMessage>(*message); if (msg->isRegister()) { registerForHelpSystem(msg->getObject(), msg->getURL()); } else { unregisterForHelpSystem(msg->getObject()); } return; } if (!RTTI::isKindOf<ShowHelpMessage>(message)) return; ShowHelpMessage* msg = RTTI::castTo<ShowHelpMessage>(*message); bool classname = false; String project = msg->getProject(); String url = msg->getURL(); if (project.hasSuffix(" class")) { classname = true; project = project.before(" "); } if (project != project_) return; if (classname) { showDocumentationFor(url, msg->getEntry()); return; } showHelp(url, msg->getEntry()); }
bool INIFile::insertLine(LineIterator line_it, const String& line) { if (!isValid(line_it)) { Log.error() << "In INIFile " << filename_ << " , error while inserting line: " << line << " . Illegal iterator!" << endl; return false; } if (line_it.isSectionLastLine()) { return appendLine(line_it.getSection()->getName(), line); } Section& section(*line_it.getSection()); // key? if (line.hasSubstring("=", 1)) { String key(line.before("=")); key.trim(); if (section.key_map_.has(key) && check_duplicate_keys_) { Log.error() << "In INIFile " << filename_ << " , error while appending line: " << line << " . Key '" << key << "' already exists in section." << endl; return false; } line_it.getSectionNextLine(); section.key_map_[key] = section.lines_.insert(line_it.position_, line); return true; } line_it.getSectionNextLine(); section.lines_.insert(line_it.position_, line); return true; }
// I'm not proud of this... --Ernest String HTTPHeader::getCookie(const char *cookie) { String line; // TODO - do away with loop here somehow, or otherwise speed it up? for (std::deque<String>::iterator i = header.begin(); i != header.end(); i++) { if (i->startsWithLower("cookie:")) { line = i->after(": "); if (line.contains(cookie)) { // We know we have the cookie line = line.after(cookie); line.lop(); // Get rid of the '=' if (line.contains(";")) { line = line.before(";"); } } // break; // Technically there should be only one Cookie: header, but... } } line.removeWhiteSpace(); #ifdef DGDEBUG std::cout << "Found GBYPASS cookie:" << line << std::endl; #endif return line; }
bool INIFile::setLine(LineIterator line_it, const String& line) { // section lines cannot be changed with this method if (!isValid(line_it) || (*line_it)[0] == '[') { return false; } String new_key(line.before("=")); new_key.trim(); if ((*line_it).hasSubstring("=", 1)) { // oh, this line had a key :( String old_key((*line_it).before("=")); old_key.trim(); if (old_key == new_key) { line_it.setLine_(line); return true; } // its a new key: delete the old one. line_it.getSection()->key_map_.remove(old_key); } line_it.setLine_(line); if (line.hasSubstring("=", 1)) { // oh, the new line has a key :( line_it.getSection()->key_map_[new_key] = line_it.getPosition(); } return true; }
// Test whether or not a particular request's incoming/outgoing data should be scanned. // This is a later-stage test; info is known about the actual data itself when this is called. int CSPlugin::willScanData(const String &url, const char *user, int filtergroup, const char *ip, bool post, bool reconstituted, bool exception, bool bypass, const String &disposition, const String &mimetype, off_t size) { //exceptionvirusmimetypelist if (mimetype.length() > 2) { if (exceptionvirusmimetypelist.findInList(mimetype.toCharArray()) != NULL) { #ifdef DGDEBUG std::cout << "willScanData: ignoring exception MIME type (" << mimetype.c_str() << ")" << std::endl; #endif return DGCS_NOSCAN; // match } } //exceptionvirusextensionlist String extension; if (disposition.length() > 2) { // If we have a content-disposition, determine file extension from that #ifdef DGDEBUG std::cout << "disposition: " << disposition << std::endl; #endif std::string::size_type start = disposition.find("filename="); if (start != std::string::npos) { start += 9; char endchar = ';'; if (disposition[start] == '"') { endchar = '"'; ++start; } std::string::size_type end = disposition.find(endchar, start); if (end != std::string::npos) extension = disposition.substr(start, end - start); else extension = disposition.substr(start); } while (extension.contains(".")) { extension = extension.after("."); } extension = "." + extension; #ifdef DGDEBUG std::cout << "extension from disposition: " << extension << std::endl; #endif } else { // Otherwise, determine it from the URL String urld(HTTPHeader::decode(url)), path; urld.removeWhiteSpace(); urld.toLower(); urld.removePTP(); if (urld.contains("/")) { path = urld.after("/"); path.hexDecode(); path.realPath(); } if (!path.contains("?")) { extension = path; } else if (mimetype.contains("application/")) { extension = path; if (extension.contains("?")) { extension = extension.before("?"); } } #ifdef DGDEBUG std::cout << "extension from URL: " << extension << std::endl; #endif } if (extension.contains(".")) { if (exceptionvirusextensionlist.findEndsWith(extension.toCharArray()) != NULL) { #ifdef DGDEBUG std::cout << "willScanData: ignoring exception file extension (" << extension.c_str() << ")" << std::endl; #endif return DGCS_NOSCAN; // match } } #ifdef DGDEBUG std::cout << "willScanData: I'm interested" << std::endl; #endif return DGCS_NEEDSCAN; }
String HTTPHeader::url(bool withport) { // Version of URL *with* port is not cached, // as vast majority of our code doesn't like // port numbers in URLs. if (cachedurl.length() > 0 && !withport) return cachedurl; port = 80; bool https = false; String hostname; String answer(header.front().after(" ")); answer.removeMultiChar(' '); if (answer.after(" ").startsWith("HTTP/")) { answer = answer.before(" HTTP/"); } else { answer = answer.before(" http/"); // just in case! } if (requestType() == "CONNECT") { https = true; port = 443; if (!answer.startsWith("https://")) { answer = "https://" + answer; } } if (pport != NULL) { port = pport->after(" ").toInteger(); if (port == 0 || port > 65535) port = (https ? 443 : 80); } if (answer.length()) { if (answer[0] == '/') { // must be the latter above if (phost != NULL) { hostname = phost->after(" "); hostname.removeWhiteSpace(); if (hostname.contains(":")) { port = hostname.after(":").toInteger(); if (port == 0 || port > 65535) { port = (https ? 443 : 80); } hostname = hostname.before(":"); } while (hostname.endsWith(".")) hostname.chop(); if (withport && (port != (https ? 443 : 80))) hostname += ":" + String(port); hostname = "http://" + hostname; answer = hostname + answer; } // Squid doesn't like requests in this format. Work around the fact. header.front() = requestType() + " " + answer + " HTTP/" + header.front().after(" HTTP/"); } else { // must be in the form GET http://foo.bar:80/ HTML/1.0 if (!answer.after("://").contains("/")) { answer += "/"; // needed later on so correct host is extracted } String protocol(answer.before("://")); hostname = answer.after("://"); String url(hostname.after("/")); url.removeWhiteSpace(); // remove rubbish like ^M and blanks if (url.length() > 0) { url = "/" + url; } hostname = hostname.before("/"); // extra / was added 4 here if (hostname.contains("@")) { // Contains a username:password combo hostname = hostname.after("@"); } if (hostname.contains(":")) { port = hostname.after(":").toInteger(); if (port == 0 || port > 65535) { port = (https ? 443 : 80); } hostname = hostname.before(":"); // chop off the port bit } while (hostname.endsWith(".")) hostname.chop(); if (withport && (port != (https ? 443 : 80))) hostname += ":" + String(port); answer = protocol + "://" + hostname + url; } } if (answer.endsWith("//")) { answer.chop(); } #ifdef DGDEBUG std::cout << "from header url:" << answer << std::endl; #endif // Don't include port numbers in the URL in the cached version. // Most of the code only copes with URLs *without* port specifiers. if (!withport) cachedurl = answer.toCharArray(); return answer; }
// initialise the plugin - determine icap ip, port & url int icapinstance::init(void* args) { // always include these lists if (!readStandardLists()) { return DGCS_ERROR; } icapurl = cv["icapurl"]; // format: icap://icapserver:1344/avscan if (icapurl.length() < 3) { if (!is_daemonised) std::cerr << "Error reading icapurl option." << std::endl; syslog(LOG_ERR, "Error reading icapurl option."); return DGCS_ERROR; // it would be far better to do a test connection } icaphost = icapurl.after("//"); icapport = icaphost.after(":").before("/").toInteger(); if (icapport == 0) { icapport = 1344; } icaphost = icaphost.before("/"); if (icaphost.contains(":")) { icaphost = icaphost.before(":"); } struct hostent *host; if ((host = gethostbyname(icaphost.toCharArray())) == 0) { if (!is_daemonised) std::cerr << "Error resolving icap host address." << std::endl; syslog(LOG_ERR, "Error resolving icap host address."); return DGCS_ERROR; } icapip = inet_ntoa(*(struct in_addr *) host->h_addr_list[0]); #ifdef DGDEBUG std::cerr << "ICAP server address:" << icapip << std::endl; #endif // try to connect to the ICAP server and perform an OPTIONS request Socket icapsock; try { if (icapsock.connect(icapip.toCharArray(), icapport) < 0) { throw std::runtime_error("Could not connect to server"); } String line("OPTIONS " + icapurl + " ICAP/1.0\r\nHost: " + icaphost + "\r\n\r\n"); icapsock.writeString(line.toCharArray()); // parse the response char buff[8192]; // first line - look for 200 OK icapsock.getLine(buff, 8192, o.content_scanner_timeout); line = buff; #ifdef DGDEBUG std::cout << "ICAP/1.0 OPTIONS response:" << std::endl << line << std::endl; #endif if (line.after(" ").before(" ") != "200") { if (!is_daemonised) std::cerr << "ICAP response not 200 OK" << std::endl; syslog(LOG_ERR, "ICAP response not 200 OK"); return DGCS_WARNING; //throw std::runtime_error("Response not 200 OK"); } while (icapsock.getLine(buff, 8192, o.content_scanner_timeout) > 0) { line = buff; #ifdef DGDEBUG std::cout << line << std::endl; #endif if (line.startsWith("\r")) { break; } else if (line.startsWith("Preview:")) { usepreviews = true; previewsize = line.after(": ").toInteger(); } else if (line.startsWith("Server:")) { if (line.contains("AntiVir-WebGate")) { needsBody = true; } } else if (line.startsWith("X-Allow-Out:")) { if (line.contains("X-Infection-Found")) { supportsXIF = true; } } } icapsock.close(); } catch(std::exception& e) { if (!is_daemonised) std::cerr << "ICAP server did not respond to OPTIONS request: " << e.what() << std::endl; syslog(LOG_ERR, "ICAP server did not respond to OPTIONS request: %s", e.what()); return DGCS_ERROR; } #ifdef DGDEBUG if (usepreviews) std::cout << "Message previews enabled; size: " << previewsize << std::endl; else std::cout << "Message previews disabled" << std::endl; #endif return DGCS_OK; }
// read in a list linking IPs, subnets & IP ranges to filter groups // return 0 for success, -1 for failure, 1 for warning int ipinstance::readIPMelangeList(const char *filename) { // load in the list file std::ifstream input ( filename ); if (!input) { if (!is_daemonised) { std::cerr << "Error reading file (does it exist?): " << filename << std::endl; } syslog(LOG_ERR, "%s%s","Error reading file (does it exist?): ",filename); return -1; } // compile regexps for determining whether a list entry is an IP, a subnet (IP + mask), or a range RegExp matchIP, matchSubnet, matchRange; #ifdef HAVE_PCRE matchIP.comp("^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$"); matchSubnet.comp("^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}/\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$"); matchRange.comp("^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}-\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$"); #else matchIP.comp("^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$"); matchSubnet.comp("^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}/[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$"); matchRange.comp("^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}-[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$"); #endif // read in the file String line; String key, value; char buffer[ 2048 ]; bool warn = false; while (input) { if (!input.getline(buffer, sizeof( buffer ))) { break; } // ignore comments if (buffer[0] == '#') continue; // ignore blank lines if (strlen(buffer) < 10) continue; line = buffer; // split into key & value if (line.contains("=")) { key = line.before("="); key.removeWhiteSpace(); value = line.after("filter"); } else { if (!is_daemonised) std::cerr << "No filter group given; entry " << line << " in " << filename << std::endl; syslog(LOG_ERR, "No filter group given; entry %s in %s", line.toCharArray(), filename); warn = true; continue; } #ifdef DGDEBUG std::cout << "key: " << key << std::endl; std::cout << "value: " << value.toInteger() << std::endl; #endif if ((value.toInteger() < 1) || (value.toInteger() > o.filter_groups)) { if (!is_daemonised) std::cerr << "Filter group out of range; entry " << line << " in " << filename << std::endl; syslog(LOG_ERR, "Filter group out of range; entry %s in %s", line.toCharArray(), filename); warn = true; continue; } // store the IP address (numerically, not as a string) and filter group in either the IP list, subnet list or range list if (matchIP.match(key.toCharArray())) { struct in_addr address; if (inet_aton(key.toCharArray(), &address)) { iplist.push_back(ip(ntohl(address.s_addr),value.toInteger()-1)); } } else if (matchSubnet.match(key.toCharArray())) { struct in_addr address; struct in_addr addressmask; String subnet(key.before("/")); String mask(key.after("/")); if (inet_aton(subnet.toCharArray(), &address) && inet_aton(mask.toCharArray(), &addressmask)) { subnetstruct s; int addr = ntohl(address.s_addr); s.mask = ntohl(addressmask.s_addr); // pre-mask the address for quick comparison s.maskedaddr = addr & s.mask; s.group = value.toInteger()-1; ipsubnetlist.push_back(s); } } else if (matchRange.match(key.toCharArray())) { struct in_addr addressstart; struct in_addr addressend; String start(key.before("-")); String end(key.after("-")); if (inet_aton(start.toCharArray(), &addressstart) && inet_aton(end.toCharArray(), &addressend)) { rangestruct r; r.startaddr = ntohl(addressstart.s_addr); r.endaddr = ntohl(addressend.s_addr); r.group = value.toInteger()-1; iprangelist.push_back(r); } } // hmmm. the key didn't match any of our regular expressions. output message & return a warning value. else { if (!is_daemonised) std::cerr << "Entry " << line << " in " << filename << " was not recognised as an IP address, subnet or range" << std::endl; syslog(LOG_ERR, "Entry %s in %s was not recognised as an IP address, subnet or range", line.toCharArray(), filename); warn = true; } } input.close(); #ifdef DGDEBUG std::cout << "starting sort" << std::endl; #endif std::sort(iplist.begin(), iplist.end()); #ifdef DGDEBUG std::cout << "sort complete" << std::endl; std::cout << "ip list dump:" << std::endl; std::vector<ip>::const_iterator i = iplist.begin(); while (i != iplist.end()) { std::cout << "IP: " << i->addr << " Group: " << i->group << std::endl; ++i; } std::cout << "subnet list dump:" << std::endl; std::list<subnetstruct>::const_iterator j = ipsubnetlist.begin(); while (j != ipsubnetlist.end()) { std::cout << "Masked IP: " << j->maskedaddr << " Mask: " << j->mask << " Group: " << j->group << std::endl; ++j; } std::cout << "range list dump:" << std::endl; std::list<rangestruct>::const_iterator k = iprangelist.begin(); while (k != iprangelist.end()) { std::cout << "Start IP: " << k->startaddr << " End IP: " << k->endaddr << " Group: " << k->group << std::endl; ++k; } #endif // return either warning or success return warn ? 1 : 0; }
// default method for deciding whether we will handle a request bool DMPlugin::willHandle(HTTPHeader *requestheader, HTTPHeader *docheader) { // match user agent first (quick) if (!(alwaysmatchua || ua_match.match(requestheader->userAgent().toCharArray()))) return false; // then check standard lists (mimetypes & extensions) // mimetypes String mimetype(""); bool matchedmime = false; if (mimelistenabled) { mimetype = docheader->getContentType(); #ifdef DGDEBUG std::cout<<"mimetype: "<<mimetype<<std::endl; #endif if (mimetypelist.findInList(mimetype.toCharArray()) == NULL) { if (!extensionlistenabled) return false; } else matchedmime = true; } if (extensionlistenabled && !matchedmime) { // determine the extension String path(requestheader->decode(requestheader->url())); path.removeWhiteSpace(); path.toLower(); path.removePTP(); path = path.after("/"); path.hexDecode(); path.realPath(); String disposition(docheader->disposition()); String extension; if (disposition.length() > 2) { extension = disposition; while (extension.contains(".")) { extension = extension.after("."); } extension = "." + extension; } else { if (!path.contains("?")) { extension = path; } else { if (mimetype.length() == 0) mimetype = docheader->getContentType(); if (mimetype.contains("application/")) { extension = path; if (extension.contains("?")) { extension = extension.before("?"); } } } } #ifdef DGDEBUG std::cout<<"extension: "<<extension<<std::endl; #endif // check the extension list if (!extension.contains(".") || (extensionlist.findEndsWith(extension.toCharArray()) == NULL)) return matchedmime; } return true; }
void DockingAlgorithm::readOptionFile(String filename, Options& output_options, list<Constraint*>& output_constraints, const AtomContainer* ref_ligand) { INIFile ini(filename); ini.read(); Size num_sections = ini.getNumberOfSections(); for(Size i = 0; i < num_sections; i++) { String name = ini.getSection(i)->getName(); if (name.hasPrefix("ReferenceArea") || name.hasPrefix("PharmacophoreConstraint")) { continue; } Options* options_category = &output_options; if (name != "Docking-Settings") { options_category = output_options.createSubcategory(name); } Log.level(10)<<endl<<"--- Reading parameter-section '" << name << "' from file "<<"'"<<filename<<"' : -----"<<endl; INIFile::LineIterator it = ini.getSectionFirstLine(name); INIFile::LineIterator it_end = ini.getSectionLastLine(name).getSectionNextLine(); it.getSectionNextLine(); for (; it != it_end; it.getSectionNextLine()) { String line = *it; if (line == "") continue; String key = line.before("="); key.trim(); String value = line.after("="); value.trim(); if (key == "" || value == "") continue; options_category->set(key, value); if (name == ScoringFunction::SUBCATEGORY_NAME || name == "IMGDock") { Log.level(10)<<key<<" : "<<value<<endl; } } } for (Size i = 0; i < 100; i++) { string sec_name = "ReferenceArea"+String(i); if (!ini.hasSection(sec_name)) break; Log.level(10)<<endl<<"--- Reading "<<sec_name<<" from file "<<"'"<<filename<<"' : -----"<<endl; String name = ini.getValue(sec_name, "name"); bool is_fraction = ini.getValue(sec_name, "is_fraction").toBool(); double penalty = ini.getValue(sec_name, "penalty").toDouble(); double atoms = ini.getValue(sec_name, "atoms").toDouble(); vector<Vector3> v(4); Log.level(10)<<"name = "<<name<<endl; Log.level(10)<<"is_fraction = "<<is_fraction<<endl; Log.level(10)<<"atoms = "<<atoms<<endl; Log.level(10)<<"penalty = "<<penalty<<endl; ReferenceArea* rf; String use_ref = ini.getValue(sec_name, "use_ref_ligand"); if (use_ref != INIFile::UNDEFINED && use_ref.toBool()) { Log.level(10)<<"use_ref_ligand = true"<<endl; if (!ref_ligand) { throw BALL::Exception::GeneralException(__FILE__, __LINE__, "DockingAlgorithm::readOptionFile()", "Reference-ligand required but not specified!"); } rf = new ReferenceArea(ref_ligand, is_fraction, atoms, penalty); v = rf->input_points_; } else { for (Size i = 0; i <= 3; i++) { String pn = "p"+String(i); String s = ini.getValue(sec_name, pn); if (s == INIFile::UNDEFINED) { Log.error()<<"[Error:] 4 points must be defined for each ReferenceArea!"<<endl; return; } s.trim(); double d0 = s.getField(0, ", ").toDouble(); double d1 = s.getField(1, ", ").toDouble(); double d2 = s.getField(2, ", ").toDouble(); v[i] = Vector3(d0, d1, d2); } rf = new ReferenceArea(v[0], v[1], v[2], v[3], is_fraction, atoms, penalty); } // Increase size of box (e.g. bounding box around ref-ligand), if desired by the user. String inc = ini.getValue(sec_name, "box_size_increase"); if (inc != INIFile::UNDEFINED) { rf->enlarge(inc.toDouble()); } Log.level(10)<<"p0 = "<<v[0]<<endl; Log.level(10)<<"p1 = "<<v[1]<<endl; Log.level(10)<<"p2 = "<<v[2]<<endl; Log.level(10)<<"p3 = "<<v[3]<<endl; if (name != INIFile::UNDEFINED) rf->setName(name); output_constraints.push_back(rf); } for (Size i = 0; i < 100; i++) { string sec_name = "PharmacophoreConstraint"+String(i); if (!ini.hasSection(sec_name)) break; Log.level(10)<<endl<<"--- Reading "<<sec_name<<" from file "<<"'"<<filename<<"' : -----"<<endl; String name = ini.getValue(sec_name, "name"); double penalty = ini.getValue(sec_name, "penalty").toDouble(); double desired_energy = ini.getValue(sec_name, "desired interaction energy").toDouble(); String residues = ini.getValue(sec_name, "residue-IDs"); vector<String> residue_vector; residues.split(residue_vector, ", "); String types = ini.getValue(sec_name, "interaction types"); vector<String> types_vector; types.split(types_vector, ", "); list<String> types_list; for (Size i = 0; i < types_vector.size(); i++) { types_list.push_back(types_vector[i]); } Log.level(10)<<"name = "<<name<<endl; Log.level(10)<<"residue-IDs = "<<residues<<endl; Log.level(10)<<"interaction types = "<<types<<endl; Log.level(10)<<"desired interaction energy = "<<desired_energy<<endl; Log.level(10)<<"penalty = "<<penalty<<endl; PharmacophoreConstraint* phc = new PharmacophoreConstraint(residue_vector, types_list, desired_energy, penalty); if (name != INIFile::UNDEFINED) phc->setName(name); output_constraints.push_back(phc); } Log.level(10)<<endl<<"--- finished reading config-file."<<endl<<endl<<endl; }
// modifies the URL in all relevant header lines after a regexp search and replace // setURL Code originally from from Ton Gorter 2004 void HTTPHeader::setURL(String &url) { String hostname; bool https = (url.before("://") == "https"); int port = (https ? 443 : 80); if (!url.after("://").contains("/")) { url += "/"; } hostname = url.after("://").before("/"); if (hostname.contains("@")) { // Contains a username:password combo hostname = hostname.after("@"); } if (hostname.contains(":")) { port = hostname.after(":").toInteger(); if (port == 0 || port > 65535) { port = (https ? 443 : 80); } hostname = hostname.before(":"); // chop off the port bit } #ifdef DGDEBUG std::cout << "setURL: header.front() changed from: " << header.front() << std::endl; #endif if (!https) header.front() = header.front().before(" ") + " " + url + " " + header.front().after(" ").after(" "); else // Should take form of "CONNECT example.com:443 HTTP/1.0" for SSL header.front() = header.front().before(" ") + " " + hostname + ":" + String(port) + " " + header.front().after(" ").after(" "); #ifdef DGDEBUG std::cout << " to: " << header.front() << std::endl; #endif if (phost != NULL) { #ifdef DGDEBUG std::cout << "setURL: header[] line changed from: " << (*phost) << std::endl; #endif (*phost) = String("Host: ") + hostname; if (port != (https ? 443 : 80)) { (*phost) += ":"; (*phost) += String(port); } (*phost) += "\r"; #ifdef DGDEBUG std::cout << " to " << (*phost) << std::endl; #endif } if (pport != NULL) { #ifdef DGDEBUG std::cout << "setURL: header[] line changed from: " << (*pport) << std::endl; #endif (*pport) = String("Port: ") + String(port) + "\r"; #ifdef DGDEBUG std::cout << " to " << (*pport) << std::endl; #endif } // Don't just cache the URL we're sent - url() performs some other // processing, notably stripping the port part. Caching here will // bypass all that. //cachedurl = url.toCharArray(); }
// the meat of the process void NaughtyFilter::checkPICSrating(std::string label, unsigned int filtergroup) { (*o.fg[filtergroup]).pics2.match(label.c_str()); if (!(*o.fg[filtergroup]).pics2.matched()) { return; } // exit if not found String lab(label.c_str()); // convert to a String for easy manip String r; String service; for (int i = 0; i < (*o.fg[filtergroup]).pics2.numberOfMatches(); i++) { r = (*o.fg[filtergroup]).pics2.result(i).c_str(); // ditto r = r.after("("); r = r.before(")"); // remove the brackets // Only check the substring of lab that is between // the start of lab (or the end of the previous match) // and the start of this rating. // It is possible to have multiple ratings in one pics-label. // This is done on e.g. http://www.jesusfilm.org/ if (i == 0) { service = lab.subString(0, (*o.fg[filtergroup]).pics2.offset(i)); } else { service = lab.subString((*o.fg[filtergroup]).pics2.offset(i - 1) + (*o.fg[filtergroup]).pics2.length(i - 1), (*o.fg[filtergroup]).pics2.offset(i)); } if (service.contains("safesurf")) { checkPICSratingSafeSurf(r, filtergroup); if (isItNaughty) { return; } } if (service.contains("evaluweb")) { checkPICSratingevaluWEB(r, filtergroup); if (isItNaughty) { return; } } if (service.contains("microsys")) { checkPICSratingCyberNOT(r, filtergroup); if (isItNaughty) { return; } } if (service.contains("icra")) { checkPICSratingICRA(r, filtergroup); if (isItNaughty) { return; } } if (service.contains("rsac")) { checkPICSratingRSAC(r, filtergroup); if (isItNaughty) { return; } } if (service.contains("weburbia")) { checkPICSratingWeburbia(r, filtergroup); if (isItNaughty) { return; } } if (service.contains("vancouver")) { checkPICSratingVancouver(r, filtergroup); if (isItNaughty) { return; } } if (service.contains("icec")) { checkPICSratingICEC(r, filtergroup); if (isItNaughty) { return; } } if (service.contains("safenet")) { checkPICSratingSafeNet(r, filtergroup); if (isItNaughty) { return; } } // check label for word denoting rating system then pass on to the // appropriate function the rating String. } }
bool Potential1210::extractSection (ForceFieldParameters& parameters, const String& section_name) { // clear the fields first clear(); // check whether the parameters are valid if (!parameters.isValid()) { return false; } // extract the basis information ParameterSection::extractSection(parameters, section_name); // check whether all variables we need are defined, terminate otherwise if (!hasVariable("A") || !hasVariable("B")) { return false; } // build a two dimensional array of the atom types // loop variable Size i; AtomTypes& atom_types = parameters.getAtomTypes(); number_of_atom_types_ = atom_types.getNumberOfTypes(); // allocate two onedimensional fields for the two parameters A_.resize(number_of_atom_types_ * number_of_atom_types_); B_.resize(number_of_atom_types_ * number_of_atom_types_); is_defined_.resize(number_of_atom_types_ * number_of_atom_types_); for (i = 0; i < number_of_atom_types_ * number_of_atom_types_; i++) { is_defined_[i] = false; } StringHashMap<Index>::Iterator it; // determine the factor to convert the parameters to the standard units used // as a default, energies are assumend to be in kJ/mol and distances in Angstrom double factor_A = 1.0; double factor_B = 1.0; if (options.has("unit_A")) { if (options["unit_A"] == "kcal/mol*A^12") { factor_A = Constants::JOULE_PER_CAL; } else { Log.warn() << "unknown unit for parameter A: " << options["unit_A"] << endl; } } if (options.has("unit_B")) { if (options["unit_B"] == "kcal/mol*A^10") { factor_B = Constants::JOULE_PER_CAL; } else { Log.warn() << "unknown unit for parameter B: " << options["unit_B"] << endl; } } Atom::Type type_I; Atom::Type type_J; String type_name_I; String type_name_J; String key; Index index = 0; for (it = section_entries_.begin(); !(it == section_entries_.end()); ++it) { key = (*it).first; if ((key.size() > 0) && (key.find_first_of(" ", 0) > 0)) { type_name_I = key.before(" ", 0); type_name_J = key.after(" ", 0); if ((atom_types.hasType(type_name_I)) && (atom_types.hasType(type_name_J))) { type_I = atom_types.getType(type_name_I); type_J = atom_types.getType(type_name_J); index = (Index)(type_I * number_of_atom_types_ + type_J); is_defined_[index] = true; A_ [index] = getValue(key, "A").toFloat() * factor_A; B_ [index] = getValue(key, "B").toFloat() * factor_B; index = (Index)(type_I + number_of_atom_types_ * type_J); is_defined_[index] = true; A_ [index] = getValue(key, "A").toFloat() * factor_A; B_ [index] = getValue(key, "B").toFloat() * factor_B; } } } return true; }
// read in a list linking IPs, subnets & IP ranges to filter groups bool IPList::readIPMelangeList(const char *filename) { // load in the list file std::ifstream input ( filename ); if (!input) { if (!is_daemonised) { std::cerr << "Error reading file (does it exist?): " << filename << std::endl; } syslog(LOG_ERR, "%s%s","Error reading file (does it exist?): ",filename); return false; } // compile regexps for determining whether a list entry is an IP, a subnet (IP + mask), or a range RegExp matchIP, matchSubnet, matchRange; #ifdef HAVE_PCRE matchIP.comp("^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$"); matchSubnet.comp("^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}/\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$"); matchRange.comp("^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}-\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$"); #else matchIP.comp("^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$"); matchSubnet.comp("^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}/[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$"); matchRange.comp("^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}-[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$"); #endif // read in the file String line; char buffer[ 2048 ]; while (input) { if (!input.getline(buffer, sizeof( buffer ))) { break; } // ignore comments if (buffer[0] == '#') continue; // ignore blank lines if (strlen(buffer) < 7) continue; line = buffer; #ifdef DGDEBUG std::cout << "line: " << line << std::endl; #endif // store the IP address (numerically, not as a string) and filter group in either the IP list, subnet list or range list if (matchIP.match(line.toCharArray())) { struct in_addr address; if (inet_aton(line.toCharArray(), &address)) { uint32_t addr = ntohl(address.s_addr); iplist.push_back(addr); } } else if (matchSubnet.match(line.toCharArray())) { struct in_addr address; struct in_addr addressmask; String subnet(line.before("/")); String mask(line.after("/")); if (inet_aton(subnet.toCharArray(), &address) && inet_aton(mask.toCharArray(), &addressmask)) { ipl_subnetstruct s; uint32_t addr = ntohl(address.s_addr); s.mask = ntohl(addressmask.s_addr); // pre-mask the address for quick comparison s.maskedaddr = addr & s.mask; ipsubnetlist.push_back(s); } } else if (matchRange.match(line.toCharArray())) { struct in_addr addressstart; struct in_addr addressend; String start(line.before("-")); String end(line.after("-")); if (inet_aton(start.toCharArray(), &addressstart) && inet_aton(end.toCharArray(), &addressend)) { ipl_rangestruct r; r.startaddr = ntohl(addressstart.s_addr); r.endaddr = ntohl(addressend.s_addr); iprangelist.push_back(r); } } // hmmm. the line didn't match any of our regular expressions. // assume it's a hostname. else { line.toLower(); hostlist.push_back(line); } } input.close(); #ifdef DGDEBUG std::cout << "starting sort" << std::endl; #endif std::sort(iplist.begin(), iplist.end()); std::sort(hostlist.begin(), hostlist.end()); #ifdef DGDEBUG std::cout << "sort complete" << std::endl; std::cout << "ip list dump:" << std::endl; std::vector<uint32_t>::iterator i = iplist.begin(); while (i != iplist.end()) { std::cout << "IP: " << *i << std::endl; ++i; } std::cout << "subnet list dump:" << std::endl; std::list<ipl_subnetstruct>::iterator j = ipsubnetlist.begin(); while (j != ipsubnetlist.end()) { std::cout << "Masked IP: " << j->maskedaddr << " Mask: " << j->mask << std::endl; ++j; } std::cout << "range list dump:" << std::endl; std::list<ipl_rangestruct>::iterator k = iprangelist.begin(); while (k != iprangelist.end()) { std::cout << "Start IP: " << k->startaddr << " End IP: " << k->endaddr << std::endl; ++k; } std::cout << "host list dump:" << std::endl; std::vector<String>::iterator l = hostlist.begin(); while (l != hostlist.end()) { std::cout << "Hostname: " << *l << std::endl; ++l; } #endif return true; }