# HG changeset patch # User Emmanuel Gil Peyrot # Date 1289349805 -3600 # Node ID 26eb015a7c40abdcaa3d784a6dd118eb30779d97 # Parent 6697f394301ff61e370b83704ba74a31b210b01d Really should learn that “hg addremove” is good. diff --git a/fdsq.js b/fdsq.js new file mode 100644 --- /dev/null +++ b/fdsq.js @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2010 Emmanuel Gil Peyrot + * + * This file is part of PSĜS, a PubSub server written in JavaScript. + * + * PSĜS is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License. + * + * PSĜS 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with PSĜS. If not, see . + */ + +var sha1hex = require('sha1').hex; + +var fdsq = exports; +fdsq.makeRandomId = function() { + return sha1hex(Date()+Math.random()); +}; + +var JID = function(jid) { + this.full = jid; + + var s = jid.indexOf('/'); + if (s == -1) + this.resource = ''; + else { + this.resource = jid.substring(s+1); + jid = jid.substr(0, s); + } + + var a = jid.indexOf('@'); + if (a == -1) { + this.user = ''; + this.server = jid; + } else { + this.user = jid.substr(0, a); + this.server = jid.substr(a+1); + } + this.bare = jid; +}; + +fdsq.toBareJID = function(jid) { + var j = new JID(jid); + return j.bare; +}; + +fdsq.toResource = function(jid) { + var j = new JID(jid); + return j.resource; +}; diff --git a/util.js b/util.js deleted file mode 100644 --- a/util.js +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2010 Emmanuel Gil Peyrot - * - * This file is part of PSĜS, a PubSub server written in JavaScript. - * - * PSĜS is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License. - * - * PSĜS 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with PSĜS. If not, see . - */ - -var sha1hex = require('sha1').hex; - -var util = exports; -util.makeRandomId = function() { - return sha1hex(Date()+Math.random()); -}; - -var JID = function(jid) { - this.full = jid; - - var s = jid.indexOf('/'); - if (s == -1) - this.resource = ''; - else { - this.resource = jid.substring(s+1); - jid = jid.substr(0, s); - } - - var a = jid.indexOf('@'); - if (a == -1) { - this.user = ''; - this.server = jid; - } else { - this.user = jid.substr(0, a); - this.server = jid.substr(a+1); - } - this.bare = jid; -}; - -util.toBareJID = function(jid) { - var j = new JID(jid); - return j.bare; -}; - -util.toResource = function(jid) { - var j = new JID(jid); - return j.resource; -};