コード例 #1
0
ファイル: utils.hpp プロジェクト: Eurospider/strusWebService
static bool is_of_type( cppcms::json::value const &v, T x )
{
	try {
		if( v.type( ) == cppcms::json::is_number ) {
			// we loose precision as ArithmenticType is float, but so what
			return true;
		} else if( v.type( ) == cppcms::json::is_string ) {
			T t = boost::lexical_cast<T>( v.str( ) );
			(void)t;
			return true;
		} else {
			return false;
		}
	} catch( boost::bad_lexical_cast &e ) {
		return false;
	}
}
コード例 #2
0
ファイル: data_file.cpp プロジェクト: opncms/opncms
bool DataFile::get(cppcms::json::value& v, const std::string& storage, const std::string& key)
{
	std::stringstream ss;
	
	BOOSTER_LOG(debug,__FUNCTION__) << "storage(" << storage << "), key(" << key << ")";

	if (storage.empty() || key.empty()) {
		BOOSTER_LOG(error,__FUNCTION__) << "storage/key are empty";
		return false;
	}

	if (!tools::data::load(storage, v)) {
		BOOSTER_LOG(error,__FUNCTION__) << "Can`t load storage";
		return false;
	}
	v = v.find(key);
	if (v.is_undefined())
		return false;
	return true;
}
コード例 #3
0
	void setup(cppcms::json::value const &v)
	{		
		ip=v.get("ip","0.0.0.0");
		port=v.get<int>("port");
		threads=v.get("threads",booster::thread::hardware_concurrency());
		int items = v.get("cache.limit",-1);
		if(items!=-1){
			cache = cppcms::impl::thread_cache_factory(items);
		}
		gc=v.get("session.gc",10);
		std::string stor = v.get("session.storage","");
		if(!stor.empty()) {
			if(stor == "files") {
				std::string dir = v.get("session.dir","");
				#ifdef CPPCMS_WIN_NATIVE
				sessions.reset(new cppcms::sessions::session_file_storage_factory(dir));
				#else
				sessions.reset(new cppcms::sessions::session_file_storage_factory(dir,threads,1,false));
				#endif
			}
			else if(stor == "memory") {
				sessions.reset(new cppcms::sessions::session_memory_storage_factory());
			}
			else if(stor == "external") {
				std::string so = v.get<std::string>("session.shared_object","");
				std::string module = v.get<std::string>("session.module","");
				std::string entry_point = v.get<std::string>("session.entry_point","sessions_generator");
				if(so.empty() && module.empty())
					throw cppcms::cppcms_error(
								"session.storage=external "
								"and neither session.shared_object "
								"nor session.module is defined");
				if(!so.empty() && !module.empty())
					throw cppcms::cppcms_error(
								"both session.shared_object "
								"and session.module are defined");

				if(so.empty()) {
					so = booster::shared_object::name(module);
				}
				std::string error;
				if(!plugin.open(so,error)) {
					throw cppcms::cppcms_error("sessions_pool: failed to load shared object " + so + ": " + error);
				}
				cppcms::sessions::cppcms_session_storage_generator_type f=0;
				plugin.symbol(f,entry_point);
				sessions.reset(f(v.find("session.settings")));
			}
			else 
				throw cppcms::cppcms_error("Unknown session.storage:"+stor);
		}
		if(!sessions && !cache) {
			throw cppcms::cppcms_error("Neither cache.limit nor session.storage is defined");
		}
	}
コード例 #4
0
ファイル: utils.hpp プロジェクト: Eurospider/strusWebService
static bool is_of_type( cppcms::json::value const &v, T x )
{
	try {
		if( v.type( ) == cppcms::json::is_number ) {
			double n;
			double d = std::modf( v.number( ), &n );
			if( std::abs( d ) < std::numeric_limits<float>::epsilon( ) ) {
				// the fractional part is smaller than the machine epsilon
				// of float (right?), so it is an integer
				return true;
			}
			return false;
		} else if( v.type( ) == cppcms::json::is_string ) {
			T t = boost::lexical_cast<T>( v.str( ) );
			(void)t;
			return true;
		} else {
			return false;
		}
	} catch( boost::bad_lexical_cast &e ) {
		return false;
	}
}
コード例 #5
0
ファイル: data_file.cpp プロジェクト: opncms/opncms
bool DataFile::get(cppcms::json::value& v, const std::string& storage)
{
	BOOSTER_LOG(debug,__FUNCTION__) << "storage(" << storage << ")";

	if (storage.empty()) {
		BOOSTER_LOG(error,__FUNCTION__) << "storage is empty";
		return false;
	}
	if (!tools::data::load(storage, v)) {
		BOOSTER_LOG(error,__FUNCTION__) << "Can`t load storage";
		return false;
	}
	if (v.is_undefined())
		return false;
	
	return true;
}
コード例 #6
0
ファイル: rpc.cpp プロジェクト: floft/freetron
void rpc::getForms(cppcms::json::value& v, long long formId)
{
    long long userId = session().get<long long>("id");

    // If formId == 0, then it'll get all the forms
    std::vector<FormData> forms = db.getForms(userId, formId);

    // Optimization
    cppcms::json::array& ar = v.array();
    ar.reserve(forms.size());

    for (const FormData& f : forms)
    {
        cppcms::json::object obj;
        obj["id"] = f.id;
        obj["key"] = f.key;
        obj["name"] = f.name;
        obj["data"] = (f.data.empty())?"Processing... please wait":f.data;
        obj["date"] = f.date;
        ar.push_back(obj);
    }
}