ModResult HandleRequest(HTTPRequest* http) { std::stringstream data(""); { ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Handling httpd event"); if ((http->GetURI() == "/config") || (http->GetURI() == "/config/")) { data << "<html><head><title>InspIRCd Configuration</title></head><body>"; data << "<h1>InspIRCd Configuration</h1><p>"; for (ConfigDataHash::iterator x = ServerInstance->Config->config_data.begin(); x != ServerInstance->Config->config_data.end(); ++x) { data << "<" << x->first << " "; ConfigTag* tag = x->second; for (std::vector<KeyVal>::const_iterator j = tag->getItems().begin(); j != tag->getItems().end(); j++) { data << Sanitize(j->first) << "="" << Sanitize(j->second) << "" "; } data << "><br>"; } data << "</body></html>"; /* Send the document back to m_httpd */ HTTPDocumentResponse response(this, *http, &data, 200); response.headers.SetHeader("X-Powered-By", MODNAME); response.headers.SetHeader("Content-Type", "text/html"); API->SendResponse(response); return MOD_RES_DENY; // Handled } } return MOD_RES_PASSTHRU; }
void OnEvent(Event& event) { std::stringstream data(""); if (event.id == "httpd_url") { ServerInstance->Logs->Log("m_http_stats", LOG_DEBUG,"Handling httpd event"); HTTPRequest* http = (HTTPRequest*)&event; if ((http->GetURI() == "/config") || (http->GetURI() == "/config/")) { data << "<html><head><title>InspIRCd Configuration</title></head><body>"; data << "<h1>InspIRCd Configuration</h1><p>"; for (ConfigDataHash::iterator x = ServerInstance->Config->config_data.begin(); x != ServerInstance->Config->config_data.end(); ++x) { data << "<" << x->first << " "; ConfigTag* tag = x->second; for (std::vector<KeyVal>::const_iterator j = tag->getItems().begin(); j != tag->getItems().end(); j++) { data << Sanitize(j->first) << "="" << Sanitize(j->second) << "" "; } data << "><br>"; } data << "</body></html>"; /* Send the document back to m_httpd */ HTTPDocumentResponse response(this, *http, &data, 200); response.headers.SetHeader("X-Powered-By", "m_httpd_config.so"); response.headers.SetHeader("Content-Type", "text/html"); response.Send(); } } }
void HTMLWriter::WriteMeta(const std::string& name, const std::string& content) { try { file << "<meta name=\"" << Sanitize(name) << "\" content=\"" << Sanitize(content) << "\"/>" << std::endl; } catch (std::ifstream::failure& e) { throw IOException(filename,"Cannot write meta",e); } catch (std::exception& e) { throw IOException(filename,"Cannot write meta",e); } }
void HTMLWriter::WriteHeaderStart(const std::string& title, const std::string& description, const std::string& keywords, const std::string& stylesheetLocation) { try { file << "<head>" << std::endl; if (!title.empty()) { file << "<title>" << Sanitize(title) << "</title>" << std::endl; } if (!stylesheetLocation.empty()) { file << "<link rel=\"stylesheet\" type=\"text/css\" href=\"" << stylesheetLocation << "\">" << std::endl; } file << "<meta charset=\"utf-8\">" << std::endl; if (!description.empty()) { WriteMeta("description",description); } if (!keywords.empty()) { WriteMeta("keywords",description); } WriteMeta("generator","libosmscout import"); } catch (std::ifstream::failure& e) { throw IOException(filename,"Cannot write header start",e); } catch (std::exception& e) { throw IOException(filename,"Cannot write header start",e); } }
int32_t MemoryAllocator::Delete (void *P) { if (P == (MemoryChunk *)0) { this->Errors++; return errno = EINVAL; } else {} if (this->Test()) { this->Errors++; return 0; } else {} this->Lock(); errno = 0; MemoryChunk *chunk = (MemoryChunk *)(P) - 1; /* if (!(chunk->llink) && !(chunk->llink)) errno = EINVAL; else if (!(chunk->llink)) { if (chunk->rlink->llink != chunk) errno = EINVAL; } else if (!(chunk->rlink)){ if (chunk->llink->rlink != chunk) errno = EINVAL; } else { if (chunk->llink->rlink != chunk->rlink->llink) errno = EINVAL; } */ if (errno == EINVAL) { this->Unlock(); return errno; } else {} this->PoolInUse - chunk; this->PoolFree + chunk; Sanitize(this->PoolFree); this->Unlock(); return errno; }
int Client::Unsubscribe(std::string wiki) { if (wiki == "all") { if (!this->SubscribedAny) return ENOTEXIST; this->SubscribedAny = false; return 0; } wiki = Sanitize(wiki); if (wiki.length() == 0) return EINVALID; pthread_mutex_lock(&this->subscriptions_lock); std::vector<std::string>::iterator position = std::find(this->Subscriptions.begin(), this->Subscriptions.end(), wiki); if (position == this->Subscriptions.end()) { pthread_mutex_unlock(&this->subscriptions_lock); return ENOTEXIST; } this->Subscriptions.erase(position); pthread_mutex_unlock(&this->subscriptions_lock); return 0; }
void HTMLWriter::WriteOSMObjectLink(const ObjectOSMRef& object, const std::string& name) { try { // TODO: Call WriteLink file << "<a href=\"https://www.openstreetmap.org/"; switch (object.GetType()) { case osmRefNone: assert(false); case osmRefNode: file << "node"; break; case osmRefWay: file << "way"; break; case osmRefRelation: file << "relation"; break; } file << "/" << object.GetId() << "\">" << Sanitize(name) << "</a>"; } catch (std::ifstream::failure& e) { throw IOException(filename,"Cannot write object link",e); } catch (std::exception& e) { throw IOException(filename,"Cannot write object link",e); } }
bool CKeyBindings::Load(const string& filename) { // inComment = false; CFileHandler ifs(filename); CSimpleParser parser(ifs); userCommand = false; // temporarily disable Sanitize() calls LoadDefaults(); while (true) { const string line = parser.GetCleanLine(); if (line.empty()) { break; } if (!ExecuteCommand(line)) { ParseTypeBind(parser, line); } } Sanitize(); userCommand = true; // re-enable Sanitize() calls return true; }
/* CPrinterNameSegment */ LPCWSTR CPrinterNameSegment::Value() { WCHAR szTemp[MAXBUF]; _ASSERTE(m_pPort != NULL); //copy printer name because we must sanitize string wcscpy_s(szTemp, LENGTHOF(szTemp), m_pPort->PrinterName()); swprintf_s(m_szBuffer, LENGTHOF(m_szBuffer), L"%*s", m_nWidth, Sanitize(szTemp)); return m_szBuffer; }
void Logger::Log( Severity severity, const char* message, const char * logFile, long logLine) { std::stringstream ss; ss << logFile << "(" << logLine << ") - " << Sanitize(message); std::string logEntry; logEntry = ss.str(); logList.push_back(logEntry); severityList.push_back(severity); }
bool CKeyBindings::Command(const string& line) { const vector<string> words = SimpleParser::Tokenize(line, 2); if (words.size() <= 0) { return false; } const string command = StringToLower(words[0]); if (command == "keydebug") { if (words.size() == 1) { debug = (debug <= 0) ? 1 : 0; } else if (words.size() >= 2) { debug = atoi(words[1].c_str()); } } else if ((command == "fakemeta") && (words.size() > 1)) { if (!SetFakeMetaKey(words[1])) { return false; } } else if ((command == "keyset") && (words.size() > 2)) { if (!AddNamedKeySet(words[1], words[2])) { return false; } } else if ((command == "keysym") && (words.size() > 2)) { if (!AddKeySymbol(words[1], words[2])) { return false; } } else if ((command == "bind") && (words.size() > 2)) { if (!Bind(words[1], words[2])) { return false; } } else if ((command == "unbind") && (words.size() > 2)) { if (!UnBind(words[1], words[2])) { return false; } } else if ((command == "unbindaction") && (words.size() > 1)) { if (!UnBindAction(words[1])) { return false; } } else if ((command == "unbindkeyset") && (words.size() > 1)) { if (!UnBindKeyset(words[1])) { return false; } } else if (command == "unbindall") { bindings.clear(); keyCodes->Reset(); namedKeySets.clear(); typeBindings.clear(); Bind("enter", "chat"); // bare minimum } else { return false; } if (userCommand) { Sanitize(); } return false; }
void HTMLWriter::WriteText(const std::string& text) { try { file << Sanitize(text) << std::endl; } catch (std::ifstream::failure& e) { throw IOException(filename,"Cannot write text",e); } catch (std::exception& e) { throw IOException(filename,"Cannot write text",e); } }
void HTMLWriter::WriteLink(const std::string& url, const std::string& title) { try { file << "<a href=\"" << url << "\">" << Sanitize(title) << "</a>"; } catch (std::ifstream::failure& e) { throw IOException(filename,"Cannot write link",e); } catch (std::exception& e) { throw IOException(filename,"Cannot write link",e); } }
void LogManager::WriteFile() { std::ofstream myFile; myFile.open("../LogOutput.html"); myFile << "<!DOCTYPE html>" << std::endl << "<html>" << std::endl << "<head>" << std::endl << "<title>Log File</title>" << std::endl << "</head>" << std::endl << "<body bgcolor = '#FFFFFF' >" << std::endl << "<h2>Log File</h2>"; myFile << "<table>\n<tr>\n" << "<td><b>Log ID </b></td>\n" << "<td><b>Severity </b></td>\n" << "<td><b>Location </b></td>\n" << "<td><b>Message </b></td>\n" << "<td><b>TimeStamp </b></td>\n" << "<td><b>Vebosity </b></td>\n"; for(unsigned int i = 0; i < logList.size(); i ++) { //copying mem so it can be parsed for HTML LogData toPrint = logList[i]; Sanitize(&toPrint);//clean for HTML myFile << "<tr style=\" color : "; switch (toPrint.severity) { case Info: myFile << "#0099FF"; break; case Warning: myFile << "#FFCC00"; break; case Error: myFile << "#FF0000"; break; case Severe: myFile << "#CC0000"; break; default: myFile << "#000000"; break; } myFile << ";\" >";//end <tr color = "??????"> myFile << "<td>" << i << "</td>\n" << "<td>" << toPrint.severity << "</td>\n" << "<td>" << toPrint.location.c_str() << "(" << toPrint.lineNumber << ")" "</td>\n" << "<td>" << toPrint.message.c_str() << "</td>\n" << "<td>" << toPrint.timestamp << "</td>\n" << "<td>" << toPrint.verbosity << "</td>\n"; myFile << "</tr>\n"; } myFile << "</table>\n"; myFile << "<center>" << FOOTER << "</center>"; myFile << "</body>" << std::endl << "</html>"; myFile.close(); }
void DumpMeta(std::stringstream& data, Extensible* ext) { data << "<metadata>"; for(Extensible::ExtensibleStore::const_iterator i = ext->GetExtList().begin(); i != ext->GetExtList().end(); i++) { ExtensionItem* item = i->first; std::string value = item->serialize(FORMAT_USER, ext, i->second); if (!value.empty()) data << "<meta name=\"" << item->name << "\">" << Sanitize(value) << "</meta>"; else if (!item->name.empty()) data << "<meta name=\"" << item->name << "\"/>"; } data << "</metadata>"; }
void FriendlyNameMapper::SaveName(uint32_t id, const std::string& suggested_name) { if (name_for_id_.find(id) != name_for_id_.end()) return; const std::string sanitized_suggested_name = Sanitize(suggested_name); std::string name = sanitized_suggested_name; auto inserted = used_names_.insert(name); if (!inserted.second) { const std::string base_name = sanitized_suggested_name + "_"; for (uint32_t index = 0; !inserted.second; ++index) { name = base_name + to_string(index); inserted = used_names_.insert(name); } } name_for_id_[id] = name; }
void Brain(User *u, Flux::string q) { if(!(cdt.requested >= 30)) { cdt.requested++; Log(LOG_TERMINAL) << "Requests: " << cdt.requested; Sanitize(q); Flux::string str = "python brain.py "+q; Flux::string information = execute(str.c_str()); information.trim(); if (information.search_ci("For search options, see Help:Searching")) u->SendMessage(RandomOops()); else if (information.search_ci("may refer to:") || information.search_ci("reasons this message may be displayed:") ) u->SendMessage(RandomAmb()); else u->SendMessage(information.strip()); }else u->SendMessage(TooManyRequests()); }
int Client::Subscribe(std::string wiki) { if (wiki == "all") { if (this->SubscribedAny) return EALREADYEXIST; this->SubscribedAny = true; return 0; } wiki = Sanitize(wiki); if (this->Subscriptions.size() > MAX_SUBSCRIPTIONS) return ETOOMANYSUBS; if (wiki.length() == 0 || wiki.length() > MAX_SUBSCR_SIZE) return EINVALID; if (this->IsSubscribed(wiki)) return EALREADYEXIST; pthread_mutex_lock(&this->subscriptions_lock); this->Subscriptions.push_back(wiki); pthread_mutex_unlock(&this->subscriptions_lock); return 0; }
bool CKeyBindings::Load(const string& filename) { inComment = false; lineNumber = 0; CFileHandler ifs(filename); userCommand = false; // temporarily disable Sanitize() calls LoadDefaults(); while (true) { const string line = GetCleanLine(ifs); if (line.empty()) { break; } Command(line); } Sanitize(); userCommand = true; // re-enable Sanitize() calls return true; }
void IMG(const wxString& src) { gCurrentString += _T("<img src='") + Sanitize(src) + _T("'/>\n"); }
bool CKeyBindings::ExecuteCommand(const string& line) { const vector<string> words = CSimpleParser::Tokenize(line, 2); if (words.empty()) { return false; } const string command = StringToLower(words[0]); if (command == "keydebug") { const int curLogLevel = log_filter_section_getMinLevel(LOG_SECTION_KEY_BINDINGS); bool debug = (curLogLevel == LOG_LEVEL_DEBUG); if (words.size() == 1) { // toggle debug = !debug; } else if (words.size() >= 2) { // set debug = atoi(words[1].c_str()); } if (debug && !LOG_IS_ENABLED_STATIC(L_DEBUG)) { LOG_L(L_WARNING, "You have to run a DEBUG build to be able to log L_DEBUG messages"); } log_filter_section_setMinLevel(LOG_SECTION_KEY_BINDINGS, (debug ? LOG_LEVEL_DEBUG : LOG_LEVEL_INFO)); } else if ((command == "fakemeta") && (words.size() > 1)) { if (!SetFakeMetaKey(words[1])) { return false; } } else if ((command == "keyset") && (words.size() > 2)) { if (!AddNamedKeySet(words[1], words[2])) { return false; } } else if ((command == "keysym") && (words.size() > 2)) { if (!AddKeySymbol(words[1], words[2])) { return false; } } else if ((command == "bind") && (words.size() > 2)) { if (!Bind(words[1], words[2])) { return false; } } else if ((command == "unbind") && (words.size() > 2)) { if (!UnBind(words[1], words[2])) { return false; } } else if ((command == "unbindaction") && (words.size() > 1)) { if (!UnBindAction(words[1])) { return false; } } else if ((command == "unbindkeyset") && (words.size() > 1)) { if (!UnBindKeyset(words[1])) { return false; } } else if (command == "unbindall") { bindings.clear(); keyCodes->Reset(); namedKeySets.clear(); typeBindings.clear(); Bind("enter", "chat"); // bare minimum } else { return false; } if (userCommand) { Sanitize(); } return false; }
spv_result_t FriendlyNameMapper::ParseInstruction( const spv_parsed_instruction_t& inst) { const auto result_id = inst.result_id; switch (inst.opcode) { case SpvOpName: SaveName(inst.words[1], reinterpret_cast<const char*>(inst.words + 2)); break; case SpvOpTypeVoid: SaveName(result_id, "void"); break; case SpvOpTypeBool: SaveName(result_id, "bool"); break; case SpvOpTypeInt: { std::string signedness; std::string root; const auto bit_width = inst.words[2]; switch (bit_width) { case 8: root = "char"; break; case 16: root = "short"; break; case 32: root = "int"; break; case 64: root = "long"; break; default: root = to_string(bit_width); signedness = "i"; break; } if (0 == inst.words[3]) signedness = "u"; SaveName(result_id, signedness + root); } break; case SpvOpTypeFloat: { const auto bit_width = inst.words[2]; switch (bit_width) { case 16: SaveName(result_id, "half"); break; case 32: SaveName(result_id, "float"); break; case 64: SaveName(result_id, "double"); break; default: SaveName(result_id, std::string("fp") + to_string(bit_width)); break; } } break; case SpvOpTypeVector: SaveName(result_id, std::string("v") + to_string(inst.words[3]) + NameForId(inst.words[2])); break; case SpvOpTypeMatrix: SaveName(result_id, std::string("mat") + to_string(inst.words[3]) + NameForId(inst.words[2])); break; case SpvOpTypeArray: SaveName(result_id, std::string("_arr_") + NameForId(inst.words[2]) + "_" + NameForId(inst.words[3])); break; case SpvOpTypeRuntimeArray: SaveName(result_id, std::string("_runtimearr_") + NameForId(inst.words[2])); break; case SpvOpTypePointer: SaveName(result_id, std::string("_ptr_") + NameForEnumOperand(SPV_OPERAND_TYPE_STORAGE_CLASS, inst.words[2]) + "_" + NameForId(inst.words[3])); break; case SpvOpTypePipe: SaveName(result_id, std::string("Pipe") + NameForEnumOperand(SPV_OPERAND_TYPE_ACCESS_QUALIFIER, inst.words[2])); break; case SpvOpTypeEvent: SaveName(result_id, "Event"); break; case SpvOpTypeDeviceEvent: SaveName(result_id, "DeviceEvent"); break; case SpvOpTypeReserveId: SaveName(result_id, "ReserveId"); break; case SpvOpTypeQueue: SaveName(result_id, "Queue"); break; case SpvOpTypeOpaque: SaveName(result_id, std::string("Opaque_") + Sanitize(reinterpret_cast<const char*>(inst.words + 2))); break; case SpvOpTypePipeStorage: SaveName(result_id, "PipeStorage"); break; case SpvOpTypeNamedBarrier: SaveName(result_id, "NamedBarrier"); break; case SpvOpTypeStruct: // Structs are mapped rather simplisitically. Just indicate that they // are a struct and then give the raw Id number. SaveName(result_id, std::string("_struct_") + to_string(result_id)); break; default: // If this instruction otherwise defines an Id, then save a mapping for // it. This is needed to ensure uniqueness in there is an OpName with // string something like "1" that might collide with this result_id. // We should only do this if a name hasn't already been registered by some // previous forward reference. if (result_id && name_for_id_.find(result_id) == name_for_id_.end()) SaveName(result_id, to_string(result_id)); break; } return SPV_SUCCESS; }
bool fio::FileINI::Load(std::string sFile) { //clear all data m_veHeaders.clear(); //even when the function fails, the default non-named header will //be there m_veHeaders.push_back(FileINIHeader()); std::vector<FileINIHeader>::iterator itHeader = m_veHeaders.begin(); //open a file to read data from std::ifstream iFile(sFile.c_str(), std::ios::in); if (!iFile.is_open()) { //could not open file return false; } std::string sLine; std::getline(iFile, sLine); while (!iFile.eof()) { //have not yet reached the end of the file, remove anything //that resembles a comment from the string const size_t nComment = sLine.find('#'); if (nComment != sLine.npos) { //remove the comment from the line sLine.substr(0, nComment); } Sanitize(sLine); if (sLine.length() != 0) { //line still contains information if (sLine[0] == '[') { //dealing with a header, create a new header FileINIHeader newHeader; const size_t nHeaderEnd = sLine.find(']'); if (nHeaderEnd == sLine.npos) { //expected to find a closing bracket as well iFile.close(); return false; } newHeader.sHeader = sLine.substr(1, nHeaderEnd - 1); //sanitize header name newHeader.sHeader = fio::RemoveLeadingWhitespace(newHeader.sHeader); newHeader.sHeader = fio::RemoveTrailingWhitespace(newHeader.sHeader); //add the the vector and update the iterator m_veHeaders.push_back(newHeader); itHeader = m_veHeaders.end() - 1; } else { //line contains data and is not a header, then it must contain //a variable and its associated value const size_t nEqual = sLine.find('='); if (nEqual == sLine.npos) { //expected to find an equal sign iFile.close(); return false; } FileINIEntry newEntry; newEntry.sName = fio::RemoveTrailingWhitespace(sLine.substr(0, nEqual)); newEntry.sValue = fio::RemoveLeadingWhitespace(sLine.substr(nEqual + 1)); //add entry to the current header itHeader->veEntries.push_back(newEntry); } } //retrieve a new line std::getline(iFile, sLine); } //if this code is reached, the file is completely loaded iFile.close(); return true; }
void LogManager::Sanitize(LogData * toClean) { toClean->message = Sanitize(toClean->message); toClean->location = Sanitize(toClean->location); }
void A(const wxString& text, const wxString& href, const wxString& name = wxEmptyString) { gCurrentString += _T("<a href='") + Sanitize(href) + _T("'") + _T(" name='") + name + _T("'>") + Sanitize(text) + _T("</a>"); }
void LI(const wxString& text) { gCurrentString += _T("<li>") + Sanitize(text) + _T("</li>\n"); }
void P(const wxString& text) { gCurrentString += _T("<p>") + Sanitize(text) + _T("</p>\n"); }
void H4(const wxString& text) { gCurrentString += _T("\n<h4>") + Sanitize(text) + _T("</h4>\n"); }