diff --git a/src/toxic.c b/src/toxic.c index 8ef714858..9ab299245 100644 --- a/src/toxic.c +++ b/src/toxic.c @@ -883,6 +883,7 @@ static void init_tox_callbacks(Tox *tox) tox_callback_group_join_fail(tox, on_group_rejected); tox_callback_group_moderation(tox, on_group_moderation); tox_callback_group_voice_state(tox, on_group_voice_state); + tox_callback_group_custom_packet(tox, on_group_custom_packet); } static void init_tox_options(struct Tox_Options *tox_opts) diff --git a/src/toxic.h b/src/toxic.h index 49d2b1ecc..e725f27f0 100644 --- a/src/toxic.h +++ b/src/toxic.h @@ -180,6 +180,8 @@ void on_group_rejected(Tox *tox, uint32_t groupnumber, Tox_Group_Join_Fail type, void on_group_moderation(Tox *tox, uint32_t groupnumber, uint32_t source_peernum, uint32_t target_peernum, Tox_Group_Mod_Event type, void *userdata); void on_group_voice_state(Tox *tox, uint32_t groupnumber, Tox_Group_Voice_State voice_state, void *userdata); +void on_group_custom_packet(Tox *tox, uint32_t groupnumber, uint32_t peer_id, const uint8_t *data, + size_t length, void *user_data); extern char *DATA_FILE; extern char *BLOCK_FILE; diff --git a/src/windows.c b/src/windows.c index 21631abb6..50f529d64 100644 --- a/src/windows.c +++ b/src/windows.c @@ -394,6 +394,49 @@ void on_group_invite(Tox *tox, uint32_t friendnumber, const uint8_t *invite_data } } +void on_group_custom_packet(Tox *tox, uint32_t groupnumber, uint32_t peer_id, const uint8_t *data, + size_t length, void *user_data) +{ + /* + | what | Length in bytes| Contents + |------ |-------- |------------------ + | magic | 6 | 0x667788113435 + | version | 1 | 0x01 + | pkt id | 1 | 0x11 + | msg id | 32 | *uint8_t to uniquely identify the message + | create ts | 4 | uint32_t unixtimestamp in UTC of local wall clock (in bigendian) + | filename | 255 | *uint8_t len TOX_MAX_FILENAME_LENGTH, data first, then pad with NULL bytes + | data |[1, 36701] | *uint8_t bytes of file data, zero length files not allowed! + */ + + const uint32_t header_size = 6 + 1 + 1 + 32 + 4 + 255; + + if (length > header_size) { + if ((data[0] == 0x66) && (data[1] == 0x77) && (data[2] == 0x88) && + (data[3] == 0x11) && (data[4] == 0x34) && (data[5] == 0x35)) { + if ((data[6] == 0x1) && (data[7] == 0x11)) { + + // TODO: handle actual incoming file data + const uint32_t file_size = length - header_size; + const uint8_t *file_data = data + header_size; + UNUSED_VAR(file_size); + UNUSED_VAR(file_data); + // save file data here ... + // TODO: handle actual incoming file data + + const char *msg = "incoming group file"; + const size_t msg_length = strlen(msg); + + for (size_t i = 0; i < MAX_WINDOWS_NUM; ++i) { + if (windows[i] != NULL && windows[i]->onGroupMessage != NULL) { + windows[i]->onGroupMessage(windows[i], tox, groupnumber, peer_id, TOX_MESSAGE_TYPE_NORMAL, msg, msg_length); + } + } + } + } + } +} + void on_group_message(Tox *tox, uint32_t groupnumber, uint32_t peer_id, TOX_MESSAGE_TYPE type, const uint8_t *message, size_t length, uint32_t message_id, void *userdata) {