Github user ted-ross commented on a diff in the pull request:
https://github.com/apache/qpid-dispatch/pull/36#discussion_r45614279
--- Diff: src/router_core/management_agent.c ---
@@ -268,6 +269,62 @@ static void qd_core_agent_read_handler(qd_dispatch_t
*qd,
}
+/**
+ * Returns true if all the keys contained in the body map are applicable
to a waypoints, false otherwise
+ * @see qdr_waypoint_columns
+ */
+static bool qd_is_valid_waypoint_keys(qd_parsed_field_t *in_body)
+{
+ if(in_body != 0 && qd_parse_is_map(in_body)) {
+ //
+ // A map containing attributes with invalid values for an entity
MUST result in a failure response with a statusCode of 400 (Bad Request).
+ //
+ int j=0;
+ qd_parsed_field_t *field = qd_parse_sub_key(in_body, j);
+ while (field) {
+ bool found = false;
+ for(int i = 1; i < QDR_WAYPOINT_COLUMN_COUNT; i++) {
+ if (qd_field_iterator_equal(qd_parse_raw(field), (unsigned
char*)qdr_waypoint_columns[i])) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) // Some bad field was specified in the body map.
Reject this request
+ return false;
+ j++;
+ field = qd_parse_sub_key(in_body, j);
+ }
+ }
+ else
+ // The body is either empty or the body is not a map, return false
+ return false;
+
+ return true;
+}
+
+
+/**
+ * The body map containing any attributes that are not applicable for the
entity being updated MUST result in a failure response with a statusCode of 400
(Bad Request).
+ */
+static bool qd_check_body(qd_router_entity_type_t entity_type,
+ qd_parsed_field_t *in_body,
+ qd_composed_field_t *out_body,
+ qd_management_context_t *ctx)
+{
+ if (entity_type == QD_ROUTER_WAYPOINT) {
+ if(!qd_is_valid_waypoint_keys(in_body)){
--- End diff --
Rather than have a proliferation of nearly identical type-specific
validation functions, why not do a more general check on the appropriate
attribute-name array? This way, you can write the logic once for all types.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]