ANSC_STATUS CcspCwmpAcscoHttpAddCookie ( ANSC_HANDLE hThisObject, PCHAR pCookie ) { PCCSP_CWMP_ACS_CONNECTION_OBJECT pMyObject = (PCCSP_CWMP_ACS_CONNECTION_OBJECT)hThisObject; ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; PHTTP_SIMPLE_CLIENT_OBJECT pHttpSimpleClient = (PHTTP_SIMPLE_CLIENT_OBJECT)pMyObject->hHttpSimpleClient; PHTTP_HFP_INTERFACE pHttpHfpIf = (PHTTP_HFP_INTERFACE)pHttpSimpleClient->GetHfpIf((ANSC_HANDLE)pHttpSimpleClient); char* pCookieValue = NULL; PHTTP_HFO_SET_COOKIE pHfoSetCookie = NULL; if ( !pCookie || AnscSizeOfString(pCookie) <= 5) { CcspTr069PaTraceDebug(("!!!Empty Cookie, ignored.\n")); return ANSC_STATUS_SUCCESS; } if ( pMyObject->NumCookies >= CCSP_CWMP_ACSCO_MAX_COOKIE ) { CcspTr069PaTraceDebug(("!!!Too many cookies, over the limit %d.\n", CCSP_CWMP_ACSCO_MAX_COOKIE)); return ANSC_STATUS_DISCARD; } pCookieValue = (PCHAR)CcspTr069PaAllocateMemory(AnscSizeOfString(pCookie) + 64); if( NULL == pCookieValue ) { return ANSC_STATUS_RESOURCES; } pHfoSetCookie = (PHTTP_HFO_SET_COOKIE)pHttpHfpIf->ParseHeader(pHttpHfpIf->hOwnerContext, pCookie, AnscSizeOfString(pCookie)); if ( pHfoSetCookie ) { ULONG ulCookieSize = 0; int nIndex; ULONG i; /* play a trick here - suppose the definitions of Cookie and Set-Cookie/2 are the same */ pHfoSetCookie->HeaderId = HTTP_HEADER_ID_COOKIE; pHfoSetCookie->Flags &= ~HTTP_FIELD_FLAG_VALUE_PRESENT; pHfoSetCookie->Flags &= ~HTTP_FIELD_FLAG_LINE_PRESENT; ulCookieSize = pHttpHfpIf->GetHeaderSize(pHttpHfpIf->hOwnerContext, (ANSC_HANDLE)pHfoSetCookie); pHttpHfpIf->BuildHeader(pHttpHfpIf->hOwnerContext, (ANSC_HANDLE)pHfoSetCookie, pCookieValue, ulCookieSize); pCookieValue[ulCookieSize] = 0; /* remove old cookies */ for ( i = 0; i < pHfoSetCookie->CookieCount; i ++ ) { nIndex = pMyObject->FindCookie((ANSC_HANDLE)pMyObject, pHfoSetCookie->CookieArray[i].Name); if ( nIndex >= 0 ) { pMyObject->DelCookie((ANSC_HANDLE)pMyObject, (ULONG)nIndex); } } pMyObject->Cookies[pMyObject->NumCookies++] = CcspTr069PaCloneString(pCookieValue + 8); CcspTr069PaFreeMemory(pHfoSetCookie); } CcspTr069PaFreeMemory(pCookieValue); return returnStatus; }
ANSC_STATUS HttpBmoCopyHeadersFrom ( ANSC_HANDLE hThisObject, PVOID buffer, PULONG pulSize ) { ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; PHTTP_BASIC_MESSAGE_OBJECT pMyObject = (PHTTP_BASIC_MESSAGE_OBJECT)hThisObject; PHTTP_HFP_INTERFACE pHfpIf = (PHTTP_HFP_INTERFACE )pMyObject->hHfpIf; PANSC_BUFFER_DESCRIPTOR pHeaderBdo = (PANSC_BUFFER_DESCRIPTOR )pMyObject->hHeaderBdo; PHTTP_HEADER_FIELD pHttpHfo = NULL; PSINGLE_LINK_ENTRY pSLinkEntry = NULL; ULONG ulHeadersSize = 0; ULONG ulCopySize = 0; ULONG ulLeftSize = *pulSize; char* pHfStream = (char*)buffer; ULONG i = 0; if ( *pulSize < pMyObject->GetHeadersSize((ANSC_HANDLE)pMyObject) ) { return ANSC_STATUS_BAD_SIZE; } else if ( pHeaderBdo ) { AnscCopyMemory ( buffer, AnscBdoGetBlock (pHeaderBdo), AnscBdoGetBlockSize(pHeaderBdo) ); *pulSize = AnscBdoGetBlockSize(pHeaderBdo); return ANSC_STATUS_SUCCESS; } ulCopySize = ulLeftSize; pHfStream = (char*)((ULONG)buffer + ulHeadersSize); returnStatus = pMyObject->CopyStartLineFrom ( (ANSC_HANDLE)pMyObject, (PVOID)pHfStream, &ulCopySize ); if ( returnStatus != ANSC_STATUS_SUCCESS ) { return returnStatus; } else { pHfStream += ulCopySize; ulHeadersSize += ulCopySize; ulLeftSize -= ulCopySize; pHfStream[0] = HTTP_CARRIAGE_RETURN; pHfStream[1] = HTTP_LINE_FEED; pHfStream += 2; ulHeadersSize += 2; ulLeftSize -= 2; } AnscAcquireLock(&pMyObject->HfoTableLock); for ( i = 0; i < HTTP_BMO_HFO_TABLE_SIZE; i++ ) { pSLinkEntry = AnscQueueGetFirstEntry(&pMyObject->HfoTable[i]); while ( pSLinkEntry ) { pHttpHfo = ACCESS_HTTP_HEADER_FIELD(pSLinkEntry); pSLinkEntry = AnscQueueGetNextEntry(pSLinkEntry); ulCopySize = pHfpIf->GetHeaderSize(pHfpIf->hOwnerContext, (ANSC_HANDLE)pHttpHfo); if ( ulCopySize > 0 ) { returnStatus = pHfpIf->BuildHeader ( pHfpIf->hOwnerContext, (ANSC_HANDLE)pHttpHfo, (PVOID)pHfStream, ulCopySize ); if ( returnStatus != ANSC_STATUS_SUCCESS ) { return returnStatus; } else { pHfStream += ulCopySize; ulHeadersSize += ulCopySize; ulLeftSize -= ulCopySize; pHfStream[0] = HTTP_CARRIAGE_RETURN; pHfStream[1] = HTTP_LINE_FEED; pHfStream += 2; ulHeadersSize += 2; ulLeftSize -= 2; } } } } AnscReleaseLock(&pMyObject->HfoTableLock); pHfStream[0] = HTTP_CARRIAGE_RETURN; pHfStream[1] = HTTP_LINE_FEED; pHfStream += 2; ulHeadersSize += 2; ulLeftSize -= 2; *pulSize = ulHeadersSize; return ANSC_STATUS_SUCCESS; }
static void HttpScoSetCookie ( ANSC_HANDLE hHfpIf, ANSC_HANDLE hResponse, ANSC_HANDLE hRequest ) { PHTTP_HFP_INTERFACE pHttpHfpIf = (PHTTP_HFP_INTERFACE)hHfpIf; PHTTP_BMO_REP_OBJECT pResponse = (PHTTP_BMO_REP_OBJECT)hResponse; PHTTP_BMO_REQ_OBJECT pRequest = (PHTTP_BMO_REQ_OBJECT)hRequest; char* pSetCookie = NULL; BOOL bSetCookie2 = FALSE; ULONG ulCount1 = 0; ULONG ulCount2 = 0; PHTTP_HEADER_FIELD pHttpHfo = NULL; pRequest->DelHeaderField((ANSC_HANDLE)pRequest, HTTP_HEADER_ID_COOKIE); while ( TRUE ) { pSetCookie = pResponse->GetHeaderValueByName2((ANSC_HANDLE)pResponse, "Set-Cookie2", ulCount1++); if ( !pSetCookie ) { pSetCookie = pResponse->GetHeaderValueByName2((ANSC_HANDLE)pResponse, "Set-Cookie", ulCount2++); bSetCookie2 = TRUE; } if ( !pSetCookie ) { break; } else { char* pCookie = NULL; ULONG ulCookieSize = AnscSizeOfString(pSetCookie) + 64; pCookie = (char *)AnscAllocateMemory(ulCookieSize); if ( pCookie ) { PHTTP_HFO_SET_COOKIE pHfoSetCookie = NULL; if ( bSetCookie2 ) { _ansc_sprintf(pCookie, "Set-Cookie2: %s", pSetCookie); } else { _ansc_sprintf(pCookie, "Set-Cookie: %s", pSetCookie); } pHfoSetCookie = (PHTTP_HFO_SET_COOKIE)pHttpHfpIf->ParseHeader(pHttpHfpIf->hOwnerContext, pCookie, AnscSizeOfString(pCookie)); if ( pHfoSetCookie ) { char* pCookieValue = NULL; pHfoSetCookie->HeaderId = HTTP_HEADER_ID_COOKIE; pHfoSetCookie->Flags &= ~HTTP_FIELD_FLAG_VALUE_PRESENT; pHfoSetCookie->Flags &= ~HTTP_FIELD_FLAG_LINE_PRESENT; ulCookieSize = pHttpHfpIf->GetHeaderSize(pHttpHfpIf->hOwnerContext, (ANSC_HANDLE)pHfoSetCookie); pHttpHfpIf->BuildHeader(pHttpHfpIf->hOwnerContext, (ANSC_HANDLE)pHfoSetCookie, pCookie, ulCookieSize); pCookie[ulCookieSize] = 0; if ( pCookie ) { pRequest->SetHeaderValueByName((ANSC_HANDLE)pRequest, "Cookie", pCookie + 8); } AnscFreeMemory(pHfoSetCookie); } AnscFreeMemory(pCookie); } } } }