lib/ovsdb-idl.c
/* XXX there must be a cleaner way to do this */
XXX there must be a cleaner way to do this
XXX there must be a cleaner way to do this
static struct json *
substitute_uuids(struct json *json, const struct ovsdb_idl_txn *txn)
{
    if (json->type == JSON_ARRAY) {
        struct uuid uuid;
        size_t i;
        if (json->array.n == 2
            && json->array.elems[0]->type == JSON_STRING
            && json->array.elems[1]->type == JSON_STRING
            && !strcmp(json->array.elems[0]->string, "uuid")
            && uuid_from_string(&uuid, json->array.elems[1]->string)) {
            const struct ovsdb_idl_row *row;
            row = ovsdb_idl_txn_get_row(txn, &uuid);
            if (row && !row->old_datum && row->new_datum) {
                json_destroy(json);
                return json_array_create_2(
                    json_string_create("named-uuid"),
                    json_string_create_nocopy(ovsdb_data_row_name(&uuid)));
            }
        }
        for (i = 0; i < json->array.n; i++) {
            json->array.elems[i] = substitute_uuids(json->array.elems[i],
                                                      txn);
        }
    } else if (json->type == JSON_OBJECT) {
        struct shash_node *node;
        SHASH_FOR_EACH (node, json_object(json)) {
            node->data = substitute_uuids(node->data, txn);
        }
    }
    return json;
}
static struct json * substitute_uuids ( struct json * json , const struct ovsdb_idl_txn * txn ) { if ( json -> type == JSON_ARRAY ) { struct uuid uuid ; size_t i ; if ( json -> array . n == 2 && json -> array . elems [ 0 ] -> type == JSON_STRING && json -> array . elems [ 1 ] -> type == JSON_STRING && ! strcmp ( json -> array . elems [ 0 ] -> string , " " ) && uuid_from_string ( & uuid , json -> array . elems [ 1 ] -> string ) ) { const struct ovsdb_idl_row * row ; row = ovsdb_idl_txn_get_row ( txn , & uuid ) ; if ( row && ! row -> old_datum && row -> new_datum ) { json_destroy ( json ) ; return json_array_create_2 ( json_string_create ( " " ) , json_string_create_nocopy ( ovsdb_data_row_name ( & uuid ) ) ) ; } } for ( i = 0 ; i < json -> array . n ; i ++ ) { json -> array . elems [ i ] = substitute_uuids ( json -> array . elems [ i ] , txn ) ; } } else if ( json -> type == JSON_OBJECT ) { struct shash_node * node ; SHASH_FOR_EACH ( node , json_object ( json ) ) { node -> data = substitute_uuids ( node -> data , txn ) ; } } return json ; }
XXX there must be a cleaner way to do this
XXX there must be a cleaner way to do this