From f48a7380cd3a69be9e53ed7b789643af04bcfa7d Mon Sep 17 00:00:00 2001 From: "psyc://psyced.org/~lynX" <@> Date: Tue, 23 Feb 2010 16:15:44 +0100 Subject: [PATCH] reset in fetch could break some apps.. other minor reorg --- config/versioncontrol.tcsh | 2 +- world/drivers/ldmud/library/library.c | 1 - world/net/http/fetch.c | 38 +++++++++++++-------------- world/net/http/library.i | 15 +++++------ world/net/http/oauth.c | 4 +-- world/net/http/server.c | 4 +-- world/net/library/hmac.c | 18 +++++++++---- 7 files changed, 42 insertions(+), 40 deletions(-) diff --git a/config/versioncontrol.tcsh b/config/versioncontrol.tcsh index a104b00..50df34f 100644 --- a/config/versioncontrol.tcsh +++ b/config/versioncontrol.tcsh @@ -61,5 +61,5 @@ alias cvsdeath 'find . -name CVS -print -prune -exec rm -r {} \;' # then "git fetch " and view with "gdifR " alias gdifR 'git diff master..\!:1/master |& difvu -' # to merge all the changes, use "gmergR " -alias gmergR 'git git merge -s resolve \!:1/master' +alias gmergR 'git merge -s resolve \!:1/master' diff --git a/world/drivers/ldmud/library/library.c b/world/drivers/ldmud/library/library.c index 8f08186..94f6fde 100644 --- a/world/drivers/ldmud/library/library.c +++ b/world/drivers/ldmud/library/library.c @@ -18,7 +18,6 @@ inherit PRO_PATH "http/library2"; # ifdef SANDBOX inherit NET_PATH "library/sandbox"; # endif -inherit NET_PATH "library/base64"; inherit NET_PATH "library/hmac"; inherit NET_PATH "library/dns"; inherit NET_PATH "library/htbasics"; diff --git a/world/net/http/fetch.c b/world/net/http/fetch.c index e24be74..9cce539 100644 --- a/world/net/http/fetch.c +++ b/world/net/http/fetch.c @@ -25,8 +25,11 @@ inherit NET_PATH "queue2"; inherit NET_PATH "queue"; #endif +// additional headers. we keep them lower-case to ensure we have no +// double items in there. HTTP ignores case by spec. +volatile mapping rheaders = ([ "user-agent": SERVER_VERSION ]); + volatile mapping headers, fheaders; -volatile mapping rheaders = (["User-Agent": SERVER_VERSION]); volatile string http_message; volatile int http_status, port, fetching, ssl; volatile string buffer, thehost, url, fetched, host, resource, method; @@ -57,10 +60,10 @@ varargs void fetch(string murl, string meth, mapping hdrs) { object load() { return ME; } void sAuth(string user, string password) { - rheaders["Authorization"] = "Basic " + encode_base64(user +":"+ password); + rheaders["authorization"] = "basic "+ encode_base64(user +":"+ password); } -string sAgent(string a) { return rheaders["User-Agent"] = a; } +string sAgent(string a) { return rheaders["user-agent"] = a; } // net/place/news code follows. @@ -74,13 +77,15 @@ void connect() { P0(("%O couldn't parse %O\n", ME, url)) return 0; } - thehost = lower_case(thehost); + //thehost = lower_case(thehost); // why? who needs that? ssl = t == "s"; } P4(("URL, THEHOST: %O, %O\n", url, thehost)) - unless (port) - unless (sscanf(thehost, "%s:%d", thehost, port) == 2) - port = ssl? HTTPS_SERVICE: HTTP_SERVICE; + unless (port) { + unless (sscanf(thehost, "%s:%d", thehost, port) == 2) + port = ssl? HTTPS_SERVICE: HTTP_SERVICE; + rheaders["host"] = thehost; + } P2(("Resolving %O and connecting.\n", thehost)) ::connect(thehost, port); } @@ -105,9 +110,7 @@ varargs int real_logon(int failure) { P2(("%O fetching /%s from %O\n", ME, resource, host)) P4(("%O using %O\n", ME, buffer)) emit(method + " /"+ resource +" HTTP/1.0\r\n" - "Host: "+ host +"\r\n" - + buffer + - "\r\n"); + + buffer +"\r\n"); buffer = ""; next_input_to(#'parse_status); @@ -177,9 +180,9 @@ disconnected(remainder) { P2(("%O got disconnected.. %O\n", ME, remainder)) headers["_fetchtime"] = isotime(ctime(time()), 1); if (headers["last-modified"]) - rheaders["If-Modified-Since"] = headers["last-modified"]; + rheaders["if-modified-since"] = headers["last-modified"]; //if (headers["etag"]) - // rheaders["If-None-Match"] = headers["etag"]; // heise does not work with etag + // rheaders["if-none-match"] = headers["etag"]; // heise does not work with etag fetched = buffer; if (remainder) fetched += remainder; @@ -228,11 +231,11 @@ string qHeader(mixed key) { } string qReqHeader(string key) { - return rheaders[key]; + return rheaders[lower_case(key)]; } void sReqHeader(string key, string value) { - rheaders[key] = value; + rheaders[lower_case(key)] = value; } varargs void refetch(closure cb, int willbehave) { @@ -240,12 +243,7 @@ varargs void refetch(closure cb, int willbehave) { unless (fetching) connect(); } -void reset() { - fetched = 0; +protected create() { qCreate(); qInit(ME, 150, 5); } - -protected create() { - reset(); -} diff --git a/world/net/http/library.i b/world/net/http/library.i index 24344cf..4ee7b28 100644 --- a/world/net/http/library.i +++ b/world/net/http/library.i @@ -134,18 +134,15 @@ string urldecode(string txt) { return txt; } -static string xx2c(string xx) { - string c = " "; - c[0] = hex2int(xx); - return c; -} - +#if 0 // inline this instead, see below static string c2xx(string c) { - return "%" + upper_case(sprintf("%x", c[0])); + return "%"+ upper_case(sprintf("%x", c[0])); } +#endif string urlencode(string txt) { - return regreplace(txt, "[^A-Za-z0-9._~-]", #'c2xx, 1); + return regreplace(txt, "[^A-Za-z0-9._~-]", (: + "%"+ upper_case(sprintf("%x", $1[0])) :), 1); } #ifndef DEFAULT_HT_TYPE @@ -192,7 +189,7 @@ default: return 0; } -parse_query(query, qs) { +mapping url_parse_query(mapping query, string qs) { foreach (string pair : explode(qs, "&")) { string key, val; diff --git a/world/net/http/oauth.c b/world/net/http/oauth.c index b5992c3..66c59a6 100644 --- a/world/net/http/oauth.c +++ b/world/net/http/oauth.c @@ -52,7 +52,7 @@ varargs void fetch(object ua, string url, string method, mapping oauth) { void parse_request_token(string body, mapping headers) { P3((">> oauth:parse_request_token(%O, %O)\n", body, headers)) mapping params = ([]); - parse_query(params, body); + url_parse_query(params, body); request_token = params["oauth_token"]; request_secret = params["oauth_token_secret"]; if (strlen(request_token) && strlen(request_secret)) { @@ -67,7 +67,7 @@ void parse_request_token(string body, mapping headers) { void parse_access_token(string body, mapping headers) { P3((">> oauth:parse_access_token(%O, %O)\n", body, headers)) mapping params = ([]); - parse_query(params, body); + url_parse_query(params, body); access_token = params["oauth_token"]; access_secret = params["oauth_token_secret"]; if (strlen(access_token) && strlen(access_secret)) { diff --git a/world/net/http/server.c b/world/net/http/server.c index 06d55dd..f20f40d 100644 --- a/world/net/http/server.c +++ b/world/net/http/server.c @@ -112,7 +112,7 @@ process() { P4(("found cookie: %O\n", t)) if (t && sscanf(t, "psyced=\"%s\"", t)) { P3(("got cookie: %O\n", t)) - query = parse_query(query, t); + query = url_parse_query(query, t); P4(("parsed cookie: %O\n", query)) } #ifdef GENERIC_COOKIES // we might need them someday..? @@ -135,7 +135,7 @@ process() { #endif if (sscanf(url, "%s?%s", file, qs)) { P3(("got query: %O\n", qs)) - query = parse_query(query, qs); + query = url_parse_query(query, qs); } else { file = url; } diff --git a/world/net/library/hmac.c b/world/net/library/hmac.c index b319439..881756b 100644 --- a/world/net/library/hmac.c +++ b/world/net/library/hmac.c @@ -1,11 +1,19 @@ -#include +#include "base64.c" -inherit NET_PATH "library/base64"; - -#include HTTP_PATH "library.i" +#if 0 // inline this (see below) +static string xx2c(string xx) { + string c = " "; + c[0] = hex2int(xx); + return c; +} +#endif string hmac_bin(int method, string key, string arg) { - return regreplace(hmac(method, key, arg), "..", #'xx2c, 1); //' + string c = " "; + return regreplace(hmac(method, key, arg), "..", (: + c[0] = hex2int($1); + return c; + :), 1); } string hmac_base64(int method, string key, string arg) {