This repository has been archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 123
/
logchange.c
99 lines (82 loc) · 3 KB
/
logchange.c
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
97
98
99
/**
* @file
*
* @brief Source for logchange plugin
*
* @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
*
*/
#ifndef HAVE_KDBCONFIG
#include "kdbconfig.h"
#endif
#include <kdbchangetracking.h>
#include <stdio.h>
#include <string.h>
#include "logchange.h"
static void logKeys (KeySet * ks, const char * message)
{
for (elektraCursor it = 0; it < ksGetSize (ks); ++it)
{
Key * k = ksAtCursor (ks, it);
printf ("%s: %s\n", message, keyName (k));
}
}
int elektraLogchangeGet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned, Key * parentKey ELEKTRA_UNUSED)
{
if (!strcmp (keyName (parentKey), "system:/elektra/modules/logchange"))
{
KeySet * contract = ksNew (
30, keyNew ("system:/elektra/modules/logchange", KEY_VALUE, "logchange plugin waits for your orders", KEY_END),
keyNew ("system:/elektra/modules/logchange/exports", KEY_END),
keyNew ("system:/elektra/modules/logchange/exports/get", KEY_FUNC, elektraLogchangeGet, KEY_END),
keyNew ("system:/elektra/modules/logchange/exports/commit", KEY_FUNC, elektraLogchangeCommit, KEY_END),
keyNew ("system:/elektra/modules/logchange/exports/hook/notification/send/get", KEY_FUNC, elektraLogchangeGet,
KEY_END),
keyNew ("system:/elektra/modules/logchange/exports/hook/notification/send/set", KEY_FUNC, elektraLogchangeCommit,
KEY_END),
keyNew ("system:/elektra/modules/logchange/exports/close", KEY_FUNC, elektraLogchangeClose, KEY_END),
#include ELEKTRA_README
keyNew ("system:/elektra/modules/logchange/infos/version", KEY_VALUE, PLUGINVERSION, KEY_END), KS_END);
ksAppend (returned, contract);
ksDel (contract);
return 1; /* success */
}
if (strncmp (keyString (ksLookupByName (elektraPluginGetConfig (handle), "/log/get", 0)), "1", 1) == 0)
{
KeySet * logset = ksNew (1, keyDup (parentKey, KEY_CP_ALL), KS_END);
logKeys (logset, "loading configuration");
ksDel (logset);
}
return 1; /* success */
}
int elektraLogchangeCommit (Plugin * handle, KeySet * returned, Key * parentKey ELEKTRA_UNUSED)
{
const ChangeTrackingContext * context = elektraChangeTrackingGetContextFromPlugin (handle);
ElektraDiff * diff = elektraChangeTrackingCalculateDiff (returned, context, parentKey);
KeySet * addedKeys = elektraDiffGetAddedKeys (diff);
KeySet * changedKeys = elektraDiffGetModifiedKeys (diff);
KeySet * removedKeys = elektraDiffGetRemovedKeys (diff);
logKeys (addedKeys, "added key");
logKeys (changedKeys, "changed key");
logKeys (removedKeys, "removed key");
ksDel (addedKeys);
ksDel (changedKeys);
ksDel (removedKeys);
elektraDiffDel (diff);
return 1; /* success */
}
int elektraLogchangeClose (Plugin * handle, Key * parentKey ELEKTRA_UNUSED)
{
KeySet * ks = (KeySet *) elektraPluginGetData (handle);
if (ks) ksDel (ks);
return 1; /* success */
}
Plugin * ELEKTRA_PLUGIN_EXPORT
{
// clang-format off
return elektraPluginExport("logchange",
ELEKTRA_PLUGIN_GET, &elektraLogchangeGet,
ELEKTRA_PLUGIN_COMMIT, &elektraLogchangeCommit,
ELEKTRA_PLUGIN_CLOSE, &elektraLogchangeClose,
ELEKTRA_PLUGIN_END);
}