Search in sources :

Example 1 with Debuggee

use of org.exist.debuggee.Debuggee in project exist by eXist-db.

the class ContextGet method eval.

@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
    try {
        Debuggee dbgr = BrokerPool.getInstance().getDebuggee();
        IoSession session = (IoSession) dbgr.getSession(args[0].getStringValue());
        if (session == null)
            return StringValue.EMPTY_STRING;
        Command command = new org.exist.debuggee.dbgp.packets.ContextGet(session, "");
        command.exec();
        return Utils.nodeFromString(getContext(), new String(command.responseBytes()));
    } catch (Throwable e) {
        throw new XPathException(this, Module.DEBUG001, e);
    }
}
Also used : Debuggee(org.exist.debuggee.Debuggee) Command(org.exist.debuggee.dbgp.packets.Command) XPathException(org.exist.xquery.XPathException) IoSession(org.apache.mina.core.session.IoSession)

Example 2 with Debuggee

use of org.exist.debuggee.Debuggee in project exist by eXist-db.

the class Stop method eval.

@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
    try {
        Debuggee dbgr = BrokerPool.getInstance().getDebuggee();
        IoSession session = (IoSession) dbgr.getSession(args[0].getStringValue());
        if (session == null)
            return BooleanValue.FALSE;
        Command command = new org.exist.debuggee.dbgp.packets.Stop(session, "");
        command.exec();
        return BooleanValue.TRUE;
    } catch (Throwable e) {
        throw new XPathException(this, Module.DEBUG001, e);
    }
}
Also used : Debuggee(org.exist.debuggee.Debuggee) Command(org.exist.debuggee.dbgp.packets.Command) XPathException(org.exist.xquery.XPathException) IoSession(org.apache.mina.core.session.IoSession)

Example 3 with Debuggee

use of org.exist.debuggee.Debuggee in project exist by eXist-db.

the class Run method eval.

@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
    try {
        Debuggee dbgr = BrokerPool.getInstance().getDebuggee();
        IoSession session = (IoSession) dbgr.getSession(args[0].getStringValue());
        if (session == null)
            return BooleanValue.FALSE;
        Command command = new org.exist.debuggee.dbgp.packets.Run(session, "");
        command.exec();
        return BooleanValue.TRUE;
    } catch (Throwable e) {
        throw new XPathException(this, Module.DEBUG001, e);
    }
}
Also used : Debuggee(org.exist.debuggee.Debuggee) Command(org.exist.debuggee.dbgp.packets.Command) XPathException(org.exist.xquery.XPathException) IoSession(org.apache.mina.core.session.IoSession)

Example 4 with Debuggee

use of org.exist.debuggee.Debuggee in project exist by eXist-db.

the class StepOut method eval.

@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
    try {
        Debuggee dbgr = BrokerPool.getInstance().getDebuggee();
        IoSession session = (IoSession) dbgr.getSession(args[0].getStringValue());
        if (session == null)
            return BooleanValue.FALSE;
        Command command = new org.exist.debuggee.dbgp.packets.StepOut(session, "");
        command.exec();
        return BooleanValue.TRUE;
    } catch (Throwable e) {
        throw new XPathException(this, Module.DEBUG001, e);
    }
}
Also used : Debuggee(org.exist.debuggee.Debuggee) Command(org.exist.debuggee.dbgp.packets.Command) XPathException(org.exist.xquery.XPathException) IoSession(org.apache.mina.core.session.IoSession)

Example 5 with Debuggee

use of org.exist.debuggee.Debuggee in project exist by eXist-db.

the class XQuery method execute.

public Sequence execute(final DBBroker broker, final CompiledXQuery expression, Sequence contextSequence, final Properties outputProperties, final boolean resetContext) throws XPathException, PermissionDeniedException {
    // check execute permissions
    if (expression.getContext().getSource() instanceof DBSource) {
        ((DBSource) expression.getContext().getSource()).validate(Permission.EXECUTE);
    }
    final long start = System.currentTimeMillis();
    final XQueryContext context = expression.getContext();
    expression.reset();
    if (resetContext) {
        // context.setBroker(broker);
        context.getWatchDog().reset();
    }
    if (context.requireDebugMode()) {
        final Debuggee debuggee = broker.getBrokerPool().getDebuggee();
        if (debuggee != null) {
            debuggee.joint(expression);
        }
    }
    // do any preparation before execution
    context.prepareForExecution();
    final Subject callingUser = broker.getCurrentSubject();
    // if setUid or setGid, become Effective User
    EffectiveSubject effectiveSubject = null;
    final Source src = expression.getContext().getSource();
    if (src instanceof DBSource) {
        final DBSource dbSrc = (DBSource) src;
        final Permission perm = dbSrc.getPermissions();
        if (perm.isSetUid()) {
            if (perm.isSetGid()) {
                // setUid and SetGid
                effectiveSubject = new EffectiveSubject(perm.getOwner(), perm.getGroup());
            } else {
                // just setUid
                effectiveSubject = new EffectiveSubject(perm.getOwner());
            }
        } else if (perm.isSetGid()) {
            // just setGid, so we use the current user as the effective user
            effectiveSubject = new EffectiveSubject(callingUser, perm.getGroup());
        }
    }
    try {
        if (effectiveSubject != null) {
            // switch to effective user (e.g. setuid/setgid)
            broker.pushSubject(effectiveSubject);
        }
        context.getProfiler().traceQueryStart();
        broker.getBrokerPool().getProcessMonitor().queryStarted(context.getWatchDog());
        try {
            // support for XQuery 3.0 - declare context item :=
            if (contextSequence == null) {
                if (context.getContextItemDeclartion() != null) {
                    contextSequence = context.getContextItemDeclartion().eval(null, null);
                }
            }
            final Sequence result = expression.eval(contextSequence);
            if (LOG.isDebugEnabled()) {
                final NumberFormat nf = NumberFormat.getNumberInstance();
                LOG.debug("Execution took {} ms", nf.format(System.currentTimeMillis() - start));
            }
            if (outputProperties != null) {
                // must be done before context.reset!
                context.checkOptions(outputProperties);
            }
            return result;
        } finally {
            context.getProfiler().traceQueryEnd(context);
            // track query stats before context is reset
            broker.getBrokerPool().getProcessMonitor().queryCompleted(context.getWatchDog());
            expression.reset();
            if (resetContext) {
                context.reset();
            }
        }
    } finally {
        if (effectiveSubject != null) {
            broker.popSubject();
        }
    }
}
Also used : EffectiveSubject(org.exist.security.EffectiveSubject) Debuggee(org.exist.debuggee.Debuggee) Permission(org.exist.security.Permission) DBSource(org.exist.source.DBSource) Sequence(org.exist.xquery.value.Sequence) Subject(org.exist.security.Subject) EffectiveSubject(org.exist.security.EffectiveSubject) StringSource(org.exist.source.StringSource) Source(org.exist.source.Source) DBSource(org.exist.source.DBSource) FileSource(org.exist.source.FileSource) NumberFormat(java.text.NumberFormat)

Aggregations

Debuggee (org.exist.debuggee.Debuggee)11 IoSession (org.apache.mina.core.session.IoSession)10 Command (org.exist.debuggee.dbgp.packets.Command)10 XPathException (org.exist.xquery.XPathException)10 NumberFormat (java.text.NumberFormat)1 EffectiveSubject (org.exist.security.EffectiveSubject)1 Permission (org.exist.security.Permission)1 Subject (org.exist.security.Subject)1 DBSource (org.exist.source.DBSource)1 FileSource (org.exist.source.FileSource)1 Source (org.exist.source.Source)1 StringSource (org.exist.source.StringSource)1 Sequence (org.exist.xquery.value.Sequence)1