| serf.h | | serf.h | |
| | | | |
| skipping to change at line 30 | | skipping to change at line 30 | |
| * @file serf.h | | * @file serf.h | |
| * @brief Main serf header file | | * @brief Main serf header file | |
| */ | | */ | |
| | | | |
| #include <apr.h> | | #include <apr.h> | |
| #include <apr_errno.h> | | #include <apr_errno.h> | |
| #include <apr_allocator.h> | | #include <apr_allocator.h> | |
| #include <apr_pools.h> | | #include <apr_pools.h> | |
| #include <apr_network_io.h> | | #include <apr_network_io.h> | |
| #include <apr_time.h> | | #include <apr_time.h> | |
|
| | | #include <apr_poll.h> | |
| | | #include <apr_uri.h> | |
| | | | |
| #include "serf_declare.h" | | #include "serf_declare.h" | |
| | | | |
| #ifdef __cplusplus | | #ifdef __cplusplus | |
| extern "C" { | | extern "C" { | |
| #endif | | #endif | |
| | | | |
| /* Forward declare some structures */ | | /* Forward declare some structures */ | |
| typedef struct serf_context_t serf_context_t; | | typedef struct serf_context_t serf_context_t; | |
| | | | |
| | | | |
| skipping to change at line 79 | | skipping to change at line 81 | |
| /** | | /** | |
| * Create a new context for serf operations. | | * Create a new context for serf operations. | |
| * | | * | |
| * A serf context defines a control loop which processes multiple | | * A serf context defines a control loop which processes multiple | |
| * connections simultaneously. | | * connections simultaneously. | |
| * | | * | |
| * The context will be allocated within @a pool. | | * The context will be allocated within @a pool. | |
| */ | | */ | |
| SERF_DECLARE(serf_context_t *) serf_context_create(apr_pool_t *pool); | | SERF_DECLARE(serf_context_t *) serf_context_create(apr_pool_t *pool); | |
| | | | |
|
| | | /** | |
| | | * Callback function. Add a socket to the externally managed poll set. | |
| | | * | |
| | | * Both @a pfd and @a serf_baton should be used when calling serf_event_tri | |
| | | gger | |
| | | * later. | |
| | | */ | |
| | | typedef apr_status_t (*serf_socket_add_t)(void *user_baton, | |
| | | apr_pollfd_t *pfd, | |
| | | void *serf_baton); | |
| | | /** | |
| | | * Callback function. Remove the socket, identified by both @a pfd and | |
| | | * @a serf_baton from the externally managed poll set. | |
| | | */ | |
| | | typedef apr_status_t (*serf_socket_remove_t)(void *user_baton, | |
| | | apr_pollfd_t *pfd, | |
| | | void *serf_baton); | |
| | | | |
| | | /* Create a new context for serf operations. | |
| | | * | |
| | | * Use this function to make serf not use its internal control loop, but | |
| | | * instead rely on an external event loop. Serf will use the @a addf and @a | |
| | | rmf | |
| | | * callbacks to notify of any event on a connection. The @a user_baton will | |
| | | be | |
| | | * passed through the addf and rmf callbacks. | |
| | | * | |
| | | * The context will be allocated within @a pool. | |
| | | */ | |
| | | SERF_DECLARE(serf_context_t *) serf_context_create_ex(void *user_baton, | |
| | | serf_socket_add_t add | |
| | | f, | |
| | | serf_socket_remove_t | |
| | | rmf, | |
| | | apr_pool_t *pool); | |
| | | | |
| | | /** | |
| | | * Make serf process events on a connection, identified by both @a pfd and | |
| | | * @a serf_baton. | |
| | | * | |
| | | * Any outbound data is delivered, and incoming data is made available to | |
| | | * the associated response handlers and their buckets. | |
| | | * | |
| | | * If any data is processed (incoming or outgoing), then this function will | |
| | | * return with APR_SUCCESS. | |
| | | */ | |
| | | SERF_DECLARE(apr_status_t) serf_event_trigger(serf_context_t *s, | |
| | | void *serf_baton, | |
| | | const apr_pollfd_t *pfd); | |
| | | | |
| /** @see serf_context_run should not block at all. */ | | /** @see serf_context_run should not block at all. */ | |
| #define SERF_DURATION_NOBLOCK 0 | | #define SERF_DURATION_NOBLOCK 0 | |
| /** @see serf_context_run should run for (nearly) "forever". */ | | /** @see serf_context_run should run for (nearly) "forever". */ | |
| #define SERF_DURATION_FOREVER 2000000000 /* approx 1^31 */ | | #define SERF_DURATION_FOREVER 2000000000 /* approx 1^31 */ | |
| | | | |
| /** | | /** | |
| * Run the main networking control loop. | | * Run the main networking control loop. | |
| * | | * | |
| * The set of connections defined by the serf context @a ctx are processed. | | * The set of connections defined by the serf context @a ctx are processed. | |
| * Any outbound data is delivered, and incoming data is made available to | | * Any outbound data is delivered, and incoming data is made available to | |
| | | | |
| skipping to change at line 105 | | skipping to change at line 152 | |
| * | | * | |
| * If no activity occurs within the specified timeout duration, then | | * If no activity occurs within the specified timeout duration, then | |
| * APR_TIMEUP is returned. | | * APR_TIMEUP is returned. | |
| * | | * | |
| * All temporary allocations will be made in @a pool. | | * All temporary allocations will be made in @a pool. | |
| */ | | */ | |
| SERF_DECLARE(apr_status_t) serf_context_run(serf_context_t *ctx, | | SERF_DECLARE(apr_status_t) serf_context_run(serf_context_t *ctx, | |
| apr_short_interval_time_t durat
ion, | | apr_short_interval_time_t durat
ion, | |
| apr_pool_t *pool); | | apr_pool_t *pool); | |
| | | | |
|
| | | SERF_DECLARE(apr_status_t) serf_context_prerun(serf_context_t *ctx); | |
| | | | |
| | | /** | |
| | | * Callback function for progress information. @a progress indicates cumula | |
| | | tive | |
| | | * number of bytes read or written, for the whole context. | |
| | | */ | |
| | | typedef void (*serf_progress_t)(void *progress_baton, | |
| | | apr_off_t read, | |
| | | apr_off_t write); | |
| | | | |
| | | /** | |
| | | * Sets the progress callback function. @a progress_func will be called eve | |
| | | ry | |
| | | * time bytes are read of or written on a socket. | |
| | | */ | |
| | | SERF_DECLARE(void) serf_context_set_progress_cb( | |
| | | serf_context_t *ctx, | |
| | | const serf_progress_t progress_func, | |
| | | void *progress_baton); | |
| | | | |
| /** @} */ | | /** @} */ | |
| | | | |
| /** | | /** | |
| * @defgroup serf connections and requests | | * @defgroup serf connections and requests | |
| * @ingroup serf | | * @ingroup serf | |
| * @{ | | * @{ | |
| */ | | */ | |
| | | | |
| /** | | /** | |
| * When a connection is established, the application needs to wrap some | | * When a connection is established, the application needs to wrap some | |
| | | | |
| skipping to change at line 256 | | skipping to change at line 322 | |
| SERF_DECLARE(serf_connection_t *) serf_connection_create( | | SERF_DECLARE(serf_connection_t *) serf_connection_create( | |
| serf_context_t *ctx, | | serf_context_t *ctx, | |
| apr_sockaddr_t *address, | | apr_sockaddr_t *address, | |
| serf_connection_setup_t setup, | | serf_connection_setup_t setup, | |
| void *setup_baton, | | void *setup_baton, | |
| serf_connection_closed_t closed, | | serf_connection_closed_t closed, | |
| void *closed_baton, | | void *closed_baton, | |
| apr_pool_t *pool); | | apr_pool_t *pool); | |
| | | | |
| /** | | /** | |
|
| | | * Create a new connection associated with the @a ctx serf context. | |
| | | * | |
| | | * A connection will be created to (eventually) connect to the address | |
| | | * specified by @a address. The address must live at least as long as | |
| | | * @a pool (thus, as long as the connection object). | |
| | | * | |
| | | * The host address will be looked up based on the hostname in @a host_info | |
| | | . | |
| | | * | |
| | | * The connection object will be allocated within @a pool. Clearing or | |
| | | * destroying this pool will close the connection, and terminate any | |
| | | * outstanding requests or responses. | |
| | | * | |
| | | * When the connection is closed (upon request or because of an error), | |
| | | * then the @a closed callback is invoked, and @a closed_baton is passed. | |
| | | * | |
| | | * ### doc on setup(_baton). tweak below comment re: acceptor. | |
| | | * NULL may be passed for @a acceptor and @a closed; default implementation | |
| | | s | |
| | | * will be used. | |
| | | * | |
| | | * Note: the connection is not made immediately. It will be opened on | |
| | | * the next call to @see serf_context_run. | |
| | | */ | |
| | | SERF_DECLARE(apr_status_t) serf_connection_create2( | |
| | | serf_connection_t **conn, | |
| | | serf_context_t *ctx, | |
| | | apr_uri_t host_info, | |
| | | serf_connection_setup_t setup, | |
| | | void *setup_baton, | |
| | | serf_connection_closed_t closed, | |
| | | void *closed_baton, | |
| | | apr_pool_t *pool); | |
| | | | |
| | | /** | |
| * Reset the connection, but re-open the socket again. | | * Reset the connection, but re-open the socket again. | |
| */ | | */ | |
| SERF_DECLARE(apr_status_t) serf_connection_reset( | | SERF_DECLARE(apr_status_t) serf_connection_reset( | |
| serf_connection_t *conn); | | serf_connection_t *conn); | |
| | | | |
| /** | | /** | |
| * Close the connection associated with @a conn and cancel all pending requ
ests. | | * Close the connection associated with @a conn and cancel all pending requ
ests. | |
| * | | * | |
| * The closed callback passed to serf_connection_create() will be invoked | | * The closed callback passed to serf_connection_create() will be invoked | |
| * with APR_SUCCESS. | | * with APR_SUCCESS. | |
| */ | | */ | |
| SERF_DECLARE(apr_status_t) serf_connection_close( | | SERF_DECLARE(apr_status_t) serf_connection_close( | |
| serf_connection_t *conn); | | serf_connection_t *conn); | |
| | | | |
| /** | | /** | |
|
| | | * Sets the maximum number of outstanding requests @a max_requests on the | |
| | | * connection @a conn. Setting max_requests to 0 means unlimited (the defau | |
| | | lt). | |
| | | * Ex.: setting max_requests to 1 means a request is sent when a response o | |
| | | n the | |
| | | * previous request was received and handled. | |
| | | */ | |
| | | SERF_DECLARE(void) | |
| | | serf_connection_set_max_outstanding_requests(serf_connection_t *conn, | |
| | | unsigned int max_requests); | |
| | | | |
| | | /** | |
| * Setup the @a request for delivery on its connection. | | * Setup the @a request for delivery on its connection. | |
| * | | * | |
| * Right before this is invoked, @a pool will be built within the | | * Right before this is invoked, @a pool will be built within the | |
| * connection's pool for the request to use. The associated response will | | * connection's pool for the request to use. The associated response will | |
| * be allocated within that subpool. An associated bucket allocator will | | * be allocated within that subpool. An associated bucket allocator will | |
| * be built. These items may be fetched from the request object through | | * be built. These items may be fetched from the request object through | |
| * @see serf_request_get_pool or @see serf_request_get_alloc. | | * @see serf_request_get_pool or @see serf_request_get_alloc. | |
| * | | * | |
| * The content of the request is specified by the @a req_bkt bucket. When | | * The content of the request is specified by the @a req_bkt bucket. When | |
| * a response arrives, the @a acceptor callback will be invoked (along with | | * a response arrives, the @a acceptor callback will be invoked (along with | |
| | | | |
| skipping to change at line 315 | | skipping to change at line 424 | |
| * | | * | |
| * Invoking any calls other than @see serf_request_cancel before the setup | | * Invoking any calls other than @see serf_request_cancel before the setup | |
| * callback executes is not supported. | | * callback executes is not supported. | |
| */ | | */ | |
| SERF_DECLARE(serf_request_t *) serf_connection_request_create( | | SERF_DECLARE(serf_request_t *) serf_connection_request_create( | |
| serf_connection_t *conn, | | serf_connection_t *conn, | |
| serf_request_setup_t setup, | | serf_request_setup_t setup, | |
| void *setup_baton); | | void *setup_baton); | |
| | | | |
| /** | | /** | |
|
| | | * Construct a request object for the @a conn connection, add it in the | |
| | | * list as the next to-be-written request before all unwritten requests. | |
| | | * | |
| | | * When it is time to deliver the request, the @a setup callback will | |
| | | * be invoked with the @a setup_baton passed into it to complete the | |
| | | * construction of the request object. | |
| | | * | |
| | | * If the request has not (yet) been delivered, then it may be canceled | |
| | | * with @see serf_request_cancel. | |
| | | * | |
| | | * Invoking any calls other than @see serf_request_cancel before the setup | |
| | | * callback executes is not supported. | |
| | | */ | |
| | | SERF_DECLARE(serf_request_t *) serf_connection_priority_request_create( | |
| | | serf_connection_t *conn, | |
| | | serf_request_setup_t setup, | |
| | | void *setup_baton); | |
| | | | |
| | | /** | |
| * Cancel the request specified by the @a request object. | | * Cancel the request specified by the @a request object. | |
| * | | * | |
| * If the request has been scheduled for delivery, then its response | | * If the request has been scheduled for delivery, then its response | |
| * handler will be run, passing NULL for the response bucket. | | * handler will be run, passing NULL for the response bucket. | |
| * | | * | |
| * If the request has already been (partially or fully) delivered, then | | * If the request has already been (partially or fully) delivered, then | |
| * APR_EBUSY is returned and the request is *NOT* canceled. To properly | | * APR_EBUSY is returned and the request is *NOT* canceled. To properly | |
| * cancel the request, the connection must be closed (by clearing or | | * cancel the request, the connection must be closed (by clearing or | |
| * destroying its associated pool). | | * destroying its associated pool). | |
| */ | | */ | |
| | | | |
| skipping to change at line 360 | | skipping to change at line 488 | |
| * Update the @a handler and @a handler_baton for this @a request. | | * Update the @a handler and @a handler_baton for this @a request. | |
| * | | * | |
| * This can be called after the request has started processing - | | * This can be called after the request has started processing - | |
| * subsequent data will be delivered to this new handler. | | * subsequent data will be delivered to this new handler. | |
| */ | | */ | |
| SERF_DECLARE(void) serf_request_set_handler( | | SERF_DECLARE(void) serf_request_set_handler( | |
| serf_request_t *request, | | serf_request_t *request, | |
| const serf_response_handler_t handler, | | const serf_response_handler_t handler, | |
| const void **handler_baton); | | const void **handler_baton); | |
| | | | |
|
| | | /** | |
| | | * Configure proxy server settings, to be used by all connections associate | |
| | | d | |
| | | * with the @a ctx serf context. | |
| | | * | |
| | | * The next connection will be created to connect to the proxy server | |
| | | * specified by @a address. The address must live at least as long as the | |
| | | * serf context. | |
| | | */ | |
| | | SERF_DECLARE(void) serf_config_proxy( | |
| | | serf_context_t *ctx, | |
| | | apr_sockaddr_t *address); | |
| | | | |
| /* ### maybe some connection control functions for flood? */ | | /* ### maybe some connection control functions for flood? */ | |
| | | | |
|
| | | /*** Special bucket creation functions ***/ | |
| | | | |
| | | /** | |
| | | * Create a bucket of type 'socket bucket'. | |
| | | * This is basically a wrapper around @a serf_bucket_socket_create, which | |
| | | * initializes the bucket using connection and/or context specific settings | |
| | | . | |
| | | */ | |
| | | SERF_DECLARE(serf_bucket_t *) serf_context_bucket_socket_create( | |
| | | serf_context_t *ctx, | |
| | | apr_socket_t *skt, | |
| | | serf_bucket_alloc_t *allocator); | |
| | | | |
| | | /** | |
| | | * Create a bucket of type 'request bucket'. | |
| | | * This is basically a wrapper around @a serf_bucket_request_create, which | |
| | | * initializes the bucket using request, connection and/or context specific | |
| | | * settings. | |
| | | * | |
| | | * If the host_url and/or user_agent options are set on the connection, | |
| | | * headers 'Host' and/or 'User-Agent' will be set on the request message. | |
| | | */ | |
| | | SERF_DECLARE(serf_bucket_t *) serf_request_bucket_request_create( | |
| | | serf_request_t *request, | |
| | | const char *method, | |
| | | const char *uri, | |
| | | serf_bucket_t *body, | |
| | | serf_bucket_alloc_t *allocator); | |
| | | | |
| /** @} */ | | /** @} */ | |
| | | | |
| /** | | /** | |
| * @defgroup serf buckets | | * @defgroup serf buckets | |
| * @ingroup serf | | * @ingroup serf | |
| * @{ | | * @{ | |
| */ | | */ | |
| | | | |
| /** Pass as REQUESTED to the read function of a bucket to read, consume, | | /** Pass as REQUESTED to the read function of a bucket to read, consume, | |
| * and return all available data. | | * and return all available data. | |
| | | | |
| skipping to change at line 710 | | skipping to change at line 878 | |
| SERF_DECLARE(apr_status_t) serf_debug__record_read( | | SERF_DECLARE(apr_status_t) serf_debug__record_read( | |
| const serf_bucket_t *bucket, | | const serf_bucket_t *bucket, | |
| apr_status_t status); | | apr_status_t status); | |
| SERF_DECLARE(void) serf_debug__entered_loop(serf_bucket_alloc_t *allocator)
; | | SERF_DECLARE(void) serf_debug__entered_loop(serf_bucket_alloc_t *allocator)
; | |
| SERF_DECLARE(void) serf_debug__closed_conn(serf_bucket_alloc_t *allocator); | | SERF_DECLARE(void) serf_debug__closed_conn(serf_bucket_alloc_t *allocator); | |
| SERF_DECLARE(void) serf_debug__bucket_destroy(const serf_bucket_t *bucket); | | SERF_DECLARE(void) serf_debug__bucket_destroy(const serf_bucket_t *bucket); | |
| SERF_DECLARE(void) serf_debug__bucket_alloc_check(serf_bucket_alloc_t *allo
cator); | | SERF_DECLARE(void) serf_debug__bucket_alloc_check(serf_bucket_alloc_t *allo
cator); | |
| | | | |
| /* Version info */ | | /* Version info */ | |
| #define SERF_MAJOR_VERSION 0 | | #define SERF_MAJOR_VERSION 0 | |
|
| #define SERF_MINOR_VERSION 1 | | #define SERF_MINOR_VERSION 2 | |
| #define SERF_PATCH_VERSION 2 | | #define SERF_PATCH_VERSION 0 | |
| | | | |
| | | /* Version number string */ | |
| | | #define SERF_VERSION_STRING APR_STRINGIFY(SERF_MAJOR_VERSION) "." \ | |
| | | APR_STRINGIFY(SERF_MINOR_VERSION) "." \ | |
| | | APR_STRINGIFY(SERF_PATCH_VERSION) | |
| | | | |
| /** | | /** | |
| * Check at compile time if the Serf version is at least a certain | | * Check at compile time if the Serf version is at least a certain | |
| * level. | | * level. | |
| * @param major The major version component of the version checked | | * @param major The major version component of the version checked | |
| * for (e.g., the "1" of "1.3.0"). | | * for (e.g., the "1" of "1.3.0"). | |
| * @param minor The minor version component of the version checked | | * @param minor The minor version component of the version checked | |
| * for (e.g., the "3" of "1.3.0"). | | * for (e.g., the "3" of "1.3.0"). | |
| * @param patch The patch level component of the version checked | | * @param patch The patch level component of the version checked | |
| * for (e.g., the "0" of "1.3.0"). | | * for (e.g., the "0" of "1.3.0"). | |
| | | | |
End of changes. 9 change blocks. |
| 2 lines changed or deleted | | 188 lines changed or added | |
|