1
0
mirror of https://gitlab.xiph.org/xiph/icecast-common.git synced 2024-12-04 14:46:31 -05:00

Feature: Added generic error type

This commit is contained in:
Philipp Schafft 2019-09-12 13:01:26 +00:00
parent eeb46eb889
commit e28102841f
3 changed files with 124 additions and 0 deletions

View File

@ -28,6 +28,7 @@ pkginclude_HEADERS = \
include/igloo/logmsg.h \
include/igloo/buffer.h \
include/igloo/list.h \
include/igloo/error.h \
include/igloo/reportxml.h
libigloo_la_SOURCES = \
@ -42,6 +43,7 @@ libigloo_la_SOURCES = \
src/logmsg.c \
src/buffer.c \
src/list.c \
src/error.c \
src/reportxml.c \
src/timing.c
libigloo_la_LIBADD = \

62
include/igloo/error.h Normal file
View File

@ -0,0 +1,62 @@
/* 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>
#ifdef IGLOO_CTC_HAVE_STDINT_H
#include <stdint.h>
#endif
#ifdef IGLOO_CTC_HAVE_STDINT_H
typedef int_least16_t igloo_error_t;
#else
typedef long int igloo_error_t;
#endif
typedef struct {
igloo_error_t error;
const char *uuid;
const char *name;
const char *message;
const char *description;
} igloo_error_desc_t;
#define igloo_ERROR_GENERIC ((igloo_error_t)-1)
#define igloo_ERROR_NONE ((igloo_error_t)0)
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_ */

60
src/error.c Normal file
View File

@ -0,0 +1,60 @@
/* 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
static const igloo_error_desc_t __desc[] = {
{
ERROR_BASE(GENERIC),
.uuid = "953b7275-21f3-4697-8d30-33f346f9833e",
.message = "Generic error",
.description = "A generic error occurred."
},
{
ERROR_BASE(NONE),
.uuid = "4fa39862-0647-46ea-bfdf-fd2a5c7f6e9d",
.message = "No error",
.description = "The operation succeeded."
}
};
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;
}