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

📄 xpt-auth.c

📁 SyncML ToolKits,学习syncml的参考工具包.非常好用.
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * 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. *  */#include "syncml_tk_prefix_file.h" // %%% luz: needed for precompiled headers in eVC++#include <xptport.h>#include "xpt-b64.h"#include "digcalc.h"#include "xpt-auth.h"typedef struct _HttpDigest   {   int  cbSize;                    // size of this structure   HttpAuthenticationType_t fType; // type of authorization, set by server   HttpAuthenticationDest_t fDest; // destination: server or proxy?   char achUser   [MAX_USER_SIZE];  // user name   char achPassword [MAX_PWD_SIZE]; // Password   char achDigest [MAX_DIGEST_SIZE];// digest value   char achRealm  [MAX_REALM_SIZE]; // server realm value, set by server   Bool_t bStale;                   // stale flag   char achCNonce [MAX_CNONCE_SIZE];// Client Nonce.   char achNonce [MAX_NONCE_SIZE];  // nonce value,   char achQOp   [MAX_QOP_SIZE];    // selected algorithm   char achNC    [MAX_NC_SIZE];     // incremented after each HTTP message.   char achOpaque [MAX_OPAQUE_SIZE];// opaque value, set by server   char achDomain [MAX_DOMAIN_SIZE];// domain Info   } HttpDigest_t, *HttpDigestPtr_t;/***********************//* Authentication Info *//***********************/typedef struct   {   int rfu;                     // not used.   int cbCount;                 // # of authentication structures   HttpDigestPtr_t digest [1];  // array of digest structures   } HttpAuthentication_t;HttpDigestPtr_t getDigest (HttpAuthenticationPtr_t handle,                           HttpAuthenticationDest_t dest)   {   HttpAuthentication_t *auth = (HttpAuthentication_t *) handle;   HttpDigestPtr_t dig = NULL;   if (auth)      {      int n;      for (n = 0; n < auth->cbCount; n ++)         {         if (auth->digest[n]->fDest == dest)            {            dig = auth->digest[n];            break;            }         }      }   return dig;   }HttpAuthenticationPtr_t authInit (void)   {   /************************/   /* Create objext stores */   /************************/   int cbAuthSize = sizeof (HttpAuthentication_t) + sizeof (HttpDigestPtr_t);   HttpAuthentication_t * auth = (HttpAuthentication_t*) xppMalloc (cbAuthSize);   if (auth == NULL) return NULL;   xppMemset (auth, 0, cbAuthSize);   /*******************************************/   /* Create two digest structures:           */   /* one to authenticate against the server, */   /* and one to authenticate against a proxy */   /*******************************************/   auth->cbCount = 2;   auth->digest [0] = (HttpDigestPtr_t) xppMalloc (sizeof (HttpDigest_t));   auth->digest [1] = (HttpDigestPtr_t) xppMalloc (sizeof (HttpDigest_t));   if ((auth->digest [0] == NULL) || (auth->digest [1] == NULL))      {      xppFree (auth);      return NULL;      }   xppMemset (auth->digest [0], 0, sizeof (HttpDigest_t));   xppMemset (auth->digest [1], 0, sizeof (HttpDigest_t));   auth->digest[0]->fDest = DEST_SERVER;   auth->digest[1]->fDest = DEST_PROXY;   auth->digest[0]->cbSize = sizeof (HttpDigest_t);   auth->digest[1]->cbSize = sizeof (HttpDigest_t);   return (HttpAuthenticationPtr_t) auth;   }void authTerminate (HttpAuthenticationPtr_t handle)   {   HttpAuthentication_t *auth = (HttpAuthentication_t *) handle;   int n;   if (auth != NULL)      {      for (n = 0; n < auth->cbCount; n ++)         {         if ((auth->digest[n] != NULL) &&             (auth->digest[n]->cbSize == sizeof (HttpAuthentication_t)))            {            auth->digest[n]->cbSize = 0;            xppFree (auth->digest[n]);            auth->digest[n] = NULL;            }         }      auth->cbCount = 0;      xppFree (auth);      }   return;   }Bool_t authSetDigest (HttpAuthenticationPtr_t auth,                      HttpAuthenticationDest_t dest,                      CString_t szDigest)   {   Bool_t rc = true;   HttpDigestPtr_t dig;   /**************************/   /* check entry conditions */   /**************************/   if ((dest != AUTH_NONE) && (auth != NULL) &&       (szDigest != NULL) &&       (xppStrlen (szDigest) < MAX_DIGEST_SIZE) &&       ((dig = getDigest (auth, dest)) != NULL) )      xppStrcpy (dig->achDigest, szDigest);   else      rc = false;   return rc;   }Bool_t authSetUserData (HttpAuthenticationPtr_t auth,                        HttpAuthenticationDest_t dest,                        HttpAuthenticationUserDataPtr_t pUserData)   {   Bool_t rc = true;   HttpDigestPtr_t dig;   /**************************/   /* check entry conditions */   /**************************/   if ((dest != AUTH_NONE) && (auth != NULL) &&       (pUserData != NULL) &&       (pUserData->cbSize == sizeof (HttpAuthenticationUserData_t)) &&       (pUserData->szUser != NULL) && (pUserData->szPassword != NULL) &&       (!pUserData->szRealm || (xppStrlen (pUserData->szRealm) < MAX_REALM_SIZE)) &&       (!pUserData->szCNonce || (xppStrlen (pUserData->szCNonce) < MAX_CNONCE_SIZE)) &&       (!pUserData->szNC || (xppStrlen (pUserData->szNC) < MAX_NC_SIZE)) &&       (xppStrlen (pUserData->szUser) < MAX_USER_SIZE) &&       (xppStrlen (pUserData->szPassword) < MAX_PWD_SIZE) &&       ((dig = getDigest (auth, dest)) != NULL) )      {      xppStrcpy (dig->achUser, pUserData->szUser);      xppStrcpy (dig->achPassword, pUserData->szPassword);      if (pUserData->szRealm == NULL)         xppStrcpy (dig->achRealm, "");      else         xppStrcpy (dig->achRealm, pUserData->szRealm);      if (pUserData->szCNonce == NULL)         xppStrcpy (dig->achCNonce, "");      else         xppStrcpy (dig->achCNonce, pUserData->szCNonce);      if (pUserData->szNC == NULL)         xppStrcpy (dig->achNC, "");      else         xppStrcpy (dig->achNC, pUserData->szNC);      }   else      rc = false;   return rc;   }Bool_t authSetType (HttpAuthenticationPtr_t auth,                    HttpAuthenticationDest_t dest,                    HttpAuthenticationType_t type)   {   Bool_t rc = true;   HttpDigestPtr_t dig;   /**************************/   /* check entry conditions */   /**************************/   if ((dest != AUTH_NONE) && (auth != NULL) &&       ((dig = getDigest (auth, dest)) != NULL) )      dig->fType = type;   else      rc = false;   return rc;   }HttpAuthenticationType_t authGetType (HttpAuthenticationPtr_t auth,                                      HttpAuthenticationDest_t dest)   {   HttpAuthenticationType_t rc = AUTH_NONE;   HttpDigestPtr_t dig;   /**************************/   /* check entry conditions */   /**************************/   if ((dest != AUTH_NONE) && (auth != NULL) &&       ((dig = getDigest (auth, dest)) != NULL) )      rc = dig->fType;   return rc;   }CString_t authGetDigest (HttpAuthenticationPtr_t auth,                         HttpAuthenticationDest_t dest)   {

⌨️ 快捷键说明

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