EcLexer *ecCreateLexer(EcCompiler *cp) { EcLexer *lp; ReservedWord *rp; int size; lp = mprAllocObjWithDestructorZeroed(cp, EcLexer, destroyLexer); if (lp == 0) { return 0; } lp->input = mprAllocObjZeroed(lp, EcInput); if (lp->input == 0) { mprFree(lp); return 0; } lp->input->lexer = lp; lp->input->compiler = cp; lp->compiler = cp; size = sizeof(keywords) / sizeof(ReservedWord); lp->keywords = mprCreateHash(lp, size); if (lp->keywords == 0) { mprFree(lp); return 0; } for (rp = keywords; rp->name; rp++) { mprAddHash(lp->keywords, rp->name, rp); } return lp; }
MaRequest *maCreateRequest(MaConn *conn) { MaRequest *req; MprHeap *arena; arena = mprAllocHeap(conn->arena, "request", MA_REQ_MEM, 0, NULL); if (arena == 0) { return 0; } req = mprAllocObjWithDestructorZeroed(arena, MaRequest, destroyRequest); if (req == 0) { return 0; } req->conn = conn; req->arena = arena; req->length = -1; req->ifMatch = 1; req->ifModified = 1; req->host = conn->host; req->remainingContent = 0; req->method = 0; req->headers = mprCreateHash(req, MA_VAR_HASH_SIZE); req->formVars = mprCreateHash(req, MA_VAR_HASH_SIZE); req->httpProtocol = "HTTP/1.1"; return req; }
/* * Create a new connection object. */ static MaConn *createConn(MprCtx ctx, MaHost *host, MprSocket *sock, cchar *ipAddr, int port, MaHostAddress *address) { MaConn *conn; conn = mprAllocObjWithDestructorZeroed(ctx, MaConn, connectionDestructor); if (conn == 0) { return 0; } if (host->keepAlive) { conn->keepAliveCount = host->maxKeepAlive; } conn->http = host->server->http; conn->sock = sock; mprStealBlock(conn, sock); conn->state = MPR_HTTP_STATE_BEGIN; conn->timeout = host->timeout; conn->remotePort = port; conn->remoteIpAddr = mprStrdup(conn, ipAddr); conn->address = address; conn->host = host; conn->originalHost = host; conn->expire = mprGetTime(conn) + host->timeout; conn->eventMask = -1; maInitSchedulerQueue(&conn->serviceq); #if BLD_FEATURE_MULTITHREAD conn->mutex = mprCreateLock(conn); #endif return conn; }
MprCmd *mprCreateCmd(MprCtx ctx) { MprCmdService *cs; MprCmd *cmd; MprCmdFile *files; int i; cmd = mprAllocObjWithDestructorZeroed(ctx, MprCmd, cmdDestructor); if (cmd == 0) { return 0; } cmd->completeCond = mprCreateCond(cmd); cmd->timeoutPeriod = MPR_TIMEOUT_CMD; cmd->timestamp = mprGetTime(cmd); cmd->forkCallback = (MprForkCallback) closeFiles; #if VXWORKS cmd->startCond = semCCreate(SEM_Q_PRIORITY, SEM_EMPTY); cmd->exitCond = semCCreate(SEM_Q_PRIORITY, SEM_EMPTY); #endif files = cmd->files; for (i = 0; i < MPR_CMD_MAX_PIPE; i++) { files[i].clientFd = -1; files[i].fd = -1; } #if BLD_FEATURE_MULTITHREAD cmd->mutex = mprCreateLock(cmd); #endif cs = mprGetMpr(ctx)->cmdService; mprLock(cs->mutex); mprAddItem(cs->cmds, cmd); mprUnlock(cs->mutex); return cmd; }
MaHttp *maCreateHttp(MprCtx ctx) { MaHttp *http; http = mprAllocObjWithDestructorZeroed(ctx, MaHttp, httpDestructor); if (http == 0) { return 0; } mprGetMpr(ctx)->appwebHttpService = http; http->servers = mprCreateList(http); http->stages = mprCreateHash(http, 0); #if BLD_FEATURE_MULTITHREAD http->mutex = mprCreateLock(http); #endif initLimits(http); #if BLD_UNIX_LIKE { struct passwd *pp; struct group *gp; http->uid = getuid(); if ((pp = getpwuid(http->uid)) == 0) { mprError(http, "Can't read user credentials: %d. Check your /etc/passwd file.", http->uid); } else { http->username = mprStrdup(http, pp->pw_name); } http->gid = getgid(); if ((gp = getgrgid(http->gid)) == 0) { mprError(http, "Can't read group credentials: %d. Check your /etc/group file", http->gid); } else { http->groupname = mprStrdup(http, gp->gr_name); } } #else http->uid = http->gid = -1; #endif #if BLD_FEATURE_SEND maOpenSendConnector(http); #endif #if BLD_FEATURE_NET maOpenNetConnector(http); #endif maOpenPassHandler(http); return http; }
MprCmdService *mprCreateCmdService(Mpr *mpr) { MprCmdService *cs; cs = (MprCmdService*) mprAllocObjWithDestructorZeroed(mpr, MprCmd, cmdDestructor); if (cs == 0) { return 0; } cs->cmds = mprCreateList(cs); #if BLD_FEATURE_MULTITHREAD cs->mutex = mprCreateLock(cs); #endif return cs; }
/* * Create a new Ssl context object */ MprSsl *mprCreateSsl(MprCtx ctx) { MprSsl *ssl; /* * Create with a null destructor so the provider can install one if required */ ssl = mprAllocObjWithDestructorZeroed(ctx, MprSsl, NULL); if (ssl == 0) { return 0; } ssl->ciphers = mprStrdup(ssl, MPR_DEFAULT_CIPHER_SUITE); ssl->protocols = MPR_HTTP_PROTO_SSLV3 | MPR_HTTP_PROTO_TLSV1; ssl->verifyDepth = 6; return ssl; }
static MprFile *openFile(MprCtx ctx, MprFileSystem *fileSystem, cchar *path, int flags, int omode) { MprRomFileSystem *rfs; MprFile *file; mprAssert(path && *path); rfs = (MprRomFileSystem*) fileSystem; file = mprAllocObjWithDestructorZeroed(ctx, MprFile, closeFile); file->fileSystem = fileSystem; file->mode = omode; file->fd = -1; if ((file->inode = lookup(rfs, path)) == 0) { return 0; } return file; }