[svn r543] fixed parse string trunk
authorrenatofilho
Thu Apr 12 21:57:16 2007 +0100 (2007-04-12)
branchtrunk
changeset 53805e6ab23f892
parent 537 7dacfb6cb424
child 539 c67cec9e6073
[svn r543] fixed parse string
gmyth-stream/libgnomevfs2/modules/gmythstream-method.c
     1.1 --- a/gmyth-stream/libgnomevfs2/modules/gmythstream-method.c	Thu Apr 12 21:28:37 2007 +0100
     1.2 +++ b/gmyth-stream/libgnomevfs2/modules/gmythstream-method.c	Thu Apr 12 21:57:16 2007 +0100
     1.3 @@ -155,45 +155,56 @@
     1.4      return;
     1.5  }
     1.6  
     1.7 -char* _parse_opt(char* opt)
     1.8 -{
     1.9 -    char** list = g_strsplit(opt, "opt=", 2);
    1.10 -    char** opts = g_strsplit(list[1], "+", 32);
    1.11 -    char* value = "";
    1.12 -    char* aux;
    1.13 -    gint i = 0;
    1.14 -
    1.15 -    for (aux = opts[0]; aux != NULL; aux = opts[++i])
    1.16 -        value = g_strdup_printf("%s %s", value, aux);
    1.17 -
    1.18 -    g_free(aux);
    1.19 -    g_strfreev(list);
    1.20 -    g_strfreev(opts);
    1.21 -    return value;
    1.22 -}
    1.23 -
    1.24  static UriArgs *
    1.25  _uri_parse_args (const GnomeVFSURI *uri)
    1.26  {
    1.27 -    gchar *file = gnome_vfs_unescape_string (uri->text, NULL);
    1.28 -    gchar **lst = g_strsplit (file, "?", 0);
    1.29 +
    1.30 +    gchar *file;
    1.31      UriArgs *info = g_new0 (UriArgs, 1);
    1.32 -    gint i = 1;
    1.33 +	GSList *args = NULL;
    1.34 +	gchar *c;
    1.35 +	GString *entry;
    1.36 +	gboolean open = FALSE;
    1.37 +	gchar **prop;
    1.38 +    GSList* walk;
    1.39 +	gchar *uri_str = gnome_vfs_uri_to_string (uri, 
    1.40 +			GNOME_VFS_URI_HIDE_USER_NAME |
    1.41 +			GNOME_VFS_URI_HIDE_PASSWORD |
    1.42 +			GNOME_VFS_URI_HIDE_HOST_NAME |
    1.43 +			GNOME_VFS_URI_HIDE_HOST_PORT |
    1.44 +			GNOME_VFS_URI_HIDE_TOPLEVEL_METHOD |
    1.45 +			GNOME_VFS_URI_HIDE_FRAGMENT_IDENTIFIER);
    1.46  
    1.47 -    gchar** prop = NULL;
    1.48 -    prop = g_strsplit_set(lst[0], "/=", 3);
    1.49 +	file = gnome_vfs_unescape_string (uri_str, NULL);
    1.50 +	c = file;
    1.51 +	//skip "/"
    1.52 +	entry = g_string_new ("");
    1.53 +	c = c + 1;
    1.54 +	do {
    1.55 +		if ((*c == '\"') || (*c == '\'')) {
    1.56 +			open = !open;
    1.57 +		}
    1.58  
    1.59 -    info->file_name = g_strdup_printf ("%s://%s",\
    1.60 -                                       prop[1],prop[2]);
    1.61 -    g_strfreev(prop);
    1.62 +		if (((*c == '?') || (c + 1 == '\0')) && !open) {
    1.63 +			args = g_slist_append (args, g_strdup (entry->str));
    1.64 +			entry = g_string_assign (entry, "");
    1.65 +		} else {
    1.66 +			g_string_append_c (entry, *c);
    1.67 +		}
    1.68 +		c = c + 1;
    1.69 +	} while (*c != '\0');
    1.70  
    1.71 -    gchar* walk;
    1.72 -    for (walk = lst[1]; walk != NULL; walk = lst[++i])
    1.73 +	g_string_free (entry, TRUE);
    1.74 +
    1.75 +    for (walk = args; walk != NULL; walk = walk->next)
    1.76      {
    1.77 -        prop = g_strsplit(walk, "=", 2);
    1.78 +		gchar *arg = (gchar *) walk->data;
    1.79 +        prop = g_strsplit(arg, "=", 2);
    1.80  
    1.81          if (g_strv_length (prop) == 2) {
    1.82 -            if (strcmp (prop[0], "mux") == 0) {
    1.83 +			if (strcmp (prop[0], "file") == 0) {
    1.84 +				info->file_name = g_strdup (prop[1]);
    1.85 +			} else if (strcmp (prop[0], "mux") == 0) {
    1.86                  info->mux = g_strdup (prop[1]);
    1.87              } else if (strcmp (prop[0], "vcodec") == 0) {
    1.88                  info->vcodec = g_strdup (prop[1]);
    1.89 @@ -210,16 +221,16 @@
    1.90              } else if (strcmp (prop[0], "height") == 0) {
    1.91                  info->height = atoi (prop[1]);
    1.92              } else if (strcmp (prop[0], "opt") == 0) {
    1.93 -                g_debug("DENTRO DE OPT: %s", walk);
    1.94 -                char* v = _parse_opt(walk);
    1.95 -                info->opt = g_strdup (v);
    1.96 +                g_debug("DENTRO DE OPT: %s", arg);
    1.97 +                //char* v = _parse_opt(walk);
    1.98 +                info->opt = g_strdup (arg);
    1.99              }
   1.100 -            }
   1.101 +        }
   1.102          g_strfreev (prop);
   1.103 +		g_free (arg);
   1.104      }
   1.105 -
   1.106      g_free (file);
   1.107 -    g_strfreev (lst);
   1.108 +	g_slist_free (args);
   1.109      return info;
   1.110  }
   1.111