-
Notifications
You must be signed in to change notification settings - Fork 0
/
fcgi_backend.cc
66 lines (55 loc) · 1.67 KB
/
fcgi_backend.cc
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
// Copyright (C) 2011 Petr Machata
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program 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. See the GNU
// Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public
// License along with this program. If not, see
// <http://www.gnu.org/licenses/>.
#include "fcgi_backend.hh"
#include "url_decode.hh"
#include <fcgi_stdio.h>
#include <cstring>
#include <sstream>
#include <iostream>
extern "C" char **environ;
bool
fcgi_backend::get_word (std::string &word)
{
if (FCGI_Accept () < 0)
return false;
static char QS[] = "QUERY_STRING=";
for (char **it = environ; *it != NULL; ++it)
if (strncmp (*it, QS, sizeof (QS) - 1) == 0)
{
word = *it + sizeof (QS) - 1;
// Arbitrary cutoff. While it seems to not be a problem for
// Seman, nobody really needs to lemmatize words this long.
// Note that since urlencode is in effect, this really is just
// about 30 characters. This should still be enough for
// sensible words.
if (word.size () > 100)
word = "";
url_decode (word);
return true;
}
word = "";
return true;
}
void
fcgi_backend::before_render ()
{
render ("Content-type: text/html; charset=UTF-8\r\n\r\n");
}
bool
fcgi_backend::render (char const *str)
{
return FCGI_printf ("%s", str) >= 0;
}