/usr/share/javascript/jssip/lib/Message.js is in libjs-jssip 0.6.34-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | module.exports = Message;
/**
* Dependencies.
*/
var util = require('util');
var events = require('events');
var JsSIP_C = require('./Constants');
var SIPMessage = require('./SIPMessage');
var Utils = require('./Utils');
var RequestSender = require('./RequestSender');
var Transactions = require('./Transactions');
var Exceptions = require('./Exceptions');
function Message(ua) {
this.ua = ua;
// Custom message empty object for high level use
this.data = {};
events.EventEmitter.call(this);
}
util.inherits(Message, events.EventEmitter);
Message.prototype.send = function(target, body, options) {
var request_sender, event, contentType, eventHandlers, extraHeaders,
originalTarget = target;
if (target === undefined || body === undefined) {
throw new TypeError('Not enough arguments');
}
// Check target validity
target = this.ua.normalizeTarget(target);
if (!target) {
throw new TypeError('Invalid target: '+ originalTarget);
}
// Get call options
options = options || {};
extraHeaders = options.extraHeaders && options.extraHeaders.slice() || [];
eventHandlers = options.eventHandlers || {};
contentType = options.contentType || 'text/plain';
this.content_type = contentType;
// Set event handlers
for (event in eventHandlers) {
this.on(event, eventHandlers[event]);
}
this.closed = false;
this.ua.applicants[this] = this;
extraHeaders.push('Content-Type: '+ contentType);
this.request = new SIPMessage.OutgoingRequest(JsSIP_C.MESSAGE, target, this.ua, null, extraHeaders);
if(body) {
this.request.body = body;
this.content = body;
} else {
this.content = null;
}
request_sender = new RequestSender(this, this.ua);
this.newMessage('local', this.request);
request_sender.send();
};
Message.prototype.receiveResponse = function(response) {
var cause;
if(this.closed) {
return;
}
switch(true) {
case /^1[0-9]{2}$/.test(response.status_code):
// Ignore provisional responses.
break;
case /^2[0-9]{2}$/.test(response.status_code):
delete this.ua.applicants[this];
this.emit('succeeded', {
originator: 'remote',
response: response
});
break;
default:
delete this.ua.applicants[this];
cause = Utils.sipErrorCause(response.status_code);
this.emit('failed', {
originator: 'remote',
response: response,
cause: cause
});
break;
}
};
Message.prototype.onRequestTimeout = function() {
if(this.closed) {
return;
}
this.emit('failed', {
originator: 'system',
cause: JsSIP_C.causes.REQUEST_TIMEOUT
});
};
Message.prototype.onTransportError = function() {
if(this.closed) {
return;
}
this.emit('failed', {
originator: 'system',
cause: JsSIP_C.causes.CONNECTION_ERROR
});
};
Message.prototype.close = function() {
this.closed = true;
delete this.ua.applicants[this];
};
Message.prototype.init_incoming = function(request) {
var transaction;
this.request = request;
this.content_type = request.getHeader('Content-Type');
if (request.body) {
this.content = request.body;
} else {
this.content = null;
}
this.newMessage('remote', request);
transaction = this.ua.transactions.nist[request.via_branch];
if (transaction && (transaction.state === Transactions.C.STATUS_TRYING || transaction.state === Transactions.C.STATUS_PROCEEDING)) {
request.reply(200);
}
};
/**
* Accept the incoming Message
* Only valid for incoming Messages
*/
Message.prototype.accept = function(options) {
options = options || {};
var
extraHeaders = options.extraHeaders && options.extraHeaders.slice() || [],
body = options.body;
if (this.direction !== 'incoming') {
throw new Exceptions.NotSupportedError('"accept" not supported for outgoing Message');
}
this.request.reply(200, null, extraHeaders, body);
};
/**
* Reject the incoming Message
* Only valid for incoming Messages
*/
Message.prototype.reject = function(options) {
options = options || {};
var
status_code = options.status_code || 480,
reason_phrase = options.reason_phrase,
extraHeaders = options.extraHeaders && options.extraHeaders.slice() || [],
body = options.body;
if (this.direction !== 'incoming') {
throw new Exceptions.NotSupportedError('"reject" not supported for outgoing Message');
}
if (status_code < 300 || status_code >= 700) {
throw new TypeError('Invalid status_code: '+ status_code);
}
this.request.reply(status_code, reason_phrase, extraHeaders, body);
};
/**
* Internal Callbacks
*/
Message.prototype.newMessage = function(originator, request) {
if (originator === 'remote') {
this.direction = 'incoming';
this.local_identity = request.to;
this.remote_identity = request.from;
} else if (originator === 'local'){
this.direction = 'outgoing';
this.local_identity = request.from;
this.remote_identity = request.to;
}
this.ua.newMessage({
originator: originator,
message: this,
request: request
});
};
|