Guardtime KSI c SDK
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Data Structures | Macros | Typedefs | Functions
tlv_element.h File Reference
#include "ksi.h"
#include "fast_tlv.h"
#include "list.h"

Go to the source code of this file.

Data Structures

struct  KSI_TlvElement_list_st
 
struct  KSI_TlvElement_st
 

Macros

#define KSI_TlvElementList_append(lst, o)   KSI_APPLY_TO_NOT_NULL((lst), append, ((lst), (o)))
 
#define KSI_TlvElementList_remove(lst, pos, o)   KSI_APPLY_TO_NOT_NULL((lst), removeElement, ((lst), (pos), (o)))
 
#define KSI_TlvElementList_indexOf(lst, o, i)   KSI_APPLY_TO_NOT_NULL((lst), indexOf, ((lst), (o), (i)))
 
#define KSI_TlvElementList_insertAt(lst, pos, o)   KSI_APPLY_TO_NOT_NULL((lst), insertAt, ((lst), (pos), (o)))
 
#define KSI_TlvElementList_replaceAt(lst, pos, o)   KSI_APPLY_TO_NOT_NULL((lst), replaceAt, ((lst), (pos), (o)))
 
#define KSI_TlvElementList_elementAt(lst, pos, o)   KSI_APPLY_TO_NOT_NULL((lst), elementAt, ((lst), (pos), (o)))
 
#define KSI_TlvElementList_length(lst)   (((lst) != NULL && (lst)->length != NULL) ? (lst)->length((lst)) : 0)
 
#define KSI_TlvElementList_sort(lst, cmp)   KSI_APPLY_TO_NOT_NULL((lst), sort, ((lst), (cmp)))
 
#define KSI_TlvElementList_foldl(lst, foldCtx, foldFn)   (((lst) != NULL) ? (((lst)->foldl != NULL) ? ((lst)->foldl((lst), (foldCtx), (foldFn))) : KSI_INVALID_STATE) : KSI_OK)
 
#define KSI_TlvElementList_find(lst, o, f, i)   KSI_APPLY_TO_NOT_NULL((lst), find, ((lst), (o), (f), (i)))
 

Typedefs

typedef struct KSI_TlvElement_st KSI_TlvElement
 
typedef struct
KSI_TlvElement_list_st 
KSI_TlvElementList
 

Functions

int KSI_TlvElementList_new (KSI_TlvElementList **list)
 
void KSI_TlvElementList_free (KSI_TlvElementList *list)
 
KSI_TlvElementKSI_TlvElement_ref (KSI_TlvElement *o)
 
int KSI_TlvElement_new (KSI_TlvElement **out)
 
int KSI_TlvElement_parse (unsigned char *dat, size_t dat_len, KSI_TlvElement **out)
 
int KSI_TlvElement_detach (KSI_TlvElement *el)
 
void KSI_TlvElement_free (KSI_TlvElement *t)
 
int KSI_TlvElement_serialize (const KSI_TlvElement *element, unsigned char *buf, size_t buf_size, size_t *len, int opt)
 
int KSI_TlvElement_appendElement (KSI_TlvElement *parent, KSI_TlvElement *child)
 
int KSI_TlvElement_setElement (KSI_TlvElement *parent, KSI_TlvElement *child)
 
int KSI_TlvElement_getElement (KSI_TlvElement *parent, unsigned tag, KSI_TlvElement **el)
 
int KSI_TlvElement_removeElement (KSI_TlvElement *parent, unsigned tag, KSI_TlvElement **el)
 
int KSI_TlvElement_getUtf8String (KSI_TlvElement *parent, KSI_CTX *ctx, unsigned tag, KSI_Utf8String **out)
 
int KSI_TlvElement_getOctetString (KSI_TlvElement *parent, KSI_CTX *ctx, unsigned tag, KSI_OctetString **out)
 
int KSI_TlvElement_getInteger (KSI_TlvElement *parent, KSI_CTX *ctx, unsigned tag, KSI_Integer **out)
 
int KSI_TlvElement_setUtf8String (KSI_TlvElement *parent, unsigned tag, KSI_Utf8String *value)
 
int KSI_TlvElement_setOctetString (KSI_TlvElement *parent, unsigned tag, KSI_OctetString *value)
 
int KSI_TlvElement_setInteger (KSI_TlvElement *parent, unsigned tag, KSI_Integer *value)
 

Macro Definition Documentation

#define KSI_TlvElementList_append (   lst,
 
)    KSI_APPLY_TO_NOT_NULL((lst), append, ((lst), (o)))
#define KSI_TlvElementList_elementAt (   lst,
  pos,
 
)    KSI_APPLY_TO_NOT_NULL((lst), elementAt, ((lst), (pos), (o)))
#define KSI_TlvElementList_find (   lst,
  o,
  f,
 
)    KSI_APPLY_TO_NOT_NULL((lst), find, ((lst), (o), (f), (i)))
#define KSI_TlvElementList_foldl (   lst,
  foldCtx,
  foldFn 
)    (((lst) != NULL) ? (((lst)->foldl != NULL) ? ((lst)->foldl((lst), (foldCtx), (foldFn))) : KSI_INVALID_STATE) : KSI_OK)
#define KSI_TlvElementList_indexOf (   lst,
  o,
 
)    KSI_APPLY_TO_NOT_NULL((lst), indexOf, ((lst), (o), (i)))
#define KSI_TlvElementList_insertAt (   lst,
  pos,
 
)    KSI_APPLY_TO_NOT_NULL((lst), insertAt, ((lst), (pos), (o)))
#define KSI_TlvElementList_length (   lst)    (((lst) != NULL && (lst)->length != NULL) ? (lst)->length((lst)) : 0)
#define KSI_TlvElementList_remove (   lst,
  pos,
 
)    KSI_APPLY_TO_NOT_NULL((lst), removeElement, ((lst), (pos), (o)))
#define KSI_TlvElementList_replaceAt (   lst,
  pos,
 
)    KSI_APPLY_TO_NOT_NULL((lst), replaceAt, ((lst), (pos), (o)))
#define KSI_TlvElementList_sort (   lst,
  cmp 
)    KSI_APPLY_TO_NOT_NULL((lst), sort, ((lst), (cmp)))

Typedef Documentation

Function Documentation

int KSI_TlvElement_appendElement ( KSI_TlvElement parent,
KSI_TlvElement child 
)

Append an element as the last child. The caller is responsible of freeing the sub element.

Parameters
[in]parentThe parent element.
[in]childThe child element.
Returns
status code (KSI_OK, when operation succeeded, otherwise an error code).
int KSI_TlvElement_detach ( KSI_TlvElement el)

This function detaches the element from outer resources. This is useful after KSI_TlvElement_parse function call if the underlying pointer needs to be reused or if the element has been altered (new sub-elements added or removed).

Parameters
[in]elThe KSI_TlvElement.
Returns
status code (KSI_OK, when operation succeeded, otherwise an error code).
void KSI_TlvElement_free ( KSI_TlvElement t)

Cleanup method for the KSI_TlvElement.

Parameters
[in]tPointer to the KSI_TlvElement.
int KSI_TlvElement_getElement ( KSI_TlvElement parent,
unsigned  tag,
KSI_TlvElement **  el 
)

Find and extract a sub element. The output variable will be NULL if the element does not exist. If there are more than one elements with the given tag, the process will fail with an error.

Parameters
[in]parentParent element.
[in]tagTag value of the element being extracted.
[out]elPointer to the receiving pointer.
Returns
status code (KSI_OK, when operation succeeded, otherwise an error code).
Note
It is the responsibility of the caller to free the output element.
int KSI_TlvElement_getInteger ( KSI_TlvElement parent,
KSI_CTX ctx,
unsigned  tag,
KSI_Integer **  out 
)

Access method for a nested KSI_Integer value by the given tag. If there is no value with the specified tag, the output is evaluated to NULL.

Parameters
[in]parentPointer to the parent element.
[in]ctxKSI context.
[in]tagTag of the requested element.
[out]outPointer to the receiving pointer.
Note
The output object must be free by the caller.
Returns
status code (KSI_OK, when operation succeeded, otherwise an error code).
int KSI_TlvElement_getOctetString ( KSI_TlvElement parent,
KSI_CTX ctx,
unsigned  tag,
KSI_OctetString **  out 
)

Access method for a nested KSI_OctetString value by the given tag. If there is no value with the specified tag, the output is evaluated to NULL.

Parameters
[in]parentPointer to the parent element.
[in]ctxKSI context.
[in]tagTag of the requested element.
[out]outPointer to the receiving pointer.
Note
The output object must be free by the caller.
Returns
status code (KSI_OK, when operation succeeded, otherwise an error code).
int KSI_TlvElement_getUtf8String ( KSI_TlvElement parent,
KSI_CTX ctx,
unsigned  tag,
KSI_Utf8String **  out 
)

Access method for a nested KSI_Utf8String value by the given tag. If there is no value with the specified tag, the output is evaluated to NULL.

Parameters
[in]parentPointer to the parent element.
[in]ctxKSI context.
[in]tagTag of the requested element.
[out]outPointer to the receiving pointer.
Note
The output object must be free by the caller.
Returns
status code (KSI_OK, when operation succeeded, otherwise an error code).
int KSI_TlvElement_new ( KSI_TlvElement **  out)

Creates a new KSI_TlvElement.

Parameters
[out]outPointer to the receiving pointer.
Returns
status code (KSI_OK, when operation succeeded, otherwise an error code).
int KSI_TlvElement_parse ( unsigned char *  dat,
size_t  dat_len,
KSI_TlvElement **  out 
)

Parses the input as a KSI_TlvElement object. The parsing process does not consume the input data pointer thus the data pointer may not be freed or modified. To detatch the data pointer from the object use KSI_TlvElement_detach.

Parameters
[in]datPointer to the serialized TLV.
[in]dat_lenLength of the serialized TLV.
[out]outPointer to the receiving pointer.
Returns
status code (KSI_OK, when operation succeeded, otherwise an error code).
See also
KSI_TlvElement_free, KSI_TlvElement_detach.
KSI_TlvElement* KSI_TlvElement_ref ( KSI_TlvElement o)
  • Increases the inner reference count of that object. *
    Parameters
    [in]oPointer to KSI_TlvElement *
    Returns
    Returns the input pointer on success or NULL on error. *
    See also
    KSI_TlvElement_free
int KSI_TlvElement_removeElement ( KSI_TlvElement parent,
unsigned  tag,
KSI_TlvElement **  el 
)

Removes a child element with the specified TLV tag. The process will fail if there is more than one element or no elements with the same tag. If output variable el is not NULL, the caller is responsible of freeing the removed element.

Parameters
[in]parentThe parent element.
[in]tagTag value of the element being removed.
[out]elPointer to the receiving pointer.
Returns
status code (KSI_OK, when operation succeeded, otherwise an error code).
int KSI_TlvElement_serialize ( const KSI_TlvElement element,
unsigned char *  buf,
size_t  buf_size,
size_t *  len,
int  opt 
)

This function serializes the KSI_TlvElement. The buffer buf may be NULL, but only if the buffer size buf_size is equal to 0 - this can be used to calculate the length of the serialized value and after that allocate the buffer.

Parameters
[in]elementPointer to the KSI_TlvElement.
[in]bufPointer to the buffer where to serialize the element.
[in]buf_sizeSize of the buffer.
[out]lenLength of the serialized data (may be NULL).
[in]optOptions for serialization. (see KSI_Serialize_Opt_en).
Returns
status code (KSI_OK, when operation succeeded, otherwise an error code).
int KSI_TlvElement_setElement ( KSI_TlvElement parent,
KSI_TlvElement child 
)

Inserts or replaces an element with the concrete TLV tag. There process will fail if there are already more than one elements with the same tag. The caller is responsible of freeing the sub element.

Parameters
[in]parentThe parent element.
[in]childThe child element.
Returns
status code (KSI_OK, when operation succeeded, otherwise an error code).
int KSI_TlvElement_setInteger ( KSI_TlvElement parent,
unsigned  tag,
KSI_Integer value 
)

A setter method for a nested KSI_Integer value. If the element already exists as a sub-element of parent, the sub-element is replaced with the new value.

Parameters
[in]parentPointer to the parent element.
[in]tagTag of the requested element.
[out]valuePointer to the receiving pointer.
Note
The input value object must be free by the caller.
Returns
status code (KSI_OK, when operation succeeded, otherwise an error code).
int KSI_TlvElement_setOctetString ( KSI_TlvElement parent,
unsigned  tag,
KSI_OctetString value 
)

A setter method for a nested KSI_OctetString value. If the element already exists as a sub-element of parent, the sub-element is replaced with the new value.

Parameters
[in]parentPointer to the parent element.
[in]tagTag of the requested element.
[out]valuePointer to the receiving pointer.
Note
The input value object must be free by the caller.
Returns
status code (KSI_OK, when operation succeeded, otherwise an error code).
int KSI_TlvElement_setUtf8String ( KSI_TlvElement parent,
unsigned  tag,
KSI_Utf8String value 
)

A setter method for a nested KSI_Utf8String value. If the element already exists as a sub-element of parent, the sub-element is replaced with the new value.

Parameters
[in]parentPointer to the parent element.
[in]tagTag of the requested element.
[out]valuePointer to the receiving pointer.
Note
The input value object must be free by the caller.
Returns
status code (KSI_OK, when operation succeeded, otherwise an error code).
void KSI_TlvElementList_free ( KSI_TlvElementList list)
int KSI_TlvElementList_new ( KSI_TlvElementList **  list)