From a0a9e533cfcfe78ee236fcab41ab0f686edc3612 Mon Sep 17 00:00:00 2001 From: "psyc://psyced.org/~lynX" <@> Date: Tue, 9 Mar 2010 18:55:51 +0100 Subject: [PATCH] bignum_cmp --- CHANGESTODO | 3 +++ world/default/en/jabber.textdb | 3 +-- world/net/library.i | 19 +++++++++++++++++++ world/net/twitter/polly.c | 15 ++++++++------- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/CHANGESTODO b/CHANGESTODO index dcd7a1d..6a73138 100644 --- a/CHANGESTODO +++ b/CHANGESTODO @@ -18,6 +18,9 @@ ________________________________________________________________________ place from psyced.ini, nor the autojoin rooms in the irc client seem to make a difference +- "invalid context" errors happen where local rooms send _context + as string uniform while local users expect the object pointer. huh? + LPC - large submissions into scratchpad can crash the driver - configure script fails on libidn now being in glibc diff --git a/world/default/en/jabber.textdb b/world/default/en/jabber.textdb index 3b69c56..68b98f8 100644 --- a/world/default/en/jabber.textdb +++ b/world/default/en/jabber.textdb @@ -138,7 +138,7 @@ _query_password_sha1 | _request_user_amount -| +| _request_registration_query | @@ -448,7 +448,6 @@ _status_log_new _status_time_boot | -| _status_place_topic |[_topic]Topic is: [_topic] diff --git a/world/net/library.i b/world/net/library.i index ef79a46..2e7cf94 100644 --- a/world/net/library.i +++ b/world/net/library.i @@ -1222,6 +1222,25 @@ string decode_embedded_charset(string text) { return text; } +// things only the twitter gateway needs... +// +// this is compatible to Perl's <=> operator: +// Binary "<=>" returns -1, 0, or 1 depending on whether the left argument +// is numerically less than, equal to, or greater than the right argument. +int bignum_cmp(string a, string b) { + int i; + if (a == b) return 0; + // calling strlen is probably faster than + // allocating a local variable to "cache" it + if (strlen(a) > strlen(b)) return 1; + if (strlen(a) < strlen(b)) return -1; + for (i=0; i b[i]) return 1; + if (a[i] < b[i]) return -1; + } +} + #endif // __PIKE__ object library_object() { diff --git a/world/net/twitter/polly.c b/world/net/twitter/polly.c index fb9d922..5fca575 100644 --- a/world/net/twitter/polly.c +++ b/world/net/twitter/polly.c @@ -40,17 +40,14 @@ parse(string body, mapping headers) { // this used to fail on MAX_INT turning the ints to negative.. it would work for // a while longer using floats, but since floating point mantissa in lpc is only // 32 bits wide, it's just a question of time until we hit that roof again (when - // status_id reaches 4294967296). so let's try strings instead. funny to run into + // status_id reaches 4294967296). so let's use bignums instead. funny to run into // such a weird problem only after years that twitter has been in existence. - // twitterific may have run into the same problem, as the timing of its breakdown - // matches ours. - if (lastid && wurst[0]["id"] <= lastid) { + if (lastid && bignum_cmp(wurst[0]["id"], lastid) <= 0) { P1(("%O received %d old updates (id0 %O <= lastid %O).\n", ME, sizeof(wurst), wurst[0]["id"], lastid)) return; } lastid = wurst[0]["id"]; - P2(("%O -- new lastid %O\n", ME, lastid)) save_object(DATA_PATH "twitter"); for (i=sizeof(wurst)-1; i>=0; i--) { d = wurst[i]; @@ -111,7 +108,7 @@ parse(string body, mapping headers) { fetch() { P2(("%O going to fetch from %O since %O\n", ME, feed, lastid)) - call_out( #'fetch, 4 * 59 ); // odd is better + call_out( #'fetch, 9 * 59 ); // odd is better.. was 4*59 feed -> content( #'parse, 1, 1 ); // twitter ignores since_id if count is present. stupid. feed -> fetch("http://twitter.com/statuses/friends_timeline.json?" @@ -124,7 +121,7 @@ create() { object o = find_object(CONFIG_PATH "config"); if (o) config = o->qConfig(); - if (!config) { + if (!config || !config["password"]) { P1(("\nNo configuration for twitter gateway found.\n")) //destruct(ME); return; @@ -134,6 +131,10 @@ create() { // we could even choose to inherit this instead... feed = clone_object(NET_PATH "http/fetch"); //feed -> sAgent(SERVER_VERSION " builtin Twitter to PSYC gateway"); + + // http://apiwiki.twitter.com/OAuth-FAQ#WhenareyougoingtoturnoffBasicAuth + // we should be using oauth by june 2010! + P1(("Using twitter account %O for %O ...\n", config["nickname"], ME)) feed -> sAuth(config["nickname"], config["password"]); call_out( #'fetch, 14 ); }