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

📄 transact.c

📁 SyncML手册及其编程
💻 C
📖 第 1 页 / 共 3 页
字号:
      return rc;   if (transaction->reqBody == NULL) {          /* First block of data         */      transaction->reqBody = (void *) xppMalloc(uDataSize);      if (transaction->reqBody == NULL)         return SML_ERR_A_XPT_MEMORY;           /* Failed to allocate storage  */      /* Copy data to request buffer                                           */      xppMemcpy(transaction->reqBody, pbData, uDataSize);      transaction->reqBodySize = uDataSize;   } else {                                     /* Accumulating data           */      temp = (void *) xppRealloc(transaction->reqBody,                              (transaction->reqBodySize) + uDataSize);      if (temp != NULL) {         transaction->reqBody = temp;         xppMemcpy(((transaction->reqBodySize) + (char *)(transaction->reqBody)), pbData, uDataSize);         transaction->reqBodySize = transaction->reqBodySize + uDataSize;      } else {                                  /* Failed to allocate storage  */         /**          *What do I do if i can't allocate more storage?  I haven't sent          * anything yet !!!          **/         rc = SML_ERR_A_XPT_COMMUNICATION;      } /* End failed xppReallocation */   } /* End of accumulating data */   return rc;} /* End of transAddRequestData() *//** *  updateDocInfoFromResponse *       - Copies response data from HTTP response header into the *         communicaton info structure. * *  IN     transaction     A pointer to a transaction structure that *                         contains the completed transaction. *         pDoc            A pointer to a structure into which the *                         response data will be copied * *  OUT    pDoc            The structure has been updated with response *                         information. * **/unsigned int updateDocInfoFromResponse(WspTransaction_t *transaction,                                    XptCommunicationInfo_t *pDoc){   unsigned int rc = SML_ERR_OK;   const char *docName       = NULL;   char       *tmp           = NULL;   XPTDEBUG(("        updateDocInfoFromResponse(%lx, %lx)...\n",             (unsigned long) transaction, (unsigned long) pDoc));   if ((transaction == NULL) || (pDoc == NULL))      return SML_ERR_A_XPT_INVALID_PARM;   tmp = getHeaderTag("Content-Length", transaction->rspHdr);   if (tmp != NULL)      pDoc->cbLength = (size_t) atoi(tmp);   xppFree(tmp);   tmp = getHeaderTag("Content-Type", transaction->rspHdr);   if (tmp != NULL){      if (xppStrlen(tmp) > XPT_DOC_TYPE_SIZE)         xppStrncpy(pDoc->mimeType, tmp, XPT_DOC_TYPE_SIZE);      else         xppStrcpy(pDoc->mimeType, tmp);   }   xppFree(tmp);   docName = "unknown";   if (docName != NULL)      xppStrncpy(pDoc->docName, docName, xppStrlen(docName));   return rc;} /* End of updateDocInfoFromResponse() *//** *  adjustResponseData *       - Removes read data from the response body cache. * *  IN     transaction     A pointer to the transaction structure containing *                         the response body. *         size            The number of bytes of data that need to be *                         removed from the response body. * *  OUT    transaction     The response body of the transaction contains *                         only unread data. **/void adjustResponseBody(WspTransaction_t *transaction, size_t size){   XPTDEBUG(("        adjustResponseBody(%lx, %lu)\n",             (unsigned long) transaction, (unsigned long) size));   if ((transaction == NULL) || (transaction->rspBody == NULL) || (size <= 0))      return;   if (size >= transaction->rspBodySize) {   /* All data was read    */      xppFree(transaction->rspBody);      transaction->rspBody = NULL;      transaction->rspBodySize = 0;   } else {      transaction->rspBodySize = transaction->rspBodySize - size;      xppMemmove(transaction->rspBody, (char *)(transaction->rspBody)+size, transaction->rspBodySize);      /* If xppRealloc fails we're ok - our 'unread' data is at beginning of original       * buffer and our size has been corrected.                               */      xppRealloc(transaction->rspBody, transaction->rspBodySize);   } /* End reduce response body */} /* End adjustResponseBody() */unsigned int transSetDocInfo(WspTransaction_t *transaction,                          const XptCommunicationInfo_t *pDoc){   unsigned int rc = SML_ERR_OK;   XPTDEBUG(("      transSetDocInfo(%lx, %lx)...\n",             (unsigned long) transaction, (unsigned long) pDoc));   if ((transaction == NULL) || (pDoc == NULL))      return SML_ERR_A_XPT_INVALID_PARM;   rc = createDocumentInfo(transaction);   if (rc != SML_ERR_OK)      return rc;   rc = copyDocumentInfo(transaction->pDoc, pDoc);   rc = updateRequestUriWithDocName(transaction);   if (rc != SML_ERR_OK)      releaseDocumentInfo(transaction);   return rc;} /* End of transSetDocInfo() *//*         docName         The path/name of the document on the host server. */unsigned int updateRequestUriWithDocName(WspTransaction_t *transaction){   int   docNameSize = 0;   int   uriOldSize  = 0;   char *temp        = NULL;   XPTDEBUG(("        updateRequestUriWithDocName(%lx)\n", (unsigned long) transaction));   if ((transaction == NULL) || (transaction->pDoc == NULL))      return SML_ERR_A_XPT_INVALID_PARM;   if (transaction->uri == NULL)      return SML_ERR_A_XPT_COMMUNICATION;   if (transaction->pDoc->docName != NULL) {      /*       * Need to handle case where docname begins with '/', so that we       * don't get '//' between uri and docname.       */      uriOldSize = xppStrlen(transaction->uri);      docNameSize = xppStrlen(transaction->pDoc->docName);      temp = (char *) xppRealloc(transaction->uri, uriOldSize + docNameSize + 1);      if (temp == NULL)         return SML_ERR_A_XPT_MEMORY;      xppStrncat(temp + uriOldSize, transaction->pDoc->docName, docNameSize);      transaction->uri = temp;   } /* End docName */   return SML_ERR_OK;} /* End of updateRequestUriWithDocName() */unsigned int transGetDocInfo(WspTransaction_t *transaction,                          XptCommunicationInfo_t *pDoc){   unsigned int rc = SML_ERR_OK;   XPTDEBUG(("      transGetDocInfo(%lx, %lx)...\n",             (unsigned long) transaction, (unsigned long) pDoc));   if ((transaction == NULL) || (pDoc == NULL))      return SML_ERR_A_XPT_INVALID_PARM;   rc = copyDocumentInfo(pDoc, transaction->pDoc);   if (transaction->status != AWSP_SUCCESS) { /* If not HTTP response code 200 */      reportHttpError(transaction);      rc = SML_ERR_A_XPT_COMMUNICATION;   }   return rc;} /* End of transGetDocInfo() */unsigned int createDocumentInfo(WspTransaction_t *transaction){   unsigned int rc = SML_ERR_OK;   XPTDEBUG(("        createDocumentInfo(%lx)\n", (unsigned long) transaction));   if (transaction == NULL)      return SML_ERR_A_XPT_INVALID_PARM;   if (transaction->pDoc != NULL)      releaseDocumentInfo(transaction);   transaction->pDoc = (XptCommunicationInfo_t *) xppMalloc(sizeof(XptCommunicationInfo_t));   if (transaction->pDoc == NULL)      return SML_ERR_A_XPT_MEMORY;   xppMemset(transaction->pDoc, 0, sizeof(XptCommunicationInfo_t));   return rc;} /* End of createDocumentInfo() */unsigned int copyDocumentInfo(XptCommunicationInfo_t *dest,                           const XptCommunicationInfo_t *source){   unsigned int rc = SML_ERR_OK;   XPTDEBUG(("        copyDocumentInfo(%lx, %lx)\n",             (unsigned long) dest, (unsigned long) source));   if ((dest == NULL) || (source == NULL))      return SML_ERR_A_XPT_INVALID_PARM;   dest->cbSize = source->cbSize;   dest->cbLength = source->cbLength;   xppStrcpy(dest->mimeType, source->mimeType);   xppStrcpy(dest->docName, source->docName);   return rc;} /* End of copyDocumentInfo() */void releaseDocumentInfo(WspTransaction_t *transaction){   XPTDEBUG(("        releaseDocumentInfo(%lx)\n", (unsigned long) transaction));   if (transaction == NULL) return;   xppFree(transaction->pDoc);   transaction->pDoc = NULL;} /* End of releaseDocumentInfo() */void reportHttpError(WspTransaction_t *transaction){   const char *msg = "HTTP 1.1 response is not 'OK' (200)";   XPTDEBUG(("        reportHttpError(%lx)...\n", (unsigned long) transaction));   if (transaction->status ==  AWSP_CONTINUE)      msg = "HTTP 1.1 response code 100 - 'Continue'";   else if (transaction->status ==  AWSP_SWITCH_PROTOCOL)      msg = "HTTP 1.1 response code 101 - 'Switch Protocol'";   else if (transaction->status ==  AWSP_CREATED)      msg = "HTTP 1.1 response code 201 - 'Created'";   else if (transaction->status ==  AWSP_ACCEPTED)      msg = "HTTP 1.1 response code 202 - 'Accepted'";   else if (transaction->status ==  AWSP_NON_AUTHORITATIVE_ANSWER)      msg = "HTTP 1.1 response code 203 - 'Non-authoritative Answer'";   else if (transaction->status ==  AWSP_NO_CONTENT)      msg = "HTTP 1.1 response code 204 - 'No Content'";   else if (transaction->status ==  AWSP_RESET_CONTENT)      msg = "HTTP 1.1 response code 205 - 'Reset Content'";   else if (transaction->status ==  AWSP_PARTIAL_CONTENT)      msg = "HTTP 1.1 response code 206 - 'Partial Content'";   else if (transaction->status ==  AWSP_MULTIPLE_CHOICES)      msg = "HTTP 1.1 response code 300 - 'Multiple Choices'";   else if (transaction->status ==  AWSP_MOVED_PERMANENTLY)      msg = "HTTP 1.1 response code 301 - 'Moved Permanently'";   else if (transaction->status ==  AWSP_MOVED_TEMPORARILY)      msg = "HTTP 1.1 response code 302 - 'Moved Temporarily'";   else if (transaction->status ==  AWSP_SEE_OTHER)      msg = "HTTP 1.1 response code 303 - 'See Other'";   else if (transaction->status ==  AWSP_NOT_MODIFIED)      msg = "HTTP 1.1 response code 304 - 'Not Modified'";   else if (transaction->status ==  AWSP_USE_PROXY)      msg = "HTTP 1.1 response code 305 - 'Use Proxy'";   else if (transaction->status ==  AWSP_BAD_REQUEST)      msg = "HTTP 1.1 response code 400 - 'Bad Request'";   else if (transaction->status ==  AWSP_UNAUTHORIZED)      msg = "HTTP 1.1 response code 401 - 'Unauthorized'";   else if (transaction->status ==  AWSP_PAYMENT_REQUIRED)      msg = "HTTP 1.1 response code 402 - 'Payment Required'";   else if (transaction->status ==  AWSP_FORBIDDEN)      msg = "HTTP 1.1 response code 403 - 'Forbidden'";   else if (transaction->status ==  AWSP_NOT_FOUND)      msg = "HTTP 1.1 response code 404 - 'Not Found'";   else if (transaction->status ==  AWSP_METHOD_NOT_ALLOWED)      msg = "HTTP 1.1 response code 405 - 'Method Not Allowed'";   else if (transaction->status ==  AWSP_NOT_ACCEPTABLE)      msg = "HTTP 1.1 response code 406 - 'Not Acceptable'";   else if (transaction->status ==  AWSP_PROXY_AUTH_REQUIRED)      msg = "HTTP 1.1 response code 407 - 'Proxy Authentication Required'";   else if (transaction->status ==  AWSP_REQUEST_TIMEOUT)      msg = "HTTP 1.1 response code 408 - 'Request Timed Out'";   else if (transaction->status ==  AWSP_CONFLICT)      msg = "HTTP 1.1 response code 409 - 'Conflict'";   else if (transaction->status ==  AWSP_GONE)      msg = "HTTP 1.1 response code 410 - 'Gone'";   else if (transaction->status ==  AWSP_LENGTH_REQUIRED)      msg = "HTTP 1.1 response code 411 - 'Length Required'";   else if (transaction->status ==  AWSP_PRECONDITION_FAILED)      msg = "HTTP 1.1 response code 412 - 'Precondition Failed'";   else if (transaction->status ==  AWSP_REQUEST_ENTITY_TOO_LARGE)      msg = "HTTP 1.1 response code 413 - 'Request Entity Too Large'";   else if (transaction->status ==  AWSP_REQUEST_URI_TOO_LARGE)      msg = "HTTP 1.1 response code 414 - 'Request URI Too Large'";   else if (transaction->status ==  AWSP_UNSUPPORTED_MEDIA_TYPE)      msg = "HTTP 1.1 response code 415 - 'Unsupported Media Type'";   else if (transaction->status ==  AWSP_INTERNAL_SERVER_ERROR)      msg = "HTTP 1.1 response code 500 - 'Internal Server Error'";   else if (transaction->status ==  AWSP_NOT_IMPLEMENTED)      msg = "HTTP 1.1 response code 501 - 'Not Implemented'";   else if (transaction->status ==  AWSP_BAD_GATEWAY)      msg = "HTTP 1.1 response code 502 - 'Bad Gateway'";   else if (transaction->status ==  AWSP_SERVICE_UNAVAILABLE)      msg = "HTTP 1.1 response code 503 - 'Service Unavailable'";   else if (transaction->status ==  AWSP_GATEWAY_TIMEOUT)      msg = "HTTP 1.1 response code 504 - 'Gateway Timeout'";   else if (transaction->status ==  AWSP_HTTP_VERSION_UNSUPPORTED)      msg = "HTTP 1.1 response code 505 - 'HTTP Version is unsupported'";   setLastError(transaction->status, msg);   XPTDEBUG(("        reportHttpError() returning...\n"));} /* End reportHttpError() */

⌨️ 快捷键说明

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