Mercurial > hg > orthanc
annotate OrthancFramework/Sources/HttpServer/HttpContentNegociation.h @ 5640:f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 30 May 2024 21:19:57 +0200 |
parents | 48b8dae6dc77 |
children |
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 |
5640
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
5485
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
1783 | 8 * |
9 * 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
|
10 * 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
|
11 * 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
|
12 * the License, or (at your option) any later version. |
1783 | 13 * |
14 * This program is distributed in the hope that it will be useful, but | |
15 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * 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
|
17 * Lesser General Public License for more details. |
1783 | 18 * |
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
|
19 * 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
|
20 * 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
|
21 * <http://www.gnu.org/licenses/>. |
1783 | 22 **/ |
23 | |
24 #pragma once | |
25 | |
3992
f9863630ec7f
working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
26 #include "../OrthancFramework.h" |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
27 #include "../Compatibility.h" |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
28 |
1783 | 29 #include <memory> |
30 #include <boost/noncopyable.hpp> | |
31 #include <map> | |
32 #include <list> | |
33 #include <string> | |
34 #include <vector> | |
35 #include <stdint.h> | |
36 | |
37 | |
38 namespace Orthanc | |
39 { | |
3992
f9863630ec7f
working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
40 class ORTHANC_PUBLIC HttpContentNegociation : public boost::noncopyable |
1783 | 41 { |
42 public: | |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
43 typedef std::map<std::string, std::string> Dictionary; |
1783 | 44 |
45 class IHandler : public boost::noncopyable | |
46 { | |
47 public: | |
48 virtual ~IHandler() | |
49 { | |
50 } | |
51 | |
52 virtual void Handle(const std::string& type, | |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
53 const std::string& subtype, |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
54 const Dictionary& parameters) = 0; |
1783 | 55 }; |
56 | |
57 private: | |
58 struct Handler | |
59 { | |
60 std::string type_; | |
61 std::string subtype_; | |
62 IHandler& handler_; | |
63 | |
64 Handler(const std::string& type, | |
65 const std::string& subtype, | |
66 IHandler& handler); | |
67 | |
68 bool IsMatch(const std::string& type, | |
69 const std::string& subtype) const; | |
70 | |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
71 void Call(const Dictionary& parameters) const |
1783 | 72 { |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
73 handler_.Handle(type_, subtype_, parameters); |
1783 | 74 } |
75 }; | |
76 | |
77 | |
78 struct Reference; | |
79 | |
80 typedef std::vector<std::string> Tokens; | |
81 typedef std::list<Handler> Handlers; | |
82 | |
83 Handlers handlers_; | |
84 | |
85 | |
86 static bool SplitPair(std::string& first /* out */, | |
87 std::string& second /* out */, | |
88 const std::string& source, | |
89 char separator); | |
90 | |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
91 static void SelectBestMatch(std::unique_ptr<Reference>& target, |
1783 | 92 const Handler& handler, |
93 const std::string& type, | |
94 const std::string& subtype, | |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
95 const Dictionary& parameters); |
1783 | 96 |
97 public: | |
98 void Register(const std::string& mime, | |
99 IHandler& handler); | |
100 | |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
101 bool Apply(const Dictionary& headers); |
1783 | 102 |
103 bool Apply(const std::string& accept); | |
104 }; | |
105 } |