]> code.delx.au - pulseaudio/blobdiff - src/modules/rtp/rtsp_client.c
Merge remote branch 'origin/master-tx'
[pulseaudio] / src / modules / rtp / rtsp_client.c
index 9eb3d9648bbeec6ff482988214c0de62c7ebeef8..915c1072e3f00a36ea097e5bbe7c12ab4de57b20 100644 (file)
@@ -5,7 +5,7 @@
 
   PulseAudio is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as published
-  by the Free Software Foundation; either version 2 of the License,
+  by the Free Software Foundation; either version 2.1 of the License,
   or (at your option) any later version.
 
   PulseAudio is distributed in the hope that it will be useful, but
@@ -30,6 +30,7 @@
 #include <arpa/inet.h>
 #include <unistd.h>
 #include <sys/ioctl.h>
+#include <netinet/in.h>
 
 #ifdef HAVE_SYS_FILIO_H
 #include <sys/filio.h>
 #include <pulsecore/log.h>
 #include <pulsecore/macro.h>
 #include <pulsecore/strbuf.h>
-#include <pulsecore/poll.h>
 #include <pulsecore/ioline.h>
 
+#ifdef HAVE_POLL_H
+#include <poll.h>
+#else
+#include <pulsecore/poll.h>
+#endif
+
 #include "rtsp_client.h"
 
 struct pa_rtsp_client {
@@ -101,26 +107,27 @@ pa_rtsp_client* pa_rtsp_client_new(pa_mainloop_api *mainloop, const char* hostna
 
 
 void pa_rtsp_client_free(pa_rtsp_client* c) {
-    if (c) {
-        if (c->sc)
-            pa_socket_client_unref(c->sc);
-        if (c->ioline)
-            pa_ioline_close(c->ioline);
-        else if (c->io)
-            pa_iochannel_free(c->io);
-
-        pa_xfree(c->hostname);
-        pa_xfree(c->url);
-        pa_xfree(c->localip);
-        pa_xfree(c->session);
-        pa_xfree(c->transport);
-        pa_xfree(c->last_header);
-        if (c->header_buffer)
-            pa_strbuf_free(c->header_buffer);
-        if (c->response_headers)
-            pa_headerlist_free(c->response_headers);
-        pa_headerlist_free(c->headers);
-    }
+    pa_assert(c);
+
+    if (c->sc)
+        pa_socket_client_unref(c->sc);
+    if (c->ioline)
+        pa_ioline_close(c->ioline);
+    else if (c->io)
+        pa_iochannel_free(c->io);
+
+    pa_xfree(c->hostname);
+    pa_xfree(c->url);
+    pa_xfree(c->localip);
+    pa_xfree(c->session);
+    pa_xfree(c->transport);
+    pa_xfree(c->last_header);
+    if (c->header_buffer)
+        pa_strbuf_free(c->header_buffer);
+    if (c->response_headers)
+        pa_headerlist_free(c->response_headers);
+    pa_headerlist_free(c->headers);
+
     pa_xfree(c);
 }
 
@@ -141,8 +148,6 @@ static void headers_read(pa_rtsp_client *c) {
         c->transport = pa_xstrdup(pa_headerlist_gets(c->response_headers, "Transport"));
 
         if (!c->session || !c->transport) {
-            pa_headerlist_free(c->response_headers);
-            c->response_headers = NULL;
             pa_log("Invalid SETUP response.");
             return;
         }
@@ -160,8 +165,6 @@ static void headers_read(pa_rtsp_client *c) {
         }
         if (0 == c->rtp_port) {
             /* Error no server_port in response */
-            pa_headerlist_free(c->response_headers);
-            c->response_headers = NULL;
             pa_log("Invalid SETUP response (no port number).");
             return;
         }
@@ -169,9 +172,6 @@ static void headers_read(pa_rtsp_client *c) {
 
     /* Call our callback */
     c->callback(c, c->state, c->response_headers, c->userdata);
-
-    pa_headerlist_free(c->response_headers);
-    c->response_headers = NULL;
 }
 
 
@@ -201,7 +201,8 @@ static void line_callback(pa_ioline *line, const char *s, void *userdata) {
     }
     if (c->waiting && 0 == strcmp("RTSP/1.0 200 OK", s2)) {
         c->waiting = 0;
-        pa_assert(!c->response_headers);
+        if (c->response_headers)
+            pa_headerlist_free(c->response_headers);
         c->response_headers = pa_headerlist_new();
         goto exit;
     }
@@ -211,13 +212,15 @@ static void line_callback(pa_ioline *line, const char *s, void *userdata) {
     }
     if (!strlen(s2)) {
         /* End of headers */
-        /* We will have a header left from our looping itteration, so add it in :) */
+        /* We will have a header left from our looping iteration, so add it in :) */
         if (c->last_header) {
+            char *tmp = pa_strbuf_tostring_free(c->header_buffer);
             /* This is not a continuation header so let's dump it into our proplist */
-            pa_headerlist_puts(c->response_headers, c->last_header, pa_strbuf_tostring_free(c->header_buffer));
+            pa_headerlist_puts(c->response_headers, c->last_header, tmp);
+            pa_xfree(tmp);
             pa_xfree(c->last_header);
             c->last_header = NULL;
-            c->header_buffer= NULL;
+            c->header_buffer = NULL;
         }
 
         pa_log_debug("Full response received. Dispatching");
@@ -239,9 +242,11 @@ static void line_callback(pa_ioline *line, const char *s, void *userdata) {
     }
 
     if (c->last_header) {
+        char *tmp = pa_strbuf_tostring_free(c->header_buffer);
         /* This is not a continuation header so let's dump the full
           header/value into our proplist */
-        pa_headerlist_puts(c->response_headers, c->last_header, pa_strbuf_tostring_free(c->header_buffer));
+        pa_headerlist_puts(c->response_headers, c->last_header, tmp);
+        pa_xfree(tmp);
         pa_xfree(c->last_header);
         c->last_header = NULL;
         c->header_buffer = NULL;
@@ -332,7 +337,7 @@ int pa_rtsp_connect(pa_rtsp_client *c) {
     pa_xfree(c->session);
     c->session = NULL;
 
-    if (!(c->sc = pa_socket_client_new_string(c->mainloop, c->hostname, c->port))) {
+    if (!(c->sc = pa_socket_client_new_string(c->mainloop, TRUE, c->hostname, c->port))) {
         pa_log("failed to connect to server '%s:%d'", c->hostname, c->port);
         return -1;
     }
@@ -353,9 +358,12 @@ void pa_rtsp_set_callback(pa_rtsp_client *c, pa_rtsp_cb_t callback, void *userda
 void pa_rtsp_disconnect(pa_rtsp_client *c) {
     pa_assert(c);
 
-    if (c->io)
+    if (c->ioline)
+        pa_ioline_close(c->ioline);
+    else if (c->io)
         pa_iochannel_free(c->io);
     c->io = NULL;
+    c->ioline = NULL;
 }
 
 
@@ -448,6 +456,8 @@ static int rtsp_exec(pa_rtsp_client* c, const char* cmd,
     l = pa_iochannel_write(c->io, hdrs, strlen(hdrs));
     pa_xfree(hdrs);
 
+    /* FIXME: this is broken, not necessarily all bytes are written */
+
     return 0;
 }
 
@@ -485,7 +495,7 @@ int pa_rtsp_record(pa_rtsp_client* c, uint16_t* seq, uint32_t* rtptime) {
 
     pa_assert(c);
     if (!c->session) {
-        /* No seesion in progres */
+        /* No session in progress */
         return -1;
     }