// $Id: cgi-util.cxx,v 1.9 1998/05/12 16:48:05 cnidr Exp $ /*********************************************************************** Copyright Notice Copyright (c) MCNC, Clearinghouse for Networked Information Discovery and Retrieval, 1996. Permission to use, copy, modify, distribute, and sell this software and its documentation, in whole or in part, for any purpose is hereby granted without fee, provided that 1. The above copyright notice and this permission notice appear in all copies of the software and related documentation. Notices of copyright and/or attribution which appear at the beginning of any file included in this distribution must remain intact. 2. Users of this software agree to make their best efforts (a) to return to MCNC any improvements or extensions that they make, so that these may be included in future releases; and (b) to inform MCNC/CNIDR of noteworthy uses of this software. 3. The names of MCNC and Clearinghouse for Networked Information Discovery and Retrieval may not be used in any advertising or publicity relating to the software without the specific, prior written permission of MCNC/CNIDR. THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MCNC/CNIDR BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ************************************************************************/ /*@@@ File: cgi-util.cxx Version: 1.04 $Revision: 1.9 $ Description: CGI utilities Authors: Kevin Gamiel, kgamiel@cnidr.org Tim Gemma, stone@k12.cnidr.org @@@*/ // change record: // reset z and initialized entry_point to fix "GET" method 9/25/96 dtw #include #include #include "cgi-util.hxx" /* # Class: CGIAPP # Method: GetInput # Comments: Reads Forms data from standard input, parses out arguments. */ void CGIAPP::GetInput() { INT ContentLen=0, x, y, z, len, nn; CHR temp1[256], temp2[256], temp3[256]; CHR *meth, *p, *query=(CHR*)NULL; if ((meth = (char *)getenv("REQUEST_METHOD"))==NULL) { cout << "Unable to get request_method" << endl; exit(1); } if (!strcmp(meth,"POST")) { if ((p=(char *)getenv("CONTENT_LENGTH"))) ContentLen = atoi(p); Method=POST; } else { if (!strcmp(meth,"GET")) { query = (char *)getenv("QUERY_STRING"); Method=GET; } else { cout << "This program is to be referenced with a METHOD of POST or GET.\n"; cout << "If you don't understand this, see this "; cout << "forms overview" << endl; exit (1); } } // Build the list of cgi entries if (Method==POST) { entry_count=0; for (x = 0; ContentLen>0; x++) { cin.getline(temp1,ContentLen+1,'&'); entry_count++; len=strlen(temp1); ContentLen=ContentLen-(len+1); for (y=0;temp1[y]!='=' && y\n"; } } PCHR CGIAPP::GetName(INT4 i) { return name[i]; } PCHR CGIAPP::GetValue(INT4 i) { return value[i]; } PCHR CGIAPP::GetValueByName(const CHR *field) { if ((field==NULL) || (field[0]=='\0')) return NULL; INT i; for (i=0;i= 'A' ? ((what[0] & 0xdf) - 'A')+10 : (what[0] - '0')); digit *= 16; digit += (what[1] >= 'A' ? ((what[1] & 0xdf) - 'A')+10 : (what[1] - '0')); return(digit); } void unescape_url(PCHR url) { INT x,y; for(x=0,y=0;url[y];++x,++y) { if((url[x] = url[y]) == '%') { url[x] = x2c(&url[y+1]); y+=2; } } url[x] = '\0'; } void plustospace(PCHR str) { INT x; for(x=0;str[x];x++) if(str[x] == '+') str[x] = ' '; } void spacetoplus(PCHR str) { INT x; for(x=0;str[x];x++) if(str[x] == ' ') str[x] = '+'; } PCHR c2x(CHR what) { PCHR out=new CHR[4]; sprintf(out, "%%%2x", what); return out; } void escape_url(PCHR url, PCHR out) { out[0] = '\0'; INT x, y; for(x=0,y=0;url[x];++x,++y) { if (isalnum(url[x]) || (url[x] == ' ')) { out[y] = url[x]; } else { PCHR esc = c2x(url[x]); INT plus = strlen(esc); out[y] = '\0'; strcat(out, esc); y += (plus - 1); delete esc; } } out[y] = '\0'; spacetoplus(out); }