blob: e3e1bdfb5dac6d26410bb3a2f5eeffab68e5be4b [file] [log] [blame]
Michal Vasko90932a92020-02-12 14:33:03 +01001/**
2 * @file parser_json.c
3 * @author Radek Krejci <rkrejci@cesnet.cz>
4 * @brief JSON data parser for libyang
5 *
6 * Copyright (c) 2019 CESNET, z.s.p.o.
7 *
8 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * https://opensource.org/licenses/BSD-3-Clause
13 */
14
Radek Krejci535ea9f2020-05-29 16:01:05 +020015#define _GNU_SOURCE
Michal Vasko90932a92020-02-12 14:33:03 +010016
Michal Vasko90932a92020-02-12 14:33:03 +010017#include <stdlib.h>
18#include <string.h>
19
Radek Krejci535ea9f2020-05-29 16:01:05 +020020#include "common.h"
21#include "config.h"
Michal Vasko90932a92020-02-12 14:33:03 +010022#include "context.h"
Michal Vasko90932a92020-02-12 14:33:03 +010023
24/**
25 * @brief JSON-parser's implementation of ly_type_resolve_prefix() callback to provide mapping between prefixes used
26 * in the values to the schema via context module names.
27 */
28const struct lys_module *
Michal Vasko52927e22020-03-16 17:26:14 +010029lydjson_resolve_prefix(const struct ly_ctx *ctx, const char *prefix, size_t prefix_len, void *UNUSED(parser))
Michal Vasko90932a92020-02-12 14:33:03 +010030{
31 const struct lys_module *mod;
32 char *name;
33
34 name = strndup(prefix, prefix_len);
35 if (!name) {
36 return NULL;
37 }
38
39 mod = ly_ctx_get_module_implemented(ctx, name);
40 free(name);
41 return mod;
42}