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

📄 obexbinding.c

📁 SyncML手册及其编程
💻 C
📖 第 1 页 / 共 5 页
字号:
                        break;//Mickey 2003.1.28//Both OBEX_HEADER_BODY and OBEX_HEADER_BODY_END can carry payload data.                    case OBEX_HEADER_BODY:                     case OBEX_HEADER_BODY_END:                        length = ObxBufSize(header->value.byteSequenceValue);//Mickey 2003.1.28//There may be no OBEX_HEADER_LENGTH header in Get command.                        docInfo->cbLength=length;                        buffer = (unsigned char *)malloc( length );                        ObxBufRead( header->value.byteSequenceValue, buffer, length );                        bodyHeaderCount++;                        break;                    default: break; /* ignore */                    }                }            }            ObxIteratorFree( iterator );            /* EOF - processing headers *///There must be data returned in the response of Get command.            if(bodyHeaderCount==0) {               ObxObjectFree(ocb->obxHandle, request);               ObxObjectFree(ocb->obxHandle, response);                               return OBX_RC_ERR_SML_BODY_HDR;            }//There must be Type header in Get command.//            if(typeHeaderCount!=1) {//               ObxObjectFree(ocb->obxHandle, request);//               ObxObjectFree(ocb->obxHandle, response);                //               return OBX_RC_ERR_SML_TYPE_HDR;//            }            ocb->docInfo = docInfo;                        ocb->dataToRead = (ObxBuf *)ALLOC_MEM( sizeof( ObxBuf ) );            if (!ocb->dataToRead) {                ObxObjectFree(ocb->obxHandle, request);                ObxObjectFree(ocb->obxHandle, response);                                return OBX_RC_ERR_MEMORY;            }            ocb->dataToRead->buf = (unsigned char *)ALLOC_MEM( ocb->docInfo->cbLength );            if (!ocb->dataToRead->buf) {                ObxObjectFree(ocb->obxHandle, request);                ObxObjectFree(ocb->obxHandle, response);                                return OBX_RC_ERR_MEMORY;            }            ocb->dataToRead->cursor = ocb->dataToRead->buf;            ocb->dataToRead->length = ocb->docInfo->cbLength;            COPY_MEM(buffer, ocb->dataToRead->buf,  ocb->docInfo->cbLength );            ObxObjectFree(ocb->obxHandle, request);            ObxObjectFree(ocb->obxHandle, response);        } else {            /* ERROR - this should not happen */            pDoc->cbLength = -1;            pDoc->cbSize   = -1;            strcpy(pDoc->docName, "");            strcpy(pDoc->mimeType, "");            if (ocb->pchXSyncmlHmac != NULL)                FREE_MEM(ocb->pchXSyncmlHmac);            return OBX_RC_ERR_NOTINITIALIZED;        }    }    strcpy( pDoc->docName,  ocb->docInfo->docName );    strcpy( pDoc->mimeType, ocb->docInfo->mimeType );    pDoc->hmacInfo = docInfo->hmacInfo;    pDoc->cbLength = ocb->docInfo->cbLength;    XPTDEBUG(("OBX obxGetDocumentInfo() name: '%s' mime: '%s' length: '%d'\n", pDoc->docName, pDoc->mimeType, pDoc->cbLength ));    return OBX_RC_OK;}/** * FUNCTION: Called when xptReceiveData() is called * *  Read data * * 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. * *     buffer, passed directly from the xptReceiveData() call. * *     bufferLen, passed directly from the xptReceiveData() call. * * OUT: *     dataLen, passed directly from the xptReceiveData() call. */Ret_t XPTAPI obxReceiveData(void *privateConnectionInfo,                            void *buffer,                            size_t bufferLen,                            size_t *dataLen) {   ObxConnectionBlock *ocb = (ObxConnectionBlock *)privateConnectionInfo;   int   length = 0;   XPTDEBUG(("OBX obxReceiveData()\n"));   CHECK_PARM( privateConnectionInfo, "obxReceiveData()", "privateConnectionInfo" );   CHECK_PARM( buffer,                "obxReceiveData()", "buffer" );   if ( ocb->dataToRead == NULL  ) {  // no data to read yet...      obxRecordError( OBX_ERRORMSG_BUFFER_LENGTH, bufferLen, "obxReceiveData()" );      return OBX_RC_OBEX_DATA_LENGTH;   } // end if   // Can we satisfy the read?   if ( bufferLen > ocb->dataToRead->length ) {      // Less data on hand, than they are requesting.      obxRecordError( OBX_ERRORMSG_BUFFER_LENGTH, bufferLen, "obxReceiveData()" );      return OBX_RC_OBEX_DATA_LENGTH;   } // end if   length   = ( bufferLen < ocb->dataToRead->length ) ? bufferLen : ocb->dataToRead->length;   *dataLen = length;   if ( length > 0 ) {      COPY_MEM( ocb->dataToRead->cursor, buffer, length );      ocb->dataToRead->length -= length;      ocb->dataToRead->cursor += length;   } // end if    return OBX_RC_OK;}/** * FUNCTION: Called when xptSetDocumentInfo() is called * *  Provide document information for an outgoing 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 xptSetDocumentInfo() call. * * Note: It is possible that the transport not known the document length *       beforehand.  In this case, the document length will be set to *       (size_t) -1 by the caller of xptSetDocumentInfo(). */Ret_t XPTAPI obxSetDocumentInfo( void *privateConnectionInfo,                                 const XptCommunicationInfo_t *pDoc ) {   ObxConnectionBlock     *ocb       = (ObxConnectionBlock *)privateConnectionInfo;   XptCommunicationInfo_t *docInfo   = NULL;   XptHmacInfo_t          *pHmacInfo = pDoc->hmacInfo;   XPTDEBUG(("OBX obxSetDocumentInfo()\n"));   CHECK_PARM( privateConnectionInfo, "obxSetDocumentInfo()", "privateConnectionInfo" );   CHECK_PARM( pDoc, "obxSetDocumentInfo()", "pDoc" );   docInfo = (XptCommunicationInfo_t *)ALLOC_MEM( sizeof( XptCommunicationInfo_t ) );   CHECK_ALLOC( docInfo, "obxSetDocumentInfo()", "docInfo" );   strcpy( docInfo->docName, pDoc->docName );   strcpy( docInfo->mimeType, pDoc->mimeType );//Mickey 2003.1.14   docInfo->cbSize = pDoc->cbSize;   docInfo->cbLength = pDoc->cbLength;   docInfo->hmacInfo = NULL;   ocb->docInfo = docInfo;   if (pHmacInfo != NULL)    {        char *copy  = NULL;        int  length = 0;        if ((pHmacInfo->username != NULL) && (pHmacInfo->mac != NULL))        {            length = strlen("algorithm=")                    + strlen( (pHmacInfo->algorithm == NULL) ? "MD5" : pHmacInfo->algorithm)                   + strlen(", username=\"") + strlen (pHmacInfo->username)                   + strlen("\", mac=") + strlen (pHmacInfo->mac);            copy = (char *)ALLOC_MEM( length + 1 );        }        if (copy) // we cannot use CHECK_ALLOC since we have to free docInfo before returning        {            sprintf(copy, "algorithm=%s, username=\"%s\", mac=%s",                 (pHmacInfo->algorithm == NULL) ? "MD5" : pHmacInfo->algorithm,                 pHmacInfo->username, pHmacInfo->mac);                        ocb->pchXSyncmlHmac = copy;           }        else        {            FREE_MEM(docInfo);            return OBX_RC_MEMORY_NULL_PNTR;        }        XPTDEBUG(("OBX obxSetDocumentInfo() hmac: '%s'\n", ocb->pchXSyncmlHmac ));   }   XPTDEBUG(("OBX obxSetDocumentInfo() name: '%s' mime: '%s' length: '%d'\n",             docInfo->docName, docInfo->mimeType, docInfo->cbLength));   return OBX_RC_OK;}/** * FUNCTION: Called when xptSendData() is called * *  Send data * * 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. * *     buffer, passed directly from the xptSendData() call. * *     bufferLen, passed directly from the xptSendData() call. * *     lastBlock, passed directly from the xptSendData() call. */Ret_t XPTAPI obxSendData(void *privateConnectionInfo,                         const void *dataBuffer,                         size_t bufferLen,                         size_t *bytesSent ) {   XPTDEBUG(("OBX obxSendData()\n"));   CHECK_PARM( privateConnectionInfo, "obxSendData()", "privateConnectionInfo" );   CHECK_PARM( bytesSent,             "obxSendData()", "bytesSent" );   CHECK_PARM( dataBuffer,            "obxSendData()", "dataBuffer" );   *bytesSent = bufferLen; // We always take all they can give.   return obxQueueBufferForSend( (ObxConnectionBlock *)privateConnectionInfo, dataBuffer, bufferLen );}/** * FUNCTION: Called when xptSendData() is called by the application, after *           sending the last byte of the document. * *  Complete send processing for an outgoing 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. * * NOTES: * *  The xpt interface layer counts the number of bytes the application *  writes using the xptSendData() function.  When the transport *  implementation has written the last byte of the document, the xpt *  interface layer calls this function in the transport implementation to *  allow it to perform any desired completion processing.  The length of *  the document is known because it was specified by the application in the *  xptSetDocumentInfo() call. * *  Any error returned from sendComplete() is returned to the application *  as the result value of the application's call to xptSendData(). * *  Note that this function call does NOT correspond to an xptSendComplete() *  function call available to the application.  Instead, it is called *  automatically by the xpt interface layer when the application has *  successfully written the last byte of the document. */Ret_t XPTAPI obxSendComplete( void *privateConnectionInfo ) {   ObxObject *object;   ObxHeader *header;   ObxBuffer *buffer;    ObxObject *response = NULL;    int   length = 0;   Ret_t rc = OBX_RC_OK;   ObxConnectionBlock *ocb = (ObxConnectionBlock *)privateConnectionInfo;   XPTDEBUG(("OBX obxSendComplete()\n"));   CHECK_PARM( privateConnectionInfo, "obxSendComplete()", "privateConnectionInfo" );    /* check wether we are server beeing pulled with get or client pushing data with PUT */    if (ocb->role == XPT_REQUEST_SENDER) {      object = ObxObjectNew( ocb->obxHandle, OBEX_CMD_PUT );    } else if (ocb->role == XPT_REQUEST_RECEIVER) {//Every response of Get command must have final bit set.//        object = ObxObjectNew( ocb->obxHandle, OBEX_RSP_CONTINUE );        object = ObxObjectNew( ocb->obxHandle, OBEX_RSP_CONTINUE | OBEX_CMD_FINAL );    } else {        /* error - bail out! */        return OBX_RC_ERR_NOTINITIALIZED;    }   if ( object == NULL ) {        return OBX_RC_OBEX_HEADER;    } // end if    //The following headers are needed only when OBEX client is make a PUT request.    if (ocb->role == XPT_REQUEST_SENDER) {//We must embed ConnectionID header in Put command.        header = ObxHeaderNew( OBEX_HEADER_CONNECTION );        rc = ( header == NULL ) ? OBX_RC_OBEX_HEADER : OBX_RC_OK;        if ( rc == OBX_RC_OK ) {            XPTDEBUG(("OBX obxSendComplete() Add header '%s' value '%x'\n", "OBEX_HEADER_CONNECTION", ocb->obxHandle->OBEXConnectionID ));            rc = ObxHeaderSetIntValue( header, ocb->obxHandle->OBEXConnectionID );            if ( rc == OBX_RC_OK ) {                rc = ObxObjectAddHeader( ocb->obxHandle, object, header );                if ( rc == OBX_RC_OK ) {                    header = NULL; // we no longer own the header                } // end if            } // end if        } // end if            // Clean up from an error        if ( rc != OBX_RC_OK ) {

⌨️ 快捷键说明

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