3using System.Threading.Tasks;
18 private string hostOverride =
null;
19 private readonly
int port;
54 this.socks5Server =
null;
63 get => this.hostOverride;
64 set => this.hostOverride = value;
81 Xml.Append(
"<identity category='proxy' type='bytestreams' name='SOCKS5 Proxy'/>");
82 return Task.CompletedTask;
85 private async Task QueryGet(
object Sender,
IqEventArgs e)
87 if (!this.socks5Server.
IsOpen)
91 StringBuilder Xml =
new StringBuilder();
93 Xml.Append(
"<query xmlns='");
96 Xml.Append(
"<streamhost host='");
98 if (!
string.IsNullOrEmpty(this.hostOverride))
99 Xml.Append(
XML.
Encode(
this.hostOverride));
101 Xml.Append(
XML.
Encode(
this.Server.Domain));
103 Xml.Append(
"' jid='");
105 Xml.Append(
"' port='");
106 Xml.Append(this.port.ToString());
107 Xml.Append(
"'/></query>");
115 private async Task QuerySet(
object Sender, IqEventArgs e)
122 foreach (XmlNode N
in e.Query.ChildNodes)
124 if (N.LocalName ==
"activate")
132 await e.IqErrorBadRequest(e.To,
"Missing JID.",
"en");
135 string s = Sid + e.From + Jid;
138 if (this.socks5Server.Activate(StreamId))
139 await e.IqResult(
string.Empty, e.To);
141 await e.IqErrorNotAllowed(e.To,
"Stream not active.",
"en");
145 await e.IqErrorForbidden(e.To,
"Account blocked from using SOCKS5.",
"en");
Helps with common XML-related tasks.
static string Attribute(XmlElement E, string Name)
Gets the value of an XML attribute.
static string Encode(string s)
Encodes a string for use in XML.
Base class for components.
void RegisterIqSetHandler(string LocalName, string Namespace, EventHandlerAsync< IqEventArgs > Handler, bool PublishNamespaceAsFeature)
Registers an IQ-Set handler.
CaseInsensitiveString Subdomain
Subdomain name.
void RegisterIqGetHandler(string LocalName, string Namespace, EventHandlerAsync< IqEventArgs > Handler, bool PublishNamespaceAsFeature)
Registers an IQ-Get handler.
XmppServer Server
XMPP Server.
bool UnregisterIqGetHandler(string LocalName, string Namespace, EventHandlerAsync< IqEventArgs > Handler, bool RemoveNamespaceAsFeature)
Unregisters an IQ-Get handler.
bool UnregisterIqSetHandler(string LocalName, string Namespace, EventHandlerAsync< IqEventArgs > Handler, bool RemoveNamespaceAsFeature)
Unregisters an IQ-Set handler.
Event arguments for IQ queries.
XmppAddress From
From address attribute
Task IqResult(string Xml, string From)
Returns a response to the current request.
Task IqErrorNotAllowed(XmppAddress From, string ErrorText, string Language)
Returns a not-allowed error.
XmppAddress To
To address attribute
Task IqErrorForbidden(XmppAddress From, string ErrorText, string Language)
Returns a forbidden error.
Implements SOCKS5 Byte streams support as an XMPP component: https://xmpp.org/extensions/xep-0065....
string HostOverride
Property that can be used to override the host attribute. If external clients needs another host name...
override bool SupportsAccounts
If the component supports accounts (true), or if the subdomain name is the only valid address.
Socks5Component(XmppServer Server, CaseInsensitiveString Subdomain, int Port)
Implements SOCKS5 Byte streams support as an XMPP component: https://xmpp.org/extensions/xep-0065....
const string Socks5Namespace
http://jabber.org/protocol/bytestreams (XEP-0065)
override Task AppendServiceDiscoveryIdentities(StringBuilder Xml, IqEventArgs e, string Node)
Appends component identities, as defined in XEP-0030, to a discovery response.
override void Dispose()
IDisposable.Dispose
void Dispose()
IDisposable.Dispose
bool IsOpen
If the server is open and accepts incoming connections.
CaseInsensitiveString Address
XMPP Address
CaseInsensitiveString BareJid
Bare JID
Represents a case-insensitive string.
static bool IsNullOrEmpty(CaseInsensitiveString value)
Indicates whether the specified string is null or an CaseInsensitiveString.Empty string.
Contains methods for simple hash calculations.
static string ComputeSHA1HashString(byte[] Data)
Computes the SHA-1 hash of a block of binary data.
Task< bool > IsPermitted(CaseInsensitiveString BareJid, string Setting)
Checks if a feature is permitted for a Bare JID.