Пример #1
0
/* merge the left and  right with NOT rule */
HLIST notmerge(HLIST left, HLIST right, int *ignore)
{
    int i, j, v, f;

    if (*ignore && left.n > 0)
	return left;
    if (*ignore && right.n > 0)
	return right;

    if (right.n <= 0)
	return left;
    if (left.n <= 0)
	return left;

    for (v = 0, i = 0, j = 0; i < left.n; i++) {
	for (f = 0; j < right.n; j++) {
	    if (left.fid[i] < right.fid[j])
		break;
	    if (left.fid[i] == right.fid[j]) {
		j++;
		f = 1;
		break;
	    }
	}
	if (!f) {
	    copy_hlist(left, v, left, i);
	    v++;
	}
    }
    free_hlist(right);
    left.n = v;
    if (left.n <= 0)
	free_hlist(left);
    return left;
}
Пример #2
0
/*
 * merge the left and  right with OR rule
 */
HLIST ormerge(HLIST left, HLIST right)
{
    int i, j, v, n;
    HLIST val;

    if (left.n <= 0 && right.n <= 0)
	return left;
    if (left.n <= 0)
	return right;
    if (right.n <= 0)
	return left;

    n = left.n + right.n;

    malloc_hlist(&val, n);

    for (v = 0, i = 0, j = 0; i < left.n; i++) {
	for (; left.fid[i] >= right.fid[j] && j < right.n; j++) {
	    if (left.fid[i] == right.fid[j]) {

                if (TfIdf) {
                    left.scr[i] = left.scr[i] + right.scr[j];
                } else {
                    /* assign a large number, left or right */
                    left.scr[i] = left.scr[i] > right.scr[j] ?
                        left.scr[i] : right.scr[j];
                }
		j++;
		break;
	    } else {
		copy_hlist(val, v, right, j);
		v++;
	    }
	}
	copy_hlist(val, v, left, i);
	v++;
    }

    for (; j < right.n; j++) {
	copy_hlist(val, v, right, j);
	v++;
    }

    free_hlist(left);
    free_hlist(right);
    val.n = v;
    return val;
}
Пример #3
0
void copy_and_clean_results(result_t *results, int result_count, char copy)
{
static result_t old_results[MAX_RESULTS];
static int old_result_count = 0;

if (copy) {
    int i;
    for (i = 0; i < old_result_count; ++i) {
        int j;
        char found = 0;
        for (j = 0; j < result_count; ++j) {
            if (results[j].pid.pid == old_results[i].pid.pid) {
                found = 1;
                results[j].hbegin = old_results[i].hbegin;
                results[j].hend = old_results[i].hend;
                results[j].hsize = old_results[i].hsize;
                break;
            }
        }
        if (!found)
            free_hlist(old_results[i].hbegin);
    }
}
else {
    memcpy(old_results, results, sizeof(old_results));
    old_result_count = result_count;
  }
}
Пример #4
0
/* merge the left and  right with AND rule */
HLIST andmerge(HLIST left, HLIST right, int *ignore)
{
    int i, j, v;

    if (*ignore && left.n > 0)
	return left;
    if (*ignore && right.n > 0)
	return right;

    if (left.n <= 0)
	return left;
    if (right.n <= 0)
	return right;

    for (v = 0, i = 0, j = 0; i < left.n; i++) {
	for (;; j++) {
	    if (j >= right.n)
		goto OUT;
	    if (left.fid[i] < right.fid[j])
		break;
	    if (left.fid[i] == right.fid[j]) {

		copy_hlist(left, v, left, i);
                if (TfIdf) {
                    left.scr[v] = left.scr[i] + right.scr[j];
                } else {
                    /* assign a smaller number, left or right*/
                    left.scr[v] = left.scr[i] < right.scr[j] ?
                        left.scr[i] : right.scr[j];
                }
		v++;
		j++;
		break;
	    }
	}
    }
  OUT:
    free_hlist(right);
    left.n = v;
    if (left.n <= 0)
	free_hlist(left);
    return left;
}
Пример #5
0
HLIST merge_hlist(HLIST *hlists)
{
    int i, n;
    HLIST value;

    if (DbNumber == 1) return hlists[0];
    for(i = n = 0; i < DbNumber; i++) {
        if (hlists[i].n > 0) {
            n += hlists[i].n;
        }
    }
    malloc_hlist(&value, n);
    for(i = n = 0; i < DbNumber; i++) {
        if (hlists[i].n <= 0) 
            continue;
        memcpy_hlist(value, hlists[i], n);
        n += hlists[i].n;
        free_hlist(hlists[i]);
    }
    value.n = n;
    return value;
}
Пример #6
0
/*
 * Check header permissions.
 * Does newsgroup checks if ReadPat is specified
 * Does Retention check if retention > 0
 */
static int check_headperm(char *msgid)
{
        char    *ng;
        time_t  msgdate;
        HLIST   *hdr = NULL, *allhdrs = NULL;
        char    header[MAX_HEADER];
        char    value[MAX_HEADER];
        char    *hval;
        CLEARBUF

        if ( cfg.LocalDreader == 1 && 
             strcmp(client->user->readpat, "all") == 0 && 
             client->profile->Retention == 0)
                return CHECK_ARTICLE_OK;

        if ( writeserver(client, "HEAD %s\r\n", msgid) == false ) 
                return CHECK_ARTICLE_FAIL;

        if ( (readserverline(client->bbuf, cfg.BufSize)) == NULL ) 
                return CHECK_ARTICLE_FAIL;

        if ( atoi(client->bbuf) > 399 )
                return CHECK_ARTICLE_FAIL;

        /* read headers from server */
        while( readserverline(client->bbuf, cfg.BufSize) != NULL ) 
        {
                if ((sscanf(client->bbuf, "%63[^\t ] %1023[^\r\n]", header, value)) == 0)
                        strncpy(value, client->bbuf, MAX_HEADER-1);

                hdr = insert_hlist(hdr, header, value);
                if ( allhdrs == NULL ) allhdrs = hdr;

                if ( header[0] == '.' )
                        break;
        }
        hdr = allhdrs;

        /* check retention time first */
        if ( client->profile->Retention > 0 )
        {
                msgdate = 0;

                if ( (hval=hlist_get_value(hdr, "NNTP-Posting-Date:")) != NULL )
                        msgdate = parsedate(hval);
                else
                if ( (hval=hlist_get_value(hdr, "Date:")) != NULL )
                        msgdate = parsedate(hval);

                if ( msgdate < (time(NULL) - (client->profile->Retention * 86400)) ) 
                {
                        free_hlist(hdr);
                        return CHECK_ARTICLE_NOPERM;
                }
        }

        /* check newsgroup permission */
        if ( (ng=hlist_get_value(hdr, "Newsgroups:")) != NULL )
        {
                free_hlist(hdr);
                /* now we've found the article and have the newsgroups header */
                if ( match_expression((unsigned char *)ng
                                        , (unsigned char *)getwildmat(client->user->readpat)
                                        , 0) ) 
                        return CHECK_ARTICLE_OK;
                else
                        return CHECK_ARTICLE_NOPERM;
        }

        /* If we reach this, the article wouldn't have a newsgroups header. */

        free_hlist(hdr);
        return CHECK_ARTICLE_FAIL;
}