Loading plugins/staticpage/static.cpp +29 −36 Changes for plugins/staticpage/static.cpp: 29 added lines, 36 removed lines. Original line number Diff line number Diff line Loading @@ -229,7 +229,6 @@ void blogi::StaticPage::delPage(const int tid,libhttppp::HttpRequest& req, libht } void blogi::StaticPage::editPage(const int tid,libhttppp::HttpRequest& req, libhtmlpp::HtmlString& setdiv){ char url[512]; uuid::uuid id; dbpp::SQL sql; dbpp::DBResult res; Loading @@ -243,15 +242,7 @@ void blogi::StaticPage::editPage(const int tid,libhttppp::HttpRequest& req, libh for (libhttppp::HttpForm::MultipartForm::Data* curformdat = form.MultipartFormData.getFormData(); curformdat; curformdat = curformdat->nextData()) { libhttppp::HttpForm::MultipartForm::Data::ContentDisposition* curctdisp = curformdat->getDisposition();{ if(std::equal(curctdisp->getValue().begin(),curctdisp->getValue().end(),"pageid")==0){ for(size_t i =0; i<curformdat->Value.size(); ++i){ if(!isdigit(curformdat->Value[i])){ libhttppp::HTTPException excep; excep[libhttppp::HTTPException::Error] << "Wrong formted Pageid!"; std::cout.write(curformdat->Value.data(),curformdat->Value.size())<<std::endl; throw excep; } } if(curctdisp->getValue().size() == 6 && std::equal(curctdisp->getValue().begin(),curctdisp->getValue().end(),"pageid")){ std::vector<char> buf; std::copy(curformdat->Value.begin(),curformdat->Value.end(), std::inserter<std::vector<char>>(buf,buf.begin())); Loading @@ -263,47 +254,49 @@ void blogi::StaticPage::editPage(const int tid,libhttppp::HttpRequest& req, libh if (!id.empty()) { for (libhttppp::HttpForm::MultipartForm::Data* curformdat = form.MultipartFormData.getFormData(); curformdat; curformdat = curformdat->nextData()) { for(libhttppp::HttpForm::MultipartForm::Data::ContentDisposition* curctdisp = curformdat->getDisposition(); curctdisp; curctdisp=curctdisp->nextContentDisposition()){ for (auto* curformdat = form.MultipartFormData.getFormData(); curformdat; curformdat = curformdat->nextData()) { for (auto* curctdisp = curformdat->getDisposition(); curctdisp; curctdisp = curctdisp->nextContentDisposition()) { std::vector<char> data; libhtmlpp::HtmlString result; const std::string key(curctdisp->getValue().begin(), curctdisp->getValue().end()); std::copy(curformdat->Value.begin(),curformdat->Value.end(), std::inserter<std::vector<char>>(data,data.begin())); const std::string val(curformdat->Value.begin(), curformdat->Value.end()); data.push_back('\0'); std::string esc; if(std::equal(curctdisp->getValue().begin(),curctdisp->getValue().end(),"url")==0){ libhtmlpp::HtmlEncode(data.data(),&result); sql<< "update static_content set url='" << result.c_str() << "' where id='" << id.c_str() <<"'; "; }else if(std::equal(curctdisp->getValue().begin(),curctdisp->getValue().end(),"meta")==0){ libhtmlpp::HtmlEncode(data.data(),&result); sql<< "update static_content set meta='" << result.c_str() << "' where id='" << id.c_str() <<"'; "; }else if(std::equal(curctdisp->getValue().begin(),curctdisp->getValue().end(),"text")==0){ sql<< "update static_content set text='"<< sql.escaped(sbuf,data.data()) << "' where id='" << id.c_str() <<"'; "; if (key == "url") { esc = sql.escaped(sbuf, val.c_str()); sql << "UPDATE static_content SET url='" << esc.c_str() << "' WHERE id='" << id.c_str() << "'; "; } else if (key == "meta") { esc = sql.escaped(sbuf, val.c_str()); sql << "UPDATE static_content SET meta='" << esc.c_str() << "' WHERE id='" << id.c_str() << "'; "; } else if (key == "text") { libhtmlpp::HtmlString html; libhtmlpp::HtmlEncode(val.c_str(), &html); esc = sql.escaped(sbuf, html.c_str()); sql << "UPDATE static_content SET text='" << esc.c_str() << "' WHERE id='" << id.c_str() << "'; "; } } } if (!sql.empty()) { Args->database[tid]->exec(sql, res); sql.clear(); } } else { for(libhttppp::HttpForm::UrlcodedForm::Data *cdat=form.UrlFormData.getFormData(); cdat; cdat=cdat->nextData()){ for (auto* cdat = form.UrlFormData.getFormData(); cdat; cdat = cdat->nextData()) { if (cdat->getKey() == "pageid") { size_t pgidlen=cdat->getValue().length(); for(size_t i =0; i<pgidlen; ++i){ if(!isdigit(cdat->getValue()[i])){ libhttppp::HTTPException excep; excep[libhttppp::HTTPException::Error] << "Wrong formted Pageid!"; throw excep; } } id.parse(cdat->getValue()); } } if (id.empty()) { libhttppp::HTTPException excep; excep[libhttppp::HTTPException::Error] << "Staticpage with this id not found!"; Loading @@ -312,7 +305,7 @@ void blogi::StaticPage::editPage(const int tid,libhttppp::HttpRequest& req, libh } }catch(...){}; sql << "select id,url,meta,text from static_content where id='"; sql << id.c_str() << "' LIMIT 1"; sql << "select id,url,meta,text from static_content where id='" << id.c_str() << "' LIMIT 1"; if(Args->database[tid]->exec(sql,res)<1){ return; Loading Loading
plugins/staticpage/static.cpp +29 −36 Changes for plugins/staticpage/static.cpp: 29 added lines, 36 removed lines. Original line number Diff line number Diff line Loading @@ -229,7 +229,6 @@ void blogi::StaticPage::delPage(const int tid,libhttppp::HttpRequest& req, libht } void blogi::StaticPage::editPage(const int tid,libhttppp::HttpRequest& req, libhtmlpp::HtmlString& setdiv){ char url[512]; uuid::uuid id; dbpp::SQL sql; dbpp::DBResult res; Loading @@ -243,15 +242,7 @@ void blogi::StaticPage::editPage(const int tid,libhttppp::HttpRequest& req, libh for (libhttppp::HttpForm::MultipartForm::Data* curformdat = form.MultipartFormData.getFormData(); curformdat; curformdat = curformdat->nextData()) { libhttppp::HttpForm::MultipartForm::Data::ContentDisposition* curctdisp = curformdat->getDisposition();{ if(std::equal(curctdisp->getValue().begin(),curctdisp->getValue().end(),"pageid")==0){ for(size_t i =0; i<curformdat->Value.size(); ++i){ if(!isdigit(curformdat->Value[i])){ libhttppp::HTTPException excep; excep[libhttppp::HTTPException::Error] << "Wrong formted Pageid!"; std::cout.write(curformdat->Value.data(),curformdat->Value.size())<<std::endl; throw excep; } } if(curctdisp->getValue().size() == 6 && std::equal(curctdisp->getValue().begin(),curctdisp->getValue().end(),"pageid")){ std::vector<char> buf; std::copy(curformdat->Value.begin(),curformdat->Value.end(), std::inserter<std::vector<char>>(buf,buf.begin())); Loading @@ -263,47 +254,49 @@ void blogi::StaticPage::editPage(const int tid,libhttppp::HttpRequest& req, libh if (!id.empty()) { for (libhttppp::HttpForm::MultipartForm::Data* curformdat = form.MultipartFormData.getFormData(); curformdat; curformdat = curformdat->nextData()) { for(libhttppp::HttpForm::MultipartForm::Data::ContentDisposition* curctdisp = curformdat->getDisposition(); curctdisp; curctdisp=curctdisp->nextContentDisposition()){ for (auto* curformdat = form.MultipartFormData.getFormData(); curformdat; curformdat = curformdat->nextData()) { for (auto* curctdisp = curformdat->getDisposition(); curctdisp; curctdisp = curctdisp->nextContentDisposition()) { std::vector<char> data; libhtmlpp::HtmlString result; const std::string key(curctdisp->getValue().begin(), curctdisp->getValue().end()); std::copy(curformdat->Value.begin(),curformdat->Value.end(), std::inserter<std::vector<char>>(data,data.begin())); const std::string val(curformdat->Value.begin(), curformdat->Value.end()); data.push_back('\0'); std::string esc; if(std::equal(curctdisp->getValue().begin(),curctdisp->getValue().end(),"url")==0){ libhtmlpp::HtmlEncode(data.data(),&result); sql<< "update static_content set url='" << result.c_str() << "' where id='" << id.c_str() <<"'; "; }else if(std::equal(curctdisp->getValue().begin(),curctdisp->getValue().end(),"meta")==0){ libhtmlpp::HtmlEncode(data.data(),&result); sql<< "update static_content set meta='" << result.c_str() << "' where id='" << id.c_str() <<"'; "; }else if(std::equal(curctdisp->getValue().begin(),curctdisp->getValue().end(),"text")==0){ sql<< "update static_content set text='"<< sql.escaped(sbuf,data.data()) << "' where id='" << id.c_str() <<"'; "; if (key == "url") { esc = sql.escaped(sbuf, val.c_str()); sql << "UPDATE static_content SET url='" << esc.c_str() << "' WHERE id='" << id.c_str() << "'; "; } else if (key == "meta") { esc = sql.escaped(sbuf, val.c_str()); sql << "UPDATE static_content SET meta='" << esc.c_str() << "' WHERE id='" << id.c_str() << "'; "; } else if (key == "text") { libhtmlpp::HtmlString html; libhtmlpp::HtmlEncode(val.c_str(), &html); esc = sql.escaped(sbuf, html.c_str()); sql << "UPDATE static_content SET text='" << esc.c_str() << "' WHERE id='" << id.c_str() << "'; "; } } } if (!sql.empty()) { Args->database[tid]->exec(sql, res); sql.clear(); } } else { for(libhttppp::HttpForm::UrlcodedForm::Data *cdat=form.UrlFormData.getFormData(); cdat; cdat=cdat->nextData()){ for (auto* cdat = form.UrlFormData.getFormData(); cdat; cdat = cdat->nextData()) { if (cdat->getKey() == "pageid") { size_t pgidlen=cdat->getValue().length(); for(size_t i =0; i<pgidlen; ++i){ if(!isdigit(cdat->getValue()[i])){ libhttppp::HTTPException excep; excep[libhttppp::HTTPException::Error] << "Wrong formted Pageid!"; throw excep; } } id.parse(cdat->getValue()); } } if (id.empty()) { libhttppp::HTTPException excep; excep[libhttppp::HTTPException::Error] << "Staticpage with this id not found!"; Loading @@ -312,7 +305,7 @@ void blogi::StaticPage::editPage(const int tid,libhttppp::HttpRequest& req, libh } }catch(...){}; sql << "select id,url,meta,text from static_content where id='"; sql << id.c_str() << "' LIMIT 1"; sql << "select id,url,meta,text from static_content where id='" << id.c_str() << "' LIMIT 1"; if(Args->database[tid]->exec(sql,res)<1){ return; Loading