/usr/bin/xtalk is in xtalk 1.3-15.3.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 | #!/usr/bin/python
######################################################################
# XTalk - A BSD talk client written in Python.
# (C) Adam P. Jenkins <adampjenkins@yahoo.com>
#
# 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., 675 Mass Ave, Cambridge, MA 02139, USA.
#
######################################################################
import sys
sys.path.append('/usr/share/xtalk')
from socket import *
SocketError = error
from Tkinter import *
from ScrolledText import ScrolledText
import TalkdInter, string, re, errno
versionMajor = 1
versionMinor = 3
# set to 1 to swap BackSpace and Delete keybindings in edit widgets.
swapBsDel = 0
class Talk(Frame):
# used to raise exceptions
error = 'TalkError'
def __init__(self, parent=None, addr=None):
self.sock = None
self.afterId = None
self.servSock = None
self.talkd = None
Frame.__init__(self, parent)
self.pack(fill=BOTH, expand=TRUE)
self.makeControls()
self.makeEdits()
self.buttons.var.set(addr)
self.status = Label(self, relief=SUNKEN)
self.status.pack(side=TOP, fill=X, expand=FALSE)
self.buttons.address.focus()
##### callback functions
def quit(self):
self.disconnect()
Frame.quit(self)
def connect(self, event=None):
try:
address = self.parseAddress(self.buttons.var.get())
except Talk.error, msg:
self.status['text'] = msg
return
# Disable "connect" event handler, enable disconnect
self.buttons.address.unbind('<Return>')
self.buttons.connect.config(state=DISABLED)
self.buttons.disconnect.config(state=NORMAL)
self.status['text'] = "Making connection to '%s@%s %s'" % \
(address[1], address[0], address[2])
self.update_idletasks()
apply(self.makeConnection, address)
def disconnect(self):
self.cleanup()
self.status['text'] = "Disconnected"
##### Functions to create the GUI
def makeControls(self):
self.buttons = Frame(self, relief=RAISED)
self.buttons.pack(side=TOP, fill=X)
self.buttons.quit = Button(self.buttons, text='Quit',
command=self.quit)
self.buttons.quit.pack(side=LEFT, padx=2, pady=2)
self.buttons.connect = Button(self.buttons, text='Connect',
command=self.connect)
self.buttons.connect.pack(side=LEFT, padx=2, pady=2)
self.buttons.disconnect = Button(self.buttons, text='Disconnect',
command=self.disconnect,
state=DISABLED)
self.buttons.disconnect.pack(side=LEFT, padx=2, pady=2)
self.buttons.lab = Label(self.buttons, text='Address')
self.buttons.lab.pack(side=LEFT)
self.buttons.var = StringVar()
self.buttons.address = Entry(self.buttons, textvariable=self.buttons.var)
self.buttons.address.pack(side=LEFT, fill=X, expand=TRUE)
self.buttons.address.bind('<Return>', self.connect)
def makeEdits(self):
self.edit = Frame(self, relief=RAISED)
self.edit.pack(side=TOP, fill=BOTH, expand=TRUE)
self.edit.local = ScrolledText(self.edit, wrap=WORD, width=80,
height=12, state=DISABLED)
self.edit.remote = ScrolledText(self.edit, wrap=WORD, width=80,
height=12, state=DISABLED)
self.edit.local.pack(side=TOP, fill=BOTH, expand=TRUE, pady=2)
self.edit.remote.pack(side=TOP, fill=BOTH, expand=TRUE, pady=2)
if swapBsDel:
bscmd = self.tk.call('bind', 'Text', '<Key-BackSpace>')
dlcmd = self.tk.call('bind', 'Text', '<Key-Delete>')
self.tk.call('bind', 'Text', '<Key-BackSpace>', dlcmd)
self.tk.call('bind', 'Text', '<Key-Delete>', bscmd)
##### Implementation
def parseAddress(self, addr):
# parses a an address as entered by a user, and returns a
# tuple (remote-host, remote-user, remote-tty) or raises a
# Talk.error exception if there's an error in address.
#rx = re.compile("\(^[^ \t@]+\)\(@\([^ \t@]+\)\)?\([ \t]+\(\w+\)\)?$")
ruatty = string.split(addr)
rua = ruatty[0]
if len(ruatty)>1:
rtty = ruatty[1]
else:
rtty = ''
#if rx.match(string.strip(addr)) > 0:
# ruser, rhost, rtty = rx.group(1, 3, 5)
# if not rhost:
# rhost = 'localhost'
# if not rtty:
# rtty = ''
# return (rhost, ruser, rtty)
ruh = string.split(rua, '@')
ruser = ruh[0]
if len(ruh)>1:
rhost = ruh[1]
else:
rhost = 'localhost'
if ruser:
return (rhost, ruser, rtty)
else:
raise Talk.error, "Bad address format given."
def cleanup(self):
if self.afterId:
self.after_cancel(self.afterId)
self.afterId = None
if self.talkd:
try:
self.talkd.deleteInvite('mine')
self.talkd.deleteInvite('his')
except TalkdInter.error, msg:
pass
self.talkd = None
if self.servSock:
self.tk.deletefilehandler(self.servSock)
self.servSock.close()
self.servSock = None
if self.sock:
self.tk.deletefilehandler(self.sock)
self.edit.local.config(state=DISABLED)
self.edit.local.unbind('<Key>')
# unset paste handling in local window
for e in ['<Button-2>', '<Control-y>']:
self.edit.local.unbind(e)
self.sock.close()
self.sock = None
# enable "connect" event handler, disable disconnect
self.buttons.address.bind('<Return>', self.connect)
self.buttons.connect.config(state=NORMAL)
self.buttons.disconnect.config(state=DISABLED)
def makeConnection(self, rhost, ruser, rtty):
try:
self.talkd = TalkdInter.TalkdInter(rhost, ruser, rtty)
self.status['text'] = "Checking for invite..."
self.update_idletasks()
try:
raddr = self.talkd.lookUp()
except TalkdInter.error, msg:
raddr = None
if raddr:
self.status['text'] = "Found invitation. connecting..."
self.update_idletasks()
self.sock = socket(AF_INET, SOCK_STREAM)
self.sock.connect(raddr)
self.status['text'] = "Connected to " + `raddr`
self.update_idletasks()
self.setupIO()
return
self.servSock = socket(AF_INET, SOCK_STREAM)
self.servSock.bind((gethostname(), 0))
myaddr = self.servSock.getsockname()
self.servSock.listen(1)
self.talkd.leaveInvite(myaddr)
self.talkd.announce()
except (TalkdInter.error, SocketError), err:
self.status['text'] = err
self.cleanup()
return
self.status['text'] = "Ringing remote party..."
self.numTries = 1
self.tk.createfilehandler(self.servSock, tkinter.READABLE,
self.acceptConnection)
# announce again after 30 seconds
self.afterId = self.after(30000, self.announceAgain)
def announceAgain(self):
try:
self.talkd.announce()
self.talkd.leaveInvite(self.servSock.getsockname())
except TalkdInter.error, msg:
self.status['text'] = msg
self.cleanup()
return
self.numTries = self.numTries + 1
self.status['text'] = "Ringing remote party, try " + `self.numTries`
self.afterId = self.after(30000, self.announceAgain)
def acceptConnection(self, file, mask):
acc = self.servSock.accept()
self.status['text'] = "Accepted connection from " + `acc[1]`
self.tk.deletefilehandler(self.servSock)
self.sock = acc[0]
self.servSock.close()
self.servSock = None
try:
self.talkd.deleteInvite('mine')
self.talkd.deleteInvite('his')
except TalkdInter.error, msg:
pass
self.talkd = None
self.setupIO()
def setupIO(self):
self.bell()
if self.afterId:
self.after_cancel(self.afterId)
self.afterId = None
# exchange edit chars. The edit chars are supposed to be
# 1) erase, i.e. backspace, Text widget uses \010
# 2) kill, not sure, think it's delete current line
# 3) wkill, not sure, think it's delete to beginning of word.
if swapBsDel:
self.sock.send('\177\0\0')
else:
self.sock.send('\010\0\0')
self.editChars = self.sock.recv(3)
self.tk.createfilehandler(self.sock, tkinter.READABLE,
self.handleRemoteInput)
self.sock.setblocking(0)
self.edit.local.config(state=NORMAL)
self.edit.remote.config(state=NORMAL)
# clear both edit windows
self.edit.local.delete('1.0', END)
self.edit.remote.delete('1.0', END)
self.edit.remote.config(state=DISABLED)
self.edit.local.bind('<Key>', self.handleLocalInput)
# set up paste handling in local window
for e in ['<Button-2>', '<Control-y>']:
self.edit.local.bind(e, self.handlePaste)
self.edit.local.focus()
def handleRemoteInput(self, file, mask):
try:
inp = self.sock.recv(80)
except SocketError, err:
if err[0] != errno.EWOULDBLOCK:
print err[1]
self.disconnect()
return
if not inp:
self.disconnect()
return
self.edit.remote.config(state=NORMAL)
for c in inp:
if c == self.editChars[0]:
self.edit.remote.delete("end - 2 char")
else:
self.edit.remote.insert(END, c)
self.edit.remote.see(END)
self.edit.remote.config(state=DISABLED)
def handleLocalInput(self, event):
c = event.char
if c == '':
return
if c == '\015':
c = '\012'
try:
self.sock.send(c)
except SocketError, err:
if err[0] != errno.EWOULDBLOCK:
print err[1]
self.disconnect()
def handlePaste(self, event):
try:
p = self.selection_get()
except TclError:
return
if len(p) == 0:
return
self.edit.local.see(END)
try:
self.sock.send(p)
except SocketError, err:
if err[0] != errno.EWOULDBLOCK:
print err[1]
self.disconnect()
def main():
if len(sys.argv) > 1:
if len(sys.argv) >= 3:
addr = "%s %s" % (sys.argv[1], sys.argv[2])
else:
addr = sys.argv[1]
else:
addr = ''
root = Tk(className='XTalk')
opt = string.lower(root.option_get('swapBsDel',''))
if opt == 'true':
swapBsDel = 1
elif opt == 'false':
swapBsDel = 0
elif opt != '':
print 'Warning: unrecognized value for XTalk.swapBsDel: %s' % opt
talk = Talk(None, addr)
talk.winfo_toplevel().title("XTalk %d.%d" % (versionMajor, versionMinor))
talk.mainloop()
if __name__ == '__main__':
main()
|