Ejemplo n.º 1
0
void vban_init(struct agent_core_t *core)
{
	struct agent_plugin_t *plug;
	struct vban_priv_t *priv;

	ALLOC_OBJ(priv);
	plug = plugin_find(core,"vban");
	priv->logger = ipc_register(core,"logger");
	priv->vadmin = ipc_register(core,"vadmin");
	plug->data = (void *)priv;
	http_register_url(core, "/ban", M_GET | M_POST, vban_reply, core);
	http_register_url(core, "/help/ban", M_GET, help_reply, strdup(BAN_HELP_TEXT));
}
Ejemplo n.º 2
0
void
vdirect_init(struct agent_core_t *core)
{
	struct agent_plugin_t *plug;
	struct vdirect_priv_t *priv = malloc(sizeof(struct vdirect_priv_t));
	plug = plugin_find(core,"vdirect");
	
	priv->logger = ipc_register(core,"logger");
	priv->vadmin = ipc_register(core,"vadmin");
	plug->data = (void *)priv;
	plug->start = NULL;
	http_register_url(core, "/direct", M_POST, vdirect_reply, core);
	http_register_url(core, "/help/direct", M_GET, help_reply, strdup(DIRECT_HELP));
}
Ejemplo n.º 3
0
void
vparams_init(struct agent_core_t *core)
{
	struct agent_plugin_t *plug;
	struct vparams_priv_t *priv;

	ALLOC_OBJ(priv);
	plug = plugin_find(core,"vparams");

	priv->logger = ipc_register(core,"logger");
	priv->vadmin = ipc_register(core,"vadmin");
	plug->data = (void *)priv;
	http_register_url(core, "/param/", M_PUT | M_GET, vparams_reply, core);
	http_register_url(core, "/paramjson/", M_GET, vparams_reply, core);
	http_register_url(core, "/help/param", M_GET, help_reply, strdup(PARAM_HELP));
}
Ejemplo n.º 4
0
void
vbackends_init(struct agent_core_t *core)
{
	struct agent_plugin_t *plug;
	struct vbackends_priv_t *priv;

	ALLOC_OBJ(priv);
	plug = plugin_find(core,"vbackends");

	priv->logger = ipc_register(core,"logger");
	priv->vadmin = ipc_register(core,"vadmin");
	plug->data = (void *)priv;
	http_register_url(core, "/backend/", M_PUT, vbackends_reply, core);
	http_register_url(core, "/backendjson/", M_GET, vbackends_reply, core);
	http_register_url(core, "/help/backend", M_GET,
	    help_reply, strdup(BACKENDS_HELP));
}
Ejemplo n.º 5
0
Archivo: vcl.c Proyecto: aondio/vagent2
void
vcl_init(struct agent_core_t *core)
{
	struct agent_plugin_t *plug;
	struct vcl_priv_t *priv;

	ALLOC_OBJ(priv);
	plug = plugin_find(core,"vcl");
	priv->logger = ipc_register(core,"logger");
	priv->vadmin = ipc_register(core,"vadmin");
	plug->data = (void *)priv;
	mk_help(core, priv);
	http_register_url(core, "/vcljson/", M_GET, vcl_reply, core);
	http_register_url(core, "/vcl/", M_DELETE | M_PUT | M_GET | M_POST, vcl_reply, core);
	http_register_url(core, "/vclactive", M_GET , vcl_reply, core);
	http_register_url(core, "/vcldeploy/", M_PUT , vcl_reply, core);
	http_register_url(core, "/help/vcl", M_GET, help_reply, priv->help);
}
Ejemplo n.º 6
0
Archivo: vlog.c Proyecto: agiza/vagent2
void vlog_init(struct agent_core_t *core)
{
	struct agent_plugin_t *plug;
	struct vlog_priv_t *priv = calloc(1, sizeof(struct vlog_priv_t));
	plug = plugin_find(core,"vlog");
	assert(plug);
	plug->data = priv;

	http_register_url(core, "/log", M_GET, vlog_reply, core);
}
Ejemplo n.º 7
0
void
html_init(struct agent_core_t *core)
{
	struct agent_plugin_t *plug;
	struct html_priv_t *priv = malloc(sizeof(struct html_priv_t));
	plug = plugin_find(core,"html");
	
	priv->logger = ipc_register(core,"logger");
	plug->data = (void *)priv;
	plug->start = NULL;
	http_register_url(core, "/html/", M_GET, html_reply, core);
}
Ejemplo n.º 8
0
int output_init_http(struct output_s *o) {

	o->buffer=sb_init(HTTP_MAX_TS, TS_PACKET_SIZE, 0);
	if (o->buffer == NULL)
		return 0;

	o->hurl=calloc(2, sizeof(struct http_url));

	o->hurl->url=o->url;
	o->hurl->cb=output_cb_http;
	o->hurl->arg=(void *) o;

	http_register_url(hserver, o->hurl);

	return 0;
}
Ejemplo n.º 9
0
Archivo: echo.c Proyecto: Dridi/vagent2
void echo_init(struct agent_core_t *core)
{
	/*
	 * Allocate the private data structure we'll keep using.
	 */
	struct echo_priv_t *priv = malloc(sizeof(struct echo_priv_t));

	/*
	 * Find our pre-allocated data structure. This is only used to
	 * define start-functions (which we don't have), module-specific
	 * private data and an IPC for the module (which we don't use).
	 */
	struct agent_plugin_t *plug;
	plug = plugin_find(core,"echo");
	assert(plug);

	/*
	 * Register with the logger.
	 */
	priv->logger = ipc_register(core,"logger");

	/*
	 * Store our private data somewhere we can reach it, and set our
	 * start function to NULL since echo is only triggered by HTTP
	 * requests.
	 */
	plug->data = (void *)priv;
	plug->start = NULL;

	/*
	 * Register the url /echo for the methods POST, PUT and GET. When a
	 * request like that is encountered, the echo_reply function will
	 * be called with "priv" as the last argument.
	 */
	http_register_url(core, "/echo", M_POST | M_PUT | M_GET, echo_reply, priv);
}
Ejemplo n.º 10
0
static unsigned int vlog_reply(struct http_request *request, void *data)
{
	struct vlog_req_priv vrp = { .limit = 10 };
	int disp_status;
	char *p;
	char *tag = NULL;
	char *tag_re = NULL;
	struct VSL_data *vsl = NULL;
	struct VSLQ *vslq = NULL;
	struct VSL_cursor *c = NULL;
	enum VSL_grouping_e grouping = VSL_g_request;
	struct agent_core_t *core = data;

	p = next_slash(request->url + 1);
	if (p) {
		char *lim = strdup(p);
		assert(lim);
		char *tmp2 = strchr(lim, '/');
		if (tmp2 && *tmp2) *tmp2 = '\0';

		int j = sscanf(lim, "%u", &vrp.limit);
		if(j != 1) {
			free(lim);
			http_reply(request->connection, 500, "Not a number");
			return 0;
		}

		free(lim);
		p = next_slash(p);
	}

	if (p) {
		tag = strdup(p);
		char *tmp2 = strchr(tag,'/');
		if (tmp2 && *tmp2) *tmp2 = '\0';
		p = next_slash(p);
	}

	if (p) {
		tag_re = strdup(p);
		char *tmp2 = strchr(tag_re, '/');
		if (tmp2 && *tmp2) *tmp2 = '\0';
		p = next_slash(p);
	}
	
	vrp.answer = VSB_new_auto();
	assert(vrp.answer != NULL);

	vrp.vsm = VSM_New();
	assert(vrp.vsm);
	if (!VSM_n_Arg(vrp.vsm, core->config->n_arg)) {
		VSB_printf(vrp.answer, "Error in creating shmlog: %s",
		    VSM_Error(vrp.vsm));
		VSB_finish(vrp.answer);
		http_reply(request->connection, 500, VSB_data(vrp.answer));
		goto cleanup;
	}

	if (VSM_Open(vrp.vsm) != 0) {
		VSB_printf(vrp.answer, "Error in opening shmlog: %s",
		    VSM_Error(vrp.vsm));
		VSB_finish(vrp.answer);
		http_reply(request->connection, 500, VSB_data(vrp.answer));
		goto cleanup;
	}
	
	vsl = VSL_New();
	assert(vsl);

	if (tag) {
		grouping = VSL_g_raw;
		
		if (VSL_Arg(vsl, 'i', tag) < 0) {
			VSB_printf(vrp.answer, "Unable to specify tag '%s': %s",
			    tag, VSL_Error(vsl));
			VSB_finish(vrp.answer);
			http_reply(request->connection, 500, VSB_data(vrp.answer));
			goto cleanup;
		}
		if (tag_re) {
			VSL_Arg(vsl,'I', tag_re);
		}
	}

	c = VSL_CursorVSM(vsl, vrp.vsm,
	    VSL_COPT_BATCH | VSL_COPT_TAILSTOP);
	if (c == NULL) {
		VSB_printf(vrp.answer, "Can't open log (%s)",
		    VSL_Error(vsl));
		VSB_finish(vrp.answer);
		http_reply(request->connection, 500, VSB_data(vrp.answer));
		goto cleanup;
	}

	
	vslq = VSLQ_New(vsl, &c, grouping, NULL);
	if (vslq == NULL) {
		VSB_clear(vrp.answer);
		VSB_printf(vrp.answer, "Error in creating query: %s",
		    VSL_Error(vsl));
		http_reply(request->connection, 500, VSB_data(vrp.answer));
		goto cleanup;
	}

	VSB_printf(vrp.answer, "{ \"log\": [");

	do {
		disp_status = VSLQ_Dispatch(vslq, vlog_cb_func, &vrp);
	} while (disp_status == 1 && vrp.entries < vrp.limit);

	VSB_printf(vrp.answer, "\n] }\n");

	assert(VSB_finish(vrp.answer) == 0);
	if (VSB_len(vrp.answer) > 1) {
		struct http_response *resp = http_mkresp(request->connection, 200, NULL);
		resp->data = VSB_data(vrp.answer);
		resp->ndata = VSB_len(vrp.answer);
		http_add_header(resp,"Content-Type","application/json");
		send_response(resp);
		http_free_resp(resp);
	} else {
		http_reply(request->connection, 500, "FAIL");
	}

 cleanup:
	free(tag);
	free(tag_re);
	VSB_delete(vrp.answer);
	if (vslq)
		VSLQ_Delete(&vslq);
	if (vsl)
		VSL_Delete(vsl);
	if (vrp.vsm)
		VSM_Delete(vrp.vsm);
	vrp.answer = NULL;
	return 0;
}

void vlog_init(struct agent_core_t *core)
{
	struct agent_plugin_t *plug;
	struct vlog_priv_t *priv;

	ALLOC_OBJ(priv);
	plug = plugin_find(core,"vlog");
	plug->data = priv;

	http_register_url(core, "/log", M_GET, vlog_reply, core);
}