summaryrefslogtreecommitdiffstats
path: root/collection/elapi_util.h
blob: 3c2a650355329093fdd710bc28a6eaf2443091c2 (plain)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
    ELAPI

    Header files with serialization methods of the collection.

    Copyright (C) Dmitri Pal <dpal@redhat.com> 2009

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/


#ifndef ELAPI_UTIL_H
#define ELAPI_UTIL_H

#include <libxml/xmlwriter.h>
#include "elapi_collection.h"

#define DEFAULT_ENCODING "ISO-8859-1"

#define TEXT_COLLECTION "EVENT"
#define TEXT_COLLEN 5

#define ELEMENT_COLLECTION "MAP"
#define ELEMENT_MEMBER "MEMBER"
#define ATTRIBUTE_NAME "name"
#define ATTRIBUTE_TYPE "type"
#define COLLEN  3 
#define BLOCK_SIZE 1024

#define ELAPI_TYPE_NAME_STRING     "string"
#define ELAPI_TYPE_NAME_BINARY     "bin"
#define ELAPI_TYPE_NAME_INTEGER    "int"
#define ELAPI_TYPE_NAME_UNSIGNED   "uint"
#define ELAPI_TYPE_NAME_LONG       "long"
#define ELAPI_TYPE_NAME_ULONG      "ulong"
#define ELAPI_TYPE_NAME_DOUBLE     "double"
#define ELAPI_TYPE_NAME_UNKNOWN    "unknown"

#define BAD_DATA "NOT UTF-8"


struct serial_data {
    char *buffer;
    int size;
    int length;
    int nest_level;
};


struct xml_data {
    xmlTextWriterPtr writer;
    xmlBufferPtr buf;
    char *given_name;
    int level; 
};


/* Calculate the potential size of the item */ 
int get_data_len(int type, int length);

/* Grow buffer to accomodate more space */
int grow_buffer(struct serial_data *buf_data, int len);

/* Specail function to add different formatting symbols to the output */
int put_marker(struct serial_data *buf_data, void *data, int len);

/* Serialization of data user handler */
int serialize(char *property_in,
              int property_len_in,
              int type,
              void *data_in,
              int length_in,
              void *custom_data,
              int *dummy);

/* Add item's data */
int xml_add(char *property,
            int property_len,
            int type,
            void *data,
            int length,
            void *custom_data,
            int *dummy);

/* Serialize using format */
int serialize_with_format(struct collection_item *event,
                          char *format_str,
                          struct serial_data *data);

#endif