/* * Create a host from scratch */ MaHost *maCreateHost(MaServer *server, cchar *ipAddrPort, MaLocation *location) { MaHost *host; host = mprAllocObjZeroed(server, MaHost); if (host == 0) { return 0; } host->aliases = mprCreateList(host); host->dirs = mprCreateList(host); host->connections = mprCreateList(host); host->locations = mprCreateList(host); if (ipAddrPort) { host->ipAddrPort = mprStrdup(server, ipAddrPort); host->name = mprStrdup(server, ipAddrPort); } else { host->ipAddrPort = 0; host->name = 0; } host->server = server; host->flags = MA_HOST_NO_TRACE; host->httpVersion = MPR_HTTP_1_1; host->timeout = MA_SERVER_TIMEOUT; host->limits = &server->http->limits; host->traceMask = MA_TRACE_REQUEST | MA_TRACE_RESPONSE | MA_TRACE_HEADERS; host->traceLevel = 3; host->traceMaxLength = INT_MAX; host->keepAliveTimeout = MA_KEEP_TIMEOUT; host->maxKeepAlive = MA_MAX_KEEP_ALIVE; host->keepAlive = 1; host->location = (location) ? location : maCreateBareLocation(host); maAddLocation(host, host->location); updateCurrentDate(host); #if BLD_FEATURE_AUTH host->location->auth = maCreateAuth(host->location, host->location->auth); #endif #if BLD_FEATURE_MULTITHREAD host->mutex = mprCreateLock(host); #endif mprSetIdleCallback(host, appwebIsIdle); return host; }
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; }