* Display a negraph message */
| 230 | * Display a negraph message |
| 231 | */ |
| 232 | void |
| 233 | _NgDebugMsg(const struct ng_mesg *msg, const char *path) |
| 234 | { |
| 235 | u_char buf[2 * sizeof(struct ng_mesg) + ARGS_BUFSIZE]; |
| 236 | struct ng_mesg *const req = (struct ng_mesg *)buf; |
| 237 | struct ng_mesg *const bin = (struct ng_mesg *)req->data; |
| 238 | int arglen, csock = -1; |
| 239 | |
| 240 | /* Display header stuff */ |
| 241 | NGLOGX("NG_MESG :"); |
| 242 | NGLOGX(" vers %d", msg->header.version); |
| 243 | NGLOGX(" arglen %u", msg->header.arglen); |
| 244 | NGLOGX(" flags %x", msg->header.flags); |
| 245 | NGLOGX(" token %u", msg->header.token); |
| 246 | NGLOGX(" cookie %s (%u)", |
| 247 | NgCookie(msg->header.typecookie), msg->header.typecookie); |
| 248 | |
| 249 | /* At lower debugging levels, skip ASCII translation */ |
| 250 | if (_gNgDebugLevel <= 2) |
| 251 | goto fail2; |
| 252 | |
| 253 | /* If path is not absolute, don't bother trying to use relative |
| 254 | address on a different socket for the ASCII translation */ |
| 255 | if (strchr(path, ':') == NULL) |
| 256 | goto fail2; |
| 257 | |
| 258 | /* Get a temporary socket */ |
| 259 | if (NgMkSockNode(NULL, &csock, NULL) < 0) |
| 260 | goto fail; |
| 261 | |
| 262 | /* Copy binary message into request message payload */ |
| 263 | arglen = msg->header.arglen; |
| 264 | if (arglen > ARGS_BUFSIZE) |
| 265 | arglen = ARGS_BUFSIZE; |
| 266 | memcpy(bin, msg, sizeof(*msg) + arglen); |
| 267 | bin->header.arglen = arglen; |
| 268 | |
| 269 | /* Lower debugging to avoid infinite recursion */ |
| 270 | _gNgDebugLevel -= RECURSIVE_DEBUG_ADJUST; |
| 271 | |
| 272 | /* Ask the node to translate the binary message to ASCII for us */ |
| 273 | if (NgSendMsg(csock, path, NGM_GENERIC_COOKIE, |
| 274 | NGM_BINARY2ASCII, bin, sizeof(*bin) + bin->header.arglen) < 0) { |
| 275 | _gNgDebugLevel += RECURSIVE_DEBUG_ADJUST; |
| 276 | goto fail; |
| 277 | } |
| 278 | if (NgRecvMsg(csock, req, sizeof(buf), NULL) < 0) { |
| 279 | _gNgDebugLevel += RECURSIVE_DEBUG_ADJUST; |
| 280 | goto fail; |
| 281 | } |
| 282 | |
| 283 | /* Restore debugging level */ |
| 284 | _gNgDebugLevel += RECURSIVE_DEBUG_ADJUST; |
| 285 | |
| 286 | /* Display command string and arguments */ |
| 287 | NGLOGX(" cmd %s (%d)", bin->header.cmdstr, bin->header.cmd); |
| 288 | NGLOGX(" args %s", bin->data); |
| 289 | goto done; |
no test coverage detected