Mercurial > psgxs
view util.js @ 8:efe8dbd34780
Rename cx method to cnode and define it if xmpp.js didn’t.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Thu, 26 Aug 2010 23:50:04 +0200 |
parents | 9ee956af41e3 |
children | 60c80751cfa5 |
line wrap: on
line source
/* * Copyright (C) 2010 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> * * 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 <http://www.gnu.org/licenses/>. */ var sha1hex = require('sha1').hex; var util = exports; util.makeRandomId = function() { return sha1hex(Date()+Math.random()); }; var JID = function(jid) { var a = jid.indexOf('@'); var b = jid.indexOf('/', a); this.full = jid; if (b == -1) { this.resource = ''; } else { this.resource = jid.substring(b+1); jid = jid.substring(0, b); } if (a == -1) { this.user = ''; this.server = jid; } else { this.user = jid.substring(0, a); this.server = jid.substring(a+1); } this.bare = jid; }; util.toBareJID = function(jid) { var j = new JID(jid); return j.bare; };