Minor modifications for new design.
[fwd] / identify.c
index 86cd594..50f7ae2 100644 (file)
@@ -1,10 +1,10 @@
 /* -*-c-*-
  *
- * $Id: identify.c,v 1.2 1999/07/03 13:56:59 mdw Exp $
+ * $Id: identify.c,v 1.3 1999/07/26 23:26:21 mdw Exp $
  *
  * Identifies and logs the client of a connection
  *
- * (c) 1999 Mark Wooding
+ * (c) 1999 Straylight/Edgeware
  */
 
 /*----- Licensing notice --------------------------------------------------* 
@@ -29,6 +29,9 @@
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: identify.c,v $
+ * Revision 1.3  1999/07/26 23:26:21  mdw
+ * Minor modifications for new design.
+ *
  * Revision 1.2  1999/07/03 13:56:59  mdw
  * Log connections to syslog or stderr as appropriate.
  *
@@ -80,8 +83,6 @@
 
 typedef struct id {
   id_req q;                            /* Copy of client's request block */
-  void (*func)(void */*p*/);           /* Function to call when done */
-  void *p;                             /* Argument to pass to function */
   time_t when;                         /* When the connection occurred */
   conn c;                              /* Connection selector */
   unsigned state;                      /* Current state of the world */
@@ -110,9 +111,6 @@ typedef struct id {
 
 static void id_done(id *i)
 {
-  char buf[64];
-  struct tm *tm;
-
   /* --- Close down the various dependent bits --- */
 
   if (!(i->state & S_HOST))
@@ -126,21 +124,13 @@ static void id_done(id *i)
 
   /* --- Report the final result --- */
 
-  tm = localtime(&i->when);
-  strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", tm);
-  if (flags & FW_SYSLOG) {
-    syslog(LOG_NOTICE, "%s %s %s from %s@%s [%s]\n",
-          buf, i->q.desc, i->q.act,
-          i->user, i->host, inet_ntoa(i->q.rsin.sin_addr));
-  } else {
-    fprintf(stderr, "%s %s %s from %s@%s [%s]\n",
-          buf, i->q.desc, i->q.act,
-          i->user, i->host, inet_ntoa(i->q.rsin.sin_addr));
-  }
+  fw_log(i->when, "[%s] %s from %s@%s [%s]",
+        i->q.desc, i->q.act,
+        i->user, i->host, inet_ntoa(i->q.rsin.sin_addr));
 
   /* --- Dispose of the block --- */
 
-  i->func(i->p);
+  REFFD_DEC(i->q.r);
   free(i);
 }
 
@@ -247,8 +237,6 @@ static void id_timer(struct timeval *tv, void *vp)
 /* --- @identify@ --- *
  *
  * Arguments:  @const id_req *q@ = pointer to request block
- *             @void (*func)(void *p)@ = function to call when done
- *             @void *p@ = argument to pass to function
  *
  * Returns:    ---
  *
@@ -256,8 +244,7 @@ static void id_timer(struct timeval *tv, void *vp)
  *             which will, eventually, report a message to the system log.
  */
 
-void identify(const id_req *q,
-             void (*func)(void */*p*/), void *p)
+void identify(const id_req *q)
 {
   id *i;
 
@@ -265,8 +252,7 @@ void identify(const id_req *q,
 
   i = xmalloc(sizeof(*i));
   i->q = *q;
-  i->func = func;
-  i->p = p;
+  REFFD_INC(i->q.r);
 
   str_sanitize(i->host, inet_ntoa(q->rsin.sin_addr), sizeof(i->host));
   strcpy(i->user, "<ANONYMOUS>");
@@ -289,9 +275,11 @@ void identify(const id_req *q,
        close(fd);
        id_conn(-1, i);
       } else {
+       int opt = 1;
        sin.sin_family = AF_INET;
        sin.sin_addr = q->rsin.sin_addr;
        sin.sin_port = htons(113);
+       setsockopt(fd, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(opt));
        conn_init(&i->c, sel, fd,
                  (struct sockaddr *)&sin, sizeof(sin),
                  id_conn, i);