diff options
Diffstat (limited to 'src/eclat.c')
-rw-r--r-- | src/eclat.c | 77 |
1 files changed, 20 insertions, 57 deletions
diff --git a/src/eclat.c b/src/eclat.c index 3703376..86b4627 100644 --- a/src/eclat.c +++ b/src/eclat.c | |||
@@ -15,85 +15,48 @@ | |||
15 | along with Eclat. If not, see <http://www.gnu.org/licenses/>. */ | 15 | along with Eclat. If not, see <http://www.gnu.org/licenses/>. */ |
16 | 16 | ||
17 | #include "eclat.h" | 17 | #include "eclat.h" |
18 | 18 | ||
19 | char *conffile = SYSCONFDIR "/eclat.conf" ; | 19 | char *conffile = SYSCONFDIR "/eclat.conf" ; |
20 | int lint_mode; | 20 | int lint_mode; |
21 | int debug_level[ECLAT_DEBCAT_MAX]; | ||
22 | int dry_run_mode; | 21 | int dry_run_mode; |
23 | int preprocess_only = 0; | 22 | int preprocess_only = 0; |
24 | 23 | ||
25 | char *endpoint = "ec2.amazonaws.com"; | 24 | char *endpoint = "ec2.amazonaws.com"; |
26 | int use_ssl; | 25 | int use_ssl; |
27 | char *access_key; | 26 | char *access_key; |
28 | char *secret_key; | 27 | char *secret_key; |
29 | char *region_name; | 28 | char *region_name; |
30 | enum eclat_command eclat_command; | 29 | enum eclat_command eclat_command; |
31 | 30 | ||
32 | 31 | ||
33 | struct debug_trans { | 32 | static char *categories[] = { |
34 | const char *name; | 33 | "main", |
35 | size_t length; | 34 | "cfgram", |
36 | int cat; | 35 | "cflex", |
36 | "conf", | ||
37 | "curl", | ||
37 | }; | 38 | }; |
38 | 39 | ||
39 | static struct debug_trans debug_trans[] = { | 40 | static void |
40 | #define S(s) #s, sizeof(#s)-1 | 41 | debug_init() |
41 | { S(main), ECLAT_DEBCAT_MAIN }, | ||
42 | { S(cfgram), ECLAT_DEBCAT_CFGRAM }, | ||
43 | { S(cflex), ECLAT_DEBCAT_CFLEX }, | ||
44 | { S(conf), ECLAT_DEBCAT_CONF }, | ||
45 | { S(curl), ECLAT_DEBCAT_CURL }, | ||
46 | { NULL } | ||
47 | }; | ||
48 | |||
49 | static int | ||
50 | parse_debug_level(const char *arg) | ||
51 | { | 42 | { |
52 | unsigned long cat, lev; | 43 | int i; |
53 | char *p; | ||
54 | 44 | ||
55 | if (isascii(*arg) && isdigit(*arg)) { | 45 | for (i = 0; i < sizeof(categories)/sizeof(categories[0]); i++) |
56 | cat = strtoul(arg, &p, 10); | 46 | debug_register(categories[i]); |
57 | if (cat > ECLAT_DEBCAT_MAX) | ||
58 | return -1; | ||
59 | } else { | ||
60 | size_t len = strcspn(arg, "."); | ||
61 | struct debug_trans *dp; | ||
62 | |||
63 | for (dp = debug_trans; dp->name; dp++) | ||
64 | if (dp->length == len && | ||
65 | memcmp(dp->name, arg, len) == 0) | ||
66 | break; | ||
67 | |||
68 | if (!dp->name) | ||
69 | return -1; | ||
70 | cat = dp->cat; | ||
71 | p = (char*) arg + len; | ||
72 | } | ||
73 | |||
74 | if (*p == 0) | ||
75 | lev = 100; | ||
76 | else if (*p != '.') | ||
77 | return -1; | ||
78 | else { | ||
79 | lev = strtoul(p + 1, &p, 10); | ||
80 | if (*p) | ||
81 | return -1; | ||
82 | } | ||
83 | debug_level[cat] = lev; | ||
84 | return 0; | ||
85 | } | 47 | } |
48 | |||
86 | 49 | ||
87 | static void | 50 | static void |
88 | dump(const char *text, FILE *stream, unsigned char *ptr, size_t size) | 51 | dump(const char *text, FILE *stream, unsigned char *ptr, size_t size) |
89 | { | 52 | { |
90 | size_t i; | 53 | size_t i; |
91 | size_t c; | 54 | size_t c; |
92 | unsigned int width = 0x10; | 55 | unsigned int width = 0x10; |
93 | int hex = debug_level[ECLAT_DEBCAT_CURL] > 2; | 56 | int hex = debug_level(ECLAT_DEBCAT_CURL) > 2; |
94 | 57 | ||
95 | if (!hex) | 58 | if (!hex) |
96 | /* without the hex output, we can fit more on screen */ | 59 | /* without the hex output, we can fit more on screen */ |
97 | width = 0x40; | 60 | width = 0x40; |
98 | 61 | ||
99 | fprintf(stream, "%s, %zd bytes (0x%zx)\n", text, size, size); | 62 | fprintf(stream, "%s, %zd bytes (0x%zx)\n", text, size, size); |
@@ -196,13 +159,13 @@ write_callback(void *ptr, size_t size, size_t nmemb, void *data) | |||
196 | XML_Parser parser = data; | 159 | XML_Parser parser = data; |
197 | enum XML_Status status; | 160 | enum XML_Status status; |
198 | int line = XML_GetCurrentLineNumber(parser); | 161 | int line = XML_GetCurrentLineNumber(parser); |
199 | int column = XML_GetCurrentColumnNumber(parser); | 162 | int column = XML_GetCurrentColumnNumber(parser); |
200 | 163 | ||
201 | /* FIXME: Debugging level. */ | 164 | /* FIXME: Debugging level. */ |
202 | if (debug_level[ECLAT_DEBCAT_MAIN] > 10) { | 165 | if (debug_level(ECLAT_DEBCAT_MAIN) > 10) { |
203 | dump_text(stderr, line, column, ptr, realsize); | 166 | dump_text(stderr, line, column, ptr, realsize); |
204 | } | 167 | } |
205 | status = XML_Parse(parser, ptr, realsize, 0); | 168 | status = XML_Parse(parser, ptr, realsize, 0); |
206 | if (status == XML_STATUS_ERROR) { | 169 | if (status == XML_STATUS_ERROR) { |
207 | enum XML_Error error = XML_GetErrorCode(parser); | 170 | enum XML_Error error = XML_GetErrorCode(parser); |
208 | 171 | ||
@@ -212,13 +175,12 @@ write_callback(void *ptr, size_t size, size_t nmemb, void *data) | |||
212 | /* FIXME: better diagnostics. */ | 175 | /* FIXME: better diagnostics. */ |
213 | die(EX_SOFTWARE, "XML parse error at %d:%d: %s", | 176 | die(EX_SOFTWARE, "XML parse error at %d:%d: %s", |
214 | line, column, XML_ErrorString(error)); | 177 | line, column, XML_ErrorString(error)); |
215 | } | 178 | } |
216 | return realsize; | 179 | return realsize; |
217 | } | 180 | } |
218 | |||
219 | 181 | ||
220 | #include "cmdline.h" | 182 | #include "cmdline.h" |
221 | 183 | ||
222 | eclat_command_handler_t handler_tab[] = { | 184 | eclat_command_handler_t handler_tab[] = { |
223 | NULL, | 185 | NULL, |
224 | eclat_start_instance, | 186 | eclat_start_instance, |
@@ -234,20 +196,21 @@ main(int argc, char **argv) | |||
234 | CURL *curl; | 196 | CURL *curl; |
235 | XML_Parser parser; | 197 | XML_Parser parser; |
236 | eclat_partial_tree_t part; | 198 | eclat_partial_tree_t part; |
237 | struct grecs_node *xmltree; | 199 | struct grecs_node *xmltree; |
238 | 200 | ||
239 | set_program_name(argv[0]); | 201 | set_program_name(argv[0]); |
202 | debug_init(); | ||
240 | config_init(); | 203 | config_init(); |
241 | parse_options(argc, argv, &index); | 204 | parse_options(argc, argv, &index); |
242 | 205 | ||
243 | argc -= index; | 206 | argc -= index; |
244 | argv += index; | 207 | argv += index; |
245 | 208 | ||
246 | grecs_gram_trace(debug_level[ECLAT_DEBCAT_CFGRAM]); | 209 | grecs_gram_trace(debug_level(ECLAT_DEBCAT_CFGRAM)); |
247 | grecs_lex_trace(debug_level[ECLAT_DEBCAT_CFLEX]); | 210 | grecs_lex_trace(debug_level(ECLAT_DEBCAT_CFLEX)); |
248 | 211 | ||
249 | if (preprocess_only) | 212 | if (preprocess_only) |
250 | exit(grecs_preproc_run(conffile, grecs_preprocessor) ? | 213 | exit(grecs_preproc_run(conffile, grecs_preprocessor) ? |
251 | EX_CONFIG : 0); | 214 | EX_CONFIG : 0); |
252 | 215 | ||
253 | if (access(conffile, R_OK) == 0) { | 216 | if (access(conffile, R_OK) == 0) { |
@@ -289,15 +252,15 @@ main(int argc, char **argv) | |||
289 | die(EX_USAGE, "no command given"); | 252 | die(EX_USAGE, "no command given"); |
290 | 253 | ||
291 | curl = curl_easy_init(); | 254 | curl = curl_easy_init(); |
292 | if (!curl) | 255 | if (!curl) |
293 | die(EX_UNAVAILABLE, "curl_easy_init failed"); | 256 | die(EX_UNAVAILABLE, "curl_easy_init failed"); |
294 | 257 | ||
295 | if (debug_level[ECLAT_DEBCAT_CURL]) { | 258 | if (debug_level(ECLAT_DEBCAT_CURL)) { |
296 | curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); | 259 | curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); |
297 | if (debug_level[ECLAT_DEBCAT_CURL] > 1) | 260 | if (debug_level(ECLAT_DEBCAT_CURL) > 1) |
298 | curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, | 261 | curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, |
299 | eclat_trace_fun); | 262 | eclat_trace_fun); |
300 | } | 263 | } |
301 | 264 | ||
302 | 265 | ||
303 | /* Create XML parser */ | 266 | /* Create XML parser */ |