ObjectiveCGI Class

ObjectiveCGI is a very simple Objective C class that can parse Common Gateway Interface query strings delivered by POST (via STDIN) or GET (via ENVIRONMENT) requests and return them as key/value pairs in an NSDictionary.



#import <Foundation/Foundation.h>
#import "ObjectiveCGI.h"

int main (int argc, const char * argv[]) 
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    // Create the CGI object
    ObjectiveCGI *cgi = [[ObjectiveCGI alloc] init];

    NSDictionary *params = [cgi getParams];
    NSEnumerator *enumerator = [params keyEnumerator];
    id key;

    printf("Content-type: text/plain\n\n");

    // Print out each key value pair as plain text
    while ((key = [enumerator nextObject])) 
        printf("%s=%s",[key cString], 
                       [[params objectForKey: key] cString]);  
    // Release the CGI object
    [cgi release];
    return 0;