/// <summary> /// Initializes a new instance of the <see cref="T:XmppServiceDiscovery"/> class. /// </summary> /// <param name="session">The session.</param> public XmppServiceDiscovery(XmppSession session) { this.session = session; this.pendingMessages = new List<string>(); this.SubscribeToSessionState(); }
private void SendOfflineMessages(XmppSession session) { if (!session.IsSignalRFake) { var domain = session.Stream.Domain; foreach (var m in offlineStore.GetOfflineMessages(session.Jid)) { var delay = new Element("delay"); delay.SetNamespace("urn:xmpp:delay"); delay.SetAttribute("From", domain); delay.SetAttribute("stamp", Time.Date(m.XDelay.Stamp)); delay.Value = "Offline Storage"; m.AddChild(delay); m.XDelay.From = new Jid(domain); m.XDelay.Value = "Offline Storage"; sender.SendTo(session, m); } if (session.Jid.Resource != "TMTalk") { offlineStore.RemoveAllOfflineMessages(session.Jid); } } }
/// <summary> /// Initializes a new instance of the <see cref = "T:XmppChatRoom" /> class. /// </summary> /// <param name = "session">The session.</param> /// <param name = "conferenceService">The conference service.</param> /// <param name = "chatRoomId">The chat room id.</param> internal XmppChatRoom(XmppSession session, XmppService conferenceService, XmppJid chatRoomId) : base(session, chatRoomId) { this.conferenceService = conferenceService; seekEnterChatRoomEvent = new AutoResetEvent(false); createChatRoomEvent = new AutoResetEvent(false); }
public Commands(XmppSession xmppSession, MyViewModel viewModel, Account account) { this.viewModel = viewModel; this.account = account; this.xmppSession = xmppSession; RegexUtilities regexUtils = new RegexUtilities(); // create an observable which is used to enable/disable the login command // based on the user input for the credentials and the xmpp connection status var canLogin = this .WhenAnyValue(x => x.account.XmppId, x => x.account.SecurePassword, x => x.viewModel.IsConnected, (xmppId, pass, isConnected) => !String.IsNullOrWhiteSpace(xmppId) && regexUtils.IsValidXmppId(xmppId) && pass?.Length > 0 && !isConnected) .DistinctUntilChanged(); ConnectCommand = ReactiveCommand.Create <Account>( async a => { await Observable.Start(async() => await xmppSession.Connect(a), RxApp.TaskpoolScheduler); } , canLogin ); SetStatusCommand = ReactiveCommand.Create <OnlineStatus>( async status => await xmppSession.SetStatus(status), this.viewModel.IsConnectedObervalble ); }
/// <summary> /// Initializes a new instance of the <see cref = "T:XmppServiceDiscovery" /> class. /// </summary> /// <param name = "session">The session.</param> public XmppServiceDiscovery(XmppSession session) { this.session = session; pendingMessages = new List <string>(); SubscribeToSessionState(); }
public XmppHandlerResult ProcessElement(BindIq element, XmppSession session, XmppHandlerContext context) { if (element.Query.TagName.Equals("bind", StringComparison.OrdinalIgnoreCase)) { if (session.Binded) { return(Error(session, ErrorCondition.Conflict, element)); } session.Bind(!string.IsNullOrEmpty(element.Query.Resource) ? element.Query.Resource : session.Jid.User); element.From = element.To = null; element.Query = new Bind(session.Jid); var result = Component(Send(session, element.ToResult())); foreach (var s in context.Sessions.GetSessions(session.Jid)) { if (!session.Equals(s)) { result.Add(Close(s)); } } return(result); } else { var resource = element.Query.Resource; return(session.Jid.Resource == resource?Close(session) : Error(session, ErrorCondition.ItemNotFound, element)); } }
/// <summary> /// Initializes a new instance of the <see cref = "XmppSession" /> class /// </summary> internal XmppActivity(XmppSession session) { this.session = session; activities = new ObservableCollection <XmppEvent>(); SubscribeToSessionState(); }
public XmppHandlerResult ProcessElement(Presence element, XmppSession session, XmppHandlerContext context) { var result = Component(); if (!element.HasTo) { if (!session.Available) { session.Presence = element; // send offline stanzas foreach (var jid in context.Storages.Users.GetAskers(session.Jid)) { result.Add(Send(session, Presence.Subscribe(jid, session.Jid))); } foreach (var e in context.Storages.Elements.GetOfflines(session.Jid)) { result.Add(Send(session, e, true)); } context.Storages.Elements.RemoveOfflines(session.Jid); // send presences from roster foreach (var ri in context.Storages.Users.GetRosterItems(session.Jid)) { if (ri.HasFromSubscription()) { foreach (var s in context.Sessions.GetSessions(ri.Jid.BareJid).Where(s => s.Available)) { if (s.Presence != null) { var p = (Presence)s.Presence.Clone(); p.To = session.Jid; result.Add(Send(session, p)); } } } } } // send to itself available resource foreach (var s in context.Sessions.GetSessions(element.From.BareJid).Where(s => s.Available)) { var p = (Presence)element.Clone(); p.To = s.Jid; result.Add(Send(s, p)); } // broadcast to subscribers foreach (var to in context.Storages.Users.GetSubscribers(session.Jid)) { foreach (var s in context.Sessions.GetSessions(to.BareJid).Where(s => s.Available)) { var p = (Presence)element.Clone(); p.To = s.Jid; result.Add(Send(s, p)); } } } return(result); }
/// <summary> /// Initializes a new instance of the <see cref = "T:XmppChatRoom" /> class. /// </summary> /// <param name = "session">The session.</param> /// <param name = "conferenceService">The conference service.</param> /// <param name = "chatRoomId">The chat room id.</param> internal XmppChatRoom(XmppSession session, XmppService conferenceService, XmppJid chatRoomId) : base(session, chatRoomId) { this.conferenceService = conferenceService; seekEnterChatRoomEvent = new AutoResetEvent(false); createChatRoomEvent = new AutoResetEvent(false); }
public XmppHandlerResult ProcessElement(Presence element, XmppSession session, XmppHandlerContext context) { var result = Component(); if (!element.HasTo) { // send to itself available resource foreach (var s in context.Sessions.GetSessions(element.From.BareJid).Where(s => s.Available)) { var p = (Presence)element.Clone(); p.To = s.Jid; result.Add(Send(s, p)); } var last = new Last { Value = element.Status, Seconds = UnixDateTime.ToUnix(DateTime.UtcNow) }; context.Storages.Elements.SaveElement(session.Jid, agsXMPP.Uri.IQ_LAST, last); // broadcast to subscribers foreach (var to in context.Storages.Users.GetSubscribers(session.Jid)) { foreach (var s in context.Sessions.GetSessions(to.BareJid).Where(s => s.Available)) { var p = (Presence)element.Clone(); p.To = s.Jid; result.Add(Send(s, p)); } } session.Presence = element; } return(result); }
private XmppHandlerResult StartBoshSession(Body element, XmppSession session, XmppHandlerContext context) { var body = new Body { XmppVersion = "1.0", Sid = session.Id, From = element.To, Secure = false, Inactivity = element.Inactivity, Wait = element.Wait, Hold = element.Hold, Window = element.Window, Requests = element.Requests, }; body.SetAttribute("xmlns:xmpp", "urn:xmpp:xbosh"); body.SetAttribute("xmpp:restartlogic", true); var stream = new Stream { Prefix = agsXMPP.Uri.PREFIX, DefaultNamespace = agsXMPP.Uri.CLIENT, Version = element.XmppVersion, To = element.To, Language = element.GetAttribute("xml:lang"), }; return(Component(Send(session, body), Process(session, stream), Send(session, new BodyEnd()))); }
public XmppHandlerResult ProcessElement(VersionIq element, XmppSession session, XmppHandlerContext context) { element.Query.Os = Environment.OSVersion.ToString(); element.Query.Name = serviceInfo.Name; element.Query.Ver = "1.0"; return(Send(session, element.ToResult())); }
public XmppHandlerResult ProcessElement(EntityTimeIq element, XmppSession session, XmppHandlerContext context) { var tzo = TimeZoneInfo.Local.BaseUtcOffset; element.Time.Tzo = tzo.Hours.ToString("+00;-00") + tzo.Minutes.ToString(":00"); element.Time.Utc = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ"); return(Send(session, element.ToResult())); }
public XmppRequestResult(XmppSession session, IQ iq, XmppHandlerResult errorResponse) : base(session) { Args.NotNull(iq, "iq"); this.iq = iq; this.errorResponse = errorResponse; }
/// <summary> /// Initializes a new instance of the <see cref = "XmppServiceDiscoveryObject" /> class. /// </summary> protected XmppServiceDiscoveryObject(XmppSession session, string identifier) { this.session = session; this.identifier = identifier; waitEvent = new AutoResetEvent(false); Subscribe(); }
private void SendOfflinePresences(XmppSession session) { foreach (var presence in offlineStore.GetOfflinePresences(session.Jid)) { sender.SendTo(session, presence); } offlineStore.RemoveAllOfflinePresences(session.Jid); }
public XmppHandlerResult ProcessElement(DiscoItemsIq element, XmppSession session, XmppHandlerContext context) { foreach (var item in items) { element.Query.AddDiscoItem(item.Jid, item.Name); } return(Send(session, element.ToResult())); }
public void SendTo(XmppSession to, Node node) { if (to == null) { throw new ArgumentNullException("to"); } SendTo(to.Stream, node); }
/// <summary> /// Initializes a new instance of the <see cref = "XmppServiceDiscoveryObject" /> class. /// </summary> protected XmppServiceDiscoveryObject(XmppSession session, string identifier) { this.session = session; this.identifier = identifier; waitEvent = new AutoResetEvent(false); Subscribe(); }
/// <summary> /// Initializes a new instance of the <see cref = "T:XmppServiceDiscovery" /> class. /// </summary> /// <param name = "session">The session.</param> internal XmppPersonalEventing(XmppSession session) { this.session = session; pendingMessages = new List<string>(); features = new List<string>(); SubscribeToSessionState(); }
/// <summary> /// Initializes a new instance of the <see cref = "T:XmppServiceDiscovery" /> class. /// </summary> /// <param name = "session">The session.</param> internal XmppPersonalEventing(XmppSession session) { this.session = session; pendingMessages = new List <string>(); features = new List <string>(); SubscribeToSessionState(); }
public XmppSendResult(XmppSession session, Element element, bool offline) : base(session) { Args.NotNull(element, "element"); this.element = element; this.offline = offline; }
/// <summary> /// Initializes a new instance of the <see cref="T:XmppServiceDiscovery"/> class. /// </summary> /// <param name="session">The session.</param> internal XmppPersonalEventing(XmppSession session) { this.session = session; this.pendingMessages = new List<string>(); this.features = new List<string>(); this.nowPlayingListener = new AmipNowPlayingListerner(this.session); this.SubscribeToSessionState(); }
public XmppHandlerResult ProcessElement(DiscoInfoIq element, XmppSession session, XmppHandlerContext context) { element.Query.AddIdentity(serviceInfo.Category, serviceInfo.Type, serviceInfo.Name); foreach (var feature in serviceInfo.Features.Reverse()) { element.Query.AddFeature(feature); } return(Send(session, element.ToResult())); }
public XmppErrorResult(XmppSession session, Exception error) : base(XmppSession.Empty) { Args.NotNull(error, "error"); var je = (error as JabberException) ?? new JabberStreamException(error); XmppHandlerResult send = new XmppSendResult(session, je.ToElement(), false); result = je.CloseStream ? new XmppComponentResult(send, new XmppCloseResult(session)) : send; }
public XmppHandlerResult ProcessElement(VcardIq element, XmppSession session, XmppHandlerContext context) { element.Query = new Vcard { Fullname = serviceInfo.Name, Description = serviceInfo.Copyrigth, Url = serviceInfo.Url }; return(Send(session, element.ToResult())); }
public override XmppHandlerResult ValidateElement(Element element, XmppSession session, XmppHandlerContext context) { var presence = element as Presence; if (presence.Type != allowed) { return(Fail()); } return(Success()); }
public XmppHandlerResult ProcessElement(Stream element, XmppSession session, XmppHandlerContext context) { if (element.To != domain) { return(Error(session, StreamErrorCondition.HostUnknown)); } var stream = new Stream { Id = session.Id, Prefix = Uri.PREFIX, Version = element.Version, From = element.To, Features = new Features { Prefix = Uri.PREFIX }, Language = element.Language, }; if (!session.Authenticated) { session.Jid = stream.From; session.Language = stream.Language; context.Sessions.OpenSession(session); stream.Features.Mechanisms = new Mechanisms(); foreach (var m in context.Handlers.SupportedAuthMechanisms) { stream.Features.Mechanisms.AddChild(m); } if (context.Handlers.SupportRegister) { stream.Features.Register = new Register(); } if (context.Handlers.SupportTls && session.Connection is IXmppTlsConnection && !((IXmppTlsConnection)session.Connection).TlsStarted) { stream.Features.StartTls = new StartTls(); } } else { if (context.Handlers.SupportBind) { stream.Features.AddChild(new Bind()); } if (context.Handlers.SupportSession) { stream.Features.AddChild(new Session()); } } return(Send(session, stream)); }
private XmppHandlerResult RestartBoshSession(Body element, XmppSession session, XmppHandlerContext context) { var stream = new Stream { Prefix = agsXMPP.Uri.PREFIX, DefaultNamespace = agsXMPP.Uri.CLIENT, To = element.To, From = element.From, }; return(Process(session, stream)); }
public XmppHandlerResult ProcessElement(Handshake element, XmppSession session, XmppHandlerContext context) { var test = new Handshake(secret, session.AuthData as string); if (element.Value != test.Value) { return(Error(session, StreamErrorCondition.NotAuthorized)); } session.Authenticate(null); session.Bind(null); return(Send(session, new Handshake())); }
private bool ProcessValidation(IXmppHandlerInvoker i, Element e, XmppSession s, XmppHandlerContext c) { foreach (var validator in i.Validators) { var result = validator.ValidateElement(e, s, c); if (result != null) { ProcessResult(result); return(false); } } return(true); }
public XmppHandlerResult ProcessElement(LastIq element, XmppSession session, XmppHandlerContext context) { if (!element.HasTo) { return(Error(session, ErrorCondition.BadRequest, element)); } if (element.Type == IqType.get) { var ri = context.Storages.Users.GetRosterItem(session.Jid, element.To); if (ri == null || !ri.HasToSubscription()) { return(Error(session, ErrorCondition.Forbidden, element)); } } if (element.Type == IqType.get && element.To.IsBare) { if (context.Sessions.GetSessions(element.To).Any()) { element.Query.Seconds = 0; } else { var last = context.Storages.Elements.GetElement(element.To, agsXMPP.Uri.IQ_LAST) as Last; if (last != null) { element.Query.Seconds = UnixDateTime.ToUnix(DateTime.UtcNow) - last.Seconds; element.Query.Value = last.Value; } else { return(Error(session, ErrorCondition.ItemNotFound, element)); } } return(Send(session, element.ToResult())); } else if (element.To.IsFull) { var to = context.Sessions.GetSession(element.To); if (to == null) { return(element.Type == IqType.get ? Error(session, ErrorCondition.RecipientUnavailable, element) : Void()); } return(Request(to, element, Error(session, ErrorCondition.RecipientUnavailable, element))); } return(element.Type == IqType.get ? Error(session, ErrorCondition.ServiceUnavailable, element) : Void()); }
private bool Send(Stanza stanza) { if (stanza.To == null) { XmppStanzaError.ToForbidden(stanza); } XmppSession session = SessionManager.GetSession(stanza.To); if (session != null) { Sender.SendTo(session.Stream, stanza); } return(session != null); }
public XmppHandlerResult ProcessElement(Element element, XmppSession session, XmppHandlerContext context) { var stanza = element as Stanza; if (stanza == null) { return(Error(session, StreamErrorCondition.UnsupportedStanzaType)); } if (!stanza.HasTo || stanza.To.IsServer) { // server answer var iq = stanza as IQ; if (iq != null && (iq.Type == IqType.get || iq.Type == IqType.set)) { // unknown request iq return(Error(session, ErrorCondition.ServiceUnavailable, stanza)); } return(Void()); // ignore } if (stanza.HasTo && stanza.To.IsFull) { var iq = stanza as IQ; // route stanza to client var to = context.Sessions.GetSession(stanza.To); if (to == null) { if (iq != null && (iq.Type == IqType.get || iq.Type == IqType.set)) { return(Error(session, ErrorCondition.RecipientUnavailable, stanza)); } else { return(Void()); } } if (iq != null) { return(Request(to, iq, Error(session, ErrorCondition.RecipientUnavailable, stanza))); } return(Send(to, stanza)); } return(Void()); }
private void SendRosterPresences(XmppSession session) { //It's correct! //Get other statuses foreach (var ri in rosterStore.GetRosterItems(session.Jid)) { //"none" -- the user does not have a subscription to the contact's presence information, and the contact does not have a subscription to the user's presence information //"to" -- the user has a subscription to the contact's presence information, but the contact does not have a subscription to the user's presence information //"from" -- the contact has a subscription to the user's presence information, but the user does not have a subscription to the contact's presence information //"both" -- both the user and the contact have subscriptions to each other's presence information if (ri.Subscribtion == SubscriptionType.to || ri.Subscribtion == SubscriptionType.both) { foreach (var contactSession in sessionManager.GetBareJidSessions(ri.Jid)) { if (contactSession.Presence != null) { //Send roster contact presence to newly availible session contactSession.Presence.To = null;//To no one sender.SendTo(session, contactSession.Presence); if (contactSession.GetRosterTime.AddMinutes(1) < DateTime.UtcNow) { //Send roster push var roster = new Roster(); roster.AddRosterItem(rosterStore.GetRosterItem(contactSession.Jid, session.Jid).ToRosterItem()); var iq = new IQ { Type = IqType.set, Namespace = Uri.SERVER, Id = UniqueId.CreateNewId(), To = contactSession.Jid, Query = roster }; sender.SendTo(contactSession, iq); } } } } } var server = new Presence() { Type = PresenceType.available, From = new Jid(session.Jid.Server) }; sender.SendTo(session, server); }
/// <summary> /// Initializes a new instance of the <see cref = "XmppEntityCapabilities" /> class. /// </summary> internal XmppSessionEntityCapabilities(XmppSession session) : base(session) { this.session = session; // Supported features Features.Add(new XmppServiceFeature(XmppFeatures.ServiceDiscoveryInfo)); // this.Features.Add(new XmppServiceFeature(XmppFeatures.ServiceDiscoveryItems)); Features.Add(new XmppServiceFeature(XmppFeatures.EntityCapabilities)); Features.Add(new XmppServiceFeature(XmppFeatures.BidirectionalStreamsOverSynchronousHTTP)); Features.Add(new XmppServiceFeature(XmppFeatures.ChatStateNotifications)); Features.Add(new XmppServiceFeature(XmppFeatures.MultiUserChat)); Features.Add(new XmppServiceFeature(XmppFeatures.MultiUserChatUser)); Features.Add(new XmppServiceFeature(XmppFeatures.UserMood)); Features.Add(new XmppServiceFeature(XmppFeatures.UserMoodWithNotify)); Features.Add(new XmppServiceFeature(XmppFeatures.UserTune)); Features.Add(new XmppServiceFeature(XmppFeatures.UserTuneWithNotify)); Features.Add(new XmppServiceFeature(XmppFeatures.XmppPing)); }
/// <summary> /// Initializes a new instance of the <see cref="T:XmppServiceDiscovery"/> class. /// </summary> /// <param name="session">The session.</param> public XmppServiceDiscovery(XmppSession session, string domainName) : this(session) { this.domainName = domainName; }
/// <summary> /// Initializes a new instance of the <see cref="XmppContactEntityCapabilities"/> class. /// </summary> internal XmppContactEntityCapabilities(XmppSession session, XmppContactResource resource) : base(session) { this.resource = resource; this.pendingMessages = new List<string>(); }
internal AmipNowPlayingListerner(XmppSession session) { this.session = session; }
/// <summary> /// Initiazes a new instance of the <see cref = "XmppGatewayService">XmppGatewayService</see> class. /// </summary> /// <param name = "session"></param> /// <param name = "serviceId"></param> public XmppGatewayService(XmppSession session, string serviceId) : base(session, serviceId) { InferGatewayType(); }
/// <summary> /// Initializes a new instance of the <see cref = "XmppEntityCapabilities" /> class. /// </summary> protected XmppEntityCapabilities(XmppSession session) { this.session = session; SubscribeToSessionState(); }
internal XmppServiceItem(XmppSession session, string identifier) : base(session, identifier) { }