diff --git a/world/net/connect.c b/world/net/connect.c index f7c9301..34c70e2 100644 --- a/world/net/connect.c +++ b/world/net/connect.c @@ -23,6 +23,7 @@ protected int block() { destruct(ME); return 0; } protected connect_failure(mc, text) { is_connecting = 0; + P1(("connect failure %O in %O, %O.\n", mc, ME, text)) monitor_report("_failure_network_connect"+ mc, object_name(ME) +" · "+ text); } @@ -42,7 +43,7 @@ protected int logon(int failure) { } is_connecting = 0; if (failure == -1 || !interactive(ME)) { - PT(("Warning: Failed connect attempt in %O\n", ME)) + P3(("Warning: Failed connect attempt in %O\n", ME)) #if __EFUN_DEFINED__(errno) connect_failure("_attempt", sprintf("connect failed: errno %s", errno())); diff --git a/world/net/http/fetch.c b/world/net/http/fetch.c index 7b9f949..530ff0e 100644 --- a/world/net/http/fetch.c +++ b/world/net/http/fetch.c @@ -4,6 +4,11 @@ // but we could fetch any page or data with it, really // tobij even allowed the object to have the URL as its object name. fancy! ;) +#ifdef Dfetch +# undef DEBUG +# define DEBUG Dfetch +#endif + #include #include #include @@ -66,7 +71,7 @@ void connect() { thehost = lower_case(thehost); ssl = t == "s"; } - PT(("URL, THEHOST: %O, %O\n", url, thehost)) + P4(("URL, THEHOST: %O, %O\n", url, thehost)) unless (port) unless (sscanf(thehost, "%s:%d", thehost, port) == 2) port = ssl? HTTPS_SERVICE: HTTP_SERVICE; @@ -74,14 +79,14 @@ void connect() { ::connect(thehost, port); } -varargs int real_logon(int arg) { +varargs int real_logon(int failure) { string scheme; headers = ([ ]); http_status = 500; http_message = "(failure)"; // used by debug only - unless(::logon(arg)) return -1; + unless(::logon(failure)) return -1; unless (url) return -3; unless (resource) sscanf(url, "%s://%s/%s", scheme, host, resource); @@ -93,7 +98,7 @@ varargs int real_logon(int arg) { // emit("If-None-Match: " + etag + "\r\n"); // we won't need connection: close w/ http/1.0 //emit("Connection: close\r\n\r\n"); - PT(("%O using %O\n", ME, buffer)) + P4(("%O using %O\n", ME, buffer)) emit("GET /"+ resource +" HTTP/1.0\r\n" "Host: "+ host +"\r\n" + buffer + @@ -104,7 +109,7 @@ varargs int real_logon(int arg) { return 0; // duh. } -varargs int logon(int arg, int sub) { +varargs int logon(int failure, int sub) { // net/connect disables telnet for all robots and circuits #if 0 //__EFUN_DEFINED__(enable_telnet) // when fetching the spiegel rss feed, telnet_neg() occasionally @@ -113,9 +118,9 @@ varargs int logon(int arg, int sub) { enable_telnet(0); #endif // when called from xmlrpc.c we can't do TLS anyway - if (sub) return ::logon(arg); + if (sub) return ::logon(failure); if (ssl) tls_init_connection(ME, #'real_logon); - else real_logon(arg); + else real_logon(failure); return 0; // duh. } @@ -125,8 +130,9 @@ int parse_status(string all) { sscanf(all, "%s%t%s", prot, state); sscanf(state, "%d%t%s", http_status, http_message); - P3(("%O got %O %O from %O\n", ME, http_status, http_message, host)); if (http_status != R_OK) { + P1(("%O got %O %O from %O\n", ME, + http_status, http_message, host)); monitor_report("_failure_unsupported_code_HTTP", S("http/fetch'ing %O returned %O %O", url || ME, http_status, http_message)); @@ -137,9 +143,9 @@ int parse_status(string all) { int parse_header(string all) { string key, val; - D2(D("htroom::parse is: " + all + "\n");) // TODO: parse status code if (all != "") { + P2(("http/fetch::parse_header %O\n", all)) if (sscanf(all, "%s:%1.0t%s", key, val) == 2) { headers[lower_case(key)] = val; // P2(("ht head: %O = %O\n", key, val)) @@ -148,6 +154,7 @@ int parse_header(string all) { return 1; } else { // das wollen wir nur bei status 200 + P2(("%O now waiting for http body\n", ME)) next_input_to(#'buffer_content); return 1; } @@ -155,70 +162,72 @@ int parse_header(string all) { } int buffer_content(string all) { + P2(("%O body %O\n", ME, all)) buffer += all + "\n"; next_input_to(#'buffer_content); return 1; } disconnected(remainder) { - headers["_fetchtime"] = isotime(ctime(time()), 1); - if (headers["last-modified"]) + P2(("%O got disconnected.. %O\n", ME, remainder)) + headers["_fetchtime"] = isotime(ctime(time()), 1); + if (headers["last-modified"]) modificationtime = headers["last-modified"]; - if (headers["etag"]) + if (headers["etag"]) etag = headers["etag"]; // heise does not work with etag - fetched = buffer; - if (remainder) fetched += remainder; - fheaders = headers; - buffer = headers = 0; - switch (http_status) { - case R_OK: - mixed *waiter; - while (qSize(ME)) { - waiter = shift(ME); - funcall(waiter[0], fetched, waiter[1] ? fheaders : copy(fheaders)); + fetched = buffer; + if (remainder) fetched += remainder; + fheaders = headers; + buffer = headers = 0; + switch (http_status) { + case R_OK: + mixed *waiter; + while (qSize(ME)) { + waiter = shift(ME); + P2(("%O calls back.. body is %O\n", ME, fetched)) + funcall(waiter[0], fetched, waiter[1] ? fheaders : copy(fheaders)); + } + break; + default: + // doesn't seem to get here when HTTP returns 301 or 302. strange. + // fall thru + case R_NOTMODIFIED: + qDel(ME); + qInit(ME, 150, 5); } - break; - default: - // doesn't seem to get here when HTTP returns 301 or 302. strange. - // fall thru - case R_NOTMODIFIED: - qDel(ME); - qInit(ME, 150, 5); - } - - fetching = 0; - return 1; // presume this disc was expected + fetching = 0; + return 1; // presume this disc was expected } varargs string content(closure cb, int force, int willbehave) { - if (cb) { - if (fetched) { - if (force) { - funcall(cb, fetched, willbehave ? fheaders : copy(fheaders)); + if (cb) { + if (fetched) { + if (force) { + funcall(cb, fetched, willbehave ? fheaders : copy(fheaders)); + } + } else { + enqueue(ME, ({ cb, willbehave })); } - } else { - enqueue(ME, ({ cb, willbehave })); } - } - return fetched; + return fetched; } varargs mapping headers(int willbehave) { - return willbehave ? fheaders : copy(fheaders); + return willbehave ? fheaders : copy(fheaders); } string qHeader(mixed key) { - if (mappingp(fheaders)) return fheaders[key]; - return 0; + if (mappingp(fheaders)) return fheaders[key]; + return 0; } varargs void refetch(closure cb, int willbehave) { - enqueue(ME, ({ cb, willbehave })); - unless (fetching) connect(); + enqueue(ME, ({ cb, willbehave })); + unless (fetching) connect(); } protected create() { - qCreate(); - qInit(ME, 150, 5); + qCreate(); + qInit(ME, 150, 5); } diff --git a/world/net/twitter/polly.c b/world/net/twitter/polly.c index 4c2203f..f8acbcd 100644 --- a/world/net/twitter/polly.c +++ b/world/net/twitter/polly.c @@ -9,16 +9,17 @@ persistent int lastid; volatile object feed; -parse(string body) { +parse(string body, mapping headers) { mixed wurst; string nick; object o; mapping d, p; int i; - //body = read_file("/net/twitter/many.json"); if (!body || body == "") { - P1(("%O failed to get its timeline.\n", ME)) + P1(("%O failed to get its timeline from %O.\n", ME, + previous_object())) + PT(("Got headers: %O", headers)) return; } //#if DEBUG > 0 @@ -60,16 +61,20 @@ parse(string body) { // should i send text as _action? "_nick": nick, // _count seems to be the better word for this + "_amount_updates": p["statuses_count"], "_amount_followers": p["followers_count"], - "_color": "#"+ p["profile_text_color"], - "_description": p["description"], - "_uniform_photo": p["profile_image_url"], - "_page": p["url"], - "_name": p["name"], + "_amount_sources": p["friends_count"], + "_color": "#"+ p["profile_sidebar_fill_color"], + "_description": p["description"] || "", + "_page": p["url"] || "", + "_name": p["name"] || "", // "_contact_twitter": p["id"], "_description_agent_HTML": d["source"], "_reference_reply": d["in_reply_to_screen_name"], // "_twit": d["id"], + "_uniform_photo": p["profile_image_url"] || "", + "_uniform_photo_background": + p["profile_background_image_url"] || "" ]), "/"); // send as root // der spiegel u.a. twittern übrigens in latin-1 @@ -81,8 +86,8 @@ parse(string body) { fetch() { feed -> content( #'parse, 0, 1 ); feed -> fetch("http://twitter.com/statuses/friends_timeline.json" - "?since_id="+ lastid +"&count=123"); - call_out( #'fetch, 9 * 60 ); + "?count="+( lastid? ("44&since_id="+ lastid) : "44")); + call_out( #'fetch, 6 * 59 ); // odd is better } create() { @@ -91,14 +96,14 @@ create() { if (o) config = o->qConfig(); if (!config) { - P1(("No configuration for twitter gateway found.\n"); - destruct(ME); + P1(("\nNo configuration for twitter gateway found.\n")) + //destruct(ME); return; } restore_object(DATA_PATH "twitter"); // we could even choose to inherit this instead... - feed = clone_object(HTTP_PATH "fetch"); + feed = clone_object(NET_PATH "http/fetch"); //feed -> sAgent(SERVER_VERSION " builtin Twitter to PSYC gateway"); feed -> sAuth(config["nickname"], config["password"]); call_out( #'fetch, 14 );