sammler/network.c

50 lines
808 B
C

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "configfile.h"
#include "logging.h"
#include "plugins.h"
#define MAX_SIZE 8192
static char *pktbuf = NULL;
static int pos = 0;
void net_submit(char *hostname, struct sammler_plugin *plugin, char *filename, int ds_id, char *data)
{
int len = 0;
if (pktbuf == NULL) {
pktbuf = malloc(MAX_SIZE);
pos = 0;
}
if (pos == 0) {
len = snprintf(pktbuf, MAX_SIZE - pos, "%s\n", hostname);
if (len < 0 || len >= MAX_SIZE - pos)
return;
pos += len;
}
len = snprintf(pktbuf + pos, MAX_SIZE - pos, "%s:%s:%d %s\n",
plugin->name, filename, ds_id, data);
if (len < 0 || len >= MAX_SIZE - pos)
return;
pos += len;
return;
}
void net_commit()
{
if (pos == 0)
return;
log_print(LOG_ERROR, "%s", pktbuf);
pos = 0;
}