]>
Commit | Line | Data |
---|---|---|
e3aced8e MM |
1 | # vi: encoding=utf-8 ts=8 sts=4 sw=4 et |
2 | ||
3 | import socket | |
4 | import os | |
5 | import select | |
6 | from common import fileexists | |
7 | import ftpio | |
8 | import cmds | |
9 | ||
10 | class Connection: | |
11 | def __init__(self, sock, authorized): | |
12 | sock.setblocking(False) | |
13 | self.sock=sock | |
14 | self.authorized=authorized | |
15 | self.fileno=sock.fileno | |
b55905f2 | 16 | self.name="" |
e3aced8e MM |
17 | self.data="" |
18 | def destroy(self): | |
19 | self.sock.close() | |
20 | rm(self) | |
21 | def handleinput(self): | |
22 | newdata=self.sock.recv(8192) | |
23 | if not newdata: | |
24 | self.destroy() | |
25 | self.data=self.data+newdata | |
26 | try: | |
27 | cmds.parse(self) | |
28 | except cmds.CmdError: | |
29 | self.destroy() | |
30 | ||
31 | def add(con): | |
32 | cons.append(con) | |
33 | ||
34 | def rm(con): | |
35 | cons.remove(con) | |
36 | ||
37 | def readables(): | |
38 | lst=cons[:] | |
39 | lst.append(privlistener) | |
40 | lst.append(publistener) | |
41 | inlst,outlst,errlst = select.select(lst, [], [], 0) | |
42 | return inlst | |
43 | ||
44 | def createlistener(path): | |
45 | if fileexists(path): | |
46 | os.remove(path) | |
47 | ||
48 | s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | |
49 | s.setblocking(False) | |
50 | s.bind(path) | |
51 | if path==ftpio.pubsock: | |
52 | os.chmod(path, 0606) | |
53 | else: | |
54 | os.chmod(path, 0600) | |
55 | s.listen(3) | |
56 | return s | |
57 | ||
58 | cons=[] | |
59 | ||
60 | privlistener=createlistener(ftpio.privsock) | |
61 | publistener=createlistener(ftpio.pubsock) | |
62 | ||
63 | ||
64 |