Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ITS - Intelligent Transport Systems
ITS
Commits
dbd36afa
Commit
dbd36afa
authored
Feb 15, 2016
by
filatov
Browse files
add support for relative time and position in certificate profiles
parent
b638d5b1
Changes
31
Expand all
Hide whitespace changes
Inline
Side-by-side
tools/itscertgen/checker/certinfo.c
View file @
dbd36afa
...
...
@@ -21,7 +21,7 @@
#include
"../cshared/copts.h"
#include
"../cshared/cserialize.h"
#include
"../cxml/cxml.h"
#include
"
../generator/
mkgmtime.h"
#include
"mkgmtime.h"
static
size_t
load_certificate
(
const
char
*
path
,
char
**
p
);
static
EC_KEY
*
load_public_key
(
const
char
*
path
,
const
EC_GROUP
*
group
);
...
...
@@ -169,13 +169,13 @@ char * _es_bufs[8][64];
int
_es_bufs_idx
=
0
;
static
const
char
*
_enumstring
(
int
value
,
const
char
**
names
,
int
nsize
)
{
const
char
*
ret
;
char
*
ret
;
if
(
!
_numeric
&&
value
>=
0
&&
value
<
nsize
&&
names
[
value
]){
return
names
[
value
];
}
ret
=
_es_bufs
[(
++
_es_bufs_idx
)
&
7
];
ret
=
(
char
*
)
_es_bufs
[(
++
_es_bufs_idx
)
&
7
];
sprintf
(
ret
,
"%d"
,
value
);
return
ret
;
return
(
const
char
*
)
ret
;
}
#define ENUMSTRING(V,L) _enumstring(V, L, sizeof(L)/sizeof(L[0]))
...
...
@@ -187,10 +187,10 @@ static int EccPoint_Size(const EccPoint * p){
static
void
EccPoint_Print
(
FILE
*
f
,
const
char
*
prefix
,
const
EccPoint
*
const
p
)
{
fprintf
(
f
,
"%s<ecc_point type=
\"
%s
\"
>
\n
%s
\t
"
,
prefix
,
ENUMSTRING
(
p
->
type
,
_point_types
),
prefix
);
print_x
(
f
,
p
->
x
,
32
);
print_x
(
f
,
(
const
char
*
)
p
->
x
,
32
);
if
(
p
->
type
==
4
){
fprintf
(
f
,
"
\n
%s
\t
"
,
prefix
);
print_x
(
f
,
p
->
y
,
32
);
print_x
(
f
,
(
const
char
*
)
p
->
y
,
32
);
}
fprintf
(
f
,
"
\n
%s</ecc_point>
\n
"
,
prefix
);
}
...
...
@@ -240,7 +240,7 @@ int main(int argc, char ** argv)
}
if
(
_xmlOutput
){
int
length
;
u
int
32_t
length
;
char
digest
[
8
];
const
char
*
p
=
cert
;
const
char
*
e
=
cert
+
certlen
;
...
...
@@ -278,11 +278,11 @@ int main(int argc, char ** argv)
}
fprintf
(
stdout
,
">
\n
"
);
p
+=
2
+
si
->
name_length
;
length
=
cintx_read
(
&
p
,
e
,
NULL
);
length
=
(
uint32_t
)
cintx_read
(
&
p
,
e
,
NULL
);
print_attributes
(
&
p
,
p
+
length
);
fprintf
(
stdout
,
"
\t
</subject>
\n
"
);
length
=
cintx_read
(
&
p
,
e
,
NULL
);
length
=
(
uint32_t
)
cintx_read
(
&
p
,
e
,
NULL
);
fprintf
(
stdout
,
"
\t
<validity>
\n
"
);
print_validity
(
&
p
,
p
+
length
);
fprintf
(
stdout
,
"
\t
</validity>
\n
"
);
...
...
@@ -390,7 +390,7 @@ static size_t load_certificate(const char * path, char ** p)
}
if
(
cert
[
0
]
!=
2
)
{
// try hexadecimal
in
t
i
;
size_
t
i
;
for
(
i
=
0
;
i
<
size
;
i
++
){
char
ch1
=
cert
[
i
];
if
(
ch1
<
'0'
...
...
@@ -513,9 +513,10 @@ static void calculate_certificate_digest(const char* data, int length, char
static
void
print_x
(
FILE
*
f
,
const
char
*
ptr
,
int
len
)
{
const
unsigned
char
*
e
=
(
const
unsigned
char
*
)(
ptr
+
len
);
for
(;
ptr
<
e
;
ptr
++
){
unsigned
char
c
=
*
ptr
;
const
unsigned
char
*
p
=
(
const
unsigned
char
*
)
ptr
;
const
unsigned
char
*
e
=
p
+
len
;
for
(;
p
<
e
;
p
++
){
unsigned
char
c
=
*
p
;
fprintf
(
f
,
"%02X"
,
c
);
}
}
...
...
@@ -528,7 +529,7 @@ static int print_attributes(const char ** pp, const char * e)
int
rc
=
0
;
const
char
*
p
=
*
pp
;
unsigned
char
atype
;
int
length
;
u
int
32_t
length
;
while
(
rc
==
0
&&
p
<
e
){
const
PublicKey
*
key
;
const
EccPoint
*
point
;
...
...
@@ -577,11 +578,11 @@ static int print_attributes(const char ** pp, const char * e)
p
+=
EccPoint_Size
(
point
);
break
;
case
its_aid_list
:
length
=
cintx_read
(
&
p
,
e
,
NULL
);
length
=
(
uint32_t
)
cintx_read
(
&
p
,
e
,
NULL
);
rc
=
print_aid_list
(
&
p
,
p
+
length
);
break
;
case
its_aid_ssp_list
:
length
=
cintx_read
(
&
p
,
e
,
NULL
);
length
=
(
uint32_t
)
cintx_read
(
&
p
,
e
,
NULL
);
rc
=
print_aid_ssp_list
(
&
p
,
p
+
length
);
break
;
default:
...
...
@@ -600,7 +601,7 @@ static int print_aid_list(const char ** pp, const char * e)
int
rc
=
0
;
const
char
*
p
=
*
pp
;
while
(
rc
==
0
&&
p
<
e
){
int
n
=
cintx_read
(
&
p
,
e
,
&
rc
);
u
int
32_t
n
=
(
uint32_t
)
cintx_read
(
&
p
,
e
,
&
rc
);
fprintf
(
stdout
,
"
\t\t\t
<aid value=
\"
%d
\"
/>
\n
"
,
n
);
}
*
pp
=
e
;
...
...
@@ -613,8 +614,8 @@ static int print_aid_ssp_list(const char ** pp, const char * e)
const
char
*
p
=
*
pp
;
while
(
rc
==
0
&&
p
<
e
){
char
*
data
;
int
n
=
cintx_read
(
&
p
,
e
,
&
rc
);
int
len
=
cintx_read
(
&
p
,
e
,
&
rc
);
u
int
32_t
n
=
(
uint32_t
)
cintx_read
(
&
p
,
e
,
&
rc
);
u
int
32_t
len
=
(
uint32_t
)
cintx_read
(
&
p
,
e
,
&
rc
);
fprintf
(
stdout
,
"
\t\t\t
<ssp aid=
\"
%d
\"
/>"
,
n
);
if
(
len
){
int
r
=
cxml_text_encode
(
NULL
,
&
data
,
p
,
len
);
...
...
@@ -726,7 +727,7 @@ static int print_validity(const char ** pp, const char * e)
if
(
rc
==
0
){
uint16_t
id
=
cint16_read
(
&
p
,
e
,
&
rc
);
if
(
rc
==
0
){
int
local
=
cintx_read
(
&
p
,
e
,
&
rc
);
u
int
32_t
local
=
(
uint32_t
)
cintx_read
(
&
p
,
e
,
&
rc
);
if
(
rc
==
0
){
fprintf
(
stdout
,
"
\t\t\t
<id dictionary=
\"
%s
\"
id=
\"
%u
\"
local=
\"
%u
\"
/>
\n
"
,
ENUMSTRING
(
dict
,
_id_region_dicts
),
id
,
local
);
...
...
tools/itscertgen/cshared/Makefile
View file @
dbd36afa
PROJECTROOT
=
..
BUILDROOT
=
../build
PROJECT
=
cshared
DEBUG
=
yes
testdir
=
tests
alibs
=
$(PROJECT)
solibs
=
$(PROJECT)
sources
:=
copts.c cserialize.c cstr.c
headers
:=
copts.h cserialize.h cstr.h
tests
:=
test_copts.c
include
../common.mk
PROJECTROOT
=
..
BUILDROOT
=
../build/
PROJECT
=
cshared
DEBUG
=
yes
testdir
=
tests
alibs
=
$(PROJECT)
solibs
=
$(PROJECT)
sources
:=
copts.c cserialize.c cstr.c cring.c e4c_lite.c
sources-WIN32
:=
cdir_win.c
headers
:=
copts.h cserialize.h cstr.h cdir.h cring.h cmem.h e4c_lite.h
tests
:=
test_copts.c
include
../common.mk
tools/itscertgen/cshared/cdir.h
0 → 100644
View file @
dbd36afa
#ifndef cdir_h
#define cdir_h
#include
"cstr.h"
#include
"cserialize.h"
#ifdef __cplusplus
extern
"C"
{
#endif
typedef
struct
cdir_t
cdir_t
;
enum
{
e_cdir_recursive
=
1
,
e_cdir_nofiles
=
4
,
e_cdir_nodirs
=
8
,
};
typedef
struct
{
const
char
*
path
;
const
char
*
fname
;
int
flags
;
uint64_t
size
;
}
cdir_stat_t
;
cdir_t
*
cdir_open
(
const
pchar_t
*
path
,
const
char
*
mask
,
int
flags
);
void
cdir_close
(
cdir_t
*
dir
);
cdir_t
*
cdir_rewind
(
cdir_t
*
dir
);
const
cdir_stat_t
*
cdir_next
(
cdir_t
*
dir
);
int
cdir_glob
(
const
char
*
mask
,
const
char
*
fname
);
#ifdef __cplusplus
}
#endif
#endif
tools/itscertgen/cshared/cdir_win.c
0 → 100644
View file @
dbd36afa
#define _CRT_SECURE_NO_WARNINGS
#include
"cdir.h"
#include
"cmem.h"
#include
"cstr.h"
#include
<windows.h>
struct
cdir_t
{
WIN32_FIND_DATA
fd
;
HANDLE
h
;
int
flags
;
char
*
path
;
char
*
fname
;
cdir_stat_t
st
;
};
static
void
_cdir_apply_filter
(
cdir_t
*
dir
)
{
do
{
if
(
dir
->
fd
.
dwFileAttributes
&
FILE_ATTRIBUTE_DIRECTORY
)
{
if
(
strcmp
(
"."
,
dir
->
fd
.
cFileName
)
&&
strcmp
(
".."
,
dir
->
fd
.
cFileName
)){
if
(
0
==
(
dir
->
flags
&
e_cdir_nodirs
))
return
;
}
}
else
{
if
(
0
==
(
dir
->
flags
&
e_cdir_nofiles
))
return
;
}
//skip this file
}
while
(
FindNextFile
(
dir
->
h
,
&
dir
->
fd
));
FindClose
(
dir
->
h
);
dir
->
h
=
INVALID_HANDLE_VALUE
;
}
cdir_t
*
cdir_open
(
const
pchar_t
*
path
,
const
char
*
mask
,
int
flags
)
{
cdir_t
*
dir
;
int
plen
=
path
?
pchar_len
(
path
)
:
0
;
dir
=
cnew
(
cdir_t
);
dir
->
path
=
pchar_alloc
(
plen
+
MAX_PATH
+
1
);
pchar_cpy
(
dir
->
path
,
path
);
while
(
plen
>
0
&&
(
dir
->
path
[
plen
-
1
]
==
'/'
||
dir
->
path
[
plen
-
1
]
==
'\\'
))
plen
--
;
if
(
plen
>
0
)
{
dir
->
path
[
plen
]
=
'\\'
;
dir
->
fname
=
dir
->
path
+
plen
+
1
;
}
else
{
dir
->
fname
=
dir
->
path
;
}
dir
->
flags
=
flags
;
if
(
mask
==
NULL
)
mask
=
"*"
;
strcpy
(
dir
->
fname
,
mask
);
dir
->
h
=
FindFirstFile
(
dir
->
path
,
&
dir
->
fd
);
if
(
INVALID_HANDLE_VALUE
==
dir
->
h
){
cfree
(
dir
);
return
NULL
;
}
_cdir_apply_filter
(
dir
);
dir
->
st
.
path
=
dir
->
path
;
dir
->
st
.
fname
=
dir
->
fname
;
return
dir
;
}
void
cdir_close
(
cdir_t
*
dir
)
{
if
(
dir
){
if
(
dir
->
h
!=
INVALID_HANDLE_VALUE
){
FindClose
(
dir
->
h
);
}
cfree
(
dir
);
}
}
cdir_t
*
cdir_rewind
(
cdir_t
*
dir
)
{
if
(
dir
){
if
(
dir
->
h
!=
INVALID_HANDLE_VALUE
){
FindClose
(
dir
->
h
);
}
*
dir
->
fname
=
0
;
dir
->
h
=
FindFirstFile
(
dir
->
path
,
&
dir
->
fd
);
if
(
INVALID_HANDLE_VALUE
==
dir
->
h
){
cfree
(
dir
);
dir
=
NULL
;
}
}
return
dir
;
}
const
cdir_stat_t
*
cdir_next
(
cdir_t
*
dir
)
{
if
(
dir
&&
dir
->
h
!=
INVALID_HANDLE_VALUE
){
pchar_cpy
(
dir
->
fname
,
dir
->
fd
.
cFileName
);
dir
->
st
.
size
=
dir
->
fd
.
nFileSizeHigh
;
dir
->
st
.
size
=
(
dir
->
st
.
size
<<
32
)
|
dir
->
fd
.
nFileSizeLow
;
if
(
FindNextFile
(
dir
->
h
,
&
dir
->
fd
)){
_cdir_apply_filter
(
dir
);
}
else
{
FindClose
(
dir
->
h
);
dir
->
h
=
INVALID_HANDLE_VALUE
;
}
return
&
dir
->
st
;
}
return
NULL
;
}
tools/itscertgen/cshared/clog.c
0 → 100644
View file @
dbd36afa
/*********************************************************************
######################################################################
##
## Created by: Denis Filatov
## Date : 10.11.2005
##
## Copyleft (c) 2003 - 2015
## This code is provided under the CeCill-C license agreement.
######################################################################
*********************************************************************/
#include
<stdio.h>
#include
<stdarg.h>
#include
<string.h>
#include
"clog.h"
static
int
_clog_level
=
CLOG_INFO
;
static
FILE
*
_clog_out
[
CLOG_LASTLEVEL
];
static
const
char
*
_clog_lnames
[
CLOG_LASTLEVEL
]
=
{
"FATAL"
,
"ERROR"
,
"WARNING"
,
"INFO"
,
"DEBUG"
,
};
static
int
_clog_out_initialized
=
0
;
static
void
_clog_out_initialize
(
void
)
{
int
i
;
_clog_out
[
CLOG_FATAL
]
=
stderr
;
_clog_out
[
CLOG_ERROR
]
=
stderr
;
_clog_out
[
CLOG_WARNING
]
=
stderr
;
for
(
i
=
CLOG_INFO
;
i
<
CLOG_LASTLEVEL
;
i
++
){
_clog_out
[
i
]
=
stdout
;
}
_clog_out_initialized
=
1
;
}
int
clog_level
(
void
)
{
return
_clog_level
;
}
void
clog_set_level
(
int
const
level
)
{
if
(
level
>=
0
&&
level
<=
CLOG_DEBUG
){
_clog_level
=
level
;
}
}
const
char
*
clog_level_name
(
int
const
level
)
{
const
char
*
ret
=
NULL
;
if
(
level
<
CLOG_LASTLEVEL
)
ret
=
_clog_lnames
[
level
];
return
ret
?
ret
:
CLOG_DEFAULT_LEVEL_NAME
;
}
void
clog_set_level_name
(
int
const
level
,
const
char
*
const
name
)
{
if
(
level
<
CLOG_LASTLEVEL
)
_clog_lnames
[
level
]
=
name
;
}
void
clog_set_output
(
int
const
level
,
void
*
const
out
)
{
if
(
0
==
_clog_out_initialized
){
_clog_out_initialize
();
}
if
(
level
<
0
){
int
i
;
for
(
i
=
0
;
i
<
sizeof
(
_clog_out
)
/
sizeof
(
_clog_out
[
0
]);
i
++
){
_clog_out
[
i
]
=
(
FILE
*
)
out
;
}
}
else
if
(
level
<
sizeof
(
_clog_out
)
/
sizeof
(
_clog_out
[
0
])){
_clog_out
[
level
]
=
(
FILE
*
)
out
;
}
}
void
clog_fprintf
(
void
*
const
f
,
int
const
level
,
const
char
*
format
,
...)
{
if
(
level
<=
_clog_level
){
FILE
*
out
;
va_list
ap
;
if
(
f
){
out
=
(
FILE
*
)
f
;
}
else
{
if
(
0
==
_clog_out_initialized
){
_clog_out_initialize
();
}
if
(
level
>=
sizeof
(
_clog_out
)
/
sizeof
(
_clog_out
[
0
])){
out
=
_clog_out
[
sizeof
(
_clog_out
)
/
sizeof
(
_clog_out
[
0
])
-
1
];
}
else
{
out
=
_clog_out
[
level
];
}
}
if
(
out
){
va_start
(
ap
,
format
);
vfprintf
(
out
,
format
,
ap
);
va_end
(
ap
);
{
int
l
=
strlen
(
format
);
if
(
l
==
0
||
format
[
l
-
1
]
!=
'\n'
){
fprintf
(
out
,
"
\n
"
);
}
}
}
}
}
tools/itscertgen/cshared/clog.h
0 → 100644
View file @
dbd36afa
/*********************************************************************
######################################################################
##
## Created by: Denis Filatov
## Date : 10.11.2005
##
## Copyleft (c) 2003 - 2015
## This code is provided under the CeCill-C license agreement.
######################################################################
*********************************************************************/
#ifndef clog_h
#define clog_h
enum
{
CLOG_FATAL
=
0
,
CLOG_ERROR
,
CLOG_WARNING
,
CLOG_INFO
,
CLOG_DEBUG
,
CLOG_LASTLEVEL
};
int
clog_level
(
void
);
void
clog_set_level
(
int
const
level
);
const
char
*
clog_level_name
(
int
const
level
);
void
clog_set_level_name
(
int
const
level
,
const
char
*
const
name
);
void
clog_set_output
(
int
const
level
,
void
*
const
out
);
#define CLOG_DEFAULT_LEVEL_NAME ""
#define STRMODULE(M) #M
#define XSTRMODULE(M) STRMODULE(M)
#define clog_flm(F, SMODULE, LEVEL, FORMAT, ...) clog_fprintf(F, LEVEL, "%10.10s: %7.7s: " FORMAT, SMODULE, clog_level_name(LEVEL), ##__VA_ARGS__)
#define clog_lm(SMODULE,LEVEL,FORMAT, ...) clog_flm((void*)0, SMODULE, LEVEL, FORMAT, ##__VA_ARGS__)
#define clog_fl(F,LEVEL,FORMAT, ...) clog_flm(F, XSTRMODULE(__MODULE__), LEVEL, FORMAT, ##__VA_ARGS__)
#define clog_l(LEVEL,FORMAT, ...) clog_flm((void*)0, XSTRMODULE(__MODULE__), LEVEL, FORMAT, ##__VA_ARGS__)
#define clog_fatal(FORMAT, ...) clog_l(CLOG_FATAL, FORMAT, ##__VA_ARGS__)
#define clog_error(FORMAT, ...) clog_l(CLOG_ERROR, FORMAT, ##__VA_ARGS__)
#define clog_warning(FORMAT, ...) clog_l(CLOG_WARNING, FORMAT, ##__VA_ARGS__)
#define clog_info(FORMAT, ...) clog_l(CLOG_INFO, FORMAT, ##__VA_ARGS__)
#define clog_debug(FORMAT, ...) clog_l(CLOG_DEBUG, FORMAT, ##__VA_ARGS__)
#define fclog_fatal(F,FORMAT, ...) clog_fl(F, CLOG_FATAL, FORMAT, ##__VA_ARGS__)
#define fclog_error(F,FORMAT, ...) clog_fl(F, CLOG_ERROR, FORMAT, ##__VA_ARGS__)
#define fclog_warning(F,FORMAT, ...) clog_fl(F, CLOG_WARNING, FORMAT, ##__VA_ARGS__)
#define fclog_info(F,FORMAT, ...) clog_fl(F, CLOG_INFO, FORMAT, ##__VA_ARGS__)
#define fclog_debug(F,FORMAT, ...) clog_fl(F, CLOG_DEBUG, FORMAT, ##__VA_ARGS__)
#define mclog_fatal(MODULE, FORMAT, ...) clog_lm(#MODULE, CLOG_FATAL, FORMAT, ##__VA_ARGS__)
#define mclog_error(MODULE, FORMAT, ...) clog_lm(#MODULE, CLOG_ERROR, FORMAT, ##__VA_ARGS__)
#define mclog_warning(MODULE, FORMAT, ...) clog_lm(#MODULE, CLOG_WARNING, FORMAT, ##__VA_ARGS__)
#define mclog_info(MODULE, FORMAT, ...) clog_lm(#MODULE, CLOG_INFO, FORMAT, ##__VA_ARGS__)
#define mclog_debug(MODULE, FORMAT, ...) clog_lm(#MODULE, CLOG_DEBUG, FORMAT, ##__VA_ARGS__)
#define fmclog_fatal(F, MODULE, FORMAT, ...) clog_flm(F, #MODULE, CLOG_FATAL, FORMAT, ##__VA_ARGS__)
#define fmclog_error(F, MODULE, FORMAT, ...) clog_flm(F, #MODULE, CLOG_ERROR, FORMAT, ##__VA_ARGS__)
#define fmclog_warning(F, MODULE, FORMAT, ...) clog_flm(F, #MODULE, CLOG_WARNING, FORMAT, ##__VA_ARGS__)
#define fmclog_info(F, MODULE, FORMAT, ...) clog_flm(F, #MODULE, CLOG_INFO, FORMAT, ##__VA_ARGS__)
#define fmclog_debug(F, MODULE, FORMAT, ...) clog_flm(F, #MODULE, CLOG_DEBUG, FORMAT, ##__VA_ARGS__)
void
clog_fprintf
(
void
*
const
f
,
int
const
level
,
const
char
*
format
,
...);
#undef __CLOG_MODULE
#endif
tools/itscertgen/cshared/cmem.h
0 → 100644
View file @
dbd36afa
/*********************************************************************
######################################################################
##
## Created by: Denis Filatov
## Date : 10.11.2005
##
## Copyleft (c) 2003 - 2015
## This code is provided under the CeCill-C license agreement.
######################################################################
*********************************************************************/
#ifndef cmem_h
#define cmem_h
#include
<stdlib.h>
#include
<string.h>
#define callocate(N) malloc(N)
#define callocate0(N) calloc(1,N)
#define cfree(P) free(P)
#define cnew(T) (T*)callocate(sizeof(T))
#define cnew0(T) (T*)callocate0(sizeof(T))
typedef
void
(
cdestructor_fn
)(
void
*
);
#if defined(__GNUC__)
#define cfetch_and_add(P,X) __sync_fetch_and_add(P, X)
#define cfetch_and_sub(P,X) __sync_fetch_and_sub(P, X)
#define cadd_and_fetch(P,X) __sync_add_and_fetch(P, X)
#define csub_and_fetch(P,X) __sync_sub_and_fetch(P, X)
#define cfetch_and_inc(P) cfetch_and_add(P,1)
#define cfetch_and_dec(P) cfetch_and_sub(P,1)
#define cinc_and_fetch(P) cadd_and_fetch(P,1)
#define cdec_and_fetch(P) csub_and_fetch(P,1)
#elif defined (_MSC_VER)
#include
<windows.h>
#define cfetch_and_add(P,X) (InterlockedAddNoFence(P,X)-X)
#define cfetch_and_sub(P,X) (InterlockedAddNoFence(P,-X)+X)
#define cadd_and_fetch(P,X) InterlockedAddNoFence(P,X)
#define csub_and_fetch(P,X) InterlockedAddNoFence(P,-X)
#define cfetch_and_inc(P) (InterlockedIncrementNoFence(P)-1)
#define cfetch_and_dec(P) (InterlockedDecrementNoFence(P)+1)
#define cinc_and_fetch(P) InterlockedIncrementNoFence(P)
#define cdec_and_fetch(P) InterlockedDecrementNoFence(P)
#ifndef __cplusplus
#define inline _inline
#endif
#endif
__inline
static
void
*
cmemdup
(
const
void
*
const
ptr
,
int
size
)
{
void
*
p
;
if
(
size
>
0
){
p
=
callocate
(
size
);
if
(
p
&&
ptr
)
{
memcpy
(
p
,
ptr
,
size
);
}
}
else
{
p
=
NULL
;
}
return
p
;
}
__inline
static
void
*
_cretain
(
void
*
p
,
int
*
prcntr
)
{
if
(
*
prcntr
!=
0
){
cinc_and_fetch
(
prcntr
);
}
return
p
;
}
__inline
static
void
_crelease
(
void
*
p
,
int
*
prcntr
,
void
*
destr
)
{
if
(
*
prcntr
!=
0
){
if
(
0
==
cdec_and_fetch
(
prcntr
)){
if
(
destr
)
((
cdestructor_fn
*
)
destr
)(
p
);
else
free
(
p
);
}
}
}
#if defined(__GNUC__)
#define cretain(S) (__typeof__(S)*)_cretain(S, &(S)->_rcntr)
#elif defined (_MSC_VER)
#define cretain(S) _cretain(S, &(S)->_rcntr)
#endif
#define crelease(S,D) _crelease(S, &(S)->_rcntr, D)
#endif
tools/itscertgen/cshared/copts.c
View file @
dbd36afa
This diff is collapsed.
Click to expand it.
tools/itscertgen/cshared/copts.h
View file @
dbd36afa
/*********************************************************************
######################################################################
##
## Created by: Denis Filatov
## Date : 10.11.2005
##
## C command line arguments and simple config file parser
##
## Copyleft (c) 2003 - 2007
## This code is provided under the CeCill-C license agreement.
######################################################################
*********************************************************************/
#ifndef copts_h
#define copts_h
#include
<stdio.h>
#ifdef __cplusplus
extern
"C"
{
#endif
/** @defgroup COPTS copts - Programm line option processing.
* @{ */
#ifndef DOXYGEN
typedef
struct
copt_t
copt_t
;
typedef
enum
coptflag_t
coptflag_t
;
typedef
enum
coptype_t
coptype_t
;
typedef
enum
copterr_t
copterr_t
;
#endif
/** @enum coptype_t
* Option types definitions.
*/
enum
coptype_t
{
COPT_BOOL
,
/**< Boolean option. Doesn't wants for argument.*/
COPT_BOOLI
,
/**< Inverted Boolean option. Doesn't wants for argument. */
COPT_LONG
,
/**< Wants for long argument */
COPT_ULONG
,
/**< Wants for unsigned long argument */
COPT_SHORT
,
/**< Wants for short (16 bit) argument */
COPT_USHORT
,
/**< Wants for unsigned short argument */