X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Flib%2Furllib.qc;h=fd8b16d881d7177db5a8f623cb2051f9260ca8ea;hb=44cad443f15ba5e3c256a4964a117a9fa43985b9;hp=c60201b58355199e4393a97cc00a68fe9529ad3f;hpb=d3e642e032c1e9e62fc5400c14627c54e37e4ae0;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/lib/urllib.qc b/qcsrc/lib/urllib.qc index c60201b58..fd8b16d88 100644 --- a/qcsrc/lib/urllib.qc +++ b/qcsrc/lib/urllib.qc @@ -7,6 +7,8 @@ const float URL_FH_STDOUT = -2; // URLs .string url_url; +.string url_content_type; +.string url_verb; .float url_wbuf; .float url_wbufpos; .float url_rbuf; @@ -22,6 +24,7 @@ const float URL_FH_STDOUT = -2; entity url_fromid[NUM_URL_ID]; int autocvar__urllib_nextslot; +ERASEABLE float url_URI_Get_Callback(int id, float status, string data) { if (id < MIN_URL_ID) return 0; @@ -53,7 +56,7 @@ float url_URI_Get_Callback(int id, float status, string data) LOG_INFO("url_URI_Get_Callback: out of memory in buf_create\n"); e.url_ready(e, e.url_ready_pass, URL_READY_ERROR); strunzone(e.url_url); - remove(e); + delete(e); return 1; } e.url_rbufpos = 0; @@ -62,7 +65,7 @@ float url_URI_Get_Callback(int id, float status, string data) LOG_INFO("url_URI_Get_Callback: out of memory in buf_create\n"); e.url_ready(e, e.url_ready_pass, URL_READY_ERROR); strunzone(e.url_url); - remove(e); + delete(e); return 1; } for (i = 0; i < n; ++i) @@ -75,11 +78,12 @@ float url_URI_Get_Callback(int id, float status, string data) // an ERROR e.url_ready(e, e.url_ready_pass, -fabs(status)); strunzone(e.url_url); - remove(e); + delete(e); return 1; } } +ERASEABLE void url_single_fopen(string url, int mode, url_ready_func rdy, entity pass) { entity e; @@ -94,9 +98,10 @@ void url_single_fopen(string url, int mode, url_ready_func rdy, entity pass) // attempts to close will result in a reading handle // create a writing end that does nothing yet - e = spawn(); - e.classname = "url_single_fopen_file"; + e = new_pure(url_single_fopen_file); e.url_url = strzone(url); + e.url_content_type = "text/plain"; + e.url_verb = ""; e.url_fh = URL_FH_CURL; e.url_wbuf = buf_create(); if (e.url_wbuf < 0) @@ -104,7 +109,7 @@ void url_single_fopen(string url, int mode, url_ready_func rdy, entity pass) LOG_INFO("url_single_fopen: out of memory in buf_create\n"); rdy(e, pass, URL_READY_ERROR); strunzone(e.url_url); - remove(e); + delete(e); return; } e.url_wbufpos = 0; @@ -143,8 +148,7 @@ void url_single_fopen(string url, int mode, url_ready_func rdy, entity pass) // Make a dummy handle object (no buffers at // all). Wait for data to come from the // server, then call the callback - e = spawn(); - e.classname = "url_single_fopen_file"; + e = new_pure(url_single_fopen_file); e.url_url = strzone(url); e.url_fh = URL_FH_CURL; e.url_rbuf = -1; @@ -165,8 +169,7 @@ void url_single_fopen(string url, int mode, url_ready_func rdy, entity pass) { case FILE_WRITE: case FILE_APPEND: - e = spawn(); - e.classname = "url_single_fopen_stdout"; + e = new_pure(url_single_fopen_stdout); e.url_fh = URL_FH_STDOUT; e.url_ready = rdy; e.url_ready_pass = pass; @@ -189,8 +192,7 @@ void url_single_fopen(string url, int mode, url_ready_func rdy, entity pass) } else { - e = spawn(); - e.classname = "url_single_fopen_file"; + e = new_pure(url_single_fopen_file); e.url_fh = fh; e.url_ready = rdy; e.url_ready_pass = pass; @@ -201,6 +203,7 @@ void url_single_fopen(string url, int mode, url_ready_func rdy, entity pass) } // close a file +ERASEABLE void url_fclose(entity e) { int i; @@ -229,19 +232,19 @@ void url_fclose(entity e) e.url_ready(e, e.url_ready_pass, URL_READY_ERROR); buf_del(e.url_wbuf); strunzone(e.url_url); - remove(e); + delete(e); return; } } // POST the data - if (!crypto_uri_postbuf(e.url_url, i + MIN_URL_ID, "text/plain", "", e.url_wbuf, 0)) + if (!crypto_uri_postbuf(e.url_url, i + MIN_URL_ID, e.url_content_type, e.url_verb, e.url_wbuf, 0)) { LOG_INFO("url_fclose: failure in crypto_uri_postbuf\n"); e.url_ready(e, e.url_ready_pass, URL_READY_ERROR); buf_del(e.url_wbuf); strunzone(e.url_url); - remove(e); + delete(e); return; } @@ -262,24 +265,25 @@ void url_fclose(entity e) e.url_ready(e, e.url_ready_pass, URL_READY_CLOSED); buf_del(e.url_rbuf); strunzone(e.url_url); - remove(e); + delete(e); } } else if (e.url_fh == URL_FH_STDOUT) { e.url_ready(e, e.url_ready_pass, URL_READY_CLOSED); // closing creates no reading handle - remove(e); + delete(e); } else { // file fclose(e.url_fh); e.url_ready(e, e.url_ready_pass, URL_READY_CLOSED); // closing creates no reading handle - remove(e); + delete(e); } } // with \n (blame FRIK_FILE) +ERASEABLE string url_fgets(entity e) { if (e.url_fh == URL_FH_CURL) @@ -304,6 +308,7 @@ string url_fgets(entity e) } // without \n (blame FRIK_FILE) +ERASEABLE void url_fputs(entity e, string s) { if (e.url_fh == URL_FH_CURL) @@ -316,7 +321,7 @@ void url_fputs(entity e, string s) else if (e.url_fh == URL_FH_STDOUT) { // stdout - LOG_INFO(s); + print(s); } else { @@ -326,6 +331,7 @@ void url_fputs(entity e, string s) } // multi URL object, tries URLs separated by space in sequence +ERASEABLE void url_multi_ready(entity fh, entity me, float status) { float n; @@ -336,7 +342,7 @@ void url_multi_ready(entity fh, entity me, float status) LOG_INFO("uri_multi_ready: got HTTP error 422, data is in unusable format - not continuing\n"); me.url_ready(fh, me.url_ready_pass, status); strunzone(me.url_url); - remove(me); + delete(me); return; } me.url_attempt += 1; @@ -345,7 +351,7 @@ void url_multi_ready(entity fh, entity me, float status) { me.url_ready(fh, me.url_ready_pass, status); strunzone(me.url_url); - remove(me); + delete(me); return; } url_single_fopen(argv(me.url_attempt), me.url_mode, url_multi_ready, me); @@ -353,6 +359,8 @@ void url_multi_ready(entity fh, entity me, float status) } me.url_ready(fh, me.url_ready_pass, status); } + +ERASEABLE void url_multi_fopen(string url, int mode, url_ready_func rdy, entity pass) { float n; @@ -364,9 +372,7 @@ void url_multi_fopen(string url, int mode, url_ready_func rdy, entity pass) return; } - entity me; - me = spawn(); - me.classname = "url_multi"; + entity me = new_pure(url_multi); me.url_url = strzone(url); me.url_attempt = 0; me.url_mode = mode;