1 /* @(#) $Id: ./src/analysisd/lists_make.c, 2011/09/08 dcid Exp $
4 /* Copyright (C) 2009 Trend Micro Inc.
7 * This program is a free software; you can redistribute it
8 * and/or modify it under the terms of the GNU General Public
9 * License (version 3) as published by the FSF - Free Software
16 #include "cdb/cdb_make.h"
21 #include "lists_make.h"
23 void Lists_OP_MakeAll(int force)
25 ListNode *lnode = OS_GetFirstList();
28 Lists_OP_MakeCDB(lnode->txt_filename,
35 void Lists_OP_MakeCDB(char *txt_filename, char *cdb_filename, int force)
46 char str[OS_MAXSTR+1];
49 char tmp_filename[OS_MAXSTR];
50 tmp_filename[OS_MAXSTR - 2] = '\0';
51 snprintf(tmp_filename, OS_MAXSTR - 2, "%s.tmp", txt_filename);
54 if((stat(txt_filename, &txt_stat)) == -1)
55 debug1("%s: stat of file %s failed", ARGV0, txt_filename);
56 if((stat(cdb_filename, &cdb_stat)) == -1)
57 debug1("%s: stat of file %s failed", ARGV0, cdb_filename);
59 if(File_DateofChange(txt_filename) > File_DateofChange(cdb_filename) ||
62 printf(" * File %s need to be updated\n", cdb_filename);
63 tmp_fd = fopen(tmp_filename, "w+");
64 cdb_make_start(&cdbm, tmp_fd);
65 if(!(txt_fd = fopen(txt_filename, "r")))
67 merror(FOPEN_ERROR, ARGV0, txt_filename);
70 while((fgets(str, OS_MAXSTR-1,txt_fd)) != NULL)
72 /* Removing new lines or carriage returns. */
73 tmp_str = strchr(str, '\r');
76 tmp_str = strchr(str, '\n');
79 if((val = strchr(str, ':')))
89 cdb_make_add(&cdbm, key, strlen(key), val, strlen(val));
90 if(force) print_out(" * adding - key: %s value: %s",key,val);
92 cdb_make_finish(&cdbm);
93 rename(tmp_filename,cdb_filename);
97 printf(" * File %s does not need to be compiled\n", cdb_filename);