annotate stream/librtsp/rtsp.c @ 25779:ad419ff363d7

Simplify and keep terminating end-of-line
author reimar
date Sat, 19 Jan 2008 16:57:53 +0000
parents 64d82a45a05d
children a3f6dc43b585
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18799
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
1 /*
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
2 * This file was ported to MPlayer from xine CVS rtsp.c,v 1.9 2003/04/10 02:30:48
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
3 */
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
4
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
5 /*
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
6 * Copyright (C) 2000-2002 the xine project
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
7 *
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
8 * This file is part of xine, a free video player.
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
9 *
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
10 * xine is free software; you can redistribute it and/or modify
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
11 * it under the terms of the GNU General Public License as published by
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
12 * the Free Software Foundation; either version 2 of the License, or
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
13 * (at your option) any later version.
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
14 *
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
15 * xine is distributed in the hope that it will be useful,
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
18 * GNU General Public License for more details.
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
19 *
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
20 * You should have received a copy of the GNU General Public License
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
21 * along with this program; if not, write to the Free Software
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
23 *
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
24 *
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
25 * a minimalistic implementation of rtsp protocol,
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
26 * *not* RFC 2326 compilant yet.
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
27 *
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
28 * 2006, Benjamin Zores and Vincent Mussard
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
29 * fixed a lot of RFC compliance issues.
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
30 */
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
31
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
32 #include <unistd.h>
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
33 #include <stdio.h>
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
34 #include <assert.h>
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
35 #include "config.h"
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
36 #ifndef HAVE_WINSOCK2
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
37 #define closesocket close
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
38 #include <sys/socket.h>
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
39 #include <netinet/in.h>
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
40 #include <netdb.h>
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
41 #else
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
42 #include <winsock2.h>
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
43 #endif
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
44 #include <string.h>
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
45 #include <sys/stat.h>
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
46 #include <fcntl.h>
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
47 #include <errno.h>
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
48 #include <stdlib.h>
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
49 #include <time.h>
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
50 #include <sys/time.h>
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
51 #include <sys/types.h>
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
52 #include <inttypes.h>
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
53
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
54 #include "mp_msg.h"
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
55 #include "rtsp.h"
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
56 #include "rtsp_session.h"
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
57 #include "osdep/timer.h"
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
58
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
59 /*
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
60 #define LOG
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
61 */
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
62
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
63 #define BUF_SIZE 4096
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
64 #define HEADER_SIZE 1024
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
65 #define MAX_FIELDS 256
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
66
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
67 struct rtsp_s {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
68
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
69 int s;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
70
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
71 char *host;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
72 int port;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
73 char *path;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
74 char *param;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
75 char *mrl;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
76 char *user_agent;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
77
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
78 char *server;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
79 unsigned int server_state;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
80 uint32_t server_caps;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
81
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
82 unsigned int cseq;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
83 char *session;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
84
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
85 char *answers[MAX_FIELDS]; /* data of last message */
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
86 char *scheduled[MAX_FIELDS]; /* will be sent with next message */
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
87 };
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
88
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
89 /*
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
90 * constants
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
91 */
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
92
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
93 #define RTSP_PROTOCOL_VERSION "RTSP/1.0"
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
94
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
95 /* server states */
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
96 #define RTSP_CONNECTED 1
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
97 #define RTSP_INIT 2
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
98 #define RTSP_READY 4
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
99 #define RTSP_PLAYING 8
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
100 #define RTSP_RECORDING 16
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
101
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
102 /* server capabilities */
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
103 #define RTSP_OPTIONS 0x001
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
104 #define RTSP_DESCRIBE 0x002
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
105 #define RTSP_ANNOUNCE 0x004
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
106 #define RTSP_SETUP 0x008
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
107 #define RTSP_GET_PARAMETER 0x010
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
108 #define RTSP_SET_PARAMETER 0x020
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
109 #define RTSP_TEARDOWN 0x040
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
110 #define RTSP_PLAY 0x080
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
111 #define RTSP_RECORD 0x100
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
112
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
113 /*
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
114 * network utilities
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
115 */
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
116
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
117 static int write_stream(int s, const char *buf, int len) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
118 int total, timeout;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
119
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
120 total = 0; timeout = 30;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
121 while (total < len){
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
122 int n;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
123
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
124 n = send (s, &buf[total], len - total, 0);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
125
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
126 if (n > 0)
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
127 total += n;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
128 else if (n < 0) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
129 #ifndef HAVE_WINSOCK2
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
130 if ((timeout>0) && ((errno == EAGAIN) || (errno == EINPROGRESS))) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
131 #else
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
132 if ((timeout>0) && ((errno == EAGAIN) || (WSAGetLastError() == WSAEINPROGRESS))) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
133 #endif
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
134 usec_sleep (1000000); timeout--;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
135 } else
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
136 return -1;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
137 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
138 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
139
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
140 return total;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
141 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
142
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
143 static ssize_t read_stream(int fd, void *buf, size_t count) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
144
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
145 ssize_t ret, total;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
146
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
147 total = 0;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
148
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
149 while (total < count) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
150
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
151 ret=recv (fd, ((uint8_t*)buf)+total, count-total, 0);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
152
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
153 if (ret<0) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
154 if(errno == EAGAIN) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
155 fd_set rset;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
156 struct timeval timeout;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
157
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
158 FD_ZERO (&rset);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
159 FD_SET (fd, &rset);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
160
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
161 timeout.tv_sec = 30;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
162 timeout.tv_usec = 0;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
163
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
164 if (select (fd+1, &rset, NULL, NULL, &timeout) <= 0) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
165 return -1;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
166 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
167 continue;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
168 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
169
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
170 mp_msg(MSGT_OPEN, MSGL_ERR, "rtsp: read error.\n");
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
171 return ret;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
172 } else
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
173 total += ret;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
174
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
175 /* end of stream */
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
176 if (!ret) break;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
177 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
178
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
179 return total;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
180 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
181
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
182 /*
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
183 * rtsp_get gets a line from stream
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
184 * and returns a null terminated string.
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
185 */
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
186
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
187 static char *rtsp_get(rtsp_t *s) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
188
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
189 int n=1;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
190 char *buffer = malloc(BUF_SIZE);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
191 char *string = NULL;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
192
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
193 read_stream(s->s, buffer, 1);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
194 while (n<BUF_SIZE) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
195 read_stream(s->s, &(buffer[n]), 1);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
196 if ((buffer[n-1]==0x0d)&&(buffer[n]==0x0a)) break;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
197 n++;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
198 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
199
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
200 if (n>=BUF_SIZE) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
201 mp_msg(MSGT_OPEN, MSGL_FATAL, "librtsp: buffer overflow in rtsp_get\n");
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
202 exit(1);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
203 }
18854
a973acb2e572 cosmetic patch to remove useless sizeof(char) statements
ben
parents: 18853
diff changeset
204 string=malloc(n);
18799
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
205 memcpy(string,buffer,n-1);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
206 string[n-1]=0;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
207
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
208 #ifdef LOG
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
209 mp_msg(MSGT_OPEN, MSGL_INFO, "librtsp: << '%s'\n", string);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
210 #endif
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
211
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
212
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
213 free(buffer);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
214 return string;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
215 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
216
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
217 /*
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
218 * rtsp_put puts a line on stream
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
219 */
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
220
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
221 static void rtsp_put(rtsp_t *s, const char *string) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
222
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
223 int len=strlen(string);
18854
a973acb2e572 cosmetic patch to remove useless sizeof(char) statements
ben
parents: 18853
diff changeset
224 char *buf=malloc(len+2);
18799
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
225
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
226 #ifdef LOG
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
227 mp_msg(MSGT_OPEN, MSGL_INFO, "librtsp: >> '%s'", string);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
228 #endif
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
229
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
230 memcpy(buf,string,len);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
231 buf[len]=0x0d;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
232 buf[len+1]=0x0a;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
233
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
234 write_stream(s->s, buf, len+2);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
235
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
236 #ifdef LOG
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
237 mp_msg(MSGT_OPEN, MSGL_INFO, " done.\n");
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
238 #endif
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
239
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
240 free(buf);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
241 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
242
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
243 /*
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
244 * extract server status code
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
245 */
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
246
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
247 static int rtsp_get_code(const char *string) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
248
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
249 char buf[4];
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
250 int code=0;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
251
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
252 if (!strncmp(string, RTSP_PROTOCOL_VERSION, strlen(RTSP_PROTOCOL_VERSION)))
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
253 {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
254 memcpy(buf, string+strlen(RTSP_PROTOCOL_VERSION)+1, 3);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
255 buf[3]=0;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
256 code=atoi(buf);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
257 } else if (!strncmp(string, RTSP_METHOD_SET_PARAMETER,8))
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
258 {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
259 return RTSP_STATUS_SET_PARAMETER;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
260 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
261
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
262 if(code != RTSP_STATUS_OK) mp_msg(MSGT_OPEN, MSGL_INFO, "librtsp: server responds: '%s'\n",string);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
263
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
264 return code;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
265 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
266
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
267 /*
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
268 * send a request
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
269 */
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
270
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
271 static void rtsp_send_request(rtsp_t *s, const char *type, const char *what) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
272
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
273 char **payload=s->scheduled;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
274 char *buf;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
275
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
276 buf = malloc(strlen(type)+strlen(what)+strlen(RTSP_PROTOCOL_VERSION)+3);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
277
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
278 sprintf(buf,"%s %s %s",type, what, RTSP_PROTOCOL_VERSION);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
279 rtsp_put(s,buf);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
280 free(buf);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
281 if (payload)
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
282 while (*payload) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
283 rtsp_put(s,*payload);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
284 payload++;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
285 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
286 rtsp_put(s,"");
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
287 rtsp_unschedule_all(s);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
288 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
289
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
290 /*
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
291 * schedule standard fields
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
292 */
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
293
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
294 static void rtsp_schedule_standard(rtsp_t *s) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
295
18853
1ec19da0c642 increase buffer size, "CSeq: %u" has a worst case of 17 (fix 1.18 from xine, see http://xine.cvs.sourceforge.net/xine/xine-lib/src/input/librtsp/rtsp.c?r1=1.17&r2=1.18)
ben
parents: 18852
diff changeset
296 char tmp[17];
18799
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
297
18853
1ec19da0c642 increase buffer size, "CSeq: %u" has a worst case of 17 (fix 1.18 from xine, see http://xine.cvs.sourceforge.net/xine/xine-lib/src/input/librtsp/rtsp.c?r1=1.17&r2=1.18)
ben
parents: 18852
diff changeset
298 snprintf(tmp, 17, "CSeq: %u", s->cseq);
18799
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
299 rtsp_schedule_field(s, tmp);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
300
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
301 if (s->session) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
302 char *buf;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
303 buf = malloc(strlen(s->session)+15);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
304 sprintf(buf, "Session: %s", s->session);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
305 rtsp_schedule_field(s, buf);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
306 free(buf);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
307 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
308 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
309 /*
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
310 * get the answers, if server responses with something != 200, return NULL
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
311 */
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
312
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
313 static int rtsp_get_answers(rtsp_t *s) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
314
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
315 char *answer=NULL;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
316 unsigned int answer_seq;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
317 char **answer_ptr=s->answers;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
318 int code;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
319 int ans_count = 0;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
320
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
321 answer=rtsp_get(s);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
322 if (!answer)
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
323 return 0;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
324 code=rtsp_get_code(answer);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
325 free(answer);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
326
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
327 rtsp_free_answers(s);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
328
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
329 do { /* while we get answer lines */
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
330
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
331 answer=rtsp_get(s);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
332 if (!answer)
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
333 return 0;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
334
18852
b17648e2762e be more tolerant on server responses parameters case (fix 1.17 from xine, see http://xine.cvs.sourceforge.net/xine/xine-lib/src/input/librtsp/rtsp.c?r1=1.16&r2=1.17)
ben
parents: 18851
diff changeset
335 if (!strncasecmp(answer,"CSeq:",5)) {
b17648e2762e be more tolerant on server responses parameters case (fix 1.17 from xine, see http://xine.cvs.sourceforge.net/xine/xine-lib/src/input/librtsp/rtsp.c?r1=1.16&r2=1.17)
ben
parents: 18851
diff changeset
336 sscanf(answer,"%*s %u",&answer_seq);
18799
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
337 if (s->cseq != answer_seq) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
338 #ifdef LOG
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
339 mp_msg(MSGT_OPEN, MSGL_WARN, "librtsp: warning: CSeq mismatch. got %u, assumed %u", answer_seq, s->cseq);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
340 #endif
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
341 s->cseq=answer_seq;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
342 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
343 }
18852
b17648e2762e be more tolerant on server responses parameters case (fix 1.17 from xine, see http://xine.cvs.sourceforge.net/xine/xine-lib/src/input/librtsp/rtsp.c?r1=1.16&r2=1.17)
ben
parents: 18851
diff changeset
344 if (!strncasecmp(answer,"Server:",7)) {
18799
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
345 char *buf = malloc(strlen(answer));
18852
b17648e2762e be more tolerant on server responses parameters case (fix 1.17 from xine, see http://xine.cvs.sourceforge.net/xine/xine-lib/src/input/librtsp/rtsp.c?r1=1.16&r2=1.17)
ben
parents: 18851
diff changeset
346 sscanf(answer,"%*s %s",buf);
18799
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
347 if (s->server) free(s->server);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
348 s->server=strdup(buf);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
349 free(buf);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
350 }
18852
b17648e2762e be more tolerant on server responses parameters case (fix 1.17 from xine, see http://xine.cvs.sourceforge.net/xine/xine-lib/src/input/librtsp/rtsp.c?r1=1.16&r2=1.17)
ben
parents: 18851
diff changeset
351 if (!strncasecmp(answer,"Session:",8)) {
18799
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
352 char *buf = calloc(1, strlen(answer));
18852
b17648e2762e be more tolerant on server responses parameters case (fix 1.17 from xine, see http://xine.cvs.sourceforge.net/xine/xine-lib/src/input/librtsp/rtsp.c?r1=1.16&r2=1.17)
ben
parents: 18851
diff changeset
353 sscanf(answer,"%*s %s",buf);
18799
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
354 if (s->session) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
355 if (strcmp(buf, s->session)) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
356 mp_msg(MSGT_OPEN, MSGL_WARN, "rtsp: warning: setting NEW session: %s\n", buf);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
357 free(s->session);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
358 s->session=strdup(buf);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
359 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
360 } else
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
361 {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
362 #ifdef LOG
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
363 mp_msg(MSGT_OPEN, MSGL_INFO, "rtsp: setting session id to: %s\n", buf);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
364 #endif
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
365 s->session=strdup(buf);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
366 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
367 free(buf);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
368 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
369 *answer_ptr=answer;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
370 answer_ptr++;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
371 } while ((strlen(answer)!=0) && (++ans_count < MAX_FIELDS));
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
372
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
373 s->cseq++;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
374
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
375 *answer_ptr=NULL;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
376 rtsp_schedule_standard(s);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
377
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
378 return code;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
379 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
380
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
381 /*
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
382 * send an ok message
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
383 */
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
384
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
385 int rtsp_send_ok(rtsp_t *s) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
386 char cseq[16];
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
387
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
388 rtsp_put(s, "RTSP/1.0 200 OK");
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
389 sprintf(cseq,"CSeq: %u", s->cseq);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
390 rtsp_put(s, cseq);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
391 rtsp_put(s, "");
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
392 return 0;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
393 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
394
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
395 /*
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
396 * implementation of must-have rtsp requests; functions return
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
397 * server status code.
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
398 */
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
399
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
400 int rtsp_request_options(rtsp_t *s, const char *what) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
401
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
402 char *buf;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
403
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
404 if (what) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
405 buf=strdup(what);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
406 } else
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
407 {
18854
a973acb2e572 cosmetic patch to remove useless sizeof(char) statements
ben
parents: 18853
diff changeset
408 buf=malloc(strlen(s->host)+16);
18799
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
409 sprintf(buf,"rtsp://%s:%i", s->host, s->port);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
410 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
411 rtsp_send_request(s,RTSP_METHOD_OPTIONS,buf);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
412 free(buf);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
413
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
414 return rtsp_get_answers(s);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
415 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
416
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
417 int rtsp_request_describe(rtsp_t *s, const char *what) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
418
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
419 char *buf;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
420
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
421 if (what) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
422 buf=strdup(what);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
423 } else
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
424 {
18854
a973acb2e572 cosmetic patch to remove useless sizeof(char) statements
ben
parents: 18853
diff changeset
425 buf=malloc(strlen(s->host)+strlen(s->path)+16);
18799
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
426 sprintf(buf,"rtsp://%s:%i/%s", s->host, s->port, s->path);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
427 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
428 rtsp_send_request(s,RTSP_METHOD_DESCRIBE,buf);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
429 free(buf);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
430
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
431 return rtsp_get_answers(s);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
432 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
433
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
434 int rtsp_request_setup(rtsp_t *s, const char *what, char *control) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
435
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
436 char *buf = NULL;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
437
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
438 if (what)
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
439 buf = strdup (what);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
440 else
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
441 {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
442 int len = strlen (s->host) + strlen (s->path) + 16;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
443 if (control)
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
444 len += strlen (control) + 1;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
445
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
446 buf = malloc (len);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
447 sprintf (buf, "rtsp://%s:%i/%s%s%s", s->host, s->port, s->path,
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
448 control ? "/" : "", control ? control : "");
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
449 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
450
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
451 rtsp_send_request (s, RTSP_METHOD_SETUP, buf);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
452 free (buf);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
453 return rtsp_get_answers (s);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
454 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
455
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
456 int rtsp_request_setparameter(rtsp_t *s, const char *what) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
457
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
458 char *buf;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
459
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
460 if (what) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
461 buf=strdup(what);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
462 } else
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
463 {
18854
a973acb2e572 cosmetic patch to remove useless sizeof(char) statements
ben
parents: 18853
diff changeset
464 buf=malloc(strlen(s->host)+strlen(s->path)+16);
18799
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
465 sprintf(buf,"rtsp://%s:%i/%s", s->host, s->port, s->path);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
466 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
467 rtsp_send_request(s,RTSP_METHOD_SET_PARAMETER,buf);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
468 free(buf);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
469
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
470 return rtsp_get_answers(s);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
471 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
472
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
473 int rtsp_request_play(rtsp_t *s, const char *what) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
474
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
475 char *buf;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
476 int ret;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
477
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
478 if (what) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
479 buf=strdup(what);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
480 } else
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
481 {
18854
a973acb2e572 cosmetic patch to remove useless sizeof(char) statements
ben
parents: 18853
diff changeset
482 buf=malloc(strlen(s->host)+strlen(s->path)+16);
18799
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
483 sprintf(buf,"rtsp://%s:%i/%s", s->host, s->port, s->path);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
484 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
485 rtsp_send_request(s,RTSP_METHOD_PLAY,buf);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
486 free(buf);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
487
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
488 ret = rtsp_get_answers (s);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
489 if (ret == RTSP_STATUS_OK)
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
490 s->server_state = RTSP_PLAYING;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
491
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
492 return ret;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
493 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
494
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
495 int rtsp_request_teardown(rtsp_t *s, const char *what) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
496
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
497 char *buf;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
498
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
499 if (what)
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
500 buf = strdup (what);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
501 else
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
502 {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
503 buf =
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
504 malloc (strlen (s->host) + strlen (s->path) + 16);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
505 sprintf (buf, "rtsp://%s:%i/%s", s->host, s->port, s->path);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
506 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
507 rtsp_send_request (s, RTSP_METHOD_TEARDOWN, buf);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
508 free (buf);
18801
f17474882196 prevent a buffer overflow to occur at teardown
ben
parents: 18799
diff changeset
509
f17474882196 prevent a buffer overflow to occur at teardown
ben
parents: 18799
diff changeset
510 /* after teardown we're done with RTSP streaming, no need to get answer as
f17474882196 prevent a buffer overflow to occur at teardown
ben
parents: 18799
diff changeset
511 reading more will only result to garbage and buffer overflow */
f17474882196 prevent a buffer overflow to occur at teardown
ben
parents: 18799
diff changeset
512 return RTSP_STATUS_OK;
18799
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
513 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
514
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
515 /*
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
516 * read opaque data from stream
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
517 */
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
518
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
519 int rtsp_read_data(rtsp_t *s, char *buffer, unsigned int size) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
520
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
521 int i,seq;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
522
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
523 if (size>=4) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
524 i=read_stream(s->s, buffer, 4);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
525 if (i<4) return i;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
526 if (((buffer[0]=='S')&&(buffer[1]=='E')&&(buffer[2]=='T')&&(buffer[3]=='_')) ||
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
527 ((buffer[0]=='O')&&(buffer[1]=='P')&&(buffer[2]=='T')&&(buffer[3]=='I'))) // OPTIONS
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
528 {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
529 char *rest=rtsp_get(s);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
530 if (!rest)
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
531 return -1;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
532
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
533 seq=-1;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
534 do {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
535 free(rest);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
536 rest=rtsp_get(s);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
537 if (!rest)
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
538 return -1;
18852
b17648e2762e be more tolerant on server responses parameters case (fix 1.17 from xine, see http://xine.cvs.sourceforge.net/xine/xine-lib/src/input/librtsp/rtsp.c?r1=1.16&r2=1.17)
ben
parents: 18851
diff changeset
539 if (!strncasecmp(rest,"CSeq:",5))
b17648e2762e be more tolerant on server responses parameters case (fix 1.17 from xine, see http://xine.cvs.sourceforge.net/xine/xine-lib/src/input/librtsp/rtsp.c?r1=1.16&r2=1.17)
ben
parents: 18851
diff changeset
540 sscanf(rest,"%*s %u",&seq);
18799
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
541 } while (strlen(rest)!=0);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
542 free(rest);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
543 if (seq<0) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
544 #ifdef LOG
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
545 mp_msg(MSGT_OPEN, MSGL_WARN, "rtsp: warning: CSeq not recognized!\n");
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
546 #endif
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
547 seq=1;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
548 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
549 /* let's make the server happy */
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
550 rtsp_put(s, "RTSP/1.0 451 Parameter Not Understood");
18854
a973acb2e572 cosmetic patch to remove useless sizeof(char) statements
ben
parents: 18853
diff changeset
551 rest=malloc(17);
18799
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
552 sprintf(rest,"CSeq: %u", seq);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
553 rtsp_put(s, rest);
18855
a60bcf4969c3 coverity report #179 from xine: variable "rest" not freed or pointed-to in function "rtsp_put" (see http://xine.cvs.sourceforge.net/xine/xine-lib/src/input/librtsp/rtsp.c?r1=1.19&r2=1.20)
ben
parents: 18854
diff changeset
554 free(rest);
18799
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
555 rtsp_put(s, "");
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
556 i=read_stream(s->s, buffer, size);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
557 } else
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
558 {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
559 i=read_stream(s->s, buffer+4, size-4);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
560 i+=4;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
561 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
562 } else
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
563 i=read_stream(s->s, buffer, size);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
564 #ifdef LOG
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
565 mp_msg(MSGT_OPEN, MSGL_INFO, "librtsp: << %d of %d bytes\n", i, size);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
566 #endif
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
567
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
568 return i;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
569 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
570
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
571 /*
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
572 * connect to a rtsp server
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
573 */
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
574
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
575 //rtsp_t *rtsp_connect(const char *mrl, const char *user_agent) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
576 rtsp_t *rtsp_connect(int fd, char* mrl, char *path, char *host, int port, char *user_agent) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
577
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
578 rtsp_t *s=malloc(sizeof(rtsp_t));
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
579 int i;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
580
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
581 for (i=0; i<MAX_FIELDS; i++) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
582 s->answers[i]=NULL;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
583 s->scheduled[i]=NULL;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
584 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
585
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
586 s->server=NULL;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
587 s->server_state=0;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
588 s->server_caps=0;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
589
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
590 s->cseq=0;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
591 s->session=NULL;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
592
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
593 if (user_agent)
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
594 s->user_agent=strdup(user_agent);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
595 else
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
596 s->user_agent=strdup("User-Agent: RealMedia Player Version 6.0.9.1235 (linux-2.0-libc6-i386-gcc2.95)");
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
597
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
598 s->mrl = strdup(mrl);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
599 s->host = strdup(host);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
600 s->port = port;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
601 s->path = strdup(path);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
602 while (*path == '/')
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
603 path++;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
604 if ((s->param = strchr(s->path, '?')) != NULL)
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
605 s->param++;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
606 //mp_msg(MSGT_OPEN, MSGL_INFO, "path=%s\n", s->path);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
607 //mp_msg(MSGT_OPEN, MSGL_INFO, "param=%s\n", s->param ? s->param : "NULL");
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
608 s->s = fd;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
609
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
610 if (s->s < 0) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
611 mp_msg(MSGT_OPEN, MSGL_ERR, "rtsp: failed to connect to '%s'\n", s->host);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
612 rtsp_close(s);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
613 return NULL;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
614 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
615
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
616 s->server_state=RTSP_CONNECTED;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
617
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
618 /* now let's send an options request. */
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
619 rtsp_schedule_field(s, "CSeq: 1");
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
620 rtsp_schedule_field(s, s->user_agent);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
621 rtsp_schedule_field(s, "ClientChallenge: 9e26d33f2984236010ef6253fb1887f7");
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
622 rtsp_schedule_field(s, "PlayerStarttime: [28/03/2003:22:50:23 00:00]");
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
623 rtsp_schedule_field(s, "CompanyID: KnKV4M4I/B2FjJ1TToLycw==");
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
624 rtsp_schedule_field(s, "GUID: 00000000-0000-0000-0000-000000000000");
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
625 rtsp_schedule_field(s, "RegionData: 0");
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
626 rtsp_schedule_field(s, "ClientID: Linux_2.4_6.0.9.1235_play32_RN01_EN_586");
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
627 /*rtsp_schedule_field(s, "Pragma: initiate-session");*/
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
628 rtsp_request_options(s, NULL);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
629
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
630 return s;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
631 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
632
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
633
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
634 /*
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
635 * closes an rtsp connection
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
636 */
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
637
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
638 void rtsp_close(rtsp_t *s) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
639
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
640 if (s->server_state)
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
641 {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
642 if (s->server_state == RTSP_PLAYING)
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
643 rtsp_request_teardown (s, NULL);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
644 closesocket (s->s);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
645 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
646
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
647 if (s->path) free(s->path);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
648 if (s->host) free(s->host);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
649 if (s->mrl) free(s->mrl);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
650 if (s->session) free(s->session);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
651 if (s->user_agent) free(s->user_agent);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
652 rtsp_free_answers(s);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
653 rtsp_unschedule_all(s);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
654 free(s);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
655 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
656
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
657 /*
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
658 * search in answers for tags. returns a pointer to the content
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
659 * after the first matched tag. returns NULL if no match found.
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
660 */
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
661
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
662 char *rtsp_search_answers(rtsp_t *s, const char *tag) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
663
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
664 char **answer;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
665 char *ptr;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
666
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
667 if (!s->answers) return NULL;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
668 answer=s->answers;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
669
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
670 while (*answer) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
671 if (!strncasecmp(*answer,tag,strlen(tag))) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
672 ptr=strchr(*answer,':');
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
673 if (!ptr) return NULL;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
674 ptr++;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
675 while(*ptr==' ') ptr++;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
676 return ptr;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
677 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
678 answer++;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
679 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
680
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
681 return NULL;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
682 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
683
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
684 /*
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
685 * session id management
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
686 */
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
687
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
688 void rtsp_set_session(rtsp_t *s, const char *id) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
689
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
690 if (s->session) free(s->session);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
691
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
692 s->session=strdup(id);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
693
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
694 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
695
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
696 char *rtsp_get_session(rtsp_t *s) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
697
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
698 return s->session;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
699
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
700 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
701
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
702 char *rtsp_get_mrl(rtsp_t *s) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
703
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
704 return s->mrl;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
705
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
706 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
707
19108
5e767cabf4cd marks several read-only string parameters and function return-values which can only be used read-only as const. Patch by Stefan Huehner, stefan _AT huener-org
reynaldo
parents: 18855
diff changeset
708 char *rtsp_get_param(rtsp_t *s, const char *p) {
18799
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
709 int len;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
710 char *param;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
711 if (!s->param)
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
712 return NULL;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
713 if (!p)
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
714 return strdup(s->param);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
715 len = strlen(p);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
716 param = s->param;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
717 while (param && *param) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
718 char *nparam = strchr(param, '&');
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
719 if (strncmp(param, p, len) == 0 && param[len] == '=') {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
720 param += len + 1;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
721 len = nparam ? nparam - param : strlen(param);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
722 nparam = malloc(len + 1);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
723 memcpy(nparam, param, len);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
724 nparam[len] = 0;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
725 return nparam;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
726 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
727 param = nparam ? nparam + 1 : NULL;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
728 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
729 return NULL;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
730 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
731
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
732 /*
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
733 * schedules a field for transmission
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
734 */
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
735
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
736 void rtsp_schedule_field(rtsp_t *s, const char *string) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
737
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
738 int i=0;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
739
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
740 if (!string) return;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
741
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
742 while(s->scheduled[i]) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
743 i++;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
744 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
745 s->scheduled[i]=strdup(string);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
746 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
747
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
748 /*
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
749 * removes the first scheduled field which prefix matches string.
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
750 */
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
751
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
752 void rtsp_unschedule_field(rtsp_t *s, const char *string) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
753
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
754 char **ptr=s->scheduled;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
755
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
756 if (!string) return;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
757
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
758 while(*ptr) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
759 if (!strncmp(*ptr, string, strlen(string)))
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
760 break;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
761 else
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
762 ptr++;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
763 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
764 if (*ptr) free(*ptr);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
765 ptr++;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
766 do {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
767 *(ptr-1)=*ptr;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
768 } while(*ptr);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
769 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
770
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
771 /*
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
772 * unschedule all fields
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
773 */
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
774
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
775 void rtsp_unschedule_all(rtsp_t *s) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
776
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
777 char **ptr;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
778
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
779 if (!s->scheduled) return;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
780 ptr=s->scheduled;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
781
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
782 while (*ptr) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
783 free(*ptr);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
784 *ptr=NULL;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
785 ptr++;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
786 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
787 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
788 /*
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
789 * free answers
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
790 */
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
791
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
792 void rtsp_free_answers(rtsp_t *s) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
793
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
794 char **answer;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
795
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
796 if (!s->answers) return;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
797 answer=s->answers;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
798
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
799 while (*answer) {
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
800 free(*answer);
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
801 *answer=NULL;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
802 answer++;
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
803 }
e16345b97dab moved generic rtsp related files from realrtsp to librtsp
ben
parents:
diff changeset
804 }