]> git.proxmox.com Git - libxdgmime-perl.git/commitdiff
Squashed 'xdgmime-source/' changes from 28b70c4..3e7ee2d
authorStoiko Ivanov <s.ivanov@proxmox.com>
Wed, 24 May 2023 11:06:12 +0000 (13:06 +0200)
committerStoiko Ivanov <s.ivanov@proxmox.com>
Wed, 24 May 2023 11:06:12 +0000 (13:06 +0200)
3e7ee2d Add SPDX-License-Identifier tags in source files
d385402 src/: LGPLv2+ -> LGPLv2.1+
0122cb5 xdgmime: Finer handling for cases where mmap() is not available
c501188 xdgmime: Prevent infinite loops from badly-formed MIME registrations
462198f xdgmime: Add xdg_mime_set_dirs() method to override XDG envvars
1414820 Add missing S_ISREG definitions for VS2022
ecbc52c xdgmimemagic: Add an assertion to clarify state after hitting an error
95e3187 test-mime-data: output errors to stderr
fe2f298 ci: Test meson build
ade1de1 build: Add meson support
0722d76 ci: Fix shared-mime-info test not exercising our build
92f6a09 xdgmimemagic: Fix unused variable warning when !LITTLE_ENDIAN
50a624b Fix segfaults due to strict ISO C99 mode enforcement
7cc63be Makefile: Add support for POSIX make
d64963b test-mime-data: fail when an error occurs
1c521ab add OOM handling in mimemagic
1318486 Silence an uninitialize variable warning
3ae3ed6 xdgmime: Call xdg_mime_init() before xdg_mime_list_mime_parents()

git-subtree-dir: xdgmime-source
git-subtree-split: 3e7ee2dc8edde524858ad9a109dabe26980cf2e5

23 files changed:
.gitlab-ci.yml
meson.build [new file with mode: 0644]
src/Makefile
src/meson.build [new file with mode: 0644]
src/print-mime-data.c
src/test-mime-data.c
src/test-mime.c
src/xdgmime.c
src/xdgmime.h
src/xdgmimealias.c
src/xdgmimealias.h
src/xdgmimecache.c
src/xdgmimecache.h
src/xdgmimeglob.c
src/xdgmimeglob.h
src/xdgmimeicon.c
src/xdgmimeicon.h
src/xdgmimeint.c
src/xdgmimeint.h
src/xdgmimemagic.c
src/xdgmimemagic.h
src/xdgmimeparent.c
src/xdgmimeparent.h

index a1ea511499483b8b0387d40960ea2bf3478548e0..9be9c50bd931e7b147cce940cda283396908f53e 100644 (file)
@@ -15,7 +15,7 @@ variables:
                 gettext-devel
                 meson
 
-build:meson:
+build:autotools:
   before_script:
     - dnf update -y --nogpgcheck
     - dnf install -y --nogpgcheck $DEPENDENCIES
@@ -25,5 +25,19 @@ build:meson:
     # Compile shared-mime-info
     - git clone https://gitlab.freedesktop.org/xdg/shared-mime-info.git
     - cd shared-mime-info
+    - meson _build -Dxdgmime-path=$PWD/../
+    - ninja -C _build test
+
+build:meson:
+  before_script:
+    - dnf update -y --nogpgcheck
+    - dnf install -y --nogpgcheck $DEPENDENCIES
+  script:
     - meson _build
+    - ninja -C _build
+
+    # Compile shared-mime-info
+    - git clone https://gitlab.freedesktop.org/xdg/shared-mime-info.git
+    - cd shared-mime-info
+    - meson _build -Dxdgmime-path=$PWD/../_build/
     - ninja -C _build test
diff --git a/meson.build b/meson.build
new file mode 100644 (file)
index 0000000..2b16fda
--- /dev/null
@@ -0,0 +1,17 @@
+project('xdgmime', 'c',
+    version: '0.0',
+    default_options: ['c_std=c99', 'warning_level=1', 'debug=true'],
+    meson_version: '>=0.48.0',
+)
+
+add_project_arguments(
+    '-D_POSIX_C_SOURCE=200809L',
+    '-DXDG_PREFIX=xdg_test',
+    '-DHAVE_MMAP',
+    '-Wmissing-prototypes',
+    '-Wno-sign-compare',
+    language: 'c',
+    native: true,
+)
+
+subdir('src')
index 6c97f94df057a5090244a8dd26cda84b737b6a3a..44c44f7865edc12a1cc590a1e780be5f5adb2739 100644 (file)
@@ -1,14 +1,22 @@
+.POSIX:
+.PHONY: all clean
 
-CFLAGS=-Wall -Wmissing-prototypes  -Wno-sign-compare -g -DXDG_PREFIX=xdg_test -DHAVE_MMAP
+C_STD = -std=c99 -D_POSIX_C_SOURCE=200809L
+ALL_CFLAGS = $(C_STD) -c -g -DXDG_PREFIX=xdg_test -DHAVE_MMAP -Wall -Wmissing-prototypes -Wno-sign-compare $(CFLAGS)
+
+.c.o:
+       $(CC) $(ALL_CFLAGS) -o $@ $<
 
 all: test-mime test-mime-data print-mime-data
 
-test-mime: xdgmime.o xdgmimeglob.o xdgmimeint.o xdgmimemagic.o xdgmimealias.o xdgmimeparent.o xdgmimecache.o xdgmimeicon.o
+test-mime: test-mime.o xdgmime.o xdgmimeglob.o xdgmimeint.o xdgmimemagic.o xdgmimealias.o xdgmimeparent.o xdgmimecache.o xdgmimeicon.o
+       $(CC) $(LDFLAGS) -o $@ $?
 
-test-mime-data: xdgmime.o xdgmimeglob.o xdgmimeint.o xdgmimemagic.o xdgmimealias.o xdgmimeparent.o xdgmimecache.o xdgmimeicon.o
+test-mime-data: test-mime-data.o xdgmime.o xdgmimeglob.o xdgmimeint.o xdgmimemagic.o xdgmimealias.o xdgmimeparent.o xdgmimecache.o xdgmimeicon.o
+       $(CC) $(LDFLAGS) -o $@ $?
 
-print-mime-data: xdgmime.o xdgmimeglob.o xdgmimeint.o xdgmimemagic.o xdgmimealias.o xdgmimeparent.o xdgmimecache.o xdgmimeicon.o
+print-mime-data: print-mime-data.o xdgmime.o xdgmimeglob.o xdgmimeint.o xdgmimemagic.o xdgmimealias.o xdgmimeparent.o xdgmimecache.o xdgmimeicon.o
+       $(CC) $(LDFLAGS) -o $@ $?
 
 clean:
        rm -f *~ *.o test-mime test-mime-data print-mime-data
-
diff --git a/src/meson.build b/src/meson.build
new file mode 100644 (file)
index 0000000..ceb407c
--- /dev/null
@@ -0,0 +1,35 @@
+libcommon = static_library('common',
+    'xdgmime.c',
+    'xdgmimeglob.c',
+    'xdgmimeint.c',
+    'xdgmimemagic.c',
+    'xdgmimealias.c',
+    'xdgmimeparent.c',
+    'xdgmimecache.c',
+    'xdgmimeicon.c',
+    native: true,
+)
+
+test_mime = executable('test-mime',
+    'test-mime.c',
+    link_with: libcommon,
+    native: true,
+    install: false,
+)
+meson.override_find_program('test-mime', test_mime)
+
+test_mime_data = executable('test-mime-data',
+    'test-mime-data.c',
+    link_with: libcommon,
+    native: true,
+    install: false,
+)
+meson.override_find_program('test-mime-data', test_mime_data)
+
+print_mime_data = executable('print-mime-data',
+    'print-mime-data.c',
+    link_with: libcommon,
+    native: true,
+    install: false,
+)
+meson.override_find_program('print-mime-data', print_mime_data)
index 2549e73e1f464988ae395770c679a5f9ceb7b921..f51528e49a2353bb5635c7a55767514d9c9f045e 100644 (file)
@@ -6,23 +6,7 @@
  * Copyright (C) 2005  Matthias Clasen <mclasen@redhat.com>
  * Copyright (C) 2012  Bastien Nocera <hadess@hadess.net>
  *
- * Licensed under the Academic Free License version 2.0
- * Or under the following terms:
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
  */
 
 #include <stdio.h>
index 1dbc6368facad80529543098b9bd4d940eb4b64a..14fb94e549d05ed35fece933d442a86b332a0ff1 100644 (file)
@@ -5,28 +5,13 @@
  * Copyright (C) 2005  Red Hat, Inc.
  * Copyright (C) 2005  Matthias Clasen <mclasen@redhat.com>
  *
- * Licensed under the Academic Free License version 2.0
- * Or under the following terms:
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
  */
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <strings.h>
 #include <libgen.h>
 
 #include "xdgmime.h"
@@ -63,8 +48,8 @@ check_mime_type (const char *mt,
       else
        {
          if (verbose > 0)
-           printf ("%s, '%s' test: expected %s, got %s\n", 
-                   filename, test, mt_expected, mt);
+           fprintf (stderr, "%s, '%s' test: expected %s, got %s\n",
+                    filename, test, mt_expected, mt);
        }
 
     }
@@ -114,7 +99,7 @@ test_by_data (const char *dir,
 
   if (file == NULL)
     {
-      printf ("Could not open %s\n", path);
+      fprintf (stderr, "Could not open %s\n", path);
       error++;
 
       return;
@@ -125,7 +110,7 @@ test_by_data (const char *dir,
 
   if (data == NULL)
     {
-      printf ("Failed to allocate memory for file %s\n", filename);
+      fprintf (stderr, "Failed to allocate memory for file %s\n", filename);
       error++;
 
       fclose (file);
@@ -136,7 +121,7 @@ test_by_data (const char *dir,
   
   if (ferror (file))
     {
-      printf ("Error reading file %s\n", path);
+      fprintf (stderr, "Error reading file %s\n", path);
       error++;
 
       free (data);
@@ -200,7 +185,7 @@ read_from_file (const char *filename)
 
   if (file == NULL)
     {
-      printf ("Could not open %s\n", filename);
+      fprintf (stderr, "Could not open %s\n", filename);
       exit (1);
     }
 
@@ -217,7 +202,7 @@ read_from_file (const char *filename)
       space = strchr (rest, ' ');
       if (!space)
        {
-         printf ("Malformed line in %s:%d\n\t%s\n", filename, lineno, line);
+         fprintf (stderr, "Malformed line in %s:%d\n\t%s\n", filename, lineno, line);
          continue;
        }
 
@@ -312,22 +297,15 @@ main (int argc, char *argv[])
        read_from_file (argv[i]);
     }
   
-  if (error > 0 || failed > 0)
-    {
-      printf ("%d errors, %d comparisons, %d failed",
-             error, total, failed);
-      if (xfailed > 0)
-       printf (" (%d expected)", xfailed);
-      if (xmatch > 0)
-       printf (", %d unexpected successes", xmatch);
-      printf ("\n");
-
-      if (xmatch > 0)
-        return 1;
-      if (xfailed == failed)
-        return 0;
-      return 1;
-    }
-
+  printf ("%d errors, %d comparisons, %d failed",
+          error, total, failed);
+  if (xfailed > 0)
+    printf (" (%d expected)", xfailed);
+  if (xmatch > 0)
+    printf (", %d unexpected successes", xmatch);
+  printf ("\n");
+
+  if (error > 0 || xmatch > 0 || failed != xfailed)
+    return 1;
   return 0;
 }
index e68222a31dd4153f4605d2051be4684038be3fd2..a194871be1a7997cdf527d95337109d591699771 100644 (file)
@@ -2,27 +2,12 @@
  * Copyright (C) 2003,2004  Red Hat, Inc.
  * Copyright (C) 2003,2004  Jonathan Blandford <jrb@alum.mit.edu>
  *
- * Licensed under the Academic Free License version 2.0
- * Or under the following terms:
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
  */
 #include "xdgmime.h"
 #include "xdgmimeglob.h"
 #include <string.h>
+#include <strings.h>
 #include <stdio.h>
 
 
index 90a0ed0d56707bb1ae694568a17df3aac3aec008..b6406518863eb90063c7aba25b5eb8244402455f 100644 (file)
@@ -6,23 +6,7 @@
  * Copyright (C) 2003,2004  Red Hat, Inc.
  * Copyright (C) 2003,2004  Jonathan Blandford <jrb@alum.mit.edu>
  *
- * Licensed under the Academic Free License version 2.0
- * Or under the following terms:
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
  */
 
 #ifdef HAVE_CONFIG_H
 #include <unistd.h>
 #include <assert.h>
 
+#ifndef S_ISREG
+#define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
+#endif
+
 typedef struct XdgDirTimeList XdgDirTimeList;
 typedef struct XdgCallbackList XdgCallbackList;
 
@@ -60,6 +48,8 @@ static XdgCallbackList *callback_list = NULL;
 static XdgIconList *icon_list = NULL;
 static XdgIconList *generic_icon_list = NULL;
 
+static char **xdg_dirs = NULL;  /* NULL terminated */
+
 XdgMimeCache **_caches = NULL;
 static int n_caches = 0;
 
@@ -144,8 +134,8 @@ xdg_mime_init_from_directory (const char *directory,
 
   assert (directory != NULL);
 
-  file_name = malloc (strlen (directory) + strlen ("/mime/mime.cache") + 1);
-  strcpy (file_name, directory); strcat (file_name, "/mime/mime.cache");
+  file_name = malloc (strlen (directory) + strlen ("/mime.cache") + 1);
+  strcpy (file_name, directory); strcat (file_name, "/mime.cache");
   if (stat (file_name, &st) == 0)
     {
       XdgMimeCache *cache = _xdg_mime_cache_new_from_file (file_name);
@@ -164,8 +154,8 @@ xdg_mime_init_from_directory (const char *directory,
     }
   free (file_name);
 
-  file_name = malloc (strlen (directory) + strlen ("/mime/globs2") + 1);
-  strcpy (file_name, directory); strcat (file_name, "/mime/globs2");
+  file_name = malloc (strlen (directory) + strlen ("/globs2") + 1);
+  strcpy (file_name, directory); strcat (file_name, "/globs2");
   if (stat (file_name, &st) == 0)
     {
       _xdg_mime_glob_read_from_file (global_hash, file_name, TRUE);
@@ -174,8 +164,8 @@ xdg_mime_init_from_directory (const char *directory,
   else
     {
       free (file_name);
-      file_name = malloc (strlen (directory) + strlen ("/mime/globs") + 1);
-      strcpy (file_name, directory); strcat (file_name, "/mime/globs");
+      file_name = malloc (strlen (directory) + strlen ("/globs") + 1);
+      strcpy (file_name, directory); strcat (file_name, "/globs");
       if (stat (file_name, &st) == 0)
         {
           _xdg_mime_glob_read_from_file (global_hash, file_name, FALSE);
@@ -187,8 +177,8 @@ xdg_mime_init_from_directory (const char *directory,
         }
     }
 
-  file_name = malloc (strlen (directory) + strlen ("/mime/magic") + 1);
-  strcpy (file_name, directory); strcat (file_name, "/mime/magic");
+  file_name = malloc (strlen (directory) + strlen ("/magic") + 1);
+  strcpy (file_name, directory); strcat (file_name, "/magic");
   if (stat (file_name, &st) == 0)
     {
       _xdg_mime_magic_read_from_file (global_magic, file_name);
@@ -199,69 +189,81 @@ xdg_mime_init_from_directory (const char *directory,
       free (file_name);
     }
 
-  file_name = malloc (strlen (directory) + strlen ("/mime/aliases") + 1);
-  strcpy (file_name, directory); strcat (file_name, "/mime/aliases");
+  file_name = malloc (strlen (directory) + strlen ("/aliases") + 1);
+  strcpy (file_name, directory); strcat (file_name, "/aliases");
   _xdg_mime_alias_read_from_file (alias_list, file_name);
   free (file_name);
 
-  file_name = malloc (strlen (directory) + strlen ("/mime/subclasses") + 1);
-  strcpy (file_name, directory); strcat (file_name, "/mime/subclasses");
+  file_name = malloc (strlen (directory) + strlen ("/subclasses") + 1);
+  strcpy (file_name, directory); strcat (file_name, "/subclasses");
   _xdg_mime_parent_read_from_file (parent_list, file_name);
   free (file_name);
 
-  file_name = malloc (strlen (directory) + strlen ("/mime/icons") + 1);
-  strcpy (file_name, directory); strcat (file_name, "/mime/icons");
+  file_name = malloc (strlen (directory) + strlen ("/icons") + 1);
+  strcpy (file_name, directory); strcat (file_name, "/icons");
   _xdg_mime_icon_read_from_file (icon_list, file_name);
   free (file_name);
 
-  file_name = malloc (strlen (directory) + strlen ("/mime/generic-icons") + 1);
-  strcpy (file_name, directory); strcat (file_name, "/mime/generic-icons");
+  file_name = malloc (strlen (directory) + strlen ("/generic-icons") + 1);
+  strcpy (file_name, directory); strcat (file_name, "/generic-icons");
   _xdg_mime_icon_read_from_file (generic_icon_list, file_name);
   free (file_name);
 
   return FALSE; /* Keep processing */
 }
 
-/* Runs a command on all the directories in the search path */
+/* Set @xdg_dirs from the environment. It must not have been set already. */
 static void
-xdg_run_command_on_dirs (XdgDirectoryFunc  func,
-                        void             *user_data)
+xdg_init_dirs (void)
 {
-  const char *xdg_data_home;
-  const char *xdg_data_dirs;
+  const char *xdg_data_home, *home, *xdg_data_dirs;
   const char *ptr;
+  size_t n_dirs = 0;
+  size_t i, current_dir;
+
+  assert (xdg_dirs == NULL);
 
   xdg_data_home = getenv ("XDG_DATA_HOME");
-  if (xdg_data_home)
+  home = getenv ("HOME");
+  xdg_data_dirs = getenv ("XDG_DATA_DIRS");
+
+  if (xdg_data_dirs == NULL)
+    xdg_data_dirs = "/usr/local/share/:/usr/share/";
+
+  /* Work out how many dirs we’re dealing with. */
+  if (xdg_data_home != NULL || home != NULL)
+    n_dirs++;
+  n_dirs++;  /* initial entry in @xdg_data_dirs */
+  for (i = 0; xdg_data_dirs[i] != '\0'; i++)
+    if (xdg_data_dirs[i] == ':')
+      n_dirs++;
+
+  xdg_dirs = calloc (n_dirs + 1  /* NULL terminator */, sizeof (char *));
+  current_dir = 0;
+
+  /* $XDG_DATA_HOME */
+  if (xdg_data_home != NULL)
     {
-      if ((func) (xdg_data_home, user_data))
-       return;
+      char *mime_subdir;
+
+      mime_subdir = malloc (strlen (xdg_data_home) + strlen ("/mime/") + 1);
+      strcpy (mime_subdir, xdg_data_home);
+      strcat (mime_subdir, "/mime/");
+
+      xdg_dirs[current_dir++] = mime_subdir;
     }
-  else
+  else if (home != NULL)
     {
-      const char *home;
+      char *guessed_xdg_home;
 
-      home = getenv ("HOME");
-      if (home != NULL)
-       {
-         char *guessed_xdg_home;
-         int stop_processing;
-
-         guessed_xdg_home = malloc (strlen (home) + strlen ("/.local/share/") + 1);
-         strcpy (guessed_xdg_home, home);
-         strcat (guessed_xdg_home, "/.local/share/");
-         stop_processing = (func) (guessed_xdg_home, user_data);
-         free (guessed_xdg_home);
+      guessed_xdg_home = malloc (strlen (home) + strlen ("/.local/share/mime/") + 1);
+      strcpy (guessed_xdg_home, home);
+      strcat (guessed_xdg_home, "/.local/share/mime/");
 
-         if (stop_processing)
-           return;
-       }
+      xdg_dirs[current_dir++] = guessed_xdg_home;
     }
 
-  xdg_data_dirs = getenv ("XDG_DATA_DIRS");
-  if (xdg_data_dirs == NULL)
-    xdg_data_dirs = "/usr/local/share/:/usr/share/";
-
+  /* $XDG_DATA_DIRS */
   ptr = xdg_data_dirs;
 
   while (*ptr != '\000')
@@ -269,33 +271,82 @@ xdg_run_command_on_dirs (XdgDirectoryFunc  func,
       const char *end_ptr;
       char *dir;
       int len;
-      int stop_processing;
 
       end_ptr = ptr;
       while (*end_ptr != ':' && *end_ptr != '\000')
-       end_ptr ++;
+        end_ptr ++;
 
       if (end_ptr == ptr)
-       {
-         ptr++;
-         continue;
-       }
+        {
+          ptr++;
+          continue;
+        }
 
       if (*end_ptr == ':')
-       len = end_ptr - ptr;
+        len = end_ptr - ptr;
       else
-       len = end_ptr - ptr + 1;
-      dir = malloc (len + 1);
+        len = end_ptr - ptr + 1;
+      dir = malloc (len + strlen ("/mime/") + 1);
       strncpy (dir, ptr, len);
       dir[len] = '\0';
-      stop_processing = (func) (dir, user_data);
-      free (dir);
+      strcat (dir, "/mime/");
 
-      if (stop_processing)
-       return;
+      xdg_dirs[current_dir++] = dir;
 
       ptr = end_ptr;
     }
+
+  /* NULL terminator */
+  xdg_dirs[current_dir] = NULL;
+
+  need_reread = TRUE;
+}
+
+/* Runs a command on all the directories in the search path (@xdg_dirs). */
+static void
+xdg_run_command_on_dirs (XdgDirectoryFunc  func,
+                         void             *user_data)
+{
+  size_t i;
+
+  if (xdg_dirs == NULL)
+    xdg_init_dirs ();
+
+  for (i = 0; xdg_dirs[i] != NULL; i++)
+    {
+      if ((func) (xdg_dirs[i], user_data))
+        return;
+    }
+}
+
+/* Allows the calling code to override the directories used by xdgmime, without
+ * having to change environment variables in a running process (which is not
+ * thread safe). This is intended to be used by tests. The changes will be
+ * picked up by xdg_mime_init() next time public API is called.
+ *
+ * This will set @xdg_dirs. Directories in @dirs must be complete, including
+ * the conventional `/mime` subdirectory. This is to allow tests to override
+ * them without the need to create a subdirectory. */
+void
+xdg_mime_set_dirs (const char * const *dirs)
+{
+  size_t i;
+
+  for (i = 0; xdg_dirs != NULL && xdg_dirs[i] != NULL; i++)
+    free (xdg_dirs[i]);
+  free (xdg_dirs);
+  xdg_dirs = NULL;
+
+  if (dirs != NULL)
+    {
+      for (i = 0; dirs[i] != NULL; i++);
+      xdg_dirs = calloc (i + 1  /* NULL terminator */, sizeof (char*));
+      for (i = 0; dirs[i] != NULL; i++)
+        xdg_dirs[i] = strdup (dirs[i]);
+      xdg_dirs[i] = NULL;
+    }
+
+  need_reread = TRUE;
 }
 
 /* Checks file_path to make sure it has the same mtime as last time it was
@@ -350,8 +401,8 @@ xdg_check_dir (const char *directory,
   assert (directory != NULL);
 
   /* Check the mime.cache file */
-  file_name = malloc (strlen (directory) + strlen ("/mime/mime.cache") + 1);
-  strcpy (file_name, directory); strcat (file_name, "/mime/mime.cache");
+  file_name = malloc (strlen (directory) + strlen ("/mime.cache") + 1);
+  strcpy (file_name, directory); strcat (file_name, "/mime.cache");
   invalid = xdg_check_file (file_name, &exists);
   free (file_name);
   if (invalid)
@@ -365,8 +416,8 @@ xdg_check_dir (const char *directory,
     }
 
   /* Check the globs file */
-  file_name = malloc (strlen (directory) + strlen ("/mime/globs") + 1);
-  strcpy (file_name, directory); strcat (file_name, "/mime/globs");
+  file_name = malloc (strlen (directory) + strlen ("/globs") + 1);
+  strcpy (file_name, directory); strcat (file_name, "/globs");
   invalid = xdg_check_file (file_name, NULL);
   free (file_name);
   if (invalid)
@@ -376,8 +427,8 @@ xdg_check_dir (const char *directory,
     }
 
   /* Check the magic file */
-  file_name = malloc (strlen (directory) + strlen ("/mime/magic") + 1);
-  strcpy (file_name, directory); strcat (file_name, "/mime/magic");
+  file_name = malloc (strlen (directory) + strlen ("/magic") + 1);
+  strcpy (file_name, directory); strcat (file_name, "/magic");
   invalid = xdg_check_file (file_name, NULL);
   free (file_name);
   if (invalid)
@@ -824,6 +875,8 @@ xdg_mime_list_mime_parents (const char *mime)
   char **result;
   int i, n;
 
+  xdg_mime_init ();
+
   if (_caches)
     return _xdg_mime_cache_list_mime_parents (mime);
 
index 6a34edfc38a499497e411aed46b7a6c84dbaa284..abba067126a84f4dadb4af2fb5e0d9dc0f3548ec 100644 (file)
@@ -6,23 +6,7 @@
  * Copyright (C) 2003  Red Hat, Inc.
  * Copyright (C) 2003  Jonathan Blandford <jrb@alum.mit.edu>
  *
- * Licensed under the Academic Free License version 2.0
- * Or under the following terms:
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
  */
 
 
@@ -119,6 +103,8 @@ int          xdg_mime_register_reload_callback     (XdgMimeCallback  callback,
                                                    XdgMimeDestroy   destroy);
 void         xdg_mime_remove_callback              (int              callback_id);
 
+void xdg_mime_set_dirs (const char * const *dirs);
+
    /* Private versions of functions that don't call xdg_mime_init () */
 int          _xdg_mime_mime_type_equal             (const char *mime_a,
                                                    const char *mime_b);
index 07d89eb32e930bbed190dddedc42bbae5849ee9b..857d274a3278d5621fd553fad17ebcfd8f13fe8b 100644 (file)
@@ -6,23 +6,7 @@
  * Copyright (C) 2004  Red Hat, Inc.
  * Copyright (C) 2004  Matthias Clasen <mclasen@redhat.com>
  *
- * Licensed under the Academic Free License version 2.0
- * Or under the following terms:
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
  */
 
 #ifdef HAVE_CONFIG_H
index 3c28012dc34e14318491ba73cbda6921d76aeb34..05df009916cbf61aefead4fba4c0511dbe742b96 100644 (file)
@@ -6,23 +6,7 @@
  * Copyright (C) 2004  Red Hat, Inc.
  * Copyright (C) 200  Matthias Clasen <mclasen@redhat.com>
  *
- * Licensed under the Academic Free License version 2.0
- * Or under the following terms:
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
  */
 
 #ifndef __XDG_MIME_ALIAS_H__
index acaed9d470edf3536f6acb46db0761e7fcde29e8..05378fc9a19cf1697b957a0a1c59634dc34ba231 100644 (file)
@@ -5,23 +5,7 @@
  *
  * Copyright (C) 2005  Matthias Clasen <mclasen@redhat.com>
  *
- * Licensed under the Academic Free License version 2.0
- * Or under the following terms:
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
  */
 
 #ifdef HAVE_CONFIG_H
 #define MAP_FAILED ((void *) -1)
 #endif
 
+#ifndef S_ISREG
+#define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
+#endif
+
 #define MAJOR_VERSION 1
 #define MINOR_VERSION_MIN 1
 #define MINOR_VERSION_MAX 2
@@ -157,6 +145,12 @@ _xdg_mime_cache_new_from_file (const char *file_name)
   if (fd != -1)
     close (fd);
 
+#else /* HAVE_MMAP */
+  cache = (XdgMimeCache *) malloc (sizeof (XdgMimeCache));
+  cache->minor = 0;
+  cache->ref_count = 1;
+  cache->buffer = NULL;
+  cache->size = 0;
 #endif  /* HAVE_MMAP */
 
   return cache;
@@ -302,10 +296,16 @@ cache_alias_lookup (const char *alias)
   for (i = 0; _caches[i]; i++)
     {
       XdgMimeCache *cache = _caches[i];
-      xdg_uint32_t list_offset = GET_UINT32 (cache->buffer, 4);
-      xdg_uint32_t n_entries = GET_UINT32 (cache->buffer, list_offset);
+      xdg_uint32_t list_offset;
+      xdg_uint32_t n_entries;
       xdg_uint32_t offset;
 
+      if (cache->buffer == NULL)
+        continue;
+
+      list_offset = GET_UINT32 (cache->buffer, 4);
+      n_entries = GET_UINT32 (cache->buffer, list_offset);
+
       min = 0; 
       max = n_entries - 1;
       while (max >= min) 
@@ -348,10 +348,16 @@ cache_glob_lookup_literal (const char *file_name,
   for (i = 0; _caches[i]; i++)
     {
       XdgMimeCache *cache = _caches[i];
-      xdg_uint32_t list_offset = GET_UINT32 (cache->buffer, 12);
-      xdg_uint32_t n_entries = GET_UINT32 (cache->buffer, list_offset);
+      xdg_uint32_t list_offset;
+      xdg_uint32_t n_entries;
       xdg_uint32_t offset;
 
+      if (cache->buffer == NULL)
+        continue;
+
+      list_offset = GET_UINT32 (cache->buffer, 12);
+      n_entries = GET_UINT32 (cache->buffer, list_offset);
+
       min = 0; 
       max = n_entries - 1;
       while (max >= min) 
@@ -404,8 +410,14 @@ cache_glob_lookup_fnmatch (const char *file_name,
     {
       XdgMimeCache *cache = _caches[i];
 
-      xdg_uint32_t list_offset = GET_UINT32 (cache->buffer, 20);
-      xdg_uint32_t n_entries = GET_UINT32 (cache->buffer, list_offset);
+      xdg_uint32_t list_offset;
+      xdg_uint32_t n_entries;
+
+      if (cache->buffer == NULL)
+        continue;
+
+      list_offset = GET_UINT32 (cache->buffer, 20);
+      n_entries = GET_UINT32 (cache->buffer, list_offset);
 
       for (j = 0; j < n_entries && n < n_mime_types; j++)
        {
@@ -528,9 +540,16 @@ cache_glob_lookup_suffix (const char *file_name,
     {
       XdgMimeCache *cache = _caches[i];
 
-      xdg_uint32_t list_offset = GET_UINT32 (cache->buffer, 16);
-      xdg_uint32_t n_entries = GET_UINT32 (cache->buffer, list_offset);
-      xdg_uint32_t offset = GET_UINT32 (cache->buffer, list_offset + 4);
+      xdg_uint32_t list_offset;
+      xdg_uint32_t n_entries;
+      xdg_uint32_t offset;
+
+      if (cache->buffer == NULL)
+        continue;
+
+      list_offset = GET_UINT32 (cache->buffer, 16);
+      n_entries = GET_UINT32 (cache->buffer, list_offset);
+      offset = GET_UINT32 (cache->buffer, list_offset + 4);
 
       n = cache_glob_node_lookup_suffix (cache, 
                                         n_entries, offset, 
@@ -637,6 +656,9 @@ _xdg_mime_cache_get_max_buffer_extents (void)
     {
       XdgMimeCache *cache = _caches[i];
 
+      if (cache->buffer == NULL)
+        continue;
+
       offset = GET_UINT32 (cache->buffer, 24);
       max_extent = MAX (max_extent, GET_UINT32 (cache->buffer, offset + 4));
     }
@@ -663,6 +685,9 @@ cache_get_mime_type_for_data (const void *data,
       int prio;
       const char *match;
 
+      if (cache->buffer == NULL)
+        continue;
+
       match = cache_magic_lookup_data (cache, data, len, &prio);
       if (prio > priority)
        {
@@ -864,11 +889,16 @@ _xdg_mime_cache_mime_type_subclass (const char *mime,
   for (i = 0; _caches[i]; i++)
     {
       XdgMimeCache *cache = _caches[i];
-      
-      xdg_uint32_t list_offset = GET_UINT32 (cache->buffer, 8);
-      xdg_uint32_t n_entries = GET_UINT32 (cache->buffer, list_offset);
+      xdg_uint32_t list_offset;
+      xdg_uint32_t n_entries;
       xdg_uint32_t offset, n_parents, parent_offset;
 
+      if (cache->buffer == NULL)
+        continue;
+
+      list_offset = GET_UINT32 (cache->buffer, 8);
+      n_entries = GET_UINT32 (cache->buffer, list_offset);
+
       min = 0; 
       max = n_entries - 1;
       while (max >= min)
@@ -889,7 +919,9 @@ _xdg_mime_cache_mime_type_subclass (const char *mime,
              for (j = 0; j < n_parents; j++)
                {
                  parent_offset = GET_UINT32 (cache->buffer, offset + 4 + 4 * j);
-                 if (_xdg_mime_cache_mime_type_subclass (cache->buffer + parent_offset, ubase))
+                 if (strcmp (cache->buffer + parent_offset, mime) != 0 &&
+                     strcmp (cache->buffer + parent_offset, umime) != 0 &&
+                     _xdg_mime_cache_mime_type_subclass (cache->buffer + parent_offset, ubase))
                    return 1;
                }
 
@@ -928,9 +960,14 @@ _xdg_mime_cache_list_mime_parents (const char *mime)
   for (i = 0; _caches[i]; i++)
     {
       XdgMimeCache *cache = _caches[i];
-  
-      xdg_uint32_t list_offset = GET_UINT32 (cache->buffer, 8);
-      xdg_uint32_t n_entries = GET_UINT32 (cache->buffer, list_offset);
+      xdg_uint32_t list_offset;
+      xdg_uint32_t n_entries;
+
+      if (cache->buffer == NULL)
+        continue;
+
+      list_offset = GET_UINT32 (cache->buffer, 8);
+      n_entries = GET_UINT32 (cache->buffer, list_offset);
 
       for (j = 0; j < n_entries; j++)
        {
@@ -980,10 +1017,16 @@ cache_lookup_icon (const char *mime, int header)
   for (i = 0; _caches[i]; i++)
     {
       XdgMimeCache *cache = _caches[i];
-      xdg_uint32_t list_offset = GET_UINT32 (cache->buffer, header);
-      xdg_uint32_t n_entries = GET_UINT32 (cache->buffer, list_offset);
+      xdg_uint32_t list_offset;
+      xdg_uint32_t n_entries;
       xdg_uint32_t offset;
 
+      if (cache->buffer == NULL)
+        continue;
+
+      list_offset = GET_UINT32 (cache->buffer, header);
+      n_entries = GET_UINT32 (cache->buffer, list_offset);
+
       min = 0; 
       max = n_entries - 1;
       while (max >= min) 
@@ -1060,6 +1103,10 @@ _xdg_mime_cache_glob_dump (void)
     xdg_uint32_t list_offset;
     xdg_uint32_t n_entries;
     xdg_uint32_t offset;
+
+    if (cache->buffer == NULL)
+      continue;
+
     list_offset = GET_UINT32 (cache->buffer, 16);
     n_entries = GET_UINT32 (cache->buffer, list_offset);
     offset = GET_UINT32 (cache->buffer, list_offset + 4);
index 27f42d0ca17573f47e98ce0985d654987ac920eb..48aa752b9d2a6c02303a48b9a4929788133381dc 100644 (file)
@@ -5,23 +5,7 @@
  *
  * Copyright (C) 2005  Matthias Clasen <mclasen@redhat.com>
  *
- * Licensed under the Academic Free License version 2.0
- * Or under the following terms:
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
  */
 
 #ifndef __XDG_MIME_CACHE_H__
index 5071418cc4a79d17f51b8168d2a21ec630b48dd8..a07305cc2a466a01fbf50e69f9a409acbba99c89 100644 (file)
@@ -6,23 +6,7 @@
  * Copyright (C) 2003  Red Hat, Inc.
  * Copyright (C) 2003  Jonathan Blandford <jrb@alum.mit.edu>
  *
- * Licensed under the Academic Free License version 2.0
- * Or under the following terms:
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
  */
 
 #ifdef HAVE_CONFIG_H
index 00182920d44250b837a118d20fdd2471692f92c8..7ecee9a8ffb77446a84f09c94f590c831c74ae79 100644 (file)
@@ -6,23 +6,7 @@
  * Copyright (C) 2003  Red Hat, Inc.
  * Copyright (C) 2003  Jonathan Blandford <jrb@alum.mit.edu>
  *
- * Licensed under the Academic Free License version 2.0
- * Or under the following terms:
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
  */
 
 #ifndef __XDG_MIME_GLOB_H__
index 05c9473a680eb43cfb6965273eb21906ff6230d2..4aaa564f1192592d6bd32f9732f6774ef7646f07 100644 (file)
@@ -5,23 +5,7 @@
  *
  * Copyright (C) 2008  Red Hat, Inc.
  *
- * Licensed under the Academic Free License version 2.0
- * Or under the following terms:
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
  */
 
 #ifdef HAVE_CONFIG_H
index b5f25835db0676d36b2d07d4f51fe8928c3970f8..f7244305aaacf0da4994c071b88421905b0b0e18 100644 (file)
@@ -5,23 +5,7 @@
  *
  * Copyright (C) 2008  Red Hat, Inc.
  *
- * Licensed under the Academic Free License version 2.0
- * Or under the following terms:
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
  */
 
 #ifndef __XDG_MIME_ICON_H__
index 5eaa7154e2cc88698a3c1c17dbec6bd456cd8d65..0655fa0b1097d62e2a957cb5d4aabb1a012650db 100644 (file)
@@ -6,23 +6,7 @@
  * Copyright (C) 2003  Red Hat, Inc.
  * Copyright (C) 2003  Jonathan Blandford <jrb@alum.mit.edu>
  *
- * Licensed under the Academic Free License version 2.0
- * Or under the following terms:
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
  */
 
 #ifdef HAVE_CONFIG_H
index 9e8b2cb85a41555345db545e0e10f8a5bd466664..041c4f489bb8ba9e51de2e810fa339052d81f1b4 100644 (file)
@@ -6,23 +6,7 @@
  * Copyright (C) 2003  Red Hat, Inc.
  * Copyright (C) 2003  Jonathan Blandford <jrb@alum.mit.edu>
  *
- * Licensed under the Academic Free License version 2.0
- * Or under the following terms:
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
  */
 
 #ifndef __XDG_MIME_INT_H__
index fd49fa8e682de9c69571c626e59b3e4d35c5a2b3..98a1274c87f3abc1fb39acd45f0e95654a71df43 100644 (file)
@@ -6,23 +6,7 @@
  * Copyright (C) 2003  Red Hat, Inc.
  * Copyright (C) 2003  Jonathan Blandford <jrb@alum.mit.edu>
  *
- * Licensed under the Academic Free License version 2.0
- * Or under the following terms:
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
  */
 
 #ifdef HAVE_CONFIG_H
@@ -103,6 +87,8 @@ _xdg_mime_magic_matchlet_new (void)
   XdgMimeMagicMatchlet *matchlet;
 
   matchlet = malloc (sizeof (XdgMimeMagicMatchlet));
+  if (matchlet == NULL)
+    return NULL;
 
   matchlet->indent = 0;
   matchlet->offset = 0;
@@ -355,6 +341,11 @@ _xdg_mime_magic_parse_magic_line (FILE              *magic_file,
     return XDG_MIME_MAGIC_ERROR;
 
   matchlet = _xdg_mime_magic_matchlet_new ();
+
+  /* OOM */
+  if (matchlet == NULL)
+    return XDG_MIME_MAGIC_ERROR;
+
   matchlet->indent = indent;
   matchlet->offset = _xdg_mime_magic_read_a_number (magic_file, &end_of_file);
   if (end_of_file)
@@ -479,7 +470,9 @@ _xdg_mime_magic_parse_magic_line (FILE              *magic_file,
       /* We clean up the matchlet, byte swapping if needed */
       if (matchlet->word_size > 1)
        {
+#if LITTLE_ENDIAN
          unsigned int i;
+#endif
          if (matchlet->value_length % matchlet->word_size != 0)
            {
              _xdg_mime_magic_matchlet_free (matchlet);
@@ -767,6 +760,11 @@ _xdg_mime_magic_read_magic_file (XdgMimeMagic *mime_magic,
        {
        case XDG_MIME_MAGIC_SECTION:
          match = _xdg_mime_magic_match_new ();
+
+         /* OOM */
+         if (match == NULL)
+           return;
+
          state = _xdg_mime_magic_parse_header (magic_file, match);
          if (state == XDG_MIME_MAGIC_EOF || state == XDG_MIME_MAGIC_ERROR)
            _xdg_mime_magic_match_free (match);
@@ -784,6 +782,11 @@ _xdg_mime_magic_read_magic_file (XdgMimeMagic *mime_magic,
          break;
        case XDG_MIME_MAGIC_ERROR:
          state = _xdg_mime_magic_parse_error (magic_file);
+
+         /* After a parse error we can only be at EOF or reset to starting a
+          * new section. */
+         assert (state == XDG_MIME_MAGIC_EOF || state == XDG_MIME_MAGIC_SECTION);
+
          break;
        case XDG_MIME_MAGIC_EOF:
        default:
index 35c8039c8eef4dd8859a7bf690c31ef5d8eb41f5..81125c2a082f3654310dd171fd5fabe4e0a08013 100644 (file)
@@ -6,23 +6,7 @@
  * Copyright (C) 2003  Red Hat, Inc.
  * Copyright (C) 2003  Jonathan Blandford <jrb@alum.mit.edu>
  *
- * Licensed under the Academic Free License version 2.0
- * Or under the following terms:
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
  */
 
 #ifndef __XDG_MIME_MAGIC_H__
index 511bbacbc19c19b59cbcf359499aa492e3bc6cca..e03a78f6caf197dfc7d4df50aabc8f4067940339 100644 (file)
@@ -6,23 +6,7 @@
  * Copyright (C) 2004  Red Hat, Inc.
  * Copyright (C) 2004  Matthias Clasen <mclasen@redhat.com>
  *
- * Licensed under the Academic Free License version 2.0
- * Or under the following terms:
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
  */
 
 #ifdef HAVE_CONFIG_H
@@ -111,6 +95,7 @@ _xdg_mime_parent_list_lookup (XdgParentList *list,
     {
       key.mime = (char *)mime;
       key.parents = NULL;
+      key.n_parents = 0;
 
       entry = bsearch (&key, list->parents, list->n_mimes,
                       sizeof (XdgMimeParents), &parent_entry_cmp);
index b564f4127f5270dc6db4c180aea24bc33670c0cf..b656e38cce076a203ef821b87b271ef5779e6f70 100644 (file)
@@ -6,23 +6,7 @@
  * Copyright (C) 2004  Red Hat, Inc.
  * Copyright (C) 200  Matthias Clasen <mclasen@redhat.com>
  *
- * Licensed under the Academic Free License version 2.0
- * Or under the following terms:
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
  */
 
 #ifndef __XDG_MIME_PARENT_H__