#include <stdlib.h>
#include <stdio.h>
#include <ptypes.h>
#include <ptime.h>
#include "config.h"
#include "sysutils.h"
#include "utils.h"
#include "urlutils.h"
USING_PTYPES
char
trail_char(
const
string& s)
{
if
(isempty(s))
return
0;
else
return
*(pconst(s) + length(s) - 1);
}
void
trunc_trail_char(string& s)
{
if
(isempty(s))
return
;
else
setlength(s, length(s) - 1);
}
static
const
cset htchars =
"<>&\"~00"
;
void
html_encode(outstm& s,
const
char
* p)
{
while
(*p != 0)
{
const
char
* b = p;
while
(!(*p & htchars))
p++;
s.write(b, p - b);
switch
(*p)
{
case
'<'
: s.put(
"<"
);
break
;
case
'>'
: s.put(
">"
);
break
;
case
'&'
: s.put(
"&"
);
break
;
case
'"'
: s.put(""");
break
;
case
'\xa0'
: s.put(
" "
);
break
;
}
if
(*p != 0)
p++;
}
}
void
std_html_header(outstm& s,
const
string& title)
{
s.put(
"<html><head>\n"
);
s.put(
"<title>"
);
html_encode(s, title);
s.put(
"</title>\n"
);
s.put(STD_CSS);
s.put(
"</head><body>\n"
);
s.put(
"<h3><br>"
);
html_encode(s, title);
s.put(
"</h3>\n"
);
}
void
std_html_footer(outstm& s)
{
s.put(
"<p><hr noshade size=1>"
);
s.put(SERVER_APP_NAME);
s.put(
" at "
);
s.put(cfg_server_name);
if
(cfg_port != DEF_HTTP_PORT)
s.put(
':'
+ itostring(cfg_port));
s.put("</p>\n<script>
(function(i,s,o,g,r,a,m){i[
'GoogleAnalyticsObject'
]=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*
new
Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,
'script'
,
'//www.google-analytics.com/analytics.js'
,
'ga'
);
ga(
'create'
,
'UA-41898676-1'
,
'srchub.org'
);
ga(
'send'
,
'pageview'
);