📄 http__server_8c-source.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>/opentcp/http/http_server.c Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.2.18 --><center><a class="qindex" href="main.html">Main Page</a> <a class="qindex" href="modules.html">Modules</a> <a class="qindex" href="annotated.html">Data Structures</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Data Fields</a> <a class="qindex" href="globals.html">Globals</a> <a class="qindex" href="pages.html">Related Pages</a> <a class="qindex" href="examples.html">Examples</a> </center><hr><h1>/opentcp/http/http_server.c</h1><a href="http__server_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">/*</span>00002 <span class="comment"> *Copyright (c) 2000-2002 Viola Systems Ltd.</span>00003 <span class="comment"> *All rights reserved.</span>00004 <span class="comment"> *</span>00005 <span class="comment"> *Redistribution and use in source and binary forms, with or without </span>00006 <span class="comment"> *modification, are permitted provided that the following conditions </span>00007 <span class="comment"> *are met:</span>00008 <span class="comment"> *</span>00009 <span class="comment"> *1. Redistributions of source code must retain the above copyright </span>00010 <span class="comment"> *notice, this list of conditions and the following disclaimer.</span>00011 <span class="comment"> *</span>00012 <span class="comment"> *2. Redistributions in binary form must reproduce the above copyright </span>00013 <span class="comment"> *notice, this list of conditions and the following disclaimer in the </span>00014 <span class="comment"> *documentation and/or other materials provided with the distribution.</span>00015 <span class="comment"> *</span>00016 <span class="comment"> *3. The end-user documentation included with the redistribution, if </span>00017 <span class="comment"> *any, must include the following acknowledgment:</span>00018 <span class="comment"> * "This product includes software developed by Viola </span>00019 <span class="comment"> * Systems (http://www.violasystems.com/)."</span>00020 <span class="comment"> *</span>00021 <span class="comment"> *Alternately, this acknowledgment may appear in the software itself, </span>00022 <span class="comment"> *if and wherever such third-party acknowledgments normally appear.</span>00023 <span class="comment"> *</span>00024 <span class="comment"> *4. The names "OpenTCP" and "Viola Systems" must not be used to </span>00025 <span class="comment"> *endorse or promote products derived from this software without prior </span>00026 <span class="comment"> *written permission. For written permission, please contact </span>00027 <span class="comment"> *opentcp@opentcp.org.</span>00028 <span class="comment"> *</span>00029 <span class="comment"> *5. Products derived from this software may not be called "OpenTCP", </span>00030 <span class="comment"> *nor may "OpenTCP" appear in their name, without prior written </span>00031 <span class="comment"> *permission of the Viola Systems Ltd.</span>00032 <span class="comment"> *</span>00033 <span class="comment"> *THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED </span>00034 <span class="comment"> *WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF </span>00035 <span class="comment"> *MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. </span>00036 <span class="comment"> *IN NO EVENT SHALL VIOLA SYSTEMS LTD. OR ITS CONTRIBUTORS BE LIABLE </span>00037 <span class="comment"> *FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR </span>00038 <span class="comment"> *CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF </span>00039 <span class="comment"> *SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR </span>00040 <span class="comment"> *BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, </span>00041 <span class="comment"> *WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE </span>00042 <span class="comment"> *OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, </span>00043 <span class="comment"> *EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>00044 <span class="comment"> *====================================================================</span>00045 <span class="comment"> *</span>00046 <span class="comment"> *OpenTCP is the unified open source TCP/IP stack available on a series </span>00047 <span class="comment"> *of 8/16-bit microcontrollers, please see <http://www.opentcp.org>.</span>00048 <span class="comment"> *</span>00049 <span class="comment"> *For more information on how to network-enable your devices, or how to </span>00050 <span class="comment"> *obtain commercial technical support for OpenTCP, please see </span>00051 <span class="comment"> *<http://www.violasystems.com/>.</span>00052 <span class="comment"> */</span>00053 00067 <span class="preprocessor">#include<<a class="code" href="datatypes_8h.html">inet/datatypes.h</a>></span>00068 <span class="preprocessor">#include<<a class="code" href="globalvariables_8h.html">inet/globalvariables.h</a>></span>00069 <span class="preprocessor">#include<<a class="code" href="debug_8h.html">inet/debug.h</a>></span>00070 <span class="preprocessor">#include<<a class="code" href="system_8h.html">inet/system.h</a>></span>00071 <span class="preprocessor">#include<<a class="code" href="tcp__ip_8h.html">inet/tcp_ip.h</a>></span>00072 <span class="preprocessor">#include<<a class="code" href="http__server_8h.html">inet/http/http_server.h</a>></span>00073 00074 <a name="l00075"></a><a class="code" href="http__server_8c.html#a0">00075</a> UINT8 <a class="code" href="http__server_8c.html#a0">https_enabled</a> = 0; <a name="l00083"></a><a class="code" href="http__server_8c.html#a1">00083</a> <span class="keyword">struct </span><a class="code" href="structhttp__server__state.html">http_server_state</a> https[NO_OF_HTTP_SESSIONS];00084 <a name="l00093"></a><a class="code" href="http__server_8c.html#a2">00093</a> INT8 <a class="code" href="http__server_8c.html#a2">https_init</a>(<span class="keywordtype">void</span>)00094 {00095 UINT8 i;00096 INT8 soch;00097 00098 00099 <span class="keywordflow">for</span>( i=0; i<NO_OF_HTTP_SESSIONS; i++)00100 {00101 https[i].<a class="code" href="structhttp__server__state.html#m0">state</a> = <a class="code" href="http__server_8h.html#a2">HTTPS_STATE_FREE</a>;00102 https[i].<a class="code" href="structhttp__server__state.html#m1">ownersocket</a> = 0;00103 https[i].<a class="code" href="structhttp__server__state.html#m2">fstart</a> = 0;00104 https[i].<a class="code" href="structhttp__server__state.html#m4">fpoint</a> = 0;00105 https[i].<a class="code" href="structhttp__server__state.html#m3">flen</a> = 0;00106 https[i].<a class="code" href="structhttp__server__state.html#m5">funacked</a> = 0;00107 00108 soch = <a class="code" href="tcp_8c.html#a3">tcp_getsocket</a>(<a class="code" href="tcp__ip_8h.html#a39">TCP_TYPE_SERVER</a>, <a class="code" href="tcp__ip_8h.html#a18">TCP_TOS_NORMAL</a>, <a class="code" href="group__opentcp__config.html#a14">TCP_DEF_TOUT</a>, https_eventlistener);00109 00110 <span class="keywordflow">if</span>(soch < 0)00111 {00112 DEBUGOUT(<span class="stringliteral">"HTTP Server uncapable of getting socket\r\n"</span>);00113 <a class="code" href="system_8h.html#a6">RESET_SYSTEM</a>();00114 <span class="comment">/*return(-1);*/</span>00115 }00116 00117 https[i].<a class="code" href="structhttp__server__state.html#m1">ownersocket</a> = soch;00118 00119 kick_WD();00120 00121 soch = <a class="code" href="tcp_8c.html#a5">tcp_listen</a>(https[i].ownersocket, <a class="code" href="http__server_8h.html#a1">HTTPS_SERVERPORT</a>);00122 00123 <span class="keywordflow">if</span>(soch < 0)00124 {00125 DEBUGOUT(<span class="stringliteral">"HTTP Server uncapable of setting socket to listening mode\r\n"</span>);00126 <a class="code" href="system_8h.html#a6">RESET_SYSTEM</a>();00127 <span class="comment">/*return(-1);*/</span>00128 } 00129 00130 00131 } 00132 00133 <a class="code" href="http__server_8c.html#a0">https_enabled</a> = 1;00134 00135 <span class="keywordflow">return</span>(i); 00136 00137 }00138 00139 00140 <span class="comment">/********************************************************************************</span>00141 <span class="comment">Function: https_run</span>00142 <span class="comment"></span>00143 <span class="comment">Parameters: void </span>00144 <span class="comment"> </span>00145 <span class="comment">Return val: void</span>00146 <span class="comment"> </span>00147 <span class="comment">Date: 13.10.2002</span>00148 <span class="comment"></span>00149 <span class="comment">Desc: This function is main 'thread' of HTTP server program</span>00150 <span class="comment"> and should be called periodically from main loop.</span>00151 <span class="comment">*********************************************************************************/</span>00152 00153 <span class="keywordtype">void</span> https_run (<span class="keywordtype">void</span>)00154 {00155 UINT8 i;00156 INT16 len;00157 <span class="keyword">static</span> UINT8 ses = 0;00158 00159 <span class="keywordflow">if</span>( <a class="code" href="http__server_8c.html#a0">https_enabled</a> == 0)00160 <span class="keywordflow">return</span>;00161 00162 <span class="comment">/* Walk thru all sessions untill we found something to send or so */</span>00163 00164 <span class="keywordflow">for</span>(i=0; i<NO_OF_HTTP_SESSIONS; i++)00165 {00166 kick_WD();00167 00168 <span class="keywordflow">if</span>(ses >= NO_OF_HTTP_SESSIONS)00169 ses = 0;00170 00171 <span class="comment">/* Keep sockets listening */</span>00172 00173 <span class="keywordflow">if</span>(<a class="code" href="tcp_8c.html#a9">tcp_getstate</a>(https[ses].ownersocket) < <a class="code" href="tcp__ip_8h.html#a45">TCP_STATE_LISTENING</a>)00174 {00175 <a class="code" href="tcp_8c.html#a5">tcp_listen</a>(https[ses].ownersocket, <a class="code" href="http__server_8h.html#a1">HTTPS_SERVERPORT</a>);00176 ses++;00177 <span class="keywordflow">continue</span>; 00178 }00179 00180 <span class="keywordflow">if</span>(https[ses].<a class="code" href="structhttp__server__state.html#m0">state</a> != <a class="code" href="http__server_8h.html#a4">HTTPS_STATE_ACTIVE</a>)00181 {00182 ses++;00183 <span class="keywordflow">continue</span>;00184 }00185 00186 <span class="keywordflow">if</span>(https[ses].<a class="code" href="structhttp__server__state.html#m5">funacked</a> != 0)00187 {00188 ses++;00189 <span class="keywordflow">continue</span>; 00190 }00191 00192 <span class="keywordflow">if</span>(https[ses].<a class="code" href="structhttp__server__state.html#m2">fstart</a> == 0)00193 {00194 ses++;00195 <span class="keywordflow">continue</span>; 00196 } 00197 00198 <span class="comment">/* End of data? */</span>00199 00200 <span class="keywordflow">if</span>( https[ses].<a class="code" href="structhttp__server__state.html#m4">fpoint</a> >= https[ses].<a class="code" href="structhttp__server__state.html#m3">flen</a>)00201 {00202 <a class="code" href="tcp_8c.html#a8">tcp_close</a>(https[ses].ownersocket);00203 <a class="code" href="tcp_8c.html#a11">tcp_abort</a>(https[ses].ownersocket);00204 https_deletesession(ses);00205 00206 ses++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -