-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_router_segments_8c-example.html
167 lines (165 loc) · 13.1 KB
/
example_router_segments_8c-example.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<!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>Sagui library: example_router_segments.c</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>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
$(document).ready(function() { init_search(); });
/* @license-end */
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="sagui.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">Sagui library<span id="projectnumber"> v3.5.0</span>
</div>
<div id="projectbrief">Cross-platform library which helps to develop web servers or frameworks.</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&dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search/",'.html');
/* @license-end */
</script>
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main Page</span></a></li>
<li><a href="modules.html"><span>Modules</span></a></li>
<li><a href="annotated.html"><span>Data Structures</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
<li><a href="examples.html"><span>Examples</span></a></li>
<li>
<div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<span id="MSearchSelect" onmouseover="return searchBox.OnSearchSelectShow()" onmouseout="return searchBox.OnSearchSelectHide()"> </span>
<input type="text" id="MSearchField" value="" placeholder="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.svg" alt=""/></a>
</span>
</div>
</li>
</ul>
</div>
</div><!-- top -->
<!-- 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 class="header">
<div class="headertitle"><div class="title">example_router_segments.c</div></div>
</div><!--header-->
<div class="contents">
<p>Simple example showing how to access the path segments of the router feature.</p>
<div class="fragment"><div class="line"><span class="comment">/* _</span></div>
<div class="line"><span class="comment"> * ___ __ _ __ _ _ _(_)</span></div>
<div class="line"><span class="comment"> * / __|/ _` |/ _` | | | | |</span></div>
<div class="line"><span class="comment"> * \__ \ (_| | (_| | |_| | |</span></div>
<div class="line"><span class="comment"> * |___/\__,_|\__, |\__,_|_|</span></div>
<div class="line"><span class="comment"> * |___/</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * Cross-platform library which helps to develop web servers or frameworks.</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * Copyright (C) 2016-2019 Silvio Clecio <[email protected]></span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * Sagui library is free software; you can redistribute it and/or</span></div>
<div class="line"><span class="comment"> * modify it under the terms of the GNU Lesser General Public</span></div>
<div class="line"><span class="comment"> * License as published by the Free Software Foundation; either</span></div>
<div class="line"><span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * Sagui library is distributed in the hope that it will be useful,</span></div>
<div class="line"><span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span></div>
<div class="line"><span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span></div>
<div class="line"><span class="comment"> * Lesser General Public License for more details.</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * You should have received a copy of the GNU Lesser General Public</span></div>
<div class="line"><span class="comment"> * License along with Sagui library; if not, write to the Free Software</span></div>
<div class="line"><span class="comment"> * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#include <stdlib.h></span></div>
<div class="line"><span class="preprocessor">#include <stdio.h></span></div>
<div class="line"><span class="preprocessor">#include <<a class="code" href="sagui_8h.html">sagui.h</a>></span></div>
<div class="line"> </div>
<div class="line"><span class="comment">/* NOTE: Error checking has been omitted to make it clear. */</span></div>
<div class="line"> </div>
<div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> segments_iter_cb(__SG_UNUSED <span class="keywordtype">void</span> *cls, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> index,</div>
<div class="line"> <span class="keyword">const</span> <span class="keywordtype">char</span> *segment) {</div>
<div class="line"> fprintf(stdout, <span class="stringliteral">" %d: %s\n"</span>, index, segment);</div>
<div class="line"> <span class="keywordflow">return</span> 0;</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> route_cb(<span class="keywordtype">void</span> *cls, <span class="keyword">struct</span> <a id="_a0" name="_a0"></a><a class="code hl_struct" href="structsg__route.html">sg_route</a> *route) {</div>
<div class="line"> fprintf(stdout, <span class="stringliteral">"%s: %s\n"</span>, <a id="a1" name="a1"></a><a class="code hl_function" href="group__sg__routing.html#ga665e84d03cb1957013938ee5d665da86">sg_route_path</a>(route), (<span class="keyword">const</span> <span class="keywordtype">char</span> *) cls);</div>
<div class="line"> <a id="a2" name="a2"></a><a class="code hl_function" href="group__sg__routing.html#gafe888e10ef5ee78be213726b7a123e11">sg_route_segments_iter</a>(route, segments_iter_cb, NULL);</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">void</span>) {</div>
<div class="line"> <span class="keyword">struct </span><a id="_a3" name="_a3"></a><a class="code hl_struct" href="structsg__router.html">sg_router</a> *router;</div>
<div class="line"> <span class="keyword">struct </span><a class="code hl_struct" href="structsg__route.html">sg_route</a> *routes = NULL;</div>
<div class="line"> <a id="a4" name="a4"></a><a class="code hl_function" href="group__sg__routing.html#gac068a83f7f83a2d722cde42da261ed15">sg_routes_add</a>(&routes, <span class="stringliteral">"/foo/[0-9]+"</span>, route_cb, <span class="stringliteral">"foo-data"</span>);</div>
<div class="line"> <a class="code hl_function" href="group__sg__routing.html#gac068a83f7f83a2d722cde42da261ed15">sg_routes_add</a>(&routes, <span class="stringliteral">"/bar/([a-zA-Z]+)/([0-9]+)"</span>, route_cb, <span class="stringliteral">"bar-data"</span>);</div>
<div class="line"> router = <a id="a5" name="a5"></a><a class="code hl_function" href="group__sg__routing.html#gaa7841a69298f7936356a2207f07c90e2">sg_router_new</a>(routes);</div>
<div class="line"> <a id="a6" name="a6"></a><a class="code hl_function" href="group__sg__routing.html#ga20914c40040042aab8f0e6edf9a750ca">sg_router_dispatch</a>(router, <span class="stringliteral">"/foo/123"</span>, NULL);</div>
<div class="line"> fprintf(stdout, <span class="stringliteral">"---\n"</span>);</div>
<div class="line"> <a class="code hl_function" href="group__sg__routing.html#ga20914c40040042aab8f0e6edf9a750ca">sg_router_dispatch</a>(router, <span class="stringliteral">"/bar/abc/123"</span>, NULL);</div>
<div class="line"> <a id="a7" name="a7"></a><a class="code hl_function" href="group__sg__routing.html#ga5ee260ff563559b8d83dd6623fbea966">sg_routes_cleanup</a>(&routes);</div>
<div class="line"> <a id="a8" name="a8"></a><a class="code hl_function" href="group__sg__routing.html#gacab84dc3bbc69dd4b1ebd1931b22f0f7">sg_router_free</a>(router);</div>
<div class="line"> fflush(stdout);</div>
<div class="line"> <span class="keywordflow">return</span> EXIT_SUCCESS;</div>
<div class="line">}</div>
<div class="ttc" id="agroup__sg__routing_html_ga20914c40040042aab8f0e6edf9a750ca"><div class="ttname"><a href="group__sg__routing.html#ga20914c40040042aab8f0e6edf9a750ca">sg_router_dispatch</a></div><div class="ttdeci">int sg_router_dispatch(struct sg_router *router, const char *path, void *user_data)</div></div>
<div class="ttc" id="agroup__sg__routing_html_ga5ee260ff563559b8d83dd6623fbea966"><div class="ttname"><a href="group__sg__routing.html#ga5ee260ff563559b8d83dd6623fbea966">sg_routes_cleanup</a></div><div class="ttdeci">int sg_routes_cleanup(struct sg_route **routes)</div></div>
<div class="ttc" id="agroup__sg__routing_html_ga665e84d03cb1957013938ee5d665da86"><div class="ttname"><a href="group__sg__routing.html#ga665e84d03cb1957013938ee5d665da86">sg_route_path</a></div><div class="ttdeci">const char * sg_route_path(struct sg_route *route)</div></div>
<div class="ttc" id="agroup__sg__routing_html_gaa7841a69298f7936356a2207f07c90e2"><div class="ttname"><a href="group__sg__routing.html#gaa7841a69298f7936356a2207f07c90e2">sg_router_new</a></div><div class="ttdeci">struct sg_router * sg_router_new(struct sg_route *routes) __attribute__((malloc))</div></div>
<div class="ttc" id="agroup__sg__routing_html_gac068a83f7f83a2d722cde42da261ed15"><div class="ttname"><a href="group__sg__routing.html#gac068a83f7f83a2d722cde42da261ed15">sg_routes_add</a></div><div class="ttdeci">bool sg_routes_add(struct sg_route **routes, const char *pattern, sg_route_cb cb, void *cls)</div></div>
<div class="ttc" id="agroup__sg__routing_html_gacab84dc3bbc69dd4b1ebd1931b22f0f7"><div class="ttname"><a href="group__sg__routing.html#gacab84dc3bbc69dd4b1ebd1931b22f0f7">sg_router_free</a></div><div class="ttdeci">void sg_router_free(struct sg_router *router)</div></div>
<div class="ttc" id="agroup__sg__routing_html_gafe888e10ef5ee78be213726b7a123e11"><div class="ttname"><a href="group__sg__routing.html#gafe888e10ef5ee78be213726b7a123e11">sg_route_segments_iter</a></div><div class="ttdeci">int sg_route_segments_iter(struct sg_route *route, sg_segments_iter_cb cb, void *cls)</div></div>
<div class="ttc" id="asagui_8h_html"><div class="ttname"><a href="sagui_8h.html">sagui.h</a></div></div>
<div class="ttc" id="astructsg__route_html"><div class="ttname"><a href="structsg__route.html">sg_route</a></div></div>
<div class="ttc" id="astructsg__router_html"><div class="ttname"><a href="structsg__router.html">sg_router</a></div></div>
</div><!-- fragment --> </div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Wed Feb 14 2024 15:11:38 for Sagui library by <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>