void SmartMote::config(){
    AString conf;
    AStringList * param = NULL;
    bool flag;
    /*  se il bottone non è premuto                                             */
    if(!checkButton()){
        /*  ritorno                                                             */
        return;
    }
    /*  accendo l'uart                                                          */
    openUART();
    /*  inizializzo il modulo come AP                                           */
    if(!m_net.initialize(AESP07::APMode)){
        /*  se fallisce notifico l'errore                                       */
        error();
    }
    /*  setto il nome come SmartMote e password admin                           */
    if(!m_net.configureAP("SmartMote", "smartmote")){
        /*  se fallisce notifico l'errore                                       */
        error();        
    }
    /*  imposto l'ip a 192.168.1.1                                              */
    if(!m_net.setIp(AESP07::APMode, "192.168.1.1")){
        /*  se fallisce notifico l'errore                                       */
        error();        
    }
    /*  disabilito le connessioni multiple                                      */
    if(!m_net.setMultipleConnections(false)){
        /*  se fallisce notifico l'errore                                       */
        error();                
    }
    /*  apro il server sulla porta 8000                                         */
    if(!m_net.listen(8000)){
        /*  se fallisce notifico l'errore                                       */
        error();
    }
    /*  aspetto di ricevere la stringa                                          */
    while(conf.isEmpty()){
        
        m_net.waitForData(conf);
    }
    /*  prendo i parametri                                                      */
    param = conf.split(' ');
    /*  se la stringlist è allocata correttamente                               */
    if(param){
        saveSSID(param->at(0));
        saveKey(param->at(1));
        saveHost(param->at(2));
        RTCC.setHours(static_cast<uint32>(param->at(3).toInt32(flag)));
        RTCC.setMinutes(static_cast<uint32>(param->at(3).toInt32(flag)));
        RTCC.setSeconds(static_cast<uint32>(param->at(3).toInt32(flag)));
    }else{
        /*  altrimenti notifico l'errore                                        */
        error();
    }
    /*  spengo i led                                                            */
    turnOffRed();
    turnOffGreen();
}
Beispiel #2
0
size_t AMySQLServer::executeSQL(const AString& sqlQuery, AResultSet& target, AString& error)
{
  target.clear();
  MYSQL_RES *pmyresult = executeSQL(sqlQuery, error);
  if (!pmyresult && !error.isEmpty())
    return AConstant::npos;

  target.useSQL().assign(sqlQuery);
  
  return (pmyresult ? _processQueryAllRows(pmyresult, target) : 0);
}
Beispiel #3
0
void ATemplateNodeHandler_DADA::_loadStaticData()
{
  AXmlElement::CONST_CONTAINER nodes;

  m_Services.useConfiguration().getConfigRoot().find("AOS_DadaData/dataset", nodes);
  AXmlElement::CONST_CONTAINER::iterator it;
  for (it = nodes.begin(); it != nodes.end(); ++it)
  {
    AString strSet;
    (*it)->getAttributes().get(ASW("name",4), strSet);
    if (strSet.isEmpty())
      ATHROW_EX(*it, AException::InvalidData, ASWNL("AOS_DadaData/dataset missing 'name' parameter"));

    ADadaDataHolder *pddh = new ADadaDataHolder();
    pddh->readData(m_Services, *it);
    m_Objects.insert(strSet, pddh, true);
  }

  nodes.clear();
  m_Services.useConfiguration().getConfigRoot().find(ASW("AOS_DadaData/template",21), nodes);
  it = nodes.begin();
  while (it != nodes.end())
  {
    AString str;
    (*it)->emitContent(str);
    
    AString strName;
    if ((*it)->getAttributes().get(ASW("name",4), strName))
    {
      AFilename filename(m_Services.useConfiguration().getAosBaseDataDirectory(), str, false);
      if (AFileSystem::exists(filename))
      {
        AFile_Physical file(filename, ASW("r", 1));
        file.open();

        str.clear();
        while (AConstant::npos != file.readLine(str))
        {
          if ('#' != str.at(0, '\x0'))
          {
            m_Templates[strName].push_back(str);
          }
          str.clear();
        }
      }
      else
        m_Services.useLog().add(ARope("AOS_DadaData: Missing file: ")+filename, ALog::EVENT_WARNING);
    }
    else
      m_Services.useLog().add(ASWNL("AOS_DadaData: AOS_DadaData/template missing 'name' attribute"), ALog::EVENT_FAILURE);

    ++it;
  }
}
Beispiel #4
0
void ATemplateNodeHandler_DADA::Node::_generateLine(ADadaDataHolder *pddh, MAP_AString_AString& globals, const AString& format, ATemplateContext& context, AOutputBuffer& output)
{
  if (format.isEmpty())
    return;
  
  AFile_AString file(format);
  size_t readresult;
  char c = '\x0';
  AString target(1024, 1024), strType(64,128);
  while (AConstant::npos != file.readUntil(target, S_DELIM_START, true, true))
  {
    file.read(c);
    readresult = file.readUntil(strType, S_DELIM_END, true, true);
    if (0 == readresult)
    {
      file.readUntilEOF(target);
      output.append(target);
      target.clear();
      break;
    }

    //a_If not EOF process type
    if (AConstant::npos != readresult)
    {
      if (strType.getSize() > 1)
      {
        switch (c)
        {
          case '%':
            //a_Process the tag {%type:tag,tag,...}
            _appendWordType(pddh, globals, strType, target);
          break;

          case '$':
            //a_ {$variable}
            _appendVariable(pddh, globals, strType, target);
          break;

          default:
            //a_Passthru of unknown tags
            target.append('{');
            target.append(strType);
            target.append('}');
            context.useEventVisitor().addEvent(ASWNL("ATemplateNodeHandler_DADA::Node:") + " unknown type:" + strType, AEventVisitor::EL_WARN);
          break;
        }
        strType.clear(); 
      }
    }
  }
  file.readUntilEOF(target);
  output.append(target);
  target.clear();
}
Beispiel #5
0
void AOSAdminRegistry::insert(const AString& name, AOSAdminInterface& object)
{
  if (name.isEmpty())
    ATHROW(this, AException::InvalidParameter);


  if (m_AdminObjects.find(name) != m_AdminObjects.end())
    m_Log.add(ASWNL("Admin object already registered"), name, ALog::EVENT_WARNING);

  //a_Insert/replace
  m_AdminObjects[name] = &object;
}
Beispiel #6
0
int AWordUtility::splitSyllables(const AString& source, VECTOR_AString& result, bool handleSilentTrailing /* = true */)
{
  if (source.isEmpty())
    return 0;

  AString word(source);
  
  if (handleSilentTrailing)
    word.stripTrailing(msstr_SilentEnd);

  int count = 0;

  size_t start = 0;
  size_t pos = word.findOneOf(msstr_SyllableSeparators);
  while (AConstant::npos != pos)
  {
    AString str;
    word.peek(str, start, pos - start + 1);
    result.push_back(str.c_str());

    ++count;

    start = pos+1;
    pos = word.findNotOneOf(msstr_SyllableSeparators, start);
    if (AConstant::npos != pos)
      pos = word.findOneOf(msstr_SyllableSeparators, start);
  }

  if (start < word.getSize())
  {
    //a_Append leftovers to last word
    AString str;
    word.peek(str, start);
    if (count > 0)
      result.back().append(str);
    else
      result.push_back(str);
  }

  //a_Account for the silent trailing letters
  if (handleSilentTrailing && word.getSize() < source.getSize())
  {
    AString str;
    source.peek(str, word.getSize());
    if (count > 0)
      result.back().append(str);
    else
      result.push_back(str);
  }

  return count;
}
Beispiel #7
0
size_t AWordUtility::getRhymeLevel(const AString& wordOne, const AString& wordTwo)
{
  //a_Check if one or both are empty
  if (wordOne.isEmpty() || wordTwo.isEmpty())
    return 0;

  AString endOne, soundOne;
  AString endTwo, soundTwo;
  AWordUtility::getPhoneticForm(wordOne, endOne);
  AWordUtility::getPhoneticForm(wordTwo, endTwo);
  AWordUtility::getSoundsLikeForm(endOne, soundOne);
  AWordUtility::getSoundsLikeForm(endTwo, soundTwo);
  
  std::cout << endOne << ":" << endTwo << "=";
  std::cout << soundOne << ":" << soundTwo << std::endl;

  soundOne.reverse();
  soundTwo.reverse();

  size_t level = (soundOne.getSize() > soundTwo.getSize() ? soundOne.diff(soundTwo) : soundTwo.diff(soundOne));
  return level;
}
Beispiel #8
0
void AFilename::setExtension(const AString& ext)
{
  size_t pos = m_Filename.rfind('.');
  if (AConstant::npos != pos)
  {
    m_Filename.setSize(pos);
  }

  //a_Set extension if any, else clear extension
  if (!ext.isEmpty())
  {
    m_Filename.append('.');
    m_Filename.append(ext);
  }
}
Beispiel #9
0
int AWordUtility::countSyllables(const AString& source)
{
  if (source.isEmpty())
    return 0;

  int count = 0;
  AString word(source);
  word.stripTrailing(msstr_SilentEnd);

  size_t pos = word.findOneOf(msstr_SyllableSeparators);
  while (AConstant::npos != pos)
  {
    ++count;
    pos = word.findNotOneOf(msstr_SyllableSeparators, pos+1);
    if (AConstant::npos != pos)
      pos = word.findOneOf(msstr_SyllableSeparators, pos+1);
  }

  return count;
}
Beispiel #10
0
bool AMySQLServer::getFields(const AString& table, VECTOR_AString& sv, AString& error)
{
  if (!isInitialized())
  {
    error.assign("Database has not been initialized;");
    return false;
  }

  if (table.isEmpty())
  {
    error = "Please use a namespace;";
    return false;
  }

  sv.clear();

  AString query("SHOW COLUMNS FROM `");
  query += table;
  query += "`";
  
  MYSQL_RES *pmyresult = executeSQL(query, error);
  if (pmyresult)
  {
    MYSQL_ROW myrow;
    int iSize = (int)mysql_num_rows(pmyresult);
    for (int i=0; i < iSize; ++i)
    {
      myrow = mysql_fetch_row(pmyresult);
      if (myrow)
      {
        sv.push_back(myrow[0]);
      }
    }

    mysql_free_result(pmyresult);
  }
  else
    return false;

  return true;
}
Beispiel #11
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;
}
Beispiel #12
0
int ut_AString_Access()
{
  std::cerr << "ut_AString_Access" << std::endl;

  int iRet = 0x0;

  //a_Peeking
  AString strPeek;
  AString str0 = "SomethingNew";
  str0.peek(strPeek, 0);
  ASSERT_UNIT_TEST(strPeek == "SomethingNew", "AString::peek", "0", iRet);

  strPeek.clear();
  str0.peek(strPeek, 0, 9);
  ASSERT_UNIT_TEST(strPeek == "Something", "AString::peek", "1", iRet);

  strPeek.clear();
  str0.peek(strPeek, 9, 3);
  ASSERT_UNIT_TEST(strPeek == "New", "AString::peek", "2", iRet);
  ASSERT_UNIT_TEST(str0.peek(4) == 't', "AString::peek", "3", iRet);

  int pos0 = 0;
  str0 = "path0/path1/path2";
  strPeek.clear();
  pos0 = str0.peekUntil(strPeek, pos0, '/');
  ASSERT_UNIT_TEST(strPeek.equals("path0"), "AString::peekUntil", "0", iRet);

  strPeek.clear();
  pos0 = str0.peekUntil(strPeek, pos0+1, '/');
  ASSERT_UNIT_TEST(strPeek.equals("path1"), "AString::peekUntil", "1", iRet);

  strPeek.clear();
  pos0 = str0.peekUntil(strPeek, pos0+1, '/');
  ASSERT_UNIT_TEST(strPeek.equals("path2"), "AString::peekUntil", "2", iRet);
  ASSERT_UNIT_TEST(AConstant::npos == pos0, "AString::peekUntil", "3", iRet);

  //a_Set
  AString strSource0 = AString("New"), strSource1("Newer"), strSource2("123Now");
  str0 = "This is old";
  str0.set(strSource0, 8);
  ASSERT_UNIT_TEST(str0.equals("This is New"), "AString::set", "0", iRet);

  str0.set(strSource1, 8);
  ASSERT_UNIT_TEST(str0.equals("This is Newer"), "AString::set", "1", iRet);

  str0.set(strSource2, 8, 3, 3);
  ASSERT_UNIT_TEST(str0.equals("This is Now"), "AString::set", "2", iRet);

  str0.set('n', 8);
  ASSERT_UNIT_TEST(str0.equals("This is now"), "AString::set", "3", iRet);

  //a_Use
  str0.use(10) = 't';
  ASSERT_UNIT_TEST(str0.peek(10) == 't', "AString::use", "0", iRet);

  //a_Get
  AString strGet;
  str0 = "YetMoreStuff!";
  str0.get(strGet, 0, 3);
  ASSERT_UNIT_TEST(strGet.equals("Yet"), "AString::get", "0", iRet);

  str0.get(strGet, 0, 4);
  ASSERT_UNIT_TEST(strGet.equals("More"), "AString::get", "1", iRet);

  str0.get(strGet, 0, 5);
  ASSERT_UNIT_TEST(strGet.equals("Stuff"), "AString::get", "2", iRet);

  str0.get(strGet, 0, 0);
  ASSERT_UNIT_TEST(strGet.isEmpty(), "AString::get", "3", iRet);

  char cX = str0.get();
  ASSERT_UNIT_TEST(cX == '!', "AString::get", "4", iRet);
  ASSERT_UNIT_TEST(strGet.isEmpty(), "AString::get", "5", iRet);

  str0 = "SomeMoreStuff!";
  str0.get(strGet, 0);
  ASSERT_UNIT_TEST(strGet.equals("SomeMoreStuff!"), "AString::get", "6", iRet);
  ASSERT_UNIT_TEST(str0.isEmpty(), "AString::get", "7", iRet);
 
  str0 = "SomeMoreStuff!";
  str0.get(strGet, 0, 0);
  ASSERT_UNIT_TEST(str0.equals("SomeMoreStuff!"), "AString::get", "8", iRet);
  ASSERT_UNIT_TEST(strGet.isEmpty(), "AString::get", "9", iRet);

  str0 = "path0/path1/path2";
  str0.getUntil(strGet, '/');
  ASSERT_UNIT_TEST(strGet.equals("path0"), "AString::getUntil", "0", iRet);

  str0.getUntil(strGet, '/');
  ASSERT_UNIT_TEST(strGet.equals("path1"), "AString::getUntil", "1", iRet);

  str0.getUntil(strGet, '/');
  ASSERT_UNIT_TEST(strGet.equals("path2"), "AString::getUntil", "2", iRet);

  str0.getUntil(strGet, '/');
  ASSERT_UNIT_TEST(str0.isEmpty(), "AString::getUntil", "3", iRet);

  AString str1;
  str0="find_file_1";
  str0.peekUntil(str1, 2, "1");
  ASSERT_UNIT_TEST(!str1.compare("nd_file_"), "AString::peekUntil", "0", iRet);

  str0.getUntil(str1, "_", true);
  ASSERT_UNIT_TEST((!str1.compare("find") && !str0.compare("file_1")), "AString::getUntil", "4", iRet);

  str0="find_file_1";
  str0.getUntilOneOf(str1, ASW("_",1), false);
  ASSERT_UNIT_TEST((!str1.compare("find") && !str0.compare("_file_1")), "AString::getUntil", "5", iRet);

  str0.remove(1);
  str1.clear();
  str0.getUntil(str1, ASW("_",1));
  ASSERT_UNIT_TEST((!str1.compare("file") && !str0.compare("1")), "AString::getUntil", "6", iRet);

  return iRet;
}
Beispiel #13
0
AOSContext::ReturnCode AOSModule_Template::execute(AOSContext& context, const AXmlElement& params)
{
  const AXmlElement *pNode = params.findElement(ASW("template",8));
  AAutoPtr<ATemplate> pTemplate(NULL, false);
  AAutoPtr<AFile> pFile(NULL, false);
  if (pNode)
  {
    //a_Element contains script
    pTemplate.reset(m_Services.createTemplate(), true);
    
    //a_Parse template
    AFile_AString strfile;
    pNode->emitContent(strfile);
    pTemplate->fromAFile(strfile);
  }
  else
  {
    //a_Filename provided, use the cache
    pNode = params.findElement(AOS_BaseModules_Constants::FILENAME);
    if (pNode)
    {
      AString relativePath;
      pNode->emitContent(relativePath);

      //a_File to be used (may need caching for it, but for now keep it dynamic)
      AFilename filename(m_Services.useConfiguration().getAosBaseDataDirectory(), true);
      filename.join(relativePath, false);
      if (ACacheInterface::NOT_FOUND == m_Services.useCacheManager().getTemplate(context, filename, pTemplate))
      {
        //a_Not found, return error
        ARope rope;
        rope.append(getClass());
        rope.append(": Unable to find a template file: ",34);
        rope.append(filename);
        context.useEventVisitor().startEvent(rope, AEventVisitor::EL_ERROR);
        return AOSContext::RETURN_ERROR;
      }
    }
    else
    {
      context.addError(getClass(), ASWNL("Unable to find module/template nor module/filename, Template module did not execute, params"));
      return AOSContext::RETURN_ERROR;  //a_Did not find either module/template or module/filename
    }
  }  

  //a_Process and save output
  ARope ropeOutput;
  pTemplate->process(context.useLuaTemplateContext(), ropeOutput);
  
  //a_Add template to debug
  if (context.getDumpContextLevel() > 0)
  {
    AString str("debug/",6);
    str.append(getClass());
    str.append("/template",9);
    AXmlElement& base = context.useModel().addElement(str);
    pTemplate->emitXml(base);
  }

  //a_Insert output into outpath (if any)
  pNode = params.findElement(AOS_BaseModules_Constants::PATH);
  if (pNode)
  {
    AString xmlpath;
    pNode->emitContent(xmlpath);
    if (!xmlpath.isEmpty())
    {
      //a_Add output as CDATA
      context.useModel().addElement(xmlpath).addData(ropeOutput, AXmlElement::ENC_CDATADIRECT);
    }
  }
  else
  {
    context.useEventVisitor().addEvent(ASWNL("Unable to find module/path, output from template discarded"), AEventVisitor::EL_WARN);
  }
  return AOSContext::RETURN_OK;
}
Beispiel #14
0
void ATextGenerator::generateFromTemplate(AOutputBuffer& target, const AString &strTemplate)
{
  if (strTemplate.isEmpty())
    return;
  
  //a_If the last is % and one before is not %, then expansion error will occur
  size_t end = strTemplate.getSize();
  if (strTemplate[end - 1] == '%')
  {
    if (end < 1)
    {
      //a_Force early termination
      end = 0;
    }
    else
      if (strTemplate[end - 2] != '%')
      {
        end--;
      }
  }
  
  char cEscape;
  for (size_t x = 0; x < end; ++x)
  {
    cEscape = strTemplate[x];
    if (cEscape == '%')
    {
      if (++x >= end)
        break;

      switch(strTemplate[x])
      {
        case '%' : break;
        
        case 'z' :
          target.append(AString::fromInt(si_Counter++));
          cEscape = '\x0';
        break;

        case 'n' :
          cEscape = generateRandomNumeral();
        break;

        case 'N' :
          if (ARandomNumberGenerator::get().nextRange(100) >= 50)
            cEscape = '+';
          else
            cEscape = '-';
        break;

        case 'l' :
          cEscape = generateRandomLowercaseLetter();
        break;

        case 'L' :
          cEscape = generateRandomUppercaseLetter();
        break;

        case 'r' :
          cEscape = (char)(ARandomNumberGenerator::get().nextRange(255) + 0x1);
        break;

        case 'R' :
          cEscape = ARandomNumberGenerator::get().nextU1();
        break;

        case 's' :
          cEscape = generateRandomUppercaseLetter();
          if (ARandomNumberGenerator::get().nextRange(100) >= 50)
            cEscape = (char)tolower(cEscape);
        break;
      
        case 't' :
          ATime().emitYYYYMMDDHHMMSS(target);
          cEscape = '\x0';
        break;
        
        case 'T' :
          ATime().emitRFCtime(target);
          cEscape = '\x0';
        break;

        default :
          //a_Escape character detected, but no valid control character found
          target.append(cEscape);          //a_Keep the sequence untouched
          cEscape = strTemplate[x];  //a_Current char becomes escape to stay consistent with the add to follow
      }
    }

    if (cEscape != '\x0')
      target.append(cEscape);
  }
}
Beispiel #15
0
void AWordUtility::getSoundexForm(const AString& source, AString& result, size_t minSize)
{
  result.clear();
  if (source.isEmpty())
    return;

  //a_First character appended as is
  AString str(source);
  str.makeLower();
  size_t sourceSize = str.getSize();

  size_t pos = 0;
  while (pos < sourceSize)
  {
    switch(str.at(pos))
    {
      case 'a':
      case 'e':
      case 'i':
      case 'o':
      case 'u':
      case 'h':
      case 'w':
      case 'y':
        break;
//---      
      case 'p':
        if (pos == 0 && sourceSize > 2)
        {
          if ('s' == str.at(pos+1))
          {
            break;  //a_ps => s at word start
          }
          else if ('h' == str.at(pos+1))
          {
            ++pos; //a_pf => f, fallthrough
          }
        }
      case 'b':
      case 'f':
      case 'v':
        if (!result.isEmpty())
        {
          if (str.at(pos) != result.at(result.getSize()-1))
            result.append('1');
        }
        else
            result.append('1');
        break;
//---      
      case 'd':
        if (pos+1 < sourceSize)
        {
          if ('g' == str.at(pos+1))
            break;        //a_dg => g
        }                 //a_Fallthough from d to t
      case 't':
        if (pos+1 < sourceSize && 'c' == str.at(pos+1))
        {
          if (pos+2 < sourceSize && 'h' == str.at(pos+2))
          {
            ++pos;
            break;  //a_tch => ch
          }
        }
        if (!result.isEmpty())
        {
          if (str.at(pos) != result.at(result.getSize()-1))
            result.append('3');
        }
        else
            result.append('3');
        break;
//---      
      case 'g':
        if (pos+1 < sourceSize)
        {
          if ('h' == str.at(pos+1))
          {
            if (pos+2 < sourceSize)
            {
              if ('t' == str.at(pos+2))
              {
                ++pos;
                break;   //a_ght => t
              }
              else
                break;   //a_gh => h
            }
          }
          else if ('n' == str.at(pos+1))
          {
            break;       //a_gn => n
          }
        } //a_Fallthrough

      case 'k':
        if (pos+1 < sourceSize && 'n' == str.at(pos+1))
        {
          break;       //a_kn => n
        }  //a_Fallthrough

      case 'c':
      case 'j':
      case 'q':
      case 's':
      case 'x':
      case 'z':
        if (!result.isEmpty())
        {
          if (str.at(pos) != result.at(result.getSize()-1))
            result.append('2');
        }
        else
            result.append('2');
        break;
//---      
      case 'l':
        if (!result.isEmpty())
        {
          if (str.at(pos) != result.at(result.getSize()-1))
            result.append('4');
        }
        else
            result.append('4');
        break;
//---      
      case 'm':
        if ('b' == str.at(pos+1, '\x0'))
        {
          ++pos;  //a_mb => m
        } //a_ Fallthrough
      case 'n':
        if (!result.isEmpty())
        {
          if (str.at(pos) != result.at(result.getSize()-1))
            result.append('5');
        }
        else
            result.append('5');
//---      
      case 'r':
        if (!result.isEmpty())
        {
          if (str.at(pos) != result.at(result.getSize()-1))
            result.append('6');
        }
        else
            result.append('6');
        break;
    }
    ++pos;
  }

  if (result.getSize() < minSize)
    result.setSize(minSize, '0');
}
Beispiel #16
0
/*
Distinct sound groups
  bfpvw
  mn
  sxz
  ckq
  gj
  dt
  l
  r

Vowels and ignored
  aeiouyh
*/
void AWordUtility::getSoundsLikeForm(const AString& source, AString& result)
{
  result.clear();
  if (source.isEmpty())
    return;

  //a_First character appended as is
  AString work(source);
  work.makeLower();
  size_t workSize = work.getSize();

  size_t pos = 0;
  while (pos < workSize)
  {
    switch(work.at(pos))
    {
      case 'b':
      case 'f':
      case 'p':
        result.append('p');
      break;

      case 'm':
      case 'n':
        result.append('m');
      break;

      case 's':
      case 'x':
      case 'z':
        result.append('s');
      break;

      case 'c':
      case 'k':
      case 'q':
        result.append('k');
      break;

      case 'g':
      case 'j':
        result.append('g');
      break;

      case 'd':
      case 't':
        result.append('d');
      break;

      case 'l':
        result.append('l');
      break;

      case 'r':
        result.append('r');
      break;

      case 'v':
      case 'w':
        result.append('v');
      break;
    }
    ++pos;
  }
}
Beispiel #17
0
void AOSOutputExecutor::execute(AOSContext& context)
{
  AString command;
  if (
    context.useRequestParameterPairs().exists(OVERRIDE_OUTPUT)
    && m_Services.useConfiguration().isOutputOverrideAllowed()
  )
  {
    //a_Override requested and allowed
    context.useRequestParameterPairs().get(OVERRIDE_OUTPUT, command);
  }
  else
  {
    command = context.getOutputCommand();
    if (context.useEventVisitor().isLogging(AEventVisitor::EL_DEBUG))
    {
      ARope rope("Default output generator overridden to: ",40);
      rope.append(command);
      context.useEventVisitor().startEvent(rope, AEventVisitor::EL_DEBUG);
    }
  }

  if (command.equals("NOP"))
  {
    //a_If NOP was used force XML
    m_Services.useConfiguration().setMimeTypeFromExt(ASW("xml",3), context);
    if (context.useEventVisitor().isLogging(AEventVisitor::EL_DEBUG))
      context.useEventVisitor().startEvent(ASWNL("NOP detected, defaulting to XML output"), AEventVisitor::EL_DEBUG);
  }

  if (command.isEmpty())
  {
    if (!m_Services.useConfiguration().getAosDefaultOutputGenerator().isEmpty())
    {
      command.assign(m_Services.useConfiguration().getAosDefaultOutputGenerator());
      if (context.useEventVisitor().isLogging(AEventVisitor::EL_DEBUG))
      {
        ARope rope("No output generator specified, defaulting to: ",46);
        rope.append(command);
        context.useEventVisitor().startEvent(rope, AEventVisitor::EL_DEBUG);
      }
    }
    else
    {
      if (context.useEventVisitor().isLogging(AEventVisitor::EL_DEBUG))
        context.useEventVisitor().startEvent(ASW("No output generator, defaulting to XML",38), AEventVisitor::EL_DEBUG);
      return;
    }
  }

  try
  {
    //a_Find input command, if not found execute the default
    OutputGeneratorContainer::iterator it = m_OutputGenerators.find(command);
    if (it == m_OutputGenerators.end())
    {
      if (context.useEventVisitor().isLogging(AEventVisitor::EL_WARN))
      {
        ARope rope("Skipping unknown output generator: ",35);
        rope.append(command);
        context.useEventVisitor().startEvent(rope, AEventVisitor::EL_WARN);
      }
    }
    else
    {
      ATimer timer(true);

      //a_Generate output
      if (context.useEventVisitor().isLogging(AEventVisitor::EL_INFO))
      {
        ARope rope("Generating output: ",19);
        rope.append((*it).first);
        context.useEventVisitor().startEvent(rope, AEventVisitor::EL_INFO);
      }

      if (context.useContextFlags().isClear(AOSContext::CTXFLAG_IS_AJAX))
      {
        context.useModel().overwriteElement(ASW("execute/output", 14)).addData(command);

        //a_Publish timers
        context.getRequestTimer().emitXml(context.useModel().overwriteElement(ASW("request_time",12)));
        context.getContextTimer().emitXml(context.useModel().overwriteElement(ASW("context_time",12)));
      }

      //a_Generate output
      AOSContext::ReturnCode ret = (*it).second->execute(context);
      switch (ret)
      {
        case AOSContext::RETURN_OK:
        break;

        case AOSContext::RETURN_REDIRECT:
          if (context.useEventVisitor().isLogging(AEventVisitor::EL_INFO))
          {
            context.useEventVisitor().startEvent(ASWNL("Output generator has done a redirect"), AEventVisitor::EL_DEBUG);
          }
        break;
      
        default:
          context.addError((*it).second->getClass(), ASWNL("Output generator returned neither OK nor REDIRECT"));
        return;
      }

      //a_Event over
      context.useEventVisitor().endEvent();

      //a_Add execution time
      (*it).second->addExecutionTimeSample(timer.getInterval());
    }
  }
  catch(AException& ex)
  {
    AString strWhere("AOSOutputExecutor::execute(", 27);
    strWhere.append(command);
    strWhere.append(')');
    context.addError(strWhere, ex.what());

    AXmlElement& element = context.useModel().addElement("output_error");
    element.addElement("where", strWhere);
    element.addElement("exception", ex);
  }
  catch(...)
  {
    AString strWhere("AOSOutputExecutor::execute(", 27);
    strWhere.append(command);
    strWhere.append(')');
    context.addError(strWhere, ASWNL("Unknown Exception"));

    context.useModel().addElement("output_error").addData("Unknown Exception");
  }
}