2 This file is part of GNUnet.
3 (C) 2010, 2011 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @brief misc. functions related to file-sharing in general
23 * @author Christian Grothoff
26 #include "gnunet_constants.h"
27 #include "gnunet_fs_service.h"
32 * Suggest a filename based on given metadata.
34 * @param md given meta data
35 * @return NULL if meta data is useless for suggesting a filename
38 GNUNET_FS_meta_data_suggest_filename (const struct GNUNET_CONTAINER_MetaData *md)
40 static const char *mimeMap[][2] = {
41 {"application/bz2", ".bz2"},
42 {"application/gnunet-directory", ".gnd"},
43 {"application/java", ".class"},
44 {"application/msword", ".doc"},
45 {"application/ogg", ".ogg"},
46 {"application/pdf", ".pdf"},
47 {"application/pgp-keys", ".key"},
48 {"application/pgp-signature", ".pgp"},
49 {"application/postscript", ".ps"},
50 {"application/rar", ".rar"},
51 {"application/rtf", ".rtf"},
52 {"application/xml", ".xml"},
53 {"application/x-debian-package", ".deb"},
54 {"application/x-dvi", ".dvi"},
55 {"applixation/x-flac", ".flac"},
56 {"applixation/x-gzip", ".gz"},
57 {"application/x-java-archive", ".jar"},
58 {"application/x-java-vm", ".class"},
59 {"application/x-python-code", ".pyc"},
60 {"application/x-redhat-package-manager", ".rpm"},
61 {"application/x-rpm", ".rpm"},
62 {"application/x-tar", ".tar"},
63 {"application/x-tex-pk", ".pk"},
64 {"application/x-texinfo", ".texinfo"},
65 {"application/x-xcf", ".xcf"},
66 {"application/x-xfig", ".xfig"},
67 {"application/zip", ".zip"},
69 {"audio/midi", ".midi"},
70 {"audio/mpeg", ".mp3"},
71 {"audio/real", ".rm"},
72 {"audio/x-wav", ".wav"},
74 {"image/gif", ".gif"},
75 {"image/jpeg", ".jpg"},
76 {"image/pcx", ".pcx"},
77 {"image/png", ".png"},
78 {"image/tiff", ".tiff"},
79 {"image/x-ms-bmp", ".bmp"},
80 {"image/x-xpixmap", ".xpm"},
83 {"text/html", ".html"},
84 {"text/plain", ".txt"},
86 {"text/x-c++hdr", ".h++"},
87 {"text/x-c++src", ".c++"},
88 {"text/x-chdr", ".h"},
89 {"text/x-csrc", ".c"},
90 {"text/x-java", ".java"},
91 {"text/x-moc", ".moc"},
92 {"text/x-pascal", ".pas"},
93 {"text/x-perl", ".pl"},
94 {"text/x-python", ".py"},
95 {"text/x-tex", ".tex"},
97 {"video/avi", ".avi"},
98 {"video/mpeg", ".mpeg"},
99 {"video/quicktime", ".qt"},
100 {"video/real", ".rm"},
101 {"video/x-msvideo", ".avi"},
110 ret = GNUNET_CONTAINER_meta_data_get_by_type (md,
111 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
115 mime = GNUNET_CONTAINER_meta_data_get_by_type (md,
116 EXTRACTOR_METATYPE_MIMETYPE);
120 while ( (mimeMap[i][0] != NULL) &&
121 (0 != strcmp (mime, mimeMap[i][0])))
123 if (mimeMap[i][1] == NULL)
124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG |
125 GNUNET_ERROR_TYPE_BULK,
126 _("Did not find mime type `%s' in extension list.\n"),
132 base = GNUNET_CONTAINER_meta_data_get_first_by_types (md,
133 EXTRACTOR_METATYPE_TITLE,
134 EXTRACTOR_METATYPE_BOOK_TITLE,
135 EXTRACTOR_METATYPE_ORIGINAL_TITLE,
136 EXTRACTOR_METATYPE_PACKAGE_NAME,
137 EXTRACTOR_METATYPE_URL,
138 EXTRACTOR_METATYPE_URI,
139 EXTRACTOR_METATYPE_DESCRIPTION,
140 EXTRACTOR_METATYPE_ISRC,
141 EXTRACTOR_METATYPE_JOURNAL_NAME,
142 EXTRACTOR_METATYPE_AUTHOR_NAME,
143 EXTRACTOR_METATYPE_SUBJECT,
144 EXTRACTOR_METATYPE_ALBUM,
145 EXTRACTOR_METATYPE_ARTIST,
146 EXTRACTOR_METATYPE_KEYWORDS,
147 EXTRACTOR_METATYPE_COMMENT,
148 EXTRACTOR_METATYPE_UNKNOWN,
150 if ( (base == NULL) &&
154 return GNUNET_strdup (ext);
157 GNUNET_asprintf (&ret,
167 * Return the current year (i.e. '2011').
170 GNUNET_FS_get_current_year ()
179 return t->tm_year + 1900;
184 * Convert a year to an expiration time of January 1st of that year.
186 * @param year a year (after 1970, please ;-)).
187 * @return absolute time for January 1st of that year.
189 struct GNUNET_TIME_Absolute
190 GNUNET_FS_year_to_time (unsigned int year)
192 struct GNUNET_TIME_Absolute ret;
196 memset (&t, 0, sizeof (t));
200 return GNUNET_TIME_absolute_get (); /* now */
202 t.tm_year = year - 1900;
208 GNUNET_break (tp != (time_t) -1);
209 ret.abs_value = tp * 1000LL; /* seconds to ms */
216 /* end of fs_misc.c */