session FEATURE session getters
diff --git a/src/io.c b/src/io.c
index 4d76a11..40eac1c 100644
--- a/src/io.c
+++ b/src/io.c
@@ -51,7 +51,10 @@
return 0;
}
- switch(session->ti_type) {
+ switch (session->ti_type) {
+ case NC_TI_NONE:
+ return 0;
+
case NC_TI_FD:
/* read via standard file descriptor */
while(count) {
@@ -253,10 +256,13 @@
#endif
}
- while(1) {
+ while (1) {
/* poll loop */
- switch(session->ti_type) {
+ switch (session->ti_type) {
+ case NC_TI_NONE:
+ return NC_MSG_ERROR;
+
#ifdef ENABLE_SSH
case NC_TI_LIBSSH:
/* we are getting data from libssh's channel */
@@ -461,6 +467,9 @@
char chunksize[20];
switch (session->ti_type) {
+ case NC_TI_NONE:
+ return -1;
+
case NC_TI_FD:
if (session->version == NC_VERSION_11) {
c = dprintf(session->ti.fd.out, "\n#%zu\n", count);
@@ -493,6 +502,9 @@
write_endtag(struct nc_session *session)
{
switch(session->ti_type) {
+ case NC_TI_NONE:
+ return 0;
+
case NC_TI_FD:
if (session->version == NC_VERSION_11) {
write(session->ti.fd.out, "\n##\n", 4);
@@ -587,6 +599,9 @@
content = va_arg(ap, struct lyd_node *);
attrs = va_arg(ap, const char *);
switch (session->ti_type) {
+ case NC_TI_NONE:
+ return -1;
+
case NC_TI_FD:
dprintf(session->ti.fd.out, "<rpc xmlns=\"%s\" message-id=\"%"PRIu64"\"%s>",
NC_NS_BASE, session->msgid + 1, attrs ? attrs : "");
@@ -620,6 +635,9 @@
case NC_MSG_REPLY:
rpc = va_arg(ap, struct nc_server_rpc *);
switch (session->ti_type) {
+ case NC_TI_NONE:
+ return -1;
+
case NC_TI_FD:
write(session->ti.fd.out, "<rpc-reply", 10);
lyxml_dump_fd(session->ti.fd.out, rpc->root, LYXML_DUMP_ATTRS);
@@ -653,6 +671,9 @@
case NC_MSG_NOTIF:
switch (session->ti_type) {
+ case NC_TI_NONE:
+ return -1;
+
case NC_TI_FD:
write(session->ti.fd.out, "<notification xmlns=\""NC_NS_NOTIF"\"/>", 21 + 47 + 3);
@@ -685,6 +706,9 @@
capabilities = va_arg(ap, const char **);
sid = va_arg(ap, uint32_t*);
switch (session->ti_type) {
+ case NC_TI_NONE:
+ return -1;
+
case NC_TI_FD:
dprintf(session->ti.fd.out, "<hello xmlns=\"%s\"><capabilities>", NC_NS_BASE);
for (i = 0; capabilities[i]; i++) {
diff --git a/src/netconf.h b/src/netconf.h
index 47dac1b..00617f5 100644
--- a/src/netconf.h
+++ b/src/netconf.h
@@ -33,9 +33,14 @@
#define NC_NS_NOTIF "urn:ietf:params:xml:ns:netconf:notification:1.0"
/** @brief Default NETCONF over SSH port */
-#define NC_PORT_SSH 830;
+#define NC_PORT_SSH 830
+/** @brief Default NETCONF over SSH Call Home port */
+#define NC_PORT_CH_SSH 6666
+
/** @brief Default NETCONF over TLS port */
-#define NC_PORT_TLS 6513;
+#define NC_PORT_TLS 6513
+/** @brief Default NETCONF over TLS Call Home port */
+#define NC_PORT_CH_TLS 6667
/**
* @brief Enumeration of reasons of the NETCONF session termination as defined in RFC 6470.
diff --git a/src/session.c b/src/session.c
index 1d0b3e6..5a4fa18 100644
--- a/src/session.c
+++ b/src/session.c
@@ -61,6 +61,48 @@
return schema_searchpath ? 0 : 1;
}
+API NC_STATUS
+nc_get_session_status(const struct nc_session *session)
+{
+ return session->status;
+}
+
+API uint32_t
+nc_get_session_id(const struct nc_session *session)
+{
+ return session->id;
+}
+
+API NC_TRANSPORT_IMPL
+nc_get_session_ti(const struct nc_session *session)
+{
+ return session->ti_type;
+}
+
+API const char *
+nc_get_session_username(const struct nc_session *session)
+{
+ return session->username;
+}
+
+API const char *
+nc_get_session_host(const struct nc_session *session)
+{
+ return session->host;
+}
+
+API uint16_t
+nc_get_session_port(const struct nc_session *session)
+{
+ return session->port;
+}
+
+API const char **
+nc_get_session_cpblts(const struct nc_session *session)
+{
+ return session->cpblts;
+}
+
/*
* @return 0 - success
* -1 - timeout
@@ -547,6 +589,9 @@
/* transport implementation cleanup */
switch (session->ti_type) {
+ case NC_TI_NONE:
+ break;
+
case NC_TI_FD:
/* nothing needed - file descriptors were provided by caller,
* so it is up to the caller to close them correctly
diff --git a/src/session.h b/src/session.h
index c5a8d52..858fd6a 100644
--- a/src/session.h
+++ b/src/session.h
@@ -52,13 +52,28 @@
* @brief Enumeration of possible session statuses
*/
typedef enum {
- NC_STATUS_STARTING, /**< session is not yet fully initiated */
- NC_STATUS_CLOSING, /**< session is being closed */
- NC_STATUS_INVALID, /**< session is corrupted and it is supposed to be closed (nc_session_free()) */
- NC_STATUS_RUNNING /**< up and running */
+ NC_STATUS_STARTING = 0, /**< session is not yet fully initiated */
+ NC_STATUS_CLOSING, /**< session is being closed */
+ NC_STATUS_INVALID, /**< session is corrupted and it is supposed to be closed (nc_session_free()) */
+ NC_STATUS_RUNNING /**< up and running */
} NC_STATUS;
/**
+ * @brief Enumeration of transport implementations (ways how libnetconf implements NETCONF transport protocol)
+ */
+typedef enum {
+ NC_TI_NONE = 0, /**< none - session is not connected yet */
+ NC_TI_FD, /**< file descriptors - use standard input/output, transport protocol is implemented
+ outside the current application */
+#ifdef ENABLE_SSH
+ NC_TI_LIBSSH, /**< libssh - use libssh library, only for NETCONF over SSH transport */
+#endif
+#ifdef ENABLE_TLS
+ NC_TI_OPENSSL /**< OpenSSL - use OpenSSL library, only for NETCONF over TLS transport */
+#endif
+} NC_TRANSPORT_IMPL;
+
+/**
* @brief NETCONF session object
*/
struct nc_session;
@@ -79,6 +94,69 @@
int nc_schema_searchpath(const char *path);
/**
+ * @brief Get session status.
+ *
+ * @param[in] session Session to get the information from.
+ *
+ * @return Session status.
+ */
+NC_STATUS nc_get_session_status(const struct nc_session *session);
+
+/**
+ * @brief Get session ID.
+ *
+ * @param[in] session Session to get the information from.
+ *
+ * @return Session ID.
+ */
+uint32_t nc_get_session_id(const struct nc_session *session);
+
+/**
+ * @brief Get session transport used.
+ *
+ * @param[in] session Session to get the information from.
+ *
+ * @return Session transport.
+ */
+NC_TRANSPORT_IMPL nc_get_session_ti(const struct nc_session *session);
+
+/**
+ * @brief Get session username.
+ *
+ * @param[in] session Session to get the information from.
+ *
+ * @return Session username.
+ */
+const char *nc_get_session_username(const struct nc_session *session);
+
+/**
+ * @brief Get session host.
+ *
+ * @param[in] session Session to get the information from.
+ *
+ * @return Session host.
+ */
+const char *nc_get_session_host(const struct nc_session *session);
+
+/**
+ * @brief Get session port.
+ *
+ * @param[in] session Session to get the information from.
+ *
+ * @return Session port.
+ */
+uint16_t nc_get_session_port(const struct nc_session *session);
+
+/**
+ * @brief Get session capabilities.
+ *
+ * @param[in] session Session to get the information from.
+ *
+ * @return Session capabilities.
+ */
+const char **nc_get_session_cpblts(const struct nc_session *session);
+
+/**
* @brief Connect to the NETCONF server via proviaded input/output file descriptors.
*
* Transport layer is supposed to be already set. Function do not cover authentication
diff --git a/src/session_p.h b/src/session_p.h
index 27398cd..8eccd1a 100644
--- a/src/session_p.h
+++ b/src/session_p.h
@@ -75,20 +75,6 @@
#define NC_READ_SLEEP 100
/**
- * @brief Enumeration of transport implementations (ways how libnetconf implements NETCONF transport protocol)
- */
-typedef enum {
- NC_TI_FD, /**< file descriptors - use standard input/output, transport protocol is implemented
- outside the current application (only for NETCONF over SSH transport) */
-#ifdef ENABLE_SSH
- NC_TI_LIBSSH, /**< libssh - use libssh library, only for NETCONF over SSH transport */
-#endif
-#ifdef ENABLE_TLS
- NC_TI_OPENSSL /**< OpenSSL - use OpenSSL library, only for NETCONF over TLS transport */
-#endif
-} NC_TRANSPORT_IMPL;
-
-/**
* @brief type of the session
*/
typedef enum {
@@ -151,7 +137,7 @@
} ti; /**< transport implementation data */
const char *username;
const char *host;
- unsigned short port;
+ uint16_t port;
/* other */
struct ly_ctx *ctx; /**< libyang context of the session */