server: intialize aux_header buffer to null if the data is missing.
[tridge/openchange.git] / branches / plugfest / libmapi++ / mapi_exception.h
1 /*
2    libmapi C++ Wrapper
3    MAPI Exception Class
4
5    Copyright (C) Alan Alvarez 2007.
6
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.
11
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.
16
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/>.
19 */
20
21 #ifndef LIBMAPIPP__MAPI_EXCEPTION_H__
22 #define LIBMAPIPP__MAPI_EXCEPTION_H__
23
24 #include <exception>
25 #include <map>
26 #include <iostream>
27 #include <string>
28
29 #include <cstring>
30
31 #include <libmapi++/clibmapi.h>
32
33 #define STATUS_TABLE_INSERT(status) sm_status_map.insert(status_map::value_type(status, #status));
34
35 namespace libmapipp {
36
37 class mapi_exception : public std::exception
38 {
39         public:
40                 explicit mapi_exception(enum MAPISTATUS status, const std::string& origin = "") : std::exception(), m_status(status), m_origin(origin), m_what_string(origin)
41                 {
42                         status_map::iterator iter = sm_status_map.find(m_status);
43
44                         m_what_string += ": ";
45                         m_what_string += (iter != sm_status_map.end()) ? iter->second : "Unknown MAPISTATUS value";
46                 }
47
48                 virtual const char* what() const throw() { return m_what_string.c_str(); }
49
50                 enum MAPISTATUS get_status() const { return m_status; }
51
52                 virtual ~mapi_exception() throw() {}
53
54         private:
55                 enum MAPISTATUS m_status;
56                 std::string     m_origin;
57                 std::string     m_what_string;
58                 friend class session;
59
60                 typedef std::map<enum MAPISTATUS, const char*> status_map;
61                 static status_map       sm_status_map;
62
63                 static void fill_status_map()
64                 {
65                         static bool filled = false;
66
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);
136
137                                 filled = true;
138                         }
139                 }       
140 };
141
142 } // namespace libmapipp
143
144 #endif //!LIBMAPIPP__EXCEPTION_H__