sipxportlib  Version 3.3
OsConfigDb.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006-2012 SIPez LLC. All rights reserved.
3 //
4 // Copyright (C) 2004-2006 SIPfoundry Inc.
5 // Licensed by SIPfoundry under the LGPL license.
6 //
7 // Copyright (C) 2004-2006 Pingtel Corp. All rights reserved.
8 // Licensed to SIPfoundry under a Contributor Agreement.
9 //
10 // $$
12 
13 
14 #ifndef _OsConfigDb_h_
15 #define _OsConfigDb_h_
16 
17 // SYSTEM INCLUDES
18 // APPLICATION INCLUDES
19 #include "os/OsDefs.h"
20 #include "os/OsRWMutex.h"
21 #include "utl/UtlContainable.h"
22 #include "utl/UtlSortedList.h"
23 #include "utl/UtlString.h"
24 
25 // DEFINES
26 // MACROS
27 // EXTERNAL FUNCTIONS
28 // EXTERNAL VARIABLES
29 // CONSTANTS
30 // STRUCTS
31 // TYPEDEFS
32 // FORWARD DECLARATIONS
33 class OsConfigEncryption;
34 class UtlSList;
35 
39 class DbEntry : public UtlContainable
40 {
41  public:
42 
43  DbEntry(const UtlString &key);
44 
45  DbEntry(const UtlString &key, const UtlString &value);
46 
47  ~DbEntry();
48 
49  virtual UtlContainableType getContainableType() const;
50 
51  static const UtlContainableType TYPE;
52 
53  virtual unsigned int hash() const;
54 
55  int compareTo(const UtlContainable *b) const;
56 
58 
60 };
61 
62 
68 {
69  friend class OsConfigDbTest;
70 
71 public:
72 
73  OsConfigDb();
74 
75  virtual ~OsConfigDb();
76 
77  virtual OsStatus loadFromFile(FILE* fp);
78 
82  virtual OsStatus loadFromFile(const char *filename);
83 
92  virtual OsStatus loadFromBuffer(const char *buf);
93 
97  virtual OsStatus storeToFile(const char *filename);
98 
102  virtual OsStatus updateFile(const char* filename) const;
103 
110  OsStatus remove(const UtlString& rKey);
111 
118  OsStatus removeByPrefix(const UtlString& rPrefix) ;
119 
125  void set(const UtlString& rKey, const UtlString& rNewValue);
126 
132  void set(const UtlString& rKey, const int iNewValue) ;
133 
139  virtual OsStatus get(const UtlString& rKey, UtlString& rValue) const;
140 
146  virtual OsStatus get(const UtlString& rKey, int& rValue) const;
147 
151  virtual const char *getIdentityLabel() const;
152 
156  virtual void setIdentityLabel(const char *idLabel);
157 
163  OsConfigEncryption *getEncryption() const;
164 
168  static void setStaticEncryption(OsConfigEncryption *encryption);
169 
173  static OsConfigEncryption *getStaticEncryption();
174 
179  void setCapitalizeName(UtlBoolean capitalize);
180 
185  void storeToBuffer(char *buff) const;
186 
191  int calculateBufferSize() const;
192 
196  virtual UtlBoolean isEmpty(void) const;
197 
201  virtual int numEntries(void) const;
202 
206  virtual OsStatus getSubHash(const UtlString& rHashSubKey,
210  OsConfigDb& rSubDb) const;
211 
224  virtual OsStatus getNext(const UtlString& rKey,
225  UtlString& rNextKey, UtlString& rNextValue) const;
226 
227 
245  virtual void addList(const UtlString& rPrefix,
246  UtlSList& rList) ;
247 
258  virtual int loadList(const UtlString& rPrefix,
259  UtlSList& rList) const;
260 
261 
277  int getPort(const char* szKey) const;
278 
282  void clear() ;
283 
287  static void removeNewlineReturns(UtlString& stringData);
288 
289  protected:
290 
292  mutable OsRWMutex mRWMutex;
293 
296 
299 
305 
306  OsStatus loadFromEncryptedFile(const char *filename);
307 
308  OsStatus loadFromUnencryptedFile(FILE* fp);
309 
310  OsStatus loadFromEncryptedBuffer(char *buf, int bufLen);
311 
312  OsStatus loadFromUnencryptedBuffer(const char *buf);
313 
314  OsStatus storeToEncryptedFile(const char *filename);
315 
316  OsStatus storeBufferToFile(const char *filename, const char *buff, unsigned long buffLen);
317 
318  void dump();
319 
320  virtual OsStatus storeToFile(FILE* fp);
321 
326  static UtlBoolean parseLine(const char* line, UtlBoolean capitalizeName, const char* fileLabelForError,
327  UtlString& name, UtlString& value);
328 
335  void insertEntry(const UtlString& rKey, const UtlString& rNewValue);
336 
340  OsConfigDb(const OsConfigDb& rOsConfigDb);
341 
345  OsConfigDb& operator=(const OsConfigDb& rhs);
346 
350  static void removeChars(UtlString *s, char c);
351 };
352 
353 
354 /* ============================ INLINE METHODS ============================ */
355 
356 #endif // _OsConfigDb_h_
~DbEntry()
Definition: OsConfigDb.cpp:1125
virtual UtlContainableType getContainableType() const
Definition: OsConfigDb.cpp:1139
Definition: UtlSortedList.h:44
UtlSortedList mDb
Definition: OsConfigDb.h:295
UtlString mIdentityLabel
Definition: OsConfigDb.h:298
OsRWMutex mRWMutex
Definition: OsConfigDb.h:292
UtlString value
Definition: OsConfigDb.h:59
OsStatus
Definition: OsStatus.h:27
UtlBoolean mCapitalizeName
Definition: OsConfigDb.h:304
const char *const UtlContainableType
Definition: UtlDefs.h:70
Definition: UtlContainable.h:37
Definition: UtlString.h:48
static const UtlContainableType TYPE
Definition: OsConfigDb.h:51
virtual unsigned int hash() const
Calculate a hash code for this object.
Definition: OsConfigDb.cpp:1134
Definition: OsConfigDb.h:67
Definition: UtlSList.h:47
Definition: OsConfigEncryption.h:35
int UtlBoolean
Definition: UtlDefs.h:41
DbEntry(const UtlString &key)
Definition: OsConfigDb.cpp:1120
Definition: OsConfigDb.h:39
UtlString key
Definition: OsConfigDb.h:57
int compareTo(const UtlContainable *b) const
Compare this object to another object.
Definition: OsConfigDb.cpp:1129