5 * $TOG: DtMailError.hh /main/15 1999/03/26 16:59:10 mgreess $
7 * RESTRICTED CONFIDENTIAL INFORMATION:
9 * The information in this document is subject to special
10 * restrictions in a confidential disclosure agreement bertween
11 * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
12 * document outside HP, IBM, Sun, USL, SCO, or Univel wihtout
13 * Sun's specific written approval. This documment and all copies
14 * and derivative works thereof must be returned or destroyed at
17 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
22 #ifndef _DTMAILERROR_H
23 #define _DTMAILERROR_H
25 #include <DtMail/DtMailTypes.h>
32 // Name of the messaging database file.
34 extern const char * DtMailCatalogDataFile;
35 static const int MailErrorSet = 1;
36 static const int SockErrorSet = 2;
37 static const int ValuesErrorSet = 2;
38 static const int FileShareMsgSet = 2;
41 // NOTE - IMPORTANT -- READ ME
43 // The order of the definitions below must match the
44 // strings in libDtMail/Common/DtMailError.C
52 DTME_FileCreateFailed,
56 DTME_InitializationFailed,
59 DTME_InvalidOperationSequence,
60 DTME_MD5ChecksumFailed,
61 DTME_MailTransportFailed,
63 DTME_NoImplementations,
70 DTME_NoSuchImplementation,
77 DTME_ObjectAccessFailed,
78 DTME_ObjectCreationFailed,
81 DTME_OpenContainerInterrupted,
82 DTME_OperationInvalid,
88 DTME_UnknownOpenError,
94 DTME_CannotRemoveStaleMailboxLockFile,
95 DTME_CannotCreateMailboxLockFile,
96 DTME_CannotCreateMailboxLockFile_NoPermission,
97 DTME_CannotCreateMailboxLockFile_IsDirectory,
98 DTME_CannotCreateMailboxLockFile_NoSuchFile,
99 DTME_CannotCreateMailboxLockFile_RemoteAccessLost,
100 DTME_CannotObtainInformationOnOpenMailboxFile,
101 DTME_CannotCreateTemporaryMailboxFile,
102 DTME_CannotCreateTemporaryMailboxFile_NoPermission,
103 DTME_CannotCreateTemporaryMailboxFile_IsDirectory,
104 DTME_CannotCreateTemporaryMailboxFile_NoSuchFile,
105 DTME_CannotCreateTemporaryMailboxFile_RemoteAccessLost,
106 DTME_CannotSetPermissionsOfTemporaryMailboxFile,
107 DTME_CannotSetOwnerOfTemporaryMailboxFile,
108 DTME_CannotSetGroupOfTemporaryMailboxFile,
109 DTME_CannotWriteToTemporaryMailboxFile,
110 DTME_CannotWriteToTemporaryMailboxFile_ProcessLimitsExceeded,
111 DTME_CannotWriteToTemporaryMailboxFile_RemoteAccessLost,
112 DTME_CannotWriteToTemporaryMailboxFile_NoFreeSpaceLeft,
113 DTME_CannotReadNewMailboxFile,
114 DTME_CannotReadNewMailboxFile_OutOfMemory,
115 DTME_CannotRemoveMailboxLockFile,
116 DTME_CannotRenameNewMailboxFileOverOld,
117 DTME_InternalAssertionFailure,
118 DTME_ResourceParsingNoEndif,
121 DTME_CannotCreateMailboxDotDtmailLockFile,
122 DTME_MailboxInodeChanged,
123 DTME_MailServerAccess_AuthorizationFailed,
124 DTME_MailServerAccess_Error,
125 DTME_MailServerAccess_MissingPassword,
126 DTME_MailServerAccess_ProtocolViolation,
127 DTME_MailServerAccess_ServerTimeoutError,
128 DTME_MailServerAccess_SocketIOError,
129 DTME_AppendMailboxFile_Error,
130 DTME_AppendMailboxFile_FileTooBig,
131 DTME_AppendMailboxFile_LinkLost,
132 DTME_AppendMailboxFile_NoSpaceLeft,
133 DTME_AppendMailboxFile_SystemError,
134 DTME_GetmailCommandRetrieval_SystemError,
135 DTME_GetmailCommandRetrieval_AbnormalExit,
136 DTME_PathElementPermissions,
137 DTME_PathElementNotDirectory,
138 DTME_PathElementDoesNotExist,
139 DTME_MailServerAccessInfo_SocketOpen,
140 DTME_MailServerAccessInfo_NoMessages,
141 DTME_MailServerAccessInfo_RetrievingMessage,
142 DTME_MailServerAccessInfo_MessageTooLarge,
147 // Make a class wrapper for errors so that we can set/clear
153 void clear(); // Sets everything to no error, and frees memory.
156 // logError() and logFatalError():
158 // This will print out in a formated way all of the error information
159 // that it can. it also sends the results to the system log device for
162 // First it will format the error message to be returned.
163 // Then if the _client message is set it will be printed.
165 // %m is used to insert the system supplied message into the supplied
166 // format (see syslog(3)):
168 // error.logError(DTM_FALSE, "I got an error: number %d\n %m , error_code);
170 // The format may be in a system specific way.
172 void logError(DtMailBoolean criticalError,
173 const char *format, ...) const;
177 // This one is the same as logError() plus it sets _fatal.
179 void logFatalError(DtMailBoolean criticalError,
180 const char *format, ...);
181 #endif /* DEAD_WOOD */
184 // Set the error code. Tt_message is optional.
186 // Fatal here is within the scope of the function called,
187 // not necessarily the program. If the program can recover - it should.
189 void setError(const DTMailError_t,
193 void vSetError(const DTMailError_t minor_code,
198 void setError(const DTMailError_t,
199 const Tt_message = NULL);
201 const char * errnoMessage(int systemErrorNumber);
202 const char * errnoMessage();
203 void setClient(void *);
204 void * getClient(void) { return _client; }
205 DtMailBoolean isSet() const; // Returns DTM_TRUE if there was an error.
206 DtMailBoolean isNotSet() const; // !IsSet()
207 DtMailBoolean isFatal() const;// Returns DTM_TRUE if the error was fatal.
208 DtMailBoolean isNotFatal() const; // !IsFatal()
211 // Cast operators. While:
215 // // You can say....
217 // const Tt_message msg = (const Tt_message)error;
219 // const CMEnv env = (const CMEnv*)error;
221 // printf("%s %d", (const char*)error, (DTMailError_t)error);
223 operator const char*();
224 operator const Tt_message() const;
225 operator DTMailError_t() const;
228 // Constructor/Destructor
230 DtMailEnv(); // The constructor will set everything to no error.
232 ~DtMailEnv(); // Sets everything to no error, and frees memory.
237 static nl_catd _errorCatalog;
238 static char *getMessageText(int set, int msg, char *dft);
243 // The implementation specific function pointer and the _client
244 // variable below was designed for use C++ API.
249 // 2) THESE FUNCTON POINTERS >>>EXPECT<<< TO CALL MT-SAFE FUNCTIONS.
251 // Implmentation specific error messages are here.
252 // The pointer to the client data is in _client.
254 // Pointer to function for C++ 'clear', 'message', and
255 // 'code' functions provided to this class from the implementation.
256 // They are set using setCPP(...) function.
258 // This is for functions that use the C++ calling conventions.
260 // The CPPclearF points to a function provided by
261 // the implementation to clear the error and free any
262 // data assoicated with the _client specific data.
264 // The CPPmessageF points to a function provided by
265 // the implementation to return the error 'message' assoicated with
266 // the _client specific data.
267 // --THE PROVIDED FUNCTION MUST RETURN NULL WHEN THERE IS NO ERROR.
269 // The CPPerrorF points to a function provided by
270 // the implementation to return the error 'code' assoicated with
271 // the _client specific data.
272 // --THE PROVIDED FUNCTION MUST RETURN ZERO (0) WHEN THERE IS NO ERROR.
274 // void setClient(void *), sets the value of _client.
277 typedef void (*CPPclearF)(void *);
278 typedef const char * (*CPPmessageF)(void *);
279 typedef int (*CPPerrorF)(void *);
281 void setCPP(CPPclearF, CPPmessageF, CPPerrorF);
285 const char * implGetMessage();
287 #endif /* DEAD_WOOD */
290 DTMailError_t _error; // The corrected error number.
291 DTMailError_t _error_minor_code; // The original error number
292 const char *_message; // The error message.
293 Tt_message _tt_message; // ToolTalk error message.
294 DtMailBoolean _fatal; // DTM_TRUE if this is a fatal error.
295 void getErrorMessageText(void);
298 // Function pointers for implementation specific clear,
299 // get message, and get error functions.
301 CPPclearF _implClearFunc; // C function that will clear the error.
302 CPPmessageF _implMessageFunc; // C function that will get the error msg.
303 CPPerrorF _implErrorFunc; // C function that will get the error code.
306 // Where the implementation stores the data.
308 void *_client; // Implmentation specific message.
311 // Has syslog been opened?
313 static DtMailBoolean _syslog_open;
318 static const char * DtMailCatalogDataFile;
321 // Inline member functions.
324 DtMailEnv::setCPP(CPPclearF clear, CPPmessageF message, CPPerrorF code)
326 _implClearFunc = clear;
327 _implMessageFunc = message;
328 _implErrorFunc = code;
332 DtMailEnv::~DtMailEnv()
340 DtMailEnv::setError(const DTMailError_t err, const Tt_message msg)
342 setError(err, DTM_FALSE, msg);
346 DtMailEnv::isSet() const
348 return(_error == DTME_NoError ? DTM_FALSE : DTM_TRUE);
352 DtMailEnv::isNotSet() const
354 return(_error == DTME_NoError ? DTM_TRUE : DTM_FALSE);
358 DtMailEnv::isFatal() const
364 DtMailEnv::isNotFatal() const
366 return(_fatal == DTM_TRUE ? DTM_FALSE : DTM_TRUE);
370 DtMailEnv::setClient(void *client)
376 DtMailEnv::operator const char*()
378 if (_message == NULL)
379 getErrorMessageText();
380 return(_message == NULL ? "Unknown" : _message);
384 DtMailEnv::operator const Tt_message() const
390 DtMailEnv::operator DTMailError_t() const
396 DtMailEnv::implClear()
398 if (_client != NULL && _implClearFunc != NULL) {
399 (*_implClearFunc)(_client);
405 DtMailError_getTTmsg(DtMailEnv & error)
407 return((const Tt_message)error); // The prefered way.
409 #endif /* DEAD_WOOD */