gmyth/src/gmyth_uri.c
branchtrunk
changeset 701 2f28edb4d804
parent 698 9019388af980
child 750 312d6bc514f3
     1.1 --- a/gmyth/src/gmyth_uri.c	Wed May 23 16:11:29 2007 +0100
     1.2 +++ b/gmyth/src/gmyth_uri.c	Wed May 23 19:50:41 2007 +0100
     1.3 @@ -10,22 +10,21 @@
     1.4   * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia.
     1.5   * @author Rosfran Borges <rosfran.borges@indt.org.br>
     1.6   *
     1.7 -                                                                                                                                                                                                                                                                                                                                                                                              *//*
     1.8 -                                                                                                                                                                                                 * 
     1.9 -                                                                                                                                                                                                 * This program is free software; you can redistribute it and/or modify
    1.10 -                                                                                                                                                                                                 * it under the terms of the GNU Lesser General Public License as published by
    1.11 -                                                                                                                                                                                                 * the Free Software Foundation; either version 2 of the License, or
    1.12 -                                                                                                                                                                                                 * (at your option) any later version.
    1.13 -                                                                                                                                                                                                 *
    1.14 -                                                                                                                                                                                                 * This program is distributed in the hope that it will be useful,
    1.15 -                                                                                                                                                                                                 * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.16 -                                                                                                                                                                                                 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.17 -                                                                                                                                                                                                 * GNU General Public License for more details.
    1.18 -                                                                                                                                                                                                 *
    1.19 -                                                                                                                                                                                                 * You should have received a copy of the GNU Lesser General Public License
    1.20 -                                                                                                                                                                                                 * along with this program; if not, write to the Free Software
    1.21 -                                                                                                                                                                                                 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.22 -                                                                                                                                                                                                 */
    1.23 + * 
    1.24 + * This program is free software; you can redistribute it and/or modify
    1.25 + * it under the terms of the GNU Lesser General Public License as published by
    1.26 + * the Free Software Foundation; either version 2 of the License, or
    1.27 + * (at your option) any later version.
    1.28 + *
    1.29 + * This program is distributed in the hope that it will be useful,
    1.30 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.31 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.32 + * GNU General Public License for more details.
    1.33 + *
    1.34 + * You should have received a copy of the GNU Lesser General Public License
    1.35 + * along with this program; if not, write to the Free Software
    1.36 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.37 + */
    1.38  
    1.39  #ifdef HAVE_CONFIG_H
    1.40  #include "config.h"
    1.41 @@ -40,89 +39,97 @@
    1.42  
    1.43  #include "gmyth_debug.h"
    1.44  
    1.45 -static void gmyth_uri_class_init (GMythURIClass * klass);
    1.46 -static void gmyth_uri_init (GMythURI * object);
    1.47 +static void gmyth_uri_class_init ( GMythURIClass * klass );
    1.48 +static void gmyth_uri_init ( GMythURI * object );
    1.49  
    1.50 -static void gmyth_uri_dispose (GObject * object);
    1.51 -static void gmyth_uri_finalize (GObject * object);
    1.52 +static void gmyth_uri_dispose ( GObject * object );
    1.53 +static void gmyth_uri_finalize ( GObject * object );
    1.54  
    1.55 -static void gmyth_uri_parser_setup_and_new (GMythURI * uri,
    1.56 -    const gchar * value);
    1.57 -static gchar *gmyth_uri_print_field (const GString * field);
    1.58 +static void gmyth_uri_parser_setup_and_new ( GMythURI * uri,
    1.59 +                                             const gchar * value );
    1.60 +static gchar *gmyth_uri_print_field ( const GString * field );
    1.61  
    1.62 -G_DEFINE_TYPE (GMythURI, gmyth_uri, G_TYPE_OBJECT)
    1.63 -     static void gmyth_uri_class_init (GMythURIClass * klass)
    1.64 +G_DEFINE_TYPE ( GMythURI, gmyth_uri, G_TYPE_OBJECT )
    1.65 +     static void gmyth_uri_class_init ( GMythURIClass * klass )
    1.66  {
    1.67      GObjectClass *gobject_class;
    1.68  
    1.69 -    gobject_class = (GObjectClass *) klass;
    1.70 +    gobject_class = ( GObjectClass * ) klass;
    1.71  
    1.72      gobject_class->dispose = gmyth_uri_dispose;
    1.73      gobject_class->finalize = gmyth_uri_finalize;
    1.74  }
    1.75  
    1.76  static void
    1.77 -gmyth_uri_init (GMythURI * gmyth_uri)
    1.78 +gmyth_uri_init ( GMythURI * gmyth_uri )
    1.79  {
    1.80  }
    1.81  
    1.82  static void
    1.83 -gmyth_uri_dispose (GObject * object)
    1.84 +gmyth_uri_dispose ( GObject * object )
    1.85  {
    1.86 -    GMythURI *gmyth_uri = GMYTH_URI (object);
    1.87 +    GMythURI *gmyth_uri = GMYTH_URI ( object );
    1.88  
    1.89 -    if (gmyth_uri->host != NULL) {
    1.90 -        g_string_free (gmyth_uri->host, TRUE);
    1.91 +    if ( gmyth_uri->host != NULL )
    1.92 +    {
    1.93 +        g_string_free ( gmyth_uri->host, TRUE );
    1.94          gmyth_uri->host = NULL;
    1.95      }
    1.96  
    1.97 -    if (gmyth_uri->protocol != NULL) {
    1.98 -        g_string_free (gmyth_uri->protocol, TRUE);
    1.99 +    if ( gmyth_uri->protocol != NULL )
   1.100 +    {
   1.101 +        g_string_free ( gmyth_uri->protocol, TRUE );
   1.102          gmyth_uri->protocol = NULL;
   1.103      }
   1.104  
   1.105 -    if (gmyth_uri->path != NULL) {
   1.106 -        g_string_free (gmyth_uri->path, TRUE);
   1.107 +    if ( gmyth_uri->path != NULL )
   1.108 +    {
   1.109 +        g_string_free ( gmyth_uri->path, TRUE );
   1.110          gmyth_uri->path = NULL;
   1.111      }
   1.112  
   1.113 -    if (gmyth_uri->fragment != NULL) {
   1.114 -        g_string_free (gmyth_uri->fragment, TRUE);
   1.115 +    if ( gmyth_uri->fragment != NULL )
   1.116 +    {
   1.117 +        g_string_free ( gmyth_uri->fragment, TRUE );
   1.118          gmyth_uri->fragment = NULL;
   1.119      }
   1.120  
   1.121 -    if (gmyth_uri->user != NULL) {
   1.122 -        g_string_free (gmyth_uri->user, TRUE);
   1.123 +    if ( gmyth_uri->user != NULL )
   1.124 +    {
   1.125 +        g_string_free ( gmyth_uri->user, TRUE );
   1.126          gmyth_uri->user = NULL;
   1.127      }
   1.128  
   1.129 -    if (gmyth_uri->password != NULL) {
   1.130 -        g_string_free (gmyth_uri->password, TRUE);
   1.131 +    if ( gmyth_uri->password != NULL )
   1.132 +    {
   1.133 +        g_string_free ( gmyth_uri->password, TRUE );
   1.134          gmyth_uri->password = NULL;
   1.135      }
   1.136  
   1.137 -    if (gmyth_uri->query != NULL) {
   1.138 -        g_string_free (gmyth_uri->query, TRUE);
   1.139 +    if ( gmyth_uri->query != NULL )
   1.140 +    {
   1.141 +        g_string_free ( gmyth_uri->query, TRUE );
   1.142          gmyth_uri->query = NULL;
   1.143      }
   1.144  
   1.145 -    if (gmyth_uri->uri != NULL) {
   1.146 -        g_string_free (gmyth_uri->uri, TRUE);
   1.147 +    if ( gmyth_uri->uri != NULL )
   1.148 +    {
   1.149 +        g_string_free ( gmyth_uri->uri, TRUE );
   1.150          gmyth_uri->uri = NULL;
   1.151      }
   1.152  
   1.153  
   1.154 -    G_OBJECT_CLASS (gmyth_uri_parent_class)->dispose (object);
   1.155 +    G_OBJECT_CLASS ( gmyth_uri_parent_class )->dispose ( object );
   1.156  }
   1.157  
   1.158  static void
   1.159 -gmyth_uri_finalize (GObject * object)
   1.160 +gmyth_uri_finalize ( GObject * object )
   1.161  {
   1.162      //GMythURI *gmyth_uri = GMYTH_URI(object);
   1.163  
   1.164 -    g_signal_handlers_destroy (object);
   1.165 +    g_signal_handlers_destroy ( object );
   1.166  
   1.167 -    G_OBJECT_CLASS (gmyth_uri_parent_class)->finalize (object);
   1.168 +    G_OBJECT_CLASS ( gmyth_uri_parent_class )->finalize ( object );
   1.169  }
   1.170  
   1.171  /** 
   1.172 @@ -131,9 +138,9 @@
   1.173   * @return a new instance of GMythURI.
   1.174   */
   1.175  GMythURI *
   1.176 -gmyth_uri_new (void)
   1.177 +gmyth_uri_new ( void )
   1.178  {
   1.179 -    GMythURI *gmyth_uri = GMYTH_URI (g_object_new (GMYTH_URI_TYPE, NULL));
   1.180 +    GMythURI *gmyth_uri = GMYTH_URI ( g_object_new ( GMYTH_URI_TYPE, NULL ) );
   1.181  
   1.182      return gmyth_uri;
   1.183  }
   1.184 @@ -146,11 +153,11 @@
   1.185   * @return a new instance of GMythURI.
   1.186   */
   1.187  GMythURI *
   1.188 -gmyth_uri_new_with_value (const gchar * uri_str)
   1.189 +gmyth_uri_new_with_value ( const gchar * uri_str )
   1.190  {
   1.191 -    GMythURI *gmyth_uri = GMYTH_URI (g_object_new (GMYTH_URI_TYPE, NULL));
   1.192 +    GMythURI *gmyth_uri = GMYTH_URI ( g_object_new ( GMYTH_URI_TYPE, NULL ) );
   1.193  
   1.194 -    gmyth_uri_parser_setup_and_new (gmyth_uri, uri_str);
   1.195 +    gmyth_uri_parser_setup_and_new ( gmyth_uri, uri_str );
   1.196  
   1.197      return gmyth_uri;
   1.198  }
   1.199 @@ -165,18 +172,18 @@
   1.200   * 				 haystack function parameter doesn't contains the needle string argument.
   1.201   */
   1.202  static gint
   1.203 -gmyth_strstr (const gchar * haystack, const gchar * needle)
   1.204 +gmyth_strstr ( const gchar * haystack, const gchar * needle )
   1.205  {
   1.206  
   1.207      gchar *strPos;
   1.208  
   1.209 -    if (haystack == NULL || needle == NULL)
   1.210 +    if ( haystack == NULL || needle == NULL )
   1.211          return -1;
   1.212 -    strPos = strstr (haystack, needle);
   1.213 -    if (strPos == NULL)
   1.214 +    strPos = strstr ( haystack, needle );
   1.215 +    if ( strPos == NULL )
   1.216          return -1;
   1.217  
   1.218 -    return (strPos - haystack);
   1.219 +    return ( strPos - haystack );
   1.220  
   1.221  }
   1.222  
   1.223 @@ -188,15 +195,15 @@
   1.224   * @return <code>true</code>, if the URI is absolute.
   1.225   */
   1.226  static gboolean
   1.227 -gmyth_uri_isabsolute (const GMythURI * uri)
   1.228 +gmyth_uri_isabsolute ( const GMythURI * uri )
   1.229  {
   1.230      gboolean ret = FALSE;
   1.231  
   1.232 -    g_return_val_if_fail (uri != NULL && uri->uri != NULL
   1.233 -        && uri->protocol != NULL, FALSE);
   1.234 +    g_return_val_if_fail ( uri != NULL && uri->uri != NULL
   1.235 +                           && uri->protocol != NULL, FALSE );
   1.236  
   1.237 -    if (gmyth_strstr (uri->uri->str, GMYTH_URI_PROTOCOL_DELIM) == 0
   1.238 -        || strlen (uri->protocol->str) > 0)
   1.239 +    if ( gmyth_strstr ( uri->uri->str, GMYTH_URI_PROTOCOL_DELIM ) == 0
   1.240 +         || strlen ( uri->protocol->str ) > 0 )
   1.241          ret = TRUE;
   1.242  
   1.243      return ret;
   1.244 @@ -216,19 +223,21 @@
   1.245   *         or <code>-1</code> if the no character of the list could be found.
   1.246   */
   1.247  static gint
   1.248 -gmyth_strrchr (const gchar * str, const gchar * chars, const gint nchars)
   1.249 +gmyth_strrchr ( const gchar * str, const gchar * chars, const gint nchars )
   1.250  {
   1.251  
   1.252      gint strLen;
   1.253      gint i, j;
   1.254  
   1.255 -    if (str == NULL || chars == NULL)
   1.256 +    if ( str == NULL || chars == NULL )
   1.257          return -1;
   1.258  
   1.259 -    strLen = strlen (str);
   1.260 -    for (i = (strLen - 1); 0 <= i; i--) {
   1.261 -        for (j = 0; j < nchars; j++) {
   1.262 -            if (str[i] == chars[j])
   1.263 +    strLen = strlen ( str );
   1.264 +    for ( i = ( strLen - 1 ); 0 <= i; i-- )
   1.265 +    {
   1.266 +        for ( j = 0; j < nchars; j++ )
   1.267 +        {
   1.268 +            if ( str[i] == chars[j] )
   1.269                  return i;
   1.270          }
   1.271      }
   1.272 @@ -238,9 +247,9 @@
   1.273  }
   1.274  
   1.275  static gchar *
   1.276 -gmyth_uri_print_field (const GString * field)
   1.277 +gmyth_uri_print_field ( const GString * field )
   1.278  {
   1.279 -    if (field != NULL && field->str != NULL && strlen (field->str) > 0)
   1.280 +    if ( field != NULL && field->str != NULL && strlen ( field->str ) > 0 )
   1.281          return field->str;
   1.282      else
   1.283          return "";
   1.284 @@ -254,7 +263,7 @@
   1.285   *
   1.286   */
   1.287  static void
   1.288 -gmyth_uri_parser_setup_and_new (GMythURI * uri, const gchar * value)
   1.289 +gmyth_uri_parser_setup_and_new ( GMythURI * uri, const gchar * value )
   1.290  {
   1.291  
   1.292      gint uriLen;
   1.293 @@ -274,126 +283,143 @@
   1.294         gint                 queryLen;
   1.295       */
   1.296  
   1.297 -    uriLen = strlen (value);
   1.298 -    uri->uri = g_string_new (value);
   1.299 +    uriLen = strlen ( value );
   1.300 +    uri->uri = g_string_new ( value );
   1.301  
   1.302      currIdx = 0;
   1.303  
   1.304 -        /*** Protocol ****/
   1.305 -    protoIdx = gmyth_strstr (value, GMYTH_URI_PROTOCOL_DELIM);
   1.306 -    if (0 < protoIdx) {
   1.307 -        uri->protocol = g_string_new_len (value, protoIdx);
   1.308 -        currIdx += protoIdx + strlen (GMYTH_URI_PROTOCOL_DELIM);
   1.309 +    /*** Protocol ****/
   1.310 +    protoIdx = gmyth_strstr ( value, GMYTH_URI_PROTOCOL_DELIM );
   1.311 +    if ( 0 < protoIdx )
   1.312 +    {
   1.313 +        uri->protocol = g_string_new_len ( value, protoIdx );
   1.314 +        currIdx += protoIdx + strlen ( GMYTH_URI_PROTOCOL_DELIM );
   1.315      }
   1.316  
   1.317 -        /*** User (Password) ****/
   1.318 -    atIdx = gmyth_strstr (value + currIdx, GMYTH_URI_USER_DELIM);
   1.319 -    if (0 < atIdx) {
   1.320 -        colonIdx = gmyth_strstr (value + currIdx, GMYTH_URI_COLON_DELIM);
   1.321 +    /*** User (Password) ****/
   1.322 +    atIdx = gmyth_strstr ( value + currIdx, GMYTH_URI_USER_DELIM );
   1.323 +    if ( 0 < atIdx )
   1.324 +    {
   1.325 +        colonIdx = gmyth_strstr ( value + currIdx, GMYTH_URI_COLON_DELIM );
   1.326  
   1.327 -        if (0 < colonIdx && colonIdx < atIdx) {
   1.328 -            uri->user = g_string_new_len (value + currIdx, colonIdx);
   1.329 +        if ( 0 < colonIdx && colonIdx < atIdx )
   1.330 +        {
   1.331 +            uri->user = g_string_new_len ( value + currIdx, colonIdx );
   1.332              uri->password =
   1.333 -                g_string_new_len (value + currIdx + colonIdx + 1,
   1.334 -                atIdx - (colonIdx + 1));
   1.335 -        } else
   1.336 -            uri->user = g_string_new_len (value + currIdx, atIdx - currIdx);
   1.337 +                g_string_new_len ( value + currIdx + colonIdx + 1,
   1.338 +                                   atIdx - ( colonIdx + 1 ) );
   1.339 +        }
   1.340 +        else
   1.341 +            uri->user = g_string_new_len ( value + currIdx, atIdx - currIdx );
   1.342          currIdx += atIdx + 1;
   1.343      }
   1.344  
   1.345 -        /*** Host (Port) ****/
   1.346 -    shashIdx = gmyth_strstr (value + currIdx, GMYTH_URI_SLASH_DELIM);
   1.347 -    if (0 < shashIdx)
   1.348 -        uri->host = g_string_new_len (value + currIdx, shashIdx);
   1.349 -    else if (gmyth_uri_isabsolute (uri) == TRUE)
   1.350 +    /*** Host (Port) ****/
   1.351 +    shashIdx = gmyth_strstr ( value + currIdx, GMYTH_URI_SLASH_DELIM );
   1.352 +    if ( 0 < shashIdx )
   1.353 +        uri->host = g_string_new_len ( value + currIdx, shashIdx );
   1.354 +    else if ( gmyth_uri_isabsolute ( uri ) == TRUE )
   1.355          uri->host =
   1.356 -            g_string_new_len (value + currIdx, strlen (value) - currIdx);
   1.357 +            g_string_new_len ( value + currIdx, strlen ( value ) - currIdx );
   1.358  
   1.359 -    host = gmyth_uri_get_host (uri);
   1.360 -    colonIdx = gmyth_strrchr (host, GMYTH_URI_COLON_DELIM, 1);
   1.361 -    eblacketIdx = gmyth_strrchr (host, GMYTH_URI_EBLACET_DELIM, 1);
   1.362 -    if ((0 < colonIdx) && (eblacketIdx < colonIdx)) {
   1.363 +    host = gmyth_uri_get_host ( uri );
   1.364 +    colonIdx = gmyth_strrchr ( host, GMYTH_URI_COLON_DELIM, 1 );
   1.365 +    eblacketIdx = gmyth_strrchr ( host, GMYTH_URI_EBLACET_DELIM, 1 );
   1.366 +    if ( ( 0 < colonIdx ) && ( eblacketIdx < colonIdx ) )
   1.367 +    {
   1.368          GString *portStr = NULL;
   1.369 -        GString *hostStr = g_string_new (host != NULL ? host : "");
   1.370 +        GString *hostStr = g_string_new ( host != NULL ? host : "" );
   1.371  
   1.372          hostLen = hostStr->len;
   1.373 -                /**** host ****/
   1.374 -        uri->host = g_string_erase (uri->host, 0, hostLen);
   1.375 -        uri->host = g_string_insert_len (uri->host, 0, hostStr->str, colonIdx);
   1.376 -        if (0 < hostLen) {
   1.377 -            if (host[0] == '[' && host[hostLen - 1] == ']')
   1.378 -                uri->host = g_string_new_len (hostStr->str + 1, colonIdx - 2);
   1.379 +        /**** host ****/
   1.380 +        uri->host = g_string_erase ( uri->host, 0, hostLen );
   1.381 +        uri->host =
   1.382 +            g_string_insert_len ( uri->host, 0, hostStr->str, colonIdx );
   1.383 +        if ( 0 < hostLen )
   1.384 +        {
   1.385 +            if ( host[0] == '[' && host[hostLen - 1] == ']' )
   1.386 +                uri->host = g_string_new_len ( hostStr->str + 1, colonIdx - 2 );
   1.387          }
   1.388 -                /**** port ****/
   1.389 +        /**** port ****/
   1.390          portStr =
   1.391 -            g_string_new_len (hostStr->str + colonIdx + 1,
   1.392 -            hostLen - colonIdx - 1);
   1.393 -        uri->port = (gint) g_ascii_strtoull (portStr->str, NULL, 10);
   1.394 -        g_string_free (portStr, TRUE);
   1.395 -        g_string_free (hostStr, TRUE);
   1.396 -    } else {
   1.397 -        const gchar *protocol = gmyth_uri_get_protocol (uri);
   1.398 +            g_string_new_len ( hostStr->str + colonIdx + 1,
   1.399 +                               hostLen - colonIdx - 1 );
   1.400 +        uri->port = ( gint ) g_ascii_strtoull ( portStr->str, NULL, 10 );
   1.401 +        g_string_free ( portStr, TRUE );
   1.402 +        g_string_free ( hostStr, TRUE );
   1.403 +    }
   1.404 +    else
   1.405 +    {
   1.406 +        const gchar *protocol = gmyth_uri_get_protocol ( uri );
   1.407  
   1.408          uri->port = GMYTH_URI_KNKOWN_PORT;
   1.409 -        if (strcmp (protocol, GMYTH_URI_PROTOCOL_HTTP) == 0)
   1.410 +        if ( strcmp ( protocol, GMYTH_URI_PROTOCOL_HTTP ) == 0 )
   1.411              uri->port = GMYTH_URI_DEFAULT_HTTP_PORT;
   1.412 -        if (strcmp (protocol, GMYTH_URI_PROTOCOL_FTP) == 0)
   1.413 +        if ( strcmp ( protocol, GMYTH_URI_PROTOCOL_FTP ) == 0 )
   1.414              uri->port = GMYTH_URI_DEFAULT_FTP_PORT;
   1.415      }
   1.416  
   1.417 -    if (shashIdx > 0)
   1.418 +    if ( shashIdx > 0 )
   1.419          currIdx += shashIdx;
   1.420  
   1.421      /*
   1.422         Handle relative URL
   1.423       */
   1.424 -    if (gmyth_uri_isabsolute (uri) == FALSE) {
   1.425 +    if ( gmyth_uri_isabsolute ( uri ) == FALSE )
   1.426 +    {
   1.427  
   1.428 -        if (shashIdx != 0) {
   1.429 +        if ( shashIdx != 0 )
   1.430 +        {
   1.431              /* Add slash delimiter at the beginning of the URL,
   1.432                 if it doesn't exist 
   1.433               */
   1.434 -            uri->path = g_string_new (GMYTH_URI_SLASH_DELIM);
   1.435 +            uri->path = g_string_new ( GMYTH_URI_SLASH_DELIM );
   1.436          }
   1.437 -        uri->path = g_string_append (uri->path, value);
   1.438 +        uri->path = g_string_append ( uri->path, value );
   1.439  
   1.440 -    } else {
   1.441 +    }
   1.442 +    else
   1.443 +    {
   1.444          /* First set path simply to the rest of URI */
   1.445 -        uri->path = g_string_new_len (value + currIdx, uriLen - currIdx);
   1.446 +        uri->path = g_string_new_len ( value + currIdx, uriLen - currIdx );
   1.447      }
   1.448  
   1.449      //gmyth_debug( "uri value:  %s", value );
   1.450      uri->query =
   1.451 -        g_string_new (g_strstr_len
   1.452 -        (value, strlen (value), GMYTH_URI_QUESTION_DELIM));
   1.453 +        g_string_new ( g_strstr_len
   1.454 +                       ( value, strlen ( value ), GMYTH_URI_QUESTION_DELIM ) );
   1.455  
   1.456 -    eIdx = gmyth_strstr (value + currIdx, GMYTH_URI_QUESTION_DELIM);
   1.457 +    eIdx = gmyth_strstr ( value + currIdx, GMYTH_URI_QUESTION_DELIM );
   1.458  
   1.459 -    if (0 < eIdx) {
   1.460 +    if ( 0 < eIdx )
   1.461 +    {
   1.462          uri->query =
   1.463 -            g_string_new (g_strstr_len
   1.464 -            (value, strlen (value), GMYTH_URI_QUESTION_DELIM));
   1.465 -        gmyth_debug ("query = %s", uri->query->str);
   1.466 +            g_string_new ( g_strstr_len
   1.467 +                           ( value, strlen ( value ),
   1.468 +                             GMYTH_URI_QUESTION_DELIM ) );
   1.469 +        gmyth_debug ( "query = %s", uri->query->str );
   1.470      }
   1.471  
   1.472 -        /**** Path (Query/Fragment) ****/
   1.473 -    sharpIdx = gmyth_strstr (value + currIdx, GMYTH_URI_E_DELIM);
   1.474 -    if (0 < sharpIdx) {
   1.475 -        uri->path = g_string_append_len (uri->path, value + currIdx, sharpIdx);
   1.476 +    /**** Path (Query/Fragment) ****/
   1.477 +    sharpIdx = gmyth_strstr ( value + currIdx, GMYTH_URI_E_DELIM );
   1.478 +    if ( 0 < sharpIdx )
   1.479 +    {
   1.480 +        uri->path =
   1.481 +            g_string_append_len ( uri->path, value + currIdx, sharpIdx );
   1.482          uri->fragment =
   1.483 -            g_string_new_len (value + currIdx + sharpIdx + 1,
   1.484 -            uriLen - (currIdx + sharpIdx + 1));
   1.485 +            g_string_new_len ( value + currIdx + sharpIdx + 1,
   1.486 +                               uriLen - ( currIdx + sharpIdx + 1 ) );
   1.487      }
   1.488  
   1.489      gmyth_debug
   1.490 -        ("[%s] GMythURI: host = %s, port = %d, path = %s, query = %s, fragment = %s, "
   1.491 -        "user = %s, password = %s.\n", __FUNCTION__,
   1.492 -        gmyth_uri_print_field (uri->host), uri->port,
   1.493 -        gmyth_uri_print_field (uri->path),
   1.494 -        gmyth_uri_print_field (uri->query),
   1.495 -        gmyth_uri_print_field (uri->fragment),
   1.496 -        gmyth_uri_print_field (uri->user),
   1.497 -        gmyth_uri_print_field (uri->password));
   1.498 +        ( "[%s] GMythURI: host = %s, port = %d, path = %s, query = %s, fragment = %s, "
   1.499 +          "user = %s, password = %s.\n", __FUNCTION__,
   1.500 +          gmyth_uri_print_field ( uri->host ), uri->port,
   1.501 +          gmyth_uri_print_field ( uri->path ),
   1.502 +          gmyth_uri_print_field ( uri->query ),
   1.503 +          gmyth_uri_print_field ( uri->fragment ),
   1.504 +          gmyth_uri_print_field ( uri->user ),
   1.505 +          gmyth_uri_print_field ( uri->password ) );
   1.506  
   1.507  }
   1.508  
   1.509 @@ -406,11 +432,11 @@
   1.510   * @return <code>true</code>, if these two URI instances are equals.
   1.511   */
   1.512  gboolean
   1.513 -gmyth_uri_is_equals (GMythURI * uri1, GMythURI * uri2)
   1.514 +gmyth_uri_is_equals ( GMythURI * uri1, GMythURI * uri2 )
   1.515  {
   1.516 -    return (g_ascii_strcasecmp
   1.517 -        (gmyth_uri_get_host (uri1), gmyth_uri_get_host (uri2)) == 0
   1.518 -        && gmyth_uri_get_port (uri1) == gmyth_uri_get_port (uri2));
   1.519 +    return ( g_ascii_strcasecmp
   1.520 +             ( gmyth_uri_get_host ( uri1 ), gmyth_uri_get_host ( uri2 ) ) == 0
   1.521 +             && gmyth_uri_get_port ( uri1 ) == gmyth_uri_get_port ( uri2 ) );
   1.522  }
   1.523  
   1.524  /** 
   1.525 @@ -421,22 +447,22 @@
   1.526   * @return <code>true</code>, if the URI points to LiveTV content.
   1.527   */
   1.528  gboolean
   1.529 -gmyth_uri_is_livetv (GMythURI * uri)
   1.530 +gmyth_uri_is_livetv ( GMythURI * uri )
   1.531  {
   1.532      gboolean ret = TRUE;
   1.533  
   1.534 -    g_return_val_if_fail (uri != NULL, FALSE);
   1.535 -    g_return_val_if_fail (uri->uri != NULL, FALSE);
   1.536 -    g_return_val_if_fail (uri->uri->str != NULL, FALSE);
   1.537 +    g_return_val_if_fail ( uri != NULL, FALSE );
   1.538 +    g_return_val_if_fail ( uri->uri != NULL, FALSE );
   1.539 +    g_return_val_if_fail ( uri->uri->str != NULL, FALSE );
   1.540  
   1.541 -    if ((strstr (uri->uri->str, "channel") == NULL) ||
   1.542 -        (strstr (uri->uri->str, "livetv") == NULL))
   1.543 +    if ( ( strstr ( uri->uri->str, "channel" ) == NULL ) ||
   1.544 +         ( strstr ( uri->uri->str, "livetv" ) == NULL ) )
   1.545          ret = FALSE;
   1.546  
   1.547 -    if (ret)
   1.548 -        gmyth_debug ("This URI is a LiveTV recording...");
   1.549 +    if ( ret )
   1.550 +        gmyth_debug ( "This URI is a LiveTV recording..." );
   1.551      else
   1.552 -        gmyth_debug ("This URI is a stored remote recording.");
   1.553 +        gmyth_debug ( "This URI is a stored remote recording." );
   1.554  
   1.555      return ret;
   1.556  
   1.557 @@ -451,31 +477,35 @@
   1.558   * 				 of the URI string.
   1.559   */
   1.560  gchar *
   1.561 -gmyth_uri_get_channel_name (GMythURI * uri)
   1.562 +gmyth_uri_get_channel_name ( GMythURI * uri )
   1.563  {
   1.564      gchar *channel = NULL;
   1.565  
   1.566 -    g_return_val_if_fail (uri != NULL && uri->uri != NULL
   1.567 -        && uri->uri->str != NULL, FALSE);
   1.568 +    g_return_val_if_fail ( uri != NULL && uri->uri != NULL
   1.569 +                           && uri->uri->str != NULL, FALSE );
   1.570  
   1.571 -    gchar *channel_query = g_strstr_len (gmyth_uri_get_query (uri),
   1.572 -        strlen (gmyth_uri_get_query (uri)),
   1.573 -        "channel");
   1.574 +    gchar *channel_query = g_strstr_len ( gmyth_uri_get_query ( uri ),
   1.575 +                                          strlen ( gmyth_uri_get_query
   1.576 +                                                   ( uri ) ),
   1.577 +                                          "channel" );
   1.578  
   1.579 -    if (channel_query != NULL) {
   1.580 -        gchar **chan_key_value = g_strsplit (gmyth_uri_get_query (uri), "=", 2);
   1.581 +    if ( channel_query != NULL )
   1.582 +    {
   1.583 +        gchar **chan_key_value =
   1.584 +            g_strsplit ( gmyth_uri_get_query ( uri ), "=", 2 );
   1.585  
   1.586          /* gmyth_debug( "Channel tuple is [ %s, %s ]", chan_key_value[0], chan_key_value[1] ); */
   1.587  
   1.588 -        if (chan_key_value[1] != NULL && strlen (chan_key_value[1]) > 0) {
   1.589 -            channel = g_strdup (chan_key_value[1]);
   1.590 +        if ( chan_key_value[1] != NULL && strlen ( chan_key_value[1] ) > 0 )
   1.591 +        {
   1.592 +            channel = g_strdup ( chan_key_value[1] );
   1.593          }
   1.594  
   1.595 -        if (chan_key_value != NULL)
   1.596 -            g_strfreev (chan_key_value);
   1.597 +        if ( chan_key_value != NULL )
   1.598 +            g_strfreev ( chan_key_value );
   1.599      }
   1.600  
   1.601 -    gmyth_debug ("Got channel decimal value from the URI: %s", channel);
   1.602 +    gmyth_debug ( "Got channel decimal value from the URI: %s", channel );
   1.603  
   1.604      return channel;
   1.605  
   1.606 @@ -490,12 +520,13 @@
   1.607   * 				 of the URI string, or <code>-1</code> it if couldn't be converted.
   1.608   */
   1.609  gint
   1.610 -gmyth_uri_get_channel_num (GMythURI * uri)
   1.611 +gmyth_uri_get_channel_num ( GMythURI * uri )
   1.612  {
   1.613 -    gchar *channel_name = gmyth_uri_get_channel_name (uri);
   1.614 +    gchar *channel_name = gmyth_uri_get_channel_name ( uri );
   1.615  
   1.616 -    if (channel_name != NULL) {
   1.617 -        return g_ascii_strtoull (channel_name, NULL, 10);
   1.618 +    if ( channel_name != NULL )
   1.619 +    {
   1.620 +        return g_ascii_strtoull ( channel_name, NULL, 10 );
   1.621      }
   1.622  
   1.623      return -1;
   1.624 @@ -510,37 +541,37 @@
   1.625   * @return <code>true</code>, if the URI points to a local file.
   1.626   */
   1.627  gboolean
   1.628 -gmyth_uri_is_local_file (const GMythURI * uri)
   1.629 +gmyth_uri_is_local_file ( const GMythURI * uri )
   1.630  {
   1.631      gboolean ret = FALSE;
   1.632      gint len = -1;
   1.633  
   1.634 -    GString *hostname = gmyth_socket_get_local_hostname ();
   1.635 +    GString *hostname = gmyth_socket_get_local_hostname (  );
   1.636  
   1.637 -    g_return_val_if_fail (uri != NULL, FALSE);
   1.638 +    g_return_val_if_fail ( uri != NULL, FALSE );
   1.639  
   1.640 -    len = strlen (gmyth_uri_get_host (uri));
   1.641 +    len = strlen ( gmyth_uri_get_host ( uri ) );
   1.642  
   1.643      // gmyth_debug("URI: host = %s, hostname = %s.", uri->host->str, hostname != NULL ? hostname->str : "[no hostname]");
   1.644  
   1.645 -    ret = (NULL != hostname && (g_ascii_strncasecmp (uri->host->str, (hostname)->str, len) == 0)    /*|| 
   1.646 -                                                                                                       ( g_ascii_strncasecmp( gmyth_uri_get_host(uri), gmyth_socket_get_primary_addr(), len ) == 0 ) */
   1.647 -        );
   1.648 +    ret = ( NULL != hostname && ( g_ascii_strncasecmp ( uri->host->str, ( hostname )->str, len ) == 0 ) /*|| 
   1.649 +                                                                                                           ( g_ascii_strncasecmp( gmyth_uri_get_host(uri), gmyth_socket_get_primary_addr(), len ) == 0 ) */
   1.650 +         );
   1.651  
   1.652 -    if (ret)
   1.653 -        gmyth_debug ("This URI is a local file...");
   1.654 +    if ( ret )
   1.655 +        gmyth_debug ( "This URI is a local file..." );
   1.656      else
   1.657 -        gmyth_debug ("This URI is NOT a local file...");
   1.658 +        gmyth_debug ( "This URI is NOT a local file..." );
   1.659  
   1.660      return ret;
   1.661  
   1.662  }
   1.663  
   1.664  char *
   1.665 -gmyth_uri_to_string (const GMythURI * uri)
   1.666 +gmyth_uri_to_string ( const GMythURI * uri )
   1.667  {
   1.668 -    g_return_val_if_fail (uri != NULL, NULL);
   1.669 -    g_return_val_if_fail (uri->uri != NULL, NULL);
   1.670 +    g_return_val_if_fail ( uri != NULL, NULL );
   1.671 +    g_return_val_if_fail ( uri->uri != NULL, NULL );
   1.672  
   1.673 -    return g_strdup (uri->uri->str);
   1.674 +    return g_strdup ( uri->uri->str );
   1.675  }