chiark / gitweb /
Various manual fixes.
[mLib] / ident.h
1 /* -*-c-*-
2  *
3  * $Id: ident.h,v 1.3 2004/04/08 01:36:11 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 #ifndef MLIB_IDENT_H
31 #define MLIB_IDENT_H
32
33 #ifdef __cplusplus
34   extern "C" {
35 #endif
36
37 /*----- Header files ------------------------------------------------------*/
38
39 #include <sys/types.h>
40 #include <sys/socket.h>
41 #include <netinet/in.h>
42 #include <arpa/inet.h>
43
44 #ifndef MLIB_CONN_H
45 #  include "conn.h"
46 #endif
47
48 #ifndef MLIB_SEL_H
49 #  include "sel.h"
50 #endif
51
52 #ifndef MLIB_SELBUF_H
53 #  include "selbuf.h"
54 #endif
55
56 /*----- Data structures ---------------------------------------------------*/
57
58 /* --- Parsed response from ident server --- */
59
60 typedef struct ident_reply {
61   unsigned short sport, dport;          /* Source and destination ports */
62   unsigned type;                        /* Type of reply from server */
63   union {
64     struct {
65       char *os;                         /* Operating system name */
66       char *user;                       /* User name */
67     } userid;
68     char *error;                        /* Error message from server */
69   } u;
70 } ident_reply;
71
72 /* --- Response type codes --- */
73
74 enum {
75   IDENT_USERID,
76   IDENT_ERROR,
77   IDENT_BAD
78 };
79
80 /* --- Request structure --- */
81
82 typedef struct ident_request {
83   struct sockaddr_in local, remote;
84   unsigned state;
85   void (*func)(ident_reply */*i*/, void */*p*/);
86   void *p;
87   sel_state *s;
88   conn c;
89   selbuf b;
90 } ident_request;
91
92 enum {
93   IDENT_CONN,
94   IDENT_READ,
95   IDENT_DONE
96 };
97
98 /*----- Functions provided ------------------------------------------------*/
99
100 /* --- @ident_abort@ --- *
101  *
102  * Arguments:   @ident_request *rq@ = pointer to request block
103  *
104  * Returns:     ---
105  *
106  * Use:         Cancels an ident request in progress.
107  */
108
109 extern void ident_abort(ident_request */*rq*/);
110
111 /* --- @ident@ --- *
112  *
113  * Arguments:   @ident_request *rq@ = pointer to request block
114  *              @sel_state *s@ = I/O multiplexor
115  *              @const struct sockaddr_in *local, *remote@ = addresses
116  *              @void (*func)(ident_reply *i, void *p)@ = handler function
117  *              @void *p@ = argument for handler
118  *
119  * Returns:     ---
120  *
121  * Use:         Initializes an ident request.
122  */
123
124 extern void ident(ident_request */*rq*/, sel_state */*s*/,
125                   const struct sockaddr_in */*local*/,
126                   const struct sockaddr_in */*remote*/, 
127                   void (*/*func*/)(ident_reply */*i*/, void */*p*/),
128                   void */*p*/);
129
130 /* --- @ident_socket@ --- *
131  *
132  * Arguments:   @ident_request *rq@ = pointer to request block
133  *              @sel_state *s@ = I/O multiplexor
134  *              @int sk@ = connected socket file descriptor
135  *              @void (*func)(ident_reply *i, void *p)@ = handler function
136  *              @void *p@ = argument for handler
137  *
138  * Returns:     ---
139  *
140  * Use:         An alternative interface to @ident@.  Initializes an ident
141  *              request from a connected socket, rather than from an explicit
142  *              address.  This will call @getsockname@ and @getpeername@ to
143  *              find out what the socket is actually connected to, which adds
144  *              convenience but wastes time.
145  */
146
147 extern void ident_socket(ident_request */*rq*/, sel_state */*s*/, int /*sk*/,
148                          void (*/*func*/)(ident_reply */*i*/, void */*p*/),
149                          void */*p*/);
150
151 /*----- That's all, folks -------------------------------------------------*/
152
153 #ifdef __cplusplus
154   }
155 #endif
156
157 #endif