blob: 3163693cdfb04a93e02c780f6a43e60aa262afdf [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"
Michal Vasko5aa44c02020-06-29 11:47:02 +020021#include "compat.h"
Radek Krejci535ea9f2020-05-29 16:01:05 +020022#include "config.h"
Michal Vasko90932a92020-02-12 14:33:03 +010023#include "context.h"
Michal Vasko90932a92020-02-12 14:33:03 +010024
25/**
26 * @brief JSON-parser's implementation of ly_type_resolve_prefix() callback to provide mapping between prefixes used
27 * in the values to the schema via context module names.
28 */
29const struct lys_module *
Michal Vasko52927e22020-03-16 17:26:14 +010030lydjson_resolve_prefix(const struct ly_ctx *ctx, const char *prefix, size_t prefix_len, void *UNUSED(parser))
Michal Vasko90932a92020-02-12 14:33:03 +010031{
32 const struct lys_module *mod;
33 char *name;
34
35 name = strndup(prefix, prefix_len);
36 if (!name) {
37 return NULL;
38 }
39
40 mod = ly_ctx_get_module_implemented(ctx, name);
41 free(name);
42 return mod;
43}