Diff for /parser3/src/classes/curl.C between versions 1.14 and 1.18

version 1.14, 2012/03/19 21:28:43 version 1.18, 2012/04/22 20:03:02
Line 6 Line 6
   
 #include "pa_config_includes.h"  #include "pa_config_includes.h"
   
 #ifdef HAVE_CURL  
   
 #include "pa_vmethod_frame.h"  #include "pa_vmethod_frame.h"
 #include "pa_request.h"  #include "pa_request.h"
 #include "pa_vfile.h"  #include "pa_vfile.h"
Line 78  public: Line 76  public:
         bool is_text;          bool is_text;
         Charset *charset, *response_charset;          Charset *charset, *response_charset;
         struct curl_httppost *f_post;          struct curl_httppost *f_post;
           FILE *stderr;
   
         ParserOptions() : filename(0), content_type(0), is_text(true), charset(0), response_charset(0), f_post(0){}          ParserOptions() : filename(0), content_type(0), is_text(true), charset(0), response_charset(0), f_post(0), stderr(0){}
         ~ParserOptions() {          ~ParserOptions() {
                 f_curl_formfree(f_post);                  f_curl_formfree(f_post);
                   if(stderr)
                           fclose(stderr);
         }          }
                     
 };  };
Line 186  public: Line 187  public:
                 CURL_FORM,                  CURL_FORM,
                 CURL_HEADERS,                  CURL_HEADERS,
                 CURL_FILE,                  CURL_FILE,
                   CURL_STDERR,
                 PARSER_LIBRARY,                  PARSER_LIBRARY,
                 PARSER_NAME,                  PARSER_NAME,
                 PARSER_CONTENT_TYPE,                  PARSER_CONTENT_TYPE,
Line 209  public: Line 211  public:
                 CURL_OPT(CURL_INT, LOCALPORT);                  CURL_OPT(CURL_INT, LOCALPORT);
                 CURL_OPT(CURL_INT, PORT);                  CURL_OPT(CURL_INT, PORT);
                                   
                   CURL_OPT(CURL_INT, VERBOSE);
                   CURL_OPT(CURL_STDERR, STDERR);
                   CURL_OPT(CURL_INT, MAXFILESIZE);
                   
                 CURL_OPT(CURL_INT, HTTPAUTH);                  CURL_OPT(CURL_INT, HTTPAUTH);
                 CURL_OPT(CURL_STRING, USERPWD);                  CURL_OPT(CURL_STRING, USERPWD);
   
 #ifdef CURLOPT_USERNAME  
                 CURL_OPT(CURL_STRING, USERNAME);                  CURL_OPT(CURL_STRING, USERNAME);
                 CURL_OPT(CURL_STRING, PASSWORD);                  CURL_OPT(CURL_STRING, PASSWORD);
 #endif  
   
                 CURL_OPT(CURL_URLENCODE, USERAGENT);                  CURL_OPT(CURL_URLENCODE, USERAGENT);
                 CURL_OPT(CURL_URLENCODE, REFERER);                  CURL_OPT(CURL_URLENCODE, REFERER);
Line 243  public: Line 247  public:
                 CURL_OPT(CURL_INT, HTTP_TRANSFER_DECODING);                  CURL_OPT(CURL_INT, HTTP_TRANSFER_DECODING);
   
                 CURL_OPT(CURL_INT, MAXREDIRS);                  CURL_OPT(CURL_INT, MAXREDIRS);
 #ifdef CURLOPT_POSTREDIR  
                 CURL_OPT(CURL_INT, POSTREDIR);                  CURL_OPT(CURL_INT, POSTREDIR);
 #endif  
   
                 CURL_OPT(CURL_STRING, RANGE);                  CURL_OPT(CURL_STRING, RANGE);
   
Line 276  public: Line 278  public:
                 CURL_OPT(CURL_STRING, SSLENGINE);                  CURL_OPT(CURL_STRING, SSLENGINE);
                 CURL_OPT(CURL_STRING, SSLENGINE_DEFAULT);                  CURL_OPT(CURL_STRING, SSLENGINE_DEFAULT);
   
 #ifdef CURLOPT_ISSUERCERT  
                 CURL_OPT(CURL_FILE, ISSUERCERT);                  CURL_OPT(CURL_FILE, ISSUERCERT);
 #endif  
   
 #ifdef CURLOPT_CRLFILE  
                 CURL_OPT(CURL_FILE, CRLFILE);                  CURL_OPT(CURL_FILE, CRLFILE);
 #endif  
   
                 CURL_OPT(CURL_STRING, CAINFO);                  CURL_OPT(CURL_STRING, CAINFO);
                 CURL_OPT(CURL_STRING, CAPATH);                  CURL_OPT(CURL_FILE, CAPATH);
                 CURL_OPT(CURL_INT, SSL_VERIFYPEER);                  CURL_OPT(CURL_INT, SSL_VERIFYPEER);
                 CURL_OPT(CURL_INT, SSL_VERIFYHOST);                  CURL_OPT(CURL_INT, SSL_VERIFYHOST);
                 CURL_OPT(CURL_STRING, SSL_CIPHER_LIST);                  CURL_OPT(CURL_STRING, SSL_CIPHER_LIST);
Line 360  static void curl_form(HashStringValue *v Line 357  static void curl_form(HashStringValue *v
         }          }
 }  }
   
   static const char *curl_check_file(const String &file_spec){
           const char *file_spec_cstr=file_spec.taint_cstr(String::L_FILE_SPEC);
           struct stat finfo;
           if(stat(file_spec_cstr, &finfo)==0)
                   check_safe_mode(finfo, file_spec, file_spec_cstr);
           return file_spec_cstr;
   }
   
 static void curl_setopt(HashStringValue::key_type key, HashStringValue::value_type value, Request& r) {  static void curl_setopt(HashStringValue::key_type key, HashStringValue::value_type value, Request& r) {
         CurlOption *opt=curl_options->get(key);          CurlOption *opt=curl_options->get(key);
   
Line 417  static void curl_setopt(HashStringValue: Line 422  static void curl_setopt(HashStringValue:
                                 f_curl_formfree(options().f_post);                                  f_curl_formfree(options().f_post);
                                 options().f_post = 0;                                  options().f_post = 0;
                         } else {                          } else {
                                 throw Exception("curl", 0, "%s must be a hash", key.cstr());                                  throw Exception("curl", 0, "failed to set option '%s': value must be a hash", key.cstr());
                         }                          }
                         res=f_curl_easy_setopt(curl(), CURLOPT_HTTPPOST, foptions->f_post);                          res=f_curl_easy_setopt(curl(), CURLOPT_HTTPPOST, foptions->f_post);
                         break;                          break;
Line 430  static void curl_setopt(HashStringValue: Line 435  static void curl_setopt(HashStringValue:
                 }                  }
                 case CurlOption::CURL_FILE:{                  case CurlOption::CURL_FILE:{
                         // file-spec curl option                          // file-spec curl option
                         const char *value_str=r.absolute(v.as_string()).taint_cstr(String::L_FILE_SPEC);                          const char *file_spec_cstr=curl_check_file(r.absolute(v.as_string()));
                         res=f_curl_easy_setopt(curl(), opt->id, value_str);                          res=f_curl_easy_setopt(curl(), opt->id, file_spec_cstr);
                           break;
                   }
                   case CurlOption::CURL_STDERR:{
                           // verbose output redirection from stderr to file curl option
                           const char *file_spec_cstr=curl_check_file(r.absolute(v.as_string()));
                           FILE *stderr=options().stderr=fopen(file_spec_cstr, "wt");
                           if (stderr){
                                   res=f_curl_easy_setopt(curl(), opt->id, stderr);
                           } else {
                                   throw Exception("curl", 0, "failed to set option '%s': unable to open file '%s'", key.cstr(), file_spec_cstr);
                           }
                         break;                          break;
                 }                  }
                 case CurlOption::PARSER_LIBRARY:{                  case CurlOption::PARSER_LIBRARY:{
Line 439  static void curl_setopt(HashStringValue: Line 455  static void curl_setopt(HashStringValue:
                         if(fcurl==0){                          if(fcurl==0){
                                 curl_library=v.as_string().taint_cstr(String::L_FILE_SPEC);                                  curl_library=v.as_string().taint_cstr(String::L_FILE_SPEC);
                         } else                           } else 
                                 throw Exception("curl", 0, "failed to set option '%s': %s", key.cstr(), "already loaded");                                  throw Exception("curl", 0, "failed to set option '%s': already loaded", key.cstr());
                         break;                          break;
                 }                  }
                 case CurlOption::PARSER_NAME:{                  case CurlOption::PARSER_NAME:{
Line 546  static void _curl_load_action(Request& r Line 562  static void _curl_load_action(Request& r
         CURL_SETOPT(CURLOPT_WRITEHEADER, &headers, "curl header buffer");          CURL_SETOPT(CURLOPT_WRITEHEADER, &headers, "curl header buffer");
   
         if((res=f_curl_easy_perform(curl())) != CURLE_OK){          if((res=f_curl_easy_perform(curl())) != CURLE_OK){
                 char *ex_type = 0;                   const char *ex_type = 0; 
                 switch(res){                  switch(res){
                         case CURLE_OPERATION_TIMEDOUT:                          case CURLE_OPERATION_TIMEDOUT:
                                 ex_type = "curl.timeout"; break;                                  ex_type = "curl.timeout"; break;
Line 618  MCurl::MCurl(): Methoded("curl") { Line 634  MCurl::MCurl(): Methoded("curl") {
         add_native_method("options", Method::CT_STATIC, _curl_options, 1, 1);          add_native_method("options", Method::CT_STATIC, _curl_options, 1, 1);
         add_native_method("load", Method::CT_STATIC, _curl_load, 0, 1);          add_native_method("load", Method::CT_STATIC, _curl_load, 0, 1);
 }  }
   
 #else // HAVE_CURL  
   
 #include "classes.h"  
 // global variable  
 DECLARE_CLASS_VAR(curl, 0, 0); // fictive  
   
 #endif // HAVE_CURL  

Removed from v.1.14  
changed lines
  Added in v.1.18


E-mail: