From: Rudolf Polzer Date: Mon, 22 Aug 2011 04:48:55 +0000 (+0200) Subject: make urllib state machine more strict, error() immediately when a problem is detected X-Git-Tag: xonotic-v0.5.0~92 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=6281438445d0d4956c0584c902d0cb6a7851a5c7;p=xonotic%2Fxonotic-data.pk3dir.git make urllib state machine more strict, error() immediately when a problem is detected --- diff --git a/qcsrc/common/urllib.qc b/qcsrc/common/urllib.qc index ef27faec3..0ab17f34a 100644 --- a/qcsrc/common/urllib.qc +++ b/qcsrc/common/urllib.qc @@ -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;