1
0
Fork 0
mirror of git://git.psyced.org/git/psyced synced 2024-08-15 03:25:10 +00:00

bignum_cmp

This commit is contained in:
psyc://psyced.org/~lynX 2010-03-09 18:55:51 +01:00
parent 8c6522112a
commit a0a9e533cf
4 changed files with 31 additions and 9 deletions

View file

@ -18,6 +18,9 @@ ________________________________________________________________________
place from psyced.ini, nor the autojoin rooms in the irc client seem place from psyced.ini, nor the autojoin rooms in the irc client seem
to make a difference 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 LPC
- large submissions into scratchpad can crash the driver - large submissions into scratchpad can crash the driver
- configure script fails on libidn now being in glibc - configure script fails on libidn now being in glibc

View file

@ -138,7 +138,7 @@ _query_password_sha1
|<iq type='result' from='{_VAR_server_XMPP}' id='[_tag_reply]'><query xmlns='jabber:iq:auth'><username/><sha1/><resource/></query></iq> |<iq type='result' from='{_VAR_server_XMPP}' id='[_tag_reply]'><query xmlns='jabber:iq:auth'><username/><sha1/><resource/></query></iq>
_request_user_amount _request_user_amount
|<iq type='get' from='[_INTERNAL_source_jabber]' to='[_INTERNAL_target_jabber]' id='[_tag]'><query xmlns='http://jabber.org/protocol/stats'><stat name='users/online'/><stat name='users/total'/></query></iq> |<iq type='get' from='[_INTERNAL_source_jabber]' to='[_INTERNAL_target_jabber]' id='[_tag]'><query xmlns='http://jabber.org/protocol/stats'><stat name='users/online'/><stat name='users/total'/></query></iq>
_request_registration_query _request_registration_query
|<iq type='get' from='[_INTERNAL_source_jabber]' to='[_INTERNAL_target_jabber]' id='[_tag]' xml:lang='[_language]'><query xmlns='jabber:iq:register'/></iq> |<iq type='get' from='[_INTERNAL_source_jabber]' to='[_INTERNAL_target_jabber]' id='[_tag]' xml:lang='[_language]'><query xmlns='jabber:iq:register'/></iq>
@ -448,7 +448,6 @@ _status_log_new
_status_time_boot _status_time_boot
|<iq id='[_tag_reply]' type='result' from='[_INTERNAL_source_jabber]' to='[_INTERNAL_target_jabber]'><query xmlns='jabber:iq:last' seconds='[_time_boot_duration]'></query></iq> |<iq id='[_tag_reply]' type='result' from='[_INTERNAL_source_jabber]' to='[_INTERNAL_target_jabber]'><query xmlns='jabber:iq:last' seconds='[_time_boot_duration]'></query></iq>
|
_status_place_topic _status_place_topic
|<message type='groupchat' to='[_INTERNAL_target_jabber]' from='[_INTERNAL_source_jabber_bare]'><subject>[_topic]</subject><body>Topic is: [_topic]</body></message> |<message type='groupchat' to='[_INTERNAL_target_jabber]' from='[_INTERNAL_source_jabber_bare]'><subject>[_topic]</subject><body>Topic is: [_topic]</body></message>

View file

@ -1222,6 +1222,25 @@ string decode_embedded_charset(string text) {
return 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<strlen(a); i++) {
if (a[i] == b[i]) continue;
if (a[i] > b[i]) return 1;
if (a[i] < b[i]) return -1;
}
}
#endif // __PIKE__ #endif // __PIKE__
object library_object() { object library_object() {

View file

@ -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 // 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 // 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 // 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. // 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 if (lastid && bignum_cmp(wurst[0]["id"], lastid) <= 0) {
// matches ours.
if (lastid && wurst[0]["id"] <= lastid) {
P1(("%O received %d old updates (id0 %O <= lastid %O).\n", P1(("%O received %d old updates (id0 %O <= lastid %O).\n",
ME, sizeof(wurst), wurst[0]["id"], lastid)) ME, sizeof(wurst), wurst[0]["id"], lastid))
return; return;
} }
lastid = wurst[0]["id"]; lastid = wurst[0]["id"];
P2(("%O -- new lastid %O\n", ME, lastid))
save_object(DATA_PATH "twitter"); save_object(DATA_PATH "twitter");
for (i=sizeof(wurst)-1; i>=0; i--) { for (i=sizeof(wurst)-1; i>=0; i--) {
d = wurst[i]; d = wurst[i];
@ -111,7 +108,7 @@ parse(string body, mapping headers) {
fetch() { fetch() {
P2(("%O going to fetch from %O since %O\n", ME, feed, lastid)) 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 ); feed -> content( #'parse, 1, 1 );
// twitter ignores since_id if count is present. stupid. // twitter ignores since_id if count is present. stupid.
feed -> fetch("http://twitter.com/statuses/friends_timeline.json?" feed -> fetch("http://twitter.com/statuses/friends_timeline.json?"
@ -124,7 +121,7 @@ create() {
object o = find_object(CONFIG_PATH "config"); object o = find_object(CONFIG_PATH "config");
if (o) config = o->qConfig(); if (o) config = o->qConfig();
if (!config) { if (!config || !config["password"]) {
P1(("\nNo configuration for twitter gateway found.\n")) P1(("\nNo configuration for twitter gateway found.\n"))
//destruct(ME); //destruct(ME);
return; return;
@ -134,6 +131,10 @@ create() {
// we could even choose to inherit this instead... // we could even choose to inherit this instead...
feed = clone_object(NET_PATH "http/fetch"); feed = clone_object(NET_PATH "http/fetch");
//feed -> sAgent(SERVER_VERSION " builtin Twitter to PSYC gateway"); //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"]); feed -> sAuth(config["nickname"], config["password"]);
call_out( #'fetch, 14 ); call_out( #'fetch, 14 );
} }