| iMatix home page
| << | < | > | >>
SFL Logo SFL
Version 1.91

 

cgi_parse_query_vars

#include "sflhttp.h"
int
cgi_parse_query_vars (
    SYMTAB *symtab,
    const char *query,
    const char *prefix)

Synopsis

Parses a CGI query string and loads the resulting variables into an existing symbol table, optionally prefixing each name with a string. Returns the number of variables loaded. The prefix can be NULL or empty if not required.

Source Code - (sflhttp.c)

{
    static char
        query_var [LINE_MAX];           /*  Query variable name              */
    char
        **query_vars,                   /*  Query as string table            */
        *equals;                        /*  Equal sign in variable           */
    int
        string_nbr,                     /*  Index into string table          */
        variables = 0;                  /*  Number of variables loaded       */

    ASSERT (symtab);
    if ((query_vars = http query2strt (query)) == NULL)
        return (0);                     /*  Not enough memory                */

    for (string_nbr = 0; query_vars [string_nbr]; string_nbr++)
      {
        equals = strchr (query_vars [string_nbr], '=');
        if (equals)
          {
            *equals = '\0';             /*  Cut into two strings             */
            if (prefix && *prefix)
              {
                ASSERT (strlen (query_vars [string_nbr])
                      + strlen (prefix) < LINE_MAX);
                xstrcpy (query_var, prefix, query_vars [string_nbr], NULL);
              }
            else
                strcpy (query_var, query_vars [string_nbr]);

            sym assume symbol (symtab, query_var, equals + 1);
            *equals = '=';              /*  Restore previous state           */
            variables++;                /*  Count this variable              */
          }
      }
    strtfree (query_vars);
    return (variables);
}

| << | < | > | >> iMatix Copyright © 1996-98 iMatix