📄 resin.c
字号:
! strcmp(argv[i], "-java-home")) { g_options.java_home = strdup(argv[i + 1]); i++; } else if (! strcmp(argv[i], "-J-classic")) { g_options.jvm_type = "classic"; } else if (! strcmp(argv[i], "-J-server")) { g_options.jvm_type = "server"; } else if (! strcmp(argv[i], "-J-client")) { g_options.jvm_type = "client"; } else if (! strcmp(argv[i], "-resin_home") || ! strcmp(argv[i], "-resin-home")) { g_options.resin_home = strdup(argv[i + 1]); i++; } else if (! strcmp(argv[i], "-resin-child")) { g_options.is_child = 1; } else if (! strcmp(argv[i], "-server_root") || ! strcmp(argv[i], "-server-root")) { g_options.server_root = strdup(argv[i + 1]); i++; } else if (! strcmp(argv[i], "-conf") || ! strcmp(argv[i], "-conf")) { new_argv[j++] = argv[i]; new_argv[j++] = argv[i + 1]; g_options.conf = strdup(argv[i + 1]); i++; } else if (! strcmp(argv[i], "-classpath") || ! strcmp(argv[i], "-cp")) { g_options.classpath = strdup(argv[i + 1]); i++; } else if (! strcmp(argv[i], "-loadpath") || ! strcmp(argv[i], "-lp")) { g_options.loadpath = strdup(argv[i + 1]); i++; } else if (! strncmp(argv[i], "-D", 2) || ! strncmp(argv[i], "-X", 2)) { add_jvm_option("%s", argv[i]); } else if (! strncmp(argv[i], "-J", 2)) { if (! strcmp(argv[i] + 2, "-verbosegc")) add_jvm_option("-verbose:gc", ""); else add_jvm_option("%s", argv[i] + 2); } else if (! strcmp(argv[i], "-verbosegc")) { add_jvm_option("-verbose:gc", ""); } else if (! strcmp(argv[i], "-stdout")) { g_options.stdout_path = strdup(argv[i + 1]); i++; } else if (! strcmp(argv[i], "-stderr")) { g_options.stderr_path = strdup(argv[i + 1]); i++; } else if (! strcmp(argv[i], "-pid")) { g_options.pid = strdup(argv[i + 1]); i++; } else if (! strcmp(argv[i], "-server")) { new_argv[j++] = argv[i]; new_argv[j++] = argv[i + 1]; g_options.server = strdup(argv[i + 1]); i++; } else if (! strcmp(argv[i], "-verbose")) { g_options.verbose = 1; } else if (! strcmp(argv[i], "start")) { g_options.start = 1; } else if (! strcmp(argv[i], "stop")) { g_options.stop = 1; } else if (! strcmp(argv[i], "restart")) { g_options.restart = 1; g_options.start = 1; } else { new_argv[j++] = argv[i]; } } new_argv[j] = 0; return new_argv;}/** * unwinds a linked path, returning the original directory. */static char *unwind_link(char *path, char *test_tail){ struct stat st; int tail = 0; path = strdup(path); while ((! lstat(path, &st)) && S_ISLNK(st.st_mode)) { char buf[8192]; readlink(path, buf, sizeof(buf)); path = strdup(buf); } for (tail = strlen(path); tail >= 0; tail--) { if (path[tail] == '/') { path[tail] = 0; if (is_file(path, test_tail)) { return path; } } } return 0;}/** * Finds a link in a classpath-like path */static char *find_link_in_path(char *path, char *test_tail, char *exe){ char *head; char *tail = 0; for (head = path; head && *head; head = tail) { char buf[8192]; struct stat st; tail = strchr(head, ':'); if (tail) { *tail = 0; tail++; } sprintf(buf, "%s/%s", head, exe); if (! stat(buf, &st)) { char *dir = unwind_link(buf, test_tail); if (dir) return dir; } } return 0;}/** * Finds the value of java_home * * 1) command-line * 2) getenv("JAVA_HOME") * 3) find by searching back the "java" command * 4) trying /usr/java */static voidfind_java_home(){ char *java_home; char *path; if (g_options.java_home) return; if ((java_home = getenv("JAVA_HOME"))) { g_options.java_home = strdup(java_home); return; } path = getenv("PATH"); if (path) { path = strdup(path); g_options.java_home = find_link_in_path(path, "jre/lib/rt.jar", "java"); } if (! g_options.java_home) g_options.java_home = "/usr/java";}/** * Finds the value of resin_home * * 1) command-line * 2) getenv("RESIN_HOME") * 3) trying /usr/local/resin */static voidfind_resin_home(char *cmd){ char *resin_home; if (g_options.resin_home) { return; } if ((resin_home = getenv("RESIN_HOME"))) { g_options.resin_home = strdup(resin_home); return; } g_options.resin_home = unwind_link(cmd, "lib/jsdk23.jar"); if (g_options.resin_home) return; if (! g_options.resin_home) { char buf[8192]; getcwd(buf, sizeof(buf)); g_options.resin_home = strdup(buf); }}/** * Convert a possibly relative path to an absolute path. */static char *normalize_path(char *path){ char buf[8192]; if (path[0] == '/') return path; buf[0] = 0; getcwd(buf, sizeof(buf)); strcat(buf, "/"); strcat(buf, path); return strdup(buf);}static voidinit_java(JNIEnv *env){ jclass classID; jmethodID methodID; /* jni_vfs_init(env); */ classID = (*env)->FindClass(env, "com/caucho/server/http/JniServer"); if (classID == 0) { fprintf(stderr, "Class not found: com.caucho.server.http.JniServer\n"); exit(1); } g_java.jni_server = classID; /* Get the application's main method */ methodID = (*env)->GetStaticMethodID(env, g_java.jni_server, "main", "(I[Ljava/lang/String;)V"); if (! methodID) { fprintf(stderr, "Can't find static main com.caucho.server.http.JniServer\n"); exit(1); } g_java.main = methodID;}/** * Reads the configuration file * * @param name the configuration file name, if specified on the command-line. */config_t *read_config(char *name){ FILE *file; config_t *config = cse_malloc(sizeof(config_t)); memset(config, 0, sizeof(config_t)); config->p = cse_create_pool(config); config->resin_home = g_options.server_root; if (! name) name = "conf/resin.conf"; file = fopen(name, "r"); if (! file) { fprintf(stderr, "can't find config file %s\n", name); exit(1); } config->registry = cse_parse(file, config, name); fclose(file); return config;}static intssl_create_node(server_socket_t *ss, registry_t *node){ ssl_config_t *config; char *flags; char *verify_mode; config = cse_malloc(sizeof(ssl_config_t)); memset(config, 0, sizeof(ssl_config_t)); ss->ssl_config = config; config->crypto_device = cse_find_value(node->first, "crypto-device"); config->alg_flags = ~0; flags = cse_find_value(node->first, "ssl2"); if (flags && ! strcmp(flags, "false")) config->alg_flags &= ~ALG_SSL2; flags = cse_find_value(node->first, "ssl3"); if (flags && ! strcmp(flags, "false")) config->alg_flags &= ~ALG_SSL3; flags = cse_find_value(node->first, "tls1"); if (flags && ! strcmp(flags, "false")) config->alg_flags &= ~ALG_TLS1; config->certificate_file = cse_find_value(node->first, "certificate-file"); if (! config->certificate_file) config->certificate_file = cse_find_value(node->first, "certificate-pem"); config->key_file = cse_find_value(node->first, "certificate-key-file"); if (! config->key_file) config->key_file = cse_find_value(node->first, "key-pem"); if (! config->key_file) config->key_file = config->certificate_file; if (! config->certificate_file) config->certificate_file = config->key_file; config->password = cse_find_value(node->first, "certificate-key-password"); if (! config->password) config->password = cse_find_value(node->first, "key-store-password"); config->certificate_chain_file = cse_find_value(node->first, "certificate-chain-file"); config->ca_certificate_path = cse_find_value(node->first, "ca-certificate-path"); config->ca_certificate_file = cse_find_value(node->first, "ca-certificate-file"); config->ca_revocation_path = cse_find_value(node->first, "ca-revocation-path"); config->ca_revocation_file = cse_find_value(node->first, "ca-revocation-file"); verify_mode = cse_find_value(node->first, "verify-client"); if (! verify_mode || ! *verify_mode) config->verify_client = Q_VERIFY_NONE; else if (! strcmp(verify_mode, "none")) config->verify_client = Q_VERIFY_NONE; else if (! strcmp(verify_mode, "optional_no_ca")) config->verify_client = Q_VERIFY_OPTIONAL_NO_CA; else if (! strcmp(verify_mode, "optional")) config->verify_client = Q_VERIFY_OPTIONAL; else if (! strcmp(verify_mode, "require")) config->verify_client = Q_VERIFY_REQUIRE; else { fprintf(stderr, "unknown verify-client value %s\n", verify_mode); return 0; } return ssl_create(ss, config);}/** * Binds the appropriate ports * * @param node the port's configuration node. * * @return the filedescriptor for the bound port */static server_socket_t *bind_port(registry_t *node){ char *value; char *host; int port; int ss; server_socket_t *socket; if (! node) { fprintf(stderr, "no <http> server entries defined.\n"); exit(1); } host = cse_find_value(node->first, "host"); if (! host) host = "*"; value = cse_find_value(node->first, "port"); if (value) port = atoi(value); else port = 8080; ss = cse_bind(host, port); if (ss < 0) { fprintf(stderr, "Can't bind to port %s:%d. Check for conflicting servers\n", host, port); exit(1); } value = cse_find_value(node->first, "request-timeout"); socket = (server_socket_t *) cse_malloc(sizeof(server_socket_t)); memset(socket, 0, sizeof(server_socket_t)); socket->fd = ss; socket->port = port; pthread_mutex_init(&socket->ssl_lock, 0); if (value) socket->request_timeout = atoi(value); else socket->request_timeout = 30; if (socket->request_timeout <= 0) socket->request_timeout = 30; if (socket->request_timeout < 10) socket->request_timeout = 10; if (cse_next_link(node->first, "ssl")) { if (! ssl_create_node(socket, node)) exit(1); fprintf(stdout, "%ss listening to %s:%d\n", node->key, host, port); } else { socket->accept = &std_accept; fprintf(stdout, "%s listening to %s:%d\n", node->key, host, port); } return socket;}/** * Count the number of ports to bind. */static intcount_ports(registry_t *node, char *server){ int count = 0; if (node) node = cse_next_link(node->first, "caucho.com"); if (node) node = cse_next_link(node->first, "http-server"); if (! node) return 0; for (node = node->first; node; node = node->next) { if (! strcmp(node->key, "http") || ! strcmp(node->key, "srun") || ! strcmp(node->key, "srun-backup") || ! strcmp(node->key, "srun-backup") || ! strcmp(node->key, "server")) { if ((! server && ! node->value) || (server && node->value && ! strcmp(server, node->value))) count++; } } return count;}/** * Binds the appropriate ports * * @param node the port's configuration node. * * @return the filedescriptor for the bound port */static voidconfigure_ports(registry_t *node, char *server){ int count; if (node) node = cse_next_link(node->first, "caucho.com"); if (node) node = cse_next_link(node->first, "http-server"); if (node) node = node->first; count = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -