static int pa_format_info_prop_compatible(const char *one, const char *two) { json_object *o1 = NULL, *o2 = NULL; int i, ret = 0; o1 = json_tokener_parse(one); if (is_error(o1)) goto out; o2 = json_tokener_parse(two); if (is_error(o2)) goto out; /* We don't deal with both values being non-fixed - just because there is no immediate need (FIXME) */ pa_return_val_if_fail(pa_json_is_fixed_type(o1) || pa_json_is_fixed_type(o2), false); if (pa_json_is_fixed_type(o1) && pa_json_is_fixed_type(o2)) { ret = pa_json_value_equal(o1, o2); goto out; } if (pa_json_is_fixed_type(o1)) { json_object *tmp = o2; o2 = o1; o1 = tmp; } /* o2 is now a fixed type, and o1 is not */ if (json_object_get_type(o1) == json_type_array) { for (i = 0; i < json_object_array_length(o1); i++) { if (pa_json_value_equal(json_object_array_get_idx(o1, i), o2)) { ret = 1; break; } } } else if (json_object_get_type(o1) == json_type_object) { /* o1 should be a range type */ int min, max, v; json_object *o_min = NULL, *o_max = NULL; if (json_object_get_type(o2) != json_type_int) { /* We don't support non-integer ranges */ goto out; } o_min = json_object_object_get(o1, PA_JSON_MIN_KEY); if (!o_min || json_object_get_type(o_min) != json_type_int) goto out; o_max = json_object_object_get(o1, PA_JSON_MAX_KEY); if (!o_max || json_object_get_type(o_max) != json_type_int) goto out; v = json_object_get_int(o2); min = json_object_get_int(o_min); max = json_object_get_int(o_max); ret = v >= min && v <= max; } else { pa_log_warn("Got a format type that we don't support"); } out: if (o1) json_object_put(o1); if (o2) json_object_put(o2); return ret; }
static int pa_format_info_prop_compatible(const char *one, const char *two) { pa_json_object *o1 = NULL, *o2 = NULL; int i, ret = 0; o1 = pa_json_parse(one); if (!o1) goto out; o2 = pa_json_parse(two); if (!o2) goto out; /* We don't deal with both values being non-fixed - just because there is no immediate need (FIXME) */ pa_return_val_if_fail(pa_json_is_fixed_type(o1) || pa_json_is_fixed_type(o2), false); if (pa_json_is_fixed_type(o1) && pa_json_is_fixed_type(o2)) { ret = pa_json_object_equal(o1, o2); goto out; } if (pa_json_is_fixed_type(o1)) { pa_json_object *tmp = o2; o2 = o1; o1 = tmp; } /* o2 is now a fixed type, and o1 is not */ if (pa_json_object_get_type(o1) == PA_JSON_TYPE_ARRAY) { for (i = 0; i < pa_json_object_get_array_length(o1); i++) { if (pa_json_object_equal(pa_json_object_get_array_member(o1, i), o2)) { ret = 1; break; } } } else if (pa_json_object_get_type(o1) == PA_JSON_TYPE_OBJECT) { /* o1 should be a range type */ int min, max, v; const pa_json_object *o_min = NULL, *o_max = NULL; if (pa_json_object_get_type(o2) != PA_JSON_TYPE_INT) { /* We don't support non-integer ranges */ goto out; } if (!(o_min = pa_json_object_get_object_member(o1, PA_JSON_MIN_KEY)) || pa_json_object_get_type(o_min) != PA_JSON_TYPE_INT) goto out; if (!(o_max = pa_json_object_get_object_member(o1, PA_JSON_MAX_KEY)) || pa_json_object_get_type(o_max) != PA_JSON_TYPE_INT) goto out; v = pa_json_object_get_int(o2); min = pa_json_object_get_int(o_min); max = pa_json_object_get_int(o_max); ret = v >= min && v <= max; } else { pa_log_warn("Got a format type that we don't support"); } out: if (o1) pa_json_object_free(o1); if (o2) pa_json_object_free(o2); return ret; }