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
52fcdcf1
Commit
52fcdcf1
authored
Sep 02, 2009
by
Sebastien Decugis
Browse files
Progress; added session module; testsess to be completed
parent
81c8b2d6
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
freeDiameter/main.c
View file @
52fcdcf1
...
...
@@ -50,9 +50,6 @@ int main(int argc, char * argv[])
/* Add definitions of the base protocol */
CHECK_FCT
(
fd_dict_base_protocol
(
fd_g_dict
)
);
/* For debug */
fd_dict_dump
(
fd_g_dict
);
TRACE_DEBUG
(
INFO
,
"freeDiameter daemon initialized."
);
return
0
;
...
...
freeDiameter/tests/CMakeLists.txt
View file @
52fcdcf1
...
...
@@ -11,9 +11,11 @@ ENDIF(TEST_TIMEOUT)
#############################
# List the test cases
SET
(
TEST_LIST
testlist
testdict
testmesg
testmq
testsess
)
#############################
...
...
freeDiameter/tests/testlist.c
0 → 100644
View file @
52fcdcf1
/*********************************************************************************************************
* 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. *
*********************************************************************************************************/
#include "tests.h"
#define TEST_STR "This is my test string (with extra unused data)"
#define TEST_STRLEN 22
/* Main test routine */
int
main
(
int
argc
,
char
*
argv
[])
{
/* First, initialize the daemon modules */
INIT_FD
();
/* Check the hash function */
{
char
buf
[
30
];
uint32_t
hash
=
fd_hash
(
TEST_STR
,
TEST_STRLEN
);
/* reference value */
/* Check that a hash of a substring / surstring is different */
CHECK
(
1
,
hash
!=
fd_hash
(
TEST_STR
,
TEST_STRLEN
-
1
)
?
1
:
0
);
CHECK
(
1
,
hash
!=
fd_hash
(
TEST_STR
,
TEST_STRLEN
+
1
)
?
1
:
0
);
/* Check alignment of the string is not important */
memcpy
(
buf
+
4
,
TEST_STR
,
TEST_STRLEN
);
CHECK
(
hash
,
fd_hash
(
buf
+
4
,
TEST_STRLEN
)
);
memcpy
(
buf
+
3
,
TEST_STR
,
TEST_STRLEN
);
CHECK
(
hash
,
fd_hash
(
buf
+
3
,
TEST_STRLEN
)
);
memcpy
(
buf
+
2
,
TEST_STR
,
TEST_STRLEN
);
CHECK
(
hash
,
fd_hash
(
buf
+
2
,
TEST_STRLEN
)
);
memcpy
(
buf
+
1
,
TEST_STR
,
TEST_STRLEN
);
CHECK
(
hash
,
fd_hash
(
buf
+
1
,
TEST_STRLEN
)
);
}
/* That's all for the tests yet */
PASSTEST
();
}
freeDiameter/tests/tests.h
View file @
52fcdcf1
...
...
@@ -97,7 +97,7 @@ static int test_verbo = 0;
/* Minimum inits */
#define INIT_FD() { \
pthread_key_create(&fd_log_thname, free);
\
CHECK( 0, fd_lib_init() );
\
fd_log_threadname(basename(__FILE__)); \
CHECK( 0, fd_dict_init(&fd_g_dict) ); \
CHECK( 0, fd_dict_base_protocol(fd_g_dict) ); \
...
...
freeDiameter/tests/testsess.c
0 → 100644
View file @
52fcdcf1
/*********************************************************************************************************
* 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. *
*********************************************************************************************************/
#include "tests.h"
#define TEST_DIAM_ID "testsess.myid"
#define TEST_OPT "suffix"
#define TEST_SID TEST_DIAM_ID ";1234;5678;" TEST_OPT
#define TEST_EYEC 0x7e57e1ec
struct
mystate
{
int
eyec
;
/* TEST_EYEC */
char
*
sid
;
/* the session with which the data was registered */
int
*
freed
;
/* location where to write the freed status */
};
void
mycleanup
(
char
*
sid
,
struct
mystate
*
data
)
{
/* sanity */
CHECK
(
1
,
sid
?
1
:
0
);
CHECK
(
1
,
data
?
1
:
0
);
CHECK
(
TEST_EYEC
,
data
->
eyec
);
CHECK
(
0
,
strcmp
(
sid
,
data
->
sid
)
);
if
(
data
->
freed
)
*
(
data
->
freed
)
+=
1
;
/* Now, free the data */
free
(
data
->
sid
);
free
(
data
);
}
/* Main test routine */
int
main
(
int
argc
,
char
*
argv
[])
{
struct
session_handler
*
hdl1
,
*
hdl2
;
struct
session
*
sess1
,
*
sess2
,
*
sess3
;
char
*
str1
,
*
str2
;
int
new
;
/* First, initialize the daemon modules */
INIT_FD
();
/* Test functions related to handlers (simple situation) */
{
CHECK
(
0
,
fd_sess_handler_create
(
&
hdl1
,
mycleanup
)
);
CHECK
(
0
,
fd_sess_handler_create
(
&
hdl2
,
mycleanup
)
);
CHECK
(
0
,
fd_sess_handler_destroy
(
&
hdl2
)
);
CHECK
(
0
,
fd_sess_handler_create
(
&
hdl2
,
mycleanup
)
);
#if 1
fd_sess_dump_hdl
(
0
,
hdl1
);
fd_sess_dump_hdl
(
0
,
hdl2
);
#endif
}
/* Test Session Id generation (fd_sess_new) */
{
/* DiamId is provided, not opt */
CHECK
(
0
,
fd_sess_new
(
&
sess1
,
TEST_DIAM_ID
,
NULL
,
0
)
);
CHECK
(
0
,
fd_sess_new
(
&
sess2
,
TEST_DIAM_ID
,
NULL
,
0
)
);
#if 1
fd_sess_dump
(
0
,
sess1
);
fd_sess_dump
(
0
,
sess2
);
#endif
/* Check both string start with the diameter Id, but are different */
CHECK
(
0
,
fd_sess_getsid
(
sess1
,
&
str1
)
);
CHECK
(
0
,
strncmp
(
str1
,
TEST_DIAM_ID
";"
,
strlen
(
TEST_DIAM_ID
)
+
1
)
);
CHECK
(
0
,
fd_sess_getsid
(
sess2
,
&
str2
)
);
CHECK
(
0
,
strncmp
(
str2
,
TEST_DIAM_ID
";"
,
strlen
(
TEST_DIAM_ID
)
+
1
)
);
CHECK
(
1
,
strcmp
(
str1
,
str2
)
?
1
:
0
);
CHECK
(
0
,
fd_sess_destroy
(
&
sess1
)
);
CHECK
(
0
,
fd_sess_destroy
(
&
sess2
)
);
/* diamId and opt */
CHECK
(
0
,
fd_sess_new
(
&
sess1
,
TEST_DIAM_ID
,
TEST_OPT
,
0
)
);
CHECK
(
0
,
fd_sess_new
(
&
sess2
,
TEST_DIAM_ID
,
TEST_OPT
,
strlen
(
TEST_OPT
)
-
1
)
);
#if 1
fd_sess_dump
(
0
,
sess1
);
fd_sess_dump
(
0
,
sess2
);
#endif
CHECK
(
0
,
fd_sess_getsid
(
sess1
,
&
str1
)
);
CHECK
(
0
,
strncmp
(
str1
,
TEST_DIAM_ID
";"
,
strlen
(
TEST_DIAM_ID
)
+
1
)
);
CHECK
(
0
,
strcmp
(
str1
+
strlen
(
str1
)
-
strlen
(
TEST_OPT
)
-
1
,
";"
TEST_OPT
)
);
CHECK
(
0
,
fd_sess_getsid
(
sess2
,
&
str2
)
);
CHECK
(
0
,
strncmp
(
str2
,
TEST_DIAM_ID
";"
,
strlen
(
TEST_DIAM_ID
)
+
1
)
);
CHECK
(
0
,
strncmp
(
str2
+
strlen
(
str2
)
-
strlen
(
TEST_OPT
),
";"
TEST_OPT
,
strlen
(
TEST_OPT
))
);
CHECK
(
1
,
strcmp
(
str1
,
str2
)
?
1
:
0
);
CHECK
(
0
,
fd_sess_destroy
(
&
sess1
)
);
CHECK
(
0
,
fd_sess_destroy
(
&
sess2
)
);
/* Now, only opt is provided */
CHECK
(
0
,
fd_sess_new
(
&
sess1
,
NULL
,
TEST_SID
,
0
)
);
CHECK
(
EALREADY
,
fd_sess_new
(
&
sess2
,
NULL
,
TEST_SID
,
0
)
);
CHECK
(
sess2
,
sess1
);
CHECK
(
EALREADY
,
fd_sess_new
(
&
sess3
,
NULL
,
TEST_SID
,
strlen
(
TEST_SID
)
)
);
CHECK
(
sess3
,
sess1
);
CHECK
(
0
,
fd_sess_new
(
&
sess2
,
NULL
,
TEST_SID
,
strlen
(
TEST_SID
)
-
1
)
);
#if 1
fd_sess_dump
(
0
,
sess1
);
fd_sess_dump
(
0
,
sess2
);
#endif
CHECK
(
0
,
fd_sess_getsid
(
sess1
,
&
str1
)
);
CHECK
(
0
,
fd_sess_getsid
(
sess2
,
&
str2
)
);
CHECK
(
0
,
strncmp
(
str1
,
str2
,
strlen
(
TEST_SID
)
-
1
)
);
CHECK
(
0
,
strcmp
(
str1
,
TEST_SID
)
);
CHECK
(
0
,
fd_sess_destroy
(
&
sess2
)
);
}
/*
int fd_sess_new ( struct session ** session, char * diamId, char * opt, size_t optlen );
int fd_sess_fromsid ( char * sid, size_t len, struct session ** session, int * new);
int fd_sess_getsid ( struct session * session, char ** sid );
int fd_sess_settimeout( struct session * session, const struct timespec * timeout );
int fd_sess_destroy ( struct session ** session );
*/
/* That's all for the tests yet */
PASSTEST
();
}
include/freeDiameter/libfreeDiameter.h
View file @
52fcdcf1
This diff is collapsed.
Click to expand it.
libfreeDiameter/CMakeLists.txt
View file @
52fcdcf1
...
...
@@ -12,6 +12,7 @@ SET(LFD_SRC
dictionary.c
messages.c
mqueues.c
sessions.c
)
# Build as a shared library
...
...
libfreeDiameter/init.c
View file @
52fcdcf1
...
...
@@ -46,8 +46,9 @@ int fd_lib_init(void)
return
ret
;
}
/* Initialize the
end-to-end id counter with random value as described in RFC3588
*/
/* Initialize the
modules that need it
*/
fd_msg_eteid_init
();
CHECK_FCT
(
fd_sess_init
()
);
return
0
;
}
libfreeDiameter/libfD.h
View file @
52fcdcf1
...
...
@@ -44,6 +44,7 @@
/* Internal to the library */
extern
const
char
*
type_base_name
[];
void
fd_msg_eteid_init
(
void
);
int
fd_sess_init
(
void
);
/* Iterator on the rules of a parent object */
int
fd_dict_iterate_rules
(
struct
dict_object
*
parent
,
void
*
data
,
int
(
*
cb
)(
void
*
,
struct
dict_rule_data
*
)
);
...
...
libfreeDiameter/sessions.c
0 → 100644
View file @
52fcdcf1
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment