-rw-r--r-- | include/opkele/exception.h | 206 |
1 files changed, 206 insertions, 0 deletions
diff --git a/include/opkele/exception.h b/include/opkele/exception.h new file mode 100644 index 0000000..2ac0661 --- a/dev/null +++ b/include/opkele/exception.h | |||
@@ -0,0 +1,206 @@ | |||
1 | #ifndef __OPKELE_EXCEPTION_H | ||
2 | #define __OPKELE_EXCEPTION_H | ||
3 | |||
4 | /** | ||
5 | * @file | ||
6 | * @brief opkele exceptions | ||
7 | */ | ||
8 | |||
9 | #include <curl/curl.h> | ||
10 | |||
11 | #include <opkele/opkele-config.h> | ||
12 | #ifdef OPKELE_HAVE_KONFORKA | ||
13 | # include <konforka/exception.h> | ||
14 | /** | ||
15 | * the exception parameters declaration | ||
16 | */ | ||
17 | # define OPKELE_E_PARS const string& fi,const string&fu,int l,const string& w | ||
18 | /** | ||
19 | * the exception parameters list to pass to constructor | ||
20 | */ | ||
21 | # define OPKELE_E_CONS_ fi,fu,l, | ||
22 | /** | ||
23 | * the exception codepoint specification | ||
24 | */ | ||
25 | # define OPKELE_CP_ CODEPOINT, | ||
26 | /** | ||
27 | * the simple rethrow of konforka-based exception | ||
28 | */ | ||
29 | # define OPKELE_RETHROW catch(konforka::exception& e) { e.see(CODEPOINT); throw } | ||
30 | #else /* OPKELE_HAVE_KONFORKA */ | ||
31 | # include <stdexcept> | ||
32 | /** | ||
33 | * the exception parameter declaration | ||
34 | */ | ||
35 | # define OPKELE_E_PARS const string& w | ||
36 | /** | ||
37 | * the dummy prefix for exception parameters list to prepend in the absence of | ||
38 | * konforka library | ||
39 | */ | ||
40 | # define OPKELE_E_CONS_ | ||
41 | /** | ||
42 | * the dummy placeholder for konforka exception codepoint specification | ||
43 | */ | ||
44 | # define OPKELE_CP_ | ||
45 | /** | ||
46 | * the dummy define for the konforka-based rethrow of exception | ||
47 | */ | ||
48 | # define OPKELE_RETHROW | ||
49 | #endif /* OPKELE_HAVE_KONFORKA */ | ||
50 | /** | ||
51 | * the exception parameters list to pass to constructor | ||
52 | */ | ||
53 | # define OPKELE_E_CONS OPKELE_E_CONS_ w | ||
54 | |||
55 | /* | ||
56 | * @brief the main opkele namespace | ||
57 | */ | ||
58 | namespace opkele { | ||
59 | using std::string; | ||
60 | |||
61 | /** | ||
62 | * the base opkele exception class | ||
63 | */ | ||
64 | class exception : public | ||
65 | # ifdef OPKELE_HAVE_KONFORKA | ||
66 | konforka::exception | ||
67 | # else | ||
68 | std::exception | ||
69 | # endif | ||
70 | { | ||
71 | public: | ||
72 | # ifdef OPKELE_HAVE_KONFORKA | ||
73 | explicit | ||
74 | exception(const string& fi,const string& fu,int l,const string& w) | ||
75 | : konforka::exception(fi,fu,l,w) { } | ||
76 | # else /* OPKELE_HAVE_KONFORKA */ | ||
77 | explicit | ||
78 | exception(const string& w) | ||
79 | : std::exception(w) { } | ||
80 | # endif /* OPKELE_HAVE_KONFORKA */ | ||
81 | }; | ||
82 | |||
83 | /** | ||
84 | * thrown in case of failed conversion | ||
85 | */ | ||
86 | class failed_conversion : public exception { | ||
87 | public: | ||
88 | failed_conversion(OPKELE_E_PARS) | ||
89 | : exception(OPKELE_E_CONS) { } | ||
90 | }; | ||
91 | /** | ||
92 | * thrown in case of failed lookup (either parameter or persistent store) | ||
93 | */ | ||
94 | class failed_lookup : public exception { | ||
95 | public: | ||
96 | failed_lookup(OPKELE_E_PARS) | ||
97 | : exception(OPKELE_E_CONS) { } | ||
98 | }; | ||
99 | /** | ||
100 | * thrown in case of bad input (either local or network) | ||
101 | */ | ||
102 | class bad_input : public exception { | ||
103 | public: | ||
104 | bad_input(OPKELE_E_PARS) | ||
105 | : exception(OPKELE_E_CONS) { } | ||
106 | }; | ||
107 | |||
108 | /** | ||
109 | * thrown on failed assertion | ||
110 | */ | ||
111 | class failed_assertion : public exception { | ||
112 | public: | ||
113 | failed_assertion(OPKELE_E_PARS) | ||
114 | : exception(OPKELE_E_CONS) { } | ||
115 | }; | ||
116 | |||
117 | /** | ||
118 | * thrown if the handle being retrieved is invalid | ||
119 | */ | ||
120 | class invalid_handle : public exception { | ||
121 | public: | ||
122 | invalid_handle(OPKELE_E_PARS) | ||
123 | : exception(OPKELE_E_CONS) { } | ||
124 | }; | ||
125 | /** | ||
126 | * thrown if the handle passed to check_authentication request is not | ||
127 | * stateless | ||
128 | */ | ||
129 | class stateful_handle : public exception { | ||
130 | public: | ||
131 | stateful_handle(OPKELE_E_PARS) | ||
132 | : exception(OPKELE_E_CONS) { } | ||
133 | }; | ||
134 | |||
135 | /** | ||
136 | * thrown if check_authentication request fails | ||
137 | */ | ||
138 | class failed_check_authentication : public exception { | ||
139 | public: | ||
140 | failed_check_authentication(OPKELE_E_PARS) | ||
141 | : exception(OPKELE_E_CONS) { } | ||
142 | }; | ||
143 | |||
144 | /** | ||
145 | * thrown if the id_res request result is negative | ||
146 | */ | ||
147 | class id_res_failed : public exception { | ||
148 | public: | ||
149 | id_res_failed(OPKELE_E_PARS) | ||
150 | : exception(OPKELE_E_CONS) { } | ||
151 | }; | ||
152 | /** | ||
153 | * thrown if the user_setup_url is provided with negative response | ||
154 | */ | ||
155 | class id_res_setup : public id_res_failed { | ||
156 | public: | ||
157 | string setup_url; | ||
158 | id_res_setup(OPKELE_E_PARS,const string& su) | ||
159 | : id_res_failed(OPKELE_E_CONS), setup_url(su) { } | ||
160 | ~id_res_setup() throw() { } | ||
161 | }; | ||
162 | /** | ||
163 | * thrown in case of signature mismatch | ||
164 | */ | ||
165 | class id_res_mismatch : public id_res_failed { | ||
166 | public: | ||
167 | id_res_mismatch(OPKELE_E_PARS) | ||
168 | : id_res_failed(OPKELE_E_CONS) { } | ||
169 | }; | ||
170 | |||
171 | /** | ||
172 | * openssl malfunction occured | ||
173 | */ | ||
174 | class exception_openssl : public exception { | ||
175 | public: | ||
176 | unsigned long _error; | ||
177 | string _ssl_string; | ||
178 | exception_openssl(OPKELE_E_PARS); | ||
179 | ~exception_openssl() throw() { } | ||
180 | }; | ||
181 | |||
182 | /** | ||
183 | * network operation related error occured | ||
184 | */ | ||
185 | class exception_network : public exception { | ||
186 | public: | ||
187 | exception_network(OPKELE_E_PARS) | ||
188 | : exception(OPKELE_E_CONS) { } | ||
189 | }; | ||
190 | |||
191 | /** | ||
192 | * network operation related error occured, specifically, related to | ||
193 | * libcurl | ||
194 | */ | ||
195 | class exception_curl : public exception_network { | ||
196 | public: | ||
197 | CURLcode _error; | ||
198 | string _curl_string; | ||
199 | exception_curl(OPKELE_E_PARS); | ||
200 | exception_curl(OPKELE_E_PARS,CURLcode e); | ||
201 | ~exception_curl() throw() { } | ||
202 | }; | ||
203 | |||
204 | } | ||
205 | |||
206 | #endif /* __OPKELE_EXCEPTION_H */ | ||