-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepr.h
62 lines (53 loc) · 1.74 KB
/
repr.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* Copyright (C) 2010 Valery V. Vorotyntsev <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#ifndef _REPR_H
#define _REPR_H
#include "list.h"
#include "asn1.h"
struct Buffer;
/*
* Format specification.
*
* This structure "knows" how to convert tag data to human-friendly
* representations and vice versa.
*/
struct Repr_Format {
struct hlist_head *dict; /* Dictionary of tags' representations */
struct hlist_head libs; /* Plugins in use */
};
#define REPR_FORMAT(name) struct Repr_Format name = { NULL, HLIST_HEAD_INIT }
/* Read configuration file and fill `dest' */
int repr_create(struct Repr_Format *dest, const char *conf_path);
/* Free resources allocated for `fmt' */
void repr_destroy(struct Repr_Format *fmt);
/* Print tag header's representation to stdout */
void repr_show_header(const struct Repr_Format *fmt, enum Tag_Class cls,
uint32_t num);
/*
* Repr_Codec -- type of function that converts raw bytes to
* human-friendly representation or vice versa.
*
* @dest: destination buffer
* @src: start of raw data
* @n: number of bytes
*
* Return value: 0 - success, -1 - conversion failed or insufficient
* `dest' capacity.
*
* Codecs should write error message to `dest' in case of error.
*/
typedef int (*Repr_Codec)(struct Buffer *dest, const uint8_t *src, size_t n);
/*
* Return tag value decoder, i.e., a pointer to the function that
* converts raw encoding (primitive) to human-friendly representation.
*
* Returned value can be NULL.
*/
Repr_Codec repr_from_raw(const struct Repr_Format *fmt, enum Tag_Class cls,
uint32_t num);
#endif /* _REPR_H */