From bc5ab968714fcc9d3d319fdd0d23ca73fd9862f1 Mon Sep 17 00:00:00 2001
From: Josh Allmann <joshua.allmann@gmail.com>
Date: Fri, 4 Jun 2010 09:47:42 -0700
Subject: [PATCH 6/6] Propagated errors up ff_rtsp_send_cmd*

Conflicts:

	libavformat/rtsp.c
---
 libavformat/rtsp.c |   25 ++++++++++++++++---------
 libavformat/rtsp.h |   12 ++++++++----
 2 files changed, 24 insertions(+), 13 deletions(-)

diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index 5d6bdca..7b3abbe 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -1003,7 +1003,7 @@ int ff_rtsp_read_reply(AVFormatContext *s, RTSPMessageHeader *reply,
     return 0;
 }
 
-void ff_rtsp_send_cmd_with_content_async(AVFormatContext *s,
+int ff_rtsp_send_cmd_with_content_async(AVFormatContext *s,
                                          const char *method, const char *url,
                                          const char *headers,
                                          const unsigned char *send_content,
@@ -1048,23 +1048,25 @@ void ff_rtsp_send_cmd_with_content_async(AVFormatContext *s,
     if (send_content_length > 0 && send_content)
         url_write(rt->rtsp_hd_out, send_content, send_content_length);
     rt->last_cmd_time = av_gettime();
+
+    return 0;
 }
 
-void ff_rtsp_send_cmd_async(AVFormatContext *s, const char *method,
+int ff_rtsp_send_cmd_async(AVFormatContext *s, const char *method,
                             const char *url, const char *headers)
 {
-    ff_rtsp_send_cmd_with_content_async(s, method, url, headers, NULL, 0);
+    return ff_rtsp_send_cmd_with_content_async(s, method, url, headers, NULL, 0);
 }
 
-void ff_rtsp_send_cmd(AVFormatContext *s, const char *method, const char *url,
+int ff_rtsp_send_cmd(AVFormatContext *s, const char *method, const char *url,
                       const char *headers, RTSPMessageHeader *reply,
                       unsigned char **content_ptr)
 {
-    ff_rtsp_send_cmd_with_content(s, method, url, headers, reply,
+    return ff_rtsp_send_cmd_with_content(s, method, url, headers, reply,
                                   content_ptr, NULL, 0);
 }
 
-void ff_rtsp_send_cmd_with_content(AVFormatContext *s,
+int ff_rtsp_send_cmd_with_content(AVFormatContext *s,
                                    const char *method, const char *url,
                                    const char *header,
                                    RTSPMessageHeader *reply,
@@ -1074,17 +1076,22 @@ void ff_rtsp_send_cmd_with_content(AVFormatContext *s,
 {
     RTSPState *rt = s->priv_data;
     HTTPAuthType cur_auth_type;
+    int ret;
 
 retry:
     cur_auth_type = rt->auth_state.auth_type;
-    ff_rtsp_send_cmd_with_content_async(s, method, url, header,
-                                        send_content, send_content_length);
+    if ((ret = ff_rtsp_send_cmd_with_content_async(s, method, url, header,
+                                        send_content, send_content_length)))
+        return ret;
 
-    ff_rtsp_read_reply(s, reply, content_ptr, 0);
+    if ((ret = ff_rtsp_read_reply(s, reply, content_ptr, 0) ) < 0)
+        return ret;
 
     if (reply->status_code == 401 && cur_auth_type == HTTP_AUTH_NONE &&
         rt->auth_state.auth_type != HTTP_AUTH_NONE)
         goto retry;
+
+    return 0;
 }
 
 /**
diff --git a/libavformat/rtsp.h b/libavformat/rtsp.h
index 778193d..4662972 100644
--- a/libavformat/rtsp.h
+++ b/libavformat/rtsp.h
@@ -357,8 +357,10 @@ extern int rtsp_rtp_port_max;
  * @param send_content if non-null, the data to send as request body content
  * @param send_content_length the length of the send_content data, or 0 if
  *                            send_content is null
+ *
+ * @return zero if success, nonzero otherwise
  */
-void ff_rtsp_send_cmd_with_content_async(AVFormatContext *s,
+int ff_rtsp_send_cmd_with_content_async(AVFormatContext *s,
                                          const char *method, const char *url,
                                          const char *headers,
                                          const unsigned char *send_content,
@@ -368,7 +370,7 @@ void ff_rtsp_send_cmd_with_content_async(AVFormatContext *s,
  *
  * @see rtsp_send_cmd_with_content_async
  */
-void ff_rtsp_send_cmd_async(AVFormatContext *s, const char *method,
+int ff_rtsp_send_cmd_async(AVFormatContext *s, const char *method,
                             const char *url, const char *headers);
 
 /**
@@ -384,8 +386,10 @@ void ff_rtsp_send_cmd_async(AVFormatContext *s, const char *method,
  * @param send_content if non-null, the data to send as request body content
  * @param send_content_length the length of the send_content data, or 0 if
  *                            send_content is null
+ *
+ * @return zero if success, nonzero otherwise
  */
-void ff_rtsp_send_cmd_with_content(AVFormatContext *s,
+int ff_rtsp_send_cmd_with_content(AVFormatContext *s,
                                    const char *method, const char *url,
                                    const char *headers,
                                    RTSPMessageHeader *reply,
@@ -398,7 +402,7 @@ void ff_rtsp_send_cmd_with_content(AVFormatContext *s,
  *
  * @see rtsp_send_cmd_with_content
  */
-void ff_rtsp_send_cmd(AVFormatContext *s, const char *method,
+int ff_rtsp_send_cmd(AVFormatContext *s, const char *method,
                       const char *url, const char *headers,
                       RTSPMessageHeader *reply, unsigned char **content_ptr);
 
-- 
1.7.0.4

