Ejemplo n.º 1
0
unsigned int checkcmd(clientget *cget, transport_t transport, subuser **iuser, acetables *g_ape)
{	
	struct _cmd_process pc = {cget->hlines, NULL, NULL, cget->client, cget->host, cget->ip_get, transport};
	
	json_item *ijson, *ojson;
	
	unsigned int ret;

	ijson = ojson = init_json_parser(cget->get);
	if (ijson == NULL || ijson->jchild.child == NULL) {
		RAW *newraw;
		json_item *jlist = json_new_object();

		json_set_property_strZ(jlist, "code", "005");
		json_set_property_strZ(jlist, "value", "BAD_JSON");

		newraw = forge_raw(RAW_ERR, jlist);
		
		send_raw_inline(cget->client, transport, newraw, g_ape);
	} else {
		for (ijson = ijson->jchild.child; ijson != NULL; ijson = ijson->next) {
			
			if (pc.guser != NULL && pc.guser->istmp) { /* if "CONNECT" was delayed, push other cmd to the queue and stop execution */
				pc.guser->cmdqueue = json_item_copy(ijson, NULL);
				break;
			}		
			if ((ret = process_cmd(ijson, &pc, iuser, g_ape)) != -1) {
				free_json_item(ojson);
				return ret;
			}
			if (*iuser != NULL) {
				pc.sub = *iuser;
			}					
		}
		free_json_item(ojson);

		return (CONNECT_KEEPALIVE);
	}
	
	return (CONNECT_SHUTDOWN);
}
Ejemplo n.º 2
0
json_item *init_json_parser(const char *json_string)
{
	const char *pRaw;
	JSON_config config;

	struct JSON_parser_struct* jc = NULL;
	
	json_context jcx = {0, 0, NULL, NULL};

	init_JSON_config(&config);
	
	config.depth		= 15;
	config.callback		= &json_callback;
	config.callback_ctx	= &jcx;
	
	config.allow_comments	= 0;
	config.handle_floats_manually = 0;

	jc = new_JSON_parser(&config);

	for (pRaw = json_string; *pRaw; pRaw++) {
		if (!JSON_parser_char(jc, *pRaw)) {
			free_json_item(jcx.head);
		    delete_JSON_parser(jc);
		    return NULL;
		}
	}
	
	if (!JSON_parser_done(jc)) {
		free_json_item(jcx.head);
		delete_JSON_parser(jc);
		return NULL;
	}

	delete_JSON_parser(jc);
	
	return jcx.head;	
}
Ejemplo n.º 3
0
void free_json_item(json_item *cx)
{
	while (cx != NULL) {
		json_item *tcx;

		if (cx->key.val != NULL) {
			free(cx->key.val);
		}
		if (cx->jval.vu.str.value != NULL) {
			free(cx->jval.vu.str.value);
		}
		if (cx->jchild.child != NULL) {
			free_json_item(cx->jchild.child);
		}
		tcx = cx->next;
		free(cx);
		cx = tcx;
	}
}