Ejemplo n.º 1
0
/* #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);
        }
Ejemplo n.º 2
0
/* #line 124 "./ragel/tsip_parser_uri.rl" */

    public static TSIP_Uri Parse(String data)
    {
        if (String.IsNullOrEmpty(data))
        {
            return(null);
        }

        int cs  = 0;
        int p   = 0;
        int pe  = data.Length;
        int eof = pe;

        int ts = 0, te = 0;
        int act = 0;

        TSIP_Uri uri = TSIP_Uri.Create(tsip_uri_type_t.Unknown);

        int tag_start = 0;


/* #line 395 "../Parsers/TSIP_ParserUri.cs" */
        {
            cs  = tsip_machine_parser_uri_start;
            ts  = -1;
            te  = -1;
            act = 0;
        }

/* #line 145 "./ragel/tsip_parser_uri.rl" */

/* #line 405 "../Parsers/TSIP_ParserUri.cs" */
        {
            sbyte _klen;
            short _trans;
            sbyte _acts;
            sbyte _nacts;
            short _keys;

            if (p == pe)
            {
                goto _test_eof;
            }
            if (cs == 0)
            {
                goto _out;
            }
_resume:
            _acts  = _tsip_machine_parser_uri_from_state_actions[cs];
            _nacts = _tsip_machine_parser_uri_actions[_acts++];
            while (_nacts-- > 0)
            {
                switch (_tsip_machine_parser_uri_actions[_acts++])
                {
                case 12:
/* #line 1 "./ragel/tsip_parser_uri.rl" */
                { ts = p; }
                break;

/* #line 426 "../Parsers/TSIP_ParserUri.cs" */
                default: break;
                }
            }

            _keys  = _tsip_machine_parser_uri_key_offsets[cs];
            _trans = (short)_tsip_machine_parser_uri_index_offsets[cs];

            _klen = _tsip_machine_parser_uri_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_uri_trans_keys[_mid])
                    {
                        _upper = (short)(_mid - 1);
                    }
                    else if (data[p] > _tsip_machine_parser_uri_trans_keys[_mid])
                    {
                        _lower = (short)(_mid + 1);
                    }
                    else
                    {
                        _trans += (short)(_mid - _keys);
                        goto _match;
                    }
                }
                _keys  += (short)_klen;
                _trans += (short)_klen;
            }

            _klen = _tsip_machine_parser_uri_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_uri_trans_keys[_mid])
                    {
                        _upper = (short)(_mid - 2);
                    }
                    else if (data[p] > _tsip_machine_parser_uri_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_uri_indicies[_trans];
_eof_trans:
            cs = _tsip_machine_parser_uri_trans_targs[_trans];

            if (_tsip_machine_parser_uri_trans_actions[_trans] == 0)
            {
                goto _again;
            }

            _acts  = _tsip_machine_parser_uri_trans_actions[_trans];
            _nacts = _tsip_machine_parser_uri_actions[_acts++];
            while (_nacts-- > 0)
            {
                switch (_tsip_machine_parser_uri_actions[_acts++])
                {
                case 0:
/* #line 36 "./ragel/tsip_parser_uri.rl" */
                {
                    tag_start = p;
                }
                break;

                case 1:
/* #line 41 "./ragel/tsip_parser_uri.rl" */
                { uri.Scheme = "sip"; uri.Type = tsip_uri_type_t.Sip; }
                break;

                case 2:
/* #line 42 "./ragel/tsip_parser_uri.rl" */
                { uri.Scheme = "sips"; uri.Type = tsip_uri_type_t.Sips; }
                break;

                case 3:
/* #line 43 "./ragel/tsip_parser_uri.rl" */
                { uri.Scheme = "tel"; uri.Type = tsip_uri_type_t.Tel; }
                break;

                case 4:
/* #line 46 "./ragel/tsip_parser_uri.rl" */
                { uri.HostType = tsip_host_type_t.IPv4; }
                break;

                case 5:
/* #line 47 "./ragel/tsip_parser_uri.rl" */
                { uri.HostType = tsip_host_type_t.IPv6; }
                break;

                case 6:
/* #line 48 "./ragel/tsip_parser_uri.rl" */
                { uri.HostType = tsip_host_type_t.Hostname; }
                break;

                case 7:
/* #line 54 "./ragel/tsip_parser_uri.rl" */
                {
                    uri.UserName = TSK_RagelState.Parser.GetString(data, p, tag_start);
                }
                break;

                case 8:
/* #line 58 "./ragel/tsip_parser_uri.rl" */
                {
                    uri.Password = TSK_RagelState.Parser.GetString(data, p, tag_start);
                }
                break;

                case 9:
/* #line 70 "./ragel/tsip_parser_uri.rl" */
                {
                    TSK_Param param = TSK_RagelState.Parser.GetParam(data, p, tag_start);
                    if (param != null)
                    {
                        uri.Params.Add(param);
                    }
                }
                break;

                case 10:
/* #line 84 "./ragel/tsip_parser_uri.rl" */
                { { cs = 26; if (true)
                    {
                        goto _again;
                    }
                  } }
                  break;

                case 13:
/* #line 1 "./ragel/tsip_parser_uri.rl" */
                { te = p + 1; }
                break;

                case 14:
/* #line 97 "./ragel/tsip_parser_uri.rl" */
                { te = p + 1; {
                      uri.Host = TSK_RagelState.Scanner.GetString(data, ts, te);
                      if (uri.HostType == tsip_host_type_t.IPv6)
                      {
                          uri.Host = TSK_String.UnQuote(uri.Host, '[', ']');
                      }
                  } }
                  break;

                case 15:
/* #line 88 "./ragel/tsip_parser_uri.rl" */
                { te = p; p--; {
                      if (TSK_String.Contains(data.Substring(te), (pe - te), "@"))
                      {
                          { cs = 18; if (true)
                    {
                        goto _again;
                    }
                          }
                      }
                  } }
                  break;

                case 16:
/* #line 94 "./ragel/tsip_parser_uri.rl" */
                { te = p; p--; { } }
                break;

                case 17:
/* #line 97 "./ragel/tsip_parser_uri.rl" */
                { te = p; p--; {
                      uri.Host = TSK_RagelState.Scanner.GetString(data, ts, te);
                      if (uri.HostType == tsip_host_type_t.IPv6)
                      {
                          uri.Host = TSK_String.UnQuote(uri.Host, '[', ']');
                      }
                  } }
                  break;

                case 18:
/* #line 105 "./ragel/tsip_parser_uri.rl" */
                { te = p; p--; {
                      ts++;
                      uri.Port = (ushort)TSK_RagelState.Scanner.GetInt32(data, ts, te);
                  } }
                  break;

                case 19:
/* #line 110 "./ragel/tsip_parser_uri.rl" */
                { te = p; p--; {  } }
                break;

                case 20:
/* #line 111 "./ragel/tsip_parser_uri.rl" */
                { te = p; p--; {  } }
                break;

                case 21:
/* #line 94 "./ragel/tsip_parser_uri.rl" */
                { { p = ((te)) - 1; } { } }
                break;

                case 22:
/* #line 97 "./ragel/tsip_parser_uri.rl" */
                { { p = ((te)) - 1; } {
                      uri.Host = TSK_RagelState.Scanner.GetString(data, ts, te);
                      if (uri.HostType == tsip_host_type_t.IPv6)
                      {
                          uri.Host = TSK_String.UnQuote(uri.Host, '[', ']');
                      }
                  } }
                  break;

                case 23:
/* #line 110 "./ragel/tsip_parser_uri.rl" */
                { { p = ((te)) - 1; } {  } }
                break;

/* #line 615 "../Parsers/TSIP_ParserUri.cs" */
                default: break;
                }
            }

_again:
            _acts  = _tsip_machine_parser_uri_to_state_actions[cs];
            _nacts = _tsip_machine_parser_uri_actions[_acts++];
            while (_nacts-- > 0)
            {
                switch (_tsip_machine_parser_uri_actions[_acts++])
                {
                case 11:
/* #line 1 "./ragel/tsip_parser_uri.rl" */
                { ts = -1; }
                break;

/* #line 629 "../Parsers/TSIP_ParserUri.cs" */
                default: break;
                }
            }

            if (cs == 0)
            {
                goto _out;
            }
            if (++p != pe)
            {
                goto _resume;
            }
            _test_eof : {}
            if (p == eof)
            {
                if (_tsip_machine_parser_uri_eof_trans[cs] > 0)
                {
                    _trans = (short)(_tsip_machine_parser_uri_eof_trans[cs] - 1);
                    goto _eof_trans;
                }
            }

            _out : {}
        }

/* #line 146 "./ragel/tsip_parser_uri.rl" */

        if (cs <
/* #line 653 "../Parsers/TSIP_ParserUri.cs" */
            26
/* #line 147 "./ragel/tsip_parser_uri.rl" */
            )
        {
            TSK_Debug.Error("Failed to parse SIP/SIPS/TEL URI");
            uri.Dispose();
            return(null);
        }

        return(uri);
    }
Ejemplo n.º 3
0
/* #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);
        }