예제 #1
0
/** \brief Start the operation
 * 
 * - at lease one of the xmlrpc_uri and jsrest_uri MUST be set
 * 
 * \param xmlrpc_uri	the http_uri_t on which to listen for the xmlrpc call.
 *			If null, dont listen to xmlrpc
 * \param jsrest_uri	the http_uri_t on which to listen for the jsrest call
 *			If null, dont listen to jsrest
 */
xmlrpc_err_t	xmlrpc_listener_t::start(http_listener_t *m_http_listener
			, const http_uri_t &xmlrpc_uri, const http_uri_t &jsrest_uri)	throw()
{
	http_err_t	http_err; 
	// log to debug
	KLOG_DBG("enter");
	// sanity check - at lease one of the xmlrpc_uri and jsrest_uri MUST be set
	DBG_ASSERT( !xmlrpc_uri.is_null() || !jsrest_uri.is_null() ); 

	// copy the parameter
	this->m_http_listener	= m_http_listener;
		
	// start the m_sresp_xmlrpc
	if( !xmlrpc_uri.is_null() ){
		m_sresp_xmlrpc	= nipmem_new http_sresp_t();
		http_err	= m_sresp_xmlrpc->start(http_listener(), xmlrpc_uri
					, http_method_t::POST, http_resp_mode_t::REJECT_SUBPATH
					, this, NULL);
		if( http_err.failed() )	return xmlrpc_err_from_http(http_err);
	}

	// start the m_sresp_jsrestm_sresp_jsrest
	if( !jsrest_uri.is_null() ){
		m_sresp_jsrest	= nipmem_new http_sresp_t();
		http_err	= m_sresp_jsrest->start(http_listener(), jsrest_uri
					, http_method_t::GET, http_resp_mode_t::REJECT_SUBPATH
					, this, NULL);
		if( http_err.failed() )	return xmlrpc_err_from_http(http_err);
	}	
	// return no error
	return xmlrpc_err_t::OK;
}
예제 #2
0
MyListener::MyListener(const http::uri& url) : m_listener(http_listener(url))
{
	m_listener.support(methods::GET, std::tr1::bind(&MyListener::handle_get, this, std::tr1::placeholders::_1)); 
	//m_listener.support(methods::PUT, std::tr1::bind(&MyListener::handle_put, this, std::tr1::placeholders::_1));
	m_listener.support(methods::POST, std::tr1::bind(&MyListener::handle_post, this, std::tr1::placeholders::_1));
	//	m_listener.support(methods::DEL, std::tr1::bind(&MyListener::handle_delete, this, std::tr1::placeholders::_1));
}
예제 #3
0
/** \brief Constructor the bt_httpo_t and http_listener_t
 */
bt_err_t	oload_apps_t::launch_httpo(const strvar_db_t &oload_conf)	throw()
{
	bt_err_t	bt_err;
	// log to debug
	KLOG_WARN("enter");

	// get the listen_ipport from the oload_conf
	std::string	port_min_str	= oload_conf.get_first_value("http_listener_port_min", "4242");
	std::string	port_max_str	= oload_conf.get_first_value("http_listener_port_max", "4242");
	ip_addr_t	listener_addr	= oload_conf.get_first_value("http_listener_addr", "127.0.0.1");
	uint16_t	listener_portmin= string_t::to_uint16(port_min_str);
	uint16_t	listener_portmax= string_t::to_uint16(port_max_str);	
	// try to find a free one within the configured range
	ipport_addr_t	listener_ipport	= ipport_addr_helper_t::find_avail_listen_addr(listener_addr
						, listener_portmin, listener_portmax);
	if( listener_ipport.is_null() )	return bt_err_t(bt_err_t::ERROR, "no free port for http_listener");

	// build the resp_arg for the http_listener_t 
	socket_resp_arg_t	resp_arg;
	resp_arg	= socket_resp_arg_t().profile(socket_profile_t(socket_domain_t::TCP))
					.domain(socket_domain_t::TCP).type(socket_type_t::STREAM)
					.listen_addr("tcp://" + listener_ipport.to_string());
	// start the http_listener_t
	http_err_t	http_err;
	m_http_listener	= nipmem_new http_listener_t();
	http_err	= m_http_listener->start(resp_arg);
	if( http_err.failed() )		return bt_err_from_http(http_err);
	
	// start the bt_httpo_t
	m_httpo_listener= nipmem_new bt_httpo_listener_t();
	bt_err		= m_httpo_listener->start(http_listener());
	if( bt_err.failed() )		return bt_err;
	
	// return no error
	return bt_err_t::OK;
}
예제 #4
0
/** \brief Start the operation
 */
bt_err_t	oload_apps_t::start()						throw()
{
	lib_session_t *		lib_session	= lib_session_get();
	lib_apps_t *		lib_apps	= lib_session->lib_apps();
	const strvar_db_t &	arg_option	= lib_apps->arg_option();
	file_path_t		config_path	= lib_session->conf_rootdir() / "oload";
	bt_err_t		bt_err;
	// log to debug
	KLOG_WARN("enter");

	// init the static link http - to ease access while debugging
	wikidbg_obj_add_static_page("/oload_apps_" + OSTREAMSTR(this));
	
	// load the configuration file for this apps
	strvar_db_t oload_conf	= strvar_helper_t::from_file(config_path / "neoip_oload.conf");

	// start the bt_httpo_t
	bt_err		= launch_httpo(oload_conf);
	if( bt_err.failed() )		return bt_err;

	// Launch the apps_httpdetect_t - use directly neoip_*_info.hpp #define 
	// - cant use libapps->canon_name() because it would be wrong for neoip-webok
	libsess_err_t	libsess_err;
	m_apps_httpdetect = nipmem_new apps_httpdetect_t();
	libsess_err	= m_apps_httpdetect->start(http_listener(), NEOIP_APPS_CANON_NAME
							, NEOIP_APPS_VERSION);
	if( libsess_err.failed() )	return bt_err_t(bt_err_t::ERROR, libsess_err.to_string());

	// Launch the bt_cast_prefetch_t
	m_cast_prefetch	= nipmem_new bt_cast_prefetch_t();
	bt_err		= m_cast_prefetch->start(http_listener());
	if( bt_err.failed() )		return bt_err;

	// Launch the oload_httpo_ctrl_t
	m_httpo_ctrl	= nipmem_new oload_httpo_ctrl_t();
	bt_err		= m_httpo_ctrl->start(this);
	if( bt_err.failed() )		return bt_err;
	
	// Launch the oload_flash_xdom_t
	m_flash_xdom	= nipmem_new oload_flash_xdom_t();
	bt_err		= m_flash_xdom->start(http_listener());
	if( bt_err.failed() )		return bt_err;
	
	// start the oload_mod_vapi_t
	bt_err		= launch_mod();
	if( bt_err.failed() )		return bt_err;
	
	// start the bt_httpo_t
	bt_err		= launch_ezsession(oload_conf);
	if( bt_err.failed() )		return bt_err;

	// if the arg_option DOES NOT contains the "nodaemon" key, pass daemon
	// - NOTE: be carefull this change the pid
	if( !arg_option.contain_key("nodaemon") && lib_apps_helper_t::daemonize().failed() ){
		DBG_ASSERT( 0 );
		return bt_err_t(bt_err_t::ERROR, "Can't daemon()");
	}

	// create the pidfile
	// - NOTE: it MUST be done after the daemon() to get the proper pid
	lib_apps_helper_t::pidfile_create();

	// create the urlfile
	// - NOTE: it MUST be done after the daemon() to get the proper pid
	lib_apps_helper_t::urlfile_create();

	// set the io_pfile_dirpath name
	m_io_pfile_dirpath	= lib_session->temp_rootdir() / (lib_apps->canon_name()+"_pfile.");
	m_io_pfile_dirpath	= file_utils_t::get_temp_path(m_io_pfile_dirpath);

	// create the temporary directory io_pfile_dirpath()
	// - TODO this should be created by bt_alloc_t?
	// - all this stuff about bt_alloc_t and bt_io_pfile_t is unclear
	// - there is the deletion of this directory in the oload_apps_t dtor
	file_err_t	file_err;
	file_err	= file_utils_t::create_directory(io_pfile_dirpath(), file_utils_t::NO_RECURSION);
	if( file_err.failed() )	return bt_err_from_file(file_err);
	// return no error
	return bt_err_t::OK;
}