Git Product home page Git Product logo

libscgi's Introduction

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. 






















libscgi's People

Contributors

akalend avatar

Watchers

Zuocheng Liu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.