void mml_set_name(MMLObject* mml, NodeIdx node, const char* name) { assert(mml); assert(name); assert(node < mml->node_pool.size); MMLNode* node_ptr = mml_get_nodeptr(mml, node); node_ptr->name_start = _set_str(mml, node_ptr->name_start, name); }
static int _fill_msg_strs(mc_msg_t* msg, entry_list_t* elist, const uint8_t* body, _parse_info_t* parse_info) { if (parse_info->key_idx >= 0) { _set_str(&msg->key, body, &elist->entries[parse_info->key_idx]); } if (parse_info->value_idx >= 0) { _set_str(&msg->value, body, &elist->entries[parse_info->value_idx]); if (msg->op == mc_op_metaget) { int af = AF_INET; if (strchr(msg->value.str, ':') != NULL) { af = AF_INET6; } if (inet_pton(af, msg->value.str, &msg->ip_addr) > 0) { msg->ipv = af == AF_INET ? 4 : 6; } msg->value.str = NULL; msg->value.len = 0; } } #ifndef LIBMC_FBTRACE_DISABLE if (parse_info->fbtrace_idx >= 0) { if (msg->fbtrace_info == NULL) { msg->fbtrace_info = new_mc_fbtrace_info(0); if (msg->fbtrace_info == NULL || msg->fbtrace_info->fbtrace == NULL) { return -1; } } else { dbg_error("msg->fbtrace_info was already initialized"); } if (_cpy_fbtrace_meta(msg->fbtrace_info->metadata, body, &elist->entries[parse_info->fbtrace_idx])) { return -1; } } #endif return 0; }
static mc_msg_t *_msg_create(mc_msg_t *base, entry_list_t *elist, _parse_info_t* parse_info) { size_t msg_size = 0; mc_msg_t *msg = NULL; size_t stats_offset = 0; size_t body_offset = 0; void *body = NULL; // Make sure we're not screwing up alignment here FBI_ASSERT(sizeof(mc_msg_t) % sizeof(void *) == 0); // Construct a message of the following format // __________________ // | | // | mc_msg_t | <- base message // |___________________| // | | // | nstring_t array | <- stats array (optional) // |___________________| // | | // | key string | <- key (optional) // |___________________| // | | // | value string | <- value (optional) // |___________________| // | | // | stats[0] | <- stats[0] (and so on...) // |___________________| // msg_size = sizeof(mc_msg_t); if (parse_info->stats_count > 0) { stats_offset = msg_size; msg_size += (sizeof(nstring_t) * parse_info->stats_count); } body_offset = msg_size; msg_size += elist->nbody; FBI_ASSERT(msg_size >= sizeof(*base)); msg = mc_msg_new(msg_size - sizeof(mc_msg_t)); if (msg == NULL) { goto error; } // Copy base mc_msg_copy(msg, base); // Copy body memcpy((void*)msg + body_offset, elist->body, elist->nbody); body = (void*)msg + body_offset; if (parse_info->stats_count > 0) { FBI_ASSERT(stats_offset > 0); nstring_t *stats = (nstring_t*) ((void*)msg + stats_offset); uint64_t i; int sidx; for (i = 0, sidx = 0; i < elist->nentries && sidx < parse_info->stats_count; i++) { um_elist_entry_t *entry = &elist->entries[i]; if (ntoh16(entry->tag) == msg_stats) { _set_str(&stats[sidx], body, entry); sidx++; } } msg->stats = stats; } _fill_msg_strs(msg, elist, body, parse_info); return msg; error: if (msg != NULL) { mc_msg_decref(msg); msg = NULL; } return NULL; }