From 65a5d154b052c9ff35a79eaf8e3405522c8737cc Mon Sep 17 00:00:00 2001 From: Mike Kazantsev Date: Mon, 11 Feb 2013 13:56:03 +0100 Subject: skype: mention --plugindir quirk in HACKING As skype support always gets built as plugin, option is required for running tests without installing plugin to the system. --- protocols/skype/HACKING | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'protocols') diff --git a/protocols/skype/HACKING b/protocols/skype/HACKING index a6ff8290..edca0a45 100644 --- a/protocols/skype/HACKING +++ b/protocols/skype/HACKING @@ -19,8 +19,19 @@ python skyped.py -n -d == Tests -The plugin is tested with a mocked IRC client and a mocked skyped. To add a new -test, the following steps are necessary: +The plugin is tested with a mocked IRC client and a mocked skyped. + +To run tests with bitlbee built in a development tree and not (the one) +installed in the system (e.g. /usr), make sure to specify --plugindir= option to +./configure script during the build process: + +bitlbee% ./configure --skype=1 --plugindir="$(realpath .)" + +Otherwise bitlbee will try to load skype.so (among other things) from /usr/lib, +which is probably not what you want to test, or produce "Unknown protocol" +error. + +To add a new test, the following steps are necessary: 1) Add a new -skyped.mock file: just do the test manually, copy&paste the skyped output and clean it up, so Alice talks to Bob. You can test the created -- cgit v1.2.3 From 1146e216e8cf8c6fca77f3b5325ccd86078f827a Mon Sep 17 00:00:00 2001 From: Mike Kazantsev Date: Mon, 11 Feb 2013 13:56:03 +0100 Subject: skype.test: do proper cleanup of skyped process despite possible exceptions, keep pexpect.log --- protocols/skype/test.py | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'protocols') diff --git a/protocols/skype/test.py b/protocols/skype/test.py index 9f4c13ce..6d4e9daf 100755 --- a/protocols/skype/test.py +++ b/protocols/skype/test.py @@ -17,25 +17,25 @@ class Test(unittest.TestCase): proc.stdin.close() proc.communicate() def mock(self, name): - skyped_log = open("t/skyped.log", "w") - skyped = subprocess.Popen([sys.executable, "skyped.py", "-c", "t/skyped/skyped.conf", "-n", "-d", "-m", "t/%s-skyped.mock" % name], + with open("t/skyped.log", "w") as skyped_log,\ + open("t/pexpect.log", "w") as pexpect_log: + skyped = subprocess.Popen([sys.executable, "skyped.py", + "-c", "t/skyped/skyped.conf", "-n", "-d", "-m", "t/%s-skyped.mock" % name], stdout=skyped_log, stderr=subprocess.STDOUT) - - try: - bitlbee = pexpect.spawn('../../bitlbee', ['-d', 't/bitlbee']) - bitlbee_mock = open("t/%s-bitlbee.mock" % name) - for i in bitlbee_mock.readlines(): - line = i.strip() - if line.startswith(">> "): - bitlbee.expect_exact(line[3:], timeout=10) - elif line.startswith("<< "): - bitlbee.sendline(line[3:]) - bitlbee_mock.close() - bitlbee.close() - finally: - skyped.terminate() - skyped.communicate() - skyped_log.close() + try: + bitlbee = pexpect.spawn('../../bitlbee', ['-d', 't/bitlbee'], logfile=pexpect_log) + bitlbee_mock = open("t/%s-bitlbee.mock" % name) + for i in bitlbee_mock.readlines(): + line = i.strip() + if line.startswith(">> "): + bitlbee.expect_exact(line[3:], timeout=10) + elif line.startswith("<< "): + bitlbee.sendline(line[3:]) + bitlbee_mock.close() + bitlbee.close() + finally: + skyped.terminate() + skyped.communicate() def setUp(self): try: -- cgit v1.2.3 From ee3bccddcc2c197444be1bb685aa893e0ae2f910 Mon Sep 17 00:00:00 2001 From: Mike Kazantsev Date: Mon, 11 Feb 2013 13:56:03 +0100 Subject: skype: make chdirs work more reliably between tests --- protocols/skype/test.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'protocols') diff --git a/protocols/skype/test.py b/protocols/skype/test.py index 6d4e9daf..f20039e2 100755 --- a/protocols/skype/test.py +++ b/protocols/skype/test.py @@ -51,16 +51,18 @@ class Test(unittest.TestCase): os.makedirs("t/skyped") cwd = os.getcwd() os.chdir("t/skyped") - shutil.copyfile("../../skyped.cnf", "skyped.cnf") - self.openssl(['req', '-new', '-x509', '-days', '365', '-nodes', '-config', 'skyped.cnf', '-out', 'skyped.cert.pem', '-keyout', 'skyped.key.pem']) - with open("skyped.conf", "w") as sock: - sock.write("[skyped]\n") - sock.write("username = alice\n") - sock.write("password = %s\n" % hashlib.sha1("foo").hexdigest()) - sock.write("cert = %s/skyped.cert.pem\n" % os.getcwd()) - sock.write("key = %s/skyped.key.pem\n" % os.getcwd()) - sock.write("port = 2727\n") - os.chdir(cwd) + try: + shutil.copyfile("../../skyped.cnf", "skyped.cnf") + self.openssl(['req', '-new', '-x509', '-days', '365', '-nodes', '-config', 'skyped.cnf', '-out', 'skyped.cert.pem', '-keyout', 'skyped.key.pem']) + with open("skyped.conf", "w") as sock: + sock.write("[skyped]\n") + sock.write("username = alice\n") + sock.write("password = %s\n" % hashlib.sha1("foo").hexdigest()) + sock.write("cert = %s/skyped.cert.pem\n" % os.getcwd()) + sock.write("key = %s/skyped.key.pem\n" % os.getcwd()) + sock.write("port = 2727\n") + finally: + os.chdir(cwd) def testMsg(self): @@ -71,13 +73,13 @@ class Test(unittest.TestCase): def testInfo(self): self.mock("info") - + def testCall(self): self.mock("call") - + def testCallFailed(self): self.mock("call-failed") - + def testAddYes(self): self.mock("add-yes") @@ -89,7 +91,7 @@ class Test(unittest.TestCase): def testGroupchatInvite(self): self.mock("groupchat-invite") - + def testCalledYes(self): self.mock("called-yes") -- cgit v1.2.3 From b56c76ccb4f9b0e2ebb220ff2b99b7a1f841b9a5 Mon Sep 17 00:00:00 2001 From: Mike Kazantsev Date: Mon, 11 Feb 2013 13:56:03 +0100 Subject: skype: use argparse instead of getopt for CLI in skyped --- protocols/skype/skyped.py | 148 +++++++++++++++++++--------------------------- 1 file changed, 61 insertions(+), 87 deletions(-) (limited to 'protocols') diff --git a/protocols/skype/skyped.py b/protocols/skype/skyped.py index f1777d0b..224a94d3 100644 --- a/protocols/skype/skyped.py +++ b/protocols/skype/skyped.py @@ -1,32 +1,30 @@ #!/usr/bin/env python2.7 -# +# # skyped.py -# +# # Copyright (c) 2007-2013 by Miklos Vajna # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, # USA. # import sys import os import signal -import locale import time import socket -import getopt import Skype4Py import hashlib from ConfigParser import ConfigParser, NoOptionError @@ -280,7 +278,7 @@ class MockedSkype: def __init__(self, mock): sock = open(mock) self.lines = sock.readlines() - + def SendCommand(self, c): pass @@ -379,43 +377,6 @@ class SkypeApi: except Skype4Py.SkypeAPIError, s: dprint("Warning, sending '%s' failed (%s)." % (e, s)) -class Options: - def __init__(self): - self.cfgpath = os.path.join(os.environ['HOME'], ".skyped", "skyped.conf") - # fall back to system-wide settings - self.syscfgpath = "/usr/local/etc/skyped/skyped.conf" - if os.path.exists(self.syscfgpath) and not os.path.exists(self.cfgpath): - self.cfgpath = self.syscfgpath - self.daemon = True - self.debug = False - self.help = False - self.host = "0.0.0.0" - self.log = None - self.port = None - self.version = False - # well, this is a bit hackish. we store the socket of the last connected client - # here and notify it. maybe later notify all connected clients? - self.conn = None - # this will be read first by the input handler - self.buf = None - self.mock = None - - - def usage(self, ret): - print """Usage: skyped [OPTION]... - -skyped is a daemon that acts as a tcp server on top of a Skype instance. - -Options: - -c --config path to configuration file (default: %s) - -d --debug enable debug messages - -h --help this help - -H --host set the tcp host, supports IPv4 and IPv6 (default: %s) - -l --log set the log file in background mode (default: none) - -n --nofork don't run as daemon in the background - -p --port set the tcp port (default: %s) - -v --version display version information""" % (self.cfgpath, self.host, self.port) - sys.exit(ret) def serverloop(options, skype): timeout = 1; # in seconds @@ -458,60 +419,70 @@ def serverloop(options, skype): else: options.last_bitlbee_pong = now -if __name__=='__main__': - options = Options() - try: - opts, args = getopt.getopt(sys.argv[1:], "c:dhH:l:m:np:v", ["config=", "debug", "help", "host=", "log=", "mock=", "nofork", "port=", "version"]) - except getopt.GetoptError: - options.usage(1) - for opt, arg in opts: - if opt in ("-c", "--config"): - options.cfgpath = arg - elif opt in ("-d", "--debug"): - options.debug = True - elif opt in ("-h", "--help"): - options.help = True - elif opt in ("-H", "--host"): - options.host = arg - elif opt in ("-l", "--log"): - options.log = arg - elif opt in ("-m", "--mock"): - options.mock = arg - elif opt in ("-n", "--nofork"): - options.daemon = False - elif opt in ("-p", "--port"): - options.port = int(arg) - elif opt in ("-v", "--version"): - options.version = True - if options.help: - options.usage(0) - elif options.version: + +def main(args=None): + global options + global skype + + cfgpath = os.path.join(os.environ['HOME'], ".skyped", "skyped.conf") + syscfgpath = "/usr/local/etc/skyped/skyped.conf" + if not os.path.exists(cfgpath) and os.path.exists(syscfgpath): + cfgpath = syscfgpath # fall back to system-wide settings + port = 2727 + + import argparse + parser = argparse.ArgumentParser() + parser.add_argument('-c', '--config', + metavar='path', default=cfgpath, + help='path to configuration file (default: %(default)s)') + parser.add_argument('-H', '--host', default='0.0.0.0', + help='set the tcp host, supports IPv4 and IPv6 (default: %(default)s)') + parser.add_argument('-p', '--port', type=int, + help='set the tcp port (default: %(default)s)') + parser.add_argument('-l', '--log', metavar='path', + help='set the log file in background mode (default: none)') + parser.add_argument('-v', '--version', action='store_true', help='display version information') + parser.add_argument('-n', '--nofork', + action='store_true', help="don't run as daemon in the background") + parser.add_argument('-m', '--mock', help='fake interactions with skype (only useful for tests)') + parser.add_argument('-d', '--debug', action='store_true', help='enable debug messages') + options = parser.parse_args(sys.argv[1:] if args is None else args) + + if options.version: print "skyped %s" % __version__ sys.exit(0) - # parse our config - if not os.path.exists(options.cfgpath): - print "Can't find configuration file at '%s'." % options.cfgpath - print "Use the -c option to specify an alternate one." - sys.exit(1) + + # well, this is a bit hackish. we store the socket of the last connected client + # here and notify it. maybe later notify all connected clients? + options.conn = None + # this will be read first by the input handler + options.buf = None + + if not os.path.exists(options.config): + parser.error(( "Can't find configuration file at '%s'." + "Use the -c option to specify an alternate one." )% options.config) + + cfgpath = options.config options.config = ConfigParser() - options.config.read(options.cfgpath) - options.config.username = options.config.get('skyped', 'username').split('#')[0] - options.config.password = options.config.get('skyped', 'password').split('#')[0] - options.config.sslkey = os.path.expanduser(options.config.get('skyped', 'key').split('#')[0]) - options.config.sslcert = os.path.expanduser(options.config.get('skyped', 'cert').split('#')[0]) + options.config.read(cfgpath) + options.config.username = options.config.get('skyped', 'username').split('#', 1)[0] + options.config.password = options.config.get('skyped', 'password').split('#', 1)[0] + options.config.sslkey = os.path.expanduser(options.config.get('skyped', 'key').split('#', 1)[0]) + options.config.sslcert = os.path.expanduser(options.config.get('skyped', 'cert').split('#', 1)[0]) + # hack: we have to parse the parameters first to locate the # config file but the -p option should overwrite the value from # the config file try: - options.config.port = int(options.config.get('skyped', 'port').split('#')[0]) + options.config.port = int(options.config.get('skyped', 'port').split('#', 1)[0]) if not options.port: options.port = options.config.port except NoOptionError: pass if not options.port: - options.port = 2727 - dprint("Parsing config file '%s' done, username is '%s'." % (options.cfgpath, options.config.username)) - if options.daemon: + options.port = port + dprint("Parsing config file '%s' done, username is '%s'." % (options.config, options.config.username)) + if not options.nofork: pid = os.fork() if pid == 0: nullin = file(os.devnull, 'r') @@ -539,3 +510,6 @@ if __name__=='__main__': options.conn = False options.lock = threading.Lock() server(options.host, options.port, skype) + + +if __name__ == '__main__': main() -- cgit v1.2.3 From 7e5b4bd31383187b04dedec4854d8c89ae2aea7b Mon Sep 17 00:00:00 2001 From: Mike Kazantsev Date: Mon, 11 Feb 2013 13:56:03 +0100 Subject: skype: add --dont-start-skype option For cases when case skype start/stop/restart is being handled externally. Skype4Py seem to be able to handle client going on/off. --- protocols/skype/skyped.py | 17 +++++++++++------ protocols/skype/skyped.txt | 3 +++ 2 files changed, 14 insertions(+), 6 deletions(-) (limited to 'protocols') diff --git a/protocols/skype/skyped.py b/protocols/skype/skyped.py index 224a94d3..76368aba 100644 --- a/protocols/skype/skyped.py +++ b/protocols/skype/skyped.py @@ -51,11 +51,12 @@ def eh(type, value, tb): gobject.MainLoop().quit() if options.conn: options.conn.close() - # shut down client if it's running - try: - skype.skype.Client.Shutdown() - except NameError: - pass + if not options.dont_start_skype: + # shut down client if it's running + try: + skype.skype.Client.Shutdown() + except NameError: + pass sys.exit("Exiting.") sys.excepthook = eh @@ -307,10 +308,12 @@ class MockedSkype: class SkypeApi: def __init__(self, mock): + global options if not mock: self.skype = Skype4Py.Skype() self.skype.OnNotify = self.recv - self.skype.Client.Start() + if not options.dont_start_skype: + self.skype.Client.Start() else: self.skype = MockedSkype(mock) @@ -444,6 +447,8 @@ def main(args=None): parser.add_argument('-v', '--version', action='store_true', help='display version information') parser.add_argument('-n', '--nofork', action='store_true', help="don't run as daemon in the background") + parser.add_argument('-s', '--dont-start-skype', action='store_true', + help="assume that skype is running independently, don't try to start/stop it") parser.add_argument('-m', '--mock', help='fake interactions with skype (only useful for tests)') parser.add_argument('-d', '--debug', action='store_true', help='enable debug messages') options = parser.parse_args(sys.argv[1:] if args is None else args) diff --git a/protocols/skype/skyped.txt b/protocols/skype/skyped.txt index 0f11f093..c5f9abb9 100644 --- a/protocols/skype/skyped.txt +++ b/protocols/skype/skyped.txt @@ -74,6 +74,9 @@ in `skyped.conf`. -n, --nofork:: Don't run as daemon in the background +-s, --dont-start-skype:: + Assume that skype is running independently, don't try to start/stop it. + -p, --port:: Set the tcp port (default: 2727) -- cgit v1.2.3 From 3e238504209e998064f0906c9edfced9713ba94d Mon Sep 17 00:00:00 2001 From: Mike Kazantsev Date: Mon, 11 Feb 2013 13:56:03 +0100 Subject: skype: add ATTACH_GDB env flag, extend hacking instructions with info on pexpect/gdb --- protocols/skype/HACKING | 29 +++++++++++++++++++++++++++++ protocols/skype/test.py | 14 ++++++++++++++ 2 files changed, 43 insertions(+) (limited to 'protocols') diff --git a/protocols/skype/HACKING b/protocols/skype/HACKING index edca0a45..935856a7 100644 --- a/protocols/skype/HACKING +++ b/protocols/skype/HACKING @@ -17,10 +17,15 @@ python skyped.py -n -d 4) irssi + == Tests The plugin is tested with a mocked IRC client and a mocked skyped. +=== Requirements + +Python pexpect module is required to run the tests. + To run tests with bitlbee built in a development tree and not (the one) installed in the system (e.g. /usr), make sure to specify --plugindir= option to ./configure script during the build process: @@ -31,6 +36,30 @@ Otherwise bitlbee will try to load skype.so (among other things) from /usr/lib, which is probably not what you want to test, or produce "Unknown protocol" error. +=== Running + +Tests can be run by running test.py script in this ("protocols/skype") +directory. + +For more control over how/which tests are being run from there, use "python -m +unittest" command: + +bitlbee/protocols/skype% python -m unittest test +bitlbee/protocols/skype% python -m unittest -f test +bitlbee/protocols/skype% python -m unittest test.Test.testMsg + +If bitlbee crashes during tests with SIGSEGV (segmentation fault), it's likely +that there is some problem with skype.c plugin. +To get a backtrace of such crash, use: + +bitlbee/protocols/skype% ATTACH_GDB=true python -m unittest test.Test.testMsg + +Example shows running "testMsg" test with gdb attached to bitlbee, which will +produce full backtrace in "t/gdb-.log" files (see pid in pexpect error +output of the test). + +=== Adding new tests + To add a new test, the following steps are necessary: 1) Add a new -skyped.mock file: just do the test manually, copy&paste the diff --git a/protocols/skype/test.py b/protocols/skype/test.py index f20039e2..b3f25f46 100755 --- a/protocols/skype/test.py +++ b/protocols/skype/test.py @@ -24,6 +24,20 @@ class Test(unittest.TestCase): stdout=skyped_log, stderr=subprocess.STDOUT) try: bitlbee = pexpect.spawn('../../bitlbee', ['-d', 't/bitlbee'], logfile=pexpect_log) + if os.environ.get('ATTACH_GDB'): + subprocess.Popen(['gdb', '-batch-silent', + '-ex', 'set logging overwrite on', + '-ex', 'set logging file t/gdb-%s.log' % bitlbee.pid, + '-ex', 'set logging on', + '-ex', 'handle all pass nostop noprint', + '-ex', 'handle SIGSEGV pass stop print', + '-ex', 'set pagination 0', + '-ex', 'continue', + '-ex', 'backtrace full', + '-ex', 'info registers', + '-ex', 'thread apply all backtrace', + '-ex', 'quit', + '../../bitlbee', str(bitlbee.pid) ]) bitlbee_mock = open("t/%s-bitlbee.mock" % name) for i in bitlbee_mock.readlines(): line = i.strip() -- cgit v1.2.3 From 5a0ffa2be7f6e5354975abd6c17fffb43bb4d694 Mon Sep 17 00:00:00 2001 From: Mike Kazantsev Date: Mon, 11 Feb 2013 13:56:03 +0100 Subject: skype: add newline to all the lines emitted --- protocols/skype/skype.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'protocols') diff --git a/protocols/skype/skype.c b/protocols/skype/skype.c index b3d29dab..d879e3ed 100644 --- a/protocols/skype/skype.c +++ b/protocols/skype/skype.c @@ -193,7 +193,7 @@ int skype_printf(struct im_connection *ic, char *fmt, ...) static void skype_buddy_ask_yes(void *data) { struct skype_buddy_ask_data *bla = data; - skype_printf(bla->ic, "SET USER %s ISAUTHORIZED TRUE", + skype_printf(bla->ic, "SET USER %s ISAUTHORIZED TRUE\n", bla->handle); g_free(bla->handle); g_free(bla); @@ -202,7 +202,7 @@ static void skype_buddy_ask_yes(void *data) static void skype_buddy_ask_no(void *data) { struct skype_buddy_ask_data *bla = data; - skype_printf(bla->ic, "SET USER %s ISAUTHORIZED FALSE", + skype_printf(bla->ic, "SET USER %s ISAUTHORIZED FALSE\n", bla->handle); g_free(bla->handle); g_free(bla); @@ -225,7 +225,7 @@ void skype_buddy_ask(struct im_connection *ic, char *handle, char *message) static void skype_call_ask_yes(void *data) { struct skype_buddy_ask_data *bla = data; - skype_printf(bla->ic, "SET CALL %s STATUS INPROGRESS", + skype_printf(bla->ic, "SET CALL %s STATUS INPROGRESS\n", bla->handle); g_free(bla->handle); g_free(bla); @@ -234,7 +234,7 @@ static void skype_call_ask_yes(void *data) static void skype_call_ask_no(void *data) { struct skype_buddy_ask_data *bla = data; - skype_printf(bla->ic, "SET CALL %s STATUS FINISHED", + skype_printf(bla->ic, "SET CALL %s STATUS FINISHED\n", bla->handle); g_free(bla->handle); g_free(bla); @@ -917,7 +917,7 @@ static void skype_parse_group(struct im_connection *ic, char *line) if (!sd->pending_user) { /* Number of users changed in this group, query its type to see * if it's a custom one we should care about. */ - skype_printf(ic, "GET GROUP %s TYPE", id); + skype_printf(ic, "GET GROUP %s TYPE\n", id); return; } @@ -926,7 +926,7 @@ static void skype_parse_group(struct im_connection *ic, char *line) struct skype_group *sg = skype_group_by_id(ic, atoi(id)); if (sg) { - skype_printf(ic, "ALTER GROUP %d ADDUSER %s", sg->id, sd->pending_user); + skype_printf(ic, "ALTER GROUP %d ADDUSER %s\n", sg->id, sd->pending_user); g_free(sd->pending_user); sd->pending_user = NULL; } else @@ -934,7 +934,7 @@ static void skype_parse_group(struct im_connection *ic, char *line) "No skype group with id %s. That's probably a bug.", id); } else if (!strcmp(info, "TYPE CUSTOM_GROUP")) /* This one is interesting, query its users. */ - skype_printf(ic, "GET GROUP %s USERS", id); + skype_printf(ic, "GET GROUP %s USERS\n", id); } static void skype_parse_chat(struct im_connection *ic, char *line) @@ -1337,7 +1337,7 @@ static char *skype_set_display_name(set_t *set, char *value) account_t *acc = set->data; struct im_connection *ic = acc->ic; - skype_printf(ic, "SET PROFILE FULLNAME %s", value); + skype_printf(ic, "SET PROFILE FULLNAME %s\n", value); return value; } @@ -1346,7 +1346,7 @@ static char *skype_set_mood_text(set_t *set, char *value) account_t *acc = set->data; struct im_connection *ic = acc->ic; - skype_printf(ic, "SET PROFILE MOOD_TEXT %s", value); + skype_printf(ic, "SET PROFILE MOOD_TEXT %s\n", value); return value; } @@ -1355,7 +1355,7 @@ static char *skype_set_balance(set_t *set, char *value) account_t *acc = set->data; struct im_connection *ic = acc->ic; - skype_printf(ic, "GET PROFILE PSTN_BALANCE"); + skype_printf(ic, "GET PROFILE PSTN_BALANCE\n"); return value; } @@ -1366,7 +1366,7 @@ static void skype_call(struct im_connection *ic, char *value) if (ptr) *ptr = '\0'; - skype_printf(ic, "CALL %s", nick); + skype_printf(ic, "CALL %s\n", nick); g_free(nick); } @@ -1375,7 +1375,7 @@ static void skype_hangup(struct im_connection *ic) struct skype_data *sd = ic->proto_data; if (sd->call_id) { - skype_printf(ic, "SET CALL %s STATUS FINISHED", + skype_printf(ic, "SET CALL %s STATUS FINISHED\n", sd->call_id); g_free(sd->call_id); sd->call_id = 0; @@ -1415,10 +1415,10 @@ static void skype_add_buddy(struct im_connection *ic, char *who, char *group) if (!sg) { /* No such group, we need to create it, then have to * add the user once it's created. */ - skype_printf(ic, "CREATE GROUP %s", group); + skype_printf(ic, "CREATE GROUP %s\n", group); sd->pending_user = g_strdup(nick); } else { - skype_printf(ic, "ALTER GROUP %d ADDUSER %s", sg->id, nick); + skype_printf(ic, "ALTER GROUP %d ADDUSER %s\n", sg->id, nick); } } } -- cgit v1.2.3 From 8e166ae8264a7c9f98e766c8635faa94cd075eb8 Mon Sep 17 00:00:00 2001 From: Mike Kazantsev Date: Mon, 11 Feb 2013 13:56:04 +0100 Subject: skype: cleanup of the send() code Use socket.sendall(), as send() is not guaranteed to send all the data passed (though it should generally work that way with blocking sockets). Use more robust, obvious and idiomatic loop conditions. Cleanup redundant imports and variables. --- protocols/skype/skyped.py | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'protocols') diff --git a/protocols/skype/skyped.py b/protocols/skype/skyped.py index 76368aba..57b2f9ce 100644 --- a/protocols/skype/skyped.py +++ b/protocols/skype/skyped.py @@ -123,35 +123,33 @@ def skype_idle_handler(skype): time.sleep(1) return True -def send(sock, txt): +def send(sock, txt, tries=10): global options - from time import sleep - count = 1 - done = False if hasgobject: - while (not done) and (count < 10): + for attempt in xrange(1, tries+1): try: - sock.send(txt) - done = True + sock.sendall(txt) except Exception, s: - count += 1 - dprint("Warning, sending '%s' failed (%s). count=%d" % (txt, s, count)) - sleep(1) - if not done: + dprint("Warning, sending '%s' failed (%s). count=%d" % (txt, s, attempt)) + time.sleep(1) + else: + break + else: options.conn.close() else: - while (not done) and (count < 10) and options.conn: + for attempt in xrange(1, tries+1): + if not options.conn: break if wait_for_lock(options.lock, 3, 10, "socket send"): try: - if options.conn: sock.send(txt) + if options.conn: sock.sendall(txt) options.lock.release() - done = True except Exception, s: options.lock.release() - count += 1 dprint("Warning, sending '%s' failed (%s). count=%d" % (txt, s, count)) - sleep(1) - if not done: + time.sleep(1) + else: + break + else: if options.conn: options.conn.close() options.conn = False -- cgit v1.2.3 From 5a4f22e15ec95696b02d9592fdd1b24adae9674e Mon Sep 17 00:00:00 2001 From: Mike Kazantsev Date: Mon, 11 Feb 2013 13:56:04 +0100 Subject: skype: don't do retries on send() on socket errors with gobject As it's a blocking socket, I imagine there might be only EINTR errors from signals, which don't seem to be used here. I think the same tweak can be applied to select() code, but I don't run it, so no idea if Skype4Py threads might make such loop necessary there. --- protocols/skype/skyped.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'protocols') diff --git a/protocols/skype/skyped.py b/protocols/skype/skyped.py index 57b2f9ce..68008fbf 100644 --- a/protocols/skype/skyped.py +++ b/protocols/skype/skyped.py @@ -126,16 +126,13 @@ def skype_idle_handler(skype): def send(sock, txt, tries=10): global options if hasgobject: - for attempt in xrange(1, tries+1): - try: - sock.sendall(txt) - except Exception, s: - dprint("Warning, sending '%s' failed (%s). count=%d" % (txt, s, attempt)) - time.sleep(1) - else: - break - else: + if not options.conn: return + try: + sock.sendall(txt) + except Exception, s: + dprint("Warning, sending '%s' failed (%s)." % (txt, s)) options.conn.close() + options.conn = False else: for attempt in xrange(1, tries+1): if not options.conn: break -- cgit v1.2.3 From 4da4e9b8a8260a55f734fefcf80ce64fc6dbdfc5 Mon Sep 17 00:00:00 2001 From: Mike Kazantsev Date: Mon, 11 Feb 2013 13:56:04 +0100 Subject: skype: handle socket errors during tls session negotiation in a graceful way Before this patch, such errors (which happen 1/4 times here) lock skyped forever, producing traceback (and hanging because threads in python). Proper fix would be to see why these happen (might be ssl handling in the plugin), but that's no excuse not to handle socket errors without crashing the daemon. --- protocols/skype/skyped.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'protocols') diff --git a/protocols/skype/skyped.py b/protocols/skype/skyped.py index 68008fbf..ae4df6a2 100644 --- a/protocols/skype/skyped.py +++ b/protocols/skype/skyped.py @@ -201,9 +201,13 @@ def listener(sock, skype): certfile=options.config.sslcert, keyfile=options.config.sslkey, ssl_version=ssl.PROTOCOL_TLSv1) - except ssl.SSLError: - dprint("Warning, SSL init failed, did you create your certificate?") - return False + except (ssl.SSLError, socket.error) as err: + if isinstance(err, ssl.SSLError): + dprint("Warning, SSL init failed, did you create your certificate?") + return False + else: + dprint('Warning, SSL init failed') + return True if hasattr(options.conn, 'handshake'): try: options.conn.handshake() -- cgit v1.2.3 From b6ab05bd13a498204ae322c9d9fd1eb5ec6abb30 Mon Sep 17 00:00:00 2001 From: Mike Kazantsev Date: Mon, 11 Feb 2013 13:56:04 +0100 Subject: skype: handle only socket errors in send() --- protocols/skype/skyped.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'protocols') diff --git a/protocols/skype/skyped.py b/protocols/skype/skyped.py index ae4df6a2..19de51aa 100644 --- a/protocols/skype/skyped.py +++ b/protocols/skype/skyped.py @@ -129,7 +129,7 @@ def send(sock, txt, tries=10): if not options.conn: return try: sock.sendall(txt) - except Exception, s: + except socket.error as s: dprint("Warning, sending '%s' failed (%s)." % (txt, s)) options.conn.close() options.conn = False @@ -140,7 +140,7 @@ def send(sock, txt, tries=10): try: if options.conn: sock.sendall(txt) options.lock.release() - except Exception, s: + except socket.error as s: options.lock.release() dprint("Warning, sending '%s' failed (%s). count=%d" % (txt, s, count)) time.sleep(1) -- cgit v1.2.3 From 61d2eabb1651e771937ea34794a501115d8cd49f Mon Sep 17 00:00:00 2001 From: Mike Kazantsev Date: Thu, 14 Feb 2013 16:20:00 +0100 Subject: skype: check for truncated commands on receiving --- protocols/skype/skype.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'protocols') diff --git a/protocols/skype/skype.c b/protocols/skype/skype.c index d879e3ed..963406db 100644 --- a/protocols/skype/skype.c +++ b/protocols/skype/skype.c @@ -28,7 +28,7 @@ #define SKYPE_DEFAULT_SERVER "localhost" #define SKYPE_DEFAULT_PORT "2727" -#define IRC_LINE_SIZE 1024 +#define IRC_LINE_SIZE 16384 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) /* @@ -1146,6 +1146,13 @@ static gboolean skype_read_callback(gpointer data, gint fd, return FALSE; /* Read the whole data. */ st = ssl_read(sd->ssl, buf, sizeof(buf)); + if (st >= IRC_LINE_SIZE-1) { + /* As we don't buffer incoming data, if IRC_LINE_SIZE amount of bytes + * were received, there's a good chance last message was truncated + * and the next recv() will yield garbage. */ + imcb_error(ic, "Unable to handle incoming data from skyped"); + st = 0; + } if (st > 0) { buf[st] = '\0'; /* Then split it up to lines. */ -- cgit v1.2.3 From 33ed4558048f8dd5a29275658b3d1892b7b4dd74 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Sat, 16 Feb 2013 14:23:11 +0100 Subject: skype: rename these tests, these are about we are added, not about we add --- protocols/skype/t/add-no-bitlbee.mock | 9 --------- protocols/skype/t/add-no-skyped.mock | 13 ------------- protocols/skype/t/add-yes-bitlbee.mock | 9 --------- protocols/skype/t/add-yes-skyped.mock | 23 ----------------------- protocols/skype/t/added-no-bitlbee.mock | 9 +++++++++ protocols/skype/t/added-no-skyped.mock | 13 +++++++++++++ protocols/skype/t/added-yes-bitlbee.mock | 9 +++++++++ protocols/skype/t/added-yes-skyped.mock | 23 +++++++++++++++++++++++ protocols/skype/test.py | 8 ++++---- 9 files changed, 58 insertions(+), 58 deletions(-) delete mode 100644 protocols/skype/t/add-no-bitlbee.mock delete mode 100644 protocols/skype/t/add-no-skyped.mock delete mode 100644 protocols/skype/t/add-yes-bitlbee.mock delete mode 100644 protocols/skype/t/add-yes-skyped.mock create mode 100644 protocols/skype/t/added-no-bitlbee.mock create mode 100644 protocols/skype/t/added-no-skyped.mock create mode 100644 protocols/skype/t/added-yes-bitlbee.mock create mode 100644 protocols/skype/t/added-yes-skyped.mock (limited to 'protocols') diff --git a/protocols/skype/t/add-no-bitlbee.mock b/protocols/skype/t/add-no-bitlbee.mock deleted file mode 100644 index d7a70c66..00000000 --- a/protocols/skype/t/add-no-bitlbee.mock +++ /dev/null @@ -1,9 +0,0 @@ ->> NOTICE AUTH -<< NICK alice -<< USER alice alice localhost :Alice ->> PRIVMSG &bitlbee -<< PRIVMSG &bitlbee :account add skype alice foo -<< PRIVMSG &bitlbee :account skype on ->> PRIVMSG &bitlbee :skype - New request: The user bob wants to add you -<< PRIVMSG &bitlbee :no ->> PRIVMSG &bitlbee :skype - Rejected diff --git a/protocols/skype/t/add-no-skyped.mock b/protocols/skype/t/add-no-skyped.mock deleted file mode 100644 index f7283cbc..00000000 --- a/protocols/skype/t/add-no-skyped.mock +++ /dev/null @@ -1,13 +0,0 @@ ->> SEARCH GROUPS CUSTOM -<< GROUPS 48, 49 ->> SEARCH FRIENDS -<< USERS echo123 ->> SET USERSTATUS ONLINE -<< USERSTATUS ONLINE ->> SET USERSTATUS ONLINE -<< USERSTATUS ONLINE ->> GET USER echo123 ONLINESTATUS -<< USER echo123 ONLINESTATUS ONLINE -<< USER bob RECEIVEDAUTHREQUEST Please allow me to see when you are online ->> SET USER bob ISAUTHORIZED FALSE -<< USER bob ISAUTHORIZED FALSE diff --git a/protocols/skype/t/add-yes-bitlbee.mock b/protocols/skype/t/add-yes-bitlbee.mock deleted file mode 100644 index df068f89..00000000 --- a/protocols/skype/t/add-yes-bitlbee.mock +++ /dev/null @@ -1,9 +0,0 @@ ->> NOTICE AUTH -<< NICK alice -<< USER alice alice localhost :Alice ->> PRIVMSG &bitlbee -<< PRIVMSG &bitlbee :account add skype alice foo -<< PRIVMSG &bitlbee :account skype on ->> PRIVMSG &bitlbee :skype - New request: The user bob wants to add you -<< PRIVMSG &bitlbee :yes ->> :bob!bob@skype.com JOIN :&bitlbee diff --git a/protocols/skype/t/add-yes-skyped.mock b/protocols/skype/t/add-yes-skyped.mock deleted file mode 100644 index e22beb97..00000000 --- a/protocols/skype/t/add-yes-skyped.mock +++ /dev/null @@ -1,23 +0,0 @@ ->> SEARCH GROUPS CUSTOM -<< GROUPS 48, 49 ->> SEARCH FRIENDS -<< USERS echo123 ->> SET USERSTATUS ONLINE -<< USERSTATUS ONLINE ->> SET USERSTATUS ONLINE -<< USERSTATUS ONLINE ->> GET USER echo123 ONLINESTATUS -<< USER echo123 ONLINESTATUS ONLINE -<< USER bob RECEIVEDAUTHREQUEST Please allow me to see when you are online ->> SET USER bob ISAUTHORIZED TRUE -<< USER bob ISAUTHORIZED TRUE -<< USER bob RECEIVEDAUTHREQUEST -<< USER bob ISAUTHORIZED TRUE -<< USER bob ISBLOCKED FALSE -<< USER bob BUDDYSTATUS 3 -<< USER bob ONLINESTATUS OFFLINE -<< USER bob ONLINESTATUS ONLINE -<< USER bob TIMEZONE 90000 -<< USER bob FULLNAME Miklos V -<< USER bob LANGUAGE hu Hungarian -<< USER bob COUNTRY hu Hungary diff --git a/protocols/skype/t/added-no-bitlbee.mock b/protocols/skype/t/added-no-bitlbee.mock new file mode 100644 index 00000000..d7a70c66 --- /dev/null +++ b/protocols/skype/t/added-no-bitlbee.mock @@ -0,0 +1,9 @@ +>> NOTICE AUTH +<< NICK alice +<< USER alice alice localhost :Alice +>> PRIVMSG &bitlbee +<< PRIVMSG &bitlbee :account add skype alice foo +<< PRIVMSG &bitlbee :account skype on +>> PRIVMSG &bitlbee :skype - New request: The user bob wants to add you +<< PRIVMSG &bitlbee :no +>> PRIVMSG &bitlbee :skype - Rejected diff --git a/protocols/skype/t/added-no-skyped.mock b/protocols/skype/t/added-no-skyped.mock new file mode 100644 index 00000000..f7283cbc --- /dev/null +++ b/protocols/skype/t/added-no-skyped.mock @@ -0,0 +1,13 @@ +>> SEARCH GROUPS CUSTOM +<< GROUPS 48, 49 +>> SEARCH FRIENDS +<< USERS echo123 +>> SET USERSTATUS ONLINE +<< USERSTATUS ONLINE +>> SET USERSTATUS ONLINE +<< USERSTATUS ONLINE +>> GET USER echo123 ONLINESTATUS +<< USER echo123 ONLINESTATUS ONLINE +<< USER bob RECEIVEDAUTHREQUEST Please allow me to see when you are online +>> SET USER bob ISAUTHORIZED FALSE +<< USER bob ISAUTHORIZED FALSE diff --git a/protocols/skype/t/added-yes-bitlbee.mock b/protocols/skype/t/added-yes-bitlbee.mock new file mode 100644 index 00000000..df068f89 --- /dev/null +++ b/protocols/skype/t/added-yes-bitlbee.mock @@ -0,0 +1,9 @@ +>> NOTICE AUTH +<< NICK alice +<< USER alice alice localhost :Alice +>> PRIVMSG &bitlbee +<< PRIVMSG &bitlbee :account add skype alice foo +<< PRIVMSG &bitlbee :account skype on +>> PRIVMSG &bitlbee :skype - New request: The user bob wants to add you +<< PRIVMSG &bitlbee :yes +>> :bob!bob@skype.com JOIN :&bitlbee diff --git a/protocols/skype/t/added-yes-skyped.mock b/protocols/skype/t/added-yes-skyped.mock new file mode 100644 index 00000000..e22beb97 --- /dev/null +++ b/protocols/skype/t/added-yes-skyped.mock @@ -0,0 +1,23 @@ +>> SEARCH GROUPS CUSTOM +<< GROUPS 48, 49 +>> SEARCH FRIENDS +<< USERS echo123 +>> SET USERSTATUS ONLINE +<< USERSTATUS ONLINE +>> SET USERSTATUS ONLINE +<< USERSTATUS ONLINE +>> GET USER echo123 ONLINESTATUS +<< USER echo123 ONLINESTATUS ONLINE +<< USER bob RECEIVEDAUTHREQUEST Please allow me to see when you are online +>> SET USER bob ISAUTHORIZED TRUE +<< USER bob ISAUTHORIZED TRUE +<< USER bob RECEIVEDAUTHREQUEST +<< USER bob ISAUTHORIZED TRUE +<< USER bob ISBLOCKED FALSE +<< USER bob BUDDYSTATUS 3 +<< USER bob ONLINESTATUS OFFLINE +<< USER bob ONLINESTATUS ONLINE +<< USER bob TIMEZONE 90000 +<< USER bob FULLNAME Miklos V +<< USER bob LANGUAGE hu Hungarian +<< USER bob COUNTRY hu Hungary diff --git a/protocols/skype/test.py b/protocols/skype/test.py index b3f25f46..78f75bb1 100755 --- a/protocols/skype/test.py +++ b/protocols/skype/test.py @@ -94,11 +94,11 @@ class Test(unittest.TestCase): def testCallFailed(self): self.mock("call-failed") - def testAddYes(self): - self.mock("add-yes") + def testAddedYes(self): + self.mock("added-yes") - def testAddNo(self): - self.mock("add-no") + def testAddedNo(self): + self.mock("added-no") def testGroupchatInvited(self): self.mock("groupchat-invited") -- cgit v1.2.3 From 3bf9f715e80169d117c6f63b273639f91b985ea5 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Sat, 16 Feb 2013 14:27:45 +0100 Subject: skyped: print again the config file path --- protocols/skype/skyped.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'protocols') diff --git a/protocols/skype/skyped.py b/protocols/skype/skyped.py index 19de51aa..cb57b7ec 100644 --- a/protocols/skype/skyped.py +++ b/protocols/skype/skyped.py @@ -485,7 +485,7 @@ def main(args=None): pass if not options.port: options.port = port - dprint("Parsing config file '%s' done, username is '%s'." % (options.config, options.config.username)) + dprint("Parsing config file '%s' done, username is '%s'." % (cfgpath, options.config.username)) if not options.nofork: pid = os.fork() if pid == 0: -- cgit v1.2.3 From 78e103e7e5c1d58a59d65a4e90cd5f9fbee92cee Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Sat, 16 Feb 2013 14:33:46 +0100 Subject: test skype_add_buddy() --- protocols/skype/t/add-yes-bitlbee.mock | 8 ++++++++ protocols/skype/t/add-yes-skyped.mock | 21 +++++++++++++++++++++ protocols/skype/test.py | 3 +++ 3 files changed, 32 insertions(+) create mode 100644 protocols/skype/t/add-yes-bitlbee.mock create mode 100644 protocols/skype/t/add-yes-skyped.mock (limited to 'protocols') diff --git a/protocols/skype/t/add-yes-bitlbee.mock b/protocols/skype/t/add-yes-bitlbee.mock new file mode 100644 index 00000000..5f17fd33 --- /dev/null +++ b/protocols/skype/t/add-yes-bitlbee.mock @@ -0,0 +1,8 @@ +>> NOTICE AUTH +<< NICK alice +<< USER alice alice localhost :Alice +>> PRIVMSG &bitlbee +<< PRIVMSG &bitlbee :account add skype alice foo +<< PRIVMSG &bitlbee :account skype on +<< PRIVMSG &bitlbee :add skype bob +>> :bob!bob@skype.com JOIN :&bitlbee diff --git a/protocols/skype/t/add-yes-skyped.mock b/protocols/skype/t/add-yes-skyped.mock new file mode 100644 index 00000000..eed257e5 --- /dev/null +++ b/protocols/skype/t/add-yes-skyped.mock @@ -0,0 +1,21 @@ +>> SEARCH GROUPS CUSTOM +<< GROUPS 48, 49 +>> SEARCH FRIENDS +<< USERS echo123 +>> SET USERSTATUS ONLINE +<< USERSTATUS ONLINE +>> SET USERSTATUS ONLINE +<< USERSTATUS ONLINE +>> GET USER echo123 ONLINESTATUS +<< USER echo123 ONLINESTATUS ONLINE +>> SET USER bob BUDDYSTATUS 2 Please authorize me +<< USER bob BUDDYSTATUS 2 +<< USER bob ISAUTHORIZED TRUE +<< USER bob ISBLOCKED FALSE +<< USER bob BUDDYSTATUS 2 +<< USER bob ONLINESTATUS OFFLINE +<< USER bob FULLNAME skype test203 +<< USER bob BUDDYSTATUS 3 +<< USER bob ONLINESTATUS OFFLINE +<< USER bob ONLINESTATUS ONLINE +<< USER bob TIMEZONE 90000 diff --git a/protocols/skype/test.py b/protocols/skype/test.py index 78f75bb1..6c967ed2 100755 --- a/protocols/skype/test.py +++ b/protocols/skype/test.py @@ -94,6 +94,9 @@ class Test(unittest.TestCase): def testCallFailed(self): self.mock("call-failed") + def testAddYes(self): + self.mock("add-yes") + def testAddedYes(self): self.mock("added-yes") -- cgit v1.2.3 From c7336baf84c5122bc8377c7a5e836152187bb5cb Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Sat, 16 Feb 2013 15:03:56 +0100 Subject: skype_buddy_action_list: fix missing hangup in help output --- protocols/skype/skype.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'protocols') diff --git a/protocols/skype/skype.c b/protocols/skype/skype.c index 963406db..94f71965 100644 --- a/protocols/skype/skype.c +++ b/protocols/skype/skype.c @@ -1590,12 +1590,14 @@ GList *skype_buddy_action_list(bee_user_t *bu) bu = bu; if (ret == NULL) { - static const struct buddy_action ba[3] = { + static const struct buddy_action ba[2] = { {"CALL", "Initiate a call" }, {"HANGUP", "Hang up a call" }, }; + int i; - ret = g_list_prepend(ret, (void *) ba + 0); + for (i = 0; i < ARRAY_SIZE(ba); i++) + ret = g_list_prepend(ret, (void *)(ba + i)); } return ret; -- cgit v1.2.3 From 3a920204f1bbeadf4971530ee91514b89652610b Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Sun, 17 Feb 2013 14:06:51 +0100 Subject: test skype_buddy_action_list() --- protocols/skype/t/ctcp-help-bitlbee.mock | 9 +++++++++ protocols/skype/t/ctcp-help-skyped.mock | 12 ++++++++++++ protocols/skype/test.py | 3 +++ 3 files changed, 24 insertions(+) create mode 100644 protocols/skype/t/ctcp-help-bitlbee.mock create mode 100644 protocols/skype/t/ctcp-help-skyped.mock (limited to 'protocols') diff --git a/protocols/skype/t/ctcp-help-bitlbee.mock b/protocols/skype/t/ctcp-help-bitlbee.mock new file mode 100644 index 00000000..98522ec1 --- /dev/null +++ b/protocols/skype/t/ctcp-help-bitlbee.mock @@ -0,0 +1,9 @@ +>> NOTICE AUTH +<< NICK alice +<< USER alice alice localhost :Alice +>> PRIVMSG &bitlbee +<< PRIVMSG &bitlbee :account add skype alice foo +<< PRIVMSG &bitlbee :account skype on +>> :bob!bob@skype.com JOIN :&bitlbee +<< PRIVMSG bob :HELP +>> :bob!bob@skype.com NOTICE alice :HELP Supported CTCPs: HANGUP (Hang up a call), CALL (Initiate a call) diff --git a/protocols/skype/t/ctcp-help-skyped.mock b/protocols/skype/t/ctcp-help-skyped.mock new file mode 100644 index 00000000..322c7c6b --- /dev/null +++ b/protocols/skype/t/ctcp-help-skyped.mock @@ -0,0 +1,12 @@ +>> SEARCH GROUPS CUSTOM +<< GROUPS 48, 49 +>> SEARCH FRIENDS +<< USERS echo123, bob +>> SET USERSTATUS ONLINE +<< USERSTATUS ONLINE +>> SET USERSTATUS ONLINE +<< USERSTATUS ONLINE +>> GET USER echo123 ONLINESTATUS +<< USER echo123 ONLINESTATUS ONLINE +>> GET USER bob ONLINESTATUS +<< USER bob ONLINESTATUS ONLINE diff --git a/protocols/skype/test.py b/protocols/skype/test.py index 6c967ed2..9f92f252 100755 --- a/protocols/skype/test.py +++ b/protocols/skype/test.py @@ -121,5 +121,8 @@ class Test(unittest.TestCase): def testGroupRead(self): self.mock("group-read") + def testCtcpHelp(self): + self.mock("ctcp-help") + if __name__ == '__main__': unittest.main() -- cgit v1.2.3 From 130f7b85cf0d75da8dbb98df6d52595fe24c65c9 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Sun, 17 Feb 2013 20:51:11 +0100 Subject: test skype_set_mood_text() --- protocols/skype/t/set-mood-text-bitlbee.mock | 9 +++++++++ protocols/skype/t/set-mood-text-skyped.mock | 12 ++++++++++++ protocols/skype/test.py | 3 +++ 3 files changed, 24 insertions(+) create mode 100644 protocols/skype/t/set-mood-text-bitlbee.mock create mode 100644 protocols/skype/t/set-mood-text-skyped.mock (limited to 'protocols') diff --git a/protocols/skype/t/set-mood-text-bitlbee.mock b/protocols/skype/t/set-mood-text-bitlbee.mock new file mode 100644 index 00000000..f017f8bd --- /dev/null +++ b/protocols/skype/t/set-mood-text-bitlbee.mock @@ -0,0 +1,9 @@ +>> NOTICE AUTH +<< NICK alice +<< USER alice alice localhost :Alice +>> PRIVMSG &bitlbee +<< PRIVMSG &bitlbee :account add skype alice foo +<< PRIVMSG &bitlbee :account skype set skypeconsole_receive true +<< PRIVMSG &bitlbee :account skype on +<< PRIVMSG &bitlbee :account skype set mood_text "foo bar" +>> PRIVMSG &bitlbee :alice: PROFILE MOOD_TEXT foo bar diff --git a/protocols/skype/t/set-mood-text-skyped.mock b/protocols/skype/t/set-mood-text-skyped.mock new file mode 100644 index 00000000..f2814248 --- /dev/null +++ b/protocols/skype/t/set-mood-text-skyped.mock @@ -0,0 +1,12 @@ +>> SEARCH GROUPS CUSTOM +<< GROUPS 48, 49 +>> SEARCH FRIENDS +<< USERS echo123 +>> SET USERSTATUS ONLINE +<< USERSTATUS ONLINE +>> SET USERSTATUS ONLINE +<< USERSTATUS ONLINE +>> GET USER echo123 ONLINESTATUS +<< USER echo123 ONLINESTATUS ONLINE +>> SET PROFILE MOOD_TEXT foo bar +<< PROFILE MOOD_TEXT foo bar diff --git a/protocols/skype/test.py b/protocols/skype/test.py index 9f92f252..ab90c955 100755 --- a/protocols/skype/test.py +++ b/protocols/skype/test.py @@ -124,5 +124,8 @@ class Test(unittest.TestCase): def testCtcpHelp(self): self.mock("ctcp-help") + def testSetMoodText(self): + self.mock("set-mood-text") + if __name__ == '__main__': unittest.main() -- cgit v1.2.3 From 94d9511f4e834f6082c2eadf6d1d35a65d162155 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Sun, 17 Feb 2013 20:51:11 +0100 Subject: skype tests: run all tests with a single skyped config This makes them a bit faster, and there is no need to have separate skyped configs for each test ATM. --- protocols/skype/test.py | 57 +++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 28 deletions(-) (limited to 'protocols') diff --git a/protocols/skype/test.py b/protocols/skype/test.py index ab90c955..632ae124 100755 --- a/protocols/skype/test.py +++ b/protocols/skype/test.py @@ -8,14 +8,35 @@ import shutil import os import hashlib +def openssl(args): + with open(os.devnull, "w") as devnull: + proc = subprocess.Popen(['openssl'] + args, stdin=subprocess.PIPE, stderr=devnull) + for i in range(6): + proc.stdin.write("\n") + proc.stdin.close() + proc.communicate() +def setupSkyped(): + try: + shutil.rmtree("t/skyped") + except OSError: + pass + os.makedirs("t/skyped") + cwd = os.getcwd() + os.chdir("t/skyped") + try: + shutil.copyfile("../../skyped.cnf", "skyped.cnf") + openssl(['req', '-new', '-x509', '-days', '365', '-nodes', '-config', 'skyped.cnf', '-out', 'skyped.cert.pem', '-keyout', 'skyped.key.pem']) + with open("skyped.conf", "w") as sock: + sock.write("[skyped]\n") + sock.write("username = alice\n") + sock.write("password = %s\n" % hashlib.sha1("foo").hexdigest()) + sock.write("cert = %s/skyped.cert.pem\n" % os.getcwd()) + sock.write("key = %s/skyped.key.pem\n" % os.getcwd()) + sock.write("port = 2727\n") + finally: + os.chdir(cwd) + class Test(unittest.TestCase): - def openssl(self, args): - with open(os.devnull, "w") as devnull: - proc = subprocess.Popen(['openssl'] + args, stdin=subprocess.PIPE, stderr=devnull) - for i in range(6): - proc.stdin.write("\n") - proc.stdin.close() - proc.communicate() def mock(self, name): with open("t/skyped.log", "w") as skyped_log,\ open("t/pexpect.log", "w") as pexpect_log: @@ -58,27 +79,6 @@ class Test(unittest.TestCase): pass os.makedirs("t/bitlbee") - try: - shutil.rmtree("t/skyped") - except OSError: - pass - os.makedirs("t/skyped") - cwd = os.getcwd() - os.chdir("t/skyped") - try: - shutil.copyfile("../../skyped.cnf", "skyped.cnf") - self.openssl(['req', '-new', '-x509', '-days', '365', '-nodes', '-config', 'skyped.cnf', '-out', 'skyped.cert.pem', '-keyout', 'skyped.key.pem']) - with open("skyped.conf", "w") as sock: - sock.write("[skyped]\n") - sock.write("username = alice\n") - sock.write("password = %s\n" % hashlib.sha1("foo").hexdigest()) - sock.write("cert = %s/skyped.cert.pem\n" % os.getcwd()) - sock.write("key = %s/skyped.key.pem\n" % os.getcwd()) - sock.write("port = 2727\n") - finally: - os.chdir(cwd) - - def testMsg(self): self.mock("msg") @@ -128,4 +128,5 @@ class Test(unittest.TestCase): self.mock("set-mood-text") if __name__ == '__main__': + setupSkyped() unittest.main() -- cgit v1.2.3 From 9754c2fd0e4dbe65e13878b947091483bfff102a Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Mon, 18 Feb 2013 09:42:30 +0100 Subject: Clean up set_my_name API implementations --- protocols/skype/skype.c | 6 ------ protocols/twitter/twitter.c | 8 -------- 2 files changed, 14 deletions(-) (limited to 'protocols') diff --git a/protocols/skype/skype.c b/protocols/skype/skype.c index 94f71965..4ae34668 100644 --- a/protocols/skype/skype.c +++ b/protocols/skype/skype.c @@ -1529,11 +1529,6 @@ static void skype_get_info(struct im_connection *ic, char *who) skype_printf(ic, "GET USER %s BIRTHDAY\n", nick); } -static void skype_set_my_name(struct im_connection *ic, char *info) -{ - skype_set_display_name(set_find(&ic->acc->set, "display_name"), info); -} - static void skype_init(account_t *acc) { set_t *s; @@ -1628,7 +1623,6 @@ void init_plugin(void) ret->logout = skype_logout; ret->buddy_msg = skype_buddy_msg; ret->get_info = skype_get_info; - ret->set_my_name = skype_set_my_name; ret->away_states = skype_away_states; ret->set_away = skype_set_away; ret->add_buddy = skype_add_buddy; diff --git a/protocols/twitter/twitter.c b/protocols/twitter/twitter.c index 8d437ed1..e48df2ed 100644 --- a/protocols/twitter/twitter.c +++ b/protocols/twitter/twitter.c @@ -469,13 +469,6 @@ static int twitter_buddy_msg(struct im_connection *ic, char *who, char *message, return (0); } -/** - * - */ -static void twitter_set_my_name(struct im_connection *ic, char *info) -{ -} - static void twitter_get_info(struct im_connection *ic, char *who) { } @@ -733,7 +726,6 @@ void twitter_initmodule() ret->logout = twitter_logout; ret->buddy_msg = twitter_buddy_msg; ret->get_info = twitter_get_info; - ret->set_my_name = twitter_set_my_name; ret->add_buddy = twitter_add_buddy; ret->remove_buddy = twitter_remove_buddy; ret->chat_msg = twitter_chat_msg; -- cgit v1.2.3