예제 #1
0
/* Like 'search_file' */
onion_connection_status OnionServer::getSettingKinectWrapped(
		Onion::Request &req, Onion::Response &res)
{
	const char* path = onion_request_get_fullpath( req.c_handler() );
#ifdef VERBOSE
	printf("Request of %s.\n",path);
#endif
	std::string filename("./html/");
	filename.append(path);

	std::ifstream file(filename.c_str());
	std::string line;

	if( file.is_open()){

		/* Create header with mime type and charset information for several file extensions.
		 * This is just a workaround. There should be an automatic mechanicm
		 * in libonion. */
		int periodPos = filename.find_last_of('.');
		std::string extension = filename.substr(periodPos+1);
		std::string key("Content-Type");
		std::string defaultType("text/html; charset: utf-8");

		std::string mime = m_mimedict.get( extension , defaultType ) ;
		res.setHeader(key,mime);
		onion_response_write_headers(res.c_handler());// missing in cpp bindings?
		//res.writeHeaders();//this was added by me...

		try{
			/*
			res.write("json_kinect = ", 14);
			const char* kinect = m_settingKinect.getConfig(true);
			size_t len = strlen( kinect );
			res.write(kinect, (int) len );
			res.write(";\n", 2 );
			*/

			while (std::getline(file, line)) {
				res.write( line.c_str(), line.size() );
				res.write("\n", 1 );
			}
		}//catch ( const boost::iobase::failure &ex )
		catch ( const std::exception & ex ){
			std::cerr << "Can not read " << filename << std::endl;
			res.write( ErrReadFailed.c_str(), ErrReadFailed.size());
		}
	}else{
		res.write( ErrNotFound.c_str(), ErrNotFound.size());
	}

	return OCS_PROCESSED;
}
예제 #2
0
/*
 Replace some template variables and send b9creator_settings.js
*/
onion_connection_status OnionServer::getB9CreatorSettingsWrapped(
		Onion::Request &req, Onion::Response &res)
{
	/*
		 std::string key("ONION_JSON");
		 std::string conf(m_b9CreatorSettings.getConfig());
		 Onion::Dict d;
		 d.add(key, conf, 0);
		 return b9creator_settings_js_template(d.c_handler(), req.c_handler(), res.c_handler());
		 */
	onion_dict *d=onion_dict_new();//will free'd in template call
	onion_dict_add( d, "ONION_JSON",
			m_b9CreatorSettings.getConfig(), 0);
	return b9creator_settings_js_template(d, req.c_handler(), res.c_handler());
}
예제 #3
0
/*
 Replace some template variables (filename of last config) call index_html_template
*/
onion_connection_status OnionServer::index_html( Onion::Request &req, Onion::Response &res)
{
	/* Problem: This cause double free of mem because
	 * onion_dict_free will called twice: in index_html_template and deconstructor.
	 * Onion::Dict d;
	 std::string key("LAST_SETTING_FILENAME");
	 d.add(key,m_b9CreatorSettings.m_configFilename,0);
	 return index_html_template(d.c_handler(), req.c_handler(), res.c_handler() );
	 */
	onion_dict *d=onion_dict_new();//will free'd in template call
	onion_dict_add( d, "LAST_SETTING_FILENAME",
			m_b9CreatorSettings.m_configFilename.c_str(), 0);

	return index_html_template(d, req.c_handler(), res.c_handler() );
}
예제 #4
0
/*
 Replace some template variables (filename of last config) call index_html_template
*/
onion_connection_status OnionServer::index_html( Onion::Request &req, Onion::Response &res)
{
	/* Issue note: The following cause double free of mem because
	 * onion_dict_free will called twice: in index_html_template and deconstructor.
	 * Onion::Dict d;
	 std::string key("LAST_SETTING_FILENAME");
	 d.add(key,m_settingKinect.m_configFilename,0);
	 return index_html_template(d.c_handler(), req.c_handler(), res.c_handler() );

	 => Thus, use pointer, but do not free here.
	 */
	onion_dict *d=onion_dict_new();//will free'd in template call
	onion_dict_add( d, "LAST_SETTING_FILENAME",
			m_settingKinect.m_configFilename.c_str(), 0);

	return index_html_template(d, req.c_handler(), res.c_handler() );
}
예제 #5
0
/*
 * Parse data from client. Use actionid-arg to distinct different
 * cases.
 */
onion_connection_status OnionServer::updateData(
		Onion::Request &req, Onion::Response &res) {
	/* Default reply is 'reload' which force reload
	 * of complete website. In mosty cases this string will replaced
	 * by one of the signal handlers.
	 */
	int actionid = atoi( onion_request_get_queryd(req.c_handler(), "actionid","0") );

	if( ! updateSignal( &req, actionid, &res) ){
		// Signal returns true if at least one handler writes into res.
		// Write default reply, if nothing was written.
		std::string reply("reload");
		res.write(reply.c_str(), reply.size() );
	}

	return OCS_PROCESSED;
}
예제 #6
0
/*
 * Parse data from client. Use actionid-arg to distinct different
 * cases.
 */
onion_connection_status OnionServer::updateData(
		Onion::Request &req, Onion::Response &res) {
	/* Default reply is 'reload' which force reload
	 * of complete website. In mosty cases this string will replaced
	 * by one of the signal handlers.
	 */
	int actionid = atoi( onion_request_get_queryd(req.c_handler(), "actionid","0") );

	const int updateResult = updateSignal( &req, actionid, &res);
	if( -3 == updateResult ){
		// Nothing was written. Write default reply (empty string).
		res.write("", 0);
	}
	else if( -2 == updateResult ){
		// Nothing was written and reload should be forced.
		std::string reply("reload");
		res.write(reply.c_str(), reply.size() );
	}

	return OCS_PROCESSED;
}
예제 #7
0
파일: shortcuts.cpp 프로젝트: hchtym/onion
onion_connection_status Onion::redirect(const std::string& url, ::Onion::Request& req, ::Onion::Response& res)
{
    return onion_shortcut_redirect(url.c_str(), req.c_handler(), res.c_handler());
}
예제 #8
0
onion_connection_status extended_html_template(Onion::Request &req, Onion::Response &res){
	extended_html_template(NULL,req.c_handler(), res.c_handler());
}
예제 #9
0
onion_connection_status extended_html_template(Onion::Dict &d, Onion::Request &req, Onion::Response &res){
	extended_html_template(onion_dict_dup(d.c_handler()),req.c_handler(), res.c_handler());
}