[svn r864] fixed bug on uri without port trunk
authorrenatofilho
Mon Oct 08 19:17:47 2007 +0100 (2007-10-08)
branchtrunk
changeset 858ebd3aaff20e0
parent 857 dda04b6cf0b2
child 859 ae56c46c7b71
[svn r864] fixed bug on uri without port
gmyth/src/gmyth_backendinfo.c
gmyth/src/gmyth_backendinfo.h
gmyth/src/gmyth_uri.c
gmyth/src/gmyth_uri.h
     1.1 --- a/gmyth/src/gmyth_backendinfo.c	Wed Sep 26 19:04:24 2007 +0100
     1.2 +++ b/gmyth/src/gmyth_backendinfo.c	Mon Oct 08 19:17:47 2007 +0100
     1.3 @@ -152,14 +152,13 @@
     1.4  GMythBackendInfo *
     1.5  gmyth_backend_info_new_with_uri(const gchar * uri_str)
     1.6  {
     1.7 -    GMythBackendInfo *backend_info =
     1.8 -        GMYTH_BACKEND_INFO(g_object_new(GMYTH_BACKEND_INFO_TYPE, NULL));
     1.9 +    GMythBackendInfo *backend_info;
    1.10 +    GMythURI       *uri;
    1.11 +    gchar         **path_parts;
    1.12  
    1.13 -    GMythURI       *uri = gmyth_uri_new_with_value(uri_str);
    1.14 -
    1.15 -    gchar         **path_parts =
    1.16 -        g_strsplit(gmyth_uri_get_path(uri), "&", -1);
    1.17 -
    1.18 +    backend_info = GMYTH_BACKEND_INFO(g_object_new(GMYTH_BACKEND_INFO_TYPE, NULL));
    1.19 +    uri = gmyth_uri_new_with_value (uri_str);
    1.20 +    path_parts = g_strsplit(gmyth_uri_get_path(uri), "&", -1);
    1.21      gmyth_backend_info_set_hostname(backend_info, gmyth_uri_get_host(uri));
    1.22      gmyth_backend_info_set_username(backend_info, gmyth_uri_get_user(uri));
    1.23      gmyth_backend_info_set_password(backend_info,
     2.1 --- a/gmyth/src/gmyth_backendinfo.h	Wed Sep 26 19:04:24 2007 +0100
     2.2 +++ b/gmyth/src/gmyth_backendinfo.h	Mon Oct 08 19:17:47 2007 +0100
     2.3 @@ -100,9 +100,9 @@
     2.4                                                           const gchar        *password);
     2.5  void                gmyth_backend_info_set_db_name      (GMythBackendInfo   *backend_info,
     2.6                                                           const gchar        *db_name);
     2.7 -void                gmyth_backend_info_set_db_port         (GMythBackendInfo   *backend_info, 
     2.8 -                                                            gint               db_port);
     2.9 -void                gmyth_backend_info_set_port         (GMythBackendInfo   *backend_info, 
    2.10 +void                gmyth_backend_info_set_db_port      (GMythBackendInfo   *backend_info,
    2.11 +                                                         gint               db_port);
    2.12 +void                gmyth_backend_info_set_port         (GMythBackendInfo   *backend_info,
    2.13                                                           gint               port);
    2.14  void                gmyth_backend_info_set_status_port  (GMythBackendInfo   *backend_info,
    2.15                                                           gint               port);
     3.1 --- a/gmyth/src/gmyth_uri.c	Wed Sep 26 19:04:24 2007 +0100
     3.2 +++ b/gmyth/src/gmyth_uri.c	Mon Oct 08 19:17:47 2007 +0100
     3.3 @@ -39,6 +39,33 @@
     3.4  
     3.5  #include "gmyth_debug.h"
     3.6  
     3.7 +/****************************************
     3.8 +* Define
     3.9 +****************************************/
    3.10 +
    3.11 +#define GMYTH_URI_KNKOWN_PORT               (-1)
    3.12 +#define GMYTH_URI_DEFAULT_HTTP_PORT         80
    3.13 +#define GMYTH_URI_DEFAULT_FTP_PORT          21
    3.14 +#define GMYTH_URI_DEFAULT_MYTH_PORT         6543
    3.15 +#define GMYTH_URI_DEFAULT_PATH              "/"
    3.16 +#define GMYTH_URI_MAXLEN                    256
    3.17 +
    3.18 +#define GMYTH_URI_PROTOCOL_DELIM            "://"
    3.19 +#define GMYTH_URI_USER_DELIM                "@"
    3.20 +#define GMYTH_URI_COLON_DELIM               ":"
    3.21 +#define GMYTH_URI_SLASH_DELIM               "/"
    3.22 +#define GMYTH_URI_SBLACET_DELIM             "["
    3.23 +#define GMYTH_URI_EBLACET_DELIM             "]"
    3.24 +#define GMYTH_URI_SHARP_DELIM               "#"
    3.25 +#define GMYTH_URI_QUESTION_DELIM            "?"
    3.26 +#define GMYTH_URI_E_DELIM                   "&"
    3.27 +#define GMYTH_URI_ESCAPING_CHAR             "%"
    3.28 +
    3.29 +#define GMYTH_URI_PROTOCOL_MYTH             "myth"
    3.30 +#define GMYTH_URI_PROTOCOL_HTTP             "http"
    3.31 +#define GMYTH_URI_PROTOCOL_FTP              "ftp"
    3.32 +
    3.33 +
    3.34  static void     gmyth_uri_class_init(GMythURIClass * klass);
    3.35  static void     gmyth_uri_init(GMythURI * object);
    3.36  
    3.37 @@ -248,6 +275,21 @@
    3.38          return "";
    3.39  }
    3.40  
    3.41 +static gint
    3.42 +gmyth_uri_get_default_port (GMythURI * uri)
    3.43 +{
    3.44 +    const gchar  *protocol = gmyth_uri_get_protocol(uri);
    3.45 +
    3.46 +    if (strcmp(protocol, GMYTH_URI_PROTOCOL_HTTP) == 0)
    3.47 +        return GMYTH_URI_DEFAULT_HTTP_PORT;
    3.48 +    if (strcmp(protocol, GMYTH_URI_PROTOCOL_FTP) == 0)
    3.49 +        return GMYTH_URI_DEFAULT_FTP_PORT;
    3.50 +    if (strcmp(protocol, GMYTH_URI_PROTOCOL_MYTH) == 0)
    3.51 +        return GMYTH_URI_DEFAULT_MYTH_PORT;
    3.52 +
    3.53 +    return GMYTH_URI_KNKOWN_PORT;
    3.54 +}
    3.55 +
    3.56  /** 
    3.57   * Parses a URI string into a GMythURI instance.
    3.58   * 
    3.59 @@ -327,21 +369,15 @@
    3.60                  uri->host =
    3.61                      g_string_new_len(hostStr->str + 1, colonIdx - 2);
    3.62          }
    3.63 +
    3.64          /**** port ****/
    3.65 -        portStr =
    3.66 -            g_string_new_len(hostStr->str + colonIdx + 1,
    3.67 -                             hostLen - colonIdx - 1);
    3.68 +        portStr = g_string_new_len(hostStr->str + colonIdx + 1,
    3.69 +                                   hostLen - colonIdx - 1);
    3.70          uri->port = (gint) g_ascii_strtoull(portStr->str, NULL, 10);
    3.71          g_string_free(portStr, TRUE);
    3.72          g_string_free(hostStr, TRUE);
    3.73      } else {
    3.74 -        const gchar    *protocol = gmyth_uri_get_protocol(uri);
    3.75 -
    3.76 -        uri->port = GMYTH_URI_KNKOWN_PORT;
    3.77 -        if (strcmp(protocol, GMYTH_URI_PROTOCOL_HTTP) == 0)
    3.78 -            uri->port = GMYTH_URI_DEFAULT_HTTP_PORT;
    3.79 -        if (strcmp(protocol, GMYTH_URI_PROTOCOL_FTP) == 0)
    3.80 -            uri->port = GMYTH_URI_DEFAULT_FTP_PORT;
    3.81 +        uri->port = gmyth_uri_get_default_port (uri);
    3.82      }
    3.83  
    3.84      if (shashIdx > 0)
     4.1 --- a/gmyth/src/gmyth_uri.h	Wed Sep 26 19:04:24 2007 +0100
     4.2 +++ b/gmyth/src/gmyth_uri.h	Mon Oct 08 19:17:47 2007 +0100
     4.3 @@ -46,30 +46,6 @@
     4.4  typedef struct _GMythURI GMythURI;
     4.5  typedef struct _GMythURIClass GMythURIClass;
     4.6  
     4.7 -    /****************************************
     4.8 -	 * Define
     4.9 -	 ****************************************/
    4.10 -
    4.11 -#define GMYTH_URI_KNKOWN_PORT               (-1)
    4.12 -#define GMYTH_URI_DEFAULT_HTTP_PORT         80
    4.13 -#define GMYTH_URI_DEFAULT_FTP_PORT          21
    4.14 -#define GMYTH_URI_DEFAULT_PATH 				"/"
    4.15 -#define GMYTH_URI_MAXLEN 					256
    4.16 -
    4.17 -#define GMYTH_URI_PROTOCOL_DELIM 			"://"
    4.18 -#define GMYTH_URI_USER_DELIM 					"@"
    4.19 -#define GMYTH_URI_COLON_DELIM 				":"
    4.20 -#define GMYTH_URI_SLASH_DELIM 				"/"
    4.21 -#define GMYTH_URI_SBLACET_DELIM 			"["
    4.22 -#define GMYTH_URI_EBLACET_DELIM 			"]"
    4.23 -#define GMYTH_URI_SHARP_DELIM 				"#"
    4.24 -#define GMYTH_URI_QUESTION_DELIM 			"?"
    4.25 -#define GMYTH_URI_E_DELIM 						"&"
    4.26 -#define GMYTH_URI_ESCAPING_CHAR 			"%"
    4.27 -
    4.28 -#define GMYTH_URI_PROTOCOL_MYTH 			"myth"
    4.29 -#define GMYTH_URI_PROTOCOL_HTTP 			"http"
    4.30 -#define GMYTH_URI_PROTOCOL_FTP 				"ftp"
    4.31  
    4.32      /****************************************
    4.33  	 * Data Type