static void testBasicAlloc(MprTestGroup *gp) { char *cp; int size; size = 16; cp = (char*) mprAlloc(gp, size); assert(cp != 0); memset(cp, 0x77, size); mprFree(cp); cp = (char*) mprAlloc(gp, size); assert(cp != 0); memset(cp, 0x77, size); cp = (char*) mprRealloc(gp, cp, size * 2); assert(cp != 0); mprFree(cp); cp = mprStrdup(gp, "Hello World"); assert(cp != 0); assert(strcmp(cp, "Hello World") == 0); mprFree(cp); /* * Test special MR allowances */ mprFree(0); cp = mprStrdup(gp, 0); assert(cp != 0); assert(cp[0] == '\0'); mprFree(cp); }
static void testAllocIntegrityChecks(MprTestGroup *gp) { void *blocks[259]; uchar *cp; int i, j, size, count; /* * Basic integrity test. Allocate blocks of 64 bytes and fill and test * each block */ size = 64; count = sizeof(blocks) / sizeof(void*); for (i = 0; i < count; i++) { blocks[i] = mprAlloc(gp, size); assert(blocks[i] != 0); memset(blocks[i], i % 0xff, size); } for (i = 0; i < count; i++) { cp = (uchar*) blocks[i]; for (j = 0; j < size; j++) { assert(cp[j] == (i % 0xff)); } mprFree(blocks[i]); } /* * Now do with bigger blocks and also free some before testing */ count = sizeof(blocks) / sizeof(void*); for (i = 1; i < count; i++) { size = 1 << ((i + 6) / 100); blocks[i] = mprAlloc(gp, size); assert(blocks[i] != 0); memset(blocks[i], i % 0xff, size); } for (i = 1; i < count; i += 3) { mprFree(blocks[i]); blocks[i] = 0; } for (i = 1; i < count; i++) { if (blocks[i] == 0) { continue; } cp = (uchar*) blocks[i]; size = 1 << ((i + 6) / 100); for (j = 0; j < size; j++) { assert(cp[j] == (i % 0xff)); } mprFree(blocks[i]); } }
/* Uri encode by encoding special characters with hex equivalents. Return an allocated string. */ PUBLIC char *mprUriEncode(cchar *inbuf, int map) { static cchar hexTable[] = "0123456789ABCDEF"; uchar c; cchar *ip; char *result, *op; int len; assert(inbuf); assert(inbuf); if (!inbuf) { return MPR->emptyString; } for (len = 1, ip = inbuf; *ip; ip++, len++) { if (charMatch[(uchar) *ip] & map) { len += 2; } } if ((result = mprAlloc(len)) == 0) { return 0; } op = result; while ((c = (uchar) (*inbuf++)) != 0) { if (c == ' ' && (map & MPR_ENCODE_URI_COMPONENT)) { *op++ = '+'; } else if (charMatch[c] & map) { *op++ = '%'; *op++ = hexTable[c >> 4]; *op++ = hexTable[c & 0xf]; } else {
static void testLotsOfAlloc(MprTestGroup *gp) { void *mp; int i; for (i = 0; i < 10000; i++) { mp = mprAlloc(gp, 64); assert(mp != 0); mprFree(mp); } for (i = 2; i < (2 * 1024 * 1024); i *= 2) { mp = mprAlloc(gp, i); assert(mp != 0); mprFree(mp); } }
PUBLIC int ecOpenFileStream(EcCompiler *cp, cchar *path) { EcFileStream *fs; MprPath info; char *contents; if ((fs = ecCreateStream(cp, sizeof(EcFileStream), path, manageFileStream)) == 0) { return MPR_ERR_MEMORY; } if ((fs->file = mprOpenFile(path, O_RDONLY | O_BINARY, 0666)) == 0) { return MPR_ERR_CANT_OPEN; } if (mprGetPathInfo(path, &info) < 0 || info.size < 0) { mprCloseFile(fs->file); return MPR_ERR_CANT_ACCESS; } if ((contents = mprAlloc((int) info.size + 1)) == 0) { mprCloseFile(fs->file); return MPR_ERR_MEMORY; } if (mprReadFile(fs->file, contents, (int) info.size) != (int) info.size) { mprCloseFile(fs->file); return MPR_ERR_CANT_READ; } contents[info.size] = '\0'; ecSetStreamBuf((EcStream*) fs, contents, (ssize) info.size); mprCloseFile(fs->file); fs->file = 0; return 0; }
char *sjoinv(cchar *buf, va_list args) { va_list ap; char *dest, *str, *dp; ssize required; va_copy(ap, args); required = 1; if (buf) { required += slen(buf); } str = va_arg(ap, char*); while (str) { required += slen(str); str = va_arg(ap, char*); } if ((dest = mprAlloc(required)) == 0) { return 0; } dp = dest; if (buf) { strcpy(dp, buf); dp += slen(buf); } va_copy(ap, args); str = va_arg(ap, char*); while (str) { strcpy(dp, str); dp += slen(str); str = va_arg(ap, char*); } *dp = '\0'; return dest; }
bool bulkPost(MprTestGroup *gp, char *url, int size, int expectStatus) { char *post; int i, j; bool success; app->postData = post = (char*) mprAlloc(size + 1); tassert(post != 0); for (i = 0; i < size; i++) { if (i > 0) { fmt(&post[i], 10, "&%07d=", i / 64); } else { fmt(&post[i], 10, "%08d=", i / 64); } for (j = i + 9; j < (i + 63); j++) { post[j] = 'a'; } post[j] = '\n'; i = j; } post[i] = '\0'; success = simplePost(gp, url, post, slen(post), expectStatus); tassert(success); app->postData = 0; return success; }
/* * Url encode by encoding special characters with hex equivalents. */ char *mprUrlEncode(MprCtx ctx, cchar *inbuf) { static cchar hexTable[] = "0123456789abcdef"; uchar c; cchar *ip; char *result, *op; int len; mprAssert(inbuf); mprAssert(inbuf); for (len = 1, ip = inbuf; *ip; ip++, len++) { if (charMatch[(uchar) *ip] & MPR_HTTP_ESCAPE_URL) { len += 2; } } if ((result = mprAlloc(ctx, len)) == 0) { return 0; } ip = inbuf; op = result; while ((c = (uchar) (*inbuf++)) != 0) { if (c == ' ') { *op++ = '+'; } else if (charMatch[c] & MPR_HTTP_ESCAPE_URL) { *op++ = '%'; *op++ = hexTable[c >> 4]; *op++ = hexTable[c & 0xf]; } else {
/* Open handler for a new request */ static void openPhp(HttpQueue *q) { HttpRx *rx; rx = q->conn->rx; /* PHP will buffer all input. i.e. does not stream. The normal Limits still apply. */ q->max = q->pair->max = MAXINT; mprLog(5, "Open php handler"); httpTrimExtraPath(q->conn); if (rx->flags & (HTTP_OPTIONS | HTTP_TRACE)) { httpHandleOptionsTrace(q->conn, "DELETE,GET,HEAD,POST,PUT"); } else if (rx->flags & (HTTP_GET | HTTP_HEAD | HTTP_POST | HTTP_PUT)) { httpMapFile(q->conn, rx->route); if (!q->stage->stageData) { if (initializePhp(q->conn->http) < 0) { httpError(q->conn, HTTP_CODE_INTERNAL_SERVER_ERROR, "PHP initialization failed"); } q->stage->stageData = mprAlloc(1); } q->queueData = mprAllocObj(MaPhp, NULL); } else { httpError(q->conn, HTTP_CODE_BAD_METHOD, "Method not supported by file handler: %s", rx->method); } }
EjsString *ejsSerializeWithOptions(Ejs *ejs, EjsAny *vp, EjsObj *options) { Json json; EjsObj *arg; EjsString *result; int i; memset(&json, 0, sizeof(Json)); json.depth = 99; json.quotes = 1; json.indent = sclone(" "); if (options) { json.options = options; if ((arg = ejsGetPropertyByName(ejs, options, EN("baseClasses"))) != 0) { json.baseClasses = (arg == ESV(true)); } if ((arg = ejsGetPropertyByName(ejs, options, EN("depth"))) != 0) { json.depth = ejsGetInt(ejs, arg); } if ((arg = ejsGetPropertyByName(ejs, options, EN("indent"))) != 0) { if (ejsIs(ejs, arg, String)) { json.indent = (char*) ejsToMulti(ejs, arg); // TODO - get another solution to hold } else if (ejsIs(ejs, arg, Number)) { i = ejsGetInt(ejs, arg); if (0 <= i && i < MPR_MAX_STRING) { json.indent = mprAlloc(i + 1); // TODO - get another solution to hold memset(json.indent, ' ', i); json.indent[i] = '\0'; } } } if ((arg = ejsGetPropertyByName(ejs, options, EN("commas"))) != 0) { json.commas = (arg == ESV(true)); } if ((arg = ejsGetPropertyByName(ejs, options, EN("hidden"))) != 0) { json.hidden = (arg == ESV(true)); } if ((arg = ejsGetPropertyByName(ejs, options, EN("namespaces"))) != 0) { json.namespaces = (arg == ESV(true)); } if ((arg = ejsGetPropertyByName(ejs, options, EN("quotes"))) != 0) { json.quotes = (arg != ESV(false)); } if ((arg = ejsGetPropertyByName(ejs, options, EN("pretty"))) != 0) { json.pretty = (arg == ESV(true)); } json.replacer = ejsGetPropertyByName(ejs, options, EN("replacer")); if (!ejsIsFunction(ejs, json.replacer)) { json.replacer = NULL; } } mprRelease(json.indent); mprHold(json.indent); result = serialize(ejs, vp, &json); // TODO - get another solution to hold return result; }
static cchar *formatOutput(HttpConn *conn, cchar *buf, ssize *count) { cchar *result; int i, c, isBinary; if (app->noout) { return 0; } if (!app->printable) { return buf; } isBinary = 0; for (i = 0; i < *count; i++) { if (!isprint((uchar) buf[i]) && buf[i] != '\n' && buf[i] != '\r' && buf[i] != '\t') { isBinary = 1; break; } } if (!isBinary) { return buf; } result = mprAlloc(*count * 3 + 1); for (i = 0; i < *count; i++) { c = (uchar) buf[i]; if (app->printable && isBinary) { fmt("%02x ", -1, &result[i * 3], c & 0xff); } else { fmt("%c", -1, &result[i], c & 0xff); } } if (app->printable && isBinary) { *count *= 3; } return result; }
int mprAllocStrcpy(MPR_LOC_DEC(ctx, loc), char **dest, int destMax, const char *src) { int len; mprAssert(dest); mprAssert(destMax >= 0); mprAssert(src); len = strlen(src); if (destMax > 0 && len >= destMax) { mprAssert(0); return MPR_ERR_WONT_FIT; } if (len > 0) { *dest = (char*) mprAllocBlock(MPR_LOC_PASS(ctx, loc), len); memcpy(*dest, src, len); (*dest)[len] = '\0'; } else { *dest = (char*) mprAlloc(ctx, 1); *dest = '\0'; len = 0; } return len; }
// TODO - remove last parameter static char *makeFilename(MaConn *conn, MaAlias *alias, cchar *url, bool skipAliasPrefix) { char *cleanPath, *path; int len; mprAssert(alias); mprAssert(url && *url); if (skipAliasPrefix) { url += alias->prefixLen; } while (*url == '/') { url++; } len = (int) strlen(alias->filename); if ((path = mprAlloc(conn->request, len + (int) strlen(url) + 2)) == 0) { return 0; } strcpy(path, alias->filename); if (*url) { path[len++] = '/'; strcpy(&path[len], url); } cleanPath = mprCleanFilename(conn, path); mprMapDelimiters(conn, cleanPath, '/'); mprFree(path); return cleanPath; }
/* * Convert a unicode string newly allocated C string */ char *mprUsToStr(uni *us) { char *str, *cp; mprAssert(us); str = cp = mprAlloc(us, us->length + 1); if (cp == 0) { return 0; } #if BLD_FEATURE_UTF16 { uniData *up; int i; up = us->str; for (i = 0; i < us->length; i++) { cp[i] = up[i]; } } #else mprStrcpy(cp, us->length, us->str); #endif return str; }
static char *joinLine(cchar *str, ssize *lenp) { cchar *cp; char *buf, *bp; ssize len; int count, bquote; for (count = 0, cp = str; *cp; cp++) { if (*cp == '\n') { count++; } } len = slen(str); if ((buf = mprAlloc(len + (count * 3) + 1)) == 0) { return 0; } bquote = 0; for (cp = str, bp = buf; *cp; cp++) { if (*cp == '\n') { *bp++ = '\\'; *bp++ = 'n'; *bp++ = '\\'; } else if (*cp == '\\' && cp[1] != '\\') { bquote++; } *bp++ = *cp; } *bp = '\0'; *lenp = len - bquote; return buf; }
/* Create a single string command to invoke - windows doesn't support exec(argv) */ static void prepWinCommand(MprCmd *cmd) { #if ME_WIN_LIKE /* WARNING: If starting a program compiled with Cygwin, there is a bug in Cygwin's parsing of the command string where embedded quotes are parsed incorrectly by the Cygwin CRT runtime. If an arg starts with a drive spec, embedded backquoted quotes will be stripped and the backquote will be passed in. Windows CRT handles this correctly. For example: ./args "c:/path \"a b\" Cygwin will parse as argv[1] == c:/path \a \b Windows will parse as argv[1] == c:/path "a b" */ cchar **ap, *start, *cp; char *dp; ssize len; int argc, quote; /* Create the command line */ argc = 0; for (len = 0, ap = cmd->argv; *ap; ap++) { /* Space and possible quotes and worst case backquoting */ len += (slen(*ap) * 2) + 2 + 1; argc++; } cmd->command = mprAlloc(len + 1); cmd->command[len] = '\0'; /* Add quotes around all args that have spaces and backquote double quotes. Example: ["showColors", "red", "light blue", "Cannot \"render\""] Becomes: "showColors" "red" "light blue" "Cannot \"render\"" */ dp = cmd->command; for (ap = &cmd->argv[0]; *ap; ) { start = cp = *ap; quote = '"'; if (cp[0] != quote && (strchr(cp, ' ') != 0 || strchr(cp, quote) != 0)) { for (*dp++ = quote; *cp; ) { if (*cp == quote && !(cp > start && cp[-1] == '\\')) { *dp++ = '\\'; } *dp++ = *cp++; } *dp++ = quote; } else { strcpy(dp, cp); dp += strlen(cp); } if (*++ap) { *dp++ = ' '; } } *dp = '\0'; mprLog("info mpr cmd", 6, "Windows command line: %s", cmd->command); #endif /* ME_WIN_LIKE */ }
static void testBigAlloc(MprTestGroup *gp) { void *mp; mp = mprAlloc(gp, 8 * 1024 * 1024); assert(mp != 0); mprFree(mp); }
/* Create the module constants. Count is the number of strings in the constant pool. Size is the size of the pool. The optional pool parameter supplies a pre-allocated buffer of constant strings. */ int ejsCreateConstants(Ejs *ejs, EjsModule *mp, int count, ssize size, char *pool) { EjsConstants *constants; char *pp; int i; assert(ejs); if ((constants = mprAllocObj(EjsConstants, manageConstants)) == 0) { return MPR_ERR_MEMORY; } lock(mp); mp->constants = constants; if (ejs->compiling && ((constants->table = mprCreateHash(EJS_DOC_HASH_SIZE, MPR_HASH_STATIC_VALUES)) == 0)) { unlock(mp); return MPR_ERR_MEMORY; } constants->poolSize = size; if ((constants->pool = pool) == 0) { assert(count == 0); if ((constants->pool = mprAlloc(size)) == 0) { unlock(mp); return MPR_ERR_MEMORY; } } if (count) { constants->poolLength = size; if ((constants->index = mprAlloc(count * sizeof(EjsString*))) == NULL) { unlock(mp); return MPR_ERR_MEMORY; } assert(pool); if (pool) { for (pp = pool, i = 0; pp < &pool[constants->poolLength]; i++) { constants->index[i] = (void*) (((pp - pool) << 1) | 0x1); pp += slen(pp) + 1; } constants->indexCount = count; } } unlock(mp); return 0; }
/* Initialize the MPR SSL layer */ PUBLIC int mprSslInit(void *unused, MprModule *module) { RandBuf randBuf; int i; randBuf.now = mprGetTime(); randBuf.pid = getpid(); RAND_seed((void*) &randBuf, sizeof(randBuf)); #if ME_UNIX_LIKE RAND_load_file("/dev/urandom", 256); #endif if ((openProvider = mprAllocObj(MprSocketProvider, manageOpenProvider)) == NULL) { return MPR_ERR_MEMORY; } openProvider->name = sclone("openssl"); openProvider->upgradeSocket = upgradeOss; openProvider->closeSocket = closeOss; openProvider->disconnectSocket = disconnectOss; openProvider->flushSocket = flushOss; openProvider->socketState = getOssState; openProvider->readSocket = readOss; openProvider->writeSocket = writeOss; mprSetSslProvider(openProvider); /* Configure the SSL library. Use the crypto ID as a one-time test. This allows users to configure the library and have their configuration used instead. */ mprGlobalLock(); if (CRYPTO_get_id_callback() == 0) { numLocks = CRYPTO_num_locks(); if ((olocks = mprAlloc(numLocks * sizeof(MprMutex*))) == 0) { return MPR_ERR_MEMORY; } for (i = 0; i < numLocks; i++) { olocks[i] = mprCreateLock(); } CRYPTO_set_id_callback(sslThreadId); CRYPTO_set_locking_callback(sslStaticLock); CRYPTO_set_dynlock_create_callback(sslCreateDynLock); CRYPTO_set_dynlock_destroy_callback(sslDestroyDynLock); CRYPTO_set_dynlock_lock_callback(sslDynLock); #if !ME_WIN_LIKE OpenSSL_add_all_algorithms(); #endif /* WARNING: SSL_library_init() is not reentrant. Caller must ensure safety. */ SSL_library_init(); SSL_load_error_strings(); } mprGlobalUnlock(); return 0; }
char *mprToAsc(MprCtx ctx, cuni *w) { char *str; int len; len = WideCharToMultiByte(CP_ACP, 0, w, -1, NULL, 0, NULL, NULL); if ((str = mprAlloc(ctx, len + 1)) != 0) { WideCharToMultiByte(CP_ACP, 0, w, -1, str, (DWORD) len, NULL, NULL); } return str; }
uni *mprToUni(MprCtx ctx, cchar* a) { uni *wstr; int len; len = MultiByteToWideChar(CP_ACP, 0, a, -1, NULL, 0); wstr = (uni*) mprAlloc(ctx, (len+1) * sizeof(uni)); if (wstr) { MultiByteToWideChar(CP_ACP, 0, a, -1, wstr, len); } return wstr; }
/* Read data as a string */ PUBLIC char *httpReadString(HttpConn *conn) { HttpRx *rx; ssize sofar, nbytes, remaining; char *content; rx = conn->rx; remaining = (ssize) min(MAXSSIZE, rx->length); if (remaining > 0) { if ((content = mprAlloc(remaining + 1)) == 0) { return 0; } sofar = 0; while (remaining > 0) { nbytes = httpRead(conn, &content[sofar], remaining); if (nbytes < 0) { return 0; } sofar += nbytes; remaining -= nbytes; } } else { content = mprAlloc(BIT_MAX_BUFFER); sofar = 0; while (1) { nbytes = httpRead(conn, &content[sofar], BIT_MAX_BUFFER); if (nbytes < 0) { return 0; } else if (nbytes == 0) { break; } sofar += nbytes; content = mprRealloc(content, sofar + BIT_MAX_BUFFER); } } content[sofar] = '\0'; return content; }
static void traceBuf(MaConn *conn, cchar *buf, int len, int mask) { cchar *cp, *tag, *digits; char *data, *dp; int level, i, printable; level = conn->host->traceLevel; for (printable = 1, i = 0; i < len; i++) { if (!isascii(buf[i])) { printable = 0; } } tag = (mask & MA_TRACE_RESPONSE) ? "Response" : "Request"; if (printable) { data = mprAlloc(conn, len + 1); memcpy(data, buf, len); data[len] = '\0'; mprRawLog(conn, level, "%s packet, conn %d, len %d >>>>>>>>>>\n%s", tag, conn->seqno, len, data); mprFree(data); } else { mprRawLog(conn, level, "%s packet, conn %d, len %d >>>>>>>>>> (binary)\n", tag, conn->seqno, len); data = mprAlloc(conn, len * 3 + ((len / 16) + 1) + 1); digits = "0123456789ABCDEF"; for (i = 0, cp = buf, dp = data; cp < &buf[len]; cp++) { *dp++ = digits[(*cp >> 4) & 0x0f]; *dp++ = digits[*cp++ & 0x0f]; *dp++ = ' '; if ((++i % 16) == 0) { *dp++ = '\n'; } } *dp++ = '\n'; *dp = '\0'; mprRawLog(conn, level, "%s", data); } mprRawLog(conn, level, "<<<<<<<<<< %s packet end, conn %d\n\n", tag, conn->seqno); }
char *sclone(cchar *str) { char *ptr; ssize size, len; if (str == 0) { str = ""; } len = slen(str); size = len + 1; if ((ptr = mprAlloc(size)) != 0) { memcpy(ptr, str, len); ptr[len] = '\0'; } return ptr; }
static int initializeToken(EcToken *tp, EcStream *stream) { tp->stream = stream; tp->loc = tp->stream->loc; tp->length = 0; tp->loc.lineNumber = 0; tp->tokenId = 0; if (tp->text == 0) { tp->size = EC_TOKEN_INCR; if ((tp->text = mprAlloc(tp->size * sizeof(wchar))) == 0) { return MPR_ERR_MEMORY; } tp->text[0] = '\0'; } return 0; }
int mprReadRegistry(MprCtx ctx, char **buf, int max, cchar *key, cchar *name) { HKEY top, h; char *value; ulong type, size; mprAssert(key && *key); mprAssert(buf); /* * Get the registry hive */ if ((key = getHive(key, &top)) == 0) { return MPR_ERR_CANT_ACCESS; } if (RegOpenKeyEx(top, key, 0, KEY_READ, &h) != ERROR_SUCCESS) { return MPR_ERR_CANT_ACCESS; } /* * Get the type */ if (RegQueryValueEx(h, name, 0, &type, 0, &size) != ERROR_SUCCESS) { RegCloseKey(h); return MPR_ERR_CANT_READ; } if (type != REG_SZ && type != REG_EXPAND_SZ) { RegCloseKey(h); return MPR_ERR_BAD_TYPE; } value = (char*) mprAlloc(ctx, size); if ((int) size > max) { RegCloseKey(h); return MPR_ERR_WONT_FIT; } if (RegQueryValueEx(h, name, 0, &type, (uchar*) value, &size) != ERROR_SUCCESS) { mprFree(value); RegCloseKey(h); return MPR_ERR_CANT_READ; } RegCloseKey(h); *buf = value; return 0; }
static int getVars(MaQueue *q, char ***keys, char *buf, int len) { char** keyList; char *eq, *cp, *pp, *tok; int i, keyCount; *keys = 0; /* * Change all plus signs back to spaces */ keyCount = (len > 0) ? 1 : 0; for (cp = buf; cp < &buf[len]; cp++) { if (*cp == '+') { *cp = ' '; } else if (*cp == '&' && (cp > buf && cp < &buf[len - 1])) { keyCount++; } } if (keyCount == 0) { return 0; } /* * Crack the input into name/value pairs */ keyList = (char**) mprAlloc(q, (keyCount * 2) * sizeof(char**)); i = 0; tok = 0; for (pp = mprStrTok(buf, "&", &tok); pp; pp = mprStrTok(0, "&", &tok)) { if ((eq = strchr(pp, '=')) != 0) { *eq++ = '\0'; mprUrlDecode(pp, (int) strlen(pp) + 1, pp); mprUrlDecode(eq, (int) strlen(eq) + 1, eq); } else { mprUrlDecode(pp, (int) strlen(pp) + 1, pp); } if (i < (keyCount * 2)) { keyList[i++] = pp; keyList[i++] = eq; } } *keys = keyList; return keyCount; }
PUBLIC char *stitle(cchar *str) { char *ptr; ssize size, len; if (str == 0) { str = ""; } len = slen(str); size = len + 1; if ((ptr = mprAlloc(size)) != 0) { memcpy(ptr, str, len); ptr[len] = '\0'; ptr[0] = (char) toupper((uchar) ptr[0]); } return ptr; }
/* Get a printable version of a buffer. Return a pointer to the start of printable data. This will use the tx or rx mime type if possible. Skips UTF encoding prefixes */ PUBLIC cchar *httpMakePrintable(HttpTrace *trace, HttpConn *conn, cchar *event, cchar *buf, ssize *lenp) { cchar *start, *cp, *digits; char *data, *dp; ssize len; int i; if (conn) { if (smatch(event, "rx.body")) { if (sstarts(mprLookupMime(0, conn->rx->mimeType), "text/")) { return buf; } } else if (smatch(event, "tx.body")) { if (sstarts(mprLookupMime(0, conn->tx->mimeType), "text/")) { return buf; } } } start = buf; len = *lenp; if (len > 3 && start[0] == (char) 0xef && start[1] == (char) 0xbb && start[2] == (char) 0xbf) { /* Step over UTF encoding */ start += 3; *lenp -= 3; } len = min(len, trace->maxContent); for (i = 0; i < len; i++) { if (!isprint((uchar) start[i]) && start[i] != '\n' && start[i] != '\r' && start[i] != '\t') { data = mprAlloc(len * 3 + ((len / 16) + 1) + 1); digits = "0123456789ABCDEF"; for (i = 0, cp = start, dp = data; cp < &start[len]; cp++) { *dp++ = digits[(*cp >> 4) & 0x0f]; *dp++ = digits[*cp & 0x0f]; *dp++ = ' '; if ((++i % 16) == 0) { *dp++ = '\n'; } } *dp++ = '\n'; *dp = '\0'; start = data; *lenp = dp - start; break; } }
char *scamel(cchar *str) { char *ptr; ssize size, len; if (str == 0) { str = ""; } len = slen(str); size = len + 1; if ((ptr = mprAlloc(size)) != 0) { memcpy(ptr, str, len); ptr[len] = '\0'; } ptr[0] = (char) tolower((uchar) ptr[0]); return ptr; }