Mercurial > hg > orthanc
annotate OrthancServer/Sources/OrthancHttpHandler.cpp @ 4894:6a501ad6545e openssl-3.x
integration mainline->openssl-3.x
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sun, 20 Feb 2022 11:16:05 +0100 |
parents | 6eff25f70121 |
children | 0ea402b4d901 |
rev | line source |
---|---|
1442 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1442 | 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 |
1442 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
9 * modify it under the terms of the GNU General Public License as | |
10 * published by the Free Software Foundation, either version 3 of the | |
11 * License, or (at your option) any later version. | |
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 | |
16 * General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 **/ | |
21 | |
22 | |
23 #include "PrecompiledHeadersServer.h" | |
24 #include "OrthancHttpHandler.h" | |
25 | |
4045 | 26 #include "../../OrthancFramework/Sources/OrthancException.h" |
1442 | 27 |
28 | |
29 namespace Orthanc | |
30 { | |
3414 | 31 bool OrthancHttpHandler::CreateChunkedRequestReader( |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
32 std::unique_ptr<IHttpHandler::IChunkedRequestReader>& target, |
3414 | 33 RequestOrigin origin, |
34 const char* remoteIp, | |
35 const char* username, | |
36 HttpMethod method, | |
37 const UriComponents& uri, | |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
38 const HttpToolbox::Arguments& headers) |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
39 { |
3414 | 40 if (method != HttpMethod_Post && |
41 method != HttpMethod_Put) | |
42 { | |
43 throw OrthancException(ErrorCode_InternalError); | |
44 } | |
45 | |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
46 for (Handlers::const_iterator it = handlers_.begin(); it != handlers_.end(); ++it) |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
47 { |
3414 | 48 if ((*it)->CreateChunkedRequestReader |
49 (target, origin, remoteIp, username, method, uri, headers)) | |
50 { | |
51 if (target.get() == NULL) | |
52 { | |
53 throw OrthancException(ErrorCode_InternalError); | |
54 } | |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
55 |
3414 | 56 return true; |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
57 } |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
58 } |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
59 |
3414 | 60 return false; |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
61 } |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
62 |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
63 |
1442 | 64 bool OrthancHttpHandler::Handle(HttpOutput& output, |
1571
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1446
diff
changeset
|
65 RequestOrigin origin, |
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1446
diff
changeset
|
66 const char* remoteIp, |
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1446
diff
changeset
|
67 const char* username, |
1442 | 68 HttpMethod method, |
69 const UriComponents& uri, | |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
70 const HttpToolbox::Arguments& headers, |
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
71 const HttpToolbox::GetArguments& getArguments, |
3401 | 72 const void* bodyData, |
1446
8dc80ba768aa
refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
73 size_t bodySize) |
1442 | 74 { |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
75 for (Handlers::const_iterator it = handlers_.begin(); it != handlers_.end(); ++it) |
1442 | 76 { |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
77 if ((*it)->Handle(output, origin, remoteIp, username, method, uri, |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
78 headers, getArguments, bodyData, bodySize)) |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
79 { |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
80 return true; |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
81 } |
1442 | 82 } |
83 | |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
84 return false; |
1442 | 85 } |
86 | |
87 | |
1443
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1442
diff
changeset
|
88 void OrthancHttpHandler::Register(IHttpHandler& handler, |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1442
diff
changeset
|
89 bool isOrthancRestApi) |
1442 | 90 { |
91 handlers_.push_back(&handler); | |
92 | |
93 if (isOrthancRestApi) | |
94 { | |
95 orthancRestApi_ = &handler; | |
96 } | |
97 } | |
98 | |
99 | |
1445
d26c8a93d05a
refactoring: SimpleGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1443
diff
changeset
|
100 IHttpHandler& OrthancHttpHandler::RestrictToOrthancRestApi(bool restrict) |
1442 | 101 { |
1445
d26c8a93d05a
refactoring: SimpleGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1443
diff
changeset
|
102 if (restrict) |
1442 | 103 { |
1445
d26c8a93d05a
refactoring: SimpleGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1443
diff
changeset
|
104 if (orthancRestApi_ == NULL) |
d26c8a93d05a
refactoring: SimpleGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1443
diff
changeset
|
105 { |
d26c8a93d05a
refactoring: SimpleGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1443
diff
changeset
|
106 throw OrthancException(ErrorCode_InternalError); |
d26c8a93d05a
refactoring: SimpleGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1443
diff
changeset
|
107 } |
d26c8a93d05a
refactoring: SimpleGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1443
diff
changeset
|
108 |
d26c8a93d05a
refactoring: SimpleGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1443
diff
changeset
|
109 return *orthancRestApi_; |
1442 | 110 } |
1445
d26c8a93d05a
refactoring: SimpleGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1443
diff
changeset
|
111 else |
d26c8a93d05a
refactoring: SimpleGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1443
diff
changeset
|
112 { |
d26c8a93d05a
refactoring: SimpleGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1443
diff
changeset
|
113 return *this; |
d26c8a93d05a
refactoring: SimpleGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1443
diff
changeset
|
114 } |
1442 | 115 } |
116 } |