summaryrefslogtreecommitdiffabout
path: root/include/sitecing/exception.h
blob: ccc7edd10a3e583cdf8ad14e7861c6c3b377dbfa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
#ifndef __SITECING_EXCEPTION_H
#define __SITECING_EXCEPTION_H

#include <string>

/**
 * @file
 * @brief The site-C-ing specific exceptions.
 */

/**
 * @brief The main site-C-ing namespace.
 */
namespace sitecing {
    using std::string;

    // TODO: status specifics

    /**
     * The http status to return.
     */
    class http_status {
	public:
	    /**
	     * The status string.
	     */
	    string status;
	    /**
	     * The message to follow the status string.
	     */
	    string message;

	    /**
	     * @param s HTTP status.
	     * @param m HTTP status message.
	     */
	    http_status(const string& s,const string& m)
		: status(s), message(m) { }
	    virtual ~http_status() throw() { }
    };

    // per RFC 2616

    /**
     * Informational.
     */
    class http_status_1xx : public http_status {
	public:
	    /**
	     * @param s HTTP status
	     * @param m HTTP status message
	     */
	    explicit http_status_1xx(const string &s,const string& m)
		: http_status(s,m) { }
    };
    /**
     * Continue.
     */
    class http_status_100 : public http_status_1xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_100(const string& m)
		: http_status_1xx("100",m) { }
	    explicit http_status_100()
		: http_status_1xx("100","Continue") { }
    };
    /**
     * Switching protocols.
     */
    class http_status_101 : public http_status_1xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_101(const string& m)
		: http_status_1xx("101",m) { }
	    explicit http_status_101()
		: http_status_1xx("101","Switching protocols") { }
    };

    /**
     * Successful.
     */
    class http_status_2xx : public http_status {
	public:
	    /**
	     * @param s HTTP status message
	     * @param m HTTP status message
	     */
	    explicit http_status_2xx(const string& s,const string& m)
		: http_status(s,m) { }
    };
    /**
     * OK.
     */
    class http_status_200 : public http_status_2xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_200(const string& m)
		: http_status_2xx("200",m) { }
	    explicit http_status_200()
		: http_status_2xx("200","OK") { }
    };
    /**
     * Created.
     */
    class http_status_201 : public http_status_2xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_201(const string& m)
		: http_status_2xx("201",m) { }
	    explicit http_status_201()
		: http_status_2xx("201","Created") { }
    };
    /**
     * Accepted.
     */
    class http_status_202 : public http_status_2xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_202(const string& m)
		: http_status_2xx("202",m) { }
	    explicit http_status_202()
		: http_status_2xx("202","Accepted") { }
    };
    /**
     * Non-authoritative infortmation.
     */
    class http_status_203 : public http_status_2xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_203(const string& m)
		: http_status_2xx("203",m) { }
	    explicit http_status_203()
		: http_status_2xx("203","Non-authoritative information") { }
    };
    /**
     * No content.
     */
    class http_status_204 : public http_status_2xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_204(const string& m)
		: http_status_2xx("204",m) { }
	    explicit http_status_204()
		: http_status_2xx("204","No content") { }
    };
    /**
     * Reset content.
     */
    class http_status_205 : public http_status_2xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_205(const string& m)
		: http_status_2xx("205",m) { }
	    explicit http_status_205()
		: http_status_2xx("205","Reset content") { }
    };
    /**
     * Partial content.
     */
    class http_status_206 : public http_status_2xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_206(const string& m)
		: http_status_2xx("206",m) { }
	    explicit http_status_206()
		: http_status_2xx("206","Partial content") { }
    };

    /**
     * Redirection.
     */
    class http_status_3xx : public http_status {
	public:
	    /**
	     * @param s HTTP status
	     * @param m HTTP status message
	     */
	    explicit http_status_3xx(const string& s,const string& m)
		: http_status(s,m) { }
    };
    /**
     * Multiple choices.
     */
    class http_status_300 : public http_status_3xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_300(const string& m)
		: http_status_3xx("300",m) { }
	    explicit http_status_300()
		: http_status_3xx("300","Multiple choices") { }
    };
    /**
     * Moved permanently.
     */
    class http_status_301 : public http_status_3xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_301(const string& m)
		: http_status_3xx("301",m) { }
	    explicit http_status_301()
		: http_status_3xx("301","Moved permanently") { }
    };
    /**
     * Found.
     */
    class http_status_302 : public http_status_3xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_302(const string& m)
		: http_status_3xx("302",m) { }
	    explicit http_status_302()
		: http_status_3xx("302","Found") { }
    };
    /**
     * See other.
     */
    class http_status_303 : public http_status_3xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_303(const string& m)
		: http_status_3xx("303",m) { }
	    explicit http_status_303()
		: http_status_3xx("303","See other") { }
    };
    /**
     * Not modified.
     */
    class http_status_304 : public http_status_3xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_304(const string& m)
		: http_status_3xx("304",m) { }
	    explicit http_status_304()
		: http_status_3xx("304","Not modified") { }
    };
    /**
     * Use proxy.
     */
    class http_status_305 : public http_status_3xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_305(const string& m)
		: http_status_3xx("305",m) { }
	    explicit http_status_305()
		: http_status_3xx("305","Use proxy") { }
    };
    // 306 is unused and reserved
    /**
     * Temporary redirect.
     */
    class http_status_307 : public http_status_3xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_307(const string& m)
		: http_status_3xx("307",m) { }
	    explicit http_status_307()
		: http_status_3xx("307","Temporary redirect") { }
    };

    /**
     * Error.
     */
    class http_status_4xx : public http_status {
	public:
	    /**
	     * @param s HTTP status
	     * @param m HTTP status message
	     */
	    explicit http_status_4xx(const string& s,const string& m)
		: http_status(s,m) { }
    };
    /**
     * Bad request.
     */
    class http_status_400 : public http_status_4xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_400(const string& m)
		: http_status_4xx("400",m) { }
	    explicit http_status_400()
		: http_status_4xx("400","Bad request") { }
    };
    /**
     * Unauthorized.
     */
    class http_status_401 : public http_status_4xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_401(const string& m)
		: http_status_4xx("401",m) { }
	    explicit http_status_401()
		: http_status_4xx("401","Unauthorized") { }
    };
    /**
     * Payment required.
     */
    class http_status_402 : public http_status_4xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_402(const string& m)
		: http_status_4xx("402",m) { }
	    explicit http_status_402()
		: http_status_4xx("402","Payment required") { }
    };
    /**
     * Forbidden.
     */
    class http_status_403 : public http_status_4xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_403(const string& m)
		: http_status_4xx("403",m) { }
	    explicit http_status_403()
		: http_status_4xx("403","Forbidden") { }
    };
    /**
     * Not found.
     */
    class http_status_404 : public http_status_4xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_404(const string& m)
		: http_status_4xx("404",m) { }
	    explicit http_status_404()
		: http_status_4xx("404","Not found") { }
    };
    /**
     * Method not allowed.
     */
    class http_status_405 : public http_status_4xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_405(const string& m)
		: http_status_4xx("405",m) { }
	    explicit http_status_405()
		: http_status_4xx("405","Method not allowed") { }
    };
    /**
     * Not acceptable.
     */
    class http_status_406 : public http_status_4xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_406(const string& m)
		: http_status_4xx("406",m) { }
	    explicit http_status_406()
		: http_status_4xx("406","Not acceptable") { }
    };
    /**
     * Proxy authentication required.
     */
    class http_status_407 : public http_status_4xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_407(const string& m)
		: http_status_4xx("407",m) { }
	    explicit http_status_407()
		: http_status_4xx("407","Proxy authentication required") { }
    };
    /**
     * Request timeout.
     */
    class http_status_408 : public http_status_4xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_408(const string& m)
		: http_status_4xx("408",m) { }
	    explicit http_status_408()
		: http_status_4xx("408","Request timeout") { }
    };
    /**
     * Conflict.
     */
    class http_status_409 : public http_status_4xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_409(const string& m)
		: http_status_4xx("409",m) { }
	    explicit http_status_409()
		: http_status_4xx("409","Conflict") { }
    };
    /**
     * Gone.
     */
    class http_status_410 : public http_status_4xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_410(const string& m)
		: http_status_4xx("410",m) { }
	    explicit http_status_410()
		: http_status_4xx("410","Gone") { }
    };
    /**
     * Length required.
     */
    class http_status_411 : public http_status_4xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_411(const string& m)
		: http_status_4xx("411",m) { }
	    explicit http_status_411()
		: http_status_4xx("411","Length required") { }
    };
    /**
     * Precondition failed.
     */
    class http_status_412 : public http_status_4xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_412(const string& m)
		: http_status_4xx("412",m) { }
	    explicit http_status_412()
		: http_status_4xx("412","Precondition failed") { }
    };
    /**
     * Request entity too large.
     */
    class http_status_413 : public http_status_4xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_413(const string& m)
		: http_status_4xx("413",m) { }
	    explicit http_status_413()
		: http_status_4xx("413","Request entity too large") { }
    };
    /**
     * Request URI too long.
     */
    class http_status_414 : public http_status_4xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_414(const string& m)
		: http_status_4xx("414",m) { }
	    explicit http_status_414()
		: http_status_4xx("414","Request URI too long") { }
    };
    /**
     * Unsupported media type.
     */
    class http_status_415 : public http_status_4xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_415(const string& m)
		: http_status_4xx("415",m) { }
	    explicit http_status_415()
		: http_status_4xx("415","Unsupported media type") { }
    };
    /**
     * Requested range not satisfiable.
     */
    class http_status_416 : public http_status_4xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_416(const string& m)
		: http_status_4xx("416",m) { }
	    explicit http_status_416()
		: http_status_4xx("416","Requested range not satisfiable") { }
    };
    /**
     * Expectation failed.
     */
    class http_status_417 : public http_status_4xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_417(const string& m)
		: http_status_4xx("417",m) { }
	    explicit http_status_417()
		: http_status_4xx("417","Expectation failed") { }
    };

    /**
     * Server error.
     */
    class http_status_5xx : public http_status {
	public:
	    /**
	     * @param s HTTP status
	     * @param m HTTP status message
	     */
	    explicit http_status_5xx(const string& s,const string& m)
		: http_status(s,m) { }
    };
    /**
     * Internal server error.
     */
    class http_status_500 : public http_status_5xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_500(const string& m)
		: http_status_5xx("500",m) { }
	    explicit http_status_500()
		: http_status_5xx("500","Internal server error") { }
    };
    /**
     * Not implemented.
     */
    class http_status_501 : public http_status_5xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_501(const string& m)
		: http_status_5xx("501",m) { }
	    explicit http_status_501()
		: http_status_5xx("501","Not implemented") { }
    };
    /**
     * Bad gateway.
     */
    class http_status_502 : public http_status_5xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_502(const string& m)
		: http_status_5xx("502",m) { }
	    explicit http_status_502()
		: http_status_5xx("502","Bad gateway") { }
    };
    /**
     * Service unavailable.
     */
    class http_status_503 : public http_status_5xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_503(const string& m)
		: http_status_5xx("503",m) { }
	    explicit http_status_503()
		: http_status_5xx("503","Service unavailable") { }
    };
    /**
     * Gateway timeout.
     */
    class http_status_504 : public http_status_5xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_504(const string& m)
		: http_status_5xx("504",m) { }
	    explicit http_status_504()
		: http_status_5xx("504","Gateway timeout") { }
    };
    /**
     * HTTP version not supported.
     */
    class http_status_505 : public http_status_5xx {
	public:
	    /**
	     * @param m HTTP status message
	     */
	    explicit http_status_505(const string& m)
		: http_status_5xx("505",m) { }
	    explicit http_status_505()
		: http_status_5xx("505","HTTP version not supported") { }
    };

    // Aliases

    /**
     * Convenience alias for informational http status exceptions
     */
    typedef http_status_1xx http_status_informational;
    /**
     * @see http_status_100
     */
    typedef http_status_100 http_status_continue;
    /**
     * @see http_status_101
     */
    typedef http_status_101 http_status_switching_protocols;

    /**
     * Convenience alias for success http status exceptions
     */
    typedef http_status_2xx http_status_sucessful;
    /**
     * @see http_status_200
     */
    typedef http_status_200 http_status_ok;
    /**
     * @see http_status_201
     */
    typedef http_status_201 http_status_created;
    /**
     * @see http_status_202
     */
    typedef http_status_202 http_status_accepted;
    /**
     * @see http_status_203
     */
    typedef http_status_203 http_status_non_authoritative_information;
    /**
     * @see http_status_204
     */
    typedef http_status_204 http_status_no_content;
    /**
     * @see http_status_205
     */
    typedef http_status_205 http_status_reset_content;
    /**
     * @see http_status_206
     */
    typedef http_status_206 http_status_partial_content;

    /**
     * Convenience alias for redirection http status exceptions
     */
    typedef http_status_3xx http_status_redirection;
    /**
     * @see http_status_200
     */
    typedef http_status_300 http_status_multiple_choices;
    /**
     * @see http_status_301
     */
    typedef http_status_301 http_status_moved_permanently;
    /**
     * @see http_status_302
     */
    typedef http_status_302 http_status_found;
    /**
     * @see http_status_303
     */
    typedef http_status_303 http_status_see_other;
    /**
     * @see http_status_304
     */
    typedef http_status_304 http_status_not_modified;
    /**
     * @see http_status_305
     */
    typedef http_status_305 http_status_use_proxy;
    // 306 is unused and reserved
    /**
     * @see http_status_307
     */
    typedef http_status_307 http_status_temporary_redirect;

    /**
     * Convenience alias for client error http exceptions
     */
    typedef http_status_4xx http_status_client_error;
    /**
     * @see http_status_400
     */
    typedef http_status_400 http_status_bad_request;
    /**
     * @see http_status_401
     */
    typedef http_status_401 http_status_unauthorized;
    /**
     * @see http_status_402
     */
    typedef http_status_402 http_status_payment_required;
    /**
     * @see http_status_403
     */
    typedef http_status_403 http_status_forbidden;
    /**
     * @see http_status_404
     */
    typedef http_status_404 http_status_not_found;
    /**
     * @see http_status_405
     */
    typedef http_status_405 http_status_method_not_allowed;
    /**
     * @see http_status_406
     */
    typedef http_status_406 http_status_not_acceptable;
    /**
     * @see http_status_407
     */
    typedef http_status_407 http_status_proxy_authentication_required;
    /**
     * @see http_status_408
     */
    typedef http_status_408 http_status_request_timeout;
    /**
     * @see http_status_409
     */
    typedef http_status_409 http_status_conflict;
    /**
     * @see http_status_410
     */
    typedef http_status_410 http_status_gone;
    /**
     * @see http_status_411
     */
    typedef http_status_411 http_status_length_required;
    /**
     * @see http_status_412
     */
    typedef http_status_412 http_status_precondition_failed;
    /**
     * @see http_status_413
     */
    typedef http_status_413 http_status_request_entity_too_large;
    /**
     * @see http_status_414
     */
    typedef http_status_414 http_status_requrest_uri_too_long;
    /**
     * @see http_status_415
     */
    typedef http_status_415 http_status_unsupported_media_type;
    /**
     * @see http_status_416
     */
    typedef http_status_416 http_status_required_range_not_satisfiable;
    /**
     * @see http_status_417
     */
    typedef http_status_417 http_status_expectation_failed;

    /**
     * Convenience alias for server error http exceptions
     */
    typedef http_status_5xx http_status_server_error;
    /**
     * @see http_status_500
     */
    typedef http_status_500 http_status_internal_server_error;
    /**
     * @see http_status_501
     */
    typedef http_status_501 http_status_not_implemented;
    /**
     * @see http_status_502
     */
    typedef http_status_502 http_status_bad_gateway;
    /**
     * @see http_status_503
     */
    typedef http_status_503 http_status_service_unavailable;
    /**
     * @see http_status_504
     */
    typedef http_status_504 http_status_gateway_timeout;
    /**
     * @see http_status_505
     */
    typedef http_status_505 http_status_http_version_not_supported;

}

#endif /* __SITECING_EXCEPTION_H */