Browse Source

Ensure we have a local copy of the tag in our request structure - which will be useful for the event framework

pull/947/head
Hamish Coleman 3 years ago
parent
commit
40773b4e4d
  1. 5
      doc/ManagementAPI.md
  2. 13
      src/edge_management.c

5
doc/ManagementAPI.md

@ -83,7 +83,8 @@ SubFields:
Each request provides a tag value. Any non error reply associated with this Each request provides a tag value. Any non error reply associated with this
request will include this tag value, allowing all related messages to be request will include this tag value, allowing all related messages to be
collected within the client. collected within the client. The tag will be truncated if needed by the
daemon, but there will be at least 8 octets of space available.
Where possible, the error replies will also include this tag, however some Where possible, the error replies will also include this tag, however some
errors occur before the tag is parsed. errors occur before the tag is parsed.
@ -131,7 +132,7 @@ containing a fragment of information related to the entire reply.
There are two keys in each dictionary containing metadata. First There are two keys in each dictionary containing metadata. First
is the `_tag`, containing the Message Tag from the original request. is the `_tag`, containing the Message Tag from the original request.
Second is the `_type` whic identifies the expected contents of this Second is the `_type` which identifies the expected contents of this
packet. packet.
### `_type: error` ### `_type: error`

13
src/edge_management.c

@ -25,7 +25,7 @@
typedef struct mgmt_req { typedef struct mgmt_req {
n2n_edge_t *eee; n2n_edge_t *eee;
enum n2n_mgmt_type type; enum n2n_mgmt_type type;
char *tag; char tag[10];
struct sockaddr_in sender_sock; struct sockaddr_in sender_sock;
} mgmt_req_t; } mgmt_req_t;
@ -359,6 +359,11 @@ static void handleMgmtJson (mgmt_req_t *req, char *udp_buf, const int recvlen) {
mgmt_handler_t *handler; mgmt_handler_t *handler;
size_t msg_len; size_t msg_len;
/* Initialise the tag field until we extract it from the cmdline */
req->tag[0] = '-';
req->tag[1] = '1';
req->tag[2] = '\0';
/* save a copy of the commandline before we reuse the udp_buf */ /* save a copy of the commandline before we reuse the udp_buf */
strncpy(cmdlinebuf, udp_buf, sizeof(cmdlinebuf)-1); strncpy(cmdlinebuf, udp_buf, sizeof(cmdlinebuf)-1);
cmdlinebuf[sizeof(cmdlinebuf)-1] = 0; cmdlinebuf[sizeof(cmdlinebuf)-1] = 0;
@ -366,7 +371,6 @@ static void handleMgmtJson (mgmt_req_t *req, char *udp_buf, const int recvlen) {
traceEvent(TRACE_DEBUG, "mgmt json %s", cmdlinebuf); traceEvent(TRACE_DEBUG, "mgmt json %s", cmdlinebuf);
typechar = strtok(cmdlinebuf, " \r\n"); typechar = strtok(cmdlinebuf, " \r\n");
req->tag = "-1";
if(!typechar) { if(!typechar) {
/* should not happen */ /* should not happen */
mgmt_error(req, udp_buf, "notype"); mgmt_error(req, udp_buf, "notype");
@ -404,7 +408,10 @@ static void handleMgmtJson (mgmt_req_t *req, char *udp_buf, const int recvlen) {
/* /*
* There might be an auth token mixed in with the tag * There might be an auth token mixed in with the tag
*/ */
req->tag = strtok(options, ":"); char *tagp = strtok(options, ":");
strncpy(req->tag, tagp, sizeof(req->tag)-1);
req->tag[sizeof(req->tag)-1] = '\0';
flagstr = strtok(NULL, ":"); flagstr = strtok(NULL, ":");
if(flagstr) { if(flagstr) {
flags = strtoul(flagstr, NULL, 16); flags = strtoul(flagstr, NULL, 16);

Loading…
Cancel
Save