Open SCAP Library
Loading...
Searching...
No Matches
sexp-manip.h
Go to the documentation of this file.
1
13/*
14 * Copyright 2009 Red Hat Inc., Durham, North Carolina.
15 * All Rights Reserved.
16 *
17 * This library is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Lesser General Public
19 * License as published by the Free Software Foundation; either
20 * version 2.1 of the License, or (at your option) any later version.
21 *
22 * This library is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 * Lesser General Public License for more details.
26 *
27 * You should have received a copy of the GNU Lesser General Public
28 * License along with this library; if not, write to the Free Software
29 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
30 *
31 * Authors:
32 * Daniel Kopecek <dkopecek@redhat.com>
33 */
34
35#pragma once
36#ifndef SEXP_MANIP_H
37#define SEXP_MANIP_H
38
39#include <stdarg.h>
40#include <stddef.h>
41#include <stdint.h>
42#include <stdbool.h>
43#include <sexp-types.h>
44#include <helpers.h>
45#include "oscap_export.h"
46#include <common/util.h>
47
48#ifdef __cplusplus
49extern "C" {
50#endif
51
52/*
53 * number
54 */
55
61OSCAP_API SEXP_t *SEXP_number_new (SEXP_numtype_t t, const void *n) __attribute__ ((nonnull (2)));
62
67OSCAP_API SEXP_t *SEXP_number_newb (bool n);
68
73OSCAP_API SEXP_t *SEXP_number_newi_8 (int8_t n);
74
79OSCAP_API SEXP_t *SEXP_number_newu_8 (uint8_t n);
80
85OSCAP_API uint8_t SEXP_number_getu_8 (const SEXP_t *s_exp);
86
91OSCAP_API SEXP_t *SEXP_number_newi_16 (int16_t n);
92
97OSCAP_API SEXP_t *SEXP_number_newu_16 (uint16_t n);
98
103#define SEXP_number_newi SEXP_number_newi_32
104
109OSCAP_API SEXP_t *SEXP_number_newi_32 (int32_t n);
110
115#define SEXP_number_geti SEXP_number_geti_32
116
121OSCAP_API int32_t SEXP_number_geti_32 (const SEXP_t *s_exp);
122
127OSCAP_API bool SEXP_number_getb (const SEXP_t *s_exp);
128
133#define SEXP_number_newu SEXP_number_newu_32
134
139OSCAP_API SEXP_t *SEXP_number_newu_32 (uint32_t n);
140
145#define SEXP_number_getu SEXP_number_getu_32
146
151OSCAP_API uint32_t SEXP_number_getu_32 (const SEXP_t *s_exp);
152
157OSCAP_API SEXP_t *SEXP_number_newi_64 (int64_t n);
158
163OSCAP_API int64_t SEXP_number_geti_64 (const SEXP_t *s_exp);
164
169OSCAP_API SEXP_t *SEXP_number_newu_64 (uint64_t n);
170
175OSCAP_API uint64_t SEXP_number_getu_64 (const SEXP_t *s_exp);
176
181OSCAP_API SEXP_t *SEXP_number_newf (double n);
182
187OSCAP_API double SEXP_number_getf (const SEXP_t *s_exp);
188
195OSCAP_API int SEXP_number_get (const SEXP_t *s_exp, void *dst, SEXP_numtype_t type);
196
201OSCAP_API uint16_t SEXP_number_getu_16 (const SEXP_t *s_exp);
202
207OSCAP_API void SEXP_number_free (SEXP_t *s_exp);
208
213OSCAP_API bool SEXP_numberp (const SEXP_t *s_exp);
214
219OSCAP_API SEXP_numtype_t SEXP_number_type (const SEXP_t *sexp);
220
221/*
222 * string
223 */
224
230OSCAP_API SEXP_t *SEXP_string_new (const void *string, size_t strlen) __attribute__ ((nonnull (1)));
231
237OSCAP_API SEXP_t *SEXP_string_newf (const char *format, ...) __attribute__ ((format (printf, 1, 2), nonnull (1)));
238
243OSCAP_API void SEXP_string_free (SEXP_t *s_exp);
244
249OSCAP_API bool SEXP_stringp (const SEXP_t *s_exp);
250
255OSCAP_API size_t SEXP_string_length (const SEXP_t *s_exp);
256
262OSCAP_API int SEXP_strcmp (const SEXP_t *s_exp, const char *str) __attribute__ ((nonnull (2)));
263
270OSCAP_API int SEXP_strncmp (const SEXP_t *s_exp, const char *str, size_t n) __attribute__ ((nonnull (2)));
271
277OSCAP_API int SEXP_string_nth (const SEXP_t *s_exp, size_t n);
278
282OSCAP_API char *SEXP_string_cstr (const SEXP_t *s_exp);
283
291OSCAP_API size_t SEXP_string_cstr_r (const SEXP_t *s_exp, char *buf, size_t len) __attribute__ ((nonnull (2)));
292
296OSCAP_API char *SEXP_string_cstrp (const SEXP_t *s_exp);
297
304OSCAP_API char *SEXP_string_subcstr (const SEXP_t *s_exp, size_t beg, size_t len);
305
311OSCAP_API int SEXP_string_cmp (const SEXP_t *str_a, const SEXP_t *str_b);
312
317OSCAP_API bool SEXP_string_getb (const SEXP_t *s_exp);
318
319/*
320 * list
321 */
322
329OSCAP_API SEXP_t *SEXP_list_new (SEXP_t *memb, ...);
330
335OSCAP_API void SEXP_list_free (SEXP_t *s_exp);
336
341OSCAP_API bool SEXP_listp (const SEXP_t *s_exp);
342
347OSCAP_API size_t SEXP_list_length (const SEXP_t *s_exp);
348
354OSCAP_API SEXP_t *SEXP_list_first (const SEXP_t *list);
355
361OSCAP_API SEXP_t *SEXP_list_rest (const SEXP_t *list);
362
368OSCAP_API SEXP_t *SEXP_list_last (const SEXP_t *list);
369
376OSCAP_API SEXP_t *SEXP_list_nth (const SEXP_t *list, uint32_t n);
377
384OSCAP_API SEXP_t *SEXP_list_add (SEXP_t *list, const SEXP_t *s_exp);
385
392OSCAP_API SEXP_t *SEXP_list_join (const SEXP_t *list_a, const SEXP_t *list_b);
393
400OSCAP_API SEXP_t *SEXP_list_push (SEXP_t *list, const SEXP_t *s_exp);
401
407OSCAP_API SEXP_t *SEXP_list_pop (SEXP_t *list);
408
412OSCAP_API SEXP_t *SEXP_list_sort(SEXP_t *list, int(*compare)(const SEXP_t *, const SEXP_t *));
413
422OSCAP_API SEXP_t *SEXP_list_replace (SEXP_t *list, uint32_t n, const SEXP_t *s_exp);
423
429OSCAP_API SEXP_t *SEXP_listref_first (SEXP_t *list);
430
436OSCAP_API SEXP_t *SEXP_listref_rest (SEXP_t *list);
437
443OSCAP_API SEXP_t *SEXP_listref_last (SEXP_t *list);
444
451OSCAP_API SEXP_t *SEXP_listref_nth (SEXP_t *list, uint32_t n);
452
453typedef struct SEXP_it SEXP_it_t;
454
455#define SEXP_IT_RECURSIVE 0x01
456#define SEXP_IT_HARDREF 0x02
457
458typedef struct SEXP_list_it SEXP_list_it;
459
460OSCAP_API SEXP_list_it *SEXP_list_it_new(const SEXP_t *list);
461OSCAP_API SEXP_t *SEXP_list_it_next(SEXP_list_it *it);
462OSCAP_API void SEXP_list_it_free(SEXP_list_it *it);
463
464/* TODO: use alloca & softref_r here */
470#define SEXP_list_foreach(var, list) \
471 for (uint32_t OSCAP_CONCAT(i,__LINE__) = 1; ((var) = SEXP_list_nth (list, OSCAP_CONCAT(i,__LINE__))) != NULL; ++OSCAP_CONCAT(i,__LINE__), SEXP_free (var), (var) = NULL)
472
480#define SEXP_sublist_foreach(var, list, beg, end) \
481 for (uint32_t OSCAP_CONCAT(i,__LINE__) = (beg); OSCAP_CONCAT(i,__LINE__) <= ((size_t)(end)) && ((var) = SEXP_list_nth (list, OSCAP_CONCAT(i,__LINE__))) != NULL; ++OSCAP_CONCAT(i,__LINE__), SEXP_free (var), (var) = NULL)
482
483#define SEXP_LIST_END (UINT32_MAX - 1)
484
485/*
486 * generic
487 */
488OSCAP_API SEXP_t *SEXP_new (void);
489
490OSCAP_API bool SEXP_emptyp(SEXP_t *sexp);
491
496OSCAP_API SEXP_t *SEXP_ref (const SEXP_t *s_exp);
497
498OSCAP_API SEXP_t *SEXP_unref (SEXP_t *s_exp_o);
499
504OSCAP_API SEXP_t *SEXP_softref (SEXP_t *s_exp);
505
510OSCAP_API bool SEXP_softrefp(const SEXP_t *s_exp);
511
516OSCAP_API uint32_t SEXP_refs (const SEXP_t *ref);
517
518OSCAP_API bool SEXP_eq (const SEXP_t *a, const SEXP_t *b);
519
523OSCAP_API int SEXP_refcmp(const SEXP_t *a, const SEXP_t *b);
524
525OSCAP_API bool SEXP_deepcmp(const SEXP_t *a, const SEXP_t *b);
526
531OSCAP_API void SEXP_free (SEXP_t *s_exp);
532
537OSCAP_API const char *SEXP_datatype (const SEXP_t *s_exp);
538
543OSCAP_API int SEXP_datatype_set (SEXP_t *s_exp, const char *name) __attribute__ ((nonnull (2)));
544
551OSCAP_API int SEXP_datatype_set_nth (SEXP_t *list, uint32_t n, const char *name) __attribute__ ((nonnull (3)));
552
557OSCAP_API SEXP_type_t SEXP_typeof (const SEXP_t *s_exp);
558
563OSCAP_API const char *SEXP_strtype (const SEXP_t *s_exp);
564
565OSCAP_API SEXP_t *SEXP_build (const char *s_str, ...);
566
567OSCAP_API size_t SEXP_sizeof (const SEXP_t *s_exp);
568
569#if !defined(NDEBUG)
570# define SEXP_VALIDATE(s) __SEXP_VALIDATE(s, __FILE__, __LINE__, __PRETTY_FUNCTION__)
571# include <stdlib.h>
572
573OSCAP_API void __SEXP_VALIDATE(const SEXP_t *s_exp, const char *file, uint32_t line, const char *func);
574
575#else
576# define SEXP_VALIDATE(s)
577#endif
578
579#ifdef __cplusplus
580}
581#endif
582
583#endif /* SEXP_MANIP_H */
OSCAP_API SEXP_t * SEXP_number_newf(double n)
Create a new sexp object from an floating point value.
Definition sexp-manip.c:516
OSCAP_API SEXP_t * SEXP_list_sort(SEXP_t *list, int(*compare)(const SEXP_t *, const SEXP_t *))
Sort a list using ‘compare’ as the comparison function.
Definition sexp-manip.c:1373
OSCAP_API size_t SEXP_list_length(const SEXP_t *s_exp)
Get the length of the sexp list.
Definition sexp-manip.c:960
OSCAP_API bool SEXP_listp(const SEXP_t *s_exp)
Check whether the provided sexp object is a list.
Definition sexp-manip.c:948
OSCAP_API void SEXP_list_free(SEXP_t *s_exp)
Free the specified sexp object.
Definition sexp-manip.c:942
OSCAP_API SEXP_t * SEXP_list_first(const SEXP_t *list)
Get the first element of a list.
Definition sexp-manip.c:981
OSCAP_API void SEXP_number_free(SEXP_t *s_exp)
Free the specified sexp object.
Definition sexp-manip.c:556
OSCAP_API size_t SEXP_string_length(const SEXP_t *s_exp)
Get the length of a string in a sexp object.
Definition sexp-manip.c:641
OSCAP_API SEXP_t * SEXP_softref(SEXP_t *s_exp)
Create a new soft reference to a sexp object.
Definition sexp-manip.c:1587
OSCAP_API SEXP_t * SEXP_listref_nth(SEXP_t *list, uint32_t n)
Get the n-th element of a list.
Definition sexp-manip.c:1155
OSCAP_API SEXP_t * SEXP_number_new(SEXP_numtype_t t, const void *n) __attribute__((nonnull(2)))
Create a new sexp object from a value and a number type.
Definition sexp-manip.c:56
OSCAP_API uint64_t SEXP_number_getu_64(const SEXP_t *s_exp)
Get unsigned integer value from a sexp object.
Definition sexp-manip.c:430
OSCAP_API char * SEXP_string_cstr(const SEXP_t *s_exp)
Get a C string from a sexp object.
Definition sexp-manip.c:755
OSCAP_API SEXP_t * SEXP_number_newb(bool n)
Create a new sexp object from a boolean value.
Definition sexp-manip.c:91
OSCAP_API double SEXP_number_getf(const SEXP_t *s_exp)
Get floating point value from a sexp object.
Definition sexp-manip.c:526
OSCAP_API int SEXP_refcmp(const SEXP_t *a, const SEXP_t *b)
Compare reference pointers.
Definition sexp-manip.c:1651
OSCAP_API SEXP_t * SEXP_listref_first(SEXP_t *list)
Get the first element of a list.
Definition sexp-manip.c:1006
OSCAP_API SEXP_t * SEXP_number_newi_8(int8_t n)
Create a new sexp object from an integer.
Definition sexp-manip.c:101
OSCAP_API SEXP_t * SEXP_list_new(SEXP_t *memb,...)
Create a new sexp list, optionally initialized with the provided sexp arguments.
Definition sexp-manip.c:926
OSCAP_API char * SEXP_string_subcstr(const SEXP_t *s_exp, size_t beg, size_t len)
Get a C substring from a sexp object.
Definition sexp-manip.c:814
OSCAP_API uint16_t SEXP_number_getu_16(const SEXP_t *s_exp)
Get unsigned integer value from a sexp object.
Definition sexp-manip.c:221
OSCAP_API int SEXP_string_cmp(const SEXP_t *str_a, const SEXP_t *str_b)
Compare two sexp strings.
Definition sexp-manip.c:872
OSCAP_API void SEXP_string_free(SEXP_t *s_exp)
Free the specified sexp object.
Definition sexp-manip.c:623
OSCAP_API uint32_t SEXP_refs(const SEXP_t *ref)
Return the value of the reference counter.
Definition sexp-manip.c:1627
OSCAP_API SEXP_t * SEXP_number_newu_8(uint8_t n)
Create a new sexp object from an unsigned integer.
Definition sexp-manip.c:123
OSCAP_API SEXP_t * SEXP_ref(const SEXP_t *s_exp)
Create a new reference to a sexp object.
Definition sexp-manip.c:1527
OSCAP_API SEXP_t * SEXP_list_nth(const SEXP_t *list, uint32_t n)
Get the n-th element of a list.
Definition sexp-manip.c:1126
OSCAP_API SEXP_numtype_t SEXP_number_type(const SEXP_t *sexp)
Get the number type of an object.
Definition sexp-manip.c:575
OSCAP_API int SEXP_strcmp(const SEXP_t *s_exp, const char *str) __attribute__((nonnull(2)))
Compare a string in a sexp object with a C string.
Definition sexp-manip.c:662
OSCAP_API SEXP_t * SEXP_number_newi_32(int32_t n)
Create a new sexp object from an integer.
Definition sexp-manip.c:256
OSCAP_API const char * SEXP_datatype(const SEXP_t *s_exp)
Get the user data type of a sexp object.
Definition sexp-manip.c:1786
OSCAP_API bool SEXP_numberp(const SEXP_t *s_exp)
Check whether the provided sexp object is a number.
Definition sexp-manip.c:562
OSCAP_API int SEXP_datatype_set_nth(SEXP_t *list, uint32_t n, const char *name) __attribute__((nonnull(3)))
Set the user data type of the nth sexp object in a list.
Definition sexp-manip.c:1829
OSCAP_API int32_t SEXP_number_geti_32(const SEXP_t *s_exp)
Get integer value from a sexp object.
Definition sexp-manip.c:266
OSCAP_API const char * SEXP_strtype(const SEXP_t *s_exp)
Get a text description of the sexp object's type.
Definition sexp-manip.c:1886
OSCAP_API SEXP_t * SEXP_list_last(const SEXP_t *list)
Get the last element of a list.
Definition sexp-manip.c:1053
OSCAP_API SEXP_t * SEXP_list_add(SEXP_t *list, const SEXP_t *s_exp)
Add an element to a list.
Definition sexp-manip.c:1185
OSCAP_API char * SEXP_string_cstrp(const SEXP_t *s_exp)
Obsolete function.
Definition sexp-manip.c:860
OSCAP_API SEXP_t * SEXP_string_newf(const char *format,...) __attribute__((format(printf
Create a new sexp object from a format string.
Definition sexp-manip.c:610
OSCAP_API int SEXP_number_get(const SEXP_t *s_exp, void *dst, SEXP_numtype_t type)
Get a value from a sexp object according to a specified type.
Definition sexp-manip.c:549
OSCAP_API SEXP_t * SEXP_list_pop(SEXP_t *list)
Extract the first element of a list.
Definition sexp-manip.c:1271
OSCAP_API int SEXP_datatype_set(SEXP_t *s_exp, const char *name) __attribute__((nonnull(2)))
Set the user data type of a sexp object.
Definition sexp-manip.c:1802
OSCAP_API size_t SEXP_string_cstr_r(const SEXP_t *s_exp, char *buf, size_t len) __attribute__((nonnull(2)))
Get a C string from a sexp object.
Definition sexp-manip.c:785
OSCAP_API SEXP_t * SEXP_string_new(const void *string, size_t strlen) __attribute__((nonnull(1)))
Create a new sexp object from a string.
Definition sexp-manip.c:600
OSCAP_API SEXP_t * SEXP_list_join(const SEXP_t *list_a, const SEXP_t *list_b)
Create a new list containing the concatenated contents of two lists.
Definition sexp-manip.c:1237
OSCAP_API SEXP_type_t SEXP_typeof(const SEXP_t *s_exp)
Get the type of a sexp object.
Definition sexp-manip.c:1869
OSCAP_API uint32_t SEXP_number_getu_32(const SEXP_t *s_exp)
Get unsigned integer value from a sexp object.
Definition sexp-manip.c:315
OSCAP_API bool SEXP_softrefp(const SEXP_t *s_exp)
Check whether an S-exp reference is a "soft" reference.
Definition sexp-manip.c:1617
OSCAP_API bool SEXP_number_getb(const SEXP_t *s_exp)
Get boolean value from a sexp object.
Definition sexp-manip.c:473
OSCAP_API SEXP_t * SEXP_list_push(SEXP_t *list, const SEXP_t *s_exp)
Push an element to the head of a list.
Definition sexp-manip.c:1263
OSCAP_API uint8_t SEXP_number_getu_8(const SEXP_t *s_exp)
Get unsigned integer value from a sexp object.
Definition sexp-manip.c:145
OSCAP_API int SEXP_string_nth(const SEXP_t *s_exp, size_t n)
Get the n-th byte of a string.
Definition sexp-manip.c:729
OSCAP_API SEXP_t * SEXP_list_replace(SEXP_t *list, uint32_t n, const SEXP_t *s_exp)
Replace the n-th element of a list.
Definition sexp-manip.c:1080
OSCAP_API SEXP_t * SEXP_number_newi_16(int16_t n)
Create a new sexp object from an integer.
Definition sexp-manip.c:177
OSCAP_API SEXP_t * SEXP_number_newu_32(uint32_t n)
Create a new sexp object from an unsigned integer.
Definition sexp-manip.c:305
OSCAP_API SEXP_t * SEXP_list_rest(const SEXP_t *list)
Get the rest of a list.
Definition sexp-manip.c:1034
OSCAP_API SEXP_t * SEXP_number_newi_64(int64_t n)
Create a new sexp object from an integer.
Definition sexp-manip.c:354
OSCAP_API bool SEXP_string_getb(const SEXP_t *s_exp)
Try to cast the supplied sexp string to a boolean.
Definition sexp-manip.c:896
OSCAP_API SEXP_t * SEXP_listref_rest(SEXP_t *list)
Get the rest of a list.
Definition sexp-manip.c:1047
OSCAP_API int SEXP_strncmp(const SEXP_t *s_exp, const char *str, size_t n) __attribute__((nonnull(2)))
Compare a string in a sexp object with a C string.
Definition sexp-manip.c:695
OSCAP_API SEXP_t * SEXP_listref_last(SEXP_t *list)
Get the last element of a list.
Definition sexp-manip.c:1120
OSCAP_API int64_t SEXP_number_geti_64(const SEXP_t *s_exp)
Get integer value from a sexp object.
Definition sexp-manip.c:376
OSCAP_API SEXP_t * SEXP_number_newu_64(uint64_t n)
Create a new sexp object from an unsigned integer.
Definition sexp-manip.c:420
OSCAP_API SEXP_t * SEXP_number_newu_16(uint16_t n)
Create a new sexp object from an unsigned integer.
Definition sexp-manip.c:199
OSCAP_API bool SEXP_stringp(const SEXP_t *s_exp)
Check whether the provided sexp object is a string.
Definition sexp-manip.c:629
OSCAP_API void SEXP_free(SEXP_t *s_exp)
Free a sexp object.
Definition sexp-manip.c:1777
Definition sexp-manip.c:1318
Definition sexp-types.h:82