public override void Execute(Tag data = null) { if (data == null) { var iq = new Iq { IdAttr = Tag.NextId(), FromAttr = Manager.Settings.Id, ToAttr = Manager.Settings.Id.Server, TypeAttr = Iq.TypeEnum.set }; iq.Add(new Session()); Manager.Connection.Send(iq); } else { Manager.SetAndExecState(new RunningState(Manager), false); Manager.Events.Ready(this); Manager.Connection.Send(new Presence()); if (Manager.Transport == Transport.Bosh) { (Manager.Connection as Bosh).StartPolling(); } } }
public void TestBuildRequestIq() { var put = new Put { Url = "https://upload.montague.tld/4a771ac1-f0b2-4a4a-9700-f2a26fa2bb67/tr%C3%A8s%20cool.jpg" }; put.AddHeader(HeaderNames.Authorization, "Basic Base64String=="); put.AddHeader(HeaderNames.Cookie, "foo=bar; user=romeo"); var get = new Get { Url = "https://download.montague.tld/4a771ac1-f0b2-4a4a-9700-f2a26fa2bb67/tr%C3%A8s%20cool.jpg" }; var slot = new Slot { Put = put, Get = get, }; var iq = new Iq { Type = Matrix.Xmpp.IqType.Result, Id = "step_03", To = "[email protected]/garden", From = "upload.montague.tld" }; iq.Add(slot); iq.ShouldBe(Resource.Get("Xmpp.HttpUpload.slot-request-iq.xml")); }
public void TestOnlineUsers() { string XML1 = @"<iq id='get-online-users-list-1' to='shakespeare.lit' type='set' xmlns='jabber:client'> <command xmlns='http://jabber.org/protocol/commands' action='execute' node='http://jabber.org/protocol/admin#get-online-users-list'/> </iq>"; var iq = new Iq { To = "shakespeare.lit", Id = "get-online-users-list-1", Type = Matrix.Xmpp.IqType.Set }; var cmd = new Command() { Action = Action.Execute, Node = "http://jabber.org/protocol/admin#get-online-users-list" }; iq.Add(cmd); iq.ShouldBe(XML1); }
public override void Execute(Tag data = null) { if (data == null) { var bind = new Bind(); var iq = new Iq { IdAttr = Tag.NextId() }; if (Manager.Settings.Id.Resource != null) { Tag res = new Resource(); ((XElement)res).Value = Manager.Settings.Id.Resource; bind.Add(res); } iq.TypeAttr = Iq.TypeEnum.set; iq.Add(bind); Manager.Connection.Send(iq); } else { Bind bind = null; var iq = data as Iq; if (iq != null) { if (iq.TypeAttr == Iq.TypeEnum.error) { Error e = iq.ErrorElements.First(); if (e != null) { Manager.Events.Error(this, ErrorType.BindingToResourceFailed, ErrorPolicyType.Deactivate, ((XElement)e).Value); } } bind = iq.Element <Bind>(Namespace.Bind); } if (bind != null) { Tags.XmppBind.Jid jid = bind.Jid; if (jid != null) { Manager.Settings.Id = jid.Value; } } #if DEBUG Manager.Events.LogMessage(this, LogType.Info, "Bind success, JID is now: {0}", Manager.Settings.Id); #endif Manager.Events.Receive(this, data); Manager.Events.ResourceBound(this, Manager.Settings.Id.ToString()); Manager.SetAndExecState(new SessionState(Manager)); } }
/// <summary> /// Accept VOIP/Video/Audio call. Should only be used after a SessionInitiate was received. /// </summary> /// <param name="to">recipient jid</param> /// <param name="sdp">Response sdp</param> public void SendSessionAccept(string to, string sdp) { Iq iq = new Iq(); iq.To = to; iq.Type = Matrix.Xmpp.IqType.Set; Matrix.Xmpp.Jingle.Jingle jingle = Jingle.JingleSdp.FromSdp(sdp); jingle.Action = Matrix.Xmpp.Jingle.Action.SessionAccept; jingle.GenerateSid(); iq.Add(jingle); xmppClient.Send(iq); Log.Info(">session-accept " + to); }
public DiscoHandler(ICaps caps, ICaps clientCaps) { Handle( el => el.OfType <Iq>() && el.Cast <Iq>().Type == IqType.Get && el.Cast <Iq>().Query.OfType <Info>(), async(context, xmppXElement) => { var iq = xmppXElement.Cast <Iq>(); var info = xmppXElement.Cast <Iq>().Query.Cast <Info>(); if (info.Node == null || info.Node == caps.Node + "#" + clientCaps.CapsHash) { var resIq = new Iq() { Id = iq.Id, To = iq.From, Type = IqType.Result }; resIq.Add(clientCaps.DiscoInfo); await SendAsync(resIq); } else { var dIq = new DiscoInfoIq { Type = IqType.Error, To = iq.From, Id = iq.Id, Info = { Node = info.Node }, Error = new Error(Matrix.Xmpp.Base.ErrorCondition.ItemNotFound) }; await SendAsync(dIq); } }); }
/// <summary> /// Disconnect VOIP/Video/Audio call. /// </summary> /// <param name="to">recipient jid</param> public void SendSessionTerminate(string to) { Matrix.Xmpp.Jingle.Jingle jIq = new Matrix.Xmpp.Jingle.Jingle(); jIq.Action = Matrix.Xmpp.Jingle.Action.SessionTerminate; jIq.GenerateSid(); string defaultNs = "urn:xmpp:jingle:1"; Matrix.Xml.XmppXElement eX = new Matrix.Xml.XmppXElement(defaultNs, "reason"); eX.Add(new Matrix.Xml.XmppXElement(defaultNs, "success")); jIq.Add(eX); Iq denyIq = new Iq(); denyIq.To = to; denyIq.From = this._jid; denyIq.Type = Matrix.Xmpp.IqType.Set; denyIq.Add(jIq); xmppClient.Send(denyIq); Log.Info(">session-terminate"); }
public void SendSessionTerminate(string to, string sid) { Matrix.Xmpp.Jingle.Jingle jIq = new Matrix.Xmpp.Jingle.Jingle(); jIq.Action = Matrix.Xmpp.Jingle.Action.SessionTerminate; jIq.Sid = sid; string defaultNs = "urn:xmpp:jingle:1"; Matrix.Xml.XmppXElement eX = new Matrix.Xml.XmppXElement(defaultNs, "reason"); eX.Add(new Matrix.Xml.XmppXElement(defaultNs, "success")); jIq.Add(eX); Iq denyIq = new Iq(); denyIq.To = to; denyIq.From = this.jid; denyIq.Type = Matrix.Xmpp.IqType.Set; denyIq.Add(jIq); Console.Write(denyIq.ToString()); xmppClient.Send(denyIq); }
/// <summary> /// Send request for VOIP/Video/Audio call /// </summary> /// <param name="to">recipient jid</param> /// <param name="sdp">SDP string from Icelink</param> public void SendSessionInitiate(string to, string sdp) { try { Iq iq = new Iq(); iq.To = to; //iq.From = this._jid; iq.Type = Matrix.Xmpp.IqType.Set; Matrix.Xmpp.Jingle.Jingle jingle = Jingle.JingleSdp.FromSdp(sdp); jingle.Action = Matrix.Xmpp.Jingle.Action.SessionInitiate; jingle.GenerateSid(); iq.Add(jingle); //iq.Add(new Matrix.Xmpp.Jingle.Jingle()); //xmppClient.Send(new Matrix.Xmpp.Client.Message(to, Matrix.Xmpp.MessageType.Chat, jingle.ToString())); xmppClient.Send(iq); Log.Info(">session-initiate " + to); } catch (Exception e) { Log.Error("Can't SendSessionInitiate " + e.ToString()); } }
public XmppWebSocketConnection(JID jid, string password, string websocketUri) : base(jid, password) { Capabilities = new CapabilitiesManager { Identity = new Identity { Category = "client", IdentityType = "mobile", IdentityName = "SharpXMPP" }, Node = "http://bggg.net.ru/caps", Features = new List <string> { Namespaces.DiscoInfo, Namespaces.DiscoItems } }; IqTracker = new XMPP.Client.IqHandler(this) { ResponseHandlers = new Dictionary <string, ResponseHandler>(), PayloadHandlers = new List <PayloadHandler> { new InfoHandler(Capabilities), new ItemsHandler() } }; Iq += (sender, iq) => IqTracker.Handle(iq); // ReSharper disable RedundantArgumentDefaultValue _connection = new WebSocket(websocketUri, "xmpp", cookies: (List <KeyValuePair <string, string> >)null); // ReSharper restore RedundantArgumentDefaultValue _connection.Opened += (sender, args) => { _currentState = XmppConnectionState.Connected; RestartStream(); }; _connection.MessageReceived += (sender, args) => { if (_currentState == XmppConnectionState.Connected) { ReadStreamStart(args.Message); _currentState = XmppConnectionState.StreamInitiated; } else if (_currentState == XmppConnectionState.StreamAuthenticated) { ReadStreamStart(args.Message); _currentState = XmppConnectionState.StreamResourceBindingRequest; } else { var currentStanza = Stanza.Parse(args.Message); OnElement(new ElementArgs { IsInput = false, Stanza = currentStanza }); var error = Stanza.Parse <StreamError>(currentStanza); if (error != null) { OnConnectionFailed(new ConnFailedArgs { Message = error.Value }); return; } switch (_currentState) { case XmppConnectionState.StreamInitiated: var features = Stanza.Parse <Features>(currentStanza); authenticator = SASLHandler.Create(features.SaslMechanisms, Jid, Password); if (authenticator == null) { OnConnectionFailed(new ConnFailedArgs { Message = "supported sasl mechanism not available" }); return; } var auth = new SASLAuth(); auth.SetAttributeValue("mechanism", authenticator.SASLMethod); var authInit = authenticator.Initiate(); if (!string.IsNullOrEmpty(authInit)) { auth.SetValue(authInit); } Send(auth); _currentState = XmppConnectionState.StreamAuthenticating; break; case XmppConnectionState.StreamAuthenticating: switch (currentStanza.Name.LocalName) { case "success": _currentState = XmppConnectionState.StreamAuthenticated; RestartStream(); break; case "failure": OnConnectionFailed(new ConnFailedArgs { Message = currentStanza.Value }); _currentState = XmppConnectionState.Disconnected; return; case "challenge": var response = new SASLResponse(); response.SetValue( authenticator.NextChallenge(currentStanza.Value)); Send(response); break; } break; case XmppConnectionState.StreamResourceBindingRequest: // todo: parse features of negotiated stream //Stanza.Parse<Features>(currentStanza); var bind = new Bind(Jid.Resource); var iq = new Iq(XMPP.Client.Elements.Iq.IqTypes.set); iq.Add(bind); Send(iq); _currentState = XmppConnectionState.StreamResourceBindingResponse; break; case XmppConnectionState.StreamResourceBindingResponse: var bindedJid = currentStanza.Element( XNamespace.Get(Namespaces.XmppBind) + "bind"); if (bindedJid == null) { OnConnectionFailed(new ConnFailedArgs { Message = "bind failed" }); _currentState = XmppConnectionState.Disconnected; } else { var sess = new XElement( XNamespace.Get(Namespaces.XmppSession) + "session"); var sessIq = new Iq(XMPP.Client.Elements.Iq.IqTypes.set); sessIq.Add(sess); Send(sessIq); _currentState = XmppConnectionState.StreamSessionNoOp; Jid = new JID( bindedJid.Element( XNamespace.Get(Namespaces.XmppBind) + "jid") .Value); } break; case XmppConnectionState.StreamSessionNoOp: OnSignedIn(new SignedInArgs { Jid = Jid }); Roster.Query(this); var initPresence = new Presence(Capabilities); Send(initPresence); _currentState = XmppConnectionState.StreamNegotiated; break; case XmppConnectionState.StreamNegotiated: if (currentStanza.Name.LocalName.Equals("iq")) { OnIq(Stanza.Parse <Iq>(currentStanza)); } if (currentStanza.Name.LocalName.Equals("message")) { OnMessage(Stanza.Parse <Message>(currentStanza)); } break; default: throw new IOException("Invalid state"); } } }; }