For now it just contains stubs for all the public functions.
meshlinkapp_SOURCES = meshlinkapp.c
meshlinkapp_LDADD = ../src/libmeshlink.la
-meshlinkapp_SOURCES = chat.c
-meshlinkapp_LDADD = ../src/libmeshlink.la
+chat_SOURCES = chat.c
+chat_LDADD = ../src/libmeshlink.la
#include <string.h>
#include "../src/meshlink.h"
-static void log(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *text) {
+static void log_message(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *text) {
const char *levelstr[] = {"DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"};
fprintf(stderr, "%s: %s\n", levelstr[level], text);
}
-static void receive(meshlink_handle_t *mesh, meshlink_node_t *source, const char *data, size_t len) {
- if(!len || data[len - 1]) {
+static void receive(meshlink_handle_t *mesh, meshlink_node_t *source, const void *data, size_t len) {
+ const char *msg = data;
+
+ if(!len || msg[len - 1]) {
fprintf(stderr, "Received invalid data from %s\n", source->name);
return;
}
- printf("%s says: %s\n", source->name, data);
+ printf("%s says: %s\n", source->name, msg);
}
static void node_status(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) {
}
meshlink_set_receive_cb(mesh, receive);
- meshlink_set_node_status_cb(mesh, node_changed);
- meshlink_set_log_cb(mesh, MESHLINK_INFO, log);
+ meshlink_set_node_status_cb(mesh, node_status);
+ meshlink_set_log_cb(mesh, MESHLINK_INFO, log_message);
if(!meshlink_start(mesh)) {
fprintf(stderr, "Could not start MeshLink: %s\n", mesh->errstr);
lib_LTLIBRARIES = libmeshlink.la
libmeshlink_la_SOURCES = \
- libmeshlink.c libmeshlink.h \
+ meshlink.c meshlink.h \
buffer.c buffer.h \
cipher.h \
conf.c conf.h \
--- /dev/null
+/*
+ meshlink.c -- Implementation of the MeshLink API.
+ Copyright (C) 2014 Guus Sliepen <guus@meshlink.io>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include "system.h"
+
+#include "meshlink_internal.h"
+
+static const char *errstr[] = {
+ [MESHLINK_OK] = "No error",
+ [MESHLINK_ENOMEM] = "Out of memory",
+ [MESHLINK_ENOENT] = "No such node",
+};
+
+const char *meshlink_strerror(meshlink_errno_t errno) {
+ return errstr[errno];
+}
+
+meshlink_handle_t *meshlink_open(const char *confbase, const char *name) {
+ return NULL;
+}
+
+bool meshlink_start(meshlink_handle_t *handle) {
+ return false;
+}
+
+void meshlink_stop(meshlink_handle_t *handle) {
+}
+
+void meshlink_close(meshlink_handle_t *handle) {
+}
+
+void meshlink_set_receive_cb(meshlink_handle_t *handle, meshlink_receive_cb_t cb) {
+}
+
+void meshlink_set_node_status_cb(meshlink_handle_t *handle, meshlink_node_status_cb_t cb) {
+}
+
+void meshlink_set_log_cb(meshlink_handle_t *handle, meshlink_log_level_t level, meshlink_log_cb_t cb) {
+}
+
+bool meshlink_send(meshlink_handle_t *handle, meshlink_node_t *destination, const void *data, unsigned int len) {
+ return false;
+}
+
+meshlink_node_t *meshlink_get_node(meshlink_handle_t *handle, const char *name) {
+ return NULL;
+}
+
+size_t meshlink_get_all_nodes(meshlink_handle_t *handle, meshlink_node_t **nodes, size_t nmemb) {
+ return 0;
+}
+
+char *meshlink_sign(meshlink_handle_t *handle, const char *data, size_t len) {
+ return NULL;
+}
+
+bool meshlink_verify(meshlink_handle_t *handle, meshlink_node_t *source, const char *data, size_t len, const char *signature) {
+ return false;
+}
+
+char *meshlink_invite(meshlink_handle_t *handle, const char *name) {
+ return NULL;
+}
+
+bool meshlink_join(meshlink_handle_t *handle, const char *invitation) {
+ return false;
+}
+
+char *meshlink_export(meshlink_handle_t *handle) {
+ return NULL;
+}
+
+bool meshlink_import(meshlink_handle_t *handle, const char *data) {
+ return false;
+}
+
+void meshlink_blacklist(meshlink_handle_t *handle, meshlink_node_t *node) {
+}
+
* @param handle A handle which represents an instance of MeshLink.
* @param cb A pointer to the function which will be called when another node sends data to the local node.
*/
-void meshlink_set_receive_cb(meshlink_handle_t *handle, meshlink_receive_cb_t cb);
+extern void meshlink_set_receive_cb(meshlink_handle_t *handle, meshlink_receive_cb_t cb);
/// A callback reporting node status changes.
/** @param handle A handle which represents an instance of MeshLink.
* @param handle A handle which represents an instance of MeshLink.
* @param cb A pointer to the function which will be called when another node's status changes.
*/
-void meshlink_set_node_status_cb(meshlink_handle_t *handle, meshlink_node_status_cb_t cb);
+extern void meshlink_set_node_status_cb(meshlink_handle_t *handle, meshlink_node_status_cb_t cb);
/// Severity of log messages generated by MeshLink.
typedef enum {
* @param level An enum describing the minimum severity level. Debugging information with a lower level will not trigger the callback.
* @param cb A pointer to the function which will be called when another node sends data to the local node.
*/
-void meshlink_set_log_cb(meshlink_handle_t *handle, meshlink_log_level_t level, meshlink_receive_cb_t cb);
+extern void meshlink_set_log_cb(meshlink_handle_t *handle, meshlink_log_level_t level, meshlink_log_cb_t cb);
/// Send data to another node.
/** This functions sends one packet of data to another node in the mesh.