]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/lib/urllib.qc
Merge branch 'master' into Mario/overkill
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / urllib.qc
index 0a48ef6cd3b84b656d2cebd5d685b64d67f54d66..d1d5c65ed2a3d4bcf34e1a35789a709e44521c07 100644 (file)
@@ -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;
@@ -53,7 +55,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 +64,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,7 +77,7 @@ 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;
        }
 }
@@ -94,9 +96,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 = new(url_single_fopen_file);
-                               make_pure(e);
+                               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 +107,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 +146,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 = new(url_single_fopen_file);
-                               make_pure(e);
+                               e = new_pure(url_single_fopen_file);
                                e.url_url = strzone(url);
                                e.url_fh = URL_FH_CURL;
                                e.url_rbuf = -1;
@@ -165,8 +167,7 @@ void url_single_fopen(string url, int mode, url_ready_func rdy, entity pass)
                {
                        case FILE_WRITE:
                        case FILE_APPEND:
-                               e = new(url_single_fopen_stdout);
-                               make_pure(e);
+                               e = new_pure(url_single_fopen_stdout);
                                e.url_fh = URL_FH_STDOUT;
                                e.url_ready = rdy;
                                e.url_ready_pass = pass;
@@ -189,8 +190,7 @@ void url_single_fopen(string url, int mode, url_ready_func rdy, entity pass)
                }
                else
                {
-                       e = new(url_single_fopen_file);
-                       make_pure(e);
+                       e = new_pure(url_single_fopen_file);
                        e.url_fh = fh;
                        e.url_ready = rdy;
                        e.url_ready_pass = pass;
@@ -229,19 +229,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,20 +262,20 @@ 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);
        }
 }
 
@@ -316,7 +316,7 @@ void url_fputs(entity e, string s)
        else if (e.url_fh == URL_FH_STDOUT)
        {
                // stdout
-               LOG_INFO(s);
+               print(s);
        }
        else
        {
@@ -336,7 +336,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 +345,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);
@@ -364,8 +364,7 @@ void url_multi_fopen(string url, int mode, url_ready_func rdy, entity pass)
                return;
        }
 
-       entity me = new(url_multi);
-       make_pure(me);
+       entity me = new_pure(url_multi);
        me.url_url = strzone(url);
        me.url_attempt = 0;
        me.url_mode = mode;