Esempio n. 1
0
/**********************************************************************

    prototype:

        BOOL
        CcspCrLoadRemoteCRInfo
            (
                ANSC_HANDLE                                 hCcspCr,
                ANSC_HANDLE                                 hXmlHandle
            );

    description:

        This function is called to load single remote cr information

    argument:   ANSC_HANDLE                                 hCcspCr
                the handle of CCSP CR component;

                ANSC_HANDLE                                 hXmlHandle
                the XML handle of remote CR in profile;

    return:     Succeeded or not;

**********************************************************************/
BOOL
CcspCrLoadRemoteCRInfo
    (
        ANSC_HANDLE                                 hCcspCr,
        ANSC_HANDLE                                 hXmlHandle
    )
{
    PCCSP_CR_MANAGER_OBJECT         pMyObject         = (PCCSP_CR_MANAGER_OBJECT)hCcspCr;
    PANSC_XML_DOM_NODE_OBJECT       pObjectNode       = (PANSC_XML_DOM_NODE_OBJECT)hXmlHandle;
    PANSC_XML_DOM_NODE_OBJECT       pChildNode        = (PANSC_XML_DOM_NODE_OBJECT)NULL;
    PCCSP_REMOTE_CRINFO             pCRInfo           = (PCCSP_REMOTE_CRINFO)NULL;
    char                            buffer1[512]       = { 0 };
    char                            buffer2[512]       = { 0 };
    ULONG                           uLength           = 512;

    /* get the prefix */
    pChildNode = (PANSC_XML_DOM_NODE_OBJECT)
        pObjectNode->GetChildByName(pObjectNode, CCSP_CR_XML_NODE_cr_prefix);
     
    if( pChildNode == NULL || pChildNode->GetDataString(pChildNode, NULL, buffer1, &uLength) != ANSC_STATUS_SUCCESS || uLength == 0)
    {
        AnscTraceWarning(("Empty or invalid 'prefix' name.\n"));
        
        return FALSE;
    }

    uLength = 512;
    /* get the id */
    pChildNode = (PANSC_XML_DOM_NODE_OBJECT)
        pObjectNode->GetChildByName(pObjectNode, CCSP_CR_XML_NODE_cr_id);
     
    if( pChildNode == NULL || pChildNode->GetDataString(pChildNode, NULL, buffer2, &uLength) != ANSC_STATUS_SUCCESS || uLength == 0)
    {
        AnscTraceWarning(("Empty or invalid 'id' name.\n"));
        
        return FALSE;
    }

    /* create a remote CR info */
    pCRInfo = (PCCSP_REMOTE_CRINFO)CcspCrAllocateMemory(sizeof(CCSP_REMOTE_CRINFO));

    if( pCRInfo != NULL)
    {
        pCRInfo->pPrefix        = CcspCrCloneString(buffer1);
        pCRInfo->pID            = CcspCrCloneString(buffer2);

        AnscQueuePushEntry(&pMyObject->RemoteCRQueue, &pCRInfo->Linkage);
    }

    return TRUE;
}
static void
CcspTr069PaSsp_XML_GetOneItemByName
    (
        PANSC_XML_DOM_NODE_OBJECT  pRootNode,
        char*                      ItemName,
        char**                     retVal
     )
{
    PANSC_XML_DOM_NODE_OBJECT pChildNode  = NULL;
    int                       uLength     = 511;
    char                      buffer[512] = {0};

    if (pRootNode && retVal && ItemName)
    {
        if(*retVal) { AnscFreeMemory(*retVal); *retVal=NULL; }
        uLength=511;
        pChildNode = (PANSC_XML_DOM_NODE_OBJECT) AnscXmlDomNodeGetChildByName(pRootNode, ItemName);
        if(pChildNode != NULL  && 
           pChildNode->GetDataString(pChildNode, NULL, buffer, &uLength) == ANSC_STATUS_SUCCESS &&
           uLength > 0)
        {
            *retVal = CcspTr069PaCloneString(buffer);
        }
    }    
    CcspTr069PaTraceDebug(("%s: %s = %s\n", __FUNCTION__, (ItemName)?(ItemName):"NULL", (*retVal)?(*retVal):"NULL"));                                                     
    //    fprintf(stderr, "%s: %s = %s\n", __FUNCTION__, (ItemName)?(ItemName):"NULL", (*retVal)?(*retVal):"NULL");
}
static ANSC_STATUS  
CcspTr069PaSsp_XML_GetMultipleItemWithSameName
    (
        PANSC_XML_DOM_NODE_OBJECT   pRootNode,
        char*                       ItemName,
        char**                      retVal
    )
{
    ANSC_STATUS                     returnStatus       = ANSC_STATUS_SUCCESS;
    PANSC_XML_DOM_NODE_OBJECT       pChildNode         = (PANSC_XML_DOM_NODE_OBJECT)NULL;
    char                            buffer[512]        = {0};
    ULONG                           uLength            = 511; 
    
    if (pRootNode && ItemName && retVal)
    {
        if(*retVal) { CcspTr069PaFreeMemory(*retVal); *retVal = NULL; }
        
        pChildNode = (PANSC_XML_DOM_NODE_OBJECT)
            AnscXmlDomNodeGetChildByName(pRootNode, ItemName);
        
        while( pChildNode != NULL)
        {
            if (AnscEqualString(pChildNode->Name, ItemName, TRUE))
            {
                uLength = 511;  // uLength: passes in max buffer length; gets out actual length
                
                if (pChildNode->GetDataString(pChildNode, NULL, buffer, &uLength) == ANSC_STATUS_SUCCESS && 
                    uLength > 0) 
                {
                    if(*retVal) 
                    {
                        char* sptr = (char*)CcspTr069PaAllocateMemory(AnscSizeOfString(*retVal)+1+uLength+1);
                        if(sptr == NULL) 
                        {
                            CcspTr069PaTraceWarning(("Failed to reallocate returnCA\n"));
                            CcspTr069PaFreeMemory(*retVal);
                            *retVal = NULL;
                            returnStatus =  ANSC_STATUS_RESOURCES;
                            goto EXIT;
                        }

                        _ansc_sprintf(sptr, "%s,%s", *retVal, buffer);
                        CcspTr069PaFreeMemory(*retVal);
                        *retVal = sptr;
                    }
                    else *retVal = CcspTr069PaCloneString(buffer);
                }
            }
            
            pChildNode = (PANSC_XML_DOM_NODE_OBJECT) AnscXmlDomNodeGetNextChild(pRootNode, pChildNode);
        }
        CcspTr069PaTraceDebug(("%s: %s = %s\n", __FUNCTION__, (ItemName)?(ItemName):"NULL", (*retVal)?(*retVal):"NULL"));
        //        fprintf(stderr, "%s: %s = %s\n", __FUNCTION__, (ItemName)?(ItemName):"NULL", (*retVal)?(*retVal):"NULL");
    }

 EXIT:
    return returnStatus;
}
Esempio n. 4
0
/**********************************************************************

    prototype:

        BOOL
        CcspCrLoadComponentProfile
            (
                ANSC_HANDLE                                 hCcspCr,
                ANSC_HANDLE                                 hXmlHandle
            );

    description:

        This function is called to load single component profile.

    argument:   ANSC_HANDLE                                 hCcspCr
                the handle of CCSP CR component;

                ANSC_HANDLE                                 hXmlHandle
                the handle of component XML handle in profile;

    return:     Succeeded or not;

**********************************************************************/
BOOL
CcspCrLoadComponentProfile
    (
        ANSC_HANDLE                                 hCcspCr,
        ANSC_HANDLE                                 hXmlHandle
    )
{
    PCCSP_CR_MANAGER_OBJECT         pMyObject         = (PCCSP_CR_MANAGER_OBJECT)hCcspCr;
    PANSC_XML_DOM_NODE_OBJECT       pObjectNode       = (PANSC_XML_DOM_NODE_OBJECT)hXmlHandle;
    PANSC_XML_DOM_NODE_OBJECT       pChildNode        = (PANSC_XML_DOM_NODE_OBJECT)NULL;
    PCCSP_COMPONENT_INFO            pCompInfo         = (PCCSP_COMPONENT_INFO)NULL;
    char                            buffer[512]       = { 0 };
    ULONG                           uLength           = 512;
    ULONG                           uVersion          = 0;

    /* get the name */
    pChildNode = (PANSC_XML_DOM_NODE_OBJECT)
        pObjectNode->GetChildByName(pObjectNode, CCSP_CR_XML_NODE_component_name);
     
    if( pChildNode == NULL || pChildNode->GetDataString(pChildNode, NULL, buffer, &uLength) != ANSC_STATUS_SUCCESS || uLength == 0)
    {
        AnscTraceWarning(("Failed to load component name.\n"));
        
        return FALSE;
    }

    /* get the version */
    pChildNode = (PANSC_XML_DOM_NODE_OBJECT)
        pObjectNode->GetChildByName(pObjectNode, CCSP_CR_XML_NODE_component_version);

    if( pChildNode == NULL || pChildNode->GetDataUlong(pChildNode, NULL, &uVersion) != ANSC_STATUS_SUCCESS)
    {
        AnscTraceWarning(("Failed to load component version.\n"));
        
        return FALSE;
    }

    /* create a Component Info and add it */
    pCompInfo = (PCCSP_COMPONENT_INFO)CcspCrAllocateMemory(sizeof(CCSP_COMPONENT_INFO));

    if( pCompInfo != NULL)
    {
        pCompInfo->pComponentName = CcspCrCloneString(buffer);
        pCompInfo->uVersion       = uVersion;
        pCompInfo->uStatus        = CCSP_Component_NotRegistered;

        AnscQueuePushEntry(&pMyObject->CompInfoQueue, &pCompInfo->Linkage);
    }

    return TRUE;
}
Esempio n. 5
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;
}
Esempio n. 6
0
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);
    }

}