forked from shadowsocks/badvpn
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add NCD, the Network Configuration Daemon
- Loading branch information
ambrop7
committed
Dec 10, 2010
1 parent
f915658
commit 20d7a01
Showing
35 changed files
with
10,360 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/** | ||
* @file ncd_tokenizer_test.c | ||
* @author Ambroz Bizjak <[email protected]> | ||
* | ||
* @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. | ||
*/ | ||
|
||
#include <stddef.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
#include <misc/debug.h> | ||
#include <ncdconfig/NCDConfigParser.h> | ||
|
||
int error; | ||
|
||
int main (int argc, char **argv) | ||
{ | ||
if (argc < 1) { | ||
return 1; | ||
} | ||
|
||
if (argc != 2) { | ||
printf("Usage: %s <string>\n", argv[0]); | ||
return 1; | ||
} | ||
|
||
// parse | ||
struct NCDConfig_interfaces *ast; | ||
if (!NCDConfigParser_Parse(argv[1], strlen(argv[1]), &ast)) { | ||
DEBUG("NCDConfigParser_Parse failed"); | ||
return 1; | ||
} | ||
|
||
struct NCDConfig_interfaces *iface = ast; | ||
while (iface) { | ||
printf("Interface %s\n", iface->name); | ||
|
||
struct NCDConfig_statements *st = iface->statements; | ||
while (st) { | ||
struct NCDConfig_strings *name = st->names; | ||
ASSERT(name) | ||
printf(" %s", name->value); | ||
name = name->next; | ||
|
||
while (name) { | ||
printf(".%s", name->value); | ||
name = name->next; | ||
} | ||
|
||
printf("\n"); | ||
|
||
struct NCDConfig_strings *arg = st->args; | ||
while (arg) { | ||
printf(" %s\n", arg->value); | ||
arg = arg->next; | ||
} | ||
|
||
st = st->next; | ||
} | ||
|
||
iface = iface->next; | ||
} | ||
|
||
NCDConfig_free_interfaces(ast); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/** | ||
* @file ncd_tokenizer_test.c | ||
* @author Ambroz Bizjak <[email protected]> | ||
* | ||
* @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. | ||
*/ | ||
|
||
#include <stddef.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
#include <misc/debug.h> | ||
#include <ncdconfig/NCDConfigTokenizer.h> | ||
|
||
int error; | ||
|
||
static int tokenizer_output (void *user, int token, char *value, size_t pos) | ||
{ | ||
if (token == NCD_ERROR) { | ||
printf("error at %zd\n", pos); | ||
error = 1; | ||
return 0; | ||
} | ||
|
||
switch (token) { | ||
case NCD_EOF: | ||
printf("eof\n"); | ||
break; | ||
case NCD_TOKEN_CURLY_OPEN: | ||
printf("curly_open\n"); | ||
break; | ||
case NCD_TOKEN_CURLY_CLOSE: | ||
printf("curly_close\n"); | ||
break; | ||
case NCD_TOKEN_SEMICOLON: | ||
printf("semicolon\n"); | ||
break; | ||
case NCD_TOKEN_DOT: | ||
printf("dot\n"); | ||
break; | ||
case NCD_TOKEN_INTERFACE: | ||
printf("interface\n"); | ||
break; | ||
case NCD_TOKEN_NAME: | ||
printf("name %s\n", value); | ||
break; | ||
case NCD_TOKEN_STRING: | ||
printf("string %s\n", value); | ||
break; | ||
default: | ||
ASSERT(0); | ||
} | ||
|
||
return 1; | ||
} | ||
|
||
int main (int argc, char **argv) | ||
{ | ||
if (argc < 1) { | ||
return 1; | ||
} | ||
|
||
if (argc != 2) { | ||
printf("Usage: %s <string>\n", argv[0]); | ||
return 1; | ||
} | ||
|
||
error = 0; | ||
|
||
NCDConfigTokenizer_Tokenize(argv[1], strlen(argv[1]), tokenizer_output, NULL); | ||
|
||
if (error) { | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.