diff --git a/src/include/lib3270/filetransfer.h b/src/include/lib3270/filetransfer.h index fc2fabf..164ab8b 100644 --- a/src/include/lib3270/filetransfer.h +++ b/src/include/lib3270/filetransfer.h @@ -91,6 +91,10 @@ const char * local; /**< Local filename */ const char * remote; /**< Remote filename */ + // ft_dft.c + char * abort_string; + + // Callbacks void (*complete)(struct _h3270ft *ft,unsigned long length,double kbytes_sec,const char *mode); void (*message)(struct _h3270ft *ft, const char *msg); void (*update)(struct _h3270ft *ft, unsigned long current, unsigned long length, double kbytes_sec); @@ -117,12 +121,12 @@ * @return Filetransfer handle if ok, NULL if failed * */ - 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); + 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); - LIB3270_EXPORT int lib3270_ft_start(H3270FT *ft); - LIB3270_EXPORT void lib3270_ft_destroy(H3270FT *ft); + LIB3270_EXPORT int lib3270_ft_start(H3270 *hSession); + LIB3270_EXPORT int lib3270_ft_destroy(H3270 *hSession); - LIB3270_EXPORT int lib3270_ft_cancel(H3270FT *ft, int force); + LIB3270_EXPORT int lib3270_ft_cancel(H3270 *hSession, int force); LIB3270_EXPORT LIB3270_FT_STATE lib3270_get_ft_state(H3270 *session); diff --git a/src/lib3270/ctlr.c b/src/lib3270/ctlr.c index 0b0cf47..a7112ef 100644 --- a/src/lib3270/ctlr.c +++ b/src/lib3270/ctlr.c @@ -484,7 +484,7 @@ enum pds process_ds(H3270 *hSession, unsigned char *buf, int buflen) case CMD_WSF: /* write structured field */ case SNA_CMD_WSF: trace_ds(hSession,"WriteStructuredField"); - return write_structured_field(buf, buflen); + return write_structured_field(hSession,buf, buflen); break; case CMD_NOP: /* no-op */ diff --git a/src/lib3270/ft.c b/src/lib3270/ft.c index 72679ad..ef80edf 100644 --- a/src/lib3270/ft.c +++ b/src/lib3270/ft.c @@ -113,39 +113,24 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); } - void ft_init(H3270 *session) + void ft_init(H3270 *hSession) { /* Register for state changes. */ - lib3270_register_schange(session, LIB3270_STATE_CONNECT, ( void (*)(H3270 *, int, void *)) ft_connected, NULL); - lib3270_register_schange(session, LIB3270_STATE_3270_MODE, ( void (*)(H3270 *, int, void *)) ft_in3270, NULL); + lib3270_register_schange(hSession, LIB3270_STATE_CONNECT, ( void (*)(H3270 *, int, void *)) ft_connected, NULL); + lib3270_register_schange(hSession, LIB3270_STATE_3270_MODE, ( void (*)(H3270 *, int, void *)) ft_in3270, NULL); } -// enum ft_state QueryFTstate(void) -// { -// return ft_state; -// } - -/* - int RegisterFTCallbacks(const struct filetransfer_callbacks *cbk) + LIB3270_EXPORT int lib3270_ft_cancel(H3270 *hSession, int force) { - if(!(cbk && cbk->sz == sizeof(struct filetransfer_callbacks)) ) - return EINVAL; + H3270FT *ft; - callbacks = cbk; + CHECK_SESSION_HANDLE(hSession); - return 0; - } -*/ + ft = (H3270FT *) hSession->ft; + if(!ft) + return EINVAL; -/* - enum ft_state GetFileTransferState(void) - { - return ft_state; - } -*/ - LIB3270_EXPORT int lib3270_ft_cancel(H3270FT *ft, int force) - { if (ft->state == LIB3270_FT_STATE_RUNNING) { set_ft_state(ft,LIB3270_FT_STATE_ABORT_WAIT); @@ -276,7 +261,7 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); return ftsession = ftHandle; } - LIB3270_EXPORT int lib3270_ft_start(H3270FT *ft) + LIB3270_EXPORT int lib3270_ft_start(H3270 *hSession) { static const char * rec = "fvu"; static const char * un[] = { "tracks", "cylinders", "avblock" }; @@ -286,8 +271,13 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); unsigned int flen; unsigned short recfm; unsigned short units; + H3270FT * ft; - CHECK_FT_HANDLE(ft); + CHECK_SESSION_HANDLE(hSession); + + ft = (H3270FT *) hSession->ft; + if(!ft) + return EINVAL; recfm = (ft->flags & FT_RECORD_FORMAT_MASK) >> 8; units = (ft->flags & FT_ALLOCATION_UNITS_MASK) >> 12; @@ -438,12 +428,18 @@ void ft_complete(H3270FT *session, const char *errmsg) } -LIB3270_EXPORT void lib3270_ft_destroy(H3270FT *session) +LIB3270_EXPORT int lib3270_ft_destroy(H3270 *hSession) { - CHECK_FT_HANDLE(session); + H3270FT *session; + + CHECK_SESSION_HANDLE(hSession); + + session = (H3270FT *) hSession->ft; + if(!session) + return EINVAL; if (session->state != LIB3270_FT_STATE_NONE) - lib3270_ft_cancel(session,1); + lib3270_ft_cancel(hSession,1); if(session->local_file) { @@ -454,11 +450,11 @@ LIB3270_EXPORT void lib3270_ft_destroy(H3270FT *session) if(session == ftsession) ftsession = NULL; - if(session->host) - session->host->ft = NULL; + hSession->ft = NULL; free(session); + return 0; } // Update the bytes-transferred count on the progress pop-up. diff --git a/src/lib3270/ft_dft.c b/src/lib3270/ft_dft.c index 8ce1bc5..d58fee9 100644 --- a/src/lib3270/ft_dft.c +++ b/src/lib3270/ft_dft.c @@ -83,20 +83,20 @@ struct data_buffer { static Boolean message_flag = False; /* Open Request for msg received */ static int dft_eof; static unsigned long recnum; -static char *abort_string = CN; +// static char *abort_string = CN; static unsigned char *dft_savebuf = NULL; static int dft_savebuf_len = 0; static int dft_savebuf_max = 0; -static void dft_abort(unsigned short code, const char *fmt, ...); +static void dft_abort(H3270 *hSession, unsigned short code, const char *fmt, ...); -static void dft_close_request(void); -static void dft_data_insert(struct data_buffer *data_bufr); -static void dft_get_request(void); -static void dft_insert_request(void); -static void dft_open_request(unsigned short len, unsigned char *cp); -static void dft_set_cur_req(void); -static int filter_len(char *s, register int len); +static void dft_close_request(H3270 *hSession); +static void dft_data_insert(H3270 *hSession, struct data_buffer *data_bufr); +static void dft_get_request(H3270 *hSession); +static void dft_insert_request(H3270 *hSession); +static void dft_open_request(H3270 *hSession, unsigned short len, unsigned char *cp); +static void dft_set_cur_req(H3270 *hSession); +static int filter_len(char *s, register int len); /** * 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) unsigned short data_length, data_type; unsigned char *cp; - if (lib3270_get_ft_state(&h3270) == FT_NONE) + if (lib3270_get_ft_state(hSession) == FT_NONE) { - trace_ds(&h3270," (no transfer in progress)\n"); + trace_ds(hSession," (no transfer in progress)\n"); return; } @@ -123,104 +123,120 @@ void ft_dft_data(H3270 *hSession, unsigned char *data, int length unused) GET16(data_type, cp); /* Handle the requests */ - switch (data_type) { - case TR_OPEN_REQ: - dft_open_request(data_length, cp); + switch (data_type) + { + case TR_OPEN_REQ: + dft_open_request(hSession,data_length, cp); break; - case TR_INSERT_REQ: /* Insert Request */ - dft_insert_request(); + + case TR_INSERT_REQ: /* Insert Request */ + dft_insert_request(hSession); break; - case TR_DATA_INSERT: - dft_data_insert(data_bufr); + + case TR_DATA_INSERT: + dft_data_insert(hSession,data_bufr); break; - case TR_SET_CUR_REQ: - dft_set_cur_req(); + + case TR_SET_CUR_REQ: + dft_set_cur_req(hSession); break; - case TR_GET_REQ: - dft_get_request(); + + case TR_GET_REQ: + dft_get_request(hSession); break; - case TR_CLOSE_REQ: - dft_close_request(); + + case TR_CLOSE_REQ: + dft_close_request(hSession); break; - default: - trace_ds(&h3270," Unsupported(0x%04x)\n", data_type); + + default: + trace_ds(hSession," Unsupported(0x%04x)\n", data_type); break; } } /* Process an Open request. */ -static void -dft_open_request(unsigned short len, unsigned char *cp) +static void dft_open_request(H3270 *hSession, unsigned short len, unsigned char *cp) { char *name = "?"; char namebuf[8]; char *s; unsigned short recsz = 0; - if (len == 0x23) { + if (len == 0x23) + { name = (char *)cp + 25; - } else if (len == 0x29) { + } + else if (len == 0x29) + { unsigned char *recszp; recszp = cp + 27; GET16(recsz, recszp); name = (char *)cp + 31; - } else { - dft_abort(TR_OPEN_REQ, "%s", _("Uknown DFT Open type from host") ); + } + else + { + dft_abort(hSession,TR_OPEN_REQ, "%s", _("Uknown DFT Open type from host") ); return; } (void) memcpy(namebuf, name, 7); namebuf[7] = '\0'; s = &namebuf[6]; - while (s >= namebuf && *s == ' ') { + while (s >= namebuf && *s == ' ') + { *s-- = '\0'; } - if (recsz) { - trace_ds(&h3270," Open('%s',recsz=%u)\n", namebuf, recsz); - } else { - trace_ds(&h3270," Open('%s')\n", namebuf); + + if (recsz) + { + trace_ds(hSession," Open('%s',recsz=%u)\n", namebuf, recsz); + } + else + { + trace_ds(hSession," Open('%s')\n", namebuf); } if (!strcmp(namebuf, OPEN_MSG)) message_flag = True; - else { + else + { message_flag = False; - ft_running(NULL,False); + ft_running(hSession->ft,False); } + dft_eof = False; recnum = 1; /* Acknowledge the Open. */ - trace_ds(&h3270,"> WriteStructuredField FileTransferData OpenAck\n"); - h3270.obptr = h3270.obuf; - space3270out(&h3270,6); - *h3270.obptr++ = AID_SF; - SET16(h3270.obptr, 5); - *h3270.obptr++ = SF_TRANSFER_DATA; - SET16(h3270.obptr, 9); - net_output(&h3270); + trace_ds(hSession,"> WriteStructuredField FileTransferData OpenAck\n"); + hSession->obptr = hSession->obuf; + space3270out(hSession,6); + *hSession->obptr++ = AID_SF; + SET16(hSession->obptr, 5); + *hSession->obptr++ = SF_TRANSFER_DATA; + SET16(hSession->obptr, 9); + net_output(hSession); } /* Process an Insert request. */ -static void -dft_insert_request(void) +static void dft_insert_request(H3270 *hSession) { - trace_ds(&h3270," Insert\n"); + trace_ds(hSession," Insert\n"); /* Doesn't currently do anything. */ } /* Process a Data Insert request. */ -static void -dft_data_insert(struct data_buffer *data_bufr) +static void dft_data_insert(H3270 *hSession, struct data_buffer *data_bufr) { /* Received a data buffer, get the length and process it */ int my_length; unsigned char *cp; - if(!message_flag && lib3270_get_ft_state(&h3270) == FT_ABORT_WAIT) + if(!message_flag && lib3270_get_ft_state(hSession) == FT_ABORT_WAIT) { - dft_abort(TR_DATA_INSERT, "%s", _("Transfer cancelled by user") ); + dft_abort(hSession,TR_DATA_INSERT, "%s", _("Transfer cancelled by user") ); return; } @@ -232,13 +248,14 @@ dft_data_insert(struct data_buffer *data_bufr) /* Adjust for 5 extra count */ my_length -= 5; - trace_ds(&h3270," Data(rec=%lu) %d bytes\n", recnum, my_length); + trace_ds(hSession," Data(rec=%lu) %d bytes\n", recnum, my_length); /* * First, check to see if we have message data or file data. * Message data will result in a popup. */ - if (message_flag) { + if (message_flag) + { /* Data is from a message */ unsigned char *msgp; unsigned char *dollarp; @@ -259,13 +276,17 @@ dft_data_insert(struct data_buffer *data_bufr) /* If transfer completed ok, use our msg. */ if (memcmp(msgp, END_TRANSFER, strlen(END_TRANSFER)) == 0) { lib3270_free(msgp); - ft_complete(NULL,NULL); - } else if (lib3270_get_ft_state(&h3270) == FT_ABORT_SENT && abort_string != CN) { + ft_complete(hSession->ft,NULL); + } + else if (lib3270_get_ft_state(hSession) == FT_ABORT_SENT && ((H3270FT *) hSession->ft)->abort_string != CN) + { lib3270_free(msgp); - ft_complete(NULL,abort_string); - Replace(abort_string, CN); - } else { - ft_complete(NULL,(char *)msgp); + ft_complete(hSession->ft,((H3270FT *) hSession->ft)->abort_string); + lib3270_free(((H3270FT *) hSession->ft)->abort_string); + } + else + { + ft_complete(hSession->ft,(char *)msgp); lib3270_free(msgp); } } else if (my_length > 0) { @@ -309,56 +330,56 @@ dft_data_insert(struct data_buffer *data_bufr) if (!rv) { /* write failed */ - dft_abort(TR_DATA_INSERT, _( "Error \"%s\" writing to local file (rc=%d)" ) , strerror(errno), errno); + dft_abort(hSession,TR_DATA_INSERT, _( "Error \"%s\" writing to local file (rc=%d)" ) , strerror(errno), errno); } /* Add up amount transferred. */ - ft_update_length((H3270FT *) h3270.ft); + ft_update_length((H3270FT *) hSession->ft); } /* Send an acknowledgement frame back. */ - trace_ds(&h3270,"> WriteStructuredField FileTransferData DataAck(rec=%lu)\n", recnum); - h3270.obptr = h3270.obuf; - space3270out(&h3270,12); - *h3270.obptr++ = AID_SF; - SET16(h3270.obptr, 11); - *h3270.obptr++ = SF_TRANSFER_DATA; - SET16(h3270.obptr, TR_NORMAL_REPLY); - SET16(h3270.obptr, TR_RECNUM_HDR); - SET32(h3270.obptr, recnum); + trace_ds(hSession,"> WriteStructuredField FileTransferData DataAck(rec=%lu)\n", recnum); + hSession->obptr = hSession->obuf; + space3270out(hSession,12); + *hSession->obptr++ = AID_SF; + SET16(hSession->obptr, 11); + *hSession->obptr++ = SF_TRANSFER_DATA; + SET16(hSession->obptr, TR_NORMAL_REPLY); + SET16(hSession->obptr, TR_RECNUM_HDR); + SET32(hSession->obptr, recnum); recnum++; - net_output(&h3270); + net_output(hSession); } /* Process a Set Cursor request. */ -static void -dft_set_cur_req(void) +static void dft_set_cur_req(H3270 *hSession) { - trace_ds(&h3270," SetCursor\n"); + trace_ds(hSession," SetCursor\n"); /* Currently doesn't do anything. */ } /* Process a Get request. */ -static void -dft_get_request(void) +static void dft_get_request(H3270 *hSession) { int numbytes; size_t numread; size_t total_read = 0; unsigned char *bufptr; - trace_ds(&h3270," Get\n"); + trace_ds(hSession," Get\n"); - if (!message_flag && lib3270_get_ft_state(&h3270) == FT_ABORT_WAIT) { - dft_abort(TR_GET_REQ, _( "Transfer cancelled by user" ) ); + if (!message_flag && lib3270_get_ft_state(hSession) == FT_ABORT_WAIT) + { + dft_abort(hSession,TR_GET_REQ, _( "Transfer cancelled by user" ) ); return; } /* Read a buffer's worth. */ - set_dft_buffersize(&h3270); - space3270out(&h3270,h3270.dft_buffersize); + set_dft_buffersize(hSession); + space3270out(hSession,h3270.dft_buffersize); numbytes = h3270.dft_buffersize - 27; /* always read 5 bytes less than we're allowed */ bufptr = h3270.obuf + 17; + while (!dft_eof && numbytes) { if (ascii_flag && cr_flag) { int c; @@ -411,9 +432,9 @@ dft_get_request(void) } /* Check for read error. */ - if (ferror(((H3270FT *) h3270.ft)->local_file)) + if (ferror(((H3270FT *) hSession->ft)->local_file)) { - dft_abort(TR_GET_REQ, _( "Error \"%s\" reading from local file (rc=%d)" ), strerror(errno), errno); + dft_abort(hSession,TR_GET_REQ, _( "Error \"%s\" reading from local file (rc=%d)" ), strerror(errno), errno); return; } @@ -424,7 +445,7 @@ dft_get_request(void) *h3270.obptr++ = SF_TRANSFER_DATA; if (total_read) { - trace_ds(&h3270,"> WriteStructuredField FileTransferData Data(rec=%lu) %d bytes\n",(unsigned long) recnum, (int) total_read); + trace_ds(hSession,"> WriteStructuredField FileTransferData Data(rec=%lu) %d bytes\n",(unsigned long) recnum, (int) total_read); SET16(h3270.obptr, TR_GET_REPLY); SET16(h3270.obptr, TR_RECNUM_HDR); SET32(h3270.obptr, recnum); @@ -442,7 +463,7 @@ dft_get_request(void) } } else { - trace_ds(&h3270,"> WriteStructuredField FileTransferData EOF\n"); + trace_ds(hSession,"> WriteStructuredField FileTransferData EOF\n"); *h3270.obptr++ = HIGH8(TR_GET_REQ); *h3270.obptr++ = TR_ERROR_REPLY; SET16(h3270.obptr, TR_ERROR_HDR); @@ -465,56 +486,55 @@ dft_get_request(void) h3270.aid = AID_SF; /* Write the data. */ - net_output(&h3270); + net_output(hSession); ft_update_length((H3270FT *) h3270.ft); } /* Process a Close request. */ -static void -dft_close_request(void) +static void dft_close_request(H3270 *hSession) { /* * Recieved a close request from the system. * Return a close acknowledgement. */ - trace_ds(&h3270," Close\n"); - trace_ds(&h3270,"> WriteStructuredField FileTransferData CloseAck\n"); - h3270.obptr = h3270.obuf; - space3270out(&h3270,6); - *h3270.obptr++ = AID_SF; - SET16(h3270.obptr, 5); /* length */ - *h3270.obptr++ = SF_TRANSFER_DATA; - SET16(h3270.obptr, TR_CLOSE_REPLY); - net_output(&h3270); + trace_ds(hSession," Close\n"); + trace_ds(hSession,"> WriteStructuredField FileTransferData CloseAck\n"); + hSession->obptr = hSession->obuf; + space3270out(hSession,6); + *hSession->obptr++ = AID_SF; + SET16(hSession->obptr, 5); /* length */ + *hSession->obptr++ = SF_TRANSFER_DATA; + SET16(hSession->obptr, TR_CLOSE_REPLY); + net_output(hSession); } /* Abort a transfer. */ -static void dft_abort(unsigned short code, const char *fmt, ...) +static void dft_abort(H3270 *hSession, unsigned short code, const char *fmt, ...) { + H3270FT *ft = (H3270FT *) hSession->ft; va_list args; - if(abort_string) - lib3270_free(abort_string); + lib3270_free(ft->abort_string); va_start(args, fmt); - abort_string = lib3270_vsprintf(fmt, args); + ft->abort_string = lib3270_vsprintf(fmt, args); va_end(args); - trace_ds(&h3270,"> WriteStructuredField FileTransferData Error\n"); + trace_ds(hSession,"> WriteStructuredField FileTransferData Error\n"); - h3270.obptr = h3270.obuf; - space3270out(&h3270,10); - *h3270.obptr++ = AID_SF; - SET16(h3270.obptr, 9); /* length */ - *h3270.obptr++ = SF_TRANSFER_DATA; - *h3270.obptr++ = HIGH8(code); - *h3270.obptr++ = TR_ERROR_REPLY; - SET16(h3270.obptr, TR_ERROR_HDR); - SET16(h3270.obptr, TR_ERR_CMDFAIL); - net_output(&h3270); + hSession->obptr = hSession->obuf; + space3270out(hSession,10); + *hSession->obptr++ = AID_SF; + SET16(hSession->obptr, 9); /* length */ + *hSession->obptr++ = SF_TRANSFER_DATA; + *hSession->obptr++ = HIGH8(code); + *hSession->obptr++ = TR_ERROR_REPLY; + SET16(hSession->obptr, TR_ERROR_HDR); + SET16(hSession->obptr, TR_ERR_CMDFAIL); + net_output(hSession); /* Update the pop-up and state. */ - ft_aborting((H3270FT *) h3270.ft); + ft_aborting(ft); } /* Returns the number of bytes in s, limited by len, that aren't CRs or ^Zs. */ diff --git a/src/lib3270/rpq.c b/src/lib3270/rpq.c index 2e252ab..526cbd5 100644 --- a/src/lib3270/rpq.c +++ b/src/lib3270/rpq.c @@ -119,10 +119,10 @@ static struct rpq_keyword { static char *x3270rpq; -/* +/** * RPQNAMES query reply. */ -void do_qr_rpqnames(void) +void do_qr_rpqnames(H3270 *hSession) { #define TERM_PREFIX_SIZE 2 /* Each term has 1 byte length and 1 byte id */ @@ -132,14 +132,14 @@ void do_qr_rpqnames(void) int remaining = 254; /* maximum data area for rpqname reply */ Boolean omit_due_space_limit; - trace_ds(&h3270,"> QueryReply(RPQNames)\n"); + trace_ds(hSession,"> QueryReply(RPQNames)\n"); /* * Allocate enough space for the maximum allowed item. * By pre-allocating the space I don't have to worry about the * possibility of addresses changing. */ - space3270out(&h3270,4+4+1+remaining); /* Maximum space for an RPQNAME item */ + space3270out(hSession,4+4+1+remaining); /* Maximum space for an RPQNAME item */ SET32(h3270.obptr, 0); /* Device number, 0 = All */ SET32(h3270.obptr, 0); /* Model number, 0 = All */ @@ -188,7 +188,7 @@ void do_qr_rpqnames(void) case RPQ_ADDRESS: /* Workstation address */ #if !defined(_WIN32) /*[*/ - h3270.obptr += get_rpq_address(h3270.obptr, remaining); + hSession->obptr += get_rpq_address(hSession->obptr, remaining); #endif /*]*/ break; @@ -197,7 +197,7 @@ void do_qr_rpqnames(void) omit_due_space_limit = (x > remaining); if (!omit_due_space_limit) { for (i = 0; i < x; i++) { - *h3270.obptr++ = asc2ebc[(int)(*(build_rpq_version+i) & 0xff)]; + *hSession->obptr++ = asc2ebc[(int)(*(build_rpq_version+i) & 0xff)]; } } break; @@ -207,7 +207,7 @@ void do_qr_rpqnames(void) omit_due_space_limit = ((x+1)/2 > remaining); if (!omit_due_space_limit) { for (i=0; i < x; i+=2) { - *h3270.obptr++ = ((*(build_rpq_timestamp+i) - '0') << 4) + *hSession->obptr++ = ((*(build_rpq_timestamp+i) - '0') << 4) + (*(build_rpq_timestamp+i+1) - '0'); } } @@ -254,7 +254,7 @@ void do_qr_rpqnames(void) } /* Fill in overall length of RPQNAME info */ - *rpql = (h3270.obptr - rpql); + *rpql = (hSession->obptr - rpql); rpq_dump_warnings(); } diff --git a/src/lib3270/sf.c b/src/lib3270/sf.c index 185842f..2b2f381 100644 --- a/src/lib3270/sf.c +++ b/src/lib3270/sf.c @@ -18,7 +18,7 @@ * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin * St, Fifth Floor, Boston, MA 02110-1301 USA * - * Este programa está nomeado como sf.c e possui 964 linhas de código. + * Este programa está nomeado como sf.c e possui - linhas de código. * * Contatos: * @@ -26,7 +26,6 @@ * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) * licinio@bb.com.br (Licínio Luis Branco) * kraucer@bb.com.br (Kraucer Fernandes Mazuco) - * macmiranda@bb.com.br (Marco Aurélio Caldas Miranda) * */ @@ -85,16 +84,16 @@ Boolean * standard_font = &sfont; /* Statics */ static Boolean qr_in_progress = False; -static enum pds sf_read_part(unsigned char buf[], unsigned buflen); -static enum pds sf_erase_reset(unsigned char buf[], int buflen); -static enum pds sf_set_reply_mode(unsigned char buf[], int buflen); -static enum pds sf_create_partition(unsigned char buf[], int buflen); +static enum pds sf_read_part(H3270 *hSession, unsigned char buf[], unsigned buflen); +static enum pds sf_erase_reset(H3270 *hSession, unsigned char buf[], int buflen); +static enum pds sf_set_reply_mode(H3270 *hSession, unsigned char buf[], int buflen); +static enum pds sf_create_partition(H3270 *hSession, unsigned char buf[], int buflen); static enum pds sf_outbound_ds(unsigned char buf[], int buflen); -static void query_reply_start(void); +static void query_reply_start(H3270 *hSession); static void do_query_reply(unsigned char code); -static void query_reply_end(void); +static void query_reply_end(H3270 *hSession); -typedef Boolean qr_multi_fn_t(unsigned *subindex, Boolean *more); +typedef Boolean qr_multi_fn_t(H3270 *hSession, unsigned *subindex, Boolean *more); static qr_single_fn_t do_qr_summary, do_qr_usable_area, do_qr_alpha_part, do_qr_charsets, do_qr_color, do_qr_highlighting, do_qr_reply_modes, @@ -145,12 +144,10 @@ static struct reply { #define NSR_ALL (sizeof(replies)/sizeof(struct reply)) #define NSR (NSR_ALL - 1) - -/* +/** * Process a 3270 Write Structured Field command */ -enum pds -write_structured_field(unsigned char buf[], int buflen) +enum pds write_structured_field(H3270 *hSession, unsigned char buf[], int buflen) { unsigned short fieldlen; unsigned char *cp = buf; @@ -164,61 +161,72 @@ write_structured_field(unsigned char buf[], int buflen) buflen--; /* Interpret fields. */ - while (buflen > 0) { + while (buflen > 0) + { if (first) - trace_ds(&h3270," "); + trace_ds(hSession," "); else - trace_ds(&h3270,"< WriteStructuredField "); + trace_ds(hSession,"< WriteStructuredField "); first = False; /* Pick out the field length. */ - if (buflen < 2) { - trace_ds(&h3270,"error: single byte at end of message\n"); + if (buflen < 2) + { + trace_ds(hSession,"error: single byte at end of message\n"); return rv ? rv : PDS_BAD_CMD; } fieldlen = (cp[0] << 8) + cp[1]; if (fieldlen == 0) fieldlen = buflen; - if (fieldlen < 3) { - trace_ds(&h3270,"error: field length %d too small\n",fieldlen); + if (fieldlen < 3) + { + trace_ds(hSession,"error: field length %d too small\n",fieldlen); return rv ? rv : PDS_BAD_CMD; } - if ((int)fieldlen > buflen) { - trace_ds(&h3270,"error: field length %d exceeds remaining message length %d\n",fieldlen, buflen); + if ((int)fieldlen > buflen) + { + trace_ds(hSession,"error: field length %d exceeds remaining message length %d\n",fieldlen, buflen); return rv ? rv : PDS_BAD_CMD; } /* Dispatch on the ID. */ - switch (cp[2]) { - case SF_READ_PART: - trace_ds(&h3270,"ReadPartition"); - rv_this = sf_read_part(cp, (int)fieldlen); + switch (cp[2]) + { + case SF_READ_PART: + trace_ds(hSession,"ReadPartition"); + rv_this = sf_read_part(hSession, cp, (int)fieldlen); break; - case SF_ERASE_RESET: - trace_ds(&h3270,"EraseReset"); - rv_this = sf_erase_reset(cp, (int)fieldlen); + + case SF_ERASE_RESET: + trace_ds(hSession,"EraseReset"); + rv_this = sf_erase_reset(hSession, cp, (int)fieldlen); break; - case SF_SET_REPLY_MODE: - trace_ds(&h3270,"SetReplyMode"); - rv_this = sf_set_reply_mode(cp, (int)fieldlen); + + case SF_SET_REPLY_MODE: + trace_ds(hSession,"SetReplyMode"); + rv_this = sf_set_reply_mode(hSession, cp, (int)fieldlen); break; - case SF_CREATE_PART: - trace_ds(&h3270,"CreatePartition"); - rv_this = sf_create_partition(cp, (int)fieldlen); + + case SF_CREATE_PART: + trace_ds(hSession,"CreatePartition"); + rv_this = sf_create_partition(hSession, cp, (int)fieldlen); break; - case SF_OUTBOUND_DS: - trace_ds(&h3270,"OutboundDS"); + + case SF_OUTBOUND_DS: + trace_ds(hSession,"OutboundDS"); rv_this = sf_outbound_ds(cp, (int)fieldlen); break; -#if defined(X3270_FT) /*[*/ - case SF_TRANSFER_DATA: /* File transfer data */ - trace_ds(&h3270,"FileTransferData"); - ft_dft_data(&h3270,cp, (int)fieldlen); + +#if defined(X3270_FT) + case SF_TRANSFER_DATA: /* File transfer data */ + trace_ds(hSession,"FileTransferData"); + ft_dft_data(hSession, cp, (int)fieldlen); break; -#endif /*]*/ - default: - trace_ds(&h3270,"unsupported ID 0x%02x\n", cp[2]); +#endif + + default: + trace_ds(hSession,"unsupported ID 0x%02x\n", cp[2]); rv_this = PDS_BAD_CMD; break; } @@ -240,7 +248,7 @@ write_structured_field(unsigned char buf[], int buflen) buflen -= fieldlen; } if (first) - trace_ds(&h3270," (null)\n"); + trace_ds(hSession," (null)\n"); if (bad_cmd && !rv) return PDS_BAD_CMD; @@ -248,8 +256,7 @@ write_structured_field(unsigned char buf[], int buflen) return rv; } -static enum pds -sf_read_part(unsigned char buf[], unsigned buflen) +static enum pds sf_read_part(H3270 *hSession, unsigned char buf[], unsigned buflen) { unsigned char partition; unsigned i; @@ -258,53 +265,53 @@ sf_read_part(unsigned char buf[], unsigned buflen) if (buflen < 5) { - trace_ds(&h3270," error: field length %d too small\n", buflen); + trace_ds(hSession," error: field length %d too small\n", buflen); return PDS_BAD_CMD; } partition = buf[3]; - trace_ds(&h3270,"(0x%02x)", partition); + trace_ds(hSession,"(0x%02x)", partition); switch (buf[4]) { case SF_RP_QUERY: - trace_ds(&h3270," Query"); + trace_ds(hSession," Query"); if (partition != 0xff) { - trace_ds(&h3270," error: illegal partition\n"); + trace_ds(hSession," error: illegal partition\n"); return PDS_BAD_CMD; } - trace_ds(&h3270,"\n"); - query_reply_start(); + trace_ds(hSession,"\n"); + query_reply_start(hSession); for (i = 0; i < NSR; i++) { #if defined(X3270_DBCS) /*[*/ if (dbcs || replies[i].code != QR_DBCS_ASIA) #endif /*]*/ do_query_reply(replies[i].code); } - query_reply_end(); + query_reply_end(hSession); break; case SF_RP_QLIST: - trace_ds(&h3270," QueryList "); + trace_ds(hSession," QueryList "); if (partition != 0xff) { - trace_ds(&h3270,"error: illegal partition\n"); + trace_ds(hSession,"error: illegal partition\n"); return PDS_BAD_CMD; } if (buflen < 6) { - trace_ds(&h3270,"error: missing request type\n"); + trace_ds(hSession,"error: missing request type\n"); return PDS_BAD_CMD; } - query_reply_start(); + query_reply_start(hSession); switch (buf[5]) { case SF_RPQ_LIST: - trace_ds(&h3270,"List("); + trace_ds(hSession,"List("); if (buflen < 7) { - trace_ds(&h3270,")\n"); + trace_ds(hSession,")\n"); do_query_reply(QR_NULL); } else { for (i = 6; i < buflen; i++) { - trace_ds(&h3270,"%s%s", comma,see_qcode(buf[i])); + trace_ds(hSession,"%s%s", comma,see_qcode(buf[i])); comma = ","; } - trace_ds(&h3270,")\n"); + trace_ds(hSession,")\n"); for (i = 0; i < NSR; i++) { if (memchr((char *)&buf[6], (char)replies[i].code, @@ -324,12 +331,12 @@ sf_read_part(unsigned char buf[], unsigned buflen) } break; case SF_RPQ_EQUIV: - trace_ds(&h3270,"Equivlent+List("); + trace_ds(hSession,"Equivlent+List("); for (i = 6; i < buflen; i++) { - trace_ds(&h3270,"%s%s", comma, see_qcode(buf[i])); + trace_ds(hSession,"%s%s", comma, see_qcode(buf[i])); comma = ","; } - trace_ds(&h3270,")\n"); + trace_ds(hSession,")\n"); for (i = 0; i < NSR; i++) #if defined(X3270_DBCS) /*[*/ if (dbcs || replies[i].code != QR_DBCS_ASIA) @@ -337,7 +344,7 @@ sf_read_part(unsigned char buf[], unsigned buflen) do_query_reply(replies[i].code); break; case SF_RPQ_ALL: - trace_ds(&h3270,"All\n"); + trace_ds(hSession,"All\n"); for (i = 0; i < NSR; i++) #if defined(X3270_DBCS) /*[*/ if (dbcs || replies[i].code != QR_DBCS_ASIA) @@ -345,254 +352,277 @@ sf_read_part(unsigned char buf[], unsigned buflen) do_query_reply(replies[i].code); break; default: - trace_ds(&h3270,"unknown request type 0x%02x\n", buf[5]); + trace_ds(hSession,"unknown request type 0x%02x\n", buf[5]); return PDS_BAD_CMD; } - query_reply_end(); + query_reply_end(hSession); break; case SNA_CMD_RMA: - trace_ds(&h3270," ReadModifiedAll"); + trace_ds(hSession," ReadModifiedAll"); if (partition != 0x00) { - trace_ds(&h3270," error: illegal partition\n"); + trace_ds(hSession," error: illegal partition\n"); return PDS_BAD_CMD; } - trace_ds(&h3270,"\n"); - ctlr_read_modified(&h3270, AID_QREPLY, True); + trace_ds(hSession,"\n"); + ctlr_read_modified(hSession, AID_QREPLY, True); break; case SNA_CMD_RB: - trace_ds(&h3270," ReadBuffer"); + trace_ds(hSession," ReadBuffer"); if (partition != 0x00) { - trace_ds(&h3270," error: illegal partition\n"); + trace_ds(hSession," error: illegal partition\n"); return PDS_BAD_CMD; } - trace_ds(&h3270,"\n"); - ctlr_read_buffer(&h3270,AID_QREPLY); + trace_ds(hSession,"\n"); + ctlr_read_buffer(hSession,AID_QREPLY); break; case SNA_CMD_RM: - trace_ds(&h3270," ReadModified"); + trace_ds(hSession," ReadModified"); if (partition != 0x00) { - trace_ds(&h3270," error: illegal partition\n"); + trace_ds(hSession," error: illegal partition\n"); return PDS_BAD_CMD; } - trace_ds(&h3270,"\n"); - ctlr_read_modified(&h3270, AID_QREPLY, False); + trace_ds(hSession,"\n"); + ctlr_read_modified(hSession, AID_QREPLY, False); break; default: - trace_ds(&h3270," unknown type 0x%02x\n", buf[4]); + trace_ds(hSession," unknown type 0x%02x\n", buf[4]); return PDS_BAD_CMD; } return PDS_OKAY_OUTPUT; } -static enum pds -sf_erase_reset(unsigned char buf[], int buflen) +static enum pds sf_erase_reset(H3270 *hSession, unsigned char buf[], int buflen) { if (buflen != 4) { - trace_ds(&h3270," error: wrong field length %d\n", buflen); + trace_ds(hSession," error: wrong field length %d\n", buflen); return PDS_BAD_CMD; } switch (buf[3]) { case SF_ER_DEFAULT: - trace_ds(&h3270," Default\n"); - ctlr_erase(&h3270,False); + trace_ds(hSession," Default\n"); + ctlr_erase(hSession,False); break; case SF_ER_ALT: - trace_ds(&h3270," Alternate\n"); - ctlr_erase(&h3270,True); + trace_ds(hSession," Alternate\n"); + ctlr_erase(hSession,True); break; default: - trace_ds(&h3270," unknown type 0x%02x\n", buf[3]); + trace_ds(hSession," unknown type 0x%02x\n", buf[3]); return PDS_BAD_CMD; } return PDS_OKAY_NO_OUTPUT; } -static enum pds -sf_set_reply_mode(unsigned char buf[], int buflen) +static enum pds sf_set_reply_mode(H3270 *hSession, unsigned char buf[], int buflen) { unsigned char partition; int i; const char *comma = "("; - if (buflen < 5) { - trace_ds(&h3270," error: wrong field length %d\n", buflen); + if (buflen < 5) + { + trace_ds(hSession," error: wrong field length %d\n", buflen); return PDS_BAD_CMD; } partition = buf[3]; - trace_ds(&h3270,"(0x%02x)", partition); - if (partition != 0x00) { - trace_ds(&h3270," error: illegal partition\n"); + trace_ds(hSession,"(0x%02x)", partition); + if (partition != 0x00) + { + trace_ds(hSession," error: illegal partition\n"); return PDS_BAD_CMD; } - switch (buf[4]) { - case SF_SRM_FIELD: - trace_ds(&h3270," Field\n"); + switch (buf[4]) + { + case SF_SRM_FIELD: + trace_ds(hSession," Field\n"); break; - case SF_SRM_XFIELD: - trace_ds(&h3270," ExtendedField\n"); + + case SF_SRM_XFIELD: + trace_ds(hSession," ExtendedField\n"); break; - case SF_SRM_CHAR: - trace_ds(&h3270," Character"); + + case SF_SRM_CHAR: + trace_ds(hSession," Character"); break; - default: - trace_ds(&h3270," unknown mode 0x%02x\n", buf[4]); + + default: + trace_ds(hSession," unknown mode 0x%02x\n", buf[4]); return PDS_BAD_CMD; } - h3270.reply_mode = buf[4]; - if (buf[4] == SF_SRM_CHAR) { - h3270.crm_nattr = buflen - 5; - for (i = 5; i < buflen; i++) { - h3270.crm_attr[i - 5] = buf[i]; - trace_ds(&h3270,"%s%s", comma, see_efa_only(buf[i])); + + hSession->reply_mode = buf[4]; + + if (buf[4] == SF_SRM_CHAR) + { + hSession->crm_nattr = buflen - 5; + for (i = 5; i < buflen; i++) + { + hSession->crm_attr[i - 5] = buf[i]; + trace_ds(hSession,"%s%s", comma, see_efa_only(buf[i])); comma = ","; } - trace_ds(&h3270,"%s\n", h3270.crm_nattr ? ")" : ""); + trace_ds(hSession,"%s\n", hSession->crm_nattr ? ")" : ""); } return PDS_OKAY_NO_OUTPUT; } -static enum pds -sf_create_partition(unsigned char buf[], int buflen) +static enum pds sf_create_partition(H3270 *hSession, unsigned char buf[], int buflen) { unsigned char pid; - unsigned char uom; /* unit of measure */ + unsigned char uom; /* unit of measure */ unsigned char am; /* addressing mode */ unsigned char flags; /* flags */ unsigned short h; /* height of presentation space */ unsigned short w; /* width of presentation space */ - unsigned short rv; /* viewport origin row */ - unsigned short cv; /* viewport origin column */ - unsigned short hv; /* viewport height */ - unsigned short wv; /* viewport width */ - unsigned short rw; /* window origin row */ - unsigned short cw; /* window origin column */ - unsigned short rs; /* scroll rows */ + unsigned short rv; /* viewport origin row */ + unsigned short cv; /* viewport origin column */ + unsigned short hv; /* viewport height */ + unsigned short wv; /* viewport width */ + unsigned short rw; /* window origin row */ + unsigned short cw; /* window origin column */ + unsigned short rs; /* scroll rows */ /* hole */ - unsigned short pw; /* character cell point width */ - unsigned short ph; /* character cell point height */ + unsigned short pw; /* character cell point width */ + unsigned short ph; /* character cell point height */ -#if defined(X3270_TRACE) /*[*/ - static const char *bit4[16] = { +#if defined(X3270_TRACE) + static const char *bit4[16] = + { "0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111" }; -#endif /*]*/ +#endif - if (buflen > 3) { - trace_ds(&h3270,"("); + if (buflen > 3) + { + trace_ds(hSession,"("); /* Partition. */ pid = buf[3]; - trace_ds(&h3270,"pid=0x%02x", pid); - if (pid != 0x00) { - trace_ds(&h3270,") error: illegal partition\n"); + trace_ds(hSession,"pid=0x%02x", pid); + if (pid != 0x00) + { + trace_ds(hSession,") error: illegal partition\n"); return PDS_BAD_CMD; } - } else + } + else pid = 0x00; - if (buflen > 4) { + if (buflen > 4) + { uom = (buf[4] & 0xf0) >> 4; - trace_ds(&h3270,",uom=B'%s'", bit4[uom]); + trace_ds(hSession,",uom=B'%s'", bit4[uom]); if (uom != 0x0 && uom != 0x02) { - trace_ds(&h3270,") error: illegal units\n"); + trace_ds(hSession,") error: illegal units\n"); return PDS_BAD_CMD; } am = buf[4] & 0x0f; - trace_ds(&h3270,",am=B'%s'", bit4[am]); - if (am > 0x2) { - trace_ds(&h3270,") error: illegal a-mode\n"); + trace_ds(hSession,",am=B'%s'", bit4[am]); + if (am > 0x2) + { + trace_ds(hSession,") error: illegal a-mode\n"); return PDS_BAD_CMD; } - } else { + } + else + { uom = 0; am = 0; } - if (buflen > 5) { + if (buflen > 5) + { flags = buf[5]; - trace_ds(&h3270,",flags=0x%02x", flags); + trace_ds(hSession,",flags=0x%02x", flags); } else flags = 0; - if (buflen > 7) { + if (buflen > 7) + { GET16(h, &buf[6]); - trace_ds(&h3270,",h=%d", h); + trace_ds(hSession,",h=%d", h); } else - h = h3270.maxROWS; + h = hSession->maxROWS; - if (buflen > 9) { + if (buflen > 9) + { GET16(w, &buf[8]); - trace_ds(&h3270,",w=%d", w); + trace_ds(hSession,",w=%d", w); } else - w = h3270.maxCOLS; + w = hSession->maxCOLS; - if (buflen > 11) { + if (buflen > 11) + { GET16(rv, &buf[10]); - trace_ds(&h3270,",rv=%d", rv); + trace_ds(hSession,",rv=%d", rv); } else rv = 0; - if (buflen > 13) { + if (buflen > 13) + { GET16(cv, &buf[12]); - trace_ds(&h3270,",cv=%d", cv); + trace_ds(hSession,",cv=%d", cv); } else cv = 0; if (buflen > 15) { GET16(hv, &buf[14]); - trace_ds(&h3270,",hv=%d", hv); + trace_ds(hSession,",hv=%d", hv); } else - hv = (h > h3270.maxROWS)? h3270.maxROWS: h; + hv = (h > hSession->maxROWS)? hSession->maxROWS: h; - if (buflen > 17) { + if (buflen > 17) + { GET16(wv, &buf[16]); - trace_ds(&h3270,",wv=%d", wv); + trace_ds(hSession,",wv=%d", wv); } else - wv = (w > h3270.maxCOLS)? h3270.maxCOLS: w; + wv = (w > hSession->maxCOLS)? hSession->maxCOLS: w; - if (buflen > 19) { + if (buflen > 19) + { GET16(rw, &buf[18]); - trace_ds(&h3270,",rw=%d", rw); + trace_ds(hSession,",rw=%d", rw); } else rw = 0; - if (buflen > 21) { + if (buflen > 21) + { GET16(cw, &buf[20]); - trace_ds(&h3270,",cw=%d", cw); + trace_ds(hSession,",cw=%d", cw); } else cw = 0; if (buflen > 23) { GET16(rs, &buf[22]); - trace_ds(&h3270,",rs=%d", rs); + trace_ds(hSession,",rs=%d", rs); } else rs = (h > hv)? 1: 0; if (buflen > 27) { GET16(pw, &buf[26]); - trace_ds(&h3270,",pw=%d", pw); + trace_ds(hSession,",pw=%d", pw); } else pw = *char_width; if (buflen > 29) { GET16(ph, &buf[28]); - trace_ds(&h3270,",ph=%d", ph); + trace_ds(hSession,",ph=%d", ph); } else ph = *char_height; - trace_ds(&h3270,")\n"); + trace_ds(hSession,")\n"); - cursor_move(&h3270,0); - h3270.buffer_addr = 0; + cursor_move(hSession,0); + hSession->buffer_addr = 0; return PDS_OKAY_NO_OUTPUT; } @@ -651,12 +681,11 @@ sf_outbound_ds(unsigned char buf[], int buflen) return PDS_OKAY_NO_OUTPUT; } -static void -query_reply_start(void) +static void query_reply_start(H3270 *hSession) { - h3270.obptr = h3270.obuf; - space3270out(&h3270,1); - *h3270.obptr++ = AID_SF; + hSession->obptr = hSession->obuf; + space3270out(hSession,1); + *hSession->obptr++ = AID_SF; qr_in_progress = True; } @@ -692,9 +721,9 @@ do_query_reply(unsigned char code) more = False; if (replies[i].single_fn) - replies[i].single_fn(); + replies[i].single_fn(&h3270); else - full = replies[i].multi_fn(&subindex, &more); + full = replies[i].multi_fn(&h3270,&subindex, &more); if (full) { int len; @@ -711,88 +740,89 @@ do_query_reply(unsigned char code) } while (more); } -static void -do_qr_null(void) +static void do_qr_null(H3270 *hSession) { - trace_ds(&h3270,"> QueryReply(Null)\n"); + trace_ds(hSession,"> QueryReply(Null)\n"); } -static void -do_qr_summary(void) +static void do_qr_summary(H3270 *hSession) { int i; const char *comma = ""; - trace_ds(&h3270,"> QueryReply(Summary("); - space3270out(&h3270,NSR); - for (i = 0; i < NSR; i++) { + trace_ds(hSession,"> QueryReply(Summary("); + space3270out(hSession,NSR); + for (i = 0; i < NSR; i++) + { #if defined(X3270_DBCS) /*[*/ - if (dbcs || replies[i].code != QR_DBCS_ASIA) { + if (dbcs || replies[i].code != QR_DBCS_ASIA) + { #endif /*]*/ - trace_ds(&h3270,"%s%s", comma, see_qcode(replies[i].code)); + trace_ds(hSession,"%s%s", comma, see_qcode(replies[i].code)); comma = ","; - *h3270.obptr++ = replies[i].code; + *hSession->obptr++ = replies[i].code; #if defined(X3270_DBCS) /*[*/ } #endif /*]*/ } - trace_ds(&h3270,"))\n"); + trace_ds(hSession,"))\n"); } -static void -do_qr_usable_area(void) +static void do_qr_usable_area(H3270 *hSession) { unsigned short num, denom; - trace_ds(&h3270,"> QueryReply(UsableArea)\n"); - space3270out(&h3270,19); - *h3270.obptr++ = 0x01; /* 12/14-bit addressing */ - *h3270.obptr++ = 0x00; /* no special character features */ - SET16(h3270.obptr, h3270.maxCOLS); /* usable width */ - SET16(h3270.obptr, h3270.maxROWS); /* usable height */ - *h3270.obptr++ = 0x01; /* units (mm) */ + trace_ds(hSession,"> QueryReply(UsableArea)\n"); + space3270out(hSession,19); + *hSession->obptr++ = 0x01; /* 12/14-bit addressing */ + *hSession->obptr++ = 0x00; /* no special character features */ + SET16(hSession->obptr, hSession->maxCOLS); /* usable width */ + SET16(hSession->obptr, hSession->maxROWS); /* usable height */ + *hSession->obptr++ = 0x01; /* units (mm) */ num = display_widthMM(); denom = display_width(); - while (!(num %2) && !(denom % 2)) { + while (!(num %2) && !(denom % 2)) + { num /= 2; denom /= 2; } - SET16(h3270.obptr, (int)num); /* Xr numerator */ - SET16(h3270.obptr, (int)denom); /* Xr denominator */ + SET16(hSession->obptr, (int)num); /* Xr numerator */ + SET16(hSession->obptr, (int)denom); /* Xr denominator */ num = display_heightMM(); denom = display_height(); - while (!(num %2) && !(denom % 2)) { + while (!(num %2) && !(denom % 2)) + { num /= 2; denom /= 2; } - SET16(h3270.obptr, (int)num); /* Yr numerator */ - SET16(h3270.obptr, (int)denom); /* Yr denominator */ - *h3270.obptr++ = *char_width; /* AW */ - *h3270.obptr++ = *char_height;/* AH */ - SET16(h3270.obptr, h3270.maxCOLS * h3270.maxROWS); /* buffer, questionable */ + SET16(hSession->obptr, (int)num); /* Yr numerator */ + SET16(hSession->obptr, (int)denom); /* Yr denominator */ + *hSession->obptr++ = *char_width; /* AW */ + *hSession->obptr++ = *char_height; /* AH */ + SET16(hSession->obptr, hSession->maxCOLS * hSession->maxROWS); /* buffer, questionable */ } -static void -do_qr_color(void) +static void do_qr_color(H3270 *hSession) { int i; int color_max; - trace_ds(&h3270,"> QueryReply(Color)\n"); + trace_ds(hSession,"> QueryReply(Color)\n"); - color_max = h3270.color8 ? 8: 16; /* report on 8 or 16 colors */ + color_max = hSession->color8 ? 8: 16; /* report on 8 or 16 colors */ - space3270out(&h3270,4 + 2*15); - *h3270.obptr++ = 0x00; /* no options */ - *h3270.obptr++ = color_max; /* report on 8 or 16 colors */ - *h3270.obptr++ = 0x00; /* default color: */ - *h3270.obptr++ = 0xf0 + COLOR_GREEN; /* green */ - for (i = 0xf1; i < 0xf1 + color_max - 1; i++) { - *h3270.obptr++ = i; - if (h3270.m3279) - *h3270.obptr++ = i; + space3270out(hSession,4 + 2*15); + *hSession->obptr++ = 0x00; /* no options */ + *hSession->obptr++ = color_max; /* report on 8 or 16 colors */ + *hSession->obptr++ = 0x00; /* default color: */ + *hSession->obptr++ = 0xf0 + COLOR_GREEN; /* green */ + for (i = 0xf1; i < 0xf1 + color_max - 1; i++) + { + *hSession->obptr++ = i; + if (hSession->m3279) + *hSession->obptr++ = i; else - *h3270.obptr++ = 0x00; + *hSession->obptr++ = 0x00; } /* @@ -809,63 +839,58 @@ do_qr_color(void) */ } -static void -do_qr_highlighting(void) +static void do_qr_highlighting(H3270 *hSession) { - trace_ds(&h3270,"> QueryReply(Highlighting)\n"); - space3270out(&h3270,11); - *h3270.obptr++ = 5; /* report on 5 pairs */ - *h3270.obptr++ = XAH_DEFAULT; /* default: */ - *h3270.obptr++ = XAH_NORMAL; /* normal */ - *h3270.obptr++ = XAH_BLINK; /* blink: */ - *h3270.obptr++ = XAH_BLINK; /* blink */ - *h3270.obptr++ = XAH_REVERSE; /* reverse: */ - *h3270.obptr++ = XAH_REVERSE; /* reverse */ - *h3270.obptr++ = XAH_UNDERSCORE; /* underscore: */ - *h3270.obptr++ = XAH_UNDERSCORE; /* underscore */ - *h3270.obptr++ = XAH_INTENSIFY; /* intensify: */ - *h3270.obptr++ = XAH_INTENSIFY; /* intensify */ + trace_ds(hSession,"> QueryReply(Highlighting)\n"); + space3270out(hSession,11); + *hSession->obptr++ = 5; /* report on 5 pairs */ + *hSession->obptr++ = XAH_DEFAULT; /* default: */ + *hSession->obptr++ = XAH_NORMAL; /* normal */ + *hSession->obptr++ = XAH_BLINK; /* blink: */ + *hSession->obptr++ = XAH_BLINK; /* blink */ + *hSession->obptr++ = XAH_REVERSE; /* reverse: */ + *hSession->obptr++ = XAH_REVERSE; /* reverse */ + *hSession->obptr++ = XAH_UNDERSCORE; /* underscore: */ + *hSession->obptr++ = XAH_UNDERSCORE; /* underscore */ + *hSession->obptr++ = XAH_INTENSIFY; /* intensify: */ + *hSession->obptr++ = XAH_INTENSIFY; /* intensify */ } -static void -do_qr_reply_modes(void) +static void do_qr_reply_modes(H3270 *hSession) { - trace_ds(&h3270,"> QueryReply(ReplyModes)\n"); - space3270out(&h3270,3); - *h3270.obptr++ = SF_SRM_FIELD; - *h3270.obptr++ = SF_SRM_XFIELD; - *h3270.obptr++ = SF_SRM_CHAR; + trace_ds(hSession,"> QueryReply(ReplyModes)\n"); + space3270out(hSession,3); + *hSession->obptr++ = SF_SRM_FIELD; + *hSession->obptr++ = SF_SRM_XFIELD; + *hSession->obptr++ = SF_SRM_CHAR; } #if defined(X3270_DBCS) /*[*/ -static void -do_qr_dbcs_asia(void) +static void do_qr_dbcs_asia(H3270 *hSession) { /* XXX: Should we support this, even when not in DBCS mode? */ - trace_ds(&h3270,"> QueryReply(DbcsAsia)\n"); - space3270out(7); - *obptr++ = 0x00; /* flags (none) */ - *obptr++ = 0x03; /* field length 3 */ - *obptr++ = 0x01; /* SI/SO supported */ - *obptr++ = 0x80; /* character set ID 0x80 */ - *obptr++ = 0x03; /* field length 3 */ - *obptr++ = 0x02; /* input control */ - *obptr++ = 0x01; /* creation supported */ + trace_ds(hSession,"> QueryReply(DbcsAsia)\n"); + space3270out(hSession,7); + *hSession->obptr++ = 0x00; /* flags (none) */ + *hSession->obptr++ = 0x03; /* field length 3 */ + *hSession->obptr++ = 0x01; /* SI/SO supported */ + *hSession->obptr++ = 0x80; /* character set ID 0x80 */ + *hSession->obptr++ = 0x03; /* field length 3 */ + *hSession->obptr++ = 0x02; /* input control */ + *hSession->obptr++ = 0x01; /* creation supported */ } #endif /*]*/ -static void -do_qr_alpha_part(void) +static void do_qr_alpha_part(H3270 *hSession) { - trace_ds(&h3270,"> QueryReply(AlphanumericPartitions)\n"); - space3270out(&h3270,4); - *h3270.obptr++ = 0; /* 1 partition */ - SET16(h3270.obptr, h3270.maxROWS * h3270.maxCOLS); /* buffer space */ - *h3270.obptr++ = 0; /* no special features */ + trace_ds(hSession,"> QueryReply(AlphanumericPartitions)\n"); + space3270out(hSession,4); + *hSession->obptr++ = 0; /* 1 partition */ + SET16(hSession->obptr, hSession->maxROWS * hSession->maxCOLS); /* buffer space */ + *hSession->obptr++ = 0; /* no special features */ } -static void -do_qr_charsets(void) +static void do_qr_charsets(H3270 *hSession) { trace_ds(&h3270,"> QueryReply(CharacterSets)\n"); space3270out(&h3270,64); @@ -948,39 +973,36 @@ do_qr_charsets(void) } #if defined(X3270_FT) /*[*/ -static void -do_qr_ddm(void) +static void do_qr_ddm(H3270 *hSession) { - set_dft_buffersize(&h3270); - - trace_ds(&h3270,"> QueryReply(DistributedDataManagement)\n"); - space3270out(&h3270,8); - SET16(h3270.obptr,0); /* set reserved field to 0 */ - SET16(h3270.obptr, h3270.dft_buffersize); /* set inbound length limit INLIM */ - SET16(h3270.obptr, h3270.dft_buffersize); /* set outbound length limit OUTLIM */ - SET16(h3270.obptr, 0x0101); /* NSS=01, DDMSS=01 */ + set_dft_buffersize(hSession); + + trace_ds(hSession,"> QueryReply(DistributedDataManagement)\n"); + space3270out(hSession,8); + SET16(hSession->obptr,0); /* set reserved field to 0 */ + SET16(hSession->obptr, hSession->dft_buffersize); /* set inbound length limit INLIM */ + SET16(hSession->obptr, hSession->dft_buffersize); /* set outbound length limit OUTLIM */ + SET16(hSession->obptr, 0x0101); /* NSS=01, DDMSS=01 */ } #endif /*]*/ -static void -do_qr_imp_part(void) +static void do_qr_imp_part(H3270 *hSession) { - trace_ds(&h3270,"> QueryReply(ImplicitPartition)\n"); - space3270out(&h3270,13); - *h3270.obptr++ = 0x0; /* reserved */ - *h3270.obptr++ = 0x0; - *h3270.obptr++ = 0x0b; /* length of display size */ - *h3270.obptr++ = 0x01; /* "implicit partition size" */ - *h3270.obptr++ = 0x00; /* reserved */ - SET16(h3270.obptr, 80); /* implicit partition width */ - SET16(h3270.obptr, 24); /* implicit partition height */ - SET16(h3270.obptr, h3270.maxCOLS); /* alternate height */ - SET16(h3270.obptr, h3270.maxROWS); /* alternate width */ + trace_ds(hSession,"> QueryReply(ImplicitPartition)\n"); + space3270out(hSession,13); + *hSession->obptr++ = 0x0; /* reserved */ + *hSession->obptr++ = 0x0; + *hSession->obptr++ = 0x0b; /* length of display size */ + *hSession->obptr++ = 0x01; /* "implicit partition size" */ + *hSession->obptr++ = 0x00; /* reserved */ + SET16(hSession->obptr, 80); /* implicit partition width */ + SET16(hSession->obptr, 24); /* implicit partition height */ + SET16(hSession->obptr, hSession->maxCOLS); /* alternate height */ + SET16(hSession->obptr, hSession->maxROWS); /* alternate width */ } -static void -query_reply_end(void) +static void query_reply_end(H3270 *hSession) { - net_output(&h3270); - kybd_inhibit(&h3270,True); + net_output(hSession); + kybd_inhibit(hSession,True); } diff --git a/src/lib3270/sf.h b/src/lib3270/sf.h index ac34033..a7fcdeb 100644 --- a/src/lib3270/sf.h +++ b/src/lib3270/sf.h @@ -1,19 +1,36 @@ /* - * Copyright 1995, 1999, 2000 by Paul Mattes. - * Permission to use, copy, modify, and distribute this software and its - * documentation for any purpose and without fee is hereby granted, - * provided that the above copyright notice appear in all copies and that - * both that copyright notice and this permission notice appear in - * supporting documentation. - * - * x3270, c3270, s3270, tcl3270 and pr3287 are distributed in the hope that - * they will be useful, but WITHOUT ANY WARRANTY; without even the implied - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * file LICENSE for more details. + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como sf.h e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * licinio@bb.com.br (Licínio Luis Branco) + * kraucer@bb.com.br (Kraucer Fernandes Mazuco) + * */ -typedef void qr_single_fn_t(void); +typedef void qr_single_fn_t(H3270 *hSession); LIB3270_INTERNAL qr_single_fn_t do_qr_rpqnames; -LIB3270_INTERNAL enum pds write_structured_field(unsigned char buf[], int buflen); +LIB3270_INTERNAL enum pds write_structured_field(H3270 *hSession, unsigned char buf[], int buflen); diff --git a/src/pw3270/filetransfer.c b/src/pw3270/filetransfer.c index c22d456..75e7769 100644 --- a/src/pw3270/filetransfer.c +++ b/src/pw3270/filetransfer.c @@ -605,13 +605,13 @@ static void run_ft_dialog(GObject *action, GtkWidget *widget, struct ftdialog *d ft->message = ft_message; gtk_widget_show_all(ftdialog); - lib3270_ft_start(ft); + lib3270_ft_start(v3270_get_session(widget)); trace("%s: Running dialog %p",__FUNCTION__,ftdialog); gtk_dialog_run(GTK_DIALOG(ftdialog)); trace("%s: Dialog %p ends",__FUNCTION__,ftdialog); - lib3270_ft_destroy(ft); + lib3270_ft_destroy(v3270_get_session(widget)); gtk_widget_destroy(ftdialog); } -- libgit2 0.21.2