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