Loading examples/httpauth.cpp +0 −1 Changes for examples/httpauth.cpp: 0 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -99,7 +99,6 @@ public: libhttppp::HttpResponse curres; curres.setState(HTTP401); curres.setVersion(HTTPVERSION(1.1)); curres.setContentType(nullptr); if(curreq.getRequestURL()=="/httpbasicauth"){ httpauth.setAuthType(BASICAUTH); }else if(curreq.getRequestURL()=="/httpdigestauth"){ Loading src/http.cpp +74 −47 Changes for src/http.cpp: 74 added lines, 47 removed lines. Original line number Diff line number Diff line Loading @@ -619,6 +619,17 @@ void libhttppp::HttpHeader::HeaderData::push_back(const char* val){ } } void libhttppp::HttpHeader::HeaderData::push_back(const Values& val){ if(_firstValue==nullptr){ _firstValue=std::make_unique<Values>(val); _lastValue=_firstValue.get(); }else{ _lastValue->_nextvalue=std::make_unique<Values>(val); _lastValue=_lastValue->_nextvalue.get(); } } void libhttppp::HttpHeader::HeaderData::push_back(const std::string &val){ if(_firstValue==nullptr){ _firstValue=std::make_unique<Values>(val); Loading Loading @@ -750,16 +761,34 @@ libhttppp::HttpHeader::HeaderData::Values &libhttppp::HttpHeader::HeaderData::Va return *this; } libhttppp::HttpHeader::HeaderData::Values & libhttppp::HttpHeader::HeaderData::Values::operator=(const Values& val){ if (this == &val) return *this; _value = val._value; if (val._nextvalue) { _nextvalue = std::make_unique<Values>(*val._nextvalue); } else { _nextvalue.reset(); } return *this; } libhttppp::HttpHeader::HeaderData::Values::Values(const char *val) { _nextvalue=nullptr; _value=val; } libhttppp::HttpHeader::HeaderData::Values::Values(const std::string& val) { _nextvalue=nullptr; _value=val; } libhttppp::HttpHeader::HeaderData::Values::Values(const Values& val) : _value(val._value) { if (val._nextvalue) { _nextvalue = std::make_unique<Values>(*val._nextvalue); } } libhttppp::HttpResponse::HttpResponse() : HttpHeader(){ setState(HTTP200); setVersion(HTTPVERSION(1.1)); Loading Loading @@ -2026,9 +2055,6 @@ libhttppp::HttpCookie::CookieData *libhttppp::HttpCookie::addCookieData(){ libhttppp::HttpAuth::HttpAuth(){ _Authtype=BASICAUTH; _Username=nullptr; _Password=nullptr; _Realm=nullptr; } libhttppp::HttpAuth::~HttpAuth(){ Loading @@ -2040,36 +2066,35 @@ void libhttppp::HttpAuth::parse(libhttppp::HttpRequest &curreq){ if(!hau) return; std::string authstr; for(HttpHeader::HeaderData::Values *cval=hau->getfirstValue(); cval; cval=cval->nextvalue() ){ if(cval->getvalue()=="basic"){ _Authtype=BASICAUTH; if(cval->nextvalue()) authstr=cval->nextvalue()->getvalue(); break; }else if(cval->getvalue()=="digest"){ _Authtype=DIGESTAUTH; if(cval->nextvalue()) authstr=cval->nextvalue()->getvalue(); break; } } switch(_Authtype){ // case BASICAUTH:{ // size_t base64strsize=strlen(authstr+6); // unsigned char *base64str=new char unsigned[base64strsize+1]; // memcpy(base64str,authstr+6,strlen(authstr)-5); // char *clearstr= new char[(base64strsize/4)*3]; // size_t cleargetlen=netplus::base64::Decode((char*)base64str,clearstr); // delete[] base64str; // for(size_t clearpos=0; clearpos<cleargetlen; clearpos++){ // if(clearstr[clearpos]==':'){ // char *usernm=new char[clearpos+1]; // memcpy(usernm,clearstr+clearpos,strlen(clearstr)-clearpos); // usernm[clearpos]='\0'; // setUsername(usernm); // setPassword(clearstr+(clearpos+1)); // delete[] usernm; // } // } // delete[] clearstr; // }; case BASICAUTH:{ netplus::base64 base64str; base64str << authstr; std::string clearstr; base64str >> clearstr; for(size_t clearpos=0; clearpos<authstr.length(); clearpos++){ if(clearstr[clearpos]==':'){ setUsername(clearstr.substr(1,clearpos)); setPassword(clearstr.substr(clearpos+1,clearstr.length()-(clearpos+1))); } } }; // case DIGESTAUTH:{ // for(size_t authstrpos=7; authstrpos<strlen(authstr)+1; authstrpos++){ // switch(authstr[authstrpos]){ Loading @@ -2088,29 +2113,31 @@ void libhttppp::HttpAuth::parse(libhttppp::HttpRequest &curreq){ void libhttppp::HttpAuth::setAuth(libhttppp::HttpResponse &curresp){ HttpHeader::HeaderData *dat=curresp.setHeaderData("www-authenticate"); // switch(_Authtype){ // case BASICAUTH:{ // if(_Realm){ // *dat << "basic realm=\"" << _Realm << "\""; // }else{ // *dat << "basic"; // } // }; // case DIGESTAUTH:{ // *dat << "digest"; // if(_Realm){ // *dat << " realm=\"" << _Realm <<"\""; // } // char nonce[16]={'0'}; // for(size_t noncepos=0; noncepos<=16; noncepos++){ // char random[]={1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f','\0'}; // for(size_t rdpos=0; random[rdpos]!='\0'; rdpos++){ // nonce[noncepos]=random[rdpos]; // } // } // *dat << "nonce=\"" << nonce << "\""; // }; // } HttpHeader::HeaderData::Values authval; switch(_Authtype){ case BASICAUTH:{ if(!_Realm.empty()){ authval << "basic realm=\"" << _Realm << "\""; }else{ authval << "basic"; } }; case DIGESTAUTH:{ authval << "digest"; if(!_Realm.empty()){ authval << " realm=\"" << _Realm <<"\""; } char nonce[16]={'0'}; for(size_t noncepos=0; noncepos<=16; noncepos++){ char random[]={1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f','\0'}; for(size_t rdpos=0; random[rdpos]!='\0'; rdpos++){ nonce[noncepos]=random[rdpos]; } } authval << "nonce=\"" << nonce << "\""; }; } dat->push_back(authval); } void libhttppp::HttpAuth::setAuthType(int authtype){ Loading src/http.h +5 −1 Changes for src/http.h: 5 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -102,6 +102,7 @@ namespace libhttppp { Values &operator=(const std::string &val); Values &operator=(size_t val); Values &operator=(int val); Values& operator=(const Values &val); Values &operator<<(const std::string &value); Values &operator<<(size_t value); Loading @@ -114,10 +115,12 @@ namespace libhttppp { Values *nextvalue(); Values(const char *value); Values(const std::string& val); Values(const Values& val); Values()=default; ~Values() = default; private: std::string _value; std::unique_ptr<Values> _nextvalue; std::unique_ptr<Values> _nextvalue=nullptr; friend class HeaderData; }; Loading @@ -125,6 +128,7 @@ namespace libhttppp { Values &at(int pos); Values &operator[](int pos); void push_back(const Values &val); void push_back(const std::string &val); void push_back(const char* val); void push_back(size_t val); Loading Loading
examples/httpauth.cpp +0 −1 Changes for examples/httpauth.cpp: 0 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -99,7 +99,6 @@ public: libhttppp::HttpResponse curres; curres.setState(HTTP401); curres.setVersion(HTTPVERSION(1.1)); curres.setContentType(nullptr); if(curreq.getRequestURL()=="/httpbasicauth"){ httpauth.setAuthType(BASICAUTH); }else if(curreq.getRequestURL()=="/httpdigestauth"){ Loading
src/http.cpp +74 −47 Changes for src/http.cpp: 74 added lines, 47 removed lines. Original line number Diff line number Diff line Loading @@ -619,6 +619,17 @@ void libhttppp::HttpHeader::HeaderData::push_back(const char* val){ } } void libhttppp::HttpHeader::HeaderData::push_back(const Values& val){ if(_firstValue==nullptr){ _firstValue=std::make_unique<Values>(val); _lastValue=_firstValue.get(); }else{ _lastValue->_nextvalue=std::make_unique<Values>(val); _lastValue=_lastValue->_nextvalue.get(); } } void libhttppp::HttpHeader::HeaderData::push_back(const std::string &val){ if(_firstValue==nullptr){ _firstValue=std::make_unique<Values>(val); Loading Loading @@ -750,16 +761,34 @@ libhttppp::HttpHeader::HeaderData::Values &libhttppp::HttpHeader::HeaderData::Va return *this; } libhttppp::HttpHeader::HeaderData::Values & libhttppp::HttpHeader::HeaderData::Values::operator=(const Values& val){ if (this == &val) return *this; _value = val._value; if (val._nextvalue) { _nextvalue = std::make_unique<Values>(*val._nextvalue); } else { _nextvalue.reset(); } return *this; } libhttppp::HttpHeader::HeaderData::Values::Values(const char *val) { _nextvalue=nullptr; _value=val; } libhttppp::HttpHeader::HeaderData::Values::Values(const std::string& val) { _nextvalue=nullptr; _value=val; } libhttppp::HttpHeader::HeaderData::Values::Values(const Values& val) : _value(val._value) { if (val._nextvalue) { _nextvalue = std::make_unique<Values>(*val._nextvalue); } } libhttppp::HttpResponse::HttpResponse() : HttpHeader(){ setState(HTTP200); setVersion(HTTPVERSION(1.1)); Loading Loading @@ -2026,9 +2055,6 @@ libhttppp::HttpCookie::CookieData *libhttppp::HttpCookie::addCookieData(){ libhttppp::HttpAuth::HttpAuth(){ _Authtype=BASICAUTH; _Username=nullptr; _Password=nullptr; _Realm=nullptr; } libhttppp::HttpAuth::~HttpAuth(){ Loading @@ -2040,36 +2066,35 @@ void libhttppp::HttpAuth::parse(libhttppp::HttpRequest &curreq){ if(!hau) return; std::string authstr; for(HttpHeader::HeaderData::Values *cval=hau->getfirstValue(); cval; cval=cval->nextvalue() ){ if(cval->getvalue()=="basic"){ _Authtype=BASICAUTH; if(cval->nextvalue()) authstr=cval->nextvalue()->getvalue(); break; }else if(cval->getvalue()=="digest"){ _Authtype=DIGESTAUTH; if(cval->nextvalue()) authstr=cval->nextvalue()->getvalue(); break; } } switch(_Authtype){ // case BASICAUTH:{ // size_t base64strsize=strlen(authstr+6); // unsigned char *base64str=new char unsigned[base64strsize+1]; // memcpy(base64str,authstr+6,strlen(authstr)-5); // char *clearstr= new char[(base64strsize/4)*3]; // size_t cleargetlen=netplus::base64::Decode((char*)base64str,clearstr); // delete[] base64str; // for(size_t clearpos=0; clearpos<cleargetlen; clearpos++){ // if(clearstr[clearpos]==':'){ // char *usernm=new char[clearpos+1]; // memcpy(usernm,clearstr+clearpos,strlen(clearstr)-clearpos); // usernm[clearpos]='\0'; // setUsername(usernm); // setPassword(clearstr+(clearpos+1)); // delete[] usernm; // } // } // delete[] clearstr; // }; case BASICAUTH:{ netplus::base64 base64str; base64str << authstr; std::string clearstr; base64str >> clearstr; for(size_t clearpos=0; clearpos<authstr.length(); clearpos++){ if(clearstr[clearpos]==':'){ setUsername(clearstr.substr(1,clearpos)); setPassword(clearstr.substr(clearpos+1,clearstr.length()-(clearpos+1))); } } }; // case DIGESTAUTH:{ // for(size_t authstrpos=7; authstrpos<strlen(authstr)+1; authstrpos++){ // switch(authstr[authstrpos]){ Loading @@ -2088,29 +2113,31 @@ void libhttppp::HttpAuth::parse(libhttppp::HttpRequest &curreq){ void libhttppp::HttpAuth::setAuth(libhttppp::HttpResponse &curresp){ HttpHeader::HeaderData *dat=curresp.setHeaderData("www-authenticate"); // switch(_Authtype){ // case BASICAUTH:{ // if(_Realm){ // *dat << "basic realm=\"" << _Realm << "\""; // }else{ // *dat << "basic"; // } // }; // case DIGESTAUTH:{ // *dat << "digest"; // if(_Realm){ // *dat << " realm=\"" << _Realm <<"\""; // } // char nonce[16]={'0'}; // for(size_t noncepos=0; noncepos<=16; noncepos++){ // char random[]={1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f','\0'}; // for(size_t rdpos=0; random[rdpos]!='\0'; rdpos++){ // nonce[noncepos]=random[rdpos]; // } // } // *dat << "nonce=\"" << nonce << "\""; // }; // } HttpHeader::HeaderData::Values authval; switch(_Authtype){ case BASICAUTH:{ if(!_Realm.empty()){ authval << "basic realm=\"" << _Realm << "\""; }else{ authval << "basic"; } }; case DIGESTAUTH:{ authval << "digest"; if(!_Realm.empty()){ authval << " realm=\"" << _Realm <<"\""; } char nonce[16]={'0'}; for(size_t noncepos=0; noncepos<=16; noncepos++){ char random[]={1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f','\0'}; for(size_t rdpos=0; random[rdpos]!='\0'; rdpos++){ nonce[noncepos]=random[rdpos]; } } authval << "nonce=\"" << nonce << "\""; }; } dat->push_back(authval); } void libhttppp::HttpAuth::setAuthType(int authtype){ Loading
src/http.h +5 −1 Changes for src/http.h: 5 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -102,6 +102,7 @@ namespace libhttppp { Values &operator=(const std::string &val); Values &operator=(size_t val); Values &operator=(int val); Values& operator=(const Values &val); Values &operator<<(const std::string &value); Values &operator<<(size_t value); Loading @@ -114,10 +115,12 @@ namespace libhttppp { Values *nextvalue(); Values(const char *value); Values(const std::string& val); Values(const Values& val); Values()=default; ~Values() = default; private: std::string _value; std::unique_ptr<Values> _nextvalue; std::unique_ptr<Values> _nextvalue=nullptr; friend class HeaderData; }; Loading @@ -125,6 +128,7 @@ namespace libhttppp { Values &at(int pos); Values &operator[](int pos); void push_back(const Values &val); void push_back(const std::string &val); void push_back(const char* val); void push_back(size_t val); Loading