From: Rudolf Polzer Date: Thu, 6 Oct 2011 14:27:55 +0000 (+0200) Subject: give urllib the failover functionality instead X-Git-Tag: xonotic-v0.6.0~40^2~88 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=3870d3c201dc9e1b27ecf4fd7fa3d8231f5dba44;p=xonotic%2Fxonotic-data.pk3dir.git give urllib the failover functionality instead --- diff --git a/qcsrc/common/urllib.qc b/qcsrc/common/urllib.qc index d23873e74..3d12c20e4 100644 --- a/qcsrc/common/urllib.qc +++ b/qcsrc/common/urllib.qc @@ -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); +} diff --git a/qcsrc/common/urllib.qh b/qcsrc/common/urllib.qh index a7735ed4f..e4aa49ee2 100644 --- a/qcsrc/common/urllib.qh +++ b/qcsrc/common/urllib.qh @@ -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);