/**********************************************************************

  prototype:

    static int
    GetAddressByDmlPath(const char *path, char *address, ULONG size)

  description:

    Get IP address string by TR-181 data module path

  arguments:
  
    @path should be:
      "Device.IP.Interface.{i}.IPv4Address.{i}" or
      "Device.IP.Interface.{i}.IPv6Address.{i}".
	and {i} is index number.

  Return:
  
    0 if success and -1 on error.

**********************************************************************/
static int
GetAddressByDmlPath(const char *path, char *address, ULONG size)
{
	char *addrBuf;

	return -1;
#if 0
	if (!path || _ansc_strlen(path) == 0 || !address)
		return -1;

	/*
	 * Don't use COSAGetParamValueString 
	 */
	if ((addrBuf = CosaGetInterfaceAddrByName(path)) == NULL)
	{
		AnscTraceWarning(("Failed to get IP Addresss for %s\n", path));
		return -1;
	}

	if (_ansc_strcmp(addrBuf, "::") == 0)
	{
		/* it may not an error, but "::" for IPv4 is unsuitable,
		 * and we can just don't bind "::" */
		AnscFreeMemory(addrBuf);
		return -1;
	}

	_ansc_snprintf(address, size, "%s", addrBuf);
	AnscFreeMemory(addrBuf);
#endif
    return 0;
}
Пример #2
0
/**********************************************************************

    caller:     owner of this object

    prototype:

        BOOL
        NSLookupDiagnostics_Validate
            (
                ANSC_HANDLE                 hInsContext,
                char*                       pReturnParamName,
                ULONG*                      puLength
            );

    description:

        This function is called to finally commit all the update.

    argument:   ANSC_HANDLE                 hInsContext,
                The instance handle;

                char*                       pReturnParamName,
                The buffer (128 bytes) of parameter name if there's a validation.

                ULONG*                      puLength
                The output length of the param name.

    return:     TRUE if there's no validation.

**********************************************************************/
BOOL
NSLookupDiagnostics_Validate
    (
        ANSC_HANDLE                 hInsContext,
        char*                       pReturnParamName,
        ULONG*                      puLength
    )
{
    char*                           p                  = NULL;
    char*                           pDomainName        = NULL;
    ULONG                           ulDNLength         = DSLH_NS_MAX_STRING_LENGTH_Host;
    ULONG                           i                  = 0;
    PCOSA_DATAMODEL_DIAG            pMyObject          = (PCOSA_DATAMODEL_DIAG)g_pCosaBEManager->hDiag;
    PDSLH_NSLOOKUP_INFO             pNSLookupDiagInfo  = pMyObject->hDiagNSLookInfo;
    char*                           pAddrName          = NULL;

    if ( !pNSLookupDiagInfo )
    {
        return FALSE;
    }

    //COSAValidateHierarchyInterface doesn't work now due to incomplete lan device management
    if ( pNSLookupDiagInfo->DiagnosticState == DSLH_DIAG_STATE_TYPE_Requested || 
         /*COSAValidateHierarchyInterface && */ AnscSizeOfString(pNSLookupDiagInfo->Interface) > 0 )
    {
        // COSAValidateHierarchyInterface depends on the specific target
       if(AnscSizeOfString(pNSLookupDiagInfo->Interface) > 0)
            pAddrName = CosaGetInterfaceAddrByName(pNSLookupDiagInfo->Interface);
       else
           pAddrName = CosaGetInterfaceAddrByName("Device.DeviceInfo.X_COMCAST-COM_WAN_IP");

        if(strcmp(pAddrName,"::") && (isValidIPv4Address(pAddrName) || isValidIPv6Address(pAddrName)))
        {
            AnscCopyString(pNSLookupDiagInfo->IfAddr, pAddrName);
            AnscFreeMemory(pAddrName);
        }
        else
        {
            AnscFreeMemory(pAddrName);
            AnscCopyString(pReturnParamName, "Interface");
            pNSLookupDiagInfo->DiagnosticState = DSLH_DIAG_STATE_TYPE_None;
            return FALSE;
        }
        /*
        if ( !COSAValidateHierarchyInterface
                (
                    pNSLookupDiagInfo->Interface,
                    DSLH_LAN_LAYER3_INTERFACE | DSLH_WAN_LAYER3_CONNECTION_INTERFACE | DSLH_NULL_STRING_INTERFACE
                ))
        {
            AnscCopyString(pReturnParamName, "Interface");
            return FALSE;
        }
        */
    }

    if ( pNSLookupDiagInfo->DiagnosticState == DSLH_DIAG_STATE_TYPE_Requested || AnscSizeOfString(pNSLookupDiagInfo->HostName) > 0 )
    {
        p = pNSLookupDiagInfo->HostName;

        //check if there is any illegal character
        for(i = 0; i < AnscSizeOfString(p); i++)
        {
            if ( (p[i] >= '0' && p[i] <= '9') || (p[i] >= 'a' && p[i] <= 'z') ||
                (p[i] >= 'A' && p[i] <= 'Z') || p[i] == '$' || p[i] == '-' ||
                p[i] == '_' || p[i] == '.' || p[i] == '+' || p[i] == '!' ||
                p[i] == '*' || p[i] == 39 || p[i] == '(' || p[i] == ')' ||
                p[i] == ',' || p[i] == '"' )
            {
                continue;
            }
            else
            {
                AnscCopyString(pReturnParamName, "HostName");
                pNSLookupDiagInfo->DiagnosticState = DSLH_DIAG_STATE_TYPE_None;
                return FALSE;
            }
        }

        if ( pNSLookupDiagInfo->HostName[0] != '.')
        {
            p = _ansc_strstr(pNSLookupDiagInfo->HostName + 1, "..");

            if ( p )
            {
                for(; p < pNSLookupDiagInfo->HostName + AnscSizeOfString(pNSLookupDiagInfo->HostName); p++)
                {
                    if ( *p != '.' )
                    {
                        AnscCopyString(pReturnParamName, "HostName");
                        pNSLookupDiagInfo->DiagnosticState = DSLH_DIAG_STATE_TYPE_None;
                        return FALSE;
                    }
                }
            }
        }
        else
        {
            AnscCopyString(pReturnParamName, "HostName");
            pNSLookupDiagInfo->DiagnosticState = DSLH_DIAG_STATE_TYPE_None;
            return FALSE;
        }

        pDomainName = AnscAllocateMemory(DSLH_NS_MAX_STRING_LENGTH_Host);

        if ( !pDomainName )
        {
            AnscCopyString(pReturnParamName, "HostName");
            pNSLookupDiagInfo->DiagnosticState = DSLH_DIAG_STATE_TYPE_None;
            return FALSE;
        }

        CosaGetParamValueString
            (
#ifndef     DM_IGD
                "Device.DHCPv4.Server.Pool.1.DomainName",
#else
                "InternetGatewayDevice.LANDevice.1.LANHostConfigManagement.DomainName",
#endif
                pDomainName,
                &ulDNLength
            );

        if ( !AnscSizeOfString(pDomainName) )
        {
            if ( pNSLookupDiagInfo->HostName[0] != '.')
            {
                p = _ansc_strchr(pNSLookupDiagInfo->HostName + 1, '.');

                if ( !p )
                {
                    AnscCopyString(pReturnParamName, "HostName");
                    pNSLookupDiagInfo->DiagnosticState = DSLH_DIAG_STATE_TYPE_None;
                    return FALSE;
                }
                else if ( p[1] == '0' || p[1] == '.' )
                {
                    AnscCopyString(pReturnParamName, "HostName");
                    pNSLookupDiagInfo->DiagnosticState = DSLH_DIAG_STATE_TYPE_None;
                    return FALSE;
                }
            }
            else
            {
                AnscCopyString(pReturnParamName, "HostName");
                pNSLookupDiagInfo->DiagnosticState = DSLH_DIAG_STATE_TYPE_None;
                return FALSE;
            }
        }
        else
        {
            if ( pNSLookupDiagInfo->HostName[0] == '.')
            {
                AnscCopyString(pReturnParamName, "HostName");
                pNSLookupDiagInfo->DiagnosticState = DSLH_DIAG_STATE_TYPE_None;
                return FALSE;
            }
        }
    }

    if ( pNSLookupDiagInfo->DiagnosticState == DSLH_DIAG_STATE_TYPE_Requested || AnscSizeOfString(pNSLookupDiagInfo->DNSServer) > 0  )
    {
		/*
		  * if DNSServer is empty then we have to take default DNS Server value Device.DNS.Client.Server.1.DNSServer 
		  */
		if ( 0 == AnscSizeOfString(pNSLookupDiagInfo->DNSServer) )
		{
			parameterValStruct_t varStruct 		= { 0 };
			UCHAR	   ucEntryNameValue[128]	= { 0 };
			UCHAR	   ucEntryParamName[128]	= { 0 };
			int 	   			 ulEntryNameLen = 0;

			AnscCopyString( ucEntryParamName, "Device.DNS.Client.Server.1.DNSServer");

			varStruct.parameterName  = ucEntryParamName;
			varStruct.parameterValue = ucEntryNameValue;

			if ( ANSC_STATUS_SUCCESS == COSAGetParamValueByPathName(  g_MessageBusHandle, 
																	   &varStruct,
																	   &ulEntryNameLen ) 
				)
			{
				AnscCopyString( pNSLookupDiagInfo->DNSServer, varStruct.parameterValue );
			}
		}

        //still not clear how to validate dns server
        // we are only validating if the server ip is v4/v6
        if(!isValidIPv4Address(pNSLookupDiagInfo->DNSServer) && !isValidIPv6Address(pNSLookupDiagInfo->DNSServer))
            {
                AnscCopyString(pReturnParamName, "DNSServer");
                pNSLookupDiagInfo->DiagnosticState = DSLH_DIAG_STATE_TYPE_None;
                return FALSE;
            }
    }

    if ( TRUE )
    {
        if ( pNSLookupDiagInfo->Timeout < DSLH_NS_MIN_Timeout )
        {
            AnscCopyString(pReturnParamName, "Timeout");
            pNSLookupDiagInfo->DiagnosticState = DSLH_DIAG_STATE_TYPE_None;
            return FALSE;
        }
    }

    if ( TRUE )
    {
        if ( pNSLookupDiagInfo->NumberOfRepetitions < DSLH_NS_MIN_NumberOfRepetitions )
        {
            AnscCopyString(pReturnParamName, "NumberOfRepetitions");
            pNSLookupDiagInfo->DiagnosticState = DSLH_DIAG_STATE_TYPE_None;
            return FALSE;
        }
    }

    return TRUE;
}