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

📄 obexbinding.c

📁 SyncML ToolKits,学习syncml的参考工具包.非常好用.
💻 C
📖 第 1 页 / 共 5 页
字号:
/** * FUNCTION: Called when xptOpenCommunication() is called, creating a *           connection instance. * *  Create a connection instance for the given service id. * * 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. * *     role, passed directly from the xptOpenCommunication() call. *          either XPT_REQUEST_RECEIVER or XPT_REQUEST_SENDER * * OUT: *pPrivateConnectionInfo, pointer to the transport binding's private *         information for the newly allocated connection instance.  This *         pointer will be passed on subsequent calls to the transport's *         functions to identify this connection instance to the transport. */// **MHB** Investigate using ObxList instead of ObxSequenceNodeRet_t XPTAPI obxOpenCommunication( void *privateServiceInfo,                                   int role,                                   void **pPrivateConnectionInfo ) {   ObxServiceBlock    *service    = (ObxServiceBlock *)privateServiceInfo;   ObxConnectionBlock *connection = NULL;   int rc = OBX_RC_OK;   XPTDEBUG(("OBX obxOpenCommunication()\n"));   CHECK_PARM( privateServiceInfo, "obxOpenCommunication()", "privateServiceInfo" );   connection = (ObxConnectionBlock *)ALLOC_MEM( sizeof( ObxConnectionBlock ));   CHECK_ALLOC( connection, "obxOpenCommunication()", "connection" );   connection->timeout        = OBX_DEFAULT_TIMEOUT;   connection->role           = role;   connection->docInfo        = NULL;   connection->pchXSyncmlHmac = NULL;   connection->dataToRead     = NULL;   connection->dataToSend     = NULL;   connection->obxHandle      = NULL;   connection->service        = service;   connection->connected      = OBEX_CONNECTED_NO;   if ( ( rc = obxAddConnection( service, connection ) ) == OBX_RC_OK ) {      *pPrivateConnectionInfo = (void *)connection;      if ( ( service->flags & XPT_SERVER ) == XPT_SERVER ) {  // Running as Server.         connection->obxHandle = service->obxHandle;      } // end if      else {                                                  // Running as Client.         rc = obxRegisterTransport( connection );      } // end else   } // end if   else {      obxFreeConnection( connection );      *pPrivateConnectionInfo = NULL;   } // end else/*We move this paragraph, which is to make an OBEX connection, from function obxBeginExchange to here because all SyncML message exchanging in the same SyncML session must take place just in one OBEX connection. This function, obxOpenCommunication, can only be called once right in the start of every SyncML session using OBEX protocol.*/    if(rc==OBX_RC_OK) {      switch ( connection->role ) {         case XPT_REQUEST_RECEIVER:            connection->currentRole = OBX_REQUEST_ROLE_RECEIVER;            XPTDEBUG(("OBX obxOpenCommunication() initializing as RECEIVER (== Server Mode)\n"));            rc = obxInitializeForServerMode( connection );  // accept()            break;         case XPT_REQUEST_SENDER:            connection->currentRole = OBX_REQUEST_ROLE_SENDER;            XPTDEBUG(("OBX obxOpenCommunication() initializing as SENDER (== Client Mode)\n"));            rc = obxInitializeForClientMode( connection );  // connect() to peer            break;         default:             XPTDEBUG(("OBX obxOpenCommunication() [ERROR] unknown role speciefied - bailing out\n"));             return OBX_RC_ERR_TRANSPORT;      }   }    return rc;}/** * FUNCTION: Called when xptCloseCommunication() is called, closing a *           connection instance. * *  Close a connection instance. * * IN: privateConnectionInfo, pointer to the transport binding's private *         information about the connection instance.  This is the same *         value that was returned by the "openCommunication" function when *         the connection instance was created. * *     disp, passed directly from the xptOpenCommunication() call. */Ret_t XPTAPI obxCloseCommunication( void *privateConnectionInfo ) {   ObxObject *response = NULL;   Ret_t rc;   ObxConnectionBlock *ocb = (ObxConnectionBlock *)privateConnectionInfo;   ObxIterator    *iterator;   ObxHeader      *header;   int connectionIDHeaderCount=0;   XPTDEBUG(("OBX obxCloseCommunication()\n"));   CHECK_PARM( ocb, "obxCloseCommunication()", "ocb" );/*We move this switch block that is to break up an OBEX connection, from function obxEndExchange to here because all SyncML message exchanging in the same SyncML session must take place just in one OBEX connection. This function, obxCloseCommunication, can only be called once right in the end of every SyncML session using OBEX protocol.*/    switch ( ocb->role ) {    case XPT_REQUEST_RECEIVER:        XPTDEBUG(("OBX obxCloseCommunication() waiting for DISCONNECT from client\n"));        //             response = ObxObjectNew( ocb->obxHandle, OBEX_CMD_NULL);            if ( response == NULL ) {                return OBX_RC_OBEX_HEADER;            }            rc = ObxTransactionRecv( ocb->obxHandle, response, TRUE );            if (rc != OBX_RC_OK) {                ObxObjectFree(ocb->obxHandle, response);                return rc;            }//Check if the header of ConnectionID carried by Disconnect command is legal.            /* ok we received the Disconnect - now lets ript the headers apart */            if ( !(iterator = ObxIteratorReset( ObxListGetIterator( ObxObjectGetHeaderList( response ) ) )) ) {                return OBX_RC_ERR_MEMORY;            }            while ( ObxIteratorHasNext( iterator ) ) {                if ( (header = (ObxHeader *)ObxIteratorNext( iterator )) ) {                /*                ** Which header is it ?                    */                    switch (header->identifier) {                    case OBEX_HEADER_CONNECTION://Check if ConnectionID in the request command is equal to the one we've assigned in the response of Connect command.                        XPTDEBUG(("OBX obxCloseCommunication() The ConnectionID carried in request command is %d and the one we assign is %d\n", header->value.fourBytevalue, ocb->obxHandle->OBEXConnectionID ));                        if(header->value.fourBytevalue!=ocb->obxHandle->OBEXConnectionID)                            return OBX_RC_ERR_SML_CONNECTIONID_HDR;                        connectionIDHeaderCount++;                        break;                    }                }            }            ObxIteratorFree( iterator );            if(connectionIDHeaderCount!=1)               return OBX_RC_ERR_SML_CONNECTIONID_HDR;                break;    case XPT_REQUEST_SENDER:        XPTDEBUG(("OBX obxCloseCommunication() sending DISCONNECT to server\n"));        if ((rc = obxSendObexDisconnect(ocb)) != OBX_RC_OK) {            return rc;        }        break;    default:        XPTDEBUG(("OBX obxCloseCommunication() [ERROR] unknown role specified - bailing out\n"));        return OBX_RC_ERR_TRANSPORT;    }   if ( ( ocb->service->flags & XPT_CLIENT ) == XPT_CLIENT ) {      if ( ObxTransportClose( ocb->obxHandle ) != OBX_RC_OK ) {         return OBX_RC_GENERAL_ERROR;      } // end if      if ( ObxTransportTerminate( ocb->obxHandle ) != OBX_RC_OK ) {         return OBX_RC_GENERAL_ERROR;      } // end if   } // end if   obxRemoveConnection( ocb );   obxFreeConnection( ocb );    return OBX_RC_OK;}/** * FUNCTION: Called when xptBeginExchange() is called * *  Prepare for a document exchange. * * IN: privateConnectionInfo, pointer to the transport binding's private *         information about the connection instance.  This is the same *         value that was returned by the "openCommunication" function when *         the connection instance was created. */Ret_t XPTAPI obxBeginExchange( void *privateConnectionInfo ) {//See obxOpenCommunication.   return OBX_RC_OK;/*   ObxConnectionBlock *ocb = (ObxConnectionBlock *)privateConnectionInfo;    ObxRc rc = OBX_RC_OK;   switch ( ocb->role ) {      case XPT_REQUEST_RECEIVER:         ocb->currentRole = OBX_REQUEST_ROLE_RECEIVER;         XPTDEBUG(("OBX obxBeginExchange() initializing as RECEIVER (== Server Mode)\n"));         rc = obxInitializeForServerMode( ocb );  // accept()         break;      case XPT_REQUEST_SENDER:         ocb->currentRole = OBX_REQUEST_ROLE_SENDER;         XPTDEBUG(("OBX obxBeginExchange() initializing as SENDER (== Client Mode)\n"));         rc = obxInitializeForClientMode( ocb );  // connect() to peer         break;      default:          XPTDEBUG(("OBX obxBeginExchange() [ERROR] unknown role speciefied - bailing out\n"));          return OBX_RC_ERR_TRANSPORT;   }   return rc;*/}/** * FUNCTION: Called when xptEndExchange() is called * *  Clean up after a document exchange. * * IN: privateConnectionInfo, pointer to the transport binding's private *         information about the connection instance.  This is the same *         value that was returned by the "openCommunication" function when *         the connection instance was created. */Ret_t XPTAPI obxEndExchange( void *privateConnectionInfo ) {        ObxConnectionBlock *ocb = (ObxConnectionBlock *)privateConnectionInfo;//See xptCloseCommunication./*    ObxObject *response = NULL;    Ret_t rc;   XPTDEBUG(("OBX obxEndExchange()\n"));   CHECK_PARM( ocb, "obxEndExchange()", "ocb" );    switch ( ocb->role ) {    case XPT_REQUEST_RECEIVER:        XPTDEBUG(("OBX obxEndExchange() waiting for DISCONNECT from client\n"));        //             response = ObxObjectNew( ocb->obxHandle, OBEX_CMD_NULL);            if ( response == NULL ) {                return OBX_RC_OBEX_HEADER;            }            rc = ObxTransactionRecv( ocb->obxHandle, response, TRUE );            if (rc != OBX_RC_OK) {                ObxObjectFree(ocb->obxHandle, response);                return rc;            }                break;    case XPT_REQUEST_SENDER:        XPTDEBUG(("OBX obxEndExchange() sending DISCONNECT to server\n"));        if ((rc = obxSendObexDisconnect(ocb)) != OBX_RC_OK) {            return rc;        }        break;    default:        XPTDEBUG(("OBX obxEndExchange() [ERROR] unknown role specified - bailing out\n"));        return OBX_RC_ERR_TRANSPORT;    }*/   // Clean up any existing information contained in the ObxConnectionBlock   obxResetConnection( ocb );    return OBX_RC_OK;}/** * FUNCTION: Called when xptGetDocumentInfo() is called * *  Retrieve the document information associated with an incoming document. * * IN: privateConnectionInfo, pointer to the transport binding's private *         information about the connection instance.  This is the same *         value that was returned by the "openCommunication" function when *         the connection instance was created. * *     pDoc, passed directly from the xptGetDocumentInfo() call. */Ret_t XPTAPI obxGetDocumentInfo( void *privateConnectionInfo,                                 XptCommunicationInfo_t *pDoc ) {   ObxConnectionBlock *ocb = (ObxConnectionBlock *)privateConnectionInfo;   Ret_t rc  = OBX_RC_OK;    int length = 0;        ObxObject *response = NULL;        ObxObject *request = NULL;    ObxIterator    *iterator;    ObxHeader      *header;    unsigned char  *someBuf, *buffer=NULL;    ObxBuffer      *inboundbuffer,*bufferx;    XptCommunicationInfo_t *docInfo = NULL;    unsigned char  *param, *value;    int bodyHeaderCount=0;

⌨️ 快捷键说明

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