From 4725e5f17445a5f5b464b3011a8920177155aaae Mon Sep 17 00:00:00 2001 From: lumi Date: Mon, 27 Feb 2017 15:35:57 +0100 Subject: [PATCH 01/73] initial commit --- .gitignore | 2 + Cargo.toml | 6 ++ src/lib.rs | 311 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 319 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 src/lib.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..a9d37c560c6ab8d4afbf47eda643e8c42e857716 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +target +Cargo.lock diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..2197a7982491878d4b1642a993d9351b27e0292e --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "jid" +version = "0.1.0" +authors = ["lumi "] + +[dependencies] diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000000000000000000000000000000000000..8214cf1e10eba56007b08f8798b7d35f141faf71 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,311 @@ +//! Provides a type for Jabber IDs. + +use std::fmt; + +use std::convert::Into; + +use std::str::FromStr; + +/// An error that signifies that a `Jid` cannot be parsed from a string. +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum JidParseError { + NoDomain, +} + +/// A struct representing a Jabber ID. +/// +/// A Jabber ID is composed of 3 components, of which 2 are optional: +/// +/// - A node/name, `node`, which is the optional part before the @. +/// - A domain, `domain`, which is the mandatory part after the @ but before the /. +/// - A resource, `resource`, which is the optional part after the /. +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct Jid { + /// The node part of the Jabber ID, if it exists, else None. + pub node: Option, + /// The domain of the Jabber ID. + pub domain: String, + /// The resource of the Jabber ID, if it exists, else None. + pub resource: Option, +} + +impl fmt::Display for Jid { + fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> { + // TODO: may need escaping + if let Some(ref node) = self.node { + write!(fmt, "{}@", node)?; + } + write!(fmt, "{}", self.domain)?; + if let Some(ref resource) = self.resource { + write!(fmt, "/{}", resource)?; + } + Ok(()) + } +} + +enum ParserState { + Node, + Domain, + Resource +} + +impl FromStr for Jid { + type Err = JidParseError; + + fn from_str(s: &str) -> Result { + // TODO: very naive, may need to do it differently + let iter = s.chars(); + let mut buf = String::new(); + let mut state = ParserState::Node; + let mut node = None; + let mut domain = None; + let mut resource = None; + for c in iter { + match state { + ParserState::Node => { + match c { + '@' => { + state = ParserState::Domain; + node = Some(buf.clone()); // TODO: performance tweaks, do not need to copy it + buf.clear(); + }, + '/' => { + state = ParserState::Resource; + domain = Some(buf.clone()); // TODO: performance tweaks + buf.clear(); + }, + c => { + buf.push(c); + }, + } + }, + ParserState::Domain => { + match c { + '/' => { + state = ParserState::Resource; + domain = Some(buf.clone()); // TODO: performance tweaks + buf.clear(); + }, + c => { + buf.push(c); + }, + } + }, + ParserState::Resource => { + buf.push(c); + }, + } + } + if !buf.is_empty() { + match state { + ParserState::Node => { + domain = Some(buf); + }, + ParserState::Domain => { + domain = Some(buf); + }, + ParserState::Resource => { + resource = Some(buf); + }, + } + } + Ok(Jid { + node: node, + domain: domain.ok_or(JidParseError::NoDomain)?, + resource: resource, + }) + } +} + +impl Jid { + /// Constructs a Jabber ID containing all three components. + /// + /// This is of the form `node`@`domain`/`resource`. + /// + /// # Examples + /// + /// ``` + /// use jid::Jid; + /// + /// let jid = Jid::full("node", "domain", "resource"); + /// + /// assert_eq!(jid.node, Some("node".to_owned())); + /// assert_eq!(jid.domain, "domain".to_owned()); + /// assert_eq!(jid.resource, Some("resource".to_owned())); + /// ``` + pub fn full(node: NS, domain: DS, resource: RS) -> Jid + where NS: Into + , DS: Into + , RS: Into { + Jid { + node: Some(node.into()), + domain: domain.into(), + resource: Some(resource.into()), + } + } + + /// Constructs a Jabber ID containing only the `node` and `domain` components. + /// + /// This is of the form `node`@`domain`. + /// + /// # Examples + /// + /// ``` + /// use jid::Jid; + /// + /// let jid = Jid::bare("node", "domain"); + /// + /// assert_eq!(jid.node, Some("node".to_owned())); + /// assert_eq!(jid.domain, "domain".to_owned()); + /// assert_eq!(jid.resource, None); + /// ``` + pub fn bare(node: NS, domain: DS) -> Jid + where NS: Into + , DS: Into { + Jid { + node: Some(node.into()), + domain: domain.into(), + resource: None, + } + } + + /// Constructs a Jabber ID containing only a `domain`. + /// + /// This is of the form `domain`. + /// + /// # Examples + /// + /// ``` + /// use jid::Jid; + /// + /// let jid = Jid::domain("domain"); + /// + /// assert_eq!(jid.node, None); + /// assert_eq!(jid.domain, "domain".to_owned()); + /// assert_eq!(jid.resource, None); + /// ``` + pub fn domain(domain: DS) -> Jid + where DS: Into { + Jid { + node: None, + domain: domain.into(), + resource: None, + } + } + + /// Constructs a Jabber ID containing the `domain` and `resource` components. + /// + /// This is of the form `domain`/`resource`. + /// + /// # Examples + /// + /// ``` + /// use jid::Jid; + /// + /// let jid = Jid::domain_with_resource("domain", "resource"); + /// + /// assert_eq!(jid.node, None); + /// assert_eq!(jid.domain, "domain".to_owned()); + /// assert_eq!(jid.resource, Some("resource".to_owned())); + /// ``` + pub fn domain_with_resource(domain: DS, resource: RS) -> Jid + where DS: Into + , RS: Into { + Jid { + node: None, + domain: domain.into(), + resource: Some(resource.into()), + } + } + + /// Constructs a new Jabber ID from an existing one, with the node swapped out with a new one. + /// + /// # Examples + /// + /// ``` + /// use jid::Jid; + /// + /// let jid = Jid::domain("domain"); + /// + /// assert_eq!(jid.node, None); + /// + /// let new_jid = jid.with_node("node"); + /// + /// assert_eq!(new_jid.node, Some("node".to_owned())); + /// ``` + pub fn with_node(&self, node: S) -> Jid + where S: Into { + Jid { + node: Some(node.into()), + domain: self.domain.clone(), + resource: self.resource.clone(), + } + } + + /// Constructs a new Jabber ID from an existing one, with the domain swapped out with a new one. + /// + /// # Examples + /// + /// ``` + /// use jid::Jid; + /// + /// let jid = Jid::domain("domain"); + /// + /// assert_eq!(jid.domain, "domain"); + /// + /// let new_jid = jid.with_domain("new_domain"); + /// + /// assert_eq!(new_jid.domain, "new_domain"); + /// ``` + pub fn with_domain(&self, domain: S) -> Jid + where S: Into { + Jid { + node: self.node.clone(), + domain: domain.into(), + resource: self.resource.clone(), + } + } + + /// Constructs a new Jabber ID from an existing one, with the resource swapped out with a new one. + /// + /// # Examples + /// + /// ``` + /// use jid::Jid; + /// + /// let jid = Jid::domain("domain"); + /// + /// assert_eq!(jid.resource, None); + /// + /// let new_jid = jid.with_resource("resource"); + /// + /// assert_eq!(new_jid.resource, Some("resource".to_owned())); + /// ``` + pub fn with_resource(&self, resource: S) -> Jid + where S: Into { + Jid { + node: self.node.clone(), + domain: self.domain.clone(), + resource: Some(resource.into()), + } + } + +} + +#[cfg(test)] +mod tests { + use super::*; + + use std::str::FromStr; + + #[test] + fn can_parse_jids() { + assert_eq!(Jid::from_str("a@b.c/d"), Ok(Jid::full("a", "b.c", "d"))); + assert_eq!(Jid::from_str("a@b.c"), Ok(Jid::bare("a", "b.c"))); + assert_eq!(Jid::from_str("b.c"), Ok(Jid::domain("b.c"))); + + assert_eq!(Jid::from_str(""), Err(JidParseError::NoDomain)); + + assert_eq!(Jid::from_str("a/b@c"), Ok(Jid::domain_with_resource("a", "b@c"))); + } +} From 5308b6b1f1715c17f4df00d05fdc9f39dc15a8ff Mon Sep 17 00:00:00 2001 From: lumi Date: Mon, 27 Feb 2017 15:06:15 +0000 Subject: [PATCH 02/73] Add .gitlab-ci.yml --- .gitlab-ci.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..cb292343052f44cf4efaa6f5bd686defc527ae8a --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,6 @@ +image: "scorpil/rust:stable" + +test:cargo: + script: + - rustc --version && cargo --version + - cargo test --verbose --jobs 1 --release \ No newline at end of file From 19efcf3560a5c4bdc14c300ed87b8ef463783831 Mon Sep 17 00:00:00 2001 From: lumi Date: Mon, 27 Feb 2017 16:42:09 +0100 Subject: [PATCH 03/73] add license, prepare for release --- COPYING | 675 +++++++++++++++++++++++++++++++++++++++++++++++++ COPYING.LESSER | 166 ++++++++++++ Cargo.toml | 10 + README.md | 31 +++ src/lib.rs | 2 + 5 files changed, 884 insertions(+) create mode 100644 COPYING create mode 100644 COPYING.LESSER create mode 100644 README.md diff --git a/COPYING b/COPYING new file mode 100644 index 0000000000000000000000000000000000000000..a737dcfed5db21fb99a8fcb812e995937d38401b --- /dev/null +++ b/COPYING @@ -0,0 +1,675 @@ + + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/COPYING.LESSER b/COPYING.LESSER new file mode 100644 index 0000000000000000000000000000000000000000..5f5ff16a4a0f6104fadb6a5beef527573e46b425 --- /dev/null +++ b/COPYING.LESSER @@ -0,0 +1,166 @@ + + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/Cargo.toml b/Cargo.toml index 2197a7982491878d4b1642a993d9351b27e0292e..95026c8e5e9144985becef8109c425b46e253d14 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,5 +2,15 @@ name = "jid" version = "0.1.0" authors = ["lumi "] +description = "A crate which provides a Jid struct for Jabber IDs." +homepage = "https://gitlab.com/lumi/jid-rs" +repository = "https://gitlab.com/lumi/jid-rs" +documentation = "https://docs.rs/jid" +readme = "README.md" +keywords = ["xmpp", "jid"] +license = "LGPL-3.0+" + +[badges] +gitlab = { repository = "lumi/jid-rs" } [dependencies] diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..8610e178b008ad6f6e42bc2d60b59b5e51b44511 --- /dev/null +++ b/README.md @@ -0,0 +1,31 @@ +jid-rs +====== + +What's this? +------------ + +A crate which provides a struct Jid for Jabber IDs. It's used in xmpp-rs but other XMPP libraries +can of course use this. + +What license is it under? +------------------------- + +LGPLv3 or later. See `COPYING` and `COPYING.LESSER`. + +License yadda yadda. +-------------------- + + Copyright 2017, jid-rs contributors. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . diff --git a/src/lib.rs b/src/lib.rs index 8214cf1e10eba56007b08f8798b7d35f141faf71..91a744bb2152804b6d69298c602e92a1f929a788 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,6 @@ //! Provides a type for Jabber IDs. +//! +//! For usage, check the documentation on the `Jid` struct. use std::fmt; From 5ae85aa8844a8ecc496f70e93652f291dbf0e7ec Mon Sep 17 00:00:00 2001 From: lumi Date: Tue, 28 Feb 2017 12:38:00 +0100 Subject: [PATCH 04/73] add #![deny(missing_docs)] and documentation --- src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 91a744bb2152804b6d69298c602e92a1f929a788..74f1d3cc1a768930cd956e14f451a1883c1bf923 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,5 @@ +#![deny(missing_docs)] + //! Provides a type for Jabber IDs. //! //! For usage, check the documentation on the `Jid` struct. @@ -11,6 +13,7 @@ use std::str::FromStr; /// An error that signifies that a `Jid` cannot be parsed from a string. #[derive(Debug, Clone, PartialEq, Eq)] pub enum JidParseError { + /// Happens when there is no domain. (really, only happens when the string is empty) NoDomain, } From 0d2fda806475b5a02fcda016078350635b9fd70f Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sun, 23 Apr 2017 14:49:00 +0100 Subject: [PATCH 05/73] implement From on String --- src/lib.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 74f1d3cc1a768930cd956e14f451a1883c1bf923..fead7e730ad0b595c7ad28dad9c48fae5d1c7f77 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,6 +34,22 @@ pub struct Jid { pub resource: Option, } +impl From for String { + fn from(jid: Jid) -> String { + let mut string = String::new(); + if let Some(ref node) = jid.node { + string.push_str(node); + string.push('@'); + } + string.push_str(&jid.domain); + if let Some(ref resource) = jid.resource { + string.push('/'); + string.push_str(resource); + } + string + } +} + impl fmt::Display for Jid { fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> { // TODO: may need escaping @@ -313,4 +329,9 @@ mod tests { assert_eq!(Jid::from_str("a/b@c"), Ok(Jid::domain_with_resource("a", "b@c"))); } + + #[test] + fn serialise() { + assert_eq!(String::from(Jid::full("a", "b", "c")), String::from("a@b/c")); + } } From bbde01160ac224007dacf36964aad28d6090da14 Mon Sep 17 00:00:00 2001 From: lumi Date: Sun, 23 Apr 2017 17:20:50 +0200 Subject: [PATCH 06/73] Add a note about not supporting RFC7622 yet. --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 8610e178b008ad6f6e42bc2d60b59b5e51b44511..e4b4fd370f7172f0fc2bed9773a095d2178fef54 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,11 @@ What license is it under? LGPLv3 or later. See `COPYING` and `COPYING.LESSER`. +Notes +----- + +This library does not yet implement RFC7622. + License yadda yadda. -------------------- From 90c4aec54f3789a2c81992789db63bffbaec30c8 Mon Sep 17 00:00:00 2001 From: lumi Date: Sun, 23 Apr 2017 17:23:09 +0200 Subject: [PATCH 07/73] Bump the version number up to 0.2.0. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 95026c8e5e9144985becef8109c425b46e253d14..8ac64e9c1d78967e206d4e44778be5521d4c19a3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "jid" -version = "0.1.0" +version = "0.2.0" authors = ["lumi "] description = "A crate which provides a Jid struct for Jabber IDs." homepage = "https://gitlab.com/lumi/jid-rs" From 0288b937df2ba5ba2e89a389fdba0d8087f9061e Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sun, 30 Apr 2017 21:44:02 +0100 Subject: [PATCH 08/73] Simplify the Display implementation. --- src/lib.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index fead7e730ad0b595c7ad28dad9c48fae5d1c7f77..37d43fa02127dbbdcb38c47623b45d6affc8eb39 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -52,14 +52,7 @@ impl From for String { impl fmt::Display for Jid { fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> { - // TODO: may need escaping - if let Some(ref node) = self.node { - write!(fmt, "{}@", node)?; - } - write!(fmt, "{}", self.domain)?; - if let Some(ref resource) = self.resource { - write!(fmt, "/{}", resource)?; - } + fmt.write_str(String::from(self.clone()).as_ref())?; Ok(()) } } From c13cebf02587390dabbd48f04f4e686c63a6c1b2 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sun, 30 Apr 2017 21:44:17 +0100 Subject: [PATCH 09/73] Implement the Debug trait in a more user-friendly way. --- src/lib.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 37d43fa02127dbbdcb38c47623b45d6affc8eb39..04f8c2e18a3da897b665823e0f40664d0e203491 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,7 +24,7 @@ pub enum JidParseError { /// - A node/name, `node`, which is the optional part before the @. /// - A domain, `domain`, which is the mandatory part after the @ but before the /. /// - A resource, `resource`, which is the optional part after the /. -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Clone, PartialEq, Eq)] pub struct Jid { /// The node part of the Jabber ID, if it exists, else None. pub node: Option, @@ -50,6 +50,13 @@ impl From for String { } } +impl fmt::Debug for Jid { + fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> { + write!(fmt, "JID({})", self)?; + Ok(()) + } +} + impl fmt::Display for Jid { fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> { fmt.write_str(String::from(self.clone()).as_ref())?; From 4cca174f68c2cb364ea900de6584b660a42f5bcb Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sat, 27 May 2017 20:45:00 +0100 Subject: [PATCH 10/73] Implement the Hash trait on Jid. --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 04f8c2e18a3da897b665823e0f40664d0e203491..b78001b05053436b49041500f83232c578f57286 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,7 +24,7 @@ pub enum JidParseError { /// - A node/name, `node`, which is the optional part before the @. /// - A domain, `domain`, which is the mandatory part after the @ but before the /. /// - A resource, `resource`, which is the optional part after the /. -#[derive(Clone, PartialEq, Eq)] +#[derive(Clone, PartialEq, Eq, Hash)] pub struct Jid { /// The node part of the Jabber ID, if it exists, else None. pub node: Option, From abaf16079c9a10210785ff338b78b1f84229c91a Mon Sep 17 00:00:00 2001 From: lumi Date: Sat, 27 May 2017 23:18:46 +0200 Subject: [PATCH 11/73] add linkmauve to authors, bump version to 0.2.1 --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8ac64e9c1d78967e206d4e44778be5521d4c19a3..5a18dc9978757d36483b399b98f8ef6fc00fff7c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "jid" -version = "0.2.0" -authors = ["lumi "] +version = "0.2.1" +authors = ["lumi ", "Emmanuel Gil Peyrot "] description = "A crate which provides a Jid struct for Jabber IDs." homepage = "https://gitlab.com/lumi/jid-rs" repository = "https://gitlab.com/lumi/jid-rs" From 072cba6a3ed6389886fcd87ff9ec71eb8f9ab524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Mon, 12 Jun 2017 17:40:39 +0100 Subject: [PATCH 12/73] Add get_ functions that return new truncated structs from the current one --- src/lib.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index b78001b05053436b49041500f83232c578f57286..323c43f640f34aa1583421842f1603974af01a5b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -190,6 +190,28 @@ impl Jid { } } + /// Returns a new Jabber ID from the current one with only node and domain. + /// + /// This is of the form `node`@`domain`. + /// + /// # Examples + /// + /// ``` + /// use jid::Jid; + /// + /// let jid = Jid::full("node", "domain", "resource").get_bare(); + /// + /// assert_eq!(jid.node, Some("node".to_owned())); + /// assert_eq!(jid.domain, "domain".to_owned()); + /// assert_eq!(jid.resource, None); + pub fn get_bare(self) -> Jid { + Jid { + node: self.node.clone(), + domain: self.domain.clone(), + resource: None, + } + } + /// Constructs a Jabber ID containing only a `domain`. /// /// This is of the form `domain`. @@ -214,6 +236,28 @@ impl Jid { } } + /// Returns a new Jabber ID from the current one with only domain. + /// + /// This is of the form `domain`. + /// + /// # Examples + /// + /// ``` + /// use jid::Jid; + /// + /// let jid = Jid::full("node", "domain", "resource").get_domain(); + /// + /// assert_eq!(jid.node, None); + /// assert_eq!(jid.domain, "domain".to_owned()); + /// assert_eq!(jid.resource, None); + pub fn get_domain(self) -> Jid { + Jid { + node: None, + domain: self.domain.clone(), + resource: None, + } + } + /// Constructs a Jabber ID containing the `domain` and `resource` components. /// /// This is of the form `domain`/`resource`. From 10ab104ea011a503ecd0eb1e62ad74c4449eea4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Mon, 12 Jun 2017 17:46:06 +0100 Subject: [PATCH 13/73] Better without clones --- src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 323c43f640f34aa1583421842f1603974af01a5b..56de906a15504a42f10304743a7fb4d7e06e2c25 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -206,8 +206,8 @@ impl Jid { /// assert_eq!(jid.resource, None); pub fn get_bare(self) -> Jid { Jid { - node: self.node.clone(), - domain: self.domain.clone(), + node: self.node, + domain: self.domain, resource: None, } } @@ -253,7 +253,7 @@ impl Jid { pub fn get_domain(self) -> Jid { Jid { node: None, - domain: self.domain.clone(), + domain: self.domain, resource: None, } } From b69ecb31aa69669a25fb5655ee258ee374bf11c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Mon, 12 Jun 2017 18:05:19 +0100 Subject: [PATCH 14/73] Renaming functions --- src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 56de906a15504a42f10304743a7fb4d7e06e2c25..00af16f840aaee132f79fdcc18d438d12cebdeaf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -199,12 +199,12 @@ impl Jid { /// ``` /// use jid::Jid; /// - /// let jid = Jid::full("node", "domain", "resource").get_bare(); + /// let jid = Jid::full("node", "domain", "resource").into_bare_jid(); /// /// assert_eq!(jid.node, Some("node".to_owned())); /// assert_eq!(jid.domain, "domain".to_owned()); /// assert_eq!(jid.resource, None); - pub fn get_bare(self) -> Jid { + pub fn into_bare_jid(self) -> Jid { Jid { node: self.node, domain: self.domain, @@ -245,12 +245,12 @@ impl Jid { /// ``` /// use jid::Jid; /// - /// let jid = Jid::full("node", "domain", "resource").get_domain(); + /// let jid = Jid::full("node", "domain", "resource").into_domain_jid(); /// /// assert_eq!(jid.node, None); /// assert_eq!(jid.domain, "domain".to_owned()); /// assert_eq!(jid.resource, None); - pub fn get_domain(self) -> Jid { + pub fn into_domain_jid(self) -> Jid { Jid { node: None, domain: self.domain, From 2f59ca4b56c392e05b47091ff3c2005ff85fcb2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Mon, 12 Jun 2017 18:20:42 +0100 Subject: [PATCH 15/73] Fix doctests --- src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 00af16f840aaee132f79fdcc18d438d12cebdeaf..5ced40038ffc54efd895bbc4946596eaac8041c3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -204,6 +204,7 @@ impl Jid { /// assert_eq!(jid.node, Some("node".to_owned())); /// assert_eq!(jid.domain, "domain".to_owned()); /// assert_eq!(jid.resource, None); + /// ``` pub fn into_bare_jid(self) -> Jid { Jid { node: self.node, @@ -250,6 +251,7 @@ impl Jid { /// assert_eq!(jid.node, None); /// assert_eq!(jid.domain, "domain".to_owned()); /// assert_eq!(jid.resource, None); + /// ``` pub fn into_domain_jid(self) -> Jid { Jid { node: None, From 1f11796057f867d361c952dc32da7db403b72ff2 Mon Sep 17 00:00:00 2001 From: lumi Date: Mon, 12 Jun 2017 22:28:14 +0200 Subject: [PATCH 16/73] set version to 0.2.2 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 5a18dc9978757d36483b399b98f8ef6fc00fff7c..715fc12844732dd8cf389a2934562545edb51e38 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "jid" -version = "0.2.1" +version = "0.2.2" authors = ["lumi ", "Emmanuel Gil Peyrot "] description = "A crate which provides a Jid struct for Jabber IDs." homepage = "https://gitlab.com/lumi/jid-rs" From e00cfa2c2e8bcdba946c400f7817fdfcbe60b144 Mon Sep 17 00:00:00 2001 From: Bastien Orivel Date: Mon, 12 Jun 2017 23:11:37 +0200 Subject: [PATCH 17/73] Speedup jid parsing name control ns/iter variable ns/iter diff ns/iter diff % speedup big_jids 638 456 -182 -28.53% x 1.40 small_jids 92 91 -1 -1.09% x 1.01 --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 5ced40038ffc54efd895bbc4946596eaac8041c3..3f39cbcfc0378a5589e1ad0e48e2a2d4909b33f3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -76,7 +76,7 @@ impl FromStr for Jid { fn from_str(s: &str) -> Result { // TODO: very naive, may need to do it differently let iter = s.chars(); - let mut buf = String::new(); + let mut buf = String::with_capacity(s.len()); let mut state = ParserState::Node; let mut node = None; let mut domain = None; From 5bd0feb17852e0113ec9263a7503d148f519d4d4 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sat, 29 Jul 2017 05:11:30 +0100 Subject: [PATCH 18/73] optionally implement minidom::IntoAttributeValue --- Cargo.toml | 1 + src/lib.rs | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 715fc12844732dd8cf389a2934562545edb51e38..97c9cf5c61033264f22b55ff447f77564167b258 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,3 +14,4 @@ license = "LGPL-3.0+" gitlab = { repository = "lumi/jid-rs" } [dependencies] +minidom = { version = "0.4.4", optional = true } diff --git a/src/lib.rs b/src/lib.rs index 3f39cbcfc0378a5589e1ad0e48e2a2d4909b33f3..30ba7f7a03ce71dce5861600c2849e53e008be9b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -359,6 +359,19 @@ impl Jid { } +#[cfg(feature = "minidom")] +extern crate minidom; + +#[cfg(feature = "minidom")] +use minidom::IntoAttributeValue; + +#[cfg(feature = "minidom")] +impl IntoAttributeValue for Jid { + fn into_attribute_value(self) -> Option { + Some(String::from(self)) + } +} + #[cfg(test)] mod tests { use super::*; @@ -380,4 +393,12 @@ mod tests { fn serialise() { assert_eq!(String::from(Jid::full("a", "b", "c")), String::from("a@b/c")); } + + #[cfg(feature = "minidom")] + #[test] + fn minidom() { + let elem: minidom::Element = "".parse().unwrap(); + let to: Jid = elem.attr("from").unwrap().parse().unwrap(); + assert_eq!(to, Jid::full("a", "b", "c")); + } } From cbff99b73d27bf8264898e8650053592e11e45ce Mon Sep 17 00:00:00 2001 From: lumi Date: Sat, 29 Jul 2017 12:06:53 +0200 Subject: [PATCH 19/73] bump version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 97c9cf5c61033264f22b55ff447f77564167b258..164e39dcdc892808704d369cc7b74cda6328b38a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "jid" -version = "0.2.2" +version = "0.2.3" authors = ["lumi ", "Emmanuel Gil Peyrot "] description = "A crate which provides a Jid struct for Jabber IDs." homepage = "https://gitlab.com/lumi/jid-rs" From 275719a204f766fcfa841f5ac93f3c6913869522 Mon Sep 17 00:00:00 2001 From: Astro Date: Mon, 14 Aug 2017 23:32:27 +0200 Subject: [PATCH 20/73] bump minidom dependency version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 164e39dcdc892808704d369cc7b74cda6328b38a..44e55843c03fcf6382ce5c2061aab8c13818e5d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,4 +14,4 @@ license = "LGPL-3.0+" gitlab = { repository = "lumi/jid-rs" } [dependencies] -minidom = { version = "0.4.4", optional = true } +minidom = { version = "0.6.0", optional = true } From c82f9b46f443abb60d11361c82d593c1f393dd45 Mon Sep 17 00:00:00 2001 From: lumi Date: Sun, 20 Aug 2017 17:20:09 +0200 Subject: [PATCH 21/73] bump version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 44e55843c03fcf6382ce5c2061aab8c13818e5d0..07b8713aa9f9ce287bcc8c0351077d3c310d7e2b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "jid" -version = "0.2.3" +version = "0.2.4" authors = ["lumi ", "Emmanuel Gil Peyrot "] description = "A crate which provides a Jid struct for Jabber IDs." homepage = "https://gitlab.com/lumi/jid-rs" From 30e6d7b47d8df032f5cbdd82c129c12c5aace531 Mon Sep 17 00:00:00 2001 From: lumi Date: Sun, 20 Aug 2017 17:50:42 +0200 Subject: [PATCH 22/73] woops, had to bump to 0.3.0, not 0.2.4 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 07b8713aa9f9ce287bcc8c0351077d3c310d7e2b..49381517a923ad1c44c6c158decf8bd4fb02f17a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "jid" -version = "0.2.4" +version = "0.3.0" authors = ["lumi ", "Emmanuel Gil Peyrot "] description = "A crate which provides a Jid struct for Jabber IDs." homepage = "https://gitlab.com/lumi/jid-rs" From e0124e50f6f4606e0589aaeef1eab587aeabfab8 Mon Sep 17 00:00:00 2001 From: lumi Date: Sun, 20 Aug 2017 17:52:32 +0200 Subject: [PATCH 23/73] bump minidom dependency to 0.6.1 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 49381517a923ad1c44c6c158decf8bd4fb02f17a..57783567112121287eb378667f1216ce37bfdd1c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,4 +14,4 @@ license = "LGPL-3.0+" gitlab = { repository = "lumi/jid-rs" } [dependencies] -minidom = { version = "0.6.0", optional = true } +minidom = { version = "0.6.1", optional = true } From 2ffa3dc1d9efb6da99cc2f5c7b93c063887bec40 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Tue, 31 Oct 2017 20:24:41 +0000 Subject: [PATCH 24/73] optionally implement minidom::IntoElements --- src/lib.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 30ba7f7a03ce71dce5861600c2849e53e008be9b..f0280d99aab1fa1670c06031411e0795686118ef 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -363,7 +363,7 @@ impl Jid { extern crate minidom; #[cfg(feature = "minidom")] -use minidom::IntoAttributeValue; +use minidom::{IntoAttributeValue, IntoElements, ElementEmitter}; #[cfg(feature = "minidom")] impl IntoAttributeValue for Jid { @@ -372,6 +372,13 @@ impl IntoAttributeValue for Jid { } } +#[cfg(feature = "minidom")] +impl IntoElements for Jid { + fn into_elements(self, emitter: &mut ElementEmitter) { + emitter.append_text_node(String::from(self)) + } +} + #[cfg(test)] mod tests { use super::*; From 5185c0bb9ef22bdc25e80d5e739aa6e55dd91ff1 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Tue, 31 Oct 2017 20:24:47 +0000 Subject: [PATCH 25/73] bump version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 57783567112121287eb378667f1216ce37bfdd1c..e87ebc91d8e10a5b153fddc56ef26cd2a4d4baea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "jid" -version = "0.3.0" +version = "0.3.1" authors = ["lumi ", "Emmanuel Gil Peyrot "] description = "A crate which provides a Jid struct for Jabber IDs." homepage = "https://gitlab.com/lumi/jid-rs" From 054123477693dba9aa72add5121f64855e0ff3d3 Mon Sep 17 00:00:00 2001 From: lumi Date: Tue, 31 Oct 2017 22:51:29 +0100 Subject: [PATCH 26/73] add a changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000000000000000000000000000000000000..55a39f96f1aba2cdb8fed727f47e4ecca2a4fcf2 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +Version 0.3.1, released 10-31-2017: + * Additions + - Link Mauve added a minidom::IntoElements implementation on Jid behind the "minidom" feature. ( https://gitlab.com/lumi/jid-rs/merge_requests/9 ) From 7490799acd43526dc56d518b2bcd1f35decf78cd Mon Sep 17 00:00:00 2001 From: lumi Date: Tue, 31 Oct 2017 22:53:10 +0100 Subject: [PATCH 27/73] fixing the date format in the change log --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 55a39f96f1aba2cdb8fed727f47e4ecca2a4fcf2..63a6cc0743f99dd40ba9e0ef1fcb1e38e30112f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,3 @@ -Version 0.3.1, released 10-31-2017: +Version 0.3.1, released 2017-10-31: * Additions - Link Mauve added a minidom::IntoElements implementation on Jid behind the "minidom" feature. ( https://gitlab.com/lumi/jid-rs/merge_requests/9 ) From a733ea5fb8593bedafd56fd664627bb7236ea17f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Wed, 27 Dec 2017 16:42:07 +0100 Subject: [PATCH 28/73] Update minidom dep to 0.7.0 --- Cargo.toml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e87ebc91d8e10a5b153fddc56ef26cd2a4d4baea..11ae97242c92b159b8e38f1d9dc63eecca5e68a4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,11 @@ [package] name = "jid" -version = "0.3.1" -authors = ["lumi ", "Emmanuel Gil Peyrot "] +version = "0.4.0" +authors = [ + "lumi ", + "Emmanuel Gil Peyrot ", + "Maxime “pep” Buquet ", +] description = "A crate which provides a Jid struct for Jabber IDs." homepage = "https://gitlab.com/lumi/jid-rs" repository = "https://gitlab.com/lumi/jid-rs" @@ -14,4 +18,4 @@ license = "LGPL-3.0+" gitlab = { repository = "lumi/jid-rs" } [dependencies] -minidom = { version = "0.6.1", optional = true } +minidom = { version = "0.7", optional = true } From 5563449c07def12b8d9f2394b38db367ba01106b Mon Sep 17 00:00:00 2001 From: lumi Date: Wed, 27 Dec 2017 17:16:59 +0100 Subject: [PATCH 29/73] change Cargo.toml to reflect the repository transfer --- Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 11ae97242c92b159b8e38f1d9dc63eecca5e68a4..a7ba1a0c3ee4547b00247bb32b4720e9921b1982 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,15 +7,15 @@ authors = [ "Maxime “pep” Buquet ", ] description = "A crate which provides a Jid struct for Jabber IDs." -homepage = "https://gitlab.com/lumi/jid-rs" -repository = "https://gitlab.com/lumi/jid-rs" +homepage = "https://gitlab.com/xmpp-rs/jid-rs" +repository = "https://gitlab.com/xmpp-rs/jid-rs" documentation = "https://docs.rs/jid" readme = "README.md" keywords = ["xmpp", "jid"] license = "LGPL-3.0+" [badges] -gitlab = { repository = "lumi/jid-rs" } +gitlab = { repository = "xmpp-rs/jid-rs" } [dependencies] minidom = { version = "0.7", optional = true } From 4392446189f1ab771fe37ee682d686a70f2da8f7 Mon Sep 17 00:00:00 2001 From: lumi Date: Wed, 27 Dec 2017 17:23:28 +0100 Subject: [PATCH 30/73] update the change log --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 63a6cc0743f99dd40ba9e0ef1fcb1e38e30112f8..49f7daac9c5edb5ff4e2f531409a74f3b391768e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +Version 0.4.0, released 2017-12-27: + * Updates + - Maxime Buquet has updated the optional `minidom` dependency. + - The repository has been transferred to xmpp-rs/jid-rs. + Version 0.3.1, released 2017-10-31: * Additions - Link Mauve added a minidom::IntoElements implementation on Jid behind the "minidom" feature. ( https://gitlab.com/lumi/jid-rs/merge_requests/9 ) From 5e6990bef9ec7a5e815e6f9562cdffea0fd24112 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Mon, 1 Jan 2018 13:41:52 +0000 Subject: [PATCH 31/73] Update docker image used in CI --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index cb292343052f44cf4efaa6f5bd686defc527ae8a..de843e5964b80dfc95c3fd7a9cb5aa061c1b993b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,6 +1,6 @@ -image: "scorpil/rust:stable" +image: "pitkley/rust:stable" test:cargo: script: - rustc --version && cargo --version - - cargo test --verbose --jobs 1 --release \ No newline at end of file + - cargo test --verbose --jobs 1 --release From 00f7d545aa7a4e5ae6aa4c545dc6ef754729b5a7 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sun, 18 Feb 2018 21:36:36 +0100 Subject: [PATCH 32/73] add tests for errors --- src/lib.rs | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index f0280d99aab1fa1670c06031411e0795686118ef..ebdfa80d55c2ec94df3cde5dcf3fe0372d2e77b8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,8 +13,13 @@ use std::str::FromStr; /// An error that signifies that a `Jid` cannot be parsed from a string. #[derive(Debug, Clone, PartialEq, Eq)] pub enum JidParseError { - /// Happens when there is no domain. (really, only happens when the string is empty) + /// Happens when there is no domain, that is either the string is empty, + /// starts with a /, or contains the @/ sequence. NoDomain, + /// Happens when the node is empty, that is the string starts with a @. + EmptyNode, + /// Happens when the resource is empty, that is the string ends with a /. + EmptyResource, } /// A struct representing a Jabber ID. @@ -86,11 +91,17 @@ impl FromStr for Jid { ParserState::Node => { match c { '@' => { + if buf == "" { + return Err(JidParseError::EmptyNode); + } state = ParserState::Domain; node = Some(buf.clone()); // TODO: performance tweaks, do not need to copy it buf.clear(); }, '/' => { + if buf == "" { + return Err(JidParseError::NoDomain); + } state = ParserState::Resource; domain = Some(buf.clone()); // TODO: performance tweaks buf.clear(); @@ -103,6 +114,9 @@ impl FromStr for Jid { ParserState::Domain => { match c { '/' => { + if buf == "" { + return Err(JidParseError::NoDomain); + } state = ParserState::Resource; domain = Some(buf.clone()); // TODO: performance tweaks buf.clear(); @@ -129,6 +143,8 @@ impl FromStr for Jid { resource = Some(buf); }, } + } else if let ParserState::Resource = state { + return Err(JidParseError::EmptyResource); } Ok(Jid { node: node, @@ -401,6 +417,34 @@ mod tests { assert_eq!(String::from(Jid::full("a", "b", "c")), String::from("a@b/c")); } + #[test] + fn invalid() { + match Jid::from_str("") { + Err(JidParseError::NoDomain) => (), + err => panic!("Invalid error: {:?}", err) + } + + match Jid::from_str("a@/c") { + Err(JidParseError::NoDomain) => (), + err => panic!("Invalid error: {:?}", err) + } + + match Jid::from_str("/c") { + Err(JidParseError::NoDomain) => (), + err => panic!("Invalid error: {:?}", err) + } + + match Jid::from_str("@b") { + Err(JidParseError::EmptyNode) => (), + err => panic!("Invalid error: {:?}", err) + } + + match Jid::from_str("b/") { + Err(JidParseError::EmptyResource) => (), + err => panic!("Invalid error: {:?}", err) + } + } + #[cfg(feature = "minidom")] #[test] fn minidom() { From c1fbfd26324ea5a46bf52c483cb18f6b535f9a70 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sun, 18 Feb 2018 21:37:01 +0100 Subject: [PATCH 33/73] bump minidom dependency --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index a7ba1a0c3ee4547b00247bb32b4720e9921b1982..84eed9924f8dbcd2864d6b442d29f68559d0cee8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,4 +18,4 @@ license = "LGPL-3.0+" gitlab = { repository = "xmpp-rs/jid-rs" } [dependencies] -minidom = { version = "0.7", optional = true } +minidom = { version = "0.8.0", optional = true } From 98ad44b5118acc7b75e82f1d5e7db0de2cd24462 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sun, 18 Feb 2018 21:38:07 +0100 Subject: [PATCH 34/73] release version 0.5.0 --- CHANGELOG.md | 5 +++++ Cargo.toml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 49f7daac9c5edb5ff4e2f531409a74f3b391768e..ad2dbb10d2e9b5b3b015b96362a4bd2e8f6c8efd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +Version 0.5.0, released 2018-02-18: + * Updates + - Link Mauve has updated the optional `minidom` dependency. + - Link Mauve has added tests for invalid JIDs, which adds more error cases. + Version 0.4.0, released 2017-12-27: * Updates - Maxime Buquet has updated the optional `minidom` dependency. diff --git a/Cargo.toml b/Cargo.toml index 84eed9924f8dbcd2864d6b442d29f68559d0cee8..cc9916d4eef4a1266f51b3344b3a6735be75a227 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "jid" -version = "0.4.0" +version = "0.5.0" authors = [ "lumi ", "Emmanuel Gil Peyrot ", From 56b465751890f7c53b0d972210338cba6528584c Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Thu, 1 Mar 2018 16:24:53 +0100 Subject: [PATCH 35/73] simplify Debug and Display implementations --- src/lib.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ebdfa80d55c2ec94df3cde5dcf3fe0372d2e77b8..0f2289f5a56b6fb15c4ea94dcef73e4324cb7e8e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -57,15 +57,13 @@ impl From for String { impl fmt::Debug for Jid { fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> { - write!(fmt, "JID({})", self)?; - Ok(()) + write!(fmt, "JID({})", self) } } impl fmt::Display for Jid { fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> { - fmt.write_str(String::from(self.clone()).as_ref())?; - Ok(()) + fmt.write_str(String::from(self.clone()).as_ref()) } } From 87d59181cb6f0d557ae221792d20320a823063f0 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Thu, 1 Mar 2018 16:25:05 +0100 Subject: [PATCH 36/73] remove redundant test --- src/lib.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0f2289f5a56b6fb15c4ea94dcef73e4324cb7e8e..6f2641e21ccd831e19c85472b60c1c10ccb9cafb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -404,9 +404,6 @@ mod tests { assert_eq!(Jid::from_str("a@b.c/d"), Ok(Jid::full("a", "b.c", "d"))); assert_eq!(Jid::from_str("a@b.c"), Ok(Jid::bare("a", "b.c"))); assert_eq!(Jid::from_str("b.c"), Ok(Jid::domain("b.c"))); - - assert_eq!(Jid::from_str(""), Err(JidParseError::NoDomain)); - assert_eq!(Jid::from_str("a/b@c"), Ok(Jid::domain_with_resource("a", "b@c"))); } From fd4a51377942cf5020d0bcb7290ce4c4af73dbef Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Thu, 1 Mar 2018 16:25:59 +0100 Subject: [PATCH 37/73] implement Fail on JidParseError --- Cargo.toml | 2 ++ src/lib.rs | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index cc9916d4eef4a1266f51b3344b3a6735be75a227..e9fcb30c59c8d30160a09348a1b8b6acd8b28510 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,4 +18,6 @@ license = "LGPL-3.0+" gitlab = { repository = "xmpp-rs/jid-rs" } [dependencies] +failure = "0.1.1" +failure_derive = "0.1.1" minidom = { version = "0.8.0", optional = true } diff --git a/src/lib.rs b/src/lib.rs index 6f2641e21ccd831e19c85472b60c1c10ccb9cafb..fb04453f54df2aec939dcc65985e5de3b5e60c07 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,9 @@ //! //! For usage, check the documentation on the `Jid` struct. +extern crate failure; +#[macro_use] extern crate failure_derive; + use std::fmt; use std::convert::Into; @@ -11,14 +14,19 @@ use std::convert::Into; use std::str::FromStr; /// An error that signifies that a `Jid` cannot be parsed from a string. -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Fail)] pub enum JidParseError { /// Happens when there is no domain, that is either the string is empty, /// starts with a /, or contains the @/ sequence. + #[fail(display = "no domain found in this JID")] NoDomain, + /// Happens when the node is empty, that is the string starts with a @. + #[fail(display = "nodepart empty despite the presence of a @")] EmptyNode, + /// Happens when the resource is empty, that is the string ends with a /. + #[fail(display = "resource empty despite the presence of a /")] EmptyResource, } From c45d1bf5ca5422686ef85a5b96c18cf312286550 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Thu, 1 Mar 2018 16:26:44 +0100 Subject: [PATCH 38/73] simplify tests for invalid JIDs --- src/lib.rs | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index fb04453f54df2aec939dcc65985e5de3b5e60c07..293c4a0ccfc04c97fbb17de4bfa8bb3b3656cbe6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -421,31 +421,12 @@ mod tests { } #[test] - fn invalid() { - match Jid::from_str("") { - Err(JidParseError::NoDomain) => (), - err => panic!("Invalid error: {:?}", err) - } - - match Jid::from_str("a@/c") { - Err(JidParseError::NoDomain) => (), - err => panic!("Invalid error: {:?}", err) - } - - match Jid::from_str("/c") { - Err(JidParseError::NoDomain) => (), - err => panic!("Invalid error: {:?}", err) - } - - match Jid::from_str("@b") { - Err(JidParseError::EmptyNode) => (), - err => panic!("Invalid error: {:?}", err) - } - - match Jid::from_str("b/") { - Err(JidParseError::EmptyResource) => (), - err => panic!("Invalid error: {:?}", err) - } + fn invalid_jids() { + assert_eq!(Jid::from_str(""), Err(JidParseError::NoDomain)); + assert_eq!(Jid::from_str("/c"), Err(JidParseError::NoDomain)); + assert_eq!(Jid::from_str("a@/c"), Err(JidParseError::NoDomain)); + assert_eq!(Jid::from_str("@b"), Err(JidParseError::EmptyNode)); + assert_eq!(Jid::from_str("b/"), Err(JidParseError::EmptyResource)); } #[cfg(feature = "minidom")] From 06afb5afede5053ee04fcb9e3abc0496d06ad348 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Thu, 1 Mar 2018 16:27:59 +0100 Subject: [PATCH 39/73] release version 0.5.1 --- CHANGELOG.md | 5 +++++ Cargo.toml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad2dbb10d2e9b5b3b015b96362a4bd2e8f6c8efd..f1dfd03b4523b2ab0330b90a1f8e0c44fff4b53d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +Version 0.5.1, released 2018-03-01: + * Updates + - Link Mauve implemented failure::Fail on JidParseError. + - Link Mauve simplified the code a bit. + Version 0.5.0, released 2018-02-18: * Updates - Link Mauve has updated the optional `minidom` dependency. diff --git a/Cargo.toml b/Cargo.toml index e9fcb30c59c8d30160a09348a1b8b6acd8b28510..8a5c09c83a46d2a231b9991089efa106d31717f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "jid" -version = "0.5.0" +version = "0.5.1" authors = [ "lumi ", "Emmanuel Gil Peyrot ", From 0ae044b0d56bc96fc425b93b139fdf16ad96f609 Mon Sep 17 00:00:00 2001 From: Astro Date: Wed, 25 Jul 2018 00:23:23 +0200 Subject: [PATCH 40/73] Bump minidom dependency to 0.9.1 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 8a5c09c83a46d2a231b9991089efa106d31717f9..f1fa81764c2b27df8add7604869ce1f512ae9d7c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,4 +20,4 @@ gitlab = { repository = "xmpp-rs/jid-rs" } [dependencies] failure = "0.1.1" failure_derive = "0.1.1" -minidom = { version = "0.8.0", optional = true } +minidom = { version = "0.9.1", optional = true } From 46b7ce9603debb542cd2c246b8890e7375c691da Mon Sep 17 00:00:00 2001 From: lumi Date: Tue, 31 Jul 2018 22:16:34 +0200 Subject: [PATCH 41/73] Prepare for release 0.5.2. --- CHANGELOG.md | 7 ++++++- Cargo.toml | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1dfd03b4523b2ab0330b90a1f8e0c44fff4b53d..733468e2183487d5616e5a0fd3ce4069f41da527 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ -Version 0.5.1, released 2018-03-01: +Version 0.5.2, released 2018-07-31: + * Updates + - Astro bumped the minidom dependency version. + - Updated the changelog to reflect that 0.5.1 was never actually released. + +Version 0.5.1, "released" 2018-03-01: * Updates - Link Mauve implemented failure::Fail on JidParseError. - Link Mauve simplified the code a bit. diff --git a/Cargo.toml b/Cargo.toml index f1fa81764c2b27df8add7604869ce1f512ae9d7c..e5f77215f2501f0a3e294c1154ee9ae478e7a048 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "jid" -version = "0.5.1" +version = "0.5.2" authors = [ "lumi ", "Emmanuel Gil Peyrot ", From d48473648be4c48b2ffa49c41ff76b4fe7219904 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Tue, 18 Dec 2018 16:35:08 +0100 Subject: [PATCH 42/73] Bump minidom dependency to 0.10. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index e5f77215f2501f0a3e294c1154ee9ae478e7a048..9d1aeed54e06c42cdf43191af739fce6c2329301 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,4 +20,4 @@ gitlab = { repository = "xmpp-rs/jid-rs" } [dependencies] failure = "0.1.1" failure_derive = "0.1.1" -minidom = { version = "0.9.1", optional = true } +minidom = { version = "0.10", optional = true } From 316268d3a115f6466f71ad7fe794be8fdc6880fe Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Tue, 18 Dec 2018 16:38:14 +0100 Subject: [PATCH 43/73] Use edition 2018. --- Cargo.toml | 1 + src/lib.rs | 4 ---- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9d1aeed54e06c42cdf43191af739fce6c2329301..d309aef6d50618c86f423581201e7404609af509 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ documentation = "https://docs.rs/jid" readme = "README.md" keywords = ["xmpp", "jid"] license = "LGPL-3.0+" +edition = "2018" [badges] gitlab = { repository = "xmpp-rs/jid-rs" } diff --git a/src/lib.rs b/src/lib.rs index 293c4a0ccfc04c97fbb17de4bfa8bb3b3656cbe6..2861ef6eb4cdd1a71bb02498152292ea441f6e18 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,7 +4,6 @@ //! //! For usage, check the documentation on the `Jid` struct. -extern crate failure; #[macro_use] extern crate failure_derive; use std::fmt; @@ -381,9 +380,6 @@ impl Jid { } -#[cfg(feature = "minidom")] -extern crate minidom; - #[cfg(feature = "minidom")] use minidom::{IntoAttributeValue, IntoElements, ElementEmitter}; From fa0894daa06f88db0531e542875bbce332bb83d0 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Tue, 18 Dec 2018 16:40:44 +0100 Subject: [PATCH 44/73] Run `cargo fmt`. --- src/lib.rs | 80 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 49 insertions(+), 31 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2861ef6eb4cdd1a71bb02498152292ea441f6e18..dd9a5f1b0bb1d82e8fe17232f9ec18d6312f9520 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,12 +4,11 @@ //! //! For usage, check the documentation on the `Jid` struct. -#[macro_use] extern crate failure_derive; - -use std::fmt; +#[macro_use] +extern crate failure_derive; use std::convert::Into; - +use std::fmt; use std::str::FromStr; /// An error that signifies that a `Jid` cannot be parsed from a string. @@ -77,7 +76,7 @@ impl fmt::Display for Jid { enum ParserState { Node, Domain, - Resource + Resource, } impl FromStr for Jid { @@ -102,7 +101,7 @@ impl FromStr for Jid { state = ParserState::Domain; node = Some(buf.clone()); // TODO: performance tweaks, do not need to copy it buf.clear(); - }, + } '/' => { if buf == "" { return Err(JidParseError::NoDomain); @@ -110,12 +109,12 @@ impl FromStr for Jid { state = ParserState::Resource; domain = Some(buf.clone()); // TODO: performance tweaks buf.clear(); - }, + } c => { buf.push(c); - }, + } } - }, + } ParserState::Domain => { match c { '/' => { @@ -125,28 +124,28 @@ impl FromStr for Jid { state = ParserState::Resource; domain = Some(buf.clone()); // TODO: performance tweaks buf.clear(); - }, + } c => { buf.push(c); - }, + } } - }, + } ParserState::Resource => { buf.push(c); - }, + } } } if !buf.is_empty() { match state { ParserState::Node => { domain = Some(buf); - }, + } ParserState::Domain => { domain = Some(buf); - }, + } ParserState::Resource => { resource = Some(buf); - }, + } } } else if let ParserState::Resource = state { return Err(JidParseError::EmptyResource); @@ -176,9 +175,11 @@ impl Jid { /// assert_eq!(jid.resource, Some("resource".to_owned())); /// ``` pub fn full(node: NS, domain: DS, resource: RS) -> Jid - where NS: Into - , DS: Into - , RS: Into { + where + NS: Into, + DS: Into, + RS: Into, + { Jid { node: Some(node.into()), domain: domain.into(), @@ -202,8 +203,10 @@ impl Jid { /// assert_eq!(jid.resource, None); /// ``` pub fn bare(node: NS, domain: DS) -> Jid - where NS: Into - , DS: Into { + where + NS: Into, + DS: Into, + { Jid { node: Some(node.into()), domain: domain.into(), @@ -250,7 +253,9 @@ impl Jid { /// assert_eq!(jid.resource, None); /// ``` pub fn domain(domain: DS) -> Jid - where DS: Into { + where + DS: Into, + { Jid { node: None, domain: domain.into(), @@ -297,8 +302,10 @@ impl Jid { /// assert_eq!(jid.resource, Some("resource".to_owned())); /// ``` pub fn domain_with_resource(domain: DS, resource: RS) -> Jid - where DS: Into - , RS: Into { + where + DS: Into, + RS: Into, + { Jid { node: None, domain: domain.into(), @@ -322,7 +329,9 @@ impl Jid { /// assert_eq!(new_jid.node, Some("node".to_owned())); /// ``` pub fn with_node(&self, node: S) -> Jid - where S: Into { + where + S: Into, + { Jid { node: Some(node.into()), domain: self.domain.clone(), @@ -346,7 +355,9 @@ impl Jid { /// assert_eq!(new_jid.domain, "new_domain"); /// ``` pub fn with_domain(&self, domain: S) -> Jid - where S: Into { + where + S: Into, + { Jid { node: self.node.clone(), domain: domain.into(), @@ -370,18 +381,19 @@ impl Jid { /// assert_eq!(new_jid.resource, Some("resource".to_owned())); /// ``` pub fn with_resource(&self, resource: S) -> Jid - where S: Into { + where + S: Into, + { Jid { node: self.node.clone(), domain: self.domain.clone(), resource: Some(resource.into()), } } - } #[cfg(feature = "minidom")] -use minidom::{IntoAttributeValue, IntoElements, ElementEmitter}; +use minidom::{ElementEmitter, IntoAttributeValue, IntoElements}; #[cfg(feature = "minidom")] impl IntoAttributeValue for Jid { @@ -408,12 +420,18 @@ mod tests { assert_eq!(Jid::from_str("a@b.c/d"), Ok(Jid::full("a", "b.c", "d"))); assert_eq!(Jid::from_str("a@b.c"), Ok(Jid::bare("a", "b.c"))); assert_eq!(Jid::from_str("b.c"), Ok(Jid::domain("b.c"))); - assert_eq!(Jid::from_str("a/b@c"), Ok(Jid::domain_with_resource("a", "b@c"))); + assert_eq!( + Jid::from_str("a/b@c"), + Ok(Jid::domain_with_resource("a", "b@c")) + ); } #[test] fn serialise() { - assert_eq!(String::from(Jid::full("a", "b", "c")), String::from("a@b/c")); + assert_eq!( + String::from(Jid::full("a", "b", "c")), + String::from("a@b/c") + ); } #[test] From 9c8da4a06329d72cd109f13bc5f11ae4bfded0f9 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Thu, 20 Dec 2018 17:49:36 +0100 Subject: [PATCH 45/73] Use a working CI script, and test on both stable and nightly. --- .gitlab-ci.yml | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index de843e5964b80dfc95c3fd7a9cb5aa061c1b993b..0b4e77f06d233074e4efced741958cc6a524498c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,6 +1,16 @@ -image: "pitkley/rust:stable" +stages: + - build -test:cargo: +rust-latest: + stage: build + image: rust:latest script: - - rustc --version && cargo --version - - cargo test --verbose --jobs 1 --release + - cargo build --verbose + - cargo test --verbose + +rust-nightly: + stage: build + image: rustlang/rust:nightly + script: + - cargo build --verbose + - cargo test --verbose From 1f260cfe8610ba5079fe185db93b94a72fae6f10 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Wed, 16 Jan 2019 13:27:54 +0100 Subject: [PATCH 46/73] =?UTF-8?q?Prepare=20for=20release=C2=A00.5.3.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 6 ++++++ Cargo.toml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 733468e2183487d5616e5a0fd3ce4069f41da527..358538efda87382fa2a0276cf4877137872a7a5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +Version 0.5.3, released 2019-01-16: + * Updates + - Link Mauve bumped the minidom dependency version. + - Use Edition 2018, putting the baseline rustc version to 1.31. + - Run cargo-fmt on the code, to lower the barrier of entry. + Version 0.5.2, released 2018-07-31: * Updates - Astro bumped the minidom dependency version. diff --git a/Cargo.toml b/Cargo.toml index d309aef6d50618c86f423581201e7404609af509..b29a3c3c9e52f6d6a07b81c1fda28800b2e257d8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "jid" -version = "0.5.2" +version = "0.5.3" authors = [ "lumi ", "Emmanuel Gil Peyrot ", From 395d4480278d87c8c6ae2ec71d1fb170b0c3c236 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sun, 21 Apr 2019 23:52:02 +0100 Subject: [PATCH 47/73] Split Jid struct into BareJid and FullJid. Jid is now an enum MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will help with being able to enforce the usage of bare or full at compile time. It is still possible to allow one or the other with the `Jid` enum. Thanks to O01eg (from xmpp-rs@muc.linkmauve.fr) for the help. This commit also contains code from them. Signed-off-by: Maxime “pep” Buquet --- src/lib.rs | 597 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 414 insertions(+), 183 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index dd9a5f1b0bb1d82e8fe17232f9ec18d6312f9520..8a243b69e4bba6a002a678f59cd084058ca3a60c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,6 +19,10 @@ pub enum JidParseError { #[fail(display = "no domain found in this JID")] NoDomain, + /// Happens when there is no resource, that is string contains no /. + #[fail(display = "no resource found in this JID")] + NoResource, + /// Happens when the node is empty, that is the string starts with a @. #[fail(display = "nodepart empty despite the presence of a @")] EmptyNode, @@ -28,46 +32,129 @@ pub enum JidParseError { EmptyResource, } -/// A struct representing a Jabber ID. +/// An enum representing a Jabber ID. It can be either a `FullJid` or a `BareJid`. +#[derive(Debug, Clone, PartialEq)] +pub enum Jid { + /// Bare Jid + Bare(BareJid), + + /// Full Jid + Full(FullJid), +} + +impl FromStr for Jid { + type Err = JidParseError; + + fn from_str(s: &str) -> Result { + let (ns, ds, rs): StringJid = _from_str(s)?; + Ok(match rs { + Some(rs) => Jid::Full(FullJid { + node: ns, + domain: ds, + resource: rs, + }), + None => Jid::Bare(BareJid { + node: ns, + domain: ds, + }) + }) + } +} + +impl From for String { + fn from(jid: Jid) -> String { + match jid { + Jid::Bare(bare) => String::from(bare), + Jid::Full(full) => String::from(full), + } + } +} + +/// A struct representing a Full Jabber ID. /// -/// A Jabber ID is composed of 3 components, of which 2 are optional: +/// A Full Jabber ID is composed of 3 components, of which one is optional: /// /// - A node/name, `node`, which is the optional part before the @. /// - A domain, `domain`, which is the mandatory part after the @ but before the /. -/// - A resource, `resource`, which is the optional part after the /. +/// - A resource, `resource`, which is the part after the /. #[derive(Clone, PartialEq, Eq, Hash)] -pub struct Jid { +pub struct FullJid { /// The node part of the Jabber ID, if it exists, else None. pub node: Option, /// The domain of the Jabber ID. pub domain: String, - /// The resource of the Jabber ID, if it exists, else None. - pub resource: Option, + /// The resource of the Jabber ID. + pub resource: String, } -impl From for String { - fn from(jid: Jid) -> String { +/// A struct representing a Bare Jabber ID. +/// +/// A Bare Jabber ID is composed of 2 components, of which one is optional: +/// +/// - A node/name, `node`, which is the optional part before the @. +/// - A domain, `domain`, which is the mandatory part after the @ but before the /. +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct BareJid { + /// The node part of the Jabber ID, if it exists, else None. + pub node: Option, + /// The domain of the Jabber ID. + pub domain: String, +} + +impl From for String { + fn from(jid: FullJid) -> String { let mut string = String::new(); if let Some(ref node) = jid.node { string.push_str(node); string.push('@'); } string.push_str(&jid.domain); - if let Some(ref resource) = jid.resource { - string.push('/'); - string.push_str(resource); + string.push('/'); + string.push_str(&jid.resource); + string + } +} + +impl From for String { + fn from(jid: BareJid) -> String { + let mut string = String::new(); + if let Some(ref node) = jid.node { + string.push_str(node); + string.push('@'); } + string.push_str(&jid.domain); string } } -impl fmt::Debug for Jid { +impl Into for FullJid { + fn into(self) -> BareJid { + BareJid { + node: self.node, + domain: self.domain, + } + } +} + +impl fmt::Debug for FullJid { fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> { - write!(fmt, "JID({})", self) + write!(fmt, "FullJID({})", self) } } -impl fmt::Display for Jid { +impl fmt::Debug for BareJid { + fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> { + write!(fmt, "BareJID({})", self) + } +} + +impl fmt::Display for FullJid { + fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> { + fmt.write_str(String::from(self.clone()).as_ref()) + } +} + +impl fmt::Display for BareJid { fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> { fmt.write_str(String::from(self.clone()).as_ref()) } @@ -79,237 +166,262 @@ enum ParserState { Resource, } -impl FromStr for Jid { - type Err = JidParseError; - - fn from_str(s: &str) -> Result { - // TODO: very naive, may need to do it differently - let iter = s.chars(); - let mut buf = String::with_capacity(s.len()); - let mut state = ParserState::Node; - let mut node = None; - let mut domain = None; - let mut resource = None; - for c in iter { - match state { - ParserState::Node => { - match c { - '@' => { - if buf == "" { - return Err(JidParseError::EmptyNode); - } - state = ParserState::Domain; - node = Some(buf.clone()); // TODO: performance tweaks, do not need to copy it - buf.clear(); - } - '/' => { - if buf == "" { - return Err(JidParseError::NoDomain); - } - state = ParserState::Resource; - domain = Some(buf.clone()); // TODO: performance tweaks - buf.clear(); +type StringJid = (Option, String, Option); +fn _from_str(s: &str) -> Result { + // TODO: very naive, may need to do it differently + let iter = s.chars(); + let mut buf = String::with_capacity(s.len()); + let mut state = ParserState::Node; + let mut node = None; + let mut domain = None; + let mut resource = None; + for c in iter { + match state { + ParserState::Node => { + match c { + '@' => { + if buf == "" { + return Err(JidParseError::EmptyNode); } - c => { - buf.push(c); + state = ParserState::Domain; + node = Some(buf.clone()); // TODO: performance tweaks, do not need to copy it + buf.clear(); + } + '/' => { + if buf == "" { + return Err(JidParseError::NoDomain); } + state = ParserState::Resource; + domain = Some(buf.clone()); // TODO: performance tweaks + buf.clear(); + } + c => { + buf.push(c); } } - ParserState::Domain => { - match c { - '/' => { - if buf == "" { - return Err(JidParseError::NoDomain); - } - state = ParserState::Resource; - domain = Some(buf.clone()); // TODO: performance tweaks - buf.clear(); - } - c => { - buf.push(c); + } + ParserState::Domain => { + match c { + '/' => { + if buf == "" { + return Err(JidParseError::NoDomain); } + state = ParserState::Resource; + domain = Some(buf.clone()); // TODO: performance tweaks + buf.clear(); + } + c => { + buf.push(c); } } - ParserState::Resource => { - buf.push(c); - } + } + ParserState::Resource => { + buf.push(c); } } - if !buf.is_empty() { - match state { - ParserState::Node => { - domain = Some(buf); - } - ParserState::Domain => { - domain = Some(buf); - } - ParserState::Resource => { - resource = Some(buf); - } + } + if !buf.is_empty() { + match state { + ParserState::Node => { + domain = Some(buf); + } + ParserState::Domain => { + domain = Some(buf); + } + ParserState::Resource => { + resource = Some(buf); } - } else if let ParserState::Resource = state { - return Err(JidParseError::EmptyResource); } - Ok(Jid { - node: node, - domain: domain.ok_or(JidParseError::NoDomain)?, - resource: resource, + } else if let ParserState::Resource = state { + return Err(JidParseError::EmptyResource); + } + Ok(( + node, + domain.ok_or(JidParseError::NoDomain)?, + resource, + )) +} + +impl FromStr for FullJid { + type Err = JidParseError; + + fn from_str(s: &str) -> Result { + let (ns, ds, rs): StringJid = _from_str(s)?; + Ok(FullJid { + node: ns, + domain: ds, + resource: rs.ok_or(JidParseError::NoResource)?, }) } } -impl Jid { - /// Constructs a Jabber ID containing all three components. +impl FullJid { + /// Constructs a Full Jabber ID containing all three components. /// /// This is of the form `node`@`domain`/`resource`. /// /// # Examples /// /// ``` - /// use jid::Jid; + /// use jid::FullJid; /// - /// let jid = Jid::full("node", "domain", "resource"); + /// let jid = FullJid::new("node", "domain", "resource"); /// /// assert_eq!(jid.node, Some("node".to_owned())); /// assert_eq!(jid.domain, "domain".to_owned()); - /// assert_eq!(jid.resource, Some("resource".to_owned())); + /// assert_eq!(jid.resource, "resource".to_owned()); /// ``` - pub fn full(node: NS, domain: DS, resource: RS) -> Jid + pub fn new(node: NS, domain: DS, resource: RS) -> FullJid where NS: Into, DS: Into, RS: Into, { - Jid { + FullJid { node: Some(node.into()), domain: domain.into(), - resource: Some(resource.into()), + resource: resource.into() } } - /// Constructs a Jabber ID containing only the `node` and `domain` components. - /// - /// This is of the form `node`@`domain`. + /// Constructs a new Jabber ID from an existing one, with the node swapped out with a new one. /// /// # Examples /// /// ``` - /// use jid::Jid; + /// use jid::FullJid; /// - /// let jid = Jid::bare("node", "domain"); + /// let jid = FullJid::new("node", "domain", "resource"); /// /// assert_eq!(jid.node, Some("node".to_owned())); - /// assert_eq!(jid.domain, "domain".to_owned()); - /// assert_eq!(jid.resource, None); + /// + /// let new_jid = jid.with_node("new_node"); + /// + /// assert_eq!(new_jid.node, Some("new_node".to_owned())); /// ``` - pub fn bare(node: NS, domain: DS) -> Jid + pub fn with_node(&self, node: NS) -> FullJid where NS: Into, - DS: Into, { - Jid { + FullJid { node: Some(node.into()), - domain: domain.into(), - resource: None, + domain: self.domain.clone(), + resource: self.resource.clone(), } } - /// Returns a new Jabber ID from the current one with only node and domain. - /// - /// This is of the form `node`@`domain`. + /// Constructs a new Jabber ID from an existing one, with the domain swapped out with a new one. /// /// # Examples /// /// ``` - /// use jid::Jid; + /// use jid::FullJid; /// - /// let jid = Jid::full("node", "domain", "resource").into_bare_jid(); + /// let jid = FullJid::new("node", "domain", "resource"); /// - /// assert_eq!(jid.node, Some("node".to_owned())); /// assert_eq!(jid.domain, "domain".to_owned()); - /// assert_eq!(jid.resource, None); + /// + /// let new_jid = jid.with_domain("new_domain"); + /// + /// assert_eq!(new_jid.domain, "new_domain"); /// ``` - pub fn into_bare_jid(self) -> Jid { - Jid { - node: self.node, - domain: self.domain, - resource: None, + pub fn with_domain(&self, domain: DS) -> FullJid + where + DS: Into, + { + FullJid { + node: self.node.clone(), + domain: domain.into(), + resource: self.resource.clone(), } } - /// Constructs a Jabber ID containing only a `domain`. - /// - /// This is of the form `domain`. + /// Constructs a Full Jabber ID from a Bare Jabber ID, specifying a `resource`. /// /// # Examples /// /// ``` - /// use jid::Jid; + /// use jid::FullJid; /// - /// let jid = Jid::domain("domain"); + /// let jid = FullJid::new("node", "domain", "resource"); /// - /// assert_eq!(jid.node, None); - /// assert_eq!(jid.domain, "domain".to_owned()); - /// assert_eq!(jid.resource, None); + /// assert_eq!(jid.resource, "resource".to_owned()); + /// + /// let new_jid = jid.with_resource("new_resource"); + /// + /// assert_eq!(new_jid.resource, "new_resource"); /// ``` - pub fn domain(domain: DS) -> Jid + pub fn with_resource(&self, resource: RS) -> FullJid where - DS: Into, + RS: Into, { - Jid { - node: None, - domain: domain.into(), - resource: None, + FullJid { + node: self.node.clone(), + domain: self.domain.clone(), + resource: resource.into(), } } +} + +impl FromStr for BareJid { + type Err = JidParseError; + + fn from_str(s: &str) -> Result { + let (ns, ds, _rs): StringJid = _from_str(s)?; + Ok(BareJid { + node: ns, + domain: ds, + }) + } +} - /// Returns a new Jabber ID from the current one with only domain. +impl BareJid { + /// Constructs a Bare Jabber ID, containing two components. /// - /// This is of the form `domain`. + /// This is of the form `node`@`domain`. /// /// # Examples /// /// ``` - /// use jid::Jid; + /// use jid::BareJid; /// - /// let jid = Jid::full("node", "domain", "resource").into_domain_jid(); + /// let jid = BareJid::new("node", "domain"); /// - /// assert_eq!(jid.node, None); + /// assert_eq!(jid.node, Some("node".to_owned())); /// assert_eq!(jid.domain, "domain".to_owned()); - /// assert_eq!(jid.resource, None); /// ``` - pub fn into_domain_jid(self) -> Jid { - Jid { - node: None, - domain: self.domain, - resource: None, + pub fn new(node: NS, domain: DS) -> BareJid + where + NS: Into, + DS: Into, + { + BareJid { + node: Some(node.into()), + domain: domain.into(), } } - /// Constructs a Jabber ID containing the `domain` and `resource` components. + /// Constructs a Bare Jabber ID containing only a `domain`. /// - /// This is of the form `domain`/`resource`. + /// This is of the form `domain`. /// /// # Examples /// /// ``` - /// use jid::Jid; + /// use jid::BareJid; /// - /// let jid = Jid::domain_with_resource("domain", "resource"); + /// let jid = BareJid::domain("domain"); /// /// assert_eq!(jid.node, None); /// assert_eq!(jid.domain, "domain".to_owned()); - /// assert_eq!(jid.resource, Some("resource".to_owned())); /// ``` - pub fn domain_with_resource(domain: DS, resource: RS) -> Jid + pub fn domain(domain: DS) -> BareJid where DS: Into, - RS: Into, { - Jid { + BareJid { node: None, domain: domain.into(), - resource: Some(resource.into()), } } @@ -318,9 +430,9 @@ impl Jid { /// # Examples /// /// ``` - /// use jid::Jid; + /// use jid::BareJid; /// - /// let jid = Jid::domain("domain"); + /// let jid = BareJid::domain("domain"); /// /// assert_eq!(jid.node, None); /// @@ -328,14 +440,13 @@ impl Jid { /// /// assert_eq!(new_jid.node, Some("node".to_owned())); /// ``` - pub fn with_node(&self, node: S) -> Jid + pub fn with_node(&self, node: NS) -> BareJid where - S: Into, + NS: Into, { - Jid { + BareJid { node: Some(node.into()), domain: self.domain.clone(), - resource: self.resource.clone(), } } @@ -344,9 +455,9 @@ impl Jid { /// # Examples /// /// ``` - /// use jid::Jid; + /// use jid::BareJid; /// - /// let jid = Jid::domain("domain"); + /// let jid = BareJid::domain("domain"); /// /// assert_eq!(jid.domain, "domain"); /// @@ -354,40 +465,38 @@ impl Jid { /// /// assert_eq!(new_jid.domain, "new_domain"); /// ``` - pub fn with_domain(&self, domain: S) -> Jid + pub fn with_domain(&self, domain: DS) -> BareJid where - S: Into, + DS: Into, { - Jid { + BareJid { node: self.node.clone(), domain: domain.into(), - resource: self.resource.clone(), } } - /// Constructs a new Jabber ID from an existing one, with the resource swapped out with a new one. + /// Constructs a Full Jabber ID from a Bare Jabber ID, specifying a `resource`. /// /// # Examples /// /// ``` - /// use jid::Jid; + /// use jid::BareJid; /// - /// let jid = Jid::domain("domain"); + /// let bare = BareJid::new("node", "domain"); + /// let full = bare.with_resource("resource"); /// - /// assert_eq!(jid.resource, None); - /// - /// let new_jid = jid.with_resource("resource"); - /// - /// assert_eq!(new_jid.resource, Some("resource".to_owned())); + /// assert_eq!(full.node, Some("node".to_owned())); + /// assert_eq!(full.domain, "domain".to_owned()); + /// assert_eq!(full.resource, "resource".to_owned()); /// ``` - pub fn with_resource(&self, resource: S) -> Jid + pub fn with_resource(self, resource: RS) -> FullJid where - S: Into, + RS: Into, { - Jid { - node: self.node.clone(), - domain: self.domain.clone(), - resource: Some(resource.into()), + FullJid { + node: self.node, + domain: self.domain, + resource: resource.into(), } } } @@ -409,6 +518,34 @@ impl IntoElements for Jid { } } +#[cfg(feature = "minidom")] +impl IntoAttributeValue for FullJid { + fn into_attribute_value(self) -> Option { + Some(String::from(self)) + } +} + +#[cfg(feature = "minidom")] +impl IntoElements for FullJid { + fn into_elements(self, emitter: &mut ElementEmitter) { + emitter.append_text_node(String::from(self)) + } +} + +#[cfg(feature = "minidom")] +impl IntoAttributeValue for BareJid { + fn into_attribute_value(self) -> Option { + Some(String::from(self)) + } +} + +#[cfg(feature = "minidom")] +impl IntoElements for BareJid { + fn into_elements(self, emitter: &mut ElementEmitter) { + emitter.append_text_node(String::from(self)) + } +} + #[cfg(test)] mod tests { use super::*; @@ -416,31 +553,88 @@ mod tests { use std::str::FromStr; #[test] - fn can_parse_jids() { - assert_eq!(Jid::from_str("a@b.c/d"), Ok(Jid::full("a", "b.c", "d"))); - assert_eq!(Jid::from_str("a@b.c"), Ok(Jid::bare("a", "b.c"))); - assert_eq!(Jid::from_str("b.c"), Ok(Jid::domain("b.c"))); + fn can_parse_full_jids() { + assert_eq!(FullJid::from_str("a@b.c/d"), Ok(FullJid::new("a", "b.c", "d"))); + assert_eq!( + FullJid::from_str("b.c/d"), + Ok(FullJid { + node: None, + domain: "b.c".to_owned(), + resource: "d".to_owned(), + }) + ); + + assert_eq!(FullJid::from_str("a@b.c"), Err(JidParseError::NoResource)); + assert_eq!(FullJid::from_str("b.c"), Err(JidParseError::NoResource)); + } + + #[test] + fn can_parse_bare_jids() { + assert_eq!(BareJid::from_str("a@b.c/d"), Ok(BareJid::new("a", "b.c"))); + assert_eq!( + BareJid::from_str("b.c/d"), + Ok(BareJid { + node: None, + domain: "b.c".to_owned(), + }) + ); + + assert_eq!(BareJid::from_str("a@b.c"), Ok(BareJid::new("a", "b.c"))); assert_eq!( - Jid::from_str("a/b@c"), - Ok(Jid::domain_with_resource("a", "b@c")) + BareJid::from_str("b.c"), + Ok(BareJid { + node: None, + domain: "b.c".to_owned(), + }) ); } + #[test] + fn can_parse_jids() { + let full = FullJid::from_str("a@b.c/d").unwrap(); + let bare = BareJid::from_str("e@f.g").unwrap(); + + assert_eq!(Jid::from_str("a@b.c/d"), Ok(Jid::Full(full))); + assert_eq!(Jid::from_str("e@f.g"), Ok(Jid::Bare(bare))); + } + + #[test] + fn full_to_bare_jid() { + let bare: BareJid = FullJid::new("a", "b.c", "d").into(); + assert_eq!(bare, BareJid::new("a", "b.c")); + } + + #[test] + fn bare_to_full_jid() { + assert_eq!(BareJid::new("a", "b.c").with_resource("d"), FullJid::new("a", "b.c", "d")); + } + #[test] fn serialise() { assert_eq!( - String::from(Jid::full("a", "b", "c")), + String::from(FullJid::new("a", "b", "c")), String::from("a@b/c") ); + assert_eq!( + String::from(BareJid::new("a", "b")), + String::from("a@b") + ); } #[test] fn invalid_jids() { - assert_eq!(Jid::from_str(""), Err(JidParseError::NoDomain)); - assert_eq!(Jid::from_str("/c"), Err(JidParseError::NoDomain)); - assert_eq!(Jid::from_str("a@/c"), Err(JidParseError::NoDomain)); - assert_eq!(Jid::from_str("@b"), Err(JidParseError::EmptyNode)); - assert_eq!(Jid::from_str("b/"), Err(JidParseError::EmptyResource)); + assert_eq!(BareJid::from_str(""), Err(JidParseError::NoDomain)); + assert_eq!(BareJid::from_str("/c"), Err(JidParseError::NoDomain)); + assert_eq!(BareJid::from_str("a@/c"), Err(JidParseError::NoDomain)); + assert_eq!(BareJid::from_str("@b"), Err(JidParseError::EmptyNode)); + assert_eq!(BareJid::from_str("b/"), Err(JidParseError::EmptyResource)); + + assert_eq!(FullJid::from_str(""), Err(JidParseError::NoDomain)); + assert_eq!(FullJid::from_str("/c"), Err(JidParseError::NoDomain)); + assert_eq!(FullJid::from_str("a@/c"), Err(JidParseError::NoDomain)); + assert_eq!(FullJid::from_str("@b"), Err(JidParseError::EmptyNode)); + assert_eq!(FullJid::from_str("b/"), Err(JidParseError::EmptyResource)); + assert_eq!(FullJid::from_str("a@b"), Err(JidParseError::NoResource)); } #[cfg(feature = "minidom")] @@ -448,6 +642,43 @@ mod tests { fn minidom() { let elem: minidom::Element = "".parse().unwrap(); let to: Jid = elem.attr("from").unwrap().parse().unwrap(); - assert_eq!(to, Jid::full("a", "b", "c")); + assert_eq!(to, Jid::Full(FullJid::new("a", "b", "c"))); + + let elem: minidom::Element = "".parse().unwrap(); + let to: Jid = elem.attr("from").unwrap().parse().unwrap(); + assert_eq!(to, Jid::Bare(BareJid::new("a", "b"))); + + let elem: minidom::Element = "".parse().unwrap(); + let to: FullJid = elem.attr("from").unwrap().parse().unwrap(); + assert_eq!(to, FullJid::new("a", "b", "c")); + + let elem: minidom::Element = "".parse().unwrap(); + let to: BareJid = elem.attr("from").unwrap().parse().unwrap(); + assert_eq!(to, BareJid::new("a", "b")); + } + + #[cfg(feature = "minidom")] + #[test] + fn minidom_into_attr() { + let full = FullJid::new("a", "b", "c"); + let elem = minidom::Element::builder("message") + .ns("jabber:client") + .attr("from", full.clone()) + .build(); + assert_eq!(elem.attr("from"), Some(String::from(full).as_ref())); + + let bare = BareJid::new("a", "b"); + let elem = minidom::Element::builder("message") + .ns("jabber:client") + .attr("from", bare.clone()) + .build(); + assert_eq!(elem.attr("from"), Some(String::from(bare.clone()).as_ref())); + + let jid = Jid::Bare(bare.clone()); + let _elem = minidom::Element::builder("message") + .ns("jabber:client") + .attr("from", jid) + .build(); + assert_eq!(elem.attr("from"), Some(String::from(bare).as_ref())); } } From 24aef813b3913cfca2166f3db7338e2bea671cc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Mon, 10 Jun 2019 22:04:03 +0200 Subject: [PATCH 48/73] rustfmt pass after split-jids merge MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- src/lib.rs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 8a243b69e4bba6a002a678f59cd084058ca3a60c..fcd6f5517bd19baa507429899b97b3f80804e87d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -56,7 +56,7 @@ impl FromStr for Jid { None => Jid::Bare(BareJid { node: ns, domain: ds, - }) + }), }) } } @@ -235,11 +235,7 @@ fn _from_str(s: &str) -> Result { } else if let ParserState::Resource = state { return Err(JidParseError::EmptyResource); } - Ok(( - node, - domain.ok_or(JidParseError::NoDomain)?, - resource, - )) + Ok((node, domain.ok_or(JidParseError::NoDomain)?, resource)) } impl FromStr for FullJid { @@ -280,7 +276,7 @@ impl FullJid { FullJid { node: Some(node.into()), domain: domain.into(), - resource: resource.into() + resource: resource.into(), } } @@ -554,7 +550,10 @@ mod tests { #[test] fn can_parse_full_jids() { - assert_eq!(FullJid::from_str("a@b.c/d"), Ok(FullJid::new("a", "b.c", "d"))); + assert_eq!( + FullJid::from_str("a@b.c/d"), + Ok(FullJid::new("a", "b.c", "d")) + ); assert_eq!( FullJid::from_str("b.c/d"), Ok(FullJid { @@ -606,7 +605,10 @@ mod tests { #[test] fn bare_to_full_jid() { - assert_eq!(BareJid::new("a", "b.c").with_resource("d"), FullJid::new("a", "b.c", "d")); + assert_eq!( + BareJid::new("a", "b.c").with_resource("d"), + FullJid::new("a", "b.c", "d") + ); } #[test] @@ -615,10 +617,7 @@ mod tests { String::from(FullJid::new("a", "b", "c")), String::from("a@b/c") ); - assert_eq!( - String::from(BareJid::new("a", "b")), - String::from("a@b") - ); + assert_eq!(String::from(BareJid::new("a", "b")), String::from("a@b")); } #[test] From 6b17aacd8e9252370616c9970b49cb2ab1a6817c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Mon, 10 Jun 2019 22:06:57 +0200 Subject: [PATCH 49/73] Prepare for release 0.6.0. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- CHANGELOG.md | 4 ++++ Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 358538efda87382fa2a0276cf4877137872a7a5c..c88c32c61212dbe6251849737b07cb3dcaf36b55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +Version 0.6.0, released 2019-06-19: + * Updates + - Jid is now an enum, with two variants, Bare(BareJid) and Full(FullJid) + Version 0.5.3, released 2019-01-16: * Updates - Link Mauve bumped the minidom dependency version. diff --git a/Cargo.toml b/Cargo.toml index b29a3c3c9e52f6d6a07b81c1fda28800b2e257d8..04fb6d4f6dd9f113411fd825f0194fa60fa40698 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "jid" -version = "0.5.3" +version = "0.6.0" authors = [ "lumi ", "Emmanuel Gil Peyrot ", From 6b1ad1ca9bd4e7f16b98d4a99c53bd9b6926f7a0 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Mon, 10 Jun 2019 22:49:57 +0200 Subject: [PATCH 50/73] Make the NoResource error description less ambiguous. --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index fcd6f5517bd19baa507429899b97b3f80804e87d..05ea4817decbb0bec691d590e6f616e81878a306 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,7 +20,7 @@ pub enum JidParseError { NoDomain, /// Happens when there is no resource, that is string contains no /. - #[fail(display = "no resource found in this JID")] + #[fail(display = "no resource found in this full JID")] NoResource, /// Happens when the node is empty, that is the string starts with a @. From b12487a5b1261cf21417983307495c921c943206 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Mon, 10 Jun 2019 22:54:52 +0200 Subject: [PATCH 51/73] =?UTF-8?q?Standardise=20the=20casing=20of=20?= =?UTF-8?q?=E2=80=9Cfull=20JID=E2=80=9D=20and=20=E2=80=9Cbare=20JID?= =?UTF-8?q?=E2=80=9D.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 05ea4817decbb0bec691d590e6f616e81878a306..8ef7a3d17defdceac59f01d78528dffb1f7be5a8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -70,9 +70,9 @@ impl From for String { } } -/// A struct representing a Full Jabber ID. +/// A struct representing a full Jabber ID. /// -/// A Full Jabber ID is composed of 3 components, of which one is optional: +/// A full Jabber ID is composed of 3 components, of which one is optional: /// /// - A node/name, `node`, which is the optional part before the @. /// - A domain, `domain`, which is the mandatory part after the @ but before the /. @@ -87,9 +87,9 @@ pub struct FullJid { pub resource: String, } -/// A struct representing a Bare Jabber ID. +/// A struct representing a bare Jabber ID. /// -/// A Bare Jabber ID is composed of 2 components, of which one is optional: +/// A bare Jabber ID is composed of 2 components, of which one is optional: /// /// - A node/name, `node`, which is the optional part before the @. /// - A domain, `domain`, which is the mandatory part after the @ but before the /. @@ -252,7 +252,7 @@ impl FromStr for FullJid { } impl FullJid { - /// Constructs a Full Jabber ID containing all three components. + /// Constructs a full Jabber ID containing all three components. /// /// This is of the form `node`@`domain`/`resource`. /// @@ -332,7 +332,7 @@ impl FullJid { } } - /// Constructs a Full Jabber ID from a Bare Jabber ID, specifying a `resource`. + /// Constructs a full Jabber ID from a bare Jabber ID, specifying a `resource`. /// /// # Examples /// @@ -372,7 +372,7 @@ impl FromStr for BareJid { } impl BareJid { - /// Constructs a Bare Jabber ID, containing two components. + /// Constructs a bare Jabber ID, containing two components. /// /// This is of the form `node`@`domain`. /// @@ -397,7 +397,7 @@ impl BareJid { } } - /// Constructs a Bare Jabber ID containing only a `domain`. + /// Constructs a bare Jabber ID containing only a `domain`. /// /// This is of the form `domain`. /// @@ -471,7 +471,7 @@ impl BareJid { } } - /// Constructs a Full Jabber ID from a Bare Jabber ID, specifying a `resource`. + /// Constructs a full Jabber ID from a bare Jabber ID, specifying a `resource`. /// /// # Examples /// From d7a74b2f28b6812ec8ae1889151fbda105c607d7 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Mon, 10 Jun 2019 22:55:15 +0200 Subject: [PATCH 52/73] Specify what is a bare and a full JID, and when to use something else. --- src/lib.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 8ef7a3d17defdceac59f01d78528dffb1f7be5a8..ad9ac023852cc0c3d8e36c88401f346772167d80 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -77,6 +77,9 @@ impl From for String { /// - A node/name, `node`, which is the optional part before the @. /// - A domain, `domain`, which is the mandatory part after the @ but before the /. /// - A resource, `resource`, which is the part after the /. +/// +/// Unlike a `BareJid`, it always contains a resource, and should only be used when you are certain +/// there is no case where a resource can be missing. Otherwise, use a `Jid` enum. #[derive(Clone, PartialEq, Eq, Hash)] pub struct FullJid { /// The node part of the Jabber ID, if it exists, else None. @@ -92,7 +95,10 @@ pub struct FullJid { /// A bare Jabber ID is composed of 2 components, of which one is optional: /// /// - A node/name, `node`, which is the optional part before the @. -/// - A domain, `domain`, which is the mandatory part after the @ but before the /. +/// - A domain, `domain`, which is the mandatory part after the @. +/// +/// Unlike a `FullJid`, it can’t contain a resource, and should only be used when you are certain +/// there is no case where a resource can be set. Otherwise, use a `Jid` enum. #[derive(Clone, PartialEq, Eq, Hash)] pub struct BareJid { /// The node part of the Jabber ID, if it exists, else None. From e2b5696beb9a81290dcc1bc8973070bf887eb2c3 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Mon, 10 Jun 2019 22:55:53 +0200 Subject: [PATCH 53/73] Add BareJid and FullJid to the ChangeLog. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c88c32c61212dbe6251849737b07cb3dcaf36b55..ccd5e619161d046d1598df23d004ff77c0929411 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ Version 0.6.0, released 2019-06-19: * Updates - Jid is now an enum, with two variants, Bare(BareJid) and Full(FullJid) + - BareJid and FullJid are two specialised variants of a JID. Version 0.5.3, released 2019-01-16: * Updates From 20a7d4fc5505395a5a6b50f2fefc21b0430451d9 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Mon, 10 Jun 2019 23:09:20 +0200 Subject: [PATCH 54/73] Switch from LGPLv3 to MPL-2.0. --- COPYING | 675 ------------------------------------------------- COPYING.LESSER | 166 ------------ Cargo.toml | 2 +- LICENSE | 373 +++++++++++++++++++++++++++ README.md | 20 +- src/lib.rs | 10 + 6 files changed, 385 insertions(+), 861 deletions(-) delete mode 100644 COPYING delete mode 100644 COPYING.LESSER create mode 100644 LICENSE diff --git a/COPYING b/COPYING deleted file mode 100644 index a737dcfed5db21fb99a8fcb812e995937d38401b..0000000000000000000000000000000000000000 --- a/COPYING +++ /dev/null @@ -1,675 +0,0 @@ - - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. diff --git a/COPYING.LESSER b/COPYING.LESSER deleted file mode 100644 index 5f5ff16a4a0f6104fadb6a5beef527573e46b425..0000000000000000000000000000000000000000 --- a/COPYING.LESSER +++ /dev/null @@ -1,166 +0,0 @@ - - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - - This version of the GNU Lesser General Public License incorporates -the terms and conditions of version 3 of the GNU General Public -License, supplemented by the additional permissions listed below. - - 0. Additional Definitions. - - As used herein, "this License" refers to version 3 of the GNU Lesser -General Public License, and the "GNU GPL" refers to version 3 of the GNU -General Public License. - - "The Library" refers to a covered work governed by this License, -other than an Application or a Combined Work as defined below. - - An "Application" is any work that makes use of an interface provided -by the Library, but which is not otherwise based on the Library. -Defining a subclass of a class defined by the Library is deemed a mode -of using an interface provided by the Library. - - A "Combined Work" is a work produced by combining or linking an -Application with the Library. The particular version of the Library -with which the Combined Work was made is also called the "Linked -Version". - - The "Minimal Corresponding Source" for a Combined Work means the -Corresponding Source for the Combined Work, excluding any source code -for portions of the Combined Work that, considered in isolation, are -based on the Application, and not on the Linked Version. - - The "Corresponding Application Code" for a Combined Work means the -object code and/or source code for the Application, including any data -and utility programs needed for reproducing the Combined Work from the -Application, but excluding the System Libraries of the Combined Work. - - 1. Exception to Section 3 of the GNU GPL. - - You may convey a covered work under sections 3 and 4 of this License -without being bound by section 3 of the GNU GPL. - - 2. Conveying Modified Versions. - - If you modify a copy of the Library, and, in your modifications, a -facility refers to a function or data to be supplied by an Application -that uses the facility (other than as an argument passed when the -facility is invoked), then you may convey a copy of the modified -version: - - a) under this License, provided that you make a good faith effort to - ensure that, in the event an Application does not supply the - function or data, the facility still operates, and performs - whatever part of its purpose remains meaningful, or - - b) under the GNU GPL, with none of the additional permissions of - this License applicable to that copy. - - 3. Object Code Incorporating Material from Library Header Files. - - The object code form of an Application may incorporate material from -a header file that is part of the Library. You may convey such object -code under terms of your choice, provided that, if the incorporated -material is not limited to numerical parameters, data structure -layouts and accessors, or small macros, inline functions and templates -(ten or fewer lines in length), you do both of the following: - - a) Give prominent notice with each copy of the object code that the - Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the object code with a copy of the GNU GPL and this license - document. - - 4. Combined Works. - - You may convey a Combined Work under terms of your choice that, -taken together, effectively do not restrict modification of the -portions of the Library contained in the Combined Work and reverse -engineering for debugging such modifications, if you also do each of -the following: - - a) Give prominent notice with each copy of the Combined Work that - the Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the Combined Work with a copy of the GNU GPL and this license - document. - - c) For a Combined Work that displays copyright notices during - execution, include the copyright notice for the Library among - these notices, as well as a reference directing the user to the - copies of the GNU GPL and this license document. - - d) Do one of the following: - - 0) Convey the Minimal Corresponding Source under the terms of this - License, and the Corresponding Application Code in a form - suitable for, and under terms that permit, the user to - recombine or relink the Application with a modified version of - the Linked Version to produce a modified Combined Work, in the - manner specified by section 6 of the GNU GPL for conveying - Corresponding Source. - - 1) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (a) uses at run time - a copy of the Library already present on the user's computer - system, and (b) will operate properly with a modified version - of the Library that is interface-compatible with the Linked - Version. - - e) Provide Installation Information, but only if you would otherwise - be required to provide such information under section 6 of the - GNU GPL, and only to the extent that such information is - necessary to install and execute a modified version of the - Combined Work produced by recombining or relinking the - Application with a modified version of the Linked Version. (If - you use option 4d0, the Installation Information must accompany - the Minimal Corresponding Source and Corresponding Application - Code. If you use option 4d1, you must provide the Installation - Information in the manner specified by section 6 of the GNU GPL - for conveying Corresponding Source.) - - 5. Combined Libraries. - - You may place library facilities that are a work based on the -Library side by side in a single library together with other library -facilities that are not Applications and are not covered by this -License, and convey such a combined library under terms of your -choice, if you do both of the following: - - a) Accompany the combined library with a copy of the same work based - on the Library, uncombined with any other library facilities, - conveyed under the terms of this License. - - b) Give prominent notice with the combined library that part of it - is a work based on the Library, and explaining where to find the - accompanying uncombined form of the same work. - - 6. Revised Versions of the GNU Lesser General Public License. - - The Free Software Foundation may publish revised and/or new versions -of the GNU Lesser General Public License from time to time. Such new -versions will be similar in spirit to the present version, but may -differ in detail to address new problems or concerns. - - Each version is given a distinguishing version number. If the -Library as you received it specifies that a certain numbered version -of the GNU Lesser General Public License "or any later version" -applies to it, you have the option of following the terms and -conditions either of that published version or of any later version -published by the Free Software Foundation. If the Library as you -received it does not specify a version number of the GNU Lesser -General Public License, you may choose any version of the GNU Lesser -General Public License ever published by the Free Software Foundation. - - If the Library as you received it specifies that a proxy can decide -whether future versions of the GNU Lesser General Public License shall -apply, that proxy's public statement of acceptance of any version is -permanent authorization for you to choose that version for the -Library. diff --git a/Cargo.toml b/Cargo.toml index 04fb6d4f6dd9f113411fd825f0194fa60fa40698..633207237c7b988a6e57270faa9122f473a825e9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ repository = "https://gitlab.com/xmpp-rs/jid-rs" documentation = "https://docs.rs/jid" readme = "README.md" keywords = ["xmpp", "jid"] -license = "LGPL-3.0+" +license = "MPL-2.0" edition = "2018" [badges] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..14e2f777f6c395e7e04ab4aa306bbcc4b0c1120e --- /dev/null +++ b/LICENSE @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. diff --git a/README.md b/README.md index e4b4fd370f7172f0fc2bed9773a095d2178fef54..905c3c3a70d45598297eb2bac8450c074ce78c1d 100644 --- a/README.md +++ b/README.md @@ -10,27 +10,9 @@ can of course use this. What license is it under? ------------------------- -LGPLv3 or later. See `COPYING` and `COPYING.LESSER`. +MPL-2.0 or later, see the `LICENSE` file. Notes ----- This library does not yet implement RFC7622. - -License yadda yadda. --------------------- - - Copyright 2017, jid-rs contributors. - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . diff --git a/src/lib.rs b/src/lib.rs index ad9ac023852cc0c3d8e36c88401f346772167d80..29982c714a19b798b7db69b5f99ba3ab475f2a0b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,13 @@ +// Copyright (c) 2017, 2018 lumi +// Copyright (c) 2017, 2018, 2019 Emmanuel Gil Peyrot +// Copyright (c) 2017, 2018, 2019 Maxime “pep” Buquet +// Copyright (c) 2017, 2018 Astro +// Copyright (c) 2017 Bastien Orivel +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + #![deny(missing_docs)] //! Provides a type for Jabber IDs. From 8ca35d81a450656d5178788ba8f51578e9d25371 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Mon, 10 Jun 2019 23:12:57 +0200 Subject: [PATCH 55/73] Fix CHANGELOG date for 0.6.0. --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ccd5e619161d046d1598df23d004ff77c0929411..642a521da05487c4ef185dcf9709540c34d851ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ -Version 0.6.0, released 2019-06-19: +Version 0.6.0, released 2019-06-10: * Updates - - Jid is now an enum, with two variants, Bare(BareJid) and Full(FullJid) + - Jid is now an enum, with two variants, Bare(BareJid) and Full(FullJid). - BareJid and FullJid are two specialised variants of a JID. Version 0.5.3, released 2019-01-16: From 78b0d016f125d60727c1d9a5756df85b493749b1 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Mon, 10 Jun 2019 23:17:24 +0200 Subject: [PATCH 56/73] Release version 0.6.1, with the MPL-2.0 relicense. --- CHANGELOG.md | 4 ++++ Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 642a521da05487c4ef185dcf9709540c34d851ca..34a0a9b1e1a7d360eece46ca6f20c220124d047c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +Version 0.6.1, released 2019-06-10: + * Updates + - Change the license from LGPLv3 to MPL-2.0. + Version 0.6.0, released 2019-06-10: * Updates - Jid is now an enum, with two variants, Bare(BareJid) and Full(FullJid). diff --git a/Cargo.toml b/Cargo.toml index 633207237c7b988a6e57270faa9122f473a825e9..8a211a972da3a96843516f04fb603ad28826b821 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "jid" -version = "0.6.0" +version = "0.6.1" authors = [ "lumi ", "Emmanuel Gil Peyrot ", From 8f0d5c7ca1368bae1c02b89250cd4df99daa459a Mon Sep 17 00:00:00 2001 From: lumi Date: Sat, 6 Jul 2019 14:55:19 +0200 Subject: [PATCH 57/73] Implement From and From for Jid. --- src/lib.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 29982c714a19b798b7db69b5f99ba3ab475f2a0b..2401792bc08bf3a2879721093249293ca14ea3c9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -80,6 +80,18 @@ impl From for String { } } +impl From for Jid { + fn from(bare_jid: BareJid) -> Jid { + Jid::Bare(bare_jid) + } +} + +impl From for Jid { + fn from(full_jid: FullJid) -> Jid { + Jid::Full(full_jid) + } +} + /// A struct representing a full Jabber ID. /// /// A full Jabber ID is composed of 3 components, of which one is optional: From 750562cd966c3267ef58b663ab846a1526371d03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sat, 20 Jul 2019 19:01:25 +0200 Subject: [PATCH 58/73] add getters for node and domain on Jid MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- src/lib.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 2401792bc08bf3a2879721093249293ca14ea3c9..62847c597966475d7cdd84af0f8ae39c348bbe52 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -92,6 +92,22 @@ impl From for Jid { } } +impl Jid { + /// The node part of the Jabber ID, if it exists, else None. + pub fn node(self) -> Option { + match self { + Jid::Bare(BareJid { node, .. }) | Jid::Full(FullJid { node, .. }) => node, + } + } + + /// The domain of the Jabber ID. + pub fn domain(self) -> String { + match self { + Jid::Bare(BareJid { domain, .. }) | Jid::Full(FullJid { domain, .. }) => domain, + } + } +} + /// A struct representing a full Jabber ID. /// /// A full Jabber ID is composed of 3 components, of which one is optional: @@ -639,6 +655,22 @@ mod tests { ); } + #[test] + fn node_from_jid() { + assert_eq!( + Jid::Full(FullJid::new("a", "b.c", "d")).node(), + Some(String::from("a")), + ); + } + + #[test] + fn domain_from_jid() { + assert_eq!( + Jid::Bare(BareJid::new("a", "b.c")).domain(), + String::from("b.c"), + ); + } + #[test] fn serialise() { assert_eq!( From 6b9e85850740bb0c4f1dafb0386b65e2686cebf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sat, 20 Jul 2019 19:14:12 +0200 Subject: [PATCH 59/73] Release version 0.6.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- CHANGELOG.md | 5 +++++ Cargo.toml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 34a0a9b1e1a7d360eece46ca6f20c220124d047c..40edcd5b457513229bd249d955506950b4991c7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +Version 0.6.2, released 2019-07-20: + * Updates + - Implement From and From for Jid + - Add node and domain getters on Jid + Version 0.6.1, released 2019-06-10: * Updates - Change the license from LGPLv3 to MPL-2.0. diff --git a/Cargo.toml b/Cargo.toml index 8a211a972da3a96843516f04fb603ad28826b821..f3235b3eff745e36c4a3f3d01b0a283c1150e654 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "jid" -version = "0.6.1" +version = "0.6.2" authors = [ "lumi ", "Emmanuel Gil Peyrot ", From 365f26523c91156ac130893418872bf9800a7359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sat, 20 Jul 2019 19:21:08 +0200 Subject: [PATCH 60/73] Add minidom feature for CI tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0b4e77f06d233074e4efced741958cc6a524498c..69b23118cdc68f3f16bfbfde4b1daca990e5e3dd 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,11 +6,11 @@ rust-latest: image: rust:latest script: - cargo build --verbose - - cargo test --verbose + - cargo test --lib --verbose --features=minidom rust-nightly: stage: build image: rustlang/rust:nightly script: - cargo build --verbose - - cargo test --verbose + - cargo test --lib --verbose --features=minidom From 24d3d8696d0a72347894a95512fcf83644434908 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sat, 20 Jul 2019 19:27:31 +0200 Subject: [PATCH 61/73] Build CI with minidom feature MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 69b23118cdc68f3f16bfbfde4b1daca990e5e3dd..5a1213e308553ae38cf2d4ca5f295d4699792d5e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,12 +5,12 @@ rust-latest: stage: build image: rust:latest script: - - cargo build --verbose + - cargo build --verbose --features=minidom - cargo test --lib --verbose --features=minidom rust-nightly: stage: build image: rustlang/rust:nightly script: - - cargo build --verbose + - cargo build --verbose --features=minidom - cargo test --lib --verbose --features=minidom From 74759a7e399c53dcaf17041ee72ca7f1eea4c163 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sat, 20 Jul 2019 19:45:06 +0200 Subject: [PATCH 62/73] Update minidom dep to 0.11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- Cargo.toml | 2 +- src/lib.rs | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f3235b3eff745e36c4a3f3d01b0a283c1150e654..4f6fe560171d271bb223f30ce1ef11ecab7d5991 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,4 +21,4 @@ gitlab = { repository = "xmpp-rs/jid-rs" } [dependencies] failure = "0.1.1" failure_derive = "0.1.1" -minidom = { version = "0.10", optional = true } +minidom = { version = "0.11", optional = true } diff --git a/src/lib.rs b/src/lib.rs index 62847c597966475d7cdd84af0f8ae39c348bbe52..c55c806731bc00b7de88369d535d77134b059c20 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -542,7 +542,7 @@ impl BareJid { } #[cfg(feature = "minidom")] -use minidom::{ElementEmitter, IntoAttributeValue, IntoElements}; +use minidom::{IntoAttributeValue, Node}; #[cfg(feature = "minidom")] impl IntoAttributeValue for Jid { @@ -552,9 +552,9 @@ impl IntoAttributeValue for Jid { } #[cfg(feature = "minidom")] -impl IntoElements for Jid { - fn into_elements(self, emitter: &mut ElementEmitter) { - emitter.append_text_node(String::from(self)) +impl Into for Jid { + fn into(self) -> Node { + Node::Text(String::from(self)) } } @@ -566,9 +566,9 @@ impl IntoAttributeValue for FullJid { } #[cfg(feature = "minidom")] -impl IntoElements for FullJid { - fn into_elements(self, emitter: &mut ElementEmitter) { - emitter.append_text_node(String::from(self)) +impl Into for FullJid { + fn into(self) -> Node { + Node::Text(String::from(self)) } } @@ -580,9 +580,9 @@ impl IntoAttributeValue for BareJid { } #[cfg(feature = "minidom")] -impl IntoElements for BareJid { - fn into_elements(self, emitter: &mut ElementEmitter) { - emitter.append_text_node(String::from(self)) +impl Into for BareJid { + fn into(self) -> Node { + Node::Text(String::from(self)) } } From bf1c2bd48b515d5f4e85040fcf6f6df50d56e02b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Fri, 26 Jul 2019 01:43:57 +0200 Subject: [PATCH 63/73] Release version 0.7.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- CHANGELOG.md | 4 ++++ Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40edcd5b457513229bd249d955506950b4991c7a..d5a731d25b0013e60d0e25784c4020d346f69443 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +Version 0.7.0, released 2019-07-26: + * Breaking + - Update minidom dependency to 0.11 + Version 0.6.2, released 2019-07-20: * Updates - Implement From and From for Jid diff --git a/Cargo.toml b/Cargo.toml index 4f6fe560171d271bb223f30ce1ef11ecab7d5991..77cbae3d3acaac8e06265579d45926aa8a3ed513 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "jid" -version = "0.6.2" +version = "0.7.0" authors = [ "lumi ", "Emmanuel Gil Peyrot ", From 56986a68e48dffbb875bb040a009939636d978d5 Mon Sep 17 00:00:00 2001 From: Randy von der Weide Date: Sat, 31 Aug 2019 13:17:51 +0000 Subject: [PATCH 64/73] Impl Display for Jid --- src/lib.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index c55c806731bc00b7de88369d535d77134b059c20..abe475ef95f28909903642c47926679eb1a1628c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -92,6 +92,12 @@ impl From for Jid { } } +impl fmt::Display for Jid { + fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> { + fmt.write_str(String::from(self.clone()).as_ref()) + } +} + impl Jid { /// The node part of the Jabber ID, if it exists, else None. pub fn node(self) -> Option { @@ -696,6 +702,14 @@ mod tests { assert_eq!(FullJid::from_str("a@b"), Err(JidParseError::NoResource)); } + #[test] + fn display_jids() { + assert_eq!(format!("{}", FullJid::new("a", "b", "c")), String::from("a@b/c")); + assert_eq!(format!("{}", BareJid::new("a", "b")), String::from("a@b")); + assert_eq!(format!("{}", Jid::Full(FullJid::new("a", "b", "c"))), String::from("a@b/c")); + assert_eq!(format!("{}", Jid::Bare(BareJid::new("a", "b"))), String::from("a@b")); + } + #[cfg(feature = "minidom")] #[test] fn minidom() { From cba7a31ea0ec64c03acb8fca20df08c8f0e4c9fb Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Thu, 5 Sep 2019 18:42:22 +0200 Subject: [PATCH 65/73] Remove failure. --- Cargo.toml | 2 -- src/lib.rs | 20 ++++++++++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 77cbae3d3acaac8e06265579d45926aa8a3ed513..162cb9a5bc633340dd41f35e3a0c322dd5d91320 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,4 @@ edition = "2018" gitlab = { repository = "xmpp-rs/jid-rs" } [dependencies] -failure = "0.1.1" -failure_derive = "0.1.1" minidom = { version = "0.11", optional = true } diff --git a/src/lib.rs b/src/lib.rs index c55c806731bc00b7de88369d535d77134b059c20..948576c35e7ac1e02547a0aaf984bf5848f59309 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,34 +14,38 @@ //! //! For usage, check the documentation on the `Jid` struct. -#[macro_use] -extern crate failure_derive; - use std::convert::Into; use std::fmt; use std::str::FromStr; /// An error that signifies that a `Jid` cannot be parsed from a string. -#[derive(Debug, Clone, PartialEq, Eq, Fail)] +#[derive(Debug, Clone, PartialEq, Eq)] pub enum JidParseError { /// Happens when there is no domain, that is either the string is empty, /// starts with a /, or contains the @/ sequence. - #[fail(display = "no domain found in this JID")] NoDomain, /// Happens when there is no resource, that is string contains no /. - #[fail(display = "no resource found in this full JID")] NoResource, /// Happens when the node is empty, that is the string starts with a @. - #[fail(display = "nodepart empty despite the presence of a @")] EmptyNode, /// Happens when the resource is empty, that is the string ends with a /. - #[fail(display = "resource empty despite the presence of a /")] EmptyResource, } +impl fmt::Display for JidParseError { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + write!(fmt, "{}", match self { + JidParseError::NoDomain => "no domain found in this JID", + JidParseError::NoResource => "no resource found in this full JID", + JidParseError::EmptyNode => "nodepart empty despite the presence of a @", + JidParseError::EmptyResource => "resource empty despite the presence of a /", + }) + } +} + /// An enum representing a Jabber ID. It can be either a `FullJid` or a `BareJid`. #[derive(Debug, Clone, PartialEq)] pub enum Jid { From b244a21e1afa965c7430f35e7bb13d6b5b40d96f Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Fri, 6 Sep 2019 11:39:03 +0200 Subject: [PATCH 66/73] Prepare for 0.7.1 release. --- CHANGELOG.md | 5 +++++ Cargo.toml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5a731d25b0013e60d0e25784c4020d346f69443..d15bd671bd2d8cbd9a13120d5f3660b844a76f83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +Version 0.7.1, released 2019-09-06: + * Updates + - Remove failure dependency, to keep compilation times in check + - Impl Display for Jid + Version 0.7.0, released 2019-07-26: * Breaking - Update minidom dependency to 0.11 diff --git a/Cargo.toml b/Cargo.toml index 162cb9a5bc633340dd41f35e3a0c322dd5d91320..f2f0ad10df4861275431793a8009e1c5817ade3b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "jid" -version = "0.7.0" +version = "0.7.1" authors = [ "lumi ", "Emmanuel Gil Peyrot ", From 1638288644bbb6cb3cc9d5858827b4196271670b Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sat, 7 Sep 2019 16:08:53 +0200 Subject: [PATCH 67/73] Reimplement std::error::Error for Error. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It was removed with the removal of failure, but like in minidom (#18) it was probably used by people, so let’s reintroduce it. --- src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 1bf038166e5d1fc6b175962799062203c74ca4a5..900eed5f89fdce90468b759ce9b3bc1fd88c62ce 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,6 +15,7 @@ //! For usage, check the documentation on the `Jid` struct. use std::convert::Into; +use std::error::Error as StdError; use std::fmt; use std::str::FromStr; @@ -35,6 +36,8 @@ pub enum JidParseError { EmptyResource, } +impl StdError for JidParseError {} + impl fmt::Display for JidParseError { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { write!(fmt, "{}", match self { From 0138a6295761cb69bf9cee3ee81ae963db371111 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sun, 8 Sep 2019 22:09:25 +0200 Subject: [PATCH 68/73] Add more helpers on Jid to convert to Bare/FullJid MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- src/lib.rs | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 900eed5f89fdce90468b759ce9b3bc1fd88c62ce..700edaad39ccdd747ef85c63ab76a78800dcdede 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,7 +14,7 @@ //! //! For usage, check the documentation on the `Jid` struct. -use std::convert::Into; +use std::convert::{Into, TryFrom}; use std::error::Error as StdError; use std::fmt; use std::str::FromStr; @@ -121,6 +121,26 @@ impl Jid { } } +impl From for BareJid { + fn from(jid: Jid) -> BareJid { + match jid { + Jid::Full(full) => full.into(), + Jid::Bare(bare) => bare, + } + } +} + +impl TryFrom for FullJid { + type Error = JidParseError; + + fn try_from(jid: Jid) -> Result { + match jid { + Jid::Full(full) => Ok(full), + Jid::Bare(_) => Err(JidParseError::NoResource), + } + } +} + /// A struct representing a full Jabber ID. /// /// A full Jabber ID is composed of 3 components, of which one is optional: @@ -684,6 +704,29 @@ mod tests { ); } + #[test] + fn jid_to_full_bare() { + let full = FullJid::new("a", "b.c", "d"); + let bare = BareJid::new("a", "b.c"); + + assert_eq!( + FullJid::try_from(Jid::Full(full.clone())), + Ok(full.clone()), + ); + assert_eq!( + FullJid::try_from(Jid::Bare(bare.clone())), + Err(JidParseError::NoResource), + ); + assert_eq!( + BareJid::from(Jid::Full(full.clone())), + bare.clone(), + ); + assert_eq!( + BareJid::from(Jid::Bare(bare.clone())), + bare, + ); + } + #[test] fn serialise() { assert_eq!( From 59e0e75d695e11ffc6985c79302037d015efba57 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Fri, 13 Sep 2019 00:42:18 +0200 Subject: [PATCH 69/73] Prepare for 0.7.2 release. --- CHANGELOG.md | 4 ++++ Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d15bd671bd2d8cbd9a13120d5f3660b844a76f83..c1a83e53e7937cb77ae6d7a7a149f75b4a157c1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +Version 0.7.2, released 2019-09-13: + * Updates + - Impl Error for JidParseError again, it got removed due to the failure removal but is still wanted. + Version 0.7.1, released 2019-09-06: * Updates - Remove failure dependency, to keep compilation times in check diff --git a/Cargo.toml b/Cargo.toml index f2f0ad10df4861275431793a8009e1c5817ade3b..fad2217dba7600edfb561c6c9ebcb45d3cc2d3ee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "jid" -version = "0.7.1" +version = "0.7.2" authors = [ "lumi ", "Emmanuel Gil Peyrot ", From d5f6c181af91e05027c24a3e2a8d1466cb044ed3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Fri, 13 Sep 2019 03:26:06 +0200 Subject: [PATCH 70/73] CI: Refactor: split jobs, add tests, and caching MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- .gitlab-ci.yml | 64 +++++++++++++++++++++++++++++++++++++++++++------- CHANGELOG.md | 4 ++++ 2 files changed, 59 insertions(+), 9 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5a1213e308553ae38cf2d4ca5f295d4699792d5e..6996a5520f6bae6c976cf77023259e37e247f9c8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,16 +1,62 @@ stages: - build + - test -rust-latest: - stage: build +variables: + FEATURES: "" + RUST_BACKTRACE: "full" + +.stable: image: rust:latest - script: - - cargo build --verbose --features=minidom - - cargo test --lib --verbose --features=minidom + cache: + key: stable + paths: + - target/ -rust-nightly: - stage: build +.nightly: image: rustlang/rust:nightly + cache: + key: nightly + paths: + - target/ + +.build: + stage: build + script: + - cargo build --verbose --no-default-features --features=$FEATURES + +.test: + stage: test script: - - cargo build --verbose --features=minidom - - cargo test --lib --verbose --features=minidom + - cargo test --lib --verbose --no-default-features --features=$FEATURES + +rust-latest-build: + extends: + - .build + - .stable + +rust-nightly-build: + extends: + - .build + - .nightly + + +rust-latest-test: + extends: + - .test + - .stable + +rust-nightly-test: + extends: + - .test + - .nightly + +rust-latest-build with features=minidom: + extends: rust-latest-build + variables: + FEATURES: "minidom" + +rust-latest-test with features=minidom: + extends: rust-latest-test + variables: + FEATURES: "minidom" diff --git a/CHANGELOG.md b/CHANGELOG.md index c1a83e53e7937cb77ae6d7a7a149f75b4a157c1d..70108afddf06ed8d5d265b9b95aaeb6e2c235f94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +Version XXX, released YYY: + * Updates + - CI: Split jobs, add tests, and caching + Version 0.7.2, released 2019-09-13: * Updates - Impl Error for JidParseError again, it got removed due to the failure removal but is still wanted. From 147d07832edb7d7f82d71c39306dad0f0f6f7a47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Tue, 15 Oct 2019 22:35:46 +0200 Subject: [PATCH 71/73] Prepare for 0.8 release MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- CHANGELOG.md | 4 +++- Cargo.toml | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 70108afddf06ed8d5d265b9b95aaeb6e2c235f94..7d82b5a77f6979243980efca911330da4f1958a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ -Version XXX, released YYY: +Version 0.8, released 2019-10-15: * Updates - CI: Split jobs, add tests, and caching + * Breaking + - 0.7.1 was actually a breaking release Version 0.7.2, released 2019-09-13: * Updates diff --git a/Cargo.toml b/Cargo.toml index fad2217dba7600edfb561c6c9ebcb45d3cc2d3ee..4f4894d07d13c7bd39a35e1f58b69cc57160f0d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "jid" -version = "0.7.2" +version = "0.8.0" authors = [ "lumi ", "Emmanuel Gil Peyrot ", From 176166b60a610bac455899aff39a06f2e802dade Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Wed, 16 Oct 2019 01:23:21 +0200 Subject: [PATCH 72/73] Ensure Jid is Hash-able MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- src/lib.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 700edaad39ccdd747ef85c63ab76a78800dcdede..ec56a71ecd626d839c8b5efb72cdfbe1c022355c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -50,7 +50,7 @@ impl fmt::Display for JidParseError { } /// An enum representing a Jabber ID. It can be either a `FullJid` or a `BareJid`. -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum Jid { /// Bare Jid Bare(BareJid), @@ -624,6 +624,7 @@ mod tests { use super::*; use std::str::FromStr; + use std::collections::HashMap; #[test] fn can_parse_full_jids() { @@ -736,6 +737,11 @@ mod tests { assert_eq!(String::from(BareJid::new("a", "b")), String::from("a@b")); } + #[test] + fn hash() { + let _map: HashMap = HashMap::new(); + } + #[test] fn invalid_jids() { assert_eq!(BareJid::from_str(""), Err(JidParseError::NoDomain)); From 5a6a1d7c97da84cb877daa1228a7ec3815fcc69c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Fri, 18 Oct 2019 14:23:21 +0200 Subject: [PATCH 73/73] Prepare for merge: Move all jid-rs files into jid-rs/ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- .gitignore => jid-rs/.gitignore | 0 .gitlab-ci.yml => jid-rs/.gitlab-ci.yml | 0 CHANGELOG.md => jid-rs/CHANGELOG.md | 0 Cargo.toml => jid-rs/Cargo.toml | 0 LICENSE => jid-rs/LICENSE | 0 README.md => jid-rs/README.md | 0 {src => jid-rs/src}/lib.rs | 0 7 files changed, 0 insertions(+), 0 deletions(-) rename .gitignore => jid-rs/.gitignore (100%) rename .gitlab-ci.yml => jid-rs/.gitlab-ci.yml (100%) rename CHANGELOG.md => jid-rs/CHANGELOG.md (100%) rename Cargo.toml => jid-rs/Cargo.toml (100%) rename LICENSE => jid-rs/LICENSE (100%) rename README.md => jid-rs/README.md (100%) rename {src => jid-rs/src}/lib.rs (100%) diff --git a/.gitignore b/jid-rs/.gitignore similarity index 100% rename from .gitignore rename to jid-rs/.gitignore diff --git a/.gitlab-ci.yml b/jid-rs/.gitlab-ci.yml similarity index 100% rename from .gitlab-ci.yml rename to jid-rs/.gitlab-ci.yml diff --git a/CHANGELOG.md b/jid-rs/CHANGELOG.md similarity index 100% rename from CHANGELOG.md rename to jid-rs/CHANGELOG.md diff --git a/Cargo.toml b/jid-rs/Cargo.toml similarity index 100% rename from Cargo.toml rename to jid-rs/Cargo.toml diff --git a/LICENSE b/jid-rs/LICENSE similarity index 100% rename from LICENSE rename to jid-rs/LICENSE diff --git a/README.md b/jid-rs/README.md similarity index 100% rename from README.md rename to jid-rs/README.md diff --git a/src/lib.rs b/jid-rs/src/lib.rs similarity index 100% rename from src/lib.rs rename to jid-rs/src/lib.rs