annotate Core/HttpServer/HttpContentNegociation.h @ 3843:138d0dde41b5

end of replacements of DicomUserConnection by DicomControlUserConnection
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 16 Apr 2020 17:24:24 +0200
parents 2a170a8f1faf
children f9863630ec7f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1783
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1783
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1783
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
3640
94f4a18a79cc upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
1783
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * In addition, as a special exception, the copyright holders of this
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * program give permission to link the code of its release with the
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * the linked executables. You must obey the GNU General Public License
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * in all respects for all of the code used other than "OpenSSL". If you
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * modify file(s) with this exception, you may extend this exception to
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * your version of the file(s), but you are not obligated to do so. If
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * you do not wish to do so, delete this exception statement from your
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * version. If you delete this exception statement from all source files
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 * in the program, then also delete it here.
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 *
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * This program is distributed in the hope that it will be useful, but
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * General Public License for more details.
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 *
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * You should have received a copy of the GNU General Public License
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 **/
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #pragma once
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
35 #include "../Compatibility.h"
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
36
1783
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include <memory>
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 #include <boost/noncopyable.hpp>
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 #include <map>
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 #include <list>
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 #include <string>
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 #include <vector>
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 #include <stdint.h>
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 namespace Orthanc
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 {
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 class HttpContentNegociation : public boost::noncopyable
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 {
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 public:
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 typedef std::map<std::string, std::string> HttpHeaders;
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 class IHandler : public boost::noncopyable
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 {
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 public:
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 virtual ~IHandler()
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 {
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 }
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 virtual void Handle(const std::string& type,
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 const std::string& subtype) = 0;
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 };
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 private:
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 struct Handler
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 {
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 std::string type_;
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 std::string subtype_;
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 IHandler& handler_;
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 Handler(const std::string& type,
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 const std::string& subtype,
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 IHandler& handler);
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 bool IsMatch(const std::string& type,
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 const std::string& subtype) const;
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 void Call() const
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 {
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 handler_.Handle(type_, subtype_);
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 }
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 };
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 struct Reference;
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 typedef std::vector<std::string> Tokens;
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 typedef std::list<Handler> Handlers;
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 Handlers handlers_;
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 static bool SplitPair(std::string& first /* out */,
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 std::string& second /* out */,
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 const std::string& source,
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 char separator);
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 static float GetQuality(const Tokens& parameters);
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
100 static void SelectBestMatch(std::unique_ptr<Reference>& best,
1783
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 const Handler& handler,
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 const std::string& type,
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 const std::string& subtype,
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 float quality);
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 public:
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 void Register(const std::string& mime,
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 IHandler& handler);
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 bool Apply(const HttpHeaders& headers);
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 bool Apply(const std::string& accept);
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 };
dbb07eb1a2f3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 }