Git Product home page Git Product logo

tcgi's Introduction

tcgi: CGI engine in C

This single source file implements a parser for CGI requests coming from a web server. It supports GET and POST and will correctly parse form data, both URL-encoded and multipart.

All incoming information are loaded into a dictionary. Data from stdin are completely loaded upfront into the dictionary, referenced by the key 'content'.

This is not meant to be a web framework, only a basic utility to implement CGI in C e.g. for embedded systems.

COMPILING

You need to obtain the dictionary implementation: http://github.com/ndevilla/dict

Copy both source files (dict.c and dict.h) to the main tcgi directory and type 'make' to build libtcgi.a. You can also compile it into your own code by adding tcgi.c and dict.h to your sources.

TESTING

To try it out with a browser: $ make test This creates a CGI program called 'test.cgi' in the current directory, together with a default config file for lighttpd that will serve it on localhost port 9000.

Start lighttpd with: $ lighttpd -f lighttpd.conf And then point your browser to http://localhost:9000

USAGE

Example code can be found at the end of tcgi.c In a nutshell:

#include "tcgi.h"

int main(int argc, char * argv[]) 
{
    dict * cgid ;
    char * content ;

    /* Parse input */
    cgid = tcgi_parse();
    /* Dump all variables to stdout */
    dict_dump(cgid, stdout) ;
    /* Get uploaded content from a POST request */
    content = dict_get(cgid, "content", NULL);
    if (content) {
        printf("uploaded:\n%s\n", content);
    }
    dict_free(cgid);
    return 0 ;
}

License

MIT -- See LICENSE file in the top directory.

N. Devillard Tue Apr 5 15:18:00 CEST 2011

tcgi's People

Contributors

ndevilla avatar

Watchers

 avatar  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.