1 /* agg - the news aggregator
2 * Copyright (C) 2011 Andreas Waidler <arandes@programmers.at>
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
31 char feed_title
[TEXT_BUFFER_SIZE
] = { 0 };
33 time_t feed_date_new
= 0;
34 bool feed_is_open
= false;
36 char item_title
[TEXT_BUFFER_SIZE
] = { 0 };
37 char item_link
[TEXT_BUFFER_SIZE
] = { 0 };
38 char item_desc
[TEXT_BUFFER_SIZE
] = { 0 };
41 void sanitize(char* str
)
44 while ((evil
= strchr(str
, '/'))) *evil
= '\\';
47 void set_item_date(const char* date
)
50 assert(strptime(date
, "%a, %d %b %Y %T %z", &t
));
51 item_date
= mktime(&t
);
52 assert(item_date
!= -1);
53 if (item_date
<= feed_date
) {
54 printf("No new feeds assumed.\n");
56 } else if (item_date
> feed_date_new
) {
57 feed_date_new
= item_date
;
61 void set_item_link(const char* link
)
63 strncpy(item_link
, link
, TEXT_BUFFER_SIZE
);
66 void set_item_desc(const char* desc
)
68 strncpy(item_desc
, desc
, TEXT_BUFFER_SIZE
);
71 void set_item_title(const char* title
)
73 strncpy(item_title
, title
, TEXT_BUFFER_SIZE
);
77 const char* get_item_title()
82 void feed_open(const char* title
)
86 strncpy(feed_title
, title
, TEXT_BUFFER_SIZE
);
89 if (!stat(feed_title
, &st
)) feed_date
= st
.st_mtime
;
90 mkdir(feed_title
, 0755);
91 assert(!chdir(feed_title
));
99 struct timeval times
[2];
100 times
[0].tv_sec
= feed_date_new
;
101 times
[0].tv_usec
= 0;
102 times
[1].tv_sec
= feed_date_new
;
103 times
[1].tv_usec
= 0;
105 if (!feed_is_open
) return;
107 assert(!chdir(".."));
108 assert(!utimes(feed_title
, times
));
109 feed_is_open
= false;
114 struct timeval times
[2];
116 char buf
[FILE_NAME_LENGTH
+ 1] = { 0 };
117 assert(feed_is_open
);
120 strncpy(buf
, item_title
, FILE_NAME_LENGTH
);
122 assert(item_desc
[0]);
123 strncpy(buf
, item_desc
, FILE_NAME_LENGTH
);
126 assert(f
= fopen(buf
, "w"));
128 fprintf(f
, "%s\n\n", item_title
);
131 fprintf(f
, "%s\n\n", item_desc
);
134 fprintf(f
, "Link: <a href=\"%s\">%s</a>\n", item_link
, item_link
);
138 /* FIXME: item date might not have been set. */
139 times
[0].tv_sec
= item_date
;
140 times
[0].tv_usec
= 0;
141 times
[1].tv_sec
= item_date
;
142 times
[1].tv_usec
= 0;
144 assert(!utimes(buf
, times
));