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>"
alias gdifR 'git diff master..\!:1/master |& difvu -'
# 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
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";

View File

@ -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();
}

View File

@ -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;

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) {
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)) {

View File

@ -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;
}

View File

@ -1,11 +1,19 @@
#include <net.h>
#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) {