GNUnet  0.19.5
fs_misc.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2010, 2011, 2017 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
25 #include "platform.h"
26 #include "gnunet_constants.h"
27 
28 #include "gnunet_fs_service.h"
29 #include "fs_api.h"
30 
31 
38 char *
40  *md)
41 {
42  static const char *mimeMap[][2] = {
43  { "application/bz2", ".bz2" },
44  { "application/gnunet-directory", ".gnd" },
45  { "application/java", ".class" },
46  { "application/msword", ".doc" },
47  { "application/nar", ".nar" },
48  { "application/narinfo", ".narinfo" },
49  { "application/ogg", ".ogg" },
50  { "application/pdf", ".pdf" },
51  { "application/pgp-keys", ".key" },
52  { "application/pgp-signature", ".pgp" },
53  { "application/postscript", ".ps" },
54  { "application/rar", ".rar" },
55  { "application/rtf", ".rtf" },
56  { "application/xml", ".xml" },
57  { "application/x-debian-package", ".deb" },
58  { "application/x-dvi", ".dvi" },
59  { "application/x-flac", ".flac" },
60  { "application/x-gzip", ".gz" },
61  { "application/x-java-archive", ".jar" },
62  { "application/x-java-vm", ".class" },
63  { "application/x-python-code", ".pyc" },
64  { "application/x-redhat-package-manager", ".rpm" },
65  { "application/x-rpm", ".rpm" },
66  { "application/x-tar", ".tar" },
67  { "application/x-tex-pk", ".pk" },
68  { "application/x-texinfo", ".texinfo" },
69  { "application/x-xcf", ".xcf" },
70  { "application/x-xfig", ".xfig" },
71  { "application/zip", ".zip" },
72 
73  { "audio/midi", ".midi" },
74  { "audio/mpeg", ".mp3" },
75  { "audio/real", ".rm" },
76  { "audio/x-wav", ".wav" },
77 
78  { "image/gif", ".gif" },
79  { "image/jpeg", ".jpg" },
80  { "image/pcx", ".pcx" },
81  { "image/png", ".png" },
82  { "image/tiff", ".tiff" },
83  { "image/x-ms-bmp", ".bmp" },
84  { "image/x-xpixmap", ".xpm" },
85 
86  { "text/css", ".css" },
87  { "text/html", ".html" },
88  { "text/plain", ".txt" },
89  { "text/rtf", ".rtf" },
90  { "text/x-c++hdr", ".h++" },
91  { "text/x-c++src", ".c++" },
92  { "text/x-chdr", ".h" },
93  { "text/x-csrc", ".c" },
94  { "text/x-java", ".java" },
95  { "text/x-moc", ".moc" },
96  { "text/x-pascal", ".pas" },
97  { "text/x-perl", ".pl" },
98  { "text/x-python", ".py" },
99  { "text/x-tex", ".tex" },
100 
101  { "video/avi", ".avi" },
102  { "video/mpeg", ".mpeg" },
103  { "video/quicktime", ".qt" },
104  { "video/real", ".rm" },
105  { "video/x-msvideo", ".avi" },
106  { NULL, NULL },
107  };
108  char *ret;
109  unsigned int i;
110  char *mime;
111  char *base;
112  const char *ext;
113 
114  ret =
117  if (ret != NULL)
118  return ret;
119  ext = NULL;
120  mime =
121  GNUNET_FS_meta_data_get_by_type (md, EXTRACTOR_METATYPE_MIMETYPE);
122  if (mime != NULL)
123  {
124  i = 0;
125  while ((mimeMap[i][0] != NULL) && (0 != strcmp (mime, mimeMap[i][0])))
126  i++;
127  if (mimeMap[i][1] == NULL)
129  _ ("Did not find mime type `%s' in extension list.\n"), mime);
130  else
131  ext = mimeMap[i][1];
132  GNUNET_free (mime);
133  }
134  base =
136  EXTRACTOR_METATYPE_TITLE,
137  EXTRACTOR_METATYPE_BOOK_TITLE,
138  EXTRACTOR_METATYPE_ORIGINAL_TITLE,
139  EXTRACTOR_METATYPE_PACKAGE_NAME,
140  EXTRACTOR_METATYPE_URL,
141  EXTRACTOR_METATYPE_URI,
142  EXTRACTOR_METATYPE_DESCRIPTION,
143  EXTRACTOR_METATYPE_ISRC,
144  EXTRACTOR_METATYPE_JOURNAL_NAME,
145  EXTRACTOR_METATYPE_AUTHOR_NAME,
146  EXTRACTOR_METATYPE_SUBJECT,
147  EXTRACTOR_METATYPE_ALBUM,
148  EXTRACTOR_METATYPE_ARTIST,
149  EXTRACTOR_METATYPE_KEYWORDS,
150  EXTRACTOR_METATYPE_COMMENT,
151  EXTRACTOR_METATYPE_UNKNOWN,
152  -1);
153  if ((base == NULL) && (ext == NULL))
154  return NULL;
155  if (base == NULL)
156  return GNUNET_strdup (ext);
157  if (ext == NULL)
158  return base;
159  GNUNET_asprintf (&ret, "%s%s", base, ext);
160  GNUNET_free (base);
161  return ret;
162 }
163 
164 
165 /* end of fs_misc.c */
shared definitions for the FS library
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
API for file sharing via GNUnet.
#define EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME
char * GNUNET_FS_meta_data_suggest_filename(const struct GNUNET_FS_MetaData *md)
Suggest a filename based on given metadata.
Definition: fs_misc.c:39
#define GNUNET_log(kind,...)
@ GNUNET_ERROR_TYPE_BULK
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_free(ptr)
Wrapper around free.
char * GNUNET_FS_meta_data_get_by_type(const struct GNUNET_FS_MetaData *md, enum EXTRACTOR_MetaType type)
Get the first MD entry of the given type.
Definition: meta_data.c:443
char * GNUNET_FS_meta_data_get_first_by_types(const struct GNUNET_FS_MetaData *md,...)
Get the first matching MD entry of the given types.
Definition: meta_data.c:461
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
Meta data to associate with a file, directory or namespace.
Definition: meta_data.c:97