view fdsq.js @ 43:023f767662d3

Fix compatibility with strict mode of node 0.4 and some files without licence header.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 01 Mar 2011 11:58:15 +0100
parents 26eb015a7c40
children 0d3f18bb1d36
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/>.
 */

'use strict';

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;
};