#include "../include/error.h" #include "../include/util.h" #include lm_error_t error = LM_ERR_NoError; void lm_error_set(lm_error_t code) { error = code; } char *lm_strerror() { lm_error_desc_t errors[] = { {.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") }, {.code = LM_ERR_URLBadPort, .desc = _("URL does not have a valid port number") }, {.code = LM_ERR_URLBadPath, .desc = _("URL does not have a valid path") }, {.code = LM_ERR_BadPort, .desc = _("hostname does not contain a valid port number") }, {.code = LM_ERR_BadHost, .desc = _("hostname is not valid") }, {.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") }, {.code = LM_ERR_MPTPHostFail, .desc = _("failed to resolve hostname for MPTP connection") }, {.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") }, {.code = LM_ERR_MPTPBadData, .desc = _("MPTP data size is invalid") }, {.code = LM_ERR_MPTPBadHost, .desc = _("MPTP host size is invalid") }, {.code = LM_ERR_MPTPSetsockopt, .desc = _("failed to set MPTP socket options") }, {.code = LM_ERR_MPTPTimeout, .desc = _("MPTP connection timed out") }, {.code = LM_ERR_MPTPBindFail, .desc = _("failed to bind MPTP socket") }, {.code = LM_ERR_ArgNULL, .desc = _("required argument is a NULL pointer or 0") }, {.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") }, {.code = LM_ERR_PoolInfoBad, .desc = _("pool info is badly formatted or is not complete") }, {.code = LM_ERR_ArcWBlockFail, .desc = _("failed to write block from archive") }, {.code = LM_ERR_ArcRBlockFail, .desc = _("failed to read block from archive") }, {.code = LM_ERR_ArcOpenFail, .desc = _("failed to open archive") }, {.code = LM_ERR_ArcWHeaderFail, .desc = _("failed to write archive header") }, {.code = LM_ERR_ArcWEntryFail, .desc = _("failed to finish writing the archive entry") }, {.code = LM_ERR_ArcNewFail, .desc = _("failed to create new archive reader/writer") }, {.code = LM_ERR_ArcRealpathFail, .desc = _("failed to resolve full path for archive file") }, {.code = LM_ERR_ArcNextHeaderFail, .desc = _("failed to read the next header of the archive") }, {.code = LM_ERR_GetCwdFail, .desc = _("failed to obtain current working directory") }, {.code = LM_ERR_PoolListDirFail, .desc = _("failed to open extracted pool list directory") }, {.code = LM_ERR_PoolListCantRead, .desc = _("failed to read access the pool list file") }, {.code = LM_ERR_PoolInfoCantRead, .desc = _("failed to read access the pool info file") }, {.code = LM_ERR_PkgDataBad, .desc = _("failed to parse package data") }, {.code = LM_ERR_PkgBadName, .desc = _("package name is invalid") }, {.code = LM_ERR_CtxDataNULL, .desc = _("data path is not set with in the ctx") }, {.code = LM_ERR_CtxTempFail, .desc = _("specified temp path does not exist") }, {.code = LM_ERR_CtxTempNotDir, .desc = _("specified temp path is not a directory") }, {.code = LM_ERR_CtxTempNoWrite, .desc = _("specified temp directory does not have write access") }, {.code = LM_ERR_CtxRootFail, .desc = _("specified root path does not exist") }, {.code = LM_ERR_CtxRootNotDir, .desc = _("specified root path is not a directory") }, {.code = LM_ERR_CtxRootNoWrite, .desc = _("specified root directory does not have write access") }, {.code = LM_ERR_CtxDataNotDir, .desc = _("specified data path does not exist") }, {.code = LM_ERR_CtxDataNoWrite, .desc = _("specified data path is not a directory") }, {.code = LM_ERR_CtxDataFailMkdir, .desc = _("failed to create specified data directory") }, {.code = LM_ERR_PoolTestNotPong, .desc = _("pool did not respond ping with pong") }, {.code = LM_ERR_PkgPathsEmpty, .desc = _("package file and directory paths are empty") }, {.code = LM_ERR_SendOpenFail, .desc = _("failed to to open target file for sending") }, {.code = LM_ERR_RecvDelFail, .desc = _("failed to to delete target file for receiving") }, {.code = LM_ERR_RecvOpenFail, .desc = _("failed to to open target file for receiving") }, {.code = LM_ERR_RecvBadCode, .desc = _("got a bad response code for receiving the target file") }, {.code = LM_ERR_RecvWriteFail, .desc = _("failed to write to the target file for receiving") }, {.code = LM_ERR_PkgNotFound, .desc = _("package not found") }, {.code = LM_ERR_DbCantAccess, .desc = _("failed to access to the database file/directory") }, {.code = LM_ERR_DbSqlOpenFail, .desc = _("failed to open SQLite database") }, {.code = LM_ERR_DbSqlCreateFail, .desc = _("failed to create table in SQLite database") }, {.code = LM_ERR_DbSqlPrepareFail, .desc = _("failed to prepare statement for SQLite database") }, {.code = LM_ERR_DbSqlInsertFail, .desc = _("failed to insert to the table in SQLite database") }, {.code = LM_ERR_PkgGPGFail, .desc = _("failed to init GPG for package verification") }, {.code = LM_ERR_PkgGPGSigFail, .desc = _("failed to import signature to GPG for package verification")}, {.code = LM_ERR_PkgGPGArchiveFail, .desc = _("failed to import archive to GPG for package verification") }, {.code = LM_ERR_PkgSigNoMatch, .desc = _("package signature verification failed with zero matches") }, {.code = LM_ERR_PkgSigNoResult, .desc = _("package signature verification failed with zero results") }, {.code = LM_ERR_PoolPathsEmpty, .desc = _("pool file and directory paths are empty") }, {.code = LM_ERR_PoolNotAvailable, .desc = _("pool is not avaliable for connection") }, {.code = LM_ERR_PoolUrlEmpty, .desc = _("pool URL is empty or invalid") }, {.code = LM_ERR_PoolBadDir, .desc = _("pool directory path is not accessible") }, {.code = LM_ERR_PoolBadPaths, .desc = _("pool directory sub-paths are not accessible") }, }; for (int i = 0; i < sizeof(errors) / sizeof(lm_error_desc_t); i++) { if (errors[i].code == error) return errors[i].desc; } return NULL; } lm_error_t lm_error() { return error; }