Skip to content

Commit

Permalink
feat: add ngc events
Browse files Browse the repository at this point in the history
  • Loading branch information
Green-Sky authored and iphydf committed Jan 12, 2024
1 parent 994ffec commit d1d48d1
Show file tree
Hide file tree
Showing 52 changed files with 5,946 additions and 68 deletions.
18 changes: 18 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,24 @@ set(toxcore_SOURCES
toxcore/events/friend_status_message.c
toxcore/events/friend_typing.c
toxcore/events/self_connection_status.c
toxcore/events/group_custom_packet.c
toxcore/events/group_custom_private_packet.c
toxcore/events/group_invite.c
toxcore/events/group_join_fail.c
toxcore/events/group_message.c
toxcore/events/group_moderation.c
toxcore/events/group_password.c
toxcore/events/group_peer_exit.c
toxcore/events/group_peer_join.c
toxcore/events/group_peer_limit.c
toxcore/events/group_peer_name.c
toxcore/events/group_peer_status.c
toxcore/events/group_privacy_state.c
toxcore/events/group_private_message.c
toxcore/events/group_self_join.c
toxcore/events/group_topic.c
toxcore/events/group_topic_lock.c
toxcore/events/group_voice_state.c
toxcore/forwarding.c
toxcore/forwarding.h
toxcore/friend_connection.c
Expand Down
2 changes: 1 addition & 1 deletion other/bootstrap_daemon/docker/tox-bootstrapd.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a6701e463517907cdb450f3210389633feb6c1cc3a1d3faec48c8b99a4aebf3c /usr/local/bin/tox-bootstrapd
a25a42c612c89e7eab338f2cf330994d4334c7f9c8230eee3590c2f79c291bde /usr/local/bin/tox-bootstrapd
55 changes: 43 additions & 12 deletions other/event_tooling/generate_event_c.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright © 2023 The TokTok team.
// Copyright © 2023-2024 The TokTok team.

// this file can be used to generate event.c files
// requires c++17
Expand Down Expand Up @@ -119,22 +119,54 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
exit(1);
}

bool need_stdlib_h = false;
bool need_string_h = false;
bool need_tox_unpack_h = false;
for (const auto& t : event_types) {
std::visit(
overloaded{
[&](const EventTypeTrivial& t) {
if (bin_unpack_name_from_type(t.type).rfind("tox_", 0) == 0) {
need_tox_unpack_h = true;
}
},
[&](const EventTypeByteRange&) {
need_stdlib_h = true;
need_string_h = true;
}
},
t
);
}

f << R"(/* SPDX-License-Identifier: GPL-3.0-or-later
* Copyright © 2023 The TokTok team.
* Copyright © 2023-2024 The TokTok team.
*/
#include "events_alloc.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>)";
if (need_stdlib_h) {
f << R"(
#include <stdlib.h>)";
}
if (need_string_h) {
f << R"(
#include <string.h>)";
}
f << R"(
#include "../bin_pack.h"
#include "../bin_unpack.h"
#include "../ccompat.h"
#include "../mem.h"
#include "../tox.h"
#include "../tox_events.h"
#include "../tox_unpack.h"
#include "../tox_events.h")";
if (need_tox_unpack_h) {
f << R"(
#include "../tox_unpack.h")";
}
f << R"(
/*****************************************************
Expand Down Expand Up @@ -205,10 +237,11 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
f << " " << event_name_l << "->" << t.name_data << " = nullptr;\n";
f << " " << event_name_l << "->" << t.name_length << " = 0;\n";
f << " }\n\n";
f << " " << event_name_l << "->" << t.name_data << " = (uint8_t *)malloc(" << t.name_length << ");\n\n";
f << " if (" << event_name_l << "->" << t.name_data << " == nullptr) {\n";
f << " uint8_t *" << t.name_data << "_copy = (uint8_t *)malloc(" << t.name_length << ");\n\n";
f << " if (" << t.name_data << "_copy == nullptr) {\n";
f << " return false;\n }\n\n";
f << " memcpy(" << event_name_l << "->" << t.name_data << ", " << t.name_data << ", " << t.name_length << ");\n";
f << " memcpy(" << t.name_data << "_copy, " << t.name_data << ", " << t.name_length << ");\n";
f << " " << event_name_l << "->" << t.name_data << " = " << t.name_data << "_copy;\n";
f << " " << event_name_l << "->" << t.name_length << " = " << t.name_length << ";\n";
f << " return true;\n";
}
Expand Down Expand Up @@ -626,7 +659,6 @@ int main(int argc, char** argv) {
}
},

#if 0 // not yet :)
{
"Group_Peer_Name",
{
Expand Down Expand Up @@ -768,7 +800,6 @@ int main(int argc, char** argv) {
EventTypeTrivial{"Tox_Group_Mod_Event", "mod_type"},
}
},
#endif
};

if (argc < 2) {
Expand Down
18 changes: 18 additions & 0 deletions toxcore/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@ libtoxcore_la_SOURCES = ../third_party/cmp/cmp.c \
../toxcore/events/friend_status_message.c \
../toxcore/events/friend_typing.c \
../toxcore/events/self_connection_status.c \
../toxcore/events/group_custom_packet.c \
../toxcore/events/group_custom_private_packet.c \
../toxcore/events/group_invite.c \
../toxcore/events/group_join_fail.c \
../toxcore/events/group_message.c \
../toxcore/events/group_moderation.c \
../toxcore/events/group_password.c \
../toxcore/events/group_peer_exit.c \
../toxcore/events/group_peer_join.c \
../toxcore/events/group_peer_limit.c \
../toxcore/events/group_peer_name.c \
../toxcore/events/group_peer_status.c \
../toxcore/events/group_privacy_state.c \
../toxcore/events/group_private_message.c \
../toxcore/events/group_self_join.c \
../toxcore/events/group_topic.c \
../toxcore/events/group_topic_lock.c \
../toxcore/events/group_voice_state.c \
../toxcore/DHT.h \
../toxcore/DHT.c \
../toxcore/mem.h \
Expand Down
5 changes: 2 additions & 3 deletions toxcore/events/conference_connected.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
/* SPDX-License-Identifier: GPL-3.0-or-later
* Copyright © 2023 The TokTok team.
* Copyright © 2023-2024 The TokTok team.
*/

#include "events_alloc.h"

#include <assert.h>
#include <stdlib.h>

#include "../bin_pack.h"
#include "../bin_unpack.h"
#include "../ccompat.h"
#include "../mem.h"
#include "../tox.h"
#include "../tox_events.h"
#include "../tox_unpack.h"


/*****************************************************
Expand Down
3 changes: 2 additions & 1 deletion toxcore/events/conference_invite.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* SPDX-License-Identifier: GPL-3.0-or-later
* Copyright © 2023 The TokTok team.
* Copyright © 2023-2024 The TokTok team.
*/

#include "events_alloc.h"
Expand All @@ -11,6 +11,7 @@
#include "../bin_pack.h"
#include "../bin_unpack.h"
#include "../ccompat.h"
#include "../mem.h"
#include "../tox.h"
#include "../tox_events.h"
#include "../tox_unpack.h"
Expand Down
3 changes: 2 additions & 1 deletion toxcore/events/conference_message.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* SPDX-License-Identifier: GPL-3.0-or-later
* Copyright © 2023 The TokTok team.
* Copyright © 2023-2024 The TokTok team.
*/

#include "events_alloc.h"
Expand All @@ -11,6 +11,7 @@
#include "../bin_pack.h"
#include "../bin_unpack.h"
#include "../ccompat.h"
#include "../mem.h"
#include "../tox.h"
#include "../tox_events.h"
#include "../tox_unpack.h"
Expand Down
5 changes: 2 additions & 3 deletions toxcore/events/conference_peer_list_changed.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
/* SPDX-License-Identifier: GPL-3.0-or-later
* Copyright © 2023 The TokTok team.
* Copyright © 2023-2024 The TokTok team.
*/

#include "events_alloc.h"

#include <assert.h>
#include <stdlib.h>

#include "../bin_pack.h"
#include "../bin_unpack.h"
#include "../ccompat.h"
#include "../mem.h"
#include "../tox.h"
#include "../tox_events.h"
#include "../tox_unpack.h"


/*****************************************************
Expand Down
4 changes: 2 additions & 2 deletions toxcore/events/conference_peer_name.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* SPDX-License-Identifier: GPL-3.0-or-later
* Copyright © 2023 The TokTok team.
* Copyright © 2023-2024 The TokTok team.
*/

#include "events_alloc.h"
Expand All @@ -11,9 +11,9 @@
#include "../bin_pack.h"
#include "../bin_unpack.h"
#include "../ccompat.h"
#include "../mem.h"
#include "../tox.h"
#include "../tox_events.h"
#include "../tox_unpack.h"


/*****************************************************
Expand Down
4 changes: 2 additions & 2 deletions toxcore/events/conference_title.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* SPDX-License-Identifier: GPL-3.0-or-later
* Copyright © 2023 The TokTok team.
* Copyright © 2023-2024 The TokTok team.
*/

#include "events_alloc.h"
Expand All @@ -11,9 +11,9 @@
#include "../bin_pack.h"
#include "../bin_unpack.h"
#include "../ccompat.h"
#include "../mem.h"
#include "../tox.h"
#include "../tox_events.h"
#include "../tox_unpack.h"


/*****************************************************
Expand Down
3 changes: 2 additions & 1 deletion toxcore/events/events_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
#include "events_alloc.h"

#include <assert.h>
#include <stdlib.h>

#include "../ccompat.h"
#include "../mem.h"
#include "../tox_event.h"
#include "../tox_events.h"

Tox_Events_State *tox_events_alloc(void *user_data)
Expand Down
18 changes: 18 additions & 0 deletions toxcore/events/events_alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,24 @@ tox_friend_status_cb tox_events_handle_friend_status;
tox_friend_status_message_cb tox_events_handle_friend_status_message;
tox_friend_typing_cb tox_events_handle_friend_typing;
tox_self_connection_status_cb tox_events_handle_self_connection_status;
tox_group_peer_name_cb tox_events_handle_group_peer_name;
tox_group_peer_status_cb tox_events_handle_group_peer_status;
tox_group_topic_cb tox_events_handle_group_topic;
tox_group_privacy_state_cb tox_events_handle_group_privacy_state;
tox_group_voice_state_cb tox_events_handle_group_voice_state;
tox_group_topic_lock_cb tox_events_handle_group_topic_lock;
tox_group_peer_limit_cb tox_events_handle_group_peer_limit;
tox_group_password_cb tox_events_handle_group_password;
tox_group_message_cb tox_events_handle_group_message;
tox_group_private_message_cb tox_events_handle_group_private_message;
tox_group_custom_packet_cb tox_events_handle_group_custom_packet;
tox_group_custom_private_packet_cb tox_events_handle_group_custom_private_packet;
tox_group_invite_cb tox_events_handle_group_invite;
tox_group_peer_join_cb tox_events_handle_group_peer_join;
tox_group_peer_exit_cb tox_events_handle_group_peer_exit;
tox_group_self_join_cb tox_events_handle_group_self_join;
tox_group_join_fail_cb tox_events_handle_group_join_fail;
tox_group_moderation_cb tox_events_handle_group_moderation;

non_null(2) nullable(1)
bool tox_events_pack(const Tox_Events *events, Bin_Pack *bp);
Expand Down
5 changes: 2 additions & 3 deletions toxcore/events/file_chunk_request.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
/* SPDX-License-Identifier: GPL-3.0-or-later
* Copyright © 2023 The TokTok team.
* Copyright © 2023-2024 The TokTok team.
*/

#include "events_alloc.h"

#include <assert.h>
#include <stdlib.h>

#include "../bin_pack.h"
#include "../bin_unpack.h"
#include "../ccompat.h"
#include "../mem.h"
#include "../tox.h"
#include "../tox_events.h"
#include "../tox_unpack.h"


/*****************************************************
Expand Down
4 changes: 2 additions & 2 deletions toxcore/events/file_recv.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* SPDX-License-Identifier: GPL-3.0-or-later
* Copyright © 2023 The TokTok team.
* Copyright © 2023-2024 The TokTok team.
*/

#include "events_alloc.h"
Expand All @@ -11,9 +11,9 @@
#include "../bin_pack.h"
#include "../bin_unpack.h"
#include "../ccompat.h"
#include "../mem.h"
#include "../tox.h"
#include "../tox_events.h"
#include "../tox_unpack.h"


/*****************************************************
Expand Down
4 changes: 2 additions & 2 deletions toxcore/events/file_recv_chunk.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* SPDX-License-Identifier: GPL-3.0-or-later
* Copyright © 2023 The TokTok team.
* Copyright © 2023-2024 The TokTok team.
*/

#include "events_alloc.h"
Expand All @@ -11,9 +11,9 @@
#include "../bin_pack.h"
#include "../bin_unpack.h"
#include "../ccompat.h"
#include "../mem.h"
#include "../tox.h"
#include "../tox_events.h"
#include "../tox_unpack.h"


/*****************************************************
Expand Down
4 changes: 2 additions & 2 deletions toxcore/events/file_recv_control.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/* SPDX-License-Identifier: GPL-3.0-or-later
* Copyright © 2023 The TokTok team.
* Copyright © 2023-2024 The TokTok team.
*/

#include "events_alloc.h"

#include <assert.h>
#include <stdlib.h>

#include "../bin_pack.h"
#include "../bin_unpack.h"
#include "../ccompat.h"
#include "../mem.h"
#include "../tox.h"
#include "../tox_events.h"
#include "../tox_unpack.h"
Expand Down
4 changes: 2 additions & 2 deletions toxcore/events/friend_connection_status.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/* SPDX-License-Identifier: GPL-3.0-or-later
* Copyright © 2023 The TokTok team.
* Copyright © 2023-2024 The TokTok team.
*/

#include "events_alloc.h"

#include <assert.h>
#include <stdlib.h>

#include "../bin_pack.h"
#include "../bin_unpack.h"
#include "../ccompat.h"
#include "../mem.h"
#include "../tox.h"
#include "../tox_events.h"
#include "../tox_unpack.h"
Expand Down
Loading

0 comments on commit d1d48d1

Please sign in to comment.