Mercurial > hg > orthanc
comparison Core/Lua/LuaContext.cpp @ 1438:af112b7d9cba
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 01 Jul 2015 09:56:41 +0200 |
parents | 02f5a3f5c0a0 |
children | 5ba7471780ae |
comparison
equal
deleted
inserted
replaced
1437:02f5a3f5c0a0 | 1438:af112b7d9cba |
---|---|
170 // Check the types of the arguments | 170 // Check the types of the arguments |
171 int nArgs = lua_gettop(state); | 171 int nArgs = lua_gettop(state); |
172 if (nArgs != 1 || !lua_isstring(state, 1)) // URL | 172 if (nArgs != 1 || !lua_isstring(state, 1)) // URL |
173 { | 173 { |
174 LOG(ERROR) << "Lua: Bad parameters to HttpGet()"; | 174 LOG(ERROR) << "Lua: Bad parameters to HttpGet()"; |
175 lua_pushstring(state, "ERROR"); | 175 lua_pushnil(state); |
176 return 1; | 176 return 1; |
177 } | 177 } |
178 | 178 |
179 // Configure the HTTP client class | 179 // Configure the HTTP client class |
180 const char* url = lua_tostring(state, 1); | 180 const char* url = lua_tostring(state, 1); |
183 | 183 |
184 // Do the HTTP GET request | 184 // Do the HTTP GET request |
185 if (!that.AnswerHttpQuery(state)) | 185 if (!that.AnswerHttpQuery(state)) |
186 { | 186 { |
187 LOG(ERROR) << "Lua: Error in HttpGet() for URL " << url; | 187 LOG(ERROR) << "Lua: Error in HttpGet() for URL " << url; |
188 lua_pushstring(state, "ERROR"); | 188 lua_pushnil(state); |
189 } | 189 } |
190 | 190 |
191 return 1; | 191 return 1; |
192 } | 192 } |
193 | 193 |
202 if ((nArgs != 1 && nArgs != 2) || | 202 if ((nArgs != 1 && nArgs != 2) || |
203 !lua_isstring(state, 1) || // URL | 203 !lua_isstring(state, 1) || // URL |
204 (nArgs >= 2 && !lua_isstring(state, 2))) // Body data | 204 (nArgs >= 2 && !lua_isstring(state, 2))) // Body data |
205 { | 205 { |
206 LOG(ERROR) << "Lua: Bad parameters to HttpPost() or HttpPut()"; | 206 LOG(ERROR) << "Lua: Bad parameters to HttpPost() or HttpPut()"; |
207 lua_pushstring(state, "ERROR"); | 207 lua_pushnil(state); |
208 return 1; | 208 return 1; |
209 } | 209 } |
210 | 210 |
211 // Configure the HTTP client class | 211 // Configure the HTTP client class |
212 const char* url = lua_tostring(state, 1); | 212 const char* url = lua_tostring(state, 1); |
224 | 224 |
225 // Do the HTTP POST/PUT request | 225 // Do the HTTP POST/PUT request |
226 if (!that.AnswerHttpQuery(state)) | 226 if (!that.AnswerHttpQuery(state)) |
227 { | 227 { |
228 LOG(ERROR) << "Lua: Error in HttpPost() or HttpPut() for URL " << url; | 228 LOG(ERROR) << "Lua: Error in HttpPost() or HttpPut() for URL " << url; |
229 lua_pushstring(state, "ERROR"); | 229 lua_pushnil(state); |
230 } | 230 } |
231 | 231 |
232 return 1; | 232 return 1; |
233 } | 233 } |
234 | 234 |
252 // Check the types of the arguments | 252 // Check the types of the arguments |
253 int nArgs = lua_gettop(state); | 253 int nArgs = lua_gettop(state); |
254 if (nArgs != 1 || !lua_isstring(state, 1)) // URL | 254 if (nArgs != 1 || !lua_isstring(state, 1)) // URL |
255 { | 255 { |
256 LOG(ERROR) << "Lua: Bad parameters to HttpDelete()"; | 256 LOG(ERROR) << "Lua: Bad parameters to HttpDelete()"; |
257 lua_pushstring(state, "ERROR"); | 257 lua_pushnil(state); |
258 return 1; | 258 return 1; |
259 } | 259 } |
260 | 260 |
261 // Configure the HTTP client class | 261 // Configure the HTTP client class |
262 const char* url = lua_tostring(state, 1); | 262 const char* url = lua_tostring(state, 1); |
266 // Do the HTTP DELETE request | 266 // Do the HTTP DELETE request |
267 std::string s; | 267 std::string s; |
268 if (!that.httpClient_.Apply(s)) | 268 if (!that.httpClient_.Apply(s)) |
269 { | 269 { |
270 LOG(ERROR) << "Lua: Error in HttpDelete() for URL " << url; | 270 LOG(ERROR) << "Lua: Error in HttpDelete() for URL " << url; |
271 lua_pushstring(state, "ERROR"); | 271 lua_pushnil(state); |
272 } | 272 } |
273 else | 273 else |
274 { | 274 { |
275 lua_pushstring(state, "SUCCESS"); | 275 lua_pushstring(state, "SUCCESS"); |
276 } | 276 } |