? neon_http_proxy_and_redirects_bus_messages.patch
Index: gstneonhttpsrc.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-bad/ext/neon/gstneonhttpsrc.c,v
retrieving revision 1.25
diff -u -r1.25 gstneonhttpsrc.c
--- gstneonhttpsrc.c	22 Mar 2007 21:07:02 -0000	1.25
+++ gstneonhttpsrc.c	29 Mar 2007 19:52:18 -0000
@@ -231,6 +231,8 @@
 gst_neonhttp_src_init (GstNeonhttpSrc * src, GstNeonhttpSrcClass * g_class)
 {
   const gchar *str = g_getenv ("http_proxy");
+  
+  GST_DEBUG("Got default HTTP proxy (%s).", str);
 
   src->neon_http_msgs_dbg = NEON_HTTP_DEBUG_DEFAULT;
   src->session = NULL;
@@ -742,30 +744,52 @@
 static gboolean
 gst_neonhttp_src_set_proxy (GstNeonhttpSrc * src, const char *uri)
 {
+  GstMessage *m = NULL;
+  g_return_val_if_fail( uri != NULL, FALSE );
+  
   ne_uri_free (&src->proxy);
 
   if (ne_uri_parse (uri, &src->proxy) != 0)
+  {
+    GST_DEBUG ("Failed when trying to parse proxy URI (uri = %s)!", uri);
     goto error;
-
+  }
+  /* TODO: need to know if the schema field in the proxy URI is useful 
   if (src->proxy.scheme)
     GST_WARNING ("The proxy schema shouldn't be defined (schema is '%s')",
-        src->proxy.scheme);
-
-  if (src->proxy.host && !src->proxy.port)
-    goto error;
+       src->proxy.scheme);
+  */
 
 #ifdef NEON_026_OR_LATER
   if (!src->proxy.path || src->proxy.userinfo)
+  {
+    GST_DEBUG ("Proxy path is wrong, path is NULL and user-info is not NULL (%s)!", src->proxy.userinfo);
     goto error;
+  }
 #else
   if (!src->proxy.path || src->proxy.authinfo)
+  {
+    GST_DEBUG ("Proxy path is wrong, path is NULL and auth-info is not NULL! (%s)!", src->proxy.authinfo);
     goto error;
+  }
 #endif
+  
+  /* we have HTTP proxy information being sent to the application now */
+  m = gst_message_new_application(GST_OBJECT (src),
+     gst_structure_new ("proxy",
+        "proxy-url", G_TYPE_STRING, uri, NULL));
+  
+  gst_element_post_message ( GST_ELEMENT(src), m );
+  
+  GST_DEBUG ("Sent message with the proxy path (uri = %s) to the bus.", uri);
+  
   return TRUE;
 
   /* ERRORS */
 error:
   {
+    GST_DEBUG ("Failed when parsing the proxy URI!");
+
     ne_uri_free (&src->proxy);
     return FALSE;
   }
@@ -784,13 +808,14 @@
   gint res;
   gint http_status = 0;
   guint request_count = 0;
+  const gchar* redir = NULL;
 
   do {
     if (src->proxy.host && src->proxy.port) {
       session =
           ne_session_create (src->uri.scheme, src->uri.host, src->uri.port);
       ne_session_proxy (session, src->proxy.host, src->proxy.port);
-    } else if (src->proxy.host || src->proxy.port) {
+    } else if (!src->proxy.host && !src->proxy.port) {
       /* both proxy host and port must be specified or none */
       return HTTP_REQUEST_WRONG_PROXY;
     } else {
@@ -819,23 +844,23 @@
       /* When the HTTP status code is 302, it is not the SHOUTcast streaming content yet;
        * Reload the HTTP request with a new URI value */
       http_status = ne_get_status (request)->code;
-      if (http_status == 302 && do_redir) {
-        const gchar *redir;
-
+      if (http_status == 302) {
         /* the new URI value to go when redirecting can be found on the 'Location' HTTP header */
         redir = ne_get_response_header (request, "Location");
-        if (redir != NULL) {
-          ne_uri_free (&src->uri);
-          gst_neonhttp_src_set_uri (src, redir);
-#ifndef GST_DISABLE_GST_DEBUG
-          if (src->neon_http_msgs_dbg)
-            GST_LOG_OBJECT (src,
-                "--> Got HTTP Status Code %d; Using 'Location' header [%s]",
-                http_status, src->uri.host);
-#endif
-        }
-      }
-    }
+
+        if ( do_redir && (redir != NULL) ) {
+            ne_uri_free (&src->uri);
+            gst_neonhttp_src_set_uri (src, redir);
+  #ifndef GST_DISABLE_GST_DEBUG
+            if (src->neon_http_msgs_dbg)
+              GST_LOG_OBJECT (src,
+                  "--> Got HTTP Status Code %d; Using 'Location' header [%s]",
+                  http_status, src->uri.host);
+  #endif
+        } /* if - do HTTP redirection? */
+
+      } /* if - 302 status code */
+    } /* if - HTTP request is OK */
 
     if ((res != NE_OK) ||
         (offset == 0 && http_status != 200) ||
@@ -851,19 +876,31 @@
     }
 
     /* if - NE_OK */
-    if (http_status == 302 && do_redir) {
-      ++request_count;
-      GST_WARNING_OBJECT (src, "%s %s.",
-          (request_count < MAX_HTTP_REDIRECTS_NUMBER)
-          && do_redir ? "Redirecting to" :
-          "WILL NOT redirect, try it again with a different URI; an alternative is",
-          src->uri.host);
-      /* FIXME: when not redirecting automatically, shouldn't we post a 
-       * redirect element message on the bus? */
-#ifndef GST_DISABLE_GST_DEBUG
-      if (src->neon_http_msgs_dbg)
-        GST_LOG_OBJECT (src, "--> request_count = %d", request_count);
-#endif
+    if (http_status == 302 ) {
+      if ( do_redir ) {
+        ++request_count;
+        GST_WARNING_OBJECT (src, "%s %s.",
+            (request_count < MAX_HTTP_REDIRECTS_NUMBER)
+            && do_redir ? "Redirecting to" :
+            "WILL NOT redirect, try it again with a different URI; an alternative is",
+            src->uri.host);
+        /* [FIXED] FIXME: when not redirecting automatically, shouldn't we post a 
+         * redirect element message on the bus? */
+  #ifndef GST_DISABLE_GST_DEBUG
+        if (src->neon_http_msgs_dbg)
+          GST_LOG_OBJECT (src, "--> request_count = %d", request_count);
+  #endif
+      } else if ( redir != NULL ) {
+          /* we have HTTP redirect information being sent to the application now */
+         GstMessage* m = gst_message_new_application(GST_OBJECT (src),
+             gst_structure_new ("http-redirect",
+                "do-redirect", G_TYPE_BOOLEAN, TRUE, 
+                "redirect-uri", G_TYPE_STRING, redir, NULL));
+          
+          gst_element_post_message ( GST_ELEMENT(src), m );
+
+          GST_WARNING_OBJECT (src, "Sent message with the redirect URI path (uri = %s) to the bus.", redir);
+      } /* if - send the proxy URI info to the bus */
     }
     /* do the redirect, go back to send another HTTP request now using the 'Location' */
   } while (do_redir && (request_count < MAX_HTTP_REDIRECTS_NUMBER)
