merged changes from lynX

This commit is contained in:
Gabor Adam Toth 2010-02-23 19:10:19 +01:00
commit 1b4463b2a4
7 changed files with 46 additions and 43 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;
@ -59,10 +62,10 @@ varargs void fetch(string murl, string meth, mixed body, 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.
@ -76,13 +79,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);
}
@ -103,10 +108,10 @@ varargs int real_logon(int failure) {
body = rbody;
} else if (mappingp(rbody) && sizeof(rbody)) {
body = make_query_string(rbody);
unless (rheaders["Content-Type"])
rheaders["Content-Type"] = "application/x-www-form-urlencoded";
unless (rheaders["content-type"])
rheaders["content-type"] = "application/x-www-form-urlencoded";
}
if (strlen(body)) rheaders["Content-Length"] = strlen(body);
if (strlen(body)) rheaders["content-length"] = strlen(body);
buffer = "";
foreach (string key, string value : rheaders) {
@ -118,8 +123,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" + body);
+ buffer + "\r\n" + body);
buffer = "";
next_input_to(#'parse_status);
@ -189,9 +193,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;
@ -240,11 +244,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) {
@ -252,12 +256,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;
}
mapping parse_query(mapping query, string qs) {
mapping url_parse_query(mapping query, string qs) {
foreach (string pair : explode(qs, "&")) {
string key, val;

View File

@ -45,13 +45,13 @@ varargs void fetch(object ua, string url, string method, mapping get, mapping po
foreach (string key, string value : oauth)
p += (strlen(p) ? "," : "") + key + "=\"" + urlencode(to_string(value)) + "\"";
ua->fetch(url, method, post, (["Authorization": "OAuth " + p]));
ua->fetch(url, method, post, (["authorization": "OAuth " + p]));
}
void parse_request_token(string body, mapping headers) {
P3((">> oauth:parse_request_token(%O, %O)\n", body, headers))
request_params = ([]);
parse_query(request_params, body);
url_parse_query(request_params, body);
if (strlen(request_params["oauth_token"]) && strlen(request_params["oauth_token_secret"])) {
shared_memory("oauth_request_tokens")[request_params["oauth_token"]] = ME;
sendmsg(user, "_notice_oauth_authorize_url", "Open [_url] to perform authorization.",
@ -64,7 +64,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))
access_params = ([]);
parse_query(access_params, body);
url_parse_query(access_params, body);
if (strlen(access_params["oauth_token"]) && strlen(access_params["oauth_token_secret"])) {
sendmsg(user, "_notice_oauth_success", "OAuth successful.");
} else {

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