chiark / gitweb /
Make ADNS wait for the event loop before collecting replies.
[mLib] / ident.h
1 /* -*-c-*-
2  *
3  * $Id: ident.h,v 1.2 1999/12/10 23:42:04 mdw Exp $
4  *
5  * Nonblocking RFC931 client
6  *
7  * (c) 1999 Mark Wooding
8  */
9
10 /*----- Licensing notice --------------------------------------------------* 
11  *
12  * This file is part of the mLib utilities library.
13  *
14  * mLib is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU Library General Public License as
16  * published by the Free Software Foundation; either version 2 of the
17  * License, or (at your option) any later version.
18  * 
19  * mLib is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU Library General Public License for more details.
23  * 
24  * You should have received a copy of the GNU Library General Public
25  * License along with mLib; if not, write to the Free
26  * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
27  * MA 02111-1307, USA.
28  */
29
30 /*----- Revision history --------------------------------------------------* 
31  *
32  * $Log: ident.h,v $
33  * Revision 1.2  1999/12/10 23:42:04  mdw
34  * Change header file guard names.
35  *
36  * Revision 1.1  1999/10/04 21:41:58  mdw
37  * Added ident client from `fw'.
38  *
39  */
40
41 #ifndef MLIB_IDENT_H
42 #define MLIB_IDENT_H
43
44 #ifdef __cplusplus
45   extern "C" {
46 #endif
47
48 /*----- Header files ------------------------------------------------------*/
49
50 #include <sys/types.h>
51 #include <sys/socket.h>
52 #include <netinet/in.h>
53 #include <arpa/inet.h>
54
55 #ifndef MLIB_CONN_H
56 #  include "conn.h"
57 #endif
58
59 #ifndef MLIB_SEL_H
60 #  include "sel.h"
61 #endif
62
63 #ifndef MLIB_SELBUF_H
64 #  include "selbuf.h"
65 #endif
66
67 /*----- Data structures ---------------------------------------------------*/
68
69 /* --- Parsed response from ident server --- */
70
71 typedef struct ident_reply {
72   unsigned short sport, dport;          /* Source and destination ports */
73   unsigned type;                        /* Type of reply from server */
74   union {
75     struct {
76       char *os;                         /* Operating system name */
77       char *user;                       /* User name */
78     } userid;
79     char *error;                        /* Error message from server */
80   } u;
81 } ident_reply;
82
83 /* --- Response type codes --- */
84
85 enum {
86   IDENT_USERID,
87   IDENT_ERROR,
88   IDENT_BAD
89 };
90
91 /* --- Request structure --- */
92
93 typedef struct ident_request {
94   struct sockaddr_in local, remote;
95   unsigned state;
96   void (*func)(ident_reply */*i*/, void */*p*/);
97   void *p;
98   sel_state *s;
99   conn c;
100   selbuf b;
101 } ident_request;
102
103 enum {
104   IDENT_CONN,
105   IDENT_READ,
106   IDENT_DONE
107 };
108
109 /*----- Functions provided ------------------------------------------------*/
110
111 /* --- @ident_abort@ --- *
112  *
113  * Arguments:   @ident_request *rq@ = pointer to request block
114  *
115  * Returns:     ---
116  *
117  * Use:         Cancels an ident request in progress.
118  */
119
120 extern void ident_abort(ident_request */*rq*/);
121
122 /* --- @ident@ --- *
123  *
124  * Arguments:   @ident_request *rq@ = pointer to request block
125  *              @sel_state *s@ = I/O multiplexor
126  *              @const struct sockaddr_in *local, *remote@ = addresses
127  *              @void (*func)(ident_reply *i, void *p)@ = handler function
128  *              @void *p@ = argument for handler
129  *
130  * Returns:     ---
131  *
132  * Use:         Initializes an ident request.
133  */
134
135 extern void ident(ident_request */*rq*/, sel_state */*s*/,
136                   const struct sockaddr_in */*local*/,
137                   const struct sockaddr_in */*remote*/, 
138                   void (*/*func*/)(ident_reply */*i*/, void */*p*/),
139                   void */*p*/);
140
141 /* --- @ident_socket@ --- *
142  *
143  * Arguments:   @ident_request *rq@ = pointer to request block
144  *              @sel_state *s@ = I/O multiplexor
145  *              @int sk@ = connected socket file descriptor
146  *              @void (*func)(ident_reply *i, void *p)@ = handler function
147  *              @void *p@ = argument for handler
148  *
149  * Returns:     ---
150  *
151  * Use:         An alternative interface to @ident@.  Initializes an ident
152  *              request from a connected socket, rather than from an explicit
153  *              address.  This will call @getsockname@ and @getpeername@ to
154  *              find out what the socket is actually connected to, which adds
155  *              convenience but wastes time.
156  */
157
158 extern void ident_socket(ident_request */*rq*/, sel_state */*s*/, int /*sk*/,
159                          void (*/*func*/)(ident_reply */*i*/, void */*p*/),
160                          void */*p*/);
161
162 /*----- That's all, folks -------------------------------------------------*/
163
164 #ifdef __cplusplus
165   }
166 #endif
167
168 #endif