From 2f8c656e1df10984527fe445bd57783f5fdcafdc Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 28 Jun 2009 16:12:45 -0400 Subject: command line arg handling a little more flexible --- scripts/commandline.inc | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) (limited to 'scripts') diff --git a/scripts/commandline.inc b/scripts/commandline.inc index 4a7757fb9..8c5c56d5e 100644 --- a/scripts/commandline.inc +++ b/scripts/commandline.inc @@ -115,24 +115,60 @@ require_once INSTALLDIR . '/lib/common.php'; set_error_handler('common_error_handler'); -function have_option($str) +function have_option($opt, $alt=null) { global $options; + + $matches = array($opt); + + if (strlen($opt) > 1 && 0 != strncmp($opt, '--', 2)) { + $matches[] = '--'.$opt; + } else { + $matches[] = $opt; + } + + if (!empty($alt)) { + if (strlen($alt) > 1 && 0 != strncmp($alt, '--', 2)) { + $matches[] = '--'.$alt; + } else { + $matches[] = $alt; + } + } + foreach ($options as $option) { - if ($option[0] == $str) { + if (in_array($option[0], $matches)) { return true; } } + return false; } -function get_option_value($str) +function get_option_value($str, $alt=null) { global $options; + + $matches = array(); + + if (strlen($opt) > 1 && 0 != strncmp($opt, '--', 2)) { + $matches[] = '--'.$opt; + } else { + $matches[] = $opt; + } + + if (!empty($alt)) { + if (strlen($alt) > 1 && 0 != strncmp($alt, '--', 2)) { + $matches[] = '--'.$alt; + } else { + $matches[] = $alt; + } + } + foreach ($options as $option) { - if ($option[0] == $str) { + if (in_array($option[0], $matches)) { return $option[1]; } } + return null; } \ No newline at end of file -- cgit v1.2.3-54-g00ecf From 47e1d2adb87ae8ffa4c954d3ba62da64e986696c Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 28 Jun 2009 16:13:08 -0400 Subject: xmppdaemon.php can stay in foreground --- scripts/xmppdaemon.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'scripts') diff --git a/scripts/xmppdaemon.php b/scripts/xmppdaemon.php index 3eecfec29..38d739e68 100755 --- a/scripts/xmppdaemon.php +++ b/scripts/xmppdaemon.php @@ -20,13 +20,14 @@ define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -$shortoptions = 'i::'; -$longoptions = array('id::'); +$shortoptions = 'fi::'; +$longoptions = array('id::', 'foreground'); $helptext = <<host) ? $this->host : $this->server; $this->log(LOG_INFO, "Connecting to $connect_to on port $this->port"); @@ -323,16 +325,16 @@ if (common_config('xmpp','enabled')==false) { exit(); } -if (have_option('i')) { - $id = get_option_value('i'); -} else if (have_option('--id')) { - $id = get_option_value('--id'); +if (have_option('i', 'id')) { + $id = get_option_value('i', 'id'); } else if (count($args) > 0) { $id = $args[0]; } else { $id = null; } -$daemon = new XMPPDaemon($id); +$foreground = have_option('f', 'foreground'); + +$daemon = new XMPPDaemon($id, $foreground); $daemon->runOnce(); -- cgit v1.2.3-54-g00ecf From c755970141810a98e08f47c52568f635167e34f1 Mon Sep 17 00:00:00 2001 From: Super-User Date: Sun, 28 Jun 2009 20:15:17 +0000 Subject: commandline processing handles errors better --- scripts/commandline.inc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/commandline.inc b/scripts/commandline.inc index 4a7757fb9..53b9a490b 100644 --- a/scripts/commandline.inc +++ b/scripts/commandline.inc @@ -63,7 +63,14 @@ if (isset($longoptions)) { $parser = new Console_Getopt(); -list($options, $args) = $parser->getopt($argv, $shortoptions, $longoptions); +$result = $parser->getopt($argv, $shortoptions, $longoptions); + +if (PEAR::isError($result)) { + print $result->getMessage()."\n"; + exit(1); +} else { + list($options, $args) = $result; +} function show_help() { -- cgit v1.2.3-54-g00ecf From b06edd1f27948aa3e34bbb0a22172fc8d87b4fe6 Mon Sep 17 00:00:00 2001 From: Super-User Date: Sun, 28 Jun 2009 20:15:45 +0000 Subject: more efficient fixup of conversations --- scripts/fixup_conversations.php | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'scripts') diff --git a/scripts/fixup_conversations.php b/scripts/fixup_conversations.php index 2cfa422e6..0be0b4bac 100755 --- a/scripts/fixup_conversations.php +++ b/scripts/fixup_conversations.php @@ -24,22 +24,17 @@ require_once INSTALLDIR.'/scripts/commandline.inc'; common_log(LOG_INFO, 'Fixing up conversations.'); -$notice = new Notice(); -$notice->whereAdd('conversation is null'); -$notice->orderBy('id'); +$nid = new Notice(); +$nid->query('select id, reply_to from notice where conversation is null'); -$cnt = $notice->find(); +while ($nid->fetch()) { -print "Found $cnt notices.\n"; - -while ($notice->fetch()) { - - print "$notice->id =>"; - - $orig = clone($notice); - - if (empty($notice->reply_to)) { - $notice->conversation = $notice->id; + $cid = null; + + $notice = new Notice(); + + if (empty($nid->reply_to)) { + $cid = $nid->id; } else { $reply = Notice::staticGet('id', $notice->reply_to); @@ -52,6 +47,9 @@ while ($notice->fetch()) { } else { $notice->conversation = $reply->conversation; } + + unset($reply); + $reply = null; } print "$notice->conversation"; @@ -63,5 +61,10 @@ while ($notice->fetch()) { continue; } + $notice = null; + $orig = null; + unset($notice); + unset($orig); + print ".\n"; } -- cgit v1.2.3-54-g00ecf From a4d0f22b4b2907134779d7710f967c4841f6f938 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 28 Jun 2009 20:16:44 +0000 Subject: twitter status fetcher takes an id argument --- scripts/twitterstatusfetcher.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/twitterstatusfetcher.php b/scripts/twitterstatusfetcher.php index 5ffdda58f..8b10bfbad 100755 --- a/scripts/twitterstatusfetcher.php +++ b/scripts/twitterstatusfetcher.php @@ -25,9 +25,14 @@ define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); define('MAXCHILDREN', 2); define('POLL_INTERVAL', 60); // in seconds +$shortoptions = 'i::'; +$longoptions = array('id::'); + $helptext = <<_id); } /** @@ -625,6 +630,16 @@ class TwitterStatusFetcher extends Daemon declare(ticks = 1); -$fetcher = new TwitterStatusFetcher(); +if (have_option('i')) { + $id = get_option_value('i'); +} else if (have_option('--id')) { + $id = get_option_value('--id'); +} else if (count($args) > 0) { + $id = $args[0]; +} else { + $id = null; +} + +$fetcher = new TwitterStatusFetcher($id); $fetcher->runOnce(); -- cgit v1.2.3-54-g00ecf From cfd25489235b176c33cc4104aadfe5378fffe67d Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 28 Jun 2009 16:33:08 -0400 Subject: got my background/foreground logic backwards --- scripts/xmppdaemon.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/xmppdaemon.php b/scripts/xmppdaemon.php index 38d739e68..608cc1a36 100755 --- a/scripts/xmppdaemon.php +++ b/scripts/xmppdaemon.php @@ -335,6 +335,6 @@ if (have_option('i', 'id')) { $foreground = have_option('f', 'foreground'); -$daemon = new XMPPDaemon($id, $foreground); +$daemon = new XMPPDaemon($id, !$foreground); $daemon->runOnce(); -- cgit v1.2.3-54-g00ecf From 25c721f6ffc5ecf5825b60ab7b9c021d78b50888 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 28 Jun 2009 16:38:59 -0400 Subject: if not in daemon mode, xmppdaemon sends log to stdout --- scripts/xmppdaemon.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/xmppdaemon.php b/scripts/xmppdaemon.php index 608cc1a36..3e46c8e26 100755 --- a/scripts/xmppdaemon.php +++ b/scripts/xmppdaemon.php @@ -309,7 +309,14 @@ class XMPPDaemon extends Daemon function log($level, $msg) { - common_log($level, 'XMPPDaemon('.$this->resource.'): '.$msg); + $text = 'XMPPDaemon('.$this->resource.'): '.$msg; + common_log($level, $text); + if (!$this->daemonize) + { + $line = common_log_line($level, $text); + echo $line; + echo "\n"; + } } function subscribed($to) -- cgit v1.2.3-54-g00ecf From 7a0d33ab5fa29993cc7e05e41a26a26ca3ffd1e8 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 28 Jun 2009 16:55:19 -0400 Subject: reformat commandline.inc --- scripts/commandline.inc | 120 ++++++++++++++++++++++++------------------------ 1 file changed, 60 insertions(+), 60 deletions(-) (limited to 'scripts') diff --git a/scripts/commandline.inc b/scripts/commandline.inc index 9c6787cb7..bca09216d 100644 --- a/scripts/commandline.inc +++ b/scripts/commandline.inc @@ -66,10 +66,10 @@ $parser = new Console_Getopt(); $result = $parser->getopt($argv, $shortoptions, $longoptions); if (PEAR::isError($result)) { - print $result->getMessage()."\n"; - exit(1); + print $result->getMessage()."\n"; + exit(1); } else { - list($options, $args) = $result; + list($options, $args) = $result; } function show_help() @@ -77,7 +77,7 @@ function show_help() global $helptext; $_default_help_text = << 1 && 0 != strncmp($opt, '--', 2)) { - $matches[] = '--'.$opt; - } else { - $matches[] = $opt; - } - - if (!empty($alt)) { - if (strlen($alt) > 1 && 0 != strncmp($alt, '--', 2)) { - $matches[] = '--'.$alt; - } else { - $matches[] = $alt; - } - } - - foreach ($options as $option) { - if (in_array($option[0], $matches)) { - return true; - } - } - - return false; + global $options; + + $matches = array(); + + if (strlen($opt) > 1 && 0 != strncmp($opt, '--', 2)) { + $matches[] = '--'.$opt; + } else { + $matches[] = $opt; + } + + if (!empty($alt)) { + if (strlen($alt) > 1 && 0 != strncmp($alt, '--', 2)) { + $matches[] = '--'.$alt; + } else { + $matches[] = $alt; + } + } + + foreach ($options as $option) { + if (in_array($option[0], $matches)) { + return true; + } + } + + return false; } function get_option_value($str, $alt=null) { - global $options; - - $matches = array(); - - if (strlen($opt) > 1 && 0 != strncmp($opt, '--', 2)) { - $matches[] = '--'.$opt; - } else { - $matches[] = $opt; - } - - if (!empty($alt)) { - if (strlen($alt) > 1 && 0 != strncmp($alt, '--', 2)) { - $matches[] = '--'.$alt; - } else { - $matches[] = $alt; - } - } - - foreach ($options as $option) { - if (in_array($option[0], $matches)) { - return $option[1]; - } - } - - return null; -} \ No newline at end of file + global $options; + + $matches = array(); + + if (strlen($opt) > 1 && 0 != strncmp($opt, '--', 2)) { + $matches[] = '--'.$opt; + } else { + $matches[] = $opt; + } + + if (!empty($alt)) { + if (strlen($alt) > 1 && 0 != strncmp($alt, '--', 2)) { + $matches[] = '--'.$alt; + } else { + $matches[] = $alt; + } + } + + foreach ($options as $option) { + if (in_array($option[0], $matches)) { + return $option[1]; + } + } + + return null; +} -- cgit v1.2.3-54-g00ecf From 3ac6b7d120dff2d2b1c35e65559aa1613f5b02dd Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 28 Jun 2009 17:02:31 -0400 Subject: error in get_option_value wasn't returning a value --- scripts/commandline.inc | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) (limited to 'scripts') diff --git a/scripts/commandline.inc b/scripts/commandline.inc index bca09216d..3b6ef6098 100644 --- a/scripts/commandline.inc +++ b/scripts/commandline.inc @@ -122,10 +122,8 @@ require_once INSTALLDIR . '/lib/common.php'; set_error_handler('common_error_handler'); -function have_option($opt, $alt=null) +function _make_matches($opt, $alt) { - global $options; - $matches = array(); if (strlen($opt) > 1 && 0 != strncmp($opt, '--', 2)) { @@ -142,6 +140,15 @@ function have_option($opt, $alt=null) } } + return $matches; +} + +function have_option($opt, $alt=null) +{ + global $options; + + $matches = _make_matches($opt, $alt); + foreach ($options as $option) { if (in_array($option[0], $matches)) { return true; @@ -151,25 +158,11 @@ function have_option($opt, $alt=null) return false; } -function get_option_value($str, $alt=null) +function get_option_value($opt, $alt=null) { global $options; - $matches = array(); - - if (strlen($opt) > 1 && 0 != strncmp($opt, '--', 2)) { - $matches[] = '--'.$opt; - } else { - $matches[] = $opt; - } - - if (!empty($alt)) { - if (strlen($alt) > 1 && 0 != strncmp($alt, '--', 2)) { - $matches[] = '--'.$alt; - } else { - $matches[] = $alt; - } - } + $matches = _make_matches($opt, $alt); foreach ($options as $option) { if (in_array($option[0], $matches)) { -- cgit v1.2.3-54-g00ecf From 96814f14dbba483baa88d6e506dc7f61f0052a13 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 28 Jun 2009 17:22:11 -0400 Subject: add a lot more logging to xmppdaemon --- scripts/xmppdaemon.php | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/xmppdaemon.php b/scripts/xmppdaemon.php index 3e46c8e26..231922e39 100755 --- a/scripts/xmppdaemon.php +++ b/scripts/xmppdaemon.php @@ -75,10 +75,17 @@ class XMPPDaemon extends Daemon return false; } + $this->log(LOG_INFO, "Connected"); + $this->conn->setReconnectTimeout(600); + $this->log(LOG_INFO, "Sending initial presence."); + jabber_send_presence("Send me a message to post a notice", 'available', null, 'available', 100); + + $this->log(LOG_INFO, "Done connecting."); + return !$this->conn->isDisconnected(); } @@ -91,17 +98,23 @@ class XMPPDaemon extends Daemon { if ($this->connect()) { + $this->log(LOG_DEBUG, "Initializing stanza handlers."); + $this->conn->addEventHandler('message', 'handle_message', $this); $this->conn->addEventHandler('presence', 'handle_presence', $this); $this->conn->addEventHandler('reconnect', 'handle_reconnect', $this); + $this->log(LOG_DEBUG, "Beginning processing loop."); + $this->conn->process(); } } function handle_reconnect(&$pl) { + $this->log(LOG_DEBUG, "Got reconnection callback."); $this->conn->processUntil('session_start'); + $this->log(LOG_DEBUG, "Sending reconnection presence."); $this->conn->presence('Send me a message to post a notice', 'available', null, 'available', 100); } @@ -113,21 +126,27 @@ class XMPPDaemon extends Daemon function handle_message(&$pl) { + $from = jabber_normalize_jid($pl['from']); + if ($pl['type'] != 'chat') { + $this->log(LOG_WARNING, "Ignoring message of type ".$pl['type']." from $from."); return; } + if (mb_strlen($pl['body']) == 0) { + $this->log(LOG_WARNING, "Ignoring message with empty body from $from."); return; } - $from = jabber_normalize_jid($pl['from']); - # Forwarded from another daemon (probably a broadcaster) for # us to handle if ($this->is_self($from)) { + $this->log(LOG_INFO, "Got forwarded notice from self ($from)."); $from = $this->get_ofrom($pl); + $this->log(LOG_INFO, "Originally sent by $from."); if (is_null($from) || $this->is_self($from)) { + $this->log(LOG_INFO, "Ignoring notice originally sent by $from."); return; } } @@ -142,6 +161,7 @@ class XMPPDaemon extends Daemon return; } if ($this->handle_command($user, $pl['body'])) { + $this->log(LOG_INFO, "Command messag by $from handled."); return; } else if ($this->is_autoreply($pl['body'])) { $this->log(LOG_INFO, 'Ignoring auto reply from ' . $from); @@ -150,12 +170,20 @@ class XMPPDaemon extends Daemon $this->log(LOG_INFO, 'Ignoring OTR from ' . $from); return; } else if ($this->is_direct($pl['body'])) { + $this->log(LOG_INFO, 'Got a direct message ' . $from); + preg_match_all('/d[\ ]*([a-z0-9]{1,64})/', $pl['body'], $to); $to = preg_replace('/^d([\ ])*/', '', $to[0][0]); $body = preg_replace('/d[\ ]*('. $to .')[\ ]*/', '', $pl['body']); + + $this->log(LOG_INFO, 'Direct message from '. $user->nickname . ' to ' . $to); + $this->add_direct($user, $body, $to, $from); } else { + + $this->log(LOG_INFO, 'Posting a notice from ' . $user->nickname); + $this->add_notice($user, $pl); } @@ -263,6 +291,7 @@ class XMPPDaemon extends Daemon $notice = Notice::saveNew($user->id, $content_shortened, 'xmpp'); if (is_string($notice)) { $this->log(LOG_ERR, $notice); + $this->from_site($user->jabber, $notice); return; } common_broadcast_notice($notice); -- cgit v1.2.3-54-g00ecf From 87e3c52fa80ca15e00ae0d1892999fc5be6282a1 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 28 Jun 2009 17:22:44 -0400 Subject: change name of constructor for xmppdaemon --- scripts/xmppdaemon.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/xmppdaemon.php b/scripts/xmppdaemon.php index 231922e39..ca6218120 100755 --- a/scripts/xmppdaemon.php +++ b/scripts/xmppdaemon.php @@ -43,7 +43,7 @@ require_once INSTALLDIR . '/lib/daemon.php'; class XMPPDaemon extends Daemon { - function XMPPDaemon($resource=null, $daemonize=true) + function __construct($resource=null, $daemonize=true) { parent::__construct($daemonize); -- cgit v1.2.3-54-g00ecf From 4a926cad4e9f2cccc438cd249d47b92c12f59157 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 30 Jun 2009 12:25:18 -0400 Subject: add showcache.php script for debugging memcached issues --- scripts/showcache.php | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 scripts/showcache.php (limited to 'scripts') diff --git a/scripts/showcache.php b/scripts/showcache.php new file mode 100644 index 000000000..7a88fdbbb --- /dev/null +++ b/scripts/showcache.php @@ -0,0 +1,71 @@ +#!/usr/bin/env php +. + */ + +define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); + +$shortoptions = "t:c:v:k:"; + +$helptext = << +shows the cached object based on the args + + -t table Table to look up + -c column Column to look up, default "id" + -v value Value to look up + -k key Key to look up; other args are ignored + +ENDOFHELP; + +require_once INSTALLDIR.'/scripts/commandline.inc'; + +$karg = get_option_value('k'); + +if (!empty($karg)) { + $k = common_cache_key($karg); +} else { + $table = get_option_value('t'); + if (empty($table)) { + die("No table or key specified\n"); + } + $column = get_option_value('c'); + if (empty($column)) { + $column = 'id'; + } + $value = get_option_value('v'); + + $k = Memcached_DataObject::cacheKey($table, $column, $value); +} + +print "Checking key '$k'...\n"; + +$c = common_memcache(); + +if (empty($c)) { + die("Can't initialize cache object!\n"); +} + +$obj = $c->get($k); + +if (empty($obj)) { + print "Empty.\n"; +} else { + var_dump($obj); + print "\n"; +} -- cgit v1.2.3-54-g00ecf