diff --git a/Makefile.am b/Makefile.am index ad466aa..404e343 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 = \ diff --git a/include/igloo/error.h b/include/igloo/error.h new file mode 100644 index 0000000..930b62f --- /dev/null +++ b/include/igloo/error.h @@ -0,0 +1,62 @@ +/* Copyright (C) 2019 Philipp "ph3-der-loewe" Schafft + * + * 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 + +#ifdef IGLOO_CTC_HAVE_STDINT_H +#include +#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_ */ diff --git a/src/error.c b/src/error.c new file mode 100644 index 0000000..5cde25f --- /dev/null +++ b/src/error.c @@ -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 , + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include +#include + +#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; +}