diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-04-27 18:33:54 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-04-27 18:33:54 +0000 |
commit | e68c2f2f25cce89321e97a332321150b67bd9c80 (patch) | |
tree | 140788e18f2506ac44404d9e7153337c3f3a6029 /src | |
parent | 27ed8fcbc85a361864948edb517d47804c2b5a56 (diff) | |
download | gnunet-e68c2f2f25cce89321e97a332321150b67bd9c80.tar.gz gnunet-e68c2f2f25cce89321e97a332321150b67bd9c80.zip |
new expiration api
Diffstat (limited to 'src')
-rw-r--r-- | src/fs/fs_misc.c | 50 | ||||
-rw-r--r-- | src/include/gnunet_fs_service.h | 16 |
2 files changed, 66 insertions, 0 deletions
diff --git a/src/fs/fs_misc.c b/src/fs/fs_misc.c index e6c4eeea9..823cd33c4 100644 --- a/src/fs/fs_misc.c +++ b/src/fs/fs_misc.c | |||
@@ -162,4 +162,54 @@ GNUNET_FS_meta_data_suggest_filename (const struct GNUNET_CONTAINER_MetaData *md | |||
162 | return ret; | 162 | return ret; |
163 | } | 163 | } |
164 | 164 | ||
165 | |||
166 | /** | ||
167 | * Return the current year (i.e. '2011'). | ||
168 | */ | ||
169 | unsigned int | ||
170 | GNUNET_FS_get_current_year () | ||
171 | { | ||
172 | time_t tp; | ||
173 | |||
174 | tp = time (NULL); | ||
175 | t = gmtime (&tp); | ||
176 | if (t == NULL) | ||
177 | return 0; | ||
178 | return t->tm_year + 1900; | ||
179 | } | ||
180 | |||
181 | |||
182 | /** | ||
183 | * Convert a year to an expiration time of January 1st of that year. | ||
184 | * | ||
185 | * @param year a year (after 1970, please ;-)). | ||
186 | * @return absolute time for January 1st of that year. | ||
187 | */ | ||
188 | struct GNUNET_TIME_Absolute | ||
189 | GNUNET_FS_year_to_time (unsigned int year) | ||
190 | { | ||
191 | struct GNUNET_TIME_Absolute ret; | ||
192 | time_t tp; | ||
193 | struct tm t; | ||
194 | |||
195 | memset (&t, 0, sizeof (t)); | ||
196 | if (year < 1900) | ||
197 | { | ||
198 | GNUNET_break (0); | ||
199 | return GNUNET_TIME_absolute_get (); /* now */ | ||
200 | } | ||
201 | t.tm_year = year - 1900; | ||
202 | t.tm_mday = 1; | ||
203 | t.tm_mon = 1; | ||
204 | t.tm_wday = 1; | ||
205 | t.tm_yday = 1; | ||
206 | tp = mktime (&t); | ||
207 | GNUNET_break (tp != (time_t) -1); | ||
208 | ret.abs_value = tp * 1000LL; /* seconds to ms */ | ||
209 | return ret; | ||
210 | } | ||
211 | |||
212 | |||
213 | |||
214 | |||
165 | /* end of fs_misc.c */ | 215 | /* end of fs_misc.c */ |
diff --git a/src/include/gnunet_fs_service.h b/src/include/gnunet_fs_service.h index 8238083b1..13b0cd2c5 100644 --- a/src/include/gnunet_fs_service.h +++ b/src/include/gnunet_fs_service.h | |||
@@ -1618,6 +1618,22 @@ struct GNUNET_FS_BlockOptions | |||
1618 | }; | 1618 | }; |
1619 | 1619 | ||
1620 | 1620 | ||
1621 | /** | ||
1622 | * Return the current year (i.e. '2011'). | ||
1623 | */ | ||
1624 | unsigned int | ||
1625 | GNUNET_FS_get_current_year (void); | ||
1626 | |||
1627 | |||
1628 | /** | ||
1629 | * Convert a year to an expiration time of January 1st of that year. | ||
1630 | * | ||
1631 | * @param year a year (after 1970, please ;-)). | ||
1632 | * @return absolute time for January 1st of that year. | ||
1633 | */ | ||
1634 | struct GNUNET_TIME_Absolute | ||
1635 | GNUNET_FS_year_to_time (unsigned int year); | ||
1636 | |||
1621 | 1637 | ||
1622 | /** | 1638 | /** |
1623 | * Handle to the file-sharing service. | 1639 | * Handle to the file-sharing service. |