libmp/src/error.c

56 lines
3.7 KiB
C
Raw Normal View History

2024-06-20 00:34:32 +00:00
#include "../include/error.h"
#include "../include/util.h"
#include <stdlib.h>
lm_error_t error = LM_ERR_NoError;
2024-06-20 22:36:56 +00:00
void lm_error_set(lm_error_t code) {
2024-06-20 00:34:32 +00:00
error = code;
}
2024-06-20 22:36:56 +00:00
char *lm_strerror() {
2024-06-20 00:34:32 +00:00
lm_error_desc_t errors[] = {
2024-06-21 01:42:51 +00:00
{.code = LM_ERR_NoError, .desc = _("no error") },
{.code = LM_ERR_URLBadChar, .desc = _("URL contains an invalid character") },
{.code = LM_ERR_URLBadProtocol, .desc = _("URL does not have a valid protocol field") },
{.code = LM_ERR_URLTooLarge, .desc = _("URL is too large") },
{.code = LM_ERR_URLHostLarge, .desc = _("URL hostname is too large") },
{.code = LM_ERR_URLPathLarge, .desc = _("URL path is too large") },
{.code = LM_ERR_URLBadHost, .desc = _("URL does not have a valid hostname") },
2024-06-22 04:03:17 +00:00
{.code = LM_ERR_URLBadPort, .desc = _("URL does not have a valid port number") },
2024-06-21 01:42:51 +00:00
{.code = LM_ERR_URLBadPath, .desc = _("URL does not have a valid path") },
2024-06-22 04:03:17 +00:00
{.code = LM_ERR_BadPort, .desc = _("hostname does not contain a valid port number")},
{.code = LM_ERR_BadHost, .desc = _("hostname is not valid")},
2024-06-21 01:42:51 +00:00
{.code = LM_ERR_URLPortUnknown, .desc = _("URL protocol port number is unknown") },
{.code = LM_ERR_URLEnd, .desc = _("URL is incomplete") },
{.code = LM_ERR_PoolNoSupport, .desc = _("pool does not support the specified protocol") },
{.code = LM_ERR_MPTPBadVersion, .desc = _("unsupported MPTP version") },
{.code = LM_ERR_MPTPBadCode, .desc = _("invalid MPTP request/response code") },
{.code = LM_ERR_MPTPBadUrl, .desc = _("invalid MPTP URL") },
2024-06-22 01:18:00 +00:00
{.code = LM_ERR_MPTPHostFail, .desc = _("failed to resolve hostname for MPTP connection") },
2024-06-21 01:42:51 +00:00
{.code = LM_ERR_MPTPSocketFail, .desc = _("failed to create a MPTP socket") },
{.code = LM_ERR_MPTPConnectFail, .desc = _("failed to connect to the MPTP host") },
{.code = LM_ERR_MPTPRecvFail, .desc = _("failed receive MPTP data from host") },
{.code = LM_ERR_MPTPSendFail, .desc = _("failed send MPTP data to host") },
2024-06-22 04:03:17 +00:00
{.code = LM_ERR_MPTPBadChunk, .desc = _("MPTP data chunk size is invalid") },
2024-06-21 01:42:51 +00:00
{.code = LM_ERR_MPTPSetsockopt, .desc = _("failed to set MPTP socket options") },
{.code = LM_ERR_MPTPTimeout, .desc = _("MPTP connection timed out") },
2024-06-22 01:18:00 +00:00
{.code = LM_ERR_MPTPBindFail, .desc = _("failed to bind MPTP socket") },
{.code = LM_ERR_ArgNULL, .desc = _("required argument is a NULL pointer") },
2024-06-22 04:03:17 +00:00
{.code = LM_ERR_MPTPNotRequest, .desc = _("not a MPTP request") },
{.code = LM_ERR_MPTPNotResponse, .desc = _("not a MPTP response") },
{.code = LM_ERR_MPTPNotLast, .desc = _("MPTP request last flag is not set") },
{.code = LM_ERR_NoPort, .desc = _("host port not specified") },
2024-06-20 00:34:32 +00:00
};
2024-06-20 22:36:56 +00:00
for (int i = 0; i < sizeof(errors) / sizeof(lm_error_desc_t); i++) {
if (errors[i].code == error)
2024-06-20 00:34:32 +00:00
return errors[i].desc;
}
return NULL;
}
2024-06-20 22:36:56 +00:00
lm_error_t lm_error() {
2024-06-20 00:34:32 +00:00
return error;
}