]> granicus.if.org Git - apache/blobdiff - modules/metadata/mod_unique_id.c
Update the copyright year in all .c, .h and .xml files
[apache] / modules / metadata / mod_unique_id.c
index 6423945655d1e36d681b257501fe603c441b5205..4d445a6ab1c03887187c1e374c161d909206d93e 100644 (file)
@@ -1,59 +1,17 @@
-/* ====================================================================
- * The Apache Software License, Version 1.1
+/* Copyright 1999-2006 The Apache Software Foundation or its licensors, as
+ * applicable.
  *
- * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
- * reserved.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
  *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
+ *     http://www.apache.org/licenses/LICENSE-2.0
  *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- *    if any, must include the following acknowledgment:
- *       "This product includes software developed by the
- *        Apache Software Foundation (http://www.apache.org/)."
- *    Alternately, this acknowledgment may appear in the software itself,
- *    if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "Apache" and "Apache Software Foundation" must
- *    not be used to endorse or promote products derived from this
- *    software without prior written permission. For written
- *    permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache",
- *    nor may "Apache" appear in their name, without prior written
- *    permission of the Apache Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation.  For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- * Portions of this software are based upon public domain software
- * originally written at the National Center for Supercomputing Applications,
- * University of Illinois, Urbana-Champaign.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  */
 
 /*
@@ -89,10 +47,10 @@ typedef struct {
  * cannot guarantee the thread_id will be an integer.
  *
  * This code looks like it won't give a unique ID with the new thread logic.
- * It will.  The reason is, we don't increment the counter in a thread_safe 
+ * It will.  The reason is, we don't increment the counter in a thread_safe
  * manner.  Because the thread_index is also in the unique ID now, this does
  * not matter.  In order for the id to not be unique, the same thread would
- * have to get the same counter twice in the same second. 
+ * have to get the same counter twice in the same second.
  */
 
 /* Comments:
@@ -165,7 +123,7 @@ static unique_id_rec cur_unique_id;
 /*
  * Number of elements in the structure unique_id_rec.
  */
-#define UNIQUE_ID_REC_MAX 5 
+#define UNIQUE_ID_REC_MAX 5
 
 static unsigned short unique_id_rec_offset[UNIQUE_ID_REC_MAX],
                       unique_id_rec_size[UNIQUE_ID_REC_MAX],
@@ -175,7 +133,6 @@ static unsigned short unique_id_rec_offset[UNIQUE_ID_REC_MAX],
 static int unique_id_global_init(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *main_server)
 {
     char str[APRMAXHOSTLEN + 1];
-    apr_short_interval_time_t pause;
     apr_status_t rv;
     char *ipaddrstr;
     apr_sockaddr_t *sockaddr;
@@ -242,17 +199,16 @@ static int unique_id_global_init(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *pt
      * If the server is pummelled with restart requests we could possibly end
      * up in a situation where we're starting again during the same second
      * that has been used in previous identifiers.  Avoid that situation.
-     * 
+     *
      * In truth, for this to actually happen not only would it have to restart
      * in the same second, but it would have to somehow get the same pids as
      * one of the other servers that was running in that second. Which would
      * mean a 64k wraparound on pids ... not very likely at all.
-     * 
+     *
      * But protecting against it is relatively cheap.  We just sleep into the
      * next second.
      */
-    pause = (apr_short_interval_time_t)(1000000 - (apr_time_now() % APR_USEC_PER_SEC));
-    apr_sleep(pause);
+    apr_sleep(apr_time_from_sec(1) - apr_time_usec(apr_time_now()));
     return OK;
 }
 
@@ -266,7 +222,7 @@ static void unique_id_child_init(apr_pool_t *p, server_rec *s)
      * physical machine there are multiple servers (i.e. using Listen). But
      * it's guaranteed that none of them will share the same pids between
      * children.
-     * 
+     *
      * XXX: for multithread this needs to use a pid/tid combo and probably
      * needs to be expanded to 32 bits
      */
@@ -295,7 +251,7 @@ static void unique_id_child_init(apr_pool_t *p, server_rec *s)
     /* Some systems have very low variance on the low end of their system
      * counter, defend against that.
      */
-    cur_unique_id.counter = (unsigned short)(tv % APR_USEC_PER_SEC / 10);
+    cur_unique_id.counter = (unsigned short)(apr_time_usec(tv) / 10);
 
     /*
      * We must always use network ordering for these bytes, so that
@@ -328,8 +284,8 @@ static int gen_unique_id(request_rec *r)
      */
     unique_id_rec new_unique_id;
     struct {
-       unique_id_rec foo;
-       unsigned char pad[2];
+        unique_id_rec foo;
+        unsigned char pad[2];
     } paddedbuf;
     unsigned char *x,*y;
     unsigned short counter;
@@ -340,10 +296,10 @@ static int gen_unique_id(request_rec *r)
      * actually called for sub requests, so we don't need to test for
      * them) */
     if (r->prev && (e = apr_table_get(r->subprocess_env, "REDIRECT_UNIQUE_ID"))) {
-       apr_table_setn(r->subprocess_env, "UNIQUE_ID", e);
-       return DECLINED;
+        apr_table_setn(r->subprocess_env, "UNIQUE_ID", e);
+        return DECLINED;
     }
-    
+
     new_unique_id.in_addr = cur_unique_id.in_addr;
     new_unique_id.pid = cur_unique_id.pid;
     new_unique_id.counter = cur_unique_id.counter;
@@ -367,7 +323,7 @@ static int gen_unique_id(request_rec *r)
      */
     x[k++] = '\0';
     x[k++] = '\0';
-    
+
     /* alloc str and do the uuencoding */
     str = (char *)apr_palloc(r->pool, unique_id_rec_size_uu + 1);
     k = 0;
@@ -397,7 +353,7 @@ static void register_hooks(apr_pool_t *p)
 {
     ap_hook_post_config(unique_id_global_init, NULL, NULL, APR_HOOK_MIDDLE);
     ap_hook_child_init(unique_id_child_init, NULL, NULL, APR_HOOK_MIDDLE);
-    ap_hook_post_read_request(gen_unique_id, NULL, NULL, APR_HOOK_MIDDLE); 
+    ap_hook_post_read_request(gen_unique_id, NULL, NULL, APR_HOOK_MIDDLE);
 }
 
 module AP_MODULE_DECLARE_DATA unique_id_module = {