Exemplo n.º 1
0
static void processDir(HttpQueue *q)
{
    HttpConn        *conn;
    HttpTx          *tx;
    HttpRx          *rx;
    MprList         *list;
    MprDirEntry     *dp;
    Dir             *dir;
    uint            nameSize;
    int             next;

    conn = q->conn;
    rx = conn->rx;
    tx = conn->tx;
    dir = conn->data;

    mprLog(5, "processDir");
    mprAssert(tx->filename);

    httpSetHeaderString(conn, "Cache-Control", "no-cache");
    httpSetHeaderString(conn, "Last-Modified", conn->http->currentDate);
    parseQuery(conn);

    list = mprGetPathFiles(tx->filename, 1);
    if (list == 0) {
        httpWrite(q, "<h2>Can't get file list</h2>\r\n");
        outputFooter(q);
        return;
    }
    if (dir->pattern) {
        filterDirList(conn, list);
    }
    sortList(conn, list);

    /*
        Get max filename
     */
    nameSize = 0;
    for (next = 0; (dp = mprGetNextItem(list, &next)) != 0; ) {
        nameSize = max((int) strlen(dp->name), nameSize);
    }
    nameSize = max(nameSize, 22);

    outputHeader(q, rx->pathInfo, nameSize);
    for (next = 0; (dp = mprGetNextItem(list, &next)) != 0; ) {
        outputLine(q, dp, tx->filename, nameSize);
    }
    outputFooter(q);
    httpFinalize(conn);
}
Exemplo n.º 2
0
int httpStartEndpoint(HttpEndpoint *endpoint)
{
    HttpHost    *host;
    cchar       *proto, *ip;
    int         next;

    if (!validateEndpoint(endpoint)) {
        return MPR_ERR_BAD_ARGS;
    }
    for (ITERATE_ITEMS(endpoint->hosts, host, next)) {
        httpStartHost(host);
    }
    if ((endpoint->sock = mprCreateSocket(endpoint->ssl)) == 0) {
        return MPR_ERR_MEMORY;
    }
    if (mprListenOnSocket(endpoint->sock, endpoint->ip, endpoint->port, MPR_SOCKET_NODELAY | MPR_SOCKET_THREAD) < 0) {
        mprError("Can't open a socket on %s:%d", *endpoint->ip ? endpoint->ip : "*", endpoint->port);
        return MPR_ERR_CANT_OPEN;
    }
    if (endpoint->http->listenCallback && (endpoint->http->listenCallback)(endpoint) < 0) {
        return MPR_ERR_CANT_OPEN;
    }
    if (endpoint->async && !endpoint->sock->handler) {
        mprAddSocketHandler(endpoint->sock, MPR_SOCKET_READABLE, endpoint->dispatcher, httpAcceptConn, endpoint, 
            (endpoint->dispatcher) ? 0 : MPR_WAIT_NEW_DISPATCHER);
    } else {
        mprSetSocketBlockingMode(endpoint->sock, 1);
    }
    proto = endpoint->ssl ? "HTTPS" : "HTTP ";
    ip = *endpoint->ip ? endpoint->ip : "*";
    if (mprIsSocketV6(endpoint->sock)) {
        mprLog(2, "Started %s service on \"[%s]:%d\"", proto, ip, endpoint->port);
    } else {
        mprLog(2, "Started %s service on \"%s:%d\"", proto, ip, endpoint->port);
    }
    return 0;
}
Exemplo n.º 3
0
/*
 *  Process incoming requests. This will process as many requests as possible before returning. All socket I/O is 
 *  non-blocking, and this routine must not block. 
 */
void maProcessReadEvent(MaConn *conn, MaPacket *packet)
{
    mprAssert(conn);

    conn->canProceed = 1;
    mprLog(conn, 7, "ENTER maProcessReadEvent state %d, packet %p", conn->state, packet);
    
    while (conn->canProceed) {
        mprLog(conn, 7, "maProcessReadEvent, state %d, packet %p", conn->state, packet);

        switch (conn->state) {
        case MPR_HTTP_STATE_BEGIN:
            conn->canProceed = parseRequest(conn, packet);
            break;

        case MPR_HTTP_STATE_CONTENT:
            conn->canProceed = processContent(conn, packet);
            packet = conn->input;
            break;

        case MPR_HTTP_STATE_PROCESSING:
            conn->canProceed = maServiceQueues(conn);
            break;

        case MPR_HTTP_STATE_COMPLETE:
            conn->canProceed = maProcessCompletion(conn);
            packet = conn->input;
            break;

        default:
            conn->keepAliveCount = 0;
            mprAssert(0);
            return;
        }
    }
    mprLog(conn, 7, "LEAVE maProcessReadEvent state %d, packet %p, dedicated %d", conn->state, packet, conn->dedicated);
}
Exemplo n.º 4
0
/*
    Write data. Return the number of bytes written or -1 on errors.
 */
static ssize writeOss(MprSocket *sp, cvoid *buf, ssize len)
{
    OpenSocket  *osp;
    ssize       totalWritten;
    int         error, rc;

    osp = (OpenSocket*) sp->sslSocket;

    if (osp->bio == 0 || osp->handle == 0 || len <= 0) {
        return MPR_ERR_BAD_STATE;
    }
    totalWritten = 0;
    ERR_clear_error();
    error = 0;

    do {
        rc = SSL_write(osp->handle, buf, (int) len);
        mprLog("info mpr ssl openssl", 7, "Wrote %d, requested len %zd", rc, len);
        if (rc <= 0) {
            error = SSL_get_error(osp->handle, rc);
            if (error == SSL_ERROR_WANT_WRITE) {
                break;
            }
            return MPR_ERR_CANT_WRITE;
        }
        totalWritten += rc;
        buf = (void*) ((char*) buf + rc);
        len -= rc;
        mprLog("info mpr ssl openssl", 7, "write len %zd, written %d, total %zd", len, rc, totalWritten);
    } while (len > 0);

    if (totalWritten == 0 && error == SSL_ERROR_WANT_WRITE) {
        mprSetError(EAGAIN);
        return MPR_ERR_NOT_READY;
    }
    return totalWritten;
}
Exemplo n.º 5
0
static int getBrowserPath(char **path, int max)
{
	mprAssert(path);

#if LINUX
	if (access("/usr/bin/htmlview", X_OK) == 0) {
		*path = mprStrdup("/usr/bin/htmlview");
		return 0;
	}
	if (access("/usr/bin/mozilla", X_OK) == 0) {
		*path = mprStrdup("/usr/bin/mozilla");
		return 0;
	}
	if (access("/usr/bin/konqueror", X_OK) == 0) {
		*path = mprStrdup("/usr/bin/knonqueror");
		return 0;
	}
	return MPR_ERR_CANT_ACCESS;

#endif
#if WIN
	char	cmd[MPR_MAX_STRING];
	char	*type;
	char	*cp;

	if (mprReadRegistry("HKEY_CLASSES_ROOT\\.htm", "", &type, 
			MPR_MAX_STRING) < 0) {
		return MPR_ERR_CANT_ACCESS;
	}

	mprSprintf(cmd, MPR_MAX_STRING,
		"HKEY_CLASSES_ROOT\\%s\\shell\\open\\command", type);
	mprFree(type);

	if (mprReadRegistry(cmd, "", path, max) < 0) {
		mprFree(cmd);
		return MPR_ERR_CANT_ACCESS;
	}

	for (cp = *path; *cp; cp++) {
		if (*cp == '\\') {
			*cp = '/';
		}
		*cp = tolower((uchar) *cp);
	}
#endif
	mprLog(4, "Browser path: %s\n", *path);
	return 0;
}
Exemplo n.º 6
0
/*
 *  Create an ejs application location block and alias
 */
static void createEjsAlias(Mpr *mpr, MaHttp *http, MaServer *server, cchar *ejsPrefix, cchar *ejsPath)
{
    MaAlias     *alias;
    MaHost      *host;
    MaDir       *dir, *parent;
    MaLocation  *location;
    int         flags;

    host = server->defaultHost;
    flags = host->location->flags & (MA_LOC_BROWSER | MA_LOC_AUTO_SESSION);

    alias = maCreateAlias(host, ejsPrefix, ejsPath, 0);
    maInsertAlias(host, alias);
    mprLog(http, 4, "Alias \"%s\" for \"%s\"", ejsPrefix, ejsPath);

    if (maLookupLocation(host, ejsPrefix)) {
        mprError(http, "Location block already exists for \"%s\"", ejsPrefix);
        return;
    }
    location = maCreateLocation(host, host->location);
    maSetLocationAuth(location, host->location->auth);
    maSetLocationPrefix(location, ejsPrefix);
    maAddLocation(host, location);
    maSetLocationFlags(location, MA_LOC_APP | flags);
    maSetHandler(http, host, location, "ejsHandler");

#if BLD_FEATURE_UPLOAD
    /*
        Upload configuration
     */
    location->autoDelete = 1;
    if (maAddFilter(http, location, "chunkFilter", "", MA_FILTER_INCOMING) < 0) {
        mprError(server, "Can't add chunkFilter for ejs");
    }
    if (maAddFilter(http, location, "uploadFilter", "", MA_FILTER_INCOMING) < 0) {
        mprError(server, "Can't add uploadFilter for ejs");
    }
#endif

    /*
     *  Make sure there is a directory for the alias target
     */
    dir = maLookupBestDir(host, ejsPath);
    if (dir == 0) {
        parent = mprGetFirstItem(host->dirs);
        dir = maCreateDir(host, alias->filename, parent);
        maInsertDir(host, dir);
    }
}
Exemplo n.º 7
0
int MaPhp4HandlerService::start()
{
	char					*serverRoot;
	void 					***tsrm_ls;
	php_core_globals 		*core_globals;
	sapi_globals_struct 	*sapi_globals;
	zend_llist				global_vars;
	zend_compiler_globals 	*compiler_globals;
	zend_executor_globals 	*executor_globals;

	tsrm_startup(128, 1, 0, 0);
	compiler_globals = (zend_compiler_globals*) 
		ts_resource(compiler_globals_id);
	executor_globals = (zend_executor_globals*) 
		ts_resource(executor_globals_id);
	core_globals = (php_core_globals*) ts_resource(core_globals_id);
	sapi_globals = (sapi_globals_struct*) ts_resource(sapi_globals_id);
	tsrm_ls = (void***) ts_resource(0);

	//
	//	Define the php.ini location to be the ServerRoot
	//
	serverRoot = MaServer::getDefaultServer()->getServerRoot();
	php4SapiBlock.php_ini_path_override = serverRoot;

	sapi_startup(&php4SapiBlock);

	if (php_module_startup(&php4SapiBlock, 0, 0) == FAILURE) {
		mprLog(0, log, "Can't startup PHP\n");
		return -1;
	}

	zend_llist_init(&global_vars, sizeof(char *), 0, 0);  

	//
	//	Set PHP defaults. As AppWeb buffers output, we don't want PHP
	//	to call flush.
	//
	SG(options) |= SAPI_OPTION_NO_CHDIR;
	zend_alter_ini_entry("register_argc_argv", 19, "0", 1, PHP_INI_SYSTEM, 
		PHP_INI_STAGE_ACTIVATE);
	zend_alter_ini_entry("html_errors", 12, "0", 1, PHP_INI_SYSTEM, 
		PHP_INI_STAGE_ACTIVATE);
	zend_alter_ini_entry("implicit_flush", 15, "0", 1, PHP_INI_SYSTEM, 
		PHP_INI_STAGE_ACTIVATE);
	zend_alter_ini_entry("max_execution_time", 19, "0", 1, PHP_INI_SYSTEM, 
		PHP_INI_STAGE_ACTIVATE);
	return 0;
}
Exemplo n.º 8
0
static bool okEscapeHtml(MprTestGroup *gp, char *html, char *expectedHtml)
{
    char    *escaped;

    escaped = mprEscapeHtml(gp, html);
    if (strcmp(expectedHtml, escaped) == 0) {
        mprFree(escaped);
        return 1;
    }
    mprLog(gp, 0, "HTML \"%s\" is escaped to be \n"
        "\"%s\" instead of \n"
        "\"%s\"\n", html, escaped, expectedHtml);
    mprFree(escaped);
    return 0;
}
Exemplo n.º 9
0
static bool okEscapeCmd(MprTestGroup *gp, char *cmd, char *validCmd)
{
    char    *escaped;

    escaped = mprEscapeCmd(gp, cmd, '\\');
    if (strcmp(validCmd, escaped) == 0) {
        mprFree(escaped);
        return 1;
    }
    mprLog(gp, 0, "Cmd \"%s\" is escaped to be \n"
        "\"%s\" instead of \n"
        "\"%s\"\n", cmd, escaped, validCmd);
    mprFree(escaped);
    return 0;
}
Exemplo n.º 10
0
static int sendRequest(HttpConn *conn, cchar *method, cchar *url, MprList *files)
{
    if (httpConnect(conn, method, url, app->ssl) < 0) {
        mprLog("error http", 0, "Cannot process request for \"%s\"\n%s", url, httpGetError(conn));
        return MPR_ERR_CANT_OPEN;
    }
    /*
        This program does not do full-duplex writes with reads. ie. if you have a request that sends and receives
        data in parallel -- http will do the writes first then read the response.
     */
    if (app->bodyData || app->formData || files) {
        if (app->chunkSize > 0) {
            httpSetChunkSize(conn, app->chunkSize);
        }
        if (writeBody(conn, files) < 0) {
            mprLog("error http", 0, "Cannot write body data to \"%s\". %s", url, httpGetError(conn));
            return MPR_ERR_CANT_WRITE;
        }
    }
    assert(!mprGetCurrentThread()->yielded);
    httpFinalizeOutput(conn);
    httpFlush(conn);
    return 0;
}
Exemplo n.º 11
0
PUBLIC int mprLoadNativeModule(MprModule *mp)
{
    MprModuleEntry  fn;
    void            *handle;

    assert(mp);

    if ((handle = (HANDLE) MPR->appInstance) == 0) {
        handle = GetModuleHandle(NULL);
    }
    if (!handle || !mp->entry || !GetProcAddress(handle, mp->entry)) {
#if ME_STATIC
        mprLog("error mpr", 0, "Cannot load module %s, product built static", mp->name);
        return MPR_ERR_BAD_STATE;
#else
        MprPath info;
        char    *at, *baseName;
        if ((at = mprSearchForModule(mp->path)) == 0) {
            mprLog("error mpr", 0, "Cannot find module \"%s\", cwd=\"%s\", search=\"%s\"", mp->path, mprGetCurrentPath(),
                mprGetModuleSearchPath());
            return MPR_ERR_CANT_ACCESS;
        }
        mp->path = at;
        mprGetPathInfo(mp->path, &info);
        mp->modified = info.mtime;
        baseName = mprGetPathBase(mp->path);
        mprLog("info mpr", 4, "Loading native module %s", baseName);
        if ((handle = LoadLibrary(wide(mp->path))) == 0) {
            mprLog("error mpr", 0, "Cannot load module %s, errno=\"%d\"", mp->path, mprGetOsError());
            return MPR_ERR_CANT_READ;
        }
        mp->handle = handle;
#endif /* !ME_STATIC */

    } else if (mp->entry) {
        mprLog("info mpr", 4, "Activating native module %s", mp->name);
    }
    if (mp->entry) {
        if ((fn = (MprModuleEntry) GetProcAddress((HINSTANCE) handle, mp->entry)) == 0) {
            mprLog("error mpr", 0, "Cannot load module %s, cannot find function \"%s\"", mp->name, mp->entry);
            FreeLibrary((HINSTANCE) handle);
            return MPR_ERR_CANT_ACCESS;
        }
        if ((fn)(mp->moduleData, mp) < 0) {
            mprLog("error mpr", 0, "Initialization for module %s failed", mp->name);
            FreeLibrary((HINSTANCE) handle);
            return MPR_ERR_CANT_INITIALIZE;
        }
    }
    return 0;
}
Exemplo n.º 12
0
PUBLIC int httpSetAuthType(HttpAuth *auth, cchar *type, cchar *details)
{
    if (type == 0 || *type == '\0' || smatch(type, "none")) {
        auth->type = 0;
        return 0;
    }
    if ((auth->type = mprLookupKey(HTTP->authTypes, type)) == 0) {
        mprLog("critical http auth", 0, "Cannot find auth type %s", type);
        return MPR_ERR_CANT_FIND;
    }
    if (!auth->store) {
        httpSetAuthStore(auth, "config");
    }
    return 0;
}
Exemplo n.º 13
0
int maStartAppweb(MaAppweb *appweb)
{
    MaServer    *server;
    char        *timeText;
    int         next;

    for (next = 0; (server = mprGetNextItem(appweb->servers, &next)) != 0; ) {
        if (maStartServer(server) < 0) {
            return MPR_ERR_CANT_INITIALIZE;
        }
    }
    timeText = mprGetDate(0);
    mprLog(1, "HTTP services Started at %s with max %d threads", timeText, mprGetMaxWorkers(appweb));
    return 0;
}
Exemplo n.º 14
0
int maStartServer(MaServer *server)
{
    MaHost      *host;
    MaListen    *listen;
    int         next, count, warned;

    /*
     *  Start the hosts
     */
    for (next = 0; (host = mprGetNextItem(server->hosts, &next)) != 0; ) {
        mprLog(server, 1, "Starting host named: \"%s\"", host->name);
        if (maStartHost(host) < 0) {
            return MPR_ERR_CANT_INITIALIZE;
        }
    }

    /*
     *  Listen to all required ipAddr:ports
     */
    warned = 0;
    count = 0;
    for (next = 0; (listen = mprGetNextItem(server->listens, &next)) != 0; ) {
        if (maStartListening(listen) < 0) {
            mprError(server, "Can't listen for HTTP on %s:%d", listen->ipAddr, listen->port);
            warned++;
            break;

        } else {
            count++;
        }
    }

    if (count == 0) {
        if (! warned) {
            mprError(server, "Server is not listening on any addresses");
        }
        return MPR_ERR_CANT_OPEN;
    }

    /*
     *  Now change user and group to the desired identities (user must be last)
     */
    if (maApplyChangedGroup(server->http) < 0 || maApplyChangedUser(server->http) < 0) {
        return MPR_ERR_CANT_COMPLETE;
    }

    return 0;
}
Exemplo n.º 15
0
int MprTimer::stop(int timeout)
{
	MprTimerService	*ts;
	int				rc;

	ts = timerService;
	ts->lock();

	mprLog(5, ts->log, "%x: MprTimer stop, inUse %d\n", this, inUse);
	if (getList()) {
		ts->timerList.remove(this);
		mprAssert(!(flags & MPR_TIMER_RUNNING));
		ts->unlock();
		return 1;
	}

	inUse++;

#if BLD_FEATURE_MULTITHREAD
	//
	//	The timer is running -- just wait for it to complete. Increment inUse
	//	so it doen't get deleted from underneath us.
	//
	while (timeout > 0 && (flags & MPR_TIMER_RUNNING)) {
		int start;
		if (stoppingCond == 0) {
			stoppingCond = new MprCond();
		}
		start = mprGetTime(0);
		ts->unlock();
		stoppingCond->waitForCond(timeout);
		ts->lock();
		timeout -= mprGetTime(0) - start;
	}

	if (stoppingCond) {
		delete stoppingCond;
		stoppingCond = 0;
	}
#endif

	if (--inUse == 0 && flags & MPR_TIMER_DISPOSED) {
		delete this;
	}
	rc = (flags & MPR_TIMER_RUNNING) ? -1 : 0;
	ts->unlock();
	return rc;
}
Exemplo n.º 16
0
void MprLogService::setDefaultLevel(int l)
{
	MprLogModule	*mp;
	
	defaultLevel = l;
	if (defaultLevel < 0) {
		defaultLevel = 0;
	}

	mp = (MprLogModule*) moduleList.getFirst();
	while (mp) {
		mp->setLevel(defaultLevel);
		mp = (MprLogModule*) moduleList.getNext(mp);
	}
	mprLog(2, "Set log level for all modules to %d\n", defaultLevel);
}
Exemplo n.º 17
0
static int writeBlock(cchar *str, uint len TSRMLS_DC)
{
    MaConn      *conn;
    int         written;

    conn = (MaConn*) SG(server_context);
    if (conn == 0) {
        return -1;
    }
    written = maWriteBlock(conn->response->queue[MA_QUEUE_SEND].nextQ, str, len, 1);
    mprLog(mprGetMpr(0), 6, "php: write %d", written);
    if (written <= 0) {
        php_handle_aborted_connection();
    }
    return written;
}
Exemplo n.º 18
0
void MprCmd::stop()
{
	mprLog(7, log, "stop\n");

	lock();
	//
	//	Ensure there are no callbacks from here on
	//
	cmdDoneProc = 0;

	if (process > 0) {
		TerminateProcess((HANDLE) process, 2);
		process = 0;
	}
	unlock();
}
Exemplo n.º 19
0
PUBLIC int mprUnloadModule(MprModule *mp)
{
    mprDebug("mpr", 5, "Unloading native module %s from %s", mp->name, mp->path);
    if (mprStopModule(mp) < 0) {
        return MPR_ERR_NOT_READY;
    }
#if ME_COMPILER_HAS_DYN_LOAD
    if (mp->flags & MPR_MODULE_LOADED) {
        if (mprUnloadNativeModule(mp) != 0) {
            mprLog("error mpr", 0, "Cannot unload module %s", mp->name);
        }
    }
#endif
    mprRemoveItem(MPR->moduleService->modules, mp);
    return 0;
}
Exemplo n.º 20
0
static int writeBlock(cchar *str, uint len TSRMLS_DC)
{
    HttpConn    *conn;
    ssize       written;

    conn = (HttpConn*) SG(server_context);
    if (conn == 0) {
        return -1;
    }
    written = httpWriteBlock(conn->tx->queue[HTTP_QUEUE_TX]->nextQ, str, len, HTTP_BLOCK);
    mprLog(6, "php: write %d", written);
    if (written <= 0) {
        php_handle_aborted_connection();
    }
    return (int) written;
}
Exemplo n.º 21
0
Ejs *ejsCreateVM(int argc, cchar **argv, int flags)
{
    EjsService  *sp;
    Ejs         *ejs;

    if ((ejs = mprAllocObj(Ejs, manageEjs)) == NULL) {
        return 0;
    }
    sp = ejs->service = MPR->ejsService;
    if (sp == 0) {
        sp = ejs->service = createService();
        defineSharedTypes(ejs);
    }
    ejs->empty = 1;
    ejs->state = mprAllocZeroed(sizeof(EjsState));
    ejs->argc = argc;
    ejs->argv = argv;
    ejs->name = sfmt("ejs-%d", sp->seqno++);
    ejs->dispatcher = mprCreateDispatcher(ejs->name, MPR_DISPATCHER_ENABLED);
    ejs->mutex = mprCreateLock(ejs);
    ejs->dontExit = sp->dontExit;
    ejs->flags |= (flags & (EJS_FLAG_NO_INIT | EJS_FLAG_DOC | EJS_FLAG_HOSTED));
    ejs->hosted = (flags & EJS_FLAG_HOSTED) ? 1 : 0;

    ejs->global = ejsCreateBlock(ejs, 0);
    mprSetName(ejs->global, "global");
    ejsDefineGlobalNamespaces(ejs);

    /*
        Modules are not marked in the modules list. This way, modules are collected when not referenced.
        Workers are marked. This way workers are preserved to run in the background until they exit.
     */
    ejs->modules = mprCreateList(-1, MPR_LIST_STATIC_VALUES);
    ejs->workers = mprCreateList(0, 0);

    initStack(ejs);
    initSearchPath(ejs, 0);
    mprAddItem(sp->vmlist, ejs);

    if (ejs->hasError || mprHasMemError(ejs)) {
        ejsDestroyVM(ejs);
        mprError("Cannot create VM");
        return 0;
    }
    mprLog(5, "ejs: create VM");
    return ejs;
}
Exemplo n.º 22
0
Arquivo: buf.cpp Projeto: OPSF/uClinux
int MprBuf::putFmt(char *fmt, ...)
{
	va_list		vargs;
	char		buf[MPR_MAX_STRING];
	int			len;
	
	va_start(vargs, fmt);

	len = mprVsprintf(buf, MPR_MAX_STRING, fmt, vargs);
	if (len >= MPR_MAX_STRING) {
		mprLog(MPR_VERBOSE, " putFmt buffer overflow\n");
		va_end(vargs);
		return 0;
	}
	va_end(vargs);
	return put((uchar*) buf, len);
}
Exemplo n.º 23
0
/*  
    Set the home directory (Server Root). We convert path into an absolute path.
 */
void maSetServerHome(MaServer *server, cchar *path)
{
    if (path == 0 || BLD_FEATURE_ROMFS) {
        path = ".";
    }
#if !VXWORKS
    /*
        VxWorks stat() is broken if using a network FTP server.
     */
    if (! mprPathExists(path, R_OK)) {
        mprError("Can't access ServerRoot directory %s", path);
        return;
    }
#endif
    server->home = mprGetAbsPath(path);
    mprLog(MPR_CONFIG, "Set server root to: \"%s\"", server->home);
}
Exemplo n.º 24
0
int MprCmd::dispose()
{
    lock();
    mprAssert(inUse > 0);
    mprAssert(!(flags & MPR_CMD_DISPOSED));

    mprLog(8, log, "dispose: process %d\n", process);
    flags |= MPR_CMD_DISPOSED;

    if (--inUse == 0) {
        delete this;
        return 1;
    } else {
        unlock();
    }
    return 0;
}
Exemplo n.º 25
0
int mprUnloadModule(MprModule *mp)
{
    mprLog(6, "Unloading native module %s from %s", mp->name, mp->path);
    if (mprStopModule(mp) < 0) {
        return MPR_ERR_NOT_READY;
    }
#if BIT_HAS_DYN_LOAD
    if (mp->handle) {
        if (mprUnloadNativeModule(mp) != 0) {
            mprError("Can't unload module %s", mp->name);
        }
        mp->handle = 0;
    }
#endif
    mprRemoveItem(MPR->moduleService->modules, mp);
    return 0;
}
Exemplo n.º 26
0
MprModule *mprLoadModule(MprCtx ctx, cchar *moduleName, cchar *initFunction)
{
    MprModule       *mp;
    MprModuleEntry  fn;
    char            *module;
    char            *path, *name;
    void            *handle;

    mprAssert(moduleName && *moduleName);

    mp = 0;
    name = path = 0;
    module = mprGetNormalizedPath(ctx, moduleName);

    if (mprSearchForModule(ctx, module, &path) < 0) {
        mprError(ctx, "Can't find module \"%s\" in search path \"%s\"", moduleName, mprGetModuleSearchPath(ctx));

    } else {
        name = mprGetPathBase(ctx, module);
        mprLog(ctx, MPR_INFO, "Loading module %s from %s", name, path);

        if ((handle = GetModuleHandle(name)) == 0 && (handle = LoadLibrary(path)) == 0) {
            mprError(ctx, "Can't load module %s\nReason: \"%d\"\n",  path, mprGetOsError());

        } else if (initFunction) {
            if ((fn = (MprModuleEntry) GetProcAddress((HINSTANCE) handle, initFunction)) != 0) {
                if ((mp = (fn)(ctx, path)) == 0) {
                    mprError(ctx, "Initialization for module %s failed", name);
                    FreeLibrary((HINSTANCE) handle);

                } else {
                    mp->handle = handle;
                }

            } else {
                mprError(ctx, "Can't load module %s\nReason: can't find function \"%s\"\n",  name, initFunction);
                FreeLibrary((HINSTANCE) handle);

            }
        }
    }
    mprFree(name);
    mprFree(path);
    mprFree(module);
    return mp;
}
Exemplo n.º 27
0
/*
    Start the user's default browser
 */
static int runBrowser(char *page)
{
    PROCESS_INFORMATION procInfo;
    STARTUPINFO         startInfo;
    char                cmdBuf[MPR_MAX_STRING];
    char                *path;
    char                *pathArg;
    int                 port;

    port = getAppwebPort();
    if (port < 0) {
        mprError("Can't get Appweb listening port");
        return -1;
    }
    path = getBrowserPath(MPR_MAX_STRING);
    if (path == 0) {
        mprError("Can't get browser startup command");
        return -1;
    }
    pathArg = strstr(path, "\"%1\"");
    if (*page == '/') {
        page++;
    }
    if (pathArg == 0) {
        mprSprintf(cmdBuf, MPR_MAX_STRING, "%s http://localhost:%d/%s", path, port, page);

    } else {
        /*
            Patch out the "%1"
         */
        *pathArg = '\0';
        mprSprintf(cmdBuf, MPR_MAX_STRING, "%s \"http://localhost:%d/%s\"", path, port, page);
    }

    mprLog(4, "Running %s\n", cmdBuf);
    memset(&startInfo, 0, sizeof(startInfo));
    startInfo.cb = sizeof(startInfo);

    if (! CreateProcess(0, cmdBuf, 0, 0, FALSE, 0, 0, 0, &startInfo, &procInfo)) {
        mprError("Can't create process: %s, %d", cmdBuf, mprGetOsError());
        return -1;
    }
    CloseHandle(procInfo.hProcess);
    return 0;
}
Exemplo n.º 28
0
static void readEventWrapper(void *data, MprSocket *sp, int mask, 
	int isPoolThread)
{
	MaClient	*cp;
	int			moreData, loopCount;

	mprLog(5, "%d: readEventWrapper: mask %x, isPool %d\n", 
		sp->getFd(), mask, isPoolThread);

	//
	//	Make sure we are not being deleted
	//
	mprGetMpr()->lock();
	cp = (MaClient*) clients.getFirst();
	while (cp) {
		if (cp == (MaClient*) data) {
			break;
		}
		cp = (MaClient*) clients.getNext(cp);
	}

	if (cp == 0) {
		mprError(MPR_L, MPR_LOG, "Client deleted prematurely.");
		return;
	}
	cp->lock();
	mprGetMpr()->unlock();

	//
	//	If we are multi-threaded and called on a pool thread, we can block and
	//	read as much data as we can. If single threaded, just do 25 reads.
	//
	loopCount = 25;
	do {
		moreData = cp->readEvent();

		if (cp->getState() == MPR_HTTP_CLIENT_DONE) {
			cp->signalComplete();
			break;
		}

	} while (moreData > 0 && (isPoolThread || loopCount-- > 0));

	cp->unlock();
}
Exemplo n.º 29
0
static void readyCacheHandler(HttpQueue *q) 
{
    HttpConn    *conn;
    HttpTx      *tx;
    cchar       *data;

    conn = q->conn;
    tx = conn->tx;

    if (tx->cachedContent) {
        mprLog(3, "cacheHandler: write cached content for '%s'", conn->rx->uri);
        if ((data = setHeadersFromCache(conn, tx->cachedContent)) != 0) {
            tx->length = slen(data);
            httpWriteString(q, data);
        }
    }
    httpFinalize(conn);
}
Exemplo n.º 30
0
int maApplyChangedGroup(MaAppweb *appweb)
{
#if BLD_UNIX_LIKE
    if (appweb->groupChanged && appweb->gid >= 0) {
        if (setgid(appweb->gid) != 0) {
            mprError("Can't change group to %s: %d\n"
                "WARNING: This is a major security exposure", appweb->group, appweb->gid);
            return MPR_ERR_BAD_STATE;
#if LINUX && PR_SET_DUMPABLE
        } else {
            prctl(PR_SET_DUMPABLE, 1);
#endif
        }
        mprLog(MPR_CONFIG, "Changing group ID to %s: %d", appweb->group, appweb->gid);
    }
#endif
    return 0;
}