void handle_reply_line(const char *bufp, size_t len) { if (!dna_helper_started) { if (len == 8 && strncmp(bufp, "STARTED\n", 8) == 0) { if (config.debug.dnahelper) DEBUGF("DNAHELPER got STARTED ACK"); dna_helper_started = 1; // Start sending request if there is one pending. if (request_bufptr) { sched_requests.poll.fd = dna_helper_stdin; watch(&sched_requests); } } else { WHYF("DNAHELPER malformed start ACK %s", alloca_toprint(-1, bufp, len)); dna_helper_kill(); } } else if (awaiting_reply) { if (len == 5 && strncmp(bufp, "DONE\n", 5) == 0) { if (config.debug.dnahelper) DEBUG("DNAHELPER reply DONE"); unschedule(&sched_timeout); awaiting_reply = 0; } else { char sidhex[SID_STRLEN + 1]; char did[DID_MAXSIZE + 1]; char name[64]; char uri[512]; const char *replyend = NULL; if (!parseDnaReply(bufp, len, sidhex, did, name, uri, &replyend)) WHYF("DNAHELPER reply %s invalid -- ignored", alloca_toprint(-1, bufp, len)); else if (uri[0] == '\0') WHYF("DNAHELPER reply %s contains empty URI -- ignored", alloca_toprint(-1, bufp, len)); else if (!str_is_uri(uri)) WHYF("DNAHELPER reply %s contains invalid URI -- ignored", alloca_toprint(-1, bufp, len)); else if (sidhex[0] == '\0') WHYF("DNAHELPER reply %s contains empty token -- ignored", alloca_toprint(-1, bufp, len)); else if (!str_is_subscriber_id(sidhex)) WHYF("DNAHELPER reply %s contains invalid token -- ignored", alloca_toprint(-1, bufp, len)); else if (strncmp(sidhex, request_buffer, SID_STRLEN) != 0) WHYF("DNAHELPER reply %s contains mismatched token -- ignored", alloca_toprint(-1, bufp, len)); else if (did[0] == '\0') WHYF("DNAHELPER reply %s contains empty DID -- ignored", alloca_toprint(-1, bufp, len)); else if (!str_is_did(did)) WHYF("DNAHELPER reply %s contains invalid DID -- ignored", alloca_toprint(-1, bufp, len)); else if (strcmp(did, request_did) != 0) WHYF("DNAHELPER reply %s contains mismatched DID -- ignored", alloca_toprint(-1, bufp, len)); else if (*replyend != '\n') WHYF("DNAHELPER reply %s contains spurious trailing chars -- ignored", alloca_toprint(-1, bufp, len)); else { if (config.debug.dnahelper) DEBUGF("DNAHELPER reply %s", alloca_toprint(-1, bufp, len)); overlay_mdp_dnalookup_reply(request_source, request_port, my_subscriber, uri, did, name); } } } else { WARNF("DNAHELPER spurious output %s -- ignored", alloca_toprint(-1, bufp, len)); } }
int cli_optional_did(const char *text) { return text[0] == '\0' || str_is_did(text); }
int cli_lookup_did(const char *text) { return text[0] == '\0' || strcmp(text, "*") == 0 || str_is_did(text); }