Esempio n. 1
0
/**
 * Apply the user agent category rules.
 *
 * Walks through the internal static category rules, attempts to apply
 * each of them to the passed in agent info.
 *
 * @param[in] fields Array of fields to match (0=product,1=platform,2=extra)
 * @param[in] rule Match rule to match against
 *
 * @returns 1 if all rules match, otherwise 0
 */
static int modua_mrule_match(const char *fields[],
                             const modua_match_rule_t *rule)
{
    IB_FTRACE_INIT();
    const modua_field_rule_t *fr;
    unsigned int ruleno;

    /* Walk through the rules; if any fail, return NULL */
    for (ruleno = 0, fr = rule->rules;
         ruleno < rule->num_rules;
         ++ruleno, ++fr) {

        /* Apply the rule */
        modua_matchresult_t result =
            modua_frule_match(fields[fr->match_field], fr);

        /* If it doesn't match the expect results, we're done, return 0 */
        if (result != fr->match_result) {
            IB_FTRACE_RET_INT( 0 );
        }
    }

    /* If we've applied all of the field rules, and all have passed,
     * return the 1 to signify a match */
    IB_FTRACE_RET_INT( 1 );
}
Esempio n. 2
0
int ib_bytestr_index_of_c(
    const ib_bytestr_t *haystack,
    const char   *needle
)
{
    IB_FTRACE_INIT();

    const uint8_t* haystack_data = ib_bytestr_const_ptr(haystack);
    const char *found;

    /* Let ib_strstr_ex() do the heavy lifting */
    found = ib_strstr_ex( (const char *)haystack_data,
                          ib_bytestr_length(haystack),
                          needle,
                          strlen(needle));

    /* Return the offset (or -1) */
    if (found != NULL) {
        IB_FTRACE_RET_INT(found - (const char *)haystack_data);
    }
    else {
        IB_FTRACE_RET_INT(-1);
    }
}
Esempio n. 3
0
/**
 * Match a field against the specified match rule.
 *
 * Attempts to match the field string (or NULL) against the field match rule.
 * NULL)
 *
 * @param[in] str User agent string to match
 * @param[in] rule Field match rule to match the string against
 *
 * @returns 1 if the string matches, 0 if not.
 */
static modua_matchresult_t modua_frule_match(const char *str,
                                             const modua_field_rule_t *rule)
{
    IB_FTRACE_INIT();

    /* First, handle the simple NULL string case */
    if (str == NULL) {
        IB_FTRACE_RET_INT(NO);
    }

    /* Match using the rule's match type */
    switch (rule->match_type) {
        case EXISTS:         /* Note: NULL/NO handled above */
            IB_FTRACE_RET_INT(YES);
        case MATCHES:
            IB_FTRACE_RET_INT(RESULT_EQ(strcmp(str, rule->string), 0));
        case STARTSWITH:
            IB_FTRACE_RET_INT(RESULT_EQ(strncmp(str, rule->string, rule->slen), 0));
        case CONTAINS:
            IB_FTRACE_RET_INT(RESULT_NE(strstr(str, rule->string), NULL));
        case ENDSWITH: {
            size_t slen = strlen(str);
            size_t offset;
            if (slen < rule->slen) {
                IB_FTRACE_RET_INT(0);
            }
            offset = (slen - rule->slen);
            IB_FTRACE_RET_INT(RESULT_EQ(strcmp(str+offset, rule->string), 0));
        }
        default :
            fprintf(stderr,
                    "modua_frule_match: invalid match type %d",
                    rule->match_type);
    }

    /* Should never get here! */
    IB_FTRACE_RET_INT(NO);
}
Esempio n. 4
0
int ib_state_event_cbdata_type(ib_state_event_type_t event)
{
    IB_FTRACE_INIT();
    IB_FTRACE_RET_INT(ib_state_event_name_cbdata_type_list[event]);
}