mirror of
https://dev.iopsys.eu/bbf/bbfdm.git
synced 2025-12-10 07:44:39 +01:00
Introduce a new library: libbbfdm-ubus
This commit is contained in:
parent
2925cd4d43
commit
1537993fc8
33 changed files with 1716 additions and 1743 deletions
|
|
@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.0)
|
||||||
PROJECT(bbf C)
|
PROJECT(bbf C)
|
||||||
|
|
||||||
add_subdirectory(libbbfdm-api)
|
add_subdirectory(libbbfdm-api)
|
||||||
|
add_subdirectory(libbbfdm-ubus)
|
||||||
add_subdirectory(libbbfdm)
|
add_subdirectory(libbbfdm)
|
||||||
add_subdirectory(bbfdmd)
|
add_subdirectory(bbfdmd)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,21 +3,10 @@ cmake_minimum_required(VERSION 3.0)
|
||||||
PROJECT(bbfdmd)
|
PROJECT(bbfdmd)
|
||||||
|
|
||||||
ADD_DEFINITIONS(-fstrict-aliasing -Wall -Wextra -Werror -Wformat -Wformat-signedness -fPIC -D_GNU_SOURCE)
|
ADD_DEFINITIONS(-fstrict-aliasing -Wall -Wextra -Werror -Wformat -Wformat-signedness -fPIC -D_GNU_SOURCE)
|
||||||
ADD_DEFINITIONS(-DBBF_VENDOR_PREFIX="${BBF_VENDOR_PREFIX}")
|
|
||||||
|
|
||||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I${CMAKE_SOURCE_DIR} -I${CMAKE_SOURCE_DIR}/libbbfdm-api/")
|
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I${CMAKE_SOURCE_DIR} -I${CMAKE_SOURCE_DIR}/libbbfdm-api/ -I${CMAKE_SOURCE_DIR}/libbbfdm-ubus/")
|
||||||
|
|
||||||
IF(${BBFDMD_MAX_MSG_LEN})
|
|
||||||
ADD_DEFINITIONS(-DBBFDM_MAX_MSG_LEN=${BBFDMD_MAX_MSG_LEN})
|
|
||||||
ENDIF()
|
|
||||||
|
|
||||||
OPTION(BBF_SCHEMA_FULL_TREE "build with schema full tree" OFF)
|
|
||||||
|
|
||||||
IF(BBF_SCHEMA_FULL_TREE)
|
|
||||||
add_compile_definitions(BBF_SCHEMA_FULL_TREE)
|
|
||||||
ENDIF(BBF_SCHEMA_FULL_TREE)
|
|
||||||
|
|
||||||
FILE(GLOB BBF_SOURCES *.c)
|
FILE(GLOB BBF_SOURCES *.c)
|
||||||
ADD_EXECUTABLE(bbfdmd ${BBF_SOURCES})
|
ADD_EXECUTABLE(bbfdmd ${BBF_SOURCES})
|
||||||
TARGET_LINK_LIBRARIES(bbfdmd ubus ubox blobmsg_json dl bbfdm-api)
|
TARGET_LINK_LIBRARIES(bbfdmd bbfdm-ubus)
|
||||||
INSTALL(TARGETS bbfdmd DESTINATION usr/sbin)
|
INSTALL(TARGETS bbfdmd DESTINATION usr/sbin)
|
||||||
|
|
|
||||||
1524
bbfdmd/ubus/bbfdmd.c
1524
bbfdmd/ubus/bbfdmd.c
File diff suppressed because it is too large
Load diff
|
|
@ -1,22 +0,0 @@
|
||||||
/*
|
|
||||||
* ipc.h: File to handle ipc related functionality
|
|
||||||
*
|
|
||||||
* Copyright (C) 2020-2023 IOPSYS Software Solutions AB. All rights reserved.
|
|
||||||
*
|
|
||||||
* Author: Vivek Dutta <vivek.dutta@iopsys.eu>
|
|
||||||
*
|
|
||||||
* See LICENSE file for license related information.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef IPC_H
|
|
||||||
#define IPC_H
|
|
||||||
|
|
||||||
#include <sys/mman.h>
|
|
||||||
|
|
||||||
#ifdef BBFDM_MAX_MSG_LEN
|
|
||||||
#define DEF_IPC_DATA_LEN (BBFDM_MAX_MSG_LEN - 128) // Configured Len - 128 bytes
|
|
||||||
#else
|
|
||||||
#define DEF_IPC_DATA_LEN (10 * 1024 * 1024 - 128) // 10M - 128 bytes
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* IPC_H */
|
|
||||||
|
|
@ -30,8 +30,8 @@
|
||||||
"name": "loglevel",
|
"name": "loglevel",
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"required": "no",
|
"required": "no",
|
||||||
"default": "1",
|
"default": "3",
|
||||||
"description": "Internal loglevel for debugging {0: No Logs; 1: Errors only; 2: Errors and warnings; 3: Error, warning and info; 4: Everything}"
|
"description": "Internal loglevel for debugging {0: No Logs; 1: Alert; 2: Critical; 3: Error; 4: Warning; 5: Notice; 6: Info; 7: Debug}"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "subprocess_level",
|
"name": "subprocess_level",
|
||||||
|
|
|
||||||
|
|
@ -98,8 +98,7 @@
|
||||||
<div class="td_row_even">1</div>
|
<div class="td_row_even">1</div>
|
||||||
</td>
|
</td>
|
||||||
<td class="td_row_even">
|
<td class="td_row_even">
|
||||||
<div class="td_row_even">Internal loglevel for debugging {0: No Logs; 1: Errors only; 2: Errors
|
<div class="td_row_even">Internal loglevel for debugging {0: No Logs; 1: Alert; 2: Critical; 3: Error; 4: Warning; 5: Notice; 6: Info; 7: Debug}</div>
|
||||||
and warnings; 3: Error, warning and info; 4: Everything}</div>
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
@ -119,23 +118,6 @@
|
||||||
<div class="td_row_even">This parameter configures when subprocess can be used for get operation. Level here denotes the Datamodel object depth up-to which subprocess will be used to collect the get data. For example, if this is configured to 1, then only get for 'Device.' shall be called within the subprocess. If configured as level 2, then all the get with up-to depth 2 like 'Device.WiFi.', 'Device.IP.' shall be called in subprocess.</div>
|
<div class="td_row_even">This parameter configures when subprocess can be used for get operation. Level here denotes the Datamodel object depth up-to which subprocess will be used to collect the get data. For example, if this is configured to 1, then only get for 'Device.' shall be called within the subprocess. If configured as level 2, then all the get with up-to depth 2 like 'Device.WiFi.', 'Device.IP.' shall be called in subprocess.</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
|
||||||
<td class="td_row_even">
|
|
||||||
<div class="td_row_even">bbf_caching_time</div>
|
|
||||||
</td>
|
|
||||||
<td class="td_row_even">
|
|
||||||
<div class="td_row_even">integer</div>
|
|
||||||
</td>
|
|
||||||
<td class="td_row_even">
|
|
||||||
<div class="td_row_even">no</div>
|
|
||||||
</td>
|
|
||||||
<td class="td_row_even">
|
|
||||||
<div class="td_row_even">0</div>
|
|
||||||
</td>
|
|
||||||
<td class="td_row_even">
|
|
||||||
<div class="td_row_even">Max caching time in seconds for ubus output used in datamodel parameters. If not configured, output shall be cleared end the end of call.</div>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
<tr>
|
||||||
<td class="td_row_even">
|
<td class="td_row_even">
|
||||||
<div class="td_row_even">refresh_time</div>
|
<div class="td_row_even">refresh_time</div>
|
||||||
|
|
|
||||||
|
|
@ -264,7 +264,7 @@ int bbfdm_get_references(struct dmctx *ctx, int match_action, const char *base_p
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_micro_service == true) { // It's a micro-service instance
|
if (dm_is_micro_service() == true) { // It's a micro-service instance
|
||||||
|
|
||||||
if (out_len - len < strlen(base_path) + strlen(key_name) + strlen(key_value) + 9) { // 9 = 'path[key_name==\"key_value\"].'
|
if (out_len - len < strlen(base_path) + strlen(key_name) + strlen(key_value) + 9) { // 9 = 'path[key_name==\"key_value\"].'
|
||||||
BBF_ERR("Buffer overflow detected. The output buffer is not large enough to hold the additional data!!!");
|
BBF_ERR("Buffer overflow detected. The output buffer is not large enough to hold the additional data!!!");
|
||||||
|
|
@ -395,7 +395,7 @@ int bbfdm_operate_reference_linker(struct dmctx *ctx, char *reference_path, char
|
||||||
if (DM_STRLEN(*reference_value) != 0)
|
if (DM_STRLEN(*reference_value) != 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (is_micro_service == true) // It's a micro-service instance
|
if (dm_is_micro_service() == true) // It's a micro-service instance
|
||||||
*reference_value = bbfdm_get_reference_value(reference_path);
|
*reference_value = bbfdm_get_reference_value(reference_path);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -33,9 +33,6 @@ extern struct dm_permession_s DMASYNC;
|
||||||
|
|
||||||
extern char *DMT_TYPE[];
|
extern char *DMT_TYPE[];
|
||||||
|
|
||||||
extern unsigned char gLogLevel;
|
|
||||||
extern bool is_micro_service;
|
|
||||||
|
|
||||||
#ifndef BBF_MAX_OBJECT_INSTANCES
|
#ifndef BBF_MAX_OBJECT_INSTANCES
|
||||||
#define BBF_MAX_OBJECT_INSTANCES (255)
|
#define BBF_MAX_OBJECT_INSTANCES (255)
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,9 @@
|
||||||
#include "dmbbf.h"
|
#include "dmbbf.h"
|
||||||
|
|
||||||
#define MAX_DM_PATH (1024)
|
#define MAX_DM_PATH (1024)
|
||||||
#define DEFAULT_LOG_LEVEL (2)
|
|
||||||
#define SEPARATOR_LIST_VALUES ";"
|
#define SEPARATOR_LIST_VALUES ";"
|
||||||
|
|
||||||
unsigned char gLogLevel = DEFAULT_LOG_LEVEL;
|
static bool is_micro_service = false;
|
||||||
bool is_micro_service = false;
|
|
||||||
|
|
||||||
char *DMT_TYPE[] = {
|
char *DMT_TYPE[] = {
|
||||||
[DMT_STRING] = "xsd:string",
|
[DMT_STRING] = "xsd:string",
|
||||||
|
|
@ -43,6 +41,16 @@ struct dm_permession_s DMWRITE = {"1", NULL};
|
||||||
struct dm_permession_s DMSYNC = {"sync", NULL};
|
struct dm_permession_s DMSYNC = {"sync", NULL};
|
||||||
struct dm_permession_s DMASYNC = {"async", NULL};
|
struct dm_permession_s DMASYNC = {"async", NULL};
|
||||||
|
|
||||||
|
bool dm_is_micro_service(void)
|
||||||
|
{
|
||||||
|
return is_micro_service;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dm_set_micro_service(void)
|
||||||
|
{
|
||||||
|
is_micro_service = true;
|
||||||
|
}
|
||||||
|
|
||||||
static int dm_browse(struct dmctx *dmctx, DMNODE *parent_node, DMOBJ *entryobj, void *data, char *instance);
|
static int dm_browse(struct dmctx *dmctx, DMNODE *parent_node, DMOBJ *entryobj, void *data, char *instance);
|
||||||
|
|
||||||
static bool is_instance_number_alias(char **str)
|
static bool is_instance_number_alias(char **str)
|
||||||
|
|
@ -819,7 +827,7 @@ static int is64digit(char c)
|
||||||
|
|
||||||
char *get_value_by_reference(struct dmctx *ctx, char *value)
|
char *get_value_by_reference(struct dmctx *ctx, char *value)
|
||||||
{
|
{
|
||||||
if (is_micro_service == true) // It's a micro-service instance
|
if (dm_is_micro_service() == true) // It's a micro-service instance
|
||||||
return value;
|
return value;
|
||||||
|
|
||||||
char *pch = NULL, *spch = NULL;
|
char *pch = NULL, *spch = NULL;
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,9 @@
|
||||||
#include "dmmem.h"
|
#include "dmmem.h"
|
||||||
#include "dmapi.h"
|
#include "dmapi.h"
|
||||||
|
|
||||||
|
bool dm_is_micro_service(void);
|
||||||
|
void dm_set_micro_service(void);
|
||||||
|
|
||||||
int get_number_of_entries(struct dmctx *ctx, void *data, char *instance, int (*browseinstobj)(struct dmctx *ctx, struct dmnode *node, void *data, char *instance));
|
int get_number_of_entries(struct dmctx *ctx, void *data, char *instance, int (*browseinstobj)(struct dmctx *ctx, struct dmnode *node, void *data, char *instance));
|
||||||
char *handle_instance(struct dmctx *dmctx, DMNODE *parent_node, struct uci_section *s, char *inst_opt, char *alias_opt);
|
char *handle_instance(struct dmctx *dmctx, DMNODE *parent_node, struct uci_section *s, char *inst_opt, char *alias_opt);
|
||||||
char *handle_instance_without_section(struct dmctx *dmctx, DMNODE *parent_node, int inst_nbr);
|
char *handle_instance_without_section(struct dmctx *dmctx, DMNODE *parent_node, int inst_nbr);
|
||||||
|
|
@ -68,27 +71,19 @@ static inline int DM_LINK_INST_OBJ(struct dmctx *dmctx, DMNODE *parent_node, voi
|
||||||
|
|
||||||
// Macros for different log levels
|
// Macros for different log levels
|
||||||
#define BBF_ERR(MESSAGE, ...) do { \
|
#define BBF_ERR(MESSAGE, ...) do { \
|
||||||
if (gLogLevel >= 1) { \
|
|
||||||
syslog(LOG_ERR, "[%s:%d] " MESSAGE, __FUNCTION__, __LINE__, ##__VA_ARGS__); /* Flawfinder: ignore */ \
|
syslog(LOG_ERR, "[%s:%d] " MESSAGE, __FUNCTION__, __LINE__, ##__VA_ARGS__); /* Flawfinder: ignore */ \
|
||||||
} \
|
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
#define BBF_WARNING(MESSAGE, ...) do { \
|
#define BBF_WARNING(MESSAGE, ...) do { \
|
||||||
if (gLogLevel >= 2) { \
|
|
||||||
syslog(LOG_WARNING, "[%s:%d] " MESSAGE, __FUNCTION__, __LINE__, ##__VA_ARGS__); /* Flawfinder: ignore */ \
|
syslog(LOG_WARNING, "[%s:%d] " MESSAGE, __FUNCTION__, __LINE__, ##__VA_ARGS__); /* Flawfinder: ignore */ \
|
||||||
} \
|
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
#define BBF_INFO(MESSAGE, ...) do { \
|
#define BBF_INFO(MESSAGE, ...) do { \
|
||||||
if (gLogLevel >= 3) { \
|
|
||||||
syslog(LOG_INFO, "[%s:%d] " MESSAGE, __FUNCTION__, __LINE__, ##__VA_ARGS__); /* Flawfinder: ignore */ \
|
syslog(LOG_INFO, "[%s:%d] " MESSAGE, __FUNCTION__, __LINE__, ##__VA_ARGS__); /* Flawfinder: ignore */ \
|
||||||
} \
|
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
#define BBF_DEBUG(MESSAGE, ...) do { \
|
#define BBF_DEBUG(MESSAGE, ...) do { \
|
||||||
if (gLogLevel >= 4) { \
|
|
||||||
syslog(LOG_DEBUG, "[%s:%d] " MESSAGE, __FUNCTION__, __LINE__, ##__VA_ARGS__); /* Flawfinder: ignore */ \
|
syslog(LOG_DEBUG, "[%s:%d] " MESSAGE, __FUNCTION__, __LINE__, ##__VA_ARGS__); /* Flawfinder: ignore */ \
|
||||||
} \
|
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -258,7 +258,7 @@ int dm_validate_allowed_objects(struct dmctx *ctx, struct dm_reference *referenc
|
||||||
|
|
||||||
if (match(reference->path, *objects, 0, NULL)) {
|
if (match(reference->path, *objects, 0, NULL)) {
|
||||||
|
|
||||||
if (is_micro_service) {
|
if (dm_is_micro_service()) {
|
||||||
if (DM_STRLEN(reference->value))
|
if (DM_STRLEN(reference->value))
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
32
libbbfdm-ubus/CMakeLists.txt
Normal file
32
libbbfdm-ubus/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
cmake_minimum_required(VERSION 3.0)
|
||||||
|
|
||||||
|
PROJECT(libbbfdm-ubus)
|
||||||
|
|
||||||
|
ADD_DEFINITIONS(-Wall -Werror -D_GNU_SOURCE)
|
||||||
|
ADD_DEFINITIONS(-DBBF_VENDOR_PREFIX="${BBF_VENDOR_PREFIX}")
|
||||||
|
|
||||||
|
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I${CMAKE_SOURCE_DIR} -I${CMAKE_SOURCE_DIR}/libbbfdm-api/")
|
||||||
|
|
||||||
|
IF(${BBFDMD_MAX_MSG_LEN})
|
||||||
|
ADD_DEFINITIONS(-DBBFDM_MAX_MSG_LEN=${BBFDMD_MAX_MSG_LEN})
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
|
OPTION(BBF_SCHEMA_FULL_TREE "build with schema full tree" OFF)
|
||||||
|
|
||||||
|
IF(BBF_SCHEMA_FULL_TREE)
|
||||||
|
add_compile_definitions(BBF_SCHEMA_FULL_TREE)
|
||||||
|
ENDIF(BBF_SCHEMA_FULL_TREE)
|
||||||
|
|
||||||
|
FILE(GLOB BBF_UBUS_SOURCES *.c)
|
||||||
|
|
||||||
|
ADD_LIBRARY(bbfdm-ubus SHARED ${BBF_UBUS_SOURCES})
|
||||||
|
|
||||||
|
TARGET_LINK_LIBRARIES(bbfdm-ubus uci ubus ubox json-c blobmsg_json bbfdm-api)
|
||||||
|
|
||||||
|
INSTALL(TARGETS bbfdm-ubus
|
||||||
|
LIBRARY DESTINATION usr/lib)
|
||||||
|
|
||||||
|
FILE(GLOB libbbfdm-ubus_headers bbfdm-ubus.h)
|
||||||
|
INSTALL(FILES ${libbbfdm-ubus_headers}
|
||||||
|
DESTINATION usr/include/libbbfdm-ubus
|
||||||
|
)
|
||||||
|
|
@ -19,7 +19,7 @@ static int bbfdm_add_object(bbfdm_data_t *data)
|
||||||
{
|
{
|
||||||
int fault = 0;
|
int fault = 0;
|
||||||
|
|
||||||
INFO("Req to add object |%s|", data->bbf_ctx.in_param);
|
BBF_INFO("Req to add object |%s|", data->bbf_ctx.in_param);
|
||||||
|
|
||||||
void *array = blobmsg_open_array(&data->bb, "results");
|
void *array = blobmsg_open_array(&data->bb, "results");
|
||||||
|
|
||||||
|
|
@ -50,7 +50,7 @@ static int bbfdm_del_object(bbfdm_data_t *data)
|
||||||
|
|
||||||
data->bbf_ctx.in_param = pn->path;
|
data->bbf_ctx.in_param = pn->path;
|
||||||
|
|
||||||
INFO("Req to delete object |%s|", data->bbf_ctx.in_param);
|
BBF_INFO("Req to delete object |%s|", data->bbf_ctx.in_param);
|
||||||
|
|
||||||
fault = bbfdm_cmd_exec(&data->bbf_ctx, BBF_DEL_OBJECT);
|
fault = bbfdm_cmd_exec(&data->bbf_ctx, BBF_DEL_OBJECT);
|
||||||
if (fault) {
|
if (fault) {
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
#ifndef ADD_DEL_H
|
#ifndef ADD_DEL_H
|
||||||
#define ADD_DEL_H
|
#define ADD_DEL_H
|
||||||
|
|
||||||
#include "bbfdmd.h"
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
DM_ADD_PATH,
|
DM_ADD_PATH,
|
||||||
DM_ADD_OBJ_PATH,
|
DM_ADD_OBJ_PATH,
|
||||||
1529
libbbfdm-ubus/bbfdm-ubus.c
Normal file
1529
libbbfdm-ubus/bbfdm-ubus.c
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -1,14 +1,21 @@
|
||||||
#ifndef BBFDMD_H
|
#ifndef BBFDM_UBUS_H
|
||||||
#define BBFDMD_H
|
#define BBFDM_UBUS_H
|
||||||
|
|
||||||
#include <libubus.h>
|
#include <libubus.h>
|
||||||
#include <libubox/blobmsg.h>
|
#include <libubox/blobmsg.h>
|
||||||
#include <libubox/list.h>
|
#include <libubox/list.h>
|
||||||
|
|
||||||
#include "dmbbf.h"
|
#include <libbbfdm-api/dmbbf.h>
|
||||||
|
|
||||||
|
#define BBFDM_DEFAULT_MICROSERVICE_INPUT_PATH "/etc/bbfdm/micro_services"
|
||||||
#define MAX_OBJS 5
|
#define MAX_OBJS 5
|
||||||
|
|
||||||
|
#ifndef DAEMON_JSON_INPUT
|
||||||
|
#define BBFDM_JSON_INPUT "/tmp/bbfdm/input.json"
|
||||||
|
#else
|
||||||
|
#define BBFDM_JSON_INPUT DAEMON_JSON_INPUT
|
||||||
|
#endif
|
||||||
|
|
||||||
struct bbfdm_async_req {
|
struct bbfdm_async_req {
|
||||||
struct ubus_context *ctx;
|
struct ubus_context *ctx;
|
||||||
struct ubus_request_data req;
|
struct ubus_request_data req;
|
||||||
|
|
@ -20,7 +27,6 @@ struct bbfdm_async_req {
|
||||||
typedef struct bbfdm_config {
|
typedef struct bbfdm_config {
|
||||||
int proto; // Protocol identifier, Possible values: { '0'<both>, '1'<cwmp>, '2'<usp> }
|
int proto; // Protocol identifier, Possible values: { '0'<both>, '1'<cwmp>, '2'<usp> }
|
||||||
int subprocess_level; // Subprocess level
|
int subprocess_level; // Subprocess level
|
||||||
uint8_t log_level; // Log level, Possible values: { '1', '2', '3', '4' }
|
|
||||||
uint32_t refresh_time; // Refresh time
|
uint32_t refresh_time; // Refresh time
|
||||||
char service_name[16]; // Service name for micro-service identification
|
char service_name[16]; // Service name for micro-service identification
|
||||||
char in_type[32]; // Input type, Possible values: { 'JSON', 'DotSo' }
|
char in_type[32]; // Input type, Possible values: { 'JSON', 'DotSo' }
|
||||||
|
|
@ -66,4 +72,11 @@ typedef struct bbfdm_data {
|
||||||
void register_instance_refresh_timer(struct ubus_context *ctx, int start_sec);
|
void register_instance_refresh_timer(struct ubus_context *ctx, int start_sec);
|
||||||
void cancel_instance_refresh_timer(struct ubus_context *ctx);
|
void cancel_instance_refresh_timer(struct ubus_context *ctx);
|
||||||
|
|
||||||
#endif /* BBFDMD_H */
|
int bbfdm_ubus_regiter_init(struct bbfdm_context *bbfdm_ctx);
|
||||||
|
int bbfdm_ubus_regiter_free(struct bbfdm_context *bbfdm_ctx);
|
||||||
|
|
||||||
|
void bbfdm_ubus_set_service_name(struct bbfdm_context *bbfdm_ctx, const char *srv_name);
|
||||||
|
void bbfdm_ubus_set_log_level(int log_level);
|
||||||
|
void bbfdm_ubus_load_data_model(DM_MAP_OBJ *DynamicObj);
|
||||||
|
|
||||||
|
#endif /* BBFDM_UBUS_H */
|
||||||
|
|
@ -12,61 +12,6 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "get_helper.h"
|
#include "get_helper.h"
|
||||||
|
|
||||||
// Logging utilities
|
|
||||||
void set_debug_level(unsigned char level)
|
|
||||||
{
|
|
||||||
gLogLevel = level;
|
|
||||||
}
|
|
||||||
|
|
||||||
void print_error(const char *format, ...)
|
|
||||||
{
|
|
||||||
va_list arglist;
|
|
||||||
|
|
||||||
if (gLogLevel < 1)
|
|
||||||
return;
|
|
||||||
|
|
||||||
va_start(arglist, format);
|
|
||||||
vsyslog(LOG_ERR, format, arglist);
|
|
||||||
va_end(arglist);
|
|
||||||
}
|
|
||||||
|
|
||||||
void print_warning(const char *format, ...)
|
|
||||||
{
|
|
||||||
va_list arglist;
|
|
||||||
|
|
||||||
if (gLogLevel < 2)
|
|
||||||
return;
|
|
||||||
|
|
||||||
va_start(arglist, format);
|
|
||||||
vsyslog(LOG_WARNING, format, arglist);
|
|
||||||
va_end(arglist);
|
|
||||||
}
|
|
||||||
|
|
||||||
void print_info(const char *format, ...)
|
|
||||||
{
|
|
||||||
va_list arglist;
|
|
||||||
|
|
||||||
if (gLogLevel < 3)
|
|
||||||
return;
|
|
||||||
|
|
||||||
va_start(arglist, format);
|
|
||||||
vsyslog(LOG_INFO, format, arglist);
|
|
||||||
va_end(arglist);
|
|
||||||
}
|
|
||||||
|
|
||||||
void print_debug(const char *format, ...)
|
|
||||||
{
|
|
||||||
va_list arglist;
|
|
||||||
|
|
||||||
if (gLogLevel < 4)
|
|
||||||
return;
|
|
||||||
|
|
||||||
va_start(arglist, format);
|
|
||||||
vsyslog(LOG_DEBUG, format, arglist);
|
|
||||||
va_end(arglist);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool is_str_eq(const char *s1, const char *s2)
|
bool is_str_eq(const char *s1, const char *s2)
|
||||||
{
|
{
|
||||||
if (strcmp(s1, s2) == 0)
|
if (strcmp(s1, s2) == 0)
|
||||||
|
|
@ -95,7 +40,7 @@ bool is_node_instance(char *path)
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
char *rb = NULL;
|
char *rb = NULL;
|
||||||
|
|
||||||
DEBUG("entry |%s|", path);
|
BBF_DEBUG("entry |%s|", path);
|
||||||
if (!path)
|
if (!path)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
@ -138,7 +83,7 @@ bool validate_msglen(bbfdm_data_t *data)
|
||||||
size_t data_len = blob_pad_len(data->bbf_ctx.bb.head);
|
size_t data_len = blob_pad_len(data->bbf_ctx.bb.head);
|
||||||
|
|
||||||
if (data_len >= DEF_IPC_DATA_LEN) {
|
if (data_len >= DEF_IPC_DATA_LEN) {
|
||||||
ERR("Blob exceed max len(%zd), data len(%zd)", DEF_IPC_DATA_LEN, data_len);
|
BBF_ERR("Blob exceed max len(%d), data len(%zd)", DEF_IPC_DATA_LEN, data_len);
|
||||||
blob_buf_free(&data->bbf_ctx.bb);
|
blob_buf_free(&data->bbf_ctx.bb);
|
||||||
blob_buf_init(&data->bbf_ctx.bb, 0);
|
blob_buf_init(&data->bbf_ctx.bb, 0);
|
||||||
fill_err_code_table(data, FAULT_9002);
|
fill_err_code_table(data, FAULT_9002);
|
||||||
|
|
@ -15,8 +15,7 @@
|
||||||
#include <libubox/list.h>
|
#include <libubox/list.h>
|
||||||
|
|
||||||
#include "dmcommon.h"
|
#include "dmcommon.h"
|
||||||
|
#include "bbfdm-ubus.h"
|
||||||
#include "bbfdmd.h"
|
|
||||||
|
|
||||||
#define STRINGIFY(x) #x
|
#define STRINGIFY(x) #x
|
||||||
#define TO_STR(x) STRINGIFY(x)
|
#define TO_STR(x) STRINGIFY(x)
|
||||||
|
|
@ -43,34 +42,18 @@
|
||||||
#define GLOB_EXPR "[=><]+"
|
#define GLOB_EXPR "[=><]+"
|
||||||
|
|
||||||
extern DMOBJ *DEAMON_DM_ROOT_OBJ;
|
extern DMOBJ *DEAMON_DM_ROOT_OBJ;
|
||||||
|
extern DM_MAP_OBJ *INTERNAL_ROOT_TREE;
|
||||||
|
|
||||||
bool is_str_eq(const char *s1, const char *s2);
|
bool is_str_eq(const char *s1, const char *s2);
|
||||||
bool is_node_instance(char *path);
|
bool is_node_instance(char *path);
|
||||||
int count_delim(const char *path);
|
int count_delim(const char *path);
|
||||||
|
|
||||||
void set_debug_level(unsigned char level);
|
|
||||||
void print_error(const char *format, ...);
|
|
||||||
void print_warning(const char *format, ...);
|
|
||||||
void print_info(const char *format, ...);
|
|
||||||
void print_debug(const char *format, ...);
|
|
||||||
bool get_boolean_string(char *value);
|
bool get_boolean_string(char *value);
|
||||||
bool validate_msglen(bbfdm_data_t *data);
|
bool validate_msglen(bbfdm_data_t *data);
|
||||||
|
|
||||||
int get_dm_type(char *dm_type);
|
int get_dm_type(char *dm_type);
|
||||||
int get_proto_type(const char *proto);
|
int get_proto_type(const char *proto);
|
||||||
|
|
||||||
#define DEBUG(fmt, args...) \
|
|
||||||
print_debug("[%s:%d]"fmt, __func__, __LINE__, ##args)
|
|
||||||
|
|
||||||
#define INFO(fmt, args...) \
|
|
||||||
print_info(fmt, ##args)
|
|
||||||
|
|
||||||
#define ERR(fmt, args...) \
|
|
||||||
print_error("[%s:%d] " fmt, __func__, __LINE__, ##args)
|
|
||||||
|
|
||||||
#define WARNING(fmt, args...) \
|
|
||||||
print_warning("[%s:%d] " fmt, __func__, __LINE__, ##args)
|
|
||||||
|
|
||||||
int get_resolved_paths(struct dmctx *bbf_ctx, char *qpath, struct list_head *resolved_paths);
|
int get_resolved_paths(struct dmctx *bbf_ctx, char *qpath, struct list_head *resolved_paths);
|
||||||
void strncpyt(char *dst, const char *src, size_t n);
|
void strncpyt(char *dst, const char *src, size_t n);
|
||||||
|
|
||||||
|
|
@ -12,7 +12,6 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "events.h"
|
#include "events.h"
|
||||||
#include "get_helper.h"
|
#include "get_helper.h"
|
||||||
#include "bbfdmd.h"
|
|
||||||
#include <libubus.h>
|
#include <libubus.h>
|
||||||
|
|
||||||
static char *get_events_dm_path(struct list_head *ev_list, const char *event)
|
static char *get_events_dm_path(struct list_head *ev_list, const char *event)
|
||||||
|
|
@ -38,7 +37,7 @@ static void bbfdm_event_handler(struct ubus_context *ctx, struct ubus_event_hand
|
||||||
|
|
||||||
u = container_of(ctx, struct bbfdm_context, ubus_ctx);
|
u = container_of(ctx, struct bbfdm_context, ubus_ctx);
|
||||||
if (u == NULL) {
|
if (u == NULL) {
|
||||||
ERR("Failed to get the bbfdm context");
|
BBF_ERR("Failed to get the bbfdm context");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -81,7 +80,7 @@ static void bbfdm_event_handler(struct ubus_context *ctx, struct ubus_event_hand
|
||||||
snprintf(method_name, sizeof(method_name), "%s.%s", DM_STRLEN(u->config.out_root_obj) ? u->config.out_root_obj : u->config.out_name, BBF_EVENT_NAME);
|
snprintf(method_name, sizeof(method_name), "%s.%s", DM_STRLEN(u->config.out_root_obj) ? u->config.out_root_obj : u->config.out_name, BBF_EVENT_NAME);
|
||||||
|
|
||||||
ubus_send_event(ctx, method_name, bbf_ctx.bb.head);
|
ubus_send_event(ctx, method_name, bbf_ctx.bb.head);
|
||||||
INFO("Event[%s], for [%s] sent", method_name, dm_path);
|
BBF_INFO("Event[%s], for [%s] sent", method_name, dm_path);
|
||||||
|
|
||||||
register_instance_refresh_timer(ctx, 2000);
|
register_instance_refresh_timer(ctx, 2000);
|
||||||
|
|
||||||
|
|
@ -99,7 +98,7 @@ static void add_ubus_event_handler(struct ubus_event_handler *ev, const char *ev
|
||||||
node = (struct ev_handler_node *) malloc(sizeof(struct ev_handler_node));
|
node = (struct ev_handler_node *) malloc(sizeof(struct ev_handler_node));
|
||||||
|
|
||||||
if (!node) {
|
if (!node) {
|
||||||
ERR("Out of memory!");
|
BBF_ERR("Out of memory!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -150,7 +149,7 @@ int register_events_to_ubus(struct ubus_context *ctx, struct list_head *ev_list)
|
||||||
|
|
||||||
struct ubus_event_handler *ev = (struct ubus_event_handler *)malloc(sizeof(struct ubus_event_handler));
|
struct ubus_event_handler *ev = (struct ubus_event_handler *)malloc(sizeof(struct ubus_event_handler));
|
||||||
if (!ev) {
|
if (!ev) {
|
||||||
ERR("Out of memory!");
|
BBF_ERR("Out of memory!");
|
||||||
err = -1;
|
err = -1;
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
@ -159,7 +158,7 @@ int register_events_to_ubus(struct ubus_context *ctx, struct list_head *ev_list)
|
||||||
ev->cb = bbfdm_event_handler;
|
ev->cb = bbfdm_event_handler;
|
||||||
|
|
||||||
if (0 != ubus_register_event_handler(ctx, ev, event_name)) {
|
if (0 != ubus_register_event_handler(ctx, ev, event_name)) {
|
||||||
ERR("Failed to register: %s", event_name);
|
BBF_ERR("Failed to register: %s", event_name);
|
||||||
err = -1;
|
err = -1;
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
@ -1,9 +1,6 @@
|
||||||
#ifndef EVENT_H
|
#ifndef EVENT_H
|
||||||
#define EVENT_H
|
#define EVENT_H
|
||||||
|
|
||||||
#include "bbfdmd.h"
|
|
||||||
#include "common.h"
|
|
||||||
|
|
||||||
int register_events_to_ubus(struct ubus_context *ctx, struct list_head *ev_list);
|
int register_events_to_ubus(struct ubus_context *ctx, struct list_head *ev_list);
|
||||||
void free_ubus_event_handler(struct ubus_context *ctx, struct list_head *ev_list);
|
void free_ubus_event_handler(struct ubus_context *ctx, struct list_head *ev_list);
|
||||||
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
* See LICENSE file for license related information.
|
* See LICENSE file for license related information.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
#include "get.h"
|
#include "get.h"
|
||||||
#include "get_helper.h"
|
#include "get_helper.h"
|
||||||
#include "pretty_print.h"
|
#include "pretty_print.h"
|
||||||
|
|
@ -101,7 +102,7 @@ static bool get_next_param(char *qPath, size_t *pos, char *param)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (qPath[++i] != '.') {
|
if (qPath[++i] != '.') {
|
||||||
ERR("No dot after search parameters");
|
BBF_ERR("No dot after search parameters");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// skip the dot
|
// skip the dot
|
||||||
|
|
@ -141,7 +142,7 @@ static bool is_present_in_datamodel(struct dmctx *bbf_ctx, char *path)
|
||||||
size_t plen = 0, rem = 0;
|
size_t plen = 0, rem = 0;
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
DEBUG("path(%s)", path);
|
BBF_DEBUG("path(%s)", path);
|
||||||
plen = DM_STRLEN(path);
|
plen = DM_STRLEN(path);
|
||||||
|
|
||||||
blobmsg_for_each_attr(cur, bbf_ctx->bb.head, rem) {
|
blobmsg_for_each_attr(cur, bbf_ctx->bb.head, rem) {
|
||||||
|
|
@ -255,7 +256,7 @@ static void handle_special_escape_sequence(char *value, char *buff, size_t buff_
|
||||||
}
|
}
|
||||||
buff[j] = '\0';
|
buff[j] = '\0';
|
||||||
|
|
||||||
DEBUG("value(%s), new_value(%s)", value, buff);
|
BBF_DEBUG("value(%s), new_value(%s)", value, buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool handle_string(char *v1, char *v2, enum operation op, int *fault)
|
static bool handle_string(char *v1, char *v2, enum operation op, int *fault)
|
||||||
|
|
@ -542,7 +543,7 @@ static bool check_values(char *val_type, char *val1, char *val2, enum operation
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
DEBUG("type(%s), val1(%s), Val2(%s), Oper(%d)", val_type, val1, val2, oper);
|
BBF_DEBUG("type(%s), val1(%s), Val2(%s), Oper(%d)", val_type, val1, val2, oper);
|
||||||
switch (get_dm_type(val_type)) {
|
switch (get_dm_type(val_type)) {
|
||||||
case DMT_STRING:
|
case DMT_STRING:
|
||||||
result = handle_string(val1, val2, oper, fault);
|
result = handle_string(val1, val2, oper, fault);
|
||||||
|
|
@ -648,7 +649,7 @@ static int solve_all_filters(struct dmctx *bbf_ctx, char *bPath, char *param, st
|
||||||
LIST_HEAD(pv_local);
|
LIST_HEAD(pv_local);
|
||||||
LIST_HEAD(plist_local);
|
LIST_HEAD(plist_local);
|
||||||
|
|
||||||
INFO("## Basepath(%s), param(%s)", bPath, param);
|
BBF_INFO("## Basepath(%s), param(%s)", bPath, param);
|
||||||
|
|
||||||
// Use shorter list for rest of the operation
|
// Use shorter list for rest of the operation
|
||||||
blen = DM_STRLEN(bPath);
|
blen = DM_STRLEN(bPath);
|
||||||
|
|
@ -682,7 +683,7 @@ static int solve_all_filters(struct dmctx *bbf_ctx, char *bPath, char *param, st
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
INFO("Filter Para(%s), oper(%d), Val(%s)", para, oper, value);
|
BBF_INFO("Filter Para(%s), oper(%d), Val(%s)", para, oper, value);
|
||||||
|
|
||||||
if (match(para, "[*]+", 0, NULL))
|
if (match(para, "[*]+", 0, NULL))
|
||||||
ret = USP_FAULT_INVALID_TYPE;
|
ret = USP_FAULT_INVALID_TYPE;
|
||||||
|
|
@ -743,7 +744,7 @@ static int resolve_path(struct dmctx *bbf_ctx, char *qPath, size_t pos, struct l
|
||||||
if (list_empty(resolved_plist))
|
if (list_empty(resolved_plist))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
INFO("Entry Len :: %d & qPath :: %s", start, qPath);
|
BBF_INFO("Entry Len :: %zu & qPath :: %s", start, qPath);
|
||||||
|
|
||||||
if (strchr(qPath+start, '.') != NULL)
|
if (strchr(qPath+start, '.') != NULL)
|
||||||
non_leaf = true;
|
non_leaf = true;
|
||||||
|
|
@ -752,7 +753,7 @@ static int resolve_path(struct dmctx *bbf_ctx, char *qPath, size_t pos, struct l
|
||||||
return USP_FAULT_INVALID_PATH_SYNTAX;
|
return USP_FAULT_INVALID_PATH_SYNTAX;
|
||||||
|
|
||||||
plen = DM_STRLEN(param);
|
plen = DM_STRLEN(param);
|
||||||
DEBUG("PARAM ::(%s) pos ::(%d)", param, start);
|
BBF_DEBUG("PARAM ::(%s) pos ::(%zu)", param, start);
|
||||||
|
|
||||||
fault = 0;
|
fault = 0;
|
||||||
list_for_each_entry(ptr, resolved_plist, list) {
|
list_for_each_entry(ptr, resolved_plist, list) {
|
||||||
|
|
@ -804,7 +805,7 @@ int get_resolved_paths(struct dmctx *bbf_ctx, char *qpath, struct list_head *res
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
|
|
||||||
pos = strlen(bpath);
|
pos = strlen(bpath);
|
||||||
INFO("Base Path :: |%s| Pos :: |%d|", bpath, pos);
|
BBF_INFO("Base Path :: |%s| Pos :: |%zu|", bpath, pos);
|
||||||
|
|
||||||
bbf_ctx->in_param = bpath;
|
bbf_ctx->in_param = bpath;
|
||||||
|
|
||||||
|
|
@ -815,12 +816,12 @@ int get_resolved_paths(struct dmctx *bbf_ctx, char *qpath, struct list_head *res
|
||||||
fault = resolve_path(bbf_ctx, qpath, pos, resolved_paths);
|
fault = resolve_path(bbf_ctx, qpath, pos, resolved_paths);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
INFO("Not able to get base path");
|
BBF_INFO("Not able to get base path");
|
||||||
fault = bbf_fault_map(bbf_ctx, FAULT_9005);
|
fault = bbf_fault_map(bbf_ctx, FAULT_9005);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fault)
|
if (fault)
|
||||||
WARNING("qpath(%s), fault(%d)", qpath, fault);
|
BBF_WARNING("qpath(%s), fault(%d)", qpath, fault);
|
||||||
|
|
||||||
return fault;
|
return fault;
|
||||||
}
|
}
|
||||||
|
|
@ -852,7 +853,7 @@ void bbfdm_get_value(bbfdm_data_t *data, void *output)
|
||||||
data->bbf_ctx.in_param = pn->path;
|
data->bbf_ctx.in_param = pn->path;
|
||||||
fill_err_code_table(data, fault);
|
fill_err_code_table(data, fault);
|
||||||
} else {
|
} else {
|
||||||
INFO("Preparing result for(%s)", pn->path);
|
BBF_INFO("Preparing result for(%s)", pn->path);
|
||||||
|
|
||||||
data->bbf_ctx.in_param = pn->path;
|
data->bbf_ctx.in_param = pn->path;
|
||||||
|
|
||||||
|
|
@ -871,7 +872,7 @@ void bbfdm_get_value(bbfdm_data_t *data, void *output)
|
||||||
blobmsg_close_array(&data->bb, array);
|
blobmsg_close_array(&data->bb, array);
|
||||||
|
|
||||||
if (!validate_msglen(data))
|
if (!validate_msglen(data))
|
||||||
ERR("IPC failed for path(%s)", data->bbf_ctx.in_param);
|
BBF_ERR("IPC failed for path(%s)", data->bbf_ctx.in_param);
|
||||||
|
|
||||||
if (output)
|
if (output)
|
||||||
memcpy(output, data->bb.head, blob_pad_len(data->bb.head));
|
memcpy(output, data->bb.head, blob_pad_len(data->bb.head));
|
||||||
|
|
@ -1,9 +1,6 @@
|
||||||
#ifndef GET_H
|
#ifndef GET_H
|
||||||
#define GET_H
|
#define GET_H
|
||||||
|
|
||||||
#include "bbfdmd.h"
|
|
||||||
#include "common.h"
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
DM_GET_PATH,
|
DM_GET_PATH,
|
||||||
DM_GET_PATHS,
|
DM_GET_PATHS,
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
#include "pretty_print.h"
|
#include "pretty_print.h"
|
||||||
|
|
||||||
DMOBJ *DEAMON_DM_ROOT_OBJ = NULL;
|
DMOBJ *DEAMON_DM_ROOT_OBJ = NULL;
|
||||||
|
DM_MAP_OBJ *INTERNAL_ROOT_TREE = NULL;
|
||||||
|
|
||||||
static jmp_buf gs_jump_location;
|
static jmp_buf gs_jump_location;
|
||||||
static bool gs_jump_called_by_bbf = false;
|
static bool gs_jump_called_by_bbf = false;
|
||||||
|
|
@ -29,7 +30,7 @@ void handle_pending_signal(int sig)
|
||||||
siglongjmp(gs_jump_location, 1);
|
siglongjmp(gs_jump_location, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
ERR("Exception [%d] not cause by bbf dm, exit with error", sig);
|
BBF_ERR("Exception [%d] not cause by bbf dm, exit with error", sig);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -44,10 +45,10 @@ int bbfdm_cmd_exec(struct dmctx *bbf_ctx, int cmd)
|
||||||
gs_jump_called_by_bbf = true;
|
gs_jump_called_by_bbf = true;
|
||||||
fault = bbf_entry_method(bbf_ctx, cmd);
|
fault = bbf_entry_method(bbf_ctx, cmd);
|
||||||
} else {
|
} else {
|
||||||
ERR("PID [%ld]::Exception on [%d => %s]", getpid(), cmd, bbf_ctx->in_param);
|
BBF_ERR("PID [%d]::Exception on [%d => %s]", getpid(), cmd, bbf_ctx->in_param);
|
||||||
fault = USP_FAULT_INTERNAL_ERROR;
|
fault = USP_FAULT_INTERNAL_ERROR;
|
||||||
if (is_micro_service) {
|
if (dm_is_micro_service()) {
|
||||||
ERR("Micro-service PID [%ld]::Exception on [%d => %s]", getpid(), cmd, bbf_ctx->in_param);
|
BBF_ERR("Micro-service PID [%d]::Exception on [%d => %s]", getpid(), cmd, bbf_ctx->in_param);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -55,7 +56,7 @@ int bbfdm_cmd_exec(struct dmctx *bbf_ctx, int cmd)
|
||||||
gs_jump_called_by_bbf = false;
|
gs_jump_called_by_bbf = false;
|
||||||
|
|
||||||
if (fault)
|
if (fault)
|
||||||
WARNING("Fault [%d => %d => %s]", fault, cmd, bbf_ctx->in_param);
|
BBF_WARNING("Fault [%d => %d => %s]", fault, cmd, bbf_ctx->in_param);
|
||||||
|
|
||||||
return fault;
|
return fault;
|
||||||
}
|
}
|
||||||
|
|
@ -104,7 +105,7 @@ void add_pv_list(char *para, char *val, char *type, struct list_head *pv_list)
|
||||||
node = (struct pvNode *) malloc(sizeof(*node));
|
node = (struct pvNode *) malloc(sizeof(*node));
|
||||||
|
|
||||||
if (!node) {
|
if (!node) {
|
||||||
ERR("Out of memory!");
|
BBF_ERR("Out of memory!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -138,7 +139,7 @@ void add_path_list(char *param, struct list_head *plist)
|
||||||
node = (struct pathNode *)calloc(1, sizeof(*node));
|
node = (struct pathNode *)calloc(1, sizeof(*node));
|
||||||
|
|
||||||
if (!node) {
|
if (!node) {
|
||||||
ERR("Out of memory!");
|
BBF_ERR("Out of memory!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
#ifndef GET_HELPER_H
|
#ifndef GET_HELPER_H
|
||||||
#define GET_HELPER_H
|
#define GET_HELPER_H
|
||||||
|
|
||||||
#include "bbfdmd.h"
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
#include <libubus.h>
|
#include <libubus.h>
|
||||||
|
|
@ -1,9 +1,6 @@
|
||||||
#ifndef OPERATE_H
|
#ifndef OPERATE_H
|
||||||
#define OPERATE_H
|
#define OPERATE_H
|
||||||
|
|
||||||
#include "bbfdmd.h"
|
|
||||||
#include "common.h"
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
DM_OPERATE_COMMAND,
|
DM_OPERATE_COMMAND,
|
||||||
DM_OPERATE_COMMAND_KEY,
|
DM_OPERATE_COMMAND_KEY,
|
||||||
|
|
@ -62,33 +62,38 @@ static void fill_dotso_micro_service_out_args(bbfdm_config_t *config, DMOBJ *ent
|
||||||
int load_dotso_plugin(void **lib_handle, const char *file_path, bbfdm_config_t *config, DMOBJ **main_entry)
|
int load_dotso_plugin(void **lib_handle, const char *file_path, bbfdm_config_t *config, DMOBJ **main_entry)
|
||||||
{
|
{
|
||||||
if (!lib_handle || !file_path || !strlen(file_path) || !main_entry) {
|
if (!lib_handle || !file_path || !strlen(file_path) || !main_entry) {
|
||||||
ERR("Input validation failed\n");
|
BBF_ERR("Input validation failed\n");
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *handle = dlopen(file_path, RTLD_NOW|RTLD_LOCAL);
|
|
||||||
if (!handle) {
|
|
||||||
ERR("Plugin failed [%s]\n", dlerror());
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
dm_dynamic_initmem(&plugin_mem);
|
dm_dynamic_initmem(&plugin_mem);
|
||||||
|
DM_MAP_OBJ *dynamic_obj = NULL;
|
||||||
|
|
||||||
|
if (strcmp(file_path, "internal_dm.so") == 0) {
|
||||||
|
dynamic_obj = INTERNAL_ROOT_TREE;
|
||||||
|
} else {
|
||||||
|
void *handle = dlopen(file_path, RTLD_NOW|RTLD_LOCAL);
|
||||||
|
if (!handle) {
|
||||||
|
BBF_ERR("Plugin failed [%s]\n", dlerror());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
*lib_handle = handle;
|
*lib_handle = handle;
|
||||||
|
|
||||||
//Dynamic Object
|
//Dynamic Object
|
||||||
DM_MAP_OBJ *dynamic_obj = NULL;
|
|
||||||
*(void **) (&dynamic_obj) = dlsym(handle, "tDynamicObj");
|
*(void **) (&dynamic_obj) = dlsym(handle, "tDynamicObj");
|
||||||
|
}
|
||||||
|
|
||||||
if (dynamic_obj) {
|
if (dynamic_obj) {
|
||||||
uint8_t obj_num = find_number_of_objects(dynamic_obj);
|
uint8_t obj_num = find_number_of_objects(dynamic_obj);
|
||||||
if (obj_num == 0) {
|
if (obj_num == 0) {
|
||||||
ERR("No Object defined in the required DotSo Plugin\n");
|
BBF_ERR("No Object defined in the required DotSo Plugin\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
DMOBJ *dm_entryobj = (DMOBJ *)dm_dynamic_calloc(&plugin_mem, obj_num + 1, sizeof(DMOBJ));
|
DMOBJ *dm_entryobj = (DMOBJ *)dm_dynamic_calloc(&plugin_mem, obj_num + 1, sizeof(DMOBJ));
|
||||||
if (dm_entryobj == NULL) {
|
if (dm_entryobj == NULL) {
|
||||||
ERR("No Memory exists\n");
|
BBF_ERR("No Memory exists\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -99,12 +104,12 @@ int load_dotso_plugin(void **lib_handle, const char *file_path, bbfdm_config_t *
|
||||||
unsigned int len = strlen(node_obj);
|
unsigned int len = strlen(node_obj);
|
||||||
|
|
||||||
if (strncmp(node_obj, ROOT_NODE, strlen(ROOT_NODE)) != 0 || node_obj[len-1] != '.') {
|
if (strncmp(node_obj, ROOT_NODE, strlen(ROOT_NODE)) != 0 || node_obj[len-1] != '.') {
|
||||||
ERR("Object (%s) not valid\n", node_obj);
|
BBF_ERR("Object (%s) not valid\n", node_obj);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill out arguments if it is running as micro-service
|
// Fill out arguments if it is running as micro-service
|
||||||
if (is_micro_service == true)
|
if (dm_is_micro_service() == true)
|
||||||
fill_dotso_micro_service_out_args(config, dynamic_obj[i].root_obj, node_obj, &out_obj_idx);
|
fill_dotso_micro_service_out_args(config, dynamic_obj[i].root_obj, node_obj, &out_obj_idx);
|
||||||
|
|
||||||
node_obj[len-1] = 0;
|
node_obj[len-1] = 0;
|
||||||
|
|
@ -118,7 +123,7 @@ int load_dotso_plugin(void **lib_handle, const char *file_path, bbfdm_config_t *
|
||||||
|
|
||||||
*main_entry = dm_entryobj;
|
*main_entry = dm_entryobj;
|
||||||
} else {
|
} else {
|
||||||
ERR("Main entry not available");
|
BBF_ERR("Main entry not available");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -159,13 +164,13 @@ int load_json_plugin(struct list_head *json_plugin, struct list_head *json_list,
|
||||||
uint8_t idx = 0;
|
uint8_t idx = 0;
|
||||||
|
|
||||||
if (!file_path || !strlen(file_path) || !main_entry) {
|
if (!file_path || !strlen(file_path) || !main_entry) {
|
||||||
ERR("Entry validation failed ...");
|
BBF_ERR("Entry validation failed ...");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
json_object *json_obj = json_object_from_file(file_path);
|
json_object *json_obj = json_object_from_file(file_path);
|
||||||
if (!json_obj) {
|
if (!json_obj) {
|
||||||
ERR("Failed to parse json file (%s)", file_path);
|
BBF_ERR("Failed to parse json file (%s)", file_path);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -181,12 +186,12 @@ int load_json_plugin(struct list_head *json_plugin, struct list_head *json_list,
|
||||||
|
|
||||||
replace_str(key, "{BBF_VENDOR_PREFIX}", BBF_VENDOR_PREFIX, node_obj, sizeof(node_obj));
|
replace_str(key, "{BBF_VENDOR_PREFIX}", BBF_VENDOR_PREFIX, node_obj, sizeof(node_obj));
|
||||||
if (strlen(node_obj) == 0) {
|
if (strlen(node_obj) == 0) {
|
||||||
ERR("ERROR: Can't get the node object\n");
|
BBF_ERR("ERROR: Can't get the node object\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strncmp(node_obj, ROOT_NODE, strlen(ROOT_NODE)) != 0 || node_obj[strlen(node_obj) - 1] != '.') {
|
if (strncmp(node_obj, ROOT_NODE, strlen(ROOT_NODE)) != 0 || node_obj[strlen(node_obj) - 1] != '.') {
|
||||||
ERR("ERROR: Object (%s) not valid\n", node_obj);
|
BBF_ERR("ERROR: Object (%s) not valid\n", node_obj);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -195,19 +200,19 @@ int load_json_plugin(struct list_head *json_plugin, struct list_head *json_list,
|
||||||
|
|
||||||
int obj_prefix_len = strlen(obj_prefix);
|
int obj_prefix_len = strlen(obj_prefix);
|
||||||
if (obj_prefix_len == 0) {
|
if (obj_prefix_len == 0) {
|
||||||
ERR("ERROR: Obj prefix is empty for (%s) Object\n", node_obj);
|
BBF_ERR("ERROR: Obj prefix is empty for (%s) Object\n", node_obj);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char obj_name[64] = {0};
|
char obj_name[64] = {0};
|
||||||
json_plugin_find_current_obj(node_obj, obj_name, sizeof(obj_name));
|
json_plugin_find_current_obj(node_obj, obj_name, sizeof(obj_name));
|
||||||
if (strlen(obj_name) == 0) {
|
if (strlen(obj_name) == 0) {
|
||||||
ERR("ERROR: Obj name is empty for (%s) Object\n", node_obj);
|
BBF_ERR("ERROR: Obj name is empty for (%s) Object\n", node_obj);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill out arguments if it is running as micro-service
|
// Fill out arguments if it is running as micro-service
|
||||||
if (is_micro_service == true)
|
if (dm_is_micro_service() == true)
|
||||||
fill_json_micro_service_out_args(config, obj_prefix, obj_name, idx, ms_name, sizeof(ms_name));
|
fill_json_micro_service_out_args(config, obj_prefix, obj_name, idx, ms_name, sizeof(ms_name));
|
||||||
|
|
||||||
// Remove '.' from object prefix
|
// Remove '.' from object prefix
|
||||||
|
|
@ -216,7 +221,7 @@ int load_json_plugin(struct list_head *json_plugin, struct list_head *json_list,
|
||||||
|
|
||||||
dm_entryobj = (DMOBJ *)dm_dynamic_realloc(json_memhead, dm_entryobj, (idx + 2) * sizeof(DMOBJ));
|
dm_entryobj = (DMOBJ *)dm_dynamic_realloc(json_memhead, dm_entryobj, (idx + 2) * sizeof(DMOBJ));
|
||||||
if (dm_entryobj == NULL) {
|
if (dm_entryobj == NULL) {
|
||||||
ERR("ERROR: No Memory exists\n");
|
BBF_ERR("ERROR: No Memory exists\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -21,7 +21,7 @@ struct resultstack {
|
||||||
|
|
||||||
static bool is_search_by_reference(char *path)
|
static bool is_search_by_reference(char *path)
|
||||||
{
|
{
|
||||||
DEBUG("Entry |%s|", path);
|
BBF_DEBUG("Entry |%s|", path);
|
||||||
if (match(path, "[+]+", 0, NULL)) {
|
if (match(path, "[+]+", 0, NULL)) {
|
||||||
size_t pindex = 0, bindex = 0;
|
size_t pindex = 0, bindex = 0;
|
||||||
char *last_plus, *last_bracket;
|
char *last_plus, *last_bracket;
|
||||||
|
|
@ -46,7 +46,7 @@ static bool is_search_by_reference(char *path)
|
||||||
static bool is_res_required(char *str, size_t *start, size_t *len)
|
static bool is_res_required(char *str, size_t *start, size_t *len)
|
||||||
{
|
{
|
||||||
|
|
||||||
DEBUG("Entry |%s|", str);
|
BBF_DEBUG("Entry |%s|", str);
|
||||||
if (match(str, GLOB_CHAR, 0, NULL)) {
|
if (match(str, GLOB_CHAR, 0, NULL)) {
|
||||||
size_t s_len, b_len, p_len;
|
size_t s_len, b_len, p_len;
|
||||||
char *star, *b_start, *b_end, *plus;
|
char *star, *b_start, *b_end, *plus;
|
||||||
|
|
@ -106,7 +106,7 @@ static size_t get_glob_len(char *path)
|
||||||
char temp_name[MAX_DM_KEY_LEN] = {'\0'};
|
char temp_name[MAX_DM_KEY_LEN] = {'\0'};
|
||||||
char *end = NULL;
|
char *end = NULL;
|
||||||
|
|
||||||
DEBUG("Entry");
|
BBF_DEBUG("Entry");
|
||||||
if (is_res_required(path, &m_index, &m_len)) {
|
if (is_res_required(path, &m_index, &m_len)) {
|
||||||
if (m_index <= MAX_DM_KEY_LEN)
|
if (m_index <= MAX_DM_KEY_LEN)
|
||||||
snprintf(temp_name, m_index, "%s", path);
|
snprintf(temp_name, m_index, "%s", path);
|
||||||
|
|
@ -190,7 +190,7 @@ static void add_data_blob(struct blob_buf *bb, char *param, char *value, char *t
|
||||||
if (param == NULL || value == NULL || type == NULL)
|
if (param == NULL || value == NULL || type == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
DEBUG("# Adding BLOB (%s)::(%s)", param, value);
|
BBF_DEBUG("# Adding BLOB (%s)::(%s)", param, value);
|
||||||
switch (get_dm_type(type)) {
|
switch (get_dm_type(type)) {
|
||||||
case DMT_UNINT:
|
case DMT_UNINT:
|
||||||
blobmsg_add_u64(bb, param, (uint32_t)strtoul(value, NULL, 10));
|
blobmsg_add_u64(bb, param, (uint32_t)strtoul(value, NULL, 10));
|
||||||
|
|
@ -230,7 +230,7 @@ static void free_result_list(struct list_head *head)
|
||||||
static void free_result_node(struct resultstack *rnode)
|
static void free_result_node(struct resultstack *rnode)
|
||||||
{
|
{
|
||||||
if (rnode) {
|
if (rnode) {
|
||||||
DEBUG("## ResStack DEL(%s)", rnode->key);
|
BBF_DEBUG("## ResStack DEL(%s)", rnode->key);
|
||||||
free(rnode->key);
|
free(rnode->key);
|
||||||
list_del(&rnode->list);
|
list_del(&rnode->list);
|
||||||
free(rnode);
|
free(rnode);
|
||||||
|
|
@ -243,13 +243,13 @@ static void add_result_node(struct list_head *rlist, char *key, char *cookie)
|
||||||
|
|
||||||
rnode = (struct resultstack *) malloc(sizeof(*rnode));
|
rnode = (struct resultstack *) malloc(sizeof(*rnode));
|
||||||
if (!rnode) {
|
if (!rnode) {
|
||||||
ERR("Out of memory!");
|
BBF_ERR("Out of memory!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
rnode->key = (key) ? strdup(key) : strdup("");
|
rnode->key = (key) ? strdup(key) : strdup("");
|
||||||
rnode->cookie = cookie;
|
rnode->cookie = cookie;
|
||||||
DEBUG("## ResSTACK ADD (%s) ##", rnode->key);
|
BBF_DEBUG("## ResSTACK ADD (%s) ##", rnode->key);
|
||||||
|
|
||||||
INIT_LIST_HEAD(&rnode->list);
|
INIT_LIST_HEAD(&rnode->list);
|
||||||
list_add(&rnode->list, rlist);
|
list_add(&rnode->list, rlist);
|
||||||
|
|
@ -362,7 +362,7 @@ void prepare_result_blob(struct blob_buf *bb, struct list_head *pv_list)
|
||||||
pv = &sortedPV[i];
|
pv = &sortedPV[i];
|
||||||
ptr = pv->param;
|
ptr = pv->param;
|
||||||
if (list_empty(&result_stack)) {
|
if (list_empty(&result_stack)) {
|
||||||
DEBUG("stack empty Processing (%s)", ptr);
|
BBF_DEBUG("stack empty Processing (%s)", ptr);
|
||||||
add_paths_to_stack(bb, pv->param, 0, pv, &result_stack);
|
add_paths_to_stack(bb, pv->param, 0, pv, &result_stack);
|
||||||
} else {
|
} else {
|
||||||
bool is_done = false;
|
bool is_done = false;
|
||||||
|
|
@ -373,12 +373,12 @@ void prepare_result_blob(struct blob_buf *bb, struct list_head *pv_list)
|
||||||
len = DM_STRLEN(rnode->key);
|
len = DM_STRLEN(rnode->key);
|
||||||
ptr = ptr + len;
|
ptr = ptr + len;
|
||||||
|
|
||||||
DEBUG("GROUP (%s), ptr(%s), len(%d)", pv->param, ptr, len);
|
BBF_DEBUG("GROUP (%s), ptr(%s), len(%zu)", pv->param, ptr, len);
|
||||||
add_paths_to_stack(bb, pv->param, len, pv, &result_stack);
|
add_paths_to_stack(bb, pv->param, len, pv, &result_stack);
|
||||||
is_done = true;
|
is_done = true;
|
||||||
} else {
|
} else {
|
||||||
// Get the latest entry before deleting it
|
// Get the latest entry before deleting it
|
||||||
DEBUG("DIFF GROUP pv(%s), param(%s)", pv->param, ptr);
|
BBF_DEBUG("DIFF GROUP pv(%s), param(%s)", pv->param, ptr);
|
||||||
blobmsg_close_table(bb, rnode->cookie);
|
blobmsg_close_table(bb, rnode->cookie);
|
||||||
free_result_node(rnode);
|
free_result_node(rnode);
|
||||||
if (list_empty(&result_stack)) {
|
if (list_empty(&result_stack)) {
|
||||||
|
|
@ -432,12 +432,12 @@ void prepare_pretty_result(uint8_t maxdepth, struct blob_buf *bb, struct dmctx *
|
||||||
|
|
||||||
LIST_HEAD(pv_local);
|
LIST_HEAD(pv_local);
|
||||||
|
|
||||||
DEBUG("################### DATA to PROCESS ##################");
|
BBF_DEBUG("################### DATA to PROCESS ##################");
|
||||||
list_for_each_entry(iter, rslvd, list) {
|
list_for_each_entry(iter, rslvd, list) {
|
||||||
DEBUG("## %s ##", iter->path);
|
BBF_DEBUG("## %s ##", iter->path);
|
||||||
resulting(maxdepth, iter->path, bbf_ctx, &pv_local);
|
resulting(maxdepth, iter->path, bbf_ctx, &pv_local);
|
||||||
}
|
}
|
||||||
DEBUG("######################################################");
|
BBF_DEBUG("######################################################");
|
||||||
|
|
||||||
prepare_result_blob(bb, &pv_local);
|
prepare_result_blob(bb, &pv_local);
|
||||||
|
|
||||||
|
|
@ -9,8 +9,8 @@
|
||||||
* See LICENSE file for license related information.
|
* See LICENSE file for license related information.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "set.h"
|
|
||||||
#include "get_helper.h"
|
#include "get_helper.h"
|
||||||
|
#include "set.h"
|
||||||
|
|
||||||
#include <libubus.h>
|
#include <libubus.h>
|
||||||
|
|
||||||
|
|
@ -116,7 +116,7 @@ blob__table:
|
||||||
snprintf(value, MAX_DM_VALUE, "%"PRIu64"", blobmsg_get_u64(attr));
|
snprintf(value, MAX_DM_VALUE, "%"PRIu64"", blobmsg_get_u64(attr));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
INFO("Unhandled set request type|%x|", blob_id(attr));
|
BBF_INFO("Unhandled set request type|%x|", blob_id(attr));
|
||||||
return USP_FAULT_INVALID_ARGUMENT;
|
return USP_FAULT_INVALID_ARGUMENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1,9 +1,6 @@
|
||||||
#ifndef SET_H
|
#ifndef SET_H
|
||||||
#define SET_H
|
#define SET_H
|
||||||
|
|
||||||
#include "bbfdmd.h"
|
|
||||||
#include "common.h"
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
DM_SET_PATH,
|
DM_SET_PATH,
|
||||||
DM_SET_VALUE,
|
DM_SET_VALUE,
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"daemon": {
|
"daemon": {
|
||||||
"config": {
|
"config": {
|
||||||
"loglevel": "4",
|
"loglevel": "3",
|
||||||
"subprocess_level": "2"
|
"subprocess_level": "2"
|
||||||
},
|
},
|
||||||
"input": {
|
"input": {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue