--- parser3/src/classes/curl.C 2015/10/09 15:43:52 1.32 +++ parser3/src/classes/curl.C 2016/05/12 19:44:49 1.37 @@ -1,7 +1,7 @@ /** @file Parser: @b curl parser class. - Copyright (c) 2001-2012 Art. Lebedev Studio (http://www.artlebedev.com) + Copyright (c) 2001-2015 Art. Lebedev Studio (http://www.artlebedev.com) */ #include "pa_config_includes.h" @@ -17,7 +17,7 @@ #include "pa_http.h" #include "ltdl.h" -volatile const char * IDENT_CURL_C="$Id: curl.C,v 1.32 2015/10/09 15:43:52 moko Exp $"; +volatile const char * IDENT_CURL_C="$Id: curl.C,v 1.37 2016/05/12 19:44:49 moko Exp $"; class MCurl: public Methoded { public: @@ -26,7 +26,7 @@ public: // global variables -DECLARE_CLASS_VAR(curl, new MCurl, 0); +DECLARE_CLASS_VAR(curl, new MCurl); #include "curl.h" @@ -556,10 +556,8 @@ static void _curl_options(Request& r, Me throw Exception("curl", 0, "failed to get %s info: %s", key.cstr(), f_curl_easy_strerror(res)); \ } -static Value *curl_getinfo(const String::Body &key) { - CurlInfo *info=curl_infos->get(key); - - if(info==0) +static Value *curl_getinfo(const String::Body &key, CurlInfo *info=0) { + if(info==0 && !(info=curl_infos->get(key))) throw Exception("curl", 0, "called with invalid parameter '%s'", key.cstr()); CURLcode res; @@ -567,7 +565,7 @@ static Value *curl_getinfo(const String: case CurlInfo::CURL_STRING:{ char *str=0; CURL_GETINFO(str); - return new VString(*new String(str, String::L_TAINTED)); + return new VString(str ? *new String(pa_strdup(str), String::L_TAINTED) : String::Empty); } case CurlInfo::CURL_INT:{ long l=0; @@ -592,7 +590,7 @@ static void _curl_info(Request& r, Metho } else { VHash& result=*new VHash; for(CurlInfoHash::Iterator i(*curl_infos); i; i.next() ){ - result.get_hash()->put(i.key(), curl_getinfo(i.key())); + result.get_hash()->put(i.key(), curl_getinfo(i.key(), i.value())); } r.write_no_lang(result); } @@ -696,10 +694,10 @@ static void _curl_load_action(Request& r VFile& result=*new VFile; - String::Body ct_header = response.headers.get(HTTP_CONTENT_TYPE_UPPER); + String::Body ct_header = String::Body(response.headers.get(HTTP_CONTENT_TYPE_UPPER)).trim(String::TRIM_BOTH, " \t\n\r"); Charset *asked_charset = options().response_charset; if (asked_charset == 0){ - Charset *remote_charset = ct_header.is_empty() ? 0 : detect_charset(ct_header.trim(String::TRIM_BOTH, " \t\n\r").cstr()); + Charset *remote_charset = ct_header.is_empty() ? 0 : detect_charset(ct_header.cstr()); asked_charset = remote_charset ? remote_charset : options().charset; } @@ -709,8 +707,8 @@ static void _curl_load_action(Request& r body.length=c.length; } - result.set(true/*tainted*/, options().is_text, body.buf, body.length, options().filename - , options().content_type ? new VString(*options().content_type) : 0, &r); + result.set(true/*tainted*/, options().is_text, body.buf, body.length, options().filename, + options().content_type ? new VString(*options().content_type) : ct_header.is_empty() ? 0 : new VString(*new String(ct_header, String::L_TAINTED)), &r); long http_status = 0; if(f_curl_easy_getinfo(curl(), CURLINFO_RESPONSE_CODE, &http_status) == CURLE_OK){ result.fields().put("status", new VInt(http_status));