reset in fetch could break some apps.. other minor reorg

This commit is contained in:
psyc://psyced.org/~lynX 2010-02-23 16:15:44 +01:00
parent b48557c67a
commit f48a7380cd
7 changed files with 42 additions and 40 deletions

View File

@ -61,5 +61,5 @@ alias cvsdeath 'find . -name CVS -print -prune -exec rm -r {} \;'
# then "git fetch <nick>" and view with "gdifR <nick>" # then "git fetch <nick>" and view with "gdifR <nick>"
alias gdifR 'git diff master..\!:1/master |& difvu -' alias gdifR 'git diff master..\!:1/master |& difvu -'
# to merge all the changes, use "gmergR <nick>" # to merge all the changes, use "gmergR <nick>"
alias gmergR 'git git merge -s resolve \!:1/master' alias gmergR 'git merge -s resolve \!:1/master'

View File

@ -18,7 +18,6 @@ inherit PRO_PATH "http/library2";
# ifdef SANDBOX # ifdef SANDBOX
inherit NET_PATH "library/sandbox"; inherit NET_PATH "library/sandbox";
# endif # endif
inherit NET_PATH "library/base64";
inherit NET_PATH "library/hmac"; inherit NET_PATH "library/hmac";
inherit NET_PATH "library/dns"; inherit NET_PATH "library/dns";
inherit NET_PATH "library/htbasics"; inherit NET_PATH "library/htbasics";

View File

@ -25,8 +25,11 @@ inherit NET_PATH "queue2";
inherit NET_PATH "queue"; inherit NET_PATH "queue";
#endif #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 headers, fheaders;
volatile mapping rheaders = (["User-Agent": SERVER_VERSION]);
volatile string http_message; volatile string http_message;
volatile int http_status, port, fetching, ssl; volatile int http_status, port, fetching, ssl;
volatile string buffer, thehost, url, fetched, host, resource, method; 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; } object load() { return ME; }
void sAuth(string user, string password) { 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. // net/place/news code follows.
@ -74,13 +77,15 @@ void connect() {
P0(("%O couldn't parse %O\n", ME, url)) P0(("%O couldn't parse %O\n", ME, url))
return 0; return 0;
} }
thehost = lower_case(thehost); //thehost = lower_case(thehost); // why? who needs that?
ssl = t == "s"; ssl = t == "s";
} }
P4(("URL, THEHOST: %O, %O\n", url, thehost)) P4(("URL, THEHOST: %O, %O\n", url, thehost))
unless (port) unless (port) {
unless (sscanf(thehost, "%s:%d", thehost, port) == 2) unless (sscanf(thehost, "%s:%d", thehost, port) == 2)
port = ssl? HTTPS_SERVICE: HTTP_SERVICE; port = ssl? HTTPS_SERVICE: HTTP_SERVICE;
rheaders["host"] = thehost;
}
P2(("Resolving %O and connecting.\n", thehost)) P2(("Resolving %O and connecting.\n", thehost))
::connect(thehost, port); ::connect(thehost, port);
} }
@ -105,9 +110,7 @@ varargs int real_logon(int failure) {
P2(("%O fetching /%s from %O\n", ME, resource, host)) P2(("%O fetching /%s from %O\n", ME, resource, host))
P4(("%O using %O\n", ME, buffer)) P4(("%O using %O\n", ME, buffer))
emit(method + " /"+ resource +" HTTP/1.0\r\n" emit(method + " /"+ resource +" HTTP/1.0\r\n"
"Host: "+ host +"\r\n" + buffer +"\r\n");
+ buffer +
"\r\n");
buffer = ""; buffer = "";
next_input_to(#'parse_status); next_input_to(#'parse_status);
@ -177,9 +180,9 @@ disconnected(remainder) {
P2(("%O got disconnected.. %O\n", ME, remainder)) P2(("%O got disconnected.. %O\n", ME, remainder))
headers["_fetchtime"] = isotime(ctime(time()), 1); headers["_fetchtime"] = isotime(ctime(time()), 1);
if (headers["last-modified"]) if (headers["last-modified"])
rheaders["If-Modified-Since"] = headers["last-modified"]; rheaders["if-modified-since"] = headers["last-modified"];
//if (headers["etag"]) //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; fetched = buffer;
if (remainder) fetched += remainder; if (remainder) fetched += remainder;
@ -228,11 +231,11 @@ string qHeader(mixed key) {
} }
string qReqHeader(string key) { string qReqHeader(string key) {
return rheaders[key]; return rheaders[lower_case(key)];
} }
void sReqHeader(string key, string value) { void sReqHeader(string key, string value) {
rheaders[key] = value; rheaders[lower_case(key)] = value;
} }
varargs void refetch(closure cb, int willbehave) { varargs void refetch(closure cb, int willbehave) {
@ -240,12 +243,7 @@ varargs void refetch(closure cb, int willbehave) {
unless (fetching) connect(); unless (fetching) connect();
} }
void reset() { protected create() {
fetched = 0;
qCreate(); qCreate();
qInit(ME, 150, 5); qInit(ME, 150, 5);
} }
protected create() {
reset();
}

View File

@ -134,18 +134,15 @@ string urldecode(string txt) {
return txt; return txt;
} }
static string xx2c(string xx) { #if 0 // inline this instead, see below
string c = " ";
c[0] = hex2int(xx);
return c;
}
static string c2xx(string c) { static string c2xx(string c) {
return "%" + upper_case(sprintf("%x", c[0])); return "%"+ upper_case(sprintf("%x", c[0]));
} }
#endif
string urlencode(string txt) { 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 #ifndef DEFAULT_HT_TYPE
@ -192,7 +189,7 @@ default:
return 0; return 0;
} }
parse_query(query, qs) { mapping url_parse_query(mapping query, string qs) {
foreach (string pair : explode(qs, "&")) { foreach (string pair : explode(qs, "&")) {
string key, val; string key, val;

View File

@ -52,7 +52,7 @@ varargs void fetch(object ua, string url, string method, mapping oauth) {
void parse_request_token(string body, mapping headers) { void parse_request_token(string body, mapping headers) {
P3((">> oauth:parse_request_token(%O, %O)\n", body, headers)) P3((">> oauth:parse_request_token(%O, %O)\n", body, headers))
mapping params = ([]); mapping params = ([]);
parse_query(params, body); url_parse_query(params, body);
request_token = params["oauth_token"]; request_token = params["oauth_token"];
request_secret = params["oauth_token_secret"]; request_secret = params["oauth_token_secret"];
if (strlen(request_token) && strlen(request_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) { void parse_access_token(string body, mapping headers) {
P3((">> oauth:parse_access_token(%O, %O)\n", body, headers)) P3((">> oauth:parse_access_token(%O, %O)\n", body, headers))
mapping params = ([]); mapping params = ([]);
parse_query(params, body); url_parse_query(params, body);
access_token = params["oauth_token"]; access_token = params["oauth_token"];
access_secret = params["oauth_token_secret"]; access_secret = params["oauth_token_secret"];
if (strlen(access_token) && strlen(access_secret)) { if (strlen(access_token) && strlen(access_secret)) {

View File

@ -112,7 +112,7 @@ process() {
P4(("found cookie: %O\n", t)) P4(("found cookie: %O\n", t))
if (t && sscanf(t, "psyced=\"%s\"", t)) { if (t && sscanf(t, "psyced=\"%s\"", t)) {
P3(("got cookie: %O\n", t)) P3(("got cookie: %O\n", t))
query = parse_query(query, t); query = url_parse_query(query, t);
P4(("parsed cookie: %O\n", query)) P4(("parsed cookie: %O\n", query))
} }
#ifdef GENERIC_COOKIES // we might need them someday..? #ifdef GENERIC_COOKIES // we might need them someday..?
@ -135,7 +135,7 @@ process() {
#endif #endif
if (sscanf(url, "%s?%s", file, qs)) { if (sscanf(url, "%s?%s", file, qs)) {
P3(("got query: %O\n", qs)) P3(("got query: %O\n", qs))
query = parse_query(query, qs); query = url_parse_query(query, qs);
} else { } else {
file = url; file = url;
} }

View File

@ -1,11 +1,19 @@
#include <net.h> #include "base64.c"
inherit NET_PATH "library/base64"; #if 0 // inline this (see below)
static string xx2c(string xx) {
#include HTTP_PATH "library.i" string c = " ";
c[0] = hex2int(xx);
return c;
}
#endif
string hmac_bin(int method, string key, string arg) { 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) { string hmac_base64(int method, string key, string arg) {