--- parser3/src/classes/curl.C 2016/07/26 13:20:23 1.38 +++ parser3/src/classes/curl.C 2016/10/04 13:23:45 1.44 @@ -17,7 +17,7 @@ #include "pa_http.h" #include "ltdl.h" -volatile const char * IDENT_CURL_C="$Id: curl.C,v 1.38 2016/07/26 13:20:23 moko Exp $"; +volatile const char * IDENT_CURL_C="$Id: curl.C,v 1.44 2016/10/04 13:23:45 moko Exp $"; class MCurl: public Methoded { public: @@ -71,14 +71,18 @@ static const char *dlink(const char *dlo class ParserOptions { public: + // real options const String *filename; const String *content_type; bool is_text; Charset *charset, *response_charset; + + // stuff for internal use + const char *url; struct curl_httppost *f_post; FILE *f_stderr; - ParserOptions() : filename(0), content_type(0), is_text(true), charset(0), response_charset(0), f_post(0), f_stderr(0){} + ParserOptions() : filename(0), content_type(0), is_text(true), charset(0), response_charset(0), url(0), f_post(0), f_stderr(0){} ~ParserOptions() { f_curl_formfree(f_post); if(f_stderr) @@ -123,17 +127,15 @@ public: }; bool curl_linked = false; -const char *curl_library="libcurl" LT_MODULE_EXT; - const char *curl_status = 0; +const char *curl_library="libcurl" LT_MODULE_EXT; static void temp_curl(void (*action)(Request&, MethodParams&), Request& r, MethodParams& params){ - if(!curl_linked){ - curl_linked=true; + if(!curl_linked) curl_status=dlink(curl_library); - } if(curl_status == 0){ + curl_linked=true; Temp_curl temp_curl; action(r,params); } else { @@ -274,6 +276,7 @@ public: CURL_OPT(CURL_INT, SSL_VERIFYHOST); CURL_OPT(CURL_STRING, SSL_CIPHER_LIST); CURL_OPT(CURL_INT, SSL_SESSIONID_CACHE); + CURL_OPT(CURL_INT, SSLVERSION); PARSER_OPT(PARSER_LIBRARY, "library"); PARSER_OPT(PARSER_NAME, "name"); @@ -407,7 +410,7 @@ static void curl_setopt(HashStringValue: throw Exception("curl", 0, "called with invalid option '%s'", key.cstr()); CURLcode res = CURLE_OK; - Value &v=r.process_to_value(*value); + Value &v=r.process(*value); switch (opt->type){ case CurlOption::CURL_STRING:{ @@ -427,8 +430,8 @@ static void curl_setopt(HashStringValue: const String url = v.as_string(); if(!url.starts_with("http://") && !url.starts_with("https://")) throw Exception("curl", 0, "failed to set option '%s': invalid url scheme '%s'", key.cstr(), url.cstr()); - const char *value_str=curl_urlencode(url, r); - res=f_curl_easy_setopt(curl(), opt->id, value_str); + options().url=curl_urlencode(url, r); + res=f_curl_easy_setopt(curl(), opt->id, options().url); break; } case CurlOption::CURL_INT:{ @@ -487,7 +490,7 @@ static void curl_setopt(HashStringValue: } case CurlOption::PARSER_LIBRARY:{ // 'library' parser option - if(fcurl==0){ + if(!curl_linked){ curl_library=v.as_string().taint_cstr(String::L_FILE_SPEC); } else throw Exception("curl", 0, "failed to set option '%s': already loaded", key.cstr()); @@ -514,7 +517,7 @@ static void curl_setopt(HashStringValue: } case CurlOption::PARSER_RESPONSE_CHARSET:{ // 'response-charset' parser option - options().response_charset=&::charsets.get(v.as_string().change_case(r.charsets.source(), String::CC_UPPER)); + options().response_charset=&pa_charsets.get(v.as_string()); break; } } @@ -530,8 +533,8 @@ static void _curl_options(Request& r, Me if(HashStringValue* options_hash=params.as_hash(0)){ if(Value* value=options_hash->get("charset")){ // charset should be handled first as params may require transcode - Value &v=r.process_to_value(*value); - options().charset=&::charsets.get(v.as_string().change_case(r.charsets.source(), String::CC_UPPER)); + Value &v=r.process(*value); + options().charset=&pa_charsets.get(v.as_string()); } options_hash->for_each(curl_setopt, r); } @@ -671,7 +674,7 @@ static void _curl_load_action(Request& r asked_charset=detect_charset(response.content_type.cstr()); if(options().is_text) - asked_charset=charsets.checkBOM(body.buf, body.length, asked_charset); + asked_charset=pa_charsets.checkBOM(body.buf, body.length, asked_charset); if (!asked_charset) asked_charset = options().charset; @@ -683,8 +686,9 @@ static void _curl_load_action(Request& r } const String *content_type = PA_DEFAULT(options().content_type, response.content_type.is_empty() ? 0 : new String(response.content_type, String::L_TAINTED)); + const String *filename = PA_DEFAULT(options().filename, new String(options().url)); - result.set(true/*tainted*/, options().is_text, body.buf, body.length, options().filename, content_type ? new VString(*content_type) : 0, &r); + result.set(true/*tainted*/, options().is_text, body.buf, body.length, filename, content_type ? new VString(*content_type) : 0, &r); long http_status = 0; if(f_curl_easy_getinfo(curl(), CURLINFO_RESPONSE_CODE, &http_status) == CURLE_OK){