Mercurial > hg > orthanc
annotate Core/RestApi/RestApiPath.cpp @ 875:d21031a7a6e4
build instructions
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 11 Jun 2014 13:23:05 +0200 |
parents | a811bdf8b8eb |
children | 886652370ff2 |
rev | line source |
---|---|
209 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
689 | 3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, |
209 | 4 * Belgium |
5 * | |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
10 * | |
11 * In addition, as a special exception, the copyright holders of this | |
12 * program give permission to link the code of its release with the | |
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
14 * that use the same license as the "OpenSSL" library), and distribute | |
15 * the linked executables. You must obey the GNU General Public License | |
16 * in all respects for all of the code used other than "OpenSSL". If you | |
17 * modify file(s) with this exception, you may extend this exception to | |
18 * your version of the file(s), but you are not obligated to do so. If | |
19 * you do not wish to do so, delete this exception statement from your | |
20 * version. If you delete this exception statement from all source files | |
21 * in the program, then also delete it here. | |
22 * | |
23 * This program is distributed in the hope that it will be useful, but | |
24 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 * General Public License for more details. | |
27 * | |
28 * You should have received a copy of the GNU General Public License | |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
30 **/ | |
31 | |
32 | |
824
a811bdf8b8eb
precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
33 #include "../PrecompiledHeaders.h" |
209 | 34 #include "RestApiPath.h" |
35 | |
36 #include <cassert> | |
37 | |
38 namespace Orthanc | |
39 { | |
40 RestApiPath::RestApiPath(const std::string& uri) | |
41 { | |
42 Toolbox::SplitUriComponents(uri_, uri); | |
43 | |
44 if (uri_.size() == 0) | |
45 { | |
218 | 46 hasTrailing_ = false; |
209 | 47 return; |
48 } | |
49 | |
50 if (uri_.back() == "*") | |
51 { | |
52 hasTrailing_ = true; | |
53 uri_.pop_back(); | |
54 } | |
55 else | |
56 { | |
57 hasTrailing_ = false; | |
58 } | |
59 | |
60 components_.resize(uri_.size()); | |
61 for (size_t i = 0; i < uri_.size(); i++) | |
62 { | |
63 size_t s = uri_[i].size(); | |
64 assert(s > 0); | |
65 | |
66 if (uri_[i][0] == '{' && | |
67 uri_[i][s - 1] == '}') | |
68 { | |
69 components_[i] = uri_[i].substr(1, s - 2); | |
70 uri_[i] = ""; | |
71 } | |
72 else | |
73 { | |
74 components_[i] = ""; | |
75 } | |
76 } | |
77 } | |
78 | |
79 bool RestApiPath::Match(Components& components, | |
80 UriComponents& trailing, | |
81 const std::string& uriRaw) const | |
82 { | |
83 UriComponents uri; | |
84 Toolbox::SplitUriComponents(uri, uriRaw); | |
85 return Match(components, trailing, uri); | |
86 } | |
87 | |
88 bool RestApiPath::Match(Components& components, | |
89 UriComponents& trailing, | |
90 const UriComponents& uri) const | |
91 { | |
92 if (uri.size() < uri_.size()) | |
93 { | |
94 return false; | |
95 } | |
96 | |
97 if (!hasTrailing_ && uri.size() > uri_.size()) | |
98 { | |
99 return false; | |
100 } | |
101 | |
102 components.clear(); | |
103 trailing.clear(); | |
104 | |
105 assert(uri_.size() <= uri.size()); | |
106 for (size_t i = 0; i < uri_.size(); i++) | |
107 { | |
108 if (components_[i].size() == 0) | |
109 { | |
110 // This URI component is not a free parameter | |
111 if (uri_[i] != uri[i]) | |
112 { | |
113 return false; | |
114 } | |
115 } | |
116 else | |
117 { | |
118 // This URI component is a free parameter | |
119 components[components_[i]] = uri[i]; | |
120 } | |
121 } | |
122 | |
123 if (hasTrailing_) | |
124 { | |
125 trailing.assign(uri.begin() + uri_.size(), uri.end()); | |
126 } | |
127 | |
128 return true; | |
129 } | |
130 | |
131 | |
132 bool RestApiPath::Match(const UriComponents& uri) const | |
133 { | |
134 Components components; | |
135 UriComponents trailing; | |
136 return Match(components, trailing, uri); | |
137 } | |
138 } |