hashTable.c File Reference

SNMP statistic module, hash table. More...

#include <stdlib.h>
#include <string.h>
#include "hashTable.h"
#include "../../dprint.h"
#include "../../mem/mem.h"
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "openserSIPRegUserTable.h"

Include dependency graph for hashTable.c:

Go to the source code of this file.

Functions

int calculateHashSlot (char *theString, int hashTableSize)
aorToIndexStruct_tcreateHashRecord (int userIndex, char *aor)
hashSlot_tcreateHashTable (int size)
void deleteUser (hashSlot_t *theTable, char *aor, int hashTableSize)
aorToIndexStruct_tfindHashRecord (hashSlot_t *theTable, char *aor, int size)
void insertHashRecord (hashSlot_t *theTable, aorToIndexStruct_t *theRecord, int size)
void printHashSlot (hashSlot_t *theTable, int index)


Detailed Description

SNMP statistic module, hash table.

For an overview of its structures, please see hashTable.h

Potential Performance Improvements: Pass the length of the aor strings around everywhere, so we don't have to calculate it ourselves.

Definition in file hashTable.c.


Function Documentation

int calculateHashSlot ( char *  theString,
int  hashTableSize 
)

Calculates and returns a hash index to a hash table. The index is calculated by summing up all the characters specified with theString, and using the hashTableSize as the modulus.

Definition at line 60 of file hashTable.c.

Referenced by deleteUser(), findHashRecord(), and insertHashRecord().

aorToIndexStruct_t* createHashRecord ( int  userIndex,
char *  aor 
)

Returns a aorToIndexStruct_t, holding the given 'userIndex' and 'aor'. The structure is used to map between the "aor" (OpenSER's way of indexing users/contacts), and the SNMPStats user and contact integer indexes.

NOTE: that this record does not make a copy of aor, but instead points directly to the parameter. Therefore make sure that aor is not on the stack, and is not going to disappear before this record is deleted.

Definition at line 250 of file hashTable.c.

References aorToIndexStruct::aor, aorToIndexStruct::aorLength, LM_ERR, NULL, aorToIndexStruct::numContacts, pkg_malloc, and aorToIndexStruct::userIndex.

Referenced by updateUser().

hashSlot_t* createHashTable ( int  size  ) 

Returns a chunk of memory large enough to store 'size' hashSlot's. The table will contain mappings between OpenSER's "aor" user/contact indexing scheme, and SNMPStats integer indexing scheme

Definition at line 110 of file hashTable.c.

References hashTable, LM_ERR, NULL, and pkg_malloc.

Referenced by initInterprocessBuffers().

void deleteUser ( hashSlot_t theTable,
char *  aor,
int  hashTableSize 
)

This function will search the provided hash table for an entry indexed by 'aor'. If an entry is found then:

  • Its numContacts counter will be decremented.
  • If its numContacts counter reaches zero, then the entry will be removed from the hash table.

Definition at line 168 of file hashTable.c.

References aorToIndexStruct::aor, aorToIndexStruct::aorLength, calculateHashSlot(), deleteRegUserRow(), hashSlot::first, hashSlot::last, aorToIndexStruct::next, NULL, aorToIndexStruct::numContacts, pkg_free, aorToIndexStruct::prev, and aorToIndexStruct::userIndex.

Referenced by executeInterprocessBufferCmd().

aorToIndexStruct_t* findHashRecord ( hashSlot_t theTable,
char *  aor,
int  size 
)

Searches the hash table specified as theTable, of size 'size', for a record indexed with 'aor'. If a match is found, then an aorToIndextStruct_t structure is returned.

This function is called to discover the map between OpenSER's "aor" (Address of Records) indexing scheme, and the SNMPStats modules integer indexing scheme for its contact/user data.

Returns: the aorToIndexStruct_t mapping structure if a match was found, or NULL otherwise.

Definition at line 84 of file hashTable.c.

References aorToIndexStruct::aor, aorToIndexStruct::aorLength, calculateHashSlot(), hashSlot::first, aorToIndexStruct::next, and NULL.

Referenced by executeInterprocessBufferCmd(), openserSIPRegUserLookupTable_set_action(), and updateUser().

void insertHashRecord ( hashSlot_t theTable,
aorToIndexStruct_t theRecord,
int  size 
)

Inserts the record specified with 'theRecord' into our hash table.

Definition at line 130 of file hashTable.c.

References aorToIndexStruct::aor, calculateHashSlot(), hashSlot::first, hashSlot::last, aorToIndexStruct::next, NULL, and aorToIndexStruct::prev.

Referenced by updateUser().

void printHashSlot ( hashSlot_t theTable,
int  index 
)

Debugging function. Prints off an entire hash slot.

Definition at line 278 of file hashTable.c.

References aorToIndexStruct::aor, hashSlot::first, LM_ERR, aorToIndexStruct::next, NULL, and aorToIndexStruct::userIndex.


Generated on Wed May 23 06:01:04 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6