|
Packit Service |
569379 |
/**
|
|
Packit Service |
569379 |
* @file oval_behavior.c
|
|
Packit Service |
569379 |
* \brief Open Vulnerability and Assessment Language
|
|
Packit Service |
569379 |
*
|
|
Packit Service |
569379 |
* See more details at http://oval.mitre.org/
|
|
Packit Service |
569379 |
*/
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
/*
|
|
Packit Service |
569379 |
* Copyright 2009--2013 Red Hat Inc., Durham, North Carolina.
|
|
Packit Service |
569379 |
* All Rights Reserved.
|
|
Packit Service |
569379 |
*
|
|
Packit Service |
569379 |
* This library is free software; you can redistribute it and/or
|
|
Packit Service |
569379 |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
569379 |
* License as published by the Free Software Foundation; either
|
|
Packit Service |
569379 |
* version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
569379 |
*
|
|
Packit Service |
569379 |
* This library is distributed in the hope that it will be useful,
|
|
Packit Service |
569379 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
569379 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
569379 |
* Lesser General Public License for more details.
|
|
Packit Service |
569379 |
*
|
|
Packit Service |
569379 |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
569379 |
* License along with this library; if not, write to the Free Software
|
|
Packit Service |
569379 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
Packit Service |
569379 |
*
|
|
Packit Service |
569379 |
* Authors:
|
|
Packit Service |
569379 |
* "David Niemoller" <David.Niemoller@g2-inc.com>
|
|
Packit Service |
569379 |
*/
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
#ifdef HAVE_CONFIG_H
|
|
Packit Service |
569379 |
#include <config.h>
|
|
Packit Service |
569379 |
#endif
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
#include <stdlib.h>
|
|
Packit Service |
569379 |
#include <stdio.h>
|
|
Packit Service |
569379 |
#include <string.h>
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
#include "oval_definitions_impl.h"
|
|
Packit Service |
569379 |
#include "adt/oval_collection_impl.h"
|
|
Packit Service |
569379 |
#include "adt/oval_string_map_impl.h"
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
#include "common/util.h"
|
|
Packit Service |
569379 |
#include "common/debug_priv.h"
|
|
Packit Service |
569379 |
#include "common/_error.h"
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
/***************************************************************************/
|
|
Packit Service |
569379 |
/* Variable definitions
|
|
Packit Service |
569379 |
* */
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
typedef struct oval_behavior {
|
|
Packit Service |
569379 |
struct oval_definition_model *model;
|
|
Packit Service |
569379 |
char *value;
|
|
Packit Service |
569379 |
char *key;
|
|
Packit Service |
569379 |
} oval_behavior_t;
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
/* End of variable definitions
|
|
Packit Service |
569379 |
* */
|
|
Packit Service |
569379 |
/***************************************************************************/
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
bool oval_behavior_iterator_has_more(struct oval_behavior_iterator *oc_behavior)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
return oval_collection_iterator_has_more((struct oval_iterator *)
|
|
Packit Service |
569379 |
oc_behavior);
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
struct oval_behavior *oval_behavior_iterator_next(struct oval_behavior_iterator
|
|
Packit Service |
569379 |
*oc_behavior)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
return (struct oval_behavior *)
|
|
Packit Service |
569379 |
oval_collection_iterator_next((struct oval_iterator *)oc_behavior);
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
void oval_behavior_iterator_free(struct oval_behavior_iterator
|
|
Packit Service |
569379 |
*oc_behavior)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
oval_collection_iterator_free((struct oval_iterator *)oc_behavior);
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
char *oval_behavior_get_value(struct oval_behavior *behavior)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
__attribute__nonnull__(behavior);
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
return behavior->value;
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
char *oval_behavior_get_key(struct oval_behavior *behavior)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
__attribute__nonnull__(behavior);
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
return behavior->key;
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
struct oval_behavior *oval_behavior_new(struct oval_definition_model *model)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
oval_behavior_t *behavior = (oval_behavior_t *) malloc(sizeof(oval_behavior_t));
|
|
Packit Service |
569379 |
if (behavior == NULL)
|
|
Packit Service |
569379 |
return NULL;
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
behavior->model = model;
|
|
Packit Service |
569379 |
behavior->value = NULL;
|
|
Packit Service |
569379 |
behavior->key = NULL;
|
|
Packit Service |
569379 |
return behavior;
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
struct oval_behavior *oval_behavior_clone(struct oval_definition_model *new_model, struct oval_behavior *old_behavior)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
struct oval_behavior *new_behavior = oval_behavior_new(new_model);
|
|
Packit Service |
569379 |
oval_behavior_set_keyval
|
|
Packit Service |
569379 |
(new_behavior, oval_behavior_get_key(old_behavior), oval_behavior_get_value(old_behavior));
|
|
Packit Service |
569379 |
return new_behavior;
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
void oval_behavior_free(struct oval_behavior *behavior)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
__attribute__nonnull__(behavior);
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
if (behavior->value)
|
|
Packit Service |
569379 |
free(behavior->value);
|
|
Packit Service |
569379 |
if (behavior->key)
|
|
Packit Service |
569379 |
free(behavior->key);
|
|
Packit Service |
569379 |
behavior->key = NULL;
|
|
Packit Service |
569379 |
behavior->value = NULL;
|
|
Packit Service |
569379 |
free(behavior);
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
void oval_behavior_set_keyval(struct oval_behavior *behavior, const char *key, const char *value)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
__attribute__nonnull__(behavior);
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
behavior->key = oscap_strdup(key);
|
|
Packit Service |
569379 |
behavior->value = oscap_strdup(value);
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
//typedef void (*oval_behavior_consumer)(struct oval_behavior_node *, void*);
|
|
Packit Service |
569379 |
int oval_behavior_parse_tag(xmlTextReaderPtr reader,
|
|
Packit Service |
569379 |
struct oval_parser_context *context,
|
|
Packit Service |
569379 |
oval_family_t family, oval_behavior_consumer consumer, void *user)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
__attribute__nonnull__(context);
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
while (xmlTextReaderMoveToNextAttribute(reader) == 1) {
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
const char *name = (const char *)xmlTextReaderConstName(reader);
|
|
Packit Service |
569379 |
const char *value = (const char *)xmlTextReaderConstValue(reader);
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
if (name && value) {
|
|
Packit Service |
569379 |
oval_behavior_t *behavior = oval_behavior_new(context->definition_model);
|
|
Packit Service |
569379 |
oval_behavior_set_keyval(behavior, name, value);
|
|
Packit Service |
569379 |
(*consumer) (behavior, user);
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
return 0;
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|