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

📄 obexbinding.c

📁 SyncML手册及其编程
💻 C
📖 第 1 页 / 共 5 页
字号:
/*************************************************************************//* module:          SyncML OBEX binding source file.                     *//* file:            src/xpt/bindings/obex/win/obexbinding.c              *//* target system:   all                                                  *//* target OS:       all                                                  *//*************************************************************************//* * 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 "syncml_tk_prefix_file.h" // %%% luz: needed for precompiled headers in eVC++#define OBEX_BINDING_IS_EXPORTING 1#include <xptTransport.h> // Mickey 2003-01-29#include <obexbinding.h>#include <iConstants.h>#include <string.h>#include <stdio.h>#include <limits.h>#include <handle.h> // Mickey 2003-01-29#ifdef _WIN32 #define WIN32_LEAN_AND_MEAN #include <windows.h> #define oSleep(sec)   SleepEx((sec)*1000, TRUE)#else #include <unistd.h> #define oSleep sleep#endif/*********************************************************************************//***************************** Public Functions **********************************//*********************************************************************************/#ifdef INCLUDE_OBEX_STATICALLY#define initializeTransport obexInitializeTransport#endif/** *  Called by xpt when our DLL is loaded.  This function is required to *  call and register each api proto. */XPTEXP1 Ret_t XPTAPI XPTEXP2 initializeTransport(void) {   Ret_t rc1, rc2;   XPTDEBUG(("OBX initializeTransport()\n"));   ObxInit();   rc1 = obxRegisterTcpObex();   rc2 = obxRegisterIrObex();   return rc1 ? rc1 : rc2;}/** * FUNCTION: Called when xptSelectProtocol() is called, selecting this *           transport binding. * *  Select the communication protocol to start the communication * * IN: privateTransportInfo, pointer to the transport binding's private *         information about the transport, the value given in the *         privateTransportInfo field of the xptTransportDescription struct *         when the transport binding was registered. * *     szSettings, passed directly from the xptSelectProtocol() call. * * OUT: *pPrivateServiceInfo, pointer to the transport binding's private *         information for the newly allocated service instance.  This *         pointer will be passed on subsequent calls to the transport's *         functions to identify this service instance to the transport. * * META: *          HOST=portSpec *             For example, 192.168.5.1 or howlandm.endicott.ibm.com *             If not specified, and using INET connections, the default is 'localhost' *          PORT=portSpec *             For example, 1122 *             If not specified, and using INET connections, the default is 650 (OBEX_PORT constant *             in the code).  This is also the default if unable to convert to short. *          SERVICE=irServiceSpec *             For example, OBEX *             If not specified, and using IR connections, the default is 'OBEX'. * */// **MHB** Investigate using ObxList instead of ObxSequenceNodeRet_t XPTAPI obxSelectProtocol( void *privateTransportInfo,                                const char *metaInformation,                                unsigned int flags,                                void **pPrivateServiceInfo ) {   ObxServiceBlock *service;   const char      *metaValue;   char            *ckstr;   unsigned long   result;   size_t          metaLen;   ObxRc rc;   char *s = NULL;   XPTDEBUG(("OBX obxSelectProtocol()\n"));   CHECK_PARM( privateTransportInfo, "obxSelectProtocol()", "privateTransport Info" );   CHECK_PARM( metaInformation,      "obxSelectProtocol()", "metaInformation" );   service = (ObxServiceBlock *)ALLOC_MEM( sizeof( ObxServiceBlock ) );   CHECK_ALLOC( service, "obxSelectProtocol()", "service" );   *pPrivateServiceInfo = (void *)service;   service->serviceName = NULL;   service->connections = NULL;   service->metadata    = NULL;   service->obxHandle   = NULL;   service->flags       = flags;   service->transport   = (ObxTransportBlock *)privateTransportInfo;   metaLen = strlen( metaInformation );   s = (char *)ALLOC_MEM( metaLen + 1 );   if( !s ) {      obxRecordError( OBX_ERRORMSG_MEMORY_ALLOC, "obxSelectProtocol()", "s" );      obxFreeService( service );      return OBX_RC_MEMORY_ERROR_ALLOC;   } // end if   strncpy( s, metaInformation, metaLen );   *( s + metaLen ) = '\0';   service->metadata = s;    // Keep for subsequent call to ObxTransportInitialize()   if ( service->transport->obxTransType == OBEX_TRANS_IRDA ) {      metaValue = xptGetMetaInfoValue( metaInformation, "SERVICE", &metaLen );      if ( !metaValue || metaLen == 0 ) {         s = (char *)ALLOC_MEM( 5 );   // strlen('OBEX') + 1         if( !s ) {            obxRecordError( OBX_ERRORMSG_MEMORY_ALLOC, "obxSelectProtocol()","s" );            obxFreeService( service );            return OBX_RC_MEMORY_ERROR_ALLOC;         }         strcpy( s, "OBEX" );      } else {         s = (char *)ALLOC_MEM( metaLen+1 );         if( !s ) {            obxRecordError( OBX_ERRORMSG_MEMORY_ALLOC, "obxSelectProtocol()","s" );            obxFreeService( service );            return OBX_RC_MEMORY_ERROR_ALLOC;         }         strncpy( s, metaValue, metaLen );         *(s+metaLen) = '\0';         }   } else if ( service->transport->obxTransType == OBEX_TRANS_INET ) {      // HOST      metaValue = xptGetMetaInfoValue( metaInformation, "HOST", &metaLen );      if ( metaValue ) {         s = (char *)ALLOC_MEM( metaLen+1 );         if( !s ) {            obxRecordError( OBX_ERRORMSG_MEMORY_ALLOC, "obxSelectProtocol()","s" );            obxFreeService( service );            return OBX_RC_MEMORY_ERROR_ALLOC;         }         strncpy( s, metaValue, metaLen );         *(s+metaLen) = '\0';      } else {         s = (char *)ALLOC_MEM( 10 );  // strlen('localhost') + 1         if( !s ) {            obxRecordError( OBX_ERRORMSG_MEMORY_ALLOC, "obxSelectProtocol()","s" );            obxFreeService( service );            return OBX_RC_MEMORY_ERROR_ALLOC;         }         strcpy( s, "localhost" );      }      // PORT      metaValue = xptGetMetaInfoValue( metaInformation, "PORT", &metaLen );      if ( metaValue ) {         result = strtoul( metaValue, &ckstr, 10 );         // %%% luz:2002-05-28, corrected such that ok if strtoul reads entire value         //     but does not need to end with NUL!         if ( ckstr!=metaValue+metaLen || result > USHRT_MAX ) {         // %%% original: if ( ckstr==metaValue || *ckstr || result > USHRT_MAX ) {            service->port = OBEX_PORT;         } else {            service->port = (unsigned short)result;         }      } else {         service->port = OBEX_PORT;      }   } else {      obxRecordError( OBX_ERRORMSG_UNKNOWN_TRANSPORT_TYP );      return OBX_RC_OBEX_INIT_FAILURE;   }   service->serviceName = s;   // If Server, initialize transport.  Server will then be 'listening' for incoming connections.   if ( ( service->flags & XPT_SERVER ) == XPT_SERVER ) {      // Create OBEX Handle      service->obxHandle = ObxHandleNew();      if ( service->obxHandle == NULL ) {         obxRecordError( OBX_ERRORMSG_OBEX_TRANSPORT_FAILURE, "OBEX Init" );         return OBX_RC_OBEX_INIT_FAILURE;      } // end if      switch ( service->transport->obxTransType ) {         case OBEX_TRANS_INET:            rc = ObxTransportRegister( service->obxHandle, ObxTransportGet( DEFINED_TRANSPORT_INET ) );            if ( rc != OBX_RC_OK ) {               return OBX_RC_OBEX_INIT_FAILURE;            } // end if            break;         case OBEX_TRANS_IRDA:            rc = ObxTransportRegister( service->obxHandle, ObxTransportGet( DEFINED_TRANSPORT_IRDA ) );            if ( rc != OBX_RC_OK ) {               return OBX_RC_OBEX_INIT_FAILURE;            } // end if            break;         default:            return OBX_RC_OBEX_INIT_FAILURE;      } // end switch      if ( ObxTransportInitialize( service->obxHandle, service->metadata ) != OBX_RC_OK ) {         return OBX_RC_OBEX_INIT_FAILURE;      } // end if      if ( ObxTransportOpen( service->obxHandle ) != OBX_RC_OK ) {         return OBX_RC_OBEX_INIT_FAILURE;      } // end if      if ( ObxTransportListen( service->obxHandle ) != OBX_RC_OK ) {         return OBX_RC_OBEX_INIT_FAILURE;      } // end if   } // end if    return OBX_RC_OK;}/** * FUNCTION: Called when xptDeselectProtocol() is called, deselecting this *           transport binding. * *  Stop a communication service instance. * * IN: privateServiceInfo, pointer to the transport binding's private *         information about the service instance.  This is the same value *         that was returned by the "selectProtocol" function when the *         service instance was created. */// **MHB** Close and DeRegister underlying OBEX protocol as well?Ret_t XPTAPI obxDeselectProtocol( void *privateServiceInfo ) {   ObxServiceBlock *service = (ObxServiceBlock *)privateServiceInfo;   XPTDEBUG(("OBX obxDeselectProtocol()\n"));   CHECK_PARM( service, "obxDeselectProtocol()", "service" );   if ( ( service->flags & XPT_SERVER ) == XPT_SERVER ) {      if ( ObxTransportClose( service->obxHandle ) != OBX_RC_OK ) {         return OBX_RC_GENERAL_ERROR;      } // end if      if ( ObxTransportTerminate( service->obxHandle ) != OBX_RC_OK ) {         return OBX_RC_GENERAL_ERROR;      } // end if   } // end if   obxFreeService( service );    // Ignore rc   return OBX_RC_OK;}

⌨️ 快捷键说明

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