adress MODAPP-55

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6491 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2007-12-04 16:22:02 +00:00
parent 41a97ef575
commit ae9f41c379
4 changed files with 66 additions and 2 deletions

View File

@ -57,6 +57,7 @@ SWITCH_BEGIN_EXTERN_C
SWITCH_DECLARE(switch_status_t) switch_b64_encode(unsigned char *in, switch_size_t ilen, unsigned char *out, switch_size_t olen);
SWITCH_DECLARE(switch_status_t) switch_b64_decode(char *in, char *out, switch_size_t olen);
SWITCH_DECLARE(char *) switch_amp_encode(char *s, char *buf, switch_size_t len);
static inline switch_bool_t switch_is_digit_string(const char *s) {

View File

@ -1545,9 +1545,13 @@ static int show_callback(void *pArg, int argc, char **argv, char **columnNames)
for (x = 0; x < argc; x++) {
char *val = switch_str_nil(argv[x]);
if (holder->http) {
char aval[512];
switch_amp_encode(argv[x], aval, sizeof(aval));
holder->stream->write_function(holder->stream, "<td>");
holder->stream->write_function(holder->stream, "%s%s", val, x == (argc - 1) ? "</td></tr>\n" : "</td><td>");
holder->stream->write_function(holder->stream, "%s%s", aval, x == (argc - 1) ? "</td></tr>\n" : "</td><td>");
} else {
holder->stream->write_function(holder->stream, "%s%s", val, x == (argc - 1) ? "\n" : holder->delim);
}
@ -1582,7 +1586,7 @@ SWITCH_STANDARD_API(show_function)
}
}
if (!as && stream->event) {
if (stream->event) {
holder.http = switch_event_get_header(stream->event, "http-host");
}

View File

@ -364,6 +364,7 @@ abyss_bool handler_hook(TSession * r)
char *fs_user = NULL, *fs_domain = NULL;
char *path_info = NULL;
abyss_bool ret = TRUE;
int html = 0;
stream.data = r;
stream.write_function = http_stream_write;
@ -371,6 +372,9 @@ abyss_bool handler_hook(TSession * r)
if ((command = strstr(r->uri, "/api/"))) {
command += 5;
} else if ((command = strstr(r->uri, "/webapi/"))) {
command += 8;
html++;
} else {
ret = FALSE;
goto end;
@ -554,6 +558,10 @@ abyss_bool handler_hook(TSession * r)
/* Generation of the server field */
ResponseAddField(r,"Server", "FreeSWITCH-" SWITCH_VERSION_FULL "-mod_xml_rpc");
if (html) {
ResponseAddField(r, "Content-Type", "text/html");
}
for (i=0;i<r->response_headers.size;i++) {
ti=&r->response_headers.item[i];
ConnWrite(r->conn, ti->name, (uint32_t)strlen(ti->name));
@ -566,6 +574,10 @@ abyss_bool handler_hook(TSession * r)
snprintf(buf, sizeof(buf), "Connection: close\r\n");
ConnWrite(r->conn, buf, (uint32_t) strlen(buf));
if (html) {
ConnWrite(r->conn, "\r\n", 2);
}
if (switch_api_execute(command, r->query, NULL, &stream) == SWITCH_STATUS_SUCCESS) {
ResponseStatus(r, 200);

View File

@ -55,6 +55,53 @@ SWITCH_DECLARE(switch_size_t) switch_fd_read_line(int fd, char *buf, switch_size
return total;
}
SWITCH_DECLARE(char *) switch_amp_encode(char *s, char *buf, switch_size_t len)
{
char *p, *q;
int x = 0;
assert(s);
q = buf;
for(p = s; x < len; p++) {
switch(*p) {
case '<':
if (x + 4 > len -1) {
goto end;
}
*q++ = '&';
*q++ = 'l';
*q++ = 't';
*q++ = ';';
x += 4;
break;
case '>':
if (x + 4 > len -1) {
goto end;
}
*q++ = '&';
*q++ = 'g';
*q++ = 't';
*q++ = ';';
x += 4;
break;
default:
if (x + 1 > len -1) {
goto end;
}
*q++ = *p;
x++;
if (*p == '\0') {
goto end;
}
break;
}
}
end:
return buf;
}
static const char switch_b64_table[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";