Changeset fc9516a2d8a7585aaaffbaab77009199ca907c90

Show
Ignore:
Timestamp:
06/05/08 14:46:45 (7 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1212677205 +0000
git-parent:

[483ffbb2a71b31651cb48c74c7436508890169f4]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1212677205 +0000
Message:

make loaders have configs, add a directory config to lua for pulling scripts, refs #28

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/modules/lua.c

    r483ffbb rfc9516a  
    1818static noit_log_stream_t nldeb = NULL; 
    1919static noit_hash_table noit_coros = NOIT_HASH_EMPTY; 
     20 
     21struct loader_conf { 
     22  char *script_dir; 
     23}; 
     24static struct loader_conf *__get_loader_conf(noit_module_loader_t *self) { 
     25  struct loader_conf *c; 
     26  c = noit_image_get_userdata(&self->hdr); 
     27  if(!c) { 
     28    c = calloc(1, sizeof(*c)); 
     29    noit_image_set_userdata(&self->hdr, c); 
     30  } 
     31  return c; 
     32} 
     33static void 
     34noit_lua_loader_set_directory(noit_module_loader_t *self, char *dir) { 
     35  struct loader_conf *c = __get_loader_conf(self); 
     36  if(c->script_dir) free(c->script_dir); 
     37  c->script_dir = strdup(dir); 
     38} 
     39static const char * 
     40noit_lua_loader_get_directory(noit_module_loader_t *self) { 
     41  struct loader_conf *c = __get_loader_conf(self); 
     42  return c->script_dir; 
     43} 
    2044 
    2145noit_lua_check_info_t * 
     
    556580} 
    557581static noit_module_t * 
    558 noit_lua_load(noit_module_loader_t *loader, 
    559               char *module_name, 
    560               noit_conf_section_t section) { 
     582noit_lua_loader_load(noit_module_loader_t *loader, 
     583                     char *module_name, 
     584                     noit_conf_section_t section) { 
    561585  noit_module_t *m; 
    562586  lua_State *L; 
     
    564588  char *script; 
    565589  char *object; 
     590  char scriptfile[MAXPATHLEN]; 
    566591   
    567592  noitL(nldeb, "Loading lua module: %s\n", module_name); 
     
    575600    return NULL; 
    576601  } 
     602  snprintf(scriptfile, sizeof(scriptfile), "%s/%s", 
     603           noit_lua_loader_get_directory(loader), script); 
     604  free(script); 
    577605 
    578606  m = noit_blank_module(); 
     
    584612  lmc = calloc(1, sizeof(*lmc)); 
    585613  lmc->object = object; 
    586   lmc->script = script
     614  lmc->script = strdup(scriptfile)
    587615 
    588616  L = lmc->lua_state = lua_open(); 
     
    616644 
    617645static int 
     646noit_lua_loader_config(noit_module_loader_t *self, noit_hash_table *o) { 
     647  char *dir = "."; 
     648  noit_hash_retrieve(o, "directory", strlen("directory"), (void **)&dir); 
     649  noit_lua_loader_set_directory(self, dir); 
     650  return 0; 
     651} 
     652static int 
    618653noit_lua_loader_onload(noit_image_t *self) { 
    619654  nlerr = noit_log_stream_find("error/serf"); 
     
    632667    noit_lua_loader_onload, 
    633668  }, 
    634   noit_lua_load 
     669  noit_lua_loader_config, 
     670  NULL, 
     671  noit_lua_loader_load 
    635672}; 
  • src/noit_module.c

    r5bf243f rfc9516a  
    2727    NULL 
    2828  }, 
     29  NULL, 
     30  NULL, 
    2931  noit_load_module_image 
    3032}; 
     
    191193      continue; 
    192194    } 
     195    if(loader->config) { 
     196      int rv; 
     197      noit_hash_table *config; 
     198      config = noit_conf_get_hash(sections[i], "config"); 
     199      rv = loader->config(loader, config); 
     200      if(rv == 0) { 
     201        noit_hash_destroy(config, free, free); 
     202        free(config); 
     203      } 
     204      else if(rv < 0) { 
     205        noitL(noit_stderr, "Failed to config loader %s\n", loader_name); 
     206        continue; 
     207      } 
     208    } 
     209    if(loader->init && loader->init(loader)) 
     210      noitL(noit_stderr, "Failed to init loader %s\n", loader_name); 
    193211  } 
    194212  if(sections) free(sections); 
  • src/noit_module.h

    r5bf243f rfc9516a  
    1212 
    1313#define NOIT_LOADER_MAGIC         0xA7AD7104 
    14 #define NOIT_LOADER_ABI_VERSION   2 
     14#define NOIT_LOADER_ABI_VERSION   3 
    1515 
    1616typedef struct _noit_image { 
     
    2323} noit_image_t; 
    2424 
     25/* onload: is called immediately after the module is loaded and before it 
     26 *         is configured. 
     27 */ 
     28 
    2529typedef struct _noit_module_loader { 
    2630  noit_image_t hdr; 
     31  int (*config)(struct _noit_module_loader *, noit_hash_table *config); 
     32  int (*init)(struct _noit_module_loader *); 
    2733  struct _noit_module *(*load)(struct _noit_module_loader *loader, 
    2834                               char *module_name, 
    2935                               noit_conf_section_t section); 
    3036} noit_module_loader_t; 
     37 
     38/* config:  is called once to configure the loader itself 
     39 *   init:  is called once, post config to initialize the module 
     40 *   load:  is called each time the loader is asked to load a module 
     41 */ 
    3142 
    3243#define NOIT_MODULE_MAGIC         0x4017DA7A 
     
    4152  void (*cleanup)(struct _noit_module *, noit_check_t *); 
    4253} noit_module_t; 
     54 
     55/*         config: is called to pass the config into the module. 
     56 *           init: is called once to initialize the module 
     57 * initiate_check: is called so start the module against checks 
     58 *        cleanup: is called if a particular check is stopped 
     59 */ 
    4360 
    4461#define NOIT_IMAGE_MAGIC(a)          ((a)->magic)