int NsSock_ModInit(char *server, char *module) { Ns_DriverInitData init; char *path; int async; path = Ns_ConfigGetPath(server, module, NULL); if (!Ns_ConfigGetBool(path, "async", &async)) { async = 1; } /* * Initialize the driver with the async option so that the driver thread * will perform event-driven read-ahead of the request before * passing to the connection for processing. */ init.version = NS_DRIVER_VERSION_1; init.name = "nssock"; init.proc = SockProc; init.opts = (async ? NS_DRIVER_ASYNC : 0); init.arg = NULL; init.path = NULL; return Ns_DriverInit(server, module, &init); }
static void php_ns_config(php_ns_context *ctx, char global) { int i; char *path; Ns_Set *set; path = Ns_ConfigGetPath(ctx->ns_server, ctx->ns_module, NULL); set = Ns_ConfigGetSection(path); for (i = 0; set && i < Ns_SetSize(set); i++) { char *key = Ns_SetKey(set, i); char *value = Ns_SetValue(set, i); if (global && !strcasecmp(key, "map")) { Ns_Log(Notice, "Registering PHP for \"%s\"", value); Ns_RegisterRequest(ctx->ns_server, "GET", value, php_ns_request_handler, NULL, ctx, 0); Ns_RegisterRequest(ctx->ns_server, "POST", value, php_ns_request_handler, NULL, ctx, 0); Ns_RegisterRequest(ctx->ns_server, "HEAD", value, php_ns_request_handler, NULL, ctx, 0); /* * Deactivated for now. The ini system will cause random crashes when * accessed from here (since there are no locks to protect the global * known_directives) */ } else if (!global && !strcasecmp(key, "php_value")) { Ns_Log(Notice, "php_value has been deactivated temporarily. Please use a php.ini file to pass directives to PHP. Thanks."); #if 0 char *val; val = strchr(value, ' '); if (val) { char *new_key; new_key = estrndup(value, val - value); do { val++; } while(*val == ' '); Ns_Log(Debug, "PHP configuration option '%s=%s'", new_key, val); zend_alter_ini_entry(new_key, strlen(new_key) + 1, val, strlen(val) + 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE); efree(new_key); } #endif } } }
/** Standard AOLserver callback. * Initialize jk2, unless already done in another server. Register URI mappping for Tomcat * If multiple virtual servers use this module, calls to Ns_ModuleInit will be made serially * in order of appearance of those servers in nsd.tcl */ int Ns_ModuleInit(char *server, char *module) { jk_env_t *env; /* configuration-related */ char* serverName=NULL; char* confPath; static char cwdBuf[PATH_MAX]; static char* serverRoot = NULL; /* APR-related */ apr_status_t aprrc; char errbuf[512]; apr_pool_t *jk_globalPool = NULL; /* URI registration */ char *hosts[2] = {"*", NULL}; jk_map_t *vhosts; int i, j, k, l, cnt1, cnt2; jk_map_t *uriMap, *webapps, *uriMaps[3]; jk_uriEnv_t *uriEnv, *hostEnv, *appEnv; if (jkInitCount++ == 0) { /* Get Tomcat installation root - this value is same for all virtual servers*/ if (serverRoot == NULL) { confPath = Ns_ConfigGetPath (NULL, module, NULL); serverRoot = (confPath? Ns_ConfigGetValue (confPath, "serverRoot") : NULL); } /* not configured in nsd.tcl? try env. variable */ if (serverRoot == NULL) { serverRoot = getenv ("TOMCAT_HOME"); } /* not in env. variables? get it from CWD */ if (serverRoot == NULL) { serverRoot = getcwd (cwdBuf, sizeof(cwdBuf)); } /* Initialize APR */ if ((aprrc=apr_initialize()) != APR_SUCCESS) { LOG_ERROR2 ("Cannot initialize APR", apr_strerror (aprrc, errbuf, sizeof(errbuf))); return NS_ERROR; } if ((aprrc=apr_pool_create(&jk_globalPool, NULL)) != APR_SUCCESS) { LOG_ERROR2 ("Cannot create global APR pool", apr_strerror (aprrc, errbuf, sizeof(errbuf))); return NS_ERROR; } /* Initialize JNI */ if (workerEnv==NULL && jk2_create_workerEnv(jk_globalPool, serverRoot)==JK_ERR) { return NS_ERROR; } env=workerEnv->globalEnv; env->setAprPool(env, jk_globalPool); /* Initialize JK2 */ if (workerEnv->init(env, workerEnv ) != JK_OK) { LOG_ERROR("Cannot initialize worker environment"); return NS_ERROR; } workerEnv->server_name = apr_pstrcat (jk_globalPool, Ns_InfoServerName(), " ", Ns_InfoServerVersion (), NULL); apr_pool_cleanup_register(jk_globalPool, NULL, jk2_shutdown, apr_pool_cleanup_null); workerEnv->was_initialized = JK_TRUE; if ((aprrc=apr_pool_userdata_set( "INITOK", "Ns_ModuleInit", NULL, jk_globalPool )) != APR_SUCCESS) { LOG_ERROR2 ("Cannot set APR pool user data", apr_strerror (aprrc, errbuf, sizeof(errbuf))); return NS_ERROR; } if (workerEnv->parentInit( env, workerEnv) != JK_OK) { LOG_ERROR ("Cannot initialize global environment"); return NS_ERROR; } /* Obtain TLS slot - it's destructor will detach threads from JVM */ jvmGlobal = workerEnv->vm->jvm; Ns_TlsAlloc (&jkTls, jkTlsDtor); Ns_Log (Notice, "nsjk2: Initialized JK2 environment"); } else { env = workerEnv->globalEnv; } Ns_RegisterShutdown (jk2_shutdown_system, NULL); /* Register URI patterns from workers2.properties with AOLserver * * Worker environment has a list of vhosts, including "*" vhost. * Each vhost has a list of web applications (contexts) associated with it. * Each webapp has a list of exact, prefix, suffix and regexp URI patterns. * * Will register URIs that are either in vhost "*", or one with name matching * this AOLserver virtual server. Will ignore regexp patterns. Will register * exact webapp URIs (context root) as JK2 somehow doesn't include them in URI * maps, even if specified in workers2.properties. * */ /* virtual server name override if specified */ confPath = Ns_ConfigGetPath (server, module, NULL); if (confPath != NULL) serverName = Ns_ConfigGetValue (confPath, "serverName"); if (serverName == NULL) serverName = server; vhosts=workerEnv->uriMap->vhosts; hosts[1]= serverName; for (i=0; i<sizeof(hosts)/sizeof(*hosts); i++) { hostEnv=vhosts->get (env, vhosts, hosts[i]); if (hostEnv==NULL || hostEnv->webapps==NULL) continue; webapps=hostEnv->webapps; cnt1=webapps->size(env, webapps); for (j=0; j<cnt1; j++) { appEnv = webapps->valueAt (env, webapps, j); if (appEnv == NULL) continue; /* register webapp root - registerURI checks if it is "/" */ registerURI (env, appEnv, server, serverName); uriMaps[0] = appEnv->exactMatch; uriMaps[1] = appEnv->prefixMatch; uriMaps[2] = appEnv->suffixMatch; for (k=0; k<sizeof(uriMaps)/sizeof(*uriMaps); k++) { if (uriMaps[k] == NULL) continue; cnt2 = uriMaps[k]->size (env, uriMaps[k]); for (l=0; l<cnt2; l++) { registerURI (env, uriMaps[k]->valueAt (env, uriMaps[k], l), server, serverName); } } } } Ns_Log (Notice, "nsjk2: Initialized on %s", server); return NS_OK; }
int NsPerl2_ModInit(char *server, char *module) { extern perl_master_context *nsperl2_master_context; int perl_exitstatus; Ns_Log(Notice,"nsperl2: loading"); if (!(nsperl2_master_context = ns_malloc (sizeof(perl_master_context)))) return TCL_ERROR; /* determine initial perl script */ nsperl2_master_context->param_path = Ns_ConfigGetPath(server, module, NULL); nsperl2_master_context->init_script = Ns_ConfigGetValue(nsperl2_master_context->param_path, "init_script"); nsperl2_master_context->init_sub = Ns_ConfigGetValue(nsperl2_master_context->param_path, "init_sub"); nsperl2_master_context->server = Ns_ConfigGetValue(nsperl2_master_context->param_path, "server"); /* TODO: what to do if multiple servers? probably need a master context per server */ Ns_Log (Notice, "nsperl2: init_script is %s", nsperl2_master_context->init_script); char *embedding[] = { "", nsperl2_master_context->init_script }; PerlInterpreter *perl_interp; int perl_argc = 0; char **perl_argv = NULL; PERL_SYS_INIT3( &perl_argc, &perl_argv, environ_h ); /* create perl interpreter */ if((perl_interp = perl_alloc()) == NULL) { Ns_Log (Error, "Couldn't alloc perl interp"); return TCL_ERROR; } perl_construct(perl_interp); PL_exit_flags |= PERL_EXIT_DESTRUCT_END; /* run END blocks at destruction */ PERL_SET_CONTEXT (perl_interp); perl_exitstatus = perl_parse(perl_interp, xs_init, 2, embedding, NULL); /* TODO: check perl_exitstatus */ nsperl2_master_context->perl_master_interp = perl_interp; /* call the init_sub - eg. where urls are registered etc. you could do the same in a BEGIN block, but this is cleaner */ dSP; PUSHMARK (SP); Tcl_Interp *tcl_interp; tcl_interp = Ns_TclAllocateInterp (server); set_nsperl2_globals (perl_interp, tcl_interp, NULL); call_pv (nsperl2_master_context->init_sub, G_NOARGS | G_VOID | G_DISCARD); /* not doing G_EVAL - if init_sub fails, we want to bail. */ /* should I destroy that tcl interp?? */ Ns_RegisterShutdown (nsperl2_free_master_context, NULL); Ns_TclInitInterps(server,NsPerl2InitInterp, NULL); return NS_OK; }