HTParse.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /* HTParse: URL parsing in the WWW Library
  2. * HTPARSE
  3. *
  4. * This module of the WWW library contains code to parse URLs and various
  5. * related things.
  6. * Implemented by HTParse.c .
  7. */
  8. #ifndef HTPARSE_H
  9. #define HTPARSE_H
  10. #ifndef HTUTILS_H
  11. #include <HTUtils.h>
  12. #endif
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. /*
  17. * The following are flag bits which may be ORed together to form
  18. * a number to give the 'wanted' argument to HTParse.
  19. */
  20. #define PARSE_ACCESS 16
  21. #define PARSE_HOST 8
  22. #define PARSE_PATH 4
  23. #define PARSE_ANCHOR 2
  24. #define PARSE_PUNCTUATION 1
  25. #define PARSE_ALL 31
  26. #define PARSE_ALL_WITHOUT_ANCHOR (PARSE_ALL ^ PARSE_ANCHOR)
  27. /*
  28. * Additional flag bits for more details on components already
  29. * covered by the above. The PARSE_PATH above doesn't really
  30. * strictly refer to the path component in the sense of the URI
  31. * specs only, but rather to that combined with a possible query
  32. * component. - kw
  33. */
  34. #define PARSE_STRICTPATH 32
  35. #define PARSE_QUERY 64
  36. /*
  37. * The following are valid mask values. The terms are the BNF names
  38. * in the URL document.
  39. */
  40. #define URL_XALPHAS UCH(1)
  41. #define URL_XPALPHAS UCH(2)
  42. #define URL_PATH UCH(4)
  43. /* Strip white space off a string. HTStrip()
  44. * -------------------------------
  45. *
  46. * On exit,
  47. * Return value points to first non-white character, or to 0 if none.
  48. * All trailing white space is OVERWRITTEN with zero.
  49. */ extern char *HTStrip(char *s);
  50. /* Parse a Name relative to another name. HTParse()
  51. * --------------------------------------
  52. *
  53. * This returns those parts of a name which are given (and requested)
  54. * substituting bits from the related name where necessary.
  55. *
  56. * On entry,
  57. * aName A filename given
  58. * relatedName A name relative to which aName is to be parsed
  59. * wanted A mask for the bits which are wanted.
  60. *
  61. * On exit,
  62. * returns A pointer to a malloc'd string which MUST BE FREED
  63. */
  64. extern char *HTParse(const char *aName,
  65. const char *relatedName,
  66. int wanted);
  67. /* HTParseAnchor(), fast HTParse() specialization
  68. * ----------------------------------------------
  69. *
  70. * On exit,
  71. * returns A pointer within input string (probably to its end '\0')
  72. */
  73. extern const char *HTParseAnchor(const char *aName);
  74. /* Simplify a filename. HTSimplify()
  75. * --------------------
  76. *
  77. * A unix-style file is allowed to contain the seqeunce xxx/../ which may
  78. * be replaced by "" , and the seqeunce "/./" which may be replaced by "/".
  79. * Simplification helps us recognize duplicate filenames.
  80. *
  81. * Thus, /etc/junk/../fred becomes /etc/fred
  82. * /etc/junk/./fred becomes /etc/junk/fred
  83. *
  84. * but we should NOT change
  85. * http://fred.xxx.edu/../..
  86. *
  87. * or ../../albert.html
  88. */
  89. extern void HTSimplify(char *filename);
  90. /* Make Relative Name. HTRelative()
  91. * -------------------
  92. *
  93. * This function creates and returns a string which gives an expression of
  94. * one address as related to another. Where there is no relation, an absolute
  95. * address is retured.
  96. *
  97. * On entry,
  98. * Both names must be absolute, fully qualified names of nodes
  99. * (no anchor bits)
  100. *
  101. * On exit,
  102. * The return result points to a newly allocated name which, if
  103. * parsed by HTParse relative to relatedName, will yield aName.
  104. * The caller is responsible for freeing the resulting name later.
  105. *
  106. */
  107. extern char *HTRelative(const char *aName,
  108. const char *relatedName);
  109. /* Escape undesirable characters using % HTEscape()
  110. * -------------------------------------
  111. *
  112. * This function takes a pointer to a string in which
  113. * some characters may be unacceptable are unescaped.
  114. * It returns a string which has these characters
  115. * represented by a '%' character followed by two hex digits.
  116. *
  117. * Unlike HTUnEscape(), this routine returns a malloc'd string.
  118. */
  119. extern char *HTEscape(const char *str,
  120. unsigned char mask);
  121. /* Escape unsafe characters using % HTEscapeUnsafe()
  122. * --------------------------------
  123. *
  124. * This function takes a pointer to a string in which
  125. * some characters may be that may be unsafe are unescaped.
  126. * It returns a string which has these characters
  127. * represented by a '%' character followed by two hex digits.
  128. *
  129. * Unlike HTUnEscape(), this routine returns a malloc'd string.
  130. */
  131. extern char *HTEscapeUnsafe(const char *str);
  132. /* Escape undesirable characters using % but space to +. HTEscapeSP()
  133. * -----------------------------------------------------
  134. *
  135. * This function takes a pointer to a string in which
  136. * some characters may be unacceptable are unescaped.
  137. * It returns a string which has these characters
  138. * represented by a '%' character followed by two hex digits,
  139. * except that spaces are converted to '+' instead of %2B.
  140. *
  141. * Unlike HTUnEscape(), this routine returns a malloc'd string.
  142. */
  143. extern char *HTEscapeSP(const char *str,
  144. unsigned char mask);
  145. /* Decode %xx escaped characters. HTUnEscape()
  146. * ------------------------------
  147. *
  148. * This function takes a pointer to a string in which some
  149. * characters may have been encoded in %xy form, where xy is
  150. * the acsii hex code for character 16x+y.
  151. * The string is converted in place, as it will never grow.
  152. */
  153. extern char *HTUnEscape(char *str);
  154. /* Decode some %xx escaped characters. HTUnEscapeSome()
  155. * ----------------------------------- Klaus Weide
  156. * (kweide@tezcat.com)
  157. * This function takes a pointer to a string in which some
  158. * characters may have been encoded in %xy form, where xy is
  159. * the acsii hex code for character 16x+y, and a pointer to
  160. * a second string containing one or more characters which
  161. * should be unescaped if escaped in the first string.
  162. * The first string is converted in place, as it will never grow.
  163. */
  164. extern char *HTUnEscapeSome(char *str,
  165. const char *do_trans);
  166. /*
  167. * Turn a string which is not a RFC 822 token into a quoted-string. - KW
  168. */
  169. extern void HTMake822Word(char **str,
  170. int quoted);
  171. #ifdef __cplusplus
  172. }
  173. #endif
  174. #endif /* HTPARSE_H */