static void loadStaticModules() { #if ME_STATIC /* If doing a static build, must now reference required modules to force the linker to include them. On linux we cannot lookup symbols with dlsym(), so we must invoke explicitly here. Add your modules here if you are doing a static link. */ Http *http = MPR->httpService; #if ME_COM_CGI maCgiHandlerInit(http, mprCreateModule("cgiHandler", 0, 0, http)); #endif #if ME_COM_ESP maEspHandlerInit(http, mprCreateModule("espHandler", 0, 0, http)); #endif #if ME_COM_EJS maEspHandlerInit(http, mprCreateModule("ejsHandler", 0, 0, http)); #endif #if ME_COM_PHP maPhpHandlerInit(http, mprCreateModule("phpHandler", 0, 0, http)); #endif #if ME_COM_SSL maSslModuleInit(http, mprCreateModule("sslModule", 0, 0, http)); #endif #endif /* ME_STATIC */ }
/* * Load the ssl provider */ static MprModule *loadSsl(MprCtx ctx, bool lazy) { Mpr *mpr; MprModule *mp; mpr = mprGetMpr(ctx); if (mpr->flags & MPR_SSL_PROVIDER_LOADED) { return mprLookupModule(ctx, "sslModule"); } mprLog(ctx, MPR_CONFIG, "Activating the SSL provider"); #if BLD_FEATURE_OPENSSL /* * NOTE: preference given to open ssl if both are enabled */ mprLog(ctx, 2, "Loading OpenSSL module"); if (mprCreateOpenSslModule(ctx, lazy) < 0) { return 0; } #elif BLD_FEATURE_MATRIXSSL mprLog(ctx, 2, "Loading MatrixSSL module"); if (mprCreateMatrixSslModule(ctx, lazy) < 0) { return 0; } #endif if ((mp = mprCreateModule(ctx, "sslModule", BLD_VERSION, NULL, NULL, NULL)) == 0) { return 0; } mpr->flags |= MPR_SSL_PROVIDER_LOADED; return mp; }
/* Load a module. Returns 0 if the modules is successfully loaded (may have already been loaded). */ int maLoadModule(MaAppweb *appweb, cchar *name, cchar *libname) { MprModule *module; char entryPoint[MPR_MAX_FNAME]; char *path; if (strcmp(name, "authFilter") == 0 || strcmp(name, "rangeFilter") == 0 || strcmp(name, "uploadFilter") == 0 || strcmp(name, "fileHandler") == 0 || strcmp(name, "dirHandler") == 0) { mprLog(1, "The %s module is now builtin. No need to use LoadModule", name); return 0; } if (libname == 0) { path = sjoin("mod_", name, BLD_SHOBJ, NULL); } else { path = sclone(libname); } if ((module = mprLookupModule(path)) != 0) { mprLog(MPR_CONFIG, "Activating module (Builtin) %s", name); return 0; } mprSprintf(entryPoint, sizeof(entryPoint), "ma%sInit", name); entryPoint[2] = toupper((int) entryPoint[2]); if ((module = mprCreateModule(name, path, entryPoint, MPR->httpService)) == 0) { return 0; } if (mprLoadModule(module) < 0) { return MPR_ERR_CANT_CREATE; } return 0; }
static int openQueue(HttpQueue *q, ssize chunkSize) { Http *http; HttpConn *conn; HttpStage *stage; MprModule *module; stage = q->stage; conn = q->conn; http = q->conn->http; if (chunkSize > 0) { q->packetSize = min(q->packetSize, chunkSize); } if (stage->flags & HTTP_STAGE_UNLOADED && stage->module) { module = stage->module; module = mprCreateModule(module->name, module->path, module->entry, http); if (mprLoadModule(module) < 0) { httpError(conn, HTTP_CODE_INTERNAL_SERVER_ERROR, "Cannot load module %s", module->name); return MPR_ERR_CANT_READ; } stage->module = module; } if (stage->module) { stage->module->lastActivity = http->now; } return 0; }
/* * Dynamic module initialization */ MprModule *maEgiHandlerInit(MaHttp *http, cchar *path) { MprModule *module; MaStage *handler; MaEgi *egi; module = mprCreateModule(http, "egiHandler", BLD_VERSION, NULL, NULL, NULL); if (module == 0) { return 0; } handler = maCreateHandler(http, "egiHandler", MA_STAGE_GET | MA_STAGE_HEAD | MA_STAGE_POST | MA_STAGE_PUT | MA_STAGE_FORM_VARS | MA_STAGE_ENV_VARS | \ MA_STAGE_VIRTUAL); if (handler == 0) { mprFree(module); return 0; } http->egiHandler = handler; handler->run = runEgi; handler->stageData = egi = mprAllocObjZeroed(handler, MaEgi); egi->forms = mprCreateHash(egi, MA_EGI_HASH_SIZE); #if EGI_TEST egiTestInit(http, path); #endif return module; }
/* Start the command to run (stdIn and stdOut are named from the client's perspective) */ PUBLIC int startProcess(MprCmd *cmd) { MprCmdTaskFn entryFn; MprModule *mp; char *entryPoint, *program, *pair; int pri, next; mprLog("info mpr cmd", 4, "Program %s", cmd->program); entryPoint = 0; if (cmd->env) { for (ITERATE_ITEMS(cmd->env, pair, next)) { if (sncmp(pair, "entryPoint=", 11) == 0) { entryPoint = sclone(&pair[11]); } } } program = mprGetPathBase(cmd->program); if (entryPoint == 0) { program = mprTrimPathExt(program); entryPoint = program; } #if ME_CPU_ARCH == MPR_CPU_IX86 || ME_CPU_ARCH == MPR_CPU_IX64 || ME_CPU_ARCH == MPR_CPU_SH /* A leading underscore is required on some architectures */ entryPoint = sjoin("_", entryPoint, NULL); #endif if (mprFindVxSym(sysSymTbl, entryPoint, (char**) (void*) &entryFn) < 0) { if ((mp = mprCreateModule(cmd->program, cmd->program, NULL, NULL)) == 0) { mprLog("error mpr cmd", 0, "Cannot create module"); return MPR_ERR_CANT_CREATE; } if (mprLoadModule(mp) < 0) { mprLog("error mpr cmd", 0, "Cannot load DLL %s, errno %d", program, mprGetOsError()); return MPR_ERR_CANT_READ; } if (mprFindVxSym(sysSymTbl, entryPoint, (char**) (void*) &entryFn) < 0) { mprLog("error mpr cmd", 0, "Cannot find symbol %s, errno %d", entryPoint, mprGetOsError()); return MPR_ERR_CANT_ACCESS; } } taskPriorityGet(taskIdSelf(), &pri); cmd->pid = taskSpawn(entryPoint, pri, VX_FP_TASK | VX_PRIVATE_ENV, ME_STACK_SIZE, (FUNCPTR) cmdTaskEntry, (int) cmd->program, (int) entryFn, (int) cmd, 0, 0, 0, 0, 0, 0, 0); if (cmd->pid < 0) { mprLog("error mpr cmd", 0, "Cannot create task %s, errno %d", entryPoint, mprGetOsError()); return MPR_ERR_CANT_CREATE; } if (semTake(cmd->startCond, MPR_TIMEOUT_START_TASK) != OK) { mprLog("error mpr cmd", 0, "Child %s did not initialize, errno %d", cmd->program, mprGetOsError()); return MPR_ERR_CANT_CREATE; } semDelete(cmd->startCond); cmd->startCond = 0; return 0; }
/* * Dynamic module initialization */ MprModule *maEjsHandlerInit(MaHttp *http, cchar *path) { MprModule *module; MaStage *handler; EjsWebControl *control; module = mprCreateModule(http, "ejsHandler", BLD_VERSION, 0, 0, 0); if (module == 0) { return 0; } handler = maCreateHandler(http, "ejsHandler", MA_STAGE_GET | MA_STAGE_HEAD | MA_STAGE_POST | MA_STAGE_PUT | MA_STAGE_FORM_VARS | MA_STAGE_VIRTUAL); if (handler == 0) { mprFree(module); return 0; } http->ejsHandler = handler; handler->match = matchEjs; handler->run = runEjs; handler->parse = parseEjs; /* * Setup the control block */ handler->stageData = control = mprAllocObjZeroed(handler, EjsWebControl); control->defineParams = defineParams; control->discardOutput = discardOutput; control->error = error; control->getHeader = getHeader; control->getVar = getVar; control->redirect = redirect; control->setCookie = setCookie; control->setHeader = setHeader; control->setHttpCode = setHttpCode; control->setMimeType = setMimeType; control->write = writeBlock; control->modulePath = mprStrdup(control, path); #if BLD_FEATURE_MULTITHREAD && FUTURE /* * This mutex is used very sparingly and must be an application global lock. */ mutex = mprCreateLock(control); control->lock = ejsWebLock; control->unlock = ejsWebUnlock; control->lockData = mutex; #endif if (ejsOpenWebFramework(control, 1) < 0) { return 0; } return module; }
/* * Loadable module interface */ MprModule *ejs_dbModuleInit(Ejs *ejs) { MprModule *module; module = mprCreateModule(ejs, "db", BLD_VERSION, 0, 0, 0); if (module == 0) { return 0; } ejsSetGeneration(ejs, EJS_GEN_ETERNAL); ejsConfigureDbTypes(ejs); ejsSetGeneration(ejs, EJS_GEN_OLD); return module; }
MprModule *acmeModuleInit(Ejs *ejs) { MprModule *module; EjsType *type; EjsName qname; mprBreakpoint(); mprLog(ejs, 1, "Loading Acme module"); if ((module = mprCreateModule(ejs, "acme", BLD_VERSION, 0, 0, 0)) == 0) { return 0; } type = (EjsType*) ejsGetPropertyByName(ejs, ejs->global, ejsName(&qname, "Acme", "Rocket")); if (type == 0) { mprError(ejs, "Can't find type %s", qname.name); return 0; } ejsBindMethod(ejs, type, ES_Acme_Rocket_countdown, (EjsNativeFunction) countdown); return module; }
/* * Loadable module initialization */ MprModule *maAuthFilterInit(MaHttp *http, cchar *path) { MprModule *module; MaStage *filter; module = mprCreateModule(http, "authFilter", BLD_VERSION, NULL, NULL, NULL); if (module == 0) { return 0; } filter = maCreateFilter(http, "authFilter", MA_STAGE_ALL); if (filter == 0) { mprFree(module); return 0; } http->authFilter = filter; filter->match = matchAuth; filter->parse = parseAuth; return module; }
/* * Module load initialization. This is called when the module is first loaded. The module name is "Simple". */ MprModule *maSimpleModuleInit(MaHttp *http) { MprModule *module; MaStage *stage; module = mprCreateModule(http, "simpleModule", BLD_VERSION, NULL, NULL, NULL); if (module == 0) { return 0; } /* * Create a stage so we can process configuration file data */ if ((stage = maCreateStage(http, "simpleModule", MA_STAGE_MODULE)) == 0) { mprFree(module); return 0; } stage->parse = parseSimple; return module; }
/* * Loadable module initialization */ MprModule *maChunkFilterInit(MaHttp *http, cchar *path) { MprModule *module; MaStage *filter; module = mprCreateModule(http, "chunkFilter", BLD_VERSION, NULL, NULL, NULL); if (module == 0) { return 0; } filter = maCreateFilter(http, "chunkFilter", MA_STAGE_ALL); if (filter == 0) { mprFree(module); return 0; } http->chunkFilter = filter; filter->open = openChunk; filter->match = matchChunk; filter->outgoingService = outgoingChunkService; filter->incomingData = incomingChunkData; return module; }
/* Dynamic module initialization */ MprModule *maCgiHandlerInit(MaHttp *http, cchar *path) { MprModule *module; MaStage *handler; if ((module = mprCreateModule(http, "cgiHandler", BLD_VERSION, NULL, NULL, NULL)) == NULL) { return 0; } handler = maCreateHandler(http, "cgiHandler", MA_STAGE_ALL | MA_STAGE_VARS | MA_STAGE_ENV_VARS | MA_STAGE_PATH_INFO | MA_STAGE_MISSING_EXT); if (handler == 0) { mprFree(module); return 0; } http->cgiHandler = handler; handler->close = closeCgi; handler->start = startCgi; handler->incomingData = incomingCgiData; handler->run = runCgi; handler->parse = parseCgi; return module; }
/* * Dynamic module initialization */ MprModule *maDirHandlerInit(MaHttp *http, cchar *path) { MprModule *module; MaStage *handler; Dir *dir; module = mprCreateModule(http, "dirHandler", BLD_VERSION, NULL, NULL, NULL); if (module == 0) { return 0; } handler = maCreateHandler(http, "dirHandler", MA_STAGE_GET | MA_STAGE_HEAD); if (handler == 0) { mprFree(module); return 0; } handler->match = matchDir; handler->run = runDir; handler->parse = parseDir; handler->stageData = dir = mprAllocObjZeroed(handler, Dir); dir->sortOrder = 1; http->dirHandler = handler; return module; }
/* WARNING: GC yield */ PUBLIC int espLoadModule(HttpRoute *route, MprDispatcher *dispatcher, cchar *kind, cchar *source, cchar **errMsg) { EspRoute *eroute; MprModule *mp; cchar *appName, *cache, *cacheName, *canonical, *entry, *module; int isView, recompile; eroute = route->eroute; *errMsg = ""; #if VXWORKS /* Trim the drive for VxWorks where simulated host drives only exist on the target */ source = mprTrimPathDrive(source); #endif canonical = mprGetPortablePath(mprGetRelPath(source, route->home)); appName = eroute->appName; if (eroute->combine) { cacheName = appName; } else { cacheName = mprGetMD5WithPrefix(sfmt("%s:%s", appName, canonical), -1, sjoin(kind, "_", NULL)); } if ((cache = httpGetDir(route, "CACHE")) == 0) { cache = "cache"; } module = mprJoinPathExt(mprJoinPaths(route->home, cache, cacheName, NULL), ME_SHOBJ); lock(esp); if (route->update) { if (mprPathExists(source, R_OK)) { isView = smatch(kind, "view"); if (espModuleIsStale(source, module, &recompile) || (isView && layoutIsStale(eroute, source, module))) { if (recompile) { mprHoldBlocks(source, module, cacheName, NULL); if (!espCompile(route, dispatcher, source, module, cacheName, isView, (char**) errMsg)) { mprReleaseBlocks(source, module, cacheName, NULL); unlock(esp); return MPR_ERR_CANT_WRITE; } mprReleaseBlocks(source, module, cacheName, NULL); } } } } if (mprLookupModule(source) == 0) { if (!mprPathExists(module, R_OK)) { *errMsg = "Module does not exist"; unlock(esp); return MPR_ERR_CANT_FIND; } entry = getModuleEntry(eroute, kind, source, cacheName); if ((mp = mprCreateModule(source, module, entry, route)) == 0) { *errMsg = "Memory allocation error loading module"; unlock(esp); return MPR_ERR_MEMORY; } if (mprLoadModule(mp) < 0) { *errMsg = "Cannot load compiled esp module"; unlock(esp); return MPR_ERR_CANT_READ; } } unlock(esp); return 0; }