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