Commit 2741d80b authored by jan.koester's avatar jan.koester
Browse files

new allocator planned for libnetplus

parent d5b04f42
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -81,10 +81,10 @@ size_t readchunk(const char *data,size_t datasize,size_t &pos){

int main(int argc, char** argv){
  signal(SIGPIPE, SIG_IGN);
  std::shared_ptr<netplus::tcp> cltsock=std::make_shared<netplus::tcp>();
  std::shared_ptr<netplus::tcp> srvsock=std::make_shared<netplus::tcp>(argv[1],atoi(argv[2]),1,0);
  netplus::tcp cltsock;
  netplus::tcp srvsock(argv[1],atoi(argv[2]),1,0);
  try{
    srvsock->connect(cltsock);
    srvsock.connect(&cltsock);

    try{
      libhttppp::HttpRequest req;
@@ -95,14 +95,14 @@ int main(int argc, char** argv){
      *req.setData("host") << argv[1] << ":" << argv[2];
      *req.setData("accept") << "text/html";
      *req.setData("user-agent") << "libhttppp/1.0 (Alpha Version 0.1)";
      req.send(cltsock,srvsock);
      req.send(&cltsock,&srvsock);
    }catch(libhttppp::HTTPException &e){
      std::cerr << e.what() << std::endl;
      return -1;
    }

    char data[16384];
    size_t recv=srvsock->recvData(cltsock,data,16384);
    size_t recv=srvsock.recvData(&cltsock,data,16384);

    std::string html;
    libhttppp::HttpResponse res;
@@ -128,7 +128,7 @@ int main(int argc, char** argv){
        html.append(data+hsize,recv-hsize);
        rlen-=recv-hsize;
        if(rlen>0){
          recv=srvsock->recvData(cltsock,data,16384);
          recv=srvsock.recvData(&cltsock,data,16384);
          hsize=0;
        }
      }while(rlen>0);
+1 −0
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ public:
    try {
        Controller controller(getServerSocket());
        controller.runEventloop();
        std::cout << "noe" << std::endl;
    }catch(netplus::NetException &e){
        httpexception[libhttppp::HTTPException::Critical] << e.what();
        throw httpexception;
+10 −13
Original line number Diff line number Diff line
@@ -200,7 +200,6 @@ libhttppp::HttpHeader::HeaderData::HeaderData(const char *key){
}

libhttppp::HttpHeader::HeaderData::~HeaderData(){
  delete _nextHeaderData;
}

libhttppp::HttpHeader::~HttpHeader(){
@@ -310,7 +309,6 @@ void libhttppp::HttpResponse::send(netplus::con* curconnection,const char* data,

  if(datalen>0)
    curconnection->SendData.append(data,datalen);
  curconnection->sending(true);
}

size_t libhttppp::HttpResponse::parse(const char *data,size_t inlen){
@@ -462,7 +460,7 @@ void libhttppp::HttpRequest::clear(){
  _RequestVersion.clear();
}


#include <iostream>

size_t libhttppp::HttpRequest::parse(){
  HTTPException excep;
@@ -470,7 +468,6 @@ size_t libhttppp::HttpRequest::parse(){
  std::vector<char> header;

  try{

    size_t startpos=0;

    if((startpos=RecvData.search("GET"))!=std::string::npos){
@@ -496,6 +493,8 @@ size_t libhttppp::HttpRequest::parse(){
    int pos=0;
    endpos+=4;

    std::move(RecvData.begin()+endpos,RecvData.end(),RecvData.begin());

    for(size_t cpos=pos; cpos< header.size(); ++cpos){
      if(header[cpos]==' '){
        pos=++cpos;
@@ -567,8 +566,6 @@ size_t libhttppp::HttpRequest::parse(){
        startkeypos=lrow+2;
      }
    }
    RecvData.resize(endpos);

  }catch(netplus::NetException &e){
    if (e.getErrorType() != netplus::NetException::Note) {
        RecvData.clear();
@@ -662,7 +659,7 @@ void libhttppp::HttpRequest::setRequestVersion(const char* version){
}


void libhttppp::HttpRequest::send(std::shared_ptr<netplus::socket> src,std::shared_ptr<netplus::socket> dest){
void libhttppp::HttpRequest::send(netplus::socket* src,netplus::socket* dest){
  std::string header;
  printHeader(header);

@@ -1141,7 +1138,7 @@ void libhttppp::HttpForm::_parseUrlDecode(const std::vector<char> &data){
  size_t fdatstpos=0;
  size_t keyendpos=0;
  for(size_t fdatpos=0; fdatpos<=data.size(); fdatpos++){
    if(data[fdatpos] == '&' || fdatpos==data.size()){
    if(data.at(fdatpos) == '&' || fdatpos==data.size()){
      if(keyendpos >fdatstpos && keyendpos<fdatpos){
        std::vector<char> key,ukey;;
        size_t vlstpos=keyendpos+1;
@@ -1159,7 +1156,7 @@ void libhttppp::HttpForm::_parseUrlDecode(const std::vector<char> &data){
        UrlFormData.addFormData(urldat);
      }
      fdatstpos=fdatpos+1;
    }else if( data[fdatpos] == '=' ){
    }else if( data.at(fdatpos) == '=' ){
      keyendpos=fdatpos;
    };
  }
+1 −2
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <stddef.h>
#include <sys/types.h>

#include <memory>
#include <vector>
#include <string>

@@ -157,7 +156,7 @@ namespace libhttppp {
    void              setRequestData(const char *data,size_t len);
    void              setMaxUploadSize(size_t upsize);

    void              send(std::shared_ptr<netplus::socket> src,std::shared_ptr<netplus::socket> dest);
    void              send(netplus::socket *src,netplus::socket *dest);

  private:
    std::string       _Request;
+4 −3
Original line number Diff line number Diff line
@@ -68,10 +68,11 @@ void libhttppp::HttpEvent::DisconnectEvent(HttpRequest *curreq){
void libhttppp::HttpEvent::RequestEvent(netplus::con* curcon){
    HttpRequest *cureq =(HttpRequest*)curcon;
    try{
        if(cureq->getRequestType()==0)
            cureq->parse();

REQUESTHANDLING:
        switch(cureq->getRequestType()){
            case 0:
                cureq->parse();
                goto REQUESTHANDLING;
            case GETREQUEST:
                RequestEvent(cureq);
                cureq->clear();