| ne_request.h | | ne_request.h | |
| | | | |
| skipping to change at line 60 | | skipping to change at line 60 | |
| ne_request *ne_request_create(ne_session *sess, | | ne_request *ne_request_create(ne_session *sess, | |
| const char *method, const char *path); | | const char *method, const char *path); | |
| | | | |
| /* The request body will be taken from 'size' bytes of 'buffer'. */ | | /* The request body will be taken from 'size' bytes of 'buffer'. */ | |
| void ne_set_request_body_buffer(ne_request *req, const char *buffer, | | void ne_set_request_body_buffer(ne_request *req, const char *buffer, | |
| size_t size); | | size_t size); | |
| | | | |
| /* The request body will be taken from 'length' bytes read from the | | /* The request body will be taken from 'length' bytes read from the | |
| * file descriptor 'fd', starting from file offset 'offset'. */ | | * file descriptor 'fd', starting from file offset 'offset'. */ | |
| void ne_set_request_body_fd(ne_request *req, int fd, | | void ne_set_request_body_fd(ne_request *req, int fd, | |
|
| off_t offset, off_t length); | | ne_off_t offset, ne_off_t length); | |
| | | | |
| #ifdef NE_LFS | | | |
| /* Alternate version of ne_set_request_body_fd taking off64_t | | | |
| * offset type for systems supporting _LARGEFILE64_SOURCE. */ | | | |
| void ne_set_request_body_fd64(ne_request *req, int fd, | | | |
| off64_t offset, off64_t length); | | | |
| #endif | | | |
| | | | |
| /* "Pull"-based request body provider: a callback which is invoked to | | /* "Pull"-based request body provider: a callback which is invoked to | |
| * provide blocks of request body on demand. | | * provide blocks of request body on demand. | |
| * | | * | |
| * Before each time the body is provided, the callback will be called | | * Before each time the body is provided, the callback will be called | |
| * once with buflen == 0. The body may have to be provided >1 time | | * once with buflen == 0. The body may have to be provided >1 time | |
| * per request (for authentication retries etc.). | | * per request (for authentication retries etc.). | |
| * | | * | |
| * For a call with buflen == 0, the callback must return zero on success | | * For a call with buflen == 0, the callback must return zero on success | |
| * or non-zero on error; the session error string must be set on error. | | * or non-zero on error; the session error string must be set on error. | |
| | | | |
| skipping to change at line 89 | | skipping to change at line 82 | |
| * <0 : error, abort request; session error string must be
set. | | * <0 : error, abort request; session error string must be
set. | |
| * 0 : ignore 'buffer' contents, end of body. | | * 0 : ignore 'buffer' contents, end of body. | |
| * 0 < x <= buflen : buffer contains x bytes of body data. */ | | * 0 < x <= buflen : buffer contains x bytes of body data. */ | |
| typedef ssize_t (*ne_provide_body)(void *userdata, | | typedef ssize_t (*ne_provide_body)(void *userdata, | |
| char *buffer, size_t buflen); | | char *buffer, size_t buflen); | |
| | | | |
| /* Install a callback which is invoked as needed to provide the | | /* Install a callback which is invoked as needed to provide the | |
| * request body, a block at a time. The total size of the request | | * request body, a block at a time. The total size of the request | |
| * body is 'length'; the callback must ensure that it returns no more | | * body is 'length'; the callback must ensure that it returns no more | |
| * than 'length' bytes in total. */ | | * than 'length' bytes in total. */ | |
|
| void ne_set_request_body_provider(ne_request *req, off_t length, | | void ne_set_request_body_provider(ne_request *req, ne_off_t length, | |
| ne_provide_body provider, void *userdata); | | ne_provide_body provider, void *userdata); | |
| | | | |
|
| #ifdef NE_LFS | | | |
| /* Duplicate version of ne_set_request_body_provider, taking an off64_t | | | |
| * offset. */ | | | |
| void ne_set_request_body_provider64(ne_request *req, off64_t length, | | | |
| ne_provide_body provider, void *userdat | | | |
| a); | | | |
| #endif | | | |
| | | | |
| /* Handling response bodies; two callbacks must be provided: | | /* Handling response bodies; two callbacks must be provided: | |
| * | | * | |
| * 1) 'acceptance' callback: determines whether you want to handle the | | * 1) 'acceptance' callback: determines whether you want to handle the | |
| * response body given the response-status information, e.g., if you | | * response body given the response-status information, e.g., if you | |
| * only want 2xx responses, say so here. | | * only want 2xx responses, say so here. | |
| * | | * | |
| * 2) 'reader' callback: passed blocks of the response-body as they | | * 2) 'reader' callback: passed blocks of the response-body as they | |
| * arrive, if the acceptance callback returned non-zero. */ | | * arrive, if the acceptance callback returned non-zero. */ | |
| | | | |
| /* 'acceptance' callback type. Return non-zero to accept the response, | | /* 'acceptance' callback type. Return non-zero to accept the response, | |
| | | | |
| skipping to change at line 251 | | skipping to change at line 237 | |
| /* Return 0 if the given flag is not set, >0 it is set, or -1 if the | | /* Return 0 if the given flag is not set, >0 it is set, or -1 if the | |
| * flag is not supported. */ | | * flag is not supported. */ | |
| int ne_get_request_flag(ne_request *req, ne_request_flag flag); | | int ne_get_request_flag(ne_request *req, ne_request_flag flag); | |
| | | | |
| /**** Request hooks handling *****/ | | /**** Request hooks handling *****/ | |
| | | | |
| typedef void (*ne_free_hooks)(void *cookie); | | typedef void (*ne_free_hooks)(void *cookie); | |
| | | | |
| /* Hook called when a request is created; passed the request method, | | /* Hook called when a request is created; passed the request method, | |
| * and the string used as the Request-URI (note that this may be a | | * and the string used as the Request-URI (note that this may be a | |
|
| * absolute URI if a proxy is in use, an absolute path, a "*", | | * absolute URI if a proxy is in use, an absolute path, a "*", etc). | |
| * etc). */ | | * A create_request hook is called exactly once per request. */ | |
| typedef void (*ne_create_request_fn)(ne_request *req, void *userdata, | | typedef void (*ne_create_request_fn)(ne_request *req, void *userdata, | |
| const char *method, const char *requri)
; | | const char *method, const char *requri)
; | |
| void ne_hook_create_request(ne_session *sess, | | void ne_hook_create_request(ne_session *sess, | |
| ne_create_request_fn fn, void *userdata); | | ne_create_request_fn fn, void *userdata); | |
| | | | |
| /* Hook called before the request is sent. 'header' is the raw HTTP | | /* Hook called before the request is sent. 'header' is the raw HTTP | |
|
| * header before the trailing CRLF is added: add in more here. */ | | * header before the trailing CRLF is added; more headers can be added | |
| | | * here. A pre_send hook may be called >1 time per request if the | |
| | | * request is retried due to a post_send hook returning NE_RETRY. */ | |
| typedef void (*ne_pre_send_fn)(ne_request *req, void *userdata, | | typedef void (*ne_pre_send_fn)(ne_request *req, void *userdata, | |
| ne_buffer *header); | | ne_buffer *header); | |
| void ne_hook_pre_send(ne_session *sess, ne_pre_send_fn fn, void *userdata); | | void ne_hook_pre_send(ne_session *sess, ne_pre_send_fn fn, void *userdata); | |
| | | | |
|
| | | /* Hook called directly after the response headers have been read, but | |
| | | * before the resposnse body has been read. 'status' is the response | |
| | | * status-code. A post_header hook may be called >1 time per request | |
| | | * if the request is retried due to a post_send hook returning | |
| | | * NE_RETRY. */ | |
| | | typedef void (*ne_post_headers_fn)(ne_request *req, void *userdata, | |
| | | const ne_status *status); | |
| | | void ne_hook_post_headers(ne_session *sess, | |
| | | ne_post_headers_fn fn, void *userdata); | |
| | | | |
| /* Hook called after the request is dispatched (request sent, and | | /* Hook called after the request is dispatched (request sent, and | |
| * the entire response read). If an error occurred reading the response, | | * the entire response read). If an error occurred reading the response, | |
| * this hook will not run. May return: | | * this hook will not run. May return: | |
| * NE_OK everything is okay | | * NE_OK everything is okay | |
| * NE_RETRY try sending the request again. | | * NE_RETRY try sending the request again. | |
| * anything else signifies an error, and the request is failed. The return | | * anything else signifies an error, and the request is failed. The return | |
| * code is passed back the _dispatch caller, so the session error must | | * code is passed back the _dispatch caller, so the session error must | |
| * also be set appropriately (ne_set_error). | | * also be set appropriately (ne_set_error). | |
| */ | | */ | |
| typedef int (*ne_post_send_fn)(ne_request *req, void *userdata, | | typedef int (*ne_post_send_fn)(ne_request *req, void *userdata, | |
| | | | |
| skipping to change at line 297 | | skipping to change at line 295 | |
| /* The ne_unhook_* functions remove a hook registered with the given | | /* The ne_unhook_* functions remove a hook registered with the given | |
| * session. If a hook is found which was registered with a given | | * session. If a hook is found which was registered with a given | |
| * function 'fn', and userdata pointer 'userdata', then it will be | | * function 'fn', and userdata pointer 'userdata', then it will be | |
| * removed from the hooks list. | | * removed from the hooks list. | |
| * | | * | |
| * It is unsafe to use any of these functions from a hook function to | | * It is unsafe to use any of these functions from a hook function to | |
| * unregister itself, except for ne_unhook_destroy_request. */ | | * unregister itself, except for ne_unhook_destroy_request. */ | |
| void ne_unhook_create_request(ne_session *sess, | | void ne_unhook_create_request(ne_session *sess, | |
| ne_create_request_fn fn, void *userdata); | | ne_create_request_fn fn, void *userdata); | |
| void ne_unhook_pre_send(ne_session *sess, ne_pre_send_fn fn, void *userdata
); | | void ne_unhook_pre_send(ne_session *sess, ne_pre_send_fn fn, void *userdata
); | |
|
| | | void ne_unhook_post_headers(ne_session *sess, ne_post_headers_fn fn, void *
userdata); | |
| void ne_unhook_post_send(ne_session *sess, ne_post_send_fn fn, void *userda
ta); | | void ne_unhook_post_send(ne_session *sess, ne_post_send_fn fn, void *userda
ta); | |
| void ne_unhook_destroy_request(ne_session *sess, | | void ne_unhook_destroy_request(ne_session *sess, | |
| ne_destroy_req_fn fn, void *userdata); | | ne_destroy_req_fn fn, void *userdata); | |
| void ne_unhook_destroy_session(ne_session *sess, | | void ne_unhook_destroy_session(ne_session *sess, | |
| ne_destroy_sess_fn fn, void *userdata); | | ne_destroy_sess_fn fn, void *userdata); | |
| | | | |
| /* Store an opaque context for the request, 'priv' is returned by a | | /* Store an opaque context for the request, 'priv' is returned by a | |
| * call to ne_request_get_private with the same ID. */ | | * call to ne_request_get_private with the same ID. */ | |
| void ne_set_request_private(ne_request *req, const char *id, void *priv); | | void ne_set_request_private(ne_request *req, const char *id, void *priv); | |
| void *ne_get_request_private(ne_request *req, const char *id); | | void *ne_get_request_private(ne_request *req, const char *id); | |
| | | | |
End of changes. 7 change blocks. |
| 20 lines changed or deleted | | 18 lines changed or added | |
|
| ne_session.h | | ne_session.h | |
| /* | | /* | |
| HTTP session handling | | HTTP session handling | |
|
| Copyright (C) 1999-2006, Joe Orton <joe@manyfish.co.uk> | | Copyright (C) 1999-2007, Joe Orton <joe@manyfish.co.uk> | |
| | | | |
| This library is free software; you can redistribute it and/or | | This library is free software; you can redistribute it and/or | |
| modify it under the terms of the GNU Library General Public | | modify it under the terms of the GNU Library General Public | |
| License as published by the Free Software Foundation; either | | License as published by the Free Software Foundation; either | |
| version 2 of the License, or (at your option) any later version. | | version 2 of the License, or (at your option) any later version. | |
| | | | |
| This library is distributed in the hope that it will be useful, | | This library is distributed in the hope that it will be useful, | |
| but WITHOUT ANY WARRANTY; without even the implied warranty of | | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| Library General Public License for more details. | | Library General Public License for more details. | |
| | | | |
| skipping to change at line 64 | | skipping to change at line 64 | |
| typedef enum ne_session_flag_e { | | typedef enum ne_session_flag_e { | |
| NE_SESSFLAG_PERSIST = 0, /* disable this flag to prevent use of | | NE_SESSFLAG_PERSIST = 0, /* disable this flag to prevent use of | |
| * persistent connections. */ | | * persistent connections. */ | |
| | | | |
| NE_SESSFLAG_ICYPROTO, /* enable this flag to enable support for | | NE_SESSFLAG_ICYPROTO, /* enable this flag to enable support for | |
| * non-HTTP ShoutCast-style "ICY" responses. */ | | * non-HTTP ShoutCast-style "ICY" responses. */ | |
| | | | |
| NE_SESSFLAG_SSLv2, /* disable this flag to disable support for | | NE_SESSFLAG_SSLv2, /* disable this flag to disable support for | |
| * SSLv2, if supported by the SSL library. */ | | * SSLv2, if supported by the SSL library. */ | |
| | | | |
|
| | | NE_SESSFLAG_RFC4918, /* enable this flag to enable support for | |
| | | * RFC4918-only WebDAV features; losing | |
| | | * backwards-compatibility with RFC2518 | |
| | | * servers. */ | |
| | | | |
| | | NE_SESSFLAG_CONNAUTH, /* enable this flag if an awful, broken, | |
| | | * RFC-violating, connection-based HTTP | |
| | | * authentication scheme is in use. */ | |
| | | | |
| NE_SESSFLAG_LAST /* enum sentinel value */ | | NE_SESSFLAG_LAST /* enum sentinel value */ | |
| } ne_session_flag; | | } ne_session_flag; | |
| | | | |
| /* Set a new value for a particular session flag. */ | | /* Set a new value for a particular session flag. */ | |
| void ne_set_session_flag(ne_session *sess, ne_session_flag flag, int value)
; | | void ne_set_session_flag(ne_session *sess, ne_session_flag flag, int value)
; | |
| | | | |
| /* Return 0 if the given flag is not set, >0 it is set, or -1 if the | | /* Return 0 if the given flag is not set, >0 it is set, or -1 if the | |
| * flag is not supported. */ | | * flag is not supported. */ | |
| int ne_get_session_flag(ne_session *sess, ne_session_flag flag); | | int ne_get_session_flag(ne_session *sess, ne_session_flag flag); | |
| | | | |
| /* Bypass the normal name resolution; force the use of specific set of | | /* Bypass the normal name resolution; force the use of specific set of | |
| * addresses for this session, addrs[0]...addrs[n-1]. The addrs array | | * addresses for this session, addrs[0]...addrs[n-1]. The addrs array | |
| * must remain valid until the session is destroyed. */ | | * must remain valid until the session is destroyed. */ | |
| void ne_set_addrlist(ne_session *sess, const ne_inet_addr **addrs, size_t n
); | | void ne_set_addrlist(ne_session *sess, const ne_inet_addr **addrs, size_t n
); | |
| | | | |
|
| /* Progress callback. */ | | /* DEPRECATED: Progress callback. */ | |
| typedef void (*ne_progress)(void *userdata, off_t progress, off_t total); | | typedef void (*ne_progress)(void *userdata, ne_off_t progress, ne_off_t tot | |
| | | al); | |
| | | | |
|
| /* Set a progress callback for the session. */ | | /* DEPRECATED API: Set a progress callback for the session; this is | |
| void ne_set_progress(ne_session *sess, | | * deprecated in favour of ne_set_notifier(). The progress callback | |
| ne_progress progress, void *userdata); | | * is invoked for after each block of the request and response body to | |
| | | * indicate request and response progress (there is no way to | |
| | | * distinguish between the two using this interface alone). | |
| | | * | |
| | | * NOTE: Use of this interface is mutually exclusive with the use of | |
| | | * ne_set_notifier(). A call to ne_set_progress() removes the | |
| | | * notifier callback, and vice versa. */ | |
| | | void ne_set_progress(ne_session *sess, ne_progress progress, void *userdata | |
| | | ); | |
| | | | |
| /* Store an opaque context for the session, 'priv' is returned by a | | /* Store an opaque context for the session, 'priv' is returned by a | |
| * call to ne_session_get_private with the same ID. */ | | * call to ne_session_get_private with the same ID. */ | |
| void ne_set_session_private(ne_session *sess, const char *id, void *priv); | | void ne_set_session_private(ne_session *sess, const char *id, void *priv); | |
| void *ne_get_session_private(ne_session *sess, const char *id); | | void *ne_get_session_private(ne_session *sess, const char *id); | |
| | | | |
|
| | | /* Status event type. */ | |
| typedef enum { | | typedef enum { | |
|
| ne_conn_namelookup, /* lookup up hostname (info = hostname) */ | | ne_status_lookup = 0, /* looking up hostname */ | |
| ne_conn_connecting, /* connecting to host (info = hostname) */ | | ne_status_connecting, /* connecting to host */ | |
| ne_conn_connected, /* connected to host (info = hostname) */ | | ne_status_connected, /* connected to host */ | |
| ne_conn_secure /* connection now secure (info = crypto level) */ | | ne_status_sending, /* sending a request body */ | |
| } ne_conn_status; | | ne_status_recving, /* receiving a response body */ | |
| | | ne_status_disconnected /* disconnected from host */ | |
| | | } ne_session_status; | |
| | | | |
|
| typedef void (*ne_notify_status)(void *userdata, | | /* Status event information union; the relevant structure within | |
| ne_conn_status status, | | * corresponds to the event type. WARNING: the size of this union is | |
| const char *info); | | * not limited by ABI constraint; it may be extended with additional | |
| | | * members of different size, or existing members may be extended. */ | |
| | | typedef union ne_session_status_info_u { | |
| | | struct /* ne_status_lookup */ { | |
| | | /* The hostname which is being resolved: */ | |
| | | const char *hostname; | |
| | | } lu; | |
| | | struct /* ne_status_connecting */ { | |
| | | /* The hostname and network address to which a connection | |
| | | * attempt is being made: */ | |
| | | const char *hostname; | |
| | | const ne_inet_addr *address; | |
| | | } ci; | |
| | | struct /* ne_status_connected, ne_status_disconnected */ { | |
| | | /* The hostname to which a connection has just been | |
| | | * established or closed: */ | |
| | | const char *hostname; | |
| | | } cd; | |
| | | struct /* ne_status_sending and ne_status_recving */ { | |
| | | /* Request/response body transfer progress; if total == 0, the | |
| | | * total size is unknown; else 0 <= progress <= total: */ | |
| | | ne_off_t progress, total; | |
| | | } sr; | |
| | | } ne_session_status_info; | |
| | | | |
| | | /* Callback invoked to notify a new session status event, given by the | |
| | | * 'status' argument. On invocation, the contents of exactly one of | |
| | | * the structures in the info union will be valid, as indicated | |
| | | * above. */ | |
| | | typedef void (*ne_notify_status)(void *userdata, ne_session_status status, | |
| | | const ne_session_status_info *info); | |
| | | | |
| /* Set a status notification callback for the session, to report | | /* Set a status notification callback for the session, to report | |
|
| * connection status. */ | | * session status events. Only one notification callback per session | |
| void ne_set_status(ne_session *sess, | | * can be registered; the most recent of successive calls to this | |
| ne_notify_status status, void *userdata); | | * function takes effect. Note that | |
| | | * | |
| | | * NOTE: Use of this interface is mutually exclusive with the use of | |
| | | * ne_set_progress(). A call to ne_set_notifier() removes the | |
| | | * progress callback, and vice versa. */ | |
| | | void ne_set_notifier(ne_session *sess, ne_notify_status status, void *userd | |
| | | ata); | |
| | | | |
| /* Certificate verification failures. | | /* Certificate verification failures. | |
| * The certificate is not yet valid: */ | | * The certificate is not yet valid: */ | |
| #define NE_SSL_NOTYETVALID (0x01) | | #define NE_SSL_NOTYETVALID (0x01) | |
| /* The certificate has expired: */ | | /* The certificate has expired: */ | |
| #define NE_SSL_EXPIRED (0x02) | | #define NE_SSL_EXPIRED (0x02) | |
| /* The hostname for which the certificate was issued does not | | /* The hostname for which the certificate was issued does not | |
| * match the hostname of the server; this could mean that the | | * match the hostname of the server; this could mean that the | |
| * connection is being intercepted: */ | | * connection is being intercepted: */ | |
| #define NE_SSL_IDMISMATCH (0x04) | | #define NE_SSL_IDMISMATCH (0x04) | |
| | | | |
| skipping to change at line 147 | | skipping to change at line 201 | |
| * certificate, or the server cert has other verification problems. */ | | * certificate, or the server cert has other verification problems. */ | |
| void ne_ssl_set_verify(ne_session *sess, ne_ssl_verify_fn fn, void *userdat
a); | | void ne_ssl_set_verify(ne_session *sess, ne_ssl_verify_fn fn, void *userdat
a); | |
| | | | |
| /* Use the given client certificate for the session. The client cert | | /* Use the given client certificate for the session. The client cert | |
| * MUST be in the decrypted state, otherwise behaviour is undefined. | | * MUST be in the decrypted state, otherwise behaviour is undefined. | |
| * The 'clicert' object is duplicated internally so can be destroyed | | * The 'clicert' object is duplicated internally so can be destroyed | |
| * by the caller. */ | | * by the caller. */ | |
| void ne_ssl_set_clicert(ne_session *sess, const ne_ssl_client_cert *clicert
); | | void ne_ssl_set_clicert(ne_session *sess, const ne_ssl_client_cert *clicert
); | |
| | | | |
| /* Indicate that the certificate 'cert' is trusted; the 'cert' object | | /* Indicate that the certificate 'cert' is trusted; the 'cert' object | |
|
| * is duplicated internally so can be destroyed by the caller. */ | | * is duplicated internally so can be destroyed by the caller. This | |
| | | * function has no effect for non-SSL sessions. */ | |
| void ne_ssl_trust_cert(ne_session *sess, const ne_ssl_certificate *cert); | | void ne_ssl_trust_cert(ne_session *sess, const ne_ssl_certificate *cert); | |
| | | | |
| /* If the SSL library provided a default set of CA certificates, trust | | /* If the SSL library provided a default set of CA certificates, trust | |
| * this set of CAs. */ | | * this set of CAs. */ | |
| void ne_ssl_trust_default_ca(ne_session *sess); | | void ne_ssl_trust_default_ca(ne_session *sess); | |
| | | | |
| /* Callback used to load a client certificate on demand. If dncount | | /* Callback used to load a client certificate on demand. If dncount | |
| * is > 0, the 'dnames' array dnames[0] through dnames[dncount-1] | | * is > 0, the 'dnames' array dnames[0] through dnames[dncount-1] | |
| * gives the list of CA names which the server indicated were | | * gives the list of CA names which the server indicated were | |
| * acceptable. The callback should load an appropriate client | | * acceptable. The callback should load an appropriate client | |
| | | | |
| skipping to change at line 172 | | skipping to change at line 227 | |
| | | | |
| /* Register a function to be called when the server requests a client | | /* Register a function to be called when the server requests a client | |
| * certificate. */ | | * certificate. */ | |
| void ne_ssl_provide_clicert(ne_session *sess, | | void ne_ssl_provide_clicert(ne_session *sess, | |
| ne_ssl_provide_fn fn, void *userdata); | | ne_ssl_provide_fn fn, void *userdata); | |
| | | | |
| /* Set the timeout (in seconds) used when reading from a socket. The | | /* Set the timeout (in seconds) used when reading from a socket. The | |
| * timeout value must be greater than zero. */ | | * timeout value must be greater than zero. */ | |
| void ne_set_read_timeout(ne_session *sess, int timeout); | | void ne_set_read_timeout(ne_session *sess, int timeout); | |
| | | | |
|
| | | /* Set the timeout (in seconds) used when making a connection. The | |
| | | * timeout value must be greater than zero. */ | |
| | | void ne_set_connect_timeout(ne_session *sess, int timeout); | |
| | | | |
| /* Sets the user-agent string. neon/VERSION will be appended, to make | | /* Sets the user-agent string. neon/VERSION will be appended, to make | |
| * the full header "User-Agent: product neon/VERSION". | | * the full header "User-Agent: product neon/VERSION". | |
| * If this function is not called, the User-Agent header is not sent. | | * If this function is not called, the User-Agent header is not sent. | |
| * The product string must follow the RFC2616 format, i.e. | | * The product string must follow the RFC2616 format, i.e. | |
| * product = token ["/" product-version] | | * product = token ["/" product-version] | |
| * product-version = token | | * product-version = token | |
| * where token is any alpha-numeric-y string [a-zA-Z0-9]* */ | | * where token is any alpha-numeric-y string [a-zA-Z0-9]* */ | |
| void ne_set_useragent(ne_session *sess, const char *product); | | void ne_set_useragent(ne_session *sess, const char *product); | |
| | | | |
| /* Returns non-zero if next-hop server does not claim compliance to | | /* Returns non-zero if next-hop server does not claim compliance to | |
| | | | |
| skipping to change at line 193 | | skipping to change at line 252 | |
| int ne_version_pre_http11(ne_session *sess); | | int ne_version_pre_http11(ne_session *sess); | |
| | | | |
| /* Returns the 'hostport' URI segment for the end-server, e.g. | | /* Returns the 'hostport' URI segment for the end-server, e.g. | |
| * "my.server.com:8080". */ | | * "my.server.com:8080". */ | |
| const char *ne_get_server_hostport(ne_session *sess); | | const char *ne_get_server_hostport(ne_session *sess); | |
| | | | |
| /* Returns the URL scheme being used for the current session, omitting | | /* Returns the URL scheme being used for the current session, omitting | |
| * the trailing ':'; e.g. "http" or "https". */ | | * the trailing ':'; e.g. "http" or "https". */ | |
| const char *ne_get_scheme(ne_session *sess); | | const char *ne_get_scheme(ne_session *sess); | |
| | | | |
|
| /* Sets the host, scheme, and port fields (and no others) of the given | | /* Sets the host, scheme, and port fields of the given URI structure | |
| * URI structure; host and scheme are malloc-allocated. */ | | * to that of the configured server and scheme for the session; host | |
| | | * and scheme are malloc-allocated. No other fields in the URI | |
| | | * structure are changed. */ | |
| void ne_fill_server_uri(ne_session *sess, ne_uri *uri); | | void ne_fill_server_uri(ne_session *sess, ne_uri *uri); | |
| | | | |
|
| | | /* If a proxy is configured, sets the host and port fields in the | |
| | | * given URI structure to that of the proxy. The hostname is | |
| | | * malloc-allocated. No other fields in the URI structure are | |
| | | * changed; if a proxy is not configured, no fields are changed. */ | |
| | | void ne_fill_proxy_uri(ne_session *sess, ne_uri *uri); | |
| | | | |
| /* Set the error string for the session; takes printf-like format | | /* Set the error string for the session; takes printf-like format | |
| * string. */ | | * string. */ | |
| void ne_set_error(ne_session *sess, const char *format, ...) | | void ne_set_error(ne_session *sess, const char *format, ...) | |
| ne_attribute((format (printf, 2, 3))); | | ne_attribute((format (printf, 2, 3))); | |
| | | | |
| /* Retrieve the error string for the session */ | | /* Retrieve the error string for the session */ | |
| const char *ne_get_error(ne_session *sess); | | const char *ne_get_error(ne_session *sess); | |
| | | | |
| NE_END_DECLS | | NE_END_DECLS | |
| | | | |
| | | | |
End of changes. 12 change blocks. |
| 20 lines changed or deleted | | 90 lines changed or added | |
|
| ne_socket.h | | ne_socket.h | |
| | | | |
| skipping to change at line 96 | | skipping to change at line 96 | |
| | | | |
| /* Destroys an address object created by ne_addr_resolve. */ | | /* Destroys an address object created by ne_addr_resolve. */ | |
| void ne_addr_destroy(ne_sock_addr *addr); | | void ne_addr_destroy(ne_sock_addr *addr); | |
| | | | |
| /* Network address type; IPv4 or IPv6 */ | | /* Network address type; IPv4 or IPv6 */ | |
| typedef enum { | | typedef enum { | |
| ne_iaddr_ipv4 = 0, | | ne_iaddr_ipv4 = 0, | |
| ne_iaddr_ipv6 | | ne_iaddr_ipv6 | |
| } ne_iaddr_type; | | } ne_iaddr_type; | |
| | | | |
|
| /* Create a network address from raw byte representation (in network | | /* Create a network address object from raw byte representation (in | |
| * byte order) of given type. 'raw' must be four bytes for an IPv4 | | * network byte order) of given type. 'raw' must be four bytes for an | |
| * address, 16 bytes for an IPv6 address. May return NULL if address | | * IPv4 address, 16 bytes for an IPv6 address. May return NULL if | |
| * type is not supported. */ | | * address type is not supported. */ | |
| ne_inet_addr *ne_iaddr_make(ne_iaddr_type type, const unsigned char *raw); | | ne_inet_addr *ne_iaddr_make(ne_iaddr_type type, const unsigned char *raw); | |
| | | | |
|
| /* Compare two network addresses i1 and i2; return non-zero if they | | /* Compare two network address objects i1 and i2; returns zero if they | |
| * are not equal. */ | | * are equivalent or non-zero otherwise. */ | |
| int ne_iaddr_cmp(const ne_inet_addr *i1, const ne_inet_addr *i2); | | int ne_iaddr_cmp(const ne_inet_addr *i1, const ne_inet_addr *i2); | |
| | | | |
|
| /* Returns the type of the given network address. */ | | /* Return the type of the given network address object. */ | |
| ne_iaddr_type ne_iaddr_typeof(const ne_inet_addr *ia); | | ne_iaddr_type ne_iaddr_typeof(const ne_inet_addr *ia); | |
| | | | |
|
| /* Prints the string representation of network address 'ia' into the | | /* Print the string representation of network address 'ia' into the | |
| * 'buffer', which is of size 'bufsiz'. Returns 'buffer'. */ | | * buffer 'buffer', which is of length 'bufsiz'. Returns 'buffer'. */ | |
| char *ne_iaddr_print(const ne_inet_addr *ia, char *buffer, size_t bufsiz); | | char *ne_iaddr_print(const ne_inet_addr *ia, char *buffer, size_t bufsiz); | |
| | | | |
|
| /* Free a network address created using ne_iaddr_make. */ | | /* Perform the reverse name lookup on network address 'ia', placing | |
| | | * the returned name in the 'buf' buffer (of length 'bufsiz') if | |
| | | * successful. Returns zero on success, or non-zero on error. */ | |
| | | int ne_iaddr_reverse(const ne_inet_addr *ia, char *buf, size_t bufsiz); | |
| | | | |
| | | /* Destroy a network address object created using ne_iaddr_make. */ | |
| void ne_iaddr_free(ne_inet_addr *addr); | | void ne_iaddr_free(ne_inet_addr *addr); | |
| | | | |
|
| /* Create a TCP socket; returns NULL on error. */ | | /* Create a socket object; returns NULL on error. */ | |
| ne_socket *ne_sock_create(void); | | ne_socket *ne_sock_create(void); | |
| | | | |
| /* Connect the socket to server at address 'addr' on port 'port'. | | /* Connect the socket to server at address 'addr' on port 'port'. | |
|
| * Returns non-zero if a connection could not be established. */ | | * Returns zero on success, NE_SOCK_TIMEOUT if a timeout occurs when a | |
| | | * non-zero connect timeout is configured (and is supported), or | |
| | | * NE_SOCK_ERROR on failure. */ | |
| int ne_sock_connect(ne_socket *sock, const ne_inet_addr *addr, | | int ne_sock_connect(ne_socket *sock, const ne_inet_addr *addr, | |
| unsigned int port); | | unsigned int port); | |
| | | | |
|
| /* ne_sock_read reads up to 'count' bytes into 'buffer'. | | /* Read up to 'count' bytes from socket into 'buffer'. Returns: | |
| * Returns: | | | |
| * NE_SOCK_* on error, | | * NE_SOCK_* on error, | |
|
| * >0 length of data read into buffer. | | * >0 length of data read into buffer (may be less than 'count') | |
| */ | | */ | |
| ssize_t ne_sock_read(ne_socket *sock, char *buffer, size_t count); | | ssize_t ne_sock_read(ne_socket *sock, char *buffer, size_t count); | |
| | | | |
|
| /* ne_sock_peek reads up to 'count' bytes into 'buffer', but the data | | /* Read up to 'count' bytes into 'buffer', leaving the data available | |
| * will still be returned on a subsequent call to ne_sock_read or | | * in the socket buffer to be returned by a subsequent call to | |
| * ne_sock_peek. | | * ne_sock_read or ne_sock_peek. Returns: | |
| * Returns: | | | |
| * NE_SOCK_* on error, | | * NE_SOCK_* on error, | |
| * >0 length of data read into buffer. | | * >0 length of data read into buffer. | |
| */ | | */ | |
| ssize_t ne_sock_peek(ne_socket *sock, char *buffer, size_t count); | | ssize_t ne_sock_peek(ne_socket *sock, char *buffer, size_t count); | |
| | | | |
| /* Block for up to 'n' seconds until data becomes available for reading | | /* Block for up to 'n' seconds until data becomes available for reading | |
|
| * on the socket. Returns: | | * from the socket. Returns: | |
| * NE_SOCK_* on error, | | * NE_SOCK_* on error, | |
|
| * NE_SOCK_TIMEOUT if no data arrives in 'n' seconds. | | * NE_SOCK_TIMEOUT if no data arrives in 'n' seconds, | |
| * 0 if data arrived on the socket. | | * 0 if data arrived on the socket. | |
| */ | | */ | |
| int ne_sock_block(ne_socket *sock, int n); | | int ne_sock_block(ne_socket *sock, int n); | |
| | | | |
|
| /* Writes 'count' bytes of 'data' to the socket. | | /* Write 'count' bytes of 'data' to the socket. Guarantees to either | |
| * Returns 0 on success, NE_SOCK_* on error. */ | | * write all the bytes or to fail. Returns 0 on success, or NE_SOCK_* | |
| | | * on error. */ | |
| int ne_sock_fullwrite(ne_socket *sock, const char *data, size_t count); | | int ne_sock_fullwrite(ne_socket *sock, const char *data, size_t count); | |
| | | | |
|
| /* Reads an LF-terminated line into 'buffer', and NUL-terminate it. | | /* Read an LF-terminated line into 'buffer', and NUL-terminate it. | |
| * At most 'len' bytes are read (including the NUL terminator). | | * At most 'len' bytes are read (including the NUL terminator). | |
| * Returns: | | * Returns: | |
| * NE_SOCK_* on error, | | * NE_SOCK_* on error, | |
| * >0 number of bytes read (including NUL terminator) | | * >0 number of bytes read (including NUL terminator) | |
| */ | | */ | |
| ssize_t ne_sock_readline(ne_socket *sock, char *buffer, size_t len); | | ssize_t ne_sock_readline(ne_socket *sock, char *buffer, size_t len); | |
| | | | |
|
| /* Read exactly 'len' bytes into buffer; returns 0 on success, | | /* Read exactly 'len' bytes into buffer, or fail; returns 0 on | |
| * NE_SOCK_* on error. */ | | * success, NE_SOCK_* on error. */ | |
| ssize_t ne_sock_fullread(ne_socket *sock, char *buffer, size_t len); | | ssize_t ne_sock_fullread(ne_socket *sock, char *buffer, size_t len); | |
| | | | |
|
| /* Accept a connection on listening socket 'fd'. */ | | /* Accepts a connection from listening socket 'fd' and places the | |
| | | * socket in 'sock'. Returns zero on success or -1 on failure. */ | |
| int ne_sock_accept(ne_socket *sock, int fd); | | int ne_sock_accept(ne_socket *sock, int fd); | |
| | | | |
| /* Returns the file descriptor used for socket 'sock'. */ | | /* Returns the file descriptor used for socket 'sock'. */ | |
| int ne_sock_fd(const ne_socket *sock); | | int ne_sock_fd(const ne_socket *sock); | |
| | | | |
|
| /* Close the socket, and destroy the socket object. Returns non-zero | | /* Close the socket and destroy the socket object. Returns zero on | |
| * on error. */ | | * success, or an errno value if close() failed. */ | |
| int ne_sock_close(ne_socket *sock); | | int ne_sock_close(ne_socket *sock); | |
| | | | |
| /* Return current error string for socket. */ | | /* Return current error string for socket. */ | |
| const char *ne_sock_error(const ne_socket *sock); | | const char *ne_sock_error(const ne_socket *sock); | |
| | | | |
|
| /* Set read timeout for socket. */ | | /* Set read timeout for socket, in seconds; must be a non-zero | |
| | | * positive integer. */ | |
| void ne_sock_read_timeout(ne_socket *sock, int timeout); | | void ne_sock_read_timeout(ne_socket *sock, int timeout); | |
| | | | |
|
| | | /* Set connect timeout for socket, in seconds; must be a positive | |
| | | * integer. If a timeout of 'zero' is used then then no explicit | |
| | | * timeout handling will be used for ne_sock_connect(), and the | |
| | | * connect call will only timeout as dictated by the TCP stack. */ | |
| | | void ne_sock_connect_timeout(ne_socket *sock, int timeout); | |
| | | | |
| /* Negotiate an SSL connection on socket as an SSL server, using given | | /* Negotiate an SSL connection on socket as an SSL server, using given | |
| * SSL context. */ | | * SSL context. */ | |
| int ne_sock_accept_ssl(ne_socket *sock, ne_ssl_context *ctx); | | int ne_sock_accept_ssl(ne_socket *sock, ne_ssl_context *ctx); | |
| | | | |
| /* Negotiate an SSL connection on socket as an SSL client, using given | | /* Negotiate an SSL connection on socket as an SSL client, using given | |
| * SSL context. The 'userdata' parameter is associated with the | | * SSL context. The 'userdata' parameter is associated with the | |
| * underlying SSL library's socket structure for use in callbacks. | | * underlying SSL library's socket structure for use in callbacks. | |
| * Returns zero on success, or non-zero on error. */ | | * Returns zero on success, or non-zero on error. */ | |
| int ne_sock_connect_ssl(ne_socket *sock, ne_ssl_context *ctx, | | int ne_sock_connect_ssl(ne_socket *sock, ne_ssl_context *ctx, | |
| void *userdata); | | void *userdata); | |
| | | | |
End of changes. 19 change blocks. |
| 30 lines changed or deleted | | 44 lines changed or added | |
|
| ne_ssl.h | | ne_ssl.h | |
| | | | |
| skipping to change at line 120 | | skipping to change at line 120 | |
| int ne_ssl_cert_cmp(const ne_ssl_certificate *c1, | | int ne_ssl_cert_cmp(const ne_ssl_certificate *c1, | |
| const ne_ssl_certificate *c2); | | const ne_ssl_certificate *c2); | |
| | | | |
| /* Deallocate memory associated with certificate. */ | | /* Deallocate memory associated with certificate. */ | |
| void ne_ssl_cert_free(ne_ssl_certificate *cert); | | void ne_ssl_cert_free(ne_ssl_certificate *cert); | |
| | | | |
| /* A client certificate (and private key). */ | | /* A client certificate (and private key). */ | |
| typedef struct ne_ssl_client_cert_s ne_ssl_client_cert; | | typedef struct ne_ssl_client_cert_s ne_ssl_client_cert; | |
| | | | |
| /* Read a client certificate and private key from a PKCS12 file; | | /* Read a client certificate and private key from a PKCS12 file; | |
|
| * returns NULL if the file could not be parsed. If the client cert | | * returns NULL if the file could not be parsed, or otherwise | |
| * is encrypted, it must be decrypted before use. */ | | * returning a client certificate object. */ | |
| ne_ssl_client_cert *ne_ssl_clicert_read(const char *filename); | | ne_ssl_client_cert *ne_ssl_clicert_read(const char *filename); | |
| | | | |
| /* Returns the "friendly name" given for the client cert, or NULL if | | /* Returns the "friendly name" given for the client cert, or NULL if | |
| * none given. This can be called before or after the client cert has | | * none given. This can be called before or after the client cert has | |
| * been decrypted. Returns a NUL-terminated, UTF-8-encoded string. */ | | * been decrypted. Returns a NUL-terminated, UTF-8-encoded string. */ | |
| const char *ne_ssl_clicert_name(const ne_ssl_client_cert *ccert); | | const char *ne_ssl_clicert_name(const ne_ssl_client_cert *ccert); | |
| | | | |
| /* Returns non-zero if client cert is encrypted. */ | | /* Returns non-zero if client cert is encrypted. */ | |
| int ne_ssl_clicert_encrypted(const ne_ssl_client_cert *ccert); | | int ne_ssl_clicert_encrypted(const ne_ssl_client_cert *ccert); | |
| | | | |
| /* Decrypt the encrypted client cert using given password. Returns | | /* Decrypt the encrypted client cert using given password. Returns | |
| * non-zero on failure, in which case, the function can be called | | * non-zero on failure, in which case, the function can be called | |
| * again with a different password. For a ccert on which _encrypted() | | * again with a different password. For a ccert on which _encrypted() | |
| * returns 0, calling _decrypt results in undefined behaviour. */ | | * returns 0, calling _decrypt results in undefined behaviour. */ | |
| int ne_ssl_clicert_decrypt(ne_ssl_client_cert *ccert, const char *password)
; | | int ne_ssl_clicert_decrypt(ne_ssl_client_cert *ccert, const char *password)
; | |
| | | | |
| /* Return the actual certificate part of the client certificate (never | | /* Return the actual certificate part of the client certificate (never | |
| * returns NULL). */ | | * returns NULL). */ | |
| const ne_ssl_certificate *ne_ssl_clicert_owner(const ne_ssl_client_cert *cc
ert); | | const ne_ssl_certificate *ne_ssl_clicert_owner(const ne_ssl_client_cert *cc
ert); | |
| | | | |
|
| /* Deallocate memory associated with a client certificate. */ | | /* Destroy a client certificate object. */ | |
| void ne_ssl_clicert_free(ne_ssl_client_cert *ccert); | | void ne_ssl_clicert_free(ne_ssl_client_cert *ccert); | |
| | | | |
| /* SSL context object. The interfaces to manipulate an SSL context | | /* SSL context object. The interfaces to manipulate an SSL context | |
| * are only needed when interfacing directly with ne_socket.h. */ | | * are only needed when interfacing directly with ne_socket.h. */ | |
| typedef struct ne_ssl_context_s ne_ssl_context; | | typedef struct ne_ssl_context_s ne_ssl_context; | |
| | | | |
| /* Context creation modes: */ | | /* Context creation modes: */ | |
| #define NE_SSL_CTX_CLIENT (0) /* client context */ | | #define NE_SSL_CTX_CLIENT (0) /* client context */ | |
| #define NE_SSL_CTX_SERVER (1) /* default server context */ | | #define NE_SSL_CTX_SERVER (1) /* default server context */ | |
| #define NE_SSL_CTX_SERVERv2 (2) /* SSLv2-specific server context */ | | #define NE_SSL_CTX_SERVERv2 (2) /* SSLv2-specific server context */ | |
| | | | |
End of changes. 2 change blocks. |
| 3 lines changed or deleted | | 3 lines changed or added | |
|
| ne_string.h | | ne_string.h | |
| /* | | /* | |
| String utility functions | | String utility functions | |
|
| Copyright (C) 1999-2006, Joe Orton <joe@manyfish.co.uk> | | Copyright (C) 1999-2007, Joe Orton <joe@manyfish.co.uk> | |
| | | | |
| This library is free software; you can redistribute it and/or | | This library is free software; you can redistribute it and/or | |
| modify it under the terms of the GNU Library General Public | | modify it under the terms of the GNU Library General Public | |
| License as published by the Free Software Foundation; either | | License as published by the Free Software Foundation; either | |
| version 2 of the License, or (at your option) any later version. | | version 2 of the License, or (at your option) any later version. | |
| | | | |
| This library is distributed in the hope that it will be useful, | | This library is distributed in the hope that it will be useful, | |
| but WITHOUT ANY WARRANTY; without even the implied warranty of | | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| Library General Public License for more details. | | Library General Public License for more details. | |
| | | | |
| skipping to change at line 32 | | skipping to change at line 32 | |
| #ifndef NE_STRING_H | | #ifndef NE_STRING_H | |
| #define NE_STRING_H | | #define NE_STRING_H | |
| | | | |
| #include "ne_defs.h" | | #include "ne_defs.h" | |
| #include "ne_alloc.h" | | #include "ne_alloc.h" | |
| | | | |
| #include <stdarg.h> | | #include <stdarg.h> | |
| | | | |
| NE_BEGIN_DECLS | | NE_BEGIN_DECLS | |
| | | | |
|
| /* ne_token and ne_qtoken return the next token in *str between *str | | /* ne_token and ne_qtoken return the next token in *str before either | |
| * and separator character 'sep' or the NUL terminator. ne_qtoken | | * the next separator character 'sep' or the NUL terminator. | |
| * skips over any parts quoted using a pair of any one of the | | * ne_qtoken skips over any parts quoted using a pair of any one of | |
| * characters given in 'quotes'. After returning, *str will point to | | * the characters given in 'quotes'. After returning, *str will point | |
| * the next character after the separator, or NULL if no more | | * to the next character after the separator, or NULL if no separator | |
| * separator characters were found. | | * character was found. | |
| * | | * | |
|
| * ne_qtoken may return NULL if unterminated quotes are found. */ | | * ne_qtoken will return NULL if unterminated quotes are found. */ | |
| char *ne_token(char **str, char sep); | | char *ne_token(char **str, char sep); | |
| char *ne_qtoken(char **str, char sep, const char *quotes); | | char *ne_qtoken(char **str, char sep, const char *quotes); | |
| | | | |
| /* Return portion of 'str' with any characters in 'whitespace' shaved | | /* Return portion of 'str' with any characters in 'whitespace' shaved | |
|
| * off the beginning and end. Modifies str. */ | | * off the beginning and end. Modifies str in-place. */ | |
| char *ne_shave(char *str, const char *whitespace); | | char *ne_shave(char *str, const char *whitespace); | |
| | | | |
|
| /* Cleanse 'str' of non-printable characters. 'str' is modified | | /* Cleanse 'str' of non-printable (e.g. control) characters. 'str' is | |
| * in-place, and returned. */ | | * modified in-place, and returned. */ | |
| char *ne_strclean(char *str); | | char *ne_strclean(char *str); | |
| | | | |
|
| /* A base64 encoder: converts 'len' bytes of 'text' to base64. | | /* Encode 'len' bytes of 'text' to base64. Returns malloc-allocated | |
| * Returns malloc-allocated buffer; caller must free(). */ | | * NUL-terminated buffer which the caller must free(). */ | |
| char *ne_base64(const unsigned char *text, size_t len); | | char *ne_base64(const unsigned char *text, size_t len); | |
| | | | |
|
| /* Base64 decoder; decodes NUL-terminated base64-encoded string | | /* Decode NUL-terminated base64-encoded string 'data', placing | |
| * 'data', places malloc-allocated raw data in '*out', returns length, | | * malloc-allocated raw decoder output in '*out'. Returns length, or | |
| * or zero on decode error (in which case *out is undefined). */ | | * zero on decode error (in which case the content of *out is | |
| | | * undefined). */ | |
| size_t ne_unbase64(const char *data, unsigned char **out); | | size_t ne_unbase64(const char *data, unsigned char **out); | |
| | | | |
|
| /* String buffer handling. (Strings are zero-terminated still). A | | /* Dynamically-allocated string buffer. A string buffer which grows | |
| * string buffer ne_buffer * which grows dynamically with the | | * dynamically . (Strings are zero-terminated still). A | |
| * string. */ | | * string buffer ne_buffer which grows dynamically with the string. */ | |
| | | | |
| typedef struct { | | typedef struct { | |
|
| char *data; /* contents: null-terminated string. */ | | char *data; /* contents: NUL-terminated string */ | |
| size_t used; /* used bytes in buffer */ | | size_t used; /* strlen(data) + 1 */ | |
| size_t length; /* length of buffer */ | | size_t length; /* number of bytes allocated */ | |
| } ne_buffer; | | } ne_buffer; | |
| | | | |
|
| | | /* Create a new string buffer object. */ | |
| | | ne_buffer *ne_buffer_create(void); | |
| | | | |
| | | /* Create a new string buffer object with at least 'size' bytes of | |
| | | * allocated space. */ | |
| | | ne_buffer *ne_buffer_ncreate(size_t size); | |
| | | | |
| /* Returns size of data in buffer, equiv to strlen(ne_buffer_data(buf)) */ | | /* Returns size of data in buffer, equiv to strlen(ne_buffer_data(buf)) */ | |
| #define ne_buffer_size(buf) ((buf)->used - 1) | | #define ne_buffer_size(buf) ((buf)->used - 1) | |
| | | | |
| /* Concatenate all given strings onto the end of the buffer. The | | /* Concatenate all given strings onto the end of the buffer. The | |
| * strings must all be NUL-terminated, and MUST be followed by a NULL | | * strings must all be NUL-terminated, and MUST be followed by a NULL | |
| * argument marking the end of the list. */ | | * argument marking the end of the list. */ | |
| void ne_buffer_concat(ne_buffer *buf, ...); | | void ne_buffer_concat(ne_buffer *buf, ...); | |
| | | | |
|
| /* Create a new ne_buffer. */ | | | |
| ne_buffer *ne_buffer_create(void); | | | |
| | | | |
| /* Create a new ne_buffer of given minimum size. */ | | | |
| ne_buffer *ne_buffer_ncreate(size_t size); | | | |
| | | | |
| /* Destroys (deallocates) a buffer */ | | | |
| void ne_buffer_destroy(ne_buffer *buf); | | | |
| | | | |
| /* Append a NUL-terminated string 'str' to buf. */ | | /* Append a NUL-terminated string 'str' to buf. */ | |
| void ne_buffer_zappend(ne_buffer *buf, const char *str); | | void ne_buffer_zappend(ne_buffer *buf, const char *str); | |
| | | | |
|
| /* Append 'len' bytes of 'data' to buf. 'data' does not need to be | | /* Append 'len' bytes of 'data' to buf, where 'data' does not contain | |
| * NUL-terminated. The resultant string will have a NUL-terminator, | | * a NUL terminator. (A NUL terminator is appended to buf) */ | |
| * either way. */ | | | |
| void ne_buffer_append(ne_buffer *buf, const char *data, size_t len); | | void ne_buffer_append(ne_buffer *buf, const char *data, size_t len); | |
| | | | |
|
| /* Append a literal constant string 'str' to buffer 'buf'. */ | | /* Print a string to the end of the buffer using printf-style format | |
| | | * string 'format' and subsqeuent arguments. At most 'max' characters | |
| | | * are appended; the number of characters appended (excluding the NUL | |
| | | * terminator) is returned. Behaviour is undefined if 'max' is passed | |
| | | * as zero. */ | |
| | | size_t ne_buffer_snprintf(ne_buffer *buf, size_t max, | |
| | | const char *format, ...) | |
| | | ne_attribute((format(printf, 3, 4))); | |
| | | | |
| | | /* Append a literal, NUL-terminated constant string 'str' to buffer | |
| | | * 'buf'. */ | |
| #define ne_buffer_czappend(buf, str) \ | | #define ne_buffer_czappend(buf, str) \ | |
| ne_buffer_append((buf), (str), sizeof((str)) - 1) | | ne_buffer_append((buf), (str), sizeof((str)) - 1) | |
| | | | |
|
| /* Empties the contents of buf; makes the buffer zero-length. */ | | /* Clear the string buffer 'buf', making it equivalent to the empty | |
| | | * string. */ | |
| void ne_buffer_clear(ne_buffer *buf); | | void ne_buffer_clear(ne_buffer *buf); | |
| | | | |
|
| /* Grows the ne_buffer to a minimum size. */ | | /* Grow the allocated size of string buffer 'buf' to at least 'size' | |
| | | * bytes. */ | |
| void ne_buffer_grow(ne_buffer *buf, size_t size); | | void ne_buffer_grow(ne_buffer *buf, size_t size); | |
| | | | |
|
| | | /* Re-establish the 'used' invariant if the string buffer data field is | |
| | | * altered directly. */ | |
| void ne_buffer_altered(ne_buffer *buf); | | void ne_buffer_altered(ne_buffer *buf); | |
| | | | |
|
| /* Destroys a buffer, WITHOUT freeing the data, and returns the | | /* Destroy the string buffer object 'buf' without deallocating the | |
| * data. */ | | * data string. The data string must subsequently be freed using | |
| | | * ne_free(). */ | |
| char *ne_buffer_finish(ne_buffer *buf); | | char *ne_buffer_finish(ne_buffer *buf); | |
| | | | |
|
| | | /* Destroy a string buffer object. */ | |
| | | void ne_buffer_destroy(ne_buffer *buf); | |
| | | | |
| /* Thread-safe strerror() wrapper; place system error for errno value | | /* Thread-safe strerror() wrapper; place system error for errno value | |
| * 'errnum' in 'buffer', which is of length 'buflen'. Returns | | * 'errnum' in 'buffer', which is of length 'buflen'. Returns | |
| * 'buffer'. */ | | * 'buffer'. */ | |
| char *ne_strerror(int errnum, char *buffer, size_t buflen); | | char *ne_strerror(int errnum, char *buffer, size_t buflen); | |
| | | | |
| /* ne_strnzcpy copies at most 'n'-1 bytes of 'src' to 'dest', and | | /* ne_strnzcpy copies at most 'n'-1 bytes of 'src' to 'dest', and | |
| * ensures that 'dest' is subsequently NUL-terminated. */ | | * ensures that 'dest' is subsequently NUL-terminated. */ | |
|
| #define ne_strnzcpy(dest, src, n) do { \ | | #define ne_strnzcpy(dest, src, n) do { size_t ne__nm1 = (n) - 1; \ | |
| strncpy(dest, src, n-1); dest[n-1] = '\0'; } while (0) | | strncpy(dest, src, ne__nm1); dest[ne__nm1] = '\0'; } while (0) | |
| | | | |
| /* Return malloc-allocated concatenation of all NUL-terminated string | | /* Return malloc-allocated concatenation of all NUL-terminated string | |
|
| * arguments, up to a terminating NULL. */ | | * arguments, up to a terminating NULL pointer. */ | |
| char *ne_concat(const char *str, ...); | | char *ne_concat(const char *str, ...); | |
| | | | |
|
| #define NE_ASC2HEX(x) (((x) <= '9') ? ((x) - '0') : (ne_tolower((x)) + 10 - | | | |
| 'a')) | | | |
| #define NE_HEX2ASC(x) ((char) ((x) > 9 ? ((x) - 10 + 'a') : ((x) + '0'))) | | | |
| | | | |
| /* Wrapper for snprintf: always NUL-terminates returned buffer, and | | /* Wrapper for snprintf: always NUL-terminates returned buffer, and | |
| * returns strlen(str). */ | | * returns strlen(str). */ | |
| size_t ne_snprintf(char *str, size_t size, const char *fmt, ...) | | size_t ne_snprintf(char *str, size_t size, const char *fmt, ...) | |
| ne_attribute((format(printf, 3, 4))); | | ne_attribute((format(printf, 3, 4))); | |
| | | | |
| /* Wrapper for vsnprintf. */ | | /* Wrapper for vsnprintf. */ | |
| size_t ne_vsnprintf(char *str, size_t size, const char *fmt, va_list ap) | | size_t ne_vsnprintf(char *str, size_t size, const char *fmt, va_list ap) | |
| ne_attribute((format(printf, 3, 0))); | | ne_attribute((format(printf, 3, 0))); | |
| | | | |
| /* Implementations of strcasecmp and strncasecmp which behave as | | /* Implementations of strcasecmp and strncasecmp which behave as | |
| | | | |
| skipping to change at line 154 | | skipping to change at line 166 | |
| * differences in case. */ | | * differences in case. */ | |
| int ne_strncasecmp(const char *s1, const char *s2, size_t n); | | int ne_strncasecmp(const char *s1, const char *s2, size_t n); | |
| | | | |
| /* Return lowercase 'c' as in POSIX locale; note difference from ANSI | | /* Return lowercase 'c' as in POSIX locale; note difference from ANSI | |
| * C semantics as both the argument and return value are unsigned | | * C semantics as both the argument and return value are unsigned | |
| * char. */ | | * char. */ | |
| #define ne_tolower(c) (ne_tolower_array()[(unsigned char)c]) | | #define ne_tolower(c) (ne_tolower_array()[(unsigned char)c]) | |
| | | | |
| const unsigned char *ne_tolower_array(void); | | const unsigned char *ne_tolower_array(void); | |
| | | | |
|
| | | /* Convert an ASCII hexadecimal character in the ranges '0'..'9' | |
| | | * 'a'..'f' 'A'..'F' to its numeric equivalent. */ | |
| | | #define NE_ASC2HEX(x) (((x) <= '9') ? ((x) - '0') : \ | |
| | | (ne_tolower((x)) + 10 - 'a')) | |
| | | | |
| | | /* Convert an integer in the range 0..15 to the equivalent (lowercase) | |
| | | * ASCII hexadecimal equivalent character, in the range '0..9,'a..f' */ | |
| | | #define NE_HEX2ASC(x) ((char) ((x) > 9 ? ((x) - 10 + 'a') : ((x) + '0'))) | |
| | | | |
| NE_END_DECLS | | NE_END_DECLS | |
| | | | |
| #endif /* NE_STRING_H */ | | #endif /* NE_STRING_H */ | |
| | | | |
End of changes. 22 change blocks. |
| 47 lines changed or deleted | | 67 lines changed or added | |
|
| ne_utils.h | | ne_utils.h | |
| | | | |
| skipping to change at line 33 | | skipping to change at line 33 | |
| #define NE_UTILS_H | | #define NE_UTILS_H | |
| | | | |
| #include <sys/types.h> | | #include <sys/types.h> | |
| | | | |
| #include <stdarg.h> | | #include <stdarg.h> | |
| #include <stdio.h> | | #include <stdio.h> | |
| | | | |
| #include "ne_defs.h" | | #include "ne_defs.h" | |
| | | | |
| #ifdef NEON_TRIO | | #ifdef NEON_TRIO | |
|
| /* no HAVE_TRIO_H check so this works from outside neon build tree. */ | | | |
| #include <trio.h> | | #include <trio.h> | |
| #endif | | #endif | |
| | | | |
| NE_BEGIN_DECLS | | NE_BEGIN_DECLS | |
| | | | |
|
| /* Returns a human-readable version string like: | | /* Returns a human-readable library version string describing the | |
| * "neon 0.2.0: Library build, OpenSSL support" | | * version and build information; for example: | |
| */ | | * "neon 0.2.0: Library build, OpenSSL support" */ | |
| const char *ne_version_string(void); | | const char *ne_version_string(void); | |
| | | | |
| /* Returns non-zero if library version is not of major version | | /* Returns non-zero if library version is not of major version | |
| * 'major', or if minor version is not greater than or equal to | | * 'major', or if minor version is not greater than or equal to | |
| * 'minor'. For neon versions with major == 0, all minor versions are | | * 'minor'. For neon versions with major == 0, all minor versions are | |
| * presumed to be incompatible. */ | | * presumed to be incompatible. */ | |
| int ne_version_match(int major, int minor); | | int ne_version_match(int major, int minor); | |
| | | | |
|
| | | /* Feature codes: */ | |
| #define NE_FEATURE_SSL (1) /* SSL/TLS support */ | | #define NE_FEATURE_SSL (1) /* SSL/TLS support */ | |
| #define NE_FEATURE_ZLIB (2) /* zlib compression in compress interface */ | | #define NE_FEATURE_ZLIB (2) /* zlib compression in compress interface */ | |
| #define NE_FEATURE_IPV6 (3) /* IPv6 is supported in resolver */ | | #define NE_FEATURE_IPV6 (3) /* IPv6 is supported in resolver */ | |
| #define NE_FEATURE_LFS (4) /* large file support */ | | #define NE_FEATURE_LFS (4) /* large file support */ | |
| #define NE_FEATURE_SOCKS (5) /* SOCKSv5 support */ | | #define NE_FEATURE_SOCKS (5) /* SOCKSv5 support */ | |
| #define NE_FEATURE_TS_SSL (6) /* Thread-safe SSL/TLS support */ | | #define NE_FEATURE_TS_SSL (6) /* Thread-safe SSL/TLS support */ | |
| #define NE_FEATURE_I18N (7) /* i18n error message support */ | | #define NE_FEATURE_I18N (7) /* i18n error message support */ | |
| | | | |
|
| /* Returns non-zero if neon has support for given feature code | | /* Returns non-zero if library is built with support for the given | |
| * NE_FEATURE_*. */ | | * NE_FEATURE_* feature code 'code'. */ | |
| int ne_has_support(int feature); | | int ne_has_support(int feature); | |
| | | | |
|
| /* CONSIDER: mutt has a nicer way of way of doing debugging output... maybe | | /* Debugging macro to allow code to be optimized out if debugging is | |
| * switch to like that. */ | | * disabled at build time. */ | |
| | | | |
| #ifndef NE_DEBUGGING | | #ifndef NE_DEBUGGING | |
| #define NE_DEBUG if (0) ne_debug | | #define NE_DEBUG if (0) ne_debug | |
| #else /* DEBUGGING */ | | #else /* DEBUGGING */ | |
| #define NE_DEBUG ne_debug | | #define NE_DEBUG ne_debug | |
| #endif /* DEBUGGING */ | | #endif /* DEBUGGING */ | |
| | | | |
|
| #define NE_DBG_SOCKET (1<<0) | | /* Debugging masks. */ | |
| #define NE_DBG_HTTP (1<<1) | | #define NE_DBG_SOCKET (1<<0) /* raw socket */ | |
| #define NE_DBG_XML (1<<2) | | #define NE_DBG_HTTP (1<<1) /* HTTP request/response handling */ | |
| #define NE_DBG_HTTPAUTH (1<<3) | | #define NE_DBG_XML (1<<2) /* XML parser */ | |
| #define NE_DBG_HTTPPLAIN (1<<4) | | #define NE_DBG_HTTPAUTH (1<<3) /* HTTP authentication (hiding credentials) | |
| #define NE_DBG_LOCKS (1<<5) | | */ | |
| #define NE_DBG_XMLPARSE (1<<6) | | #define NE_DBG_HTTPPLAIN (1<<4) /* plaintext HTTP authentication */ | |
| #define NE_DBG_HTTPBODY (1<<7) | | #define NE_DBG_LOCKS (1<<5) /* WebDAV locking */ | |
| #define NE_DBG_SSL (1<<8) | | #define NE_DBG_XMLPARSE (1<<6) /* low-level XML parser */ | |
| #define NE_DBG_FLUSH (1<<30) | | #define NE_DBG_HTTPBODY (1<<7) /* HTTP response body blocks */ | |
| | | #define NE_DBG_SSL (1<<8) /* SSL/TLS */ | |
| | | #define NE_DBG_FLUSH (1<<30) /* always flush debugging */ | |
| | | | |
| /* Send debugging output to 'stream', for all of the given debug | | /* Send debugging output to 'stream', for all of the given debug | |
| * channels. To disable debugging, pass 'stream' as NULL and 'mask' | | * channels. To disable debugging, pass 'stream' as NULL and 'mask' | |
| * as 0. */ | | * as 0. */ | |
| void ne_debug_init(FILE *stream, int mask); | | void ne_debug_init(FILE *stream, int mask); | |
| | | | |
| /* The current debug mask and stream set by the last call to | | /* The current debug mask and stream set by the last call to | |
| * ne_debug_init. */ | | * ne_debug_init. */ | |
| extern int ne_debug_mask; | | extern int ne_debug_mask; | |
| extern FILE *ne_debug_stream; | | extern FILE *ne_debug_stream; | |
| | | | |
| skipping to change at line 108 | | skipping to change at line 108 | |
| int major_version; | | int major_version; | |
| int minor_version; | | int minor_version; | |
| int code; /* Status-Code value */ | | int code; /* Status-Code value */ | |
| int klass; /* Class of Status-Code (1-5) */ | | int klass; /* Class of Status-Code (1-5) */ | |
| char *reason_phrase; | | char *reason_phrase; | |
| } ne_status; | | } ne_status; | |
| | | | |
| /* NB: couldn't use 'class' in ne_status because it would clash with | | /* NB: couldn't use 'class' in ne_status because it would clash with | |
| * the C++ reserved word. */ | | * the C++ reserved word. */ | |
| | | | |
|
| /* Parser for strings which follow the Status-Line grammar from | | /* Parse 'status_line' using the the RFC2616 Status-Line grammar. | |
| * RFC2616. s->reason_phrase is malloc-allocated if non-NULL, and | | * s->reason_phrase is malloc-allocated if non-NULL, and must be | |
| * must be free'd by the caller. | | * free'd by the caller. Returns 0 on success, in which case all | |
| * Returns: | | * fields of '*s' will be set; or -1 on parse error, in which case | |
| * 0 on success, *s will be filled in. | | * '*s' is unmodified. */ | |
| * -1 on parse error. | | | |
| */ | | | |
| int ne_parse_statusline(const char *status_line, ne_status *s); | | int ne_parse_statusline(const char *status_line, ne_status *s); | |
| | | | |
| NE_END_DECLS | | NE_END_DECLS | |
| | | | |
| #endif /* NE_UTILS_H */ | | #endif /* NE_UTILS_H */ | |
| | | | |
End of changes. 7 change blocks. |
| 26 lines changed or deleted | | 25 lines changed or added | |
|
| ne_xml.h | | ne_xml.h | |
| /* | | /* | |
| neon XML parser interface | | neon XML parser interface | |
|
| Copyright (C) 1999-2004, Joe Orton <joe@manyfish.co.uk> | | Copyright (C) 1999-2007, Joe Orton <joe@manyfish.co.uk> | |
| | | | |
| This library is free software; you can redistribute it and/or | | This library is free software; you can redistribute it and/or | |
| modify it under the terms of the GNU Library General Public | | modify it under the terms of the GNU Library General Public | |
| License as published by the Free Software Foundation; either | | License as published by the Free Software Foundation; either | |
| version 2 of the License, or (at your option) any later version. | | version 2 of the License, or (at your option) any later version. | |
| | | | |
| This library is distributed in the hope that it will be useful, | | This library is distributed in the hope that it will be useful, | |
| but WITHOUT ANY WARRANTY; without even the implied warranty of | | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| Library General Public License for more details. | | Library General Public License for more details. | |
| | | | |
| skipping to change at line 91 | | skipping to change at line 91 | |
| /* Push a new handler on the stack of parser 'p'. 'cdata' and/or | | /* Push a new handler on the stack of parser 'p'. 'cdata' and/or | |
| * 'endelm' may be NULL; startelm must be non-NULL. */ | | * 'endelm' may be NULL; startelm must be non-NULL. */ | |
| void ne_xml_push_handler(ne_xml_parser *p, | | void ne_xml_push_handler(ne_xml_parser *p, | |
| ne_xml_startelm_cb *startelm, | | ne_xml_startelm_cb *startelm, | |
| ne_xml_cdata_cb *cdata, | | ne_xml_cdata_cb *cdata, | |
| ne_xml_endelm_cb *endelm, | | ne_xml_endelm_cb *endelm, | |
| void *userdata); | | void *userdata); | |
| | | | |
| /* ne_xml_failed returns non-zero if there was an error during | | /* ne_xml_failed returns non-zero if there was an error during | |
| * parsing, or zero if the parse completed successfully. The return | | * parsing, or zero if the parse completed successfully. The return | |
|
| * value is equal to that of the last ne_xml_parse call for this | | * value is equal to that of the last ne_xml_parse() call for this | |
| * parser. */ | | * parser object. */ | |
| int ne_xml_failed(ne_xml_parser *p); | | int ne_xml_failed(ne_xml_parser *p); | |
| | | | |
|
| /* Set error string for parser: the string may be truncated. */ | | /* Set error string for parser. (The string may be truncated | |
| | | * internally). */ | |
| void ne_xml_set_error(ne_xml_parser *p, const char *msg); | | void ne_xml_set_error(ne_xml_parser *p, const char *msg); | |
| | | | |
|
| /* Return the error string (never NULL). After ne_xml_failed returns | | /* Return the error string (and never NULL). After ne_xml_failed | |
| * >0, this will describe the parse error. Otherwise it will be a | | * returns >0, this will describe the parse error. Otherwise it will | |
| * default error string. */ | | * be a default error string. */ | |
| const char *ne_xml_get_error(ne_xml_parser *p); | | const char *ne_xml_get_error(ne_xml_parser *p); | |
| | | | |
|
| /* Destroy the parser object. */ | | | |
| void ne_xml_destroy(ne_xml_parser *p); | | | |
| | | | |
| /* Parse the given block of input of length len. Parser must be | | /* Parse the given block of input of length len. Parser must be | |
| * called with len=0 to signify the end of the document (for that | | * called with len=0 to signify the end of the document (for that | |
| * case, the block argument is ignored). Returns zero on success, or | | * case, the block argument is ignored). Returns zero on success, or | |
| * non-zero on error: for an XML syntax error, a positive number is | | * non-zero on error: for an XML syntax error, a positive number is | |
| * returned; if parsing is aborted by a caller-supplied callback, that | | * returned; if parsing is aborted by a caller-supplied callback, that | |
| * callback's return value is returned. */ | | * callback's return value is returned. */ | |
| int ne_xml_parse(ne_xml_parser *p, const char *block, size_t len); | | int ne_xml_parse(ne_xml_parser *p, const char *block, size_t len); | |
| | | | |
|
| /* As above, casting (ne_xml_parser *)userdata internally. | | /* As ne_xml_parse, casting (ne_xml_parser *)userdata internally. | |
| * (This function can be passed to ne_add_response_body_reader) */ | | * (This function can be passed to ne_add_response_body_reader) */ | |
| int ne_xml_parse_v(void *userdata, const char *block, size_t len); | | int ne_xml_parse_v(void *userdata, const char *block, size_t len); | |
| | | | |
|
| /* Return current parse line for errors */ | | /* Return current line of document during parsing or after parsing is | |
| | | * complete. */ | |
| int ne_xml_currentline(ne_xml_parser *p); | | int ne_xml_currentline(ne_xml_parser *p); | |
| | | | |
| /* From a start_element callback which was passed 'attrs' using given | | /* From a start_element callback which was passed 'attrs' using given | |
| * parser, return attribute of given name and namespace. If nspace is | | * parser, return attribute of given name and namespace. If nspace is | |
|
| * NULL, no namespace resolution is performed. */ | | * NULL, no namespace resolution is performed. Note that this call is | |
| | | * context-specific; if called outside a start_element callback, | |
| | | * behaviour is undefined. */ | |
| const char *ne_xml_get_attr(ne_xml_parser *parser, | | const char *ne_xml_get_attr(ne_xml_parser *parser, | |
| const char **attrs, const char *nspace, | | const char **attrs, const char *nspace, | |
| const char *name); | | const char *name); | |
| | | | |
|
| | | /* From a start_element callback, resolve a given XML Namespace | |
| | | * prefix, if defined. Given a non-NULL prefix, returns the namespace | |
| | | * URI which corresponds to the prefix 'prefix' (of length 'length'), | |
| | | * or NULL if no such namespace prefix is defined. Given a NULL | |
| | | * prefix, returns the default namespace URI or the empty string if | |
| | | * none is defined. Note that this call is context-specific; if | |
| | | * called outside a start_element callback, behaviour is undefined. */ | |
| | | const char *ne_xml_resolve_nspace(ne_xml_parser *parser, | |
| | | const char *prefix, size_t length); | |
| | | | |
| /* Return the encoding of the document being parsed. May return NULL | | /* Return the encoding of the document being parsed. May return NULL | |
| * if no encoding is defined or if the XML declaration has not yet | | * if no encoding is defined or if the XML declaration has not yet | |
| * been parsed. */ | | * been parsed. */ | |
| const char *ne_xml_doc_encoding(const ne_xml_parser *p); | | const char *ne_xml_doc_encoding(const ne_xml_parser *p); | |
| | | | |
|
| | | /* Destroy the parser object. */ | |
| | | void ne_xml_destroy(ne_xml_parser *p); | |
| | | | |
| /* A utility interface for mapping {nspace, name} onto an integer. */ | | /* A utility interface for mapping {nspace, name} onto an integer. */ | |
| struct ne_xml_idmap { | | struct ne_xml_idmap { | |
| const char *nspace, *name; | | const char *nspace, *name; | |
| int id; | | int id; | |
| }; | | }; | |
| | | | |
| /* Return the size of an idmap array */ | | /* Return the size of an idmap array */ | |
| #define NE_XML_MAPLEN(map) (sizeof(map) / sizeof(struct ne_xml_idmap)) | | #define NE_XML_MAPLEN(map) (sizeof(map) / sizeof(struct ne_xml_idmap)) | |
| | | | |
| /* Return the 'id' corresponding to {nspace, name}, or zero. */ | | /* Return the 'id' corresponding to {nspace, name}, or zero. */ | |
| | | | |
End of changes. 10 change blocks. |
| 13 lines changed or deleted | | 27 lines changed or added | |
|