annotate src/vbuf.h @ 108:1b2a4fac1303 stable-0-6-21

fix title bug with old schema in pst2ldif, also escape commas in distinguished names per rfc4514.
author Carl Byington <carl@five-ten-sg.com>
date Tue, 21 Oct 2008 14:37:13 -0700
parents b12f4e50e2e8
children ed2a260bbb98
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
70
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
1 /* vbuf.h - variable length buffer functions
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
2 *
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
3 * Functions that try to make dealing with buffers easier.
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
4 *
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
5 * vbuf
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
6 *
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
7 * vstr
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
8 * - should always contain a valid string
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
9 *
70
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
10 */
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
11
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
12 #ifndef VBUF_H
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
13 #define VBUF_H
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
14 #define SZ_MAX 4096
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
15 #include <stdlib.h>
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
16 #include <stdio.h>
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
17 #include <stdarg.h>
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
18 /***************************************************/
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
19
70
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
20 // Tokenizer const TOK_EMPTY, TOK_ELEMENT, DELIM
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
21 #define DELIM '\\'
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
22
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
23 #define TOK_EMPTY 0
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
24 #define TOK_DELIM 1
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
25 #define TOK_PARENT 2
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
26 #define TOK_CURRENT 3
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
27 #define TOK_ELEMENT 4
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
28
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
29 #define TOK_ERROR 10
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
30 #define TOK_BUF_SMALL 11
70
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
31
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
32
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
33
70
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
34 // Variable-length buffers
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
35 struct varbuf {
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
36 size_t dlen; //length of data stored in buffer
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
37 size_t blen; //length of buffer
70
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
38 char *buf; //buffer
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
39 char *b; //start of stored data
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
40 };
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
41
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
42
70
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
43 // The exact same thing as a varbuf but should always contain at least '\0'
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
44 struct varstr {
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
45 size_t dlen; //length of data stored in buffer
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
46 size_t blen; //length of buffer
70
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
47 char *buf; //buffer
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
48 char *b; //start of stored data
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
49 };
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
50
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
51
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
52 typedef struct varbuf vbuf;
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
53 typedef struct varstr vstr;
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
54
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
55 #define VBUF_STATIC(x,y) static vbuf *x = NULL; if(!x) x = vballoc(y);
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
56 #define VSTR_STATIC(x,y) static vstr *x = NULL; if(!x) x = vsalloc(y);
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
57
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
58 // vbuf functions
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
59 struct varbuf *vballoc( size_t len );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
60 void vbfree( vbuf *vb );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
61 void vbclear( vbuf *vb ); //ditch the data, keep the buffer
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
62 void vbresize( vbuf *vb, size_t len );
70
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
63 size_t vbavail( vbuf *vb );
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
64 void vbdump( vbuf *vb );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
65 void vbgrow( vbuf *vb, size_t len ); // grow buffer by len bytes, data are preserved
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
66 void vbset( vbuf *vb, void *data, size_t len );
70
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
67 void vbskipws( vbuf *vb );
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
68 void vbappend( vbuf *vb, void *data, size_t length );
70
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
69 void vbskip( vbuf *vb, size_t skip );
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
70 void vboverwrite( vbuf *vbdest, vbuf *vbsrc );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
71
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
72 // vstr functions
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
73 vstr *vsalloc( size_t len );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
74 char *vsb( vstr *vs );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
75 size_t vslen( vstr *vs ); //strlen
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
76 void vsfree( vstr *vs );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
77 void vsset( vstr *vs, char *s ); // Store string s in vb
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
78 void vsnset( vstr *vs, char *s, size_t n ); // Store string s in vb
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
79 void vsgrow( vstr *vs, size_t len ); // grow buffer by len bytes, data are preserved
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
80 size_t vsavail( vstr *vs );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
81 void vscat( vstr *vs, char *str );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
82 void vsncat( vstr *vs, char *str, size_t len );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
83 void vsnprepend( vstr *vs, char *str, size_t len ) ;
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
84 void vsskip( vstr *vs, size_t len );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
85 int vscmp( vstr *vs, char *str );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
86 void vsskipws( vstr *vs );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
87 void vs_printf( vstr *vs, char *fmt, ... );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
88 void vs_printfa( vstr *vs, char *fmt, ... );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
89 void vshexdump( vstr *vs, char *b, size_t start, size_t stop, int ascii );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
90 int vscatprintf( vstr *vs, char *fmt, ... );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
91 void vsvprintf( vstr *vs, char *fmt, va_list ap );
70
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
92 void vstrunc( vstr *vs, size_t off ); // Drop chars [off..dlen]
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
93 int vslast( vstr *vs ); // returns the last character stored in a vstr string
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
94 void vscharcat( vstr *vs, int ch );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
95 int vsutf16( vstr *vs, vbuf *in ); //in: in=zero-terminated utf16; out: vs=utf8; returns: 0 on success, else on fail
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
96
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
97 int vs_parse_escaped_string( vstr *vs, char *str, size_t len );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
98
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
99
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
100 /*
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
101 * Windows unicode output trash - this stuff sucks
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
102 * TODO: most of this should not be here
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
103 */
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
104
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
105 void unicode_init();
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
106 void unicode_close();
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
107 int utf16_write( FILE* stream, const void *buf, size_t count );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
108 int utf16_fprintf( FILE* stream, const char *fmt, ... );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
109 int utf16to8( char *inbuf_o, char *outbuf_o, int length );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
110 int utf8to16( char *inbuf_o, int iblen, char *outbuf_o, int oblen);
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
111 int vb_utf8to16T( vbuf *bout, char *cin, int inlen );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
112 int vb_utf16to8( vbuf *dest, char *buf, int len );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
113 int iso8859_1to8( char *inbuf_o, char *outbuf_o, int length );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
114 int utf8toascii( const char *inbuf_o, char *outbuf_o, int length );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
115
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
116 /* dump ascii hex in windoze format */
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
117 void winhex(FILE* stream, unsigned char *hbuf, int start, int stop, int loff);
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
118 void winhex8(FILE *stream, unsigned char *hbuf, int start, int stop, int loff );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
119
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
120 void vbwinhex8(vbuf *vb, unsigned char *hbuf, int start, int stop, int loff );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
121
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
122 /* general search routine, find something in something else */
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
123 int find_in_buf(char *buf, char *what, int sz, int len, int start);
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
124
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
125 /* Get INTEGER from memory. This is probably low-endian specific? */
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
126 int get_int( char *array );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
127
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
128 int find_nl( vstr *vs ); // find newline of type type in b
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
129 int skip_nl( char *s ); // returns the width of the newline at s[0]
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
130 //int vb_readline( struct varbuf *vb, int *ctype, FILE *in ); // read *AT LEAST* one full line of data from in
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
131 int vb_skipline( struct varbuf *vb ); // in: vb->b == "stuff\nmore_stuff"; out: vb->b == "more_stuff"
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
132 /* Get a string of HEX bytes (space separated),
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
133 * or if first char is ' get an ASCII string instead. */
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
134 int gethexorstr(char **c, char *wb);
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
135 char *esc_index( char *s, int c ); // just like index(3), but works on strings with escape sequences
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
136 char *esc_rindex( char *s, int c ); // just like rindex(3), but works on strings with escape sequences
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
137
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
138 char *tok_esc_char( char *s, int *is_esc, int *c );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
139 int vb_path_token( vbuf *tok, char **path ); // returns things like TOK_EMPTY, TOK_ERROR, complete list at top
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
140
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
141 int gettoken( char *tok, int len, char **path, char delim ); // Path tokenizer: increments path, dumps token in tok
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
142 #endif