forked from ElektraInitiative/libelektra
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnull.c
More file actions
97 lines (84 loc) · 2.13 KB
/
Copy pathnull.c
File metadata and controls
97 lines (84 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/**
* @file
*
* @brief
*
* @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
*/
#include "null.h"
#ifndef HAVE_KDBCONFIG
#include "kdbconfig.h"
#endif
#include <kdbhelper.h>
#include <stdlib.h>
#include <string.h>
int elektraNullGet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned, Key * parentKey)
{
if (!strcmp (keyName (parentKey), "system/elektra/modules/null"))
{
KeySet * moduleConfig =
ksNew (30, keyNew ("system/elektra/modules/null", KEY_VALUE, "null plugin waits for your orders", KEY_END),
keyNew ("system/elektra/modules/null/exports", KEY_END),
keyNew ("system/elektra/modules/null/exports/get", KEY_FUNC, elektraNullGet, KEY_END),
keyNew ("system/elektra/modules/null/exports/set", KEY_FUNC, elektraNullSet, KEY_END),
#include "readme_null.c"
keyNew ("system/elektra/modules/null/infos/version", KEY_VALUE, PLUGINVERSION, KEY_END), KS_END);
ksAppend (returned, moduleConfig);
ksDel (moduleConfig);
return 1;
}
/* get all keys */
Key * k;
ksRewind (returned);
while ((k = ksNext (returned)) != 0)
{
if (!strcmp (keyString (k), "@NULL"))
{
keySetBinary (k, 0, 0);
}
else if (!strcmp (keyString (k), "@EMPTY"))
{
keySetString (k, "");
}
else if (!strncmp (keyString (k), "@@", 2))
{
/* Drop the first of the @ */
keySetString (k, keyString (k) + 1);
}
}
return 1; /* success */
}
int elektraNullSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned, Key * parentKey ELEKTRA_UNUSED)
{
/* set all keys */
Key * k;
ksRewind (returned);
while ((k = ksNext (returned)) != 0)
{
if (keyValue (k) == 0)
{
keySetString (k, "@NULL");
}
else if (!strcmp (keyValue (k), ""))
{
keySetString (k, "@EMPTY");
}
else if (!strncmp (keyValue (k), "@", 1))
{
char * n = elektraMalloc (keyGetValueSize (k) + 1);
strcpy (n, "@");
strcat (n, keyValue (k));
keySetString (k, n);
elektraFree (n);
}
}
return 1; /* success */
}
Plugin * ELEKTRA_PLUGIN_EXPORT
{
// clang-format off
return elektraPluginExport("null",
ELEKTRA_PLUGIN_GET, &elektraNullGet,
ELEKTRA_PLUGIN_SET, &elektraNullSet,
ELEKTRA_PLUGIN_END);
}