#ifdef __VOS__
#define _POSIX_C_SOURCE 200112L
#include <sys/time.h>
#endif
#include <stdio.h>
#include <string.h>
#include <stddef.h>
#include <time.h>
#include <limits.h>
#include <errno.h>
#include <ctype.h>
#ifdef _WIN32
#define strcasecmp stricmp
#define snprintf _snprintf
#else
#endif
#if defined(__TANDEM)
#include <strings.h>
#endif
#include "lbmmon_int.h"
#include <lbm/lbmmonfmtcsv.h>
#include "lbmcommon.h"
#include "mullog.h"
{
lbmmon_format_csv_init,
NULL,
lbmmon_rcv_format_csv_serialize,
lbmmon_src_format_csv_serialize,
lbmmon_rcv_format_csv_deserialize,
lbmmon_src_format_csv_deserialize,
lbmmon_format_csv_finish,
lbmmon_format_csv_errmsg,
lbmmon_evq_format_csv_serialize,
lbmmon_evq_format_csv_deserialize,
lbmmon_ctx_format_csv_serialize,
lbmmon_ctx_format_csv_deserialize,
lbmmon_rcv_topic_format_csv_serialize,
lbmmon_rcv_topic_format_csv_deserialize,
lbmmon_wildcard_rcv_format_csv_serialize,
lbmmon_wildcard_rcv_format_csv_deserialize,
lbmmon_store_format_csv_serialize,
lbmmon_store_format_csv_deserialize,
NULL,
NULL,
lbmmon_gateway_format_csv_serialize,
lbmmon_gateway_format_csv_deserialize,
NULL
};
typedef struct
{
unsigned char mSeparator;
int mPassthrough;
size_t mBufferSize;
char * mBuffer;
} lbmmon_format_csv_t;
static const char * next_csv_value(const char * String, char * Value, size_t Size, char Separator);
#define LBMMON_FORMAT_CSV_VERSION_1 1
#define LBMMON_FORMAT_CSV_VERSION_2 2
#define LBMMON_FORMAT_CSV_VERSION_3 3
#define LBMMON_FORMAT_CSV_VERSION_4 4
#define LBMMON_FORMAT_CSV_VERSION_5 5
#define LBMMON_FORMAT_CSV_VERSION_CURRENT LBMMON_FORMAT_CSV_VERSION_5
typedef struct
{
const size_t * layout;
size_t count;
} lbmmon_csv_layout_t;
static char ErrorString[1024];
static void lbmmon_format_csv_report_allocation_error(size_t Size)
{
snprintf(ErrorString, sizeof(ErrorString), "Unable to allocate %u bytes", (unsigned) Size);
}
static void lbmmon_format_csv_convert_to_hex(
char * Buffer,
const lbm_uint8_t * Data,
size_t Length)
{
static char hextable[16] =
{ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
unsigned char c;
char * buf = Buffer;
size_t iidx = 0;
size_t oidx = 0;
while (iidx < Length)
{
c = Data[iidx];
buf[oidx++] = hextable[((c >> 4) & 0x0f)];
buf[oidx++] = hextable[(c & 0x0f)];
iidx++;
}
}
static void lbmmon_format_csv_convert_from_hex(
char * Buffer,
const lbm_uint8_t * Data,
size_t Length)
{
unsigned char c;
char * buf = Buffer;
size_t iidx = 0;
size_t oidx = 0;
unsigned char n1;
unsigned char n2;
unsigned char b;
if ((Length % 2) != 0)
{
memset((void *) Buffer, 0, (Length / 2));
return;
}
while (iidx < Length)
{
b = 0;
c = Data[iidx++];
if (isxdigit(c))
{
if (isdigit(c))
{
n1 = c - '0';
}
else if (isupper(c))
{
n1 = 0x0a + (c - 'A');
}
else
{
n1 = 0x0a + (c - 'a');
}
}
else
{
n1 = 0;
}
c = Data[iidx++];
if (isxdigit(c))
{
if (isdigit(c))
{
n2 = c - '0';
}
else if (isupper(c))
{
n2 = 0x0a + (c - 'A');
}
else
{
n2 = 0x0a + (c - 'a');
}
}
else
{
n2 = 0;
}
b = ((n1 & 0x0f) << 4) | (n2 & 0x0f);
buf[oidx++] = b;
}
}
{
return (&LBMMON_FORMAT_CSV);
}
int lbmmon_format_csv_init(void * * FormatClientData, const void * FormatOptions)
{
char key[512];
char value[512];
const char * ptr = (const char *) FormatOptions;
lbmmon_format_csv_t * data;
memset(ErrorString, 0, sizeof(ErrorString));
*FormatClientData = NULL;
data = malloc(sizeof(lbmmon_format_csv_t));
if (data == NULL)
{
lbmmon_format_csv_report_allocation_error(sizeof(lbmmon_format_csv_t));
return (-1);
}
data->mSeparator = ',';
data->mBufferSize = 1024;
data->mBuffer = malloc(data->mBufferSize);
if (data->mBuffer == NULL)
{
lbmmon_format_csv_report_allocation_error(data->mBufferSize);
free(data);
return (-1);
}
{
if (strcasecmp(key, "separator") == 0)
{
data->mSeparator = value[0];
}
else if (strcasecmp(key, "passthrough") == 0)
{
if (strcasecmp(value, "off") == 0) {
}
else if (strcasecmp(value, "on") == 0) {
}
else if (strcasecmp(value, "convert") == 0) {
}
else {
LBM_EINVAL_RETURN("CoreApi-9778-100: value must be \"off\", \"on\" or \"convert\" for monitor format option \"passthrough\".", -1);
}
}
}
*FormatClientData = (void *)data;
return (0);
}
int lbmmon_rcv_format_csv_serialize(char * Destination, size_t * Size, unsigned short * ModuleID,
{
char work[1024];
lbmmon_format_csv_t * fmt;
if ((Destination == NULL) || (Size == NULL) || (*Size == 0) || (Statistics == NULL) || (FormatClientData == NULL))
{
return (-1);
}
fmt = (lbmmon_format_csv_t *) FormatClientData;
memset(work, 0, sizeof(work));
snprintf(work, sizeof(work), "%d%c\"",
fmt->mSeparator);
strncat(work, Statistics->
source,
sizeof(work) - strlen(work) - 1);
strncat(work, "\"", sizeof(work) - strlen(work) - 1);
strncpy(Destination, work, *Size);
switch (Statistics->
type)
{
snprintf(work,
sizeof(work),
"%c%lx%c%lx%c%lx%c%lx",
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
if (strlen(work) >= (*Size - strlen(Destination) - 1))
{
strncpy(ErrorString, "Destination too small for data", sizeof(ErrorString));
return (-1);
}
strncat(Destination, work, *Size - strlen(Destination) - 1);
break;
snprintf(work,
sizeof(work),
"%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx",
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
if (strlen(work) >= (*Size - strlen(Destination) - 1))
{
strncpy(ErrorString, "Destination too small for data", sizeof(ErrorString));
return (-1);
}
strncat(Destination, work, *Size - strlen(Destination) - 1);
snprintf(work,
sizeof(work),
"%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx",
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
if (strlen(work) >= (*Size - strlen(Destination) - 1))
{
strncpy(ErrorString, "Destination too small for data", sizeof(ErrorString));
return (-1);
}
strncat(Destination, work, *Size - strlen(Destination) - 1);
snprintf(work,
sizeof(work),
"%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx",
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
if (strlen(work) >= (*Size - strlen(Destination) - 1))
{
strncpy(ErrorString, "Destination too small for data", sizeof(ErrorString));
return (-1);
}
strncat(Destination, work, *Size - strlen(Destination) - 1);
snprintf(work,
sizeof(work),
"%c%lx%c%lx%c%lx",
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
if (strlen(work) >= (*Size - strlen(Destination) - 1))
{
strncpy(ErrorString, "Destination too small for data", sizeof(ErrorString));
return (-1);
}
strncat(Destination, work, *Size - strlen(Destination) - 1);
break;
snprintf(work,
sizeof(work),
"%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx",
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
if (strlen(work) >= (*Size - strlen(Destination) - 1))
{
strncpy(ErrorString, "Destination too small for data", sizeof(ErrorString));
return (-1);
}
strncat(Destination, work, *Size - strlen(Destination) - 1);
snprintf(work,
sizeof(work),
"%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx",
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
if (strlen(work) >= (*Size - strlen(Destination) - 1))
{
strncpy(ErrorString, "Destination too small for data", sizeof(ErrorString));
return (-1);
}
strncat(Destination, work, *Size - strlen(Destination) - 1);
snprintf(work,
sizeof(work),
"%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx",
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
if (strlen(work) >= (*Size - strlen(Destination) - 1))
{
strncpy(ErrorString, "Destination too small for data", sizeof(ErrorString));
return (-1);
}
strncat(Destination, work, *Size - strlen(Destination) - 1);
snprintf(work,
sizeof(work),
"%c%lx%c%lx%c%lx",
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
if (strlen(work) >= (*Size - strlen(Destination) - 1))
{
strncpy(ErrorString, "Destination too small for data", sizeof(ErrorString));
return (-1);
}
strncat(Destination, work, *Size - strlen(Destination) - 1);
break;
snprintf(work,
sizeof(work),
"%c%lx%c%lx%c%lx%c%lx%c%lx",
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
if (strlen(work) >= (*Size - strlen(Destination) - 1))
{
strncpy(ErrorString, "Destination too small for data", sizeof(ErrorString));
return (-1);
}
strncat(Destination, work, *Size - strlen(Destination) - 1);
break;
snprintf(work,
sizeof(work),
"%c%lx%c%lx%c%lx%c%lx%c%lx",
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
if (strlen(work) >= (*Size - strlen(Destination) - 1))
{
strncpy(ErrorString, "Destination too small for data", sizeof(ErrorString));
return (-1);
}
strncat(Destination, work, *Size - strlen(Destination) - 1);
break;
snprintf(work,
sizeof(work),
"%c%lx%c%lx%c%lx%c%lx%c%lx",
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
if (strlen(work) >= (*Size - strlen(Destination) - 1))
{
strncpy(ErrorString, "Destination too small for data", sizeof(ErrorString));
return (-1);
}
strncat(Destination, work, *Size - strlen(Destination) - 1);
break;
snprintf(work,
sizeof(work),
"%c%lx%c%lx",
fmt->mSeparator,
fmt->mSeparator,
if (strlen(work) >= (*Size - strlen(Destination) - 1))
{
strncpy(ErrorString, "Destination too small for data", sizeof(ErrorString));
return (-1);
}
strncat(Destination, work, *Size - strlen(Destination) - 1);
break;
default:
strncpy(ErrorString, "Unknown LBM transport type", sizeof(ErrorString));
return (-1);
}
*Size = strlen(Destination);
return (0);
}
int lbmmon_src_format_csv_serialize(char * Destination, size_t * Size, unsigned short * ModuleID,
{
char work[1024];
lbmmon_format_csv_t * fmt;
if ((Destination == NULL) || (Size == NULL) || (*Size == 0) || (Statistics == NULL) || (FormatClientData == NULL))
{
return (-1);
}
fmt = (lbmmon_format_csv_t *) FormatClientData;
memset(work, 0, sizeof(work));
snprintf(work, sizeof(work), "%d%c\"",
fmt->mSeparator);
strncat(work, Statistics->
source,
sizeof(work) - strlen(work) - 1);
strncat(work, "\"", sizeof(work) - strlen(work) - 1);
strncpy(Destination, work, *Size);
switch (Statistics->
type)
{
snprintf(work,
sizeof(work),
"%c%lx%c%lx",
fmt->mSeparator,
fmt->mSeparator,
if (strlen(work) >= (*Size - strlen(Destination) - 1))
{
strncpy(ErrorString, "Destination too small for data", sizeof(ErrorString));
return (-1);
}
strncat(Destination, work, *Size - strlen(Destination) - 1);
break;
snprintf(work,
sizeof(work),
"%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx",
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
if (strlen(work) >= (*Size - strlen(Destination) - 1))
{
strncpy(ErrorString, "Destination too small for data", sizeof(ErrorString));
return (-1);
}
strncat(Destination, work, *Size - strlen(Destination) - 1);
snprintf(work,
sizeof(work),
"%c%lx%c%lx%c%lx%c%lx%c%lx",
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
if (strlen(work) >= (*Size - strlen(Destination) - 1))
{
strncpy(ErrorString, "Destination too small for data", sizeof(ErrorString));
return (-1);
}
strncat(Destination, work, *Size - strlen(Destination) - 1);
break;
snprintf(work,
sizeof(work),
"%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx",
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
if (strlen(work) >= (*Size - strlen(Destination) - 1))
{
strncpy(ErrorString, "Destination too small for data", sizeof(ErrorString));
return (-1);
}
strncat(Destination, work, *Size - strlen(Destination) - 1);
snprintf(work,
sizeof(work),
"%c%lx%c%lx",
fmt->mSeparator,
fmt->mSeparator,
if (strlen(work) >= (*Size - strlen(Destination) - 1))
{
return (-1);
}
strncat(Destination, work, *Size - strlen(Destination) - 1);
break;
snprintf(work,
sizeof(work),
"%c%lx%c%lx%c%lx",
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
if (strlen(work) >= (*Size - strlen(Destination) - 1))
{
strncpy(ErrorString, "Destination too small for data", sizeof(ErrorString));
return (-1);
}
strncat(Destination, work, *Size - strlen(Destination) - 1);
break;
snprintf(work,
sizeof(work),
"%c%lx%c%lx%c%lx",
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
if (strlen(work) >= (*Size - strlen(Destination) - 1))
{
strncpy(ErrorString, "Destination too small for data", sizeof(ErrorString));
return (-1);
}
strncat(Destination, work, *Size - strlen(Destination) - 1);
break;
snprintf(work,
sizeof(work),
"%c%lx%c%lx%c%lx",
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
if (strlen(work) >= (*Size - strlen(Destination) - 1))
{
strncpy(ErrorString, "Destination too small for data", sizeof(ErrorString));
return (-1);
}
strncat(Destination, work, *Size - strlen(Destination) - 1);
break;
snprintf(work,
sizeof(work),
"%c%lx%c%lx",
fmt->mSeparator,
fmt->mSeparator,
if (strlen(work) >= (*Size - strlen(Destination) - 1))
{
strncpy(ErrorString, "Destination too small for data", sizeof(ErrorString));
return (-1);
}
strncat(Destination, work, *Size - strlen(Destination) - 1);
break;
}
*Size = strlen(Destination);
return (0);
}
int lbmmon_evq_format_csv_serialize(char * Destination, size_t * Size, unsigned short * ModuleID,
{
lbmmon_format_csv_t * fmt;
char work[1024];
if ((Destination == NULL) || (Size == NULL) || (*Size == 0) || (Statistics == NULL) || (FormatClientData == NULL))
{
return (-1);
}
fmt = (lbmmon_format_csv_t *) FormatClientData;
memset(work, 0, sizeof(work));
memset(Destination, 0, 2048);
snprintf(work,
sizeof(work),
"%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c",
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator);
if (strlen(work) >= (*Size - strlen(Destination) - 1))
{
strncpy(ErrorString, "Destination too small for data", sizeof(ErrorString));
return (-1);
}
strncat(Destination, work, *Size - strlen(Destination) - 1);
snprintf(work,
sizeof(work),
"%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c",
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator);
if (strlen(work) >= (*Size - strlen(Destination) - 1))
{
strncpy(ErrorString, "Destination too small for data", sizeof(ErrorString));
return (-1);
}
strncat(Destination, work, *Size - strlen(Destination) - 1);
snprintf(work,
sizeof(work),
"%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c",
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator);
if (strlen(work) >= (*Size - strlen(Destination) - 1))
{
strncpy(ErrorString, "Destination too small for data", sizeof(ErrorString));
return (-1);
}
strncat(Destination, work, *Size - strlen(Destination) - 1);
snprintf(work,
sizeof(work),
"%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx",
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
if (strlen(work) >= (*Size - strlen(Destination) - 1))
{
strncpy(ErrorString, "Destination too small for data", sizeof(ErrorString));
return (-1);
}
strncat(Destination, work, *Size - strlen(Destination) - 1);
*Size = strlen(Destination);
return (0);
}
int lbmmon_ctx_format_csv_serialize(char * Destination, size_t * Size, unsigned short * ModuleID,
{
lbmmon_format_csv_t * fmt;
char work[1024];
if ((Destination == NULL) || (Size == NULL) || (*Size == 0) || (Statistics == NULL) || (FormatClientData == NULL))
{
return (-1);
}
fmt = (lbmmon_format_csv_t *) FormatClientData;
memset(work, 0, sizeof(work));
memset(Destination, 0, 2048);
snprintf(work,
sizeof(work),
"%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c",
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator);
if (strlen(work) >= (*Size - strlen(Destination) - 1))
{
strncpy(ErrorString, "Destination too small for data", sizeof(ErrorString));
return (-1);
}
strncat(Destination, work, *Size - strlen(Destination) - 1);
snprintf(work,
sizeof(work),
"%lx%c%lx%c%lx%c%lx%c%lx%c%lx%c%lx",
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
fmt->mSeparator,
if (strlen(work) >= (*Size - strlen(Destination) - 1))
{
strncpy(ErrorString, "Destination too small for data", sizeof(ErrorString));
return (-1);
}
strncat(Destination, work, *Size - strlen(Destination) - 1);
*Size = strlen(Destination);
return (0);
}
int lbmmon_rcv_topic_format_csv_serialize(char * Destination, size_t * Size, unsigned short * ModuleID,
{
lbmmon_format_csv_t * fmt;
char work[1024];
int idx;
if ((Destination == NULL) || (Size == NULL) || (*Size == 0) || (FormatClientData == NULL))
{
return (-1);
}
fmt = (lbmmon_format_csv_t *) FormatClientData;
memset(work, 0, sizeof(work));
memset(Destination, 0, 2048);
snprintf(work, sizeof(work),
"\"%s\"%c%lx",
Topic,
fmt->mSeparator,
SourceCount);
if (strlen(work) >= (*Size - strlen(Destination) - 1))
{
strncpy(ErrorString, "Destination too small for data", sizeof(ErrorString));
return (-1);
}
strncat(Destination, work, *Size - strlen(Destination) - 1);
if (SourceCount > 0)
{
for (idx = 0; idx < SourceCount; ++idx)
{
size_t offset;
memset(work, 0, sizeof(work));
snprintf(work, sizeof(work),
"%c\"%s\"%c",
fmt->mSeparator,
fmt->mSeparator);
offset = strlen(work);
lbmmon_format_csv_convert_to_hex(work + offset, Sources[idx].otid, LBM_OTID_BLOCK_SZ);
offset = strlen(work);
snprintf(work + offset, sizeof(work) - offset,
"%c%x",
fmt->mSeparator,
if (strlen(work) >= (*Size - strlen(Destination) - 1))
{
strncpy(ErrorString, "Destination too small for data", sizeof(ErrorString));
return (-1);
}
strncat(Destination, work, *Size - strlen(Destination) - 1);
}
}
*Size = strlen(Destination);
return (0);
}
int lbmmon_wildcard_rcv_format_csv_serialize(char * Destination, size_t * Size, unsigned short * ModuleID,
{
lbmmon_format_csv_t * fmt;
char work[1024];
if ((Destination == NULL) || (Size == NULL) || (*Size == 0) || (Statistics == NULL) || (FormatClientData == NULL))
{
return (-1);
}
fmt = (lbmmon_format_csv_t *) FormatClientData;
memset(work, 0, sizeof(work));
memset(Destination, 0, 2048);
snprintf(work, sizeof(work),
"\"%s\"%c%x",
fmt->mSeparator,
if (strlen(work) >= (*Size - strlen(Destination) - 1))
{
strncpy(ErrorString, "Destination too small for data", sizeof(ErrorString));
return (-1);
}
strncat(Destination, work, *Size - strlen(Destination) - 1);
*Size = strlen(Destination);
return (0);
}
int lbmmon_store_format_csv_serialize(char * Destination, size_t * Size, unsigned short * ModuleID,
{
strncpy(ErrorString, "CSV format not supported for stores at this time", sizeof(ErrorString));
return (-1);
}
int lbmmon_gateway_format_csv_serialize(char * Destination, size_t * Size, unsigned short * ModuleID,
{
strncpy(ErrorString, "CSV format not supported for gateways at this time", sizeof(ErrorString));
return (-1);
}
const char * next_csv_value(const char * String, char * Value, size_t Size, char Separator)
{
const char * ptr = String;
size_t pos;
if ((ptr == NULL) || (Value == NULL) || (Size == 0))
{
return (NULL);
}
memset(Value, 0, Size);
while ((*ptr != '\0') && (*ptr != Separator) && ((*ptr == ' ') || (*ptr == '\t')))
{
ptr++;
}
pos = 0;
if (*ptr == '\0')
{
return (NULL);
}
else if (*ptr == Separator)
{
ptr++;
return (ptr);
}
else if ((*ptr == '\"') || (*ptr == '\''))
{
char quote = *ptr;
ptr++;
while ((*ptr != '\0') && (*ptr != quote) && (pos < (Size - 1)))
{
Value[pos++] = *ptr++;
}
while ((*ptr != '\0') && (*ptr != quote))
{
ptr++;
}
while ((*ptr != '\0') && (*ptr != Separator))
{
ptr++;
}
}
else
{
while ((*ptr != '\0') && (*ptr != Separator) && (pos < (Size - 1)))
{
Value[pos++] = *ptr++;
}
while ((*ptr != '\0') && (*ptr != Separator))
{
ptr++;
}
}
if (*ptr == Separator)
{
ptr++;
}
return (ptr);
}
{
const char * ptr = Buffer;
while (1)
{
errno = 0;
value = strtoul(ptr, NULL, 16);
if ((value == ULONG_MAX) && (errno == ERANGE))
{
ptr++;
}
else
{
return (value);
}
}
}
static const size_t csv_rcv_tcp_stat_offset_v1[] =
{
};
#define csv_rcv_tcp_stat_offset_v2 csv_rcv_tcp_stat_offset_v1
#define csv_rcv_tcp_stat_offset_v3 csv_rcv_tcp_stat_offset_v2
#define csv_rcv_tcp_stat_offset_v4 csv_rcv_tcp_stat_offset_v3
#define csv_rcv_tcp_stat_offset_v5 csv_rcv_tcp_stat_offset_v4
static const lbmmon_csv_layout_t csv_rcv_tcp_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT+1] =
{
{ NULL, 0 },
{ csv_rcv_tcp_stat_offset_v1, sizeof(csv_rcv_tcp_stat_offset_v1)/sizeof(csv_rcv_tcp_stat_offset_v1[0]) },
{ csv_rcv_tcp_stat_offset_v2, sizeof(csv_rcv_tcp_stat_offset_v2)/sizeof(csv_rcv_tcp_stat_offset_v2[0]) },
{ csv_rcv_tcp_stat_offset_v3, sizeof(csv_rcv_tcp_stat_offset_v3)/sizeof(csv_rcv_tcp_stat_offset_v3[0]) },
{ csv_rcv_tcp_stat_offset_v4, sizeof(csv_rcv_tcp_stat_offset_v4)/sizeof(csv_rcv_tcp_stat_offset_v4[0]) },
{ csv_rcv_tcp_stat_offset_v5, sizeof(csv_rcv_tcp_stat_offset_v5)/sizeof(csv_rcv_tcp_stat_offset_v5[0]) }
};
static const size_t csv_rcv_lbtrm_stat_offset_v1[] =
{
};
#define csv_rcv_lbtrm_stat_offset_v2 csv_rcv_lbtrm_stat_offset_v1
static const size_t csv_rcv_lbtrm_stat_offset_v3[] =
{
};
#define csv_rcv_lbtrm_stat_offset_v4 csv_rcv_lbtrm_stat_offset_v3
#define csv_rcv_lbtrm_stat_offset_v5 csv_rcv_lbtrm_stat_offset_v4
static const lbmmon_csv_layout_t csv_rcv_lbtrm_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT+1] =
{
{ NULL, 0 },
{ csv_rcv_lbtrm_stat_offset_v1, sizeof(csv_rcv_lbtrm_stat_offset_v1)/sizeof(csv_rcv_lbtrm_stat_offset_v1[0]) },
{ csv_rcv_lbtrm_stat_offset_v2, sizeof(csv_rcv_lbtrm_stat_offset_v2)/sizeof(csv_rcv_lbtrm_stat_offset_v2[0]) },
{ csv_rcv_lbtrm_stat_offset_v3, sizeof(csv_rcv_lbtrm_stat_offset_v3)/sizeof(csv_rcv_lbtrm_stat_offset_v3[0]) },
{ csv_rcv_lbtrm_stat_offset_v4, sizeof(csv_rcv_lbtrm_stat_offset_v4)/sizeof(csv_rcv_lbtrm_stat_offset_v4[0]) },
{ csv_rcv_lbtrm_stat_offset_v5, sizeof(csv_rcv_lbtrm_stat_offset_v5)/sizeof(csv_rcv_lbtrm_stat_offset_v5[0]) }
};
static const size_t csv_rcv_lbtru_stat_offset_v1[] =
{
};
#define csv_rcv_lbtru_stat_offset_v2 csv_rcv_lbtru_stat_offset_v1
static const size_t csv_rcv_lbtru_stat_offset_v3[] =
{
};
#define csv_rcv_lbtru_stat_offset_v4 csv_rcv_lbtru_stat_offset_v3
#define csv_rcv_lbtru_stat_offset_v5 csv_rcv_lbtru_stat_offset_v4
static const lbmmon_csv_layout_t csv_rcv_lbtru_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT+1] =
{
{ NULL, 0 },
{ csv_rcv_lbtru_stat_offset_v1, sizeof(csv_rcv_lbtru_stat_offset_v1)/sizeof(csv_rcv_lbtru_stat_offset_v1[0]) },
{ csv_rcv_lbtru_stat_offset_v2, sizeof(csv_rcv_lbtru_stat_offset_v2)/sizeof(csv_rcv_lbtru_stat_offset_v2[0]) },
{ csv_rcv_lbtru_stat_offset_v3, sizeof(csv_rcv_lbtru_stat_offset_v3)/sizeof(csv_rcv_lbtru_stat_offset_v3[0]) },
{ csv_rcv_lbtru_stat_offset_v4, sizeof(csv_rcv_lbtru_stat_offset_v4)/sizeof(csv_rcv_lbtru_stat_offset_v4[0]) },
{ csv_rcv_lbtru_stat_offset_v5, sizeof(csv_rcv_lbtru_stat_offset_v5)/sizeof(csv_rcv_lbtru_stat_offset_v5[0]) }
};
static const size_t csv_rcv_lbtipc_stat_offset_v2[] =
{
};
#define csv_rcv_lbtipc_stat_offset_v3 csv_rcv_lbtipc_stat_offset_v2
#define csv_rcv_lbtipc_stat_offset_v4 csv_rcv_lbtipc_stat_offset_v3
#define csv_rcv_lbtipc_stat_offset_v5 csv_rcv_lbtipc_stat_offset_v4
static const lbmmon_csv_layout_t csv_rcv_lbtipc_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT+1] =
{
{ NULL, 0 },
{ NULL, 0 },
{ csv_rcv_lbtipc_stat_offset_v2, sizeof(csv_rcv_lbtipc_stat_offset_v2)/sizeof(csv_rcv_lbtipc_stat_offset_v2[0]) },
{ csv_rcv_lbtipc_stat_offset_v3, sizeof(csv_rcv_lbtipc_stat_offset_v3)/sizeof(csv_rcv_lbtipc_stat_offset_v3[0]) },
{ csv_rcv_lbtipc_stat_offset_v4, sizeof(csv_rcv_lbtipc_stat_offset_v4)/sizeof(csv_rcv_lbtipc_stat_offset_v4[0]) },
{ csv_rcv_lbtipc_stat_offset_v5, sizeof(csv_rcv_lbtipc_stat_offset_v5)/sizeof(csv_rcv_lbtipc_stat_offset_v5[0]) }
};
static const size_t csv_rcv_lbtsmx_stat_offset_v2[] =
{
};
#define csv_rcv_lbtsmx_stat_offset_v3 csv_rcv_lbtsmx_stat_offset_v2
#define csv_rcv_lbtsmx_stat_offset_v4 csv_rcv_lbtsmx_stat_offset_v3
#define csv_rcv_lbtsmx_stat_offset_v5 csv_rcv_lbtsmx_stat_offset_v4
static const lbmmon_csv_layout_t csv_rcv_lbtsmx_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT+1] =
{
{ NULL, 0 },
{ NULL, 0 },
{ csv_rcv_lbtsmx_stat_offset_v2, sizeof(csv_rcv_lbtsmx_stat_offset_v2)/sizeof(csv_rcv_lbtsmx_stat_offset_v2[0]) },
{ csv_rcv_lbtsmx_stat_offset_v3, sizeof(csv_rcv_lbtsmx_stat_offset_v3)/sizeof(csv_rcv_lbtsmx_stat_offset_v3[0]) },
{ csv_rcv_lbtsmx_stat_offset_v4, sizeof(csv_rcv_lbtsmx_stat_offset_v4)/sizeof(csv_rcv_lbtsmx_stat_offset_v4[0]) },
{ csv_rcv_lbtsmx_stat_offset_v5, sizeof(csv_rcv_lbtsmx_stat_offset_v5)/sizeof(csv_rcv_lbtsmx_stat_offset_v5[0]) }
};
static const size_t csv_rcv_lbtrdma_stat_offset_v2[] =
{
};
#define csv_rcv_lbtrdma_stat_offset_v3 csv_rcv_lbtrdma_stat_offset_v2
#define csv_rcv_lbtrdma_stat_offset_v4 csv_rcv_lbtrdma_stat_offset_v3
#define csv_rcv_lbtrdma_stat_offset_v5 csv_rcv_lbtrdma_stat_offset_v4
static const lbmmon_csv_layout_t csv_rcv_lbtrdma_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT+1] =
{
{ NULL, 0 },
{ NULL, 0 },
{ csv_rcv_lbtrdma_stat_offset_v2, sizeof(csv_rcv_lbtrdma_stat_offset_v2)/sizeof(csv_rcv_lbtrdma_stat_offset_v2[0]) },
{ csv_rcv_lbtrdma_stat_offset_v3, sizeof(csv_rcv_lbtrdma_stat_offset_v3)/sizeof(csv_rcv_lbtrdma_stat_offset_v3[0]) },
{ csv_rcv_lbtrdma_stat_offset_v4, sizeof(csv_rcv_lbtrdma_stat_offset_v4)/sizeof(csv_rcv_lbtrdma_stat_offset_v4[0]) },
{ csv_rcv_lbtrdma_stat_offset_v5, sizeof(csv_rcv_lbtrdma_stat_offset_v5)/sizeof(csv_rcv_lbtrdma_stat_offset_v5[0]) }
};
static const size_t csv_rcv_broker_stat_offset_v2[] =
{
};
#define csv_rcv_broker_stat_offset_v3 csv_rcv_broker_stat_offset_v2
#define csv_rcv_broker_stat_offset_v4 csv_rcv_broker_stat_offset_v3
#define csv_rcv_broker_stat_offset_v5 csv_rcv_broker_stat_offset_v4
static const lbmmon_csv_layout_t csv_rcv_broker_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT+1] =
{
{ NULL, 0 },
{ NULL, 0 },
{ csv_rcv_broker_stat_offset_v2, sizeof(csv_rcv_broker_stat_offset_v2)/sizeof(csv_rcv_broker_stat_offset_v2[0]) },
{ csv_rcv_broker_stat_offset_v3, sizeof(csv_rcv_broker_stat_offset_v3)/sizeof(csv_rcv_broker_stat_offset_v3[0]) },
{ csv_rcv_broker_stat_offset_v4, sizeof(csv_rcv_broker_stat_offset_v4)/sizeof(csv_rcv_broker_stat_offset_v4[0]) },
{ csv_rcv_broker_stat_offset_v5, sizeof(csv_rcv_broker_stat_offset_v5)/sizeof(csv_rcv_broker_stat_offset_v5[0]) }
};
const char * Source, size_t Length, unsigned short ModuleID, void * FormatClientData)
{
const char * ptr;
char value[1024];
lbmmon_format_csv_t * fmt;
size_t idx;
unsigned char modid;
unsigned char modver;
const size_t * stat_layout = NULL;
size_t stat_count = 0;
if ((Statistics == NULL) || (Source == NULL) || (*Source == '\0') || (Length == 0) || (FormatClientData == NULL) )
{
strncpy(ErrorString, "Invalid parameter", sizeof(ErrorString));
}
fmt = (lbmmon_format_csv_t *) FormatClientData;
{
}
{
snprintf(ErrorString, sizeof(ErrorString), "Invalid module ID %u", (unsigned)modid);
}
if (fmt->mBuffer == NULL)
{
fmt->mBufferSize = 1024;
fmt->mBuffer = malloc(fmt->mBufferSize);
if (fmt->mBuffer == NULL)
{
lbmmon_format_csv_report_allocation_error(fmt->mBufferSize);
}
}
if (Length >= fmt->mBufferSize)
{
fmt->mBufferSize = 2 * Length;
free(fmt->mBuffer);
fmt->mBuffer = malloc(fmt->mBufferSize);
if (fmt->mBuffer == NULL)
{
lbmmon_format_csv_report_allocation_error(fmt->mBufferSize);
}
}
memset(fmt->mBuffer, 0, fmt->mBufferSize);
memcpy(fmt->mBuffer, Source, Length);
ptr = fmt->mBuffer;
ptr = next_csv_value(ptr, value, sizeof(value), fmt->mSeparator);
if (ptr == NULL)
{
strncpy(ErrorString, "No type field found", sizeof(ErrorString));
}
Statistics->
type = atoi(value);
ptr = next_csv_value(ptr, Statistics->
source,
sizeof(Statistics->
source), fmt->mSeparator);
if (ptr == NULL)
{
strncpy(ErrorString, "No source field found", sizeof(ErrorString));
}
MUL_DEBUG(LBM_DEBUG_LBMMON, (
"lbmmon_rcv_format_csv_deserialize (%s) (%d) (%d)\n", Statistics->
source, Statistics->
type, Length));
switch (Statistics->
type)
{
if (modver >= LBMMON_FORMAT_CSV_VERSION_CURRENT)
{
stat_layout = csv_rcv_tcp_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT].layout;
stat_count = csv_rcv_tcp_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT].count;
}
else
{
stat_layout = csv_rcv_tcp_stat_layout[modver].layout;
stat_count = csv_rcv_tcp_stat_layout[modver].count;
}
for (idx = 0; idx < stat_count; ++idx)
{
ptr = next_csv_value(ptr, value, sizeof(value), fmt->mSeparator);
if (ptr == NULL)
{
strncpy(ErrorString, "Data contains too few fields", sizeof(ErrorString));
}
}
break;
if (modver >= LBMMON_FORMAT_CSV_VERSION_CURRENT)
{
stat_layout = csv_rcv_lbtrm_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT].layout;
stat_count = csv_rcv_lbtrm_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT].count;
}
else
{
stat_layout = csv_rcv_lbtrm_stat_layout[modver].layout;
stat_count = csv_rcv_lbtrm_stat_layout[modver].count;
}
for (idx = 0; idx < stat_count; ++idx)
{
ptr = next_csv_value(ptr, value, sizeof(value), fmt->mSeparator);
if (ptr == NULL)
{
return 0;
}
strncpy(ErrorString, "Data contains too few fields", sizeof(ErrorString));
}
}
break;
if (modver >= LBMMON_FORMAT_CSV_VERSION_CURRENT)
{
stat_layout = csv_rcv_lbtru_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT].layout;
stat_count = csv_rcv_lbtru_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT].count;
}
else
{
stat_layout = csv_rcv_lbtru_stat_layout[modver].layout;
stat_count = csv_rcv_lbtru_stat_layout[modver].count;
}
for (idx = 0; idx < stat_count; ++idx)
{
ptr = next_csv_value(ptr, value, sizeof(value), fmt->mSeparator);
if (ptr == NULL)
{
strncpy(ErrorString, "Data contains too few fields", sizeof(ErrorString));
}
}
break;
if (modver >= LBMMON_FORMAT_CSV_VERSION_CURRENT)
{
stat_layout = csv_rcv_lbtipc_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT].layout;
stat_count = csv_rcv_lbtipc_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT].count;
}
else
{
stat_layout = csv_rcv_lbtipc_stat_layout[modver].layout;
stat_count = csv_rcv_lbtipc_stat_layout[modver].count;
}
for (idx = 0; idx < stat_count; ++idx)
{
ptr = next_csv_value(ptr, value, sizeof(value), fmt->mSeparator);
if (ptr == NULL)
{
strncpy(ErrorString, "Data contains too few fields", sizeof(ErrorString));
}
}
break;
if (modver >= LBMMON_FORMAT_CSV_VERSION_CURRENT)
{
stat_layout = csv_rcv_lbtsmx_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT].layout;
stat_count = csv_rcv_lbtsmx_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT].count;
}
else
{
stat_layout = csv_rcv_lbtsmx_stat_layout[modver].layout;
stat_count = csv_rcv_lbtsmx_stat_layout[modver].count;
}
for (idx = 0; idx < stat_count; ++idx)
{
ptr = next_csv_value(ptr, value, sizeof(value), fmt->mSeparator);
if (ptr == NULL)
{
strncpy(ErrorString, "Data contains too few fields", sizeof(ErrorString));
}
}
break;
if (modver >= LBMMON_FORMAT_CSV_VERSION_CURRENT)
{
stat_layout = csv_rcv_lbtrdma_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT].layout;
stat_count = csv_rcv_lbtrdma_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT].count;
}
else
{
stat_layout = csv_rcv_lbtrdma_stat_layout[modver].layout;
stat_count = csv_rcv_lbtrdma_stat_layout[modver].count;
}
for (idx = 0; idx < stat_count; ++idx)
{
ptr = next_csv_value(ptr, value, sizeof(value), fmt->mSeparator);
if (ptr == NULL)
{
strncpy(ErrorString, "Data contains too few fields", sizeof(ErrorString));
}
}
break;
if (modver >= LBMMON_FORMAT_CSV_VERSION_CURRENT)
{
stat_layout = csv_rcv_broker_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT].layout;
stat_count = csv_rcv_broker_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT].count;
}
else
{
stat_layout = csv_rcv_broker_stat_layout[modver].layout;
stat_count = csv_rcv_broker_stat_layout[modver].count;
}
for (idx = 0; idx < stat_count; ++idx)
{
ptr = next_csv_value(ptr, value, sizeof(value), fmt->mSeparator);
if (ptr == NULL)
{
strncpy(ErrorString, "Data contains too few fields", sizeof(ErrorString));
}
}
break;
default:
strncpy(ErrorString, "Invalid LBM transport type", sizeof(ErrorString));
}
{
}
}
static size_t csv_src_tcp_stat_offset_v1[] =
{
};
#define csv_src_tcp_stat_offset_v2 csv_src_tcp_stat_offset_v1
#define csv_src_tcp_stat_offset_v3 csv_src_tcp_stat_offset_v2
#define csv_src_tcp_stat_offset_v4 csv_src_tcp_stat_offset_v3
#define csv_src_tcp_stat_offset_v5 csv_src_tcp_stat_offset_v4
static const lbmmon_csv_layout_t csv_src_tcp_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT+1] =
{
{ NULL, 0 },
{ csv_src_tcp_stat_offset_v1, sizeof(csv_src_tcp_stat_offset_v1)/sizeof(csv_src_tcp_stat_offset_v1[0]) },
{ csv_src_tcp_stat_offset_v2, sizeof(csv_src_tcp_stat_offset_v2)/sizeof(csv_src_tcp_stat_offset_v2[0]) },
{ csv_src_tcp_stat_offset_v3, sizeof(csv_src_tcp_stat_offset_v3)/sizeof(csv_src_tcp_stat_offset_v3[0]) },
{ csv_src_tcp_stat_offset_v4, sizeof(csv_src_tcp_stat_offset_v4)/sizeof(csv_src_tcp_stat_offset_v4[0]) },
{ csv_src_tcp_stat_offset_v5, sizeof(csv_src_tcp_stat_offset_v5)/sizeof(csv_src_tcp_stat_offset_v5[0]) }
};
static size_t csv_src_lbtrm_stat_offset_v1[] =
{
};
static size_t csv_src_lbtrm_stat_offset_v2[] =
{
};
#define csv_src_lbtrm_stat_offset_v3 csv_src_lbtrm_stat_offset_v2
#define csv_src_lbtrm_stat_offset_v4 csv_src_lbtrm_stat_offset_v3
#define csv_src_lbtrm_stat_offset_v5 csv_src_lbtrm_stat_offset_v4
static const lbmmon_csv_layout_t csv_src_lbtrm_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT+1] =
{
{ NULL, 0 },
{ csv_src_lbtrm_stat_offset_v1, sizeof(csv_src_lbtrm_stat_offset_v1)/sizeof(csv_src_lbtrm_stat_offset_v1[0]) },
{ csv_src_lbtrm_stat_offset_v2, sizeof(csv_src_lbtrm_stat_offset_v2)/sizeof(csv_src_lbtrm_stat_offset_v2[0]) },
{ csv_src_lbtrm_stat_offset_v3, sizeof(csv_src_lbtrm_stat_offset_v3)/sizeof(csv_src_lbtrm_stat_offset_v3[0]) },
{ csv_src_lbtrm_stat_offset_v4, sizeof(csv_src_lbtrm_stat_offset_v4)/sizeof(csv_src_lbtrm_stat_offset_v4[0]) },
{ csv_src_lbtrm_stat_offset_v5, sizeof(csv_src_lbtrm_stat_offset_v5)/sizeof(csv_src_lbtrm_stat_offset_v5[0]) }
};
static size_t csv_src_lbtru_stat_offset_v1[] =
{
};
static size_t csv_src_lbtru_stat_offset_v2[] =
{
};
#define csv_src_lbtru_stat_offset_v3 csv_src_lbtru_stat_offset_v2
#define csv_src_lbtru_stat_offset_v4 csv_src_lbtru_stat_offset_v3
#define csv_src_lbtru_stat_offset_v5 csv_src_lbtru_stat_offset_v4
static const lbmmon_csv_layout_t csv_src_lbtru_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT+1] =
{
{ NULL, 0 },
{ csv_src_lbtru_stat_offset_v1, sizeof(csv_src_lbtru_stat_offset_v1)/sizeof(csv_src_lbtru_stat_offset_v1[0]) },
{ csv_src_lbtru_stat_offset_v2, sizeof(csv_src_lbtru_stat_offset_v2)/sizeof(csv_src_lbtru_stat_offset_v2[0]) },
{ csv_src_lbtru_stat_offset_v3, sizeof(csv_src_lbtru_stat_offset_v3)/sizeof(csv_src_lbtru_stat_offset_v3[0]) },
{ csv_src_lbtru_stat_offset_v4, sizeof(csv_src_lbtru_stat_offset_v4)/sizeof(csv_src_lbtru_stat_offset_v4[0]) },
{ csv_src_lbtru_stat_offset_v5, sizeof(csv_src_lbtru_stat_offset_v5)/sizeof(csv_src_lbtru_stat_offset_v5[0]) }
};
static size_t csv_src_lbtipc_stat_offset_v2[] =
{
};
#define csv_src_lbtipc_stat_offset_v3 csv_src_lbtipc_stat_offset_v2
#define csv_src_lbtipc_stat_offset_v4 csv_src_lbtipc_stat_offset_v3
#define csv_src_lbtipc_stat_offset_v5 csv_src_lbtipc_stat_offset_v4
static const lbmmon_csv_layout_t csv_src_lbtipc_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT+1] =
{
{ NULL, 0 },
{ NULL, 0 },
{ csv_src_lbtipc_stat_offset_v2, sizeof(csv_src_lbtipc_stat_offset_v2)/sizeof(csv_src_lbtipc_stat_offset_v2[0]) },
{ csv_src_lbtipc_stat_offset_v3, sizeof(csv_src_lbtipc_stat_offset_v3)/sizeof(csv_src_lbtipc_stat_offset_v3[0]) },
{ csv_src_lbtipc_stat_offset_v4, sizeof(csv_src_lbtipc_stat_offset_v4)/sizeof(csv_src_lbtipc_stat_offset_v4[0]) },
{ csv_src_lbtipc_stat_offset_v5, sizeof(csv_src_lbtipc_stat_offset_v5)/sizeof(csv_src_lbtipc_stat_offset_v5[0]) }
};
static size_t csv_src_lbtsmx_stat_offset_v2[] =
{
};
#define csv_src_lbtsmx_stat_offset_v3 csv_src_lbtsmx_stat_offset_v2
#define csv_src_lbtsmx_stat_offset_v4 csv_src_lbtsmx_stat_offset_v3
#define csv_src_lbtsmx_stat_offset_v5 csv_src_lbtsmx_stat_offset_v4
static const lbmmon_csv_layout_t csv_src_lbtsmx_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT+1] =
{
{ NULL, 0 },
{ NULL, 0 },
{ csv_src_lbtsmx_stat_offset_v2, sizeof(csv_src_lbtsmx_stat_offset_v2)/sizeof(csv_src_lbtsmx_stat_offset_v2[0]) },
{ csv_src_lbtsmx_stat_offset_v3, sizeof(csv_src_lbtsmx_stat_offset_v3)/sizeof(csv_src_lbtsmx_stat_offset_v3[0]) },
{ csv_src_lbtsmx_stat_offset_v4, sizeof(csv_src_lbtsmx_stat_offset_v4)/sizeof(csv_src_lbtsmx_stat_offset_v4[0]) },
{ csv_src_lbtsmx_stat_offset_v5, sizeof(csv_src_lbtsmx_stat_offset_v5)/sizeof(csv_src_lbtsmx_stat_offset_v5[0]) }
};
static size_t csv_src_lbtrdma_stat_offset_v2[] =
{
};
#define csv_src_lbtrdma_stat_offset_v3 csv_src_lbtrdma_stat_offset_v2
#define csv_src_lbtrdma_stat_offset_v4 csv_src_lbtrdma_stat_offset_v3
#define csv_src_lbtrdma_stat_offset_v5 csv_src_lbtrdma_stat_offset_v4
static const lbmmon_csv_layout_t csv_src_lbtrdma_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT+1] =
{
{ NULL, 0 },
{ NULL, 0 },
{ csv_src_lbtrdma_stat_offset_v2, sizeof(csv_src_lbtrdma_stat_offset_v2)/sizeof(csv_src_lbtrdma_stat_offset_v2[0]) },
{ csv_src_lbtrdma_stat_offset_v3, sizeof(csv_src_lbtrdma_stat_offset_v3)/sizeof(csv_src_lbtrdma_stat_offset_v3[0]) },
{ csv_src_lbtrdma_stat_offset_v4, sizeof(csv_src_lbtrdma_stat_offset_v4)/sizeof(csv_src_lbtrdma_stat_offset_v4[0]) },
{ csv_src_lbtrdma_stat_offset_v5, sizeof(csv_src_lbtrdma_stat_offset_v5)/sizeof(csv_src_lbtrdma_stat_offset_v5[0]) }
};
static size_t csv_src_broker_stat_offset_v2[] =
{
};
#define csv_src_broker_stat_offset_v3 csv_src_broker_stat_offset_v2
#define csv_src_broker_stat_offset_v4 csv_src_broker_stat_offset_v3
#define csv_src_broker_stat_offset_v5 csv_src_broker_stat_offset_v4
static const lbmmon_csv_layout_t csv_src_broker_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT+1] =
{
{ NULL, 0 },
{ NULL, 0 },
{ csv_src_broker_stat_offset_v2, sizeof(csv_src_broker_stat_offset_v2)/sizeof(csv_src_broker_stat_offset_v2[0]) },
{ csv_src_broker_stat_offset_v3, sizeof(csv_src_broker_stat_offset_v3)/sizeof(csv_src_broker_stat_offset_v3[0]) },
{ csv_src_broker_stat_offset_v4, sizeof(csv_src_broker_stat_offset_v4)/sizeof(csv_src_broker_stat_offset_v4[0]) },
{ csv_src_broker_stat_offset_v5, sizeof(csv_src_broker_stat_offset_v5)/sizeof(csv_src_broker_stat_offset_v5[0]) }
};
const char * Source, size_t Length, unsigned short ModuleID, void * FormatClientData)
{
const char * ptr;
char value[1024];
lbmmon_format_csv_t * fmt;
size_t idx;
unsigned char modid;
unsigned char modver;
const size_t * stat_layout = NULL;
size_t stat_count = 0;
if ((Statistics == NULL) || (Source == NULL) || (*Source == '\0') || (Length == 0) || (FormatClientData == NULL) )
{
strncpy(ErrorString, "Invalid parameter", sizeof(ErrorString));
}
fmt = (lbmmon_format_csv_t *) FormatClientData;
{
}
{
snprintf(ErrorString, sizeof(ErrorString), "Invalid module ID %u", (unsigned)modid);
}
if (fmt->mBuffer == NULL)
{
fmt->mBufferSize = 1024;
fmt->mBuffer = malloc(fmt->mBufferSize);
if (fmt->mBuffer == NULL)
{
lbmmon_format_csv_report_allocation_error(fmt->mBufferSize);
}
}
if (Length >= fmt->mBufferSize)
{
fmt->mBufferSize = 2 * Length;
free(fmt->mBuffer);
fmt->mBuffer = malloc(fmt->mBufferSize);
if (fmt->mBuffer == NULL)
{
lbmmon_format_csv_report_allocation_error(fmt->mBufferSize);
}
}
memset(fmt->mBuffer, 0, fmt->mBufferSize);
memcpy(fmt->mBuffer, Source, Length);
ptr = fmt->mBuffer;
ptr = next_csv_value(ptr, value, sizeof(value), fmt->mSeparator);
if (ptr == NULL)
{
strncpy(ErrorString, "No type field found", sizeof(ErrorString));
}
Statistics->
type = atoi(value);
ptr = next_csv_value(ptr, Statistics->
source,
sizeof(Statistics->
source), fmt->mSeparator);
if (ptr == NULL)
{
strncpy(ErrorString, "No source field found", sizeof(ErrorString));
}
MUL_DEBUG(LBM_DEBUG_LBMMON, (
"lbmmon_src_format_csv_deserialize (%s) (%d) (%d)\n", Statistics->
source, Statistics->
type, Length));
switch (Statistics->
type)
{
if (modver >= LBMMON_FORMAT_CSV_VERSION_CURRENT)
{
stat_layout = csv_src_tcp_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT].layout;
stat_count = csv_src_tcp_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT].count;
}
else
{
stat_layout = csv_src_tcp_stat_layout[modver].layout;
stat_count = csv_src_tcp_stat_layout[modver].count;
}
for (idx = 0; idx < stat_count; ++idx)
{
ptr = next_csv_value(ptr, value, sizeof(value), fmt->mSeparator);
if (ptr == NULL)
{
strncpy(ErrorString, "Data contains too few fields", sizeof(ErrorString));
}
}
break;
if (modver >= LBMMON_FORMAT_CSV_VERSION_CURRENT)
{
stat_layout = csv_src_lbtrm_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT].layout;
stat_count = csv_src_lbtrm_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT].count;
}
else
{
stat_layout = csv_src_lbtrm_stat_layout[modver].layout;
stat_count = csv_src_lbtrm_stat_layout[modver].count;
}
for (idx = 0; idx < stat_count; ++idx)
{
ptr = next_csv_value(ptr, value, sizeof(value), fmt->mSeparator);
if (ptr == NULL)
{
strncpy(ErrorString, "Data contains too few fields", sizeof(ErrorString));
}
}
break;
if (modver >= LBMMON_FORMAT_CSV_VERSION_CURRENT)
{
stat_layout = csv_src_lbtru_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT].layout;
stat_count = csv_src_lbtru_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT].count;
}
else
{
stat_layout = csv_src_lbtru_stat_layout[modver].layout;
stat_count = csv_src_lbtru_stat_layout[modver].count;
}
for (idx = 0; idx < stat_count; ++idx)
{
ptr = next_csv_value(ptr, value, sizeof(value), fmt->mSeparator);
if (ptr == NULL)
{
strncpy(ErrorString, "Data contains too few fields", sizeof(ErrorString));
}
}
break;
if (modver >= LBMMON_FORMAT_CSV_VERSION_CURRENT)
{
stat_layout = csv_src_lbtipc_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT].layout;
stat_count = csv_src_lbtipc_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT].count;
}
else
{
stat_layout = csv_src_lbtipc_stat_layout[modver].layout;
stat_count = csv_src_lbtipc_stat_layout[modver].count;
}
for (idx = 0; idx < stat_count; ++idx)
{
ptr = next_csv_value(ptr, value, sizeof(value), fmt->mSeparator);
if (ptr == NULL)
{
strncpy(ErrorString, "Data contains too few fields", sizeof(ErrorString));
}
}
break;
if (modver >= LBMMON_FORMAT_CSV_VERSION_CURRENT)
{
stat_layout = csv_src_lbtsmx_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT].layout;
stat_count = csv_src_lbtsmx_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT].count;
}
else
{
stat_layout = csv_src_lbtsmx_stat_layout[modver].layout;
stat_count = csv_src_lbtsmx_stat_layout[modver].count;
}
for (idx = 0; idx < stat_count; ++idx)
{
ptr = next_csv_value(ptr, value, sizeof(value), fmt->mSeparator);
if (ptr == NULL)
{
strncpy(ErrorString, "Data contains too few fields", sizeof(ErrorString));
}
}
break;
if (modver >= LBMMON_FORMAT_CSV_VERSION_CURRENT)
{
stat_layout = csv_src_lbtrdma_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT].layout;
stat_count = csv_src_lbtrdma_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT].count;
}
else
{
stat_layout = csv_src_lbtrdma_stat_layout[modver].layout;
stat_count = csv_src_lbtrdma_stat_layout[modver].count;
}
for (idx = 0; idx < stat_count; ++idx)
{
ptr = next_csv_value(ptr, value, sizeof(value), fmt->mSeparator);
if (ptr == NULL)
{
strncpy(ErrorString, "Data contains too few fields", sizeof(ErrorString));
}
}
break;
if (modver >= LBMMON_FORMAT_CSV_VERSION_CURRENT)
{
stat_layout = csv_src_broker_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT].layout;
stat_count = csv_src_broker_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT].count;
}
else
{
stat_layout = csv_src_broker_stat_layout[modver].layout;
stat_count = csv_src_broker_stat_layout[modver].count;
}
for (idx = 0; idx < stat_count; ++idx)
{
ptr = next_csv_value(ptr, value, sizeof(value), fmt->mSeparator);
if (ptr == NULL)
{
strncpy(ErrorString, "Data contains too few fields", sizeof(ErrorString));
}
}
break;
default:
strncpy(ErrorString, "Invalid LBM transport type", sizeof(ErrorString));
}
{
}
}
static size_t csv_evq_stat_offset_v2[] =
{
};
static size_t csv_evq_stat_offset_v3[] =
{
};
#define csv_evq_stat_offset_v4 csv_evq_stat_offset_v3
#define csv_evq_stat_offset_v5 csv_evq_stat_offset_v4
static const lbmmon_csv_layout_t csv_evq_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT+1] =
{
{ NULL, 0 },
{ NULL, 0 },
{ csv_evq_stat_offset_v2, sizeof(csv_evq_stat_offset_v2)/sizeof(csv_evq_stat_offset_v2[0]) },
{ csv_evq_stat_offset_v3, sizeof(csv_evq_stat_offset_v3)/sizeof(csv_evq_stat_offset_v3[0]) },
{ csv_evq_stat_offset_v4, sizeof(csv_evq_stat_offset_v4)/sizeof(csv_evq_stat_offset_v4[0]) },
{ csv_evq_stat_offset_v5, sizeof(csv_evq_stat_offset_v5)/sizeof(csv_evq_stat_offset_v5[0]) }
};
const char * Source, size_t Length, unsigned short ModuleID, void * FormatClientData)
{
const char * ptr;
char value[1024];
lbmmon_format_csv_t * fmt;
size_t idx;
unsigned char modid;
unsigned char modver;
const size_t * stat_layout = NULL;
size_t stat_count = 0;
if ((Statistics == NULL) || (Source == NULL) || (*Source == '\0') || (Length == 0) || (FormatClientData == NULL) )
{
strncpy(ErrorString, "Invalid parameter", sizeof(ErrorString));
}
fmt = (lbmmon_format_csv_t *) FormatClientData;
{
}
{
snprintf(ErrorString, sizeof(ErrorString), "Invalid module ID %u", (unsigned)modid);
}
if (fmt->mBuffer == NULL)
{
fmt->mBufferSize = 1024;
fmt->mBuffer = malloc(fmt->mBufferSize);
if (fmt->mBuffer == NULL)
{
lbmmon_format_csv_report_allocation_error(fmt->mBufferSize);
}
}
if (Length >= fmt->mBufferSize)
{
fmt->mBufferSize = 2 * Length;
free(fmt->mBuffer);
fmt->mBuffer = malloc(fmt->mBufferSize);
if (fmt->mBuffer == NULL)
{
lbmmon_format_csv_report_allocation_error(fmt->mBufferSize);
}
}
memset(fmt->mBuffer, 0, fmt->mBufferSize);
memcpy(fmt->mBuffer, Source, Length);
ptr = fmt->mBuffer;
if (modver >= LBMMON_FORMAT_CSV_VERSION_CURRENT)
{
stat_layout = csv_evq_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT].layout;
stat_count = csv_evq_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT].count;
}
else
{
stat_layout = csv_evq_stat_layout[modver].layout;
stat_count = csv_evq_stat_layout[modver].count;
}
for (idx = 0; idx < stat_count; ++idx)
{
ptr = next_csv_value(ptr, value, sizeof(value), fmt->mSeparator);
if (ptr == NULL)
{
strncpy(ErrorString, "Data contains too few fields", sizeof(ErrorString));
}
*((
lbm_ulong_t *)(((
unsigned char *) Statistics) + stat_layout[idx])) = convert_value(value);
}
{
}
}
static size_t csv_ctx_stat_offset_v2[] =
{
};
#define csv_ctx_stat_offset_v3 csv_ctx_stat_offset_v2
static size_t csv_ctx_stat_offset_v4[] =
{
};
static size_t csv_ctx_stat_offset_v5[] =
{
};
static const lbmmon_csv_layout_t csv_ctx_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT+1] =
{
{ NULL, 0 },
{ NULL, 0 },
{ csv_ctx_stat_offset_v2, sizeof(csv_ctx_stat_offset_v2)/sizeof(csv_ctx_stat_offset_v2[0]) },
{ csv_ctx_stat_offset_v3, sizeof(csv_ctx_stat_offset_v3)/sizeof(csv_ctx_stat_offset_v3[0]) },
{ csv_ctx_stat_offset_v4, sizeof(csv_ctx_stat_offset_v4)/sizeof(csv_ctx_stat_offset_v4[0]) },
{ csv_ctx_stat_offset_v5, sizeof(csv_ctx_stat_offset_v5)/sizeof(csv_ctx_stat_offset_v5[0]) }
};
const char * Source, size_t Length, unsigned short ModuleID, void * FormatClientData)
{
const char * ptr;
char value[1024];
lbmmon_format_csv_t * fmt;
size_t idx;
unsigned char modid;
unsigned char modver;
const size_t * stat_layout = NULL;
size_t stat_count = 0;
if ((Statistics == NULL) || (Source == NULL) || (*Source == '\0') || (Length == 0) || (FormatClientData == NULL) )
{
strncpy(ErrorString, "Invalid parameter", sizeof(ErrorString));
}
fmt = (lbmmon_format_csv_t *) FormatClientData;
{
}
{
snprintf(ErrorString, sizeof(ErrorString), "Invalid module ID %u", (unsigned)modid);
}
if (fmt->mBuffer == NULL)
{
fmt->mBufferSize = 1024;
fmt->mBuffer = malloc(fmt->mBufferSize);
if (fmt->mBuffer == NULL)
{
lbmmon_format_csv_report_allocation_error(fmt->mBufferSize);
}
}
if (Length >= fmt->mBufferSize)
{
fmt->mBufferSize = 2 * Length;
free(fmt->mBuffer);
fmt->mBuffer = malloc(fmt->mBufferSize);
if (fmt->mBuffer == NULL)
{
lbmmon_format_csv_report_allocation_error(fmt->mBufferSize);
}
}
memset(fmt->mBuffer, 0, fmt->mBufferSize);
memcpy(fmt->mBuffer, Source, Length);
ptr = fmt->mBuffer;
if (modver >= LBMMON_FORMAT_CSV_VERSION_CURRENT)
{
stat_layout = csv_ctx_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT].layout;
stat_count = csv_ctx_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT].count;
}
else
{
stat_layout = csv_ctx_stat_layout[modver].layout;
stat_count = csv_ctx_stat_layout[modver].count;
}
for (idx = 0; idx < stat_count; ++idx)
{
ptr = next_csv_value(ptr, value, sizeof(value), fmt->mSeparator);
if (ptr == NULL)
{
strncpy(ErrorString, "Data contains too few fields", sizeof(ErrorString));
}
*((
lbm_ulong_t *)(((
unsigned char *) Statistics) + stat_layout[idx])) = convert_value(value);
}
{
}
}
void * FormatClientData)
{
const char * ptr;
char value[1024];
lbmmon_format_csv_t * fmt;
size_t idx;
unsigned char modid;
unsigned char modver;
char topic[LBM_MSG_MAX_TOPIC_LEN + 1];
size_t src_count;
if ((Count == NULL) || (*Count == 0) || (Statistics == NULL) || (Source == NULL) || (*Source == '\0') || (Length == 0) || (FormatClientData == NULL) )
{
strncpy(ErrorString, "Invalid parameter", sizeof(ErrorString));
}
fmt = (lbmmon_format_csv_t *) FormatClientData;
{
}
{
snprintf(ErrorString, sizeof(ErrorString), "Invalid module ID %u", (unsigned)modid);
}
if (modver != LBMMON_FORMAT_CSV_VERSION_5)
{
strncpy(ErrorString, "Unknown version", sizeof(ErrorString));
}
if (fmt->mBuffer == NULL)
{
fmt->mBufferSize = 1024;
fmt->mBuffer = malloc(fmt->mBufferSize);
if (fmt->mBuffer == NULL)
{
lbmmon_format_csv_report_allocation_error(fmt->mBufferSize);
}
}
if (Length >= fmt->mBufferSize)
{
fmt->mBufferSize = 2 * Length;
free(fmt->mBuffer);
fmt->mBuffer = malloc(fmt->mBufferSize);
if (fmt->mBuffer == NULL)
{
lbmmon_format_csv_report_allocation_error(fmt->mBufferSize);
}
}
memset(fmt->mBuffer, 0, fmt->mBufferSize);
memcpy(fmt->mBuffer, Source, Length);
ptr = fmt->mBuffer;
ptr = next_csv_value(ptr, value, sizeof(value), fmt->mSeparator);
if (ptr == NULL)
{
strncpy(ErrorString, "Data contains too few fields", sizeof(ErrorString));
}
strncpy(topic, value, sizeof(topic));
ptr = next_csv_value(ptr, value, sizeof(value), fmt->mSeparator);
if (ptr == NULL)
{
strncpy(ErrorString, "Data contains too few fields", sizeof(ErrorString));
}
src_count = (size_t) convert_value(value);
if (*Count < src_count)
{
*Count = src_count;
return (-2);
}
if (src_count == 0)
{
strncpy(Statistics[0].topic, topic, sizeof(Statistics[idx].topic));
src_count = 1;
}
else
{
for (idx = 0; idx < src_count; ++idx)
{
strncpy(Statistics[idx].topic, topic, sizeof(Statistics[idx].topic));
Statistics[idx].
flags |= LBM_RCV_TOPIC_STATS_FLAG_SRC_VALID;
ptr = next_csv_value(ptr, value, sizeof(value), fmt->mSeparator);
if (ptr == NULL)
{
strncpy(ErrorString, "Data contains too few fields", sizeof(ErrorString));
}
strncpy(Statistics[idx].source, (void *) value, sizeof(Statistics[idx].source));
ptr = next_csv_value(ptr, value, sizeof(value), fmt->mSeparator);
if (ptr == NULL)
{
strncpy(ErrorString, "Data contains too few fields", sizeof(ErrorString));
}
lbmmon_format_csv_convert_from_hex((
char *) &(Statistics[idx].otid), (
lbm_uint8_t *) value, strlen(value));
ptr = next_csv_value(ptr, value, sizeof(value), fmt->mSeparator);
if (ptr == NULL)
{
strncpy(ErrorString, "Data contains too few fields", sizeof(ErrorString));
}
}
}
*Count = src_count;
{
}
}
#if 0
static size_t csv_wrcv_stat_offset_v5[] =
{
};
static const lbmmon_csv_layout_t csv_wrcv_stat_layout[LBMMON_FORMAT_CSV_VERSION_CURRENT+1] =
{
{ NULL, 0 },
{ NULL, 0 },
{ NULL, 0 },
{ NULL, 0 },
{ NULL, 0 },
{ csv_wrcv_stat_offset_v5, sizeof(csv_wrcv_stat_offset_v5)/sizeof(csv_wrcv_stat_offset_v5[0]) }
};
#endif
const char * Source, size_t Length, unsigned short ModuleID, void * FormatClientData)
{
const char * ptr;
char value[1024];
lbmmon_format_csv_t * fmt;
unsigned char modid;
unsigned char modver;
if ((Statistics == NULL) || (Source == NULL) || (*Source == '\0') || (Length == 0) || (FormatClientData == NULL) )
{
strncpy(ErrorString, "Invalid parameter", sizeof(ErrorString));
}
fmt = (lbmmon_format_csv_t *) FormatClientData;
{
}
{
snprintf(ErrorString, sizeof(ErrorString), "Invalid module ID %u", (unsigned)modid);
}
if (modver != LBMMON_FORMAT_CSV_VERSION_5)
{
strncpy(ErrorString, "Unknown version", sizeof(ErrorString));
}
if (fmt->mBuffer == NULL)
{
fmt->mBufferSize = 1024;
fmt->mBuffer = malloc(fmt->mBufferSize);
if (fmt->mBuffer == NULL)
{
lbmmon_format_csv_report_allocation_error(fmt->mBufferSize);
}
}
if (Length >= fmt->mBufferSize)
{
fmt->mBufferSize = 2 * Length;
free(fmt->mBuffer);
fmt->mBuffer = malloc(fmt->mBufferSize);
if (fmt->mBuffer == NULL)
{
lbmmon_format_csv_report_allocation_error(fmt->mBufferSize);
}
}
memset(fmt->mBuffer, 0, fmt->mBufferSize);
memcpy(fmt->mBuffer, Source, Length);
ptr = fmt->mBuffer;
ptr = next_csv_value(ptr, value, sizeof(value), fmt->mSeparator);
if (ptr == NULL)
{
strncpy(ErrorString, "Data contains too few fields", sizeof(ErrorString));
}
ptr = next_csv_value(ptr, value, sizeof(value), fmt->mSeparator);
if (ptr == NULL)
{
strncpy(ErrorString, "Data contains too few fields", sizeof(ErrorString));
}
{
}
}
const char * Source, size_t Length, unsigned short ModuleID, void * FormatClientData)
{
strncpy(ErrorString, "CSV format not supported for stores at this time", sizeof(ErrorString));
}
const char * Source, size_t Length, unsigned short ModuleID, void * FormatClientData)
{
strncpy(ErrorString, "CSV format not supported for gateway stats at this time", sizeof(ErrorString));
}
int lbmmon_format_csv_finish(void * FormatClientData)
{
if (FormatClientData != NULL)
{
lbmmon_format_csv_t * data = (lbmmon_format_csv_t *) FormatClientData;
if (data->mBuffer != NULL)
{
free(data->mBuffer);
data->mBuffer = NULL;
}
free(data);
}
return (0);
}
const char * lbmmon_format_csv_errmsg(void)
{
return (ErrorString);
}