Re: [devel] [PATCH 1 of 2] IMM: add support for forwards compatibility of attribute flags [#116]

2014-02-24 Thread Anders Bjornerstedt
Ack from me 4.4/4.5  patch 1  with same adjustment to the comment.

/AndersBj


--
Flow-based real-time traffic analytics software. Cisco certified tool.
Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer
Customize your own dashboards, set traffic alerts and generate reports.
Network behavioral analysis & security monitoring. All-in-one tool.
http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk
___
Opensaf-devel mailing list
Opensaf-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensaf-devel


Re: [devel] [PATCH 1 of 2] IMM: add support for forwards compatibility of attribute flags [#116]

2014-02-24 Thread Anders Bjornerstedt
Ack from me 4.3 patch 1  with same adjustment to the comment marked below.

Zoran Milinkovic wrote:
>  osaf/libs/common/immsv/immpbe_dump.cc  |2 +-
>  osaf/services/saf/immsv/immloadd/imm_loader.cc |  140 
> -
>  osaf/services/saf/immsv/immnd/ImmModel.cc  |   36 +++--
>  osaf/services/saf/immsv/immnd/ImmSearchOp.cc   |2 +-
>  osaf/services/saf/immsv/immnd/ImmSearchOp.hh   |4 +-
>  5 files changed, 165 insertions(+), 19 deletions(-)
>
>
> Add support for 64-bit attribute flags to IMM service.
> If immload finds unknown attribute flag, immload will try to find the 
> attribute flag in the schema defined in the top element of the loading IMM 
> XML file.
>
> diff --git a/osaf/libs/common/immsv/immpbe_dump.cc 
> b/osaf/libs/common/immsv/immpbe_dump.cc
> --- a/osaf/libs/common/immsv/immpbe_dump.cc
> +++ b/osaf/libs/common/immsv/immpbe_dump.cc
> @@ -873,7 +873,7 @@ ClassInfo* classToPBE(std::string classN
>   LOG_ER("Failed to bind attr_type with error code: %d", 
> rc);
>   goto bailout;
>   }
> - if((rc = sqlite3_bind_int(stmt, 4, (*p)->attrFlags)) != 
> SQLITE_OK) {
> + if((rc = sqlite3_bind_int64(stmt, 4, (*p)->attrFlags)) != 
> SQLITE_OK) {
>   LOG_ER("Failed to bind attr_flags with error code: %d", 
> rc);
>   goto bailout;
>   }
> diff --git a/osaf/services/saf/immsv/immloadd/imm_loader.cc 
> b/osaf/services/saf/immsv/immloadd/imm_loader.cc
> --- a/osaf/services/saf/immsv/immloadd/imm_loader.cc
> +++ b/osaf/services/saf/immsv/immloadd/imm_loader.cc
> @@ -17,7 +17,9 @@
>  
>  #include "imm_loader.hh"
>  #include 
> +#include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -26,6 +28,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  
>  #define MAX_DEPTH 10
>  #define MAX_CHAR_BUFFER_SIZE 8192  //8k
> @@ -111,6 +114,12 @@ typedef struct ParserStateStruct
>  SaImmHandleT ccbHandle;
>  } ParserState;
>  
> +bool isXsdLoaded;
> +std::string xsddir;
> +std::string xsd;
> +typedef std::set AttrFlagSet;
> +AttrFlagSet attrFlagSet;
> +
>  /* Helper functions */
>  
>  static void addToAttrTypeCache(ParserState*, SaImmValueTypeT);
> @@ -874,6 +883,13 @@ static void startElementHandler(void* us
>  else if (strcmp((const char*)name, "imm:IMM-contents") == 0)
>  {
>  state->state[state->depth] = IMM_CONTENTS;
> +char *schema = (char *)getAttributeValue(attrs, (xmlChar 
> *)"noNamespaceSchemaLocation");
> +if(!schema) {
> +schema = (char *)getAttributeValue(attrs, (xmlChar 
> *)"xsi:noNamespaceSchemaLocation");
> +}
> +if(schema) {
> +xsd = schema;
> +}
>  }
>  else
>  {
> @@ -1424,6 +1440,106 @@ static xmlEntityPtr
>  return xmlGetPredefinedEntity(name);
>  }
>  
> +static inline char *getAttrValue(xmlAttributePtr attr) {
> +if(!attr || !attr->children) {
> +return NULL;
> +}
> +
> +return (char *)attr->children->content;
> +}
> +
> +static bool loadXsd(const char *xsdFile) {
> +struct stat st;
> +if(stat(xsdFile, &st)) {
> +if(errno == ENOENT) {
> +LOG_ER("%s does not exist", xsdFile);
> +} else {
> +LOG_ER("stat of %s return error: %d", xsdFile, errno);
> +}
> +
> +return false;
> +}
> +// It should be a file or a directory
> +if(!S_ISREG(st.st_mode)) {
> +LOG_ER("%s is not a file", xsdFile);
> +return false;
> +}
> +
> +xmlNodePtr xsdDocRoot;
> +xmlDocPtr xsdDoc = xmlParseFile(xsdFile);
> +if(!xsdDoc) {
> +return false;
> +}
> +
> +bool rc = true;
> +xmlXPathContextPtr ctx = xmlXPathNewContext(xsdDoc);
> +if(!ctx) {
> +rc = false;
> +goto freedoc;
> +}
> +
> +//Add namespace of the first element
> +xsdDocRoot = xmlDocGetRootElement(xsdDoc);
> +if(xsdDocRoot->ns) {
> +ctx->namespaces = (xmlNsPtr *)malloc(sizeof(xmlNsPtr));
> +ctx->namespaces[0] = xsdDocRoot->ns;
> +ctx->nsNr = 1;
> +}
> +
> +xmlXPathObjectPtr xpathObj;
> +xpathObj = xmlXPathEval((const 
> xmlChar*)"/xs:schema/xs:simpleType[@name=\"attr-flags\"]/xs:restriction/xs:enumeration",
>  ctx);
> +if(!xpathObj || !xpathObj->nodesetval) {
> +rc = false;
> +goto freectx;
> +}
> +
> +xmlElementPtr element;
> +xmlAttributePtr attr;
> +char *value;
> +int size;
> +
> +size = xpathObj->nodesetval->nodeNr;
> +for(int i=0; i +value = NULL;
> +element = (xmlElementPtr)xpathObj->nodesetval->nodeTab[i];
> +attr = element->attributes;
> +while(attr) {
> +if(!strcmp((char *)attr->name, "value")) {
> +value = getAttrValue(attr);
> +}
> +
> +if(value) {
> +break;
> +}
> +
> +

Re: [devel] [PATCH 1 of 2] IMM: add support for forwards compatibility of attribute flags [#116]

2014-02-24 Thread Anders Bjornerstedt
ACK from me 4.2 patch 1 with adjustment to comment, see below.
In principle something about this flag compatibility stuff should also 
go into the README,
but we will have to take that later and separately.

/AndesBJ

Zoran Milinkovic wrote:
>  osaf/services/saf/immsv/immnd/ImmModel.cc|  39 
> ++-
>  osaf/services/saf/immsv/immnd/ImmSearchOp.cc |   2 +-
>  osaf/services/saf/immsv/immnd/ImmSearchOp.hh |   4 +-
>  3 files changed, 35 insertions(+), 10 deletions(-)
>
>
> diff --git a/osaf/services/saf/immsv/immnd/ImmModel.cc 
> b/osaf/services/saf/immsv/immnd/ImmModel.cc
> --- a/osaf/services/saf/immsv/immnd/ImmModel.cc
> +++ b/osaf/services/saf/immsv/immnd/ImmModel.cc
> @@ -72,7 +72,7 @@ struct AttrInfo
>  {
>  AttrInfo():mValueType(0), mFlags(0), mNtfId(0){}
>  SaUint32T   mValueType;
> -SaUint32T   mFlags;
> +SaImmAttrFlagsT mFlags;
>  SaUint32T   mNtfId;
>  ImmAttrValuemDefaultValue;
>  };
> @@ -2219,6 +2219,7 @@ ImmModel::classCreate(const ImmsvOmClass
>  int illegal=0;
>  bool persistentRt = false;
>  bool persistentRdn = false;
> +bool useUnknownFlag = false;
>  ClassInfo* classInfo = NULL;
>  ClassInfo* prevClassInfo = NULL;
>  ClassInfo dummyClass(req->classCategory);
> @@ -2423,7 +2424,10 @@ ImmModel::classCreate(const ImmsvOmClass
>  }
>  }
>  err = attrCreate(classInfo, attr, attrName);
> -if(err != SA_AIS_OK) {
> +if(err == SA_AIS_ERR_NOT_SUPPORTED) {
> +useUnknownFlag = true;
> +err = SA_AIS_OK;
> +} else if(err != SA_AIS_OK) {
>  illegal = 1;
>  }
>  list = list->next;
> @@ -2476,6 +2480,10 @@ ImmModel::classCreate(const ImmsvOmClass
>  goto done;
>  }
>  
> +if(useUnknownFlag) {
> +LOG_NO("At least one attribute in class %s has unsupported attribute 
> flag", className.c_str());
> +}
> +
>  /* All checks passed, now install the class def. */
>  
>  if(!schemaChange) {
> @@ -3054,12 +3062,29 @@ ImmModel::attrCreate(ClassInfo* classInf
>  }
>  }
>  
> -TRACE_5("create attribute '%s'", attrName.c_str());
> +SaImmAttrFlagsT unknownFlags = attr->attrFlags &
> +  ~(SA_IMM_ATTR_MULTI_VALUE |
> +SA_IMM_ATTR_RDN |
> +SA_IMM_ATTR_CONFIG |
> +SA_IMM_ATTR_WRITABLE |
> +SA_IMM_ATTR_INITIALIZED |
> +SA_IMM_ATTR_RUNTIME |
> +SA_IMM_ATTR_PERSISTENT |
> +SA_IMM_ATTR_CACHED);
> +
> +if(unknownFlags) {
> +/* This error means that at least one attribute flag is not 
> supported by OpenSAF,
> + * but because of forward compatibility, future flags must be 
> supported.
> + */
>   
I have two problems with the comment.
First, he flag is not supported by this >>release<< of OpenSAF.
Second, its not that we must "support" future flags (contradicts that it 
is not supported by this release)
but that this release must try to "cope" with future flags by 
essentially ignoring them.
I suggest instead:

/* This error means that at least one attribute flag is not supported by this
   OpenSAF release. This release will still try to cope with such flags by 
   ignoring them (e.g. not failing to load the rest of the data). This can only
   be done if either the XSD pointed at by the file can be loaded and the
   unsupported flag is confirmed as a valid flag name in that XSD; or if the
   recognition of the unsupported flag has been hardcoded into this older 
release.
   Hardcoding is only done for non-integrity related flags such as 
SA_IMM_ATTR_NOTIFY
   and allows the flag to pass through this system (e.g. be included in a dump).
 */



> +err = SA_AIS_ERR_NOT_SUPPORTED;
> +TRACE_5("create attribute '%s' with unknown flag(s), attribute 
> flag: %llu", attrName.c_str(), attr->attrFlags);
> +} else {
> +TRACE_5("create attribute '%s'", attrName.c_str());
> +}
>  
>  AttrInfo* attrInfo = new AttrInfo;
>  attrInfo->mValueType = attr->attrValueType;
> -osafassert(attr->attrFlags < 0x);
> -attrInfo->mFlags = (SaUint32T) attr->attrFlags;
> +attrInfo->mFlags = attr->attrFlags;
>  attrInfo->mNtfId = attr->attrNtfId;
>  if(attr->attrDefaultValue) {
>  IMMSV_OCTET_STRING tmpos; //temporary octet string
> @@ -3142,13 +3167,13 @@ ImmModel::classDescriptionGet(const IMMS
>  
>  struct AttrFlagIncludes
>  {
> -AttrFlagIncludes(SaUint32T attrFlag) : mFlag(attrFlag) { }
> +AttrFlagIncludes(SaImmAttrFlagsT attrFlag) : mFlag(attrFlag) { }
>  
>  bool operator() (AttrMap::value_type& item) const {
>  return (item.second->mFlags & mFlag) != 0;
>  }
>  
> -SaUint32T mFlag;
> +SaImmAttrFlagsT mFlag;
>  };
>  
>  struct IdIs
> diff --git a/osaf/services/saf/immsv/immnd/Imm

[devel] [PATCH 1 of 2] IMM: add support for forwards compatibility of attribute flags [#116]

2014-02-21 Thread Zoran Milinkovic
 osaf/libs/common/immsv/immpbe_dump.cc  |2 +-
 osaf/services/saf/immsv/immloadd/imm_loader.cc |  140 -
 osaf/services/saf/immsv/immnd/ImmModel.cc  |   36 +++--
 osaf/services/saf/immsv/immnd/ImmSearchOp.cc   |2 +-
 osaf/services/saf/immsv/immnd/ImmSearchOp.hh   |4 +-
 5 files changed, 165 insertions(+), 19 deletions(-)


Add support for 64-bit attribute flags to IMM service.
If immload finds unknown attribute flag, immload will try to find the attribute 
flag in the schema defined in the top element of the loading IMM XML file.

diff --git a/osaf/libs/common/immsv/immpbe_dump.cc 
b/osaf/libs/common/immsv/immpbe_dump.cc
--- a/osaf/libs/common/immsv/immpbe_dump.cc
+++ b/osaf/libs/common/immsv/immpbe_dump.cc
@@ -900,7 +900,7 @@ ClassInfo* classToPBE(std::string classN
LOG_ER("Failed to bind attr_type with error code: %d", 
rc);
goto bailout;
}
-   if((rc = sqlite3_bind_int(stmt, 4, (*p)->attrFlags)) != 
SQLITE_OK) {
+   if((rc = sqlite3_bind_int64(stmt, 4, (*p)->attrFlags)) != 
SQLITE_OK) {
LOG_ER("Failed to bind attr_flags with error code: %d", 
rc);
goto bailout;
}
diff --git a/osaf/services/saf/immsv/immloadd/imm_loader.cc 
b/osaf/services/saf/immsv/immloadd/imm_loader.cc
--- a/osaf/services/saf/immsv/immloadd/imm_loader.cc
+++ b/osaf/services/saf/immsv/immloadd/imm_loader.cc
@@ -17,7 +17,9 @@
 
 #include "imm_loader.hh"
 #include 
+#include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -26,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #define MAX_DEPTH 10
@@ -114,6 +117,12 @@ typedef struct ParserStateStruct
 SaUint32T* preloadEpochPtr;
 } ParserState;
 
+bool isXsdLoaded;
+std::string xsddir;
+std::string xsd;
+typedef std::set AttrFlagSet;
+AttrFlagSet attrFlagSet;
+
 /* Helper functions */
 
 static void addToAttrTypeCache(ParserState*, SaImmValueTypeT);
@@ -935,6 +944,13 @@ static void startElementHandler(void* us
 else if (strcmp((const char*)name, "imm:IMM-contents") == 0)
 {
 state->state[state->depth] = IMM_CONTENTS;
+char *schema = (char *)getAttributeValue(attrs, (xmlChar 
*)"noNamespaceSchemaLocation");
+if(!schema) {
+schema = (char *)getAttributeValue(attrs, (xmlChar 
*)"xsi:noNamespaceSchemaLocation");
+}
+if(schema) {
+xsd = schema;
+}
 }
 else
 {
@@ -1523,6 +1539,106 @@ static xmlEntityPtr
 return xmlGetPredefinedEntity(name);
 }
 
+static inline char *getAttrValue(xmlAttributePtr attr) {
+if(!attr || !attr->children) {
+return NULL;
+}
+
+return (char *)attr->children->content;
+}
+
+static bool loadXsd(const char *xsdFile) {
+struct stat st;
+if(stat(xsdFile, &st)) {
+if(errno == ENOENT) {
+LOG_ER("%s does not exist", xsdFile);
+} else {
+LOG_ER("stat of %s return error: %d", xsdFile, errno);
+}
+
+return false;
+}
+// It should be a file or a directory
+if(!S_ISREG(st.st_mode)) {
+LOG_ER("%s is not a file", xsdFile);
+return false;
+}
+
+xmlNodePtr xsdDocRoot;
+xmlDocPtr xsdDoc = xmlParseFile(xsdFile);
+if(!xsdDoc) {
+return false;
+}
+
+bool rc = true;
+xmlXPathContextPtr ctx = xmlXPathNewContext(xsdDoc);
+if(!ctx) {
+rc = false;
+goto freedoc;
+}
+
+// Add namespace of the first element
+xsdDocRoot = xmlDocGetRootElement(xsdDoc);
+if(xsdDocRoot->ns) {
+ctx->namespaces = (xmlNsPtr *)malloc(sizeof(xmlNsPtr));
+ctx->namespaces[0] = xsdDocRoot->ns;
+ctx->nsNr = 1;
+}
+
+xmlXPathObjectPtr xpathObj;
+xpathObj = xmlXPathEval((const 
xmlChar*)"/xs:schema/xs:simpleType[@name=\"attr-flags\"]/xs:restriction/xs:enumeration",
 ctx);
+if(!xpathObj || !xpathObj->nodesetval) {
+rc = false;
+goto freectx;
+}
+
+xmlElementPtr element;
+xmlAttributePtr attr;
+char *value;
+int size;
+
+size = xpathObj->nodesetval->nodeNr;
+for(int i=0; inodesetval->nodeTab[i];
+attr = element->attributes;
+while(attr) {
+if(!strcmp((char *)attr->name, "value")) {
+value = getAttrValue(attr);
+}
+
+if(value) {
+break;
+}
+
+attr = (xmlAttributePtr)attr->next;
+}
+
+if(value) {
+if(strcmp(value, "SA_RUNTIME") && strcmp(value, "SA_CONFIG") &&
+strcmp(value, "SA_MULTI_VALUE") && strcmp(value, 
"SA_WRITABLE") &&
+strcmp(value, "SA_INITIALIZED") && strcmp(value, 
"SA_PERSISTENT") &&
+strcmp(value, "SA_CACHED") && strcmp(value, "SA_NOTIFY") &&
+strcmp(value, "SA_NO_DUPLICATES") && strcmp(value, 
"SA_NO_DANGLING")) {
+ 

[devel] [PATCH 1 of 2] IMM: add support for forwards compatibility of attribute flags [#116]

2014-02-21 Thread Zoran Milinkovic
 osaf/libs/common/immsv/immpbe_dump.cc  |2 +-
 osaf/services/saf/immsv/immloadd/imm_loader.cc |  140 -
 osaf/services/saf/immsv/immnd/ImmModel.cc  |   36 +++--
 osaf/services/saf/immsv/immnd/ImmSearchOp.cc   |2 +-
 osaf/services/saf/immsv/immnd/ImmSearchOp.hh   |4 +-
 5 files changed, 165 insertions(+), 19 deletions(-)


Add support for 64-bit attribute flags to IMM service.
If immload finds unknown attribute flag, immload will try to find the attribute 
flag in the schema defined in the top element of the loading IMM XML file.

diff --git a/osaf/libs/common/immsv/immpbe_dump.cc 
b/osaf/libs/common/immsv/immpbe_dump.cc
--- a/osaf/libs/common/immsv/immpbe_dump.cc
+++ b/osaf/libs/common/immsv/immpbe_dump.cc
@@ -873,7 +873,7 @@ ClassInfo* classToPBE(std::string classN
LOG_ER("Failed to bind attr_type with error code: %d", 
rc);
goto bailout;
}
-   if((rc = sqlite3_bind_int(stmt, 4, (*p)->attrFlags)) != 
SQLITE_OK) {
+   if((rc = sqlite3_bind_int64(stmt, 4, (*p)->attrFlags)) != 
SQLITE_OK) {
LOG_ER("Failed to bind attr_flags with error code: %d", 
rc);
goto bailout;
}
diff --git a/osaf/services/saf/immsv/immloadd/imm_loader.cc 
b/osaf/services/saf/immsv/immloadd/imm_loader.cc
--- a/osaf/services/saf/immsv/immloadd/imm_loader.cc
+++ b/osaf/services/saf/immsv/immloadd/imm_loader.cc
@@ -17,7 +17,9 @@
 
 #include "imm_loader.hh"
 #include 
+#include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -26,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define MAX_DEPTH 10
 #define MAX_CHAR_BUFFER_SIZE 8192  //8k
@@ -111,6 +114,12 @@ typedef struct ParserStateStruct
 SaImmHandleT ccbHandle;
 } ParserState;
 
+bool isXsdLoaded;
+std::string xsddir;
+std::string xsd;
+typedef std::set AttrFlagSet;
+AttrFlagSet attrFlagSet;
+
 /* Helper functions */
 
 static void addToAttrTypeCache(ParserState*, SaImmValueTypeT);
@@ -874,6 +883,13 @@ static void startElementHandler(void* us
 else if (strcmp((const char*)name, "imm:IMM-contents") == 0)
 {
 state->state[state->depth] = IMM_CONTENTS;
+char *schema = (char *)getAttributeValue(attrs, (xmlChar 
*)"noNamespaceSchemaLocation");
+if(!schema) {
+schema = (char *)getAttributeValue(attrs, (xmlChar 
*)"xsi:noNamespaceSchemaLocation");
+}
+if(schema) {
+xsd = schema;
+}
 }
 else
 {
@@ -1424,6 +1440,106 @@ static xmlEntityPtr
 return xmlGetPredefinedEntity(name);
 }
 
+static inline char *getAttrValue(xmlAttributePtr attr) {
+if(!attr || !attr->children) {
+return NULL;
+}
+
+return (char *)attr->children->content;
+}
+
+static bool loadXsd(const char *xsdFile) {
+struct stat st;
+if(stat(xsdFile, &st)) {
+if(errno == ENOENT) {
+LOG_ER("%s does not exist", xsdFile);
+} else {
+LOG_ER("stat of %s return error: %d", xsdFile, errno);
+}
+
+return false;
+}
+// It should be a file or a directory
+if(!S_ISREG(st.st_mode)) {
+LOG_ER("%s is not a file", xsdFile);
+return false;
+}
+
+xmlNodePtr xsdDocRoot;
+xmlDocPtr xsdDoc = xmlParseFile(xsdFile);
+if(!xsdDoc) {
+return false;
+}
+
+bool rc = true;
+xmlXPathContextPtr ctx = xmlXPathNewContext(xsdDoc);
+if(!ctx) {
+rc = false;
+goto freedoc;
+}
+
+//Add namespace of the first element
+xsdDocRoot = xmlDocGetRootElement(xsdDoc);
+if(xsdDocRoot->ns) {
+ctx->namespaces = (xmlNsPtr *)malloc(sizeof(xmlNsPtr));
+ctx->namespaces[0] = xsdDocRoot->ns;
+ctx->nsNr = 1;
+}
+
+xmlXPathObjectPtr xpathObj;
+xpathObj = xmlXPathEval((const 
xmlChar*)"/xs:schema/xs:simpleType[@name=\"attr-flags\"]/xs:restriction/xs:enumeration",
 ctx);
+if(!xpathObj || !xpathObj->nodesetval) {
+rc = false;
+goto freectx;
+}
+
+xmlElementPtr element;
+xmlAttributePtr attr;
+char *value;
+int size;
+
+size = xpathObj->nodesetval->nodeNr;
+for(int i=0; inodesetval->nodeTab[i];
+attr = element->attributes;
+while(attr) {
+if(!strcmp((char *)attr->name, "value")) {
+value = getAttrValue(attr);
+}
+
+if(value) {
+break;
+}
+
+attr = (xmlAttributePtr)attr->next;
+}
+
+if(value) {
+if(strcmp(value, "SA_RUNTIME") && strcmp(value, "SA_CONFIG") &&
+strcmp(value, "SA_MULTI_VALUE") && strcmp(value, 
"SA_WRITABLE") &&
+strcmp(value, "SA_INITIALIZED") && strcmp(value, 
"SA_PERSISTENT") &&
+strcmp(value, "SA_CACHED") && strcmp(value, "SA_NOTIFY") &&
+strcmp(value, "SA_NO_DUPLICATES")) {
+

[devel] [PATCH 1 of 2] IMM: add support for forwards compatibility of attribute flags [#116]

2014-02-21 Thread Zoran Milinkovic
 osaf/services/saf/immsv/immnd/ImmModel.cc|  39 ++-
 osaf/services/saf/immsv/immnd/ImmSearchOp.cc |   2 +-
 osaf/services/saf/immsv/immnd/ImmSearchOp.hh |   4 +-
 3 files changed, 35 insertions(+), 10 deletions(-)


diff --git a/osaf/services/saf/immsv/immnd/ImmModel.cc 
b/osaf/services/saf/immsv/immnd/ImmModel.cc
--- a/osaf/services/saf/immsv/immnd/ImmModel.cc
+++ b/osaf/services/saf/immsv/immnd/ImmModel.cc
@@ -72,7 +72,7 @@ struct AttrInfo
 {
 AttrInfo():mValueType(0), mFlags(0), mNtfId(0){}
 SaUint32T   mValueType;
-SaUint32T   mFlags;
+SaImmAttrFlagsT mFlags;
 SaUint32T   mNtfId;
 ImmAttrValuemDefaultValue;
 };
@@ -2219,6 +2219,7 @@ ImmModel::classCreate(const ImmsvOmClass
 int illegal=0;
 bool persistentRt = false;
 bool persistentRdn = false;
+bool useUnknownFlag = false;
 ClassInfo* classInfo = NULL;
 ClassInfo* prevClassInfo = NULL;
 ClassInfo dummyClass(req->classCategory);
@@ -2423,7 +2424,10 @@ ImmModel::classCreate(const ImmsvOmClass
 }
 }
 err = attrCreate(classInfo, attr, attrName);
-if(err != SA_AIS_OK) {
+if(err == SA_AIS_ERR_NOT_SUPPORTED) {
+useUnknownFlag = true;
+err = SA_AIS_OK;
+} else if(err != SA_AIS_OK) {
 illegal = 1;
 }
 list = list->next;
@@ -2476,6 +2480,10 @@ ImmModel::classCreate(const ImmsvOmClass
 goto done;
 }
 
+if(useUnknownFlag) {
+LOG_NO("At least one attribute in class %s has unsupported attribute 
flag", className.c_str());
+}
+
 /* All checks passed, now install the class def. */
 
 if(!schemaChange) {
@@ -3054,12 +3062,29 @@ ImmModel::attrCreate(ClassInfo* classInf
 }
 }
 
-TRACE_5("create attribute '%s'", attrName.c_str());
+SaImmAttrFlagsT unknownFlags = attr->attrFlags &
+  ~(SA_IMM_ATTR_MULTI_VALUE |
+SA_IMM_ATTR_RDN |
+SA_IMM_ATTR_CONFIG |
+SA_IMM_ATTR_WRITABLE |
+SA_IMM_ATTR_INITIALIZED |
+SA_IMM_ATTR_RUNTIME |
+SA_IMM_ATTR_PERSISTENT |
+SA_IMM_ATTR_CACHED);
+
+if(unknownFlags) {
+/* This error means that at least one attribute flag is not 
supported by OpenSAF,
+ * but because of forward compatibility, future flags must be 
supported.
+ */
+err = SA_AIS_ERR_NOT_SUPPORTED;
+TRACE_5("create attribute '%s' with unknown flag(s), attribute 
flag: %llu", attrName.c_str(), attr->attrFlags);
+} else {
+TRACE_5("create attribute '%s'", attrName.c_str());
+}
 
 AttrInfo* attrInfo = new AttrInfo;
 attrInfo->mValueType = attr->attrValueType;
-osafassert(attr->attrFlags < 0x);
-attrInfo->mFlags = (SaUint32T) attr->attrFlags;
+attrInfo->mFlags = attr->attrFlags;
 attrInfo->mNtfId = attr->attrNtfId;
 if(attr->attrDefaultValue) {
 IMMSV_OCTET_STRING tmpos; //temporary octet string
@@ -3142,13 +3167,13 @@ ImmModel::classDescriptionGet(const IMMS
 
 struct AttrFlagIncludes
 {
-AttrFlagIncludes(SaUint32T attrFlag) : mFlag(attrFlag) { }
+AttrFlagIncludes(SaImmAttrFlagsT attrFlag) : mFlag(attrFlag) { }
 
 bool operator() (AttrMap::value_type& item) const {
 return (item.second->mFlags & mFlag) != 0;
 }
 
-SaUint32T mFlag;
+SaImmAttrFlagsT mFlag;
 };
 
 struct IdIs
diff --git a/osaf/services/saf/immsv/immnd/ImmSearchOp.cc 
b/osaf/services/saf/immsv/immnd/ImmSearchOp.cc
--- a/osaf/services/saf/immsv/immnd/ImmSearchOp.cc
+++ b/osaf/services/saf/immsv/immnd/ImmSearchOp.cc
@@ -51,7 +51,7 @@ ImmSearchOp::addObject(
 void
 ImmSearchOp::addAttribute(const std::string& attributeName, 
 SaUint32T valueType,
-SaUint32T flags)
+SaImmAttrFlagsT flags)
 
 {
 SearchObject& obj = mResultList.back();
diff --git a/osaf/services/saf/immsv/immnd/ImmSearchOp.hh 
b/osaf/services/saf/immsv/immnd/ImmSearchOp.hh
--- a/osaf/services/saf/immsv/immnd/ImmSearchOp.hh
+++ b/osaf/services/saf/immsv/immnd/ImmSearchOp.hh
@@ -32,7 +32,7 @@ struct SearchAttribute
 std::string name;
 ImmAttrValue* valuep;
 SaImmValueTypeT  valueType;
-SaUint32T flags;
+SaImmAttrFlagsT flags;
 
 ~SearchAttribute();
 };
@@ -63,7 +63,7 @@ public:
 void  addAttribute(
const std::string& attributeName, 
SaUint32T valueType,
-   SaUint32T flags);
+   SaImmAttrFlagsT flags);
 void  addAttrValue(const ImmAttrValue& value);
 void  setImplementer(
  SaUint32T conn, 

--
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has 

[devel] [PATCH 1 of 2] IMM: add support for forwards compatibility of attribute flags [#116]

2014-02-18 Thread Zoran Milinkovic
 osaf/libs/common/immsv/immpbe_dump.cc  |2 +-
 osaf/services/saf/immsv/immloadd/imm_loader.cc |  165 -
 osaf/services/saf/immsv/immnd/ImmModel.cc  |   36 +-
 osaf/services/saf/immsv/immnd/ImmSearchOp.cc   |2 +-
 osaf/services/saf/immsv/immnd/ImmSearchOp.hh   |4 +-
 osaf/services/saf/immsv/schema/SAI-AIS-IMM-XSD-A.02.12.xsd |   14 +-
 osaf/services/saf/immsv/schema/SAI-AIS-IMM-XSD-A.02.13.xsd |   16 +-
 7 files changed, 205 insertions(+), 34 deletions(-)


diff --git a/osaf/libs/common/immsv/immpbe_dump.cc 
b/osaf/libs/common/immsv/immpbe_dump.cc
--- a/osaf/libs/common/immsv/immpbe_dump.cc
+++ b/osaf/libs/common/immsv/immpbe_dump.cc
@@ -885,7 +885,7 @@ ClassInfo* classToPBE(std::string classN
LOG_ER("Failed to bind attr_type with error code: %d", 
rc);
goto bailout;
}
-   if((rc = sqlite3_bind_int(stmt, 4, (*p)->attrFlags)) != 
SQLITE_OK) {
+   if((rc = sqlite3_bind_int64(stmt, 4, (*p)->attrFlags)) != 
SQLITE_OK) {
LOG_ER("Failed to bind attr_flags with error code: %d", 
rc);
goto bailout;
}
diff --git a/osaf/services/saf/immsv/immloadd/imm_loader.cc 
b/osaf/services/saf/immsv/immloadd/imm_loader.cc
--- a/osaf/services/saf/immsv/immloadd/imm_loader.cc
+++ b/osaf/services/saf/immsv/immloadd/imm_loader.cc
@@ -18,6 +18,7 @@
 #include "imm_loader.hh"
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -26,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #define MAX_DEPTH 10
@@ -114,6 +116,23 @@ typedef struct ParserStateStruct
 SaUint32T* preloadEpochPtr;
 } ParserState;
 
+bool isXsdLoaded;
+std::string xsddir;
+std::string xsd;
+typedef std::map AttrFlagMap;
+AttrFlagMap attrFlagMap;
+
+static SaImmAttrFlagsT attrFlagMask = (SA_IMM_ATTR_RUNTIME
+   | SA_IMM_ATTR_CONFIG
+   | SA_IMM_ATTR_MULTI_VALUE
+   | SA_IMM_ATTR_WRITABLE
+   | SA_IMM_ATTR_INITIALIZED
+   | SA_IMM_ATTR_PERSISTENT
+   | SA_IMM_ATTR_CACHED
+   | SA_IMM_ATTR_NOTIFY
+   | SA_IMM_ATTR_NO_DUPLICATES
+   | SA_IMM_ATTR_NO_DANGLING);
+
 /* Helper functions */
 
 static void addToAttrTypeCache(ParserState*, SaImmValueTypeT);
@@ -935,6 +954,13 @@ static void startElementHandler(void* us
 else if (strcmp((const char*)name, "imm:IMM-contents") == 0)
 {
 state->state[state->depth] = IMM_CONTENTS;
+char *schema = (char *)getAttributeValue(attrs, (xmlChar 
*)"noNamespaceSchemaLocation");
+if(!schema) {
+schema = (char *)getAttributeValue(attrs, (xmlChar 
*)"xsi:noNamespaceSchemaLocation");
+}
+if(schema) {
+xsd = schema;
+}
 }
 else
 {
@@ -1523,6 +1549,121 @@ static xmlEntityPtr
 return xmlGetPredefinedEntity(name);
 }
 
+static inline char *getAttrValue(xmlAttributePtr attr) {
+if(!attr || !attr->children) {
+return NULL;
+}
+
+return (char *)attr->children->content;
+}
+
+static bool loadXsd(const char *xsdFile) {
+   struct stat st;
+   if(stat(xsdFile, &st)) {
+   if(errno == ENOENT) {
+   LOG_ER("%s does not exist", xsdFile);
+   } else {
+   LOG_ER("stat of %s return error: %d", xsdFile, errno);
+   }
+
+   return false;
+   }
+   // It should be a file or a directory
+   if(!S_ISREG(st.st_mode)) {
+   LOG_ER("%s is not a file", xsdFile);
+   return false;
+   }
+
+   xmlNodePtr xsdDocRoot;
+   xmlDocPtr xsdDoc = xmlParseFile(xsdFile);
+   if(!xsdDoc) {
+   return false;
+   }
+
+   bool rc = true;
+   xmlXPathContextPtr ctx = xmlXPathNewContext(xsdDoc);
+   if(!ctx) {
+   rc = false;
+   goto freedoc;
+   }
+
+   //  Add namespace of the first element
+   xsdDocRoot = xmlDocGetRootElement(xsdDoc);
+   if(xsdDocRoot->ns) {
+   ctx->namespaces = (xmlNsPtr *)malloc(sizeof(xmlNsPtr));
+   ctx->namespaces[0] = xsdDocRoot->ns;
+   ctx->nsNr = 1;
+   }
+
+   xmlXPathObjectPtr xpathObj;
+   xpathObj = xmlXPathEval((const 
xmlChar*)"/xs:schema/xs:simpleType[@name=\"attr-flags\"]/xs:restriction/xs:enumeration",
 ctx);
+   if(!xpathObj || !xpathObj->nodesetval) {
+   rc = false;
+   goto freectx;
+   }
+
+   xmlElementPtr element;
+   xmlAttributePtr attr;
+   char *id;
+   char *value;
+   int size;
+
+   size = xpathObj->nodesetval->nodeNr;
+   for(int i=0; inodesetval->nodeTab[i];
+   attr = element->attributes;
+   while(attr) {
+   if(!strcmp((char *)attr->name, "ID")) {
+  

[devel] [PATCH 1 of 2] IMM: add support for forwards compatibility of attribute flags [#116]

2014-02-18 Thread Zoran Milinkovic
 osaf/libs/common/immsv/immpbe_dump.cc  |2 +-
 osaf/services/saf/immsv/immloadd/imm_loader.cc |  164 -
 osaf/services/saf/immsv/immnd/ImmModel.cc  |   36 +-
 osaf/services/saf/immsv/immnd/ImmSearchOp.cc   |2 +-
 osaf/services/saf/immsv/immnd/ImmSearchOp.hh   |4 +-
 osaf/services/saf/immsv/schema/SAI-AIS-IMM-XSD-A.02.12.xsd |   14 +-
 6 files changed, 196 insertions(+), 26 deletions(-)


diff --git a/osaf/libs/common/immsv/immpbe_dump.cc 
b/osaf/libs/common/immsv/immpbe_dump.cc
--- a/osaf/libs/common/immsv/immpbe_dump.cc
+++ b/osaf/libs/common/immsv/immpbe_dump.cc
@@ -873,7 +873,7 @@ ClassInfo* classToPBE(std::string classN
LOG_ER("Failed to bind attr_type with error code: %d", 
rc);
goto bailout;
}
-   if((rc = sqlite3_bind_int(stmt, 4, (*p)->attrFlags)) != 
SQLITE_OK) {
+   if((rc = sqlite3_bind_int64(stmt, 4, (*p)->attrFlags)) != 
SQLITE_OK) {
LOG_ER("Failed to bind attr_flags with error code: %d", 
rc);
goto bailout;
}
diff --git a/osaf/services/saf/immsv/immloadd/imm_loader.cc 
b/osaf/services/saf/immsv/immloadd/imm_loader.cc
--- a/osaf/services/saf/immsv/immloadd/imm_loader.cc
+++ b/osaf/services/saf/immsv/immloadd/imm_loader.cc
@@ -18,6 +18,7 @@
 #include "imm_loader.hh"
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -26,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define MAX_DEPTH 10
 #define MAX_CHAR_BUFFER_SIZE 8192  //8k
@@ -111,6 +113,22 @@ typedef struct ParserStateStruct
 SaImmHandleT ccbHandle;
 } ParserState;
 
+bool isXsdLoaded;
+std::string xsddir;
+std::string xsd;
+typedef std::map AttrFlagMap;
+AttrFlagMap attrFlagMap;
+
+static SaImmAttrFlagsT attrFlagMask = (SA_IMM_ATTR_RUNTIME
+   | SA_IMM_ATTR_CONFIG
+   | SA_IMM_ATTR_MULTI_VALUE
+   | SA_IMM_ATTR_WRITABLE
+   | SA_IMM_ATTR_INITIALIZED
+   | SA_IMM_ATTR_PERSISTENT
+   | SA_IMM_ATTR_CACHED
+   | SA_IMM_ATTR_NOTIFY
+   | SA_IMM_ATTR_NO_DUPLICATES);
+
 /* Helper functions */
 
 static void addToAttrTypeCache(ParserState*, SaImmValueTypeT);
@@ -874,6 +892,13 @@ static void startElementHandler(void* us
 else if (strcmp((const char*)name, "imm:IMM-contents") == 0)
 {
 state->state[state->depth] = IMM_CONTENTS;
+char *schema = (char *)getAttributeValue(attrs, (xmlChar 
*)"noNamespaceSchemaLocation");
+if(!schema) {
+schema = (char *)getAttributeValue(attrs, (xmlChar 
*)"xsi:noNamespaceSchemaLocation");
+}
+if(schema) {
+xsd = schema;
+}
 }
 else
 {
@@ -1424,6 +1449,121 @@ static xmlEntityPtr
 return xmlGetPredefinedEntity(name);
 }
 
+static inline char *getAttrValue(xmlAttributePtr attr) {
+if(!attr || !attr->children) {
+return NULL;
+}
+
+return (char *)attr->children->content;
+}
+
+static bool loadXsd(const char *xsdFile) {
+   struct stat st;
+   if(stat(xsdFile, &st)) {
+   if(errno == ENOENT) {
+   LOG_ER("%s does not exist", xsdFile);
+   } else {
+   LOG_ER("stat of %s return error: %d", xsdFile, errno);
+   }
+
+   return false;
+   }
+   // It should be a file or a directory
+   if(!S_ISREG(st.st_mode)) {
+   LOG_ER("%s is not a file", xsdFile);
+   return false;
+   }
+
+   xmlNodePtr xsdDocRoot;
+   xmlDocPtr xsdDoc = xmlParseFile(xsdFile);
+   if(!xsdDoc) {
+   return false;
+   }
+
+   bool rc = true;
+   xmlXPathContextPtr ctx = xmlXPathNewContext(xsdDoc);
+   if(!ctx) {
+   rc = false;
+   goto freedoc;
+   }
+
+   //  Add namespace of the first element
+   xsdDocRoot = xmlDocGetRootElement(xsdDoc);
+   if(xsdDocRoot->ns) {
+   ctx->namespaces = (xmlNsPtr *)malloc(sizeof(xmlNsPtr));
+   ctx->namespaces[0] = xsdDocRoot->ns;
+   ctx->nsNr = 1;
+   }
+
+   xmlXPathObjectPtr xpathObj;
+   xpathObj = xmlXPathEval((const 
xmlChar*)"/xs:schema/xs:simpleType[@name=\"attr-flags\"]/xs:restriction/xs:enumeration",
 ctx);
+   if(!xpathObj || !xpathObj->nodesetval) {
+   rc = false;
+   goto freectx;
+   }
+
+   xmlElementPtr element;
+   xmlAttributePtr attr;
+   char *id;
+   char *value;
+   int size;
+
+   size = xpathObj->nodesetval->nodeNr;
+   for(int i=0; inodesetval->nodeTab[i];
+   attr = element->attributes;
+   while(attr) {
+   if(!strcmp((char *)attr->name, "ID")) {
+   id = getAttrValue(attr);
+   } else if(!s

[devel] [PATCH 1 of 2] IMM: add support for forwards compatibility of attribute flags [#116]

2014-02-18 Thread Zoran Milinkovic
 osaf/services/saf/immsv/immnd/ImmModel.cc  |  39 
-
 osaf/services/saf/immsv/immnd/ImmSearchOp.cc   |   2 +-
 osaf/services/saf/immsv/immnd/ImmSearchOp.hh   |   4 +-
 osaf/services/saf/immsv/schema/SAI-AIS-IMM-XSD-A.01.02_OpenSAF.xsd |  10 +-
 4 files changed, 40 insertions(+), 15 deletions(-)


diff --git a/osaf/services/saf/immsv/immnd/ImmModel.cc 
b/osaf/services/saf/immsv/immnd/ImmModel.cc
--- a/osaf/services/saf/immsv/immnd/ImmModel.cc
+++ b/osaf/services/saf/immsv/immnd/ImmModel.cc
@@ -72,7 +72,7 @@ struct AttrInfo
 {
 AttrInfo():mValueType(0), mFlags(0), mNtfId(0){}
 SaUint32T   mValueType;
-SaUint32T   mFlags;
+SaImmAttrFlagsT mFlags;
 SaUint32T   mNtfId;
 ImmAttrValuemDefaultValue;
 };
@@ -2219,6 +2219,7 @@ ImmModel::classCreate(const ImmsvOmClass
 int illegal=0;
 bool persistentRt = false;
 bool persistentRdn = false;
+bool useUnknownFlag = false;
 ClassInfo* classInfo = NULL;
 ClassInfo* prevClassInfo = NULL;
 ClassInfo dummyClass(req->classCategory);
@@ -2423,7 +2424,10 @@ ImmModel::classCreate(const ImmsvOmClass
 }
 }
 err = attrCreate(classInfo, attr, attrName);
-if(err != SA_AIS_OK) {
+if(err == SA_AIS_ERR_NOT_SUPPORTED) {
+useUnknownFlag = true;
+err = SA_AIS_OK;
+} else if(err != SA_AIS_OK) {
 illegal = 1;
 }
 list = list->next;
@@ -2476,6 +2480,10 @@ ImmModel::classCreate(const ImmsvOmClass
 goto done;
 }
 
+if(useUnknownFlag) {
+LOG_NO("At least one attribute in class %s has unsupported attribute 
flag", className.c_str());
+}
+
 /* All checks passed, now install the class def. */
 
 if(!schemaChange) {
@@ -3054,12 +3062,29 @@ ImmModel::attrCreate(ClassInfo* classInf
 }
 }
 
-TRACE_5("create attribute '%s'", attrName.c_str());
+SaImmAttrFlagsT unknownFlags = attr->attrFlags &
+  ~(SA_IMM_ATTR_MULTI_VALUE |
+SA_IMM_ATTR_RDN |
+SA_IMM_ATTR_CONFIG |
+SA_IMM_ATTR_WRITABLE |
+SA_IMM_ATTR_INITIALIZED |
+SA_IMM_ATTR_RUNTIME |
+SA_IMM_ATTR_PERSISTENT |
+SA_IMM_ATTR_CACHED);
+
+if(unknownFlags) {
+/* This error means that at least one attribute flag is not 
supported by OpenSAF,
+ * but because of forward compatibility, future flags must be 
supported.
+ */
+err = SA_AIS_ERR_NOT_SUPPORTED;
+TRACE_5("create attribute '%s' with unknown flag(s), attribute 
flag: %llu", attrName.c_str(), attr->attrFlags);
+} else {
+TRACE_5("create attribute '%s'", attrName.c_str());
+}
 
 AttrInfo* attrInfo = new AttrInfo;
 attrInfo->mValueType = attr->attrValueType;
-osafassert(attr->attrFlags < 0x);
-attrInfo->mFlags = (SaUint32T) attr->attrFlags;
+attrInfo->mFlags = attr->attrFlags;
 attrInfo->mNtfId = attr->attrNtfId;
 if(attr->attrDefaultValue) {
 IMMSV_OCTET_STRING tmpos; //temporary octet string
@@ -3142,13 +3167,13 @@ ImmModel::classDescriptionGet(const IMMS
 
 struct AttrFlagIncludes
 {
-AttrFlagIncludes(SaUint32T attrFlag) : mFlag(attrFlag) { }
+AttrFlagIncludes(SaImmAttrFlagsT attrFlag) : mFlag(attrFlag) { }
 
 bool operator() (AttrMap::value_type& item) const {
 return (item.second->mFlags & mFlag) != 0;
 }
 
-SaUint32T mFlag;
+SaImmAttrFlagsT mFlag;
 };
 
 struct IdIs
diff --git a/osaf/services/saf/immsv/immnd/ImmSearchOp.cc 
b/osaf/services/saf/immsv/immnd/ImmSearchOp.cc
--- a/osaf/services/saf/immsv/immnd/ImmSearchOp.cc
+++ b/osaf/services/saf/immsv/immnd/ImmSearchOp.cc
@@ -51,7 +51,7 @@ ImmSearchOp::addObject(
 void
 ImmSearchOp::addAttribute(const std::string& attributeName, 
 SaUint32T valueType,
-SaUint32T flags)
+SaImmAttrFlagsT flags)
 
 {
 SearchObject& obj = mResultList.back();
diff --git a/osaf/services/saf/immsv/immnd/ImmSearchOp.hh 
b/osaf/services/saf/immsv/immnd/ImmSearchOp.hh
--- a/osaf/services/saf/immsv/immnd/ImmSearchOp.hh
+++ b/osaf/services/saf/immsv/immnd/ImmSearchOp.hh
@@ -32,7 +32,7 @@ struct SearchAttribute
 std::string name;
 ImmAttrValue* valuep;
 SaImmValueTypeT  valueType;
-SaUint32T flags;
+SaImmAttrFlagsT flags;
 
 ~SearchAttribute();
 };
@@ -63,7 +63,7 @@ public:
 void  addAttribute(
const std::string& attributeName, 
SaUint32T valueType,
-   SaUint32T flags);
+   SaImmAttrFlagsT flags);
 void  addAttrValue(const ImmAttrValue& value);
 void  setImplementer(
  SaUint32T conn, 
diff --git a/osaf/services/saf/immsv/schema/