I tried to attach this solution to the bug report, but I get this error:

You did not enter a valid attachment number.


Anyhow, this is a solution for bug 232:

http://bugzilla.ganglia.info/cgi-bin/bugzilla/show_bug.cgi?id=232

As a consequence of applying this patch:
- whenever an RRD is created/updated, the hostname directory name will be converted to lowercase
- any capitalization can be used with the `h' parameter to the web interface
- whenever gmetad receives a hostname in the XML, it will use a non-case-sensitive comparison to decide if it already has data for that host - the XML emitted by gmetad will show the capitalization that was received in the XML, not the lowercase version

Anyone applying this patch needs to rename all their hostname directories to lowercase.

Regards,

Daniel
Index: lib/hash.c
===================================================================
--- lib/hash.c	(revision )
+++ lib/hash.c	(revision )
@@ -1,4 +1,5 @@
 /* $Id: hash.c 1146 2008-03-28 16:40:27Z bnicholes $ */
+#include <ctype.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
@@ -171,6 +172,18 @@
    free( hash );
 }
 
+int
+hash_get_flags (hash_t *hash)
+{
+   return hash->flags;
+}
+
+void
+hash_set_flags (hash_t *hash, int flags)
+{
+   hash->flags = flags;
+}
+
 size_t
 hashval ( datum_t *key, hash_t *hash )
 {
@@ -181,13 +194,35 @@
    if ( hash == NULL || key == NULL || key->data == NULL || key->size <= 0 )
       return 0;
 
-   hash_val = ((unsigned char *)key->data)[0];
-   for ( i = 0; i < key->size ; i++ )
-      hash_val = ( hash_val * 32 + ((unsigned char *)key->data)[i]) % hash->size;
+   if(hash->flags & HASH_FLAG_IGNORE_CASE)
+   {
+      hash_val = tolower(((unsigned char *)key->data)[0]);
+      for ( i = 0; i < key->size ; i++ )
+         hash_val = ( hash_val * 32 + tolower(((unsigned char *)key->data)[i])) % hash->size; 
+   }
+   else
+   {
+      hash_val = ((unsigned char *)key->data)[0];
+      for ( i = 0; i < key->size ; i++ )
+         hash_val = ( hash_val * 32 + ((unsigned char *)key->data)[i]) % hash->size;
+   }
 
    return hash_val;
 }
 
+int
+hash_keycmp(hash_t *hash, datum_t *key1, datum_t *key2)
+{
+   if(hash->flags & HASH_FLAG_IGNORE_CASE)
+   {
+      return strncasecmp(key1->data, key2->data, key1->size);
+   }
+   else
+   {
+      return strncmp(key1->data, key2->data, key1->size);
+   }
+}
+
 datum_t *
 hash_insert (datum_t *key, datum_t *val, hash_t *hash)
 {
@@ -241,7 +276,7 @@
          if( bucket->key->size != key->size )
             continue;
 
-         if(! strncmp(bucket->key->data, key->data, key->size) )
+         if(! hash_keycmp(hash, bucket->key, key) )
             {
                /* New data for an existing key */
 
@@ -316,7 +351,7 @@
       if ( key->size != bucket->key->size )
          continue;
  
-      if (! memcmp( key->data, bucket->key->data, key->size ))
+      if (! hash_keycmp( hash, key, bucket->key))
          {
             val =  datum_dup( bucket->val );
             READ_UNLOCK(hash, i);
@@ -349,7 +384,7 @@
        bucket != NULL; last = bucket, bucket = bucket->next)
     {
       if (bucket->key->size == key->size 
-          && !strncmp (key->data, bucket->key->data, key->size))
+          && !hash_keycmp(hash, key, bucket->key))
         {
           if (last != NULL)
             {
Index: lib/hash.h
===================================================================
--- lib/hash.h	(revision )
+++ lib/hash.h	(revision )
@@ -13,6 +13,8 @@
 #define WRITE_UNLOCK(__hash, __nodeval) \
 pthread_rdwr_wunlock_np( &(__hash->node[__nodeval]->rwlock))
 
+#define HASH_FLAG_IGNORE_CASE 1
+
 typedef struct 
 {
    void        *data;
@@ -39,12 +41,16 @@
 {
   size_t size;
   node_t **node;
+  int flags;
 }
 hash_t;
 
 hash_t  *hash_create (size_t size);
 void     hash_destroy(hash_t *hash);
 
+int      hash_get_flags(hash_t *hash);
+void     hash_set_flags(hash_t *hash, int flags);
+
 datum_t *hash_insert (datum_t *key, datum_t *val, hash_t *hash);
 datum_t *hash_delete (datum_t *key, hash_t *hash);
 
Index: gmetad/process_xml.c
===================================================================
--- gmetad/process_xml.c	(revision )
+++ gmetad/process_xml.c	(revision )
@@ -313,6 +313,7 @@
                err_msg("Could not create hash table for cluster %s", name);
                return 1;
             }
+         hash_set_flags(source->authority, HASH_FLAG_IGNORE_CASE);
 
          source->metric_summary = hash_create(DEFAULT_METRICSIZE);
          if (!source->metric_summary)
@@ -438,6 +439,14 @@
     */
    xmldata->hostname = realloc(xmldata->hostname, strlen(name)+1);
    strcpy(xmldata->hostname, name);
+
+   /* Convert name to lower case - host names can't be
+    * case sensitive
+    */
+   /*for(i = 0; name[i] != 0; i++)
+       xmldata->hostname[i] = tolower(name[i]);
+   xmldata->hostname[i] = 0; */
+
    hashkey.data = (void*) name;
    hashkey.size =  strlen(name) + 1;
 
Index: gmetad/rrd_helpers.c
===================================================================
--- gmetad/rrd_helpers.c	(revision )
+++ gmetad/rrd_helpers.c	(revision )
@@ -179,6 +179,7 @@
 {
    char rrd[ PATHSIZE ];
    char *summary_dir = "__SummaryInfo__";
+   int i;
 
    /* Build the path to our desired RRD file. Assume the rootdir exists. */
    strcpy(rrd, gmetad_config.rrd_rootdir);
@@ -191,7 +192,10 @@
 
    if (host) {
       strncat(rrd, "/", PATHSIZE);
+      i = strlen(rrd);
       strncat(rrd, host, PATHSIZE);
+      for( ; rrd[i] != 0; i++)
+         rrd[i] = tolower(rrd[i]);
       my_mkdir( rrd );
    }
    else {
Index: web/get_context.php
===================================================================
--- web/get_context.php	(revision )
+++ web/get_context.php	(working copy)
@@ -21,7 +21,7 @@
 $gridname = isset($_GET["G"]) ?
     escapeshellcmd( clean_string( rawurldecode($_GET["G"]) ) ) : NULL;
 $hostname = isset($_GET["h"]) ?
-    escapeshellcmd( clean_string( rawurldecode($_GET["h"]) ) ) : NULL;
+    strtolower( escapeshellcmd( clean_string( rawurldecode($_GET["h"]) ) ) ) : NULL;
 $range = isset( $_GET["r"] ) && in_array($_GET["r"], array_keys( $time_ranges ) ) ?
     escapeshellcmd( rawurldecode($_GET["r"])) : NULL;
 $metricname = isset($_GET["m"]) ?
------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Ganglia-developers mailing list
Ganglia-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ganglia-developers

Reply via email to