MServiceMapperPrivate::ServiceInfo MServiceMapperPrivate::serviceInterfacePair(const QString &fileName) const
{
    MServiceMapperPrivate::ServiceInfo serviceInterfacePair;

    if ( m_serviceFileInfo.contains( fileName ) ) {
        serviceInterfacePair = m_serviceFileInfo.value( fileName );
    } else {
        QString absoluteFileName = QDir(m_serviceFileDir).absoluteFilePath(fileName);

        if (fileExistsAndReadable(absoluteFileName)) {
            QIODevice *file = accessFile(absoluteFileName);
            if (file->open(QIODevice::ReadOnly)) {
                QTextStream in(file);

                while (!in.atEnd()) {
                    QString line = in.readLine();

                    QStringList fields = line.split('=');

                    if (fields[0] == "Name") {
                        serviceInterfacePair.service=fields[1];
                    } else
                        if (fields[0] == "Interface") {
                            serviceInterfacePair.interface=fields[1];
                        }
                }
            }

            delete file;
        }
    }

    return serviceInterfacePair;
}
Exemplo n.º 2
0
/* Flush all dirty sectors. */
CoreResult coreFlushFile(CryptedVolume * pVolume, CryptedFileID id)
{
   CoreResult cr;
   CryptedSector * * papDirty, * p, * * q;
   CryptedFile * pFile;

   cr = accessFile(pVolume, id, &pFile);
   if (cr) return cr;

   if (pFile->csDirty) {

      papDirty = malloc(pFile->csDirty * sizeof(CryptedSector *));
      if (!papDirty) return CORERC_NOT_ENOUGH_MEMORY;

      for (p = pFile->pFirstSector, q = papDirty; p;
           p = p->pNextInFile)
         if (p->fDirty) *q++ = p;

      sortSectorList(pFile->csDirty, papDirty);

      cr = flushSectors(pFile->csDirty, papDirty);
      free(papDirty);
      if (cr) return cr;
      assert(pFile->csDirty == 0);
   }

   return CORERC_OK;
}
Exemplo n.º 3
0
/* Fetch sectors from the specified file.  csExtent may not be larger
   than the maximum cache size. */
CoreResult coreFetchSectors(CryptedVolume * pVolume,
   CryptedFileID id, SectorNumber sStart, SectorNumber csExtent,
   unsigned int flFlags)
{
   CoreResult cr;
   SectorNumber i;
   unsigned int csMissing;
   SectorNumber * pasMissing;
   CryptedFile * pFile;

   cr = accessFile(pVolume, id, &pFile);
   if (cr) return cr;
   
   if (!csExtent) return CORERC_OK;
   if (csExtent > pFile->pVolume->parms.csMaxCached)
      return CORERC_CACHE_OVERFLOW;

   /* Determine which sectors are not in the cache. */
   pasMissing = malloc(csExtent * sizeof(SectorNumber *));
   if (!pasMissing) return CORERC_NOT_ENOUGH_MEMORY;
   csMissing = 0;
   for (i = 0; i < csExtent; i++)
      if (!queryCachedSector(pVolume, id, sStart + i)) 
         pasMissing[csMissing++] = sStart + i;

   if (!csMissing) { /* everything already in cache */
      free(pasMissing);
      return CORERC_OK;
   }

   /* Make sure that there is enough room in the cache. */
   if (pFile->pVolume->csInCache + csMissing >
      pFile->pVolume->parms.csMaxCached)
   {
      cr = purgeCache(pFile->pVolume,
         pFile->pVolume->csInCache -
         (pFile->pVolume->parms.csMaxCached - csMissing),
         pFile, sStart, csExtent);
      if (cr) {
         free(pasMissing);
         return cr;
      }
   }

   cr = readSectors(pFile, csMissing, pasMissing, flFlags);
   free(pasMissing);
   return cr;
}
Exemplo n.º 4
0
/* Create a file with the given ID and initial size. The content of
   the allocated sectors is undefined (and reading them will give a
   CRC error with high probability).  The initial size is advisory
   only (see coreSuggestFileSize). */
CoreResult coreCreateFile(CryptedVolume * pVolume,
   CryptedFileID id, SectorNumber csPreallocate)
{
   CoreResult cr;
   CryptedFile * pFile;

   if (pVolume->parms.fReadOnly) return CORERC_READ_ONLY;

   if (storageFileExists(pVolume, id)) return CORERC_ID_EXISTS;

   /* Create a CryptedFile for this file. */
   cr = accessFile(pVolume, id, &pFile);
   if (cr) return cr;

   /* Create a storage file. */
   cr = openStorageFile(pFile, true, csPreallocate * SECTOR_SIZE);
   if (cr) {
      dropFile(pFile);
      return cr;
   }

   return CORERC_OK;
}
Exemplo n.º 5
0
/* Suggest that the size of the storage file be increased or decreased
   to the specified number of sectors.  This can be used to improve
   performance and reduce fragmentation on certain systems (like
   OS/2). */
CoreResult coreSuggestFileAllocation(CryptedVolume * pVolume,
   CryptedFileID id, SectorNumber csAllocate)
{
   CoreResult cr;
   FilePos cbNewSize;
   CryptedFile * pFile;

   if (pVolume->parms.fReadOnly) return CORERC_READ_ONLY;

   cr = accessFile(pVolume, id, &pFile);
   if (cr) return cr;

   deleteHighSectors(pFile, csAllocate);
   
   /* Make sure the storage file for this CryptedFile is open. */
   cr = openStorageFile(pFile, false, 0);
   if (cr) return cr;

   /* Set the new file size.  The semantics of sysSetFileSize() do not
      guarantee that growing a file will work (and it doesn't, in
      general, on POSIX).  */
   cbNewSize = SECTOR_SIZE * (CryptedFilePos) csAllocate;
   return sys2core(sysSetFileSize(pFile->pStorageFile, cbNewSize));
}
Exemplo n.º 6
0
/* Destroy the specified file.  This means freeing all the file's
   resources in memory (see dropFile()) and deleting the
   associated storage file. */
CoreResult coreDestroyFile(CryptedVolume * pVolume, CryptedFileID id)
{
   CoreResult cr;
   char szPathName[MAX_STORAGE_PATH_NAME];
   CryptedFile * pFile;

   if (pVolume->parms.fReadOnly) return CORERC_READ_ONLY;

   cr = accessFile(pVolume, id, &pFile);
   if (cr) return cr;

   makeStoragePathName(pVolume, pFile->id, szPathName);

   /* Delete all the file's sectors from the cache without flushing to
      disk. */
   deleteHighSectors(pFile, 0);
   
   /* Drop the crypted file.  This will close the storage file. */
   cr = dropFile(pFile);
   if (cr) return cr;

   /* Delete the storage file. */
   return sys2core(sysDeleteFile(szPathName, true, pVolume->parms.cred));
}
Exemplo n.º 7
0
void ParseCache::parse(std::string filename)
{
    _configPath = ".";
    _configFileName = filename;
    _cacheFile = _configPath + "/.cache/" + _configFileName + ".xml.cache";
    if (!isDirectory("./.cache"))
    {
        createDirectory("./.cache");
    }
    if (!accessFile(_cacheFile))
    {
        LOGW("ParseCache::parse [" << _cacheFile << " not found.");
        return;
    }
    tinyxml2::XMLDocument doc;
    if (doc.LoadFile(_cacheFile.c_str()) != tinyxml2::XML_SUCCESS)
    {
        E(" ParseCache::parse Error. configFile=" << _cacheFile << ", err1=" << doc.GetErrorStr1() << ", err2" << doc.GetErrorStr2());
    }

    for (int i = SL_NORMAL+1; i < SL_END; i++)
    {
        XMLElement * md5 = doc.FirstChildElement(SupportLanguageString[i]);
        if (md5 && md5->GetText())
        {
            _md5Cache[i] = md5->GetText();
        }
    }
    
    XMLElement * cacheEles = doc.FirstChildElement("cacheNumber");
    if (cacheEles == NULL)
    {
        LOGW("ParseCache::parse can not found cacheNumber. configFile=" << _cacheFile);
        return ;
    }

    XMLElement * next = cacheEles->FirstChildElement("cache");
    do
    {
        if (next == NULL)
        {
            break;
        }
        const char * key = next->Attribute("key");
        const char * number = next->Attribute("Number");
        if (key == NULL || number == NULL)
        {
            E("ParseCache::parse cache number is invalid. configFile=" << _cacheFile);
        }


        auto founder = _cacheNumber.find(key);
        if (founder != _cacheNumber.end())
        {
            E("ParseCache::parse dumplicate key on " << key << " from " << _cacheFile);
        }
        _cacheNumber[key] = atoi(number);

        if (_currentProtoID <= atoi(number))
        {
            _currentProtoID = atoi(number) + 1;
        }

        next = next->NextSiblingElement("cache");
    } while (true);
}