void HandleSubscribe(XElement Node) { if (OnSubscribe == null) { return; } JID From = new JID(Node.Attribute("from").Value); SubscribeResponse Action = OnSubscribe.Invoke(From); if (Action == SubscribeResponse.Reject) { return; } XElement PresenceTag = new XElement("presence"); PresenceTag.SetAttributeValue("to", From.GetBareJID()); PresenceTag.SetAttributeValue("type", "subscribed"); Uplink.GetNetworkClient().WriteTextToSocket(PresenceTag.ToString()); if (Action == SubscribeResponse.Allow) { return; } Subscribe(From); }
public override void EnforceAttributes(JID From) { base.EnforceAttributes(From); switch (MessageType) { case StanzaMessageType.Chat: Payload.SetAttributeValue("type", "chat"); break; case StanzaMessageType.Error: Payload.SetAttributeValue("type", "error"); break; case StanzaMessageType.Groupchat: Payload.SetAttributeValue("type", "groupchat"); break; case StanzaMessageType.Headline: Payload.SetAttributeValue("type", "headline"); break; case StanzaMessageType.Normal: Payload.SetAttributeValue("type", "normal"); break; } }
public Connection(string Hostname, int Portnumber, JID RequestedJID, X509Certificate2 Certificate) : this(Hostname, Portnumber, RequestedJID, null, Certificate) { }
List <ResourceAccess> GetAccessRights(DXMPP.JID Actor, AccessToken Token) { try { AccessTokenSession TV = AccessTokens[Actor.GetBareJID() + Token]; if (TV.ExpiresAtUTC <= DateTime.UtcNow) { AccessTokens.TryRemove(Token, out TV); throw new AccessViolation(); } if (TV.Actor.GetBareJID() != Actor.GetBareJID()) { throw new AccessViolation(); } return(TV.Rights); } catch { if (ForceAccessTokenSessions) { throw new AccessViolation(); } } throw new AccessViolation(); }
public Connection(string Hostname, int Portnumber, JID RequestedJID, X509Certificate2 Certificate, int DebugLevel = 0) : this(Hostname, Portnumber, RequestedJID, null, Certificate, false, 30, DebugLevel) { }
public void Unsubscribe(JID To) { XElement PresenceTag = new XElement("presence"); PresenceTag.SetAttributeValue("to", To.GetBareJID()); PresenceTag.SetAttributeValue("type", "unsubscribe"); Uplink.GetNetworkClient().WriteTextToSocket(PresenceTag.ToString()); }
void PresenceHandler(XElement Node) { string type = "available"; if (Node.Attribute("type") != null) { type = Node.Attribute("type").Value; } switch (type) { case "subcribe": HandleSubscribe(Node); return; case "subcribed": HandleSubscribed(Node); return; case "unsubscribe": HandleUnsubscribe(Node); return; case "unsubscribed": HandleUnsubscribed(Node); return; } JID From = new JID(Node.Attribute("from").Value); int Priority = 0; XElement PrioNode = Node.XPathSelectElement("//priority"); if (PrioNode != null) { Priority = Convert.ToInt32(PrioNode.Value); } string Show = string.Empty; string Status = string.Empty; XElement ShowNode = Node.XPathSelectElement("//show"); if (ShowNode != null) { Show = ShowNode.Value; } XElement StatusNode = Node.XPathSelectElement("//status"); if (StatusNode != null) { Show = StatusNode.Value; } if (OnPresence != null) { OnPresence.Invoke(From, Status != "unavailable", Priority, Status, Show); } }
void HandleUnsubscribed(XElement Node) { if (OnUnsubscribed == null) { return; } JID From = new JID(Node.Attribute("from").Value); OnUnsubscribed.Invoke(From); }
public virtual void EnforceAttributes(JID From) { if (To != null) { Payload.SetAttributeValue("to", To.ToString()); } if (From != null) { Payload.SetAttributeValue("from", From.ToString()); } Payload.SetAttributeValue("id", ID); }
public Connection(string Hostname, int Portnumber, JID RequestedJID, string Password, X509Certificate2 Certificate = null) { this.Hostname = Hostname; this.Portnumber = Portnumber; this.MyJID = RequestedJID; if (MyJID.GetResource() == string.Empty) { MyJID.SetResource(System.Guid.NewGuid().ToString()); } this.Password = Password; this.RosterMaintainer = new Roster(this); this.Certificate = Certificate; }
void CheckForBindSuccess(XElement Doc) { if (Doc.Name.LocalName != "iq") { Console.WriteLine("no iqnode?!"); BroadcastConnectionState(CallbackConnectionState.ErrorUnknown); CurrentConnectionState = ConnectionState.ErrorUnknown; return; } this.MyJID = new JID((Doc.FirstNode as XElement).Value); string StartSession = "<iq type='set' id='1'><session xmlns='urn:ietf:params:xml:ns:xmpp-session'/></iq>"; Client.WriteTextToSocket(StartSession); CurrentConnectionState = ConnectionState.WaitingForSession; CurrentAuthenticationState = AuthenticationState.Authenticated; }
public Stanza(XElement Payload) { this.Payload = Payload; if (Payload.Attribute("to") != null) { To = new JID(Payload.Attribute("to").Value); } if (Payload.Attribute("from") != null) { From = new JID(Payload.Attribute("from").Value); } if (Payload.Attribute("id") != null) { this.ID = Payload.Attribute("id").Value; } }
public Connection(string Hostname, int Portnumber, JID RequestedJID, string Password, X509Certificate2 Certificate = null, bool AllowSelfSignedServerCertificate = false, int KeepAliveByWhiteSpaceInterval = 30, int DebugLevel = 0) { this.Hostname = Hostname; this.Portnumber = Portnumber; this.MyJID = RequestedJID; if (MyJID.GetResource() == string.Empty) { MyJID.SetResource(System.Guid.NewGuid().ToString()); } this.Password = Password; this.RosterMaintainer = new Roster(this); this.Certificate = Certificate; this.AllowSelfSignedServerCertificate = AllowSelfSignedServerCertificate; this.KeepAliveByWhiteSpaceInterval = KeepAliveByWhiteSpaceInterval; this.DebugLevel = DebugLevel; }
public override void EnforceAttributes(JID From) { base.EnforceAttributes(From); switch (IQType) { case StanzaIQType.Get: Payload.SetAttributeValue("type", "get"); break; case StanzaIQType.Set: Payload.SetAttributeValue("type", "set"); break; case StanzaIQType.Result: Payload.SetAttributeValue("type", "result"); break; case StanzaIQType.Error: Payload.SetAttributeValue("type", "error"); break; } }
void PresenceHandler(XElement Node) { string type = "available"; if (Node.Attribute("type") != null) { type = Node.Attribute("type").Value; } switch (type) { case "subscribe": HandleSubscribe(Node); return; case "subscribed": HandleSubscribed(Node); return; case "unsubscribe": HandleUnsubscribe(Node); return; case "unsubscribed": HandleUnsubscribed(Node); return; } JID From = new JID(Node.Attribute("from").Value); int Priority = 0; XElement PrioNode = Node.XPathSelectElement("//priority"); if (PrioNode != null) { Priority = Convert.ToInt32(PrioNode.Value); } string Show = string.Empty; string Status = string.Empty; XElement ShowNode = Node.XPathSelectElement("//show"); if (ShowNode != null) { Show = ShowNode.Value; } XElement StatusNode = Node.XPathSelectElement("//status"); if (StatusNode != null) { Show = StatusNode.Value; } PresenceInformation PI = new PresenceInformation() { FullJID = From, Priority = Priority, Show = Show, Status = Status }; if (!AggregatedPresence.ContainsKey(From.GetBareJID())) { AggregatedPresence[From.GetBareJID()] = new List <PresenceInformation>(); } AggregatedPresence[From.GetBareJID()].Add(PI); if (OnPresence != null) { OnPresence.Invoke(From, Status != "unavailable", Priority, Status, Show); } }
public new void EnforceAttributes(JID From) { base.EnforceAttributes(From); }