Преглед изворни кода

ncd: modules: concatlist: remove, and make it an alias for listfrom()

ambrop7 пре 14 година
родитељ
комит
15c6494f5e

+ 0 - 1
blog_channels.txt

@@ -9,7 +9,6 @@ ncd_depend 4
 ncd_multidepend 4
 ncd_concat 4
 ncd_concatv 4
-ncd_concatlist 4
 ncd_if 4
 ncd_strcmp 4
 ncd_regex_match 4

+ 84 - 85
generated/blog_channels_defines.h

@@ -9,88 +9,87 @@
 #define BLOG_CHANNEL_ncd_multidepend 8
 #define BLOG_CHANNEL_ncd_concat 9
 #define BLOG_CHANNEL_ncd_concatv 10
-#define BLOG_CHANNEL_ncd_concatlist 11
-#define BLOG_CHANNEL_ncd_if 12
-#define BLOG_CHANNEL_ncd_strcmp 13
-#define BLOG_CHANNEL_ncd_regex_match 14
-#define BLOG_CHANNEL_ncd_logical 15
-#define BLOG_CHANNEL_ncd_sleep 16
-#define BLOG_CHANNEL_ncd_print 17
-#define BLOG_CHANNEL_ncd_blocker 18
-#define BLOG_CHANNEL_ncd_ip_in_network 19
-#define BLOG_CHANNEL_ncd_run 20
-#define BLOG_CHANNEL_ncd_runonce 21
-#define BLOG_CHANNEL_ncd_spawn 22
-#define BLOG_CHANNEL_ncd_call 23
-#define BLOG_CHANNEL_ncd_ref 24
-#define BLOG_CHANNEL_ncd_index 25
-#define BLOG_CHANNEL_ncd_alias 26
-#define BLOG_CHANNEL_ncd_process_manager 27
-#define BLOG_CHANNEL_ncd_ondemand 28
-#define BLOG_CHANNEL_ncd_foreach 29
-#define BLOG_CHANNEL_ncd_choose 30
-#define BLOG_CHANNEL_ncd_net_backend_waitdevice 31
-#define BLOG_CHANNEL_ncd_net_backend_waitlink 32
-#define BLOG_CHANNEL_ncd_net_backend_badvpn 33
-#define BLOG_CHANNEL_ncd_net_backend_wpa_supplicant 34
-#define BLOG_CHANNEL_ncd_net_backend_rfkill 35
-#define BLOG_CHANNEL_ncd_net_up 36
-#define BLOG_CHANNEL_ncd_net_dns 37
-#define BLOG_CHANNEL_ncd_net_iptables 38
-#define BLOG_CHANNEL_ncd_net_ipv4_addr 39
-#define BLOG_CHANNEL_ncd_net_ipv4_route 40
-#define BLOG_CHANNEL_ncd_net_ipv4_dhcp 41
-#define BLOG_CHANNEL_ncd_net_ipv4_arp_probe 42
-#define BLOG_CHANNEL_ncd_net_watch_interfaces 43
-#define BLOG_CHANNEL_ncd_sys_watch_input 44
-#define BLOG_CHANNEL_ncd_sys_evdev 45
-#define BLOG_CHANNEL_ncd_sys_watch_directory 46
-#define BLOG_CHANNEL_StreamPeerIO 47
-#define BLOG_CHANNEL_DatagramPeerIO 48
-#define BLOG_CHANNEL_BReactor 49
-#define BLOG_CHANNEL_BSignal 50
-#define BLOG_CHANNEL_FragmentProtoAssembler 51
-#define BLOG_CHANNEL_BPredicate 52
-#define BLOG_CHANNEL_ServerConnection 53
-#define BLOG_CHANNEL_Listener 54
-#define BLOG_CHANNEL_DataProto 55
-#define BLOG_CHANNEL_FrameDecider 56
-#define BLOG_CHANNEL_BSocksClient 57
-#define BLOG_CHANNEL_BDHCPClientCore 58
-#define BLOG_CHANNEL_BDHCPClient 59
-#define BLOG_CHANNEL_NCDIfConfig 60
-#define BLOG_CHANNEL_BUnixSignal 61
-#define BLOG_CHANNEL_BProcess 62
-#define BLOG_CHANNEL_PRStreamSink 63
-#define BLOG_CHANNEL_PRStreamSource 64
-#define BLOG_CHANNEL_PacketProtoDecoder 65
-#define BLOG_CHANNEL_DPRelay 66
-#define BLOG_CHANNEL_BThreadWork 67
-#define BLOG_CHANNEL_DPReceive 68
-#define BLOG_CHANNEL_BInputProcess 69
-#define BLOG_CHANNEL_NCDUdevMonitorParser 70
-#define BLOG_CHANNEL_NCDUdevMonitor 71
-#define BLOG_CHANNEL_NCDUdevCache 72
-#define BLOG_CHANNEL_NCDUdevManager 73
-#define BLOG_CHANNEL_BTime 74
-#define BLOG_CHANNEL_BEncryption 75
-#define BLOG_CHANNEL_SPProtoDecoder 76
-#define BLOG_CHANNEL_LineBuffer 77
-#define BLOG_CHANNEL_BTap 78
-#define BLOG_CHANNEL_lwip 79
-#define BLOG_CHANNEL_NCDConfigParser 80
-#define BLOG_CHANNEL_nsskey 81
-#define BLOG_CHANNEL_addr 82
-#define BLOG_CHANNEL_PasswordListener 83
-#define BLOG_CHANNEL_NCDInterfaceMonitor 84
-#define BLOG_CHANNEL_NCDRfkillMonitor 85
-#define BLOG_CHANNEL_udpgw 86
-#define BLOG_CHANNEL_UdpGwClient 87
-#define BLOG_CHANNEL_SocksUdpGwClient 88
-#define BLOG_CHANNEL_BNetwork 89
-#define BLOG_CHANNEL_BConnection 90
-#define BLOG_CHANNEL_BSSLConnection 91
-#define BLOG_CHANNEL_BDatagram 92
-#define BLOG_CHANNEL_PeerChat 93
-#define BLOG_CHANNEL_BArpProbe 94
-#define BLOG_NUM_CHANNELS 95
+#define BLOG_CHANNEL_ncd_if 11
+#define BLOG_CHANNEL_ncd_strcmp 12
+#define BLOG_CHANNEL_ncd_regex_match 13
+#define BLOG_CHANNEL_ncd_logical 14
+#define BLOG_CHANNEL_ncd_sleep 15
+#define BLOG_CHANNEL_ncd_print 16
+#define BLOG_CHANNEL_ncd_blocker 17
+#define BLOG_CHANNEL_ncd_ip_in_network 18
+#define BLOG_CHANNEL_ncd_run 19
+#define BLOG_CHANNEL_ncd_runonce 20
+#define BLOG_CHANNEL_ncd_spawn 21
+#define BLOG_CHANNEL_ncd_call 22
+#define BLOG_CHANNEL_ncd_ref 23
+#define BLOG_CHANNEL_ncd_index 24
+#define BLOG_CHANNEL_ncd_alias 25
+#define BLOG_CHANNEL_ncd_process_manager 26
+#define BLOG_CHANNEL_ncd_ondemand 27
+#define BLOG_CHANNEL_ncd_foreach 28
+#define BLOG_CHANNEL_ncd_choose 29
+#define BLOG_CHANNEL_ncd_net_backend_waitdevice 30
+#define BLOG_CHANNEL_ncd_net_backend_waitlink 31
+#define BLOG_CHANNEL_ncd_net_backend_badvpn 32
+#define BLOG_CHANNEL_ncd_net_backend_wpa_supplicant 33
+#define BLOG_CHANNEL_ncd_net_backend_rfkill 34
+#define BLOG_CHANNEL_ncd_net_up 35
+#define BLOG_CHANNEL_ncd_net_dns 36
+#define BLOG_CHANNEL_ncd_net_iptables 37
+#define BLOG_CHANNEL_ncd_net_ipv4_addr 38
+#define BLOG_CHANNEL_ncd_net_ipv4_route 39
+#define BLOG_CHANNEL_ncd_net_ipv4_dhcp 40
+#define BLOG_CHANNEL_ncd_net_ipv4_arp_probe 41
+#define BLOG_CHANNEL_ncd_net_watch_interfaces 42
+#define BLOG_CHANNEL_ncd_sys_watch_input 43
+#define BLOG_CHANNEL_ncd_sys_evdev 44
+#define BLOG_CHANNEL_ncd_sys_watch_directory 45
+#define BLOG_CHANNEL_StreamPeerIO 46
+#define BLOG_CHANNEL_DatagramPeerIO 47
+#define BLOG_CHANNEL_BReactor 48
+#define BLOG_CHANNEL_BSignal 49
+#define BLOG_CHANNEL_FragmentProtoAssembler 50
+#define BLOG_CHANNEL_BPredicate 51
+#define BLOG_CHANNEL_ServerConnection 52
+#define BLOG_CHANNEL_Listener 53
+#define BLOG_CHANNEL_DataProto 54
+#define BLOG_CHANNEL_FrameDecider 55
+#define BLOG_CHANNEL_BSocksClient 56
+#define BLOG_CHANNEL_BDHCPClientCore 57
+#define BLOG_CHANNEL_BDHCPClient 58
+#define BLOG_CHANNEL_NCDIfConfig 59
+#define BLOG_CHANNEL_BUnixSignal 60
+#define BLOG_CHANNEL_BProcess 61
+#define BLOG_CHANNEL_PRStreamSink 62
+#define BLOG_CHANNEL_PRStreamSource 63
+#define BLOG_CHANNEL_PacketProtoDecoder 64
+#define BLOG_CHANNEL_DPRelay 65
+#define BLOG_CHANNEL_BThreadWork 66
+#define BLOG_CHANNEL_DPReceive 67
+#define BLOG_CHANNEL_BInputProcess 68
+#define BLOG_CHANNEL_NCDUdevMonitorParser 69
+#define BLOG_CHANNEL_NCDUdevMonitor 70
+#define BLOG_CHANNEL_NCDUdevCache 71
+#define BLOG_CHANNEL_NCDUdevManager 72
+#define BLOG_CHANNEL_BTime 73
+#define BLOG_CHANNEL_BEncryption 74
+#define BLOG_CHANNEL_SPProtoDecoder 75
+#define BLOG_CHANNEL_LineBuffer 76
+#define BLOG_CHANNEL_BTap 77
+#define BLOG_CHANNEL_lwip 78
+#define BLOG_CHANNEL_NCDConfigParser 79
+#define BLOG_CHANNEL_nsskey 80
+#define BLOG_CHANNEL_addr 81
+#define BLOG_CHANNEL_PasswordListener 82
+#define BLOG_CHANNEL_NCDInterfaceMonitor 83
+#define BLOG_CHANNEL_NCDRfkillMonitor 84
+#define BLOG_CHANNEL_udpgw 85
+#define BLOG_CHANNEL_UdpGwClient 86
+#define BLOG_CHANNEL_SocksUdpGwClient 87
+#define BLOG_CHANNEL_BNetwork 88
+#define BLOG_CHANNEL_BConnection 89
+#define BLOG_CHANNEL_BSSLConnection 90
+#define BLOG_CHANNEL_BDatagram 91
+#define BLOG_CHANNEL_PeerChat 92
+#define BLOG_CHANNEL_BArpProbe 93
+#define BLOG_NUM_CHANNELS 94

+ 0 - 1
generated/blog_channels_list.h

@@ -9,7 +9,6 @@
 {.name = "ncd_multidepend", .loglevel = 4},
 {.name = "ncd_concat", .loglevel = 4},
 {.name = "ncd_concatv", .loglevel = 4},
-{.name = "ncd_concatlist", .loglevel = 4},
 {.name = "ncd_if", .loglevel = 4},
 {.name = "ncd_strcmp", .loglevel = 4},
 {.name = "ncd_regex_match", .loglevel = 4},

+ 0 - 1
ncd/CMakeLists.txt

@@ -43,7 +43,6 @@ add_executable(badvpn-ncd
     modules/multidepend.c
     modules/concat.c
     modules/concatv.c
-    modules/concatlist.c
     modules/if.c
     modules/strcmp.c
     modules/regex_match.c

+ 0 - 143
ncd/modules/concatlist.c

@@ -1,143 +0,0 @@
-/**
- * @file concatlist.c
- * @author Ambroz Bizjak <ambrop7@gmail.com>
- * 
- * @section LICENSE
- * 
- * This file is part of BadVPN.
- * 
- * BadVPN is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2
- * as published by the Free Software Foundation.
- * 
- * BadVPN is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- * 
- * @section DESCRIPTION
- * 
- * List concatenation module.
- * 
- * Synopsis: concatlist(list elem1, ..., list elemN)
- * Variables:
- *   list (empty) - elem1, ..., elemN concatenated
- */
-
-#include <stdlib.h>
-#include <string.h>
-
-#include <ncd/NCDModule.h>
-
-#include <generated/blog_channel_ncd_concatlist.h>
-
-#define ModuleLog(i, ...) NCDModuleInst_Backend_Log((i), BLOG_CURRENT_CHANNEL, __VA_ARGS__)
-
-struct instance {
-    NCDModuleInst *i;
-};
-
-static void func_new (NCDModuleInst *i)
-{
-    // allocate instance
-    struct instance *o = malloc(sizeof(*o));
-    if (!o) {
-        ModuleLog(i, BLOG_ERROR, "failed to allocate instance");
-        goto fail0;
-    }
-    NCDModuleInst_Backend_SetUser(i, o);
-    
-    // init arguments
-    o->i = i;
-    
-    // check arguments
-    NCDValue *arg = NCDValue_ListFirst(o->i->args);
-    while (arg) {
-        if (NCDValue_Type(arg) != NCDVALUE_LIST) {
-            ModuleLog(i, BLOG_ERROR, "wrong type");
-            goto fail1;
-        }
-        arg = NCDValue_ListNext(o->i->args, arg);
-    }
-    
-    // signal up
-    NCDModuleInst_Backend_Up(o->i);
-    
-    return;
-    
-fail1:
-    free(o);
-fail0:
-    NCDModuleInst_Backend_SetError(i);
-    NCDModuleInst_Backend_Dead(i);
-}
-
-static void func_die (void *vo)
-{
-    struct instance *o = vo;
-    NCDModuleInst *i = o->i;
-    
-    // free instance
-    free(o);
-    
-    NCDModuleInst_Backend_Dead(i);
-}
-
-static int func_getvar (void *vo, const char *name, NCDValue *out)
-{
-    struct instance *o = vo;
-    
-    if (!strcmp(name, "")) {
-        NCDValue_InitList(out);
-        
-        NCDValue *arg = NCDValue_ListFirst(o->i->args);
-        while (arg) {
-            NCDValue *val = NCDValue_ListFirst(arg);
-            while (val) {
-                NCDValue copy;
-                if (!NCDValue_InitCopy(&copy, val)) {
-                    ModuleLog(o->i, BLOG_ERROR, "NCDValue_InitCopy failed");
-                    goto fail1;
-                }
-                
-                if (!NCDValue_ListAppend(out, copy)) {
-                    ModuleLog(o->i, BLOG_ERROR, "NCDValue_ListAppend failed");
-                    NCDValue_Free(&copy);
-                    goto fail1;
-                }
-                
-                val = NCDValue_ListNext(arg, val);
-            }
-            
-            arg = NCDValue_ListNext(o->i->args, arg);
-        }
-        
-        return 1;
-        
-    fail1:
-        NCDValue_Free(out);
-    fail0:
-        return 0;
-    }
-    
-    return 0;
-}
-
-static const struct NCDModule modules[] = {
-    {
-        .type = "concatlist",
-        .func_new = func_new,
-        .func_die = func_die,
-        .func_getvar = func_getvar
-    }, {
-        .type = NULL
-    }
-};
-
-const struct NCDModuleGroup ncdmodule_concatlist = {
-    .modules = modules
-};

+ 6 - 0
ncd/modules/list.c

@@ -635,6 +635,12 @@ static const struct NCDModule modules[] = {
         .func_new = func_new_listfrom,
         .func_die = func_die,
         .func_getvar = func_getvar
+    }, {
+        .type = "concatlist", // alias for listfrom
+        .base_type = "list",
+        .func_new = func_new_listfrom,
+        .func_die = func_die,
+        .func_getvar = func_getvar
     }, {
         .type = "list::append",
         .func_new = append_func_new,

+ 0 - 2
ncd/modules/modules.h

@@ -33,7 +33,6 @@ extern const struct NCDModuleGroup ncdmodule_depend;
 extern const struct NCDModuleGroup ncdmodule_multidepend;
 extern const struct NCDModuleGroup ncdmodule_concat;
 extern const struct NCDModuleGroup ncdmodule_concatv;
-extern const struct NCDModuleGroup ncdmodule_concatlist;
 extern const struct NCDModuleGroup ncdmodule_if;
 extern const struct NCDModuleGroup ncdmodule_strcmp;
 extern const struct NCDModuleGroup ncdmodule_regex_match;
@@ -83,7 +82,6 @@ static const struct NCDModuleGroup *ncd_modules[] = {
     &ncdmodule_multidepend,
     &ncdmodule_concat,
     &ncdmodule_concatv,
-    &ncdmodule_concatlist,
     &ncdmodule_if,
     &ncdmodule_strcmp,
     &ncdmodule_regex_match,