void Browser::open_novisit(std::string url, int usertimeout=20) { timeout = usertimeout; assert(timeout>0); //set the url in the options curl_easy_setopt(curl, CURLOPT_URL, url.c_str() ); //Handle the response if(writing_bytes==false) { addheaders("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); addheaders("Connection" ,"keep-alive"); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_to_string ); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &html_response); curl_easy_setopt(curl, CURLOPT_WRITEHEADER, &header_); } else { assert(filepipe!=NULL); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); curl_easy_setopt(curl, CURLOPT_WRITEDATA, filepipe); } curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout ); res = curl_easy_perform(curl); if(error()) { std::cerr<<"\n"; } if(writing_bytes==true) { fclose(filepipe); writing_bytes=false; } }
void Browser::open(std::string url, int usertimeout,std::string post_data) { init(); timeout = usertimeout; assert(timeout>0); //set the url in the options curl_easy_setopt(curl, CURLOPT_URL, url.c_str() ); //and set it as the options for curl curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post_data.c_str()); //Handle the response if(writing_bytes==false) { addheaders("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); addheaders("Connection" ,"keep-alive"); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_to_string ); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &html_response); curl_easy_setopt(curl, CURLOPT_WRITEHEADER, &header_); } else { assert(filepipe!=NULL); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); curl_easy_setopt(curl, CURLOPT_WRITEDATA, filepipe); } curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout ); res = curl_easy_perform(curl); if(error()) { std::cerr<<"\n===============================================\n"; } if(writing_bytes==true) fclose(filepipe); //because we don't want to parse bytes for forms else { if(fetching_forms == true) forms.initialize(html_response); if(fetching_links == true) { links.getlinks(html_response); emails.init(links); } } history_.push_back(geturl()); }
int writecontrolfile(struct letter *let) { FILE *f; char ctrlfile[sizeof(DATAPFX)+6+1]; int count; enum r_status status; /* after writing the data, write the control file */ sprintf(ctrlfile, CTRLPFX "%s", let->qid); if ( (f=fopen(ctrlfile, "w")) != 0) { /* queue comments always come first. */ if (let->qcomment && let->qcomment[0]) fprintf(f, "%c%s\n", C_STATUS, let->qcomment); if (notnull(let->from)) { if (let->from->domain && strlen(let->from->domain) > 0) fprintf(f, "%c%s\n", C_FROM, let->from->full); else fprintf(f, "%c%s@%s\n",C_FROM,let->from->user, let->env->localhost); } for (count=let->remote.count; count-- > 0; ) { status = let->remote.to[count].status; if (status == PENDING || status == ACCEPTED) { fprintf(f, "%c%s|%s\n", C_TO, let->remote.to[count].fullname, let->remote.to[count].host); } } if (let->mesgfrom) fprintf(f, "%cF ;has from:\n", C_FLAGS); /* additional headers ALWAYS come at the end of the * control message so we can cheat and simply spool them * off the disk. */ if ( let->has_headers ) { fprintf(f, "%cH ;has headers\n", C_FLAGS); fprintf(f, "%c%c ;additional headers\n", C_HEADER, C_HEADER); addheaders(f, let); } if ( ferror(f) == 0 && fclose(f) == 0) return 1; syslog(LOG_ERR, "can't write to controlfile: %m"); fclose(f); } syslog(LOG_ERR, "can't save to controlfile: %m"); return 0; }