PUD: also setup the cache for DNS nodeIdType
authorFerry Huberts <ferry.huberts@pelagic.nl>
Thu, 2 Feb 2012 10:25:59 +0000 (11:25 +0100)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Tue, 14 Feb 2012 13:32:57 +0000 (14:32 +0100)
Signed-off-by: Ferry Huberts <f.huberts@mindef.nl>
lib/pud/src/configuration.c
lib/pud/wireformat/include/OlsrdPudWireFormat/wireFormat.h
lib/pud/wireformat/src/wireFormat.c

index 0663731..d5d07e8 100644 (file)
@@ -326,8 +326,16 @@ static bool setupNodeIdBinaryString(void) {
                        PUD_NODE_ID_NAME, &report[0], sizeof(report));
        if (invalidChars) {
                pudError(false, &report[0]);
+               return false;
+       }
+
+       /* including trailing \0 */
+       if (setupNodeIdBinaryBufferForOlsrCache(&nodeId[0], nodeIdLength + 1)) {
+               return true;
        }
-       return !invalidChars;
+
+       pudError(false, "%s value \"%s\" is too long", PUD_NODE_ID_NAME, getNodeId());
+       return false;
 }
 
 /**
index 9acc27c..76e5882 100644 (file)
@@ -874,6 +874,7 @@ static inline void setPositionUpdateHdop(PudOlsrPositionUpdate * olsrGpsMessage,
 bool setupNodeIdNumberForOlsrCache(/*const char * nodeIdParameterName,*/
 unsigned long long val, unsigned long long min, unsigned long long max,
                unsigned int bytes);
+bool setupNodeIdBinaryBufferForOlsrCache(void * val, size_t bytes);
 
 /**
  Get the nodeIdType of the position update message
index fec5496..07e9866 100644 (file)
@@ -77,6 +77,28 @@ bool setupNodeIdNumberForOlsrCache(unsigned long long val,
        return false;
 }
 
+/**
+ Setup a nodeId buffer in the cachedNodeIdBuffer.
+
+ @param val
+ The value to setup in the cache
+ @param bytes
+ The number of bytes used by the number in the wire format
+
+ @return
+ - true when the number is valid
+ - false otherwise
+ */
+bool setupNodeIdBinaryBufferForOlsrCache(void * val, size_t bytes) {
+       if (bytes >= PUD_CACHED_NODEID_BUFFER_SIZE) {
+               return false;
+       }
+
+       memcpy(cachedNodeIdBuffer, val, bytes);
+       cachedNodeIdBufferLength = bytes;
+       return true;
+}
+
 /* ************************************************************************
  * Validity Time
  * ************************************************************************ */