示例#1
0
文件: ceph.c 项目: Zanop/collectd
/**
 * Parse key to remove "type" if this is for schema and initiate compaction
 */
static int parse_keys (char *buffer, size_t buffer_size, const char *key_str)
{
    char tmp[2 * buffer_size];

    if (buffer == NULL || buffer_size == 0 || key_str == NULL || strlen (key_str) == 0)
        return EINVAL;

    if ((count_parts (key_str) > 2) && has_suffix (key_str, ".type"))
    {
        /* strip ".type" suffix iff the key has more than two parts. */
        size_t sz = strlen (key_str) - strlen (".type") + 1;

        if (sz > sizeof (tmp))
            sz = sizeof (tmp);
        sstrncpy (tmp, key_str, sz);
    }
    else
    {
        sstrncpy (tmp, key_str, sizeof (tmp));
    }

    return compact_ds_name (buffer, buffer_size, tmp);
}
示例#2
0
/**
 * Parse key to remove "type" if this is for schema and initiate compaction
 */
static int parse_keys(const char *key_str, char *ds_name)
{
    char *ptr, *rptr;
    size_t ds_name_len = 0;
    /**
     * allow up to 100 characters before compaction - compact_ds_name will not
     * allow more than DATA_MAX_NAME_LEN chars
     */
    int max_str_len = 100;
    char tmp_ds_name[max_str_len];
    memset(tmp_ds_name, 0, sizeof(tmp_ds_name));
    if(ds_name == NULL || key_str == NULL ||  key_str[0] == '\0' ||
                                                            ds_name[0] != '\0')
    {
        return -1;
    }
    if((ptr = strchr(key_str, '.')) == NULL
            || (rptr = strrchr(key_str, '.')) == NULL)
    {
        memcpy(tmp_ds_name, key_str, max_str_len - 1);
        goto compact;
    }

    ds_name_len = (rptr - ptr) > max_str_len ? max_str_len : (rptr - ptr);
    if((ds_name_len == 0) || strncmp(rptr + 1, "type", 4))
    { /** copy whole key **/
        memcpy(tmp_ds_name, key_str, max_str_len - 1);
    }
    else
    {/** more than two keys **/
        memcpy(tmp_ds_name, key_str, ((rptr - key_str) > (max_str_len - 1) ?
                (max_str_len - 1) : (rptr - key_str)));
    }

    compact: compact_ds_name(tmp_ds_name, ds_name);
    return 0;
}