[asterisk-commits] kpfleming: trunk r109762 - in /trunk: include/asterisk/ main/ res/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Mar 18 17:32:27 CDT 2008
Author: kpfleming
Date: Tue Mar 18 17:32:26 2008
New Revision: 109762
URL: http://svn.digium.com/view/asterisk?view=rev&rev=109762
Log:
start the process of changing HTTP request dispatching to do it based on *both* URI and method, so that POST support can move into a module; move http.c's private function prototypes into _private.h
Modified:
trunk/include/asterisk/_private.h
trunk/include/asterisk/http.h
trunk/main/http.c
trunk/main/manager.c
trunk/res/res_phoneprov.c
Modified: trunk/include/asterisk/_private.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/_private.h?view=diff&rev=109762&r1=109761&r2=109762
==============================================================================
--- trunk/include/asterisk/_private.h (original)
+++ trunk/include/asterisk/_private.h Tue Mar 18 17:32:26 2008
@@ -33,7 +33,9 @@
int astobj2_init(void); /*!< Provided by astobj2.c */
int ast_file_init(void); /*!< Provided by file.c */
int ast_features_init(void); /*!< Provided by features.c */
-void ast_autoservice_init(void); /*!< Provided by autoservice.c */
+void ast_autoservice_init(void); /*!< Provided by autoservice.c */
+int ast_http_init(void); /*!< Provided by http.c */
+int ast_http_reload(void); /*!< Provided by http.c */
/*!
* \brief Reload asterisk modules.
Modified: trunk/include/asterisk/http.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/http.h?view=diff&rev=109762&r1=109761&r2=109762
==============================================================================
--- trunk/include/asterisk/http.h (original)
+++ trunk/include/asterisk/http.h Tue Mar 18 17:32:26 2008
@@ -65,29 +65,37 @@
content is specified)
\endverbatim
*/
-typedef struct ast_str *(*ast_http_callback)(struct ast_tcptls_session_instance *ser, const char *uri, struct ast_variable *params, int *status, char **title, int *contentlength);
-/*! \brief Definition of a URI reachable in the embedded HTTP server */
+enum ast_http_method {
+ AST_HTTP_GET = 0,
+ AST_HTTP_POST,
+};
+
+typedef struct ast_str *(*ast_http_callback)(struct ast_tcptls_session_instance *ser, const char *uri, enum ast_http_method method,
+ struct ast_variable *params, int *status, char **title, int *contentlength);
+
+/*! \brief Definition of a URI handler */
struct ast_http_uri {
AST_LIST_ENTRY(ast_http_uri) entry;
const char *description;
const char *uri;
+ ast_http_callback callback;
unsigned int has_subtree:1;
- /*! This URI mapping serves static content */
+ /*! This handler serves static content */
unsigned int static_content:1;
- ast_http_callback callback;
+ /*! This handler accepts GET requests */
+ unsigned int supports_get:1;
+ /*! This handler accepts POST requests */
+ unsigned int supports_post:1;
};
-/*! \brief Link into the Asterisk HTTP server */
+/*! \brief Register a URI handler */
int ast_http_uri_link(struct ast_http_uri *urihandler);
+
+/*! \brief Unregister a URI handler */
+void ast_http_uri_unlink(struct ast_http_uri *urihandler);
/*! \brief Return an ast_str malloc()'d string containing an HTTP error message */
struct ast_str *ast_http_error(int status, const char *title, const char *extra_header, const char *text);
-/*! \brief Destroy an HTTP server */
-void ast_http_uri_unlink(struct ast_http_uri *urihandler);
-
-int ast_http_init(void);
-int ast_http_reload(void);
-
#endif /* _ASTERISK_SRV_H */
Modified: trunk/main/http.c
URL: http://svn.digium.com/view/asterisk/trunk/main/http.c?view=diff&rev=109762&r1=109761&r2=109762
==============================================================================
--- trunk/main/http.c (original)
+++ trunk/main/http.c Tue Mar 18 17:32:26 2008
@@ -32,8 +32,6 @@
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-#include "asterisk/paths.h" /* use ast_config_AST_DATA_DIR */
-#include "asterisk/network.h"
#include <time.h>
#include <sys/time.h>
#include <sys/stat.h>
@@ -44,6 +42,8 @@
#include <gmime/gmime.h>
#endif /* ENABLE_UPLOADS */
+#include "asterisk/paths.h" /* use ast_config_AST_DATA_DIR */
+#include "asterisk/network.h"
#include "asterisk/cli.h"
#include "asterisk/tcptls.h"
#include "asterisk/http.h"
@@ -53,6 +53,7 @@
#include "asterisk/stringfields.h"
#include "asterisk/ast_version.h"
#include "asterisk/manager.h"
+#include "asterisk/_private.h"
#define MAX_PREFIX 80
@@ -145,7 +146,8 @@
return wkspace;
}
-static struct ast_str *static_callback(struct ast_tcptls_session_instance *ser, const char *uri, struct ast_variable *vars, int *status, char **title, int *contentlength)
+static struct ast_str *static_callback(struct ast_tcptls_session_instance *ser, const char *uri, enum ast_http_method method,
+ struct ast_variable *vars, int *status, char **title, int *contentlength)
{
char *path;
char *ftype;
@@ -215,7 +217,8 @@
}
-static struct ast_str *httpstatus_callback(struct ast_tcptls_session_instance *ser, const char *uri, struct ast_variable *vars, int *status, char **title, int *contentlength)
+static struct ast_str *httpstatus_callback(struct ast_tcptls_session_instance *ser, const char *uri, enum ast_http_method method,
+ struct ast_variable *vars, int *status, char **title, int *contentlength)
{
struct ast_str *out = ast_str_create(512);
struct ast_variable *v;
@@ -641,7 +644,7 @@
if (urih) {
if (urih->static_content)
*static_content = 1;
- out = urih->callback(ser, uri, vars, status, title, contentlength);
+ out = urih->callback(ser, uri, AST_HTTP_GET, vars, status, title, contentlength);
AST_RWLIST_UNLOCK(&uris);
} else {
out = ast_http_error(404, "Not Found", NULL,
Modified: trunk/main/manager.c
URL: http://svn.digium.com/view/asterisk/trunk/main/manager.c?view=diff&rev=109762&r1=109761&r2=109762
==============================================================================
--- trunk/main/manager.c (original)
+++ trunk/main/manager.c Tue Mar 18 17:32:26 2008
@@ -3476,7 +3476,7 @@
}
static struct ast_str *generic_http_callback(enum output_format format,
- struct sockaddr_in *requestor, const char *uri,
+ struct sockaddr_in *requestor, const char *uri, enum ast_http_method method,
struct ast_variable *params, int *status,
char **title, int *contentlength)
{
@@ -3631,19 +3631,19 @@
return out;
}
-static struct ast_str *manager_http_callback(struct ast_tcptls_session_instance *ser, const char *uri, struct ast_variable *params, int *status, char **title, int *contentlength)
-{
- return generic_http_callback(FORMAT_HTML, &ser->requestor, uri, params, status, title, contentlength);
-}
-
-static struct ast_str *mxml_http_callback(struct ast_tcptls_session_instance *ser, const char *uri, struct ast_variable *params, int *status, char **title, int *contentlength)
-{
- return generic_http_callback(FORMAT_XML, &ser->requestor, uri, params, status, title, contentlength);
-}
-
-static struct ast_str *rawman_http_callback(struct ast_tcptls_session_instance *ser, const char *uri, struct ast_variable *params, int *status, char **title, int *contentlength)
-{
- return generic_http_callback(FORMAT_RAW, &ser->requestor, uri, params, status, title, contentlength);
+static struct ast_str *manager_http_callback(struct ast_tcptls_session_instance *ser, const char *uri, enum ast_http_method method, struct ast_variable *params, int *status, char **title, int *contentlength)
+{
+ return generic_http_callback(FORMAT_HTML, &ser->requestor, uri, method, params, status, title, contentlength);
+}
+
+static struct ast_str *mxml_http_callback(struct ast_tcptls_session_instance *ser, const char *uri, enum ast_http_method method, struct ast_variable *params, int *status, char **title, int *contentlength)
+{
+ return generic_http_callback(FORMAT_XML, &ser->requestor, uri, method, params, status, title, contentlength);
+}
+
+static struct ast_str *rawman_http_callback(struct ast_tcptls_session_instance *ser, const char *uri, enum ast_http_method method, struct ast_variable *params, int *status, char **title, int *contentlength)
+{
+ return generic_http_callback(FORMAT_RAW, &ser->requestor, uri, method, params, status, title, contentlength);
}
struct ast_http_uri rawmanuri = {
Modified: trunk/res/res_phoneprov.c
URL: http://svn.digium.com/view/asterisk/trunk/res/res_phoneprov.c?view=diff&rev=109762&r1=109761&r2=109762
==============================================================================
--- trunk/res/res_phoneprov.c (original)
+++ trunk/res/res_phoneprov.c Tue Mar 18 17:32:26 2008
@@ -323,7 +323,8 @@
}
/*! \brief Callback that is executed everytime an http request is received by this module */
-static struct ast_str *phoneprov_callback(struct ast_tcptls_session_instance *ser, const char *uri, struct ast_variable *vars, int *status, char **title, int *contentlength)
+static struct ast_str *phoneprov_callback(struct ast_tcptls_session_instance *ser, const char *uri, enum ast_http_method method,
+ struct ast_variable *vars, int *status, char **title, int *contentlength)
{
struct http_route *route;
struct http_route search_route = {
@@ -358,7 +359,7 @@
}
ast_strftime(buf, sizeof(buf), "%a, %d %b %Y %H:%M:%S %Z", ast_localtime(&tv, &tm, "GMT"));
- fprintf(ser->f, "HTTP/1.1 200 OK\r\n"
+ fprintf(ser->f, "HTTP/1.1 200 OK\r\n"
"Server: Asterisk/%s\r\n"
"Date: %s\r\n"
"Connection: close\r\n"
More information about the asterisk-commits
mailing list