diff options
-rw-r--r-- | src/input/input_rtsp.c | 3 | ||||
-rw-r--r-- | src/input/libreal/real.c | 12 | ||||
-rw-r--r-- | src/input/librtsp/rtsp.c | 40 | ||||
-rw-r--r-- | src/input/librtsp/rtsp.h | 9 | ||||
-rw-r--r-- | src/input/librtsp/rtsp_session.c | 8 | ||||
-rw-r--r-- | src/input/pnm.c | 40 |
6 files changed, 86 insertions, 26 deletions
diff --git a/src/input/input_rtsp.c b/src/input/input_rtsp.c index f97e3e02c..172358f85 100644 --- a/src/input/input_rtsp.c +++ b/src/input/input_rtsp.c @@ -236,6 +236,9 @@ static input_plugin_t *open_plugin (input_class_t *cls_gen, xine_stream_t *strea if (!rtsp) { free (mrl); +#ifdef LOG + printf ("input_rtsp: returning null.\n"); +#endif return NULL; } diff --git a/src/input/libreal/real.c b/src/input/libreal/real.c index 908629316..a239712b8 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.2 2002/12/14 00:02:31 holstsn Exp $ + * $Id: real.c,v 1.3 2002/12/16 21:50:54 holstsn Exp $ * * special functions for real streams. * adopted from joschkas real tools. @@ -895,7 +895,15 @@ rmff_header_t *real_setup_and_get_header(rtsp_t *rtsp_session, uint32_t bandwid rtsp_schedule_field(rtsp_session, "Require: com.real.retain-entity-for-setup"); status=rtsp_request_describe(rtsp_session,NULL); - if (status != 200) return NULL; + if ( status<200 || status>299 ) + { + char *alert=rtsp_search_answers(rtsp_session,"Alert"); + if (alert) { + printf("real: got message from server:\n%s\n", alert); + } + rtsp_send_ok(rtsp_session); + return NULL; + } /* receive description */ size=0; diff --git a/src/input/librtsp/rtsp.c b/src/input/librtsp/rtsp.c index b1f92ce6a..15cef3066 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.2 2002/12/14 00:02:31 holstsn Exp $ + * $Id: rtsp.c,v 1.3 2002/12/16 21:50:55 holstsn Exp $ * * a minimalistic implementation of rtsp protocol, * *not* RFC 2326 compilant yet. @@ -301,11 +301,17 @@ static void rtsp_put(rtsp_t *s, const char *string) { static int rtsp_get_code(const char *string) { char buf[4]; - int code; - - memcpy(buf, string+strlen(rtsp_protocol_version)+1, 3); - buf[3]=0; - code=atoi(buf); + int code=0; + + if (!strncmp(string, rtsp_protocol_version, strlen(rtsp_protocol_version))) + { + memcpy(buf, string+strlen(rtsp_protocol_version)+1, 3); + buf[3]=0; + code=atoi(buf); + } else if (!strncmp(string, "SET_PARAMETER",8)) + { + return RTSP_STATUS_SET_PARAMETER; + } if(code != 200) printf("librtsp: server responds: '%s'\n",string); @@ -367,8 +373,12 @@ static int rtsp_get_answers(rtsp_t *s) { if (!strncmp(answer,"Cseq:",5)) { sscanf(answer,"Cseq: %u",&answer_seq); if (s->cseq != answer_seq) { +#ifdef LOG printf("librtsp: warning: Cseq mismatch. got %u, assumed %u", answer_seq, s->cseq); - } +#endif + s->cseq=answer_seq; + } else + s->cseq++; } if (!strncmp(answer,"Server:",7)) { sscanf(answer,"Server: %s",s->buffer); @@ -397,13 +407,26 @@ static int rtsp_get_answers(rtsp_t *s) { } while (strlen(answer)!=0); *answer_ptr=NULL; - s->cseq++; rtsp_schedule_standard(s); return code; } /* + * send an ok message + */ + +int rtsp_send_ok(rtsp_t *s) { + char cseq[16]; + + rtsp_put(s, "RTSP/1.0 200 OK"); + sprintf(cseq,"CSeq: %u", s->cseq); + rtsp_put(s, cseq); + rtsp_put(s, ""); + +} + +/* * implementation of must-have rtsp requests; functions return * server status code. */ @@ -568,6 +591,7 @@ rtsp_t *rtsp_connect(const char *mrl, const char *user_agent) { s->host=NULL; s->port=554; /* rtsp standard port */ s->path=NULL; + s->mrl=NULL; s->mrl=strdup(mrl); s->server=NULL; diff --git a/src/input/librtsp/rtsp.h b/src/input/librtsp/rtsp.h index 346ef59af..02e838da6 100644 --- a/src/input/librtsp/rtsp.h +++ b/src/input/librtsp/rtsp.h @@ -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.h,v 1.1 2002/12/12 22:14:56 holstsn Exp $ + * $Id: rtsp.h,v 1.2 2002/12/16 21:50:55 holstsn Exp $ * * a minimalistic implementation of rtsp protocol, * *not* RFC 2326 compilant yet. @@ -35,6 +35,11 @@ #define uint8_t unsigned char #endif +/* some codes returned by rtsp_request_* functions */ + +#define RTSP_STATUS_SET_PARAMETER 10 +#define RTSP_STATUS_OK 200 + typedef struct rtsp_s rtsp_t; rtsp_t* rtsp_connect (const char *mrl, const char *user_agent); @@ -46,6 +51,8 @@ int rtsp_request_setparameter(rtsp_t *s, const char *what); int rtsp_request_play(rtsp_t *s, const char *what); int rtsp_request_tearoff(rtsp_t *s, const char *what); +int rtsp_send_ok(rtsp_t *s); + int rtsp_read_data(rtsp_t *s, char *buffer, unsigned int size); char* rtsp_search_answers(rtsp_t *s, const char *tag); diff --git a/src/input/librtsp/rtsp_session.c b/src/input/librtsp/rtsp_session.c index 3e51ac7a1..04302a7d2 100644 --- a/src/input/librtsp/rtsp_session.c +++ b/src/input/librtsp/rtsp_session.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_session.c,v 1.3 2002/12/15 16:54:10 holstsn Exp $ + * $Id: rtsp_session.c,v 1.4 2002/12/16 21:50:55 holstsn Exp $ * * high level interface to rtsp servers. */ @@ -97,6 +97,12 @@ connect: rtsp_close(rtsp_session->s); free(server); goto connect; /* *shudder* i made a design mistake somewhere */ + } else + { + printf("rtsp_session: session can not be established.\n"); + rtsp_close(rtsp_session->s); + free(rtsp_session); + return NULL; } } diff --git a/src/input/pnm.c b/src/input/pnm.c index fa3c307a7..dff3650a3 100644 --- a/src/input/pnm.c +++ b/src/input/pnm.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: pnm.c,v 1.3 2002/12/15 01:34:56 holstsn Exp $ + * $Id: pnm.c,v 1.4 2002/12/16 21:50:54 holstsn Exp $ * * pnm protocol implementation * based upon code from joschka @@ -177,6 +177,8 @@ unsigned char after_chunks[]={ 0x1f, 0x3a /* varies on each request (checksum ?)*/ }; +static void hexdump (char *buf, int length); + /* * network utilities */ @@ -346,7 +348,7 @@ static unsigned int pnm_get_chunk(pnm_t *p, switch (*chunk_type) { case PNA_TAG: ptr=&data[PREAMBLE_SIZE]; - rm_read (p->s, ptr, 0x0b - PREAMBLE_SIZE); + rm_read (p->s, ptr, 0x0c - PREAMBLE_SIZE); ptr+=0x0b-PREAMBLE_SIZE; if (data[PREAMBLE_SIZE+0x01] == 'X') /* checking for server message */ { @@ -355,16 +357,16 @@ static unsigned int pnm_get_chunk(pnm_t *p, rm_read (p->s, &data[PREAMBLE_SIZE+0x04], n); data[PREAMBLE_SIZE+0x04+n]=0; printf("%s\n",&data[PREAMBLE_SIZE+0x04]); - exit(0); + return -1; } if (data[PREAMBLE_SIZE+0x01] == 'F') { printf("input_pnm: server error.\n"); - exit(0); + return -1; } /* expecting following chunk format: 0x4f <chunk size> <data...> */ - rm_read (p->s, ptr, 2); + rm_read (p->s, ptr+1, 1); while (*ptr == 0x4f) { ptr++; n=(*ptr); @@ -384,7 +386,7 @@ static unsigned int pnm_get_chunk(pnm_t *p, printf("error: max chunk size exeeded (max was 0x%04x)\n", max); n=rm_read (p->s, &data[PREAMBLE_SIZE], 0x100 - PREAMBLE_SIZE); hexdump(data,n+PREAMBLE_SIZE); - exit(0); + return -1; } rm_read (p->s, &data[PREAMBLE_SIZE], chunk_size-PREAMBLE_SIZE); break; @@ -494,9 +496,11 @@ static void pnm_send_response(pnm_t *p, const char *response) { * get headers and challenge and fix headers * write headers to p->header * write challenge to p->buffer + * + * return 0 on error. != 0 on success */ -static void pnm_get_headers(pnm_t *p) { +static int pnm_get_headers(pnm_t *p) { uint32_t chunk_type; uint8_t *ptr=p->header; @@ -508,9 +512,10 @@ static void pnm_get_headers(pnm_t *p) { if (HEADER_SIZE-size<=0) { printf("input_pnm: header buffer overflow. exiting\n"); - exit(1); + return 0; } chunk_size=pnm_get_chunk(p,HEADER_SIZE-size,&chunk_type,ptr); + if (chunk_size < 0) return 0; if (chunk_type == 0) break; if (chunk_type == PNA_TAG) { @@ -658,15 +663,15 @@ static int pnm_get_stream_chunk(pnm_t *p) { { int size=BE_16(&p->buffer[1]); - rm_read (p->s, &p->buffer[8], size-8); - p->buffer[size+8]=0; - printf("input_pnm: got message from server:\n%s\n", &p->buffer[3]); - exit(0); + rm_read (p->s, &p->buffer[8], size-5); + p->buffer[size+3]=0; + printf("input_pnm: got message from server while reading stream:\n%s\n", &p->buffer[3]); + return 0; } if (p->buffer[0] == 'F') { printf("input_pnm: server error.\n"); - exit(0); + return 0; } /* skip bytewise to next chunk. @@ -803,7 +808,14 @@ pnm_t *pnm_connect(const char *mrl) { p->s=fd; pnm_send_request(p,pnm_available_bandwidths[10]); - pnm_get_headers(p); + if (!pnm_get_headers(p)) { + printf ("input_pnm: failed to set up stream\n"); + free(p->path); + free(p->host); + free(p->url); + free(p); + return NULL; + } pnm_send_response(p, pnm_response); p->ts_last[0]=0; p->ts_last[1]=0; |