1
0
mirror of https://github.com/stefanocasazza/ULib.git synced 2025-09-28 19:05:55 +08:00
ULib/ulib.html
stefanocasazza 3539f934d4 sync
2017-05-07 18:06:08 +02:00

403 lines
13 KiB
HTML

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>ULib</title>
<!-- 2017-05-07 Sun 13:21 -->
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="generator" content="Org-mode" />
<meta name="author" content="nemsys" />
<style type="text/css">
<!--/*--><![CDATA[/*><!--*/
.title { text-align: center; }
.todo { font-family: monospace; color: red; }
.done { color: green; }
.tag { background-color: #eee; font-family: monospace;
padding: 2px; font-size: 80%; font-weight: normal; }
.timestamp { color: #bebebe; }
.timestamp-kwd { color: #5f9ea0; }
.right { margin-left: auto; margin-right: 0px; text-align: right; }
.left { margin-left: 0px; margin-right: auto; text-align: left; }
.center { margin-left: auto; margin-right: auto; text-align: center; }
.underline { text-decoration: underline; }
#postamble p, #preamble p { font-size: 90%; margin: .2em; }
p.verse { margin-left: 3%; }
pre {
border: 1px solid #ccc;
box-shadow: 3px 3px 3px #eee;
padding: 8pt;
font-family: monospace;
overflow: auto;
margin: 1.2em;
}
pre.src {
position: relative;
overflow: visible;
padding-top: 1.2em;
}
pre.src:before {
display: none;
position: absolute;
background-color: white;
top: -10px;
right: 10px;
padding: 3px;
border: 1px solid black;
}
pre.src:hover:before { display: inline;}
pre.src-sh:before { content: 'sh'; }
pre.src-bash:before { content: 'sh'; }
pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
pre.src-R:before { content: 'R'; }
pre.src-perl:before { content: 'Perl'; }
pre.src-java:before { content: 'Java'; }
pre.src-sql:before { content: 'SQL'; }
table { border-collapse:collapse; }
caption.t-above { caption-side: top; }
caption.t-bottom { caption-side: bottom; }
td, th { vertical-align:top; }
th.right { text-align: center; }
th.left { text-align: center; }
th.center { text-align: center; }
td.right { text-align: right; }
td.left { text-align: left; }
td.center { text-align: center; }
dt { font-weight: bold; }
.footpara:nth-child(2) { display: inline; }
.footpara { display: block; }
.footdef { margin-bottom: 1em; }
.figure { padding: 1em; }
.figure p { text-align: center; }
.inlinetask {
padding: 10px;
border: 2px solid gray;
margin: 10px;
background: #ffffcc;
}
#org-div-home-and-up
{ text-align: right; font-size: 70%; white-space: nowrap; }
textarea { overflow-x: auto; }
.linenr { font-size: smaller }
.code-highlighted { background-color: #ffff00; }
.org-info-js_info-navigation { border-style: none; }
#org-info-js_console-label
{ font-size: 10px; font-weight: bold; white-space: nowrap; }
.org-info-js_search-highlight
{ background-color: #ffff00; color: #000000; font-weight: bold; }
/*]]>*/-->
</style>
<script type="text/javascript">
/*
@licstart The following is the entire license notice for the
JavaScript code in this tag.
Copyright (C) 2012-2013 Free Software Foundation, Inc.
The JavaScript code in this tag is free software: you can
redistribute it and/or modify it under the terms of the GNU
General Public License (GNU GPL) as published by the Free Software
Foundation, either version 3 of the License, or (at your option)
any later version. The code is distributed WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
As additional permission under GNU GPL version 3 section 7, you
may distribute non-source (e.g., minimized or compacted) forms of
that code without the copy of the GNU GPL normally required by
section 4, provided you include this license notice and a URL
through which recipients can access the Corresponding Source.
@licend The above is the entire license notice
for the JavaScript code in this tag.
*/
<!--/*--><![CDATA[/*><!--*/
function CodeHighlightOn(elem, id)
{
var target = document.getElementById(id);
if(null != target) {
elem.cacheClassElem = elem.className;
elem.cacheClassTarget = target.className;
target.className = "code-highlighted";
elem.className = "code-highlighted";
}
}
function CodeHighlightOff(elem, id)
{
var target = document.getElementById(id);
if(elem.cacheClassElem)
elem.className = elem.cacheClassElem;
if(elem.cacheClassTarget)
target.className = elem.cacheClassTarget;
}
/*]]>*///-->
</script>
</head>
<body>
<div id="content">
<h1 class="title">ULib</h1>
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#sec-1">1. Getting Started With ULib</a>
<ul>
<li><a href="#sec-1-1">1.1. What is userver</a></li>
<li><a href="#sec-1-2">1.2. Get a copy of the ULib source code</a></li>
<li><a href="#sec-1-3">1.3. configure your build</a></li>
<li><a href="#sec-1-4">1.4. configure userver</a></li>
<li><a href="#sec-1-5">1.5. debug environment</a></li>
<li><a href="#sec-1-6">1.6. Running your server (static pages)</a></li>
<li><a href="#sec-1-7">1.7. USP ULib Servlet Page (dynamic pages)</a></li>
<li><a href="#sec-1-8">1.8. Tags</a>
<ul>
<li><a href="#sec-1-8-1">1.8.1. c++ header file .h</a></li>
<li><a href="#sec-1-8-2">1.8.2. c++ code file .cpp</a></li>
<li><a href="#sec-1-8-3">1.8.3. html template</a></li>
</ul>
</li>
<li><a href="#sec-1-9">1.9. Compiling</a></li>
<li><a href="#sec-1-10">1.10. Test</a></li>
<li><a href="#sec-1-11">1.11. SECURITY</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div id="outline-container-sec-1" class="outline-2">
<h2 id="sec-1"><span class="section-number-2">1</span> Getting Started With ULib</h2>
<div class="outline-text-2" id="text-1">
<p>
To help those curious souls that want to see if userver is a good fit for their needs I have recorded my own experiences below.
Firstly a huge thankyou to Stefano Casazza not only for making ULib but for all his patience in answering all my questions.
</p>
</div>
<div id="outline-container-sec-1-1" class="outline-3">
<h3 id="sec-1-1"><span class="section-number-3">1.1</span> What is userver</h3>
<div class="outline-text-3" id="text-1-1">
<p>
UServer is a extensible plugin based web server that is build on top of ULib.
</p>
<p>
ULib is installed as a set of shared object libraries and header files (like Boost).
</p>
</div>
</div>
<div id="outline-container-sec-1-2" class="outline-3">
<h3 id="sec-1-2"><span class="section-number-3">1.2</span> Get a copy of the ULib source code</h3>
<div class="outline-text-3" id="text-1-2">
<p>
git clone <a href="https://github.com/stefanocasazza/ULib.git">https://github.com/stefanocasazza/ULib.git</a>
</p>
</div>
</div>
<div id="outline-container-sec-1-3" class="outline-3">
<h3 id="sec-1-3"><span class="section-number-3">1.3</span> configure your build</h3>
<div class="outline-text-3" id="text-1-3">
<p>
For those of you like me who havn't had much experience playing with autotools read the config help or:
</p>
<p>
./configure -h
</p>
<p>
Having now decided on what features you need let ./configure do its magic.
</p>
<p>
For example:
./configure &#x2013;enable-debug &#x2013;with-sqlite3
</p>
<p>
make
sudo make install
</p>
</div>
</div>
<div id="outline-container-sec-1-4" class="outline-3">
<h3 id="sec-1-4"><span class="section-number-3">1.4</span> configure userver</h3>
<div class="outline-text-3" id="text-1-4">
<p>
Assuming you haven't changed the PREFIX make will install userver to /usr/local
</p>
<p>
At this point we need to configure /usr/local/etc/userver.cfg
The file is well annotated at a bare minimum setup the following values:
<br>
DOCUMENT_ROOT /var/www<br>
LOG_FILE userver.log<br>
PLUGIN "http"<br>
PLUGIN_DIR /usr/local/libexec<br>
ORM_DRIVER_DIR /usr/local/libexec<br>
</p>
</div>
</div>
<p>
This environment variables are for ORM management:
<br>
ORM_DRIVER "sqlite"<br>
ORM_OPTION "host=localhost user=user password=pass character-set=utf8 dbname=/path_to_db/dbname.db"
</p>
</div>
</div>
<div id="outline-container-sec-1-5" class="outline-3">
<h3 id="sec-1-5"><span class="section-number-3">1.5</span> debug environment</h3>
<div class="outline-text-3" id="text-1-5">
<p>
userver_tcp expects some environment variables for debug mode to save typing it is easiest to put these into a bash script like this:
</p>
<p>
#!/bin/sh
</p>
<p>
UTRACE="0 20M 0"<br>
UTRACE_SIGNAL="0 20M 0"<br>
#UOBJDUMP="0 10M 100"<br>
#USIMERR="error.sim"<br>
export UTRACE UOBJDUMP USIMERR UTRACE_SIGNAL
</p>
<p>
userver_tcp
</p>
</div>
</div>
<div id="outline-container-sec-1-6" class="outline-3">
<h3 id="sec-1-6"><span class="section-number-3">1.6</span> Running your server (static pages)</h3>
<div class="outline-text-3" id="text-1-6">
<p>
Once you have configured your userver.cfg and placed the relevant html documents in your docroot just execute the bash script above.
</p>
<p>
Point your browser to localhost/filename you should now have a working server.
</p>
</div>
</div>
<div id="outline-container-sec-1-7" class="outline-3">
<h3 id="sec-1-7"><span class="section-number-3">1.7</span> USP ULib Servlet Page (dynamic pages)</h3>
<div class="outline-text-3" id="text-1-7">
<p>
userver offers a wide variety of ways to generate dynamic content we will be looking at USP method.
</p>
<p>
A USP page is a multi-format document that permits c++ code to be embedded into html.
This document is then compiled into a shared object library that will be executed by userver.
</p>
<p>
The document consists of overloaded html comment tags that the USP compiler will extract.
</p>
</div>
</div>
<div id="outline-container-sec-1-8" class="outline-3">
<h3 id="sec-1-8"><span class="section-number-3">1.8</span> Tags</h3>
<div class="outline-text-3" id="text-1-8">
<p>
Have a look at the examples in the ULib source directory ULib/src/ulib/net/server/plugin/usp for usage but in very simple terms.
</p>
</div>
<div id="outline-container-sec-1-8-1" class="outline-4">
<h4 id="sec-1-8-1"><span class="section-number-4">1.8.1</span> c++ header file .h</h4>
<div class="outline-text-4" id="text-1-8-1">
<p>
&lt;!&#x2013;#declaration
&#x2013;&gt;
</p>
</div>
</div>
<div id="outline-container-sec-1-8-2" class="outline-4">
<h4 id="sec-1-8-2"><span class="section-number-4">1.8.2</span> c++ code file .cpp</h4>
<div class="outline-text-4" id="text-1-8-2">
<p>
&lt;!&#x2013;#code
UString name = U_STRING_FROM_CONSTANT("Hello World");
&#x2013;&gt;
</p>
</div>
</div>
<div id="outline-container-sec-1-8-3" class="outline-4">
<h4 id="sec-1-8-3"><span class="section-number-4">1.8.3</span> html template</h4>
<div class="outline-text-4" id="text-1-8-3">
<p>
&lt;h1&gt;Hello &lt;!&#x2013;#xmlputs name &#x2013;&gt;&lt;/h1&gt;
</p>
</div>
</div>
</div>
<div id="outline-container-sec-1-9" class="outline-3">
<h3 id="sec-1-9"><span class="section-number-3">1.9</span> Compiling</h3>
<div class="outline-text-3" id="text-1-9">
<p>
Once you have written your .usp file it needs to be compiled.
I found it easiest to navigate to the folder where the file.usp was saved and execute the compilation in the shell for example:
</p>
<p>
cd /srv/http/servlet
/usr/local/bin/usp_compile.sh test
</p>
<p>
Please note that usp_compile.sh wants the usp file without the extension.
The shell script will call the relevant programs to generate c++ code from the usp file and finally call gcc and libtool to create a shared library.Any compilation errors will be output to console and no .so file will be generated.
</p>
<p>
It would be trivial to execute usp_compile as a custom command from most IDEs.
</p>
</div>
</div>
<div id="outline-container-sec-1-10" class="outline-3">
<h3 id="sec-1-10"><span class="section-number-3">1.10</span> Test</h3>
<div class="outline-text-3" id="text-1-10">
<p>
Now point your browser to localhost/nameofusp and userver will execute the USP file.
</p>
</div>
</div>
<div id="outline-container-sec-1-11" class="outline-3">
<h3 id="sec-1-11"><span class="section-number-3">1.11</span> SECURITY</h3>
<div class="outline-text-3" id="text-1-11">
<p>
As with all web servers do not run them as the root user.
This introduction has been written to give you an idea of the ULib/UServer workflow. It is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. It is your responsibility to secure your web server and follow sound security conscious programming practices.
</p>
</div>
</div>
</div>
</div>
<div id="postamble" class="status">
<p class="author">Author: nemsys</p>
<p class="date">Created: 2017-05-07 Sun 13:21</p>
<p class="creator"><a href="http://www.gnu.org/software/emacs/">Emacs</a> 25.2.1 (<a href="http://orgmode.org">Org</a> mode 8.2.10)</p>
<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
</div>
</body>
</html>