context BUGFIX add context.c into a build system and fix issues
diff --git a/src/common.h b/src/common.h
index 0e1bc70..e6cf5e5 100644
--- a/src/common.h
+++ b/src/common.h
@@ -18,8 +18,8 @@
#include <stdint.h>
#include <stdlib.h>
-#include "libyang.h"
#include "config.h"
+#include "log.h"
#if __STDC_VERSION__ >= 201112 && !defined __STDC_NO_THREADS__
# define THREAD_LOCAL _Thread_local
@@ -51,6 +51,7 @@
extern volatile uint8_t ly_log_level;
extern volatile uint8_t ly_log_opts;
+void ly_err_free(void *ptr);
void ly_log(const struct ly_ctx *ctx, LY_LOG_LEVEL level, LY_ERR no, const char *format, ...);
#define LOGERR(ctx, errno, str, args...) ly_log(ctx, LY_LLERR, errno, str, ##args)
diff --git a/src/context.c b/src/context.c
index c2eba9b..31f6e3e 100644
--- a/src/context.c
+++ b/src/context.c
@@ -15,9 +15,10 @@
#include <errno.h>
#include <unistd.h>
-#include "libyang.h"
-#include "common.h"
#include "context.h"
+#include "common.h"
+
+#include "libyang.h"
#define LY_INTERNAL_MODS_COUNT 0 /* TODO 6 when parser available */
@@ -36,7 +37,6 @@
#include IETF_YANG_TYPES_PATH
#include IETF_DATASTORES
#include IETF_YANG_LIB_PATH
-#endif
static struct internal_modules_s {
const char *name;
@@ -45,7 +45,6 @@
uint8_t implemented;
LYS_INFORMAT format;
} internal_modules[LY_INTERNAL_MODS_COUNT] = {
-#if LY_INTERNAL_MODS_COUNT
{"ietf-yang-metadata", "2016-08-05", (const char*)ietf_yang_metadata_2016_08_05_yin, 0, LYS_IN_YIN},
{"yang", "2017-02-20", (const char*)yang_2017_02_20_yin, 1, LYS_IN_YIN},
{"ietf-inet-types", "2013-07-15", (const char*)ietf_inet_types_2013_07_15_yin, 0, LYS_IN_YIN},
@@ -53,8 +52,8 @@
/* ietf-datastores and ietf-yang-library must be right here at the end of the list! */
{"ietf-datastores", "2017-08-17", (const char*)ietf_datastores_2017_08_17_yin, 0, LYS_IN_YIN},
{"ietf-yang-library", IETF_YANG_LIB_REV, (const char*)ietf_yang_library_2018_01_17_yin, 1, LYS_IN_YIN}
-#endif
};
+#endif
API LY_ERR
ly_ctx_set_searchdir(struct ly_ctx *ctx, const char *search_dir)
@@ -72,7 +71,7 @@
LY_CHECK_ERR_GOTO(!new_dir,
LOGERR(ctx, LY_ESYS, "realpath() call failed for \"%s\" (%s).", search_dir, strerror(errno)),
cleanup);
- if (ly_set_add(ctx->search_paths, new_dir) == -1) {
+ if (ly_set_add(&ctx->search_paths, new_dir, 0) == -1) {
free(new_dir);
return LY_EMEM;
}
@@ -104,7 +103,7 @@
if (index >= 0) {
/* remove specific search directory */
- return ly_set_rm_index(ctx->search_paths, index);
+ return ly_set_rm_index(&ctx->search_paths, index);
} else {
/* remove them all */
for (; ctx->search_paths.number; ctx->search_paths.number--) {
@@ -125,19 +124,20 @@
char *search_dir_list;
char *sep, *dir;
LY_ERR rc = LY_SUCCESS;
- int i;
ctx = calloc(1, sizeof *ctx);
- LY_CHECK_ERR_RETURN(!ctx, LOGMEM(NULL), LY_EMEM);
+ LY_CHECK_ERR_RET(!ctx, LOGMEM(NULL), LY_EMEM);
/* dictionary */
lydict_init(&ctx->dict);
+#if 0 /* TODO when plugins implemented */
/* plugins */
ly_load_plugins();
+#endif
/* initialize thread-specific key */
- while ((i = pthread_key_create(&ctx->errlist_key, ly_err_free)) == EAGAIN);
+ while ((pthread_key_create(&ctx->errlist_key, ly_err_free)) == EAGAIN);
/* models list */
ctx->flags = options;
@@ -161,12 +161,14 @@
}
ctx->module_set_id = 1;
+#if 0 /* TODO when parser implemented */
/* load internal modules */
for (i = 0; i < (options & LY_CTX_NOYANGLIBRARY) ? LY_INTERNAL_MODS_COUNT - 2 : LY_INTERNAL_MODS_COUNT; i++) {
module = (struct lys_module *)lys_parse_mem(ctx, internal_modules[i].data, internal_modules[i].format);
LY_CHECK_GOTO(!module, error);
module->parsed->implemented = internal_modules[i].implemented;
}
+#endif
*new_ctx = ctx;
return rc;
@@ -259,7 +261,7 @@
}
API void
-ly_ctx_destroy(struct ly_ctx *ctx, void (*private_destructor)(const struct lys_node *node, void *priv))
+ly_ctx_destroy(struct ly_ctx *ctx, void (*private_destructor)(const struct lysc_node *node, void *priv))
{
LY_CHECK_ARG_RET(ctx, ctx,);
diff --git a/src/context.h b/src/context.h
index 4ff45ad..e907042 100644
--- a/src/context.h
+++ b/src/context.h
@@ -18,6 +18,7 @@
#include <pthread.h>
#include "common.h"
+#include "set.h"
#include "hash_table.h"
#include "tree_schema.h"
diff --git a/src/dict.h b/src/dict.h
index d24c522..2099012 100644
--- a/src/dict.h
+++ b/src/dict.h
@@ -19,12 +19,13 @@
#include <stdint.h>
#include <string.h>
-#include "libyang.h"
-
#ifdef __cplusplus
extern "C" {
#endif
+/* dummy context structure */
+struct ly_ctx;
+
/**
* @defgroup dict Dictionary
* @{
diff --git a/src/libyang.h b/src/libyang.h
index a023fbb..1a117af 100644
--- a/src/libyang.h
+++ b/src/libyang.h
@@ -107,9 +107,9 @@
*
* @param[in] ctx Context to be modified.
* @param[in] search_dir New search path to add to the current paths previously set in ctx.
- * @return EXIT_SUCCESS, EXIT_FAILURE.
+ * @return LY_ERR return value.
*/
-int ly_ctx_set_searchdir(struct ly_ctx *ctx, const char *search_dir);
+LY_ERR ly_ctx_set_searchdir(struct ly_ctx *ctx, const char *search_dir);
/**
* @brief Clean the search path(s) from the libyang context
diff --git a/src/log.h b/src/log.h
index 0d67918..8ab9703 100644
--- a/src/log.h
+++ b/src/log.h
@@ -15,12 +15,13 @@
#ifndef LY_LOG_H_
#define LY_LOG_H_
-#include "libyang.h"
-
#ifdef __cplusplus
extern "C" {
#endif
+/* dummy context structure */
+struct ly_ctx;
+
/**
* @defgroup log Logger
* @{