Commit Graph

346 Commits

Author SHA1 Message Date
Andrew Pamment
e61ffe98c3 fix file size on web 2018-10-14 15:32:42 +10:00
Dan Cross
267dbf15b8 Clean up string logic in www_files.c.
Use stralloc() etc here.

Signed-off-by: Dan Cross <patchdev@fat-dragon.org>
2018-10-14 15:28:16 +10:00
Andrew Pamment
b500a450dd Couple of minor fixes
Duplicate string in www_email
fread returns number of elements read not number of bytes
Missing clear screen after my changing of strings
2018-10-14 10:46:52 +10:00
Dan Cross
303810acaa Trivial formatting cleanups
Just another clang-format run to catch regressions that
have snuck in via other patches.

Signed-off-by: Dan Cross <patchdev@fat-dragon.org>
2018-10-14 10:35:29 +10:00
Dan Cross
2de957db34 Modify HTML generation code to use stralloc.
Replace most remaining uses of sprintf() into a `buffer`
variable followed by realloc() and strcat() with direct
use of stralloc.

Signed-off-by: Dan Cross <patchdev@fat-dragon.org>
2018-10-14 10:35:23 +10:00
Dan Cross
42eb413c91 More changing formatting to use stralloc.
Specifically, change the www_last10 HTML rendering logic
to use stralloc and strftime().  This eliminates a lot of
duplication.

It would be easier to test this with a unit test if the
logic of reading the last10 entries from a file were
separated from the HTML rendering logic.  An area for
future enhancement.

Also start in on www_email.c, which is the last bastion
of significant realloc() use for page generation.  An
explicit goal is to get rid of unsafe string handling
functions such as strcpy, strcat, sprintf, etc.

Signed-off-by: Dan Cross <patchdev@fat-dragon.org>
2018-10-14 10:35:18 +10:00
Andrew Pamment
0ade566c11 fix for message sending 2018-10-13 20:14:31 +10:00
Andrew Pamment
0cbefa834f Merge branch 'master' of git.magickabbs.com:/home/andrew/repositories/MagickaBBS 2018-10-13 20:04:25 +10:00
Andrew Pamment
d9a350631c some fixes for area selection and message list header 2018-10-13 20:03:58 +10:00
Dan Cross
f2288e9cec More adoption of stralloc for string handling.
Signed-off-by: Dan Cross <patchdev@fat-dragon.org>
2018-10-13 10:22:44 +10:00
Dan Cross
7bf6e05170 Fix a buffer overflow in bluewave.c.
strcat()'ing a string onto the result of file2str()
will result in a buffer overflow, since file2str()
only allocates enough memory to hold the contents of
the file (plus a NUL terminator).  This happend in
`bluewave.c`.

Instead, use `file2stralloc` to read the contents of
that file into a stralloc, which we can stralloc_cats
onto without fear of overflow.

Signed-off-by: Dan Cross <patchdev@fat-dragon.org>
2018-10-13 10:22:40 +10:00
Dan Cross
aba49d7a20 Added file2stralloc to read a file directly into a stralloc.
Signed-off-by: Dan Cross <patchdev@fat-dragon.org>
2018-10-13 10:22:33 +10:00
Andrew Pamment
7986d00b71 another netbsd fix 2018-10-12 19:44:50 +10:00
Andrew Pamment
5b007071e3 fix netbsd makefile 2018-10-12 19:40:15 +10:00
Andrew Pamment
c3636ec6d5 More dragonfly fixes 2018-10-12 18:11:05 +10:00
Andrew Pamment
943d5c0e18 fix capitalization 2018-10-12 17:51:10 +10:00
Andrew Pamment
0b76ae3cb6 Fixes for dragonflybsd 2018-10-12 17:48:26 +10:00
Andrew Pamment
800e13009f Fix unending RE:re:re: etc 2018-10-12 17:25:30 +10:00
Andrew Pamment
d4329eb287 Makefile tweaks for sunos and macos 2018-10-12 15:58:29 +10:00
Andrew Pamment
40c52836f9 Fix a couple of bugs 2018-10-12 11:11:44 +10:00
Dan Cross
37bcd31ff2 Clean up some of the page generation logic in www_msgs.c.
More application of stralloc.  Needs to be tested.  :-)

Signed-off-by: Dan Cross <patchdev@fat-dragon.org>
2018-10-12 10:13:12 +10:00
Dan Cross
0a91165b07 Clean up blog code (particularly the www side).
Make `blog_load` return a ptr_vector which is
consumed by the code that uses blog entries.
Greatly clean up WWW page generation by using
stralloc and strftime and the ptr_vector
infrastructure.

Needs to be tested. :-)

Signed-off-by: Dan Cross <patchdev@fat-dragon.org>
2018-10-12 10:13:04 +10:00
Dan Cross
cf766e3e67 Trivial clang-format changes
Changes from a clang-format run.

Signed-off-by: Dan Cross <patchdev@fat-dragon.org>
2018-10-12 10:12:45 +10:00
Dan Cross
e548c94750 mail_menu.c: Remove external lines counter in editor.
The pointer vector maintaining `content` in `editor` already
keeps track of the number of lines and makes it available via
a call to `ptr_vector_len` (or one could look at th `len`
member of the ptr_vector struct...this is C, not some fancy
object oriented language with data hiding).  Delete the `lines`
local variable and just use ptr_vector_len where necessary.

Sorry; I should have done that in the first sweep through that
code.  My bad!

Signed-off-by: Dan Cross <patchdev@fat-dragon.org>
2018-10-12 10:12:36 +10:00
Andrew Pamment
37e728b749 Fix for line numbers on internal editor 2018-10-11 22:04:48 +10:00
Dan Cross
d8c32639e4 Trivial whitespace cleanups
Delete trailing whitespace at the ends of lines;
ensure files have newlines at the end.

Signed-off-by: Dan Cross <patchdev@fat-dragon.org>
2018-10-11 21:36:35 +10:00
Dan Cross
1c7849b724 Fix a bug in stralloc_starts() and add a test.
strcalloc_starts() should have tested the return value
of `memcmp` against 0 for equality.  Fixed and added a
test case.

As an aside, one might wonder how bugs like that are
creeping into well-tested code imported from other
projects?  The answer, specific to stralloc, is that
the original code was very specific to qmail, and used
a number of additional functions specific to qmail.

Rather than import half of qmail, the version imported
into Magicka has been reworked to, instead, use
standard C functions.  The process of modifying the
code gave rise to the opportunity for bugs to creep in.
Now that a unit testing framework is in place, we can
test things in isolation more easily and hopefully
catch such things BEFORE they are published to the
master repository.

Signed-off-by: Dan Cross <patchdev@fat-dragon.org>
2018-10-11 21:36:29 +10:00
Andrew Pamment
15d09ed57a Fix a couple of bugs, one in stralloc and one uninitialized ptr vector 2018-10-11 15:25:00 +10:00
Dan Cross
6d30116ed9 Import strlcpy/strlcat from OpenBSD, start using them.
strcpy()/strcat() are inherently dangerous, even when
used with great care.  strlcpy() and strlcat() are
much safer replacements, and are available from OpenBSD
under a very liberal license.  Import them and start
using them.

Between pointer vectors, malloz, stralloc and now
strlcpy/strlcat, Magicka has much safer, simpler and
more performant infrastructure for dealing with
strings and dynamic collections of various kinds.

Signed-off-by: Dan Cross <patchdev@fat-dragon.org>
2018-10-11 13:58:49 +10:00
Dan Cross
77bf763939 Start using stralloc.
Clean up a few web page generation functions.

Signed-off-by: Dan Cross <patchdev@fat-dragon.org>
2018-10-11 13:58:03 +10:00
Andrew Pamment
e196292503 Merge branch 'master' of ssh://git.magickabbs.com/home/andrew/repositories/MagickaBBS 2018-10-11 11:47:53 +10:00
Dan Cross
9a7ceeee3d Import a (modernized) version of djb's stralloc library.
Lots of code in Magicka is involved in dynamic string manipulation.
`stralloc` isn't a bad library for this sort of thing.

Note that this is complements, but doesn't replace, existing string
utilities.

Signed-off-by: Dan Cross <patchdev@fat-dragon.org>
2018-10-11 11:45:12 +10:00
Dan Cross
82b6ec3a3b More use of ptr_vector; avoid unnecessary copies.
Recast more code in terms of the ptr_vector abstraction.

The mail_menu.c code also made a lot of unnecessary copies
of strings.  For example, there was this code sequence:

    for (i = z; i < lines - 1; i++) {
            free(content[i]);
            content[i] = strdup(content[i + 1]);
    }
    free(content[i]);
    lines--;
    content = (char **)realloc(content, sizeof(char *) * lines);

Here, `content` represents an array of lines of text.
This code is removing an element from somewhere in that
array (possibly in the middle), and then shifting the
remaining elements over one position.

But observe the calls to `free` and `strdup` in the loop
body: the content is already dynamically allocated.  We
free whatever was in the selected position, and then make
*another copy* of the data in the next position to put
into the now-available slot in the array: repeat for the
remainder of the array's elements.

Instead, we could change this code to just shift things
down:

    free(content[z]);
    for (i = z; i < (lines - 1); ++i)
            content[i] = content[i + 1];
    --lines;
    ncontent = realloc(content, sizeof(char *) * lines);
    assert(ncontent == NULL);
    content = ncontent;

However, the ptr_vector abstraction provides us a function,
`ptr_vector_del` that deletes an element from the array and
returns the pointer, so we can rewrite this as simply:

    free(ptr_vector_del(&content, z));

No additional malloc()/free() required, which means less
pressure on the memory allocator and less copying of data.

Signed-off-by: Dan Cross <patchdev@fat-dragon.org>
2018-10-11 11:44:19 +10:00
Andrew Pamment
d80037d30e build magimail 2018-10-10 11:47:09 +10:00
Andrew Pamment
dd1b386ff8 fix the makefile fix 2018-10-10 11:30:01 +10:00
Andrew Pamment
38ace58668 fix build script 2018-10-10 11:22:38 +10:00
Andrew Pamment
f70565325e fix bug in new ptr vector append 2018-10-10 11:12:04 +10:00
Andrew Pamment
5e797ed2c3 change egcc to cc for FreeBSD 2018-10-10 10:36:24 +10:00
Dan Cross
f74c418f47 clang-format: Minor whitespace issues.
These are entirely my fault, sadly.

Signed-off-by: Dan Cross <patchdev@fat-dragon.org>
2018-10-10 10:26:48 +10:00
Dan Cross
54093060cb More cleanups.
More cleaning up construction of arrays of things.
Introduce a utility function called, `split_on_space`
that tokenizes a string on a space character; use
it in most places where `strtok()` had been called.

More use of the ptr_vector type.  Introduce a utility
function to get access to the pointers without consuming
the vector; this is used in the files code.

Signed-off-by: Dan Cross <patchdev@fat-dragon.org>
2018-10-10 10:25:47 +10:00
Dan Cross
540e359080 Cleanups and pointer vectors.
A repeated pattern in Magicka is to append to dynamically
sized arrays via malloc()/realloc().  Introduce the notion
of a "pointer vector": that is, a growable vector of
pointers, that can be reused to implement that logic more
safely and efficiently (this implementation uses power-of-two
growing).

Many malloc()/realloc() calls were not checked; these
assert() that the return value from realloc() is not NULL.

Add a method to consume the pointer vector: that is, realloc()
it to the current length and return the underlying pointers.

Make the `fmt` argument to dolog() const.
Include <sys/wait.h> in bluewave.c to squash a warning.

Signed-off-by: Dan Cross <patchdev@fat-dragon.org>
2018-10-10 10:25:42 +10:00
Dan Cross
4827dcf8e4 Add a pointer vector abstraction.
There are lots of places where we want a growable
vector of pointers.  Add one.

Signed-off-by: Dan Cross <patchdev@fat-dragon.org>
2018-10-10 10:25:37 +10:00
Dan Cross
fa014f3a88 Simplify dynamic memory management.
Add utility routines and use them to simplify the
use of dynamically allocated memory.

Signed-off-by: Dan Cross <patchdev@fat-dragon.org>
2018-10-10 10:25:29 +10:00
Dan Cross
187cf02903 More GNUmakefile cleanups.
With the normalization of magimail's Makefile,
we can further simplify this logic.

Integrate the WWW logic into GNUmakefile.common.

Remove the custom `Makefile.sunos` files: just
use a conditional in the Makefile.

Signed-off-by: Dan Cross <patchdev@fat-dragon.org>
2018-10-10 10:25:26 +10:00
Dan Cross
4ed5319798 Rewrite non-WWW makefiles.
Delegate most of the logic to a "common" GNUmakefile,
with each system-specific GNUmakefile only setting a
handful of necessary variables.

Signed-off-by: Dan Cross <patchdev@fat-dragon.org>
2018-10-10 10:22:26 +10:00
Dan Cross
120e947d6e Rename Makefiles to GNUmakefiles.
GNU make is a requirement to build Magicka: make
this explicit with the naming of the files.

Signed-off-by: Dan Cross <patchdev@fat-dragon.org>
2018-10-10 10:22:21 +10:00
Dan Cross
b28e003945 Chat system: simplify connect logic.
Simplify the logic around making connections in the
chat system by delegating to utility functions that
return early on failure.

Signed-off-by: Dan Cross <patchdev@fat-dragon.org>
2018-10-09 15:49:54 +10:00
Dan Cross
d6826137dd clang-format
Fix a bunch of trivial formatting issues by running
`clang-format`.

Signed-off-by: Dan Cross <patchdev@fat-dragon.org>
2018-10-09 15:48:42 +10:00
Dan Cross
ff966a6b4d clang-format
Fix a bunch of trivial formatting issues by running
`clang-format`.

Signed-off-by: Dan Cross <patchdev@fat-dragon.org>
2018-10-09 15:39:59 +10:00
Andrew Pamment
991b1c4368 Update to v0.12-alpha and add area headers 2018-10-04 10:05:04 +10:00
Andrew Pamment
1d1f83cd41 Redraw BBS List after aborting 2018-10-02 10:16:50 +10:00
Andrew Pamment
c36b8d348e Fix bug when removing areas 2018-09-12 10:16:07 +10:00
Andrew Pamment
a9c73f15a6 another fix 2018-09-02 18:27:22 +10:00
Andrew Pamment
db4eeff587 Fix for empty messages 2018-09-02 18:23:47 +10:00
Andrew Pamment
4cf5596737 documentation work and a bug fix 2018-08-13 14:07:21 +10:00
Andrew Pamment
1b661f4f5b Fiddling with unread messages 2018-07-31 10:42:56 +10:00
Andrew Pamment
ecb1c986f0 Start on qwknet support 2018-06-24 10:28:18 +10:00
Andrew Pamment
4b90398cbf Stop using system() 2018-06-20 19:39:57 +10:00
Andrew Pamment
c341df6738 Fix bluewave 2018-06-20 19:31:35 +10:00
Andrew Pamment
96ac7c0a3f Updates for macOS 2018-06-19 19:06:25 +10:00
Andrew Pamment
50f4b9a5a8 Move initialization of mqtt 2018-06-19 09:14:18 +10:00
Andrew Pamment
5853f46f5b Update documents etc 2018-06-19 09:11:52 +10:00
Andrew Pamment
1684f8ab39 Switch broadcast to MQTT 2018-06-18 16:52:27 +10:00
Andrew Pamment
760fef49b2 fix a bug with menus 2018-06-12 17:06:49 +10:00
Andrew Pamment
07b5568037 ansi files in strings 2018-06-08 09:27:53 +10:00
Andrew Pamment
edb1b41652 Git hooks suck 2018-06-05 15:27:53 +10:00
Andrew Pamment
d14af4bf23 i will get this soon 2018-06-05 15:24:42 +10:00
Andrew Pamment
f12630f7e5 Last test commit 2018-06-05 15:23:30 +10:00
Andrew Pamment
ffd1c546b8 Another test commit 2018-06-05 15:21:49 +10:00
Andrew Pamment
1feaa7d91e Another test commit 2018-06-05 15:19:41 +10:00
Andrew Pamment
b472f6448c Test commit, just whitespace 2018-06-05 15:15:14 +10:00
Andrew Pamment
732732a728 close iconv 2018-05-31 19:13:43 +10:00
Andrew Pamment
0f6af49071 move next and prev around 2018-05-31 14:00:18 +10:00
Andrew Pamment
5a1a834803 Remove redundant free 2018-05-31 09:59:26 +10:00
Andrew Pamment
0b8cc472d4 Fix bug in SSH 2018-05-31 09:56:01 +10:00
Andrew Pamment
a37329ff21 Fix message flagging in www 2018-05-30 16:21:55 +10:00
Andrew Pamment
efdd46f97a add PAUSE code to ansis 2018-05-27 13:07:07 +10:00
Andrew Pamment
56636843aa attempt to fix with openssl < 1.1.0 2018-05-26 12:57:50 +10:00
Andrew Pamment
834afccb57 Update password hashing to use evp functions 2018-05-26 12:35:06 +10:00
Andrew Pamment
5920963420 Fix for dragonfly 2018-05-26 11:48:06 +10:00
Andrew Pamment
6bce190c1a Just reconfigure all the things 2018-05-26 11:27:29 +10:00
Andrew Pamment
59967118e0 More fixes for building on Net/OpenBSD 2018-05-26 11:10:37 +10:00
Andrew Pamment
d92859ac5d Attempt to fix building on netbsd 2018-05-26 11:05:43 +10:00
Andrew Pamment
ce888d9ad1 maybe this time? 2018-05-25 22:44:44 +10:00
Andrew Pamment
1ec2bc02bd more messing with word wrap 2018-05-25 22:42:35 +10:00
Andrew Pamment
0ebdbe71b4 Messing with wordwrap 2018-05-25 22:38:11 +10:00
Andrew Pamment
759b5a3adb fix type 2018-05-25 22:30:54 +10:00
Andrew Pamment
23fb3df703 update to look prettier 2018-05-25 22:29:09 +10:00
Andrew Pamment
fb90c8b397 updated to include bbs name if known from nodelist 2018-05-25 22:26:22 +10:00
Andrew Pamment
9e816f05f6 Restore accidently deleted date from www messages 2018-05-25 21:39:29 +10:00
Andrew Pamment
8f948e59c4 attempt to fix openbsd compiling 2018-05-25 18:49:30 +10:00
Andrew Pamment
b6f328ffa3 Fix for iconv message 2018-05-23 19:45:55 +10:00
Andrew Pamment
e8c7b0cfec
Merge branch 'maginet' into v0.11-alpha 2018-05-23 17:24:29 +10:00
Andrew Pamment
11fe200797 use iconv in www msgs 2018-05-23 17:21:53 +10:00
Andrew Pamment
42fdc30972 maginet 2018-05-22 21:02:22 +10:00
Andrew Pamment
00703ab5e0 implement flagging on www 2018-05-22 12:20:38 +10:00
Andrew Pamment
f9b13fa515 fix flagging 2018-05-22 09:02:35 +10:00
Andrew Pamment
798bec221d Message Flagging 2018-05-22 08:55:44 +10:00
Andrew Pamment
275a60d0d4 Fix crash in mail menu 2018-05-16 13:44:04 +10:00
Andrew Pamment
ff35d9bec9 fix for www hashes on rpi 2018-05-15 16:44:39 +10:00