]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
make urllib state machine more strict, error() immediately when a problem is detected
authorRudolf Polzer <divVerent@xonotic.org>
Mon, 22 Aug 2011 04:48:55 +0000 (06:48 +0200)
committerRudolf Polzer <divVerent@xonotic.org>
Mon, 22 Aug 2011 04:48:55 +0000 (06:48 +0200)
qcsrc/common/urllib.qc

index ef27faec3240c92086e71ea414b88d933c98b00f..0ab17f34a4eebed25e7dee028c104c7d5fb25602 100644 (file)
@@ -34,6 +34,10 @@ float url_URI_Get_Callback(float id, float status, string data)
        // whatever happens, we will remove the URL from the list of IDs
        url_fromid[id] = world;
 
+       // if we get here, we MUST have both buffers cleared
+       if(e.url_rbuf != -1 || e.url_wbuf != -1 || e.url_fh != -1)
+               error("url_URI_Get_Callback: not a request waiting for data");
+
        if(status == 0)
        {
                // WE GOT DATA!
@@ -180,6 +184,10 @@ void url_fclose(entity e, url_ready_func rdy, entity pass)
 
        if(e.url_fh < 0)
        {
+               if(e.url_rbuf == -1 || e.url_wbuf != -1) // not(post GET/POST request)
+               if(e.url_rbuf != -1 || e.url_wbuf == -1) // not(pre POST request)
+                       error("url_fclose: not closable in current state");
+
                // closing an URL!
                if(e.url_wbuf >= 0)
                {
@@ -252,6 +260,8 @@ string url_fgets(entity e)
 {
        if(e.url_fh < 0)
        {
+               if(e.url_rbuf == -1)
+                       error("url_fgets: not readable in current state");
                // curl
                string s;
                s = bufstr_get(e.url_rbuf, e.url_rbufpos);
@@ -270,6 +280,8 @@ void url_fputs(entity e, string s)
 {
        if(e.url_fh < 0)
        {
+               if(e.url_wbuf == -1)
+                       error("url_fputs: not writable in current state");
                // curl
                bufstr_set(e.url_wbuf, e.url_wbufpos, s);
                e.url_wbufpos += 1;