Changeset e6b4cf6a1124487d96198a65530f9cf02b65e7d1
- Timestamp:
- 09/25/09 18:28:59
(4 years ago)
- Author:
- Theo Schlossnagle <jesus@omniti.com>
- git-committer:
- Theo Schlossnagle <jesus@omniti.com> 1253903339 +0000
- git-parent:
[4dd8a488802d75bd0661c3e90912b84d7cf3bf7b]
- git-author:
- Theo Schlossnagle <jesus@omniti.com> 1253903339 +0000
- Message:
refs #188
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r88a7178 |
re6b4cf6 |
|
| 69 | 69 | static noit_hash_table loaders = NOIT_HASH_EMPTY; |
|---|
| 70 | 70 | static noit_hash_table modules = NOIT_HASH_EMPTY; |
|---|
| | 71 | static noit_hash_table generics = NOIT_HASH_EMPTY; |
|---|
| 71 | 72 | |
|---|
| 72 | 73 | noit_module_loader_t * noit_loader_lookup(const char *name) { |
|---|
| … | … | |
| 86 | 87 | } |
|---|
| 87 | 88 | |
|---|
| | 89 | noit_module_generic_t * noit_module_generic_lookup(const char *name) { |
|---|
| | 90 | void *vmodule; |
|---|
| | 91 | |
|---|
| | 92 | if(noit_hash_retrieve(&generics, name, strlen(name), &vmodule)) |
|---|
| | 93 | return (noit_module_generic_t *)vmodule; |
|---|
| | 94 | return NULL; |
|---|
| | 95 | } |
|---|
| | 96 | |
|---|
| 88 | 97 | static int noit_module_validate_magic(noit_image_t *obj) { |
|---|
| 89 | 98 | if (NOIT_IMAGE_MAGIC(obj) != NOIT_MODULE_MAGIC) return -1; |
|---|
| 90 | 99 | if (NOIT_IMAGE_VERSION(obj) != NOIT_MODULE_ABI_VERSION) return -1; |
|---|
| | 100 | return 0; |
|---|
| | 101 | } |
|---|
| | 102 | |
|---|
| | 103 | static int noit_module_generic_validate_magic(noit_image_t *obj) { |
|---|
| | 104 | if (NOIT_IMAGE_MAGIC(obj) != NOIT_GENERIC_MAGIC) return -1; |
|---|
| | 105 | if (NOIT_IMAGE_VERSION(obj) != NOIT_GENERIC_ABI_VERSION) return -1; |
|---|
| 91 | 106 | return 0; |
|---|
| 92 | 107 | } |
|---|
| … | … | |
| 161 | 176 | noit_hash_store(registry, obj->name, strlen(obj->name), obj); |
|---|
| 162 | 177 | return 0; |
|---|
| | 178 | } |
|---|
| | 179 | |
|---|
| | 180 | static noit_module_generic_t * |
|---|
| | 181 | noit_load_generic_image(noit_module_loader_t *loader, |
|---|
| | 182 | char *g_name, |
|---|
| | 183 | noit_conf_section_t section) { |
|---|
| | 184 | char g_file[PATH_MAX]; |
|---|
| | 185 | |
|---|
| | 186 | if(!noit_conf_get_stringbuf(section, "ancestor-or-self::node()/@image", |
|---|
| | 187 | g_file, sizeof(g_file))) { |
|---|
| | 188 | noitL(noit_stderr, "No image defined for %s\n", g_name); |
|---|
| | 189 | return NULL; |
|---|
| | 190 | } |
|---|
| | 191 | if(noit_load_image(g_file, g_name, &generics, |
|---|
| | 192 | noit_module_generic_validate_magic, |
|---|
| | 193 | sizeof(noit_module_generic_t))) { |
|---|
| | 194 | noitL(noit_stderr, "Could not load %s:%s\n", g_file, g_name); |
|---|
| | 195 | return NULL; |
|---|
| | 196 | } |
|---|
| | 197 | return noit_module_generic_lookup(g_name); |
|---|
| 163 | 198 | } |
|---|
| 164 | 199 | |
|---|
| … | … | |
| 344 | 379 | noit_console_add_help("module", noit_module_help, noit_module_options); |
|---|
| 345 | 380 | |
|---|
| | 381 | /* Load our generic modules */ |
|---|
| | 382 | sections = noit_conf_get_sections(NULL, "/noit/modules//generic", &cnt); |
|---|
| | 383 | for(i=0; i<cnt; i++) { |
|---|
| | 384 | char g_name[256]; |
|---|
| | 385 | noit_module_generic_t *gen; |
|---|
| | 386 | |
|---|
| | 387 | if(!noit_conf_get_stringbuf(sections[i], "ancestor-or-self::node()/@name", |
|---|
| | 388 | g_name, sizeof(g_name))) { |
|---|
| | 389 | noitL(noit_stderr, "No name defined in generic stanza %d\n", i+1); |
|---|
| | 390 | continue; |
|---|
| | 391 | } |
|---|
| | 392 | gen = noit_load_generic_image(&__noit_image_loader, g_name, |
|---|
| | 393 | sections[i]); |
|---|
| | 394 | if(!gen) { |
|---|
| | 395 | noitL(noit_stderr, "Failed to load generic %s\n", g_name); |
|---|
| | 396 | continue; |
|---|
| | 397 | } |
|---|
| | 398 | if(gen->config) { |
|---|
| | 399 | int rv; |
|---|
| | 400 | noit_hash_table *config; |
|---|
| | 401 | config = noit_conf_get_hash(sections[i], "config"); |
|---|
| | 402 | rv = gen->config(gen, config); |
|---|
| | 403 | if(rv == 0) { |
|---|
| | 404 | noit_hash_destroy(config, free, free); |
|---|
| | 405 | free(config); |
|---|
| | 406 | } |
|---|
| | 407 | else if(rv < 0) { |
|---|
| | 408 | noitL(noit_stderr, "Failed to config generic %s\n", g_name); |
|---|
| | 409 | continue; |
|---|
| | 410 | } |
|---|
| | 411 | } |
|---|
| | 412 | if(gen->init && gen->init(gen)) |
|---|
| | 413 | noitL(noit_stderr, "Failed to init generic %s\n", g_name); |
|---|
| | 414 | } |
|---|
| | 415 | if(sections) free(sections); |
|---|
| 346 | 416 | /* Load our module loaders */ |
|---|
| 347 | 417 | sections = noit_conf_get_sections(NULL, "/noit/modules//loader", &cnt); |
|---|
| r88a7178 |
re6b4cf6 |
|
| 54 | 54 | * is configured. |
|---|
| 55 | 55 | */ |
|---|
| | 56 | |
|---|
| | 57 | typedef struct _noit_module_generic { |
|---|
| | 58 | noit_image_t hdr; |
|---|
| | 59 | int (*config)(struct _noit_module_generic *, noit_hash_table *config); |
|---|
| | 60 | int (*init)(struct _noit_module_generic *); |
|---|
| | 61 | } noit_module_generic_t; |
|---|
| | 62 | |
|---|
| | 63 | #define NOIT_GENERIC_MAGIC 0x3FD892A0 |
|---|
| | 64 | #define NOIT_GENERIC_ABI_VERSION 1 |
|---|
| 56 | 65 | |
|---|
| 57 | 66 | typedef struct _noit_module_loader { |
|---|