/* * demo4.c: sample module showing URL-based redirection. */ #include <unistd.h> #include "tuxmodule.h" #define REPLY_HEADER "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n" #define REPLY_HEADER_LEN (sizeof(REPLY_HEADER)-1) #define EXT ".shtml" #define EXT_LEN (sizeof(EXT)-1) int TUXAPI_handle_events (user_req_t *req) { int ret = TUX_RETURN_USERSPACE_REQUEST; int len; len = strlen(req->objectname); if ((len > EXT_LEN) && !memcmp(req->objectname + len - EXT_LEN, EXT, EXT_LEN)) return tux(TUX_ACTION_REDIRECT_REQ, req); if (!req->objectname[0] && !req->query[0]) return tux(TUX_ACTION_FINISH_CLOSE_REQ, req); switch (req->event) { /* * A new request starts with event code 0. */ case 0: write (req->sock, REPLY_HEADER, REPLY_HEADER_LEN); req->http_status = 200; /* * set req->objectname is to the requested object * in the query string if it exists. This simulates * simple static GETs. Otherwise just send the * requested object. */ if (req->query[0]) strcpy(req->objectname, req->query); req->event = 1; ret = tux(TUX_ACTION_GET_OBJECT, req); break; case 1: req->event = 2; ret = tux(TUX_ACTION_SEND_OBJECT, req); break; case 2: ret = tux(TUX_ACTION_FINISH_CLOSE_REQ, req); break; } return ret; }