]>
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): | |
235da16e | 12 | sock.setblocking(False) |
e3aced8e MM |
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): | |
5b5cb482 MM |
22 | try: |
23 | newdata=self.sock.recv(8192) | |
24 | except: | |
25 | self.destroy() | |
e3aced8e MM |
26 | if not newdata: |
27 | self.destroy() | |
28 | self.data=self.data+newdata | |
29 | try: | |
30 | cmds.parse(self) | |
5fcf3f9a | 31 | except cmds.BailOut: |
e3aced8e MM |
32 | self.destroy() |
33 | ||
34 | def add(con): | |
35 | cons.append(con) | |
36 | ||
37 | def rm(con): | |
38 | cons.remove(con) | |
39 | ||
40 | def readables(): | |
41 | lst=cons[:] | |
42 | lst.append(privlistener) | |
43 | lst.append(publistener) | |
4f276739 | 44 | inlst,outlst,errlst = select.select(lst, [], [], 0.1) |
e3aced8e MM |
45 | return inlst |
46 | ||
47 | def createlistener(path): | |
48 | if fileexists(path): | |
49 | os.remove(path) | |
50 | ||
51 | s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | |
52 | s.setblocking(False) | |
53 | s.bind(path) | |
54 | if path==ftpio.pubsock: | |
55 | os.chmod(path, 0606) | |
56 | else: | |
57 | os.chmod(path, 0600) | |
58 | s.listen(3) | |
59 | return s | |
60 | ||
61 | cons=[] | |
62 | ||
63 | privlistener=createlistener(ftpio.privsock) | |
64 | publistener=createlistener(ftpio.pubsock) | |
65 | ||
66 | ||
67 |