summaryrefslogtreecommitdiff
path: root/sfeed_frames.c
AgeCommit message (Collapse)Author
2023-05-07iterate on previous commit which adds $SFEED_NEW_MAX_SECSHiltjo Posthuma
Separate the common pattern to get the time to compare new items in format tools to the new util function: getcomparetime(). Some changes and notes: - Change it so it is OK to set this value to 0 or negative (in the future). - sfeed_curses: truncating newmaxsecs to an int would limit the value too much. - Just use strtotime() and parse the value to time_t. This is a signed long (32-bit, until 2038) or signed long long (64-bit) on most platforms. - sfeed_curses gets the comparison time on reload aswell and it needs errno = 0, because it uses die(). time() is not guaranteed to set an errno if it fails. - Rename environment variable to $SFEED_NEW_AGE.
2023-05-07sfeed_{curses,frames,gopher,html,plain}: SFEED_NEW_MAX_SECSAlvar Penning
By introducing the new environment variable $SFEED_NEW_MAX_SECS in all sfeed_* utilities marking feeds as new based on comparing their age, it is now possible to override this age limit. This allows, for example, to be notified about new feeds within the last hour with SFEED_NEW_MAX_SECS=3600 sfeed_plain ~/.sfeed/feeds/* while creating a beautiful web report for last week's news by SFEED_NEW_MAX_SECS=604800 sfeed_html ~/.sfeed/feeds/*
2022-03-27Revert "rm sys/types.h include and improve portability"Hiltjo Posthuma
This reverts commit db1dcafd03997127f2cbc82376e2cc8df9b77356. This is needed. Tested on an (old) Slackware 11 install.
2022-03-25rm sys/types.h include and improve portabilityHiltjo Posthuma
This include is not needed. It was intended for ssize_t but this is already defined by stdio.h for getline().
2022-03-15stricter error checking in file streams (input, output)Hiltjo Posthuma
This also makes the programs exit with a non-zero status when a read or write error occurs. This makes checking the exit status more reliable in scripts. A simple example to simulate a disk with no space left: curl -s 'https://codemadness.org/atom.xml' | sfeed > f /mnt/test: write failed, file system is full echo $? 0 Which now produces: curl -s 'https://codemadness.org/atom.xml' | sfeed > f /mnt/test: write failed, file system is full write error: <stdout> echo $? 1 Tested with a small mfs on OpenBSD, fstab entry: swap /mnt/test mfs rw,nodev,nosuid,-s=1M 0 0
2022-03-14improve time(NULL) error checkingHiltjo Posthuma
Use errx, time(NULL) does not set errno. For sfeed_curses reset errno so it doesn't print a random error if it failed. POSIX recommends checking against (time_t)-1 on failure. Note that some implementation, like the OpenBSD man page says time() cannot fail.
2021-06-01portability and standards: add BSD-like err() and errx() functionsHiltjo Posthuma
These are BSD functions. - HaikuOS now compiles without having to use libbsd. - Tested on SerenityOS (for fun), which doesn't have these functions (yet). With a small change to support wcwidth() sfeed works on SerenityOS.
2021-05-27sfeed_frames/sfeed_html: show the total counts and improve the title formatHiltjo Posthuma
This title format now matches the one with sfeed_curses. It shows the count to the most left and makes it more readable imho. It also works better when the titlebar is small.
2021-01-10optimize converting UNIX timestamp to localtimeHiltjo Posthuma
Make a huge difference (cuts the time in half to process the same amount of lines) on atleast glibc 2.30 on Void Linux. Seems to make no difference on OpenBSD. - This removes atleast one heap allocation per line (checked with valgrind). This is because glibc will strdup() the environment variable $TZ and free it each time, which is pointless here and wasteful. - localtime_r does not require to set the variables like tzname. In glibc-2.30/time/tzset.c in __tz_convert is the following code and comment: /* Update internal database according to current TZ setting. POSIX.1 8.3.7.2 says that localtime_r is not required to set tzname. This is a good idea since this allows at least a bit more parallelism. */ tzset_internal (tp == &_tmbuf && use_localtime); This makes it always tzset() and inspect the environment $TZ etc. While with localtime_r it will only initialize it once: static void tzset_internal (int always) { [...] if (is_initialized && !always) return;
2020-10-09fix counting due to uninitialized variable when the time could not be parsedHiltjo Posthuma
Since commit 276d5789fd91d1cbe84b7baee736dea28b1e04c0 if the time is empty or could not be parsed then it is shown/aligned as a blank space instead of being skipped. An oversight in this change was that items should be counted and set in `isnew`. This commit fixes the uninitialized variable and possible miscounting.
2020-07-05format tools: don't skip items with a missing/invalid timestamp fieldHiltjo Posthuma
Handle it appropriately in the context of each format tool. Output the item but keep it blanked. NOTE: maybe in sfeed_twtxt it should use the current time instead?
2020-06-21sfeed_html/sfeed_frames: simplify struct feed allocationHiltjo Posthuma
There's no need for a dynamic struct feed **. The required size is known (argc). Just allocate it in one go.
2020-04-01util: improve/cleanup parseline()Hiltjo Posthuma
- remove a check that has no use/can never happen. - remove the return value as it's unused and the input size is known. - fix an old comment that doesn't reflect what the function does anymore.
2020-03-11sfeed_html/sfeed_frames: fix bold markup for lynxHiltjo Posthuma
The previous style was not bold: <b><a href="">some link</a></b> The following link is now bold: <a href=""><b>some link</b></a>
2020-03-10sfeed_html/sfeed_frames: use a <pre> section per feedHiltjo Posthuma
This improves output with Dillo, w3m and possibly other simple browsers. - Dillo has a bug where it resets its block-style after <h2> when it is inside <pre>. Then it ignores newlines (inside <pre>) and the links are inlined. - w3m does not have a (line)margin for h2.
2020-01-24cleanup some includesHiltjo Posthuma
2019-04-30sfeed_frames, sfeed_html: use the same code for link handlingHiltjo Posthuma
2019-04-20sfeed_frames, sfeed_html: do not send referer headerHiltjo Posthuma
Do not send referer header if the browser supports this tag. This makes sure in some browsers where referer hiding is not setup this header is still hidden. The proper way is to setup your browser environment however to strip/change the referer header and trim your browser footprint.
2019-04-06sfeed_frames/sfeed_html: improve HTML output a bitHiltjo Posthuma
declare UTF-8 before <title>
2018-08-21sfeed_frames: stricter pledge when only reading from stdinHiltjo Posthuma
2018-08-16sfeed_frames: overhaulHiltjo Posthuma
sfeed_frames used to write HTML pages for each entry for each feed. This can be useful but had security issues, because the context of the content changes. sfeed_frames is now a HTML version which works better with browsers that don't support CSS or tables well like w3m and lynx. It is now an alternative for sfeed_html. - Don't reference and embed HTML content for security reasons. This was documented under "SECURITY CONSIDERATIONS" in the man page. - Tighten pledge(2). - Simplify
2018-02-18sfeed_frames: code-styleHiltjo Posthuma
2017-12-24format programs: ignore fields with an invalid timeHiltjo Posthuma
this makes sure tail -f with multiple files ignores the ==> file <== lines too.
2017-08-12add newline after </html>Hiltjo Posthuma
2017-04-27simplify pledge stubHiltjo Posthuma
2017-04-27compatiblity with browsers: use numeric entity for aposHiltjo Posthuma
this entity is XHTML, it is not supported by some (older) browsers.
2016-08-06sfeed_frames, sfeed_html: don't use HTML tablesHiltjo Posthuma
reasons: - HTML table rendering is extremely slow (invalidate because of resizing cells etc). - whitespace wrapping does not work properly in ancient browsers, links(1).
2016-08-06add USE_PLEDGE, remove pledge dummy functionHiltjo Posthuma
2016-04-12sfeed_frames: make content filename more unique: use UNIX timestamp in titleHiltjo Posthuma
this makes sure if an item has the same title but is posted or updated at a different time it will not overwrite the file.
2016-04-10sfeed_frames: dont make title of content a link if its emptyHiltjo Posthuma
2016-04-10remove basename, just use last part of the path...Hiltjo Posthuma
... as a bonus it also saves an allocation.
2016-03-29add time parsing to sfeed itself, remove time fieldHiltjo Posthuma
- less overhead (we only need GMT time) so no setenv("TZ", ...) tzset() crap. - timezone format (for example %z in strptime) is non-standard, this will add some lines of code and some complexity to our code though, but the trade-off is worth it imho.
2016-03-20sfeed_frames: also XML encode formatted time (just in case)Hiltjo Posthuma
2016-03-04sfeed_frames: use S_IR* names (portability), respect umaskHiltjo Posthuma
use 0777 and 0666 permissions, it will respect the process umask (generally 0022), so 0755 and 0644 effectively.
2016-03-04sfeed_frames: use mkdir and check errno EEXISTHiltjo Posthuma
no need to stat and then mkdir, this is a (theoretical) race-condition too.
2016-02-29sfeed_frames: no need to read from index files, mode "w+b" to "wb"Hiltjo Posthuma
2016-02-29sfeed_frames: whoops, set file permissions (else its 0000)Hiltjo Posthuma
2016-02-28sfeed_frames: add fattr to pledge...Hiltjo Posthuma
... it did not abort, but set it anyway. I think cpath implies fattr, it makes sense.
2016-02-28sfeed_frames: fix open file permission (write only).Hiltjo Posthuma
check errno EEXIST (file exist? -> ignore), handle other errno codes as errors. ... also make sure to fflush write before modifying file access and modification timestamps or it will be overwritten again.
2016-02-28sfeed_frames: fix TOCTTUO with access() and fopen()Hiltjo Posthuma
... and use futimens() in favor of deprecated utime(). a minor difference in behaviour is now filetimes are only updated when the file doesn't exist. minor cleanup: remove namelen, its variable was unused (reported by cppcheck).
2016-02-28null-terminate line at newline from getline()Hiltjo Posthuma
2016-02-27various improvementsHiltjo Posthuma
- pledge tools and add define to enable it on platforms that support it, currently only OpenBSD 5.9+ - separate getline and parseline functionality. - use murmur3 hash instead of jenkins1: faster and less collisions. - make some error messages a bit more clear, for example with path truncation. - some small cleanups, move printutf8pad to util.
2016-02-27remove some unneeded checksHiltjo Posthuma
2015-08-16code-style + no need to zero static variablesHiltjo Posthuma
2015-08-16code-style, wrap some lines, etcHiltjo Posthuma
2015-08-07util: strtotime: stricter time parsingHiltjo Posthuma
as input: an empty string or non-digit characters are digits are considered an error now. Still, for the format tools output the formatted time string as time_t 0 on a parse error.
2015-08-02sfeed_frames: wrap plain-text, encode as XML/HTML 2.0Hiltjo Posthuma
2015-08-02sfeed_frames: limit titles and feednames to 128 chars for filenamesHiltjo Posthuma
This prevents unnecessary path-truncation in some cases, with the side-effect it can overwrite items with the same title more often. We handle path truncation as a fatal error, so this was annoying.
2015-08-02sfeed_frames: normalizepath: dont start with replaced -, just ignoreHiltjo Posthuma
2015-08-02util: simplify parseline() and check t for strtotime().Hiltjo Posthuma