Beispiel #1
0
void web_server::handle_post(socket_ptr socket, variant doc, const http::environment& env)
{
	static const variant TypeVariant("type");
	const std::string& type = doc[TypeVariant].as_string();
	if(type == "stats") {
		process_stats(doc);
	} else if(type == "upload_table_definitions") {
		//TODO: add authentication to get info about the user
		//and make sure they have permission to update this module.
		const std::string& module = doc[variant("module")].as_string();
		init_tables_for_module(module, doc[variant("definition")]);

		try {
			send_msg(socket, "text/json", "{ \"status\": \"ok\" }", "");
			sys::write_file("stats-definitions.json", get_tables_definition().write_json());
		} catch(validation_failure_exception& e) {
			std::map<variant,variant> msg;
			msg[variant("status")] = variant("error");
			msg[variant("message")] = variant(e.msg);
			send_msg(socket, "text/json", variant(&msg).write_json(true, variant::JSON_COMPLIANT), "");
		}

		return;
	}
	disconnect(socket);
}
Beispiel #2
0
void init_tables(const variant& doc)
{
	foreach(const variant module, doc.get_keys().as_list()) {
		init_tables_for_module(module.as_string(), doc[module]);
	}
}