示例#1
0
文件: browser.cpp 项目: hiwang123/x0
    void isAncient(x0::HttpRequest *r, const x0::FlowParams& args, x0::FlowValue& result)
    {
        x0::BufferRef userAgent(r->requestHeader("User-Agent"));

        for (auto& ancient: ancients_) {
            if (userAgent.find(ancient.c_str()) != x0::BufferRef::npos) {
                result.set(true);
                return;
            }
        }
        result.set(false);
    }
示例#2
0
文件: compress.cpp 项目: hiwang123/x0
	void populateContentTypes(const x0::FlowValue& from)
	{
		switch (from.type()) {
			case x0::FlowValue::STRING:
				contentTypes_.push_back(from.toString());
				break;
			case x0::FlowValue::ARRAY:
				for (auto p: from.toArray())
					populateContentTypes(p);
				break;
			default:
				;
		}
	}
示例#3
0
文件: ssl.cpp 项目: liveck/x0
	// ssl.listener(BINDADDR_PORT);
	void add_listener(const x0::FlowParams& args, x0::FlowValue& result)
	{
		x0::SocketSpec socketSpec;
		socketSpec << args;

		if (!socketSpec.isValid()) {
			result.set(false);
		} else {
			x0::ServerSocket* listener = server().setupListener(socketSpec);
			if (listener) {
				SslDriver *driver = new SslDriver(this);
				listener->setSocketDriver(driver);
			}

			result.set(listener != nullptr);
		}
	}
示例#4
0
文件: vhost.cpp 项目: illdefined/x0
	void registerHost(const x0::FlowValue& arg)
	{
		if (arg.type() == x0::FlowValue::ARRAY) {
			const x0::FlowArray& args = arg.toArray();
			if (args.size() != 2)
				return;

			const x0::FlowValue& fqdn = args[0];
			const x0::FlowValue& proc = args[1];

			if (!fqdn.isString())
				return;

			if (!proc.isFunction())
				return;

			registerHost(fqdn.toString(), proc.toFunction());
		}
	}
示例#5
0
文件: rrdfile.cpp 项目: hiwang123/x0
	void setup_filename(const x0::FlowParams& args, x0::FlowValue& result)
	{
		if (args.empty()) {
			result.set(filename_.c_str());
			return;
		}

		args[0].load(filename_);

		checkStart();
	}
示例#6
0
文件: rrdfile.cpp 项目: hiwang123/x0
	void setup_step(const x0::FlowParams& args, x0::FlowValue& result)
	{
		if (args.empty()) {
			result.set(step_);
			return;
		}

		args[0].load(step_);

		if (step_)
			evTimer_.set(step_, step_);

		checkStart();
	}
示例#7
0
文件: browser.cpp 项目: hiwang123/x0
    void isModern(x0::HttpRequest *r, const x0::FlowParams& args, x0::FlowValue& result)
    {
        x0::BufferRef userAgent(r->requestHeader("User-Agent"));

        for (auto& modern: modern_) {
            std::size_t i = userAgent.find(modern.first.c_str());
            if (i == x0::BufferRef::npos)
                continue;

            i += modern.first.size();
            if (userAgent[i] != '/') // expecting '/' as delimiter
                continue;

            float version = userAgent.ref(++i).toFloat();

            if (version < modern.second)
                continue;

            result.set(true);
            return;
        }
        result.set(false);
    }