<commit_before>/**
 * \file messages.c
 * \author <NAME> <<EMAIL>>
 * \brief libnetconf2 - NETCONF messages functions
 *
 * Copyright (c) 2015 CESNET, z.s.p.o.
 *
 * This source code is licensed under BSD 3-Clause License (the "License").
 * You may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://opensource.org/licenses/BSD-3-Clause
 */

#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>

#include <libyang/libyang.h>

#include "libnetconf.h"

const char *rpcedit_dfltop2str[] = {NULL, "merge", "replace", "none"};
const char *rpcedit_testopt2str[] = {NULL, "test-then-set", "set", "test-only"};
const char *rpcedit_erropt2str[] = {NULL, "stop-on-error", "continue-on-error", "rollback-on-error"};

API NC_RPC_TYPE
nc_rpc_get_type(const struct nc_rpc *rpc)
{
    if (!rpc) {
        ERRARG("rpc");
        return 0;
    }

    return rpc->type;
}

API struct nc_rpc *
nc_rpc_generic(const struct lyd_node *data, NC_PARAMTYPE paramtype)
{
    struct nc_rpc_generic *rpc;

    if (!data) {
        ERRARG("data");
        return NULL;
    }

    if (data->next || (data->prev != data)) {
        ERR("Generic RPC must have a single root node.");
        return NULL;
    }

    rpc = malloc(sizeof *rpc);
    if (!rpc) {
        ERRMEM;
        return NULL;
    }

    rpc->type = NC_RPC_GENERIC;
    rpc->has_data = 1;
    if (paramtype == NC_PARAMTYPE_DUP_AND_FREE) {
        rpc->content.data = lyd_dup(data, 1);
    } else {
        rpc->content.data = (struct lyd_node *)data;
    }
    rpc->free = (paramtype == NC_PARAMTYPE_CONST ? 0 : 1);

    return (struct nc_rpc *)rpc;
}

API struct nc_rpc *
nc_rpc_generic_xml(const char *xml_str, NC_PARAMTYPE paramtype)<commit_msg>client messages MAINTENANCE parameter check enhanced<commit_after>/**
 * \file messages.c
 * \author <NAME> <<EMAIL>>
 * \brief libnetconf2 - NETCONF messages functions
 *
 * Copyright (c) 2015 CESNET, z.s.p.o.
 *
 * This source code is licensed under BSD 3-Clause License (the "License").
 * You may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://opensource.org/licenses/BSD-3-Clause
 */

#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>

#include <libyang/libyang.h>

#include "libnetconf.h"

const char *rpcedit_dfltop2str[] = {NULL, "merge", "replace", "none"};
const char *rpcedit_testopt2str[] = {NULL, "test-then-set", "set", "test-only"};
const char *rpcedit_erropt2str[] = {NULL, "stop-on-error", "continue-on-error", "rollback-on-error"};

API NC_RPC_TYPE
nc_rpc_get_type(const struct nc_rpc *rpc)
{
    if (!rpc) {
        ERRARG("rpc");
        return 0;
    }

    return rpc->type;
}

API struct nc_rpc *
nc_rpc_generic(const struct lyd_node *data, NC_PARAMTYPE paramtype)
{
    struct nc_rpc_generic *rpc;

    if (!data || (data->schema->nodetype != LYS_RPC) || data->next || (data->prev != data)) {
        ERRARG("data");
        return NULL;
    }

    rpc = malloc(sizeof *rpc);
    if (!rpc) {
        ERRMEM;
        return NULL;
    }

    rpc->type = NC_RPC_GENERIC;
    rpc->has_data = 1;
    if (paramtype == NC_PARAMTYPE_DUP_AND_FREE) {
        rpc->content.data = lyd_dup(data, 1);
    } else {
        rpc->content.data = (struct lyd_node *)data;
    }
    rpc->free = (paramtype == NC_PARAMTYPE_CONST ? 0 : 1);

    return (struct nc_rpc *)rpc;
}

API struct nc_rpc *
nc_rpc_generic_xml(const char *xml_str, NC_PARAMTYPE paramtype)
{'fraction_non_alphanumeric': 0.14548022598870056, 'fraction_numerical': 0.00847457627118644, 'mean_word_length': 3.1463700234192036, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 37, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2187230', 'n_tokens_mistral': 1327, 'n_tokens_neox': 1268, 'n_words': 327}