io REFACTOR minor improvements and doxygen added
diff --git a/src/io.c b/src/io.c
index f44af52..8633146 100644
--- a/src/io.c
+++ b/src/io.c
@@ -1,10 +1,11 @@
/**
* @file io.c
* @author Radek Krejci <rkrejci@cesnet.cz>
+ * @author Michal Vasko <mvasko@cesnet.cz>
* @brief libnetconf2 - input/output functions
*
* @copyright
- * Copyright (c) 2015 CESNET, z.s.p.o.
+ * Copyright (c) 2015 - 2024 CESNET, z.s.p.o.
*
* This source code is licensed under BSD 3-Clause License (the "License").
* You may not use this file except in compliance with the License.
@@ -622,6 +623,15 @@
size_t len;
};
+/**
+ * @brief Write to a NETCONF session.
+ *
+ * @param[in] session Session to write to.
+ * @param[in] buf Buffer to write.
+ * @param[in] count Count of bytes from @p buf to write.
+ * @return Number of bytes written.
+ * @return -1 on error.
+ */
static int
nc_write(struct nc_session *session, const void *buf, size_t count)
{
@@ -644,7 +654,7 @@
return -1;
}
- DBG(session, "Sending message:\n%.*s\n", count, buf);
+ DBG(session, "Sending message:\n%.*s\n", (int)count, buf);
do {
interrupted = 0;
@@ -659,7 +669,7 @@
c = 0;
interrupted = 1;
} else if (c < 0) {
- ERR(session, "socket error (%s).", strerror(errno));
+ ERR(session, "Socket error (%s).", strerror(errno));
return -1;
}
break;
@@ -726,13 +736,21 @@
return written;
}
+/**
+ * @brief Write the start tag and the message part of a chunked-framing NETCONF message.
+ *
+ * @param[in] session Session to write to.
+ * @param[in] buf Message buffer to write.
+ * @param[in] count Count of bytes from @p buf to write.
+ * @return Number of bytes written.
+ * @return -1 on error.
+ */
static int
nc_write_starttag_and_msg(struct nc_session *session, const void *buf, size_t count)
{
int ret = 0, c;
char chunksize[24];
- // warning: ‘%zu’ directive writing between 4 and 20 bytes into a region of size 18 [-Wformat-overflow=]
if (session->version == NC_VERSION_11) {
sprintf(chunksize, "\n#%zu\n", count);
ret = nc_write(session, chunksize, strlen(chunksize));
@@ -750,6 +768,13 @@
return ret;
}
+/**
+ * @brief Write the end tag part of a chunked-framing NETCONF message.
+ *
+ * @param[in] session Session to write to.
+ * @return Number of bytes written.
+ * @return -1 on error.
+ */
static int
nc_write_endtag(struct nc_session *session)
{
@@ -764,6 +789,13 @@
return ret;
}
+/**
+ * @brief Flush all the data buffered for writing.
+ *
+ * @param[in] warg Write callback structure to flush.
+ * @return Number of written bytes.
+ * @return -1 on error.
+ */
static int
nc_write_clb_flush(struct wclb_arg *warg)
{
@@ -778,6 +810,16 @@
return ret;
}
+/**
+ * @brief Write callback buffering the data in a write structure.
+ *
+ * @param[in] arg Write structure used for buffering.
+ * @param[in] buf Buffer to write.
+ * @param[in] count Count of bytes to write from @p buf.
+ * @param[in] xmlcontent Whether the data are actually printed as part of an XML in which case they need to be encoded.
+ * @return Number of written bytes.
+ * @return -1 on error.
+ */
static ssize_t
nc_write_clb(void *arg, const void *buf, size_t count, int xmlcontent)
{
@@ -863,6 +905,9 @@
return ret;
}
+/**
+ * @brief Write print callback used by libyang.
+ */
static ssize_t
nc_write_xmlclb(void *arg, const void *buf, size_t count)
{