|
||||
File indexing completed on 2025-01-18 09:57:12
0001 /* 0002 * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu> 0003 * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 0004 * 0005 * Redistribution and use in source and binary forms, with or without 0006 * modification, are permitted provided that the following conditions 0007 * are met: 0008 * 1. Redistributions of source code must retain the above copyright 0009 * notice, this list of conditions and the following disclaimer. 0010 * 2. Redistributions in binary form must reproduce the above copyright 0011 * notice, this list of conditions and the following disclaimer in the 0012 * documentation and/or other materials provided with the distribution. 0013 * 3. The name of the author may not be used to endorse or promote products 0014 * derived from this software without specific prior written permission. 0015 * 0016 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 0017 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 0018 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 0019 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 0020 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 0021 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 0022 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 0023 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0024 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 0025 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0026 */ 0027 #ifndef EVENT2_HTTP_H_INCLUDED_ 0028 #define EVENT2_HTTP_H_INCLUDED_ 0029 0030 /* For int types. */ 0031 #include <event2/util.h> 0032 #include <event2/visibility.h> 0033 0034 #ifdef __cplusplus 0035 extern "C" { 0036 #endif 0037 0038 /* In case we haven't included the right headers yet. */ 0039 struct evbuffer; 0040 struct event_base; 0041 struct bufferevent; 0042 struct evhttp_connection; 0043 0044 /** @file event2/http.h 0045 * 0046 * Basic support for HTTP serving. 0047 * 0048 * As Libevent is a library for dealing with event notification and most 0049 * interesting applications are networked today, I have often found the 0050 * need to write HTTP code. The following prototypes and definitions provide 0051 * an application with a minimal interface for making HTTP requests and for 0052 * creating a very simple HTTP server. 0053 */ 0054 0055 /* Response codes */ 0056 #define HTTP_OK 200 /**< request completed ok */ 0057 #define HTTP_NOCONTENT 204 /**< request does not have content */ 0058 #define HTTP_MOVEPERM 301 /**< the uri moved permanently */ 0059 #define HTTP_MOVETEMP 302 /**< the uri moved temporarily */ 0060 #define HTTP_NOTMODIFIED 304 /**< page was not modified from last */ 0061 #define HTTP_BADREQUEST 400 /**< invalid http request was made */ 0062 #define HTTP_NOTFOUND 404 /**< could not find content for uri */ 0063 #define HTTP_BADMETHOD 405 /**< method not allowed for this uri */ 0064 #define HTTP_ENTITYTOOLARGE 413 /**< */ 0065 #define HTTP_EXPECTATIONFAILED 417 /**< we can't handle this expectation */ 0066 #define HTTP_INTERNAL 500 /**< internal error */ 0067 #define HTTP_NOTIMPLEMENTED 501 /**< not implemented */ 0068 #define HTTP_SERVUNAVAIL 503 /**< the server is not available */ 0069 0070 struct evhttp; 0071 struct evhttp_request; 0072 struct evkeyvalq; 0073 struct evhttp_bound_socket; 0074 struct evconnlistener; 0075 struct evdns_base; 0076 0077 /** 0078 * Create a new HTTP server. 0079 * 0080 * @param base (optional) the event base to receive the HTTP events 0081 * @return a pointer to a newly initialized evhttp server structure or NULL 0082 * on error 0083 * @see evhttp_free() 0084 */ 0085 EVENT2_EXPORT_SYMBOL 0086 struct evhttp *evhttp_new(struct event_base *base); 0087 0088 /** 0089 * Binds an HTTP server on the specified address and port. 0090 * 0091 * Can be called multiple times to bind the same http server 0092 * to multiple different ports. 0093 * 0094 * @param http a pointer to an evhttp object 0095 * @param address a string containing the IP address to listen(2) on 0096 * @param port the port number to listen on 0097 * @return 0 on success, -1 on failure. 0098 * @see evhttp_accept_socket() 0099 */ 0100 EVENT2_EXPORT_SYMBOL 0101 int evhttp_bind_socket(struct evhttp *http, const char *address, ev_uint16_t port); 0102 0103 /** 0104 * Like evhttp_bind_socket(), but returns a handle for referencing the socket. 0105 * 0106 * The returned pointer is not valid after \a http is freed. 0107 * 0108 * @param http a pointer to an evhttp object 0109 * @param address a string containing the IP address to listen(2) on 0110 * @param port the port number to listen on 0111 * @return Handle for the socket on success, NULL on failure. 0112 * @see evhttp_bind_socket(), evhttp_del_accept_socket() 0113 */ 0114 EVENT2_EXPORT_SYMBOL 0115 struct evhttp_bound_socket *evhttp_bind_socket_with_handle(struct evhttp *http, const char *address, ev_uint16_t port); 0116 0117 /** 0118 * Makes an HTTP server accept connections on the specified socket. 0119 * 0120 * This may be useful to create a socket and then fork multiple instances 0121 * of an http server, or when a socket has been communicated via file 0122 * descriptor passing in situations where an http servers does not have 0123 * permissions to bind to a low-numbered port. 0124 * 0125 * Can be called multiple times to have the http server listen to 0126 * multiple different sockets. 0127 * 0128 * @param http a pointer to an evhttp object 0129 * @param fd a socket fd that is ready for accepting connections 0130 * @return 0 on success, -1 on failure. 0131 * @see evhttp_bind_socket() 0132 */ 0133 EVENT2_EXPORT_SYMBOL 0134 int evhttp_accept_socket(struct evhttp *http, evutil_socket_t fd); 0135 0136 /** 0137 * Like evhttp_accept_socket(), but returns a handle for referencing the socket. 0138 * 0139 * The returned pointer is not valid after \a http is freed. 0140 * 0141 * @param http a pointer to an evhttp object 0142 * @param fd a socket fd that is ready for accepting connections 0143 * @return Handle for the socket on success, NULL on failure. 0144 * @see evhttp_accept_socket(), evhttp_del_accept_socket() 0145 */ 0146 EVENT2_EXPORT_SYMBOL 0147 struct evhttp_bound_socket *evhttp_accept_socket_with_handle(struct evhttp *http, evutil_socket_t fd); 0148 0149 /** 0150 * The most low-level evhttp_bind/accept method: takes an evconnlistener, and 0151 * returns an evhttp_bound_socket. The listener will be freed when the bound 0152 * socket is freed. 0153 */ 0154 EVENT2_EXPORT_SYMBOL 0155 struct evhttp_bound_socket *evhttp_bind_listener(struct evhttp *http, struct evconnlistener *listener); 0156 0157 /** 0158 * Return the listener used to implement a bound socket. 0159 */ 0160 EVENT2_EXPORT_SYMBOL 0161 struct evconnlistener *evhttp_bound_socket_get_listener(struct evhttp_bound_socket *bound); 0162 0163 typedef void evhttp_bound_socket_foreach_fn(struct evhttp_bound_socket *, void *); 0164 /** 0165 * Applies the function specified in the first argument to all 0166 * evhttp_bound_sockets associated with "http". The user must not 0167 * attempt to free or remove any connections, sockets or listeners 0168 * in the callback "function". 0169 * 0170 * @param http pointer to an evhttp object 0171 * @param function function to apply to every bound socket 0172 * @param argument pointer value passed to function for every socket iterated 0173 */ 0174 EVENT2_EXPORT_SYMBOL 0175 void evhttp_foreach_bound_socket(struct evhttp *http, evhttp_bound_socket_foreach_fn *function, void *argument); 0176 0177 /** 0178 * Makes an HTTP server stop accepting connections on the specified socket 0179 * 0180 * This may be useful when a socket has been sent via file descriptor passing 0181 * and is no longer needed by the current process. 0182 * 0183 * If you created this bound socket with evhttp_bind_socket_with_handle or 0184 * evhttp_accept_socket_with_handle, this function closes the fd you provided. 0185 * If you created this bound socket with evhttp_bind_listener, this function 0186 * frees the listener you provided. 0187 * 0188 * \a bound_socket is an invalid pointer after this call returns. 0189 * 0190 * @param http a pointer to an evhttp object 0191 * @param bound_socket a handle returned by evhttp_{bind,accept}_socket_with_handle 0192 * @see evhttp_bind_socket_with_handle(), evhttp_accept_socket_with_handle() 0193 */ 0194 EVENT2_EXPORT_SYMBOL 0195 void evhttp_del_accept_socket(struct evhttp *http, struct evhttp_bound_socket *bound_socket); 0196 0197 /** 0198 * Get the raw file descriptor referenced by an evhttp_bound_socket. 0199 * 0200 * @param bound_socket a handle returned by evhttp_{bind,accept}_socket_with_handle 0201 * @return the file descriptor used by the bound socket 0202 * @see evhttp_bind_socket_with_handle(), evhttp_accept_socket_with_handle() 0203 */ 0204 EVENT2_EXPORT_SYMBOL 0205 evutil_socket_t evhttp_bound_socket_get_fd(struct evhttp_bound_socket *bound_socket); 0206 0207 /** 0208 * Free the previously created HTTP server. 0209 * 0210 * Works only if no requests are currently being served. 0211 * 0212 * @param http the evhttp server object to be freed 0213 * @see evhttp_start() 0214 */ 0215 EVENT2_EXPORT_SYMBOL 0216 void evhttp_free(struct evhttp* http); 0217 0218 /** XXX Document. */ 0219 EVENT2_EXPORT_SYMBOL 0220 void evhttp_set_max_headers_size(struct evhttp* http, ev_ssize_t max_headers_size); 0221 /** XXX Document. */ 0222 EVENT2_EXPORT_SYMBOL 0223 void evhttp_set_max_body_size(struct evhttp* http, ev_ssize_t max_body_size); 0224 0225 /** 0226 Set the value to use for the Content-Type header when none was provided. If 0227 the content type string is NULL, the Content-Type header will not be 0228 automatically added. 0229 0230 @param http the http server on which to set the default content type 0231 @param content_type the value for the Content-Type header 0232 */ 0233 EVENT2_EXPORT_SYMBOL 0234 void evhttp_set_default_content_type(struct evhttp *http, 0235 const char *content_type); 0236 0237 /** 0238 Sets the what HTTP methods are supported in requests accepted by this 0239 server, and passed to user callbacks. 0240 0241 If not supported they will generate a "405 Method not allowed" response. 0242 0243 By default this includes the following methods: GET, POST, HEAD, PUT, DELETE 0244 0245 @param http the http server on which to set the methods 0246 @param methods bit mask constructed from evhttp_cmd_type values 0247 */ 0248 EVENT2_EXPORT_SYMBOL 0249 void evhttp_set_allowed_methods(struct evhttp* http, ev_uint16_t methods); 0250 0251 /** 0252 Set a callback for a specified URI 0253 0254 @param http the http sever on which to set the callback 0255 @param path the path for which to invoke the callback 0256 @param cb the callback function that gets invoked on requesting path 0257 @param cb_arg an additional context argument for the callback 0258 @return 0 on success, -1 if the callback existed already, -2 on failure 0259 */ 0260 EVENT2_EXPORT_SYMBOL 0261 int evhttp_set_cb(struct evhttp *http, const char *path, 0262 void (*cb)(struct evhttp_request *, void *), void *cb_arg); 0263 0264 /** Removes the callback for a specified URI */ 0265 EVENT2_EXPORT_SYMBOL 0266 int evhttp_del_cb(struct evhttp *, const char *); 0267 0268 /** 0269 Set a callback for all requests that are not caught by specific callbacks 0270 0271 Invokes the specified callback for all requests that do not match any of 0272 the previously specified request paths. This is catchall for requests not 0273 specifically configured with evhttp_set_cb(). 0274 0275 @param http the evhttp server object for which to set the callback 0276 @param cb the callback to invoke for any unmatched requests 0277 @param arg an context argument for the callback 0278 */ 0279 EVENT2_EXPORT_SYMBOL 0280 void evhttp_set_gencb(struct evhttp *http, 0281 void (*cb)(struct evhttp_request *, void *), void *arg); 0282 0283 /** 0284 Set a callback used to create new bufferevents for connections 0285 to a given evhttp object. 0286 0287 You can use this to override the default bufferevent type -- for example, 0288 to make this evhttp object use SSL bufferevents rather than unencrypted 0289 ones. 0290 0291 New bufferevents must be allocated with no fd set on them. 0292 0293 @param http the evhttp server object for which to set the callback 0294 @param cb the callback to invoke for incoming connections 0295 @param arg an context argument for the callback 0296 */ 0297 EVENT2_EXPORT_SYMBOL 0298 void evhttp_set_bevcb(struct evhttp *http, 0299 struct bufferevent *(*cb)(struct event_base *, void *), void *arg); 0300 0301 /** 0302 Adds a virtual host to the http server. 0303 0304 A virtual host is a newly initialized evhttp object that has request 0305 callbacks set on it via evhttp_set_cb() or evhttp_set_gencb(). It 0306 most not have any listing sockets associated with it. 0307 0308 If the virtual host has not been removed by the time that evhttp_free() 0309 is called on the main http server, it will be automatically freed, too. 0310 0311 It is possible to have hierarchical vhosts. For example: A vhost 0312 with the pattern *.example.com may have other vhosts with patterns 0313 foo.example.com and bar.example.com associated with it. 0314 0315 @param http the evhttp object to which to add a virtual host 0316 @param pattern the glob pattern against which the hostname is matched. 0317 The match is case insensitive and follows otherwise regular shell 0318 matching. 0319 @param vhost the virtual host to add the regular http server. 0320 @return 0 on success, -1 on failure 0321 @see evhttp_remove_virtual_host() 0322 */ 0323 EVENT2_EXPORT_SYMBOL 0324 int evhttp_add_virtual_host(struct evhttp* http, const char *pattern, 0325 struct evhttp* vhost); 0326 0327 /** 0328 Removes a virtual host from the http server. 0329 0330 @param http the evhttp object from which to remove the virtual host 0331 @param vhost the virtual host to remove from the regular http server. 0332 @return 0 on success, -1 on failure 0333 @see evhttp_add_virtual_host() 0334 */ 0335 EVENT2_EXPORT_SYMBOL 0336 int evhttp_remove_virtual_host(struct evhttp* http, struct evhttp* vhost); 0337 0338 /** 0339 Add a server alias to an http object. The http object can be a virtual 0340 host or the main server. 0341 0342 @param http the evhttp object 0343 @param alias the alias to add 0344 @see evhttp_add_remove_alias() 0345 */ 0346 EVENT2_EXPORT_SYMBOL 0347 int evhttp_add_server_alias(struct evhttp *http, const char *alias); 0348 0349 /** 0350 Remove a server alias from an http object. 0351 0352 @param http the evhttp object 0353 @param alias the alias to remove 0354 @see evhttp_add_server_alias() 0355 */ 0356 EVENT2_EXPORT_SYMBOL 0357 int evhttp_remove_server_alias(struct evhttp *http, const char *alias); 0358 0359 /** 0360 * Set the timeout for an HTTP request. 0361 * 0362 * @param http an evhttp object 0363 * @param timeout_in_secs the timeout, in seconds 0364 */ 0365 EVENT2_EXPORT_SYMBOL 0366 void evhttp_set_timeout(struct evhttp *http, int timeout_in_secs); 0367 0368 /** 0369 * Set the timeout for an HTTP request. 0370 * 0371 * @param http an evhttp object 0372 * @param tv the timeout, or NULL 0373 */ 0374 EVENT2_EXPORT_SYMBOL 0375 void evhttp_set_timeout_tv(struct evhttp *http, const struct timeval* tv); 0376 0377 /* Read all the clients body, and only after this respond with an error if the 0378 * clients body exceed max_body_size */ 0379 #define EVHTTP_SERVER_LINGERING_CLOSE 0x0001 0380 /** 0381 * Set connection flags for HTTP server. 0382 * 0383 * @see EVHTTP_SERVER_* 0384 * @return 0 on success, otherwise non zero (for example if flag doesn't 0385 * supported). 0386 */ 0387 EVENT2_EXPORT_SYMBOL 0388 int evhttp_set_flags(struct evhttp *http, int flags); 0389 0390 /* Request/Response functionality */ 0391 0392 /** 0393 * Send an HTML error message to the client. 0394 * 0395 * @param req a request object 0396 * @param error the HTTP error code 0397 * @param reason a brief explanation of the error. If this is NULL, we'll 0398 * just use the standard meaning of the error code. 0399 */ 0400 EVENT2_EXPORT_SYMBOL 0401 void evhttp_send_error(struct evhttp_request *req, int error, 0402 const char *reason); 0403 0404 /** 0405 * Send an HTML reply to the client. 0406 * 0407 * The body of the reply consists of the data in databuf. After calling 0408 * evhttp_send_reply() databuf will be empty, but the buffer is still 0409 * owned by the caller and needs to be deallocated by the caller if 0410 * necessary. 0411 * 0412 * @param req a request object 0413 * @param code the HTTP response code to send 0414 * @param reason a brief message to send with the response code 0415 * @param databuf the body of the response 0416 */ 0417 EVENT2_EXPORT_SYMBOL 0418 void evhttp_send_reply(struct evhttp_request *req, int code, 0419 const char *reason, struct evbuffer *databuf); 0420 0421 /* Low-level response interface, for streaming/chunked replies */ 0422 0423 /** 0424 Initiate a reply that uses Transfer-Encoding chunked. 0425 0426 This allows the caller to stream the reply back to the client and is 0427 useful when either not all of the reply data is immediately available 0428 or when sending very large replies. 0429 0430 The caller needs to supply data chunks with evhttp_send_reply_chunk() 0431 and complete the reply by calling evhttp_send_reply_end(). 0432 0433 @param req a request object 0434 @param code the HTTP response code to send 0435 @param reason a brief message to send with the response code 0436 */ 0437 EVENT2_EXPORT_SYMBOL 0438 void evhttp_send_reply_start(struct evhttp_request *req, int code, 0439 const char *reason); 0440 0441 /** 0442 Send another data chunk as part of an ongoing chunked reply. 0443 0444 The reply chunk consists of the data in databuf. After calling 0445 evhttp_send_reply_chunk() databuf will be empty, but the buffer is 0446 still owned by the caller and needs to be deallocated by the caller 0447 if necessary. 0448 0449 @param req a request object 0450 @param databuf the data chunk to send as part of the reply. 0451 */ 0452 EVENT2_EXPORT_SYMBOL 0453 void evhttp_send_reply_chunk(struct evhttp_request *req, 0454 struct evbuffer *databuf); 0455 0456 /** 0457 Send another data chunk as part of an ongoing chunked reply. 0458 0459 The reply chunk consists of the data in databuf. After calling 0460 evhttp_send_reply_chunk() databuf will be empty, but the buffer is 0461 still owned by the caller and needs to be deallocated by the caller 0462 if necessary. 0463 0464 @param req a request object 0465 @param databuf the data chunk to send as part of the reply. 0466 @param cb callback funcion 0467 @param call back's argument. 0468 */ 0469 EVENT2_EXPORT_SYMBOL 0470 void evhttp_send_reply_chunk_with_cb(struct evhttp_request *, struct evbuffer *, 0471 void (*cb)(struct evhttp_connection *, void *), void *arg); 0472 0473 /** 0474 Complete a chunked reply, freeing the request as appropriate. 0475 0476 @param req a request object 0477 */ 0478 EVENT2_EXPORT_SYMBOL 0479 void evhttp_send_reply_end(struct evhttp_request *req); 0480 0481 /* 0482 * Interfaces for making requests 0483 */ 0484 0485 /** The different request types supported by evhttp. These are as specified 0486 * in RFC2616, except for PATCH which is specified by RFC5789. 0487 * 0488 * By default, only some of these methods are accepted and passed to user 0489 * callbacks; use evhttp_set_allowed_methods() to change which methods 0490 * are allowed. 0491 */ 0492 enum evhttp_cmd_type { 0493 EVHTTP_REQ_GET = 1 << 0, 0494 EVHTTP_REQ_POST = 1 << 1, 0495 EVHTTP_REQ_HEAD = 1 << 2, 0496 EVHTTP_REQ_PUT = 1 << 3, 0497 EVHTTP_REQ_DELETE = 1 << 4, 0498 EVHTTP_REQ_OPTIONS = 1 << 5, 0499 EVHTTP_REQ_TRACE = 1 << 6, 0500 EVHTTP_REQ_CONNECT = 1 << 7, 0501 EVHTTP_REQ_PATCH = 1 << 8 0502 }; 0503 0504 /** a request object can represent either a request or a reply */ 0505 enum evhttp_request_kind { EVHTTP_REQUEST, EVHTTP_RESPONSE }; 0506 0507 /** 0508 * Create and return a connection object that can be used to for making HTTP 0509 * requests. The connection object tries to resolve address and establish the 0510 * connection when it is given an http request object. 0511 * 0512 * @param base the event_base to use for handling the connection 0513 * @param dnsbase the dns_base to use for resolving host names; if not 0514 * specified host name resolution will block. 0515 * @param bev a bufferevent to use for connecting to the server; if NULL, a 0516 * socket-based bufferevent will be created. This buffrevent will be freed 0517 * when the connection closes. It must have no fd set on it. 0518 * @param address the address to which to connect 0519 * @param port the port to connect to 0520 * @return an evhttp_connection object that can be used for making requests or 0521 * NULL on error 0522 */ 0523 EVENT2_EXPORT_SYMBOL 0524 struct evhttp_connection *evhttp_connection_base_bufferevent_new( 0525 struct event_base *base, struct evdns_base *dnsbase, struct bufferevent* bev, const char *address, ev_uint16_t port); 0526 0527 /** 0528 * Return the bufferevent that an evhttp_connection is using. 0529 */ 0530 EVENT2_EXPORT_SYMBOL 0531 struct bufferevent* evhttp_connection_get_bufferevent(struct evhttp_connection *evcon); 0532 0533 /** 0534 * Return the HTTP server associated with this connection, or NULL. 0535 */ 0536 EVENT2_EXPORT_SYMBOL 0537 struct evhttp *evhttp_connection_get_server(struct evhttp_connection *evcon); 0538 0539 /** 0540 * Creates a new request object that needs to be filled in with the request 0541 * parameters. The callback is executed when the request completed or an 0542 * error occurred. 0543 */ 0544 EVENT2_EXPORT_SYMBOL 0545 struct evhttp_request *evhttp_request_new( 0546 void (*cb)(struct evhttp_request *, void *), void *arg); 0547 0548 /** 0549 * Enable delivery of chunks to requestor. 0550 * @param cb will be called after every read of data with the same argument 0551 * as the completion callback. Will never be called on an empty 0552 * response. May drain the input buffer; it will be drained 0553 * automatically on return. 0554 */ 0555 EVENT2_EXPORT_SYMBOL 0556 void evhttp_request_set_chunked_cb(struct evhttp_request *, 0557 void (*cb)(struct evhttp_request *, void *)); 0558 0559 /** 0560 * Register callback for additional parsing of request headers. 0561 * @param cb will be called after receiving and parsing the full header. 0562 * It allows analyzing the header and possibly closing the connection 0563 * by returning a value < 0. 0564 */ 0565 EVENT2_EXPORT_SYMBOL 0566 void evhttp_request_set_header_cb(struct evhttp_request *, 0567 int (*cb)(struct evhttp_request *, void *)); 0568 0569 /** 0570 * The different error types supported by evhttp 0571 * 0572 * @see evhttp_request_set_error_cb() 0573 */ 0574 enum evhttp_request_error { 0575 /** 0576 * Timeout reached, also @see evhttp_connection_set_timeout() 0577 */ 0578 EVREQ_HTTP_TIMEOUT, 0579 /** 0580 * EOF reached 0581 */ 0582 EVREQ_HTTP_EOF, 0583 /** 0584 * Error while reading header, or invalid header 0585 */ 0586 EVREQ_HTTP_INVALID_HEADER, 0587 /** 0588 * Error encountered while reading or writing 0589 */ 0590 EVREQ_HTTP_BUFFER_ERROR, 0591 /** 0592 * The evhttp_cancel_request() called on this request. 0593 */ 0594 EVREQ_HTTP_REQUEST_CANCEL, 0595 /** 0596 * Body is greater then evhttp_connection_set_max_body_size() 0597 */ 0598 EVREQ_HTTP_DATA_TOO_LONG 0599 }; 0600 /** 0601 * Set a callback for errors 0602 * @see evhttp_request_error for error types. 0603 * 0604 * On error, both the error callback and the regular callback will be called, 0605 * error callback is called before the regular callback. 0606 **/ 0607 EVENT2_EXPORT_SYMBOL 0608 void evhttp_request_set_error_cb(struct evhttp_request *, 0609 void (*)(enum evhttp_request_error, void *)); 0610 0611 /** 0612 * Set a callback to be called on request completion of evhttp_send_* function. 0613 * 0614 * The callback function will be called on the completion of the request after 0615 * the output data has been written and before the evhttp_request object 0616 * is destroyed. This can be useful for tracking resources associated with a 0617 * request (ex: timing metrics). 0618 * 0619 * @param req a request object 0620 * @param cb callback function that will be called on request completion 0621 * @param cb_arg an additional context argument for the callback 0622 */ 0623 EVENT2_EXPORT_SYMBOL 0624 void evhttp_request_set_on_complete_cb(struct evhttp_request *req, 0625 void (*cb)(struct evhttp_request *, void *), void *cb_arg); 0626 0627 /** Frees the request object and removes associated events. */ 0628 EVENT2_EXPORT_SYMBOL 0629 void evhttp_request_free(struct evhttp_request *req); 0630 0631 /** 0632 * Create and return a connection object that can be used to for making HTTP 0633 * requests. The connection object tries to resolve address and establish the 0634 * connection when it is given an http request object. 0635 * 0636 * @param base the event_base to use for handling the connection 0637 * @param dnsbase the dns_base to use for resolving host names; if not 0638 * specified host name resolution will block. 0639 * @param address the address to which to connect 0640 * @param port the port to connect to 0641 * @return an evhttp_connection object that can be used for making requests or 0642 * NULL on error 0643 */ 0644 EVENT2_EXPORT_SYMBOL 0645 struct evhttp_connection *evhttp_connection_base_new( 0646 struct event_base *base, struct evdns_base *dnsbase, 0647 const char *address, ev_uint16_t port); 0648 0649 /** 0650 * Set family hint for DNS requests. 0651 */ 0652 EVENT2_EXPORT_SYMBOL 0653 void evhttp_connection_set_family(struct evhttp_connection *evcon, 0654 int family); 0655 0656 /* reuse connection address on retry */ 0657 #define EVHTTP_CON_REUSE_CONNECTED_ADDR 0x0008 0658 /* Try to read error, since server may already send and close 0659 * connection, but if at that time we have some data to send then we 0660 * can send get EPIPE and fail, while we can read that HTTP error. */ 0661 #define EVHTTP_CON_READ_ON_WRITE_ERROR 0x0010 0662 /* @see EVHTTP_SERVER_LINGERING_CLOSE */ 0663 #define EVHTTP_CON_LINGERING_CLOSE 0x0020 0664 /* Padding for public flags, @see EVHTTP_CON_* in http-internal.h */ 0665 #define EVHTTP_CON_PUBLIC_FLAGS_END 0x100000 0666 /** 0667 * Set connection flags. 0668 * 0669 * @see EVHTTP_CON_* 0670 * @return 0 on success, otherwise non zero (for example if flag doesn't 0671 * supported). 0672 */ 0673 EVENT2_EXPORT_SYMBOL 0674 int evhttp_connection_set_flags(struct evhttp_connection *evcon, 0675 int flags); 0676 0677 /** Takes ownership of the request object 0678 * 0679 * Can be used in a request callback to keep onto the request until 0680 * evhttp_request_free() is explicitly called by the user. 0681 */ 0682 EVENT2_EXPORT_SYMBOL 0683 void evhttp_request_own(struct evhttp_request *req); 0684 0685 /** Returns 1 if the request is owned by the user */ 0686 EVENT2_EXPORT_SYMBOL 0687 int evhttp_request_is_owned(struct evhttp_request *req); 0688 0689 /** 0690 * Returns the connection object associated with the request or NULL 0691 * 0692 * The user needs to either free the request explicitly or call 0693 * evhttp_send_reply_end(). 0694 */ 0695 EVENT2_EXPORT_SYMBOL 0696 struct evhttp_connection *evhttp_request_get_connection(struct evhttp_request *req); 0697 0698 /** 0699 * Returns the underlying event_base for this connection 0700 */ 0701 EVENT2_EXPORT_SYMBOL 0702 struct event_base *evhttp_connection_get_base(struct evhttp_connection *req); 0703 0704 EVENT2_EXPORT_SYMBOL 0705 void evhttp_connection_set_max_headers_size(struct evhttp_connection *evcon, 0706 ev_ssize_t new_max_headers_size); 0707 0708 EVENT2_EXPORT_SYMBOL 0709 void evhttp_connection_set_max_body_size(struct evhttp_connection* evcon, 0710 ev_ssize_t new_max_body_size); 0711 0712 /** Frees an http connection */ 0713 EVENT2_EXPORT_SYMBOL 0714 void evhttp_connection_free(struct evhttp_connection *evcon); 0715 0716 /** Disowns a given connection object 0717 * 0718 * Can be used to tell libevent to free the connection object after 0719 * the last request has completed or failed. 0720 */ 0721 EVENT2_EXPORT_SYMBOL 0722 void evhttp_connection_free_on_completion(struct evhttp_connection *evcon); 0723 0724 /** sets the ip address from which http connections are made */ 0725 EVENT2_EXPORT_SYMBOL 0726 void evhttp_connection_set_local_address(struct evhttp_connection *evcon, 0727 const char *address); 0728 0729 /** sets the local port from which http connections are made */ 0730 EVENT2_EXPORT_SYMBOL 0731 void evhttp_connection_set_local_port(struct evhttp_connection *evcon, 0732 ev_uint16_t port); 0733 0734 /** Sets the timeout in seconds for events related to this connection */ 0735 EVENT2_EXPORT_SYMBOL 0736 void evhttp_connection_set_timeout(struct evhttp_connection *evcon, 0737 int timeout_in_secs); 0738 0739 /** Sets the timeout for events related to this connection. Takes a struct 0740 * timeval. */ 0741 EVENT2_EXPORT_SYMBOL 0742 void evhttp_connection_set_timeout_tv(struct evhttp_connection *evcon, 0743 const struct timeval *tv); 0744 0745 /** Sets the delay before retrying requests on this connection. This is only 0746 * used if evhttp_connection_set_retries is used to make the number of retries 0747 * at least one. Each retry after the first is twice as long as the one before 0748 * it. */ 0749 EVENT2_EXPORT_SYMBOL 0750 void evhttp_connection_set_initial_retry_tv(struct evhttp_connection *evcon, 0751 const struct timeval *tv); 0752 0753 /** Sets the retry limit for this connection - -1 repeats indefinitely */ 0754 EVENT2_EXPORT_SYMBOL 0755 void evhttp_connection_set_retries(struct evhttp_connection *evcon, 0756 int retry_max); 0757 0758 /** Set a callback for connection close. */ 0759 EVENT2_EXPORT_SYMBOL 0760 void evhttp_connection_set_closecb(struct evhttp_connection *evcon, 0761 void (*)(struct evhttp_connection *, void *), void *); 0762 0763 /** Get the remote address and port associated with this connection. */ 0764 EVENT2_EXPORT_SYMBOL 0765 void evhttp_connection_get_peer(struct evhttp_connection *evcon, 0766 char **address, ev_uint16_t *port); 0767 0768 /** Get the remote address associated with this connection. 0769 * extracted from getpeername() OR from nameserver. 0770 * 0771 * @return NULL if getpeername() return non success, 0772 * or connection is not connected, 0773 * otherwise it return pointer to struct sockaddr_storage */ 0774 EVENT2_EXPORT_SYMBOL 0775 const struct sockaddr* 0776 evhttp_connection_get_addr(struct evhttp_connection *evcon); 0777 0778 /** 0779 Make an HTTP request over the specified connection. 0780 0781 The connection gets ownership of the request. On failure, the 0782 request object is no longer valid as it has been freed. 0783 0784 @param evcon the evhttp_connection object over which to send the request 0785 @param req the previously created and configured request object 0786 @param type the request type EVHTTP_REQ_GET, EVHTTP_REQ_POST, etc. 0787 @param uri the URI associated with the request 0788 @return 0 on success, -1 on failure 0789 @see evhttp_cancel_request() 0790 */ 0791 EVENT2_EXPORT_SYMBOL 0792 int evhttp_make_request(struct evhttp_connection *evcon, 0793 struct evhttp_request *req, 0794 enum evhttp_cmd_type type, const char *uri); 0795 0796 /** 0797 Cancels a pending HTTP request. 0798 0799 Cancels an ongoing HTTP request. The callback associated with this request 0800 is not executed and the request object is freed. If the request is 0801 currently being processed, e.g. it is ongoing, the corresponding 0802 evhttp_connection object is going to get reset. 0803 0804 A request cannot be canceled if its callback has executed already. A request 0805 may be canceled reentrantly from its chunked callback. 0806 0807 @param req the evhttp_request to cancel; req becomes invalid after this call. 0808 */ 0809 EVENT2_EXPORT_SYMBOL 0810 void evhttp_cancel_request(struct evhttp_request *req); 0811 0812 /** 0813 * A structure to hold a parsed URI or Relative-Ref conforming to RFC3986. 0814 */ 0815 struct evhttp_uri; 0816 0817 /** Returns the request URI */ 0818 EVENT2_EXPORT_SYMBOL 0819 const char *evhttp_request_get_uri(const struct evhttp_request *req); 0820 /** Returns the request URI (parsed) */ 0821 EVENT2_EXPORT_SYMBOL 0822 const struct evhttp_uri *evhttp_request_get_evhttp_uri(const struct evhttp_request *req); 0823 /** Returns the request command */ 0824 EVENT2_EXPORT_SYMBOL 0825 enum evhttp_cmd_type evhttp_request_get_command(const struct evhttp_request *req); 0826 0827 EVENT2_EXPORT_SYMBOL 0828 int evhttp_request_get_response_code(const struct evhttp_request *req); 0829 EVENT2_EXPORT_SYMBOL 0830 const char * evhttp_request_get_response_code_line(const struct evhttp_request *req); 0831 0832 /** Returns the input headers */ 0833 EVENT2_EXPORT_SYMBOL 0834 struct evkeyvalq *evhttp_request_get_input_headers(struct evhttp_request *req); 0835 /** Returns the output headers */ 0836 EVENT2_EXPORT_SYMBOL 0837 struct evkeyvalq *evhttp_request_get_output_headers(struct evhttp_request *req); 0838 /** Returns the input buffer */ 0839 EVENT2_EXPORT_SYMBOL 0840 struct evbuffer *evhttp_request_get_input_buffer(struct evhttp_request *req); 0841 /** Returns the output buffer */ 0842 EVENT2_EXPORT_SYMBOL 0843 struct evbuffer *evhttp_request_get_output_buffer(struct evhttp_request *req); 0844 /** Returns the host associated with the request. If a client sends an absolute 0845 URI, the host part of that is preferred. Otherwise, the input headers are 0846 searched for a Host: header. NULL is returned if no absolute URI or Host: 0847 header is provided. */ 0848 EVENT2_EXPORT_SYMBOL 0849 const char *evhttp_request_get_host(struct evhttp_request *req); 0850 0851 /* Interfaces for dealing with HTTP headers */ 0852 0853 /** 0854 Finds the value belonging to a header. 0855 0856 @param headers the evkeyvalq object in which to find the header 0857 @param key the name of the header to find 0858 @returns a pointer to the value for the header or NULL if the header 0859 could not be found. 0860 @see evhttp_add_header(), evhttp_remove_header() 0861 */ 0862 EVENT2_EXPORT_SYMBOL 0863 const char *evhttp_find_header(const struct evkeyvalq *headers, 0864 const char *key); 0865 0866 /** 0867 Removes a header from a list of existing headers. 0868 0869 @param headers the evkeyvalq object from which to remove a header 0870 @param key the name of the header to remove 0871 @returns 0 if the header was removed, -1 otherwise. 0872 @see evhttp_find_header(), evhttp_add_header() 0873 */ 0874 EVENT2_EXPORT_SYMBOL 0875 int evhttp_remove_header(struct evkeyvalq *headers, const char *key); 0876 0877 /** 0878 Adds a header to a list of existing headers. 0879 0880 @param headers the evkeyvalq object to which to add a header 0881 @param key the name of the header 0882 @param value the value belonging to the header 0883 @returns 0 on success, -1 otherwise. 0884 @see evhttp_find_header(), evhttp_clear_headers() 0885 */ 0886 EVENT2_EXPORT_SYMBOL 0887 int evhttp_add_header(struct evkeyvalq *headers, const char *key, const char *value); 0888 0889 /** 0890 Removes all headers from the header list. 0891 0892 @param headers the evkeyvalq object from which to remove all headers 0893 */ 0894 EVENT2_EXPORT_SYMBOL 0895 void evhttp_clear_headers(struct evkeyvalq *headers); 0896 0897 /* Miscellaneous utility functions */ 0898 0899 0900 /** 0901 Helper function to encode a string for inclusion in a URI. All 0902 characters are replaced by their hex-escaped (%22) equivalents, 0903 except for characters explicitly unreserved by RFC3986 -- that is, 0904 ASCII alphanumeric characters, hyphen, dot, underscore, and tilde. 0905 0906 The returned string must be freed by the caller. 0907 0908 @param str an unencoded string 0909 @return a newly allocated URI-encoded string or NULL on failure 0910 */ 0911 EVENT2_EXPORT_SYMBOL 0912 char *evhttp_encode_uri(const char *str); 0913 0914 /** 0915 As evhttp_encode_uri, but if 'size' is nonnegative, treat the string 0916 as being 'size' bytes long. This allows you to encode strings that 0917 may contain 0-valued bytes. 0918 0919 The returned string must be freed by the caller. 0920 0921 @param str an unencoded string 0922 @param size the length of the string to encode, or -1 if the string 0923 is NUL-terminated 0924 @param space_to_plus if true, space characters in 'str' are encoded 0925 as +, not %20. 0926 @return a newly allocate URI-encoded string, or NULL on failure. 0927 */ 0928 EVENT2_EXPORT_SYMBOL 0929 char *evhttp_uriencode(const char *str, ev_ssize_t size, int space_to_plus); 0930 0931 /** 0932 Helper function to sort of decode a URI-encoded string. Unlike 0933 evhttp_uridecode, it decodes all plus characters that appear 0934 _after_ the first question mark character, but no plusses that occur 0935 before. This is not a good way to decode URIs in whole or in part. 0936 0937 The returned string must be freed by the caller 0938 0939 @deprecated This function is deprecated; you probably want to use 0940 evhttp_uridecode instead. 0941 0942 @param uri an encoded URI 0943 @return a newly allocated unencoded URI or NULL on failure 0944 */ 0945 EVENT2_EXPORT_SYMBOL 0946 char *evhttp_decode_uri(const char *uri); 0947 0948 /** 0949 Helper function to decode a URI-escaped string or HTTP parameter. 0950 0951 If 'decode_plus' is 1, then we decode the string as an HTTP parameter 0952 value, and convert all plus ('+') characters to spaces. If 0953 'decode_plus' is 0, we leave all plus characters unchanged. 0954 0955 The returned string must be freed by the caller. 0956 0957 @param uri a URI-encode encoded URI 0958 @param decode_plus determines whether we convert '+' to space. 0959 @param size_out if size_out is not NULL, *size_out is set to the size of the 0960 returned string 0961 @return a newly allocated unencoded URI or NULL on failure 0962 */ 0963 EVENT2_EXPORT_SYMBOL 0964 char *evhttp_uridecode(const char *uri, int decode_plus, 0965 size_t *size_out); 0966 0967 /** 0968 Helper function to parse out arguments in a query. 0969 0970 Parsing a URI like 0971 0972 http://foo.com/?q=test&s=some+thing 0973 0974 will result in two entries in the key value queue. 0975 0976 The first entry is: key="q", value="test" 0977 The second entry is: key="s", value="some thing" 0978 0979 @deprecated This function is deprecated as of Libevent 2.0.9. Use 0980 evhttp_uri_parse and evhttp_parse_query_str instead. 0981 0982 @param uri the request URI 0983 @param headers the head of the evkeyval queue 0984 @return 0 on success, -1 on failure 0985 */ 0986 EVENT2_EXPORT_SYMBOL 0987 int evhttp_parse_query(const char *uri, struct evkeyvalq *headers); 0988 0989 /** 0990 Helper function to parse out arguments from the query portion of an 0991 HTTP URI. 0992 0993 Parsing a query string like 0994 0995 q=test&s=some+thing 0996 0997 will result in two entries in the key value queue. 0998 0999 The first entry is: key="q", value="test" 1000 The second entry is: key="s", value="some thing" 1001 1002 @param query_parse the query portion of the URI 1003 @param headers the head of the evkeyval queue 1004 @return 0 on success, -1 on failure 1005 */ 1006 EVENT2_EXPORT_SYMBOL 1007 int evhttp_parse_query_str(const char *uri, struct evkeyvalq *headers); 1008 1009 /** 1010 * Escape HTML character entities in a string. 1011 * 1012 * Replaces <, >, ", ' and & with <, >, ", 1013 * ' and & correspondingly. 1014 * 1015 * The returned string needs to be freed by the caller. 1016 * 1017 * @param html an unescaped HTML string 1018 * @return an escaped HTML string or NULL on error 1019 */ 1020 EVENT2_EXPORT_SYMBOL 1021 char *evhttp_htmlescape(const char *html); 1022 1023 /** 1024 * Return a new empty evhttp_uri with no fields set. 1025 */ 1026 EVENT2_EXPORT_SYMBOL 1027 struct evhttp_uri *evhttp_uri_new(void); 1028 1029 /** 1030 * Changes the flags set on a given URI. See EVHTTP_URI_* for 1031 * a list of flags. 1032 **/ 1033 EVENT2_EXPORT_SYMBOL 1034 void evhttp_uri_set_flags(struct evhttp_uri *uri, unsigned flags); 1035 1036 /** Return the scheme of an evhttp_uri, or NULL if there is no scheme has 1037 * been set and the evhttp_uri contains a Relative-Ref. */ 1038 EVENT2_EXPORT_SYMBOL 1039 const char *evhttp_uri_get_scheme(const struct evhttp_uri *uri); 1040 /** 1041 * Return the userinfo part of an evhttp_uri, or NULL if it has no userinfo 1042 * set. 1043 */ 1044 EVENT2_EXPORT_SYMBOL 1045 const char *evhttp_uri_get_userinfo(const struct evhttp_uri *uri); 1046 /** 1047 * Return the host part of an evhttp_uri, or NULL if it has no host set. 1048 * The host may either be a regular hostname (conforming to the RFC 3986 1049 * "regname" production), or an IPv4 address, or the empty string, or a 1050 * bracketed IPv6 address, or a bracketed 'IP-Future' address. 1051 * 1052 * Note that having a NULL host means that the URI has no authority 1053 * section, but having an empty-string host means that the URI has an 1054 * authority section with no host part. For example, 1055 * "mailto:user@example.com" has a host of NULL, but "file:///etc/motd" 1056 * has a host of "". 1057 */ 1058 EVENT2_EXPORT_SYMBOL 1059 const char *evhttp_uri_get_host(const struct evhttp_uri *uri); 1060 /** Return the port part of an evhttp_uri, or -1 if there is no port set. */ 1061 EVENT2_EXPORT_SYMBOL 1062 int evhttp_uri_get_port(const struct evhttp_uri *uri); 1063 /** Return the path part of an evhttp_uri, or NULL if it has no path set */ 1064 EVENT2_EXPORT_SYMBOL 1065 const char *evhttp_uri_get_path(const struct evhttp_uri *uri); 1066 /** Return the query part of an evhttp_uri (excluding the leading "?"), or 1067 * NULL if it has no query set */ 1068 EVENT2_EXPORT_SYMBOL 1069 const char *evhttp_uri_get_query(const struct evhttp_uri *uri); 1070 /** Return the fragment part of an evhttp_uri (excluding the leading "#"), 1071 * or NULL if it has no fragment set */ 1072 EVENT2_EXPORT_SYMBOL 1073 const char *evhttp_uri_get_fragment(const struct evhttp_uri *uri); 1074 1075 /** Set the scheme of an evhttp_uri, or clear the scheme if scheme==NULL. 1076 * Returns 0 on success, -1 if scheme is not well-formed. */ 1077 EVENT2_EXPORT_SYMBOL 1078 int evhttp_uri_set_scheme(struct evhttp_uri *uri, const char *scheme); 1079 /** Set the userinfo of an evhttp_uri, or clear the userinfo if userinfo==NULL. 1080 * Returns 0 on success, -1 if userinfo is not well-formed. */ 1081 EVENT2_EXPORT_SYMBOL 1082 int evhttp_uri_set_userinfo(struct evhttp_uri *uri, const char *userinfo); 1083 /** Set the host of an evhttp_uri, or clear the host if host==NULL. 1084 * Returns 0 on success, -1 if host is not well-formed. */ 1085 EVENT2_EXPORT_SYMBOL 1086 int evhttp_uri_set_host(struct evhttp_uri *uri, const char *host); 1087 /** Set the port of an evhttp_uri, or clear the port if port==-1. 1088 * Returns 0 on success, -1 if port is not well-formed. */ 1089 EVENT2_EXPORT_SYMBOL 1090 int evhttp_uri_set_port(struct evhttp_uri *uri, int port); 1091 /** Set the path of an evhttp_uri, or clear the path if path==NULL. 1092 * Returns 0 on success, -1 if path is not well-formed. */ 1093 EVENT2_EXPORT_SYMBOL 1094 int evhttp_uri_set_path(struct evhttp_uri *uri, const char *path); 1095 /** Set the query of an evhttp_uri, or clear the query if query==NULL. 1096 * The query should not include a leading "?". 1097 * Returns 0 on success, -1 if query is not well-formed. */ 1098 EVENT2_EXPORT_SYMBOL 1099 int evhttp_uri_set_query(struct evhttp_uri *uri, const char *query); 1100 /** Set the fragment of an evhttp_uri, or clear the fragment if fragment==NULL. 1101 * The fragment should not include a leading "#". 1102 * Returns 0 on success, -1 if fragment is not well-formed. */ 1103 EVENT2_EXPORT_SYMBOL 1104 int evhttp_uri_set_fragment(struct evhttp_uri *uri, const char *fragment); 1105 1106 /** 1107 * Helper function to parse a URI-Reference as specified by RFC3986. 1108 * 1109 * This function matches the URI-Reference production from RFC3986, 1110 * which includes both URIs like 1111 * 1112 * scheme://[[userinfo]@]foo.com[:port]]/[path][?query][#fragment] 1113 * 1114 * and relative-refs like 1115 * 1116 * [path][?query][#fragment] 1117 * 1118 * Any optional elements portions not present in the original URI are 1119 * left set to NULL in the resulting evhttp_uri. If no port is 1120 * specified, the port is set to -1. 1121 * 1122 * Note that no decoding is performed on percent-escaped characters in 1123 * the string; if you want to parse them, use evhttp_uridecode or 1124 * evhttp_parse_query_str as appropriate. 1125 * 1126 * Note also that most URI schemes will have additional constraints that 1127 * this function does not know about, and cannot check. For example, 1128 * mailto://www.example.com/cgi-bin/fortune.pl is not a reasonable 1129 * mailto url, http://www.example.com:99999/ is not a reasonable HTTP 1130 * URL, and ftp:username@example.com is not a reasonable FTP URL. 1131 * Nevertheless, all of these URLs conform to RFC3986, and this function 1132 * accepts all of them as valid. 1133 * 1134 * @param source_uri the request URI 1135 * @param flags Zero or more EVHTTP_URI_* flags to affect the behavior 1136 * of the parser. 1137 * @return uri container to hold parsed data, or NULL if there is error 1138 * @see evhttp_uri_free() 1139 */ 1140 EVENT2_EXPORT_SYMBOL 1141 struct evhttp_uri *evhttp_uri_parse_with_flags(const char *source_uri, 1142 unsigned flags); 1143 1144 /** Tolerate URIs that do not conform to RFC3986. 1145 * 1146 * Unfortunately, some HTTP clients generate URIs that, according to RFC3986, 1147 * are not conformant URIs. If you need to support these URIs, you can 1148 * do so by passing this flag to evhttp_uri_parse_with_flags. 1149 * 1150 * Currently, these changes are: 1151 * <ul> 1152 * <li> Nonconformant URIs are allowed to contain otherwise unreasonable 1153 * characters in their path, query, and fragment components. 1154 * </ul> 1155 */ 1156 #define EVHTTP_URI_NONCONFORMANT 0x01 1157 1158 /** Alias for evhttp_uri_parse_with_flags(source_uri, 0) */ 1159 EVENT2_EXPORT_SYMBOL 1160 struct evhttp_uri *evhttp_uri_parse(const char *source_uri); 1161 1162 /** 1163 * Free all memory allocated for a parsed uri. Only use this for URIs 1164 * generated by evhttp_uri_parse. 1165 * 1166 * @param uri container with parsed data 1167 * @see evhttp_uri_parse() 1168 */ 1169 EVENT2_EXPORT_SYMBOL 1170 void evhttp_uri_free(struct evhttp_uri *uri); 1171 1172 /** 1173 * Join together the uri parts from parsed data to form a URI-Reference. 1174 * 1175 * Note that no escaping of reserved characters is done on the members 1176 * of the evhttp_uri, so the generated string might not be a valid URI 1177 * unless the members of evhttp_uri are themselves valid. 1178 * 1179 * @param uri container with parsed data 1180 * @param buf destination buffer 1181 * @param limit destination buffer size 1182 * @return an joined uri as string or NULL on error 1183 * @see evhttp_uri_parse() 1184 */ 1185 EVENT2_EXPORT_SYMBOL 1186 char *evhttp_uri_join(struct evhttp_uri *uri, char *buf, size_t limit); 1187 1188 #ifdef __cplusplus 1189 } 1190 #endif 1191 1192 #endif /* EVENT2_HTTP_H_INCLUDED_ */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |