qs_parse is a library I built for myself for quick and dirty FastCGI programming in C. Parsing the query string is the first step for the server to perform, so I felt a need to have a query string parser that was fast and flexible that I could reach for whenever I feel the need to write web apps in C.

You can browse the code here, or download a tarball here. Or if you're using git and would like to clone it, you can do so with git clone http://www.bartgrantham.com/_projects/qs_parse/.git . It's license is MIT, so feel free to use it however you'd like. The README file is below.


A set of simple and easy functions for parsing URL query strings, such as
those generated in an HTTP GET form submission.

How to Use
These qs_* functions can be used in two different ways:

    A faster version that requires a pre-processing stage and **is destructive
    to the query string**
        - Better for repeated lookups of k/v pairs
        - Does all decoding/processing in-place, so no memory copying
        - Requires an array of pointers to strings to be passed to
          the preprocessing stage
        - Cannot be used where the query string is const
    A slower version that will scan for the given key and will decode the value
    into a user-provided string
        - Doesn't alter the query string so can be used where it is const, or
          cannot be altered
        - Only needs a user-passed char string for copying into
        - Scans the entire qs on each call, so isn't as fast as qs_k2v()

Since qs_parse()/qs_k2v() alters the query string that is passed to it in a way
that defeats qs_scanvalue(), do not mix these two methods (or if you must,
either don't call qs_scanvalue() after a call to qs_parse() or make a copy of
the query string beforehand)

[note: speed comparisons will be more relevant when the sorting the k/v pairs
code is implemented]

All you really need is qs.h and qs.c.  I've included my test program
("qs_test.c") and a quick program that shows how to use these functions
("qs_example.c").  Also included is a quick Makefile.  If you want to see it
come to life just get all the files and:

# make
# ./qs_example

Bugs, etc.
Please let me know if you find any, or if you have public-domain-license-
friendly enhancements to add.

Public Domain.  I grant *NO* warranties as to the correctness of this code or
it's suitability for it's stated purpose.  In using this code, you grant that
I am not responsible for any losses incurred as a result of this code.

Few things are more enjoyable than the knowledge that you've helped another
person. If you do use these functions for anything, I'd love to hear about it: