/********************************************************************** prototype: BOOL CcspCrLoadDeviceProfile ( ANSC_HANDLE hCcspCr ); description: This function is called to load device profile for CR. argument: ANSC_HANDLE hCcspCr the handle of CCSP CR component; return: Succeeded or not; **********************************************************************/ BOOL CcspCrLoadDeviceProfile ( ANSC_HANDLE hCcspCr ) { PCCSP_CR_MANAGER_OBJECT pMyObject = (PCCSP_CR_MANAGER_OBJECT)hCcspCr; PCCSP_NAMESPACE_MGR_OBJECT pNSMgr = (PCCSP_NAMESPACE_MGR_OBJECT)pMyObject->hCcspNamespaceMgr; ANSC_HANDLE pFileHandle = NULL; char* pXMLContent = NULL; char* pBackContent = NULL; ULONG uXMLLength = 0; PANSC_XML_DOM_NODE_OBJECT pXmlNode = (PANSC_XML_DOM_NODE_OBJECT)NULL; PANSC_XML_DOM_NODE_OBJECT pListNode = (PANSC_XML_DOM_NODE_OBJECT)NULL; PANSC_XML_DOM_NODE_OBJECT pChildNode = (PANSC_XML_DOM_NODE_OBJECT)NULL; BOOL bStatus = TRUE; ULONG uFileLength = 0; ULONG uBufferSize = 0; char buffer[512] = { 0 }; ULONG uLength = 511; PCCSP_COMPONENT_INFO pCompInfo = (PCCSP_COMPONENT_INFO)NULL; /* load from the file */ pFileHandle = AnscOpenFile ( CCSP_CR_DEVICE_PROFILE_XML_FILE, ANSC_FILE_O_BINARY | ANSC_FILE_O_RDONLY, ANSC_FILE_S_IREAD ); if( pFileHandle == NULL) { AnscTrace("Failed to load the file : '%s'\n", CCSP_CR_DEVICE_PROFILE_XML_FILE); return FALSE; } uFileLength = AnscGetFileSize( pFileHandle); pXMLContent = (char*)AnscAllocateMemory( uFileLength + 8); if( pXMLContent == NULL) { return FALSE; } uBufferSize = uFileLength + 8; if( AnscReadFile( pFileHandle, pXMLContent, &uBufferSize) != ANSC_STATUS_SUCCESS) { AnscFreeMemory(pXMLContent); return FALSE; } if( pFileHandle != NULL) { AnscCloseFile(pFileHandle); } /* parse the XML content */ pBackContent = pXMLContent; pXmlNode = (PANSC_XML_DOM_NODE_OBJECT) AnscXmlDomParseString((ANSC_HANDLE)NULL, (PCHAR*)&pXMLContent, uBufferSize); AnscFreeMemory(pBackContent); if( pXmlNode == NULL) { AnscTraceWarning(("Failed to parse the CR profile file.\n")); return FALSE; } /* load CR name */ pChildNode = (PANSC_XML_DOM_NODE_OBJECT) AnscXmlDomNodeGetChildByName(pXmlNode, CCSP_CR_XML_NODE_crName); if( pChildNode != NULL && pChildNode->GetDataString(pChildNode, NULL, buffer, &uLength) == ANSC_STATUS_SUCCESS && uLength > 0) { pMyObject->pCRName = AnscCloneString(buffer); } else { pMyObject->pCRName = AnscCloneString(CCSP_CR_NAME); } AnscTraceWarning(("CR Name: %s\n", pMyObject->pCRName)); #if 0 /* load prefix name */ /* Prefix will be set from command line instead */ uLength = 511; AnscZeroMemory(buffer, 512); pChildNode = (PANSC_XML_DOM_NODE_OBJECT) AnscXmlDomNodeGetChildByName(pXmlNode, CCSP_CR_XML_NODE_prefix); if( pChildNode != NULL && pChildNode->GetDataString(pChildNode, NULL, buffer, &uLength) == ANSC_STATUS_SUCCESS && uLength > 0) { pMyObject->pPrefix = AnscCloneString(buffer); pNSMgr->SubsysPrefix = AnscCloneString(buffer); AnscTraceWarning(("CR Prefix: %s\n", pMyObject->pPrefix)); } #endif /* get remote cr array */ pListNode = (PANSC_XML_DOM_NODE_OBJECT) AnscXmlDomNodeGetChildByName(pXmlNode, CCSP_CR_XML_NODE_remote); if( pListNode != NULL) { pChildNode = (PANSC_XML_DOM_NODE_OBJECT) AnscXmlDomNodeGetHeadChild(pListNode); while(pChildNode != NULL) { /* load remote cr information */ if(!CcspCrLoadRemoteCRInfo(hCcspCr, (ANSC_HANDLE)pChildNode)) { AnscTraceWarning(("Failed to load remote cr infor.\n")); } pChildNode = (PANSC_XML_DOM_NODE_OBJECT) AnscXmlDomNodeGetNextChild(pListNode, pChildNode); } } /* get the component array node */ pListNode = (PANSC_XML_DOM_NODE_OBJECT) AnscXmlDomNodeGetChildByName(pXmlNode, CCSP_CR_XML_NODE_components); if( pListNode != NULL) { pChildNode = (PANSC_XML_DOM_NODE_OBJECT) AnscXmlDomNodeGetHeadChild(pListNode); while(pChildNode != NULL) { /* load component information */ if(!CcspCrLoadComponentProfile(hCcspCr, (ANSC_HANDLE)pChildNode)) { AnscTraceWarning(("Failed to load component profile.\n")); } pChildNode = (PANSC_XML_DOM_NODE_OBJECT) AnscXmlDomNodeGetNextChild(pListNode, pChildNode); } } if( pXmlNode != NULL) { pXmlNode->Remove(pXmlNode); } /* create a Component Info for CR itself */ pCompInfo = (PCCSP_COMPONENT_INFO)CcspCrAllocateMemory(sizeof(CCSP_COMPONENT_INFO)); if( pCompInfo != NULL) { pCompInfo->pComponentName = CcspCrCloneString(CCSP_CR_NAME); pCompInfo->uVersion = CCSP_CR_VERSION; pCompInfo->uStatus = CCSP_Component_NotRegistered; AnscQueuePushEntry(&pMyObject->CompInfoQueue, &pCompInfo->Linkage); } return bStatus; }
ANSC_STATUS CcspTr069PaSsp_LoadCfgFile ( char* pCfgFileName ) { ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; char* pXMLContent = NULL; ULONG uBufferSize = 0; char partnerID[128]; /* load configuration file */ { ANSC_HANDLE pFileHandle = NULL; pFileHandle = AnscOpenFile ( pCfgFileName, ANSC_FILE_O_BINARY | ANSC_FILE_O_RDONLY, ANSC_FILE_S_IREAD ); if( pFileHandle == NULL) { CcspTr069PaTraceWarning(("Failed to open file %s\n", pCfgFileName)); return ANSC_STATUS_FAILURE; } uBufferSize = AnscGetFileSize(pFileHandle) + 8; pXMLContent = (char*)AnscAllocateMemory(uBufferSize); if (pXMLContent == NULL) { CcspTr069PaTraceWarning(("Failed to allocate buffer\n")); AnscCloseFile(pFileHandle); return ANSC_STATUS_RESOURCES; } if ( AnscReadFile(pFileHandle, pXMLContent, &uBufferSize) != ANSC_STATUS_SUCCESS ) { CcspTr069PaTraceWarning(("Failed to read file %s\n", pCfgFileName)); AnscFreeMemory(pXMLContent); AnscCloseFile(pFileHandle); return ANSC_STATUS_FAILURE; } AnscCloseFile(pFileHandle); } /* * Parse the XML content */ { PANSC_XML_DOM_NODE_OBJECT pRootNode = (PANSC_XML_DOM_NODE_OBJECT)NULL; PANSC_XML_DOM_NODE_OBJECT pChildNode = (PANSC_XML_DOM_NODE_OBJECT)NULL; char* pXMLIterator = pXMLContent; pRootNode = (PANSC_XML_DOM_NODE_OBJECT) AnscXmlDomParseString((ANSC_HANDLE)NULL, (PCHAR*)&pXMLIterator, uBufferSize); if ( pRootNode == NULL ) { CcspTr069PaTraceWarning(("Failed to parse the file to retrieve the root node!\n")); returnStatus = ANSC_STATUS_FAILURE; goto EXIT; } #ifdef _ANSC_USE_OPENSSL_ pChildNode = (PANSC_XML_DOM_NODE_OBJECT) AnscXmlDomNodeGetChildByName(pRootNode, CCSP_TR069PA_CFG_Name_Certificates); if ( pChildNode != NULL) { CcspTr069PaSsp_XML_GetMultipleItemWithSameName(pChildNode, CCSP_TR069PA_CERTIFICATE_CFG_Name_ca, &openssl_client_ca_certificate_files); CcspTr069PaSsp_XML_GetOneItemByName(pChildNode, CCSP_TR069PA_CERTIFICATE_CFG_Name_dev, &openssl_client_dev_certificate_file); CcspTr069PaSsp_XML_GetOneItemByName(pChildNode, CCSP_TR069PA_CERTIFICATE_CFG_Name_pkey, &openssl_client_private_key_file); } #endif CcspTr069PaSsp_XML_GetOneItemByName(pRootNode, CCSP_TR069PA_CFG_Name_Outbound_If, &g_Tr069PaOutboundIfName); CcspTr069PaSsp_GetPartnerID(partnerID); if (strcmp(partnerID,"comcast")==0) { CcspTr069PaSsp_XML_GetOneItemByName(pRootNode, CCSP_TR069PA_CFG_Name_AcsDefAddr, &g_Tr069PaAcsDefAddr); } else { CcspTr069PaSsp_XML_GetOneItemByName(pRootNode, partnerID, &g_Tr069PaAcsDefAddr); } returnStatus = ANSC_STATUS_SUCCESS; } EXIT: AnscFreeMemory(pXMLContent); return returnStatus; }
ANSC_STATUS HttpMboFileOutput ( ANSC_HANDLE hThisObject, ANSC_HANDLE hSerializeContext ) { ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; PHTTP_MBO_FILE_OBJECT pMyObject = (PHTTP_MBO_FILE_OBJECT)hThisObject; PHTTP_HFP_INTERFACE pHfpIf = (PHTTP_HFP_INTERFACE )pMyObject->hHfpIf; PHTTP_BCC_INTERFACE pBccIf = (PHTTP_BCC_INTERFACE )pMyObject->hBccIf; ANSC_HANDLE hFile = (ANSC_HANDLE )NULL; ULONG ulFileSize = 0; ULONG ulCopySize = 0; PVOID pSerializedBuffer = NULL; ULONG ulSerializedSize = 0; ULONG ulRoundNumber = 0; ULONG i = 0; if ( !pMyObject->FileName ) { return ANSC_STATUS_UNAPPLICABLE; } else { ulCopySize = pMyObject->GetBodySize((ANSC_HANDLE)pMyObject); } if ( ulCopySize == 0 ) { return ANSC_STATUS_UNAPPLICABLE; } else { hFile = AnscOpenFile ( pMyObject->FileName, ANSC_FILE_MODE_READ, ANSC_FILE_TYPE_READ ); } if ( !hFile ) { return ANSC_STATUS_INTERNAL_ERROR; } else { AnscSeekFile(hFile, (ULONG)pMyObject->RangeFrom, ANSC_FILE_SEEK_SET); } pSerializedBuffer = AnscAllocateMemory(HTTP_MBOFILE_DEF_WRITE_UNIT); if ( !pSerializedBuffer ) { AnscCloseFile(hFile); return ANSC_STATUS_RESOURCES; } if ( ulCopySize <= HTTP_MBOFILE_DEF_WRITE_UNIT ) { ulSerializedSize = HTTP_MBOFILE_DEF_WRITE_UNIT; returnStatus = AnscReadFile ( hFile, pSerializedBuffer, &ulSerializedSize ); returnStatus = pBccIf->Serialize ( pBccIf->hOwnerContext, pSerializedBuffer, ulSerializedSize, hSerializeContext ); } else { if ( (ulCopySize % HTTP_MBOFILE_DEF_WRITE_UNIT) == 0 ) { ulRoundNumber = ulCopySize / HTTP_MBOFILE_DEF_WRITE_UNIT; } else { ulRoundNumber = ulCopySize / HTTP_MBOFILE_DEF_WRITE_UNIT + 1; } for ( i = 0; i < ulRoundNumber; i++ ) { ulSerializedSize = HTTP_MBOFILE_DEF_WRITE_UNIT; returnStatus = AnscReadFile ( hFile, pSerializedBuffer, &ulSerializedSize ); returnStatus = pBccIf->Serialize ( pBccIf->hOwnerContext, pSerializedBuffer, ulSerializedSize, hSerializeContext ); } } AnscCloseFile(hFile); if ( pSerializedBuffer ) { AnscFreeMemory(pSerializedBuffer); } return returnStatus; }
void init_ccsp_snmp_plugin(void) { ANSC_HANDLE pFileHandle = NULL; char* pXMLContent = NULL; ULONG uXMLLength = 0; ULONG uFileLength = 0; ULONG uBufferSize = 0; PANSC_XML_DOM_NODE_OBJECT pRootNode = (PANSC_XML_DOM_NODE_OBJECT)NULL; PANSC_XML_DOM_NODE_OBJECT pChildNode = (PANSC_XML_DOM_NODE_OBJECT)NULL; char buffer[64] = { 0 }; ULONG uLength = 63; PCHAR pBackBuffer = NULL; set_debug_level(); #ifdef FEATURE_SUPPORT_RDKLOG RDK_LOGGER_INIT(); #endif #ifdef INCLUDE_BREAKPAD breakpad_ExceptionHandler( ); #endif /* INCLUDE_BREAKPAD */ /* init the COSA debus */ if (!Cosa_Init()) { AnscTraceError(("%s: Cosa_Init error\n", __FUNCTION__)); return; } printf("****snmp rdklogger init %s\n",pComponentName); CcspTraceWarning(("SNMP:snmp initialzed!\n")); g_CcspMibHelper = (PCCSP_MIB_HELPER_OBJECT)CcspCreateMibHelper(); if( g_CcspMibHelper == NULL) { return; } /* load the MIB List XML file */ pFileHandle = AnscOpenFile ( CCSP_MIB_MAPPING_LIST_FILE, ANSC_FILE_O_BINARY | ANSC_FILE_O_RDONLY, ANSC_FILE_S_IREAD ); if( pFileHandle == NULL) { AnscTraceWarning(("Failed to load the file : '%s'\n", CCSP_MIB_MAPPING_LIST_FILE)); return; } uFileLength = AnscGetFileSize( pFileHandle); pXMLContent = (char*)AnscAllocateMemory( uFileLength + 8); if( pXMLContent == NULL) { AnscCloseFile(pFileHandle); return; } uBufferSize = uFileLength + 8; if( AnscReadFile( pFileHandle, pXMLContent, &uBufferSize) != ANSC_STATUS_SUCCESS) { AnscFreeMemory(pXMLContent); AnscCloseFile(pFileHandle); return; } /* close the file handle */ AnscCloseFile(pFileHandle); /* parse the XML file */ pBackBuffer = pXMLContent; pRootNode = (PANSC_XML_DOM_NODE_OBJECT) AnscXmlDomParseString((ANSC_HANDLE)NULL, (PCHAR*)&pBackBuffer, uBufferSize); printf("Test XML : %s\n", pRootNode->Name); AnscFreeMemory(pXMLContent); if( pRootNode == NULL) { AnscTraceWarning(("Failed to Ccsp MIB List XML file.\n")); return; } /* go through MIB files one by one */ pChildNode = (PANSC_XML_DOM_NODE_OBJECT)pRootNode->GetHeadChild(pRootNode); while( pChildNode != NULL) { AnscZeroMemory(buffer, 64); uLength = 63; if(AnscEqualString(pChildNode->GetName(pChildNode),CCSP_MIB_FILE_NODE_NAME, TRUE)) { pChildNode->GetDataString(pChildNode, NULL, buffer, &uLength); if ( !g_CcspMibHelper->LoadCcspMibFile(g_CcspMibHelper, buffer)) { AnscTraceWarning(("Failed to load Ccsp Mib file: %s\n", buffer)); } } else { AnscTraceWarning(("Unknown XML node name: %s\n", pChildNode->GetName(pChildNode))); } /* goto next one */ pChildNode = (PANSC_XML_DOM_NODE_OBJECT)pRootNode->GetNextChild(pRootNode, pChildNode); } /* clear the XML node handle */ if( pRootNode != NULL) { pRootNode->Remove(pRootNode); } }