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 Fri, 24 Jan 2003 21:10:17 GMT
gregames    2003/01/24 13:10:17

  Modified:    specweb99/specweb99-2.0 mod_specweb99.c
  Log:
  get rid of time() syscalls in requests with cookies (custom ad GETs and POSTs)
  
  suggested by: Madhu Mathihalli
  
  Revision  Changes    Path
  1.21      +21 -16    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.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- mod_specweb99.c	22 Jan 2003 21:47:37 -0000	1.20
  +++ mod_specweb99.c	24 Jan 2003 21:10:16 -0000	1.21
  @@ -315,7 +315,8 @@
    ***********************************************************************/
   
   static apr_int16_t checkUPFile(struct server_rec *sv, struct request_rec *r,
  -                               struct specweb99_module_data * _my)
  +                               struct specweb99_module_data * _my,
  +                               time_t now)
   {
       apr_finfo_t s;
       apr_status_t rv;
  @@ -323,9 +324,7 @@
       apr_int16_t numrecords, up_uid;
       int e = 0;
       char up_record[UPRLENGTH + 1];
  -    apr_time_t now;
   
  -    now = time(NULL);
       if (_my->check == now) {
           return 0;
       }
  @@ -864,7 +863,7 @@
    * do_cadget                                                           *
    ***********************************************************************/
   
  -static int do_cadget(request_rec *r, int my_user, int last_ad)
  +static int do_cadget(request_rec *r, int my_user, int last_ad, time_t now)
   {
       struct specweb99_module_data *_my =
       ap_get_module_config(r->server->module_config, &specweb99_module);
  @@ -895,7 +894,7 @@
        * Find User.Personality record using UserIndex
        */
   
  -    if (checkUPFile(r->server, r, _my)) {
  +    if (checkUPFile(r->server, r, _my, now)) {
           ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r->server,
                        "User personality check failed.");
           returnHTMLPageWithMessage(r,
  @@ -956,12 +955,12 @@
               }
           }
           expired =
  -         ((time((time_t *) NULL) > _my->cad[adindex].expiration_time))  ? 1 : 0;
  +         (now > _my->cad[adindex].expiration_time)  ? 1 : 0;
   
           ap_log_error(APLOG_MARK, APLOG_INFO | APLOG_NOERRNO, 0, r->server,
                        "Found ad %d : expire %s (%d > %d)",
                        adindex, expired ? "yes" : "no",
  -                     (int) time((time_t *) NULL),
  +                     (int) now,
                        _my->cad[adindex].expiration_time);
   
           cookie_out = apr_psprintf(r->pool,
  @@ -981,17 +980,16 @@
   
   static char *_log_and_write(struct request_rec *r, apr_file_t * f,
                               char *filename, const char *urlroot, int dirnum,
  -                            int classnum, int filenum, int clientnum, int uid)
  +                            int classnum, int filenum, int clientnum, int uid,
  +                            time_t stamp)
   {
       pid_t pid;
  -    time_t stamp;
       apr_uint32_t recnum;
       char recnumstr[12];             /* ten wide plus return plus \0 */
       apr_size_t l;
       apr_off_t zero = 0;
       apr_status_t rv;
   
  -    stamp = time(NULL);
       pid = getpid();
   
       if ((rv = apr_file_read_full(f, recnumstr, 11, &l)) != APR_SUCCESS)
  @@ -1020,7 +1018,7 @@
       return NULL;
   }
   
  -static int do_post(request_rec *r, int uid)
  +static int do_post(request_rec *r, int uid, time_t now)
   {
       struct specweb99_module_data *_my =
       ap_get_module_config(r->server->module_config, &specweb99_module);
  @@ -1163,7 +1161,7 @@
       else {
           char *msg =
           _log_and_write(r, f, filename, urlroot, dirnum, classnum, filenum,
  -                       clientnum, uid);
  +                       clientnum, uid, now);
           if (msg) {
               rv = APR_OS_START_USEERR;
               ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server, msg);
  @@ -1218,10 +1216,17 @@
       if (cookie_in) {
           int user_id, last_ad;
           char *end;
  +        time_t cur_time;
   #ifdef DEBUG
           specweb99_debug(r->server, ap_psprintf(r->pool,
  -                       "Got a cookie: %s", cookie_in));
  +                        "Got a cookie: %s", cookie_in));
   #endif
  +        /* 
  +         * get the current time in seconds.  This assumes the division done
  +         * by the macro is cheaper than a time() syscall (not verified)
  +         */
  +        cur_time = apr_time_sec(r->request_time);
  +    
           /*
            * 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): 
  @@ -1234,9 +1239,9 @@
               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 do_cadget(r, user_id, last_ad, cur_time);
           }
  -        return do_post(r, user_id);
  +        return do_post(r, user_id, cur_time);
       }
       if (!strncmp(r->args, "command/", 8)) {
           return do_housekeeping(r);
  
  
  

Mime
View raw message