[asterisk-commits] tilghman: branch group/manager_http_auth r189200 - in /team/group/manager_htt...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Apr 17 18:13:24 CDT 2009
Author: tilghman
Date: Fri Apr 17 18:13:08 2009
New Revision: 189200
URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=189200
Log:
Changes due to Russell's review
Modified:
team/group/manager_http_auth/include/asterisk/http.h
team/group/manager_http_auth/main/ast_expr2.h
team/group/manager_http_auth/main/http.c
team/group/manager_http_auth/main/manager.c
team/group/manager_http_auth/res/res_http_post.c
team/group/manager_http_auth/res/res_phoneprov.c
Modified: team/group/manager_http_auth/include/asterisk/http.h
URL: http://svn.digium.com/svn-view/asterisk/team/group/manager_http_auth/include/asterisk/http.h?view=diff&rev=189200&r1=189199&r2=189200
==============================================================================
--- team/group/manager_http_auth/include/asterisk/http.h (original)
+++ team/group/manager_http_auth/include/asterisk/http.h Fri Apr 17 18:13:08 2009
@@ -116,16 +116,35 @@
/*! \brief Unregister all handlers with matching key */
void ast_http_uri_unlink_all_with_key(const char *key);
-/*! \brief Return http method name string */
-char *ast_get_http_method(enum ast_http_method method);
+/*!\brief Return http method name string
+ * \since 1.6.3
+ */
+const char *ast_get_http_method(enum ast_http_method method) attribute_pure;
-/*! \brief Return mime type based on extension */
-char *ast_ftype2mtype(const char *ftype);
+/*!\brief Return mime type based on extension
+ * \param ftype filename extension
+ * \return String containing associated MIME type
+ * \since 1.6.3
+ */
+const char *ast_http_ftype2mtype(const char *ftype) attribute_pure;
-/*! \brief Return manager id, if exist, from request headers */
-uint32_t manid_from_vars(struct ast_variable *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.6.3
+ */
+uint32_t ast_http_manid_from_vars(struct ast_variable *headers) attribute_pure;
-/*! \brief Generic function for sending http/1.1 responce.
+/*! \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)
+ * \param status_title English equivalent to the status_code parameter
+ * \param http_header An ast_str object containing all headers
+ * \param out An ast_str object containing the body of the response
+ * \param fd If out is NULL, a file descriptor where the body of the response is held (otherwise -1)
+ * \param static_content Zero if the content is dynamically generated and should not be cached; nonzero otherwise
+ *
* \note Function determines the HTTP response header from status_code,
* status_header, and http_header.
*
@@ -139,6 +158,8 @@
*
* Both the http_header and out arguments will be freed by this function;
* however, if FD is open, it will remain open.
+ *
+ * \since 1.6.3
*/
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);
@@ -157,10 +178,14 @@
void ast_http_prefix(char *buf, int len);
-/*!\brief get post variables from client Request Entity-Body, if content type
- * is application/x-www-form-urlencoded.
+/*!\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
+ * \note Since returned list is malloc'd, list should be free'd by the calling function
+ * \since 1.6.3
*/
-struct ast_variable *get_post_vars(struct ast_tcptls_session_instance *ser, struct ast_variable *headers);
+struct ast_variable *ast_http_get_post_vars(struct ast_tcptls_session_instance *ser, struct ast_variable *headers);
#endif /* _ASTERISK_SRV_H */
Modified: team/group/manager_http_auth/main/ast_expr2.h
URL: http://svn.digium.com/svn-view/asterisk/team/group/manager_http_auth/main/ast_expr2.h?view=diff&rev=189200&r1=189199&r2=189200
==============================================================================
--- team/group/manager_http_auth/main/ast_expr2.h (original)
+++ team/group/manager_http_auth/main/ast_expr2.h Fri Apr 17 18:13:08 2009
@@ -94,13 +94,13 @@
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
-#line 345 "/home/tilghman/Asterisk/manager_http_auth/main/ast_expr2.y"
+#line 345 "ast_expr2.y"
{
struct val *val;
struct expr_node *arglist;
}
/* Line 1489 of yacc.c. */
-#line 104 "/home/tilghman/Asterisk/manager_http_auth/main/ast_expr2.h"
+#line 104 "ast_expr2.h"
YYSTYPE;
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
Modified: team/group/manager_http_auth/main/http.c
URL: http://svn.digium.com/svn-view/asterisk/team/group/manager_http_auth/main/http.c?view=diff&rev=189200&r1=189199&r2=189200
==============================================================================
--- team/group/manager_http_auth/main/http.c (original)
+++ team/group/manager_http_auth/main/http.c Fri Apr 17 18:13:08 2009
@@ -116,25 +116,23 @@
static AST_RWLIST_HEAD_STATIC(uri_redirects, http_uri_redirect);
-const struct ast_cfhttp_methods_text {
+const struct ast_cfhttp_methods_text {
enum ast_http_method method;
- char * const text;
+ const char text[];
} ast_http_methods_text[] = {
{ AST_HTTP_UNKNOWN, "UNKNOWN" },
{ AST_HTTP_GET, "GET" },
{ AST_HTTP_POST, "POST" },
{ AST_HTTP_HEAD, "HEAD" },
- { AST_HTTP_PUT, "PUT" }
+ { AST_HTTP_PUT, "PUT" },
};
-/*! \brief Return http method name string */
-char *ast_get_http_method(enum ast_http_method method) {
+const char *ast_get_http_method(enum ast_http_method method)
+{
return ast_http_methods_text[method].text;
}
-
-/*! \brief Return mime type based on extension */
-char *ast_ftype2mtype(const char *ftype)
+const char *ast_http_ftype2mtype(const char *ftype)
{
int x;
@@ -148,7 +146,8 @@
return NULL;
}
-uint32_t manid_from_vars(struct ast_variable *headers) {
+uint32_t ast_http_manid_from_vars(struct ast_variable *headers)
+{
uint32_t mngid = 0;
struct ast_variable *v, *cookies;
@@ -172,11 +171,14 @@
}
}
-static int static_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_vars, struct ast_variable *headers)
+static int static_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_vars,
+ struct ast_variable *headers)
{
char *path;
- char *ftype;
- char *mtype;
+ const char *ftype;
+ const char *mtype;
char wkspace[80];
struct stat st;
int len;
@@ -212,9 +214,8 @@
ftype++;
}
- mtype = ast_ftype2mtype(ftype);
- if (!mtype) {
- snprintf(wkspace, sizeof(wkspace), "text/%s", ftype ? ftype : "plain");
+ if (!(mtype = ast_http_ftype2mtype(ftype))) {
+ snprintf(wkspace, sizeof(wkspace), "text/%s", S_OR(ftype, "plain"));
}
/* Cap maximum length */
@@ -237,7 +238,7 @@
goto out403;
}
- if (strstr(path, "/private/") && !astman_is_authed(manid_from_vars(headers))) {
+ if (strstr(path, "/private/") && !astman_is_authed(ast_http_manid_from_vars(headers))) {
goto out403;
}
@@ -288,7 +289,10 @@
return -1;
}
-static int httpstatus_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_vars, struct ast_variable *headers)
+static int httpstatus_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_vars,
+ struct ast_variable *headers)
{
struct ast_str *out;
struct ast_variable *v, *cookies = NULL;
@@ -355,7 +359,10 @@
/* send http/1.1 responce */
/* free content variable and close socket*/
-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, const int fd,
+ unsigned int static_content)
{
struct timeval now = ast_tvnow();
struct ast_tm tm;
@@ -424,7 +431,9 @@
}
/* Send http "401 Unauthorized" responce 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)
+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)
{
struct ast_str *http_headers = ast_str_create(128);
struct ast_str *out = ast_str_create(512);
@@ -576,7 +585,9 @@
* get post variables from client Request Entity-Body, if content type is
* application/x-www-form-urlencoded
*/
-struct ast_variable *get_post_vars(struct ast_tcptls_session_instance *ser, struct ast_variable *headers) {
+struct ast_variable *ast_http_get_post_vars(
+ struct ast_tcptls_session_instance *ser, struct ast_variable *headers)
+{
int content_length = 0;
struct ast_variable *v, *post_vars=NULL, *prev = NULL;
char *buf, *var, *val;
@@ -628,8 +639,8 @@
return post_vars;
}
-static int handle_uri(struct ast_tcptls_session_instance *ser, char *uri, enum ast_http_method method,
- struct ast_variable *headers)
+static int handle_uri(struct ast_tcptls_session_instance *ser, char *uri,
+ enum ast_http_method method, struct ast_variable *headers)
{
char *c;
int res = -1;
Modified: team/group/manager_http_auth/main/manager.c
URL: http://svn.digium.com/svn-view/asterisk/team/group/manager_http_auth/main/manager.c?view=diff&rev=189200&r1=189199&r2=189200
==============================================================================
--- team/group/manager_http_auth/main/manager.c (original)
+++ team/group/manager_http_auth/main/manager.c Fri Apr 17 18:13:08 2009
@@ -4099,7 +4099,7 @@
}
if (method == AST_HTTP_POST) {
- params = get_post_vars(ser, headers);
+ params = ast_http_get_post_vars(ser, headers);
}
for (x = 0, v = params; v && (x < AST_MAX_MANHEADERS); x++, v = v->next) {
@@ -4450,7 +4450,7 @@
}
if (method == AST_HTTP_POST) {
- params = get_post_vars(ser, headers);
+ params = ast_http_get_post_vars(ser, headers);
}
for (x = 0, v = params; v && (x < AST_MAX_MANHEADERS); x++, v = v->next) {
Modified: team/group/manager_http_auth/res/res_http_post.c
URL: http://svn.digium.com/svn-view/asterisk/team/group/manager_http_auth/res/res_http_post.c?view=diff&rev=189200&r1=189199&r2=189200
==============================================================================
--- team/group/manager_http_auth/res/res_http_post.c (original)
+++ team/group/manager_http_auth/res/res_http_post.c Fri Apr 17 18:13:08 2009
@@ -307,7 +307,7 @@
return -1;
}
- if (!astman_is_authed(manid_from_vars(headers))) {
+ if (!astman_is_authed(ast_http_manid_from_vars(headers))) {
ast_http_error(ser, 403, "Access Denied", "Sorry, I cannot let you do that, Dave.");
return -1;
}
Modified: team/group/manager_http_auth/res/res_phoneprov.c
URL: http://svn.digium.com/svn-view/asterisk/team/group/manager_http_auth/res/res_phoneprov.c?view=diff&rev=189200&r1=189199&r2=189200
==============================================================================
--- team/group/manager_http_auth/res/res_phoneprov.c (original)
+++ team/group/manager_http_auth/res/res_phoneprov.c Fri Apr 17 18:13:08 2009
@@ -629,7 +629,8 @@
* 3) Default mime type specified in profile
* 4) text/plain
*/
- ast_string_field_set(pp_file, mime_type, S_OR(args.mimetype, (S_OR(S_OR(ast_ftype2mtype(file_extension), profile->default_mime_type), "text/plain"))));
+ ast_string_field_set(pp_file, mime_type, S_OR(args.mimetype,
+ (S_OR(S_OR(ast_http_ftype2mtype(file_extension), profile->default_mime_type), "text/plain"))));
if (!strcasecmp(v->name, "static_file")) {
ast_string_field_set(pp_file, format, args.filename);
More information about the asterisk-commits
mailing list