#ifdef __VOS__
#define _POSIX_C_SOURCE 200112L
#include <sys/time.h>
#endif
#include <stdio.h>
#include <time.h>
#include <string.h>
#ifdef _WIN32
#define strcasecmp stricmp
#define snprintf _snprintf
#else
#include "config.h"
#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#if defined(__TANDEM)
#if defined(HAVE_TANDEM_SPT)
#include <ktdmtyp.h>
#include <spthread.h>
#else
#include <pthread.h>
#endif
#else
#include <pthread.h>
#endif
#include <strings.h>
#endif
#include <lbm/lbmmontrlbm.h>
{
lbmmon_transport_lbm_initsrc,
lbmmon_transport_lbm_initrcv,
lbmmon_transport_lbm_send,
lbmmon_transport_lbm_receive,
lbmmon_transport_lbm_src_finish,
lbmmon_transport_lbm_rcv_finish,
lbmmon_transport_lbm_errmsg,
lbmmon_transport_lbm_ctrlmsgtarget,
lbmmon_transport_lbm_ctrlmsg_receive,
lbmmon_transport_lbm_ctrlmsg_response,
lbmmon_transport_allow_debug
};
struct lbmmon_transport_lbm_rcv_node_t_stct
{
size_t mUsedBytes;
struct lbmmon_transport_lbm_rcv_node_t_stct * mNext;
};
typedef struct lbmmon_transport_lbm_rcv_node_t_stct lbmmon_transport_lbm_rcv_node_t;
typedef struct
{
unsigned int mLockCreated;
#ifdef _WIN32
CRITICAL_SECTION mLock;
#else
pthread_mutex_t mLock;
#endif
lbmmon_transport_lbm_rcv_node_t * mHead;
lbmmon_transport_lbm_rcv_node_t * mTail;
int mAllowDebug;
} lbmmon_transport_lbm_clientd_t;
static void cleanup_clientd(lbmmon_transport_lbm_clientd_t * Data);
static int receive_callback(
lbm_rcv_t * Receiver,
lbm_msg_t * Message,
void * ClientData);
static void lock(lbmmon_transport_lbm_clientd_t * Receiver);
static void unlock(lbmmon_transport_lbm_clientd_t * Receiver);
static int scope_is_valid(const char * Scope);
#define DEFAULT_CONTEXT_NAME "29west_statistics_context"
#define DEFAULT_TOPIC "/29west/statistics"
static char ErrorString[2048];
static char RequestTargetAddress[80];
typedef struct
{
const char * option;
const char * value;
} option_entry_t;
static option_entry_t SourceContextOption[] =
{
{ "operational_mode", "embedded" },
{ "monitor_interval", "0" },
{ "mim_incoming_address", "0.0.0.0" },
{ "resolver_cache", "0" },
{ NULL, NULL }
};
static option_entry_t ReceiverContextOption[] =
{
{ "operational_mode", "embedded" },
{ "monitor_interval", "0" },
{ "request_tcp_bind_request_port", "0" },
{ "mim_incoming_address", "0.0.0.0" },
{ "resolver_cache", "0" },
{ NULL, NULL }
};
static option_entry_t SourceTopicOption[] =
{
{ "transport_lbtru_transmission_window_size", "500000" },
{ "transport_lbtrm_transmission_window_size", "500000" },
{ NULL, NULL }
};
static option_entry_t ReceiverTopicOption[] =
{
{ NULL, NULL }
};
static option_entry_t WildcardReceiverOption[] =
{
{ NULL, NULL }
};
static void lbmmon_transport_lbm_report_allocation_error(size_t Size)
{
snprintf(ErrorString, sizeof(ErrorString), "Unable to allocate %u bytes", (unsigned) Size);
}
lbmmon_transport_lbm_module(void)
{
return (&LBMMON_TRANSPORT_LBM);
}
{
lbmmon_transport_lbm_clientd_t * src = (lbmmon_transport_lbm_clientd_t *)ClientData;
lbmmon_transport_lbm_rcv_node_t * node;
{
lock(src);
node = malloc(sizeof(lbmmon_transport_lbm_rcv_node_t));
if (node == NULL)
{
lbmmon_transport_lbm_report_allocation_error(sizeof(lbmmon_transport_lbm_rcv_node_t));
return (-1);
}
node->mMessage = Message;
node->mUsedBytes = 0;
node->mNext = NULL;
if (src->mTail != NULL)
{
src->mTail->mNext = node;
} else
{
src->mHead = node;
}
src->mTail = node;
unlock(src);
} else {
}
return (0);
}
int
lbmmon_transport_lbm_initsrc(void * * TransportClientData, const void * TransportOptions)
{
lbmmon_transport_lbm_clientd_t * data;
int rc;
const char * ptr = (const char *) TransportOptions;
char key[512];
char value[512];
char config_file[512];
char topic[512];
char scope[512];
char option[512];
option_entry_t * entry;
size_t optlen;
unsigned short int request_port;
int request_port_bound;
struct in_addr inaddr;
memset(ErrorString, 0, sizeof(ErrorString));
memset(RequestTargetAddress, 0, sizeof(RequestTargetAddress));
data = malloc(sizeof(lbmmon_transport_lbm_clientd_t));
if (data == NULL)
{
lbmmon_transport_lbm_report_allocation_error(sizeof(lbmmon_transport_lbm_clientd_t));
return (-1);
}
memset(data, 0, sizeof(lbmmon_transport_lbm_clientd_t));
memset(config_file, 0, sizeof(config_file));
strncpy(topic, DEFAULT_TOPIC, sizeof(topic));
{
if (strcasecmp(key, "config") == 0)
{
strncpy(config_file, value, sizeof(config_file));
}
else if (strcasecmp(key, "topic") == 0)
{
strncpy(topic, value, sizeof(topic));
}
else if (strcasecmp(key, "allow_debug") == 0)
{
if (strcasecmp(value, "on") == 0)
{
data->mAllowDebug = 1;
}
else if (strcasecmp(value, "off") == 0)
{
data->mAllowDebug = 0;
}
else
{
snprintf(ErrorString,
sizeof(ErrorString),
"invalid allow_debug argument [%s], argument must be \"on\" or \"off\"", value);
}
}
}
{
snprintf(ErrorString,
sizeof(ErrorString),
"lbm_context_attr_create() failed, %s",
return (rc);
}
{
snprintf(ErrorString,
sizeof(ErrorString),
"lbm_context_attr_str_setopt() failed, %s",
return (rc);
}
{
snprintf(ErrorString,
sizeof(ErrorString),
"lbm_context_attr_str_setopt() failed, %s",
return (rc);
}
if (config_file[0] != '\0')
{
if (rc != 0)
{
snprintf(ErrorString,
sizeof(ErrorString),
"lbmaux_context_attr_setopt_from_file() failed, %s",
cleanup_clientd(data);
return (-1);
}
}
ptr = (const char *) TransportOptions;
{
if (sscanf(key, "%[a-zA-Z_]|%[a-zA-Z_]", scope, option) != 2)
{
continue;
}
if (scope_is_valid(scope) == -1)
{
snprintf(ErrorString,
sizeof(ErrorString),
"invalid option scope [%s]",
scope);
cleanup_clientd(data);
return (-1);
}
if (strcasecmp(scope, "context") == 0)
{
{
snprintf(ErrorString,
sizeof(ErrorString),
"invalid option [context %s %s], %s",
option,
value,
cleanup_clientd(data);
return (rc);
}
}
}
entry = &SourceContextOption[0];
while (entry->option != NULL)
{
{
snprintf(ErrorString,
sizeof(ErrorString),
"error setting option [context %s %s], %s",
entry->option,
entry->value,
cleanup_clientd(data);
return (rc);
}
entry++;
}
{
topicless_im_rcv_func.
clientd = data;
topicless_im_rcv_func.
evq = NULL;
topicless_im_rcv_func.
func = handle_immediate_msg;
&topicless_im_rcv_func, sizeof(topicless_im_rcv_func));
{
snprintf(ErrorString,
sizeof(ErrorString),
"lbm_context_rcv_immediate_msgs: %s",
cleanup_clientd(data);
return (rc);
}
}
#ifdef _WIN32
InitializeCriticalSection(&(data->mLock));
#else
pthread_mutex_init(&(data->mLock), NULL);
#endif
data->mLockCreated = 1;
lock(data);
{
snprintf(ErrorString,
sizeof(ErrorString),
"lbm_context_create() failed, %s",
unlock(data);
cleanup_clientd(data);
return (rc);
}
optlen = sizeof(request_port_bound);
"request_tcp_bind_request_port",
&request_port_bound,
{
snprintf(ErrorString,
sizeof(ErrorString),
"lbm_context_getopt(request_tcp_bind_request_port): %s",
unlock(data);
cleanup_clientd(data);
return (rc);
}
if (request_port_bound == 1) {
optlen = sizeof(request_port);
"request_tcp_port",
&request_port,
{
snprintf(ErrorString,
sizeof(ErrorString),
"lbm_context_getopt(request_tcp_port): %s",
unlock(data);
cleanup_clientd(data);
return (rc);
}
optlen = sizeof(unicast_target_iface);
"request_tcp_interface",
&unicast_target_iface,
{
snprintf(ErrorString,
sizeof(ErrorString),
"lbm_context_getopt(request_tcp_interface): %s",
unlock(data);
cleanup_clientd(data);
return (rc);
}
if (unicast_target_iface.
addr == INADDR_ANY) {
"resolver_multicast_interface",
&unicast_target_iface,
{
snprintf(ErrorString,
sizeof(ErrorString),
"lbm_context_getopt(resolver_multicast_interface): %s",
unlock(data);
cleanup_clientd(data);
return (rc);
}
}
inaddr.s_addr = unicast_target_iface.
addr;
snprintf(RequestTargetAddress, sizeof(RequestTargetAddress), "TCP:%s:%d", inet_ntoa(inaddr), ntohs(request_port));
}
{
snprintf(ErrorString,
sizeof(ErrorString),
"lbm_src_topic_attr_create_default() failed, %s",
unlock(data);
cleanup_clientd(data);
return (rc);
}
entry = &SourceTopicOption[0];
while (entry->option != NULL)
{
{
snprintf(ErrorString,
sizeof(ErrorString),
"error setting option [source %s %s], %s",
entry->option,
entry->value,
unlock(data);
cleanup_clientd(data);
return (rc);
}
entry++;
}
if (config_file[0] != '\0')
{
if (rc != 0)
{
snprintf(ErrorString,
sizeof(ErrorString),
"lbmaux_src_topic_attr_setopt_from_file() failed, %s",
unlock(data);
cleanup_clientd(data);
return (-1);
}
}
ptr = (const char *) TransportOptions;
{
if (sscanf(key, "%[a-zA-Z_]|%[a-zA-Z_]", scope, option) != 2)
{
continue;
}
if (strcasecmp(scope, "source") == 0)
{
{
snprintf(ErrorString,
sizeof(ErrorString),
"invalid option [source %s %s], %s",
option,
value,
unlock(data);
cleanup_clientd(data);
return (rc);
}
}
}
rc =
lbm_src_topic_alloc(&(data->mTopic), data->mContext, topic, data->mSourceTopicAttributes);
{
snprintf(ErrorString,
sizeof(ErrorString),
"lbm_src_topic_alloc() failed, %s",
unlock(data);
cleanup_clientd(data);
return (rc);
}
rc =
lbm_src_create(&(data->mSource), data->mContext, data->mTopic, NULL, NULL, NULL);
{
snprintf(ErrorString,
sizeof(ErrorString),
"lbm_src_create() failed, %s",
unlock(data);
cleanup_clientd(data);
return (rc);
}
*TransportClientData = data;
unlock(data);
return (0);
}
int
{
lbmmon_transport_lbm_clientd_t * rcv = (lbmmon_transport_lbm_clientd_t *) ClientData;
lbmmon_transport_lbm_rcv_node_t * node;
{
lock(rcv);
node = malloc(sizeof(lbmmon_transport_lbm_rcv_node_t));
if (node == NULL)
{
lbmmon_transport_lbm_report_allocation_error(sizeof(lbmmon_transport_lbm_rcv_node_t));
return (-1);
}
node->mMessage = Message;
node->mUsedBytes = 0;
node->mNext = NULL;
if (rcv->mTail != NULL)
{
rcv->mTail->mNext = node;
}
else
{
rcv->mHead = node;
}
rcv->mTail = node;
unlock(rcv);
}
return (0);
}
int
lbmmon_transport_lbm_initrcv(void * * TransportClientData, const void * TransportOptions)
{
lbmmon_transport_lbm_clientd_t * data;
int rc;
const char * ptr = (const char *) TransportOptions;
char key[512];
char value[512];
char config_file[512];
char topic[512];
char wildcard_topic[512];
char scope[512];
char option[512];
option_entry_t * entry;
memset(ErrorString, 0, sizeof(ErrorString));
data = malloc(sizeof(lbmmon_transport_lbm_clientd_t));
if (data == NULL)
{
lbmmon_transport_lbm_report_allocation_error(sizeof(lbmmon_transport_lbm_clientd_t));
return (-1);
}
memset(data, 0, sizeof(lbmmon_transport_lbm_clientd_t));
memset(config_file, 0, sizeof(config_file));
strncpy(topic, DEFAULT_TOPIC, sizeof(topic));
memset(wildcard_topic, 0, sizeof(wildcard_topic));
{
if (strcasecmp(key, "config") == 0)
{
strncpy(config_file, value, sizeof(config_file));
}
else if (strcasecmp(key, "topic") == 0)
{
strncpy(topic, value, sizeof(topic));
}
else if (strcasecmp(key, "wctopic") == 0)
{
strncpy(wildcard_topic, value, sizeof(wildcard_topic));
}
}
{
snprintf(ErrorString,
sizeof(ErrorString),
"lbm_context_attr_create() failed, %s",
cleanup_clientd(data);
return (rc);
}
{
snprintf(ErrorString,
sizeof(ErrorString),
"lbm_context_attr_str_setopt() failed, %s",
return (rc);
}
if (config_file[0] != '\0')
{
if (rc != 0)
{
snprintf(ErrorString,
sizeof(ErrorString),
"lbmaux_context_attr_setopt_from_file() failed, %s",
cleanup_clientd(data);
return (-1);
}
}
ptr = (const char *) TransportOptions;
{
if (sscanf(key, "%[a-zA-Z_]|%[a-zA-Z_]", scope, option) != 2)
{
continue;
}
if (scope_is_valid(scope) == -1)
{
snprintf(ErrorString,
sizeof(ErrorString),
"invalid option scope [%s]",
scope);
cleanup_clientd(data);
return (-1);
}
if (strcasecmp(scope, "context") == 0)
{
{
snprintf(ErrorString,
sizeof(ErrorString),
"invalid option [context %s %s], %s",
option,
value,
cleanup_clientd(data);
return (rc);
}
}
}
entry = &ReceiverContextOption[0];
while (entry->option != NULL)
{
{
snprintf(ErrorString,
sizeof(ErrorString),
"error setting option [context %s %s], %s",
entry->option,
entry->value,
cleanup_clientd(data);
return (rc);
}
entry++;
}
if (wildcard_topic[0] != '\0')
{
{
snprintf(ErrorString,
sizeof(ErrorString),
"error setting option [context %s %s], %s",
"resolver_cache",
"1",
cleanup_clientd(data);
return (rc);
}
}
{
snprintf(ErrorString,
sizeof(ErrorString),
"lbm_context_create() failed, %s",
cleanup_clientd(data);
return (rc);
}
if (wildcard_topic[0] != '\0')
{
{
snprintf(ErrorString,
sizeof(ErrorString),
"lbm_wildcard_rcv_attr_init() failed, %s",
cleanup_clientd(data);
return (rc);
}
if (config_file[0] != '\0')
{
{
snprintf(ErrorString,
sizeof(ErrorString),
"lbmaux_wildcard_rcv_attr_setopt_from_file() failed, %s",
cleanup_clientd(data);
return (-1);
}
}
ptr = (const char *) TransportOptions;
{
if (sscanf(key, "%[a-zA-Z_]|%[a-zA-Z_]", scope, option) != 2)
{
continue;
}
if (strcasecmp(scope, "wildcard_receiver") == 0)
{
{
snprintf(ErrorString,
sizeof(ErrorString),
"invalid option [wildcard_receiver %s %s], %s",
option,
value,
cleanup_clientd(data);
return (rc);
}
}
}
entry = &WildcardReceiverOption[0];
while (entry->option != NULL)
{
{
snprintf(ErrorString,
sizeof(ErrorString),
"error setting option [wildcard_receiver %s %s], %s",
entry->option,
entry->value,
cleanup_clientd(data);
return (rc);
}
entry++;
}
}
{
snprintf(ErrorString,
sizeof(ErrorString),
"lbm_rcv_topic_attr_init() failed, %s",
cleanup_clientd(data);
return (rc);
}
if (config_file[0] != '\0')
{
{
snprintf(ErrorString,
sizeof(ErrorString),
"lbmaux_rcv_topic_attr_setopt_from_file() failed, %s",
cleanup_clientd(data);
return (-1);
}
}
ptr = (const char *) TransportOptions;
{
if (sscanf(key, "%[a-zA-Z_]|%[a-zA-Z_]", scope, option) != 2)
{
continue;
}
if (strcasecmp(scope, "receiver") == 0)
{
{
snprintf(ErrorString,
sizeof(ErrorString),
"invalid option [receiver %s %s], %s",
option,
value,
cleanup_clientd(data);
return (rc);
}
}
}
entry = &ReceiverTopicOption[0];
while (entry->option != NULL)
{
{
snprintf(ErrorString,
sizeof(ErrorString),
"error setting option [receiver %s %s], %s",
entry->option,
entry->value,
cleanup_clientd(data);
return (rc);
}
entry++;
}
if (wildcard_topic[0] == '\0')
{
{
snprintf(ErrorString,
sizeof(ErrorString),
"lbm_rcv_topic_lookup() failed, %s",
cleanup_clientd(data);
return (rc);
}
}
#ifdef _WIN32
InitializeCriticalSection(&(data->mLock));
#else
pthread_mutex_init(&(data->mLock), NULL);
#endif
data->mLockCreated = 1;
lock(data);
if (wildcard_topic[0] != '\0')
{
data->mContext,
wildcard_topic,
data->mReceiverTopicAttributes,
data->mWildcardReceiverAttributes,
receive_callback,
data,
NULL);
}
else
{
data->mContext,
data->mTopic,
receive_callback,
data,
NULL);
}
{
snprintf(ErrorString,
sizeof(ErrorString),
"lbm_wildcard_rcv_create()/lbm_rcv_create() failed, %s",
unlock(data);
cleanup_clientd(data);
return (rc);
}
*TransportClientData = data;
unlock(data);
return (0);
}
int
lbmmon_transport_lbm_send(const char * Data, size_t Length, void * TransportClientData)
{
lbmmon_transport_lbm_clientd_t * src;
int rc;
if ((Data == NULL) || (TransportClientData == NULL))
{
strncpy(ErrorString, "Invalid argument", sizeof(ErrorString));
return (-1);
}
src = (lbmmon_transport_lbm_clientd_t *) TransportClientData;
{
snprintf(ErrorString,
sizeof(ErrorString),
"lbm_src_send() failed, %s",
}
return (rc);
}
int
lbmmon_transport_lbm_receive(char * Data, size_t * Length, unsigned int TimeoutMS, void * TransportClientData)
{
lbmmon_transport_lbm_clientd_t * rcv = (lbmmon_transport_lbm_clientd_t *) TransportClientData;
lbmmon_transport_lbm_rcv_node_t * node;
int rc = 0;
size_t length_remaining;
#if defined(_WIN32)
#elif defined(__TANDEM)
unsigned int sleep_sec;
unsigned int sleep_usec;
#else
struct timespec ivl;
#endif
if ((Data == NULL) || (Length == NULL) || (TransportClientData == NULL))
{
strncpy(ErrorString, "Invalid argument", sizeof(ErrorString));
return (-1);
}
if (*Length == 0)
{
return (0);
}
lock(rcv);
if (rcv->mHead != NULL)
{
node = rcv->mHead;
length_remaining = node->mMessage->len - node->mUsedBytes;
if (*Length >= length_remaining)
{
memcpy(Data, node->mMessage->data + node->mUsedBytes, length_remaining);
*Length = length_remaining;
rc = 0;
rcv->mHead = node->mNext;
if (rcv->mHead == NULL)
{
rcv->mTail = NULL;
}
free(node);
}
else
{
lbm_logf(
LBM_LOG_ERR,
"Core-8034-1: [LBMMON] Dropping monitoring message that is larger than the maximum allowed size of %lu (size=%lu)",
*Length, node->mMessage->len);
rcv->mHead = node->mNext;
if (rcv->mHead == NULL)
{
rcv->mTail = NULL;
}
free(node);
rc = 1;
}
unlock(rcv);
}
else
{
unlock(rcv);
#define NANOSECONDS_PER_SECOND 1000000000
#define MICROSECONDS_PER_SECOND 1000000
#define MILLISECONDS_PER_SECOND 1000
#define NANOSECONDS_PER_MILLISECOND (NANOSECONDS_PER_SECOND / MILLISECONDS_PER_SECOND)
#define MICROSECONDS_PER_MILLISECOND (MICROSECONDS_PER_SECOND / MILLISECONDS_PER_SECOND)
#if defined(_WIN32)
Sleep(TimeoutMS);
#elif defined(__TANDEM)
sleep_sec = TimeoutMS / MILLISECONDS_PER_SECOND;
sleep_usec = (TimeoutMS % MILLISECONDS_PER_SECOND) * MICROSECONDS_PER_MILLISECOND;
if (sleep_usec > 0)
{
usleep(sleep_usec);
}
if (sleep_sec > 0)
{
sleep(sleep_sec);
}
#else
ivl.tv_sec = TimeoutMS / MILLISECONDS_PER_SECOND;
ivl.tv_nsec = (TimeoutMS % MILLISECONDS_PER_SECOND) * NANOSECONDS_PER_MILLISECOND;
nanosleep(&ivl, NULL);
#endif
rc = 1;
}
return (rc);
}
void
cleanup_clientd(lbmmon_transport_lbm_clientd_t * Data)
{
lbmmon_transport_lbm_rcv_node_t * node;
lbmmon_transport_lbm_rcv_node_t * next;
if (Data->mSource != NULL)
{
Data->mSource = NULL;
}
if (Data->mSourceTopicAttributes != NULL)
{
Data->mSourceTopicAttributes = NULL;
}
if (Data->mWildcardReceiver != NULL)
{
Data->mWildcardReceiver = NULL;
}
if (Data->mWildcardReceiverAttributes != NULL)
{
Data->mWildcardReceiverAttributes = NULL;
}
if (Data->mReceiver != NULL)
{
Data->mReceiver = NULL;
}
if (Data->mReceiverTopicAttributes != NULL)
{
Data->mReceiverTopicAttributes = NULL;
}
Data->mTopic = NULL;
if (Data->mLockCreated != 0)
{
lock(Data);
}
if (Data->mContext != NULL)
{
Data->mContext = NULL;
}
if (Data->mContextAttributes != NULL)
{
Data->mContextAttributes = NULL;
}
node = Data->mHead;
while (node != NULL)
{
next = node->mNext;
free(node);
node = next;
}
if (Data->mLockCreated)
{
unlock(Data);
#ifdef _WIN32
DeleteCriticalSection(&(Data->mLock));
#else
pthread_mutex_destroy(&(Data->mLock));
#endif
}
free(Data);
}
int
lbmmon_transport_lbm_src_finish(void * TransportClientData)
{
lbmmon_transport_lbm_clientd_t * rcv;
if (TransportClientData == NULL)
{
strncpy(ErrorString, "Invalid argument", sizeof(ErrorString));
return (-1);
}
rcv = (lbmmon_transport_lbm_clientd_t *)TransportClientData;
cleanup_clientd(rcv);
return (0);
}
int
lbmmon_transport_lbm_rcv_finish(void * TransportClientData)
{
lbmmon_transport_lbm_clientd_t * rcv;
if (TransportClientData == NULL)
{
strncpy(ErrorString, "Invalid argument", sizeof(ErrorString));
return (-1);
}
rcv = (lbmmon_transport_lbm_clientd_t *) TransportClientData;
cleanup_clientd(rcv);
return (0);
}
void
lock(lbmmon_transport_lbm_clientd_t * Receiver)
{
#ifdef _WIN32
EnterCriticalSection(&(Receiver->mLock));
#else
pthread_mutex_lock(&(Receiver->mLock));
#endif
}
void
unlock(lbmmon_transport_lbm_clientd_t * Receiver)
{
#ifdef _WIN32
LeaveCriticalSection(&(Receiver->mLock));
#else
pthread_mutex_unlock(&(Receiver->mLock));
#endif
}
const int
lbmmon_transport_allow_debug(void * TransportClientData)
{
lbmmon_transport_lbm_clientd_t * client_data = (lbmmon_transport_lbm_clientd_t *)TransportClientData;
return (client_data->mAllowDebug);
}
const char *
lbmmon_transport_lbm_errmsg(void)
{
return (ErrorString);
}
const char *
lbmmon_transport_lbm_ctrlmsgtarget(void)
{
if (RequestTargetAddress[0] == '\0') {
return NULL;
} else {
return (RequestTargetAddress);
}
}
int
lbmmon_transport_lbm_ctrlmsg_receive(char * Data, size_t * Length, void * TransportClientData)
{
lbmmon_transport_lbm_clientd_t * rcv = (lbmmon_transport_lbm_clientd_t *)TransportClientData;
lbmmon_transport_lbm_rcv_node_t * node;
int rc = 0;
size_t length_remaining;
if ((Data == NULL) || (Length == NULL) || (TransportClientData == NULL))
{
strncpy(ErrorString, "Invalid argument", sizeof(ErrorString));
return (-1);
}
if (*Length == 0)
{
return (0);
}
lock(rcv);
if (rcv->mHead != NULL)
{
node = rcv->mHead;
length_remaining = node->mMessage->len - node->mUsedBytes;
if (*Length >= length_remaining)
{
memcpy(Data, node->mMessage->data + node->mUsedBytes, length_remaining);
*Length = length_remaining;
rc = 0;
}
else
{
lbm_logf(
LBM_LOG_ERR,
"Core-10995-15: [LBMMON] Dropping monitoring message that is larger than the maximum allowed size of %lu (size=%lu)",
*Length, node->mMessage->len);
rcv->mHead = node->mNext;
if (rcv->mHead == NULL)
{
rcv->mTail = NULL;
}
free(node);
rc = 1;
}
}
else
{
rc = 1;
}
unlock(rcv);
return (rc);
}
int
lbmmon_transport_lbm_ctrlmsg_response(const char * Data, size_t Length, void * clientd)
{
lbmmon_transport_lbm_clientd_t * rcv = (lbmmon_transport_lbm_clientd_t *)clientd;
lbmmon_transport_lbm_rcv_node_t * node;
lock(rcv);
if (rcv->mHead != NULL) {
node = rcv->mHead;
{
{
}
}
rcv->mHead = node->mNext;
if (rcv->mHead == NULL)
{
rcv->mTail = NULL;
}
free(node);
}
unlock(rcv);
return (0);
}
int
scope_is_valid(const char * Scope)
{
if (strcasecmp(Scope, "context") == 0)
{
return (0);
}
if (strcasecmp(Scope, "source") == 0)
{
return (0);
}
if (strcasecmp(Scope, "receiver") == 0)
{
return (0);
}
if (strcasecmp(Scope, "event_queue") == 0)
{
return (0);
}
return (-1);
}