// SPDX-License-Identifier: GPL-3.0-or-later
#include "pluginsd_parser.h"
#define LOG_FUNCTIONS false
static int send_to_plugin(const char *txt, void *data) {
PARSER *parser = data;
if(!txt || !*txt)
return 0;
#ifdef ENABLE_HTTPS
struct netdata_ssl *ssl = parser->ssl_output;
if(ssl) {
if(ssl->conn && ssl->flags == NETDATA_SSL_HANDSHAKE_COMPLETE)
return (int)netdata_ssl_write(ssl->conn, (void *)txt, strlen(txt));
error("PLUGINSD: cannot send command (SSL)");
return -1;
}
#endif
if(parser->fp_output) {
int bytes = fprintf(parser->fp_output, "%s", txt);
if(bytes <= 0) {
error("PLUGINSD: cannot send command (FILE)");
return -2;
}
fflush(parser->fp_output);
return bytes;
}
if(parser->fd != -1) {
size_t bytes = 0;
size_t total = strlen(txt);
ssize_t sent;
do {
sent = write(parser->fd, &txt[bytes], total - bytes);
if(sent <= 0) {
error("PLUGINSD: cannot send command (fd)");
return -3;
}
bytes +=