aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilippe Crama <pcfeb0009@gmx.com>2010-12-17 21:57:04 +0100
committerPhilippe Crama <pcfeb0009@gmx.com>2010-12-17 21:57:04 +0100
commiteeab8bcdb7e7026caca7d695c358599b3fa58022 (patch)
treef567a82bb30c78fcb813681e4ac931c851b01e63
parenta618ea653d159324a9691af06d3da42373f27be9 (diff)
Remove dependency on gobject and use select standard module
This is a restart of the windows-skyped branch based on the updated bitlbee-skype using the builtin SSL libs of Python. This version connects, but hangs for long times... to be continued
-rw-r--r--skype/skyped.py41
1 files changed, 31 insertions, 10 deletions
diff --git a/skype/skyped.py b/skype/skyped.py
index f15245ed..adc3f1c8 100644
--- a/skype/skyped.py
+++ b/skype/skyped.py
@@ -25,7 +25,6 @@ import os
import signal
import locale
import time
-import gobject
import socket
import getopt
import Skype4Py
@@ -33,6 +32,7 @@ import hashlib
from ConfigParser import ConfigParser, NoOptionError
from traceback import print_exception
import ssl
+import select
__version__ = "0.1.1"
@@ -41,7 +41,6 @@ def eh(type, value, tb):
if type != KeyboardInterrupt:
print_exception(type, value, tb)
- gobject.MainLoop().quit()
options.conn.close()
# shut down client if it's running
try:
@@ -93,6 +92,7 @@ def send(sock, txt):
options.conn.close()
def bitlbee_idle_handler(skype):
+ global options
if options.conn:
try:
e = "PING"
@@ -102,15 +102,16 @@ def bitlbee_idle_handler(skype):
options.conn.close()
return True
-def server(host, port):
+def server(host, port, skype):
global options
sock = socket.socket()
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind((host, port))
sock.listen(1)
- gobject.io_add_watch(sock, gobject.IO_IN, listener)
+ dprint("Waiting for connection...")
+ listener(sock, skype)
-def listener(sock, *args):
+def listener(sock, skype):
global options
rawsock, addr = sock.accept()
options.conn = ssl.wrap_socket(rawsock,
@@ -139,7 +140,7 @@ def listener(sock, *args):
if ret == 2:
dprint("Username and password OK.")
options.conn.send("PASSWORD OK\n")
- gobject.io_add_watch(options.conn, gobject.IO_IN, input_handler)
+ serverloop(options, skype)
return True
else:
dprint("Username and/or password WRONG.")
@@ -190,6 +191,7 @@ class SkypeApi:
dprint('<< ' + e)
if options.conn:
try:
+ # I called the send function really_send
send(options.conn, e + "\n")
except Exception, s:
dprint("Warning, sending '%s' failed (%s)." % (e, s))
@@ -252,6 +254,28 @@ Options:
-v --version display version information""" % (self.cfgpath, self.host, self.port)
sys.exit(ret)
+def serverloop(options, skype):
+ timeout = 1; # in seconds
+ skype_ping_period = 5
+ bitlbee_ping_period = 30
+ skype_ping_start_time = time.time()
+ bitlbee_ping_start_time = time.time()
+ while 1:
+ ready_to_read, ready_to_write, in_error = \
+ select.select([options.conn], [], [], timeout)
+ now = time.time()
+ if len(ready_to_read) == 1:
+ input_handler(ready_to_read.pop(), options)
+ # don't ping bitlbee/skype if they already received data
+ bitlbee_ping_start_time = now
+ skype_ping_start_time = now
+ if now - skype_ping_period > skype_ping_start_time:
+ skype_idle_handler(skype)
+ skype_ping_start_time = now
+ if now - bitlbee_ping_period > bitlbee_ping_start_time:
+ bitlbee_idle_handler(skype)
+ bitlbee_ping_start_time = now
+
if __name__=='__main__':
options = Options()
try:
@@ -316,11 +340,8 @@ if __name__=='__main__':
sys.exit(0)
else:
dprint('skyped is started on port %s' % options.port)
- server(options.host, options.port)
try:
skype = SkypeApi()
except Skype4Py.SkypeAPIError, s:
sys.exit("%s. Are you sure you have started Skype?" % s)
- gobject.timeout_add(2000, skype_idle_handler, skype)
- gobject.timeout_add(60000, bitlbee_idle_handler, skype)
- gobject.MainLoop().run()
+ server(options.host, options.port, skype)