当前位置: 首页>>代码示例>>C++>>正文


C++ HTTPServer::FindAction方法代码示例

本文整理汇总了C++中HTTPServer::FindAction方法的典型用法代码示例。如果您正苦于以下问题:C++ HTTPServer::FindAction方法的具体用法?C++ HTTPServer::FindAction怎么用?C++ HTTPServer::FindAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HTTPServer的用法示例。

在下文中一共展示了HTTPServer::FindAction方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: ConfigException


//.........这里部分代码省略.........
					Sinkhole::ConfigurationBlock &ab = b.GetBlock("action", k);

					try
					{
						std::string aname = ab.GetValue("name");
						std::string sname = ab.GetValue("server-name");

						std::vector<HTTPVhost> vhosts;
						for (int m = 0, n = ab.CountBlock("vhost"); m < n; ++m)
						{
							Sinkhole::ConfigurationBlock &vb = ab.GetBlock("vhost", m);

							std::string vname = vb.GetValue("name");
							HTTPVhost::Type t = HTTPVhost::TYPE_SERVE;
							std::string data;
							try { data = vb.GetValue("serve"); }
							catch (const Sinkhole::ConfigException &)
							{
								t = HTTPVhost::TYPE_ROOT;
								try { data = vb.GetValue("root"); }
								catch (const Sinkhole::ConfigException &)
								{
									throw Sinkhole::ConfigException("You must define either serve or root");
								}
							}

							HTTPVhost vhost;
							vhost.name = vname;
							vhost.data = data;
							vhost.type = t;
							vhosts.push_back(vhost);
						}

						HTTPVhost::Type t = HTTPVhost::TYPE_SERVE;
						std::string data;
						try { data = ab.GetValue("serve"); }
						catch (const Sinkhole::ConfigException &)
						{
							t = HTTPVhost::TYPE_ROOT;
							try { data = ab.GetValue("root"); }
							catch (const Sinkhole::ConfigException &)
							{
								throw Sinkhole::ConfigException("You must define either serve or root");
							}
						}

						HTTPAction *a = new HTTPAction();
						a->vhosts = vhosts;
						a->name = aname;
						a->server_name = sname;
						a->data = data;
						a->type = t;
						s->actions.insert(std::make_pair(a->name, a));
					}
					catch (const Sinkhole::ConfigException &ex)
					{
						Sinkhole::Log(Sinkhole::LOG_ERROR) << "Error loading http:action for " << name << ": " << ex.GetReason();
					}
				}

				for (int k = 0, l = b.CountBlock("class"); k < l; ++k)
				{
					Sinkhole::ConfigurationBlock &cb = b.GetBlock("class", k);

					try
					{
						std::vector<Sinkhole::cidr> sources;
						for (int m = 0, n = cb.CountBlock("source"); m < n; ++m)
						{
							Sinkhole::ConfigurationBlock &cbs = cb.GetBlock("source", m);
							Sinkhole::cidr range(cbs.GetValue("addr"));
							sources.push_back(range);
						}

						std::string action = cb.GetValue("action");

						HTTPAction *a = s->FindAction(action);
						if (a == NULL)
							throw Sinkhole::ConfigException("Unknown action \"" + action + "\"");

						HTTPClass *c = new HTTPClass(a);
						c->sources = sources;
						s->classes.push_back(c);
					}
					catch (const Sinkhole::SocketException &ex)
					{
						Sinkhole::Log(Sinkhole::LOG_ERROR) << "Error loading http:class:source for " << name << ": " << ex.GetReason();
					}
					catch (const Sinkhole::ConfigException &ex)
					{
						Sinkhole::Log(Sinkhole::LOG_ERROR) << "Error loading http:class:source for " << name << ": " << ex.GetReason();
					}
				}
			}
			catch (const Sinkhole::ConfigException &ex)
			{
				Sinkhole::Log(Sinkhole::LOG_ERROR) << "Error loading http block " << i << ": " << ex.GetReason();
			}
		}
	}
开发者ID:insomp,项目名称:sinkhole,代码行数:101,代码来源:http.cpp



注:本文中的HTTPServer::FindAction方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。