2017-10-16 09:40:27 +02:00
|
|
|
/** Node type: nanomsg
|
|
|
|
*
|
|
|
|
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
2020-01-20 17:17:00 +01:00
|
|
|
* @copyright 2014-2020, Institute for Automation of Complex Power Systems, EONERC
|
2017-10-16 09:40:27 +02:00
|
|
|
* @license GNU General Public License (version 3)
|
|
|
|
*
|
|
|
|
* VILLASnode
|
|
|
|
*
|
|
|
|
* 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 3 of the License, or
|
|
|
|
* 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************************/
|
|
|
|
|
2019-06-23 16:57:00 +02:00
|
|
|
#include <cstring>
|
2017-10-16 09:40:27 +02:00
|
|
|
|
2017-11-18 01:05:18 +01:00
|
|
|
#include <amqp_ssl_socket.h>
|
|
|
|
#include <amqp_tcp_socket.h>
|
|
|
|
|
2021-06-21 16:11:42 -04:00
|
|
|
#include <villas/node.h>
|
2019-04-23 00:12:31 +02:00
|
|
|
#include <villas/nodes/amqp.hpp>
|
2019-04-23 13:15:00 +02:00
|
|
|
#include <villas/utils.hpp>
|
2021-02-16 14:15:14 +01:00
|
|
|
#include <villas/exceptions.hpp>
|
2017-10-16 09:40:27 +02:00
|
|
|
|
2021-02-16 14:15:14 +01:00
|
|
|
using namespace villas;
|
2021-05-10 00:12:30 +02:00
|
|
|
using namespace villas::node;
|
2019-06-04 16:55:38 +02:00
|
|
|
using namespace villas::utils;
|
|
|
|
|
2017-11-18 01:05:18 +01:00
|
|
|
static void amqp_default_ssl_info(struct amqp_ssl_info *s)
|
2017-10-16 09:40:27 +02:00
|
|
|
{
|
2017-11-18 01:05:18 +01:00
|
|
|
s->verify_peer = 1;
|
|
|
|
s->verify_hostname = 1;
|
2019-04-22 23:45:38 +02:00
|
|
|
s->client_key = nullptr;
|
|
|
|
s->client_cert = nullptr;
|
|
|
|
s->ca_cert = nullptr;
|
2017-11-18 01:05:18 +01:00
|
|
|
}
|
2017-10-16 09:40:27 +02:00
|
|
|
|
2017-11-18 01:05:18 +01:00
|
|
|
static amqp_bytes_t amqp_bytes_strdup(const char *str)
|
|
|
|
{
|
|
|
|
size_t len = strlen(str) + 1;
|
|
|
|
amqp_bytes_t buf = amqp_bytes_malloc(len);
|
2017-10-16 09:40:27 +02:00
|
|
|
|
2017-11-18 01:05:18 +01:00
|
|
|
memcpy(buf.bytes, str, len);
|
2017-10-16 09:40:27 +02:00
|
|
|
|
2017-11-18 01:05:18 +01:00
|
|
|
return buf;
|
2017-10-16 09:40:27 +02:00
|
|
|
}
|
|
|
|
|
2017-11-18 01:05:18 +01:00
|
|
|
static amqp_connection_state_t amqp_connect(struct amqp_connection_info *ci, struct amqp_ssl_info *ssl)
|
2017-10-16 09:40:27 +02:00
|
|
|
{
|
2017-11-18 01:05:18 +01:00
|
|
|
int ret;
|
|
|
|
amqp_rpc_reply_t rep;
|
|
|
|
amqp_connection_state_t conn;
|
|
|
|
amqp_socket_t *sock;
|
2017-10-16 09:40:27 +02:00
|
|
|
|
2017-11-18 01:05:18 +01:00
|
|
|
conn = amqp_new_connection();
|
|
|
|
if (!conn)
|
2019-04-22 23:45:38 +02:00
|
|
|
return nullptr;
|
2017-10-16 09:40:27 +02:00
|
|
|
|
2017-11-18 01:05:18 +01:00
|
|
|
if (ci->ssl) {
|
|
|
|
sock = amqp_ssl_socket_new(conn);
|
|
|
|
if (!sock)
|
2019-04-22 23:45:38 +02:00
|
|
|
return nullptr;
|
2017-10-16 09:40:27 +02:00
|
|
|
|
2017-11-18 01:05:18 +01:00
|
|
|
amqp_ssl_socket_set_verify_peer(sock, ssl->verify_peer);
|
|
|
|
amqp_ssl_socket_set_verify_hostname(sock, ssl->verify_hostname);
|
2017-10-16 09:40:27 +02:00
|
|
|
|
2017-11-18 01:05:18 +01:00
|
|
|
if (ssl->ca_cert)
|
|
|
|
amqp_ssl_socket_set_cacert(sock, ssl->ca_cert);
|
2017-10-16 09:40:27 +02:00
|
|
|
|
2017-11-18 01:05:18 +01:00
|
|
|
if (ssl->client_key && ssl->client_cert)
|
|
|
|
amqp_ssl_socket_set_key(sock, ssl->client_cert, ssl->client_key);
|
2017-10-16 09:40:27 +02:00
|
|
|
}
|
2017-11-18 01:05:18 +01:00
|
|
|
else {
|
|
|
|
sock = amqp_tcp_socket_new(conn);
|
|
|
|
if (!sock)
|
2019-04-22 23:45:38 +02:00
|
|
|
return nullptr;
|
2017-11-18 01:05:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = amqp_socket_open(sock, ci->host, ci->port);
|
|
|
|
if (ret != AMQP_STATUS_OK)
|
2019-04-22 23:45:38 +02:00
|
|
|
return nullptr;
|
2017-11-18 01:05:18 +01:00
|
|
|
|
|
|
|
rep = amqp_login(conn, ci->vhost, 0, 131072, 0, AMQP_SASL_METHOD_PLAIN, ci->user, ci->password);
|
|
|
|
if (rep.reply_type != AMQP_RESPONSE_NORMAL)
|
2019-04-22 23:45:38 +02:00
|
|
|
return nullptr;
|
2017-11-18 01:05:18 +01:00
|
|
|
|
|
|
|
amqp_channel_open(conn, 1);
|
|
|
|
rep = amqp_get_rpc_reply(conn);
|
|
|
|
if (rep.reply_type != AMQP_RESPONSE_NORMAL)
|
2019-04-22 23:45:38 +02:00
|
|
|
return nullptr;
|
2017-11-18 01:05:18 +01:00
|
|
|
|
|
|
|
return conn;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int amqp_close(amqp_connection_state_t conn)
|
|
|
|
{
|
|
|
|
amqp_rpc_reply_t rep;
|
|
|
|
|
|
|
|
rep = amqp_channel_close(conn, 1, AMQP_REPLY_SUCCESS);
|
|
|
|
if (rep.reply_type != AMQP_RESPONSE_NORMAL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
rep = amqp_connection_close(conn, AMQP_REPLY_SUCCESS);
|
|
|
|
if (rep.reply_type != AMQP_RESPONSE_NORMAL)
|
|
|
|
return -1;
|
2017-10-16 09:40:27 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-08-25 21:00:52 +02:00
|
|
|
int amqp_parse(struct vnode *n, json_t *json)
|
2017-10-16 09:40:27 +02:00
|
|
|
{
|
|
|
|
int ret;
|
2019-04-22 23:43:46 +02:00
|
|
|
struct amqp *a = (struct amqp *) n->_vd;
|
2017-10-16 09:40:27 +02:00
|
|
|
|
2018-04-26 09:53:35 +02:00
|
|
|
int port = 5672;
|
2019-04-22 23:45:38 +02:00
|
|
|
const char *uri = nullptr;
|
2018-04-26 09:53:35 +02:00
|
|
|
const char *host = "localhost";
|
|
|
|
const char *vhost = "/";
|
|
|
|
const char *username = "guest";
|
|
|
|
const char *password = "guest";
|
2017-11-18 01:05:18 +01:00
|
|
|
const char *exchange, *routing_key;
|
2017-10-16 09:40:27 +02:00
|
|
|
|
|
|
|
json_error_t err;
|
|
|
|
|
2019-04-22 23:45:38 +02:00
|
|
|
json_t *json_ssl = nullptr;
|
2021-05-10 00:12:30 +02:00
|
|
|
json_t *json_format = nullptr;
|
2017-10-16 09:40:27 +02:00
|
|
|
|
|
|
|
/* Default values */
|
2017-11-18 01:05:18 +01:00
|
|
|
amqp_default_ssl_info(&a->ssl_info);
|
2017-10-16 09:40:27 +02:00
|
|
|
amqp_default_connection_info(&a->connection_info);
|
|
|
|
|
2021-05-10 00:12:30 +02:00
|
|
|
ret = json_unpack_ex(json, &err, 0, "{ s?: s, s?: s, s?: s, s?: s, s?: s, s?: i, s: s, s: s, s?: o, s?: o }",
|
2017-10-16 09:40:27 +02:00
|
|
|
"uri", &uri,
|
2018-04-26 09:53:35 +02:00
|
|
|
"host", &host,
|
|
|
|
"vhost", &vhost,
|
|
|
|
"username", &username,
|
|
|
|
"password", &password,
|
|
|
|
"port", &port,
|
2017-10-16 09:40:27 +02:00
|
|
|
"exchange", &exchange,
|
|
|
|
"routing_key", &routing_key,
|
2021-05-10 00:12:30 +02:00
|
|
|
"format", &json_format,
|
2017-11-18 01:05:18 +01:00
|
|
|
"ssl", &json_ssl
|
2017-10-16 09:40:27 +02:00
|
|
|
);
|
|
|
|
if (ret)
|
2021-02-16 14:15:14 +01:00
|
|
|
throw ConfigError(json, err, "node-config-node-amqp");
|
2017-10-16 09:40:27 +02:00
|
|
|
|
2017-11-18 01:05:18 +01:00
|
|
|
a->exchange = amqp_bytes_strdup(exchange);
|
|
|
|
a->routing_key = amqp_bytes_strdup(routing_key);
|
|
|
|
|
2018-04-26 09:53:35 +02:00
|
|
|
if (uri)
|
2017-11-18 01:05:18 +01:00
|
|
|
a->uri = strdup(uri);
|
2018-04-26 09:53:35 +02:00
|
|
|
else
|
2018-06-16 21:29:28 +02:00
|
|
|
a->uri = strf("amqp://%s:%s@%s:%d/%s", username, password, host, port, vhost);
|
2017-11-18 01:05:18 +01:00
|
|
|
|
2018-04-26 09:53:35 +02:00
|
|
|
ret = amqp_parse_url(a->uri, &a->connection_info);
|
|
|
|
if (ret != AMQP_STATUS_OK)
|
2021-02-16 14:15:14 +01:00
|
|
|
throw ConfigError(json, "node-config-node-uri", "Failed to parse URI '{}'", uri);
|
2017-10-16 09:40:27 +02:00
|
|
|
|
2017-11-18 01:05:18 +01:00
|
|
|
if (json_ssl) {
|
2019-04-22 23:45:38 +02:00
|
|
|
const char *ca_cert = nullptr;
|
|
|
|
const char *client_cert = nullptr;
|
|
|
|
const char *client_key = nullptr;
|
2017-11-18 01:05:18 +01:00
|
|
|
|
|
|
|
ret = json_unpack_ex(json_ssl, &err, 0, "{ s?: b, s?: b, s?: s, s?: s, s?: s }",
|
|
|
|
"verify_peer", &a->ssl_info.verify_peer,
|
|
|
|
"verify_hostname", &a->ssl_info.verify_hostname,
|
|
|
|
"ca_cert", &ca_cert,
|
|
|
|
"client_key", &client_key,
|
|
|
|
"client_cert", &client_cert
|
|
|
|
);
|
|
|
|
if (ret)
|
2021-02-16 14:15:14 +01:00
|
|
|
throw ConfigError(json_ssl, err, "node-config-node-amqp-ssl", "Failed to parse SSL configuration");
|
2017-11-18 01:05:18 +01:00
|
|
|
|
|
|
|
if (ca_cert)
|
|
|
|
a->ssl_info.ca_cert = strdup(ca_cert);
|
|
|
|
|
|
|
|
if (client_cert)
|
|
|
|
a->ssl_info.client_cert = strdup(client_cert);
|
|
|
|
|
|
|
|
if (client_key)
|
|
|
|
a->ssl_info.client_key = strdup(client_key);
|
2017-10-16 09:40:27 +02:00
|
|
|
}
|
|
|
|
|
2021-05-10 00:12:30 +02:00
|
|
|
/* Format */
|
|
|
|
a->formatter = json_format
|
|
|
|
? FormatFactory::make(json_format)
|
|
|
|
: FormatFactory::make("json");
|
|
|
|
if (!a->formatter)
|
|
|
|
throw ConfigError(json_format, "node-config-node-amqp-format", "Invalid format configuration");
|
2017-10-16 09:40:27 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-08-25 21:00:52 +02:00
|
|
|
char * amqp_print(struct vnode *n)
|
2017-10-16 09:40:27 +02:00
|
|
|
{
|
2019-04-22 23:43:46 +02:00
|
|
|
struct amqp *a = (struct amqp *) n->_vd;
|
2017-10-16 09:40:27 +02:00
|
|
|
|
2019-04-22 23:45:38 +02:00
|
|
|
char *buf = nullptr;
|
2017-10-16 09:40:27 +02:00
|
|
|
|
2021-05-10 00:12:30 +02:00
|
|
|
strcatf(&buf, "uri=%s://%s:%s@%s:%d%s, exchange=%s, routing_key=%s",
|
2017-11-18 01:05:18 +01:00
|
|
|
a->connection_info.ssl ? "amqps" : "amqp",
|
2017-10-16 09:40:27 +02:00
|
|
|
a->connection_info.user,
|
|
|
|
a->connection_info.password,
|
|
|
|
a->connection_info.host,
|
|
|
|
a->connection_info.port,
|
|
|
|
a->connection_info.vhost,
|
2017-11-18 01:05:18 +01:00
|
|
|
(char *) a->exchange.bytes,
|
|
|
|
(char *) a->routing_key.bytes
|
2017-10-16 09:40:27 +02:00
|
|
|
);
|
|
|
|
|
2017-11-18 01:05:18 +01:00
|
|
|
if (a->connection_info.ssl) {
|
|
|
|
strcatf(&buf, ", ssl_info.verify_peer=%s, ssl_info.verify_hostname=%s",
|
|
|
|
a->ssl_info.verify_peer ? "true" : "false",
|
|
|
|
a->ssl_info.verify_hostname ? "true" : "false"
|
|
|
|
);
|
|
|
|
|
|
|
|
if (a->ssl_info.ca_cert)
|
|
|
|
strcatf(&buf, ", ssl_info.ca_cert=%s", a->ssl_info.ca_cert);
|
|
|
|
|
|
|
|
if (a->ssl_info.client_cert)
|
|
|
|
strcatf(&buf, ", ssl_info.client_cert=%s", a->ssl_info.client_cert);
|
|
|
|
|
|
|
|
if (a->ssl_info.client_key)
|
|
|
|
strcatf(&buf, ", ssl_info.client_key=%s", a->ssl_info.client_key);
|
|
|
|
}
|
|
|
|
|
2017-10-16 09:40:27 +02:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2020-08-25 21:00:52 +02:00
|
|
|
int amqp_start(struct vnode *n)
|
2017-10-16 09:40:27 +02:00
|
|
|
{
|
2019-04-22 23:43:46 +02:00
|
|
|
struct amqp *a = (struct amqp *) n->_vd;
|
2017-10-16 09:40:27 +02:00
|
|
|
|
2017-11-18 01:05:18 +01:00
|
|
|
amqp_bytes_t queue;
|
|
|
|
amqp_rpc_reply_t rep;
|
|
|
|
amqp_queue_declare_ok_t *r;
|
2017-10-16 09:40:27 +02:00
|
|
|
|
2021-05-10 00:12:30 +02:00
|
|
|
a->formatter->start(&n->in.signals, ~(int) SampleFlags::HAS_OFFSET);
|
2018-08-20 18:30:01 +02:00
|
|
|
|
2017-11-18 01:05:18 +01:00
|
|
|
/* Connect producer */
|
|
|
|
a->producer = amqp_connect(&a->connection_info, &a->ssl_info);
|
|
|
|
if (!a->producer)
|
2017-10-16 09:40:27 +02:00
|
|
|
return -1;
|
|
|
|
|
2017-11-18 01:05:18 +01:00
|
|
|
/* Connect consumer */
|
|
|
|
a->consumer = amqp_connect(&a->connection_info, &a->ssl_info);
|
|
|
|
if (!a->consumer)
|
|
|
|
return -1;
|
2017-10-16 09:40:27 +02:00
|
|
|
|
2017-11-18 01:05:18 +01:00
|
|
|
/* Declare exchange */
|
|
|
|
amqp_exchange_declare(a->producer, 1, a->exchange, amqp_cstring_bytes("direct"), 0, 0, 0, 0, amqp_empty_table);
|
|
|
|
rep = amqp_get_rpc_reply(a->consumer);
|
|
|
|
if (rep.reply_type != AMQP_RESPONSE_NORMAL)
|
|
|
|
return -1;
|
2017-10-16 09:40:27 +02:00
|
|
|
|
2017-11-18 01:05:18 +01:00
|
|
|
/* Declare private queue */
|
|
|
|
r = amqp_queue_declare(a->consumer, 1, amqp_empty_bytes, 0, 0, 0, 1, amqp_empty_table);
|
|
|
|
rep = amqp_get_rpc_reply(a->consumer);
|
|
|
|
if (rep.reply_type != AMQP_RESPONSE_NORMAL)
|
|
|
|
return -1;
|
2017-10-16 09:40:27 +02:00
|
|
|
|
2017-11-18 01:05:18 +01:00
|
|
|
queue = amqp_bytes_malloc_dup(r->queue);
|
2019-04-22 23:45:38 +02:00
|
|
|
if (queue.bytes == nullptr)
|
2017-11-18 01:05:18 +01:00
|
|
|
return -1;
|
2017-10-16 09:40:27 +02:00
|
|
|
|
2017-11-18 01:05:18 +01:00
|
|
|
/* Bind queue to exchange */
|
|
|
|
amqp_queue_bind(a->consumer, 1, queue, a->exchange, a->routing_key, amqp_empty_table);
|
|
|
|
rep = amqp_get_rpc_reply(a->consumer);
|
|
|
|
if (rep.reply_type != AMQP_RESPONSE_NORMAL)
|
2017-10-16 09:40:27 +02:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Start consumer */
|
2017-11-18 01:05:18 +01:00
|
|
|
amqp_basic_consume(a->consumer, 1, queue, amqp_empty_bytes, 0, 1, 0, amqp_empty_table);
|
|
|
|
rep = amqp_get_rpc_reply(a->consumer);
|
|
|
|
if (rep.reply_type != AMQP_RESPONSE_NORMAL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
amqp_bytes_free(queue);
|
2017-10-16 09:40:27 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-08-25 21:00:52 +02:00
|
|
|
int amqp_stop(struct vnode *n)
|
2017-10-16 09:40:27 +02:00
|
|
|
{
|
|
|
|
int ret;
|
2019-04-22 23:43:46 +02:00
|
|
|
struct amqp *a = (struct amqp *) n->_vd;
|
2017-10-16 09:40:27 +02:00
|
|
|
|
2017-11-18 01:05:18 +01:00
|
|
|
ret = amqp_close(a->consumer);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2017-10-16 09:40:27 +02:00
|
|
|
|
2017-11-18 01:05:18 +01:00
|
|
|
ret = amqp_close(a->producer);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2017-10-16 09:40:27 +02:00
|
|
|
|
2021-05-10 00:12:30 +02:00
|
|
|
delete a->formatter;
|
2018-08-20 18:30:01 +02:00
|
|
|
|
2017-10-16 09:40:27 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-05-10 00:12:30 +02:00
|
|
|
int amqp_read(struct vnode *n, struct sample * const smps[], unsigned cnt)
|
2017-10-16 09:40:27 +02:00
|
|
|
{
|
2017-11-18 01:05:18 +01:00
|
|
|
int ret;
|
2019-04-22 23:43:46 +02:00
|
|
|
struct amqp *a = (struct amqp *) n->_vd;
|
2017-11-18 01:05:18 +01:00
|
|
|
amqp_envelope_t env;
|
|
|
|
amqp_rpc_reply_t rep;
|
2017-10-16 09:40:27 +02:00
|
|
|
|
2019-04-22 23:45:38 +02:00
|
|
|
rep = amqp_consume_message(a->consumer, &env, nullptr, 0);
|
2017-11-18 01:05:18 +01:00
|
|
|
if (rep.reply_type != AMQP_RESPONSE_NORMAL)
|
|
|
|
return -1;
|
|
|
|
|
2021-05-10 00:12:30 +02:00
|
|
|
ret = a->formatter->sscan(static_cast<char *>(env.message.body.bytes), env.message.body.len, nullptr, smps, cnt);
|
2017-10-16 09:40:27 +02:00
|
|
|
|
2017-11-18 01:05:18 +01:00
|
|
|
amqp_destroy_envelope(&env);
|
2017-10-16 09:40:27 +02:00
|
|
|
|
2017-11-18 01:05:18 +01:00
|
|
|
return ret;
|
2017-10-16 09:40:27 +02:00
|
|
|
}
|
|
|
|
|
2021-05-10 00:12:30 +02:00
|
|
|
int amqp_write(struct vnode *n, struct sample * const smps[], unsigned cnt)
|
2017-10-16 09:40:27 +02:00
|
|
|
{
|
|
|
|
int ret;
|
2019-04-22 23:43:46 +02:00
|
|
|
struct amqp *a = (struct amqp *) n->_vd;
|
2017-11-18 01:05:18 +01:00
|
|
|
char data[1500];
|
2017-10-16 09:40:27 +02:00
|
|
|
size_t wbytes;
|
|
|
|
|
2021-05-10 00:12:30 +02:00
|
|
|
ret = a->formatter->sprint(data, sizeof(data), &wbytes, smps, cnt);
|
2017-10-16 09:40:27 +02:00
|
|
|
if (ret <= 0)
|
|
|
|
return -1;
|
|
|
|
|
2017-11-18 01:05:18 +01:00
|
|
|
amqp_bytes_t message = {
|
|
|
|
.len = wbytes,
|
|
|
|
.bytes = data
|
|
|
|
};
|
|
|
|
|
2017-10-16 09:40:27 +02:00
|
|
|
/* Send message */
|
2017-11-18 01:05:18 +01:00
|
|
|
ret = amqp_basic_publish(a->producer, 1,
|
|
|
|
a->exchange,
|
|
|
|
a->routing_key,
|
2019-04-22 23:45:38 +02:00
|
|
|
0, 0, nullptr, message);
|
2017-10-16 09:40:27 +02:00
|
|
|
|
|
|
|
if (ret != AMQP_STATUS_OK)
|
|
|
|
return -1;
|
|
|
|
|
2018-07-11 18:14:29 +02:00
|
|
|
return cnt;
|
2017-10-16 09:40:27 +02:00
|
|
|
}
|
|
|
|
|
2020-08-25 21:00:52 +02:00
|
|
|
int amqp_poll_fds(struct vnode *n, int fds[])
|
2017-10-16 09:40:27 +02:00
|
|
|
{
|
2019-04-22 23:43:46 +02:00
|
|
|
struct amqp *a = (struct amqp *) n->_vd;
|
2017-10-16 09:40:27 +02:00
|
|
|
|
2017-11-18 01:05:18 +01:00
|
|
|
amqp_socket_t *sock = amqp_get_socket(a->consumer);
|
|
|
|
|
2019-01-21 15:47:34 +01:00
|
|
|
fds[0] = amqp_socket_get_sockfd(sock);
|
|
|
|
|
|
|
|
return 1;
|
2017-11-18 01:05:18 +01:00
|
|
|
}
|
|
|
|
|
2020-08-25 21:00:52 +02:00
|
|
|
int amqp_destroy(struct vnode *n)
|
2017-11-18 01:05:18 +01:00
|
|
|
{
|
2019-04-22 23:43:46 +02:00
|
|
|
struct amqp *a = (struct amqp *) n->_vd;
|
2017-11-18 01:05:18 +01:00
|
|
|
|
|
|
|
if (a->uri)
|
|
|
|
free(a->uri);
|
|
|
|
|
|
|
|
if (a->ssl_info.client_cert)
|
|
|
|
free(a->ssl_info.client_cert);
|
|
|
|
|
|
|
|
if (a->ssl_info.client_key)
|
|
|
|
free(a->ssl_info.client_key);
|
|
|
|
|
|
|
|
if (a->ssl_info.ca_cert)
|
|
|
|
free(a->ssl_info.ca_cert);
|
|
|
|
|
|
|
|
if (a->producer)
|
|
|
|
amqp_destroy_connection(a->producer);
|
|
|
|
|
|
|
|
if (a->consumer)
|
|
|
|
amqp_destroy_connection(a->consumer);
|
|
|
|
|
|
|
|
return 0;
|
2017-10-16 09:40:27 +02:00
|
|
|
}
|
|
|
|
|
2021-06-21 16:11:42 -04:00
|
|
|
static struct vnode_type p;
|
2019-04-23 00:36:06 +02:00
|
|
|
|
|
|
|
__attribute__((constructor(110)))
|
|
|
|
static void register_plugin() {
|
2021-06-21 16:11:42 -04:00
|
|
|
p.name = "amqp";
|
|
|
|
p.description = "Advanced Message Queueing Protoocl (rabbitmq-c)";
|
|
|
|
p.vectorize = 0;
|
|
|
|
p.size = sizeof(struct amqp);
|
|
|
|
p.destroy = amqp_destroy;
|
|
|
|
p.parse = amqp_parse;
|
|
|
|
p.print = amqp_print;
|
|
|
|
p.start = amqp_start;
|
|
|
|
p.stop = amqp_stop;
|
|
|
|
p.read = amqp_read;
|
|
|
|
p.write = amqp_write;
|
|
|
|
p.poll_fds = amqp_poll_fds;
|
|
|
|
|
|
|
|
if (!node_types)
|
|
|
|
node_types = new NodeTypeList();
|
|
|
|
|
|
|
|
node_types->push_back(&p);
|
2019-04-23 00:36:06 +02:00
|
|
|
}
|