annotate Core/HttpServer/HttpOutput.h @ 1066:bb82e5e818e9

OnStoredInstance callback in plugins
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 25 Jul 2014 18:39:02 +0200
parents 8d1845feb277
children ba5c0908600c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
59
c996319e90bc renaming in Core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
689
2d0a347e8cfc switch to 2014
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege,
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Belgium
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
136
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
10 *
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
11 * In addition, as a special exception, the copyright holders of this
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
12 * program give permission to link the code of its release with the
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
15 * the linked executables. You must obey the GNU General Public License
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
16 * in all respects for all of the code used other than "OpenSSL". If you
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
17 * modify file(s) with this exception, you may extend this exception to
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
18 * your version of the file(s), but you are not obligated to do so. If
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
19 * you do not wish to do so, delete this exception statement from your
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
20 * version. If you delete this exception statement from all source files
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
21 * in the program, then also delete it here.
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * This program is distributed in the hope that it will be useful, but
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * You should have received a copy of the GNU General Public License
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 **/
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #pragma once
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
330
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 324
diff changeset
35 #include <list>
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 #include <string>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include <stdint.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 #include "../Enumerations.h"
910
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
39 #include "IHttpOutputStream.h"
324
64925c94825c api improvement
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
40 #include "HttpHandler.h"
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
59
c996319e90bc renaming in Core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
42 namespace Orthanc
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 {
912
dcb2469f00f4 PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 911
diff changeset
44 class HttpOutput : public boost::noncopyable
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 private:
330
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 324
diff changeset
47 typedef std::list< std::pair<std::string, std::string> > Header;
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 324
diff changeset
48
910
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
49 class StateMachine : public boost::noncopyable
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
50 {
911
306afd58a0b3 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 910
diff changeset
51 private:
910
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
52 enum State
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
53 {
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
54 State_WaitingHttpStatus,
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
55 State_WritingHeader,
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
56 State_WritingBody
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
57 };
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
58
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
59 IHttpOutputStream& stream_;
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
60 State state_;
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
61
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
62 public:
911
306afd58a0b3 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 910
diff changeset
63 StateMachine(IHttpOutputStream& stream) :
306afd58a0b3 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 910
diff changeset
64 stream_(stream),
910
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
65 state_(State_WaitingHttpStatus)
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
66 {
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
67 }
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
68
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
69 void SendHttpStatus(HttpStatus status);
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
70
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
71 void SendHeaderData(const void* buffer, size_t length);
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
72
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
73 void SendHeaderString(const std::string& str);
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
74
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
75 void SendBodyData(const void* buffer, size_t length);
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
76
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
77 void SendBodyString(const std::string& str);
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
78 };
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
79
330
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 324
diff changeset
80 void PrepareOkHeader(Header& header,
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 324
diff changeset
81 const char* contentType,
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 324
diff changeset
82 bool hasContentLength,
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 324
diff changeset
83 uint64_t contentLength,
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 324
diff changeset
84 const char* contentFilename);
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 324
diff changeset
85
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 324
diff changeset
86 void SendOkHeader(const Header& header);
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 324
diff changeset
87
910
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
88 StateMachine stateMachine_;
1042
8d1845feb277 set cookies, not allowed methods, unauthorized in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 912
diff changeset
89 HttpHandler::Arguments cookies_;
908
e078ea944089 refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
90
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 public:
910
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
92 HttpOutput(IHttpOutputStream& stream) : stateMachine_(stream)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
96 void SendOkHeader(const char* contentType,
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
97 bool hasContentLength,
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
98 uint64_t contentLength,
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
99 const char* contentFilename);
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
100
908
e078ea944089 refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
101 void SendBodyData(const void* buffer, size_t length)
e078ea944089 refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
102 {
911
306afd58a0b3 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 910
diff changeset
103 stateMachine_.SendBodyData(buffer, length);
908
e078ea944089 refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
104 }
e078ea944089 refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
105
e078ea944089 refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
106 void SendBodyString(const std::string& str)
e078ea944089 refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
107 {
911
306afd58a0b3 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 910
diff changeset
108 stateMachine_.SendBodyString(str);
908
e078ea944089 refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
109 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110
1042
8d1845feb277 set cookies, not allowed methods, unauthorized in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 912
diff changeset
111 void SendMethodNotAllowed(const std::string& allowed);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112
473
c9a5d72f8481 changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
113 void SendHeader(HttpStatus status);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114
217
1ac3aacd10a5 simplifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 207
diff changeset
115 void Redirect(const std::string& path);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116
908
e078ea944089 refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
117 void SendUnauthorized(const std::string& realm);
e078ea944089 refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
118
1042
8d1845feb277 set cookies, not allowed methods, unauthorized in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 912
diff changeset
119 void SetCookie(const std::string& cookie,
8d1845feb277 set cookies, not allowed methods, unauthorized in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 912
diff changeset
120 const std::string& value)
8d1845feb277 set cookies, not allowed methods, unauthorized in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 912
diff changeset
121 {
8d1845feb277 set cookies, not allowed methods, unauthorized in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 912
diff changeset
122 cookies_[cookie] = value;
8d1845feb277 set cookies, not allowed methods, unauthorized in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 912
diff changeset
123 }
8d1845feb277 set cookies, not allowed methods, unauthorized in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 912
diff changeset
124
217
1ac3aacd10a5 simplifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 207
diff changeset
125 // Higher-level constructs to send entire buffers ----------------------------
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 void AnswerBufferWithContentType(const std::string& buffer,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 const std::string& contentType);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 void AnswerBufferWithContentType(const void* buffer,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 size_t size,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 const std::string& contentType);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 };
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 }