#!/bin/sh # # This is a shell archive. To extract its contents, # execute this file with /bin/sh to create the file(s): # # cgi_4gla/4gl_wrapper.c cgi_4gla/circinfo.4gl # cgi_4gla/CDI_ANNOUNCE cgi_4gla/formsproc.c # cgi_4gla/Makefile cgi_4gla/formsproc.h # cgi_4gla/README cgi_4glb/README # cgi_4gla/WEB_PAGE.TXT cgi_4glb/formsproc.c # # This shell archive created: Tue Jan 27 10:00:17 EST 1998 # if [ ! -d ./cgi_4gla ] then echo "Making directory ./cgi_4gla" mkdir ./cgi_4gla fi echo "Extracting file cgi_4gla/4gl_wrapper.c" sed -e 's/^X//' <<\SHAR_EOF > cgi_4gla/4gl_wrapper.c X/* X * Copyright (c) 1995 Brigham Young University. All rights reserved. X * X * Permission is hereby granted, without written agreement and without X * license or royalty fees, to use, copy, modify, and distribute this X * software and its documentation for any purpose, provided that the X * above copyright notice and the following two paragraphs appear in X * all copies of this software. X * X * IN NO EVENT SHALL BRIGHAM YOUNG UNIVERSITY BE LIABLE TO ANY PARTY X * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES X * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN X * IF BRIGHAM YOUNG UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF X * SUCH DAMAGE. X * X * BRIGHAM YOUNG UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES, X * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY X * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER X * IS ON AN "AS IS" BASIS, AND BRIGHAM YOUNG UNIVERSITY HAS NO OBLIGATION X * TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. X */ X X/**************************************************************************** X * BRIAN K. HOLMAN * E-Mail: brian_holman@byu.edu * X * Programmer/Systems Analyst * URL: http://library.byu.edu/staff/bkh.html * X * Library Information Systems * Mail: 2330 HBLL, Provo, UT 84602 * X * Brigham Young University * Phone: (801) 378-8162 * X ****************************************************************************/ X X#include X#include "formsproc.h" X Xint load_form(int nargs) X{ X int num_ent; X X if (nargs != 0) X { X printf("Content-type: text/html%c%c",10,10); X printf("ERROR: wrong number of arguments in load_form\n"); X exit(1); X } X num_ent = load_form_entries(); X retint(num_ent); X return(1); X} X Xint free_form(int nargs) X{ X if (nargs != 0) X { X printf("Content-type: text/html%c%c",10,10); X printf("ERROR: wrong number of arguments in free_form\n"); X exit(1); X } X free_form_entries(); X return(0); X} X Xint get_entry(int nargs) X{ X char field_name[ENTRY_SIZE]; X char *field_value; X X if (nargs != 1) X { X printf("Content-type: text/html%c%c",10,10); X printf("ERROR: wrong number of arguments\n"); X exit(1); X } X X /* Pop field_name */ X popquote(field_name, ENTRY_SIZE); X trim(field_name); X X field_value = retrieve_form_entry(field_name); X X /* Push field value */ X retquote(field_value); X return(1); X} X Xint load_cmdln(int nargs) X{ X int num_ent; X X if (nargs != 0) X { X printf("Content-type: text/html%c%c",10,10); X printf("ERROR: wrong number of arguments\n"); X exit(1); X } X num_ent = load_cmdln_entries(); X retint(num_ent); X return(1); X} X Xint get_cmdln(int nargs) X{ X char field_name[ENTRY_SIZE]; X char *field_value; X X if (nargs != 1) X { X printf("Content-type: text/html%c%c",10,10); X printf("ERROR: wrong number of arguments\n"); X exit(1); X } X X /* Pop field_name */ X popquote(field_name, ENTRY_SIZE); X trim(field_name); X X field_value = retrieve_cmdln_entry(field_name); X X /* Push field value */ X retquote(field_value); X return(1); X} SHAR_EOF if [ `wc -c < cgi_4gla/4gl_wrapper.c` -ne 3076 ] then echo "Lengths do not match -- Bad Copy of cgi_4gla/4gl_wrapper.c" fi if [ ! -d ./cgi_4gla ] then echo "Making directory ./cgi_4gla" mkdir ./cgi_4gla fi echo "Extracting file cgi_4gla/CDI_ANNOUNCE" sed -e 's/^X//' <<\SHAR_EOF > cgi_4gla/CDI_ANNOUNCE XFrom: bkh@lib1.byu.edu (Brian K. Holman) XDate: 15 Feb 1995 22:17:29 GMT XSubject: [ANNOUNCE]Informix 4GL World-Wide-Web Interface XMessage-ID: <3htuhp$oc8@bones.et.byu.edu> X XI have created a small group of functions in the C language to simplify the Xretrieval of field values from HTML forms. I have also created Informix-4GL Xwrappers for each of those functions. So in essence, you can create CGI X(Common Gateway Interface) compliant executables to take advantage of the XMosaic user interface and the Informix-4GL development environment. This Xproject is very much in the early stages, any suggestions or improvements to Xthe software are welcome! X XMore information on my Informix 4GL World-Wide-Web Interface and my personal Xfeelings on using 4GL with the Web can be obtained at the following URL: X Xhttp://library.byu.edu/staff/bkh/cgi_4gldoc.html X X-- X+-----------------------------+--------------------------------------------+ X| BRIAN K. HOLMAN | E-Mail: brian_holman@byu.edu | X| Programmer/Systems Analyst | URL: http://library.byu.edu/staff/bkh/ | X| Library Information Systems | Mail: 2330 HBLL, Provo, UT 84602 | X| Brigham Young University | Phone: (801) 378-8162 | X+-----------------------------+--------------------------------------------+ SHAR_EOF if [ `wc -c < cgi_4gla/CDI_ANNOUNCE` -ne 1313 ] then echo "Lengths do not match -- Bad Copy of cgi_4gla/CDI_ANNOUNCE" fi if [ ! -d ./cgi_4gla ] then echo "Making directory ./cgi_4gla" mkdir ./cgi_4gla fi echo "Extracting file cgi_4gla/Makefile" sed -e 's/^X//' <<\SHAR_EOF > cgi_4gla/Makefile XINSTALL_DIR = /users/httpserv/cgi-bin XALL = circinfo XCFLAGS = -O2 X Xall: $(ALL) X X# circulation lookup program Xcircinfo: X c4gl circinfo.4gl 4gl_wrapper.c formsproc.c -o circinfo X X# install section Xinstall: X make all X installbsd -c -g web -m 750 -o httpserv circinfo $(INSTALL_DIR) X X# clean section Xclean: X rm -f $(ALL) X rm -f *.o X rm -f *~ X rm -f *.ec X rm -f *.frm SHAR_EOF if [ `wc -c < cgi_4gla/Makefile` -ne 364 ] then echo "Lengths do not match -- Bad Copy of cgi_4gla/Makefile" fi if [ ! -d ./cgi_4gla ] then echo "Making directory ./cgi_4gla" mkdir ./cgi_4gla fi echo "Extracting file cgi_4gla/README" sed -e 's/^X//' <<\SHAR_EOF > cgi_4gla/README XComments: X========= X Xcircinfo.4gl will not compile out of the box because it needs specific XInformix tables to be set up and calls a "has" function which is not Xpresent. But it should be a good model for how to design your own CGI/4GL Xapplications. Refer to the following web page for more information: X X http://library.byu.edu/staff/bkh/cgi_4gldoc.html X XFiles: X====== X4gl_wrapper.c C Wrapper Functions for 4GL XMakefile Sample Makefile Xcircinfo.4gl Sample 4GL program Xformsproc.c CGI C API Xformsproc.h CGI C API Header file SHAR_EOF if [ `wc -c < cgi_4gla/README` -ne 544 ] then echo "Lengths do not match -- Bad Copy of cgi_4gla/README" fi if [ ! -d ./cgi_4gla ] then echo "Making directory ./cgi_4gla" mkdir ./cgi_4gla fi echo "Extracting file cgi_4gla/WEB_PAGE.TXT" sed -e 's/^X//' <<\SHAR_EOF > cgi_4gla/WEB_PAGE.TXT X Informix 4GL World-Wide-Web Interface X X by Brian K. Holman, Library Information Systems, Brigham Young University X X------------------------------------------------------------------------------- X XDescription: X XI have created a small group of functions in the C language to simplify the Xretrieval of field values from HTML forms. I have also created Informix-4GL Xwrappers for each of those functions. So in essence, you can create CGI (Common XGateway Interface) compliant executables to take advantage of the Mosaic user Xinterface and the Informix-4GL development environment. This project is very Xmuch in the early stages, any suggestions or improvements to the software are Xwelcome! X XSystem Requirements: X X * NCSA httpd Version 1.3 X * Informix 4GL - Compiled Version X * forms-capable WWW Client (I prefer Netscape) X XUser Requirements: X X * A knowledge of HTML and HTML forms X * A knowledge of Informix 4GL X * Experience administering a Web Server X XDevelopment Strategy: X XOne common way of programming CGI applications is to create an HTML document Xthat includes HTML forms for data entry and then to create an executable that Xhandles the results and processes them in some meaningful way. This means you Xhave one shot at data entry and then the results are processed. X XThis is the easiest way to do it in the state-less environment of the XWorld-Wide-Web. However, most database applications lend themselves to a more Xstateful approach. For example, if someone types in an invalid PIN with their Xaccount number you would like to redisplay the form with the valid account Xnumber, tell them the PIN was invalid and allow them another chance at entering Xa PIN. This would be very difficult to do with the approach taken above, Xespecially as forms get more complex. X XI propose taking a pseudo-stateful approach to give the appearance of a Xstateful environment to the user while the underlying environment is really Xstateless. There are some different aspects of WWW technology that I employ to Xgive this effect: X X * Embed the HTML document containing the form within the CGI executable X * Use hidden fields in HTML forms to retain state information X XDocumentation on the most important CGI-4GL functions: X XCALL load_form() RETURNING load_result XThe load_form function is used to determine whether or not the current instance Xof the CGI executable is suppose to display a form or process the results of a Xsubmitted form. It should be the first function called in any CGI-4GL program. XIf the load_result is 0 (zero) then the program should output the HTML form, Xotherwise it should begin processing the submitted field-value pairs. X XCALL free_form() XThis function should be the last function called in any CGI-4GL program. It Xfrees up the dynamic structure that stores the field-value pairs. It is just Xfor goodhousekeeping since the memory gets deallocated when the program Xterminates. X XCALL get_entry(field_name) RETURNING field_value XThis function is used to retrieve the values submitted from an HTML POST Xoperation. Call get_entry passing in a string for the field_name as contained Xin the HTML form and the value of field_name is returned typecast according to XInformix-4GL rules. X XAn Example Application: X XThis application prompts for a student ID and PIN number. If the values entered Xproduce an error then an error message is displayed along with the original Xform. The portion of the data that was entered correctly displays on the new Xform as well. If the values are correct then the form is processed and the Xoutput displayed. One CGI-4GL executable performs all the above functions. X XWhen testing the application, try using the ID number 111 11 1430 and the PIN X1234. Try another PIN number or a random ID number, etc. X XPress here to try it out or press here to view the 4GL source. X XSource: X XClick here to download the source for the CGI API, the 4GL wrapper functions, Xand the sample program. X XDisclaimer: X XThis project is NOT affiliated in any way with Informix Software, Inc. Click Xhere for Informix copyright and trademark information. X XCopyright © 1995 Brigham Young University. All rights reserved. X XPermission is hereby granted, without written agreement and without license or Xroyalty fees, to use, copy, modify, and distribute this software and its Xdocumentation for any purpose, provided that the above copyright notice and the Xfollowing two paragraphs appear in all copies of this software. X XIN NO EVENT SHALL BRIGHAM YOUNG UNIVERSITY BE LIABLE TO ANY PARTY FOR DIRECT, XINDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE XOF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF BRIGHAM YOUNG UNIVERSITY HAS XBEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. X XBRIGHAM YOUNG UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT XNOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A XPARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND XBRIGHAM YOUNG UNIVERSITY HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, XUPDATES, ENHANCEMENTS, OR MODIFICATIONS. SHAR_EOF if [ `wc -c < cgi_4gla/WEB_PAGE.TXT` -ne 5084 ] then echo "Lengths do not match -- Bad Copy of cgi_4gla/WEB_PAGE.TXT" fi if [ ! -d ./cgi_4gla ] then echo "Making directory ./cgi_4gla" mkdir ./cgi_4gla fi echo "Extracting file cgi_4gla/circinfo.4gl" sed -e 's/^X//' <<\SHAR_EOF > cgi_4gla/circinfo.4gl XDATABASE library X XMAIN X DEFINE X formrc INT, X retc INT, X p_pin LIKE security.pin, X p_id_number LIKE patron.id_number, X err_msg CHAR(128), X err_cnt INT, X p_valid RECORD X id_number LIKE patron.id_number, X pin LIKE security.pin, X name LIKE patron.name, X id_status LIKE patron.id_status, X status LIKE status_code.description X END RECORD X X CALL load_form() RETURNING formrc X X IF formrc = 0 THEN X CALL output_form("", 0, "") X ELSE X CALL get_entry("ssn") RETURNING p_id_number X CALL get_entry("pin") RETURNING p_pin X CALL get_entry("retry") RETURNING err_cnt X X IF err_cnt = 3 THEN X CALL show_error("Too many incorrect tries!") X ELSE X SELECT patron.id_number, security.pin, patron.name, X patron.id_status, status_code.description X INTO p_valid.* X FROM patron, security, status_code, standing_code X WHERE patron.id_number = security.id_number AND X patron.id_status = status_code.id_status AND X patron.standing = standing_code.standing AND X patron.id_number = p_id_number X X IF status = 0 THEN X IF p_valid.id_status = "G" THEN X IF p_pin = p_valid.pin THEN X CALL has (p_valid.id_number, p_valid.name) RETURNING retc X IF retc = FALSE THEN X LET err_msg = "No circulation information was found for ", p_valid.name CLIPPED, "." X CALL show_error(err_msg) X END IF X ELSE X LET err_msg = "Invalid PIN ", p_pin, ", please try again." X LET err_cnt = err_cnt + 1 X CALL output_form(err_msg, err_cnt, p_id_number) X END IF X ELSE X LET err_msg = "ID NOT VALID because it is ", p_valid.status CLIPPED, "." X CALL show_error(err_msg) X END IF X ELSE X LET err_msg = "The BYU ID ", p_id_number, " was not found in our patron database." X LET err_cnt = err_cnt + 1 X CALL has (p_id_number, "SPECIAL ACCOUNT") RETURNING retc X IF retc = FALSE THEN X CALL output_form(err_msg, err_cnt, "") X END IF X END IF X END IF X END IF X CALL free_form() XEND MAIN X XFUNCTION output_form(special_msg, retry, ssn_str) X DEFINE X special_msg CHAR(128), X retry INT, X ssn_str CHAR(9) X X DISPLAY "Content-type: text/html" X DISPLAY "" X DISPLAY "Brigham Young University Libraries Patron Circulation Records" X DISPLAY "
" X DISPLAY "

Patron Circulation Records

" X DISPLAY "
" X DISPLAY "Enter your BYU ID number:

" X DISPLAY "Enter your personal identification number:

" X DISPLAY "" X DISPLAY "" X DISPLAY "" X DISPLAY "
" X DISPLAY "

" X DISPLAY "", special_msg CLIPPED, "" X DISPLAY "
" X DISPLAY "
" X DISPLAY "" X DISPLAY "
" XEND FUNCTION X XFUNCTION show_error(error_msg) X DEFINE X error_msg CHAR(128) X X DISPLAY "Content-type: text/html" X DISPLAY "" X DISPLAY "Brigham Young University Libraries Patron Circulation Records" X DISPLAY "
" X DISPLAY "", error_msg CLIPPED, "" X DISPLAY "
" XEND FUNCTION SHAR_EOF if [ `wc -c < cgi_4gla/circinfo.4gl` -ne 3557 ] then echo "Lengths do not match -- Bad Copy of cgi_4gla/circinfo.4gl" fi if [ ! -d ./cgi_4gla ] then echo "Making directory ./cgi_4gla" mkdir ./cgi_4gla fi echo "Extracting file cgi_4gla/formsproc.c" sed -e 's/^X//' <<\SHAR_EOF > cgi_4gla/formsproc.c X/* X * Copyright (c) 1995 Brigham Young University. All rights reserved. X * X * Permission is hereby granted, without written agreement and without X * license or royalty fees, to use, copy, modify, and distribute this X * software and its documentation for any purpose, provided that the X * above copyright notice and the following two paragraphs appear in X * all copies of this software. X * X * IN NO EVENT SHALL BRIGHAM YOUNG UNIVERSITY BE LIABLE TO ANY PARTY X * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES X * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN X * IF BRIGHAM YOUNG UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF X * SUCH DAMAGE. X * X * BRIGHAM YOUNG UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES, X * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY X * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER X * IS ON AN "AS IS" BASIS, AND BRIGHAM YOUNG UNIVERSITY HAS NO OBLIGATION X * TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. X */ X X/**************************************************************************** X * BRIAN K. HOLMAN * E-Mail: brian_holman@byu.edu * X * Programmer/Systems Analyst * URL: http://library.byu.edu/staff/bkh.html * X * Library Information Systems * Mail: 2330 HBLL, Provo, UT 84602 * X * Brigham Young University * Phone: (801) 378-8162 * X ****************************************************************************/ X X#include X#include X#include "formsproc.h" X X/* Variable Definitions */ X Xform_entry form_entries[MAX_ENTRIES]; Xcmdln_entry cmdln_entries[MAX_ENTRIES]; Xint num_form_entries; Xint num_cmdln_entries; X X/* CGI Functions */ Xvoid getword(char *word, char *line, char stop) X{ X int x = 0,y; X X for(x=0;((line[x]) && (line[x] != stop));x++) X word[x] = line[x]; X X word[x] = '\0'; X if(line[x]) ++x; X y=0; X X while(line[y++] = line[x++]); X} X Xchar *makeword(char *line, char stop) X{ X int x = 0,y; X char *word = (char *) malloc(sizeof(char) * (strlen(line) + 1)); X X for(x=0;((line[x]) && (line[x] != stop));x++) X word[x] = line[x]; X X word[x] = '\0'; X if(line[x]) ++x; X y=0; X X while(line[y++] = line[x++]); X return word; X} X Xchar *fmakeword(FILE *f, char stop, int *cl) X{ X int wsize; X char *word; X int ll; X X wsize = 102400; X ll=0; X word = (char *) malloc(sizeof(char) * (wsize + 1)); X X while(1) X { X word[ll] = (char)fgetc(f); X if(ll==wsize) X { X word[ll+1] = '\0'; X wsize+=102400; X word = (char *)realloc(word,sizeof(char)*(wsize+1)); X } X --(*cl); X if((word[ll] == stop) || (feof(f)) || (!(*cl))) X { X if(word[ll] != stop) ll++; X word[ll] = '\0'; X return word; X } X ++ll; X } X} X Xchar x2c(char *what) X{ X register char digit; X X digit = (what[0] >= 'A' ? ((what[0] & 0xdf) - 'A')+10 : (what[0] - '0')); X digit *= 16; X digit += (what[1] >= 'A' ? ((what[1] & 0xdf) - 'A')+10 : (what[1] - '0')); X return(digit); X} X Xvoid unescape_url(char *url) X{ X register int x,y; X X for(x=0,y=0;url[y];++x,++y) X { X if((url[x] = url[y]) == '%') X { X url[x] = x2c(&url[y+1]); X y+=2; X } X } X url[x] = '\0'; X} X Xvoid plustospace(char *str) X{ X register int x; X X for(x=0;str[x];x++) if(str[x] == '+') str[x] = ' '; X} X Xint rind(char *s, char c) X{ X register int x; X for(x=strlen(s) - 1;x != -1; x--) X if(s[x] == c) return x; X return -1; X} X Xint getline(char *s, int n, FILE *f) X{ X register int i=0; X X while(1) X { X s[i] = (char)fgetc(f); X X if(s[i] == CR) X s[i] = fgetc(f); X X if((s[i] == 0x4) || (s[i] == LF) || (i == (n-1))) X { X s[i] = '\0'; X return (feof(f) ? 1 : 0); X } X ++i; X } X} X Xvoid send_fd(FILE *f, FILE *fd) X{ X int num_chars=0; X char c; X X while (1) X { X c = fgetc(f); X if(feof(f)) X return; X fputc(c,fd); X } X} X Xint ind(char *s, char c) X{ X register int x; X X for(x=0;s[x];x++) X if(s[x] == c) return x; X X return -1; X} X Xvoid escape_shell_cmd(char *cmd) X{ X register int x,y,l; X X l=strlen(cmd); X for(x=0;cmd[x];x++) X { X if(ind("&;`'\"|*?~<>^()[]{}$\\",cmd[x]) != -1) X { X for(y=l+1;y>x;y--) X cmd[y] = cmd[y-1]; X l++; /* length has been increased */ X cmd[x] = '\\'; X x++; /* skip the character */ X } X } X} X Xint load_form_entries() X{ X register int index; X int content_length; X X num_form_entries=0; X if(strcmp(getenv("REQUEST_METHOD"),"POST")) X { X /* Can't proceed if not a post */ X return 0; X } X if(strcmp(getenv("CONTENT_TYPE"),"application/x-www-form-urlencoded")) X { X printf("Content-type: text/html%c%c",10,10); X printf("This function can only be used to decode form results.\n"); X exit(1); X } X content_length = atoi(getenv("CONTENT_LENGTH")); X X for(index=0;content_length && (!feof(stdin));index++) X { X num_form_entries=index; X form_entries[index].val = fmakeword(stdin,'&',&content_length); X plustospace(form_entries[index].val); X unescape_url(form_entries[index].val); X form_entries[index].name = makeword(form_entries[index].val,'='); X } X return num_form_entries; X} X Xvoid free_form_entries() X{ X register int index; X X for(index=0;index <= num_form_entries; index++) X { X free(form_entries[index].name); X free(form_entries[index].val); X } X} X Xchar *retrieve_form_entry(char *field_name) X{ X register int index; X X for(index=0; (index <= num_form_entries) && (strcmp(form_entries[index].name,field_name)); index++); X if (index > num_form_entries) X return NULL; X return form_entries[index].val; X} X Xint load_cmdln_entries() X{ X register int index; X char *cl; X X num_cmdln_entries=0; X cl = getenv("QUERY_STRING"); X if (cl == NULL) X { X /* No query information to decode */ X return 0; X } X for (index=0; cl[0] != '\0'; index++) X { X num_cmdln_entries=index; X getword(cmdln_entries[index].val,cl,'&'); X plustospace(cmdln_entries[index].val); X unescape_url(cmdln_entries[index].val); X getword(cmdln_entries[index].name,cmdln_entries[index].val,'='); X } X return num_cmdln_entries; X} X Xchar *retrieve_cmdln_entry(char *field_name) X{ X register int index; X X for(index=0; (index <= num_cmdln_entries) && (strcmp(cmdln_entries[index].name,field_name)); index++); X if (index > num_cmdln_entries) X return NULL; X return cmdln_entries[index].val; X} X Xchar *trim(char *trim_str) X{ X int index; X X for (index = strlen(trim_str)-1; index >= 0; index--) X if (trim_str[index] != ' ' && trim_str[index] != '\t' && trim_str[index] != '\n') X break; X trim_str[index+1] = '\0'; X return trim_str; X} SHAR_EOF if [ `wc -c < cgi_4gla/formsproc.c` -ne 6389 ] then echo "Lengths do not match -- Bad Copy of cgi_4gla/formsproc.c" fi if [ ! -d ./cgi_4gla ] then echo "Making directory ./cgi_4gla" mkdir ./cgi_4gla fi echo "Extracting file cgi_4gla/formsproc.h" sed -e 's/^X//' <<\SHAR_EOF > cgi_4gla/formsproc.h X/* X * Copyright (c) 1995 Brigham Young University. All rights reserved. X * X * Permission is hereby granted, without written agreement and without X * license or royalty fees, to use, copy, modify, and distribute this X * software and its documentation for any purpose, provided that the X * above copyright notice and the following two paragraphs appear in X * all copies of this software. X * X * IN NO EVENT SHALL BRIGHAM YOUNG UNIVERSITY BE LIABLE TO ANY PARTY X * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES X * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN X * IF BRIGHAM YOUNG UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF X * SUCH DAMAGE. X * X * BRIGHAM YOUNG UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES, X * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY X * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER X * IS ON AN "AS IS" BASIS, AND BRIGHAM YOUNG UNIVERSITY HAS NO OBLIGATION X * TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. X */ X X/**************************************************************************** X * BRIAN K. HOLMAN * E-Mail: brian_holman@byu.edu * X * Programmer/Systems Analyst * URL: http://library.byu.edu/staff/bkh.html * X * Library Information Systems * Mail: 2330 HBLL, Provo, UT 84602 * X * Brigham Young University * Phone: (801) 378-8162 * X ****************************************************************************/ X X/* Constants */ X#define ENTRY_SIZE 128 X#define LF 10 X#define CR 13 X#define MAX_ENTRIES 1000 X X/* Type Definitions */ Xtypedef struct X{ X char *name; X char *val; X} form_entry; X Xtypedef struct X{ X char name[ENTRY_SIZE]; X char val[ENTRY_SIZE]; X} cmdln_entry; X X/* Function Prototypes */ Xint load_form_entries(); Xvoid free_form_entries(); Xchar *retrieve_form_entry(char *field_name); Xint load_cmdln_entries(); Xchar *retrieve_cmdln_entry(char *field_name); Xchar *trim(char *trim_str); SHAR_EOF if [ `wc -c < cgi_4gla/formsproc.h` -ne 2013 ] then echo "Lengths do not match -- Bad Copy of cgi_4gla/formsproc.h" fi if [ ! -d ./cgi_4glb ] then echo "Making directory ./cgi_4glb" mkdir ./cgi_4glb fi echo "Extracting file cgi_4glb/README" sed -e 's/^X//' <<\SHAR_EOF > cgi_4glb/README XThis directory contains a version of formsproc.c proposed by John Cokos. XThe comments that accompanied his submission to the Repository follow Xbelow: X X XFrom: jcokos@ccs.net (John Cokos) XDate: Mon, 26 Jan 1998 17:40:15 -0500 X XI have lots of "web stuff" running that use these functions. I can't tell Xyou how happy I was to find the original version of this. Now that I X"fixed" it, it has become indespensible, and enabled me to do lots of web Xprogrammin that previously was very kludgey (We use informix 2.x and 4.1 X... Informix's webdriver cgi is not available for us, and none of the Perl XInterfaces work either). This code was a godsend. X XJohn SHAR_EOF if [ `wc -c < cgi_4glb/README` -ne 650 ] then echo "Lengths do not match -- Bad Copy of cgi_4glb/README" fi if [ ! -d ./cgi_4glb ] then echo "Making directory ./cgi_4glb" mkdir ./cgi_4glb fi echo "Extracting file cgi_4glb/formsproc.c" sed -e 's/^X//' <<\SHAR_EOF > cgi_4glb/formsproc.c X/* X * Copyright (c) 1995 Brigham Young University. All rights reserved. X * X * Permission is hereby granted, without written agreement and without X * license or royalty fees, to use, copy, modify, and distribute this X * software and its documentation for any purpose, provided that the X * above copyright notice and the following two paragraphs appear in X * all copies of this software. X * X * IN NO EVENT SHALL BRIGHAM YOUNG UNIVERSITY BE LIABLE TO ANY PARTY X * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES X * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN X * IF BRIGHAM YOUNG UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF X * SUCH DAMAGE. X * X * BRIGHAM YOUNG UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES, X * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY X * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER X * IS ON AN "AS IS" BASIS, AND BRIGHAM YOUNG UNIVERSITY HAS NO OBLIGATION X * TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. X */ X X/**************************************************************************** X * BRIAN K. HOLMAN * E-Mail: brian_holman@byu.edu * X * Programmer/Systems Analyst * URL: http://library.byu.edu/staff/bkh.html * X * Library Information Systems * Mail: 2330 HBLL, Provo, UT 84602 * X * Brigham Young University * Phone: (801) 378-8162 * X ****************************************************************************/ X X#include X#include X#include "formsproc.h" X X/* Variable Definitions */ X Xform_entry form_entries[MAX_ENTRIES]; Xcmdln_entry cmdln_entries[MAX_ENTRIES]; Xint num_form_entries; Xint num_cmdln_entries; X X/* CGI Functions */ Xvoid getword(char *word, char *line, char stop) X{ X int x = 0,y; X X for(x=0;((line[x]) && (line[x] != stop));x++) X word[x] = line[x]; X X word[x] = '\0'; X if(line[x]) ++x; X y=0; X X while(line[y++] = line[x++]); X} X Xchar *makeword(char *line, char stop) X{ X int x = 0,y; X char *word = (char *) malloc(sizeof(char) * (strlen(line) + 1)); X X for(x=0;((line[x]) && (line[x] != stop));x++) X word[x] = line[x]; X X word[x] = '\0'; X if(line[x]) ++x; X y=0; X X while(line[y++] = line[x++]); X return word; X} X Xchar *fmakeword(FILE *f, char stop, int *cl) X{ X int wsize; X char *word; X int ll; X X wsize = 102400; X ll=0; X word = (char *) malloc(sizeof(char) * (wsize + 1)); X X while(1) X { X word[ll] = (char)fgetc(f); X if(ll==wsize) X { X word[ll+1] = '\0'; X wsize+=102400; X word = (char *)realloc(word,sizeof(char)*(wsize+1)); X } X X if((word[ll] == stop) || (feof(f)) || (!(*cl))) X { X if(word[ll] != stop) ll++; X word[ll] = '\0'; X return word; X } X ++ll; X } X} X Xchar x2c(char *what) X{ X register char digit; X X digit = (what[0] >= 'A' ? ((what[0] & 0xdf) - 'A')+10 : (what[0] - '0')); X digit *= 16; X digit += (what[1] >= 'A' ? ((what[1] & 0xdf) - 'A')+10 : (what[1] - '0')); X return(digit); X} X Xvoid unescape_url(char *url) X{ X register int x,y; X X for(x=0,y=0;url[y];++x,++y) X { X if((url[x] = url[y]) == '%') X { X url[x] = x2c(&url[y+1]); X y+=2; X } X } X url[x] = '\0'; X} X Xvoid plustospace(char *str) X{ X register int x; X X for(x=0;str[x];x++) if(str[x] == '+') str[x] = ' '; X} X Xint rind(char *s, char c) X{ X register int x; X for(x=strlen(s) - 1;x != -1; x--) X if(s[x] == c) return x; X return -1; X} X Xint getline(char *s, int n, FILE *f) X{ X register int i=0; X X while(1) X { X s[i] = (char)fgetc(f); X X if(s[i] == CR) X s[i] = fgetc(f); X X if((s[i] == 0x4) || (s[i] == LF) || (i == (n-1))) X { X s[i] = '\0'; X return (feof(f) ? 1 : 0); X } X ++i; X } X} X Xvoid send_fd(FILE *f, FILE *fd) X{ X int num_chars=0; X char c; X X while (1) X { X c = fgetc(f); X if(feof(f)) X return; X fputc(c,fd); X } X} X Xint ind(char *s, char c) X{ X register int x; X X for(x=0;s[x];x++) X if(s[x] == c) return x; X X return -1; X} X Xvoid escape_shell_cmd(char *cmd) X{ X register int x,y,l; X X l=strlen(cmd); X for(x=0;cmd[x];x++) X { X if(ind("&;`'\"|*?~<>^()[]{}$\\",cmd[x]) != -1) X { X for(y=l+1;y>x;y--) X cmd[y] = cmd[y-1]; X l++; /* length has been increased */ X cmd[x] = '\\'; X x++; /* skip the character */ X } X } X} X Xint load_form_entries() X{ X register int index; X int content_length; X X num_form_entries=0; X if(strcmp(getenv("REQUEST_METHOD"),"POST")) X { X /* Can't proceed if not a post */ X /* Removed 11/2/97 jcc return 0; */ X get_get_entries(); X return num_form_entries; X } X if(strcmp(getenv("CONTENT_TYPE"),"application/x-www-form-urlencoded")) X { X printf("Content-type: text/html%c%c",10,10); X printf("This function can only be used to decode form results.\n"); X exit(1); X } X content_length = atoi(getenv("CONTENT_LENGTH")); X X for(index=0;content_length && (!feof(stdin));index++) X { X num_form_entries=index; X form_entries[index].val = fmakeword(stdin,'&',&content_length); X plustospace(form_entries[index].val); X unescape_url(form_entries[index].val); X form_entries[index].name = makeword(form_entries[index].val,'='); X } X return num_form_entries; X} X X/* 11/2/97 John Cokos inserted to handle GET forms */ Xint get_get_entries() X{ X int j,m=0; X char *qs; X X if(strcmp(getenv("REQUEST_METHOD"),"GET")) { X /* Tried POST earlier, now GET is bad, get outta here */ X return 0; X } X X X qs = getenv("QUERY_STRING"); X if(qs == NULL) { X return 0; X } X X for(j=0;qs[j] != '\0'&&j