Back to index

libcitadel  8.12
Typedefs | Functions
xdgmimemagic.h File Reference
#include <unistd.h>
#include "xdgmime.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef struct XdgMimeMagic

Functions

XdgMimeMagic_xdg_mime_magic_new (void)
void _xdg_mime_magic_read_from_file (XdgMimeMagic *mime_magic, const char *file_name)
void _xdg_mime_magic_free (XdgMimeMagic *mime_magic)
int _xdg_mime_magic_get_buffer_extents (XdgMimeMagic *mime_magic)
const char * _xdg_mime_magic_lookup_data (XdgMimeMagic *mime_magic, const void *data, size_t len, const char *mime_types[], int n_mime_types)

Typedef Documentation

typedef struct XdgMimeMagic

Definition at line 33 of file xdgmimemagic.h.


Function Documentation

void _xdg_mime_magic_free ( XdgMimeMagic mime_magic)

Definition at line 643 of file xdgmimemagic.c.

{
  if (mime_magic) {
    _xdg_mime_magic_match_free (mime_magic->match_list);
    free (mime_magic);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 652 of file xdgmimemagic.c.

{
  return mime_magic->max_extent;
}

Here is the caller graph for this function:

const char* _xdg_mime_magic_lookup_data ( XdgMimeMagic mime_magic,
const void *  data,
size_t  len,
const char *  mime_types[],
int  n_mime_types 
)

Definition at line 658 of file xdgmimemagic.c.

{
  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;
           }
         else if (had_match && match->priority == priority &&
                 !_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];
       }
    }

  return mime_type;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 637 of file xdgmimemagic.c.

{
  return calloc (1, sizeof (XdgMimeMagic));
}

Here is the caller graph for this function:

void _xdg_mime_magic_read_from_file ( XdgMimeMagic mime_magic,
const char *  file_name 
)

Definition at line 805 of file xdgmimemagic.c.

{
  FILE *magic_file;
  char header[12];

  magic_file = fopen (file_name, "r");

  if (magic_file == NULL)
    return;

  if (fread (header, 1, 12, magic_file) == 12)
    {
      if (memcmp ("MIME-Magic\0\n", header, 12) == 0)
        _xdg_mime_magic_read_magic_file (mime_magic, magic_file);
    }

  fclose (magic_file);
}

Here is the call graph for this function:

Here is the caller graph for this function: