Revision 88b5da7b transports/janus_pfunix.c

View differences:

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 */

Also available in: Unified diff