]> git.meshlink.io Git - meshlink/blobdiff - src/meshlink.h
Check all arguments of the public API for NULL pointers.
[meshlink] / src / meshlink.h
index 7bb0da9997955277d7ab4b7707425ffca46d401e..e06a59068699898ca62fe1f6340108ea70637c82 100644 (file)
@@ -29,6 +29,7 @@
 extern "C" {
 #endif
 
+/// The length in bytes of a signature made with meshlink_sign()
 #define MESHLINK_SIGLEN 64
 
 /// A handle for an instance of MeshLink.
@@ -47,11 +48,12 @@ typedef enum {
        MESHLINK_ENOENT, ///< Node is not known
 } meshlink_errno_t;
 
+/// A variable holding the last encountered error from MeshLink.
+extern __thread meshlink_errno_t meshlink_errno;
+
 #ifndef MESHLINK_INTERNAL_H
 
 struct meshlink_handle {
-       meshlink_errno_t meshlink_errno; ///< Code of the last encountered error.
-       const char *errstr;              ///< Textual representation of most recent error encountered.
 };
 
 struct meshlink_node {
@@ -219,9 +221,10 @@ extern meshlink_node_t *meshlink_get_node(meshlink_handle_t *mesh, const char *n
  *  @param nodes        A pointer to an array of pointers to meshlink_node_t, which should be allocated by the application.
  *  @param nmemb        The maximum number of pointers that can be stored in the nodes array.
  *
- *  @return             The number of known nodes. This can be larger than nmemb, in which case not all nodes were stored in the nodes array.
+ *  @return             The number of known nodes, or -1 in case of an error.
+ *                      The returned number of nodes can be larger than nmemb, in which case not all nodes were stored in the nodes array.
  */
-extern size_t meshlink_get_all_nodes(meshlink_handle_t *mesh, meshlink_node_t **nodes, size_t nmemb);
+extern ssize_t meshlink_get_all_nodes(meshlink_handle_t *mesh, meshlink_node_t **nodes, size_t nmemb);
 
 /// Sign data using the local node's MeshLink key.
 /** This function signs data using the local node's MeshLink key.
@@ -334,7 +337,7 @@ extern void meshlink_blacklist(meshlink_handle_t *mesh, meshlink_node_t *node);
  *  @return             This function should return true if the application accepts the incoming channel, false otherwise.
  *                      If returning false, the channel is invalid and may not be used anymore.
  */
-typedef bool (*meshlink_channel_accept_cb_t)(meshlink_handle_t *mesh, meshlink_channel_t *channel, meshlink_node_t *node, uint16_t port, void *data, size_t len);
+typedef bool (*meshlink_channel_accept_cb_t)(meshlink_handle_t *mesh, meshlink_channel_t *channel, meshlink_node_t *node, uint16_t port, const void *data, size_t len);
 
 /// A callback for receiving data from a channel.
 /** This function is called whenever a remote node wants to open a channel to the local node.
@@ -345,7 +348,7 @@ typedef bool (*meshlink_channel_accept_cb_t)(meshlink_handle_t *mesh, meshlink_c
  *  @param data         A pointer to a buffer containing data sent by the source.
  *  @param len          The length of the data.
  */
-typedef void (*meshlink_channel_receive_cb_t)(meshlink_handle_t *mesh, meshlink_channel_t *channel, void *data, size_t len);
+typedef void (*meshlink_channel_receive_cb_t)(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *data, size_t len);
 
 /// Set the accept callback.
 /** This functions sets the callback that is called whenever another node sends data to the local node.
@@ -385,7 +388,7 @@ extern void meshlink_set_channel_receive_cb(meshlink_handle_t *mesh, meshlink_ch
  *
  *  @return             A handle for the channel, or NULL in case of an error.
  */
-extern meshlink_channel_t *meshlink_channel_open(meshlink_handle_t *mesh, meshlink_node_t *node, uint16_t port, meshlink_channel_receive_cb_t cb, void *data, size_t len);
+extern meshlink_channel_t *meshlink_channel_open(meshlink_handle_t *mesh, meshlink_node_t *node, uint16_t port, meshlink_channel_receive_cb_t cb, const void *data, size_t len);
 
 /// Partially close a reliable stream channel.
 /** This shuts down the read or write side of a channel, or both, without closing the handle.
@@ -418,7 +421,7 @@ extern void meshlink_channel_close(meshlink_handle_t *mesh, meshlink_channel_t *
  *
  *  @return             The amount of data that was queued, which can be less than len, or a negative value in case of an error.
  */
-extern ssize_t meshlink_channel_send(meshlink_handle_t *mesh, meshlink_channel_t *channel, void *data, size_t len);
+extern ssize_t meshlink_channel_send(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *data, size_t len);
 
 #ifdef __cplusplus
 }