sipxportlib  Version 3.3
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends | List of all members
OsConfigDb Class Reference

#include <OsConfigDb.h>

Collaboration diagram for OsConfigDb:
Collaboration graph
[legend]

Public Member Functions

 OsConfigDb ()
 
virtual ~OsConfigDb ()
 
virtual OsStatus loadFromFile (FILE *fp)
 
virtual OsStatus loadFromFile (const char *filename)
 
virtual OsStatus loadFromBuffer (const char *buf)
 
virtual OsStatus storeToFile (const char *filename)
 
virtual OsStatus updateFile (const char *filename) const
 
OsStatus remove (const UtlString &rKey)
 
OsStatus removeByPrefix (const UtlString &rPrefix)
 
void set (const UtlString &rKey, const UtlString &rNewValue)
 
void set (const UtlString &rKey, const int iNewValue)
 
virtual OsStatus get (const UtlString &rKey, UtlString &rValue) const
 
virtual OsStatus get (const UtlString &rKey, int &rValue) const
 
virtual const char * getIdentityLabel () const
 
virtual void setIdentityLabel (const char *idLabel)
 
OsConfigEncryptiongetEncryption () const
 
void setCapitalizeName (UtlBoolean capitalize)
 
void storeToBuffer (char *buff) const
 
int calculateBufferSize () const
 
virtual UtlBoolean isEmpty (void) const
 
virtual int numEntries (void) const
 
virtual OsStatus getSubHash (const UtlString &rHashSubKey, OsConfigDb &rSubDb) const
 
virtual OsStatus getNext (const UtlString &rKey, UtlString &rNextKey, UtlString &rNextValue) const
 
virtual void addList (const UtlString &rPrefix, UtlSList &rList)
 
virtual int loadList (const UtlString &rPrefix, UtlSList &rList) const
 
int getPort (const char *szKey) const
 
void clear ()
 

Static Public Member Functions

static void setStaticEncryption (OsConfigEncryption *encryption)
 
static OsConfigEncryptiongetStaticEncryption ()
 
static void removeNewlineReturns (UtlString &stringData)
 

Protected Member Functions

OsStatus loadFromEncryptedFile (const char *filename)
 
OsStatus loadFromUnencryptedFile (FILE *fp)
 
OsStatus loadFromEncryptedBuffer (char *buf, int bufLen)
 
OsStatus loadFromUnencryptedBuffer (const char *buf)
 
OsStatus storeToEncryptedFile (const char *filename)
 
OsStatus storeBufferToFile (const char *filename, const char *buff, unsigned long buffLen)
 
void dump ()
 
virtual OsStatus storeToFile (FILE *fp)
 
void insertEntry (const UtlString &rKey, const UtlString &rNewValue)
 
 OsConfigDb (const OsConfigDb &rOsConfigDb)
 
OsConfigDboperator= (const OsConfigDb &rhs)
 

Static Protected Member Functions

static UtlBoolean parseLine (const char *line, UtlBoolean capitalizeName, const char *fileLabelForError, UtlString &name, UtlString &value)
 
static void removeChars (UtlString *s, char c)
 

Protected Attributes

OsRWMutex mRWMutex
 
UtlSortedList mDb
 
UtlString mIdentityLabel
 
UtlBoolean mCapitalizeName
 

Friends

class OsConfigDbTest
 

Detailed Description

Configuration database containing key/value pairs with ability to read and write to disk.

Constructor & Destructor Documentation

~OsConfigDb ( )
virtual
OsConfigDb ( const OsConfigDb rOsConfigDb)
protected

Copy constructor (not implemented for this class)

Member Function Documentation

OsStatus loadFromFile ( FILE *  fp)
virtual
OsStatus loadFromFile ( const char *  filename)
virtual

Load the configuration database from a file

OsStatus loadFromBuffer ( const char *  buf)
virtual

Load the configuation database from a string buffer(Buffer CANNOT be encrypted) with the following format:

s : s
s : s
...

OsStatus storeToFile ( const char *  filename)
virtual

Store the config database to a file

OsStatus updateFile ( const char *  filename) const
virtual

Attempts to update existing file without loosing comments or parameter order

OsStatus remove ( const UtlString rKey)

Remove the key/value pair associated with rKey.

return OS_SUCCESS if the key was found in the database, return OS_NOT_FOUND otherwise

OsStatus removeByPrefix ( const UtlString rPrefix)

Remove all the key/value pairs starting with the designated prefix

return OS_SUCCESS if one key or more keys were found in the database, return OS_NOT_FOUND otherwise

void set ( const UtlString rKey,
const UtlString rNewValue 
)

Insert the key/value pair into the config database If the database already contains an entry for this key, then set the value for the existing entry to rNewValue.

void set ( const UtlString rKey,
const int  iNewValue 
)

Insert the key/value pair into the config database If the database already contains an entry for this key, then set the value for the existing entry to iNewValue.

OsStatus get ( const UtlString rKey,
UtlString rValue 
) const
virtual

Sets rValue to the value in the database associated with rKey. If rKey is found in the database, returns OS_SUCCESS. Otherwise, returns OS_NOT_FOUND and sets rValue to the empty string.

OsStatus get ( const UtlString rKey,
int &  rValue 
) const
virtual

Sets rValue to the value in the database associated with rKey. If rKey is found in the database, returns OS_SUCCESS. Otherwise, returns OS_NOT_FOUND and sets rValue to -1.

const char * getIdentityLabel ( ) const
virtual

Filename, URI, or what helps identify the contents of this config

void setIdentityLabel ( const char *  idLabel)
virtual

Filename, URI, or what helps identify the contents of this config

OsConfigEncryption * getEncryption ( ) const

Current encryption support. NULL when there's no encryption support, !NULL then there's a possiblity that actual contents of config will be encrypted or decrypted from/to io source.

void setStaticEncryption ( OsConfigEncryption encryption)
static

Set the default encryption support for all OsConfig instances

OsConfigEncryption * getStaticEncryption ( )
static

Get the encryption support for call instances

void setCapitalizeName ( UtlBoolean  capitalize)

force capitalization of all keys, most profiles want this off even keys are typcialy stored as capitalized

void storeToBuffer ( char *  buff) const

Store all contents into a buffer, call calculateBufferSize to get safe size. Call strlen to get actual size

int calculateBufferSize ( ) const

Return gauronteed to be large enough, (unless values are changed) when storing into a buffer

UtlBoolean isEmpty ( void  ) const
virtual

Return TRUE if the database is empty, otherwise FALSE

int numEntries ( void  ) const
virtual

Return the number of entries in the config database

OsStatus getSubHash ( const UtlString rHashSubKey,
OsConfigDb rSubDb 
) const
virtual

Get a hash of name value pairs with the given key prefix

Parameters
rHashSubKeythe prefix for keys to name value pairs which are copied into the given rSubDb. The key in the sub-OsConfigDb have the prefix removed.
OsStatus getNext ( const UtlString rKey,
UtlString rNextKey,
UtlString rNextValue 
) const
virtual

Relative to rKey, return the key and value associated with next (lexicographically ordered) key/value pair stored in the database. If rKey is the empty string, key and value associated with the first entry in the database will be returned.

Returns
OS_SUCCESS if there is a "next" entry;
OS_NOT_FOUND if rKey is not found in the database and is not the empty string
OS_NO_MORE_DATA if there is no "next" entry.
void addList ( const UtlString rPrefix,
UtlSList rList 
)
virtual

Stores a list of strings to the configuration datadase using the designated prefix as the base for the list items. The prefix is used to build unique configuration keys. For example, if you use specify a prefix of "MYLIST" and supply a list containing ("item 1", "item 2", and "item 3"), you will end up with the following:

MYLIST.COUNT : 3 MYLIST.1 : item 1 MYLIST.2 : item 2 MYLIST.3 : item 3

Warning: All items with a key of "[rPrefix]." are removed as a side effect.

Parameters
rPrefixConfiguration name prefix
rListList of UtlString values.
int loadList ( const UtlString rPrefix,
UtlSList rList 
) const
virtual

Loads a list of strings from the configuration datadase using the designated prefix as the base for the list items. The number of list items is returned.

Parameters
rPrefixConfiguration name prefix
rListList of UtlString values.
See also
addList
int getPort ( const char *  szKey) const

Helper method to obtain a port value from the configuration database. Results are as follows:

  PORT_DEFAULT : Let a port be selected automatically.
                 Represented as "DEFAULT".
  PORT_NONE :    Disabled (either specified as such, the key
                 was not found, or the value was blank)
                 Represented as "NONE".
  other :        The port number that was specified
                 Represented as a decimal integer.
Parameters
szKeyKey file to lookup.
void clear ( )

Delete all entries from the configuration database

void removeNewlineReturns ( UtlString stringData)
static

Remove newlines and carriage returns from string

OsStatus loadFromEncryptedFile ( const char *  filename)
protected
OsStatus loadFromUnencryptedFile ( FILE *  fp)
protected
OsStatus loadFromEncryptedBuffer ( char *  buf,
int  bufLen 
)
protected
OsStatus loadFromUnencryptedBuffer ( const char *  buf)
protected
OsStatus storeToEncryptedFile ( const char *  filename)
protected
OsStatus storeBufferToFile ( const char *  filename,
const char *  buff,
unsigned long  buffLen 
)
protected
void dump ( )
protected
OsStatus storeToFile ( FILE *  fp)
protectedvirtual
UtlBoolean parseLine ( const char *  line,
UtlBoolean  capitalizeName,
const char *  fileLabelForError,
UtlString name,
UtlString value 
)
staticprotected

Parse "key : value" and returns TRUE if parameter found Returns false if line is blank or a comment (begins with #).

void insertEntry ( const UtlString rKey,
const UtlString rNewValue 
)
protected

Method for inserting a key/value pair into the dictionary The write lock for the database should be taken before calling this method. If the database already contains an entry for this key, then set the value for the existing entry to rNewValue.

OsConfigDb& operator= ( const OsConfigDb rhs)
protected

Assignment operator (not implemented for this class)

void removeChars ( UtlString s,
char  c 
)
staticprotected

Utility func to remove all chars = c from given string

Friends And Related Function Documentation

friend class OsConfigDbTest
friend

Member Data Documentation

OsRWMutex mRWMutex
mutableprotected

reader/writer lock for synchronization

UtlSortedList mDb
protected

sorted storage of key/values

UtlString mIdentityLabel
protected

ID, used to distiguish which files should be encrypted

UtlBoolean mCapitalizeName
protected

Force capitalization on all keys. Most profile do not want this on even though most of their keys are already captilized