/* Loadable module initialization */ PUBLIC int maCgiHandlerInit(Http *http, MprModule *module) { HttpStage *handler, *connector; if ((handler = httpCreateHandler("cgiHandler", module)) == 0) { return MPR_ERR_CANT_CREATE; } http->cgiHandler = handler; handler->close = closeCgi; handler->outgoingService = cgiToBrowserService; handler->incoming = browserToCgiData; handler->open = openCgi; handler->start = startCgi; if ((connector = httpCreateConnector("cgiConnector", module)) == 0) { return MPR_ERR_CANT_CREATE; } http->cgiConnector = connector; connector->outgoingService = browserToCgiService; connector->incoming = cgiToBrowserData; /* Add configuration file directives */ maAddDirective("Action", actionDirective); maAddDirective("ScriptAlias", scriptAliasDirective); maAddDirective("CgiEscape", cgiEscapeDirective); maAddDirective("CgiPrefix", cgiPrefixDirective); return 0; }
/* Loadable module initialization */ PUBLIC int maOpenDirHandler(Http *http) { HttpStage *handler; MaAppweb *appweb; Dir *dir; if ((handler = httpCreateHandler(http, "dirHandler", NULL)) == 0) { return MPR_ERR_CANT_CREATE; } if ((handler->stageData = dir = mprAllocObj(Dir, manageDir)) == 0) { return MPR_ERR_MEMORY; } handler->start = startDir; http->dirHandler = handler; dir->sortOrder = 1; /* Declare configuration file directives */ appweb = httpGetContext(http); maAddDirective(appweb, "IndexOrder", indexOrderDirective); maAddDirective(appweb, "indexOptions", indexOptionsDirective); maAddDirective(appweb, "Options", optionsDirective); return 0; }
int httpOpenCacheHandler(Http *http) { HttpStage *handler, *filter; /* Create the cache handler to serve cached content */ if ((handler = httpCreateHandler(http, "cacheHandler", HTTP_STAGE_ALL, NULL)) == 0) { return MPR_ERR_CANT_CREATE; } http->cacheHandler = handler; handler->match = matchCacheHandler; handler->ready = readyCacheHandler; /* Create the cache filter to capture and cache response content */ if ((filter = httpCreateFilter(http, "cacheFilter", HTTP_STAGE_ALL, NULL)) == 0) { return MPR_ERR_CANT_CREATE; } http->cacheFilter = filter; filter->match = matchCacheFilter; filter->outgoingService = outgoingCacheFilterService; return 0; }
/* Module load initialization. This is called when the module is first loaded. The module name is "Simple". */ int maSimpleHandlerInit(Http *http, MprModule *module) { HttpStage *stage; if ((stage = httpCreateHandler(http, "simpleHandler", 0, module)) == 0) { return MPR_ERR_CANT_CREATE; } stage->process = processSimple; stage->incomingData = incomingSimpleData; return 0; }
PUBLIC int httpOpenPassHandler() { HttpStage *stage; if ((stage = httpCreateHandler("passHandler", NULL)) == 0) { return MPR_ERR_CANT_CREATE; } HTTP->passHandler = stage; stage->start = startPass; stage->ready = readyPass; /* PassHandler is an alias as the ErrorHandler too */ if ((stage = httpCreateHandler("errorHandler", NULL)) == 0) { return MPR_ERR_CANT_CREATE; } stage->start = startPass; stage->ready = readyError; return 0; }
int httpOpenPassHandler(Http *http) { HttpStage *stage; if ((stage = httpCreateHandler(http, "passHandler", HTTP_STAGE_ALL, NULL)) == 0) { return MPR_ERR_CANT_CREATE; } http->passHandler = stage; stage->start = startPass; stage->ready = readyPass; /* PassHandler is an alias as the ErrorHandler too */ if ((stage = httpCreateHandler(http, "errorHandler", HTTP_STAGE_ALL, NULL)) == 0) { return MPR_ERR_CANT_CREATE; } stage->start = startPass; stage->ready = readyError; return 0; }
PUBLIC int httpOpenActionHandler() { HttpStage *stage; if ((stage = httpCreateHandler("actionHandler", NULL)) == 0) { return MPR_ERR_CANT_CREATE; } HTTP->actionHandler = stage; if ((stage->stageData = mprCreateHash(0, MPR_HASH_STATIC_VALUES)) == 0) { return MPR_ERR_MEMORY; } stage->start = startAction; return 0; }
/* Loadable module initialization */ PUBLIC int httpOpenDirHandler() { HttpStage *handler; HttpDir *dir; if ((handler = httpCreateHandler("dirHandler", NULL)) == 0) { return MPR_ERR_CANT_CREATE; } if ((handler->stageData = dir = mprAllocObj(HttpDir, manageDir)) == 0) { return MPR_ERR_MEMORY; } handler->flags |= HTTP_STAGE_INTERNAL; handler->start = startDir; HTTP->dirHandler = handler; dir->sortOrder = 1; return 0; }
PUBLIC int maProxyHandlerInit(Http *http, MprModule *module) { HttpStage *handler; MaAppweb *appweb; if ((handler = httpCreateHandler(http, module->name, 0, module)) == 0) { return MPR_ERR_CANT_CREATE; } handler->open = openProxy; handler->close = closeProxy; handler->incomingData = incomingProxyData; handler->outgoingService = outgoingProxyService; handler->start = startProxy; handler->ready = readyProxy; handler->process = processProxy; appweb = httpGetContext(http); maAddDirective(appweb, "Proxy", proxyDirective); return 0; }
/* Loadable module initialization */ PUBLIC int httpOpenFileHandler() { HttpStage *handler; /* This handler serves requests without using thread workers. */ if ((handler = httpCreateHandler("fileHandler", NULL)) == 0) { return MPR_ERR_CANT_CREATE; } handler->rewrite = rewriteFileHandler; handler->open = openFileHandler; handler->close = closeFileHandler; handler->start = startFileHandler; handler->ready = readyFileHandler; handler->outgoingService = outgoingFileService; handler->incoming = incomingFile; HTTP->fileHandler = handler; return 0; }
/* Load and initialize ESP module. Manually loaded when used inside esp.c. */ PUBLIC int espOpen(MprModule *module) { HttpStage *handler; if ((handler = httpCreateHandler("espHandler", module)) == 0) { return MPR_ERR_CANT_CREATE; } HTTP->espHandler = handler; handler->open = openEsp; handler->close = closeEsp; handler->start = startEsp; /* Using the standard 'incoming' callback that simply transfers input to the queue head Applications should read by defining a notifier for READABLE events and then calling httpGetPacket on the read queue. */ if ((esp = mprAllocObj(Esp, manageEsp)) == 0) { return MPR_ERR_MEMORY; } MPR->espService = esp; handler->stageData = esp; esp->mutex = mprCreateLock(); esp->local = mprCreateThreadLocal(); if (espInitParser() < 0) { return 0; } if ((esp->ediService = ediCreateService()) == 0) { return 0; } #if ME_COM_MDB mdbInit(); #endif #if ME_COM_SQLITE sdbInit(); #endif if (module) { mprSetModuleFinalizer(module, unloadEsp); } return 0; }
/* Dynamic module initialization */ int maOpenDirHandler(Http *http) { HttpStage *handler; MaAppweb *appweb; Dir *dir; if ((handler = httpCreateHandler(http, "dirHandler", HTTP_STAGE_GET | HTTP_STAGE_HEAD, NULL)) == 0) { return MPR_ERR_CANT_CREATE; } if ((handler->stageData = dir = mprAllocObj(Dir, manageDir)) == 0) { return MPR_ERR_MEMORY; } handler->match = maMatchDir; handler->process = processDir; http->dirHandler = handler; dir->sortOrder = 1; appweb = httpGetContext(http); maAddDirective(appweb, "IndexOrder", indexOrderDirective); maAddDirective(appweb, "indexOptions", indexOptionsDirective); maAddDirective(appweb, "Options", optionsDirective); return 0; }
PUBLIC Http *httpCreate(int flags) { Http *http; HttpStatusCode *code; mprGlobalLock(); if (MPR->httpService) { mprGlobalUnlock(); return MPR->httpService; } if ((http = mprAllocObj(Http, manageHttp)) == 0) { mprGlobalUnlock(); return 0; } MPR->httpService = HTTP = http; http->software = sclone(ME_HTTP_SOFTWARE); http->protocol = sclone("HTTP/1.1"); http->mutex = mprCreateLock(); http->stages = mprCreateHash(-1, MPR_HASH_STABLE); http->hosts = mprCreateList(-1, MPR_LIST_STABLE); http->connections = mprCreateList(-1, MPR_LIST_STATIC_VALUES); http->authTypes = mprCreateHash(-1, MPR_HASH_CASELESS | MPR_HASH_UNIQUE | MPR_HASH_STABLE); http->authStores = mprCreateHash(-1, MPR_HASH_CASELESS | MPR_HASH_UNIQUE | MPR_HASH_STABLE); http->routeSets = mprCreateHash(-1, MPR_HASH_STATIC_VALUES | MPR_HASH_STABLE); http->booted = mprGetTime(); http->flags = flags; http->monitorPeriod = ME_HTTP_MONITOR_PERIOD; http->secret = mprGetRandomString(HTTP_MAX_SECRET); http->trace = httpCreateTrace(0); http->startLevel = 2; http->localPlatform = slower(sfmt("%s-%s-%s", ME_OS, ME_CPU, ME_PROFILE)); httpSetPlatform(http->localPlatform); httpSetPlatformDir(NULL); updateCurrentDate(); http->statusCodes = mprCreateHash(41, MPR_HASH_STATIC_VALUES | MPR_HASH_STATIC_KEYS | MPR_HASH_STABLE); for (code = HttpStatusCodes; code->code; code++) { mprAddKey(http->statusCodes, code->codeString, code); } httpGetUserGroup(); httpInitParser(); httpInitAuth(); httpOpenNetConnector(); httpOpenSendConnector(); httpOpenRangeFilter(); httpOpenChunkFilter(); #if ME_HTTP_WEB_SOCKETS httpOpenWebSockFilter(); #endif mprSetIdleCallback(isIdle); mprAddTerminator(terminateHttp); if (flags & HTTP_SERVER_SIDE) { http->endpoints = mprCreateList(-1, MPR_LIST_STABLE); http->counters = mprCreateList(-1, MPR_LIST_STABLE); http->monitors = mprCreateList(-1, MPR_LIST_STABLE); http->routeTargets = mprCreateHash(-1, MPR_HASH_STATIC_VALUES | MPR_HASH_STABLE); http->routeConditions = mprCreateHash(-1, MPR_HASH_STATIC_VALUES | MPR_HASH_STABLE); http->routeUpdates = mprCreateHash(-1, MPR_HASH_STATIC_VALUES | MPR_HASH_STABLE); http->sessionCache = mprCreateCache(MPR_CACHE_SHARED | MPR_HASH_STABLE); http->addresses = mprCreateHash(-1, MPR_HASH_STABLE); http->defenses = mprCreateHash(-1, MPR_HASH_STABLE); http->remedies = mprCreateHash(-1, MPR_HASH_CASELESS | MPR_HASH_STATIC_VALUES | MPR_HASH_STABLE); httpOpenUploadFilter(); httpOpenCacheHandler(); httpOpenPassHandler(); httpOpenActionHandler(); httpOpenDirHandler(); httpOpenFileHandler(); http->serverLimits = httpCreateLimits(1); httpDefineRouteBuiltins(); httpAddCounters(); httpAddRemedies(); httpCreateDefaultHost(); } if (flags & HTTP_CLIENT_SIDE) { http->defaultClientHost = sclone("127.0.0.1"); http->defaultClientPort = 80; http->clientLimits = httpCreateLimits(0); http->clientRoute = httpCreateConfiguredRoute(0, 0); http->clientHandler = httpCreateHandler("client", 0); } mprGlobalUnlock(); return http; }