40 static GDataInputStream*
41 get_DIS_from_filename (
const gchar* filename)
44 GFileInputStream* fis = NULL;
45 GDataInputStream* dis = NULL;
48 file = g_file_new_for_path (filename);
49 fis = g_file_read (file, NULL, &error);
54 g_error (
"%s\n\n", error->message);
56 dis = g_data_input_stream_new (G_INPUT_STREAM(fis));
68 process_file (
const gchar* filepath,
int mode,
struct arglist* script_args)
70 g_debug(
"Processing %s", filepath);
73 g_print (
"Error while processing %s.\n", filepath);
87 process_file_list (
const gchar* list_file,
int mode,
92 GDataInputStream* nvt_list = get_DIS_from_filename(list_file);
96 gchar* line = g_data_input_stream_read_line (nvt_list, NULL, NULL,
103 g_error (
"%s\n\n", error->message);
109 if (process_file(line, mode, script_args))
114 g_object_unref (nvt_list);
126 process_files(
const gchar** files,
int mode,
struct arglist* script_args)
132 if (process_file(files[n], mode, script_args))
146 custom_log_handler(
const gchar *log_domain,
147 GLogLevelFlags log_level,
148 const gchar *message,
151 gint log_mask = GPOINTER_TO_INT (user_data);
152 if ((log_level & log_mask) != 0)
153 g_log_default_handler(log_domain, log_level, message, user_data);
165 static gboolean debug = FALSE;
166 static gchar *include_dir = NULL;
167 static gchar *nvt_file_list = NULL;
168 static const gchar **nvt_files = NULL;
169 struct arglist *script_infos = g_malloc0 (
sizeof (
struct arglist));
170 GError *error = NULL;
171 GOptionContext *option_context;
172 static GOptionEntry entries[] = {
173 {
"debug",
'd', 0, G_OPTION_ARG_NONE, &debug,
174 "Output debug log messages.", NULL},
175 {
"nvt-list",
'l', 0, G_OPTION_ARG_STRING, &nvt_file_list,
176 "Process files from <file>",
"<file>"},
177 {
"include-dir",
'i', 0, G_OPTION_ARG_STRING, &include_dir,
178 "Search for includes in <dir>",
"<dir>"},
179 {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &nvt_files,
180 "Absolute path to one or more nasl scripts",
"NASL_FILE..."},
185 g_option_context_new (
"- standalone NASL linter for OpenVAS");
186 g_option_context_add_main_entries (option_context, entries, NULL);
187 if (!g_option_context_parse (option_context, &argc, &argv, &error))
189 g_error (
"%s\n\n", error->message);
191 g_option_context_free (option_context);
193 #if !GLIB_CHECK_VERSION(2, 35, 0) 206 if (include_dir != NULL)
210 g_log_set_handler (NULL,
213 GINT_TO_POINTER (G_LOG_LEVEL_DEBUG|G_LOG_LEVEL_INFO|
216 G_LOG_LEVEL_CRITICAL|
219 g_log_set_handler (NULL,
222 GINT_TO_POINTER (G_LOG_LEVEL_WARNING|
223 G_LOG_LEVEL_CRITICAL|
227 if (nvt_file_list != NULL)
228 err += process_file_list(nvt_file_list, mode, script_infos);
231 if (nvt_files != NULL)
232 err += process_files(nvt_files, mode, script_infos);
234 g_print (
"%d errors found\n",
err);
int exec_nasl_script(struct arglist *script_infos, const char *name, const char *oid, int mode)
Execute a NASL script.
#define NASL_COMMAND_LINE
#define NASL_ALWAYS_SIGNED
int main(int argc, char **argv)
Main of the nasl QA linter.
int add_nasl_inc_dir(const char *)
Adds the given string as directory for searching for includes.