- Timestamp:
- 06/05/07 10:46:00 (5 years ago)
- Location:
- trunk/ithildin
- Files:
-
- 9 edited
-
include/ithildin/conf.h (modified) (1 diff)
-
include/ithildin/util.h (modified) (1 diff)
-
lib/conf.c (modified) (9 diffs)
-
lib/module.c (modified) (3 diffs)
-
lib/util.c (modified) (3 diffs)
-
modules/ircd/command.c (modified) (1 diff)
-
modules/ircd/conf.c (modified) (2 diffs)
-
modules/ircd/ircd.c (modified) (2 diffs)
-
modules/ircd/protocol.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ithildin/include/ithildin/conf.h
r578 r808 47 47 48 48 /* general conf handling calls */ 49 extern conf_list_t *read_conf(char *); 49 char *find_conf_file(const char *); 50 conf_list_t *read_conf(const char *); 50 51 void destroy_conf_branch(conf_list_t *); 51 52 void conf_display_tree(int, conf_list_t *); -
trunk/ithildin/include/ithildin/util.h
r787 r808 14 14 char *mmap_file(char *); 15 15 char **mmap_file_to_array(char *); 16 17 16 char *sfgets(char *, int, FILE *); 18 17 19 /* these are wrappers for malloc() family functions */ 20 void *calloc_wrap(size_t number, size_t size, char *file, int line); 21 void free_wrap(void *memory, char *file, int line); 22 void *malloc_wrap(size_t size, char *file, int line); 23 void *realloc_wrap(void *ptr, size_t size, char *file, int line); 18 bool is_absolute_path(const char *); 19 char *basename(const char *); 20 char *dirname(const char *); 24 21 25 22 /* subtract timeval 1 from timeval 2 */ -
trunk/ithildin/lib/conf.c
r787 r808 15 15 16 16 /* these are parsing functions */ 17 static char *conf_preparse(c har *, char *);18 static conf_list_t *conf_parse(c har *, int, char *);17 static char *conf_preparse(const char *, char *); 18 static conf_list_t *conf_parse(const char *, int, char *); 19 19 static conf_entry_t *merge_into_conf(conf_list_t *, conf_entry_t *, 20 20 conf_list_t *); 21 21 static char *conf_expand_text(char *); 22 static const char *included_from = NULL; 22 23 23 24 #define parse_err(x) log_error("%s:%d %s", file, line, x); … … 26 27 * tree headed at the conf_list structure it returns. The rest of the 27 28 * functions in this file can then be used to look at this data. */ 28 conf_list_t *read_conf(c har *file) {29 conf_list_t *read_conf(const char *file) { 29 30 char *stuff = NULL; 30 31 conf_list_t *list = NULL; 32 char *fname = NULL; 33 34 /* Look for the file. If it is not an absolute path search first in the 35 * same directory as the file it is being included from (if any) and 36 * then relative to our configured path for config files. */ 37 if (is_absolute_path(file)) 38 fname = strdup(file); 39 else { 40 fname = malloc(PATH_MAX); 41 *fname = '\0'; 42 if (included_from != NULL) { 43 snprintf(fname, PATH_MAX, "%s/%s", dirname(included_from), file); 44 if (access(fname, R_OK) && errno == ENOENT) 45 *fname = '\0'; 46 } 47 if (*fname == '\0') 48 snprintf(fname, PATH_MAX, "%s/%s", me.conf_path, file); 49 if (access(fname, R_OK)) { 50 if (errno != ENOENT) 51 log_error("Could not access file %s (%s)", fname, 52 strerror(errno)); 53 else 54 log_error("Could not find config file %s", fname); 55 free(fname); 56 return NULL; 57 } 58 } 31 59 32 60 /* mmap the data in */ 33 if ((stuff = mmap_file(file)) == NULL) 61 if ((stuff = mmap_file(fname)) == NULL) { 62 log_error("Could not open config file %s", file); 63 free(fname); 34 64 return NULL; 65 } 35 66 36 67 /* weed out comments, and bad strings */ 37 if ((stuff = conf_preparse(file, stuff)) == NULL) 68 if ((stuff = conf_preparse(fname, stuff)) == NULL) { 69 free(fname); 38 70 return NULL; 71 } 39 72 40 73 /* now parse */ 41 list = conf_parse(f ile, 1, stuff);74 list = conf_parse(fname, 1, stuff); 42 75 /* 'stuff' is now not necessary one way or the other */ 43 76 free(stuff); 44 45 if (list == NULL) 46 return NULL; 47 48 /* display_tree(0, list);*/ 77 free(fname); 78 49 79 return list; 50 80 } … … 69 99 70 100 /* this is a debugging function whicb prints the data in 'list' out in a 71 * tree-like format to stdout. */101 * * tree-like format to stdout. */ 72 102 void conf_display_tree(int depth, conf_list_t *list) { 73 103 int i; … … 81 111 ep->string); 82 112 else { 83 printf("%s->[%s]\n", (depth ? "\b" : ""), ep->name);113 printf("%s->[%s]\n", (depth ? "\b" : ""), ep->name); 84 114 conf_display_tree(depth + 1, ep->list); 85 115 } … … 237 267 * and handles reading in included files. It also does light sanity-checking 238 268 * to make sure comments and strings are properly terminated. */ 239 static char *conf_preparse(c har *file, char *oldstr) {269 static char *conf_preparse(const char *file, char *oldstr) { 240 270 char *s = oldstr; 241 271 char *newstr = malloc(strlen(oldstr) + 1); … … 344 374 /* do the final parsing of the data, extract name/value pairs and build our 345 375 * tree, and all with a spot of recursion. yum! */ 346 static conf_list_t *conf_parse(c har *file, int line, char *str) {376 static conf_list_t *conf_parse(const char *file, int line, char *str) { 347 377 conf_list_t *list = malloc(sizeof(conf_list_t)); 348 378 conf_entry_t *ent = NULL, *last = NULL; … … 351 381 int startline = 0; 352 382 353 #define swallow_whitespace() do { \354 while (*str) { \355 if (*str == '\n') \356 line++; \357 if (isspace(*str)) \358 str++; \359 else \360 break; \361 } \383 #define swallow_whitespace() do { \ 384 while (*str) { \ 385 if (*str == '\n') \ 386 line++; \ 387 if (isspace(*str)) \ 388 str++; \ 389 else \ 390 break; \ 391 } \ 362 392 } while (0) 363 393 … … 469 499 conf_list_t *inclist; 470 500 501 included_from = file; 471 502 if ((inclist = read_conf(ent->string)) == NULL) { 472 503 parse_err("error in included file:"); … … 479 510 last = merge_into_conf(list, last, inclist); 480 511 } 512 included_from = NULL; 481 513 } else { 482 514 if (last == NULL) -
trunk/ithildin/lib/module.c
r806 r808 70 70 bool new = false; 71 71 char *s = NULL; 72 char *dname = NULL; 72 73 73 74 if (cep->type == CONF_TYPE_LIST) { … … 97 98 if (clp != NULL) { 98 99 if ((s = conf_find_entry("config", clp, 1)) != NULL) { 99 /* try to access their config file as specified, if it does not 100 * come with a path prefix, we try prepending the conf 101 * directory, then with the full pathname make sure we can load 102 * the conf. if we can't we won't load the module */ 103 m->conffile = malloc(PATH_MAX); 104 if (*s != 's') /* XXX: this will suck come windows support time */ 105 snprintf(m->conffile, PATH_MAX, "%s/%s", me.conf_path, s); 106 else 107 strlcpy(m->conffile, s, PATH_MAX); 108 109 } 110 111 if ((s = conf_find_entry("load", clp, 1)) != NULL && 112 str_conv_bool(s, false)) 113 m->flags |= MODULE_FL_AUTOLOAD; 114 else 100 /* Let the config code sort out the correct path.. */ 101 m->conffile = strdup(s); 102 } 103 104 if ((s = conf_find_entry("load", clp, 1)) != NULL) { 105 if (str_conv_bool(s, false)) 106 m->flags |= MODULE_FL_AUTOLOAD; 107 } else 115 108 m->flags |= MODULE_FL_AUTOLOAD; /* default is to load. */ 116 109 … … 128 121 /* let's also take a stab at guessing their module config file name. 129 122 * We try two things: $confdir/modulename.conf and 130 * $confdir/modulename/modulename.conf. If neither works we do not 131 * make any further efforts. We determine the usability of these 132 * files through the access() call. */ 123 * $confdir/modulename/modulename.conf. For modules with '.'s in 124 * their name we replace the '.'s with path separators and try that 125 * way, using the last portion of the module's name as the name of 126 * the config file. */ 127 s = dname = strdup(m->name); 128 while (*s != '\0') { 129 if (*s == '.') 130 *s = '/'; 131 s++; 132 } 133 133 134 s = malloc(PATH_MAX); 134 snprintf(s, PATH_MAX, "%s/%s.conf", me.conf_path, m->name); 135 /* first try the path without the additional directory layer */ 136 snprintf(s, PATH_MAX, "%s/%s.conf", me.conf_path, dname); 135 137 if (access(s, R_OK) == 0) 136 138 m->conffile = s; 137 139 else { 138 /* don't try the directory method if the module name already 139 * contains slashes (indicating it is subdirectory-ized already) */ 140 if (!strchr(s, '/')) { 141 snprintf(s, PATH_MAX, "%s/%s/%s.conf", me.conf_path, m->name, 142 m->name); 143 if (access(s, R_OK) == 0) 144 m->conffile = s; 145 } 146 } 140 /* Now try the subdirectory method, this is a little weird since 141 * we need to get just the last component of the module's name 142 * (if it has dots in it) */ 143 snprintf(s, PATH_MAX, "%s/%s/%s.conf", me.conf_path, dname, 144 (strchr(m->name, '.') ? strrchr(m->name, '.') + 1 : 145 m->name)); 146 if (access(s, R_OK) == 0) 147 m->conffile = s; 148 } 149 free(dname); 150 if (m->conffile == NULL) 151 free(s); 147 152 } 148 153 -
trunk/ithildin/lib/util.c
r787 r808 41 41 char *canonize_make_human(int size, char type); 42 42 43 /* mmap a file into a single string */ 43 /* memory map a file into a single string (using malloc, though, not 44 * mmap...) */ 44 45 char *mmap_file(char *file) { 45 46 struct stat sb; … … 63 64 64 65 fp = fopen(file, "r"); 65 if (fp ==NULL) {66 if (fp == NULL) { 66 67 free(data); 67 68 return NULL; … … 127 128 } 128 129 130 #define PATH_SEPARATOR '/' 131 /* A function to determine whether a filename given is an absolute path or 132 * not. For unix systems this is a trivial check for a '/', on win32 it 133 * requires that we examine the path for drive letter/etc */ 134 bool is_absolute_path(const char *fname) { 135 if (*fname == PATH_SEPARATOR) 136 return true; 137 return false; 138 } 139 140 /* get the base/dirname of a file (portably). these are also provided by 141 * some operating systems, and we can happily interoperate with those 142 * implementations. */ 143 char bdname_buf[PATH_MAX]; 144 char *basename(const char *fname) { 145 char *s; 146 147 if (strlen(fname) >= PATH_MAX) { 148 errno = EINVAL; 149 return NULL; 150 } 151 152 /* chew off any trailing slashes */ 153 strlcpy(bdname_buf, fname, PATH_MAX); 154 s = bdname_buf + strlen(fname) - 1; 155 while (*s == PATH_SEPARATOR && s >= bdname_buf) 156 *s-- = '\0'; 157 158 if ((s = strrchr(bdname_buf, PATH_SEPARATOR)) == NULL) 159 /* no path separator, easy.. */ 160 return bdname_buf; 161 else { 162 /* just move the end of the string to the beginning with memcpy */ 163 s++; 164 memcpy(bdname_buf, s, strlen(s) + 1); 165 return bdname_buf; 166 } 167 } 168 169 char *dirname(const char *fname) { 170 char *s; 171 172 if (strlen(fname) >= PATH_MAX) { 173 errno = EINVAL; 174 return NULL; 175 } 176 177 /* chew off any trailing slashes */ 178 strlcpy(bdname_buf, fname, PATH_MAX); 179 s = bdname_buf + strlen(fname) - 1; 180 while (*s == PATH_SEPARATOR && s >= bdname_buf) 181 *s-- = '\0'; 182 183 if ((s = strrchr(bdname_buf, PATH_SEPARATOR)) == NULL) { 184 strcpy(bdname_buf, "."); 185 return bdname_buf; 186 } else { 187 while (*s == PATH_SEPARATOR && s >= bdname_buf) 188 *s-- = '\0'; 189 if (*bdname_buf == '\0') 190 strcpy(bdname_buf, "."); 191 return bdname_buf; 192 } 193 } 194 129 195 struct timeval *subtract_timeval(struct timeval tv1, struct timeval tv2) { 130 196 static struct timeval result; -
trunk/ithildin/modules/ircd/command.c
r806 r808 33 33 /* only do all this stuff if the command doesn't exist. */ 34 34 if ((cmd = find_command(name)) == NULL || cmd->flags & COMMAND_FL_ALIAS) { 35 sprintf(mname, "ircd /commands/%s", name);35 sprintf(mname, "ircd.command.%s", name); 36 36 37 37 /* see if this is an alias, if it is warn the user that it is about to -
trunk/ithildin/modules/ircd/conf.c
r806 r808 372 372 } 373 373 if (find_command(ctmp->string) == NULL) { 374 sprintf(mname, "ircd /commands/%s", ctmp->string);374 sprintf(mname, "ircd.command.%s", ctmp->string); 375 375 if (load_module(mname, MODULE_FL_CREATE|MODULE_FL_QUIET)) 376 376 log_debug("loaded command module for %s", ctmp->string); … … 472 472 } 473 473 474 /* also handle usermodes and channel modes.. */ 474 475 static void ircd_parse_addons(conf_list_t *conf) { 475 476 char *s = NULL; 476 477 char mname[PATH_MAX]; 477 478 478 while ((s = conf_find_entry_next("addon", s, conf, 1)) != NULL) { 479 sprintf(mname, "ircd/addons/%s", s); 480 481 if (module_loaded(mname) != 0) 482 continue; 483 484 if (!load_module(mname, 485 MODULE_FL_CREATE|MODULE_FL_QUIET|MODULE_FL_EXPORT)) 486 log_error("unable to load module for addon %s", s); 487 else 488 log_debug("loaded addon module %s", s); 489 } 479 #define ircd_parse_addons_load(type) do { \ 480 s = NULL; \ 481 while ((s = conf_find_entry_next(type, s, conf, 1)) != NULL) { \ 482 sprintf(mname, "ircd.%s.%s", type, s); \ 483 if (module_loaded(mname) != 0) \ 484 continue; \ 485 if (!load_module(mname, MODULE_FL_CREATE|MODULE_FL_QUIET)) \ 486 log_error("unable to load module for %s %s", type, s); \ 487 else \ 488 log_debug("loaded %s module %s", type, s); \ 489 } \ 490 } while (0) 491 ircd_parse_addons_load("addon"); 492 ircd_parse_addons_load("chanmode"); 493 ircd_parse_addons_load("usermode"); 494 #undef ircd_parse_addons_load 490 495 } 491 496 -
trunk/ithildin/modules/ircd/ircd.c
r804 r808 297 297 PRIVILEGE_FL_BOOL, &ui64, NULL); 298 298 } 299 300 /* Initialize our modes. Pass the success of the savedata request in to301 * the loader to tell it what to do. */302 usermode_init(get_module_savedata(savelist, "ircd.umodes",303 &ircd.umodes));304 chanmode_init(get_module_savedata(savelist, "ircd.cmodes",305 &ircd.cmodes));306 299 307 300 /* setup our events. started is always created, since it is destroyed … … 473 466 ircd.mdext.class->iter = class_mdext_iter; 474 467 } 468 469 /* Initialize our modes. Pass the success of the savedata request in to 470 * the loader to tell it what to do. */ 471 usermode_init(get_module_savedata(savelist, "ircd.umodes", 472 &ircd.umodes)); 473 chanmode_init(get_module_savedata(savelist, "ircd.cmodes", 474 &ircd.cmodes)); 475 475 476 476 if (reload) { -
trunk/ithildin/modules/ircd/protocol.c
r806 r808 179 179 protocol_t *pp; 180 180 181 sprintf(mname, "ircd /protocols/%s", name);181 sprintf(mname, "ircd.protocol.%s", name); 182 182 if (!load_module(mname, MODULE_FL_CREATE|MODULE_FL_QUIET)) { 183 183 log_error("unable to load module for protocol %s", name);
Note: See TracChangeset
for help on using the changeset viewer.
