mirror of
https://gitlab.xiph.org/xiph/icecast-server.git
synced 2025-04-18 00:48:43 -04:00
Feature: Support JSON mapping for all reportxml based outputs
This commit is contained in:
parent
deaad3246c
commit
b44df0da76
23
src/client.c
23
src/client.c
@ -43,6 +43,7 @@
|
|||||||
#include "reportxml.h"
|
#include "reportxml.h"
|
||||||
#include "refobject.h"
|
#include "refobject.h"
|
||||||
#include "xslt.h"
|
#include "xslt.h"
|
||||||
|
#include "xml2json.h"
|
||||||
#include "source.h"
|
#include "source.h"
|
||||||
|
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
@ -363,6 +364,7 @@ static inline void _client_send_report(client_t *client, const char *uuid, const
|
|||||||
|
|
||||||
switch (admin_format) {
|
switch (admin_format) {
|
||||||
case ADMIN_FORMAT_RAW:
|
case ADMIN_FORMAT_RAW:
|
||||||
|
case ADMIN_FORMAT_JSON:
|
||||||
xslt = NULL;
|
xslt = NULL;
|
||||||
break;
|
break;
|
||||||
case ADMIN_FORMAT_HTML:
|
case ADMIN_FORMAT_HTML:
|
||||||
@ -554,6 +556,7 @@ void client_send_reportxml(client_t *client, reportxml_t *report, document_domai
|
|||||||
if (!xsl) {
|
if (!xsl) {
|
||||||
switch (admin_format) {
|
switch (admin_format) {
|
||||||
case ADMIN_FORMAT_RAW:
|
case ADMIN_FORMAT_RAW:
|
||||||
|
case ADMIN_FORMAT_JSON:
|
||||||
/* noop, we don't need to set xsl */
|
/* noop, we don't need to set xsl */
|
||||||
break;
|
break;
|
||||||
case ADMIN_FORMAT_HTML:
|
case ADMIN_FORMAT_HTML:
|
||||||
@ -581,14 +584,24 @@ void client_send_reportxml(client_t *client, reportxml_t *report, document_domai
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (admin_format == ADMIN_FORMAT_RAW) {
|
if (admin_format == ADMIN_FORMAT_RAW || admin_format == ADMIN_FORMAT_JSON) {
|
||||||
xmlChar *buff = NULL;
|
xmlChar *buff = NULL;
|
||||||
size_t location_length = 0;
|
size_t location_length = 0;
|
||||||
int len = 0;
|
int len = 0;
|
||||||
size_t buf_len;
|
size_t buf_len;
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
|
const char *content_type;
|
||||||
|
|
||||||
|
if (admin_format == ADMIN_FORMAT_RAW) {
|
||||||
xmlDocDumpMemory(doc, &buff, &len);
|
xmlDocDumpMemory(doc, &buff, &len);
|
||||||
|
content_type = "text/xml";
|
||||||
|
} else {
|
||||||
|
char *json = xml2json_render_doc_simple(doc);
|
||||||
|
buff = xmlStrdup(XMLSTR(json));
|
||||||
|
len = strlen(json);
|
||||||
|
free(json);
|
||||||
|
content_type = "application/json";
|
||||||
|
}
|
||||||
|
|
||||||
if (location) {
|
if (location) {
|
||||||
location_length = strlen(location);
|
location_length = strlen(location);
|
||||||
@ -604,7 +617,7 @@ void client_send_reportxml(client_t *client, reportxml_t *report, document_domai
|
|||||||
|
|
||||||
ret = util_http_build_header(client->refbuf->data, buf_len, 0,
|
ret = util_http_build_header(client->refbuf->data, buf_len, 0,
|
||||||
0, status, NULL,
|
0, status, NULL,
|
||||||
"text/xml", "utf-8",
|
content_type, "utf-8",
|
||||||
NULL, NULL, client);
|
NULL, NULL, client);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
ICECAST_LOG_ERROR("Dropping client as we can not build response headers.");
|
ICECAST_LOG_ERROR("Dropping client as we can not build response headers.");
|
||||||
@ -621,7 +634,7 @@ void client_send_reportxml(client_t *client, reportxml_t *report, document_domai
|
|||||||
client->refbuf->len = buf_len;
|
client->refbuf->len = buf_len;
|
||||||
ret = util_http_build_header(client->refbuf->data, buf_len, 0,
|
ret = util_http_build_header(client->refbuf->data, buf_len, 0,
|
||||||
0, status, NULL,
|
0, status, NULL,
|
||||||
"text/xml", "utf-8",
|
content_type, "utf-8",
|
||||||
NULL, NULL, client);
|
NULL, NULL, client);
|
||||||
if (ret == -1) {
|
if (ret == -1) {
|
||||||
ICECAST_LOG_ERROR("Dropping client as we can not build response headers.");
|
ICECAST_LOG_ERROR("Dropping client as we can not build response headers.");
|
||||||
@ -756,7 +769,7 @@ admin_format_t client_get_admin_format_by_content_negotiation(client_t *client)
|
|||||||
if (!client || !client->parser)
|
if (!client || !client->parser)
|
||||||
return CLIENT_DEFAULT_ADMIN_FORMAT;
|
return CLIENT_DEFAULT_ADMIN_FORMAT;
|
||||||
|
|
||||||
pref = util_http_select_best(httpp_getvar(client->parser, "accept"), "text/xml", "text/html", "text/plain", (const char*)NULL);
|
pref = util_http_select_best(httpp_getvar(client->parser, "accept"), "text/xml", "text/html", "text/plain", "application/json", (const char*)NULL);
|
||||||
|
|
||||||
if (strcmp(pref, "text/xml") == 0) {
|
if (strcmp(pref, "text/xml") == 0) {
|
||||||
return ADMIN_FORMAT_RAW;
|
return ADMIN_FORMAT_RAW;
|
||||||
@ -764,6 +777,8 @@ admin_format_t client_get_admin_format_by_content_negotiation(client_t *client)
|
|||||||
return ADMIN_FORMAT_HTML;
|
return ADMIN_FORMAT_HTML;
|
||||||
} else if (strcmp(pref, "text/plain") == 0) {
|
} else if (strcmp(pref, "text/plain") == 0) {
|
||||||
return ADMIN_FORMAT_PLAINTEXT;
|
return ADMIN_FORMAT_PLAINTEXT;
|
||||||
|
} else if (strcmp(pref, "application/json") == 0) {
|
||||||
|
return ADMIN_FORMAT_JSON;
|
||||||
} else {
|
} else {
|
||||||
return CLIENT_DEFAULT_ADMIN_FORMAT;
|
return CLIENT_DEFAULT_ADMIN_FORMAT;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user