|
Packit |
1422b7 |
/**
|
|
Packit |
1422b7 |
* @file annot.h
|
|
Packit |
1422b7 |
* @brief The annotation set object
|
|
Packit |
1422b7 |
* @class ln_annot annot.h
|
|
Packit |
1422b7 |
*//*
|
|
Packit |
1422b7 |
* Copyright 2011 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 meant to be included by applications using liblognorm.
|
|
Packit |
1422b7 |
* For lognorm library files themselves, include "lognorm.h".
|
|
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 |
#ifndef LIBLOGNORM_ANNOT_H_INCLUDED
|
|
Packit |
1422b7 |
#define LIBLOGNORM_ANNOT_H_INCLUDED
|
|
Packit |
1422b7 |
#include <libestr.h>
|
|
Packit |
1422b7 |
|
|
Packit |
1422b7 |
typedef struct ln_annotSet_s ln_annotSet;
|
|
Packit |
1422b7 |
typedef struct ln_annot_s ln_annot;
|
|
Packit |
1422b7 |
typedef struct ln_annot_op_s ln_annot_op;
|
|
Packit |
1422b7 |
typedef enum {ln_annot_ADD=0, ln_annot_RM=1} ln_annot_opcode;
|
|
Packit |
1422b7 |
|
|
Packit |
1422b7 |
/**
|
|
Packit |
1422b7 |
* List of annotation operations.
|
|
Packit |
1422b7 |
*/
|
|
Packit |
1422b7 |
struct ln_annot_op_s {
|
|
Packit |
1422b7 |
ln_annot_op *next;
|
|
Packit |
1422b7 |
ln_annot_opcode opc; /**< opcode */
|
|
Packit |
1422b7 |
es_str_t *name;
|
|
Packit |
1422b7 |
es_str_t *value;
|
|
Packit |
1422b7 |
};
|
|
Packit |
1422b7 |
|
|
Packit |
1422b7 |
/**
|
|
Packit |
1422b7 |
* annotation object
|
|
Packit |
1422b7 |
*/
|
|
Packit |
1422b7 |
struct ln_annot_s {
|
|
Packit |
1422b7 |
ln_annot *next; /**< used for chaining annotations */
|
|
Packit |
1422b7 |
es_str_t *tag; /**< tag associated for this annotation */
|
|
Packit |
1422b7 |
ln_annot_op *oproot;
|
|
Packit |
1422b7 |
};
|
|
Packit |
1422b7 |
|
|
Packit |
1422b7 |
/**
|
|
Packit |
1422b7 |
* annotation set object
|
|
Packit |
1422b7 |
*
|
|
Packit |
1422b7 |
* Note: we do not (yet) use a hash table. However, performance should
|
|
Packit |
1422b7 |
* be gained by pre-processing rules so that tags directly point into
|
|
Packit |
1422b7 |
* the annotation. This is even faster than hash table access.
|
|
Packit |
1422b7 |
*/
|
|
Packit |
1422b7 |
struct ln_annotSet_s {
|
|
Packit |
1422b7 |
ln_annot *aroot;
|
|
Packit |
1422b7 |
ln_ctx ctx; /**< save our context for easy dbgprintf et al... */
|
|
Packit |
1422b7 |
};
|
|
Packit |
1422b7 |
|
|
Packit |
1422b7 |
/* Methods */
|
|
Packit |
1422b7 |
|
|
Packit |
1422b7 |
|
|
Packit |
1422b7 |
/**
|
|
Packit |
1422b7 |
* Allocates and initializes a new annotation set.
|
|
Packit |
1422b7 |
* @memberof ln_annot
|
|
Packit |
1422b7 |
*
|
|
Packit |
1422b7 |
* @param[in] ctx current library context. This MUST match the
|
|
Packit |
1422b7 |
* context of the parent.
|
|
Packit |
1422b7 |
*
|
|
Packit |
1422b7 |
* @return pointer to new node or NULL on error
|
|
Packit |
1422b7 |
*/
|
|
Packit |
1422b7 |
ln_annotSet* ln_newAnnotSet(ln_ctx ctx);
|
|
Packit |
1422b7 |
|
|
Packit |
1422b7 |
|
|
Packit |
1422b7 |
/**
|
|
Packit |
1422b7 |
* Free annotation set and destruct all members.
|
|
Packit |
1422b7 |
* @memberof ln_annot
|
|
Packit |
1422b7 |
*
|
|
Packit |
1422b7 |
* @param[in] tree pointer to annot to free
|
|
Packit |
1422b7 |
*/
|
|
Packit |
1422b7 |
void ln_deleteAnnotSet(ln_annotSet *as);
|
|
Packit |
1422b7 |
|
|
Packit |
1422b7 |
|
|
Packit |
1422b7 |
/**
|
|
Packit |
1422b7 |
* Find annotation inside set based on given tag name.
|
|
Packit |
1422b7 |
* @memberof ln_annot
|
|
Packit |
1422b7 |
*
|
|
Packit |
1422b7 |
* @param[in] as annotation set
|
|
Packit |
1422b7 |
* @param[in] tag tag name to look for
|
|
Packit |
1422b7 |
*
|
|
Packit |
1422b7 |
* @returns NULL if not found, ptr to object otherwise
|
|
Packit |
1422b7 |
*/
|
|
Packit |
1422b7 |
ln_annot* ln_findAnnot(ln_annotSet *as, es_str_t *tag);
|
|
Packit |
1422b7 |
|
|
Packit |
1422b7 |
|
|
Packit |
1422b7 |
/**
|
|
Packit |
1422b7 |
* Add annotation to set.
|
|
Packit |
1422b7 |
* If an annotation associated with this tag already exists, these
|
|
Packit |
1422b7 |
* are combined. If not, a new annotation is added. Note that the
|
|
Packit |
1422b7 |
* caller must not access any of the objects passed in to this method
|
|
Packit |
1422b7 |
* after it has finished (objects may become deallocated during the
|
|
Packit |
1422b7 |
* method).
|
|
Packit |
1422b7 |
* @memberof ln_annot
|
|
Packit |
1422b7 |
*
|
|
Packit |
1422b7 |
* @param[in] as annotation set
|
|
Packit |
1422b7 |
* @param[in] annot annotation to add
|
|
Packit |
1422b7 |
*
|
|
Packit |
1422b7 |
* @returns 0 on success, something else otherwise
|
|
Packit |
1422b7 |
*/
|
|
Packit |
1422b7 |
int ln_addAnnotToSet(ln_annotSet *as, ln_annot *annot);
|
|
Packit |
1422b7 |
|
|
Packit |
1422b7 |
|
|
Packit |
1422b7 |
/**
|
|
Packit |
1422b7 |
* Allocates and initializes a new annotation.
|
|
Packit |
1422b7 |
* The tag passed in identifies the new annotation. The caller
|
|
Packit |
1422b7 |
* no longer owns the tag string after calling this method, so
|
|
Packit |
1422b7 |
* it must not access the same copy when the method returns.
|
|
Packit |
1422b7 |
* @memberof ln_annot
|
|
Packit |
1422b7 |
*
|
|
Packit |
1422b7 |
* @param[in] tag tag associated to annot (must not be NULL)
|
|
Packit |
1422b7 |
* @return pointer to new node or NULL on error
|
|
Packit |
1422b7 |
*/
|
|
Packit |
1422b7 |
ln_annot* ln_newAnnot(es_str_t *tag);
|
|
Packit |
1422b7 |
|
|
Packit |
1422b7 |
|
|
Packit |
1422b7 |
/**
|
|
Packit |
1422b7 |
* Free annotation and destruct all members.
|
|
Packit |
1422b7 |
* @memberof ln_annot
|
|
Packit |
1422b7 |
*
|
|
Packit |
1422b7 |
* @param[in] tree pointer to annot to free
|
|
Packit |
1422b7 |
*/
|
|
Packit |
1422b7 |
void ln_deleteAnnot(ln_annot *annot);
|
|
Packit |
1422b7 |
|
|
Packit |
1422b7 |
|
|
Packit |
1422b7 |
/**
|
|
Packit |
1422b7 |
* Add an operation to the annotation set.
|
|
Packit |
1422b7 |
* The operation description will be added as entry.
|
|
Packit |
1422b7 |
* @memberof ln_annot
|
|
Packit |
1422b7 |
*
|
|
Packit |
1422b7 |
* @param[in] annot pointer to annot to modify
|
|
Packit |
1422b7 |
* @param[in] op operation
|
|
Packit |
1422b7 |
* @param[in] name name of field, must NOT be re-used by caller
|
|
Packit |
1422b7 |
* @param[in] value value of field, may be NULL (e.g. in remove operation),
|
|
Packit |
1422b7 |
* must NOT be re-used by caller
|
|
Packit |
1422b7 |
* @returns 0 on success, something else otherwise
|
|
Packit |
1422b7 |
*/
|
|
Packit |
1422b7 |
int ln_addAnnotOp(ln_annot *anot, ln_annot_opcode opc, es_str_t *name, es_str_t *value);
|
|
Packit |
1422b7 |
|
|
Packit |
1422b7 |
|
|
Packit |
1422b7 |
/**
|
|
Packit |
1422b7 |
* Annotate an event.
|
|
Packit |
1422b7 |
* This adds annotations based on the event's tagbucket.
|
|
Packit |
1422b7 |
* @memberof ln_annot
|
|
Packit |
1422b7 |
*
|
|
Packit |
1422b7 |
* @param[in] ctx current context
|
|
Packit |
1422b7 |
* @param[in] event event to annotate (updated with anotations on exit)
|
|
Packit |
1422b7 |
* @returns 0 on success, something else otherwise
|
|
Packit |
1422b7 |
*/
|
|
Packit |
1422b7 |
int ln_annotate(ln_ctx ctx, struct json_object *json, struct json_object *tags);
|
|
Packit |
1422b7 |
|
|
Packit |
1422b7 |
#endif /* #ifndef LOGNORM_ANNOT_H_INCLUDED */
|