-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
11 ion nm fails to handle hex string with blank space (#69)
* added new patch for nm rest * updated python39 to 3, RHEL8 to RHEL9 * updated ci to use var for know hosts file * fixing loading modules * updating ci for RHEL9 * updating anms-init to rhel9 * installing node rpm directly * added patch from dtnma-tools --------- Co-authored-by: d-linko <[email protected]> Co-authored-by: Brian Sipos <[email protected]>
- Loading branch information
1 parent
25e02a1
commit dc28179
Showing
2 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
diff --git a/nm/mgr/nm_rest.c b/nm/mgr/nm_rest.c | ||
index 72b63294..054134a4 100644 | ||
--- a/nm/mgr/nm_rest.c | ||
+++ b/nm/mgr/nm_rest.c | ||
@@ -278,11 +278,12 @@ static int agentsHandler(struct mg_connection *conn, void *cbdata) | ||
return agentsGETHandler(conn); | ||
} else if (0 == strcmp(ri->request_method, "POST")) { | ||
char buffer[AMP_MAX_EID_LEN+1]; | ||
- int dlen = mg_read(conn, buffer, sizeof(buffer)); | ||
+ int dlen = mg_read(conn, buffer, sizeof(buffer) - 1); | ||
if ( dlen < 1 ) { | ||
mg_send_http_error(conn, 400, "Invalid request body data (expect EID name) %d", dlen); | ||
return 400; | ||
} else { | ||
+ buffer[dlen] = '\0'; | ||
return agentsCreateHandler(conn, buffer); | ||
} | ||
} else { | ||
@@ -300,34 +301,64 @@ static int agentSendRaw(struct mg_connection *conn, time_t ts, agent_t *agent, c | ||
msg_ctrl_t *msg = NULL; | ||
int success; | ||
|
||
- blob_t *data = utils_string_to_hex(hex); | ||
- if (data == NULL) { | ||
+ if((msg = msg_ctrl_create()) == NULL) | ||
+ { | ||
mg_send_http_error(conn, | ||
500, | ||
- "Error creating blob from input"); | ||
+ "Error creating message"); | ||
return 500; | ||
} | ||
- id = ari_deserialize_raw(data, &success); | ||
- blob_release(data, 1); | ||
- if (id == NULL) { | ||
+ if((msg->ac = ac_create()) == NULL) | ||
+ { | ||
+ msg_ctrl_release(msg, 1); | ||
mg_send_http_error(conn, | ||
500, | ||
- "Error creating blob from input"); | ||
+ "Error creating AC"); | ||
return 500; | ||
} | ||
|
||
- | ||
- ui_postprocess_ctrl(id); | ||
+ msg->start = ts; | ||
|
||
- if((msg = msg_ctrl_create_ari(id)) == NULL) | ||
- { | ||
- ari_release(id, 1); | ||
- mg_send_http_error(conn, | ||
- 500, | ||
- "Error creating ARI from input"); | ||
- return HTTP_INTERNAL_ERROR; | ||
+ char *part = NULL; | ||
+ const char *ctrlsep = " \f\n\r\t\v"; // Identical to isspace() | ||
+ char *saveptr = NULL; | ||
+ part = strtok_r(hex, ctrlsep, &saveptr); | ||
+ while(part != NULL) { | ||
+ fprintf(stderr, "Handling message part %s\n", part); | ||
+ | ||
+ blob_t *data = utils_string_to_hex(part); | ||
+ if (data == NULL) { | ||
+ mg_send_http_error(conn, | ||
+ HTTP_INTERNAL_ERROR, | ||
+ "Error creating blob from input"); | ||
+ msg_ctrl_release(msg, 1); | ||
+ return HTTP_INTERNAL_ERROR; | ||
+ } | ||
+ id = ari_deserialize_raw(data, &success); | ||
+ blob_release(data, 1); | ||
+ if (id == NULL) { | ||
+ mg_send_http_error(conn, | ||
+ HTTP_INTERNAL_ERROR, | ||
+ "Error decoding CTRL"); | ||
+ msg_ctrl_release(msg, 1); | ||
+ return HTTP_INTERNAL_ERROR; | ||
+ } | ||
+ | ||
+ ui_postprocess_ctrl(id); | ||
+ if(vec_push(&(msg->ac->values), id) != VEC_OK) { | ||
+ mg_send_http_error(conn, | ||
+ HTTP_INTERNAL_ERROR, | ||
+ "Error adding CTRL to message"); | ||
+ ari_release(id, 1); | ||
+ msg_ctrl_release(msg, 1); | ||
+ return HTTP_INTERNAL_ERROR; | ||
+ } | ||
+ | ||
+ part = strtok_r(NULL, ctrlsep, &saveptr); | ||
} | ||
- msg->start = ts; | ||
+ | ||
+ fprintf(stderr, "Sending message with %d controls\n", ac_get_count(msg->ac)); | ||
+ | ||
iif_send_msg(&ion_ptr, MSG_TYPE_PERF_CTRL, msg, agent->eid.name); | ||
ui_log_transmit_msg(agent, msg); | ||
msg_ctrl_release(msg, 1); | ||
@@ -460,21 +491,23 @@ static int agentEidHandler(struct mg_connection *conn, void *cbdata) | ||
} | ||
else if (0 == strcmp(cmd, "hex")) | ||
{ | ||
- // URL idx field translates to agent name | ||
- // Optional query parameter "ts" will translate to timestamp (TODO: Always 0 for initial cut) | ||
- // Request body contains CBOR-encoded HEX string | ||
- char buffer[MAX_INPUT_BYTES]; | ||
- int dlen = mg_read(conn, buffer, sizeof(buffer)); | ||
- if (dlen <= 0) { | ||
- return HTTP_BAD_REQUEST; | ||
- } | ||
- buffer[dlen] = 0; // Ensure string is NULL-terminated | ||
- int ts = 0; | ||
- if (cnt == 3) { | ||
- // Optional Timestamp as last element of URL path | ||
- ts = atoi(cmd2); | ||
- } | ||
- return agentSendRaw(conn, | ||
+ // URL idx field translates to agent name | ||
+ // Optional query parameter "ts" will translate to timestamp (TODO: Always 0 for initial cut) | ||
+ // Request body contains CBOR-encoded HEX string | ||
+ char buffer[MAX_INPUT_BYTES]; | ||
+ int dlen = mg_read(conn, buffer, sizeof(buffer) - 1); | ||
+ if (dlen <= 0) { | ||
+ return HTTP_BAD_REQUEST; | ||
+ } | ||
+ buffer[dlen] = '\0'; | ||
+ | ||
+ int ts = 0; | ||
+ if (cnt == 3) { | ||
+ // Optional Timestamp as last element of URL path | ||
+ ts = atoi(cmd2); | ||
+ } | ||
+ | ||
+ return agentSendRaw(conn, | ||
ts, | ||
agent, | ||
buffer | ||
@@ -557,7 +590,11 @@ static int agentIdxHandler(struct mg_connection *conn, void *cbdata) | ||
// Optional query parameter "ts" will translate to timestamp (TODO: Always 0 for initial cut) | ||
// Request body contains CBOR-encoded HEX string | ||
char buffer[MAX_INPUT_BYTES]; | ||
- int dlen = mg_read(conn, buffer, sizeof(buffer)); | ||
+ int dlen = mg_read(conn, buffer, sizeof(buffer) - 1); | ||
+ if (dlen <= 0) { | ||
+ return HTTP_BAD_REQUEST; | ||
+ } | ||
+ buffer[dlen] = '\0'; | ||
return agentSendRaw(conn, | ||
0, // Timestamp TODO. This will be an optional query param | ||
agent, |