Loading src/admin.cpp +41 −60 Changes for src/admin.cpp: 41 added lines, 60 removed lines. Original line number Diff line number Diff line Loading @@ -702,6 +702,7 @@ namespace authdb { libhttppp::HttpForm curform; curform.parse(curreq); std::string name; int stortype=-1; if (curform.getBoundary()) { uuid::uuid uid; Loading @@ -714,89 +715,69 @@ namespace authdb { if(curformdat->Value.empty()) continue; int stortype=TextStorage; for(libhttppp::HttpForm::MultipartForm::Data::ContentDisposition *curdispo=curformdat->getDisposition(); curdispo; curdispo=curdispo->nextContentDisposition() ){ std::string tmp=curdispo->getKey().data(); if(tmp=="domainname"){ name=curdispo->getValue().data(); continue; } if(tmp=="domainstorage"){ stortype=BinaryStorage; continue; } bool numeric=true; stortype=TextStorage; std::string field; // the form field name: domainname/domainstorage/domainoptions StorageType stortype = EmptyStorage; for(auto t=curformdat->Value.begin(); t!=curformdat->Value.end(); ++t){ if(!std::isdigit(*t)){ numeric=false; break; } } // Determine field name and storage type for (auto *curdispo = curformdat->getDisposition(); curdispo; curdispo = curdispo->nextContentDisposition()) { const std::string key = curdispo->getKey().data(); // usually "name" or "filename" const std::string val = curdispo->getValue().data(); // for key=="name": the real field name if(numeric){ stortype=StorageType::IntStorage; if (key == "name") { field = val; // e.g. "domainname", "domainstorage", "domainoptions" } else if (key == "filename") { // Not expected for these fields; if you later add file inputs, set BinaryStorage here. // For now, do nothing. } } if(name.empty() || stortype == EmptyStorage) // Decide storage type strictly by field if (field == "domainname" || field == "domainoptions") { stortype = TextStorage; } else if (field == "domainstorage") { stortype = IntStorage; } else { // Unknown field; skip continue; } struct AuthData::Record dodat; // Build record AuthData::Record dodat{}; dodat.start = 0xFE; std::copy(&uid.value[0], &uid.value[16], &dodat.ruid[0]); dodat.type = DomainData; dodat.storage = stortype; strcpy(dodat.fieldname,name.c_str()); std::strncpy(dodat.fieldname, field.c_str(), sizeof(dodat.fieldname)-1); dodat.fieldname[sizeof(dodat.fieldname)-1] = '\0'; if(dodat.storage==TextStorage){ curformdat->Value.push_back('\0'); dodat.datasize=curformdat->Value.size(); dodat.data=new char[dodat.datasize]; std::copy(curformdat->Value.begin(), curformdat->Value.end(),dodat.data); ddat.append(dodat); delete[] dodat.data; }else if(dodat.storage==IntStorage){ curformdat->Value.push_back('\0'); if (stortype == IntStorage) { // Expect numeric value (e.g., AuthBackendType) int val = 0; // curformdat->Value may not be null-terminated; make a string first std::string s(curformdat->Value.begin(), curformdat->Value.end()); val = std::atoi(s.c_str()); dodat.datasize = sizeof(int); dodat.data = new char[sizeof(int)]; int val=atoi(curformdat->Value.data()); std::copy( reinterpret_cast<const char*>(&val), reinterpret_cast<const char*>(&val)+dodat.datasize, dodat.data ); std::memcpy(dodat.data, &val, sizeof(int)); ddat.append(dodat); delete dodat.data; }else { dodat.datasize=curformdat->Value.size(); dodat.data=new char[dodat.datasize]; std::copy(curformdat->Value.begin(), curformdat->Value.end(),dodat.data); delete[] dodat.data; } else { // TextStorage // Ensure trailing NUL std::vector<char> buf = curformdat->Value; buf.push_back('\0'); dodat.datasize = buf.size(); dodat.data = new char[dodat.datasize]; std::copy(buf.begin(), buf.end(), dodat.data); ddat.append(dodat); delete[] dodat.data; } name.clear(); stortype=EmptyStorage; } Domain domain; domain.create(_AdminBackend,&ddat); } libhtmlpp::HtmlString form,out; Loading Loading
src/admin.cpp +41 −60 Changes for src/admin.cpp: 41 added lines, 60 removed lines. Original line number Diff line number Diff line Loading @@ -702,6 +702,7 @@ namespace authdb { libhttppp::HttpForm curform; curform.parse(curreq); std::string name; int stortype=-1; if (curform.getBoundary()) { uuid::uuid uid; Loading @@ -714,89 +715,69 @@ namespace authdb { if(curformdat->Value.empty()) continue; int stortype=TextStorage; for(libhttppp::HttpForm::MultipartForm::Data::ContentDisposition *curdispo=curformdat->getDisposition(); curdispo; curdispo=curdispo->nextContentDisposition() ){ std::string tmp=curdispo->getKey().data(); if(tmp=="domainname"){ name=curdispo->getValue().data(); continue; } if(tmp=="domainstorage"){ stortype=BinaryStorage; continue; } bool numeric=true; stortype=TextStorage; std::string field; // the form field name: domainname/domainstorage/domainoptions StorageType stortype = EmptyStorage; for(auto t=curformdat->Value.begin(); t!=curformdat->Value.end(); ++t){ if(!std::isdigit(*t)){ numeric=false; break; } } // Determine field name and storage type for (auto *curdispo = curformdat->getDisposition(); curdispo; curdispo = curdispo->nextContentDisposition()) { const std::string key = curdispo->getKey().data(); // usually "name" or "filename" const std::string val = curdispo->getValue().data(); // for key=="name": the real field name if(numeric){ stortype=StorageType::IntStorage; if (key == "name") { field = val; // e.g. "domainname", "domainstorage", "domainoptions" } else if (key == "filename") { // Not expected for these fields; if you later add file inputs, set BinaryStorage here. // For now, do nothing. } } if(name.empty() || stortype == EmptyStorage) // Decide storage type strictly by field if (field == "domainname" || field == "domainoptions") { stortype = TextStorage; } else if (field == "domainstorage") { stortype = IntStorage; } else { // Unknown field; skip continue; } struct AuthData::Record dodat; // Build record AuthData::Record dodat{}; dodat.start = 0xFE; std::copy(&uid.value[0], &uid.value[16], &dodat.ruid[0]); dodat.type = DomainData; dodat.storage = stortype; strcpy(dodat.fieldname,name.c_str()); std::strncpy(dodat.fieldname, field.c_str(), sizeof(dodat.fieldname)-1); dodat.fieldname[sizeof(dodat.fieldname)-1] = '\0'; if(dodat.storage==TextStorage){ curformdat->Value.push_back('\0'); dodat.datasize=curformdat->Value.size(); dodat.data=new char[dodat.datasize]; std::copy(curformdat->Value.begin(), curformdat->Value.end(),dodat.data); ddat.append(dodat); delete[] dodat.data; }else if(dodat.storage==IntStorage){ curformdat->Value.push_back('\0'); if (stortype == IntStorage) { // Expect numeric value (e.g., AuthBackendType) int val = 0; // curformdat->Value may not be null-terminated; make a string first std::string s(curformdat->Value.begin(), curformdat->Value.end()); val = std::atoi(s.c_str()); dodat.datasize = sizeof(int); dodat.data = new char[sizeof(int)]; int val=atoi(curformdat->Value.data()); std::copy( reinterpret_cast<const char*>(&val), reinterpret_cast<const char*>(&val)+dodat.datasize, dodat.data ); std::memcpy(dodat.data, &val, sizeof(int)); ddat.append(dodat); delete dodat.data; }else { dodat.datasize=curformdat->Value.size(); dodat.data=new char[dodat.datasize]; std::copy(curformdat->Value.begin(), curformdat->Value.end(),dodat.data); delete[] dodat.data; } else { // TextStorage // Ensure trailing NUL std::vector<char> buf = curformdat->Value; buf.push_back('\0'); dodat.datasize = buf.size(); dodat.data = new char[dodat.datasize]; std::copy(buf.begin(), buf.end(), dodat.data); ddat.append(dodat); delete[] dodat.data; } name.clear(); stortype=EmptyStorage; } Domain domain; domain.create(_AdminBackend,&ddat); } libhtmlpp::HtmlString form,out; Loading