Commit 124c864a authored by jan.koester's avatar jan.koester
Browse files

easier

parent f3150af1
Loading
Loading
Loading
Loading
+5 −113
Changes for plugins/youtube/youtube.cpp: 5 added lines, 113 removed lines.
Original line number Diff line number Diff line
@@ -122,7 +122,7 @@ namespace blogi {
        }

        void SyncYoutube(const int tid,int channel_id,libhtmlpp::HtmlString &out){
            std::string json;
            std::vector<char> json;
            libhttppp::HttpResponse res;
            size_t hsize=0;
            int cpos=0;
@@ -146,8 +146,7 @@ namespace blogi {
                netplus::x509cert ycert;
                ycert.loadFromBuffer(ycert.pemCertToDer(GOOGLECA));
                libhttppp::HttpUrl yurl("hhtps://www.googleapis.com");
                std::unique_ptr<netplus::socket> ycsock=std::make_unique<netplus::ssl>(ycert);

                libhttppp::HttpClient clt(yurl);
             //   ycsock->setTimeout(10);

                libhttppp::HttpRequest nreq;
@@ -160,126 +159,19 @@ namespace blogi {
                nreq.setHeaderData("host")->push_back("www.googleapis.com:443");
                nreq.setHeaderData("accept")->push_back("text/json");
                nreq.setHeaderData("user-agent")->push_back("blogi/1.0 (Alpha Version 0.1)");
                nreq.send(yurl,ycsock);


                int recv,chunklen=0;
                netplus::buffer data(BLOCKSIZE);

                try{
                    for(;;){
                        try{

                            recv=ycsock->recvData(data,0);
                            break;
                        }catch(netplus::NetException &re){
                            if(re.getErrorType()!=netplus::NetException::Note)
                                throw re;
                            else
                                continue;
                        }
                    }
                }catch(netplus::NetException &e){
                    libhttppp::HTTPException he;
                    he[libhttppp::HTTPException::Error] << e.what();
                    throw he;
                }

                hsize=res.parse(data.data.buf,recv);

                recv-=hsize;

                memmove(data.data.buf,data.data.buf+hsize,recv);

                cpos=0;

                try{
                    for(libhttppp::HttpHeader::HeaderData::Values *chdat=res.getTransferEncoding(); chdat; chdat=chdat->nextvalue()){
                        if(chdat->getvalue()=="chunked")
                            chunked=true;
                    }
                    if(!chunked)
                        throw "e";
                }catch(...){
                    rlen=res.getContentLength();
                    json.resize(rlen);
                }

                if(!chunked){
                    do{
                        try{
                            json.append(data.data.buf+cpos,recv);
                            rlen-=recv;
                            if(rlen>0){
                                for(;;){
                                    cpos=0;
                                    for(;;){
                                        try{
                                            recv=ycsock->recvData(data,0);
                                            break;
                                        }catch(netplus::NetException &re){
                                            if(re.getErrorType()!=netplus::NetException::Note)
                                                throw re;
                                            else
                                                continue;
                                        }
                                    }
                                }
                            }
                json=clt.Get(nreq);
            }catch(netplus::NetException &e){
                libhttppp::HTTPException ee;
                ee[libhttppp::HTTPException::Error] << e.what();
                throw ee;
            }
                    }while(rlen>0);
                }else{

                    int readed=0;

                    for(;;){
                        if(recv - cpos > 0){

                            if(readed==chunklen){
                                if( (chunklen=readchunk(data.data.buf,recv,cpos)) == 0 ){
                                    break;
                                }
                                readed=0;
                            }

                            int len = (chunklen - readed) < (recv - cpos) ? (chunklen - readed)  : (recv - cpos);

                            json.append(data.data.buf+cpos,len);
                            cpos+=len;
                            readed+=len;
                        }else{
                            cpos=0;
                            for(;;){
                                try{
                                    recv=ycsock->recvData(data,0);
                                    break;
                                }catch(netplus::NetException &e){
                                    if(e.getErrorType()!=netplus::NetException::Note){
                                        libhttppp::HTTPException ee;
                                        ee[libhttppp::HTTPException::Error] << e.what();
                                        throw ee;
                                    }else{
                                        continue;
                                    }
                                }
                            }
                        }
                    };
                }
            }catch(netplus::NetException &e){
                libhttppp::HTTPException ee;
                ee[libhttppp::HTTPException::Error] << e.what();
                throw ee;
            }
            json.push_back('\0');

            libhtmlpp::HtmlElement youmain("ul");

            struct json_object *youindex;
            youindex = json_tokener_parse(json.c_str());
            youindex = json_tokener_parse(json.data());

            if(!youindex){
                libhttppp::HTTPException e;