Index: ext/libicpf/src/libicpf/cfg.cpp =================================================================== diff -u -r42fda86dd6448c89e6db68e0df8741e9ad5269f1 -r9934e5dc9613bf3246f7d4955d4dd7c07f0dd555 --- ext/libicpf/src/libicpf/cfg.cpp (.../cfg.cpp) (revision 42fda86dd6448c89e6db68e0df8741e9ad5269f1) +++ ext/libicpf/src/libicpf/cfg.cpp (.../cfg.cpp) (revision 9934e5dc9613bf3246f7d4955d4dd7c07f0dd555) @@ -197,6 +197,29 @@ m_lock.unlock(); } +/** Reads the configuration data from the provided buffer. + * + * \param[in] pszData - pointer to the buffer with data + * \param[in] stSize - size of the data in buffer + */ +void config::read_from_buffer(const tchar_t* pszData, size_t stSize) +{ + m_lock.lock(); + try + { + m_pCfgBase->read_from_buffer(pszData, stSize); + + // and transform it to eatable form using registered properties + load_registered(); + } + catch(...) + { + m_lock.unlock(); + throw; + } + m_lock.unlock(); +} + /** Writes all the registered properties into the given file using * the underlying config base to do this. * Index: ext/libicpf/src/libicpf/cfg.h =================================================================== diff -u -r3150d0c0a9a5fe75a5954e17a5a445a14e0bea1f -r9934e5dc9613bf3246f7d4955d4dd7c07f0dd555 --- ext/libicpf/src/libicpf/cfg.h (.../cfg.h) (revision 3150d0c0a9a5fe75a5954e17a5a445a14e0bea1f) +++ ext/libicpf/src/libicpf/cfg.h (.../cfg.h) (revision 9934e5dc9613bf3246f7d4955d4dd7c07f0dd555) @@ -93,6 +93,7 @@ /** \name Reading and writing to the external medium */ /**@{*/ void read(const tchar_t *pszPath); ///< Reads the properties from the source file + void read_from_buffer(const tchar_t* pszData, size_t stSize); void write(const tchar_t* pszPath); ///< Saves the properties to the file /**@}*/ Index: ext/libicpf/src/libicpf/cfg_ini.cpp =================================================================== diff -u -r3150d0c0a9a5fe75a5954e17a5a445a14e0bea1f -r9934e5dc9613bf3246f7d4955d4dd7c07f0dd555 --- ext/libicpf/src/libicpf/cfg_ini.cpp (.../cfg_ini.cpp) (revision 3150d0c0a9a5fe75a5954e17a5a445a14e0bea1f) +++ ext/libicpf/src/libicpf/cfg_ini.cpp (.../cfg_ini.cpp) (revision 9934e5dc9613bf3246f7d4955d4dd7c07f0dd555) @@ -117,7 +117,9 @@ else parse_line(pszBuffer); } - + + delete [] pszBuffer; + // check if that was eof or error if(feof(pFile) == 0) { @@ -130,6 +132,69 @@ fclose(pFile); } +/// Processes the data from a given buffer +void ini_cfg::read_from_buffer(const tchar_t* pszBuffer, size_t stLen) +{ + // clear current contents + clear(); + + tchar_t* pszLine = new tchar_t[INI_BUFFER]; + size_t stLineLen = 0; + const tchar_t* pszCurrent = pszBuffer; + const tchar_t* pszLast = pszBuffer; + bool bFirstLine = true; + while(stLen--) + { + if(*pszCurrent == _t('\n')) + { + // there is a line [pszLast, pszCurrent) + stLineLen = pszCurrent - pszLast; + if(stLineLen) + { + if(stLineLen >= INI_BUFFER) + stLineLen = INI_BUFFER - 1; + _tcsncpy(pszLine, pszLast, stLineLen); + pszLine[stLineLen] = _t('\0'); + + if(bFirstLine) + { + bFirstLine = false; + // check BOM + if(pszLine[0] != _t('\0') && *(ushort_t*)pszLine == 0xfeff) + parse_line(pszLine + 1); + else + parse_line(pszLine); + } + else + { + // process the line + parse_line(pszLine); + } + } + pszLast = pszCurrent + 1; + } + ++pszCurrent; + } + if(pszCurrent != pszLast) + { + // there is a line [pszLast, pszCurrent) + stLineLen = pszCurrent - pszLast; + if(stLineLen) + { + if(stLineLen >= INI_BUFFER) + stLineLen = INI_BUFFER - 1; + + _tcsncpy(pszLine, pszLast, stLineLen); + pszLine[stLineLen] = _t('\0'); + + // process the line + parse_line(pszLine); + } + } + + delete [] pszLine; +} + /** Saves the internal xml nodes to the specified xml file. * * \param[in] pszPath - path to the file the data should be written to Index: ext/libicpf/src/libicpf/cfg_ini.h =================================================================== diff -u -r3150d0c0a9a5fe75a5954e17a5a445a14e0bea1f -r9934e5dc9613bf3246f7d4955d4dd7c07f0dd555 --- ext/libicpf/src/libicpf/cfg_ini.h (.../cfg_ini.h) (revision 3150d0c0a9a5fe75a5954e17a5a445a14e0bea1f) +++ ext/libicpf/src/libicpf/cfg_ini.h (.../cfg_ini.h) (revision 9934e5dc9613bf3246f7d4955d4dd7c07f0dd555) @@ -43,6 +43,8 @@ /**@{*/ /// Reads the xml document from the specified file virtual void read(const tchar_t* pszPath); + /// Processes the data from a given buffer + virtual void read_from_buffer(const tchar_t* pszBuffer, size_t stLen); /// Saves the internal data to a specified file as the xml document virtual void save(const tchar_t* pszPath); /**@}*/ Index: ext/libicpf/src/libicpf/config_base.h =================================================================== diff -u -r3150d0c0a9a5fe75a5954e17a5a445a14e0bea1f -r9934e5dc9613bf3246f7d4955d4dd7c07f0dd555 --- ext/libicpf/src/libicpf/config_base.h (.../config_base.h) (revision 3150d0c0a9a5fe75a5954e17a5a445a14e0bea1f) +++ ext/libicpf/src/libicpf/config_base.h (.../config_base.h) (revision 9934e5dc9613bf3246f7d4955d4dd7c07f0dd555) @@ -50,6 +50,8 @@ /**@{*/ /// Reads the xml document from the specified file virtual void read(const tchar_t* pszPath) = 0; + /// Processes the data from a given buffer + virtual void read_from_buffer(const tchar_t* pszBuffer, size_t stLen) = 0; /// Saves the internal data to a specified file as the xml document virtual void save(const tchar_t* pszPath) = 0; /**@}*/