Skip to content

Commit

Permalink
v5.36
Browse files Browse the repository at this point in the history
  • Loading branch information
Colum Paget committed Feb 4, 2025
1 parent c19b3e5 commit 8d0f7f5
Show file tree
Hide file tree
Showing 14 changed files with 239 additions and 126 deletions.
13 changes: 11 additions & 2 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
v5.36
* Restructure XMLGetTag and ensure whitespace is preserved in data between tags
* Properly implement 'websocket frame too big', closing connection when this happens
* Websocket code no longer outputs http debugging.
* Handle prompt/prefix in new 'LineEdit' based TerminalReadLine
* Ensure CopyStr/CatStr return allocated memory even if both dst and src start as null
* Handle 'Stolen characters' after unicode in TerminalPutStr
* More work on LineEdit.c

v5.35
* Added LineEdit.c for full line editing with history
* Handle 'bigframes' in Websocket.c
Expand Down Expand Up @@ -27,7 +36,7 @@ v5.31 (2024-12-20)

v5.30 (2024-10-29)
* Fix crash if TerminalTextAlign has NULL for the Terminal
* Added HttpGet and HttpPost functions
* Added HttpGet and HttpPost functions
* Improvements to httpserver authentication.
* Add 'extra' field to passwords file to allow storing data against a user.

Expand Down Expand Up @@ -165,6 +174,6 @@ v5.5 (2024-01-13)
* fixes/improvements for 'PipeSpawn'
* copy file permissions when FileCopy
* handle SUPER key in terminal functions
* lots of work on Ouath and experimental websocket and http servers
* lots of work on OAuth and experimental websocket and http servers


1 change: 1 addition & 0 deletions GeneralFunctions.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ int xsetenv(const char *Name, const char *Value)
return(FALSE);
}

//increment ptr but don't go past '\0'
int ptr_incr(const char **ptr, int count)
{
const char *end;
Expand Down
1 change: 1 addition & 0 deletions KeyCodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Copyright (c) 2015 Colum Paget <[email protected]>
#define TKEY_ESCAPE 0x1b
#define TKEY_TAB ' '
#define TKEY_BACKSPACE 0x08
#define TKEY_ERASE 0x7f

#ifndef TKEY_ENTER
#define TKEY_ENTER '\n'
Expand Down
3 changes: 3 additions & 0 deletions LibSettings.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ void LibUsefulInitSettings()
SetVar(LibUsefulSettings,"LibUseful:BuildTime",Tempstr);
Tempstr=FormatStr(Tempstr, "%d", 4096 * 10000);
SetVar(LibUsefulSettings,"MaxDocumentSize", Tempstr);
Tempstr=FormatStr(Tempstr, "%d", 4096 * 10000);
SetVar(LibUsefulSettings,"WEBSOCKET:MaxFrameSize", Tempstr);

DestroyString(Tempstr);
}

Expand Down
68 changes: 42 additions & 26 deletions LineEdit.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ TLineEdit *LineEditCreate(int Flags)

LE=(TLineEdit *) calloc(1, sizeof(TLineEdit));
LE->Flags = Flags;
if (Flags & LINE_EDIT_HISTORY) LE->History=ListCreate();
LE->MaxHistory=30;
if (Flags & LINE_EDIT_HISTORY)
{
LE->History=ListCreate();
LE->MaxHistory=30;
}

return(LE);
}
Expand All @@ -17,7 +20,7 @@ void LineEditDestroy(TLineEdit *LE)
{
if (LE)
{
if (LE->History) ListDestroy(LE->History, Destroy);
if ((LE->Flags & LINE_EDIT_HISTORY) && LE->History) ListDestroy(LE->History, NULL);
Destroy(LE->Line);
free(LE);
}
Expand All @@ -34,31 +37,44 @@ void LineEditSetText(TLineEdit *LE, const char *Text)

void LineEditClearHistory(TLineEdit *LE)
{
if (LE->History) ListClear(LE->History, Destroy);
if (LE->History) ListClear(LE->History, NULL);
}

void LineEditAddToHistory(TLineEdit *LE, const char *Text)
{
ListNode *Node;

if (StrValid(Text))
ListNode *LineEditSwapHistory(TLineEdit *LE, ListNode *NewHist)
{
if (! LE->History) LE->History=ListCreate();
ListNode *Old;

if (ListSize(LE->History) > LE->MaxHistory)
{
Node=ListGetNext(LE->History);
ListDeleteNode(Node);
Old=LE->History;
LE->History=NewHist;

return(Old);
}

Node=ListGetLast(LE->History);

if (Node && Node->Tag)
void LineEditAddToHistory(TLineEdit *LE, const char *Text)
{
if (strcmp(Node->Tag, Text) !=0) ListAddNamedItem(LE->History, Text, NULL);
}
else ListAddNamedItem(LE->History, Text, NULL);
}
ListNode *Node;

if (! LE->History) return;

if (StrValid(Text))
{

if ( (LE->MaxHistory > 0) && (ListSize(LE->History) > LE->MaxHistory) )
{
Node=ListGetNext(LE->History);
ListDeleteNode(Node);
}

Node=ListGetLast(LE->History);

if (Node && Node->Tag)
{
if (strcmp(Node->Tag, Text) !=0) ListAddNamedItem(LE->History, Text, NULL);
}
else ListAddNamedItem(LE->History, Text, NULL);
}

}

Expand All @@ -81,10 +97,10 @@ int LineEditHandleChar(TLineEdit *LE, int Char)
case TKEY_UP:
if (LE->History)
{
if (LE->History->Side)
{
if (LE->History->Side != ListGetNext(LE->History)) LE->History->Side=ListGetPrev(LE->History->Side);
}
if (LE->History->Side)
{
if (LE->History->Side != ListGetNext(LE->History)) LE->History->Side=ListGetPrev(LE->History->Side);
}
else LE->History->Side=ListGetLast(LE->History);

if (LE->History->Side) LineEditSetText(LE, LE->History->Side->Tag);
Expand Down Expand Up @@ -118,8 +134,7 @@ int LineEditHandleChar(TLineEdit *LE, int Char)
if ((! (LE->Flags & LINE_EDIT_NOMOVE)) && (LE->Cursor < LE->Len)) LE->Cursor=LE->Len;
break;

//'backspace' key on keyboard will send the 'del' character in some cases!
case 0x7f: //this is 'del'
case TKEY_DELETE:
if (LE->Cursor < LE->Len)
{
ptr=LE->Line + LE->Cursor;
Expand All @@ -130,6 +145,7 @@ int LineEditHandleChar(TLineEdit *LE, int Char)
break;

case TKEY_BACKSPACE:
case TKEY_ERASE: //this is 'del'
if (LE->Cursor > 0)
{
LE->Cursor--;
Expand All @@ -141,7 +157,7 @@ int LineEditHandleChar(TLineEdit *LE, int Char)
break;

case TKEY_ENTER:
if (LE->History) LE->History->Side=NULL;
if (LE->History) LE->History->Side=NULL;
return(LINE_EDIT_ENTER);
break;

Expand Down
10 changes: 10 additions & 0 deletions LineEdit.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ TKEY_ESCAPE - cancel line editing
The 'EditLineHandleChar' function returns the cursor position within the edited line, or if 'enter' is pressed it will return the value LINE_EDIT_ENTER, if 'escape' is pressed then it will return LINE_EDIT_CANCEL.
When LINE_EDIT_ENTER is called 'LineEditDone' should be used to collect the typed line, as it will reset the LineEdit for a new line to be typed in, and if history mode is active, it will add the typed line to the history.
The 'history' is a List (as in List.c) of named items where the line is added as the 'Tag' for each named node. The 'Item' member of each node is expected to be NULL, which has impacts on 'LineEditDestroy' as mentioned below. The size of the history will be limited (default 30 items) but this limit can be changed with 'LineEditSetMaxHistory'. Setting the maximum history to '0' disables history limits, allowing the history to grow indefinitely.
If the LineEditCreate was called with the flag LINE_EDIT_HISTORY, then 'LineEditDestroy' will attempt to destroy/free the history. However, it will not free any items included as (ListNode *)->Item values. It will only free the list structures themselves, including the 'Tags' that are the history lines. Thus if you add or update history nodes to have their ->Item members point to something, you will have to free that something yourself.
You can swap in externally managed histories with 'LineEditSwapHistory', which returns the old history that's been swapped out. In this situation it's best to create the LineEdit without the LINE_EDIT_HISTORY flag, so that LineEditDestroy won't try to free the history. The LineEdit system will use the history, adding to it and recalling from it. However, in this situation, where LINE_EDIT_HISTORY was not passed to LineEditCreate, the line edit system will not apply limits to the size of the history. If you want it to apply limits to external histories that are being swapped in and out, you can use LineEditSetMaxHistory to force this feature.
*/


Expand All @@ -57,6 +63,7 @@ ListNode *History;


#define LineEditSetMaxHistory(LE, Max) ((LE)->MaxHistory = (Max))
#define LineEditGetHistory(LE) ((LE)->History)

TLineEdit *LineEditCreate(int Flags);
void LineEditSetText(TLineEdit *LE, const char *Text);
Expand All @@ -66,4 +73,7 @@ char *LineEditDone(char *RetStr, TLineEdit *LE);
void LineEditClearHistory(TLineEdit *LE);
void LineEditAddToHistory(TLineEdit *LE, const char *Text);

//swap history list for another, return the old one
ListNode *LineEditSwapHistory(TLineEdit *LE, ListNode *NewHist);

#endif
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CC = gcc
AR = ar
VERSION = 5.35
VERSION = 5.36
MAJOR=5
LIBFILE=libUseful.so.$(VERSION)
SONAME=libUseful.so.$(MAJOR)
Expand All @@ -9,7 +9,7 @@ LDFLAGS=
LIBS = -lc -lz -lssl -lcrypto -lc -lc -lc -lc
prefix=/usr/local
sysconfdir=${prefix}/etc
FLAGS=$(LDFLAGS) $(CPPFLAGS) $(CFLAGS) -fPIC -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -D_FILE_OFFSET_BITS=64 -DHAVE_LIBC=1 -DHAVE_GET_CURR_DIR=1 -DHAVE_PTSNAME_R=1 -DHAVE_CLEARENV=1 -DHAVE_SETRESUID=1 -DHAVE_INITGROUPS=1 -DHAVE_POLL=1 -DHAVE_MLOCK=1 -DHAVE_MLOCKALL=1 -DHAVE_MUNLOCKALL=1 -DHAVE_MADVISE=1 -DHAVE_MKOSTEMP=1 -DHAVE_MOUNT=1 -DHAVE_UMOUNT=1 -DHAVE_UMOUNT2=1 -DHAVE_GETENTROPY=1 -DHAVE_PRCTL=1 -DHAVE_STDIO_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_STRINGS_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_UNISTD_H=1 -DSTDC_HEADERS=1 -DHAVE_SENDFILE=1 -DUSE_INET6=1 -DHAVE_LIBC=1 -DHAVE_XATTR=1 -DHAVE_LIBC=1 -DHAVE_UNSHARE=1 -DHAVE_LIBC=1 -DHAVE_SETNS=1 -DHAVE_LIBCRYPTO=1 -DHAVE_LIBSSL=1 -DHAVE_EVP_MD_CTX_CREATE=1 -DHAVE_EVP_MD_CTX_NEW=1 -DHAVE_EVP_MD_CTX_DESTROY=1 -DHAVE_EVP_MD_CTX_FREE=1 -DHAVE_X509_CHECK_HOST=1 -DHAVE_SSL_SET_MIN_PROTO_VERSION=1 -DHAVE_DECL_OPENSSL_ADD_ALL_ALGORITHMS=1 -DHAVE_OPENSSL_ADD_ALL_ALGORITHMS=1 -DHAVE_DECL_SSL_SET_TLSEXT_HOST_NAME=1 -DHAVE_SSL_SET_TLSEXT_HOST_NAME=1 -DHAVE_LIBZ=1 -DHAVE_LIBC=1 -DUSE_SECCOMP=1 -DVERSION=\"$(VERSION)\" -DSYSCONFDIR=\"$(sysconfdir)\"
FLAGS=$(LDFLAGS) $(CPPFLAGS) $(CFLAGS) -fPIC -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DHAVE_LIBC=1 -DHAVE_GET_CURR_DIR=1 -DHAVE_PTSNAME_R=1 -DHAVE_CLEARENV=1 -DHAVE_SETRESUID=1 -DHAVE_INITGROUPS=1 -DHAVE_POLL=1 -DHAVE_MLOCK=1 -DHAVE_MLOCKALL=1 -DHAVE_MUNLOCKALL=1 -DHAVE_MADVISE=1 -DHAVE_MKOSTEMP=1 -DHAVE_MOUNT=1 -DHAVE_UMOUNT=1 -DHAVE_UMOUNT2=1 -DHAVE_GETENTROPY=1 -DHAVE_PRCTL=1 -DHAVE_STDIO_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_STRINGS_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_UNISTD_H=1 -DSTDC_HEADERS=1 -DHAVE_SENDFILE=1 -DUSE_INET6=1 -DHAVE_LIBC=1 -DHAVE_XATTR=1 -DHAVE_LIBC=1 -DHAVE_UNSHARE=1 -DHAVE_LIBC=1 -DHAVE_SETNS=1 -DHAVE_LIBCRYPTO=1 -DHAVE_LIBSSL=1 -DHAVE_EVP_MD_CTX_NEW=1 -DHAVE_EVP_MD_CTX_FREE=1 -DHAVE_X509_CHECK_HOST=1 -DHAVE_EVP_CIPHER_FETCH=1 -DHAVE_DECL_OPENSSL_ADD_ALL_ALGORITHMS=1 -DHAVE_OPENSSL_ADD_ALL_ALGORITHMS=1 -DHAVE_DECL_SSL_SET_TLSEXT_HOST_NAME=1 -DHAVE_SSL_SET_TLSEXT_HOST_NAME=1 -DHAVE_LIBZ=1 -DHAVE_LIBC=1 -DUSE_SECCOMP=1 -DVERSION=\"$(VERSION)\" -DSYSCONFDIR=\"$(sysconfdir)\"
OBJ=StrLenCache.o String.o Array.o List.o IPAddress.o Socket.o Server.o UnixSocket.o Stream.o StreamAuth.o Errors.o Unicode.o TerminalKeys.o Terminal.o TerminalWidget.o TerminalMenu.o TerminalChoice.o TerminalBar.o TerminalProgress.o TerminalCalendar.o TerminalTheme.o FileSystem.o GeneralFunctions.o DataProcessing.o Pty.o Log.o HttpUtil.o HttpChunkedTransfer.o Http.o Gemini.o Smtp.o Inet.o Expect.o base32.o base64.o crc32.o md5c.o sha1.o sha2.o whirlpool.o jh_ref.o HashCRC32.o HashMD5.o HashSHA.o HashJH.o HashWhirlpool.o HashOpenSSL.o Hash.o HMAC.o Ssh.o Compression.o Encryption.o OAuth.o LibSettings.o Vars.o Time.o Markup.o SpawnPrograms.o Tokenizer.o StringList.o PatternMatch.o URL.o DataParser.o ConnectionChain.o OpenSSL.o Seccomp.o Process.o Container.o Encodings.o RawData.o SecureMem.o CommandLineParser.o SysInfo.o Entropy.o Users.o UnitsOfMeasure.o HttpServer.o WebSocket.o ContentType.o PasswordFile.o OTP.o CGI.o LineEdit.o


Expand Down
2 changes: 1 addition & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CC = @CC@
AR = @AR@
VERSION = 5.35
VERSION = 5.36
MAJOR=5
LIBFILE=libUseful.so.$(VERSION)
SONAME=libUseful.so.$(MAJOR)
Expand Down
Loading

0 comments on commit 8d0f7f5

Please sign in to comment.