001000$CONTROL POST85,USLINIT,BOUNDS,LOCKING,LINES=58
001100 IDENTIFICATION DIVISION.
001200 PROGRAM-ID. TBASE.
001300 AUTHOR. D BECKER.
001400 DATE-WRITTEN. WED, DEC 19, 2001.
001500 DATE-COMPILED.
001600
001700***********************************************************
001800* *
001900* This program accepts a database name and password; *
002000* *
002100* It is a CGI program interacting with an Apache Server *
002200* gathering information from a post in an html page *
002300* *
002400* *
002500* If the database can be opened (mode 5), the Image *
002600* intrisics are called to determine the characteristics *
002700* of the database. *
002800* *
002900* First, a summary of the datasets is shown; *
003000* Next, all the active items in the database are shown; *
003100* Finally, datasets are shown with their items and paths. *
003200* *
003300* Developers are advised that Chapter 5 of the TurboIMAGE *
003400* Database Management System Reference, Edition 7, is *
003500* vital to understand the DBINFO calls used to power *
003600* the program. *
003700* *
003800* Note that this program also checks to see if TPI is *
003900* present and if it is turned on, will account for *
004000* additional key fields used as indices by the Third *
004100* Party Index provider [note that OMNIDEX was used for *
004200* the model and SUPERDEX may not work the same way. *
004300* *
004400* The following CSMC script is provided to allow *
004500* program compilation [note: Use lower case!]: *
004600*
004700* PARM PROG,SUFF="CC"
004800* COB85XL !PROG!SUFF
004900* LINK $OLDPASS;TO=./!PROG;RL=/lib/libc.a ;posix ;share
005000* PURGE !PROG
005100* COPY ./!PROG , !PROG
005200* PURGE /APACHE/PUB/cgi-bin/!PROG
005300* COPY ./!PROG , /APACHE/PUB/cgi-bin/!PROG
005400* XEQ /SYS/HPBIN/CHMOD;INFO=" 777 /APACHE/PUB/cgi-bin/!PROG"
005500*
005600* Note that using :CSMC tbase works just fine *
005700* DON'T USE UPPER CASE ON tbase! *
005800* *
005900* *
006000***********************************************************
006100
006200 ENVIRONMENT DIVISION.
006300 CONFIGURATION SECTION.
006400
006500 SOURCE-COMPUTER. HP-3000.
006600 OBJECT-COMPUTER. HP-3000.
006700
006800 SPECIAL-NAMES.
006900 CONDITION-CODE IS CC
007000 SYMBOLIC CHARACTERS NUL is 1, LF is 11, CR is 14.
007100
007200 DATA DIVISION.
007300 WORKING-STORAGE SECTION.
007400 77 XUB1 PIC S9(9) COMP VALUE 0.
007500 77 TPI-MODE PIC X VALUE " ".
007600 88 TPI-ON VALUE "9".
007700
007800 77 PATH-SW9 PIC X VALUE " ".
007900 88 PATH-SW VALUE "9".
008000
008100 77 GOAL PIC X(12) VALUE SPACES.
008200 77 DATELINE PIC X(28) VALUE SPACES.
008300 77 DZ PIC Z9-.
008400
008500 77 DISPLAY-TYPE PIC X(12) VALUE SPACES.
008600
008700 77 PARM-SIZE PIC S9(4) COMP VALUE 80.
008800 77 PARM-VALUE PIC S9(4) COMP VALUE 0.
008900
009000 1 INFO.
009100 5 INFO-X PIC X VALUE " ".
009200 5 INFO-R PIC X(79) VALUE " ".
009300
009400 01 PARM-INFO.
009500 5 PARM-INFO72 PIC X(72) VALUE " ".
009600 5 FILLER PIC X(8) VALUE " ".
009700
009800 77 WHO-MODE PIC S9(4) COMP VALUE 0.
009900 77 WHO-MODE1 PIC S9(4) COMP VALUE 0.
010000 77 WHO-USER PIC X(8) VALUE " ".
010100 77 WHO-ACCOUNT PIC X(8) VALUE " ".
010200 77 WHO-GROUP PIC X(8) VALUE " ".
010300 77 INFO-LENGTH PIC S9(4) COMP VALUE -80.
010400
010500 77 SUB PIC S9(4) COMP VALUE 0.
010600 77 SUB1 PIC S9(4) COMP VALUE 0.
010700 77 SUB2 PIC S9(4) COMP VALUE 0.
010800 77 SUB3 PIC S9(4) COMP VALUE 0.
010900 77 SUB4 PIC S9(4) COMP VALUE 0.
011000 77 SUB5 PIC S9(4) COMP VALUE 0.
011100 77 SUB6 PIC S9(4) COMP VALUE 0.
011200 77 SUB7 PIC S9(4) COMP VALUE 0.
011300 77 SUB8 PIC S9(4) COMP VALUE 0.
011400 77 SUB9 PIC S9(4) COMP VALUE 0.
011500
011600 77 INFO-IN PIC X VALUE " ".
011700 88 INFO-IN-OK VALUE " ".
011800
011900 77 DSPLY-ITM PIC ----9.
012000
012100 77 LINE-LENGTH PIC S9(4) COMP VALUE 256.
012200 77 NEG-LENGTH PIC S9(4) COMP VALUE -80.
012300
012400 77 DSPLY PIC ---,---,---,--9.
012500
012600 01 CTL-Y-FLAG PIC S9(4) COMP.
012700 01 Y-FLAG PIC X VALUE " ".
012800
012900 1 DISPLAY-LINE.
013000 5 DSPLY-LN OCCURS 1 TO 256 TIMES DEPENDING ON LINE-LENGTH
013100 PIC X.
013200
013300 1 SJW.
013400 3 SJW1.
013500 5 SJW-NUM PIC 9(4).
013600 5 SJW-XO.
013700 7 SJW-X PIC X.
013800 7 SJW-R1 PIC X(79).
013900 3 SJW2 REDEFINES SJW1.
014000 5 SJW-X2 PIC X.
014100 5 SJW-R3 PIC X(83).
014200
014300 77 UPPER PIC X(26) VALUE "ABCDEFGHIJKLMNOPQRSTUVWXYZ".
014400 77 LOWER PIC X(26) VALUE "abcdefghijklmnopqrstuvwxyz".
014500
014600 1 QUALIFIER.
014700 3 BUFFER.
014800 05 Q0 OCCURS 256 TIMES PIC S9(4) COMP VALUE 0.
014900 3 XITEMS.
015000 05 I0 OCCURS 1024 TIMES PIC S9(4) COMP VALUE 0.
015100 3 DATASET-ITEMS.
015200 05 DI OCCURS 1024 TIMES PIC S9(4) COMP VALUE 0.
015300 3 ITEM-DATASETS.
015400 05 IM OCCURS 256 TIMES PIC S9(4) COMP VALUE 0.
015500 3 TPIITEMS.
015600 05 TPI1 PIC S9(4) COMP VALUE 0.
015700 05 TPIO OCCURS 1024 TIMES PIC S9(4) COMP VALUE 0.
015800
015900 1 SK.
016000 3 SKO OCCURS 256 TIMES.
016100 5 SKI PIC 9(4) COMP VALUE 0.
016200 5 SKM PIC 9(4) COMP VALUE 0.
016300
016400 1 SEARCH-KEY.
016500 3 SEARCH-KEY-ITEM PIC 9(4) COMP VALUE 0.
016600 3 SEARCH-KEY-MASTER PIC 9(4) COMP VALUE 0.
016700
016800 1 PATHS.
016900 05 PATH-NO PIC 9(4) COMP VALUE 0.
017000 05 PATH-OCCURS OCCURS 16 TIMES.
017100 7 PATH-KEY PIC 9(4) COMP VALUE 0.
017200 7 PATH-SEARCH PIC 9(4) COMP VALUE 0.
017300 7 PATH-SORT PIC 9(4) COMP VALUE 0.
017400
017500 01 BASE.
017600 03 BASE-ID PIC X(2) VALUE SPACES.
017700 03 BASE-NAME PIC X(26) VALUE "TEST.BASE.DEVEL;".
017800
017900 01 PASSWORD PIC X(9) VALUE "ABC123;".
018000
018100 01 DUMMY PIC X(2) VALUE SPACES.
018200
018300 01 ALL-LIST PIC X(2) VALUE "@;".
018400
018500 01 SAME-LIST PIC X(2) VALUE "*;".
018600
018700 01 STAT.
018800 03 DBS-IMAGE.
018900 05 IMAGE-STATUS PIC S9(4) COMP VALUE 0.
019000 05 ENTRYLEN PIC S9(4) COMP VALUE 0.
019100 05 RECDNUMB PIC S9(9) COMP VALUE 0.
019200 05 CHAINLEN PIC S9(9) COMP VALUE 0.
019300 05 BACKPOINT PIC S9(9) COMP VALUE 0.
019400 05 FORWPOINT PIC S9(9) COMP VALUE 0.
019500
019600 01 DB-MODES.
019700 03 MODE1 PIC S9(4) COMP VALUE 1.
019800 03 MODE2 PIC S9(4) COMP VALUE 2.
019900 03 MODE3 PIC S9(4) COMP VALUE 3.
020000 03 MODE4 PIC S9(4) COMP VALUE 4.
020100 03 MODE5 PIC S9(4) COMP VALUE 5.
020200 03 MODE6 PIC S9(4) COMP VALUE 6.
020300 03 MODE7 PIC S9(4) COMP VALUE 7.
020400 03 MODE8 PIC S9(4) COMP VALUE 8.
020500 03 MODE102 PIC S9(4) COMP VALUE 102.
020600 03 MODE103 PIC S9(4) COMP VALUE 103.
020700 03 MODE104 PIC S9(4) COMP VALUE 104.
020800 03 MODE202 PIC S9(4) COMP VALUE 202.
020900 03 MODE203 PIC S9(4) COMP VALUE 203.
021000 03 MODE204 PIC S9(4) COMP VALUE 204.
021100 03 MODE301 PIC S9(4) COMP VALUE 301.
021200 03 MODE302 PIC S9(4) COMP VALUE 302.
021300 03 MODE801 PIC S9(4) COMP VALUE 801.
021400 03 MODE802 PIC S9(4) COMP VALUE 802.
021500 03 MODE812 PIC S9(4) COMP VALUE 812.
021600 03 MODE813 PIC S9(4) COMP VALUE 813.
021700 03 MODE814 PIC S9(4) COMP VALUE 814.
021800 03 MODE821 PIC S9(4) COMP VALUE 821.
021900 03 MODE832 PIC S9(4) COMP VALUE 832.
022000
022100 1 TPI-DATA.
022200 5 TPI-PRODUCT PIC X(40) VALUE SPACES.
022300 5 TPI-VERSION PIC X(10) VALUE SPACES.
022400 5 TPI-INSTALLED PIC S9(4) COMP VALUE 0.
022500 5 FILLER PIC S9(4) COMP VALUE 0.
022600 5 TPI-TIME PIC S9(9) COMP VALUE 0.
022700
022800 01 DS-USERID-M PIC X(9) VALUE "USERID-M;".
022900
023000 01 DB-USERID-M.
023100 03 USERID PIC X(8) VALUE SPACES.
023200 03 ACCT PIC X(8) VALUE SPACES.
023300
023400 01 DS-SORT-KEY-A PIC X(11) VALUE "SORT-KEY-A;".
023500
023600 01 DB-SORT-KEY-A.
023700 03 SORT-KEY PIC X(2) VALUE SPACES.
023800
023900 01 DS-JOB-DEF-D PIC X(10) VALUE "JOB-DEF-D;".
024000
024100 01 DB-JOB-DEF-D.
024200 03 USERID PIC X(8) VALUE SPACES.
024300 03 ACCT PIC X(8) VALUE SPACES.
024400 03 CHANGE-INDIC PIC X(2) VALUE SPACES.
024500 03 SORT-KEY PIC X(2) VALUE SPACES.
024600 03 INTR-NUM PIC 9(6) VALUE ZEROS.
024700 03 PARM-CNT PIC S9(4) COMP VALUE 0.
024800 03 SCND-OPERAND PIC S9(9) COMP VALUE 0.
024900
025000 01 DI-USERID PIC X(7) VALUE "USERID;".
025100
025200 01 DI-SORT-KEY PIC X(9) VALUE "SORT-KEY;".
025300
025400 01 LIST.
025500 03 LIST-1 PIC X(65) VALUE "@;".
025600
025700 77 SS-PTR1 PIC S9(4) COMP VALUE 0.
025800 77 SS-PTR2 PIC S9(4) COMP VALUE 0.
025900 77 SS-PTR3 PIC S9(4) COMP VALUE 0.
026000 77 SS-PTR4 PIC S9(4) COMP VALUE 0.
026100 77 SS-PTR5 PIC S9(4) COMP VALUE 0.
026200 77 SS-PTR6 PIC S9(4) COMP VALUE 0.
026300
026400 01 DS-TABLE.
026500 5 DATA-SET-TABLE OCCURS 256 TIMES PIC X(16) VALUE SPACES.
026600 5 DATA-SET-REF OCCURS 256 TIMES PIC S9(4) COMP VALUE 0.
026700
026800 01 SSS-TABLE.
026900 5 SSS-OCCURS OCCURS 256 TIMES.
027000
027100 7 SET-INFO.
027200 9 DATA-SET-NAME PIC X(16) VALUE SPACES.
027300 9 SSS-KEY REDEFINES DATA-SET-NAME PIC X(16).
027400 9 SSS-KEYC REDEFINES DATA-SET-NAME PIC X(16).
027500 9 SSS-REST.
027600 11 SSS-RESTC.
027700 19 DATA-SET-TYPE PIC XX VALUE SPACES.
027800 19 DATA-SET-ENTRY-LENGTH PIC S9(4) COMP VALUE 0.
027900 19 DATA-SET-BLOCKING-FACTOR PIC S9(4) COMP VALUE 0.
028000 19 DATA-SET-ORIGINAL-NUMBER PIC S9(4) COMP VALUE 0.
028100 19 FILLER PIC S9(4) COMP VALUE 0.
028200 19 DATA-SET-ENTRIES PIC S9(9) COMP VALUE 0.
028300 19 DATA-SET-CAPACITY PIC S9(9) COMP VALUE 0.
028400
028500 01 DSHEAD.
028600 5 FILLER PIC XXX VALUE "".
028700 5 FILLER PIC X(28) VALUE
028800 ' Data set name'.
028900 5 FILLER PIC X(10) VALUE ' Type '.
029000 5 FILLER PIC X(8) VALUE 'Length'.
029100 5 FILLER PIC X(11) VALUE ' Records'.
029200 5 FILLER PIC X(12) VALUE ' Capacity '.
029300 5 FILLER PIC X(6) VALUE ' %Full'.
029400 5 FILLER PIC X(4) VALUE ''.
029500 5 FILLER PIC X VALUE CR.
029600 5 FILLER PIC X VALUE LF.
029700
029800 1 DSLINE.
029900 5 DSTYPE PIC X(9) VALUE " ".
030000 5 DSRECSZ PIC ZZZ,ZZ9-.
030100 5 DSENTRIES PIC ZZZ,ZZZ,ZZ9-.
030200 5 DSCAPACITY PIC ZZZ,ZZZ,ZZ9-.
030300 5 FILLER PIC X(14) VALUE ''.
030800 5 DSPERCENT PIC ZZ9.9.
030900 5 FILLER PIC X VALUE '%'.
031000 5 FILLER PIC X(7) VALUE ''.
031100 5 FILLER PIC X VALUE CR.
031200 5 FILLER PIC X VALUE LF.
031300
031400 77 DS-PERCENT PIC 999V9 COMP VALUE 0.
031500
031600 1 SORT-RECORD.
031700 5 SORT-KEY.
031800 7 SORT-KEYC PIC X(16).
031900
032000 5 SORT-REST.
032100 7 SORT-RESTC PIC X(20).
032200
032300 77 SORT-IND PIC X VALUE "0".
032400 88 SORT-END VALUE "9".
032500
032600 77 XS-PTR1 PIC S9(4) COMP VALUE 0.
032700 77 XS-PTR2 PIC S9(4) COMP VALUE 0.
032800 77 XS-PTR3 PIC S9(4) COMP VALUE 0.
032900 77 XS-PTR4 PIC S9(4) COMP VALUE 0.
033000 77 XS-PTR5 PIC S9(4) COMP VALUE 0.
033100 77 XS-PTR6 PIC S9(4) COMP VALUE 0.
033200
033300 77 XSS-TEMP-PROPERTIES PIC X(11).
033400
033500 01 ITEM-NAME-WORK.
033600 5 ITEM-NAMEN PIC X(60) VALUE SPACES.
033700
033800 01 XSS-DISPLAY-TABLE.
033900 3 XSS-DISPLAY OCCURS 1024 TIMES.
034000 5 XSS-ITEM PIC X(17) VALUE SPACES.
034100 5 XSS-PROPERTIES PIC X(11) VALUE SPACES.
034200
034300 01 XSS-TABLE.
034400 5 XSS-OCCURS OCCURS 1024 TIMES.
034500 7 ITEM-INFO.
034600 9 ITEM-NAME PIC X(16) VALUE SPACES.
034700 9 XSS-REST.
034800 11 XSS-RESTC.
034900 13 ITEM-TYPE PIC XX VALUE SPACES.
035000 13 ITEM-LENGTH PIC S9(4) COMP VALUE 0000.
035100 13 ITEM-COUNT PIC S9(4) COMP VALUE 0.
035200 13 ITEM-ORIGINAL PIC S9(4) COMP VALUE 0.
035300 13 FILLER PIC S9(4) COMP VALUE 0.
035400
035500 1 TXSS-HEAD.
035600 5 TXSSHEAD PIC X(22) VALUE 'Omnidex Items:'.
035700 5 FILLER PIC X VALUE CR.
035800 5 FILLER PIC X VALUE LF.
035900 5 FILLER PIC X VALUE CR.
036000 5 FILLER PIC X VALUE LF.
036100
036200 01 TXSS-DISPLAY-TABLE.
036300 3 TXSS-DISPLAY.
036400 5 TXSS-ITEM PIC X(17) VALUE SPACES.
036500 5 TXSS-PROPERTIES PIC X(11) VALUE SPACES.
036600
036700 01 TXSS-TABLE.
036800 5 TXSS-OCCURS.
036900 7 TITEM-INFO.
037000 9 TITEM-NAME PIC X(16) VALUE SPACES.
037100 9 TXSS-REST.
037200 11 TXSS-RESTC.
037300 13 TITEM-TYPE PIC XX VALUE SPACES.
037400 13 TITEM-LENGTH PIC S9(4) COMP VALUE 0000.
037500 13 TITEM-COUNT PIC S9(4) COMP VALUE 0.
037600 13 TITEM-KTYPE PIC S9(4) COMP VALUE 0.
037700 13 FILLER PIC S9(4) COMP VALUE 0.
037800
037900 1 XORT-RECORD.
038000 5 XORT-KEY.
038100 7 XORT-KEYC PIC X(16).
038200
038300 5 XORT-REST.
038400 7 XORT-RESTC PIC X(10).
038500
038600 77 XORT-IND PIC X VALUE "0".
038700 88 XORT-END VALUE "9".
038800
038900 77 NR-PREFIX1 PIC X(5) VALUE "summ_".
039000 77 NR-PREFIX2 PIC X(5) VALUE "href_".
039100 77 NR-NAME PIC X(32) VALUE SPACES.
039200
039300 1 NAME-REF.
039400 5 FILLER PIC X(9) VALUE '".
039900 5 NRNAME PIC X(32) VALUE SPACES.
040000
040100 1 ITEM-REF.
040200 5 FILLER PIC X(3) VALUE '".
040700 5 ITEMREF2 PIC X(30) VALUE SPACES.
040800 5 ITEMTYPE PIC X(8) VALUE SPACES.
040900 5 ITEMCHAR PIC X(80) VALUE SPACES.
041000
041100
041200 1 SET-IN-ITEM.
041300 5 FILLER PIC X(5) VALUE ' QUERY_TEXT = ".
043100 5 QUERYTEXT PIC X(256) VALUE SPACES.
043200 5 FILLER PIC X(5) VALUE " '.
047500 77 H3 PIC X(24) VALUE 'Database Cross Reference'.
047600 77 H4 PIC X(12) VALUE '
'.
047700 77 HF1 PIC X(45) VALUE
047800 '".
049200
049300 01 HREFS.
049400 05 FILLER PIC X(25) VALUE '
' CRLF. 055900 DISPLAY HF6 CRLF. 056000 DISPLAY HF6 '
' CRLF. 056100 056200 DISPLAY HF7 CRLF. 056300 DISPLAY HF8 '
' CRLF. 056400 DISPLAY HF9 CRLF. 056500 DISPLAY HF9 CRLF. 056600 056700 DISPLAY HEFORM CRLF. 056800 056900 CALL INTRINSIC "DATELINE" USING DATELINE. 057000 DISPLAY 'Cross Reference for ' BASE-NAME ' - ' 057100 DATELINE. 057200 057300 DISPLAY "" CR LF. 057400 057500 DISPLAY HREFS. 057600 057700 CALL "DBOPEN" USING BASE, PASSWORD, MODE5, STAT. 057800 057900 IF IMAGE-STATUS NOT = 0 058000 DISPLAY "Database " BASE-NAME 058100* " pass=" PASSWORD 058200 " not opened" CRLF 058300 058400 PERFORM DBEXPLAIN 058500 058600 ELSE 058700 058800 PERFORM BASIC-PROGRAM. 058900 059000 DISPLAY "" CR LF 059100 DISPLAY "" CR LF. 059200 059300 STOP RUN. 059400 059500 TPI. 059600 INITIALIZE TPI-DATA. 059700 CALL "DBINFO" USING BASE, QUALIFIER, MODE801, STAT, 059800 TPI-DATA. 059900 060000 IF IMAGE-STATUS NOT = 0 OR TPI-PRODUCT = SPACES 060100 DISPLAY "No Third Party Indexing (TPI) on " 060200 BASE-NAME '' CRLF 060300 ELSE 060400 CALL "DBINFO" USING BASE, QUALIFIER, MODE802, STAT, 060500 SUB 060600 IF IMAGE-STATUS NOT = 0 PERFORM DBEXPLAIN 060700 ELSE 060800 IF SUB > 0 060900 DISPLAY "TPI Enabled: " TPI-PRODUCT CRLF 061000 DISPLAY " Version: " TPI-VERSION CRLF 061100 SET TPI-ON TO TRUE 061200 ELSE 061300 DISPLAY "TPI Disabled: " TPI-PRODUCT CRLF 061400 DISPLAY " Version: " TPI-VERSION CRLF. 061500 061600* IF TPI-ON 061700* MOVE 813 TO MODE103 061800* MOVE 814 TO MODE104. 061900 062000 GET-VARIABLES. 062100* Get the information from the post: 062200 062300 STRING "SERVER_SOFTWARE", NUL 062400 DELIMITED BY SIZE INTO ENV-NAME. 062500 062600 PERFORM MY-GETENV. 062700 062800 STRING "REMOTE_ADDR", NUL 062900 DELIMITED BY SIZE INTO ENV-NAME. 063000 063100 PERFORM MY-GETENV. 063200 063300 STRING ENV-TEXT DELIMITED BY NUL 063400 INTO TCPIP. 063500 063600 STRING "REQUEST_METHOD" NUL 063700 DELIMITED BY SIZE INTO env-name. 063800 063900 PERFORM my-getenv. 064000 064100 STRING "CONTENT_LENGTH" NUL 064200 DELIMITED BY SIZE INTO env-name. 064300 064400 PERFORM my-getenv. 064500 064600* DISPLAY "POST Method received CONTENT_LENGTH as " 064700* env-text (1 : env-length) "
" CR LF. 064800 064900 IF env-length = 0 then 065000 065100 DISPLAY "GET Method needs valid QUERY_STRING
" CR LF. 065200 065300* ELSE 065400 065500* DISPLAY "GET Method received QUERY_STRING as " 065600* env-text (1:env-length) "
" CR LF. 065700 065800 COMPUTE post-length = function numval (env-text) 065900 066000 IF post-length > function length (post-buf) then 066100 066200 DISPLAY "Too much DATA for my POST buffer
" CR LF 066300 066400 ELSE 066500 066600 COMPUTE post-get = - post-length 066700 066800 CALL intrinsic "readx" 066900 USING post-buf , post-get GIVING post-got. 067000 067100* DISPLAY "Received " post-got " bytes WITH " 067200* post-buf (1 : post-got) "
" CR LF. 067300 067400 MOVE POST-BUF (1 : POST-GOT) TO QUERYTEXT. 067500 067600 INSPECT QUERYTEXT REPLACING ALL "+" BY SPACES. 067700 INSPECT QUERYTEXT REPLACING ALL CR BY SPACES. 067800 INSPECT QUERYTEXT REPLACING ALL LF BY SPACES. 067900 INSPECT QUERYTEXT REPLACING ALL NUL BY SPACES. 068000 INSPECT QUERYTEXT REPLACING ALL LOW-VALUES BY SPACES. 068100 INSPECT QUERYTEXT REPLACING ALL HIGH-VALUES BY SPACES. 068200 068300* DISPLAY QUERY-TEXT. 068400 068500 UNSTRING QUERYTEXT 068600 DELIMITED BY "database=" OR "&password=" OR 068700 "&B1=" OR "&R1=" 068800 INTO UNSTRING1 DELIMITER IN UNSTRING2N 068900 UNSTRING2 DELIMITER IN UNSTRING3N 069000 UNSTRING3 DELIMITER IN UNSTRING4N 069100 UNSTRING4 DELIMITER IN UNSTRING5N 069200 UNSTRING5 DELIMITER IN UNSTRING6N 069300 ON OVERFLOW 069400 DISPLAY "Unstring Overflow Occured
" cr lf. 069500 069600* DISPLAY "UNSTRING1 =" UNSTRING1 CRLF. 069700* DISPLAY "UNSTRING2N=" UNSTRING2N CRLF. 069800 069900* DISPLAY "UNSTRING2 =" UNSTRING2 CRLF. 070000* DISPLAY "UNSTRING3N=" UNSTRING3N CRLF. 070100 070200* DISPLAY "UNSTRING3 =" UNSTRING3 CRLF. 070300* DISPLAY "UNSTRING4N=" UNSTRING4N CRLF. 070400 070500 070600* DISPLAY "UNSTRING4 =" UNSTRING4 CRLF. 070700* DISPLAY "UNSTRING5N=" UNSTRING5N CRLF. 070800 070900 071000* DISPLAY "UNSTRING5 =" UNSTRING5 CRLF. 071100* DISPLAY "UNSTRING6N=" UNSTRING6N CRLF. 071200 071300 IF UNSTRING2 NOT = SPACES MOVE UNSTRING2 TO BASE-NAME. 071400 IF UNSTRING3 NOT = SPACES MOVE UNSTRING3 TO PASSWORD. 071500 071600 071700 BASIC-PROGRAM. 071800 PERFORM TPI. 071900 DISPLAY '
'. 072000 DISPLAY 'Datasets Summary:
' CRLF. 072100 072200* Get all dataset names, store in table, sort in order: 072300 PERFORM DBINFO-CALL203. 072400 072500* Display datasets in database in summary format: 072600 072700 PERFORM DISPLAY-DATA-SETS Q0 (1) TIMES. 072800 DISPLAY HREFS. 072900 DISPLAY "
". 073000 073100* Display items in database: 073200 DISPLAY 'Items
' CRLF. 073300 PERFORM DBINFO-CALL103. 073400 DISPLAY HREFS. 073500 DISPLAY "
". 073600 DISPLAY 'Datasets:
' CRLF. 073700 DISPLAY "------- DATA SETS and Items " 073800 'for ' BASE-NAME "
" CRLF. 073900 MOVE "href_" TO NR-PREFIX1. 074000 MOVE "summ_" TO NR-PREFIX2. 074100 074200 MOVE 0 TO SS-PTR6. 074300 074400* Display datasets with items and paths: 074500 PERFORM DISPLAY-DATA-SET-ITEMS Q0 (1) TIMES. 074600 DISPLAY HREFS. 074700 DISPLAY "
". 074800 DISPLAY "
GET Method needs valid QUERY_STRING
" CR LF 145100 145200 145300 ELSE 145400 145500 DISPLAY "GET Method received QUERY_STRING as " 145600 env-text (1:env-length) "
" CR LF 145700 145800 COMPUTE loop-count = function numval (env-text) 145900 146000 IF loop-count < 1 then 146100 MOVE 1 to loop-count 146200 DISPLAY "Loop Count was less than one
" CR LF 146300 end-if 146400 146500 IF loop-count > 1000 then 146600 MOVE 1000 to loop-count 146700 DISPLAY "Loop Count was greater than 1000
" CR LF 146800 end-if 146900 147000* Now return the (loop-count) lines to the web client 147100 147200 DISPLAY "" CR LF 147300 147400 PERFORM WITH test before until loop-count < 1 147500 DISPLAY "Test message loop countdown at " loop-count CR LF 147600 SUBTRACT 1 from loop-count 147700 end-perform 147800 147900 DISPLAY "" CR LF 148000 148100 end-if. 148200 148300 148400* HANDLE-POST: Handle an http Method POST request from client 148500 148600* First retrieve the CONTENT_LENGTH Posix env var and echo it back 148700* to the client. Then read that number of bytes from stdin, unless 148800* it is more than our buffer can hold, and echo it back to the web 148900* page. Parse the input STRING for fields named MYTEXT and MYLOOP, 149000* supplying default values in case they are missing. Finally send 149100* output lines WITH MYTEXT according to the MYLOOP count. 149200 149300* Notice that the output loop does not CALL the PRINT intrinsic 149400* for every line but tries to combine as many lines as possible 149500* in the (relatively large) output buffer. This might improve the 149600* performance and reduce the resource consumption. The loops in 149700* handle-post and handle-get have been implemented differently to 149800* allow comparing them easily (try 1000 loops, for example). 149900 150000 150100 handle-post. 150200 STRING "CONTENT_LENGTH" NUL 150300 DELIMITED BY SIZE INTO env-name. 150400 150500 PERFORM my-getenv. 150600 150700 DISPLAY "
POST Method received CONTENT_LENGTH as " 150800 env-text (1 : env-length) "
" CR LF 150900 151000 COMPUTE post-length = function numval (env-text) 151100 151200 IF post-length > function length (post-buf) then 151300 151400 DISPLAY "Too much DATA for my POST buffer
" CR LF 151500 151600 ELSE 151700 151800 COMPUTE post-get = - post-length 151900 152000 CALL intrinsic "readx" 152100 USING post-buf , post-get GIVING post-got 152200 152300 DISPLAY "Received " post-got " bytes WITH " 152400 post-buf (1 : post-got) "
" CR LF 152500 152600* Use defaults IF MYLOOP and/or MYTEXT missing in HTML Form 152700 152800 MOVE 10 to loop-count 152900 MOVE "Default Test Message" to test-msg 153000 MOVE 20 to test-msg-len 153100 153200* Terminate the buffer STRING for easier parsing loop 153300 153400 MOVE "&" to post-buf (post-got + 1 : 1) 153500 153600* Begin parsing to extract MYLOOP and MYTEXT fields 153700 153800 MOVE 1 to post-pos 153900 154000 PERFORM WITH test before until post-length <= 0 154100 154200 INITIALIZE field-name 154300 INITIALIZE field-value 154400 154500 UNSTRING post-buf delimited by "=" 154600 INTO field-name count in field-name-len 154700 WITH pointer post-pos 154800 154900 UNSTRING post-buf delimited by "&" 155000 INTO field-value count in field-value-len 155100 WITH pointer post-pos 155200 155300 EVALUATE field-name 155400 WHEN "mytext" MOVE field-value to test-msg 155500 MOVE field-value-len to test-msg-len 155600 WHEN "myloop" COMPUTE loop-count 155700 = function numval (field-value) 155800 end-evaluate 155900 156000 SUBTRACT field-name-len from post-length 156100 SUBTRACT field-value-len from post-length 156200 SUBTRACT 2 from post-length 156300 156400 end-perform 156500 156600* Now return the (loop-count) lines to the web client, 156700* but utilize our buffer to use fewer calls to PRINT 156800 156900 DISPLAY "" CR LF 157000 157100 PERFORM WITH test before until loop-count <= 0 157200 157300 DISPLAY "Countdown at " loop-count 157400 " WITH message " test-msg (1 : test-msg-len) CR LF 157500 157600 157700 SUBTRACT 1 from loop-count 157800 157900 end-perform 158000 158100 DISPLAY "" CR LF 158200 158300 end-if. 158400 158500 158600* HANDLE-ERR: Return error to client for unknown REQUEST-METHOD 158700 158800 handle-err. 158900 DISPLAY "
Unknown REQUEST_METHOD " 159000 env-text (1 : env-length) " received
" CR LF. 159100 159200* MY-GETENV: retrieve Posix env var USING Posix C lib functions 159300 159400* getenv() returns pointer to C STRING, strlen() determines 159500* STRING length and strncpy() copies appropriate number of 159600* characters to a buffer var in our WORKING-STORAGE SECTION. 159700 159800* notice that this version silently clips "too long" input 159900* and returns a zero-length STRING for undefined env vars. 160000 160100 my-getenv. 160200 INITIALIZE env-text. 160300 160400 CALL "getenv" 160500 USING env-name GIVING env-pointer. 160600 160700 IF env-pointer > 0 then 160800 CALL "strlen" 160900 USING \env-pointer\ GIVING env-length 161000 161100 IF env-length > function length(env-text) then 161200 COMPUTE env-length = function length(env-text) 161300 end-if 161400 161500 CALL "strncpy" 161600 USING env-text , \env-pointer\ , \env-length\ 161700 ELSE 161800 MOVE 0 to env-length 161900 162000 end-if. 162100