A task management system. At least this was the initial idea. Basically this it the base code for the taskrambler framework.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

271 lines
23 KiB

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Server: src/http/parser/parse.c Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript">
$(document).ready(initResizable);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body onload='searchBox.OnSelectItem(0);'>
<!-- Generated by Doxygen 1.7.3 -->
<script type="text/javascript"><!--
var searchBox = new SearchBox("searchBox", "search",false,'Search');
--></script>
<div id="top">
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td style="padding-left: 0.5em;">
<div id="projectname">Server&#160;<span id="projectnumber">0.0.1</span></div>
<div id="projectbrief">HTTP/REST server implementation</div>
</td>
</tr>
</tbody>
</table>
</div>
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main&#160;Page</span></a></li>
<li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
<li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
<li class="current"><a href="files.html"><span>Files</span></a></li>
<li id="searchli">
<div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<img id="MSearchSelect" src="search/mag_sel.png"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
alt=""/>
<input type="text" id="MSearchField" value="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
</span>
</div>
</li>
</ul>
</div>
<div id="navrow2" class="tabs2">
<ul class="tablist">
<li><a href="files.html"><span>File&#160;List</span></a></li>
<li><a href="globals.html"><span>Globals</span></a></li>
</ul>
</div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
initNavTree('parse_8c.html','');
</script>
<div id="doc-content">
<div class="header">
<div class="headertitle">
<h1>src/http/parser/parse.c</h1> </div>
</div>
<div class="contents">
<a href="parse_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001
<a name="l00023"></a>00023 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00024"></a>00024
<a name="l00025"></a>00025 <span class="preprocessor">#include &quot;class.h&quot;</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include &quot;cbuf.h&quot;</span>
<a name="l00027"></a>00027 <span class="preprocessor">#include &quot;stream.h&quot;</span>
<a name="l00028"></a>00028
<a name="l00029"></a>00029 <span class="preprocessor">#include &quot;http/parser.h&quot;</span>
<a name="l00030"></a>00030 <span class="preprocessor">#include &quot;http/header.h&quot;</span>
<a name="l00031"></a>00031 <span class="preprocessor">#include &quot;http/interface/http_intro.h&quot;</span>
<a name="l00032"></a>00032
<a name="l00033"></a>00033 <span class="preprocessor">#include &quot;utils/memory.h&quot;</span>
<a name="l00034"></a>00034 <span class="preprocessor">#include &quot;commons.h&quot;</span>
<a name="l00035"></a>00035
<a name="l00036"></a><a class="code" href="parse_8c.html#a3acffbd305ee72dcd4593c0d8af64a4f">00036</a> <span class="preprocessor">#define MIN(a,b) ((a)&lt;(b)? (a) : (b))</span>
<a name="l00037"></a>00037 <span class="preprocessor"></span>
<a name="l00038"></a>00038
<a name="l00039"></a>00039 ssize_t
<a name="l00040"></a><a class="code" href="parse_8c.html#a1aa3a9f8959238057fe18ca5bda180db">00040</a> <a class="code" href="parser_8h.html#a327e735e383c72c2b1da1bfd4734015e">httpParserParse</a>(<span class="keywordtype">void</span> * _this, <a class="code" href="structStream.html">Stream</a> st)
<a name="l00041"></a>00041 {
<a name="l00042"></a>00042 <a class="code" href="structHttpParser.html">HttpParser</a> <span class="keyword">this</span> = _this;
<a name="l00043"></a>00043 <span class="keywordtype">int</span> cont = 1;
<a name="l00044"></a>00044 ssize_t read;
<a name="l00045"></a>00045 <span class="keywordtype">char</span> * line;
<a name="l00046"></a>00046 <span class="keywordtype">char</span> * line_end;
<a name="l00047"></a>00047
<a name="l00048"></a>00048 <span class="keywordflow">if</span> (<a class="code" href="cbuf_8h.html#a87c05ad967d95ea590151e69af0ff4fe">cbufIsLocked</a>(this-&gt;buffer)) {
<a name="l00049"></a>00049 <span class="keywordflow">if</span> (<a class="code" href="commons_8h.html#aa93f0eb578d23995850d61f7d61c55c1">FALSE</a> == this-&gt;ourLock)
<a name="l00050"></a>00050 <span class="keywordflow">return</span> 0;
<a name="l00051"></a>00051 }
<a name="l00052"></a>00052 <span class="keywordflow">else</span> {
<a name="l00053"></a>00053 <a class="code" href="cbuf_8h.html#a9836b66494452a0b01511163285e2ba6">cbufLock</a>(this-&gt;buffer);
<a name="l00054"></a>00054 this-&gt;ourLock = <a class="code" href="commons_8h.html#aa8cecfc5c5c054d2875c03e77b7be15d">TRUE</a>;
<a name="l00055"></a>00055 }
<a name="l00056"></a>00056
<a name="l00057"></a>00057 <span class="keywordflow">if</span> (NULL != this-&gt;incomplete) {
<a name="l00058"></a>00058 <a class="code" href="cbuf_8h.html#aee8e983250f1f7b58d98cc70b765493a">cbufSetData</a>(this-&gt;buffer, this-&gt;incomplete, this-&gt;isize);
<a name="l00059"></a>00059 free(this-&gt;incomplete);
<a name="l00060"></a>00060 this-&gt;incomplete = NULL;
<a name="l00061"></a>00061 }
<a name="l00062"></a>00062
<a name="l00063"></a>00063 <span class="keywordflow">if</span> (0 &gt; (read = <a class="code" href="cbuf_8h.html#a6e4de5096568ca24607ed25184f39621">cbufRead</a>(this-&gt;buffer, st))) {
<a name="l00064"></a>00064 <span class="keywordflow">return</span> read;
<a name="l00065"></a>00065 }
<a name="l00066"></a>00066
<a name="l00067"></a>00067 <span class="keywordflow">while</span> (cont) {
<a name="l00068"></a>00068 <span class="keywordflow">switch</span>(this-&gt;state) {
<a name="l00069"></a>00069 <span class="keywordflow">case</span> <a class="code" href="parser_8h.html#a994a868cfd1ee04fd1e546d6469d602cab5145e30bcb9d79664a352c9a2573d60">HTTP_MESSAGE_GARBAGE</a>:
<a name="l00070"></a>00070 <a class="code" href="cbuf_8h.html#a1983134b7a26ad2ea077adcd343dca24">cbufSkipNonAlpha</a>(this-&gt;buffer);
<a name="l00071"></a>00071 <span class="keywordflow">if</span> (! <a class="code" href="cbuf_8h.html#aa041996b32209a9b81a3e5db178c8339">cbufIsEmpty</a>(this-&gt;buffer)) {
<a name="l00072"></a>00072 this-&gt;state = <a class="code" href="parser_8h.html#a994a868cfd1ee04fd1e546d6469d602ca4c3fc077c05ce00bbf8c9d1a9df652d3">HTTP_MESSAGE_START</a>;
<a name="l00073"></a>00073 }
<a name="l00074"></a>00074 <span class="keywordflow">else</span> {
<a name="l00075"></a>00075 <a class="code" href="cbuf_8h.html#aa6b501bd8016dfe1951f54dffe59262e">cbufRelease</a>(this-&gt;buffer);
<a name="l00076"></a>00076 this-&gt;ourLock = <a class="code" href="commons_8h.html#aa93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00077"></a>00077 cont = 0;
<a name="l00078"></a>00078 }
<a name="l00079"></a>00079
<a name="l00080"></a>00080 <span class="keywordflow">break</span>;
<a name="l00081"></a>00081
<a name="l00082"></a>00082 <span class="keywordflow">case</span> <a class="code" href="parser_8h.html#a994a868cfd1ee04fd1e546d6469d602ca4c3fc077c05ce00bbf8c9d1a9df652d3">HTTP_MESSAGE_START</a>:
<a name="l00083"></a>00083 <span class="keywordflow">if</span> (NULL == (line = <a class="code" href="cbuf_8h.html#a60512cdcca11f127c26a8a30e42b8c5c">cbufGetLine</a>(this-&gt;buffer, &amp;line_end))) {
<a name="l00084"></a>00084 <span class="keywordflow">if</span> (! <a class="code" href="cbuf_8h.html#aa041996b32209a9b81a3e5db178c8339">cbufIsEmpty</a>(this-&gt;buffer)) {
<a name="l00085"></a>00085 this-&gt;isize = this-&gt;buffer-&gt;bused;
<a name="l00086"></a>00086 this-&gt;incomplete = malloc(this-&gt;isize);
<a name="l00087"></a>00087 memcpy(this-&gt;incomplete,
<a name="l00088"></a>00088 <a class="code" href="cbuf_8h.html#abc3bb54c6a324c849b872823ec70ce62">cbufGetData</a>(this-&gt;buffer, this-&gt;isize),
<a name="l00089"></a>00089 this-&gt;isize);
<a name="l00090"></a>00090 }
<a name="l00091"></a>00091 <a class="code" href="cbuf_8h.html#aa6b501bd8016dfe1951f54dffe59262e">cbufRelease</a>(this-&gt;buffer);
<a name="l00092"></a>00092 this-&gt;ourLock = <a class="code" href="commons_8h.html#aa93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00093"></a>00093 cont = 0;
<a name="l00094"></a>00094 <span class="keywordflow">break</span>;
<a name="l00095"></a>00095 }
<a name="l00096"></a>00096
<a name="l00097"></a>00097 <a class="code" href="parser_8h.html#ad17a51c93dbb9085c719de8a586614d2">httpParserNewMessage</a>(<span class="keyword">this</span>, line, line_end);
<a name="l00098"></a>00098 <span class="keywordflow">if</span> (NULL == this-&gt;current) {
<a name="l00099"></a>00099 <a class="code" href="cbuf_8h.html#aa6b501bd8016dfe1951f54dffe59262e">cbufRelease</a>(this-&gt;buffer);
<a name="l00100"></a>00100 this-&gt;ourLock = <a class="code" href="commons_8h.html#aa93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00101"></a>00101 <span class="keywordflow">return</span> -1;
<a name="l00102"></a>00102 }
<a name="l00103"></a>00103 <a class="code" href="parser_8h.html#a3ed6fd01af0d4079f592fd492b79672b">httpParserRequestVars</a>(<span class="keyword">this</span>);
<a name="l00104"></a>00104
<a name="l00105"></a>00105 this-&gt;state = <a class="code" href="parser_8h.html#a994a868cfd1ee04fd1e546d6469d602ca33f96168adc45b3ecc59d9c842ecb6dc">HTTP_MESSAGE_INTRO_DONE</a>;
<a name="l00106"></a>00106 <span class="keywordflow">break</span>;
<a name="l00107"></a>00107
<a name="l00108"></a>00108 <span class="keywordflow">case</span> <a class="code" href="parser_8h.html#a994a868cfd1ee04fd1e546d6469d602ca33f96168adc45b3ecc59d9c842ecb6dc">HTTP_MESSAGE_INTRO_DONE</a>:
<a name="l00109"></a>00109 <span class="keywordflow">if</span> (NULL == (line = <a class="code" href="cbuf_8h.html#a60512cdcca11f127c26a8a30e42b8c5c">cbufGetLine</a>(this-&gt;buffer, &amp;line_end))) {
<a name="l00110"></a>00110 <span class="keywordflow">if</span> (! <a class="code" href="cbuf_8h.html#aa041996b32209a9b81a3e5db178c8339">cbufIsEmpty</a>(this-&gt;buffer)) {
<a name="l00111"></a>00111 this-&gt;isize = this-&gt;buffer-&gt;bused;
<a name="l00112"></a>00112 this-&gt;incomplete = malloc(this-&gt;isize);
<a name="l00113"></a>00113 memcpy(this-&gt;incomplete,
<a name="l00114"></a>00114 <a class="code" href="cbuf_8h.html#abc3bb54c6a324c849b872823ec70ce62">cbufGetData</a>(this-&gt;buffer, this-&gt;isize),
<a name="l00115"></a>00115 this-&gt;isize);
<a name="l00116"></a>00116 }
<a name="l00117"></a>00117 <a class="code" href="cbuf_8h.html#aa6b501bd8016dfe1951f54dffe59262e">cbufRelease</a>(this-&gt;buffer);
<a name="l00118"></a>00118 this-&gt;ourLock = <a class="code" href="commons_8h.html#aa93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00119"></a>00119 cont = 0;
<a name="l00120"></a>00120 <span class="keywordflow">break</span>;
<a name="l00121"></a>00121 }
<a name="l00122"></a>00122
<a name="l00123"></a>00123 <span class="keywordflow">if</span> (0 == strlen(line)) {
<a name="l00124"></a>00124 this-&gt;state = <a class="code" href="parser_8h.html#a994a868cfd1ee04fd1e546d6469d602cac2c0d477eee3e2a67de0e412ebeaffeb">HTTP_MESSAGE_HEADERS_DONE</a>;
<a name="l00125"></a>00125 <span class="keywordflow">break</span>;
<a name="l00126"></a>00126 }
<a name="l00127"></a>00127
<a name="l00128"></a>00128 <a class="code" href="parser_8h.html#a3add6b1b4a1e26a5baa86f2fa4c9d843">httpParserHeader</a>(<span class="keyword">this</span>, line, line_end);
<a name="l00129"></a>00129 <span class="keywordflow">break</span>;
<a name="l00130"></a>00130
<a name="l00131"></a>00131 <span class="keywordflow">case</span> <a class="code" href="parser_8h.html#a994a868cfd1ee04fd1e546d6469d602cac2c0d477eee3e2a67de0e412ebeaffeb">HTTP_MESSAGE_HEADERS_DONE</a>:
<a name="l00132"></a>00132 <span class="keywordflow">if</span> (this-&gt;current-&gt;dbody == this-&gt;current-&gt;nbody) {
<a name="l00133"></a>00133 this-&gt;state = <a class="code" href="parser_8h.html#a994a868cfd1ee04fd1e546d6469d602cae0ee4bfa2f146984095eb3bfb9e60be4">HTTP_MESSAGE_DONE</a>;
<a name="l00134"></a>00134 <span class="keywordflow">break</span>;
<a name="l00135"></a>00135 }
<a name="l00136"></a>00136
<a name="l00137"></a>00137 <span class="keywordflow">if</span> (<a class="code" href="cbuf_8h.html#aa041996b32209a9b81a3e5db178c8339">cbufIsEmpty</a>(this-&gt;buffer)) {
<a name="l00138"></a>00138 <a class="code" href="cbuf_8h.html#aa6b501bd8016dfe1951f54dffe59262e">cbufRelease</a>(this-&gt;buffer);
<a name="l00139"></a>00139 this-&gt;ourLock = <a class="code" href="commons_8h.html#aa93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00140"></a>00140 cont = 0;
<a name="l00141"></a>00141 <span class="keywordflow">break</span>;
<a name="l00142"></a>00142 }
<a name="l00143"></a>00143
<a name="l00144"></a>00144 <a class="code" href="cbuf_8h.html#ac6a5c458373606ebadf44cb631a615cb">cbufIncRead</a>(
<a name="l00145"></a>00145 this-&gt;buffer,
<a name="l00146"></a>00146 <a class="code" href="parser_8h.html#ada957e3200a4127a9a803e5312610651">httpParserBody</a>(
<a name="l00147"></a>00147 <span class="keyword">this</span>,
<a name="l00148"></a>00148 <a class="code" href="cbuf_8h.html#a652d95658664b0658eceaa09e93a3252">cbufGetRead</a>(this-&gt;buffer),
<a name="l00149"></a>00149 this-&gt;buffer-&gt;bused));
<a name="l00150"></a>00150 <span class="keywordflow">break</span>;
<a name="l00151"></a>00151
<a name="l00152"></a>00152 <span class="keywordflow">case</span> <a class="code" href="parser_8h.html#a994a868cfd1ee04fd1e546d6469d602cae0ee4bfa2f146984095eb3bfb9e60be4">HTTP_MESSAGE_DONE</a>:
<a name="l00153"></a>00153 {
<a name="l00154"></a>00154 <a class="code" href="structHttpHeader.html">HttpHeader</a> enc = <a class="code" href="hash_2hash_8h.html#ae63f5dffd0f7894f09a5f9b725cb6113">hashGet</a>(
<a name="l00155"></a>00155 this-&gt;current-&gt;header,
<a name="l00156"></a>00156 <a class="code" href="memory_8h.html#a2a9234835facec8c1ebca59c214391e3" title="Const STRing Argument.">CSTRA</a>(<span class="stringliteral">&quot;content-type&quot;</span>));
<a name="l00157"></a>00157
<a name="l00161"></a>00161 <span class="keywordflow">if</span> (NULL != enc &amp;&amp; 0 == strncasecmp(
<a name="l00162"></a>00162 <span class="stringliteral">&quot;application/x-www-form-urlencoded&quot;</span>,
<a name="l00163"></a>00163 enc-&gt;<a class="code" href="structHttpHeader.html#a34d93457f37f09aaf369bb16df485c39">value</a>[0],
<a name="l00164"></a>00164 <a class="code" href="parse_8c.html#a3acffbd305ee72dcd4593c0d8af64a4f">MIN</a>(<span class="keyword">sizeof</span>(<span class="stringliteral">&quot;application/x-www-form-urlencoded&quot;</span>)-1,
<a name="l00165"></a>00165 enc-&gt;<a class="code" href="structHttpHeader.html#a3f813ff5ee403e50a83fffc2dbf5cbb6" title="len of value without \0">nvalue</a>[0]))) {
<a name="l00167"></a>00167 <a class="code" href="parser_8h.html#a0ac1a5d015b74c978d757b2867786693">httpParserPostVars</a>(<span class="keyword">this</span>);
<a name="l00168"></a>00168 }
<a name="l00169"></a>00169
<a name="l00173"></a>00173 this-&gt;queue-&gt;msgs[(this-&gt;queue-&gt;nmsgs)++] = this-&gt;current;
<a name="l00174"></a>00174 this-&gt;current = NULL;
<a name="l00175"></a>00175
<a name="l00179"></a>00179 this-&gt;state = <a class="code" href="parser_8h.html#a994a868cfd1ee04fd1e546d6469d602cab5145e30bcb9d79664a352c9a2573d60">HTTP_MESSAGE_GARBAGE</a>;
<a name="l00180"></a>00180 }
<a name="l00181"></a>00181 <span class="keywordflow">break</span>;
<a name="l00182"></a>00182
<a name="l00183"></a>00183 <span class="keywordflow">default</span>:
<a name="l00184"></a>00184 <span class="keywordflow">break</span>;
<a name="l00185"></a>00185 }
<a name="l00186"></a>00186 }
<a name="l00187"></a>00187
<a name="l00188"></a>00188 <span class="keywordflow">return</span> this-&gt;queue-&gt;nmsgs;
<a name="l00189"></a>00189 }
<a name="l00190"></a>00190
<a name="l00191"></a>00191 <span class="comment">// vim: set ts=4 sw=4:</span>
</pre></div></div>
</div>
<div id="nav-path" class="navpath">
<ul>
<li class="navelem"><a class="el" href="parse_8c.html">parse.c</a> </li>
<li class="footer">Generated on Wed Mar 28 2012 10:39:43 for Server by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.3 </li>
</ul>
</div>
<!--- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Defines</a></div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
</body>
</html>