Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 13 additions & 20 deletions auto_tests/messenger_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,12 @@
static bool enable_broken_tests = false;

static const char *friend_id_str = "e4b3d5030bc99494605aecc33ceec8875640c1d74aa32790e821b17e98771c4a00000000f1db";
static const char *good_id_str = "d3f14b6d384d8f5f2a66cff637e69f28f539c5de61bc29744785291fa4ef4d64";
static const char *bad_id_str = "9B569D14ff637e69f2";

/* in case we need more than one ID for a test */
static const char *good_id_a_str = "DB9B569D14850ED8364C3744CAC2C8FF78985D213E980C7C508D0E91E8E45441";
static const char *good_id_b_str = "d3f14b6d384d8f5f2a66cff637e69f28f539c5de61bc29744785291fa4ef4d64";

static const char *bad_id_str = "9B569D14ff637e69f2";

static unsigned char *friend_id = nullptr;
static unsigned char *good_id_a = nullptr;
static unsigned char *good_id_b = nullptr;
static unsigned char *bad_id = nullptr;
static uint8_t *friend_id = nullptr;
static uint8_t *good_id = nullptr;
static uint8_t *bad_id = nullptr;

static int friend_id_num = 0;

Expand Down Expand Up @@ -146,24 +141,24 @@ START_TEST(test_m_addfriend)
+ crypto_box_ZEROBYTES + 100);

/* TODO(irungentoo): Update this properly to latest master */
if (m_addfriend(m, (const uint8_t *)friend_id, (const uint8_t *)good_data, really_bad_len) != FAERR_TOOLONG) {
if (m_addfriend(m, friend_id, (const uint8_t *)good_data, really_bad_len) != FAERR_TOOLONG) {
ck_abort_msg("m_addfriend did NOT catch the following length: %d\n", really_bad_len);
}

/* this will return an error if the original m_addfriend_norequest() failed */
if (m_addfriend(m, (const uint8_t *)friend_id, (const uint8_t *)good_data, good_len) != FAERR_ALREADYSENT) {
if (m_addfriend(m, friend_id, (const uint8_t *)good_data, good_len) != FAERR_ALREADYSENT) {
ck_abort_msg("m_addfriend did NOT catch adding a friend we already have.\n"
"(this can be caused by the error of m_addfriend_norequest in"
" the beginning of the suite)\n");
}

if (m_addfriend(m, (const uint8_t *)good_id_b, (const uint8_t *)bad_data, bad_len) != FAERR_NOMESSAGE) {
if (m_addfriend(m, good_id, (const uint8_t *)bad_data, bad_len) != FAERR_NOMESSAGE) {
ck_abort_msg("m_addfriend did NOT catch the following length: %d\n", bad_len);
}

/* this should REALLY return an error */
/* TODO(irungentoo): validate client_id in m_addfriend? */
if (m_addfriend(m, (const uint8_t *)bad_id, (const uint8_t *)good_data, good_len) >= 0) {
if (m_addfriend(m, bad_id, (const uint8_t *)good_data, good_len) >= 0) {
ck_abort_msg("The following ID passed through "
"m_addfriend without an error:\n'%s'\n", bad_id_str);
}
Expand Down Expand Up @@ -348,8 +343,7 @@ int main(void)
setvbuf(stdout, nullptr, _IONBF, 0);

friend_id = hex_string_to_bin(friend_id_str);
good_id_a = hex_string_to_bin(good_id_a_str);
good_id_b = hex_string_to_bin(good_id_b_str);
good_id = hex_string_to_bin(good_id_str);
bad_id = hex_string_to_bin(bad_id_str);

/* IPv6 status from global define */
Expand All @@ -361,13 +355,13 @@ int main(void)
m = new_messenger(&options, nullptr);

/* setup a default friend and friendnum */
if (m_addfriend_norequest(m, (uint8_t *)friend_id) < 0) {
if (m_addfriend_norequest(m, friend_id) < 0) {
fputs("m_addfriend_norequest() failed on a valid ID!\n"
"this was CRITICAL to the test, and the build WILL fail.\n"
"the tests will continue now...\n\n", stderr);
}

if ((friend_id_num = getfriend_id(m, (uint8_t *)friend_id)) < 0) {
if ((friend_id_num = getfriend_id(m, friend_id)) < 0) {
fputs("getfriend_id() failed on a valid ID!\n"
"this was CRITICAL to the test, and the build WILL fail.\n"
"the tests will continue now...\n\n", stderr);
Expand All @@ -382,8 +376,7 @@ int main(void)

srunner_free(test_runner);
free(friend_id);
free(good_id_a);
free(good_id_b);
free(good_id);
free(bad_id);

kill_messenger(m);
Expand Down
2 changes: 1 addition & 1 deletion toxav/msi.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ int msi_kill(MSISession *session, const Logger *log)
return -1;
}

m_callback_msi_packet((struct Messenger *) session->messenger, nullptr, nullptr);
m_callback_msi_packet(session->messenger, nullptr, nullptr);

if (pthread_mutex_trylock(session->mutex) != 0) {
LOGGER_ERROR(session->messenger->log, "Failed to acquire lock on msi mutex");
Expand Down
12 changes: 6 additions & 6 deletions toxav/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ VCSession *vc_new(const Logger *log, ToxAV *av, uint32_t friend_number, toxav_vi
vpx_codec_destroy(vc->decoder);
BASE_CLEANUP:
pthread_mutex_destroy(vc->queue_mutex);
rb_kill((RingBuffer *)vc->vbuf_raw);
rb_kill(vc->vbuf_raw);
free(vc);
return nullptr;
}
Expand All @@ -283,11 +283,11 @@ void vc_kill(VCSession *vc)
vpx_codec_destroy(vc->decoder);
void *p;

while (rb_read((RingBuffer *)vc->vbuf_raw, &p)) {
while (rb_read(vc->vbuf_raw, &p)) {
free(p);
}

rb_kill((RingBuffer *)vc->vbuf_raw);
rb_kill(vc->vbuf_raw);
pthread_mutex_destroy(vc->queue_mutex);
LOGGER_DEBUG(vc->log, "Terminated video handler: %p", (void *)vc);
free(vc);
Expand All @@ -303,7 +303,7 @@ void vc_iterate(VCSession *vc)

struct RTPMessage *p;

if (!rb_read((RingBuffer *)vc->vbuf_raw, (void **)&p)) {
if (!rb_read(vc->vbuf_raw, (void **)&p)) {
LOGGER_TRACE(vc->log, "no Video frame data available");
pthread_mutex_unlock(vc->queue_mutex);
return;
Expand All @@ -323,7 +323,7 @@ void vc_iterate(VCSession *vc)
}

LOGGER_DEBUG(vc->log, "vc_iterate: rb_read p->len=%d p->header.xe=%d", (int)full_data_len, p->header.xe);
LOGGER_DEBUG(vc->log, "vc_iterate: rb_read rb size=%d", (int)rb_size((RingBuffer *)vc->vbuf_raw));
LOGGER_DEBUG(vc->log, "vc_iterate: rb_read rb size=%d", (int)rb_size(vc->vbuf_raw));
const vpx_codec_err_t rc = vpx_codec_decode(vc->decoder, p->data, full_data_len, nullptr, MAX_DECODE_TIME_US);
free(p);

Expand Down Expand Up @@ -378,7 +378,7 @@ int vc_queue_message(void *vcp, struct RTPMessage *msg)
LOGGER_DEBUG(vc->log, "rb_write msg->len=%d b0=%d b1=%d", (int)msg->len, (int)msg->data[0], (int)msg->data[1]);
}

free(rb_write((RingBuffer *)vc->vbuf_raw, msg));
free(rb_write(vc->vbuf_raw, msg));

/* Calculate time it took for peer to send us this frame */
uint32_t t_lcfd = current_time_monotonic() - vc->linfts;
Expand Down