annotate OrthancFramework/Sources/Images/PamReader.h @ 4151:8c559dd5034b

Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 19 Aug 2020 11:59:02 +0200
parents bf7b9edf6b81
children afad57ac30ef
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
1 /**
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
3640
94f4a18a79cc upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3456
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
6 *
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
7 * 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: 4063
diff changeset
8 * 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: 4063
diff changeset
9 * 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: 4063
diff changeset
10 * the License, or (at your option) any later version.
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
11 *
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
14 * 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: 4063
diff changeset
15 * Lesser General Public License for more details.
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
16 *
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
17 * 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: 4063
diff changeset
18 * 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: 4063
diff changeset
19 * <http://www.gnu.org/licenses/>.
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
20 **/
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
21
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
22
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
23 #pragma once
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
24
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
25 #include "ImageAccessor.h"
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
26
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
27 #if !defined(ORTHANC_SANDBOXED)
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
28 # error The macro ORTHANC_SANDBOXED must be defined
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
29 #endif
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
30
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
31 namespace Orthanc
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
32 {
4063
e00f3d089991 shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
33 class ORTHANC_PUBLIC PamReader : public ImageAccessor
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
34 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
35 private:
2705
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2702
diff changeset
36 void ParseContent();
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2702
diff changeset
37
3834
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
38 /**
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
39 Whether we want to use the default malloc alignment in the image buffer,
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
40 at the expense of an extra copy
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
41 */
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
42 bool enforceAligned_;
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
43
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
44 /**
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
45 This is actually a copy of wrappedContent_, but properly aligned.
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
46
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
47 It is only used if the enforceAligned parameter is set to true in the
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
48 constructor.
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
49 */
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
50 void* alignedImageBuffer_;
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
51
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
52 /**
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
53 Points somewhere in the content_ buffer.
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
54 */
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
55 ImageAccessor wrappedContent_;
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
56
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
57 /**
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
58 Raw content (file bytes or answer from the server, for instance).
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
59 */
2705
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2702
diff changeset
60 std::string content_;
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
61
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
62 public:
3834
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
63 /**
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
64 See doc for field enforceAligned_
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
65 */
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
66 PamReader(bool enforceAligned = false) :
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
67 enforceAligned_(enforceAligned),
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
68 alignedImageBuffer_(NULL)
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
69 {
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
70 }
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
71
3838
95083d2f6819 fix build on os x
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3834
diff changeset
72 virtual ~PamReader();
3455
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
73
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
74 #if ORTHANC_SANDBOXED == 0
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
75 void ReadFromFile(const std::string& filename);
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
76 #endif
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
77
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
78 void ReadFromMemory(const std::string& buffer);
2919
2ca9cd064b15 PamReader::ReadFromMemory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2861
diff changeset
79
2ca9cd064b15 PamReader::ReadFromMemory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2861
diff changeset
80 void ReadFromMemory(const void* buffer,
2ca9cd064b15 PamReader::ReadFromMemory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2861
diff changeset
81 size_t size);
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
82 };
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
83 }