MCPcopy Create free account
hub / github.com/BernardoGiordano/Checkpoint / webResult

Function webResult

common/script/checkpoint_api.cpp:396–426  ·  view source on GitHub ↗

Every web_* binding is argument marshalling over Http::perform (httpcall.hpp), which owns the option set, the abort polling, the upload progress bar and the allocation-safe write callback. This turns one response into the script's (return code, out buffer, out size) triple.

Source from the content-addressed store, hash-verified

394 // progress bar and the allocation-safe write callback. This turns one
395 // response into the script's (return code, out buffer, out size) triple.
396 int webResult(const char* what, const char* url, const Http::Response& res, char** out, int* outSize, char** respHeaders)
397 {
398 switch (res.result) {
399 case Http::Result::Ok:
400 break;
401 case Http::Result::TransferFailed:
402 Logging::warning("[script] {} '{}' failed: {}", what, url, Http::strerror(res.code));
403 return -((int)res.code + 100);
404 case Http::Result::OutOfMemory:
405 Logging::warning("[script] {} '{}' ran out of memory for the response", what, url);
406 return -2;
407 default:
408 return -1;
409 }
410
411 // Run-scoped copy (scriptheap.hpp), NUL-terminated past the length the
412 // script gets: an abort mid-script no longer strands the whole body.
413 // A failed copy is the same "it did not fit" the script must retry
414 // smaller, so it reports as -2 rather than as "no network stack".
415 char* buf = (char*)strToRet(res.body);
416 if (!buf) {
417 Logging::warning("[script] {} '{}': no room for a {}-byte response body", what, url, res.body.size());
418 return -2;
419 }
420 *out = buf;
421 *outSize = (int)res.body.size();
422 if (respHeaders) {
423 *respHeaders = (char*)strToRet(res.headers);
424 }
425 return (int)res.httpStatus;
426 }
427}
428
429void ckpt_net_ip(struct ParseState* Parser, struct Value* ReturnValue, struct Value** Param, int NumArgs)

Callers 3

ckpt_web_getFunction · 0.85
ckpt_web_requestFunction · 0.85
ckpt_web_upload_fileFunction · 0.85

Calls 4

warningFunction · 0.85
strerrorFunction · 0.85
strToRetFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected