Revision 88b5da7b

View differences:

conf/janus.transport.http.cfg.sample.in
8 8
; pool instead. Since long polls are involved, make sure you choose a
9 9
; value that doesn't keep new connections waiting.
10 10
[general]
11
json = indented				; Whether the JSON messages should be indented (default),
12
							; plain (no indentation) or compact (no indentation and no spaces)
11 13
base_path = /janus			; Base path to bind to in the web server (plain HTTP only)
12 14
threads = unlimited			; unlimited=thread per connection, number=thread pool
13 15
http = yes					; Whether to enable the plain HTTP interface
conf/janus.transport.pfunix.cfg.sample
4 4
[general]
5 5
enabled = yes					; Whether to enable the Unix Sockets interface
6 6
								; for Janus API clients
7
json = indented					; Whether the JSON messages should be indented (default),
8
								; plain (no indentation) or compact (no indentation and no spaces)
7 9
path = /tmp/ux-janusapi			; Path to bind to (Janus API)
8 10
;type = SOCK_SEQPACKET			; SOCK_SEQPACKET (default) or SOCK_DGRAM?
9 11

  
conf/janus.transport.rabbitmq.cfg.sample
16 16
; is disabled by default, so set enable=yes if you want to use it.
17 17
[general]
18 18
enable = no					; Whether the support must be enabled
19
json = indented				; Whether the JSON messages should be indented (default),
20
							; plain (no indentation) or compact (no indentation and no spaces)
19 21
host = localhost			; The address of the RabbitMQ server
20 22
;port = 5672				; The port of the RabbitMQ server (5672 by default)
21 23
;username = guest			; Username to use to authenticate, if needed
conf/janus.transport.websockets.cfg.sample.in
1 1
; WebSockets stuff: whether they should be enabled, which ports they
2 2
; should use, and so on.
3 3
[general]
4
json = indented				; Whether the JSON messages should be indented (default),
5
							; plain (no indentation) or compact (no indentation and no spaces)
4 6
ws = yes					; Whether to enable the WebSockets API
5 7
ws_port = 8188				; WebSockets server port
6 8
;ws_interface = eth0		; Whether we should bind this server to a specific interface only
transports/janus_http.c
104 104
static gboolean http_janus_api_enabled = FALSE;
105 105
static gboolean http_admin_api_enabled = FALSE;
106 106

  
107
/* JSON serialization options */
108
static size_t json_format = JSON_INDENT(3) | JSON_PRESERVE_ORDER;
109

  
107 110

  
108 111
/* Incoming HTTP message */
109 112
typedef struct janus_http_msg {
......
551 554
		janus_config_print(config);
552 555

  
553 556
		/* Handle configuration */
554
		
555
		/* ... starting with the base paths */
556
		janus_config_item *item = janus_config_get_item_drilldown(config, "general", "base_path");
557
		janus_config_item *item = janus_config_get_item_drilldown(config, "general", "json");
558
		if(item && item->value) {
559
			/* Check how we need to format/serialize the JSON output */
560
			if(!strcasecmp(item->value, "indented")) {
561
				/* Default: indented, we use three spaces for that */
562
				json_format = JSON_INDENT(3) | JSON_PRESERVE_ORDER;
563
			} else if(!strcasecmp(item->value, "plain")) {
564
				/* Not indented and no new lines, but still readable */
565
				json_format = JSON_INDENT(0) | JSON_PRESERVE_ORDER;
566
			} else if(!strcasecmp(item->value, "compact")) {
567
				/* Compact, so no spaces between separators */
568
				json_format = JSON_COMPACT | JSON_PRESERVE_ORDER;
569
			} else {
570
				JANUS_LOG(LOG_WARN, "Unsupported JSON format option '%s', using default (indented)\n", item->value);
571
				json_format = JSON_INDENT(3) | JSON_PRESERVE_ORDER;
572
			}
573
		}
574

  
575
		/* Check the base paths */
576
		item = janus_config_get_item_drilldown(config, "general", "base_path");
557 577
		if(item && item->value) {
558 578
			if(item->value[0] != '/') {
559 579
				JANUS_LOG(LOG_FATAL, "Invalid base path %s (it should start with a /, e.g., /janus\n", item->value);
......
1298 1318
		if(event != NULL) {
1299 1319
			if(max_events == 1) {
1300 1320
				/* Return just this message and leave */
1301
				gchar *event_text = json_dumps(event, JSON_INDENT(3) | JSON_PRESERVE_ORDER);
1321
				gchar *event_text = json_dumps(event, json_format);
1302 1322
				json_decref(event);
1303 1323
				ret = janus_http_return_success(msg, event_text);
1304 1324
			} else {
......
1314 1334
					events++;
1315 1335
				}
1316 1336
				/* Return the array of messages and leave */
1317
				gchar *list_text = json_dumps(list, JSON_INDENT(3) | JSON_PRESERVE_ORDER);
1337
				gchar *list_text = json_dumps(list, json_format);
1318 1338
				json_decref(list);
1319 1339
				ret = janus_http_return_success(msg, list_text);
1320 1340
			}
......
1366 1386
	if(!msg->response) {
1367 1387
		ret = MHD_NO;
1368 1388
	} else {
1369
		char *response_text = json_dumps(msg->response, JSON_INDENT(3) | JSON_PRESERVE_ORDER);
1389
		char *response_text = json_dumps(msg->response, json_format);
1370 1390
		json_decref(msg->response);
1371 1391
		msg->response = NULL;
1372 1392
		ret = janus_http_return_success(msg, response_text);
......
1613 1633
	if(!msg->response) {
1614 1634
		ret = MHD_NO;
1615 1635
	} else {
1616
		char *response_text = json_dumps(msg->response, JSON_INDENT(3) | JSON_PRESERVE_ORDER);
1636
		char *response_text = json_dumps(msg->response, json_format);
1617 1637
		json_decref(msg->response);
1618 1638
		msg->response = NULL;
1619 1639
		ret = janus_http_return_success(msg, response_text);
......
1740 1760
		}
1741 1761
		/* FIXME Improve the Janus protocol keep-alive mechanism in JavaScript */
1742 1762
	}
1743
	char *payload_text = json_dumps(list ? list : event, JSON_INDENT(3) | JSON_PRESERVE_ORDER);
1763
	char *payload_text = json_dumps(list ? list : event, json_format);
1744 1764
	json_decref(list ? list : event);
1745 1765
	/* Finish the request by sending the response */
1746 1766
	JANUS_LOG(LOG_VERB, "We have a message to serve...\n\t%s\n", payload_text);
......
1798 1818
	json_object_set_new(error_data, "code", json_integer(error));
1799 1819
	json_object_set_new(error_data, "reason", json_string(error_string));
1800 1820
	json_object_set_new(reply, "error", error_data);
1801
	gchar *reply_text = json_dumps(reply, JSON_INDENT(3) | JSON_PRESERVE_ORDER);
1821
	gchar *reply_text = json_dumps(reply, json_format);
1802 1822
	json_decref(reply);
1803 1823
	/* Use janus_http_return_error to send the error response */
1804 1824
	return janus_http_return_success(msg, reply_text);
transports/janus_pfunix.c
97 97
static gint initialized = 0, stopping = 0;
98 98
static janus_transport_callbacks *gateway = NULL;
99 99

  
100
/* JSON serialization options */
101
static size_t json_format = JSON_INDENT(3) | JSON_PRESERVE_ORDER;
102

  
100 103
#define BUFFER_SIZE		8192
101 104

  
102 105
struct sockaddr_un sizecheck;
......
190 193
		/* Handle configuration */
191 194
		janus_config_print(config);
192 195

  
196
		janus_config_item *item = janus_config_get_item_drilldown(config, "general", "json");
197
		if(item && item->value) {
198
			/* Check how we need to format/serialize the JSON output */
199
			if(!strcasecmp(item->value, "indented")) {
200
				/* Default: indented, we use three spaces for that */
201
				json_format = JSON_INDENT(3) | JSON_PRESERVE_ORDER;
202
			} else if(!strcasecmp(item->value, "plain")) {
203
				/* Not indented and no new lines, but still readable */
204
				json_format = JSON_INDENT(0) | JSON_PRESERVE_ORDER;
205
			} else if(!strcasecmp(item->value, "compact")) {
206
				/* Compact, so no spaces between separators */
207
				json_format = JSON_COMPACT | JSON_PRESERVE_ORDER;
208
			} else {
209
				JANUS_LOG(LOG_WARN, "Unsupported JSON format option '%s', using default (indented)\n", item->value);
210
				json_format = JSON_INDENT(3) | JSON_PRESERVE_ORDER;
211
			}
212
		}
213

  
193 214
		/* First of all, initialize the socketpair for writeable notifications */
194 215
		if(socketpair(PF_LOCAL, SOCK_STREAM, 0, write_fd) < 0) {
195 216
			JANUS_LOG(LOG_FATAL, "Error creating socket pair for writeable events: %d, %s\n", errno, strerror(errno));
......
197 218
		}
198 219

  
199 220
		/* Setup the Janus API Unix Sockets server(s) */
200
		janus_config_item *item = janus_config_get_item_drilldown(config, "general", "enabled");
221
		item = janus_config_get_item_drilldown(config, "general", "enabled");
201 222
		if(!item || !item->value || !janus_is_true(item->value)) {
202 223
			JANUS_LOG(LOG_WARN, "Unix Sockets server disabled (Janus API)\n");
203 224
		} else {
......
343 364
	}
344 365
	janus_mutex_unlock(&clients_mutex);
345 366
	/* Convert to string */
346
	char *payload = json_dumps(message, JSON_INDENT(3) | JSON_PRESERVE_ORDER);
367
	char *payload = json_dumps(message, json_format);
347 368
	json_decref(message);
348 369
	if(client->fd != -1) {
349 370
		/* SOCK_SEQPACKET, enqueue the packet and have poll tell us when it's time to send it */
transports/janus_rabbitmq.c
105 105
static gboolean rmq_janus_api_enabled = FALSE;
106 106
static gboolean rmq_admin_api_enabled = FALSE;
107 107

  
108
/* JSON serialization options */
109
static size_t json_format = JSON_INDENT(3) | JSON_PRESERVE_ORDER;
110

  
108 111

  
109 112
/* RabbitMQ client session: we only create a single one as of now */
110 113
typedef struct janus_rabbitmq_client {
......
162 165
	if(config != NULL)
163 166
		janus_config_print(config);
164 167

  
168
	janus_config_item *item = janus_config_get_item_drilldown(config, "general", "json");
169
	if(item && item->value) {
170
		/* Check how we need to format/serialize the JSON output */
171
		if(!strcasecmp(item->value, "indented")) {
172
			/* Default: indented, we use three spaces for that */
173
			json_format = JSON_INDENT(3) | JSON_PRESERVE_ORDER;
174
		} else if(!strcasecmp(item->value, "plain")) {
175
			/* Not indented and no new lines, but still readable */
176
			json_format = JSON_INDENT(0) | JSON_PRESERVE_ORDER;
177
		} else if(!strcasecmp(item->value, "compact")) {
178
			/* Compact, so no spaces between separators */
179
			json_format = JSON_COMPACT | JSON_PRESERVE_ORDER;
180
		} else {
181
			JANUS_LOG(LOG_WARN, "Unsupported JSON format option '%s', using default (indented)\n", item->value);
182
			json_format = JSON_INDENT(3) | JSON_PRESERVE_ORDER;
183
		}
184
	}
185

  
165 186
	/* Handle configuration, starting from the server details */
166 187
	char *rmqhost = NULL;
167
	janus_config_item *item = janus_config_get_item_drilldown(config, "general", "host");
188
	item = janus_config_get_item_drilldown(config, "general", "host");
168 189
	if(item && item->value)
169 190
		rmqhost = g_strdup(item->value);
170 191
	else
......
591 612
		if(!rmq_client->destroy && !g_atomic_int_get(&stopping) && response->payload) {
592 613
			janus_mutex_lock(&rmq_client->mutex);
593 614
			/* Gotcha! Convert json_t to string */
594
			char *payload_text = json_dumps(response->payload, JSON_INDENT(3) | JSON_PRESERVE_ORDER);
615
			char *payload_text = json_dumps(response->payload, json_format);
595 616
			json_decref(response->payload);
596 617
			response->payload = NULL;
597 618
			JANUS_LOG(LOG_VERB, "Sending %s API message to RabbitMQ (%zu bytes)...\n", response->admin ? "Admin" : "Janus", strlen(payload_text));
transports/janus_websockets.c
98 98
static gboolean wss_janus_api_enabled = FALSE;
99 99
static gboolean wss_admin_api_enabled = FALSE;
100 100

  
101
/* JSON serialization options */
102
static size_t json_format = JSON_INDENT(3) | JSON_PRESERVE_ORDER;
103

  
101 104

  
102 105
/* Logging */
103 106
static int ws_log_level = 0;
......
360 363
		janus_config_print(config);
361 364

  
362 365
		/* Handle configuration */
363
		janus_config_item *item = janus_config_get_item_drilldown(config, "general", "ws_logging");
366
		janus_config_item *item = janus_config_get_item_drilldown(config, "general", "json");
367
		if(item && item->value) {
368
			/* Check how we need to format/serialize the JSON output */
369
			if(!strcasecmp(item->value, "indented")) {
370
				/* Default: indented, we use three spaces for that */
371
				json_format = JSON_INDENT(3) | JSON_PRESERVE_ORDER;
372
			} else if(!strcasecmp(item->value, "plain")) {
373
				/* Not indented and no new lines, but still readable */
374
				json_format = JSON_INDENT(0) | JSON_PRESERVE_ORDER;
375
			} else if(!strcasecmp(item->value, "compact")) {
376
				/* Compact, so no spaces between separators */
377
				json_format = JSON_COMPACT | JSON_PRESERVE_ORDER;
378
			} else {
379
				JANUS_LOG(LOG_WARN, "Unsupported JSON format option '%s', using default (indented)\n", item->value);
380
				json_format = JSON_INDENT(3) | JSON_PRESERVE_ORDER;
381
			}
382
		}
383

  
384
		item = janus_config_get_item_drilldown(config, "general", "ws_logging");
364 385
		if(item && item->value) {
365 386
			ws_log_level = atoi(item->value);
366 387
			if(ws_log_level < 0)
......
782 803
	}
783 804
	janus_mutex_lock(&client->mutex);
784 805
	/* Convert to string and enqueue */
785
	char *payload = json_dumps(message, JSON_INDENT(3) | JSON_PRESERVE_ORDER);
806
	char *payload = json_dumps(message, json_format);
786 807
	g_async_queue_push(client->messages, payload);
787 808
#ifdef HAVE_LIBWEBSOCKETS_NEWAPI
788 809
	lws_callback_on_writable(client->wsi);

Also available in: Unified diff