Пример #1
0
 /// <summary>
 /// Create an x:data form from the given iq stanza.
 /// </summary>
 /// <param name="parent">Original stanza</param>
 public XDataForm(Kixeye.Jabber.Protocol.Client.IQ parent) : this(FindData(parent))
 {
     m_stanza = (Packet) parent.CloneNode(true);
     Data d = FindData(m_stanza);
     m_parent = (Element)d.ParentNode;
     m_parent.RemoveChild(d);
 }
Пример #2
0
 /// <summary>
 /// Create an x:data form from the given message stanza.
 /// </summary>
 /// <param name="parent">Original stanza</param>
 public XDataForm(Kixeye.Jabber.Protocol.Client.Message parent) : this(FindData(parent) as Kixeye.Jabber.Protocol.X.Data)
 {
     m_stanza = (Packet) parent.CloneNode(true);
     Data d = FindData(m_stanza);
     Debug.Assert(d != null);
     m_parent = (Element)d.ParentNode;
     m_parent.RemoveChild(d);
 }
Пример #3
0
        /// <summary>
        /// Insert the given message into the history.  The timestamp on the message will be used, if
        /// included, otherwise the current time will be used.
        /// Messages without bodies will be ignored.
        /// </summary>
        /// <param name="msg"></param>
        public void InsertMessage(Kixeye.Jabber.Protocol.Client.Message msg)
        {
            string body = msg.Body;
            if (body == null)
                return;  // typing indicator, e.g.

            string nick = (m_nick == null) ? msg.From.Resource : m_nick;
            AppendMaybeScroll(m_recvColor, nick + ":", body);
        }
Пример #4
0
        /// <summary>
        /// overridden OnConnect to start off SHTTP protocol.
        /// </summary>
        /// <param name="sock"></param>
        public override void OnConnect(Kixeye.Jabber.Net.BaseSocket sock)
        {
            if (m_state == States.Connecting)
            { // CONNECT users.instapix.com:5222 HTTP/1.0
                m_state = States.WaitingForAuth;
                string cmd = string.Format(@"CONNECT {0}:{1} HTTP/1.1
Host: {0}
", RemoteAddress.Hostname, RemoteAddress.Port);

                // if authinfo is set, send it.
                if (Username != null && Username.Length > 0 && Password != null && Password.Length > 0)
                {
                    string auth = Convert.ToBase64String(Encoding.ASCII.GetBytes(Username + ":" + Password));
                    cmd += "Proxy-Authorization: Basic " + auth + "\r\n";
                }
                cmd += "\r\n";
                Debug.WriteLine("PSEND:" + cmd);
                Write(Encoding.ASCII.GetBytes(cmd));
                RequestRead();
            }
        }
Пример #5
0
        /// <summary>
        /// overridden OnConnect to start off Socks5 protocol.
        /// </summary>
        /// <param name="sock"></param>
        public override void OnConnect(Kixeye.Jabber.Net.BaseSocket sock)
        {
            if (m_state == States.Connecting)
            {
                IPHostEntry server = Dns.GetHostEntry(RemoteAddress.Hostname);
                IPAddress ip_addr = server.AddressList[0];

                byte[] addr = ip_addr.GetAddressBytes();

                int port = RemoteAddress.Port;
                byte [] buffer = new Byte[14];
                buffer[0] = 4;  // protocol version.
                buffer[1] = 1;  // connect.
                buffer[2] = (byte)(port >> 8);
                buffer[3] = (byte)port;
                // TODO: test byte order!
                buffer[4] = addr[3];
                buffer[5] = addr[2];
                buffer[6] = addr[1];
                buffer[7] = addr[0];
                buffer[8] = (byte)'i';
                buffer[9] = (byte)'d';
                buffer[10] = (byte)'e';
                buffer[11] = (byte)'n';
                buffer[12] = (byte)'t';
                buffer[13] = 0;

                /*
                +----+----+----+----+----+----+----+----+----+----+....+----+
                | VN | CD | DSTPORT |      DSTIP        | USERID       |NULL|
                +----+----+----+----+----+----+----+----+----+----+....+----+
    # of bytes:    1    1      2              4           variable       1
                */


                Write(buffer);
                RequestRead();
                m_state = States.RequestingProxy;
            }
        }
Пример #6
0
 /// <summary>
 /// Writes a stream:stream start tag.
 /// Some underlying implementations will ignore this,
 /// but may pull out pertinent data.
 /// </summary>
 /// <param name="stream">Stream containing the start tag.</param>
 abstract public void WriteStartTag(Kixeye.Jabber.Protocol.Stream.Stream stream);
Пример #7
0
        ///<summary>
        /// Removes the publish-subscribe node from the manager and sends a delete
        /// node to the XMPP server.
        ///</summary>
        /// <param name="service">
        /// Component that handles PubSub requests.
        /// </param>
        /// <param name="node">
        /// The node on the component that the client wants to interact with.
        /// </param>
        /// <param name="errorHandler">
        /// Callback for any errors with the publish-subscribe node deletion.
        /// </param>
        public void RemoveNode(JID service, string node, Kixeye.Bedrock.ExceptionHandler errorHandler)
        {
            JIDNode jn = new JIDNode(service, node);

            PubSubNode psNode = null;
            if (m_nodes.TryGetValue(jn, out psNode))
            {
                m_nodes.Remove(jn);
            }
            else
            {
                psNode = new PubSubNode(Stream, service, node, 10);
            }

            psNode.OnError += errorHandler;

            psNode.Delete();
        }
Пример #8
0
 /// <summary>
 /// Prepare to start accepting inbound requests.  Call RequestAccept() to start the async process.
 /// </summary>
 /// <param name="addr">Address to listen on</param>
 /// <param name="backlog">The Maximum length of the queue of pending connections</param>
 public override void Accept(Kixeye.Jabber.Net.Address addr, int backlog)
 {
     m_sock.Accept(addr, backlog);
 }
Пример #9
0
 /// <summary>
 /// Writes a stream:stream.
 /// </summary>
 /// <param name="stream">Stream containing the stream:stream packet to send.</param>
 public override void WriteStartTag(Kixeye.Jabber.Protocol.Stream.Stream stream)
 {
     Write(stream.StartTag());
 }
Пример #10
0
 /// <summary>
 /// Remember that we're in the connecting state, let base connect to proxy, resumes in OnConnect.
 /// </summary>
 /// <param name="addr"></param>
 public override void Connect(Kixeye.Jabber.Net.Address addr)
 {
     m_state = States.Connecting;
     base.Connect(addr);
 }
Пример #11
0
 /// <summary>
 /// Overridden OnRead to handle 4 Socks5 states...
 /// </summary>
 /// <param name="sock"></param>
 /// <param name="buf"></param>
 /// <param name="offset"></param>
 /// <param name="length"></param>
 /// <returns></returns>
 public override bool OnRead(Kixeye.Jabber.Net.BaseSocket sock, byte[] buf, int offset, int length)
 {
     switch (m_state)
     {
     case States.WaitingForAuth:
         m_headerstream.Write(buf, offset, length);
         int state = 0;
         int line = 0;
         foreach (byte b in buf)
         {
             // Look for \r\n\r\n for end of response header
             switch (state)
             {
             case 0:
                 if (b == '\r')
                     state++;
                 break;
             case 1:
                 if (b == '\n')
                 {
                     byte[] hs = m_headerstream.ToArray();
                     string s = System.Text.Encoding.UTF8.GetString(hs);
                     Debug.Write("PRECV: " + s);
                     m_headers.Add(s);
                     m_headerstream.SetLength(0);
                     state++;
                     line++;
                 }
                 else
                     state = 0;
                 break;
             case 2:
                 if (b == '\r')
                     state++;
                 else
                     state = 0;
                 break;
             case 3:
                 if (b == '\n')
                 {
                     Debug.WriteLine("End of proxy headers");
                     string line0 = (string)m_headers[0];
                     if (line0.IndexOf("200") == -1)
                     {
                         Debug.WriteLine("200 response not detected.  Closing.");
                         m_state = States.Error;
                         this.Close();
                     }
                     else
                     {
                         Debug.WriteLine("Proxy connected");
                         m_listener.OnConnect(sock); // tell the real listener that we're connected.
                         m_state = States.Running;
                     }
                     // they'll call RequestRead(), so we can return false here.
                     return false;
                 }
                 else
                     state = 0;
                 break;
             }
         }
         return true;
     case States.Error:
         throw new InvalidOperationException("Cannot read after error");
     default:
         return base.OnRead(sock, buf, offset, length);
     }
 }
Пример #12
0
        private void JabberClient_OnSASLEnd(Object sender, Kixeye.Jabber.Protocol.Stream.Features feat)
        {
            lock (StateLock)
            {
                State = BindState.Instance;
            }
            if (feat["bind", URI.BIND] != null)
            {
                IQ iq = new IQ(this.Document);
                iq.Type = IQType.set;

                Kixeye.Jabber.Protocol.Stream.Bind bind = new Kixeye.Jabber.Protocol.Stream.Bind(this.Document);
                if ((Resource != null) && (Resource != ""))
                    bind.Resource = Resource;

                iq.AddChild(bind);
                this.Tracker.BeginIQ(iq, new IqCB(GotResource), feat);
            }
            else if (feat["session", URI.SESSION] != null)
            {
                IQ iq = new IQ(this.Document);
                iq.Type = IQType.set;
                iq.AddChild(new Kixeye.Jabber.Protocol.Stream.Session(this.Document));
                this.Tracker.BeginIQ(iq, new IqCB(GotSession), feat);
            }
            else
                IsAuthenticated = true;
        }
Пример #13
0
 /// <summary>
 /// Overridden OnRead to handle 4 Socks5 states...
 /// </summary>
 /// <param name="sock"></param>
 /// <param name="buf"></param>
 /// <param name="offset"></param>
 /// <param name="length"></param>
 /// <returns></returns>
 public override bool OnRead(Kixeye.Jabber.Net.BaseSocket sock, byte[] buf, int offset, int length)
 {
     switch (m_state)
     {
         case States.GettingMethods:
             return HandleGetMethodsResponse(buf[offset], buf[offset + 1]);
         case States.WaitingForAuth:
             return HandleAuthResponse(buf[offset], buf[offset + 1]);
         case States.RequestingProxy:
             bool ret = HandleRequestResponse(buf[offset], buf[offset + 1]);
             if (ret)
             {
                 m_listener.OnConnect(sock); // tell the real listener that we're connected.
                 // they'll call RequestRead(), so we can return false here.
             }
             return false;
         default:
             return base.OnRead(sock, buf, offset, length);
     }
 }
Пример #14
0
        private void JabberService_OnSASLStart(object sender, Kixeye.Jabber.Connection.SASL.SASLProcessor proc)
        {
            Kixeye.Jabber.Connection.BaseState s = null;
            lock (StateLock)
            {
                s = State;
            }

            if (s == Kixeye.Jabber.Connection.NonSASLAuthState.Instance)
            {
                lock (StateLock)
                {
                    State = HandshakingState.Instance;
                }

                if (this.Type == ComponentType.Accept)
                {
                    Handshake hand = new Handshake(this.Document);
                    hand.SetAuth(this.Secret, StreamID);
                    Write(hand);
                }
            }
        }
Пример #15
0
        private void JabberClient_OnSASLStart(Object sender, Kixeye.Jabber.Connection.SASL.SASLProcessor proc)
        {
            BaseState s = null;
            lock (StateLock)
            {
                s = State;
            }

            // HACK: fire OnSASLStart with state of NonSASLAuthState to initiate old-style auth.
            if (s == NonSASLAuthState.Instance)
            {
                if ((bool)this[Options.AUTO_LOGIN_THISPASS])
                    Login();
                else
                    LoginRequired(ManualLoginState.Instance);
            }
            else
            {
                if ((bool)this[Options.AUTO_LOGIN_THISPASS])
                {
                    // TODO: integrate SASL params into XmppStream params
                    proc[SASLProcessor.USERNAME] = User;
                    proc[SASLProcessor.PASSWORD] = Password;
                    proc[MD5Processor.REALM] = this.Server;
                    // Always false until we get a new KerbProcessor back
                    proc["USE_WINDOWS_CRED"] = false.ToString();
                }
                else
                {
                    LoginRequired(ManualSASLLoginState.Instance);
                }
            }
        }
Пример #16
0
        /// <summary>
        /// Connect to the jabberd, or wait for it to connect to us.
        /// Either way, this call returns immediately.
        /// </summary>
        /// <param name="address">The address to connect to.</param>
        public void Connect(Kixeye.Jabber.Net.Address address)
        {
            this.NetworkHost = address.Hostname;
            this.Port = address.Port;

            Connect();
        }
Пример #17
0
        /// <summary>
        /// Create an x:data form from the given XML form description
        /// </summary>
        /// <param name="x">x:data form to render</param>
        public XDataForm(Kixeye.Jabber.Protocol.X.Data x) : this()
        {
            if (x == null)
                throw new ArgumentException("x:data form must not be null", "x");

            m_type = x.Type;

            this.SuspendLayout();
            if (x.Title != null)
                this.Text = x.Title;
            if (m_type == XDataType.cancel)
            {
                lblInstructions.Text = "Form canceled.";  // TODO: Localize!
                lblInstructions.Resize += new EventHandler(lblInstructions_Resize);
                lblInstructions_Resize(lblInstructions, null);
            }
            else if (x.Instructions == null)
                lblInstructions.Visible = false;
            else
            {
                lblInstructions.Text = DeWhitespace(x.Instructions);
                lblInstructions.Resize += new EventHandler(lblInstructions_Resize);
                lblInstructions_Resize(lblInstructions, null);
            }

            pnlFields.SuspendLayout();
            Field[] fields = x.GetFields();
            m_fields = new FormField[fields.Length];
            for (int i=fields.Length-1; i>=0; i--)
            {
                m_fields[i] = new FormField(fields[i], this, i);
            }

            panel1.TabIndex = fields.Length;

            if (m_type != XDataType.form)
            {
                btnOK.Location = btnCancel.Location;
                btnCancel.Visible = false;
            }

            pnlFields.ResumeLayout(true);
            this.ResumeLayout(true);

            for (int i=0; i<fields.Length; i++)
            {
                if ((fields[i].Type != FieldType.hidden) &&
                    (fields[i].Type != FieldType.Fixed))
                    m_fields[i].Focus();
            }
        }
Пример #18
0
 /// <summary>
 /// Writes just the start tag of the given XML element.
 /// Typically only used for &lt;stream:stream&gt;.
 /// </summary>
 /// <param name="elem">&lt;stream:stream%gt; XML element.</param>
 public void WriteStartTag(Kixeye.Jabber.Protocol.Stream.Stream elem)
 {
     m_stanzas.WriteStartTag(elem);
 }
Пример #19
0
        /// <summary>
        /// Creates the node using the specified configuration form.
        /// </summary>
        /// <param name="config">Null for the default configuration</param>
        public void Create(Kixeye.Jabber.Protocol.X.Data config)
        {
            lock (this)
            {
                if (!NeedsAsking(this[Op.CREATE]))
                {
                    SubscribeIfPending();
                    return;
                }

                this[Op.CREATE] = STATE.Asking;
            }
/*
<iq type='set'
    from='[email protected]/elsinore'
    to='pubsub.shakespeare.lit'
    id='create1'>
    <pubsub xmlns='http://jabber.org/protocol/pubsub'>
      <create node='princely_musings'/>
      <configure/>
    </pubsub>
</iq>
 */
            PubSubCommandIQ<Create> iq = new PubSubCommandIQ<Create>(m_stream.Document, m_node);
            iq.To = m_jid;
            iq.Type = IQType.set;
            iq.Command.CreateConfiguration(config);
            BeginIQ(iq, GotCreated, null);
        }
Пример #20
0
 /// <summary>
 /// Returns a new collection that contains all of the items that
 /// are in this list *and* the other set.
 /// </summary>
 /// <param name="other">
 /// Other set to intersect with.
 /// </param>
 /// <returns>Combined set.</returns>
 public Kixeye.Bedrock.Collections.ISet Intersection(Kixeye.Bedrock.Collections.ISet other)
 {
     throw new NotImplementedException();
 }
Пример #21
0
 /// <summary>
 /// overridden OnConnect to start off Socks5 protocol.
 /// </summary>
 /// <param name="sock"></param>
 public override void OnConnect(Kixeye.Jabber.Net.BaseSocket sock)
 {
     if (m_state == States.Connecting)
     {
         byte [] buffer = new Byte[4];
         buffer[0] = 5; // protocol version.
         buffer[1] = 2; // number of methods.
         buffer[2] = 0; // no auth.
         buffer[3] = 2; // username password.
         Debug.WriteLine("sending auth methods to proxy...");
         Write(buffer);
         RequestRead();
         m_state = States.GettingMethods;
     }
 }
Пример #22
0
 private void m_cli_OnPresence(object sender, Kixeye.Jabber.Protocol.Client.Presence pres)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Пример #23
0
 /// <summary>
 /// Overridden OnWrite to ensure that the base only gets called when in running state.
 /// </summary>
 /// <param name="sock"></param>
 /// <param name="buf"></param>
 /// <param name="offset"></param>
 /// <param name="length"></param>
 public override void OnWrite(Kixeye.Jabber.Net.BaseSocket sock, byte[] buf, int offset, int length)
 {
     if (m_state == States.Running)
     {
         base.OnWrite(sock, buf, offset, length);
     }
 }
Пример #24
0
 /// <summary>
 /// Create a Client Login dialog box than manages the connection properties of a particular client
 /// connection.
 /// </summary>
 /// <param name="cli">The client connection to modify</param>
 public ClientLogin(Kixeye.Jabber.Client.JabberClient cli) : this()
 {
     this.Xmpp = cli;
 }
Пример #25
0
 public bool InvalidCertificate(Kixeye.Jabber.Net.BaseSocket sock,
     System.Security.Cryptography.X509Certificates.X509Certificate certificate,
     System.Security.Cryptography.X509Certificates.X509Chain chain,
     System.Net.Security.SslPolicyErrors sslPolicyErrors)
 {
     if (OnInvalidCertificate != null)
     {
         return OnInvalidCertificate(sock, certificate, chain, sslPolicyErrors);
     }
     throw new Exception("Invalid certificate; no event handler set.");
 }
Пример #26
0
 /// <summary>
 /// Create a Client Login dialog box that manages a component
 /// </summary>
 /// <param name="service">The component to manage</param>
 public ComponentLogin(Kixeye.Jabber.Server.JabberService service) : this()
 {
     this.Xmpp = service;
 }
Пример #27
0
 /// <summary>
 /// Log in to the server
 /// </summary>
 /// <param name="service">The JabberClient instance to connect</param>
 /// <param name="propertyFile">The name of an XML file to store properties in.</param>
 /// <returns>True if the user clicked OK, false on cancel</returns>
 public static bool Login(Kixeye.Jabber.Server.JabberService service, string propertyFile)
 {
     return new ComponentLogin(service).Login(propertyFile);
 }
Пример #28
0
 /// <summary>
 /// Saves the address passed in, and really connects to m_host:m_port.
 /// </summary>
 /// <param name="addr"></param>
 public override void Connect(Kixeye.Jabber.Net.Address addr)
 {
     m_remote_addr = addr; // save this till we are ready for it...
     Debug.Assert(m_host != null);
     Debug.Assert(m_port != 0);
     // connect to the proxy.
     Address proxy_addr = new Address(m_host, m_port);
     m_sock.Connect(proxy_addr, m_hostid);
     // we'll end up in OnConnected below.
 }
Пример #29
0
 private void m_stream_OnConnect(object sender, Kixeye.Jabber.Connection.StanzaStream stream)
 {
     // I think this is right.  Double check.
     rtDebug.Clear();
 }
Пример #30
0
 /// <summary>
 /// Log in to the server
 /// </summary>
 /// <param name="cli">The JabberClient instance to connect</param>
 /// <param name="propertyFile">The name of an XML file to store properties in.</param>
 /// <returns>True if the user clicked OK, false on cancel</returns>
 public static bool Login(Kixeye.Jabber.Client.JabberClient cli, string propertyFile)
 {
     return new ClientLogin(cli).Login(propertyFile);
 }