Code Monkey home page Code Monkey logo

multipart-parser's Introduction

Multipart Parser

This is a parser written in C for multipart bodies. The code was mostly inspired by joyent/http-parser. The parser does not make any syscalls nor allocations, it does not buffer data except the boundary that you pass to mulpartparser_init() function.

Usage

One multipartparser struct must be initialized every time you need to parse a body. The multipartparser_callbacks struct can be initialized only once and can be used by many parsers at the same time. The code to initialize a multipart parser should be similar to this:

multipartparser_callbacks callbacks;
multipartparser           parser;

multipartparser_callbacks_init(&callbacks); // It only sets all callbacks to NULL.
callbacks.on_body_begin = &on_body_begin;
callbacks.on_part_begin = &on_part_begin;
callbacks.on_header_field = &on_header_field;
callbacks.on_header_value = &on_header_value;
callbacks.on_headers_complete = &on_headers_complete;
callbacks.on_data = &on_data;
callbacks.on_part_end = &on_part_end;
callbacks.on_body_end = &on_body_end;

multipartparser_init(&parser, boundary);
parser->data = my_data;

When there is data to parse call the multipart parser like this:

size_t nparsed;

nparsed = multipartparser_execute(&parser, &callbacks, data, size);
if (nparsed != size) {
    /* parse error */
}

Callbacks

See joyent/http-parser's README to understand how to use callbacks especially for on_header_field and on_header_value.

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.