chiark / gitweb /
resolver: Provide input name as argument to callback
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 29 Sep 2014 14:00:47 +0000 (15:00 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 2 Oct 2014 15:30:22 +0000 (16:30 +0100)
This is going to be convenient for our one call site.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
resolver.c
secnet.h
site.c

index f2c620b..8109a27 100644 (file)
@@ -20,6 +20,7 @@ struct adns {
 
 struct query {
     void *cst;
+    const char *name;
     int port;
     struct comm_if *comm;
     resolve_answer_fn *answer;
@@ -60,17 +61,17 @@ static bool_t resolve_request(void *sst, cstring_t name,
            snprintf(msg,sizeof(msg),"invalid address literal: %s",
                     strerror(rv));
            msg[sizeof(msg)-1]=0;
-           cb(cst,0,0,msg);
+           cb(cst,0,0,name,msg);
        } else {
-           cb(cst,&ca,1,0);
+           cb(cst,&ca,1,name,0);
        }
 #else
        ca.ia.sin.sin_family=AF_INET;
        ca.ia.sin.sin_port=htons(port);
        if (inet_aton(trimmed,&ca.ia.sin.sin_addr))
-           cb(cst,&ca,1,0);
+           cb(cst,&ca,1,name,0);
        else
-           cb(cst,0,0,"invalid IP address");
+           cb(cst,0,0,name,"invalid IP address");
 #endif
        return True;
     }
@@ -79,6 +80,7 @@ static bool_t resolve_request(void *sst, cstring_t name,
     q->cst=cst;
     q->comm=comm;
     q->port=port;
+    q->name=name;
     q->answer=cb;
 
     rv=adns_submit(st->ast, name, adns_r_addr, 0, q, &q->query);
@@ -117,7 +119,7 @@ static void resolver_afterpoll(void *sst, struct pollfd *fds, int nfds)
        if (rv==0) {
            q=qp;
            if (ans->status!=adns_s_ok) {
-               q->answer(q->cst,NULL,0,adns_strerror(ans->status));
+               q->answer(q->cst,NULL,0,q->name,adns_strerror(ans->status));
                free(q);
                free(ans);
            } else {
@@ -153,7 +155,7 @@ static void resolver_afterpoll(void *sst, struct pollfd *fds, int nfds)
                        break;
                    }
                }
-               q->answer(q->cst,ca_buf,wslot,0);
+               q->answer(q->cst,ca_buf,wslot,q->name,0);
                free(q);
                free(ans);
            }
index a38b77c..6925a6e 100644 (file)
--- a/secnet.h
+++ b/secnet.h
@@ -295,7 +295,10 @@ struct buffer_if;
    will be freed once resolve_answer_fn returns. It is in network byte
    order. */
 typedef void resolve_answer_fn(void *st, const struct comm_addr *addrs,
-                              int naddrs, const char *failwhy);
+                              int naddrs, const char *name,
+                              const char *failwhy);
+  /* name is the same ptr as passed to request, so its lifetime must
+   * be suitable*/
 typedef bool_t resolve_request_fn(void *st, cstring_t name,
                                  int remoteport, struct comm_if *comm,
                                  resolve_answer_fn *cb, void *cst);
diff --git a/site.c b/site.c
index bcacef1..dab2dc2 100644 (file)
--- a/site.c
+++ b/site.c
@@ -1193,7 +1193,8 @@ static bool_t send_msg(struct site *st)
 }
 
 static void site_resolve_callback(void *sst, const struct comm_addr *addrs,
-                                 int naddrs, const char *failwhy)
+                                 int naddrs, const char *address,
+                                 const char *failwhy)
 {
     struct site *st=sst;