+/**
+ * Export a single trustchain to a path
+ */
+static void export_csv(private_certexpire_export_t *this, char *path,
+ hashtable_t *chains)
+{
+ enumerator_t *enumerator;
+ char buf[PATH_MAX];
+ entry_t *entry;
+ FILE *file;
+ struct tm tm;
+ time_t t;
+ int i;
+
+ t = time(NULL);
+ localtime_r(&t, &tm);
+
+ strftime(buf, sizeof(buf), path, &tm);
+ file = fopen(buf, "a");
+ if (file)
+ {
+ DBG1(DBG_CFG, "exporting expiration dates of %d trustchain%s to '%s'",
+ chains->get_count(chains),
+ chains->get_count(chains) == 1 ? "" : "s", buf);
+ this->mutex->lock(this->mutex);
+ enumerator = chains->create_enumerator(chains);
+ while (enumerator->enumerate(enumerator, NULL, &entry))
+ {
+ fprintf(file, "%s%s", entry->id, this->separator);
+ for (i = 0; i < MAX_TRUSTCHAIN_LENGTH; i++)
+ {
+ if (entry->expire[i])
+ {
+ localtime_r(&entry->expire[i], &tm);
+ strftime(buf, sizeof(buf), this->format, &tm);
+ fprintf(file, "%s", buf);
+ }
+ if (i == MAX_TRUSTCHAIN_LENGTH - 1)
+ {
+ fprintf(file, "\n");
+ }
+ else if (this->fixed_fields || entry->expire[i])
+ {
+ fprintf(file, "%s", this->separator);
+ }
+ }
+ chains->remove_at(chains, enumerator);
+ free(entry);
+ }
+ enumerator->destroy(enumerator);
+ this->mutex->unlock(this->mutex);
+ fclose(file);
+ }
+ else
+ {
+ DBG1(DBG_CFG, "opening CSV file '%s' failed: %s", buf, strerror(errno));
+ }
+}
+
+/**
+ * Export cached trustchain expiration dates to CSV files
+ */
+static void cron_export(private_certexpire_export_t *this)
+{
+ if (this->local_path)
+ {
+ export_csv(this, this->local_path, this->local);
+ }
+ if (this->remote_path)
+ {
+ export_csv(this, this->remote_path, this->remote);
+ }
+}
+