diff options
author | irungentoo <irungentoo@gmail.com> | 2013-09-16 11:22:01 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-09-16 11:22:01 -0400 |
commit | 1d2f4465bf634f45704eb69791c45bd623154909 (patch) | |
tree | e226a52f72f75d3a5555f0afef26cbe2d99045f4 /toxcore/Messenger.c | |
parent | 98fb06c1b75a3bd5ad674daf5c0496a712bc0551 (diff) |
Toxcore should never print anything when built normally.
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r-- | toxcore/Messenger.c | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index f2be6008..cdc133d0 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -1393,6 +1393,7 @@ static int Messenger_load_old(Messenger *m, uint8_t *data, uint32_t length) | |||
1393 | length -= sizeof(nospam); | 1393 | length -= sizeof(nospam); |
1394 | 1394 | ||
1395 | uint32_t size; | 1395 | uint32_t size; |
1396 | |||
1396 | if (length < sizeof(size)) | 1397 | if (length < sizeof(size)) |
1397 | return -1; | 1398 | return -1; |
1398 | 1399 | ||
@@ -1404,8 +1405,11 @@ static int Messenger_load_old(Messenger *m, uint8_t *data, uint32_t length) | |||
1404 | return -1; | 1405 | return -1; |
1405 | 1406 | ||
1406 | if (DHT_load_old(m->dht, data, size) == -1) | 1407 | if (DHT_load_old(m->dht, data, size) == -1) |
1408 | #ifdef DEBUG | ||
1407 | fprintf(stderr, "Data file: Something wicked happened to the stored connections...\n"); | 1409 | fprintf(stderr, "Data file: Something wicked happened to the stored connections...\n"); |
1408 | /* DO go on, friends/name still might be intact */ | 1410 | |
1411 | #endif | ||
1412 | /* DO go on, friends/name still might be intact */ | ||
1409 | 1413 | ||
1410 | data += size; | 1414 | data += size; |
1411 | length -= size; | 1415 | length -= size; |
@@ -1425,6 +1429,7 @@ static int Messenger_load_old(Messenger *m, uint8_t *data, uint32_t length) | |||
1425 | Friend *friend_list = (Friend *)data; | 1429 | Friend *friend_list = (Friend *)data; |
1426 | 1430 | ||
1427 | uint32_t i; | 1431 | uint32_t i; |
1432 | |||
1428 | for (i = 0; i < num; ++i) { | 1433 | for (i = 0; i < num; ++i) { |
1429 | if (friend_list[i].status >= 3) { | 1434 | if (friend_list[i].status >= 3) { |
1430 | int fnum = m_addfriend_norequest(m, friend_list[i].client_id); | 1435 | int fnum = m_addfriend_norequest(m, friend_list[i].client_id); |
@@ -1478,11 +1483,11 @@ uint32_t Messenger_size(Messenger *m) | |||
1478 | { | 1483 | { |
1479 | uint32_t size32 = sizeof(uint32_t), sizesubhead = size32 * 2; | 1484 | uint32_t size32 = sizeof(uint32_t), sizesubhead = size32 * 2; |
1480 | return size32 * 2 // global cookie | 1485 | return size32 * 2 // global cookie |
1481 | + sizesubhead + sizeof(uint32_t) + crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES | 1486 | + sizesubhead + sizeof(uint32_t) + crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES |
1482 | + sizesubhead + DHT_size(m->dht) // DHT | 1487 | + sizesubhead + DHT_size(m->dht) // DHT |
1483 | + sizesubhead + sizeof(Friend) * m->numfriends // Friendlist itself. | 1488 | + sizesubhead + sizeof(Friend) * m->numfriends // Friendlist itself. |
1484 | + sizesubhead + m->name_length // Own nickname. | 1489 | + sizesubhead + m->name_length // Own nickname. |
1485 | ; | 1490 | ; |
1486 | } | 1491 | } |
1487 | 1492 | ||
1488 | static uint8_t *z_state_save_subheader(uint8_t *data, uint32_t len, uint16_t type) | 1493 | static uint8_t *z_state_save_subheader(uint8_t *data, uint32_t len, uint16_t type) |
@@ -1538,14 +1543,15 @@ void Messenger_save(Messenger *m, uint8_t *data) | |||
1538 | static int messenger_load_state_callback(void *outer, uint8_t *data, uint32_t length, uint16_t type) | 1543 | static int messenger_load_state_callback(void *outer, uint8_t *data, uint32_t length, uint16_t type) |
1539 | { | 1544 | { |
1540 | Messenger *m = outer; | 1545 | Messenger *m = outer; |
1541 | switch(type) { | 1546 | |
1547 | switch (type) { | ||
1542 | case MESSENGER_STATE_TYPE_NOSPAMKEYS: | 1548 | case MESSENGER_STATE_TYPE_NOSPAMKEYS: |
1543 | if (length == crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES + sizeof(uint32_t)) { | 1549 | if (length == crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES + sizeof(uint32_t)) { |
1544 | set_nospam(&(m->fr), *(uint32_t *)data); | 1550 | set_nospam(&(m->fr), *(uint32_t *)data); |
1545 | load_keys(m->net_crypto, &data[sizeof(uint32_t)]); | 1551 | load_keys(m->net_crypto, &data[sizeof(uint32_t)]); |
1546 | } | 1552 | } else |
1547 | else | ||
1548 | return -1; /* critical */ | 1553 | return -1; /* critical */ |
1554 | |||
1549 | break; | 1555 | break; |
1550 | 1556 | ||
1551 | case MESSENGER_STATE_TYPE_DHT: | 1557 | case MESSENGER_STATE_TYPE_DHT: |
@@ -1557,6 +1563,7 @@ static int messenger_load_state_callback(void *outer, uint8_t *data, uint32_t le | |||
1557 | uint16_t num = length / sizeof(Friend); | 1563 | uint16_t num = length / sizeof(Friend); |
1558 | Friend *friends = (Friend *)data; | 1564 | Friend *friends = (Friend *)data; |
1559 | uint32_t i; | 1565 | uint32_t i; |
1566 | |||
1560 | for (i = 0; i < num; ++i) { | 1567 | for (i = 0; i < num; ++i) { |
1561 | if (friends[i].status >= 3) { | 1568 | if (friends[i].status >= 3) { |
1562 | int fnum = m_addfriend_norequest(m, friends[i].client_id); | 1569 | int fnum = m_addfriend_norequest(m, friends[i].client_id); |
@@ -1573,17 +1580,21 @@ static int messenger_load_state_callback(void *outer, uint8_t *data, uint32_t le | |||
1573 | } | 1580 | } |
1574 | } | 1581 | } |
1575 | } | 1582 | } |
1583 | |||
1576 | break; | 1584 | break; |
1577 | 1585 | ||
1578 | case MESSENGER_STATE_TYPE_NAME: | 1586 | case MESSENGER_STATE_TYPE_NAME: |
1579 | if ((length > 0) && (length < MAX_NAME_LENGTH)) { | 1587 | if ((length > 0) && (length < MAX_NAME_LENGTH)) { |
1580 | setname(m, data, length); | 1588 | setname(m, data, length); |
1581 | } | 1589 | } |
1590 | |||
1582 | break; | 1591 | break; |
1583 | 1592 | ||
1584 | default: | 1593 | default: |
1594 | #ifdef DEBUG | ||
1585 | fprintf(stderr, "Load state: contains unrecognized part (len %u, type %u)\n", | 1595 | fprintf(stderr, "Load state: contains unrecognized part (len %u, type %u)\n", |
1586 | length, type); | 1596 | length, type); |
1597 | #endif | ||
1587 | } | 1598 | } |
1588 | 1599 | ||
1589 | return 0; | 1600 | return 0; |
@@ -1593,10 +1604,12 @@ static int messenger_load_state_callback(void *outer, uint8_t *data, uint32_t le | |||
1593 | int Messenger_load(Messenger *m, uint8_t *data, uint32_t length) | 1604 | int Messenger_load(Messenger *m, uint8_t *data, uint32_t length) |
1594 | { | 1605 | { |
1595 | uint32_t cookie_len = 2 * sizeof(uint32_t); | 1606 | uint32_t cookie_len = 2 * sizeof(uint32_t); |
1607 | |||
1596 | if (length < cookie_len) | 1608 | if (length < cookie_len) |
1597 | return -1; | 1609 | return -1; |
1598 | 1610 | ||
1599 | uint32_t *data32 = (uint32_t *)data; | 1611 | uint32_t *data32 = (uint32_t *)data; |
1612 | |||
1600 | if (!data32[0] && (data32[1] == MESSENGER_STATE_COOKIE_GLOBAL)) | 1613 | if (!data32[0] && (data32[1] == MESSENGER_STATE_COOKIE_GLOBAL)) |
1601 | return load_state(messenger_load_state_callback, m, data + cookie_len, | 1614 | return load_state(messenger_load_state_callback, m, data + cookie_len, |
1602 | length - cookie_len, MESSENGER_STATE_COOKIE_TYPE); | 1615 | length - cookie_len, MESSENGER_STATE_COOKIE_TYPE); |