summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorRichard Mudgett <rmudgett@digium.com>2014-07-03 17:16:55 +0000
committerRichard Mudgett <rmudgett@digium.com>2014-07-03 17:16:55 +0000
commitdbec5e0d8d2d8c51e14f912354d12e1f713b6077 (patch)
tree0d4c189e72b3e0a3a4194efcb62b5779597245d6 /include
parent758b13858b79256104c0f81a9adf1924df7d2da9 (diff)
HTTP: Add persistent connection support.
Persistent HTTP connection support is needed due to the increased usage of the Asterisk core HTTP transport and the frequency at which REST API calls are going to be issued. * Add http.conf session_keep_alive option to enable persistent connections. * Parse and discard optional chunked body extension information and trailing request headers. * Increased the maximum application/json and application/x-www-form-urlencoded body size allowed to 4k. The previous 1k was kind of small. * Removed a couple inlined versions of ast_http_manid_from_vars() by calling the function. manager.c:generic_http_callback() and res_http_post.c:http_post_callback() * Add missing va_end() in ast_ari_response_error(). * Eliminated unnecessary RAII_VAR() use in http.c:auth_create(). ASTERISK-23552 #close Reported by: Scott Griepentrog Review: https://reviewboard.asterisk.org/r/3691/ ........ Merged revisions 417880 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@417901 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'include')
-rw-r--r--include/asterisk/http.h93
-rw-r--r--include/asterisk/tcptls.h3
2 files changed, 72 insertions, 24 deletions
diff --git a/include/asterisk/http.h b/include/asterisk/http.h
index 35c8b22bd..ad91823b5 100644
--- a/include/asterisk/http.h
+++ b/include/asterisk/http.h
@@ -66,28 +66,34 @@ enum ast_http_method {
struct ast_http_uri;
-/*! \brief HTTP Callbacks
+/*!
+ * \brief HTTP Callbacks
+ *
+ * \param ser TCP/TLS session object
+ * \param urih Registered URI handler struct for the URI.
+ * \param uri Remaining request URI path (also with the get_params removed).
+ * \param method enum ast_http_method GET, POST, etc.
+ * \param get_params URI argument list passed with the HTTP request.
+ * \param headers HTTP request header-name/value pair list
*
- * \note The callback function receives server instance, uri, http method,
- * get method (if present in URI), and http headers as arguments and should
- * use the ast_http_send() function for sending content allocated with ast_str
- * and/or content from an opened file descriptor.
+ * \note Should use the ast_http_send() function for sending content
+ * allocated with ast_str and/or content from an opened file descriptor.
*
* Status and status text should be sent as arguments to the ast_http_send()
* function to reflect the status of the request (200 or 304, for example).
* Content length is calculated by ast_http_send() automatically.
*
- * Static content may be indicated to the ast_http_send() function, to indicate
- * that it may be cached.
+ * Static content may be indicated to the ast_http_send() function,
+ * to indicate that it may be cached.
+ *
+ * For a need authentication response, the ast_http_auth() function
+ * should be used.
*
- * \verbatim
- * The return value may include additional headers at the front and MUST
- * include a blank line with \r\n to provide separation between user headers
- * and content (even if no content is specified)
- * \endverbatim
+ * For an error response, the ast_http_error() function should be used.
*
- * For an error response, the ast_http_error() function may be used.
-*/
+ * \retval 0 Continue and process the next HTTP request.
+ * \retval -1 Fatal HTTP connection error. Force the HTTP connection closed.
+ */
typedef int (*ast_http_callback)(struct ast_tcptls_session_instance *ser, const struct ast_http_uri *urih, const char *uri, enum ast_http_method method, struct ast_variable *get_params, struct ast_variable *headers);
/*! \brief Definition of a URI handler */
@@ -141,26 +147,30 @@ void ast_http_uri_unlink(struct ast_http_uri *urihandler);
/*! \brief Unregister all handlers with matching key */
void ast_http_uri_unlink_all_with_key(const char *key);
-/*!\brief Return http method name string
+/*!
+ * \brief Return http method name string
* \since 1.8
*/
const char *ast_get_http_method(enum ast_http_method method) attribute_pure;
-/*!\brief Return mime type based on extension
+/*!
+ * \brief Return mime type based on extension
* \param ftype filename extension
* \return String containing associated MIME type
* \since 1.8
*/
const char *ast_http_ftype2mtype(const char *ftype) attribute_pure;
-/*!\brief Return manager id, if exist, from request headers
+/*!
+ * \brief Return manager id, if exist, from request headers
* \param headers List of HTTP headers
* \return 32-bit associated manager session identifier
* \since 1.8
*/
uint32_t ast_http_manid_from_vars(struct ast_variable *headers) attribute_pure;
-/*! \brief Generic function for sending http/1.1 response.
+/*!
+ * \brief Generic function for sending HTTP/1.1 response.
* \param ser TCP/TLS session object
* \param method GET/POST/HEAD
* \param status_code HTTP response code (200/401/403/404/500)
@@ -186,12 +196,14 @@ uint32_t ast_http_manid_from_vars(struct ast_variable *headers) attribute_pure;
*
* \since 1.8
*/
-void ast_http_send(struct ast_tcptls_session_instance *ser, enum ast_http_method method, int status_code, const char *status_title, struct ast_str *http_header, struct ast_str *out, const int fd, unsigned int static_content);
+void ast_http_send(struct ast_tcptls_session_instance *ser, enum ast_http_method method,
+ int status_code, const char *status_title, struct ast_str *http_header,
+ struct ast_str *out, int fd, unsigned int static_content);
-/*!\brief Send http "401 Unauthorized" response and close socket */
+/*! \brief Send http "401 Unauthorized" response and close socket */
void ast_http_auth(struct ast_tcptls_session_instance *ser, const char *realm, const unsigned long nonce, const unsigned long opaque, int stale, const char *text);
-/*!\brief Send HTTP error message and close socket */
+/*! \brief Send HTTP error message and close socket */
void ast_http_error(struct ast_tcptls_session_instance *ser, int status, const char *title, const char *text);
/*!
@@ -202,8 +214,42 @@ void ast_http_error(struct ast_tcptls_session_instance *ser, int status, const c
*/
void ast_http_prefix(char *buf, int len);
+/*!
+ * \brief Request the HTTP connection be closed after this HTTP request.
+ * \since 12.4.0
+ *
+ * \param ser HTTP TCP/TLS session object.
+ *
+ * \note Call before ast_http_error() to make the connection close.
+ *
+ * \return Nothing
+ */
+void ast_http_request_close_on_completion(struct ast_tcptls_session_instance *ser);
+
+/*!
+ * \brief Update the body read success status.
+ * \since 12.4.0
+ *
+ * \param ser HTTP TCP/TLS session object.
+ * \param read_success TRUE if body was read successfully.
+ *
+ * \return Nothing
+ */
+void ast_http_body_read_status(struct ast_tcptls_session_instance *ser, int read_success);
-/*!\brief Get post variables from client Request Entity-Body, if content type is application/x-www-form-urlencoded.
+/*!
+ * \brief Read and discard any unread HTTP request body.
+ * \since 12.4.0
+ *
+ * \param ser HTTP TCP/TLS session object.
+ *
+ * \retval 0 on success.
+ * \retval -1 on error.
+ */
+int ast_http_body_discard(struct ast_tcptls_session_instance *ser);
+
+/*!
+ * \brief Get post variables from client Request Entity-Body, if content type is application/x-www-form-urlencoded.
* \param ser TCP/TLS session object
* \param headers List of HTTP headers
* \return List of variables within the POST body
@@ -214,7 +260,8 @@ struct ast_variable *ast_http_get_post_vars(struct ast_tcptls_session_instance *
struct ast_json;
-/*!\brief Get JSON from client Request Entity-Body, if content type is
+/*!
+ * \brief Get JSON from client Request Entity-Body, if content type is
* application/json.
* \param ser TCP/TLS session object
* \param headers List of HTTP headers
diff --git a/include/asterisk/tcptls.h b/include/asterisk/tcptls.h
index 3356a92cc..0e8d9d042 100644
--- a/include/asterisk/tcptls.h
+++ b/include/asterisk/tcptls.h
@@ -210,7 +210,6 @@ struct ast_tcptls_session_instance {
FILE *f; /*!< fopen/funopen result */
int fd; /*!< the socket returned by accept() */
SSL *ssl; /*!< ssl state */
-/* iint (*ssl_setup)(SSL *); */
int client;
struct ast_sockaddr remote_address;
struct ast_tcptls_session_args *parent;
@@ -222,6 +221,8 @@ struct ast_tcptls_session_instance {
struct ast_str *overflow_buf;
/*! ao2 FILE stream cookie object associated with f. */
struct ast_tcptls_stream *stream_cookie;
+ /*! ao2 object private data of parent->worker_fn */
+ void *private_data;
};
#if defined(HAVE_FUNOPEN)