httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rasmus Lerdorf <ras...@lerdorf.on.ca>
Subject RE: A couple of Apache architecture questions
Date Fri, 18 Sep 1998 19:11:58 GMT
> Handful of standard modules, yes. However, people converting CGI's to Apache
> modules for speed expect this sort of thing (and almost all of them would
> use it if present).

But there is no such code provided by Apache for CGI's so the CGI must
already have a way to parse a query string.

Seems like a trivial function to me and one that as a module writer I
would want full control over myself.  Something like:

  s = strdup(r->args);
  var = strtok(s,"&");
  while(var) {
    val = strchr(var,"=");
    if(val) {
      *val++ = '\0';
      urldecode(var,strlen(var));
      urldecode(val,strlen(val));
      /* do something with your var,val pair here */
    }
    var = strtok(NULL, "&");
  }
  free(s);

Note that for cookie data you'd want to split on ";" instead of "&" and
you would get it from a call to table_get(r->subprocess_env,"HTTP_COOKIE")
Post data is split the on "&" as well, but fetching it is very different.

You would need to provide your own urldecode function as well.

I use:

int urldecode(char *str, int len) {
    char *dest = str;
    char *data = str;

    while (len--) {
        if (*data == '+')
            *dest = ' ';
        else if (*data == '%' && len >= 2 && isxdigit((int) *(data + 1))
&& isxdigit((int) *(data + 2))) {
#ifndef CHARSET_EBCDIC
            *dest = (char) php3_htoi(data + 1);
#else
            *dest = os_toebcdic[(char) php3_htoi(data + 1)];
#endif
            data += 2;
            len -= 2;
        } else
            *dest = *data;
        data++;
        dest++;
    }
    *dest = '\0';
    return dest - str;
}

-Rasmus


Mime
View raw message