1 | /* |
---|
2 | * Jeti, a Java Jabber client, Copyright (C) 2004 E.S. de Boer |
---|
3 | * |
---|
4 | * This program is free software; you can redistribute it and/or modify |
---|
5 | * it under the terms of the GNU General Public License as published by |
---|
6 | * the Free Software Foundation; either version 2 of the License, or |
---|
7 | * (at your option) any later version. |
---|
8 | * |
---|
9 | * This program is distributed in the hope that it will be useful, |
---|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | * GNU General Public License for more details. |
---|
13 | * |
---|
14 | * You should have received a copy of the GNU General Public License |
---|
15 | * along with this program; if not, write to the Free Software |
---|
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
17 | * |
---|
18 | * For questions, comments etc, |
---|
19 | * use the website at http://jeti.jabberstudio.org |
---|
20 | * or mail me at eric@jeti.tk |
---|
21 | */ |
---|
22 | |
---|
23 | // Created on 28-okt-2004 |
---|
24 | package nu.fw.jeti.plugins.filetransfer.socks5; |
---|
25 | |
---|
26 | import java.util.Iterator; |
---|
27 | import java.util.List; |
---|
28 | |
---|
29 | import nu.fw.jeti.jabber.Backend; |
---|
30 | import nu.fw.jeti.jabber.JID; |
---|
31 | import nu.fw.jeti.jabber.elements.Extension; |
---|
32 | import nu.fw.jeti.jabber.elements.IQExtension; |
---|
33 | import nu.fw.jeti.jabber.elements.InfoQuery; |
---|
34 | import nu.fw.jeti.plugins.filetransfer.GetFileWindow; |
---|
35 | import nu.fw.jeti.plugins.filetransfer.Plugin; |
---|
36 | import nu.fw.jeti.util.Log; |
---|
37 | import nu.fw.jeti.util.Popups; |
---|
38 | |
---|
39 | /** |
---|
40 | * @author E.S. de Boer |
---|
41 | * |
---|
42 | */ |
---|
43 | public class Socks5Extension extends Extension implements IQExtension |
---|
44 | { |
---|
45 | private String sid; |
---|
46 | private JID streamHost; |
---|
47 | private List streamHosts; |
---|
48 | private JID activate; |
---|
49 | |
---|
50 | public Socks5Extension(String sid, JID streamHost, List streamHosts, JID activate) |
---|
51 | { |
---|
52 | this.sid = sid; |
---|
53 | this.streamHost = streamHost; |
---|
54 | this.streamHosts = streamHosts; |
---|
55 | this.activate = activate; |
---|
56 | } |
---|
57 | public Socks5Extension(String sid,List streamhosts) |
---|
58 | { |
---|
59 | this.sid=sid; |
---|
60 | this.streamHosts = streamhosts; |
---|
61 | } |
---|
62 | |
---|
63 | public Socks5Extension(String sid,JID activation) |
---|
64 | { |
---|
65 | this.sid=sid; |
---|
66 | this.activate = activation; |
---|
67 | } |
---|
68 | |
---|
69 | public Socks5Extension(JID streamHost,String sid) |
---|
70 | { |
---|
71 | this.sid=sid; |
---|
72 | this.streamHost = streamHost; |
---|
73 | } |
---|
74 | |
---|
75 | public String getSid() |
---|
76 | { |
---|
77 | return sid; |
---|
78 | } |
---|
79 | |
---|
80 | public JID getStreamHostUsed() |
---|
81 | { |
---|
82 | return streamHost; |
---|
83 | } |
---|
84 | |
---|
85 | public boolean hasStreamHosts() |
---|
86 | { |
---|
87 | return streamHosts!=null; |
---|
88 | } |
---|
89 | |
---|
90 | public Iterator getStreamHosts() |
---|
91 | { |
---|
92 | return streamHosts.iterator(); |
---|
93 | } |
---|
94 | |
---|
95 | public void execute(InfoQuery iq, Backend backend) |
---|
96 | { |
---|
97 | if(iq.getType().equals("set")) |
---|
98 | { |
---|
99 | GetFileWindow w = Plugin.getGetFile(iq.getFrom(),sid); |
---|
100 | if(w==null) Log.xmlReceivedError("Socks stream from unknown"); |
---|
101 | else |
---|
102 | { |
---|
103 | w.startDownloading(new ReceiveSocks5(backend,iq,w)); |
---|
104 | } |
---|
105 | } |
---|
106 | } |
---|
107 | |
---|
108 | public void appendToXML(StringBuffer xml) |
---|
109 | { |
---|
110 | xml.append("<query xmlns= 'http://jabber.org/protocol/bytestreams'"); |
---|
111 | appendAttribute(xml,"sid",sid); |
---|
112 | xml.append(">"); |
---|
113 | appendElement(xml,"activate",activate); |
---|
114 | if(streamHost!=null) |
---|
115 | { |
---|
116 | xml.append("<streamhost-used"); |
---|
117 | appendAttribute(xml,"jid",streamHost); |
---|
118 | xml.append("/>"); |
---|
119 | } |
---|
120 | if(streamHosts!=null) |
---|
121 | { |
---|
122 | for(Iterator i=streamHosts.iterator();i.hasNext();) |
---|
123 | { |
---|
124 | ((StreamHost)i.next()).appendToXML(xml); |
---|
125 | } |
---|
126 | } |
---|
127 | |
---|
128 | xml.append("</query>"); |
---|
129 | } |
---|
130 | } |
---|
131 | /* |
---|
132 | * Overrides for emacs |
---|
133 | * Local variables: |
---|
134 | * tab-width: 4 |
---|
135 | * End: |
---|
136 | */ |
---|