kvaMemoLibXML.h
Go to the documentation of this file.
1 /*
2 * Copyright 2017 by Kvaser AB, Molndal, Sweden
3 * http://www.kvaser.com
4 *
5 * This software is dual licensed under the following two licenses:
6 * BSD-new and GPLv2. You may use either one. See the included
7 * COPYING file for details.
8 *
9 * License: BSD-new
10 * ==============================================================================
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
13 * * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * * Neither the name of the <organization> nor the
19 * names of its contributors may be used to endorse or promote products
20 * derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
29 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
30 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *
34 *
35 * License: GPLv2
36 * ==============================================================================
37 * This program is free software; you can redistribute it and/or modify
38 * it under the terms of the GNU General Public License as published by
39 * the Free Software Foundation; either version 2 of the License, or
40 * (at your option) any later version.
41 *
42 * This program is distributed in the hope that it will be useful,
43 * but WITHOUT ANY WARRANTY; without even the implied warranty of
44 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45 * GNU General Public License for more details.
46 *
47 * You should have received a copy of the GNU General Public License
48 * along with this program; if not, write to the Free Software
49 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
50 *
51 *
52 * IMPORTANT NOTICE:
53 * ==============================================================================
54 * This source code is made available for free, as an open license, by Kvaser AB,
55 * for use with its applications. Kvaser AB does not accept any liability
56 * whatsoever for any third party patent or other immaterial property rights
57 * violations that may result from any usage of this source code, regardless of
58 * the combination of source code and various applications that it can be used
59 * in, or with.
60 *
61 * -----------------------------------------------------------------------------
62 */
63
64 #ifndef KVAMEMOLIBXML_H
65 #define KVAMEMOLIBXML_H
66
93 #include <stdlib.h>
94 #define WINAPI
95
96 #ifdef __cplusplus
97 extern "C" {
98 #endif
99
109 #define XML_ERROR_MESSAGE_LENGTH 2048
110
122 typedef enum {
123 KvaXmlStatusOK = 0,
124 KvaXmlStatusFail = -1,
125 KvaXmlStatusERR_ATTR_NOT_FOUND = -3,
126 KvaXmlStatusERR_ATTR_VALUE = -4,
127 KvaXmlStatusERR_ELEM_NOT_FOUND = -5,
128 KvaXmlStatusERR_VALUE_RANGE = -6,
129 KvaXmlStatusERR_VALUE_UNIQUE = -7,
130 KvaXmlStatusERR_VALUE_CONSECUTIVE = -8,
131 KvaXmlStatusERR_EXPRESSION = -9,
132 KvaXmlStatusERR_XML_PARSER = -10,
133 KvaXmlStatusERR_DTD_VALIDATION = -11,
134 KvaXmlStatusERR_SCRIPT_ERROR = -12,
135 KvaXmlStatusERR_INTERNAL = -20,
136 } KvaXmlStatus;
149 typedef enum {
150 KvaXmlValidationStatusOK = 0,
151 KvaXmlValidationStatusFail = -1,
152 KvaXmlValidationStatusERR_ABORT = -2,
153 KvaXmlValidationStatusERR_SILENT_TRANSMIT = -3,
154 KvaXmlValidationStatusERR_UNDEFINED_TRIGGER = -4,
155 KvaXmlValidationStatusERR_MULTIPLE_EXT_TRIGGER = -5,
156 KvaXmlValidationStatusERR_MULTIPLE_START_TRIGGER = -6,
157 KvaXmlValidationStatusERR_DISK_FULL_STARTS_LOG = -7,
158 KvaXmlValidationStatusERR_NUM_OUT_OF_RANGE = -8,
159 KvaXmlValidationStatusERR_SCRIPT_NOT_FOUND = -9,
160 KvaXmlValidationStatusERR_SCRIPT_TOO_LARGE = -10,
161 KvaXmlValidationStatusERR_SCRIPT_TOO_MANY = -11,
162 KvaXmlValidationStatusERR_SCRIPT_CONFLICT = -12,
163 KvaXmlValidationStatusERR_ELEMENT_COUNT = -13,
164 KvaXmlValidationStatusERR_PARSER = -14,
165 KvaXmlValidationStatusERR_SCRIPT = -15,
166 KvaXmlValidationStatusERR_EXPRESSION = -16,
167
168 KvaXmlValidationStatusWARN_ABORT = -100,
169 KvaXmlValidationStatusWARN_NO_ACTIVE_LOG = -101,
170 KvaXmlValidationStatusWARN_DISK_FULL_AND_FIFO = -102,
171 KvaXmlValidationStatusWARN_IGNORED_ELEMENT = -103,
172 KvaXmlValidationStatusWARN_MULTIPLE_EXT_TRIGGER = -104,
173 } KvaXmlValidationStatus;
188 KvaXmlStatus WINAPI kvaXmlInitialize (void);
189
204 KvaXmlStatus WINAPI kvaXmlGetLastError (char *buf, unsigned int len, KvaXmlStatus *err);
205
224 KvaXmlStatus WINAPI kvaXmlToBuffer (const char *xmlbuf, unsigned int xmllen, char *outbuf, unsigned int *outlen, long *version);
225
238 KvaXmlStatus WINAPI kvaXmlToFile (const char *infile, const char *outfile);
239
252 KvaXmlStatus WINAPI kvaFileToXml(const char * parfile, const char * xmlfile);
253
266 KvaXmlStatus WINAPI kvaXmlDebugOutput (int on);
267
286 KvaXmlStatus WINAPI kvaBufferToXml (const char *inbuf, unsigned int inlen, char *xmlbuf, unsigned int *xmllen, long *version, const char * scriptpath);
287
299 KvaXmlStatus WINAPI kvaXmlValidate (const char *xmlbuf, unsigned int xmllen);
300
312 KvaXmlStatus WINAPI kvaXmlGetValidationStatusCount (int *countErr, int *countWarn);
313
327 KvaXmlStatus WINAPI kvaXmlGetValidationError (KvaXmlValidationStatus *status, char *buf, unsigned int len);
328
342 KvaXmlStatus WINAPI kvaXmlGetValidationWarning (KvaXmlValidationStatus *status, char *buf, unsigned int len);
343
356 KvaXmlStatus WINAPI kvaXmlGetErrorText (KvaXmlStatus status, char *buf, unsigned int len);
357
371 KvaXmlStatus WINAPI kvaXmlGetValidationText (KvaXmlValidationStatus status, char *buf, unsigned int len);
372
385 unsigned short WINAPI kvaXmlGetVersion (void);
386
387
388 // Functions and definitions provided by kv_parser, used for going back and
389 // forth between infix and postfix notation.
390
397 typedef struct tag_token {
398 int type; // T_xxx
399 char *name; // Name for identifiers
400 struct tag_token *left; // Left part of expr if this is an op
401 struct tag_token *right; // Right dito
402 int start_pos; // Token's start pos
403 int end_pos; // Token's end pos
404 struct tag_token *next; // For later memory deallocation
405 int errCode; // ERR_xxx if this is a T_ERROR
406 } Token;
407
413 typedef struct {
414 Token *next;
415 } KvParseHandle;
416
427 KvParseHandle* WINAPI kvaToolsParseCreate(void);
428
436 void WINAPI kvaToolsParseDestroy(KvParseHandle *h);
437
448 void WINAPI kvaToolsExprGetErrorString(int errCode, char *s, size_t bufsiz);
449
462 int WINAPI kvaToolsParseExpr(KvParseHandle *h, char* expr, Token **t);
463
474 int WINAPI kvaToolsFreeExpr(KvParseHandle *h, Token *t);
475
487 int WINAPI kvaToolsDumpExpr(KvParseHandle *h, Token *t);
488
501 int WINAPI kvaToolsExprHasErrors(KvParseHandle *h, Token *t);
502
516 int WINAPI kvaToolsExprGetError(KvParseHandle *h, Token *t, int *errCode, int *pos);
517
547 #ifdef __cplusplus
548 }
549 #endif
550
551 #endif //KVAMEMOLIBXML_H
kvaToolsExprHasErrors
int kvaToolsExprHasErrors(KvParseHandle *h, Token *t)
KvaXmlValidationStatusERR_MULTIPLE_START_TRIGGER
There are more than one start up trigger defined.
Definition: kvaMemoLibXML.h:156
tag_token::next
struct tag_token * next
Definition: kvaMemoLibXML.h:404
KvaXmlValidationStatus
KvaXmlValidationStatus
Definition: kvaMemoLibXML.h:149
KvaXmlValidationStatusERR_ABORT
Too many errors, validation aborted.
Definition: kvaMemoLibXML.h:152
KvaXmlValidationStatusERR_SCRIPT_CONFLICT
More than one active script is set as &#39;primary&#39;.
Definition: kvaMemoLibXML.h:162
KvaXmlValidationStatusERR_MULTIPLE_EXT_TRIGGER
There are more than one external trigger defined.
Definition: kvaMemoLibXML.h:155
KvaXmlValidationStatusWARN_ABORT
Too many warnings, validation aborted.
Definition: kvaMemoLibXML.h:168
kvaXmlGetValidationWarning
KvaXmlStatus kvaXmlGetValidationWarning(KvaXmlValidationStatus *status, char *buf, unsigned int len)
KvaXmlValidationStatusWARN_MULTIPLE_EXT_TRIGGER
Using more than one external trigger requires firmware version 3.7 or better.
Definition: kvaMemoLibXML.h:172
KvaXmlStatusERR_ELEM_NOT_FOUND
Could not find a required element.
Definition: kvaMemoLibXML.h:127
tag_token::type
int type
Definition: kvaMemoLibXML.h:398
KvaXmlValidationStatusFail
Generic error.
Definition: kvaMemoLibXML.h:151
KvaXmlValidationStatusERR_EXPRESSION
A general trigger expression found during parsing.
Definition: kvaMemoLibXML.h:166
kvaXmlGetErrorText
KvaXmlStatus kvaXmlGetErrorText(KvaXmlStatus status, char *buf, unsigned int len)
KvaXmlValidationStatusWARN_NO_ACTIVE_LOG
No active logging detected.
Definition: kvaMemoLibXML.h:169
kvaXmlToFile
KvaXmlStatus kvaXmlToFile(const char *infile, const char *outfile)
KvaXmlStatusERR_VALUE_RANGE
The value is outside the allowed range.
Definition: kvaMemoLibXML.h:128
Token
struct tag_token Token
Token used when parsing postfix expressions (deprecated):
KvaXmlStatusFail
Generic error.
Definition: kvaMemoLibXML.h:124
WINAPI
#define WINAPI
Definition: kvaMemoLibXML.h:94
KvaXmlValidationStatusERR_SILENT_TRANSMIT
Transmit lists used in silent mode.
Definition: kvaMemoLibXML.h:153
KvParseHandle::next
Token * next
Definition: kvaMemoLibXML.h:414
kvaToolsFreeExpr
int kvaToolsFreeExpr(KvParseHandle *h, Token *t)
tag_token::start_pos
int start_pos
Definition: kvaMemoLibXML.h:402
KvaXmlValidationStatusERR_SCRIPT
A general t-script error found during parsing.
Definition: kvaMemoLibXML.h:165
KvaXmlValidationStatusWARN_IGNORED_ELEMENT
This XML element was ignored.
Definition: kvaMemoLibXML.h:171
KvaXmlStatusERR_ATTR_NOT_FOUND
Failed to find an attribute in a node.
Definition: kvaMemoLibXML.h:125
tag_token::end_pos
int end_pos
Definition: kvaMemoLibXML.h:403
kvaXmlDebugOutput
KvaXmlStatus kvaXmlDebugOutput(int on)
tag_token::errCode
int errCode
Definition: kvaMemoLibXML.h:405
KvaXmlValidationStatusERR_DISK_FULL_STARTS_LOG
A trigger on disk full starts the logging.
Definition: kvaMemoLibXML.h:157
KvaXmlValidationStatusERR_SCRIPT_NOT_FOUND
A t-script file could not be opened.
Definition: kvaMemoLibXML.h:159
KvaXmlValidationStatusERR_SCRIPT_TOO_MANY
Too many active t-scripts for selected device.
Definition: kvaMemoLibXML.h:161
KvaXmlStatusERR_INTERNAL
Internal errors, e.g. null pointers.
Definition: kvaMemoLibXML.h:135
kvaXmlGetValidationError
KvaXmlStatus kvaXmlGetValidationError(KvaXmlValidationStatus *status, char *buf, unsigned int len)
KvaXmlValidationStatusERR_UNDEFINED_TRIGGER
An undefined trigger is used in an expression.
Definition: kvaMemoLibXML.h:154
KvaXmlStatusERR_VALUE_UNIQUE
The value is not unique; usually idx attributes.
Definition: kvaMemoLibXML.h:129
KvaXmlStatusERR_XML_PARSER
The XML settings contain syntax errors.
Definition: kvaMemoLibXML.h:132
kvaXmlGetValidationStatusCount
KvaXmlStatus kvaXmlGetValidationStatusCount(int *countErr, int *countWarn)
kvaXmlToBuffer
KvaXmlStatus kvaXmlToBuffer(const char *xmlbuf, unsigned int xmllen, char *outbuf, unsigned int *outlen, long *version)
KvParseHandle
Handle used when parsing postfix expressions (deprecated):
Definition: kvaMemoLibXML.h:413
KvaXmlStatusERR_SCRIPT_ERROR
t-script related errors, e.g. file not found.
Definition: kvaMemoLibXML.h:134
KvaXmlValidationStatusOK
OK.
Definition: kvaMemoLibXML.h:150
KvaXmlValidationStatusERR_ELEMENT_COUNT
Too many or too few elements of this type.
Definition: kvaMemoLibXML.h:163
KvaXmlStatus
KvaXmlStatus
Definition: kvaMemoLibXML.h:122
tag_token::name
char * name
Definition: kvaMemoLibXML.h:399
KvaXmlStatusERR_EXPRESSION
The trigger expression could not be parsed.
Definition: kvaMemoLibXML.h:131
kvaToolsParseCreate
KvParseHandle * kvaToolsParseCreate(void)
KvaXmlStatusERR_DTD_VALIDATION
The XML settings do not follow the DTD.
Definition: kvaMemoLibXML.h:133
KvaXmlStatusERR_VALUE_CONSECUTIVE
The values are not consecutive; usually idx attributes.
Definition: kvaMemoLibXML.h:130
KvaXmlStatusERR_ATTR_VALUE
The attribute value is not correct, e.g. whitespace after a number.
Definition: kvaMemoLibXML.h:126
KvaXmlStatusOK
OK.
Definition: kvaMemoLibXML.h:123
kvaToolsParseExpr
int kvaToolsParseExpr(KvParseHandle *h, char *expr, Token **t)
kvaXmlGetValidationText
KvaXmlStatus kvaXmlGetValidationText(KvaXmlValidationStatus status, char *buf, unsigned int len)
KvaXmlValidationStatusWARN_DISK_FULL_AND_FIFO
A trigger on disk full used with FIFO mode.
Definition: kvaMemoLibXML.h:170
kvaToolsExprGetError
int kvaToolsExprGetError(KvParseHandle *h, Token *t, int *errCode, int *pos)
kvaXmlGetLastError
KvaXmlStatus kvaXmlGetLastError(char *buf, unsigned int len, KvaXmlStatus *err)
tag_token
Token used when parsing postfix expressions (deprecated):
Definition: kvaMemoLibXML.h:397
kvaToolsDumpExpr
int kvaToolsDumpExpr(KvParseHandle *h, Token *t)
kvaXmlInitialize
KvaXmlStatus kvaXmlInitialize(void)
KvaXmlValidationStatusERR_PARSER
A general error found during parsing.
Definition: kvaMemoLibXML.h:164
KvaXmlValidationStatusERR_SCRIPT_TOO_LARGE
A t-script is too large for the configuration.
Definition: kvaMemoLibXML.h:160
kvaToolsExprGetErrorString
void kvaToolsExprGetErrorString(int errCode, char *s, size_t bufsiz)
tag_token::left
struct tag_token * left
Definition: kvaMemoLibXML.h:400
kvaToolsParseDestroy
void kvaToolsParseDestroy(KvParseHandle *h)
KvaXmlValidationStatusERR_NUM_OUT_OF_RANGE
A numerical value is out of range.
Definition: kvaMemoLibXML.h:158
kvaFileToXml
KvaXmlStatus kvaFileToXml(const char *parfile, const char *xmlfile)
kvaXmlValidate
KvaXmlStatus kvaXmlValidate(const char *xmlbuf, unsigned int xmllen)
kvaBufferToXml
KvaXmlStatus kvaBufferToXml(const char *inbuf, unsigned int inlen, char *xmlbuf, unsigned int *xmllen, long *version, const char *scriptpath)
kvaXmlGetVersion
unsigned short kvaXmlGetVersion(void)
tag_token::right
struct tag_token * right
Definition: kvaMemoLibXML.h:401