mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-07 10:28:32 +00:00
After discussing this with other people, we decided we'd like to try to do this a little differently.
Stay tuned. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@43290 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -106,12 +106,6 @@ int ast_manager_register2(
|
|||||||
*/
|
*/
|
||||||
int ast_manager_unregister( char *action );
|
int ast_manager_unregister( char *action );
|
||||||
|
|
||||||
/*! Add a manager_user to current list of manager */
|
|
||||||
int *ast_manager_add(struct ast_manager_user *amu);
|
|
||||||
|
|
||||||
/*! Get an manager by his name */
|
|
||||||
struct ast_manager_user *ast_get_manager_by_name_locked(const char *name);
|
|
||||||
|
|
||||||
/*! External routines may send asterisk manager events this way */
|
/*! External routines may send asterisk manager events this way */
|
||||||
/*! \param category Event category, matches manager authorization
|
/*! \param category Event category, matches manager authorization
|
||||||
\param event Event name
|
\param event Event name
|
||||||
@@ -139,11 +133,5 @@ void astman_append(struct mansession *s, const char *fmt, ...)
|
|||||||
int init_manager(void);
|
int init_manager(void);
|
||||||
/*! Called by Asterisk initialization */
|
/*! Called by Asterisk initialization */
|
||||||
int reload_manager(void);
|
int reload_manager(void);
|
||||||
/*! Add a manager_user to current list of manager */
|
|
||||||
int *ast_manager_add(struct ast_manager_user *amu);
|
|
||||||
int *ast_manager_user_add(struct ast_manager_user *amu);
|
|
||||||
/*! Get an manager by his name */
|
|
||||||
struct ast_manager_user *ast_get_manager_by_name_locked(const char *name);
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* _ASTERISK_MANAGER_H */
|
#endif /* _ASTERISK_MANAGER_H */
|
||||||
|
|||||||
86
main/http.c
86
main/http.c
@@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Asterisk -- An open source telephony toolkit.
|
* Asterisk -- An open source telephony toolkit.
|
||||||
*
|
*
|
||||||
* Copyright (C) 1999 - 2006, Digium, Inc.
|
* Copyright (C) 1999 - 2006, Digium, Inc.
|
||||||
@@ -17,13 +17,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \file
|
* \file
|
||||||
* \brief http server for AMI access
|
* \brief http server for AMI access
|
||||||
*
|
*
|
||||||
* \author Mark Spencer <markster@digium.com>
|
* \author Mark Spencer <markster@digium.com>
|
||||||
* This program implements a tiny http server supporting the "get" method
|
* This program implements a tiny http server supporting the "get" method
|
||||||
* only and was inspired by micro-httpd by Jef Poskanzer
|
* only and was inspired by micro-httpd by Jef Poskanzer
|
||||||
*
|
*
|
||||||
* \ref AstHTTP - AMI over the http protocol
|
* \ref AstHTTP - AMI over the http protocol
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -110,7 +110,7 @@ static char *static_callback(struct sockaddr_in *req, const char *uri, struct as
|
|||||||
int fd;
|
int fd;
|
||||||
void *blob;
|
void *blob;
|
||||||
|
|
||||||
/* Yuck. I'm not really sold on this, but if you don't deliver static content it makes your configuration
|
/* Yuck. I'm not really sold on this, but if you don't deliver static content it makes your configuration
|
||||||
substantially more challenging, but this seems like a rather irritating feature creep on Asterisk. */
|
substantially more challenging, but this seems like a rather irritating feature creep on Asterisk. */
|
||||||
if (!enablestatic || ast_strlen_zero(uri))
|
if (!enablestatic || ast_strlen_zero(uri))
|
||||||
goto out403;
|
goto out403;
|
||||||
@@ -119,16 +119,16 @@ static char *static_callback(struct sockaddr_in *req, const char *uri, struct as
|
|||||||
goto out403;
|
goto out403;
|
||||||
if (strstr(uri, "/.."))
|
if (strstr(uri, "/.."))
|
||||||
goto out403;
|
goto out403;
|
||||||
|
|
||||||
if ((ftype = strrchr(uri, '.')))
|
if ((ftype = strrchr(uri, '.')))
|
||||||
ftype++;
|
ftype++;
|
||||||
mtype=ftype2mtype(ftype, wkspace, sizeof(wkspace));
|
mtype=ftype2mtype(ftype, wkspace, sizeof(wkspace));
|
||||||
|
|
||||||
/* Cap maximum length */
|
/* Cap maximum length */
|
||||||
len = strlen(uri) + strlen(ast_config_AST_DATA_DIR) + strlen("/static-http/") + 5;
|
len = strlen(uri) + strlen(ast_config_AST_DATA_DIR) + strlen("/static-http/") + 5;
|
||||||
if (len > 1024)
|
if (len > 1024)
|
||||||
goto out403;
|
goto out403;
|
||||||
|
|
||||||
path = alloca(len);
|
path = alloca(len);
|
||||||
sprintf(path, "%s/static-http/%s", ast_config_AST_DATA_DIR, uri);
|
sprintf(path, "%s/static-http/%s", ast_config_AST_DATA_DIR, uri);
|
||||||
if (stat(path, &st))
|
if (stat(path, &st))
|
||||||
@@ -138,9 +138,9 @@ static char *static_callback(struct sockaddr_in *req, const char *uri, struct as
|
|||||||
fd = open(path, O_RDONLY);
|
fd = open(path, O_RDONLY);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
goto out403;
|
goto out403;
|
||||||
|
|
||||||
len = st.st_size + strlen(mtype) + 40;
|
len = st.st_size + strlen(mtype) + 40;
|
||||||
|
|
||||||
blob = malloc(len);
|
blob = malloc(len);
|
||||||
if (blob) {
|
if (blob) {
|
||||||
c = blob;
|
c = blob;
|
||||||
@@ -211,14 +211,14 @@ static struct ast_http_uri statusuri = {
|
|||||||
.uri = "httpstatus",
|
.uri = "httpstatus",
|
||||||
.has_subtree = 0,
|
.has_subtree = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct ast_http_uri staticuri = {
|
static struct ast_http_uri staticuri = {
|
||||||
.callback = static_callback,
|
.callback = static_callback,
|
||||||
.description = "Asterisk HTTP Static Delivery",
|
.description = "Asterisk HTTP Static Delivery",
|
||||||
.uri = "static",
|
.uri = "static",
|
||||||
.has_subtree = 1,
|
.has_subtree = 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
char *ast_http_error(int status, const char *title, const char *extra_header, const char *text)
|
char *ast_http_error(int status, const char *title, const char *extra_header, const char *text)
|
||||||
{
|
{
|
||||||
char *c = NULL;
|
char *c = NULL;
|
||||||
@@ -253,7 +253,7 @@ int ast_http_uri_link(struct ast_http_uri *urih)
|
|||||||
prev->next = urih;
|
prev->next = urih;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ast_http_uri_unlink(struct ast_http_uri *urih)
|
void ast_http_uri_unlink(struct ast_http_uri *urih)
|
||||||
{
|
{
|
||||||
@@ -282,8 +282,8 @@ static char *handle_uri(struct sockaddr_in *sin, char *uri, int *status, char **
|
|||||||
struct ast_http_uri *urih=NULL;
|
struct ast_http_uri *urih=NULL;
|
||||||
int len;
|
int len;
|
||||||
struct ast_variable *vars=NULL, *v, *prev = NULL;
|
struct ast_variable *vars=NULL, *v, *prev = NULL;
|
||||||
|
|
||||||
|
|
||||||
params = strchr(uri, '?');
|
params = strchr(uri, '?');
|
||||||
if (params) {
|
if (params) {
|
||||||
*params = '\0';
|
*params = '\0';
|
||||||
@@ -294,7 +294,7 @@ static char *handle_uri(struct sockaddr_in *sin, char *uri, int *status, char **
|
|||||||
*val = '\0';
|
*val = '\0';
|
||||||
val++;
|
val++;
|
||||||
ast_uri_decode(val);
|
ast_uri_decode(val);
|
||||||
} else
|
} else
|
||||||
val = "";
|
val = "";
|
||||||
ast_uri_decode(var);
|
ast_uri_decode(var);
|
||||||
if ((v = ast_variable_new(var, val))) {
|
if ((v = ast_variable_new(var, val))) {
|
||||||
@@ -395,32 +395,32 @@ static void *ast_httpd_helper_thread(void *data)
|
|||||||
break;
|
break;
|
||||||
if (!strncasecmp(cookie, "Cookie: ", 8)) {
|
if (!strncasecmp(cookie, "Cookie: ", 8)) {
|
||||||
|
|
||||||
/* TODO - The cookie parsing code below seems to work
|
/* TODO - The cookie parsing code below seems to work
|
||||||
in IE6 and FireFox 1.5. However, it is not entirely
|
in IE6 and FireFox 1.5. However, it is not entirely
|
||||||
correct, and therefore may not work in all
|
correct, and therefore may not work in all
|
||||||
circumstances.
|
circumstances.
|
||||||
For more details see RFC 2109 and RFC 2965 */
|
For more details see RFC 2109 and RFC 2965 */
|
||||||
|
|
||||||
/* FireFox cookie strings look like:
|
/* FireFox cookie strings look like:
|
||||||
Cookie: mansession_id="********"
|
Cookie: mansession_id="********"
|
||||||
InternetExplorer's look like:
|
InternetExplorer's look like:
|
||||||
Cookie: $Version="1"; mansession_id="********" */
|
Cookie: $Version="1"; mansession_id="********" */
|
||||||
|
|
||||||
/* If we got a FireFox cookie string, the name's right
|
/* If we got a FireFox cookie string, the name's right
|
||||||
after "Cookie: " */
|
after "Cookie: " */
|
||||||
vname = cookie + 8;
|
vname = cookie + 8;
|
||||||
|
|
||||||
/* If we got an IE cookie string, we need to skip to
|
/* If we got an IE cookie string, we need to skip to
|
||||||
past the version to get to the name */
|
past the version to get to the name */
|
||||||
if (*vname == '$') {
|
if (*vname == '$') {
|
||||||
vname = strchr(vname, ';');
|
vname = strchr(vname, ';');
|
||||||
if (vname) {
|
if (vname) {
|
||||||
vname++;
|
vname++;
|
||||||
if (*vname == ' ')
|
if (*vname == ' ')
|
||||||
vname++;
|
vname++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vname) {
|
if (vname) {
|
||||||
vval = strchr(vname, '=');
|
vval = strchr(vname, '=');
|
||||||
if (vval) {
|
if (vval) {
|
||||||
@@ -444,11 +444,11 @@ static void *ast_httpd_helper_thread(void *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (*uri) {
|
if (*uri) {
|
||||||
if (!strcasecmp(buf, "get"))
|
if (!strcasecmp(buf, "get"))
|
||||||
c = handle_uri(&ser->requestor, uri, &status, &title, &contentlength, &vars);
|
c = handle_uri(&ser->requestor, uri, &status, &title, &contentlength, &vars);
|
||||||
else
|
else
|
||||||
c = ast_http_error(501, "Not Implemented", NULL, "Attempt to use unimplemented / unsupported method");\
|
c = ast_http_error(501, "Not Implemented", NULL, "Attempt to use unimplemented / unsupported method");\
|
||||||
} else
|
} else
|
||||||
c = ast_http_error(400, "Bad Request", NULL, "Invalid Request");
|
c = ast_http_error(400, "Bad Request", NULL, "Invalid Request");
|
||||||
|
|
||||||
/* If they aren't mopped up already, clean up the cookies */
|
/* If they aren't mopped up already, clean up the cookies */
|
||||||
@@ -492,7 +492,7 @@ static void *http_root(void *data)
|
|||||||
struct ast_http_server_instance *ser;
|
struct ast_http_server_instance *ser;
|
||||||
pthread_t launched;
|
pthread_t launched;
|
||||||
pthread_attr_t attr;
|
pthread_attr_t attr;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
ast_wait_for_input(httpfd, -1);
|
ast_wait_for_input(httpfd, -1);
|
||||||
sinlen = sizeof(sin);
|
sinlen = sizeof(sin);
|
||||||
@@ -509,7 +509,7 @@ static void *http_root(void *data)
|
|||||||
if ((ser->f = fdopen(ser->fd, "w+"))) {
|
if ((ser->f = fdopen(ser->fd, "w+"))) {
|
||||||
pthread_attr_init(&attr);
|
pthread_attr_init(&attr);
|
||||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
||||||
|
|
||||||
if (ast_pthread_create(&launched, &attr, ast_httpd_helper_thread, ser)) {
|
if (ast_pthread_create(&launched, &attr, ast_httpd_helper_thread, ser)) {
|
||||||
ast_log(LOG_WARNING, "Unable to launch helper thread: %s\n", strerror(errno));
|
ast_log(LOG_WARNING, "Unable to launch helper thread: %s\n", strerror(errno));
|
||||||
fclose(ser->f);
|
fclose(ser->f);
|
||||||
@@ -541,36 +541,36 @@ static void http_server_start(struct sockaddr_in *sin)
|
|||||||
{
|
{
|
||||||
int flags;
|
int flags;
|
||||||
int x = 1;
|
int x = 1;
|
||||||
|
|
||||||
/* Do nothing if nothing has changed */
|
/* Do nothing if nothing has changed */
|
||||||
if (!memcmp(&oldsin, sin, sizeof(oldsin))) {
|
if (!memcmp(&oldsin, sin, sizeof(oldsin))) {
|
||||||
ast_log(LOG_DEBUG, "Nothing changed in http\n");
|
ast_log(LOG_DEBUG, "Nothing changed in http\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(&oldsin, sin, sizeof(oldsin));
|
memcpy(&oldsin, sin, sizeof(oldsin));
|
||||||
|
|
||||||
/* Shutdown a running server if there is one */
|
/* Shutdown a running server if there is one */
|
||||||
if (master != AST_PTHREADT_NULL) {
|
if (master != AST_PTHREADT_NULL) {
|
||||||
pthread_cancel(master);
|
pthread_cancel(master);
|
||||||
pthread_kill(master, SIGURG);
|
pthread_kill(master, SIGURG);
|
||||||
pthread_join(master, NULL);
|
pthread_join(master, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (httpfd != -1)
|
if (httpfd != -1)
|
||||||
close(httpfd);
|
close(httpfd);
|
||||||
|
|
||||||
/* If there's no new server, stop here */
|
/* If there's no new server, stop here */
|
||||||
if (!sin->sin_family)
|
if (!sin->sin_family)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
httpfd = socket(AF_INET, SOCK_STREAM, 0);
|
httpfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
if (httpfd < 0) {
|
if (httpfd < 0) {
|
||||||
ast_log(LOG_WARNING, "Unable to allocate socket: %s\n", strerror(errno));
|
ast_log(LOG_WARNING, "Unable to allocate socket: %s\n", strerror(errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setsockopt(httpfd, SOL_SOCKET, SO_REUSEADDR, &x, sizeof(x));
|
setsockopt(httpfd, SOL_SOCKET, SO_REUSEADDR, &x, sizeof(x));
|
||||||
if (bind(httpfd, (struct sockaddr *)sin, sizeof(*sin))) {
|
if (bind(httpfd, (struct sockaddr *)sin, sizeof(*sin))) {
|
||||||
ast_log(LOG_NOTICE, "Unable to bind http server to %s:%d: %s\n",
|
ast_log(LOG_NOTICE, "Unable to bind http server to %s:%d: %s\n",
|
||||||
@@ -634,7 +634,7 @@ static int __ast_http_load(int reload)
|
|||||||
} else {
|
} else {
|
||||||
newprefix[0] = '\0';
|
newprefix[0] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
v = v->next;
|
v = v->next;
|
||||||
}
|
}
|
||||||
|
|||||||
466
main/manager.c
466
main/manager.c
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user