ILE C/C++ Programmer's Guide

Record Functions for ICF Files

Use the following record functions to process ICF files:

Example:

The following example gets a user ID and password from a source program and sends it to a target program. The target program checks the user ID and password for errors and sends a response to the source program.

Note:
To run this example the target program T1520TGT must exist on a remote system. A communications line between the source system with program T1520ICF and the target system with program T1520TGT must be active. You also need Advanced Program to Program Communications (APPC).
  1. To create the physical file T1520DDA, enter:

    CRTPF FILE(MYLIB/T1520DDA) SRCFILE(QCPPLE/QADDSSRC)

    Figure 149. T1520DDA -- DDS Source for Password and User ID


    
    
    A UNIQUE
    A R PASSWRDF
    A USERID 8A
    A PASSWRD 10A
    A K USERID
  2. To create the ICF file T1520DDB using the DDS source shown below:, enter:

    CRTICFF FILE(MYLIB/T1520DDB) SRCFILE(QCPPLE/QADDSSRC)
    ACQPGMDEV(CAPPC2)

    Figure 150. T1520DDB -- DDS Source to Send Password and User ID


    
    
    A R SNDPASS
    A FLD1 18A
    A R CHKPASS
    A FLD1 1A
    A R EVOKPGM
    A EVOKE(MYLIB/T1520TGT)
    A SECURITY(2 'PASSWRD' +
    A 3 'USRID')
  3. To create the ICF file T1520DDC using the DDS source shown below, enter:

    CRTICFF FILE(MYLIB/T1520DDC) SRCFILE(QCPPLE/QADDSSRC) ACQPGMDEV(CAPPC1)

    Figure 151. T1520DDC -- DDS Source to Receive Password and User ID


    
    
    A R RCVPASS
    A UID 8A
    A PWD 10A
    A R VRYPASS
    A CHKPASS 1A
  4. Create an intrasystem device INTRAC. From the command line, enter:

    CRTDEVINTR DEVD(INTRAC) RMTLOCNAME(INTRAC) ONLINE(*NO)
  5. Vary on the intrasystem device INTRAC. From the command line, enter:

    VRYCFG CFGOBJ(INTRAC) CFGTYPE(*DEV) STATUS(*ON) RANGE(*OBJ) 
  6. To add a program device entry for ICF file T1520DDB, enter:

    ADDICFDEVE FILE(MYLIB/T1520DDB) PGMDEV(CAPPC2) RMTLOCNAME( CAPPC1)
    MODE(CAPPCMOD)
  7. To add a program device entry for ICF file T1520DDC, enter:

    ADDICFDEVE FILE(MYLIB/T1520DDC) PGMDEV(CAPPC1) RMTLOCNAME(*REQUESTER)
    MODE(CAPPCMOD)
  8. To create the program T1520ICF using the source shown below, enter:

    CRTBNDC PGM(MYLIB/T1520ICF) SRCFILE(QCPPLE/QACSRC)

    Figure 152. T1520ICF -- ILE C Source to Send and Receive Data


    
    
    /* This program sends a userid and password to a target program */
    /* on another system. The target program returns the userid and */
    /* password. This program verifies the returned values. */
    #include <stdio.h>
    #include <recio.h>
    #include <stdlib.h>
    #include <string.h>
    #define ID_SIZE 8
    #define PASSWD_SIZE 10
    #define RCD_SIZE ID_SIZE + PASSWD_SIZE
    #define ERROR '2'
    #define VALID '1'

    _RFILE *fp;
    void ioCheck(char *majorRc)
    {
    if ( memcmp(majorRc, "00", 2) != 0 )
    {
    printf("Fatal I/O error occurred, program ends\n");
    _Rclose(fp);
    exit(1);
    }

    int main(void)
    {
    _RIOFB_T *fb;
    char idPass[RCD_SIZE];
    char buf[RCD_SIZE + 1];
    char passwordCheck=ERROR;
    
    
    /* Open the source file T1520DDB. */ 
    if ( (fp = _Ropen("*LIBL/T1520DDB", "ar+")) == NULL )
    {
    printf("Could not open SOURCE ICF file\n");
    exit(2);


    /* Start the target program T1520TGT. */ 
    _Racquire(fp, "DEV1"); /* acquire device */
    _Rformat(fp, "EVOKPGM");
    fb = _Rwrite(fp, "", 0);
    ioCheck(fb->sysparm->_Maj_Min.major_rc);

    /* Get the user-id and password. */ 
    memset(idPass, ' ', RCD_SIZE);
    printf("Enter user-id (maximum 8 characters):\n");
    scanf("%s", buf);
    memcpy(idPass, buf, strlen(buf));
    printf("Enter password (maximum 10 characters):\n");
    scanf("%s", buf);
    memcpy(idPass + ID_SIZE, buf, strlen(buf));

    /* Send data to the TARGET program T1520TGT. */
    _Rformat(fp, "SNDPASS");
    fb = _Rwrite(fp, idPass, RCD_SIZE);
    ioCheck(fb->sysparm->_Maj_Min.major_rc);

    /* Receive data from TARGET program T1520TGT. */ 
    _Rformat(fp, "CHKPASS");
    fb = _Rreadn(fp, &passwordCheck, 1, __DFT);
    ioCheck(fb->sysparm->_Maj_Min.major_rc);

    /* If a problem, such as a communications line is down, occurs in the */
    /* TARGET program, then end the program. */
    /* Otherwise, print the password verification. */
     
    if ( passwordCheck == ERROR )
    {
    _Rclose(fp);
    exit(3);
    }
    else if ( passwordCheck == VALID )
    {
    printf("Password valid\n");
    }
    else
    {
    printf("Password invalid\n");
    }
    _Rclose(fp);
    return(0);
    }

    The _Ropen() function opens the record file T1520DDB. The _Rformat() function accesses the record format EVOKPGM in the file T1520DDB. The EVOKE statement in T1520DDB calls the target program T1520TGT. The _Rformat() function accesses the record format SNDPASS in the file T1520DDB. The user ID and password is sent to the target program T1520TGT. The _Rformat() function accesses the record format CHKPASS in the file T1520DDB. The received password and user ID is then verified.

  9. To create the program T1520TGT using the following source, enter:

    CRTBNDC PGM(MYLIB/T1520TGT) SRCFILE(QCPPLE/QACSRC)

    Figure 153. T1520TGT -- ILE C Source to Check Data is Sent and Returned


    
    
    /* This program checks the userid and password. */
     
    #include <stdio.h>
    #include <recio.h>
    #include <string.h>
    #include <stdlib.h>
     
    #define ID_SIZE 8
    #define PASSWD_SIZE 10
    #define RCD_SIZE ID_SIZE + PASSWD_SIZE
    #define ERROR '2'
    #define VALID '1'
    #define INVALID '0'

    int main(void)
    {
    _RFILE *icff;
    _RFILE *pswd;
    _RIOFB_T *fb;

    char rcv[RCD_SIZE];
    char pwrd[RCD_SIZE];
    char vry;
     
    /* Open the TARGET file T1529DDC. */
     
    if ( (icff = _Ropen("QGPL/T1520DDC", "ar+")) == NULL )
    {
    printf("Could not open TARGET icf file T1520DDC\n");
    exit(1);
    }
    /* Open the PASSWORD file T1520DDA. */
     
    if ( (pswd = _Ropen("QGPL/T1520DDA", "rr")) == NULL )
    {
    printf("Could not open PASSWORD file T1520DDA\n");
    exit(2);
    }
    /* Read the information from the SOURCE program T1520ICF. */
     
    _Racquire(icff, "DEV1");
    _Rformat(icff, "RCVPASS");
    fb = _Rreadn(icff, &rcv, RCD_SIZE, __DFT);
    
    
    /* Check for errors and send response to SOURCE program. */
     
    if ( memcmp(fb->sysparm->_Maj_Min.major_rc, "00", 2) != 0 )
    {
    vry = ERROR;
    }
    else
    {
    fb = _Rreadk(pswd, &pwrd, RCD_SIZE, __DFT, &rcv, ID_SIZE);
     
    if ( fb->num_bytes == RCD_SIZE &&
    memcmp(pwrd + ID_SIZE, rcv + ID_SIZE, PASSWD_SIZE) == 0 )
    {
    vry = VALID;
    }
    else
    {
    vry = INVALID;
    }
    }
    _Rformat(icff, "VRYPASS");
    _Rwrite(icff, &vry, 1);
    _Rclose(icff);
    _Rclose(pswd);
    return(0);
    }

    The _Ropen() function opens the file T1520DDC. The _Ropen() function opens the password file T1520DDA. The _Rformat() function accesses the record format RCVPASS in the file T1520DDC. The _Rreadn() function reads the password and user ID from the source program T1520ICF. Errors are checked, and a response is sent to the source program T1520ICF.

  10. To run the program T1520ICF, enter:

    CALL PGM(MYLIB/T1520ICF)

    After calling the program, you may enter a user ID and password. If the password is correct, Password valid appears on the display; if it is incorrect, Password invalid appears.

    The output is as follows:

    +--------------------------------------------------------------------------------+
    |  Password valid                                                                |
    |  Press ENTER to end terminal session.                                          |
    +--------------------------------------------------------------------------------+


[ Top of Page | Previous Page | Next Page | Table of Contents ]