/* @file WebsockUtil.cpp */

#include "WebsockUtil.hpp"

#define STRINGIFY(x) #x

namespace xo {
    namespace web {
        char const *
        WebsockUtil::ws_callback_reason_descr(lws_callback_reasons x) {

#define CASE(x) case x: return STRINGIFY(x)

            /* ubuntu build (available via github actions) has older version of libwebsockets.
             * typically building (e.g. via nix) with libwebsockets 4.3.2
             *
             * see lws_config.h for version numbers vars
             */

            switch (x) {
                CASE(LWS_CALLBACK_PROTOCOL_INIT);
                CASE(LWS_CALLBACK_PROTOCOL_DESTROY);
                CASE(LWS_CALLBACK_WSI_CREATE);
                CASE(LWS_CALLBACK_WSI_DESTROY);
                CASE(LWS_CALLBACK_WSI_TX_CREDIT_GET);
                CASE(LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS);
                CASE(LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS);
                CASE(LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION);
#ifdef OBSOLETE // at least on osx w/ nixpkgs dd868b7bd4d1407d607da0d1d9c5eca89132e2f7
                CASE(LWS_CALLBACK_OPENSSL_CONTEXT_REQUIRES_PRIVATE_KEY);
#endif
                CASE(LWS_CALLBACK_SSL_INFO);
                CASE(LWS_CALLBACK_OPENSSL_PERFORM_SERVER_CERT_VERIFICATION);
                CASE(LWS_CALLBACK_SERVER_NEW_CLIENT_INSTANTIATED);
                CASE(LWS_CALLBACK_HTTP);
                CASE(LWS_CALLBACK_HTTP_BODY);
                CASE(LWS_CALLBACK_HTTP_BODY_COMPLETION);
                CASE(LWS_CALLBACK_HTTP_FILE_COMPLETION);
                CASE(LWS_CALLBACK_HTTP_WRITEABLE);
                CASE(LWS_CALLBACK_CLOSED_HTTP);
                CASE(LWS_CALLBACK_FILTER_HTTP_CONNECTION);
                CASE(LWS_CALLBACK_ADD_HEADERS);
                CASE(LWS_CALLBACK_VERIFY_BASIC_AUTHORIZATION);
                CASE(LWS_CALLBACK_CHECK_ACCESS_RIGHTS);
                CASE(LWS_CALLBACK_PROCESS_HTML);
                CASE(LWS_CALLBACK_HTTP_BIND_PROTOCOL);
                CASE(LWS_CALLBACK_HTTP_DROP_PROTOCOL);
                CASE(LWS_CALLBACK_HTTP_CONFIRM_UPGRADE);
                CASE(LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP);
                CASE(LWS_CALLBACK_CLOSED_CLIENT_HTTP);
                CASE(LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ);
                CASE(LWS_CALLBACK_RECEIVE_CLIENT_HTTP);
                CASE(LWS_CALLBACK_COMPLETED_CLIENT_HTTP);
                CASE(LWS_CALLBACK_CLIENT_HTTP_WRITEABLE);
#if ((LWS_LIBRARY_VERSION_MAJOR > 4) || (LWS_LIBRARY_VERSION_MAJOR == 4) && (LWS_LIBRARY_VERSION_MINOR >= 3))
                CASE(LWS_CALLBACK_CLIENT_HTTP_REDIRECT);
#endif
                CASE(LWS_CALLBACK_CLIENT_HTTP_BIND_PROTOCOL);
                CASE(LWS_CALLBACK_CLIENT_HTTP_DROP_PROTOCOL);
                CASE(LWS_CALLBACK_ESTABLISHED);
                CASE(LWS_CALLBACK_CLOSED);
                CASE(LWS_CALLBACK_SERVER_WRITEABLE);
                CASE(LWS_CALLBACK_RECEIVE);
                CASE(LWS_CALLBACK_RECEIVE_PONG);
                CASE(LWS_CALLBACK_WS_PEER_INITIATED_CLOSE);
                CASE(LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION);
                CASE(LWS_CALLBACK_CONFIRM_EXTENSION_OKAY);
                CASE(LWS_CALLBACK_WS_SERVER_BIND_PROTOCOL);
                CASE(LWS_CALLBACK_WS_SERVER_DROP_PROTOCOL);
                CASE(LWS_CALLBACK_CLIENT_CONNECTION_ERROR);
                CASE(LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH);
                CASE(LWS_CALLBACK_CLIENT_ESTABLISHED);
                CASE(LWS_CALLBACK_CLIENT_CLOSED);
                CASE(LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER);
                CASE(LWS_CALLBACK_CLIENT_RECEIVE);
                CASE(LWS_CALLBACK_CLIENT_RECEIVE_PONG);
                CASE(LWS_CALLBACK_CLIENT_WRITEABLE);
                CASE(LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED);
                CASE(LWS_CALLBACK_WS_EXT_DEFAULTS);
                CASE(LWS_CALLBACK_FILTER_NETWORK_CONNECTION);
                CASE(LWS_CALLBACK_WS_CLIENT_BIND_PROTOCOL);
                CASE(LWS_CALLBACK_WS_CLIENT_DROP_PROTOCOL);
                CASE(LWS_CALLBACK_GET_THREAD_ID);
                CASE(LWS_CALLBACK_ADD_POLL_FD);
                CASE(LWS_CALLBACK_DEL_POLL_FD);
                CASE(LWS_CALLBACK_CHANGE_MODE_POLL_FD);
                CASE(LWS_CALLBACK_LOCK_POLL);
                CASE(LWS_CALLBACK_UNLOCK_POLL);
                CASE(LWS_CALLBACK_CGI);
                CASE(LWS_CALLBACK_CGI_TERMINATED);
                CASE(LWS_CALLBACK_CGI_STDIN_DATA);
                CASE(LWS_CALLBACK_CGI_STDIN_COMPLETED);
                CASE(LWS_CALLBACK_CGI_PROCESS_ATTACH);
                CASE(LWS_CALLBACK_SESSION_INFO);
                CASE(LWS_CALLBACK_GS_EVENT);
                CASE(LWS_CALLBACK_HTTP_PMO);
                CASE(LWS_CALLBACK_RAW_PROXY_CLI_RX);
                CASE(LWS_CALLBACK_RAW_PROXY_SRV_RX);
                CASE(LWS_CALLBACK_RAW_PROXY_CLI_CLOSE);
                CASE(LWS_CALLBACK_RAW_PROXY_SRV_CLOSE);
                CASE(LWS_CALLBACK_RAW_PROXY_CLI_WRITEABLE);
                CASE(LWS_CALLBACK_RAW_PROXY_SRV_WRITEABLE);
                CASE(LWS_CALLBACK_RAW_PROXY_CLI_ADOPT);
                CASE(LWS_CALLBACK_RAW_PROXY_SRV_ADOPT);
                CASE(LWS_CALLBACK_RAW_PROXY_CLI_BIND_PROTOCOL);
                CASE(LWS_CALLBACK_RAW_PROXY_SRV_BIND_PROTOCOL);
                CASE(LWS_CALLBACK_RAW_PROXY_CLI_DROP_PROTOCOL);
                CASE(LWS_CALLBACK_RAW_PROXY_SRV_DROP_PROTOCOL);
                CASE(LWS_CALLBACK_RAW_RX);
                CASE(LWS_CALLBACK_RAW_CLOSE);
                CASE(LWS_CALLBACK_RAW_WRITEABLE);
                CASE(LWS_CALLBACK_RAW_ADOPT);
                CASE(LWS_CALLBACK_RAW_CONNECTED);
                CASE(LWS_CALLBACK_RAW_SKT_BIND_PROTOCOL);
                CASE(LWS_CALLBACK_RAW_SKT_DROP_PROTOCOL);
                CASE(LWS_CALLBACK_RAW_ADOPT_FILE);
                CASE(LWS_CALLBACK_RAW_RX_FILE);
                CASE(LWS_CALLBACK_RAW_WRITEABLE_FILE);
                CASE(LWS_CALLBACK_RAW_CLOSE_FILE);
                CASE(LWS_CALLBACK_RAW_FILE_BIND_PROTOCOL);
                CASE(LWS_CALLBACK_RAW_FILE_DROP_PROTOCOL);
                CASE(LWS_CALLBACK_TIMER);
                CASE(LWS_CALLBACK_EVENT_WAIT_CANCELLED);
                CASE(LWS_CALLBACK_CHILD_CLOSING);
#if ((LWS_LIBRARY_VERSION_MAJOR > 4) || (LWS_LIBRARY_VERSION_MAJOR == 4) && (LWS_LIBRARY_VERSION_MINOR >= 3))
                CASE(LWS_CALLBACK_CONNECTING);
#endif
                CASE(LWS_CALLBACK_VHOST_CERT_AGING);
                CASE(LWS_CALLBACK_VHOST_CERT_UPDATE);
                CASE(LWS_CALLBACK_MQTT_NEW_CLIENT_INSTANTIATED);
                CASE(LWS_CALLBACK_MQTT_IDLE);
                CASE(LWS_CALLBACK_MQTT_CLIENT_ESTABLISHED);
                CASE(LWS_CALLBACK_MQTT_SUBSCRIBED);
                CASE(LWS_CALLBACK_MQTT_CLIENT_WRITEABLE);
                CASE(LWS_CALLBACK_MQTT_CLIENT_RX);
                CASE(LWS_CALLBACK_MQTT_UNSUBSCRIBED);
                CASE(LWS_CALLBACK_MQTT_DROP_PROTOCOL);
                CASE(LWS_CALLBACK_MQTT_CLIENT_CLOSED);
                CASE(LWS_CALLBACK_MQTT_ACK);
                CASE(LWS_CALLBACK_MQTT_RESEND);
#if ((LWS_LIBRARY_VERSION_MAJOR > 4) || (LWS_LIBRARY_VERSION_MAJOR == 4) && (LWS_LIBRARY_VERSION_MINOR >= 3))
                CASE(LWS_CALLBACK_MQTT_UNSUBSCRIBE_TIMEOUT);
                CASE(LWS_CALLBACK_MQTT_SHADOW_TIMEOUT);
#endif
                CASE(LWS_CALLBACK_USER);
            }

#undef CASE

            return "???";
        } /*ws_callback_reason_descr*/
    } /*namespace web*/
} /*namespace xo*/

/* end WebsockUtil.cpp */
