Well,

        New routine works:  But I am loosing the Left [ and Right ] when I
pass them through to the server app.. Checked the ccsid and it is set to 37.
for the HTTP Job... Translate is done with ...

        QDCXLATE(fdlen, ptr, "QASCII    ", "QSYS      ");

            The table QASCII is 0x4a to 0x58 and 0x5a to 0x5D Which is right
...

Web Page:        Test Page (Left & Right) using [Square] and & ..
Printf(%s):         CGI Parms List: 5-Test Page (Left & Right) using
[Square] and & ...
ASCII:              Test Page (Left & Right) using âSquareã and & ..

            This is through an open socket to an ascii server
application....

TIA,
    JMS...
=============================

/** Convert a two-char hex string into the char it represents **/
char x2c(char *What) {
 int Hi;        /* holds high byte   */
 int Lo;        /* holds low byte    */
 int Result;    /* holds result      */


   Hi = What[0];
    if ('0' <= Hi && Hi <= '9') {
      Hi -= '0';
    } else
    if ('a' <= Hi && Hi <= 'f') {
      Hi -= ('a'-10);
    } else
    if ('A' <= Hi && Hi <= 'F') {
      Hi -= ('A'-10);
    }

   Lo = What[1];
    if ('0' <= Lo && Lo <= '9') {
      Lo -= '0';
    } else
    if ('a' <= Lo && Lo <= 'f') {
      Lo -= ('a'-10);
    } else
    if ('A' <= Lo && Lo <= 'F') {
      Lo -= ('A'-10);
    }

   Result = Lo + (16 * Hi);

 return(Result);
}
----- Original Message -----
From: "Jeff Silberberg" <jsilberberg@mindspring.com>
To: <web400@midrange.com>
Sent: Friday, November 29, 2002 12:10 PM
Subject: [WEB400] Stuck in unesacpe -----


Afternoon all,

        I am sitting here attempting to get an ILE-C routine to work and
having some issues with the unescape code !

        Test Message from the HTML (code) to see what unescape [will] do
with the characters..

        Results in this ---

        Test Message from the HTML  codeá to see what unescape qwillr do
with the characters..

        Note that ( ) [ ] are lost / mistranslated....in the routine x2c().
        Using  a standard cgilib.c (below) from the web, and I have
attempted translating back to ascii in the routine with the same results...

        Any direction ????  Rewrite ??

/* cgilib-c  **/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define max_input 100
#define max_login 9


/** Convert a two-char hex string into the char it represents **/
char x2c(char *what) {
register char digit;
digit = (what[0] >= '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);
}

/** Reduce any %xx escape sequences to the characters they represent **/
void unescape_url(char *url) {
register int i,j;
for(i=0,j=0; url[j]; ++i,++j) {
if((url[i] = url[j]) == '%') {
url[i] = x2c(&url[j+1]) ;
j+= 2 ;
}
}
url[i] = '\0' ;
}

/** Read the CGI input and place all name/val pairs into list. **/
/** Returns list containing name1, value1, name2, value2, ... , NULL **/
char **getcgivars() {
register int i ;
char *request_method ;
int content_length;
char *cgiinput ;
char **cgivars ;
char **pairlist ;
int paircount ;
char *nvpair ;
char *eqpos ;

/** Depending on the request method, read all CGI input into cgiinput **/
/** (really should produce HTML error messages, instead of exit()ing) **/
request_method= getenv("REQUEST_METHOD") ;
if (!strcmp(request_method, "GET") || !strcmp(request_method, "HEAD") ) {
cgiinput= strdup(getenv("QUERY_STRING")) ;
}
else if (!strcmp(request_method, "POST")) {
/* strcasecmp() is not supported in Windows-- use strcmpi() instead */
if ( strcasecmp(getenv("CONTENT_TYPE"),
"application/x-www-form-urlencoded")) {
printf("getcgivars(): Unsupported Content-Type.\n") ;
exit(1) ;
}
if ( !(content_length = atoi(getenv("CONTENT_LENGTH"))) ) {
printf("getcgivars(): No Content-Length was sent with the POST request.\n")
;
exit(1) ;
}
if ( !(cgiinput= (char *) malloc(content_length+1)) ) {
printf("getcgivars(): Could not malloc for cgiinput.\n") ;
exit(1) ;
}
if (!fread(cgiinput, content_length, 1, stdin)) {
printf("Couldn't read CGI input from STDIN.\n") ;
exit(1) ;
}
cgiinput[content_length]='\0' ;
}
else {
printf("getcgivars(): unsupported REQUEST_METHOD\n") ;
exit(1) ;
}
/** Change all plusses back to spaces **/
for(i=0; cgiinput[i]; i++) if(cgiinput[i] == '+') cgiinput[i] = ' ' ;
/** First, split on "&" to extract the name-value pairs into pairlist **/
pairlist= (char **) malloc(256*sizeof(char **)) ;
paircount= 0 ;
nvpair= strtok(cgiinput, "&") ;
while (nvpair) {
pairlist[paircount++]= strdup(nvpair) ;
if (!(paircount%256))
pairlist= (char **) realloc(pairlist,(paircount+256)*sizeof(char **)) ;
nvpair= strtok(NULL, "&") ;
}
pairlist[paircount]= 0 ; /* terminate the list with NULL */
/** Then, from the list of pairs, extract the names and values **/
cgivars= (char **) malloc((paircount*2+1)*sizeof(char **)) ;
for (i= 0; i<paircount; i++) {
if (eqpos=strchr(pairlist[i], '=')) {
*eqpos= '\0' ;
unescape_url(cgivars[i*2+1]= strdup(eqpos+1)) ;
} else {
unescape_url(cgivars[i*2+1]= strdup("")) ;
}
unescape_url(cgivars[i*2]= strdup(pairlist[i])) ;
}
cgivars[paircount*2]= 0 ; /* terminate the list with NULL */
/** Free anything that needs to be freed **/
free(cgiinput) ;
for (i=0; pairlist[i]; i++) free(pairlist[i]) ;
free(pairlist) ;
/** Return the list of name-value strings **/
return cgivars ;
}
void print_head()
{
printf("Content-type: text/html\n\n") ;
//printf("<html>\n") ;
//printf("<head><title>CGI Results</title></head>\n") ;
//printf("<body>\n") ;
}
void print_tail()
{
printf("</body>\n") ;
printf("</html>\n") ;
}
struct user {
char loginname[9];
char uid[9];
char gid[9];
char comment[31];
char homedir[31];
char shell[31];
};


_______________________________________________
This is the Web Enabling the AS400 / iSeries (WEB400) mailing list
To post a message email: WEB400@midrange.com
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/cgi-bin/listinfo/web400
or email: WEB400-request@midrange.com
Before posting, please take a moment to review the archives
at http://archive.midrange.com/web400.




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.