# HG changeset patch
# User renatofilho
# Date 1191867467 -3600
# Node ID ebd3aaff20e06829f03af8fd368d61128b65497d
# Parent  dda04b6cf0b2ec328a032a7f1663c0218d56715b
[svn r864] fixed bug on uri without port

diff -r dda04b6cf0b2 -r ebd3aaff20e0 gmyth/src/gmyth_backendinfo.c
--- a/gmyth/src/gmyth_backendinfo.c	Wed Sep 26 19:04:24 2007 +0100
+++ b/gmyth/src/gmyth_backendinfo.c	Mon Oct 08 19:17:47 2007 +0100
@@ -152,14 +152,13 @@
 GMythBackendInfo *
 gmyth_backend_info_new_with_uri(const gchar * uri_str)
 {
-    GMythBackendInfo *backend_info =
-        GMYTH_BACKEND_INFO(g_object_new(GMYTH_BACKEND_INFO_TYPE, NULL));
+    GMythBackendInfo *backend_info;
+    GMythURI       *uri;
+    gchar         **path_parts;
 
-    GMythURI       *uri = gmyth_uri_new_with_value(uri_str);
-
-    gchar         **path_parts =
-        g_strsplit(gmyth_uri_get_path(uri), "&", -1);
-
+    backend_info = GMYTH_BACKEND_INFO(g_object_new(GMYTH_BACKEND_INFO_TYPE, NULL));
+    uri = gmyth_uri_new_with_value (uri_str);
+    path_parts = g_strsplit(gmyth_uri_get_path(uri), "&", -1);
     gmyth_backend_info_set_hostname(backend_info, gmyth_uri_get_host(uri));
     gmyth_backend_info_set_username(backend_info, gmyth_uri_get_user(uri));
     gmyth_backend_info_set_password(backend_info,
diff -r dda04b6cf0b2 -r ebd3aaff20e0 gmyth/src/gmyth_backendinfo.h
--- a/gmyth/src/gmyth_backendinfo.h	Wed Sep 26 19:04:24 2007 +0100
+++ b/gmyth/src/gmyth_backendinfo.h	Mon Oct 08 19:17:47 2007 +0100
@@ -100,9 +100,9 @@
                                                          const gchar        *password);
 void                gmyth_backend_info_set_db_name      (GMythBackendInfo   *backend_info,
                                                          const gchar        *db_name);
-void                gmyth_backend_info_set_db_port         (GMythBackendInfo   *backend_info, 
-                                                            gint               db_port);
-void                gmyth_backend_info_set_port         (GMythBackendInfo   *backend_info, 
+void                gmyth_backend_info_set_db_port      (GMythBackendInfo   *backend_info,
+                                                         gint               db_port);
+void                gmyth_backend_info_set_port         (GMythBackendInfo   *backend_info,
                                                          gint               port);
 void                gmyth_backend_info_set_status_port  (GMythBackendInfo   *backend_info,
                                                          gint               port);
diff -r dda04b6cf0b2 -r ebd3aaff20e0 gmyth/src/gmyth_uri.c
--- a/gmyth/src/gmyth_uri.c	Wed Sep 26 19:04:24 2007 +0100
+++ b/gmyth/src/gmyth_uri.c	Mon Oct 08 19:17:47 2007 +0100
@@ -39,6 +39,33 @@
 
 #include "gmyth_debug.h"
 
+/****************************************
+* Define
+****************************************/
+
+#define GMYTH_URI_KNKOWN_PORT               (-1)
+#define GMYTH_URI_DEFAULT_HTTP_PORT         80
+#define GMYTH_URI_DEFAULT_FTP_PORT          21
+#define GMYTH_URI_DEFAULT_MYTH_PORT         6543
+#define GMYTH_URI_DEFAULT_PATH              "/"
+#define GMYTH_URI_MAXLEN                    256
+
+#define GMYTH_URI_PROTOCOL_DELIM            "://"
+#define GMYTH_URI_USER_DELIM                "@"
+#define GMYTH_URI_COLON_DELIM               ":"
+#define GMYTH_URI_SLASH_DELIM               "/"
+#define GMYTH_URI_SBLACET_DELIM             "["
+#define GMYTH_URI_EBLACET_DELIM             "]"
+#define GMYTH_URI_SHARP_DELIM               "#"
+#define GMYTH_URI_QUESTION_DELIM            "?"
+#define GMYTH_URI_E_DELIM                   "&"
+#define GMYTH_URI_ESCAPING_CHAR             "%"
+
+#define GMYTH_URI_PROTOCOL_MYTH             "myth"
+#define GMYTH_URI_PROTOCOL_HTTP             "http"
+#define GMYTH_URI_PROTOCOL_FTP              "ftp"
+
+
 static void     gmyth_uri_class_init(GMythURIClass * klass);
 static void     gmyth_uri_init(GMythURI * object);
 
@@ -248,6 +275,21 @@
         return "";
 }
 
+static gint
+gmyth_uri_get_default_port (GMythURI * uri)
+{
+    const gchar  *protocol = gmyth_uri_get_protocol(uri);
+
+    if (strcmp(protocol, GMYTH_URI_PROTOCOL_HTTP) == 0)
+        return GMYTH_URI_DEFAULT_HTTP_PORT;
+    if (strcmp(protocol, GMYTH_URI_PROTOCOL_FTP) == 0)
+        return GMYTH_URI_DEFAULT_FTP_PORT;
+    if (strcmp(protocol, GMYTH_URI_PROTOCOL_MYTH) == 0)
+        return GMYTH_URI_DEFAULT_MYTH_PORT;
+
+    return GMYTH_URI_KNKOWN_PORT;
+}
+
 /** 
  * Parses a URI string into a GMythURI instance.
  * 
@@ -327,21 +369,15 @@
                 uri->host =
                     g_string_new_len(hostStr->str + 1, colonIdx - 2);
         }
+
         /**** port ****/
-        portStr =
-            g_string_new_len(hostStr->str + colonIdx + 1,
-                             hostLen - colonIdx - 1);
+        portStr = g_string_new_len(hostStr->str + colonIdx + 1,
+                                   hostLen - colonIdx - 1);
         uri->port = (gint) g_ascii_strtoull(portStr->str, NULL, 10);
         g_string_free(portStr, TRUE);
         g_string_free(hostStr, TRUE);
     } else {
-        const gchar    *protocol = gmyth_uri_get_protocol(uri);
-
-        uri->port = GMYTH_URI_KNKOWN_PORT;
-        if (strcmp(protocol, GMYTH_URI_PROTOCOL_HTTP) == 0)
-            uri->port = GMYTH_URI_DEFAULT_HTTP_PORT;
-        if (strcmp(protocol, GMYTH_URI_PROTOCOL_FTP) == 0)
-            uri->port = GMYTH_URI_DEFAULT_FTP_PORT;
+        uri->port = gmyth_uri_get_default_port (uri);
     }
 
     if (shashIdx > 0)
diff -r dda04b6cf0b2 -r ebd3aaff20e0 gmyth/src/gmyth_uri.h
--- a/gmyth/src/gmyth_uri.h	Wed Sep 26 19:04:24 2007 +0100
+++ b/gmyth/src/gmyth_uri.h	Mon Oct 08 19:17:47 2007 +0100
@@ -46,30 +46,6 @@
 typedef struct _GMythURI GMythURI;
 typedef struct _GMythURIClass GMythURIClass;
 
-    /****************************************
-	 * Define
-	 ****************************************/
-
-#define GMYTH_URI_KNKOWN_PORT               (-1)
-#define GMYTH_URI_DEFAULT_HTTP_PORT         80
-#define GMYTH_URI_DEFAULT_FTP_PORT          21
-#define GMYTH_URI_DEFAULT_PATH 				"/"
-#define GMYTH_URI_MAXLEN 					256
-
-#define GMYTH_URI_PROTOCOL_DELIM 			"://"
-#define GMYTH_URI_USER_DELIM 					"@"
-#define GMYTH_URI_COLON_DELIM 				":"
-#define GMYTH_URI_SLASH_DELIM 				"/"
-#define GMYTH_URI_SBLACET_DELIM 			"["
-#define GMYTH_URI_EBLACET_DELIM 			"]"
-#define GMYTH_URI_SHARP_DELIM 				"#"
-#define GMYTH_URI_QUESTION_DELIM 			"?"
-#define GMYTH_URI_E_DELIM 						"&"
-#define GMYTH_URI_ESCAPING_CHAR 			"%"
-
-#define GMYTH_URI_PROTOCOL_MYTH 			"myth"
-#define GMYTH_URI_PROTOCOL_HTTP 			"http"
-#define GMYTH_URI_PROTOCOL_FTP 				"ftp"
 
     /****************************************
 	 * Data Type