Пример #1
0
// Called from lua to start listening to files
static int addon_output_pload_listen_start(lua_State *L) {

	// Args should be :
	// 1) self
	// 2) open function
	// 3) write function
	// 4) close function

	// Push nill if additional functions are missing
	while (lua_gettop(L) < 4)
		lua_pushnil(L);

	// Stack : instance, read_func, write_func, close_func

	// Get the output
	struct addon_instance_priv *p = addon_output_get_priv(L, 1);

	if (!lua_isfunction(L, 2) && !lua_isfunction(L, 3) && !lua_isfunction(L, 4))
		luaL_error(L, "At least one function should be provided to pload_listen_start()");

	// Check if we are already listening or not
	lua_getfield(L, 1, "__pload_listener");
	if (!lua_isnil(L, -1))
		luaL_error(L, "The output is already listening for payloads");

	if (pload_listen_start(p, NULL, NULL, addon_output_pload_open, addon_output_pload_write, addon_output_pload_close) != POM_OK)
		luaL_error(L, "Error while registering the payload listener");


	// Create table to track pload listener functions
	lua_pushliteral(L, "__pload_listener");
	lua_newtable(L);

	if (!lua_isnil(L, 2)) {
		lua_pushliteral(L, "open");
		lua_pushvalue(L, 2);
		lua_settable(L, -3);
	}

	if (!lua_isnil(L, 3)) {
		lua_pushliteral(L, "write");
		lua_pushvalue(L, 3);
		lua_settable(L, -3);
	}

	if (!lua_isnil(L, 4)) {
		lua_pushliteral(L, "close");
		lua_pushvalue(L, 4);
		lua_settable(L, -3);
	}

	lua_settable(L, 1);
	
	return 0;
}
Пример #2
0
int output_file_open(void *output_priv) {

	struct output_file_priv *priv = output_priv;

	char *filter_str = PTYPE_STRING_GETVAL(priv->p_filter);
	struct filter *filter = NULL;

	if (strlen(filter_str)) {
		filter = pload_filter_compile(filter_str);
		if (!filter) {
			pomlog(POMLOG_ERR "Error while parsing filter '%s'", filter_str);
			return POM_ERR;
		}
	}

	char *listen_pload_evt = PTYPE_BOOL_GETVAL(priv->p_listen_pload_evt);
	if (*listen_pload_evt && event_payload_listen_start() != POM_OK) {
		if (filter)
			filter_cleanup(filter);
		return POM_ERR;
	}

	return pload_listen_start(output_priv, NULL, filter, output_file_pload_open, output_file_pload_write, output_file_pload_close);
}
Пример #3
0
static int analyzer_multipart_init(struct analyzer *analyzer) {

	return pload_listen_start(analyzer, ANALYZER_MULTIPART_PLOAD_TYPE, NULL, analyzer_multipart_pload_open, analyzer_multipart_pload_write, analyzer_multipart_pload_close);
}