httpd-test-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From grega...@apache.org
Subject cvs commit: httpd-test/specweb99/specweb99-2.0 mod_specweb99.c
Date Thu, 17 Oct 2002 21:39:32 GMT
gregames    2002/10/17 14:39:32

  Modified:    specweb99/specweb99-2.0 mod_specweb99.c
  Log:
  Rename specweb99_foo_handler to do_foo, since they are technically not handlers
  any more.
  
  Get rid of a few redundant error checks.  Use common code in the quick handler
  to parse the inbound cookie.
  
  Revision  Changes    Path
  1.9       +39 -90    httpd-test/specweb99/specweb99-2.0/mod_specweb99.c
  
  Index: mod_specweb99.c
  ===================================================================
  RCS file: /home/cvs/httpd-test/specweb99/specweb99-2.0/mod_specweb99.c,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- mod_specweb99.c	16 Oct 2002 15:37:22 -0000	1.8
  +++ mod_specweb99.c	17 Oct 2002 21:39:32 -0000	1.9
  @@ -634,7 +634,7 @@
   }				/* specweb99_module_init */
   
   
  -static int specweb99_hk_handler(request_rec *r)
  +static int do_housekeeping(request_rec *r)
   {
       struct specweb99_module_data *_my =
   	ap_get_module_config(r->server->module_config, &specweb99_module);
  @@ -649,11 +649,13 @@
       const char *docroot = ap_document_root(r);
       apr_uri_t urlrootrec;	/* To parse the urlroot string into */
   
  -    if (strstr(r->args, "command/Fetch") != NULL) {
  +    /* we already know args starts with "command/", so skip over that */
  +    
  +    if (!strncmp(r->args + 8, "Fetch", 5)) {  
   	returnHTMLPageWithFile(r, _my->log_path);
   	return OK;
       }
  -    else if ((data = strstr(r->args, "command/Reset"))) {
  +    else if ((data = strstr(r->args + 8, "Reset"))) {
   	/*
   	 * We are sleeping at least one second - to make sure that any
   	 * fstat() on mtime will actually yield different values - no matter
  @@ -671,7 +673,7 @@
   	 * command/Reset&maxload=[MaxLoad]&pttime=[PointTime]&maxthreads=[
   	 * MaxThreads]&exp=[ExpiredList]&urlroot=[UrlRoot]
   	 */
  -	data += 14;		/* position at start of argument string */
  +	data += 6;		/* position at start of argument string */
   	/* Tokenize argument string */
   	tab = apr_table_make(r->pool, 0);
   
  @@ -796,26 +798,15 @@
   
   
   /***********************************************************************
  - * specweb99_get_handler                                               *
  + * do_standard_get                                                     *
    ***********************************************************************/
   
  -static int specweb99_get_handler(request_rec *r)
  +static int do_standard_get(request_rec *r)
   {
       char *path;
       const char *docroot = ap_document_root(r);
   
       /*
  -     * This should not be tested for every request. Eventually, this code
  -     * will find its way to the housekeeping command handler, but that does
  -     * not exist yet.
  -     */
  -
  -    if(r->args == NULL) {
  -        returnHTMLPageWithMessage(r,"Error: No file argument provided");
  -        return OK;
  -    }
  -
  -    /*
        * Construct the path to our file. Note that using ap_document_root() is
        * not senang. I should do this a subrequest but OTOH that would take
        * time and we don't have time.
  @@ -824,7 +815,7 @@
       returnHTMLPageWithFile(r, path);
   
       return OK;
  -}				/* specweb99_get_handler */
  +}				/* do_standard_get */
   
   
   
  @@ -889,34 +880,21 @@
   
   
   /***********************************************************************
  - * specweb99_cadget_handler                                            *
  + * do_cadget                                                           *
    ***********************************************************************/
   
  -static int specweb99_cadget_handler(request_rec *r)
  +static int do_cadget(request_rec *r, int my_user, int last_ad)
   {
       struct specweb99_module_data *_my =
       ap_get_module_config(r->server->module_config, &specweb99_module);
  -    char *cookie_in, *cookie_out, *end;
  +    char *cookie_out;
       const char *docroot = ap_document_root(r);
       char *filename;
  -    int16_t my_user, last_ad, userindex, adindex, expired = 0;
  +    int16_t userindex, adindex, expired = 0;
       u_int32_t userdemographics, combineddemographics;	/* it's a bitmap */
       u_int16_t ad_weight;
   
       /*
  -     * This should not be tested for every request. Eventually, this code
  -     * will find its way to the housekeeping command handler, but that does
  -     * not exist yet.
  -     */
  -    /* Get the cookie */
  -    cookie_in = (char *) apr_table_get(r->headers_in, "Cookie");
  -#ifdef DEBUG
  -    specweb99_debug(r->server, ap_psprintf(r->pool,
  -					"Got cadget request, cookie is: %s",
  -					   cookie_in));
  -#endif
  -
  -    /*
        * XXX Again, ap_document_root is deprecated. I should probably find the
        * document root in my init handler and keep it around.
        */
  @@ -926,35 +904,6 @@
       ap_log_error(APLOG_MARK, APLOG_NOERRNO | APLOG_DEBUG, r->server,
   		 "Full path is '%s'", filename);
   #endif
  -
  -    /*
  -     * Parse Cookie string into MyUser and Last_Ad. The format of the cookie
  -     * is as follows (the order of keys and values is fixed): 
  -     *           1         2         3         4         5 
  -     * 012345678901234567890123456789012345678901234567890123456789
  -     * my_cookie=user_id=[MyUser]&last_ad=[Last_ad]
  -     */
  -    if (!cookie_in) {
  -	ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r->server,
  -		     "Error: expected cookie but found none");
  -	returnHTMLPageWithMessage(r, "Error: expected cookie but found none");
  -	return HTTP_INTERNAL_SERVER_ERROR;
  -    }				/* Is there a cookie */
  -
  -    /* Parse the incoming Cookie data */
  -    /* Format of input: user_id=<x>&last_ad=<y> */
  -    my_user = strtol(cookie_in + 18, &end, 10);
  -    last_ad = atoi(end + 9);	/* We trust that there is something behind
  -				 * the last_ad value to stop the conversion */
  -#ifdef DEBUG
  -    specweb99_debug(r->server, ap_psprintf(r->pool,
  -					"UserID: %d, LastAd: %d, Valid: %s",
  -					   my_user,
  -					   last_ad,
  -					   (cookie_in ==
  -					    end) ? "no" : "yes"));
  -#endif
  -
       /*
        * Calculate UserIndex into User.Personality file UserIndex = MyUser -
        * 10000
  @@ -1092,15 +1041,14 @@
       return NULL;
   }
   
  -static int specweb99_post_handler(request_rec *r)
  +static int do_post(request_rec *r, int uid)
   {
       struct specweb99_module_data *_my =
       ap_get_module_config(r->server->module_config, &specweb99_module);
       const char *urlroot = "<none>";
  -    int dirnum = 0, classnum = 0, filenum = 0, clientnum = 0, uid = 0;
  +    int dirnum = 0, classnum = 0, filenum = 0, clientnum = 0;
       char *filename;
       int posterr;
  -    const char *cookie_in;
       apr_file_t *f;
       char *data = "<none>";
       const char *type, *docroot;
  @@ -1211,23 +1159,6 @@
   	return HTTP_INTERNAL_SERVER_ERROR;
       }
   
  -/*    Parse Cookie string to get MyCookie. The format is as */
  -/*    follows (the order of the keys and values is fixed):*/
  -    /*
  -     *           1         2       
  -     * 012345678901234567890123
  -     * my_cookie=user_id=[MyCookie]&last_ad=[IgnoredField]
  -     */
  -
  -    cookie_in = apr_table_get(r->headers_in, "Cookie");
  -    if (cookie_in == NULL) {
  -	ap_log_error(APLOG_MARK, APLOG_NOERRNO | APLOG_ERR, 0, r->server,
  -		     "No cookie");
  -	returnHTMLPageWithMessage(r, "Invalid Cookie");
  -	return HTTP_INTERNAL_SERVER_ERROR;
  -    }
  -    uid = atoi(cookie_in + 18);
  -
   /*  Filename = [urlroot]/dir[5-digit Dir#]/class[Class#]_[File#]*/
   /*        (for example, the POST input of */
   /*        urlroot=/specweb99/file_set&dir=00123&class=1&num=1&client=10003
*/
  @@ -1308,7 +1239,7 @@
       returnHTMLPageWithFile(r, filename);
   
       return OK;
  -}				/* specweb99_post_handler */
  +}				/* do_post */
   
   static int specweb99_quick_handler(request_rec *r, int lookup)
   {
  @@ -1321,15 +1252,33 @@
       }
       cookie_in = apr_table_get(r->headers_in, "Cookie");
       if (cookie_in) {
  +        int user_id, last_ad;
  +        char *end;
  +#ifdef DEBUG
  +        specweb99_debug(r->server, ap_psprintf(r->pool,
  +					"Got a cookie: %s",
  +					   cookie_in));
  +#endif
  +        /*
  +         * Parse Cookie string into MyUser and Last_Ad(cadget). The format of the 
  +         * cookie is as follows (the order of keys and values is fixed): 
  +         *           1         2         3         4         5 
  +         * 012345678901234567890123456789012345678901234567890123456789
  +         * my_cookie=user_id=[MyUser]&last_ad=[Last_ad]
  +         */
  +        user_id = strtol(cookie_in + 18, &end, 10);
           if (r->method_number == M_GET) {
  -            return specweb99_cadget_handler(r); 
  +            last_ad = atoi(end + 9); /* We trust that there is something behind
  +                                      * the last_ad value to stop the conversion 
  +                                      */
  +            return do_cadget(r, user_id, last_ad); 
           }
  -        return specweb99_post_handler(r); 
  +        return do_post(r, user_id); 
       }
       if (!strncmp(r->args, "command/", 8)) {
  -        return specweb99_hk_handler(r);
  +        return do_housekeeping(r);
       }
  -    return specweb99_get_handler(r);
  +    return do_standard_get(r);
   }                                  /* specweb99_quick_handler    */
   
   static void register_hooks(apr_pool_t * p)
  
  
  

Mime
View raw message