Loading plugins/staticpage/static.cpp +28 −25 Changes for plugins/staticpage/static.cpp: 28 added lines, 25 removed lines. Original line number Diff line number Diff line Loading @@ -92,8 +92,6 @@ void blogi::StaticPage::Settings(const int tid,libhttppp::HttpRequest &req, libh SENDFIND: surl=curl.substr(prelen,send); std::cout << surl << std::endl; if(surl=="newpage"){ newPage(tid,req,setdiv); return; Loading Loading @@ -245,35 +243,42 @@ void blogi::StaticPage::editPage(const int tid, libhttppp::HttpRequest& req, lib libhttppp::HttpForm form; form.parse(req); // Helper to create string_view and remove trailing NULL (necessary for this library) auto sv_from_vec = [](const std::vector<char>& v) -> std::string_view { std::string_view sv(v.data(), v.size()); // gängige Parser hinterlassen ein '\0' am Ende – weg damit if (!sv.empty() && sv.back() == '\0') sv.remove_suffix(1); return sv; }; // Lambda to reliably find a Content-Disposition parameter by key (e.g., "name") auto find_disposition_param = [&](libhttppp::HttpForm::MultipartForm::Data* formData, const std::string ¶mKey) -> std::string_view { for (auto* cd = formData->getDisposition(); cd; cd = cd->nextContentDisposition()) { // Assume cd->getKey() returns the parameter name (like "name") if (cd->getKey().size()==paramKey.length() && std::equal(cd->getKey().begin(),cd->getKey().end(),paramKey.begin())) { return sv_from_vec(cd->getValue()); } } return std::string_view(); // Return empty view if not found }; try { // 1) pageid aus multipart lesen (alle Dispositions iterieren!) // --- 1) Reliable Page ID Retrieval --- for (auto* curformdat = form.MultipartFormData.getFormData(); curformdat; curformdat = curformdat->nextData()) { for (auto* cd = curformdat->getDisposition(); cd; cd = cd->nextContentDisposition()) { // Viele Parser liefern Paare wie name="pageid". // Falls du auch getKey() hast, prüfe zusätzlich: if (cd->getKey()=="name") const std::string_view disp = sv_from_vec(cd->getValue()); if (disp == "pageid") { std::string_view fieldName = find_disposition_param(curformdat, "name"); if (fieldName == "pageid") { std::string_view val = sv_from_vec(curformdat->Value); uuid::uuid tmp; tmp.parse(std::string(val).c_str()); if (!tmp.empty()) { id = tmp; break; } } } if (!id.empty()) break; } // Fallback: urlencoded // Fallback: urlencoded (kept your original logic here) if (id.empty()) { for (auto* cdat = form.UrlFormData.getFormData(); cdat; cdat = cdat->nextData()) { if (cdat->getKey() == "pageid") { Loading @@ -289,20 +294,19 @@ void blogi::StaticPage::editPage(const int tid, libhttppp::HttpRequest& req, lib throw excep; } // 2) Updates einsammeln // --- 2) Update SQL Building and Execution --- sql.clear(); for (auto* curformdat = form.MultipartFormData.getFormData(); curformdat; curformdat = curformdat->nextData()) { for (auto* cd = curformdat->getDisposition(); cd; cd = cd->nextContentDisposition()) { const std::string_view key = sv_from_vec(cd->getValue()); // Use the robust finder to get the field name ("url", "meta", "text") std::string_view key = find_disposition_param(curformdat, "name"); const std::string_view val_sv = sv_from_vec(curformdat->Value); const std::string val(val_sv); // kopieren wenn wir escapen const std::string val(val_sv); auto put_update = [&](const char* col, const char* raw) { std::string esc = sql.escaped(sbuf, raw); // Batch UPDATE statements for efficiency sql << "UPDATE static_content SET " << col << "='" << esc.c_str() << "' WHERE id='" << id.c_str() << "'; "; }; Loading @@ -321,19 +325,19 @@ void blogi::StaticPage::editPage(const int tid, libhttppp::HttpRequest& req, lib put_update("text", html.c_str()); } } } if (!sql.empty()) { // Execute the batch of UPDATE statements Args->database[tid]->exec(sql, res); sql.clear(); } } catch (const std::exception& e) { // Fehler nicht schlucken – wenigstens loggen/weiterreichen // log(e.what()); throw; libhttppp::HTTPException excep; excep[libhttppp::HTTPException::Error] << e.what(); throw excep; } // Seite erneut laden // --- 3) Re-load and Output Form (Unchanged Logic) --- 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 @@ -353,7 +357,6 @@ void blogi::StaticPage::editPage(const int tid, libhttppp::HttpRequest& req, lib << "</form></div>"; } void blogi::StaticPage::uploadPage(const int tid,libhttppp::HttpRequest& req, libhtmlpp::HtmlString& setdiv){ } Loading src/blogi.cpp +1 −1 Changes for src/blogi.cpp: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -359,7 +359,7 @@ void blogi::Blogi::settingsPage(libhttppp::HttpRequest& curreq,const int tid,con curplg->getInstace()->Rendering(tid,curreq,&index,RenderingType::Desktop); } PlgArgs->theme->printSite(tid,out,&index,curreq.getRequestURL(),false); PlgArgs->theme->printSite(tid,out,&index,curreq.getRequestURL(),true); libhttppp::HttpResponse curres; curres.setState(HTTP200); curres.setVersion(HTTPVERSION(1.1)); Loading Loading
plugins/staticpage/static.cpp +28 −25 Changes for plugins/staticpage/static.cpp: 28 added lines, 25 removed lines. Original line number Diff line number Diff line Loading @@ -92,8 +92,6 @@ void blogi::StaticPage::Settings(const int tid,libhttppp::HttpRequest &req, libh SENDFIND: surl=curl.substr(prelen,send); std::cout << surl << std::endl; if(surl=="newpage"){ newPage(tid,req,setdiv); return; Loading Loading @@ -245,35 +243,42 @@ void blogi::StaticPage::editPage(const int tid, libhttppp::HttpRequest& req, lib libhttppp::HttpForm form; form.parse(req); // Helper to create string_view and remove trailing NULL (necessary for this library) auto sv_from_vec = [](const std::vector<char>& v) -> std::string_view { std::string_view sv(v.data(), v.size()); // gängige Parser hinterlassen ein '\0' am Ende – weg damit if (!sv.empty() && sv.back() == '\0') sv.remove_suffix(1); return sv; }; // Lambda to reliably find a Content-Disposition parameter by key (e.g., "name") auto find_disposition_param = [&](libhttppp::HttpForm::MultipartForm::Data* formData, const std::string ¶mKey) -> std::string_view { for (auto* cd = formData->getDisposition(); cd; cd = cd->nextContentDisposition()) { // Assume cd->getKey() returns the parameter name (like "name") if (cd->getKey().size()==paramKey.length() && std::equal(cd->getKey().begin(),cd->getKey().end(),paramKey.begin())) { return sv_from_vec(cd->getValue()); } } return std::string_view(); // Return empty view if not found }; try { // 1) pageid aus multipart lesen (alle Dispositions iterieren!) // --- 1) Reliable Page ID Retrieval --- for (auto* curformdat = form.MultipartFormData.getFormData(); curformdat; curformdat = curformdat->nextData()) { for (auto* cd = curformdat->getDisposition(); cd; cd = cd->nextContentDisposition()) { // Viele Parser liefern Paare wie name="pageid". // Falls du auch getKey() hast, prüfe zusätzlich: if (cd->getKey()=="name") const std::string_view disp = sv_from_vec(cd->getValue()); if (disp == "pageid") { std::string_view fieldName = find_disposition_param(curformdat, "name"); if (fieldName == "pageid") { std::string_view val = sv_from_vec(curformdat->Value); uuid::uuid tmp; tmp.parse(std::string(val).c_str()); if (!tmp.empty()) { id = tmp; break; } } } if (!id.empty()) break; } // Fallback: urlencoded // Fallback: urlencoded (kept your original logic here) if (id.empty()) { for (auto* cdat = form.UrlFormData.getFormData(); cdat; cdat = cdat->nextData()) { if (cdat->getKey() == "pageid") { Loading @@ -289,20 +294,19 @@ void blogi::StaticPage::editPage(const int tid, libhttppp::HttpRequest& req, lib throw excep; } // 2) Updates einsammeln // --- 2) Update SQL Building and Execution --- sql.clear(); for (auto* curformdat = form.MultipartFormData.getFormData(); curformdat; curformdat = curformdat->nextData()) { for (auto* cd = curformdat->getDisposition(); cd; cd = cd->nextContentDisposition()) { const std::string_view key = sv_from_vec(cd->getValue()); // Use the robust finder to get the field name ("url", "meta", "text") std::string_view key = find_disposition_param(curformdat, "name"); const std::string_view val_sv = sv_from_vec(curformdat->Value); const std::string val(val_sv); // kopieren wenn wir escapen const std::string val(val_sv); auto put_update = [&](const char* col, const char* raw) { std::string esc = sql.escaped(sbuf, raw); // Batch UPDATE statements for efficiency sql << "UPDATE static_content SET " << col << "='" << esc.c_str() << "' WHERE id='" << id.c_str() << "'; "; }; Loading @@ -321,19 +325,19 @@ void blogi::StaticPage::editPage(const int tid, libhttppp::HttpRequest& req, lib put_update("text", html.c_str()); } } } if (!sql.empty()) { // Execute the batch of UPDATE statements Args->database[tid]->exec(sql, res); sql.clear(); } } catch (const std::exception& e) { // Fehler nicht schlucken – wenigstens loggen/weiterreichen // log(e.what()); throw; libhttppp::HTTPException excep; excep[libhttppp::HTTPException::Error] << e.what(); throw excep; } // Seite erneut laden // --- 3) Re-load and Output Form (Unchanged Logic) --- 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 @@ -353,7 +357,6 @@ void blogi::StaticPage::editPage(const int tid, libhttppp::HttpRequest& req, lib << "</form></div>"; } void blogi::StaticPage::uploadPage(const int tid,libhttppp::HttpRequest& req, libhtmlpp::HtmlString& setdiv){ } Loading
src/blogi.cpp +1 −1 Changes for src/blogi.cpp: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -359,7 +359,7 @@ void blogi::Blogi::settingsPage(libhttppp::HttpRequest& curreq,const int tid,con curplg->getInstace()->Rendering(tid,curreq,&index,RenderingType::Desktop); } PlgArgs->theme->printSite(tid,out,&index,curreq.getRequestURL(),false); PlgArgs->theme->printSite(tid,out,&index,curreq.getRequestURL(),true); libhttppp::HttpResponse curres; curres.setState(HTTP200); curres.setVersion(HTTPVERSION(1.1)); Loading