code accordingly.
-/* $OpenBSD: engine_lpr.c,v 1.1.1.1 2018/04/27 16:14:35 eric Exp $ */
+/* $OpenBSD: engine_lpr.c,v 1.2 2019/04/04 19:25:45 eric Exp $ */
/*
* Copyright (c) 2017 Eric Faurot <eric@openbsd.org>
{
m_create(p_frontend, IMSG_LPR_ALLOWEDHOST, connid, 0, -1);
m_add_string(p_frontend, hostname);
- m_add_string(p_frontend, reject ? reject : "");
+ m_add_string(p_frontend, reject);
m_close(p_frontend);
}
lpr_displayq_res(uint32_t connid, int fd, const char *host, const char *cmd)
{
m_create(p_frontend, IMSG_LPR_DISPLAYQ, connid, 0, fd);
- m_add_string(p_frontend, host ? host : "");
- m_add_string(p_frontend, cmd ? cmd : "");
+ m_add_string(p_frontend, host);
+ m_add_string(p_frontend, cmd);
m_close(p_frontend);
}
lpr_rmjob_res(uint32_t connid, int fd, const char *host, const char *cmd)
{
m_create(p_frontend, IMSG_LPR_RMJOB, connid, 0, fd);
- m_add_string(p_frontend, host ? host : "");
- m_add_string(p_frontend, cmd ? cmd : "");
+ m_add_string(p_frontend, host);
+ m_add_string(p_frontend, cmd);
m_close(p_frontend);
}
-/* $OpenBSD: frontend_lpr.c,v 1.1.1.1 2018/04/27 16:14:35 eric Exp $ */
+/* $OpenBSD: frontend_lpr.c,v 1.2 2019/04/04 19:25:45 eric Exp $ */
/*
* Copyright (c) 2017 Eric Faurot <eric@openbsd.org>
m_get_string(proc, &hostname);
m_get_string(proc, &reject);
m_end(proc);
- lpr_on_allowedhost(conn, hostname, reject[0] ? reject : NULL);
+ lpr_on_allowedhost(conn, hostname, reject);
break;
case IMSG_LPR_RECVJOB:
m_get_string(proc, &hostname);
m_get_string(proc, &cmd);
m_end(proc);
- lpr_on_request(conn, imsg->fd, hostname[0] ? hostname : NULL,
- cmd[0] ? cmd : NULL);
+ lpr_on_request(conn, imsg->fd, hostname, cmd);
break;
default:
-/* $OpenBSD: proc.c,v 1.1.1.1 2018/04/27 16:14:37 eric Exp $ */
+/* $OpenBSD: proc.c,v 1.2 2019/04/04 19:25:46 eric Exp $ */
/*
* Copyright (c) 2017 Eric Faurot <eric@openbsd.org>
void
m_add_string(struct imsgproc *p, const char *str)
{
- m_add(p, str, strlen(str) + 1);
+ if (str) {
+ m_add(p, "s", 1);
+ m_add(p, str, strlen(str) + 1);
+ }
+ else
+ m_add(p, "\0", 1);
}
void
void
m_get_string(struct imsgproc *p, const char **dst)
{
- char *end;
+ char *end, c;
if (p->m_in.pos >= p->m_in.end)
fatalx("%s: no data left", __func__);
+ c = *p->m_in.pos++;
+ if (c == '\0') {
+ *dst = NULL;
+ return;
+ }
+
+ if (p->m_in.pos >= p->m_in.end)
+ fatalx("%s: no data left", __func__);
end = memchr(p->m_in.pos, 0, p->m_in.end - p->m_in.pos);
if (end == NULL)
fatalx("%s: unterminated string", __func__);
-/* $OpenBSD: resolver.c,v 1.2 2018/09/05 17:32:56 eric Exp $ */
+/* $OpenBSD: resolver.c,v 1.3 2019/04/04 19:25:46 eric Exp $ */
/*
* Copyright (c) 2017-2018 Eric Faurot <eric@openbsd.org>
m_add_int(p_resolver, hints ? hints->ai_socktype : 0);
m_add_int(p_resolver, hints ? hints->ai_protocol : 0);
m_add_string(p_resolver, hostname);
- m_add_string(p_resolver, servname ? servname : "");
+ m_add_string(p_resolver, servname);
m_close(p_resolver);
}
m_get_int(proc, &hints.ai_socktype);
m_get_int(proc, &hints.ai_protocol);
m_get_string(proc, &hostname);
- if (!m_is_eom(proc))
- m_get_string(proc, &servname);
+ m_get_string(proc, &servname);
m_end(proc);
s = NULL;
m_create(proc, IMSG_GETNAMEINFO, reqid, 0, -1);
m_add_int(proc, EAI_SYSTEM);
m_add_int(proc, save_errno);
+ m_add_string(proc, NULL);
+ m_add_string(proc, NULL);
m_close(proc);
break;
memmove(ai->ai_addr, &ss, ss.ss_len);
- if (cname[0]) {
+ if (cname) {
ai->ai_canonname = strdup(cname);
if (ai->ai_canonname == NULL) {
log_warn("%s: strdup", __func__);
case IMSG_GETNAMEINFO:
m_get_int(proc, &gai_errno);
m_get_int(proc, &errno);
- if (gai_errno == 0) {
- m_get_string(proc, &host);
- m_get_string(proc, &serv);
- }
+ m_get_string(proc, &host);
+ m_get_string(proc, &serv);
m_end(proc);
SPLAY_REMOVE(reqtree, &reqs, req);
- req->cb_ni(req->arg, gai_errno, gai_errno ? NULL : host,
- gai_errno ? NULL : serv);
+ req->cb_ni(req->arg, gai_errno, host, serv);
free(req);
break;
}
m_add_int(s->proc, ai->ai_socktype);
m_add_int(s->proc, ai->ai_protocol);
m_add_sockaddr(s->proc, ai->ai_addr);
- m_add_string(s->proc, ai->ai_canonname ?
- ai->ai_canonname : "");
+ m_add_string(s->proc, ai->ai_canonname);
m_close(s->proc);
}
m_create(s->proc, IMSG_GETNAMEINFO, s->reqid, 0, -1);
m_add_int(s->proc, ar->ar_gai_errno);
m_add_int(s->proc, ar->ar_errno);
- if (ar->ar_gai_errno == 0) {
- m_add_string(s->proc, s->host);
- m_add_string(s->proc, s->serv);
- }
+ m_add_string(s->proc, ar->ar_gai_errno ? NULL : s->host);
+ m_add_string(s->proc, ar->ar_gai_errno ? NULL : s->serv);
m_close(s->proc);
free(s->host);