/
README
125 lines (77 loc) · 3.54 KB
/
README
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
The libscgi is lightweight framework realise the scgi prootocol http://en.wikipedia.org/wiki/SCGI It is simple scgi server based on libevent. You can use as backend to Apache/lighttpd/nginix ( http://nginx.org )
The field of use is lightweight scripts as quickly find, script of autocomplete, online dictionary.
Configure nginx scgi_module:
location /dictionary {
scgi_pass localhost:8080;
include scgi_params;
}
You can to change host/port.
The example of code:
/**
* the cackback handler
* example Users logic
*/
class Handler: IScgiHandler {
void run(map< string,string > * parms, char * buffUot) {
string parm = getParam("REQUEST_METHOD",parms);
// if method is POST
if ( parm == "POST" ) {
// return to WEB-client the POST data
strcpy(buffUot, getParam("POST_DATA",parms).c_str());
return;
}
// or return to WEB-client the QUERY_STRING parameter
strcpy(buffUot, getParam("QUERY_STRING",parms).c_str());
}
};
int main(int argc, char **argv)
{
scgiServer scgi;
if (scgi.checkPid()) {
cerr << "the pid file exist or daemon already started\n" << endl;
return 1;
}
if ((pid = scgi.demonize()) < 1) {
if (pid == -1) {
cerr << "demonize error\n";
return 1;
}
return 0;
}
if (scgi.init("127.0.0.1", 8080) ) {
cerr << "server stopped\n";
return 1;
}
scgi.addHandler("/dictionary", reinterpret_cast<IScgiHandler *>(new Handler()));
scgi.run();
}
INSTALL
make liby - compile the scgi-library
make - compile the scgi-bin example
make ac - compile the city autocompile programm
City Autocomplete programm (as example)
The practical example is city autocomplete. See source of the autocomplete.cpp.
The autocomplete program read the city names file. The format is csv: city lowcase name or shortname, city official name, range, id. The example:
"new-york","New York",25,1267
"newyork","New York",25,1267
"washington",""Washington",10,1121
etc...
The range is sort order variable. For example:
Moscow - is Russian capital, must be first in the padding list, beginning with letter "m".
Mogilev - is region center city.
Malinovka - is country, but if show by abc, the name "Malinovka" will showed before Moscow. Using range variable , we creale ordered list: Moscow,Mogilev,Malinovka.
The run script: ./server /path/to/cityNameFile.csv
Input data: send post data (one-two-three symbols from word) to url http://hostname/cityes
The output is in json format: {"cityes" : [ { "name": "New York", "id":90},{ "name": "New Vasyki", "id":808},{ "name": "Nazareth", "id":1505},{ "name": "Neaple", "id":1965}],"time":304}
The limitation of the output is ten items. This limitation can change by definition constant MAXITEMS in source before compilation. The "time" parametr is processing time for search an range in microseconds.
LICENSE
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.