Skip to content

Commit

Permalink
WIP: incoming NGC group images
Browse files Browse the repository at this point in the history
  • Loading branch information
zoff99 committed Jan 10, 2024
1 parent daf3d6b commit e57c7bb
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/toxic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/toxic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
41 changes: 41 additions & 0 deletions src/windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,47 @@ 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] == (byte) 0x66) && (data[1] == (byte) 0x77) && (data[2] == (byte) 0x88) &&
(data[3] == (byte) 0x11) && (data[4] == (byte) 0x34) && (data[5] == (byte) 0x35)) {
if ((data[6] == (byte) 0x1) && (data[7] == (byte) 0x11)) {

// TODO: handle actual incoming file data
const uint32_t file_size = length - header_size;
const uint8_t *file_data = data + header_size;
// 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)
{
Expand Down

0 comments on commit e57c7bb

Please sign in to comment.