Mercurial > hg > orthanc
comparison OrthancServer/LuaScripting.cpp @ 1658:54bafe0e7e7b
Optional argument "keepStrings" in "DumpJson()"
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 30 Sep 2015 09:44:38 +0200 |
parents | d7e569640d09 |
children | d78b87f93bcf |
comparison
equal
deleted
inserted
replaced
1657:5360cdba70d8 | 1658:54bafe0e7e7b |
---|---|
81 } | 81 } |
82 | 82 |
83 const char* uri = lua_tostring(state, 1); | 83 const char* uri = lua_tostring(state, 1); |
84 bool builtin = (nArgs == 2 ? lua_toboolean(state, 2) != 0 : false); | 84 bool builtin = (nArgs == 2 ? lua_toboolean(state, 2) != 0 : false); |
85 | 85 |
86 std::string result; | 86 try |
87 if (HttpToolbox::SimpleGet(result, serverContext->GetHttpHandler().RestrictToOrthancRestApi(builtin), | 87 { |
88 RequestOrigin_Lua, uri)) | 88 std::string result; |
89 { | 89 if (HttpToolbox::SimpleGet(result, serverContext->GetHttpHandler().RestrictToOrthancRestApi(builtin), |
90 lua_pushlstring(state, result.c_str(), result.size()); | 90 RequestOrigin_Lua, uri)) |
91 } | 91 { |
92 else | 92 lua_pushlstring(state, result.c_str(), result.size()); |
93 { | 93 return 1; |
94 LOG(ERROR) << "Lua: Error in RestApiGet() for URI: " << uri; | 94 } |
95 lua_pushnil(state); | 95 } |
96 } | 96 catch (OrthancException& e) |
97 | 97 { |
98 LOG(ERROR) << "Lua: " << e.What(); | |
99 } | |
100 | |
101 LOG(ERROR) << "Lua: Error in RestApiGet() for URI: " << uri; | |
102 lua_pushnil(state); | |
98 return 1; | 103 return 1; |
99 } | 104 } |
100 | 105 |
101 | 106 |
102 int LuaScripting::RestApiPostOrPut(lua_State *state, | 107 int LuaScripting::RestApiPostOrPut(lua_State *state, |
125 const char* uri = lua_tostring(state, 1); | 130 const char* uri = lua_tostring(state, 1); |
126 size_t bodySize = 0; | 131 size_t bodySize = 0; |
127 const char* bodyData = lua_tolstring(state, 2, &bodySize); | 132 const char* bodyData = lua_tolstring(state, 2, &bodySize); |
128 bool builtin = (nArgs == 3 ? lua_toboolean(state, 3) != 0 : false); | 133 bool builtin = (nArgs == 3 ? lua_toboolean(state, 3) != 0 : false); |
129 | 134 |
130 std::string result; | 135 try |
131 if (isPost ? | 136 { |
132 HttpToolbox::SimplePost(result, serverContext->GetHttpHandler().RestrictToOrthancRestApi(builtin), | 137 std::string result; |
133 RequestOrigin_Lua, uri, bodyData, bodySize) : | 138 if (isPost ? |
134 HttpToolbox::SimplePut(result, serverContext->GetHttpHandler().RestrictToOrthancRestApi(builtin), | 139 HttpToolbox::SimplePost(result, serverContext->GetHttpHandler().RestrictToOrthancRestApi(builtin), |
135 RequestOrigin_Lua, uri, bodyData, bodySize)) | 140 RequestOrigin_Lua, uri, bodyData, bodySize) : |
136 { | 141 HttpToolbox::SimplePut(result, serverContext->GetHttpHandler().RestrictToOrthancRestApi(builtin), |
137 lua_pushlstring(state, result.c_str(), result.size()); | 142 RequestOrigin_Lua, uri, bodyData, bodySize)) |
138 } | 143 { |
139 else | 144 lua_pushlstring(state, result.c_str(), result.size()); |
140 { | 145 return 1; |
141 LOG(ERROR) << "Lua: Error in " << (isPost ? "RestApiPost()" : "RestApiPut()") << " for URI: " << uri; | 146 } |
142 lua_pushnil(state); | 147 } |
143 } | 148 catch (OrthancException& e) |
144 | 149 { |
150 LOG(ERROR) << "Lua: " << e.What(); | |
151 } | |
152 | |
153 LOG(ERROR) << "Lua: Error in " << (isPost ? "RestApiPost()" : "RestApiPut()") << " for URI: " << uri; | |
154 lua_pushnil(state); | |
145 return 1; | 155 return 1; |
146 } | 156 } |
147 | 157 |
148 | 158 |
149 // Syntax in Lua: RestApiPost(uri, body, builtin) | 159 // Syntax in Lua: RestApiPost(uri, body, builtin) |
183 } | 193 } |
184 | 194 |
185 const char* uri = lua_tostring(state, 1); | 195 const char* uri = lua_tostring(state, 1); |
186 bool builtin = (nArgs == 2 ? lua_toboolean(state, 2) != 0 : false); | 196 bool builtin = (nArgs == 2 ? lua_toboolean(state, 2) != 0 : false); |
187 | 197 |
188 if (HttpToolbox::SimpleDelete(serverContext->GetHttpHandler().RestrictToOrthancRestApi(builtin), | 198 try |
189 RequestOrigin_Lua, uri)) | 199 { |
190 { | 200 if (HttpToolbox::SimpleDelete(serverContext->GetHttpHandler().RestrictToOrthancRestApi(builtin), |
191 lua_pushboolean(state, 1); | 201 RequestOrigin_Lua, uri)) |
192 } | 202 { |
193 else | 203 lua_pushboolean(state, 1); |
194 { | 204 return 1; |
195 LOG(ERROR) << "Lua: Error in RestApiDelete() for URI: " << uri; | 205 } |
196 lua_pushnil(state); | 206 } |
197 } | 207 catch (OrthancException& e) |
208 { | |
209 LOG(ERROR) << "Lua: " << e.What(); | |
210 } | |
211 | |
212 LOG(ERROR) << "Lua: Error in RestApiDelete() for URI: " << uri; | |
213 lua_pushnil(state); | |
198 | 214 |
199 return 1; | 215 return 1; |
200 } | 216 } |
201 | 217 |
202 | 218 |
314 | 330 |
315 void LuaScripting::SubmitJob(const std::string& description) | 331 void LuaScripting::SubmitJob(const std::string& description) |
316 { | 332 { |
317 Json::Value operations; | 333 Json::Value operations; |
318 LuaFunctionCall call2(lua_, "_AccessJob"); | 334 LuaFunctionCall call2(lua_, "_AccessJob"); |
319 call2.ExecuteToJson(operations); | 335 call2.ExecuteToJson(operations, false); |
320 | 336 |
321 if (operations.type() != Json::arrayValue) | 337 if (operations.type() != Json::arrayValue) |
322 { | 338 { |
323 throw OrthancException(ErrorCode_InternalError); | 339 throw OrthancException(ErrorCode_InternalError); |
324 } | 340 } |