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

📄 obex.c

📁 SyncML手册及其编程
💻 C
📖 第 1 页 / 共 5 页
字号:
/* * 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. *  *//******************************************************************************* Defines public API's and constants for the OBEX transport.**** (See obexStructures.h for command/response constants.)*****************************************************************************/#include "syncml_tk_prefix_file.h" // %%% luz: needed for precompiled headers in eVC++#define EXPORT_OBEX_FUNCTIONS#include <obex/obex.h>#include <iConstants.h>#include <handle.h>#include <object.h>#include <utils.h>#include <buffer.h>#include <transport.h>#include <limits.h>#include <assert.h>#include <time.h>	/* for time() */#ifndef min #define min(a, b) ((a) < (b) ? (a) : (b))#endif#ifndef max #define max(a, b) ((a) > (b) ? (a) : (b))#endifOBEX_EXPORT void ObxInit() {   OBXDBGFLOW(("ObxInit() entry.\n"));   /*   ** We've made some assumptions about the size of things...   */   assert( sizeof( short ) == 2 );   assert( sizeof( int ) == 4 );#ifdef _WIN32   _initializeSockets();#endif}OBEX_EXPORT ObxHandle* ObxHandleNew() {   OBXDBGFLOW(("ObxHandleNew() entry.\n"));   return iobxHandleNew();}OBEX_EXPORT void ObxHandleFree( ObxHandle *handle ) {   OBXDBGFLOW(("ObxHandleFree() entry, handle=0x%08x\n", handle));   iobxHandleFree( handle );}OBEX_EXPORT ObxTransport *ObxTransportGet( short preDefinedTransportId ) {   OBXDBGFLOW(("ObxTransportGet() entry, id=%d\n", preDefinedTransportId));   return iobxTransportGet( preDefinedTransportId );}OBEX_EXPORT void ObxTransportFree( ObxTransport *transport ) {   OBXDBGFLOW(("ObxTransportFree() entry, transport=0x%08x\n", transport));   iobxTransportFree( transport );}OBEX_EXPORT ObxRc ObxTransportRegister( ObxHandle *handle, ObxTransport *transport ) {   OBXDBGFLOW(("ObxTransportRegister() entry, handle=0x%08x\ttransport=0x%08x\n", handle, transport));   return ( handle == NULL ) ?            OBX_RC_ERR_BADPLIST : (handle->transport = transport, OBX_RC_OK);}OBEX_EXPORT ObxRc ObxTransportInitialize( ObxHandle *handle, const char *meta ) {   OBXDBGFLOW(("ObxTransportInitialize() entry, handle=0x%08x\n", handle));   return ( handle == NULL || handle->transport == NULL ) ?            OBX_RC_ERR_BADPLIST : (handle->transport->initialize)( meta );}OBEX_EXPORT ObxRc ObxTransportOpen( ObxHandle *handle ) {   OBXDBGFLOW(("ObxTransportOpen() entry, handle=0x%08x\n", handle));   return ( handle == NULL || handle->transport == NULL ) ?            OBX_RC_ERR_BADPLIST : (handle->transport->open)( &handle->connectionId );}OBEX_EXPORT ObxRc ObxTransportClose( ObxHandle *handle ) {   OBXDBGFLOW(("ObxTransportClose() entry, handle=0x%08x\n", handle));   return ( handle == NULL || handle->transport == NULL ) ?            OBX_RC_ERR_BADPLIST : (handle->transport->close)( &handle->connectionId );}OBEX_EXPORT ObxRc ObxTransportListen( ObxHandle *handle ) {   OBXDBGFLOW(("ObxTransportListen() entry, handle=0x%08x\n", handle));   return ( handle == NULL || handle->transport == NULL ) ?            OBX_RC_ERR_BADPLIST : (handle->transport->listen)( &handle->connectionId );}OBEX_EXPORT ObxRc ObxTransportAccept( ObxHandle *handle ) {   OBXDBGFLOW(("ObxTransportAccept() entry, handle=0x%08x\n", handle));   return ( handle == NULL || handle->transport == NULL ) ?            OBX_RC_ERR_BADPLIST : (handle->transport->accept)( &handle->connectionId );}OBEX_EXPORT ObxRc ObxTransportConnect( ObxHandle *handle ) {   OBXDBGFLOW(("ObxTransportConnect() entry, handle=0x%08x\n", handle));   return ( handle == NULL || handle->transport == NULL ) ?            OBX_RC_ERR_BADPLIST : (handle->transport->connect)( &handle->connectionId );}OBEX_EXPORT ObxRc ObxTransportTerminate( ObxHandle *handle ) {   OBXDBGFLOW(("ObxTransportTerminate() entry, handle=0x%08x\n", handle));   return ( handle == NULL || handle->transport == NULL ) ?            OBX_RC_ERR_BADPLIST : (handle->transport->terminate)();}OBEX_EXPORT ObxRc ObxObjectSend( ObxHandle *handle, ObxObject *object ) {   OBXDBGFLOW(("ObxObjectSend() entry, handle=0x%08x\tobject=0x%08x\n", handle, object));   return iobxObjectSendObject( object, handle );}#ifndef RAW_API_ONLYOBEX_EXPORT ObxStream *ObxStreamNew() {   ObxStream *stream;   if ( (stream=(ObxStream *)malloc(sizeof( ObxStream ) )) ) {      OBXDBGBUF(("ObxStreamNew() malloc, addr=0x%08x, len=%d.\n", stream, sizeof(ObxStream) ));      stream->handle = NULL;      stream->data = iobxBufNew( 10 );      stream->request = iobxObjectNew();      stream->state = STREAM_UNOPEN;   }   return stream;}OBEX_EXPORT ObxRc ObxStreamFree( ObxStream *stream ) {   ObxRc rc = OBX_RC_OK;   if ( stream ) {      if ( stream->state != STREAM_CLOSED ) {         OBXDBGERR(("[ERROR] ObxStreamFree() freeing stream before it was closed!\n"));      }      iobxBufFree( stream->data );      stream->data = NULL;      /*      ** We can just release any buffers contained within this request, because      ** the *only* element ever put on it's list is stream->data, which was      ** just released.      */      iobxListRelease( iobxObjectGetHeaderList( stream->request ) );      iobxObjectFree( stream->request );      stream->request = NULL;      free( stream );   }   return rc;}OBEX_EXPORT ObxRc ObxStreamingSend( ObxHandle *handle, ObxObject *request, ObxStream *stream ) {   ObxRc          rc = OBX_RC_OK;   ObxObject      *response;   OBXDBGFLOW(("ObxStreamingSend() entry, handle=0x%08x\trequest=0x%08x\tstream=0x%08x\n", handle, request, stream));   if ( handle && request && stream ) {      if ( request->cmd == OBEX_CMD_GET ) {         return OBX_RC_ERR_INAPPROPRIATE;      }      /*      ** State must be UNOPEN when this is called.      */      if ( stream->state == STREAM_UNOPEN ) {         response = iobxObjectNew();         if ( request->cmd == OBEX_CMD_PUT ) {            /*            ** Setup stream, we're SENDING.            */            stream->cmd = OBEX_CMD_PUT;   /* Always */            stream->state = STREAM_SENDING;            stream->handle = handle;            request->stream = TRUE;       /* request is part of a stream */            /*            ** Send all headers the user has provided in their initial request.            */            if ( (rc= ObxTransactionSend( stream->handle, request, response )) != OBX_RC_OK ) {               OBXDBGERR(("[ERROR] ObxStreamingSend() unexpected rc calling ObxTransactionSend().\n"));            } else {               OBXDBGINFO(("ObxStreamingSend() success.\n"));            }         } else {            OBXDBGERR(("[ERROR] ObxStreamingSend() Must be a PUT command!\n"));            rc = OBX_RC_ERR_INAPPROPRIATE;         }         iobxObjectFree( response );      } else {         OBXDBGERR(("[ERROR] ObxStreamingSend() stream state was not STREAM_UNOPEN!\n"));         rc = OBX_RC_ERR_INAPPROPRIATE;      }   } else {      OBXDBGERR(("[ERROR] ObxStreamingSend() Bad plist on call\n"));      rc = OBX_RC_ERR_BADPLIST;   }   return rc;}OBEX_EXPORT ObxRc ObxStreamingRecv( ObxHandle *handle, ObxObject *request, ObxStream *stream ) {   ObxRc rc = OBX_RC_OK;   OBXDBGFLOW(("ObxStreamingRecv() entry, handle=0x%08x\trequest=0x%08x\tstream=0x%08x\n", handle, request, stream));   if ( handle && request && stream ) {      /*      ** Stream must be UNOPENed when this is called.      */      if ( stream->state == STREAM_UNOPEN ) {         /*         ** Setup stream, we're receiving now.         */         stream->state = STREAM_RECEIVING;         stream->handle = handle;         request->stream = TRUE;    /* Request is part of a stream */         /*         ** Populate the users request object with a group of headers.         ** This could be all the headers, or just the first group.         */         if ( (rc= ObxTransactionRecv( stream->handle, request, FALSE )) != OBX_RC_OK ) {            OBXDBGERR(("[ERROR] ObxStreamingRecv() unexpected rc calling ObxTransactionRecv().\n"));         } else {            if ( request->cmd == OBEX_CMD_GET ) {               return OBX_RC_ERR_NO_GET_SUPPORT;            }            /*            ** Was that all the peer was sending on this transaction?            */            if ( request->cmd & OBEX_CMD_FINAL ) {               /*               ** Yep, all in one send.               */               stream->state = STREAM_FINISHED;               rc = OBX_RC_STREAM_EOF;               OBXDBGINFO(("ObxStreamingRecv() success, FINAL packet from peer.\n"));            } else {               /*               ** Nope, more are expected.               */               OBXDBGINFO(("ObxStreamingRecv() success, more packets expected from peer..\n"));            }

⌨️ 快捷键说明

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