mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-20 08:40:16 +00:00
- Doxygen additions
- Formatting fixes (read guidelines :-) ) - Removing compilation warnings git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@17105 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
24
http.c
24
http.c
@@ -18,10 +18,13 @@
|
|||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \file
|
* \file
|
||||||
* \brief http server
|
* \brief http server for AMI access
|
||||||
*
|
*
|
||||||
|
* \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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@@ -41,6 +44,9 @@
|
|||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
#include "asterisk.h"
|
#include "asterisk.h"
|
||||||
|
|
||||||
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
||||||
|
|
||||||
#include "asterisk/cli.h"
|
#include "asterisk/cli.h"
|
||||||
#include "asterisk/http.h"
|
#include "asterisk/http.h"
|
||||||
#include "asterisk/utils.h"
|
#include "asterisk/utils.h"
|
||||||
@@ -67,7 +73,7 @@ static int prefix_len = 0;
|
|||||||
static struct sockaddr_in oldsin;
|
static struct sockaddr_in oldsin;
|
||||||
static int enablestatic=0;
|
static int enablestatic=0;
|
||||||
|
|
||||||
/* Limit the kinds of files we're willing to serve up */
|
/*! \brief Limit the kinds of files we're willing to serve up */
|
||||||
static struct {
|
static struct {
|
||||||
char *ext;
|
char *ext;
|
||||||
char *mtype;
|
char *mtype;
|
||||||
@@ -360,18 +366,21 @@ static void *ast_httpd_helper_thread(void *data)
|
|||||||
if (fgets(buf, sizeof(buf), ser->f)) {
|
if (fgets(buf, sizeof(buf), ser->f)) {
|
||||||
/* Skip method */
|
/* Skip method */
|
||||||
uri = buf;
|
uri = buf;
|
||||||
while(*uri && (*uri > 32)) uri++;
|
while(*uri && (*uri > 32))
|
||||||
|
uri++;
|
||||||
if (*uri) {
|
if (*uri) {
|
||||||
*uri = '\0';
|
*uri = '\0';
|
||||||
uri++;
|
uri++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Skip white space */
|
/* Skip white space */
|
||||||
while (*uri && (*uri < 33)) uri++;
|
while (*uri && (*uri < 33))
|
||||||
|
uri++;
|
||||||
|
|
||||||
if (*uri) {
|
if (*uri) {
|
||||||
c = uri;
|
c = uri;
|
||||||
while (*c && (*c > 32)) c++;
|
while (*c && (*c > 32))
|
||||||
|
c++;
|
||||||
if (*c) {
|
if (*c) {
|
||||||
*c = '\0';
|
*c = '\0';
|
||||||
}
|
}
|
||||||
@@ -492,7 +501,7 @@ static void *http_root(void *data)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *ast_http_setcookie(const char *var, const char *val, int expires, char *buf, int buflen)
|
char *ast_http_setcookie(const char *var, const char *val, int expires, char *buf, size_t buflen)
|
||||||
{
|
{
|
||||||
char *c;
|
char *c;
|
||||||
c = buf;
|
c = buf;
|
||||||
@@ -575,6 +584,7 @@ static int __ast_http_load(int reload)
|
|||||||
struct hostent *hp;
|
struct hostent *hp;
|
||||||
struct ast_hostent ahp;
|
struct ast_hostent ahp;
|
||||||
char newprefix[MAX_PREFIX];
|
char newprefix[MAX_PREFIX];
|
||||||
|
|
||||||
memset(&sin, 0, sizeof(sin));
|
memset(&sin, 0, sizeof(sin));
|
||||||
sin.sin_port = 8088;
|
sin.sin_port = 8088;
|
||||||
strcpy(newprefix, DEFAULT_PREFIX);
|
strcpy(newprefix, DEFAULT_PREFIX);
|
||||||
@@ -654,7 +664,7 @@ static char show_http_help[] =
|
|||||||
|
|
||||||
static struct ast_cli_entry http_cli[] = {
|
static struct ast_cli_entry http_cli[] = {
|
||||||
{ { "show", "http", NULL }, handle_show_http,
|
{ { "show", "http", NULL }, handle_show_http,
|
||||||
"Display HTTP status", show_http_help },
|
"Display HTTP server status", show_http_help },
|
||||||
};
|
};
|
||||||
|
|
||||||
int ast_http_init(void)
|
int ast_http_init(void)
|
||||||
|
|||||||
@@ -37,6 +37,7 @@
|
|||||||
* \arg \ref AstREADME
|
* \arg \ref AstREADME
|
||||||
* \arg \ref AstVar
|
* \arg \ref AstVar
|
||||||
* \arg \ref AstENUM : The IETF way to redirect from phone numbers to VoIP calls
|
* \arg \ref AstENUM : The IETF way to redirect from phone numbers to VoIP calls
|
||||||
|
* \arg \ref AstHTTP
|
||||||
* \arg \ref ConfigFiles
|
* \arg \ref ConfigFiles
|
||||||
* \arg \ref SoundFiles included in the Asterisk distribution
|
* \arg \ref SoundFiles included in the Asterisk distribution
|
||||||
* \arg \ref AstCREDITS : A Thank You to contributors
|
* \arg \ref AstCREDITS : A Thank You to contributors
|
||||||
@@ -446,3 +447,12 @@ DUNDi is not itself a Voice-over IP signaling or media protocol. Instead, it pub
|
|||||||
* \par See also
|
* \par See also
|
||||||
* \arg \ref codecs
|
* \arg \ref codecs
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*! \page AstHTTP AMI over HTTP support
|
||||||
|
* The http.c file includes support for manager transactions over
|
||||||
|
* http.
|
||||||
|
* \section ami AMI - The manager Interface
|
||||||
|
* \arg \link Config_ami Configuration file \endlink
|
||||||
|
* \verbinclude http.txt
|
||||||
|
*/
|
||||||
|
|
||||||
|
|||||||
@@ -16,10 +16,6 @@
|
|||||||
* at the top of the source tree.
|
* at the top of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
* DNS SRV record support
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _ASTERISK_HTTP_H
|
#ifndef _ASTERISK_HTTP_H
|
||||||
#define _ASTERISK_HTTP_H
|
#define _ASTERISK_HTTP_H
|
||||||
|
|
||||||
@@ -30,9 +26,10 @@
|
|||||||
\brief Support for Private Asterisk HTTP Servers.
|
\brief Support for Private Asterisk HTTP Servers.
|
||||||
\note Note: The Asterisk HTTP servers are extremely simple and minimal and
|
\note Note: The Asterisk HTTP servers are extremely simple and minimal and
|
||||||
only support the "GET" method.
|
only support the "GET" method.
|
||||||
|
\author Mark Spencer <markster@digium.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* HTTP Callbacks take the socket, the method and the path as arguments and should
|
/*! \brief HTTP Callbacks take the socket, the method and the path as arguments and should
|
||||||
return the content, allocated with malloc(). Status should be changed to reflect
|
return the content, allocated with malloc(). Status should be changed to reflect
|
||||||
the status of the request if it isn't 200 and title may be set to a malloc()'d string
|
the status of the request if it isn't 200 and title may be set to a malloc()'d string
|
||||||
to an appropriate title for non-200 responses. Content length may also be specified.
|
to an appropriate title for non-200 responses. Content length may also be specified.
|
||||||
@@ -49,16 +46,16 @@ struct ast_http_uri {
|
|||||||
ast_http_callback callback;
|
ast_http_callback callback;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Link into the Asterisk HTTP server */
|
/*! \brief Link into the Asterisk HTTP server */
|
||||||
int ast_http_uri_link(struct ast_http_uri *urihandler);
|
int ast_http_uri_link(struct ast_http_uri *urihandler);
|
||||||
|
|
||||||
/* Return a malloc()'d string containing an HTTP error message */
|
/*! \brief Return a malloc()'d string containing an HTTP error message */
|
||||||
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);
|
||||||
|
|
||||||
/* Destroy an HTTP server */
|
/*! \brief Destroy an HTTP server */
|
||||||
void ast_http_uri_unlink(struct ast_http_uri *urihandler);
|
void ast_http_uri_unlink(struct ast_http_uri *urihandler);
|
||||||
|
|
||||||
char *ast_http_setcookie(const char *var, const char *val, int expires, char *buf, int buflen);
|
char *ast_http_setcookie(const char *var, const char *val, int expires, char *buf, size_t buflen);
|
||||||
|
|
||||||
int ast_http_init(void);
|
int ast_http_init(void);
|
||||||
int ast_http_reload(void);
|
int ast_http_reload(void);
|
||||||
|
|||||||
27
manager.c
27
manager.c
@@ -237,7 +237,7 @@ static char *complete_show_mancmd(const char *line, const char *word, int pos, i
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void xml_copy_escape(char **dst, int *maxlen, const char *src, int lower)
|
static void xml_copy_escape(char **dst, size_t *maxlen, const char *src, int lower)
|
||||||
{
|
{
|
||||||
while (*src && (*maxlen > 6)) {
|
while (*src && (*maxlen > 6)) {
|
||||||
switch(*src) {
|
switch(*src) {
|
||||||
@@ -273,6 +273,7 @@ static void xml_copy_escape(char **dst, int *maxlen, const char *src, int lower)
|
|||||||
src++;
|
src++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *xml_translate(char *in, struct ast_variable *vars)
|
static char *xml_translate(char *in, struct ast_variable *vars)
|
||||||
{
|
{
|
||||||
struct ast_variable *v;
|
struct ast_variable *v;
|
||||||
@@ -281,12 +282,13 @@ static char *xml_translate(char *in, struct ast_variable *vars)
|
|||||||
char *objtype=NULL;
|
char *objtype=NULL;
|
||||||
int colons = 0;
|
int colons = 0;
|
||||||
int breaks = 0;
|
int breaks = 0;
|
||||||
int len;
|
size_t len;
|
||||||
int count = 1;
|
int count = 1;
|
||||||
int escaped = 0;
|
int escaped = 0;
|
||||||
int inobj = 0;
|
int inobj = 0;
|
||||||
int x;
|
int x;
|
||||||
v = vars;
|
v = vars;
|
||||||
|
|
||||||
while(v) {
|
while(v) {
|
||||||
if (!dest && !strcasecmp(v->name, "ajaxdest"))
|
if (!dest && !strcasecmp(v->name, "ajaxdest"))
|
||||||
dest = v->value;
|
dest = v->value;
|
||||||
@@ -298,7 +300,7 @@ static char *xml_translate(char *in, struct ast_variable *vars)
|
|||||||
dest = "unknown";
|
dest = "unknown";
|
||||||
if (!objtype)
|
if (!objtype)
|
||||||
objtype = "generic";
|
objtype = "generic";
|
||||||
for (x=0;in[x];x++) {
|
for (x=0; in[x]; x++) {
|
||||||
if (in[x] == ':')
|
if (in[x] == ':')
|
||||||
colons++;
|
colons++;
|
||||||
else if (in[x] == '\n')
|
else if (in[x] == '\n')
|
||||||
@@ -306,14 +308,15 @@ static char *xml_translate(char *in, struct ast_variable *vars)
|
|||||||
else if (strchr("&\"<>", in[x]))
|
else if (strchr("&\"<>", in[x]))
|
||||||
escaped++;
|
escaped++;
|
||||||
}
|
}
|
||||||
len = strlen(in) + colons * 5 + breaks * (40 + strlen(dest) + strlen(objtype)) + escaped * 10; /* foo="bar", "<response type=\"object\" id=\"dest\"", "&" */
|
len = (size_t) (strlen(in) + colons * 5 + breaks * (40 + strlen(dest) + strlen(objtype)) + escaped * 10); /* foo="bar", "<response type=\"object\" id=\"dest\"", "&" */
|
||||||
out = malloc(len);
|
out = malloc(len);
|
||||||
if (!out)
|
if (!out)
|
||||||
return 0;
|
return 0;
|
||||||
tmp = out;
|
tmp = out;
|
||||||
while(*in) {
|
while(*in) {
|
||||||
var = in;
|
var = in;
|
||||||
while (*in && (*in >= 32)) in++;
|
while (*in && (*in >= 32))
|
||||||
|
in++;
|
||||||
if (*in) {
|
if (*in) {
|
||||||
if ((count > 3) && inobj) {
|
if ((count > 3) && inobj) {
|
||||||
ast_build_string(&tmp, &len, " /></response>\n");
|
ast_build_string(&tmp, &len, " /></response>\n");
|
||||||
@@ -353,10 +356,11 @@ static char *html_translate(char *in)
|
|||||||
int x;
|
int x;
|
||||||
int colons = 0;
|
int colons = 0;
|
||||||
int breaks = 0;
|
int breaks = 0;
|
||||||
int len;
|
size_t len;
|
||||||
int count=1;
|
int count=1;
|
||||||
char *tmp, *var, *val, *out;
|
char *tmp, *var, *val, *out;
|
||||||
for (x=0;in[x];x++) {
|
|
||||||
|
for (x=0; in[x]; x++) {
|
||||||
if (in[x] == ':')
|
if (in[x] == ':')
|
||||||
colons++;
|
colons++;
|
||||||
if (in[x] == '\n')
|
if (in[x] == '\n')
|
||||||
@@ -369,7 +373,8 @@ static char *html_translate(char *in)
|
|||||||
tmp = out;
|
tmp = out;
|
||||||
while(*in) {
|
while(*in) {
|
||||||
var = in;
|
var = in;
|
||||||
while (*in && (*in >= 32)) in++;
|
while (*in && (*in >= 32))
|
||||||
|
in++;
|
||||||
if (*in) {
|
if (*in) {
|
||||||
if ((count % 4) == 0){
|
if ((count % 4) == 0){
|
||||||
ast_build_string(&tmp, &len, "<tr><td colspan=\"2\"><hr></td></tr>\r\n");
|
ast_build_string(&tmp, &len, "<tr><td colspan=\"2\"><hr></td></tr>\r\n");
|
||||||
@@ -405,7 +410,8 @@ void astman_append(struct mansession *s, const char *fmt, ...)
|
|||||||
va_end(ap);
|
va_end(ap);
|
||||||
if (res == -1) {
|
if (res == -1) {
|
||||||
ast_log(LOG_ERROR, "Memory allocation failure\n");
|
ast_log(LOG_ERROR, "Memory allocation failure\n");
|
||||||
} else {
|
return;
|
||||||
|
}
|
||||||
if (s->fd > -1)
|
if (s->fd > -1)
|
||||||
ast_carefulwrite(s->fd, stuff, strlen(stuff), s->writetimeout);
|
ast_carefulwrite(s->fd, stuff, strlen(stuff), s->writetimeout);
|
||||||
else {
|
else {
|
||||||
@@ -418,7 +424,6 @@ void astman_append(struct mansession *s, const char *fmt, ...)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(stuff);
|
free(stuff);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int handle_showmancmd(int fd, int argc, char *argv[])
|
static int handle_showmancmd(int fd, int argc, char *argv[])
|
||||||
@@ -2139,7 +2144,7 @@ static char *generic_http_callback(int format, struct sockaddr_in *requestor, co
|
|||||||
char workspace[256];
|
char workspace[256];
|
||||||
char cookie[128];
|
char cookie[128];
|
||||||
char iabuf[INET_ADDRSTRLEN];
|
char iabuf[INET_ADDRSTRLEN];
|
||||||
int len = sizeof(workspace);
|
size_t len = sizeof(workspace);
|
||||||
int blastaway = 0;
|
int blastaway = 0;
|
||||||
char *c = workspace;
|
char *c = workspace;
|
||||||
char *retval=NULL;
|
char *retval=NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user