Skip to content

Commit 97586c3

Browse files
committed
WIP: incoming NGC group images
1 parent daf3d6b commit 97586c3

3 files changed

Lines changed: 46 additions & 0 deletions

File tree

src/toxic.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,7 @@ static void init_tox_callbacks(Tox *tox)
883883
tox_callback_group_join_fail(tox, on_group_rejected);
884884
tox_callback_group_moderation(tox, on_group_moderation);
885885
tox_callback_group_voice_state(tox, on_group_voice_state);
886+
tox_callback_group_custom_packet(tox, on_group_custom_packet);
886887
}
887888

888889
static void init_tox_options(struct Tox_Options *tox_opts)

src/toxic.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ void on_group_rejected(Tox *tox, uint32_t groupnumber, Tox_Group_Join_Fail type,
180180
void on_group_moderation(Tox *tox, uint32_t groupnumber, uint32_t source_peernum, uint32_t target_peernum,
181181
Tox_Group_Mod_Event type, void *userdata);
182182
void on_group_voice_state(Tox *tox, uint32_t groupnumber, Tox_Group_Voice_State voice_state, void *userdata);
183+
void on_group_custom_packet(Tox *tox, uint32_t groupnumber, uint32_t peer_id, const uint8_t *data,
184+
size_t length, void *user_data);
183185

184186
extern char *DATA_FILE;
185187
extern char *BLOCK_FILE;

src/windows.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,49 @@ void on_group_invite(Tox *tox, uint32_t friendnumber, const uint8_t *invite_data
394394
}
395395
}
396396

397+
void on_group_custom_packet(Tox *tox, uint32_t groupnumber, uint32_t peer_id, const uint8_t *data,
398+
size_t length, void *user_data)
399+
{
400+
/*
401+
| what | Length in bytes| Contents
402+
|------ |-------- |------------------
403+
| magic | 6 | 0x667788113435
404+
| version | 1 | 0x01
405+
| pkt id | 1 | 0x11
406+
| msg id | 32 | *uint8_t to uniquely identify the message
407+
| create ts | 4 | uint32_t unixtimestamp in UTC of local wall clock (in bigendian)
408+
| filename | 255 | *uint8_t len TOX_MAX_FILENAME_LENGTH, data first, then pad with NULL bytes
409+
| data |[1, 36701] | *uint8_t bytes of file data, zero length files not allowed!
410+
*/
411+
412+
const uint32_t header_size = 6 + 1 + 1 + 32 + 4 + 255;
413+
414+
if (length > header_size) {
415+
if ((data[0] == 0x66) && (data[1] == 0x77) && (data[2] == 0x88) &&
416+
(data[3] == 0x11) && (data[4] == 0x34) && (data[5] == 0x35)) {
417+
if ((data[6] == 0x1) && (data[7] == 0x11)) {
418+
419+
// TODO: handle actual incoming file data
420+
const uint32_t file_size = length - header_size;
421+
const uint8_t *file_data = data + header_size;
422+
UNUSED_VAR(file_size);
423+
UNUSED_VAR(file_data);
424+
// save file data here ...
425+
// TODO: handle actual incoming file data
426+
427+
const char *msg = "incoming group file";
428+
const size_t msg_length = strlen(msg);
429+
430+
for (size_t i = 0; i < MAX_WINDOWS_NUM; ++i) {
431+
if (windows[i] != NULL && windows[i]->onGroupMessage != NULL) {
432+
windows[i]->onGroupMessage(windows[i], tox, groupnumber, peer_id, TOX_MESSAGE_TYPE_NORMAL, msg, msg_length);
433+
}
434+
}
435+
}
436+
}
437+
}
438+
}
439+
397440
void on_group_message(Tox *tox, uint32_t groupnumber, uint32_t peer_id, TOX_MESSAGE_TYPE type,
398441
const uint8_t *message, size_t length, uint32_t message_id, void *userdata)
399442
{

0 commit comments

Comments
 (0)