Example #1
0
static size_t curlHeaderCallback(void *ptr, size_t size, size_t nmemb, void *opaque)
{
    Hashtable<String,String>* pHeaders = (Hashtable<String,String>*)opaque;
    size_t nBytes = size*nmemb;
    String strHeader((const char *)ptr, nBytes);
    RAWTRACE1("Received header: %s", strHeader.c_str());
    
    int nSep = strHeader.find(':');
    if (nSep > 0 )
    {		
        String strName = String_trim(strHeader.substr(0, nSep));
        String lName;
        std::transform(strName.begin(), strName.end(), std::back_inserter(lName), &::tolower);
        
        String strValue = String_trim(strHeader.substr(nSep+1, strHeader.length() - (nSep+3) ));
        
        if ( pHeaders->containsKey(lName) )
        {
            strValue += ";" + pHeaders->get( lName );
            pHeaders->put( lName, strValue );
        }
        else
            pHeaders->put(lName, strValue);
    }
    
    return nBytes;
}
Example #2
0
void deleteDups(LinkListNode n) {
	Hashtable table;
	LinkListNode prev;
	while (n) {
		if (table.containsKey(n.data)) {
			prev.next = n.next;
		}
		else {
			table.insert(n.data, true);
			prev = n;
		}
		n = n.next;
	}
}
Example #3
0
void CDBAttrManager::loadBlobAttrs(CDBAdapter& db)
{
    loadAttrs(db, m_mapBlobAttrs, "blob_attribs");

    String strTriggerPrefix = "rhoSchemaTrigger_";
    IDBResult res = db.executeSQL( "SELECT name FROM sqlite_master WHERE type='trigger'" );
    Hashtable<String,int> mapTriggers;
    for ( ; !res.isEnd(); res.next() )
    {
        String strName = res.getStringByIdx(0);
        if ( !String_startsWith(strName, strTriggerPrefix) )
            continue;

        mapTriggers[strName.substr(strTriggerPrefix.length())] = 0;
    }

    for ( HashtablePtr< int, Hashtable<String,int>* >::iterator it = m_mapBlobAttrs.begin();  it != m_mapBlobAttrs.end(); ++it )
    {
        int nSrcID = it->first;

        IDBResult res = db.executeSQL("SELECT name FROM sources WHERE source_id=?", nSrcID);
        if ( res.isEnd() )
            continue;

        String strName = res.getStringByIdx(0);
        if ( !db.isTableExist(strName) )
            continue;

        Hashtable<String,int>& hashAttribs = *it->second;
        for ( Hashtable<String,int>::iterator itAttr = hashAttribs.begin();  itAttr != hashAttribs.end(); ++itAttr )
        {
            String strTriggerName = strName + "_" + itAttr->first;
            if ( !mapTriggers.containsKey(strTriggerName + "_delete") )
            {
                String strTrigger = String("CREATE TRIGGER ") + strTriggerPrefix + strTriggerName + "_delete BEFORE DELETE ON \"" + strName + "\" FOR EACH ROW \r\n"
                "   BEGIN \r\n"
                "       SELECT rhoOnDeleteSchemaRecord( OLD." + itAttr->first + ");\r\n"
                "   END;\r\n"
                ";";

                db.createTrigger(strTrigger);
            }else
                mapTriggers[strTriggerName + "_delete"] = 1;

            if ( !mapTriggers.containsKey(strTriggerName + "_update") )
            {
                String strTrigger = String("CREATE TRIGGER ") + strTriggerPrefix + strTriggerName + "_update BEFORE UPDATE ON \"" + strName + "\" FOR EACH ROW\r\n"
                "   BEGIN \r\n"
                "       SELECT rhoOnUpdateSchemaRecord( OLD." + itAttr->first + ", NEW." + itAttr->first + ");\r\n"
                "   END;\r\n"
                ";";

                db.createTrigger(strTrigger);
            }else
                mapTriggers[strTriggerName + "_update"] = 1;

        }
    }

    //Remove outdated triggers
    for ( Hashtable<String,int>::iterator itTriggers = mapTriggers.begin();  itTriggers != mapTriggers.end(); ++itTriggers )
    {
        if ( !itTriggers->second )
        {
            db.dropTrigger(strTriggerPrefix+itTriggers->first);
        }
    }
}
Example #4
0
rho::net::CNetResponseWrapper CNetRequestWrapper::pullFile(const String& strUrl, const String& strFilePath, IRhoSession* oSession, Hashtable<String,String>* pHeaders,bool overwriteFile,bool createFolders, bool* pFileExistsFlag )
{
    if (!overwriteFile && common::CRhoFile::isFileExist(strFilePath.c_str())) {
        LOGC(WARNING,"Net") + "pullFile: " + strFilePath + " already exists, won't download since overwrite flag is not set";
        
        if ( pFileExistsFlag != 0 ) {
            *pFileExistsFlag = true;
        }
        
        return m_pReqImpl->createEmptyNetResponse();
    }
    
    if ( pFileExistsFlag != 0 ) {
        *pFileExistsFlag = false;
    }
    
    if ( createFolders ) {
        String targetDir = common::CFilePath(strFilePath).getFolderName();
        
        if ( !common::CRhoFile::isDirectory(targetDir.c_str()) ) {
            common::CRhoFile::recursiveCreateDir(targetDir.c_str(), "");
        }
    }
    
    String tmpfilename = strFilePath + ".rhodownload";
    String modfilename = strFilePath + ".modtime";
    
    common::CRhoFile tmpFile;
    common::CRhoFile::EOpenModes openMode = common::CRhoFile::OpenForWrite;
    
    //don't request headers of will overwrite anyway
    if (!overwriteFile) {
        Hashtable<String, String> h;
        ::getNetRequest().doRequest("HEAD", strUrl, "", oSession, &h );
    
        if ( h.containsKey("last-modified") )
        {
            if ( common::CRhoFile::isFileExist(modfilename.c_str()) ) {
                String modDate;
                common::CRhoFile fModDate;
                if ( fModDate.open(modfilename.c_str(), common::CRhoFile::OpenReadOnly)) {
                    fModDate.readString(modDate);
                    if (modDate == h.get("last-modified")) {
                        openMode = common::CRhoFile::OpenForAppend;
                    }
                }
            } else {
                common::CRhoFile fModDate;
                if ( fModDate.open(modfilename.c_str(), common::CRhoFile::OpenForWrite) ) {
                    const String& modDate = h.get("last-modified");
                    fModDate.write((void*)modDate.c_str(), modDate.length());
                }
            }
        }
    }
    
    if ( !tmpFile.open(tmpfilename.c_str(),openMode) )
    {
        LOGC(ERROR, "Net") + "pullFile: cannot create file :" + tmpfilename;
        return m_pReqImpl->createEmptyNetResponse();
    }
    
    INetResponse* pResp = m_pReqImpl->pullFile( strUrl, tmpFile, oSession, pHeaders );
    
    tmpFile.close();
    
    if ( (pResp->getRespCode() == 200) || (pResp->getRespCode() == 206) ) 
    {
        common::CRhoFile::deleteFile(strFilePath.c_str());

        if ( common::CRhoFile::renameFile( tmpfilename.c_str(), strFilePath.c_str() ) != 0 ) 
        {
            LOGC(ERROR, "Net") + "pullFile: cannot rename file :" + tmpfilename + " to " + strFilePath;
            return m_pReqImpl->createEmptyNetResponse();
        }
        
        common::CRhoFile::deleteFile(modfilename.c_str());
    }
    
    return pResp;
}
Example #5
0
void DDaceXMLHandler::startElement(const std::string& name, 
				   const Hashtable& attributes)
{
  try
    {
      if (samplerTypes_.containsKey(name))
	{
	  samplerParams_ = attributes;
	  samplerName_ = name;
	  
	  int samples = atoi(attributes.get("samples"));
	  pts_.resize(samples);
	  results_.resize(samples);
	  status_.resize(samples);
	  // give default values to elements of status_
	  for(int j=0; j < samples; j++)
	    status_[j] = DDaceRunNotStarted;
	}
      else if (name == "Variable")
	{
	  varNames_.append(attributes.get("name"));
	  
	  if (attributes.containsKey("distribution") 
	      && attributes.get("distribution") != "uniform")
	    {
	      std::string distType = attributes.get("distribution");
	      if (distType == "normal")
		{
		  if (attributes.containsKey("mean") 
		      && attributes.containsKey("sigma"))
		    {
		      double mean = atof(attributes.get("mean"));
		      double sigma = atof(attributes.get("sigma"));
		      double nDev = atof(attributes.get("cutoff"));
		      varDist_.append(NormalDistribution(Mean(mean), 
							 StdDeviation(sigma),
							 nDev));
		    }
		  else if (attributes.containsKey("upper") && attributes.containsKey("lower"))
		    {
		      double lower = atof(attributes.get("lower"));
		      double upper = atof(attributes.get("upper"));
		      if (attributes.containsKey("nDev"))
			{
			  double nDev = atof(attributes.get("cutoff"));
			  varDist_.append(NormalDistribution(lower, upper, nDev));
			}
		      else
			{
			  varDist_.append(NormalDistribution(lower, upper));
			}
		    }
		  else
		    {
		      ExceptionBase::raise("invalid xml specification of normally distributed variable");
		    }
		}
	      else
		{
		  ExceptionBase::raise("unrecognized xml specification of distribution type");
		}
	    }			
	  else if ( samplerName_ == "UserInputSampler" )
	    {
	      // no distribution information required for UserInputSampler
	    }	      
	  else /* uniform distribution */
	    {
	      double lower = atof(attributes.get("lower"));
	      double upper = atof(attributes.get("upper"));
	      varDist_.append(UniformDistribution(lower, upper));
	      
	    }
	}
      else if (name == "Archive")
	{
	  archiveFilename_ = attributes.get("name");
	}
      else if (name == "Output")
	{
	  outputNames_.append(attributes.get("name"));
	}
      else if (name == "Sample")
	{
	  currentTag_ = atoi(attributes.get("tag"));
	}
      else if (name == "SamplePoint")
	{
	  isSamplePt_ = true;
	  charStr_ = "";
	}
      else if (name == "SampleResult")
	{
	  isArchiveFile_ = true;
	  if (currentTag_ == -1)
	    ExceptionBase::raise("Index tag corresponding to current "
				 "sample is -1.");
	  String statusString = attributes.get("status");
	  if (statusString == "Run OK")
	    status_[currentTag_] = DDaceRunOK;
	  else if (statusString == "Run failed")
	    status_[currentTag_] = DDaceRunFailed;
	  else if (statusString == "Post processing failed")
	    status_[currentTag_] = DDacePostProcFailed;
	  else if (statusString == "Run not started")
	    status_[currentTag_] = DDaceRunNotStarted;
	  else if (statusString == "Run pending")
	    status_[currentTag_] = DDaceRunPending;
	  else 
	    ExceptionBase::raise("unrecognized sample status inside "
				 "SampleResult for "
				 "DDaceXMLHandler::startElement()");
	  isSampleResult_ = true;
	  charStr_= "";
	}
    }
  catch(ExceptionBase& e)
    {
      e.trace("in DDaceXMLHandler::startElement( tag = " + name + ")");
    }
}