Commit 6a61adbb authored by Husin Sajjadi's avatar Husin Sajjadi

update 1.0.9

parent 8c9836c6
# Sipml5 webrtc for Ecmascript
# Sipml5 webrtc for Angular
This is a Webrtc library for Angular based on [Sipml5](https://www.doubango.org/sipml5/). In fact, It's a bridge between [Sipml5](https://www.doubango.org/sipml5/) and Angular.
......@@ -7,14 +7,14 @@ This is a Webrtc library for Angular based on [Sipml5](https://www.doubango.org/
Install via npm
```bash
npm i ecmascript-webrtc-sipml
npm i angular-webrtc-sipml
```
## Usage
import SIPmlWebRTC into your component
```javascript
import SIPmlWebRTC from 'ecmascript-webrtc-sipml';
import SIPmlWebRTC from 'angular-webrtc-sipml';
```
Add the following tags into your html component (audio tags are used to play voice call)
......
/*
* Copyright (C) 2012-2018 Doubango Telecom <http://www.doubango.org>
* License: BSD
* This file is part of Open Source sipML5 solution <http://www.sipml5.org>
*/
// IMPORTANT: /!\ DO NOT EDIT THIS FILE /!\
// ================== DEBUG CODE =============== //
let SIPml = require('./SIPml.js')
// var __b_release_mode = false;
// var tag_hdr = document.getElementsByTagName('head')[0];
// ['./SIPml.js', './files/tinySIP/src/tsip_api.js'].forEach(function (file) {
// var tag_script = document.createElement('script');
// tag_script.setAttribute('type', 'text/javascript');
// tag_script.setAttribute('src', file);
// tag_hdr.appendChild(tag_script);
// });
// window.console &&window.console.warn && window.console.warn("YOUR ARE USING DEBUG CODE. PLEASE USE CODE UNDER 'release' FOLDER or check https://code.google.com/p/sipml5/wiki/FAQ#How_to_reduce_the_size_of_the_scripts_before_deploying for more information on how to amalgamate the code.");
// ================== RELEASE CODE =============== //
// http://code.google.com/p/sipml5/wiki/FAQ#How_to_reduce_the_size_of_the_scripts_before_deploying
//
\ No newline at end of file
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
/*
* Copyright (C) 2012-2018 Doubango Telecom <http://www.doubango.org>
* License: BSD
* This file is part of Open Source sipML5 solution <http://www.sipml5.org>
*/
function tmedia_api_add_js_scripts(s_elt) {
var tag_hdr = document.getElementsByTagName(s_elt)[0];
for (var i = 1; i < arguments.length; ++i) {
var tag_script = document.createElement('script');
tag_script.setAttribute('type', 'text/javascript');
tag_script.setAttribute('src', arguments[i] + "?svn=252");
tag_hdr.appendChild(tag_script);
}
};
tmedia_api_add_js_scripts('head',
'src/tinyMEDIA/src/tmedia_common.js',
//'src/tinyMEDIA/src/tmedia_defaults.js', #include_in<tmedia_common.js>
'src/tinyMEDIA/src/tmedia_param.js',
'src/tinyMEDIA/src/tmedia_qos.js'
//'src/tinyMEDIA/src/tmedia_session.js', #include_in<tmedia_common.js>
//'src/tinyMEDIA/src/tmedia_session_jsep.js', #include_in<tmedia_session.js>
//'src/tinyMEDIA/src/tmedia_session_roap.js', #include_in<tmedia_session.js>
//'src/tinyMEDIA/src/tmedia_session_ghost.js' #include_in<tmedia_session.js>
// 'src/tinyMEDIA/src/tmedia_webrtc4all.js' // #include_in<tmedia_common.js>
);
\ No newline at end of file
/*
* Copyright (C) 2012-2018 Doubango Telecom <http://www.doubango.org>
* License: BSD
* This file is part of Open Source sipML5 solution <http://www.sipml5.org>
*/
var tmedia_type_e =
{
NONE: { i_id: 0, s_name: null },
GHOST: { i_id: (0x01 << 0), s_name: null },
AUDIO: { i_id: (0x01 << 1), s_name: "audio" },
VIDEO: { i_id: (0x01 << 2), s_name: "video" },
CHAT: { i_id: (0x01 << 3), s_name: "message" },
FILE: { i_id: (0x01 << 4), s_name: "message" },
T38: { i_id: (0x01 << 5), s_name: "t38" },
SCREEN_SHARE: { i_id: (0x01 << 2) | (0x01 << 6) /* VIDEO + SCREENSHARE */, s_name: "sccreen share" },
BFCP: { i_id: (0x01 << 7), s_name: "bfcp" },
BFCPAUDIO: { i_id: (0x01 << 8) | (0x01 << 7)/*BFCP*/, s_name: "bfcpaudio" },
BFCPVIDEO: { i_id: (0x01 << 9) | (0x01 << 7)/*BFCP*/, s_name: "bfcpvideo" },
MSRP: { i_id: (0x01 << 3) | (0x01 << 4)/* (CHAT.i_id | FILE.i_id) */, s_name: "message" },
AUDIO_VIDEO: { i_id: (0x01 << 1) | (0x01 << 2)/* (AUDIO.i_id | VIDEO.i_id) */, s_name: "audio/video" },
AUDIO_BFCPVIDEO: { i_id: (0x01 << 1) | (0x01 << 9) | (0x01 << 7), s_name: "audio/bfcpvideo" },
VIDEO_BFCPVIDEO: { i_id: (0x01 << 2) | (0x01 << 9) | (0x01 << 7), s_name: "video/bfcpvideo" },
AUDIO_VIDEO_BFCPVIDEO: { i_id: (0x01 << 1) | (0x01 << 2) | (0x01 << 9) | (0x01 << 7), s_name: "audio/video/bfcpvideo" },
ALL: { i_id: 0xFF, s_name: "all" }
};
function tmedia_type_from_id(i_id) {
for (var key in tmedia_type_e) {
if (tmedia_type_e[key].i_id == i_id) {
return tmedia_type_e[key];
}
}
return tmedia_type_e.NONE;
}
if(!window.__b_release_mode){
tmedia_api_add_js_scripts('head',
'src/tinyMEDIA/src/tmedia_webrtc4all.js', // must be first
'src/tinyMEDIA/src/tmedia_defaults.js',
'src/tinyMEDIA/src/tmedia_session.js'
);
}
\ No newline at end of file
/*
* Copyright (C) 2012-2018 Doubango Telecom <http://www.doubango.org>
* License: BSD
* This file is part of Open Source sipML5 solution <http://www.sipml5.org>
*/
var __tmedia_defaults_e_media_type = tmedia_type_e.AUDIO_VIDEO;
function tmedia_defaults_get_media_type() {
return __tmedia_defaults_e_media_type;
}
\ No newline at end of file
/*
* Copyright (C) 2012-2018 Doubango Telecom <http://www.doubango.org>
* License: BSD
* This file is part of Open Source sipML5 solution <http://www.sipml5.org>
*/
var tmedia_param_type_e =
{
CODEC: 0,
SESSION: 1,
MANAGER: 2
};
function tmedia_param(e_type, e_media_type, s_key, o_value) {
this.e_type = e_type;
this.e_media_type = e_media_type;
this.s_key = s_key;
this.o_value = o_value;
}
\ No newline at end of file
/*
* Copyright (C) 2012-2018 Doubango Telecom <http://www.doubango.org>
* License: BSD
* This file is part of Open Source sipML5 solution <http://www.sipml5.org>
*/
var tmedia_qos_status_e =
{
CURR: 0,
DEST: 1,
CONF: 3
};
var tmedia_qos_ptype_e =
{
QOS: 0
};
var tmedia_qos_stype_e =
{
NONE: 0,
SEGMENTED: 1,
E2E: 2
};
var tmedia_qos_strength_e =
{
NONE: 0,
FAILURE: 1,
UNKNOWN: 2,
OPTIONAL: 3,
MANDATORY: 4
};
var tmedia_qos_direction_e =
{
NONE: 0x00,
SEND: (0x01 << 1),
RECV: (0x01 << 2),
SEND_RECV: (0x01 << 1) | (0x01 << 2)// (SEND | RECV)
};
This diff is collapsed.
/*
* Copyright (C) 2012-2018 Doubango Telecom <http://www.doubango.org>
* License: BSD
* This file is part of Open Source sipML5 solution <http://www.sipml5.org>
*/
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/*
* Copyright (C) 2012-2018 Doubango Telecom <http://www.doubango.org>
* License: BSD
* This file is part of Open Source sipML5 solution <http://www.sipml5.org>
*/
function tsk_api_add_js_script(s_elt) {
var tag_hdr = document.getElementsByTagName(s_elt)[0];
for (var i = 1; i < arguments.length; ++i) {
var tag_script = document.createElement('script');
tag_script.setAttribute('type', 'text/javascript');
tag_script.setAttribute('src', arguments[i] + "?svn=252");
tag_hdr.appendChild(tag_script);
}
};
tsk_api_add_js_script('head',
'./src/adapter.js',
'./src/tinySAK/src/tsk_base64.js',
'./src/tinySAK/src/tsk_buff.js',
'./src/tinySAK/src/tsk_fsm.js',
'./src/tinySAK/src/tsk_md5.js',
'./src/tinySAK/src/tsk_param.js',
'./src/tinySAK/src/tsk_ragel.js',
'./src/tinySAK/src/tsk_string.js',
'./src/tinySAK/src/tsk_utils.js'
);
\ No newline at end of file
/*
* Copyright (C) 2012-2018 Doubango Telecom <http://www.doubango.org>
* License: BSD
* This file is part of Open Source sipML5 solution <http://www.sipml5.org>
*/
// Base64 code from Tyler Akins -- http://rumkin.com
var Base64 = (function () {
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
var obj = {
/**
* Encodes a string in base64
* @param {String} input The string to encode in base64.
*/
encode: function (input) {
var output = "";
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;
do {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if (isNaN(chr2)) {
enc3 = enc4 = 64;
} else if (isNaN(chr3)) {
enc4 = 64;
}
output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) +
keyStr.charAt(enc3) + keyStr.charAt(enc4);
} while (i < input.length);
return output;
},
/**
* Decodes a base64 string.
* @param {String} input The string to decode.
*/
decode: function (input) {
var output = "";
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;
// remove all characters that are not A-Z, a-z, 0-9, +, /, or =
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
do {
enc1 = keyStr.indexOf(input.charAt(i++));
enc2 = keyStr.indexOf(input.charAt(i++));
enc3 = keyStr.indexOf(input.charAt(i++));
enc4 = keyStr.indexOf(input.charAt(i++));
chr1 = (enc1 << 2) | (enc2 >> 4);
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
chr3 = ((enc3 & 3) << 6) | enc4;
output = output + String.fromCharCode(chr1);
if (enc3 != 64) {
output = output + String.fromCharCode(chr2);
}
if (enc4 != 64) {
output = output + String.fromCharCode(chr3);
}
} while (i < input.length);
return output;
}
};
return obj;
})();
/*
* Copyright (C) 2012-2018 Doubango Telecom <http://www.doubango.org>
* License: BSD
* This file is part of Open Source sipML5 solution <http://www.sipml5.org>
*/
// convert a string to a integer buffer
// each char will be converted to it's conresponding utf-16 value
function tsk_buff_str2ib(s_str) {
if (!s_str) {
tsk_utils_log_error("Invalid argument");
return -1;
}
var len = s_str.length;
var ib = new Array(len);
for (var i = 0; i < len; ++i) {
ib[i] = s_str.charCodeAt(i);
}
return ib;
}
function tsk_buff_ab2str(buff) {
return tsk_buff_u8b2ascii(new Uint8Array(buff));
}
function tsk_buff_u8b2ascii(au8_buff) {
// return Array.prototype.slice.call(au8_buff).join("");
var str = new String();
var i_length = au8_buff.byteLength == undefined ? au8_buff.length : au8_buff.byteLength;
for (var i = 0; i < i_length; ++i) {
str += String.fromCharCode(au8_buff[i] & 0xff);
}
return str;
}
function tsk_buff_u8b2utf8(au8_buff) {
try {
var str = new String();
var c_char;
var i_length = au8_buff.byteLength == undefined ? au8_buff.length : au8_buff.byteLength;
for (var i = 0; i < i_length; ) {
c_char = au8_buff[i];
if (c_char < 0x80) {
str += String.fromCharCode(c_char); ++i;
}
else if ((c_char > 0xbf) && (c_char < 0xe0)) {
str += String.fromCharCode(((c_char & 0x1f) << 6) | (au8_buff[i + 1] & 0x3f)); i += 2;
}
else {
str += String.fromCharCode(((c_char & 0x0f) << 12) | ((au8_buff[i + 1] & 0x3f) << 6) | (au8_buff[i + 2] & 0x3f)); i += 3;
}
}
return str;
}
catch (e) {
tsk_utils_log_error(e);
return tsk_buff_u8b2ascii(au8_buff);
}
}
function tsk_buff_str2u8b(s_str) {
var array = new Uint8Array(s_str.length);
for (var i = 0; i < s_str.length; ++i) {
array[i] = s_str[i].charCodeAt(0) & 0xff;
}
return array;
}
\ No newline at end of file
/*
* Copyright (C) 2012-2018 Doubango Telecom <http://www.doubango.org>
* License: BSD
* This file is part of Open Source sipML5 solution <http://www.sipml5.org>
*/
tsk_fsm.prototype.__i_state_any = -0xFFFF;
tsk_fsm.prototype.__i_state_default = -0xFFF0;
tsk_fsm.prototype.__i_state_none = -0xFF00;
tsk_fsm.prototype.__i_state_final = -0xF000;
tsk_fsm.prototype.__i_action_any = -0xFFFF;
// fn_onterm = bool fn(o_usr_data)
function tsk_fsm(i_state_curr, i_state_term, fn_onterm, o_usr_data) {
this.i_state_curr = i_state_curr;
this.i_state_term = i_state_term;
this.fn_onterm = fn_onterm;
this.o_usr_data = o_usr_data;
this.ao_entries = new Array();
this.b_debug = false;
}
tsk_fsm.prototype.is_terminated = function () {
return this.i_state_curr == this.i_state_term;
}
tsk_fsm.prototype.is_debug_enabled = function () {
return this.b_debug;
}
tsk_fsm.prototype.set_debug_enabled = function (b_enable) {
this.b_debug = b_enable;
}
tsk_fsm.prototype.set_onterm_callback = function (fn_callback, o_usr_data) {
this.fn_onterm = fn_callback;
this.o_usr_data = o_usr_data;
}
tsk_fsm.prototype.get_usr_data = function () {
return this.o_usr_data;
}
// set( ...entries)
tsk_fsm.prototype.set = function () {
for (var i = 0; i < arguments.length; ++i) {
if (arguments[i]) {
this.ao_entries.push(arguments[i]);
}
}
this.ao_entries.sort(tsk_fsm_entry_compare);
return 0;
}
// tsk_fsm_act(i_action, o_cond_obj1, o_cond_obj2, ...exec_args)
tsk_fsm.prototype.act = function (i_action, o_cond_obj1, o_cond_obj2) {
var b_found = false;
var b_terminates = false;
var i_ret_exec = 0;
var o_entry;
if (this.is_terminated()) {
tsk_utils_log_warn("The FSM is in the final state");
return -2;
}
// FIXME: deadlock
// while (this.b_locked) tsk_utils_log_info("locked");
this.b_locked = true;
for (var i = 0; i < this.ao_entries.length; ++i) {
if (!(o_entry = this.ao_entries[i])) {
continue;
}
if ((o_entry.i_state_from != tsk_fsm.prototype.__i_state_any) && (o_entry.i_state_from != this.i_state_curr)) {
continue;
}
if ((o_entry.i_action != tsk_fsm.prototype.__i_action_any) && (o_entry.i_action != i_action)) {
continue;
}
// check condition
if (!o_entry.fn_condition || o_entry.fn_condition(o_cond_obj1, o_cond_obj2)) {
if (this.is_debug_enabled()) {
tsk_utils_log_info("State machine: " + o_entry.s_description);
}
if (o_entry.i_state_to != tsk_fsm.prototype.__i_state_any) {
this.i_state_curr = o_entry.i_state_to;
}
if (o_entry.fn_execute) {
try {
if ((i_ret_exec = o_entry.fn_execute(Array.prototype.slice.call(arguments, 3)))) {
tsk_utils_log_info("State machine: Exec function failed. Moving to the termnial state");
}
}
catch (e) {
tsk_utils_log_error(e);
i_ret_exec = -3;
}
}
else {
i_ret_exec = 0;
}
b_terminates = (i_ret_exec != 0 || (this.i_state_curr == this.i_state_term));
b_found = true;
break;
}
}
if (b_terminates) {
this.i_state_curr = this.i_state_term;
if (this.fn_onterm) {
this.fn_onterm(this.o_usr_data);
}
}
this.b_locked = false;
return i_ret_exec;
}
// fn_condition = bool fn(o_1, o_2)
// fn_execute = int fn(exec_args[])
function tsk_fsm_entry(i_state_from, i_action, fn_condition, i_state_to, fn_execute, s_description) {
this.i_state_from = i_state_from;
this.i_action = i_action;
this.fn_condition = fn_condition;
this.i_state_to = i_state_to;
this.fn_execute = fn_execute;
this.s_description = s_description;
}
tsk_fsm_entry.prototype.Create = function (i_state_from, i_action, fn_condition, i_state_to, fn_execute, s_description) {
return new tsk_fsm_entry(i_state_from, i_action, fn_condition, i_state_to, fn_execute, s_description);
}
tsk_fsm_entry.prototype.CreateAlways = function(i_state_from, i_action, i_state_to, fn_execute, s_description) {
return new tsk_fsm_entry(i_state_from, i_action, null, i_state_to, fn_execute, s_description);
}
tsk_fsm_entry.prototype.CreateNothing = function(i_state_from, i_action, fn_condition, s_description) {
return new tsk_fsm_entry(i_state_from, i_action, fn_condition, i_state_from, null, s_description);
}
tsk_fsm_entry.prototype.CreateAlwaysNothing = function(i_state_from, s_description) {
return new tsk_fsm_entry(i_state_from, tsk_fsm.prototype.__i_action_any, null, i_state_from, null, s_description);
}
function tsk_fsm_entry_compare(o_entry1, o_entry2) {
if (o_entry1 && o_entry2) {
if (o_entry1.i_state_from == tsk_fsm.prototype.__i_state_any) {
return +20;
}
else if (o_entry2.i_state_from == tsk_fsm.prototype.__i_state_any) {
return -20;
}
// put "any" actions at the bottom (weak)
if (o_entry1.i_action == tsk_fsm.prototype.__i_action_any) {
return +10;
}
else if (o_entry2.i_action == tsk_fsm.prototype.__i_action_any) {
return -10;
}
// put conditions first
return o_entry1.fn_condition ? -1 : (o_entry2.fn_condition ? 1 : 0);
}
return 0
}
\ No newline at end of file
This diff is collapsed.
/*
* Copyright (C) 2012-2018 Doubango Telecom <http://www.doubango.org>
* License: BSD
* This file is part of Open Source sipML5 solution <http://www.sipml5.org>
*/
function tsk_param_create(s_name, s_value) {
var self = new Object();
self.s_name = s_name;
self.s_value = s_value;
self.b_tag = false;
return self;
}
function tsk_param_create_null() {
return tsk_param_create(null, null);
}
function tsk_param_parse(s_line) {
if (!tsk_string_is_null_or_empty(s_line)) {
var i_start = 0;
var i_end = s_line.length;
var i_equal = tsk_string_index_of(s_line, i_end, "=");
var s_name = null;
var s_value = null;
if (i_equal >= 0 && i_equal < i_end) {
s_name = s_line.substring(i_start, i_start + (i_equal - i_start));
s_value = s_line.substring(i_equal + 1, i_equal + (i_end - i_equal));
}
else {
s_name = s_line;
}
return tsk_param_create(s_name, s_value);
}
return null;
}
function tsk_param_get_index_by_name(ao_params, s_name) {
if (ao_params && !tsk_string_is_null_or_empty(s_name)) {
var s_name_i = s_name.toLowerCase();
for(var i = 0; i < ao_params.length; ++i){
if(ao_params[i].s_name.toLowerCase() == s_name_i){
return i;
}
}
}
return -1;
}
function tsk_param_get_by_name(ao_params, s_name) {
var i_index = tsk_param_get_index_by_name(ao_params, s_name);
if(i_index != -1){
return ao_params[i_index];
}
return null;
}
function tsk_param_get_value_by_name(ao_params, s_name) {
var o_param = tsk_param_get_by_name(ao_params, s_name);
if(o_param){
return o_param.s_value;
}
return null;
}
function tsk_params_have_param(ao_params, s_name) {
return tsk_param_get_by_name(ao_params, s_name) != null;
}
function tsk_params_add(ao_params, s_name, s_value){
if(ao_params && !tsk_string_is_null_or_empty(s_name)){
var i_index = tsk_param_get_index_by_name(ao_params, s_name);
if(i_index != -1){
ao_params[i_index].s_value = s_value;
}
else{
ao_params.push(tsk_param_create(s_name, s_value));
}
}
}
function tsk_params_add_param(ao_params, o_param) {
if (ao_params && o_param) {
tsk_params_add(ao_params, o_param.s_name, o_param.s_value);
}
}
function tsk_params_remove_by_name(ao_params, s_name){
if(ao_params && !tsk_string_is_null_or_empty(s_name)){
var i_index = tsk_param_get_index_by_name(ao_params, s_name);
if(i_index != -1){
ao_params.splice(i_index, 1);
}
}
}
function tsk_param_tostring(o_param){
if(o_param && o_param.s_name){
return !tsk_string_is_null_or_empty(o_param.s_value) ? (o_param.s_name + "=" + o_param.s_value) : o_param.s_name;
}
return "";
}
function tsk_params_tostring(o_params, c_separator){
var s_ret = "";
if(o_params){
for (var i = 0; i < o_params.length; ++i) {
if (!tsk_string_is_null_or_empty(s_ret)) {
s_ret += c_separator;
}
s_ret += tsk_param_tostring(o_params[i]);
}
}
return s_ret;
}
/*
* Copyright (C) 2012-2018 Doubango Telecom <http://www.doubango.org>
* License: BSD
* This file is part of Open Source sipML5 solution <http://www.sipml5.org>
*/
function tsk_ragel_state_create() {
var self = new Object();
tsk_ragel_state_init(self, null, 0);
return self;
}
function tsk_ragel_state_init(o_self, o_data, i_size) {
o_self.i_cs = 0;
o_self.i_p = 0;
o_self.i_pe = i_size;
o_self.o_data = o_data;
o_self.s_data = null;
o_self.i_eof = 0;
o_self.i_tag_start = 0;
o_self.i_tag_end = i_size;
}
function tsk_ragel_state_init_ai(o_self, ai_data) {
return tsk_ragel_state_init_str(o_self, tsk_buff_ab2str(ai_data));
}
function tsk_ragel_state_init_str(o_self, s_str) {
tsk_ragel_state_init(o_self, tsk_buff_str2ib(s_str), s_str.length);
o_self.s_data = s_str;
}
function tsk_ragel_parser_get_string(s_str, i_p, i_tag_start) {
var i_len = (i_p - i_tag_start);
var s_ret = null;
if (i_len > 0) {
s_ret = s_str.substring(i_tag_start, (i_tag_start + i_len));
}
return s_ret;
}
function tsk_ragel_parser_get_int(s_str, i_p, i_tag_start) {
var i_ret = 0;
var s_curr = tsk_ragel_parser_get_string(s_str, i_p, i_tag_start);
if (!tsk_string_is_null_or_empty(s_curr)) {
i_ret = parseInt(s_curr);
}
return i_ret;
}
function tsk_ragel_parser_get_param(s_str, i_p, i_tag_start) {
if (!tsk_string_is_null_or_empty(s_str)) {
var i_len = (i_p - i_tag_start);
return tsk_param_parse(s_str.substring(i_tag_start, i_tag_start + i_len));
}
return null;
}
function tsk_ragel_add_param(s_str, i_p, i_tag_start, ao_params) {
var o_param = tsk_ragel_parser_get_param(s_str, i_p, i_tag_start);
if (o_param) {
ao_params.push(o_param);
}
}
function tsk_ragel_parser_add_string(s_str, i_p, i_tag_start, sa_strings){
var s_curr = tsk_ragel_parser_get_string(s_str, i_p, i_tag_start);
if (!tsk_string_is_null_or_empty(s_curr)) {
sa_strings.push(s_curr);
}
return sa_strings;
}
function tsk_ragel_scanner_get_string(s_str, i_ts, i_te){
var i_len = (i_te - i_ts);
var s_ret = null;
if(i_len > 0){
s_ret = s_str.substring(i_ts, (i_ts + i_len));
}
return s_ret;
}
function tsk_ragel_scanner_get_int(s_str, i_ts, i_te){
var s_curr = tsk_ragel_scanner_get_string(s_str, i_ts, i_te);
if(s_curr){
return parseInt(s_curr);
}
return 0;
}
function tsk_tagel_scanner_add_param(s_str, i_ts_i_te, ao_params) {
if (ao_params && !tsk_string_is_null_or_empty(s_str)) {
var i_len = (te - ts);
var o_param = tsk_param_parse(s_str.substring(i_ts, i_ts + i_len));
ao_params.push(o_param);
}
}
\ No newline at end of file
/*
* Copyright (C) 2012-2018 Doubango Telecom <http://www.doubango.org>
* License: BSD
* This file is part of Open Source sipML5 solution <http://www.sipml5.org>
*/
function tsk_string_is_null_or_empty(s_str) {
return !s_str || s_str == "";
}
function tsk_string_is_string(o_str) {
return (o_str instanceof String || typeof o_str == "string");
}
function tsk_string_index_of(s_str, i_len, s_substr){
var i_ret = -1;
if(s_str && s_substr){
i_ret = s_str.indexOf(s_substr);
}
return i_ret < i_len ? i_ret : -1;
}
function tsk_string_contains(s_str, i_len, s_substr){
return tsk_string_index_of(s_str, i_len, s_substr) >= 0;
}
function tsk_string_unquote(s_str, c_lquote, c_rquote){
var s_ret = s_str;
if(s_ret){
var i_len = s_ret.length;
if(i_len >= 2 && s_ret[0] == c_lquote && s_ret[i_len - 1] == c_rquote){
s_ret = s_str.substring(1, i_len - 1);
}
}
return s_ret;
}
function tsk_string_unquote_2(s_str){
return tsk_string_unquote(s_str, "\"", "\"");
}
function tsk_strdup(s_str) {
if (s_str) {
return new String(s_str).toString();
}
return s_str;
}
// tsk_string_format(s_format, ...)
function tsk_string_format(s_str) {
for (var i = 1; i < arguments.length; i++) {
var regexp = new RegExp('\\{' + (i - 1) + '\\}', 'gi');
s_str = s_str.replace(regexp, arguments[i]);
}
return s_str;
};
function tsk_string_equals(s_1, s_2) {
return (s_1 == s_2);
}
function tsk_string_iequals(s_1, s_2) {
if (s_1 && s_2) {
return s_1.toLowerCase() == s_2.toLowerCase();
}
return (s_1 == s_2);
}
function tsk_string_random_from_dict(i_length, s_dict) {
var s_ret = "";
for (var i = 0; i < i_length; i++) {
s_ret += s_dict[Math.floor(Math.random() * s_dict.length)];
}
return s_ret;
}
function tsk_string_random(i_length) {
var s_dict = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
return tsk_string_random_from_dict(i_length, s_dict);
}
function tsk_string_random_uuid() {
// e.g. 6ba7b810-9dad-11d1-80b4-00c04fd430c8
var s_dict = "0123456789abcdef";
return tsk_string_format("{0}-{1}-{2}-{3}-{4}",
tsk_string_random_from_dict(8, s_dict),
tsk_string_random_from_dict(4, s_dict),
tsk_string_random_from_dict(4, s_dict),
tsk_string_random_from_dict(4, s_dict),
tsk_string_random_from_dict(12, s_dict));
}
function tsk_string_to_int(s_str, i_default) {
try{ return parseInt(s_str); }
catch(e){ return i_default; }
}
function tsk_string_to_object(s_str) {
if(!tsk_string_is_null_or_empty(s_str)){
try{ eval("var obj = " + s_str + ";"); return obj; }
catch(e){}
}
}
// s_url: <scheme>://<host>:<port>/<dir>
// <dir> is optional
// s_url: udp://192.168.0.10:8545/ws
// @return array is succeed or null otherwise
function tsk_string_parse_url(s_url) {
if (!s_url) {
tsk_utils_log_error("Invalid argument");
return null;
}
var i_0 = s_url.indexOf("://");
var i_1 = s_url.lastIndexOf(":");
if (i_0 == -1 || i_1 == -1) {
tsk_utils_log_error(s_url + " not valid as url");
return null;
}
var ao_params = new Array();
ao_params.push(s_url.substring(0, i_0));
ao_params.push(s_url.substring((i_0 + 3), i_1));
try {
var i_3 = s_url.substring(i_0 + 3).indexOf("/");
if (i_3 == -1) {
ao_params.push(parseInt(s_url.substring(i_1 + 1), 10));
}
else {
ao_params.push(parseInt(s_url.substring(i_1 + 1, i_3 + i_0 + 3), 10));
ao_params.push(s_url.substring(i_3 + i_0 + 3 + 1));
}
}
catch (e) {
tsk_utils_log_error(e);
return null;
}
return ao_params;
}
\ No newline at end of file
/*
* Copyright (C) 2012-2018 Doubango Telecom <http://www.doubango.org>
* License: BSD
* This file is part of Open Source sipML5 solution <http://www.sipml5.org>
*/
function tsk_utils_init_webrtc() {
// WebRtc plugins
WebRtc4all_Init();
}
function tsk_utils_have_websocket() {
try {
return !!window.WebSocket;
}
catch (e) {
return false;
}
}
function tsk_utils_have_webrtc() {
return (WebRtc4all_GetType() != WebRtcType_e.NONE);
}
function tsk_utils_have_webrtc4all() {
return (tsk_utils_have_webrtc4npapi() || tsk_utils_have_webrtc4ie());
}
function tsk_utils_have_webrtc4npapi() {
return (WebRtc4all_GetType() == WebRtcType_e.NPAPI);
}
function tsk_utils_have_webrtc4ie() {
return (WebRtc4all_GetType() == WebRtcType_e.IE);
}
function tsk_utils_have_webrtc4native() {
return (WebRtc4all_GetType() == WebRtcType_e.NATIVE);
}
function tsk_utils_have_webrtc4ericsson() {
return (WebRtc4all_GetType() == WebRtcType_e.ERICSSON);
}
function tsk_utils_webrtc4all_get_version() {
return WebRtc4all_GetVersion();
}
function tsk_utils_have_stream() {
try {
return (tsk_utils_have_webrtc4all() || !!navigator.getUserMedia);
}
catch (e) { }
return false;
}
var __s_navigator_friendly_name = undefined;
function tsk_utils_get_navigator_friendly_name(){
if(!__s_navigator_friendly_name){
__s_navigator_friendly_name = 'unknown';
if (navigator.userAgent || navigator.appName) {
var ao_friendly_names = [
{s_id: 'chrome', s_name: 'chrome'},
{s_id: 'firefox', s_name: 'firefox'},
{s_id: 'safari', s_name: 'safari'},
{s_id: 'opera', s_name: 'opera'},
{s_id: 'microsoft internet explorer', s_name: 'ie'},
{s_id: 'netscape', s_name: 'netscape'}
];
var s_userAgent = navigator.userAgent ? navigator.userAgent.toLowerCase() : 'null';
var s_appName = navigator.appName ? navigator.appName.toLowerCase() : 'null';
for (var i_index = 0; i_index < ao_friendly_names.length; ++i_index) {
if (s_userAgent.indexOf(ao_friendly_names[i_index].s_id) != -1 || s_appName.indexOf(ao_friendly_names[i_index].s_id) != -1) {
__s_navigator_friendly_name = ao_friendly_names[i_index].s_name;
break;
}
}
}
}
return __s_navigator_friendly_name;
}
var __s_system_friendly_name = undefined;
function tsk_utils_get_system_friendly_name(){
if(!__s_system_friendly_name){
__s_system_friendly_name = 'unknown';
if (navigator.appVersion) {
var ao_friendly_names = [
{s_id: 'mac', s_name: 'mac'},
{s_id: 'powerpc', s_name: 'powerpc'},
{s_id: 'win', s_name: 'windows'},
{s_id: 'sunos', s_name: 'sunos'},
{s_id: 'linux', s_name: 'linux'}
];
var s_appVersion = navigator.appVersion.toLowerCase();
for (var i_index = 0; i_index < ao_friendly_names.length; ++i_index) {
if (s_appVersion.indexOf(ao_friendly_names[i_index].s_id) != -1) {
__s_system_friendly_name = ao_friendly_names[i_index].s_name;
break;
}
}
}
}
return __s_system_friendly_name;
}
var __i_debug_level = 4; // INFO:4, WARN:3, ERROR:2, FATAL:1
function tsk_utils_log_set_level(i_level) {
__i_debug_level = i_level;
}
function tsk_utils_log_info(s_msg) {
if (__i_debug_level >= 4) {
window.console && window.console.info && window.console.info(s_msg);
}
}
function tsk_utils_log_warn(s_msg) {
if (__i_debug_level >= 3) {
window.console && window.console.warn && window.console.warn(s_msg);
}
}
function tsk_utils_log_error(s_msg) {
if (__i_debug_level >= 2) {
window.console && window.console.error && window.console.error(s_msg);
}
}
function tsk_utils_log_fatal(s_msg) {
if(__i_debug_level >= 1) {
tsk_utils_log_error(s_msg);
}
}
\ No newline at end of file
# Ragel generator
# For more information about Ragel: http://www.complang.org/ragel/
# folder (./src/headers) jsname(tsdp_parser_message) jrlname (tsdp_parser_message)
ProcessFile()
{
ragel-js $OPTIONS -o $1/$2.js ./ragel/$3.jrl
sed -i 's/const _tsdp_machine_/_tsdp_machine_/g' $1/$2.js
sed -i 's/const tsdp_machine_/tsdp_machine_/g' $1/$2.js
# sed -i -b 's/if (_goto_level <= _test_eof) {$1/$2.js}//g' $1/$2.js
}
export OPTIONS="-E -L -T0"
# SDP Message parser
ProcessFile "./src" "tsdp_parser_message" "tsdp_parser_message"
# ==Str (E, I, K, P, R, S, U, Z)
ProcessFile "./src/headers" "tsdp_header_Str" "tsdp_parser_header_Str"
# ==A
ProcessFile "./src/headers" "tsdp_header_A" "tsdp_parser_header_A"
# ==B
#ProcessFile "./src/headers" "tsdp_header_B" "tsdp_parser_header_B"
# ==C
ProcessFile "./src/headers" "tsdp_header_C" "tsdp_parser_header_C"
# ==Dummy
#ProcessFile "./src/headers" "tsdp_header_Dummy" "tsdp_parser_header_Dummy"
# ==E
#ragel.exe $OPTIONS -o ./src/headers/tsdp_header_E.js ./ragel/tsdp_parser_header_E.jrl
# ==I
#ragel.exe $OPTIONS -o ./src/headers/tsdp_header_I.js ./ragel/tsdp_parser_header_I.jrl
# ==K
#ragel.exe $OPTIONS -o ./src/headers/tsdp_header_K.js ./ragel/tsdp_parser_header_K.jrl
# ==M
ProcessFile "./src/headers" "tsdp_header_M" "tsdp_parser_header_M"
# ==O
ProcessFile "./src/headers" "tsdp_header_O" "tsdp_parser_header_O"
# ==P
#ragel.exe $OPTIONS -o ./src/headers/tsdp_header_P.js ./ragel/tsdp_parser_header_P.jrl
# ==R
#ProcessFile "./src/headers" "tsdp_header_R" "tsdp_parser_header_R"
# ==S
#ragel.exe $OPTIONS -o ./src/headers/tsdp_header_S.js ./ragel/tsdp_parser_header_S.jrl
# ==T
#ProcessFile "./src/headers" "tsdp_header_T" "tsdp_parser_header_T"
# ==U
#ragel.exe $OPTIONS -o ./src/headers/tsdp_header_U.js ./ragel/tsdp_parser_header_U.jrl
# ==V
ProcessFile "./src/headers" "tsdp_header_V" "tsdp_parser_header_V"
# ==Z
#ProcessFile "./src/headers" "tsdp_header_Z" "tsdp_parser_header_Z"
/*
* Copyright (C) 2012 Doubango Telecom <http://www.doubango.org>
* License: BSD
* This file is part of Open Source sipML5 solution <http://www.sipml5.org>
*/
%%{
machine tsdp_machine_utils;
OCTET = "0x"[0-9A-Fa-f]+;
CHAR = 0x01..0x7f;
VCHAR = 0x21..0x7e;
ALPHA = 0x41..0x5a | 0x61..0x7a;
DIGIT = 0x30..0x39;
CTL = 0x00..0x1f | 0x7f;
HTAB = "\t";
LF = "\n";
CR = "\r";
SP = " ";
DQUOTE = "\"";
BIT = "0" | "1";
HEXDIG = DIGIT | "A"i | "B"i | "C"i | "D"i | "E"i | "F"i;
CRLF = CR LF;
WSP = SP | HTAB;
LWSP = ( WSP | ( CRLF WSP ) )*;
LWS = ( WSP* CRLF )? WSP+;
SWS = LWS?;
EQUAL = SWS "=" SWS;
LHEX = DIGIT | 0x61..0x66;
HCOLON = ( SP | HTAB )* ":" SWS;
separators = "(" | ")" | "<" | ">" | "@" | "," | ";" | ":" | "\\" | DQUOTE | "/" | "[" | "]" | "?" | "=" | "{" | "}" | SP | HTAB;
STAR = SWS "*" SWS;
SLASH = SWS "/" SWS;
LPAREN = SWS "(" SWS;
RPAREN = SWS ")" SWS;
COMMA = SWS "," SWS;
SEMI = SWS ";" SWS;
COLON = SWS ":" SWS;
LAQUOT = SWS "<";
LDQUOT = SWS DQUOTE;
RAQUOT = ">" SWS;
RDQUOT = DQUOTE SWS;
UTF8_CONT = 0x80..0xbf;
##### FIXME: UTF8_NONASCII up to 2bytes will fail on Android
UTF8_NONASCII = ( 0x80..0xff );
#UTF8_NONASCII = ( 0xc0..0xdf UTF8_CONT ) | ( 0xe0..0xef UTF8_CONT{2} ) | ( 0xf0..0xf7 UTF8_CONT{3} ) | ( 0xf8..0xfb UTF8_CONT{4} ) | ( 0xfc..0xfd UTF8_CONT{5} ); ctext = 0x21..0x27 | 0x2a..0x5b | 0x5d..0x7e | UTF8_NONASCII | LWS;
qvalue = ( "0" ( "." DIGIT{,3} )? ) | ( "1" ( "." "0"{,3} )? );
js_any = 0x0000..0xffff;
alphanum = ALPHA | DIGIT;
token = ( alphanum | "-" | "." | "!" | "%" | "*" | "_" | "+" | "`" | "'" | "~" )+;
ietf_token = token;
x_token = "x-"i token;
iana_token = token;
token_nodot = ( alphanum | "-" | "!" | "%" | "*" | "_" | "+" | "`" | "'" | "~" )+;
word = ( alphanum | "-" | "." | "!" | "%" | "*" | "_" | "+" | "`" | "'" | "~" | "(" | ")" | "<" | ">" | ":" | "\\" | DQUOTE | "/" | "[" | "]" | "?" | "{" | "}" )+;
}%%
/*
* Copyright (C) 2012 Doubango Telecom <http://www.doubango.org>
* License: BSD
* This file is part of Open Source sipML5 solution <http://www.sipml5.org>
*/
tsdp_header_A.prototype = Object.create(tsdp_header.prototype);
%%{
machine tsdp_machine_parser_header_A;
# Includes
include tsdp_machine_utils "./tsdp_machine_utils.jrl";
action tag{
i_tag_start = p;
}
action parse_field{
hdr_A.s_field = tsk_ragel_parser_get_string(s_str, p, i_tag_start);
}
action parse_value{
hdr_A.s_value = tsk_ragel_parser_get_string(s_str, p, i_tag_start);
}
field = token>tag %parse_field;
value = js_any*>tag %parse_value;
A = 'a' SP* "=" SP*<: ((field ":" value) | (field));
# Entry point
main := A :>CRLF?;
}%%
%%write data;
function tsdp_header_A(s_field, s_value){
tsdp_header.call(this, tsdp_header_type_e.A);
this.s_field = s_field;
this.s_value = s_value;
}
tsdp_header_A.prototype.toString = function(){
return tsk_string_format("{0}{1}{2}",
this.s_field,
this.s_value ? ":" : "",
this.s_value ? this.s_value : "");
}
tsdp_header_A.prototype.RemoveAllByField = function(ao_headers, s_field){
var o_hdr_A;
if(!ao_headers || !s_field){
tsk_utils_log_error("Invalid parameter");
return -1;
}
for(i = 0; i < ao_headers.length; ){
o_hdr_A = ao_headers[i];
if(tsk_string_iequals(s_field, o_hdr_A.s_field)){
ao_headers.splice(i, 1);
continue;
}
++i;
}
return 0;
}
tsdp_header_A.prototype.Parse = function(s_str){
var cs = 0;
var p = 0;
var pe = s_str.length;
var eof = pe;
var data = tsk_buff_str2ib(s_str);
var i_tag_start;
var hdr_A = new tsdp_header_A(null, null);
%%write init;
%%write exec;
if( cs < %%{ write first_final; }%% ){
tsk_utils_log_error("Failed to parse \"a=\" header: " + s_str);
return null;
}
return hdr_A;
}
/*
* Copyright (C) 2012 Doubango Telecom <http://www.doubango.org>
* License: BSD
* This file is part of Open Source sipML5 solution <http://www.sipml5.org>
*/
tsdp_header_B.prototype = Object.create(tsdp_header.prototype);
%%{
machine tsdp_machine_parser_header_B;
# Includes
include tsdp_machine_utils "./tsdp_machine_utils.jrl";
action tag{
i_tag_start = p;
}
action parse_bwtype{
hdr_B.s_bwtype = tsk_ragel_parser_get_string(s_str, p, i_tag_start);
}
action parse_bandwidth{
hdr_B.i_bandwidth = tsk_ragel_parser_get_int(s_str, p, i_tag_start);
}
bwtype = token>tag %parse_bwtype;
bandwidth = DIGIT+>tag %parse_bandwidth;
B = 'b' SP* "=" SP*<: bwtype ":" bandwidth;
# Entry point
main := B :>CRLF?;
}%%
%%write data;
function tsdp_header_B(s_bwtype, i_bandwidth){
tsdp_header.call(this, tsdp_header_type_e.A);
this.s_bwtype = s_bwtype;
this.i_bandwidth = i_bandwidth;
}
tsdp_header_B.prototype.toString = function(){
return tsk_string_format("{0}:{1}", this.s_bwtype, this.i_bandwidth);
}
tsdp_header_B.prototype.Parse = function(s_str){
var cs = 0;
var p = 0;
var pe = s_str.length;
var eof = pe;
var data = tsk_buff_str2ib(s_str);
var i_tag_start;
var hdr_B = new tsdp_header_B(null, 0);
%%write init;
%%write exec;
if( cs < %%{ write first_final; }%% ){
tsk_utils_log_error("Failed to parse \"b=\" header: " + s_str);
return null;
}
return hdr_B;
}
/*
* Copyright (C) 2012 Doubango Telecom <http://www.doubango.org>
* License: BSD
* This file is part of Open Source sipML5 solution <http://www.sipml5.org>
*/
tsdp_header_C.prototype = Object.create(tsdp_header.prototype);
%%{
machine tsdp_machine_parser_header_C;
# Includes
include tsdp_machine_utils "./tsdp_machine_utils.jrl";
action tag{
i_tag_start = p;
}
action parse_nettype{
hdr_C.s_nettype = tsk_ragel_parser_get_string(s_str, p, i_tag_start);
}
action parse_addrtype{
hdr_C.s_addrtype = tsk_ragel_parser_get_string(s_str, p, i_tag_start);
}
action parse_addr{
hdr_C.s_addr = tsk_ragel_parser_get_string(s_str, p, i_tag_start);
}
nettype = js_any* >tag %parse_nettype;
addrtype = js_any* >tag %parse_addrtype;
addr = js_any* >tag %parse_addr;
C = 'c' SP* "=" SP*<: nettype :>SP addrtype :>SP addr;
# Entry point
main := C :>CRLF?;
}%%
%%write data;
function tsdp_header_C(s_nettype, s_addrtype, s_addr){
tsdp_header.call(this, tsdp_header_type_e.C);
this.s_nettype = s_nettype;
this.s_addrtype = s_addrtype;
this.s_addr = s_addr;
}
tsdp_header_C.prototype.toString = function(){
return tsk_string_format("{0} {1} {2}",
this.s_nettype,
this.s_addrtype,
this.s_addr);
}
tsdp_header_C.prototype.Parse = function(s_str){
var cs = 0;
var p = 0;
var pe = s_str.length;
var eof = pe;
var data = tsk_buff_str2ib(s_str);
var i_tag_start;
var hdr_C = new tsdp_header_C(null, null, null);
%%write init;
%%write exec;
if( cs < %%{ write first_final; }%% ){
tsk_utils_log_error("Failed to parse \"c=\" header: " + s_str);
return null;
}
return hdr_C;
}
\ No newline at end of file
/*
* Copyright (C) 2012 Doubango Telecom <http://www.doubango.org>
* License: BSD
* This file is part of Open Source sipML5 solution <http://www.sipml5.org>
*/
tsdp_header_Dummy.prototype = Object.create(tsdp_header.prototype);
%%{
machine tsdp_machine_parser_header_Dummy;
# Includes
include tsdp_machine_utils "./tsdp_machine_utils.jrl";
action tag{
i_tag_start = p;
}
action parse_name{
hdr_Dummy.c_name = s_str[i_tag_start];
}
action parse_value{
hdr_Dummy.s_value = tsk_ragel_parser_get_string(s_str, p, i_tag_start);
}
Dummy = alpha>tag %parse_name SP* "=" SP*<: js_any*>tag %parse_value;
# Entry point
main := Dummy :>CRLF?;
}%%
%%write data;
function tsdp_header_Dummy(c_name, s_value){
tsdp_header.call(this, tsdp_header_type_e.DUMMY);
this.c_name = c_name;
this.s_value = s_value;
}
tsdp_header_Dummy.prototype.toString = function(){
return this.s_value;
}
tsdp_header_Dummy.prototype.Parse = function(s_str){
var cs = 0;
var p = 0;
var pe = s_str.length;
var eof = pe;
var data = tsk_buff_str2ib(s_str);
var i_tag_start;
var hdr_Dummy = new tsdp_header_Dummy('*', null);
%%write init;
%%write exec;
if( cs < %%{ write first_final; }%% ){
tsk_utils_log_error("Failed to parse 'Dummy' header: " + s_str);
return null;
}
return hdr_Dummy;
}
This diff is collapsed.
/*
* Copyright (C) 2012 Doubango Telecom <http://www.doubango.org>
* License: BSD
* This file is part of Open Source sipML5 solution <http://www.sipml5.org>
*/
tsdp_header_O.prototype = Object.create(tsdp_header.prototype);
%%{
machine tsdp_machine_parser_header_O;
# Includes
include tsdp_machine_utils "./tsdp_machine_utils.jrl";
action tag{
i_tag_start = p;
}
action parse_username{
hdr_O.s_username = tsk_ragel_parser_get_string(s_str, p, i_tag_start);
}
action parse_sess_id{
hdr_O.i_sess_id = tsk_ragel_parser_get_int(s_str, p, i_tag_start);
}
action parse_sess_version{
hdr_O.i_sess_version = tsk_ragel_parser_get_int(s_str, p, i_tag_start);
}
action parse_nettype{
hdr_O.s_nettype = tsk_ragel_parser_get_string(s_str, p, i_tag_start);
}
action parse_addrtype{
hdr_O.s_addrtype = tsk_ragel_parser_get_string(s_str, p, i_tag_start);
}
action parse_addr{
hdr_O.s_addr= tsk_ragel_parser_get_string(s_str, p, i_tag_start);
}
username = js_any*>tag %parse_username;
sess_id = DIGIT+>tag %parse_sess_id;
sess_version = DIGIT+>tag %parse_sess_version;
nettype = js_any*>tag %parse_nettype;
addrtype = js_any*>tag %parse_addrtype;
addr = js_any*>tag %parse_addr;
O = 'o' SP* "=" SP*<: username :>SP sess_id :>SP sess_version :>SP nettype :>SP addrtype :>SP addr;
# Entry point
main := O :>CRLF?;
}%%
%%write data;
function tsdp_header_O(s_username, i_sess_id, i_sess_version, s_nettype, s_addrtype, s_addr){
tsdp_header.call(this, tsdp_header_type_e.O);
this.s_username = s_username;
this.i_sess_id = i_sess_id;
this.i_sess_version = i_sess_version;
this.s_nettype = s_nettype;
this.s_addrtype = s_addrtype;
this.s_addr = s_addr;
}
tsdp_header_O.prototype.toString = function(){
// o=alice 2890844526 2890844526 IN IP4 host.atlanta.example.com
return tsk_string_format("{0} {1} {2} {3} {4} {5}",
this.s_username,
this.i_sess_id,
this.i_sess_version,
this.s_nettype,
this.s_addrtype,
this.s_addr);
}
tsdp_header_O.prototype.Parse = function(s_str){
var cs = 0;
var p = 0;
var pe = s_str.length;
var eof = pe;
var data = tsk_buff_str2ib(s_str);
var i_tag_start;
var hdr_O = new tsdp_header_O(null, 0, 0, null, null, null);
%%write init;
%%write exec;
if( cs < %%{ write first_final; }%% ){
tsk_utils_log_error("Failed to parse \"o=\" header: " + s_str);
return null;
}
return hdr_O;
}
/*
* Copyright (C) 2012 Doubango Telecom <http://www.doubango.org>
* License: BSD
* This file is part of Open Source sipML5 solution <http://www.sipml5.org>
*/
tsdp_header_R.prototype = Object.create(tsdp_header.prototype);
%%{
machine tsdp_machine_parser_header_R;
# Includes
include tsdp_machine_utils "./tsdp_machine_utils.jrl";
action tag{
i_tag_start = p;
}
action parse_repeat_interval{
hdr_R.s_repeat_interval = tsk_ragel_parser_get_string(s_str, p, i_tag_start);
}
action parse_typed_time{
tsk_ragel_parser_add_string(s_str, p, i_tag_start, hdr_R.as_typed_times);
}
fixed_len_time_unit = "d" | "h" | "m" | "s";
repeat_interval = (DIGIT+ fixed_len_time_unit?) >tag %parse_repeat_interval;
typed_time = (DIGIT+ fixed_len_time_unit?) >tag %parse_typed_time;
R = 'r' SP* "=" SP*<: repeat_interval :>SP typed_time (SP<: typed_time)+;
# Entry point
main := R :>CRLF?;
}%%
%%write data;
function tsdp_header_R(s_repeat_interval, s_typed_time){
tsdp_header.call(this, tsdp_header_type_e.R);
this.s_repeat_interval = s_repeat_interval;
this.as_typed_times = new Array();
if(s_typed_time){
this.as_typed_times.push(s_typed_time);
}
}
tsdp_header_R.prototype.toString = function(){
// r=7d 1h 0 25h
var s_str = this.s_repeat_interval;
for(var i = 0; i < this.as_typed_times.length; ++i){
s_str += " " + this.as_typed_times[i];
}
return s_str;
}
tsdp_header_R.prototype.Parse = function(s_str){
var cs = 0;
var p = 0;
var pe = s_str.length;
var eof = pe;
var data = tsk_buff_str2ib(s_str);
var i_tag_start;
var hdr_R = new tsdp_header_R(null, null);
%%write init;
%%write exec;
if( cs < %%{ write first_final; }%% ){
tsk_utils_log_error("Failed to parse \"r=\" header: " + s_str);
return null;
}
return hdr_R;
}
\ No newline at end of file
/*
* Copyright (C) 2012 Doubango Telecom <http://www.doubango.org>
* License: BSD
* This file is part of Open Source sipML5 solution <http://www.sipml5.org>
*/
// Parse headers: B, E, I, K, P, R, S, T, U, Z, Dummy
tsdp_header_Str.prototype = Object.create(tsdp_header.prototype);
tsdp_header_B.prototype = Object.create(tsdp_header_Str.prototype);
tsdp_header_E.prototype = Object.create(tsdp_header_Str.prototype);
tsdp_header_I.prototype = Object.create(tsdp_header_Str.prototype);
tsdp_header_K.prototype = Object.create(tsdp_header_Str.prototype);
tsdp_header_P.prototype = Object.create(tsdp_header_Str.prototype);
tsdp_header_R.prototype = Object.create(tsdp_header_Str.prototype);
tsdp_header_S.prototype = Object.create(tsdp_header_Str.prototype);
tsdp_header_T.prototype = Object.create(tsdp_header_Str.prototype);
tsdp_header_U.prototype = Object.create(tsdp_header_Str.prototype);
tsdp_header_Z.prototype = Object.create(tsdp_header_Str.prototype);
tsdp_header_Dummy.prototype = Object.create(tsdp_header_Str.prototype);
tsdp_header_Str.prototype.s_value = null;
%%{
machine tsdp_machine_parser_header_Str;
# Includes
include tsdp_machine_utils "./tsdp_machine_utils.jrl";
action tag{
i_tag_start = p;
}
action is_B{ o_hdr = new tsdp_header_B(); }
action is_E{ o_hdr = new tsdp_header_E(); }
action is_I{ o_hdr = new tsdp_header_I(); }
action is_K{ o_hdr = new tsdp_header_K(); }
action is_P{ o_hdr = new tsdp_header_P(); }
action is_R{ o_hdr = new tsdp_header_R(); }
action is_S{ o_hdr = new tsdp_header_S(); }
action is_T{ o_hdr = new tsdp_header_T(); }
action is_U{ o_hdr = new tsdp_header_U(); }
action is_Z{ o_hdr = new tsdp_header_Z(); }
action is_Dummy{ o_hdr = new tsdp_header_Dummy(); o_hdr.c_name = tsk_ragel_parser_get_string(s_str, p, i_tag_start)[0]; }
action parse_value{
if(o_hdr){
o_hdr.s_value = tsk_ragel_parser_get_string(s_str, p, i_tag_start);
}
}
Str = ( ('b'%is_B | 'e'%is_E | 'i'%is_I | 'k'%is_K | 'p'%is_P | 'r'%is_R | 's'%is_S | 't'%is_T | 'u'%is_U | 'z'%is_Z)@1 | (alpha>tag%is_Dummy)@0 ) :>SP* "=" SP*<: js_any*>tag %parse_value;
# Entry point
main := Str :>CRLF?;
}%%
%%write data;
function tsdp_header_Str(e_type, s_value){
tsdp_header.call(this, e_type);
this.s_value = s_value;
}
tsdp_header_Str.prototype.toString = function(){
return this.s_value;
}
tsdp_header_Str.prototype.Parse = function(s_str){
var cs = 0;
var p = 0;
var pe = s_str.length;
var eof = pe;
var data = tsk_buff_str2ib(s_str);
var i_tag_start;
var o_hdr = null;
%%write init;
%%write exec;
if( cs < %%{ write first_final; }%% ){
tsk_utils_log_error("Failed to parse header: " + s_str);
return null;
}
return o_hdr;
}
function tsdp_header_B(s_value){ tsdp_header_Str.call(this, tsdp_header_type_e.B, s_value); }
function tsdp_header_E(s_value){ tsdp_header_Str.call(this, tsdp_header_type_e.E, s_value); }
function tsdp_header_I(s_value){ tsdp_header_Str.call(this, tsdp_header_type_e.I, s_value); }
function tsdp_header_K(s_value){ tsdp_header_Str.call(this, tsdp_header_type_e.K, s_value); }
function tsdp_header_P(s_value){ tsdp_header_Str.call(this, tsdp_header_type_e.P, s_value); }
function tsdp_header_R(s_value){ tsdp_header_Str.call(this, tsdp_header_type_e.R, s_value); }
function tsdp_header_S(s_value){ tsdp_header_Str.call(this, tsdp_header_type_e.S, s_value); }
function tsdp_header_T(s_value){ tsdp_header_Str.call(this, tsdp_header_type_e.T, s_value); }
function tsdp_header_U(s_value){ tsdp_header_Str.call(this, tsdp_header_type_e.U, s_value); }
function tsdp_header_Z(s_value){ tsdp_header_Str.call(this, tsdp_header_type_e.Z, s_value); }
function tsdp_header_Dummy(s_name, s_value){ tsdp_header_Str.call(this, tsdp_header_type_e.DUMMY, s_value); this.s_name = s_name; }
This diff is collapsed.
/*
* Copyright (C) 2012 Doubango Telecom <http://www.doubango.org>
* License: BSD
* This file is part of Open Source sipML5 solution <http://www.sipml5.org>
*/
tsdp_header_V.prototype = Object.create(tsdp_header.prototype);
%%{
machine tsdp_machine_parser_header_V;
# Includes
include tsdp_machine_utils "./tsdp_machine_utils.jrl";
action tag{
i_tag_start = p;
}
action parse_version{
hdr_V.i_version = tsk_ragel_parser_get_int(s_str, p, i_tag_start);
}
V = 'v' SP* "=" SP*<: DIGIT+>tag %parse_version;
# Entry point
main := V :>CRLF?;
}%%
%%write data;
function tsdp_header_V(i_version){
tsdp_header.call(this, tsdp_header_type_e.V);
this.i_version = i_version;
this.toString = function(){
return this.i_version.toString();
}
}
tsdp_header_V.prototype.Parse = function(s_str){
var cs = 0;
var p = 0;
var pe = s_str.length;
var eof = pe;
var data = tsk_buff_str2ib(s_str);
var i_tag_start;
var hdr_V = new tsdp_header_V(0);
%%write init;
%%write exec;
if( cs < %%{ write first_final; }%% ){
tsk_utils_log_error("Failed to parse \"v=\" header: " + s_str);
return null;
}
return hdr_V;
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/*
* Copyright (C) 2012 Doubango Telecom <http://www.doubango.org>
* License: BSD
* This file is part of Open Source sipML5 solution <http://www.sipml5.org>
*/
%%{
machine tsip_machine_message;
#message_body = OCTET*;
message_body = js_any*;
SIP_Version = ("SIP"i "/" DIGIT+ "." DIGIT+) >tag %parse_sipversion;
action prev_not_comma{
prev_not_comma(o_ragel_state, p)
}
message_header = ((token) SP* HCOLON SP*<: ((js_any+ - CRLF) (COMMA CRLF SP)?)* CRLF) >tag %parse_header;
# SIP RESPONSE
Reason_Phrase = (( reserved | unreserved | escaped | UTF8_NONASCII | UTF8_CONT | SP | HTAB )*)>tag %parse_reason_phrase;
Status_Line = SIP_Version :>SP Status_Code>tag %parse_status_code :>SP Reason_Phrase :>CRLF;
Response = Status_Line (message_header* CRLF);
# SIP REQUEST
URI = (scheme HCOLON js_any+)>tag %parse_requesturi;
Request_URI = URI;
Request_Line = Method>tag %parse_method :>SP Request_URI :>SP SIP_Version :>CRLF;
Request = Request_Line (message_header* CRLF);
# SIP MESSAGE
SIP_message = (Response | Request)>1 @eoh message_body?>0;
}%%
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment