Exemple #1
0
    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);
    }
Exemple #2
0
	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:
				;
		}
	}
Exemple #3
0
	// 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);
		}
	}
Exemple #4
0
	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());
		}
	}
Exemple #5
0
	void setup_filename(const x0::FlowParams& args, x0::FlowValue& result)
	{
		if (args.empty()) {
			result.set(filename_.c_str());
			return;
		}

		args[0].load(filename_);

		checkStart();
	}
Exemple #6
0
	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();
	}
Exemple #7
0
    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);
    }