HTParse.h
Upload User: zlh9724
Upload Date: 2007-01-04
Package Size: 1991k
Code Size: 4k
Category:

Browser Client

Development Platform:

Unix_Linux

  1. /*                                                                                URI Parsing
  2.                                        URI PARSING
  3.                                              
  4.  */
  5. /*
  6. **      (c) COPYRIGHT MIT 1995.
  7. **      Please first read the full copyright statement in the file COPYRIGH.
  8. */
  9. /*
  10.    This module contains code to parse URIs and various related things such as:
  11.    
  12.       Parse a URI for tokens
  13.       
  14.       Canonicalization of URIs
  15.       
  16.       Search a URI for illigal characters in order to prevent security holes
  17.       
  18.    This module is implemented by HTParse.c, and it is a part of the  W3C Reference
  19.    Library.
  20.    
  21.  */
  22. #ifndef HTPARSE_H
  23. #define HTPARSE_H
  24. #include "HTEscape.h"
  25. /*
  26. Parsing URIs
  27.    These functions can be used to get information in a URI.
  28.    
  29.   PARSE A URI RELATIVE TO ANOTHER URI
  30.   
  31.    This returns those parts of a name which are given (and requested) substituting bits
  32.    from the related name where necessary. The aName argument is the (possibly relative)
  33.    URI to be parsed, the relatedName is the URI which the aName is to be parsed relative
  34.    to. Passing an empty string means that the aName is an absolute URI. The following are
  35.    flag bits which may be OR'ed together to form a number to give the 'wanted' argument to
  36.    HTParse.
  37.    
  38.  */
  39. #define PARSE_ACCESS            16
  40. #define PARSE_HOST               8
  41. #define PARSE_PATH               4
  42. #define PARSE_ANCHOR             2
  43. #define PARSE_PUNCTUATION        1
  44. #define PARSE_ALL               31
  45. /*
  46.    where the format of a URI is as follows:
  47.    
  48.  */
  49. /*
  50.         ACCESS :// HOST / PATH # ANCHOR
  51. */
  52. /*
  53.    PUNCTUATION means any delimiter like '/', ':', '#' between the tokens above. The string
  54.    returned by the function must be freed by the caller.
  55.    
  56.  */
  57. extern char * HTParse  (CONST char * aName, CONST char * relatedName,
  58.                         int wanted);
  59. /*
  60.   CREATE A RELATIVE (PARTIAL) URI
  61.   
  62.    This function creates and returns a string which gives an expression of one address as
  63.    related to another.  Where there is no relation, an absolute address is retured.
  64.    
  65.   ON ENTRY,
  66.   
  67.    Both names must be absolute, fully qualified names of nodes (no anchor bits)
  68.    
  69.   ON EXIT,
  70.   
  71.    The return result points to a newly allocated name which, if parsed by HTParse relative
  72.    to relatedName, will yield aName. The caller is responsible for freeing the resulting
  73.    name later.
  74.    
  75.  */
  76. extern char * HTRelative (CONST char * aName, CONST char *relatedName);
  77. /*
  78. Canonicalization
  79.    Canonicalization of URIs is a difficult job, but it saves a lot of down loads and
  80.    double entries in the cache if we do a good job. A URI is allowed to contain the
  81.    seqeunce xxx/../ which may be replaced by "" , and the seqeunce "/./" which may be
  82.    replaced by "/".  Simplification helps us recognize duplicate URIs. Thus, the following
  83.    transformations are done:
  84.    
  85.        /etc/junk/../fred
  86.       becomes
  87.       /etc/fred
  88.       
  89.        /etc/junk/./fred
  90.       becomes
  91.       /etc/junk/fred
  92.       
  93.    but we should NOT change
  94.    
  95.        http://fred.xxx.edu/../.. or
  96.       
  97.        ../../albert.html
  98.       
  99.    In the same manner, the following prefixed are preserved:
  100.    
  101.        ./
  102.       
  103.        //
  104.       
  105.    In order to avoid empty URIs the following URIs become:
  106.    
  107.        /fred/..
  108.       
  109.       
  110.       becomes /fred/..
  111.       
  112.        /fred/././..
  113.       
  114.       becomes /fred/..
  115.       
  116.        /fred/.././junk/.././
  117.       becomes /fred/..
  118.       
  119.    If more than one set of `://' is found (several proxies in cascade) then only the part
  120.    after the last `://' is simplified.
  121.    
  122.  */
  123. extern char *HTSimplify (char **filename);
  124. /*
  125. Prevent Security Holes
  126.    In many telnet like protocols, it can be very dangerous to allow a full ASCII character
  127.    set to be in a URI. Therefore we have to strip them out. HTCleanTelnetString() makes
  128.    sure that the given string doesn't contain characters that could cause security holes,
  129.    such as newlines in ftp, gopher, news or telnet URLs; more specifically: allows
  130.    everything between hexadesimal ASCII 20-7E, and also A0-FE, inclusive.
  131.    
  132.   str                     the string that is *modified* if necessary.  The string will be
  133.                              truncated at the first illegal character that is encountered.
  134.                          
  135.   returns                 YES, if the string was modified.      NO, otherwise.
  136.                          
  137.  */
  138. extern BOOL HTCleanTelnetString (char * str);
  139. /*
  140.  */
  141. #endif  /* HTPARSE_H */
  142. /*
  143.    End of HTParse Module */