/* * Initializes the openserSIPContactTable module. This involves: * * 1) Registering the tables OID with the master agent * * 2) Creating a default row, so that there is a row to query to trigger the * consumption of the interprocess buffer. */ void init_openserSIPContactTable(void) { initialize_table_openserSIPContactTable(); static char *defaultUser = "******"; createContactRow(1, 1, defaultUser, NULL); }
/*! * This function takes an element of the interprocess buffer passed to it, and * handles populating the respective user and contact tables with its contained * data. */ static void executeInterprocessBufferCmd(interprocessBuffer_t *currentBuffer) { int delContactIndex; aorToIndexStruct_t *currentUser; if (currentBuffer->callbackType == UL_CONTACT_INSERT) { /* Add the user if the user doesn't exist, or increment its * contact index otherwise. */ updateUser(currentBuffer->stringName); } else if (currentBuffer->callbackType != UL_CONTACT_EXPIRE) { /* Currently we only support UL_CONTACT_INSERT and * UL_CONTACT_EXPIRE. If we receive another callback type, this * is a bug. */ LM_ERR("found a command on the interprocess buffer that" " was not an INSERT or EXPIRE"); return; } currentUser = findHashRecord(hashTable, currentBuffer->stringName, HASH_SIZE); /* This should never happen. This is more of a sanity check. */ if (currentUser == NULL) { LM_ERR("Received a request for contact: %s for user: %s who doesn't " "exists\n", currentBuffer->stringName, currentBuffer->stringContact); return; } /* This buffer element specified that we need to add a contact. So lets * add them */ if (currentBuffer->callbackType == UL_CONTACT_INSERT) { /* Increment the contact index, which will be used to generate * our new row. */ currentUser->contactIndex++; /* We should do this after we create the row in the snmptable. * Its easier to delete the SNMP Row than the contact record. */ if(!insertContactRecord(&(currentUser->contactList), currentUser->contactIndex, currentBuffer->stringContact)) { LM_ERR("openserSIPRegUserTable was unable to allocate memory for " "adding contact: %s to user %s.\n", currentBuffer->stringName, currentBuffer->stringContact); /* We didn't use the index, so decrement it so we can * use it next time around. */ currentUser->contactIndex--; return; } if (!createContactRow(currentUser->userIndex, currentUser->contactIndex, currentBuffer->stringContact, currentBuffer->contactInfo)) { deleteContactRecord(&(currentUser->contactList), currentBuffer->stringContact); } } else { delContactIndex = deleteContactRecord(&(currentUser->contactList), currentBuffer->stringContact); /* This should never happen. But its probably wise to check and * to print out debug messages in case there is a hidden bug. */ if(delContactIndex == 0) { LM_ERR("Received a request to delete contact: %s for user: %s" " who doesn't exist\n", currentBuffer->stringName, currentBuffer->stringContact); return; } deleteContactRow(currentUser->userIndex, delContactIndex); deleteUser(hashTable, currentBuffer->stringName, HASH_SIZE); } }