/* * PROGRAM: cksock.c * * DESCRIPTION: This is the client part of a CICS sockets web sample. * cksock.c contains all the CGI code for the client. It * is linked with sockets.c to provide a CGI program which * can issues TCP/IP socket calls. * * This program sends an initial FORM to the web browser, * receives input from the web-browser, sends this information * to the server using socket calls, and then sends the info * from the server back to the web browser and waits for input * again. * */ #include #include #include #define LF 10 #define HTML_BREAK printf("
%c", LF); #define HTML_HR printf("
%c", LF); #define HTML_NEWPARA printf("

%c", LF); typedef struct { char name[128]; char val[128]; } entry; typedef struct { char qfield[256]; int qlen; char qname[256]; } fields; static fields idxfields[] = { {"XTran", 4, "Tranid"}, {"XAddr", 20, "Address"}, {"XPort", 5, "Port"}, {"", 0, ""} }; /* function prototypes */ void send_doc(int which); void getword(char *word, char *line, char stop); void plustospace(char *str); char *do_socket_call(char *addr, char *port, char *tran, char *action, char *queue, char *qdata); /* * getword() * * This function parses the HTML text received from the form, and returns * the next word (ie. up to the next 'stop' character) * */ void getword(char *word, char *line, char stop) { int x = 0, y; for (x=0; ((line[x]) && (line[x] != stop)); x++) word[x] = line[x]; word[x] = '\0'; if (line[x]) ++x; y = 0; while (line[y++] = line[x++]); } /* * plustospace() * * This function converts all '+' characters to spaces in the input text * from the form. * */ void plustospace(char *str) { register int x; for (x=0; str[x];x++) if (str[x] == '+') str[x] = ' '; } /* * send_doc() * * Sends the initial HTML form * */ void send_doc(int which) { int x; printf("%c", LF); printf("NERDC CICS Check Sockets CGI%c", LF); printf("

NERDC CICS Check Sockets CGI

%c", LF); HTML_NEWPARA HTML_HR printf("Select the CICS Transid, Host IP address, and Port number to connect to, then Submit:%c", LF); printf("
%c", getenv("SERVER_NAME"), getenv("SERVER_PORT"), getenv("SCRIPT_NAME"), LF); HTML_NEWPARA printf("%c", LF); /* printf("%s ", idxfields[0].qname); */ printf("%c" ,idxfields[0].qfield, idxfields[0].qlen ,idxfields[0].qlen+1,LF); printf("Transid=SOKT, or ", LF); printf("%c" ,idxfields[0].qfield, idxfields[0].qlen ,idxfields[0].qlen+1,LF); printf("Transid=XXXX (intentionally invalid)", LF); HTML_NEWPARA /* printf(" %s ", idxfields[1].qname); */ printf("%c" ,idxfields[1].qfield, idxfields[1].qlen ,idxfields[1].qlen,LF); printf("Host=nermvs.nerdc.ufl.edu (NER1), or ", LF); HTML_BREAK printf("%c" ,idxfields[1].qfield, idxfields[1].qlen ,idxfields[1].qlen,LF); printf("Host=nermvsa.nerdc.ufl.edu (NER2), or ", LF); HTML_BREAK printf("%c" ,idxfields[1].qfield, idxfields[1].qlen ,idxfields[1].qlen,LF); printf("Host=nermvst.nerdc.ufl.edu (NER4)", LF); HTML_NEWPARA /* printf(" %s ", idxfields[2].qname); */ printf("%c" ,idxfields[2].qfield, idxfields[2].qlen ,idxfields[2].qlen,LF); printf("Port=3000 (TST1), or ", LF); printf("%c" ,idxfields[2].qfield, idxfields[2].qlen ,idxfields[2].qlen,LF); printf("Port=3001 (PRD3), or ", LF); HTML_BREAK printf("%c" ,idxfields[2].qfield, idxfields[2].qlen ,idxfields[2].qlen,LF); printf("Port=3002 (PRD5), or ", LF); printf("%c" ,idxfields[2].qfield, idxfields[2].qlen ,idxfields[2].qlen,LF); printf("Port=3003 (TSTI), or ", LF); HTML_BREAK printf("%c" ,idxfields[2].qfield, idxfields[2].qlen ,idxfields[2].qlen,LF); printf("Port=3004 (TSTI), or ", LF); printf("%c" ,idxfields[2].qfield, idxfields[2].qlen ,idxfields[2].qlen,LF); printf("Port=3005 (TST5), or ", LF); HTML_BREAK printf("%c" ,idxfields[2].qfield, idxfields[2].qlen ,idxfields[2].qlen,LF); printf("Port=3006 (TST5), or ", LF); printf("%c" ,idxfields[2].qfield, idxfields[2].qlen ,idxfields[2].qlen,LF); printf("Port=3007 (PRD7), or ", LF); HTML_BREAK printf("%c" ,idxfields[2].qfield, idxfields[2].qlen ,idxfields[2].qlen,LF); printf("Port=3008 (PRD8), or ", LF); printf("%c" ,idxfields[2].qfield, idxfields[2].qlen ,idxfields[2].qlen,LF); printf("Port=3009 (DEV1), or ", LF); HTML_BREAK printf("%c" ,idxfields[2].qfield, idxfields[2].qlen ,idxfields[2].qlen,LF); printf("Port=3010 (PRD1), or ", LF); printf("%c" ,idxfields[2].qfield, idxfields[2].qlen ,idxfields[2].qlen,LF); printf("Port=3011 (TST2), or ", LF); HTML_BREAK printf("%c" ,idxfields[2].qfield, idxfields[2].qlen ,idxfields[2].qlen,LF); printf("Port=3012 (PRD2)", LF); printf("%c", LF); HTML_NEWPARA HTML_HR HTML_NEWPARA printf("%c", LF); printf(" %c", LF); printf("
%c", LF); HTML_HR printf("
    %c", LF); printf("
  • This CGI application uses an AIX \"C\" socket client program and a High Level Assembler CICS/ESA socket child server program.%c", LF); HTML_BREAK printf("
  • Client program (extensively modified) based upon an IBM sample.%c", LF); HTML_BREAK printf("
  • Implemented at NERDC in April of 1998 by Steve Ware.%c", LF); printf("
%c", LF); HTML_HR printf("Questions, comments, or suggestions regarding this page should be directed to cicsgrp@nersp.nerdc.ufl.edu.%c", LF); HTML_NEWPARA printf("\"NERDCReturn to NERDC CICS Home Page%c", LF); HTML_NEWPARA printf("Last updated:December 1, 1998, by Steve Ware.%c", LF); } main(int argc, char *argv[]) { char message[2001]; char CICSTran[5]; char CICSAddr[21]; char CICSPort[6]; char CICSAction[7]; char CICSQueue[9]; char CICSQData[51]; entry entries[256]; register int x,m=0; char *cl; char *tp; char returnstr[1024], typestr[4098], commandstr[8192], serverstr[256]; printf("Content-type: text/html%c%c",LF,LF); cl = getenv("QUERY_STRING"); if((!cl) || (!cl[0])) { send_doc(0); exit(1); } if (cl[0] != '\0') { getword(returnstr, cl, '&'); getword(typestr, returnstr, '='); strcpy(CICSTran, returnstr); getword(returnstr, cl, '&'); getword(typestr, returnstr, '='); strcpy(CICSAddr, returnstr); getword(returnstr, cl, '&'); getword(typestr, returnstr, '='); strcpy(CICSPort, returnstr); getword(returnstr, cl, '&'); getword(typestr, returnstr, '='); strcpy(CICSAction, returnstr); getword(returnstr, cl, '&'); getword(typestr, returnstr, '='); strcpy(CICSQueue, returnstr); getword(returnstr, cl, '&'); getword(typestr, returnstr, '='); plustospace(returnstr); strcpy(CICSQData, returnstr); } printf("%c%c", LF,LF); printf("

Query Results

%c", LF); HTML_NEWPARA CICSTran[4]='\0'; /* ensure null-termination of strings */ CICSAddr[20]='\0'; CICSPort[5]='\0'; CICSAction[1]='\0'; CICSQueue[8]='\0'; CICSQData[50]='\0'; /* * Here we call do_socket_call() passing the user information. This * passes the info the server, and returns the HTML information which * the server sends back. * This return info is then displayed. * The server has control over what is sent back and hence what is * displayed. */ strcpy(message, do_socket_call((char *)CICSAddr, (char *)CICSPort, (char *)CICSTran, (char *)CICSAction, (char *)CICSQueue, (char *)CICSQData)); printf("%s %c", message, LF); printf("%c", LF); }