|
Packit |
1422b7 |
/* This file implements the liblognorm API.
|
|
Packit |
1422b7 |
* See header file for descriptions.
|
|
Packit |
1422b7 |
*
|
|
Packit |
1422b7 |
* liblognorm - a fast samples-based log normalization library
|
|
Packit |
1422b7 |
* Copyright 2013-2015 by Rainer Gerhards and Adiscon GmbH.
|
|
Packit |
1422b7 |
*
|
|
Packit |
1422b7 |
* Modified by Pavel Levshin (pavel@levshin.spb.ru) in 2013
|
|
Packit |
1422b7 |
*
|
|
Packit |
1422b7 |
* This file is part of liblognorm.
|
|
Packit |
1422b7 |
*
|
|
Packit |
1422b7 |
* This library is free software; you can redistribute it and/or
|
|
Packit |
1422b7 |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit |
1422b7 |
* License as published by the Free Software Foundation; either
|
|
Packit |
1422b7 |
* version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
1422b7 |
*
|
|
Packit |
1422b7 |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
1422b7 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
1422b7 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
1422b7 |
* Lesser General Public License for more details.
|
|
Packit |
1422b7 |
*
|
|
Packit |
1422b7 |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit |
1422b7 |
* License along with this library; if not, write to the Free Software
|
|
Packit |
1422b7 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
Packit |
1422b7 |
*
|
|
Packit |
1422b7 |
* A copy of the LGPL v2.1 can be found in the file "COPYING" in this distribution.
|
|
Packit |
1422b7 |
*/
|
|
Packit |
1422b7 |
#include "config.h"
|
|
Packit |
1422b7 |
#include <string.h>
|
|
Packit |
1422b7 |
#include <errno.h>
|
|
Packit |
1422b7 |
|
|
Packit |
1422b7 |
#include "liblognorm.h"
|
|
Packit |
1422b7 |
#include "v1_liblognorm.h"
|
|
Packit |
1422b7 |
#include "v1_ptree.h"
|
|
Packit |
1422b7 |
#include "lognorm.h"
|
|
Packit |
1422b7 |
#include "annot.h"
|
|
Packit |
1422b7 |
#include "v1_samp.h"
|
|
Packit |
1422b7 |
|
|
Packit |
1422b7 |
#define ERR_ABORT {r = 1; goto done; }
|
|
Packit |
1422b7 |
|
|
Packit |
1422b7 |
#define CHECK_CTX \
|
|
Packit |
1422b7 |
if(ctx->objID != LN_ObjID_CTX) { \
|
|
Packit |
1422b7 |
r = -1; \
|
|
Packit |
1422b7 |
goto done; \
|
|
Packit |
1422b7 |
}
|
|
Packit |
1422b7 |
|
|
Packit |
1422b7 |
|
|
Packit |
1422b7 |
ln_ctx
|
|
Packit |
1422b7 |
ln_v1_inherittedCtx(ln_ctx parent)
|
|
Packit |
1422b7 |
{
|
|
Packit |
1422b7 |
ln_ctx child = ln_initCtx();
|
|
Packit |
1422b7 |
if (child != NULL) {
|
|
Packit |
1422b7 |
child->opts = parent->opts;
|
|
Packit |
1422b7 |
child->dbgCB = parent->dbgCB;
|
|
Packit |
1422b7 |
child->dbgCookie = parent->dbgCookie;
|
|
Packit |
1422b7 |
child->version = parent->version;
|
|
Packit |
1422b7 |
child->ptree = ln_newPTree(child, NULL);
|
|
Packit |
1422b7 |
}
|
|
Packit |
1422b7 |
|
|
Packit |
1422b7 |
return child;
|
|
Packit |
1422b7 |
}
|
|
Packit |
1422b7 |
|
|
Packit |
1422b7 |
|
|
Packit |
1422b7 |
int
|
|
Packit |
1422b7 |
ln_v1_loadSample(ln_ctx ctx, const char *buf)
|
|
Packit |
1422b7 |
{
|
|
Packit |
1422b7 |
// Something bad happened - no new sample
|
|
Packit |
1422b7 |
if (ln_v1_processSamp(ctx, buf, strlen(buf)) == NULL) {
|
|
Packit |
1422b7 |
return 1;
|
|
Packit |
1422b7 |
}
|
|
Packit |
1422b7 |
return 0;
|
|
Packit |
1422b7 |
}
|
|
Packit |
1422b7 |
|
|
Packit |
1422b7 |
|
|
Packit |
1422b7 |
int
|
|
Packit |
1422b7 |
ln_v1_loadSamples(ln_ctx ctx, const char *file)
|
|
Packit |
1422b7 |
{
|
|
Packit |
1422b7 |
int r = 0;
|
|
Packit |
1422b7 |
FILE *repo;
|
|
Packit |
1422b7 |
struct ln_v1_samp *samp;
|
|
Packit |
1422b7 |
int isEof = 0;
|
|
Packit |
1422b7 |
|
|
Packit |
1422b7 |
char *fn_to_free = NULL;
|
|
Packit |
1422b7 |
CHECK_CTX;
|
|
Packit |
1422b7 |
|
|
Packit |
1422b7 |
ctx->conf_file = fn_to_free = strdup(file);
|
|
Packit |
1422b7 |
ctx->conf_ln_nbr = 0;
|
|
Packit |
1422b7 |
|
|
Packit |
1422b7 |
if(file == NULL) ERR_ABORT;
|
|
Packit |
1422b7 |
if((repo = fopen(file, "r")) == NULL) {
|
|
Packit |
1422b7 |
ln_errprintf(ctx, errno, "cannot open file %s", file);
|
|
Packit |
1422b7 |
ERR_ABORT;
|
|
Packit |
1422b7 |
}
|
|
Packit |
1422b7 |
while(!isEof) {
|
|
Packit |
1422b7 |
if((samp = ln_v1_sampRead(ctx, repo, &isEof)) == NULL) {
|
|
Packit |
1422b7 |
/* TODO: what exactly to do? */
|
|
Packit |
1422b7 |
}
|
|
Packit |
1422b7 |
}
|
|
Packit |
1422b7 |
fclose(repo);
|
|
Packit |
1422b7 |
|
|
Packit |
1422b7 |
ctx->conf_file = NULL;
|
|
Packit |
1422b7 |
|
|
Packit |
1422b7 |
done:
|
|
Packit |
1422b7 |
free((void*)fn_to_free);
|
|
Packit |
1422b7 |
return r;
|
|
Packit |
1422b7 |
}
|
|
Packit |
1422b7 |
|