Mercurial > hg > orthanc
annotate OrthancFramework/Sources/HttpServer/HttpContentNegociation.h @ 4984:c8cdf5163cd2
cppcheck
author | Alain Mazy <am@osimis.io> |
---|---|
date | Mon, 25 Apr 2022 18:54:45 +0200 |
parents | 43e613a7756b |
children | 0ea402b4d901 |
rev | line source |
---|---|
1783 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1783 | 4 * Department, University Hospital of Liege, Belgium |
4870
43e613a7756b
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
43e613a7756b
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
1783 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public License |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
10 * as published by the Free Software Foundation, either version 3 of |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
11 * the License, or (at your option) any later version. |
1783 | 12 * |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
16 * Lesser General Public License for more details. |
1783 | 17 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
19 * License along with this program. If not, see |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
20 * <http://www.gnu.org/licenses/>. |
1783 | 21 **/ |
22 | |
23 #pragma once | |
24 | |
3992
f9863630ec7f
working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
25 #include "../OrthancFramework.h" |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
26 #include "../Compatibility.h" |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
27 |
1783 | 28 #include <memory> |
29 #include <boost/noncopyable.hpp> | |
30 #include <map> | |
31 #include <list> | |
32 #include <string> | |
33 #include <vector> | |
34 #include <stdint.h> | |
35 | |
36 | |
37 namespace Orthanc | |
38 { | |
3992
f9863630ec7f
working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
39 class ORTHANC_PUBLIC HttpContentNegociation : public boost::noncopyable |
1783 | 40 { |
41 public: | |
42 typedef std::map<std::string, std::string> HttpHeaders; | |
43 | |
44 class IHandler : public boost::noncopyable | |
45 { | |
46 public: | |
47 virtual ~IHandler() | |
48 { | |
49 } | |
50 | |
51 virtual void Handle(const std::string& type, | |
52 const std::string& subtype) = 0; | |
53 }; | |
54 | |
55 private: | |
56 struct Handler | |
57 { | |
58 std::string type_; | |
59 std::string subtype_; | |
60 IHandler& handler_; | |
61 | |
62 Handler(const std::string& type, | |
63 const std::string& subtype, | |
64 IHandler& handler); | |
65 | |
66 bool IsMatch(const std::string& type, | |
67 const std::string& subtype) const; | |
68 | |
69 void Call() const | |
70 { | |
71 handler_.Handle(type_, subtype_); | |
72 } | |
73 }; | |
74 | |
75 | |
76 struct Reference; | |
77 | |
78 typedef std::vector<std::string> Tokens; | |
79 typedef std::list<Handler> Handlers; | |
80 | |
81 Handlers handlers_; | |
82 | |
83 | |
84 static bool SplitPair(std::string& first /* out */, | |
85 std::string& second /* out */, | |
86 const std::string& source, | |
87 char separator); | |
88 | |
89 static float GetQuality(const Tokens& parameters); | |
90 | |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
91 static void SelectBestMatch(std::unique_ptr<Reference>& best, |
1783 | 92 const Handler& handler, |
93 const std::string& type, | |
94 const std::string& subtype, | |
95 float quality); | |
96 | |
97 public: | |
98 void Register(const std::string& mime, | |
99 IHandler& handler); | |
100 | |
101 bool Apply(const HttpHeaders& headers); | |
102 | |
103 bool Apply(const std::string& accept); | |
104 }; | |
105 } |