LCOV - code coverage report
Current view: top level - src/plugins/noresolver - noresolver.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 20 30 66.7 %
Date: 2019-09-12 12:28:41 Functions: 4 7 57.1 %

          Line data    Source code
       1             : /**
       2             :  * @file
       3             :  *
       4             :  * @brief
       5             :  *
       6             :  * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
       7             :  */
       8             : 
       9             : #ifndef HAVE_KDBCONFIG
      10             : #include "kdbconfig.h"
      11             : #endif
      12             : 
      13             : #include "noresolver.h"
      14             : #include <kdblogger.h>
      15             : #include <string.h>
      16             : 
      17             : /**
      18             :  * @retval 1 on success (Relative path)
      19             :  * @retval 0 on success (Absolute path)
      20             :  * @retval never -1 (success guaranteed)
      21             :  */
      22           8 : int elektraNoresolverCheckFile (const char * filename)
      23             : {
      24           8 :         if (filename[0] == '/') return 0;
      25             : 
      26           8 :         return 1;
      27             : }
      28             : 
      29          76 : static KeySet * elektraNoresolverModules (void)
      30             : {
      31          76 :         return ksNew (
      32             :                 50,
      33             :                 keyNew ("system/elektra/modules/" ELEKTRA_PLUGIN_NAME "", KEY_VALUE, "" ELEKTRA_PLUGIN_NAME " plugin waits for your orders",
      34             :                         KEY_END),
      35             :                 keyNew ("system/elektra/modules/" ELEKTRA_PLUGIN_NAME "/exports", KEY_END),
      36             :                 keyNew ("system/elektra/modules/" ELEKTRA_PLUGIN_NAME "/exports/get", KEY_FUNC, elektraNoresolverGet, KEY_END),
      37             :                 keyNew ("system/elektra/modules/" ELEKTRA_PLUGIN_NAME "/exports/set", KEY_FUNC, elektraNoresolverSet, KEY_END),
      38             :                 keyNew ("system/elektra/modules/" ELEKTRA_PLUGIN_NAME "/exports/error", KEY_FUNC, elektraNoresolverError, KEY_END),
      39             :                 keyNew ("system/elektra/modules/" ELEKTRA_PLUGIN_NAME "/exports/checkfile", KEY_FUNC, elektraNoresolverCheckFile, KEY_END),
      40             : #include ELEKTRA_README
      41             :                 keyNew ("system/elektra/modules/" ELEKTRA_PLUGIN_NAME "/infos/version", KEY_VALUE, PLUGINVERSION, KEY_END), KS_END);
      42             : }
      43             : 
      44          85 : int elektraNoresolverGet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned ELEKTRA_UNUSED, Key * parentKey)
      45             : {
      46             : 
      47          85 :         Key * root = keyNew ("system/elektra/modules/" ELEKTRA_PLUGIN_NAME, KEY_END);
      48             : 
      49          85 :         if (keyRel (root, parentKey) >= 0)
      50             :         {
      51          76 :                 keyDel (root);
      52          76 :                 KeySet * info = elektraNoresolverModules ();
      53          76 :                 ksAppend (returned, info);
      54          76 :                 ksDel (info);
      55          76 :                 return 1;
      56             :         }
      57           9 :         keyDel (root);
      58           9 :         KeySet * config = elektraPluginGetConfig (handle);
      59           9 :         Key * pathKey = ksLookupByName (config, "/path", KDB_O_NONE);
      60           9 :         if (pathKey) keySetString (parentKey, keyString (pathKey));
      61             : 
      62           9 :         if (!strcmp (keyString (ksLookupByName (config, "/assume/unchanged", 0)), "1"))
      63             :         {
      64             :                 // always return 0, except the first time
      65           0 :                 uintptr_t nr = (uintptr_t) elektraPluginGetData (handle);
      66           0 :                 if (nr == 1)
      67             :                 {
      68             :                         ELEKTRA_LOG ("assume config is unchanged");
      69             :                         return 0;
      70             :                 }
      71           0 :                 elektraPluginSetData (handle, (void *) 1);
      72             :         }
      73             : 
      74             :         ELEKTRA_LOG ("assume config is changed");
      75             :         return 1; /* success */
      76             : }
      77             : 
      78           0 : int elektraNoresolverSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned ELEKTRA_UNUSED, Key * parentKey)
      79             : {
      80           0 :         KeySet * config = elektraPluginGetConfig (handle);
      81           0 :         Key * pathKey = ksLookupByName (config, "/path", KDB_O_NONE);
      82           0 :         if (pathKey) keySetString (parentKey, keyString (pathKey));
      83             : 
      84           0 :         return 1; /* success */
      85             : }
      86             : 
      87           0 : int elektraNoresolverError (Plugin * handle ELEKTRA_UNUSED, KeySet * returned ELEKTRA_UNUSED, Key * parentKey ELEKTRA_UNUSED)
      88             : {
      89             :         /* set all keys */
      90             : 
      91           0 :         return 1; /* success */
      92             : }
      93             : 
      94         128 : Plugin * ELEKTRA_PLUGIN_EXPORT
      95             : {
      96             :         // clang-format off
      97         128 :         return elektraPluginExport("noresolver",
      98             :                 ELEKTRA_PLUGIN_GET,     &elektraNoresolverGet,
      99             :                 ELEKTRA_PLUGIN_SET,     &elektraNoresolverSet,
     100             :                 ELEKTRA_PLUGIN_ERROR,   &elektraNoresolverError,
     101             :                 ELEKTRA_PLUGIN_END);
     102             : }
     103             : 

Generated by: LCOV version 1.13