Ejemplo n.º 1
0
/*----------------------------------------------------------------------------*/
void video_filter_insert(my1video_t *video, my1vpass_t *vpass)
{
	my1vpass_t* ptask;
	while (vpass)
	{
		/* link buffer and parent */
		vpass->buffer = &video->vbuff;
		/* keep a copy to insert */
		ptask = vpass;
		vpass = vpass->next;
		/* insert video filter */
		video->ppass = filter_insert(video->ppass,ptask);
	}
}
SYS_NETFD filter_create_stack(Session *sn)
{
    // The bottom layer of the stack will be a "null" NSPR IO layer that
    // doesn't actually do anything
    PRFileDesc *fd = filter_alloc_null_iolayer(sn, &_filter_null_priomethods);
    if (!fd)
        return SYS_NET_ERRORFD;

    fd->higher = NULL;
    fd->lower = NULL;

    // Add a callback filter to the top of the stack
    if (sn)
        filter_insert(fd, NULL, sn, NULL, NULL, _filter_callback);

    return fd;
}
NSAPI_PUBLIC int filter_insert(SYS_NETFD fd, pblock *pb, Session *sn, Request *rq, void *data, const Filter *filter)
{
    // Use session's csd if caller didn't specify an fd
    if (!fd && sn && sn->csd_open == 1)
        fd = sn->csd;

    if (!fd || !filter)
        return REQ_NOACTION;

    PR_ASSERT((void *)filter == (void *)&filter->priomethods);

    // Check Request-based filter preconditions
    if (rq) {
        // Request-based filters must be associated with a session
        if (rq && !sn) {
            NsprError::setError(PR_INVALID_ARGUMENT_ERROR, XP_GetAdminStr(DBT_MissingSession));
            return REQ_ABORTED;
        }

        // Don't insert FILTER_CONTENT_CODING and lower filters on child
        // requests
        if (INTERNAL_REQUEST(rq) && filter->order < FILTER_SUBREQUEST_BOUNDARY)
            return REQ_NOACTION;
    }

    // Check for a NativeThread="yes" filter running on a local thread 
    if (filter->flags & FILTER_USE_NATIVE_THREAD) {
        if (!_filter_logged_native_thread_issue) {
            // XXX this is inefficient
            if (PR_GetThreadScope(PR_GetCurrentThread()) == PR_LOCAL_THREAD) {
                _filter_logged_native_thread_issue = PR_TRUE;
                log_error(LOG_MISCONFIG, "filter-insert", sn, rq, XP_GetAdminStr(DBT_FilterXRequiresNativeThreads), filter->name);
            }
        }
    }

    // Find where the filter belongs in the filter stack
    PRFileDesc *bottom = NULL;
    PRFileDesc *unknown = NULL;
    PRFileDesc *position;
    for (position = fd; position; position = position->lower) {
        // Find a layer we can determine the order of
        int order = filter_iolayer_order(position);
        if (order < 0) {
            if (!unknown)
                unknown = position;

            continue;
        }

        // Does the new layer belong above this layer?
        if (filter->order >= order) {
            // If there are non-filter IO layers directly above this layer,
            // the filter belongs above them
            if (unknown)
                position = unknown;

            break;
        }

        unknown = NULL;

        // This may be the bottom-most layer with a known order
        bottom = position;
    }
    if (!position) {
        if (!bottom) {
            // We're the first layer, we go on top
            position = fd;
        } else if (bottom->lower) {
            // Insert below the lowest layer with a known order
            position = bottom->lower;
        } else {
            // Nowhere to install the filter
            NsprError::setError(PR_INVALID_ARGUMENT_ERROR, XP_GetAdminStr(DBT_InvalidFilterStack));
            return REQ_ABORTED;
        }
    }

    // Get an IO layer for the filter
    PRFileDesc *iolayer = filter_alloc_filter_iolayer(sn, filter);
    if (!iolayer)
        return REQ_ABORTED;

    // Initialize filter layer context
    FilterContext *context = filter_create_context(sn, rq, data, filter, (FilterLayer *)iolayer);
    if (!context) {
        // Dispose of the IO layer
        filter_free_iolayer(sn, iolayer);

        return REQ_ABORTED;
    }

    // Install the filter's IO layer
    if (filter_insert_iolayer(position, &iolayer) != REQ_PROCEED) {
        // Destroy the filter's context
        filter_destroy_context((FilterLayer *)iolayer);

        // Dispose of the IO layer
        filter_free_iolayer(sn, iolayer);

        return REQ_ABORTED;
    }
    PR_ASSERT(iolayer->methods == &filter->priomethods);

    // Give the filter a chance to initialize
    int rv = filter->insert((FilterLayer *)iolayer, pb ? pb : _empty_pb);
    if (rv != REQ_PROCEED) {
        // Destroy the filter's context
        filter_destroy_context((FilterLayer *)iolayer);

        // Remove the IO layer from the stack
        iolayer = filter_extract_iolayer(iolayer);

        // Dispose of the IO layer
        filter_free_iolayer(sn, iolayer);

        return rv;
    }

    // Let the NSAPIRequest know it needs to clean up after a filter
    if (rq) {
        NSAPIRequest *nrq = (NSAPIRequest *)rq;
        NSAPISession *nsn = (NSAPISession *)sn;
        PR_ASSERT(nrq->filter_sn == NULL || nrq->filter_sn == sn);
        nrq->filter_sn = sn;
    }

    // If the new filter doesn't call the callbacks...
    if (!(filter->flags & FILTER_CALLS_CALLBACKS)) {
        // If the new filter was added to the top of the stack...
        if (position == fd && position->lower && position->lower->identity == _filter_identity) {
            // If the new filter is masking a filter that does call the
            // callbacks (i.e. httpfilter)...
            FilterLayer *lower = (FilterLayer *)position->lower;
            if (lower->filter->flags & FILTER_CALLS_CALLBACKS) {
                // Add a callback filter to the top of the stack
                filter_insert(fd, NULL, lower->context->sn, NULL, NULL, _filter_callback);
            }
        }
    }

    return rv;
}
Ejemplo n.º 4
0
qboolean G_FilterString(char *str, char **words, int numWords, char *customWords, int numCustomWords)
{
    int      i, j, len, fidx, sidx;
    char     *filtered;
    qboolean res = qfalse;
    char     lastchar;

    lastchar = ' ';
    for (j = 0; str[j] != '\0'; j++)
    {
        for (i = 0; i < numWords; i++)
        {
            fidx = i * 2;
            sidx = i * 2 + 1;
            len  = strlen(words[fidx]);
            if (words[sidx] == NULL)
            {
                if (filter_cmpgood(&str[j], words[fidx]))
                {
                    j += len - 1;
                }
            }
            else
            {
                if (filter_cmp(&str[j], words[fidx], !filter_isletter(lastchar)))
                {
                    len = filter_insert(&str[j], words[sidx]);
                    res = qtrue;
                    j  += len - 1;
                }
            }
        }
        lastchar = str[j];
    }

    if (customWords[0])
    {
        lastchar = ' ';
        for (j = 0; str[j] != '\0'; j++)
        {
            filtered = customWords;
            for (i = 0; i < numCustomWords; i++)
            {
                len = strlen(filtered);
                if (filter_cmp(&str[j], filtered, !filter_isletter(lastchar)))
                {
                    len = filter_blank(&str[j], len);
                    res = qtrue;
                    j  += len - 1;
                }

                while (*filtered != '\0')
                {
                    filtered++;
                }

                filtered++;
            }
            lastchar = str[j];
        }
    }

    return res;
}