the magic protocol word here
authorAleš Křenek <ljocha@ics.muni.cz>
Tue, 9 Aug 2005 19:27:47 +0000 (19:27 +0000)
committerAleš Křenek <ljocha@ics.muni.cz>
Tue, 9 Aug 2005 19:27:47 +0000 (19:27 +0000)
org.glite.lb.common/src/il_msg.c
org.glite.lb.common/test/il_msg_test.cpp

index a9e3fff..8c6e973 100644 (file)
@@ -7,15 +7,18 @@
 #include <unistd.h>
 #include <stdlib.h>
 
+#define IL_PROTOCOL_MAGIC_WORD "michal"
+
 int 
 encode_il_msg(char **buffer, const char *event)
 {
   int len;
   char *p;
+  char *protocol_magic_word = IL_PROTOCOL_MAGIC_WORD;
 
 
   /* allocate enough room to hold the message */
-  len = 17 + len_string((char*)event);
+  len = 17 + len_string(protocol_magic_word) + len_string((char*)event);
   if((*buffer = malloc(len)) == NULL) {
     return(-1);
   }
@@ -27,6 +30,7 @@ encode_il_msg(char **buffer, const char *event)
   p += 17;
 
   /* write rest of the message */
+  p = put_string(p, protocol_magic_word);
   p = put_string(p, (char*)event);
 
   return(p - *buffer);
@@ -59,8 +63,21 @@ int
 decode_il_msg(char **event, const char *buf)
 {
   char *p;
+  char *protocol_magic_word=NULL;
+  int magic_word_check_failed = 0;
+
+  /* First check that the protocol 'magic' word is there */
+  p = get_string((char*)buf, &protocol_magic_word);
+  if (protocol_magic_word) {
+    if (strcmp (protocol_magic_word, IL_PROTOCOL_MAGIC_WORD) != 0) {
+      magic_word_check_failed = 1;
+    }
+    free(protocol_magic_word);
+  }
+
+  if (magic_word_check_failed != 0) return (-1);
 
-  p = get_string((char*)buf, event);
+  p = get_string(p, event);
   if(p == NULL) {
     if(*event) { free(*event); *event = NULL; };
     return(-1);
index 6748bdb..230b6f1 100644 (file)
@@ -28,7 +28,7 @@ public:
        }
 
        void testEncodeMsg() {
-               CPPUNIT_ASSERT_EQUAL(len_msg, 26);
+               CPPUNIT_ASSERT_EQUAL(len_msg, 35);
                CPPUNIT_ASSERT(buffer_msg != NULL);
                CPPUNIT_ASSERT(!strncmp(buffer_msg, msg, len_msg));
        }
@@ -68,9 +68,9 @@ public:
                char *s;
 
                l = read_il_data(&s, test_reader);
-               CPPUNIT_ASSERT_EQUAL(l, 9);
+               CPPUNIT_ASSERT_EQUAL(l, 18);
                CPPUNIT_ASSERT(s != NULL);
-               CPPUNIT_ASSERT(!strcmp(s, "6 zprava\n"));
+               CPPUNIT_ASSERT(!strcmp(s, "6 michal\n6 zprava\n"));
                free(s);
        }
 
@@ -87,7 +87,7 @@ private:
        }
 };
 
-const char *IlMsgTest::msg = "               9\n6 zprava\n";
+const char *IlMsgTest::msg = "              18\n6 michal\n6 zprava\n";
 const char *IlMsgTest::rep = "              14\n10\n20\n5 chyba\n";
 int IlMsgTest::pos;