Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
oai
freediameter
Commits
949bc2fe
Commit
949bc2fe
authored
Dec 07, 2009
by
Sebastien Decugis
Browse files
Ported the app_test application
parent
c7b49997
Changes
11
Hide whitespace changes
Inline
Side-by-side
extensions/CMakeLists.txt
View file @
949bc2fe
...
...
@@ -78,7 +78,7 @@ OPTION(BUILD_MONITOR "Build monitor.fdx? (display periodical debug information o
# SUBDIRS(rt_debug)
# ENDIF (BUILD_RT_DEBUG)
#
OPTION(BUILD_APP_TEST "Build app_test? (Testing application to send dummy message to another peer, for testing purpose only)" OFF)
#
IF (BUILD_APP_TEST)
#
SUBDIRS(app_test)
#
ENDIF (BUILD_APP_TEST)
OPTION
(
BUILD_APP_TEST
"Build app_test? (Testing application to send dummy message to another peer, for testing purpose only)"
OFF
)
IF
(
BUILD_APP_TEST
)
SUBDIRS
(
app_test
)
ENDIF
(
BUILD_APP_TEST
)
extensions/app_test/CMakeLists.txt
0 → 100644
View file @
949bc2fe
# The dict_nasreq extension
PROJECT
(
"Test Diameter Application"
C
)
# Parser files
BISON_FILE
(
atst_conf.y
)
FLEX_FILE
(
atst_conf.l
)
SET_SOURCE_FILES_PROPERTIES
(
lex.atst_conf.c atst_conf.tab.c PROPERTIES COMPILE_FLAGS
"-I
${
CMAKE_CURRENT_SOURCE_DIR
}
"
)
# List of source files
SET
(
APP_TEST_SRC
app_test.c
app_test.h
lex.atst_conf.c
atst_conf.tab.c
atst_conf.tab.h
atst_sig.c
atst_dict.c
atst_serv.c
atst_cli.c
)
# Compile as a module
FD_ADD_EXTENSION
(
app_test
${
APP_TEST_SRC
}
)
extensions/app_test/app_test.c
0 → 100644
View file @
949bc2fe
/*********************************************************************************************************
* Software License Agreement (BSD License) *
* Author: Sebastien Decugis <sdecugis@nict.go.jp> *
* *
* Copyright (c) 2009, WIDE Project and NICT *
* All rights reserved. *
* *
* Redistribution and use of this software in source and binary forms, with or without modification, are *
* permitted provided that the following conditions are met: *
* *
* * Redistributions of source code must retain the above *
* copyright notice, this list of conditions and the *
* following disclaimer. *
* *
* * Redistributions in binary form must reproduce the above *
* copyright notice, this list of conditions and the *
* following disclaimer in the documentation and/or other *
* materials provided with the distribution. *
* *
* * Neither the name of the WIDE Project or NICT nor the *
* names of its contributors may be used to endorse or *
* promote products derived from this software without *
* specific prior written permission of WIDE Project and *
* NICT. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
*********************************************************************************************************/
/*
* Test application for freeDiameter.
*/
#include "app_test.h"
/* Initialize the configuration */
struct
atst_conf
*
atst_conf
=
NULL
;
static
struct
atst_conf
_conf
;
static
int
atst_conf_init
(
void
)
{
atst_conf
=
&
_conf
;
memset
(
atst_conf
,
0
,
sizeof
(
struct
atst_conf
));
/* Set the default values */
atst_conf
->
vendor_id
=
0
;
/* IETF */
atst_conf
->
appli_id
=
0xffffff
;
/* dummy value */
atst_conf
->
cmd_id
=
0xfffffe
;
/* Experimental */
atst_conf
->
avp_id
=
0xffffff
;
/* dummy value */
atst_conf
->
mode
=
MODE_SERV
|
MODE_CLI
;
atst_conf
->
dest_realm
=
strdup
(
fd_g_config
->
cnf_diamrlm
);
atst_conf
->
dest_host
=
NULL
;
atst_conf
->
signal
=
10
;
/* SIGUSR1 */
return
0
;
}
static
void
atst_conf_dump
(
void
)
{
TRACE_DEBUG
(
FULL
,
"------- app_test configuration dump: ---------"
);
TRACE_DEBUG
(
FULL
,
" Vendor Id .......... : %u"
,
atst_conf
->
vendor_id
);
TRACE_DEBUG
(
FULL
,
" Application Id ..... : %u"
,
atst_conf
->
appli_id
);
TRACE_DEBUG
(
FULL
,
" Command Id ......... : %u"
,
atst_conf
->
cmd_id
);
TRACE_DEBUG
(
FULL
,
" AVP Id ............. : %u"
,
atst_conf
->
avp_id
);
TRACE_DEBUG
(
FULL
,
" Mode ............... : %s%s"
,
atst_conf
->
mode
&
MODE_SERV
?
"Serv"
:
""
,
atst_conf
->
mode
&
MODE_CLI
?
"Cli"
:
""
);
TRACE_DEBUG
(
FULL
,
" Destination Realm .. : %s"
,
atst_conf
->
dest_realm
?:
"- none -"
);
TRACE_DEBUG
(
FULL
,
" Destination Host ... : %s"
,
atst_conf
->
dest_host
?:
"- none -"
);
TRACE_DEBUG
(
FULL
,
" Signal ............. : %i"
,
atst_conf
->
signal
);
TRACE_DEBUG
(
FULL
,
"------- /app_test configuration dump ---------"
);
}
/* entry point */
static
int
atst_entry
(
char
*
conffile
)
{
TRACE_ENTRY
(
"%p"
,
conffile
);
/* Initialize configuration */
CHECK_FCT
(
atst_conf_init
()
);
/* Parse configuration file */
if
(
conffile
!=
NULL
)
{
CHECK
(
atst_conf_handle
(
conffile
)
);
}
TRACE_DEBUG
(
INFO
,
"Extension APP/Test initialized with configuration: '%s'"
,
conffile
);
atst_conf_dump
();
/* Install objects definitions for this test application */
CHECK_FCT
(
atst_dict_init
()
);
/* Install the handlers for incoming messages */
if
(
atst_conf
->
mode
&
MODE_SERV
)
{
CHECK_FCT
(
atst_serv_init
()
);
}
/* Start the signal handler thread */
if
(
atst_conf
->
mode
&
MODE_CLI
)
{
CHECK_FCT
(
atst_cli_init
()
);
}
return
0
;
}
/* Unload */
void
fd_ext_fini
(
void
)
{
if
(
atst_conf
->
mode
&
MODE_CLI
)
atst_cli_fini
();
if
(
atst_conf
->
mode
&
MODE_SERV
)
atst_serv_fini
();
}
EXTENSION_ENTRY
(
"app_test"
,
atst_entry
);
extensions/app_test/app_test.h
0 → 100644
View file @
949bc2fe
/*********************************************************************************************************
* Software License Agreement (BSD License) *
* Author: Sebastien Decugis <sdecugis@nict.go.jp> *
* *
* Copyright (c) 2009, WIDE Project and NICT *
* All rights reserved. *
* *
* Redistribution and use of this software in source and binary forms, with or without modification, are *
* permitted provided that the following conditions are met: *
* *
* * Redistributions of source code must retain the above *
* copyright notice, this list of conditions and the *
* following disclaimer. *
* *
* * Redistributions in binary form must reproduce the above *
* copyright notice, this list of conditions and the *
* following disclaimer in the documentation and/or other *
* materials provided with the distribution. *
* *
* * Neither the name of the WIDE Project or NICT nor the *
* names of its contributors may be used to endorse or *
* promote products derived from this software without *
* specific prior written permission of WIDE Project and *
* NICT. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
*********************************************************************************************************/
/* Header file for the app_test extension.
*
* This extension provides a way to send configurable messages on the network
*
* See the app_test.conf.sample file for the format of the configuration file.
*/
#include <freeDiameter/extension.h>
/* Mode for the extension */
#define MODE_SERV 0x1
#define MODE_CLI 0x2
/* The module configuration */
struct
atst_conf
{
uint32_t
vendor_id
;
/* default 999999 */
uint32_t
appli_id
;
/* default 123456 */
uint32_t
cmd_id
;
/* default 234567 */
uint32_t
avp_id
;
/* default 345678 */
int
mode
;
/* default MODE_SERV | MODE_CLI */
char
*
dest_realm
;
/* default local realm */
char
*
dest_host
;
/* default NULL */
int
signal
;
/* default SIGUSR1 */
};
extern
struct
atst_conf
*
atst_conf
;
/* Parse the configuration file */
int
atst_conf_handle
(
char
*
conffile
);
/* Start or stop the signal handler */
int
atst_sig_init
(
void
(
*
cb
)(
void
));
void
atst_sig_fini
(
void
);
/* Handle incoming messages (server) */
int
atst_serv_init
(
void
);
void
atst_serv_fini
(
void
);
/* Create outgoing message (client) */
int
atst_cli_init
(
void
);
void
atst_cli_fini
(
void
);
/* Initialize dictionary definitions */
int
atst_dict_init
(
void
);
/* Some global variables for dictionary */
extern
struct
dict_object
*
atst_vendor
;
extern
struct
dict_object
*
atst_appli
;
extern
struct
dict_object
*
atst_cmd_r
;
extern
struct
dict_object
*
atst_cmd_a
;
extern
struct
dict_object
*
atst_avp
;
extern
struct
dict_object
*
atst_sess_id
;
extern
struct
dict_object
*
atst_origin_host
;
extern
struct
dict_object
*
atst_origin_realm
;
extern
struct
dict_object
*
atst_dest_host
;
extern
struct
dict_object
*
atst_dest_realm
;
extern
struct
dict_object
*
atst_res_code
;
extensions/app_test/atst_cli.c
0 → 100644
View file @
949bc2fe
/*********************************************************************************************************
* Software License Agreement (BSD License) *
* Author: Sebastien Decugis <sdecugis@nict.go.jp> *
* *
* Copyright (c) 2009, WIDE Project and NICT *
* All rights reserved. *
* *
* Redistribution and use of this software in source and binary forms, with or without modification, are *
* permitted provided that the following conditions are met: *
* *
* * Redistributions of source code must retain the above *
* copyright notice, this list of conditions and the *
* following disclaimer. *
* *
* * Redistributions in binary form must reproduce the above *
* copyright notice, this list of conditions and the *
* following disclaimer in the documentation and/or other *
* materials provided with the distribution. *
* *
* * Neither the name of the WIDE Project or NICT nor the *
* names of its contributors may be used to endorse or *
* promote products derived from this software without *
* specific prior written permission of WIDE Project and *
* NICT. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
*********************************************************************************************************/
/* Create and send a message, and receive it */
/* Note that we use both sessions and the argument to answer callback to pass the same value.
* This is just for the purpose of checking everything went OK.
*/
#include "app_test.h"
static
struct
session_handler
*
atst_cli_reg
=
NULL
;
struct
atst_mess_info
{
int32_t
randval
;
/* a random value to store in Test-AVP */
struct
timespec
ts
;
/* Time of sending the message */
}
;
/* Cb called when an answer is received */
static
void
atst_cb_ans
(
void
*
data
,
struct
msg
**
msg
)
{
struct
atst_mess_info
*
mi
=
NULL
;
struct
timespec
ts
;
struct
session
*
sess
;
struct
avp
*
avp
;
struct
avp_hdr
*
hdr
;
CHECK_SYS_DO
(
clock_gettime
(
CLOCK_REALTIME
,
&
ts
),
return
);
/* Search the session, retrieve its data */
{
int
new
;
CHECK_FCT_DO
(
fd_msg_sess_get
(
fd_g_config
->
cnf_dict
,
*
msg
,
&
sess
,
&
new
),
return
);
ASSERT
(
new
==
0
);
CHECK_FCT_DO
(
fd_sess_state_retrieve
(
atst_cli_reg
,
sess
,
&
mi
),
return
);
TRACE_DEBUG
(
INFO
,
"%p %p"
,
mi
,
data
);
ASSERT
(
(
void
*
)
mi
==
data
);
}
/* Now log content of the answer */
fprintf
(
stderr
,
"RECV "
);
/* Value of Test-AVP */
CHECK_FCT_DO
(
fd_msg_search_avp
(
*
msg
,
atst_avp
,
&
avp
),
return
);
if
(
avp
)
{
CHECK_FCT_DO
(
fd_msg_avp_hdr
(
avp
,
&
hdr
),
return
);
fprintf
(
stderr
,
"%x (%s) "
,
hdr
->
avp_value
->
i32
,
(
hdr
->
avp_value
->
i32
==
mi
->
randval
)
?
"Ok"
:
"PROBLEM"
);
}
else
{
fprintf
(
stderr
,
"no_Test-AVP "
);
}
/* Value of Result Code */
CHECK_FCT_DO
(
fd_msg_search_avp
(
*
msg
,
atst_res_code
,
&
avp
),
return
);
if
(
avp
)
{
CHECK_FCT_DO
(
fd_msg_avp_hdr
(
avp
,
&
hdr
),
return
);
fprintf
(
stderr
,
"Status: %d "
,
hdr
->
avp_value
->
i32
);
}
else
{
fprintf
(
stderr
,
"no_Result-Code "
);
}
/* Value of Origin-Host */
CHECK_FCT_DO
(
fd_msg_search_avp
(
*
msg
,
atst_origin_host
,
&
avp
),
return
);
if
(
avp
)
{
CHECK_FCT_DO
(
fd_msg_avp_hdr
(
avp
,
&
hdr
),
return
);
fprintf
(
stderr
,
"From '%.*s' "
,
hdr
->
avp_value
->
os
.
len
,
hdr
->
avp_value
->
os
.
data
);
}
else
{
fprintf
(
stderr
,
"no_Origin-Host "
);
}
/* Value of Origin-Realm */
CHECK_FCT_DO
(
fd_msg_search_avp
(
*
msg
,
atst_origin_realm
,
&
avp
),
return
);
if
(
avp
)
{
CHECK_FCT_DO
(
fd_msg_avp_hdr
(
avp
,
&
hdr
),
return
);
fprintf
(
stderr
,
"('%.*s') "
,
hdr
->
avp_value
->
os
.
len
,
hdr
->
avp_value
->
os
.
data
);
}
else
{
fprintf
(
stderr
,
"no_Origin-Realm "
);
}
/* Now compute how long it took */
if
(
ts
.
tv_nsec
>
mi
->
ts
.
tv_nsec
)
{
fprintf
(
stderr
,
"in %d.%06ld sec"
,
(
int
)(
ts
.
tv_sec
-
mi
->
ts
.
tv_sec
),
(
long
)(
ts
.
tv_nsec
-
mi
->
ts
.
tv_nsec
)
/
1000
);
}
else
{
fprintf
(
stderr
,
"in %d.%06ld sec"
,
(
int
)(
ts
.
tv_sec
+
1
-
mi
->
ts
.
tv_sec
),
(
long
)(
1000000000
+
ts
.
tv_nsec
-
mi
->
ts
.
tv_nsec
)
/
1000
);
}
fprintf
(
stderr
,
"
\n
"
);
fflush
(
stderr
);
/* Free the message */
CHECK_FCT_DO
(
fd_msg_free
(
*
msg
),
return
);
*
msg
=
NULL
;
free
(
mi
);
return
;
}
/* Create a test message */
static
void
atst_cli_test_message
(
void
)
{
struct
msg
*
req
=
NULL
;
struct
avp
*
avp
;
union
avp_value
val
;
struct
atst_mess_info
*
mi
=
NULL
;
struct
session
*
sess
=
NULL
;
TRACE_DEBUG
(
FULL
,
"Creating a new message for sending."
);
/* Create the request from template */
CHECK_FCT_DO
(
fd_msg_new
(
atst_cmd_r
,
MSGFL_ALLOC_ETEID
,
&
req
),
return
);
/* Create a new session */
CHECK_FCT_DO
(
fd_sess_new
(
&
sess
,
fd_g_config
->
cnf_diamid
,
"app_test"
,
8
),
return
);
/* Create the random value to store with the session */
mi
=
malloc
(
sizeof
(
struct
atst_mess_info
));
if
(
mi
==
NULL
)
{
fd_log_debug
(
"malloc failed: %s"
,
strerror
(
errno
));
return
;
}
mi
->
randval
=
(
int32_t
)
random
();
/* Now set all AVPs values */
/* Session-Id */
{
char
*
sid
;
CHECK_FCT_DO
(
fd_sess_getsid
(
sess
,
&
sid
),
return
);
CHECK_FCT_DO
(
fd_msg_avp_new
(
atst_sess_id
,
0
,
&
avp
),
return
);
val
.
os
.
data
=
sid
;
val
.
os
.
len
=
strlen
(
sid
);
CHECK_FCT_DO
(
fd_msg_avp_setvalue
(
avp
,
&
val
),
return
);
CHECK_FCT_DO
(
fd_msg_avp_add
(
req
,
MSG_BRW_FIRST_CHILD
,
avp
),
return
);
}
/* Set the Destination-Realm AVP */
{
CHECK_FCT_DO
(
fd_msg_avp_new
(
atst_dest_realm
,
0
,
&
avp
),
return
);
val
.
os
.
data
=
(
unsigned
char
*
)(
atst_conf
->
dest_realm
);
val
.
os
.
len
=
strlen
(
atst_conf
->
dest_realm
);
CHECK_FCT_DO
(
fd_msg_avp_setvalue
(
avp
,
&
val
),
return
);
CHECK_FCT_DO
(
fd_msg_avp_add
(
req
,
MSG_BRW_LAST_CHILD
,
avp
),
return
);
}
/* Set the Destination-Host AVP if needed*/
if
(
atst_conf
->
dest_host
)
{
CHECK_FCT_DO
(
fd_msg_avp_new
(
atst_dest_host
,
0
,
&
avp
),
return
);
val
.
os
.
data
=
(
unsigned
char
*
)(
atst_conf
->
dest_host
);
val
.
os
.
len
=
strlen
(
atst_conf
->
dest_host
);
CHECK_FCT_DO
(
fd_msg_avp_setvalue
(
avp
,
&
val
),
return
);
CHECK_FCT_DO
(
fd_msg_avp_add
(
req
,
MSG_BRW_LAST_CHILD
,
avp
),
return
);
}
/* Set Origin-Host & Origin-Realm */
CHECK_FCT_DO
(
fd_msg_add_origin
(
req
,
0
),
return
);
/* Set the Test-AVP AVP */
{
CHECK_FCT_DO
(
fd_msg_avp_new
(
atst_avp
,
0
,
&
avp
),
return
);
val
.
i32
=
mi
->
randval
;
CHECK_FCT_DO
(
fd_msg_avp_setvalue
(
avp
,
&
val
),
return
);
CHECK_FCT_DO
(
fd_msg_avp_add
(
req
,
MSG_BRW_LAST_CHILD
,
avp
),
return
);
}
CHECK_SYS_DO
(
clock_gettime
(
CLOCK_REALTIME
,
&
mi
->
ts
),
return
);
/* Store this value in the session */
CHECK_FCT_DO
(
fd_sess_state_store
(
atst_cli_reg
,
sess
,
&
mi
),
return
);
/* Log sending the message */
fprintf
(
stderr
,
"SEND %x to '%s' (%s)
\n
"
,
mi
->
randval
,
atst_conf
->
dest_realm
,
atst_conf
->
dest_host
?:
"-"
);
fflush
(
stderr
);
/* Send the request */
CHECK_FCT_DO
(
fd_msg_send
(
&
req
,
atst_cb_ans
,
mi
),
return
);
return
;
}
int
atst_cli_init
(
void
)
{
CHECK_FCT
(
fd_sess_handler_create
(
&
atst_cli_reg
,
free
)
);
CHECK_FCT
(
atst_sig_init
(
atst_cli_test_message
)
);
return
0
;
}
void
atst_cli_fini
(
void
)
{
(
void
)
fd_sess_handler_destroy
(
&
atst_cli_reg
);
atst_sig_fini
();
return
;
};
extensions/app_test/atst_conf.l
0 → 100644
View file @
949bc2fe
/*********************************************************************************************************
* Software License Agreement (BSD License) *
* Author: Sebastien Decugis <sdecugis@nict.go.jp> *
* *
* Copyright (c) 2009, WIDE Project and NICT *
* All rights reserved. *
* *
* Redistribution and use of this software in source and binary forms, with or without modification, are *
* permitted provided that the following conditions are met: *
* *
* * Redistributions of source code must retain the above *
* copyright notice, this list of conditions and the *
* following disclaimer. *
* *
* * Redistributions in binary form must reproduce the above *
* copyright notice, this list of conditions and the *
* following disclaimer in the documentation and/or other *
* materials provided with the distribution. *
* *
* * Neither the name of the WIDE Project or NICT nor the *
* names of its contributors may be used to endorse or *
* promote products derived from this software without *
* specific prior written permission of WIDE Project and *
* NICT. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
*********************************************************************************************************/
/* Lex extension's configuration parser.
*
* The configuration file contains a default priority, and a list of peers with optional overwite priority.
* -- see the app_test.conf.sample file for more detail.
*/
%{
#include "app_test.h"
/* Include yacc tokens definitions */
#include "atst_conf.tab.h"
/* Update the column information */
#define YY_USER_ACTION { \
yylloc->first_column = yylloc->last_column + 1; \
yylloc->last_column = yylloc->first_column + yyleng - 1; \
}
/* Avoid warning with newer flex */
#define YY_NO_INPUT
%}
%option bison-bridge bison-locations
%option noyywrap
%option nounput
%%
/* Update the line count */
\n {
yylloc->first_line++;
yylloc->last_line++;
yylloc->last_column=0;
}
/* Eat all spaces but not new lines */
([[:space:]]{-}[\n])+ ;
/* Eat all comments */
#.*$ ;
/* Recognize any integer */
[-]?[[:digit:]]+ {
/* Convert this to an integer value */
int ret=0;
ret = sscanf(yytext, "%i", &yylval->integer);
if (ret != 1) {
/* No matching: an error occurred */
fd_log_debug("Unable to convert the value '%s' to a valid number: %s\n", yytext, strerror(errno));
return LEX_ERROR; /* trig an error in yacc parser */
/* Maybe we could REJECT instead of failing here? */
}
return INTEGER;
}
/* Recognize quoted strings */
\"[[:alnum:].-]+\" {
/* Match a string. expected only ASCII characters, '-' and '.'. The validation is done in yacc */
yylval->string = strdup(yytext+1);
if (!yylval->string) {
fd_log_debug("Unable to copy the string '%s': %s\n", yytext, strerror(errno));
TRACE_DEBUG(INFO, "strdup failed");
return LEX_ERROR; /* trig an error in yacc parser */
}
yylval->string[strlen(yytext) - 2] = '\0';
return QSTRING;
}
/* Recognize the tokens */
(?i:"vendor-id") {
return VENDOR_ID;
}
(?i:"appli-id") {
return APPLI_ID;
}
(?i:"cmd-id") {
return CMD_ID;
}
(?i:"avp-id") {
return AVP_ID;
}
(?i:"mode") {
return MODE;
}
(?i:"server") {
yylval->integer = MODE_SERV;
return INTEGER;
}
(?i:"client") {
yylval->integer = MODE_CLI;
return INTEGER;
}
(?i:"both") {