C-style update: Unified comment, retvals in order, remove trailing spaces

Changed function name for `clicon_debug` functions
This commit is contained in:
Olof hagsand 2023-10-22 18:04:47 +02:00
parent 6e314dd96f
commit 62348fc9c7
204 changed files with 6047 additions and 4904 deletions

View file

@ -92,7 +92,7 @@
/*! Find an event notification stream given name
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] name Name of stream
* @retval es Event notification stream structure
* @retval NULL Not found
@ -116,18 +116,20 @@ stream_find(clicon_handle h,
/*! Add notification event stream
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] name Name of stream
* @param[in] description Description of stream
* @param[in] replay_enabled Set if replay possible in stream
* @param[in] retention For replay buffer how much relative to save
* @retval 0 OK
* @retval -1 Error
*/
int
stream_add(clicon_handle h,
const char *name,
const char *name,
const char *description,
const int replay_enabled,
struct timeval *retention)
struct timeval *retention)
{
int retval = -1;
event_stream_t *es;
@ -159,8 +161,9 @@ stream_add(clicon_handle h,
/*! Delete complete notification event stream list (not just single stream)
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] force Force deletion of
* @retval 0 OK
*/
int
stream_delete_all(clicon_handle h,
@ -170,7 +173,7 @@ stream_delete_all(clicon_handle h,
struct stream_subscription *ss;
event_stream_t *es;
event_stream_t *head = clicon_stream(h);
while ((es = clicon_stream(h)) != NULL){
DELQ(es, head, event_stream_t *);
clicon_stream_set(h, head);
@ -193,12 +196,12 @@ stream_delete_all(clicon_handle h,
/*! Return stream definition state in XML supporting RFC 8040 and RFC5277
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] access If set, include access/location
* @param[out] cb Output buffer containing XML on exit
* @retval 0 OK
* @retval -1 Error
*/
*/
int
stream_get_xml(clicon_handle h,
int access,
@ -222,7 +225,7 @@ stream_get_xml(clicon_handle h,
cprintf(cb, "<encoding>xml</encoding>");
url_prefix = clicon_option_str(h, "CLICON_STREAM_URL");
stream_path = clicon_option_str(h, "CLICON_STREAM_PATH");
cprintf(cb, "<location>%s/%s/%s</location>",
cprintf(cb, "<location>%s/%s/%s</location>",
url_prefix, stream_path, es->es_name);
cprintf(cb, "</access>");
}
@ -237,7 +240,9 @@ 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
* @param[in] arg Clixon handle
* @retval 0 OK
* @retval -1 Error
* @note format is given by clixon_event_reg_timeout callback function (fd not needed)
*/
int
@ -255,8 +260,8 @@ stream_timer_setup(int fd,
struct stream_subscription *ss1;
struct stream_replay *r;
struct stream_replay *r1;
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
/* Go thru callbacks and see if any have timed out, if so remove them
* Could also be done by a separate timer.
*/
@ -313,20 +318,9 @@ stream_timer_setup(int fd,
return retval;
}
#ifdef NYI
/*! Delete single notification event stream
* XXX notused
*/
int
stream_del()
{
return 0;
}
#endif
/*! Add an event notification callback to a stream given a callback function
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] stream Name of stream
* @param[in] xpath Filter selector - xpath
* @param[in] startime If set, Make a replay
@ -348,7 +342,7 @@ stream_ss_add(clicon_handle h,
event_stream_t *es;
struct stream_subscription *ss = NULL;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if ((es = stream_find(h, stream)) == NULL){
clicon_err(OE_CFG, ENOENT, "Stream %s not found", stream);
goto done;
@ -382,7 +376,7 @@ stream_ss_add(clicon_handle h,
/*! Delete event stream subscription to a stream given a callback and arg
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] stream Name of stream or NULL for all streams
* @param[in] fn Callback when event occurs
* @param[in] arg Argument to use with callback. Also handle when deleting
@ -395,7 +389,7 @@ stream_ss_rm(clicon_handle h,
struct stream_subscription *ss,
int force)
{
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
DELQ(ss, es->es_subscription, struct stream_subscription *);
/* Remove from upper layers - close socket etc. */
(*ss->ss_fn)(h, 1, NULL, ss->ss_arg);
@ -406,7 +400,7 @@ stream_ss_rm(clicon_handle h,
free(ss->ss_xpath);
free(ss);
}
clicon_debug(1, "%s retval: 0", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval: 0", __FUNCTION__);
return 0;
}
@ -436,9 +430,11 @@ stream_ss_find(event_stream_t *es,
/*! Remove stream subscription identified with fn and arg in all streams
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] fn Stream callback
* @param[in] arg Argument - typically unique client handle
* @retval 0 OK
* @retval -1 Error
* @see stream_ss_delete For single stream
*/
int
@ -458,7 +454,7 @@ stream_ss_delete_all(clicon_handle h,
}
es = NEXTQ(struct event_stream *, es);
} while (es && es != clicon_stream(h));
}
}
retval = 0;
done:
return retval;
@ -466,6 +462,10 @@ stream_ss_delete_all(clicon_handle h,
/*! Delete a single stream
*
* @param[in] h Clixon handle
* @retval 0 OK
* @retval -1 Error
* @see stream_ss_delete_all (merge with this?)
*/
int
@ -487,7 +487,7 @@ stream_ss_delete(clicon_handle h,
}
es = NEXTQ(struct event_stream *, es);
} while (es && es != clicon_stream(h));
}
}
retval = 0;
done:
return retval;
@ -495,7 +495,7 @@ stream_ss_delete(clicon_handle h,
/*! Stream notify event and distribute to all registered callbacks
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] stream Name of event stream. CLICON is predefined as LOG stream
* @param[in] tv Timestamp. Dont notify if subscription has stoptime<tv
* @param[in] event Notification as xml tree
@ -505,15 +505,15 @@ stream_ss_delete(clicon_handle h,
* @see stream_ss_timeout where subscriptions are removed if stoptime<now
*/
static int
stream_notify1(clicon_handle h,
stream_notify1(clicon_handle h,
event_stream_t *es,
struct timeval *tv,
cxobj *xevent)
{
int retval = -1;
struct stream_subscription *ss;
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
/* Go thru all subscriptions and find matches */
if ((ss = es->es_subscription) != NULL)
do {
@ -542,7 +542,7 @@ stream_notify1(clicon_handle h,
/*! Stream notify event and distribute to all registered callbacks
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] stream Name of event stream. CLICON is predefined as LOG stream
* @param[in] event Notification as format string according to printf(3)
* @retval 0 OK
@ -554,8 +554,8 @@ stream_notify1(clicon_handle h,
* @see stream_notify1 Internal
*/
int
stream_notify(clicon_handle h,
char *stream,
stream_notify(clicon_handle h,
char *stream,
const char *event, ...)
{
int retval = -1;
@ -569,7 +569,7 @@ stream_notify(clicon_handle h,
struct timeval tv;
event_stream_t *es;
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
if ((es = stream_find(h, stream)) == NULL)
goto ok;
va_start(args, event);
@ -624,7 +624,7 @@ stream_notify(clicon_handle h,
/*! Backward compatible function
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] stream Name of event stream. CLICON is predefined as LOG stream
* @param[in] xml Notification as XML stream. Is copied.
* @retval 0 OK
@ -632,8 +632,8 @@ stream_notify(clicon_handle h,
* @see stream_notify Should be merged with this
*/
int
stream_notify_xml(clicon_handle h,
char *stream,
stream_notify_xml(clicon_handle h,
char *stream,
cxobj *xml)
{
int retval = -1;
@ -646,7 +646,7 @@ stream_notify_xml(clicon_handle h,
struct timeval tv;
event_stream_t *es;
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
if ((es = stream_find(h, stream)) == NULL)
goto ok;
if ((yspec = clicon_dbspec_yang(h)) == NULL){
@ -763,6 +763,8 @@ stream_replay_notify(clicon_handle h,
* @param[in] es Stream
* @param[in] tv Timestamp
* @param[in] xv XML
* @retval 0 OK
* @retval -1 Error
*/
int
stream_replay_add(event_stream_t *es,
@ -799,6 +801,8 @@ struct replay_arg{
*
* @param[in] fd Ignore
* @param[in] arg tmp struct including clicon handle, stream and subscription
* @retval 0 OK
* @retval -1 Error
*/
static int
stream_replay_cb(int fd,
@ -808,7 +812,7 @@ stream_replay_cb(int fd,
struct replay_arg *ra= (struct replay_arg*)arg;
event_stream_t *es;
struct stream_subscription *ss;
if (ra == NULL)
goto ok;
if (ra->ra_stream == NULL)
@ -836,6 +840,8 @@ stream_replay_cb(int fd,
* @param[in] stream Name of stream
* @param[in] fn Stream callback
* @param[in] arg Argument - typically unique client handle
* @retval 0 OK
* @retval -1 Error
*/
int
stream_replay_trigger(clicon_handle h,
@ -843,8 +849,8 @@ stream_replay_trigger(clicon_handle h,
stream_fn_t fn,
void *arg)
{
int retval = -1;
struct timeval now;
int retval = -1;
struct timeval now;
struct replay_arg *ra;
if ((ra = malloc(sizeof(*ra))) == NULL){
@ -890,10 +896,10 @@ struct curlbuf{
* realloc. Therefore, we append new data to the userdata buffer.
*/
static size_t
curl_get_cb(void *ptr,
curl_get_cb(void *ptr,
size_t size,
size_t nmemb,
void *userdata)
void *userdata)
{
struct curlbuf *buf = (struct curlbuf *)userdata;
int len;
@ -917,8 +923,8 @@ curl_get_cb(void *ptr,
* @see same function (url_post) in grideye_curl.c
*/
static int
url_post(char *url,
char *postfields,
url_post(char *url,
char *postfields,
char **getdata)
{
int retval = -1;
@ -928,15 +934,15 @@ url_post(char *url,
CURLcode errcode;
/* Try it with curl -X PUT -d '*/
clicon_debug(1, "%s: curl -X POST -d '%s' %s",
clixon_debug(CLIXON_DBG_DEFAULT, "%s: curl -X POST -d '%s' %s",
__FUNCTION__, postfields, url);
/* Set up curl for doing the communication with the controller */
if ((curl = curl_easy_init()) == NULL) {
clicon_debug(1, "curl_easy_init");
clixon_debug(CLIXON_DBG_DEFAULT, "curl_easy_init");
goto done;
}
if ((err = malloc(CURL_ERROR_SIZE)) == NULL) {
clicon_debug(1, "%s: malloc", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s: malloc", __FUNCTION__);
goto done;
}
curl_easy_setopt(curl, CURLOPT_URL, url);
@ -947,12 +953,12 @@ url_post(char *url,
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postfields);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(postfields));
if (clicon_debug_get())
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
if (clixon_debug_get())
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
if ((errcode = curl_easy_perform(curl)) != CURLE_OK){
clicon_debug(1, "%s: curl: %s(%d)", __FUNCTION__, err, errcode);
clixon_debug(CLIXON_DBG_DEFAULT, "%s: curl: %s(%d)", __FUNCTION__, err, errcode);
retval = 0;
goto done;
goto done;
}
if (getdata && cb.b_buf){
*getdata = cb.b_buf;
@ -965,21 +971,23 @@ url_post(char *url,
if (cb.b_buf)
free(cb.b_buf);
if (curl)
curl_easy_cleanup(curl); /* cleanup */
curl_easy_cleanup(curl); /* cleanup */
return retval;
}
/*! Stream callback for example stream notification
*
* Push via curl_post to publish stream event
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] op Operation: 0 OK, 1 Close
* @param[in] event Event as XML
* @param[in] arg Extra argument provided in stream_ss_add
* @retval 0 OK
* @retval -1 Error
* @see stream_ss_add
*/
static int
stream_publish_cb(clicon_handle h,
static int
stream_publish_cb(clicon_handle h,
int op,
cxobj *event,
void *arg)
@ -991,7 +999,7 @@ stream_publish_cb(clicon_handle h,
char *result = NULL;
char *stream = (char*)arg;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (op != 0)
goto ok;
/* Create pub url */
@ -1016,7 +1024,7 @@ stream_publish_cb(clicon_handle h,
&result) < 0) /* result as xml */
goto done;
if (result)
clicon_debug(1, "%s: %s", __FUNCTION__, result);
clixon_debug(CLIXON_DBG_DEFAULT, "%s: %s", __FUNCTION__, result);
ok:
retval = 0;
done:
@ -1046,12 +1054,12 @@ stream_publish(clicon_handle h,
return retval;
#else
clicon_log(LOG_WARNING, "%s called but CLIXON_PUBLISH_STREAMS not enabled (enable with configure --enable-publish)", __FUNCTION__);
clicon_log_init("xpath", LOG_WARNING, CLICON_LOG_STDERR);
clicon_log_init("xpath", LOG_WARNING, CLICON_LOG_STDERR);
return 0;
#endif
}
int
int
stream_publish_init()
{
#ifdef CLIXON_PUBLISH_STREAMS
@ -1060,7 +1068,7 @@ stream_publish_init()
if (curl_global_init(CURL_GLOBAL_ALL) != 0){
clicon_err(OE_PLUGIN, errno, "curl_global_init");
goto done;
}
}
retval = 0;
done:
return retval;
@ -1069,11 +1077,11 @@ stream_publish_init()
#endif
}
int
int
stream_publish_exit()
{
#ifdef CLIXON_PUBLISH_STREAMS
curl_global_cleanup();
#endif
#endif
return 0;
}