Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(215)

Side by Side Diff: base/third_party/xdg_mime/xdgmime.c

Issue 10824186: Linux: update base/third_party/xdg_mime from upstream. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/third_party/xdg_mime/xdgmime.h ('k') | base/third_party/xdg_mime/xdgmimealias.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* -*- mode: C; c-file-style: "gnu" -*- */ 1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* xdgmime.c: XDG Mime Spec mime resolver. Based on version 0.11 of the spec. 2 /* xdgmime.c: XDG Mime Spec mime resolver. Based on version 0.11 of the spec.
3 * 3 *
4 * More info can be found at http://www.freedesktop.org/standards/ 4 * More info can be found at http://www.freedesktop.org/standards/
5 * 5 *
6 * Copyright (C) 2003,2004 Red Hat, Inc. 6 * Copyright (C) 2003,2004 Red Hat, Inc.
7 * Copyright (C) 2003,2004 Jonathan Blandford <jrb@alum.mit.edu> 7 * Copyright (C) 2003,2004 Jonathan Blandford <jrb@alum.mit.edu>
8 * 8 *
9 * Licensed under the Academic Free License version 2.0 9 * Licensed under the Academic Free License version 2.0
10 * Or under the following terms: 10 * Or under the following terms:
11 * 11 *
12 * This library is free software; you can redistribute it and/or 12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public 13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either 14 * License as published by the Free Software Foundation; either
15 * version 2 of the License, or (at your option) any later version. 15 * version 2 of the License, or (at your option) any later version.
16 * 16 *
17 * This library is distributed in the hope that it will be useful, 17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details. 20 * Lesser General Public License for more details.
21 * 21 *
22 * You should have received a copy of the GNU Lesser General Public 22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the 23 * License along with this library; if not, write to the
24 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 24 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 * Boston, MA 02111-1307, USA. 25 * Boston, MA 02111-1307, USA.
26 */ 26 */
27 27
28 #ifdef HAVE_CONFIG_H 28 #ifdef HAVE_CONFIG_H
29 #include "config.h" 29 #include <config.h>
30 #endif 30 #endif
31 31
32 #include "xdgmime.h" 32 #include "xdgmime.h"
33 #include "xdgmimeint.h" 33 #include "xdgmimeint.h"
34 #include "xdgmimeglob.h" 34 #include "xdgmimeglob.h"
35 #include "xdgmimemagic.h" 35 #include "xdgmimemagic.h"
36 #include "xdgmimealias.h" 36 #include "xdgmimealias.h"
37 #include "xdgmimeicon.h" 37 #include "xdgmimeicon.h"
38 #include "xdgmimeparent.h" 38 #include "xdgmimeparent.h"
39 #include "xdgmimecache.h" 39 #include "xdgmimecache.h"
(...skipping 17 matching lines...) Expand all
57 static XdgParentList *parent_list = NULL; 57 static XdgParentList *parent_list = NULL;
58 static XdgDirTimeList *dir_time_list = NULL; 58 static XdgDirTimeList *dir_time_list = NULL;
59 static XdgCallbackList *callback_list = NULL; 59 static XdgCallbackList *callback_list = NULL;
60 static XdgIconList *icon_list = NULL; 60 static XdgIconList *icon_list = NULL;
61 static XdgIconList *generic_icon_list = NULL; 61 static XdgIconList *generic_icon_list = NULL;
62 62
63 XdgMimeCache **_caches = NULL; 63 XdgMimeCache **_caches = NULL;
64 static int n_caches = 0; 64 static int n_caches = 0;
65 65
66 const char xdg_mime_type_unknown[] = "application/octet-stream"; 66 const char xdg_mime_type_unknown[] = "application/octet-stream";
67 const char xdg_mime_type_empty[] = "application/x-zerosize";
68 const char xdg_mime_type_textplain[] = "text/plain";
67 69
68 70
69 enum 71 enum
70 { 72 {
71 XDG_CHECKED_UNCHECKED, 73 XDG_CHECKED_UNCHECKED,
72 XDG_CHECKED_VALID, 74 XDG_CHECKED_VALID,
73 XDG_CHECKED_INVALID 75 XDG_CHECKED_INVALID
74 }; 76 };
75 77
76 struct XdgDirTimeList 78 struct XdgDirTimeList
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 160
159 return FALSE; 161 return FALSE;
160 } 162 }
161 } 163 }
162 free (file_name); 164 free (file_name);
163 165
164 file_name = malloc (strlen (directory) + strlen ("/mime/globs2") + 1); 166 file_name = malloc (strlen (directory) + strlen ("/mime/globs2") + 1);
165 strcpy (file_name, directory); strcat (file_name, "/mime/globs2"); 167 strcpy (file_name, directory); strcat (file_name, "/mime/globs2");
166 if (stat (file_name, &st) == 0) 168 if (stat (file_name, &st) == 0)
167 { 169 {
168 _xdg_mime_glob_read_from_file (global_hash, file_name); 170 _xdg_mime_glob_read_from_file (global_hash, file_name, TRUE);
169 xdg_dir_time_list_add (file_name, st.st_mtime); 171 xdg_dir_time_list_add (file_name, st.st_mtime);
170 } 172 }
171 else 173 else
172 { 174 {
173 free (file_name); 175 free (file_name);
174 file_name = malloc (strlen (directory) + strlen ("/mime/globs") + 1); 176 file_name = malloc (strlen (directory) + strlen ("/mime/globs") + 1);
175 strcpy (file_name, directory); strcat (file_name, "/mime/globs"); 177 strcpy (file_name, directory); strcat (file_name, "/mime/globs");
176 if (stat (file_name, &st) == 0) 178 if (stat (file_name, &st) == 0)
177 { 179 {
178 _xdg_mime_glob_read_from_file (global_hash, file_name); 180 _xdg_mime_glob_read_from_file (global_hash, file_name, FALSE);
179 xdg_dir_time_list_add (file_name, st.st_mtime); 181 xdg_dir_time_list_add (file_name, st.st_mtime);
180 } 182 }
181 else 183 else
182 { 184 {
183 free (file_name); 185 free (file_name);
184 } 186 }
185 } 187 }
186 188
187 file_name = malloc (strlen (directory) + strlen ("/mime/magic") + 1); 189 file_name = malloc (strlen (directory) + strlen ("/mime/magic") + 1);
188 strcpy (file_name, directory); strcat (file_name, "/mime/magic"); 190 strcpy (file_name, directory); strcat (file_name, "/mime/magic");
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 } 462 }
461 } 463 }
462 464
463 const char * 465 const char *
464 xdg_mime_get_mime_type_for_data (const void *data, 466 xdg_mime_get_mime_type_for_data (const void *data,
465 size_t len, 467 size_t len,
466 int *result_prio) 468 int *result_prio)
467 { 469 {
468 const char *mime_type; 470 const char *mime_type;
469 471
472 if (len == 0)
473 {
474 *result_prio = 100;
475 return XDG_MIME_TYPE_EMPTY;
476 }
477
470 xdg_mime_init (); 478 xdg_mime_init ();
471 479
472 if (_caches) 480 if (_caches)
473 return _xdg_mime_cache_get_mime_type_for_data (data, len, result_prio); 481 mime_type = _xdg_mime_cache_get_mime_type_for_data (data, len, result_prio);
474 482 else
475 mime_type = _xdg_mime_magic_lookup_data (global_magic, data, len, result_prio, NULL, 0); 483 mime_type = _xdg_mime_magic_lookup_data (global_magic, data, len, result_pri o, NULL, 0);
476 484
477 if (mime_type) 485 if (mime_type)
478 return mime_type; 486 return mime_type;
479 487
480 return XDG_MIME_TYPE_UNKNOWN; 488 return _xdg_binary_or_text_fallback(data, len);
481 } 489 }
482 490
483 const char * 491 const char *
484 xdg_mime_get_mime_type_for_file (const char *file_name, 492 xdg_mime_get_mime_type_for_file (const char *file_name,
485 struct stat *statbuf) 493 struct stat *statbuf)
486 { 494 {
487 const char *mime_type; 495 const char *mime_type;
488 /* currently, only a few globs occur twice, and none 496 /* currently, only a few globs occur twice, and none
489 * more often, so 5 seems plenty. 497 * more often, so 5 seems plenty.
490 */ 498 */
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 557
550 mime_type = _xdg_mime_magic_lookup_data (global_magic, data, bytes_read, NULL, 558 mime_type = _xdg_mime_magic_lookup_data (global_magic, data, bytes_read, NULL,
551 mime_types, n); 559 mime_types, n);
552 560
553 free (data); 561 free (data);
554 fclose (file); 562 fclose (file);
555 563
556 if (mime_type) 564 if (mime_type)
557 return mime_type; 565 return mime_type;
558 566
559 return XDG_MIME_TYPE_UNKNOWN; 567 return _xdg_binary_or_text_fallback(data, bytes_read);
560 } 568 }
561 569
562 const char * 570 const char *
563 xdg_mime_get_mime_type_from_file_name (const char *file_name) 571 xdg_mime_get_mime_type_from_file_name (const char *file_name)
564 { 572 {
565 const char *mime_type; 573 const char *mime_type;
566 574
567 xdg_mime_init (); 575 xdg_mime_init ();
568 576
569 if (_caches) 577 if (_caches)
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 const char * 925 const char *
918 xdg_mime_get_generic_icon (const char *mime) 926 xdg_mime_get_generic_icon (const char *mime)
919 { 927 {
920 xdg_mime_init (); 928 xdg_mime_init ();
921 929
922 if (_caches) 930 if (_caches)
923 return _xdg_mime_cache_get_generic_icon (mime); 931 return _xdg_mime_cache_get_generic_icon (mime);
924 932
925 return _xdg_mime_icon_list_lookup (generic_icon_list, mime); 933 return _xdg_mime_icon_list_lookup (generic_icon_list, mime);
926 } 934 }
OLDNEW
« no previous file with comments | « base/third_party/xdg_mime/xdgmime.h ('k') | base/third_party/xdg_mime/xdgmimealias.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698