all clixon event functions prepended with clixon_

Replaced fcgi getparam code with clixon-data parameters
This commit is contained in:
Olof hagsand 2020-06-05 16:19:03 +02:00
parent a455b15f03
commit 14b03f63a3
34 changed files with 567 additions and 877 deletions

View file

@ -2,7 +2,9 @@
*
***** BEGIN LICENSE BLOCK *****
Copyright (C) 2009-2019 Olof Hagsand and Benny Holmgren
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
Copyright (C) 2017-2019 Olof Hagsand
Copyright (C) 2020 Olof Hagsand and Rubicon Communications, LLC(Netgate)
This file is part of CLIXON.
@ -35,6 +37,7 @@
* Access functions for clixon data.
* Free-typed values for runtime getting and setting.
* Accessed with clicon_data(h).
* @see clixon_option.[ch] for clixon options
*/
#ifdef HAVE_CONFIG_H
#include "clixon_config.h" /* generated by config & autoconf */
@ -75,8 +78,66 @@
#include "clixon_xpath.h"
#include "clixon_data.h"
/*! Get YANG specification for application specs
* Must use hash functions directly since they are not strings.
/*! Get generic clixon data on the form <name>=<val> where <val> is string
* @param[in] h Clicon handle
* @param[in] name Data name
* @param[out] val Data value as string
* @retval 0 OK
* @retval -1 Not found
* @see clicon_option_str
*/
int
clicon_data_get(clicon_handle h,
char *name,
char **val)
{
clicon_hash_t *cdat = clicon_data(h);
if (val == NULL){
clicon_err(OE_CFG, EINVAL, "%s val is NULL", __FUNCTION__);
return -1;
}
if (clicon_hash_lookup(cdat, (char*)name) == NULL)
return -1;
*val = clicon_hash_value(cdat, (char*)name, NULL);
return 0;
}
/*! Set generic clixon data on the form <name>=<val> where <val> is string
* @param[in] h Clicon handle
* @param[in] name Data name
* @param[in] val Data value as null-terminated string
* @retval 0 OK
* @retval -1 Error
* @see clicon_option_str_set
*/
int
clicon_data_set(clicon_handle h,
char *name,
char *val)
{
clicon_hash_t *cdat = clicon_data(h);
return clicon_hash_add(cdat, (char*)name, val, strlen(val)+1)==NULL?-1:0;
}
/*! Delete generic clixon data
* @param[in] h Clicon handle
* @param[in] name Data name
* @retval 0 OK
* @retval -1 Error
* @see clicon_option_del
*/
int
clicon_data_del(clicon_handle h,
char *name)
{
clicon_hash_t *cdat = clicon_data(h);
return clicon_hash_del(cdat, (char*)name);
}
/*!
* @param[in] h Clicon handle
* @retval yspec Yang spec
* @see clicon_config_yang for the configuration yang
@ -655,3 +716,4 @@ clicon_session_id_set(clicon_handle h,
clicon_hash_add(cdat, "session-id", &id, sizeof(uint32_t));
return 0;
}

View file

@ -2,7 +2,9 @@
*
***** BEGIN LICENSE BLOCK *****
Copyright (C) 2009-2019 Olof Hagsand and Benny Holmgren
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
Copyright (C) 2017-2019 Olof Hagsand
Copyright (C) 2020 Olof Hagsand and Rubicon Communications, LLC(Netgat)e
This file is part of CLIXON.
@ -80,7 +82,7 @@ struct event_data{
static struct event_data *ee = NULL;
static struct event_data *ee_timers = NULL;
/* Set if element in ee is deleted (event_unreg_fd). Check in ee loops */
/* Set if element in ee is deleted (clixon_event_unreg_fd). Check in ee loops */
static int _ee_unreg = 0;
static int _clicon_exit = 0;
@ -123,14 +125,14 @@ clicon_exit_get(void)
* @code
* int fn(int fd, void *arg){
* }
* event_reg_fd(fd, fn, (void*)42, "call fn on input on fd");
* clixon_event_reg_fd(fd, fn, (void*)42, "call fn on input on fd");
* @endcode
*/
int
event_reg_fd(int fd,
int (*fn)(int, void*),
void *arg,
char *str)
clixon_event_reg_fd(int fd,
int (*fn)(int, void*),
void *arg,
char *str)
{
struct event_data *e;
@ -154,12 +156,12 @@ event_reg_fd(int fd,
* @param[in] s File descriptor
* @param[in] fn Function to call when input available on fd
* Note: deregister when exactly function and socket match, not argument
* @see event_reg_fd
* @see event_unreg_timeout
* @see clixon_event_reg_fd
* @see clixon_event_unreg_timeout
*/
int
event_unreg_fd(int s,
int (*fn)(int, void*))
clixon_event_unreg_fd(int s,
int (*fn)(int, void*))
{
struct event_data *e, **e_prev;
int found = 0;
@ -189,7 +191,7 @@ event_unreg_fd(int s,
* gettimeofday(&t, NULL);
* t1.tv_sec = 1; t1.tv_usec = 0;
* timeradd(&t, &t1, &t);
* event_reg_timeout(t, fn, NULL, "call every second");
* clixon_event_reg_timeout(t, fn, NULL, "call every second");
* }
* @endcode
*
@ -198,14 +200,14 @@ event_unreg_fd(int s,
* registration for each period, see example above.
* Note also that the first argument to fn is a dummy, just to get the same
* signatute as for file-descriptor callbacks.
* @see event_reg_fd
* @see event_unreg_timeout
* @see clixon_event_reg_fd
* @see clixon_event_unreg_timeout
*/
int
event_reg_timeout(struct timeval t,
int (*fn)(int, void*),
void *arg,
char *str)
clixon_event_reg_timeout(struct timeval t,
int (*fn)(int, void*),
void *arg,
char *str)
{
struct event_data *e, *e1, **e_prev;
@ -228,22 +230,22 @@ event_reg_timeout(struct timeval t,
}
e->e_next = e1;
*e_prev = e;
clicon_debug(2, "event_reg_timeout: %s", str);
clicon_debug(2, "%s: %s", __FUNCTION__, str);
return 0;
}
/*! Deregister a timeout callback as previosly registered by event_reg_timeout()
/*! Deregister a timeout callback as previosly registered by clixon_event_reg_timeout()
* Note: deregister when exactly function and function arguments match, not time. So you
* cannot have same function and argument callback on different timeouts. This is a little
* different from event_unreg_fd.
* different from clixon_event_unreg_fd.
* @param[in] fn Function to call at time t
* @param[in] arg Argument to function fn
* @see event_reg_timeout
* @see event_unreg_fd
* @see clixon_event_reg_timeout
* @see clixon_event_unreg_fd
*/
int
event_unreg_timeout(int (*fn)(int, void*),
void *arg)
clixon_event_unreg_timeout(int (*fn)(int, void*),
void *arg)
{
struct event_data *e, **e_prev;
int found = 0;
@ -268,7 +270,7 @@ event_unreg_timeout(int (*fn)(int, void*),
* @retval 1 Something to read on fd
*/
int
event_poll(int fd)
clixon_event_poll(int fd)
{
int retval = -1;
fd_set fdset;
@ -288,7 +290,7 @@ event_poll(int fd)
* @retval -1 Error: eg select, callback, timer,
*/
int
event_loop(void)
clixon_event_loop(void)
{
struct event_data *e;
struct event_data *e_next;
@ -363,7 +365,7 @@ event_loop(void)
}
int
event_exit(void)
clixon_event_exit(void)
{
struct event_data *e, *e_next;

View file

@ -37,9 +37,7 @@
* This file contains access functions for two types of clixon vars:
* - options, ie string based variables from Clixon configuration files.
* Accessed with clicon_options(h).
* - data. Free-typed values for runtime getting and setting.
* Accessed with clicon_data(h).
* Consider splitting?
* @see clixon_data.[ch] for free-type runtime get/set
*/
#ifdef HAVE_CONFIG_H
#include "clixon_config.h" /* generated by config & autoconf */

View file

@ -230,7 +230,7 @@ stream_get_xml(clicon_handle h,
/*! Check all stream subscription stop timers, set up new timer
* @param[in] fd No-op
* @param[in] arg Clicon handle
* @note format is given by event_reg_timeout callback function (fd not needed)
* @note format is given by clixon_event_reg_timeout callback function (fd not needed)
*/
int
stream_timer_setup(int fd,
@ -295,7 +295,7 @@ stream_timer_setup(int fd,
}
/* Initiate new timer */
timeradd(&now, &t1, &t);
if (event_reg_timeout(t,
if (clixon_event_reg_timeout(t,
stream_timer_setup, /* this function */
h, /* clicon handle */
"stream timer setup") < 0)
@ -841,7 +841,7 @@ stream_replay_trigger(clicon_handle h,
ra->ra_fn = fn;
ra->ra_arg = arg;
gettimeofday(&now, NULL);
if (event_reg_timeout(now, stream_replay_cb, ra,
if (clixon_event_reg_timeout(now, stream_replay_cb, ra,
"create-subscribtion stream replay") < 0)
goto done;
retval = 0;

View file

@ -148,6 +148,59 @@ clicon_strjoin(int argc,
return str;
}
/*! Split a string once into two parts: prefix and suffix
* @param[in] string
* @param[in] delim
* @param[out] prefix If non-NULL, return malloced string, or NULL.
* @param[out] suffix If non-NULL, return malloced identifier.
* @retval 0 OK
* @retval -1 Error
* @code
* char *a = NULL;
* char *b = NULL;
* if (clixon_strsplit(nodeid, ':', &a, &b) < 0)
* goto done;
* if (a)
* free(a);
* if (b)
* free(b);
* @note caller need to free prefix and suffix after use
* @see clicon_strsep not just single split
*/
int
clixon_strsplit(char *string,
const int delim,
char **prefix,
char **suffix)
{
int retval = -1;
char *str;
if ((str = strchr(string, delim)) == NULL){
if (suffix && (*suffix = strdup(string)) == NULL){
clicon_err(OE_YANG, errno, "strdup");
goto done;
}
}
else {
if (prefix){
if ((*prefix = strdup(string)) == NULL){
clicon_err(OE_YANG, errno, "strdup");
goto done;
}
(*prefix)[str-string] = '\0';
}
str++;
if (suffix && (*suffix = strdup(str)) == NULL){
clicon_err(OE_YANG, errno, "strdup");
goto done;
}
}
retval = 0;
done:
return retval;
}
static int
uri_unreserved(unsigned char in)
{
@ -676,6 +729,7 @@ clicon_str2int_search(const map_str2int *mstab,
return -1; /* not found */
}
/*! Split colon-separated node identifier into prefix and name
* @param[in] node-id
* @param[out] prefix If non-NULL, return malloced string, or NULL.
@ -698,32 +752,7 @@ nodeid_split(char *nodeid,
char **prefix,
char **id)
{
int retval = -1;
char *str;
if ((str = strchr(nodeid, ':')) == NULL){
if (id && (*id = strdup(nodeid)) == NULL){
clicon_err(OE_YANG, errno, "strdup");
goto done;
}
}
else {
if (prefix){
if ((*prefix = strdup(nodeid)) == NULL){
clicon_err(OE_YANG, errno, "strdup");
goto done;
}
(*prefix)[str-nodeid] = '\0';
}
str++;
if (id && (*id = strdup(str)) == NULL){
clicon_err(OE_YANG, errno, "strdup");
goto done;
}
}
retval = 0;
done:
return retval;
return clixon_strsplit(nodeid, ':', prefix, id);
}
/*! Trim blanks from front and end of a string, return new string