aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2019-02-03 14:49:20 +0100
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2019-02-03 14:49:20 +0100
commitadca120fdf42d8285d10173d584abec6a08ab1fc (patch)
tree04a2b29ee93b520f81ed9aebd29345fe0f84a380 /src
parent8a749d44699853f1df894443065dbf794264c8fa (diff)
downloadblogc-adca120fdf42d8285d10173d584abec6a08ab1fc.tar.gz
blogc-adca120fdf42d8285d10173d584abec6a08ab1fc.tar.bz2
blogc-adca120fdf42d8285d10173d584abec6a08ab1fc.zip
blogc: added datetime template variable
Diffstat (limited to 'src')
-rw-r--r--src/blogc/funcvars.c4
-rw-r--r--src/blogc/sysinfo.c36
-rw-r--r--src/blogc/sysinfo.h6
3 files changed, 46 insertions, 0 deletions
diff --git a/src/blogc/funcvars.c b/src/blogc/funcvars.c
index 50abbb8..96bc3c5 100644
--- a/src/blogc/funcvars.c
+++ b/src/blogc/funcvars.c
@@ -30,6 +30,10 @@ static const struct func_map {
{"BLOGC_SYSINFO_HOSTNAME", blogc_sysinfo_inject_hostname},
#endif
+#ifdef HAVE_SYSINFO_DATETIME
+ {"BLOGC_SYSINFO_DATETIME", blogc_sysinfo_inject_datetime},
+#endif
+
{NULL, NULL},
};
diff --git a/src/blogc/sysinfo.c b/src/blogc/sysinfo.c
index 191f60e..d934483 100644
--- a/src/blogc/sysinfo.c
+++ b/src/blogc/sysinfo.c
@@ -14,6 +14,10 @@
#include <unistd.h>
#endif /* HAVE_UNISTD_H */
+#ifdef HAVE_TIME_H
+#include <time.h>
+#endif /* HAVE_TIME_H */
+
#include <stdlib.h>
#include "../common/utils.h"
#include "sysinfo.h"
@@ -45,3 +49,35 @@ blogc_sysinfo_inject_hostname(bc_trie_t *global)
bc_trie_insert(global, "BLOGC_SYSINFO_HOSTNAME", hostname);
}
+
+
+char*
+blogc_sysinfo_get_datetime(void)
+{
+#ifndef HAVE_SYSINFO_DATETIME
+ return NULL;
+#else
+ time_t tmp;
+ if (-1 == time(&tmp))
+ return NULL;
+
+ struct tm *t = gmtime(&tmp);
+
+ char buf[1024];
+ if (0 == strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", t))
+ return NULL;
+
+ return bc_strdup(buf);
+#endif
+}
+
+
+void
+blogc_sysinfo_inject_datetime(bc_trie_t *global)
+{
+ char *t = blogc_sysinfo_get_datetime();
+ if (t == NULL)
+ return;
+
+ bc_trie_insert(global, "BLOGC_SYSINFO_DATETIME", t);
+}
diff --git a/src/blogc/sysinfo.h b/src/blogc/sysinfo.h
index 0104911..f26662a 100644
--- a/src/blogc/sysinfo.h
+++ b/src/blogc/sysinfo.h
@@ -19,9 +19,15 @@
#endif /* HAVE_GETHOSTNAME */
#endif /* HAVE_UNISTD_H */
+#ifdef HAVE_TIME_H
+#define HAVE_SYSINFO_DATETIME 1
+#endif /* HAVE_TIME_H */
+
#include "../common/utils.h"
char* blogc_sysinfo_get_hostname(void);
void blogc_sysinfo_inject_hostname(bc_trie_t *global);
+char* blogc_sysinfo_get_datetime(void);
+void blogc_sysinfo_inject_datetime(bc_trie_t *global);
#endif /* ___SYSINFO_H */