aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2015-07-21 15:21:12 +0200
committerAris Adamantiadis <aris@0xbadc0de.be>2015-12-07 20:23:57 +0100
commit143f7ecbd225fb8e44e3713c156f2dda21082e81 (patch)
tree60c6327aa6fdc7bcc9ea21cd7d2158daf9209f52
parentc48fb644c6fd34edde024a290320576d8b3ff7b6 (diff)
downloadlibssh-143f7ecbd225fb8e44e3713c156f2dda21082e81.tar.gz
libssh-143f7ecbd225fb8e44e3713c156f2dda21082e81.tar.xz
libssh-143f7ecbd225fb8e44e3713c156f2dda21082e81.zip
callbacks: Add macro for callbacks execute list
Signed-off-by: Aris Adamantiadis <aris@0xbadc0de.be> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r--include/libssh/callbacks.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/include/libssh/callbacks.h b/include/libssh/callbacks.h
index 6b07b087..9a6f2418 100644
--- a/include/libssh/callbacks.h
+++ b/include/libssh/callbacks.h
@@ -435,6 +435,34 @@ typedef struct ssh_socket_callbacks_struct *ssh_socket_callbacks;
((p)-> c != NULL) \
)
+/**
+ * @internal
+ *
+ * @brief Iterate through a list of callback structures
+ *
+ * This tests for their validity and executes them. The userdata argument is
+ * automatically passed through.
+ *
+ * @param list list of callbacks
+ *
+ * @param cbtype type of the callback
+ *
+ * @param c callback name
+ *
+ * @param va_args parameters to be passed
+ */
+#define ssh_callbacks_execute_list(list, cbtype, c, ...) \
+ do { \
+ struct ssh_iterator *i = ssh_list_get_iterator(list); \
+ cbtype cb; \
+ while (i != NULL){ \
+ cb = ssh_iterator_value(cbtype, i); \
+ if (ssh_callbacks_exists(cb, c)) \
+ cb-> c (__VA_ARGS__, cb->userdata); \
+ i = i->next; \
+ } \
+ } while(0)
+
/** @brief Prototype for a packet callback, to be called when a new packet arrives
* @param session The current session of the packet
* @param type packet type (see ssh2.h)