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

📄 wsphttp.c

📁 SyncML ToolKits,学习syncml的参考工具包.非常好用.
💻 C
📖 第 1 页 / 共 3 页
字号:
/*************************************************************************//* module:          Communication Services, WSP HTTP Header Functions    *//* file:            src/xpt/all/wsphttp.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. *  *//* * Version Label * * RELEASE ??? CANDIDATE ? * 13.06.2000 */#include <wsphttp.h>#include <wsputil.h>#include <xpt.h>        /* For SML_ERRs */#include <xptport.h>/** * Eyecatcher to validate WspProtocolHandle_t structure **/#define WSP_HTTP_HANDLE_VALID_FLAG 0x48505357L    // 'WSPH'/*****************************************************************************//*****************************************************************************//**                                                                         **//**                         Private Implementation Methods                  **//**                                                                         **//*****************************************************************************//*****************************************************************************//** * HTTP Settings parameters: *    accept           = acceptable mime types, *                       default = "application/vnd.syncml-xml, application/vnd.syncml-wbxml" *    acceptCharset    = acceptable character sets, *                       default = "UTF8" *    acceptEncoding   = acceptable encodings *    acceptLanguage   = acceptable language *    emailAddress     = email address of user *    authUserid       = userid for basic/digest authentication *    authPassword     = password for basic authentication *    authRealm        = realm for basic/digest authentication **/unsigned int httpInitialize(const char *szSettings, WspHttpParms_t **parmPtr){   unsigned int rc = SML_ERR_OK;   WspHttpParms_t *httpParms = NULL;   XPTDEBUG(("    httpInitialize(%s, %lx)\n", szSettings, (unsigned long) parmPtr));   if (parmPtr == NULL)      return SML_ERR_A_XPT_INVALID_PARM;   if (*parmPtr != NULL) {      httpRelease(*parmPtr);      *parmPtr = NULL;   }   httpParms = (WspHttpParms_t *) xppMalloc(sizeof(WspHttpParms_t));   if (httpParms == NULL)      return SML_ERR_A_XPT_MEMORY;   xppMemset(httpParms, 0, sizeof(WspHttpParms_t));   httpParms->valid = WSP_HTTP_HANDLE_VALID_FLAG;   rc = initializeRequestParms(httpParms, szSettings);   if (rc != SML_ERR_OK) {      httpRelease(httpParms);      return rc;   }   *parmPtr = httpParms;   return rc;} /* End httpInitialize */void httpRelease(WspHttpParms_t *parmPtr){   XPTDEBUG(("    httpRelease(%lx)\n", (unsigned long) parmPtr));   if ((parmPtr == NULL) || (parmPtr->valid != WSP_HTTP_HANDLE_VALID_FLAG))      return;   releaseRequestParms(parmPtr->request);   releaseResponseParms(parmPtr->response);   parmPtr->request  = NULL;   parmPtr->response = NULL;   parmPtr->valid = 0;   xppFree(parmPtr);} /* End httpRelease *//* * Unfortunately there are 2 kinds of data maintained in this object - * 'static' data that is specified at the time the protocol is selected * (i.e. settings metadata) and dynamic data that gathers as transactions * are being processed.  When a transaction completes, the dynamic * data must be removed/reset.  That is the purpose of this method. */void httpReinitParms(WspHttpParms_t *parmPtr) {   XPTDEBUG(("    httpReinitParms(%lx)\n", (unsigned long) parmPtr));   if ((parmPtr == NULL) || (parmPtr->valid != WSP_HTTP_HANDLE_VALID_FLAG))      return;   if (parmPtr->request != NULL) {      xppFree(parmPtr->request->composedHeader);      parmPtr->request->composedHeader = NULL;      if (parmPtr->request->authorization != NULL) {         xppFree(parmPtr->request->authorization->realm);         parmPtr->request->authorization->realm = NULL;         xppFree(parmPtr->request->authorization->cnonce);         parmPtr->request->authorization->cnonce = NULL;         xppFree(parmPtr->request->authorization->opaque);         parmPtr->request->authorization->opaque = NULL;      } /* End have authorization parms */   } /* End have request parms */   releaseResponseParms(parmPtr->response);   parmPtr->response = NULL;   xppFree(parmPtr);} /* End httpReinitParms() *//* * Note: This shares a buffer with httpGetRequestHdrs, so the returned value *       can no longer be used once httpGetRequestHdrs is invoked. */const char *httpGetStaticRequestHdrs(WspHttpParms_t *parmPtr){   unsigned int hdrSize = 0;   XPTDEBUG(("    httpGetStaticRequestHdrs(%lx)\n", (unsigned long) parmPtr));   if ((parmPtr == NULL) || (parmPtr->request == NULL))      return NULL;   hdrSize = calcStaticHeaderSize(parmPtr->request);   if (parmPtr->request->composedHeader != NULL)      parmPtr->request->composedHeader = (char *) xppRealloc(parmPtr->request->composedHeader, hdrSize);   else      parmPtr->request->composedHeader = (char *) xppMalloc(hdrSize);   if (parmPtr->request->composedHeader == NULL)      return NULL;   xppMemset(parmPtr->request->composedHeader, 0, hdrSize);   addTag(parmPtr->request->composedHeader, "Cache-Control", D_CACHE_CONTROL);   addTag(parmPtr->request->composedHeader, "Accept", parmPtr->request->accept);   addTag(parmPtr->request->composedHeader, "Accept-Charset", parmPtr->request->acceptCharset);   addTag(parmPtr->request->composedHeader, "From", parmPtr->request->from);   addTag(parmPtr->request->composedHeader, "User-Agent", D_USER_AGENT);   addTag(parmPtr->request->composedHeader, "Accept-Encoding", parmPtr->request->acceptEncoding);   addTag(parmPtr->request->composedHeader, "Accept-Language", parmPtr->request->acceptLanguage);   addTag(parmPtr->request->composedHeader, "host", parmPtr->request->host);   xppStrcat(parmPtr->request->composedHeader, NL);   XPTDEBUG(("    httpGetStaticRequestHdrs() response = %s\n", parmPtr->request->composedHeader));   return parmPtr->request->composedHeader;} /* End httpGetStaticRequestHdrs *//* * Note: This shares a buffer with httpGetStaticRequestHdrs, so the returned value *       can no longer be used once httpGetStaticRequestHdrs is invoked. */const char *httpGetRequestHdrs(WspHttpParms_t *parmPtr, const char *contentType,                                  const char *contentLength){   int headerSize = 0;   char *date     = getRFC822Date();   XPTDEBUG(("    httpGetRequestHdrs(%lx, %s, %s)\n", (unsigned long) parmPtr,             contentType, contentLength));   if ((parmPtr == NULL) || (parmPtr->request == NULL))      return NULL;   headerSize += getTagLen("Content-Type", contentType);   headerSize += getTagLen("Content-Length", contentLength);   headerSize += getTagLen("Date", date);   headerSize += getTagLen("Referer: ", parmPtr->request->referer);   headerSize += xppStrlen(NL);   headerSize += 1;              /* For null terminator */   if (parmPtr->request->composedHeader != NULL)      parmPtr->request->composedHeader = (char *) xppRealloc(parmPtr->request->composedHeader, headerSize);   else      parmPtr->request->composedHeader = (char *) xppMalloc(headerSize);   if (parmPtr->request->composedHeader == NULL)      return NULL;   xppMemset(parmPtr->request->composedHeader, 0, headerSize);   addTag(parmPtr->request->composedHeader, "Content-Type", contentType);   addTag(parmPtr->request->composedHeader, "Content-Length", contentLength);   addTag(parmPtr->request->composedHeader, "Date", date);   addTag(parmPtr->request->composedHeader, "Referer", parmPtr->request->referer);   xppStrcat(parmPtr->request->composedHeader, NL);   XPTDEBUG(("    httpGetRequestHdrs() response = %s\n", parmPtr->request->composedHeader));   return parmPtr->request->composedHeader;} /* End httpGetRequestHdrs */char *getRFC822Date(void){   return "Fri, 14 Jul 2000 00:00:00 GMT";} /* End getRFC822Date() *//* * Note: If the update fails, the previous authentication information is lost. */unsigned int httpUpdateAuthorization(WspHttpParms_t *parmPtr, const char *userid,                                     const char *password, const char *realm){   unsigned int rc = SML_ERR_OK;   XPTDEBUG(("    httpUpdateAuthorization(%lx, %s, %s, %s)\n",              (unsigned long) parmPtr, userid, password, realm));   if (parmPtr == NULL)      return SML_ERR_A_XPT_INVALID_PARM;   if ((parmPtr->request == NULL) || (parmPtr->request->authorization == NULL))      return SML_ERR_A_XPT_COMMUNICATION;   rc = updateStringField(&(parmPtr->request->authorization->userid), userid);   if (rc == SML_ERR_OK) {      rc = updateStringField(&(parmPtr->request->authorization->password), password);      if (rc == SML_ERR_OK) {         rc = updateStringField(&(parmPtr->request->authorization->realm), realm);      } /* End successful password update */   } /* End successful userid update */   if (rc != SML_ERR_OK) {      xppFree(parmPtr->request->authorization->userid);      parmPtr->request->authorization->userid = NULL;      xppFree(parmPtr->request->authorization->password);      parmPtr->request->authorization->password = NULL;      xppFree(parmPtr->request->authorization->realm);      parmPtr->request->authorization->realm = NULL;   } /* End update(s) failed) */   return rc;} /* End httpSetAuthenticationInfo *//* * Note: If the set fails, the previous referer information is lost. */unsigned int httpSetReferer(WspHttpParms_t *parmPtr, const char *referer){   unsigned int rc = SML_ERR_OK;   XPTDEBUG(("    httpSetRefered(%lx, %s)\n", (unsigned long) parmPtr, referer));

⌨️ 快捷键说明

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