osaf/tools/safimm/immcfg/imm_cfg.c | 13 +++++++++---- osaf/tools/safimm/immcfg/imm_import.cc | 34 ++++++++++++++++++++++------------ 2 files changed, 31 insertions(+), 16 deletions(-)
For backwards compatibility, it's needed to revert the code for old way of parsing default values. Flag --strict is added for a more strict parsing values, which fail immcfg if an attribute value does not match the attribute data type. diff --git a/osaf/tools/safimm/immcfg/imm_cfg.c b/osaf/tools/safimm/immcfg/imm_cfg.c --- a/osaf/tools/safimm/immcfg/imm_cfg.c +++ b/osaf/tools/safimm/immcfg/imm_cfg.c @@ -81,8 +81,8 @@ typedef enum { // Interface functions which implement -f and -L options (imm_import.cc) int importImmXML(char* xmlfileC, char* adminOwnerName, int verbose, int ccb_safe, SaImmHandleT *immHandle, SaImmAdminOwnerHandleT *ownerHandle, - SaImmCcbHandleT *ccbHandle, int mode, const char *xsdPath); -int validateImmXML(const char *xmlfile, int verbose, int mode); + SaImmCcbHandleT *ccbHandle, int mode, const char *xsdPath, int strictParse); +int validateImmXML(const char *xmlfile, int verbose, int mode, int strictParse); static int imm_operation(int argc, char *argv[]); char *(*readln)(const char *); @@ -1100,6 +1100,7 @@ static int imm_operation(int argc, char {"ccb-apply", no_argument, NULL, 0}, {"ccb-abort", no_argument, NULL, 0}, {"xsd", required_argument, NULL, 'X'}, + {"strict", no_argument, NULL, 0}, {0, 0, 0, 0} }; SaAisErrorT error; @@ -1123,6 +1124,7 @@ static int imm_operation(int argc, char attr_notify_t attrNotify = NOTIFY_UNDEFINED; char *xsdPath = NULL; + int strictParse = 0; while (1) { int option_index = 0; @@ -1182,6 +1184,8 @@ static int imm_operation(int argc, char exit(EXIT_FAILURE); } op = verify_setoption(op, CCB_ABORT); + } else if (strcmp("strict", long_options[option_index].name) == 0) { + strictParse = 1; } break; case 'a': @@ -1273,7 +1277,7 @@ static int imm_operation(int argc, char if (op == VALIDATE_IMMFILE) { VERBOSE_INFO("validateImmXML(xmlFilename=%s, verbose=%d)\n", xmlFilename, verbose); - rc = validateImmXML(xmlFilename, verbose, transaction_mode); + rc = validateImmXML(xmlFilename, verbose, transaction_mode, strictParse); if(rc == 0) printf("Validation is successful\n"); @@ -1289,7 +1293,8 @@ static int imm_operation(int argc, char if (op == LOAD_IMMFILE) { VERBOSE_INFO("importImmXML(xmlFilename=%s, verbose=%d)\n", xmlFilename, verbose); rc = importImmXML(xmlFilename, adminOwnerName, verbose, ccb_safe, - &immHandle, &ownerHandle, &ccbHandle, transaction_mode, xsdPath); + &immHandle, &ownerHandle, &ccbHandle, transaction_mode, + xsdPath, strictParse); if(transaction_mode) { if(rc) { fprintf(stderr, "CCB is aborted\n"); diff --git a/osaf/tools/safimm/immcfg/imm_import.cc b/osaf/tools/safimm/immcfg/imm_import.cc --- a/osaf/tools/safimm/immcfg/imm_import.cc +++ b/osaf/tools/safimm/immcfg/imm_import.cc @@ -64,8 +64,8 @@ extern "C" { int importImmXML(char* xmlfileC, char* adminOwnerName, int verbose, int ccb_safe, SaImmHandleT *immHandle, SaImmAdminOwnerHandleT *ownerHandle, - SaImmCcbHandleT *ccbHandle, int mode, const char *xsdPath); - int validateImmXML(const char *xmlfile, int verbose, int mode); + SaImmCcbHandleT *ccbHandle, int mode, const char *xsdPath, int strictParse); + int validateImmXML(const char *xmlfile, int verbose, int mode, int strictParse); } extern ImmutilErrorFnT immutilError; @@ -146,6 +146,7 @@ typedef struct ParserStateStruct { bool validation; xmlParserCtxtPtr ctxt; int parsingStatus; /* 0 = ok */ + bool strictParse; } ParserState; bool isXsdLoaded = false; @@ -168,7 +169,8 @@ static void getDNForClass(ParserState*, SaImmAttrValuesT_2*); static int charsToValueHelper(SaImmAttrValueT*, SaImmValueTypeT, - const char*); + const char*, + bool strictParse); static SaImmValueTypeT charsToTypeHelper(const xmlChar* str, size_t len); static SaImmAttrFlagsT charsToFlagsHelper(const xmlChar* str, size_t len); @@ -1162,7 +1164,8 @@ static void getDNForClass(ParserState* s if(charsToValueHelper(values->attrValues, values->attrValueType, - state->objectName)) { + state->objectName, + true)) { free(values->attrValues); values->attrValues = NULL; @@ -2147,7 +2150,8 @@ static void addObjectAttributeDefinition if(charsToValueHelper(&attrValues.attrValues[i], attrValues.attrValueType, - *it)) { + *it, + true)) { LOG_ER("Failed to parse a value of attribute %s", state->attrName); stopParser(state); state->parsingStatus = 1; @@ -2398,7 +2402,8 @@ static void addClassAttributeDefinition( if (state->attrDefaultValueSet) { if(charsToValueHelper(&attrDefinition.attrDefaultValue, state->attrValueType, - state->attrDefaultValueBuffer)) { + state->attrDefaultValueBuffer, + state->strictParse)) { LOG_ER("Failed to parse default value of attribute %s", state->attrName); stopParser(state); state->parsingStatus = 1; @@ -2423,7 +2428,8 @@ static void addClassAttributeDefinition( */ static int charsToValueHelper(SaImmAttrValueT* value, SaImmValueTypeT type, - const char* str) + const char* str, + bool strictParse) { size_t len; unsigned int i; @@ -2515,15 +2521,17 @@ static int charsToValueHelper(SaImmAttrV return -1; } - if(rc) { + if(rc && strictParse) { free(*value); *value = NULL; + } else { + rc = 0; } return rc; } -int loadImmXML(const char *xmlfile) +int loadImmXML(const char *xmlfile, int strictParse) { ParserState state; SaVersionT version; @@ -2577,6 +2585,7 @@ int loadImmXML(const char *xmlfile) state.validation = 0; state.parsingStatus = 0; + state.strictParse = strictParse; //std::cout << "Loading " << xmlfile << std::endl; @@ -2660,7 +2669,7 @@ int loadImmXML(const char *xmlfile) // to ease a future refactoring towards common codebase int importImmXML(char* xmlfileC, char* adminOwnerName, int verbose, int ccb_safe, SaImmHandleT *immHandle, SaImmAdminOwnerHandleT *ownerHandle, - SaImmCcbHandleT *ccbHandle, int mode, const char *xsdPath) + SaImmCcbHandleT *ccbHandle, int mode, const char *xsdPath, int strictParse) { imm_import_adminOwnerName = adminOwnerName; imm_import_verbose = verbose; @@ -2680,10 +2689,10 @@ int importImmXML(char* xmlfileC, char* a // assign own immutil errorhandler (no call to abort()) immutilError = imm_importImmutilError; - return loadImmXML(xmlfileC); + return loadImmXML(xmlfileC, strictParse); } -int validateImmXML(const char *xmlfile, int verbose, int mode) +int validateImmXML(const char *xmlfile, int verbose, int mode, int strictParse) { ParserState state; int result = 1; @@ -2714,6 +2723,7 @@ int validateImmXML(const char *xmlfile, state.validation = 1; state.parsingStatus = 0; + state.strictParse = strictParse; transaction_mode = mode; ------------------------------------------------------------------------------ Start Your Social Network Today - Download eXo Platform Build your Enterprise Intranet with eXo Platform Software Java Based Open Source Intranet - Social, Extensible, Cloud Ready Get Started Now And Turn Your Intranet Into A Collaboration Platform http://p.sf.net/sfu/ExoPlatform _______________________________________________ Opensaf-devel mailing list Opensaf-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/opensaf-devel