Esempio n. 1
0
int
xdg_mime_mime_type_equal (const char *mime_a,
			  const char *mime_b)
{
  xdg_mime_init ();

  return _xdg_mime_mime_type_equal (mime_a, mime_b);
}
Esempio n. 2
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;
}
static const char *
cache_magic_lookup_data (XdgMimeCache *cache, 
			 const void   *data, 
			 size_t        len, 
			 int          *prio,
			 const char   *mime_types[],
			 int           n_mime_types)
{
  xdg_uint32_t list_offset;
  xdg_uint32_t n_entries;
  xdg_uint32_t offset;

  int j, n;

  *prio = 0;

  list_offset = GET_UINT32 (cache->buffer, 24);
  n_entries = GET_UINT32 (cache->buffer, list_offset);
  offset = GET_UINT32 (cache->buffer, list_offset + 8);
  
  for (j = 0; j < n_entries; j++)
    {
      const char *match;

      match = cache_magic_compare_to_data (cache, offset + 16 * j, 
					   data, len, prio);
      if (match)
	return match;
      else
	{
	  xdg_uint32_t mimetype_offset;
	  const char *non_match;
	  
	  mimetype_offset = GET_UINT32 (cache->buffer, offset + 16 * j + 4);
	  non_match = cache->buffer + mimetype_offset;

	  for (n = 0; n < n_mime_types; n++)
	    {
	      if (mime_types[n] && 
		  _xdg_mime_mime_type_equal (mime_types[n], non_match))
		mime_types[n] = NULL;
	    }
	}
    }

  return NULL;
}
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;

  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. 5
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;
}