Ejemplo n.º 1
0
static bool get_index_by_uuid(const int8 *uuid, const int32 type, int32 *index)
{
	struct node_info *subnode = NULL;
	struct node_info *sub_node = NULL;
	int32 subnode_num = 0;
	int32 i;
	int8 rs[128] = {0};
	int64 error_code = 0;
	int32 loc_id = 0;

	subnode = libdb_list_node_by_type(DB_RMM, (uint32)type, (uint32)type, &subnode_num, NULL, LOCK_ID_NULL);

	if (subnode == NULL) {
		rmm_log(ERROR, "get subnode error\n");
		return FALSE;
	}

	sub_node = (struct node_info *)malloc(sizeof(struct node_info) * subnode_num);
	if (sub_node == NULL) {
		rmm_log(ERROR, "malloc error\n");
		return FALSE;
	}

	memcpy_s(sub_node, sizeof(struct node_info) * subnode_num, subnode, sizeof(struct node_info) * subnode_num);

	for (i = 0; i < subnode_num; i++) {
		memset(rs, 0, 128);
		error_code = 0;
		error_code = libdb_attr_get_string(DB_RMM, sub_node[i].node_id, WRAP_UUID_STR, rs, 128, LOCK_ID_NULL);

		if (error_code != 0) {
			rmm_log(ERROR, "%s:%d: error code:%d\n", __func__, __LINE__, error_code);
			libdb_free_node(sub_node);
			return FALSE;
		} else {
			if (0 == strcasecmp(uuid, rs)) {
				memset(rs, 0, 128);
				error_code = 0;
				error_code = libdb_attr_get_string(DB_RMM, sub_node[i].node_id, WRAP_LOC_ID_STR, rs, 128, LOCK_ID_NULL);
				if (error_code != 0) {
					rmm_log(ERROR, "%s:%d: error code:%d\n", __func__, __LINE__, error_code);
					libdb_free_node(sub_node);
					return FALSE;
				} else if (index != NULL) {
					loc_id = str2int(rs);
					*index = gen_asset_index(type, loc_id, sub_node[i].node_id);
					libdb_free_node(sub_node);
					return TRUE;
				}
			}
		}
	}

	libdb_free_node(sub_node);
	return FALSE;
}
static bool get_index_by_uuid(const int8 *uuid, const int32 type, int32 *index)
{
	struct node_info *subnode = NULL;
	int32 subnode_num = 0;
	int32 i;
	int8 rs[128] = {0};
	int64 error_code = 0;
	int32 loc_id = 0;

	subnode = libdb_list_node_by_type(DB_RMM, (uint32)type, (uint32)type, &subnode_num, NULL, LOCK_ID_NULL);

	for (i = 0; i < subnode_num; i++) {
		memset(rs, 0, 128);
		error_code = 0;
		error_code = libdb_attr_get_string(DB_RMM, subnode[i].node_id, (int8 *)type_key[type].uuid_key, rs, 128, LOCK_ID_NULL);
		if (error_code != 0) {
			rmm_log(ERROR, "%s:%d: error code:%d\n", __func__, __LINE__, error_code);
			libdb_free_node(subnode);
			return FALSE;
		} else {
			if (0 == strcmp(uuid, rs)) {
				memset(rs, 0, 128);
				error_code = 0;
				error_code = libdb_attr_get_string(DB_RMM, subnode[i].node_id, (int8 *)type_key[type].id_key, rs, 128, LOCK_ID_NULL);
				if (error_code != 0) {
					rmm_log(ERROR, "%s:%d: error code:%d\n", __func__, __LINE__, error_code);
					libdb_free_node(subnode);
					return FALSE;
				} else if (index != NULL) {
					loc_id = str2int(rs);
					*index = gen_asset_index(type, loc_id, subnode[i].node_id);
					libdb_free_node(subnode);
					return TRUE;
				}
			}
		}
	}

	libdb_free_node(subnode);
	return FALSE;
}