ANSC_HANDLE BspTemplateWriterWriteDouble ( ANSC_HANDLE hThisObject, #ifdef _BSPENG_NO_DOUBLE BSP_TEMPLATE_DOUBLE Value #else double Value #endif ) { PBSP_TEMPLATE_WRITER_OBJECT pMyObject = (PBSP_TEMPLATE_WRITER_OBJECT)hThisObject; char buf[16]; ULONG ulLen; #ifdef _BSPENG_NO_DOUBLE LONG lInt; ULONG ulFrac; lInt = BSP_TEMPLATE_DOUBLE_GET_INT_TRUNK(Value); ulFrac = BSP_TEMPLATE_DOUBLE_GET_FRAC(Value); if (ulFrac == 0) ulLen = _ansc_sprintf(buf, "%d", lInt); else ulLen = _ansc_sprintf(buf, BSP_TEMPLATE_DOUBLE_FORMAT, lInt, ulFrac); #else ulLen = _ansc_sprintf(buf, "%f", Value); #endif pMyObject->WriteBytes(hThisObject, buf, &ulLen); return hThisObject; }
//Set and Get of ManagedDevices values ( in parental control features ) from PSM Database. void PSM_Set_ParentalControl_MDDev_RecordValues(COSA_DML_MD_DEV *pEntry) { int retPsmSet = CCSP_SUCCESS; char param_name[256] = {0}; char param_value[256] = {0}; ULONG instancenum = pEntry->InstanceNumber; if(pEntry->Type == MD_TYPE_BLOCK){ _ansc_sprintf(param_value,"%s","Block"); } else{ _ansc_sprintf(param_value,"%s","Allow"); } _PSM_WRITE_PARAM(PSM_PC_MD_TYPE); _ansc_sprintf(param_value,"%s",pEntry->Description); _PSM_WRITE_PARAM(PSM_PC_MD_DESCRIPTION); _ansc_sprintf(param_value,"%s",pEntry->MACAddress); _PSM_WRITE_PARAM(PSM_PC_MD_MACADDRESS); if(pEntry->AlwaysBlock == TRUE) _ansc_sprintf(param_value,"%s","TRUE"); else _ansc_sprintf(param_value,"%s","FALSE"); _PSM_WRITE_PARAM(PSM_PC_MD_ALWAYSBLOCK); _ansc_sprintf(param_value,"%s",pEntry->StartTime); _PSM_WRITE_PARAM(PSM_PC_MD_STARTTIME); _ansc_sprintf(param_value,"%s",pEntry->EndTime); _PSM_WRITE_PARAM(PSM_PC_MD_ENDTIME); _ansc_sprintf(param_value,"%s",pEntry->BlockDays); _PSM_WRITE_PARAM(PSM_PC_MD_BLOCKDAYS); }
void PSM_Set_ParentalControl_ManagedServices_RecordValues(COSA_DML_MANAGED_SERVS *Conf) { int retPsmSet = CCSP_SUCCESS; char param_name[256] = {0}; char param_value[256] = {0}; if(Conf->Enable == TRUE) _ansc_sprintf(param_value,"%s","TRUE"); else _ansc_sprintf(param_value,"%s","FALSE"); _PSM_WRITE_PARAMs(PSM_PC_MSE_ENABLE); }
void PSM_Set_ParentalControl_ManagedSites_RecordValues(bool Enable) { int retPsmSet = CCSP_SUCCESS; char param_name[256] = {0}; char param_value[256] = {0}; if(Enable == TRUE) _ansc_sprintf(param_value,"%s","TRUE"); else _ansc_sprintf(param_value,"%s","FALSE"); _PSM_WRITE_PARAMs(PSM_PC_MS_ENABLE); }
ANSC_HANDLE IPv6rdIF_AddEntry( ANSC_HANDLE hInsContext, ULONG *pInsNumber) { PCOSA_DATAMODEL_IPV6RD pMyObject = (PCOSA_DATAMODEL_IPV6RD)g_pCosaBEManager->hIPv6rd; PSLIST_HEADER pListHead = (PSLIST_HEADER)&pMyObject->IfList; PCOSA_DML_IPV6RD_IF pEntry = NULL; PCOSA_CONTEXT_LINK_OBJECT pCosaContext = NULL; PSINGLE_LINK_ENTRY pSLinkEntry = NULL; pEntry = (PCOSA_DML_IPV6RD_IF)AnscAllocateMemory(sizeof(COSA_DML_IPV6RD_IF)); if (!pEntry) { return NULL; } /* Set default values here */ memset(pEntry, 0, sizeof(COSA_DML_IPV6RD_IF)); _ansc_sprintf(pEntry->Alias, "tun6rd%d", pMyObject->ulIfNextInstance); #if !CFG_TR181_NO_CosaDml_Ifname2Addr CosaDml_Ifname2Addr(CFG_TR181_6rd_IfName, pEntry->AddressSource, sizeof(pEntry->AddressSource)); #endif _ansc_sprintf(pEntry->Status, "Disabled"); pCosaContext = (PCOSA_CONTEXT_LINK_OBJECT)AnscAllocateMemory(sizeof(COSA_CONTEXT_LINK_OBJECT)); if (!pCosaContext) { AnscFreeMemory(pEntry); return NULL; } pCosaContext->InstanceNumber = pEntry->InstanceNumber = pMyObject->ulIfNextInstance; pMyObject->ulIfNextInstance++; if (pMyObject->ulIfNextInstance == 0) { pMyObject->ulIfNextInstance = 1; } pCosaContext->hContext = (ANSC_HANDLE)pEntry; pCosaContext->hParentTable = NULL; pCosaContext->bNew = TRUE; CosaSListPushEntryByInsNum(pListHead, pCosaContext); CosaIPv6rdIfRegAddInfo((ANSC_HANDLE)pMyObject, pCosaContext); *pInsNumber = pCosaContext->InstanceNumber; return pCosaContext; }
void PSM_Set_ParentalControl_ManagedBlkURL_RecordValues(COSA_DML_BLOCKEDURL *pEntry) { int retPsmSet = CCSP_SUCCESS; char param_name[256] = {0}; char param_value[256] = {0}; ULONG instancenum = pEntry->InstanceNumber; if(pEntry->BlockMethod == BLOCK_METHOD_URL) _ansc_sprintf(param_value,"%s","URL"); else _ansc_sprintf(param_value,"%s","Keyword"); _PSM_WRITE_PARAM(PSM_PC_MS_BLOCKMETHOD); _ansc_sprintf(param_value,"%s",pEntry->Site); _PSM_WRITE_PARAM(PSM_PC_MS_SITE); if(pEntry->AlwaysBlock == TRUE) _ansc_sprintf(param_value,"%s","TRUE"); else _ansc_sprintf(param_value,"%s","FALSE"); _PSM_WRITE_PARAM(PSM_PC_MS_ALWAYSBLOCK); _ansc_sprintf(param_value,"%s",pEntry->StartTime); _PSM_WRITE_PARAM(PSM_PC_MS_STARTTIME); _ansc_sprintf(param_value,"%s",pEntry->EndTime); _PSM_WRITE_PARAM(PSM_PC_MS_ENDTIME); _ansc_sprintf(param_value,"%s",pEntry->BlockDays); _PSM_WRITE_PARAM(PSM_PC_MS_BLOCKDAYS); }
/********************************************************************** prototype: char* DslhVarroMacAddrListToString ( SLAP_UCHAR_ARRAY* mac_addr_list ); description: This function is called to export MAC address list to a string. argument: SLAP_UCHAR_ARRAY* mac_addr_list The input mac address list; return: The exported string; **********************************************************************/ char* DslhVarroMacAddrListToString ( SLAP_UCHAR_ARRAY* mac_addr_list ) { char* var_string = (char* )(mac_addr_list? AnscAllocateMemory(mac_addr_list->VarCount * 24 / 6 + 1) : NULL); ULONG i = 0; if ( !var_string ) { return NULL; } else if ( !mac_addr_list || (mac_addr_list->VarCount == 0) ) { return var_string; } for ( i = 0; i < mac_addr_list->VarCount; i++ ) { if( i != 0 ) { if ( (i % 6) == 0) { _ansc_sprintf ( &var_string[AnscSizeOfString(var_string)], "," ); } else if( i % 6 ) { _ansc_sprintf ( &var_string[AnscSizeOfString(var_string)], ":" ); } } _ansc_sprintf ( &var_string[AnscSizeOfString(var_string)], "%02X", mac_addr_list->Array.arrayUchar[i] ); } return var_string; }
PUCHAR AnscDupIp4Addr ( PUCHAR pStr ) { /* this function generate string format of a IP4 address */ if (!pStr) { return NULL; } else { ULONG ulStrLen; PUCHAR pDupStr; /* xxx.xxx.xxx.xxx */ ulStrLen = 15; pDupStr = (PUCHAR)AnscAllocateMemory(ulStrLen + 1); if (pDupStr) { _ansc_sprintf(pDupStr, "%d.%d.%d.%d", pStr[0], pStr[1], pStr[2], pStr[3]); } return pDupStr; } }
char* DslhVarroGetFullName ( ANSC_HANDLE hThisObject ) { ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; PDSLH_VAR_RECORD_OBJECT pMyObject = (PDSLH_VAR_RECORD_OBJECT)hThisObject; PDSLH_VAR_ENTITY_OBJECT pVarEntity = (PDSLH_VAR_ENTITY_OBJECT)pMyObject->hDslhVarEntity; PDSLH_OBJ_RECORD_OBJECT pObjRecord = (PDSLH_OBJ_RECORD_OBJECT)pMyObject->hDslhObjRecord; char* pLastName = (char* )pVarEntity->ParamDescr->Name; char* pFullName = (char* )NULL; ULONG ulFullNameSize = (ULONG )0; ulFullNameSize = (pObjRecord->FullName? AnscSizeOfString(pObjRecord->FullName) : 0) + AnscSizeOfString(pLastName) + 4; pFullName = (char*)AnscAllocateMemory(ulFullNameSize); if ( !pFullName ) { return NULL; } else { _ansc_sprintf ( pFullName, "%s%s", pObjRecord->FullName, pLastName ); } return pFullName; }
ANSC_STATUS CosaDmlDiGetFirstUseDate ( ANSC_HANDLE hContext, char* pValue, PULONG pulSize ) { UtopiaContext ctx; int rc = -1; char firstUseDate[64]; if (!Utopia_Init(&ctx)) return ERR_UTCTX_INIT; rc = Utopia_Get_First_Use_Date(&ctx,firstUseDate); Utopia_Free(&ctx,0); // fprintf(stderr, "<RT> rc=%d, First Use Date = '%s'\n", rc, firstUseDate); if(rc || firstUseDate[0] == '\0') _ansc_sprintf(firstUseDate, "2013-11-22T00:00:00"); AnscCopyString(pValue,firstUseDate); *pulSize = AnscSizeOfString(pValue); return ANSC_STATUS_SUCCESS; }
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; }
void PSM_Set_ParentalControl_ManagedDevices_RecordValues(COSA_DML_MANAGED_DEVS *conf) { int retPsmSet = CCSP_SUCCESS; char param_name[256] = {0}; char param_value[256] = {0}; if(conf->Enable == TRUE) _ansc_sprintf(param_value,"%s","TRUE"); else _ansc_sprintf(param_value,"%s","FALSE"); _PSM_WRITE_PARAMs(PSM_PC_MD_ENABLE); if(conf->AllowAll == TRUE) _ansc_sprintf(param_value,"%s","TRUE"); else _ansc_sprintf(param_value,"%s","FALSE"); _PSM_WRITE_PARAMs(PSM_PC_MD_ALLOWALL); }
BOOL IPv6rdIF_SetParamStringValue( ANSC_HANDLE hInsContext, char *ParamName, char *pString ) { PCOSA_CONTEXT_LINK_OBJECT pLinkObject = (PCOSA_CONTEXT_LINK_OBJECT)hInsContext; PCOSA_DML_IPV6RD_IF pEntry = (PCOSA_DML_IPV6RD_IF)pLinkObject->hContext; char v4addr[16]; ULONG addlen; char tmp[128]; if (!pLinkObject || !pEntry) return FALSE; if (AnscEqualString(ParamName, "Alias", TRUE)) { AnscCopyString(pEntry->Alias, pString); return TRUE; } else if (AnscEqualString(ParamName, "BorderRelayIPv4Addresses", TRUE)) { AnscCopyString(pEntry->BorderRelayIPv4Addr, pString); return TRUE; } else if (AnscEqualString(ParamName, "SPIPv6Prefix", TRUE)) { AnscCopyString(pEntry->SPIPv6Prefix, pString); return TRUE; } else if (AnscEqualString(ParamName, "AddressSource", TRUE)) { if (!pString || _ansc_strlen(pString) == 0) { AnscCopyString(pEntry->AddressSource, ""); return TRUE; } addlen = sizeof(v4addr); _ansc_sprintf(tmp, "%sIPAddress", pString); if (g_GetParamValueString(g_pDslhDmlAgent, tmp, v4addr, &addlen) != 0) { CcspTraceWarning(("IPv6rdIF_SetParamStringValue: fail to get %s\n", tmp)); return FALSE; } AnscCopyString(pEntry->AddressSource, v4addr); /* AnscCopyString(pEntry->AddressSource, pString); */ return TRUE; } return FALSE; }
ANSC_STATUS ssp_cancel_wifi ( PCCSP_COMPONENT_CFG pStartCfg ) { int nRet = 0; char CrName[256]; char CpName[256]; if( pDslhCpeController == NULL) { return ANSC_STATUS_SUCCESS; } if ( g_Subsystem[0] != 0 ) { _ansc_sprintf(CrName, "%s%s", g_Subsystem, CCSP_DBUS_INTERFACE_CR); _ansc_sprintf(CpName, "%s%s", g_Subsystem, pStartCfg->ComponentName); } else { _ansc_sprintf(CrName, "%s", CCSP_DBUS_INTERFACE_CR); _ansc_sprintf(CpName, "%s", pStartCfg->ComponentName); } /* unregister component */ nRet = CcspBaseIf_unregisterComponent(bus_handle, CrName, CpName ); AnscTrace("unregisterComponent returns %d\n", nRet); pDslhCpeController->Cancel((ANSC_HANDLE)pDslhCpeController); AnscFreeMemory(pDslhCpeController); pDslhCpeController = NULL; return ANSC_STATUS_SUCCESS; }
ANSC_HANDLE BspTemplateWriterWriteHex ( ANSC_HANDLE hThisObject, ULONG ulNum ) { PBSP_TEMPLATE_WRITER_OBJECT pMyObject = (PBSP_TEMPLATE_WRITER_OBJECT)hThisObject; char buf[16]; ULONG ulLen; ulLen = _ansc_sprintf(buf, "0x%.8x", ulNum); pMyObject->WriteBytes(hThisObject, buf, &ulLen); return hThisObject; }
ANSC_STATUS CosaNatGenForTriggerEntry ( ANSC_HANDLE hDml, PCOSA_DML_NAT_PTRIGGER pEntry ) { ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; PCOSA_DATAMODEL_NAT pNat = (PCOSA_DATAMODEL_NAT)g_pCosaBEManager->hNat; /* For dynamic and writable table, we don't keep the Maximum InstanceNumber. If there is delay_added entry, we just jump that InstanceNumber. */ do { if ( pNat->ulPtNextInstanceNumber == 0 ) { pNat->ulPtNextInstanceNumber = 1; } if ( !CosaSListGetEntryByInsNum(&pNat->NatPTriggerList, pNat->ulPtNextInstanceNumber) ) { break; } else { pNat->ulPtNextInstanceNumber++; } }while(1); pEntry->InstanceNumber = pNat->ulPtNextInstanceNumber; if ( pEntry->Alias[0] == '\0' ) { _ansc_sprintf( pEntry->Alias, "PortTrigger%d", pEntry->InstanceNumber ); } pNat->ulPtNextInstanceNumber++; /* keep new ulPtInstanceNumber */ returnStatus = CosaNatRegSetNatInfo(pNat); return returnStatus; }
static int tableGroupGetSubDMMapping ( ANSC_HANDLE hThisObject, char* pSubDM, int indexes[3] ) { PCCSP_TABLE_HELPER_OBJECT pThisObject = (PCCSP_TABLE_HELPER_OBJECT)hThisObject; int size = 0; parameterValStruct_t** paramValues = NULL; parameterValStruct_t* pValue = NULL; char pTemp[256] = { 0 }; char* pSubDMName = pTemp; int iReturn = 0; int uDMType; _ansc_sprintf(pTemp, pSubDM, indexes[0], indexes[1], indexes[2]); if( !Cosa_GetParamValues(pThisObject->pCcspComp, pThisObject->pCcspPath, &pSubDMName, 1, &size, ¶mValues)) { AnscTraceError(("Failed to get value of '%s'\n", pTemp)); } else { pValue = paramValues[0]; if (pValue->parameterName && pValue->parameterValue) CcspTraceDebug(("Index SubDM: %s %s\n", pValue->parameterName, pValue->parameterValue)); uDMType = (int)pValue->type; if( uDMType == ccsp_int || uDMType == ccsp_long || uDMType == ccsp_unsignedInt || uDMType == ccsp_unsignedLong) { iReturn = atoi(pValue->parameterValue); } else { AnscTraceError(("Index SubDM, Invalid data type. %s %s\n", pValue->parameterName, pValue->parameterValue)); } } Cosa_FreeParamValues(size, paramValues); return iReturn; }
PUCHAR AnscDupMacAddr ( PUCHAR pStr ) { /* this function generate string format of a IP4 address */ if (!pStr) { return NULL; } else { ULONG ulStrLen; PUCHAR pDupStr; /* xx-xx-xx-xx-xx-xx */ ulStrLen = 3 * ANSC_MAX_MAC_ADDRESS_SIZE; pDupStr = (PUCHAR)AnscAllocateMemory(ulStrLen); if (pDupStr) { _ansc_sprintf ( pDupStr, "%.2X-%.2X-%.2X-%.2X-%.2X-%.2X", pStr[0], pStr[1], pStr[2], pStr[3], pStr[4], pStr[5] ); } return pDupStr; } }
ANSC_STATUS CosaNatGen ( ANSC_HANDLE hDml, PCOSA_DML_NAT_PMAPPING pEntry ) { ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; PCOSA_DATAMODEL_NAT pNat = (PCOSA_DATAMODEL_NAT)g_pCosaBEManager->hNat; /* For dynamic and writable table, we don't keep the Maximum InstanceNumber. If there is delay_added entry, we just jump that InstanceNumber. */ do { pNat->MaxInstanceNumber++; if ( pNat->MaxInstanceNumber <= 0 ) { pNat->MaxInstanceNumber = 1; } if ( !CosaSListGetEntryByInsNum(&pNat->NatPMappingList, pNat->MaxInstanceNumber) ) { break; } }while(1); pEntry->InstanceNumber = pNat->MaxInstanceNumber; _ansc_sprintf( pEntry->Alias, "PortMapping%d", pEntry->InstanceNumber ); /* keep new MaxInstanceNumber */ returnStatus = CosaNatRegSetNatInfo(pNat); return returnStatus; }
void PSM_Set_ParentalControl_ManagedServices_Trusted_RecordValues(COSA_DML_MS_TRUSTEDUSER *pEntry) { int retPsmSet = CCSP_SUCCESS; char param_name[256] = {0}; char param_value[256] = {0}; ULONG instancenum = pEntry->InstanceNumber; _ansc_sprintf(param_value,"%s",pEntry->HostDescription); _PSM_WRITE_PARAM(PSM_PC_MSE_TRUSTED_HOST_DESCRIPTION); _ansc_sprintf(param_value,"%s",pEntry->IPAddress); _PSM_WRITE_PARAM(PSM_PC_MSE_TRUSTED_IPADDRESS); if(pEntry->Trusted == TRUE) _ansc_sprintf(param_value,"%s","TRUE"); else _ansc_sprintf(param_value,"%s","FALSE"); _PSM_WRITE_PARAM(PSM_PC_MSE_TRUSTED_ENABLE); if(pEntry->IPAddressType == IPADDR_IPV4) _ansc_sprintf(param_value,"%s","IPv4"); else _ansc_sprintf(param_value,"%s","IPv6"); _PSM_WRITE_PARAM(PSM_PC_MSE_TRUSTED_IPADDRESS_TYPE); }
ANSC_STATUS ssp_engage_wifi ( PCCSP_COMPONENT_CFG pStartCfg ) { ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; char CrName[256] = {0}; PCCSP_DM_XML_CFG_LIST pXmlCfgList = NULL; g_pComponent_Common_Dm->Health = CCSP_COMMON_COMPONENT_HEALTH_Yellow; if ( pWifiCcdIf ) { pWifiFcContext->hCcspCcdIf = (ANSC_HANDLE)pWifiCcdIf; pWifiFcContext->hMessageBus = bus_handle; } g_DslhDataModelAgent->SetFcContext((ANSC_HANDLE)g_DslhDataModelAgent, (ANSC_HANDLE)pWifiFcContext); pDslhCpeController->AddInterface((ANSC_HANDLE)pDslhCpeController, (ANSC_HANDLE)MsgHelper_CreateCcdMbiIf((void*)bus_handle,g_Subsystem)); pDslhCpeController->AddInterface((ANSC_HANDLE)pDslhCpeController, (ANSC_HANDLE)pWifiCcdIf); pDslhCpeController->SetDbusHandle((ANSC_HANDLE)pDslhCpeController, bus_handle); pDslhCpeController->Engage((ANSC_HANDLE)pDslhCpeController); if ( g_Subsystem[0] != 0 ) { _ansc_sprintf(CrName, "%s%s", g_Subsystem, CCSP_DBUS_INTERFACE_CR); } else { _ansc_sprintf(CrName, "%s", CCSP_DBUS_INTERFACE_CR); } returnStatus = CcspComponentLoadDmXmlList(pStartCfg->DmXmlCfgFileName, &pXmlCfgList); if ( returnStatus != ANSC_STATUS_SUCCESS ) { return returnStatus; } returnStatus = pDslhCpeController->RegisterCcspDataModel ( (ANSC_HANDLE)pDslhCpeController, CrName, /* CCSP CR ID */ pXmlCfgList->FileList[0], /* Data Model XML file. Can be empty if only base data model supported. */ pStartCfg->ComponentName, /* Component Name */ pStartCfg->Version, /* Component Version */ pStartCfg->DbusPath, /* Component Path */ g_Subsystem /* Component Prefix */ ); if ( returnStatus == ANSC_STATUS_SUCCESS || returnStatus == CCSP_SUCCESS ) { /* System is fully initialized */ g_pComponent_Common_Dm->Health = CCSP_COMMON_COMPONENT_HEALTH_Green; } AnscFreeMemory(pXmlCfgList); return ANSC_STATUS_SUCCESS; }
ANSC_STATUS CosaNatRegSetNatInfo ( ANSC_HANDLE hThisObject ) { ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; PCOSA_DATAMODEL_NAT pMyObject = (PCOSA_DATAMODEL_NAT )hThisObject; PPOAM_IREP_FOLDER_OBJECT pPoamIrepFoNat = (PPOAM_IREP_FOLDER_OBJECT)pMyObject->hIrepFolderNat; PPOAM_IREP_FOLDER_OBJECT pPoamIrepFoNatPt = (PPOAM_IREP_FOLDER_OBJECT)NULL; PPOAM_IREP_FOLDER_OBJECT pPoamIrepFoEnumNat = (PPOAM_IREP_FOLDER_OBJECT)NULL; PCOSA_CONTEXT_LINK_OBJECT pCosaNatContext = NULL; PCOSA_DML_NAT_PMAPPING pCosaNat = NULL; PCOSA_DML_NAT_PTRIGGER pCosaNatPt = NULL; PSINGLE_LINK_ENTRY pSLinkEntry = (PSINGLE_LINK_ENTRY )NULL; PSLAP_VARIABLE pSlapVariable = NULL; ULONG ulEntryCount = 0; ULONG ulIndex = 0; ULONG uInstanceNumber = 0; char* pAliasNat = NULL; char* pFolderName = NULL; char FolderName[16] = {0}; if ( !pPoamIrepFoNat ) { return ANSC_STATUS_FAILURE; } else { pPoamIrepFoNat->EnableFileSync((ANSC_HANDLE)pPoamIrepFoNat, FALSE); } if ( TRUE ) { pPoamIrepFoNat->Clear((ANSC_HANDLE)pPoamIrepFoNat); SlapAllocVariable(pSlapVariable); if ( !pSlapVariable ) { returnStatus = ANSC_STATUS_RESOURCES; goto EXIT1; } } /* This is saved structure for Nat ***************************************** <Nat> <PortMapping> <1> <alias>xxx</> <bNew>false</> </1> <2> <alias>xxx</> <bNew>false</> </2> </PortMapping> </Nat> ******************************************/ pSLinkEntry = AnscSListGetFirstEntry(&pMyObject->NatPMappingList); while ( pSLinkEntry ) { /* create nat.{i} */ pCosaNatContext = ACCESS_COSA_CONTEXT_LINK_OBJECT(pSLinkEntry); pSLinkEntry = AnscSListGetNextEntry(pSLinkEntry); pCosaNat = (PCOSA_DML_NAT_PMAPPING)pCosaNatContext->hContext; if ( !pCosaNatContext->bNew ) { continue; } _ansc_sprintf(FolderName, "%d", pCosaNat->InstanceNumber); pPoamIrepFoEnumNat = pPoamIrepFoNat->AddFolder ( (ANSC_HANDLE)pPoamIrepFoNat, FolderName, 0 ); if ( !pPoamIrepFoEnumNat ) { continue; } /* add nat.{i}.Alias */ if ( TRUE ) { pSlapVariable->Syntax = SLAP_VAR_SYNTAX_string; pSlapVariable->Variant.varString = AnscCloneString(pCosaNat->Alias); returnStatus = pPoamIrepFoEnumNat->AddRecord ( (ANSC_HANDLE)pPoamIrepFoEnumNat, COSA_DML_RR_NAME_NATAlias, SYS_REP_RECORD_TYPE_ASTR, SYS_RECORD_CONTENT_DEFAULT, pSlapVariable, 0 ); SlapCleanVariable(pSlapVariable); SlapInitVariable (pSlapVariable); } /* add nat.{i}.bNew */ if ( TRUE ) { pSlapVariable->Syntax = SLAP_VAR_SYNTAX_bool; pSlapVariable->Variant.varBool = pCosaNatContext->bNew; returnStatus = pPoamIrepFoEnumNat->AddRecord ( (ANSC_HANDLE)pPoamIrepFoEnumNat, COSA_DML_RR_NAME_NATbNew, SYS_REP_RECORD_TYPE_BOOL, SYS_RECORD_CONTENT_DEFAULT, pSlapVariable, 0 ); SlapCleanVariable(pSlapVariable); SlapInitVariable (pSlapVariable); } /*release some resource */ pPoamIrepFoEnumNat->Remove((ANSC_HANDLE)pPoamIrepFoEnumNat); pPoamIrepFoEnumNat = NULL; } /* For PortTrigger */ /* This is saved structure for Nat ***************************************** <Nat> <PortTrigger> <NextInsNumber>xxx</> <1> <alias>xxx</> <bNew>true</> </1> <2> <alias>xxx</> <bNew>true</> </2> </PortTrigger> </Nat> ******************************************/ pPoamIrepFoNatPt = pPoamIrepFoNat->AddFolder ( (ANSC_HANDLE)pPoamIrepFoNat, COSA_IREP_FOLDER_NAME_PORTTRIGGER, 0 ); if ( !pPoamIrepFoNatPt ) { returnStatus = ANSC_STATUS_FAILURE; goto EXIT1; } /* Save next instance number for port trigger */ if ( TRUE ) { pSlapVariable->Syntax = SLAP_VAR_SYNTAX_uint32; pSlapVariable->Variant.varUint32 = pMyObject->ulPtNextInstanceNumber; returnStatus = pPoamIrepFoNatPt->AddRecord ( (ANSC_HANDLE)pPoamIrepFoNatPt, COSA_DML_RR_NAME_NATNextInsNumber, SYS_REP_RECORD_TYPE_UINT, SYS_RECORD_CONTENT_DEFAULT, pSlapVariable, 0 ); SlapCleanVariable(pSlapVariable); SlapInitVariable (pSlapVariable); } pSLinkEntry = AnscSListGetFirstEntry(&pMyObject->NatPTriggerList); while ( pSLinkEntry ) { /* create nat.PortTrigger.{i} */ pCosaNatContext = ACCESS_COSA_CONTEXT_LINK_OBJECT(pSLinkEntry); pSLinkEntry = AnscSListGetNextEntry(pSLinkEntry); pCosaNatPt = (PCOSA_DML_NAT_PTRIGGER)pCosaNatContext->hContext; if ( !pCosaNatContext->bNew ) { continue; } _ansc_sprintf(FolderName, "%d", pCosaNatPt->InstanceNumber); pPoamIrepFoEnumNat = pPoamIrepFoNatPt->AddFolder ( (ANSC_HANDLE)pPoamIrepFoNatPt, FolderName, 0 ); if ( !pPoamIrepFoEnumNat ) { continue; } /* add PortTrigger.{i}.Alias */ if ( TRUE ) { pSlapVariable->Syntax = SLAP_VAR_SYNTAX_string; pSlapVariable->Variant.varString = AnscCloneString(pCosaNatPt->Alias); returnStatus = pPoamIrepFoEnumNat->AddRecord ( (ANSC_HANDLE)pPoamIrepFoEnumNat, COSA_DML_RR_NAME_NATAlias, SYS_REP_RECORD_TYPE_ASTR, SYS_RECORD_CONTENT_DEFAULT, pSlapVariable, 0 ); SlapCleanVariable(pSlapVariable); SlapInitVariable (pSlapVariable); } /* add PortTrigger.{i}.bNew */ if ( TRUE ) { pSlapVariable->Syntax = SLAP_VAR_SYNTAX_bool; pSlapVariable->Variant.varBool = pCosaNatContext->bNew; returnStatus = pPoamIrepFoEnumNat->AddRecord ( (ANSC_HANDLE)pPoamIrepFoEnumNat, COSA_DML_RR_NAME_NATbNew, SYS_REP_RECORD_TYPE_BOOL, SYS_RECORD_CONTENT_DEFAULT, pSlapVariable, 0 ); SlapCleanVariable(pSlapVariable); SlapInitVariable (pSlapVariable); } /*release some resource */ pPoamIrepFoEnumNat->Remove((ANSC_HANDLE)pPoamIrepFoEnumNat); pPoamIrepFoEnumNat = NULL; } EXIT1: if ( pSlapVariable ) { SlapFreeVariable(pSlapVariable); pSlapVariable = NULL; } if ( pPoamIrepFoEnumNat ) pPoamIrepFoEnumNat->Remove((ANSC_HANDLE)pPoamIrepFoEnumNat); pPoamIrepFoNat->EnableFileSync((ANSC_HANDLE)pPoamIrepFoNat, TRUE); return returnStatus; }
ANSC_STATUS CosaDdnsInitialize ( ANSC_HANDLE hThisObject ) { ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; PCOSA_DATAMODEL_DDNS pMyObject = (PCOSA_DATAMODEL_DDNS )hThisObject; PSLIST_HEADER pListHead = (PSLIST_HEADER )&pMyObject->ContextHead; PCOSA_DML_DDNS_CFG pDdnsCfg = (PCOSA_DML_DDNS_CFG )NULL; PCOSA_CONTEXT_LINK_OBJECT pCosaContext = (PCOSA_CONTEXT_LINK_OBJECT)NULL; PCOSA_DML_DDNS_SERVICE pDdnsService = (PCOSA_DML_DDNS_SERVICE )NULL; PPOAM_IREP_FOLDER_OBJECT pPoamIrepFoCOSA = (PPOAM_IREP_FOLDER_OBJECT )NULL; PPOAM_IREP_FOLDER_OBJECT pPoamIrepFoDdns = (PPOAM_IREP_FOLDER_OBJECT )NULL; PSLAP_VARIABLE pSlapVariable = (PSLAP_VARIABLE )NULL; ULONG ulServiceCount = 0; ULONG ulIndex = 0; returnStatus = CosaDmlDdnsInit(NULL, NULL); if ( returnStatus != ANSC_STATUS_SUCCESS ) { return returnStatus; } /* Initiation all functions */ pMyObject->ulNextInstance = 1; AnscSListInitializeHeader(&pMyObject->ContextHead); pDdnsCfg = AnscAllocateMemory(sizeof(COSA_DML_DDNS_CFG)); if ( !pDdnsCfg ) { CcspTraceWarning(("X_CISCO_COM_DDNS Resource allocation error\n")); return ANSC_STATUS_RESOURCES; } returnStatus = CosaDmlDdnsGetConfig(NULL, pDdnsCfg); if ( returnStatus != ANSC_STATUS_SUCCESS ) { goto EXIT1; } pMyObject->DdnsConfig.bEnabled = pDdnsCfg->bEnabled; pMyObject->hIrepFolderCOSA = g_GetRegistryRootFolder(g_pDslhDmlAgent); pPoamIrepFoCOSA = (PPOAM_IREP_FOLDER_OBJECT)pMyObject->hIrepFolderCOSA; if ( !pPoamIrepFoCOSA ) { returnStatus = ANSC_STATUS_FAILURE; goto EXIT1; } pPoamIrepFoDdns = (PPOAM_IREP_FOLDER_OBJECT)pPoamIrepFoCOSA->GetFolder ( (ANSC_HANDLE)pPoamIrepFoCOSA, COSA_IREP_FOLDER_NAME_DDNS ); if ( !pPoamIrepFoDdns ) { pPoamIrepFoDdns = pPoamIrepFoCOSA->AddFolder ( (ANSC_HANDLE)pPoamIrepFoCOSA, COSA_IREP_FOLDER_NAME_DDNS, 0 ); } if ( !pPoamIrepFoDdns ) { returnStatus = ANSC_STATUS_FAILURE; goto EXIT1; } else { pMyObject->hIrepFolderDdns = (ANSC_HANDLE)pPoamIrepFoDdns; } /* Retrieve Next Instance Number */ if ( TRUE ) { pSlapVariable = (PSLAP_VARIABLE)pPoamIrepFoDdns->GetRecord ( (ANSC_HANDLE)pPoamIrepFoDdns, COSA_DML_RR_NAME_DdnsServiceNextInsNumber, NULL ); if ( pSlapVariable ) { pMyObject->ulNextInstance = pSlapVariable->Variant.varUint32; SlapFreeVariable(pSlapVariable); } } /* Initialize middle layer */ ulServiceCount = CosaDmlDdnsGetNumberOfServices(NULL); for ( ulIndex = 0; ulIndex < ulServiceCount; ulIndex++ ) { pDdnsService = (PCOSA_DML_DDNS_SERVICE)AnscAllocateMemory(sizeof(COSA_DML_DDNS_SERVICE)); if ( !pDdnsService ) { returnStatus = ANSC_STATUS_RESOURCES; goto EXIT1; } returnStatus = CosaDmlDdnsGetService(NULL, ulIndex, pDdnsService); if ( returnStatus == ANSC_STATUS_SUCCESS ) { pCosaContext = (PCOSA_CONTEXT_LINK_OBJECT)AnscAllocateMemory(sizeof(COSA_CONTEXT_LINK_OBJECT)); if ( !pCosaContext ) { returnStatus = ANSC_STATUS_RESOURCES; goto EXIT2; } if ( pDdnsService->InstanceNumber != 0 ) { pCosaContext->InstanceNumber = pDdnsService->InstanceNumber; if ( pMyObject->ulNextInstance <= pDdnsService->InstanceNumber ) { pMyObject->ulNextInstance = pDdnsService->InstanceNumber + 1; if ( pMyObject->ulNextInstance == 0 ) { pMyObject->ulNextInstance = 1; } } } else { pDdnsService->InstanceNumber = pCosaContext->InstanceNumber = pMyObject->ulNextInstance; pMyObject->ulNextInstance++; if ( pMyObject->ulNextInstance == 0 ) { pMyObject->ulNextInstance = 1; } /* Generate Alias */ _ansc_sprintf(pDdnsService->Alias, "DdnsService%d", pCosaContext->InstanceNumber); returnStatus = CosaDmlDdnsServiceSetValues ( NULL, ulIndex, pCosaContext->InstanceNumber, pDdnsService->Alias ); if ( returnStatus != ANSC_STATUS_SUCCESS ) { CcspTraceWarning(("!!! CosaDmlDdnsServiceSetValues index: %d-- fail !!!\n", ulIndex)); AnscFreeMemory(pDdnsService); AnscFreeMemory(pCosaContext); continue; } } pCosaContext->hContext = (ANSC_HANDLE)pDdnsService; pCosaContext->hParentTable = NULL; pCosaContext->bNew = FALSE; CosaSListPushEntryByInsNum(pListHead, pCosaContext); } } /* Load the newly added but not yet committed entries, if exist */ CosaDdnsRegGetDdnsInfo((ANSC_HANDLE)pMyObject); goto EXIT1; EXIT2: AnscFreeMemory(pDdnsService); EXIT1: AnscFreeMemory(pDdnsCfg); return returnStatus; }
ANSC_STATUS CosaUsersRegSetUserInfo ( ANSC_HANDLE hThisObject ) { ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; PCOSA_DATAMODEL_USERS pMyObject = (PCOSA_DATAMODEL_USERS )hThisObject; PPOAM_IREP_FOLDER_OBJECT pPoamIrepFoUser = (PPOAM_IREP_FOLDER_OBJECT )pMyObject->hIrepFolderUser; PPOAM_IREP_FOLDER_OBJECT pPoamIrepFoEnumUser = (PPOAM_IREP_FOLDER_OBJECT )NULL; PCOSA_CONTEXT_LINK_OBJECT pCosaUserContext = NULL; PCOSA_DML_USER pCosaUser = NULL; PSINGLE_LINK_ENTRY pSLinkEntry = (PSINGLE_LINK_ENTRY )NULL; PSLAP_VARIABLE pSlapVariable = NULL; ULONG ulEntryCount = 0; ULONG ulIndex = 0; ULONG uInstanceNumber = 0; char* pAliasUser = NULL; char* pFolderName = NULL; char FolderName[16] = {0}; if ( !pPoamIrepFoUser ) { return ANSC_STATUS_FAILURE; } else { pPoamIrepFoUser->EnableFileSync((ANSC_HANDLE)pPoamIrepFoUser, FALSE); } if ( TRUE ) { pPoamIrepFoUser->Clear((ANSC_HANDLE)pPoamIrepFoUser); SlapAllocVariable(pSlapVariable); if ( !pSlapVariable ) { returnStatus = ANSC_STATUS_RESOURCES; goto EXIT1; } } /* This is saved structure for user ***************************************** <User> <NextInstanceNumber> xxx </> <1> <alias>xxx</> <bNew>false</> </1> <2> <alias>xxx</> <bNew>false</> </2> </User> **************************************************** */ /* add client.{i}.maxInstanceNumber */ if ( TRUE ) { pSlapVariable->Syntax = SLAP_VAR_SYNTAX_uint32; pSlapVariable->Variant.varUint32 = pMyObject->maxInstanceOfUser; returnStatus = pPoamIrepFoUser->AddRecord ( (ANSC_HANDLE)pPoamIrepFoUser, COSA_DML_RR_NAME_UserNextInsNunmber, SYS_REP_RECORD_TYPE_UINT, SYS_RECORD_CONTENT_DEFAULT, pSlapVariable, 0 ); SlapCleanVariable(pSlapVariable); SlapInitVariable (pSlapVariable); } pSLinkEntry = AnscSListGetFirstEntry(&pMyObject->UserList); while ( pSLinkEntry ) { /* create user.{i} */ pCosaUserContext = ACCESS_COSA_CONTEXT_LINK_OBJECT(pSLinkEntry); pSLinkEntry = AnscSListGetNextEntry(pSLinkEntry); pCosaUser = (PCOSA_DML_USER)pCosaUserContext->hContext; if ( !pCosaUserContext->bNew) { continue; } _ansc_sprintf(FolderName, "%d", pCosaUser->InstanceNumber); pPoamIrepFoEnumUser = pPoamIrepFoUser->AddFolder ( (ANSC_HANDLE)pPoamIrepFoUser, FolderName, 0 ); if ( !pPoamIrepFoEnumUser ) { continue; } /* add user.{i}.Username */ if ( TRUE ) { pSlapVariable->Syntax = SLAP_VAR_SYNTAX_string; pSlapVariable->Variant.varString = AnscCloneString(pCosaUser->Username); returnStatus = pPoamIrepFoEnumUser->AddRecord ( (ANSC_HANDLE)pPoamIrepFoEnumUser, COSA_DML_RR_NAME_UserAlias, SYS_REP_RECORD_TYPE_ASTR, SYS_RECORD_CONTENT_DEFAULT, pSlapVariable, 0 ); SlapCleanVariable(pSlapVariable); SlapInitVariable (pSlapVariable); } /* add user.{i}.bNew */ if ( TRUE ) { pSlapVariable->Syntax = SLAP_VAR_SYNTAX_bool; pSlapVariable->Variant.varBool = pCosaUserContext->bNew; returnStatus = pPoamIrepFoEnumUser->AddRecord ( (ANSC_HANDLE)pPoamIrepFoEnumUser, COSA_DML_RR_NAME_UserbNew, SYS_REP_RECORD_TYPE_BOOL, SYS_RECORD_CONTENT_DEFAULT, pSlapVariable, 0 ); SlapCleanVariable(pSlapVariable); SlapInitVariable (pSlapVariable); } /*release some resource */ pPoamIrepFoEnumUser->Remove((ANSC_HANDLE)pPoamIrepFoEnumUser); pPoamIrepFoEnumUser = NULL; } EXIT1: if ( pSlapVariable ) { SlapFreeVariable(pSlapVariable); pSlapVariable = NULL; } if ( pPoamIrepFoEnumUser ) pPoamIrepFoEnumUser->Remove((ANSC_HANDLE)pPoamIrepFoEnumUser); pPoamIrepFoUser->EnableFileSync((ANSC_HANDLE)pPoamIrepFoUser, TRUE); return returnStatus; }
ANSC_STATUS CosaUsersBackendGetUserInfo ( ANSC_HANDLE hThisObject ) { ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; PCOSA_DATAMODEL_USERS pMyObject = (PCOSA_DATAMODEL_USERS)hThisObject; PCOSA_DML_USER pCosaUser = NULL; ULONG clientCount = 0; ULONG count = 0; ULONG ulIndex = 0; PCOSA_CONTEXT_LINK_OBJECT pUserCxtLink = NULL; PCOSA_CONTEXT_LINK_OBJECT pUserCxtLink2 = NULL; PCOSA_CONTEXT_LINK_OBJECT pCxtLink = NULL; BOOL bNeedSave = FALSE; /* Get Users.user.{i} */ clientCount = CosaDmlUserGetNumberOfEntries(NULL); for ( ulIndex = 0; ulIndex < clientCount; ulIndex++ ) { pCosaUser = (PCOSA_DML_USER)AnscAllocateMemory( sizeof(COSA_DML_USER) ); if ( !pCosaUser ) { break; } USERS_USER_SET_DEFAULTVALUE(pCosaUser); pCosaUser->NumOfFailedAttempts=0; returnStatus = CosaDmlUserGetEntry(NULL, ulIndex, pCosaUser); if ( returnStatus != ANSC_STATUS_SUCCESS ) { AnscFreeMemory(pCosaUser); break; } if (ulIndex == 2) { char buff[128]={'\0'}; syscfg_get( NULL, "hash_password_3",buff, sizeof(buff)); if( buff[0] != '\0' && pCosaUser->HashedPassword[0]== '\0') { _ansc_strncpy(pCosaUser->HashedPassword,buff,sizeof(pCosaUser->HashedPassword)); } } #if defined(_COSA_FOR_BCI_) if (ulIndex == 1) { char buff[128]={'\0'}; syscfg_get( NULL, "hash_password_2",buff, sizeof(buff)); if( buff[0] != '\0' && pCosaUser->HashedPassword[0]== '\0') { _ansc_strncpy(pCosaUser->HashedPassword,buff,sizeof(pCosaUser->HashedPassword)); } pCosaUser->LockOutRemainingTime = 0 ; memset(buff,0,sizeof(buff)); syscfg_get( NULL, "PasswordLockoutAttempts", buff, sizeof(buff)); if( atoi ( buff ) != 10 ) { memset(buff,0,sizeof(buff)); sprintf(buff, "%d", 10); syscfg_set(NULL, "PasswordLockoutAttempts", buff) ; syscfg_commit() ; } memset(buff,0,sizeof(buff)); syscfg_get( NULL, "NumOfFailedAttempts_2", buff, sizeof(buff)); if( buff[0] != '\0' ) { pCosaUser->NumOfFailedAttempts = atoi(buff) ; } memset(buff,0,sizeof(buff)); syscfg_get( NULL, "PasswordLoginCounts_2", buff, sizeof(buff)); if( buff[0] != '\0' ) { pCosaUser->LoginCounts = atoi(buff) ; } } #endif pUserCxtLink = (PCOSA_CONTEXT_LINK_OBJECT)AnscAllocateMemory( sizeof(COSA_CONTEXT_LINK_OBJECT) ); if ( !pUserCxtLink ) { AnscFreeMemory(pCosaUser); break; } COSA_CONTEXT_LINK_INITIATION_CONTENT(pUserCxtLink) pUserCxtLink->hContext = (ANSC_HANDLE)pCosaUser; pUserCxtLink->bNew = FALSE; if ( !pCosaUser->InstanceNumber ) { if ( !++pMyObject->maxInstanceOfUser ) { pMyObject->maxInstanceOfUser = 1; } bNeedSave = TRUE; pCosaUser->InstanceNumber = pMyObject->maxInstanceOfUser; pUserCxtLink->InstanceNumber = pCosaUser->InstanceNumber; _ansc_sprintf(pCosaUser->Username, "Username%d", pCosaUser->InstanceNumber); returnStatus = CosaDmlUserSetValues ( NULL, ulIndex, pCosaUser->InstanceNumber ); if ( returnStatus != ANSC_STATUS_SUCCESS ) { AnscFreeMemory(pCosaUser); AnscFreeMemory(pUserCxtLink); break; } /* Put into our list */ CosaSListPushEntryByInsNum(&pMyObject->UserList, pUserCxtLink); } else { pUserCxtLink->InstanceNumber = pCosaUser->InstanceNumber; if ( pMyObject->maxInstanceOfUser < pUserCxtLink->InstanceNumber ) { pMyObject->maxInstanceOfUser = pUserCxtLink->InstanceNumber; bNeedSave = TRUE; } /* if this entry is in link tree already because it's the parent of delay_added table. */ pUserCxtLink2 = (PCOSA_CONTEXT_LINK_OBJECT)CosaSListGetEntryByInsNum(&pMyObject->UserList, pUserCxtLink->InstanceNumber); if ( !pUserCxtLink2 ) { CosaSListPushEntryByInsNum(&pMyObject->UserList, pUserCxtLink); } else { AnscFreeMemory( pUserCxtLink2->hContext ); pUserCxtLink2->hContext = (ANSC_HANDLE)pCosaUser; if ( pUserCxtLink2->bNew ) { pUserCxtLink2->bNew = FALSE; bNeedSave = TRUE; } AnscFreeMemory(pUserCxtLink); pUserCxtLink = pUserCxtLink2; pUserCxtLink2 = NULL; } } } /* Max InstanceNumber is changed. Save now.*/ if (bNeedSave) { CosaUsersRegSetUserInfo(pMyObject); } return returnStatus; }
ANSC_STATUS CcspCwmpAcscoHttpBspBrowse ( ANSC_HANDLE hThisObject, ANSC_HANDLE hBmoReq, ANSC_HANDLE hBmoRep, ANSC_HANDLE hReqContext ) { ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; PCCSP_CWMP_ACS_CONNECTION_OBJECT pMyObject = (PCCSP_CWMP_ACS_CONNECTION_OBJECT)hThisObject; PHTTP_BMO_REQ_OBJECT pHttpBmoReq = (PHTTP_BMO_REQ_OBJECT )hBmoReq; PHTTP_BMO_REP_OBJECT pHttpBmoRep = (PHTTP_BMO_REP_OBJECT )hBmoRep; PANSC_ACS_INTERN_HTTP_CONTENT pHttpGetReq = (PANSC_ACS_INTERN_HTTP_CONTENT )hReqContext; PHTTP_RESPONSE_INFO pHttpRepInfo = (PHTTP_RESPONSE_INFO )pHttpBmoRep->GetRepInfo ((ANSC_HANDLE)pHttpBmoRep); ULONG ulResponseSize = (ULONG )pHttpBmoRep->GetBodySize((ANSC_HANDLE)pHttpBmoRep); char* pHttpResponse = (char* )NULL; char* pHeaderLocation = NULL; char* pCookie = NULL; ULONG ulCode = 0; char* pCookieHeader = NULL; ULONG ulCookieIndex = 0; BOOL bCookiesRemoved = FALSE; if ( pHttpGetReq == NULL) { return ANSC_STATUS_FAILURE; } ulCode = pHttpBmoRep->GetCode((ANSC_HANDLE)pHttpBmoRep); if( HTTP_STATUS_NO_CONTENT == ulCode) /* ACS has nothing to say */ { if( pHttpGetReq != NULL) { pHttpGetReq->ulContentSize = 0; pHttpGetReq->pContent = NULL; pHttpGetReq->bIsRedirect = FALSE; } returnStatus = ANSC_STATUS_SUCCESS; goto EXIT1; } else if( HTTP_STATUS_MOVED_PERMANENTLY != ulCode && HTTP_STATUS_FOUND != ulCode && HTTP_STATUS_OK != ulCode && HTTP_STATUS_UNAUTHORIZED != ulCode && HTTP_STATUS_TEMP_REDIRECT != ulCode ) { returnStatus = ANSC_STATUS_FAILURE; CcspTr069PaTraceDebug(("HttpClient returned code: %d\n", (int)ulCode)); goto EXIT1; } /* save Authorization header value */ if ( TRUE ) { char* pAuthHeaderValue = NULL; /* Authorization header in request */ pAuthHeaderValue = pHttpBmoReq->GetHeaderValueById((ANSC_HANDLE)pHttpBmoReq, HTTP_HEADER_ID_AUTHORIZATION); if ( pMyObject->AuthHeaderValue ) CcspTr069PaFreeMemory(pMyObject->AuthHeaderValue); pMyObject->AuthHeaderValue = CcspTr069PaCloneString(pAuthHeaderValue); } /* look for Set-Cookie headers */ pCookie = pHttpBmoRep->GetHeaderValueById2((ANSC_HANDLE)pHttpBmoRep, HTTP_HEADER_ID_SET_COOKIE2, ulCookieIndex); if ( pCookie && AnscSizeOfString(pCookie) > 0 ) { /* pMyObject->RemoveCookies((ANSC_HANDLE)pMyObject); bCookiesRemoved = TRUE; */ while ( pCookie != NULL && AnscSizeOfString(pCookie) > 0) { pCookieHeader = CcspTr069PaAllocateMemory(AnscSizeOfString(pCookie) + 16); if ( pCookieHeader ) _ansc_sprintf(pCookieHeader, "Set-Cookie2: %s", pCookie); pMyObject->AddCookie((ANSC_HANDLE)pMyObject, pCookieHeader); CcspTr069PaFreeMemory(pCookieHeader); pCookie = pHttpBmoRep->GetHeaderValueById2((ANSC_HANDLE)pHttpBmoRep, HTTP_HEADER_ID_SET_COOKIE2, ++ulCookieIndex); } } /* If Set-Cookie and Set-Cookie2 co-exist happily, we save them all */ ulCookieIndex = 0; pCookie = pHttpBmoRep->GetHeaderValueById2((ANSC_HANDLE)pHttpBmoRep, HTTP_HEADER_ID_SET_COOKIE, ulCookieIndex); if( pCookie != NULL && AnscSizeOfString(pCookie) > 0) { /* if ( !bCookiesRemoved ) { pMyObject->RemoveCookies((ANSC_HANDLE)pMyObject); bCookiesRemoved = TRUE; } */ while ( pCookie && AnscSizeOfString(pCookie) ) { pCookieHeader = CcspTr069PaAllocateMemory(AnscSizeOfString(pCookie) + 16); if ( pCookieHeader ) _ansc_sprintf(pCookieHeader, "Set-Cookie: %s", pCookie); pMyObject->AddCookie((ANSC_HANDLE)pMyObject, pCookieHeader); CcspTr069PaFreeMemory(pCookieHeader); pCookie = pHttpBmoRep->GetHeaderValueById2((ANSC_HANDLE)pHttpBmoRep, HTTP_HEADER_ID_SET_COOKIE, ++ulCookieIndex); } } /* if ( !bCookiesRemoved ) { CcspTr069PaTraceDebug(("No Cookie in the response.\n")); if( pMyObject->NumCookies != 0) { for ( i = 0; i < pMyObject->NumCookies; i ++ ) { CcspTr069PaTraceDebug(("Keep the old cookie: %s\n", pMyObject->Cookies[i])); } } else { CcspTr069PaTraceDebug(("???No cookie exists...\n")); } } */ if( HTTP_STATUS_UNAUTHORIZED == ulCode) { /* make sure if server sends back challenge, terminates the session if otherwise */ char* pWwwAuth = NULL; pHttpGetReq->bUnauthorized = TRUE; pWwwAuth = pHttpBmoRep->GetHeaderValueByName((ANSC_HANDLE)pHttpBmoRep, "WWW-Authenticate"); if ( pWwwAuth ) { returnStatus = ANSC_STATUS_DO_IT_AGAIN; /* ANSC_STATUS_SUCCESS; */ } else { returnStatus = ANSC_STATUS_FAILURE; } goto EXIT1; } if( ulCode == HTTP_STATUS_MOVED_PERMANENTLY || HTTP_STATUS_FOUND == ulCode || HTTP_STATUS_TEMP_REDIRECT == ulCode) { pHeaderLocation = pHttpBmoRep->GetHeaderValueByName((ANSC_HANDLE)pHttpBmoRep, "Location" ); if( pHeaderLocation == NULL || AnscSizeOfString(pHeaderLocation) == 0) { returnStatus = ANSC_STATUS_FAILURE; goto EXIT1; } CcspTr069PaTraceInfo(("ACS URL moved (HTTP code=%u) to: %s\n", ulCode, pHeaderLocation)); pHttpGetReq->ulContentSize = AnscSizeOfString(pHeaderLocation); pHttpGetReq->pContent = CcspTr069PaCloneString(pHeaderLocation); pHttpGetReq->bIsRedirect = TRUE; /* notify underlying HTTP Webc Transaction object to clearn request * otherwise, in case ACS closes the socket first, we will get notified * again and current session will be terminated prematurely. */ returnStatus = ANSC_STATUS_NO_MORE_DATA; } else { if ( ulResponseSize == 0 ) { returnStatus = ANSC_STATUS_FAILURE; goto EXIT1; } else { pHttpResponse = (char*)CcspTr069PaAllocateMemory(ulResponseSize + 1); /* we must leave room for the NULL terminator */ if ( !pHttpResponse ) { returnStatus = ANSC_STATUS_RESOURCES; goto EXIT1; } else { returnStatus = pHttpBmoRep->CopyBodyFrom ( (ANSC_HANDLE)pHttpBmoRep, pHttpResponse, &ulResponseSize ); } } pHttpGetReq->ulContentSize = ulResponseSize; pHttpGetReq->pContent = (PVOID)pHttpResponse; pHttpGetReq->bIsRedirect = FALSE; } /****************************************************************** GRACEFUL ROLLBACK PROCEDURES AND EXIT DOORS ******************************************************************/ EXIT1: if ( pHttpGetReq ) { pHttpGetReq->CompleteStatus = (returnStatus == ANSC_STATUS_DO_IT_AGAIN || returnStatus == ANSC_STATUS_NO_MORE_DATA) ? ANSC_STATUS_SUCCESS : returnStatus; AnscSetEvent(&pHttpGetReq->CompleteEvent); } return returnStatus; }
ANSC_STATUS CcspCwmpAcscoHttpBspPolish ( ANSC_HANDLE hThisObject, ANSC_HANDLE hBmoReq, ANSC_HANDLE hReqContext ) { PCCSP_CWMP_ACS_CONNECTION_OBJECT pMyObject = (PCCSP_CWMP_ACS_CONNECTION_OBJECT)hThisObject; PANSC_ACS_INTERN_HTTP_CONTENT pHttpGetReq = (PANSC_ACS_INTERN_HTTP_CONTENT)hReqContext; ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; PHTTP_BMO_REQ_OBJECT pBmoReqObj = (PHTTP_BMO_REQ_OBJECT)hBmoReq; char pBuffer[64] = { 0 }; ULONG i, len = 0; /* add Authorization header - last good one */ if ( pMyObject->AuthHeaderValue ) { pBmoReqObj->SetHeaderValueByName((ANSC_HANDLE)pBmoReqObj, "Authorization", pMyObject->AuthHeaderValue); } /* * If there's a cookie returned, add the cookie */ for ( i = 0; i < pMyObject->NumCookies; i ++ ) { if ( pMyObject->Cookies[i] == NULL ) break; len += _ansc_strlen(pMyObject->Cookies[i]); } if ( pMyObject->NumCookies == 0 ) { CcspTr069PaTraceDebug(("No Cookie will be added.\n")); } else { char *cookies = (char *)CcspTr069PaAllocateMemory(len + pMyObject->NumCookies*2); if (cookies) { AnscZeroMemory(cookies, len + pMyObject->NumCookies*2); for ( i = 0; i < pMyObject->NumCookies; i ++ ) { if ( pMyObject->Cookies[i] == NULL ) break; _ansc_strcat(cookies, pMyObject->Cookies[i]); if ( i < pMyObject->NumCookies - 1 ) _ansc_strcat(cookies, "; "); } pBmoReqObj->SetHeaderValueByName ( (ANSC_HANDLE)pBmoReqObj, "Cookie", cookies ); CcspTr069PaTraceDebug(("Add Cookie into message: %s\n", cookies)); CcspTr069PaFreeMemory(cookies); } } /* 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( pHttpGetReq ==NULL || pHttpGetReq->SoapMessage == NULL || AnscSizeOfString(pHttpGetReq->SoapMessage) == 0) { /* * An empty HTTP POST MUST NOT contain a SOAPAction header. * An empty HTTP POST MUST NOT contain a Content-Type header. */ pBmoReqObj->SetHeaderValueByName((ANSC_HANDLE)pBmoReqObj, "Content-Length", "0"); /* pBmoReqObj->SetHeaderValueByName((ANSC_HANDLE)pBmoReqObj, "Content-Type", "text/xml;charset=utf-8"); */ } else { pBmoReqObj->SetHeaderValueByName((ANSC_HANDLE)pBmoReqObj, "Content-Type", "text/xml;charset=utf-8"); _ansc_sprintf(pBuffer, "%u", (unsigned int)AnscSizeOfString(pHttpGetReq->SoapMessage)); pBmoReqObj->SetHeaderValueByName((ANSC_HANDLE)pBmoReqObj, "Content-Length", pBuffer); if( pHttpGetReq->MethodName == NULL || AnscSizeOfString(pHttpGetReq->MethodName) == 0) { pBmoReqObj->SetHeaderValueByName((ANSC_HANDLE)pBmoReqObj, "SOAPAction", ""); } else { _ansc_sprintf(pBuffer, "\"%s\"", pHttpGetReq->MethodName); pBmoReqObj->SetHeaderValueByName((ANSC_HANDLE)pBmoReqObj, "SOAPAction", pBuffer); } returnStatus = pBmoReqObj->AppendBody ( pBmoReqObj, pHttpGetReq->SoapMessage, AnscSizeOfString(pHttpGetReq->SoapMessage) ); } return returnStatus; }
BOOL IPv6rdIF_SetParamStringValue( ANSC_HANDLE hInsContext, char *ParamName, char *pString ) { PCOSA_CONTEXT_LINK_OBJECT pLinkObject = (PCOSA_CONTEXT_LINK_OBJECT)hInsContext; PCOSA_DML_IPV6RD_IF pEntry = (PCOSA_DML_IPV6RD_IF)pLinkObject->hContext; char v4addr[16]; ULONG addlen; char tmp[128]; ANSC_STATUS ret=ANSC_STATUS_FAILURE; if (!pLinkObject || !pEntry) return FALSE; if (AnscEqualString(ParamName, "Alias", TRUE)) { char wrapped_inputparam[256]={0}; ret=isValidInput(pString,wrapped_inputparam, AnscSizeOfString(pString), sizeof( wrapped_inputparam )); if(ANSC_STATUS_SUCCESS != ret) return FALSE; AnscCopyString(pEntry->Alias, wrapped_inputparam); return TRUE; } else if (AnscEqualString(ParamName, "BorderRelayIPv4Addresses", TRUE)) { char wrapped_inputparam[256]={0}; ret=isValidInput(pString,wrapped_inputparam, AnscSizeOfString(pString), sizeof( wrapped_inputparam )); if(ANSC_STATUS_SUCCESS != ret) return FALSE; AnscCopyString(pEntry->BorderRelayIPv4Addr, wrapped_inputparam); return TRUE; } else if (AnscEqualString(ParamName, "SPIPv6Prefix", TRUE)) { char wrapped_inputparam[256]={0}; ret=isValidInput(pString,wrapped_inputparam, AnscSizeOfString(pString), sizeof( wrapped_inputparam )); if(ANSC_STATUS_SUCCESS != ret) return FALSE; AnscCopyString(pEntry->SPIPv6Prefix, wrapped_inputparam); return TRUE; } else if (AnscEqualString(ParamName, "AddressSource", TRUE)) { char wrapped_inputparam[256]={0}; ret=isValidInput(pString,wrapped_inputparam, AnscSizeOfString(pString), sizeof( wrapped_inputparam )); if(ANSC_STATUS_SUCCESS != ret) return FALSE; if (( '\0' == wrapped_inputparam[ 0 ] ) || \ ( _ansc_strlen(wrapped_inputparam) == 0) ) { AnscCopyString(pEntry->AddressSource, ""); return TRUE; } addlen = sizeof(v4addr); _ansc_sprintf(tmp, "%sIPAddress", wrapped_inputparam); if (g_GetParamValueString(g_pDslhDmlAgent, tmp, v4addr, &addlen) != 0) { CcspTraceWarning(("IPv6rdIF_SetParamStringValue: fail to get %s\n", tmp)); return FALSE; } AnscCopyString(pEntry->AddressSource, v4addr); /* AnscCopyString(pEntry->AddressSource, pString); */ return TRUE; } return FALSE; }
ANSC_STATUS AnscSctoEngage ( ANSC_HANDLE hThisObject ) { ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; PANSC_SIMPLE_CLIENT_TCP_OBJECT pMyObject = (PANSC_SIMPLE_CLIENT_TCP_OBJECT)hThisObject; PANSC_SCTO_WORKER_OBJECT pWorker = (PANSC_SCTO_WORKER_OBJECT )pMyObject->hWorker; int s_error = 0; ansc_socket_addr_in ansc_client_addr; ansc_socket_addr_in ansc_server_addr; xskt_socket_addr_in xskt_client_addr; xskt_socket_addr_in xskt_server_addr; #ifdef _ANSC_IPV6_COMPATIBLE_ ansc_addrinfo ansc_hints = {0}; ansc_addrinfo* pansc_server_addrinfo = NULL; ansc_addrinfo* pansc_client_addrinfo = NULL; xskt_addrinfo xskt_hints = {0}; xskt_addrinfo* pxskt_server_addrinfo = NULL; xskt_addrinfo* pxskt_client_addrinfo = NULL; USHORT usPort = 0; char port[6] = {0}; #endif if ( pMyObject->bActive ) { return ANSC_STATUS_SUCCESS; } else if ( !pWorker ) { return ANSC_STATUS_UNAPPLICABLE; } else { /* * Just like any other socket-based ANSC object, we will create a separate async recv task * which is dedicated to receiving packets. This async recv task is controlled by 'bActive' * flag. What if at this moment right before we're about to enable the socket operation and * setting 'bActive' flag to TRUE, the old recv task created by the last call of Engage() * is still running? While it may not cause crash, but it certainly confuses the owner * object because all async recv tasks share the same worker interface. The most obvious * solution is to wait for previous recv task to exit before creating a new one. */ while ( pMyObject->EngineTaskCount != 0 ) { AnscSleep(50); } pMyObject->bActive = TRUE; pMyObject->bClosed = FALSE; } /* * The underlying socket wrapper may require an explicit startup() call, such is the case on * Microsoft windows platforms. The wrapper initialization has to done for each task. On most * real-time operating systems, this call is not required. */ if ( pMyObject->Mode & ANSC_SCTO_MODE_XSOCKET ) { AnscStartupXsocketWrapper((ANSC_HANDLE)pMyObject); } else { AnscStartupSocketWrapper((ANSC_HANDLE)pMyObject); } #ifdef _ANSC_IPV6_COMPATIBLE_ if ( pMyObject->Mode & ANSC_SCTO_MODE_XSOCKET ) { xskt_hints.ai_family = AF_UNSPEC; xskt_hints.ai_socktype = XSKT_SOCKET_STREAM; xskt_hints.ai_flags = AI_CANONNAME; usPort = pMyObject->GetPeerPort((ANSC_HANDLE)pMyObject); _ansc_sprintf(port, "%d", usPort); AnscTrace("!!! Peer Port: %s !!!\n", port); char * pPeerName = pMyObject->GetPeerName((ANSC_HANDLE)pMyObject); AnscTrace("Peer Name: %s!!!\n", pPeerName); /* struct addrinfo hints,*res=NULL; memset(&hints,0,sizeof(hints)); hints.ai_family=PF_UNSPEC; hints.ai_socktype=SOCK_DGRAM; hints.ai_protocol=IPPROTO_UDP; s_error=getaddrinfo("127.0.0.1","123",&hints,&res); */ /* s_error = _xskt_getaddrinfo ( "10.74.52.92", port, &xskt_hints, &pxskt_server_addrinfo ); AnscTrace("!!!!!! _xskt_getaddrinfo returns: %d %s !!!\n", s_error, gai_strerror(s_error)); */ if ( _xskt_getaddrinfo ( pMyObject->GetPeerName((ANSC_HANDLE)pMyObject), port, &xskt_hints, &pxskt_server_addrinfo ) || _xskt_getaddrinfo ( "localhost", NULL, &xskt_hints, &pxskt_client_addrinfo ) ) { AnscTrace("!!! error 1 !!!\n"); if ( pMyObject->Mode & ANSC_SCTO_MODE_NO_BSP_NOTIFY_CONN_ERR == 0 ) { pWorker->Notify ( pWorker->hWorkerContext, ANSC_SCTOWO_EVENT_SOCKET_ERROR, (ANSC_HANDLE)NULL ); } returnStatus = ANSC_STATUS_FAILURE; goto EXIT1; } AnscTrace("!!! after getaddrinfo !!!\n"); } else { ansc_hints.ai_family = AF_UNSPEC; ansc_hints.ai_socktype = ANSC_SOCKET_STREAM; ansc_hints.ai_flags = AI_CANONNAME; usPort = pMyObject->GetPeerPort((ANSC_HANDLE)pMyObject); _ansc_sprintf(port, "%d", usPort); if ( _ansc_getaddrinfo ( pMyObject->GetPeerName((ANSC_HANDLE)pMyObject), port, &ansc_hints, &pansc_server_addrinfo ) || _ansc_getaddrinfo ( "localhost", NULL, &ansc_hints, &pansc_client_addrinfo ) ) { if ( pMyObject->Mode & ANSC_SCTO_MODE_NO_BSP_NOTIFY_CONN_ERR == 0 ) { pWorker->Notify ( pWorker->hWorkerContext, ANSC_SCTOWO_EVENT_SOCKET_ERROR, (ANSC_HANDLE)NULL ); } returnStatus = ANSC_STATUS_FAILURE; goto EXIT1; } } #endif /* * To engage the Tcp Client, we need to perform following acts in the respective order: * * (1) create the os-dependent socket * (2) bind to the newly socket * (3) connect to the specified server address * (4) allocate a buffer for receiving * (5) spawn a separate thread and start receiving */ if ( pMyObject->Mode & ANSC_SCTO_MODE_XSOCKET ) { #ifdef _ANSC_IPV6_COMPATIBLE_ pMyObject->Socket = (ANSC_SOCKET)_xskt_socket(pxskt_server_addrinfo->ai_family, pxskt_server_addrinfo->ai_socktype, 0); #else pMyObject->Socket = (ANSC_SOCKET)_xskt_socket(XSKT_SOCKET_AF_INET, XSKT_SOCKET_STREAM, 0); #endif if ( (XSKT_SOCKET)pMyObject->Socket == XSKT_SOCKET_INVALID_SOCKET ) { AnscTrace("!!!!!!!!!! _xskt_socket error !!!!!!!!!!\n"); if ( pMyObject->Mode & ANSC_SCTO_MODE_NO_BSP_NOTIFY_CONN_ERR == 0 ) { pWorker->Notify ( pWorker->hWorkerContext, ANSC_SCTOWO_EVENT_SOCKET_ERROR, (ANSC_HANDLE)NULL ); } returnStatus = ANSC_STATUS_FAILURE; goto EXIT1; } else AnscTrace("Opening IPv4 socket Ok\n"); } else { #ifdef _ANSC_IPV6_COMPATIBLE_ pMyObject->Socket = _ansc_socket(pansc_server_addrinfo->ai_family, pansc_server_addrinfo->ai_socktype, 0); #else pMyObject->Socket = _ansc_socket(ANSC_SOCKET_AF_INET, ANSC_SOCKET_STREAM, 0); #endif if ( pMyObject->Socket == ANSC_SOCKET_INVALID_SOCKET ) { if ( pMyObject->Mode & ANSC_SCTO_MODE_NO_BSP_NOTIFY_CONN_ERR == 0 ) { pWorker->Notify ( pWorker->hWorkerContext, ANSC_SCTOWO_EVENT_SOCKET_ERROR, (ANSC_HANDLE)NULL ); } returnStatus = ANSC_STATUS_FAILURE; goto EXIT1; } } /* * Normally we don't need to know which local network interface we shall bind to, and the * underlying operating system usually supports such notation as "any address". */ #ifndef _ANSC_IPV6_COMPATIBLE_ if ( pMyObject->Mode & ANSC_SCTO_MODE_XSOCKET ) { xskt_client_addr.sin_family = XSKT_SOCKET_AF_INET; xskt_client_addr.sin_port = _xskt_htons(pMyObject->HostPort); if (pMyObject->bSocketBindToDevice && *(pMyObject->SocketDeviceName)) { if (_xskt_setsocketopt ( pMyObject->Socket, XSKT_SOCKET_SOL_SOCKET, XSKT_SOCKET_SO_BINDTODEVICE, pMyObject->SocketDeviceName, _ansc_strlen(pMyObject->SocketDeviceName) + 1 ) < 0) { perror("setsockopt-SOL_SOCKET-SO_BINDTODEVICE"); returnStatus = ANSC_STATUS_FAILURE; goto EXIT2; } } // fprintf(stderr, "<RT XSKT> Binding socket to Device '%s'.\n", pMyObject->SocketDeviceName); if ( pMyObject->HostAddress.Value == 0 ) { ((pansc_socket_addr_in)&xskt_client_addr)->sin_addr.s_addr = XSKT_SOCKET_ANY_ADDRESS; } else { ((pansc_socket_addr_in)&xskt_client_addr)->sin_addr.s_addr = pMyObject->HostAddress.Value; } if ( _xskt_bind((XSKT_SOCKET)pMyObject->Socket, (xskt_socket_addr*)&xskt_client_addr, sizeof(xskt_client_addr)) != 0 ) { AnscTrace("!!!!!!!!!! _xskt_bind error: socket=%d, error=%d !!!!!!!!!!\n", (XSKT_SOCKET)pMyObject->Socket, errno); { int j; char s[256]; char *ptr1 = ((xskt_socket_addr*)(&xskt_client_addr))->sa_data; char stmp[16]; s[0] = '\0'; for(j=0; j<13; j++) { sprintf(stmp, "%.2x:", *(ptr1++)); strcat(s, stmp); } sprintf(stmp, "%.2x", *ptr1); strcat(s, stmp); AnscTrace("!!!!!!!!!! _xskt_bind error: client_addr=%s\n", s); } perror("_xskt_bind error"); if ( pMyObject->Mode & ANSC_SCTO_MODE_NO_BSP_NOTIFY_CONN_ERR == 0 ) { pWorker->Notify ( pWorker->hWorkerContext, ANSC_SCTOWO_EVENT_SOCKET_ERROR, (ANSC_HANDLE)NULL ); } returnStatus = ANSC_STATUS_FAILURE; goto EXIT2; } } else { ansc_client_addr.sin_family = ANSC_SOCKET_AF_INET; ansc_client_addr.sin_port = _ansc_htons(pMyObject->HostPort); if (pMyObject->bSocketBindToDevice && *(pMyObject->SocketDeviceName)) { if (_xskt_setsocketopt ( pMyObject->Socket, ANSC_SOCKET_SOL_SOCKET, ANSC_SOCKET_SO_BINDTODEVICE, pMyObject->SocketDeviceName, _ansc_strlen(pMyObject->SocketDeviceName) + 1 ) < 0) { perror("setsockopt-SOL_SOCKET-SO_BINDTODEVICE"); returnStatus = ANSC_STATUS_FAILURE; goto EXIT2; } } // fprintf(stderr, "<RT AnscSKT> Binding socket to Device '%s'.\n", pMyObject->SocketDeviceName); if ( pMyObject->HostAddress.Value == 0 ) { ansc_client_addr.sin_addr.s_addr = ANSC_SOCKET_ANY_ADDRESS; } else { ansc_client_addr.sin_addr.s_addr = pMyObject->HostAddress.Value; } if ( _ansc_bind(pMyObject->Socket, (ansc_socket_addr*)&ansc_client_addr, sizeof(ansc_client_addr)) != 0 ) { AnscTrace("!!!!!!!!!! _ansc_bind error: socket=%d, error=%d !!!!!!!!!!\n", (XSKT_SOCKET)pMyObject->Socket, errno); { int j; char s[256]; char *ptr1 = ((ansc_socket_addr*)(&ansc_client_addr))->sa_data; char stmp[16]; s[0] = '\0'; for(j=0; j<13; j++) { sprintf(stmp, "%.2x:", *(ptr1++)); strcat(s, stmp); } sprintf(stmp, "%.2x", *ptr1); strcat(s, stmp); AnscTrace("!!!!!!!!!! _ansc_bind error: client_addr=%s\n", s); } perror("_ansc_bind error"); if ( pMyObject->Mode & ANSC_SCTO_MODE_NO_BSP_NOTIFY_CONN_ERR == 0 ) { pWorker->Notify ( pWorker->hWorkerContext, ANSC_SCTOWO_EVENT_SOCKET_ERROR, (ANSC_HANDLE)NULL ); } returnStatus = ANSC_STATUS_FAILURE; goto EXIT2; } } #endif /* * As a Tcp client application, we now try to connect the network server, whose address is * specified by the "peer address" and "peer port" fields. */ if ( pMyObject->Mode & ANSC_SCTO_MODE_XSOCKET ) { #ifdef _ANSC_IPV6_COMPATIBLE_ BOOL bNoConn = TRUE; #endif _ansc_memset(&xskt_server_addr, 0, sizeof(xskt_server_addr)); xskt_server_addr.sin_family = XSKT_SOCKET_AF_INET; xskt_server_addr.sin_addr.s_addr = pMyObject->PeerAddress.Value; xskt_server_addr.sin_port = _xskt_htons(pMyObject->PeerPort); #ifdef _ANSC_IPV6_COMPATIBLE_ while ( bNoConn && pxskt_server_addrinfo ) { if ( _xskt_connect((XSKT_SOCKET)pMyObject->Socket, pxskt_server_addrinfo->ai_addr, pxskt_server_addrinfo->ai_addrlen) != 0 ) { pxskt_server_addrinfo = pxskt_server_addrinfo->ai_next; /* try next ip address */ } else { bNoConn = FALSE; break; } } if ( bNoConn ) #else if ( _xskt_connect((XSKT_SOCKET)pMyObject->Socket, (xskt_socket_addr*)&xskt_server_addr, sizeof(xskt_server_addr)) != 0 ) #endif { AnscTrace("!!!!!!!!!! _xskt_connect error: socket=%d, error=%d !!!!!!!!!!\n", (XSKT_SOCKET)pMyObject->Socket, errno); { int j; char s[256]; char *ptr1 = ((xskt_socket_addr*)(&xskt_server_addr))->sa_data; char stmp[16]; s[0] = '\0'; for(j=0; j<13; j++) { sprintf(stmp, "%.2x:", *(ptr1++)); strcat(s, stmp); } sprintf(stmp, "%.2x", *ptr1); strcat(s, stmp); AnscTrace("!!!!!!!!!! _xskt_connect error: server_addr=%s\n", s); } perror("_xskt_connect error"); s_error = _xskt_get_last_error(); if ( pMyObject->Mode & ANSC_SCTO_MODE_NO_BSP_NOTIFY_CONN_ERR == 0 ) { pWorker->Notify ( pWorker->hWorkerContext, ANSC_SCTOWO_EVENT_SOCKET_TIMEOUT, (ANSC_HANDLE)NULL ); } returnStatus = ANSC_STATUS_FAILURE; goto EXIT2; } } else { _ansc_memset(&ansc_server_addr, 0, sizeof(ansc_server_addr)); ansc_server_addr.sin_family = ANSC_SOCKET_AF_INET; ansc_server_addr.sin_addr.s_addr = pMyObject->PeerAddress.Value; ansc_server_addr.sin_port = _ansc_htons(pMyObject->PeerPort); #ifdef _ANSC_IPV6_COMPATIBLE_ if ( _ansc_connect(pMyObject->Socket, pansc_server_addrinfo->ai_addr, pansc_server_addrinfo->ai_addrlen) != 0 ) #else if ( _ansc_connect(pMyObject->Socket, (ansc_socket_addr*)&ansc_server_addr, sizeof(ansc_server_addr)) != 0 ) #endif { s_error = _ansc_get_last_error(); AnscTrace("!!! Connect error: %d, %s !!!\n", s_error, strerror(s_error)); if ( pMyObject->Mode & ANSC_SCTO_MODE_NO_BSP_NOTIFY_CONN_ERR == 0 ) { pWorker->Notify ( pWorker->hWorkerContext, ANSC_SCTOWO_EVENT_SOCKET_TIMEOUT, (ANSC_HANDLE)NULL ); } returnStatus = ANSC_STATUS_FAILURE; goto EXIT2; } } /* * We have gone so far that all socket operations succeeded, we want to allocate a buffer that * is big enough for any incoming message. */ if ( !pMyObject->RecvBuffer && !(pMyObject->Mode & ANSC_SCTO_MODE_FOREIGN_BUFFER) ) { pMyObject->RecvBuffer = AnscAllocateMemory(pMyObject->RecvBufferSize); pMyObject->RecvPacketSize = 0; pMyObject->RecvOffset = 0; if ( !pMyObject->RecvBuffer ) { returnStatus = ANSC_STATUS_RESOURCES; goto EXIT2; } } pMyObject->RecvBytesCount = 0; pMyObject->SendBytesCount = 0; pMyObject->LastRecvAt = AnscGetTickInSeconds(); pMyObject->LastSendAt = AnscGetTickInSeconds(); /* * If the compilation option '_ANSC_SOCKET_TLS_LAYER_' is enabled, we can simply let the ANSC * socket layer to perform the SSL/TLS functionality; otherwise, we need to prepare for doing * SSL/TLS internally. */ if ( pMyObject->Mode & ANSC_SCTO_MODE_TLS_ENABLED ) { #ifdef _ANSC_USE_OPENSSL_ pMyObject->bTlsEnabled = TRUE; if ( !openssl_init(SSL_CLIENT_CALLS) ) { AnscTrace("AnscSctoEngage - openssl_init() failed!\n"); returnStatus = ANSC_STATUS_FAILURE; goto EXIT2; } #else #ifdef _ANSC_SOCKET_TLS_LAYER_ { _ansc_en_usetls(pMyObject->Socket); pMyObject->bTlsEnabled = FALSE; } #else { pMyObject->hTlsScsIf = (pMyObject->hTlsScsIf != NULL)? pMyObject->hTlsScsIf : AnscSocketTlsGetScsIf(); pMyObject->bTlsEnabled = TRUE; } #endif #endif } /* * To save the worker object from having to deal with blocking/non-blocking/async receiving * functions provided by underlying socket layer, we create a separate task to do that. */ returnStatus = pMyObject->SpawnTask3 ( (ANSC_HANDLE)pMyObject, (void* )pMyObject->RecvTask, (ANSC_HANDLE)pMyObject, ANSC_SCTO_RECV_TASK_NAME, USER_DEFAULT_TASK_PRIORITY, 11*USER_DEFAULT_TASK_STACK_SIZE ); #ifdef _ANSC_USE_OPENSSL_ if ( pMyObject->bTlsEnabled ) { SSL *ssl = NULL; ssl = openssl_connect (pMyObject->Socket); if ( !ssl ) { pMyObject->bTlsConnected = FALSE; returnStatus = ANSC_STATUS_FAILURE; //PANSC_SCTO_WORKER_OBJECT pWorker = (PANSC_SCTO_WORKER_OBJECT)pMyObject->hWorker; if ( pMyObject->Mode & ANSC_SCTO_MODE_NO_BSP_NOTIFY_CONN_ERR == 0 ) { pWorker->Notify ( pWorker->hWorkerContext, ANSC_SCTOWO_EVENT_TLS_ERROR, (ANSC_HANDLE)0L ); } } else { s_error = openssl_validate_certificate (pMyObject->Socket, pMyObject->HostName, ssl, SSL_CLIENT_CALLS); if ( s_error == 0 ) { AnscTrace("AnscSctoEngage - openssl_validate_certificate() failed %p.\n", ssl); //PANSC_SCTO_WORKER_OBJECT pWorker = (PANSC_SCTO_WORKER_OBJECT )pMyObject->hWorker; if ( pMyObject->Mode & ANSC_SCTO_MODE_NO_BSP_NOTIFY_CONN_ERR == 0 ) { pWorker->Notify ( pWorker->hWorkerContext, ANSC_SCTOWO_EVENT_TLS_ERROR, (ANSC_HANDLE)NULL ); } returnStatus = ANSC_STATUS_FAILURE; } pMyObject->hTlsConnection = ssl; pMyObject->bTlsConnected = TRUE; } } #else /* * If SSL/TLS is enabled, we should complete TLS handshake before returning from Engage(). This * behavior allows a single consistent API to used between this object and the worker object. * Since the handshake will take multiple messages to complete, we need to block the current * task until being notified by the TLS module. */ if ( pMyObject->bTlsEnabled && pMyObject->hTlsScsIf ) { pMyObject->bTlsConnected = FALSE; pMyObject->InitTlsClient((ANSC_HANDLE)pMyObject); } #endif if ( returnStatus != ANSC_STATUS_SUCCESS ) { goto EXIT2; } return ANSC_STATUS_SUCCESS; /****************************************************************** GRACEFUL ROLLBACK PROCEDURES AND EXIT DOORS ******************************************************************/ EXIT2: AnscTrace("AnscSctoEngage - failed with status %lu, socket error %d!\n", returnStatus, s_error); if ( pMyObject->Mode & ANSC_SCTO_MODE_XSOCKET ) { _xskt_closesocket((XSKT_SOCKET)pMyObject->Socket); } else { _ansc_closesocket(pMyObject->Socket); } EXIT1: if ( returnStatus != ANSC_STATUS_SUCCESS ) { pMyObject->bActive = FALSE; pMyObject->Reset((ANSC_HANDLE)pMyObject); } return returnStatus; }
ANSC_STATUS AnscDstoEngage ( ANSC_HANDLE hThisObject ) { ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; PANSC_DAEMON_SERVER_TCP_OBJECT pMyObject = (PANSC_DAEMON_SERVER_TCP_OBJECT)hThisObject; PANSC_DSTO_WORKER_OBJECT pWorker = (PANSC_DSTO_WORKER_OBJECT )pMyObject->hWorker; int s_result = 0; #ifdef _ANSC_IPV6_COMPATIBLE_ ansc_addrinfo ansc_hints = {0}; ansc_addrinfo* pansc_local_addrinfo = NULL; xskt_addrinfo xskt_hints = {0}; xskt_addrinfo* pxskt_local_addrinfo = NULL; USHORT usPort = 0; char port[6] = {0}; #else /*RDKB-6151, CID-24487,24794; initializing variable before use*/ ansc_socket_addr_in local_addr1 = {0}; xskt_socket_addr_in local_addr2 = {0}; #endif if ( pMyObject->bActive ) { return ANSC_STATUS_SUCCESS; } else if ( !pWorker ) { return ANSC_STATUS_UNAPPLICABLE; } else { pWorker->Init(pWorker->hWorkerContext); pMyObject->StartTime = AnscGetTickInSecondsAbs(); pMyObject->bActive = TRUE; } /* * The underlying socket wrapper may require an explicit startup() call, such is the case on * Microsoft windows platforms. The wrapper initialization has to done for each task. On most * real-time operating systems, this call is not required. */ if ( pMyObject->Mode & ANSC_DSTO_MODE_XSOCKET ) { AnscStartupXsocketWrapper((ANSC_HANDLE)pMyObject); } else { AnscStartupSocketWrapper((ANSC_HANDLE)pMyObject); } #ifdef _ANSC_IPV6_COMPATIBLE_ if ( pMyObject->Mode & ANSC_DSTO_MODE_XSOCKET ) { xskt_hints.ai_family = AF_UNSPEC; xskt_hints.ai_socktype = XSKT_SOCKET_STREAM; xskt_hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG; usPort = pMyObject->GetHostPort((ANSC_HANDLE)pMyObject); _ansc_sprintf(port, "%d", usPort); CcspTraceInfo(("!!! Host Name: %s, Host Port: %s !!!\n", pMyObject->HostName, port)); if ( _xskt_getaddrinfo ( pMyObject->HostName[0] ? pMyObject->HostName : "::", port, &xskt_hints, &pxskt_local_addrinfo ) ) { CcspTraceError(("!!! error 1 !!!\n")); returnStatus = ANSC_STATUS_FAILURE; goto EXIT1; } pMyObject->pHostAddr2 = pxskt_local_addrinfo; } else { ansc_hints.ai_family = AF_UNSPEC; ansc_hints.ai_socktype = ANSC_SOCKET_STREAM; ansc_hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG; usPort = pMyObject->GetHostPort((ANSC_HANDLE)pMyObject); _ansc_sprintf(port, "%d", usPort); CcspTraceInfo(("!!! Host Name: %s, Host Port: %s !!!\n", pMyObject->HostName, port)); if ( _ansc_getaddrinfo ( pMyObject->HostName[0] ? pMyObject->HostName : "::", port, &ansc_hints, &pansc_local_addrinfo ) ) { returnStatus = ANSC_STATUS_FAILURE; goto EXIT1; } pMyObject->pHostAddr1 = pansc_local_addrinfo; } #endif /* * To engage the Tcp Daemon, we need to perform following acts in the respective order: * * (1) create the os-dependent socket * (2) manufacture and start all the engines objects * (3) manufacture the global socket object pool * (4) bind to the socket and listen on it */ if ( pMyObject->Mode & ANSC_DSTO_MODE_XSOCKET ) { #ifdef _ANSC_IPV6_COMPATIBLE_ pMyObject->Socket = _xskt_socket(pxskt_local_addrinfo->ai_family, pxskt_local_addrinfo->ai_socktype, 0); #else pMyObject->Socket = _xskt_socket(XSKT_SOCKET_AF_INET, XSKT_SOCKET_STREAM, 0); #endif } else { #ifdef _ANSC_IPV6_COMPATIBLE_ pMyObject->Socket = _ansc_socket(pansc_local_addrinfo->ai_family, pansc_local_addrinfo->ai_socktype, 0); #else pMyObject->Socket = _ansc_socket(ANSC_SOCKET_AF_INET, ANSC_SOCKET_STREAM, 0); #endif } if ( ((pMyObject->Socket == XSKT_SOCKET_INVALID_SOCKET) && (pMyObject->Mode & ANSC_DSTO_MODE_XSOCKET)) || ((pMyObject->Socket == ANSC_SOCKET_INVALID_SOCKET) && !(pMyObject->Mode & ANSC_DSTO_MODE_XSOCKET)) ) { returnStatus = ANSC_STATUS_FAILURE; goto EXIT1; } _ansc_en_reuseaddr(pMyObject->Socket); #ifndef _ANSC_IPV6_COMPATIBLE_ if ( pMyObject->Mode & ANSC_DSTO_MODE_XSOCKET ) { local_addr2.sin_family = XSKT_SOCKET_AF_INET; local_addr2.sin_port = _xskt_htons(pMyObject->HostPort); if ( pMyObject->HostAddress.Value == 0 ) { ((pansc_socket_addr_in)&local_addr2)->sin_addr.s_addr = XSKT_SOCKET_ANY_ADDRESS; } else { ((pansc_socket_addr_in)&local_addr2)->sin_addr.s_addr = pMyObject->HostAddress.Value; } } else { local_addr1.sin_family = ANSC_SOCKET_AF_INET; local_addr1.sin_port = _ansc_htons(pMyObject->HostPort); if ( pMyObject->HostAddress.Value == 0 ) { local_addr1.sin_addr.s_addr = ANSC_SOCKET_ANY_ADDRESS; } else { local_addr1.sin_addr.s_addr = pMyObject->HostAddress.Value; } } #endif #if !defined(_ANSC_KERNEL) || !defined(_ANSC_LINUX) if ( pMyObject->Mode & ANSC_DSTO_MODE_XSOCKET ) { #ifdef _ANSC_IPV6_COMPATIBLE_ s_result = _xskt_bind(pMyObject->Socket, pxskt_local_addrinfo->ai_addr, pxskt_local_addrinfo->ai_addrlen); #else AnscTrace("AnscDstoEngage -- the address is 0x%lX:%d, familty %d.\n", _ansc_ntohl(local_addr2.sin_addr.s_addr), _ansc_ntohs(local_addr2.sin_port), local_addr2.sin_family); s_result = _xskt_bind(pMyObject->Socket, (xskt_socket_addr*)&local_addr2, sizeof(local_addr2)); #endif } else { #ifdef _ANSC_IPV6_COMPATIBLE_ s_result = _ansc_bind(pMyObject->Socket, pansc_local_addrinfo->ai_addr, pansc_local_addrinfo->ai_addrlen); #else s_result = _ansc_bind(pMyObject->Socket, (ansc_socket_addr*)&local_addr1, sizeof(local_addr1)); #endif } #else if ( pMyObject->Mode & ANSC_DSTO_MODE_XSOCKET ) { while ( _xskt_bind(pMyObject->Socket, (ansc_socket_addr*)&local_addr2, sizeof(local_addr2)) != 0 ) { AnscTrace ( "AnscDstoEngage -- failure to bind try again !socket %d family %d port %d address %X \n", pMyObject->Socket, local_addr2.sin_family, local_addr2.sin_port, ((pansc_socket_addr_in)&local_addr2)->sin_addr.s_addr ); AnscSleep(10); } } else { while ( _ansc_bind(pMyObject->Socket, (ansc_socket_addr*)&local_addr1, sizeof(local_addr1)) != 0 ) { AnscTrace ( "AnscDstoEngage -- failure to bind try again !socket %d family %d port %d address %X \n", pMyObject->Socket, local_addr1.sin_family, local_addr1.sin_port, local_addr1.sin_addr.s_addr ); AnscSleep(10); } } #endif if ( s_result != 0 ) { AnscTrace ( "AnscDstoEngage -- failed to bind to the socket, error code is %d!!!\n", (pMyObject->Mode & ANSC_DSTO_MODE_XSOCKET) ? _xskt_get_last_error() : _ansc_get_last_error() ); returnStatus = ANSC_STATUS_FAILURE; goto EXIT2; } pMyObject->ManufactureEnginePool((ANSC_HANDLE)pMyObject); pMyObject->ManufactureSocketPool((ANSC_HANDLE)pMyObject); pMyObject->StartEngines ((ANSC_HANDLE)pMyObject); if ( pMyObject->Mode & ANSC_DSTO_MODE_XSOCKET ) { s_result = _xskt_listen(pMyObject->Socket, ANSC_SOCKET_BACKLOG_VALUE); } else { s_result = _ansc_listen(pMyObject->Socket, ANSC_SOCKET_BACKLOG_VALUE); } if ( s_result != 0 ) { AnscTrace("AnscDstoEngage -- failed to listen on the socket!\n"); returnStatus = ANSC_STATUS_FAILURE; goto EXIT2; } /* * If the compilation option '_ANSC_SOCKET_TLS_LAYER_' is enabled, we can simply let the ANSC * socket layer to perform the SSL/TLS functionality; otherwise, we need to prepare for doing * SSL/TLS internally. */ if ( pMyObject->Mode & ANSC_DSTO_MODE_TLS_ENABLED ) { #ifdef _ANSC_USE_OPENSSL_ pMyObject->bTlsEnabled = TRUE; if ( !openssl_init(SSL_SERVER_CALLS) ) { AnscTrace("AnscSctoEngage - openssl_init() failed!\n"); returnStatus = ANSC_STATUS_FAILURE; goto EXIT2; } #else #ifdef _ANSC_SOCKET_TLS_LAYER_ { _ansc_en_usetls(pMyObject->Socket); pMyObject->bTlsEnabled = FALSE; } #else { pMyObject->hTlsScsIf = (pMyObject->hTlsScsIf != NULL)? pMyObject->hTlsScsIf : AnscSocketTlsGetScsIf(); pMyObject->bTlsEnabled = TRUE; pMyObject->bTlsReqCert = (pMyObject->Mode & ANSC_DSTO_MODE_TLS_REQ_CERT); } #endif #endif } AnscResetEvent(&pMyObject->AcceptEvent); returnStatus = pMyObject->SpawnTask3 ( (ANSC_HANDLE)pMyObject, (void* )pMyObject->AcceptTask, (ANSC_HANDLE)pMyObject, ANSC_DSTO_ACCEPT_TASK_NAME, USER_DEFAULT_TASK_PRIORITY, 2*USER_DEFAULT_TASK_STACK_SIZE ); return ANSC_STATUS_SUCCESS; /****************************************************************** GRACEFUL ROLLBACK PROCEDURES AND EXIT DOORS ******************************************************************/ EXIT2: if ( pMyObject->Mode & ANSC_DSTO_MODE_XSOCKET ) { _xskt_closesocket(pMyObject->Socket); } else { _ansc_closesocket(pMyObject->Socket); } EXIT1: if ( returnStatus != ANSC_STATUS_SUCCESS ) { pMyObject->bActive = FALSE; } return returnStatus; }