diff options
author | Dave Beckett <dave@dajobe.org> | 2020-10-23 18:39:21 -0700 |
---|---|---|
committer | Dave Beckett <dave@dajobe.org> | 2020-10-23 18:39:21 -0700 |
commit | 4c8f09c2e15144d8029167f517547e68a179f77c (patch) | |
tree | 60b134fca9d3d6b12b114018687039aaf3d81de3 /src | |
parent | 5f2eb4fd8d15b610821ed7f8d4750532d825163c (diff) | |
download | raptor-4c8f09c2e15144d8029167f517547e68a179f77c.tar.gz |
Add raptor_www setters with return value for errors
Added raptor_www_set_user_agent2, raptor_www_set_proxy2,
raptor_www_set_http_accept2 taking value string length and returning
error code on failure.
Deprecates raptor_www_set_user_agent, raptor_www_set_proxy
raptor_www_set_http_accept respectively.
Diffstat (limited to 'src')
-rw-r--r-- | src/raptor2.h.in | 6 | ||||
-rw-r--r-- | src/raptor_parse.c | 4 | ||||
-rw-r--r-- | src/raptor_www.c | 123 |
3 files changed, 107 insertions, 26 deletions
diff --git a/src/raptor2.h.in b/src/raptor2.h.in index 1d38a93d..f97326a6 100644 --- a/src/raptor2.h.in +++ b/src/raptor2.h.in @@ -1441,10 +1441,16 @@ int raptor_www_set_ssl_cert_options(raptor_www* www, const char* cert_filename, RAPTOR_API int raptor_www_set_ssl_verify_options(raptor_www* www, int verify_peer, int verify_host); RAPTOR_API +int raptor_www_set_user_agent2(raptor_www *www, const char *user_agent, size_t user_agent_len); +RAPTOR_API RAPTOR_DEPRECATED void raptor_www_set_user_agent(raptor_www *www, const char *user_agent); RAPTOR_API +int raptor_www_set_proxy2(raptor_www *www, const char *proxy, size_t proxy_len); +RAPTOR_API RAPTOR_DEPRECATED void raptor_www_set_proxy(raptor_www *www, const char *proxy); RAPTOR_API +int raptor_www_set_http_accept2(raptor_www *www, const char *value, size_t value_len); +RAPTOR_API RAPTOR_DEPRECATED void raptor_www_set_http_accept(raptor_www *www, const char *value); RAPTOR_API void raptor_www_set_write_bytes_handler(raptor_www *www, raptor_www_write_bytes_handler handler, void *user_data); diff --git a/src/raptor_parse.c b/src/raptor_parse.c index d51c3d01..95ab2ac4 100644 --- a/src/raptor_parse.c +++ b/src/raptor_parse.c @@ -758,7 +758,7 @@ raptor_parser_parse_uri_with_connection(raptor_parser* rdf_parser, accept_h = raptor_parser_get_accept_header(rdf_parser); if(accept_h) { - raptor_www_set_http_accept(rdf_parser->www, accept_h); + raptor_www_set_http_accept2(rdf_parser->www, accept_h, 0); RAPTOR_FREE(char*, accept_h); } } @@ -789,7 +789,7 @@ raptor_parser_parse_uri_with_connection(raptor_parser* rdf_parser, ua = RAPTOR_OPTIONS_GET_STRING(rdf_parser, RAPTOR_OPTION_WWW_HTTP_USER_AGENT); if(ua) - raptor_www_set_user_agent(rdf_parser->www, ua); + raptor_www_set_user_agent2(rdf_parser->www, ua, 0); cert_filename = RAPTOR_OPTIONS_GET_STRING(rdf_parser, RAPTOR_OPTION_WWW_CERT_FILENAME); diff --git a/src/raptor_www.c b/src/raptor_www.c index c651f752..e1808837 100644 --- a/src/raptor_www.c +++ b/src/raptor_www.c @@ -267,86 +267,141 @@ raptor_www_set_content_type_handler(raptor_www* www, /** - * raptor_www_set_user_agent: + * raptor_www_set_user_agent2: * @www: WWW object * @user_agent: User-Agent string + * @user_agent_len: Length of @user_agent string or 0 to count it here. * * Set the user agent value, for HTTP requests typically. + * + * Return value: non-0 on failure **/ -void -raptor_www_set_user_agent(raptor_www* www, const char *user_agent) +int +raptor_www_set_user_agent2(raptor_www* www, const char *user_agent, + size_t user_agent_len) { char *ua_copy = NULL; - size_t ua_len; if(!user_agent || !*user_agent) { www->user_agent = NULL; - return; + return 0; } - - ua_len = strlen(user_agent); - ua_copy = RAPTOR_MALLOC(char*, ua_len + 1); + + if(user_agent_len == 0) + user_agent_len = strlen(user_agent); + + ua_copy = RAPTOR_MALLOC(char*, user_agent_len + 1); if(!ua_copy) - return; + return 1; - memcpy(ua_copy, user_agent, ua_len + 1); /* copy NUL */ + memcpy(ua_copy, user_agent, user_agent_len + 1); /* copy NUL */ www->user_agent = ua_copy; + + return 0; } /** - * raptor_www_set_proxy: + * raptor_www_set_user_agent: + * @www: WWW object + * @user_agent: User-Agent string + * + * Set the user agent value, for HTTP requests typically. + * + * @Deprecated: use raptor_www_set_user_agent2() which takes a length + * parameter and returns a value to singify failure. + * + **/ +void +raptor_www_set_user_agent(raptor_www* www, const char *user_agent) +{ + (void)raptor_www_set_user_agent2(www, user_agent, 0); +} + + +/** + * raptor_www_set_proxy2: * @www: WWW object * @proxy: proxy string. + * @proxy_len: Length of @proxy string or 0 to count it here. * * Set the proxy for the WWW object. * * The @proxy usually a string of the form http://server.domain:port. + * + * Return value: non-0 on failure **/ -void -raptor_www_set_proxy(raptor_www* www, const char *proxy) +int +raptor_www_set_proxy2(raptor_www* www, const char *proxy, + size_t proxy_len) { char *proxy_copy; - size_t proxy_len; if(!proxy) - return; + return 1; + + if(proxy_len == 0) + proxy_len = strlen(proxy); - proxy_len = strlen(proxy); proxy_copy = RAPTOR_MALLOC(char*, proxy_len + 1); if(!proxy_copy) - return; + return 1; memcpy(proxy_copy, proxy, proxy_len + 1); /* copy NUL */ www->proxy = proxy_copy; + + return 0; } /** - * raptor_www_set_http_accept: + * raptor_www_set_proxy: + * @www: WWW object + * @proxy: proxy string. + * + * Set the proxy for the WWW object. + * + * The @proxy usually a string of the form http://server.domain:port. + * + * @Deprecated: use raptor_www_set_proxy2() which takes an length + * parameter and returns a value to singify failure. + * + **/ +void +raptor_www_set_proxy(raptor_www* www, const char *proxy) +{ + (void)raptor_www_set_proxy2(www, proxy, 0); +} + + +/** + * raptor_www_set_http_accept2: * @www: #raptor_www class * @value: Accept: header value or NULL to have an empty one. + * @value_len: Length of @value string or 0 to count it here. * * Set HTTP Accept header. * + * Return value: non-0 on failure **/ -void -raptor_www_set_http_accept(raptor_www* www, const char *value) +int +raptor_www_set_http_accept2(raptor_www* www, const char *value, + size_t value_len) { char *value_copy; size_t len = 8; /* strlen("Accept:")+1 */ - size_t value_len = 0; if(value) { - value_len = strlen(value); + if (value_len == 0) + value_len = strlen(value); len += 1 + value_len; /* " "+value */ } value_copy = RAPTOR_MALLOC(char*, len); if(!value_copy) - return; + return 1; www->http_accept = value_copy; /* copy header name */ @@ -355,7 +410,7 @@ raptor_www_set_http_accept(raptor_www* www, const char *value) /* copy header value */ if(value) { - *value_copy ++= ' '; + *value_copy++ = ' '; memcpy(value_copy, value, value_len + 1); /* Copy NUL */ } else { /* Ensure value is NUL terminated */ @@ -365,6 +420,26 @@ raptor_www_set_http_accept(raptor_www* www, const char *value) #if defined(RAPTOR_DEBUG) && RAPTOR_DEBUG > 1 RAPTOR_DEBUG2("Using Accept header: '%s'\n", www->http_accept); #endif + + return 0; +} + + +/** + * raptor_www_set_http_accept: + * @www: #raptor_www class + * @value: Accept: header value or NULL to have an empty one. + * + * Set HTTP Accept header. + * + * @Deprecated: use raptor_www_set_http_accept2() which takes an + * length parameter and returns a value to singify failure. + * + **/ +void +raptor_www_set_http_accept(raptor_www* www, const char *value) +{ + (void)raptor_www_set_http_accept2(www, value, 0); } |