📄 config.c
字号:
struct stat st; depend_t *depend; depend = (depend_t *) cse_alloc(config->p, sizeof(depend_t)); memset(depend, 0, sizeof(depend_t)); depend->next = config->depend_list; config->depend_list = depend; depend->path = cse_strdup(config->p, path); if (! stat(path, &st)) { depend->last_modified = st.st_mtime; depend->last_size = st.st_size; }}/** * Initialize a web application. */static voidcse_init_web_app(web_app_t *app, registry_t *node, char *app_dir){ config_t *config = app->config; char buf[4096]; FILE *file; char *webXml; cse_init_web_app_contents(app, node ? node->first : 0); if (! app_dir) return; /* XXX: should the registry itself get updated? i.e. adding this // node somewhere? */ webXml = cse_find_inherited_value(node ? node->first : 0, "web-xml", "web.xml"); sprintf(buf, "%s/WEB-INF/%s", app_dir, webXml); /* LOG(("web-app %s\n", buf)); */ cse_add_depend(app->config, buf); file = fopen(buf, "r"); if (file) { registry_t *web = cse_parse(file, config, cse_strdup(config->p, buf)); fclose(file); if (web && web->first) cse_init_web_app_contents(app, web->first->first); }}/** * Initialize the war dir. */static voidcse_init_war_dir(config_t *config, char *host, char *war_dir){#ifndef WIN32 DIR *dir; struct dirent *dirent; /* LOG(("war-dir %s\n", war_dir)); */ cse_add_depend(config, war_dir); dir = opendir(war_dir); if (! dir) return; while ((dirent = readdir(dir))) { char app_dir[4096]; char prefix[4096]; char *name = dirent->d_name; struct stat st; if (! strcmp(name, "ROOT")) sprintf(prefix, "/"); else sprintf(prefix, "/%s", name); sprintf(app_dir, "%s/%s", war_dir, name); if (! stat(app_dir, &st) && S_ISDIR(st.st_mode) && name[0] != '.' && name[0] != '_') { web_app_t *app; /* LOG(("app %s\n", name)); */ app = cse_add_application(config, host, prefix); cse_init_web_app(app, 0, app_dir); if (app && ! app->has_resin_conf) cse_add_location(app, "/*", 0); } } closedir(dir);#else WIN32_FIND_DATA dir; HANDLE hSearch; char buf[8192]; /* LOG(("war-dir %s\n", war_dir)); */ cse_add_depend(config, war_dir); sprintf(buf, "%s/*", war_dir); hSearch = FindFirstFile(buf, &dir); if (hSearch != INVALID_HANDLE_VALUE) { do { char app_dir[4096]; char prefix[4096]; char *name = dir.cFileName; web_app_t *app; struct stat st; char lower[1024]; int i; for (i = 0; name[i]; i++) { if (isupper(name[i])) lower[i] = tolower(name[i]); else lower[i] = name[i]; } lower[i] = 0; if (! strcmp(lower, "root")) sprintf(prefix, "/"); else sprintf(prefix, "/%s", name); sprintf(app_dir, "%s/%s", war_dir, name); if (! stat(app_dir, &st) && (st.st_mode & _S_IFDIR) && name[0] != '.' && name[0] != '_') { /* LOG(("app %s\n", name)); */ app = cse_add_application(config, host, prefix); cse_init_web_app(app, 0, app_dir); if (app && ! app->has_resin_conf) cse_add_location(app, "/*", 0); } } while (FindNextFile(hSearch, &dir)); }#endif}/** * Initialize the configuration mapping for the <host> block. * * @param config configuration structure holding the parsed mapping. * @param node the configuration node for the <host> block. * @param host default host name. * @param app_dir current directory. */static voidcse_init_host(config_t *config, registry_t *node, char *host, char *host_dir, registry_t *default_node){ registry_t *host_default = node; char *expand_dir; web_app_t *app; if (node && (expand_dir = cse_find_value(node->first, "war-expand-dir"))) expand_dir = cse_normalize_path(config, config->resin_home, expand_dir); else if (node && (expand_dir = cse_find_value(node->first, "war-dir"))) expand_dir = cse_normalize_path(config, config->resin_home, expand_dir); else { char buf[1024]; sprintf(buf, "%s/_war", config->work_dir); expand_dir = cse_strdup(config->p, buf); } app = cse_add_application(config, host, ""); cse_init_web_app(app, node, host_dir); cse_init_web_app(app, default_node, 0); if (! host_default) return; for (node = host_default->first; node; node = node->next) { if (! node->value) { } else if (! strcmp(node->key, "web-app")) { char *prefix = node->value; char *subdir = cse_app_dir(config, node, host_dir, expand_dir); app = cse_add_application(config, host, prefix); if (app) app->has_resin_conf = 1; cse_init_web_app(app, node, subdir); cse_init_web_app(app, host_default, 0); cse_init_web_app(app, default_node, 0); } } for (node = host_default->first; node; node = node->next) { if (! node->value) { } else if (! strcmp(node->key, "war-dir") && node->value) { char *subdir = node->value; char war_dir[8192]; if (is_path_absolute(subdir)) sprintf(war_dir, "%s", subdir); else sprintf(war_dir, "%s/%s", config->resin_home, subdir); cse_init_war_dir(config, host, expand_dir); } }}/** * Initialize the dispatch mappings. */static voidcse_init_server(config_t *config, registry_t *node){ registry_t *default_node = node; char *app_dir = cse_app_dir(config, node, config->resin_home, 0); cse_init_host(config, node, "", config->resin_home, 0); if (! node) return; for (node = node->first; node; node = node->next) { if (node->value && ! strcmp(node->key, "host")) { char *name = node->value; char *host_dir = cse_app_dir(config, node, app_dir, 0); cse_init_host(config, node, name, host_dir, default_node); } }}/** * Adds a new backup to the configuration */srun_item_t *cse_add_host(config_t *config, const char *hostname, int port){ return cse_add_host_int(config, hostname, port, -1, "", "", 0, 0);}/** * Adds a new backup to the configuration */srun_item_t *cse_add_backup(config_t *config, const char *hostname, int port){ return cse_add_host_int(config, hostname, port, -1, "", "", 1, 0);}/** * initialize a single srun host */static voidcse_init_host_node(config_t *config, registry_t *id_node, registry_t *node, int is_backup){ int port; char *host; registry_t *host_node = cse_next_link(node, "srun-host"); registry_t *port_node = cse_next_link(node, "srun-port"); registry_t *index_node = cse_next_link(node, "srun-index"); registry_t *ssl_node = cse_next_link(node, "ssl"); registry_t *group_node = cse_next_link(node, "srun-group"); int session; srun_item_t *srun_item = 0; srun_t *srun; registry_t *subnode; char *id = ""; char *group = ""; int is_ssl; if (! host_node) host_node = cse_next_link(node, "host"); if (! port_node) port_node = cse_next_link(node, "port"); if (host_node && host_node->value && *host_node->value && *host_node->value != '*') host = host_node->value; else host = "localhost"; if (port_node && port_node->value && *port_node->value) port = atoi(port_node->value); else port = 6802; if (index_node && index_node->value && *index_node->value) session = atoi(index_node->value) - 1; else session = -1; if (id_node && id_node->value) id = id_node->value; else id = ""; if (group_node && group_node->value) group = group_node->value; else group = ""; is_ssl = (ssl_node && ssl_node->value && strcmp(ssl_node->value, "false") && strcmp(ssl_node->value, "no")); srun_item = cse_add_host_int(config, host, port, session, id, group, is_backup, is_ssl); if (! srun_item) return; srun = srun_item->srun; if (! srun) return; subnode = cse_next_link(id_node->parent->first, "connect-timeout"); if (subnode && subnode->value && *subnode->value) srun->connect_timeout = atoi(subnode->value); subnode = cse_next_link(node, "connect-timeout"); if (subnode && subnode->value && *subnode->value) srun->connect_timeout = atoi(subnode->value); subnode = cse_next_link(id_node->parent->first, "live-time"); if (subnode && subnode->value && *subnode->value) srun->live_time = atoi(subnode->value); subnode = cse_next_link(node, "live-time"); if (subnode && subnode->value && *subnode->value) srun->live_time = atoi(subnode->value); if (srun->live_time < 10) srun->live_time = 10; subnode = cse_next_link(id_node->parent->first, "dead-time"); if (subnode && subnode->value && *subnode->value) srun->dead_time = atoi(subnode->value); subnode = cse_next_link(node, "dead-time"); if (subnode && subnode->value && *subnode->value) srun->dead_time = atoi(subnode->value); if (srun->dead_time < 5) srun->dead_time = 5;}/** * Initialize all the load-balancing hosts in the configuration. */static void cse_init_hosts(config_t *config, registry_t *top){ int has_srun = 0; registry_t *node; for (node = cse_next_link(top, "srun"); node; node = cse_next_link(node->next, "srun")) { has_srun = 1; cse_init_host_node(config, node, node->first, 0); } for (node = cse_next_link(top, "srun-backup"); node; node = cse_next_link(node->next, "srun-backup")) { has_srun = 1; cse_init_host_node(config, node, node->first, 1); }}/** * Logging for the configuration file. */voidcse_log_config(config_t *config){ web_app_t *app = config->applications; for (; app; app = app->next) { location_t *loc = app->locations; for (; loc; loc = loc->next) { LOG(("cfg host:%s%s prefix:%s suffix:%s next:%x\n", app->host ? app->host : "null", app->prefix ? app->prefix : "/", loc->prefix ? loc->prefix : "null", loc->suffix ? loc->suffix : "null", loc->next)); } }}static voidcse_init_error_page(config_t *config, registry_t *node){ for (node = cse_next_link(node, "error-page"); node; node = cse_next_link(node->next, "error-page")) { char *exn = cse_find_value(node->first, "exception-type"); char *code = cse_find_value(node->first, "error-code"); if (exn && ! strcmp(exn, "connection")) config->error_page = cse_find_value(node->first, "location"); else if (! exn && ! code && ! config->error_page) config->error_page = cse_find_value(node->first, "location"); }}/** * Initialize the configuration. */voidcse_init_config(config_t *p_config){ registry_t *root = 0; registry_t *node = 0; FILE *is; char *caucho_status; config_t new_config = *p_config; config_t *config = &new_config; int i; LOG(("initializing from %s\n", config->path)); LOG(("pool %x\n", config->p)); if (! config->p) config->p = cse_create_pool(config); LOG(("post-pool %x\n", config->p)); LOG(("path %x\n", config->path)); LOG(("resin-home %x\n", config->resin_home)); if (! config->resin_home) { int p = strlen(config->path); for (; p >= 0 && (config->path[p] != '/' && config->path[p] != '\\'); p--) { } for (p--; p >= 0 && (config->path[p] != '/' && config->path[p] != '\\'); p--) { } if (p >= 0) { config->resin_home = cse_strdup(config->p, config->path); config->resin_home[p] = 0; } else { config->resin_home = "."; } } LOG(("server-root: %s\n", config->resin_home)); /* // XXX: in theory, should free these, but they only change during // development, so it really shouldn't matter */ config->registry = 0; config->applications = 0; config->error = 0; for (i = 0; i < CACHE_SIZE; i++) { if (g_url_cache[i].uri) { free(g_url_cache[i].uri); free(g_url_cache[i].host); } g_url_cache[i].uri = 0; } config->update_count++; config->disable_caucho_status = 1; config->disable_session_failover = 0; config->srun_list = 0; config->srun_capacity = 0; config->srun_size = 0; config->depend_list = 0; config->session_url_prefix = ";jsessionid="; config->alt_session_prefix = 0; config->alt_session_prefix_length = 0; config->session_cookie = 0; cse_add_depend(config, config->path); is = fopen(config->path, "r");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -