Home | History | Annotate | Download | only in src
      1 /*************************************************************************/
      2 /* module:          Encoder utils file                                   */
      3 /* file:            xltenccom.c                                          */
      4 /* target system:   All                                                  */
      5 /* target OS:       All                                                  */
      6 /*************************************************************************/
      7 
      8 /*
      9  * Copyright Notice
     10  * Copyright (c) Ericsson, IBM, Lotus, Matsushita Communication
     11  * Industrial Co., Ltd., Motorola, Nokia, Openwave Systems, Inc.,
     12  * Palm, Inc., Psion, Starfish Software, Symbian, Ltd. (2001).
     13  * All Rights Reserved.
     14  * Implementation of all or part of any Specification may require
     15  * licenses under third party intellectual property rights,
     16  * including without limitation, patent rights (such a third party
     17  * may or may not be a Supporter). The Sponsors of the Specification
     18  * are not responsible and shall not be held responsible in any
     19  * manner for identifying or failing to identify any or all such
     20  * third party intellectual property rights.
     21  *
     22  * THIS DOCUMENT AND THE INFORMATION CONTAINED HEREIN ARE PROVIDED
     23  * ON AN "AS IS" BASIS WITHOUT WARRANTY OF ANY KIND AND ERICSSON, IBM,
     24  * LOTUS, MATSUSHITA COMMUNICATION INDUSTRIAL CO. LTD, MOTOROLA,
     25  * NOKIA, PALM INC., PSION, STARFISH SOFTWARE AND ALL OTHER SYNCML
     26  * SPONSORS DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
     27  * BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
     28  * HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF
     29  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
     30  * SHALL ERICSSON, IBM, LOTUS, MATSUSHITA COMMUNICATION INDUSTRIAL CO.,
     31  * LTD, MOTOROLA, NOKIA, PALM INC., PSION, STARFISH SOFTWARE OR ANY
     32  * OTHER SYNCML SPONSOR BE LIABLE TO ANY PARTY FOR ANY LOSS OF
     33  * PROFITS, LOSS OF BUSINESS, LOSS OF USE OF DATA, INTERRUPTION OF
     34  * BUSINESS, OR FOR DIRECT, INDIRECT, SPECIAL OR EXEMPLARY, INCIDENTAL,
     35  * PUNITIVE OR CONSEQUENTIAL DAMAGES OF ANY KIND IN CONNECTION WITH
     36  * THIS DOCUMENT OR THE INFORMATION CONTAINED HEREIN, EVEN IF ADVISED
     37  * OF THE POSSIBILITY OF SUCH LOSS OR DAMAGE.
     38  *
     39  * The above notice and this paragraph must be included on all copies
     40  * of this document that are made.
     41  *
     42  */
     43 
     44 /*************************************************************************/
     45 /*  Definitions                                                          */
     46 /*************************************************************************/
     47 
     48 
     49 #include "xltenccom.h"
     50 #include <smlerr.h>
     51 #include <libmem.h>
     52 
     53 /**
     54  * FUNCTION: xltAddToBuffer
     55  *
     56  * Add a string to the global buffer
     57  *
     58  * PRE-Condition:  pContent contains some content bytes to write to the (WB) XML buffer
     59  *
     60  * POST-Condition: content is written to the buffer
     61  *
     62  * IN:             pContent, the character pointer referencing the content to
     63  *                           write to the buffer
     64  *                 size, the content length
     65  *
     66  * IN/OUT:         pBufMgr, pointer to a structure containing buffer management elements
     67  *
     68  * RETURN:         shows error codes of function,
     69  *                 0, if OK
     70  */
     71 Ret_t xltAddToBuffer(const MemPtr_t pContent, MemSize_t size, BufferMgmtPtr_t pBufMgr)
     72 {
     73   // if we are doing a space evaluation, do not write the data physically - just remember its length
     74   if (!pBufMgr->spaceEvaluation) {
     75     //check if buffersize is to small to write the content
     76   	if ((size + pBufMgr->smlXltWrittenBytes) > pBufMgr->smlXltBufferLen) {
     77   	  #ifdef NCDEBUGPRINTFX
     78   	  #warning "%%%%% delete that message later"
     79   	  NCDEBUGPRINTFX(DBG_SYNCML,(
     80   	    "xltAddToBuffer: buffer too small, pContent='%0.30s', size=%ld, pBufMgr->smlXltWrittenBytes=%ld, pBufMgr->smlXltBufferLen=%ld",
     81   	    pContent,
     82   	    size,
     83   	    pBufMgr->smlXltWrittenBytes,
     84   	    pBufMgr->smlXltBufferLen
     85   	  ));
     86   	  #endif
     87       return SML_ERR_XLT_BUF_ERR;
     88   	}
     89 
     90     if (!(smlLibMemcpy((void*) pBufMgr->smlXltBufferP, (void*) pContent, (MemSize_t) size))) {
     91   	  #ifdef NCDEBUGPRINTFX
     92   	  #warning "%%%%% delete that message later"
     93   	  NCDEBUGPRINTFX(DBG_SYNCML,(
     94   	    "xltAddToBuffer: memCpy failed, pBufMgr->smlXltBufferP=%lX, size=%ld",
     95   	    (long)pBufMgr->smlXltBufferP,
     96   	    size
     97   	  ));
     98   	  #endif
     99       return SML_ERR_XLT_BUF_ERR;
    100     }
    101     pBufMgr->smlXltBufferP += size;
    102   }
    103   pBufMgr->smlXltWrittenBytes += size;
    104 
    105   return SML_ERR_OK;
    106 }
    107