PUD: add isValidNodeIdType function to wireformat library
authorFerry Huberts <f.huberts@mindef.nl>
Tue, 11 Oct 2011 13:33:46 +0000 (15:33 +0200)
committerFerry Huberts <f.huberts@mindef.nl>
Tue, 18 Oct 2011 10:08:27 +0000 (12:08 +0200)
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 b50908b..349c9e1 100644 (file)
@@ -179,24 +179,10 @@ int setNodeIdType(const char *value, void *data __attribute__ ((unused)),
                return true;
        }
 
-       switch (nodeIdTypeNew) {
-               case PUD_NODEIDTYPE_MAC:
-               case PUD_NODEIDTYPE_MSISDN:
-               case PUD_NODEIDTYPE_TETRA:
-               case PUD_NODEIDTYPE_DNS:
-               case PUD_NODEIDTYPE_IPV4:
-               case PUD_NODEIDTYPE_IPV6:
-               case PUD_NODEIDTYPE_MMSI:
-               case PUD_NODEIDTYPE_URN:
-               case PUD_NODEIDTYPE_192:
-               case PUD_NODEIDTYPE_193:
-               case PUD_NODEIDTYPE_194:
-                       break;
-
-               default:
-                       pudError(false, "Configured %s (%llu) is reserved", valueName,
-                                       nodeIdTypeNew);
-                       return true;
+       if (!isValidNodeIdType(nodeIdTypeNew)) {
+               pudError(false, "Configured %s (%llu) is reserved", valueName,
+                               nodeIdTypeNew);
+               return true;
        }
 
        nodeIdType = nodeIdTypeNew;
index 95ce526..89ba219 100644 (file)
@@ -283,6 +283,12 @@ typedef struct _UplinkMessage {
  * FUNCTIONS
  * ************************************************************************ */
 
+/*
+ * NodeIdType
+ */
+
+bool isValidNodeIdType(unsigned long long nodeIdType);
+
 /*
  * Validity Time
  */
index 67eca25..654cf1d 100644 (file)
@@ -1,6 +1,26 @@
 #include <OlsrdPudWireFormat/wireFormat.h>
 #include <OlsrdPudWireFormat/compiler.h>
 
+bool isValidNodeIdType(unsigned long long nodeIdType) {
+       switch (nodeIdType) {
+                       case PUD_NODEIDTYPE_MAC:
+                       case PUD_NODEIDTYPE_MSISDN:
+                       case PUD_NODEIDTYPE_TETRA:
+                       case PUD_NODEIDTYPE_DNS:
+                       case PUD_NODEIDTYPE_IPV4:
+                       case PUD_NODEIDTYPE_IPV6:
+                       case PUD_NODEIDTYPE_MMSI:
+                       case PUD_NODEIDTYPE_URN:
+                       case PUD_NODEIDTYPE_192:
+                       case PUD_NODEIDTYPE_193:
+                       case PUD_NODEIDTYPE_194:
+                               return true;
+
+                       default:
+                               return false;
+               }
+}
+
 /* ************************************************************************
  * VALIDITY TIME CACHE
  * ************************************************************************ */