]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
give urllib the failover functionality instead
authorRudolf Polzer <divVerent@xonotic.org>
Thu, 6 Oct 2011 14:27:55 +0000 (16:27 +0200)
committerRudolf Polzer <divVerent@xonotic.org>
Thu, 6 Oct 2011 14:27:55 +0000 (16:27 +0200)
qcsrc/common/urllib.qc
qcsrc/common/urllib.qh

index d23873e74c81eea11a1f877c43a9ce44252a1380..3d12c20e470a93436bb489c5f97072fe92c47fdf 100644 (file)
@@ -326,3 +326,45 @@ void url_fputs(entity e, string s)
                fputs(e.url_fh, s);
        }
 }
+
+// multi URL object, tries URLs separated by space in sequence
+void url_multi_ready(entity fh, entity me, float status)
+{
+       float n;
+       if(status == URL_READY_ERROR)
+       {
+               me.cnt += 1;
+               n = tokenize_console(me.url_url);
+               if(n <= me.cnt)
+               {
+                       me.url_ready(fh, me.url_ready_pass, status);
+                       strunzone(me.url_url);
+                       remove(me);
+                       return;
+               }
+               url_fopen(argv(me.cnt), me.lip, url_multi_ready, me);
+               return;
+       }
+       me.url_ready(fh, me.url_ready_pass, status);
+}
+void url_multi_fopen(string url, float mode, url_ready_func rdy, entity pass)
+{
+       float n;
+       n = tokenize_console(url);
+       if(n <= 0)
+       {
+               print("url_multi_fopen: need at least one URL\n");
+               rdy(world, pass, URL_READY_ERROR);
+               return;
+       }
+
+       entity me;
+       me = spawn();
+       me.classname = "url_multi";
+       me.url_url = strzone(url);
+       me.cnt = 0;
+       me.lip = mode;
+       me.url_ready = rdy;
+       me.url_ready_pass = pass;
+       url_fopen(argv(0), mode, url_multi_ready, me);
+}
index a7735ed4f3f9ee1b05d279366125e7dfe0dd4a05..e4aa49ee23a33610bfab30f9d72358d10a4c0701 100644 (file)
@@ -14,3 +14,5 @@ void url_fputs(entity e, string s);
 float url_URI_Get_Callback(float id, float status, string data);
 #define MIN_URL_ID 128
 #define NUM_URL_ID 64
+
+void url_multi_fopen(string url, float mode, url_ready_func rdy, entity pass);