mirror of
https://gitlab.xiph.org/xiph/icecast-common.git
synced 2024-12-04 14:46:31 -05:00
Merge branch 'feature-filter' into libigloo
This commit is contained in:
commit
9527c26828
@ -23,6 +23,7 @@ pkginclude_HEADERS = \
|
||||
include/igloo/interface.h \
|
||||
include/igloo/io.h \
|
||||
include/igloo/stdio.h \
|
||||
include/igloo/filter.h \
|
||||
include/igloo/buffer.h \
|
||||
include/igloo/list.h \
|
||||
include/igloo/reportxml.h
|
||||
@ -33,6 +34,7 @@ libigloo_la_SOURCES = \
|
||||
src/ro.c \
|
||||
src/io.c \
|
||||
src/stdio.c \
|
||||
src/filter.c \
|
||||
src/buffer.c \
|
||||
src/list.c \
|
||||
src/reportxml.c
|
||||
|
87
include/igloo/filter.h
Normal file
87
include/igloo/filter.h
Normal file
@ -0,0 +1,87 @@
|
||||
/* 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__FILTER_H_
|
||||
#define _LIBIGLOO__FILTER_H_
|
||||
/**
|
||||
* @file
|
||||
* Put a good description of this file here
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "ro.h"
|
||||
#include "interface.h"
|
||||
|
||||
/* About thread safety:
|
||||
* This set of functions is thread safe.
|
||||
*/
|
||||
|
||||
igloo_RO_FORWARD_TYPE(igloo_filter_t);
|
||||
|
||||
/* Result of a test. */
|
||||
typedef enum {
|
||||
/* The test resulted in an error condition. */
|
||||
igloo_FILTER_RESULT_ERROR = -1,
|
||||
/* The object did not pass the test and should not be processed. */
|
||||
igloo_FILTER_RESULT_DROP = 0,
|
||||
/* The object passed the test and should be processed. */
|
||||
igloo_FILTER_RESULT_PASS = 1
|
||||
} igloo_filter_result_t;
|
||||
|
||||
/* Interface description */
|
||||
typedef struct {
|
||||
igloo_interface_base_ifdesc_t __base;
|
||||
|
||||
/* Perform the actual test on the object.
|
||||
* This must implement thread-safety itself if necessary.
|
||||
*/
|
||||
igloo_filter_result_t (*test)(igloo_INTERFACE_BASIC_ARGS, igloo_ro_t object);
|
||||
} igloo_filter_ifdesc_t;
|
||||
|
||||
/* This creates a new filter from a interface description and state.
|
||||
* Parameters:
|
||||
* ifdesc
|
||||
* The interface description to use.
|
||||
* backend_object
|
||||
* A object used by the backend or igloo_RO_NULL.
|
||||
* backend_userdata
|
||||
* A userdata pointer used by the backend or NULL.
|
||||
* name, associated
|
||||
* See refobject_new().
|
||||
*/
|
||||
igloo_filter_t * igloo_filter_new(const igloo_filter_ifdesc_t *ifdesc, igloo_ro_t backend_object, void *backend_userdata, const char *name, igloo_ro_t associated);
|
||||
|
||||
/* This tests a object according to the filter.
|
||||
* Parameters:
|
||||
* filter
|
||||
* The filter to use.
|
||||
* object
|
||||
* The object to test.
|
||||
* Returns:
|
||||
* Result of the test (error, drop, pass).
|
||||
*/
|
||||
igloo_filter_result_t igloo_filter_test(igloo_filter_t *filter, igloo_ro_t object);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ! _LIBIGLOO__FILTER_H_ */
|
@ -33,6 +33,7 @@ extern "C" {
|
||||
#include "typedef.h"
|
||||
|
||||
typedef struct igloo_io_tag igloo_io_t;
|
||||
typedef struct igloo_filter_tag igloo_filter_t;
|
||||
typedef struct igloo_buffer_tag igloo_buffer_t;
|
||||
typedef struct igloo_list_tag igloo_list_t;
|
||||
|
||||
@ -52,6 +53,7 @@ typedef union __attribute__ ((__transparent_union__)) {
|
||||
/* Those are libigloo's own types */
|
||||
igloo_RO_TYPE(igloo_ro_base_t)
|
||||
igloo_RO_TYPE(igloo_io_t)
|
||||
igloo_RO_TYPE(igloo_filter_t)
|
||||
igloo_RO_TYPE(igloo_buffer_t)
|
||||
igloo_RO_TYPE(igloo_list_t)
|
||||
igloo_RO_TYPE(igloo_reportxml_t)
|
||||
|
39
src/filter.c
Normal file
39
src/filter.c
Normal file
@ -0,0 +1,39 @@
|
||||
/* 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 <igloo/ro.h>
|
||||
#include <igloo/filter.h>
|
||||
#include "private.h"
|
||||
|
||||
struct igloo_filter_tag {
|
||||
igloo_interface_base(filter)
|
||||
};
|
||||
|
||||
igloo_RO_PUBLIC_TYPE(igloo_filter_t,
|
||||
igloo_RO_TYPEDECL_FREE(igloo_interface_base_free)
|
||||
);
|
||||
|
||||
igloo_filter_t * igloo_filter_new(const igloo_filter_ifdesc_t *ifdesc, igloo_ro_t backend_object, void *backend_userdata, const char *name, igloo_ro_t associated)
|
||||
{
|
||||
return igloo_interface_base_new(igloo_filter_t, ifdesc, backend_object, backend_userdata, name, associated);
|
||||
}
|
||||
|
||||
igloo_filter_result_t igloo_filter_test(igloo_filter_t *filter, igloo_ro_t object)
|
||||
{
|
||||
if (!filter)
|
||||
return igloo_FILTER_RESULT_ERROR;
|
||||
|
||||
if (filter->ifdesc->test)
|
||||
return filter->ifdesc->test(igloo_INTERFACE_BASIC_CALL(filter), object);
|
||||
|
||||
return igloo_FILTER_RESULT_ERROR;
|
||||
}
|
Loading…
Reference in New Issue
Block a user