Beispiel #1
0
/**********************************************************************

    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;
}
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);
    }

}