diff --git a/src/authdb.cpp b/src/authdb.cpp index 6626e54239a003b5613b9e6253e837f505fcfddb..f3271202be441312db133b775678ed4c64b2b633 100644 --- a/src/authdb.cpp +++ b/src/authdb.cpp @@ -232,7 +232,7 @@ namespace authdb { continue; std::string name; - int stortype=TextStorage; + int stortype=EmptyStorage; for(libhttppp::HttpForm::MultipartForm::Data::ContentDisposition *curdispo=curformdat->getDisposition(); curdispo; curdispo=curdispo->nextContentDisposition() @@ -243,14 +243,30 @@ namespace authdb { std::transform(tmp.begin(), tmp.end(), tmp.begin(), [](unsigned char c){ return std::tolower(c); }); - if(tmp=="name") + if(tmp=="name"){ name=curdispo->getValue(); + } if(tmp=="filename"){ stortype=BinaryStorage; } } + if(stortype==EmptyStorage){ + bool numeric=true; + for(auto i : curformdat->Value){ + if(!std::isdigit(i)){ + numeric=false; + break; + } + } + + if(!numeric) + stortype=TextStorage; + else + stortype=IntStorage; + } + if(name.empty() || stortype == EmptyStorage) continue; @@ -262,6 +278,7 @@ namespace authdb { cudat.type=UserData; cudat.storage=stortype; + strcpy(cudat.fieldname,name.c_str()); if(cudat.storage==BinaryStorage){ @@ -269,7 +286,10 @@ namespace authdb { cudat.data=new char[cudat.datasize]; memcpy(cudat.data,curformdat->Value.data(), cudat.datasize); - }else{ + + udat.Data->append(cudat); + delete[] cudat.data; + }else if(cudat.storage==TextStorage){ if(strcmp(cudat.fieldname,"pwhash")==0){ Hash hash; std::string pwhash,inpw; @@ -280,17 +300,32 @@ namespace authdb { cudat.data=new char[cudat.datasize]; memcpy(cudat.data,pwhash.c_str(),pwhash.length()); cudat.data[pwhash.length()]='\0'; + + udat.Data->append(cudat); + delete[] cudat.data; }else{ - cudat.datasize=curformdat->Value.size()+1; + curformdat->Value.push_back('\0'); + + cudat.datasize=curformdat->Value.size(); cudat.data=new char[cudat.datasize]; memcpy(cudat.data,curformdat->Value.data(), curformdat->Value.size()); - cudat.data[curformdat->Value.size()]='\0'; + + udat.Data->append(cudat); + delete[] cudat.data; } + }else if(cudat.storage==IntStorage){ + curformdat->Value.push_back('\0'); + int val=atoi(curformdat->Value.data()); + cudat.datasize=sizeof(int); + cudat.data=(char*)new int; + memcpy(cudat.data,&val, + curformdat->Value.size()); + + udat.Data->append(cudat); + delete[] cudat.data; } - udat.Data->append(cudat); - delete[] cudat.data; } User user; user.create(*backend,&udat); @@ -461,6 +496,7 @@ namespace authdb { AuthData curec(uid); + curec.Data->type=UserData; curec.Data->storage=EmptyStorage; for(libhttppp::HttpForm::MultipartForm::Data::ContentDisposition *curdispo=curformdat->getDisposition(); @@ -508,6 +544,8 @@ namespace authdb { curec.Data->storage=TextStorage; } + + if(curec.Data->storage==TextStorage) { curformdat->Value.push_back('\0'); if(strcmp(curec.Data->fieldname,"pwhash")==0){ @@ -988,6 +1026,7 @@ VALUEFOUND: AuthData::AuthData(const uuid_t id){ Data = new struct AuthData::Record; + memset(Data,0,sizeof(AuthData::Record)); uuid_copy(Data->uuid,id); Data->start=0xFE; Data->storage=EmptyStorage; @@ -1002,7 +1041,6 @@ VALUEFOUND: AuthData *dest=this; for(const AuthData *cursrc=&src; cursrc; cursrc=cursrc->next()){ - std::cout << "test" << std::endl; memcpy(dest->Data,cursrc->Data,sizeof(AuthData::Record)); dest->Data->datasize=cursrc->Data->datasize; dest->Data->data=new char[dest->Data->datasize];