hooks.c

Go to the documentation of this file.
00001 /*----------------------------------------------------------------------------
00002  secwatch - Copyright (C) 2006 Nic Stevens -- See COPYING for license details
00003 ------------------------------------------------------------------------------
00004  hooks.c - functions to allow modules to hook into various scanning and 
00005  processing loops
00006 -----------------------------------------------------------------------------*/
00007 #ifdef HAVE_CONFIG_H
00008 #include <config.h>
00009 #endif
00010 #include <stdio.h>
00011 #include <string.h>
00012 #include <stdlib.h>
00013 #include <unistd.h>
00014 #include <strutil.h>
00015 #include <configfile.h>
00016 #include <funprotos.h>
00017 
00018 static hookfn_t * loghooks = NULL;
00019 static int hookcnt = 0;
00020 
00021 static loopfn_t * loophooks = NULL;
00022 static int loopcnt = 0;
00028 int addLogHook(hookfn_t hf) {
00029      int hp = hookcnt ++;
00030      if((loghooks = realloc(loghooks,(sizeof(hookfn_t)*hookcnt))) == NULL)
00031           return -1;
00032      loghooks[hp] = hf;
00033      return 0;
00034 }
00038 void processLogHooks(char *buf) {
00039      int i;
00040      if(loghooks == NULL) 
00041           return;
00042      
00043      for(i = 0; i < hookcnt; i++) 
00044           loghooks[i](0,buf);
00045 }
00051 int addLoopHook(loopfn_t hf) {
00052      int hp = hookcnt ++;
00053      if((loophooks = realloc(loophooks,(sizeof(hookfn_t)*hookcnt))) == NULL)
00054           return -1;
00055      loophooks[hp] = hf;
00056      return 0;
00057 }
00061 void processLoopHooks(char *buf) {
00062      int i;
00063      if(loophooks == NULL) 
00064           return;
00065      
00066      for(i = 0; i < hookcnt; i++) 
00067           loophooks[i]();
00068 }

Generated on Tue Oct 31 10:17:23 2006 for secwatch by  doxygen 1.4.6