Пример #1
0
int AXmlElement::getInt(const AString& path, int iDefault) const
{
  AString str;
  if (emitContentFromPath(path, str))
    return str.toInt();
  else
    return iDefault;
}
Пример #2
0
size_t AFragmentString::parse(const AString& str)
{
  size_t iRet = AConstant::npos;
  size_t iX = 0;
  AString strHold;
  while(iX < str.getSize())
  {
    switch(str[iX])
    {
      case '\\' :
      { 
        ++iX;
        if (str.getSize() > iX)
        {
          strHold += str[iX];
          iRet = iX;
        }
        else
        {
          //a_String truncated
          iRet = iX - 1;
          return iRet;
        }
      }
      break;

      case '(' :
      {
        iX++;
        if (str.getSize() > iX)
        {
          size_t iF = str.find(')', iX+1);
          if (iF != AConstant::npos)
          {
            AASSERT(this, iF >= iX);
            if (!strHold.isEmpty()) { m_Container.push_back(new AFragmentConstant(strHold)); strHold.clear(); iRet = iX-1; }
            AString strT;
            str.peek(strT, iX, iF-iX);
            iX = iF;  // advance offset after extraction

            u1 b;
            u4 n[2];
            
            b = (u1)strT.toInt();
            if (b > 9)
              b = 9;
            if ((iF = strT.find(',')) == AConstant::npos)
            {
              // Only 1 number, the digit value
              long stop = 10;
              for (int i=1; i<b; ++i)
                stop *= 10;
              m_Container.push_back(new AFragmentCounter(b, u4(stop-1)));
            }
            else
            {
              AString str1;
              strT.peek(str1, iF + 1);
              if ((iF = str1.find(',')) == AConstant::npos)
              {                             
                n[0] = str1.toU4();
                m_Container.push_back(new AFragmentCounter(b, n[0]));
              }
              else
              {
                AString strQ;
                str1.peek(strQ, 0, iF);
                n[0] = strQ.toU4();
                strQ.clear();
                str1.peek(strQ, iF+1);
                n[1] = strQ.toU4();
                if ((iF = str1.find(',', iF+1)) == AConstant::npos)
                  m_Container.push_back(new AFragmentCounter(b, n[0], n[1]));
                else {
                  strQ.clear();
                  str1.peek(strQ, iF+1);
                  m_Container.push_back(new AFragmentCounter(b, n[0], n[1], strQ.toInt()));
                }
              }
            }
            iRet = iX;
          }
          else 
          {
            //a_Closing tag not found
            iRet = iX-1;
            return iRet;
          }
        }
        else
        {
          //a_String is truncated
          iRet = iX-1;
          return iRet;
        }
      }
      break;

      case '{' :
      {
        ++iX;
        if (str.getSize() > iX)
        {
          size_t iF = str.find('}', iX+1);
          if (!strHold.isEmpty()) { m_Container.push_back(new AFragmentConstant(strHold)); strHold.clear(); iRet = iX-1;}
          if (iF != AConstant::npos)
          {
            AASSERT(this, iF >= iX);
            AString strT;
            str.peek(strT, iX, iF-iX);
            char cX;
            while (!strT.isEmpty())
            {
              cX = strT.get();
              switch (cX)
              {
                case '#': m_Container.push_back(new AFragmentSet(AFragmentSet::Numeric)); break;
                case '&': m_Container.push_back(new AFragmentSet(AFragmentSet::LowercaseAlpha)); break;
                case '@': m_Container.push_back(new AFragmentSet(AFragmentSet::UppercaseAlpha)); break;
                case '%': m_Container.push_back(new AFragmentSet(AFragmentSet::LowercaseAlphaNumeric)); break;
                case '^': m_Container.push_back(new AFragmentSet(AFragmentSet::UppercaseAlphaNumeric)); break;
                case '?': m_Container.push_back(new AFragmentSet(AFragmentSet::AlphaNumeric)); break;
                default : strHold += cX;
              }
            }
            iX = iF;
            iRet = iX;
          }
          else
          {
            //a_Closing tag not found
            iRet = iX-1;
            return iRet;
          }
        }
        else
        {
          //a_String is truncated
          iRet = iX-1;
          return iRet;
        }
      }
      break;

      case '[' :
      {
        size_t iF = str.find(']', iX+1);
        if (iF != AConstant::npos)
        {
          AASSERT(this, iF >= iX);
          if (!strHold.isEmpty()) { m_Container.push_back(new AFragmentConstant(strHold)); strHold.clear(); }
          AString strT;
          str.peek(strT, iX + 1, iF - iX - 1);
          m_Container.push_back(new AFragmentSet(strT));
          iX = iF;
          iRet = iX;
        }
        else
        {
          //a_Closing tag not found, return iRet at point of error
          iRet = iX;
          return iRet;
        }
      }
      break;

      case '<' :
      {
        size_t iF = str.find('>', iX+1);
        if (iF != AConstant::npos)
        {
          AASSERT(this, iF >= iX);
          if (!strHold.isEmpty()) { m_Container.push_back(new AFragmentConstant(strHold)); strHold.clear(); }
          AString strT;
          str.peek(strT, iX + 1, iF - iX - 1);
          m_Container.push_back(new AFragmentOdometer(strT.toSize_t()));
          iX = iF;
          iRet = iX;
        }
        else
        {
          //a_Closing tag not found, return iRet at point of error
          iRet = iX;
          return iRet;
        }
      }
      break;

      default  : 
        strHold += str[iX];
        iRet = iX;
    }
    iX++;
  }

  if (!strHold.isEmpty()) {
    m_Container.push_back(new AFragmentConstant(strHold));
  }

  //a_If we got here we have succeeded
  iRet = iX;
  m_Finished = false;

  return iRet;
}
Пример #3
0
void AOSContextManager::adminProcessAction(AXmlElement& eBase, const AHTTPRequestHeader& request)
{
  AString str;
  if (request.getUrl().getParameterPairs().get(ASW("property",8), str))
  {
    if (str.equals(ASWNL("AOSContextManager.log_level")))
    {
      str.clear();
      if (request.getUrl().getParameterPairs().get(ASW("Set",3), str))
      {
        int level = str.toInt();
        if (level >= AEventVisitor::EL_NONE && level <= AEventVisitor::EL_DEBUG)
        {
          m_DefaultEventLogLevel = level;
        }
        else
        {
          adminAddError(eBase, ASWNL("Invalid log level, must be (0-5)"));
        }
      }
    }
    else if (str.equals(ASWNL("AOSContextManager.clear_history")))
    {
      str.clear();
      if (request.getUrl().getParameterPairs().get(ASW("Clear",5), str))
      {
        int level = str.toInt();
        switch(level)
        {
          case 0:
            _clearHistory();
            _clearErrorHistory();
          break;

          case 1:
            _clearHistory();
          break;

          case 2:
            _clearErrorHistory();
          break;

          default:
            adminAddError(eBase, ASWNL("Invalid level for history clearing, must be (0,1,2)"));
        }
      }
    }
    else if (str.equals(ASWNL("AOSContextManager.history.max_size")))
    {
      str.clear();
      if (request.getUrl().getParameterPairs().get(ASW("Set",3), str))
      {
        int i = str.toInt();
        if (i >= 0)
        {
          m_HistoryMaxSize = i;
        }
        else
        {
          adminAddError(eBase, ASWNL("Invalid maximum size, must be >=0"));
        }
      }
    }
    else if (str.equals(ASWNL("AOSContextManager.error_history.max_size")))
    {
      str.clear();
      if (request.getUrl().getParameterPairs().get(ASW("Set",3), str))
      {
        int i = str.toInt();
        if (i >= 0)
        {
          m_ErrorHistoryMaxSize = i;
        }
        else
        {
          adminAddError(eBase, ASWNL("Invalid maximum size, must be >=0"));
        }
      }
    }
    else if (str.equals(ASWNL("AOSContextManager.freestore.max_size")))
    {
      str.clear();
      if (request.getUrl().getParameterPairs().get(ASW("Set",3), str))
      {
        int i = str.toInt();
        if (i >= 0)
        {
          m_FreeStoreMaxSize = i;
        }
        else
        {
          adminAddError(eBase, ASWNL("Invalid maximum size, must be >=0"));
        }
      }
    }
  }
}