Esempio n. 1
0
const char *
_xdg_mime_magic_lookup_data (XdgMimeMagic *mime_magic,
			     const void   *data,
			     size_t        len,
			     int           *result_prio,
                             const char   *mime_types[],
                             int           n_mime_types)
{
  XdgMimeMagicMatch *match;
  const char *mime_type;
  int n;
  int prio;

  prio = 0;
  mime_type = NULL;
  for (match = mime_magic->match_list; match; match = match->next)
    {
      if (_xdg_mime_magic_match_compare_to_data (match, data, len))
	{
	  prio = match->priority;
	  mime_type = match->mime_type;
	  break;
	}
      else 
	{
	  for (n = 0; n < n_mime_types; n++)
	    {
	      if (mime_types[n] && 
		  _xdg_mime_mime_type_equal (mime_types[n], match->mime_type))
		mime_types[n] = NULL;
	    }
	}
    }

  if (mime_type == NULL)
    {
      for (n = 0; n < n_mime_types; n++)
	{
	  if (mime_types[n])
	    mime_type = mime_types[n];
	}
    }
  
  if (result_prio)
    *result_prio = prio;

  return mime_type;
}
Esempio n. 2
0
const char *
_xdg_mime_magic_lookup_data (XdgMimeMagic *mime_magic,
			     const void   *data,
			     size_t        len)
{
  XdgMimeMagicMatch *match;

  for (match = mime_magic->match_list; match; match = match->next)
    {
      if (_xdg_mime_magic_match_compare_to_data (match, data, len))
	{
	  return match->mime_type;
	}
    }

  return NULL;
}
Esempio n. 3
0
const char *
_xdg_mime_magic_lookup_data (XdgMimeMagic *mime_magic,
			     const void   *data,
			     size_t        len,
                             const char   *mime_types[],
                             int           n_mime_types)
{
  XdgMimeMagicMatch *match;
  const char *mime_type;
  int n;

  mime_type = NULL;
  for (match = mime_magic->match_list; match; match = match->next)
    {
      if (_xdg_mime_magic_match_compare_to_data (match, data, len))
	{
	  if ((mime_type == NULL) || (_xdg_mime_mime_type_subclass (match->mime_type, mime_type))) {
	    mime_type = match->mime_type;
	  }
	}
      else 
	{
	  for (n = 0; n < n_mime_types; n++)
	    {
	      if (mime_types[n] && 
		  _xdg_mime_mime_type_equal (mime_types[n], match->mime_type))
		mime_types[n] = NULL;
	    }
	}
    }

  if (mime_type == NULL)
    {
      for (n = 0; n < n_mime_types; n++)
	{
	  if (mime_types[n])
	    mime_type = mime_types[n];
	}
    }

  return mime_type;
}
Esempio n. 4
0
const char *
_xdg_mime_magic_lookup_data (XdgMimeMagic *mime_magic,
			     const void   *data,
			     size_t        len,
                             const char   *mime_types[],
                             int           n_mime_types)
{
  XdgMimeMagicMatch *match;
  const char *mime_type;
  int n;
  int priority;
  int had_match;

  mime_type = NULL;
  priority = 0;
  had_match = 0;
  for (match = mime_magic->match_list; match; match = match->next)
    {
      if (_xdg_mime_magic_match_compare_to_data (match, data, len))
	{
	  if (!had_match || match->priority > priority ||
	      (mime_type != NULL && _xdg_mime_mime_type_subclass (match->mime_type, mime_type)))
	    {
	      mime_type = match->mime_type;
	      priority = match->priority;
	    }
	  /* Is this another match at same priority which is not the same
	   * type again, or a sub-type */
	  else if (had_match && match->priority == priority && mime_type &&
		   strcmp(mime_type, match->mime_type)!=0 &&
		   !_xdg_mime_mime_type_subclass (mime_type, match->mime_type))
	    /* multiple unrelated patterns with the same priority matched,
	     * so we can't tell what type this is. */
	    mime_type = NULL;

	  had_match = 1;
	}
      else 
	{
	  for (n = 0; n < n_mime_types; n++)
	    {
	      if (mime_types[n] && 
		  _xdg_mime_mime_type_equal (mime_types[n], match->mime_type))
		mime_types[n] = NULL;
	    }
	}
    }

  if (mime_type == NULL)
    {
      for (n = 0; n < n_mime_types; n++)
	{
	  if (mime_types[n])
	    mime_type = mime_types[n];
	}
    }

  if (mime_type == NULL)
    {
      if(_rox_buffer_looks_like_text(data, len))
	 mime_type = XDG_MIME_TYPE_UNKNOWN_TEXT;
    }
  
  return mime_type;
}