annotate OrthancServer/Sources/OrthancHttpHandler.cpp @ 4709:a9a75281cae9 openssl-3.x

fix build on MSVC 2008 32bit
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 22 Jun 2021 10:26:27 +0200
parents f0038043fb97
children 2e71a08eea15
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1442
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1571
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1442
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
4437
d9473bd5ed43 upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium
1442
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * General Public License for more details.
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include "PrecompiledHeadersServer.h"
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include "OrthancHttpHandler.h"
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
4045
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
25 #include "../../OrthancFramework/Sources/OrthancException.h"
1442
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 namespace Orthanc
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 {
3414
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
30 bool OrthancHttpHandler::CreateChunkedRequestReader(
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
31 std::unique_ptr<IHttpHandler::IChunkedRequestReader>& target,
3414
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
32 RequestOrigin origin,
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
33 const char* remoteIp,
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
34 const char* username,
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
35 HttpMethod method,
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
36 const UriComponents& uri,
4330
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
37 const HttpToolbox::Arguments& headers)
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
38 {
3414
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
39 if (method != HttpMethod_Post &&
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
40 method != HttpMethod_Put)
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
41 {
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
42 throw OrthancException(ErrorCode_InternalError);
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
43 }
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
44
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
45 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
46 {
3414
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
47 if ((*it)->CreateChunkedRequestReader
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
48 (target, origin, remoteIp, username, method, uri, headers))
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
49 {
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
50 if (target.get() == NULL)
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
51 {
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
52 throw OrthancException(ErrorCode_InternalError);
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
53 }
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
54
3414
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
55 return true;
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
56 }
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
3414
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
59 return false;
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
60 }
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
1442
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 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
64 RequestOrigin origin,
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1446
diff changeset
65 const char* remoteIp,
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1446
diff changeset
66 const char* username,
1442
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 HttpMethod method,
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 const UriComponents& uri,
4330
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
69 const HttpToolbox::Arguments& headers,
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
70 const HttpToolbox::GetArguments& getArguments,
3401
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3395
diff changeset
71 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
72 size_t bodySize)
1442
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 {
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
74 for (Handlers::const_iterator it = handlers_.begin(); it != handlers_.end(); ++it)
1442
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 {
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
76 if ((*it)->Handle(output, origin, remoteIp, username, method, uri,
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
77 headers, getArguments, bodyData, bodySize))
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
78 {
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
79 return true;
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
80 }
1442
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 }
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
83 return false;
1442
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 }
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86
1443
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1442
diff changeset
87 void OrthancHttpHandler::Register(IHttpHandler& handler,
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1442
diff changeset
88 bool isOrthancRestApi)
1442
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 {
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 handlers_.push_back(&handler);
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 if (isOrthancRestApi)
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 {
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 orthancRestApi_ = &handler;
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 }
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 }
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98
1445
d26c8a93d05a refactoring: SimpleGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1443
diff changeset
99 IHttpHandler& OrthancHttpHandler::RestrictToOrthancRestApi(bool restrict)
1442
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 {
1445
d26c8a93d05a refactoring: SimpleGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1443
diff changeset
101 if (restrict)
1442
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 {
1445
d26c8a93d05a refactoring: SimpleGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1443
diff changeset
103 if (orthancRestApi_ == NULL)
d26c8a93d05a refactoring: SimpleGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1443
diff changeset
104 {
d26c8a93d05a refactoring: SimpleGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1443
diff changeset
105 throw OrthancException(ErrorCode_InternalError);
d26c8a93d05a refactoring: SimpleGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1443
diff changeset
106 }
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 return *orthancRestApi_;
1442
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 }
1445
d26c8a93d05a refactoring: SimpleGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1443
diff changeset
110 else
d26c8a93d05a refactoring: SimpleGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1443
diff changeset
111 {
d26c8a93d05a refactoring: SimpleGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1443
diff changeset
112 return *this;
d26c8a93d05a refactoring: SimpleGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1443
diff changeset
113 }
1442
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 }
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 }