static void makeAltBody(HttpConn *conn, int status) { HttpRx *rx; HttpTx *tx; cchar *statusMsg, *msg; rx = conn->rx; tx = conn->tx; assert(rx && tx); statusMsg = httpLookupStatus(conn->http, status); msg = ""; if (rx && (!rx->route || rx->route->flags & HTTP_ROUTE_SHOW_ERRORS)) { msg = conn->errorMsg; } if (rx && scmp(rx->accept, "text/plain") == 0) { tx->altBody = sfmt("Access Error: %d -- %s\r\n%s\r\n", status, statusMsg, msg); } else { tx->altBody = sfmt("<!DOCTYPE html>\r\n" "<head>\r\n" " <title>%s</title>\r\n" " <link rel=\"shortcut icon\" href=\"data:image/x-icon;,\" type=\"image/x-icon\">\r\n" "</head>\r\n" "<body>\r\n<h2>Access Error: %d -- %s</h2>\r\n<pre>%s</pre>\r\n</body>\r\n</html>\r\n", statusMsg, status, statusMsg, mprEscapeHtml(msg)); } tx->length = slen(tx->altBody); }
/* Add the client 'Authorization' header for authenticated requests Must first get a 401 response to get the authData. */ PUBLIC bool httpDigestSetHeaders(HttpConn *conn, cchar *username, cchar *password) { Http *http; HttpTx *tx; DigestData *dp; char *ha1, *ha2, *digest, *cnonce; http = conn->http; tx = conn->tx; if ((dp = conn->authData) == 0) { /* Need to await a failing auth response */ return 0; } cnonce = sfmt("%s:%s:%x", http->secret, dp->realm, (int) http->now); ha1 = mprGetMD5(sfmt("%s:%s:%s", username, dp->realm, password)); ha2 = mprGetMD5(sfmt("%s:%s", tx->method, tx->parsedUri->path)); if (smatch(dp->qop, "auth")) { digest = mprGetMD5(sfmt("%s:%s:%08x:%s:%s:%s", ha1, dp->nonce, dp->nc, cnonce, dp->qop, ha2)); httpAddHeader(conn, "Authorization", "Digest username=\"%s\", realm=\"%s\", domain=\"%s\", " "algorithm=\"MD5\", qop=\"%s\", cnonce=\"%s\", nc=\"%08x\", nonce=\"%s\", opaque=\"%s\", " "stale=\"FALSE\", uri=\"%s\", response=\"%s\"", username, dp->realm, dp->domain, dp->qop, cnonce, dp->nc, dp->nonce, dp->opaque, tx->parsedUri->path, digest); } else { digest = mprGetMD5(sfmt("%s:%s:%s", ha1, dp->nonce, ha2)); httpAddHeader(conn, "Authorization", "Digest username=\"%s\", realm=\"%s\", nonce=\"%s\", " "uri=\"%s\", response=\"%s\"", username, dp->realm, dp->nonce, tx->parsedUri->path, digest); } return 1; }
static int runCommand(HttpRoute *route, MprDispatcher *dispatcher, cchar *command, cchar *csource, cchar *module, char **errMsg) { MprCmd *cmd; MprKey *var; MprList *elist; EspRoute *eroute; cchar **env, *commandLine; char *err, *out; int rc; *errMsg = 0; eroute = route->eroute; cmd = mprCreateCmd(dispatcher); if ((commandLine = espExpandCommand(route, command, csource, module)) == 0) { *errMsg = sfmt("Missing EspCompile directive for %s", csource); return MPR_ERR_CANT_READ; } mprTrace(4, "ESP command: %s\n", commandLine); if (eroute->env) { elist = mprCreateList(0, MPR_LIST_STABLE); for (ITERATE_KEYS(eroute->env, var)) { mprAddItem(elist, sfmt("%s=%s", var->key, var->data)); } mprAddNullItem(elist); env = (cchar**) &elist->items[0]; } else {
static void testHashScale(MprTestGroup *gp) { MprHash *table; MprKey *sp; char *str; char name[80], *address; int i; table = mprCreateHash(HASH_COUNT, 0); assert(mprGetHashLength(table) == 0); /* All inserts below will insert allocated strings. We must free before deleting the table. */ for (i = 0; i < HASH_COUNT; i++) { mprSprintf(name, sizeof(name), "name.%d", i); address = sfmt("%d Park Ave", i); sp = mprAddKey(table, name, address); assert(sp != 0); } assert(mprGetHashLength(table) == HASH_COUNT); /* Check data entered into the hash */ for (i = 0; i < HASH_COUNT; i++) { mprSprintf(name, sizeof(name), "name.%d", i); str = mprLookupKey(table, name); assert(str != 0); address = sfmt("%d Park Ave", i); assert(strcmp(str, address) == 0); } }
/* Get a password digest using the MD5 algorithm -- See RFC 2617 to understand this code. */ static char *calcDigest(HttpConn *conn, DigestData *dp, cchar *username) { HttpAuth *auth; char *digestBuf, *ha1, *ha2; auth = conn->rx->route->auth; if (!conn->user) { conn->user = mprLookupKey(auth->userCache, username); } assert(conn->user && conn->user->password); if (conn->user == 0 || conn->user->password == 0) { return 0; } /* Compute HA1. Password is already expected to be in the HA1 format MD5(username:realm:password). */ ha1 = sclone(conn->user->password); /* HA2 */ ha2 = mprGetMD5(sfmt("%s:%s", conn->rx->method, dp->uri)); /* H(HA1:nonce:HA2) */ if (scmp(dp->qop, "auth") == 0) { digestBuf = sfmt("%s:%s:%s:%s:%s:%s", ha1, dp->nonce, dp->nc, dp->cnonce, dp->qop, ha2); } else { digestBuf = sfmt("%s:%s:%s", ha1, dp->nonce, ha2); } return mprGetMD5(digestBuf); }
static char *getModuleEntry(EspRoute *eroute, cchar *kind, cchar *source, cchar *cacheName) { char *cp, *entry; if (smatch(kind, "view")) { entry = sfmt("esp_%s", cacheName); } else if (smatch(kind, "app")) { if (eroute->combine) { entry = sfmt("esp_%s_%s_combine", kind, eroute->appName); } else { entry = sfmt("esp_%s_%s", kind, eroute->appName); } } else { /* Controller */ if (eroute->appName) { entry = sfmt("esp_%s_%s_%s", kind, eroute->appName, mprTrimPathExt(mprGetPathBase(source))); } else { entry = sfmt("esp_%s_%s", kind, mprTrimPathExt(mprGetPathBase(source))); } } for (cp = entry; *cp; cp++) { if (!isalnum((uchar) *cp) && *cp != '_') { *cp = '_'; } } return entry; }
PUBLIC ssize espRenderError(HttpConn *conn, int status, cchar *fmt, ...) { va_list args; HttpRx *rx; ssize written; cchar *msg, *title, *text; va_start(args, fmt); rx = conn->rx; written = 0; if (!httpIsFinalized(conn)) { if (status == 0) { status = HTTP_CODE_INTERNAL_SERVER_ERROR; } title = sfmt("Request Error for \"%s\"", rx->pathInfo); msg = mprEscapeHtml(sfmtv(fmt, args)); if (rx->route->flags & HTTP_ROUTE_SHOW_ERRORS) { text = sfmt(\ "<!DOCTYPE html>\r\n<html>\r\n<head><title>%s</title></head>\r\n" \ "<body>\r\n<h1>%s</h1>\r\n" \ " <pre>%s</pre>\r\n" \ " <p>To prevent errors being displayed in the browser, " \ " set <b>ShowErrors off</b> in the appweb.conf file.</p>\r\n", \ "</body>\r\n</html>\r\n", title, title, msg); httpSetHeader(conn, "Content-Type", "text/html"); written += espRenderString(conn, text); espFinalize(conn); mprTrace(4, "Request error (%d) for: \"%s\"", status, rx->pathInfo); } } va_end(args); return written; }
cchar *ediFormatField(cchar *fmt, EdiField field) { MprTime when; if (fmt == 0) { return field.value; } switch (field.type) { case EDI_TYPE_BINARY: case EDI_TYPE_BOOL: return field.value; case EDI_TYPE_DATE: if (mprParseTime(&when, field.value, MPR_LOCAL_TIMEZONE, 0) == 0) { return mprFormatLocalTime(fmt, when); } return field.value; case EDI_TYPE_FLOAT: return sfmt(fmt, atof(field.value)); case EDI_TYPE_INT: return sfmt("%Ld", stoi(field.value)); case EDI_TYPE_STRING: case EDI_TYPE_TEXT: return sfmt(fmt, field.value); default: mprError("Unknown field type %d", field.type); } return 0; }
/* Check the certificate peer name validates and matches the desired name */ static int checkPeerCertName(MprSocket *sp) { MprSsl *ssl; OpenSocket *osp; X509 *cert; X509_NAME *xSubject; char subject[512], issuer[512], peerName[512], *target, *certName, *tp; ssl = sp->ssl; osp = (OpenSocket*) sp->sslSocket; if ((cert = SSL_get_peer_certificate(osp->handle)) == 0) { peerName[0] = '\0'; } else { xSubject = X509_get_subject_name(cert); X509_NAME_oneline(xSubject, subject, sizeof(subject) -1); X509_NAME_oneline(X509_get_issuer_name(cert), issuer, sizeof(issuer) -1); X509_NAME_get_text_by_NID(xSubject, NID_commonName, peerName, sizeof(peerName) - 1); sp->peerName = sclone(peerName); sp->peerCert = sclone(subject); sp->peerCertIssuer = sclone(issuer); X509_free(cert); } if (ssl->verifyPeer && osp->requiredPeerName) { target = osp->requiredPeerName; certName = peerName; if (target == 0 || *target == '\0' || strchr(target, '.') == 0) { sp->errorMsg = sfmt("Bad peer name"); return MPR_ERR_BAD_VALUE; } if (!smatch(certName, "localhost")) { if (strchr(certName, '.') == 0) { sp->errorMsg = sfmt("Peer certificate must have a domain: \"%s\"", certName); return MPR_ERR_BAD_VALUE; } if (*certName == '*' && certName[1] == '.') { /* Wildcard cert */ certName = &certName[2]; if (strchr(certName, '.') == 0) { /* Peer must be of the form *.domain.tld. i.e. *.com is not valid */ sp->errorMsg = sfmt("Peer CN is not valid %s", peerName); return MPR_ERR_BAD_VALUE; } if ((tp = strchr(target, '.')) != 0 && strchr(&tp[1], '.')) { /* Strip host name if target has a host name */ target = &tp[1]; } } } if (!smatch(target, certName)) { sp->errorMsg = sfmt("Certificate common name mismatch CN \"%s\" vs required \"%s\"", peerName, osp->requiredPeerName); return MPR_ERR_BAD_VALUE; } } return 0; }
static char *makeCacheKey(HttpConn *conn) { HttpRx *rx; rx = conn->rx; if (conn->tx->cache->flags & (HTTP_CACHE_ONLY | HTTP_CACHE_UNIQUE)) { return sfmt("http::response-%s?%s", rx->pathInfo, httpGetParamsString(conn)); } else { return sfmt("http::response-%s", rx->pathInfo); } }
static char *getSearchPath(cchar *dir) { #if WIN // bin : . return sfmt("%s" MPR_SEARCH_SEP ".", dir); #else // bin : /usr/lib/appweb/bin : /usr/lib/appweb/lib : lib : . char *libDir = mprJoinPath(mprGetPathParent(dir), BLD_LIB_NAME); return sfmt("%s" MPR_SEARCH_SEP "%s" MPR_SEARCH_SEP ".", dir, mprSamePath(BLD_BIN_PREFIX, dir) ? BLD_LIB_PREFIX: libDir); #endif }
void CMenu::_initGameInfoMenu(CMenu::SThemeData &theme) { STexture emptyTex; _addUserLabels(theme, m_gameinfoLblUser, 0, 1, "GAMEINFO"); _addUserLabels(theme, m_gameinfoLblUser, 2, 1, "GAMEINFO"); m_gameinfoBg = _texture(theme.texSet, "GAMEINFO/BG", "texture", theme.bg); m_gameinfoLblID = _addLabel(theme, "GAMEINFO/GAMEID", 125, 10, 420, 75, FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE); m_gameinfoLblGenre = _addText(theme, "GAMEINFO/GENRE", 40, 140, 560, 56, FTGX_JUSTIFY_LEFT | FTGX_ALIGN_TOP); m_gameinfoLblDev = _addText(theme, "GAMEINFO/DEVELOPER", 40, 170, 560, 56, FTGX_JUSTIFY_LEFT | FTGX_ALIGN_TOP); m_gameinfoLblPublisher = _addText(theme, "GAMEINFO/PUBLISHER", 40, 200, 560, 56, FTGX_JUSTIFY_LEFT | FTGX_ALIGN_TOP); m_gameinfoLblRlsdate = _addText(theme, "GAMEINFO/RLSDATE", 40, 230, 560, 56, FTGX_JUSTIFY_LEFT | FTGX_ALIGN_TOP); m_gameinfoLblRegion = _addText(theme, "GAMEINFO/REGION", 40, 260, 560, 56, FTGX_JUSTIFY_LEFT | FTGX_ALIGN_TOP); m_gameinfoLblRating = _addLabel(theme, "GAMEINFO/RATING", 550, 380, 48, 60, 0, m_rating); m_gameinfoLblSynopsis = _addText(theme, "GAMEINFO/SYNOPSIS", 40, 120, 560, 320, FTGX_JUSTIFY_LEFT | FTGX_ALIGN_TOP); m_gameinfoLblWifiplayers = _addLabel(theme, "GAMEINFO/WIFIPLAYERS", 550, 110, 68, 60, FTGX_JUSTIFY_LEFT | FTGX_ALIGN_TOP, m_wifi); _addUserLabels(theme, m_gameinfoLblUser, 1, 1, "GAMEINFO"); _addUserLabels(theme, m_gameinfoLblUser, 3, 2, "GAMEINFO"); m_gameinfoLblTitle = _addLabel(theme, "GAMEINFO/TITLE", 20, 37, 600, 75, FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE); for (u8 i = 0; i < ARRAY_SIZE(m_gameinfoLblControlsReq); ++i) { string dom(sfmt("GAMEINFO/CONTROLSREQ%i", i + 1)); m_gameinfoLblControlsReq[i] = _addLabel(theme, dom.c_str(), 40 + (i*60), 310, 60, 40, 0, emptyTex); _setHideAnim(m_gameinfoLblControlsReq[i], dom.c_str(), 0, -100, 0.f, 0.f); } for (u8 i = 0; i < ARRAY_SIZE(m_gameinfoLblControls); ++i) { string dom(sfmt("GAMEINFO/CONTROLS%i", i + 1)); m_gameinfoLblControls[i] = _addLabel(theme, dom.c_str(), 40 + (i*60), 380, 60, 40, 0, emptyTex); _setHideAnim(m_gameinfoLblControls[i], dom.c_str(), 0, -100, 0.f, 0.f); } // _setHideAnim(m_gameinfoLblID, "GAMEINFO/GAMEID",0, -100, 0.f, 0.f); _setHideAnim(m_gameinfoLblTitle, "GAMEINFO/TITLE", 0, -100, 0.f, 0.f); _setHideAnim(m_gameinfoLblRating, "GAMEINFO/RATING", 100, 0, 0.f, 0.f); _setHideAnim(m_gameinfoLblSynopsis, "GAMEINFO/SYNOPSIS", 0, 100, 0.f, 0.f); _setHideAnim(m_gameinfoLblRegion, "GAMEINFO/REGION", 0, -100, 0.f, 0.f); _setHideAnim(m_gameinfoLblDev, "GAMEINFO/DEVELOPER", 0, -100, 0.f, 0.f); _setHideAnim(m_gameinfoLblPublisher, "GAMEINFO/PUBLISHER", 0, -100, 0.f, 0.f); _setHideAnim(m_gameinfoLblRlsdate, "GAMEINFO/RLSDATE", 0, -100, 0.f, 0.f); _setHideAnim(m_gameinfoLblGenre, "GAMEINFO/GENRE", 0, -100, 0.f, 0.f); _setHideAnim(m_gameinfoLblWifiplayers, "GAMEINFO/WIFIPLAYERS", 0, -100, 0.f, 0.f); // _hideGameInfo(true); }
static void connTimeout(HttpConn *conn, MprEvent *mprEvent) { HttpLimits *limits; cchar *event, *msg, *prefix; if (conn->destroyed) { return; } assert(conn->tx); assert(conn->rx); msg = 0; event = 0; limits = conn->limits; assert(limits); if (conn->timeoutCallback) { (conn->timeoutCallback)(conn); } if (!conn->connError) { prefix = (conn->state == HTTP_STATE_BEGIN) ? "Idle connection" : "Request"; if (conn->timeout == HTTP_PARSE_TIMEOUT) { msg = sfmt("%s exceeded parse headers timeout of %lld sec", prefix, limits->requestParseTimeout / 1000); event = "timeout.parse"; } else if (conn->timeout == HTTP_INACTIVITY_TIMEOUT) { msg = sfmt("%s exceeded inactivity timeout of %lld sec", prefix, limits->inactivityTimeout / 1000); event = "timeout.inactivity"; } else if (conn->timeout == HTTP_REQUEST_TIMEOUT) { msg = sfmt("%s exceeded timeout %lld sec", prefix, limits->requestTimeout / 1000); event = "timeout.duration"; } if (conn->state < HTTP_STATE_FIRST) { httpDisconnect(conn); if (msg) { httpTrace(conn, event, "error", "msg:'%s'", msg); } } else { httpError(conn, HTTP_CODE_REQUEST_TIMEOUT, "%s", msg); } } if (httpClientConn(conn)) { httpDestroyConn(conn); } else { httpEnableConnEvents(conn); } }
static void basicLogin(Webs *wp) { assure(wp); assure(wp->route); wfree(wp->authResponse); wp->authResponse = sfmt("Basic realm=\"%s\"", BIT_REALM); }
static int runCommand(HttpConn *conn, cchar *command, cchar *csource, cchar *module) { EspReq *req; EspRoute *eroute; MprCmd *cmd; MprKey *var; MprList *elist; cchar **env; char *err, *out; req = conn->data; eroute = req->route->eroute; cmd = mprCreateCmd(conn->dispatcher); if ((req->commandLine = espExpandCommand(eroute, command, csource, module)) == 0) { httpError(conn, HTTP_CODE_INTERNAL_SERVER_ERROR, "Missing EspCompile directive for %s", csource); return MPR_ERR_CANT_READ; } mprLog(4, "ESP command: %s\n", req->commandLine); if (eroute->env) { elist = mprCreateList(0, 0); for (ITERATE_KEYS(eroute->env, var)) { mprAddItem(elist, sfmt("%s=%s", var->key, var->data)); } mprAddNullItem(elist); env = (cchar**) &elist->items[0]; } else {
/* Create a nonce value for digest authentication (RFC 2617) */ static char *createDigestNonce(HttpConn *conn, cchar *secret, cchar *realm) { static int64 next = 0; assert(realm && *realm); return mprEncode64(sfmt("%s:%s:%Lx:%Lx", secret, realm, mprGetTime(), next++)); }
/* Dump the file upload details. Don't actually do anything with the uploaded file. */ static void uploadTest(Webs *wp, char *path, char *query) { WebsKey *s; WebsUpload *up; char *upfile; websSetStatus(wp, 200); websWriteHeaders(wp, -1, 0); websWriteHeader(wp, "Content-Type", "text/plain"); websWriteEndHeaders(wp); if (scaselessmatch(wp->method, "POST")) { for (s = hashFirst(wp->files); s; s = hashNext(wp->files, s)) { up = s->content.value.symbol; websWrite(wp, "FILE: %s\r\n", s->name.value.string); websWrite(wp, "FILENAME=%s\r\n", up->filename); websWrite(wp, "CLIENT=%s\r\n", up->clientFilename); websWrite(wp, "TYPE=%s\r\n", up->contentType); websWrite(wp, "SIZE=%d\r\n", up->size); upfile = sfmt("%s/tmp/%s", websGetDocuments(), up->clientFilename); rename(up->filename, upfile); wfree(upfile); } websWrite(wp, "\r\nVARS:\r\n"); for (s = hashFirst(wp->vars); s; s = hashNext(wp->vars, s)) { websWrite(wp, "%s=%s\r\n", s->name.value.string, s->content.value.string); } } websDone(wp); }
PUBLIC void espAddPak(HttpRoute *route, cchar *name, cchar *version) { if (!version || !*version || smatch(version, "0.0.0")) { version = "*"; } mprSetJson(route->config, sfmt("dependencies.%s", name), version, MPR_JSON_STRING); }
static void basicLogin(Webs *wp) { assert(wp); assert(wp->route); wfree(wp->authResponse); wp->authResponse = sfmt("Basic realm=\"%s\"", ME_GOAHEAD_REALM); }
PUBLIC bool espHasComponent(HttpRoute *route, cchar *name) { EspRoute *eroute; eroute = route->eroute; return mprGetJsonValue(eroute->config, sfmt("settings.components[@ = '%s']", name), 0) != 0; }
/* Create the top level appweb control object. This is typically a singleton. */ PUBLIC MaAppweb *maCreateAppweb() { MaAppweb *appweb; Http *http; if ((appweb = mprAllocObj(MaAppweb, manageAppweb)) == NULL) { return 0; } MPR->appwebService = appweb; appweb->http = http = httpCreate(HTTP_CLIENT_SIDE | HTTP_SERVER_SIDE); httpSetContext(http, appweb); appweb->servers = mprCreateList(-1, 0); appweb->localPlatform = slower(sfmt("%s-%s-%s", BIT_OS, BIT_CPU, BIT_PROFILE)); maSetPlatform(NULL); maGetUserGroup(appweb); maParseInit(appweb); /* Open the builtin handlers */ #if BIT_PACK_DIR maOpenDirHandler(http); #endif maOpenFileHandler(http); return appweb; }
static void readBody(HttpConn *conn, MprFile *outFile) { char buf[BIT_MAX_BUFFER]; cchar *result; ssize bytes; while (!conn->error && conn->sock && (bytes = httpRead(conn, buf, sizeof(buf))) > 0) { if (!app->noout) { result = formatOutput(conn, buf, &bytes); if (result) { mprWriteFile(outFile, result, bytes); } } #if FUTURE // This should be pushed into a range filter. // Buffer all output and then parsing can work type = httpGetHeader(conn, "Content-Type"); if (scontains(type, "multipart/byteranges")) { if ((boundary = scontains(type, "boundary=")) != 0) { boundary += 9; if (*boundary) { boundary = sfmt("--%s\r\n", boundary); } } } #endif } }
static int clientRequest(HttpStream *stream, cchar *method, cchar *uri, cchar *data, int protocol, char **err) { ssize len; /* Open a connection to issue the request. Then finalize the request output - this forces the request out. */ *err = 0; if (httpConnect(stream, method, uri, NULL) < 0) { *err = sfmt("Cannot connect to %s", uri); return MPR_ERR_CANT_CONNECT; } if (data) { len = slen(data); if (httpWriteBlock(stream->writeq, data, len, HTTP_BLOCK) != len) { *err = sclone("Cannot write request body data"); return MPR_ERR_CANT_WRITE; } } httpFinalizeOutput(stream); if (httpWait(stream, HTTP_STATE_CONTENT, MPR_MAX_TIMEOUT) < 0) { *err = sclone("No response"); return MPR_ERR_BAD_STATE; } return 0; }
static int makeChannel(MprCmd *cmd, int index) { MprCmdFile *file; int nonBlock; static int tempSeed = 0; file = &cmd->files[index]; file->name = sfmt("/pipe/%s_%d_%d", ME_NAME, taskIdSelf(), tempSeed++); if (pipeDevCreate(file->name, 6, ME_BUFSIZE) < 0) { mprLog("error mpr cmd", 0, "Cannot create pipes to run %s", cmd->program); return MPR_ERR_CANT_OPEN; } /* Open the server end of the pipe. MPR_CMD_STDIN is from the client's perspective. */ if (index == MPR_CMD_STDIN) { file->fd = open(file->name, O_WRONLY, 0644); } else { file->fd = open(file->name, O_RDONLY, 0644); } if (file->fd < 0) { mprLog("error mpr cmd", 0, "Cannot create stdio pipes. Err %d", mprGetOsError()); return MPR_ERR_CANT_CREATE; } nonBlock = 1; ioctl(file->fd, FIONBIO, (int) &nonBlock); return 0; }
static void processing() { MprThread *tp; ThreadData *data; int j; if (app->chunkSize > 0) { mprAddItem(app->headers, mprCreateKeyPair("X-Appweb-Chunk-Size", sfmt("%d", app->chunkSize))); } app->activeLoadThreads = app->loadThreads; app->threadData = mprCreateList(app->loadThreads, 0); for (j = 0; j < app->loadThreads; j++) { char name[64]; if ((data = mprAllocObj(ThreadData, manageThreadData)) == 0) { return; } mprAddItem(app->threadData, data); mprSprintf(name, sizeof(name), "http.%d", j); tp = mprCreateThread(name, threadMain, NULL, 0); tp->data = data; mprStartThread(tp); } }
static char *getOutDir(cchar *name) { #if DEBUG_IDE return mprGetAppDir(); #else return mprNormalizePath(sfmt("%s/../%s", mprGetAppDir(), name)); #endif }
PUBLIC void espAddComponent(HttpRoute *route, cchar *name) { EspRoute *eroute; eroute = route->eroute; if (!mprGetJsonValue(eroute->config, sfmt("settings.components[@ = %s]", name), 0)) { mprSetJsonValue(eroute->config, "settings.components[*]", name, 0); } }
PUBLIC cchar *mprGetCompatibleVersion(cchar *version) { MprVersion *vp; if ((vp = mprCreateVersion(version)) == 0) { return 0; } return sfmt("%d.%d", vp->major, vp->minor); }
static void testCopyPath(MprTestGroup *gp) { MprFile *file; char *from, *to; from = sfmt("copyTest-%s.tmp", mprGetCurrentThreadName(gp)); assert(from != 0); file = mprOpenFile(from, O_CREAT | O_TRUNC | O_WRONLY, 0664); assert(file != 0); mprWriteFileString(file, "Hello World"); mprCloseFile(file); to = sfmt("newTest-%s.tmp", mprGetCurrentThreadName(gp)); assert(mprPathExists(from, F_OK)); mprCopyPath(from, to, 0664); assert(mprPathExists(to, F_OK)); mprDeletePath(from); mprDeletePath(to); }
PUBLIC void renderError(int status, cchar *fmt, ...) { va_list args; cchar *msg; va_start(args, fmt); msg = sfmt(fmt, args); espRenderError(getStream(), status, "%s", msg); va_end(args); }