📄 xpt-http.c
字号:
{ pszRest [0] = '\0'; // separate token from rest pszRest ++; while (pszRest [0] == ' ') pszRest ++; } *ppszToken = pszToken; return pszRest; }// Note: gcc cannot parse multi-line macros in files with DOS lineends#define SKIP_WHITESPACE(s) while (((s)[0] == ' ')||((s)[0] == ',')||((s)[0] == '\t')) (s) ++/**************************************************************//* Function: parse one parameter from the specified line. *//* it is assumed that the parameter has the following format: *//* parm={ value | "value" }[,] *//* Return the rest of the string, or NULL if here are no more *//* data to handle *//* The function changes the contents of pszLine!! *//**************************************************************/// %%% luz 2002-04-16: made static as same name is used for slightly different function in obexbinding.cstatic StringBuffer_t splitParmValue (StringBuffer_t pszLine, // i: line StringPtr_t ppszParm, // o: ptr to extracted parameter StringPtr_t ppszValue) // o: ptr to extracted parameter value { StringBuffer_t pszToken = pszLine; StringBuffer_t pszRest = NULL; if (pszToken == NULL) return NULL; /* skip leading blanks */ SKIP_WHITESPACE (pszToken); pszRest = pszToken; *ppszParm = pszRest; if (pszToken [0] == '\0') return NULL; /* Find the delimiter */ while ((*pszRest != '\0') && (*pszRest != '=') && (*pszRest != ' ') && (*pszRest != ',')) pszRest ++; switch (*pszRest) { case '\0': // *ppszValue = pszRest; break; case ',': case ' ': // whitespace: there is no value assigned to this parameter *pszRest = '\0'; *ppszValue = pszRest; pszRest ++; break; case '=': /* The value part may or may not be enclosed in quotes */ *pszRest = '\0'; pszRest ++; SKIP_WHITESPACE (pszRest); if (pszRest [0] == '\"') { *ppszValue = ++pszRest; while ((*pszRest != '\0') && (*pszRest != '\"')) pszRest ++; } else { *ppszValue = pszRest; while ((*pszRest != '\0') && (*pszRest != ' ') && (*pszRest != ',')) pszRest ++; } if (*pszRest) { *pszRest = '\0'; pszRest ++; } break; } return pszRest; }/*************************************************************************//* Function: Separate the first line from the specified multiline string *//* Return the rest of the string. *//* The function changes the contents of pchLine!! *//*************************************************************************/StringBuffer_t splitLine (StringBuffer_t pchLine) // i: multiline string { StringBuffer_t ptr; StringBuffer_t pszSplit; ptr = xppStrchr ((char *)pchLine, '\n'); if (ptr) { if (*(ptr-1) == '\r') pszSplit = ptr-1; else pszSplit = ptr; *pszSplit = '\0'; ptr ++; } return ptr; }void evaluateHdrHost (HttpBufferPtr_t p, StringBuffer_t pszValue) { freeString (p->pchHost); p->pchHost = makeString (pszValue); }void evaluateHdrFrom (HttpBufferPtr_t p, StringBuffer_t pszValue) { freeString (p->pchFrom); p->pchFrom = makeString (pszValue); }void evaluateHdrReferer (HttpBufferPtr_t p, StringBuffer_t pszValue) { freeString (p->pchReferer); p->pchReferer = makeString (pszValue); }void evaluateHdrContentLength (HttpBufferPtr_t p, StringBuffer_t pszValue) { p->cbDataLength = (BufferSize_t) atol (pszValue); }void evaluateHdrContentType (HttpBufferPtr_t p, StringBuffer_t pszValue) { freeString (p->pchResponseType); p->pchResponseType = makeString (pszValue); p->bEox = false; // we expect an attached document }void evaluateHdrConnection (HttpBufferPtr_t p, StringBuffer_t pszValue) { if (!xppStricmp (pszValue, "close")) p->fConnection = CLOSE; else p->fConnection = KEEP_ALIVE; }void evaluateHdrTransferEncoding (HttpBufferPtr_t p, StringBuffer_t pszValue) { CString_t pszToken = NULL; while ((pszValue != NULL) && (pszValue [0] != '\0')) { pszValue = splitToken (pszValue, &pszToken); if (!xppStricmp (pszToken, "chunked")) p->fTransferCoding = CHUNKED;// if (!xppStricmp (pszToken, "base64"))// p->fEncoding = BASE64; } p->bEox = false; // we expect an attached document }void evaluateHdrXSyncmlHmac (HttpBufferPtr_t p, StringBuffer_t pszValue) { StringBuffer_t line; CString_t param = NULL; CString_t value = NULL; freeString (p->sXSyncmlHmac.pchHmac); p->sXSyncmlHmac.pchHmac = makeString (pszValue); line = p->sXSyncmlHmac.pchHmac; while (line != NULL) { line = splitParmValue(line, ¶m, &value); if ((param != NULL) && (param [0] != '\0')) { if (!xppStricmp (param, "algorithm")) p->sXSyncmlHmac.hmacInfo.algorithm = value; else if (!xppStricmp (param, "username")) p->sXSyncmlHmac.hmacInfo.username = value; else if (!xppStricmp (param, "mac")) p->sXSyncmlHmac.hmacInfo.mac = value; } } }void evaluateHdrAuthorization (HttpBufferPtr_t p, StringBuffer_t pszValue, HttpAuthenticationPtr_t auth, HttpAuthenticationDest_t dest) { CString_t pszParm = NULL; CString_t pszToken = NULL; if (p->fOpenMode == MODE_HTTP_SERVER) { pszValue = splitToken (pszValue, &pszToken); if (!xppStricmp (pszToken, "Basic")) authSetDigest (auth, dest, pszValue); else if (!xppStricmp (pszToken, "Digest")) { CString_t pszDigest = NULL; HttpAuthenticationUserData_t aud; HttpAuthenticationData_t ad; xppMemset (&aud, 0, sizeof (aud)); aud.cbSize = sizeof (aud); xppMemset (&ad, 0, sizeof (ad)); ad.cbSize = sizeof (ad); while (pszValue != NULL) { pszValue = splitParmValue (pszValue, &pszToken, &pszParm); if (!xppStricmp (pszToken, "nonce")) ad.szNonce = pszParm; else if (!xppStricmp (pszToken, "nc")) aud.szNC = pszParm; else if (!xppStricmp (pszToken, "cnonce")) aud.szCNonce = pszParm; else if (!xppStricmp (pszToken, "qop")) ad.szQop = pszParm; else if (!xppStricmp (pszToken, "opaque")) ad.szOpaque = pszParm; else if (!xppStricmp (pszToken, "username")) aud.szUser = pszParm; else if (!xppStricmp (pszToken, "realm")) aud.szRealm = ad.szRealm = pszParm; else if (!xppStricmp (pszToken, "stale") && !xppStricmp (pszParm, "true")) ad.bStale = true; else if (!xppStricmp (pszToken, "response")) pszDigest = pszParm; } authSetUserData (auth, dest, &aud); authSetAuthenticationData (auth, dest, &ad); authSetDigest (auth, dest, pszDigest); } } return; }void evaluateHdrAuthenticationInfo (HttpBufferPtr_t p, StringBuffer_t pszValue, HttpAuthenticationPtr_t auth, HttpAuthenticationDest_t dest) // will be overwritten! { HttpAuthenticationInfo_t ai; CString_t pszToken; CString_t pszParm; xppMemset (&ai, 0, sizeof (HttpAuthenticationInfo_t)); ai.cbSize = sizeof (HttpAuthenticationInfo_t); if (p->fOpenMode != MODE_HTTP_SERVER) { /*************************************************************/ /* Find ount if the Authentication info block belongs to the */ /* server authentication or to the proxy authentication */ /*************************************************************/ if (p->iHttpStatus == 407) dest = DEST_PROXY; else dest = DEST_SERVER; while (pszValue != NULL) { pszValue = splitParmValue (pszValue, &pszToken, &pszParm); if (!xppStricmp (pszToken, "nextnonce")) ai.szNonce = pszParm; else if (!xppStricmp (pszToken, "nc")) ai.szNC = pszParm; else if (!xppStricmp (pszToken, "qop")) ai.szQop = pszParm; } authSetAuthenticationInfo (auth, dest, &ai); } }void evaluateHdrWWWAuthenticateInfo (HttpBufferPtr_t p, StringBuffer_t pszValue, HttpAuthenticationPtr_t auth, HttpAuthenticationDest_t dest) { CString_t pszToken = NULL; CString_t pszParm = NULL; // CString_t pszNonce = NULL; // CString_t pszOpaque = NULL; // CString_t pszRealm = NULL; // CString_t pszDomain = NULL; // CString_t pszQop = NULL; HttpAuthenticationType_t typ; HttpAuthenticationData_t ad; xppMemset (&ad, 0, sizeof (HttpAuthenticationData_t)); ad.cbSize = sizeof (HttpAuthenticationData_t); if (p->fOpenMode != MODE_HTTP_SERVER) { /*********************************/ /* Parse the authentication type */ /*********************************/ pszValue = splitToken (pszValue, &pszToken); if (!xppStricmp (pszToken, "Basic")) typ = AUTH_BASIC; else if (!xppStricmp (pszToken, "Digest") ) typ = AUTH_DIGEST; else return; // unsupported authentication type: // the HTTP error 401 will be returned to the application /*******************************************/ /* Get the other authentication parameters */ /*******************************************/ while (pszValue != NULL) { pszValue = splitParmValue (pszValue, &pszToken, &pszParm); if (!xppStricmp (pszToken, "qop")) { /********************************************/ /* Check if one of the supported algorithms */ /* is returned in the QOP parameter buffer. */ /********************************************/ unsigned int uQop = 0; char * pszAlgorithms = pszValue; while (pszAlgorithms != NULL) { pszAlgorithms = splitToken (pszAlgorithms, &pszToken); if (!xppStricmp (pszToken, "auth-int")) uQop |= 2; if (!xppStricmp (pszToken, "auth")) uQop |= 1; } if (uQop & 1) ad.szQop = "auth"; else if (uQop & 2) ad.szQop = "auth-int"; } if (!xppStricmp (pszToken, "realm")) ad.szRealm = pszParm; if (!xppStricmp (pszToken, "nonce")) ad.szNonce = pszParm; if (!xppStricmp (pszToken, "opaque")) ad.szOpaque = pszParm;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -