diff --git a/src/include/switch_utils.h b/src/include/switch_utils.h
index cdea67b889..1d090b2941 100644
--- a/src/include/switch_utils.h
+++ b/src/include/switch_utils.h
@@ -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) {
diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c
index 914e1600b4..ebf209dff0 100644
--- a/src/mod/applications/mod_commands/mod_commands.c
+++ b/src/mod/applications/mod_commands/mod_commands.c
@@ -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, "
");
- holder->stream->write_function(holder->stream, "%s%s", val, x == (argc - 1) ? " | \n" : "");
+ holder->stream->write_function(holder->stream, "%s%s", aval, x == (argc - 1) ? " | \n" : "");
} 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");
}
diff --git a/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c b/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c
index 3983d30aee..85b1c0f177 100644
--- a/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c
+++ b/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c
@@ -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;iresponse_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);
diff --git a/src/switch_utils.c b/src/switch_utils.c
index 84f91c5b39..0028b154a9 100644
--- a/src/switch_utils.c
+++ b/src/switch_utils.c
@@ -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+/";
|