From fe7dc995d6c4f0b469ee21b27690e46b24a5666b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D1=83=D1=85=D0=B0=D1=80=D0=B8=D0=BA?= Date: Mon, 25 May 2015 23:09:09 +0300 Subject: [PATCH] use toxcore error codes --- src/core/core.cpp | 60 ++++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/src/core/core.cpp b/src/core/core.cpp index 6ac86e8e9..129f46be8 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -180,43 +180,49 @@ void Core::make_tox(QByteArray savedata) } } - tox = tox_new(&toxOptions, (uint8_t*)savedata.data(), savedata.size(), nullptr); - if (tox == nullptr) + TOX_ERR_NEW tox_err; + tox = tox_new(&toxOptions, (uint8_t*)savedata.data(), savedata.size(), &tox_err); + + switch (tox_err) { - if (enableIPv6) // Fallback to IPv4 - { - toxOptions.ipv6_enabled = false; - tox = tox_new(&toxOptions, (uint8_t*)savedata.data(), savedata.size(), nullptr); - if (tox == nullptr) + case TOX_ERR_NEW_OK: + break; + case TOX_ERR_NEW_PORT_ALLOC: + if (enableIPv6) { - if (toxOptions.proxy_type != TOX_PROXY_TYPE_NONE) + toxOptions.ipv6_enabled = false; + tox = tox_new(&toxOptions, (uint8_t*)savedata.data(), savedata.size(), &tox_err); + if (tox_err == TOX_ERR_NEW_OK) { - qCritical() << "bad proxy! no toxcore!"; - emit badProxy(); + qWarning() << "Core failed to start with IPv6, falling back to IPv4. LAN discovery may not work properly."; + break; } - else - { - qCritical() << "Tox core failed to start"; - emit failedToStart(); - } - return; } - else - { - qWarning() << "Core failed to start with IPv6, falling back to IPv4. LAN discovery may not work properly."; - } - } - else if (toxOptions.proxy_type != TOX_PROXY_TYPE_NONE) - { + + qCritical() << "can't to bind the port"; + emit failedToStart(); + return; + case TOX_ERR_NEW_PROXY_BAD_HOST: + case TOX_ERR_NEW_PROXY_BAD_PORT: + qCritical() << "bad proxy"; emit badProxy(); return; - } - else - { + case TOX_ERR_NEW_PROXY_NOT_FOUND: + qCritical() << "proxy not found"; + emit badProxy(); + return; + case TOX_ERR_NEW_LOAD_ENCRYPTED: + qCritical() << "load data is encrypted"; + emit failedToStart(); + return; + case TOX_ERR_NEW_LOAD_BAD_FORMAT: + qCritical() << "bad load data format"; + emit failedToStart(); + return; + default: qCritical() << "Tox core failed to start"; emit failedToStart(); return; - } } toxav = toxav_new(tox, TOXAV_MAX_CALLS);