ANSC_STATUS HttpBmoReqCopyStartLineFrom ( ANSC_HANDLE hThisObject, PVOID buffer, PULONG pulSize ) { ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; PHTTP_BMO_REQ_OBJECT pMyObject = (PHTTP_BMO_REQ_OBJECT)hThisObject; PHTTP_HFP_INTERFACE pHfpIf = (PHTTP_HFP_INTERFACE )pMyObject->hHfpIf; PHTTP_REQUEST_INFO pReqInfo = (PHTTP_REQUEST_INFO )pMyObject->hReqInfo; ULONG ulStartLineSize = pMyObject->GetStartLineSize((ANSC_HANDLE)pMyObject); if ( *pulSize < ulStartLineSize ) { return ANSC_STATUS_BAD_SIZE; } returnStatus = pHfpIf->BuildRequestLine ( pHfpIf->hOwnerContext, (ANSC_HANDLE)pReqInfo, buffer, ulStartLineSize ); *pulSize = ulStartLineSize; return returnStatus; }
char* HttpBmoGetHeaderValueById2 ( ANSC_HANDLE hThisObject, ULONG ulHeaderId, ULONG ulIndex ) { 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; #ifndef _CCSP_CWMP_TCP_CONNREQ_HANDLER PHTTP_HELPER_CONTAINER_OBJECT pHttpHco = (PHTTP_HELPER_CONTAINER_OBJECT)pMyObject->hContainerContext; #endif PHTTP_HEADER_FIELD pHttpHfo = NULL; char* pHttpHfValue = NULL; pHttpHfo = (PHTTP_HEADER_FIELD)pMyObject->GetHeaderField2 ( (ANSC_HANDLE)pMyObject, ulHeaderId, ulIndex ); if ( !pHttpHfo ) { return NULL; } else if ( !(pHttpHfo->Flags & HTTP_FIELD_FLAG_LINE_PRESENT) ) { returnStatus = pHfpIf->BuildHeader ( pHfpIf->hOwnerContext, (ANSC_HANDLE)pHttpHfo, NULL, 0 ); } AnscHttpGetHfValue(pHttpHfo->HeaderLine, AnscSizeOfString(pHttpHfo->HeaderLine), pHttpHfValue); return pHttpHfValue; }
ANSC_STATUS HttpBmoParseHeaders ( ANSC_HANDLE hThisObject ) { 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; PVOID pHeaderBuffer = NULL; ULONG ulBufferSize = 0; char* pHfStart = NULL; ULONG ulSkipSize = 0; char* pRawHfLine = NULL; char* pStdHfLine = (char*)pMyObject->ScratchPad1; ULONG ulRawLineSize = 0; ULONG ulStdLineSize = 0; pMyObject->DelStartLine((ANSC_HANDLE)pMyObject); pMyObject->DelAllHfos ((ANSC_HANDLE)pMyObject); returnStatus = pMyObject->ParseStartLine((ANSC_HANDLE)pMyObject); if ( returnStatus != ANSC_STATUS_SUCCESS ) { return returnStatus; } else if ( !pHeaderBdo ) { return ANSC_STATUS_UNAPPLICABLE; } else { pHeaderBuffer = AnscBdoGetBlock (pHeaderBdo); ulBufferSize = AnscBdoGetBlockSize(pHeaderBdo); } AnscHttpFindHfStart(pHeaderBuffer, ulBufferSize, pHfStart); if ( !pHfStart ) { return ANSC_STATUS_UNAPPLICABLE; } else { ulSkipSize = (ULONG)pHfStart - (ULONG)pHeaderBuffer; ulBufferSize -= ulSkipSize; pRawHfLine = pHfStart; } /* * Skip the first line, which is the start line: request-line in client message and status-line * in server message. */ AnscHttpGetHfLineSize(pRawHfLine, ulBufferSize, ulRawLineSize); pRawHfLine += ulRawLineSize; ulBufferSize -= ulRawLineSize; /* * We don't have to verify the completeness of the header fields, since the caller SHOULD have * done so already. We create a separate HTTP Header Field Object for each header line and add * it into the distributed hash table. The end of header fields is signalled by the presece of * a CRLF pair. */ while ( (ulBufferSize > 0) && pRawHfLine && !AnscHttpIsCr(*pRawHfLine) && !AnscHttpIsLf(*pRawHfLine) ) { AnscHttpGetHfLineSize(pRawHfLine, ulBufferSize, ulRawLineSize); if ( ulRawLineSize <= pMyObject->PadSize1 ) { AnscHttpPrepareHeader(pRawHfLine, ulRawLineSize, pStdHfLine, ulStdLineSize); pStdHfLine[ulStdLineSize + 0] = HTTP_CARRIAGE_RETURN; pStdHfLine[ulStdLineSize + 1] = HTTP_LINE_FEED; pHttpHfo = (PHTTP_HEADER_FIELD)pHfpIf->ParseHeader ( pHfpIf->hOwnerContext, pStdHfLine, ulStdLineSize ); if ( pHttpHfo ) { returnStatus = pMyObject->AddHeaderField ( (ANSC_HANDLE)pMyObject, (ANSC_HANDLE)pHttpHfo ); } } pRawHfLine += ulRawLineSize; ulBufferSize -= ulRawLineSize; } return ANSC_STATUS_SUCCESS; }
ANSC_STATUS HttpBmoSetHeaderValueByName ( ANSC_HANDLE hThisObject, char* name, char* value ) { 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; #ifndef _CCSP_CWMP_TCP_CONNREQ_HANDLER PHTTP_HELPER_CONTAINER_OBJECT pHttpHco = (PHTTP_HELPER_CONTAINER_OBJECT)pMyObject->hContainerContext; #endif PHTTP_HEADER_FIELD pHttpHfo = NULL; char* pHttpHfValue = NULL; char* pHfLine = (char*)pMyObject->ScratchPad1; ULONG ulLineSize = 0; if ( (AnscSizeOfString(name) + AnscSizeOfString(value) + 4) >= pMyObject->PadSize1 ) { return ANSC_STATUS_RESOURCES; } else { AnscCopyString(pHfLine, name); ulLineSize = AnscSizeOfString(name); pHfLine[ulLineSize + 0] = HTTP_COLON; pHfLine[ulLineSize + 1] = HTTP_SPACE; ulLineSize += 2; AnscCopyString(pHfLine + ulLineSize, value); ulLineSize += AnscSizeOfString(value); pHfLine[ulLineSize + 0] = HTTP_CARRIAGE_RETURN; pHfLine[ulLineSize + 1] = HTTP_LINE_FEED; } pHttpHfo = (PHTTP_HEADER_FIELD)pHfpIf->ParseHeader ( pHfpIf->hOwnerContext, pHfLine, ulLineSize ); if ( !pHttpHfo ) { return ANSC_STATUS_UNAPPLICABLE; } else { returnStatus = pMyObject->AddHeaderField ( (ANSC_HANDLE)pMyObject, (ANSC_HANDLE)pHttpHfo ); } 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; }
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 HttpBmoReqParseStartLine ( ANSC_HANDLE hThisObject ) { ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; PHTTP_BMO_REQ_OBJECT pMyObject = (PHTTP_BMO_REQ_OBJECT )hThisObject; PHTTP_HFP_INTERFACE pHfpIf = (PHTTP_HFP_INTERFACE )pMyObject->hHfpIf; PANSC_BUFFER_DESCRIPTOR pHeaderBdo = (PANSC_BUFFER_DESCRIPTOR)pMyObject->hHeaderBdo; PHTTP_REQUEST_INFO pReqInfo = (PHTTP_REQUEST_INFO )pMyObject->hReqInfo; PVOID pHeaderBuffer = NULL; ULONG ulBufferSize = 0; char* pHfStart = NULL; ULONG ulSkipSize = 0; char* pRawHfLine = NULL; char* pStdHfLine = (char*)pMyObject->ScratchPad1; ULONG ulRawLineSize = 0; ULONG ulStdLineSize = 0; pMyObject->DelStartLine((ANSC_HANDLE)pMyObject); if ( !pHeaderBdo ) { return ANSC_STATUS_UNAPPLICABLE; } else { pHeaderBuffer = AnscBdoGetBlock (pHeaderBdo); ulBufferSize = AnscBdoGetBlockSize(pHeaderBdo); } AnscHttpFindHfStart(pHeaderBuffer, ulBufferSize, pHfStart); if ( !pHfStart ) { return ANSC_STATUS_UNAPPLICABLE; } else { ulSkipSize = (ULONG)pHfStart - (ULONG)pHeaderBuffer; ulBufferSize -= ulSkipSize; pRawHfLine = pHfStart; } AnscHttpGetHfLineSize(pRawHfLine, ulBufferSize, ulRawLineSize); if ( ulRawLineSize <= pMyObject->PadSize1 ) { AnscHttpPrepareHeader(pRawHfLine, ulRawLineSize, pStdHfLine, ulStdLineSize); pStdHfLine[ulStdLineSize + 0] = HTTP_CARRIAGE_RETURN; pStdHfLine[ulStdLineSize + 1] = HTTP_LINE_FEED; pReqInfo = (PHTTP_REQUEST_INFO)pHfpIf->ParseRequestLine ( pHfpIf->hOwnerContext, pStdHfLine, ulStdLineSize ); } else { pReqInfo = NULL; } if ( !pReqInfo ) { return ANSC_STATUS_BAD_PAYLOAD; } else { pMyObject->hReqInfo = (ANSC_HANDLE)pReqInfo; } 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); } } } }
ANSC_STATUS HttpBmoSaveFormAsFile ( ANSC_HANDLE hThisObject, char* param_name, char* file_name, BOOL bFlushBody ) { ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; PHTTP_BASIC_MESSAGE_OBJECT pMyObject = (PHTTP_BASIC_MESSAGE_OBJECT)hThisObject; PHTTP_BMO_REQ_OBJECT pBmoReq = (PHTTP_BMO_REQ_OBJECT )pMyObject; PHTTP_HFP_INTERFACE pHfpIf = (PHTTP_HFP_INTERFACE )pMyObject->hHfpIf; PHTTP_TMH_INTERFACE pTmhIf = (PHTTP_TMH_INTERFACE )pMyObject->hTmhIf; PHTTP_BCC_INTERFACE pBccIf = (PHTTP_BCC_INTERFACE )pMyObject->hBccIf; PHTTP_RCP_INTERFACE pRcpIf = (PHTTP_RCP_INTERFACE )pBmoReq->hRcpIf; PHTTP_FUM_INTERFACE pFumIf = (PHTTP_FUM_INTERFACE )pMyObject->hFumIf; PHTTP_MDH_INTERFACE pMdhIf = (PHTTP_MDH_INTERFACE )NULL; PHTTP_MESSAGE_BODY_OBJECT pMessageBody = (PHTTP_MESSAGE_BODY_OBJECT )pMyObject->hMessageBody; char* pBoundaryStr = NULL; ULONG ulEncType = HTTP_HFP_FORM_ENCTYPE_URLENCODED; ULONG ulMediaType = IANA_MEDIA_TYPE_CODE_APPLICATION; ULONG ulSubType = IANA_MT_AP_STYPE_CODE_X_FORM_URLENCODED; char* pReqUri = pRcpIf->GetPathInfo(pRcpIf->hOwnerContext, (ANSC_HANDLE)pMyObject); pMdhIf = (PHTTP_MDH_INTERFACE)pFumIf->GetMdhIf(pFumIf->hOwnerContext, pReqUri); if ( pMdhIf ) { return pMdhIf->SaveFileAs ( pMdhIf->hOwnerContext, pBmoReq->GetWebSessionId((ANSC_HANDLE)pBmoReq), pReqUri, param_name, file_name ); } if ( !pMessageBody || (pMyObject->Oid != HTTP_BMO_REQ_OID) ) { return ANSC_STATUS_UNAPPLICABLE; } else if ( pBmoReq->GetMethod((ANSC_HANDLE)pBmoReq) != HTTP_METHOD_CODE_POST ) { return ANSC_STATUS_UNAPPLICABLE; } if ( TRUE ) { returnStatus = HttpBmoReqCgiGetContentType ( (ANSC_HANDLE)pBmoReq, &ulMediaType, &ulSubType ); if ( (ulMediaType == IANA_MEDIA_TYPE_CODE_APPLICATION ) && (ulSubType == IANA_MT_AP_STYPE_CODE_X_FORM_URLENCODED) ) { ulEncType = HTTP_HFP_FORM_ENCTYPE_URLENCODED; } else if ( (ulMediaType == IANA_MEDIA_TYPE_CODE_MULTIPART ) && (ulSubType == IANA_MT_MP_STYPE_CODE_FORM_DATA) ) { ulEncType = HTTP_HFP_FORM_ENCTYPE_MULTIPART; pBoundaryStr = HttpBmoReqCgiGetBoundaryDelimiter((ANSC_HANDLE)pBmoReq); if ( !pBoundaryStr ) { return ANSC_STATUS_UNAPPLICABLE; } } else { return ANSC_STATUS_UNAPPLICABLE; } } returnStatus = pHfpIf->SaveFormPartAsFile ( pHfpIf->hOwnerContext, param_name, file_name, ulEncType, pBoundaryStr, (ANSC_HANDLE)pMessageBody, bFlushBody ); if ( pBoundaryStr ) { AnscFreeMemory(pBoundaryStr); } return returnStatus; }
ANSC_STATUS HttpMboChkParseTrailer ( ANSC_HANDLE hThisObject, char* pRawTrailer, ULONG ulTrailerSize ) { ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; PHTTP_MBO_CHUNKED_OBJECT pMyObject = (PHTTP_MBO_CHUNKED_OBJECT)hThisObject; PHTTP_HFP_INTERFACE pHfpIf = (PHTTP_HFP_INTERFACE )pMyObject->hHfpIf; PHTTP_BCC_INTERFACE pBccIf = (PHTTP_BCC_INTERFACE )pMyObject->hBccIf; PHTTP_HEADER_FIELD pHttpHfo = NULL; char* pHfStart = (char*)pRawTrailer; char* pRawHfLine = (char*)pRawTrailer; char* pStdHfLine = (char*)pMyObject->ScratchPad2; ULONG ulRawLineSize = 0; ULONG ulStdLineSize = 0; ULONG ulBufferSize = ulTrailerSize; if ( ulTrailerSize == 2 ) { return ANSC_STATUS_SUCCESS; } else { pHfStart = pRawTrailer; pRawHfLine = pHfStart; } /* * Skip the first line, which is the start line: request-line in client message and status-line * in server message. */ AnscHttpGetHfLineSize(pRawHfLine, ulBufferSize, ulRawLineSize); pRawHfLine += ulRawLineSize; ulBufferSize -= ulRawLineSize; /* * We don't have to verify the completeness of the header fields, since the caller SHOULD have * done so already. We create a separate HTTP Header Field Object for each header line and add * it into the distributed hash table. The end of header fields is signalled by the presece of * a CRLF pair. */ while ( (ulBufferSize > 0) && pRawHfLine && !AnscHttpIsCr(*pRawHfLine) && !AnscHttpIsLf(*pRawHfLine) ) { AnscHttpGetHfLineSize(pRawHfLine, ulBufferSize, ulRawLineSize); if ( ulRawLineSize <= pMyObject->PadSize1 ) { AnscHttpPrepareHeader(pRawHfLine, ulRawLineSize, pStdHfLine, ulStdLineSize); pStdHfLine[ulStdLineSize + 0] = HTTP_CARRIAGE_RETURN; pStdHfLine[ulStdLineSize + 1] = HTTP_LINE_FEED; pHttpHfo = (PHTTP_HEADER_FIELD)pHfpIf->ParseHeader ( pHfpIf->hOwnerContext, pStdHfLine, ulStdLineSize ); if ( !pHttpHfo ) { return ANSC_STATUS_BAD_PAYLOAD; } else { returnStatus = pBccIf->AddHeaderField ( pBccIf->hOwnerContext, (ANSC_HANDLE)pHttpHfo ); } } pRawHfLine += ulRawLineSize; ulBufferSize -= ulRawLineSize; } return ANSC_STATUS_SUCCESS; }
/********************************************************************** prototype: ANSC_STATUS CcspCwmpAcscoRequestOny ( ANSC_HANDLE hThisObject ); description: This function is called to send the last empty request to ACS. argument: ANSC_HANDLE hThisObject The caller object. return: the status of the operation; **********************************************************************/ ANSC_STATUS CcspCwmpAcscoRequestOnly ( ANSC_HANDLE hThisObject ) { PCCSP_CWMP_ACS_CONNECTION_OBJECT pMyObject = (PCCSP_CWMP_ACS_CONNECTION_OBJECT)hThisObject; return pMyObject->Request((ANSC_HANDLE)pMyObject, NULL, NULL, 0, 0); #if 0 PHTTP_SIMPLE_CLIENT_OBJECT pHttpClient = (PHTTP_SIMPLE_CLIENT_OBJECT)pMyObject->hHttpSimpleClient; PCCSP_CWMP_SESSION_OBJECT pWmpSession = (PCCSP_CWMP_SESSION_OBJECT )pMyObject->hCcspCwmpSession; PCCSP_CWMP_MCO_INTERFACE pCcspCwmpMcoIf = (PCCSP_CWMP_MCO_INTERFACE )pWmpSession->hCcspCwmpMcoIf; PHTTP_HFP_INTERFACE pHttpHfpIf = (PHTTP_HFP_INTERFACE)pHttpClient->GetHfpIf((ANSC_HANDLE)pHttpClient); PHTTP_CAS_INTERFACE pHttpCasIf = NULL; PHTTP_REQUEST_URI pHttpReqInfo = NULL; ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; ANSC_ACS_INTERN_HTTP_CONTENT intHttpContent = { 0 }; PANSC_ACS_INTERN_HTTP_CONTENT pHttpGetReq = &intHttpContent; BOOL bApplyTls = FALSE; PCHAR pRequestURL = NULL; PCHAR pTempString = NULL; PHTTP_AUTH_CLIENT_OBJECT pAuthClientObj = NULL; char pNewUrl[257] = { 0 }; ULONG uRedirect = 0; ULONG uMaxRedirect = 5; if( pMyObject->AcsUrl == NULL || AnscSizeOfString(pMyObject->AcsUrl) <= 10 || pHttpHfpIf == NULL) { return ANSC_STATUS_NOT_READY; } CcspTr069PaTraceDebug(("CcspCwmpAcscoRequest -- AcsUrl = '%s'\n", pMyObject->AcsUrl)); pRequestURL = pMyObject->AcsUrl; if ( AnscEqualString2(pRequestURL, "https", 5, FALSE) ) { bApplyTls = TRUE; } else if ( AnscEqualString2(pRequestURL, "http", 4, FALSE) ) { bApplyTls = FALSE; } else { return ANSC_STATUS_NOT_SUPPORTED; } pHttpCasIf = (PHTTP_CAS_INTERFACE)pHttpClient->GetCasIf((ANSC_HANDLE)pHttpClient); if ( pHttpCasIf != NULL) { if( pMyObject->Username == NULL || AnscSizeOfString(pMyObject->Username) == 0) { pHttpCasIf->EnableAuth(pHttpCasIf->hOwnerContext, FALSE); } else { pHttpCasIf->EnableAuth(pHttpCasIf->hOwnerContext, TRUE); pAuthClientObj = (PHTTP_AUTH_CLIENT_OBJECT)pHttpClient->GetClientAuthObj((ANSC_HANDLE)pHttpClient); if ( pAuthClientObj != NULL) { pAuthClientObj->SetAcmIf((ANSC_HANDLE)pAuthClientObj, (ANSC_HANDLE)pMyObject->hHttpAcmIf); } else { CcspTr069PaTraceError(("Failed to Get HttpAuthClient object.\n")); } } } pHttpReqInfo = (PHTTP_REQUEST_URI)pHttpHfpIf->ParseHttpUrl ( pHttpHfpIf->hOwnerContext, pRequestURL, AnscSizeOfString(pRequestURL) ); if ( !pHttpReqInfo ) { return ANSC_STATUS_INTERNAL_ERROR; } pHttpReqInfo->Type = HTTP_URI_TYPE_ABS_PATH; CcspTr069PaTraceInfo(("Send empty request to now at: %u\n", (unsigned int)AnscGetTickInSeconds())); returnStatus = pHttpClient->Request ( (ANSC_HANDLE)pHttpClient, (ULONG )HTTP_METHOD_CODE_POST, (ANSC_HANDLE)pHttpReqInfo, (ANSC_HANDLE)NULL, bApplyTls ); AnscSleep(500); CcspTr069PaFreeMemory(pHttpReqInfo); return returnStatus; #endif }
ANSC_STATUS CcspCwmpAcscoRequest ( ANSC_HANDLE hThisObject, char* pSoapMessage, char* pMethodName, ULONG ulReqEnvCount, ULONG ulRepEnvCount ) { PCCSP_CWMP_ACS_CONNECTION_OBJECT pMyObject = (PCCSP_CWMP_ACS_CONNECTION_OBJECT)hThisObject; PHTTP_SIMPLE_CLIENT_OBJECT pHttpClient = (PHTTP_SIMPLE_CLIENT_OBJECT)pMyObject->hHttpSimpleClient; PCCSP_CWMP_SESSION_OBJECT pWmpSession = (PCCSP_CWMP_SESSION_OBJECT )pMyObject->hCcspCwmpSession; PCCSP_CWMP_CPE_CONTROLLER_OBJECT pCcspCwmpCpeController = (PCCSP_CWMP_CPE_CONTROLLER_OBJECT)pWmpSession->hCcspCwmpCpeController; PCCSP_CWMP_STAT_INTERFACE pCcspCwmpStatIf = (PCCSP_CWMP_STAT_INTERFACE)pCcspCwmpCpeController->hCcspCwmpStaIf; PCCSP_CWMP_CFG_INTERFACE pCcspCwmpCfgIf = (PCCSP_CWMP_CFG_INTERFACE)pCcspCwmpCpeController->hCcspCwmpCfgIf; PCCSP_CWMP_MCO_INTERFACE pCcspCwmpMcoIf = (PCCSP_CWMP_MCO_INTERFACE )pWmpSession->hCcspCwmpMcoIf; PHTTP_HFP_INTERFACE pHttpHfpIf = (PHTTP_HFP_INTERFACE)pHttpClient->GetHfpIf((ANSC_HANDLE)pHttpClient); PHTTP_CAS_INTERFACE pHttpCasIf = NULL; PHTTP_REQUEST_URI pHttpReqInfo = NULL; ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; PANSC_ACS_INTERN_HTTP_CONTENT pHttpGetReq = &intHttpContent; BOOL bApplyTls = FALSE; PCHAR pRequestURL = NULL; PCHAR pTempString = NULL; PHTTP_AUTH_CLIENT_OBJECT pAuthClientObj = NULL; char pNewUrl[257] = { 0 }; ULONG uRedirect = 0; ULONG uMaxRedirect = 5; ULONG ulRpcCallTimeout= CCSP_CWMPSO_RPCCALL_TIMEOUT; /* If the response is 401 authentication required, we need to try again */ int nMaxAuthRetries = 2; if( pMyObject->AcsUrl == NULL || AnscSizeOfString(pMyObject->AcsUrl) <= 10 || pHttpHfpIf == NULL) { return ANSC_STATUS_NOT_READY; } AnscZeroMemory(pHttpGetReq, sizeof(ANSC_ACS_INTERN_HTTP_CONTENT)); CcspTr069PaTraceDebug(("CcspCwmpAcscoRequest -- AcsUrl = '%s'\n", pMyObject->AcsUrl)); pHttpCasIf = (PHTTP_CAS_INTERFACE)pHttpClient->GetCasIf((ANSC_HANDLE)pHttpClient); if ( pHttpCasIf != NULL) { if( pMyObject->Username == NULL || AnscSizeOfString(pMyObject->Username) == 0) { pHttpCasIf->EnableAuth(pHttpCasIf->hOwnerContext, FALSE); } else { pHttpCasIf->EnableAuth(pHttpCasIf->hOwnerContext, TRUE); pAuthClientObj = (PHTTP_AUTH_CLIENT_OBJECT)pHttpClient->GetClientAuthObj((ANSC_HANDLE)pHttpClient); if ( pAuthClientObj != NULL) { pAuthClientObj->SetAcmIf((ANSC_HANDLE)pAuthClientObj, (ANSC_HANDLE)pMyObject->hHttpAcmIf); } else { CcspTr069PaTraceError(("Failed to Get HttpAuthClient object.\n")); } } } #ifdef _DEBUG if ( !pSoapMessage ) { CcspTr069PaTraceDebug(("CPE Request:\n<EMPTY>\n")); } else if ( AnscSizeOfString(pSoapMessage) <= CCSP_CWMP_TRACE_MAX_SOAP_MSG_LENGTH ) { CcspTr069PaTraceDebug(("CPE Request:\n%s\n", pSoapMessage)); } else { char partSoap[CCSP_CWMP_TRACE_MAX_SOAP_MSG_LENGTH+1+8]; AnscCopyMemory(partSoap, pSoapMessage, CCSP_CWMP_TRACE_MAX_SOAP_MSG_LENGTH); partSoap[CCSP_CWMP_TRACE_MAX_SOAP_MSG_LENGTH] = '\n'; partSoap[CCSP_CWMP_TRACE_MAX_SOAP_MSG_LENGTH+1] = '.'; partSoap[CCSP_CWMP_TRACE_MAX_SOAP_MSG_LENGTH+2] = '.'; partSoap[CCSP_CWMP_TRACE_MAX_SOAP_MSG_LENGTH+3] = '.'; partSoap[CCSP_CWMP_TRACE_MAX_SOAP_MSG_LENGTH+4] = '\n'; partSoap[CCSP_CWMP_TRACE_MAX_SOAP_MSG_LENGTH+5] = 0; CcspTr069PaTraceDebug(("CPE Request:\n%s\n", partSoap)); } #endif START: pRequestURL = pMyObject->AcsUrl; pHttpReqInfo = (PHTTP_REQUEST_URI)pHttpHfpIf->ParseHttpUrl ( pHttpHfpIf->hOwnerContext, pRequestURL, AnscSizeOfString(pRequestURL) ); if ( !pHttpReqInfo ) { return ANSC_STATUS_INTERNAL_ERROR; } pHttpReqInfo->Type = HTTP_URI_TYPE_ABS_PATH; /* init the request */ AnscZeroMemory(pHttpGetReq, sizeof(ANSC_ACS_INTERN_HTTP_CONTENT)); pHttpGetReq->bIsRedirect = FALSE; pHttpGetReq->SoapMessage = pSoapMessage; /* When there is more than one envelope in a single HTTP Request, * when there is a SOAP response in an HTTP Request, or when there is a * SOAP Fault response in an HTTP Request, the SOAPAction header in the * HTTP Request MUST have no value (with no quotes), indicating that this * header provides no information as to the intent of the message." */ if( ulReqEnvCount == 1 && ulRepEnvCount == 0) { pHttpGetReq->MethodName = pMethodName; } AnscInitializeEvent(&pHttpGetReq->CompleteEvent); while ( nMaxAuthRetries > 0 ) { CcspTr069PaTraceInfo(("ACS Request now at: %u\n", (unsigned int)AnscGetTickInSeconds())); if ( AnscEqualString2(pRequestURL, "https", 5, FALSE) ) { bApplyTls = TRUE; } else if ( AnscEqualString2(pRequestURL, "http", 4, FALSE) ) { if ( bIsComcastImage() ){ #ifdef _SUPPORT_HTTP CcspTr069PaTraceInfo(("HTTP request from ACS is supported\n")); bApplyTls = FALSE; #else CcspTr069PaTraceInfo(("TR-069 blocked unsecured traffic from ACS\n")); pHttpGetReq->CompleteStatus = ANSC_STATUS_NOT_SUPPORTED; pHttpGetReq->bUnauthorized = TRUE; pHttpGetReq->bIsRedirect = FALSE; break; #endif } else { bApplyTls = FALSE; } } else { pHttpGetReq->CompleteStatus = ANSC_STATUS_NOT_SUPPORTED; pHttpGetReq->bUnauthorized = FALSE; pHttpGetReq->bIsRedirect = FALSE; break; } if(pHttpGetReq->pContent != NULL) { CcspTr069PaFreeMemory(pHttpGetReq->pContent); pHttpGetReq->pContent = NULL; } pHttpGetReq->CompleteStatus = ANSC_STATUS_FAILURE; pHttpGetReq->bUnauthorized = FALSE; AnscResetEvent (&pHttpGetReq->CompleteEvent); returnStatus = pHttpClient->Request ( (ANSC_HANDLE)pHttpClient, (ULONG )HTTP_METHOD_CODE_POST, (ANSC_HANDLE)pHttpReqInfo, (ANSC_HANDLE)pHttpGetReq, bApplyTls ); if( returnStatus != ANSC_STATUS_SUCCESS) { CcspTr069PaTraceError(("ACS Request failed: returnStatus = %.X\n", (unsigned int)returnStatus)); break; } if ( pCcspCwmpCfgIf && pCcspCwmpCfgIf->GetCwmpRpcTimeout ) { ulRpcCallTimeout = pCcspCwmpCfgIf->GetCwmpRpcTimeout(pCcspCwmpCfgIf->hOwnerContext); if ( ulRpcCallTimeout < CCSP_CWMPSO_RPCCALL_TIMEOUT ) { ulRpcCallTimeout = CCSP_CWMPSO_RPCCALL_TIMEOUT; } } AnscWaitEvent(&pHttpGetReq->CompleteEvent, ulRpcCallTimeout * 1000); if ( pHttpGetReq->CompleteStatus == ANSC_STATUS_SUCCESS && pHttpGetReq->bUnauthorized && nMaxAuthRetries > 0 ) { CcspTr069PaTraceError(("ACS Request is not authenticated, try again.\n")); nMaxAuthRetries --; #ifdef _ANSC_USE_OPENSSL_ if( bApplyTls ) { if ( ANSC_STATUS_SUCCESS == CcspTr069PaSsp_GetTr069CertificateLocationForSyndication( &openssl_client_ca_certificate_files ) ) { openssl_load_ca_certificates( SSL_CLIENT_CALLS ); } } #endif /* _ANSC_USE_OPENSSL_ */ } else { CcspTr069PaTraceInfo(("ACS Request has completed with status code %lu, at %lu\n", pHttpGetReq->CompleteStatus, AnscGetTickInSeconds())); break; } } /* AnscResetEvent (&pHttpGetReq->CompleteEvent); */ AnscFreeEvent(&pHttpGetReq->CompleteEvent); CcspTr069PaFreeMemory(pHttpReqInfo); if ( pHttpGetReq->CompleteStatus != ANSC_STATUS_SUCCESS ) { if ( pHttpGetReq->CompleteStatus == ANSC_STATUS_RESET_SESSION ) { goto REDIRECTED; } else { returnStatus = pHttpGetReq->CompleteStatus; goto EXIT; } } else if( pHttpGetReq->bUnauthorized) { returnStatus = ANSC_STATUS_FAILURE; if( pCcspCwmpStatIf) { pCcspCwmpStatIf->IncTcpFailure(pCcspCwmpStatIf->hOwnerContext); } goto EXIT; } REDIRECTED: if( pHttpGetReq->bIsRedirect) { if( _ansc_strstr((PCHAR)pHttpGetReq->pContent, "http") == pHttpGetReq->pContent) { if ( pMyObject->AcsUrl ) CcspTr069PaFreeMemory(pMyObject->AcsUrl); pMyObject->AcsUrl = CcspTr069PaCloneString(pHttpGetReq->pContent); } else { /* if it's partial path */ pTempString = _ansc_strstr(pRequestURL, "//"); if( pTempString == NULL) { returnStatus = ANSC_STATUS_FAILURE; goto EXIT; } pTempString += AnscSizeOfString("//"); pTempString = _ansc_strstr(pTempString, "/"); if( pTempString == NULL) { returnStatus = ANSC_STATUS_FAILURE; goto EXIT; } AnscCopyMemory(pNewUrl, pRequestURL, (ULONG)(pTempString - pRequestURL)); AnscCatString(pNewUrl, (PCHAR)pHttpGetReq->pContent); if ( pMyObject->AcsUrl ) CcspTr069PaFreeMemory(pMyObject->AcsUrl); pMyObject->AcsUrl = CcspTr069PaCloneString(pNewUrl); } uRedirect ++; if( uRedirect >= uMaxRedirect) { CcspTr069PaTraceDebug(("Maximum Redirection reached. Give up!\n")); returnStatus = ANSC_STATUS_FAILURE; goto EXIT; } else { CcspTr069PaTraceDebug(("Acs connection redirection #%u: '%s'\n", (unsigned int)uRedirect, pMyObject->AcsUrl)); /* in case redirected ACS challenges CPE again */ nMaxAuthRetries = 2; /* tear down current HTTP session before redirecting to new ACS, * otherwise, there might be case that ACS sends out redirection * response and immediately closes the socket, CWMP may be * confused by closing CWMP session prematurely. */ pHttpClient->DelAllWcsos((ANSC_HANDLE)pHttpClient); goto START; } } if(pWmpSession != NULL) { if( pHttpGetReq->ulContentSize > 0 && pHttpGetReq->pContent != NULL) { CcspTr069PaTraceDebug(("Response:\n%s\n", (char*)pHttpGetReq->pContent)); returnStatus = pWmpSession->RecvSoapMessage ( pWmpSession, (PCHAR)pHttpGetReq->pContent ); } else { CcspTr069PaTraceDebug(("Response: <EMPTY>\n")); returnStatus = pCcspCwmpMcoIf->NotifyAcsStatus ( pCcspCwmpMcoIf->hOwnerContext, TRUE, /* no more requests */ FALSE ); } } EXIT: if(pHttpGetReq->pContent != NULL) { CcspTr069PaFreeMemory(pHttpGetReq->pContent); pHttpGetReq->pContent = NULL; } /****************************************************************** GRACEFUL ROLLBACK PROCEDURES AND EXIT DOORS ******************************************************************/ return returnStatus; }