summaryrefslogtreecommitdiff
path: root/protocols/Telegram/tdlib/td/tdutils/generate
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/Telegram/tdlib/td/tdutils/generate')
-rw-r--r--protocols/Telegram/tdlib/td/tdutils/generate/CMakeLists.txt20
-rw-r--r--protocols/Telegram/tdlib/td/tdutils/generate/generate_mime_types_gperf.cpp22
-rw-r--r--protocols/Telegram/tdlib/td/tdutils/generate/mime_types.txt28
3 files changed, 50 insertions, 20 deletions
diff --git a/protocols/Telegram/tdlib/td/tdutils/generate/CMakeLists.txt b/protocols/Telegram/tdlib/td/tdutils/generate/CMakeLists.txt
index 69697b04b8..69b42d9144 100644
--- a/protocols/Telegram/tdlib/td/tdutils/generate/CMakeLists.txt
+++ b/protocols/Telegram/tdlib/td/tdutils/generate/CMakeLists.txt
@@ -1,7 +1,13 @@
-cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
+if ((CMAKE_MAJOR_VERSION LESS 3) OR (CMAKE_VERSION VERSION_LESS "3.0.2"))
+ message(FATAL_ERROR "CMake >= 3.0.2 is required")
+endif()
# Generates files for MIME type <-> extension conversions
-# DEPENDS ON: gperf grep bash/powershell
+# DEPENDS ON: gperf grep
+
+if (NOT TDUTILS_MIME_TYPE)
+ return()
+endif()
file(MAKE_DIRECTORY auto)
@@ -19,7 +25,7 @@ add_custom_target(tdmime_auto DEPENDS ${TDMIME_SOURCE})
if (NOT CMAKE_CROSSCOMPILING)
find_program(GPERF_EXECUTABLE gperf)
if (NOT GPERF_EXECUTABLE)
- message(FATAL_ERROR "Could NOT find gperf. Path to gperf needs to be specified manually, i.e. 'cmake -DGPERF_EXECUTABLE:FILEPATH=\"<path to gperf executable>\" .')")
+ message(FATAL_ERROR "Could NOT find gperf. Add path to gperf executable to PATH environment variable or specify it manually using GPERF_EXECUTABLE option, i.e. 'cmake -DGPERF_EXECUTABLE:FILEPATH=\"<path to gperf executable>\"'.")
endif()
set(GPERF_FILES
@@ -38,7 +44,7 @@ if (NOT CMAKE_CROSSCOMPILING)
DEPENDS generate_mime_types_gperf mime_types.txt
)
- if (WIN32)
+ if (CMAKE_HOST_WIN32)
set(MIME_TYPE_TO_EXTENSION_CMD ${GPERF_EXECUTABLE} -m100 --output-file=auto/mime_type_to_extension.cpp auto/mime_type_to_extension.gperf)
else()
set(MIME_TYPE_TO_EXTENSION_CMD ${GPERF_EXECUTABLE} -m100 auto/mime_type_to_extension.gperf | grep -v __gnu_inline__ > auto/mime_type_to_extension.cpp)
@@ -47,10 +53,10 @@ if (NOT CMAKE_CROSSCOMPILING)
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/auto/mime_type_to_extension.cpp
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${MIME_TYPE_TO_EXTENSION_CMD}
- DEPENDS auto/mime_type_to_extension.gperf
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/auto/mime_type_to_extension.gperf
)
- if (WIN32)
+ if (CMAKE_HOST_WIN32)
set(EXTENSION_TO_MIME_TYPE_CMD ${GPERF_EXECUTABLE} -m100 --output-file=auto/extension_to_mime_type.cpp auto/extension_to_mime_type.gperf)
else()
set(EXTENSION_TO_MIME_TYPE_CMD ${GPERF_EXECUTABLE} -m100 auto/extension_to_mime_type.gperf | grep -v __gnu_inline__ > auto/extension_to_mime_type.cpp)
@@ -59,6 +65,6 @@ if (NOT CMAKE_CROSSCOMPILING)
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/auto/extension_to_mime_type.cpp
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${EXTENSION_TO_MIME_TYPE_CMD}
- DEPENDS auto/extension_to_mime_type.gperf
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/auto/extension_to_mime_type.gperf
)
endif()
diff --git a/protocols/Telegram/tdlib/td/tdutils/generate/generate_mime_types_gperf.cpp b/protocols/Telegram/tdlib/td/tdutils/generate/generate_mime_types_gperf.cpp
index ac7ff68605..44ab2bd1e9 100644
--- a/protocols/Telegram/tdlib/td/tdutils/generate/generate_mime_types_gperf.cpp
+++ b/protocols/Telegram/tdlib/td/tdutils/generate/generate_mime_types_gperf.cpp
@@ -1,5 +1,5 @@
//
-// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018
+// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -15,7 +15,7 @@
#include <utility>
#include <vector>
-std::pair<std::string, std::string> split(std::string s, char delimiter = ' ') {
+static std::pair<std::string, std::string> split(std::string s, char delimiter = ' ') {
auto delimiter_pos = s.find(delimiter);
if (delimiter_pos == std::string::npos) {
return {std::move(s), ""};
@@ -26,8 +26,8 @@ std::pair<std::string, std::string> split(std::string s, char delimiter = ' ') {
}
}
-bool generate(const char *file_name, const char *from_name, const char *to_name,
- const std::map<std::string, std::string> &map) {
+static bool generate(const char *file_name, const char *from_name, const char *to_name,
+ const std::map<std::string, std::string> &map) {
// binary mode is needed for MSYS2 gperf
std::ofstream out(file_name, std::ios_base::trunc | std::ios_base::binary);
if (!out) {
@@ -71,6 +71,10 @@ bool generate(const char *file_name, const char *from_name, const char *to_name,
return true;
}
+static bool is_private_mime_type(const std::string &mime_type) {
+ return mime_type.find("/x-") != std::string::npos;
+}
+
int main(int argc, char *argv[]) {
if (argc != 4) {
std::cerr << "Wrong number of arguments supplied. Expected 'generate_mime_types_gperf <mime_types.txt> "
@@ -112,7 +116,7 @@ int main(int argc, char *argv[]) {
std::vector<std::string> extensions;
while (!extensions_string.empty()) {
- extensions.push_back("");
+ extensions.emplace_back();
std::tie(extensions.back(), extensions_string) = split(extensions_string);
}
assert(!extensions.empty());
@@ -132,7 +136,13 @@ int main(int argc, char *argv[]) {
for (auto &extension : extensions) {
if (!extension_to_mime_type.emplace(extension, mime_type).second) {
- std::cerr << "Extension \"" << extension << "\" matches more than one type" << std::endl;
+ if (is_private_mime_type(extension_to_mime_type[extension]) == is_private_mime_type(mime_type)) {
+ std::cerr << "Extension \"" << extension << "\" matches more than one type" << std::endl;
+ } else {
+ if (!is_private_mime_type(mime_type)) {
+ extension_to_mime_type[extension] = mime_type;
+ }
+ }
}
}
}
diff --git a/protocols/Telegram/tdlib/td/tdutils/generate/mime_types.txt b/protocols/Telegram/tdlib/td/tdutils/generate/mime_types.txt
index a2d4abbf29..18dcfb775b 100644
--- a/protocols/Telegram/tdlib/td/tdutils/generate/mime_types.txt
+++ b/protocols/Telegram/tdlib/td/tdutils/generate/mime_types.txt
@@ -14,7 +14,7 @@ application/davmount+xml davmount
application/docbook+xml dbk
application/dssc+der dssc
application/dssc+xml xdssc
-application/ecmascript ecma
+application/ecmascript es
application/emma+xml emma
application/epub+zip epub
application/exi exi
@@ -498,6 +498,7 @@ application/x-dtbresource+xml res
application/x-dvi dvi
application/x-envoy evy
application/x-eva eva
+application/x-fictionbook+xml fb2
application/x-font-bdf bdf
application/x-font-ghostscript gsf
application/x-font-linux-psf psf
@@ -506,7 +507,7 @@ application/x-font-pcf pcf
application/x-font-snf snf
application/x-font-ttf ttf ttc
application/x-font-type1 pfa pfb pfm afm
-application/font-woff woff
+application/x-font-woff woff
application/x-freearc arc
application/x-futuresplash spl
application/x-gca-compressed gca
@@ -564,6 +565,8 @@ application/x-tex tex
application/x-tex-tfm tfm
application/x-texinfo texinfo texi
application/x-tgif obj
+application/x-tgsticker tgs
+application/x-tgwallpattern tgv
application/x-ustar ustar
application/x-wais-source src
application/x-x509-ca-cert der crt
@@ -589,9 +592,9 @@ application/zip zip
audio/adpcm adp
audio/basic au snd
audio/midi mid midi kar rmi
-audio/mp4 mp4a
+audio/mp4 m4a mp4a
audio/mpeg mpga mp2 mp2a mp3 m2a m3a
-audio/ogg oga ogg spx
+audio/ogg oga ogg opus spx
audio/s3m s3m
audio/silk sil
audio/vnd.dece.audio uva uvva
@@ -624,10 +627,19 @@ chemical/x-cmdf cmdf
chemical/x-cml cml
chemical/x-csml csml
chemical/x-xyz xyz
+font/collection ttc
+font/otf otf
+font/ttf ttf
+font/woff woff
+font/woff2 woff2
image/bmp bmp
image/cgm cgm
image/g3fax g3
image/gif gif
+image/heic heic
+image/heic-sequence heics
+image/heif heif
+image/heif-sequence heifs
image/ief ief
image/jpeg jpeg jpg jpe
image/ktx ktx
@@ -638,8 +650,8 @@ image/svg+xml svg svgz
image/tiff tiff tif
image/vnd.adobe.photoshop psd
image/vnd.dece.graphic uvi uvvi uvg uvvg
-image/vnd.dvb.subtitle sub
image/vnd.djvu djvu djv
+image/vnd.dvb.subtitle sub
image/vnd.dwg dwg
image/vnd.dxf dxf
image/vnd.fastbidsheet fbs
@@ -700,8 +712,8 @@ text/uri-list uri uris urls
text/vcard vcard
text/vnd.curl curl
text/vnd.curl.dcurl dcurl
-text/vnd.curl.scurl scurl
text/vnd.curl.mcurl mcurl
+text/vnd.curl.scurl scurl
text/vnd.dvb.subtitle sub
text/vnd.fly fly
text/vnd.fmi.flexstor flx
@@ -715,9 +727,10 @@ text/x-asm s asm
text/x-c c cc cxx cpp h hh dic
text/x-fortran f for f77 f90
text/x-java-source java
+text/x-nfo nfo
text/x-opml opml
text/x-pascal p pas
-text/x-nfo nfo
+text/x-php php
text/x-setext etx
text/x-sfv sfv
text/x-uuencode uu
@@ -728,6 +741,7 @@ video/3gpp2 3g2
video/h261 h261
video/h263 h263
video/h264 h264
+video/h265 h265
video/jpeg jpgv
video/jpm jpm jpgm
video/mj2 mj2 mjp2