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.
 
 
 
 

132 lines
13 KiB

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.7"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Webserv: srcs/webserv.cpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr id="projectrow">
<td id="projectalign">
<div id="projectname">Webserv
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.7 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search/",'.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>
<div id="nav-path" class="navpath">
<ul>
<li class="navelem"><a class="el" href="dir_b73b02d482d1c4a3db20c3d9ad52d395.html">srcs</a></li> </ul>
</div>
</div><!-- top -->
<div class="header">
<div class="headertitle"><div class="title">webserv.cpp</div></div>
</div><!--header-->
<div class="contents">
<a href="webserv_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a id="l00001" name="l00001"></a><span class="lineno"> 1</span> </div>
<div class="line"><a id="l00009" name="l00009"></a><span class="lineno"> 9</span><span class="preprocessor">#include &quot;<a class="code" href="webserv_8hpp.html">webserv.hpp</a>&quot;</span></div>
<div class="line"><a id="l00010" name="l00010"></a><span class="lineno"> 10</span> </div>
<div class="line"><a id="l00011" name="l00011"></a><span class="lineno"> 11</span>fd_set <a class="code hl_variable" href="classMaster.html#a16a05173b1961ea7fc302319f06716a4">Master::_readfds</a>; </div>
<div class="line"><a id="l00012" name="l00012"></a><span class="lineno"> 12</span><span class="keywordtype">int</span> <a class="code hl_variable" href="classMaster.html#a6c0dd4e4c7de17dea3de77f28e1de308">Master::_min_fd</a> = INT_MAX; </div>
<div class="line"><a id="l00013" name="l00013"></a><span class="lineno"> 13</span><span class="keywordtype">int</span> <a class="code hl_variable" href="classMaster.html#a40b24ae083809951e7d3e1a08d06fe65">Master::_max_fd</a> = 0; </div>
<div class="line"><a id="l00014" name="l00014"></a><span class="lineno"> 14</span><span class="keywordtype">int</span> <a class="code hl_variable" href="classMaster.html#a2418abd3c0d0e9f4db769335cadd7545">Master::_amount</a> = 0; </div>
<div class="line"><a id="l00015" name="l00015"></a><span class="lineno"> 15</span> </div>
<div class="line"><a id="l00016" name="l00016"></a><span class="lineno"> 16</span><span class="comment">/* *******************************/</span></div>
<div class="line"><a id="l00025" name="l00025"></a><span class="lineno"> 25</span><span class="comment">/* *******************************/</span></div>
<div class="line"><a id="l00026" name="l00026"></a><span class="lineno"><a class="line" href="webserv_8cpp.html#a0c99d968a34e803d378692bde2e3f18f"> 26</a></span><span class="keywordtype">int</span> <a class="code hl_function" href="webserv_8cpp.html#a0c99d968a34e803d378692bde2e3f18f">main</a>(<span class="keywordtype">int</span> ac, <span class="keywordtype">char</span> **av) {</div>
<div class="line"><a id="l00027" name="l00027"></a><span class="lineno"> 27</span> <span class="keywordflow">try</span> {</div>
<div class="line"><a id="l00028" name="l00028"></a><span class="lineno"> 28</span> <span class="comment">// Parse config file</span></div>
<div class="line"><a id="l00029" name="l00029"></a><span class="lineno"> 29</span> <span class="keywordflow">if</span> (ac &gt; 2)</div>
<div class="line"><a id="l00030" name="l00030"></a><span class="lineno"> 30</span> <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">&quot;Too many arguments&quot;</span>);</div>
<div class="line"><a id="l00031" name="l00031"></a><span class="lineno"> 31</span> std::string config_file = <span class="stringliteral">&quot;default.json&quot;</span>;</div>
<div class="line"><a id="l00032" name="l00032"></a><span class="lineno"> 32</span> <span class="keywordflow">if</span> (ac == 2)</div>
<div class="line"><a id="l00033" name="l00033"></a><span class="lineno"> 33</span> config_file = av[1];</div>
<div class="line"><a id="l00034" name="l00034"></a><span class="lineno"> 34</span> std::ifstream file(config_file.c_str());</div>
<div class="line"><a id="l00035" name="l00035"></a><span class="lineno"> 35</span> <span class="keywordflow">if</span> (!file.good())</div>
<div class="line"><a id="l00036" name="l00036"></a><span class="lineno"> 36</span> <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">&quot;File not found&quot;</span>);</div>
<div class="line"><a id="l00037" name="l00037"></a><span class="lineno"> 37</span> cout &lt;&lt; <span class="stringliteral">&quot;Parsing configuration file from JSON conf file.\n&quot;</span>;</div>
<div class="line"><a id="l00038" name="l00038"></a><span class="lineno"> 38</span> cout &lt;&lt; <span class="stringliteral">&quot;You must be sure the syntax is correct\n&quot;</span>;</div>
<div class="line"><a id="l00039" name="l00039"></a><span class="lineno"> 39</span> <a class="code hl_class" href="classJSONParser.html">JSONParser</a> parser(config_file);</div>
<div class="line"><a id="l00040" name="l00040"></a><span class="lineno"> 40</span> <a class="code hl_class" href="classJSONNode.html">JSONNode</a> *conf = parser.<a class="code hl_function" href="classJSONParser.html#ac397e1ef199b5cd553c1dece740a045e">parse</a>();</div>
<div class="line"><a id="l00041" name="l00041"></a><span class="lineno"> 41</span> <span class="comment">// Here we start the server and his environment using conf</span></div>
<div class="line"><a id="l00042" name="l00042"></a><span class="lineno"> 42</span> cout &lt;&lt; <span class="stringliteral">&quot;Initialization of server...\n&quot;</span>;</div>
<div class="line"><a id="l00043" name="l00043"></a><span class="lineno"> 43</span> <a class="code hl_class" href="classEnv.html">Env</a> env(conf);</div>
<div class="line"><a id="l00044" name="l00044"></a><span class="lineno"> 44</span> <span class="keywordflow">while</span> (1)</div>
<div class="line"><a id="l00045" name="l00045"></a><span class="lineno"> 45</span> env.<a class="code hl_function" href="classEnv.html#a0c8b92f45308987231f9b0be8751d39f">cycle</a>();</div>
<div class="line"><a id="l00046" name="l00046"></a><span class="lineno"> 46</span> } <span class="keywordflow">catch</span> (<span class="keyword">const</span> std::exception &amp;e) {</div>
<div class="line"><a id="l00047" name="l00047"></a><span class="lineno"> 47</span> std::cerr &lt;&lt; e.what() &lt;&lt; <span class="charliteral">&#39;\n&#39;</span>;</div>
<div class="line"><a id="l00048" name="l00048"></a><span class="lineno"> 48</span> <span class="keywordflow">return</span> EXIT_FAILURE;</div>
<div class="line"><a id="l00049" name="l00049"></a><span class="lineno"> 49</span> }</div>
<div class="line"><a id="l00050" name="l00050"></a><span class="lineno"> 50</span> <span class="keywordflow">return</span> EXIT_SUCCESS;</div>
<div class="line"><a id="l00051" name="l00051"></a><span class="lineno"> 51</span>}</div>
<div class="ttc" id="aclassEnv_html"><div class="ttname"><a href="classEnv.html">Env</a></div><div class="ttdef"><b>Definition:</b> <a href="Env_8hpp_source.html#l00004">Env.hpp:4</a></div></div>
<div class="ttc" id="aclassEnv_html_a0c8b92f45308987231f9b0be8751d39f"><div class="ttname"><a href="classEnv.html#a0c8b92f45308987231f9b0be8751d39f">Env::cycle</a></div><div class="ttdeci">void cycle(void)</div><div class="ttdoc">A Wevserv cycle:</div><div class="ttdef"><b>Definition:</b> <a href="Env_8cpp_source.html#l00055">Env.cpp:55</a></div></div>
<div class="ttc" id="aclassJSONNode_html"><div class="ttname"><a href="classJSONNode.html">JSONNode</a></div><div class="ttdef"><b>Definition:</b> <a href="Nodes_8hpp_source.html#l00004">Nodes.hpp:4</a></div></div>
<div class="ttc" id="aclassJSONParser_html"><div class="ttname"><a href="classJSONParser.html">JSONParser</a></div><div class="ttdef"><b>Definition:</b> <a href="Parser_8hpp_source.html#l00004">Parser.hpp:4</a></div></div>
<div class="ttc" id="aclassJSONParser_html_ac397e1ef199b5cd553c1dece740a045e"><div class="ttname"><a href="classJSONParser.html#ac397e1ef199b5cd553c1dece740a045e">JSONParser::parse</a></div><div class="ttdeci">JSONNode * parse()</div><div class="ttdef"><b>Definition:</b> <a href="Parser_8cpp_source.html#l00005">Parser.cpp:5</a></div></div>
<div class="ttc" id="aclassMaster_html_a16a05173b1961ea7fc302319f06716a4"><div class="ttname"><a href="classMaster.html#a16a05173b1961ea7fc302319f06716a4">Master::_readfds</a></div><div class="ttdeci">static fd_set _readfds</div><div class="ttdef"><b>Definition:</b> <a href="Master_8hpp_source.html#l00019">Master.hpp:19</a></div></div>
<div class="ttc" id="aclassMaster_html_a2418abd3c0d0e9f4db769335cadd7545"><div class="ttname"><a href="classMaster.html#a2418abd3c0d0e9f4db769335cadd7545">Master::_amount</a></div><div class="ttdeci">static int _amount</div><div class="ttdoc">&lt; The higher one</div><div class="ttdef"><b>Definition:</b> <a href="Master_8hpp_source.html#l00020">Master.hpp:20</a></div></div>
<div class="ttc" id="aclassMaster_html_a40b24ae083809951e7d3e1a08d06fe65"><div class="ttname"><a href="classMaster.html#a40b24ae083809951e7d3e1a08d06fe65">Master::_max_fd</a></div><div class="ttdeci">static int _max_fd</div><div class="ttdoc">&lt; The lower socket fd</div><div class="ttdef"><b>Definition:</b> <a href="Master_8hpp_source.html#l00020">Master.hpp:20</a></div></div>
<div class="ttc" id="aclassMaster_html_a6c0dd4e4c7de17dea3de77f28e1de308"><div class="ttname"><a href="classMaster.html#a6c0dd4e4c7de17dea3de77f28e1de308">Master::_min_fd</a></div><div class="ttdeci">static int _min_fd</div><div class="ttdoc">&lt; The sockets fd which will be select</div><div class="ttdef"><b>Definition:</b> <a href="Master_8hpp_source.html#l00020">Master.hpp:20</a></div></div>
<div class="ttc" id="awebserv_8cpp_html_a0c99d968a34e803d378692bde2e3f18f"><div class="ttname"><a href="webserv_8cpp.html#a0c99d968a34e803d378692bde2e3f18f">main</a></div><div class="ttdeci">int main(int ac, char **av)</div><div class="ttdoc">&lt; The amount of sockets listens</div><div class="ttdef"><b>Definition:</b> <a href="webserv_8cpp_source.html#l00026">webserv.cpp:26</a></div></div>
<div class="ttc" id="awebserv_8hpp_html"><div class="ttname"><a href="webserv_8hpp.html">webserv.hpp</a></div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.7
</small></address>
</body>
</html>