36 if (e.url_rbuf >= 0 || e.url_wbuf >= 0)
38 LOG_INFOF(
"WARNING: handle %d (%s) has already received data?!?",
id +
NUM_URL_ID, e.url_url);
46 if (e.url_rbuf != -1 || e.url_wbuf != -1 || e.url_fh !=
URL_FH_CURL)
error(
"url_URI_Get_Callback: not a request waiting for data");
56 LOG_INFO(
"url_URI_Get_Callback: out of memory in buf_create");
65 LOG_INFO(
"url_URI_Get_Callback: out of memory in buf_create");
71 for (i = 0; i < n; ++i)
72 bufstr_set(e.url_rbuf, i,
argv(i));
79 e.url_ready(e, e.url_ready_pass, -
fabs(status));
101 e =
new_pure(url_single_fopen_file);
103 e.url_content_type =
"text/plain";
109 LOG_INFO(
"url_single_fopen: out of memory in buf_create");
118 e.url_ready_pass =
pass;
132 if (i >= autocvar__urllib_nextslot)
134 LOG_INFO(
"url_single_fopen: too many concurrent requests");
143 LOG_INFO(
"url_single_fopen: failure in crypto_uri_postbuf");
151 e =
new_pure(url_single_fopen_file);
157 e.url_ready_pass =
pass;
162 cvar_set(
"_urllib_nextslot",
ftos((i + 1) % NUM_URL_ID));
172 e =
new_pure(url_single_fopen_stdout);
175 e.url_ready_pass =
pass;
179 LOG_INFO(
"url_single_fopen: cannot open '-' for reading");
187 fh =
fopen(url, mode);
195 e =
new_pure(url_single_fopen_file);
198 e.url_ready_pass =
pass;
213 if (e.url_rbuf == -1 || e.url_wbuf != -1)
214 if (e.url_rbuf != -1 || e.url_wbuf == -1)
215 error(
"url_fclose: not closable in current state");
229 if (i >= autocvar__urllib_nextslot)
231 LOG_INFO(
"url_fclose: too many concurrent requests");
241 if (!crypto_uri_postbuf(e.url_url, i +
MIN_URL_ID, e.url_content_type, e.url_verb, e.url_wbuf, 0))
243 LOG_INFO(
"url_fclose: failure in crypto_uri_postbuf");
260 cvar_set(
"_urllib_nextslot",
ftos((i + 1) % NUM_URL_ID));
291 if (e.url_rbuf == -1)
error(
"url_fgets: not readable in current state");
294 s = bufstr_get(e.url_rbuf, e.url_rbufpos);
306 return fgets(e.url_fh);
316 if (e.url_wbuf == -1)
error(
"url_fputs: not writable in current state");
318 bufstr_set(e.url_wbuf, e.url_wbufpos, s);
342 LOG_INFO(
"uri_multi_ready: got HTTP error 422, data is in unusable format - not continuing");
343 me.url_ready(fh, me.url_ready_pass, status);
350 if (n <= me.url_attempt)
352 me.url_ready(fh, me.url_ready_pass, status);
360 me.url_ready(fh, me.url_ready_pass, status);
370 LOG_INFO(
"url_multi_fopen: need at least one URL");
380 me.url_ready_pass =
pass;
const float URL_READY_CANREAD
const float URL_READY_CLOSED
const float URL_READY_CANWRITE
ERASEABLE float url_URI_Get_Callback(int id, float status, string data)
entity url_fromid[NUM_URL_ID]
ERASEABLE void url_multi_ready(entity fh, entity me, float status)
void(entity handle, entity pass, float status) url_ready_func
ERASEABLE void url_fputs(entity e, string s)
ERASEABLE void url_fclose(entity e)
int autocvar__urllib_nextslot
ERASEABLE void url_single_fopen(string url, int mode, url_ready_func rdy, entity pass)
#define tokenizebyseparator
#define new_pure(class)
purely logical entities (.origin doesn't work)
const float URL_READY_ERROR
const float URL_FH_STDOUT
ERASEABLE void url_multi_fopen(string url, int mode, url_ready_func rdy, entity pass)
#define pass(name, colormin, colormax)
ERASEABLE string url_fgets(entity e)