📄 m2pppsecuritysecretslib.c
字号:
if (identity != NULL) free(newDataEntryPtr->pppSecuritySecretsIdentity); if (secret != NULL) free(newDataEntryPtr->pppSecuritySecretsSecret); free(newDataEntryPtr); free(newEntryPtr); /* We inserted a primary node. We realized that we do not * have sufficient data to proceed. Hence, we leave after * returning the database to its previous state. */ PPP_SECRETS_SEM_GIVE; return ERROR; } } else { /* we have sufficient data and we will constuct the new entry */ newDataEntryPtr->pppSecuritySecretsDirection = *pDirection; newDataEntryPtr->pppSecuritySecretsProtocol = *pProtocol; strcpy(newDataEntryPtr->pppSecuritySecretsIdentity, identity); strcpy(newDataEntryPtr->pppSecuritySecretsSecret, secret); newDataEntryPtr->pppSecuritySecretsStatus = PPP_SECURITY_SECRETS_STATUS_VALID; /* we will forcefully insert the new data entry */ auxGenericArgument.p = (void *)newDataEntryPtr; if (NULL == (retrievedDataEntryPtr = avlRemoveInsert(pppSecretsDataTreePtr, newDataEntryPtr, auxGenericArgument, ldpiDataKeyCompare))) /* note that newDataEntryPtr appears twice */ { /* We inserted a primary node without a conflict. Having * sufficient input data we constructed a new data * (secondary, i.e. corresponding to ldpi key) entry and * we inserted it without a conflict. */ PPP_SECRETS_SEM_GIVE; return OK; } else { /* in order to enter the new data entry we had to * remove another data entry. We will retrieve its * (link,idIndex) primary key and we will delete * the corresponding primary tree node. */ POPULATE_PPP_SECRETS_KEY_ENTRY; keyDataEntry.pppSecuritySecretsLink = retrievedDataEntryPtr->pppSecuritySecretsLink; keyDataEntry.pppSecuritySecretsIdIndex = retrievedDataEntryPtr->pppSecuritySecretsIdIndex; /* we free the memory reserved for the old data entry */ free(retrievedDataEntryPtr->pppSecuritySecretsIdentity); free(retrievedDataEntryPtr->pppSecuritySecretsSecret); free(retrievedDataEntryPtr); auxGenericArgument.p = (void *)(&keyEntry); if (NULL == (retrievedEntryPtr = avlDelete(pppSecretsTreePtr, auxGenericArgument, m2pppAgentKeyCompare))) { logMsg("inconsistency: invisible primary node\n", 0,0,0,0,0,0); logMsg("SERIOUS INCONSISTENCY\n",0,0,0,0,0,0); logMsg("recovery was not attempted\n",0,0,0,0,0,0); logMsg("corresponding secondary node was removed\n", 0,0,0,0,0,0); /* We inserted a primary node without a conflict. Having * sufficient input data we constructed a new data * (secondary, i.e. corresponding to ldpi key) entry. * When we tried to insert the data entry we encountered * conflict but when we tried to remove the primary * node that corresponds to the conflicting data entry * we failed due to database inconsistency. */ PPP_SECRETS_SEM_GIVE; return ERROR; } else { free(retrievedEntryPtr); free(retrievedEntryPtr); free(retrievedEntryPtr); /* We inserted a primary node without a conflict. Having * sufficient input data we constructed a new data * (secondary, i.e. corresponding to ldpi key) entry. * When we tried to insert the data entry we encountered * conflict but we had to remove the the primary * node that corresponds to the conflicting data entry. */ PPP_SECRETS_SEM_GIVE; return OK; } } } } } }/******************************************************************************** m2pppSecretsDataEntryPtrAgentLookup - * Get the pppSecuritySecretsDataEntry pointer * paired to the SNMP specified key (link, idIndex) composed by the input data.** RETURNS: OK if a database entry is paired to the input key -in which case it* places its data entry pointer to the position pointed by the input* <ppSecretDataEntry> - or ERROR.** NOMANUAL*/STATUS m2pppSecretsDataEntryPtrAgentLookup ( UINT32 link, UINT32 idIndex, PPP_SECURITY_SECRETS_DATA_ENTRY ** ppSecretsDataEntry ) { PPP_SECURITY_SECRETS_ENTRY keyEntry; PPP_SECURITY_SECRETS_DATA_ENTRY keyDataEntry; PPP_SECURITY_SECRETS_ENTRY * retrievedEntryPtr; GENERIC_ARGUMENT auxGenericArgument; /* first we check consistency of input data */ if ((link > MAX_LINK) || (idIndex > MAX_ID_INDEX) || (NULL == ppSecretsDataEntry)) { /* abort m2pppSecretsDataEntryPtrAgentLookup: invalid input */ return ERROR; }; POPULATE_PPP_SECRETS_KEY_ENTRY; PPP_SECRETS_SEM_TAKE; auxGenericArgument.p = (void *)(&keyEntry); if (NULL == (retrievedEntryPtr = avlSearch(pppSecretsTree, auxGenericArgument, m2pppAgentKeyCompare))) { *ppSecretsDataEntry = NULL; PPP_SECRETS_SEM_GIVE; return ERROR; } else { *ppSecretsDataEntry = retrievedEntryPtr->pSecretsDataEntry; PPP_SECRETS_SEM_GIVE; return OK; } }/******************************************************************************** m2pppNextSecretsDataEntryPtrAgentLookup - * Get the pppSecuritySecretsDataEntry* pointer paired to the minimum superior SNMP specified key (link, idIndex) * composed by the input data.** RETURNS: OK if a database entry exists with key superior to the input key -in * which case it finds the entry with key immediate successor to the input key* and places its data entry pointer to the position pointed by the input* <ppSecretDataEntry> - or ERROR.** NOMANUAL*/STATUS m2pppNextSecretsDataEntryPtrAgentLookup ( UINT32 link, UINT32 idIndex, PPP_SECURITY_SECRETS_DATA_ENTRY ** ppSecretsDataEntry ) { PPP_SECURITY_SECRETS_ENTRY keyEntry; PPP_SECURITY_SECRETS_DATA_ENTRY keyDataEntry; PPP_SECURITY_SECRETS_ENTRY * retrievedEntryPtr; GENERIC_ARGUMENT auxGenericArgument; /* first we check consistency of input data */ if ((link > MAX_LINK) || (idIndex > MAX_ID_INDEX) || (NULL == ppSecretsDataEntry)) { /* abort m2pppNextSecretsDataEntryPtrAgentLookup: invalid input */ return ERROR; }; POPULATE_PPP_SECRETS_KEY_ENTRY; PPP_SECRETS_SEM_TAKE; auxGenericArgument.p = (void *)(&keyEntry); if (NULL == (retrievedEntryPtr = avlSuccessorGet(pppSecretsTree, auxGenericArgument, m2pppAgentKeyCompare))) { *ppSecretsDataEntry = NULL; PPP_SECRETS_SEM_GIVE; return ERROR; } else { *ppSecretsDataEntry = retrievedEntryPtr->pSecretsDataEntry; PPP_SECRETS_SEM_GIVE; return OK; } }/******************************************************************************** m2pppPreviousSecretsDataEntryPtrAgentLookup - ** Get the pppSecuritySecretsDataEntry * pointer paired to the maximum inferior SNMP specified key (link, idIndex) * composed by the input data.** RETURNS: OK if a database entry exists with key inferior to the input key -in * which case it finds the entry with key immediate predecessor to the input key* and places its data entry pointer to the position pointed by the input* <ppSecretDataEntry> - or ERROR.** NOMANUAL*/STATUS m2pppPreviousSecretsDataEntryPtrAgentLookup ( UINT32 link, UINT32 idIndex, PPP_SECURITY_SECRETS_DATA_ENTRY ** ppSecretsDataEntry ) { PPP_SECURITY_SECRETS_ENTRY keyEntry; PPP_SECURITY_SECRETS_DATA_ENTRY keyDataEntry; PPP_SECURITY_SECRETS_ENTRY * retrievedEntryPtr; GENERIC_ARGUMENT auxGenericArgument; /* first we check consistency of input data */ if ((link > MAX_LINK) || (idIndex > MAX_ID_INDEX) || (NULL == ppSecretsDataEntry)) { /* abort m2pppPreviousSecretsDataEntryPtrAgentLookup: invalid input */ return ERROR; }; POPULATE_PPP_SECRETS_KEY_ENTRY; PPP_SECRETS_SEM_TAKE; auxGenericArgument.p = (void *)(&keyEntry); if (NULL == (retrievedEntryPtr = avlPredecessorGet(pppSecretsTree, auxGenericArgument, m2pppAgentKeyCompare))) { *ppSecretsDataEntry = NULL; PPP_SECRETS_SEM_GIVE; return ERROR; } else { *ppSecretsDataEntry = retrievedEntryPtr->pSecretsDataEntry; PPP_SECRETS_SEM_GIVE; return OK; } }/******************************************************************************** m2pppSecretsEntryAgentLookup - lookup keyed by (link, idIndex)** Produce the data of the pppSecuritySecretsEntry identified by * its SNMP specified key (pppSecuritySecretsLink, pppSecuritySecretsIdIndex).** It will return OK if a database entry is paired to the input key* -in which case it will place the appropriate data in the places pointed * by pDirection, pProtocol, identity, secret, and pStatus- or ERROR.** RETURNS: OK or ERROR*/STATUS m2pppSecretsEntryAgentLookup ( UINT32 link, /* required */ UINT32 idIndex, /* required */ PPP_SECURITY_SECRETS_DIRECTION * pDirection, /* should not be NULL */ PPP_SECURITY_PROTOCOL * pProtocol, /* should not be NULL */ char * identity, /* should not be NULL */ char * secret, /* should not be NULL */ PPP_SECURITY_SECRETS_STATUS * pStatus /* should not be NULL */ ) { PPP_SECURITY_SECRETS_ENTRY keyEntry; PPP_SECURITY_SECRETS_DATA_ENTRY keyDataEntry; PPP_SECURITY
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -