Automate RST HTML generation with doxygen info
[krb5.git] / src / include / cm.h
1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* include/cm.h */
3 /*
4  * Copyright 2002 by the Massachusetts Institute of Technology.
5  * All Rights Reserved.
6  *
7  * Export of this software from the United States of America may
8  *   require a specific license from the United States Government.
9  *   It is the responsibility of any person or organization contemplating
10  *   export to obtain such a license before exporting.
11  *
12  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13  * distribute this software and its documentation for any purpose and
14  * without fee is hereby granted, provided that the above copyright
15  * notice appear in all copies and that both that copyright notice and
16  * this permission notice appear in supporting documentation, and that
17  * the name of M.I.T. not be used in advertising or publicity pertaining
18  * to distribution of the software without specific, written prior
19  * permission.  Furthermore if you modify this software you must label
20  * your software as modified software and not distribute it in such a
21  * fashion that it might be confused with the original M.I.T. software.
22  * M.I.T. makes no representations about the suitability of
23  * this software for any purpose.  It is provided "as is" without express
24  * or implied warranty.
25  */
26
27 /*
28  * Since fd_set is large on some platforms (8K on AIX 5.2), this probably
29  * shouldn't be allocated in automatic storage.  Define USE_POLL and
30  * MAX_POLLFDS in the consumer of this header file to use poll state instead of
31  * select state.
32  */
33 struct select_state {
34 #ifdef USE_POLL
35     struct pollfd fds[MAX_POLLFDS];
36 #else
37     int max;
38     fd_set rfds, wfds, xfds;
39 #endif
40     int nfds;
41     struct timeval end_time;    /* magic: tv_sec==0 => never time out */
42 };
43
44
45 /* Select state flags.  */
46 #define SSF_READ        0x01
47 #define SSF_WRITE       0x02
48 #define SSF_EXCEPTION   0x04
49
50
51 static const char *const state_strings[] = {
52     "INITIALIZING", "CONNECTING", "WRITING", "READING", "FAILED"
53 };
54
55
56 /* connection states */
57 enum conn_states { INITIALIZING, CONNECTING, WRITING, READING, FAILED };
58 struct incoming_krb5_message {
59     size_t bufsizebytes_read;
60     size_t bufsize;
61     char *buf;
62     char *pos;
63     unsigned char bufsizebytes[4];
64     size_t n_left;
65 };
66 struct conn_state {
67     SOCKET fd;
68     krb5_error_code err;
69     enum conn_states state;
70     unsigned int is_udp : 1;
71     int (*service)(krb5_context context, struct conn_state *,
72                    struct select_state *, int);
73     int socktype;
74     int family;
75     size_t addrlen;
76     struct sockaddr_storage addr;
77     struct {
78         struct {
79             sg_buf sgbuf[2];
80             sg_buf *sgp;
81             int sg_count;
82             unsigned char msg_len_buf[4];
83         } out;
84         struct incoming_krb5_message in;
85     } x;
86     krb5_data callback_buffer;
87     size_t server_index;
88     struct conn_state *next;
89 };
90
91 struct sendto_callback_info {
92     int  (*pfn_callback) (struct conn_state *, void *, krb5_data *);
93     void (*pfn_cleanup)  (void *, krb5_data *);
94     void  *context;
95 };
96
97
98 krb5_error_code krb5int_cm_call_select (const struct select_state *,
99                                         struct select_state *, int *);