forked from OpenSCAP/openscap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpe_ctx_priv.c
83 lines (72 loc) · 2.32 KB
/
cpe_ctx_priv.c
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
/*
* Copyright 2013--2014 Red Hat Inc., Durham, North Carolina.
* All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors:
* Šimon Lukašík
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string.h>
#include <libxml/xmlreader.h>
#include "cpe_ctx_priv.h"
#include "common/_error.h"
#include "common/elements.h"
struct cpe_parser_ctx {
xmlTextReaderPtr reader;
bool owns_reader;
char *schema_version;
};
static inline struct cpe_parser_ctx *_cpe_parser_ctx_new()
{
return calloc(1, sizeof(struct cpe_parser_ctx));
}
struct cpe_parser_ctx *cpe_parser_ctx_from_reader(xmlTextReaderPtr reader)
{
struct cpe_parser_ctx *ctx = _cpe_parser_ctx_new();
ctx->reader = reader;
ctx->owns_reader = false;
return ctx;
}
void cpe_parser_ctx_free(struct cpe_parser_ctx *ctx)
{
if (ctx) {
if (ctx->reader != NULL && ctx->owns_reader)
xmlFreeTextReader(ctx->reader);
free(ctx->schema_version);
free(ctx);
}
}
static inline const char *_cpe_parser_ctx_get_schema_version(struct cpe_parser_ctx *ctx)
{
return (ctx->schema_version == NULL) ? "2.3" : ctx->schema_version;
}
static int _cpe_parser_ctx_version_cmp(struct cpe_parser_ctx *ctx, const char *version)
{
#ifdef __USE_GNU
return strverscmp(_cpe_parser_ctx_get_schema_version(ctx), version);
#else
return strcmp(_cpe_parser_ctx_get_schema_version(ctx), version);
#endif
}
bool cpe_parser_ctx_version_gt(struct cpe_parser_ctx *ctx, const char *version)
{
return _cpe_parser_ctx_version_cmp(ctx, version) > 0;
}
OSCAP_GETTER(xmlTextReaderPtr, cpe_parser_ctx, reader);
OSCAP_SETTER_GENERIC(cpe_parser_ctx, const char *, schema_version, free, oscap_strdup);