Giter VIP home page Giter VIP logo

a-cgi-library's Introduction

Overview of A CGI Library

ACGI is a key/value CGI parser library written in C, designed to simplify the parsing and handling of CGI data in URLs. There are functions for decoding CGI strings, extracting key-value pairs, and converting them to various data types.

Dependencies

Installation

Clone the library and change to the directory

git clone https://github.com/contactandyc/a-cgi-library.git
cd a-cgi-library

Build and install the library

mkdir -p build
cd build
cmake ..
make
make install

An Example

#include <stdio.h>
#include "a-cgi-library/acgi.h"
#include "a-memory-library/aml_pool.h"

int main() {
    // Sample CGI query string
    const char* cgi_str = "name=John+Doe&age=30&is_student=false";

    // Create a memory pool for memory management (required for acgi)
    aml_pool_t *pool = aml_pool_init(1024);

    // Initialize a CGI object
    acgi_t *cgi = acgi_init(pool, cgi_str);

    // Extract data from the CGI query
    const char* name = acgi_str(cgi, "name", "unknown");
    int age = acgi_int(cgi, "age", -1);
    bool is_student = acgi_bool(cgi, "is_student", false);

    // Print the values
    printf("Name: %s\n", name);
    printf("Age: %d\n", age);
    printf("Is Student: %s\n", is_student ? "true" : "false");

    // Clean up
    aml_pool_destroy(pool);
    return 0;
}

Core Functions

  • acgi_init: Initializes a CGI object using a memory pool.
  • acgi_to_json: Converts CGI data to a JSON object.
  • acgi_query: Retrieves the original CGI query.

Data Type Conversion

  • acgi_strs: Returns a NULL-terminated array of decoded values for a given key.
  • acgi_str: Retrieves the first decoded string for a given key.
  • acgi_bool: Converts the first decoded string of a key to a boolean.
  • acgi_int: Converts the first decoded string of a key to an integer.
  • acgi_long: Converts the first decoded string of a key to a long.
  • acgi_double: Converts the first decoded string of a key to a double.
  • acgi_int32: Retrieves a 32-bit integer from the CGI data.
  • acgi_uint32: Retrieves an unsigned 32-bit integer from the CGI data.
  • acgi_int64: Retrieves a 64-bit integer from the CGI data.
  • acgi_uint64: Retrieves an unsigned 64-bit integer from the CGI data.

Decoding Function

  • acgi_decode: Decodes CGI text.

a-cgi-library's People

Contributors

contactandyc avatar

Stargazers

 avatar

Watchers

 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.