<commit_before>/* -*- c -*- */

#include <stdbool.h>

#include "network/rtsp.h"
#include "network/rtp.h"
#include "network/ragel_parsers.h"

%% machine ragel_transport_header;

gboolean ragel_parse_transport_header(RTSP_Client *rtsp,
                                      RTP_transport *rtp_t,
                                      const char *header) {
    struct ParsedTransport transport;
    int cs;
    const char *p = header, *pe = p + strlen(p) +1;
    uint32_t portval; uint16_t chanval;

    %%{
        action start_port {
            portval = 0;
        }

        action count_port {
            portval = (portval*10) + (fc - '0');
        }

        action check_port {
            if ( portval > G_MAXUINT16 )
                portval = G_MAXUINT16;
        }

        action start_channel {
            chanval = 0;
        }

        action count_channel {
            chanval = (chanval*10) + (fc - '0');
        }

        action check_channel {
            if ( chanval > G_MAXUINT8 )
                chanval = G_MAXUINT8;
        }

        Port = digit{,5} >start_port @count_port %check_port;
        Channel = digit{,3} >start_channel @count_channel %check_channel;

        Unicast = ";unicast" %{transport.mode = TransportUnicast;};
        Multicast = ";multicast" %{transport.mode = TransportMulticast;};

        TransportParamName = ( alnum | '_' )+;
        TransportParamValue = (print - ('=' | ';' ))+;

        TransportParam = ";" . TransportParamName . ( '=' . TransportParamValue )?;

        ClientPort = ";client_port=" .
            Port%{transport.parameters.UDP.Unicast.port_rtp = portval;} .
            ( "-" . Port%{transport.parameters.UDP.Unicast.port_rtcp = portval;} );

        UnicastUDPParams = Unicast . ( ClientPort | TransportParam )+;
        MulticastUDPParams = Multicast . TransportParam+;

        UDPParams = ( UnicastUDPParams | MulticastUDPParams );

        Interleaved = ";interleaved=" .
            Channel%{transport.parameters.TCP.ich_rtp = chanval;} .
            ( "-" . Channel%{transport.parameters.TCP.ich_rtcp = chanval;} );

        TCPParams = ( Interleaved | TransportParam)+;

        Streams = ";streams" .
            Channel%{transport.parameters.SCTP.ch_rtp = chanval;} .
            ( "-" . Channel%{transport.parameters.SCTP.ch_rtcp = chanval;} );

        SCTPParams = TransportParam+;
<commit_msg>Unbreak sctp stream parsing, now sctp works with mplayer-nemesi<commit_after>/* -*- c -*- */

#include <stdbool.h>

#include "network/rtsp.h"
#include "network/rtp.h"
#include "network/ragel_parsers.h"

%% machine ragel_transport_header;

gboolean ragel_parse_transport_header(RTSP_Client *rtsp,
                                      RTP_transport *rtp_t,
                                      const char *header) {
    struct ParsedTransport transport;
    int cs;
    const char *p = header, *pe = p + strlen(p) +1;
    uint32_t portval; uint16_t chanval;

    %%{
        action start_port {
            portval = 0;
        }

        action count_port {
            portval = (portval*10) + (fc - '0');
        }

        action check_port {
            if ( portval > G_MAXUINT16 )
                portval = G_MAXUINT16;
        }

        action start_channel {
            chanval = 0;
        }

        action count_channel {
            chanval = (chanval*10) + (fc - '0');
        }

        action check_channel {
            if ( chanval > G_MAXUINT8 )
                chanval = G_MAXUINT8;
        }

        Port = digit{,5} >start_port @count_port %check_port;
        Channel = digit{,3} >start_channel @count_channel %check_channel;

        Unicast = ";unicast" %{transport.mode = TransportUnicast;};
        Multicast = ";multicast" %{transport.mode = TransportMulticast;};

        TransportParamName = ( alnum | '_' )+;
        TransportParamValue = (print - ('=' | ';' ))+;

        TransportParam = ";" . TransportParamName . ( '=' . TransportParamValue )?;

        ClientPort = ";client_port=" .
            Port%{transport.parameters.UDP.Unicast.port_rtp = portval;} .
            ( "-" . Port%{transport.parameters.UDP.Unicast.port_rtcp = portval;} );

        UnicastUDPParams = Unicast . ( ClientPort | TransportParam )+;
        MulticastUDPParams = Multicast . TransportParam+;

        UDPParams = ( UnicastUDPParams | MulticastUDPParams );

        Interleaved = ";interleaved=" .
            Channel%{transport.parameters.TCP.ich_rtp = chanval;} .
            ( "-" . Channel%{transport.parameters.TCP.ich_rtcp = chanval;} );

        TCPParams = ( Interleaved | TransportParam)+;

        Streams = ";streams=" .
            Channel%{transport.parameters.SCTP.ch_rtp = chanval;} .
            ( "-" . Channel%{transport.parameters.SCTP.ch_rtcp = chanval;} );

        SCTPParams = ( Streams | TransportParam)+;

{'fraction_non_alphanumeric': 0.125, 'fraction_numerical': 0.00869205298013245, 'mean_word_length': 2.0074673304293715, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6790914', 'n_tokens_mistral': 1572, 'n_tokens_neox': 1492, 'n_words': 267}