1 /* TN5250 - An implementation of the 5250 telnet protocol. 2 * Copyright (C) 1997-2008 Michael Madore 3 * 4 * This file is part of TN5250. 5 * 6 * TN5250 is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU Lesser General Public License as published by 8 * the Free Software Foundation; either version 2.1, or (at your option) 9 * any later version. 10 * 11 * TN5250 is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public License 17 * along with this software; see the file COPYING. If not, write to 18 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, 19 * Boston, MA 02111-1307 USA 20 * 21 */ 22 #ifndef STREAM5250_H 23 #define STREAM5250_H 24 25 #if WIN32 26 # include <winsock.h> /* Need for SOCKET type. GJS 3/3/2000 */ 27 #endif 28 29 #ifdef HAVE_LIBSSL 30 #include <openssl/ssl.h> 31 #endif 32 33 #ifdef __cplusplus 34 extern "C" { 35 #endif 36 37 #define TN3270_STREAM 0 38 #define TN3270E_STREAM 1 39 #define TN5250_STREAM 2 40 41 struct _Tn5250Config; 42 43 struct Tn5250Header { 44 int flowtype; 45 unsigned char flags; 46 unsigned char opcode; 47 }; 48 49 struct Tn3270Header { 50 unsigned char data_type; 51 unsigned char request_flag; 52 unsigned char response_flag; 53 int sequence; 54 }; 55 56 union _StreamHeader { 57 struct Tn5250Header h5250; 58 struct Tn3270Header h3270; 59 }; 60 61 typedef union _StreamHeader StreamHeader; 62 63 64 /****s* lib5250/Tn5250Stream 65 * NAME 66 * Tn5250Stream 67 * SYNOPSIS 68 * Tn5250Stream *str = tn5250_stream_open ("telnet:my.as400.com"); 69 * Tn5250Record *rec; 70 * tn5250_stream_send_packet (str, 0, TN5250_RECORD_FLOW_DISPLAY, 71 * TN5250_RECORD_H_NONE, TN5250_RECORD_OPCODE_PUT_GET, NULL); 72 * rec = tn5250_stream_get_record (str); 73 * tn5250_stream_disconnect (str); 74 * tn5250_stream_destroy (str); 75 * DESCRIPTION 76 * Tn5250Stream is 'abstract', implementations currently reside in 77 * the telnetstr.c and debug.c source files. A stream object 78 * manages the communications transport, such as TCP/IP. 79 * SOURCE 80 */ 81 #define TN5250_RBSIZE 8192 82 struct _Tn5250Stream { 83 int (* connect) (struct _Tn5250Stream *This, const char *to); 84 int (* accept) (struct _Tn5250Stream *This, SOCKET_TYPE masterSock); 85 void (* disconnect) (struct _Tn5250Stream *This); 86 int (* handle_receive) (struct _Tn5250Stream *This); 87 void (* send_packet) (struct _Tn5250Stream *This, int length, 88 StreamHeader header, unsigned char *data); 89 void (/*@null@*/ * destroy) (struct _Tn5250Stream /*@only@*/ *This); 90 91 struct _Tn5250Config *config; 92 93 Tn5250Record /*@null@*/ *records; 94 Tn5250Record /*@dependent@*/ /*@null@*/ *current_record; 95 int record_count; 96 97 Tn5250Buffer sb_buf; 98 99 SOCKET_TYPE sockfd; 100 int status; 101 int state; 102 int streamtype; 103 long msec_wait; 104 unsigned char options; 105 106 unsigned char rcvbuf[TN5250_RBSIZE]; 107 int rcvbufpos; 108 int rcvbuflen; 109 110 #ifdef HAVE_LIBSSL 111 SSL *ssl_handle; 112 SSL_CTX *ssl_context; 113 void *userdata; 114 #endif 115 116 #ifndef NDEBUG 117 FILE *debugfile; 118 #endif 119 }; 120 121 typedef struct _Tn5250Stream Tn5250Stream; 122 /******/ 123 124 125 extern Tn5250Stream /*@only@*/ /*@null@*/ *tn5250_stream_open (const char *to, struct _Tn5250Config *config); 126 extern int tn5250_stream_config (Tn5250Stream *This, struct _Tn5250Config *config); 127 extern void tn5250_stream_destroy(Tn5250Stream /*@only@*/ * This); 128 extern Tn5250Record /*@only@*/ *tn5250_stream_get_record(Tn5250Stream * This); 129 extern Tn5250Stream *tn5250_stream_host(SOCKET_TYPE masterSock, long timeout, 130 int streamtype); 131 #define tn5250_stream_connect(This,to) \ 132 (* (This->connect)) ((This),(to)) 133 #define tn5250_stream_disconnect(This) \ 134 (* (This->disconnect)) ((This)) 135 #define tn5250_stream_handle_receive(This) \ 136 (* (This->handle_receive)) ((This)) 137 #define tn5250_stream_send_packet(This,len,header,data) \ 138 (* (This->send_packet)) ((This),(len),(header),(data)) 139 140 /* This should be a more flexible replacement for different NEW_ENVIRON 141 * strings. */ 142 extern void tn5250_stream_setenv(Tn5250Stream * This, const char *name, 143 const char /*@null@*/ *value); 144 extern void tn5250_stream_unsetenv(Tn5250Stream * This, const char *name); 145 extern /*@observer@*/ /*@null@*/ const char *tn5250_stream_getenv(Tn5250Stream * This, const char *name); 146 147 #define tn5250_stream_record_count(This) ((This)->record_count) 148 extern int tn5250_stream_socket_handle (Tn5250Stream *This); 149 150 #ifdef __cplusplus 151 } 152 153 #endif 154 #endif 155 156 /* vi:set cindent sts=3 sw=3: */ 157