LCOV - code coverage report
Current view: top level - source/lobby - GlooxConversion.cpp (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 0 103 0.0 %
Date: 2026-12-03 01:19:39 Functions: 0 6 0.0 %

          Line data    Source code
       1             : /* Copyright (C) 2026 Wildfire Games.
       2             :  * This file is part of 0 A.D.
       3             :  *
       4             :  * 0 A.D. is free software: you can redistribute it and/or modify
       5             :  * it under the terms of the GNU General Public License as published by
       6             :  * the Free Software Foundation, either version 2 of the License, or
       7             :  * (at your option) any later version.
       8             :  *
       9             :  * 0 A.D. is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12             :  * GNU General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU General Public License
      15             :  * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
      16             :  */
      17             : 
      18             : #include "precompiled.h"
      19             : 
      20             : #include "lib/config2.h"
      21             : #if CONFIG2_LOBBY
      22             : #include "GlooxConversion.h"
      23             : 
      24             : #include "i18n/L10n.h"
      25             : #include "ps/CLogger.h"
      26             : 
      27           0 : const char* GetPresenceString(const gloox::Presence::PresenceType presenceType)
      28             : {
      29           0 :     switch (presenceType)
      30             :     {
      31             : #define CASE(X,Y) case gloox::Presence::X: return Y
      32             :     CASE(Available, "available");
      33           0 :     CASE(Chat, "chat");
      34             :     CASE(Away, "away");
      35           0 :     CASE(DND, "playing");
      36             :     CASE(XA, "away");
      37           0 :     CASE(Unavailable, "offline");
      38           0 :     CASE(Probe, "probe");
      39           0 :     CASE(Error, "error");
      40           0 :     CASE(Invalid, "invalid");
      41           0 :     default:
      42           0 :         LOGERROR("Unknown presence type '{}'", static_cast<int>(presenceType));
      43           0 :         return "";
      44             : #undef CASE
      45             :     }
      46             : }
      47             : 
      48           0 : const char* GetRoleString(const gloox::MUCRoomRole role)
      49             : {
      50           0 :     switch (role)
      51             :     {
      52             : #define CASE(X, Y) case gloox::X: return Y
      53             :     CASE(RoleNone, "none");
      54           0 :     CASE(RoleVisitor, "visitor");
      55           0 :     CASE(RoleParticipant, "participant");
      56           0 :     CASE(RoleModerator, "moderator");
      57           0 :     CASE(RoleInvalid, "invalid");
      58           0 :     default:
      59           0 :         LOGERROR("Unknown role type '{}'", static_cast<int>(role));
      60           0 :         return "";
      61             : #undef CASE
      62             :     }
      63             : }
      64             : 
      65           0 : std::string StanzaErrorToString(gloox::StanzaError err)
      66             : {
      67             : #define CASE(X, Y) case gloox::X: return Y
      68             : #define DEBUG_CASE(X, Y) case gloox::X: return g_L10n.Translate("Error") + " (" + Y + ")"
      69           0 :     switch (err)
      70             :     {
      71           0 :     CASE(StanzaErrorUndefined, g_L10n.Translate("No error"));
      72           0 :     DEBUG_CASE(StanzaErrorBadRequest, "Server received malformed XML");
      73           0 :     CASE(StanzaErrorConflict, g_L10n.Translate("Player already logged in"));
      74           0 :     DEBUG_CASE(StanzaErrorFeatureNotImplemented, "Server does not implement requested feature");
      75           0 :     CASE(StanzaErrorForbidden, g_L10n.Translate("Forbidden"));
      76           0 :     DEBUG_CASE(StanzaErrorGone, "Unable to find message receipiant");
      77           0 :     CASE(StanzaErrorInternalServerError, g_L10n.Translate("Internal server error"));
      78           0 :     DEBUG_CASE(StanzaErrorItemNotFound, "Message receipiant does not exist");
      79           0 :     DEBUG_CASE(StanzaErrorJidMalformed, "JID (XMPP address) malformed");
      80           0 :     DEBUG_CASE(StanzaErrorNotAcceptable, "Receipiant refused message. Possible policy issue");
      81           0 :     CASE(StanzaErrorNotAllowed, g_L10n.Translate("Not allowed"));
      82           0 :     CASE(StanzaErrorNotAuthorized, g_L10n.Translate("Not authorized"));
      83           0 :     DEBUG_CASE(StanzaErrorNotModified, "Requested item has not changed since last request");
      84           0 :     DEBUG_CASE(StanzaErrorPaymentRequired, "This server requires payment");
      85           0 :     CASE(StanzaErrorRecipientUnavailable, g_L10n.Translate("Recipient temporarily unavailable"));
      86           0 :     DEBUG_CASE(StanzaErrorRedirect, "Request redirected");
      87           0 :     CASE(StanzaErrorRegistrationRequired, g_L10n.Translate("Registration required"));
      88           0 :     DEBUG_CASE(StanzaErrorRemoteServerNotFound, "Remote server not found");
      89           0 :     DEBUG_CASE(StanzaErrorRemoteServerTimeout, "Remote server timed out");
      90           0 :     DEBUG_CASE(StanzaErrorResourceConstraint,
      91             :         "The recipient is unable to process the message due to resource constraints");
      92           0 :     CASE(StanzaErrorServiceUnavailable, g_L10n.Translate("Service unavailable"));
      93           0 :     DEBUG_CASE(StanzaErrorSubscribtionRequired, "Service requires subscription");
      94           0 :     DEBUG_CASE(StanzaErrorUnexpectedRequest, "Attempt to send from invalid stanza address");
      95           0 :     DEBUG_CASE(StanzaErrorUnknownSender, "Invalid 'from' address");
      96           0 :     default:
      97           0 :         return g_L10n.Translate("Unknown error");
      98             :     }
      99             : #undef DEBUG_CASE
     100             : #undef CASE
     101             : }
     102             : 
     103           0 : std::string ConnectionErrorToString(gloox::ConnectionError err)
     104             : {
     105             : #define CASE(X, Y) case gloox::X: return Y
     106             : #define DEBUG_CASE(X, Y) case gloox::X: return g_L10n.Translate("Error") + " (" + Y + ")"
     107           0 :     switch (err)
     108             :     {
     109           0 :     CASE(ConnNoError, g_L10n.Translate("No error"));
     110           0 :     CASE(ConnStreamError, g_L10n.Translate("Stream error"));
     111           0 :     CASE(ConnStreamVersionError, g_L10n.Translate("The incoming stream version is unsupported"));
     112           0 :     CASE(ConnStreamClosed, g_L10n.Translate("The stream has been closed by the server"));
     113           0 :     DEBUG_CASE(ConnProxyAuthRequired, "The HTTP/SOCKS5 proxy requires authentication");
     114           0 :     DEBUG_CASE(ConnProxyAuthFailed, "HTTP/SOCKS5 proxy authentication failed");
     115           0 :     DEBUG_CASE(ConnProxyNoSupportedAuth,
     116             :         "The HTTP/SOCKS5 proxy requires an unsupported authentication mechanism");
     117           0 :     CASE(ConnIoError, g_L10n.Translate("An I/O error occurred"));
     118           0 :     DEBUG_CASE(ConnParseError, "An XML parse error occurred");
     119           0 :     CASE(ConnConnectionRefused, g_L10n.Translate("The connection was refused by the server"));
     120           0 :     CASE(ConnDnsError, g_L10n.Translate("Resolving the server's hostname failed"));
     121           0 :     CASE(ConnOutOfMemory, g_L10n.Translate("This system is out of memory"));
     122           0 :     DEBUG_CASE(ConnNoSupportedAuth, "The authentication mechanisms the server offered are not supported "
     123             :         "or no authentication mechanisms were available");
     124           0 :     CASE(ConnTlsFailed, g_L10n.Translate("The server's certificate could not be verified or the TLS "
     125             :         "handshake did not complete successfully"));
     126           0 :     CASE(ConnTlsNotAvailable, g_L10n.Translate("The server did not offer required TLS encryption"));
     127           0 :     DEBUG_CASE(ConnCompressionFailed, "Negotiation/initializing compression failed");
     128           0 :     CASE(ConnAuthenticationFailed,
     129             :         g_L10n.Translate("Authentication failed. Incorrect password or account does not exist"));
     130           0 :     CASE(ConnUserDisconnected, g_L10n.Translate("The user or system requested a disconnect"));
     131           0 :     CASE(ConnNotConnected, g_L10n.Translate("There is no active connection"));
     132           0 :     default:
     133           0 :         return g_L10n.Translate("Unknown error");
     134             :     }
     135             : #undef DEBUG_CASE
     136             : #undef CASE
     137             : }
     138             : 
     139           0 : std::string RegistrationResultToString(gloox::RegistrationResult res)
     140             : {
     141             : #define CASE(X, Y) case gloox::X: return Y
     142             : #define DEBUG_CASE(X, Y) case gloox::X: return g_L10n.Translate("Error") + " (" + Y + ")"
     143           0 :     switch (res)
     144             :     {
     145           0 :     CASE(RegistrationSuccess, g_L10n.Translate("Your account has been successfully registered"));
     146           0 :     CASE(RegistrationNotAcceptable, g_L10n.Translate("Not all necessary information provided"));
     147           0 :     CASE(RegistrationConflict, g_L10n.Translate("Username already exists"));
     148           0 :     DEBUG_CASE(RegistrationNotAuthorized, "Account removal timeout or insufficiently secure channel for password change");
     149           0 :     DEBUG_CASE(RegistrationBadRequest, "Server received an incomplete request");
     150           0 :     DEBUG_CASE(RegistrationForbidden, "Registration forbidden");
     151           0 :     DEBUG_CASE(RegistrationRequired, "Account cannot be removed as it does not exist");
     152           0 :     DEBUG_CASE(RegistrationUnexpectedRequest, "This client is unregistered with the server");
     153           0 :     DEBUG_CASE(RegistrationNotAllowed, "Server does not permit password changes");
     154           0 :     default:
     155           0 :         return "";
     156             :     }
     157             : #undef DEBUG_CASE
     158             : #undef CASE
     159             : }
     160             : 
     161           0 : std::string CertificateErrorToString(gloox::CertStatus status)
     162             : {
     163           0 :     std::map<gloox::CertStatus, std::string> certificateErrorStrings = {
     164           0 :         { gloox::CertInvalid, g_L10n.Translate("The certificate is not trusted.") },
     165           0 :         { gloox::CertSignerUnknown, g_L10n.Translate("The certificate hasn't got a known issuer.") },
     166           0 :         { gloox::CertRevoked, g_L10n.Translate("The certificate has been revoked.") },
     167           0 :         { gloox::CertExpired, g_L10n.Translate("The certificate has expired.") },
     168           0 :         { gloox::CertNotActive, g_L10n.Translate("The certificate is not yet active.") },
     169           0 :         { gloox::CertWrongPeer,
     170           0 :             g_L10n.Translate("The certificate has not been issued for the peer connected to.") },
     171           0 :         { gloox::CertSignerNotCa,
     172           0 :             g_L10n.Translate("The certificate signer is not a certificate authority.") }
     173           0 :     };
     174             : 
     175           0 :     std::string result;
     176             : 
     177           0 :     for (std::map<gloox::CertStatus, std::string>::iterator it = certificateErrorStrings.begin();
     178           0 :         it != certificateErrorStrings.end(); ++it)
     179             :     {
     180           0 :         if (status & it->first)
     181           0 :             result += "\n" + it->second;
     182             :     }
     183             : 
     184           0 :     return result;
     185           0 : }
     186             : 
     187             : #endif // CONFIG2_LOBBY

Generated by: LCOV version 1.16