Home | History | Annotate | Download | only in src
      1 #ifdef LOB_SUPPORT
      2 //------------------------------------------------------------------------
      3 //
      4 //   Module Name: dm_tree_default_ESN_class.cc
      5 //
      6 //   General Description:Contains the implementations of the methods of
      7 //                       DMDefaultESN class.
      8 //------------------------------------------------------------------------
      9 // Revision History:
     10 //                     Modification   Tracking
     11 // Author (core ID)       Date         Number    Description of Changes
     12 //c23495               11/29/2006    libgg67059             LOB support
     13 // cdp180              03/16/2007    LIBll55345   Removing ACL check for internal calls
     14 // -----------------  ------------   ----------  -------------------------
     15 // Portability: This module is portable to other compilers.
     16 //------------------------------------------------------------------------
     17 //                          INCLUDE FILES
     18 //------------------------------------------------------------------------
     19 #include "dmdefs.h"
     20 #include "dm_tree_default_ESN_class.H" //header file for class defn
     21 #include "dm_tree_util.h"                    //FillgetRetData
     22 #include "xpl_File.h"
     23 #include "dm_uri_utils.h"
     24 
     25 //------------------------------------------------------------------------
     26 //                     LOCAL FUNCTION PROTOTYPES
     27 //------------------------------------------------------------------------
     28 //------------------------------------------------------------------------
     29 //                          LOCAL CONSTANTS
     30 //------------------------------------------------------------------------
     31 //------------------------------------------------------------------------
     32 //               LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
     33 //------------------------------------------------------------------------
     34 
     35 //------------------------------------------------------------------------
     36 //                            LOCAL MACROS
     37 //------------------------------------------------------------------------
     38 //------------------------------------------------------------------------
     39 //                           LOCAL VARIABLES
     40 //------------------------------------------------------------------------
     41 
     42 //------------------------------------------------------------------------
     43 //                          GLOBAL VARIABLES
     44 //------------------------------------------------------------------------
     45 //------------------------------------------------------------------------
     46 //                           LOCAL FUNCTIONS
     47 //------------------------------------------------------------------------
     48 //------------------------------------------------------------------------
     49 //                          GLOBAL FUNCTIONS
     50 //------------------------------------------------------------------------
     51 //------------------------------------------------------------------------
     52 
     53 //default constructor
     54 DMDefaultESN::DMDefaultESN(CPCHAR pbFileName):DMDefaultLeafNode()
     55 {
     56    abStorageName = NULL;
     57    abOriginalName =  (pbFileName != NULL) ? pbFileName : NULL;
     58 
     59    totalSize = 0L;
     60    m_bSetComplete = TRUE;
     61    m_bDirty = FALSE;
     62    m_bNeedLogging = FALSE;
     63 
     64    fileHandle = NULL;
     65    offset = 0L;
     66    // Mark as ESN
     67    SetESN();
     68 }
     69 // Destructor for ESN
     70 DMDefaultESN::~DMDefaultESN()
     71 {
     72 	CloseInternalFile();
     73 	abStorageName = NULL;
     74    	abOriginalName = NULL;
     75 }
     76 // Get internal storage file name
     77 CPCHAR DMDefaultESN::GetInternalStorageFileName(void) const
     78 {
     79 	return (abStorageName != NULL) ? abStorageName.c_str() : NULL;
     80 
     81 }
     82 CPCHAR DMDefaultESN::GetOriginalInternalFileName(void) const
     83 {
     84 	return (abOriginalName != NULL) ? abOriginalName.c_str() : NULL;
     85 }
     86 /*==================================================================================================
     87   * Function: : Close intenal storage file
     88   * param:
     89   * return : Return SYNCML_DM_SUCCESS if file open successfull and others in case of error
     90 *==================================================================================================
     91 */
     92 SYNCML_DM_RET_STATUS_T DMDefaultESN::CloseInternalFile(void)
     93 {
     94   SYNCML_DM_RET_STATUS_T retStatus = SYNCML_DM_SUCCESS;
     95   if (fileHandle != NULL)
     96  {
     97      fileHandle->close();
     98      delete fileHandle;
     99      fileHandle = NULL;
    100   }
    101   return retStatus;
    102 }
    103 /*==================================================================================================
    104   * Function: : Open intenal storage file
    105   * param:
    106   * return : Return SYNCML_DM_SUCCESS if file open successfull and others in case of error
    107 *==================================================================================================
    108 */
    109 
    110 SYNCML_DM_RET_STATUS_T DMDefaultESN::OpenInternalStorageFile()
    111 {
    112   SYNCML_DM_RET_STATUS_T retStatus = SYNCML_DM_SUCCESS;
    113   // If the file is not opened before
    114   if(fileHandle == NULL)
    115   {
    116    DMString abESNFileName;
    117 
    118    if(abStorageName.length() != 0)
    119    	abESNFileName = abStorageName;
    120    else
    121 	  abESNFileName = abOriginalName;
    122 
    123    if(abESNFileName.length() != 0) {
    124 
    125     INT32 modeFlag = XPL_FS_FILE_RDWR;
    126     // If file does not exist use write mode instead of read/write to prevent file I/O error
    127     if (!XPL_FS_Exist(abESNFileName.c_str()))
    128     {
    129 		modeFlag = XPL_FS_FILE_WRITE;
    130     }
    131     fileHandle = new DMFileHandler(abESNFileName.c_str(), FALSE);
    132     if (fileHandle == NULL)
    133        return SYNCML_DM_IO_FAILURE;
    134     if (fileHandle->open(modeFlag) != SYNCML_DM_SUCCESS)
    135     {
    136        fileHandle->deleteFile();
    137        delete fileHandle;
    138        fileHandle = NULL;
    139        return SYNCML_DM_IO_FAILURE;
    140     }
    141     totalSize = fileHandle->size();
    142    }
    143    else
    144    	totalSize = 0;
    145   }
    146    return retStatus;
    147 }
    148 //------------------------------------------------------------------------
    149 // FUNCTION        : Add
    150 // DESCRIPTION     : This function sets the ACCESS type and format
    151 //                   properties for an Interior node added in the tree.
    152 //                   No data involved ,so synchronous Non-blocking call
    153 //                   callback function pointers will be ignored
    154 // ARGUMENTS PASSED: *psAdd,
    155 // RETURN VALUE    : SYNCML_DM_RET_STATUS_T : status code
    156 // PRE-CONDITIONS  : 1.URI has already been validated
    157 //                   2.The node object of the plug-in class has been
    158 //                     created and a reference has been given to DMTNM
    159 // POST-CONDITIONS : Following property values are set by the function
    160 //                   Format = SYNCML_DM_FORMAT_NODE
    161 // IMPORTANT NOTES : The default Leaf node class grants all Access
    162 //                   rights to the Node in Add
    163 //                   If a Plug-in needs to implement a class for interior
    164 //                   nodes in which the access type needs to be plug-in
    165 //                   specific Ex: that plug-in does not want to give
    166 //                   delete access type, then the plug-in SHALL implement
    167 //                   it's own Add accordingly.
    168 // REQUIREMENT #   : ESR-DMTNM0042-m
    169 //------------------------------------------------------------------------
    170 SYNCML_DM_RET_STATUS_T DMDefaultESN::Add(DMAddData & oAddData)
    171 {
    172    return set(&oAddData);
    173 }
    174 
    175 //------------------------------------------------------------------------
    176 // FUNCTION        : Delete
    177 // DESCRIPTION     : This function should not actually not get called.
    178 //                   since DMTNM deletes the node object.It is a pure
    179 //                   virtual function in DMNode,hence is implemented and
    180 //                   returns SYNCML_DM_SUCCESS
    181 // ARGUMENTS PASSED: waitMsgForStatus
    182 //                   replyStatusCback
    183 //                   dwCommandId,
    184 //                   bItemNumber,
    185 //                   *pbUri,
    186 //                   oIsThisAtomic,
    187 // RETURN VALUE    : SYNCML_DM_RET_STATUS_T : ALWAYS returns
    188 //                   SYNCML_DM_COMMAND_NOT_ALLOWED
    189 // PRE-CONDITIONS  : 1.URI has already been validated
    190 // POST-CONDITIONS : DMTNM actually deletes the node object
    191 // IMPORTANT NOTES :
    192 // REQUIREMENT #   : ESR-DMTNM0025-m to ESR-DMTNM0027-m
    193 //------------------------------------------------------------------------
    194 SYNCML_DM_RET_STATUS_T DMDefaultESN::Delete(CPCHAR pbUri)
    195 {
    196   SYNCML_DM_RET_STATUS_T retStatus = SYNCML_DM_SUCCESS;
    197 
    198   // Remoeve temporary file
    199   if(m_bDirty)
    200   {
    201   retStatus = OpenInternalStorageFile();
    202   if(retStatus != SYNCML_DM_SUCCESS)
    203 	  return retStatus;
    204 
    205   retStatus = fileHandle->deleteFile();
    206   if(retStatus != SYNCML_DM_SUCCESS)
    207 	  return retStatus;
    208   delete fileHandle;
    209   fileHandle = NULL;
    210   }
    211   return CloseInternalFile();
    212 }
    213 
    214 
    215 //------------------------------------------------------------------------
    216 // FUNCTION        : Get
    217 // DESCRIPTION     :
    218 // ARGUMENTS PASSED: waitMsgForGetdata
    219 //                   waitMsgForGetdata
    220 //                   dwCommandId,
    221 //                   bItemNumber,
    222 //                   *pbUri,
    223 //                   dwStartByte,
    224 //                   dwNBytes
    225 //                   **ppsReturnData
    226 // RETURN VALUE    : SYNCML_DM_RET_STATUS_T : ALWAYS returns
    227 //                   SYNCML_DM_COMMAND_NOT_ALLOWED
    228 // PRE-CONDITIONS  : 1.URI has already been validated
    229 // POST-CONDITIONS :
    230 // IMPORTANT NOTES : The DMTNM will return the list of child names(if
    231 //                   the interior node has no children it will return
    232 //                   an empty list
    233 // REQUIREMENT #   : ESR-DMTNM0028-m
    234 //------------------------------------------------------------------------
    235 SYNCML_DM_RET_STATUS_T DMDefaultESN::Get(CPCHAR pbUri, DMGetData & oReturnData)
    236 {
    237   	SYNCML_DM_RET_STATUS_T retStatus = SYNCML_DM_SUCCESS;
    238 	// Set ESN flag
    239 	oReturnData.SetESN(TRUE);
    240 
    241 	if(oReturnData.chunkData != NULL)
    242 	{
    243 		if(m_bSetComplete == FALSE)
    244 			return SYNCML_DM_ESN_SET_NOT_COMPLETE;
    245 
    246 		offset = oReturnData.m_chunkOffset;
    247 		if(oReturnData.m_chunkOffset ==0)
    248 			retStatus = GetFirstChunk(*oReturnData.chunkData);
    249 		else
    250 			retStatus = GetNextChunk(*oReturnData.chunkData);
    251 	}
    252 	else
    253 	{
    254 		retStatus = OpenInternalStorageFile();
    255 		if(retStatus != SYNCML_DM_SUCCESS)
    256 			return retStatus;
    257 		retStatus = DMDefaultLeafNode::Get(pbUri, oReturnData);
    258 		oReturnData.m_TotalSize = totalSize;
    259 	}
    260 	return retStatus;
    261 }
    262 
    263 
    264 //------------------------------------------------------------------------
    265 // FUNCTION        : GetFormat
    266 //
    267 // DESCRIPTION     : This function returns FORMAT of the node
    268 // ARGUMENTS PASSED: waitMsgForGetFormat,
    269 //                   replyGetFormatCback,
    270 //                   *pbUri,
    271 //                   **pRetPropertyData
    272 // RETURN VALUE    : ALWAYS returns SYNCML_DM_FORMAT_NODE
    273 // PRE-CONDITIONS  : 1.URI has already been validated
    274 // POST-CONDITIONS :
    275 // IMPORTANT NOTES :
    276 // REQUIREMENT #   : ESR-DMTNM0033-m
    277 //------------------------------------------------------------------------
    278 SYNCML_DM_RET_STATUS_T DMDefaultESN::GetFormat(CPCHAR pbUri,
    279                                                        SYNCML_DM_FORMAT_T *dwpRetPropertyData)
    280 {
    281    *dwpRetPropertyData = this->bFormat;
    282    return(SYNCML_DM_SUCCESS);
    283 }
    284 
    285 //------------------------------------------------------------------------
    286 // FUNCTION        : GetType
    287 // DESCRIPTION     : This function returns MIME type
    288 // ARGUMENTS PASSED: waitMsgForGetFormat,
    289 //                   replyGetFormatCback,
    290 //                   *pbUri,
    291 //                   **pRetPropertyData
    292 // RETURN VALUE    : status code,type is NULL for interior nodes
    293 // PRE-CONDITIONS  : 1.URI has already been validated
    294 // POST-CONDITIONS :
    295 // IMPORTANT NOTES :
    296 // REQUIREMENT #   : ESR-DMTNM0033-m
    297 //------------------------------------------------------------------------
    298 SYNCML_DM_RET_STATUS_T DMDefaultESN::GetType(CPCHAR pbUri,
    299                                                      DMString& strType)
    300 {
    301    strType = this->getType();
    302    return SYNCML_DM_SUCCESS;
    303 }
    304 
    305 //------------------------------------------------------------------------
    306 // FUNCTION        : GetSize
    307 // DESCRIPTION     : This function returns SIZE of the node.
    308 // ARGUMENTS PASSED: waitMsgForGetFormat,
    309 //                   replyGetFormatCback,
    310 //                   *pbUri,
    311 //                   **pRetPropertyData
    312 // RETURN VALUE    :
    313 // PRE-CONDITIONS  : 1.URI has already been validated
    314 // POST-CONDITIONS :
    315 // IMPORTANT NOTES :
    316 // REQUIREMENT #   :
    317 //------------------------------------------------------------------------
    318 SYNCML_DM_RET_STATUS_T DMDefaultESN ::GetSize(CPCHAR pbUri,
    319                                                      UINT32 *dwpRetPropertyData)
    320 {
    321   SYNCML_DM_RET_STATUS_T retStatus = OpenInternalStorageFile();
    322   if(retStatus != SYNCML_DM_SUCCESS)
    323 		return retStatus;
    324    *dwpRetPropertyData= totalSize;
    325    return(SYNCML_DM_SUCCESS);
    326 }
    327 
    328 //------------------------------------------------------------------------
    329 // FUNCTION        : Rename
    330 // DESCRIPTION     : This function is called when a node's name has
    331 //                   been changed
    332 // ARGUMENTS PASSED: *pbUri,
    333 //                   pNewNodeName
    334 // RETURN VALUE    : ALWAYS returns SYNCML_DM_SUCCESS
    335 // PRE-CONDITIONS  : 1.URI has already been validated
    336 // POST-CONDITIONS :
    337 // IMPORTANT NOTES : The node Name will be renamed by the DMTNM.It informs
    338 //                   the plug-in about this to allow the plug-in to change
    339 //                   the name in the data-base correspondingly.Since
    340 //                   Interior nodes in this class have no database this
    341 //                   method simply returns SYNCML_DM_SUCCESS.This means that
    342 //                   name of node will be renamed by DMTNM,and plug-in
    343 //                   does not have anything specific to do.
    344 // REQUIREMENT #   :
    345 //------------------------------------------------------------------------
    346 SYNCML_DM_RET_STATUS_T DMDefaultESN::Rename(CPCHAR pbUri,
    347                                                     CPCHAR pNewNodeName)
    348 {
    349    return(SYNCML_DM_SUCCESS);
    350 }
    351 
    352 //------------------------------------------------------------------------
    353 // FUNCTION        : Replace
    354 //
    355 // DESCRIPTION     : This function is called when a node's value has
    356 //                   to be replaced.
    357 // ARGUMENTS PASSED: waitMsgForStatus,
    358 //                   replyStatusCback,
    359 //                   dwCommandId,
    360 //                   bItemNumber,
    361 //                   *pReplace,
    362 //                   oMoreData
    363 //                   oIsThisAtomic
    364 // RETURN VALUE    :
    365 // PRE-CONDITIONS  : 1.URI has already been validated
    366 // POST-CONDITIONS :
    367 // IMPORTANT NOTES :
    368 // REQUIREMENT #   : ESR-DMTNM0024-m
    369 //------------------------------------------------------------------------
    370 SYNCML_DM_RET_STATUS_T DMDefaultESN::Replace(DMAddData & oReplace)
    371 {
    372 	SYNCML_DM_RET_STATUS_T retStatus = SYNCML_DM_SUCCESS;
    373 	if(oReplace.chunkData != NULL)
    374 	{
    375 		offset = oReplace.m_chunkOffset;
    376 
    377 		if(oReplace.m_chunkOffset ==0)
    378 		{
    379 			retStatus = CloseInternalFile();
    380 			if(retStatus != SYNCML_DM_SUCCESS)
    381 			  	return retStatus;
    382 
    383 			retStatus = SetFirstChunk(*oReplace.chunkData);
    384 			if(retStatus != SYNCML_DM_SUCCESS)
    385 			  	return retStatus;
    386 		 	if(oReplace.IsLastChunk())
    387 			{  m_bSetComplete = TRUE;
    388 			   retStatus = CloseInternalFile();
    389 		 	}
    390 		}
    391 		else
    392 		{
    393 		    if(m_bDirty)
    394 		    {  if(oReplace.IsLastChunk())
    395 				retStatus = SetLastChunk(*oReplace.chunkData);
    396 			else
    397 				retStatus = SetNextChunk(*oReplace.chunkData);
    398 		    }
    399 		    else
    400 		      retStatus =  SYNCML_DM_INVALID_PARAMETER;
    401 		}
    402 	}
    403 	else
    404 	   retStatus = DMDefaultLeafNode::Replace(oReplace);
    405 	return retStatus;
    406 }
    407 //------------------------------------------------------------------------
    408 // FUNCTION        : Commit
    409 //
    410 // DESCRIPTION     : This function The method will commit  operations on the node
    411 // ARGUMENTS PASSED: waitMsgForStatus,
    412 //
    413 // RETURN VALUE    :
    414 // POST-CONDITIONS :
    415 // IMPORTANT NOTES :
    416 //------------------------------------------------------------------------
    417 SYNCML_DM_RET_STATUS_T DMDefaultESN::Commit()
    418 {
    419  SYNCML_DM_RET_STATUS_T retStatus = CloseInternalFile();
    420 
    421  if(retStatus != SYNCML_DM_SUCCESS)
    422  	return retStatus;
    423 
    424   // Is temporary file created?
    425   if(m_bDirty)
    426   {
    427 	 // Check if operations to the node is complete
    428 	 if(m_bSetComplete)
    429 	 {
    430 	   // Newly created node
    431 	   if(abOriginalName == NULL)
    432 	  	 abOriginalName.RemoveSufix(abStorageName.c_str(), SYNCML_DM_DOT);
    433 
    434 	   abStorageName = NULL;
    435 	   m_bDirty = FALSE;
    436 	   m_bSetComplete = TRUE;
    437 	 }
    438 	 else
    439 	 {
    440 		retStatus	 = SYNCML_DM_INCOMPLETE_COMMAND;
    441 	 }
    442  }
    443  return retStatus;
    444 
    445 }
    446 
    447 //------------------------------------------------------------------------
    448 // FUNCTION        : Rollback
    449 //
    450 // DESCRIPTION     : This function is called when a node's value has
    451 //                   needs to be rolledback. NOT SUPPORTED FOR PHASE 1
    452 // ARGUMENTS PASSED: waitMsgForStatus,
    453 //                   replyStatusCback,
    454 //                   dwCommandId,
    455 //                   bItemNumber,
    456 //                   dmCommand
    457 //                   *pbUri,
    458 // RETURN VALUE    : returns SYNCML_DM_FEATURE_NOT_SUPPORTED
    459 // PRE-CONDITIONS  : 1.URI has already been validated
    460 // POST-CONDITIONS :
    461 // IMPORTANT NOTES :
    462 // REQUIREMENT #   : ESR-DMTNM0037-m
    463 //------------------------------------------------------------------------
    464 SYNCML_DM_RET_STATUS_T DMDefaultESN::Rollback()
    465 {
    466    SYNCML_DM_RET_STATUS_T retStatus = CloseInternalFile();
    467    if(retStatus != SYNCML_DM_SUCCESS)
    468 	   return retStatus;
    469 
    470   if(m_bDirty)
    471   {	// Are there any temoprary file?
    472 	 if( abStorageName.length() != 0)
    473 	 {
    474 	 	SYNCML_DM_RET_STATUS_T retStatus = OpenInternalStorageFile();
    475 		 if(retStatus != SYNCML_DM_SUCCESS)
    476 		 return retStatus;
    477 
    478  	   	// Always delete the temporary file
    479 	    	if(fileHandle != NULL)
    480 	   	{ 	  retStatus = fileHandle->deleteFile();
    481 			  delete fileHandle;
    482 			  fileHandle = NULL;
    483 	   	}
    484 	}
    485 	// Clear the temporary file name
    486 	abStorageName = NULL;
    487    	m_bDirty = FALSE;
    488    	m_bSetComplete = TRUE;
    489   }
    490  return retStatus;
    491 }
    492 /*==================================================================================================
    493   * Function: :Get the first chunk
    494   * param dmtChunkData  -- reference to DmtDataChunk
    495   * return status code
    496 *==================================================================================================
    497 */
    498 SYNCML_DM_RET_STATUS_T DMDefaultESN::GetFirstChunk(DmtDataChunk&  chunkData)
    499 {
    500   	SYNCML_DM_RET_STATUS_T retStatus = OpenInternalStorageFile();
    501 	UINT32 remainlLen = totalSize- offset;
    502 	UINT32 getLen = 0L;
    503 	UINT8 *bufp;
    504 	if(retStatus != SYNCML_DM_SUCCESS)
    505 		return retStatus;
    506 
    507 	if(fileHandle == NULL)
    508 	{
    509 		chunkData.SetChunkData(NULL, 0L);
    510 		chunkData.SetReturnLen(getLen);
    511 		return retStatus;
    512 	}
    513 	chunkData.GetChunkData(&bufp);
    514 	if(remainlLen <0|| bufp == NULL)
    515 		return SYNCML_DM_INVALID_PARAMETER;
    516 
    517 	if(remainlLen == 0)
    518 	{
    519 		chunkData.SetChunkData(NULL, 0L);
    520 		chunkData.SetReturnLen(remainlLen);
    521 		return SYNCML_DM_SUCCESS;
    522 	}
    523 
    524 	getLen = chunkData.GetChunkSize();
    525 	if(getLen > remainlLen)
    526 		getLen = remainlLen;
    527 
    528 	chunkData.GetChunkData(&bufp); 	// the chunk data is available
    529 	if(bufp == NULL)
    530 		return SYNCML_DM_INVALID_PARAMETER;
    531     	if(fileHandle->seek(XPL_FS_SEEK_SET, offset) != SYNCML_DM_SUCCESS)
    532 	        return  SYNCML_DM_IO_FAILURE;
    533     	if(fileHandle->read(bufp, getLen) != SYNCML_DM_SUCCESS)
    534 	        return  SYNCML_DM_IO_FAILURE;
    535 	// Set data size
    536 	chunkData.SetChunkData(NULL, getLen);
    537 	// Set return data size
    538 	chunkData.SetReturnLen(getLen);
    539 	return retStatus;
    540 }
    541 
    542 /*==================================================================================================
    543   * Function: :Get the first chunk
    544   * param dmtChunkData  -- reference to DmtDataChunk
    545   * return status code
    546 *==================================================================================================
    547 */
    548 
    549 SYNCML_DM_RET_STATUS_T DMDefaultESN::GetNextChunk(DmtDataChunk& chunkData)
    550 {
    551 	return GetFirstChunk(chunkData);
    552 }
    553 /*==================================================================================================
    554   * Function: :set the first chunk
    555   * param dmtChunkData  -- reference to DmtDataChunk
    556   * return status code
    557 *==================================================================================================
    558 */
    559 SYNCML_DM_RET_STATUS_T DMDefaultESN::SetFirstChunk(DmtDataChunk& chunkData)
    560 {
    561 	SYNCML_DM_RET_STATUS_T retStatus = SYNCML_DM_SUCCESS;
    562 	UINT32 dataLen;
    563 	UINT8 *bufp;
    564     LOGD("DMDefaultESN::SetFirstChunk");
    565 
    566 	// No internal file created yet
    567 	if(abStorageName.length() == 0) {
    568 	   	retStatus = DMFileHandler::createTempESNFileName(abStorageName);
    569 		if(retStatus != SYNCML_DM_SUCCESS)
    570 			return retStatus;
    571 		if(offset == 0L)
    572 		{	m_bNeedLogging = TRUE;
    573 			m_bSetComplete = FALSE;
    574 		}
    575 
    576 	}
    577 	else// Replace previous data
    578 		{
    579 			// Set first trunk
    580 			if(offset == 0L)
    581 			{	totalSize = 0L;
    582    				m_bSetComplete = FALSE;
    583 				m_bNeedLogging = TRUE;
    584 
    585 				// Remove the current data file
    586   				retStatus = OpenInternalStorageFile();
    587 				if(retStatus != SYNCML_DM_SUCCESS)
    588 					return retStatus;
    589 
    590 				retStatus = fileHandle->deleteFile();
    591 				if(retStatus != SYNCML_DM_SUCCESS)
    592 					return retStatus;
    593 				delete fileHandle;
    594 				fileHandle = NULL;
    595 			}
    596 			else
    597 			{	m_bNeedLogging = FALSE;
    598 			}
    599 	}
    600 	chunkData.GetChunkDataSize(dataLen);
    601 	if(dataLen != 0)
    602 	{	retStatus = OpenInternalStorageFile();
    603 		if(retStatus != SYNCML_DM_SUCCESS)
    604 			return retStatus;
    605 
    606 		chunkData.GetChunkData(&bufp); 	// the chunk data is available
    607 		if(fileHandle == NULL  ||bufp == NULL)
    608 			return SYNCML_DM_INVALID_PARAMETER;
    609 
    610 		XPL_FS_SIZE_T fsize = fileHandle->size();
    611         LOGD("fileHandle file size=%d", fsize);
    612 
    613         // ehb005: no need to seek since we're writing and always appending to end of file
    614     	//if(fileHandle->seek(XPL_FS_SEEK_SET, offset) != SYNCML_DM_SUCCESS)
    615 	    //    return  SYNCML_DM_IO_FAILURE;
    616 	    	if(fileHandle->write(bufp, dataLen) != SYNCML_DM_SUCCESS)
    617 		        return  SYNCML_DM_IO_FAILURE;
    618 	}
    619 
    620 	totalSize = offset + dataLen;
    621 	chunkData.SetReturnLen(dataLen);
    622 	m_bDirty = TRUE;
    623 	LOGD("dataLen=%d, totalSize=%d, offset=%d", dataLen, totalSize, offset);
    624     LOGD("DMDefaultESN::SetFirstChunk abStorageName=%s", abStorageName.c_str());
    625 
    626     return retStatus;
    627 }
    628 /*==================================================================================================
    629   * Function: :set the next chunk
    630   * param dmtChunkData  -- reference to DmtDataChunk
    631   * return status code
    632 *==================================================================================================
    633 */
    634 SYNCML_DM_RET_STATUS_T DMDefaultESN::SetNextChunk(DmtDataChunk& chunkData)
    635 {
    636     LOGD("DMDefaultESN::SetNextChunk");
    637  	return SetFirstChunk(chunkData);
    638 }
    639 
    640 /*==================================================================================================
    641   * Function: :set the last chunk
    642   * param dmtChunkData  -- reference to DmtDataChunk
    643   * return status code
    644 *==================================================================================================
    645 */
    646 SYNCML_DM_RET_STATUS_T DMDefaultESN::SetLastChunk(DmtDataChunk& chunkData)
    647 {
    648     LOGD("DMDefaultESN::SetLastChunk");
    649 	SYNCML_DM_RET_STATUS_T retStatus = SetFirstChunk(chunkData);;
    650 	if(retStatus != SYNCML_DM_SUCCESS)
    651 		return retStatus;
    652 
    653 	m_bSetComplete = TRUE;
    654 	retStatus = CloseInternalFile();
    655 	return retStatus;
    656 }
    657 #endif
    658 
    659