[
https://issues.apache.org/jira/browse/DISPATCH-179?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15194076#comment-15194076
]
ASF GitHub Bot commented on DISPATCH-179:
-----------------------------------------
Github user ted-ross commented on a diff in the pull request:
https://github.com/apache/qpid-dispatch/pull/59#discussion_r56071049
--- Diff: src/router_core/agent_link.c ---
@@ -229,3 +242,185 @@ void qdra_link_get_next_CT(qdr_core_t *core,
qdr_query_t *query)
//
qdr_agent_enqueue_response_CT(core, query);
}
+
+
+static void qdr_manage_write_response_map_CT(qd_composed_field_t *body,
qdr_link_t *link)
+{
+ qd_compose_start_map(body);
+
+ for(int i = 0; i < QDR_LINK_COLUMN_COUNT; i++) {
+ qd_compose_insert_string(body, qdr_link_columns[i]);
+ qdr_agent_write_column_CT(body, i, link);
+ }
+
+ qd_compose_end_map(body);
+}
+
+
+static qdr_link_t *qdr_link_find_by_identity(qdr_core_t *core,
qd_field_iterator_t *identity)
+{
+ if (!identity)
+ return 0;
+
+ qdr_link_t *link = DEQ_HEAD(core->open_links);
+
+ while(link) {
+ char id[100];
+ if (link->identifier) {
+ snprintf(id, 100, "%ld", link->identifier);
+ if (qd_field_iterator_equal(identity, (const unsigned char
*)id))
+ break;
+ }
+ link = DEQ_NEXT(link);
+ }
+
+ return link;
+
+}
+
+
+static qdr_link_t *qdr_link_find_by_name(qdr_core_t *core,
qd_field_iterator_t *name)
+{
+ if(!name)
+ return 0;
+
+ qdr_link_t *link = DEQ_HEAD(core->open_links);
+
+ while(link) {
+ if (link->name && qd_field_iterator_equal(name, (const unsigned
char *)link->name))
+ break;
+ link = DEQ_NEXT(link);
+ }
+
+ return link;
+}
+
+
+/**
+ * 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).
+ * TODO - Generalize this function so that all update functions can use it.
+ */
+static qd_error_t qd_is_update_request_valid(qd_router_entity_type_t
entity_type,
+ qd_parsed_field_t *in_body)
+{
+ qd_error_clear();
+ if(in_body != 0 && qd_parse_is_map(in_body)) {
+ int j=0;
+ qd_parsed_field_t *field = qd_parse_sub_key(in_body, j);
+
+ while (field) {
+ bool found = false;
+
+ qd_field_iterator_t *iter = qd_parse_raw(field);
+
+ for(int i = 1; i < QDR_LINK_COLUMN_COUNT; i++) {
+ if (qd_field_iterator_equal(iter, (unsigned
char*)qdr_link_columns[i])) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {// Some bad field was specified in the body map.
Reject this request
+ int field_len = qd_field_iterator_length(iter);
+ // lenth of "Invalid Column Name :" + '\0' is 22
+ char error_message[22 + field_len];
+ snprintf(error_message, 22, "Invalid Column Name: ");
+ char octet = qd_field_iterator_octet(iter);
+ int i = 0;
+ while (octet) {
+ char *spot = &error_message[21+i];
+ snprintf(spot, 2, &octet);
+ octet = qd_field_iterator_octet(iter);
+ i++;
+ }
+ return qd_error(QD_ERROR_MESSAGE, "%s", error_message);
+ }
+
+ j++;
+
+ //Get the next field in the body
+ field = qd_parse_sub_key(in_body, j);
+ }
+ }
+ else
+ return qd_error(QD_ERROR_MESSAGE, "%s", "Message body is not a
map"); // The body is either empty or the body is not a map, return false
+
+ return QD_ERROR_NONE;
+}
+
+
+static void qdra_link_update_set_status(qdr_core_t *core, qdr_query_t
*query, qdr_link_t *link)
+{
+ if (link) {
+ //link->admin_state = qd_field_iterator_copy(adm_state);
+ qdr_manage_write_response_map_CT(query->body, link);
+ query->status = QD_AMQP_OK;
+ }
+ else {
+ query->status = QD_AMQP_NOT_FOUND;
+ qd_compose_start_map(query->body);
+ qd_compose_end_map(query->body);
+ }
+}
+
+static void qdra_link_set_bad_request(qdr_query_t *query)
+{
+ query->status = QD_AMQP_BAD_REQUEST;
+ qd_compose_start_map(query->body);
+ qd_compose_end_map(query->body);
+}
+
+void qdra_link_update_CT(qdr_core_t *core,
+ qd_field_iterator_t *name,
+ qd_field_iterator_t *identity,
+ qdr_query_t *query,
+ qd_parsed_field_t *in_body)
+
+{
+ // If the request was successful then the statusCode MUST contain 200
(OK) and the body of the message
+ // MUST contain a map containing the actual attributes of the entity
updated. These MAY differ from those
+ // requested.
+ // A map containing attributes that are not applicable for the entity
being created, or invalid values for a
+ // given attribute, MUST result in a failure response with a
statusCode of 400 (Bad Request).
+ if (qd_parse_is_map(in_body)) {
+ // The absence of an attribute name implies that the entity should
retain its existing value.
+ // If the map contains a key-value pair where the value is null
then the updated entity should have no value
+ // for that attribute, removing any previous value.
+
+ if (qd_is_update_request_valid(query->entity_type, in_body) ==
QD_ERROR_NONE) {
+ qd_parsed_field_t *admin_state =
qd_parse_value_by_key(in_body, qdr_link_columns[12]);
--- End diff --
There are constants defined for this. Using the numeric literal will cause
bugs later when columns are inevitable moved around.
> Refactor Router Core
> --------------------
>
> Key: DISPATCH-179
> URL: https://issues.apache.org/jira/browse/DISPATCH-179
> Project: Qpid Dispatch
> Issue Type: Improvement
> Components: Router Node
> Reporter: Ted Ross
> Assignee: Ted Ross
> Fix For: 0.6
>
>
> Refactor the core router function to clean up the architecture and to fix the
> significant lock contention issue that exists in 0.5.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]