File: netencoding.mli

package info (click to toggle)
netstring 0.10.1-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,000 kB
  • ctags: 895
  • sloc: ml: 8,389; xml: 416; makefile: 188; sh: 103
file content (283 lines) | stat: -rw-r--r-- 10,499 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
(* $Id: netencoding.mli,v 1.5 2001/08/30 19:45:43 gerd Exp $
 * ----------------------------------------------------------------------
 *
 *)

(**********************************************************************)
(* Several encodings important for the net                            *)
(**********************************************************************)


(**********************************************************************)
(* Base 64 encoding                                                   *)
(**********************************************************************)

(* See RFC 2045 for a description of Base 64 encoding. *)

(* THREAD-SAFETY: 
 * All Base64 functions are reentrant and thus thread-safe.
 *)

module Base64 : sig

  val encode : ?pos:int -> ?len:int -> ?linelength:int -> ?crlf:bool ->
               string -> string
      (* Compute the "base 64" encoding of the given string argument.
       * Note that the result is a string that only contains the characters
       * a-z, A-Z, 0-9, +, /, =, and optionally spaces, CR and LF characters.
       *
       * If pos and/or len are passed, only the substring starting at
       * pos (default: 0) with length len (default: rest of the string)
       * is encoded.
       *
       * The result is divided up into lines not longer than 'linelength' 
       * (without counting the line separator); default: do not divide lines.
       * If 'linelength' is smaller than 4, no line division is performed.
       * If 'linelength' is not divisible by 4, the produced lines are a 
       * bit shorter than 'linelength'.
       *
       * If 'crlf' (default: false) the lines are ended by CRLF; otherwise 
       * they are only ended by LF.
       * (You need the crlf option to produce correct MIME messages.)
       * 
       *)

  val url_encode : ?pos:int -> ?len:int -> ?linelength:int -> ?crlf:bool ->
                   string -> string
      (* Same as 'encode' but use slightly different characters that can be
       * part of URLs without additional encodings.
       * The encoded string consists only of the characters a-z, A-Z, 0-9, 
       * -, /, .
       * 'url_encode' does NOT implement the Base 64 encoding as described
       * in the standard!
       *)

  val encode_substring : string -> pos:int -> len:int -> linelength:int -> 
                         crlf:bool -> string
      (* *** DEPRECATED FUNCTION *** Use 'encode' instead! ***
       *
       * encode_substring s pos len linelen crlf:
       * Encodes the substring at position 'pos' in 's' with length 'len'.
       * The result is divided up into lines not longer than 'linelen' (without
       * counting the line separator).
       * If 'linelen' is smaller than 4, no line division is performed.
       * If 'linelen' is not divisible by 4, the produced lines are a 
       * bit shorter than 'linelen'.
       * If 'crlf' the lines are ended by CRLF; otherwise they are only
       * ended by LF.
       * (You need the crlf option to produce correct MIME messages.)
       *)

  val decode : ?pos:int -> ?len:int -> ?url_variant:bool -> 
               ?accept_spaces:bool -> string -> string
      (* Decodes the given string argument. 
       *
       * If pos and/or len are passed, only the substring starting at
       * pos (default: 0) with length len (default: rest of the string)
       * is decoded.
       * 
       * If url_variant (default: true) is set, the functions also
       * accepts the characters '-' and '.' as produced by 'url_encode'.
       *
       * If accept_spaces (default: false) is set, the function ignores
       * white space contained in the string to decode (otherwise the
       * function fails if it finds white space).
       *)

  val decode_ignore_spaces : string -> string
      (* *** DEPRECATED FUNCTION *** Use 'decode' instead! ***
       *
       * Decodes the string, too, but it is allowed that the string contains
       * whitespace characters.
       * This function is slower than 'decode'.
       *)

  val decode_substring : string -> pos:int -> len:int -> url_variant:bool -> 
                         accept_spaces:bool -> string
      (* *** DEPRECATED FUNCTION *** Use 'decode' instead! ***
       *
       * decode_substring s pos len url spaces:
       * Decodes the substring of 's' beginning at 'pos' with length 'len'.
       * If 'url', strings created by 'url_encode' are accepted, too.
       * If 'spaces', whitespace characters are allowed in the string.
       *)
end

(**********************************************************************)
(* Quoted printable encoding                                          *)
(**********************************************************************)

(* See RFC 2045.
 * This implementation assumes that the encoded string has a text MIME
 * type. Because of this, the characters CR and LF are never protected 
 * by hex tokens; they are copied literally to the output string.
 *)

(* THREAD-SAFETY: 
 * All QuotedPrintable functions are reentrant and thus thread-safe.
 *)

module QuotedPrintable :
  sig
    val encode : ?pos:int -> ?len:int -> string -> string
	(* Encodes the string and returns it.
	 * Note line breaks: 
	 *   No additional soft line breaks are added. The characters CR
	 *   and LF are not represented as =0D resp. =0A. (But other control
	 *   characters ARE encoded.)
	 * Note unsafe characters:
	 *   As recommended by RFC 2045, the characters !\"#$@[]^`{|}~
	 *   are additionally represented as hex tokens.        -- "
	 *
	 * If pos and/or len are passed, only the substring starting at
	 * pos (default: 0) with length len (default: rest of the string)
	 * is encoded.
	 *)

    val encode_substring : string -> pos:int -> len:int -> string
	(* *** DEPRECATED FUNCTION *** Use 'encode' instead! ***
	 * encode_substring s pos len:
	 * Encodes the substring of 's' beginning at 'pos' with length 'len'.
	 *)

    val decode : ?pos:int -> ?len:int -> string -> string
	(* Decodes the string and returns it.
	 * Most format errors cause an Invalid_argument exception.
	 * Note that soft line breaks can be properly decoded although 
	 * 'encode' will never produce them.
	 *
	 * If pos and/or len are passed, only the substring starting at
	 * pos (default: 0) with length len (default: rest of the string)
	 * is decoded.
	 *)

    val decode_substring : string -> pos:int -> len:int -> string
        (* *** DEPRECATED FUNCTION *** Use 'decode' instead! ***
	 * decode_substring s pos len:
	 * Decodes the substring of 's' beginning at 'pos' with length 'len'.
	 *)

  end

(**********************************************************************)
(* Q encoding                                                         *)
(**********************************************************************)

(* See RFC 2047. 
 * The functions behave similar to those of QuotedPrintable. 
 *)

(* THREAD-SAFETY: 
 * All Q functions are reentrant and thus thread-safe.
 *)

module Q :
  sig
    val encode : ?pos:int -> ?len:int -> string -> string
	(* Note:
	 * All characters except alphanumeric characters are protected by
	 * hex tokens.
	 * In particular, spaces are represented as "=20", not as "_".
	 *)

    val decode : ?pos:int -> ?len:int -> string -> string

    val encode_substring : string -> pos:int -> len:int -> string
        (* *** DEPRECATED FUNCTION *** Use 'encode' instead! *** *)

    val decode_substring : string -> pos:int -> len:int -> string
        (* *** DEPRECATED FUNCTION *** Use 'decode' instead! *** *)
  end

(**********************************************************************)
(* B encoding                                                         *)
(**********************************************************************)

(* The B encoding of RFC 2047 is the same as Base64. *)


(**********************************************************************)
(* URL-encoding                                                       *)
(**********************************************************************)

(* Encoding/Decoding within URLs:
 *
 * The following two functions perform the '%'-substitution for
 * characters that may otherwise be interpreted as metacharacters.
 *
 * According to: RFC 1738, RFC 1630
 *
 * Option ~plus: This option has been added because there are some
 * implementations that do not map ' ' to '+', for example Javascript's
 * escape function. The default is "true" because this is the RFC-
 * compliant definition.
 *)

(* THREAD-SAFETY:
 * The Url functions are thread-safe.
 *)

module Url : 
  sig
    val decode : ?plus:bool -> string -> string
	(* Option ~plus: Whether '+' is converted to space. The default
	 * is true. If false, '+' is returned as it is.
	 *)
    val encode : ?plus:bool -> string -> string
	(* Option ~plus: Whether spaces are converted to '+'. The default
	 * is true. If false, spaces are converted to "%20", and
	 * only %xx sequences are produced.
	 *)
  end


(**********************************************************************)
(* HTMLization                                                        *)
(**********************************************************************)

(* Encodes characters that need protection by converting them to
 * entity references. E.g. "<" is converted to "&lt;".
 * As the entities may be named, there is a dependency on the character
 * set. Currently, there are only functions for the Latin 1 alphabet.
 *)

(* THREAD-SAFETY:
 * The Html functions are thread-safe.
 *)

module Html :
  sig
    val encode_from_latin1 : string -> string
	(* Encodes the characters 0-8, 11-12, 14-31, '<', '>', '"', '&',
	 * 127-255. If the characters have a name, a named entity is
	 * preferred over a numeric entity.
	 *)
    val decode_to_latin1   : string -> string
	(* Decodes the string. Unknown named entities are left as they
	 * are (i.e. decode_to_latin1 "&nonsense;" = "&nonsense;").
	 * The same applies to numeric entities greater than 255.
	 *)
  end


(* ======================================================================
 * History:
 * 
 * $Log: netencoding.mli,v $
 * Revision 1.5  2001/08/30 19:45:43  gerd
 * 	Module Url: added the option ~plus
 *
 * Revision 1.4  2000/06/25 22:34:43  gerd
 * 	Added labels to arguments.
 *
 * Revision 1.3  2000/06/25 21:15:48  gerd
 * 	Checked thread-safety.
 *
 * Revision 1.2  2000/03/03 01:08:29  gerd
 * 	Added Netencoding.Html functions.
 *
 * Revision 1.1  2000/03/02 01:14:48  gerd
 * 	Initial revision.
 *
 * 
 *)