Fix OpenChange server code and access to Samba4 databases.
[OpenChange-git-clone.git] / libmapi++ / mapi_exception.h
blobff240c67b25d7f3a79d4a5b78a042270188fe13d
1 /*
2 libmapi C++ Wrapper
3 MAPI Exception Class
5 Copyright (C) Alan Alvarez 2007.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #ifndef LIBMAPIPP__MAPI_EXCEPTION_H__
22 #define LIBMAPIPP__MAPI_EXCEPTION_H__
24 #include <exception>
25 #include <map>
26 #include <iostream>
27 #include <string>
29 #include <cstring>
31 #include <libmapi++/clibmapi.h>
33 #define STATUS_TABLE_INSERT(status) sm_status_map.insert(status_map::value_type(status, #status));
35 namespace libmapipp {
37 class mapi_exception : public std::exception
39 public:
40 mapi_exception(enum MAPISTATUS status, const std::string& origin = "") : std::exception(), m_status(status), m_origin(origin), m_what_string(origin)
42 status_map::iterator iter = sm_status_map.find(m_status);
44 m_what_string += ": ";
45 m_what_string += (iter != sm_status_map.end()) ? iter->second : "Unknown MAPISTATUS value";
48 virtual const char* what() const throw() { return m_what_string.c_str(); }
50 enum MAPISTATUS get_status() const { return m_status; }
52 virtual ~mapi_exception() throw() {}
54 private:
55 enum MAPISTATUS m_status;
56 std::string m_origin;
57 std::string m_what_string;
58 friend class session;
60 typedef std::map<enum MAPISTATUS, const char*> status_map;
61 static status_map sm_status_map;
63 static void fill_status_map()
65 static bool filled = false;
67 if (!filled) {
68 STATUS_TABLE_INSERT(MAPI_E_SUCCESS);
69 STATUS_TABLE_INSERT(MAPI_E_CALL_FAILED);
70 STATUS_TABLE_INSERT(MAPI_E_NO_SUPPORT);
71 STATUS_TABLE_INSERT(MAPI_E_BAD_CHARWIDTH);
72 STATUS_TABLE_INSERT(MAPI_E_STRING_TOO_LONG);
73 STATUS_TABLE_INSERT(MAPI_E_UNKNOWN_FLAGS);
74 STATUS_TABLE_INSERT(MAPI_E_INVALID_ENTRYID);
75 STATUS_TABLE_INSERT(MAPI_E_INVALID_OBJECT);
76 STATUS_TABLE_INSERT(MAPI_E_OBJECT_CHANGED);
77 STATUS_TABLE_INSERT(MAPI_E_OBJECT_DELETED);
78 STATUS_TABLE_INSERT(MAPI_E_BUSY);
79 STATUS_TABLE_INSERT(MAPI_E_NOT_ENOUGH_DISK);
80 STATUS_TABLE_INSERT(MAPI_E_NOT_ENOUGH_RESOURCES);
81 STATUS_TABLE_INSERT(MAPI_E_NOT_FOUND);
82 STATUS_TABLE_INSERT(MAPI_E_VERSION);
83 STATUS_TABLE_INSERT(MAPI_E_LOGON_FAILED);
84 STATUS_TABLE_INSERT(MAPI_E_SESSION_LIMIT);
85 STATUS_TABLE_INSERT(MAPI_E_USER_CANCEL);
86 STATUS_TABLE_INSERT(MAPI_E_UNABLE_TO_ABORT);
87 STATUS_TABLE_INSERT(MAPI_E_NETWORK_ERROR);
88 STATUS_TABLE_INSERT(MAPI_E_DISK_ERROR);
89 STATUS_TABLE_INSERT(MAPI_E_TOO_COMPLEX);
90 STATUS_TABLE_INSERT(MAPI_E_BAD_COLUMN);
91 STATUS_TABLE_INSERT(MAPI_E_EXTENDED_ERROR);
92 STATUS_TABLE_INSERT(MAPI_E_COMPUTED);
93 STATUS_TABLE_INSERT(MAPI_E_CORRUPT_DATA);
94 STATUS_TABLE_INSERT(MAPI_E_UNCONFIGURED);
95 STATUS_TABLE_INSERT(MAPI_E_FAILONEPROVIDER);
96 STATUS_TABLE_INSERT(MAPI_E_UNKNOWN_CPID);
97 STATUS_TABLE_INSERT(MAPI_E_UNKNOWN_LCID);
98 STATUS_TABLE_INSERT(MAPI_E_PASSWORD_CHANGE_REQUIRED);
99 STATUS_TABLE_INSERT(MAPI_E_PASSWORD_EXPIRED);
100 STATUS_TABLE_INSERT(MAPI_E_INVALID_WORKSTATION_ACCOUNT);
101 STATUS_TABLE_INSERT(MAPI_E_INVALID_ACCESS_TIME);
102 STATUS_TABLE_INSERT(MAPI_E_ACCOUNT_DISABLED);
103 STATUS_TABLE_INSERT(MAPI_E_END_OF_SESSION);
104 STATUS_TABLE_INSERT(MAPI_E_UNKNOWN_ENTRYID);
105 STATUS_TABLE_INSERT(MAPI_E_MISSING_REQUIRED_COLUMN);
106 STATUS_TABLE_INSERT(MAPI_E_BAD_VALUE);
107 STATUS_TABLE_INSERT(MAPI_E_INVALID_TYPE);
108 STATUS_TABLE_INSERT(MAPI_E_TYPE_NO_SUPPORT);
109 STATUS_TABLE_INSERT(MAPI_E_UNEXPECTED_TYPE);
110 STATUS_TABLE_INSERT(MAPI_E_TOO_BIG);
111 STATUS_TABLE_INSERT(MAPI_E_DECLINE_COPY);
112 STATUS_TABLE_INSERT(MAPI_E_UNEXPECTED_ID);
113 STATUS_TABLE_INSERT(MAPI_E_UNABLE_TO_COMPLETE);
114 STATUS_TABLE_INSERT(MAPI_E_TIMEOUT);
115 STATUS_TABLE_INSERT(MAPI_E_TABLE_EMPTY);
116 STATUS_TABLE_INSERT(MAPI_E_TABLE_TOO_BIG);
117 STATUS_TABLE_INSERT(MAPI_E_INVALID_BOOKMARK);
118 STATUS_TABLE_INSERT(MAPI_E_WAIT);
119 STATUS_TABLE_INSERT(MAPI_E_CANCEL);
120 STATUS_TABLE_INSERT(MAPI_E_NOT_ME);
121 STATUS_TABLE_INSERT(MAPI_E_CORRUPT_STORE);
122 STATUS_TABLE_INSERT(MAPI_E_NOT_IN_QUEUE);
123 STATUS_TABLE_INSERT(MAPI_E_NO_SUPPRESS);
124 STATUS_TABLE_INSERT(MAPI_E_COLLISION);
125 STATUS_TABLE_INSERT(MAPI_E_NOT_INITIALIZED);
126 STATUS_TABLE_INSERT(MAPI_E_NON_STANDARD);
127 STATUS_TABLE_INSERT(MAPI_E_NO_RECIPIENTS);
128 STATUS_TABLE_INSERT(MAPI_E_SUBMITTED);
129 STATUS_TABLE_INSERT(MAPI_E_HAS_FOLDERS);
130 STATUS_TABLE_INSERT(MAPI_E_HAS_MESAGES);
131 STATUS_TABLE_INSERT(MAPI_E_FOLDER_CYCLE);
132 STATUS_TABLE_INSERT(MAPI_E_AMBIGUOUS_RECIP);
133 STATUS_TABLE_INSERT(MAPI_E_NO_ACCESS);
134 STATUS_TABLE_INSERT(MAPI_E_INVALID_PARAMETER);
135 STATUS_TABLE_INSERT(MAPI_E_RESERVED);
137 filled = true;
142 mapi_exception::status_map mapi_exception::sm_status_map = status_map();
144 } // namespace libmapipp
146 #endif //!LIBMAPIPP__EXCEPTION_H__