diff --git a/external/libs b/external/libs index 075a26b..8929a0c 160000 --- a/external/libs +++ b/external/libs @@ -1 +1 @@ -Subproject commit 075a26b8f9ec93110cd3dd22a6e319e970b40519 +Subproject commit 8929a0cebccda978dbb611808c8e66298b56fba0 diff --git a/makefile b/makefile index d0ff4f4..e5f3e8e 100644 --- a/makefile +++ b/makefile @@ -63,13 +63,13 @@ endif ifeq ($(CONFIG),release) # release LIBRARIES += \ - external/bin/libs/release/bflibc/libbfc.a \ external/bin/libs/release/bflibcpp/libbfcpp.a \ + external/bin/libs/release/bflibc/libbfc.a \ external/bin/libs/release/bfnet/libbfnet.a else LIBRARIES += \ - external/bin/libs/debug/bflibc/libbfc-debug.a \ external/bin/libs/debug/bflibcpp/libbfcpp-debug.a \ + external/bin/libs/debug/bflibc/libbfc-debug.a \ external/bin/libs/debug/bfnet/libbfnet-debug.a endif diff --git a/src/agent.cpp b/src/agent.cpp index 1f41a76..76613e2 100644 --- a/src/agent.cpp +++ b/src/agent.cpp @@ -328,22 +328,25 @@ void Agent::receivedPayloadTypeChatroomResignation(const Packet * pkt) { } int Agent::sendPacket(const Packet * pkt) { + if (!pkt) return 1; + + LOG_DEBUG("sending package header type=%d", pkt->header.type); SealedPacket c(pkt, sizeof(Packet)); - return this->_sc->queueData(c.data(), c.size()); + return this->_sc->queueData(c.data()); } -void Agent::packetReceive(SocketEnvelope * envelope) { +void Agent::packetReceive(Envelope * envelope) { if (!envelope) return; BFRetain(envelope); - SealedPacket c(envelope->buf()->data(), envelope->buf()->size()); + SealedPacket c(envelope->data()->buffer(), envelope->data()->size()); Connection * sc = envelope->connection(); - const Packet * p = (const Packet *) c.data(); - size_t size = c.size(); + const Packet * p = (const Packet *) c.data()->buffer(); + size_t size = c.data()->size(); if (!sc || !p) { BFRelease(envelope); @@ -370,6 +373,7 @@ void Agent::packetReceive(SocketEnvelope * envelope) { BFRetain(agent); + LOG_DEBUG("agent received packet header: %d", p->header.type); switch (p->header.type) { case kPayloadTypeMessage: agent->receivedPayloadTypeMessage(p); @@ -402,6 +406,7 @@ void Agent::packetReceive(SocketEnvelope * envelope) { agent->receivedPayloadTypeChatroomEnrollmentForm(p); break; default: + LOG_DEBUG("unknown header type: %d", p->header.type); break; } diff --git a/src/agent.hpp b/src/agent.hpp index 89581eb..aa6f6ba 100644 --- a/src/agent.hpp +++ b/src/agent.hpp @@ -15,7 +15,7 @@ class User; namespace BF { namespace Net { - class SocketEnvelope; + class Envelope; class Connection; } } @@ -35,7 +35,7 @@ class Agent : public BF::Object { * sc : each agent should have this * bub : copy data if you need to use after function returns */ - static void packetReceive(BF::Net::SocketEnvelope * envelope); + static void packetReceive(BF::Net::Envelope * envelope); /** * this is a callback described by the Socket family diff --git a/src/chat.cpp b/src/chat.cpp index 5c9efc8..1cf0ff5 100644 --- a/src/chat.cpp +++ b/src/chat.cpp @@ -188,6 +188,7 @@ int Chat::Main(int argc, char * argv[]) { LOG_OPEN; LOG_DEBUG("============ App started ============"); + LOG_DEBUG("packet size: %d", CHAT_SOCKET_BUFFER_SIZE); if (showversion) { _ChatShowVersion(argv[0]); diff --git a/src/chatroom.cpp b/src/chatroom.cpp index d3d8bdd..cdff2a1 100644 --- a/src/chatroom.cpp +++ b/src/chatroom.cpp @@ -30,8 +30,7 @@ void _ChatroomReleaseAgent(Agent * a) { BFRelease(a); } Chatroom::Chatroom() : Object() { #ifndef TESTING if (Chat::SocketGetMode() != SOCKET_MODE_SERVER) { - String msg("Can only create a raw chatroom from server mode (current mode '%c')", Chat::SocketGetMode()); - throw Exception(msg); + throw Exception("Can only create a raw chatroom from server mode (current mode '%c')", Chat::SocketGetMode()); } #endif diff --git a/src/interface.cpp b/src/interface.cpp index 4684b27..c082eda 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -551,7 +551,7 @@ int _InterfaceDrawUserInputDraft( werase(inputwin); box(inputwin, 0, 0); - _InterfaceFixTextInBoxedWindow(inputwin, userInput, 1); + _InterfaceFixTextInBoxedWindow(inputwin, userInput.cString(), 1); wrefresh(inputwin); @@ -673,7 +673,7 @@ int Interface::processinputStateLobby(InputBuffer & userInput) { } else { char chatroomname[CHAT_ROOM_NAME_SIZE]; if (cmd.count() > 1) { - strncpy(chatroomname, cmd[1], CHAT_ROOM_NAME_SIZE); + strncpy(chatroomname, cmd[1].cString(), CHAT_ROOM_NAME_SIZE); } else { // set up chat room name // @@ -820,7 +820,6 @@ int Interface::windowLoop() { this->_prevstate = kInterfaceStateUnknown; this->_state = kInterfaceStatePromptUsername; - //this->_state = kInterfaceStateLobby; while (this->_state.get() != kInterfaceStateQuit) { // draw ui based on current state diff --git a/src/log.hpp b/src/log.hpp index 3bc4a67..7b59ff4 100644 --- a/src/log.hpp +++ b/src/log.hpp @@ -1,6 +1,6 @@ /** * author: brando - * date: + * date: 2/12/24 */ #ifndef LOG_HPP diff --git a/src/office.cpp b/src/office.cpp index 96dd3e1..fe14d4a 100644 --- a/src/office.cpp +++ b/src/office.cpp @@ -18,7 +18,7 @@ using namespace BF; using namespace BF::Net; -Atomic> inbox; +Atomic> inbox; BFLock inboxlock; BFThreadAsyncID _tid = NULL; @@ -34,7 +34,7 @@ int Office::quitApplication(const User * user) { return Agent::broadcast(&p); } -void Office::packetReceive(SocketEnvelope * envelope) { +void Office::packetReceive(Envelope * envelope) { // push into queue BFRetain(envelope); inbox.get().push(envelope); @@ -49,7 +49,7 @@ void _OfficeInDataWorkerThread(void * in) { inbox.lock(); // get first item from the queue - SocketEnvelope * envelope = inbox.unsafeget().front(); + Envelope * envelope = inbox.unsafeget().front(); // send it over to the agents Agent::packetReceive(envelope); diff --git a/src/office.hpp b/src/office.hpp index 90d06a1..35093ce 100644 --- a/src/office.hpp +++ b/src/office.hpp @@ -13,7 +13,7 @@ class User; namespace BF { namespace Net { - class SocketEnvelope; + class Envelope; } } @@ -22,7 +22,7 @@ namespace BF { */ namespace Office { -void packetReceive(BF::Net::SocketEnvelope * envelope); +void packetReceive(BF::Net::Envelope * envelope); int start(); int stop(); diff --git a/src/operand.cpp b/src/operand.cpp index 851b000..4031a1a 100644 --- a/src/operand.cpp +++ b/src/operand.cpp @@ -27,11 +27,10 @@ int _OperandAcceptArgsCompare(char * a, char * b) { return strcmp(a, b); } -Operand::Operand(std::initializer_list list) : Object() { +Operand::Operand(std::initializer_list list) : Object() { this->_acceptedArgs.setReleaseCallback(_OperandAcceptArgsRelease); - for (const char * arg : list) { - char * buf = BFStringCopyString(arg); - this->_acceptedArgs.add(buf); + for (const String & arg : list) { + this->_acceptedArgs.add(arg.cStringCopy()); } this->_acceptedArgs.setComparator(_OperandAcceptArgsCompare); } diff --git a/src/operand.hpp b/src/operand.hpp index b601759..dcc4a62 100644 --- a/src/operand.hpp +++ b/src/operand.hpp @@ -22,7 +22,7 @@ */ class Operand : public BF::Object { public: - Operand(std::initializer_list list); + Operand(std::initializer_list list); virtual ~Operand(); bool compare(const Operand & op); diff --git a/src/sealedpacket.cpp b/src/sealedpacket.cpp index 0bfb993..6c1eee4 100644 --- a/src/sealedpacket.cpp +++ b/src/sealedpacket.cpp @@ -12,7 +12,10 @@ extern "C" { #include } +using namespace BF; + SealedPacket::SealedPacket(const void * data, size_t size) { + /* this->_dataPlainSize = size; this->_dataPlain = malloc(sizeof(char) * size); @@ -20,16 +23,24 @@ SealedPacket::SealedPacket(const void * data, size_t size) { return; memcpy(this->_dataPlain, data, size); + */ + this->_data = new Data(size, (const unsigned char *) data); } SealedPacket::~SealedPacket() { - BFFree(this->_dataPlain); + //BFFree(this->_dataPlain); + BFRelease(this->_data); } bool SealedPacket::isEncrypted() { return false; } +const Data * SealedPacket::data() const { + return this->_data; +} + +/* const void * SealedPacket::data() { return this->_dataPlain; } @@ -37,4 +48,4 @@ const void * SealedPacket::data() { size_t SealedPacket::size() { return this->_dataPlainSize; } - +*/ diff --git a/src/sealedpacket.hpp b/src/sealedpacket.hpp index a7a4049..aa6f475 100644 --- a/src/sealedpacket.hpp +++ b/src/sealedpacket.hpp @@ -7,6 +7,7 @@ #define SEALED_PACKET_HPP #include +#include /** * handles encryption and serialization of the @@ -22,12 +23,12 @@ class SealedPacket : public BF::Object { ~SealedPacket(); bool isEncrypted(); - const void * data(); - size_t size(); + + const BF::Data * data() const; private: - void * _dataPlain; - size_t _dataPlainSize; + + BF::Data * _data; }; #endif // SEALED_PACKET_HPP diff --git a/testbench/ciphersymmetric_tests.hpp b/testbench/ciphersymmetric_tests.hpp index ea1de0d..3f5af7a 100644 --- a/testbench/ciphersymmetric_tests.hpp +++ b/testbench/ciphersymmetric_tests.hpp @@ -141,7 +141,7 @@ BFTEST_UNIT_FUNC(test_LongString, 2<<10, { if (!result) { String res = dec; - if (strcmp(res.cString(), str)) { + if (res != str) { printf("%s != %s\n", res.cString(), str.cString()); result = 3; } diff --git a/testbench/command_tests.hpp b/testbench/command_tests.hpp index aded932..a2a7d0a 100644 --- a/testbench/command_tests.hpp +++ b/testbench/command_tests.hpp @@ -37,9 +37,9 @@ BFTEST_UNIT_FUNC(test_commandargs, 2<<10, { Command c(buf); BF_ASSERT(c.op() == Operand({"command"})); - BF_ASSERT(!strcmp(c[1], "subcommand")); - BF_ASSERT(!strcmp(c[2], "arg0")); - BF_ASSERT(!strcmp(c[3], "arg1")); + BF_ASSERT(!strcmp(c[1].c_str(), "subcommand")); + BF_ASSERT(!strcmp(c[2].c_str(), "arg0")); + BF_ASSERT(!strcmp(c[3].c_str(), "arg1")); }) BFTEST_UNIT_FUNC(test_commandargscount, 2<<10, { diff --git a/todo.md b/todo.md index 2d3e1f8..5e389e1 100644 --- a/todo.md +++ b/todo.md @@ -1,17 +1,17 @@ -x.x +**x.x** - [ ] window dynamic resizing - [ ] add to homebrew package manager - [ ] docker? - [ ] ai bot chatroom - [ ] clean interface.cpp. split some code into categorical source files -0.4 +**0.4** - [ ] wrap entire communication in encryption - [ ] user data window editor - [ ] ability to change user name - [ ] get list of users in chatroom -0.3 +**0.3** - [x] improved controls (easier commands or guidance) - [x] use of ":" for long commands - [x] single key commands @@ -25,14 +25,15 @@ x.x - [x] move package logic to libs - [ ] host vs server (allow user to run this application as a service) - [x] detect if users are active. Protect the case when remote users are disconnected unintentionally +- [ ] fix ncurses borders -0.2.1 +**0.2.1** - [x] issue with sending messages between two machines that are on macos and linux - [x] test on two macs - [x] build a macos universal binary - [x] properly quit to make sure the receiver isn't overworking -0.2 +**0.2** - [x] cross platform - [x] configure a local openssl usage in this repo - [x] chatroom encryption @@ -47,7 +48,7 @@ x.x - https://github.com/openssl/openssl/discussions/24924 - [x] separate sources for libs -0.1 +**0.1** - [x] make linux build - [x] make macos build - [x] test release builds