commit: r248 - trunk/daemon

[email protected]
Newsgroups gmane.network.spread.cvs
Message-ID <[email protected]>
Author: jonathan
Date: 2005-07-15 11:43:00 -0400 (Fri, 15 Jul 2005)
New Revision: 248

Modified:
   trunk/daemon/configuration.c
Log:
Add spread daemon version number to configuration hash. 
This will prevent daemons with different version from inter-operating.



Modified: trunk/daemon/configuration.c
===================================================================
--- trunk/daemon/configuration.c	2005-07-15 15:42:01 UTC (rev 247)
+++ trunk/daemon/configuration.c	2005-07-15 15:43:00 UTC (rev 248)
@@ -266,12 +266,52 @@
         return(need_partition);
 }
 
+/* conf_convert_version_to_string()
+ * char * segstr : output string
+ * int strsize : length of output string space
+ * int return : length of string written or -1 if error (like string not have room)
+ * 
+ *
+ * The string will have appended to it the spread version number in the following format.
+ *
+ * "Version: 3.17.3\n"
+ *
+ */
+static  int    conf_convert_version_to_string(char *segstr, int strsize)
+{
+    size_t      curlen = 0;
+    char        temp_str[30];
+
+    sprintf(temp_str, "Version: %d.%d.%d", 
+            SP_MAJOR_VERSION,
+            SP_MINOR_VERSION,
+            SP_PATCH_VERSION );
+
+    strncat( segstr, temp_str, strsize - curlen);
+    curlen += strlen(temp_str);
+
+    /* terminate each segment by a newline */
+    strncat( segstr, "\n", strsize - curlen);
+    curlen += 1;
+
+    if (curlen > strsize) {
+        /* ran out of space in string -- should never happen. */
+        Alarmp( SPLOG_ERROR, CONF, "The conf hash string is too long! %d characters attemped is more then %d characters allowed", curlen, strsize);
+        Alarmp( SPLOG_ERROR, CONF, "The error occured when adding the version number. Successful string was: %s\n", segstr);
+        return(-1);
+    }
+
+    Alarmp( SPLOG_DEBUG, CONF, "The version string is %d characters long:\n%s", curlen, segstr);
+    return(curlen);
+}
+
 void	Conf_load_conf_file( char *file_name, char *my_name )
 {
         struct hostent  *host_ptr;
 	char	machine_name[256];
 	char	ip[16];
 	int	i,j;
+        int     added_len;
         unsigned int name_len;
         char    configfile_location[MAXPATHLEN];
 
@@ -327,11 +367,18 @@
             }
         }
 
+        /* Add Spread daemon version number to hash string */
+        added_len = conf_convert_version_to_string(&ConfStringRep[ConfStringLen], MAX_CONF_STRING - ConfStringLen );
+        if (added_len == -1 )
+            Alarmp( SPLOG_FATAL, CONF, "Failed to update string with version number!\n");
+        ConfStringLen += added_len;
+
         /* calculate hash value of configuration. 
          * This daemon will only work with other daemons who have an identical hash value.
          */
         Config->hash_code = conf_hash_string(ConfStringRep, ConfStringLen);
-        Alarmp(SPLOG_DEBUG, CONF, "Hash value for this configuration is: %u\n", Config->hash_code);
+        Alarmp( SPLOG_DEBUG, CONF, "Full hash string is %d characters long:\n%s", ConfStringLen, ConfStringRep);
+        Alarmp( SPLOG_DEBUG, CONF, "Hash value for this configuration is: %u\n", Config->hash_code);
 
         /* Match my IP address to entry in configuration file */
 	if( my_name == NULL ){
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.