示例#1
0
	virtual int onRead(ServerContext& ctxt, FileServer& server, const char *path, string& contents)
	{
		stringstream cmd;
		string_list_t list;
		const char *script = get_string(server.options(), "InfoScript", NULL);
		if (script == NULL)
		{
			return -EFAULT;
		}

		explode(path, "/", list);
		if (list.front().empty())
		{
			list.pop_front();
		}
		if (list.back() == ":info")
		{
			list.pop_back();
		}
		if (list.size() == 0)
		{
			return -EINVAL;
		}
		
		cmd << script;
		while (list.size() > 0)
		{
			cmd << " " << list.front();
			list.pop_front();
		}
		
		const char *prog = cmd.str().c_str();
		bool res = ::run_read_script(prog, contents);
		if (!res)
		{
			contents.clear();
			return -EIO;
		}

		return contents.length();
	}