2017-09-18 08:30:18 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2017 Ortega Froysa, Nicolás <nortega@themusicinnoise.net>
|
|
|
|
* Author: Ortega Froysa, Nicolás <nortega@themusicinnoise.net>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2017-09-23 09:29:25 +00:00
|
|
|
/**
|
|
|
|
* @file neocomm.h
|
|
|
|
* @brief Include file for NeoComm
|
|
|
|
*/
|
|
|
|
|
2017-09-18 08:30:18 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-09-20 06:35:23 +00:00
|
|
|
#ifdef __cplusplus
|
2017-09-18 08:30:18 +00:00
|
|
|
extern "C" {
|
2017-09-22 06:41:52 +00:00
|
|
|
#include <ctime>
|
|
|
|
#else
|
|
|
|
#include <time.h>
|
2017-09-20 06:35:23 +00:00
|
|
|
#endif
|
2017-09-18 08:30:18 +00:00
|
|
|
|
2017-09-22 06:41:52 +00:00
|
|
|
/**
|
|
|
|
* @brief A structure with necessary variables for other users.
|
|
|
|
*/
|
|
|
|
struct user {
|
|
|
|
const char *nick; ///< The alias used by the user.
|
|
|
|
const char *hash; ///< The unique hash of the user.
|
|
|
|
};
|
|
|
|
|
2017-09-23 09:29:25 +00:00
|
|
|
/**
|
|
|
|
* @brief Structure with relevant message information.
|
|
|
|
*/
|
2017-09-22 06:41:52 +00:00
|
|
|
struct message {
|
|
|
|
const char *msg; ///< The text message.
|
|
|
|
time_t sent; ///< The time it was sent.
|
2017-09-23 10:17:08 +00:00
|
|
|
struct user from; ///< Info on the peer who sent the message.
|
2017-09-22 06:41:52 +00:00
|
|
|
};
|
|
|
|
|
2017-09-18 08:30:18 +00:00
|
|
|
/**
|
2017-09-20 13:14:28 +00:00
|
|
|
* @brief Initialize a local DHT node. If port is 0 then the default port
|
|
|
|
* number will be used.
|
2017-09-18 08:30:18 +00:00
|
|
|
*
|
|
|
|
* @param port The port for the node to listen on.
|
2017-09-25 11:01:13 +00:00
|
|
|
*
|
|
|
|
* @return 1 upon success, 0 upon failure. Use NeoComm_get_last_error for a
|
|
|
|
* text description of the error.
|
2017-09-18 08:30:18 +00:00
|
|
|
*/
|
2017-09-25 11:01:13 +00:00
|
|
|
int NeoComm_init(const unsigned short port);
|
2017-09-18 08:30:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Deinitialize the local node.
|
|
|
|
*/
|
|
|
|
void NeoComm_deinit();
|
|
|
|
|
|
|
|
/**
|
2017-09-22 06:41:52 +00:00
|
|
|
* @brief Connect to a foreign node.
|
2017-09-18 08:30:18 +00:00
|
|
|
*
|
|
|
|
* @param address DNS/IP of the node.
|
|
|
|
* @param port Port of the foreign node.
|
2017-09-20 19:01:07 +00:00
|
|
|
*
|
|
|
|
* @return 1 upon success, 0 upon failure. Use NeoComm_get_last_error for a
|
|
|
|
* text description of the error.
|
2017-09-18 08:30:18 +00:00
|
|
|
*/
|
2017-09-20 19:01:07 +00:00
|
|
|
int NeoComm_connect(const char *address, const unsigned short port);
|
2017-09-18 08:30:18 +00:00
|
|
|
|
2017-09-25 14:37:09 +00:00
|
|
|
/*
|
2017-09-18 08:30:18 +00:00
|
|
|
* @brief Import a list of nodes from a node file and connect to them.
|
|
|
|
*
|
|
|
|
* @param node_file Path to the node list file.
|
|
|
|
*
|
|
|
|
* @return 1 upon success, 0 upon failure. Use NeoComm_get_last_error for a
|
2017-09-20 13:14:28 +00:00
|
|
|
* text description of the error.
|
2017-09-18 08:30:18 +00:00
|
|
|
*/
|
2017-09-25 14:21:16 +00:00
|
|
|
//int NeoComm_import_nodes(const char *node_file);
|
2017-09-18 08:30:18 +00:00
|
|
|
|
2017-09-25 14:37:09 +00:00
|
|
|
/*
|
2017-09-18 08:30:18 +00:00
|
|
|
* @brief Export current list of nodes into a file.
|
|
|
|
*
|
|
|
|
* @param node_file path to node list file.
|
|
|
|
*
|
|
|
|
* @return 1 upon success, 0 upon failure. Use NeoComm_get_last_error for a
|
2017-09-20 13:14:28 +00:00
|
|
|
* text description of the error.
|
2017-09-18 08:30:18 +00:00
|
|
|
*/
|
2017-09-25 14:21:16 +00:00
|
|
|
//int NeoComm_export_nodes(const char *node_file);
|
2017-09-18 08:30:18 +00:00
|
|
|
|
2017-09-20 13:14:28 +00:00
|
|
|
/**
|
|
|
|
* @brief Join a channel.
|
|
|
|
*
|
|
|
|
* @param channel_name Name of the channel.
|
|
|
|
*
|
|
|
|
* @return 1 upon success, 0 upon failure. Use NeoComm_get_last_error for a
|
|
|
|
* text description of the error.
|
|
|
|
*/
|
|
|
|
int NeoComm_join_channel(const char *channel_name);
|
|
|
|
|
2017-09-20 19:01:07 +00:00
|
|
|
/**
|
|
|
|
* @brief Leave a channel.
|
|
|
|
*
|
|
|
|
* @param channel_name Name of the channel to disconnect from.
|
|
|
|
*/
|
|
|
|
void NeoComm_leave_channel(const char *channel_name);
|
|
|
|
|
2017-09-22 06:41:52 +00:00
|
|
|
/**
|
|
|
|
* @brief Get the next available message (in chronological order) for
|
|
|
|
* a given channel.
|
|
|
|
*
|
|
|
|
* @param channel_name Channel to check for new messages.
|
|
|
|
*
|
|
|
|
* @return A structure of the message. If NULL then there are no new messages.
|
|
|
|
*
|
2017-09-25 14:34:45 +00:00
|
|
|
* @warning This command will remove the message from the internal list.
|
|
|
|
* @warning The message must be freed from memory using NeoComm_free_message.
|
2017-09-22 06:41:52 +00:00
|
|
|
*/
|
|
|
|
struct message *NeoComm_get_next_message(const char *channel_name);
|
|
|
|
|
2017-09-23 09:29:25 +00:00
|
|
|
/**
|
|
|
|
* @brief Free the memory for a message.
|
|
|
|
*
|
|
|
|
* @param msg The message to free from memory.
|
|
|
|
*/
|
2017-09-22 06:41:52 +00:00
|
|
|
void NeoComm_free_message(struct message *msg);
|
|
|
|
|
2017-09-25 11:01:13 +00:00
|
|
|
/**
|
|
|
|
* @brief Send a message to a channel.
|
|
|
|
*
|
|
|
|
* @param channel_name Name of the channel to send the message to.
|
|
|
|
* @param message A message to send to the channel.
|
|
|
|
*
|
|
|
|
* @return 1 upon success, 0 upon failure. Use NeoComm_get_last_error for a
|
|
|
|
* text description of the error.
|
|
|
|
*/
|
|
|
|
int NeoComm_send_message(const char *channel_name, const char *message);
|
|
|
|
|
2017-09-18 08:30:18 +00:00
|
|
|
/**
|
|
|
|
* @brief Get the last error that occurred in text.
|
|
|
|
*
|
|
|
|
* @return A string with the last error occurred.
|
|
|
|
*/
|
|
|
|
const char *NeoComm_get_last_error();
|
|
|
|
|
2017-09-20 06:35:23 +00:00
|
|
|
#ifdef __cplusplus
|
2017-09-18 08:30:18 +00:00
|
|
|
}
|
2017-09-20 06:35:23 +00:00
|
|
|
#endif
|