Commit 3ec6fb96766c4182b93d39a9ae1a6fb13e02dddd

Authored by perry.werneck@gmail.com
1 parent 770f6a8e

Incluindo suporte multi-sessão em mais métodos

src/include/lib3270/filetransfer.h
@@ -91,6 +91,10 @@ @@ -91,6 +91,10 @@
91 const char * local; /**< Local filename */ 91 const char * local; /**< Local filename */
92 const char * remote; /**< Remote filename */ 92 const char * remote; /**< Remote filename */
93 93
  94 + // ft_dft.c
  95 + char * abort_string;
  96 +
  97 + // Callbacks
94 void (*complete)(struct _h3270ft *ft,unsigned long length,double kbytes_sec,const char *mode); 98 void (*complete)(struct _h3270ft *ft,unsigned long length,double kbytes_sec,const char *mode);
95 void (*message)(struct _h3270ft *ft, const char *msg); 99 void (*message)(struct _h3270ft *ft, const char *msg);
96 void (*update)(struct _h3270ft *ft, unsigned long current, unsigned long length, double kbytes_sec); 100 void (*update)(struct _h3270ft *ft, unsigned long current, unsigned long length, double kbytes_sec);
@@ -117,12 +121,12 @@ @@ -117,12 +121,12 @@
117 * @return Filetransfer handle if ok, NULL if failed 121 * @return Filetransfer handle if ok, NULL if failed
118 * 122 *
119 */ 123 */
120 - LIB3270_EXPORT H3270FT * lib3270_ft_new(H3270 *session, LIB3270_FT_OPTION flags, const char *local, const char *remote, int lrecl, int blksize, int primspace, int secspace, int dft, const char **msg); 124 + LIB3270_EXPORT H3270FT * lib3270_ft_new(H3270 *hSession, LIB3270_FT_OPTION flags, const char *local, const char *remote, int lrecl, int blksize, int primspace, int secspace, int dft, const char **msg);
121 125
122 - LIB3270_EXPORT int lib3270_ft_start(H3270FT *ft);  
123 - LIB3270_EXPORT void lib3270_ft_destroy(H3270FT *ft); 126 + LIB3270_EXPORT int lib3270_ft_start(H3270 *hSession);
  127 + LIB3270_EXPORT int lib3270_ft_destroy(H3270 *hSession);
124 128
125 - LIB3270_EXPORT int lib3270_ft_cancel(H3270FT *ft, int force); 129 + LIB3270_EXPORT int lib3270_ft_cancel(H3270 *hSession, int force);
126 130
127 131
128 LIB3270_EXPORT LIB3270_FT_STATE lib3270_get_ft_state(H3270 *session); 132 LIB3270_EXPORT LIB3270_FT_STATE lib3270_get_ft_state(H3270 *session);
src/lib3270/ctlr.c
@@ -484,7 +484,7 @@ enum pds process_ds(H3270 *hSession, unsigned char *buf, int buflen) @@ -484,7 +484,7 @@ enum pds process_ds(H3270 *hSession, unsigned char *buf, int buflen)
484 case CMD_WSF: /* write structured field */ 484 case CMD_WSF: /* write structured field */
485 case SNA_CMD_WSF: 485 case SNA_CMD_WSF:
486 trace_ds(hSession,"WriteStructuredField"); 486 trace_ds(hSession,"WriteStructuredField");
487 - return write_structured_field(buf, buflen); 487 + return write_structured_field(hSession,buf, buflen);
488 break; 488 break;
489 489
490 case CMD_NOP: /* no-op */ 490 case CMD_NOP: /* no-op */
src/lib3270/ft.c
@@ -113,39 +113,24 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); @@ -113,39 +113,24 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state);
113 113
114 } 114 }
115 115
116 - void ft_init(H3270 *session) 116 + void ft_init(H3270 *hSession)
117 { 117 {
118 /* Register for state changes. */ 118 /* Register for state changes. */
119 - lib3270_register_schange(session, LIB3270_STATE_CONNECT, ( void (*)(H3270 *, int, void *)) ft_connected, NULL);  
120 - lib3270_register_schange(session, LIB3270_STATE_3270_MODE, ( void (*)(H3270 *, int, void *)) ft_in3270, NULL); 119 + lib3270_register_schange(hSession, LIB3270_STATE_CONNECT, ( void (*)(H3270 *, int, void *)) ft_connected, NULL);
  120 + lib3270_register_schange(hSession, LIB3270_STATE_3270_MODE, ( void (*)(H3270 *, int, void *)) ft_in3270, NULL);
121 } 121 }
122 122
123 -// enum ft_state QueryFTstate(void)  
124 -// {  
125 -// return ft_state;  
126 -// }  
127 -  
128 -/*  
129 - int RegisterFTCallbacks(const struct filetransfer_callbacks *cbk) 123 + LIB3270_EXPORT int lib3270_ft_cancel(H3270 *hSession, int force)
130 { 124 {
131 - if(!(cbk && cbk->sz == sizeof(struct filetransfer_callbacks)) )  
132 - return EINVAL; 125 + H3270FT *ft;
133 126
134 - callbacks = cbk; 127 + CHECK_SESSION_HANDLE(hSession);
135 128
136 - return 0;  
137 - }  
138 -*/ 129 + ft = (H3270FT *) hSession->ft;
  130 + if(!ft)
  131 + return EINVAL;
139 132
140 -/*  
141 - enum ft_state GetFileTransferState(void)  
142 - {  
143 - return ft_state;  
144 - }  
145 -*/  
146 133
147 - LIB3270_EXPORT int lib3270_ft_cancel(H3270FT *ft, int force)  
148 - {  
149 if (ft->state == LIB3270_FT_STATE_RUNNING) 134 if (ft->state == LIB3270_FT_STATE_RUNNING)
150 { 135 {
151 set_ft_state(ft,LIB3270_FT_STATE_ABORT_WAIT); 136 set_ft_state(ft,LIB3270_FT_STATE_ABORT_WAIT);
@@ -276,7 +261,7 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); @@ -276,7 +261,7 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state);
276 return ftsession = ftHandle; 261 return ftsession = ftHandle;
277 } 262 }
278 263
279 - LIB3270_EXPORT int lib3270_ft_start(H3270FT *ft) 264 + LIB3270_EXPORT int lib3270_ft_start(H3270 *hSession)
280 { 265 {
281 static const char * rec = "fvu"; 266 static const char * rec = "fvu";
282 static const char * un[] = { "tracks", "cylinders", "avblock" }; 267 static const char * un[] = { "tracks", "cylinders", "avblock" };
@@ -286,8 +271,13 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); @@ -286,8 +271,13 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state);
286 unsigned int flen; 271 unsigned int flen;
287 unsigned short recfm; 272 unsigned short recfm;
288 unsigned short units; 273 unsigned short units;
  274 + H3270FT * ft;
289 275
290 - CHECK_FT_HANDLE(ft); 276 + CHECK_SESSION_HANDLE(hSession);
  277 +
  278 + ft = (H3270FT *) hSession->ft;
  279 + if(!ft)
  280 + return EINVAL;
291 281
292 recfm = (ft->flags & FT_RECORD_FORMAT_MASK) >> 8; 282 recfm = (ft->flags & FT_RECORD_FORMAT_MASK) >> 8;
293 units = (ft->flags & FT_ALLOCATION_UNITS_MASK) >> 12; 283 units = (ft->flags & FT_ALLOCATION_UNITS_MASK) >> 12;
@@ -438,12 +428,18 @@ void ft_complete(H3270FT *session, const char *errmsg) @@ -438,12 +428,18 @@ void ft_complete(H3270FT *session, const char *errmsg)
438 428
439 } 429 }
440 430
441 -LIB3270_EXPORT void lib3270_ft_destroy(H3270FT *session) 431 +LIB3270_EXPORT int lib3270_ft_destroy(H3270 *hSession)
442 { 432 {
443 - CHECK_FT_HANDLE(session); 433 + H3270FT *session;
  434 +
  435 + CHECK_SESSION_HANDLE(hSession);
  436 +
  437 + session = (H3270FT *) hSession->ft;
  438 + if(!session)
  439 + return EINVAL;
444 440
445 if (session->state != LIB3270_FT_STATE_NONE) 441 if (session->state != LIB3270_FT_STATE_NONE)
446 - lib3270_ft_cancel(session,1); 442 + lib3270_ft_cancel(hSession,1);
447 443
448 if(session->local_file) 444 if(session->local_file)
449 { 445 {
@@ -454,11 +450,11 @@ LIB3270_EXPORT void lib3270_ft_destroy(H3270FT *session) @@ -454,11 +450,11 @@ LIB3270_EXPORT void lib3270_ft_destroy(H3270FT *session)
454 if(session == ftsession) 450 if(session == ftsession)
455 ftsession = NULL; 451 ftsession = NULL;
456 452
457 - if(session->host)  
458 - session->host->ft = NULL; 453 + hSession->ft = NULL;
459 454
460 free(session); 455 free(session);
461 456
  457 + return 0;
462 } 458 }
463 459
464 // Update the bytes-transferred count on the progress pop-up. 460 // Update the bytes-transferred count on the progress pop-up.
src/lib3270/ft_dft.c
@@ -83,20 +83,20 @@ struct data_buffer { @@ -83,20 +83,20 @@ struct data_buffer {
83 static Boolean message_flag = False; /* Open Request for msg received */ 83 static Boolean message_flag = False; /* Open Request for msg received */
84 static int dft_eof; 84 static int dft_eof;
85 static unsigned long recnum; 85 static unsigned long recnum;
86 -static char *abort_string = CN; 86 +// static char *abort_string = CN;
87 static unsigned char *dft_savebuf = NULL; 87 static unsigned char *dft_savebuf = NULL;
88 static int dft_savebuf_len = 0; 88 static int dft_savebuf_len = 0;
89 static int dft_savebuf_max = 0; 89 static int dft_savebuf_max = 0;
90 90
91 -static void dft_abort(unsigned short code, const char *fmt, ...); 91 +static void dft_abort(H3270 *hSession, unsigned short code, const char *fmt, ...);
92 92
93 -static void dft_close_request(void);  
94 -static void dft_data_insert(struct data_buffer *data_bufr);  
95 -static void dft_get_request(void);  
96 -static void dft_insert_request(void);  
97 -static void dft_open_request(unsigned short len, unsigned char *cp);  
98 -static void dft_set_cur_req(void);  
99 -static int filter_len(char *s, register int len); 93 +static void dft_close_request(H3270 *hSession);
  94 +static void dft_data_insert(H3270 *hSession, struct data_buffer *data_bufr);
  95 +static void dft_get_request(H3270 *hSession);
  96 +static void dft_insert_request(H3270 *hSession);
  97 +static void dft_open_request(H3270 *hSession, unsigned short len, unsigned char *cp);
  98 +static void dft_set_cur_req(H3270 *hSession);
  99 +static int filter_len(char *s, register int len);
100 100
101 /** 101 /**
102 * Process a Transfer Data structured field from the host. 102 * Process a Transfer Data structured field from the host.
@@ -108,9 +108,9 @@ void ft_dft_data(H3270 *hSession, unsigned char *data, int length unused) @@ -108,9 +108,9 @@ void ft_dft_data(H3270 *hSession, unsigned char *data, int length unused)
108 unsigned short data_length, data_type; 108 unsigned short data_length, data_type;
109 unsigned char *cp; 109 unsigned char *cp;
110 110
111 - if (lib3270_get_ft_state(&h3270) == FT_NONE) 111 + if (lib3270_get_ft_state(hSession) == FT_NONE)
112 { 112 {
113 - trace_ds(&h3270," (no transfer in progress)\n"); 113 + trace_ds(hSession," (no transfer in progress)\n");
114 return; 114 return;
115 } 115 }
116 116
@@ -123,104 +123,120 @@ void ft_dft_data(H3270 *hSession, unsigned char *data, int length unused) @@ -123,104 +123,120 @@ void ft_dft_data(H3270 *hSession, unsigned char *data, int length unused)
123 GET16(data_type, cp); 123 GET16(data_type, cp);
124 124
125 /* Handle the requests */ 125 /* Handle the requests */
126 - switch (data_type) {  
127 - case TR_OPEN_REQ:  
128 - dft_open_request(data_length, cp); 126 + switch (data_type)
  127 + {
  128 + case TR_OPEN_REQ:
  129 + dft_open_request(hSession,data_length, cp);
129 break; 130 break;
130 - case TR_INSERT_REQ: /* Insert Request */  
131 - dft_insert_request(); 131 +
  132 + case TR_INSERT_REQ: /* Insert Request */
  133 + dft_insert_request(hSession);
132 break; 134 break;
133 - case TR_DATA_INSERT:  
134 - dft_data_insert(data_bufr); 135 +
  136 + case TR_DATA_INSERT:
  137 + dft_data_insert(hSession,data_bufr);
135 break; 138 break;
136 - case TR_SET_CUR_REQ:  
137 - dft_set_cur_req(); 139 +
  140 + case TR_SET_CUR_REQ:
  141 + dft_set_cur_req(hSession);
138 break; 142 break;
139 - case TR_GET_REQ:  
140 - dft_get_request(); 143 +
  144 + case TR_GET_REQ:
  145 + dft_get_request(hSession);
141 break; 146 break;
142 - case TR_CLOSE_REQ:  
143 - dft_close_request(); 147 +
  148 + case TR_CLOSE_REQ:
  149 + dft_close_request(hSession);
144 break; 150 break;
145 - default:  
146 - trace_ds(&h3270," Unsupported(0x%04x)\n", data_type); 151 +
  152 + default:
  153 + trace_ds(hSession," Unsupported(0x%04x)\n", data_type);
147 break; 154 break;
148 } 155 }
149 } 156 }
150 157
151 /* Process an Open request. */ 158 /* Process an Open request. */
152 -static void  
153 -dft_open_request(unsigned short len, unsigned char *cp) 159 +static void dft_open_request(H3270 *hSession, unsigned short len, unsigned char *cp)
154 { 160 {
155 char *name = "?"; 161 char *name = "?";
156 char namebuf[8]; 162 char namebuf[8];
157 char *s; 163 char *s;
158 unsigned short recsz = 0; 164 unsigned short recsz = 0;
159 165
160 - if (len == 0x23) { 166 + if (len == 0x23)
  167 + {
161 name = (char *)cp + 25; 168 name = (char *)cp + 25;
162 - } else if (len == 0x29) { 169 + }
  170 + else if (len == 0x29)
  171 + {
163 unsigned char *recszp; 172 unsigned char *recszp;
164 173
165 recszp = cp + 27; 174 recszp = cp + 27;
166 GET16(recsz, recszp); 175 GET16(recsz, recszp);
167 name = (char *)cp + 31; 176 name = (char *)cp + 31;
168 - } else {  
169 - dft_abort(TR_OPEN_REQ, "%s", _("Uknown DFT Open type from host") ); 177 + }
  178 + else
  179 + {
  180 + dft_abort(hSession,TR_OPEN_REQ, "%s", _("Uknown DFT Open type from host") );
170 return; 181 return;
171 } 182 }
172 183
173 (void) memcpy(namebuf, name, 7); 184 (void) memcpy(namebuf, name, 7);
174 namebuf[7] = '\0'; 185 namebuf[7] = '\0';
175 s = &namebuf[6]; 186 s = &namebuf[6];
176 - while (s >= namebuf && *s == ' ') { 187 + while (s >= namebuf && *s == ' ')
  188 + {
177 *s-- = '\0'; 189 *s-- = '\0';
178 } 190 }
179 - if (recsz) {  
180 - trace_ds(&h3270," Open('%s',recsz=%u)\n", namebuf, recsz);  
181 - } else {  
182 - trace_ds(&h3270," Open('%s')\n", namebuf); 191 +
  192 + if (recsz)
  193 + {
  194 + trace_ds(hSession," Open('%s',recsz=%u)\n", namebuf, recsz);
  195 + }
  196 + else
  197 + {
  198 + trace_ds(hSession," Open('%s')\n", namebuf);
183 } 199 }
184 200
185 if (!strcmp(namebuf, OPEN_MSG)) 201 if (!strcmp(namebuf, OPEN_MSG))
186 message_flag = True; 202 message_flag = True;
187 - else { 203 + else
  204 + {
188 message_flag = False; 205 message_flag = False;
189 - ft_running(NULL,False); 206 + ft_running(hSession->ft,False);
190 } 207 }
  208 +
191 dft_eof = False; 209 dft_eof = False;
192 recnum = 1; 210 recnum = 1;
193 211
194 /* Acknowledge the Open. */ 212 /* Acknowledge the Open. */
195 - trace_ds(&h3270,"> WriteStructuredField FileTransferData OpenAck\n");  
196 - h3270.obptr = h3270.obuf;  
197 - space3270out(&h3270,6);  
198 - *h3270.obptr++ = AID_SF;  
199 - SET16(h3270.obptr, 5);  
200 - *h3270.obptr++ = SF_TRANSFER_DATA;  
201 - SET16(h3270.obptr, 9);  
202 - net_output(&h3270); 213 + trace_ds(hSession,"> WriteStructuredField FileTransferData OpenAck\n");
  214 + hSession->obptr = hSession->obuf;
  215 + space3270out(hSession,6);
  216 + *hSession->obptr++ = AID_SF;
  217 + SET16(hSession->obptr, 5);
  218 + *hSession->obptr++ = SF_TRANSFER_DATA;
  219 + SET16(hSession->obptr, 9);
  220 + net_output(hSession);
203 } 221 }
204 222
205 /* Process an Insert request. */ 223 /* Process an Insert request. */
206 -static void  
207 -dft_insert_request(void) 224 +static void dft_insert_request(H3270 *hSession)
208 { 225 {
209 - trace_ds(&h3270," Insert\n"); 226 + trace_ds(hSession," Insert\n");
210 /* Doesn't currently do anything. */ 227 /* Doesn't currently do anything. */
211 } 228 }
212 229
213 /* Process a Data Insert request. */ 230 /* Process a Data Insert request. */
214 -static void  
215 -dft_data_insert(struct data_buffer *data_bufr) 231 +static void dft_data_insert(H3270 *hSession, struct data_buffer *data_bufr)
216 { 232 {
217 /* Received a data buffer, get the length and process it */ 233 /* Received a data buffer, get the length and process it */
218 int my_length; 234 int my_length;
219 unsigned char *cp; 235 unsigned char *cp;
220 236
221 - if(!message_flag && lib3270_get_ft_state(&h3270) == FT_ABORT_WAIT) 237 + if(!message_flag && lib3270_get_ft_state(hSession) == FT_ABORT_WAIT)
222 { 238 {
223 - dft_abort(TR_DATA_INSERT, "%s", _("Transfer cancelled by user") ); 239 + dft_abort(hSession,TR_DATA_INSERT, "%s", _("Transfer cancelled by user") );
224 return; 240 return;
225 } 241 }
226 242
@@ -232,13 +248,14 @@ dft_data_insert(struct data_buffer *data_bufr) @@ -232,13 +248,14 @@ dft_data_insert(struct data_buffer *data_bufr)
232 /* Adjust for 5 extra count */ 248 /* Adjust for 5 extra count */
233 my_length -= 5; 249 my_length -= 5;
234 250
235 - trace_ds(&h3270," Data(rec=%lu) %d bytes\n", recnum, my_length); 251 + trace_ds(hSession," Data(rec=%lu) %d bytes\n", recnum, my_length);
236 252
237 /* 253 /*
238 * First, check to see if we have message data or file data. 254 * First, check to see if we have message data or file data.
239 * Message data will result in a popup. 255 * Message data will result in a popup.
240 */ 256 */
241 - if (message_flag) { 257 + if (message_flag)
  258 + {
242 /* Data is from a message */ 259 /* Data is from a message */
243 unsigned char *msgp; 260 unsigned char *msgp;
244 unsigned char *dollarp; 261 unsigned char *dollarp;
@@ -259,13 +276,17 @@ dft_data_insert(struct data_buffer *data_bufr) @@ -259,13 +276,17 @@ dft_data_insert(struct data_buffer *data_bufr)
259 /* If transfer completed ok, use our msg. */ 276 /* If transfer completed ok, use our msg. */
260 if (memcmp(msgp, END_TRANSFER, strlen(END_TRANSFER)) == 0) { 277 if (memcmp(msgp, END_TRANSFER, strlen(END_TRANSFER)) == 0) {
261 lib3270_free(msgp); 278 lib3270_free(msgp);
262 - ft_complete(NULL,NULL);  
263 - } else if (lib3270_get_ft_state(&h3270) == FT_ABORT_SENT && abort_string != CN) { 279 + ft_complete(hSession->ft,NULL);
  280 + }
  281 + else if (lib3270_get_ft_state(hSession) == FT_ABORT_SENT && ((H3270FT *) hSession->ft)->abort_string != CN)
  282 + {
264 lib3270_free(msgp); 283 lib3270_free(msgp);
265 - ft_complete(NULL,abort_string);  
266 - Replace(abort_string, CN);  
267 - } else {  
268 - ft_complete(NULL,(char *)msgp); 284 + ft_complete(hSession->ft,((H3270FT *) hSession->ft)->abort_string);
  285 + lib3270_free(((H3270FT *) hSession->ft)->abort_string);
  286 + }
  287 + else
  288 + {
  289 + ft_complete(hSession->ft,(char *)msgp);
269 lib3270_free(msgp); 290 lib3270_free(msgp);
270 } 291 }
271 } else if (my_length > 0) { 292 } else if (my_length > 0) {
@@ -309,56 +330,56 @@ dft_data_insert(struct data_buffer *data_bufr) @@ -309,56 +330,56 @@ dft_data_insert(struct data_buffer *data_bufr)
309 330
310 if (!rv) { 331 if (!rv) {
311 /* write failed */ 332 /* write failed */
312 - dft_abort(TR_DATA_INSERT, _( "Error \"%s\" writing to local file (rc=%d)" ) , strerror(errno), errno); 333 + dft_abort(hSession,TR_DATA_INSERT, _( "Error \"%s\" writing to local file (rc=%d)" ) , strerror(errno), errno);
313 } 334 }
314 335
315 /* Add up amount transferred. */ 336 /* Add up amount transferred. */
316 - ft_update_length((H3270FT *) h3270.ft); 337 + ft_update_length((H3270FT *) hSession->ft);
317 } 338 }
318 339
319 /* Send an acknowledgement frame back. */ 340 /* Send an acknowledgement frame back. */
320 - trace_ds(&h3270,"> WriteStructuredField FileTransferData DataAck(rec=%lu)\n", recnum);  
321 - h3270.obptr = h3270.obuf;  
322 - space3270out(&h3270,12);  
323 - *h3270.obptr++ = AID_SF;  
324 - SET16(h3270.obptr, 11);  
325 - *h3270.obptr++ = SF_TRANSFER_DATA;  
326 - SET16(h3270.obptr, TR_NORMAL_REPLY);  
327 - SET16(h3270.obptr, TR_RECNUM_HDR);  
328 - SET32(h3270.obptr, recnum); 341 + trace_ds(hSession,"> WriteStructuredField FileTransferData DataAck(rec=%lu)\n", recnum);
  342 + hSession->obptr = hSession->obuf;
  343 + space3270out(hSession,12);
  344 + *hSession->obptr++ = AID_SF;
  345 + SET16(hSession->obptr, 11);
  346 + *hSession->obptr++ = SF_TRANSFER_DATA;
  347 + SET16(hSession->obptr, TR_NORMAL_REPLY);
  348 + SET16(hSession->obptr, TR_RECNUM_HDR);
  349 + SET32(hSession->obptr, recnum);
329 recnum++; 350 recnum++;
330 - net_output(&h3270); 351 + net_output(hSession);
331 } 352 }
332 353
333 /* Process a Set Cursor request. */ 354 /* Process a Set Cursor request. */
334 -static void  
335 -dft_set_cur_req(void) 355 +static void dft_set_cur_req(H3270 *hSession)
336 { 356 {
337 - trace_ds(&h3270," SetCursor\n"); 357 + trace_ds(hSession," SetCursor\n");
338 /* Currently doesn't do anything. */ 358 /* Currently doesn't do anything. */
339 } 359 }
340 360
341 /* Process a Get request. */ 361 /* Process a Get request. */
342 -static void  
343 -dft_get_request(void) 362 +static void dft_get_request(H3270 *hSession)
344 { 363 {
345 int numbytes; 364 int numbytes;
346 size_t numread; 365 size_t numread;
347 size_t total_read = 0; 366 size_t total_read = 0;
348 unsigned char *bufptr; 367 unsigned char *bufptr;
349 368
350 - trace_ds(&h3270," Get\n"); 369 + trace_ds(hSession," Get\n");
351 370
352 - if (!message_flag && lib3270_get_ft_state(&h3270) == FT_ABORT_WAIT) {  
353 - dft_abort(TR_GET_REQ, _( "Transfer cancelled by user" ) ); 371 + if (!message_flag && lib3270_get_ft_state(hSession) == FT_ABORT_WAIT)
  372 + {
  373 + dft_abort(hSession,TR_GET_REQ, _( "Transfer cancelled by user" ) );
354 return; 374 return;
355 } 375 }
356 376
357 /* Read a buffer's worth. */ 377 /* Read a buffer's worth. */
358 - set_dft_buffersize(&h3270);  
359 - space3270out(&h3270,h3270.dft_buffersize); 378 + set_dft_buffersize(hSession);
  379 + space3270out(hSession,h3270.dft_buffersize);
360 numbytes = h3270.dft_buffersize - 27; /* always read 5 bytes less than we're allowed */ 380 numbytes = h3270.dft_buffersize - 27; /* always read 5 bytes less than we're allowed */
361 bufptr = h3270.obuf + 17; 381 bufptr = h3270.obuf + 17;
  382 +
362 while (!dft_eof && numbytes) { 383 while (!dft_eof && numbytes) {
363 if (ascii_flag && cr_flag) { 384 if (ascii_flag && cr_flag) {
364 int c; 385 int c;
@@ -411,9 +432,9 @@ dft_get_request(void) @@ -411,9 +432,9 @@ dft_get_request(void)
411 } 432 }
412 433
413 /* Check for read error. */ 434 /* Check for read error. */
414 - if (ferror(((H3270FT *) h3270.ft)->local_file)) 435 + if (ferror(((H3270FT *) hSession->ft)->local_file))
415 { 436 {
416 - dft_abort(TR_GET_REQ, _( "Error \"%s\" reading from local file (rc=%d)" ), strerror(errno), errno); 437 + dft_abort(hSession,TR_GET_REQ, _( "Error \"%s\" reading from local file (rc=%d)" ), strerror(errno), errno);
417 return; 438 return;
418 } 439 }
419 440
@@ -424,7 +445,7 @@ dft_get_request(void) @@ -424,7 +445,7 @@ dft_get_request(void)
424 *h3270.obptr++ = SF_TRANSFER_DATA; 445 *h3270.obptr++ = SF_TRANSFER_DATA;
425 446
426 if (total_read) { 447 if (total_read) {
427 - trace_ds(&h3270,"> WriteStructuredField FileTransferData Data(rec=%lu) %d bytes\n",(unsigned long) recnum, (int) total_read); 448 + trace_ds(hSession,"> WriteStructuredField FileTransferData Data(rec=%lu) %d bytes\n",(unsigned long) recnum, (int) total_read);
428 SET16(h3270.obptr, TR_GET_REPLY); 449 SET16(h3270.obptr, TR_GET_REPLY);
429 SET16(h3270.obptr, TR_RECNUM_HDR); 450 SET16(h3270.obptr, TR_RECNUM_HDR);
430 SET32(h3270.obptr, recnum); 451 SET32(h3270.obptr, recnum);
@@ -442,7 +463,7 @@ dft_get_request(void) @@ -442,7 +463,7 @@ dft_get_request(void)
442 } 463 }
443 464
444 } else { 465 } else {
445 - trace_ds(&h3270,"> WriteStructuredField FileTransferData EOF\n"); 466 + trace_ds(hSession,"> WriteStructuredField FileTransferData EOF\n");
446 *h3270.obptr++ = HIGH8(TR_GET_REQ); 467 *h3270.obptr++ = HIGH8(TR_GET_REQ);
447 *h3270.obptr++ = TR_ERROR_REPLY; 468 *h3270.obptr++ = TR_ERROR_REPLY;
448 SET16(h3270.obptr, TR_ERROR_HDR); 469 SET16(h3270.obptr, TR_ERROR_HDR);
@@ -465,56 +486,55 @@ dft_get_request(void) @@ -465,56 +486,55 @@ dft_get_request(void)
465 h3270.aid = AID_SF; 486 h3270.aid = AID_SF;
466 487
467 /* Write the data. */ 488 /* Write the data. */
468 - net_output(&h3270); 489 + net_output(hSession);
469 ft_update_length((H3270FT *) h3270.ft); 490 ft_update_length((H3270FT *) h3270.ft);
470 } 491 }
471 492
472 /* Process a Close request. */ 493 /* Process a Close request. */
473 -static void  
474 -dft_close_request(void) 494 +static void dft_close_request(H3270 *hSession)
475 { 495 {
476 /* 496 /*
477 * Recieved a close request from the system. 497 * Recieved a close request from the system.
478 * Return a close acknowledgement. 498 * Return a close acknowledgement.
479 */ 499 */
480 - trace_ds(&h3270," Close\n");  
481 - trace_ds(&h3270,"> WriteStructuredField FileTransferData CloseAck\n");  
482 - h3270.obptr = h3270.obuf;  
483 - space3270out(&h3270,6);  
484 - *h3270.obptr++ = AID_SF;  
485 - SET16(h3270.obptr, 5); /* length */  
486 - *h3270.obptr++ = SF_TRANSFER_DATA;  
487 - SET16(h3270.obptr, TR_CLOSE_REPLY);  
488 - net_output(&h3270); 500 + trace_ds(hSession," Close\n");
  501 + trace_ds(hSession,"> WriteStructuredField FileTransferData CloseAck\n");
  502 + hSession->obptr = hSession->obuf;
  503 + space3270out(hSession,6);
  504 + *hSession->obptr++ = AID_SF;
  505 + SET16(hSession->obptr, 5); /* length */
  506 + *hSession->obptr++ = SF_TRANSFER_DATA;
  507 + SET16(hSession->obptr, TR_CLOSE_REPLY);
  508 + net_output(hSession);
489 } 509 }
490 510
491 /* Abort a transfer. */ 511 /* Abort a transfer. */
492 -static void dft_abort(unsigned short code, const char *fmt, ...) 512 +static void dft_abort(H3270 *hSession, unsigned short code, const char *fmt, ...)
493 { 513 {
  514 + H3270FT *ft = (H3270FT *) hSession->ft;
494 va_list args; 515 va_list args;
495 516
496 - if(abort_string)  
497 - lib3270_free(abort_string); 517 + lib3270_free(ft->abort_string);
498 518
499 va_start(args, fmt); 519 va_start(args, fmt);
500 - abort_string = lib3270_vsprintf(fmt, args); 520 + ft->abort_string = lib3270_vsprintf(fmt, args);
501 va_end(args); 521 va_end(args);
502 522
503 - trace_ds(&h3270,"> WriteStructuredField FileTransferData Error\n"); 523 + trace_ds(hSession,"> WriteStructuredField FileTransferData Error\n");
504 524
505 - h3270.obptr = h3270.obuf;  
506 - space3270out(&h3270,10);  
507 - *h3270.obptr++ = AID_SF;  
508 - SET16(h3270.obptr, 9); /* length */  
509 - *h3270.obptr++ = SF_TRANSFER_DATA;  
510 - *h3270.obptr++ = HIGH8(code);  
511 - *h3270.obptr++ = TR_ERROR_REPLY;  
512 - SET16(h3270.obptr, TR_ERROR_HDR);  
513 - SET16(h3270.obptr, TR_ERR_CMDFAIL);  
514 - net_output(&h3270); 525 + hSession->obptr = hSession->obuf;
  526 + space3270out(hSession,10);
  527 + *hSession->obptr++ = AID_SF;
  528 + SET16(hSession->obptr, 9); /* length */
  529 + *hSession->obptr++ = SF_TRANSFER_DATA;
  530 + *hSession->obptr++ = HIGH8(code);
  531 + *hSession->obptr++ = TR_ERROR_REPLY;
  532 + SET16(hSession->obptr, TR_ERROR_HDR);
  533 + SET16(hSession->obptr, TR_ERR_CMDFAIL);
  534 + net_output(hSession);
515 535
516 /* Update the pop-up and state. */ 536 /* Update the pop-up and state. */
517 - ft_aborting((H3270FT *) h3270.ft); 537 + ft_aborting(ft);
518 } 538 }
519 539
520 /* Returns the number of bytes in s, limited by len, that aren't CRs or ^Zs. */ 540 /* Returns the number of bytes in s, limited by len, that aren't CRs or ^Zs. */
src/lib3270/rpq.c
@@ -119,10 +119,10 @@ static struct rpq_keyword { @@ -119,10 +119,10 @@ static struct rpq_keyword {
119 119
120 static char *x3270rpq; 120 static char *x3270rpq;
121 121
122 -/* 122 +/**
123 * RPQNAMES query reply. 123 * RPQNAMES query reply.
124 */ 124 */
125 -void do_qr_rpqnames(void) 125 +void do_qr_rpqnames(H3270 *hSession)
126 { 126 {
127 #define TERM_PREFIX_SIZE 2 /* Each term has 1 byte length and 1 127 #define TERM_PREFIX_SIZE 2 /* Each term has 1 byte length and 1
128 byte id */ 128 byte id */
@@ -132,14 +132,14 @@ void do_qr_rpqnames(void) @@ -132,14 +132,14 @@ void do_qr_rpqnames(void)
132 int remaining = 254; /* maximum data area for rpqname reply */ 132 int remaining = 254; /* maximum data area for rpqname reply */
133 Boolean omit_due_space_limit; 133 Boolean omit_due_space_limit;
134 134
135 - trace_ds(&h3270,"> QueryReply(RPQNames)\n"); 135 + trace_ds(hSession,"> QueryReply(RPQNames)\n");
136 136
137 /* 137 /*
138 * Allocate enough space for the maximum allowed item. 138 * Allocate enough space for the maximum allowed item.
139 * By pre-allocating the space I don't have to worry about the 139 * By pre-allocating the space I don't have to worry about the
140 * possibility of addresses changing. 140 * possibility of addresses changing.
141 */ 141 */
142 - space3270out(&h3270,4+4+1+remaining); /* Maximum space for an RPQNAME item */ 142 + space3270out(hSession,4+4+1+remaining); /* Maximum space for an RPQNAME item */
143 143
144 SET32(h3270.obptr, 0); /* Device number, 0 = All */ 144 SET32(h3270.obptr, 0); /* Device number, 0 = All */
145 SET32(h3270.obptr, 0); /* Model number, 0 = All */ 145 SET32(h3270.obptr, 0); /* Model number, 0 = All */
@@ -188,7 +188,7 @@ void do_qr_rpqnames(void) @@ -188,7 +188,7 @@ void do_qr_rpqnames(void)
188 188
189 case RPQ_ADDRESS: /* Workstation address */ 189 case RPQ_ADDRESS: /* Workstation address */
190 #if !defined(_WIN32) /*[*/ 190 #if !defined(_WIN32) /*[*/
191 - h3270.obptr += get_rpq_address(h3270.obptr, remaining); 191 + hSession->obptr += get_rpq_address(hSession->obptr, remaining);
192 #endif /*]*/ 192 #endif /*]*/
193 break; 193 break;
194 194
@@ -197,7 +197,7 @@ void do_qr_rpqnames(void) @@ -197,7 +197,7 @@ void do_qr_rpqnames(void)
197 omit_due_space_limit = (x > remaining); 197 omit_due_space_limit = (x > remaining);
198 if (!omit_due_space_limit) { 198 if (!omit_due_space_limit) {
199 for (i = 0; i < x; i++) { 199 for (i = 0; i < x; i++) {
200 - *h3270.obptr++ = asc2ebc[(int)(*(build_rpq_version+i) & 0xff)]; 200 + *hSession->obptr++ = asc2ebc[(int)(*(build_rpq_version+i) & 0xff)];
201 } 201 }
202 } 202 }
203 break; 203 break;
@@ -207,7 +207,7 @@ void do_qr_rpqnames(void) @@ -207,7 +207,7 @@ void do_qr_rpqnames(void)
207 omit_due_space_limit = ((x+1)/2 > remaining); 207 omit_due_space_limit = ((x+1)/2 > remaining);
208 if (!omit_due_space_limit) { 208 if (!omit_due_space_limit) {
209 for (i=0; i < x; i+=2) { 209 for (i=0; i < x; i+=2) {
210 - *h3270.obptr++ = ((*(build_rpq_timestamp+i) - '0') << 4) 210 + *hSession->obptr++ = ((*(build_rpq_timestamp+i) - '0') << 4)
211 + (*(build_rpq_timestamp+i+1) - '0'); 211 + (*(build_rpq_timestamp+i+1) - '0');
212 } 212 }
213 } 213 }
@@ -254,7 +254,7 @@ void do_qr_rpqnames(void) @@ -254,7 +254,7 @@ void do_qr_rpqnames(void)
254 } 254 }
255 255
256 /* Fill in overall length of RPQNAME info */ 256 /* Fill in overall length of RPQNAME info */
257 - *rpql = (h3270.obptr - rpql); 257 + *rpql = (hSession->obptr - rpql);
258 258
259 rpq_dump_warnings(); 259 rpq_dump_warnings();
260 } 260 }
src/lib3270/sf.c
@@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
18 * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin 18 * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
19 * St, Fifth Floor, Boston, MA 02110-1301 USA 19 * St, Fifth Floor, Boston, MA 02110-1301 USA
20 * 20 *
21 - * Este programa está nomeado como sf.c e possui 964 linhas de código. 21 + * Este programa está nomeado como sf.c e possui - linhas de código.
22 * 22 *
23 * Contatos: 23 * Contatos:
24 * 24 *
@@ -26,7 +26,6 @@ @@ -26,7 +26,6 @@
26 * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) 26 * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
27 * licinio@bb.com.br (Licínio Luis Branco) 27 * licinio@bb.com.br (Licínio Luis Branco)
28 * kraucer@bb.com.br (Kraucer Fernandes Mazuco) 28 * kraucer@bb.com.br (Kraucer Fernandes Mazuco)
29 - * macmiranda@bb.com.br (Marco Aurélio Caldas Miranda)  
30 * 29 *
31 */ 30 */
32 31
@@ -85,16 +84,16 @@ Boolean * standard_font = &amp;sfont; @@ -85,16 +84,16 @@ Boolean * standard_font = &amp;sfont;
85 84
86 /* Statics */ 85 /* Statics */
87 static Boolean qr_in_progress = False; 86 static Boolean qr_in_progress = False;
88 -static enum pds sf_read_part(unsigned char buf[], unsigned buflen);  
89 -static enum pds sf_erase_reset(unsigned char buf[], int buflen);  
90 -static enum pds sf_set_reply_mode(unsigned char buf[], int buflen);  
91 -static enum pds sf_create_partition(unsigned char buf[], int buflen); 87 +static enum pds sf_read_part(H3270 *hSession, unsigned char buf[], unsigned buflen);
  88 +static enum pds sf_erase_reset(H3270 *hSession, unsigned char buf[], int buflen);
  89 +static enum pds sf_set_reply_mode(H3270 *hSession, unsigned char buf[], int buflen);
  90 +static enum pds sf_create_partition(H3270 *hSession, unsigned char buf[], int buflen);
92 static enum pds sf_outbound_ds(unsigned char buf[], int buflen); 91 static enum pds sf_outbound_ds(unsigned char buf[], int buflen);
93 -static void query_reply_start(void); 92 +static void query_reply_start(H3270 *hSession);
94 static void do_query_reply(unsigned char code); 93 static void do_query_reply(unsigned char code);
95 -static void query_reply_end(void); 94 +static void query_reply_end(H3270 *hSession);
96 95
97 -typedef Boolean qr_multi_fn_t(unsigned *subindex, Boolean *more); 96 +typedef Boolean qr_multi_fn_t(H3270 *hSession, unsigned *subindex, Boolean *more);
98 97
99 static qr_single_fn_t do_qr_summary, do_qr_usable_area, do_qr_alpha_part, 98 static qr_single_fn_t do_qr_summary, do_qr_usable_area, do_qr_alpha_part,
100 do_qr_charsets, do_qr_color, do_qr_highlighting, do_qr_reply_modes, 99 do_qr_charsets, do_qr_color, do_qr_highlighting, do_qr_reply_modes,
@@ -145,12 +144,10 @@ static struct reply { @@ -145,12 +144,10 @@ static struct reply {
145 #define NSR_ALL (sizeof(replies)/sizeof(struct reply)) 144 #define NSR_ALL (sizeof(replies)/sizeof(struct reply))
146 #define NSR (NSR_ALL - 1) 145 #define NSR (NSR_ALL - 1)
147 146
148 -  
149 -/* 147 +/**
150 * Process a 3270 Write Structured Field command 148 * Process a 3270 Write Structured Field command
151 */ 149 */
152 -enum pds  
153 -write_structured_field(unsigned char buf[], int buflen) 150 +enum pds write_structured_field(H3270 *hSession, unsigned char buf[], int buflen)
154 { 151 {
155 unsigned short fieldlen; 152 unsigned short fieldlen;
156 unsigned char *cp = buf; 153 unsigned char *cp = buf;
@@ -164,61 +161,72 @@ write_structured_field(unsigned char buf[], int buflen) @@ -164,61 +161,72 @@ write_structured_field(unsigned char buf[], int buflen)
164 buflen--; 161 buflen--;
165 162
166 /* Interpret fields. */ 163 /* Interpret fields. */
167 - while (buflen > 0) { 164 + while (buflen > 0)
  165 + {
168 166
169 if (first) 167 if (first)
170 - trace_ds(&h3270," "); 168 + trace_ds(hSession," ");
171 else 169 else
172 - trace_ds(&h3270,"< WriteStructuredField "); 170 + trace_ds(hSession,"< WriteStructuredField ");
173 first = False; 171 first = False;
174 172
175 /* Pick out the field length. */ 173 /* Pick out the field length. */
176 - if (buflen < 2) {  
177 - trace_ds(&h3270,"error: single byte at end of message\n"); 174 + if (buflen < 2)
  175 + {
  176 + trace_ds(hSession,"error: single byte at end of message\n");
178 return rv ? rv : PDS_BAD_CMD; 177 return rv ? rv : PDS_BAD_CMD;
179 } 178 }
180 fieldlen = (cp[0] << 8) + cp[1]; 179 fieldlen = (cp[0] << 8) + cp[1];
181 if (fieldlen == 0) 180 if (fieldlen == 0)
182 fieldlen = buflen; 181 fieldlen = buflen;
183 - if (fieldlen < 3) {  
184 - trace_ds(&h3270,"error: field length %d too small\n",fieldlen); 182 + if (fieldlen < 3)
  183 + {
  184 + trace_ds(hSession,"error: field length %d too small\n",fieldlen);
185 return rv ? rv : PDS_BAD_CMD; 185 return rv ? rv : PDS_BAD_CMD;
186 } 186 }
187 - if ((int)fieldlen > buflen) {  
188 - trace_ds(&h3270,"error: field length %d exceeds remaining message length %d\n",fieldlen, buflen); 187 + if ((int)fieldlen > buflen)
  188 + {
  189 + trace_ds(hSession,"error: field length %d exceeds remaining message length %d\n",fieldlen, buflen);
189 return rv ? rv : PDS_BAD_CMD; 190 return rv ? rv : PDS_BAD_CMD;
190 } 191 }
191 192
192 /* Dispatch on the ID. */ 193 /* Dispatch on the ID. */
193 - switch (cp[2]) {  
194 - case SF_READ_PART:  
195 - trace_ds(&h3270,"ReadPartition");  
196 - rv_this = sf_read_part(cp, (int)fieldlen); 194 + switch (cp[2])
  195 + {
  196 + case SF_READ_PART:
  197 + trace_ds(hSession,"ReadPartition");
  198 + rv_this = sf_read_part(hSession, cp, (int)fieldlen);
197 break; 199 break;
198 - case SF_ERASE_RESET:  
199 - trace_ds(&h3270,"EraseReset");  
200 - rv_this = sf_erase_reset(cp, (int)fieldlen); 200 +
  201 + case SF_ERASE_RESET:
  202 + trace_ds(hSession,"EraseReset");
  203 + rv_this = sf_erase_reset(hSession, cp, (int)fieldlen);
201 break; 204 break;
202 - case SF_SET_REPLY_MODE:  
203 - trace_ds(&h3270,"SetReplyMode");  
204 - rv_this = sf_set_reply_mode(cp, (int)fieldlen); 205 +
  206 + case SF_SET_REPLY_MODE:
  207 + trace_ds(hSession,"SetReplyMode");
  208 + rv_this = sf_set_reply_mode(hSession, cp, (int)fieldlen);
205 break; 209 break;
206 - case SF_CREATE_PART:  
207 - trace_ds(&h3270,"CreatePartition");  
208 - rv_this = sf_create_partition(cp, (int)fieldlen); 210 +
  211 + case SF_CREATE_PART:
  212 + trace_ds(hSession,"CreatePartition");
  213 + rv_this = sf_create_partition(hSession, cp, (int)fieldlen);
209 break; 214 break;
210 - case SF_OUTBOUND_DS:  
211 - trace_ds(&h3270,"OutboundDS"); 215 +
  216 + case SF_OUTBOUND_DS:
  217 + trace_ds(hSession,"OutboundDS");
212 rv_this = sf_outbound_ds(cp, (int)fieldlen); 218 rv_this = sf_outbound_ds(cp, (int)fieldlen);
213 break; 219 break;
214 -#if defined(X3270_FT) /*[*/  
215 - case SF_TRANSFER_DATA: /* File transfer data */  
216 - trace_ds(&h3270,"FileTransferData");  
217 - ft_dft_data(&h3270,cp, (int)fieldlen); 220 +
  221 +#if defined(X3270_FT)
  222 + case SF_TRANSFER_DATA: /* File transfer data */
  223 + trace_ds(hSession,"FileTransferData");
  224 + ft_dft_data(hSession, cp, (int)fieldlen);
218 break; 225 break;
219 -#endif /*]*/  
220 - default:  
221 - trace_ds(&h3270,"unsupported ID 0x%02x\n", cp[2]); 226 +#endif
  227 +
  228 + default:
  229 + trace_ds(hSession,"unsupported ID 0x%02x\n", cp[2]);
222 rv_this = PDS_BAD_CMD; 230 rv_this = PDS_BAD_CMD;
223 break; 231 break;
224 } 232 }
@@ -240,7 +248,7 @@ write_structured_field(unsigned char buf[], int buflen) @@ -240,7 +248,7 @@ write_structured_field(unsigned char buf[], int buflen)
240 buflen -= fieldlen; 248 buflen -= fieldlen;
241 } 249 }
242 if (first) 250 if (first)
243 - trace_ds(&h3270," (null)\n"); 251 + trace_ds(hSession," (null)\n");
244 252
245 if (bad_cmd && !rv) 253 if (bad_cmd && !rv)
246 return PDS_BAD_CMD; 254 return PDS_BAD_CMD;
@@ -248,8 +256,7 @@ write_structured_field(unsigned char buf[], int buflen) @@ -248,8 +256,7 @@ write_structured_field(unsigned char buf[], int buflen)
248 return rv; 256 return rv;
249 } 257 }
250 258
251 -static enum pds  
252 -sf_read_part(unsigned char buf[], unsigned buflen) 259 +static enum pds sf_read_part(H3270 *hSession, unsigned char buf[], unsigned buflen)
253 { 260 {
254 unsigned char partition; 261 unsigned char partition;
255 unsigned i; 262 unsigned i;
@@ -258,53 +265,53 @@ sf_read_part(unsigned char buf[], unsigned buflen) @@ -258,53 +265,53 @@ sf_read_part(unsigned char buf[], unsigned buflen)
258 265
259 if (buflen < 5) 266 if (buflen < 5)
260 { 267 {
261 - trace_ds(&h3270," error: field length %d too small\n", buflen); 268 + trace_ds(hSession," error: field length %d too small\n", buflen);
262 return PDS_BAD_CMD; 269 return PDS_BAD_CMD;
263 } 270 }
264 271
265 partition = buf[3]; 272 partition = buf[3];
266 - trace_ds(&h3270,"(0x%02x)", partition); 273 + trace_ds(hSession,"(0x%02x)", partition);
267 274
268 switch (buf[4]) { 275 switch (buf[4]) {
269 case SF_RP_QUERY: 276 case SF_RP_QUERY:
270 - trace_ds(&h3270," Query"); 277 + trace_ds(hSession," Query");
271 if (partition != 0xff) { 278 if (partition != 0xff) {
272 - trace_ds(&h3270," error: illegal partition\n"); 279 + trace_ds(hSession," error: illegal partition\n");
273 return PDS_BAD_CMD; 280 return PDS_BAD_CMD;
274 } 281 }
275 - trace_ds(&h3270,"\n");  
276 - query_reply_start(); 282 + trace_ds(hSession,"\n");
  283 + query_reply_start(hSession);
277 for (i = 0; i < NSR; i++) { 284 for (i = 0; i < NSR; i++) {
278 #if defined(X3270_DBCS) /*[*/ 285 #if defined(X3270_DBCS) /*[*/
279 if (dbcs || replies[i].code != QR_DBCS_ASIA) 286 if (dbcs || replies[i].code != QR_DBCS_ASIA)
280 #endif /*]*/ 287 #endif /*]*/
281 do_query_reply(replies[i].code); 288 do_query_reply(replies[i].code);
282 } 289 }
283 - query_reply_end(); 290 + query_reply_end(hSession);
284 break; 291 break;
285 case SF_RP_QLIST: 292 case SF_RP_QLIST:
286 - trace_ds(&h3270," QueryList "); 293 + trace_ds(hSession," QueryList ");
287 if (partition != 0xff) { 294 if (partition != 0xff) {
288 - trace_ds(&h3270,"error: illegal partition\n"); 295 + trace_ds(hSession,"error: illegal partition\n");
289 return PDS_BAD_CMD; 296 return PDS_BAD_CMD;
290 } 297 }
291 if (buflen < 6) { 298 if (buflen < 6) {
292 - trace_ds(&h3270,"error: missing request type\n"); 299 + trace_ds(hSession,"error: missing request type\n");
293 return PDS_BAD_CMD; 300 return PDS_BAD_CMD;
294 } 301 }
295 - query_reply_start(); 302 + query_reply_start(hSession);
296 switch (buf[5]) { 303 switch (buf[5]) {
297 case SF_RPQ_LIST: 304 case SF_RPQ_LIST:
298 - trace_ds(&h3270,"List("); 305 + trace_ds(hSession,"List(");
299 if (buflen < 7) { 306 if (buflen < 7) {
300 - trace_ds(&h3270,")\n"); 307 + trace_ds(hSession,")\n");
301 do_query_reply(QR_NULL); 308 do_query_reply(QR_NULL);
302 } else { 309 } else {
303 for (i = 6; i < buflen; i++) { 310 for (i = 6; i < buflen; i++) {
304 - trace_ds(&h3270,"%s%s", comma,see_qcode(buf[i])); 311 + trace_ds(hSession,"%s%s", comma,see_qcode(buf[i]));
305 comma = ","; 312 comma = ",";
306 } 313 }
307 - trace_ds(&h3270,")\n"); 314 + trace_ds(hSession,")\n");
308 for (i = 0; i < NSR; i++) { 315 for (i = 0; i < NSR; i++) {
309 if (memchr((char *)&buf[6], 316 if (memchr((char *)&buf[6],
310 (char)replies[i].code, 317 (char)replies[i].code,
@@ -324,12 +331,12 @@ sf_read_part(unsigned char buf[], unsigned buflen) @@ -324,12 +331,12 @@ sf_read_part(unsigned char buf[], unsigned buflen)
324 } 331 }
325 break; 332 break;
326 case SF_RPQ_EQUIV: 333 case SF_RPQ_EQUIV:
327 - trace_ds(&h3270,"Equivlent+List("); 334 + trace_ds(hSession,"Equivlent+List(");
328 for (i = 6; i < buflen; i++) { 335 for (i = 6; i < buflen; i++) {
329 - trace_ds(&h3270,"%s%s", comma, see_qcode(buf[i])); 336 + trace_ds(hSession,"%s%s", comma, see_qcode(buf[i]));
330 comma = ","; 337 comma = ",";
331 } 338 }
332 - trace_ds(&h3270,")\n"); 339 + trace_ds(hSession,")\n");
333 for (i = 0; i < NSR; i++) 340 for (i = 0; i < NSR; i++)
334 #if defined(X3270_DBCS) /*[*/ 341 #if defined(X3270_DBCS) /*[*/
335 if (dbcs || replies[i].code != QR_DBCS_ASIA) 342 if (dbcs || replies[i].code != QR_DBCS_ASIA)
@@ -337,7 +344,7 @@ sf_read_part(unsigned char buf[], unsigned buflen) @@ -337,7 +344,7 @@ sf_read_part(unsigned char buf[], unsigned buflen)
337 do_query_reply(replies[i].code); 344 do_query_reply(replies[i].code);
338 break; 345 break;
339 case SF_RPQ_ALL: 346 case SF_RPQ_ALL:
340 - trace_ds(&h3270,"All\n"); 347 + trace_ds(hSession,"All\n");
341 for (i = 0; i < NSR; i++) 348 for (i = 0; i < NSR; i++)
342 #if defined(X3270_DBCS) /*[*/ 349 #if defined(X3270_DBCS) /*[*/
343 if (dbcs || replies[i].code != QR_DBCS_ASIA) 350 if (dbcs || replies[i].code != QR_DBCS_ASIA)
@@ -345,254 +352,277 @@ sf_read_part(unsigned char buf[], unsigned buflen) @@ -345,254 +352,277 @@ sf_read_part(unsigned char buf[], unsigned buflen)
345 do_query_reply(replies[i].code); 352 do_query_reply(replies[i].code);
346 break; 353 break;
347 default: 354 default:
348 - trace_ds(&h3270,"unknown request type 0x%02x\n", buf[5]); 355 + trace_ds(hSession,"unknown request type 0x%02x\n", buf[5]);
349 return PDS_BAD_CMD; 356 return PDS_BAD_CMD;
350 } 357 }
351 - query_reply_end(); 358 + query_reply_end(hSession);
352 break; 359 break;
353 case SNA_CMD_RMA: 360 case SNA_CMD_RMA:
354 - trace_ds(&h3270," ReadModifiedAll"); 361 + trace_ds(hSession," ReadModifiedAll");
355 if (partition != 0x00) { 362 if (partition != 0x00) {
356 - trace_ds(&h3270," error: illegal partition\n"); 363 + trace_ds(hSession," error: illegal partition\n");
357 return PDS_BAD_CMD; 364 return PDS_BAD_CMD;
358 } 365 }
359 - trace_ds(&h3270,"\n");  
360 - ctlr_read_modified(&h3270, AID_QREPLY, True); 366 + trace_ds(hSession,"\n");
  367 + ctlr_read_modified(hSession, AID_QREPLY, True);
361 break; 368 break;
362 case SNA_CMD_RB: 369 case SNA_CMD_RB:
363 - trace_ds(&h3270," ReadBuffer"); 370 + trace_ds(hSession," ReadBuffer");
364 if (partition != 0x00) { 371 if (partition != 0x00) {
365 - trace_ds(&h3270," error: illegal partition\n"); 372 + trace_ds(hSession," error: illegal partition\n");
366 return PDS_BAD_CMD; 373 return PDS_BAD_CMD;
367 } 374 }
368 - trace_ds(&h3270,"\n");  
369 - ctlr_read_buffer(&h3270,AID_QREPLY); 375 + trace_ds(hSession,"\n");
  376 + ctlr_read_buffer(hSession,AID_QREPLY);
370 break; 377 break;
371 case SNA_CMD_RM: 378 case SNA_CMD_RM:
372 - trace_ds(&h3270," ReadModified"); 379 + trace_ds(hSession," ReadModified");
373 if (partition != 0x00) { 380 if (partition != 0x00) {
374 - trace_ds(&h3270," error: illegal partition\n"); 381 + trace_ds(hSession," error: illegal partition\n");
375 return PDS_BAD_CMD; 382 return PDS_BAD_CMD;
376 } 383 }
377 - trace_ds(&h3270,"\n");  
378 - ctlr_read_modified(&h3270, AID_QREPLY, False); 384 + trace_ds(hSession,"\n");
  385 + ctlr_read_modified(hSession, AID_QREPLY, False);
379 break; 386 break;
380 default: 387 default:
381 - trace_ds(&h3270," unknown type 0x%02x\n", buf[4]); 388 + trace_ds(hSession," unknown type 0x%02x\n", buf[4]);
382 return PDS_BAD_CMD; 389 return PDS_BAD_CMD;
383 } 390 }
384 return PDS_OKAY_OUTPUT; 391 return PDS_OKAY_OUTPUT;
385 } 392 }
386 393
387 -static enum pds  
388 -sf_erase_reset(unsigned char buf[], int buflen) 394 +static enum pds sf_erase_reset(H3270 *hSession, unsigned char buf[], int buflen)
389 { 395 {
390 if (buflen != 4) 396 if (buflen != 4)
391 { 397 {
392 - trace_ds(&h3270," error: wrong field length %d\n", buflen); 398 + trace_ds(hSession," error: wrong field length %d\n", buflen);
393 return PDS_BAD_CMD; 399 return PDS_BAD_CMD;
394 } 400 }
395 401
396 switch (buf[3]) 402 switch (buf[3])
397 { 403 {
398 case SF_ER_DEFAULT: 404 case SF_ER_DEFAULT:
399 - trace_ds(&h3270," Default\n");  
400 - ctlr_erase(&h3270,False); 405 + trace_ds(hSession," Default\n");
  406 + ctlr_erase(hSession,False);
401 break; 407 break;
402 408
403 case SF_ER_ALT: 409 case SF_ER_ALT:
404 - trace_ds(&h3270," Alternate\n");  
405 - ctlr_erase(&h3270,True); 410 + trace_ds(hSession," Alternate\n");
  411 + ctlr_erase(hSession,True);
406 break; 412 break;
407 413
408 default: 414 default:
409 - trace_ds(&h3270," unknown type 0x%02x\n", buf[3]); 415 + trace_ds(hSession," unknown type 0x%02x\n", buf[3]);
410 return PDS_BAD_CMD; 416 return PDS_BAD_CMD;
411 } 417 }
412 return PDS_OKAY_NO_OUTPUT; 418 return PDS_OKAY_NO_OUTPUT;
413 } 419 }
414 420
415 -static enum pds  
416 -sf_set_reply_mode(unsigned char buf[], int buflen) 421 +static enum pds sf_set_reply_mode(H3270 *hSession, unsigned char buf[], int buflen)
417 { 422 {
418 unsigned char partition; 423 unsigned char partition;
419 int i; 424 int i;
420 const char *comma = "("; 425 const char *comma = "(";
421 426
422 - if (buflen < 5) {  
423 - trace_ds(&h3270," error: wrong field length %d\n", buflen); 427 + if (buflen < 5)
  428 + {
  429 + trace_ds(hSession," error: wrong field length %d\n", buflen);
424 return PDS_BAD_CMD; 430 return PDS_BAD_CMD;
425 } 431 }
426 432
427 partition = buf[3]; 433 partition = buf[3];
428 - trace_ds(&h3270,"(0x%02x)", partition);  
429 - if (partition != 0x00) {  
430 - trace_ds(&h3270," error: illegal partition\n"); 434 + trace_ds(hSession,"(0x%02x)", partition);
  435 + if (partition != 0x00)
  436 + {
  437 + trace_ds(hSession," error: illegal partition\n");
431 return PDS_BAD_CMD; 438 return PDS_BAD_CMD;
432 } 439 }
433 440
434 - switch (buf[4]) {  
435 - case SF_SRM_FIELD:  
436 - trace_ds(&h3270," Field\n"); 441 + switch (buf[4])
  442 + {
  443 + case SF_SRM_FIELD:
  444 + trace_ds(hSession," Field\n");
437 break; 445 break;
438 - case SF_SRM_XFIELD:  
439 - trace_ds(&h3270," ExtendedField\n"); 446 +
  447 + case SF_SRM_XFIELD:
  448 + trace_ds(hSession," ExtendedField\n");
440 break; 449 break;
441 - case SF_SRM_CHAR:  
442 - trace_ds(&h3270," Character"); 450 +
  451 + case SF_SRM_CHAR:
  452 + trace_ds(hSession," Character");
443 break; 453 break;
444 - default:  
445 - trace_ds(&h3270," unknown mode 0x%02x\n", buf[4]); 454 +
  455 + default:
  456 + trace_ds(hSession," unknown mode 0x%02x\n", buf[4]);
446 return PDS_BAD_CMD; 457 return PDS_BAD_CMD;
447 } 458 }
448 - h3270.reply_mode = buf[4];  
449 - if (buf[4] == SF_SRM_CHAR) {  
450 - h3270.crm_nattr = buflen - 5;  
451 - for (i = 5; i < buflen; i++) {  
452 - h3270.crm_attr[i - 5] = buf[i];  
453 - trace_ds(&h3270,"%s%s", comma, see_efa_only(buf[i])); 459 +
  460 + hSession->reply_mode = buf[4];
  461 +
  462 + if (buf[4] == SF_SRM_CHAR)
  463 + {
  464 + hSession->crm_nattr = buflen - 5;
  465 + for (i = 5; i < buflen; i++)
  466 + {
  467 + hSession->crm_attr[i - 5] = buf[i];
  468 + trace_ds(hSession,"%s%s", comma, see_efa_only(buf[i]));
454 comma = ","; 469 comma = ",";
455 } 470 }
456 - trace_ds(&h3270,"%s\n", h3270.crm_nattr ? ")" : ""); 471 + trace_ds(hSession,"%s\n", hSession->crm_nattr ? ")" : "");
457 } 472 }
458 return PDS_OKAY_NO_OUTPUT; 473 return PDS_OKAY_NO_OUTPUT;
459 } 474 }
460 475
461 -static enum pds  
462 -sf_create_partition(unsigned char buf[], int buflen) 476 +static enum pds sf_create_partition(H3270 *hSession, unsigned char buf[], int buflen)
463 { 477 {
464 unsigned char pid; 478 unsigned char pid;
465 - unsigned char uom; /* unit of measure */ 479 + unsigned char uom; /* unit of measure */
466 unsigned char am; /* addressing mode */ 480 unsigned char am; /* addressing mode */
467 unsigned char flags; /* flags */ 481 unsigned char flags; /* flags */
468 unsigned short h; /* height of presentation space */ 482 unsigned short h; /* height of presentation space */
469 unsigned short w; /* width of presentation space */ 483 unsigned short w; /* width of presentation space */
470 - unsigned short rv; /* viewport origin row */  
471 - unsigned short cv; /* viewport origin column */  
472 - unsigned short hv; /* viewport height */  
473 - unsigned short wv; /* viewport width */  
474 - unsigned short rw; /* window origin row */  
475 - unsigned short cw; /* window origin column */  
476 - unsigned short rs; /* scroll rows */ 484 + unsigned short rv; /* viewport origin row */
  485 + unsigned short cv; /* viewport origin column */
  486 + unsigned short hv; /* viewport height */
  487 + unsigned short wv; /* viewport width */
  488 + unsigned short rw; /* window origin row */
  489 + unsigned short cw; /* window origin column */
  490 + unsigned short rs; /* scroll rows */
477 /* hole */ 491 /* hole */
478 - unsigned short pw; /* character cell point width */  
479 - unsigned short ph; /* character cell point height */ 492 + unsigned short pw; /* character cell point width */
  493 + unsigned short ph; /* character cell point height */
480 494
481 -#if defined(X3270_TRACE) /*[*/  
482 - static const char *bit4[16] = { 495 +#if defined(X3270_TRACE)
  496 + static const char *bit4[16] =
  497 + {
483 "0000", "0001", "0010", "0011", 498 "0000", "0001", "0010", "0011",
484 "0100", "0101", "0110", "0111", 499 "0100", "0101", "0110", "0111",
485 "1000", "1001", "1010", "1011", 500 "1000", "1001", "1010", "1011",
486 "1100", "1101", "1110", "1111" 501 "1100", "1101", "1110", "1111"
487 }; 502 };
488 -#endif /*]*/ 503 +#endif
489 504
490 - if (buflen > 3) {  
491 - trace_ds(&h3270,"("); 505 + if (buflen > 3)
  506 + {
  507 + trace_ds(hSession,"(");
492 508
493 /* Partition. */ 509 /* Partition. */
494 pid = buf[3]; 510 pid = buf[3];
495 - trace_ds(&h3270,"pid=0x%02x", pid);  
496 - if (pid != 0x00) {  
497 - trace_ds(&h3270,") error: illegal partition\n"); 511 + trace_ds(hSession,"pid=0x%02x", pid);
  512 + if (pid != 0x00)
  513 + {
  514 + trace_ds(hSession,") error: illegal partition\n");
498 return PDS_BAD_CMD; 515 return PDS_BAD_CMD;
499 } 516 }
500 - } else 517 + }
  518 + else
501 pid = 0x00; 519 pid = 0x00;
502 520
503 - if (buflen > 4) { 521 + if (buflen > 4)
  522 + {
504 uom = (buf[4] & 0xf0) >> 4; 523 uom = (buf[4] & 0xf0) >> 4;
505 - trace_ds(&h3270,",uom=B'%s'", bit4[uom]); 524 + trace_ds(hSession,",uom=B'%s'", bit4[uom]);
506 if (uom != 0x0 && uom != 0x02) { 525 if (uom != 0x0 && uom != 0x02) {
507 - trace_ds(&h3270,") error: illegal units\n"); 526 + trace_ds(hSession,") error: illegal units\n");
508 return PDS_BAD_CMD; 527 return PDS_BAD_CMD;
509 } 528 }
510 am = buf[4] & 0x0f; 529 am = buf[4] & 0x0f;
511 - trace_ds(&h3270,",am=B'%s'", bit4[am]);  
512 - if (am > 0x2) {  
513 - trace_ds(&h3270,") error: illegal a-mode\n"); 530 + trace_ds(hSession,",am=B'%s'", bit4[am]);
  531 + if (am > 0x2)
  532 + {
  533 + trace_ds(hSession,") error: illegal a-mode\n");
514 return PDS_BAD_CMD; 534 return PDS_BAD_CMD;
515 } 535 }
516 - } else { 536 + }
  537 + else
  538 + {
517 uom = 0; 539 uom = 0;
518 am = 0; 540 am = 0;
519 } 541 }
520 542
521 - if (buflen > 5) { 543 + if (buflen > 5)
  544 + {
522 flags = buf[5]; 545 flags = buf[5];
523 - trace_ds(&h3270,",flags=0x%02x", flags); 546 + trace_ds(hSession,",flags=0x%02x", flags);
524 } else 547 } else
525 flags = 0; 548 flags = 0;
526 549
527 - if (buflen > 7) { 550 + if (buflen > 7)
  551 + {
528 GET16(h, &buf[6]); 552 GET16(h, &buf[6]);
529 - trace_ds(&h3270,",h=%d", h); 553 + trace_ds(hSession,",h=%d", h);
530 } else 554 } else
531 - h = h3270.maxROWS; 555 + h = hSession->maxROWS;
532 556
533 - if (buflen > 9) { 557 + if (buflen > 9)
  558 + {
534 GET16(w, &buf[8]); 559 GET16(w, &buf[8]);
535 - trace_ds(&h3270,",w=%d", w); 560 + trace_ds(hSession,",w=%d", w);
536 } else 561 } else
537 - w = h3270.maxCOLS; 562 + w = hSession->maxCOLS;
538 563
539 - if (buflen > 11) { 564 + if (buflen > 11)
  565 + {
540 GET16(rv, &buf[10]); 566 GET16(rv, &buf[10]);
541 - trace_ds(&h3270,",rv=%d", rv); 567 + trace_ds(hSession,",rv=%d", rv);
542 } else 568 } else
543 rv = 0; 569 rv = 0;
544 570
545 - if (buflen > 13) { 571 + if (buflen > 13)
  572 + {
546 GET16(cv, &buf[12]); 573 GET16(cv, &buf[12]);
547 - trace_ds(&h3270,",cv=%d", cv); 574 + trace_ds(hSession,",cv=%d", cv);
548 } else 575 } else
549 cv = 0; 576 cv = 0;
550 577
551 if (buflen > 15) { 578 if (buflen > 15) {
552 GET16(hv, &buf[14]); 579 GET16(hv, &buf[14]);
553 - trace_ds(&h3270,",hv=%d", hv); 580 + trace_ds(hSession,",hv=%d", hv);
554 } else 581 } else
555 - hv = (h > h3270.maxROWS)? h3270.maxROWS: h; 582 + hv = (h > hSession->maxROWS)? hSession->maxROWS: h;
556 583
557 - if (buflen > 17) { 584 + if (buflen > 17)
  585 + {
558 GET16(wv, &buf[16]); 586 GET16(wv, &buf[16]);
559 - trace_ds(&h3270,",wv=%d", wv); 587 + trace_ds(hSession,",wv=%d", wv);
560 } else 588 } else
561 - wv = (w > h3270.maxCOLS)? h3270.maxCOLS: w; 589 + wv = (w > hSession->maxCOLS)? hSession->maxCOLS: w;
562 590
563 - if (buflen > 19) { 591 + if (buflen > 19)
  592 + {
564 GET16(rw, &buf[18]); 593 GET16(rw, &buf[18]);
565 - trace_ds(&h3270,",rw=%d", rw); 594 + trace_ds(hSession,",rw=%d", rw);
566 } else 595 } else
567 rw = 0; 596 rw = 0;
568 597
569 - if (buflen > 21) { 598 + if (buflen > 21)
  599 + {
570 GET16(cw, &buf[20]); 600 GET16(cw, &buf[20]);
571 - trace_ds(&h3270,",cw=%d", cw); 601 + trace_ds(hSession,",cw=%d", cw);
572 } else 602 } else
573 cw = 0; 603 cw = 0;
574 604
575 if (buflen > 23) { 605 if (buflen > 23) {
576 GET16(rs, &buf[22]); 606 GET16(rs, &buf[22]);
577 - trace_ds(&h3270,",rs=%d", rs); 607 + trace_ds(hSession,",rs=%d", rs);
578 } else 608 } else
579 rs = (h > hv)? 1: 0; 609 rs = (h > hv)? 1: 0;
580 610
581 if (buflen > 27) { 611 if (buflen > 27) {
582 GET16(pw, &buf[26]); 612 GET16(pw, &buf[26]);
583 - trace_ds(&h3270,",pw=%d", pw); 613 + trace_ds(hSession,",pw=%d", pw);
584 } else 614 } else
585 pw = *char_width; 615 pw = *char_width;
586 616
587 if (buflen > 29) { 617 if (buflen > 29) {
588 GET16(ph, &buf[28]); 618 GET16(ph, &buf[28]);
589 - trace_ds(&h3270,",ph=%d", ph); 619 + trace_ds(hSession,",ph=%d", ph);
590 } else 620 } else
591 ph = *char_height; 621 ph = *char_height;
592 - trace_ds(&h3270,")\n"); 622 + trace_ds(hSession,")\n");
593 623
594 - cursor_move(&h3270,0);  
595 - h3270.buffer_addr = 0; 624 + cursor_move(hSession,0);
  625 + hSession->buffer_addr = 0;
596 626
597 return PDS_OKAY_NO_OUTPUT; 627 return PDS_OKAY_NO_OUTPUT;
598 } 628 }
@@ -651,12 +681,11 @@ sf_outbound_ds(unsigned char buf[], int buflen) @@ -651,12 +681,11 @@ sf_outbound_ds(unsigned char buf[], int buflen)
651 return PDS_OKAY_NO_OUTPUT; 681 return PDS_OKAY_NO_OUTPUT;
652 } 682 }
653 683
654 -static void  
655 -query_reply_start(void) 684 +static void query_reply_start(H3270 *hSession)
656 { 685 {
657 - h3270.obptr = h3270.obuf;  
658 - space3270out(&h3270,1);  
659 - *h3270.obptr++ = AID_SF; 686 + hSession->obptr = hSession->obuf;
  687 + space3270out(hSession,1);
  688 + *hSession->obptr++ = AID_SF;
660 qr_in_progress = True; 689 qr_in_progress = True;
661 } 690 }
662 691
@@ -692,9 +721,9 @@ do_query_reply(unsigned char code) @@ -692,9 +721,9 @@ do_query_reply(unsigned char code)
692 721
693 more = False; 722 more = False;
694 if (replies[i].single_fn) 723 if (replies[i].single_fn)
695 - replies[i].single_fn(); 724 + replies[i].single_fn(&h3270);
696 else 725 else
697 - full = replies[i].multi_fn(&subindex, &more); 726 + full = replies[i].multi_fn(&h3270,&subindex, &more);
698 727
699 if (full) { 728 if (full) {
700 int len; 729 int len;
@@ -711,88 +740,89 @@ do_query_reply(unsigned char code) @@ -711,88 +740,89 @@ do_query_reply(unsigned char code)
711 } while (more); 740 } while (more);
712 } 741 }
713 742
714 -static void  
715 -do_qr_null(void) 743 +static void do_qr_null(H3270 *hSession)
716 { 744 {
717 - trace_ds(&h3270,"> QueryReply(Null)\n"); 745 + trace_ds(hSession,"> QueryReply(Null)\n");
718 } 746 }
719 747
720 -static void  
721 -do_qr_summary(void) 748 +static void do_qr_summary(H3270 *hSession)
722 { 749 {
723 int i; 750 int i;
724 const char *comma = ""; 751 const char *comma = "";
725 752
726 - trace_ds(&h3270,"> QueryReply(Summary(");  
727 - space3270out(&h3270,NSR);  
728 - for (i = 0; i < NSR; i++) { 753 + trace_ds(hSession,"> QueryReply(Summary(");
  754 + space3270out(hSession,NSR);
  755 + for (i = 0; i < NSR; i++)
  756 + {
729 #if defined(X3270_DBCS) /*[*/ 757 #if defined(X3270_DBCS) /*[*/
730 - if (dbcs || replies[i].code != QR_DBCS_ASIA) { 758 + if (dbcs || replies[i].code != QR_DBCS_ASIA)
  759 + {
731 #endif /*]*/ 760 #endif /*]*/
732 - trace_ds(&h3270,"%s%s", comma, see_qcode(replies[i].code)); 761 + trace_ds(hSession,"%s%s", comma, see_qcode(replies[i].code));
733 comma = ","; 762 comma = ",";
734 - *h3270.obptr++ = replies[i].code; 763 + *hSession->obptr++ = replies[i].code;
735 #if defined(X3270_DBCS) /*[*/ 764 #if defined(X3270_DBCS) /*[*/
736 } 765 }
737 #endif /*]*/ 766 #endif /*]*/
738 } 767 }
739 - trace_ds(&h3270,"))\n"); 768 + trace_ds(hSession,"))\n");
740 } 769 }
741 770
742 -static void  
743 -do_qr_usable_area(void) 771 +static void do_qr_usable_area(H3270 *hSession)
744 { 772 {
745 unsigned short num, denom; 773 unsigned short num, denom;
746 774
747 - trace_ds(&h3270,"> QueryReply(UsableArea)\n");  
748 - space3270out(&h3270,19);  
749 - *h3270.obptr++ = 0x01; /* 12/14-bit addressing */  
750 - *h3270.obptr++ = 0x00; /* no special character features */  
751 - SET16(h3270.obptr, h3270.maxCOLS); /* usable width */  
752 - SET16(h3270.obptr, h3270.maxROWS); /* usable height */  
753 - *h3270.obptr++ = 0x01; /* units (mm) */ 775 + trace_ds(hSession,"> QueryReply(UsableArea)\n");
  776 + space3270out(hSession,19);
  777 + *hSession->obptr++ = 0x01; /* 12/14-bit addressing */
  778 + *hSession->obptr++ = 0x00; /* no special character features */
  779 + SET16(hSession->obptr, hSession->maxCOLS); /* usable width */
  780 + SET16(hSession->obptr, hSession->maxROWS); /* usable height */
  781 + *hSession->obptr++ = 0x01; /* units (mm) */
754 num = display_widthMM(); 782 num = display_widthMM();
755 denom = display_width(); 783 denom = display_width();
756 - while (!(num %2) && !(denom % 2)) { 784 + while (!(num %2) && !(denom % 2))
  785 + {
757 num /= 2; 786 num /= 2;
758 denom /= 2; 787 denom /= 2;
759 } 788 }
760 - SET16(h3270.obptr, (int)num); /* Xr numerator */  
761 - SET16(h3270.obptr, (int)denom); /* Xr denominator */ 789 + SET16(hSession->obptr, (int)num); /* Xr numerator */
  790 + SET16(hSession->obptr, (int)denom); /* Xr denominator */
762 num = display_heightMM(); 791 num = display_heightMM();
763 denom = display_height(); 792 denom = display_height();
764 - while (!(num %2) && !(denom % 2)) { 793 + while (!(num %2) && !(denom % 2))
  794 + {
765 num /= 2; 795 num /= 2;
766 denom /= 2; 796 denom /= 2;
767 } 797 }
768 - SET16(h3270.obptr, (int)num); /* Yr numerator */  
769 - SET16(h3270.obptr, (int)denom); /* Yr denominator */  
770 - *h3270.obptr++ = *char_width; /* AW */  
771 - *h3270.obptr++ = *char_height;/* AH */  
772 - SET16(h3270.obptr, h3270.maxCOLS * h3270.maxROWS); /* buffer, questionable */ 798 + SET16(hSession->obptr, (int)num); /* Yr numerator */
  799 + SET16(hSession->obptr, (int)denom); /* Yr denominator */
  800 + *hSession->obptr++ = *char_width; /* AW */
  801 + *hSession->obptr++ = *char_height; /* AH */
  802 + SET16(hSession->obptr, hSession->maxCOLS * hSession->maxROWS); /* buffer, questionable */
773 } 803 }
774 804
775 -static void  
776 -do_qr_color(void) 805 +static void do_qr_color(H3270 *hSession)
777 { 806 {
778 int i; 807 int i;
779 int color_max; 808 int color_max;
780 809
781 - trace_ds(&h3270,"> QueryReply(Color)\n"); 810 + trace_ds(hSession,"> QueryReply(Color)\n");
782 811
783 - color_max = h3270.color8 ? 8: 16; /* report on 8 or 16 colors */ 812 + color_max = hSession->color8 ? 8: 16; /* report on 8 or 16 colors */
784 813
785 - space3270out(&h3270,4 + 2*15);  
786 - *h3270.obptr++ = 0x00; /* no options */  
787 - *h3270.obptr++ = color_max; /* report on 8 or 16 colors */  
788 - *h3270.obptr++ = 0x00; /* default color: */  
789 - *h3270.obptr++ = 0xf0 + COLOR_GREEN; /* green */  
790 - for (i = 0xf1; i < 0xf1 + color_max - 1; i++) {  
791 - *h3270.obptr++ = i;  
792 - if (h3270.m3279)  
793 - *h3270.obptr++ = i; 814 + space3270out(hSession,4 + 2*15);
  815 + *hSession->obptr++ = 0x00; /* no options */
  816 + *hSession->obptr++ = color_max; /* report on 8 or 16 colors */
  817 + *hSession->obptr++ = 0x00; /* default color: */
  818 + *hSession->obptr++ = 0xf0 + COLOR_GREEN; /* green */
  819 + for (i = 0xf1; i < 0xf1 + color_max - 1; i++)
  820 + {
  821 + *hSession->obptr++ = i;
  822 + if (hSession->m3279)
  823 + *hSession->obptr++ = i;
794 else 824 else
795 - *h3270.obptr++ = 0x00; 825 + *hSession->obptr++ = 0x00;
796 } 826 }
797 827
798 /* 828 /*
@@ -809,63 +839,58 @@ do_qr_color(void) @@ -809,63 +839,58 @@ do_qr_color(void)
809 */ 839 */
810 } 840 }
811 841
812 -static void  
813 -do_qr_highlighting(void) 842 +static void do_qr_highlighting(H3270 *hSession)
814 { 843 {
815 - trace_ds(&h3270,"> QueryReply(Highlighting)\n");  
816 - space3270out(&h3270,11);  
817 - *h3270.obptr++ = 5; /* report on 5 pairs */  
818 - *h3270.obptr++ = XAH_DEFAULT; /* default: */  
819 - *h3270.obptr++ = XAH_NORMAL; /* normal */  
820 - *h3270.obptr++ = XAH_BLINK; /* blink: */  
821 - *h3270.obptr++ = XAH_BLINK; /* blink */  
822 - *h3270.obptr++ = XAH_REVERSE; /* reverse: */  
823 - *h3270.obptr++ = XAH_REVERSE; /* reverse */  
824 - *h3270.obptr++ = XAH_UNDERSCORE; /* underscore: */  
825 - *h3270.obptr++ = XAH_UNDERSCORE; /* underscore */  
826 - *h3270.obptr++ = XAH_INTENSIFY; /* intensify: */  
827 - *h3270.obptr++ = XAH_INTENSIFY; /* intensify */ 844 + trace_ds(hSession,"> QueryReply(Highlighting)\n");
  845 + space3270out(hSession,11);
  846 + *hSession->obptr++ = 5; /* report on 5 pairs */
  847 + *hSession->obptr++ = XAH_DEFAULT; /* default: */
  848 + *hSession->obptr++ = XAH_NORMAL; /* normal */
  849 + *hSession->obptr++ = XAH_BLINK; /* blink: */
  850 + *hSession->obptr++ = XAH_BLINK; /* blink */
  851 + *hSession->obptr++ = XAH_REVERSE; /* reverse: */
  852 + *hSession->obptr++ = XAH_REVERSE; /* reverse */
  853 + *hSession->obptr++ = XAH_UNDERSCORE; /* underscore: */
  854 + *hSession->obptr++ = XAH_UNDERSCORE; /* underscore */
  855 + *hSession->obptr++ = XAH_INTENSIFY; /* intensify: */
  856 + *hSession->obptr++ = XAH_INTENSIFY; /* intensify */
828 } 857 }
829 858
830 -static void  
831 -do_qr_reply_modes(void) 859 +static void do_qr_reply_modes(H3270 *hSession)
832 { 860 {
833 - trace_ds(&h3270,"> QueryReply(ReplyModes)\n");  
834 - space3270out(&h3270,3);  
835 - *h3270.obptr++ = SF_SRM_FIELD;  
836 - *h3270.obptr++ = SF_SRM_XFIELD;  
837 - *h3270.obptr++ = SF_SRM_CHAR; 861 + trace_ds(hSession,"> QueryReply(ReplyModes)\n");
  862 + space3270out(hSession,3);
  863 + *hSession->obptr++ = SF_SRM_FIELD;
  864 + *hSession->obptr++ = SF_SRM_XFIELD;
  865 + *hSession->obptr++ = SF_SRM_CHAR;
838 } 866 }
839 867
840 #if defined(X3270_DBCS) /*[*/ 868 #if defined(X3270_DBCS) /*[*/
841 -static void  
842 -do_qr_dbcs_asia(void) 869 +static void do_qr_dbcs_asia(H3270 *hSession)
843 { 870 {
844 /* XXX: Should we support this, even when not in DBCS mode? */ 871 /* XXX: Should we support this, even when not in DBCS mode? */
845 - trace_ds(&h3270,"> QueryReply(DbcsAsia)\n");  
846 - space3270out(7);  
847 - *obptr++ = 0x00; /* flags (none) */  
848 - *obptr++ = 0x03; /* field length 3 */  
849 - *obptr++ = 0x01; /* SI/SO supported */  
850 - *obptr++ = 0x80; /* character set ID 0x80 */  
851 - *obptr++ = 0x03; /* field length 3 */  
852 - *obptr++ = 0x02; /* input control */  
853 - *obptr++ = 0x01; /* creation supported */ 872 + trace_ds(hSession,"> QueryReply(DbcsAsia)\n");
  873 + space3270out(hSession,7);
  874 + *hSession->obptr++ = 0x00; /* flags (none) */
  875 + *hSession->obptr++ = 0x03; /* field length 3 */
  876 + *hSession->obptr++ = 0x01; /* SI/SO supported */
  877 + *hSession->obptr++ = 0x80; /* character set ID 0x80 */
  878 + *hSession->obptr++ = 0x03; /* field length 3 */
  879 + *hSession->obptr++ = 0x02; /* input control */
  880 + *hSession->obptr++ = 0x01; /* creation supported */
854 } 881 }
855 #endif /*]*/ 882 #endif /*]*/
856 883
857 -static void  
858 -do_qr_alpha_part(void) 884 +static void do_qr_alpha_part(H3270 *hSession)
859 { 885 {
860 - trace_ds(&h3270,"> QueryReply(AlphanumericPartitions)\n");  
861 - space3270out(&h3270,4);  
862 - *h3270.obptr++ = 0; /* 1 partition */  
863 - SET16(h3270.obptr, h3270.maxROWS * h3270.maxCOLS); /* buffer space */  
864 - *h3270.obptr++ = 0; /* no special features */ 886 + trace_ds(hSession,"> QueryReply(AlphanumericPartitions)\n");
  887 + space3270out(hSession,4);
  888 + *hSession->obptr++ = 0; /* 1 partition */
  889 + SET16(hSession->obptr, hSession->maxROWS * hSession->maxCOLS); /* buffer space */
  890 + *hSession->obptr++ = 0; /* no special features */
865 } 891 }
866 892
867 -static void  
868 -do_qr_charsets(void) 893 +static void do_qr_charsets(H3270 *hSession)
869 { 894 {
870 trace_ds(&h3270,"> QueryReply(CharacterSets)\n"); 895 trace_ds(&h3270,"> QueryReply(CharacterSets)\n");
871 space3270out(&h3270,64); 896 space3270out(&h3270,64);
@@ -948,39 +973,36 @@ do_qr_charsets(void) @@ -948,39 +973,36 @@ do_qr_charsets(void)
948 } 973 }
949 974
950 #if defined(X3270_FT) /*[*/ 975 #if defined(X3270_FT) /*[*/
951 -static void  
952 -do_qr_ddm(void) 976 +static void do_qr_ddm(H3270 *hSession)
953 { 977 {
954 - set_dft_buffersize(&h3270);  
955 -  
956 - trace_ds(&h3270,"> QueryReply(DistributedDataManagement)\n");  
957 - space3270out(&h3270,8);  
958 - SET16(h3270.obptr,0); /* set reserved field to 0 */  
959 - SET16(h3270.obptr, h3270.dft_buffersize); /* set inbound length limit INLIM */  
960 - SET16(h3270.obptr, h3270.dft_buffersize); /* set outbound length limit OUTLIM */  
961 - SET16(h3270.obptr, 0x0101); /* NSS=01, DDMSS=01 */ 978 + set_dft_buffersize(hSession);
  979 +
  980 + trace_ds(hSession,"> QueryReply(DistributedDataManagement)\n");
  981 + space3270out(hSession,8);
  982 + SET16(hSession->obptr,0); /* set reserved field to 0 */
  983 + SET16(hSession->obptr, hSession->dft_buffersize); /* set inbound length limit INLIM */
  984 + SET16(hSession->obptr, hSession->dft_buffersize); /* set outbound length limit OUTLIM */
  985 + SET16(hSession->obptr, 0x0101); /* NSS=01, DDMSS=01 */
962 } 986 }
963 #endif /*]*/ 987 #endif /*]*/
964 988
965 -static void  
966 -do_qr_imp_part(void) 989 +static void do_qr_imp_part(H3270 *hSession)
967 { 990 {
968 - trace_ds(&h3270,"> QueryReply(ImplicitPartition)\n");  
969 - space3270out(&h3270,13);  
970 - *h3270.obptr++ = 0x0; /* reserved */  
971 - *h3270.obptr++ = 0x0;  
972 - *h3270.obptr++ = 0x0b; /* length of display size */  
973 - *h3270.obptr++ = 0x01; /* "implicit partition size" */  
974 - *h3270.obptr++ = 0x00; /* reserved */  
975 - SET16(h3270.obptr, 80); /* implicit partition width */  
976 - SET16(h3270.obptr, 24); /* implicit partition height */  
977 - SET16(h3270.obptr, h3270.maxCOLS); /* alternate height */  
978 - SET16(h3270.obptr, h3270.maxROWS); /* alternate width */ 991 + trace_ds(hSession,"> QueryReply(ImplicitPartition)\n");
  992 + space3270out(hSession,13);
  993 + *hSession->obptr++ = 0x0; /* reserved */
  994 + *hSession->obptr++ = 0x0;
  995 + *hSession->obptr++ = 0x0b; /* length of display size */
  996 + *hSession->obptr++ = 0x01; /* "implicit partition size" */
  997 + *hSession->obptr++ = 0x00; /* reserved */
  998 + SET16(hSession->obptr, 80); /* implicit partition width */
  999 + SET16(hSession->obptr, 24); /* implicit partition height */
  1000 + SET16(hSession->obptr, hSession->maxCOLS); /* alternate height */
  1001 + SET16(hSession->obptr, hSession->maxROWS); /* alternate width */
979 } 1002 }
980 1003
981 -static void  
982 -query_reply_end(void) 1004 +static void query_reply_end(H3270 *hSession)
983 { 1005 {
984 - net_output(&h3270);  
985 - kybd_inhibit(&h3270,True); 1006 + net_output(hSession);
  1007 + kybd_inhibit(hSession,True);
986 } 1008 }
src/lib3270/sf.h
1 /* 1 /*
2 - * Copyright 1995, 1999, 2000 by Paul Mattes.  
3 - * Permission to use, copy, modify, and distribute this software and its  
4 - * documentation for any purpose and without fee is hereby granted,  
5 - * provided that the above copyright notice appear in all copies and that  
6 - * both that copyright notice and this permission notice appear in  
7 - * supporting documentation.  
8 - *  
9 - * x3270, c3270, s3270, tcl3270 and pr3287 are distributed in the hope that  
10 - * they will be useful, but WITHOUT ANY WARRANTY; without even the implied  
11 - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  
12 - * file LICENSE for more details. 2 + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
  3 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
  4 + * aplicativos mainframe. Registro no INPI sob o nome G3270.
  5 + *
  6 + * Copyright (C) <2008> <Banco do Brasil S.A.>
  7 + *
  8 + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
  9 + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
  10 + * Free Software Foundation.
  11 + *
  12 + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
  13 + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
  14 + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
  15 + * obter mais detalhes.
  16 + *
  17 + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
  18 + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
  19 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + * Este programa está nomeado como sf.h e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
  27 + * licinio@bb.com.br (Licínio Luis Branco)
  28 + * kraucer@bb.com.br (Kraucer Fernandes Mazuco)
  29 + *
13 */ 30 */
14 31
15 -typedef void qr_single_fn_t(void); 32 +typedef void qr_single_fn_t(H3270 *hSession);
16 33
17 LIB3270_INTERNAL qr_single_fn_t do_qr_rpqnames; 34 LIB3270_INTERNAL qr_single_fn_t do_qr_rpqnames;
18 35
19 -LIB3270_INTERNAL enum pds write_structured_field(unsigned char buf[], int buflen); 36 +LIB3270_INTERNAL enum pds write_structured_field(H3270 *hSession, unsigned char buf[], int buflen);
src/pw3270/filetransfer.c
@@ -605,13 +605,13 @@ static void run_ft_dialog(GObject *action, GtkWidget *widget, struct ftdialog *d @@ -605,13 +605,13 @@ static void run_ft_dialog(GObject *action, GtkWidget *widget, struct ftdialog *d
605 ft->message = ft_message; 605 ft->message = ft_message;
606 606
607 gtk_widget_show_all(ftdialog); 607 gtk_widget_show_all(ftdialog);
608 - lib3270_ft_start(ft); 608 + lib3270_ft_start(v3270_get_session(widget));
609 609
610 trace("%s: Running dialog %p",__FUNCTION__,ftdialog); 610 trace("%s: Running dialog %p",__FUNCTION__,ftdialog);
611 gtk_dialog_run(GTK_DIALOG(ftdialog)); 611 gtk_dialog_run(GTK_DIALOG(ftdialog));
612 trace("%s: Dialog %p ends",__FUNCTION__,ftdialog); 612 trace("%s: Dialog %p ends",__FUNCTION__,ftdialog);
613 613
614 - lib3270_ft_destroy(ft); 614 + lib3270_ft_destroy(v3270_get_session(widget));
615 615
616 gtk_widget_destroy(ftdialog); 616 gtk_widget_destroy(ftdialog);
617 } 617 }