forked from bcxorg/onepixd
-
Notifications
You must be signed in to change notification settings - Fork 1
/
xml.c
77 lines (64 loc) · 1.46 KB
/
xml.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "onepixd.h"
static char *
xml_now(time_t now)
{
char nowbuf[128];
char *n;
struct tm *lt = NULL;
#if HAVE_LOCALTIME_R
struct tm tm;
#else
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
#endif
#if HAVE_LOCALTIME_R
lt = localtime_r(&now, &tm);
#else
(void) pthread_mutex_lock(&mutex);
lt = localtime(&now);
#endif
(void) strftime(nowbuf, sizeof nowbuf, "%a, %d %b %Y %T GMT", lt);
#if ! HAVE_LOCALTIME_R
(void) pthread_mutex_unlock(&mutex);
#endif
n = str_dup(nowbuf, __FILE__, __LINE__);
return n;
}
void
xml_header(char *x, size_t xlen)
{
time_t now;
char * cp;
if (x == NULL)
return;
now = time(NULL);
(void) strlcat(x, "<?xml version=\"1.0\" encoding=\"us-ascii\" ?>\r\n", xlen);
(void) strlcat(x, "<!-- generated by onepixd ", xlen);
(void) strlcat(x, VERSION, xlen);
(void) strlcat(x, " -->\r\n", xlen);
(void) strlcat(x, "<data>\r\n", xlen);
(void) strlcat(x, "<title>OnePixd Data Report</title>\r\n", xlen);
(void) strlcat(x, "<language>en-us</language>\r\n", xlen);
(void) strlcat(x, "<pubDate>", xlen);
cp = xml_now(now);
(void) strlcat(x, cp, xlen);
(void) strlcat(x, "</pubDate>\r\n", xlen);
cp = str_free(cp, __FILE__, __LINE__);
return;
}
void
xml_trailer(char *x, size_t xlen)
{
if (x == NULL)
return;
(void) strlcat(x, "</data>\r\n", xlen);
return;
}
char *
xml_path_to_datetime(char *path)
{
time_t date;
if (path == NULL)
return NULL;
date = file_path_to_time(path);
return xml_now(date);
}