GNUnet  0.10.x
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 #include "gnunet_fs_service.h"
28 #include "fs_api.h"
29 
30 
37 char *
39  *md)
40 {
41  static const char *mimeMap[][2] = {
42  {"application/bz2", ".bz2"},
43  {"application/gnunet-directory", ".gnd"},
44  {"application/java", ".class"},
45  {"application/msword", ".doc"},
46  {"application/nar", ".nar"},
47  {"application/narinfo", ".narinfo"},
48  {"application/ogg", ".ogg"},
49  {"application/pdf", ".pdf"},
50  {"application/pgp-keys", ".key"},
51  {"application/pgp-signature", ".pgp"},
52  {"application/postscript", ".ps"},
53  {"application/rar", ".rar"},
54  {"application/rtf", ".rtf"},
55  {"application/xml", ".xml"},
56  {"application/x-debian-package", ".deb"},
57  {"application/x-dvi", ".dvi"},
58  {"application/x-flac", ".flac"},
59  {"application/x-gzip", ".gz"},
60  {"application/x-java-archive", ".jar"},
61  {"application/x-java-vm", ".class"},
62  {"application/x-python-code", ".pyc"},
63  {"application/x-redhat-package-manager", ".rpm"},
64  {"application/x-rpm", ".rpm"},
65  {"application/x-tar", ".tar"},
66  {"application/x-tex-pk", ".pk"},
67  {"application/x-texinfo", ".texinfo"},
68  {"application/x-xcf", ".xcf"},
69  {"application/x-xfig", ".xfig"},
70  {"application/zip", ".zip"},
71 
72  {"audio/midi", ".midi"},
73  {"audio/mpeg", ".mp3"},
74  {"audio/real", ".rm"},
75  {"audio/x-wav", ".wav"},
76 
77  {"image/gif", ".gif"},
78  {"image/jpeg", ".jpg"},
79  {"image/pcx", ".pcx"},
80  {"image/png", ".png"},
81  {"image/tiff", ".tiff"},
82  {"image/x-ms-bmp", ".bmp"},
83  {"image/x-xpixmap", ".xpm"},
84 
85  {"text/css", ".css"},
86  {"text/html", ".html"},
87  {"text/plain", ".txt"},
88  {"text/rtf", ".rtf"},
89  {"text/x-c++hdr", ".h++"},
90  {"text/x-c++src", ".c++"},
91  {"text/x-chdr", ".h"},
92  {"text/x-csrc", ".c"},
93  {"text/x-java", ".java"},
94  {"text/x-moc", ".moc"},
95  {"text/x-pascal", ".pas"},
96  {"text/x-perl", ".pl"},
97  {"text/x-python", ".py"},
98  {"text/x-tex", ".tex"},
99 
100  {"video/avi", ".avi"},
101  {"video/mpeg", ".mpeg"},
102  {"video/quicktime", ".qt"},
103  {"video/real", ".rm"},
104  {"video/x-msvideo", ".avi"},
105  {NULL, NULL},
106  };
107  char *ret;
108  unsigned int i;
109  char *mime;
110  char *base;
111  const char *ext;
112 
113  ret =
116  if (ret != NULL)
117  return ret;
118  ext = NULL;
119  mime =
121  if (mime != NULL)
122  {
123  i = 0;
124  while ((mimeMap[i][0] != NULL) && (0 != strcmp (mime, mimeMap[i][0])))
125  i++;
126  if (mimeMap[i][1] == NULL)
128  _("Did not find mime type `%s' in extension list.\n"), mime);
129  else
130  ext = mimeMap[i][1];
131  GNUNET_free (mime);
132  }
133  base =
151  -1);
152  if ((base == NULL) && (ext == NULL))
153  return NULL;
154  if (base == NULL)
155  return GNUNET_strdup (ext);
156  if (ext == NULL)
157  return base;
158  GNUNET_asprintf (&ret, "%s%s", base, ext);
159  GNUNET_free (base);
160  return ret;
161 }
162 
163 
164 /* end of fs_misc.c */
char * GNUNET_FS_meta_data_suggest_filename(const struct GNUNET_CONTAINER_MetaData *md)
Suggest a filename based on given metadata.
Definition: fs_misc.c:38
char * GNUNET_CONTAINER_meta_data_get_by_type(const struct GNUNET_CONTAINER_MetaData *md, enum EXTRACTOR_MetaType type)
Get the first MD entry of the given type.
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
char * GNUNET_CONTAINER_meta_data_get_first_by_types(const struct GNUNET_CONTAINER_MetaData *md,...)
Get the first matching MD entry of the given types.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
Meta data to associate with a file, directory or namespace.
shared definitions for the FS library
#define GNUNET_log(kind,...)
#define GNUNET_free(ptr)
Wrapper around free.