internal TSIP_Uri GetProxyCSCFUri(Boolean lr) { TSIP_Uri uri = null; if (mLayerTransport != null && mLayerTransport.Transports.Count > 0) { TSIP_Transport transport = mLayerTransport.Transports[0]; if (transport != null) { Boolean ipv6 = TNET_Socket.IsIPv6Type(transport.Type); Boolean quote_ip = (ipv6 && !String.IsNullOrEmpty(mProxyHost) && mProxyHost.Contains(":")) /* IPv6 IP string?*/; String uriString = String.Format("{0}:{1}{2}{3}:{4};{5};transport={6}", transport.Scheme, quote_ip ? "[" : "", mProxyHost, quote_ip ? "]" : "", mProxyPort, lr ? "lr" : "", transport.Protocol ); uri = TSIP_ParserUri.Parse(uriString); } } return(uri); }
internal TSIP_Uri GetUri(Boolean lr) { Boolean ipv6 = TNET_Socket.IsIPv6Type(this.Type); String uristring = String.Format("{0}:{1}{2}{3}:{4};{5};transport={6}", this.Scheme, ipv6 ? "[" : String.Empty, mStack.AoRIP, ipv6 ? "]" : String.Empty, mStack.AoRPort, lr ? "lr" : String.Empty, this.Protocol); TSIP_Uri uri = TSIP_ParserUri.Parse(uristring); uri.HostType = ipv6 ? tsip_host_type_t.IPv6 : tsip_host_type_t.IPv4; return(uri); }
internal static void TestUriParser() { int i; for (i = 0; i < __Uris.Length; i++) { TSIP_Uri uri = TSIP_ParserUri.Parse(__Uris[i]); TSK_Debug.Info("\n== Parsing {{ {0} }} ==\n", __Uris[i]); if (uri != null) { TSK_Debug.Info("scheme: {0}", uri.Scheme); TSK_Debug.Info("user-name: {0}", uri.UserName); TSK_Debug.Info("password: {0}", uri.Password); TSK_Debug.Info("host: {0}", uri.Host); TSK_Debug.Info("port: {0}", uri.Port); TSK_Debug.Info("host-type: {0}", uri.HostType == tsip_host_type_t.IPv4 ? "IPv4" : (uri.HostType == tsip_host_type_t.IPv6 ? "IPv6" : (uri.HostType == tsip_host_type_t.Hostname ? "HOSTNAME" : "UNKNOWN"))); TSK_Debug.Info("---PARAMS---"); /* dump all parameters */ foreach (TSK_Param param in uri.Params) { TSK_Debug.Info("-->{0}={1}", param.Name, param.Value); } TSK_Debug.Info("Is-secure: {0}", uri.IsSecure ? "YES" : "NO"); TestToString(uri); uri.Dispose(); } else { TSK_Debug.Error("INVALID SIP URI"); } TSK_Debug.Info("\n\n"); } }
/* #line 133 "./ragel/tsip_parser_header_From.rl" */ public static TSIP_HeaderFrom Parse(String data) { int cs = 0; int p = 0; int pe = data.Length; int eof = pe; TSIP_HeaderFrom hdr_from = new TSIP_HeaderFrom(); int tag_start = 0; /* #line 392 "../Headers/TSIP_HeaderFrom.cs" */ { cs = tsip_machine_parser_header_From_start; } /* #line 145 "./ragel/tsip_parser_header_From.rl" */ /* #line 399 "../Headers/TSIP_HeaderFrom.cs" */ { sbyte _klen; short _trans; sbyte _acts; sbyte _nacts; short _keys; if (p == pe) { goto _test_eof; } if (cs == 0) { goto _out; } _resume: _keys = _tsip_machine_parser_header_From_key_offsets[cs]; _trans = (short)_tsip_machine_parser_header_From_index_offsets[cs]; _klen = _tsip_machine_parser_header_From_single_lengths[cs]; if (_klen > 0) { short _lower = _keys; short _mid; short _upper = (short)(_keys + _klen - 1); while (true) { if (_upper < _lower) { break; } _mid = (short)(_lower + ((_upper - _lower) >> 1)); if (data[p] < _tsip_machine_parser_header_From_trans_keys[_mid]) { _upper = (short)(_mid - 1); } else if (data[p] > _tsip_machine_parser_header_From_trans_keys[_mid]) { _lower = (short)(_mid + 1); } else { _trans += (short)(_mid - _keys); goto _match; } } _keys += (short)_klen; _trans += (short)_klen; } _klen = _tsip_machine_parser_header_From_range_lengths[cs]; if (_klen > 0) { short _lower = _keys; short _mid; short _upper = (short)(_keys + (_klen << 1) - 2); while (true) { if (_upper < _lower) { break; } _mid = (short)(_lower + (((_upper - _lower) >> 1) & ~1)); if (data[p] < _tsip_machine_parser_header_From_trans_keys[_mid]) { _upper = (short)(_mid - 2); } else if (data[p] > _tsip_machine_parser_header_From_trans_keys[_mid + 1]) { _lower = (short)(_mid + 2); } else { _trans += (short)((_mid - _keys) >> 1); goto _match; } } _trans += (short)_klen; } _match: _trans = (short)_tsip_machine_parser_header_From_indicies[_trans]; cs = _tsip_machine_parser_header_From_trans_targs[_trans]; if (_tsip_machine_parser_header_From_trans_actions[_trans] == 0) { goto _again; } _acts = _tsip_machine_parser_header_From_trans_actions[_trans]; _nacts = _tsip_machine_parser_header_From_actions[_acts++]; while (_nacts-- > 0) { switch (_tsip_machine_parser_header_From_actions[_acts++]) { case 0: /* #line 32 "./ragel/tsip_parser_header_From.rl" */ { tag_start = p; } break; case 1: /* #line 36 "./ragel/tsip_parser_header_From.rl" */ { int len = (int)(p - tag_start); if (hdr_from != null && hdr_from.Uri == null) { if ((hdr_from.Uri = TSIP_ParserUri.Parse(data.Substring(tag_start, len))) != null && !String.IsNullOrEmpty(hdr_from.DisplayName)) { hdr_from.Uri.DisplayName = hdr_from.DisplayName; } } } break; case 2: /* #line 45 "./ragel/tsip_parser_header_From.rl" */ { hdr_from.DisplayName = TSK_RagelState.Parser.GetString(data, p, tag_start); hdr_from.DisplayName = TSK_String.UnQuote(hdr_from.DisplayName); } break; case 3: /* #line 50 "./ragel/tsip_parser_header_From.rl" */ { hdr_from.Tag = TSK_RagelState.Parser.GetString(data, p, tag_start); } break; case 4: /* #line 54 "./ragel/tsip_parser_header_From.rl" */ { hdr_from.Params = TSK_RagelState.Parser.AddParam(data, p, tag_start, hdr_from.Params); } break; case 5: /* #line 58 "./ragel/tsip_parser_header_From.rl" */ { } break; /* #line 514 "../Headers/TSIP_HeaderFrom.cs" */ default: break; } } _again: if (cs == 0) { goto _out; } if (++p != pe) { goto _resume; } _test_eof : {} _out : {} } /* #line 146 "./ragel/tsip_parser_header_From.rl" */ if (cs < /* #line 531 "../Headers/TSIP_HeaderFrom.cs" */ 108 /* #line 147 "./ragel/tsip_parser_header_From.rl" */ ) { TSK_Debug.Error("Failed to parse SIP 'From' header."); hdr_from.Dispose(); hdr_from = null; } return(hdr_from); }
/* #line 137 "./ragel/tsip_parser_header_Route.rl" */ public static List <TSIP_HeaderRoute> Parse(String data) { int cs = 0; int p = 0; int pe = data.Length; int eof = pe; List <TSIP_HeaderRoute> hdr_routes = new List <TSIP_HeaderRoute>(); TSIP_HeaderRoute curr_route = null; int tag_start = 0; /* #line 324 "../Headers/TSIP_HeaderRoute.cs" */ { cs = tsip_machine_parser_header_Route_start; } /* #line 151 "./ragel/tsip_parser_header_Route.rl" */ /* #line 331 "../Headers/TSIP_HeaderRoute.cs" */ { sbyte _klen; short _trans; sbyte _acts; sbyte _nacts; short _keys; if (p == pe) { goto _test_eof; } if (cs == 0) { goto _out; } _resume: _keys = _tsip_machine_parser_header_Route_key_offsets[cs]; _trans = (short)_tsip_machine_parser_header_Route_index_offsets[cs]; _klen = _tsip_machine_parser_header_Route_single_lengths[cs]; if (_klen > 0) { short _lower = _keys; short _mid; short _upper = (short)(_keys + _klen - 1); while (true) { if (_upper < _lower) { break; } _mid = (short)(_lower + ((_upper - _lower) >> 1)); if (data[p] < _tsip_machine_parser_header_Route_trans_keys[_mid]) { _upper = (short)(_mid - 1); } else if (data[p] > _tsip_machine_parser_header_Route_trans_keys[_mid]) { _lower = (short)(_mid + 1); } else { _trans += (short)(_mid - _keys); goto _match; } } _keys += (short)_klen; _trans += (short)_klen; } _klen = _tsip_machine_parser_header_Route_range_lengths[cs]; if (_klen > 0) { short _lower = _keys; short _mid; short _upper = (short)(_keys + (_klen << 1) - 2); while (true) { if (_upper < _lower) { break; } _mid = (short)(_lower + (((_upper - _lower) >> 1) & ~1)); if (data[p] < _tsip_machine_parser_header_Route_trans_keys[_mid]) { _upper = (short)(_mid - 2); } else if (data[p] > _tsip_machine_parser_header_Route_trans_keys[_mid + 1]) { _lower = (short)(_mid + 2); } else { _trans += (short)((_mid - _keys) >> 1); goto _match; } } _trans += (short)_klen; } _match: _trans = (short)_tsip_machine_parser_header_Route_indicies[_trans]; cs = _tsip_machine_parser_header_Route_trans_targs[_trans]; if (_tsip_machine_parser_header_Route_trans_actions[_trans] == 0) { goto _again; } _acts = _tsip_machine_parser_header_Route_trans_actions[_trans]; _nacts = _tsip_machine_parser_header_Route_actions[_acts++]; while (_nacts-- > 0) { switch (_tsip_machine_parser_header_Route_actions[_acts++]) { case 0: /* #line 31 "./ragel/tsip_parser_header_Route.rl" */ { tag_start = p; } break; case 1: /* #line 35 "./ragel/tsip_parser_header_Route.rl" */ { if (curr_route == null) { curr_route = new TSIP_HeaderRoute(); } } break; case 2: /* #line 41 "./ragel/tsip_parser_header_Route.rl" */ { if (curr_route != null) { curr_route.DisplayName = TSK_RagelState.Parser.GetString(data, p, tag_start); curr_route.DisplayName = TSK_String.UnQuote(curr_route.DisplayName); } } break; case 3: /* #line 48 "./ragel/tsip_parser_header_Route.rl" */ { if (curr_route != null && curr_route.Uri == null) { int len = (int)(p - tag_start); if ((curr_route.Uri = TSIP_ParserUri.Parse(data.Substring(tag_start, len))) != null && !String.IsNullOrEmpty(curr_route.DisplayName)) { curr_route.Uri.DisplayName = curr_route.DisplayName; } } } break; case 4: /* #line 58 "./ragel/tsip_parser_header_Route.rl" */ { if (curr_route != null) { curr_route.Params = TSK_RagelState.Parser.AddParam(data, p, tag_start, curr_route.Params); } } break; case 5: /* #line 64 "./ragel/tsip_parser_header_Route.rl" */ { if (curr_route != null) { hdr_routes.Add(curr_route); curr_route = null; } } break; case 6: /* #line 71 "./ragel/tsip_parser_header_Route.rl" */ { } break; /* #line 462 "../Headers/TSIP_HeaderRoute.cs" */ default: break; } } _again: if (cs == 0) { goto _out; } if (++p != pe) { goto _resume; } _test_eof : {} _out : {} } /* #line 152 "./ragel/tsip_parser_header_Route.rl" */ if (cs < /* #line 479 "../Headers/TSIP_HeaderRoute.cs" */ 92 /* #line 153 "./ragel/tsip_parser_header_Route.rl" */ ) { TSK_Debug.Error("Failed to parse SIP 'Route' header."); hdr_routes.Clear(); hdr_routes = null; curr_route.Dispose(); curr_route = null; } return(hdr_routes); }
public static TSIP_Uri Clone(TSIP_Uri uri, Boolean with_params, Boolean with_quote) { String uriString = TSIP_Uri.Serialize(uri, with_params, with_params); return(TSIP_ParserUri.Parse(uriString)); }
public static TSIP_Uri Create(String uri) { return(TSIP_ParserUri.Parse(uri)); }
private static TSIP_Message Execute(ref TSK_RagelState state, Boolean extractContent) { int cs = state.CS; int p = state.P; int pe = state.PE; int eof = state.EOF; byte[] data = state.Data; TSIP_Message message = null; /* #line 233 "../Parsers/TSIP_ParserMessage.cs" */ { sbyte _klen; byte _trans; int _widec; sbyte _acts; sbyte _nacts; byte _keys; if (p == pe) { goto _test_eof; } if (cs == 0) { goto _out; } _resume: _widec = data[p]; _klen = _tsip_machine_parser_message_cond_lengths[cs]; _keys = (byte)(_tsip_machine_parser_message_cond_offsets[cs] * 2); if (_klen > 0) { short _lower = _keys; short _mid; short _upper = (short)(_keys + (_klen << 1) - 2); while (true) { if (_upper < _lower) { break; } _mid = (short)(_lower + (((_upper - _lower) >> 1) & ~1)); if (_widec < _tsip_machine_parser_message_cond_keys[_mid]) { _upper = (short)(_mid - 2); } else if (_widec > _tsip_machine_parser_message_cond_keys[_mid + 1]) { _lower = (short)(_mid + 2); } else { switch (_tsip_machine_parser_message_cond_spaces[_tsip_machine_parser_message_cond_offsets[cs] + ((_mid - _keys) >> 1)]) { case 0: { _widec = (int)(65536u + (data[p] - 0u)); if ( /* #line 29 "./ragel/tsip_parser_message.rl" */ PrevNotComma(state, p) ) { _widec += 65536; } break; } default: break; } break; } } } _keys = _tsip_machine_parser_message_key_offsets[cs]; _trans = (byte)_tsip_machine_parser_message_index_offsets[cs]; _klen = _tsip_machine_parser_message_single_lengths[cs]; if (_klen > 0) { short _lower = _keys; short _mid; short _upper = (short)(_keys + _klen - 1); while (true) { if (_upper < _lower) { break; } _mid = (short)(_lower + ((_upper - _lower) >> 1)); if (_widec < _tsip_machine_parser_message_trans_keys[_mid]) { _upper = (short)(_mid - 1); } else if (_widec > _tsip_machine_parser_message_trans_keys[_mid]) { _lower = (short)(_mid + 1); } else { _trans += (byte)(_mid - _keys); goto _match; } } _keys += (byte)_klen; _trans += (byte)_klen; } _klen = _tsip_machine_parser_message_range_lengths[cs]; if (_klen > 0) { short _lower = _keys; short _mid; short _upper = (short)(_keys + (_klen << 1) - 2); while (true) { if (_upper < _lower) { break; } _mid = (short)(_lower + (((_upper - _lower) >> 1) & ~1)); if (_widec < _tsip_machine_parser_message_trans_keys[_mid]) { _upper = (short)(_mid - 2); } else if (_widec > _tsip_machine_parser_message_trans_keys[_mid + 1]) { _lower = (short)(_mid + 2); } else { _trans += (byte)((_mid - _keys) >> 1); goto _match; } } _trans += (byte)_klen; } _match: _trans = (byte)_tsip_machine_parser_message_indicies[_trans]; cs = _tsip_machine_parser_message_trans_targs[_trans]; if (_tsip_machine_parser_message_trans_actions[_trans] == 0) { goto _again; } _acts = _tsip_machine_parser_message_trans_actions[_trans]; _nacts = _tsip_machine_parser_message_actions[_acts++]; while (_nacts-- > 0) { switch (_tsip_machine_parser_message_actions[_acts++]) { case 0: /* #line 30 "./ragel/tsip_parser_message.rl" */ { state.TagStart = p; } break; case 1: /* #line 36 "./ragel/tsip_parser_message.rl" */ { int len; state.TagEnd = p; len = (int)(state.TagEnd - state.TagStart); String method = Encoding.UTF8.GetString(data, state.TagStart, len); if (message == null) { message = new TSIP_Request(method, null, null, null, null, 0); } else { state.CS = tsip_machine_parser_message_error; } } break; case 2: /* #line 53 "./ragel/tsip_parser_message.rl" */ { int len; state.TagEnd = p; len = (int)(state.TagEnd - state.TagStart); if ((message as TSIP_Request).Uri == null) { (message as TSIP_Request).Uri = TSIP_ParserUri.Parse(Encoding.UTF8.GetString(state.Data, state.TagStart, len)); } } break; case 3: /* #line 65 "./ragel/tsip_parser_message.rl" */ { int len; state.TagEnd = p; len = (int)(state.TagEnd - state.TagStart); if (message == null) { message = new TSIP_Response(0, null, null); } message.Version = Encoding.UTF8.GetString(state.Data, state.TagStart, len); } break; case 4: /* #line 79 "./ragel/tsip_parser_message.rl" */ { int len; state.TagEnd = p; len = (int)(state.TagEnd - state.TagStart); if (message == null) { message = new TSIP_Response(0, null, null); } UInt16 statusCode = 0; if (UInt16.TryParse(Encoding.UTF8.GetString(state.Data, state.TagStart, len), out statusCode)) { (message as TSIP_Response).StatusCode = statusCode; } } break; case 5: /* #line 98 "./ragel/tsip_parser_message.rl" */ { int len; state.TagEnd = p; len = (int)(state.TagEnd - state.TagStart); (message as TSIP_Response).ReasonPhrase = Encoding.UTF8.GetString(state.Data, state.TagStart, len); } break; case 6: /* #line 107 "./ragel/tsip_parser_message.rl" */ { int len; state.TagEnd = p; len = (int)(state.TagEnd - state.TagStart); if (!TSIP_ParserHeader.Parse(state, ref message)) { TSK_Debug.Error("Failed to parse header at {0}", state.TagStart); } } break; case 7: /* #line 119 "./ragel/tsip_parser_message.rl" */ { state.CS = cs; state.P = p; state.PE = pe; state.EOF = eof; TSIP_ParserMessage.EoH(ref state, ref message, extractContent); cs = state.CS; p = state.P; pe = state.PE; eof = state.EOF; } break; /* #line 447 "../Parsers/TSIP_ParserMessage.cs" */ default: break; } } _again: if (cs == 0) { goto _out; } if (++p != pe) { goto _resume; } _test_eof : {} _out : {} } /* #line 192 "./ragel/tsip_parser_message.rl" */ state.CS = cs; state.P = p; state.PE = pe; state.EOF = eof; return(message); }