Loading src/admin.cpp +14 −31 Changes for src/admin.cpp: 14 added lines, 31 removed lines. Original line number Diff line number Diff line Loading @@ -702,7 +702,6 @@ namespace authdb { libhttppp::HttpForm curform; curform.parse(curreq); std::string name; int stortype=-1; if (curform.getBoundary()) { uuid::uuid uid; Loading @@ -712,62 +711,45 @@ namespace authdb { for (libhttppp::HttpForm::MultipartForm::Data* curformdat = curform.MultipartFormData.getFormData(); curformdat; curformdat = curformdat->nextData()) { if(curformdat->Value.empty()) continue; stortype=TextStorage; std::string field; // the form field name: domainname/domainstorage/domainoptions std::string field; // "domainname" | "domainstorage" | "domainoptions" StorageType stortype = EmptyStorage; // 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 (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. } for (auto *d = curformdat->getDisposition(); d; d = d->nextContentDisposition()) { std::string key(d->getKey().begin(), d->getKey().end()); std::string val(d->getValue().begin(), d->getValue().end()); if (key == "name") field = val; } // Decide storage type strictly by field std::cout << field << std::endl; if (field == "domainname" || field == "domainoptions") { stortype = TextStorage; } else if (field == "domainstorage") { stortype = IntStorage; } else { // Unknown field; skip continue; continue; // unknown field } // 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; std::strncpy(dodat.fieldname, field.c_str(), sizeof(dodat.fieldname)-1); dodat.fieldname[sizeof(dodat.fieldname)-1] = '\0'; std::strncpy(dodat.fieldname, field.c_str(), field.length()); dodat.fieldname[field.length()]='\0'; std::cout << dodat.fieldname << std::endl; // 4) Write data 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()); int val = std::atoi(s.c_str()); dodat.datasize = sizeof(int); dodat.data = new char[sizeof(int)]; std::memcpy(dodat.data, &val, sizeof(int)); ddat.append(dodat); 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); Loading @@ -775,6 +757,7 @@ namespace authdb { delete[] dodat.data; } } Domain domain; domain.create(_AdminBackend,&ddat); Loading src/domain.cpp +1 −1 Changes for src/domain.cpp: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -73,7 +73,7 @@ void authdb::Domain::create(authdb::AuthBackend& backend,class DomainData *data) int exi=0; if(exits(backend,data->Data.ruid,data->getDomainName().c_str(),exi)){ if(exits(backend,data->Data.ruid,data->getDomainName(),exi)){ switch(exi){ case 1: throw authdb::AuthBackendError("Create Domain: Domainname already Exists aborting!"); Loading Loading
src/admin.cpp +14 −31 Changes for src/admin.cpp: 14 added lines, 31 removed lines. Original line number Diff line number Diff line Loading @@ -702,7 +702,6 @@ namespace authdb { libhttppp::HttpForm curform; curform.parse(curreq); std::string name; int stortype=-1; if (curform.getBoundary()) { uuid::uuid uid; Loading @@ -712,62 +711,45 @@ namespace authdb { for (libhttppp::HttpForm::MultipartForm::Data* curformdat = curform.MultipartFormData.getFormData(); curformdat; curformdat = curformdat->nextData()) { if(curformdat->Value.empty()) continue; stortype=TextStorage; std::string field; // the form field name: domainname/domainstorage/domainoptions std::string field; // "domainname" | "domainstorage" | "domainoptions" StorageType stortype = EmptyStorage; // 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 (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. } for (auto *d = curformdat->getDisposition(); d; d = d->nextContentDisposition()) { std::string key(d->getKey().begin(), d->getKey().end()); std::string val(d->getValue().begin(), d->getValue().end()); if (key == "name") field = val; } // Decide storage type strictly by field std::cout << field << std::endl; if (field == "domainname" || field == "domainoptions") { stortype = TextStorage; } else if (field == "domainstorage") { stortype = IntStorage; } else { // Unknown field; skip continue; continue; // unknown field } // 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; std::strncpy(dodat.fieldname, field.c_str(), sizeof(dodat.fieldname)-1); dodat.fieldname[sizeof(dodat.fieldname)-1] = '\0'; std::strncpy(dodat.fieldname, field.c_str(), field.length()); dodat.fieldname[field.length()]='\0'; std::cout << dodat.fieldname << std::endl; // 4) Write data 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()); int val = std::atoi(s.c_str()); dodat.datasize = sizeof(int); dodat.data = new char[sizeof(int)]; std::memcpy(dodat.data, &val, sizeof(int)); ddat.append(dodat); 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); Loading @@ -775,6 +757,7 @@ namespace authdb { delete[] dodat.data; } } Domain domain; domain.create(_AdminBackend,&ddat); Loading
src/domain.cpp +1 −1 Changes for src/domain.cpp: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -73,7 +73,7 @@ void authdb::Domain::create(authdb::AuthBackend& backend,class DomainData *data) int exi=0; if(exits(backend,data->Data.ruid,data->getDomainName().c_str(),exi)){ if(exits(backend,data->Data.ruid,data->getDomainName(),exi)){ switch(exi){ case 1: throw authdb::AuthBackendError("Create Domain: Domainname already Exists aborting!"); Loading