1 /* 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 /* Since fd_set is large on some platforms (8K on AIX 5.2), this 28 probably shouldn't be allocated in automatic storage. */ 29 struct select_state { 30 int max, nfds; 31 fd_set rfds, wfds, xfds; 32 struct timeval end_time; /* magic: tv_sec==0 => never time out */ 33 }; 34 35 36 /* Select state flags. */ 37 #define SSF_READ 0x01 38 #define SSF_WRITE 0x02 39 #define SSF_EXCEPTION 0x04 40 41 42 static const char *const state_strings[] = { 43 "INITIALIZING", "CONNECTING", "WRITING", "READING", "FAILED" 44 }; 45 46 47 /* connection states */ 48 enum conn_states { INITIALIZING, CONNECTING, WRITING, READING, FAILED }; 49 struct incoming_krb5_message { 50 size_t bufsizebytes_read; 51 size_t bufsize; 52 char *buf; 53 char *pos; 54 unsigned char bufsizebytes[4]; 55 size_t n_left; 56 }; 57 struct conn_state { 58 SOCKET fd; 59 krb5_error_code err; 60 enum conn_states state; 61 unsigned int is_udp : 1; 62 int (*service)(struct conn_state *, struct select_state *, int); 63 struct addrinfo *addr; 64 struct { 65 struct { 66 sg_buf sgbuf[2]; 67 sg_buf *sgp; 68 int sg_count; 69 unsigned char msg_len_buf[4]; 70 } out; 71 struct incoming_krb5_message in; 72 } x; 73 }; 74 75 struct sendto_callback_info { 76 int (*pfn_callback) (struct conn_state *, void *, krb5_data *); 77 void (*pfn_cleanup) (void *, krb5_data *); 78 void *context; 79 }; 80 81 82 krb5_error_code krb5int_cm_call_select (const struct select_state *, 83 struct select_state *, int *); 84