예제 #1
0
/**
 * Which bits to check
 */
static int
aim_log_bits__(aim_log_t* alt, const char* flag, uint32_t* common,
               uint32_t* custom)
{
    /*
     * Check custom flags first, then common flags.
     */
    int i;
    *common = 0;
    *custom = 0;

    if(!AIM_STRCMP(flag, "all")) {
        *custom = ~0;
        *common = ~0;
        return 1;
    }

    if(alt->custom_map && aim_map_si_s(&i, flag, alt->custom_map, 0)) {
        *custom = (1 << i);
        return 1;
    }

    if(aim_map_si_s(&i, flag, aim_log_flag_map, 0)) {
        *common = (1 << i);
        return 1;
    }

    return 0;
}
예제 #2
0
static int
aim_datatype_equals__(const aim_datatype_t* dt, char c, const char* type)
{
    if( ( (c==0) || (dt->c == c)) &&
        ( (type==NULL || type[0]==0) || (dt->type && !AIM_STRCMP(type, dt->type)))) {
        return 1;
    }
    return 0;
}
예제 #3
0
aim_datatype_map_t*
aim_datatype_map_find_value(aim_datatype_map_t* map, const char* name)
{
    aim_datatype_map_t* p;
    for(p = map; p->s; p++) {
        if(!AIM_STRCMP(p->s, name)) {
            return p;
        }
    }
    return NULL;
}
예제 #4
0
/**
 * Find a module.
 */
aim_log_t*
aim_log_find(const char* name)
{
    aim_log_t* aml;
    AIM_LOG_FOREACH(aml) {
        if(!AIM_STRCMP(aml->name, name)) {
            return aml;
        }
    }
    return NULL;
}
예제 #5
0
uint8_t*
aim_bytes_from_string(const char* string, int* size)
{
    unsigned char* bytes;
    unsigned char byte;
    int i;
    int nibble_count;
    int string_len;

    if(string == NULL || size == NULL || string[0] == 0) {
        return NULL;
    }

    if(!AIM_STRCMP(string, "NULL")) {
        *size = 0;
        return NULL;
    }

    string_len = AIM_STRLEN(string);

    bytes = aim_zmalloc((string_len+1) / 2);

    byte = 0;
    nibble_count = 0;

    for(i = 0; i < string_len; i++) {
        int hv = hex_val__(string[i]);
        if(hv >= 0) {
            byte |= hv;
            if( (nibble_count % 2) == 0) {
                byte <<= 4;
            }
            else {
                bytes[nibble_count/2] = byte;
                byte = 0;
            }
            nibble_count++;
        }
    }
    if(nibble_count & 1) {
        /* Last nibble will be padded as zero */
        bytes[nibble_count++/2] = byte;
    }

    *size = nibble_count / 2;
    return bytes;
}
예제 #6
0
파일: aim_map.c 프로젝트: amertahir/indigo
int
aim_map_si_s(int* rv, const char* s, aim_map_si_t* maps, unsigned int count)
{
    unsigned int idx;
    aim_map_si_t* p;

    for(p = maps, idx = 0; (count && (idx < count)) || p->s; idx++, p++) {
        if(!AIM_STRCMP(p->s, s)) {
            if(rv) {
                *rv = p->i;
            }
            return 1;
        }
    }

    return 0;
}
예제 #7
0
int
aim_avsparse_type(const char* arg, aim_pvs_t* epvs,
                  char c, char* type, aim_va_list_t* vargs)
{
    int rv;
    aim_datatype_t* dt;
    aim_datatype_context_t dtc;

    if(arg == NULL) {
        return AIM_ERROR_PARAM;
    }

    if(type && type[0] == '%') {
        /* Immediate string specified. The argument must be that string. */
        if(type[1] == 0) {
            /* No string */
            return AIM_ERROR_PARAM;
        }
        if(!AIM_STRCMP(type+1, arg)) {
            return AIM_ERROR_NONE;
        }
        aim_printf(epvs, "expected '%s', not '%s'\n", type+1, arg);
        return AIM_ERROR_PARAM;
    }

    dt = aim_datatype_find(c, type);
    if(dt == NULL) {
        /* Unrecognized type */
        aim_printf(epvs, "<bug: no handler for type '%c:%s'>\n", (c) ? c : '.', (type) ? type : "[NULL]");
        return AIM_ERROR_NOT_FOUND;
    }

    dtc.dt = dt;
    dtc.epvs = epvs;
    rv = dt->from_str(&dtc, arg, vargs);

    if( (rv < 0) && dt->desc) {
        aim_printf(epvs, "'%s' is not a valid %s\n", arg, dt->desc);
    }
    return rv;
}