chiark / gitweb /
subdirmk: Change stub force target to `run-main.mk'
[secnet.git] / util.c
diff --git a/util.c b/util.c
index d0c3d966de4bcd2feb177dcb32300717e3f7b2b1..977e131fbeda106fcaa8fe7964af878ccbe2ebe9 100644 (file)
--- a/util.c
+++ b/util.c
@@ -401,6 +401,38 @@ const char *truncmsg_terminate(const struct buffer_if *buf)
     return buf->start;
 }
 
+void priomsg_new(struct priomsg *pm, int32_t maxlen)
+{
+    buffer_new(&pm->m, maxlen);
+    pm->prio = INT_MIN;
+}
+void priomsg_reset(struct priomsg *pm)
+{
+    buffer_init(&pm->m, 0);
+    pm->prio = INT_MIN;
+}
+bool_t priomsg_update_p(struct priomsg *pm, int prio)
+{
+    if (!pm) return False;
+    if (prio <= pm->prio) return False;
+    buffer_init(&pm->m, 0);
+    pm->prio = prio;
+    return True;
+}
+const char *priomsg_getmessage(const struct priomsg *pm, const char *defmsg)
+{
+    if (pm->prio >= INT_MIN)
+       return truncmsg_terminate(&pm->m);
+    else
+       return defmsg;
+}
+
+bool_t priomsg_update_fixed(struct priomsg *pm, int prio, const char *m) {
+    if (!priomsg_update_p(pm, prio)) return False;
+    truncmsg_add_string(&pm->m, m);
+    return True;
+}
+
 void buffer_new(struct buffer_if *buf, int32_t len)
 {
     buf->free=True;
@@ -499,10 +531,11 @@ void send_nak(const struct comm_addr *dest, uint32_t our_index,
     buf_append_uint32(buf,our_index);
     buf_append_uint32(buf,LABEL_NAK);
     if (logwhy)
-       Message(M_INFO,"%s: %08"PRIx32"<-%08"PRIx32": %08"PRIx32":"
-               " %s; sending NAK\n",
+       Message(M_INFO,"%s: sending NAK for"
+               " %08"PRIx32" %08"PRIx32"<-%08"PRIx32":"
+               " %s\n",
                comm_addr_to_string(dest),
-               our_index, their_index, msgtype, logwhy);
+               msgtype, our_index, their_index, logwhy);
     dest->comm->sendmsg(dest->comm->st, buf, dest, 0);
 }