Ejemplo n.º 1
0
void leadHQHandle(void) {
  int rsize;
  unsigned short index[32]; // <10 keypairs in the incoming json

  // only continue if new data to read
  if (!Scout.wifi.client.available()) {
    return;
  }

  // Read a block of data and look for packets
  while ((rsize = hqIncoming.readClient(Scout.wifi.client, 128))) {
    int nl;
    while((nl = hqIncoming.indexOf('\n')) >= 0) {
     // look for a packet
      if (hqVerboseOutput) {
        Serial.print(F("looking for packet in: "));
        Serial.println(hqIncoming);
      }

      // Parse JSON up to the first newline
      if (!js0n((const unsigned char*)hqIncoming.c_str(), nl, index, 32)) {
        leadIncoming(hqIncoming.c_str(), nl, index);
      } else {
        if (hqVerboseOutput) {
          Serial.println(F("JSON parse failed"));
        }
      }

      // Remove up to and including the newline
      hqIncoming.remove(0, nl + 1);
    }
  }
}
//---------------------------------------------------------------------------
//  getInstallPath
//---------------------------------------------------------------------------
bool CDaliDeploymentEngine::getInstallPath(const char *filename, StringBuffer& installPath)
{
    //BUG: 9254 - Deploy Wizard's "compare" for Dali looks in wrong folder
    //If filename is in deploy folder then compare file in folder above it.
    //
    StringBuffer machine;
    StringBuffer path;
    StringBuffer tail;
    StringBuffer ext;
    bool             rc;

    splitUNCFilename(filename, &machine, &path, &tail, &ext);
    const char* pszPath = path.str();
    const char* pattern = "deploy\\";
    const unsigned int patternLen = sizeof("deploy\\") - 1;
    const char* match = strstr(pszPath, pattern);

    if (match && strlen(match)==patternLen)//path ends with "deploy\\"
    {
        path.remove(match-pszPath, patternLen);
        installPath.append(machine).append(path).append(tail).append(ext);
        rc = true;
    }
    else
    {
        installPath.append(filename);
        rc = false;
    }
    return rc;
}
//---------------------------------------------------------------------------
// getPluginDirectory
//
// returns absolute path where plugins are to be deployed
//---------------------------------------------------------------------------
void CPluginDeploymentEngine::getPluginDirectory(const char* destPath, StringBuffer& sPluginDest) const
{
   sPluginDest.clear().append(destPath); 
   sPluginDest.replace('\\', '/');

   StringBuffer sPluginsDir; //relative path (from ECL server installation directory) for plugins
   m_process.getProp("@pluginsPath", sPluginsDir);

   if (sPluginsDir.length())
   {
      sPluginsDir.replace('\\', '/');
      sPluginsDir.replace('$', ':');

      if (! ::PathIsRelative(sPluginsDir.str()))
         throw MakeStringExceptionDirect(-1, "Plugins path for ECL server must be relative to its installation directory!");

      if (!strncmp(sPluginsDir.str(), "./", 2))
         sPluginsDir.remove(0, 2);

      sPluginDest.append(sPluginsDir);
   }

   const char* pchLast = sPluginDest.str() + sPluginDest.length() - 1;
   if (*pchLast != '/')
      sPluginDest.append('/');
}
Ejemplo n.º 4
0
void CConfigGenEngine::createFakePlugins(StringBuffer& destFilePath) const
{
    String destFilePathStr(destFilePath);
    String* tmpstr = destFilePathStr.toLowerCase();
    if (!tmpstr->endsWith("plugins.xml"))
    {
        int index = tmpstr->indexOf("plugins.xml");
        destFilePath.remove(index + 11, destFilePath.length() - (index + 11));
    }

    delete tmpstr;

    StringBuffer tmpoutbuf("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Plugins/>");

    if (m_instances.ordinality() > 1 && strcmp(m_process.queryName(), XML_TAG_ESPPROCESS))
        destFilePath.replaceString("@temp"PATHSEPSTR, m_cachePath);
    else
    {
        char tempPath[_MAX_PATH];
        getTempPath(tempPath, sizeof(tempPath), m_name);
        ensurePath(tempPath);
        destFilePath.replaceString("@temp"PATHSEPSTR, tempPath);
    }

    Owned<IFile> pTargetFile = createIFile(destFilePath.str());
    if (pTargetFile->exists() && pTargetFile->isReadOnly())
        pTargetFile->setReadOnly(false);
    Owned<IFileIO> pTargetFileIO = pTargetFile->open(IFOcreate);
    pTargetFileIO->write( 0, tmpoutbuf.length(), tmpoutbuf.str());
    m_envDepEngine.addTempFile(destFilePath.str());
}
Ejemplo n.º 5
0
void leadHQHandle(void) {
  int rsize = 0;
  int nl;
  unsigned short index[32]; // <10 keypairs in the incoming json

  if(Scout.handler.isBridged)
  {
    rsize = (int)Scout.handler.bridge.length();
    hqIncoming += Scout.handler.bridge;
    Scout.handler.bridge = "";
  } else if (WifiModule::instance.bp()) {
    if (WifiModule::instance.bp()->client.available()) {
      rsize = hqIncoming.readClient(WifiModule::instance.bp()->client, 128);
      if(rsize > 0) Scout.handler.seen = SleepHandler::uptime().seconds;
    }
  }

  // only continue if new data to process
  if(rsize <= 0) return;
  
  // Read a block of data and look for packets
  while((nl = hqIncoming.indexOf('\n')) >= 0) {
    // look for a packet
    if(nl)
    {
      if (Scout.handler.isVerbose) {
        Serial.print(F("looking for packet in: "));
        Serial.println(hqIncoming);
      }

      // Parse JSON up to the first newline
      if (!js0n((const unsigned char*)hqIncoming.c_str(), nl, index, 32)) {
        leadIncoming(hqIncoming.c_str(), nl, index);
      } else {
        if (Scout.handler.isVerbose) {
          Serial.println(F("JSON parse failed"));
        }
      }
    }else{
      if (Scout.handler.isVerbose) {
        Serial.println(F("HQ ack'd"));
      }
    }

    // Remove up to and including the newline
    hqIncoming.remove(0, nl + 1);
  }
}
bool CLogContentFilter::readLogFilters(IPropertyTree* cfg, unsigned groupID)
{
    Owned<CESPLogContentGroupFilters> espLogContentGroupFilters = new CESPLogContentGroupFilters((ESPLogContentGroup) groupID);
    StringBuffer xpath;
    if (groupID != ESPLCGAll)
        xpath.appendf("Filters/Filter[@type='%s']", espLogContentGroupNames[groupID]);
    else
        xpath.append("Filters/Filter");
    Owned<IPropertyTreeIterator> filters = cfg->getElements(xpath.str());
    ForEach(*filters)
    {
        IPropertyTree &filter = filters->query();
        StringBuffer value = filter.queryProp("@value");
        if (!value.length())
            continue;

        //clean "//"
        unsigned idx = value.length()-1;
        while (idx)
        {
            if ((value.charAt(idx-1) == '/') && (value.charAt(idx) == '/'))
                value.remove(idx, 1);
            idx--;
        }

        //clean "/*" at the end
        while ((value.length() > 1) && (value.charAt(value.length()-2) == '/') && (value.charAt(value.length()-1) == '*'))
            value.setLength(value.length() - 2);

        if (value.length() && !streq(value.str(), "*") && !streq(value.str(), "/") && !streq(value.str(), "*/"))
        {
            espLogContentGroupFilters->addFilter(value.str());
        }
        else
        {
            espLogContentGroupFilters->clearFilters();
            break;
        }
    }

    bool hasFilter = espLogContentGroupFilters->getFilterCount() > 0;
    if (hasFilter)
        groupFilters.append(*espLogContentGroupFilters.getClear());
    return hasFilter;
}
Ejemplo n.º 7
0
int COneServerHttpProxyThread::start()
{
    try
    {
        char peername[256];
        int port = m_client->peer_name(peername, 256);
        if(http_tracelevel >= 5)
            fprintf(m_ofile, "\n>>receivd request from %s:%d\n", peername, port);

        StringBuffer requestbuf;
        Owned<IByteOutputStream> reqstream = createOutputStream(requestbuf);
        bool isRoxie;
        Http::receiveData(m_client, reqstream.get(), false, isRoxie);
        
        if(http_tracelevel >= 10)
            fprintf(m_ofile, "%s%s%s", sepstr, requestbuf.str(), sepstr);
        else if(http_tracelevel >= 5)
        {
            const char* endofline = strstr(requestbuf.str(), "\n");
            if(endofline)
            {
                StringBuffer firstline;
                firstline.append((endofline - requestbuf.str()), requestbuf.str());
                fprintf(m_ofile, "%s", firstline.str());
            }
            else
                fprintf(m_ofile, "%s\n", requestbuf.str());
        }


        if (0 != stricmp(m_url_prefix, "/"))
        {
            int url_offset;
            if (!strnicmp(requestbuf.str(), "GET ", 4))
                url_offset = 4;
            else if (!strnicmp(requestbuf.str(), "POST ", 5))
                url_offset = 5;
            else
                url_offset = -1;

            if (url_offset > 0)
            {
                const int prefix_len = strlen(m_url_prefix);
                if (0 != strnicmp(requestbuf.str()+url_offset, m_url_prefix, prefix_len))
                {
                    const char* endofline = strstr(requestbuf.str(), "\n");
                    if(endofline)
                    {
                        StringBuffer firstline;
                        firstline.append((endofline - requestbuf.str()), requestbuf.str());
                        fprintf(m_ofile, "INVALID request: %s", firstline.str());
                    }
                    else
                        fprintf(m_ofile, "INVALID request:\n%s\n", requestbuf.str());


                    StringBuffer respbuf;
                    respbuf.append("HTTP/1.1 404 Not Found\n")
                        .append("Content-Type: text/xml; charset=UTF-8\n")
                        .append("Connection: close\n");

                    m_client->write(respbuf.str(), respbuf.length());

                    if(http_tracelevel >= 5)
                        fprintf(m_ofile, ">>sent the response back to %s:%d:\n", peername, port);
                    if(http_tracelevel >= 10)
                        fprintf(m_ofile, "%s%s%s", sepstr, respbuf.str(), sepstr);
                    fflush(m_ofile);

                    m_client->shutdown();
                    m_client->close();
                    return -1;
                }
                else
                {
                    //we want to map /x to / and /x/y to /y as follows:
                    //if m_url_prefix is /x and url is /x/y then remove x
                    //to result in //y
                    requestbuf.remove(++url_offset, prefix_len-1);
                    //now, if we have //y then change it to /y
                    if (*(requestbuf.str()+url_offset) == '/')
                        requestbuf.remove(url_offset, 1);
                }
            }
        }

        SocketEndpoint ep;
        Owned<ISocket> socket2;

        ep.set(m_host.str(), m_port);
        socket2.setown(ISocket::connect(ep));
        if(m_use_ssl && m_ssctx != NULL)
        {
            Owned<ISecureSocket> securesocket = m_ssctx->createSecureSocket(socket2.getLink());
            int res = securesocket->secure_connect();
            if(res >= 0)
            {
                socket2.set(securesocket.get());
            }
        }

        if(socket2.get() == NULL)
        {
            StringBuffer urlstr;
            DBGLOG(">>Can't connect to %s", ep.getUrlStr(urlstr).str());
            return -1;
        }
        
        char newhost[1024];
        sprintf(newhost, "%s:%d", m_host.str(), m_port);
        replaceHeader(requestbuf, "Host", newhost);

        //checkContentLength(requestbuf);
        if(http_tracelevel >= 5)
            fprintf(m_ofile, "\n>>sending request to %s:%d\n", m_host.str(), m_port);
        if(http_tracelevel >= 10)
            fprintf(m_ofile, "%s%s%s", sepstr, requestbuf.str(), sepstr);

        socket2->write(requestbuf.str(), requestbuf.length());
        StringBuffer respbuf;
        Owned<IByteOutputStream> respstream = createOutputStream(respbuf);
        isRoxie;
        Http::receiveData(socket2.get(), respstream.get(), true, isRoxie);
        
        if(http_tracelevel >= 5)
            fprintf(m_ofile, ">>received response from %s:%d:\n", m_host.str(), m_port);
        if(http_tracelevel >= 10)
            fprintf(m_ofile, "%s%s%s", sepstr, respbuf.str(), sepstr);

        m_client->write(respbuf.str(), respbuf.length());
        fflush(m_ofile);

        if(http_tracelevel >= 5)
            fprintf(m_ofile, ">>sent the response back to %s:%d:\n", peername, port);
        if(http_tracelevel >= 10)
            fprintf(m_ofile, "%s%s%s", sepstr, respbuf.str(), sepstr);

        socket2->shutdown();
        socket2->close();
        m_client->shutdown();
        m_client->close();
    }
    catch(IException *excpt)
    {
        StringBuffer errMsg;
        DBGLOG("%s", excpt->errorMessage(errMsg).str());
        return -1;
    }
    catch(...)
    {
        DBGLOG("unknown exception");
        return -1;
    }

    return 0;
}