Ejemplo n.º 1
0
void remove_rule (struct ruleset *rule)
{
    LIST_REMOVE(rule_list, rule, HASH_INT(rule->direction));
    if (rule_list.ltail == rule)
        rule_list.ltail = rule->lprev;
    free(rule);
}
Ejemplo n.º 2
0
JSAtom *
js_AtomizeInt(JSContext *cx, jsint i, uintN flags)
{
    jsval key;
    JSHashNumber keyHash;

    key = INT_TO_JSVAL(i);
    keyHash = HASH_INT(i);
    return js_AtomizeHashedKey(cx, key, keyHash, flags);
}
Ejemplo n.º 3
0
js_hash_atom_key(const void *key)
{
    jsval v;
    jsdouble *dp;

    /* Order JSVAL_IS_* tests by likelihood of success. */
    v = (jsval)key;
    if (JSVAL_IS_STRING(v))
        return js_HashString(JSVAL_TO_STRING(v));
    if (JSVAL_IS_INT(v))
        return HASH_INT(JSVAL_TO_INT(v));
    if (JSVAL_IS_DOUBLE(v)) {
        dp = JSVAL_TO_DOUBLE(v);
        return HASH_DOUBLE(dp);
    }
    if (JSVAL_IS_OBJECT(v))
        return HASH_OBJECT(JSVAL_TO_OBJECT(v));
    if (JSVAL_IS_BOOLEAN(v))
        return HASH_BOOLEAN(JSVAL_TO_BOOLEAN(v));
    return (JSHashNumber)v;
}
Ejemplo n.º 4
0
struct ruleset *add_rule (char *ruledata)
{
    struct ruleset ruleset;
    memset(&ruleset, 0, sizeof(ruleset));

    char *what, *direction, *stuff;
    char temp[1024];
    strncpy(temp, ruledata, 1023);
    what = temp;
    direction = SeperateWord(what);
    stuff = SeperateWord(direction);

    if (strempty(what) || strempty(direction))
        return NULL;

    if (!strcmp(what,"drop"))
        ruleset.rule = RULE_DROP;
    else if (!strcmp(what,"pass"))
        ruleset.rule = RULE_PASS;
    else
        return NULL;

    if (!strcmp(direction,"in"))
        ruleset.direction = DIRECT_IN;
    else if (!strcmp(direction,"out"))
        ruleset.direction = DIRECT_OUT;
    else
        return NULL;

    char *param, *data;
    param = stuff;
    stuff = SeperateWord(param);

    if (!strcmp(param, "quick")) {
        ruleset.quick = 1;
        param = stuff;
        stuff = SeperateWord(param);
    }

    for (; stuff; param = stuff, stuff = SeperateWord(stuff)) {
        if (strcmp(param, "data")) { /* not data */
            data = stuff;
            stuff = SeperateWord(data);
            if (strempty(data))
                return NULL;
            if (!strcmp(param, "from"))
                strncpy(ruleset.from, data, 32);
            else if (!strcmp(param, "to")) {
                if (*data == '\\' && *(data+1) == '#')
                    data++;
                strncpy(ruleset.to, data, 32);
            } else if (!strcmp(param, "action"))
                strncpy(ruleset.action, data, 32);
            else
                return NULL;
        } else {
            data = strchr(stuff, '"');
            if (strempty(data))
                return NULL;
            data++;
            char *tmp = strchr(data, '"');
            if (strempty(tmp))
                return NULL;
            *tmp = '\0';
            if (*(tmp+1) == 'i')
                ruleset.icase = 1;
            stuff = StripBlanks(tmp+1);
            strncpy(ruleset.data, data, 1024);
        }
    }

    struct ruleset *new_rule;
    new_rule = (struct ruleset *)calloc(1, sizeof(struct ruleset));
    memcpy(new_rule, &ruleset, sizeof(ruleset));
    LIST_INSERT_HEAD(rule_list, new_rule, HASH_INT(new_rule->direction));
    if (rule_list.size == 1)
        rule_list.ltail = new_rule;

    return new_rule;
}