chiark / gitweb /
debian: Replace Debian build system with CDBS.
[mLib] / ident.c
diff --git a/ident.c b/ident.c
index 342dc81551c2d7ac142110ba03465fb131ff4459..c015331b1008d2a4c288c2884773a477ca94a80c 100644 (file)
--- a/ident.c
+++ b/ident.c
@@ -1,13 +1,13 @@
 /* -*-c-*-
  *
- * $Id: ident.c,v 1.1 1999/10/04 21:41:58 mdw Exp $
+ * $Id: ident.c,v 1.6 2004/04/08 01:36:11 mdw Exp $
  *
  * Nonblocking RFC931 client
  *
  * (c) 1999 Mark Wooding
  */
 
-/*----- Licensing notice --------------------------------------------------* 
+/*----- Licensing notice --------------------------------------------------*
  *
  * This file is part of the mLib utilities library.
  *
  * it under the terms of the GNU Library General Public License as
  * published by the Free Software Foundation; either version 2 of the
  * License, or (at your option) any later version.
- * 
+ *
  * mLib is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU Library General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Library General Public
  * License along with mLib; if not, write to the Free
  * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  * MA 02111-1307, USA.
  */
 
-/*----- Revision history --------------------------------------------------* 
- *
- * $Log: ident.c,v $
- * Revision 1.1  1999/10/04 21:41:58  mdw
- * Added ident client from `fw'.
- *
- */
-
 /*----- Header files ------------------------------------------------------*/
 
 #include <ctype.h>
@@ -156,6 +148,7 @@ static void parse(char *p, ident_reply *i)
 /* --- @line@ --- *
  *
  * Arguments:  @char *s@ = pointer to string from ident server
+ *             @size_t len@ = length of the line
  *             @void *p@ = pointer to my request block
  *
  * Returns:    ---
@@ -163,12 +156,11 @@ static void parse(char *p, ident_reply *i)
  * Use:                Handles a string from an ident server.
  */
 
-static void line(char *s, void *p)
+static void line(char *s, size_t len, void *p)
 {
   ident_request *rq = p;
 
   rq->state = IDENT_DONE;
-  selbuf_disable(&rq->b);
   close(rq->b.reader.fd);
   if (!s)
     rq->func(0, rq->p);
@@ -177,6 +169,7 @@ static void line(char *s, void *p)
     parse(s, &i);
     rq->func(&i, rq->p);
   }
+  selbuf_destroy(&rq->b);
 }
 
 /* --- @connected@ --- *
@@ -247,8 +240,8 @@ void ident_abort(ident_request *rq)
       conn_kill(&rq->c);
       break;
     case IDENT_READ:
-      selbuf_disable(&rq->b);
       close(rq->b.reader.fd);
+      selbuf_destroy(&rq->b);
       break;
   }
 }
@@ -269,7 +262,7 @@ static void go(ident_request *rq)
   int opt;
 
   /* --- Create the socket I'll use --- */
-  
+
   if ((fd = socket(PF_INET, SOCK_STREAM, 0)) < 0)
     goto fail_0;
   memset(&sin, 0, sizeof(sin));
@@ -289,8 +282,9 @@ static void go(ident_request *rq)
   sin.sin_family = AF_INET;
   sin.sin_port = htons(113);
   sin.sin_addr = rq->remote.sin_addr;
-  conn_init(&rq->c, rq->s, fd, (struct sockaddr *)&sin, sizeof(sin),
-           connected, rq);
+  if (conn_init(&rq->c, rq->s, fd, (struct sockaddr *)&sin, sizeof(sin),
+               connected, rq))
+    goto fail_1;
 
   /* --- Finish off initializing the block --- */
 
@@ -321,7 +315,7 @@ fail_0:
 
 void ident(ident_request *rq, sel_state *s,
           const struct sockaddr_in *local,
-          const struct sockaddr_in *remote, 
+          const struct sockaddr_in *remote,
           void (*func)(ident_reply */*i*/, void */*p*/),
           void *p)
 {
@@ -354,7 +348,7 @@ void ident_socket(ident_request *rq, sel_state *s, int sk,
                  void (*func)(ident_reply */*i*/, void */*p*/),
                  void *p)
 {
-  int sinsz;
+  size_t sinsz;
   if ((sinsz = sizeof(struct sockaddr_in),
        getsockname(sk, (struct sockaddr *)&rq->local, &sinsz)) ||
       (sinsz = sizeof(struct sockaddr_in),