int riemann_event_set_attributes(riemann_event_t *evtp, const riemann_attribute_pairs_t *apairsp, size_t n_attrs) { int i; riemann_attribute_t **attrs = malloc(sizeof(riemann_attribute_t *) * n_attrs); if (!attrs) return -2; for (i = 0; i < n_attrs; i++) { attrs[i] = riemann_attribute_alloc(); if (!attrs[i]) { int j; for (j = 0; j < i; j++) riemann_attribute_free(attrs[i]); return -1; } riemann_attribute_init(attrs[i]); riemann_attribute_set_key(attrs[i], apairsp[i].key); riemann_attribute_set_value(attrs[i], apairsp[i].value); } evtp->attributes = attrs; evtp->n_attributes = n_attrs; return 0; }
int riemann_attribute_set (riemann_attribute_t *attrib, const char *key, const char *value) { int e; if ((e = riemann_attribute_set_key (attrib, key)) != 0) return e; if ((e = riemann_attribute_set_value (attrib, value)) != 0) return e; return 0; }
riemann_attribute_t * riemann_attribute_create (const char *key, const char *value) { riemann_attribute_t *attrib; /* All of these calls can only fail if run out of memory, in which case, the library will crash anyway. We only set the key or the value when they were supplied to this function, so that branch is guarded against, too. */ attrib = riemann_attribute_new (); if (key) riemann_attribute_set_key (attrib, key); if (value) riemann_attribute_set_value (attrib, value); return attrib; }