Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
urllib.qh File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define MIN_URL_ID   URI_GET_URLLIB
#define NUM_URL_ID   (URI_GET_URLLIB_END - URI_GET_URLLIB + 1)

Typedefs

using url_ready_func = void (entity handle, entity pass, float status)

Functions

ERASEABLE void url_fclose (entity e)
ERASEABLE string url_fgets (entity e)
ERASEABLE void url_fputs (entity e, string s)
ERASEABLE void url_multi_fopen (string url, float mode, url_ready_func rdy, entity pass)
ERASEABLE void url_single_fopen (string url, float mode, url_ready_func rdy, entity pass)
ERASEABLE float url_URI_Get_Callback (int id, float status, string data)

Variables

const int URI_GET_CURL = 17
const int URI_GET_CURL_END = 32
const int URI_GET_DISCARD = 0
const int URI_GET_IPBAN = 1
const int URI_GET_IPBAN_END = 16
const int URI_GET_TOS = 34
const int URI_GET_UPDATENOTIFICATION = 33
const int URI_GET_URLLIB = 128
const int URI_GET_URLLIB_END = 191
const float URL_READY_CANREAD = 2
const float URL_READY_CANWRITE = 1
const float URL_READY_CLOSED = 0
const float URL_READY_ERROR = -1

Macro Definition Documentation

◆ MIN_URL_ID

#define MIN_URL_ID   URI_GET_URLLIB

Definition at line 33 of file urllib.qh.

Referenced by url_fclose(), url_single_fopen(), and url_URI_Get_Callback().

◆ NUM_URL_ID

#define NUM_URL_ID   (URI_GET_URLLIB_END - URI_GET_URLLIB + 1)

Definition at line 34 of file urllib.qh.

Referenced by url_fclose(), url_single_fopen(), and url_URI_Get_Callback().

Typedef Documentation

◆ url_ready_func

using url_ready_func = void (entity handle, entity pass, float status)

Definition at line 19 of file urllib.qh.

Function Documentation

◆ url_fclose()

ERASEABLE void url_fclose ( entity e)

Definition at line 207 of file urllib.qc.

208{
209 int i;
210
211 if (e.url_fh == URL_FH_CURL)
212 {
213 if (e.url_rbuf == -1 || e.url_wbuf != -1) // not(post GET/POST request)
214 if (e.url_rbuf != -1 || e.url_wbuf == -1) // not(pre POST request)
215 error("url_fclose: not closable in current state");
216
217 // closing an URL!
218 if (e.url_wbuf >= 0)
219 {
220 // we are closing the write end (HTTP POST request)
221
222 // get slot for HTTP request
223 for (i = autocvar__urllib_nextslot; i < NUM_URL_ID; ++i)
224 if (url_fromid[i] == NULL) break;
225 if (i >= NUM_URL_ID)
226 {
227 for (i = 0; i < autocvar__urllib_nextslot; ++i)
228 if (url_fromid[i] == NULL) break;
230 {
231 LOG_INFO("url_fclose: too many concurrent requests");
232 e.url_ready(e, e.url_ready_pass, URL_READY_ERROR);
233 buf_del(e.url_wbuf);
234 strfree(e.url_url);
235 delete(e);
236 return;
237 }
238 }
239
240 // POST the data
241 if (!crypto_uri_postbuf(e.url_url, i + MIN_URL_ID, e.url_content_type, e.url_verb, e.url_wbuf, 0))
242 {
243 LOG_INFO("url_fclose: failure in crypto_uri_postbuf");
244 e.url_ready(e, e.url_ready_pass, URL_READY_ERROR);
245 buf_del(e.url_wbuf);
246 strfree(e.url_url);
247 delete(e);
248 return;
249 }
250
251 // delete write end. File handle is now in unusable
252 // state. Wait for data to come from the server, then
253 // call the callback
254 buf_del(e.url_wbuf);
255 e.url_wbuf = -1;
256 e.url_id = i;
257 url_fromid[i] = e;
258
259 // make sure this slot won't be reused quickly even on map change
260 cvar_set("_urllib_nextslot", ftos((i + 1) % NUM_URL_ID));
261 }
262 else
263 {
264 // we have READ all data, just close
265 e.url_ready(e, e.url_ready_pass, URL_READY_CLOSED);
266 buf_del(e.url_rbuf);
267 strfree(e.url_url);
268 delete(e);
269 }
270 }
271 else if (e.url_fh == URL_FH_STDOUT)
272 {
273 e.url_ready(e, e.url_ready_pass, URL_READY_CLOSED); // closing creates no reading handle
274 delete(e);
275 }
276 else
277 {
278 // file
279 fclose(e.url_fh);
280 e.url_ready(e, e.url_ready_pass, URL_READY_CLOSED); // closing creates no reading handle
281 delete(e);
282 }
283}
#define LOG_INFO(...)
Definition log.qh:65
void cvar_set(string name, string value)
void fclose(float fhandle)
string ftos(float f)
#define NULL
Definition post.qh:14
#define error
Definition pre.qh:6
#define strfree(this)
Definition string.qh:59
int autocvar__urllib_nextslot
Definition urllib.qc:25
const float URL_FH_CURL
Definition urllib.qc:5
entity url_fromid[NUM_URL_ID]
Definition urllib.qc:24
const float URL_FH_STDOUT
Definition urllib.qc:6
const float URL_READY_CLOSED
Definition urllib.qh:15
const float URL_READY_ERROR
Definition urllib.qh:14
#define MIN_URL_ID
Definition urllib.qh:33
#define NUM_URL_ID
Definition urllib.qh:34

References autocvar__urllib_nextslot, cvar_set(), entity(), error, fclose(), ftos(), LOG_INFO, MIN_URL_ID, NULL, NUM_URL_ID, strfree, URL_FH_CURL, URL_FH_STDOUT, url_fromid, URL_READY_CLOSED, and URL_READY_ERROR.

Referenced by AdditionalServerInfo_OnGet(), MX_JLF_(), MX_Messages_(), MX_Nick_(), MX_Say_(), MX_Sync_(), MX_Typing_(), PlayerStats_GameReport_Handler(), PlayerStats_PlayerBasic_Handler(), PlayerStats_PlayerDetail_Handler(), WeaponStats_ready(), and XonoticToS_OnGet().

◆ url_fgets()

ERASEABLE string url_fgets ( entity e)

Definition at line 287 of file urllib.qc.

288{
289 if (e.url_fh == URL_FH_CURL)
290 {
291 if (e.url_rbuf == -1) error("url_fgets: not readable in current state");
292 // curl
293 string s;
294 s = bufstr_get(e.url_rbuf, e.url_rbufpos);
295 e.url_rbufpos += 1;
296 return s;
297 }
298 else if (e.url_fh == URL_FH_STDOUT)
299 {
300 // stdout
301 return string_null;
302 }
303 else
304 {
305 // file
306 return fgets(e.url_fh);
307 }
308}
string fgets(float fhandle)
string string_null
Definition nil.qh:9

References entity(), error, fgets(), string_null, URL_FH_CURL, and URL_FH_STDOUT.

Referenced by AdditionalServerInfo_OnGet(), MX_Messages_(), MX_Sync_(), PlayerStats_GameReport_Handler(), PlayerStats_PlayerBasic_Handler(), PlayerStats_PlayerDetail_Handler(), WeaponStats_ready(), and XonoticToS_OnGet().

◆ url_fputs()

ERASEABLE void url_fputs ( entity e,
string s )

Definition at line 312 of file urllib.qc.

313{
314 if (e.url_fh == URL_FH_CURL)
315 {
316 if (e.url_wbuf == -1) error("url_fputs: not writable in current state");
317 // curl
318 bufstr_set(e.url_wbuf, e.url_wbufpos, s);
319 e.url_wbufpos += 1;
320 }
321 else if (e.url_fh == URL_FH_STDOUT)
322 {
323 // stdout
324 print(s);
325 }
326 else
327 {
328 // file
329 fputs(e.url_fh, s);
330 }
331}
void fputs(float fhandle, string s)
void print(string text,...)

References entity(), error, fputs(), print(), URL_FH_CURL, and URL_FH_STDOUT.

Referenced by MX_JLF_(), MX_Nick_(), MX_Say_(), MX_Typing_(), PlayerStats_GameReport_Handler(), PlayerStats_PlayerBasic_Handler(), PlayerStats_PlayerDetail_Handler(), and WeaponStats_ready().

◆ url_multi_fopen()

ERASEABLE void url_multi_fopen ( string url,
float mode,
url_ready_func rdy,
entity pass )

References entity(), and pass.

◆ url_single_fopen()

ERASEABLE void url_single_fopen ( string url,
float mode,
url_ready_func rdy,
entity pass )

References entity(), ERASEABLE, and pass.

◆ url_URI_Get_Callback()

ERASEABLE float url_URI_Get_Callback ( int id,
float status,
string data )

Definition at line 28 of file urllib.qc.

29{
30 if (id < MIN_URL_ID) return 0;
31 id -= MIN_URL_ID;
32 if (id >= NUM_URL_ID) return 0;
33 entity e;
34 e = url_fromid[id];
35 if (!e) return 0;
36 if (e.url_rbuf >= 0 || e.url_wbuf >= 0)
37 {
38 LOG_INFOF("WARNING: handle %d (%s) has already received data?!?", id + NUM_URL_ID, e.url_url);
39 return 0;
40 }
41
42 // whatever happens, we will remove the URL from the list of IDs
43 url_fromid[id] = NULL;
44
45 // if we get here, we MUST have both buffers cleared
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");
47
48 if (status == 0)
49 {
50 // WE GOT DATA!
51 float n, i;
52 n = tokenizebyseparator(data, "\n");
53 e.url_rbuf = buf_create();
54 if (e.url_rbuf < 0)
55 {
56 LOG_INFO("url_URI_Get_Callback: out of memory in buf_create");
57 e.url_ready(e, e.url_ready_pass, URL_READY_ERROR);
58 strfree(e.url_url);
59 delete(e);
60 return 1;
61 }
62 e.url_rbufpos = 0;
63 if (e.url_rbuf < 0)
64 {
65 LOG_INFO("url_URI_Get_Callback: out of memory in buf_create");
66 e.url_ready(e, e.url_ready_pass, URL_READY_ERROR);
67 strfree(e.url_url);
68 delete(e);
69 return 1;
70 }
71 for (i = 0; i < n; ++i)
72 bufstr_set(e.url_rbuf, i, argv(i));
73 e.url_ready(e, e.url_ready_pass, URL_READY_CANREAD);
74 return 1;
75 }
76 else
77 {
78 // an ERROR
79 e.url_ready(e, e.url_ready_pass, -fabs(status));
80 strfree(e.url_url);
81 delete(e);
82 return 1;
83 }
84}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
#define tokenizebyseparator
#define buf_create
#define LOG_INFOF(...)
Definition log.qh:66
float fabs(float f)
string argv(float n)
const float URL_READY_CANREAD
Definition urllib.qh:17

References argv(), buf_create, entity(), error, fabs(), LOG_INFO, LOG_INFOF, MIN_URL_ID, NULL, NUM_URL_ID, strfree, tokenizebyseparator, URL_FH_CURL, url_fromid, URL_READY_CANREAD, and URL_READY_ERROR.

Referenced by URI_Get_Callback(), and URI_Get_Callback().

Variable Documentation

◆ URI_GET_CURL

const int URI_GET_CURL = 17

◆ URI_GET_CURL_END

const int URI_GET_CURL_END = 32

Definition at line 8 of file urllib.qh.

Referenced by GenericCommand_qc_curl(), URI_Get_Callback(), and URI_Get_Callback().

◆ URI_GET_DISCARD

const int URI_GET_DISCARD = 0

◆ URI_GET_IPBAN

const int URI_GET_IPBAN = 1

Definition at line 5 of file urllib.qh.

Referenced by OnlineBanList_Think(), OnlineBanList_URI_Get_Callback(), and URI_Get_Callback().

◆ URI_GET_IPBAN_END

const int URI_GET_IPBAN_END = 16

Definition at line 6 of file urllib.qh.

Referenced by URI_Get_Callback().

◆ URI_GET_TOS

const int URI_GET_TOS = 34

Definition at line 10 of file urllib.qh.

◆ URI_GET_UPDATENOTIFICATION

const int URI_GET_UPDATENOTIFICATION = 33

Definition at line 9 of file urllib.qh.

Referenced by updateCheck(), and URI_Get_Callback().

◆ URI_GET_URLLIB

const int URI_GET_URLLIB = 128

Definition at line 11 of file urllib.qh.

◆ URI_GET_URLLIB_END

const int URI_GET_URLLIB_END = 191

Definition at line 12 of file urllib.qh.

◆ URL_READY_CANREAD

◆ URL_READY_CANWRITE

◆ URL_READY_CLOSED

◆ URL_READY_ERROR