Exemplo n.º 1
0
Boolean InstanceIndexFile::lookupEntry(
    const String& path,
    const CIMObjectPath& instanceName,
    Uint32& indexOut,
    Uint32& sizeOut)
{
    PEG_METHOD_ENTER(TRC_REPOSITORY, "InstanceIndexFile::lookupEntry()");

    fstream fs;

    if (!_openFile(path, fs))
    {
        PEG_METHOD_EXIT();
        return false;
    }

    Uint32 entryOffset = 0;

    Boolean result = _lookupEntry(
                         fs, instanceName, indexOut, sizeOut, entryOffset);

    fs.close();

    PEG_METHOD_EXIT();
    return result;
}
Exemplo n.º 2
0
bool XAP_Dictionary::save(void)
{
	if (!m_bDirty)
		return true;

	if (!_openFile("w"))
		return false;

	UT_GenericVector<UT_UCSChar *> * pVec = m_hashWords.enumerate();
	UT_ASSERT(pVec);

	UT_uint32 size = pVec->size();

	for (UT_uint32 i = 0; i < size; i++)
	{
		UT_UCSChar * pWord = pVec->getNthItem(i);
		_outputUTF8(pWord, UT_UCS4_strlen(pWord));
		_writeBytes(reinterpret_cast<const UT_Byte *>("\n"));
	}

	_closeFile();

	delete pVec;
	m_bDirty = false;

	return true;
}
Exemplo n.º 3
0
Boolean InstanceIndexFile::createEntry(
    const String& path,
    const CIMObjectPath& instanceName,
    Uint32 indexIn,
    Uint32 sizeIn)
{
    PEG_METHOD_ENTER(TRC_REPOSITORY, "InstanceIndexFile::createEntry()");

    //
    // Open the file:
    //

    fstream fs;

    if (!_openFile(path, fs, true))
    {
        PEG_METHOD_EXIT();
        return false;
    }

    //
    // Return false if entry already exists:
    //

    Uint32 tmpIndex;
    Uint32 tmpSize;
    Uint32 tmpEntryOffset;

    if (InstanceIndexFile::_lookupEntry(
                fs, instanceName, tmpIndex, tmpSize, tmpEntryOffset))
    {
        PEG_METHOD_EXIT();
        return false;
    }

    //
    // Append the new entry to the end of the file:
    //

    if (!_appendEntry(fs, instanceName, indexIn, sizeIn))
    {
        PEG_METHOD_EXIT();
        return false;
    }

    //
    // Close the file:
    //

    fs.close();

    PEG_METHOD_EXIT();
    return true;
}
Exemplo n.º 4
0
Boolean InstanceIndexFile::deleteEntry(
    const String& path,
    const CIMObjectPath& instanceName,
    Uint32& freeCount)
{
    PEG_METHOD_ENTER(TRC_REPOSITORY, "InstanceIndexFile::deleteEntry()");

    freeCount = 0;

    //
    // Open the file:
    //

    fstream fs;

    if (!_openFile(path, fs))
    {
        PEG_METHOD_EXIT();
        return false;
    }

    //
    // Mark the entry as free:
    //

    if (!_markEntryFree(fs, instanceName))
    {
        PEG_METHOD_EXIT();
        return false;
    }

    //
    // Increment the free count:
    //

    freeCount = 0;

    if (!_incrementFreeCount(fs, freeCount))
    {
        PEG_METHOD_EXIT();
        return false;
    }

    //
    // Close the file:
    //

    fs.close();

    PEG_METHOD_EXIT();
    return true;
}
Exemplo n.º 5
0
void SDHandler::_keyPressed() {
  if(!_active) {
    _sd->mount();
    _getFileNumber();
    _led->write(1);
    _log("Pressed\n");
    _log("New file number: %i\n", _fileNumber);
    _dirTest();
    _openFile();
    _active = true;
    //_logWatchdogReset();
  }
}
Exemplo n.º 6
0
Arquivo: ftp.c Projeto: maplefish/MICO
//ftp.send(file [,append])
//==================================
static int lftp_send( lua_State* L )
{
  if ( (gL == NULL) || (ftpCmdSocket == NULL) || (!(status & FTP_LOGGED)) ) {
    ftp_log("[FTP usr] Login first\r\n" );
    lua_pushinteger(L, -11);
    return 1;
  }
  if (lua_gettop(L) >= 2) {
    send_type = (uint8_t)luaL_checkinteger(L, 2);
    if (send_type != SEND_APPEND) send_type = SEND_OVERWRITTE;
  }
  else send_type = SEND_OVERWRITTE;
  
  if (_getFName(L, 1) < 0) {
    ftp_log("[FTP fil] File name missing\r\n" );
    lua_pushinteger(L, -12);
    return 1;
  }
  if (_openFile("r") < 0) {
    lua_pushinteger(L, -13);
    return 1;
  }

  spiffs_stat s;
  // Get file size
  SPIFFS_fstat(&fs, file_fd, &s);
  file_size = s.size;
  
  data_done = 0;
  ftpCmdSocket->clientFlag = REQ_ACTION_SEND;
  
  if (ftpCmdSocket->sent_cb == LUA_NOREF) {
    // no cb function, wait until file received (max 10 sec)
    uint32_t tmo = mico_get_time();
    while (!data_done) {
      if ((mico_get_time() - tmo) > 10000) break;
      mico_thread_msleep(60);
      luaWdgReload();
    }
    if (!data_done) {
      ftp_log("[FTP usr] Timeout: file not sent\r\n" );
      lua_pushinteger(L, -14);
    }
    else {
      ftp_log("[FTP usr] File sent\r\n" );
      lua_pushinteger(L, file_status);
    }
  }
  else lua_pushinteger(L, 0);
  return 1;
}
Exemplo n.º 7
0
Arquivo: ftp.c Projeto: maplefish/MICO
//ftp.recv(file [,tostr])
//===================================
static int lftp_recv( lua_State* L )
{
  if ( (gL == NULL) || (ftpCmdSocket == NULL) || (!(status & FTP_LOGGED)) ) {
    ftp_log("[FTP usr] Login first\r\n" );
    lua_pushinteger(L, -11);
    return 1;
  }

  if (_getFName(L, 1) < 0) {
    ftp_log("[FTP fil] File name missing\r\n" );
    lua_pushinteger(L, -12);
    return 1;
  }
  if (_openFile("w") < 0) {
    lua_pushinteger(L, -13);
    return 1;
  }
  
  recv_type = RECV_TOFILE;
  if (lua_gettop(L) >= 2) {
    int tos = luaL_checkinteger(L, 2);
    if (tos == 1) recv_type = RECV_TOSTRING;
  }
  data_done = 0;
  ftpCmdSocket->clientFlag = REQ_ACTION_RECV;
  
  if (ftpCmdSocket->received_cb == LUA_NOREF) {
    // no cb function, wait until file received (max 10 sec)
    uint32_t tmo = mico_get_time();
    while (!data_done) {
      if ((mico_get_time() - tmo) > 10000) break;
      mico_thread_msleep(60);
      luaWdgReload();
    }
    if (!data_done) {
      ftp_log("[FTP usr] Timeout: file not received\r\n" );
      lua_pushinteger(L, -14);
    }
    else {
      ftp_log("[FTP usr] File received\r\n" );
      lua_pushinteger(L, file_status);
      if (recv_type == RECV_TOSTRING) {
        lua_pushstring(L, recvDataBuf);
        return 2;
      }
    }
  }
  else lua_pushinteger(L, 0);
  return 1;
}
Exemplo n.º 8
0
void SDHandler::logData(const std::string data) {
  if(_checkNewDate(data)) {
    _log("logData: _checkNewDate is true\n");
    if(_active) {
      _log("logData: _active is true\n");
      if(_firstTime) {
        _firstTime = false;
      } else {
        ++_fileNumber;
      }
      _closeFile();
      _openFile();
    }
  }

  if(_fp != 0) {
    _filterData(data);
  }
}
Exemplo n.º 9
0
bool XAP_Dictionary::load(void)
{
	UT_ASSERT(m_hashWords.size() == 0);

	if (!_openFile("r"))
		return false;

	if (!_parseUTF8())
		_abortFile();
	else
		_closeFile();

	m_bDirty = false;
//
// Hardwire in some words that should be in the English Language :-)
//
	addWord("AbiWord");
	addWord("AbiSource");
	return true;
}
void EmailListenerDestination::_sendViaEmail(
    const Array<String> & mailTo,
    const Array<String> & mailCc,
    const String & mailSubject,
    const String & formattedText)
{
    PEG_METHOD_ENTER (TRC_IND_HANDLER,
                      "EmailListenerDestination::_sendViaEmail");

#if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_LINUX)

    String exceptionStr;
    FILE * mailFilePtr;
    FILE * filePtr;
    char mailFile[TEMP_NAME_LEN];

    // Check for proper execute permissions for sendmail
    if (access(SENDMAIL_CMD, X_OK) < 0)
    {
        Tracer::trace(TRC_IND_HANDLER, Tracer::LEVEL4,
                      "Cannot execute %s: %s." SENDMAIL_CMD,
                      strerror(errno));

        MessageLoaderParms parms(
            "Handler.EmailListenerDestination.EmailListenerDestination._MSG_EXECUTE_ACCESS_FAILED",
            "Cannot execute $0: $1",
            SENDMAIL_CMD,
            strerror(errno));

        Logger::put_l (Logger::STANDARD_LOG, System::CIMSERVER,
                       Logger::WARNING,
                       "Handler.EmailListenerDestination.EmailListenerDestination._MSG_EXECUTE_ACCESS_FAILED",
                       MessageLoader::getMessage(parms));

        PEG_METHOD_EXIT();

        return;
    }

    // open a temporary file to hold the indication mail message
    _openFile(&filePtr, mailFile);

    try
    {
        _buildMailHeader(mailTo, mailCc, mailSubject, filePtr);

        // write indication text to the file
        _writeStrToFile(formattedText, filePtr);

        fclose(filePtr);

    }
    catch (CIMException &c)
    {
        fclose(filePtr);
        unlink(mailFile);

        PEG_METHOD_EXIT();
        return;
    }

    try
    {
        // send the message
        _sendMsg(mailFile);
    }
    catch (CIMException &c)
    {
        unlink(mailFile);

        PEG_METHOD_EXIT();
        return;
    }

    unlink(mailFile);

    PEG_METHOD_EXIT();

#else
    PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4,
                     "sendmail is not supported.");
    PEG_METHOD_EXIT();


    throw PEGASUS_CIM_EXCEPTION_L (CIM_ERR_NOT_SUPPORTED,
                                   MessageLoaderParms("Handler.EmailListenerDestination."
                                           "EmailListenerDestination.UNSUPPORTED_OPERATION",
                                           "sendmail is not supported."));
#endif
    PEG_METHOD_EXIT();

}
Exemplo n.º 11
0
Boolean InstanceIndexFile::enumerateEntries(
    const String& path,
    Array<Uint32>& freeFlags,
    Array<Uint32>& indices,
    Array<Uint32>& sizes,
    Array<CIMObjectPath>& instanceNames,
    Boolean includeFreeEntries)
{
    PEG_METHOD_ENTER(TRC_REPOSITORY, "InstanceIndexFile::enumerateEntries()");

    //
    // Reserve space for at least COUNT entries:
    //

    const Uint32 COUNT = 1024;

    freeFlags.reserveCapacity(COUNT);
    indices.reserveCapacity(COUNT);
    sizes.reserveCapacity(COUNT);
    instanceNames.reserveCapacity(COUNT);

    //
    // Open input file:
    //

    fstream fs;

    if (!_openFile(path, fs))
    {
        // file does not exist, just return with no instanceNames
        PEG_METHOD_EXIT();
        return true;
    }

    //
    // Iterate over all instances to build output arrays:
    //

    Array<char> line;
    Uint32 freeFlag;
    Uint32 hashCode;
    const char* instanceName;
    Uint32 index;
    Uint32 size;
    Boolean error;

    while (_GetNextRecord(
                fs, line, freeFlag, hashCode, index, size, instanceName, error))
    {
        if (!freeFlag || includeFreeEntries)
        {
            freeFlags.append(freeFlag);
            indices.append(index);
            sizes.append(size);
            instanceNames.append (CIMObjectPath (instanceName));
        }
    }

    if (error)
    {
        PEG_METHOD_EXIT();
        return false;
    }

    PEG_METHOD_EXIT();
    return true;
}