ucx
UAP Common Extensions
Loading...
Searching...
No Matches
properties.h
Go to the documentation of this file.
1/*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 2024 Mike Becker, Olaf Wintermann All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
35
36#ifndef UCX_PROPERTIES_H
37#define UCX_PROPERTIES_H
38
39#include "common.h"
40#include "string.h"
41#include "map.h"
42#include "buffer.h"
43
44#include <stdio.h>
45#include <string.h>
46
47#ifdef __cplusplus
48extern "C" {
49#endif
50
60
66
72
78
79 /*
80 * The character, when appearing at the end of a line, continues that line.
81 * This is '\' by default.
82 */
87};
88
93
98
162
167
187
192
193
198
213 CxProperties *prop,
215 cxstring key,
216 cxstring value
217);
218
236
237
242
259 CxProperties *prop,
261 cxstring *target
262);
263
273 CxProperties *prop,
275);
276
284 CxProperties *prop,
286);
287
320
330
344
355
362#define cxPropertiesInitDefault(prop) \
363 cxPropertiesInit(prop, cx_properties_config_default)
364
387CX_EXPORT int cxPropertiesFilln(CxProperties *prop, const char *buf, size_t len);
388
399 return cxPropertiesFilln(prop, str.ptr, str.length);
400}
401
422#define cxPropertiesFill(prop, str) cx_properties_fill(prop, cx_strcast(str))
423
432CX_EXPORT void cxPropertiesUseStack(CxProperties *prop, char *buf, size_t capacity);
433
466
483
493
504
517
529
530
562
563#ifdef __cplusplus
564} // extern "C"
565#endif
566
567#endif // UCX_PROPERTIES_H
Advanced buffer implementation.
struct cx_buffer_s CxBuffer
UCX buffer.
Definition buffer.h:196
Common definitions and feature checks.
#define CX_INLINE
Declares a function to be inlined.
Definition common.h:290
#define cx_attr_nonnull
All pointer arguments must be non-NULL.
Definition common.h:141
#define CX_EXPORT
Only used for building Windows DLLs.
Definition common.h:278
#define cx_attr_nodiscard
Warn about discarded return value.
Definition common.h:256
#define cx_attr_access_r(...)
Specifies that the function will only read through the given pointer.
Definition common.h:230
#define cx_attr_cstr_arg(idx)
No support for null_terminated_string_arg in clang or GCC below 14.
Definition common.h:211
Interface for map implementations.
struct cx_map_s CxMap
Type for the UCX map.
Definition map.h:54
CxPropertiesSource cxPropertiesCstrSource(const char *str)
Creates a properties source based on a C string.
void cxPropertiesInit(CxProperties *prop, CxPropertiesConfig config)
Initialize a properties interface.
void cxPropertiesReset(CxProperties *prop)
Destroys and re-initializes the properties interface.
int(* cx_properties_read_init_func)(CxProperties *prop, CxPropertiesSource *src)
A function that may initialize additional memory for the source.
Definition properties.h:272
int(* cx_properties_read_func)(CxProperties *prop, CxPropertiesSource *src, cxstring *target)
A function that reads data from a source.
Definition properties.h:258
struct cx_properties_sink_s CxPropertiesSink
Typedef for a properties sink.
Definition properties.h:197
const CxPropertiesConfig cx_properties_config_default
Default properties configuration.
void cxPropertiesDestroy(CxProperties *prop)
Destroys the properties interface.
struct cx_properties_source_s CxPropertiesSource
Typedef for a properties source.
Definition properties.h:241
CxPropertiesStatus cxPropertiesNext(CxProperties *prop, cxstring *key, cxstring *value)
Retrieves the next key/value-pair.
CxPropertiesSource cxPropertiesCstrnSource(const char *str, size_t len)
Creates a properties source based on C string with the specified length.
int(* cx_properties_sink_func)(CxProperties *prop, CxPropertiesSink *sink, cxstring key, cxstring value)
A function that consumes a k/v-pair in a sink.
Definition properties.h:212
int cxPropertiesFilln(CxProperties *prop, const char *buf, size_t len)
Fills the input buffer with data.
struct cx_properties_config_s CxPropertiesConfig
Typedef for the properties config.
Definition properties.h:92
CxPropertiesSource cxPropertiesFileSource(FILE *file, size_t chunk_size)
Creates a properties source based on an FILE.
CxPropertiesStatus cxPropertiesLoad(CxProperties *prop, CxPropertiesSink sink, CxPropertiesSource source)
Loads properties data from a source and transfers it to a sink.
static int cx_properties_fill(CxProperties *prop, cxstring str)
Internal function, do not use.
Definition properties.h:398
CxPropertiesSink cxPropertiesMapSink(CxMap *map)
Creates a properties sink for an UCX map.
CxPropertiesSource cxPropertiesStringSource(cxstring str)
Creates a properties source based on an UCX string.
void cxPropertiesUseStack(CxProperties *prop, char *buf, size_t capacity)
Specifies stack memory that shall be used as an internal buffer.
void(* cx_properties_read_clean_func)(CxProperties *prop, CxPropertiesSource *src)
A function that cleans memory initialized by the read_init_func.
Definition properties.h:283
struct cx_properties_s CxProperties
Typedef for the properties interface.
Definition properties.h:191
cx_properties_status
Status codes for the properties interface.
Definition properties.h:102
@ CX_PROPERTIES_SINK_FAILED
Sinking a k/v-pair failed.
Definition properties.h:160
@ CX_PROPERTIES_NO_ERROR
Everything is fine.
Definition properties.h:106
@ CX_PROPERTIES_INVALID_EMPTY_KEY
The line contains a delimiter but no key.
Definition properties.h:134
@ CX_PROPERTIES_OK
Not used as a status and never returned by any function.
Definition properties.h:126
@ CX_PROPERTIES_NULL_INPUT
Input buffer is NULL.
Definition properties.h:130
@ CX_PROPERTIES_READ_FAILED
Reading from a properties source failed.
Definition properties.h:154
@ CX_PROPERTIES_INCOMPLETE_DATA
The input ends unexpectedly.
Definition properties.h:117
@ CX_PROPERTIES_READ_INIT_FAILED
Initializing the properties source failed.
Definition properties.h:148
@ CX_PROPERTIES_BUFFER_ALLOC_FAILED
More internal buffer was needed, but could not be allocated.
Definition properties.h:142
@ CX_PROPERTIES_NO_DATA
The input buffer does not contain more data.
Definition properties.h:110
@ CX_PROPERTIES_INVALID_MISSING_DELIMITER
The line contains data but no delimiter.
Definition properties.h:138
enum cx_properties_status CxPropertiesStatus
Typedef for the properties status enum.
Definition properties.h:166
Strings that know their length.
struct cx_string_s cxstring
An immutable string.
Definition string.h:87
Configures the expected characters for the properties parser.
Definition properties.h:54
char continuation
Reserved for future use.
Definition properties.h:86
char delimiter
The key/value delimiter that shall be used.
Definition properties.h:59
char comment3
The third comment character.
Definition properties.h:77
char comment2
The second comment character.
Definition properties.h:71
char comment1
The first comment character.
Definition properties.h:65
Interface for working with properties data.
Definition properties.h:171
CxBuffer input
The text input buffer.
Definition properties.h:180
CxPropertiesConfig config
The configuration.
Definition properties.h:175
CxBuffer buffer
Internal buffer.
Definition properties.h:185
Defines a sink for k/v-pairs.
Definition properties.h:222
cx_properties_sink_func sink_func
A function for consuming k/v-pairs into the sink.
Definition properties.h:234
void * sink
The sink object.
Definition properties.h:226
void * data
Optional custom data.
Definition properties.h:230
Defines a properties source.
Definition properties.h:291
cx_properties_read_init_func read_init_func
Optional function that may prepare the source for reading data.
Definition properties.h:313
void * src
The source object.
Definition properties.h:297
void * data_ptr
Optional additional data pointer.
Definition properties.h:301
size_t data_size
Optional size information.
Definition properties.h:305
cx_properties_read_func read_func
A function that reads data from the source.
Definition properties.h:309
cx_properties_read_clean_func read_clean_func
Optional function that cleans additional memory allocated by the read_init_func.
Definition properties.h:318