Guardtime KSI c SDK
Data Structures | Macros | Typedefs | Functions
TLV Templates

Data Structures

struct  KSI_TlvTemplate_st
 

Macros

#define KSI_TLV_TEMPLATE(name)   name##_template
 
#define KSI_IMPORT_TLV_TEMPLATE(name)   KSI_DEFINE_EXTERN(const KSI_TlvTemplate KSI_TLV_TEMPLATE(name)[])
 
#define KSI_TLV_TEMPLATE_OBJECT   1
 
#define KSI_TLV_TEMPLATE_COMPOSITE   2
 
#define KSI_TLV_TEMPLATE_LIST   3
 
#define KSI_TLV_TMPL_FLG_NONE   0x00
 
#define KSI_TLV_TMPL_FLG_FORWARD   0x01
 
#define KSI_TLV_TMPL_FLG_NONCRITICAL   0x02
 
#define KSI_TLV_TMPL_FLG_MANDATORY   0x04
 
#define KSI_TLV_TMPL_FLG_LEAST_ONE_G0   0x08
 
#define KSI_TLV_TMPL_FLG_LEAST_ONE_G1   0x10
 
#define KSI_TLV_TMPL_FLG_MORE_DEFS   0x20
 
#define KSI_TLV_TMPL_FLG_NO_SERIALIZE   0x40
 
#define KSI_TLV_TMPL_FLG_MOST_ONE_G0   0x80
 
#define KSI_TLV_TMPL_FLG_MOST_ONE_G1   0x100
 
#define KSI_TLV_TMPL_FLG_FIXED_ORDER   0x200
 
#define KSI_TLV_TMPL_FLG_FIRST   0x400
 
#define KSI_TLV_TMPL_FLG_LAST   0x800
 
#define KSI_TLV_TMPL_FLG_NO_VALUE   0x1000
 
#define KSI_TLV_TMPL_FLG_MANTATORY_MOST_ONE_G0   (KSI_TLV_TMPL_FLG_LEAST_ONE_G0 | KSI_TLV_TMPL_FLG_MOST_ONE_G0)
 
#define KSI_TLV_TMPL_FLG_MANTATORY_MOST_ONE_G1   (KSI_TLV_TMPL_FLG_LEAST_ONE_G1 | KSI_TLV_TMPL_FLG_MOST_ONE_G1)
 
#define KSI_TLV_FULL_TEMPLATE_DEF(typ, tg, flg, gttr, sttr, constr, destr, subTmpl, list_append, mul, list_new, list_free, list_len, list_elAt, fromTlv, toTlv, descr, parser, p_opt, setRaw)
 
#define KSI_TLV_PRIMITIVE_TEMPLATE_DEF(typ, tg, flg, gttr, sttr, descr)   KSI_TLV_FULL_TEMPLATE_DEF(typ, tg, flg, gttr, sttr, NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, descr, NULL, 0, NULL)
 
#define KSI_DEFINE_TLV_TEMPLATE(name)   const KSI_TlvTemplate name##_template[] = {
 
#define KSI_TLV_OBJECT(tg, flg, gttr, sttr, fromTlv, toTlv, destr, descr)   KSI_TLV_FULL_TEMPLATE_DEF(KSI_TLV_TEMPLATE_OBJECT, tg, flg, gttr, sttr, NULL, destr, NULL, NULL, 0, NULL, NULL, NULL, NULL, fromTlv, toTlv, descr, NULL, 0, NULL)
 
#define KSI_TLV_WRAP_OBJECT(tg, flg, gttr, sttr, parser, toTlv, destr, descr)   KSI_TLV_FULL_TEMPLATE_DEF(KSI_TLV_TEMPLATE_OBJECT, tg, flg, gttr, sttr, NULL, destr, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, toTlv, descr, (parser), 0, NULL)
 
#define KSI_TLV_COMPOSITE_OBJECT(tg, flg, gttr, sttr, fromTlv, toTlv, destr, tmpl, descr)   KSI_TLV_FULL_TEMPLATE_DEF(KSI_TLV_TEMPLATE_OBJECT, tg, flg, gttr, sttr, NULL, destr, (tmpl), NULL, 0, NULL, NULL, NULL, NULL, fromTlv, toTlv, descr, NULL, 0, NULL)
 
#define KSI_TLV_UTF8_STRING(tg, flg, gttr, sttr, descr)   KSI_TLV_OBJECT(tg, flg, gttr, sttr, KSI_Utf8String_fromTlv, KSI_Utf8String_toTlv, KSI_Utf8String_free, descr)
 
#define KSI_TLV_INTEGER(tg, flg, gttr, sttr, descr)   KSI_TLV_OBJECT(tg, flg, gttr, sttr, KSI_Integer_fromTlv, KSI_Integer_toTlv, KSI_Integer_free, descr)
 
#define KSI_TLV_OCTET_STRING(tg, flg, gttr, sttr, descr)   KSI_TLV_OBJECT(tg, flg, gttr, sttr, KSI_OctetString_fromTlv, KSI_OctetString_toTlv, KSI_OctetString_free, descr)
 
#define KSI_TLV_IMPRINT(tg, flg, gttr, sttr, descr)   KSI_TLV_OBJECT(tg, flg, gttr, sttr, KSI_DataHash_fromTlv, KSI_DataHash_toTlv, KSI_DataHash_free, descr)
 
#define KSI_TLV_WRAP_IMPRINT(tg, flg, gttr, sttr, descr)   KSI_TLV_WRAP_OBJECT(tg, flg, gttr, sttr, KSI_DataHash_parse, KSI_DataHash_toTlv, KSI_DataHash_free, descr)
 
#define KSI_TLV_TIME_S   KSI_TLV_INTEGER
 
#define KSI_TLV_TIME_US   KSI_TLV_INTEGER
 
#define KSI_TLV_OBJECT_LIST(tg, flg, gttr, sttr, obj, descr)   KSI_TLV_FULL_TEMPLATE_DEF(KSI_TLV_TEMPLATE_OBJECT, tg, flg, gttr, sttr, NULL, obj##_free, NULL, KSI_List_append, 1, obj##List_new, obj##List_free, KSI_List_length, KSI_List_elementAt, obj##_fromTlv, obj##_toTlv, descr, NULL, 0, NULL)
 
#define KSI_TLV_OCTET_STRING_LIST(tg, flg, gttr, sttr, descr)   KSI_TLV_OBJECT_LIST(tg, flg, gttr, sttr, KSI_OctetString, descr)
 
#define KSI_TLV_UTF8_STRING_LIST(tg, flg, gttr, sttr, descr)   KSI_TLV_OBJECT_LIST(tg, flg, gttr, sttr, KSI_Utf8String, descr)
 
#define KSI_TLV_INTEGER_LIST(tg, flg, gttr, sttr, descr)   KSI_TLV_OBJECT_LIST(tg, flg, gttr, sttr, KSI_Integer, descr)
 
#define KSI_TLV_COMPOSITE(tg, flg, gttr, sttr, sub, descr)   KSI_TLV_FULL_TEMPLATE_DEF(KSI_TLV_TEMPLATE_COMPOSITE, tg, flg, gttr, sttr, sub##_new, sub##_free, sub##_template, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, descr, NULL, 0, NULL)
 
#define KSI_TLV_COMPOSITE_LIST(tg, flg, gttr, sttr, sub, descr)   KSI_TLV_FULL_TEMPLATE_DEF(KSI_TLV_TEMPLATE_COMPOSITE, tg, flg, gttr, sttr, sub##_new, sub##_free, sub##_template, KSI_List_append, 1, sub##List_new, sub##List_free, KSI_List_length, KSI_List_elementAt, NULL, NULL, descr, NULL, 0, NULL)
 
#define KSI_END_TLV_TEMPLATE   { -1, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL}};
 
#define KSI_IMPLEMENT_OBJECT_PARSE(type, tag)
 
#define KSI_IMPLEMENT_OBJECT_SERIALIZE(type, tag, nc, fwd)
 
#define KSI_IMPLEMENT_WRITE_BYTES(typ, tag, nc, fwd)
 

Typedefs

typedef int(* getter_t) (const void *, void **)
 
typedef int(* setter_t) (void *, void *)
 
typedef int(* cb_decode_t) (KSI_CTX *ctx, const KSI_TLV *, void *, const KSI_TlvTemplate *)
 
typedef int(* cb_encode_t) (KSI_CTX *, KSI_TLV *, const void *, const KSI_TlvTemplate *)
 
typedef int(* parse_t) (KSI_CTX *, unsigned char *, size_t, int, void *)
 

Functions

int KSI_TlvTemplate_extract (KSI_CTX *ctx, void *payload, KSI_TLV *tlv, const KSI_TlvTemplate *tmpl)
 
int KSI_TlvTemplate_parse (KSI_CTX *ctx, const unsigned char *raw, size_t raw_len, const KSI_TlvTemplate *tmpl, void *payload)
 
int KSI_TlvTemplate_extractGenerator (KSI_CTX *ctx, void *payload, void *generatorCtx, const KSI_TlvTemplate *tmpl, int(*generator)(void *, KSI_TLV **))
 
int KSI_TlvTemplate_construct (KSI_CTX *ctx, KSI_TLV *tlv, const void *payload, const KSI_TlvTemplate *tmpl)
 
int KSI_TlvTemplate_serializeObject (KSI_CTX *ctx, const void *obj, unsigned tag, int isNc, int isFwd, const KSI_TlvTemplate *tmpl, unsigned char **raw, size_t *raw_len)
 
int KSI_TlvTemplate_writeBytes (KSI_CTX *ctx, const void *obj, unsigned tag, int isNc, int isFwd, const KSI_TlvTemplate *tmpl, unsigned char *raw, size_t raw_size, size_t *raw_len, int opt)
 

Detailed Description

The TLV templates are used to convert plain c structs into KSI_TLV object trees and back.

Macro Definition Documentation

#define KSI_DEFINE_TLV_TEMPLATE (   name)    const KSI_TlvTemplate name##_template[] = {

This macro starts a KSI_TlvTemplate definition. The definition is ended with KSI_END_TLV_TEMPLATE .

Parameters
[in]nameTemplate name - recommended to use the object type name.
#define KSI_END_TLV_TEMPLATE   { -1, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL}};

This macro ends the KSI_TlvTemplate definition started by KSI_TLV_TEMPLATE.

#define KSI_IMPLEMENT_OBJECT_PARSE (   type,
  tag 
)
Value:
int type##_parse(KSI_CTX *ctx, const unsigned char *raw, size_t len, type **t) { \
int res = KSI_UNKNOWN_ERROR; \
KSI_TLV *tlv = NULL; \
type *tmp = NULL; \
if (ctx == NULL || t == NULL) { \
goto cleanup; \
} \
res = KSI_TLV_parseBlob2(ctx, (unsigned char *)raw, len, 0, &tlv); \
if (res != KSI_OK) goto cleanup; \
if (KSI_TLV_getTag(tlv) != (tag)) { \
goto cleanup; \
} \
res = type##_new(ctx, &tmp); \
if (res != KSI_OK) goto cleanup; \
res = KSI_TlvTemplate_parse(ctx, raw, len, KSI_TLV_TEMPLATE(type), tmp); \
if (res != KSI_OK) goto cleanup; \
*t = tmp; \
tmp = NULL; \
res = KSI_OK; \
cleanup: \
KSI_TLV_free(tlv); \
type##_free(tmp); \
return res; \
} \
int KSI_TlvTemplate_parse(KSI_CTX *ctx, const unsigned char *raw, size_t raw_len, const KSI_TlvTemplate *tmpl, void *payload)
Definition: ksi.h:49
int KSI_TLV_parseBlob2(KSI_CTX *ctx, unsigned char *data, size_t data_length, int ownMemory, KSI_TLV **tlv)
#define KSI_TLV_TEMPLATE(name)
Definition: tlv_template.h:170
unsigned KSI_TLV_getTag(const KSI_TLV *tlv)
Definition: ksi.h:337
struct KSI_CTX_st KSI_CTX
Definition: types_base.h:124
struct KSI_TLV_st KSI_TLV
Definition: types_base.h:129
void KSI_TLV_free(KSI_TLV *tlv)
Definition: ksi.h:82
Definition: ksi.h:77

Macro to generate object parsers.

Parameters
[in]typeType name.
[in]tagTag of the concrete TLV.
#define KSI_IMPLEMENT_OBJECT_SERIALIZE (   type,
  tag,
  nc,
  fwd 
)
Value:
int type##_serialize(const type *t, unsigned char **raw, size_t *len) { \
int res = KSI_UNKNOWN_ERROR; \
if (t == NULL || raw == NULL || len == NULL) { \
goto cleanup; \
} \
res = KSI_TlvTemplate_serializeObject(t->ctx, t, (tag), (nc), (fwd), KSI_TLV_TEMPLATE(type), raw, len); \
if (res != KSI_OK) goto cleanup; \
res = KSI_OK; \
cleanup: \
return res; \
} \
Definition: ksi.h:49
#define KSI_TLV_TEMPLATE(name)
Definition: tlv_template.h:170
Definition: ksi.h:337
int KSI_TlvTemplate_serializeObject(KSI_CTX *ctx, const void *obj, unsigned tag, int isNc, int isFwd, const KSI_TlvTemplate *tmpl, unsigned char **raw, size_t *raw_len)
Definition: ksi.h:77

Macro to generate object serializer.

Parameters
[in]typeType name.
[in]tagTag of the concrete TLV.
[in]ncNon-critical flag.
[in]fwdForward flag.
#define KSI_IMPLEMENT_WRITE_BYTES (   typ,
  tag,
  nc,
  fwd 
)
Value:
if (o == NULL) return KSI_INVALID_ARGUMENT; \
return KSI_TlvTemplate_writeBytes(o->ctx, (void *)o, tag, nc, fwd, KSI_TLV_TEMPLATE(typ), buf, buf_size, buf_len, opt); \
} \
int KSI_TlvTemplate_writeBytes(KSI_CTX *ctx, const void *obj, unsigned tag, int isNc, int isFwd, const KSI_TlvTemplate *tmpl, unsigned char *raw, size_t raw_size, size_t *raw_len, int opt)
#define KSI_TLV_TEMPLATE(name)
Definition: tlv_template.h:170
#define KSI_DEFINE_WRITE_BYTES(typ)
Definition: types_base.h:89
Definition: ksi.h:77
#define KSI_IMPORT_TLV_TEMPLATE (   name)    KSI_DEFINE_EXTERN(const KSI_TlvTemplate KSI_TLV_TEMPLATE(name)[])

This macro is used to import predefined templates.

#define KSI_TLV_COMPOSITE (   tg,
  flg,
  gttr,
  sttr,
  sub,
  descr 
)    KSI_TLV_FULL_TEMPLATE_DEF(KSI_TLV_TEMPLATE_COMPOSITE, tg, flg, gttr, sttr, sub##_new, sub##_free, sub##_template, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, descr, NULL, 0, NULL)

TLV template for composite objects.

Parameters
[in]tgTLV tag value.
[in]flgFlags for the template.
[in]gttrGetter function.
[in]sttrSetter function.
[in]subComposite element template.
[in]descrShort description.
#define KSI_TLV_COMPOSITE_LIST (   tg,
  flg,
  gttr,
  sttr,
  sub,
  descr 
)    KSI_TLV_FULL_TEMPLATE_DEF(KSI_TLV_TEMPLATE_COMPOSITE, tg, flg, gttr, sttr, sub##_new, sub##_free, sub##_template, KSI_List_append, 1, sub##List_new, sub##List_free, KSI_List_length, KSI_List_elementAt, NULL, NULL, descr, NULL, 0, NULL)

TLV template for list of composite objects.

Parameters
[in]tgTLV tag value.
[in]flgFlags for the template.
[in]gttrGetter function.
[in]sttrSetter function.
[in]subComposite element template.
[in]descrShort description.
#define KSI_TLV_COMPOSITE_OBJECT (   tg,
  flg,
  gttr,
  sttr,
  fromTlv,
  toTlv,
  destr,
  tmpl,
  descr 
)    KSI_TLV_FULL_TEMPLATE_DEF(KSI_TLV_TEMPLATE_OBJECT, tg, flg, gttr, sttr, NULL, destr, (tmpl), NULL, 0, NULL, NULL, NULL, NULL, fromTlv, toTlv, descr, NULL, 0, NULL)
#define KSI_TLV_FULL_TEMPLATE_DEF (   typ,
  tg,
  flg,
  gttr,
  sttr,
  constr,
  destr,
  subTmpl,
  list_append,
  mul,
  list_new,
  list_free,
  list_len,
  list_elAt,
  fromTlv,
  toTlv,
  descr,
  parser,
  p_opt,
  setRaw 
)
Value:
{ typ, tg, flg , (getter_t)gttr, (setter_t)sttr, (int (*)(KSI_CTX *, void **)) constr, (void (*)(void *)) destr, subTmpl, \
(int (*)(void *, void *))list_append, mul, (int (*)(void **)) list_new, (void (*)(void *)) list_free, (int (*)(const void *)) list_len, (int (*)(const void *, int, void **))list_elAt, \
(int (*)(KSI_TLV *, void **)) fromTlv, (int (*)(KSI_CTX *, void *, unsigned, int, int, KSI_TLV **))toTlv, (descr), (parse_t)(parser), (p_opt), (int (*)(void *, KSI_OctetString *))(setRaw)}, \
int(* parse_t)(KSI_CTX *, unsigned char *, size_t, int, void *)
Definition: tlv_template.h:65
struct KSI_OctetString_st KSI_OctetString
Definition: types_base.h:145
int(* getter_t)(const void *, void **)
Definition: tlv_template.h:48
struct KSI_CTX_st KSI_CTX
Definition: types_base.h:124
struct KSI_TLV_st KSI_TLV
Definition: types_base.h:129
int(* setter_t)(void *, void *)
Definition: tlv_template.h:53

A helper macro for defining a single template with all parameters.

Parameters
[in]typTemplate internal type.
[in]tgTLV tag value.
[in]flgFlags for the template.
[in]gttrGetter function.
[in]sttrSetter function.
[in]constrConstructor function.
[in]destrDestructor function.
[in]subTmplSub-template.
[in]list_appendList append function.
[in]mulAre multiple values allowed inside a single TLV?
[in]list_newList object constructor function.
[in]list_freeList object destructor function.
[in]list_lenList length function.
[in]list_elAtList elements random access function.
[in]fromTlvCreate object from TLV function.
[in]toTlvCreate TLV from object function.
[in]descrShort description.
[in]parserCreate object from raw data.
[in]p_optParser option.
[in]setRawNot used.
#define KSI_TLV_IMPRINT (   tg,
  flg,
  gttr,
  sttr,
  descr 
)    KSI_TLV_OBJECT(tg, flg, gttr, sttr, KSI_DataHash_fromTlv, KSI_DataHash_toTlv, KSI_DataHash_free, descr)

TLV template for KSI_DataHash type.

Parameters
[in]tgTLV tag value.
[in]flgFlags for the template.
[in]gttrGetter function.
[in]sttrSetter function.
[in]descrShort description.
#define KSI_TLV_INTEGER (   tg,
  flg,
  gttr,
  sttr,
  descr 
)    KSI_TLV_OBJECT(tg, flg, gttr, sttr, KSI_Integer_fromTlv, KSI_Integer_toTlv, KSI_Integer_free, descr)

TLV template for KSI_Integer type.

Parameters
[in]tgTLV tag value.
[in]flgFlags for the template.
[in]gttrGetter function.
[in]sttrSetter function.
[in]descrShort description.
#define KSI_TLV_INTEGER_LIST (   tg,
  flg,
  gttr,
  sttr,
  descr 
)    KSI_TLV_OBJECT_LIST(tg, flg, gttr, sttr, KSI_Integer, descr)

TLV template for list of KSI_Integer types.

Parameters
[in]tgTLV tag value.
[in]flgFlags for the template.
[in]gttrGetter function.
[in]sttrSetter function.
[in]descrShort description.
#define KSI_TLV_OBJECT (   tg,
  flg,
  gttr,
  sttr,
  fromTlv,
  toTlv,
  destr,
  descr 
)    KSI_TLV_FULL_TEMPLATE_DEF(KSI_TLV_TEMPLATE_OBJECT, tg, flg, gttr, sttr, NULL, destr, NULL, NULL, 0, NULL, NULL, NULL, NULL, fromTlv, toTlv, descr, NULL, 0, NULL)

Generic TLV template for objects for which fromTlv and toTlv functions are defined.

Parameters
[in]tgTLV tag value.
[in]flgFlags for the template.
[in]gttrGetter function.
[in]sttrSetter function.
[in]fromTlvFunction to create the object from TLV.
[in]toTlvFunction to create a TLV from the object.
[in]destrDestructor function pointer.
[in]descrShort description.
#define KSI_TLV_OBJECT_LIST (   tg,
  flg,
  gttr,
  sttr,
  obj,
  descr 
)    KSI_TLV_FULL_TEMPLATE_DEF(KSI_TLV_TEMPLATE_OBJECT, tg, flg, gttr, sttr, NULL, obj##_free, NULL, KSI_List_append, 1, obj##List_new, obj##List_free, KSI_List_length, KSI_List_elementAt, obj##_fromTlv, obj##_toTlv, descr, NULL, 0, NULL)

Generic object list template. The obj parameter may be only a type for which there is a list type defined (see KSI_DEFINE_LIST and KSI_IMPLEMENT_LIST).

Parameters
[in]tgTLV tag value.
[in]flgFlags for the template.
[in]gttrGetter function.
[in]sttrSetter function.
[in]objType of object stored in the list.
[in]descrShort description.
#define KSI_TLV_OCTET_STRING (   tg,
  flg,
  gttr,
  sttr,
  descr 
)    KSI_TLV_OBJECT(tg, flg, gttr, sttr, KSI_OctetString_fromTlv, KSI_OctetString_toTlv, KSI_OctetString_free, descr)

TLV template for KSI_OctetString type.

Parameters
[in]tgTLV tag value.
[in]flgFlags for the template.
[in]gttrGetter function.
[in]sttrSetter function.
[in]descrShort description.
#define KSI_TLV_OCTET_STRING_LIST (   tg,
  flg,
  gttr,
  sttr,
  descr 
)    KSI_TLV_OBJECT_LIST(tg, flg, gttr, sttr, KSI_OctetString, descr)

TLV template for list of KSI_OctetString types.

Parameters
[in]tgTLV tag value.
[in]flgFlags for the template.
[in]gttrGetter function.
[in]sttrSetter function.
[in]descrShort description.
#define KSI_TLV_PRIMITIVE_TEMPLATE_DEF (   typ,
  tg,
  flg,
  gttr,
  sttr,
  descr 
)    KSI_TLV_FULL_TEMPLATE_DEF(typ, tg, flg, gttr, sttr, NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, descr, NULL, 0, NULL)

A helper macro for defining primitive templates.

Parameters
[in]typTemplate internal type.
[in]tgTLV tag value.
[in]flgFlags for the template.
[in]gttrGetter function.
[in]sttrSetter function.
[in]descrShort description.
#define KSI_TLV_TEMPLATE (   name)    name##_template

Derive template actual object name.

Parameters
[in]nameTemplate name.
Returns
Actual template object name (i.e the name concatenated with postfix "_template").
#define KSI_TLV_TEMPLATE_COMPOSITE   2

Composite (a nested TLV) KSI_TlvTemplate type.

#define KSI_TLV_TEMPLATE_LIST   3

List KSI_TlvTemplate type.

#define KSI_TLV_TEMPLATE_OBJECT   1

Generic KSI_TlvTemplate type.

#define KSI_TLV_TIME_S   KSI_TLV_INTEGER

TLV templates for time representation

#define KSI_TLV_TIME_US   KSI_TLV_INTEGER
#define KSI_TLV_TMPL_FLG_FIRST   0x400

Element with this flag enabled, if present, must be the first element.

#define KSI_TLV_TMPL_FLG_FIXED_ORDER   0x200

All the sub elements with this flag enabled may be present in the TLV only in the same order as they appear in the template.

#define KSI_TLV_TMPL_FLG_FORWARD   0x01

Should the template be forwarded if it is unknown for the parser?

#define KSI_TLV_TMPL_FLG_LAST   0x800

Element with this flag enabled, if present, must be the last element.

#define KSI_TLV_TMPL_FLG_LEAST_ONE_G0   0x08

At least one TLV of the group 0 should be present.

#define KSI_TLV_TMPL_FLG_LEAST_ONE_G1   0x10

At least one TLV of the group 1 should be present.

#define KSI_TLV_TMPL_FLG_MANDATORY   0x04

Is this TLV object mandatory?.

#define KSI_TLV_TMPL_FLG_MANTATORY_MOST_ONE_G0   (KSI_TLV_TMPL_FLG_LEAST_ONE_G0 | KSI_TLV_TMPL_FLG_MOST_ONE_G0)

One and only one of the group 0 must be present.

#define KSI_TLV_TMPL_FLG_MANTATORY_MOST_ONE_G1   (KSI_TLV_TMPL_FLG_LEAST_ONE_G1 | KSI_TLV_TMPL_FLG_MOST_ONE_G1)

One and only one of the group 1 must be present.

#define KSI_TLV_TMPL_FLG_MORE_DEFS   0x20

This flags specifies that there can be more definitions for parsing the TLV. If this flag is not set, the remaining templates are not searched.

#define KSI_TLV_TMPL_FLG_MOST_ONE_G0   0x80

None or at most one TLV in the group 0 may be present.

#define KSI_TLV_TMPL_FLG_MOST_ONE_G1   0x100

None or at most one TLV in the group 1 may be present.

#define KSI_TLV_TMPL_FLG_NO_SERIALIZE   0x40

This flag prevents the serialization.

#define KSI_TLV_TMPL_FLG_NO_VALUE   0x1000

Element with this flag enabled does not have any payload.

#define KSI_TLV_TMPL_FLG_NONCRITICAL   0x02

Is the TLV non-critical i.e should it be an error if this TLV is unknown to the parser?

#define KSI_TLV_TMPL_FLG_NONE   0x00

Empty placeholder for a template with no flags set.

#define KSI_TLV_UTF8_STRING (   tg,
  flg,
  gttr,
  sttr,
  descr 
)    KSI_TLV_OBJECT(tg, flg, gttr, sttr, KSI_Utf8String_fromTlv, KSI_Utf8String_toTlv, KSI_Utf8String_free, descr)

TLV template for KSI_Utf8String type.

Parameters
[in]tgTLV tag value.
[in]flgFlags for the template.
[in]gttrGetter function.
[in]sttrSetter function.
[in]descrShort description.
#define KSI_TLV_UTF8_STRING_LIST (   tg,
  flg,
  gttr,
  sttr,
  descr 
)    KSI_TLV_OBJECT_LIST(tg, flg, gttr, sttr, KSI_Utf8String, descr)

TLV template for list of KSI_Utf8String types.

Parameters
[in]tgTLV tag value.
[in]flgFlags for the template.
[in]gttrGetter function.
[in]sttrSetter function.
[in]descrShort description.
#define KSI_TLV_WRAP_IMPRINT (   tg,
  flg,
  gttr,
  sttr,
  descr 
)    KSI_TLV_WRAP_OBJECT(tg, flg, gttr, sttr, KSI_DataHash_parse, KSI_DataHash_toTlv, KSI_DataHash_free, descr)
#define KSI_TLV_WRAP_OBJECT (   tg,
  flg,
  gttr,
  sttr,
  parser,
  toTlv,
  destr,
  descr 
)    KSI_TLV_FULL_TEMPLATE_DEF(KSI_TLV_TEMPLATE_OBJECT, tg, flg, gttr, sttr, NULL, destr, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, toTlv, descr, (parser), 0, NULL)

Typedef Documentation

typedef int(* cb_decode_t) (KSI_CTX *ctx, const KSI_TLV *, void *, const KSI_TlvTemplate *)

Generic decode function type.

typedef int(* cb_encode_t) (KSI_CTX *, KSI_TLV *, const void *, const KSI_TlvTemplate *)

Generic encode function type.

typedef int(* getter_t) (const void *, void **)

Generic value getter function type.

typedef int(* parse_t) (KSI_CTX *, unsigned char *, size_t, int, void *)
typedef int(* setter_t) (void *, void *)

Generic value setter function type.

Function Documentation

int KSI_TlvTemplate_construct ( KSI_CTX ctx,
KSI_TLV tlv,
const void *  payload,
const KSI_TlvTemplate tmpl 
)

Given a payload object, template and a initialized target TLV, this function constructs a TLV using the template and the values from the payload.

Parameters
[in]ctxKSI context.
[in]tlvAn empty target TLV.
[in]payloadEvaluated payload.
[in]tmplTemplate of the TLV expected structure.
Returns
status code (KSI_OK, when operation succeeded, otherwise an error code).
int KSI_TlvTemplate_extract ( KSI_CTX ctx,
void *  payload,
KSI_TLV tlv,
const KSI_TlvTemplate tmpl 
)

Given a TLV object, template and a initialized target payload, this function evaluates the payload objects with the data from the TLV.

Parameters
[in]ctxKSI context.
[in]payloadPreinitialized empty object to be evaluated with the TLV values.
[in]tlvTLV value which has the structure represented in template.
[in]tmplTemplate of the TLV expected structure.
Returns
status code (KSI_OK, when operation succeeded, otherwise an error code).
int KSI_TlvTemplate_extractGenerator ( KSI_CTX ctx,
void *  payload,
void *  generatorCtx,
const KSI_TlvTemplate tmpl,
int(*)(void *, KSI_TLV **)  generator 
)

This function acts similarly as KSI_TlvTemplate_extract but allows the caller to specify how the top level TLV's are retrieved (e.g. read from a file).

Parameters
[in]ctxKSI context.
[in]payloadPreinitialized empty object to be evaluated with the TLV values.
[in]generatorCtxContext for the generator.
[in]tmplTemplate of the TLV expected structure.
[in]generatorGenerator function. The generatorCtx is passed as the first parameter and a KSI_TLV object is expected to be returned by the second parameter - a NULL value is interpreted as end of input. The function is expected to return KSI_OK on success.
Returns
status code (KSI_OK, when operation succeeded, otherwise an error code).
int KSI_TlvTemplate_parse ( KSI_CTX ctx,
const unsigned char *  raw,
size_t  raw_len,
const KSI_TlvTemplate tmpl,
void *  payload 
)

Parses a given raw data into a pre-existing element. The caller needs to know the outcome type and create it.

Parameters
[in]ctxKSI context.
[in]rawPointer to the raw data.
[in]raw_lenLength of the raw data.
[in]tmplTemplate.
[in]payloadPointer to the payload which will be populated with the parsed data.
Returns
status code (KSI_OK, when operation succeeded, otherwise an error code).
int KSI_TlvTemplate_serializeObject ( KSI_CTX ctx,
const void *  obj,
unsigned  tag,
int  isNc,
int  isFwd,
const KSI_TlvTemplate tmpl,
unsigned char **  raw,
size_t *  raw_len 
)

Serializes an object using KSI_TlvTemplate.

Parameters
[in]ctxKSI context.
[in]objObject to be serialized.
[in]tagTag of the serialized object.
[in]isNcTLV flag is-non-critical.
[in]isFwdTLV flag is-forward.
[in]tmplTemplate to be used.
[out]rawPointer to the receiving pointer to the serialized value.
[out]raw_lenLength of the serialized value.
Returns
status code (KSI_OK, when operation succeeded, otherwise an error code).
Note
Thre returned pointer raw belongs to the caller and it needs to be freed using KSI_free
See also
KSI_free
int KSI_TlvTemplate_writeBytes ( KSI_CTX ctx,
const void *  obj,
unsigned  tag,
int  isNc,
int  isFwd,
const KSI_TlvTemplate tmpl,
unsigned char *  raw,
size_t  raw_size,
size_t *  raw_len,
int  opt 
)

This function serializes the given object based on the template.

Parameters
[in]ctxKSI context.
[in]objObject to be serialized.
[in]tagTag of the outer TLV.
[in]isNcFlag of the outer TLV: is non-critical
[in]isFwdFlag of the outer TLV: is forward
[in]tmplTemplate
[in]rawPointer to target buffer
[in]raw_sizeSize of the target buffer
[out]raw_lenLength of the serialization.
[in]optOptions.
Returns
status code (KSI_OK, when operation succeeded, otherwise an error code).