summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/input/libreal/real.c9
-rw-r--r--src/input/librtsp/rtsp.c99
2 files changed, 61 insertions, 47 deletions
diff --git a/src/input/libreal/real.c b/src/input/libreal/real.c
index 2d05058a7..efc445645 100644
--- a/src/input/libreal/real.c
+++ b/src/input/libreal/real.c
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
- * $Id: real.c,v 1.17 2004/04/24 16:55:42 miguelfreitas Exp $
+ * $Id: real.c,v 1.18 2004/04/24 20:43:57 miguelfreitas Exp $
*
* special functions for real streams.
* adopted from joschkas real tools.
@@ -601,7 +601,7 @@ int real_get_rdt_chunk(rtsp_t *rtsp_session, unsigned char **buffer) {
size-=12;
n=rtsp_read_data(rtsp_session, (*buffer)+12, size);
- return n+12;
+ return (n <= 0) ? 0 : n+12;
}
rmff_header_t *real_setup_and_get_header(rtsp_t *rtsp_session, uint32_t bandwidth) {
@@ -661,7 +661,10 @@ rmff_header_t *real_setup_and_get_header(rtsp_t *rtsp_session, uint32_t bandwid
description = malloc(sizeof(char)*(size+1));
- rtsp_read_data(rtsp_session, description, size);
+ if( rtsp_read_data(rtsp_session, description, size) <= 0) {
+ xine_buffer_free(buf);
+ return NULL;
+ }
description[size]=0;
/* parse sdp (sdpplin) and create a header and a subscribe string */
diff --git a/src/input/librtsp/rtsp.c b/src/input/librtsp/rtsp.c
index 02337cec3..dc60beca2 100644
--- a/src/input/librtsp/rtsp.c
+++ b/src/input/librtsp/rtsp.c
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
- * $Id: rtsp.c,v 1.15 2003/12/05 15:54:58 f1rmb Exp $
+ * $Id: rtsp.c,v 1.16 2004/04/24 20:43:58 miguelfreitas Exp $
*
* a minimalistic implementation of rtsp protocol,
* *not* RFC 2326 compilant yet.
@@ -42,7 +42,7 @@
#define LOG_VERBOSE
/*
#define LOG
-*/
+*/
#include "rtsp.h"
#include "io_helper.h"
@@ -68,8 +68,6 @@ struct rtsp_s {
unsigned int server_state;
uint32_t server_caps;
- char buffer[BUF_SIZE]; /* scratch buffer */
-
unsigned int cseq;
char *session;
@@ -103,33 +101,24 @@ const char rtsp_protocol_version[]="RTSP/1.0";
/*
* rtsp_get gets a line from stream
- * and returns a null terminated string.
+ * and returns a null terminated string (must be freed).
*/
static char *rtsp_get(rtsp_t *s) {
- int n=0;
- char *string;
-
- while (n<BUF_SIZE) {
- _x_io_tcp_read(s->stream, s->s, &s->buffer[n], 1);
- if ((s->buffer[n-1]==0x0d)&&(s->buffer[n]==0x0a)) break;
- n++;
- }
-
- if (n>=BUF_SIZE) {
- xprintf(s->stream->xine, XINE_VERBOSITY_DEBUG, "librtsp: buffer overflow in rtsp_get\n");
- exit(1);
+ char *buffer = malloc(BUF_SIZE);
+ char *string = NULL;
+
+ if ( _x_io_tcp_read_line(s->stream, s->s, buffer, BUF_SIZE) >= 0 ) {
+ lprintf("<< '%s'\n", buffer);
+ string = strdup( buffer );
}
- string = malloc(sizeof(char)*n);
- memcpy(string,s->buffer,n-1);
- string[n-1]=0;
-
- lprintf("<< '%s'\n", string);
-
+
+ free(buffer);
return string;
}
+
/*
* rtsp_put puts a line on stream
*/
@@ -184,8 +173,13 @@ static int rtsp_get_code(rtsp_t *s, const char *string) {
static void rtsp_send_request(rtsp_t *s, const char *type, const char *what) {
char **payload=s->scheduled;
- sprintf(s->buffer,"%s %s %s",type, what, rtsp_protocol_version);
- rtsp_put(s,s->buffer);
+ char *buf;
+
+ buf = malloc(strlen(type)+strlen(what)+strlen(rtsp_protocol_version)+3);
+
+ sprintf(buf,"%s %s %s",type, what, rtsp_protocol_version);
+ rtsp_put(s,buf);
+ free(buf);
if (payload)
while (*payload) {
rtsp_put(s,*payload);
@@ -201,11 +195,17 @@ static void rtsp_send_request(rtsp_t *s, const char *type, const char *what) {
static void rtsp_schedule_standard(rtsp_t *s) {
- sprintf(s->buffer, "Cseq: %u", s->cseq);
- rtsp_schedule_field(s, s->buffer);
+ char tmp[16];
+
+ sprintf(tmp, "Cseq: %u", s->cseq);
+ rtsp_schedule_field(s, tmp);
+
if (s->session) {
- sprintf(s->buffer, "Session: %s", s->session);
- rtsp_schedule_field(s, s->buffer);
+ char *buf;
+ buf = malloc(strlen(s->session)+15);
+ sprintf(buf, "Session: %s", s->session);
+ rtsp_schedule_field(s, buf);
+ free(buf);
}
}
/*
@@ -220,6 +220,8 @@ static int rtsp_get_answers(rtsp_t *s) {
int code;
answer=rtsp_get(s);
+ if (!answer)
+ return 0;
code=rtsp_get_code(s, answer);
free(answer);
@@ -228,6 +230,8 @@ static int rtsp_get_answers(rtsp_t *s) {
do { /* while we get answer lines */
answer=rtsp_get(s);
+ if (!answer)
+ return 0;
if (!strncmp(answer,"Cseq:",5)) {
sscanf(answer,"Cseq: %u",&answer_seq);
@@ -238,26 +242,29 @@ static int rtsp_get_answers(rtsp_t *s) {
}
}
if (!strncmp(answer,"Server:",7)) {
- sscanf(answer,"Server: %s",s->buffer);
+ char *buf = xine_xmalloc(strlen(answer));
+ sscanf(answer,"Server: %s",buf);
if (s->server) free(s->server);
- s->server=strdup(s->buffer);
+ s->server=strdup(buf);
+ free(buf);
}
if (!strncmp(answer,"Session:",8)) {
- memset(s->buffer,0, BUF_SIZE);
- sscanf(answer,"Session: %s",s->buffer);
+ char *buf = xine_xmalloc(strlen(answer));
+ sscanf(answer,"Session: %s",buf);
if (s->session) {
- if (strcmp(s->buffer, s->session)) {
+ if (strcmp(buf, s->session)) {
xprintf(s->stream->xine, XINE_VERBOSITY_DEBUG,
- "rtsp: warning: setting NEW session: %s\n", s->buffer);
+ "rtsp: warning: setting NEW session: %s\n", buf);
free(s->session);
- s->session=strdup(s->buffer);
+ s->session=strdup(buf);
}
} else
{
- lprintf("setting session id to: %s\n", s->buffer);
+ lprintf("setting session id to: %s\n", buf);
- s->session=strdup(s->buffer);
+ s->session=strdup(buf);
}
+ free(buf);
}
*answer_ptr=answer;
answer_ptr++;
@@ -386,13 +393,15 @@ int rtsp_read_data(rtsp_t *s, char *buffer, unsigned int size) {
if ((buffer[0]=='S')&&(buffer[1]=='E')&&(buffer[2]=='T')&&(buffer[3]=='_'))
{
char *rest=rtsp_get(s);
- /* a real server wanna play table tennis? */
- memcpy(s->buffer, buffer, 4);
- strcpy(s->buffer+4, rest);
+ if (!rest)
+ return -1;
+
seq=-1;
do {
free(rest);
rest=rtsp_get(s);
+ if (!rest)
+ return -1;
if (!strncmp(rest,"Cseq:",5))
sscanf(rest,"Cseq: %u",&seq);
} while (strlen(rest)!=0);
@@ -482,9 +491,11 @@ rtsp_t *rtsp_connect(xine_stream_t *stream, const char *mrl, const char *user_ag
if (pathbegin < strlen(mrl_ptr)) s->path=strdup(mrl_ptr+pathbegin+1);
if (colon != slash) {
- strncpy(s->buffer,mrl_ptr+hostend+1, pathbegin-hostend-1);
- s->buffer[pathbegin-hostend-1]=0;
- s->port=atoi(s->buffer);
+ char buffer[pathbegin-hostend];
+
+ strncpy(buffer,mrl_ptr+hostend+1, pathbegin-hostend-1);
+ buffer[pathbegin-hostend-1]=0;
+ s->port=atoi(buffer);
}
lprintf("got mrl: %s %i %s\n",s->host,s->port,s->path);