The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
section.h
Go to the documentation of this file.
1#pragma once
2/*
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16 */
17
18/**
19 * $Id: 54d9910ff7655df493eea2a935f0f00ff539d877 $
20 *
21 * @file lib/server/section.h
22 * @brief Structures which identify sections
23 *
24 * @copyright 2024 Arran Cudbard-Bell (a.cudbardb@freeradius.org)
25 */
26RCSIDH(section_h, "$Id: 54d9910ff7655df493eea2a935f0f00ff539d877 $")
27
28#include <freeradius-devel/server/cf_util.h>
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34/** Define a section name consisting of a verb and a noun
35 *
36 * @param[in] _name1 verb name.
37 * @param[in] _name2 noun name.
38 */
39#define SECTION_NAME(_name1, _name2) &(section_name_t){ .name1 = _name1, .name2 = _name2 }
40
41/** Section name identifier
42 */
43typedef struct {
44 char const *name1; //!< First section name. Usually a verb like 'recv', 'send', etc...
45 char const *name2; //!< Second section name. Usually a packet type like 'access-request', 'access-accept', etc...
47
48/* Compare two sections based on name2
49 *
50 * Respects CF_IDENT_ANY values
51 *
52 * @param[in] a First section name.
53 * @param[in] b Second section name.
54 *
55 * @return
56 * - 1 if name2 values match.
57 * - 0 if name2 values don't match.
58 */
59static inline int section_name2_match(section_name_t const *a, section_name_t const *b)
60{
61 if ((a->name2 == CF_IDENT_ANY) || (b->name2 == CF_IDENT_ANY)) return 1;
62 if (!a->name2 || !b->name2) {
63 if (a->name2 == b->name2) return 1;
64 return 0;
65 }
66
67 return (strcmp(a->name2, b->name2) == 0) ? 1 : 0;
68}
69
70/* Compare two section names
71 *
72 * Respects CF_IDENT_ANY values
73 *
74 * @param[in] a First section name.
75 * @param[in] b Second section name.
76 *
77 * @return
78 * - 1 if the section names match.
79 * - 0 if the section names don't match.
80 * - -1 if name1 doesn't match.
81 *
82 */
83static inline int section_name_match(section_name_t const *a, section_name_t const *b)
84{
85 if ((a->name1 == CF_IDENT_ANY) || (b->name1 == CF_IDENT_ANY)) goto name2;
86
87 if (strcmp(a->name1, b->name1) != 0) return -1;
88
89name2:
90 return section_name2_match(a, b);
91}
92
93/** Return a printable string for the section name
94 *
95 * @param[in] name Section name.
96 */
97static inline char const *section_name_str(char const *name)
98{
99 if (name == NULL) return "NULL";
100 if (name == CF_IDENT_ANY) return "*";
101 return name;
102}
103
104static inline void section_name_dup(TALLOC_CTX *ctx, section_name_t *dst, section_name_t const *src)
105{
106 dst->name1 = src->name1;
107 dst->name2 = src->name2;
108
109 if (dst->name1 && (dst->name1 != CF_IDENT_ANY)) dst->name1 = talloc_strdup(ctx, src->name1);
110 if (dst->name2 && (dst->name2 != CF_IDENT_ANY)) dst->name2 = talloc_strdup(ctx, src->name2);
111}
112
113int8_t section_name_cmp(void const *one, void const *two);
114
115#ifdef __cplusplus
116}
117#endif
#define RCSIDH(h, id)
Definition build.h:489
#define CF_IDENT_ANY
Definition cf_util.h:75
static char const * name
static int section_name2_match(section_name_t const *a, section_name_t const *b)
Definition section.h:59
static char const * section_name_str(char const *name)
Return a printable string for the section name.
Definition section.h:97
static int section_name_match(section_name_t const *a, section_name_t const *b)
Definition section.h:83
int8_t section_name_cmp(void const *one, void const *two)
Compare two sections.
Definition section.c:47
static void section_name_dup(TALLOC_CTX *ctx, section_name_t *dst, section_name_t const *src)
Definition section.h:104
char const * name2
Second section name. Usually a packet type like 'access-request', 'access-accept',...
Definition section.h:45
char const * name1
First section name. Usually a verb like 'recv', 'send', etc...
Definition section.h:44
Section name identifier.
Definition section.h:43
#define talloc_strdup(_ctx, _str)
Definition talloc.h:142