sipxportlib  Version 3.3
OsUtil.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2004-2006 SIPfoundry Inc.
3 // Licensed by SIPfoundry under the LGPL license.
4 //
5 // Copyright (C) 2004-2006 Pingtel Corp. All rights reserved.
6 // Licensed to SIPfoundry under a Contributor Agreement.
7 //
8 // $$
10 
11 
12 #ifndef _OsUtil_h_
13 #define _OsUtil_h_
14 
15 // SYSTEM INCLUDES
16 // APPLICATION INCLUDES
17 #include <utl/UtlString.h>
18 
19 #include "os/OsStatus.h"
20 #include "os/OsTime.h"
21 
22 // DEFINES
23 // MACROS
24 // EXTERNAL FUNCTIONS
25 // EXTERNAL VARIABLES
26 // CONSTANTS
27 // STRUCTS
28 // TYPEDEFS
29 // FORWARD DECLARATIONS
30 
31 //:Miscellaneous useful static methods
32 class OsUtil
33 {
34 /* //////////////////////////// PUBLIC //////////////////////////////////// */
35 public:
36 
38  {
54  };
55 
57  {
61  };
62 
63  static const UtlString NULL_OS_STRING;
64 
66  static char *memscan(const char *lookIn,
67  int lookInLen,
68  const char *lookFor,
69  int lookForLen);
70 
71 /* ============================ Name Database ============================= */
72 
73  static OsStatus insertKeyValue(const UtlString& rPrefix,
74  const UtlString& rName,
75  const intptr_t value,
76  UtlBoolean exceptOnErr=TRUE);
77  //:Insert a key-value pair into the name database
78  // The key is constructed by concatenating rPrefix and rName.
79  // If exceptOnErr is TRUE, then upon encountering an error, this method
80  // will throw an exception. This is sometimes useful for indicating an
81  // error from within an object constructor.
82 
83  static OsStatus deleteKeyValue(const UtlString& rPrefix,
84  const UtlString& rName,
85  intptr_t* pValue=NULL);
86  //:Remove the indicated key-value pair from the name database
87  // The key is constructed by concatenating rPrefix and rName.
88  // If pValue is non-NULL, the value for the key-value pair is returned
89  // via pValue.
90  // Return OS_SUCCESS if the lookup is successful, return
91  // OS_NOT_FOUND if there is no match for the specified key.
92 
93  static OsStatus lookupKeyValue(const UtlString& rPrefix,
94  const UtlString& rName,
95  intptr_t* pValue=NULL);
96  //:Retrieve the value associated with the specified key
97  // The key is constructed by concatenating rPrefix and rName.
98  // If pValue is non-NULL, the value is returned via pValue.
99  // Return OS_SUCCESS if the lookup is successful, return
100  // OS_NOT_FOUND if there is no match for the specified key.
101 
102  static OsStatus convertUtlStringToInt(const UtlString& rStr, int& rInt);
103  //:Convert the value in rStr to an integer.
104  // Uses strtol() with base==0 to perform the conversion.
105  // Return OS_SUCCESS if the conversion was successful and set rInt to
106  // the converted value in rInt. If the conversion failed, return
107  // OS_FAILED and set rInt to -1.
108 
109 
110  static OsStatus checkIpAddress(const char* addr) ;
111  // :Check the designated ip address for validity:
112  // 1) 4 octets separated by '.'
113  // 2) Each octet is between 0 and 255
114  // 3) Address is not 0.0.0.0 or 255.255.255.255
115  // Return OS_SUCCESS if the addr is valid, otherwise return OS_INVALID
116 
117 
118  static OsStatus checkNetmask(const char* netmask) ;
119  // :Check the designated netmask for validity:
120  // 1) Between 255.0.0.0 and 255.255.255.254
121  // Return OS_SUCCESS if the addr is valid, otherwise return OS_INVALID
122 
123 
124  static UtlBoolean isSameNetwork(const char* destIpAddr,
125  const char* myIpAddr,
126  const char* myNetMask) ;
127  // :Return TRUE if the destIpAddress is on the same logical network as
128  // myIpAddr given netmask myNetMask. Returns FALSE otherwise.
129 
130 
131  //returns OS_SUCCESS if the host repsonds within timeout
132  OsStatus checkDnsAvailability(char *dnsServer, OsTime timeout);
133 
134 
135  //returns OS_SUCCESS if the host repsonds within timeout
136  OsStatus checkResponsiveDest(char *destHost, OsTime timeout);
137 
138 
139 /* ============================ MANIPULATORS ============================== */
140 
141 /* ============================ ACCESSORS ================================= */
142 
143  static void getCurDate(UtlString& dateStr,
144  const struct tm* pCurTime, int maxLen);
145  //:Return the current date
146  // An example showing the date format is: "Wed Oct 7 1998".
147 
148  static void getCurTime(UtlString& timeStr,
149  const struct tm* pCurTime, int maxLen);
150  //:Return the current time
151  // An example showing the time format is: "8:03 PM".
152 
153  static int getPlatformType(void);
154  //:Return the type of platform we are running on (e.g., PLATFORM_TCAS2)
155 
156  static int getProductType(void);
157  //:Return the type of platform we are running on (e.g., PRODUCT_XPRESSA)
158 
159 /* ============================ INQUIRY =================================== */
160 
161 
162 /* //////////////////////////// PROTECTED ///////////////////////////////// */
163 protected:
164 
165  OsUtil();
166  //:Default constructor (not implemented for this class)
167  // We identify this as a protected method so that gcc doesn't complain
168  // that the class only defines a private constructor and has no friends.
169 
170  virtual
171  ~OsUtil();
172  //:Destructor (not implemented for this class)
173  // We identify this as a protected method so that gcc doesn't complain
174  // that the class only defines a private destructor and has no friends.
175 
176  static UtlBoolean convertIpAddressToOctets(const char* ipAddr, unsigned char octets[]) ;
177  // :Convert a nnn.nnn.nnn.nnn ip address into an array of 4 unsigned chars.
178  // Returns FALSE on error otherwise TRUE
179 
180 
181 
182 /* //////////////////////////// PRIVATE /////////////////////////////////// */
183 private:
184 
185  OsUtil(const OsUtil& rOsUtil);
186  //:Copy constructor (not implemented for this class)
187 
188  OsUtil& operator=(const OsUtil& rhs);
189  //:Assignment operator (not implemented for this class)
190 
191 };
192 
193 /* ============================ INLINE METHODS ============================ */
194 
195 #endif // _OsUtil_h_
Definition: OsUtil.h:41
Definition: OsUtil.h:47
Definition: OsUtil.h:53
static OsStatus convertUtlStringToInt(const UtlString &rStr, int &rInt)
Definition: OsUtil.cpp:167
static OsStatus checkIpAddress(const char *addr)
Definition: OsUtil.cpp:194
static OsStatus deleteKeyValue(const UtlString &rPrefix, const UtlString &rName, intptr_t *pValue=NULL)
Definition: OsUtil.cpp:130
Definition: OsUtil.h:49
Definition: OsUtil.h:43
virtual ~OsUtil()
static int getProductType(void)
Definition: OsUtil.cpp:446
static void getCurDate(UtlString &dateStr, const struct tm *pCurTime, int maxLen)
Definition: OsUtil.cpp:334
Definition: OsUtil.h:44
OsStatus checkResponsiveDest(char *destHost, OsTime timeout)
Definition: OsUtil.cpp:321
OsStatus
Definition: OsStatus.h:27
#define NULL
Definition: UtlDefs.h:29
Definition: OsUtil.h:46
Definition: OsUtil.h:39
static int getPlatformType(void)
Definition: OsUtil.cpp:423
Definition: OsUtil.h:45
Definition: OsUtil.h:58
Definition: UtlString.h:48
Definition: OsUtil.h:60
static void getCurTime(UtlString &timeStr, const struct tm *pCurTime, int maxLen)
Definition: OsUtil.cpp:388
static OsStatus insertKeyValue(const UtlString &rPrefix, const UtlString &rName, const intptr_t value, UtlBoolean exceptOnErr=TRUE)
Definition: OsUtil.cpp:87
static OsStatus checkNetmask(const char *netmask)
Definition: OsUtil.cpp:211
Definition: OsUtil.h:52
Definition: OsTime.h:37
Definition: OsUtil.h:51
Definition: OsUtil.h:42
int UtlBoolean
Definition: UtlDefs.h:41
static const UtlString NULL_OS_STRING
Definition: OsUtil.h:63
Definition: OsUtil.h:40
#define TRUE
Definition: UtlDefs.h:25
Definition: OsUtil.h:50
static OsStatus lookupKeyValue(const UtlString &rPrefix, const UtlString &rName, intptr_t *pValue=NULL)
Definition: OsUtil.cpp:150
OsStatus checkDnsAvailability(char *dnsServer, OsTime timeout)
Definition: OsUtil.cpp:286
Definition: OsUtil.h:59
static UtlBoolean convertIpAddressToOctets(const char *ipAddr, unsigned char octets[])
Definition: OsUtil.cpp:468
_W64 signed int intptr_t
Definition: stdint.h:118
static char * memscan(const char *lookIn, int lookInLen, const char *lookFor, int lookForLen)
Search a buffer for first occurance of another buffer. binary or ascii.
Definition: OsUtil.cpp:50
Definition: OsUtil.h:32
static UtlBoolean isSameNetwork(const char *destIpAddr, const char *myIpAddr, const char *myNetMask)
Definition: OsUtil.cpp:253
OsProductType
Definition: OsUtil.h:56
OsPlatformType
Definition: OsUtil.h:37
Definition: OsUtil.h:48