0

When using the code below, the handler will not recognize non file requests (e.g. the request has to contain a file in the www folder). With all other requests main isn't even called, and I have no idea why this is.

int init(int argc, char *argv[])

{
   printf("init\n");

   *(u32 *)get_env(argv, US_HANDLER_STATES) = (1L << HDL_AFTER_ACCEPT) | (1L << HDL_AFTER_READ) | (1L << HDL_BEFORE_WRITE);

   return 0;
}

void clean(int argc, char *argv[])
{
   printf("clean\n");
}

int main(int argc, char *argv[])
{
   printf("%s\n", (char *)get_env(argv, REQUEST));

   return 255;
}

Request: 127.0.0.1/index.html
Prints: GET /index.html

Request: 127.0.0.1/favicon.ico
Prints: GET /favicon.ico

Request: 127.0.0.1/index
Prints: N/A

Thanks for any assistance.

  • Which version of G-wan are you using? What about your development environment? The most recent version of G-wan is known for being not compatible with many distros. If that is your case, then your best bet is either use the old G-wan 3.3, or try to match the dev environment of the G-wan team (I believe it is Ubuntu 10.04) – Nagi Jan 13 '13 at 05:41
  • My bad, I'm running Ubuntu 12.10, and glibc version 2.15. `root@desktop-Ubuntu:~ # /lib/x86_64-linux-gnu/libc.so.6 GNU C Library (Ubuntu EGLIBC 2.15-0ubuntu20) stable release version 2.15, by Roland McGrath et al. Compiled by GNU CC version 4.6.3 20120918 (prerelease). Compiled on a Linux 3.5.4 system on 2012-10-04. Available extensions: crypt add-on version 2.1 by Michael Glad and others GNU Libidn by Simon Josefsson Native POSIX Threads Library by Ulrich Drepper et al BIND-8.2.3-T5B libc ABIs: UNIQUE IFUNC` – user1956556 Jan 13 '13 at 13:02

1 Answers1

0

Handlers get any request, valid or not, about files or otherwise.

Your handler is incorrect. Since you ask notifications BEFORE HTTP and HTML parsing took place:

   *(u32*)get_env(argv, US_HANDLER_STATES) = 
      (1L << HDL_AFTER_ACCEPT) 
    | (1L << HDL_AFTER_READ) 
    | (1L << HDL_BEFORE_WRITE);

...you should absolutely check that the REQUEST is available before displaying it with printf():

   const char *req = (char*)get_env(argv, REQUEST);
   printf("%s\n", req ? req : "not parsed yet");

The code that you have posted above will crash, every single time, because the HTTP REQUEST value is NULL (not available yet) at the time the connection is ACCEPTED, or the request is READ.

Gil
  • 3,279
  • 1
  • 15
  • 25