Annotation of libwww/Library/src/HTParse.c, revision 2.56

2.41      frystyk     1: /*                                                                   HTParse.c
                      2: **     URI MANAGEMENT
                      3: **
2.46      frystyk     4: **     (c) COPYRIGHT MIT 1995.
2.41      frystyk     5: **     Please first read the full copyright statement in the file COPYRIGH.
2.26      frystyk     6: **
                      7: ** history:
                      8: **     May 12 94       TAB added as legal char in HTCleanTelnetString
                      9: **
1.1       timbl      10: */
2.31      frystyk    11: 
2.44      frystyk    12: /* Library include files */
                     13: #include "tcp.h"
1.1       timbl      14: #include "HTUtils.h"
2.38      frystyk    15: #include "HTParse.h"
2.44      frystyk    16: #include "HTString.h"
2.31      frystyk    17: #include "HTTCP.h"
2.6       timbl      18: 
1.1       timbl      19: struct struct_parts {
2.20      timbl      20:        char * access;          /* Now known as "scheme" */
1.1       timbl      21:        char * host;
                     22:        char * absolute;
                     23:        char * relative;
                     24: /*     char * search;          no - treated as part of path */
                     25:        char * anchor;
                     26: };
                     27: 
                     28: /*     Scan a filename for its consituents
                     29: **     -----------------------------------
                     30: **
                     31: ** On entry,
                     32: **     name    points to a document name which may be incomplete.
                     33: ** On exit,
                     34: **      absolute or relative may be nonzero (but not both).
                     35: **     host, anchor and access may be nonzero if they were specified.
                     36: **     Any which are nonzero point to zero terminated strings.
                     37: */
2.32      frystyk    38: PRIVATE void scan ARGS2(char *, name, struct struct_parts *, parts)
1.1       timbl      39: {
                     40:     char * after_access;
                     41:     char * p;
                     42:     int length = strlen(name);
                     43:     
                     44:     parts->access = 0;
                     45:     parts->host = 0;
                     46:     parts->absolute = 0;
                     47:     parts->relative = 0;
                     48:     parts->anchor = 0;
                     49:     
                     50:     after_access = name;
                     51:     for(p=name; *p; p++) {
                     52:        if (*p==':') {
                     53:                *p = 0;
2.20      timbl      54:                parts->access = after_access; /* Scheme has been specified */
2.37      howcome    55: 
2.44      frystyk    56: /* The combination of gcc, the "-O" flag and the HP platform is
                     57:    unhealthy. The following three lines is a quick & dirty fix, but is
                     58:    not recommended. Rather, turn off "-O". */
                     59: 
2.42      howcome    60: /*             after_access = p;*/
2.44      frystyk    61: /*             while (*after_access == 0)*/
                     62: /*                 after_access++;*/
2.42      howcome    63: 
1.1       timbl      64:                after_access = p+1;
2.37      howcome    65: 
2.22      luotonen   66:                if (0==strcasecomp("URL", parts->access)) {
2.20      timbl      67:                    parts->access = NULL;  /* Ignore IETF's URL: pre-prefix */
                     68:                } else break;
1.1       timbl      69:        }
2.20      timbl      70:        if (*p=='/') break;             /* Access has not been specified */
1.1       timbl      71:        if (*p=='#') break;
                     72:     }
                     73:     
                     74:     for(p=name+length-1; p>=name; p--) {
                     75:        if (*p =='#') {
                     76:            parts->anchor=p+1;
                     77:            *p=0;                               /* terminate the rest */
                     78:        }
                     79:     }
                     80:     p = after_access;
                     81:     if (*p=='/'){
                     82:        if (p[1]=='/') {
                     83:            parts->host = p+2;          /* host has been specified      */
                     84:            *p=0;                       /* Terminate access             */
                     85:            p=strchr(parts->host,'/');  /* look for end of host name if any */
                     86:            if(p) {
                     87:                *p=0;                   /* Terminate host */
                     88:                parts->absolute = p+1;          /* Root has been found */
                     89:            }
                     90:        } else {
                     91:            parts->absolute = p+1;              /* Root found but no host */
                     92:        }           
                     93:     } else {
2.49      frystyk    94:         parts->relative = (*after_access) ? after_access : 0; /* zero for "" */
1.1       timbl      95:     }
2.50      frystyk    96: }
1.1       timbl      97: 
                     98: 
                     99: /*     Parse a Name relative to another name
                    100: **     -------------------------------------
                    101: **
                    102: **     This returns those parts of a name which are given (and requested)
                    103: **     substituting bits from the related name where necessary.
                    104: **
                    105: ** On entry,
                    106: **     aName           A filename given
2.33      howcome   107: **      relatedName     A name relative to which aName is to be parsed. Give
                    108: **                      it an empty string if aName is absolute.
1.1       timbl     109: **      wanted          A mask for the bits which are wanted.
                    110: **
                    111: ** On exit,
                    112: **     returns         A pointer to a malloc'd string which MUST BE FREED
                    113: */
2.32      frystyk   114: char * HTParse ARGS3(CONST char *, aName, CONST char *, relatedName,
                    115:                     int, wanted)
1.1       timbl     116: {
                    117:     char * result = 0;
                    118:     char * return_value = 0;
                    119:     int len;
                    120:     char * name = 0;
                    121:     char * rel = 0;
                    122:     char * p;
2.12      timbl     123:     char * access;
1.1       timbl     124:     struct struct_parts given, related;
2.33      howcome   125:     
                    126:     if (!relatedName)        /* HWL 23/8/94: dont dump due to NULL */
                    127:         relatedName = "";
1.1       timbl     128:     
2.50      frystyk   129:     /* Make working copies of input strings to cut up: */
1.1       timbl     130:     len = strlen(aName)+strlen(relatedName)+10;
                    131:     result=(char *)malloc(len);                /* Lots of space: more than enough */
                    132:     if (result == NULL) outofmem(__FILE__, "HTParse");
                    133:     
                    134:     StrAllocCopy(name, aName);
                    135:     StrAllocCopy(rel, relatedName);
                    136:     
                    137:     scan(name, &given);
                    138:     scan(rel,  &related); 
                    139:     result[0]=0;               /* Clear string  */
2.12      timbl     140:     access = given.access ? given.access : related.access;
1.1       timbl     141:     if (wanted & PARSE_ACCESS)
2.12      timbl     142:         if (access) {
                    143:            strcat(result, access);
1.1       timbl     144:            if(wanted & PARSE_PUNCTUATION) strcat(result, ":");
                    145:        }
                    146:        
                    147:     if (given.access && related.access)        /* If different, inherit nothing. */
                    148:         if (strcmp(given.access, related.access)!=0) {
                    149:            related.host=0;
                    150:            related.absolute=0;
                    151:            related.relative=0;
                    152:            related.anchor=0;
                    153:        }
                    154:        
                    155:     if (wanted & PARSE_HOST)
                    156:         if(given.host || related.host) {
                    157:            if(wanted & PARSE_PUNCTUATION) strcat(result, "//");
                    158:            strcat(result, given.host ? given.host : related.host);
                    159:        }
                    160:        
                    161:     if (given.host && related.host)  /* If different hosts, inherit no path. */
                    162:         if (strcmp(given.host, related.host)!=0) {
                    163:            related.absolute=0;
                    164:            related.relative=0;
                    165:            related.anchor=0;
                    166:        }
                    167:        
                    168:     if (wanted & PARSE_PATH) {
                    169:         if(given.absolute) {                           /* All is given */
                    170:            if(wanted & PARSE_PUNCTUATION) strcat(result, "/");
                    171:            strcat(result, given.absolute);
                    172:        } else if(related.absolute) {   /* Adopt path not name */
                    173:            strcat(result, "/");
                    174:            strcat(result, related.absolute);
                    175:            if (given.relative) {
                    176:                p = strchr(result, '?');        /* Search part? */
                    177:                if (!p) p=result+strlen(result)-1;
                    178:                for (; *p!='/'; p--);   /* last / */
                    179:                p[1]=0;                                 /* Remove filename */
                    180:                strcat(result, given.relative);         /* Add given one */
2.55      frystyk   181: #if 0
2.45      frystyk   182:                result = HTSimplify (&result);
2.55      frystyk   183: #endif
1.1       timbl     184:            }
                    185:        } else if(given.relative) {
                    186:            strcat(result, given.relative);             /* what we've got */
                    187:        } else if(related.relative) {
                    188:            strcat(result, related.relative);
                    189:        } else {  /* No inheritance */
                    190:            strcat(result, "/");
                    191:        }
                    192:     }
                    193:                
                    194:     if (wanted & PARSE_ANCHOR)
                    195:         if(given.anchor || related.anchor) {
                    196:            if(wanted & PARSE_PUNCTUATION) strcat(result, "#");
                    197:            strcat(result, given.anchor ? given.anchor : related.anchor);
                    198:        }
                    199:     free(rel);
                    200:     free(name);
                    201:     
                    202:     StrAllocCopy(return_value, result);
                    203:     free(result);
                    204:     return return_value;               /* exactly the right length */
                    205: }
2.21      frystyk   206: 
2.20      timbl     207: 
2.53      frystyk   208: /*                                                            HTCanon
                    209: **
                    210: **     Canonicalizes the URL in the following manner starting from the host
                    211: **     pointer:
                    212: **
                    213: **     1) The host name is converted to lowercase
                    214: **     2) Expands the host name of the URL from a local name to a full
                    215: **        domain name. A host name is started by `://'.
                    216: **     3) Chop off port if `:80' (http), `:70' (gopher), or `:21' (ftp)
                    217: **
                    218: **     Return: OK      The position of the current path part of the URL
                    219: **                     which might be the old one or a new one.
                    220: */
                    221: PRIVATE char *HTCanon ARGS2 (char **, filename, char *, host)
                    222: {
                    223:     char *newname = NULL;
                    224:     char *port;
                    225:     char *strptr;
                    226:     char *path;
                    227:     char *access = host-3;
                    228: 
                    229:     while (access>*filename && *(access-1)!='/')       /* Find access method */
                    230:        access--;
                    231:     if ((path = strchr(host, '/')) == NULL)                    /* Find path */
                    232:        path = host + strlen(host);
                    233:     if ((strptr = strchr(host, '@')) != NULL && strptr<path)      /* UserId */
                    234:        host = strptr;
                    235:     if ((port = strchr(host, ':')) != NULL && port>path)      /* Port number */
                    236:        port = NULL;
                    237: 
                    238:     strptr = host;                                 /* Convert to lower-case */
                    239:     while (strptr<path) {
                    240:        *strptr = TOLOWER(*strptr);
                    241:        strptr++;
                    242:     }
                    243:     
                    244:     /* Does the URL contain a full domain name? This also works for a
                    245:        numerical host name. The domain name is already made lower-case
                    246:        and without a trailing dot. */
                    247:     if (((strptr = strchr(host, '.')) == NULL || strptr >= path) &&
                    248:        strncasecomp(host, "localhost", 9)) {
                    249:        CONST char *domain = HTGetDomainName();
                    250:        if (domain && *domain) {
                    251:            if ((newname = (char *) calloc(1, strlen(*filename) +
                    252:                                       strlen(domain)+2)) == NULL)
                    253:                outofmem(__FILE__, "HTCanon");
                    254:            if (port)
                    255:                strncpy(newname, *filename, (int) (port-*filename));
                    256:            else
                    257:                strncpy(newname, *filename, (int) (path-*filename));
                    258:            strcat(newname, ".");
                    259:            strcat(newname, domain);
                    260:        }
                    261:     } else {                                     /* Look for a trailing dot */
                    262:        char *dot = port ? port : path;
                    263:        if (dot > *filename && *--dot=='.') {
                    264:            char *orig=dot, *dest=dot+1;
                    265:            while((*orig++ = *dest++));
                    266:            if (port) port--;
                    267:            path--;
                    268:        }
                    269:     }
                    270:     /* Chop off port if `:', `:80' (http), `:70' (gopher), or `:21' (ftp) */
                    271:     if (port) {
                    272:        if (!*(port+1) || *(port+1)=='/') {
                    273:            if (!newname) {
                    274:                char *orig=port, *dest=port+1;
                    275:                while((*orig++ = *dest++));
                    276:            }
                    277:        } else if ((!strncmp(access, "http", 4) &&
                    278:             (*(port+1)=='8'&&*(port+2)=='0'&&(*(port+3)=='/'||!*(port+3)))) ||
                    279:            (!strncmp(access, "gopher", 6) &&
                    280:             (*(port+1)=='7'&&*(port+2)=='0'&&(*(port+3)=='/'||!*(port+3)))) ||
                    281:            (!strncmp(access, "ftp", 3) &&
                    282:             (*(port+1)=='2'&&*(port+2)=='1'&&(*(port+3)=='/'||!*(port+3))))) {
                    283:            if (!newname) {
                    284:                char *orig=port, *dest=port+3;
                    285:                while((*orig++ = *dest++));
2.54      frystyk   286:                path -= 3;             /* Update path position, Henry Minsky */
2.53      frystyk   287:            }
                    288:        } else if (newname)
                    289:            strncat(newname, port, (int) (path-port));
                    290:     }
                    291: 
                    292:     if (newname) {
                    293:        char *newpath = newname+strlen(newname);
                    294:        strcat(newname, path);
                    295:        path = newpath;
                    296:        free(*filename);                                    /* Free old copy */
                    297:        *filename = newname;
                    298:     }
                    299:     return path;
                    300: }
                    301: 
2.20      timbl     302: /*             Simplify a URI
                    303: //             --------------
                    304: // A URI is allowed to contain the seqeunce xxx/../ which may be
1.1       timbl     305: // replaced by "" , and the seqeunce "/./" which may be replaced by "/".
2.20      timbl     306: // Simplification helps us recognize duplicate URIs. 
1.1       timbl     307: //
                    308: //     Thus,   /etc/junk/../fred       becomes /etc/fred
                    309: //             /etc/junk/./fred        becomes /etc/junk/fred
2.11      timbl     310: //
                    311: //      but we should NOT change
                    312: //             http://fred.xxx.edu/../..
                    313: //
                    314: //     or      ../../albert.html
2.26      frystyk   315: //
                    316: // In order to avoid empty URLs the following URLs become:
                    317: //
                    318: //             /fred/..                becomes /fred/..
                    319: //             /fred/././..            becomes /fred/..
2.27      frystyk   320: //             /fred/.././junk/.././   becomes /fred/..
2.26      frystyk   321: //
2.30      frystyk   322: // If more than one set of `://' is found (several proxies in cascade) then
                    323: // only the part after the last `://' is simplified.
2.44      frystyk   324: //
                    325: // Returns: A string which might be the old one or a new one.
1.1       timbl     326: */
2.55      frystyk   327: PUBLIC char *HTSimplify ARGS1(char **, url)
1.1       timbl     328: {
2.31      frystyk   329:     char *path;
                    330:     char *p;
2.19      frystyk   331: 
2.55      frystyk   332:     if (!url || !*url) {
                    333:        if (URI_TRACE) fprintf(TDEST, "HTSimplify.. Nothing done\n");
                    334:        return *url;
2.31      frystyk   335:     }
2.55      frystyk   336:     if (URI_TRACE) fprintf(TDEST, "HTSimplify.. `%s\' ", *url);
2.27      frystyk   337: 
2.55      frystyk   338:     /* Find any scheme name */
                    339:     if ((path = strstr(*url, "://")) != NULL) {                   /* Find host name */
2.30      frystyk   340:        char *newptr;
2.31      frystyk   341:        path += 3;
                    342:        while ((newptr = strstr(path, "://")) != NULL)
                    343:            path = newptr+3;
2.55      frystyk   344:        path = HTCanon(url, path);                    /* We have a host name */
                    345:     } else if ((path = strstr(*url, ":/")) != NULL) {
2.31      frystyk   346:        path += 2;
2.27      frystyk   347:     } else
2.55      frystyk   348:        path = *url;
2.31      frystyk   349:     if (*path == '/' && *(path+1)=='/') {        /* Some URLs start //<foo> */
                    350:        path += 1;
2.34      frystyk   351:     } else if (!strncmp(path, "news:", 5)) {
                    352:        char *ptr = strchr(path+5, '@');
                    353:        if (!ptr) ptr = path+5;
                    354:        while (*ptr) {                      /* Make group or host lower case */
                    355:            *ptr = TOLOWER(*ptr);
                    356:            ptr++;
2.31      frystyk   357:        }
                    358:        if (URI_TRACE)
2.55      frystyk   359:            fprintf(TDEST, "into\n............ `%s'\n", *url);
                    360:        return *url;                  /* Doesn't need to do any more */
2.31      frystyk   361:     }
                    362:     if ((p = path)) {
2.55      frystyk   363:        char *end;
                    364:        if (!((end = strchr(path, ';')) || (end = strchr(path, '?')) ||
                    365:              (end = strchr(path, '#'))))
                    366:            end = path+strlen(path);
2.31      frystyk   367: 
2.55      frystyk   368: #if 0
2.31      frystyk   369:        /* Parse string first time to find number of `real' tokens */
2.55      frystyk   370:        int segments = 0;
                    371:        while (p<end) {
2.31      frystyk   372:            if (*p=='/' || p==path) {
                    373:                if (!((*(p+1)=='/' || !*(p+1)) ||
                    374:                      (*(p+1)=='.' && (*(p+2)=='/' || !*(p+2))) ||
                    375:                      (*(p+1)=='.' && *(p+2)=='.' &&(*(p+3)=='/' || !*(p+3)))))
                    376:                    segments++;
                    377:            }
                    378:            p++;
                    379:        }
2.55      frystyk   380: #endif 
2.31      frystyk   381:        /* Parse string second time to simplify */
                    382:        p = path;
2.55      frystyk   383:        while(p<end) {
2.31      frystyk   384:            if (*p=='/') {
2.56    ! frystyk   385:                if (p>*url && *(p+1)=='.' && (*(p+2)=='/' || !*(p+2))) {
        !           386:                    char *orig = p+1;
        !           387:                    char *dest = (*(p+2)!='/') ? p+2 : p+3;
2.31      frystyk   388:                    while ((*orig++ = *dest++)); /* Remove a slash and a dot */
2.55      frystyk   389:                    end = orig-1;
2.56    ! frystyk   390:                } else if (*(p+1)=='.' && *(p+2)=='.' && (*(p+3)=='/' || !*(p+3))) {
2.31      frystyk   391:                    char *q = p;
                    392:                    while (q>path && *--q!='/');               /* prev slash */
2.56    ! frystyk   393:                    if (strncmp(q, "/../", 4)) {
        !           394:                        char *orig = q+1;
        !           395:                        char *dest = (*(p+3)!='/') ? p+3 : p+4;
2.31      frystyk   396:                        while ((*orig++ = *dest++));       /* Remove /xxx/.. */
2.55      frystyk   397:                        end = orig-1;
2.56    ! frystyk   398:                        p = q;                /* Start again with prev slash */
2.31      frystyk   399:                    } else
                    400:                        p++;
                    401:                } else if (*(p+1)=='/') {
                    402:                    while (*(p+1)=='/') {
                    403:                        char *orig=p, *dest=p+1;
                    404:                        while ((*orig++ = *dest++));  /* Remove multiple /'s */
2.55      frystyk   405:                        end = orig-1;
2.19      frystyk   406:                    }
2.56    ! frystyk   407:                } else
        !           408:                    p++;
        !           409:            } else
        !           410:                p++;
        !           411:        }
2.19      frystyk   412:     }
2.31      frystyk   413:     if (URI_TRACE)
2.55      frystyk   414:        fprintf(TDEST, "into\n............ `%s'\n", *url);
                    415:     return *url;
2.19      frystyk   416: }
2.31      frystyk   417: 
2.19      frystyk   418: #ifdef OLD_CODE
2.17      frystyk   419:     char * p = filename;
1.1       timbl     420:     char * q;
2.17      frystyk   421:     
                    422:     if (p) {
                    423:        while (*p && (*p == '/' || *p == '.'))     /* Pass starting / or .'s */
                    424:            p++;
                    425:        while(*p) {
                    426:            if (*p=='/') {
1.1       timbl     427:            if ((p[1]=='.') && (p[2]=='.') && (p[3]=='/' || !p[3] )) {
2.11      timbl     428:                for (q=p-1; (q>=filename) && (*q!='/'); q--); /* prev slash */
                    429:                if (q[0]=='/' && 0!=strncmp(q, "/../", 4)
                    430:                        &&!(q-1>filename && q[-1]=='/')) {
2.15      luotonen  431:                    ari_strcpy(q, p+3);         /* Remove  /xxx/..      */
1.1       timbl     432:                    if (!*filename) strcpy(filename, "/");
                    433:                    p = q-1;            /* Start again with prev slash  */
2.11      timbl     434:                } else {                        /*   xxx/.. leave it!   */
2.9       timbl     435: #ifdef BUG_CODE
2.15      luotonen  436:                    ari_strcpy(filename, p[3] ? p+4 : p+3); /* rm  xxx/../ */
1.1       timbl     437:                    p = filename;               /* Start again */
2.9       timbl     438: #endif
1.1       timbl     439:                }
                    440:            } else if ((p[1]=='.') && (p[2]=='/' || !p[2])) {
2.15      luotonen  441:                ari_strcpy(p, p+2);             /* Remove a slash and a dot */
2.13      luotonen  442:            } else if (p[-1] != ':') {
                    443:                while (p[1] == '/') {
2.15      luotonen  444:                    ari_strcpy(p, p+1); /* Remove multiple slashes */
2.13      luotonen  445:                }
1.1       timbl     446:            }
2.17      frystyk   447:            }
                    448:            p++;
                    449:        }  /* end while (*p) */
                    450:     } /* end if (p) */
1.1       timbl     451: }
2.19      frystyk   452: #endif /* OLD_CODE */
1.1       timbl     453: 
                    454: 
                    455: /*             Make Relative Name
                    456: **             ------------------
                    457: **
                    458: ** This function creates and returns a string which gives an expression of
                    459: ** one address as related to another. Where there is no relation, an absolute
                    460: ** address is retured.
                    461: **
                    462: **  On entry,
                    463: **     Both names must be absolute, fully qualified names of nodes
                    464: **     (no anchor bits)
                    465: **
                    466: **  On exit,
                    467: **     The return result points to a newly allocated name which, if
                    468: **     parsed by HTParse relative to relatedName, will yield aName.
                    469: **     The caller is responsible for freeing the resulting name later.
                    470: **
                    471: */
2.32      frystyk   472: char * HTRelative ARGS2(CONST char *, aName, CONST char *, relatedName)
1.1       timbl     473: {
                    474:     char * result = 0;
                    475:     CONST char *p = aName;
                    476:     CONST char *q = relatedName;
                    477:     CONST char * after_access = 0;
                    478:     CONST char * path = 0;
                    479:     CONST char * last_slash = 0;
                    480:     int slashes = 0;
                    481:     
                    482:     for(;*p; p++, q++) {       /* Find extent of match */
                    483:        if (*p!=*q) break;
                    484:        if (*p==':') after_access = p+1;
                    485:        if (*p=='/') {
                    486:            last_slash = p;
                    487:            slashes++;
                    488:            if (slashes==3) path=p;
                    489:        }
                    490:     }
                    491:     
                    492:     /* q, p point to the first non-matching character or zero */
                    493:     
                    494:     if (!after_access) {                       /* Different access */
                    495:         StrAllocCopy(result, aName);
                    496:     } else if (slashes<3){                     /* Different nodes */
                    497:        StrAllocCopy(result, after_access);
                    498:     } else {                                   /* Some path in common */
                    499:         int levels= 0;
                    500:         for(; *q && (*q!='#'); q++)  if (*q=='/') levels++;
                    501:        result = (char *)malloc(3*levels + strlen(last_slash) + 1);
                    502:       if (result == NULL) outofmem(__FILE__, "HTRelative");
                    503:        result[0]=0;
                    504:        for(;levels; levels--)strcat(result, "../");
                    505:        strcat(result, last_slash+1);
                    506:     }
2.44      frystyk   507:     if (URI_TRACE) fprintf(TDEST,
2.21      frystyk   508:                      "HTRelative.. `%s' expressed relative to `%s' is `%s'\n",
                    509:                       aName, relatedName, result);
1.1       timbl     510:     return result;
                    511: }
2.1       timbl     512: 
2.24      luotonen  513: /*                                                     HTCleanTelnetString()
                    514:  *     Make sure that the given string doesn't contain characters that
                    515:  *     could cause security holes, such as newlines in ftp, gopher,
                    516:  *     news or telnet URLs; more specifically: allows everything between
2.26      frystyk   517:  *     ASCII 20-7E, and also A0-FE, inclusive. Also TAB ('\t') allowed!
2.24      luotonen  518:  *
                    519:  * On entry,
                    520:  *     str     the string that is *modified* if necessary.  The
                    521:  *             string will be truncated at the first illegal
                    522:  *             character that is encountered.
                    523:  * On exit,
                    524:  *     returns YES, if the string was modified.
                    525:  *             NO, otherwise.
                    526:  */
                    527: PUBLIC BOOL HTCleanTelnetString ARGS1(char *, str)
                    528: {
                    529:     char * cur = str;
                    530: 
                    531:     if (!str) return NO;
                    532: 
                    533:     while (*cur) {
2.52      frystyk   534:        int a = TOASCII((unsigned char) *cur);
2.26      frystyk   535:        if (a != 0x9 && (a < 0x20 || (a > 0x7E && a < 0xA0) ||  a > 0xFE)) {
2.31      frystyk   536:            if (URI_TRACE)
2.44      frystyk   537:                fprintf(TDEST, "Illegal..... character in URL: \"%s\"\n",str);
2.24      luotonen  538:            *cur = 0;
2.31      frystyk   539:            if (URI_TRACE)
2.44      frystyk   540:                fprintf(TDEST, "Truncated... \"%s\"\n",str);
2.24      luotonen  541:            return YES;
                    542:        }
                    543:        cur++;
                    544:     }
                    545:     return NO;
                    546: }
                    547: 

Webmaster