- if (G_UNLIKELY (res == GST_RTSP_EEOF))
- goto eof;
- if (res == GST_RTSP_ETGET) {
- GString *str;
- GstRTSPStatusCode code;
- guint size;
-
- if (watch->funcs.tunnel_start)
- code = watch->funcs.tunnel_start (watch, watch->user_data);
- else
- code = GST_RTSP_STS_OK;
-
- /* queue the response string */
- str = gen_tunnel_reply (watch->conn, code);
- size = str->len;
- gst_rtsp_watch_queue_data (watch, (guint8 *) g_string_free (str, FALSE),
- size);
- } else if (res == GST_RTSP_ETPOST) {
- /* in the callback the connection should be tunneled with the
- * GET connection */
- if (watch->funcs.tunnel_complete)
- watch->funcs.tunnel_complete (watch, watch->user_data);
- } else if (G_UNLIKELY (res != GST_RTSP_OK))
- goto error;
+ else if (G_UNLIKELY (res == GST_RTSP_EEOF)) {
+ watch->readfd.events = 0;
+ watch->readfd.revents = 0;
+ g_source_remove_poll ((GSource *) watch, &watch->readfd);
+ /* When we are in tunnelled mode, the read socket can be closed and we
+ * should be prepared for a new POST method to reopen it */
+ if (watch->conn->tstate == TUNNEL_STATE_COMPLETE) {
+ /* remove the read connection for the tunnel */
+ /* we accept a new POST request */
+ watch->conn->tstate = TUNNEL_STATE_GET;
+ /* and signal that we lost our tunnel */
+ if (watch->funcs.tunnel_lost)
+ res = watch->funcs.tunnel_lost (watch, watch->user_data);
+ goto read_done;
+ } else
+ goto eof;
+ } else if (G_LIKELY (res == GST_RTSP_OK)) {
+ if (!watch->conn->manual_http &&
+ watch->message.type == GST_RTSP_MESSAGE_HTTP_REQUEST) {
+ if (watch->conn->tstate == TUNNEL_STATE_NONE &&
+ watch->message.type_data.request.method == GST_RTSP_GET) {
+ GstRTSPMessage *response;
+ GstRTSPStatusCode code;
+
+ watch->conn->tstate = TUNNEL_STATE_GET;
+
+ if (watch->funcs.tunnel_start)
+ code = watch->funcs.tunnel_start (watch, watch->user_data);
+ else
+ code = GST_RTSP_STS_OK;
+
+ /* queue the response */
+ response = gen_tunnel_reply (watch->conn, code, &watch->message);
+ gst_rtsp_watch_send_message (watch, response, NULL);
+ gst_rtsp_message_free (response);
+ goto read_done;
+ } else if (watch->conn->tstate == TUNNEL_STATE_NONE &&
+ watch->message.type_data.request.method == GST_RTSP_POST) {
+ watch->conn->tstate = TUNNEL_STATE_POST;
+
+ /* in the callback the connection should be tunneled with the
+ * GET connection */
+ if (watch->funcs.tunnel_complete)
+ watch->funcs.tunnel_complete (watch, watch->user_data);
+ goto read_done;
+ }
+ }
+ }
+
+ if (!watch->conn->manual_http) {
+ /* if manual HTTP support is not enabled, then restore the message to
+ * what it would have looked like without the support for parsing HTTP
+ * messages being present */
+ if (watch->message.type == GST_RTSP_MESSAGE_HTTP_REQUEST) {
+ watch->message.type = GST_RTSP_MESSAGE_REQUEST;
+ watch->message.type_data.request.method = GST_RTSP_INVALID;
+ if (watch->message.type_data.request.version != GST_RTSP_VERSION_1_0)
+ watch->message.type_data.request.version = GST_RTSP_VERSION_INVALID;
+ res = GST_RTSP_EPARSE;
+ } else if (watch->message.type == GST_RTSP_MESSAGE_HTTP_RESPONSE) {
+ watch->message.type = GST_RTSP_MESSAGE_RESPONSE;
+ if (watch->message.type_data.response.version != GST_RTSP_VERSION_1_0)
+ watch->message.type_data.response.version =
+ GST_RTSP_VERSION_INVALID;
+ res = GST_RTSP_EPARSE;
+ }
+ }