diff options
author | Kristian Monsen <kristianm@google.com> | 2011-03-30 17:20:49 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2011-03-30 17:20:49 -0700 |
commit | 5f4b50b39e01b3818e293cb5c6933500eee85a97 (patch) | |
tree | bdd0e1757a04f6092834faaff35c68a4298fe2e0 /base | |
parent | df5fef6c965bc95a2b6c3827a6a90c51667ffb9e (diff) | |
parent | 47c0a16e8b9f5c6cfb515871409697aa20236ed5 (diff) | |
download | external_chromium-5f4b50b39e01b3818e293cb5c6933500eee85a97.zip external_chromium-5f4b50b39e01b3818e293cb5c6933500eee85a97.tar.gz external_chromium-5f4b50b39e01b3818e293cb5c6933500eee85a97.tar.bz2 |
am 47c0a16e: Removing projects that are not needed to compile
* commit '47c0a16e8b9f5c6cfb515871409697aa20236ed5':
Removing projects that are not needed to compile
Diffstat (limited to 'base')
39 files changed, 0 insertions, 7542 deletions
diff --git a/base/third_party/purify/LICENSE b/base/third_party/purify/LICENSE deleted file mode 100644 index f876ca8..0000000 --- a/base/third_party/purify/LICENSE +++ /dev/null @@ -1,2 +0,0 @@ -(C) Copyright IBM Corporation. 2006, 2006. All Rights Reserved. -You may recompile and redistribute these definitions as required. diff --git a/base/third_party/purify/README.chromium b/base/third_party/purify/README.chromium deleted file mode 100644 index feecf91..0000000 --- a/base/third_party/purify/README.chromium +++ /dev/null @@ -1,2 +0,0 @@ -Name: purify headers -URL: http://www-01.ibm.com/software/awdtools/purify/ diff --git a/base/third_party/purify/pure.h b/base/third_party/purify/pure.h deleted file mode 100644 index ed50a37..0000000 --- a/base/third_party/purify/pure.h +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Header file of Pure API function declarations. - * -* (C) Copyright IBM Corporation. 2006, 2006. All Rights Reserved. - * You may recompile and redistribute these definitions as required. - * - * Version 1.0 - */ - -#if defined(PURIFY) || defined(QUANTIFY) - -#if defined(c_plusplus) || defined(__cplusplus) -extern "C" { -#endif - -// Don't include this file directly, use purify.h instead. -// If you need something that's not there, add it. -#ifdef PURIFY_PRIVATE_INCLUDE - -#define PURE_H_VERSION 1 -#include <stddef.h> - -////////////////////////////// -// API's Specific to Purify // -////////////////////////////// - -// TRUE when Purify is running. -int __cdecl PurifyIsRunning(void) ; -// -// Print a string to the viewer. -// -int __cdecl PurePrintf(const char *fmt, ...) ; -int __cdecl PurifyPrintf(const char *fmt, ...) ; -// -// Purify functions for leak and memory-in-use functionalty. -// -size_t __cdecl PurifyNewInuse(void) ; -size_t __cdecl PurifyAllInuse(void) ; -size_t __cdecl PurifyClearInuse(void) ; -size_t __cdecl PurifyNewLeaks(void) ; -size_t __cdecl PurifyAllLeaks(void) ; -size_t __cdecl PurifyClearLeaks(void) ; -// -// Purify functions for handle leakage. -// -size_t __cdecl PurifyAllHandlesInuse(void) ; -size_t __cdecl PurifyNewHandlesInuse(void) ; -// -// Functions that tell you about the state of memory. -// -size_t __cdecl PurifyDescribe(void *addr) ; -size_t __cdecl PurifyWhatColors(void *addr, size_t size) ; -// -// Functions to test the state of memory. If the memory is not -// accessable, an error is signaled just as if there were a memory -// reference and the function returns false. -// -int __cdecl PurifyAssertIsReadable(const void *addr, size_t size) ; // size used to be an int, until IA64 came along -int __cdecl PurifyAssertIsWritable(const void *addr, size_t size) ; -// -// Functions to test the state of memory. If the memory is not -// accessable, these functions return false. No error is signaled. -// -int __cdecl PurifyIsReadable(const void *addr, size_t size) ; -int __cdecl PurifyIsWritable(const void *addr, size_t size) ; -int __cdecl PurifyIsInitialized(const void *addr, size_t size) ; -// -// Functions to set the state of memory. -// -void __cdecl PurifyMarkAsInitialized(void *addr, size_t size) ; -void __cdecl PurifyMarkAsUninitialized(void *addr, size_t size) ; -// -// Functions to do late detection of ABWs, FMWs, IPWs. -// -#define PURIFY_HEAP_CRT (HANDLE) ~(__int64) 1 /* 0xfffffffe */ -#define PURIFY_HEAP_ALL (HANDLE) ~(__int64) 2 /* 0xfffffffd */ -#define PURIFY_HEAP_BLOCKS_LIVE 0x80000000 -#define PURIFY_HEAP_BLOCKS_DEFERRED_FREE 0x40000000 -#define PURIFY_HEAP_BLOCKS_ALL (PURIFY_HEAP_BLOCKS_LIVE|PURIFY_HEAP_BLOCKS_DEFERRED_FREE) -int __cdecl PurifyHeapValidate(unsigned int hHeap, unsigned int dwFlags, const void *addr) ; -int __cdecl PurifySetLateDetectScanCounter(int counter); -int __cdecl PurifySetLateDetectScanInterval(int seconds); -// -// Functions to support pool allocators -// -void __cdecl PurifySetPoolId(const void *mem, int id); -int __cdecl PurifyGetPoolId(const void *mem); -void __cdecl PurifySetUserData(const void *mem, void *data); -void * __cdecl PurifyGetUserData(const void *mem); -void __cdecl PurifyMapPool(int id, void(*fn)()); - - -//////////////////////////////// -// API's Specific to Quantify // -//////////////////////////////// - -// TRUE when Quantify is running. -int __cdecl QuantifyIsRunning(void) ; - -// -// Functions for controlling collection -// -int __cdecl QuantifyDisableRecordingData(void) ; -int __cdecl QuantifyStartRecordingData(void) ; -int __cdecl QuantifyStopRecordingData(void) ; -int __cdecl QuantifyClearData(void) ; -int __cdecl QuantifyIsRecordingData(void) ; - -// Add a comment to the dataset -int __cdecl QuantifyAddAnnotation(char *) ; - -// Save the current data, creating a "checkpoint" dataset -int __cdecl QuantifySaveData(void) ; - -// Set the name of the current thread in the viewer -int __cdecl QuantifySetThreadName(char *) ; - -//////////////////////////////// -// API's Specific to Coverage // -//////////////////////////////// - -// TRUE when Coverage is running. -int __cdecl CoverageIsRunning(void) ; -// -// Functions for controlling collection -// -int __cdecl CoverageDisableRecordingData(void) ; -int __cdecl CoverageStartRecordingData(void) ; -int __cdecl CoverageStopRecordingData(void) ; -int __cdecl CoverageClearData(void) ; -int __cdecl CoverageIsRecordingData(void) ; -// Add a comment to the dataset -int __cdecl CoverageAddAnnotation(char *) ; - -// Save the current data, creating a "checkpoint" dataset -int __cdecl CoverageSaveData(void) ; - - -#endif // PURIFY_PRIVATE_INCLUDE - -#if defined(c_plusplus) || defined(__cplusplus) -} -#endif - -#endif // defined(PURIFY) || defined(QUANTIFY)
\ No newline at end of file diff --git a/base/third_party/purify/pure_api.c b/base/third_party/purify/pure_api.c deleted file mode 100644 index 7203cfd..0000000 --- a/base/third_party/purify/pure_api.c +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Header file of Pure API function declarations. - * - * Explicitly no copyright. - * You may recompile and redistribute these definitions as required. - * - * NOTE1: In some situations when compiling with MFC, you should - * enable the setting 'Not using precompiled headers' in Visual C++ - * to avoid a compiler diagnostic. - * - * NOTE2: This file works through the use of deep magic. Calls to functions - * in this file are replaced with calls into the OCI runtime system - * when an instrumented version of this program is run. - * - * NOTE3: The static vars avoidGy_n (where n is a unique number) are used - * to prevent optimizing the functions away when compiler option - * /Gy is set. This is needed so that NOTE2 works properly. - */ - -// Chromium note: We used to only compile this code if PURIFY was defined, -// because we did special builds with all optimizations turned off for Purify. -// However, for profiling with Quantify, we want most/all optimizations turned -// on so that we measure something closer to real execution. - -#ifdef _WINDOWS // we only use Purify/Quantify on Windows - -#pragma once - extern int errno; -typedef int ptrdiff_t; -typedef unsigned int size_t; -typedef unsigned short wchar_t; -static int avoidGy_1 = 0; -static int avoidGy_2 = 0; -static int avoidGy_3 = 0; -static int avoidGy_4 = 0; -static int avoidGy_5 = 0; -static int avoidGy_6 = 0; -static int avoidGy_7 = 0; -static int avoidGy_8 = 0; -static int avoidGy_9 = 0; -static int avoidGy_10 = 0; -static int avoidGy_11 = 0; -static int avoidGy_12 = 0; -static int avoidGy_13 = 0; -static int avoidGy_14 = 0; -static int avoidGy_15 = 0; -static int avoidGy_16 = 0; -static int avoidGy_17 = 0; -static int avoidGy_18 = 0; -static int avoidGy_19 = 0; -static int avoidGy_20 = 0; -static int avoidGy_21 = 0; -static int avoidGy_22 = 0; -static int avoidGy_23 = 0; -static int avoidGy_24 = 0; -static int avoidGy_25 = 0; -static int avoidGy_26 = 0; -static int avoidGy_27 = 0; -static int avoidGy_28 = 0; -static int avoidGy_29 = 0; -static int avoidGy_30 = 0; -static int avoidGy_31 = 0; -static int avoidGy_32 = 0; -static int avoidGy_33 = 0; -static int avoidGy_34 = 0; -static int avoidGy_35 = 0; -static int avoidGy_36 = 0; -static int avoidGy_37 = 0; -static int avoidGy_38 = 0; -static int avoidGy_39 = 0; -static int avoidGy_40 = 0; -static int avoidGy_41 = 0; -static int avoidGy_42 = 0; -static int avoidGy_43 = 0; -static int avoidGy_44 = 0; -static int avoidGy_45 = 0; -static int avoidGy_46 = 0; -static int avoidGy_47 = 0; -static int avoidGy_48 = 0; -static int avoidGy_49 = 0; -static int avoidGy_50 = 0; -static int avoidGy_51 = 0; -static int avoidGy_52 = 0; -static int avoidGy_53 = 0; -static int avoidGy_54 = 0; -static int avoidGy_55 = 0; -static int avoidGy_56 = 0; -static int avoidGy_57 = 0; -static int avoidGy_58 = 0; -static int avoidGy_59 = 0; -static int avoidGy_60 = 0; -static int avoidGy_61 = 0; -static int avoidGy_62 = 0; -static int avoidGy_63 = 0; -static int avoidGy_64 = 0; -static int avoidGy_65 = 0; -static int avoidGy_PL_01 = 0; -static int avoidGy_PL_02 = 0; -__declspec(dllexport) int __cdecl PurePrintf(const char *fmt, ...) { if(!++avoidGy_1); fmt; return 0; } -__declspec(dllexport) int __cdecl PurifyIsRunning(void) { if(!++avoidGy_2); return 0; } -__declspec(dllexport) int __cdecl PurifyPrintf(const char *fmt, ...) { if(!++avoidGy_3); fmt; return 0; } -__declspec(dllexport) size_t __cdecl PurifyNewInuse(void) { if(!++avoidGy_4); return 0; } -__declspec(dllexport) size_t __cdecl PurifyAllInuse(void) { if(!++avoidGy_5); return 0; } -__declspec(dllexport) size_t __cdecl PurifyClearInuse(void) { if(!++avoidGy_6); return 0; } -__declspec(dllexport) size_t __cdecl PurifyNewLeaks(void) { if(!++avoidGy_7); return 0; } -__declspec(dllexport) size_t __cdecl PurifyAllLeaks(void) { if(!++avoidGy_8); return 0; } -__declspec(dllexport) size_t __cdecl PurifyClearLeaks(void) { if(!++avoidGy_9); return 0; } -__declspec(dllexport) size_t __cdecl PurifyAllHandlesInuse(void) { if(!++avoidGy_10); return 0; } -__declspec(dllexport) size_t __cdecl PurifyNewHandlesInuse(void) { if(!++avoidGy_11); return 0; } -__declspec(dllexport) size_t __cdecl PurifyDescribe(void *addr) { if(!++avoidGy_12); addr; return 0; } -__declspec(dllexport) int __cdecl PurifyWhatColors(void *addr, size_t size) { if(!++avoidGy_13); addr; size; return 0; } -__declspec(dllexport) int __cdecl PurifyAssertIsReadable(const void *addr, size_t size) { if(!++avoidGy_14); addr; size; return 1; } -__declspec(dllexport) int __cdecl PurifyAssertIsWritable(const void *addr, size_t size) { if(!++avoidGy_15); addr; size; return 1; } -__declspec(dllexport) int __cdecl PurifyIsReadable(const void *addr, size_t size) { if(!++avoidGy_16); addr; size; return 1; } -__declspec(dllexport) int __cdecl PurifyIsWritable(const void *addr, size_t size) { if(!++avoidGy_17); addr; size; return 1; } -__declspec(dllexport) int __cdecl PurifyIsInitialized(const void *addr, size_t size) { if(!++avoidGy_18); addr; size; return 1; } -__declspec(dllexport) int __cdecl PurifyRed(void *addr, size_t size) { if(!++avoidGy_19); addr; size; return 0; } -__declspec(dllexport) int __cdecl PurifyGreen(void *addr, size_t size) { if(!++avoidGy_20); addr; size; return 0; } -__declspec(dllexport) int __cdecl PurifyYellow(void *addr, size_t size) { if(!++avoidGy_21); addr; size; return 0; } -__declspec(dllexport) int __cdecl PurifyBlue(void *addr, size_t size) { if(!++avoidGy_22); addr; size; return 0; } -__declspec(dllexport) int __cdecl PurifyMarkAsInitialized(void *addr, size_t size) { if(!++avoidGy_23); addr; size; return 0; } -__declspec(dllexport) int __cdecl PurifyMarkAsUninitialized(void *addr, size_t size) { if(!++avoidGy_24); addr; size; return 0; } -__declspec(dllexport) int __cdecl PurifyMarkForTrap(void *addr, size_t size) { if(!++avoidGy_25); addr; size; return 0; } -__declspec(dllexport) int __cdecl PurifyMarkForNoTrap(void *addr, size_t size) { if(!++avoidGy_26); addr; size; return 0; } -__declspec(dllexport) int __cdecl PurifyHeapValidate(unsigned int hHeap, unsigned int dwFlags, const void *addr) - { if(!++avoidGy_27); hHeap; dwFlags; addr; return 1; } -__declspec(dllexport) int __cdecl PurifySetLateDetectScanCounter(int counter) { if(!++avoidGy_28); counter; return 0; }; -__declspec(dllexport) int __cdecl PurifySetLateDetectScanInterval(int seconds) { if(!++avoidGy_29); seconds; return 0; }; -__declspec(dllexport) void __cdecl PurifySetPoolId(const void *mem, int id) { if(!++avoidGy_61); mem; id; return; }; -__declspec(dllexport) int __cdecl PurifyGetPoolId(const void *mem) { if(!++avoidGy_62); mem; return 0; }; -__declspec(dllexport) void __cdecl PurifySetUserData(const void *mem, void *data) { if(!++avoidGy_63); mem; data; return; }; -__declspec(dllexport) void * __cdecl PurifyGetUserData(const void *mem) { if(!++avoidGy_64); mem; return 0; }; -__declspec(dllexport) void __cdecl PurifyMapPool(int id, void(*fn)()) { if(!++avoidGy_65); id; fn; return; }; -__declspec(dllexport) int __cdecl CoverageIsRunning(void) { if(!++avoidGy_30); return 0; } -__declspec(dllexport) int __cdecl CoverageDisableRecordingData(void) { if(!++avoidGy_31); return 0; } -__declspec(dllexport) int __cdecl CoverageStartRecordingData(void) { if(!++avoidGy_32); return 0; } -__declspec(dllexport) int __cdecl CoverageStopRecordingData(void) { if(!++avoidGy_33); return 0; } -__declspec(dllexport) int __cdecl CoverageClearData(void) { if(!++avoidGy_34); return 0; } -__declspec(dllexport) int __cdecl CoverageIsRecordingData(void) { if(!++avoidGy_35); return 0; } -__declspec(dllexport) int __cdecl CoverageAddAnnotation(char *str) { if(!++avoidGy_36); str; return 0; } -__declspec(dllexport) int __cdecl CoverageSaveData(void) { if(!++avoidGy_37); return 0; } -__declspec(dllexport) int __cdecl QuantifyIsRunning(void) { if(!++avoidGy_42); return 0; } -__declspec(dllexport) int __cdecl QuantifyDisableRecordingData(void) { if(!++avoidGy_43); return 0; } -__declspec(dllexport) int __cdecl QuantifyStartRecordingData(void) { if(!++avoidGy_44); return 0; } -__declspec(dllexport) int __cdecl QuantifyStopRecordingData(void) { if(!++avoidGy_45); return 0; } -__declspec(dllexport) int __cdecl QuantifyClearData(void) { if(!++avoidGy_46); return 0; } -__declspec(dllexport) int __cdecl QuantifyIsRecordingData(void) { if(!++avoidGy_47); return 0; } -__declspec(dllexport) int __cdecl QuantifyAddAnnotation(char *str) { if(!++avoidGy_48); str; return 0; } -__declspec(dllexport) int __cdecl QuantifySaveData(void) { if(!++avoidGy_49); return 0; } -__declspec(dllexport) int __cdecl QuantifySetThreadName(const char *szName) { if(!++avoidGy_50) ; szName; return 0; } - -#endif // _WINDOWS diff --git a/base/third_party/symbolize/DEPS b/base/third_party/symbolize/DEPS deleted file mode 100644 index 73eab50..0000000 --- a/base/third_party/symbolize/DEPS +++ /dev/null @@ -1,3 +0,0 @@ -include_rules = [ - "+glog", -] diff --git a/base/third_party/symbolize/LICENSE b/base/third_party/symbolize/LICENSE deleted file mode 100644 index 433a3d1..0000000 --- a/base/third_party/symbolize/LICENSE +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) 2006, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/base/third_party/symbolize/README.chromium b/base/third_party/symbolize/README.chromium deleted file mode 100644 index 655f787..0000000 --- a/base/third_party/symbolize/README.chromium +++ /dev/null @@ -1,17 +0,0 @@ -Name: google-glog's symbolization library -URL: http://code.google.com/p/google-glog/ - -The following files are copied AS-IS from: -http://code.google.com/p/google-glog/source/browse/#svn/trunk/src (r76) - -- demangle.cc -- demangle.h -- symbolize.cc -- symbolize.h - -The following files are minimal stubs created for use in Chromium: - -- config.h -- glog/logging.h -- glog/raw_logging.h -- utilities.h diff --git a/base/third_party/symbolize/config.h b/base/third_party/symbolize/config.h deleted file mode 100644 index 945f5a6..0000000 --- a/base/third_party/symbolize/config.h +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#define GOOGLE_NAMESPACE google -#define _END_GOOGLE_NAMESPACE_ } -#define _START_GOOGLE_NAMESPACE_ namespace google { diff --git a/base/third_party/symbolize/demangle.cc b/base/third_party/symbolize/demangle.cc deleted file mode 100644 index 46556bf..0000000 --- a/base/third_party/symbolize/demangle.cc +++ /dev/null @@ -1,1231 +0,0 @@ -// Copyright (c) 2006, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: Satoru Takabayashi - -#include <stdio.h> // for NULL -#include "demangle.h" - -_START_GOOGLE_NAMESPACE_ - -typedef struct { - const char *abbrev; - const char *real_name; -} AbbrevPair; - -// List of operators from Itanium C++ ABI. -static const AbbrevPair kOperatorList[] = { - { "nw", "new" }, - { "na", "new[]" }, - { "dl", "delete" }, - { "da", "delete[]" }, - { "ps", "+" }, - { "ng", "-" }, - { "ad", "&" }, - { "de", "*" }, - { "co", "~" }, - { "pl", "+" }, - { "mi", "-" }, - { "ml", "*" }, - { "dv", "/" }, - { "rm", "%" }, - { "an", "&" }, - { "or", "|" }, - { "eo", "^" }, - { "aS", "=" }, - { "pL", "+=" }, - { "mI", "-=" }, - { "mL", "*=" }, - { "dV", "/=" }, - { "rM", "%=" }, - { "aN", "&=" }, - { "oR", "|=" }, - { "eO", "^=" }, - { "ls", "<<" }, - { "rs", ">>" }, - { "lS", "<<=" }, - { "rS", ">>=" }, - { "eq", "==" }, - { "ne", "!=" }, - { "lt", "<" }, - { "gt", ">" }, - { "le", "<=" }, - { "ge", ">=" }, - { "nt", "!" }, - { "aa", "&&" }, - { "oo", "||" }, - { "pp", "++" }, - { "mm", "--" }, - { "cm", "," }, - { "pm", "->*" }, - { "pt", "->" }, - { "cl", "()" }, - { "ix", "[]" }, - { "qu", "?" }, - { "st", "sizeof" }, - { "sz", "sizeof" }, - { NULL, NULL }, -}; - -// List of builtin types from Itanium C++ ABI. -static const AbbrevPair kBuiltinTypeList[] = { - { "v", "void" }, - { "w", "wchar_t" }, - { "b", "bool" }, - { "c", "char" }, - { "a", "signed char" }, - { "h", "unsigned char" }, - { "s", "short" }, - { "t", "unsigned short" }, - { "i", "int" }, - { "j", "unsigned int" }, - { "l", "long" }, - { "m", "unsigned long" }, - { "x", "long long" }, - { "y", "unsigned long long" }, - { "n", "__int128" }, - { "o", "unsigned __int128" }, - { "f", "float" }, - { "d", "double" }, - { "e", "long double" }, - { "g", "__float128" }, - { "z", "ellipsis" }, - { NULL, NULL } -}; - -// List of substitutions Itanium C++ ABI. -static const AbbrevPair kSubstitutionList[] = { - { "St", "" }, - { "Sa", "allocator" }, - { "Sb", "basic_string" }, - // std::basic_string<char, std::char_traits<char>,std::allocator<char> > - { "Ss", "string"}, - // std::basic_istream<char, std::char_traits<char> > - { "Si", "istream" }, - // std::basic_ostream<char, std::char_traits<char> > - { "So", "ostream" }, - // std::basic_iostream<char, std::char_traits<char> > - { "Sd", "iostream" }, - { NULL, NULL } -}; - -// State needed for demangling. -typedef struct { - const char *mangled_cur; // Cursor of mangled name. - const char *mangled_end; // End of mangled name. - char *out_cur; // Cursor of output string. - const char *out_begin; // Beginning of output string. - const char *out_end; // End of output string. - const char *prev_name; // For constructors/destructors. - int prev_name_length; // For constructors/destructors. - int nest_level; // For nested names. - int number; // Remember the previous number. - bool append; // Append flag. - bool overflowed; // True if output gets overflowed. -} State; - -// We don't use strlen() in libc since it's not guaranteed to be async -// signal safe. -static size_t StrLen(const char *str) { - size_t len = 0; - while (*str != '\0') { - ++str; - ++len; - } - return len; -} - -// Returns true if "str" has "prefix" as a prefix. -static bool StrPrefix(const char *str, const char *prefix) { - size_t i = 0; - while (str[i] != '\0' && prefix[i] != '\0' && - str[i] == prefix[i]) { - ++i; - } - return prefix[i] == '\0'; // Consumed everything in "prefix". -} - -static void InitState(State *state, const char *mangled, - char *out, int out_size) { - state->mangled_cur = mangled; - state->mangled_end = mangled + StrLen(mangled); - state->out_cur = out; - state->out_begin = out; - state->out_end = out + out_size; - state->prev_name = NULL; - state->prev_name_length = -1; - state->nest_level = -1; - state->number = -1; - state->append = true; - state->overflowed = false; -} - -// Calculates the remaining length of the mangled name. -static int RemainingLength(State *state) { - return state->mangled_end - state->mangled_cur; -} - -// Returns true and advances "mangled_cur" if we find "c" at -// "mangled_cur" position. -static bool ParseChar(State *state, const char c) { - if (RemainingLength(state) >= 1 && *state->mangled_cur == c) { - ++state->mangled_cur; - return true; - } - return false; -} - -// Returns true and advances "mangled_cur" if we find "two_chars" at -// "mangled_cur" position. -static bool ParseTwoChar(State *state, const char *two_chars) { - if (RemainingLength(state) >= 2 && - state->mangled_cur[0] == two_chars[0] && - state->mangled_cur[1] == two_chars[1]) { - state->mangled_cur += 2; - return true; - } - return false; -} - -// Returns true and advances "mangled_cur" if we find any character in -// "char_class" at "mangled_cur" position. -static bool ParseCharClass(State *state, const char *char_class) { - if (state->mangled_cur == state->mangled_end) { - return false; - } - const char *p = char_class; - for (; *p != '\0'; ++p) { - if (*state->mangled_cur == *p) { - state->mangled_cur += 1; - return true; - } - } - return false; -} - -// This function is used for handling an optional non-terminal. -static bool Optional(bool status) { - return true; -} - -// This function is used for handling <non-terminal>+ syntax. -typedef bool (*ParseFunc)(State *); -static bool OneOrMore(ParseFunc parse_func, State *state) { - if (parse_func(state)) { - while (parse_func(state)) { - } - return true; - } - return false; -} - -// Append "str" at "out_cur". If there is an overflow, "overflowed" -// is set to true for later use. The output string is ensured to -// always terminate with '\0' as long as there is no overflow. -static void Append(State *state, const char * const str, const int length) { - int i; - for (i = 0; i < length; ++i) { - if (state->out_cur + 1 < state->out_end) { // +1 for '\0' - *state->out_cur = str[i]; - ++state->out_cur; - } else { - state->overflowed = true; - break; - } - } - if (!state->overflowed) { - *state->out_cur = '\0'; // Terminate it with '\0' - } -} - -// We don't use equivalents in libc to avoid locale issues. -static bool IsLower(char c) { - return c >= 'a' && c <= 'z'; -} - -static bool IsAlpha(char c) { - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')); -} - -// Append "str" with some tweaks, iff "append" state is true. -// Returns true so that it can be placed in "if" conditions. -static void MaybeAppendWithLength(State *state, const char * const str, - const int length) { - if (state->append && length > 0) { - // Append a space if the output buffer ends with '<' and "str" - // starts with '<' to avoid <<<. - if (str[0] == '<' && state->out_begin < state->out_cur && - state->out_cur[-1] == '<') { - Append(state, " ", 1); - } - // Remember the last identifier name for ctors/dtors. - if (IsAlpha(str[0]) || str[0] == '_') { - state->prev_name = state->out_cur; - state->prev_name_length = length; - } - Append(state, str, length); - } -} - -// A convenient wrapper arount MaybeAppendWithLength(). -static bool MaybeAppend(State *state, const char * const str) { - if (state->append) { - int length = StrLen(str); - MaybeAppendWithLength(state, str, length); - } - return true; -} - -// This function is used for handling nested names. -static bool EnterNestedName(State *state) { - state->nest_level = 0; - return true; -} - -// This function is used for handling nested names. -static bool LeaveNestedName(State *state, int prev_value) { - state->nest_level = prev_value; - return true; -} - -// Disable the append mode not to print function parameters, etc. -static bool DisableAppend(State *state) { - state->append = false; - return true; -} - -// Restore the append mode to the previous state. -static bool RestoreAppend(State *state, bool prev_value) { - state->append = prev_value; - return true; -} - -// Increase the nest level for nested names. -static void MaybeIncreaseNestLevel(State *state) { - if (state->nest_level > -1) { - ++state->nest_level; - } -} - -// Appends :: for nested names if necessary. -static void MaybeAppendSeparator(State *state) { - if (state->nest_level >= 1) { - MaybeAppend(state, "::"); - } -} - -// Cancel the last separator if necessary. -static void MaybeCancelLastSeparator(State *state) { - if (state->nest_level >= 1 && state->append && - state->out_begin <= state->out_cur - 2) { - state->out_cur -= 2; - *state->out_cur = '\0'; - } -} - -// Returns true if identifier pointed by "mangled_cur" is anonymous -// namespace. -static bool IdentifierIsAnonymousNamespace(State *state) { - const char anon_prefix[] = "_GLOBAL__N_"; - return (state->number > sizeof(anon_prefix) - 1 && // Should be longer. - StrPrefix(state->mangled_cur, anon_prefix)); -} - -// Forward declarations of our parsing functions. -static bool ParseMangledName(State *state); -static bool ParseEncoding(State *state); -static bool ParseName(State *state); -static bool ParseUnscopedName(State *state); -static bool ParseUnscopedTemplateName(State *state); -static bool ParseNestedName(State *state); -static bool ParsePrefix(State *state); -static bool ParseUnqualifiedName(State *state); -static bool ParseSourceName(State *state); -static bool ParseLocalSourceName(State *state); -static bool ParseNumber(State *state); -static bool ParseFloatNumber(State *state); -static bool ParseSeqId(State *state); -static bool ParseIdentifier(State *state); -static bool ParseOperatorName(State *state); -static bool ParseSpecialName(State *state); -static bool ParseCallOffset(State *state); -static bool ParseNVOffset(State *state); -static bool ParseVOffset(State *state); -static bool ParseCtorDtorName(State *state); -static bool ParseType(State *state); -static bool ParseCVQualifiers(State *state); -static bool ParseBuiltinType(State *state); -static bool ParseFunctionType(State *state); -static bool ParseBareFunctionType(State *state); -static bool ParseClassEnumType(State *state); -static bool ParseArrayType(State *state); -static bool ParsePointerToMemberType(State *state); -static bool ParseTemplateParam(State *state); -static bool ParseTemplateTemplateParam(State *state); -static bool ParseTemplateArgs(State *state); -static bool ParseTemplateArg(State *state); -static bool ParseExpression(State *state); -static bool ParseExprPrimary(State *state); -static bool ParseLocalName(State *state); -static bool ParseDiscriminator(State *state); -static bool ParseSubstitution(State *state); - -// Implementation note: the following code is a straightforward -// translation of the Itanium C++ ABI defined in BNF with a couple of -// exceptions. -// -// - Support GNU extensions not defined in the Itanium C++ ABI -// - <prefix> and <template-prefix> are combined to avoid infinite loop -// - Reorder patterns to shorten the code -// - Reorder patterns to give greedier functions precedence -// We'll mark "Less greedy than" for these cases in the code -// -// Each parsing function changes the state and returns true on -// success. Otherwise, don't change the state and returns false. To -// ensure that the state isn't changed in the latter case, we save the -// original state before we call more than one parsing functions -// consecutively with &&, and restore the state if unsuccessful. See -// ParseEncoding() as an example of this convention. We follow the -// convention throughout the code. -// -// Originally we tried to do demangling without following the full ABI -// syntax but it turned out we needed to follow the full syntax to -// parse complicated cases like nested template arguments. Note that -// implementing a full-fledged demangler isn't trivial (libiberty's -// cp-demangle.c has +4300 lines). -// -// Note that (foo) in <(foo) ...> is a modifier to be ignored. -// -// Reference: -// - Itanium C++ ABI -// <http://www.codesourcery.com/cxx-abi/abi.html#mangling> - -// <mangled-name> ::= _Z <encoding> -static bool ParseMangledName(State *state) { - if (ParseTwoChar(state, "_Z") && ParseEncoding(state)) { - // Append trailing version suffix if any. - // ex. _Z3foo@@GLIBCXX_3.4 - if (state->mangled_cur < state->mangled_end && - state->mangled_cur[0] == '@') { - MaybeAppend(state, state->mangled_cur); - state->mangled_cur = state->mangled_end; - } - return true; - } - return false; -} - -// <encoding> ::= <(function) name> <bare-function-type> -// ::= <(data) name> -// ::= <special-name> -static bool ParseEncoding(State *state) { - State copy = *state; - if (ParseName(state) && ParseBareFunctionType(state)) { - return true; - } - *state = copy; - - if (ParseName(state) || ParseSpecialName(state)) { - return true; - } - return false; -} - -// <name> ::= <nested-name> -// ::= <unscoped-template-name> <template-args> -// ::= <unscoped-name> -// ::= <local-name> -static bool ParseName(State *state) { - if (ParseNestedName(state) || ParseLocalName(state)) { - return true; - } - - State copy = *state; - if (ParseUnscopedTemplateName(state) && - ParseTemplateArgs(state)) { - return true; - } - *state = copy; - - // Less greedy than <unscoped-template-name> <template-args>. - if (ParseUnscopedName(state)) { - return true; - } - return false; -} - -// <unscoped-name> ::= <unqualified-name> -// ::= St <unqualified-name> -static bool ParseUnscopedName(State *state) { - if (ParseUnqualifiedName(state)) { - return true; - } - - State copy = *state; - if (ParseTwoChar(state, "St") && - MaybeAppend(state, "std::") && - ParseUnqualifiedName(state)) { - return true; - } - *state = copy; - return false; -} - -// <unscoped-template-name> ::= <unscoped-name> -// ::= <substitution> -static bool ParseUnscopedTemplateName(State *state) { - return ParseUnscopedName(state) || ParseSubstitution(state); -} - -// <nested-name> ::= N [<CV-qualifiers>] <prefix> <unqualified-name> E -// ::= N [<CV-qualifiers>] <template-prefix> <template-args> E -static bool ParseNestedName(State *state) { - State copy = *state; - if (ParseChar(state, 'N') && - EnterNestedName(state) && - Optional(ParseCVQualifiers(state)) && - ParsePrefix(state) && - LeaveNestedName(state, copy.nest_level) && - ParseChar(state, 'E')) { - return true; - } - *state = copy; - return false; -} - -// This part is tricky. If we literally translate them to code, we'll -// end up infinite loop. Hence we merge them to avoid the case. -// -// <prefix> ::= <prefix> <unqualified-name> -// ::= <template-prefix> <template-args> -// ::= <template-param> -// ::= <substitution> -// ::= # empty -// <template-prefix> ::= <prefix> <(template) unqualified-name> -// ::= <template-param> -// ::= <substitution> -static bool ParsePrefix(State *state) { - bool has_something = false; - while (true) { - MaybeAppendSeparator(state); - if (ParseTemplateParam(state) || - ParseSubstitution(state) || - ParseUnscopedName(state)) { - has_something = true; - MaybeIncreaseNestLevel(state); - continue; - } - MaybeCancelLastSeparator(state); - if (has_something && ParseTemplateArgs(state)) { - return ParsePrefix(state); - } else { - break; - } - } - return true; -} - -// <unqualified-name> ::= <operator-name> -// ::= <ctor-dtor-name> -// ::= <source-name> -// ::= <local-source-name> -static bool ParseUnqualifiedName(State *state) { - return (ParseOperatorName(state) || - ParseCtorDtorName(state) || - ParseSourceName(state) || - ParseLocalSourceName(state)); -} - -// <source-name> ::= <positive length number> <identifier> -static bool ParseSourceName(State *state) { - State copy = *state; - if (ParseNumber(state) && ParseIdentifier(state)) { - return true; - } - *state = copy; - return false; -} - -// <local-source-name> ::= L <source-name> [<discriminator>] -// -// References: -// http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31775 -// http://gcc.gnu.org/viewcvs?view=rev&revision=124467 -static bool ParseLocalSourceName(State *state) { - State copy = *state; - if (ParseChar(state, 'L') && ParseSourceName(state) && - Optional(ParseDiscriminator(state))) { - return true; - } - *state = copy; - return false; -} - -// <number> ::= [n] <non-negative decimal integer> -static bool ParseNumber(State *state) { - int sign = 1; - if (ParseChar(state, 'n')) { - sign = -1; - } - const char *p = state->mangled_cur; - int number = 0; - for (;p < state->mangled_end; ++p) { - if ((*p >= '0' && *p <= '9')) { - number = number * 10 + (*p - '0'); - } else { - break; - } - } - if (p != state->mangled_cur) { // Conversion succeeded. - state->mangled_cur = p; - state->number = number * sign; - return true; - } - return false; -} - -// Floating-point literals are encoded using a fixed-length lowercase -// hexadecimal string. -static bool ParseFloatNumber(State *state) { - const char *p = state->mangled_cur; - int number = 0; - for (;p < state->mangled_end; ++p) { - if ((*p >= '0' && *p <= '9')) { - number = number * 16 + (*p - '0'); - } else if (*p >= 'a' && *p <= 'f') { - number = number * 16 + (*p - 'a' + 10); - } else { - break; - } - } - if (p != state->mangled_cur) { // Conversion succeeded. - state->mangled_cur = p; - state->number = number; - return true; - } - return false; -} - -// The <seq-id> is a sequence number in base 36, -// using digits and upper case letters -static bool ParseSeqId(State *state) { - const char *p = state->mangled_cur; - int number = 0; - for (;p < state->mangled_end; ++p) { - if ((*p >= '0' && *p <= '9')) { - number = number * 36 + (*p - '0'); - } else if (*p >= 'A' && *p <= 'Z') { - number = number * 36 + (*p - 'A' + 10); - } else { - break; - } - } - if (p != state->mangled_cur) { // Conversion succeeded. - state->mangled_cur = p; - state->number = number; - return true; - } - return false; -} - -// <identifier> ::= <unqualified source code identifier> -static bool ParseIdentifier(State *state) { - if (state->number == -1 || - RemainingLength(state) < state->number) { - return false; - } - if (IdentifierIsAnonymousNamespace(state)) { - MaybeAppend(state, "(anonymous namespace)"); - } else { - MaybeAppendWithLength(state, state->mangled_cur, state->number); - } - state->mangled_cur += state->number; - state->number = -1; // Reset the number. - return true; -} - -// <operator-name> ::= nw, and other two letters cases -// ::= cv <type> # (cast) -// ::= v <digit> <source-name> # vendor extended operator -static bool ParseOperatorName(State *state) { - if (RemainingLength(state) < 2) { - return false; - } - // First check with "cv" (cast) case. - State copy = *state; - if (ParseTwoChar(state, "cv") && - MaybeAppend(state, "operator ") && - EnterNestedName(state) && - ParseType(state) && - LeaveNestedName(state, copy.nest_level)) { - return true; - } - *state = copy; - - // Then vendor extended operators. - if (ParseChar(state, 'v') && ParseCharClass(state, "0123456789") && - ParseSourceName(state)) { - return true; - } - *state = copy; - - // Other operator names should start with a lower alphabet followed - // by a lower/upper alphabet. - if (!(IsLower(state->mangled_cur[0]) && - IsAlpha(state->mangled_cur[1]))) { - return false; - } - // We may want to perform a binary search if we really need speed. - const AbbrevPair *p; - for (p = kOperatorList; p->abbrev != NULL; ++p) { - if (state->mangled_cur[0] == p->abbrev[0] && - state->mangled_cur[1] == p->abbrev[1]) { - MaybeAppend(state, "operator"); - if (IsLower(*p->real_name)) { // new, delete, etc. - MaybeAppend(state, " "); - } - MaybeAppend(state, p->real_name); - state->mangled_cur += 2; - return true; - } - } - return false; -} - -// <special-name> ::= TV <type> -// ::= TT <type> -// ::= TI <type> -// ::= TS <type> -// ::= Tc <call-offset> <call-offset> <(base) encoding> -// ::= GV <(object) name> -// ::= T <call-offset> <(base) encoding> -// G++ extensions: -// ::= TC <type> <(offset) number> _ <(base) type> -// ::= TF <type> -// ::= TJ <type> -// ::= GR <name> -// ::= GA <encoding> -// ::= Th <call-offset> <(base) encoding> -// ::= Tv <call-offset> <(base) encoding> -// -// Note: we don't care much about them since they don't appear in -// stack traces. The are special data. -static bool ParseSpecialName(State *state) { - State copy = *state; - if (ParseChar(state, 'T') && - ParseCharClass(state, "VTIS") && - ParseType(state)) { - return true; - } - *state = copy; - - if (ParseTwoChar(state, "Tc") && ParseCallOffset(state) && - ParseCallOffset(state) && ParseEncoding(state)) { - return true; - } - *state = copy; - - if (ParseTwoChar(state, "GV") && - ParseName(state)) { - return true; - } - *state = copy; - - if (ParseChar(state, 'T') && ParseCallOffset(state) && - ParseEncoding(state)) { - return true; - } - *state = copy; - - // G++ extensions - if (ParseTwoChar(state, "TC") && ParseType(state) && - ParseNumber(state) && ParseChar(state, '_') && - DisableAppend(state) && - ParseType(state)) { - RestoreAppend(state, copy.append); - return true; - } - *state = copy; - - if (ParseChar(state, 'T') && ParseCharClass(state, "FJ") && - ParseType(state)) { - return true; - } - *state = copy; - - if (ParseTwoChar(state, "GR") && ParseName(state)) { - return true; - } - *state = copy; - - if (ParseTwoChar(state, "GA") && ParseEncoding(state)) { - return true; - } - *state = copy; - - if (ParseChar(state, 'T') && ParseCharClass(state, "hv") && - ParseCallOffset(state) && ParseEncoding(state)) { - return true; - } - *state = copy; - return false; -} - -// <call-offset> ::= h <nv-offset> _ -// ::= v <v-offset> _ -static bool ParseCallOffset(State *state) { - State copy = *state; - if (ParseChar(state, 'h') && - ParseNVOffset(state) && ParseChar(state, '_')) { - return true; - } - *state = copy; - - if (ParseChar(state, 'v') && - ParseVOffset(state) && ParseChar(state, '_')) { - return true; - } - *state = copy; - - return false; -} - -// <nv-offset> ::= <(offset) number> -static bool ParseNVOffset(State *state) { - return ParseNumber(state); -} - -// <v-offset> ::= <(offset) number> _ <(virtual offset) number> -static bool ParseVOffset(State *state) { - State copy = *state; - if (ParseNumber(state) && ParseChar(state, '_') && - ParseNumber(state)) { - return true; - } - *state = copy; - return false; -} - -// <ctor-dtor-name> ::= C1 | C2 | C3 -// ::= D0 | D1 | D2 -static bool ParseCtorDtorName(State *state) { - State copy = *state; - if (ParseChar(state, 'C') && - ParseCharClass(state, "123")) { - const char * const prev_name = state->prev_name; - const int prev_name_length = state->prev_name_length; - MaybeAppendWithLength(state, prev_name, prev_name_length); - return true; - } - *state = copy; - - if (ParseChar(state, 'D') && - ParseCharClass(state, "012")) { - const char * const prev_name = state->prev_name; - const int prev_name_length = state->prev_name_length; - MaybeAppend(state, "~"); - MaybeAppendWithLength(state, prev_name, prev_name_length); - return true; - } - *state = copy; - return false; -} - -// <type> ::= <CV-qualifiers> <type> -// ::= P <type> -// ::= R <type> -// ::= C <type> -// ::= G <type> -// ::= U <source-name> <type> -// ::= <builtin-type> -// ::= <function-type> -// ::= <class-enum-type> -// ::= <array-type> -// ::= <pointer-to-member-type> -// ::= <template-template-param> <template-args> -// ::= <template-param> -// ::= <substitution> -static bool ParseType(State *state) { - // We should check CV-qualifers, and PRGC things first. - State copy = *state; - if (ParseCVQualifiers(state) && ParseType(state)) { - return true; - } - *state = copy; - - if (ParseCharClass(state, "PRCG") && ParseType(state)) { - return true; - } - *state = copy; - - if (ParseChar(state, 'U') && ParseSourceName(state) && - ParseType(state)) { - return true; - } - *state = copy; - - if (ParseBuiltinType(state) || - ParseFunctionType(state) || - ParseClassEnumType(state) || - ParseArrayType(state) || - ParsePointerToMemberType(state) || - ParseSubstitution(state)) { - return true; - } - - if (ParseTemplateTemplateParam(state) && - ParseTemplateArgs(state)) { - return true; - } - *state = copy; - - // Less greedy than <template-template-param> <template-args>. - if (ParseTemplateParam(state)) { - return true; - } - - return false; -} - -// <CV-qualifiers> ::= [r] [V] [K] -// We don't allow empty <CV-qualifiers> to avoid infinite loop in -// ParseType(). -static bool ParseCVQualifiers(State *state) { - int num_cv_qualifiers = 0; - num_cv_qualifiers += ParseChar(state, 'r'); - num_cv_qualifiers += ParseChar(state, 'V'); - num_cv_qualifiers += ParseChar(state, 'K'); - return num_cv_qualifiers > 0; -} - -// <builtin-type> ::= v, etc. -// ::= u <source-name> -static bool ParseBuiltinType(State *state) { - const AbbrevPair *p; - for (p = kBuiltinTypeList; p->abbrev != NULL; ++p) { - if (state->mangled_cur[0] == p->abbrev[0]) { - MaybeAppend(state, p->real_name); - ++state->mangled_cur; - return true; - } - } - - State copy = *state; - if (ParseChar(state, 'u') && ParseSourceName(state)) { - return true; - } - *state = copy; - return false; -} - -// <function-type> ::= F [Y] <bare-function-type> E -static bool ParseFunctionType(State *state) { - State copy = *state; - if (ParseChar(state, 'F') && Optional(ParseChar(state, 'Y')) && - ParseBareFunctionType(state) && ParseChar(state, 'E')) { - return true; - } - *state = copy; - return false; -} - -// <bare-function-type> ::= <(signature) type>+ -static bool ParseBareFunctionType(State *state) { - State copy = *state; - DisableAppend(state); - if (OneOrMore(ParseType, state)) { - RestoreAppend(state, copy.append); - MaybeAppend(state, "()"); - return true; - } - *state = copy; - return false; -} - -// <class-enum-type> ::= <name> -static bool ParseClassEnumType(State *state) { - return ParseName(state); -} - -// <array-type> ::= A <(positive dimension) number> _ <(element) type> -// ::= A [<(dimension) expression>] _ <(element) type> -static bool ParseArrayType(State *state) { - State copy = *state; - if (ParseChar(state, 'A') && ParseNumber(state) && - ParseChar(state, '_') && ParseType(state)) { - return true; - } - *state = copy; - - if (ParseChar(state, 'A') && Optional(ParseExpression(state)) && - ParseChar(state, '_') && ParseType(state)) { - return true; - } - *state = copy; - return false; -} - -// <pointer-to-member-type> ::= M <(class) type> <(member) type> -static bool ParsePointerToMemberType(State *state) { - State copy = *state; - if (ParseChar(state, 'M') && ParseType(state) && - ParseType(state)) { - return true; - } - *state = copy; - return false; -} - -// <template-param> ::= T_ -// ::= T <parameter-2 non-negative number> _ -static bool ParseTemplateParam(State *state) { - if (ParseTwoChar(state, "T_")) { - MaybeAppend(state, "?"); // We don't support template substitutions. - return true; - } - - State copy = *state; - if (ParseChar(state, 'T') && ParseNumber(state) && - ParseChar(state, '_')) { - MaybeAppend(state, "?"); // We don't support template substitutions. - return true; - } - *state = copy; - return false; -} - - -// <template-template-param> ::= <template-param> -// ::= <substitution> -static bool ParseTemplateTemplateParam(State *state) { - return (ParseTemplateParam(state) || - ParseSubstitution(state)); -} - -// <template-args> ::= I <template-arg>+ E -static bool ParseTemplateArgs(State *state) { - State copy = *state; - DisableAppend(state); - if (ParseChar(state, 'I') && - OneOrMore(ParseTemplateArg, state) && - ParseChar(state, 'E')) { - RestoreAppend(state, copy.append); - MaybeAppend(state, "<>"); - return true; - } - *state = copy; - return false; -} - -// <template-arg> ::= <type> -// ::= <expr-primary> -// ::= X <expression> E -static bool ParseTemplateArg(State *state) { - if (ParseType(state) || - ParseExprPrimary(state)) { - return true; - } - - State copy = *state; - if (ParseChar(state, 'X') && ParseExpression(state) && - ParseChar(state, 'E')) { - return true; - } - *state = copy; - return false; -} - -// <expression> ::= <template-param> -// ::= <expr-primary> -// ::= <unary operator-name> <expression> -// ::= <binary operator-name> <expression> <expression> -// ::= <trinary operator-name> <expression> <expression> -// <expression> -// ::= st <type> -// ::= sr <type> <unqualified-name> <template-args> -// ::= sr <type> <unqualified-name> -static bool ParseExpression(State *state) { - if (ParseTemplateParam(state) || ParseExprPrimary(state)) { - return true; - } - - State copy = *state; - if (ParseOperatorName(state) && - ParseExpression(state) && - ParseExpression(state) && - ParseExpression(state)) { - return true; - } - *state = copy; - - if (ParseOperatorName(state) && - ParseExpression(state) && - ParseExpression(state)) { - return true; - } - *state = copy; - - if (ParseOperatorName(state) && - ParseExpression(state)) { - return true; - } - *state = copy; - - if (ParseTwoChar(state, "st") && ParseType(state)) { - return true; - } - *state = copy; - - if (ParseTwoChar(state, "sr") && ParseType(state) && - ParseUnqualifiedName(state) && - ParseTemplateArgs(state)) { - return true; - } - *state = copy; - - if (ParseTwoChar(state, "sr") && ParseType(state) && - ParseUnqualifiedName(state)) { - return true; - } - *state = copy; - return false; -} - -// <expr-primary> ::= L <type> <(value) number> E -// ::= L <type> <(value) float> E -// ::= L <mangled-name> E -// // A bug in g++'s C++ ABI version 2 (-fabi-version=2). -// ::= LZ <encoding> E -static bool ParseExprPrimary(State *state) { - State copy = *state; - if (ParseChar(state, 'L') && ParseType(state) && - ParseNumber(state) && - ParseChar(state, 'E')) { - return true; - } - *state = copy; - - if (ParseChar(state, 'L') && ParseType(state) && - ParseFloatNumber(state) && - ParseChar(state, 'E')) { - return true; - } - *state = copy; - - if (ParseChar(state, 'L') && ParseMangledName(state) && - ParseChar(state, 'E')) { - return true; - } - *state = copy; - - if (ParseTwoChar(state, "LZ") && ParseEncoding(state) && - ParseChar(state, 'E')) { - return true; - } - *state = copy; - - return false; -} - -// <local-name> := Z <(function) encoding> E <(entity) name> -// [<discriminator>] -// := Z <(function) encoding> E s [<discriminator>] -static bool ParseLocalName(State *state) { - State copy = *state; - if (ParseChar(state, 'Z') && ParseEncoding(state) && - ParseChar(state, 'E') && MaybeAppend(state, "::") && - ParseName(state) && Optional(ParseDiscriminator(state))) { - return true; - } - *state = copy; - - if (ParseChar(state, 'Z') && ParseEncoding(state) && - ParseTwoChar(state, "Es") && Optional(ParseDiscriminator(state))) { - return true; - } - *state = copy; - return false; -} - -// <discriminator> := _ <(non-negative) number> -static bool ParseDiscriminator(State *state) { - State copy = *state; - if (ParseChar(state, '_') && ParseNumber(state)) { - return true; - } - *state = copy; - return false; -} - -// <substitution> ::= S_ -// ::= S <seq-id> _ -// ::= St, etc. -static bool ParseSubstitution(State *state) { - if (ParseTwoChar(state, "S_")) { - MaybeAppend(state, "?"); // We don't support substitutions. - return true; - } - - State copy = *state; - if (ParseChar(state, 'S') && ParseSeqId(state) && - ParseChar(state, '_')) { - MaybeAppend(state, "?"); // We don't support substitutions. - return true; - } - *state = copy; - - // Expand abbreviations like "St" => "std". - if (ParseChar(state, 'S')) { - const AbbrevPair *p; - for (p = kSubstitutionList; p->abbrev != NULL; ++p) { - if (state->mangled_cur[0] == p->abbrev[1]) { - MaybeAppend(state, "std"); - if (p->real_name[0] != '\0') { - MaybeAppend(state, "::"); - MaybeAppend(state, p->real_name); - } - state->mangled_cur += 1; - return true; - } - } - } - *state = copy; - return false; -} - -// The demangler entry point. -bool Demangle(const char *mangled, char *out, int out_size) { - State state; - InitState(&state, mangled, out, out_size); - return (ParseMangledName(&state) && - state.overflowed == false && - RemainingLength(&state) == 0); -} - -_END_GOOGLE_NAMESPACE_ diff --git a/base/third_party/symbolize/demangle.h b/base/third_party/symbolize/demangle.h deleted file mode 100644 index 9c75915..0000000 --- a/base/third_party/symbolize/demangle.h +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright (c) 2006, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: Satoru Takabayashi -// -// An async-signal-safe and thread-safe demangler for Itanium C++ ABI -// (aka G++ V3 ABI). - -// The demangler is implemented to be used in async signal handlers to -// symbolize stack traces. We cannot use libstdc++'s -// abi::__cxa_demangle() in such signal handlers since it's not async -// signal safe (it uses malloc() internally). -// -// Note that this demangler doesn't support full demangling. More -// specifically, it doesn't print types of function parameters and -// types of template arguments. It just skips them. However, it's -// still very useful to extract basic information such as class, -// function, constructor, destructor, and operator names. -// -// See the implementation note in demangle.cc if you are interested. -// -// Example: -// -// | Mangled Name | The Demangler | abi::__cxa_demangle() -// |---------------|---------------|----------------------- -// | _Z1fv | f() | f() -// | _Z1fi | f() | f(int) -// | _Z3foo3bar | foo() | foo(bar) -// | _Z1fIiEvi | f<>() | void f<int>(int) -// | _ZN1N1fE | N::f | N::f -// | _ZN3Foo3BarEv | Foo::Bar() | Foo::Bar() -// | _Zrm1XS_" | operator%() | operator%(X, X) -// | _ZN3FooC1Ev | Foo::Foo() | Foo::Foo() -// | _Z1fSs | f() | f(std::basic_string<char, -// | | | std::char_traits<char>, -// | | | std::allocator<char> >) -// -// See the unit test for more examples. -// -// Note: we might want to write demanglers for ABIs other than Itanium -// C++ ABI in the future. -// - -#ifndef BASE_DEMANGLE_H_ -#define BASE_DEMANGLE_H_ - -#include "config.h" - -_START_GOOGLE_NAMESPACE_ - -// Demangle "mangled". On success, return true and write the -// demangled symbol name to "out". Otherwise, return false. -// "out" is modified even if demangling is unsuccessful. -bool Demangle(const char *mangled, char *out, int out_size); - -_END_GOOGLE_NAMESPACE_ - -#endif // BASE_DEMANGLE_H_ diff --git a/base/third_party/symbolize/glog/logging.h b/base/third_party/symbolize/glog/logging.h deleted file mode 100644 index a42c306..0000000 --- a/base/third_party/symbolize/glog/logging.h +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Empty. diff --git a/base/third_party/symbolize/glog/raw_logging.h b/base/third_party/symbolize/glog/raw_logging.h deleted file mode 100644 index f5515c4..0000000 --- a/base/third_party/symbolize/glog/raw_logging.h +++ /dev/null @@ -1,6 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#define WARNING 1; -#define RAW_LOG(severity, ...); // Do nothing. diff --git a/base/third_party/symbolize/symbolize.cc b/base/third_party/symbolize/symbolize.cc deleted file mode 100644 index 3465de6..0000000 --- a/base/third_party/symbolize/symbolize.cc +++ /dev/null @@ -1,681 +0,0 @@ -// Copyright (c) 2006, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: Satoru Takabayashi -// Stack-footprint reduction work done by Raksit Ashok -// -// Implementation note: -// -// We don't use heaps but only use stacks. We want to reduce the -// stack consumption so that the symbolizer can run on small stacks. -// -// Here are some numbers collected with GCC 4.1.0 on x86: -// - sizeof(Elf32_Sym) = 16 -// - sizeof(Elf32_Shdr) = 40 -// - sizeof(Elf64_Sym) = 24 -// - sizeof(Elf64_Shdr) = 64 -// -// This implementation is intended to be async-signal-safe but uses -// some functions which are not guaranteed to be so, such as memchr() -// and memmove(). We assume they are async-signal-safe. -// - -#include "utilities.h" - -#if defined(HAVE_SYMBOLIZE) - -#include <limits> - -#include "symbolize.h" -#include "demangle.h" - -_START_GOOGLE_NAMESPACE_ - -// We don't use assert() since it's not guaranteed to be -// async-signal-safe. Instead we define a minimal assertion -// macro. So far, we don't need pretty printing for __FILE__, etc. - -// A wrapper for abort() to make it callable in ? :. -static int AssertFail() { - abort(); - return 0; // Should not reach. -} - -#define SAFE_ASSERT(expr) ((expr) ? 0 : AssertFail()) - -static SymbolizeCallback g_symbolize_callback = NULL; -void InstallSymbolizeCallback(SymbolizeCallback callback) { - g_symbolize_callback = callback; -} - -// This function wraps the Demangle function to provide an interface -// where the input symbol is demangled in-place. -// To keep stack consumption low, we would like this function to not -// get inlined. -static ATTRIBUTE_NOINLINE void DemangleInplace(char *out, int out_size) { - char demangled[256]; // Big enough for sane demangled symbols. - if (Demangle(out, demangled, sizeof(demangled))) { - // Demangling succeeded. Copy to out if the space allows. - int len = strlen(demangled); - if (len + 1 <= out_size) { // +1 for '\0'. - SAFE_ASSERT(len < sizeof(demangled)); - memmove(out, demangled, len + 1); - } - } -} - -_END_GOOGLE_NAMESPACE_ - -#if defined(__ELF__) - -#include <dlfcn.h> -#include <elf.h> -#include <errno.h> -#include <fcntl.h> -#include <limits.h> -#include <link.h> // For ElfW() macro. -#include <stdint.h> -#include <stdio.h> -#include <stdlib.h> -#include <stddef.h> -#include <string.h> -#include <sys/stat.h> -#include <sys/types.h> -#include <unistd.h> - -#include "symbolize.h" -#include "config.h" -#include "glog/raw_logging.h" - -// Re-runs fn until it doesn't cause EINTR. -#define NO_INTR(fn) do {} while ((fn) < 0 && errno == EINTR) - -_START_GOOGLE_NAMESPACE_ - -// Read up to "count" bytes from file descriptor "fd" into the buffer -// starting at "buf" while handling short reads and EINTR. On -// success, return the number of bytes read. Otherwise, return -1. -static ssize_t ReadPersistent(const int fd, void *buf, const size_t count) { - SAFE_ASSERT(fd >= 0); - SAFE_ASSERT(count >= 0 && count <= std::numeric_limits<ssize_t>::max()); - char *buf0 = reinterpret_cast<char *>(buf); - ssize_t num_bytes = 0; - while (num_bytes < count) { - ssize_t len; - NO_INTR(len = read(fd, buf0 + num_bytes, count - num_bytes)); - if (len < 0) { // There was an error other than EINTR. - return -1; - } - if (len == 0) { // Reached EOF. - break; - } - num_bytes += len; - } - SAFE_ASSERT(num_bytes <= count); - return num_bytes; -} - -// Read up to "count" bytes from "offset" in the file pointed by file -// descriptor "fd" into the buffer starting at "buf". On success, -// return the number of bytes read. Otherwise, return -1. -static ssize_t ReadFromOffset(const int fd, void *buf, - const size_t count, const off_t offset) { - off_t off = lseek(fd, offset, SEEK_SET); - if (off == (off_t)-1) { - return -1; - } - return ReadPersistent(fd, buf, count); -} - -// Try reading exactly "count" bytes from "offset" bytes in a file -// pointed by "fd" into the buffer starting at "buf" while handling -// short reads and EINTR. On success, return true. Otherwise, return -// false. -static bool ReadFromOffsetExact(const int fd, void *buf, - const size_t count, const off_t offset) { - ssize_t len = ReadFromOffset(fd, buf, count, offset); - return len == count; -} - -// Returns elf_header.e_type if the file pointed by fd is an ELF binary. -static int FileGetElfType(const int fd) { - ElfW(Ehdr) elf_header; - if (!ReadFromOffsetExact(fd, &elf_header, sizeof(elf_header), 0)) { - return -1; - } - if (memcmp(elf_header.e_ident, ELFMAG, SELFMAG) != 0) { - return -1; - } - return elf_header.e_type; -} - -// Read the section headers in the given ELF binary, and if a section -// of the specified type is found, set the output to this section header -// and return true. Otherwise, return false. -// To keep stack consumption low, we would like this function to not get -// inlined. -static ATTRIBUTE_NOINLINE bool -GetSectionHeaderByType(const int fd, ElfW(Half) sh_num, const off_t sh_offset, - ElfW(Word) type, ElfW(Shdr) *out) { - // Read at most 16 section headers at a time to save read calls. - ElfW(Shdr) buf[16]; - for (int i = 0; i < sh_num;) { - const ssize_t num_bytes_left = (sh_num - i) * sizeof(buf[0]); - const ssize_t num_bytes_to_read = - (sizeof(buf) > num_bytes_left) ? num_bytes_left : sizeof(buf); - const ssize_t len = ReadFromOffset(fd, buf, num_bytes_to_read, - sh_offset + i * sizeof(buf[0])); - SAFE_ASSERT(len % sizeof(buf[0]) == 0); - const ssize_t num_headers_in_buf = len / sizeof(buf[0]); - SAFE_ASSERT(num_headers_in_buf <= sizeof(buf) / sizeof(buf[0])); - for (int j = 0; j < num_headers_in_buf; ++j) { - if (buf[j].sh_type == type) { - *out = buf[j]; - return true; - } - } - i += num_headers_in_buf; - } - return false; -} - -// There is no particular reason to limit section name to 63 characters, -// but there has (as yet) been no need for anything longer either. -const int kMaxSectionNameLen = 64; - -// name_len should include terminating '\0'. -bool GetSectionHeaderByName(int fd, const char *name, size_t name_len, - ElfW(Shdr) *out) { - ElfW(Ehdr) elf_header; - if (!ReadFromOffsetExact(fd, &elf_header, sizeof(elf_header), 0)) { - return false; - } - - ElfW(Shdr) shstrtab; - off_t shstrtab_offset = (elf_header.e_shoff + - elf_header.e_shentsize * elf_header.e_shstrndx); - if (!ReadFromOffsetExact(fd, &shstrtab, sizeof(shstrtab), shstrtab_offset)) { - return false; - } - - for (int i = 0; i < elf_header.e_shnum; ++i) { - off_t section_header_offset = (elf_header.e_shoff + - elf_header.e_shentsize * i); - if (!ReadFromOffsetExact(fd, out, sizeof(*out), section_header_offset)) { - return false; - } - char header_name[kMaxSectionNameLen]; - if (sizeof(header_name) < name_len) { - RAW_LOG(WARNING, "Section name '%s' is too long (%"PRIuS"); " - "section will not be found (even if present).", name, name_len); - // No point in even trying. - return false; - } - off_t name_offset = shstrtab.sh_offset + out->sh_name; - ssize_t n_read = ReadFromOffset(fd, &header_name, name_len, name_offset); - if (n_read == -1) { - return false; - } else if (n_read != name_len) { - // Short read -- name could be at end of file. - continue; - } - if (memcmp(header_name, name, name_len) == 0) { - return true; - } - } - return false; -} - -// Read a symbol table and look for the symbol containing the -// pc. Iterate over symbols in a symbol table and look for the symbol -// containing "pc". On success, return true and write the symbol name -// to out. Otherwise, return false. -// To keep stack consumption low, we would like this function to not get -// inlined. -static ATTRIBUTE_NOINLINE bool -FindSymbol(uint64_t pc, const int fd, char *out, int out_size, - uint64_t symbol_offset, const ElfW(Shdr) *strtab, - const ElfW(Shdr) *symtab) { - if (symtab == NULL) { - return false; - } - const int num_symbols = symtab->sh_size / symtab->sh_entsize; - for (int i = 0; i < num_symbols;) { - off_t offset = symtab->sh_offset + i * symtab->sh_entsize; - - // If we are reading Elf64_Sym's, we want to limit this array to - // 32 elements (to keep stack consumption low), otherwise we can - // have a 64 element Elf32_Sym array. -#if __WORDSIZE == 64 -#define NUM_SYMBOLS 32 -#else -#define NUM_SYMBOLS 64 -#endif - - // Read at most NUM_SYMBOLS symbols at once to save read() calls. - ElfW(Sym) buf[NUM_SYMBOLS]; - const ssize_t len = ReadFromOffset(fd, &buf, sizeof(buf), offset); - SAFE_ASSERT(len % sizeof(buf[0]) == 0); - const ssize_t num_symbols_in_buf = len / sizeof(buf[0]); - SAFE_ASSERT(num_symbols_in_buf <= sizeof(buf)/sizeof(buf[0])); - for (int j = 0; j < num_symbols_in_buf; ++j) { - const ElfW(Sym)& symbol = buf[j]; - uint64_t start_address = symbol.st_value; - start_address += symbol_offset; - uint64_t end_address = start_address + symbol.st_size; - if (symbol.st_value != 0 && // Skip null value symbols. - symbol.st_shndx != 0 && // Skip undefined symbols. - start_address <= pc && pc < end_address) { - ssize_t len1 = ReadFromOffset(fd, out, out_size, - strtab->sh_offset + symbol.st_name); - if (len1 <= 0 || memchr(out, '\0', out_size) == NULL) { - return false; - } - return true; // Obtained the symbol name. - } - } - i += num_symbols_in_buf; - } - return false; -} - -// Get the symbol name of "pc" from the file pointed by "fd". Process -// both regular and dynamic symbol tables if necessary. On success, -// write the symbol name to "out" and return true. Otherwise, return -// false. -static bool GetSymbolFromObjectFile(const int fd, uint64_t pc, - char *out, int out_size, - uint64_t map_start_address) { - // Read the ELF header. - ElfW(Ehdr) elf_header; - if (!ReadFromOffsetExact(fd, &elf_header, sizeof(elf_header), 0)) { - return false; - } - - uint64_t symbol_offset = 0; - if (elf_header.e_type == ET_DYN) { // DSO needs offset adjustment. - symbol_offset = map_start_address; - } - - ElfW(Shdr) symtab, strtab; - - // Consult a regular symbol table first. - if (!GetSectionHeaderByType(fd, elf_header.e_shnum, elf_header.e_shoff, - SHT_SYMTAB, &symtab)) { - return false; - } - if (!ReadFromOffsetExact(fd, &strtab, sizeof(strtab), elf_header.e_shoff + - symtab.sh_link * sizeof(symtab))) { - return false; - } - if (FindSymbol(pc, fd, out, out_size, symbol_offset, - &strtab, &symtab)) { - return true; // Found the symbol in a regular symbol table. - } - - // If the symbol is not found, then consult a dynamic symbol table. - if (!GetSectionHeaderByType(fd, elf_header.e_shnum, elf_header.e_shoff, - SHT_DYNSYM, &symtab)) { - return false; - } - if (!ReadFromOffsetExact(fd, &strtab, sizeof(strtab), elf_header.e_shoff + - symtab.sh_link * sizeof(symtab))) { - return false; - } - if (FindSymbol(pc, fd, out, out_size, symbol_offset, - &strtab, &symtab)) { - return true; // Found the symbol in a dynamic symbol table. - } - - return false; -} - -namespace { -// Thin wrapper around a file descriptor so that the file descriptor -// gets closed for sure. -struct FileDescriptor { - const int fd_; - explicit FileDescriptor(int fd) : fd_(fd) {} - ~FileDescriptor() { - if (fd_ >= 0) { - NO_INTR(close(fd_)); - } - } - int get() { return fd_; } - - private: - explicit FileDescriptor(const FileDescriptor&); - void operator=(const FileDescriptor&); -}; - -// Helper class for reading lines from file. -// -// Note: we don't use ProcMapsIterator since the object is big (it has -// a 5k array member) and uses async-unsafe functions such as sscanf() -// and snprintf(). -class LineReader { - public: - explicit LineReader(int fd, char *buf, int buf_len) : fd_(fd), - buf_(buf), buf_len_(buf_len), bol_(buf), eol_(buf), eod_(buf) { - } - - // Read '\n'-terminated line from file. On success, modify "bol" - // and "eol", then return true. Otherwise, return false. - // - // Note: if the last line doesn't end with '\n', the line will be - // dropped. It's an intentional behavior to make the code simple. - bool ReadLine(const char **bol, const char **eol) { - if (BufferIsEmpty()) { // First time. - const ssize_t num_bytes = ReadPersistent(fd_, buf_, buf_len_); - if (num_bytes <= 0) { // EOF or error. - return false; - } - eod_ = buf_ + num_bytes; - bol_ = buf_; - } else { - bol_ = eol_ + 1; // Advance to the next line in the buffer. - SAFE_ASSERT(bol_ <= eod_); // "bol_" can point to "eod_". - if (!HasCompleteLine()) { - const int incomplete_line_length = eod_ - bol_; - // Move the trailing incomplete line to the beginning. - memmove(buf_, bol_, incomplete_line_length); - // Read text from file and append it. - char * const append_pos = buf_ + incomplete_line_length; - const int capacity_left = buf_len_ - incomplete_line_length; - const ssize_t num_bytes = ReadPersistent(fd_, append_pos, - capacity_left); - if (num_bytes <= 0) { // EOF or error. - return false; - } - eod_ = append_pos + num_bytes; - bol_ = buf_; - } - } - eol_ = FindLineFeed(); - if (eol_ == NULL) { // '\n' not found. Malformed line. - return false; - } - *eol_ = '\0'; // Replace '\n' with '\0'. - - *bol = bol_; - *eol = eol_; - return true; - } - - // Beginning of line. - const char *bol() { - return bol_; - } - - // End of line. - const char *eol() { - return eol_; - } - - private: - explicit LineReader(const LineReader&); - void operator=(const LineReader&); - - char *FindLineFeed() { - return reinterpret_cast<char *>(memchr(bol_, '\n', eod_ - bol_)); - } - - bool BufferIsEmpty() { - return buf_ == eod_; - } - - bool HasCompleteLine() { - return !BufferIsEmpty() && FindLineFeed() != NULL; - } - - const int fd_; - char * const buf_; - const int buf_len_; - char *bol_; - char *eol_; - const char *eod_; // End of data in "buf_". -}; -} // namespace - -// Place the hex number read from "start" into "*hex". The pointer to -// the first non-hex character or "end" is returned. -static char *GetHex(const char *start, const char *end, uint64_t *hex) { - *hex = 0; - const char *p; - for (p = start; p < end; ++p) { - int ch = *p; - if ((ch >= '0' && ch <= '9') || - (ch >= 'A' && ch <= 'F') || (ch >= 'a' && ch <= 'f')) { - *hex = (*hex << 4) | (ch < 'A' ? ch - '0' : (ch & 0xF) + 9); - } else { // Encountered the first non-hex character. - break; - } - } - SAFE_ASSERT(p <= end); - return const_cast<char *>(p); -} - -// Search for the object file (from /proc/self/maps) that contains -// the specified pc. If found, open this file and return the file handle, -// and also set start_address to the start address of where this object -// file is mapped to in memory. Otherwise, return -1. -static ATTRIBUTE_NOINLINE int -OpenObjectFileContainingPcAndGetStartAddress(uint64_t pc, - uint64_t &start_address) { - int object_fd; - - // Open /proc/self/maps. - int maps_fd; - NO_INTR(maps_fd = open("/proc/self/maps", O_RDONLY)); - FileDescriptor wrapped_maps_fd(maps_fd); - if (wrapped_maps_fd.get() < 0) { - return -1; - } - - // Iterate over maps and look for the map containing the pc. Then - // look into the symbol tables inside. - char buf[1024]; // Big enough for line of sane /proc/self/maps - LineReader reader(wrapped_maps_fd.get(), buf, sizeof(buf)); - while (true) { - const char *cursor; - const char *eol; - if (!reader.ReadLine(&cursor, &eol)) { // EOF or malformed line. - return -1; - } - - // Start parsing line in /proc/self/maps. Here is an example: - // - // 08048000-0804c000 r-xp 00000000 08:01 2142121 /bin/cat - // - // We want start address (08048000), end address (0804c000), flags - // (r-xp) and file name (/bin/cat). - - // Read start address. - cursor = GetHex(cursor, eol, &start_address); - if (cursor == eol || *cursor != '-') { - return -1; // Malformed line. - } - ++cursor; // Skip '-'. - - // Read end address. - uint64_t end_address; - cursor = GetHex(cursor, eol, &end_address); - if (cursor == eol || *cursor != ' ') { - return -1; // Malformed line. - } - ++cursor; // Skip ' '. - - // Check start and end addresses. - if (!(start_address <= pc && pc < end_address)) { - continue; // We skip this map. PC isn't in this map. - } - - // Read flags. Skip flags until we encounter a space or eol. - const char * const flags_start = cursor; - while (cursor < eol && *cursor != ' ') { - ++cursor; - } - // We expect at least four letters for flags (ex. "r-xp"). - if (cursor == eol || cursor < flags_start + 4) { - return -1; // Malformed line. - } - - // Check flags. We are only interested in "r-x" maps. - if (memcmp(flags_start, "r-x", 3) != 0) { // Not a "r-x" map. - continue; // We skip this map. - } - ++cursor; // Skip ' '. - - // Skip to file name. "cursor" now points to file offset. We need to - // skip at least three spaces for file offset, dev, and inode. - int num_spaces = 0; - while (cursor < eol) { - if (*cursor == ' ') { - ++num_spaces; - } else if (num_spaces >= 3) { - // The first non-space character after skipping three spaces - // is the beginning of the file name. - break; - } - ++cursor; - } - if (cursor == eol) { - return -1; // Malformed line. - } - - // Finally, "cursor" now points to file name of our interest. - NO_INTR(object_fd = open(cursor, O_RDONLY)); - if (object_fd < 0) { - return -1; - } - return object_fd; - } -} - -// The implementation of our symbolization routine. If it -// successfully finds the symbol containing "pc" and obtains the -// symbol name, returns true and write the symbol name to "out". -// Otherwise, returns false. If Callback function is installed via -// InstallSymbolizeCallback(), the function is also called in this function, -// and "out" is used as its output. -// To keep stack consumption low, we would like this function to not -// get inlined. -static ATTRIBUTE_NOINLINE bool SymbolizeAndDemangle(void *pc, char *out, - int out_size) { - uint64_t pc0 = reinterpret_cast<uintptr_t>(pc); - uint64_t start_address = 0; - - int object_fd = OpenObjectFileContainingPcAndGetStartAddress(pc0, - start_address); - if (object_fd == -1) { - return false; - } - FileDescriptor wrapped_object_fd(object_fd); - int elf_type = FileGetElfType(wrapped_object_fd.get()); - if (elf_type == -1) { - return false; - } - if (g_symbolize_callback) { - // Run the call back if it's installed. - // Note: relocation (and much of the rest of this code) will be - // wrong for prelinked shared libraries and PIE executables. - uint64 relocation = (elf_type == ET_DYN) ? start_address : 0; - int num_bytes_written = g_symbolize_callback(wrapped_object_fd.get(), - pc, out, out_size, - relocation); - if (num_bytes_written > 0) { - out += num_bytes_written; - out_size -= num_bytes_written; - } - } - if (!GetSymbolFromObjectFile(wrapped_object_fd.get(), pc0, - out, out_size, start_address)) { - return false; - } - - // Symbolization succeeded. Now we try to demangle the symbol. - DemangleInplace(out, out_size); - return true; -} - -_END_GOOGLE_NAMESPACE_ - -#elif defined(OS_MACOSX) && defined(HAVE_DLADDR) - -#include <dlfcn.h> -#include <string.h> - -_START_GOOGLE_NAMESPACE_ - -static ATTRIBUTE_NOINLINE bool SymbolizeAndDemangle(void *pc, char *out, - int out_size) { - Dl_info info; - if (dladdr(pc, &info)) { - if (strlen(info.dli_sname) < out_size) { - strcpy(out, info.dli_sname); - // Symbolization succeeded. Now we try to demangle the symbol. - DemangleInplace(out, out_size); - return true; - } - } - return false; -} - -_END_GOOGLE_NAMESPACE_ - -#else -# error BUG: HAVE_SYMBOLIZE was wrongly set -#endif - -_START_GOOGLE_NAMESPACE_ - -bool Symbolize(void *pc, char *out, int out_size) { - SAFE_ASSERT(out_size >= 0); - return SymbolizeAndDemangle(pc, out, out_size); -} - -_END_GOOGLE_NAMESPACE_ - -#else /* HAVE_SYMBOLIZE */ - -#include <assert.h> - -#include "config.h" - -_START_GOOGLE_NAMESPACE_ - -// TODO: Support other environments. -bool Symbolize(void *pc, char *out, int out_size) { - assert(0); - return false; -} - -_END_GOOGLE_NAMESPACE_ - -#endif diff --git a/base/third_party/symbolize/symbolize.h b/base/third_party/symbolize/symbolize.h deleted file mode 100644 index c3e41be..0000000 --- a/base/third_party/symbolize/symbolize.h +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright (c) 2006, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: Satoru Takabayashi -// -// This library provides Symbolize() function that symbolizes program -// counters to their corresponding symbol names on linux platforms. -// This library has a minimal implementation of an ELF symbol table -// reader (i.e. it doesn't depend on libelf, etc.). -// -// The algorithm used in Symbolize() is as follows. -// -// 1. Go through a list of maps in /proc/self/maps and find the map -// containing the program counter. -// -// 2. Open the mapped file and find a regular symbol table inside. -// Iterate over symbols in the symbol table and look for the symbol -// containing the program counter. If such a symbol is found, -// obtain the symbol name, and demangle the symbol if possible. -// If the symbol isn't found in the regular symbol table (binary is -// stripped), try the same thing with a dynamic symbol table. -// -// Note that Symbolize() is originally implemented to be used in -// FailureSignalHandler() in base/google.cc. Hence it doesn't use -// malloc() and other unsafe operations. It should be both -// thread-safe and async-signal-safe. - -#ifndef BASE_SYMBOLIZE_H_ -#define BASE_SYMBOLIZE_H_ - -#include "utilities.h" -#include "config.h" -#include "glog/logging.h" - -#ifdef HAVE_SYMBOLIZE - -#if defined(__ELF__) // defined by gcc -#if defined(__OpenBSD__) -#include <sys/exec_elf.h> -#else -#include <elf.h> -#endif -#include <link.h> // For ElfW() macro. - -// For systems where SIZEOF_VOID_P is not defined, determine it -// based on __LP64__ (defined by gcc on 64-bit systems) -#if !defined(SIZEOF_VOID_P) -# if defined(__LP64__) -# define SIZEOF_VOID_P 8 -# else -# define SIZEOF_VOID_P 4 -# endif -#endif - -// If there is no ElfW macro, let's define it by ourself. -#ifndef ElfW -# if SIZEOF_VOID_P == 4 -# define ElfW(type) Elf32_##type -# elif SIZEOF_VOID_P == 8 -# define ElfW(type) Elf64_##type -# else -# error "Unknown sizeof(void *)" -# endif -#endif - -_START_GOOGLE_NAMESPACE_ - -// Gets the section header for the given name, if it exists. Returns true on -// success. Otherwise, returns false. -bool GetSectionHeaderByName(int fd, const char *name, size_t name_len, - ElfW(Shdr) *out); - -_END_GOOGLE_NAMESPACE_ - -#endif /* __ELF__ */ - -_START_GOOGLE_NAMESPACE_ - -// Installs a callback function, which will be called right before a symbol name -// is printed. The callback is intended to be used for showing a file name and a -// line number preceding a symbol name. -// "fd" is a file descriptor of the object file containing the program -// counter "pc". The callback function should write output to "out" -// and return the size of the output written. On error, the callback -// function should return -1. -typedef int (*SymbolizeCallback)(int fd, void *pc, char *out, size_t out_size, - uint64 relocation); -void InstallSymbolizeCallback(SymbolizeCallback callback); - -_END_GOOGLE_NAMESPACE_ - -#endif - -_START_GOOGLE_NAMESPACE_ - -// Symbolizes a program counter. On success, returns true and write the -// symbol name to "out". The symbol name is demangled if possible -// (supports symbols generated by GCC 3.x or newer). Otherwise, -// returns false. -bool Symbolize(void *pc, char *out, int out_size); - -_END_GOOGLE_NAMESPACE_ - -#endif // BASE_SYMBOLIZE_H_ diff --git a/base/third_party/symbolize/utilities.h b/base/third_party/symbolize/utilities.h deleted file mode 100644 index 0bed526..0000000 --- a/base/third_party/symbolize/utilities.h +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -typedef uint64_t uint64; -#define HAVE_SYMBOLIZE 1 -#define ATTRIBUTE_NOINLINE __attribute__ ((noinline)) diff --git a/base/third_party/xdg_mime/LICENSE b/base/third_party/xdg_mime/LICENSE deleted file mode 100644 index 876ec23..0000000 --- a/base/third_party/xdg_mime/LICENSE +++ /dev/null @@ -1,17 +0,0 @@ -# Permission is hereby granted, free of charge, to any person obtaining a -# copy of this software and associated documentation files (the "Software"), -# to deal in the Software without restriction, including without limitation -# the rights to use, copy, modify, merge, publish, distribute, sublicense, -# and/or sell copies of the Software, and to permit persons to whom the -# Software is furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included -# in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR -# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -# OTHER DEALINGS IN THE SOFTWARE. diff --git a/base/third_party/xdg_mime/README b/base/third_party/xdg_mime/README deleted file mode 100644 index e7f3f68..0000000 --- a/base/third_party/xdg_mime/README +++ /dev/null @@ -1,8 +0,0 @@ -This module is a simple module that parses the proposed MIME spec listed -at http://freedesktop.org/. It is currently targetted at version 0.12. -There are no formal releases planned for this module, and it is not -intended to be installed at this time. Rather, it is meant to be used -by other libraries or applications to add support for the MIME system. - -It is dual-licensed under the terms of the GNU Lesser General Public -License, and the Academic Free License, version 2.0. diff --git a/base/third_party/xdg_mime/README.chromium b/base/third_party/xdg_mime/README.chromium deleted file mode 100644 index 5319478..0000000 --- a/base/third_party/xdg_mime/README.chromium +++ /dev/null @@ -1,10 +0,0 @@ -Name: xdg-mime -URL: http://portland.freedesktop.org/wiki/ - -The code in this directory is synced from: -http://svn.gnome.org/svn/glib/trunk/gio/xdgmime/ -@ r7784 on 2009/05/11. -This version contains some bugfixes to the original code. - -In addition, we have the following patch(es): -- compile.patch: small tweaks to make the code compile. diff --git a/base/third_party/xdg_mime/compile.patch b/base/third_party/xdg_mime/compile.patch deleted file mode 100644 index 7b3a09e..0000000 --- a/base/third_party/xdg_mime/compile.patch +++ /dev/null @@ -1,27 +0,0 @@ ---- a/xdgmimecache.c -+++ b/xdgmimecache.c -@@ -40,6 +40,8 @@ - - #include <netinet/in.h> /* for ntohl/ntohs */ - -+#define HAVE_MMAP 1 -+ - #ifdef HAVE_MMAP - #include <sys/mman.h> - #else -@@ -1000,5 +1002,3 @@ - dump_glob_node (cache, offset + 20 * j, 0); - } - } -- -- ---- a/xdgmimeglob.c -+++ b/xdgmimeglob.c -@@ -375,7 +375,6 @@ - int i, n; - MimeWeight mimes[10]; - int n_mimes = 10; -- xdg_unichar_t *ucs4; - int len; - - /* First, check the literals */ diff --git a/base/third_party/xdg_mime/xdgmime.c b/base/third_party/xdg_mime/xdgmime.c deleted file mode 100644 index c9bcfba..0000000 --- a/base/third_party/xdg_mime/xdgmime.c +++ /dev/null @@ -1,926 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu" -*- */ -/* xdgmime.c: XDG Mime Spec mime resolver. Based on version 0.11 of the spec. - * - * More info can be found at http://www.freedesktop.org/standards/ - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "xdgmime.h" -#include "xdgmimeint.h" -#include "xdgmimeglob.h" -#include "xdgmimemagic.h" -#include "xdgmimealias.h" -#include "xdgmimeicon.h" -#include "xdgmimeparent.h" -#include "xdgmimecache.h" -#include <stdio.h> -#include <string.h> -#include <sys/stat.h> -#include <sys/types.h> -#include <sys/time.h> -#include <unistd.h> -#include <assert.h> - -typedef struct XdgDirTimeList XdgDirTimeList; -typedef struct XdgCallbackList XdgCallbackList; - -static int need_reread = TRUE; -static time_t last_stat_time = 0; - -static XdgGlobHash *global_hash = NULL; -static XdgMimeMagic *global_magic = NULL; -static XdgAliasList *alias_list = NULL; -static XdgParentList *parent_list = NULL; -static XdgDirTimeList *dir_time_list = NULL; -static XdgCallbackList *callback_list = NULL; -static XdgIconList *icon_list = NULL; -static XdgIconList *generic_icon_list = NULL; - -XdgMimeCache **_caches = NULL; -static int n_caches = 0; - -const char xdg_mime_type_unknown[] = "application/octet-stream"; - - -enum -{ - XDG_CHECKED_UNCHECKED, - XDG_CHECKED_VALID, - XDG_CHECKED_INVALID -}; - -struct XdgDirTimeList -{ - time_t mtime; - char *directory_name; - int checked; - XdgDirTimeList *next; -}; - -struct XdgCallbackList -{ - XdgCallbackList *next; - XdgCallbackList *prev; - int callback_id; - XdgMimeCallback callback; - void *data; - XdgMimeDestroy destroy; -}; - -/* Function called by xdg_run_command_on_dirs. If it returns TRUE, further - * directories aren't looked at */ -typedef int (*XdgDirectoryFunc) (const char *directory, - void *user_data); - -static void -xdg_dir_time_list_add (char *file_name, - time_t mtime) -{ - XdgDirTimeList *list; - - for (list = dir_time_list; list; list = list->next) - { - if (strcmp (list->directory_name, file_name) == 0) - { - free (file_name); - return; - } - } - - list = calloc (1, sizeof (XdgDirTimeList)); - list->checked = XDG_CHECKED_UNCHECKED; - list->directory_name = file_name; - list->mtime = mtime; - list->next = dir_time_list; - dir_time_list = list; -} - -static void -xdg_dir_time_list_free (XdgDirTimeList *list) -{ - XdgDirTimeList *next; - - while (list) - { - next = list->next; - free (list->directory_name); - free (list); - list = next; - } -} - -static int -xdg_mime_init_from_directory (const char *directory) -{ - char *file_name; - struct stat st; - - assert (directory != NULL); - - file_name = malloc (strlen (directory) + strlen ("/mime/mime.cache") + 1); - strcpy (file_name, directory); strcat (file_name, "/mime/mime.cache"); - if (stat (file_name, &st) == 0) - { - XdgMimeCache *cache = _xdg_mime_cache_new_from_file (file_name); - - if (cache != NULL) - { - xdg_dir_time_list_add (file_name, st.st_mtime); - - _caches = realloc (_caches, sizeof (XdgMimeCache *) * (n_caches + 2)); - _caches[n_caches] = cache; - _caches[n_caches + 1] = NULL; - n_caches++; - - return FALSE; - } - } - free (file_name); - - file_name = malloc (strlen (directory) + strlen ("/mime/globs2") + 1); - strcpy (file_name, directory); strcat (file_name, "/mime/globs2"); - if (stat (file_name, &st) == 0) - { - _xdg_mime_glob_read_from_file (global_hash, file_name); - xdg_dir_time_list_add (file_name, st.st_mtime); - } - else - { - free (file_name); - file_name = malloc (strlen (directory) + strlen ("/mime/globs") + 1); - strcpy (file_name, directory); strcat (file_name, "/mime/globs"); - if (stat (file_name, &st) == 0) - { - _xdg_mime_glob_read_from_file (global_hash, file_name); - xdg_dir_time_list_add (file_name, st.st_mtime); - } - else - { - free (file_name); - } - } - - file_name = malloc (strlen (directory) + strlen ("/mime/magic") + 1); - strcpy (file_name, directory); strcat (file_name, "/mime/magic"); - if (stat (file_name, &st) == 0) - { - _xdg_mime_magic_read_from_file (global_magic, file_name); - xdg_dir_time_list_add (file_name, st.st_mtime); - } - else - { - free (file_name); - } - - file_name = malloc (strlen (directory) + strlen ("/mime/aliases") + 1); - strcpy (file_name, directory); strcat (file_name, "/mime/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"); - _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"); - _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"); - _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 */ -static void -xdg_run_command_on_dirs (XdgDirectoryFunc func, - void *user_data) -{ - const char *xdg_data_home; - const char *xdg_data_dirs; - const char *ptr; - - xdg_data_home = getenv ("XDG_DATA_HOME"); - if (xdg_data_home) - { - if ((func) (xdg_data_home, user_data)) - return; - } - else - { - const char *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); - - if (stop_processing) - return; - } - } - - xdg_data_dirs = getenv ("XDG_DATA_DIRS"); - if (xdg_data_dirs == NULL) - xdg_data_dirs = "/usr/local/share/:/usr/share/"; - - ptr = xdg_data_dirs; - - while (*ptr != '\000') - { - const char *end_ptr; - char *dir; - int len; - int stop_processing; - - end_ptr = ptr; - while (*end_ptr != ':' && *end_ptr != '\000') - end_ptr ++; - - if (end_ptr == ptr) - { - ptr++; - continue; - } - - if (*end_ptr == ':') - len = end_ptr - ptr; - else - len = end_ptr - ptr + 1; - dir = malloc (len + 1); - strncpy (dir, ptr, len); - dir[len] = '\0'; - stop_processing = (func) (dir, user_data); - free (dir); - - if (stop_processing) - return; - - ptr = end_ptr; - } -} - -/* Checks file_path to make sure it has the same mtime as last time it was - * checked. If it has a different mtime, or if the file doesn't exist, it - * returns FALSE. - * - * FIXME: This doesn't protect against permission changes. - */ -static int -xdg_check_file (const char *file_path, - int *exists) -{ - struct stat st; - - /* If the file exists */ - if (stat (file_path, &st) == 0) - { - XdgDirTimeList *list; - - if (exists) - *exists = TRUE; - - for (list = dir_time_list; list; list = list->next) - { - if (! strcmp (list->directory_name, file_path)) - { - if (st.st_mtime == list->mtime) - list->checked = XDG_CHECKED_VALID; - else - list->checked = XDG_CHECKED_INVALID; - - return (list->checked != XDG_CHECKED_VALID); - } - } - return TRUE; - } - - if (exists) - *exists = FALSE; - - return FALSE; -} - -static int -xdg_check_dir (const char *directory, - int *invalid_dir_list) -{ - int invalid, exists; - char *file_name; - - 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"); - invalid = xdg_check_file (file_name, &exists); - free (file_name); - if (invalid) - { - *invalid_dir_list = TRUE; - return TRUE; - } - else if (exists) - { - return FALSE; - } - - /* Check the globs file */ - file_name = malloc (strlen (directory) + strlen ("/mime/globs") + 1); - strcpy (file_name, directory); strcat (file_name, "/mime/globs"); - invalid = xdg_check_file (file_name, NULL); - free (file_name); - if (invalid) - { - *invalid_dir_list = TRUE; - return TRUE; - } - - /* Check the magic file */ - file_name = malloc (strlen (directory) + strlen ("/mime/magic") + 1); - strcpy (file_name, directory); strcat (file_name, "/mime/magic"); - invalid = xdg_check_file (file_name, NULL); - free (file_name); - if (invalid) - { - *invalid_dir_list = TRUE; - return TRUE; - } - - return FALSE; /* Keep processing */ -} - -/* Walks through all the mime files stat()ing them to see if they've changed. - * Returns TRUE if they have. */ -static int -xdg_check_dirs (void) -{ - XdgDirTimeList *list; - int invalid_dir_list = FALSE; - - for (list = dir_time_list; list; list = list->next) - list->checked = XDG_CHECKED_UNCHECKED; - - xdg_run_command_on_dirs ((XdgDirectoryFunc) xdg_check_dir, - &invalid_dir_list); - - if (invalid_dir_list) - return TRUE; - - for (list = dir_time_list; list; list = list->next) - { - if (list->checked != XDG_CHECKED_VALID) - return TRUE; - } - - return FALSE; -} - -/* We want to avoid stat()ing on every single mime call, so we only look for - * newer files every 5 seconds. This will return TRUE if we need to reread the - * mime data from disk. - */ -static int -xdg_check_time_and_dirs (void) -{ - struct timeval tv; - time_t current_time; - int retval = FALSE; - - gettimeofday (&tv, NULL); - current_time = tv.tv_sec; - - if (current_time >= last_stat_time + 5) - { - retval = xdg_check_dirs (); - last_stat_time = current_time; - } - - return retval; -} - -/* Called in every public function. It reloads the hash function if need be. - */ -static void -xdg_mime_init (void) -{ - if (xdg_check_time_and_dirs ()) - { - xdg_mime_shutdown (); - } - - if (need_reread) - { - global_hash = _xdg_glob_hash_new (); - global_magic = _xdg_mime_magic_new (); - alias_list = _xdg_mime_alias_list_new (); - parent_list = _xdg_mime_parent_list_new (); - icon_list = _xdg_mime_icon_list_new (); - generic_icon_list = _xdg_mime_icon_list_new (); - - xdg_run_command_on_dirs ((XdgDirectoryFunc) xdg_mime_init_from_directory, - NULL); - - need_reread = FALSE; - } -} - -const char * -xdg_mime_get_mime_type_for_data (const void *data, - size_t len, - int *result_prio) -{ - const char *mime_type; - - xdg_mime_init (); - - if (_caches) - return _xdg_mime_cache_get_mime_type_for_data (data, len, result_prio); - - mime_type = _xdg_mime_magic_lookup_data (global_magic, data, len, result_prio, NULL, 0); - - if (mime_type) - return mime_type; - - return XDG_MIME_TYPE_UNKNOWN; -} - -const char * -xdg_mime_get_mime_type_for_file (const char *file_name, - struct stat *statbuf) -{ - const char *mime_type; - /* currently, only a few globs occur twice, and none - * more often, so 5 seems plenty. - */ - const char *mime_types[5]; - FILE *file; - unsigned char *data; - int max_extent; - int bytes_read; - struct stat buf; - const char *base_name; - int n; - - if (file_name == NULL) - return NULL; - if (! _xdg_utf8_validate (file_name)) - return NULL; - - xdg_mime_init (); - - if (_caches) - return _xdg_mime_cache_get_mime_type_for_file (file_name, statbuf); - - base_name = _xdg_get_base_name (file_name); - n = _xdg_glob_hash_lookup_file_name (global_hash, base_name, mime_types, 5); - - if (n == 1) - return mime_types[0]; - - if (!statbuf) - { - if (stat (file_name, &buf) != 0) - return XDG_MIME_TYPE_UNKNOWN; - - statbuf = &buf; - } - - if (!S_ISREG (statbuf->st_mode)) - return XDG_MIME_TYPE_UNKNOWN; - - /* FIXME: Need to make sure that max_extent isn't totally broken. This could - * be large and need getting from a stream instead of just reading it all - * in. */ - max_extent = _xdg_mime_magic_get_buffer_extents (global_magic); - data = malloc (max_extent); - if (data == NULL) - return XDG_MIME_TYPE_UNKNOWN; - - file = fopen (file_name, "r"); - if (file == NULL) - { - free (data); - return XDG_MIME_TYPE_UNKNOWN; - } - - bytes_read = fread (data, 1, max_extent, file); - if (ferror (file)) - { - free (data); - fclose (file); - return XDG_MIME_TYPE_UNKNOWN; - } - - mime_type = _xdg_mime_magic_lookup_data (global_magic, data, bytes_read, NULL, - mime_types, n); - - free (data); - fclose (file); - - if (mime_type) - return mime_type; - - return XDG_MIME_TYPE_UNKNOWN; -} - -const char * -xdg_mime_get_mime_type_from_file_name (const char *file_name) -{ - const char *mime_type; - - xdg_mime_init (); - - if (_caches) - return _xdg_mime_cache_get_mime_type_from_file_name (file_name); - - if (_xdg_glob_hash_lookup_file_name (global_hash, file_name, &mime_type, 1)) - return mime_type; - else - return XDG_MIME_TYPE_UNKNOWN; -} - -int -xdg_mime_get_mime_types_from_file_name (const char *file_name, - const char *mime_types[], - int n_mime_types) -{ - xdg_mime_init (); - - if (_caches) - return _xdg_mime_cache_get_mime_types_from_file_name (file_name, mime_types, n_mime_types); - - return _xdg_glob_hash_lookup_file_name (global_hash, file_name, mime_types, n_mime_types); -} - -int -xdg_mime_is_valid_mime_type (const char *mime_type) -{ - /* FIXME: We should make this a better test - */ - return _xdg_utf8_validate (mime_type); -} - -void -xdg_mime_shutdown (void) -{ - XdgCallbackList *list; - - /* FIXME: Need to make this (and the whole library) thread safe */ - if (dir_time_list) - { - xdg_dir_time_list_free (dir_time_list); - dir_time_list = NULL; - } - - if (global_hash) - { - _xdg_glob_hash_free (global_hash); - global_hash = NULL; - } - if (global_magic) - { - _xdg_mime_magic_free (global_magic); - global_magic = NULL; - } - - if (alias_list) - { - _xdg_mime_alias_list_free (alias_list); - alias_list = NULL; - } - - if (parent_list) - { - _xdg_mime_parent_list_free (parent_list); - parent_list = NULL; - } - - if (icon_list) - { - _xdg_mime_icon_list_free (icon_list); - icon_list = NULL; - } - - if (generic_icon_list) - { - _xdg_mime_icon_list_free (generic_icon_list); - generic_icon_list = NULL; - } - - if (_caches) - { - int i; - - for (i = 0; i < n_caches; i++) - _xdg_mime_cache_unref (_caches[i]); - free (_caches); - _caches = NULL; - n_caches = 0; - } - - for (list = callback_list; list; list = list->next) - (list->callback) (list->data); - - need_reread = TRUE; -} - -int -xdg_mime_get_max_buffer_extents (void) -{ - xdg_mime_init (); - - if (_caches) - return _xdg_mime_cache_get_max_buffer_extents (); - - return _xdg_mime_magic_get_buffer_extents (global_magic); -} - -const char * -_xdg_mime_unalias_mime_type (const char *mime_type) -{ - const char *lookup; - - if (_caches) - return _xdg_mime_cache_unalias_mime_type (mime_type); - - if ((lookup = _xdg_mime_alias_list_lookup (alias_list, mime_type)) != NULL) - return lookup; - - return mime_type; -} - -const char * -xdg_mime_unalias_mime_type (const char *mime_type) -{ - xdg_mime_init (); - - return _xdg_mime_unalias_mime_type (mime_type); -} - -int -_xdg_mime_mime_type_equal (const char *mime_a, - const char *mime_b) -{ - const char *unalias_a, *unalias_b; - - unalias_a = _xdg_mime_unalias_mime_type (mime_a); - unalias_b = _xdg_mime_unalias_mime_type (mime_b); - - if (strcmp (unalias_a, unalias_b) == 0) - return 1; - - return 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); -} - -int -xdg_mime_media_type_equal (const char *mime_a, - const char *mime_b) -{ - char *sep; - - sep = strchr (mime_a, '/'); - - if (sep && strncmp (mime_a, mime_b, sep - mime_a + 1) == 0) - return 1; - - return 0; -} - -#if 1 -static int -xdg_mime_is_super_type (const char *mime) -{ - int length; - const char *type; - - length = strlen (mime); - type = &(mime[length - 2]); - - if (strcmp (type, "/*") == 0) - return 1; - - return 0; -} -#endif - -int -_xdg_mime_mime_type_subclass (const char *mime, - const char *base) -{ - const char *umime, *ubase; - const char **parents; - - if (_caches) - return _xdg_mime_cache_mime_type_subclass (mime, base); - - umime = _xdg_mime_unalias_mime_type (mime); - ubase = _xdg_mime_unalias_mime_type (base); - - if (strcmp (umime, ubase) == 0) - return 1; - -#if 1 - /* Handle supertypes */ - if (xdg_mime_is_super_type (ubase) && - xdg_mime_media_type_equal (umime, ubase)) - return 1; -#endif - - /* Handle special cases text/plain and application/octet-stream */ - if (strcmp (ubase, "text/plain") == 0 && - strncmp (umime, "text/", 5) == 0) - return 1; - - if (strcmp (ubase, "application/octet-stream") == 0) - return 1; - - parents = _xdg_mime_parent_list_lookup (parent_list, umime); - for (; parents && *parents; parents++) - { - if (_xdg_mime_mime_type_subclass (*parents, ubase)) - return 1; - } - - return 0; -} - -int -xdg_mime_mime_type_subclass (const char *mime, - const char *base) -{ - xdg_mime_init (); - - return _xdg_mime_mime_type_subclass (mime, base); -} - -char ** -xdg_mime_list_mime_parents (const char *mime) -{ - const char **parents; - char **result; - int i, n; - - if (_caches) - return _xdg_mime_cache_list_mime_parents (mime); - - parents = xdg_mime_get_mime_parents (mime); - - if (!parents) - return NULL; - - for (i = 0; parents[i]; i++) ; - - n = (i + 1) * sizeof (char *); - result = (char **) malloc (n); - memcpy (result, parents, n); - - return result; -} - -const char ** -xdg_mime_get_mime_parents (const char *mime) -{ - const char *umime; - - xdg_mime_init (); - - umime = _xdg_mime_unalias_mime_type (mime); - - return _xdg_mime_parent_list_lookup (parent_list, umime); -} - -void -xdg_mime_dump (void) -{ - xdg_mime_init(); - - printf ("*** ALIASES ***\n\n"); - _xdg_mime_alias_list_dump (alias_list); - printf ("\n*** PARENTS ***\n\n"); - _xdg_mime_parent_list_dump (parent_list); - printf ("\n*** CACHE ***\n\n"); - _xdg_glob_hash_dump (global_hash); - printf ("\n*** GLOBS ***\n\n"); - _xdg_glob_hash_dump (global_hash); - printf ("\n*** GLOBS REVERSE TREE ***\n\n"); - _xdg_mime_cache_glob_dump (); -} - - -/* Registers a function to be called every time the mime database reloads its files - */ -int -xdg_mime_register_reload_callback (XdgMimeCallback callback, - void *data, - XdgMimeDestroy destroy) -{ - XdgCallbackList *list_el; - static int callback_id = 1; - - /* Make a new list element */ - list_el = calloc (1, sizeof (XdgCallbackList)); - list_el->callback_id = callback_id; - list_el->callback = callback; - list_el->data = data; - list_el->destroy = destroy; - list_el->next = callback_list; - if (list_el->next) - list_el->next->prev = list_el; - - callback_list = list_el; - callback_id ++; - - return callback_id - 1; -} - -void -xdg_mime_remove_callback (int callback_id) -{ - XdgCallbackList *list; - - for (list = callback_list; list; list = list->next) - { - if (list->callback_id == callback_id) - { - if (list->next) - list->next = list->prev; - - if (list->prev) - list->prev->next = list->next; - else - callback_list = list->next; - - /* invoke the destroy handler */ - (list->destroy) (list->data); - free (list); - return; - } - } -} - -const char * -xdg_mime_get_icon (const char *mime) -{ - xdg_mime_init (); - - if (_caches) - return _xdg_mime_cache_get_icon (mime); - - return _xdg_mime_icon_list_lookup (icon_list, mime); -} - -const char * -xdg_mime_get_generic_icon (const char *mime) -{ - xdg_mime_init (); - - if (_caches) - return _xdg_mime_cache_get_generic_icon (mime); - - return _xdg_mime_icon_list_lookup (generic_icon_list, mime); -} diff --git a/base/third_party/xdg_mime/xdgmime.h b/base/third_party/xdg_mime/xdgmime.h deleted file mode 100644 index d3031a3..0000000 --- a/base/third_party/xdg_mime/xdgmime.h +++ /dev/null @@ -1,127 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu" -*- */ -/* xdgmime.h: XDG Mime Spec mime resolver. Based on version 0.11 of the spec. - * - * More info can be found at http://www.freedesktop.org/standards/ - * - * 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. - */ - - -#ifndef __XDG_MIME_H__ -#define __XDG_MIME_H__ - -#include <stdlib.h> -#include <sys/stat.h> - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#ifdef XDG_PREFIX -#define XDG_ENTRY(func) _XDG_ENTRY2(XDG_PREFIX,func) -#define _XDG_ENTRY2(prefix,func) _XDG_ENTRY3(prefix,func) -#define _XDG_ENTRY3(prefix,func) prefix##_##func - -#define XDG_RESERVED_ENTRY(func) _XDG_RESERVED_ENTRY2(XDG_PREFIX,func) -#define _XDG_RESERVED_ENTRY2(prefix,func) _XDG_RESERVED_ENTRY3(prefix,func) -#define _XDG_RESERVED_ENTRY3(prefix,func) _##prefix##_##func -#endif - -typedef void (*XdgMimeCallback) (void *user_data); -typedef void (*XdgMimeDestroy) (void *user_data); - - -#ifdef XDG_PREFIX -#define xdg_mime_get_mime_type_for_data XDG_ENTRY(get_mime_type_for_data) -#define xdg_mime_get_mime_type_for_file XDG_ENTRY(get_mime_type_for_file) -#define xdg_mime_get_mime_type_from_file_name XDG_ENTRY(get_mime_type_from_file_name) -#define xdg_mime_get_mime_types_from_file_name XDG_ENTRY(get_mime_types_from_file_name) -#define xdg_mime_is_valid_mime_type XDG_ENTRY(is_valid_mime_type) -#define xdg_mime_mime_type_equal XDG_ENTRY(mime_type_equal) -#define xdg_mime_media_type_equal XDG_ENTRY(media_type_equal) -#define xdg_mime_mime_type_subclass XDG_ENTRY(mime_type_subclass) -#define xdg_mime_get_mime_parents XDG_ENTRY(get_mime_parents) -#define xdg_mime_list_mime_parents XDG_ENTRY(list_mime_parents) -#define xdg_mime_unalias_mime_type XDG_ENTRY(unalias_mime_type) -#define xdg_mime_get_max_buffer_extents XDG_ENTRY(get_max_buffer_extents) -#define xdg_mime_shutdown XDG_ENTRY(shutdown) -#define xdg_mime_dump XDG_ENTRY(dump) -#define xdg_mime_register_reload_callback XDG_ENTRY(register_reload_callback) -#define xdg_mime_remove_callback XDG_ENTRY(remove_callback) -#define xdg_mime_type_unknown XDG_ENTRY(type_unknown) -#define xdg_mime_get_icon XDG_ENTRY(get_icon) -#define xdg_mime_get_generic_icon XDG_ENTRY(get_generic_icon) - -#define _xdg_mime_mime_type_equal XDG_RESERVED_ENTRY(mime_type_equal) -#define _xdg_mime_mime_type_subclass XDG_RESERVED_ENTRY(mime_type_subclass) -#define _xdg_mime_unalias_mime_type XDG_RESERVED_ENTRY(unalias_mime_type) -#endif - -extern const char xdg_mime_type_unknown[]; -#define XDG_MIME_TYPE_UNKNOWN xdg_mime_type_unknown - -const char *xdg_mime_get_mime_type_for_data (const void *data, - size_t len, - int *result_prio); -const char *xdg_mime_get_mime_type_for_file (const char *file_name, - struct stat *statbuf); -const char *xdg_mime_get_mime_type_from_file_name (const char *file_name); -int xdg_mime_get_mime_types_from_file_name(const char *file_name, - const char *mime_types[], - int n_mime_types); -int xdg_mime_is_valid_mime_type (const char *mime_type); -int xdg_mime_mime_type_equal (const char *mime_a, - const char *mime_b); -int xdg_mime_media_type_equal (const char *mime_a, - const char *mime_b); -int xdg_mime_mime_type_subclass (const char *mime_a, - const char *mime_b); - /* xdg_mime_get_mime_parents() is deprecated since it does - * not work correctly with caches. Use xdg_mime_list_parents() - * instead, but notice that that function expects you to free - * the array it returns. - */ -const char **xdg_mime_get_mime_parents (const char *mime); -char ** xdg_mime_list_mime_parents (const char *mime); -const char *xdg_mime_unalias_mime_type (const char *mime); -const char *xdg_mime_get_icon (const char *mime); -const char *xdg_mime_get_generic_icon (const char *mime); -int xdg_mime_get_max_buffer_extents (void); -void xdg_mime_shutdown (void); -void xdg_mime_dump (void); -int xdg_mime_register_reload_callback (XdgMimeCallback callback, - void *data, - XdgMimeDestroy destroy); -void xdg_mime_remove_callback (int callback_id); - - /* 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); -int _xdg_mime_mime_type_subclass (const char *mime, - const char *base); -const char *_xdg_mime_unalias_mime_type (const char *mime); - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* __XDG_MIME_H__ */ diff --git a/base/third_party/xdg_mime/xdgmimealias.c b/base/third_party/xdg_mime/xdgmimealias.c deleted file mode 100644 index c33adfa..0000000 --- a/base/third_party/xdg_mime/xdgmimealias.c +++ /dev/null @@ -1,184 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu" -*- */ -/* xdgmimealias.c: Private file. Datastructure for storing the aliases. - * - * More info can be found at http://www.freedesktop.org/standards/ - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "xdgmimealias.h" -#include "xdgmimeint.h" -#include <stdlib.h> -#include <stdio.h> -#include <assert.h> -#include <string.h> -#include <fnmatch.h> - -#ifndef FALSE -#define FALSE (0) -#endif - -#ifndef TRUE -#define TRUE (!FALSE) -#endif - -typedef struct XdgAlias XdgAlias; - -struct XdgAlias -{ - char *alias; - char *mime_type; -}; - -struct XdgAliasList -{ - struct XdgAlias *aliases; - int n_aliases; -}; - -XdgAliasList * -_xdg_mime_alias_list_new (void) -{ - XdgAliasList *list; - - list = malloc (sizeof (XdgAliasList)); - - list->aliases = NULL; - list->n_aliases = 0; - - return list; -} - -void -_xdg_mime_alias_list_free (XdgAliasList *list) -{ - int i; - - if (list->aliases) - { - for (i = 0; i < list->n_aliases; i++) - { - free (list->aliases[i].alias); - free (list->aliases[i].mime_type); - } - free (list->aliases); - } - free (list); -} - -static int -alias_entry_cmp (const void *v1, const void *v2) -{ - return strcmp (((XdgAlias *)v1)->alias, ((XdgAlias *)v2)->alias); -} - -const char * -_xdg_mime_alias_list_lookup (XdgAliasList *list, - const char *alias) -{ - XdgAlias *entry; - XdgAlias key; - - if (list->n_aliases > 0) - { - key.alias = (char *)alias; - key.mime_type = NULL; - - entry = bsearch (&key, list->aliases, list->n_aliases, - sizeof (XdgAlias), alias_entry_cmp); - if (entry) - return entry->mime_type; - } - - return NULL; -} - -void -_xdg_mime_alias_read_from_file (XdgAliasList *list, - const char *file_name) -{ - FILE *file; - char line[255]; - int alloc; - - file = fopen (file_name, "r"); - - if (file == NULL) - return; - - /* FIXME: Not UTF-8 safe. Doesn't work if lines are greater than 255 chars. - * Blah */ - alloc = list->n_aliases + 16; - list->aliases = realloc (list->aliases, alloc * sizeof (XdgAlias)); - while (fgets (line, 255, file) != NULL) - { - char *sep; - if (line[0] == '#') - continue; - - sep = strchr (line, ' '); - if (sep == NULL) - continue; - *(sep++) = '\000'; - sep[strlen (sep) -1] = '\000'; - if (list->n_aliases == alloc) - { - alloc <<= 1; - list->aliases = realloc (list->aliases, - alloc * sizeof (XdgAlias)); - } - list->aliases[list->n_aliases].alias = strdup (line); - list->aliases[list->n_aliases].mime_type = strdup (sep); - list->n_aliases++; - } - list->aliases = realloc (list->aliases, - list->n_aliases * sizeof (XdgAlias)); - - fclose (file); - - if (list->n_aliases > 1) - qsort (list->aliases, list->n_aliases, - sizeof (XdgAlias), alias_entry_cmp); -} - - -void -_xdg_mime_alias_list_dump (XdgAliasList *list) -{ - int i; - - if (list->aliases) - { - for (i = 0; i < list->n_aliases; i++) - { - printf ("%s %s\n", - list->aliases[i].alias, - list->aliases[i].mime_type); - } - } -} - - diff --git a/base/third_party/xdg_mime/xdgmimealias.h b/base/third_party/xdg_mime/xdgmimealias.h deleted file mode 100644 index 3c28012..0000000 --- a/base/third_party/xdg_mime/xdgmimealias.h +++ /dev/null @@ -1,51 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu" -*- */ -/* xdgmimealias.h: Private file. Datastructure for storing the aliases. - * - * More info can be found at http://www.freedesktop.org/standards/ - * - * 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. - */ - -#ifndef __XDG_MIME_ALIAS_H__ -#define __XDG_MIME_ALIAS_H__ - -#include "xdgmime.h" - -typedef struct XdgAliasList XdgAliasList; - -#ifdef XDG_PREFIX -#define _xdg_mime_alias_read_from_file XDG_RESERVED_ENTRY(alias_read_from_file) -#define _xdg_mime_alias_list_new XDG_RESERVED_ENTRY(alias_list_new) -#define _xdg_mime_alias_list_free XDG_RESERVED_ENTRY(alias_list_free) -#define _xdg_mime_alias_list_lookup XDG_RESERVED_ENTRY(alias_list_lookup) -#define _xdg_mime_alias_list_dump XDG_RESERVED_ENTRY(alias_list_dump) -#endif - -void _xdg_mime_alias_read_from_file (XdgAliasList *list, - const char *file_name); -XdgAliasList *_xdg_mime_alias_list_new (void); -void _xdg_mime_alias_list_free (XdgAliasList *list); -const char *_xdg_mime_alias_list_lookup (XdgAliasList *list, - const char *alias); -void _xdg_mime_alias_list_dump (XdgAliasList *list); - -#endif /* __XDG_MIME_ALIAS_H__ */ diff --git a/base/third_party/xdg_mime/xdgmimecache.c b/base/third_party/xdg_mime/xdgmimecache.c deleted file mode 100644 index e26a8be..0000000 --- a/base/third_party/xdg_mime/xdgmimecache.c +++ /dev/null @@ -1,1004 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu" -*- */ -/* xdgmimealias.c: Private file. mmappable caches for mime data - * - * More info can be found at http://www.freedesktop.org/standards/ - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <ctype.h> - -#include <fcntl.h> -#include <unistd.h> -#include <fnmatch.h> -#include <assert.h> - -#include <netinet/in.h> /* for ntohl/ntohs */ - -#define HAVE_MMAP 1 - -#ifdef HAVE_MMAP -#include <sys/mman.h> -#else -#warning Building xdgmime without MMAP support. Binary "mime.info" cache files will not be used. -#endif - -#include <sys/stat.h> -#include <sys/types.h> - -#include "xdgmimecache.h" -#include "xdgmimeint.h" - -#ifndef MAX -#define MAX(a,b) ((a) > (b) ? (a) : (b)) -#endif - -#ifndef FALSE -#define FALSE (0) -#endif - -#ifndef TRUE -#define TRUE (!FALSE) -#endif - -#ifndef _O_BINARY -#define _O_BINARY 0 -#endif - -#ifndef MAP_FAILED -#define MAP_FAILED ((void *) -1) -#endif - -#define MAJOR_VERSION 1 -#define MINOR_VERSION 1 - -struct _XdgMimeCache -{ - int ref_count; - - size_t size; - char *buffer; -}; - -#define GET_UINT16(cache,offset) (ntohs(*(xdg_uint16_t*)((cache) + (offset)))) -#define GET_UINT32(cache,offset) (ntohl(*(xdg_uint32_t*)((cache) + (offset)))) - -XdgMimeCache * -_xdg_mime_cache_ref (XdgMimeCache *cache) -{ - cache->ref_count++; - return cache; -} - -void -_xdg_mime_cache_unref (XdgMimeCache *cache) -{ - cache->ref_count--; - - if (cache->ref_count == 0) - { -#ifdef HAVE_MMAP - munmap (cache->buffer, cache->size); -#endif - free (cache); - } -} - -XdgMimeCache * -_xdg_mime_cache_new_from_file (const char *file_name) -{ - XdgMimeCache *cache = NULL; - -#ifdef HAVE_MMAP - int fd = -1; - struct stat st; - char *buffer = NULL; - - /* Open the file and map it into memory */ - fd = open (file_name, O_RDONLY|_O_BINARY, 0); - - if (fd < 0) - return NULL; - - if (fstat (fd, &st) < 0 || st.st_size < 4) - goto done; - - buffer = (char *) mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0); - - if (buffer == MAP_FAILED) - goto done; - - /* Verify version */ - if (GET_UINT16 (buffer, 0) != MAJOR_VERSION || - GET_UINT16 (buffer, 2) != MINOR_VERSION) - { - munmap (buffer, st.st_size); - - goto done; - } - - cache = (XdgMimeCache *) malloc (sizeof (XdgMimeCache)); - cache->ref_count = 1; - cache->buffer = buffer; - cache->size = st.st_size; - - done: - if (fd != -1) - close (fd); - -#endif /* HAVE_MMAP */ - - return cache; -} - -static int -cache_magic_matchlet_compare_to_data (XdgMimeCache *cache, - xdg_uint32_t offset, - const void *data, - size_t len) -{ - xdg_uint32_t range_start = GET_UINT32 (cache->buffer, offset); - xdg_uint32_t range_length = GET_UINT32 (cache->buffer, offset + 4); - xdg_uint32_t data_length = GET_UINT32 (cache->buffer, offset + 12); - xdg_uint32_t data_offset = GET_UINT32 (cache->buffer, offset + 16); - xdg_uint32_t mask_offset = GET_UINT32 (cache->buffer, offset + 20); - - int i, j; - - for (i = range_start; i <= range_start + range_length; i++) - { - int valid_matchlet = TRUE; - - if (i + data_length > len) - return FALSE; - - if (mask_offset) - { - for (j = 0; j < data_length; j++) - { - if ((((unsigned char *)cache->buffer)[data_offset + j] & ((unsigned char *)cache->buffer)[mask_offset + j]) != - ((((unsigned char *) data)[j + i]) & ((unsigned char *)cache->buffer)[mask_offset + j])) - { - valid_matchlet = FALSE; - break; - } - } - } - else - { - for (j = 0; j < data_length; j++) - { - if (((unsigned char *)cache->buffer)[data_offset + j] != ((unsigned char *) data)[j + i]) - { - valid_matchlet = FALSE; - break; - } - } - } - - if (valid_matchlet) - return TRUE; - } - - return FALSE; -} - -static int -cache_magic_matchlet_compare (XdgMimeCache *cache, - xdg_uint32_t offset, - const void *data, - size_t len) -{ - xdg_uint32_t n_children = GET_UINT32 (cache->buffer, offset + 24); - xdg_uint32_t child_offset = GET_UINT32 (cache->buffer, offset + 28); - - int i; - - if (cache_magic_matchlet_compare_to_data (cache, offset, data, len)) - { - if (n_children == 0) - return TRUE; - - for (i = 0; i < n_children; i++) - { - if (cache_magic_matchlet_compare (cache, child_offset + 32 * i, - data, len)) - return TRUE; - } - } - - return FALSE; -} - -static const char * -cache_magic_compare_to_data (XdgMimeCache *cache, - xdg_uint32_t offset, - const void *data, - size_t len, - int *prio) -{ - xdg_uint32_t priority = GET_UINT32 (cache->buffer, offset); - xdg_uint32_t mimetype_offset = GET_UINT32 (cache->buffer, offset + 4); - xdg_uint32_t n_matchlets = GET_UINT32 (cache->buffer, offset + 8); - xdg_uint32_t matchlet_offset = GET_UINT32 (cache->buffer, offset + 12); - - int i; - - for (i = 0; i < n_matchlets; i++) - { - if (cache_magic_matchlet_compare (cache, matchlet_offset + i * 32, - data, len)) - { - *prio = priority; - - return cache->buffer + mimetype_offset; - } - } - - return NULL; -} - -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; -} - -static const char * -cache_alias_lookup (const char *alias) -{ - const char *ptr; - int i, min, max, mid, cmp; - - 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 offset; - - min = 0; - max = n_entries - 1; - while (max >= min) - { - mid = (min + max) / 2; - - offset = GET_UINT32 (cache->buffer, list_offset + 4 + 8 * mid); - ptr = cache->buffer + offset; - cmp = strcmp (ptr, alias); - - if (cmp < 0) - min = mid + 1; - else if (cmp > 0) - max = mid - 1; - else - { - offset = GET_UINT32 (cache->buffer, list_offset + 4 + 8 * mid + 4); - return cache->buffer + offset; - } - } - } - - return NULL; -} - -typedef struct { - const char *mime; - int weight; -} MimeWeight; - -static int -cache_glob_lookup_literal (const char *file_name, - const char *mime_types[], - int n_mime_types) -{ - const char *ptr; - int i, min, max, mid, cmp; - - 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 offset; - - min = 0; - max = n_entries - 1; - while (max >= min) - { - mid = (min + max) / 2; - - offset = GET_UINT32 (cache->buffer, list_offset + 4 + 12 * mid); - ptr = cache->buffer + offset; - cmp = strcmp (ptr, file_name); - - if (cmp < 0) - min = mid + 1; - else if (cmp > 0) - max = mid - 1; - else - { - offset = GET_UINT32 (cache->buffer, list_offset + 4 + 12 * mid + 4); - mime_types[0] = (const char *)(cache->buffer + offset); - - return 1; - } - } - } - - return 0; -} - -static int -cache_glob_lookup_fnmatch (const char *file_name, - MimeWeight mime_types[], - int n_mime_types) -{ - const char *mime_type; - const char *ptr; - - int i, j, n; - - n = 0; - for (i = 0; _caches[i]; i++) - { - 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); - - for (j = 0; j < n_entries && n < n_mime_types; j++) - { - xdg_uint32_t offset = GET_UINT32 (cache->buffer, list_offset + 4 + 12 * j); - xdg_uint32_t mimetype_offset = GET_UINT32 (cache->buffer, list_offset + 4 + 12 * j + 4); - int weight = GET_UINT32 (cache->buffer, list_offset + 4 + 12 * j + 8); - ptr = cache->buffer + offset; - mime_type = cache->buffer + mimetype_offset; - - /* FIXME: Not UTF-8 safe */ - if (fnmatch (ptr, file_name, 0) == 0) - { - mime_types[n].mime = mime_type; - mime_types[n].weight = weight; - n++; - } - } - - if (n > 0) - return n; - } - - return 0; -} - -static int -cache_glob_node_lookup_suffix (XdgMimeCache *cache, - xdg_uint32_t n_entries, - xdg_uint32_t offset, - const char *file_name, - int len, - int ignore_case, - MimeWeight mime_types[], - int n_mime_types) -{ - xdg_unichar_t character; - xdg_unichar_t match_char; - xdg_uint32_t mimetype_offset; - xdg_uint32_t n_children; - xdg_uint32_t child_offset; - int weight; - - int min, max, mid, n, i; - - character = file_name[len - 1]; - if (ignore_case) - character = tolower (character); - - assert (character != 0); - - min = 0; - max = n_entries - 1; - while (max >= min) - { - mid = (min + max) / 2; - match_char = GET_UINT32 (cache->buffer, offset + 12 * mid); - if (match_char < character) - min = mid + 1; - else if (match_char > character) - max = mid - 1; - else - { - len--; - n = 0; - n_children = GET_UINT32 (cache->buffer, offset + 12 * mid + 4); - child_offset = GET_UINT32 (cache->buffer, offset + 12 * mid + 8); - - if (len > 0) - { - n = cache_glob_node_lookup_suffix (cache, - n_children, child_offset, - file_name, len, - ignore_case, - mime_types, - n_mime_types); - } - if (n == 0) - { - i = 0; - while (n < n_mime_types && i < n_children) - { - match_char = GET_UINT32 (cache->buffer, child_offset + 12 * i); - if (match_char != 0) - break; - - mimetype_offset = GET_UINT32 (cache->buffer, child_offset + 12 * i + 4); - weight = GET_UINT32 (cache->buffer, child_offset + 12 * i + 8); - - mime_types[n].mime = cache->buffer + mimetype_offset; - mime_types[n].weight = weight; - n++; - i++; - } - } - return n; - } - } - return 0; -} - -static int -cache_glob_lookup_suffix (const char *file_name, - int len, - int ignore_case, - MimeWeight mime_types[], - int n_mime_types) -{ - int i, n; - - for (i = 0; _caches[i]; i++) - { - 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); - - n = cache_glob_node_lookup_suffix (cache, - n_entries, offset, - file_name, len, - ignore_case, - mime_types, - n_mime_types); - if (n > 0) - return n; - } - - return 0; -} - -static int compare_mime_weight (const void *a, const void *b) -{ - const MimeWeight *aa = (const MimeWeight *)a; - const MimeWeight *bb = (const MimeWeight *)b; - - return aa->weight - bb->weight; -} - -static int -cache_glob_lookup_file_name (const char *file_name, - const char *mime_types[], - int n_mime_types) -{ - int n; - MimeWeight mimes[10]; - int n_mimes = 10; - int i; - int len; - - assert (file_name != NULL && n_mime_types > 0); - - /* First, check the literals */ - n = cache_glob_lookup_literal (file_name, mime_types, n_mime_types); - if (n > 0) - return n; - - len = strlen (file_name); - n = cache_glob_lookup_suffix (file_name, len, FALSE, mimes, n_mimes); - - if (n == 0) - n = cache_glob_lookup_suffix (file_name, len, TRUE, mimes, n_mimes); - - /* Last, try fnmatch */ - if (n == 0) - n = cache_glob_lookup_fnmatch (file_name, mimes, n_mimes); - - qsort (mimes, n, sizeof (MimeWeight), compare_mime_weight); - - if (n_mime_types < n) - n = n_mime_types; - - for (i = 0; i < n; i++) - mime_types[i] = mimes[i].mime; - - return n; -} - -int -_xdg_mime_cache_get_max_buffer_extents (void) -{ - xdg_uint32_t offset; - xdg_uint32_t max_extent; - int i; - - max_extent = 0; - for (i = 0; _caches[i]; i++) - { - XdgMimeCache *cache = _caches[i]; - - offset = GET_UINT32 (cache->buffer, 24); - max_extent = MAX (max_extent, GET_UINT32 (cache->buffer, offset + 4)); - } - - return max_extent; -} - -static const char * -cache_get_mime_type_for_data (const void *data, - size_t len, - int *result_prio, - const char *mime_types[], - int n_mime_types) -{ - const char *mime_type; - int i, n, priority; - - priority = 0; - mime_type = NULL; - for (i = 0; _caches[i]; i++) - { - XdgMimeCache *cache = _caches[i]; - - int prio; - const char *match; - - match = cache_magic_lookup_data (cache, data, len, &prio, - mime_types, n_mime_types); - if (prio > priority) - { - priority = prio; - mime_type = match; - } - } - - if (result_prio) - *result_prio = priority; - - if (priority > 0) - return mime_type; - - for (n = 0; n < n_mime_types; n++) - { - - if (mime_types[n]) - return mime_types[n]; - } - - return XDG_MIME_TYPE_UNKNOWN; -} - -const char * -_xdg_mime_cache_get_mime_type_for_data (const void *data, - size_t len, - int *result_prio) -{ - return cache_get_mime_type_for_data (data, len, result_prio, NULL, 0); -} - -const char * -_xdg_mime_cache_get_mime_type_for_file (const char *file_name, - struct stat *statbuf) -{ - const char *mime_type; - const char *mime_types[10]; - FILE *file; - unsigned char *data; - int max_extent; - int bytes_read; - struct stat buf; - const char *base_name; - int n; - - if (file_name == NULL) - return NULL; - - if (! _xdg_utf8_validate (file_name)) - return NULL; - - base_name = _xdg_get_base_name (file_name); - n = cache_glob_lookup_file_name (base_name, mime_types, 10); - - if (n == 1) - return mime_types[0]; - - if (!statbuf) - { - if (stat (file_name, &buf) != 0) - return XDG_MIME_TYPE_UNKNOWN; - - statbuf = &buf; - } - - if (!S_ISREG (statbuf->st_mode)) - return XDG_MIME_TYPE_UNKNOWN; - - /* FIXME: Need to make sure that max_extent isn't totally broken. This could - * be large and need getting from a stream instead of just reading it all - * in. */ - max_extent = _xdg_mime_cache_get_max_buffer_extents (); - data = malloc (max_extent); - if (data == NULL) - return XDG_MIME_TYPE_UNKNOWN; - - file = fopen (file_name, "r"); - if (file == NULL) - { - free (data); - return XDG_MIME_TYPE_UNKNOWN; - } - - bytes_read = fread (data, 1, max_extent, file); - if (ferror (file)) - { - free (data); - fclose (file); - return XDG_MIME_TYPE_UNKNOWN; - } - - mime_type = cache_get_mime_type_for_data (data, bytes_read, NULL, - mime_types, n); - - free (data); - fclose (file); - - return mime_type; -} - -const char * -_xdg_mime_cache_get_mime_type_from_file_name (const char *file_name) -{ - const char *mime_type; - - if (cache_glob_lookup_file_name (file_name, &mime_type, 1)) - return mime_type; - else - return XDG_MIME_TYPE_UNKNOWN; -} - -int -_xdg_mime_cache_get_mime_types_from_file_name (const char *file_name, - const char *mime_types[], - int n_mime_types) -{ - return cache_glob_lookup_file_name (file_name, mime_types, n_mime_types); -} - -#if 1 -static int -is_super_type (const char *mime) -{ - int length; - const char *type; - - length = strlen (mime); - type = &(mime[length - 2]); - - if (strcmp (type, "/*") == 0) - return 1; - - return 0; -} -#endif - -int -_xdg_mime_cache_mime_type_subclass (const char *mime, - const char *base) -{ - const char *umime, *ubase; - - int i, j, min, max, med, cmp; - - umime = _xdg_mime_cache_unalias_mime_type (mime); - ubase = _xdg_mime_cache_unalias_mime_type (base); - - if (strcmp (umime, ubase) == 0) - return 1; - - /* We really want to handle text/ * in GtkFileFilter, so we just - * turn on the supertype matching - */ -#if 1 - /* Handle supertypes */ - if (is_super_type (ubase) && - xdg_mime_media_type_equal (umime, ubase)) - return 1; -#endif - - /* Handle special cases text/plain and application/octet-stream */ - if (strcmp (ubase, "text/plain") == 0 && - strncmp (umime, "text/", 5) == 0) - return 1; - - if (strcmp (ubase, "application/octet-stream") == 0) - return 1; - - 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 offset, n_parents, parent_offset; - - min = 0; - max = n_entries - 1; - while (max >= min) - { - med = (min + max)/2; - - offset = GET_UINT32 (cache->buffer, list_offset + 4 + 8 * med); - cmp = strcmp (cache->buffer + offset, umime); - if (cmp < 0) - min = med + 1; - else if (cmp > 0) - max = med - 1; - else - { - offset = GET_UINT32 (cache->buffer, list_offset + 4 + 8 * med + 4); - n_parents = GET_UINT32 (cache->buffer, offset); - - 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)) - return 1; - } - - break; - } - } - } - - return 0; -} - -const char * -_xdg_mime_cache_unalias_mime_type (const char *mime) -{ - const char *lookup; - - lookup = cache_alias_lookup (mime); - - if (lookup) - return lookup; - - return mime; -} - -char ** -_xdg_mime_cache_list_mime_parents (const char *mime) -{ - int i, j, k, l, p; - char *all_parents[128]; /* we'll stop at 128 */ - char **result; - - mime = xdg_mime_unalias_mime_type (mime); - - p = 0; - 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); - - for (j = 0; j < n_entries; j++) - { - xdg_uint32_t mimetype_offset = GET_UINT32 (cache->buffer, list_offset + 4 + 8 * j); - xdg_uint32_t parents_offset = GET_UINT32 (cache->buffer, list_offset + 4 + 8 * j + 4); - - if (strcmp (cache->buffer + mimetype_offset, mime) == 0) - { - xdg_uint32_t parent_mime_offset; - xdg_uint32_t n_parents = GET_UINT32 (cache->buffer, parents_offset); - - for (k = 0; k < n_parents && p < 127; k++) - { - parent_mime_offset = GET_UINT32 (cache->buffer, parents_offset + 4 + 4 * k); - - /* Don't add same parent multiple times. - * This can happen for instance if the same type is listed in multiple directories - */ - for (l = 0; l < p; l++) - { - if (strcmp (all_parents[l], cache->buffer + parent_mime_offset) == 0) - break; - } - - if (l == p) - all_parents[p++] = cache->buffer + parent_mime_offset; - } - - break; - } - } - } - all_parents[p++] = NULL; - - result = (char **) malloc (p * sizeof (char *)); - memcpy (result, all_parents, p * sizeof (char *)); - - return result; -} - -static const char * -cache_lookup_icon (const char *mime, int header) -{ - const char *ptr; - int i, min, max, mid, cmp; - - 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 offset; - - min = 0; - max = n_entries - 1; - while (max >= min) - { - mid = (min + max) / 2; - - offset = GET_UINT32 (cache->buffer, list_offset + 4 + 8 * mid); - ptr = cache->buffer + offset; - cmp = strcmp (ptr, mime); - - if (cmp < 0) - min = mid + 1; - else if (cmp > 0) - max = mid - 1; - else - { - offset = GET_UINT32 (cache->buffer, list_offset + 4 + 8 * mid + 4); - return cache->buffer + offset; - } - } - } - - return NULL; -} - -const char * -_xdg_mime_cache_get_generic_icon (const char *mime) -{ - return cache_lookup_icon (mime, 36); -} - -const char * -_xdg_mime_cache_get_icon (const char *mime) -{ - return cache_lookup_icon (mime, 32); -} - -static void -dump_glob_node (XdgMimeCache *cache, - xdg_uint32_t offset, - int depth) -{ - xdg_unichar_t character; - xdg_uint32_t mime_offset; - xdg_uint32_t n_children; - xdg_uint32_t child_offset; - int i; - - character = GET_UINT32 (cache->buffer, offset); - mime_offset = GET_UINT32 (cache->buffer, offset + 4); - n_children = GET_UINT32 (cache->buffer, offset + 8); - child_offset = GET_UINT32 (cache->buffer, offset + 12); - for (i = 0; i < depth; i++) - printf (" "); - printf ("%c", character); - if (mime_offset) - printf (" - %s", cache->buffer + mime_offset); - printf ("\n"); - if (child_offset) - { - for (i = 0; i < n_children; i++) - dump_glob_node (cache, child_offset + 20 * i, depth + 1); - } -} - -void -_xdg_mime_cache_glob_dump (void) -{ - int i, j; - for (i = 0; _caches[i]; i++) - { - XdgMimeCache *cache = _caches[i]; - xdg_uint32_t list_offset; - xdg_uint32_t n_entries; - xdg_uint32_t offset; - list_offset = GET_UINT32 (cache->buffer, 16); - n_entries = GET_UINT32 (cache->buffer, list_offset); - offset = GET_UINT32 (cache->buffer, list_offset + 4); - for (j = 0; j < n_entries; j++) - dump_glob_node (cache, offset + 20 * j, 0); - } -} diff --git a/base/third_party/xdg_mime/xdgmimecache.h b/base/third_party/xdg_mime/xdgmimecache.h deleted file mode 100644 index 27f42d0..0000000 --- a/base/third_party/xdg_mime/xdgmimecache.h +++ /dev/null @@ -1,81 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu" -*- */ -/* xdgmimecache.h: Private file. Datastructure for mmapped caches. - * - * More info can be found at http://www.freedesktop.org/standards/ - * - * 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. - */ - -#ifndef __XDG_MIME_CACHE_H__ -#define __XDG_MIME_CACHE_H__ - -#include "xdgmime.h" - -typedef struct _XdgMimeCache XdgMimeCache; - -#ifdef XDG_PREFIX -#define _xdg_mime_cache_new_from_file XDG_RESERVED_ENTRY(cache_new_from_file) -#define _xdg_mime_cache_ref XDG_RESERVED_ENTRY(cache_ref) -#define _xdg_mime_cache_unref XDG_RESERVED_ENTRY(cache_unref) -#define _xdg_mime_cache_get_max_buffer_extents XDG_RESERVED_ENTRY(cache_get_max_buffer_extents) -#define _xdg_mime_cache_get_mime_type_for_data XDG_RESERVED_ENTRY(cache_get_mime_type_for_data) -#define _xdg_mime_cache_get_mime_type_for_file XDG_RESERVED_ENTRY(cache_get_mime_type_for_file) -#define _xdg_mime_cache_get_mime_type_from_file_name XDG_RESERVED_ENTRY(cache_get_mime_type_from_file_name) -#define _xdg_mime_cache_get_mime_types_from_file_name XDG_RESERVED_ENTRY(cache_get_mime_types_from_file_name) -#define _xdg_mime_cache_list_mime_parents XDG_RESERVED_ENTRY(cache_list_mime_parents) -#define _xdg_mime_cache_mime_type_subclass XDG_RESERVED_ENTRY(cache_mime_type_subclass) -#define _xdg_mime_cache_unalias_mime_type XDG_RESERVED_ENTRY(cache_unalias_mime_type) -#define _xdg_mime_cache_get_icon XDG_RESERVED_ENTRY(cache_get_icon) -#define _xdg_mime_cache_get_generic_icon XDG_RESERVED_ENTRY(cache_get_generic_icon) -#define _xdg_mime_cache_glob_dump XDG_RESERVED_ENTRY(cache_glob_dump) -#endif - -extern XdgMimeCache **_caches; - -XdgMimeCache *_xdg_mime_cache_new_from_file (const char *file_name); -XdgMimeCache *_xdg_mime_cache_ref (XdgMimeCache *cache); -void _xdg_mime_cache_unref (XdgMimeCache *cache); - - -const char *_xdg_mime_cache_get_mime_type_for_data (const void *data, - size_t len, - int *result_prio); -const char *_xdg_mime_cache_get_mime_type_for_file (const char *file_name, - struct stat *statbuf); -int _xdg_mime_cache_get_mime_types_from_file_name (const char *file_name, - const char *mime_types[], - int n_mime_types); -const char *_xdg_mime_cache_get_mime_type_from_file_name (const char *file_name); -int _xdg_mime_cache_is_valid_mime_type (const char *mime_type); -int _xdg_mime_cache_mime_type_equal (const char *mime_a, - const char *mime_b); -int _xdg_mime_cache_media_type_equal (const char *mime_a, - const char *mime_b); -int _xdg_mime_cache_mime_type_subclass (const char *mime_a, - const char *mime_b); -char **_xdg_mime_cache_list_mime_parents (const char *mime); -const char *_xdg_mime_cache_unalias_mime_type (const char *mime); -int _xdg_mime_cache_get_max_buffer_extents (void); -const char *_xdg_mime_cache_get_icon (const char *mime); -const char *_xdg_mime_cache_get_generic_icon (const char *mime); -void _xdg_mime_cache_glob_dump (void); - -#endif /* __XDG_MIME_CACHE_H__ */ diff --git a/base/third_party/xdg_mime/xdgmimeglob.c b/base/third_party/xdg_mime/xdgmimeglob.c deleted file mode 100644 index d7c79b1..0000000 --- a/base/third_party/xdg_mime/xdgmimeglob.c +++ /dev/null @@ -1,602 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu" -*- */ -/* xdgmimeglob.c: Private file. Datastructure for storing the globs. - * - * More info can be found at http://www.freedesktop.org/standards/ - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "xdgmimeglob.h" -#include "xdgmimeint.h" -#include <stdlib.h> -#include <stdio.h> -#include <assert.h> -#include <string.h> -#include <fnmatch.h> -#include <ctype.h> - -#ifndef FALSE -#define FALSE (0) -#endif - -#ifndef TRUE -#define TRUE (!FALSE) -#endif - -typedef struct XdgGlobHashNode XdgGlobHashNode; -typedef struct XdgGlobList XdgGlobList; - -struct XdgGlobHashNode -{ - xdg_unichar_t character; - const char *mime_type; - int weight; - XdgGlobHashNode *next; - XdgGlobHashNode *child; -}; -struct XdgGlobList -{ - const char *data; - const char *mime_type; - int weight; - XdgGlobList *next; -}; - -struct XdgGlobHash -{ - XdgGlobList *literal_list; - XdgGlobHashNode *simple_node; - XdgGlobList *full_list; -}; - - -/* XdgGlobList - */ -static XdgGlobList * -_xdg_glob_list_new (void) -{ - XdgGlobList *new_element; - - new_element = calloc (1, sizeof (XdgGlobList)); - - return new_element; -} - -/* Frees glob_list and all of it's children */ -static void -_xdg_glob_list_free (XdgGlobList *glob_list) -{ - XdgGlobList *ptr, *next; - - ptr = glob_list; - - while (ptr != NULL) - { - next = ptr->next; - - if (ptr->data) - free ((void *) ptr->data); - if (ptr->mime_type) - free ((void *) ptr->mime_type); - free (ptr); - - ptr = next; - } -} - -static XdgGlobList * -_xdg_glob_list_append (XdgGlobList *glob_list, - void *data, - const char *mime_type, - int weight) -{ - XdgGlobList *new_element; - XdgGlobList *tmp_element; - - new_element = _xdg_glob_list_new (); - new_element->data = data; - new_element->mime_type = mime_type; - new_element->weight = weight; - if (glob_list == NULL) - return new_element; - - tmp_element = glob_list; - while (tmp_element->next != NULL) - tmp_element = tmp_element->next; - - tmp_element->next = new_element; - - return glob_list; -} - -/* XdgGlobHashNode - */ - -static XdgGlobHashNode * -_xdg_glob_hash_node_new (void) -{ - XdgGlobHashNode *glob_hash_node; - - glob_hash_node = calloc (1, sizeof (XdgGlobHashNode)); - - return glob_hash_node; -} - -static void -_xdg_glob_hash_node_dump (XdgGlobHashNode *glob_hash_node, - int depth) -{ - int i; - for (i = 0; i < depth; i++) - printf (" "); - - printf ("%c", (char)glob_hash_node->character); - if (glob_hash_node->mime_type) - printf (" - %s %d\n", glob_hash_node->mime_type, glob_hash_node->weight); - else - printf ("\n"); - if (glob_hash_node->child) - _xdg_glob_hash_node_dump (glob_hash_node->child, depth + 1); - if (glob_hash_node->next) - _xdg_glob_hash_node_dump (glob_hash_node->next, depth); -} - -static XdgGlobHashNode * -_xdg_glob_hash_insert_ucs4 (XdgGlobHashNode *glob_hash_node, - xdg_unichar_t *text, - const char *mime_type, - int weight) -{ - XdgGlobHashNode *node; - xdg_unichar_t character; - - character = text[0]; - - if ((glob_hash_node == NULL) || - (character < glob_hash_node->character)) - { - node = _xdg_glob_hash_node_new (); - node->character = character; - node->next = glob_hash_node; - glob_hash_node = node; - } - else if (character == glob_hash_node->character) - { - node = glob_hash_node; - } - else - { - XdgGlobHashNode *prev_node; - int found_node = FALSE; - - /* Look for the first character of text in glob_hash_node, and insert it if we - * have to.*/ - prev_node = glob_hash_node; - node = prev_node->next; - - while (node != NULL) - { - if (character < node->character) - { - node = _xdg_glob_hash_node_new (); - node->character = character; - node->next = prev_node->next; - prev_node->next = node; - - found_node = TRUE; - break; - } - else if (character == node->character) - { - found_node = TRUE; - break; - } - prev_node = node; - node = node->next; - } - - if (! found_node) - { - node = _xdg_glob_hash_node_new (); - node->character = character; - node->next = prev_node->next; - prev_node->next = node; - } - } - - text++; - if (*text == 0) - { - if (node->mime_type) - { - if (strcmp (node->mime_type, mime_type)) - { - XdgGlobHashNode *child; - int found_node = FALSE; - - child = node->child; - while (child && child->character == 0) - { - if (strcmp (child->mime_type, mime_type) == 0) - { - found_node = TRUE; - break; - } - child = child->next; - } - - if (!found_node) - { - child = _xdg_glob_hash_node_new (); - child->character = 0; - child->mime_type = strdup (mime_type); - child->weight = weight; - child->child = NULL; - child->next = node->child; - node->child = child; - } - } - } - else - { - node->mime_type = strdup (mime_type); - node->weight = weight; - } - } - else - { - node->child = _xdg_glob_hash_insert_ucs4 (node->child, text, mime_type, weight); - } - return glob_hash_node; -} - -/* glob must be valid UTF-8 */ -static XdgGlobHashNode * -_xdg_glob_hash_insert_text (XdgGlobHashNode *glob_hash_node, - const char *text, - const char *mime_type, - int weight) -{ - XdgGlobHashNode *node; - xdg_unichar_t *unitext; - int len; - - unitext = _xdg_convert_to_ucs4 (text, &len); - _xdg_reverse_ucs4 (unitext, len); - node = _xdg_glob_hash_insert_ucs4 (glob_hash_node, unitext, mime_type, weight); - free (unitext); - return node; -} - -typedef struct { - const char *mime; - int weight; -} MimeWeight; - -static int -_xdg_glob_hash_node_lookup_file_name (XdgGlobHashNode *glob_hash_node, - const char *file_name, - int len, - int ignore_case, - MimeWeight mime_types[], - int n_mime_types) -{ - int n; - XdgGlobHashNode *node; - xdg_unichar_t character; - - if (glob_hash_node == NULL) - return 0; - - character = file_name[len - 1]; - if (ignore_case) - character = tolower(character); - - for (node = glob_hash_node; node && character >= node->character; node = node->next) - { - if (character == node->character) - { - len--; - n = 0; - if (len > 0) - { - n = _xdg_glob_hash_node_lookup_file_name (node->child, - file_name, - len, - ignore_case, - mime_types, - n_mime_types); - } - if (n == 0) - { - if (node->mime_type) - { - mime_types[n].mime = node->mime_type; - mime_types[n].weight = node->weight; - n++; - } - node = node->child; - while (n < n_mime_types && node && node->character == 0) - { - if (node->mime_type) - { - mime_types[n].mime = node->mime_type; - mime_types[n].weight = node->weight; - n++; - } - node = node->next; - } - } - return n; - } - } - - return 0; -} - -static int compare_mime_weight (const void *a, const void *b) -{ - const MimeWeight *aa = (const MimeWeight *)a; - const MimeWeight *bb = (const MimeWeight *)b; - - return aa->weight - bb->weight; -} - -int -_xdg_glob_hash_lookup_file_name (XdgGlobHash *glob_hash, - const char *file_name, - const char *mime_types[], - int n_mime_types) -{ - XdgGlobList *list; - int i, n; - MimeWeight mimes[10]; - int n_mimes = 10; - int len; - - /* First, check the literals */ - - assert (file_name != NULL && n_mime_types > 0); - - n = 0; - - for (list = glob_hash->literal_list; list; list = list->next) - { - if (strcmp ((const char *)list->data, file_name) == 0) - { - mime_types[0] = list->mime_type; - return 1; - } - } - - len = strlen (file_name); - n = _xdg_glob_hash_node_lookup_file_name (glob_hash->simple_node, file_name, len, FALSE, - mimes, n_mimes); - if (n == 0) - n = _xdg_glob_hash_node_lookup_file_name (glob_hash->simple_node, file_name, len, TRUE, - mimes, n_mimes); - - if (n == 0) - { - for (list = glob_hash->full_list; list && n < n_mime_types; list = list->next) - { - if (fnmatch ((const char *)list->data, file_name, 0) == 0) - { - mimes[n].mime = list->mime_type; - mimes[n].weight = list->weight; - n++; - } - } - } - - qsort (mimes, n, sizeof (MimeWeight), compare_mime_weight); - - if (n_mime_types < n) - n = n_mime_types; - - for (i = 0; i < n; i++) - mime_types[i] = mimes[i].mime; - - return n; -} - - - -/* XdgGlobHash - */ - -XdgGlobHash * -_xdg_glob_hash_new (void) -{ - XdgGlobHash *glob_hash; - - glob_hash = calloc (1, sizeof (XdgGlobHash)); - - return glob_hash; -} - - -static void -_xdg_glob_hash_free_nodes (XdgGlobHashNode *node) -{ - if (node) - { - if (node->child) - _xdg_glob_hash_free_nodes (node->child); - if (node->next) - _xdg_glob_hash_free_nodes (node->next); - if (node->mime_type) - free ((void *) node->mime_type); - free (node); - } -} - -void -_xdg_glob_hash_free (XdgGlobHash *glob_hash) -{ - _xdg_glob_list_free (glob_hash->literal_list); - _xdg_glob_list_free (glob_hash->full_list); - _xdg_glob_hash_free_nodes (glob_hash->simple_node); - free (glob_hash); -} - -XdgGlobType -_xdg_glob_determine_type (const char *glob) -{ - const char *ptr; - int maybe_in_simple_glob = FALSE; - int first_char = TRUE; - - ptr = glob; - - while (*ptr != '\0') - { - if (*ptr == '*' && first_char) - maybe_in_simple_glob = TRUE; - else if (*ptr == '\\' || *ptr == '[' || *ptr == '?' || *ptr == '*') - return XDG_GLOB_FULL; - - first_char = FALSE; - ptr = _xdg_utf8_next_char (ptr); - } - if (maybe_in_simple_glob) - return XDG_GLOB_SIMPLE; - else - return XDG_GLOB_LITERAL; -} - -/* glob must be valid UTF-8 */ -void -_xdg_glob_hash_append_glob (XdgGlobHash *glob_hash, - const char *glob, - const char *mime_type, - int weight) -{ - XdgGlobType type; - - assert (glob_hash != NULL); - assert (glob != NULL); - - type = _xdg_glob_determine_type (glob); - - switch (type) - { - case XDG_GLOB_LITERAL: - glob_hash->literal_list = _xdg_glob_list_append (glob_hash->literal_list, strdup (glob), strdup (mime_type), weight); - break; - case XDG_GLOB_SIMPLE: - glob_hash->simple_node = _xdg_glob_hash_insert_text (glob_hash->simple_node, glob + 1, mime_type, weight); - break; - case XDG_GLOB_FULL: - glob_hash->full_list = _xdg_glob_list_append (glob_hash->full_list, strdup (glob), strdup (mime_type), weight); - break; - } -} - -void -_xdg_glob_hash_dump (XdgGlobHash *glob_hash) -{ - XdgGlobList *list; - printf ("LITERAL STRINGS\n"); - if (!glob_hash || glob_hash->literal_list == NULL) - { - printf (" None\n"); - } - else - { - for (list = glob_hash->literal_list; list; list = list->next) - printf (" %s - %s %d\n", (char *)list->data, list->mime_type, list->weight); - } - printf ("\nSIMPLE GLOBS\n"); - if (!glob_hash || glob_hash->simple_node == NULL) - { - printf (" None\n"); - } - else - { - _xdg_glob_hash_node_dump (glob_hash->simple_node, 4); - } - - printf ("\nFULL GLOBS\n"); - if (!glob_hash || glob_hash->full_list == NULL) - { - printf (" None\n"); - } - else - { - for (list = glob_hash->full_list; list; list = list->next) - printf (" %s - %s %d\n", (char *)list->data, list->mime_type, list->weight); - } -} - - -void -_xdg_mime_glob_read_from_file (XdgGlobHash *glob_hash, - const char *file_name) -{ - FILE *glob_file; - char line[255]; - - glob_file = fopen (file_name, "r"); - - if (glob_file == NULL) - return; - - /* FIXME: Not UTF-8 safe. Doesn't work if lines are greater than 255 chars. - * Blah */ - while (fgets (line, 255, glob_file) != NULL) - { - char *colon, *colon2; - char *mimetype, *glob; - int weight; - - if (line[0] == '#') - continue; - - colon = strchr (line, ':'); - if (colon == NULL) - continue; - *(colon++) = '\0'; - colon[strlen (colon) -1] = '\0'; - colon2 = strchr (colon, ':'); - if (colon2) - { - *(colon2++) = '\000'; - weight = atoi (line); - mimetype = colon; - glob = colon2; - } - else - { - weight = 50; - mimetype = line; - glob = colon; - } - _xdg_glob_hash_append_glob (glob_hash, glob, mimetype, weight); - } - - fclose (glob_file); -} diff --git a/base/third_party/xdg_mime/xdgmimeglob.h b/base/third_party/xdg_mime/xdgmimeglob.h deleted file mode 100644 index df8dc79..0000000 --- a/base/third_party/xdg_mime/xdgmimeglob.h +++ /dev/null @@ -1,68 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu" -*- */ -/* xdgmimeglob.h: Private file. Datastructure for storing the globs. - * - * More info can be found at http://www.freedesktop.org/standards/ - * - * 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. - */ - -#ifndef __XDG_MIME_GLOB_H__ -#define __XDG_MIME_GLOB_H__ - -#include "xdgmime.h" - -typedef struct XdgGlobHash XdgGlobHash; - -typedef enum -{ - XDG_GLOB_LITERAL, /* Makefile */ - XDG_GLOB_SIMPLE, /* *.gif */ - XDG_GLOB_FULL /* x*.[ch] */ -} XdgGlobType; - - -#ifdef XDG_PREFIX -#define _xdg_mime_glob_read_from_file XDG_RESERVED_ENTRY(glob_read_from_file) -#define _xdg_glob_hash_new XDG_RESERVED_ENTRY(hash_new) -#define _xdg_glob_hash_free XDG_RESERVED_ENTRY(hash_free) -#define _xdg_glob_hash_lookup_file_name XDG_RESERVED_ENTRY(hash_lookup_file_name) -#define _xdg_glob_hash_append_glob XDG_RESERVED_ENTRY(hash_append_glob) -#define _xdg_glob_determine_type XDG_RESERVED_ENTRY(determine_type) -#define _xdg_glob_hash_dump XDG_RESERVED_ENTRY(hash_dump) -#endif - -void _xdg_mime_glob_read_from_file (XdgGlobHash *glob_hash, - const char *file_name); -XdgGlobHash *_xdg_glob_hash_new (void); -void _xdg_glob_hash_free (XdgGlobHash *glob_hash); -int _xdg_glob_hash_lookup_file_name (XdgGlobHash *glob_hash, - const char *text, - const char *mime_types[], - int n_mime_types); -void _xdg_glob_hash_append_glob (XdgGlobHash *glob_hash, - const char *glob, - const char *mime_type, - int weight); -XdgGlobType _xdg_glob_determine_type (const char *glob); -void _xdg_glob_hash_dump (XdgGlobHash *glob_hash); - -#endif /* __XDG_MIME_GLOB_H__ */ diff --git a/base/third_party/xdg_mime/xdgmimeicon.c b/base/third_party/xdg_mime/xdgmimeicon.c deleted file mode 100644 index 16db843..0000000 --- a/base/third_party/xdg_mime/xdgmimeicon.c +++ /dev/null @@ -1,183 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu" -*- */ -/* xdgmimeicon.c: Private file. Datastructure for storing the aliases. - * - * More info can be found at http://www.freedesktop.org/standards/ - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "xdgmimeicon.h" -#include "xdgmimeint.h" -#include <stdlib.h> -#include <stdio.h> -#include <assert.h> -#include <string.h> -#include <fnmatch.h> - -#ifndef FALSE -#define FALSE (0) -#endif - -#ifndef TRUE -#define TRUE (!FALSE) -#endif - -typedef struct XdgIcon XdgIcon; - -struct XdgIcon -{ - char *mime_type; - char *icon_name; -}; - -struct XdgIconList -{ - struct XdgIcon *icons; - int n_icons; -}; - -XdgIconList * -_xdg_mime_icon_list_new (void) -{ - XdgIconList *list; - - list = malloc (sizeof (XdgIconList)); - - list->icons = NULL; - list->n_icons = 0; - - return list; -} - -void -_xdg_mime_icon_list_free (XdgIconList *list) -{ - int i; - - if (list->icons) - { - for (i = 0; i < list->n_icons; i++) - { - free (list->icons[i].mime_type); - free (list->icons[i].icon_name); - } - free (list->icons); - } - free (list); -} - -static int -icon_entry_cmp (const void *v1, const void *v2) -{ - return strcmp (((XdgIcon *)v1)->mime_type, ((XdgIcon *)v2)->mime_type); -} - -const char * -_xdg_mime_icon_list_lookup (XdgIconList *list, - const char *mime_type) -{ - XdgIcon *entry; - XdgIcon key; - - if (list->n_icons > 0) - { - key.mime_type = (char *)mime_type; - key.icon_name = NULL; - - entry = bsearch (&key, list->icons, list->n_icons, - sizeof (XdgIcon), icon_entry_cmp); - if (entry) - return entry->icon_name; - } - - return NULL; -} - -void -_xdg_mime_icon_read_from_file (XdgIconList *list, - const char *file_name) -{ - FILE *file; - char line[255]; - int alloc; - - file = fopen (file_name, "r"); - - if (file == NULL) - return; - - /* FIXME: Not UTF-8 safe. Doesn't work if lines are greater than 255 chars. - * Blah */ - alloc = list->n_icons + 16; - list->icons = realloc (list->icons, alloc * sizeof (XdgIcon)); - while (fgets (line, 255, file) != NULL) - { - char *sep; - if (line[0] == '#') - continue; - - sep = strchr (line, ':'); - if (sep == NULL) - continue; - *(sep++) = '\000'; - sep[strlen (sep) -1] = '\000'; - if (list->n_icons == alloc) - { - alloc <<= 1; - list->icons = realloc (list->icons, - alloc * sizeof (XdgIcon)); - } - list->icons[list->n_icons].mime_type = strdup (line); - list->icons[list->n_icons].icon_name = strdup (sep); - list->n_icons++; - } - list->icons = realloc (list->icons, - list->n_icons * sizeof (XdgIcon)); - - fclose (file); - - if (list->n_icons > 1) - qsort (list->icons, list->n_icons, - sizeof (XdgIcon), icon_entry_cmp); -} - - -void -_xdg_mime_icon_list_dump (XdgIconList *list) -{ - int i; - - if (list->icons) - { - for (i = 0; i < list->n_icons; i++) - { - printf ("%s %s\n", - list->icons[i].mime_type, - list->icons[i].icon_name); - } - } -} - - diff --git a/base/third_party/xdg_mime/xdgmimeicon.h b/base/third_party/xdg_mime/xdgmimeicon.h deleted file mode 100644 index b5f2583..0000000 --- a/base/third_party/xdg_mime/xdgmimeicon.h +++ /dev/null @@ -1,50 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu" -*- */ -/* xdgmimeicon.h: Private file. Datastructure for storing the aliases. - * - * More info can be found at http://www.freedesktop.org/standards/ - * - * 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. - */ - -#ifndef __XDG_MIME_ICON_H__ -#define __XDG_MIME_ICON_H__ - -#include "xdgmime.h" - -typedef struct XdgIconList XdgIconList; - -#ifdef XDG_PREFIX -#define _xdg_mime_icon_read_from_file XDG_ENTRY(icon_read_from_file) -#define _xdg_mime_icon_list_new XDG_ENTRY(icon_list_new) -#define _xdg_mime_icon_list_free XDG_ENTRY(icon_list_free) -#define _xdg_mime_icon_list_lookup XDG_ENTRY(icon_list_lookup) -#define _xdg_mime_icon_list_dump XDG_ENTRY(icon_list_dump) -#endif - -void _xdg_mime_icon_read_from_file (XdgIconList *list, - const char *file_name); -XdgIconList *_xdg_mime_icon_list_new (void); -void _xdg_mime_icon_list_free (XdgIconList *list); -const char *_xdg_mime_icon_list_lookup (XdgIconList *list, - const char *mime); -void _xdg_mime_icon_list_dump (XdgIconList *list); - -#endif /* __XDG_MIME_ICON_H__ */ diff --git a/base/third_party/xdg_mime/xdgmimeint.c b/base/third_party/xdg_mime/xdgmimeint.c deleted file mode 100644 index b2aa956..0000000 --- a/base/third_party/xdg_mime/xdgmimeint.c +++ /dev/null @@ -1,191 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu" -*- */ -/* xdgmimeint.c: Internal defines and functions. - * - * More info can be found at http://www.freedesktop.org/standards/ - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "xdgmimeint.h" -#include <ctype.h> -#include <string.h> - -#ifndef FALSE -#define FALSE (0) -#endif - -#ifndef TRUE -#define TRUE (!FALSE) -#endif - -static const char _xdg_utf8_skip_data[256] = { - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,6,6,1,1 -}; - -const char * const _xdg_utf8_skip = _xdg_utf8_skip_data; - - - -/* Returns the number of unprocessed characters. */ -xdg_unichar_t -_xdg_utf8_to_ucs4(const char *source) -{ - xdg_unichar_t ucs32; - if( ! ( *source & 0x80 ) ) - { - ucs32 = *source; - } - else - { - int bytelength = 0; - xdg_unichar_t result; - if ( ! (*source & 0x40) ) - { - ucs32 = *source; - } - else - { - if ( ! (*source & 0x20) ) - { - result = *source++ & 0x1F; - bytelength = 2; - } - else if ( ! (*source & 0x10) ) - { - result = *source++ & 0x0F; - bytelength = 3; - } - else if ( ! (*source & 0x08) ) - { - result = *source++ & 0x07; - bytelength = 4; - } - else if ( ! (*source & 0x04) ) - { - result = *source++ & 0x03; - bytelength = 5; - } - else if ( ! (*source & 0x02) ) - { - result = *source++ & 0x01; - bytelength = 6; - } - else - { - result = *source++; - bytelength = 1; - } - - for ( bytelength --; bytelength > 0; bytelength -- ) - { - result <<= 6; - result |= *source++ & 0x3F; - } - ucs32 = result; - } - } - return ucs32; -} - - -/* hullo. this is great code. don't rewrite it */ - -xdg_unichar_t -_xdg_ucs4_to_lower (xdg_unichar_t source) -{ - /* FIXME: Do a real to_upper sometime */ - /* CaseFolding-3.2.0.txt has a table of rules. */ - if ((source & 0xFF) == source) - return (xdg_unichar_t) tolower ((unsigned char) source); - return source; -} - -int -_xdg_utf8_validate (const char *source) -{ - /* FIXME: actually write */ - return TRUE; -} - -const char * -_xdg_get_base_name (const char *file_name) -{ - const char *base_name; - - if (file_name == NULL) - return NULL; - - base_name = strrchr (file_name, '/'); - - if (base_name == NULL) - return file_name; - else - return base_name + 1; -} - -xdg_unichar_t * -_xdg_convert_to_ucs4 (const char *source, int *len) -{ - xdg_unichar_t *out; - int i; - const char *p; - - out = malloc (sizeof (xdg_unichar_t) * (strlen (source) + 1)); - - p = source; - i = 0; - while (*p) - { - out[i++] = _xdg_utf8_to_ucs4 (p); - p = _xdg_utf8_next_char (p); - } - out[i] = 0; - *len = i; - - return out; -} - -void -_xdg_reverse_ucs4 (xdg_unichar_t *source, int len) -{ - xdg_unichar_t c; - int i; - - for (i = 0; i < len - i - 1; i++) - { - c = source[i]; - source[i] = source[len - i - 1]; - source[len - i - 1] = c; - } -} - diff --git a/base/third_party/xdg_mime/xdgmimeint.h b/base/third_party/xdg_mime/xdgmimeint.h deleted file mode 100644 index 232c808..0000000 --- a/base/third_party/xdg_mime/xdgmimeint.h +++ /dev/null @@ -1,77 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu" -*- */ -/* xdgmimeint.h: Internal defines and functions. - * - * More info can be found at http://www.freedesktop.org/standards/ - * - * 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. - */ - -#ifndef __XDG_MIME_INT_H__ -#define __XDG_MIME_INT_H__ - -#include "xdgmime.h" - - -#ifndef FALSE -#define FALSE (0) -#endif - -#ifndef TRUE -#define TRUE (!FALSE) -#endif - -/* FIXME: Needs to be configure check */ -typedef unsigned int xdg_unichar_t; -typedef unsigned char xdg_uchar8_t; -typedef unsigned short xdg_uint16_t; -typedef unsigned int xdg_uint32_t; - -#ifdef XDG_PREFIX -#define _xdg_utf8_skip XDG_RESERVED_ENTRY(utf8_skip) -#define _xdg_utf8_to_ucs4 XDG_RESERVED_ENTRY(utf8_to_ucs4) -#define _xdg_ucs4_to_lower XDG_RESERVED_ENTRY(ucs4_to_lower) -#define _xdg_utf8_validate XDG_RESERVED_ENTRY(utf8_validate) -#define _xdg_get_base_name XDG_RESERVED_ENTRY(get_base_name) -#define _xdg_convert_to_ucs4 XDG_RESERVED_ENTRY(convert_to_ucs4) -#define _xdg_reverse_ucs4 XDG_RESERVED_ENTRY(reverse_ucs4) -#endif - -#define SWAP_BE16_TO_LE16(val) (xdg_uint16_t)(((xdg_uint16_t)(val) << 8)|((xdg_uint16_t)(val) >> 8)) - -#define SWAP_BE32_TO_LE32(val) (xdg_uint32_t)((((xdg_uint32_t)(val) & 0xFF000000U) >> 24) | \ - (((xdg_uint32_t)(val) & 0x00FF0000U) >> 8) | \ - (((xdg_uint32_t)(val) & 0x0000FF00U) << 8) | \ - (((xdg_uint32_t)(val) & 0x000000FFU) << 24)) -/* UTF-8 utils - */ -extern const char *const _xdg_utf8_skip; -#define _xdg_utf8_next_char(p) (char *)((p) + _xdg_utf8_skip[*(unsigned char *)(p)]) -#define _xdg_utf8_char_size(p) (int) (_xdg_utf8_skip[*(unsigned char *)(p)]) - -xdg_unichar_t _xdg_utf8_to_ucs4 (const char *source); -xdg_unichar_t _xdg_ucs4_to_lower (xdg_unichar_t source); -int _xdg_utf8_validate (const char *source); -xdg_unichar_t *_xdg_convert_to_ucs4 (const char *source, int *len); -void _xdg_reverse_ucs4 (xdg_unichar_t *source, int len); -const char *_xdg_get_base_name (const char *file_name); - -#endif /* __XDG_MIME_INT_H__ */ diff --git a/base/third_party/xdg_mime/xdgmimemagic.c b/base/third_party/xdg_mime/xdgmimemagic.c deleted file mode 100644 index ae1093a..0000000 --- a/base/third_party/xdg_mime/xdgmimemagic.c +++ /dev/null @@ -1,813 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu" -*- */ -/* xdgmimemagic.: Private file. Datastructure for storing magic files. - * - * More info can be found at http://www.freedesktop.org/standards/ - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <assert.h> -#include "xdgmimemagic.h" -#include "xdgmimeint.h" -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <ctype.h> -#include <errno.h> -#include <limits.h> - -#ifndef FALSE -#define FALSE (0) -#endif - -#ifndef TRUE -#define TRUE (!FALSE) -#endif - -#if !defined getc_unlocked && !defined HAVE_GETC_UNLOCKED -# define getc_unlocked(fp) getc (fp) -#endif - -typedef struct XdgMimeMagicMatch XdgMimeMagicMatch; -typedef struct XdgMimeMagicMatchlet XdgMimeMagicMatchlet; - -typedef enum -{ - XDG_MIME_MAGIC_SECTION, - XDG_MIME_MAGIC_MAGIC, - XDG_MIME_MAGIC_ERROR, - XDG_MIME_MAGIC_EOF -} XdgMimeMagicState; - -struct XdgMimeMagicMatch -{ - const char *mime_type; - int priority; - XdgMimeMagicMatchlet *matchlet; - XdgMimeMagicMatch *next; -}; - - -struct XdgMimeMagicMatchlet -{ - int indent; - int offset; - unsigned int value_length; - unsigned char *value; - unsigned char *mask; - unsigned int range_length; - unsigned int word_size; - XdgMimeMagicMatchlet *next; -}; - - -struct XdgMimeMagic -{ - XdgMimeMagicMatch *match_list; - int max_extent; -}; - -static XdgMimeMagicMatch * -_xdg_mime_magic_match_new (void) -{ - return calloc (1, sizeof (XdgMimeMagicMatch)); -} - - -static XdgMimeMagicMatchlet * -_xdg_mime_magic_matchlet_new (void) -{ - XdgMimeMagicMatchlet *matchlet; - - matchlet = malloc (sizeof (XdgMimeMagicMatchlet)); - - matchlet->indent = 0; - matchlet->offset = 0; - matchlet->value_length = 0; - matchlet->value = NULL; - matchlet->mask = NULL; - matchlet->range_length = 1; - matchlet->word_size = 1; - matchlet->next = NULL; - - return matchlet; -} - - -static void -_xdg_mime_magic_matchlet_free (XdgMimeMagicMatchlet *mime_magic_matchlet) -{ - if (mime_magic_matchlet) - { - if (mime_magic_matchlet->next) - _xdg_mime_magic_matchlet_free (mime_magic_matchlet->next); - if (mime_magic_matchlet->value) - free (mime_magic_matchlet->value); - if (mime_magic_matchlet->mask) - free (mime_magic_matchlet->mask); - free (mime_magic_matchlet); - } -} - - -/* Frees mime_magic_match and the remainder of its list - */ -static void -_xdg_mime_magic_match_free (XdgMimeMagicMatch *mime_magic_match) -{ - XdgMimeMagicMatch *ptr, *next; - - ptr = mime_magic_match; - while (ptr) - { - next = ptr->next; - - if (ptr->mime_type) - free ((void *) ptr->mime_type); - if (ptr->matchlet) - _xdg_mime_magic_matchlet_free (ptr->matchlet); - free (ptr); - - ptr = next; - } -} - -/* Reads in a hunk of data until a newline character or a '\000' is hit. The - * returned string is null terminated, and doesn't include the newline. - */ -static unsigned char * -_xdg_mime_magic_read_to_newline (FILE *magic_file, - int *end_of_file) -{ - unsigned char *retval; - int c; - int len, pos; - - len = 128; - pos = 0; - retval = malloc (len); - *end_of_file = FALSE; - - while (TRUE) - { - c = getc_unlocked (magic_file); - if (c == EOF) - { - *end_of_file = TRUE; - break; - } - if (c == '\n' || c == '\000') - break; - retval[pos++] = (unsigned char) c; - if (pos % 128 == 127) - { - len = len + 128; - retval = realloc (retval, len); - } - } - - retval[pos] = '\000'; - return retval; -} - -/* Returns the number read from the file, or -1 if no number could be read. - */ -static int -_xdg_mime_magic_read_a_number (FILE *magic_file, - int *end_of_file) -{ - /* LONG_MAX is about 20 characters on my system */ -#define MAX_NUMBER_SIZE 30 - char number_string[MAX_NUMBER_SIZE + 1]; - int pos = 0; - int c; - long retval = -1; - - while (TRUE) - { - c = getc_unlocked (magic_file); - - if (c == EOF) - { - *end_of_file = TRUE; - break; - } - if (! isdigit (c)) - { - ungetc (c, magic_file); - break; - } - number_string[pos] = (char) c; - pos++; - if (pos == MAX_NUMBER_SIZE) - break; - } - if (pos > 0) - { - number_string[pos] = '\000'; - errno = 0; - retval = strtol (number_string, NULL, 10); - - if ((retval < INT_MIN) || (retval > INT_MAX) || (errno != 0)) - return -1; - } - - return retval; -} - -/* Headers are of the format: - * [<priority>:<mime-type>] - */ -static XdgMimeMagicState -_xdg_mime_magic_parse_header (FILE *magic_file, XdgMimeMagicMatch *match) -{ - int c; - char *buffer; - char *end_ptr; - int end_of_file = 0; - - assert (magic_file != NULL); - assert (match != NULL); - - c = getc_unlocked (magic_file); - if (c == EOF) - return XDG_MIME_MAGIC_EOF; - if (c != '[') - return XDG_MIME_MAGIC_ERROR; - - match->priority = _xdg_mime_magic_read_a_number (magic_file, &end_of_file); - if (end_of_file) - return XDG_MIME_MAGIC_EOF; - if (match->priority == -1) - return XDG_MIME_MAGIC_ERROR; - - c = getc_unlocked (magic_file); - if (c == EOF) - return XDG_MIME_MAGIC_EOF; - if (c != ':') - return XDG_MIME_MAGIC_ERROR; - - buffer = (char *)_xdg_mime_magic_read_to_newline (magic_file, &end_of_file); - if (end_of_file) - return XDG_MIME_MAGIC_EOF; - - end_ptr = buffer; - while (*end_ptr != ']' && *end_ptr != '\000' && *end_ptr != '\n') - end_ptr++; - if (*end_ptr != ']') - { - free (buffer); - return XDG_MIME_MAGIC_ERROR; - } - *end_ptr = '\000'; - - match->mime_type = strdup (buffer); - free (buffer); - - return XDG_MIME_MAGIC_MAGIC; -} - -static XdgMimeMagicState -_xdg_mime_magic_parse_error (FILE *magic_file) -{ - int c; - - while (1) - { - c = getc_unlocked (magic_file); - if (c == EOF) - return XDG_MIME_MAGIC_EOF; - if (c == '\n') - return XDG_MIME_MAGIC_SECTION; - } -} - -/* Headers are of the format: - * [ indent ] ">" start-offset "=" value - * [ "&" mask ] [ "~" word-size ] [ "+" range-length ] "\n" - */ -static XdgMimeMagicState -_xdg_mime_magic_parse_magic_line (FILE *magic_file, - XdgMimeMagicMatch *match) -{ - XdgMimeMagicMatchlet *matchlet; - int c; - int end_of_file; - int indent = 0; - int bytes_read; - - assert (magic_file != NULL); - - /* Sniff the buffer to make sure it's a valid line */ - c = getc_unlocked (magic_file); - if (c == EOF) - return XDG_MIME_MAGIC_EOF; - else if (c == '[') - { - ungetc (c, magic_file); - return XDG_MIME_MAGIC_SECTION; - } - else if (c == '\n') - return XDG_MIME_MAGIC_MAGIC; - - /* At this point, it must be a digit or a '>' */ - end_of_file = FALSE; - if (isdigit (c)) - { - ungetc (c, magic_file); - indent = _xdg_mime_magic_read_a_number (magic_file, &end_of_file); - if (end_of_file) - return XDG_MIME_MAGIC_EOF; - if (indent == -1) - return XDG_MIME_MAGIC_ERROR; - c = getc_unlocked (magic_file); - if (c == EOF) - return XDG_MIME_MAGIC_EOF; - } - - if (c != '>') - return XDG_MIME_MAGIC_ERROR; - - matchlet = _xdg_mime_magic_matchlet_new (); - matchlet->indent = indent; - matchlet->offset = _xdg_mime_magic_read_a_number (magic_file, &end_of_file); - if (end_of_file) - { - _xdg_mime_magic_matchlet_free (matchlet); - return XDG_MIME_MAGIC_EOF; - } - if (matchlet->offset == -1) - { - _xdg_mime_magic_matchlet_free (matchlet); - return XDG_MIME_MAGIC_ERROR; - } - c = getc_unlocked (magic_file); - if (c == EOF) - { - _xdg_mime_magic_matchlet_free (matchlet); - return XDG_MIME_MAGIC_EOF; - } - else if (c != '=') - { - _xdg_mime_magic_matchlet_free (matchlet); - return XDG_MIME_MAGIC_ERROR; - } - - /* Next two bytes determine how long the value is */ - matchlet->value_length = 0; - c = getc_unlocked (magic_file); - if (c == EOF) - { - _xdg_mime_magic_matchlet_free (matchlet); - return XDG_MIME_MAGIC_EOF; - } - matchlet->value_length = c & 0xFF; - matchlet->value_length = matchlet->value_length << 8; - - c = getc_unlocked (magic_file); - if (c == EOF) - { - _xdg_mime_magic_matchlet_free (matchlet); - return XDG_MIME_MAGIC_EOF; - } - matchlet->value_length = matchlet->value_length + (c & 0xFF); - - matchlet->value = malloc (matchlet->value_length); - - /* OOM */ - if (matchlet->value == NULL) - { - _xdg_mime_magic_matchlet_free (matchlet); - return XDG_MIME_MAGIC_ERROR; - } - bytes_read = fread (matchlet->value, 1, matchlet->value_length, magic_file); - if (bytes_read != matchlet->value_length) - { - _xdg_mime_magic_matchlet_free (matchlet); - if (feof (magic_file)) - return XDG_MIME_MAGIC_EOF; - else - return XDG_MIME_MAGIC_ERROR; - } - - c = getc_unlocked (magic_file); - if (c == '&') - { - matchlet->mask = malloc (matchlet->value_length); - /* OOM */ - if (matchlet->mask == NULL) - { - _xdg_mime_magic_matchlet_free (matchlet); - return XDG_MIME_MAGIC_ERROR; - } - bytes_read = fread (matchlet->mask, 1, matchlet->value_length, magic_file); - if (bytes_read != matchlet->value_length) - { - _xdg_mime_magic_matchlet_free (matchlet); - if (feof (magic_file)) - return XDG_MIME_MAGIC_EOF; - else - return XDG_MIME_MAGIC_ERROR; - } - c = getc_unlocked (magic_file); - } - - if (c == '~') - { - matchlet->word_size = _xdg_mime_magic_read_a_number (magic_file, &end_of_file); - if (end_of_file) - { - _xdg_mime_magic_matchlet_free (matchlet); - return XDG_MIME_MAGIC_EOF; - } - if (matchlet->word_size != 0 && - matchlet->word_size != 1 && - matchlet->word_size != 2 && - matchlet->word_size != 4) - { - _xdg_mime_magic_matchlet_free (matchlet); - return XDG_MIME_MAGIC_ERROR; - } - c = getc_unlocked (magic_file); - } - - if (c == '+') - { - matchlet->range_length = _xdg_mime_magic_read_a_number (magic_file, &end_of_file); - if (end_of_file) - { - _xdg_mime_magic_matchlet_free (matchlet); - return XDG_MIME_MAGIC_EOF; - } - if (matchlet->range_length == -1) - { - _xdg_mime_magic_matchlet_free (matchlet); - return XDG_MIME_MAGIC_ERROR; - } - c = getc_unlocked (magic_file); - } - - - if (c == '\n') - { - /* We clean up the matchlet, byte swapping if needed */ - if (matchlet->word_size > 1) - { - int i; - if (matchlet->value_length % matchlet->word_size != 0) - { - _xdg_mime_magic_matchlet_free (matchlet); - return XDG_MIME_MAGIC_ERROR; - } - /* FIXME: need to get this defined in a <config.h> style file */ -#if LITTLE_ENDIAN - for (i = 0; i < matchlet->value_length; i = i + matchlet->word_size) - { - if (matchlet->word_size == 2) - *((xdg_uint16_t *) matchlet->value + i) = SWAP_BE16_TO_LE16 (*((xdg_uint16_t *) (matchlet->value + i))); - else if (matchlet->word_size == 4) - *((xdg_uint32_t *) matchlet->value + i) = SWAP_BE32_TO_LE32 (*((xdg_uint32_t *) (matchlet->value + i))); - if (matchlet->mask) - { - if (matchlet->word_size == 2) - *((xdg_uint16_t *) matchlet->mask + i) = SWAP_BE16_TO_LE16 (*((xdg_uint16_t *) (matchlet->mask + i))); - else if (matchlet->word_size == 4) - *((xdg_uint32_t *) matchlet->mask + i) = SWAP_BE32_TO_LE32 (*((xdg_uint32_t *) (matchlet->mask + i))); - - } - } -#endif - } - - matchlet->next = match->matchlet; - match->matchlet = matchlet; - - - return XDG_MIME_MAGIC_MAGIC; - } - - _xdg_mime_magic_matchlet_free (matchlet); - if (c == EOF) - return XDG_MIME_MAGIC_EOF; - - return XDG_MIME_MAGIC_ERROR; -} - -static int -_xdg_mime_magic_matchlet_compare_to_data (XdgMimeMagicMatchlet *matchlet, - const void *data, - size_t len) -{ - int i, j; - for (i = matchlet->offset; i < matchlet->offset + matchlet->range_length; i++) - { - int valid_matchlet = TRUE; - - if (i + matchlet->value_length > len) - return FALSE; - - if (matchlet->mask) - { - for (j = 0; j < matchlet->value_length; j++) - { - if ((matchlet->value[j] & matchlet->mask[j]) != - ((((unsigned char *) data)[j + i]) & matchlet->mask[j])) - { - valid_matchlet = FALSE; - break; - } - } - } - else - { - for (j = 0; j < matchlet->value_length; j++) - { - if (matchlet->value[j] != ((unsigned char *) data)[j + i]) - { - valid_matchlet = FALSE; - break; - } - } - } - if (valid_matchlet) - return TRUE; - } - return FALSE; -} - -static int -_xdg_mime_magic_matchlet_compare_level (XdgMimeMagicMatchlet *matchlet, - const void *data, - size_t len, - int indent) -{ - while ((matchlet != NULL) && (matchlet->indent == indent)) - { - if (_xdg_mime_magic_matchlet_compare_to_data (matchlet, data, len)) - { - if ((matchlet->next == NULL) || - (matchlet->next->indent <= indent)) - return TRUE; - - if (_xdg_mime_magic_matchlet_compare_level (matchlet->next, - data, - len, - indent + 1)) - return TRUE; - } - - do - { - matchlet = matchlet->next; - } - while (matchlet && matchlet->indent > indent); - } - - return FALSE; -} - -static int -_xdg_mime_magic_match_compare_to_data (XdgMimeMagicMatch *match, - const void *data, - size_t len) -{ - return _xdg_mime_magic_matchlet_compare_level (match->matchlet, data, len, 0); -} - -static void -_xdg_mime_magic_insert_match (XdgMimeMagic *mime_magic, - XdgMimeMagicMatch *match) -{ - XdgMimeMagicMatch *list; - - if (mime_magic->match_list == NULL) - { - mime_magic->match_list = match; - return; - } - - if (match->priority > mime_magic->match_list->priority) - { - match->next = mime_magic->match_list; - mime_magic->match_list = match; - return; - } - - list = mime_magic->match_list; - while (list->next != NULL) - { - if (list->next->priority < match->priority) - { - match->next = list->next; - list->next = match; - return; - } - list = list->next; - } - list->next = match; - match->next = NULL; -} - -XdgMimeMagic * -_xdg_mime_magic_new (void) -{ - return calloc (1, sizeof (XdgMimeMagic)); -} - -void -_xdg_mime_magic_free (XdgMimeMagic *mime_magic) -{ - if (mime_magic) { - _xdg_mime_magic_match_free (mime_magic->match_list); - free (mime_magic); - } -} - -int -_xdg_mime_magic_get_buffer_extents (XdgMimeMagic *mime_magic) -{ - return mime_magic->max_extent; -} - -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 void -_xdg_mime_update_mime_magic_extents (XdgMimeMagic *mime_magic) -{ - XdgMimeMagicMatch *match; - int max_extent = 0; - - for (match = mime_magic->match_list; match; match = match->next) - { - XdgMimeMagicMatchlet *matchlet; - - for (matchlet = match->matchlet; matchlet; matchlet = matchlet->next) - { - int extent; - - extent = matchlet->value_length + matchlet->offset + matchlet->range_length; - if (max_extent < extent) - max_extent = extent; - } - } - - mime_magic->max_extent = max_extent; -} - -static XdgMimeMagicMatchlet * -_xdg_mime_magic_matchlet_mirror (XdgMimeMagicMatchlet *matchlets) -{ - XdgMimeMagicMatchlet *new_list; - XdgMimeMagicMatchlet *tmp; - - if ((matchlets == NULL) || (matchlets->next == NULL)) - return matchlets; - - new_list = NULL; - tmp = matchlets; - while (tmp != NULL) - { - XdgMimeMagicMatchlet *matchlet; - - matchlet = tmp; - tmp = tmp->next; - matchlet->next = new_list; - new_list = matchlet; - } - - return new_list; - -} - -static void -_xdg_mime_magic_read_magic_file (XdgMimeMagic *mime_magic, - FILE *magic_file) -{ - XdgMimeMagicState state; - XdgMimeMagicMatch *match = NULL; /* Quiet compiler */ - - state = XDG_MIME_MAGIC_SECTION; - - while (state != XDG_MIME_MAGIC_EOF) - { - switch (state) - { - case XDG_MIME_MAGIC_SECTION: - match = _xdg_mime_magic_match_new (); - 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); - break; - case XDG_MIME_MAGIC_MAGIC: - state = _xdg_mime_magic_parse_magic_line (magic_file, match); - if (state == XDG_MIME_MAGIC_SECTION || - (state == XDG_MIME_MAGIC_EOF && match->mime_type)) - { - match->matchlet = _xdg_mime_magic_matchlet_mirror (match->matchlet); - _xdg_mime_magic_insert_match (mime_magic, match); - } - else if (state == XDG_MIME_MAGIC_EOF || state == XDG_MIME_MAGIC_ERROR) - _xdg_mime_magic_match_free (match); - break; - case XDG_MIME_MAGIC_ERROR: - state = _xdg_mime_magic_parse_error (magic_file); - break; - case XDG_MIME_MAGIC_EOF: - default: - /* Make the compiler happy */ - assert (0); - } - } - _xdg_mime_update_mime_magic_extents (mime_magic); -} - -void -_xdg_mime_magic_read_from_file (XdgMimeMagic *mime_magic, - const char *file_name) -{ - 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); -} diff --git a/base/third_party/xdg_mime/xdgmimemagic.h b/base/third_party/xdg_mime/xdgmimemagic.h deleted file mode 100644 index 35c8039..0000000 --- a/base/third_party/xdg_mime/xdgmimemagic.h +++ /dev/null @@ -1,57 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu" -*- */ -/* xdgmimemagic.h: Private file. Datastructure for storing the magic files. - * - * More info can be found at http://www.freedesktop.org/standards/ - * - * 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. - */ - -#ifndef __XDG_MIME_MAGIC_H__ -#define __XDG_MIME_MAGIC_H__ - -#include <unistd.h> -#include "xdgmime.h" -typedef struct XdgMimeMagic XdgMimeMagic; - -#ifdef XDG_PREFIX -#define _xdg_mime_glob_read_from_file XDG_RESERVED_ENTRY(glob_read_from_file) -#define _xdg_mime_magic_new XDG_RESERVED_ENTRY(magic_new) -#define _xdg_mime_magic_read_from_file XDG_RESERVED_ENTRY(magic_read_from_file) -#define _xdg_mime_magic_free XDG_RESERVED_ENTRY(magic_free) -#define _xdg_mime_magic_get_buffer_extents XDG_RESERVED_ENTRY(magic_get_buffer_extents) -#define _xdg_mime_magic_lookup_data XDG_RESERVED_ENTRY(magic_lookup_data) -#endif - - -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, - int *result_prio, - const char *mime_types[], - int n_mime_types); - -#endif /* __XDG_MIME_MAGIC_H__ */ diff --git a/base/third_party/xdg_mime/xdgmimeparent.c b/base/third_party/xdg_mime/xdgmimeparent.c deleted file mode 100644 index 52d3c0c..0000000 --- a/base/third_party/xdg_mime/xdgmimeparent.c +++ /dev/null @@ -1,219 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu" -*- */ -/* xdgmimealias.c: Private file. Datastructure for storing the hierarchy. - * - * More info can be found at http://www.freedesktop.org/standards/ - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "xdgmimeparent.h" -#include "xdgmimeint.h" -#include <stdlib.h> -#include <stdio.h> -#include <assert.h> -#include <string.h> -#include <fnmatch.h> - -#ifndef FALSE -#define FALSE (0) -#endif - -#ifndef TRUE -#define TRUE (!FALSE) -#endif - -typedef struct XdgMimeParents XdgMimeParents; - -struct XdgMimeParents -{ - char *mime; - char **parents; - int n_parents; -}; - -struct XdgParentList -{ - struct XdgMimeParents *parents; - int n_mimes; -}; - -XdgParentList * -_xdg_mime_parent_list_new (void) -{ - XdgParentList *list; - - list = malloc (sizeof (XdgParentList)); - - list->parents = NULL; - list->n_mimes = 0; - - return list; -} - -void -_xdg_mime_parent_list_free (XdgParentList *list) -{ - int i; - char **p; - - if (list->parents) - { - for (i = 0; i < list->n_mimes; i++) - { - for (p = list->parents[i].parents; *p; p++) - free (*p); - - free (list->parents[i].parents); - free (list->parents[i].mime); - } - free (list->parents); - } - free (list); -} - -static int -parent_entry_cmp (const void *v1, const void *v2) -{ - return strcmp (((XdgMimeParents *)v1)->mime, ((XdgMimeParents *)v2)->mime); -} - -const char ** -_xdg_mime_parent_list_lookup (XdgParentList *list, - const char *mime) -{ - XdgMimeParents *entry; - XdgMimeParents key; - - if (list->n_mimes > 0) - { - key.mime = (char *)mime; - key.parents = NULL; - - entry = bsearch (&key, list->parents, list->n_mimes, - sizeof (XdgMimeParents), &parent_entry_cmp); - if (entry) - return (const char **)entry->parents; - } - - return NULL; -} - -void -_xdg_mime_parent_read_from_file (XdgParentList *list, - const char *file_name) -{ - FILE *file; - char line[255]; - int i, alloc; - XdgMimeParents *entry; - - file = fopen (file_name, "r"); - - if (file == NULL) - return; - - /* FIXME: Not UTF-8 safe. Doesn't work if lines are greater than 255 chars. - * Blah */ - alloc = list->n_mimes + 16; - list->parents = realloc (list->parents, alloc * sizeof (XdgMimeParents)); - while (fgets (line, 255, file) != NULL) - { - char *sep; - if (line[0] == '#') - continue; - - sep = strchr (line, ' '); - if (sep == NULL) - continue; - *(sep++) = '\000'; - sep[strlen (sep) -1] = '\000'; - entry = NULL; - for (i = 0; i < list->n_mimes; i++) - { - if (strcmp (list->parents[i].mime, line) == 0) - { - entry = &(list->parents[i]); - break; - } - } - - if (!entry) - { - if (list->n_mimes == alloc) - { - alloc <<= 1; - list->parents = realloc (list->parents, - alloc * sizeof (XdgMimeParents)); - } - list->parents[list->n_mimes].mime = strdup (line); - list->parents[list->n_mimes].parents = NULL; - entry = &(list->parents[list->n_mimes]); - list->n_mimes++; - } - - if (!entry->parents) - { - entry->n_parents = 1; - entry->parents = malloc ((entry->n_parents + 1) * sizeof (char *)); - } - else - { - entry->n_parents += 1; - entry->parents = realloc (entry->parents, - (entry->n_parents + 2) * sizeof (char *)); - } - entry->parents[entry->n_parents - 1] = strdup (sep); - entry->parents[entry->n_parents] = NULL; - } - - list->parents = realloc (list->parents, - list->n_mimes * sizeof (XdgMimeParents)); - - fclose (file); - - if (list->n_mimes > 1) - qsort (list->parents, list->n_mimes, - sizeof (XdgMimeParents), &parent_entry_cmp); -} - - -void -_xdg_mime_parent_list_dump (XdgParentList *list) -{ - int i; - char **p; - - if (list->parents) - { - for (i = 0; i < list->n_mimes; i++) - { - for (p = list->parents[i].parents; *p; p++) - printf ("%s %s\n", list->parents[i].mime, *p); - } - } -} - - diff --git a/base/third_party/xdg_mime/xdgmimeparent.h b/base/third_party/xdg_mime/xdgmimeparent.h deleted file mode 100644 index b564f41..0000000 --- a/base/third_party/xdg_mime/xdgmimeparent.h +++ /dev/null @@ -1,51 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu" -*- */ -/* xdgmimeparent.h: Private file. Datastructure for storing the hierarchy. - * - * More info can be found at http://www.freedesktop.org/standards/ - * - * 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. - */ - -#ifndef __XDG_MIME_PARENT_H__ -#define __XDG_MIME_PARENT_H__ - -#include "xdgmime.h" - -typedef struct XdgParentList XdgParentList; - -#ifdef XDG_PREFIX -#define _xdg_mime_parent_read_from_file XDG_RESERVED_ENTRY(parent_read_from_file) -#define _xdg_mime_parent_list_new XDG_RESERVED_ENTRY(parent_list_new) -#define _xdg_mime_parent_list_free XDG_RESERVED_ENTRY(parent_list_free) -#define _xdg_mime_parent_list_lookup XDG_RESERVED_ENTRY(parent_list_lookup) -#define _xdg_mime_parent_list_dump XDG_RESERVED_ENTRY(parent_list_dump) -#endif - -void _xdg_mime_parent_read_from_file (XdgParentList *list, - const char *file_name); -XdgParentList *_xdg_mime_parent_list_new (void); -void _xdg_mime_parent_list_free (XdgParentList *list); -const char **_xdg_mime_parent_list_lookup (XdgParentList *list, - const char *mime); -void _xdg_mime_parent_list_dump (XdgParentList *list); - -#endif /* __XDG_MIME_PARENT_H__ */ diff --git a/base/third_party/xdg_user_dirs/LICENSE b/base/third_party/xdg_user_dirs/LICENSE deleted file mode 100644 index 540e803..0000000 --- a/base/third_party/xdg_user_dirs/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ - Copyright (c) 2007 Red Hat, inc - - Permission is hereby granted, free of charge, to any person - obtaining a copy of this software and associated documentation files - (the "Software"), to deal in the Software without restriction, - including without limitation the rights to use, copy, modify, merge, - publish, distribute, sublicense, and/or sell copies of the Software, - and to permit persons to whom the Software is furnished to do so, - subject to the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. diff --git a/base/third_party/xdg_user_dirs/README.chromium b/base/third_party/xdg_user_dirs/README.chromium deleted file mode 100644 index ec9d810..0000000 --- a/base/third_party/xdg_user_dirs/README.chromium +++ /dev/null @@ -1,6 +0,0 @@ -Name: xdg-user-dirs -URL: http://www.freedesktop.org/wiki/Software/xdg-user-dirs - -This directory include xdg-user-dir-lookup.c renamed as xdg_user_dir_lookup.cc -from xdg-user-dirs 0.10. We made xdg_user_dir_lookup() non-static and added a -xdg_user_dir_lookup.h. diff --git a/base/third_party/xdg_user_dirs/xdg_user_dir_lookup.cc b/base/third_party/xdg_user_dirs/xdg_user_dir_lookup.cc deleted file mode 100644 index 343f70c..0000000 --- a/base/third_party/xdg_user_dirs/xdg_user_dir_lookup.cc +++ /dev/null @@ -1,232 +0,0 @@ -/* - This file is not licenced under the GPL like the rest of the code. - Its is under the MIT license, to encourage reuse by cut-and-paste. - - Copyright (c) 2007 Red Hat, inc - - Permission is hereby granted, free of charge, to any person - obtaining a copy of this software and associated documentation files - (the "Software"), to deal in the Software without restriction, - including without limitation the rights to use, copy, modify, merge, - publish, distribute, sublicense, and/or sell copies of the Software, - and to permit persons to whom the Software is furnished to do so, - subject to the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. -*/ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -/** - * xdg_user_dir_lookup_with_fallback: - * @type: a string specifying the type of directory - * @fallback: value to use if the directory isn't specified by the user - * @returns: a newly allocated absolute pathname - * - * Looks up a XDG user directory of the specified type. - * Example of types are "DESKTOP" and "DOWNLOAD". - * - * In case the user hasn't specified any directory for the specified - * type the value returned is @fallback. - * - * The return value is newly allocated and must be freed with - * free(). The return value is never NULL if @fallback != NULL, unless - * out of memory. - **/ -static char * -xdg_user_dir_lookup_with_fallback (const char *type, const char *fallback) -{ - FILE *file; - char *home_dir, *config_home, *config_file; - char buffer[512]; - char *user_dir; - char *p, *d; - int len; - int relative; - - home_dir = getenv ("HOME"); - - if (home_dir == NULL) - goto error; - - config_home = getenv ("XDG_CONFIG_HOME"); - if (config_home == NULL || config_home[0] == 0) - { - config_file = (char*) malloc (strlen (home_dir) + strlen ("/.config/user-dirs.dirs") + 1); - if (config_file == NULL) - goto error; - - strcpy (config_file, home_dir); - strcat (config_file, "/.config/user-dirs.dirs"); - } - else - { - config_file = (char*) malloc (strlen (config_home) + strlen ("/user-dirs.dirs") + 1); - if (config_file == NULL) - goto error; - - strcpy (config_file, config_home); - strcat (config_file, "/user-dirs.dirs"); - } - - file = fopen (config_file, "r"); - free (config_file); - if (file == NULL) - goto error; - - user_dir = NULL; - while (fgets (buffer, sizeof (buffer), file)) - { - /* Remove newline at end */ - len = strlen (buffer); - if (len > 0 && buffer[len-1] == '\n') - buffer[len-1] = 0; - - p = buffer; - while (*p == ' ' || *p == '\t') - p++; - - if (strncmp (p, "XDG_", 4) != 0) - continue; - p += 4; - if (strncmp (p, type, strlen (type)) != 0) - continue; - p += strlen (type); - if (strncmp (p, "_DIR", 4) != 0) - continue; - p += 4; - - while (*p == ' ' || *p == '\t') - p++; - - if (*p != '=') - continue; - p++; - - while (*p == ' ' || *p == '\t') - p++; - - if (*p != '"') - continue; - p++; - - relative = 0; - if (strncmp (p, "$HOME/", 6) == 0) - { - p += 6; - relative = 1; - } - else if (*p != '/') - continue; - - if (relative) - { - user_dir = (char*) malloc (strlen (home_dir) + 1 + strlen (p) + 1); - if (user_dir == NULL) - goto error2; - - strcpy (user_dir, home_dir); - strcat (user_dir, "/"); - } - else - { - user_dir = (char*) malloc (strlen (p) + 1); - if (user_dir == NULL) - goto error2; - - *user_dir = 0; - } - - d = user_dir + strlen (user_dir); - while (*p && *p != '"') - { - if ((*p == '\\') && (*(p+1) != 0)) - p++; - *d++ = *p++; - } - *d = 0; - } -error2: - fclose (file); - - if (user_dir) - return user_dir; - - error: - if (fallback) - return strdup (fallback); - return NULL; -} - -/** - * xdg_user_dir_lookup: - * @type: a string specifying the type of directory - * @returns: a newly allocated absolute pathname - * - * Looks up a XDG user directory of the specified type. - * Example of types are "DESKTOP" and "DOWNLOAD". - * - * The return value is always != NULL (unless out of memory), - * and if a directory - * for the type is not specified by the user the default - * is the home directory. Except for DESKTOP which defaults - * to ~/Desktop. - * - * The return value is newly allocated and must be freed with - * free(). - **/ -char * -xdg_user_dir_lookup (const char *type) -{ - char *dir, *home_dir, *user_dir; - - dir = xdg_user_dir_lookup_with_fallback (type, NULL); - if (dir != NULL) - return dir; - - home_dir = getenv ("HOME"); - - if (home_dir == NULL) - return strdup ("/tmp"); - - /* Special case desktop for historical compatibility */ - if (strcmp (type, "DESKTOP") == 0) - { - user_dir = (char*) malloc (strlen (home_dir) + strlen ("/Desktop") + 1); - if (user_dir == NULL) - return NULL; - - strcpy (user_dir, home_dir); - strcat (user_dir, "/Desktop"); - return user_dir; - } - - return strdup (home_dir); -} - -#ifdef STANDALONE_XDG_USER_DIR_LOOKUP -int -main (int argc, char *argv[]) -{ - if (argc != 2) - { - fprintf (stderr, "Usage %s <dir-type>\n", argv[0]); - exit (1); - } - - printf ("%s\n", xdg_user_dir_lookup (argv[1])); - return 0; -} -#endif diff --git a/base/third_party/xdg_user_dirs/xdg_user_dir_lookup.h b/base/third_party/xdg_user_dirs/xdg_user_dir_lookup.h deleted file mode 100644 index 9e81e1b..0000000 --- a/base/third_party/xdg_user_dirs/xdg_user_dir_lookup.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - This file is not licenced under the GPL like the rest of the code. - Its is under the MIT license, to encourage reuse by cut-and-paste. - - Copyright (c) 2007 Red Hat, inc - - Permission is hereby granted, free of charge, to any person - obtaining a copy of this software and associated documentation files - (the "Software"), to deal in the Software without restriction, - including without limitation the rights to use, copy, modify, merge, - publish, distribute, sublicense, and/or sell copies of the Software, - and to permit persons to whom the Software is furnished to do so, - subject to the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. -*/ - -#ifndef CHROME_THIRD_PARTY_XDG_USER_DIRS_XDG_USER_DIR_LOOKUP_H_ -#define CHROME_THIRD_PARTY_XDG_USER_DIRS_XDG_USER_DIR_LOOKUP_H_ - -char* xdg_user_dir_lookup(const char *type); - -#endif // CHROME_THIRD_PARTY_XDG_USER_DIRS_XDG_USER_DIR_LOOKUP_H_ |