⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 _h_t_t_p_module_8hpp-source.html

📁 用c++编写http server的源码库,对socket等网络处理的代码可迅速转为己用.
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"><title>libpion: /Users/mdickey/code/libpion-export/include/libpion/HTTPModule.hpp Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"><link href="tabs.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.5.2 --><div class="tabs">  <ul>    <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>    <li><a href="namespaces.html"><span>Namespaces</span></a></li>    <li><a href="annotated.html"><span>Classes</span></a></li>    <li class="current"><a href="files.html"><span>Files</span></a></li>  </ul></div><h1>/Users/mdickey/code/libpion-export/include/libpion/HTTPModule.hpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// -----------------------------------------------------------------</span><a name="l00002"></a>00002 <span class="comment">// libpion: a C++ framework for building lightweight HTTP interfaces</span><a name="l00003"></a>00003 <span class="comment">// -----------------------------------------------------------------</span><a name="l00004"></a>00004 <span class="comment">// Copyright (C) 2007 Atomic Labs, Inc.  (http://www.atomiclabs.com)</span><a name="l00005"></a>00005 <span class="comment">//</span><a name="l00006"></a>00006 <span class="comment">// Distributed under the Boost Software License, Version 1.0.</span><a name="l00007"></a>00007 <span class="comment">// See accompanying file COPYING or copy at http://www.boost.org/LICENSE_1_0.txt</span><a name="l00008"></a>00008 <span class="comment">//</span><a name="l00009"></a>00009 <a name="l00010"></a>00010 <span class="preprocessor">#ifndef __PION_HTTPMODULE_HEADER__</span><a name="l00011"></a>00011 <span class="preprocessor"></span><span class="preprocessor">#define __PION_HTTPMODULE_HEADER__</span><a name="l00012"></a>00012 <span class="preprocessor"></span><a name="l00013"></a>00013 <span class="preprocessor">#include &lt;libpion/PionConfig.hpp&gt;</span><a name="l00014"></a>00014 <span class="preprocessor">#include &lt;libpion/PionException.hpp&gt;</span><a name="l00015"></a>00015 <span class="preprocessor">#include &lt;libpion/HTTPRequest.hpp&gt;</span><a name="l00016"></a>00016 <span class="preprocessor">#include &lt;libpion/TCPConnection.hpp&gt;</span><a name="l00017"></a>00017 <span class="preprocessor">#include &lt;boost/noncopyable.hpp&gt;</span><a name="l00018"></a>00018 <span class="preprocessor">#include &lt;string&gt;</span><a name="l00019"></a>00019 <a name="l00020"></a>00020 <a name="l00021"></a><a class="code" href="namespacepion.html">00021</a> <span class="keyword">namespace </span>pion {    <span class="comment">// begin namespace pion</span><a name="l00022"></a>00022 <a name="l00026"></a><a class="code" href="classpion_1_1_h_t_t_p_module.html">00026</a> <span class="keyword">class </span><a class="code" href="classpion_1_1_h_t_t_p_module.html">HTTPModule</a> :<a name="l00027"></a>00027     <span class="keyword">private</span> boost::noncopyable<a name="l00028"></a>00028 {<a name="l00029"></a>00029 <span class="keyword">public</span>:<a name="l00030"></a>00030 <a name="l00032"></a><a class="code" href="classpion_1_1_h_t_t_p_module_1_1_unknown_option_exception.html">00032</a>     <span class="keyword">class </span><a class="code" href="classpion_1_1_h_t_t_p_module_1_1_unknown_option_exception.html" title="exception thrown if the module does not recognize a configuration option">UnknownOptionException</a> : <span class="keyword">public</span> <a class="code" href="classpion_1_1_pion_exception.html">PionException</a> {<a name="l00033"></a>00033     <span class="keyword">public</span>:<a name="l00034"></a><a class="code" href="classpion_1_1_h_t_t_p_module_1_1_unknown_option_exception.html#adc0a6a0cbab8786de8f3a5b5d87b567">00034</a>         <a class="code" href="classpion_1_1_h_t_t_p_module_1_1_unknown_option_exception.html#adc0a6a0cbab8786de8f3a5b5d87b567">UnknownOptionException</a>(<span class="keyword">const</span> std::string&amp; name)<a name="l00035"></a>00035             : <a class="code" href="classpion_1_1_pion_exception.html">PionException</a>(<span class="stringliteral">"Option not recognized by HTTP module: "</span>, name) {}<a name="l00036"></a>00036     };<a name="l00037"></a>00037 <a name="l00039"></a><a class="code" href="classpion_1_1_h_t_t_p_module.html#358332a4ee0995e43c031df6101da8c2">00039</a>     <a class="code" href="classpion_1_1_h_t_t_p_module.html#358332a4ee0995e43c031df6101da8c2" title="default constructor">HTTPModule</a>(<span class="keywordtype">void</span>) {}<a name="l00040"></a>00040 <a name="l00042"></a><a class="code" href="classpion_1_1_h_t_t_p_module.html#22363dc9498c8c01a9f5693289b248f5">00042</a>     <span class="keyword">virtual</span> <a class="code" href="classpion_1_1_h_t_t_p_module.html#22363dc9498c8c01a9f5693289b248f5" title="virtual destructor">~HTTPModule</a>() {}<a name="l00043"></a>00043 <a name="l00052"></a>00052     <span class="keyword">virtual</span> <span class="keywordtype">bool</span> <a class="code" href="classpion_1_1_h_t_t_p_module.html#316354d4546e5f1ca1bc4531bb1b2fd9">handleRequest</a>(<a class="code" href="namespacepion.html#3c0f3fad0f449ebd309eaf4872f2b222" title="data type for a HTTP request pointer">HTTPRequestPtr</a>&amp; request, <a class="code" href="namespacepion.html#1858b89656b28c6498ad9efd6b7e9d41" title="data type for a TCPConnection pointer">TCPConnectionPtr</a>&amp; tcp_conn) = 0;<a name="l00053"></a>00053     <a name="l00060"></a><a class="code" href="classpion_1_1_h_t_t_p_module.html#438852ea07e92aef908c633c2de9b8bc">00060</a>     <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classpion_1_1_h_t_t_p_module.html#438852ea07e92aef908c633c2de9b8bc">setOption</a>(<span class="keyword">const</span> std::string&amp; name, <span class="keyword">const</span> std::string&amp; value) {<a name="l00061"></a>00061         <span class="keywordflow">throw</span> <a class="code" href="classpion_1_1_h_t_t_p_module_1_1_unknown_option_exception.html" title="exception thrown if the module does not recognize a configuration option">UnknownOptionException</a>(name);<a name="l00062"></a>00062     }<a name="l00063"></a>00063     <a name="l00065"></a><a class="code" href="classpion_1_1_h_t_t_p_module.html#4f5878a0690f7b84b53ea58365d743ad">00065</a>     <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classpion_1_1_h_t_t_p_module.html#4f5878a0690f7b84b53ea58365d743ad" title="called when the module's server is starting">start</a>(<span class="keywordtype">void</span>) {}<a name="l00066"></a>00066     <a name="l00068"></a><a class="code" href="classpion_1_1_h_t_t_p_module.html#def44217f53d5684bf5f1c142ec7a337">00068</a>     <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classpion_1_1_h_t_t_p_module.html#def44217f53d5684bf5f1c142ec7a337" title="called when the module's server is stopping">stop</a>(<span class="keywordtype">void</span>) {}<a name="l00069"></a>00069     <a name="l00071"></a><a class="code" href="classpion_1_1_h_t_t_p_module.html#108d617af983e75e52d7563d53571e7d">00071</a>     <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classpion_1_1_h_t_t_p_module.html#108d617af983e75e52d7563d53571e7d" title="sets the URI stem or resource that is bound to the module (strips any trailing slash)...">setResource</a>(<span class="keyword">const</span> std::string&amp; str) { m_resource = stripTrailingSlash(str); }<a name="l00072"></a>00072 <a name="l00074"></a><a class="code" href="classpion_1_1_h_t_t_p_module.html#aad5404f6bb1cdda1d75da7df1ca8022">00074</a>     <span class="keyword">inline</span> <span class="keyword">const</span> std::string&amp; <a class="code" href="classpion_1_1_h_t_t_p_module.html#aad5404f6bb1cdda1d75da7df1ca8022" title="returns the URI stem or resource that is bound to the module">getResource</a>(<span class="keywordtype">void</span>)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> m_resource; }<a name="l00075"></a>00075     <a name="l00077"></a><a class="code" href="classpion_1_1_h_t_t_p_module.html#d6371c2480fef34429845567067c072e">00077</a>     <span class="keyword">inline</span> std::string <a class="code" href="classpion_1_1_h_t_t_p_module.html#d6371c2480fef34429845567067c072e" title="returns the path to the resource requested, relative to the module's location">getRelativeResource</a>(<span class="keyword">const</span> std::string&amp; resource_requested)<span class="keyword"> const </span>{<a name="l00078"></a>00078         <span class="keywordflow">if</span> (resource_requested.size() &lt;= <a class="code" href="classpion_1_1_h_t_t_p_module.html#aad5404f6bb1cdda1d75da7df1ca8022" title="returns the URI stem or resource that is bound to the module">getResource</a>().size()) {<a name="l00079"></a>00079             <span class="comment">// either the request matches the module's resource path (a directory)</span><a name="l00080"></a>00080             <span class="comment">// or the request does not match (should never happen)</span><a name="l00081"></a>00081             <span class="keywordflow">return</span> std::string();<a name="l00082"></a>00082         }<a name="l00083"></a>00083         <span class="comment">// strip the module's resource path plus the slash after it</span><a name="l00084"></a>00084         <span class="keywordflow">return</span> <a class="code" href="structpion_1_1_h_t_t_p_types.html#adee1392ed4b47bf03224d985cab146c" title="escapes URL-encoded strings (a20value+with20spaces)">HTTPTypes::url_decode</a>(resource_requested.substr(<a class="code" href="classpion_1_1_h_t_t_p_module.html#aad5404f6bb1cdda1d75da7df1ca8022" title="returns the URI stem or resource that is bound to the module">getResource</a>().size() + 1));<a name="l00085"></a>00085     }<a name="l00086"></a>00086     <a name="l00087"></a>00087     <a name="l00088"></a>00088 <span class="keyword">private</span>:<a name="l00089"></a>00089         <a name="l00091"></a>00091     <span class="keyword">static</span> <span class="keyword">inline</span> std::string stripTrailingSlash(<span class="keyword">const</span> std::string&amp; str) {<a name="l00092"></a>00092         std::string result(str);<a name="l00093"></a>00093         <span class="keywordflow">if</span> (!result.empty() &amp;&amp; result[result.size()-1]==<span class="charliteral">'/'</span>)<a name="l00094"></a>00094             result.resize(result.size() - 1);<a name="l00095"></a>00095         <span class="keywordflow">return</span> result;<a name="l00096"></a>00096     }<a name="l00097"></a>00097         <a name="l00099"></a>00099     std::string m_resource;<a name="l00100"></a>00100 };<a name="l00101"></a>00101 <a name="l00102"></a>00102 <a name="l00103"></a>00103 <span class="comment">//</span><a name="l00104"></a>00104 <span class="comment">// The following symbols must be defined for any HTTP modules that you would</span><a name="l00105"></a>00105 <span class="comment">// like to be able to load dynamically using the HTTPServer::loadModule()</span><a name="l00106"></a>00106 <span class="comment">// function.  These are not required for any modules that you only want to link</span><a name="l00107"></a>00107 <span class="comment">// directly into your programs.</span><a name="l00108"></a>00108 <span class="comment">//</span><a name="l00109"></a>00109 <span class="comment">// Make sure that you replace "HTTPModule" with the name of your derived class.</span><a name="l00110"></a>00110 <span class="comment">// This name must also match the name of the object file (excluding the</span><a name="l00111"></a>00111 <span class="comment">// extension).  These symbols must be linked into your module's object file,</span><a name="l00112"></a>00112 <span class="comment">// not included in any headers that it may use (declarations are OK in headers</span><a name="l00113"></a>00113 <span class="comment">// but not the definitions).</span><a name="l00114"></a>00114 <span class="comment">//</span><a name="l00115"></a>00115 <span class="comment">// The "pion_create" function is used to create new instances of your module.</span><a name="l00116"></a>00116 <span class="comment">// The "pion_destroy" function is used to destroy instances of your module.</span><a name="l00117"></a>00117 <span class="comment">//</span><a name="l00118"></a>00118 <span class="comment">// extern "C" HTTPModule *pion_create_HTTPModule(void) {</span><a name="l00119"></a>00119 <span class="comment">//      return new HTTPModule;</span><a name="l00120"></a>00120 <span class="comment">// }</span><a name="l00121"></a>00121 <span class="comment">//</span><a name="l00122"></a>00122 <span class="comment">// extern "C" void pion_destroy_HTTPModule(HTTPModule *module_ptr) {</span><a name="l00123"></a>00123 <span class="comment">//      delete module_ptr;</span><a name="l00124"></a>00124 <span class="comment">// }</span><a name="l00125"></a>00125 <span class="comment">//</span><a name="l00126"></a>00126 <a name="l00127"></a>00127 }   <span class="comment">// end namespace pion</span><a name="l00128"></a>00128 <a name="l00129"></a>00129 <span class="preprocessor">#endif</span></pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Tue Jun 19 13:29:22 2007 for libpion by&nbsp;<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.2 </small></address></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -