Revision 88b5da7b transports/janus_rabbitmq.c

View differences:

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));

Also available in: Unified diff