Commit c89d62ed authored by berge's avatar berge

Merged revision(s) 1840-1916 from branches/Security

parent d0339b89
......@@ -27,6 +27,8 @@ import org.etsi.its.adapter.ports.FsapPort;
import org.etsi.its.adapter.ports.GnPort;
import org.etsi.ttcn.tci.CharstringValue;
import de.fraunhofer.sit.c2x.CryptoLib;
/**
* This class is used to centralise test adapter configuration and execution parameters
* All settings are component specific (multiton)
......@@ -411,8 +413,9 @@ public class Management implements IManagementTA, IManagementLayers {
// Extract public keys
atCertificate = certificate.toByteArray();
// System.out.println("Management.setupSecuredModeFromTaConfig: certificate=" + ByteHelper.byteArrayToString(value));
atCertificateDigest = new byte[8];
System.arraycopy(atCertificate, 3, atCertificateDigest, 0, 8);
// Compute AT certificate digest
byte[] atHash = CryptoLib.hashWithSha256(atCertificate);
atCertificateDigest = ByteHelper.extract(atHash, atHash.length - 8, 8);
// System.out.println("Management.setupSecuredModeFromTaConfig: atCertificateDigest=" + ByteHelper.byteArrayToString(atCertificateDigest));
int offset = 18;
// KeyX
......
......@@ -7,7 +7,7 @@ package org.etsi.its.adapter;
import java.io.ByteArrayInputStream;
import org.etsi.ttcn.common.ByteHelper;
import org.etsi.common.ByteHelper;
public class TlsHelper {
......
......@@ -242,7 +242,7 @@ public class GnPort extends ProtocolPort implements Runnable, IEthernetSpecific
@Override
public boolean send(byte[] message) {
HashMap<String, Object> params = new HashMap<String, Object>();
ByteHelper.dump(">>> GnPort.send", message);
// ByteHelper.dump(">>> GnPort.send", message);
byte[] destMacAddress = ByteHelper.extract(message, message.length - 6, 6);
message = ByteHelper.extract(message, 0, message.length - 6);
......@@ -250,7 +250,7 @@ public class GnPort extends ProtocolPort implements Runnable, IEthernetSpecific
if (management.isSecuredModeSet()) { // Secure mode disabled
message = createSecuredMessage(message);
}
ByteHelper.dump("GnPort.send", message);
// ByteHelper.dump("GnPort.send", message);
return send(message, params);
}
......
......@@ -77,7 +77,7 @@ public abstract class ProtocolPort extends Layer implements IPort, IObservable {
public boolean send(byte[] message) {
HashMap<String, Object> params = new HashMap<String, Object>();
ByteHelper.dump("ProtocolPortLayer.send", message);
// ByteHelper.dump("ProtocolPortLayer.send", message);
return send(message, params);
}
......
......@@ -5,11 +5,6 @@ import org.etsi.certificates.io.ICertificatesIO;
public class CertificatesIOFactory {
/**
* The single instance of this class.
*/
private static CertificatesIOFactory _instance = new CertificatesIOFactory();
/**
* The single instance of the class CertificatesIO.
*/
......@@ -20,7 +15,7 @@ public class CertificatesIOFactory {
* @return The single instance of this class.
*/
public static ICertificatesIO getInstance() {
return _instance._certIO;
return _certIO;
}
/**
......
......@@ -7,6 +7,7 @@ package org.etsi.certificates;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
......@@ -68,32 +69,46 @@ public final class Helpers {
/**
* Recursively walk a directory tree and return a List of all Files found; the List is sorted using File.compareTo().
* @param startingDir is a valid directory, which can be read.
* @param p_startingDir The valid directory, which can be read.
* @param p_extension The file extension, in lower case
* @param p_excludedPatterns The pattern which shall be excluded, in lower case
*/
public List<File> getFileListing(File startingDir) throws FileNotFoundException {
validateDirectory(startingDir);
List<File> result = getFileListingNoSort(startingDir);
public List<File> getFileListing(File p_startingDir, final String p_extension, final String[] p_excludedPatterns) throws FileNotFoundException {
validateDirectory(p_startingDir);
List<File> result = getFileListingNoSort(p_startingDir, p_extension, p_excludedPatterns);
Collections.sort(result);
return result;
}
private List<File> getFileListingNoSort(File startingDir) throws FileNotFoundException {
private List<File> getFileListingNoSort(final File p_startingDir, final String p_extension, final String[] p_excludedPatterns) throws FileNotFoundException {
List<File> result = new ArrayList<File>();
File[] filesAndDirs = startingDir.listFiles();
FilenameFilter filter = new FilenameFilter() {
@Override
public boolean accept(final File p_dirName, final String p_fileName) {
String name = p_fileName.toLowerCase();
if (!p_extension.isEmpty() && !name.endsWith(p_extension)) {
return false;
}
if (p_excludedPatterns != null) {
for (String excludePattern : p_excludedPatterns) {
if (name.indexOf(excludePattern) != -1) {
return false;
}
}
}
return true;
}
};
File[] filesAndDirs = p_startingDir.listFiles(filter);
List<File> filesDirs = Arrays.asList(filesAndDirs);
for (File file : filesDirs) {
if (file.isDirectory() && ((file.getName().indexOf(".svn") != -1)
|| (file.getName().indexOf("._.DS_Store") != -1)
|| (file.getName().indexOf(".DS_Store") != -1))) { // For debug purpose only
// Skip svn files
continue;
}
result.add(file); // always add, even if directory
if (!file.isFile()) {
//must be a directory
//recursive call!
List<File> deeperList = getFileListingNoSort(file);
List<File> deeperList = getFileListingNoSort(file, p_extension, p_excludedPatterns);
result.addAll(deeperList);
}
}
......
......@@ -36,6 +36,14 @@ public interface ICertificatesIO {
*/
boolean readCertificate(final String certificateId, final ByteArrayOutputStream certificate);
/**
* @desc Read the specified certificate digest
* @param certificateId the certificate identifier
* @param digest the expected digest
* @return true on success, false otherwise
*/
boolean readCertificateDigest(final String certificateId, final ByteArrayOutputStream digest);
/**
* @desc Read the private keys for the specified certificate
* @param keysId the keys identifier
......@@ -45,4 +53,11 @@ public interface ICertificatesIO {
*/
boolean readPrivateKeys(final String keysName, final ByteArrayOutputStream signingPrivateKey, final ByteArrayOutputStream encryptPrivateKey);
/**
* @desc Retrieve the key identifier associated to the Digest value
* @param p_hashedId8ToBeUsed the Digest value
* @return The key identifier
*/
String getKeyIdFromHashedId8(final byte[] p_hashedId8ToBeUsed);
} // End of interface ICertificatesIO
......@@ -38,8 +38,8 @@ public class MainCodec extends ICodec {
@Override
public Value decode(CodecBuffer buf, Type decodingHypothesis) {
System.out.println(">>> MainCodec.decode: " + decodingHypothesis.getName());
ByteHelper.dump(">>> MainCodec.decode: ", buf.getBytes());
// System.out.println(">>> MainCodec.decode: " + decodingHypothesis.getName());
// ByteHelper.dump(">>> MainCodec.decode: ", buf.getBytes());
CodecFactory cf = CodecFactory.getInstance();
TciCDProvided extCodec = cf.getExternalCodec(decodingHypothesis.getTypeEncoding());
......@@ -61,10 +61,10 @@ public class MainCodec extends ICodec {
codec.preDecode(buf, decodingHypothesis);
// TODO To be removed, for debug purpose only
Value decValue = codec.decode(buf, decodingHypothesis);
System.out.println("<<< MainCodec.decode: " + decValue);
return decValue;
// return codec.decode(buf, decodingHypothesis);
// Value decValue = codec.decode(buf, decodingHypothesis);
// System.out.println("<<< MainCodec.decode: " + decValue);
// return decValue;
return codec.decode(buf, decodingHypothesis);
}
}
......@@ -90,7 +90,7 @@ public class MainCodec extends ICodec {
buf = preBuf;
}
ByteHelper.dump("<<< MainCodec.encode: ", buf.getBytes());
// ByteHelper.dump("<<< MainCodec.encode: ", buf.getBytes());
return buf;
}
}
......
......@@ -26,7 +26,7 @@ public class Float extends ICodec {
FloatValue fv = mainCodec.getTciCDRequired().getFloat();
fv.setFloat(ByteHelper.byteArrayToFloat(buf.readBits(java.lang.Float.SIZE)));
System.out.println("<<< Float.decode: " + fv.getFloat());
// System.out.println("<<< Float.decode: " + fv.getFloat());
return fv;
}
......
......@@ -113,6 +113,7 @@ public class Plugin {
cf.setCodec(TciTypeClass.INTEGER, "LibItsSecurity", "HeaderFieldContainer.its_aid", IntX.class);
cf.setCodec(TciTypeClass.INTEGER, "LibItsSecurity", "ValidityRestrictionContainer.end_validity", Time32.class);
cf.setCodec(TciTypeClass.SET_OF, "LibItsSecurity", "SignerInfoContainer.certificates", RecordOf.class);
cf.setCodec(TciTypeClass.SET_OF, "LibItsSecurity", "GeographicRegionContainer.rectangular_region", RecordOf.class);
cf.setCodec(TciTypeClass.SET_OF, "LibItsSecurity", "GeographicRegionContainer.polygonal_region", RecordOf.class);
cf.setCodec(TciTypeClass.SET_OF, "LibItsSecurity", "HeaderFieldContainer.digests", RecordOf.class);
......
......@@ -24,6 +24,7 @@ public class RecordOf extends org.etsi.ttcn.codec.generic.RecordOf {
// System.out.println(">>> security.RecordOf.decode: " + decodingHypothesis.getName());
int len = (int) TlsHelper.getInstance().tls2size(buf);// buf.readBytes(1)[0]; // Get number of items into the RecordOf
// System.out.println("security.RecordOf.decode: length=" + len);
if (len == 0) {
RecordOfValue rov = (RecordOfValue)decodingHypothesis.newInstance();
rov.setLength(0);
......
BUILDROOT = .
PROJECT = kgen
DEBUG = yes
bins = certgen
sources := certgen.c ecc_openssl.c mkgmtime.c
sources-WIN32 := applink.c
packages += openssl cxml cshared
include common.mk
#define APPLINK_STDIN 1
#define APPLINK_STDOUT 2
#define APPLINK_STDERR 3
#define APPLINK_FPRINTF 4
#define APPLINK_FGETS 5
#define APPLINK_FREAD 6
#define APPLINK_FWRITE 7
#define APPLINK_FSETMOD 8
#define APPLINK_FEOF 9
#define APPLINK_FCLOSE 10 /* should not be used */
#define APPLINK_FOPEN 11 /* solely for completeness */
#define APPLINK_FSEEK 12
#define APPLINK_FTELL 13
#define APPLINK_FFLUSH 14
#define APPLINK_FERROR 15
#define APPLINK_CLEARERR 16
#define APPLINK_FILENO 17 /* to be used with below */
#define APPLINK_OPEN 18 /* formally can't be used, as flags can vary */
#define APPLINK_READ 19
#define APPLINK_WRITE 20
#define APPLINK_LSEEK 21
#define APPLINK_CLOSE 22
#define APPLINK_MAX 22 /* always same as last macro */
#ifndef APPMACROS_ONLY
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
static void *app_stdin(void) { return stdin; }
static void *app_stdout(void) { return stdout; }
static void *app_stderr(void) { return stderr; }
static int app_feof(FILE *fp) { return feof(fp); }
static int app_ferror(FILE *fp) { return ferror(fp); }
static void app_clearerr(FILE *fp) { clearerr(fp); }
static int app_fileno(FILE *fp) { return _fileno(fp); }
static int app_fsetmod(FILE *fp,char mod)
{ return _setmode (_fileno(fp),mod=='b'?_O_BINARY:_O_TEXT); }
#ifdef __cplusplus
extern "C" {
#endif
__declspec(dllexport)
void **
#if defined(__BORLANDC__)
__stdcall /* __stdcall appears to be the only way to get the name
* decoration right with Borland C. Otherwise it works
* purely incidentally, as we pass no parameters. */
#else
__cdecl
#endif
OPENSSL_Applink(void)
{ static int once=1;
static void *OPENSSL_ApplinkTable[APPLINK_MAX+1]={(void *)APPLINK_MAX};
if (once)
{ OPENSSL_ApplinkTable[APPLINK_STDIN] = app_stdin;
OPENSSL_ApplinkTable[APPLINK_STDOUT] = app_stdout;
OPENSSL_ApplinkTable[APPLINK_STDERR] = app_stderr;
OPENSSL_ApplinkTable[APPLINK_FPRINTF] = fprintf;
OPENSSL_ApplinkTable[APPLINK_FGETS] = fgets;
OPENSSL_ApplinkTable[APPLINK_FREAD] = fread;
OPENSSL_ApplinkTable[APPLINK_FWRITE] = fwrite;
OPENSSL_ApplinkTable[APPLINK_FSETMOD] = app_fsetmod;
OPENSSL_ApplinkTable[APPLINK_FEOF] = app_feof;
OPENSSL_ApplinkTable[APPLINK_FCLOSE] = fclose;
OPENSSL_ApplinkTable[APPLINK_FOPEN] = fopen;
OPENSSL_ApplinkTable[APPLINK_FSEEK] = fseek;
OPENSSL_ApplinkTable[APPLINK_FTELL] = ftell;
OPENSSL_ApplinkTable[APPLINK_FFLUSH] = fflush;
OPENSSL_ApplinkTable[APPLINK_FERROR] = app_ferror;
OPENSSL_ApplinkTable[APPLINK_CLEARERR] = app_clearerr;
OPENSSL_ApplinkTable[APPLINK_FILENO] = app_fileno;
OPENSSL_ApplinkTable[APPLINK_OPEN] = _open;
OPENSSL_ApplinkTable[APPLINK_READ] = _read;
OPENSSL_ApplinkTable[APPLINK_WRITE] = _write;
OPENSSL_ApplinkTable[APPLINK_LSEEK] = _lseek;
OPENSSL_ApplinkTable[APPLINK_CLOSE] = _close;
once = 0;
}
return OPENSSL_ApplinkTable;
}
#ifdef __cplusplus
}
#endif
#endif
This diff is collapsed.
export LANG=en_US
ALL_CONFIGURATIONS := POSIX WIN32
.PHONY: all clean tests docs cleandocs distr DUMMY
ifeq ($(ARCH),)
ARCH = $(shell gcc -dumpmachine)
GCC := gcc
else
GCC := $(addprefix $(addsuffix -,$(ARCH)), gcc)
endif
ifneq ($(findstring w32,$(ARCH)),)
packages := $(filter-out readline threads, $(packages))
CFG += WIN32
else
CFG += POSIX
endif
cflags += -Wall
ifeq ($(DEBUG),)
DEBUG=no
endif
ifeq ($(DEBUG),yes)
cflags += -g -O0
defines += DEBUG
dsuffix = -d
else
defines += NDEBUG
cflags += -O2
endif
ifneq ($(filter readline, $(packages)),)
defines += USE_READLINE
libs += -lreadline
endif
ifneq ($(filter dmalloc, $(packages)),)
defines += DMALLOC DMALLOC_FUNC_CHECK
libs += -ldmalloc
dsuffix = -dmalloc
endif
ifneq ($(filter thread, $(packages)),)
defines += USE_THREADS
libs += -lpthread
endif
ifneq ($(filter profile, $(packages)),)
cflags += -pg
endif
ifneq ($(filter openssl, $(packages)),)
ifneq ($(findstring mingw32,$(ARCH)),)
includes += C:/OpenSSL-Win32/include
libs += C:/OpenSSL-Win32/lib/MinGW/libeay32.a C:/OpenSSL-Win32/lib/MinGW/ssleay32.a
else
libs += -lssl -lcrypto
endif
endif
ifneq ($(filter cxml, $(packages)),)
predirs += cxml
endif
ifneq ($(filter cshared, $(packages)),)
predirs += cshared
endif
ifeq ($(testdir), )
testdir := tests
endif
includes += $(foreach cfg,$(CFG),$(includes-$(cfg)))
defines += $(foreach cfg,$(CFG),$(defines-$(cfg)))
libs += $(foreach cfg,$(CFG),$(libs-$(cfg)))
sources += $(foreach cfg,$(CFG),$(sources-$(cfg)))
headers += $(foreach cfg,$(CFG),$(headers-$(cfg)))
tests += $(foreach cfg,$(CFG),$(tests-$(cfg)))
distfiles += $(foreach cfg,$(CFG),$(distfiles-$(cfg)))
predirs += $(foreach cfg,$(CFG),$(predirs-$(cfg)))
postdirs += $(foreach cfg,$(CFG),$(postdirs-$(cfg)))
tests := $(addprefix $(addsuffix /,$(testdir)),$(tests))
sources := $(addprefix $(addsuffix /,$(srcdir)),$(sources))
headers := $(addprefix $(addsuffix /,$(incdir)),$(headers))
cflags += $(addprefix -I, $(includes)) $(addprefix -D, $(defines))
ifeq ($(BUILDROOT),)
BUILDROOT = .
endif
outdir := $(BUILDROOT)/$(ARCH)$(dsuffix)
objdir := $(outdir)/$(PROJECT)
objects := $(patsubst %.c, $(objdir)/%.o, $(sources))
testbins := $(patsubst %.c, $(outdir)/%, $(tests))
dirs := $(objdir) $(outdir)/tests
alibnames := $(patsubst %, $(outdir)/lib%.a, $(alibs))
solibnames := $(patsubst %, $(outdir)/lib%.so, $(solibs))
binnames := $(patsubst %, $(outdir)/%, $(bins))
ldflags += $(patsubst %, -L%, $(outdir) $(libdirs))
ifneq ($(filter cxml, $(packages)),)
libs += $(outdir)/libcxml.a
endif
ifneq ($(filter cshared, $(packages)),)
libs += $(outdir)/libcshared.a
endif
all: $(dirs) $(predirs) $(alibnames) $(solibnames) $(binnames) $(postdirs)
tests: all $(testbins)
$(predirs) $(postdirs): DUMMY
$(MAKE) -C $@ BUILDROOT=$(BUILDROOT)/.. DEBUG=$(DEBUG)
$(alibnames): $(outdir)/lib%.a : $(objects)
ar rcs $@ $^
$(solibnames): $(outdir)/lib%.so : $(objects)
$(GCC) $(cflags) -shared $(ldflags) -o $@ $^ $(csharedlib) $(libs)
$(binnames): $(outdir)/% : $(objects)
$(GCC) $(cflags) $(ldflags) -o $@ $^ $(csharedlib) $(libs)
$(testbins): $(alibnames)
$(testbins): $(outdir)/tests/% : tests/%.c
$(GCC) $(cflags) -o $@ $< $(alibnames) $(libs)
$(dirs):
mkdir -p $@
$(objects): $(objdir)/%.o: %.c
@mkdir -p $(dir $@)
$(GCC) $(cflags) -o $@ -MMD -MF $(objdir)/$*.d -c $<
clean:
rm -rf $(outdir) $(addsuffix /*~, . $(subdirs))
distfiles += $(wildcard Makefile $(DOXYFILE))
dist:
-rm -rf $(PROJECT) $(PROJECT)-$(shell date -u '+%Y%m%d').tar.gz
mkdir $(PROJECT)
cp --parents $(sources) $(headers) $(distfiles) $(addprefix tests/, $(tests)) $(PROJECT)
tar -zcvf $(PROJECT)-$(shell date -u '+%Y%m%d').tar.gz $(PROJECT)
rm -rf $(PROJECT)
# tar -zcvf $(PROJECT)-$(shell date -u '+%Y%m%d').tar.gz $(sources) $(headers) $(distfiles) $(addprefix tests/, $(tests))
ifneq (,$(DOXYFILE))
docs: $(DOXYFILE)
doxygen $(DOXYFILE)
cleandocs:
rm -rf doc/html
endif
include $(wildcard $(addsuffix /*.d, $(objdir)))
BUILDROOT = ..
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
This diff is collapsed.
/*********************************************************************
######################################################################
## copts.h
##
######################################################################
##
## Created by: Denis Filatov
## Date : 10.11.2005
##
##
## C command line arguments and simple config file parser
##
## Copyright (c) 2003 - 2007
## All rights reserved.
##
## STRICTLY CONFIDENTIAL.
## THIS SOURCE CODE IS A PROPERTY OF POPULAR TELEPHONY INC.
## IT IS PROTECTED BY INTERNATIONAL LAWS
## ANY UNAUTHORISED DISTRIBUTION OF THIS CODE IS PROHIBITED
##
######################################################################
*********************************************************************/
#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 */
COPT_CHAR , /**< Wants for char or unsigned char argument */
COPT_STR , /**< Wants for string (const char *) arguments */
COPT_HOST, /**< Wants for string (const char *) arguments. Checks url syntax. */
COPT_STRLIST, /**< Wants for string list argument (const char *[])
* Every time when this opion will be occuren in argv
* the value will be assigned to given pointer and
* this pointer will be incremented. */
COPT_STRENUM, /**< Wants for one of the string in the array given by vptr)
* Array of strings must be terminated by NULL pointer.
* After option found the vptr pointer will point to the
* to the element given by option */
COPT_CFGFILE, /**< Wants for string (const char *) arguments.
* Treat it as config file name and load if found.
* If one or more config file options are exists in copt_t list
* this options will be executed before any other options parsing */
COPT_HELP, /**< Do not wants for argument.
* If this option is occured in command line parsing will be
* terminated imediate and COPT_EHELP will be returned */
COPT_TYPE_MASK = 0x00FF, /**< Option type mask. For internal usage. */
COPT_CALLBACK = 0x4000, /**< Mask. Can be or-ed with any other option.
* That's mean treat vptr as a callback addres to call
* when option is occured */
COPT_CONFIG = 0x8000, /**< Mask. Can be or-ed with any other option.
* That's mean this option can be reached from config file
* and have to be writen to.*/
COPT_END = 0xFFFF, /**< End of options.
* If vptr is not NULL, treat it as callback to call for unknown
* options and non-option values */
};
#define COPT_INT COPT_LONG
#define COPT_UINT COPT_ULONG
#define COPT_IBOOL COPT_BOOLI
/** Main options item.
* Have to be used to define options items.
* Short and long options can be defined.
* Possible options notations:
* - Boolean options:
* - -o
* - --option
* - Other types except of boolean:
* - -o value
* - -o=value
* - --option=value
*/
struct copt_t
{
const char* sopts; /**< Short options. */
const char* lopt; /**< Long option. */
const coptype_t type; /**< Option type ( see @ref coptype_t ). */
void* vptr; /**< Option variable pointer. */
const char* helpstr; /**< Option help string. */
};
/**
* Execute option parser.
* @param argc Command line parameters count (from arguments of main() for example).
* @param argv Array of command line parameters.
* @param flags Configuration flags ( @ref coptflag_t ).
* @param opts Array of possible options. Must be finished by item with COPT_END type.
* @return <ul><li>On success returns the index of the first option argument in the arguments array.<li>On error returns negative index of the invalid option in the arguments array.</ul>
*/
int coptions(int argc, char* argv[], int flags, copt_t* opts);
/** Get enum index from the option variable.
* @param opts @ref copt_t array.
* @param idx Index of the enum option in the array.
* @param ptr The initial value of the @a vptr field of the opion array item.
* @return the integer enum value of the selected item.
*/
#define copts_enum_value(opts,idx,ptr) \
((const char **)((opts)[idx]).vptr) - ((const char **)(ptr))
/**
* Load options config file.
* @param filename File path to load.
* @param section If not NULL then try to find the last occurance of the
* given section or load the file complet.
* @param flags Configuration flags ( see @ref coptflag_t ).
* @param opts The Array of possible option records. Must be finished
* by the item with COPT_END type.
* @return
<ul><li>On success returns 0.<li>On error returns negative line number of the invalid expression.</ul>
*/
int coptions_load(const char* filename, const char * section, int flags, copt_t* const opts);
/**
* Save current options to the file
*/
int coptions_save(const char* filename, const copt_t* const opts);
/**
* Save current options to already opened file
*/
int coptions_fsave(FILE * fd, const copt_t* const opts);
/**
* Generate and print the help page.
* @param fd File descriptor to print the resulting help page.
* @param prgname Application name. Can be taken from argv[0].
* @param opt Options array.
* @param usagestr The string to print before option list.
* @param header Help page header.
* @param footer Help page footer.
*/
void coptions_help_ex(FILE * fd, const char * prgname, int flags, copt_t* opt, const char* usagestr,
const char* header, const char* footer);
/** The lite version of the @ref coptions_help_ex.
* @param fd File descriptor to print the resulting help page.
* @param prgname Application name. Can be taken from argv[0].
* @param opt Options array.
* @param usagestr The string to print before option list.
*/
#define coptions_help(fd,prgname,flags,opt,usagestr) \
coptions_help_ex(fd,prgname,flags,opt,usagestr,NULL,NULL)
/** Wild value definition */
typedef union{
int v_boolean;
signed short v_short;
unsigned short v_ushort;
signed long v_long;
unsigned long v_ulong;
char v_char;
char * v_str;
}copt_value_t;