mirror of
https://gitlab.xiph.org/xiph/icecast-common.git
synced 2024-12-04 14:46:31 -05:00
Merge branch 'feature-error' into libigloo
This commit is contained in:
commit
2e8e00739c
@ -28,6 +28,7 @@ pkginclude_HEADERS = \
|
|||||||
include/igloo/logmsg.h \
|
include/igloo/logmsg.h \
|
||||||
include/igloo/buffer.h \
|
include/igloo/buffer.h \
|
||||||
include/igloo/list.h \
|
include/igloo/list.h \
|
||||||
|
include/igloo/error.h \
|
||||||
include/igloo/reportxml.h
|
include/igloo/reportxml.h
|
||||||
|
|
||||||
libigloo_la_SOURCES = \
|
libigloo_la_SOURCES = \
|
||||||
@ -42,6 +43,7 @@ libigloo_la_SOURCES = \
|
|||||||
src/logmsg.c \
|
src/logmsg.c \
|
||||||
src/buffer.c \
|
src/buffer.c \
|
||||||
src/list.c \
|
src/list.c \
|
||||||
|
src/error.c \
|
||||||
src/reportxml.c \
|
src/reportxml.c \
|
||||||
src/timing.c
|
src/timing.c
|
||||||
libigloo_la_LIBADD = \
|
libigloo_la_LIBADD = \
|
||||||
|
73
include/igloo/error.h
Normal file
73
include/igloo/error.h
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
/* Copyright (C) 2019 Philipp "ph3-der-loewe" Schafft <lion@lion.leolix.org>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the
|
||||||
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||||
|
* Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _LIBIGLOO__ERROR_H_
|
||||||
|
#define _LIBIGLOO__ERROR_H_
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Put a good description of this file here
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Put stuff here */
|
||||||
|
|
||||||
|
#include <igloo/config.h>
|
||||||
|
#include <igloo/types.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
igloo_error_t error;
|
||||||
|
const char *uuid;
|
||||||
|
const char *name;
|
||||||
|
const char *message;
|
||||||
|
const char *description;
|
||||||
|
} igloo_error_desc_t;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NOTE: The following lines bust keep their exact formating as it is used for code generation!
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define igloo_ERROR_GENERIC ((igloo_error_t)-1) /* Generic error: A generic error occurred. */
|
||||||
|
#define igloo_ERROR_NONE ((igloo_error_t)0) /* No error: The operation succeeded. */
|
||||||
|
|
||||||
|
#define igloo_ERROR_FAULT ((igloo_error_t)1) /* Invalid address */
|
||||||
|
#define igloo_ERROR_INVAL ((igloo_error_t)2) /* Invalid argument */
|
||||||
|
#define igloo_ERROR_BUSY ((igloo_error_t)3) /* Device or resource busy */
|
||||||
|
#define igloo_ERROR_AGAIN ((igloo_error_t)4) /* Try again later */
|
||||||
|
#define igloo_ERROR_NOMEM ((igloo_error_t)5) /* Not enough space: Memory allocation failed. */
|
||||||
|
#define igloo_ERROR_NOENT ((igloo_error_t)6) /* Node does not exist: File, directory, object, or node does not exist. */
|
||||||
|
#define igloo_ERROR_EXIST ((igloo_error_t)7) /* Node exists: Object, or node already exists. */
|
||||||
|
#define igloo_ERROR_PERM ((igloo_error_t)8) /* Operation not permitted */
|
||||||
|
#define igloo_ERROR_CONNECTED ((igloo_error_t)9) /* Already connected: The operation can not be completed while object is connected. */
|
||||||
|
#define igloo_ERROR_UNCONNECTED ((igloo_error_t)10) /* Unconnected: The operation can not be completed while object is not connected. */
|
||||||
|
#define igloo_ERROR_IO ((igloo_error_t)11) /* Input/output error */
|
||||||
|
#define igloo_ERROR_CANNOTCONNECT ((igloo_error_t)12) /* Can not connect: Can not connect to remote resource. */
|
||||||
|
#define igloo_ERROR_NOLOGIN ((igloo_error_t)13) /* Can not login: Can not log into service. */
|
||||||
|
#define igloo_ERROR_NOTSECURE ((igloo_error_t)14) /* Connection, or object not secure: Connection, or object is not on required security level. */
|
||||||
|
#define igloo_ERROR_BADCERT ((igloo_error_t)15) /* Bad certificate */
|
||||||
|
|
||||||
|
const igloo_error_desc_t * igloo_error_get_description(igloo_error_t error);
|
||||||
|
const igloo_error_desc_t * igloo_error_getbyname(const char *name);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* ! _LIBIGLOO__ERROR_H_ */
|
@ -29,6 +29,11 @@ extern "C" {
|
|||||||
/* For size_t and ssize_t */
|
/* For size_t and ssize_t */
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
/* for {,u}int_{,least}{8,16,32,64}_t */
|
||||||
|
#ifdef IGLOO_CTC_HAVE_STDINT_H
|
||||||
|
#include <stdint.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <igloo/config.h>
|
#include <igloo/config.h>
|
||||||
|
|
||||||
/* Included in case is not yet included */
|
/* Included in case is not yet included */
|
||||||
@ -52,6 +57,13 @@ typedef struct igloo_reportxml_database_tag igloo_reportxml_database_t;
|
|||||||
typedef struct igloo_ro_base_tag igloo_ro_base_t;
|
typedef struct igloo_ro_base_tag igloo_ro_base_t;
|
||||||
igloo_RO_FORWARD_TYPE(igloo_ro_base_t);
|
igloo_RO_FORWARD_TYPE(igloo_ro_base_t);
|
||||||
|
|
||||||
|
/* For error.h */
|
||||||
|
#ifdef IGLOO_CTC_HAVE_STDINT_H
|
||||||
|
typedef int_least16_t igloo_error_t;
|
||||||
|
#else
|
||||||
|
typedef long int igloo_error_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef IGLOO_CTC_HAVE_TYPE_ATTRIBUTE_TRANSPARENT_UNION
|
#ifdef IGLOO_CTC_HAVE_TYPE_ATTRIBUTE_TRANSPARENT_UNION
|
||||||
typedef union __attribute__ ((__transparent_union__)) {
|
typedef union __attribute__ ((__transparent_union__)) {
|
||||||
/* Those are libigloo's own types */
|
/* Those are libigloo's own types */
|
||||||
|
144
src/error.c
Normal file
144
src/error.c
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
/* Icecast
|
||||||
|
*
|
||||||
|
* This program is distributed under the GNU General Public License, version 2.
|
||||||
|
* A copy of this license is included with this source.
|
||||||
|
*
|
||||||
|
* Copyright 2019, Philipp "ph3-der-loewe" Schafft <lion@lion.leolix.org>,
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <igloo/error.h>
|
||||||
|
#include <igloo/types.h>
|
||||||
|
|
||||||
|
#define ERROR_BASE(x) .error = igloo_ERROR_ ## x, .name = # x
|
||||||
|
|
||||||
|
// grep '^#define igloo_ERROR_' include/igloo/error.h | sed 's/^#define igloo_ERROR_\([^ ]*\) \+[^ ]\+ */\1::/; s/::\/\* \+\([^:]\+\): \+\(.\+\) \+\*\//:\1:\2/; s/::\/\* \+\([^:]\+\) \+\*\//:\1:/' | while IFS=: read name message description; do uuid=$(uuid -v 5 c4ce7102-4f5b-4421-9fb7-adbb299e336e "$name"); p=' '; printf "$p{\n$p${p}ERROR_BASE(%s),\n" "$name"; [ -n "$message" ] && printf "$p$p.message = \"%s\",\n" "$message"; [ -n "$description" ] && printf "$p$p.description = \"%s\",\n" "$description"; printf "$p$p.uuid = \"%s\"\n$p},\n" "$uuid"; done | sed '$s/,$//'
|
||||||
|
static const igloo_error_desc_t __desc[] = {
|
||||||
|
{
|
||||||
|
ERROR_BASE(GENERIC),
|
||||||
|
.message = "Generic error",
|
||||||
|
.description = "A generic error occurred.",
|
||||||
|
.uuid = "4f4dfebc-0b86-51e7-8233-73ff1c4707cf"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ERROR_BASE(NONE),
|
||||||
|
.message = "No error",
|
||||||
|
.description = "The operation succeeded.",
|
||||||
|
.uuid = "3f9fa7d9-3d35-5358-bfa4-0c708bc2d7c9"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ERROR_BASE(FAULT),
|
||||||
|
.message = "Invalid address",
|
||||||
|
.uuid = "92ef9c60-654f-550d-a256-dc80a85ba0a0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ERROR_BASE(INVAL),
|
||||||
|
.message = "Invalid argument",
|
||||||
|
.uuid = "1146a208-c6aa-59be-93c5-e8c431e48892"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ERROR_BASE(BUSY),
|
||||||
|
.message = "Device or resource busy",
|
||||||
|
.uuid = "5d867873-72ba-569c-bf62-f9c784b9ef3f"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ERROR_BASE(AGAIN),
|
||||||
|
.message = "Try again later",
|
||||||
|
.uuid = "8b8d4d4b-ff8f-53e0-ad82-aa4d15a4c64b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ERROR_BASE(NOMEM),
|
||||||
|
.message = "Not enough space",
|
||||||
|
.description = "Memory allocation failed.",
|
||||||
|
.uuid = "3c236243-fb2e-5f63-a8ff-255a496ff998"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ERROR_BASE(NOENT),
|
||||||
|
.message = "Node does not exist",
|
||||||
|
.description = "File, directory, object, or node does not exist.",
|
||||||
|
.uuid = "0bd73191-c0a8-5a60-8986-590aad6f937c"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ERROR_BASE(EXIST),
|
||||||
|
.message = "Node exists",
|
||||||
|
.description = "Object, or node already exists.",
|
||||||
|
.uuid = "2f763d4f-3bd9-5a2a-a5bd-c9da14b721bd"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ERROR_BASE(PERM),
|
||||||
|
.message = "Operation not permitted",
|
||||||
|
.uuid = "bd371bfb-1e55-5819-aeb5-e8a085e287cf"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ERROR_BASE(CONNECTED),
|
||||||
|
.message = "Already connected",
|
||||||
|
.description = "The operation can not be completed while object is connected.",
|
||||||
|
.uuid = "eeabbbd0-ac81-5eb5-ac77-6e474bc6caee"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ERROR_BASE(UNCONNECTED),
|
||||||
|
.message = "Unconnected",
|
||||||
|
.description = "The operation can not be completed while object is not connected.",
|
||||||
|
.uuid = "7c2e9838-add7-5d2f-8b7a-ba04924075f7"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ERROR_BASE(IO),
|
||||||
|
.message = "Input/output error",
|
||||||
|
.uuid = "25541978-3f69-5d63-bd06-c86e299d8f10"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ERROR_BASE(CANNOTCONNECT),
|
||||||
|
.message = "Can not connect",
|
||||||
|
.description = "Can not connect to remote resource.",
|
||||||
|
.uuid = "3f507c9c-e30b-5c81-91aa-e7c3a21bf3f6"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ERROR_BASE(NOLOGIN),
|
||||||
|
.message = "Can not login",
|
||||||
|
.description = "Can not log into service.",
|
||||||
|
.uuid = "6fcaf080-dfaf-5ab0-a800-9d67d2d9c64f"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ERROR_BASE(NOTSECURE),
|
||||||
|
.message = "Connection, or object not secure",
|
||||||
|
.description = "Connection, or object is not on required security level.",
|
||||||
|
.uuid = "393bc752-cb40-5781-b6ce-c23ccc3c46b0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ERROR_BASE(BADCERT),
|
||||||
|
.message = "Bad certificate",
|
||||||
|
.uuid = "07bbfd3a-d432-55b0-a294-a99278e6fa04"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const igloo_error_desc_t * igloo_error_get_description(igloo_error_t error)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
for (i = 0; i < (sizeof(__desc)/sizeof(*__desc)); i++)
|
||||||
|
if (__desc[i].error == error)
|
||||||
|
return &(__desc[i]);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
const igloo_error_desc_t * igloo_error_getbyname(const char *name)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
if (!name)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
for (i = 0; i < (sizeof(__desc)/sizeof(*__desc)); i++) {
|
||||||
|
if (__desc[i].name && strcmp(__desc[i].name, name) == 0) {
|
||||||
|
return &(__desc[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user