⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cimmofparser.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 4 页
字号:
}//--------------------------------------------------------------------// Exception Control//--------------------------------------------------------------------voidcimmofParser::maybeThrowParseError(const String &msg) const{  // If an option is available to allow the MOF compilation to ignore  // errors and continue, then the message should be printed using elog() with  // no exception thrown.  throw ParseError(msg);}voidcimmofParser::maybeThrowLexerError(const String &msg) const{  // If an option is available to allow the MOF compilation to ignore  // errors and continue, then the message should be printed using elog() with  // no exception thrown.  The current Lexer implementation does not allow  // errors to be ignored, though.  throw LexerError(msg);}//--------------------------------------------------------------------// Update class//--------------------------------------------------------------------BooleancimmofParser::updateClass(const CIMClass &classdecl,                          cimmofMessages::MsgCode &updateMessage,                          Boolean &classExist){  classExist = true;  Boolean ret = true;  Boolean iExperimental = false;  Boolean rExperimental = false;  String iVersion;  /* format of version is m.n.u */  int iM = -1;   /* Major id  */  int iN = -1;   /* Minor id  */  int iU = -1;   /* Update id */  String rVersion;  /* format of version is m.n.u */  int rM = -1;   /* Major id  */  int rN = -1;   /* Minor id  */  int rU = -1;   /* Update id */  Sint32 idx;  CIMClass cRep;  // This function was created to implement PEP #43. It allows updates  // to the repository.  PEP #43 only allows updates to leaf classes.  // Superclasses and classes that have subclasses cannot be updated.  // Please reference PEP #43 for more information.  // Note: Updating the class was not done when an "class already exists  // exception" in cimmofParser::addClass() occurs because when it gets  // to the catch the class has been fully populated (it has inherited  // all the properties and qualifiers from the superclass).  This means  // that the Version and Experimental qualifers were propagated to child  // class.  This made checking whether a version or experimental change  // would occur difficult. This class, cimmofParser::updateClass(), will  // get the class, if it exists, from the repository and save off the  // version and experimental qualifiers so that it can be compared with  // qualifiers of the class in the mof files.  It it finds the class and  // the class cannot be updated, cimmofParser::addClass() will be notified  // that the class exists and send the same message that it has sent  // in the past.  In cases when the class cannot be modified due to that  // the allow experimental and allow version options have not be specified  // then an appropriate message will also be sent to cimmofParser::addClass().  // Note on Experimental qualifier:  // With the implementation of PEP #43 Experimental classes cannot be  // added to the repository unless the -aE option is specified in the  // cimmof/cimmofl CLIs.  // Note on Version qualifier:  // Classes that cause a Major update (the m in m.n.u is changed) will  // require that the -aV option be specified.  Classes that cause a  // Down Revision will also require that the -aV option be specified.  // If the version of the class in the mof file has the same version  // as the class in the repository the class will not be updated.  // Classes with the same version are considered the same.  // The version specified in the Version qualifier will be checked for  // a valid format.  A valid version format is m.n.u (m is major, n is minor,  // and u is update).  Examples of valid version are 2, 2.7, 2.7.0  // Get the class from the repository  try  {    cRep = _repository.getClass(getNamespacePath(), classdecl.getClassName());  }  catch (const CIMException &e)  {    if (e.getCode() == CIM_ERR_NOT_FOUND)    {        classExist = false;    }    else    if (e.getCode() == CIM_ERR_INVALID_CLASS)    {        /* Note:  this is where cimmofl and cimmof fall into */        classExist = false;    }    else    {        throw;    }  }  // Get the experimental qualifier from the input class  idx = classdecl.findQualifier(EXPERIMENTAL);  if (idx >= 0)  {      CIMConstQualifier iExp = classdecl.getQualifier(idx);      CIMValue iExpVal = iExp.getValue();      iExpVal.get(iExperimental);  }  // Get the version qualifier from the input class  idx = classdecl.findQualifier(VERSION);  // A version was found for the input class  if (idx >= 0)  {      CIMConstQualifier iVer = classdecl.getQualifier(idx);      CIMValue iVerVal = iVer.getValue();      iVerVal.get(iVersion);  }  // Get experimental and version qualifiers from the repository class  if (classExist)  {      // Get the experimental qualifier from the repository class      idx = cRep.findQualifier(EXPERIMENTAL);      if (idx >= 0)      {          CIMQualifier rExp = cRep.getQualifier(idx);          CIMValue rExpVal = rExp.getValue();          rExpVal.get(rExperimental);      }      // Get the version qualifier from the repository class      idx = cRep.findQualifier(VERSION);      if (idx >= 0)      {          CIMQualifier rVer = cRep.getQualifier(idx);          CIMValue rVal = rVer.getValue();          rVal.get(rVersion);      }  }  // Verify version format specified in the Version qualifier of mof class  if (!verifyVersion(iVersion, iM, iN, iU))  {       updateMessage = cimmofMessages::INVALID_VERSION_FORMAT;       return false;  }  // Verify version format specified in the Version qualifier of repository class  if (!verifyVersion(rVersion, rM, rN, rU))  {       updateMessage = cimmofMessages::INVALID_VERSION_FORMAT;       return false;  }  //  // The following code was modeled after the algorithm in PEP 43.  //  if (!classExist)  {      // Will create an experimental class in the repository      if (iExperimental)      {          if (!_cmdline->allow_experimental())          {              /* PEP43: ID = 1 */              //printf("ID=1 (NoAction): Does Not Exist. -aE not set.\n");              updateMessage = cimmofMessages::NO_EXPERIMENTAL_UPDATE;              return false;          }          else          {              /* PEP43: ID = 2 */              //printf("ID=2 (CreateClass): Does Not Exist. -aE set.\n");          }      }      else      {          /* PEP43: ID = 3 */          //printf("ID=3 (CreateClass): Does Not Exist. Not Experimental.\n");      }  }  else  {      if (!_cmdline->update_class())      {          /* PEP43: ID = 4 */          //printf("ID=4 (NoAction): Exists. -uC not set.\n");          updateMessage = cimmofMessages::NO_CLASS_UPDATE;          return false;      }      // Will create an experimental class in the repository      if (!rExperimental && iExperimental)   /* FALSE->TRUE */      {          if (!_cmdline->allow_experimental())          {              /* PEP43: ID = 5 */              //printf("ID=5 (NoAction): Exists. -aE not set.\n");              updateMessage = cimmofMessages::NO_EXPERIMENTAL_UPDATE;              return false;          }          // Some examples:          // Requires minor and update ids in repository and mof to be set with the          // exception of the major id          // 2.7.0->NULL (ex. repository has 2.7.0 and mof has no version)          // 2.7.0->3.x.x or 2.7.0->1.x.x (Major Update)          // 2.7.0->2.6.x                 (Down Revision of minor id)          // 2.7.1->2.7.0                 (Down Revision of update id)          if ((rM >= 0  &&  iM < 0) ||                     /* remove version (Version->NULL) */              (iM != rM  &&  rM >= 0) ||                   /* Major Update (up or down)      */              (iN < rN  &&  rN >= 0 && iN >= 0) ||         /* Down Revision of minor id      */              (iU < rU  &&  rU >= 0 && iU >= 0 && rN==iU)) /* Down Revision of update id     */          {              if (!_cmdline->allow_version())              {                  /* PEP43: ID = 6 */                  //printf("ID=6 (No Action): Exists. -aV not set.\n");                  updateMessage = cimmofMessages::NO_VERSION_UPDATE;                  return false;              }              else              {                  /* ID = 7 */                  //printf("ID=7: (ModifyClass): Exists. -aEV set. (Major Update, Down Revision, Version->NULL)\n");              }          }          else          {             // Some examples:             // NULL->x.x.x (ex. repository has no version and mof has x.x.x)             // 2.7.0->2.8.x   (minor update of minor id )             // 2.7.0->2.7.1   (minor update of update id )             // 2.7.9->2.8.0   (minor update of both minor and update id)             if ((rM < 0)  ||              /* add a version (NULL->Any) */                 (iN > rN && rN >= 0) ||   /* minor update of minor id  */                 (iU > rU && rU >= 0))     /* minor update of update id */             {                 /* PEP43: ID = 8 */                 //printf("ID=8 (ModifyClass): Exists. -aE set. (Minor Update, NULL->Any)\n");             }             else             {                 // Some examples:                 // 2.7.0->2.7.0 (ex. repository has 2.7.0 and mof has 2.7.0)                 // 2    ->2.0.0 or 2.0.0->2   (equates to same version)                 // 2.7  ->2.7.0 or 2.7.0->2.7 (equates to same version)                 /* PEP43: ID = 9 --> Same Version */                 //printf("ID=9 (NoAction): Exists. Same Version.\n");                 updateMessage = cimmofMessages::SAME_VERSION;                 return false;             }          }      }      else      {          // Will not create an experimental class in the repository or          // class in the repository is already experimental          if ((rExperimental && iExperimental) ||        /* TRUE->TRUE */              (!iExperimental))                          /* Any->FALSE */          {              // See above for examples...ID=6              if ((rM >= 0  &&  iM < 0) ||                     /* remove version (Version->NULL) */                  (iM != rM  &&  rM >= 0) ||                   /* Major Update (up or down)      */                  (iN < rN  &&  rN >= 0 && iN >= 0) ||         /* Down Revision of minor id      */                  (iU < rU  &&  rU >= 0 && iU >= 0 && rN==iU)) /* Down Revision of update id     */              {                  if (!_cmdline->allow_version())                  {                      /* PEP43: ID = 10 */                      //printf("ID=10 (NoAction): Exists. -aV not set.\n");                      updateMessage = cimmofMessages::NO_VERSION_UPDATE;                      return false;                  }                  else                  {                      /* ID = 11 */                      //printf("ID=11 (ModifyClass): Exists. -aV set. (Major Update, Down Revision, Version->NULL)\n");                  }              }              else              {                 // See above for examples...ID=8                 if ((rM < 0)  ||              /* add a version (NULL->Any) */                     (iN > rN && rN >= 0) ||   /* minor update of minor id  */                     (iU > rU && rU >= 0))     /* minor update of update id */                 {                     /* PEP43: ID = 12 */                     //printf("ID=12 (ModifyClass): Exists: (Minor Update, NULL->Any)\n");                 }                 else                 {                     /* PEP43: ID = 13 --> Same Version */                     // See above for examples...ID=9                     //printf("ID=13 (NoAction): Exists. Same Version.\n");                     updateMessage = cimmofMessages::SAME_VERSION;                     return false;                 }              }          }      }  }  return ret;}BooleancimmofParser::verifyVersion(const String &version, int &iM, int &iN, int &iU){  Boolean ret = true;  int pos  = -1;  int posM = -1;   /* Major  */  int posN = -1;   /* Minor  */  int posU = -1;   /* Update */  // Parse the input version  if (version.size())  {      // If "V" specified as first character go ahead and ignore      if ((version[0] >= '0') && (version[0] <= '9'))      {          pos = 0;          posM = version.find(0, CHAR_PERIOD);      }      else      {          pos = 1;          if (String::equalNoCase(version.subString(0,1), "V"))          {              posM = version.find(1, CHAR_PERIOD);          }          else          {              // First character is unknown.              // Examples of invalid version:  ".2.7", ".", "..", "...", "AB"              return false;          }      }      // Find the second and possible third period      if (posM >=0)      {          posN = version.find(posM+1, CHAR_PERIOD);      }      if (posN >= 0)      {          posU = version.find(posN+1, CHAR_PERIOD);      }      // There should be no additional identifiers after the update identifier      if (posU >= 0)      {          // Examples of invalid version:  "2.7.0.", "2.7.0.1", "2.7.0.a", "2.7.0.1."          return false;      }      // Check for trailing period      if ((posM >=0 && posM+1 == (int)version.size()) ||          (posN >=0 && posN+1 == (int)version.size()) ||          (posU >=0 && posU+1 == (int)version.size()))      {          // Examples of invalid version:  "2.", "2.7.", "V.", "9.."          return false;      }      // Major identifier is not specified      if (((pos > 0) && (posM < 0) && (!version.subString(pos).size())) ||          ((pos > 0) && (posM >= 0) && (posM <= pos)))      {          // Examples of invalid version: "V.2.7", "V"          return false;      }      // Check Major identifier for invalid format      int endM = posM;      if (posM < 0)      {         endM = version.size();      }      for (int i = pos; i < endM; i++)      {           if (!((version[i] >= '0') && (version[i] <= '9')))           {               // Example of invalid version:  "1B.2D.3F"               return false;           }      }      // Minor identifier is not specified      if (posM+1 == posN)      {          // Example of invalid version:  "2..9"          return false;      }      // Check Minor identifier for invalid format      if (posM > 0)      {          int endN = posN;          if (posN < 0)          {              endN = version.size();          }          for (int i = posM+1; i < endN; i++)          {               if (!((version[i] >= '0') && (version[i] <= '9')))               {                   // Example of invalid version:  "99.CD", "11.2D.3F"                   return false;               }          }      }      // Check Update identifier for invalid format      if (posN > 0)      {          for (int i = posN+1; i < (int)version.size(); i++)          {               if (!((version[i] >= '0') && (version[i] <= '9')))               {                    // Example of invalid version: "99.88.EF", "11.22.3F"                    return false;               }          }      }      // Set major, minor, and update values as integers      if (posM >= 0)      {          iM = atoi((const char*)(version.subString(pos, posM).getCString()));          if (posN >= 0)          {              iN = atoi((const char*)(version.subString(posM+1, posN).getCString()));              iU = atoi((const char*)(version.subString(posN+1).getCString()));          }          else          {              iN = atoi((const char*)(version.subString(posM+1).getCString()));          }      }      else      {          iM = atoi((const char*)(version.subString(pos).getCString()));      }  }  return ret;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -