]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- Expose the configured listening and outgoing interfaces, if any, as
authorGeorge Thessalonikefs <yorgos@nlnetlabs.nl>
Mon, 16 Oct 2023 13:53:47 +0000 (15:53 +0200)
committerGeorge Thessalonikefs <yorgos@nlnetlabs.nl>
Mon, 16 Oct 2023 13:53:47 +0000 (15:53 +0200)
  a list of strings in the Python 'config_file' class instead of the
  current Swig object proxy; fixes #79.

doc/Changelog
pythonmod/doc/modules/config.rst
pythonmod/interface.i

index 893dfc2d5d31cb49de2526c64fea111fbabe32c7..195e3b17033e3b165f4cd28f5c37803e3148ad1f 100644 (file)
@@ -2,6 +2,9 @@
        - Expose the script filename in the Python module environment 'mod_env'
          instead of the config_file structure which includes the linked list
          of scripts in a multi Python module setup; fixes #79.
+       - Expose the configured listening and outgoing interfaces, if any, as
+         a list of strings in the Python 'config_file' class instead of the
+         current Swig object proxy; fixes #79.
 
 13 October 2023: George
        - Better fix for infinite loop when reading multiple lines of input on
index 1298725f273ed15e9ce108d2f3f15ddf1b8e24d2..ac4db4c94af275c120fea24f9296643c537205ab 100644 (file)
@@ -129,7 +129,7 @@ config_file
    
    .. attribute:: ifs
    
-      Interface description strings (IP addresses).
+      List of interface description strings (IP addresses).
 
    .. attribute:: num_out_ifs
    
@@ -138,7 +138,7 @@ config_file
 
    .. attribute:: out_ifs
    
-      Outgoing interface description strings (IP addresses).
+      List of outgoing interface description strings (IP addresses).
       
    .. attribute:: root_hints
    
index d31c7ae558b69ab24b4573064d2dfdb4aebb5469..d9839fc3866c2d7c4382ff272ac6dc09ae41b136 100644 (file)
      }
      return list;
    }
+
+   /* converts an array of strings (char**) to a List of strings */
+   PyObject* CharArrayAsStringList(char** array, int len) {
+     PyObject* list;
+     int i;
+
+     if(!array||len==0) return PyList_New(0);
+
+     list = PyList_New(len);
+     for (i=0; i < len; i++) {
+            PyList_SET_ITEM(list, i, PyString_FromString(array[i]));
+     }
+     return list;
+   }
 %}
 
 /* ************************************************************************************ *
@@ -952,6 +966,8 @@ struct config_str2list {
 /* ************************************************************************************ *
    Structure config_file
  * ************************************************************************************ */
+%ignore config_file::ifs;
+%ignore config_file::out_ifs;
 %ignore config_file::python_script;
 struct config_file {
    int verbosity;
@@ -1036,8 +1052,20 @@ struct config_file {
    struct config_strlist* python_script;
 };
 
+%inline %{
+   PyObject* _get_ifs_tuple(struct config_file* cfg) {
+      return CharArrayAsStringList(cfg->ifs, cfg->num_ifs);
+   }
+   PyObject* _get_ifs_out_tuple(struct config_file* cfg) {
+      return CharArrayAsStringList(cfg->out_ifs, cfg->num_out_ifs);
+   }
+%}
+
 %extend config_file {
    %pythoncode %{
+        ifs = property(_unboundmodule._get_ifs_tuple)
+        out_ifs = property(_unboundmodule._get_ifs_out_tuple)
+
         def _deprecated_python_script(self): return "cfg.python_script is deprecated, you can use `mod_env['script']` instead."
         python_script = property(_deprecated_python_script)
    %}