save_execute.c revision 255332
1#include "ipf.h" 2#include "ipmon.h" 3 4static void *execute_parse __P((char **)); 5static void execute_destroy __P((void *)); 6static int execute_send __P((void *, ipmon_msg_t *)); 7static void execute_print __P((void *)); 8 9typedef struct execute_opts_s { 10 char *path; 11} execute_opts_t; 12 13ipmon_saver_t executesaver = { 14 "execute", 15 execute_destroy, 16 NULL, /* dup */ 17 NULL, /* match */ 18 execute_parse, 19 execute_print, 20 execute_send 21}; 22 23 24static void * 25execute_parse(char **strings) 26{ 27 execute_opts_t *ctx; 28 29 ctx = calloc(1, sizeof(*ctx)); 30 31 if (ctx != NULL && strings[0] != NULL && strings[0][0] != '\0') { 32 ctx->path = strdup(strings[0]); 33 34 } else { 35 free(ctx); 36 return NULL; 37 } 38 39 return ctx; 40} 41 42 43static void 44execute_print(ctx) 45 void *ctx; 46{ 47 execute_opts_t *exe = ctx; 48 49 printf("%s", exe->path); 50} 51 52 53static void 54execute_destroy(ctx) 55 void *ctx; 56{ 57 execute_opts_t *exe = ctx; 58 59 if (exe != NULL) 60 free(exe->path); 61 free(exe); 62} 63 64 65static int 66execute_send(ctx, msg) 67 void *ctx; 68 ipmon_msg_t *msg; 69{ 70 execute_opts_t *exe = ctx; 71 FILE *fp; 72 73 fp = popen(exe->path, "w"); 74 if (fp != NULL) { 75 fwrite(msg->imm_msg, msg->imm_msglen, 1, fp); 76 pclose(fp); 77 } 78 return 0; 79} 80 81