Exemplo n.º 1
0
Arquivo: dnd.c Projeto: polarcat/yad
static void
drop_data_cb (GtkWidget *w, GdkDragContext *dc, gint x, gint y,
	      GtkSelectionData *sel, guint info, guint t, gpointer data)
{
  GdkAtom stgt;

  stgt = gtk_selection_data_get_target (sel);

  if (gtk_targets_include_uri (&stgt, 1))
    {
      gchar **uris;
      gint i = 0;

      uris = gtk_selection_data_get_uris (sel);
      if (!uris)
        return;

      while (uris[i])
	{
	  gchar *dstr = g_uri_unescape_string (uris[i], NULL);
	  if (options.common_data.command)
	    {
	      gchar *action = g_strdup_printf ("%s '%s'", options.common_data.command, dstr);
	      g_spawn_command_line_async (action, NULL);
	      g_free (action);
	    }
	  else
	    {
	      g_printf ("%s\n", dstr);
	      fflush (stdout);
	    }
	  g_free (dstr);
	  i++;
	}
      g_strfreev (uris);
    }
  else if (gtk_targets_include_text (&stgt, 1))
    {
      guchar *str = gtk_selection_data_get_text (sel);
      if (str)
	{
	  gchar *dstr = g_uri_unescape_string ((const gchar *) str, NULL);
	  if (options.common_data.command)
	    {
	      gchar *action = g_strdup_printf ("%s '%s'", options.common_data.command, dstr);
	      g_spawn_command_line_async (action, NULL);
	      g_free (action);
	    }
	  else
	    {
	      g_printf ("%s\n", dstr);
	      fflush (stdout);
	    }
	  g_free (dstr);
	  g_free(str);
	}
    }
}
Exemplo n.º 2
0
static void
doc_code_selection(Tdocument * doc, Treplace_mode mode)
{
	gint start, end;
	if (doc_get_selection(doc, &start, &end)) {
		gchar *inbuf, *outbuf = NULL;

		inbuf = doc_get_chars(doc, start, end);
		switch (mode) {
		case mode_urlencode:
			outbuf = g_uri_escape_string(inbuf, NULL, FALSE);
			break;
		case mode_urldecode:
			outbuf = g_uri_unescape_string(inbuf, NULL);
			break;
		case mode_tolowercase:
			if (inbuf)
				outbuf = g_utf8_strdown(inbuf, -1);
			break;
		case mode_touppercase:
			if (inbuf)
				outbuf = g_utf8_strup(inbuf, -1);
			break;
		}
		g_free(inbuf);
		if (outbuf) {
			doc_replace_text(doc, outbuf, start, end);
			g_free(outbuf);
		}
	}
}
Exemplo n.º 3
0
GBytes *
gtk_file_load_bytes (GFile         *file,
                     GCancellable  *cancellable,
                     GError       **error)
{
  gchar *contents;
  gsize len;

  g_return_val_if_fail (G_IS_FILE (file), NULL);
  g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), NULL);

  if (g_file_has_uri_scheme (file, "resource"))
    {
      gchar *uri, *unescaped;
      GBytes *bytes;

      uri = g_file_get_uri (file);
      unescaped = g_uri_unescape_string (uri + strlen ("resource://"), NULL);
      g_free (uri);

      bytes = g_resources_lookup_data (unescaped, 0, error);
      g_free (unescaped);

      return bytes;
    }

  /* contents is always \0 terminated, but we don't include that in the bytes */
  if (g_file_load_contents (file, cancellable, &contents, &len, NULL, error))
    return g_bytes_new_take (contents, len);

  return NULL;
}
static void
escapedStringCriteriaSetWidgetData (GtkWidget *widget, GValue *val)
{
	char *text = g_uri_unescape_string (g_value_get_string (val), NULL);
	gtk_entry_set_text (GTK_ENTRY (widget), text);
	g_free (text);
}
Exemplo n.º 5
0
static GdkPixbuf*
decode_image (const char *val)
{
  int i;
  GError *error = NULL;
  GdkPixbuf *res = NULL;
  struct {
    const char *prefix;
    const char *mime_type;
  } formats[] = {
    { "data:image/x-icon;base64,", "image/x-icon" },
    { "data:image/png;base64,", "image/png" }
  };

  g_return_val_if_fail (val, NULL);

  for (i = 0; i < G_N_ELEMENTS (formats); i++)
    {
      if (g_str_has_prefix (val, formats[i].prefix))
        {
          gsize len;
          guchar *data = NULL;
          char *unescaped;

          unescaped = g_uri_unescape_string (val + strlen (formats[i].prefix), NULL);
          if (unescaped)
            {
              data = g_base64_decode (unescaped, &len);
              g_free (unescaped);
            }

          if (data)
            {
              GdkPixbufLoader *loader;

              loader = gdk_pixbuf_loader_new_with_mime_type (formats[i].mime_type, &error);
              if (loader &&
                  gdk_pixbuf_loader_write (loader, data, len, &error) &&
                  gdk_pixbuf_loader_close (loader, &error))
                {
                  res = gdk_pixbuf_loader_get_pixbuf (loader);
                  g_object_ref (res);
                }
              g_object_unref (loader);
              g_free (data);
            }
        }
    }
  if (!res)
    {
      if (error)
        {
          g_warning ("%s\n", error->message);
          g_error_free (error);
        }
      else
        g_warning ("incorrect data uri");
    }
  return res;
}
Exemplo n.º 6
0
static void
convert_xml_file (xmlDocPtr xml,
		  GFile *dir)
{
	xmlNodePtr node;
	xmlChar *name;
	char *unescaped_name;
	GFile *file;

	for (node = xml_get_root_children (xml);
	     node != NULL; node = node->next) {
		if (strcmp ((char *)node->name, "file") == 0) {
			name = xmlGetProp (node, (xmlChar *)"name");
			unescaped_name = g_uri_unescape_string ((char *)name, "/");
			xmlFree (name);

			if (unescaped_name == NULL) {
				continue;
			}

			if (strcmp (unescaped_name, ".") == 0) {
				file = g_object_ref (dir);
			} else  {
			    file = g_file_get_child (dir, unescaped_name);
			}

			parse_xml_node (file, node);
			g_object_unref (file);
			g_free (unescaped_name);
		}
	}
}
Exemplo n.º 7
0
static gchar * dt_make_path_absolute(const gchar * input)
{
  gchar *filename = NULL;

  if(g_str_has_prefix(input, "file://")) // in this case we should take care of %XX encodings in the string (for example %20 = ' ')
  {
    input += strlen("file://");
    filename = g_uri_unescape_string(input, NULL);
  }
  else
    filename = g_strdup(input);

  if(g_path_is_absolute(filename) == FALSE)
  {
    char* current_dir = g_get_current_dir();
    char* tmp_filename = g_build_filename(current_dir, filename, NULL);
    g_free(filename);
    filename = g_realpath(tmp_filename);
    if(filename == NULL)
    {
      g_free(current_dir);
      g_free(tmp_filename);
      g_free(filename);
      return NULL;
    }
    g_free(current_dir);
    g_free(tmp_filename);
  }

  return filename;
}
Exemplo n.º 8
0
/**
 * fm_path_new_for_uri
 * @path_name: a URI with special characters escaped.
 * Encoded URI such as http://wiki.lxde.org/zh/%E9%A6%96%E9%A0%81
 * will be unescaped.
 *
 * You can call fm_path_to_uri () to convert a FmPath to a escaped URI
 * string.
 *
 * Returns: a newly created FmPath for the path. You have to call
 * fm_path_unref () when it's no longer needed.
 */
static FmPath *_fm_path_new_for_uri_internal (const char *uri, gboolean need_unescape)
{
    FmPath *path, *root;
    const char *rel_path;
    
    if (!uri || !*uri)
        return fm_path_ref (root_path);

    root = _fm_path_new_uri_root (uri, strlen (uri), &rel_path, need_unescape);
    
    if (*rel_path)
    {
        if (need_unescape)
            rel_path = g_uri_unescape_string (rel_path, NULL);
        
        path = fm_path_new_relative (root, rel_path);
        fm_path_unref (root);
        
        if (need_unescape)
            g_free ((char*)rel_path);
    }
    else
    {
        path = root;
    }
    return path;
}
Exemplo n.º 9
0
gboolean
audacious_get_currsong(gchar** name,gchar** path)
{
	FILE *stream;
	gchar buf[400],**tmp,*fullname;
	gint i;

	memset(buf,0,sizeof(buf));

	stream = popen("audtool --current-song-filename","r");
	fread(buf, sizeof(gchar),sizeof(buf)-1,stream);

	fullname = g_uri_unescape_string(buf,NULL);
	if (fullname)
		tmp = g_strsplit_set(fullname,":.",3);
	else {
		pclose(stream);
		return FALSE;
	}
	if (*tmp[1]) {
		*name = g_path_get_basename(tmp[1]);
		*path = g_path_get_dirname(tmp[1]);
	} else {
		g_free(fullname);
		g_strfreev(tmp);
		pclose(stream);
		return FALSE;
	}
	g_free(fullname);
	g_strfreev(tmp);
	pclose(stream);
	return TRUE;
}
Exemplo n.º 10
0
static void gtkui_drag_data_received( GtkWidget *widget,
                                      GdkDragContext *drag_context,
                                      gint x, gint y,
                                      GtkSelectionData *data,
                                      guint info, guint time )
{
  static char uri_prefix[] = "file://";
  char *filename, *p, *data_end;

  if ( data && data->length > sizeof( uri_prefix ) ) {
    filename = ( char * )( data->data + sizeof( uri_prefix ) - 1 );
    data_end = ( char * )( data->data + data->length );
    p = filename; 
    do {
      if ( *p == '\r' || *p == '\n' ) {
        *p = '\0';
	break;
      }
    } while ( p++ != data_end );

    if ( ( filename = g_uri_unescape_string( filename, NULL ) ) != NULL ) {
      fuse_emulation_pause();
      utils_open_file( filename, settings_current.auto_load, NULL );
      free( filename );
      display_refresh_all();
      fuse_emulation_unpause();
    }
  }
  gtk_drag_finish(drag_context, FALSE, FALSE, time);
}
Exemplo n.º 11
0
static void
setup_button (Launcher *launcher)
{
	char *comment;
	char *name;
	char *str;
	char *icon;
	char *unescaped_str;
	
	g_return_if_fail (launcher != NULL);

	name = panel_key_file_get_locale_string (launcher->key_file, "Name");
	comment = panel_key_file_get_locale_string (launcher->key_file,
						    "Comment");

	/* Setup tooltip */
	if (!PANEL_GLIB_STR_EMPTY (name) && !PANEL_GLIB_STR_EMPTY (comment))
		str = g_strdup_printf ("%s\n%s", name, comment);
	else if (!PANEL_GLIB_STR_EMPTY (name))
		str = g_strdup (name);
	else
		str = g_strdup (comment);

	g_free (name);
	g_free (comment);

	/* If we can unescape the string, then we probably have an escaped
	 * string (a location e.g.). If we can't, then it most probably means
	 * we have a % that is not here to encode a character, and we don't
	 * want to unescape in this case. See bug #170516 for details. */
	unescaped_str = g_uri_unescape_string (str, NULL);
	if (unescaped_str) {
		g_free (str);
		str = unescaped_str;
	}

	panel_util_set_tooltip_text (launcher->button, str);

	/* Setup accessible name */
	panel_a11y_set_atk_name_desc (launcher->button, str, NULL);

	g_free (str);

	/* Setup icon */
	icon = panel_key_file_get_locale_string (launcher->key_file, "Icon");
	if (icon && icon[0] == '\0') {
		g_free (icon);
		icon = NULL;
	}

	if (!icon)
		icon = guess_icon_from_exec (button_widget_get_icon_theme (BUTTON_WIDGET (launcher->button)),
					     launcher->key_file);
	if (!icon)
		icon = g_strdup (PANEL_ICON_LAUNCHER);

	button_widget_set_icon_name (BUTTON_WIDGET (launcher->button), icon);
	g_free (icon);
}
Exemplo n.º 12
0
static gboolean
gtk_css_image_url_parse (GtkCssImage  *image,
                         GtkCssParser *parser)
{
  GtkCssImageUrl *url = GTK_CSS_IMAGE_URL (image);
  GdkPixbuf *pixbuf;
  GFile *file;
  cairo_t *cr;
  GError *error = NULL;
  GFileInputStream *input;

  file = _gtk_css_parser_read_url (parser);
  if (file == NULL)
    return FALSE;

  /* We special case resources here so we can use
     gdk_pixbuf_new_from_resource, which in turn has some special casing
     for GdkPixdata files to avoid duplicating the memory for the pixbufs */
  if (g_file_has_uri_scheme (file, "resource"))
    {
      char *uri = g_file_get_uri (file);
      char *resource_path = g_uri_unescape_string (uri + strlen ("resource://"), NULL);

      pixbuf = gdk_pixbuf_new_from_resource (resource_path, &error);
      g_free (resource_path);
      g_free (uri);
    }
  else
    {
      input = g_file_read (file, NULL, &error);
      if (input == NULL)
	{
	  _gtk_css_parser_take_error (parser, error);
	  return FALSE;
	}

      pixbuf = gdk_pixbuf_new_from_stream (G_INPUT_STREAM (input), NULL, &error);
      g_object_unref (input);
    }
  g_object_unref (file);

  if (pixbuf == NULL)
    {
      _gtk_css_parser_take_error (parser, error);
      return FALSE;
    }

  url->surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
                                             gdk_pixbuf_get_width (pixbuf),
                                             gdk_pixbuf_get_height (pixbuf));
  cr = cairo_create (url->surface);
  gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
  cairo_paint (cr);
  cairo_destroy (cr);
  g_object_unref (pixbuf);

  return TRUE;
}
Exemplo n.º 13
0
void chmsee_open_uri(ChmSee *chmsee, const gchar *uri) {
  if(!g_str_has_prefix(uri, "file://")) {
    return;
  }

  gchar* fname = g_uri_unescape_string(uri+7, NULL);
  chmsee_open_file(chmsee, fname);
  g_free(fname);
}
Exemplo n.º 14
0
static GUniquePtr<char> unescapedFilename(const String& path)
{
    if (path.isEmpty())
        return nullptr;
#if OS(WINDOWS)
    return GUniquePtr<char>(g_strdup(path.utf8().data()));
#else
    return GUniquePtr<char>(g_uri_unescape_string(path.utf8().data(), nullptr));
#endif
}
/**
 * Update a SearchExpression with a new key = value condition.
 *
 * Will modifiy the passed expression to (expression AND (key = value))
 *
 * @param expression The expression to update or null to create a new one
 * @param key        Key of the key/value condition
 * @param value      Value of the key/value condition
 */
static void
rygel_media_export_query_container_factory_update_search_expression (RygelSearchExpression **expression,
                                                                     const gchar            *key,
                                                                     const gchar            *value) {
  RygelSearchExpression *search_sub;
  RygelRelationalExpression *subexpression;
  gchar *clean_key;
  GError *error;

  g_return_if_fail (expression != NULL);
  g_return_if_fail (*expression == NULL || RYGEL_IS_SEARCH_EXPRESSION (*expression));
  g_return_if_fail (key != NULL);
  g_return_if_fail (value != NULL);

  subexpression = rygel_relational_expression_new ();
  search_sub = RYGEL_SEARCH_EXPRESSION (subexpression);
  error = NULL;
  clean_key = rygel_media_export_string_replace (key,
                                                 RYGEL_MEDIA_EXPORT_QUERY_CONTAINER_PREFIX,
                                                 "",
                                                 &error);
  if (error) {
    g_warning ("Failed to remove "  " from %s: %s",
               key,
               error->message);
    g_error_free (error);
  }
  search_sub->operand1 = g_uri_unescape_string (clean_key, NULL);
  search_sub->op = (gpointer) ((gintptr) GUPNP_SEARCH_CRITERIA_OP_EQ);
  search_sub->operand2 = g_uri_unescape_string (value, NULL);
  g_free (clean_key);
  if (*expression) {
    RygelLogicalExpression *conjunction = rygel_logical_expression_new ();
    RygelSearchExpression *search_conj = RYGEL_SEARCH_EXPRESSION (conjunction);

    search_conj->operand1 = *expression;
    search_conj->operand2 = subexpression;
    search_conj->op = (gpointer) ((gintptr) RYGEL_LOGICAL_OPERATOR_AND);
    *expression = search_conj;
  } else {
    *expression = search_sub;
  }
}
Exemplo n.º 16
0
static void
parse_sftp_uri (GFile *file,
                char **user,
                char **host,
                unsigned int *port,
                char **path)
{
  char *tmp, *save;
  char *uri;

  uri = g_file_get_uri (file);
  g_assert (uri != NULL);
  save = uri;

  *path = NULL;
  *user = NULL;
  *host = NULL;
  *port = 0;

  /* skip intial 'sftp:// prefix */
  g_assert (!strncmp (uri, SFTP_PREFIX, strlen (SFTP_PREFIX)));
  uri += strlen (SFTP_PREFIX);

  /* cut out the path */
  tmp = strchr (uri, '/');
  if (tmp != NULL) {
    *path = g_uri_unescape_string (tmp, "/");
    *tmp = '\0';
  }

  /* read the username - it ends with @ */
  tmp = strchr (uri, '@');
  if (tmp != NULL) {
    *tmp++ = '\0';

    *user = strdup (uri);
    if (strchr (*user, ':') != NULL) {
      /* chop the password */
      *(strchr (*user, ':')) = '\0'; 
    }

    uri = tmp;
  }

  /* now read the port, starts with : */
  tmp = strchr (uri, ':');
  if (tmp != NULL) {
    *tmp++ = '\0';
    *port = atoi (tmp);  /*FIXME: getservbyname*/
  }

  /* what is left is the host */
  *host = strdup (uri);
  g_free (save);
}
Exemplo n.º 17
0
static int request_parse_query(const gchar *query, GHashTable *params) {

	gchar **v, **p;
	
	v=g_strsplit(query, "&", 0);
	if (v==NULL) return -1;

	for (p=v; *p; p++) {

		gchar *key=NULL, *val=NULL, *uval=NULL;
		gchar **vv=NULL;
		
		vv=g_strsplit_set(*p, "=", 2);
		if (vv==NULL) {
			DEBUG_PRINT("g_strsplit_set returned NULL");
			continue;
		}

		key=g_strdup(*vv);
		if (key==NULL) {
			DEBUG_PRINT("g_strdup returned NULL");
			g_strfreev(vv);
			continue;
		}

		val= g_strdup(*(vv+1)!=NULL ? *(vv+1) : "");
		if (val==NULL) {
			DEBUG_PRINT("g_strdup returned NULL");
			g_free(key);
			g_strfreev(vv);
			continue;
		}

		g_strfreev(vv);

		uval = g_uri_unescape_string(val, NULL);

		if (uval==NULL) {
			DEBUG_PRINT("g_uri_unescape_string returned NULL");
			g_free(key); g_free(val);
			continue;
		}
		g_free(val);

#ifdef DEBUG
fprintf(stderr, "Parameter: %s -> %s\n", key, uval);
#endif
		g_hash_table_insert(params, key, uval);
	}

	g_strfreev(v);

	return 0;
}
Exemplo n.º 18
0
static GtkCssImage *
gtk_css_image_url_load_image (GtkCssImageUrl  *url,
                              GError         **error)
{
  GdkTexture *texture;
  GError *local_error = NULL;

  if (url->loaded_image)
    return url->loaded_image;

  /* We special case resources here so we can use
     gdk_pixbuf_new_from_resource, which in turn has some special casing
     for GdkPixdata files to avoid duplicating the memory for the pixbufs */
  if (g_file_has_uri_scheme (url->file, "resource"))
    {
      char *uri = g_file_get_uri (url->file);
      char *resource_path = g_uri_unescape_string (uri + strlen ("resource://"), NULL);

      texture = gdk_texture_new_from_resource (resource_path);

      g_free (resource_path);
      g_free (uri);
    }
  else
    {
      texture = gdk_texture_new_from_file (url->file, &local_error);
    }

  if (texture == NULL)
    {
      if (error)
        {
          char *uri;

          uri = g_file_get_uri (url->file);
          g_set_error (error,
                       GTK_CSS_PARSER_ERROR,
                       GTK_CSS_PARSER_ERROR_FAILED,
                       "Error loading image '%s': %s", uri, local_error->message);
          g_free (uri);
       }
      
      url->loaded_image = gtk_css_image_invalid_new ();
    }
  else
    {
      url->loaded_image = gtk_css_image_paintable_new (GDK_PAINTABLE (texture), GDK_PAINTABLE (texture));
      g_object_unref (texture);
    }

  g_clear_error (&local_error);

  return url->loaded_image;
}
Exemplo n.º 19
0
static GtkCssImage *
gtk_css_image_url_load_image (GtkCssImageUrl *url)
{
  GdkPixbuf *pixbuf;
  GError *error = NULL;
  GFileInputStream *input;

  if (url->loaded_image)
    return url->loaded_image;

  /* We special case resources here so we can use
     gdk_pixbuf_new_from_resource, which in turn has some special casing
     for GdkPixdata files to avoid duplicating the memory for the pixbufs */
  if (g_file_has_uri_scheme (url->file, "resource"))
    {
      char *uri = g_file_get_uri (url->file);
      char *resource_path = g_uri_unescape_string (uri + strlen ("resource://"), NULL);

      pixbuf = gdk_pixbuf_new_from_resource (resource_path, &error);
      g_free (resource_path);
      g_free (uri);
    }
  else
    {
      input = g_file_read (url->file, NULL, &error);
      if (input != NULL)
	{
          pixbuf = gdk_pixbuf_new_from_stream (G_INPUT_STREAM (input), NULL, &error);
          g_object_unref (input);
	}
      else
        {
          pixbuf = NULL;
        }
    }

  if (pixbuf == NULL)
    {
      cairo_surface_t *empty = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 0, 0);

      /* XXX: Can we get the error somehow sent to the CssProvider?
       * I don't like just dumping it to stderr or losing it completely. */
      g_warning ("Error loading image: %s", error->message);
      g_error_free (error);
      url->loaded_image = _gtk_css_image_surface_new (empty);
      cairo_surface_destroy (empty);
      return url->loaded_image; 
    }

  url->loaded_image = _gtk_css_image_surface_new_for_pixbuf (pixbuf);
  g_object_unref (pixbuf);

  return url->loaded_image;
}
Exemplo n.º 20
0
gchar*
balde_urldecode(const gchar* str)
{
    // corner case: + -> ' '
    GRegex *re_space = g_regex_new("\\+", 0, 0, NULL);
    gchar *new_str = g_regex_replace_literal(re_space, str, -1, 0, "%20", 0, NULL);
    g_regex_unref(re_space);
    gchar *rv = g_uri_unescape_string(new_str, NULL);
    g_free(new_str);
    return rv;
}
Exemplo n.º 21
0
GFile *
_g_resource_file_new (const char *uri)
{
  GFile *resource;
  char *path;

  path = g_uri_unescape_string (uri + strlen ("resource:"), NULL);
  resource = g_resource_file_new_for_path (path);
  g_free (path);

  return G_FILE (resource);
}
Exemplo n.º 22
0
static char *
get_filename_from_uri (const char *uri)
{
	char *filename;
	char *basename;
	
	filename = g_uri_unescape_string (uri, NULL);
	basename = g_path_get_basename (filename);
	g_free(filename);

	return basename;
}
Exemplo n.º 23
0
char *
ephy_uri_safe_unescape (const char *uri_string)
{
  char *decoded_uri;

  /* This function is not null-safe since it is mostly used in scenarios where
   * passing or returning null would typically lead to a security issue. */
  g_assert (uri_string);

  /* Protect against escaped null characters and escaped slashes. */
  decoded_uri = g_uri_unescape_string (uri_string, "/");
  return decoded_uri ? decoded_uri : g_strdup (uri_string);
}
Exemplo n.º 24
0
CString fileSystemRepresentation(const String& path)
{
// WARNING: this is just used by platform/network/soup, thus must be GLIB!!!
// TODO: move this to CString and use it instead in both, being more standard
#if !PLATFORM(WIN_OS) && defined(USE_SOUP)
    char* filename = g_uri_unescape_string(path.utf8().data(), 0);
    CString cfilename(filename);
    g_free(filename);
    return cfilename;
#else
    return path.utf8();
#endif
}
Exemplo n.º 25
0
static gboolean
try_mount (GVfsBackend  *backend,
           GVfsJobMount *job,
           GMountSpec   *mount_spec,
           GMountSource *mount_source,
           gboolean      is_automount)
{
  GVfsBackendHttp *op_backend;
  const char      *uri_str;
  char            *path;
  SoupURI         *uri;
  GMountSpec      *real_mount_spec;

  op_backend = G_VFS_BACKEND_HTTP (backend);

  uri = NULL;
  uri_str = g_mount_spec_get (mount_spec, "uri");

  if (uri_str)
    uri = soup_uri_new (uri_str);

  g_debug ("+ try_mount: %s\n", uri_str ? uri_str : "(null)");

  if (uri == NULL)
    {
      g_vfs_job_failed (G_VFS_JOB (job),
                        G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
                        _("Invalid mount spec"));
      return TRUE;
    }

  real_mount_spec = g_mount_spec_new ("http");
  g_mount_spec_set (real_mount_spec, "uri", uri_str);

  if (uri->path != NULL)
    {
      path = g_uri_unescape_string (uri->path, "/");
      g_free (real_mount_spec->mount_prefix);
      real_mount_spec->mount_prefix = g_mount_spec_canonicalize_path (path);
      g_free (path);
    }

  g_vfs_backend_set_mount_spec (backend, real_mount_spec);

  op_backend->mount_base = uri;

  g_vfs_job_succeeded (G_VFS_JOB (job));
  return TRUE;
}
static GSList *
_read_graft_point (xmlDocPtr project,
                   xmlNodePtr graft,
                   GSList *grafts)
{
    RejillaGraftPt *retval;

    retval = g_new0 (RejillaGraftPt, 1);
    grafts = g_slist_prepend (grafts, retval);
    while (graft) {
        if (!xmlStrcmp (graft->name, (const xmlChar *) "uri")) {
            xmlChar *uri;

            if (retval->uri)
                goto error;

            uri = xmlNodeListGetString (project,
                                        graft->xmlChildrenNode,
                                        1);
            retval->uri = g_uri_unescape_string ((char *)uri, NULL);
            g_free (uri);
            if (!retval->uri)
                goto error;
        }
        else if (!xmlStrcmp (graft->name, (const xmlChar *) "path")) {
            if (retval->path)
                goto error;

            retval->path = (char *) xmlNodeListGetString (project,
                           graft->xmlChildrenNode,
                           1);
            if (!retval->path)
                goto error;
        }
        else if (graft->type == XML_ELEMENT_NODE)
            goto error;

        graft = graft->next;
    }

    return grafts;

error:

    g_slist_foreach (grafts, (GFunc) rejilla_graft_point_free, NULL);
    g_slist_free (grafts);

    return NULL;
}
Exemplo n.º 27
0
static char *
program_get_metadata_fallback (MexGenericContent *gc,
                               MexContentMetadata key)
{
  MexContent *content = MEX_CONTENT (gc);
  const gchar *showname;
  gchar *target;

  switch (key) {
  case MEX_CONTENT_METADATA_TITLE:
    showname = mex_content_get_metadata (content,
                                         MEX_CONTENT_METADATA_SERIES_NAME);

    if (!showname) {
      const gchar *url;
      gchar *basename;

      url = mex_content_get_metadata (content, MEX_CONTENT_METADATA_URL);
      basename = g_path_get_basename (url);
      target = g_uri_unescape_string (basename, NULL);
      g_free (basename);
    } else {
      const gchar *episode, *season;

      episode = mex_content_get_metadata (content,
                                          MEX_CONTENT_METADATA_EPISODE);
      season = mex_content_get_metadata (content,
                                         MEX_CONTENT_METADATA_SEASON);

      if (episode && season) {
        target = g_strdup_printf ("%s: Season %s, Episode %s",
                                  showname, season, episode);
      } else if (episode) {
        target = g_strdup_printf ("%s: Episode %s", showname, episode);
      } else if (season) {
        target = g_strdup_printf ("%s: Season %s", showname, season);
      } else {
        target = g_strdup (showname);
      }
    }
    break;

  default:
    target = NULL;
    break;
  }

  return target;
}
Exemplo n.º 28
0
void
sflphone_switch_video_input(const gchar *resource)
{
    gchar *decoded = g_uri_unescape_string(resource, NULL);
    g_debug("MRL: '%s'", decoded);

    if (dbus_switch_video_input(decoded)) {
        g_free(last_uri);
        last_uri = g_strdup(resource);
    } else {
        g_warning("Failed to switch to MRL '%s'\n", resource);
    }

    g_free(decoded);
}
Exemplo n.º 29
0
static void
save_userinfo (GProxyAddressEnumeratorPrivate *priv,
	       const gchar *proxy)
{
  gchar *userinfo;

  if (priv->proxy_username)
    {
      g_free (priv->proxy_username);
      priv->proxy_username = NULL;
    }

  if (priv->proxy_password)
    {
      g_free (priv->proxy_password);
      priv->proxy_password = NULL;
    }
  
  if (_g_uri_parse_authority (proxy, NULL, NULL, &userinfo))
    {
      if (userinfo)
	{
	  gchar **split = g_strsplit (userinfo, ":", 2);

	  if (split[0] != NULL)
	    {
	      priv->proxy_username = g_uri_unescape_string (split[0], NULL);
	      if (split[1] != NULL)
		priv->proxy_password = g_uri_unescape_string (split[1], NULL);
	    }

	  g_strfreev (split);
	  g_free (userinfo);
	}
    }
}
Exemplo n.º 30
0
/**
 * lomo_em_art_search_stringify:
 * @search: An #LomoEMArtSearch
 *
 * Transforms @search into a string just for debugging purposes
 *
 * Returns: The strigified form of @search
 */
const gchar*
lomo_em_art_search_stringify(LomoEMArtSearch *search)
{
	g_return_val_if_fail(LOMO_IS_EM_ART_SEARCH(search), NULL);
	LomoEMArtSearchPrivate *priv = GET_PRIVATE(search);

	if (!priv->stringify)
	{
		gchar *unescape = g_uri_unescape_string(lomo_stream_get_uri(priv->stream), NULL);
		priv->stringify = g_path_get_basename(unescape);
		g_free(unescape);
		g_return_val_if_fail(priv->stringify, NULL);
	}
	return priv->stringify;
}