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

📄 transact.c

📁 SyncML ToolKits,学习syncml的参考工具包.非常好用.
💻 C
📖 第 1 页 / 共 3 页
字号:
   if (aRc == AWSP_RC_BUFFER_TOO_SMALL) {      if (transaction->rspHdrSize != 0) {         transaction->rspHdr = (char *)xppMalloc(1 + transaction->rspHdrSize);         if (transaction->rspHdr == NULL)            transaction->rspHdrSize = 0;         else            xppMemset(transaction->rspHdr, 0, 1 + transaction->rspHdrSize);      }      if (transaction->rspBodySize != 0) {         transaction->rspBody = (void *) xppMalloc(transaction->rspBodySize);         if (transaction->rspBody == NULL)            transaction->rspBodySize = 0;         else            xppMemset(transaction->rspBody, 0, transaction->rspBodySize);      }      aRc = awsp_get_methodResult_ind(sessionHandle,                                      transaction->id,                                      &(transaction->status),                                      transaction->rspHdr,                                      &(transaction->rspHdrSize),                                      transaction->rspBody,                                      &(transaction->rspBodySize));   } /* End buffer too small */   if (aRc != AWSP_RC_OK) {      setLastError(aRc, "WSP Binding awsp method result indicator failed.");      rc = SML_ERR_A_XPT_COMMUNICATION;   }   /* Create a new document info object and update it with the post results */   createDocumentInfo(transaction);   updateDocInfoFromResponse(transaction, transaction->pDoc);   return rc;} /* End getMethodResponse() *//** *  transSendRequestNoSession *       - Does a connectionless abstract WSP methodInvoke *       - waits for method result * *  IN:    connHandle      A pointer to a connection handle *         transaction     A pointer to a transaction structure which *                         contains the method request parameters. * *  OUT:   transaction     The transaction structure has been updated to *                         contain the method response information. * *  RETURN: *       An indication of whether the method invocation was successful **/unsigned int transSendRequestNoSession(awsp_ConnectionHandle connHandle,                                       WspTransaction_t     *transaction){   unsigned int rc          = SML_ERR_OK;   awsp_Rc_t   aRc         = AWSP_RC_OK;   XPTDEBUG(("      transSendRequestNoSession(%lx, %lx)...\n",             (unsigned long) connHandle, (unsigned long) transaction));   if ((connHandle == NULL) || (transaction == NULL))      return SML_ERR_A_XPT_INVALID_PARM;   /* Send WSP request and wait for response                                   */   aRc = awsp_unit_methodInvoke_req(connHandle,                                    transaction->id,                                    transaction->method,                                    transaction->uri,                                    transaction->reqHdr,                                    transaction->reqHdrSize,                                    transaction->reqBody,                                    transaction->reqBodySize);   if (aRc != AWSP_RC_OK) {      setLastError(aRc, "WSP Binding awsp method invoke request failed.");      rc = SML_ERR_A_XPT_COMMUNICATION;   } else      rc = getUnitMethodResponse(connHandle, transaction);   return rc;} /* End transSendRequestNoSession() */unsigned int getUnitMethodResponse(awsp_ConnectionHandle connHandle,                                   WspTransaction_t     *transaction){   unsigned int rc          = SML_ERR_OK;   awsp_Rc_t   aRc         = AWSP_RC_OK;   XPTDEBUG(("        getUnitMethodResponse(%lx, %lx)\n",             (unsigned long) connHandle, (unsigned long) transaction));   if ((connHandle == NULL) || (transaction == NULL))      return SML_ERR_A_XPT_INVALID_PARM;   aRc = awsp_get_unit_methodResult_ind(connHandle,                                        transaction->id,                                        &(transaction->status),                                        NULL,                                        &(transaction->rspHdrSize),                                        NULL,                                        &(transaction->rspBodySize));   if (aRc == AWSP_RC_BUFFER_TOO_SMALL) {      if (transaction->rspHdrSize != 0)         transaction->rspHdr = (char *)xppMalloc(transaction->rspHdrSize);         if (transaction->rspHdr == NULL)            transaction->rspHdrSize = 0;         else            xppMemset(transaction->rspHdr, 0, 1 + transaction->rspHdrSize);      if (transaction->rspBodySize != 0)         transaction->rspBody = (void *) xppMalloc(transaction->rspBodySize);         if (transaction->rspBody == NULL)            transaction->rspBodySize = 0;         else            xppMemset(transaction->rspBody, 0, 1 + transaction->rspBodySize);      aRc = awsp_get_unit_methodResult_ind(connHandle,                                           transaction->id,                                           &(transaction->status),                                           transaction->rspHdr,                                           &(transaction->rspHdrSize),                                           transaction->rspBody,                                           &(transaction->rspBodySize));   } /* End buffer too small */   if (aRc != AWSP_RC_OK) {      setLastError(aRc, "WSP Binding awsp unit method result indication failed.");      rc = SML_ERR_A_XPT_COMMUNICATION;   }   /* Create a new document info object and update it with the post results */   createDocumentInfo(transaction);   updateDocInfoFromResponse(transaction, transaction->pDoc);   return rc;} /* End getUnitMethodResponse() *//** *  transCreateRequest *       - Builds the http request uri and headers. * *  IN     transaction     A pointer to a transaction structure *         host            The host name of the sync server to which the *                         request is directed. *         pDoc            A pointer to a structure that contains information *                         about the data to be transmitted. * *  OUT    transaction     The transaction structure has been updated to *                         contain the request info. * *  RETURN: *       An indication of whether the URI was successfully composed. **/unsigned int transCreateRequest(WspTransaction_t *transaction,                                WspHttpParms_t   *httpParms,                                char *host,                                awsp_BOOL sessionMode){   unsigned int rc = SML_ERR_OK;   XPTDEBUG(("      transCreateRequest(%lx, %s, %i)...\n",             (unsigned long) transaction, host, (int) sessionMode));   if ((transaction == NULL) || (host == NULL))      return SML_ERR_A_XPT_INVALID_PARM;   rc = composeRequestUri(transaction,                          host);   if (rc == SML_ERR_OK)      rc = composeHttpHeader(transaction, httpParms, sessionMode);   return rc;} /* End of transCreateRequest() *//** *  composeRequestUri *       - Builds uri from input host and document name * *  IN     transaction     A pointer to the wsp transaction structure *         host            The ip address or dns name of the host * *  OUT    transaction     The transaction structure has been updated to *                         contain the URI. * *  RETURN: *       An indication of whether the URI was successfully composed. **/unsigned int composeRequestUri(WspTransaction_t *transaction,                            const char *host){   const char *HTTP     = "http://";   const char *BKBK     = "//";   int         uriSize  = 0;   XPTDEBUG(("        composeRequestUri(%lx, %s)\n", (unsigned long) transaction, host));   if ((transaction == NULL) || (host == NULL))      return SML_ERR_A_XPT_INVALID_PARM;   uriSize  = xppStrlen(HTTP) + xppStrlen(host) + xppStrlen(BKBK) + 1;   /* Allocate and initialize storage                                          */   transaction->uri = (char *) xppMalloc(uriSize);   if (transaction->uri == NULL)      return SML_ERR_A_XPT_MEMORY;   xppMemset(transaction->uri, 0 , uriSize);   /* Build uri                                                                */   xppStrcat(transaction->uri, HTTP);   xppStrcat(transaction->uri, host);   xppStrcat(transaction->uri, BKBK);   return SML_ERR_OK;} /* End composeRequestUri *//** *  composeHttpHeader *       - Builds http request header * *  IN     transaction     A pointer to the wsp transaction structure *         sessionMode     An indication of whether the request is *                         going across an established session or whether *                         it is connectionless.  AWSP_TRUE means session. * *  OUT    transaction     The transaction structure has been updated to *                         contain the request header. * *  RETURN: *       An indication of whether the request header was successfully composed. * * Notes: * * Required Headers: *   General:           Cache-Control: no store *                      Cache-Control: private *   Request:           Accept: application/vnd.syncml-xml, application/vnd.syncml-wbxml *                      Accept-Charset: UTF-8 *                      User-Agent: HTTP Client [en] (WinNT; I) *                      From: *                      Authorization: **/unsigned int composeHttpHeader(WspTransaction_t *transaction, WspHttpParms_t *httpParms,                               awsp_BOOL sessionMode){   const char *tmpS = NULL;   /* temp for static request hdrs */   size_t      lenS = 0;   XPTDEBUG(("        composeHttpHeader(%lx, %lx, %i)\n",             (unsigned long) transaction, (unsigned long) httpParms, (int) sessionMode));   if (transaction == NULL)      return SML_ERR_A_XPT_INVALID_PARM;   transaction->reqHdr = NULL;   transaction->reqHdrSize = 0;   /*    * If not in session mode, request header must include 'static' headers    * that session would have established    */   if (sessionMode == AWSP_FALSE) {      tmpS = httpGetStaticRequestHdrs(httpParms);      lenS = xppStrlen(tmpS);      if ((tmpS != NULL) && (lenS > 0)) {         transaction->reqHdr = (char *) xppMalloc(lenS + 1);         transaction->reqHdrSize = lenS;         if (transaction->reqHdr != NULL)            xppStrcpy(transaction->reqHdr, tmpS);      } /* End got static hdrs */   } /* End not session mode */   return SML_ERR_OK;} /* End composeHttpHeader */unsigned int transBuildDynamicRequestHdr(WspTransaction_t *transaction,                                         WspHttpParms_t *httpParms){   char       *tmp  = NULL;   /* temp for xppRealloc */   const char *tmpR = NULL;   /* temp for dynamic request hdrs */   size_t      lenR = 0;   size_t      lenS = 0;   char        cLen[32];   XPTDEBUG(("        transBuildDynamicRequestHdr(%lx, %lx)\n",            (unsigned long) transaction, (unsigned long) httpParms));   if (transaction == NULL)      return SML_ERR_A_XPT_INVALID_PARM;   if (transaction->pDoc != NULL) {      xppMemset(cLen, 0, sizeof cLen);      sprintf(cLen, "%lu", (unsigned long) transaction->pDoc->cbLength);      tmpR = httpGetRequestHdrs(httpParms, transaction->pDoc->mimeType, cLen);      lenR = xppStrlen(tmpR);   } else {      tmpR = httpGetRequestHdrs(httpParms, NULL, NULL);      lenR = xppStrlen(tmpR);   }   if ((tmpR != NULL) && (lenR > 0)) {      if (transaction->reqHdr == NULL) {         transaction->reqHdr = (char *) xppMalloc(lenR + 1);         if (transaction->reqHdr != NULL)            xppStrcpy(transaction->reqHdr, tmpR);         transaction->reqHdrSize = lenR;      } else {         /* Need to append dynamic to static.  Remember to remove last '\n' from static */         lenS = xppStrlen(transaction->reqHdr);         tmp = (char *) xppRealloc(transaction->reqHdr, lenS + lenR);         if (tmp != NULL) {            transaction->reqHdr = tmp;            tmp = tmp + lenS - 1;      /* Bump pointer to last '\n' in static */            xppStrcpy(tmp, tmpR);         /* Copy dynamic into buffer */         }      } /* End append dynamic to static */   } /* End dynamic headers */   return SML_ERR_OK;} /* End transBuildDynamicRequestHdr() */unsigned int transAddRequestData(WspTransaction_t *transaction,                              const void *pbData,                              size_t uDataSize){   unsigned int rc = SML_ERR_OK;   void *temp = NULL;   XPTDEBUG(("      transAddRequestData(%lx, %lx, %lu)...\n",            (unsigned long) transaction, (unsigned long) pbData, (unsigned long) uDataSize));   if (transaction == NULL)      return SML_ERR_A_XPT_INVALID_PARM;   if (pbData == NULL)

⌨️ 快捷键说明

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