- Timestamp:
- 2010-12-17T20:57:04Z (14 years ago)
- Branches:
- master
- Children:
- 5a54ec8
- Parents:
- a618ea6
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
skype/skyped.py
ra618ea6 reeab8bc 26 26 import locale 27 27 import time 28 import gobject29 28 import socket 30 29 import getopt … … 34 33 from traceback import print_exception 35 34 import ssl 35 import select 36 36 37 37 __version__ = "0.1.1" … … 42 42 if type != KeyboardInterrupt: 43 43 print_exception(type, value, tb) 44 gobject.MainLoop().quit()45 44 options.conn.close() 46 45 # shut down client if it's running … … 94 93 95 94 def bitlbee_idle_handler(skype): 95 global options 96 96 if options.conn: 97 97 try: … … 103 103 return True 104 104 105 def server(host, port ):105 def server(host, port, skype): 106 106 global options 107 107 sock = socket.socket() … … 109 109 sock.bind((host, port)) 110 110 sock.listen(1) 111 gobject.io_add_watch(sock, gobject.IO_IN, listener) 112 113 def listener(sock, *args): 111 dprint("Waiting for connection...") 112 listener(sock, skype) 113 114 def listener(sock, skype): 114 115 global options 115 116 rawsock, addr = sock.accept() … … 140 141 dprint("Username and password OK.") 141 142 options.conn.send("PASSWORD OK\n") 142 gobject.io_add_watch(options.conn, gobject.IO_IN, input_handler)143 serverloop(options, skype) 143 144 return True 144 145 else: … … 191 192 if options.conn: 192 193 try: 194 # I called the send function really_send 193 195 send(options.conn, e + "\n") 194 196 except Exception, s: … … 252 254 -v --version display version information""" % (self.cfgpath, self.host, self.port) 253 255 sys.exit(ret) 256 257 def serverloop(options, skype): 258 timeout = 1; # in seconds 259 skype_ping_period = 5 260 bitlbee_ping_period = 30 261 skype_ping_start_time = time.time() 262 bitlbee_ping_start_time = time.time() 263 while 1: 264 ready_to_read, ready_to_write, in_error = \ 265 select.select([options.conn], [], [], timeout) 266 now = time.time() 267 if len(ready_to_read) == 1: 268 input_handler(ready_to_read.pop(), options) 269 # don't ping bitlbee/skype if they already received data 270 bitlbee_ping_start_time = now 271 skype_ping_start_time = now 272 if now - skype_ping_period > skype_ping_start_time: 273 skype_idle_handler(skype) 274 skype_ping_start_time = now 275 if now - bitlbee_ping_period > bitlbee_ping_start_time: 276 bitlbee_idle_handler(skype) 277 bitlbee_ping_start_time = now 254 278 255 279 if __name__=='__main__': … … 317 341 else: 318 342 dprint('skyped is started on port %s' % options.port) 319 server(options.host, options.port)320 343 try: 321 344 skype = SkypeApi() 322 345 except Skype4Py.SkypeAPIError, s: 323 346 sys.exit("%s. Are you sure you have started Skype?" % s) 324 gobject.timeout_add(2000, skype_idle_handler, skype) 325 gobject.timeout_add(60000, bitlbee_idle_handler, skype) 326 gobject.MainLoop().run() 347 server(options.host, options.port, skype)
Note: See TracChangeset
for help on using the changeset viewer.