--- parser3/src/classes/curl.C 2012/03/16 09:24:06 1.13 +++ parser3/src/classes/curl.C 2012/04/20 20:25:47 1.17 @@ -6,8 +6,6 @@ #include "pa_config_includes.h" -#ifdef HAVE_CURL - #include "pa_vmethod_frame.h" #include "pa_request.h" #include "pa_vfile.h" @@ -18,7 +16,7 @@ #include "pa_http.h" #include "ltdl.h" -volatile const char * IDENT_CURL_C="$Id: curl.C,v 1.13 2012/03/16 09:24:06 moko Exp $"; +volatile const char * IDENT_CURL_C="$Id: curl.C,v 1.17 2012/04/20 20:25:47 moko Exp $"; class MCurl: public Methoded { public: @@ -45,7 +43,7 @@ typedef void (*t_curl_formfree)(struct c #define GLINK(name) f_##name=(t_##name)lt_dlsym(handle, #name); #define DLINK(name) GLINK(name) if(!f_##name) return "function " #name " was not found"; -const char *dlink(const char *dlopen_file_spec) { +static const char *dlink(const char *dlopen_file_spec) { if(lt_dlinit()) return lt_dlerror(); @@ -78,10 +76,13 @@ public: bool is_text; Charset *charset, *response_charset; 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() { f_curl_formfree(f_post); + if(stderr) + fclose(stderr); } }; @@ -186,6 +187,7 @@ public: CURL_FORM, CURL_HEADERS, CURL_FILE, + CURL_STDERR, PARSER_LIBRARY, PARSER_NAME, PARSER_CONTENT_TYPE, @@ -209,13 +211,15 @@ public: CURL_OPT(CURL_INT, LOCALPORT); 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_STRING, USERPWD); -#ifdef CURLOPT_USERNAME CURL_OPT(CURL_STRING, USERNAME); CURL_OPT(CURL_STRING, PASSWORD); -#endif CURL_OPT(CURL_URLENCODE, USERAGENT); CURL_OPT(CURL_URLENCODE, REFERER); @@ -243,9 +247,7 @@ public: CURL_OPT(CURL_INT, HTTP_TRANSFER_DECODING); CURL_OPT(CURL_INT, MAXREDIRS); -#ifdef CURLOPT_POSTREDIR CURL_OPT(CURL_INT, POSTREDIR); -#endif CURL_OPT(CURL_STRING, RANGE); @@ -276,13 +278,8 @@ public: CURL_OPT(CURL_STRING, SSLENGINE); CURL_OPT(CURL_STRING, SSLENGINE_DEFAULT); -#ifdef CURLOPT_ISSUERCERT CURL_OPT(CURL_FILE, ISSUERCERT); -#endif - -#ifdef CURLOPT_CRLFILE CURL_OPT(CURL_FILE, CRLFILE); -#endif CURL_OPT(CURL_STRING, CAINFO); CURL_OPT(CURL_STRING, CAPATH); @@ -417,7 +414,7 @@ static void curl_setopt(HashStringValue: f_curl_formfree(options().f_post); options().f_post = 0; } 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); break; @@ -434,12 +431,23 @@ static void curl_setopt(HashStringValue: res=f_curl_easy_setopt(curl(), opt->id, value_str); break; } + case CurlOption::CURL_STDERR:{ + // verbose output redirection from stderr to file curl option + const char *value_str=r.absolute(v.as_string()).taint_cstr(String::L_FILE_SPEC); + FILE *stderr=options().stderr=fopen(value_str, "at"); + 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(), value_str); + } + break; + } case CurlOption::PARSER_LIBRARY:{ // 'library' parser option if(fcurl==0){ curl_library=v.as_string().taint_cstr(String::L_FILE_SPEC); } 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; } case CurlOption::PARSER_NAME:{ @@ -546,7 +554,7 @@ static void _curl_load_action(Request& r CURL_SETOPT(CURLOPT_WRITEHEADER, &headers, "curl header buffer"); if((res=f_curl_easy_perform(curl())) != CURLE_OK){ - char *ex_type = 0; + const char *ex_type = 0; switch(res){ case CURLE_OPERATION_TIMEDOUT: ex_type = "curl.timeout"; break; @@ -618,11 +626,3 @@ MCurl::MCurl(): Methoded("curl") { add_native_method("options", Method::CT_STATIC, _curl_options, 1, 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