private void Parse(string address) { Match match = AddressRegex.Match(address); this.userName = String.Empty; this.domainName = String.Empty; this.resourceName = String.Empty; if (match != null) { // The Local part is optional if (match.Groups["localpart"] != null) { this.userName = Stringprep.NamePrep(match.Groups["localpart"].Value); } // The Domain part is mandatory this.domainName = Stringprep.NodePrep(match.Groups["domainpart"].Value); // The Resource part is optional if (match.Groups["resourcepart"] != null) { this.resourceName = Stringprep.ResourcePrep(match.Groups["resourcepart"].Value); } } this.Update(); }
public void StreamStartHandle(XmppStream xmppStream, Stream stream, XmppHandlerContext context) { lock (this) { //Check tennats here if (ValidateHost(stream.To)) { //Create new services foreach (var template in templates) { var service = (IXmppService)Activator.CreateInstance(template.Value); service.Jid = new Jid(Stringprep.NamePrep(string.Format("{0}.{1}", template.Key, stream.To.Server).Trim('.'))); if (serviceManager.GetService(service.Jid) != null) { continue; } service.Name = service.Jid.ToString(); if (!string.IsNullOrEmpty(template.Key)) { service.ParentService = serviceManager.GetService(new Jid(Stringprep.NamePrep(stream.To.Server))); } service.Configure(new Dictionary <string, string>()); serviceManager.RegisterService(service); } //Reroute handlerManager.ProcessStreamStart(stream, Uri.CLIENT, xmppStream); } else { context.Sender.SendToAndClose(xmppStream, XmppStreamError.HostUnknown); } } }
/// <summary> /// Initializes a new instance of the <see cref = "XmppJid" /> class with /// the given user name, domain name and resource name. /// </summary> /// <param name = "userName">The user name</param> /// <param name = "domainName">The domain name</param> /// <param name = "resourceName">The resource name</param> public XmppJid(string userName, string domainName, string resourceName) { this.userName = Stringprep.NamePrep(userName); this.domainName = Stringprep.NodePrep(domainName); this.resourceName = Stringprep.ResourcePrep(resourceName); BuildBareAndFullJid(); }
/// <summary> /// Initializes a new instance of the <see cref="XmppAddress"/> class with /// the given user name, domain name and resource name. /// </summary> /// <param name="userName">The user name</param> /// <param name="domainName">The domain name</param> /// <param name="resourceName">The resource name</param> public XmppAddress(string userName, string domainName, string resourceName) { this.userName = Stringprep.NamePrep(userName); this.domainName = Stringprep.NodePrep(domainName); this.resourceName = Stringprep.ResourcePrep(resourceName); this.Update(); }
private static void ConfigureServices(JabberConfigurationSection jabberSection, XmppServer server) { foreach (ServiceConfigurationElement se in jabberSection.Services) { var service = (IXmppService)Activator.CreateInstance(Type.GetType(se.TypeName, true)); service.Jid = new Jid(Stringprep.NamePrep(se.Jid)); service.Name = se.Name; if (!string.IsNullOrEmpty(se.Parent)) { service.ParentService = server.GetXmppService(new Jid(Stringprep.NamePrep(se.Parent))); } service.Configure(se.GetProperties()); server.RegisterXmppService(service); } }
private Jid NodePrep(Jid jid) { if (jid != null) { if (jid.HasUser) { jid.User = Stringprep.NodePrep(jid.User); } if (jid.HasResource) { jid.Resource = Stringprep.ResourcePrep(jid.Resource); } //BUG: Many faults here in log jid.Server = Stringprep.NamePrep(jid.Server); } return(jid); }
/// <summary> /// builds a new Jid object /// </summary> /// <param name="user">XMPP User part</param> /// <param name="server">XMPP Domain part</param> /// <param name="resource">XMPP Resource part</param> public Jid(string user, string server, string resource, bool stringprep = false) { if (!stringprep) { if (user != null) { user = EscapeNode(user); this.m_User = user.ToLower(); } if (server != null) { this.m_Server = server.ToLower(); } if (resource != null) { this.m_Resource = resource; } } else { if (user != null) { user = EscapeNode(user); this.m_User = Stringprep.NodePrep(user); } if (server != null) { this.m_Server = Stringprep.NamePrep(server); } if (resource != null) { this.m_Resource = Stringprep.ResourcePrep(resource); } } this.BuildJid(); }
/// <summary> /// builds a new Jid object /// </summary> /// <param name="user">XMPP User part</param> /// <param name="server">XMPP Domain part</param> /// <param name="resource">XMPP Resource part</param> public Jid(string user, string server, string resource) { #if !STRINGPREP if (user != null) { user = EscapeNode(user); m_User = user.ToLower(); } if (server != null) { m_Server = server.ToLower(); } if (resource != null) { m_Resource = resource; } #else if (user != null) { user = EscapeNode(user); m_User = Stringprep.NodePrep(user); } if (server != null) { m_Server = Stringprep.NamePrep(server); } if (resource != null) { m_Resource = Stringprep.ResourcePrep(resource); } #endif BuildJid(); }
private void Parse(string jid) { Match match = JidRegex.Match(jid); if (match != null) { if (match.Groups["userid"] != null) { userName = Stringprep.NamePrep(match.Groups["userid"].Value); } if (match.Groups["domain"] != null) { domainName = Stringprep.NodePrep(match.Groups["domain"].Value); } if (match.Groups["resource"] != null) { resourceName = Stringprep.ResourcePrep(match.Groups["resource"].Value); } } BuildBareAndFullJid(); }
private string Nameprep(string value) { return(string.IsNullOrEmpty(value) ? value : Stringprep.NamePrep(value)); }
public XmppHandlerResult ProcessElement(RegisterIq element, XmppSession session, XmppHandlerContext context) { if (element.Type == IqType.get) { element.Query.Instructions = RS.RegisterInstructions; element.Query.Username = string.Empty; element.Query.Password = string.Empty; element.ToResult(); if (session.Jid.HasUser && context.Storages.Users.GetUser(session.Jid.User) != null) { element.Query.Username = session.Jid.User; element.Query.AddChild(new Element("registered")); } else { element.To = null; } element.From = null; return(Send(session, element)); } else { if (element.Query.RemoveAccount) { if (!session.Authenticated || !session.Jid.HasUser) { return(Error(session, StreamErrorCondition.NotAuthorized)); } context.Storages.Users.RemoveUser(session.Jid.User); var errors = Component(); foreach (var s in context.Sessions.GetSessions(session.Jid.BareJid)) { if (!session.Equals(s)) { errors.Add(Error(s, StreamErrorCondition.NotAuthorized)); } } element.Query.Remove(); element.ToResult(); element.From = element.To = null; return(Component(Send(session, element), errors)); } if (string.IsNullOrEmpty(element.Query.Username)) { return(Error(session, ErrorCondition.NotAcceptable, element, RS.RegisterEmptyUsername)); } if (string.IsNullOrEmpty(element.Query.Password)) { return(Error(session, ErrorCondition.NotAcceptable, element, RS.RegisterEmptyPassword)); } if (Stringprep.NamePrep(element.Query.Username) != element.Query.Username) { return(Error(session, ErrorCondition.NotAcceptable, element, RS.RegisterInvalidCharacter)); } var user = context.Storages.Users.GetUser(element.Query.Username); if (user != null && user.Name != session.Jid.User) { return(Error(session, ErrorCondition.Conflict, element)); } context.Storages.Users.SaveUser(new XmppUser(element.Query.Username, element.Query.Password)); element.Query.Remove(); element.ToResult(); if (!session.Authenticated) { element.To = null; } element.From = null; return(Send(session, element)); } }
private IQ SetRegister(XmppStream stream, IQ iq, XmppHandlerContext context) { var register = (Register)iq.Query; iq.Type = IqType.result; if (register.RemoveAccount) { if (!stream.Authenticated || !iq.From.HasUser) { context.Sender.SendToAndClose(stream, XmppStreamError.NotAuthorized); } context.UserManager.RemoveUser(iq.From); foreach (var s in context.SessionManager.GetBareJidSessions(iq.From)) { if (s.Stream.Id == stream.Id) { continue; } context.Sender.SendToAndClose(s.Stream, XmppStreamError.Conflict); } //TODO: remove roster subscriptions register.RemoveAllChildNodes(); iq.SwitchDirection(); return(iq); } if (string.IsNullOrEmpty(register.Username) || string.IsNullOrEmpty(register.Password) || Stringprep.NamePrep(register.Username) != register.Username) { var error = XmppStanzaError.ToNotAcceptable(iq); if (string.IsNullOrEmpty(register.Username)) { error.Error.Message = "Empty required field Username."; } else if (string.IsNullOrEmpty(register.Password)) { error.Error.Message = "Empty required field Password."; } else if (Stringprep.NamePrep(register.Username) != register.Username) { error.Error.Message = "Invalid character."; } return(error); } var userJid = new Jid(register.Username, stream.Domain, null); if (context.UserManager.IsUserExists(userJid)) { return(XmppStanzaError.ToConflict(iq)); } var user = new User(userJid, register.Password); context.UserManager.SaveUser(user); register.RemoveAllChildNodes(); if (stream.Authenticated) { iq.SwitchDirection(); } else { iq.To = null; } iq.From = null; return(iq); }