comparison Core/Lua/LuaContext.cpp @ 4026:05a363186da6

ORTHANC_BUILDING_FRAMEWORK_LIBRARY, Orthanc::InitializeFramework()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 09 Jun 2020 16:26:57 +0200
parents 94f4a18a79cc
children e3b3af80732d
comparison
equal deleted inserted replaced
4019:bf35c4628777 4026:05a363186da6
165 165
166 return 1; 166 return 1;
167 } 167 }
168 168
169 169
170 #if ORTHANC_ENABLE_CURL == 1
170 int LuaContext::SetHttpCredentials(lua_State *state) 171 int LuaContext::SetHttpCredentials(lua_State *state)
171 { 172 {
172 LuaContext& that = GetLuaContext(state); 173 LuaContext& that = GetLuaContext(state);
173 174
174 // Check the types of the arguments 175 // Check the types of the arguments
187 that.httpClient_.SetCredentials(username, password); 188 that.httpClient_.SetCredentials(username, password);
188 } 189 }
189 190
190 return 0; 191 return 0;
191 } 192 }
192 193 #endif
193 194
195
196 #if ORTHANC_ENABLE_CURL == 1
194 bool LuaContext::AnswerHttpQuery(lua_State* state) 197 bool LuaContext::AnswerHttpQuery(lua_State* state)
195 { 198 {
196 std::string str; 199 std::string str;
197 200
198 try 201 try
207 // Return the result of the HTTP request 210 // Return the result of the HTTP request
208 lua_pushlstring(state, str.c_str(), str.size()); 211 lua_pushlstring(state, str.c_str(), str.size());
209 212
210 return true; 213 return true;
211 } 214 }
215 #endif
212 216
213 217
218 #if ORTHANC_ENABLE_CURL == 1
214 void LuaContext::SetHttpHeaders(int top) 219 void LuaContext::SetHttpHeaders(int top)
215 { 220 {
216 std::map<std::string, std::string> headers; 221 std::map<std::string, std::string> headers;
217 GetDictionaryArgument(headers, lua_, top, false /* keep key case as provided by Lua script */); 222 GetDictionaryArgument(headers, lua_, top, false /* keep key case as provided by Lua script */);
218 223
221 for (std::map<std::string, std::string>::const_iterator 226 for (std::map<std::string, std::string>::const_iterator
222 it = headers.begin(); it != headers.end(); ++it) 227 it = headers.begin(); it != headers.end(); ++it)
223 { 228 {
224 httpClient_.AddHeader(it->first, it->second); 229 httpClient_.AddHeader(it->first, it->second);
225 } 230 }
226 } 231 }
227 232 #endif
228 233
234
235 #if ORTHANC_ENABLE_CURL == 1
229 int LuaContext::CallHttpGet(lua_State *state) 236 int LuaContext::CallHttpGet(lua_State *state)
230 { 237 {
231 LuaContext& that = GetLuaContext(state); 238 LuaContext& that = GetLuaContext(state);
232 239
233 // Check the types of the arguments 240 // Check the types of the arguments
254 lua_pushnil(state); 261 lua_pushnil(state);
255 } 262 }
256 263
257 return 1; 264 return 1;
258 } 265 }
259 266 #endif
260 267
268
269 #if ORTHANC_ENABLE_CURL == 1
261 int LuaContext::CallHttpPostOrPut(lua_State *state, 270 int LuaContext::CallHttpPostOrPut(lua_State *state,
262 HttpMethod method) 271 HttpMethod method)
263 { 272 {
264 LuaContext& that = GetLuaContext(state); 273 LuaContext& that = GetLuaContext(state);
265 274
306 lua_pushnil(state); 315 lua_pushnil(state);
307 } 316 }
308 317
309 return 1; 318 return 1;
310 } 319 }
311 320 #endif
312 321
322
323 #if ORTHANC_ENABLE_CURL == 1
313 int LuaContext::CallHttpPost(lua_State *state) 324 int LuaContext::CallHttpPost(lua_State *state)
314 { 325 {
315 return CallHttpPostOrPut(state, HttpMethod_Post); 326 return CallHttpPostOrPut(state, HttpMethod_Post);
316 } 327 }
317 328 #endif
318 329
330
331 #if ORTHANC_ENABLE_CURL == 1
319 int LuaContext::CallHttpPut(lua_State *state) 332 int LuaContext::CallHttpPut(lua_State *state)
320 { 333 {
321 return CallHttpPostOrPut(state, HttpMethod_Put); 334 return CallHttpPostOrPut(state, HttpMethod_Put);
322 } 335 }
323 336 #endif
324 337
338
339 #if ORTHANC_ENABLE_CURL == 1
325 int LuaContext::CallHttpDelete(lua_State *state) 340 int LuaContext::CallHttpDelete(lua_State *state)
326 { 341 {
327 LuaContext& that = GetLuaContext(state); 342 LuaContext& that = GetLuaContext(state);
328 343
329 // Check the types of the arguments 344 // Check the types of the arguments
354 lua_pushstring(state, "SUCCESS"); 369 lua_pushstring(state, "SUCCESS");
355 } 370 }
356 371
357 return 1; 372 return 1;
358 } 373 }
374 #endif
359 375
360 376
361 void LuaContext::PushJson(const Json::Value& value) 377 void LuaContext::PushJson(const Json::Value& value)
362 { 378 {
363 if (value.isString()) 379 if (value.isString())
552 568
553 luaL_openlibs(lua_); 569 luaL_openlibs(lua_);
554 lua_register(lua_, "print", PrintToLog); 570 lua_register(lua_, "print", PrintToLog);
555 lua_register(lua_, "ParseJson", ParseJson); 571 lua_register(lua_, "ParseJson", ParseJson);
556 lua_register(lua_, "DumpJson", DumpJson); 572 lua_register(lua_, "DumpJson", DumpJson);
573
574 #if ORTHANC_ENABLE_CURL == 1
557 lua_register(lua_, "HttpGet", CallHttpGet); 575 lua_register(lua_, "HttpGet", CallHttpGet);
558 lua_register(lua_, "HttpPost", CallHttpPost); 576 lua_register(lua_, "HttpPost", CallHttpPost);
559 lua_register(lua_, "HttpPut", CallHttpPut); 577 lua_register(lua_, "HttpPut", CallHttpPut);
560 lua_register(lua_, "HttpDelete", CallHttpDelete); 578 lua_register(lua_, "HttpDelete", CallHttpDelete);
561 lua_register(lua_, "SetHttpCredentials", SetHttpCredentials); 579 lua_register(lua_, "SetHttpCredentials", SetHttpCredentials);
580 #endif
562 581
563 SetGlobalVariable("_LuaContext", this); 582 SetGlobalVariable("_LuaContext", this);
564 } 583 }
565 584
566 585