diff options
author | rtognimp <rtognimp@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2003-04-17 20:39:41 +0000 |
---|---|---|
committer | rtognimp <rtognimp@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2003-04-17 20:39:41 +0000 |
commit | 2e8e95d779d064dd9830a558419105170cd373a4 (patch) | |
tree | 3156d962dcc96cf95a3c493b26a172e9c9807cd6 | |
parent | f09836cc0e3b39d7944e0d29526d07a81182a348 (diff) | |
download | mpv-2e8e95d779d064dd9830a558419105170cd373a4.tar.bz2 mpv-2e8e95d779d064dd9830a558419105170cd373a4.tar.xz |
Real rstp:// streaming support, ported from xine
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@9923 b3059339-0415-0410-9bf9-f77b7e298cf2
-rw-r--r-- | libmpdemux/Makefile | 1 | ||||
-rw-r--r-- | libmpdemux/network.c | 63 | ||||
-rw-r--r-- | libmpdemux/realrtsp/asmrp.c | 670 | ||||
-rw-r--r-- | libmpdemux/realrtsp/asmrp.h | 45 | ||||
-rw-r--r-- | libmpdemux/realrtsp/real.c | 744 | ||||
-rw-r--r-- | libmpdemux/realrtsp/real.h | 52 | ||||
-rw-r--r-- | libmpdemux/realrtsp/rmff.c | 907 | ||||
-rw-r--r-- | libmpdemux/realrtsp/rmff.h | 270 | ||||
-rw-r--r-- | libmpdemux/realrtsp/rtsp.c | 774 | ||||
-rw-r--r-- | libmpdemux/realrtsp/rtsp.h | 79 | ||||
-rw-r--r-- | libmpdemux/realrtsp/rtsp_session.c | 190 | ||||
-rw-r--r-- | libmpdemux/realrtsp/rtsp_session.h | 41 | ||||
-rw-r--r-- | libmpdemux/realrtsp/sdpplin.c | 315 | ||||
-rw-r--r-- | libmpdemux/realrtsp/sdpplin.h | 115 | ||||
-rw-r--r-- | libmpdemux/realrtsp/xbuffer.c | 86 | ||||
-rw-r--r-- | libmpdemux/realrtsp/xbuffer.h | 25 |
16 files changed, 4377 insertions, 0 deletions
diff --git a/libmpdemux/Makefile b/libmpdemux/Makefile index fa71e52bbe..f96a0d6f41 100644 --- a/libmpdemux/Makefile +++ b/libmpdemux/Makefile @@ -4,6 +4,7 @@ LIBNAME = libmpdemux.a include ../config.mak SRCS = mp3_hdr.c video.c mpeg_hdr.c cache2.c asfheader.c aviheader.c aviprint.c muxer.c muxer_avi.c muxer_mpeg.c demux_asf.c demux_avi.c demux_mov.c parse_mp4.c demux_mpg.c demux_pva.c demux_viv.c demuxer.c dvdauth.c dvdnav_stream.c open.c parse_es.c stream.c stream_file.c stream_netstream.c stream_vcd.c stream_null.c tv.c tvi_dummy.c tvi_v4l.c tvi_bsdbt848.c frequencies.c demux_fli.c demux_real.c demux_y4m.c yuv4mpeg.c yuv4mpeg_ratio.c demux_nuv.c demux_film.c demux_roq.c mf.c demux_mf.c demux_audio.c demux_demuxers.c demux_ogg.c demux_bmp.c cdda.c demux_rawaudio.c demux_rawvideo.c cddb.c cdinfo.c demux_rawdv.c ai_alsa.c ai_oss.c audio_in.c demux_smjpeg.c cue_read.c extension.c demux_gif.c demux_ts.c +SRCS += realrtsp/asmrp.c realrtsp/real.c realrtsp/rmff.c realrtsp/rtsp.c realrtsp/rtsp_session.c realrtsp/sdpplin.c realrtsp/xbuffer.c ifeq ($(XMMS_PLUGINS),yes) SRCS += demux_xmms.c endif diff --git a/libmpdemux/network.c b/libmpdemux/network.c index 96c5eccece..3b180c60ff 100644 --- a/libmpdemux/network.c +++ b/libmpdemux/network.c @@ -28,6 +28,7 @@ #include "rtp.h" #endif #include "pnm.h" +#include "realrtsp/rtsp_session.h" #include "../version.h" @@ -582,6 +583,20 @@ extension=NULL; // Checking for RTSP if( !strcasecmp(url->protocol, "rtsp") ) { + // Checking for Real rtsp:// + // Extension based detection, should be replaced with something based on server answer + extension = NULL; + if( url->file!=NULL ) + for( i=strlen(url->file) ; i>0 ; i-- ) + if( url->file[i]=='.' ) { + extension=(url->file)+i+1; + break; + } + if (!strcasecmp(extension, "rm")) { + *file_format = DEMUXER_TYPE_REAL; + return 0; + } + mp_msg(MSGT_NETWORK,MSGL_INFO,"Not a Realmedia rtsp url. Trying standard rtsp protocol.\n"); #ifdef STREAMING_LIVE_DOT_COM *file_format = DEMUXER_TYPE_RTP; return 0; @@ -864,6 +879,48 @@ pnm_streaming_start( stream_t *stream ) { } +int +realrtsp_streaming_read( int fd, char *buffer, int size, streaming_ctrl_t *stream_ctrl ) { + return rtsp_session_read(stream_ctrl->data, buffer, size); +} + + +int +realrtsp_streaming_start( stream_t *stream ) { + int fd; + rtsp_session_t *rtsp; + char *mrl; + int port; + char aport[10]; + if( stream==NULL ) return -1; + + fd = connect2Server( stream->streaming_ctrl->url->hostname, + port = (stream->streaming_ctrl->url->port ? stream->streaming_ctrl->url->port : 554) ); + printf("rtsp:// fd=%d\n",fd); + if(fd<0) return -1; + + sprintf(aport,"%d",port); + mrl = (char *)malloc(strlen(stream->streaming_ctrl->url->url)+1+10+1); + strcpy(mrl,stream->streaming_ctrl->url->url); + strcat(mrl,":"); + strcat(mrl,aport); + rtsp = rtsp_session_start(fd,mrl, stream->streaming_ctrl->url->file, + stream->streaming_ctrl->url->hostname, port); + free(mrl); + if(!rtsp) return -1; + + stream->fd=fd; + stream->streaming_ctrl->data=rtsp; + + stream->streaming_ctrl->streaming_read = realrtsp_streaming_read; +// stream->streaming_ctrl->streaming_seek = nop_streaming_seek; + stream->streaming_ctrl->prebuffer_size = 128*1024; // 8 KBytes + stream->streaming_ctrl->buffering = 1; + stream->streaming_ctrl->status = streaming_playing_e; + return 0; +} + + #ifndef STREAMING_LIVE_DOT_COM // Start listening on a UDP port. If multicast, join the group. int @@ -1008,6 +1065,12 @@ streaming_start(stream_t *stream, int *demuxer_type, URL_t *url) { ret = pnm_streaming_start( stream ); } else + if( (!strcasecmp( stream->streaming_ctrl->url->protocol, "rtsp")) && + (*demuxer_type == DEMUXER_TYPE_REAL)) { + stream->fd = -1; + ret = realrtsp_streaming_start( stream ); + } else + // For connection-oriented streams, we can usually determine the streaming type. switch( *demuxer_type ) { case DEMUXER_TYPE_ASF: diff --git a/libmpdemux/realrtsp/asmrp.c b/libmpdemux/realrtsp/asmrp.c new file mode 100644 index 0000000000..4f05b3bda0 --- /dev/null +++ b/libmpdemux/realrtsp/asmrp.c @@ -0,0 +1,670 @@ +/* + * This file was ported to MPlayer from xine CVS asmrp.c,v 1.2 2002/12/17 16:49:48 + */ + +/* + * Copyright (C) 2002 the xine project + * + * This file is part of xine, a free video player. + * + * xine is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * xine is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + * + * a parser for real's asm rules + * + * grammar for these rules: + * + + rule_book = { rule } + rule = ( '#' condition { ',' assignment } | [ assignment {',' assignment} ]) ';' + assignment = id '=' const + const = ( number | string ) + condition = comp_expr { ( '&&' | '||' ) comp_expr } + comp_expr = operand { ( '<' | '<=' | '==' | '>=' | '>' ) operand } + operand = ( '$' id | num | '(' condition ')' ) + + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +/* +#define LOG +*/ + +#define ASMRP_SYM_NONE 0 +#define ASMRP_SYM_EOF 1 + +#define ASMRP_SYM_NUM 2 +#define ASMRP_SYM_ID 3 +#define ASMRP_SYM_STRING 4 + +#define ASMRP_SYM_HASH 10 +#define ASMRP_SYM_SEMICOLON 11 +#define ASMRP_SYM_COMMA 12 +#define ASMRP_SYM_EQUALS 13 +#define ASMRP_SYM_AND 14 +#define ASMRP_SYM_OR 15 +#define ASMRP_SYM_LESS 16 +#define ASMRP_SYM_LEQ 17 +#define ASMRP_SYM_GEQ 18 +#define ASMRP_SYM_GREATER 19 +#define ASMRP_SYM_DOLLAR 20 +#define ASMRP_SYM_LPAREN 21 +#define ASMRP_SYM_RPAREN 22 + +#define ASMRP_MAX_ID 1024 + +#define ASMRP_MAX_SYMTAB 10 + +typedef struct { + char *id; + int v; +} asmrp_sym_t; + +typedef struct { + + /* public part */ + + int sym; + int num; + + char str[ASMRP_MAX_ID]; + + /* private part */ + + char *buf; + int pos; + char ch; + + asmrp_sym_t sym_tab[ASMRP_MAX_SYMTAB]; + int sym_tab_num; + +} asmrp_t; + +static asmrp_t *asmrp_new () { + + asmrp_t *p; + + p = malloc (sizeof (asmrp_t)); + + p->sym_tab_num = 0; + p->sym = ASMRP_SYM_NONE; + + return p; +} + +static void asmrp_dispose (asmrp_t *p) { + + int i; + + for (i=0; i<p->sym_tab_num; i++) + free (p->sym_tab[i].id); + + free (p); +} + +static void asmrp_getch (asmrp_t *p) { + p->ch = p->buf[p->pos]; + p->pos++; + +#ifdef LOG + printf ("%c\n", p->ch); +#endif + +} + +static void asmrp_init (asmrp_t *p, const char *str) { + + p->buf = strdup (str); + p->pos = 0; + + asmrp_getch (p); +} + +static void asmrp_number (asmrp_t *p) { + + int num; + + num = 0; + while ( (p->ch>='0') && (p->ch<='9') ) { + + num = num*10 + (p->ch - '0'); + + asmrp_getch (p); + } + + p->sym = ASMRP_SYM_NUM; + p->num = num; +} + +static void asmrp_string (asmrp_t *p) { + + int l; + + l = 0; + + while ( (p->ch!='"') && (p->ch>=32) ) { + + p->str[l] = p->ch; + + l++; + asmrp_getch (p); + } + p->str[l]=0; + + if (p->ch=='"') + asmrp_getch (p); + + p->sym = ASMRP_SYM_STRING; +} + +static void asmrp_identifier (asmrp_t *p) { + + int l; + + l = 0; + + while ( ((p->ch>='A') && (p->ch<='z')) + || ((p->ch>='0') && (p->ch<='9'))) { + + p->str[l] = p->ch; + + l++; + asmrp_getch (p); + } + p->str[l]=0; + + p->sym = ASMRP_SYM_ID; +} + +#ifdef LOG +static void asmrp_print_sym (asmrp_t *p) { + + printf ("symbol: "); + + switch (p->sym) { + + case ASMRP_SYM_NONE: + printf ("NONE\n"); + break; + + case ASMRP_SYM_EOF: + printf ("EOF\n"); + break; + + case ASMRP_SYM_NUM: + printf ("NUM %d\n", p->num); + break; + + case ASMRP_SYM_ID: + printf ("ID '%s'\n", p->str); + break; + + case ASMRP_SYM_STRING: + printf ("STRING \"%s\"\n", p->str); + break; + + case ASMRP_SYM_HASH: + printf ("#\n"); + break; + + case ASMRP_SYM_SEMICOLON: + printf (";\n"); + break; + case ASMRP_SYM_COMMA: + printf (",\n"); + break; + case ASMRP_SYM_EQUALS: + printf ("==\n"); + break; + case ASMRP_SYM_AND: + printf ("&&\n"); + break; + case ASMRP_SYM_OR: + printf ("||\n"); + break; + case ASMRP_SYM_LESS: + printf ("<\n"); + break; + case ASMRP_SYM_LEQ: + printf ("<=\n"); + break; + case ASMRP_SYM_GEQ: + printf (">=\n"); + break; + case ASMRP_SYM_GREATER: + printf (">\n"); + break; + case ASMRP_SYM_DOLLAR: + printf ("$\n"); + break; + case ASMRP_SYM_LPAREN: + printf ("(\n"); + break; + case ASMRP_SYM_RPAREN: + printf (")\n"); + break; + + default: + printf ("unknown symbol %d\n", p->sym); + } +} +#endif + +static void asmrp_get_sym (asmrp_t *p) { + + while (p->ch <= 32) { + if (p->ch == 0) { + p->sym = ASMRP_SYM_EOF; + return; + } + + asmrp_getch (p); + } + + if (p->ch == '\\') + asmrp_getch (p); + + switch (p->ch) { + + case '#': + p->sym = ASMRP_SYM_HASH; + asmrp_getch (p); + break; + case ';': + p->sym = ASMRP_SYM_SEMICOLON; + asmrp_getch (p); + break; + case ',': + p->sym = ASMRP_SYM_COMMA; + asmrp_getch (p); + break; + case '=': + p->sym = ASMRP_SYM_EQUALS; + asmrp_getch (p); + if (p->ch=='=') + asmrp_getch (p); + break; + case '&': + p->sym = ASMRP_SYM_AND; + asmrp_getch (p); + if (p->ch=='&') + asmrp_getch (p); + break; + case '|': + p->sym = ASMRP_SYM_OR; + asmrp_getch (p); + if (p->ch=='|') + asmrp_getch (p); + break; + case '<': + p->sym = ASMRP_SYM_LESS; + asmrp_getch (p); + if (p->ch=='=') { + p->sym = ASMRP_SYM_LEQ; + asmrp_getch (p); + } + break; + case '>': + p->sym = ASMRP_SYM_GREATER; + asmrp_getch (p); + if (p->ch=='=') { + p->sym = ASMRP_SYM_GEQ; + asmrp_getch (p); + } + break; + case '$': + p->sym = ASMRP_SYM_DOLLAR; + asmrp_getch (p); + break; + case '(': + p->sym = ASMRP_SYM_LPAREN; + asmrp_getch (p); + break; + case ')': + p->sym = ASMRP_SYM_RPAREN; + asmrp_getch (p); + break; + + case '"': + asmrp_getch (p); + asmrp_string (p); + break; + + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + asmrp_number (p); + break; + + default: + asmrp_identifier (p); + } + +#ifdef LOG + asmrp_print_sym (p); +#endif + +} + +static int asmrp_find_id (asmrp_t *p, char *s) { + + int i; + + for (i=0; i<p->sym_tab_num; i++) { + if (!strcmp (s, p->sym_tab[i].id)) + return i; + } + + return -1; +} + +static int asmrp_set_id (asmrp_t *p, char *s, int v) { + + int i; + + i = asmrp_find_id (p, s); + + if (i<0) { + i = p->sym_tab_num; + p->sym_tab_num++; + p->sym_tab[i].id = strdup (s); + +#ifdef LOG + printf ("new symbol '%s'\n", s); +#endif + + } + + p->sym_tab[i].v = v; + +#ifdef LOG + printf ("symbol '%s' assigned %d\n", s, v); +#endif + + return i; +} + +static int asmrp_condition (asmrp_t *p) ; + +static int asmrp_operand (asmrp_t *p) { + + int i, ret; + +#ifdef LOG + printf ("operand\n"); +#endif + + ret = 0; + + switch (p->sym) { + + case ASMRP_SYM_DOLLAR: + + asmrp_get_sym (p); + + if (p->sym != ASMRP_SYM_ID) { + printf ("error: identifier expected.\n"); + abort(); + } + + i = asmrp_find_id (p, p->str); + if (i<0) { + printf ("error: unknown identifier %s\n", p->str); + } + ret = p->sym_tab[i].v; + + asmrp_get_sym (p); + break; + + case ASMRP_SYM_NUM: + ret = p->num; + + asmrp_get_sym (p); + break; + + case ASMRP_SYM_LPAREN: + asmrp_get_sym (p); + + ret = asmrp_condition (p); + + if (p->sym != ASMRP_SYM_RPAREN) { + printf ("error: ) expected.\n"); + abort(); + } + + asmrp_get_sym (p); + break; + + default: + printf ("syntax error, $ number or ( expected\n"); + abort(); + } + +#ifdef LOG + printf ("operand done, =%d\n", ret); +#endif + + return ret; +} + +static int asmrp_comp_expression (asmrp_t *p) { + + int a; + +#ifdef LOG + printf ("comp_expression\n"); +#endif + + a = asmrp_operand (p); + + while ( (p->sym == ASMRP_SYM_LESS) + || (p->sym == ASMRP_SYM_LEQ) + || (p->sym == ASMRP_SYM_EQUALS) + || (p->sym == ASMRP_SYM_GEQ) + || (p->sym == ASMRP_SYM_GREATER) ) { + int op = p->sym; + int b; + + asmrp_get_sym (p); + + b = asmrp_operand (p); + + switch (op) { + case ASMRP_SYM_LESS: + a = a<b; + break; + case ASMRP_SYM_LEQ: + a = a<=b; + break; + case ASMRP_SYM_EQUALS: + a = a==b; + break; + case ASMRP_SYM_GEQ: + a = a>=b; + break; + case ASMRP_SYM_GREATER: + a = a>b; + break; + } + + } + +#ifdef LOG + printf ("comp_expression done = %d\n", a); +#endif + return a; +} + +static int asmrp_condition (asmrp_t *p) { + + int a; + +#ifdef LOG + printf ("condition\n"); +#endif + + a = asmrp_comp_expression (p); + + while ( (p->sym == ASMRP_SYM_AND) || (p->sym == ASMRP_SYM_OR) ) { + int op, b; + + op = p->sym; + + asmrp_get_sym (p); + + b = asmrp_comp_expression (p); + + switch (op) { + case ASMRP_SYM_AND: + a = a & b; + break; + case ASMRP_SYM_OR: + a = a | b; + break; + } + } + +#ifdef LOG + printf ("condition done = %d\n", a); +#endif + return a; +} + +static void asmrp_assignment (asmrp_t *p) { + +#ifdef LOG + printf ("assignment\n"); +#endif + + if (p->sym != ASMRP_SYM_ID) { + printf ("error: identifier expected\n"); + abort (); + } + asmrp_get_sym (p); + + if (p->sym != ASMRP_SYM_EQUALS) { + printf ("error: = expected\n"); + abort (); + } + asmrp_get_sym (p); + + if ( (p->sym != ASMRP_SYM_NUM) && (p->sym != ASMRP_SYM_STRING) + && (p->sym != ASMRP_SYM_ID)) { + printf ("error: number or string expected\n"); + abort (); + } + asmrp_get_sym (p); + +#ifdef LOG + printf ("assignment done\n"); +#endif +} + +static int asmrp_rule (asmrp_t *p) { + + int ret; + +#ifdef LOG + printf ("rule\n"); +#endif + + ret = 1; + + if (p->sym == ASMRP_SYM_HASH) { + + asmrp_get_sym (p); + ret = asmrp_condition (p); + + while (p->sym == ASMRP_SYM_COMMA) { + + asmrp_get_sym (p); + + asmrp_assignment (p); + } + + } else if (p->sym != ASMRP_SYM_SEMICOLON) { + + asmrp_assignment (p); + + while (p->sym == ASMRP_SYM_COMMA) { + + asmrp_get_sym (p); + asmrp_assignment (p); + } + } + +#ifdef LOG + printf ("rule done = %d\n", ret); +#endif + + if (p->sym != ASMRP_SYM_SEMICOLON) { + printf ("semicolon expected.\n"); + abort (); + } + + asmrp_get_sym (p); + + return ret; +} + +static int asmrp_eval (asmrp_t *p, int *matches) { + + int rule_num, num_matches; + +#ifdef LOG + printf ("eval\n"); +#endif + + asmrp_get_sym (p); + + rule_num = 0; num_matches = 0; + while (p->sym != ASMRP_SYM_EOF) { + + if (asmrp_rule (p)) { +#ifdef LOG + printf ("rule #%d is true\n", rule_num); +#endif + matches[num_matches] = rule_num; + num_matches++; + } + + rule_num++; + } + + matches[num_matches] = -1; + return num_matches; +} + +int asmrp_match (const char *rules, int bandwidth, int *matches) { + + asmrp_t *p; + int num_matches; + + p = asmrp_new (); + + asmrp_init (p, rules); + + asmrp_set_id (p, "Bandwidth", bandwidth); + asmrp_set_id (p, "OldPNMPlayer", 0); + + num_matches = asmrp_eval (p, matches); + + asmrp_dispose (p); + + return num_matches; +} + diff --git a/libmpdemux/realrtsp/asmrp.h b/libmpdemux/realrtsp/asmrp.h new file mode 100644 index 0000000000..7cbd37d74a --- /dev/null +++ b/libmpdemux/realrtsp/asmrp.h @@ -0,0 +1,45 @@ +/* + * This file was ported to MPlayer from xine CVS asmrp.h,v 1.1 2002/12/12 22:14:54 + */ + +/* + * Copyright (C) 2002 the xine project + * + * This file is part of xine, a free video player. + * + * xine is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * xine is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + * + * a parser for real's asm rules + * + * grammar for these rules: + * + + rule_book = { '#' rule ';'} + rule = condition {',' assignment} + assignment = id '=' const + const = ( number | string ) + condition = comp_expr { ( '&&' | '||' ) comp_expr } + comp_expr = operand { ( '<' | '<=' | '==' | '>=' | '>' ) operand } + operand = ( '$' id | num | '(' condition ')' ) + + */ + +#ifndef HAVE_ASMRP_H +#define HAVE_ASMRP_H + +int asmrp_match (const char *rules, int bandwidth, int *matches) ; + +#endif diff --git a/libmpdemux/realrtsp/real.c b/libmpdemux/realrtsp/real.c new file mode 100644 index 0000000000..ecc5260eaa --- /dev/null +++ b/libmpdemux/realrtsp/real.c @@ -0,0 +1,744 @@ +/* + * This file was ported to MPlayer from xine CVS real.c,v 1.8 2003/03/30 17:11:50 + */ + +/* + * Copyright (C) 2002 the xine project + * + * This file is part of xine, a free video player. + * + * xine is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * xine is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + * + * special functions for real streams. + * adopted from joschkas real tools. + * + */ + +#include <stdio.h> +#include <string.h> + +#include "real.h" +#include "asmrp.h" +#include "sdpplin.h" + +/* +#define LOG +*/ + +const unsigned char xor_table[] = { + 0x05, 0x18, 0x74, 0xd0, 0x0d, 0x09, 0x02, 0x53, + 0xc0, 0x01, 0x05, 0x05, 0x67, 0x03, 0x19, 0x70, + 0x08, 0x27, 0x66, 0x10, 0x10, 0x72, 0x08, 0x09, + 0x63, 0x11, 0x03, 0x71, 0x08, 0x08, 0x70, 0x02, + 0x10, 0x57, 0x05, 0x18, 0x54, 0x00, 0x00, 0x00 }; + + +#define BE_32C(x,y) x[3]=(char)(y & 0xff);\ + x[2]=(char)((y >> 8) & 0xff);\ + x[1]=(char)((y >> 16) & 0xff);\ + x[0]=(char)((y >> 24) & 0xff); + +#define BE_16(x) ((((uint8_t*)(x))[0] << 8) | ((uint8_t*)(x))[1]) + +#define BE_32(x) ((((uint8_t*)(x))[0] << 24) | \ + (((uint8_t*)(x))[1] << 16) | \ + (((uint8_t*)(x))[2] << 8) | \ + ((uint8_t*)(x))[3]) + +#define MAX(x,y) ((x>y) ? x : y) + +#ifdef LOG +static void hexdump (const char *buf, int length) { + + int i; + + printf (" hexdump> "); + for (i = 0; i < length; i++) { + unsigned char c = buf[i]; + + printf ("%02x", c); + + if ((i % 16) == 15) + printf ("\n "); + + if ((i % 2) == 1) + printf (" "); + + } + printf ("\n"); +} +#endif + + +static void hash(char *field, char *param) { + + uint32_t a, b, c, d; + + + /* fill variables */ + memcpy(&a, field, sizeof(uint32_t)); + memcpy(&b, &field[4], sizeof(uint32_t)); + memcpy(&c, &field[8], sizeof(uint32_t)); + memcpy(&d, &field[12], sizeof(uint32_t)); + +#ifdef LOG + printf("real: hash input: %x %x %x %x\n", a, b, c, d); + printf("real: hash parameter:\n"); + hexdump(param, 64); +#endif + + a = ((b & c) | (~b & d)) + *((uint32_t*)(param+0x00)) + a - 0x28955B88; + a = ((a << 0x07) | (a >> 0x19)) + b; + d = ((a & b) | (~a & c)) + *((uint32_t*)(param+0x04)) + d - 0x173848AA; + d = ((d << 0x0c) | (d >> 0x14)) + a; + c = ((d & a) | (~d & b)) + *((uint32_t*)(param+0x08)) + c + 0x242070DB; + c = ((c << 0x11) | (c >> 0x0f)) + d; + b = ((c & d) | (~c & a)) + *((uint32_t*)(param+0x0c)) + b - 0x3E423112; + b = ((b << 0x16) | (b >> 0x0a)) + c; + a = ((b & c) | (~b & d)) + *((uint32_t*)(param+0x10)) + a - 0x0A83F051; + a = ((a << 0x07) | (a >> 0x19)) + b; + d = ((a & b) | (~a & c)) + *((uint32_t*)(param+0x14)) + d + 0x4787C62A; + d = ((d << 0x0c) | (d >> 0x14)) + a; + c = ((d & a) | (~d & b)) + *((uint32_t*)(param+0x18)) + c - 0x57CFB9ED; + c = ((c << 0x11) | (c >> 0x0f)) + d; + b = ((c & d) | (~c & a)) + *((uint32_t*)(param+0x1c)) + b - 0x02B96AFF; + b = ((b << 0x16) | (b >> 0x0a)) + c; + a = ((b & c) | (~b & d)) + *((uint32_t*)(param+0x20)) + a + 0x698098D8; + a = ((a << 0x07) | (a >> 0x19)) + b; + d = ((a & b) | (~a & c)) + *((uint32_t*)(param+0x24)) + d - 0x74BB0851; + d = ((d << 0x0c) | (d >> 0x14)) + a; + c = ((d & a) | (~d & b)) + *((uint32_t*)(param+0x28)) + c - 0x0000A44F; + c = ((c << 0x11) | (c >> 0x0f)) + d; + b = ((c & d) | (~c & a)) + *((uint32_t*)(param+0x2C)) + b - 0x76A32842; + b = ((b << 0x16) | (b >> 0x0a)) + c; + a = ((b & c) | (~b & d)) + *((uint32_t*)(param+0x30)) + a + 0x6B901122; + a = ((a << 0x07) | (a >> 0x19)) + b; + d = ((a & b) | (~a & c)) + *((uint32_t*)(param+0x34)) + d - 0x02678E6D; + d = ((d << 0x0c) | (d >> 0x14)) + a; + c = ((d & a) | (~d & b)) + *((uint32_t*)(param+0x38)) + c - 0x5986BC72; + c = ((c << 0x11) | (c >> 0x0f)) + d; + b = ((c & d) | (~c & a)) + *((uint32_t*)(param+0x3c)) + b + 0x49B40821; + b = ((b << 0x16) | (b >> 0x0a)) + c; + + a = ((b & d) | (~d & c)) + *((uint32_t*)(param+0x04)) + a - 0x09E1DA9E; + a = ((a << 0x05) | (a >> 0x1b)) + b; + d = ((a & c) | (~c & b)) + *((uint32_t*)(param+0x18)) + d - 0x3FBF4CC0; + d = ((d << 0x09) | (d >> 0x17)) + a; + c = ((d & b) | (~b & a)) + *((uint32_t*)(param+0x2c)) + c + 0x265E5A51; + c = ((c << 0x0e) | (c >> 0x12)) + d; + b = ((c & a) | (~a & d)) + *((uint32_t*)(param+0x00)) + b - 0x16493856; + b = ((b << 0x14) | (b >> 0x0c)) + c; + a = ((b & d) | (~d & c)) + *((uint32_t*)(param+0x14)) + a - 0x29D0EFA3; + a = ((a << 0x05) | (a >> 0x1b)) + b; + d = ((a & c) | (~c & b)) + *((uint32_t*)(param+0x28)) + d + 0x02441453; + d = ((d << 0x09) | (d >> 0x17)) + a; + c = ((d & b) | (~b & a)) + *((uint32_t*)(param+0x3c)) + c - 0x275E197F; + c = ((c << 0x0e) | (c >> 0x12)) + d; + b = ((c & a) | (~a & d)) + *((uint32_t*)(param+0x10)) + b - 0x182C0438; + b = ((b << 0x14) | (b >> 0x0c)) + c; + a = ((b & d) | (~d & c)) + *((uint32_t*)(param+0x24)) + a + 0x21E1CDE6; + a = ((a << 0x05) | (a >> 0x1b)) + b; + d = ((a & c) | (~c & b)) + *((uint32_t*)(param+0x38)) + d - 0x3CC8F82A; + d = ((d << 0x09) | (d >> 0x17)) + a; + c = ((d & b) | (~b & a)) + *((uint32_t*)(param+0x0c)) + c - 0x0B2AF279; + c = ((c << 0x0e) | (c >> 0x12)) + d; + b = ((c & a) | (~a & d)) + *((uint32_t*)(param+0x20)) + b + 0x455A14ED; + b = ((b << 0x14) | (b >> 0x0c)) + c; + a = ((b & d) | (~d & c)) + *((uint32_t*)(param+0x34)) + a - 0x561C16FB; + a = ((a << 0x05) | (a >> 0x1b)) + b; + d = ((a & c) | (~c & b)) + *((uint32_t*)(param+0x08)) + d - 0x03105C08; + d = ((d << 0x09) | (d >> 0x17)) + a; + c = ((d & b) | (~b & a)) + *((uint32_t*)(param+0x1c)) + c + 0x676F02D9; + c = ((c << 0x0e) | (c >> 0x12)) + d; + b = ((c & a) | (~a & d)) + *((uint32_t*)(param+0x30)) + b - 0x72D5B376; + b = ((b << 0x14) | (b >> 0x0c)) + c; + + a = (b ^ c ^ d) + *((uint32_t*)(param+0x14)) + a - 0x0005C6BE; + a = ((a << 0x04) | (a >> 0x1c)) + b; + d = (a ^ b ^ c) + *((uint32_t*)(param+0x20)) + d - 0x788E097F; + d = ((d << 0x0b) | (d >> 0x15)) + a; + c = (d ^ a ^ b) + *((uint32_t*)(param+0x2c)) + c + 0x6D9D6122; + c = ((c << 0x10) | (c >> 0x10)) + d; + b = (c ^ d ^ a) + *((uint32_t*)(param+0x38)) + b - 0x021AC7F4; + b = ((b << 0x17) | (b >> 0x09)) + c; + a = (b ^ c ^ d) + *((uint32_t*)(param+0x04)) + a - 0x5B4115BC; + a = ((a << 0x04) | (a >> 0x1c)) + b; + d = (a ^ b ^ c) + *((uint32_t*)(param+0x10)) + d + 0x4BDECFA9; + d = ((d << 0x0b) | (d >> 0x15)) + a; + c = (d ^ a ^ b) + *((uint32_t*)(param+0x1c)) + c - 0x0944B4A0; + c = ((c << 0x10) | (c >> 0x10)) + d; + b = (c ^ d ^ a) + *((uint32_t*)(param+0x28)) + b - 0x41404390; + b = ((b << 0x17) | (b >> 0x09)) + c; + a = (b ^ c ^ d) + *((uint32_t*)(param+0x34)) + a + 0x289B7EC6; + a = ((a << 0x04) | (a >> 0x1c)) + b; + d = (a ^ b ^ c) + *((uint32_t*)(param+0x00)) + d - 0x155ED806; + d = ((d << 0x0b) | (d >> 0x15)) + a; + c = (d ^ a ^ b) + *((uint32_t*)(param+0x0c)) + c - 0x2B10CF7B; + c = ((c << 0x10) | (c >> 0x10)) + d; + b = (c ^ d ^ a) + *((uint32_t*)(param+0x18)) + b + 0x04881D05; + b = ((b << 0x17) | (b >> 0x09)) + c; + a = (b ^ c ^ d) + *((uint32_t*)(param+0x24)) + a - 0x262B2FC7; + a = ((a << 0x04) | (a >> 0x1c)) + b; + d = (a ^ b ^ c) + *((uint32_t*)(param+0x30)) + d - 0x1924661B; + d = ((d << 0x0b) | (d >> 0x15)) + a; + c = (d ^ a ^ b) + *((uint32_t*)(param+0x3c)) + c + 0x1fa27cf8; + c = ((c << 0x10) | (c >> 0x10)) + d; + b = (c ^ d ^ a) + *((uint32_t*)(param+0x08)) + b - 0x3B53A99B; + b = ((b << 0x17) | (b >> 0x09)) + c; + + a = ((~d | b) ^ c) + *((uint32_t*)(param+0x00)) + |