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
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/ogg", ".ogg"},
47 {"application/pdf", ".pdf"},
48 {"application/pgp-keys", ".key"},
49 {"application/pgp-signature", ".pgp"},
50 {"application/postscript", ".ps"},
51 {"application/rar", ".rar"},
52 {"application/rtf", ".rtf"},
53 {"application/xml", ".xml"},
54 {"application/x-debian-package", ".deb"},
55 {"application/x-dvi", ".dvi"},
56 {"applixation/x-flac", ".flac"},
57 {"applixation/x-gzip", ".gz"},
58 {"application/x-java-archive", ".jar"},
59 {"application/x-java-vm", ".class"},
60 {"application/x-python-code", ".pyc"},
61 {"application/x-redhat-package-manager", ".rpm"},
62 {"application/x-rpm", ".rpm"},
63 {"application/x-tar", ".tar"},
64 {"application/x-tex-pk", ".pk"},
65 {"application/x-texinfo", ".texinfo"},
66 {"application/x-xcf", ".xcf"},
67 {"application/x-xfig", ".xfig"},
68 {"application/zip", ".zip"},
70 {"audio/midi", ".midi"},
71 {"audio/mpeg", ".mp3"},
72 {"audio/real", ".rm"},
73 {"audio/x-wav", ".wav"},
75 {"image/gif", ".gif"},
76 {"image/jpeg", ".jpg"},
77 {"image/pcx", ".pcx"},
78 {"image/png", ".png"},
79 {"image/tiff", ".tiff"},
80 {"image/x-ms-bmp", ".bmp"},
81 {"image/x-xpixmap", ".xpm"},
84 {"text/html", ".html"},
85 {"text/plain", ".txt"},
87 {"text/x-c++hdr", ".h++"},
88 {"text/x-c++src", ".c++"},
89 {"text/x-chdr", ".h"},
90 {"text/x-csrc", ".c"},
91 {"text/x-java", ".java"},
92 {"text/x-moc", ".moc"},
93 {"text/x-pascal", ".pas"},
94 {"text/x-perl", ".pl"},
95 {"text/x-python", ".py"},
96 {"text/x-tex", ".tex"},
98 {"video/avi", ".avi"},
99 {"video/mpeg", ".mpeg"},
100 {"video/quicktime", ".qt"},
101 {"video/real", ".rm"},
102 {"video/x-msvideo", ".avi"},
112 GNUNET_CONTAINER_meta_data_get_by_type (md,
113 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
118 GNUNET_CONTAINER_meta_data_get_by_type (md, EXTRACTOR_METATYPE_MIMETYPE);
122 while ((mimeMap[i][0] != NULL) && (0 != strcmp (mime, mimeMap[i][0])))
124 if (mimeMap[i][1] == NULL)
125 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
126 _("Did not find mime type `%s' in extension list.\n"), mime);
132 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) && (ext == NULL))
153 return GNUNET_strdup (ext);
156 GNUNET_asprintf (&ret, "%s%s", base, ext);
163 * Return the current year (i.e. '2011').
166 GNUNET_FS_get_current_year ()
175 return t->tm_year + 1900;
180 * Convert a year to an expiration time of January 1st of that year.
182 * @param year a year (after 1970, please ;-)).
183 * @return absolute time for January 1st of that year.
185 struct GNUNET_TIME_Absolute
186 GNUNET_FS_year_to_time (unsigned int year)
188 struct GNUNET_TIME_Absolute ret;
192 memset (&t, 0, sizeof (t));
196 return GNUNET_TIME_absolute_get (); /* now */
198 t.tm_year = year - 1900;
204 GNUNET_break (tp != (time_t) - 1);
205 ret.abs_value = tp * 1000LL; /* seconds to ms */
211 * Convert an expiration time to the respective year (rounds)
213 * @param at absolute time
214 * @return year a year (after 1970), 0 on error
217 GNUNET_FS_time_to_year (struct GNUNET_TIME_Absolute at)
222 tp = at.abs_value / 1000; /* ms to seconds */
226 return t->tm_year + 1900;
231 /* end of fs_misc.c */