/********************************************************************** prototype: ANSC_STATUS CcspCwmpAcscoConnect ( ANSC_HANDLE hThisObject ); description: This function is called to connect to ACS. argument: ANSC_HANDLE hThisObject The caller object. return: the status of the operation; **********************************************************************/ ANSC_STATUS CcspCwmpAcscoConnect ( ANSC_HANDLE hThisObject ) { PCCSP_CWMP_ACS_CONNECTION_OBJECT pMyObject = (PCCSP_CWMP_ACS_CONNECTION_OBJECT)hThisObject; PHTTP_SIMPLE_CLIENT_OBJECT pHttpClient = (PHTTP_SIMPLE_CLIENT_OBJECT)pMyObject->hHttpSimpleClient; ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; PCCSP_CWMP_SESSION_OBJECT pWmpSession = (PCCSP_CWMP_SESSION_OBJECT )pMyObject->hCcspCwmpSession; if ( pWmpSession ) { PCCSP_CWMP_CPE_CONTROLLER_OBJECT pCcspCwmpCpeController = (PCCSP_CWMP_CPE_CONTROLLER_OBJECT)pWmpSession->hCcspCwmpCpeController; if ( pCcspCwmpCpeController ) { PCCSP_CWMP_CFG_INTERFACE pCcspCwmpCfgIf = (PCCSP_CWMP_CFG_INTERFACE)pCcspCwmpCpeController->hCcspCwmpCfgIf; PHTTP_SIMPLE_CLIENT_OBJECT pHttpClient = (PHTTP_SIMPLE_CLIENT_OBJECT)pMyObject->hHttpSimpleClient; ULONG ulSessionIdleTimeout = 0; if ( pCcspCwmpCfgIf && pCcspCwmpCfgIf->GetHttpSessionIdleTimeout ) { ulSessionIdleTimeout = pCcspCwmpCfgIf->GetHttpSessionIdleTimeout(pCcspCwmpCfgIf->hOwnerContext); } pHttpClient->SetSessionIdleTimeout((ANSC_HANDLE)pHttpClient, ulSessionIdleTimeout); // fprintf(stderr, "<RT> %s: OutboundIfName = '%s'\n", __FUNCTION__, pCcspCwmpCpeController->OutboundIfName ? pCcspCwmpCpeController->OutboundIfName : "NULL"); if ( pCcspCwmpCpeController->OutboundIfName && pCcspCwmpCpeController->OutboundIfName[0] && AnscSizeOfString(pCcspCwmpCpeController->OutboundIfName) < HTTP_MAX_DEVICE_NAME_SIZE) { AnscCopyString(pHttpClient->Property.BindToDevice.DeviceName, pCcspCwmpCpeController->OutboundIfName); } else { pHttpClient->Property.BindToDevice.DeviceName[0] = '\0'; } } } if( pMyObject->AcsUrl == NULL || AnscSizeOfString(pMyObject->AcsUrl) <= 10) { return ANSC_STATUS_NOT_READY; } returnStatus = pHttpClient->Engage ((ANSC_HANDLE)pHttpClient); if( returnStatus == ANSC_STATUS_SUCCESS) { pMyObject->bActive = TRUE; } return returnStatus; }
ANSC_STATUS HttpWcsoReturn ( ANSC_HANDLE hThisObject ) { ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; PHTTP_WEBC_SESSION_OBJECT pMyObject = (PHTTP_WEBC_SESSION_OBJECT )hThisObject; PHTTP_SIMPLE_CLIENT_OBJECT pSimpleClient = (PHTTP_SIMPLE_CLIENT_OBJECT)pMyObject->hOwnerContext; returnStatus = pSimpleClient->ReleaseWcso ( (ANSC_HANDLE)pSimpleClient, (ANSC_HANDLE)pMyObject ); return returnStatus; }
/********************************************************************** prototype: ANSC_STATUS CcspCwmpAcscoClose ( ANSC_HANDLE hThisObject ); description: This function is called to close the connection to ACS argument: ANSC_HANDLE hThisObject The caller object. return: the status of the operation; **********************************************************************/ ANSC_STATUS CcspCwmpAcscoClose ( ANSC_HANDLE hThisObject ) { PCCSP_CWMP_ACS_CONNECTION_OBJECT pMyObject = (PCCSP_CWMP_ACS_CONNECTION_OBJECT)hThisObject; PHTTP_SIMPLE_CLIENT_OBJECT pHttpClient = (PHTTP_SIMPLE_CLIENT_OBJECT)pMyObject->hHttpSimpleClient; ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; returnStatus = pHttpClient->Cancel((ANSC_HANDLE)pHttpClient); /* pMyObject->RemoveCookies((ANSC_HANDLE)pMyObject); */ pMyObject->bActive = FALSE; return returnStatus; }
ANSC_HANDLE HttpWcsoAddNewWcto ( ANSC_HANDLE hThisObject ) { ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; PHTTP_WEBC_SESSION_OBJECT pMyObject = (PHTTP_WEBC_SESSION_OBJECT )hThisObject; PHTTP_WEBC_SESSION_PROPERTY pProperty = (PHTTP_WEBC_SESSION_PROPERTY )&pMyObject->Property; PHTTP_SIMPLE_CLIENT_OBJECT pSimpleClient = (PHTTP_SIMPLE_CLIENT_OBJECT )pMyObject->hOwnerContext; PANSC_SIMPLE_CLIENT_TCP_OBJECT pTcpSimpleClient = (PANSC_SIMPLE_CLIENT_TCP_OBJECT)pMyObject->hTcpSimpleClient; PHTTP_BSP_INTERFACE pBspIf = (PHTTP_BSP_INTERFACE )pMyObject->hBspIf; PHTTP_HFP_INTERFACE pHfpIf = (PHTTP_HFP_INTERFACE )pMyObject->hHfpIf; PHTTP_WEBC_TRANS_OBJECT pWebcTrans = NULL; pWebcTrans = (PHTTP_WEBC_TRANS_OBJECT)pSimpleClient->AcquireWcto((ANSC_HANDLE)pSimpleClient); if ( !pWebcTrans ) { return (ANSC_HANDLE)NULL; } else { pWebcTrans->SetBspIf ((ANSC_HANDLE)pWebcTrans, (ANSC_HANDLE)pBspIf ); pWebcTrans->SetHfpIf ((ANSC_HANDLE)pWebcTrans, (ANSC_HANDLE)pHfpIf ); pWebcTrans->SetWebcSession ((ANSC_HANDLE)pWebcTrans, (ANSC_HANDLE)pMyObject ); pWebcTrans->SetTcpSimpleClient((ANSC_HANDLE)pWebcTrans, (ANSC_HANDLE)pTcpSimpleClient); pWebcTrans->SetTransState ((ANSC_HANDLE)pWebcTrans, HTTP_WCTO_STATE_INITIALIZED ); pWebcTrans->Open ((ANSC_HANDLE)pWebcTrans); } AnscAcquireLock(&pMyObject->WctoSListLock); AnscSListPushEntry(&pMyObject->WctoSList, &pWebcTrans->Linkage); pWebcTrans->AcquireAccess((ANSC_HANDLE)pWebcTrans); AnscReleaseLock(&pMyObject->WctoSListLock); return (ANSC_HANDLE)pWebcTrans; }
ANSC_HANDLE HttpScoAddWcso ( ANSC_HANDLE hThisObject, char* host, USHORT port, ANSC_HANDLE hReqContext, BOOL bUseTls ) { ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; PHTTP_SIMPLE_CLIENT_OBJECT pMyObject = (PHTTP_SIMPLE_CLIENT_OBJECT )hThisObject; PHTTP_SIMPLE_CLIENT_PROPERTY pProperty = (PHTTP_SIMPLE_CLIENT_PROPERTY)&pMyObject->Property; PHTTP_BSP_INTERFACE pBspIf = (PHTTP_BSP_INTERFACE )pMyObject->hBspIf; PHTTP_HFP_INTERFACE pHfpIf = (PHTTP_HFP_INTERFACE )pMyObject->hHfpIf; PHTTP_WEBC_SESSION_OBJECT pWebcSession = (PHTTP_WEBC_SESSION_OBJECT )pMyObject->AcquireWcso((ANSC_HANDLE)pMyObject); ULONG ulHashIndex = AnscHashString2(host, AnscSizeOfString(host), HTTP_SCO_WCSO_TABLE_SIZE); if ( !pWebcSession ) { AnscTrace("HttpScoAddWcso - can't acquire web client session object!\n"); return (ANSC_HANDLE)NULL; } else { ULONG ulWebcSessionMode = bUseTls? HTTP_WCSO_FLAG_tlsEnabled : 0; if ( pMyObject->ClientMode & HTTP_SCO_MODE_XSOCKET ) { ulWebcSessionMode |= HTTP_WCSO_FLAG_xsocketEnabled; } if ( pMyObject->ClientMode & HTTP_SCO_MODE_NOTIFY_ON_ALL_CONN_ONCE ) { ulWebcSessionMode |= HTTP_WCSO_FLAG_BspNotifyOnAllConnOnce; } pWebcSession->hBspReqContext = hReqContext; pWebcSession->Timestamp = AnscGetTickInSeconds(); pWebcSession->HashIndex = ulHashIndex; pWebcSession->SetPeerName ((ANSC_HANDLE)pWebcSession, host ); pWebcSession->SetPeerPort ((ANSC_HANDLE)pWebcSession, port ); pWebcSession->SetHostPort ((ANSC_HANDLE)pWebcSession, 0 ); pWebcSession->SetSessionFlags((ANSC_HANDLE)pWebcSession, ulWebcSessionMode ); pWebcSession->SetBspIf ((ANSC_HANDLE)pWebcSession, (ANSC_HANDLE)pBspIf); pWebcSession->SetHfpIf ((ANSC_HANDLE)pWebcSession, (ANSC_HANDLE)pHfpIf); } returnStatus = pWebcSession->Open((ANSC_HANDLE)pWebcSession); if ( returnStatus != ANSC_STATUS_SUCCESS ) { pWebcSession->Return((ANSC_HANDLE)pWebcSession); return (ANSC_HANDLE)NULL; } AnscAcquireLock (&pMyObject->WcsoTableLock); AnscSListPushEntry(&pMyObject->WcsoTable[ulHashIndex], &pWebcSession->Linkage); pWebcSession->AcquireAccess((ANSC_HANDLE)pWebcSession); AnscReleaseLock (&pMyObject->WcsoTableLock); return (ANSC_HANDLE)pWebcSession; }
ANSC_HANDLE HttpScoMapWcso ( ANSC_HANDLE hThisObject, char* host, USHORT port, ANSC_HANDLE hReqContext, BOOL bUseTls ) { ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; PHTTP_SIMPLE_CLIENT_OBJECT pMyObject = (PHTTP_SIMPLE_CLIENT_OBJECT )hThisObject; PHTTP_SIMPLE_CLIENT_PROPERTY pProperty = (PHTTP_SIMPLE_CLIENT_PROPERTY)&pMyObject->Property; PHTTP_WEBC_SESSION_OBJECT pWebcSession = NULL; PSINGLE_LINK_ENTRY pSLinkEntry = NULL; ULONG ulHashIndex = AnscHashString2(host, AnscSizeOfString(host), HTTP_SCO_WCSO_TABLE_SIZE); ULONG ulClientMode = pMyObject->ClientMode; ULONG ulSessFlags; AnscAcquireLock(&pMyObject->WcsoTableLock); pSLinkEntry = AnscSListGetFirstEntry(&pMyObject->WcsoTable[ulHashIndex]); while ( pSLinkEntry ) { pWebcSession = ACCESS_HTTP_WEBC_SESSION_OBJECT(pSLinkEntry); pSLinkEntry = AnscSListGetNextEntry(pSLinkEntry); if ( pWebcSession->bRemoveMe ) { continue; } ulSessFlags = bUseTls? HTTP_WCSO_FLAG_tlsEnabled : 0; if ( pMyObject->ClientMode & HTTP_SCO_MODE_XSOCKET ) { ulSessFlags |= HTTP_WCSO_FLAG_xsocketEnabled; } if ( pMyObject->ClientMode & HTTP_SCO_MODE_NOTIFY_ON_ALL_CONN_ONCE ) { ulSessFlags |= HTTP_WCSO_FLAG_BspNotifyOnAllConnOnce; } if ( pWebcSession->MatchServer ( (ANSC_HANDLE)pWebcSession, host, port, ulSessFlags ) ) { pWebcSession->AcquireAccess((ANSC_HANDLE)pWebcSession); if ( pWebcSession->IsReadyToRequest((ANSC_HANDLE)pWebcSession) ) { ANSC_IPV4_ADDRESS ipAddr; AnscReleaseLock(&pMyObject->WcsoTableLock); ipAddr.Value = pMyObject->GetCurPeerAddr((ANSC_HANDLE)pMyObject); if ( ipAddr.Value != 0 ) { pMyObject->ResetPeerAddrPick((ANSC_HANDLE)pMyObject, ipAddr.Value); } return (ANSC_HANDLE)pWebcSession; } else { pWebcSession->ReleaseAccess((ANSC_HANDLE)pWebcSession); } } } AnscReleaseLock(&pMyObject->WcsoTableLock); return pMyObject->AddWcso ( (ANSC_HANDLE)pMyObject, host, port, hReqContext, bUseTls ); }
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 CcspCwmpAcscoEnrollObjects ( ANSC_HANDLE hThisObject ) { ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; PCCSP_CWMP_ACS_CONNECTION_OBJECT pMyObject = (PCCSP_CWMP_ACS_CONNECTION_OBJECT)hThisObject; PHTTP_BSP_INTERFACE pHttpBspIf = (PHTTP_BSP_INTERFACE )pMyObject->hHttpBspIf; PHTTP_ACM_INTERFACE pHttpAcmIf = (PHTTP_ACM_INTERFACE )pMyObject->hHttpAcmIf; PHTTP_SIMPLE_CLIENT_OBJECT pHttpClient = (PHTTP_SIMPLE_CLIENT_OBJECT)NULL; PHTTP_HFP_INTERFACE pHttpHfpIf = (PHTTP_HFP_INTERFACE)NULL; if ( !pHttpBspIf ) { pHttpBspIf = (PHTTP_BSP_INTERFACE)CcspTr069PaAllocateMemory(sizeof(HTTP_BSP_INTERFACE)); if ( !pHttpBspIf ) { return ANSC_STATUS_RESOURCES; } else { pMyObject->hHttpBspIf = (ANSC_HANDLE)pHttpBspIf; } AnscCopyString(pHttpBspIf->Name, HTTP_BSP_INTERFACE_NAME); pHttpBspIf->InterfaceId = HTTP_BSP_INTERFACE_ID; pHttpBspIf->hOwnerContext = (ANSC_HANDLE)pMyObject; pHttpBspIf->Size = sizeof(HTTP_BSP_INTERFACE); pHttpBspIf->Polish = CcspCwmpAcscoHttpBspPolish; pHttpBspIf->Browse = CcspCwmpAcscoHttpBspBrowse; pHttpBspIf->Notify = CcspCwmpAcscoHttpBspNotify; } if ( !pHttpAcmIf ) { pHttpAcmIf = (PHTTP_ACM_INTERFACE)CcspTr069PaAllocateMemory(sizeof(HTTP_ACM_INTERFACE)); if ( !pHttpAcmIf ) { return ANSC_STATUS_RESOURCES; } else { pMyObject->hHttpAcmIf = (ANSC_HANDLE)pHttpAcmIf; } pHttpAcmIf->hOwnerContext = (ANSC_HANDLE)pMyObject; pHttpAcmIf->Size = sizeof(HTTP_ACM_INTERFACE); pHttpAcmIf->GetCredential = CcspCwmpAcscoHttpGetCredential; } /* * Create Http Simple Client */ pHttpClient = (PHTTP_SIMPLE_CLIENT_OBJECT)HttpCreateSimpleClient ( (ANSC_HANDLE)pMyObject->hHttpHelpContainer, (ANSC_HANDLE)pMyObject, (ANSC_HANDLE)NULL ); if( pHttpClient == NULL) { return ANSC_STATUS_RESOURCES; } pHttpClient->SetProductName(pHttpClient, "HTTP Client V1.0"); pHttpClient->SetBspIf((ANSC_HANDLE)pHttpClient, pMyObject->hHttpBspIf); pHttpClient->SetClientMode(pHttpClient, HTTP_SCO_MODE_XSOCKET | HTTP_SCO_MODE_COMPACT | HTTP_SCO_MODE_NOTIFY_ON_ALL_CONN_ONCE); pMyObject->hHttpSimpleClient = (ANSC_HANDLE)pHttpClient; AnscCoEnrollObjects((ANSC_HANDLE)pMyObject); return ANSC_STATUS_SUCCESS; }
ANSC_STATUS CcspCwmpAcscoRemove ( ANSC_HANDLE hThisObject ) { ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; PCCSP_CWMP_ACS_CONNECTION_OBJECT pMyObject = (PCCSP_CWMP_ACS_CONNECTION_OBJECT)hThisObject; PHTTP_BSP_INTERFACE pHttpBspIf = (PHTTP_BSP_INTERFACE )pMyObject->hHttpBspIf; PHTTP_ACM_INTERFACE pHttpAcmIf = (PHTTP_ACM_INTERFACE )pMyObject->hHttpAcmIf; PHTTP_SIMPLE_CLIENT_OBJECT pHttpClient = (PHTTP_SIMPLE_CLIENT_OBJECT)pMyObject->hHttpSimpleClient; pMyObject->Reset((ANSC_HANDLE)pMyObject); pMyObject->RemoveCookies(hThisObject); if( pMyObject->AcsUrl != NULL) { CcspTr069PaFreeMemory(pMyObject->AcsUrl); pMyObject->AcsUrl = NULL; } if( pMyObject->Username != NULL) { CcspTr069PaFreeMemory(pMyObject->Username); pMyObject->Username = NULL; } if( pMyObject->Password != NULL) { CcspTr069PaFreeMemory(pMyObject->Password); pMyObject->Password = NULL; } if ( pMyObject->AuthHeaderValue ) { CcspTr069PaFreeMemory(pMyObject->AuthHeaderValue); pMyObject->AuthHeaderValue = NULL; } if ( pHttpBspIf ) { CcspTr069PaFreeMemory(pHttpBspIf); pMyObject->hHttpBspIf = (ANSC_HANDLE)NULL; } if ( pHttpAcmIf ) { CcspTr069PaFreeMemory(pHttpAcmIf); pMyObject->hHttpAcmIf = (ANSC_HANDLE)NULL; } if( pHttpClient != NULL) { pHttpClient->Remove(pHttpClient); } AnscCoRemove((ANSC_HANDLE)pMyObject); return ANSC_STATUS_SUCCESS; }
ANSC_STATUS HttpWcsoConnect ( ANSC_HANDLE hThisObject ) { ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; PHTTP_WEBC_SESSION_OBJECT pMyObject = (PHTTP_WEBC_SESSION_OBJECT )hThisObject; PHTTP_WEBC_SESSION_PROPERTY pProperty = (PHTTP_WEBC_SESSION_PROPERTY )&pMyObject->Property; PHTTP_BSP_INTERFACE pBspIf = (PHTTP_BSP_INTERFACE )pMyObject->hBspIf; PANSC_SIMPLE_CLIENT_TCP_OBJECT pTcpSimpleClient = (PANSC_SIMPLE_CLIENT_TCP_OBJECT)pMyObject->hTcpSimpleClient; PHTTP_SIMPLE_CLIENT_OBJECT pHttpSco = (PHTTP_SIMPLE_CLIENT_OBJECT )pMyObject->hOwnerContext; ULONG ulSctoMode = ANSC_SCTO_MODE_FOREIGN_BUFFER; PANSC_BUFFER_DESCRIPTOR pBufferDesp = NULL; HTTP_SCO_HOST_ADDRESSES PeerAddr; BOOL bSameAddresses = FALSE; ANSC_IPV4_ADDRESS ipAddr = {1,1,1,1}; AnscStartupXsocketWrapper((ANSC_HANDLE)pMyObject); AnscZeroMemory(&PeerAddr, sizeof(HTTP_SCO_HOST_ADDRESSES)); PeerAddr.NumPeers = HTTP_SCO_MAX_RESOLVED_HOST; if ( pProperty->SessionFlags & HTTP_WCSO_FLAG_xsocketEnabled ) { XsktResolveHostName2(pProperty->PeerName, ((PULONG)PeerAddr.PeerAddresses), (PeerAddr.NumPeers)); } else { AnscResolveHostName2(pProperty->PeerName, ((PULONG)PeerAddr.PeerAddresses), (PeerAddr.NumPeers)); } #ifndef _ANSC_IPV6_COMPATIBLE_ if ( PeerAddr.NumPeers == 0 ) { returnStatus = pBspIf->Notify ( pBspIf->hOwnerContext, HTTP_BSP_EVENT_CANNOT_RESOLVE_NAME, 0, pMyObject->hBspReqContext, NULL, NULL ); pMyObject->SessionState = HTTP_WCSO_STATE_FINISHED; return ANSC_STATUS_BAD_NAME; } else { pHttpSco->SetPeerAddresses((ANSC_HANDLE)pHttpSco, (ANSC_HANDLE)&PeerAddr, &bSameAddresses); if ( bSameAddresses ) { ipAddr.Value = pHttpSco->GetCurPeerAddr((ANSC_HANDLE)pHttpSco); pHttpSco->ResetPeerAddrPick((ANSC_HANDLE)pHttpSco, ipAddr.Value); } else { pHttpSco->GetNextPeerAddr((ANSC_HANDLE)pHttpSco, &ipAddr.Value); } } #endif returnStatus = pMyObject->ConnectPeer((ANSC_HANDLE)pMyObject, ipAddr.Value); if ( returnStatus != ANSC_STATUS_SUCCESS ) { pMyObject->ConnectionFailed((ANSC_HANDLE)pMyObject); pMyObject->SessionState = HTTP_WCSO_STATE_FINISHED; return ANSC_STATUS_FAILURE; } return returnStatus; }
ANSC_STATUS HttpWcsoConnectPeer ( ANSC_HANDLE hThisObject, ULONG ipAddrToConnect ) { ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; PHTTP_WEBC_SESSION_OBJECT pMyObject = (PHTTP_WEBC_SESSION_OBJECT )hThisObject; PHTTP_WEBC_SESSION_PROPERTY pProperty = (PHTTP_WEBC_SESSION_PROPERTY )&pMyObject->Property; PHTTP_BSP_INTERFACE pBspIf = (PHTTP_BSP_INTERFACE )pMyObject->hBspIf; PANSC_SIMPLE_CLIENT_TCP_OBJECT pTcpSimpleClient = (PANSC_SIMPLE_CLIENT_TCP_OBJECT)pMyObject->hTcpSimpleClient; PHTTP_SIMPLE_CLIENT_OBJECT pHttpSco = (PHTTP_SIMPLE_CLIENT_OBJECT )pMyObject->hOwnerContext; ULONG ulSctoMode = ANSC_SCTO_MODE_FOREIGN_BUFFER; PANSC_BUFFER_DESCRIPTOR pBufferDesp = NULL; BOOL bGotPeerAddr = TRUE; ANSC_IPV4_ADDRESS PeerAddr; PANSC_BUFFER_DESCRIPTOR pRecvBdo = (ANSC_HANDLE)NULL; ULONG ipAddr = ipAddrToConnect; TRY_NEXT: if ( ipAddr == 0 ) { goto NO_MORE_TRY; } PeerAddr.Value = ipAddr; pRecvBdo = (PANSC_BUFFER_DESCRIPTOR)pTcpSimpleClient->GetBufferContext((ANSC_HANDLE)pTcpSimpleClient); pTcpSimpleClient->SetBufferContext((ANSC_HANDLE)pTcpSimpleClient, NULL, 0, NULL); if ( pRecvBdo ) { AnscReleaseBdo(pRecvBdo); pRecvBdo = NULL; } returnStatus = pTcpSimpleClient->Cancel((ANSC_HANDLE)pTcpSimpleClient); if ( pProperty->SessionFlags & HTTP_WCSO_FLAG_tlsEnabled ) { ulSctoMode |= ANSC_SCTO_MODE_TLS_ENABLED; } if ( pProperty->SessionFlags & HTTP_WCSO_FLAG_xsocketEnabled ) { ulSctoMode |= ANSC_SCTO_MODE_XSOCKET; } pTcpSimpleClient->SetHostAddress ((ANSC_HANDLE)pTcpSimpleClient, pProperty->HostAddr.Dot ); pTcpSimpleClient->SetHostPort ((ANSC_HANDLE)pTcpSimpleClient, pProperty->HostPort ); pTcpSimpleClient->SetPeerName ((ANSC_HANDLE)pTcpSimpleClient, pProperty->PeerName ); pTcpSimpleClient->SetPeerAddress ((ANSC_HANDLE)pTcpSimpleClient, PeerAddr.Dot ); pTcpSimpleClient->SetPeerPort ((ANSC_HANDLE)pTcpSimpleClient, pProperty->PeerPort ); pTcpSimpleClient->SetMaxMessageSize((ANSC_HANDLE)pTcpSimpleClient, HTTP_WCSO_MAX_MESSAGE_SIZE); pTcpSimpleClient->SetMode ((ANSC_HANDLE)pTcpSimpleClient, ulSctoMode ); // fprintf(stderr, "<RT> %s: HTTP Client DeviceName = '%s'\n", __FUNCTION__, pHttpSco ? pHttpSco->Property.BindToDevice.DeviceName : "NULL"); if( pHttpSco && pHttpSco->Property.BindToDevice.DeviceName[0] && AnscSizeOfString(pHttpSco->Property.BindToDevice.DeviceName) < ANSC_OBJ_IF_NAME_SIZE) { pTcpSimpleClient->SetSocketBindToDevice ((ANSC_HANDLE)pTcpSimpleClient, TRUE); pTcpSimpleClient->SetSocketDeviceName ((ANSC_HANDLE)pTcpSimpleClient, pHttpSco->Property.BindToDevice.DeviceName); } else { pTcpSimpleClient->SetSocketBindToDevice ((ANSC_HANDLE)pTcpSimpleClient, FALSE); pTcpSimpleClient->SetSocketDeviceName ((ANSC_HANDLE)pTcpSimpleClient, ""); } returnStatus = pTcpSimpleClient->Engage((ANSC_HANDLE)pTcpSimpleClient); NO_MORE_TRY: if ( returnStatus != ANSC_STATUS_SUCCESS ) { if ( bGotPeerAddr ) { BOOL bSucc = FALSE; bSucc = pHttpSco->GetNextPeerAddr((ANSC_HANDLE)pHttpSco, &ipAddr); if ( bSucc && ipAddr != 0 ) { pMyObject->SessionState = HTTP_WCSO_STATE_INITIALIZED; goto TRY_NEXT; } } return ANSC_STATUS_FAILURE; } else { pMyObject->SessionState = HTTP_WCSO_STATE_SERVER_CONNECTED; } pBufferDesp = (PANSC_BUFFER_DESCRIPTOR)AnscAllocateBdo ( HTTP_WCSO_MAX_MESSAGE_SIZE, 0, 0 ); if ( pBufferDesp ) { pTcpSimpleClient->SetBufferContext ( (ANSC_HANDLE)pTcpSimpleClient, AnscBdoGetEndOfBlock(pBufferDesp), AnscBdoGetLeftSize (pBufferDesp), (ANSC_HANDLE)pBufferDesp ); } return returnStatus; }
ANSC_STATUS HttpScoInitialize ( ANSC_HANDLE hThisObject ) { ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; PHTTP_SIMPLE_CLIENT_OBJECT pMyObject = (PHTTP_SIMPLE_CLIENT_OBJECT)hThisObject; ULONG i = 0; /* * Until you have to simulate C++ object-oriented programming style with standard C, you don't * appreciate all the nice little things come with C++ language and all the dirty works that * have been done by the C++ compilers. Member initialization is one of these things. While in * C++ you don't have to initialize all the member fields inherited from the base class since * the compiler will do it for you, such is not the case with C. */ AnscCoInitialize((ANSC_HANDLE)pMyObject); /* * Although we have initialized some of the member fields in the "create" member function, we * repeat the work here for completeness. While this simulation approach is pretty stupid from * a C++/Java programmer perspective, it's the best we can get for universal embedded network * programming. Before we develop our own operating system (don't expect that to happen any * time soon), this is the way things gonna be. */ pMyObject->Oid = HTTP_SIMPLE_CLIENT_OID; pMyObject->Create = HttpScoCreate; pMyObject->Remove = HttpScoRemove; pMyObject->EnrollObjects = HttpScoEnrollObjects; pMyObject->Initialize = HttpScoInitialize; pMyObject->ClientMode = HTTP_SCO_MODE_COMPACT; pMyObject->bActive = FALSE; pMyObject->hWebClientSession = NULL; pMyObject->SessionIdleTimeout = 0; pMyObject->GetBspIf = HttpScoGetBspIf; pMyObject->SetBspIf = HttpScoSetBspIf; pMyObject->GetHfpIf = HttpScoGetHfpIf; pMyObject->SetHfpIf = HttpScoSetHfpIf; pMyObject->GetCasIf = HttpScoGetCasIf; pMyObject->GetClientAuthObj = HttpScoGetClientAuthObj; pMyObject->GetClientMode = HttpScoGetClientMode; pMyObject->SetClientMode = HttpScoSetClientMode; pMyObject->GetProductName = HttpScoGetProductName; pMyObject->SetProductName = HttpScoSetProductName; pMyObject->SetSessionIdleTimeout = HttpScoSetSessionIdleTimeout; pMyObject->GetProperty = HttpScoGetProperty; pMyObject->SetProperty = HttpScoSetProperty; pMyObject->ResetProperty = HttpScoResetProperty; pMyObject->Reset = HttpScoReset; pMyObject->GetCredential = HttpScoGetCredential; pMyObject->Engage = HttpScoEngage; pMyObject->Cancel = HttpScoCancel; pMyObject->SessionTdoInvoke = HttpScoSessionTdoInvoke; pMyObject->AcquireWcso = HttpScoAcquireWcso; pMyObject->ReleaseWcso = HttpScoReleaseWcso; pMyObject->ManufactureWcsoPool = HttpScoManufactureWcsoPool; pMyObject->DestroyWcsoPool = HttpScoDestroyWcsoPool; pMyObject->AcquireWcto = HttpScoAcquireWcto; pMyObject->ReleaseWcto = HttpScoReleaseWcto; pMyObject->ManufactureWctoPool = HttpScoManufactureWctoPool; pMyObject->DestroyWctoPool = HttpScoDestroyWctoPool; pMyObject->AcquireBmoReq = HttpScoAcquireBmoReq; pMyObject->ReleaseBmoReq = HttpScoReleaseBmoReq; pMyObject->ManufactureBmoReqPool = HttpScoManufactureBmoReqPool; pMyObject->DestroyBmoReqPool = HttpScoDestroyBmoReqPool; pMyObject->AcquireBmoRep = HttpScoAcquireBmoRep; pMyObject->ReleaseBmoRep = HttpScoReleaseBmoRep; pMyObject->ManufactureBmoRepPool = HttpScoManufactureBmoRepPool; pMyObject->DestroyBmoRepPool = HttpScoDestroyBmoRepPool; pMyObject->Request = HttpScoRequest; pMyObject->Request2 = HttpScoRequest2; pMyObject->Request3 = HttpScoRequest3; pMyObject->DoOptions = HttpScoDoOptions; pMyObject->DoGet = HttpScoDoGet; pMyObject->DoHead = HttpScoDoHead; pMyObject->DoPost = HttpScoDoPost; pMyObject->DoPut = HttpScoDoPut; pMyObject->DoDelete = HttpScoDoDelete; pMyObject->DoTrace = HttpScoDoTrace; pMyObject->DoConnect = HttpScoDoConnect; pMyObject->MapWcso = HttpScoMapWcso; pMyObject->GetWcso = HttpScoGetWcso; pMyObject->AddWcso = HttpScoAddWcso; pMyObject->DelAllWcsos = HttpScoDelAllWcsos; pMyObject->BspPolish = HttpScoBspPolish; pMyObject->BspBrowse = HttpScoBspBrowse; pMyObject->BspNotify = HttpScoBspNotify; pMyObject->SetPeerAddresses = HttpScoSetPeerAddresses; pMyObject->GetNextPeerAddr = HttpScoGetNextPeerAddr; pMyObject->GetCurPeerAddr = HttpScoGetCurPeerAddr; pMyObject->ResetPeerAddrPick = HttpScoResetPeerAddrPick; for ( i = 0; i < HTTP_SCO_WCSO_TABLE_SIZE; i++ ) { AnscSListInitializeHeader(&pMyObject->WcsoTable[i]); } AnscInitializeLock(&pMyObject->WcsoTableLock); AnscSListInitializeHeader(&pMyObject->WcsoSList ); AnscInitializeLock (&pMyObject->WcsoSListLock ); AnscSListInitializeHeader(&pMyObject->WctoSList ); AnscInitializeLock (&pMyObject->WctoSListLock ); AnscSListInitializeHeader(&pMyObject->BmoReqSList ); AnscInitializeLock (&pMyObject->BmoReqSListLock); AnscSListInitializeHeader(&pMyObject->BmoRepSList ); AnscInitializeLock (&pMyObject->BmoRepSListLock); /* * We shall initialize the configuration properties to the default values, which may be changed * later via the set_property() member function. Note that this call may not guarantee a valid * and legtimate configuration. */ pMyObject->ResetProperty((ANSC_HANDLE)pMyObject); return ANSC_STATUS_SUCCESS; }
ANSC_STATUS HttpScoRemove ( ANSC_HANDLE hThisObject ) { ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; PHTTP_SIMPLE_CLIENT_OBJECT pMyObject = (PHTTP_SIMPLE_CLIENT_OBJECT )hThisObject; PHTTP_BSP_INTERFACE pBspIf = (PHTTP_BSP_INTERFACE )pMyObject->hBspIf; PHTTP_HFP_INTERFACE pHfpIf = (PHTTP_HFP_INTERFACE )pMyObject->hHfpIf; PHTTP_CAS_INTERFACE pCasIf = (PHTTP_CAS_INTERFACE )pMyObject->hCasIf; PANSC_TIMER_DESCRIPTOR_OBJECT pSessionTdo = (PANSC_TIMER_DESCRIPTOR_OBJECT)pMyObject->hSessionTdo; PANSC_TDO_CLIENT_OBJECT pSessionTdoClient = (PANSC_TDO_CLIENT_OBJECT )pMyObject->hSessionTdoClient; PHTTP_AUTH_CLIENT_OBJECT pClientAuthObj = (PHTTP_AUTH_CLIENT_OBJECT )pMyObject->hClientAuthObj; PHTTP_ACM_INTERFACE pAcmIf = (PHTTP_ACM_INTERFACE )pMyObject->hAcmIf; pMyObject->Cancel((ANSC_HANDLE)pMyObject); pMyObject->Reset ((ANSC_HANDLE)pMyObject); if ( pBspIf ) { AnscFreeMemory(pBspIf); } if ( pHfpIf ) { AnscFreeMemory(pHfpIf); } if ( pCasIf ) { AnscFreeMemory(pCasIf); } if ( pSessionTdo ) { pSessionTdo->Remove((ANSC_HANDLE)pSessionTdo); } if ( pSessionTdoClient ) { AnscFreeMemory(pSessionTdoClient); } if ( pClientAuthObj ) { pClientAuthObj->Remove((ANSC_HANDLE)pClientAuthObj); } if ( pAcmIf ) { AnscFreeMemory(pAcmIf); } if ( pMyObject->pAuthUserName ) { AnscFreeMemory(pMyObject->pAuthUserName); } if ( pMyObject->pAuthPassword ) { AnscFreeMemory(pMyObject->pAuthPassword); } AnscFreeLock(&pMyObject->WcsoTableLock ); AnscFreeLock(&pMyObject->WcsoSListLock ); AnscFreeLock(&pMyObject->WctoSListLock ); AnscFreeLock(&pMyObject->BmoReqSListLock); AnscFreeLock(&pMyObject->BmoRepSListLock); AnscCoRemove((ANSC_HANDLE)pMyObject); 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; }