⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 object.c

📁 SyncML ToolKits,学习syncml的参考工具包.非常好用.
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * Copyright Notice * Copyright (c) Ericsson, IBM, Lotus, Matsushita Communication  * Industrial Co., Ltd., Motorola, Nokia, Openwave Systems, Inc.,  * Palm, Inc., Psion, Starfish Software, Symbian, Ltd. (2001). * All Rights Reserved. * Implementation of all or part of any Specification may require  * licenses under third party intellectual property rights,  * including without limitation, patent rights (such a third party  * may or may not be a Supporter). The Sponsors of the Specification  * are not responsible and shall not be held responsible in any  * manner for identifying or failing to identify any or all such  * third party intellectual property rights. *  * THIS DOCUMENT AND THE INFORMATION CONTAINED HEREIN ARE PROVIDED  * ON AN "AS IS" BASIS WITHOUT WARRANTY OF ANY KIND AND ERICSSON, IBM,  * LOTUS, MATSUSHITA COMMUNICATION INDUSTRIAL CO. LTD, MOTOROLA,  * NOKIA, PALM INC., PSION, STARFISH SOFTWARE AND ALL OTHER SYNCML  * SPONSORS DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING  * BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION  * HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT  * SHALL ERICSSON, IBM, LOTUS, MATSUSHITA COMMUNICATION INDUSTRIAL CO.,  * LTD, MOTOROLA, NOKIA, PALM INC., PSION, STARFISH SOFTWARE OR ANY  * OTHER SYNCML SPONSOR BE LIABLE TO ANY PARTY FOR ANY LOSS OF  * PROFITS, LOSS OF BUSINESS, LOSS OF USE OF DATA, INTERRUPTION OF  * BUSINESS, OR FOR DIRECT, INDIRECT, SPECIAL OR EXEMPLARY, INCIDENTAL,  * PUNITIVE OR CONSEQUENTIAL DAMAGES OF ANY KIND IN CONNECTION WITH  * THIS DOCUMENT OR THE INFORMATION CONTAINED HEREIN, EVEN IF ADVISED  * OF THE POSSIBILITY OF SUCH LOSS OR DAMAGE. *  * The above notice and this paragraph must be included on all copies  * of this document that are made. *  */#include <object.h>#include <iConstants.h>#include <utils.h>#include <buffer.h>/******************************************************************************* Obex Object**** Represents an obex object (i.e. connect request, response ect.).** Obex objects consist of indentifiers and a list of headers.*****************************************************************************//*** Creates and initializes a new ObxObject structure.*/ObxObject      *iobxObjectNew() {   ObxObject *object = NULL;   OBXDBGFLOW(("iobxObjectNew() entry.\n"));   if ( (object = (ObxObject *)malloc( sizeof( ObxObject ) )) ) {      OBXDBGBUF(("iobxObjectNew() malloc, addr=0x%08x, len=%d.\n", object, sizeof(ObxObject)));      object->stream = 0;      object->headers = NULL;      object->meta.connectMeta = NULL;      object->meta.setPathMeta = NULL; /* Not really needed, since union */   }   return object;}/*** Destroys the passed ObxObject structure.  All internal structures and** the ObxObject structure itself is free()'ed.*/void           iobxObjectFree( ObxObject *object ) {   ObxIterator  *obxiterator = NULL;   OBXDBGFLOW(("iobxObjectFree() entry, object=0x%08x\n", object));   if ( object ) {      if ( object->headers ) {         if ( (obxiterator=iobxListGetIterator( object->headers )) ) {            iobxIteratorReset( obxiterator );            while ( iobxIteratorHasNext( obxiterator ) ) {                ObxHeader *tempHeader =(ObxHeader *)iobxIteratorNext( obxiterator ) ;               iobxHeaderFree( tempHeader);               tempHeader = NULL;            }            iobxListRelease( object->headers );            iobxListFree( object->headers );            object->headers = NULL;         }         if ( obxiterator ) {            iobxIteratorFree( obxiterator );         }      }      /*      ** Since it's a union, and both types are pointers to structs..      ** we just free one.. it will get the other... :-)      */      if ( object->meta.connectMeta ) {         free( (void *)object->meta.connectMeta );         object->meta.connectMeta = NULL;         object->meta.setPathMeta = NULL; /* Redundant... */      }      free( object );   }}/*** The passed ObxObject is cleared to an initial state.  Allows users to** reuse objects.*/ObxRc          iobxObjectReset( ObxObject *object ) {   ObxRc rc = OBX_RC_OK;   OBXDBGFLOW(("iobxObjectReset() entry, object=0x%08x\n", object));   if ( object ) {      /*      ** Free/setmeta      */      /*      ** Since it's a union, and both types are pointers to structs..      ** we just free one.. it will get the other... :-)      */      if ( object->meta.connectMeta ) {         free( (void *)object->meta.connectMeta );         object->meta.connectMeta = NULL;         object->meta.setPathMeta = NULL; /* Redundant... */      }      object->cmd = 0;      object->stream = 0;      /*      ** Recycle the headers list, if it exists, if not, create it.      */      if ( object->headers ) {         //iobxListReset( object->headers );          iobxListRelease( object->headers );          iobxListFree( object->headers );         if ( !(object->headers = iobxListNew()) ) {            OBXDBGERR(("[ERROR] iobxObjectReset() failure creating list.\n"));            rc = OBX_RC_ERR_MEMORY;         }      } else {         if ( !(object->headers = iobxListNew()) ) {            OBXDBGERR(("[ERROR] iobxObjectReset() failure creating list.\n"));            rc = OBX_RC_ERR_MEMORY;         }      }      object->state = STATE_BUILDING;   } else {      OBXDBGERR(("[ERROR] iobxObjectReset() bad plist on call.\n"));      rc = OBX_RC_ERR_BADPLIST;   }   return rc;}/*** Adds a header to the list of headers associated with the object.*/ObxRc          iobxObjectAddHeader( ObxObject *object, ObxHeader *newheader, ObxHandle *handle ) {   ObxRc          rc = OBX_RC_OK;   int            availLen = 0;   ObxIterator    *iterator = NULL;   ObxHeader      *header = NULL;   OBXDBGFLOW(("iobxObjectAddHeader() entry, object=0x%08x\theader=0x%08x\thandle=0x%08x\n", object, newheader, handle));   if ( object && newheader && handle ) {      if ( object->state == STATE_BUILDING ) {         if ( object->headers ) {            if ( newheader->identifier == OBEX_HEADER_BODY || newheader->identifier == OBEX_HEADER_BODY_END ) {               /*               ** Just add it.               */               iobxListAppend( object->headers, newheader );            } else {               /*               ** Will inbound non-body header fit within an MTU?               */               if ( (iterator = iobxListGetIterator( object->headers )) ) {                  /*                  ** Calc size                  ** [MJH] Maybe I should just have an incrementing int or something.. avoid                  ** iteration for each header...                  */                  iterator = iobxIteratorReset( iterator );                  availLen = handle->maxPacketLen - iobxObjectPrefixSize( object, handle );                  while ( iobxIteratorHasNext( iterator ) ) {                     if ( (header = (ObxHeader *)iobxIteratorNext( iterator )) ) {                        /*                        ** Determine amount of non-body data we're holding.                        */                        if ( header->identifier != OBEX_HEADER_BODY && header->identifier != OBEX_HEADER_BODY_END ) {                           availLen -= iobxHeaderSize( header );                        }                     }                  }               } else {                  OBXDBGERR(("[ERROR] iobxObjectAddHeader() error calling iobxListGetIterator().\n"));                  return OBX_RC_ERR_TRANSPORT;               }               iobxIteratorFree( iterator );               if ( availLen >= iobxHeaderSize( newheader ) ) {                  iobxListAppend( object->headers, newheader );               } else {                  OBXDBGERR(("[ERROR] iobxObjectAddHeader() inbound header would cause object size to exceed maximum packet length of %d.\n", handle->maxPacketLen));                  rc = OBX_RC_ERR_OBJ_HDR_NO_FIT;               }            }         } else {            OBXDBGERR(("[ERROR] iobxObjectAddHeader() list object does not appear to be initialized.\n"));            rc = OBX_RC_ERR_NOTINITIALIZED;         }      } else {         OBXDBGERR(("[ERROR] iobxObjectAddHeader() object not 'building', inappropriate call.\n"));         rc = OBX_RC_ERR_INAPPROPRIATE;      }   } else {      OBXDBGERR(("[ERROR] iobxObjectAddHeader() bad plist on call.\n"));      rc = OBX_RC_ERR_BADPLIST;   }   return rc;}/*** Requests the current list of headers be returned.  From this object users** can get an iterator and manipulate the header list.*/ObxList        *iobxObjectGetHeaderList( ObxObject *object ) {   OBXDBGFLOW(("iobxObjectGetHeaderList() entry, object=0x%08x\n", object));   return (object ? object->headers : NULL);}/*** What's the prefix size of this object?*/int         iobxObjectPrefixSize( ObxObject *object, ObxHandle *handle ) {   int prefixSize = 0;   if (   handle->lastRecv == OBEX_CMD_CONNECT || object->cmd == OBEX_CMD_CONNECT ) {      /*      ** This implies that we're responding to a connect, or connecting anew.      ** In either case, our prefix length (because of the meta data) is the same.      */      prefixSize = 7;   } else if ( object->cmd == OBEX_CMD_SETPATH ) {      /*

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -