diff options
-rw-r--r-- | librdfa/curie.c | 2 | ||||
-rw-r--r-- | src/raptor_config_cmake.h.in | 1 | ||||
-rw-r--r-- | src/raptor_grddl.c | 11 | ||||
-rw-r--r-- | src/raptor_internal.h | 2 | ||||
-rw-r--r-- | src/raptor_serialize_rdfxmla.c | 2 | ||||
-rw-r--r-- | src/raptor_www.c | 5 | ||||
-rw-r--r-- | src/raptor_www_curl.c | 132 | ||||
-rw-r--r-- | src/turtle_parser.y | 7 |
8 files changed, 123 insertions, 39 deletions
diff --git a/librdfa/curie.c b/librdfa/curie.c index 704f6b5a..98ee7e0a 100644 --- a/librdfa/curie.c +++ b/librdfa/curie.c @@ -308,7 +308,7 @@ char* rdfa_resolve_uri(rdfacontext* context, const char* uri) sptr++; } - else if(sptr[0] == '.' && sptr[1] == '.' && sptr[1] == '\0') + else if(sptr[0] == '.' && sptr[1] == '.' && sptr[2] == '\0') { /* D. if the input buffer consists only of "..", then remove * that from the input buffer; otherwise, diff --git a/src/raptor_config_cmake.h.in b/src/raptor_config_cmake.h.in index 8e8e57da..2e1582b2 100644 --- a/src/raptor_config_cmake.h.in +++ b/src/raptor_config_cmake.h.in @@ -13,6 +13,7 @@ #cmakedefine HAVE_STDLIB_H #cmakedefine HAVE_STRING_H #cmakedefine HAVE_UNISTD_H +#cmakedefine HAVE_TIME_H #cmakedefine HAVE_SYS_PARAM_H #cmakedefine HAVE_TIME_H #cmakedefine HAVE_SYS_STAT_H diff --git a/src/raptor_grddl.c b/src/raptor_grddl.c index f419164b..b54d8c88 100644 --- a/src/raptor_grddl.c +++ b/src/raptor_grddl.c @@ -927,18 +927,18 @@ raptor_grddl_fetch_uri(raptor_parser* rdf_parser, return 1; if(raptor_www_set_user_agent2(www, "grddl/0.1", 0)) - return 1; + goto cleanup_www; if(flags & FETCH_ACCEPT_XSLT) { if(raptor_www_set_http_accept2(www, "application/xml", 0)) - return 1; + goto cleanup_www; } else { accept_h = raptor_parser_get_accept_header(rdf_parser); if(accept_h) { ret = raptor_www_set_http_accept2(www, accept_h, 0); RAPTOR_FREE(char*, accept_h); if(ret) - return 1; + goto cleanup_www; } } if(rdf_parser->uri_filter) @@ -964,6 +964,11 @@ raptor_grddl_fetch_uri(raptor_parser* rdf_parser, raptor_world_internal_set_ignore_errors(rdf_parser->world, 0); return ret; + +cleanup_www: + raptor_free_www(www); + + return 1; } diff --git a/src/raptor_internal.h b/src/raptor_internal.h index ed5b068d..be8698dc 100644 --- a/src/raptor_internal.h +++ b/src/raptor_internal.h @@ -1052,7 +1052,7 @@ int raptor_www_libxml_fetch(raptor_www *www); void raptor_www_error(raptor_www *www, const char *message, ...) RAPTOR_PRINTF_FORMAT(2, 3); -void raptor_www_curl_init(raptor_www *www); +int raptor_www_curl_init(raptor_www *www); void raptor_www_curl_free(raptor_www *www); int raptor_www_curl_fetch(raptor_www *www); int raptor_www_curl_set_ssl_cert_options(raptor_www* www, const char* cert_filename, const char* cert_type, const char* cert_passphrase); diff --git a/src/raptor_serialize_rdfxmla.c b/src/raptor_serialize_rdfxmla.c index e77f162f..c9fe232e 100644 --- a/src/raptor_serialize_rdfxmla.c +++ b/src/raptor_serialize_rdfxmla.c @@ -593,7 +593,7 @@ raptor_rdfxmla_emit_subject_properties(raptor_serializer* serializer, /* Return error if emitting something failed above */ if(rv) - return rv; + break; raptor_free_xml_element(element); diff --git a/src/raptor_www.c b/src/raptor_www.c index e1808837..26c2fa2f 100644 --- a/src/raptor_www.c +++ b/src/raptor_www.c @@ -136,7 +136,10 @@ raptor_new_www_with_connection(raptor_world* world, void *connection) #ifdef RAPTOR_WWW_LIBCURL www->curl_handle = (CURL*)connection; - raptor_www_curl_init(www); + if(raptor_www_curl_init(www)) { + raptor_free_www(www); + www = NULL; + } #endif #ifdef RAPTOR_WWW_LIBXML raptor_www_libxml_init(www); diff --git a/src/raptor_www_curl.c b/src/raptor_www_curl.c index ea660585..d689f2bd 100644 --- a/src/raptor_www_curl.c +++ b/src/raptor_www_curl.c @@ -157,9 +157,18 @@ raptor_www_curl_header_callback(void* ptr, size_t size, size_t nmemb, } -void +/* Return non-0 on failure */ +int raptor_www_curl_init(raptor_www *www) { + CURLcode res; + +#define curl_init_setopt_or_fail(h, k, v) do { \ + res = curl_easy_setopt(h, k, v); \ + if(res != CURLE_OK) \ + return 1; \ + } while(0) + if(!www->curl_handle) { www->curl_handle = curl_easy_init(); www->curl_init_here = 1; @@ -171,31 +180,34 @@ raptor_www_curl_init(raptor_www *www) #endif /* send all data to this function */ - curl_easy_setopt(www->curl_handle, CURLOPT_WRITEFUNCTION, - raptor_www_curl_write_callback); + curl_init_setopt_or_fail(www->curl_handle, CURLOPT_WRITEFUNCTION, + raptor_www_curl_write_callback); /* ... using this data pointer */ - curl_easy_setopt(www->curl_handle, CURLOPT_WRITEDATA, www); + curl_init_setopt_or_fail(www->curl_handle, CURLOPT_WRITEDATA, www); /* send all headers to this function */ - curl_easy_setopt(www->curl_handle, CURLOPT_HEADERFUNCTION, - raptor_www_curl_header_callback); + curl_init_setopt_or_fail(www->curl_handle, CURLOPT_HEADERFUNCTION, + raptor_www_curl_header_callback); /* ... using this data pointer */ - curl_easy_setopt(www->curl_handle, CURLOPT_WRITEHEADER, www); + curl_init_setopt_or_fail(www->curl_handle, CURLOPT_WRITEHEADER, www); /* Make it follow Location: headers */ - curl_easy_setopt(www->curl_handle, CURLOPT_FOLLOWLOCATION, 1); + curl_init_setopt_or_fail(www->curl_handle, CURLOPT_FOLLOWLOCATION, 1); #if defined(RAPTOR_DEBUG) && RAPTOR_DEBUG > 2 - curl_easy_setopt(www->curl_handle, CURLOPT_VERBOSE, (void*)1); + curl_init_setopt_or_fail(www->curl_handle, CURLOPT_VERBOSE, (void*)1); #endif - curl_easy_setopt(www->curl_handle, CURLOPT_ERRORBUFFER, www->error_buffer); + curl_init_setopt_or_fail(www->curl_handle, CURLOPT_ERRORBUFFER, + www->error_buffer); /* Connection timeout in seconds */ - curl_easy_setopt(www->curl_handle, CURLOPT_CONNECTTIMEOUT, - www->connection_timeout); - curl_easy_setopt(www->curl_handle, CURLOPT_NOSIGNAL, 1); + curl_init_setopt_or_fail(www->curl_handle, CURLOPT_CONNECTTIMEOUT, + www->connection_timeout); + curl_init_setopt_or_fail(www->curl_handle, CURLOPT_NOSIGNAL, 1); + + return 0; } @@ -213,14 +225,27 @@ raptor_www_curl_free(raptor_www *www) int raptor_www_curl_fetch(raptor_www *www) { + CURLcode res = CURLE_OK; struct curl_slist *slist = NULL; - if(www->proxy) - curl_easy_setopt(www->curl_handle, CURLOPT_PROXY, www->proxy); - - if(www->user_agent) - curl_easy_setopt(www->curl_handle, CURLOPT_USERAGENT, www->user_agent); + if(www->proxy) { + res = curl_easy_setopt(www->curl_handle, CURLOPT_PROXY, www->proxy); + if(res != CURLE_OK) { + www->failed = 1; + raptor_www_error(www, "Setting proxy to %s failed", www->proxy); + return 1; + } + } + if(www->user_agent) { + res = curl_easy_setopt(www->curl_handle, CURLOPT_USERAGENT, www->user_agent); + if(res != CURLE_OK) { + www->failed = 1; + raptor_www_error(www, "Setting user agent to %s failed", www->user_agent); + return 1; + } + } + if(www->http_accept) slist = curl_slist_append(slist, (const char*)www->http_accept); @@ -229,12 +254,23 @@ raptor_www_curl_fetch(raptor_www *www) if(www->cache_control) slist = curl_slist_append(slist, (const char*)www->cache_control); - if(slist) - curl_easy_setopt(www->curl_handle, CURLOPT_HTTPHEADER, slist); + if(slist) { + res = curl_easy_setopt(www->curl_handle, CURLOPT_HTTPHEADER, slist); + if(res != CURLE_OK) { + www->failed = 1; + raptor_www_error(www, "Setting request http headers failed"); + return 1; + } + } /* specify URL to get */ - curl_easy_setopt(www->curl_handle, CURLOPT_URL, - raptor_uri_as_string(www->uri)); + res = curl_easy_setopt(www->curl_handle, CURLOPT_URL, + raptor_uri_as_string(www->uri)); + if(res != CURLE_OK) { + www->failed = 1; + raptor_www_error(www, "Setting request URL failed"); + return 1; + } if(curl_easy_perform(www->curl_handle)) { /* failed */ @@ -267,21 +303,43 @@ raptor_www_curl_set_ssl_cert_options(raptor_www* www, const char* cert_type, const char* cert_passphrase) { + CURLcode res; + /* client certificate file name */ - if(cert_filename) - curl_easy_setopt(www->curl_handle, CURLOPT_SSLCERT, cert_filename); + if(cert_filename) { + res = curl_easy_setopt(www->curl_handle, CURLOPT_SSLCERT, cert_filename); + if(res != CURLE_OK) { + www->failed = 1; + raptor_www_error(www, "Setting request SSL cert filename to %s failed", + cert_filename); + return 1; + } + } /* curl default is "PEM" */ - if(cert_type) - curl_easy_setopt(www->curl_handle, CURLOPT_SSLCERTTYPE, cert_type); + if(cert_type) { + res = curl_easy_setopt(www->curl_handle, CURLOPT_SSLCERTTYPE, cert_type); + if(res != CURLE_OK) { + www->failed = 1; + raptor_www_error(www, "Setting request SSL cert type to %s failed", + cert_type); + return 1; + } + } /* passphrase */ /* Removed in 7.16.4 */ #if LIBCURL_VERSION_NUM < 0x071004 #define CURLOPT_KEYPASSWD CURLOPT_SSLKEYPASSWD #endif - if(cert_passphrase) - curl_easy_setopt(www->curl_handle, CURLOPT_KEYPASSWD, cert_passphrase); + if(cert_passphrase) { + res = curl_easy_setopt(www->curl_handle, CURLOPT_KEYPASSWD, cert_passphrase); + if(res != CURLE_OK) { + www->failed = 1; + raptor_www_error(www, "Setting request SSL cert pass phrase failed"); + return 1; + } + } return 0; } @@ -291,9 +349,17 @@ int raptor_www_curl_set_ssl_verify_options(raptor_www* www, int verify_peer, int verify_host) { + CURLcode res; + if(verify_peer) verify_peer = 1; - curl_easy_setopt(www->curl_handle, CURLOPT_SSL_VERIFYPEER, verify_peer); + res = curl_easy_setopt(www->curl_handle, CURLOPT_SSL_VERIFYPEER, verify_peer); + if(res != CURLE_OK) { + www->failed = 1; + raptor_www_error(www, "Setting request SSL verify peer flag %d failed", + verify_peer); + return 1; + } /* curl 7.28.1 removed the value 1 from being legal: * http://daniel.haxx.se/blog/2012/10/25/libcurl-claimed-to-be-dangerous/ @@ -307,7 +373,13 @@ raptor_www_curl_set_ssl_verify_options(raptor_www* www, int verify_peer, */ if(verify_host) verify_host = 2; - curl_easy_setopt(www->curl_handle, CURLOPT_SSL_VERIFYHOST, verify_host); + res = curl_easy_setopt(www->curl_handle, CURLOPT_SSL_VERIFYHOST, verify_host); + if(res != CURLE_OK) { + www->failed = 1; + raptor_www_error(www, "Setting request SSL verify host flag %d failed", + verify_host); + return 1; + } return 0; } diff --git a/src/turtle_parser.y b/src/turtle_parser.y index d18e68e9..1474a3db 100644 --- a/src/turtle_parser.y +++ b/src/turtle_parser.y @@ -1334,11 +1334,11 @@ turtle_parser_error_simple(void* user_data, const char *msg, ...) !turtle_parser->is_end) { /* we encountered an error on or around the last byte of the buffer * sorting it in the next run aye? */ - return; + goto tidy; } if(turtle_parser->error_count++) - return; + goto tidy; rdf_parser->locator.line = turtle_parser->lineno; #ifdef RAPTOR_TURTLE_USE_ERROR_COLUMNS @@ -1348,6 +1348,9 @@ turtle_parser_error_simple(void* user_data, const char *msg, ...) raptor_log_error_varargs(rdf_parser->world, RAPTOR_LOG_LEVEL_ERROR, &rdf_parser->locator, msg, args); + +tidy: + va_end(args); } |