static gboolean
rb_audiocd_plugin_can_reuse_stream_cb (RBPlayer *player,
				       const char *new_uri,
				       const char *stream_uri,
				       GstElement *stream_bin,
				       RBAudioCdPlugin *plugin)
{
	const char *new_device;
	const char *old_device;

	/* can't do anything with non-cdda URIs */
	if (g_str_has_prefix (new_uri, "cdda://") == FALSE ||
	    g_str_has_prefix (stream_uri, "cdda://") == FALSE) {
		return FALSE;
	}

	/* check the device matches */
	new_device = g_utf8_strrchr (new_uri, -1, '#');
	old_device = g_utf8_strrchr (stream_uri, -1, '#');
	if (strcmp (old_device, new_device) != 0) {
		return FALSE;
	}

	return TRUE;
}
char *
rb_uri_get_short_path_name (const char *uri)
{
	const char *start;
	const char *end;

	if (uri == NULL)
		return NULL;

	/* skip query string */
	end = g_utf8_strchr (uri, -1, '?');

	start = g_utf8_strrchr (uri, end ? (end - uri) : -1, '/');
	if (start == NULL) {
		/* no separator, just a single file name */
	} else if ((start + 1 == end) || *(start + 1) == '\0') {
		/* last character is the separator, so find the previous one */
		end = start;
		start = g_utf8_strrchr (uri, (end - uri)-1, '/');

		if (start != NULL)
			start++;
	} else {
		start++;
	}

	if (start == NULL)
		start = uri;

	if (end == NULL) {
		return g_strdup (start);
	} else {
		return g_strndup (start, (end - start));
	}
}
示例#3
0
/**
 * used for now only while loading a file before the 0.6.0 version
 * reduce the exponant IN THE STRING of the amount because before the 0.6.0
 * all the gdouble where saved with an exponent very big
 * ie : in the file we have "12.340000"
 * and that fonction return "12.34" wich will be nicely imported
 * with gsb_data_transaction_set_amount_from_string
 *
 * \param amount_string
 * \param exponent the exponent we want at the end (normally always 2, but if ever...)
 *
 * \return a newly allocated string with only 'exponent' digits after the separator (need to be freed). This function returns NULL if the amount_string parameter is NULL.
 * */
gchar *utils_str_reduce_exponant_from_string ( const gchar *amount_string,
                        gint exponent )
{
    gchar *return_string;
    gchar *p;
    gchar *mon_decimal_point;
    gunichar decimal_point = (gunichar )-2;
    struct lconv *conv = localeconv ( );

    if ( !amount_string )
	    return NULL;

    mon_decimal_point = g_locale_to_utf8 ( conv->mon_decimal_point,
                        -1, NULL, NULL, NULL );
    if ( mon_decimal_point )
        decimal_point = g_utf8_get_char_validated ( mon_decimal_point, -1 );

    return_string = my_strdup ( amount_string );

    if ( ( p = g_utf8_strrchr ( (const gchar *) return_string, -1, '.' ) ) )
    {
        if ( g_unichar_isdefined ( decimal_point )
         &&
         g_utf8_strchr ( p, 1, decimal_point ) == NULL )
        {
            gchar **tab;

            tab = g_strsplit ( return_string, ".", 2 );
            return_string = g_strjoinv ( mon_decimal_point, tab );
            g_strfreev ( tab );
            p = g_utf8_strrchr ( (const gchar *) return_string, -1,
                        decimal_point );
        }
    }
    else if ( ( p = g_utf8_strrchr ( (const gchar *) return_string, -1, ',' ) ) )
    {
        if ( g_unichar_isdefined ( decimal_point )
         &&
         g_utf8_strchr ( p, 1, decimal_point ) == NULL )
        {
            gchar **tab;

            tab = g_strsplit ( return_string, ",", 2 );
            return_string = g_strjoinv ( mon_decimal_point, tab );
            g_strfreev ( tab );
            p = g_utf8_strrchr ( (const gchar *) return_string, -1,
                        decimal_point );
        }
    }
    else
        return NULL;

    p[exponent + 1] = '\0';

    return return_string;
}
static void
rb_audiocd_plugin_reuse_stream_cb (RBPlayer *player,
				   const char *new_uri,
				   const char *stream_uri,
				   GstElement *element,
				   RBAudioCdPlugin *plugin)
{
	GstFormat track_format = gst_format_get_by_nick ("track");
	char *track_str;
	char *new_device;
	guint track;
	guint cdda_len;

	/* get the new track number */
	cdda_len = strlen ("cdda://");
	new_device = g_utf8_strrchr (new_uri, -1, '#');
	track_str = g_strndup (new_uri + cdda_len, new_device - (new_uri + cdda_len));
	track = atoi (track_str);
	g_free (track_str);

	rb_debug ("seeking to track %d on CD device %s", track, new_device+1);

	gst_element_seek (element,
			  1.0, track_format, GST_SEEK_FLAG_FLUSH,
			  GST_SEEK_TYPE_SET, track-1,
			  GST_SEEK_TYPE_NONE, -1);
}
static void
set_source_properties (GstElement *source, const char *uri, gboolean playback_mode)
{
	const char *device;

	if (g_str_has_prefix (uri, "cdda://") == FALSE)
		return;

	device = g_utf8_strrchr (uri, -1, '#');
	if (device != NULL) {
		device++;	/* skip the # */
		g_object_set (source, "device", device, NULL);

		if (playback_mode) {
			/* disable paranoia (if using cdparanoiasrc) and set read speed to 1 */
			if (g_object_class_find_property (G_OBJECT_GET_CLASS (source), "paranoia-mode"))
				g_object_set (source, "paranoia-mode", 0, NULL);

			if (g_object_class_find_property (G_OBJECT_GET_CLASS (source), "read-speed"))
				g_object_set (source, "read-speed", 1, NULL);
		} else {
			/* enable full paranoia; maybe this should be configurable. */
			/* also, sound-juicer defaults to 8 (scratch) not 0xff (full) here.. */
			if (g_object_class_find_property (G_OBJECT_GET_CLASS (source), "paranoia-mode"))
				g_object_set (source, "paranoia-mode", 0xff, NULL);
		}
	}
}
示例#6
0
文件: list_if.c 项目: johlim/study
/*******************************************************************************
*	Description		:
*	Argurments		:
*	Return value	:
*	Modify			:
*	warning			:
*******************************************************************************/
static int compare_unicode(const char *data0, const char *data1, void *mode_ptr)
{
	const char *ptr0, *ptr1;
	SortingMode mode = *((SortingMode*)mode_ptr);

	ptr0 = g_utf8_strrchr(data0, -1, 0x002F);
	ptr1 = g_utf8_strrchr(data1, -1, 0x002F);
	ptr0 = ptr0 ? ptr0 + 1 : data0;
	ptr1 = ptr1 ? ptr1 + 1 : data1;
	if(mode & SORT_ASCEND) {
		return g_utf8_collate(ptr0, ptr1);
	}
	else {
		return g_utf8_collate(ptr1, ptr0);
	}
}
示例#7
0
gchar *
bracketted_to_string (gchar *bracketted,
		      const char *start_bracket,
		      const char *end_bracket)
{
  const char *utfstart, *utfend, *utfstr;
  int start_len, end_len, str_len;

  if (!bracketted) return NULL;

  utfstart = start_bracket;
  utfend = end_bracket;

  start_len = strlen (utfstart);
  end_len = strlen (utfend);
  str_len = strlen (bracketted);
  utfstr = bracketted;

  if (!strncmp (utfstr, utfstart, start_len)) {
    utfstr += start_len;
    str_len -= start_len;
  }
  if (str_len >= end_len && end_len > 0) {
    if (g_utf8_strrchr (utfstr, str_len, g_utf8_get_char (utfend)))
      str_len -= end_len;
  }
  return g_strndup (utfstr, str_len);
}
gchar *
rejilla_image_format_fix_path_extension (RejillaImageFormat format,
					 gboolean check_existence,
					 const gchar *path)
{
	gchar *dot;
	guint i = 0;
	gchar *retval = NULL;
	const gchar *suffix = NULL;;
	const gchar *suffixes [] = {".iso",
				    ".toc",
				    ".cue",
				    ".toc",
				    NULL };

	/* search the last dot to check extension */
	dot = g_utf8_strrchr (path, -1, '.');
	if (dot && strlen (dot) < 5 && strlen (dot) > 1) {
		if (format & REJILLA_IMAGE_FORMAT_BIN
		&&  strcmp (suffixes [0], dot))
			*dot = '\0';
		else if (format & REJILLA_IMAGE_FORMAT_CLONE
		     &&  strcmp (suffixes [1], dot))
			*dot = '\0';
		else if (format & REJILLA_IMAGE_FORMAT_CUE
		     &&  strcmp (suffixes [2], dot))
			*dot = '\0';
		else if (format & REJILLA_IMAGE_FORMAT_CDRDAO
		     &&  strcmp (suffixes [3], dot))
			*dot = '\0';
		else
			return g_strdup (path);
	}

	/* determine the proper suffix */
	if (format & REJILLA_IMAGE_FORMAT_BIN)
		suffix = suffixes [0];
	else if (format & REJILLA_IMAGE_FORMAT_CLONE)
		suffix = suffixes [1];
	else if (format & REJILLA_IMAGE_FORMAT_CUE)
		suffix = suffixes [2];
	else if (format & REJILLA_IMAGE_FORMAT_CDRDAO)
		suffix = suffixes [3];
	else
		return g_strdup (path);

	/* make sure the file doesn't exist */
	retval = g_strdup_printf ("%s%s", path, suffix);
	if (!check_existence)
		return retval;

	while (g_file_test (retval, G_FILE_TEST_EXISTS)) {
		g_free (retval);
		retval = g_strdup_printf ("%s-%i%s", path, i, suffix);
		i ++;
	}

	return retval;
}
示例#9
0
static void fm_path_entry_changed(GtkEditable *editable, gpointer user_data)
{
    FmPathEntry *entry = FM_PATH_ENTRY(editable);
    FmPathEntryPrivate *priv  = FM_PATH_ENTRY_GET_PRIVATE(entry);
    GtkWidget* widget = GTK_WIDGET(entry);
    const gchar *path_str, *sep;

    /* find parent dir of current path */
    path_str = gtk_entry_get_text( GTK_ENTRY(entry) );
    sep = g_utf8_strrchr(path_str, -1, G_DIR_SEPARATOR);
    if(sep) /* we found a parent dir */
    {
        int parent_len = (sep - path_str) + 1; /* includes the dir separator / */
        if(!priv->parent_dir
           || priv->parent_len != parent_len
           || strncmp(priv->parent_dir, path_str, parent_len ))
        {
            /* parent dir has been changed, reload dir list */
            ListSubDirNames* data = g_slice_new0(ListSubDirNames);
            g_free(priv->parent_dir);
            priv->parent_dir = g_strndup(path_str, parent_len);
            priv->parent_len = parent_len;
            /* g_debug("parent dir is changed to %s", priv->parent_dir); */

            /* FIXME: convert utf-8 encoded path to on-disk encoding. */
            data->entry = entry;
            if(priv->parent_dir[0] == '~') /* special case for home dir */
            {
                char* expand = g_strconcat(g_get_home_dir(), priv->parent_dir + 1, NULL);
                data->dir = g_file_new_for_commandline_arg(expand);
                g_free(expand);
            }
            else
                data->dir = g_file_new_for_commandline_arg(priv->parent_dir);

            /* clear current model */
            gtk_list_store_clear(GTK_LIST_STORE(priv->model));

            /* cancel running dir-listing jobs */
            if(priv->cancellable)
            {
                g_cancellable_cancel(priv->cancellable);
                g_object_unref(priv->cancellable);
            }

            /* launch a new job to do dir listing */
            data->cancellable = g_cancellable_new();
            priv->cancellable = (GCancellable*)g_object_ref(data->cancellable);
            g_io_scheduler_push_job(list_sub_dirs,
                                    data, (GDestroyNotify)list_sub_dir_names_free,
                                    G_PRIORITY_LOW, data->cancellable);
        }
        /* calculate the length of remaining part after / */
        priv->typed_basename_len = strlen(sep + 1);
    }
    else /* clear all autocompletion thing. */
        clear_completion(priv);
}
示例#10
0
文件: diagram.c 项目: brunetton/dia
int
diagram_load_into(Diagram         *diagram,
		  const char      *filename,
		  DiaImportFilter *ifilter)
{
  /* ToDo: move context further up in the callstack and to sth useful with it's content */
  DiaContext *ctx = dia_context_new(_("Load Into"));

  gboolean was_default = diagram->is_default;
  if (!ifilter)
    ifilter = filter_guess_import_filter(filename);
  /* slightly hacked to avoid 'Not a Dia File' for .shape */
  if (!ifilter && g_str_has_suffix (filename, ".shape"))
    ifilter = filter_import_get_by_name ("dia-svg");
  if (!ifilter)  /* default to native format */
    ifilter = &dia_import_filter;

  dia_context_set_filename (ctx, filename);
  if (ifilter->import_func(filename, diagram->data, ctx, ifilter->user_data)) {
    if (ifilter != &dia_import_filter) {
      /* When loading non-Dia files, change filename to reflect that saving
       * will produce a Dia file. See bug #440093 */
      if (strcmp (diagram->filename, filename) == 0) {
	/* not a real load into but initial load */
	gchar *old_filename = g_strdup (diagram->filename);
        gchar *suffix_offset = g_utf8_strrchr(old_filename, -1, (gunichar)'.');
        gchar *new_filename;
        if (suffix_offset != NULL) {
	  new_filename = g_strndup(old_filename, suffix_offset - old_filename);
	  g_free(old_filename);
	} else {
	  new_filename = old_filename;
	}
        old_filename = g_strconcat(new_filename, ".dia", NULL);
        g_free(new_filename);
        diagram_set_filename(diagram, old_filename);
        g_free(old_filename);
        diagram->unsaved = TRUE;
	diagram_update_for_filename (diagram);
	diagram_modified(diagram);
      }
    } else {
      /* the initial diagram should have confirmed filename  */
      diagram->unsaved = 
	  strcmp(filename, diagram->filename) == 0 ? FALSE : was_default;
    }
    diagram_set_modified(diagram, TRUE);
    dia_context_release(ctx);
    return TRUE;
  } else {
    dia_context_release(ctx);
    return FALSE;
  }
}
示例#11
0
static gboolean
_evhelpers_filename_check_data_base64_prefix(const gchar *string)
{
    gchar *c;
    gsize s;

    c = g_utf8_strchr(string, -1, ',');
    s = c - string;
    if ( ( c == NULL ) || ( s < strlen(";base64") ) )
        return FALSE;

    c = g_utf8_strrchr(string, s, ';');
    if ( ( c == NULL ) || ( ! g_str_has_prefix(c, ";base64") ) )
        return FALSE;

    return TRUE;
}
示例#12
0
文件: exif.c 项目: jcupitt/libvips
/* The final " (xx, yy, zz, kk)" part of the string (if present) was
 * added by us in _to_s(), we must remove it before setting the string 
 * back again.
 *
 * It may not be there if the user has changed the string.
 */
static char *
drop_tail( const char *data )
{
	char *str;
	char *p;

	str = g_strdup( data );

	p = str + strlen( str );
	if( p > str &&
		*g_utf8_prev_char( p ) == ')' &&
		(p = g_utf8_strrchr( str, -1, (gunichar) '(')) &&
		p > str &&
		*(p = g_utf8_prev_char( p )) == ' ' )
		*p = '\0';

	return( str );
}
示例#13
0
static gchar *
photos_utils_get_pixbuf_suffix_from_basename (const gchar *basename)
{
  gchar *suffix;
  gchar *suffix_start;
  guint len;

  /* FIXME: does this work for all locales? */
  suffix_start = g_utf8_strrchr (basename, -1, '.');

  if (suffix_start == NULL)
    return NULL;

  len = strlen (suffix_start) - 1;
  suffix = g_strndup (suffix_start+1, len);

  return suffix;
}
示例#14
0
gchar * GetNameFromFileName(const gchar* lpszFileName, gchar * lpszName, gint nLen)
{
	if (!lpszName || nLen == 0)return NULL;
	lpszName[0] = 0;
	gchar * lpszDot = g_utf8_strrchr(lpszFileName, MAX_PATH, '.');
	if (lpszDot)
	{
		int nCpy = nLen - 1;
		if (nCpy > lpszDot - lpszFileName)nCpy = lpszDot - lpszFileName;
		memcpy(lpszName, lpszFileName, nCpy);
		lpszName[nCpy] = 0;
	}
	else
	{
		strncpy(lpszName, lpszFileName, nLen);
	}
	return lpszName;
}
示例#15
0
文件: drun.c 项目: yusiwen/rofi
static void get_apps_history ( DRunModePrivateData *pd )
{
    unsigned int length = 0;
    gchar        *path  = g_build_filename ( cache_dir, DRUN_CACHE_FILE, NULL );
    gchar        **retv = history_get_list ( path, &length );
    for ( unsigned int index = 0; index < length; index++ ) {
        char **st = g_strsplit ( retv[index], ":::", 2 );
        if ( st && st[0] && st[1] ) {
            const gchar *basename = g_utf8_strrchr ( st[1], -1, G_DIR_SEPARATOR );
            if ( basename == NULL || !read_desktop_file ( pd, st[0], st[1], ++basename ) ) {
                history_remove ( path, retv[index] );
            }
        }
        g_strfreev ( st );
    }
    g_strfreev ( retv );
    g_free ( path );
    pd->history_length = pd->cmd_list_length;
}
示例#16
0
文件: fm-gtk-utils.c 项目: lxde/libfm
static gchar* fm_get_user_input_rename(GtkWindow* parent, const char* title, const char* msg, const char* default_text)
{
    GtkDialog* dlg = _fm_get_user_input_dialog( parent, title, msg);
    GtkEntry* entry = GTK_ENTRY(gtk_entry_new());
    gtk_entry_set_activates_default(entry, TRUE);

    if(default_text && default_text[0])
    {
        gtk_entry_set_text(entry, default_text);
        /* only select filename part without extension name. */
        if(default_text[1])
        {
            /* FIXME: handle the special case for *.tar.gz or *.tar.bz2
             * We should exam the file extension with g_content_type_guess, and
             * find out a longest valid extension name.
             * For example, the extension name of foo.tar.gz is .tar.gz, not .gz. */
            const char* dot = g_utf8_strrchr(default_text, -1, '.');
            if(dot)
                gtk_editable_select_region(GTK_EDITABLE(entry), 0, g_utf8_pointer_to_offset(default_text, dot));
            else
                gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
            /*
            const char* dot = default_text;
            while( dot = g_utf8_strchr(dot + 1, -1, '.') )
            {
                gboolean uncertain;
                char* type = g_content_type_guess(dot-1, NULL, 0, &uncertain);
                if(!g_content_type_is_unknown(type))
                {
                    g_free(type);
                    gtk_editable_select_region(entry, 0, g_utf8_pointer_to_offset(default_text, dot));
                    break;
                }
                g_free(type);
            }
            */
        }
    }

    return _fm_user_input_dialog_run(dlg, entry, NULL);
}
static GSList *
tracker_gsettings_get_all (gint *longest_name_length)
{
	typedef struct {
		const gchar *schema;
		const gchar *path;
	} SchemaWithPath;

	TrackerMinerManager *manager;
	GError *error = NULL;
	GSettings *settings;
	GSList *all = NULL;
	GSList *l;
	GSList *miners_available;
	GSList *valid_schemas = NULL;
	const gchar * const *schema;
	gint len = 0;
	SchemaWithPath components[] = {
		{ "Store", "store" },
		{ "Extract", "extract" },
		{ "Writeback", "writeback" },
		{ 0 }
	};
	SchemaWithPath *swp;

	/* Don't auto-start the miners here */
	manager = tracker_miner_manager_new_full (FALSE, &error);
	if (!manager) {
		g_printerr (_("Could not get GSettings for miners, manager could not be created, %s"),
		            error ? error->message : "unknown error");
		g_printerr ("\n");
		g_clear_error (&error);
		return NULL;
	}

	miners_available = tracker_miner_manager_get_available (manager);

	/* Get valid schemas so we don't try to load invalid ones */
	for (schema = g_settings_list_schemas (); schema && *schema; schema++) {
		if (!g_str_has_prefix (*schema, "org.freedesktop.Tracker.")) {
			continue;
		}

		valid_schemas = g_slist_prepend (valid_schemas, g_strdup (*schema));
	}

	/* Store / General */
	for (swp = components; swp && swp->schema; swp++) {
		gchar *schema;
		gchar *path;

		schema = g_strdup_printf ("org.freedesktop.Tracker.%s", swp->schema);
		path = g_strdup_printf ("/org/freedesktop/tracker/%s/", swp->path);

		/* If miner doesn't have a schema, no point in getting config */
		if (!tracker_string_in_gslist (schema, valid_schemas)) {
			g_free (path);
			g_free (schema);
			continue;
		}

		len = MAX (len, strlen (swp->schema));

		settings = g_settings_new_with_path (schema, path);
		if (settings) {
			ComponentGSettings *c = g_slice_new (ComponentGSettings);

			c->name = g_strdup (swp->schema);
			c->settings = settings;
			c->is_miner = FALSE;

			all = g_slist_prepend (all, c);
		}
	}

	/* Miners */
	for (l = miners_available; l; l = l->next) {
		const gchar *name;
		gchar *schema;
		gchar *name_lowercase;
		gchar *path;
		gchar *miner;

		miner = l->data;
		if (!miner) {
			continue;
		}

		name = g_utf8_strrchr (miner, -1, '.');
		if (!name) {
			continue;
		}

		name++;
		name_lowercase = g_utf8_strdown (name, -1);

		schema = g_strdup_printf ("org.freedesktop.Tracker.Miner.%s", name);
		path = g_strdup_printf ("/org/freedesktop/tracker/miner/%s/", name_lowercase);
		g_free (name_lowercase);

		/* If miner doesn't have a schema, no point in getting config */
		if (!tracker_string_in_gslist (schema, valid_schemas)) {
			g_free (path);
			g_free (schema);
			continue;
		}

		settings = g_settings_new_with_path (schema, path);
		g_free (path);
		g_free (schema);

		if (settings) {
			ComponentGSettings *c = g_slice_new (ComponentGSettings);

			c->name = g_strdup (name);
			c->settings = settings;
			c->is_miner = TRUE;

			all = g_slist_prepend (all, c);
			len = MAX (len, strlen (name));
		}
	}

	g_slist_foreach (valid_schemas, (GFunc) g_free, NULL);
	g_slist_free (valid_schemas);
	g_slist_foreach (miners_available, (GFunc) g_free, NULL);
	g_slist_free (miners_available);
	g_object_unref (manager);

	if (longest_name_length) {
		*longest_name_length = len;
	}

	return g_slist_reverse (all);
}
示例#18
0
文件: m3u8.c 项目: jwzl/ossbuild
/*
 * @data: a m3u8 playlist text data, taking ownership
 */
static gboolean
gst_m3u8_update (GstM3U8 * self, gchar * data, gboolean * updated)
{
    gint val, duration;
    gchar *title, *end;
//  gboolean discontinuity;
    GstM3U8 *list;

    g_return_val_if_fail (self != NULL, FALSE);
    g_return_val_if_fail (data != NULL, FALSE);
    g_return_val_if_fail (updated != NULL, FALSE);

    *updated = TRUE;

    /* check if the data changed since last update */
    if (self->last_data && g_str_equal (self->last_data, data)) {
        GST_DEBUG ("Playlist is the same as previous one");
        *updated = FALSE;
        g_free (data);
        return TRUE;
    }

    if (!g_str_has_prefix (data, "#EXTM3U")) {
        GST_WARNING ("Data doesn't start with #EXTM3U");
        g_free (data);
        return FALSE;
    }

    g_free (self->last_data);
    self->last_data = data;

    if (self->files) {
        g_list_foreach (self->files, (GFunc) gst_m3u8_media_file_free, NULL);
        g_list_free (self->files);
        self->files = NULL;
    }

    list = NULL;
    duration = -1;
    title = NULL;
    data += 7;
    while (TRUE) {
        end = g_utf8_strchr (data, -1, '\n');       /* FIXME: support \r\n */
        if (end)
            *end = '\0';

        if (data[0] != '#') {
            if (duration < 0 && list == NULL) {
                GST_LOG ("%s: got line without EXTINF or EXTSTREAMINF, dropping", data);
                goto next_line;
            }

            if (!gst_uri_is_valid (data)) {
                gchar *slash;
                if (!self->uri) {
                    GST_WARNING ("uri not set, can't build a valid uri");
                    goto next_line;
                }
                slash = g_utf8_strrchr (self->uri, -1, '/');
                if (!slash) {
                    GST_WARNING ("Can't build a valid uri");
                    goto next_line;
                }

                *slash = '\0';
                data = g_strdup_printf ("%s/%s", self->uri, data);
                *slash = '/';
            } else
                data = g_strdup (data);

            if (list != NULL) {
                if (g_list_find_custom (self->lists, data,
                                        (GCompareFunc) _m3u8_compare_uri)) {
                    GST_DEBUG ("Already have a list with this URI");
                    gst_m3u8_free (list);
                    g_free (data);
                } else {
                    gst_m3u8_set_uri (list, data);
                    self->lists = g_list_append (self->lists, list);
                }
                list = NULL;
            } else {
                GstM3U8MediaFile *file;
                file =
                    gst_m3u8_media_file_new (data, title, duration,
                                             self->mediasequence++);
                duration = -1;
                title = NULL;
                self->files = g_list_append (self->files, file);
            }

        } else if (g_str_has_prefix (data, "#EXT-X-ENDLIST")) {
            self->endlist = TRUE;
        } else if (g_str_has_prefix (data, "#EXT-X-VERSION:")) {
            if (int_from_string (data + 15, &data, &val))
                self->version = val;
        } else if (g_str_has_prefix (data, "#EXT-X-STREAM-INF:")) {
            gchar *v, *a;

            if (list != NULL) {
                GST_WARNING ("Found a list without a uri..., dropping");
                gst_m3u8_free (list);
            }

            list = gst_m3u8_new ();
            data = data + 18;
            while (data && parse_attributes (&data, &a, &v)) {
                if (g_str_equal (a, "BANDWIDTH")) {
                    if (!int_from_string (v, NULL, &list->bandwidth))
                        GST_WARNING ("Error while reading BANDWIDTH");
                } else if (g_str_equal (a, "PROGRAM-ID")) {
                    if (!int_from_string (v, NULL, &list->program_id))
                        GST_WARNING ("Error while reading PROGRAM-ID");
                } else if (g_str_equal (a, "CODECS")) {
                    g_free (list->codecs);
                    list->codecs = g_strdup (v);
                } else if (g_str_equal (a, "RESOLUTION")) {
                    if (!int_from_string (v, &v, &list->width))
                        GST_WARNING ("Error while reading RESOLUTION width");
                    if (!v || *v != '=') {
                        GST_WARNING ("Missing height");
                    } else {
                        v = g_utf8_next_char (v);
                        if (!int_from_string (v, NULL, &list->height))
                            GST_WARNING ("Error while reading RESOLUTION height");
                    }
                }
            }
        } else if (g_str_has_prefix (data, "#EXT-X-TARGETDURATION:")) {
            if (int_from_string (data + 22, &data, &val))
                self->targetduration = val;
        } else if (g_str_has_prefix (data, "#EXT-X-MEDIA-SEQUENCE:")) {
            if (int_from_string (data + 22, &data, &val))
                self->mediasequence = val;
        } else if (g_str_has_prefix (data, "#EXT-X-DISCONTINUITY")) {
            /* discontinuity = TRUE; */
        } else if (g_str_has_prefix (data, "#EXT-X-PROGRAM-DATE-TIME:")) {
            /* <YYYY-MM-DDThh:mm:ssZ> */
            GST_DEBUG ("FIXME parse date");
        } else if (g_str_has_prefix (data, "#EXT-X-ALLOW-CACHE:")) {
            g_free (self->allowcache);
            self->allowcache = g_strdup (data + 19);
        } else if (g_str_has_prefix (data, "#EXTINF:")) {
            if (!int_from_string (data + 8, &data, &val)) {
                GST_WARNING ("Can't read EXTINF duration");
                goto next_line;
            }
            duration = val;
            if (duration > self->targetduration)
                GST_WARNING ("EXTINF duration > TARGETDURATION");
            if (!data || *data != ',')
                goto next_line;
            data = g_utf8_next_char (data);
            if (data != end) {
                g_free (title);
                title = g_strdup (data);
            }
        } else {
            GST_LOG ("Ignored line: %s", data);
        }

next_line:
        if (!end)
            break;
        data = g_utf8_next_char (end);      /* skip \n */
    }

    /* redorder playlists by bitrate */
    if (self->lists)
        self->lists =
            g_list_sort (self->lists,
                         (GCompareFunc) gst_m3u8_compare_playlist_by_bitrate);

    return TRUE;
}
gboolean
rb_uri_is_hidden (const char *text_uri)
{
	return g_utf8_strrchr (text_uri, -1, '/')[1] == '.';
}
示例#20
0
static char *
get_filename_from_list (GList *file_list)
{
	GList *l;
	GString *common_part = NULL;
	gboolean matches = TRUE;
	guint offset = 0;
	const char *encoding;
	gboolean use_utf8 = TRUE;

	encoding = g_getenv ("G_FILENAME_ENCODING");

	if (encoding != NULL && strcasecmp (encoding, "UTF-8") != 0)
		use_utf8 = FALSE;

	if (file_list == NULL)
		return NULL;

	common_part = g_string_new ("");

	while (TRUE) {
		gunichar cur_char = '\0';
		for (l = file_list; l ; l = l->next) {
			char *path = NULL, *name = NULL;
			char *offset_name = NULL;

			path = g_filename_from_uri ((char *) l->data, NULL, NULL);
			if (!path)
				break;

			name = g_path_get_basename (path);

			if (!use_utf8) {
				char *tmp;

				tmp = g_filename_to_utf8 (name, -1, NULL, NULL, NULL);
				g_free (name);
				name = tmp;
			}

			if (!name) {
				g_free (path);
				break;
			}

			if (offset >= g_utf8_strlen (name, -1)) {
				g_free(name);
				g_free(path);
				matches = FALSE;
				break;
			}

			offset_name = g_utf8_offset_to_pointer (name, offset);

			if (offset_name == g_utf8_strrchr (name, -1, '.')) {
				g_free (name);
				g_free (path);
				matches = FALSE;
				break;
			}
			if (cur_char == '\0') {
				cur_char = g_utf8_get_char (offset_name);
			} else if (cur_char != g_utf8_get_char (offset_name)) {
				g_free (name);
				g_free (path);
				matches = FALSE;
				break;
			}
			g_free (name);
			g_free (path);
		}
		if (matches == TRUE &&
		    cur_char != '\0' &&
		    cur_char != '-' &&
		    cur_char != '_') {
			offset++;
			common_part = g_string_append_unichar (common_part,
					cur_char);
		} else {
			break;
		}
	}

	if (g_utf8_strlen (common_part->str, -1) < 4) {
		g_string_free (common_part, TRUE);
		return NULL;
	}

	return g_string_free (common_part, FALSE);
}
示例#21
0
static char *
impl_build_dest_uri (RBTransferTarget *target,
		     RhythmDBEntry *entry,
		     const char *media_type,
		     const char *extension)
{
	RBAndroidSourcePrivate *priv = GET_PRIVATE (target);
	const char *in_artist;
	char *artist, *album, *title;
	gulong track_number, disc_number;
	char *number;
	char *file = NULL;
	char *storage_uri;
	char *uri;
	char *ext;
	GFile *storage = NULL;

	if (extension != NULL) {
		ext = g_strconcat (".", extension, NULL);
	} else {
		ext = g_strdup ("");
	}

	in_artist = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_ALBUM_ARTIST);
	if (in_artist[0] == '\0') {
		in_artist = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_ARTIST);
	}
	artist = sanitize_path (in_artist);
	album = sanitize_path (rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_ALBUM));
	title = sanitize_path (rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_TITLE));

	/* we really do need to fix this so untagged entries actually have NULL rather than
	 * a translated string.
	 */
	if (strcmp (artist, _("Unknown")) == 0 && strcmp (album, _("Unknown")) == 0 &&
	    g_str_has_suffix (rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_LOCATION), title)) {
		/* file isn't tagged, so just use the filename as-is, replacing the extension */
		char *p;

		p = g_utf8_strrchr (title, -1, '.');
		if (p != NULL) {
			*p = '\0';
		}
		file = g_strdup_printf ("%s%s", title, ext);
	}

	if (file == NULL) {
		track_number = rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_TRACK_NUMBER);
		disc_number = rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_DISC_NUMBER);
		if (disc_number > 0)
			number = g_strdup_printf ("%.02u.%.02u", (guint)disc_number, (guint)track_number);
		else
			number = g_strdup_printf ("%.02u", (guint)track_number);

		/* artist/album/number - title */
		file = g_strdup_printf (G_DIR_SEPARATOR_S "%s" G_DIR_SEPARATOR_S "%s" G_DIR_SEPARATOR_S "%s%%20-%%20%s%s",
					artist, album, number, title, ext);
		g_free (number);
	}

	g_free (artist);
	g_free (album);
	g_free (title);
	g_free (ext);

	/* pick storage container to use somehow
	for (l = priv->storage; l != NULL; l = l->next) {
	}
	*/
	if (priv->storage)
		storage = priv->storage->data;

	if (storage == NULL) {
		rb_debug ("couldn't find a container to store anything in");
		g_free (file);
		return NULL;
	}

	storage_uri = g_file_get_uri (storage);
	uri = g_strconcat (storage_uri, file, NULL);
	g_free (file);
	g_free (storage_uri);

	return uri;
}
static char *
impl_build_dest_uri (RBRemovableMediaSource *source,
		     RhythmDBEntry *entry,
		     const char *mimetype,
		     const char *extension)
{
	RBGenericPlayerSourcePrivate *priv = GENERIC_PLAYER_SOURCE_GET_PRIVATE (source);
	char *artist, *album, *title;
	gulong track_number, disc_number;
	const char *folders;
	char **audio_folders;
	char *mount_path;
	char *number;
	char *file = NULL;
	char *path;
	char *ext;

	rb_debug ("building dest uri for entry at %s", rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_LOCATION));

	if (extension != NULL) {
		ext = g_strconcat (".", extension, NULL);
	} else {
		ext = g_strdup ("");
	}

	artist = sanitize_path (rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_ARTIST));
	album = sanitize_path (rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_ALBUM));
	title = sanitize_path (rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_TITLE));

	/* we really do need to fix this so untagged entries actually have NULL rather than
	 * a translated string.
	 */
	if (strcmp (artist, _("Unknown")) == 0 && strcmp (album, _("Unknown")) == 0 &&
	    g_str_has_suffix (rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_LOCATION), title)) {
		/* file isn't tagged, so just use the filename as-is, replacing the extension */
		char *p;

		p = g_utf8_strrchr (title, -1, '.');
		if (p != NULL) {
			*p = '\0';
		}
		file = g_strdup_printf ("%s%s", title, ext);
	}

	if (file == NULL) {
		int folder_depth;

		track_number = rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_TRACK_NUMBER);
		disc_number = rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_DISC_NUMBER);
		if (disc_number > 0)
			number = g_strdup_printf ("%.02u.%.02u", (guint)disc_number, (guint)track_number);
		else
			number = g_strdup_printf ("%.02u", (guint)track_number);

		g_object_get (priv->device_info, "folder-depth", &folder_depth, NULL);
		switch (folder_depth) {
		case 0:
			/* artist - album - number - title */
			file = g_strdup_printf ("%s - %s - %s - %s%s",
						artist, album, number, title, ext);
			break;

		case 1:
			/* artist - album/number - title */
			file = g_strdup_printf ("%s - %s" G_DIR_SEPARATOR_S "%s - %s%s",
						artist, album, number, title, ext);
			break;

		default: /* use this for players that don't care */
		case 2:
			/* artist/album/number - title */
			file = g_strdup_printf ("%s" G_DIR_SEPARATOR_S "%s" G_DIR_SEPARATOR_S "%s - %s%s",
						artist, album, number, title, ext);
			break;
		}
		g_free (number);
	}

	g_free (artist);
	g_free (album);
	g_free (title);
	g_free (ext);

	if (file == NULL)
		return NULL;

	g_object_get (priv->device_info, "audio-folders", &audio_folders, NULL);
	if (audio_folders != NULL && g_strv_length (audio_folders) > 0) {
		folders = g_strdup (audio_folders[0]);
	} else {
		folders = "";
	}
	g_strfreev (audio_folders);

	mount_path = rb_generic_player_source_get_mount_path (RB_GENERIC_PLAYER_SOURCE (source));
	path = g_build_filename (mount_path, folders, file, NULL);
	g_free (file);
	g_free (mount_path);

	/* TODO: check for duplicates, or just overwrite by default? */
	rb_debug ("dest file is %s", path);
	return path;
}
示例#23
0
文件: io.c 项目: SteveJones/j4status
static void
_j4status_io_server_add(J4statusIOContext *self, const gchar *server_desc)
{
    GSocketAddress *address = NULL;
    const gchar *path = NULL;

    if ( g_str_has_prefix(server_desc, "tcp:") )
    {
        GInetAddress *inet_address;
        const gchar *uri = server_desc + strlen("tcp:");
        gchar *port_str = g_utf8_strrchr(uri, -1, ':');
        if ( port_str == NULL )
        {
            /* No host, only port */
            port_str = (gchar *) uri;
            /* If you want IPv4, just use "0.0.0.0" */
            inet_address = g_inet_address_new_any(G_SOCKET_FAMILY_IPV6);
        }
        else
        {
            *port_str = '\0';
            ++port_str;
            inet_address = g_inet_address_new_from_string(uri);
        }


        guint64 port;
        port = g_ascii_strtoull(port_str, NULL, 10);
        if ( port > 65535 )
            return;


        address = g_inet_socket_address_new(inet_address, port);
    }

#ifdef G_OS_UNIX
    if ( g_str_has_prefix(server_desc, "unix:") )
    {
        path = server_desc + strlen("unix:");

        address = g_unix_socket_address_new(path);
    }
#endif /* G_OS_UNIX */

    if ( address == NULL )
        return;

    gboolean need_free_server = _j4status_io_add_server(self);

    GError *error = NULL;
    gboolean r;
    r = g_socket_listener_add_address(G_SOCKET_LISTENER(self->server), address, G_SOCKET_TYPE_STREAM, G_SOCKET_PROTOCOL_DEFAULT, NULL, NULL, &error);
    g_object_unref(address);

    if ( r )
    {
        if ( path != NULL )
            self->paths_to_unlink = g_list_prepend(self->paths_to_unlink, g_strdup(path));
        return;
    }

    g_warning("Couldn't add listener for '%s': %s", server_desc, error->message);
    g_clear_error(&error);

    if ( need_free_server )
    {
        g_object_unref(self->server);
        self->server = NULL;
    }
}
示例#24
0
/* Trash everything. */
gboolean cmd_wipe_in_line(struct cmdline* cmd, enum direction dir) {
	gchar* CR_l;
	gchar* CR_r;
	int chars;

	switch (dir) {

		case D_RIGHT:	/* Clear to right (in this line) */

			/* Find the ^M to the right. */
			if (cmd->is_utf8) {
				CR_r = g_utf8_strchr(
						cmd->data->str + cmd->pos,
						cmd->data->len - cmd->pos,
						g_utf8_get_char("\015"));
			}
			else
				CR_r = strchr(cmd->data->str + cmd->pos, '\015');

			if (!CR_r) {
				/* Erase everything to the right -- no ^Ms to take into
				   account. */
				cmd->data = g_string_truncate(cmd->data, cmd->pos);
			}
			else {
				/* Erase to the right up to the first ^M. */
				if (cmd->is_utf8) {
					chars = g_utf8_pointer_to_offset(
							cmd->data->str + cmd->pos, CR_r);
				}
				else
					chars = (CR_r - cmd->data->str) - cmd->pos;

				cmd_del_chars(cmd, chars);

				/* If we were at pos 0, this is the new pos 0; delete the
				   CR. */
				if (cmd->pos == 0)
					cmd_del_chars(cmd, 1);
			}
			break;

		case D_LEFT:	/* Clear to left -- I've never seen this happen. */
			g_return_val_if_reached(FALSE);
			break;

		case D_ALL:	/* Clear all (in this line). */

			/* Find the ^M to the right. */
			if (cmd->is_utf8) {
				CR_r = g_utf8_strchr(
						cmd->data->str + cmd->pos,
						cmd->data->len - cmd->pos,
						g_utf8_get_char("\015"));
			}
			else
				CR_r = strchr(cmd->data->str + cmd->pos, '\015');

			if (!CR_r)
				CR_r = cmd->data->str + cmd->data->len;
			
			/* Find the ^M to the left. */
			if (cmd->is_utf8) {
				CR_l = g_utf8_strrchr(cmd->data->str, cmd->pos,
						g_utf8_get_char("\015"));
			}
			else
				CR_l = g_strrstr_len(cmd->data->str, cmd->pos, "\015");

			if (!CR_l)
				CR_l = cmd->data->str;

			/* Delete everything in-between. */
			cmd->pos = CR_l - cmd->data->str;

			if (cmd->is_utf8)
				chars = g_utf8_pointer_to_offset(CR_l, CR_r);
			else 
				chars = CR_r - CR_l;

			cmd_del_chars(cmd, chars);

			break;

		default:
			g_return_val_if_reached(FALSE);
			break;
	}

	action_queue(A_SEND_CMD);
	return TRUE;
}
示例#25
0
文件: io.c 项目: SteveJones/j4status
static void
_j4status_io_add_stream(J4statusIOContext *self, const gchar *stream_desc)
{
    J4statusIOStream *stream;
    if ( g_strcmp0(stream_desc, "std") == 0 )
    {
        GOutputStream *out;
        GInputStream *in;
#ifdef G_OS_UNIX
        out = g_unix_output_stream_new(1, FALSE);
        in = g_unix_input_stream_new(0, FALSE);
#else /* ! G_OS_UNIX */
        return;
#endif /* ! G_OS_UNIX */

        stream = _j4status_io_stream_new(self);

        stream->out = g_data_output_stream_new(out);
        stream->in = g_data_input_stream_new(in);
        g_object_unref(out);
        g_object_unref(in);

        _j4status_io_stream_put_header(stream, self->header);
        g_data_input_stream_read_line_async(stream->in, G_PRIORITY_DEFAULT, NULL, _j4status_io_stream_read_callback, stream);

        goto end;
    }

    GSocketAddress *address = NULL;

    if ( g_str_has_prefix(stream_desc, "tcp:") )
    {
        const gchar *uri = stream_desc + strlen("tcp:");
        gchar *port_str = g_utf8_strrchr(uri, -1, ':');
        if ( port_str == NULL )
            /* No port, illegal stream description */
            return;

        *port_str = '\0';
        ++port_str;

        guint64 port;
        port = g_ascii_strtoull(port_str, NULL, 10);
        if ( port > 65535 )
            return;

        GInetAddress *inet_address;
        inet_address = g_inet_address_new_from_string(uri);

        address = g_inet_socket_address_new(inet_address, port);
    }

#ifdef G_OS_UNIX
    if ( g_str_has_prefix(stream_desc, "unix:") )
    {
        const gchar *path = stream_desc + strlen("unix:");

        address = g_unix_socket_address_new(path);
    }
#endif /* G_OS_UNIX */

    if ( address == NULL )
        return;

    stream = _j4status_io_stream_new(self);
    stream->address = address;

    _j4status_io_stream_connect(stream);

end:
    self->streams = g_list_prepend(self->streams, stream);
}
示例#26
0
/*
 * Get mime-type info of the specified file (slow, but more accurate):
 * To determine the mime-type of the file, mime_type_get_by_filename() is
 * tried first.  If the mime-type couldn't be determined, the content of
 * the file will be checked, which is much more time-consuming.
 * If statbuf is not NULL, it will be used to determine if the file is a directory,
 * or if the file is an executable file; otherwise, the function will call stat()
 * to gather this info itself. So if you already have stat info of the file,
 * pass it to the function to prevent checking the file stat again.
 * If you have basename of the file, pass it to the function can improve the
 * efifciency, too. Otherwise, the function will try to get the basename of
 * the specified file again.
*/
const char* mime_type_get_by_file( const char* filepath, struct stat64* statbuf, const char* basename )
{
    const char* type;
    struct stat64 _statbuf;

    if( statbuf == NULL || G_UNLIKELY( S_ISLNK(statbuf->st_mode) ) )
    {
        statbuf = &_statbuf;
        if( stat64 ( filepath, statbuf ) == -1 )
            return XDG_MIME_TYPE_UNKNOWN;
    }

    if( S_ISDIR( statbuf->st_mode ) )
        return XDG_MIME_TYPE_DIRECTORY;

    if( basename == NULL )
    {
        basename = g_utf8_strrchr( filepath, -1, '/' );
        if( G_LIKELY( basename ) )
            ++basename;
        else
            basename = filepath;
    }

    if( G_LIKELY(basename) )
    {
        type = mime_type_get_by_filename( basename, statbuf );
        if( G_LIKELY( strcmp( type, XDG_MIME_TYPE_UNKNOWN ) ) )
            return type;
        type = NULL;
    }

    //sfm added check for fifo due to hang on one system with a particular pipe
    // - is this needed?
    if( G_LIKELY(statbuf->st_size > 0 && !S_ISFIFO( statbuf->st_mode ) ) )
    {
        int fd = -1;
        char* data;

        /* Open the file and map it into memory */
        fd = open ( filepath, O_RDONLY, 0 );
        if ( fd != -1 )
        {
            int len = mime_cache_max_extent < statbuf->st_size ?  mime_cache_max_extent : statbuf->st_size;
#ifdef HAVE_MMAP
            data = (char*) mmap( NULL, len, PROT_READ, MAP_SHARED, fd, 0 );
#else
            /*
             * FIXME: Can g_alloca() be used here? It's very fast, but is it safe?
             * Actually, we can allocate a block of memory with the size of mime_cache_max_extent,
             * then we don't need to  do dynamic allocation/free every time, but multi-threading
             * will be a nightmare, so...
             */
            /* try to lock the common buffer */
            if( G_LIKELY( G_TRYLOCK( mime_magic_buf ) ) )
                data = mime_magic_buf;
            else /* the buffer is in use, allocate new one */
                data = g_malloc( len );

            len = read( fd, data, len );

            if( G_UNLIKELY( len == -1 ) )
            {
                if( G_LIKELY( data == mime_magic_buf ) )
                    G_UNLOCK( mime_magic_buf );
                else
                    g_free( data );
                data = (void*)-1;
            }
#endif
            if( data != (void*)-1 )
            {
                int i;
                for( i = 0; ! type && i < n_caches; ++i )
                    type = mime_cache_lookup_magic( caches[i], data, len );

                /* Check for executable file */
                if( ! type && g_file_test( filepath, G_FILE_TEST_IS_EXECUTABLE ) )
                    type = XDG_MIME_TYPE_EXECUTABLE;

                /* fallback: check for plain text */
                if( ! type )
                {
                    if( mime_type_is_data_plain_text( data, len > TEXT_MAX_EXTENT ? TEXT_MAX_EXTENT : len ) )
                        type = XDG_MIME_TYPE_PLAIN_TEXT;
                }

#ifdef HAVE_MMAP
                munmap ( (char*)data, len );
#else
                if( G_LIKELY( data == mime_magic_buf ) )
                    G_UNLOCK( mime_magic_buf );  /* unlock the common buffer */
                else /* we use our own buffer */
                    g_free( data );
#endif
            }
            close( fd );
        }
    }
    else
    {
        /* empty file can be viewed as text file */
        type = XDG_MIME_TYPE_PLAIN_TEXT;
    }
    return type && *type ? type : XDG_MIME_TYPE_UNKNOWN;
}