summaryrefslogtreecommitdiff
path: root/xdelta1/libedsio
diff options
context:
space:
mode:
authorJosh MacDonald <josh.macdonald@gmail.com>2016-02-26 21:43:58 -0800
committerJosh MacDonald <josh.macdonald@gmail.com>2016-02-26 21:43:58 -0800
commitd594fbe514e2a381541a510fe01041e546f56a67 (patch)
tree316072f34cf7dc94518ec14a8d955d57c20d65b7 /xdelta1/libedsio
parent81aebf78ae67c29f528088d65743643e5355e3d3 (diff)
Remove xdelta1 from this repo
Diffstat (limited to 'xdelta1/libedsio')
-rw-r--r--xdelta1/libedsio/Makefile.am52
-rw-r--r--xdelta1/libedsio/base64.c525
-rw-r--r--xdelta1/libedsio/default.c343
-rw-r--r--xdelta1/libedsio/edsio-comp.in46
-rw-r--r--xdelta1/libedsio/edsio.c1610
-rw-r--r--xdelta1/libedsio/edsio.el1864
-rw-r--r--xdelta1/libedsio/edsio.h531
-rw-r--r--xdelta1/libedsio/edsio.ser129
-rw-r--r--xdelta1/libedsio/edsiotest.c213
-rw-r--r--xdelta1/libedsio/fh.c167
-rw-r--r--xdelta1/libedsio/generic.c252
-rw-r--r--xdelta1/libedsio/library.c121
-rw-r--r--xdelta1/libedsio/maketime.c391
-rw-r--r--xdelta1/libedsio/maketime.h39
-rw-r--r--xdelta1/libedsio/md5c.c298
-rw-r--r--xdelta1/libedsio/partime.c742
-rw-r--r--xdelta1/libedsio/partime.h67
-rw-r--r--xdelta1/libedsio/sha.c239
-rw-r--r--xdelta1/libedsio/simple.c179
19 files changed, 0 insertions, 7808 deletions
diff --git a/xdelta1/libedsio/Makefile.am b/xdelta1/libedsio/Makefile.am
deleted file mode 100644
index 298aa02..0000000
--- a/xdelta1/libedsio/Makefile.am
+++ /dev/null
@@ -1,52 +0,0 @@
1
2INCLUDES = $(GLIB_CFLAGS)
3
4noinst_SCRIPTS = edsio-comp
5
6lib_LTLIBRARIES = libedsio.la
7
8noinst_PROGRAMS = edsiotest
9
10edsiotest_SOURCES = edsiotest.c
11
12edsiotest_LDADD = libedsio.la $(GLIB_LIBS)
13
14noinst_HEADERS = maketime.h partime.h
15
16include_HEADERS = edsio.h edsio_edsio.h
17
18libedsio_la_LIBADD = $(GLIB_LIBS)
19
20libedsio_la_SOURCES = \
21 library.c \
22 simple.c \
23 edsio.c \
24 edsio_edsio.c \
25 sha.c \
26 md5c.c \
27 fh.c \
28 generic.c \
29 default.c \
30 base64.c \
31 maketime.c \
32 partime.c
33
34EXTRA_DIST = edsio.el edsio.ser $(SER_OUT1) edsio-comp.in edsio.prj stamp-ser1
35
36#
37# Rules for the generated code
38#
39
40stamp-ser1: $(top_srcdir)/libedsio/edsio.el edsio.ser
41 $(top_srcdir)/libedsio/edsio-comp edsio.ser
42 touch stamp-ser1
43
44SER_OUT1 = edsio_edsio.c edsio_edsio.h
45
46$(SER_OUT1): stamp-ser1
47
48BUILT_SOURCES = edsio_edsio.c
49
50#
51#
52#
diff --git a/xdelta1/libedsio/base64.c b/xdelta1/libedsio/base64.c
deleted file mode 100644
index c37ddae..0000000
--- a/xdelta1/libedsio/base64.c
+++ /dev/null
@@ -1,525 +0,0 @@
1/* -*-Mode: C;-*-
2 * $Id: base64.c 1.1 Sun, 28 Jan 2007 10:02:26 -0800 jmacd $
3 *
4 * Copyright (C) 1998, 1999, Josh MacDonald.
5 * All Rights Reserved.
6 *
7 * Author: Josh MacDonald <jmacd@CS.Berkeley.EDU>
8 */
9
10#include "edsio.h"
11
12/* BASE64 Encoding
13 */
14
15static const unsigned char base64_table[64] = {
16 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
17 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a',
18 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
19 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2',
20 '3', '4', '5', '6', '7', '8', '9', '+', '/'
21};
22
23static gint16 base64_inverse_table[128];
24
25static void
26init_inverse_table (void)
27{
28 static int i = 0;
29 static int j = 0;
30
31 for (; j < 128; j += 1)
32 base64_inverse_table[j] = -1;
33
34 for (; i < 64; i += 1)
35 base64_inverse_table[base64_table[i]] = i;
36
37 base64_inverse_table['='] = 0;
38}
39
40GByteArray*
41edsio_base64_encode_region (const guint8* data, guint len)
42{
43 GByteArray* out = g_byte_array_new ();
44 guint real_len;
45
46 g_byte_array_set_size (out, (len+2)*4/3);
47
48 real_len = out->len;
49
50 if (! edsio_base64_encode_region_into (data, len, out->data, &real_len))
51 {
52 g_byte_array_free (out, TRUE);
53 return NULL;
54 }
55
56 g_byte_array_set_size (out, real_len);
57
58 return out;
59}
60
61gboolean
62edsio_base64_encode_region_into (const guint8* data, guint len, guint8* out, guint *out_len)
63{
64 gint i;
65 guint32 word = 0, count = 0;
66
67 if ((*out_len) < (len + 2) * 4/3)
68 {
69 edsio_generate_void_event (EC_EdsioInvalidBase64Encoding);
70 return FALSE;
71 }
72
73 *out_len = 0;
74
75 for (i = 0; i < len; i += 1)
76 {
77 word |= data[i] << (8*(2-(count++)));
78
79 if (count == 3)
80 {
81 out[(*out_len)++] = base64_table[(word>>18) & 0x3f];
82 out[(*out_len)++] = base64_table[(word>>12) & 0x3f];
83 out[(*out_len)++] = base64_table[(word>> 6) & 0x3f];
84 out[(*out_len)++] = base64_table[(word ) & 0x3f];
85
86 count = 0;
87 word = 0;
88 }
89 }
90
91 if (count > 0)
92 {
93 out[(*out_len)++] = base64_table[(word>>18) & 0x3f];
94 out[(*out_len)++] = base64_table[(word>>12) & 0x3f];
95 out[(*out_len)++] = (count > 1) ? base64_table[(word>>6) & 0x3f] : '=';
96 out[(*out_len)++] = '=';
97 }
98
99 return TRUE;
100}
101
102GByteArray*
103edsio_base64_decode_region (const guint8* data, guint data_len)
104{
105 GByteArray* it = g_byte_array_new ();
106 guint real_len;
107
108 g_byte_array_set_size (it, data_len*3/4);
109
110 real_len = it->len;
111
112 if (! edsio_base64_decode_region_into (data, data_len, it->data, &real_len))
113 {
114 g_byte_array_free (it, TRUE);
115 return NULL;
116 }
117
118 g_byte_array_set_size (it, real_len);
119
120 return it;
121}
122
123gboolean
124edsio_base64_decode_region_into (const guint8* data, guint len, guint8* out, guint *out_len)
125{
126 guint32 pos = 0;
127 gboolean found_end = FALSE;
128 gint found_end_at = 0;
129
130 init_inverse_table ();
131
132 if ((*out_len) < (len*3/4))
133 {
134 edsio_generate_void_event (EC_EdsioOutputBufferShort);
135 return FALSE;
136 }
137
138 (*out_len) = 0;
139
140 while (pos < len)
141 {
142 gint i, x;
143 gint word = 0, junk = 0;
144
145 if (len - pos < 4)
146 {
147 edsio_generate_void_event (EC_EdsioInvalidBase64Encoding);
148 return FALSE;
149 }
150
151 for (i = 0; i < 4; i += 1)
152 {
153 x = data[pos++];
154
155 if (x > 127 || base64_inverse_table[x] < 0)
156 {
157 edsio_generate_void_event (EC_EdsioInvalidBase64Encoding);
158 return FALSE;
159 }
160
161 if (x == '=')
162 {
163 if (! found_end)
164 found_end_at = i;
165
166 found_end = TRUE;
167 }
168 else
169 {
170 if (found_end)
171 {
172 edsio_generate_void_event (EC_EdsioInvalidBase64Encoding);
173 return FALSE;
174 }
175
176 word |= base64_inverse_table[x] << (6*(3-i));
177 }
178 }
179
180 if (found_end)
181 {
182 if (found_end_at < 2)
183 {
184 edsio_generate_void_event (EC_EdsioInvalidBase64Encoding);
185 return FALSE;
186 }
187
188 if (found_end_at == 2)
189 junk = 2;
190 else if (found_end_at == 3)
191 junk = 1;
192 }
193 else
194 junk = 0;
195
196 out[(*out_len)++] = (word >> 16) & 0xff;
197
198 if (junk < 2)
199 out[(*out_len)++] = (word >> 8) & 0xff;
200
201 if (junk < 1)
202 out[(*out_len)++] = (word >> 0) & 0xff;
203 }
204
205 return TRUE;
206}
207
208/* Base64 sink
209 */
210typedef struct _Base64Sink Base64Sink;
211
212static gboolean base64_sink_close (SerialSink* sink);
213static gboolean base64_sink_write (SerialSink* sink, const guint8 *ptr, guint32 len);
214static void base64_sink_free (SerialSink* sink);
215static gboolean base64_sink_quantum (SerialSink* sink);
216
217struct _Base64Sink
218{
219 SerialSink sink;
220
221 SerialSink* out;
222
223 guint32 word;
224 guint32 count;
225};
226
227SerialSink*
228serializeio_base64_sink (SerialSink* out)
229{
230 Base64Sink* it = g_new0 (Base64Sink, 1);
231 SerialSink* sink = (SerialSink*) it;
232
233 serializeio_sink_init (sink,
234 NULL,
235 base64_sink_close,
236 base64_sink_write,
237 base64_sink_free,
238 base64_sink_quantum);
239
240 it->out = out;
241
242 return sink;
243}
244
245gboolean
246base64_sink_write (SerialSink* fsink, const guint8 *ptr, guint32 len)
247{
248 guint32 i;
249
250 Base64Sink* sink = (Base64Sink*) fsink;
251
252 for (i = 0; i < len; )
253 {
254 if (sink->count == 3)
255 {
256 guint8 out[4];
257
258 out[0] = base64_table[(sink->word>>18) & 0x3f];
259 out[1] = base64_table[(sink->word>>12) & 0x3f];
260 out[2] = base64_table[(sink->word>> 6) & 0x3f];
261 out[3] = base64_table[(sink->word ) & 0x3f];
262
263#if 0
264 g_print ("%02x %02x %02x -> %c%c%c%c (3)\n",
265 (sink->word>>16) & 0xff,
266 (sink->word>>8) & 0xff,
267 (sink->word>>0) & 0xff,
268 out[0],
269 out[1],
270 out[2],
271 out[3]);
272#endif
273
274 if (! sink->out->sink_write (sink->out, out, 4))
275 return FALSE;
276
277 sink->count = 0;
278 sink->word = 0;
279 }
280
281 while (sink->count < 3 && i < len)
282 sink->word |= ptr[i++] << (8*(2-(sink->count++)));
283 }
284
285 return TRUE;
286}
287
288gboolean
289base64_sink_close (SerialSink* fsink)
290{
291 Base64Sink* sink = (Base64Sink*) fsink;
292
293 if (sink->count == 3)
294 {
295 guint8 out[4];
296
297 out[0] = base64_table[(sink->word>>18) & 0x3f];
298 out[1] = base64_table[(sink->word>>12) & 0x3f];
299 out[2] = base64_table[(sink->word>> 6) & 0x3f];
300 out[3] = base64_table[(sink->word ) & 0x3f];
301
302#if 0
303 g_print ("%02x %02x %02x -> %c%c%c%c (3)\n",
304 (sink->word>>16) & 0xff,
305 (sink->word>>8) & 0xff,
306 (sink->word>>0) & 0xff,
307 out[0],
308 out[1],
309 out[2],
310 out[3]);
311#endif
312
313 if (! sink->out->sink_write (sink->out, out, 4))
314 return FALSE;
315
316 sink->count = 0;
317 sink->word = 0;
318 }
319
320 if (sink->count > 0)
321 {
322 guint8 out[4];
323
324 out[0] = base64_table[(sink->word>>18) & 0x3f];
325 out[1] = base64_table[(sink->word>>12) & 0x3f];
326 out[2] = (sink->count > 1) ? base64_table[(sink->word>>6) & 0x3f] : '=';
327 out[3] = '=';
328
329#if 0
330 g_print ("%02x %02x %02x -> %c%c%c%c (%d)\n",
331 (sink->word>>16) & 0xff,
332 (sink->word>>8) & 0xff,
333 (sink->word>>0) & 0xff,
334 out[0],
335 out[1],
336 out[2],
337 out[3],
338 sink->count);
339#endif
340
341 if (! sink->out->sink_write (sink->out, out, 4))
342 return FALSE;
343
344 sink->count = 0;
345 sink->word = 0;
346 }
347
348 return sink->out->sink_close (sink->out);
349}
350
351
352void
353base64_sink_free (SerialSink* fsink)
354{
355 Base64Sink* sink = (Base64Sink*) fsink;
356
357 sink->out->sink_free (sink->out);
358
359 g_free (sink);
360}
361
362gboolean
363base64_sink_quantum (SerialSink* fsink)
364{
365 Base64Sink* sink = (Base64Sink*) fsink;
366
367 if (sink->out->sink_quantum)
368 return sink->out->sink_quantum (sink->out);
369
370 return TRUE;
371}
372
373/* Base64 source
374 */
375
376typedef struct _Base64Source Base64Source;
377
378struct _Base64Source {
379 SerialSource source;
380
381 SerialSource *in;
382
383 guint32 avail;
384 guint32 count;
385 gboolean found_end;
386 gint found_end_at;
387 guint8 buf[3];
388};
389
390static gboolean base64_source_close (SerialSource* source);
391static gboolean base64_source_read (SerialSource* source, guint8 *ptr, guint32 len);
392static void base64_source_free (SerialSource* source);
393
394SerialSource*
395serializeio_base64_source (SerialSource* in0)
396{
397 Base64Source* it = g_new0 (Base64Source, 1);
398 SerialSource* source = (SerialSource*) it;
399
400 serializeio_source_init (source,
401 NULL,
402 base64_source_close,
403 base64_source_read,
404 base64_source_free,
405 NULL,
406 NULL);
407
408 it->in = in0;
409
410 return source;
411}
412
413gboolean
414base64_source_close (SerialSource* fsource)
415{
416 Base64Source* source = (Base64Source*) fsource;
417
418 if (! source->in->source_close (source->in))
419 return FALSE;
420
421 return TRUE;
422}
423
424gboolean
425base64_source_read (SerialSource* fsource, guint8 *ptr, guint32 len)
426{
427 guint32 pos;
428 Base64Source* source = (Base64Source*) fsource;
429
430 init_inverse_table ();
431
432 for (pos = 0; pos < len; )
433 {
434 if (source->count == 0)
435 {
436 guint8 buf[4];
437 guint32 i, word = 0, junk;
438
439 if (source->found_end)
440 {
441 edsio_generate_void_event (EC_EdsioInvalidBase64Encoding);
442 return FALSE;
443 }
444
445 if (! source->in->source_read (source->in, buf, 4))
446 return FALSE;
447
448 for (i = 0; i < 4; i += 1)
449 {
450 gint x = buf[i];
451
452 if (x > 127 || base64_inverse_table[x] < 0)
453 {
454 edsio_generate_void_event (EC_EdsioInvalidBase64Encoding);
455 return FALSE;
456 }
457
458 if (x == '=')
459 {
460 if (! source->found_end)
461 source->found_end_at = i;
462
463 source->found_end = TRUE;
464 }
465 else
466 {
467 if (source->found_end)
468 {
469 edsio_generate_void_event (EC_EdsioInvalidBase64Encoding);
470 return FALSE;
471 }
472
473 word |= base64_inverse_table[x] << (6*(3-i));
474 }
475 }
476
477 if (source->found_end)
478 {
479 if (source->found_end_at == 2)
480 junk = 2;
481 else if (source->found_end_at == 3)
482 junk = 1;
483 else
484 {
485 edsio_generate_void_event (EC_EdsioInvalidBase64Encoding);
486 return FALSE;
487 }
488 }
489 else
490 junk = 0;
491
492 source->avail = source->count = 3 - junk;
493
494 source->buf[0] = (word >> 16) & 0xff;
495 source->buf[1] = (word >> 8) & 0xff;
496 source->buf[2] = (word >> 0) & 0xff;
497
498#if 0
499 g_print ("%c%c%c%c -> %02x %02x %02x (%d)\n",
500 buf[0],
501 buf[1],
502 buf[2],
503 buf[3],
504 (word>>16) & 0xff,
505 (word>>8) & 0xff,
506 (word>>0) & 0xff,
507 3-junk);
508#endif
509 }
510
511 ptr[pos++] = source->buf[source->avail-(source->count--)];
512 }
513
514 return TRUE;
515}
516
517void
518base64_source_free (SerialSource* fsource)
519{
520 Base64Source* source = (Base64Source*) fsource;
521
522 source->in->source_free (source->in);
523
524 g_free (source);
525}
diff --git a/xdelta1/libedsio/default.c b/xdelta1/libedsio/default.c
deleted file mode 100644
index 0da2176..0000000
--- a/xdelta1/libedsio/default.c
+++ /dev/null
@@ -1,343 +0,0 @@
1/* -*-Mode: C;-*-
2 * $Id: default.c 1.1 Sun, 28 Jan 2007 10:02:26 -0800 jmacd $
3 *
4 * Copyright (C) 1998, 1999, Josh MacDonald.
5 * All Rights Reserved.
6 *
7 * Author: Josh MacDonald <jmacd@CS.Berkeley.EDU>
8 */
9
10#include "edsio.h"
11
12/* Default Sink methods
13 */
14
15static gboolean
16sink_type_default (SerialSink* sink, SerialType type, guint32 len, gboolean set_allocation)
17{
18 if (! sink->next_uint32 (sink, type))
19 return FALSE;
20
21 /* Note: set_allocation is deprecated in 1.1.4 */
22 if (set_allocation && !sink->next_uint32 (sink, len))
23 return FALSE;
24
25 return TRUE;
26}
27
28static gboolean
29sink_next_uint16 (SerialSink* sink, guint16 num)
30{
31 num = g_htons (num);
32
33 return sink->sink_write (sink, (guint8*) &num, sizeof (num));
34}
35
36static gboolean
37sink_next_uint32 (SerialSink* sink, guint32 num)
38{
39 num = g_htonl (num);
40
41 return sink->sink_write (sink, (guint8*) &num, sizeof (num));
42}
43
44static gboolean
45sink_next_uint (SerialSink* sink, guint32 num)
46{
47 /* This is mostly because I dislike endian, and less to save space
48 * on small ints. However, the uint32 and uint16 functions are used
49 * when the number is expected to be large, in which case this
50 * format can expand the number. */
51
52 guint8 sink_buf[16]; /* this is enough room for a 12-byte int */
53 guint sink_count = 0;
54
55 do
56 {
57 guint left = num & 0x7f;
58 guint outnum;
59
60 num >>= 7;
61
62 outnum = left | (num ? 0x80 : 0);
63
64 sink_buf[sink_count++] = outnum;
65 }
66 while (num);
67
68 return sink->sink_write (sink, sink_buf, sink_count);
69}
70
71static gboolean
72sink_next_uint8 (SerialSink* sink, guint8 val)
73{
74 return sink->sink_write (sink, &val, 1);
75}
76
77static gboolean
78sink_next_bool (SerialSink* sink, gboolean val)
79{
80 guint8 sink_buf[1];
81 sink_buf[0] = val;
82 return sink->sink_write (sink, sink_buf, 1);
83}
84
85static gboolean
86sink_next_string (SerialSink* sink, const char *ptr)
87{
88 return sink->next_bytes (sink, ptr, strlen (ptr));
89}
90
91static gboolean
92sink_next_bytes (SerialSink* sink, const guint8 *ptr, guint32 len)
93{
94 return sink->next_uint (sink, len) &&
95 sink->sink_write (sink, ptr, len);
96}
97
98static gboolean
99sink_next_bytes_known (SerialSink* sink, const guint8 *ptr, guint32 len)
100{
101 return sink->sink_write (sink, ptr, len);
102}
103
104void
105serializeio_sink_init (SerialSink* it,
106 gboolean (* sink_type) (SerialSink* sink,
107 SerialType type,
108 guint32 mem_size,
109 gboolean set_allocation),
110 gboolean (* sink_close) (SerialSink* sink),
111 gboolean (* sink_write) (SerialSink* sink,
112 const guint8 *ptr,
113 guint32 len),
114 void (* sink_free) (SerialSink* sink),
115 gboolean (* sink_quantum) (SerialSink* sink))
116{
117 it->next_bytes_known = sink_next_bytes_known;
118 it->next_bytes = sink_next_bytes;
119 it->next_uint = sink_next_uint;
120 it->next_uint32 = sink_next_uint32;
121 it->next_uint16 = sink_next_uint16;
122 it->next_uint8 = sink_next_uint8;
123 it->next_bool = sink_next_bool;
124 it->next_string = sink_next_string;
125
126 if (sink_type)
127 it->sink_type = sink_type;
128 else
129 it->sink_type = sink_type_default;
130
131 it->sink_close = sink_close;
132 it->sink_write = sink_write;
133 it->sink_free = sink_free;
134 it->sink_quantum = sink_quantum;
135}
136
137/* Default Source methods
138 */
139
140static SerialType
141source_type_default (SerialSource* source, gboolean set_allocation)
142{
143 guint32 x;
144
145 if (! source->next_uint32 (source, & x))
146 return ST_Error;
147
148 if (set_allocation)
149 {
150 /* Note: set_allocation is deprecated in 1.1.4 */
151 guint32 bogus;
152 if (! source->next_uint32 (source, &bogus))
153 return ST_Error;
154 }
155
156 return x;
157}
158
159static gboolean
160source_next_uint32 (SerialSource* source, guint32 *ptr)
161{
162 guint32 x;
163
164 if (! source->source_read (source, (guint8*) &x, sizeof (x)))
165 return FALSE;
166
167 (*ptr) = g_ntohl (x);
168
169 return TRUE;
170}
171
172static gboolean
173source_next_uint16 (SerialSource* source, guint16 *ptr)
174{
175 guint16 x;
176
177 if (! source->source_read (source, (guint8*) &x, sizeof (x)))
178 return FALSE;
179
180 (*ptr) = g_ntohs (x);
181
182 return TRUE;
183}
184
185static gboolean
186source_next_uint (SerialSource* source, guint32 *ptr)
187{
188 /* This is mostly because I dislike endian, and less to save space
189 * on small ints */
190 guint8 c;
191 guint8 arr[16];
192 gint i = 0;
193 gint donebit = 1;
194 gint bits;
195
196 while (source->next_uint8 (source, &c))
197 {
198 donebit = c & 0x80;
199 bits = c & 0x7f;
200
201 arr[i++] = bits;
202
203 if (!donebit)
204 break;
205 }
206
207 if (donebit)
208 return FALSE;
209
210 *ptr = 0;
211
212 for (i -= 1; i >= 0; i -= 1)
213 {
214 *ptr <<= 7;
215 *ptr |= arr[i];
216 }
217
218 return TRUE;
219}
220
221static gboolean
222source_next_uint8 (SerialSource* source, guint8 *ptr)
223{
224 return source->source_read (source, ptr, 1);
225}
226
227static gboolean
228source_next_bool (SerialSource* source, gboolean *ptr)
229{
230 guint8 sink_buf[1];
231
232 if (! source->source_read (source, sink_buf, 1))
233 return FALSE;
234
235 if (sink_buf[0])
236 *ptr = TRUE;
237 else
238 *ptr = FALSE;
239
240 return TRUE;
241}
242
243static gboolean
244source_next_string (SerialSource* source, const char **ptr)
245{
246 guint32 len;
247 guint8* buf;
248
249 if (! source->next_uint (source, &len))
250 return FALSE;
251
252 if (! (buf = serializeio_source_alloc (source, len+1)))
253 return FALSE;
254
255 buf[len] = 0;
256
257 (*ptr) = buf;
258
259 return source->source_read (source, buf, len);
260}
261
262static gboolean
263source_next_bytes (SerialSource* source, const guint8 **ptr, guint32 *len_ptr)
264{
265 guint32 len;
266 guint8* buf;
267
268 if (! source->next_uint (source, &len))
269 return FALSE;
270
271 if (! (buf = serializeio_source_alloc (source, len)))
272 return FALSE;
273
274 (*len_ptr) = len;
275 (*ptr) = buf;
276
277 return source->source_read (source, buf, len);
278}
279
280static gboolean
281source_next_bytes_known (SerialSource* source, guint8 *ptr, guint32 len)
282{
283 return source->source_read (source, ptr, len);
284}
285
286void*
287serializeio_source_alloc (SerialSource* source, guint32 len)
288{
289 AllocList *al;
290 void* ret;
291
292 if (source->salloc_func)
293 {
294 ret = source->salloc_func (source, len);
295 al = source->salloc_func (source, sizeof(AllocList));
296 }
297 else
298 {
299 ret = g_malloc0 (len);
300 al = g_malloc0 (sizeof(AllocList));
301 }
302
303 al->ptr = ret;
304 al->next = source->alloc_list;
305 source->alloc_list = al;
306
307 return ret;
308}
309
310void
311serializeio_source_init (SerialSource* it,
312 SerialType (* source_type) (SerialSource* source,
313 gboolean set_allocation),
314 gboolean (* source_close) (SerialSource* source),
315 gboolean (* source_read) (SerialSource* source,
316 guint8 *ptr,
317 guint32 len),
318 void (* source_free) (SerialSource* source),
319 void* (* salloc_func) (SerialSource* source,
320 guint32 len),
321 void (* sfree_func) (SerialSource* source,
322 void* ptr))
323{
324 it->alloc_list = NULL;
325 it->next_bytes_known = source_next_bytes_known;
326 it->next_bytes = source_next_bytes;
327 it->next_uint = source_next_uint;
328 it->next_uint32 = source_next_uint32;
329 it->next_uint16 = source_next_uint16;
330 it->next_uint8 = source_next_uint8;
331 it->next_bool = source_next_bool;
332 it->next_string = source_next_string;
333
334 if (source_type != NULL)
335 it->source_type = source_type;
336 else
337 it->source_type = source_type_default;
338 it->source_close = source_close;
339 it->source_read = source_read;
340 it->source_free = source_free;
341 it->salloc_func = salloc_func;
342 it->sfree_func = sfree_func;
343}
diff --git a/xdelta1/libedsio/edsio-comp.in b/xdelta1/libedsio/edsio-comp.in
deleted file mode 100644
index 51b55d7..0000000
--- a/xdelta1/libedsio/edsio-comp.in
+++ /dev/null
@@ -1,46 +0,0 @@
1#!/bin/sh
2
3# Derived from:
4
5# Copyright (C) 1995 Free Software Foundation, Inc.
6# François Pinard <pinard@iro.umontreal.ca>, 1995.
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2, or (at your option)
11# any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program; if not, write to the Free Software
20# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
22EMACS=@EMACS@
23TOP_SRCDIR=@top_srcdir_absolute@/libedsio
24
25SCRIPT=$TMPDIR/script.$$
26
27trap "rm -f $SCRIPT" 0
28
29if test $# != 1; then
30 echo 1>&2 "usage: $0 INPUT"
31 exit 1
32else
33 if test -z "$EMACS" || test "$EMACS" = "t"; then
34 # Value of "t" means we are running in a shell under Emacs.
35 # Just assume Emacs is called "emacs".
36 EMACS=emacs
37 fi
38
39 INPUT=$1
40 INPUT_PREF=`echo $INPUT | sed 's/\.[^\.]*$//'`
41
42 echo "(load-file \"$TOP_SRCDIR/edsio.el\") " \
43 "(generate-ser \"$INPUT\" \"$INPUT_PREF\")" > $SCRIPT
44
45 $EMACS --batch -l $SCRIPT
46fi
diff --git a/xdelta1/libedsio/edsio.c b/xdelta1/libedsio/edsio.c
deleted file mode 100644
index 4d110f6..0000000
--- a/xdelta1/libedsio/edsio.c
+++ /dev/null
@@ -1,1610 +0,0 @@
1/* -*-Mode: C;-*-
2 * $Id: edsio.c 1.1 Sun, 28 Jan 2007 10:02:26 -0800 jmacd $
3 *
4 * Copyright (C) 1998, 1999, Josh MacDonald.
5 * All Rights Reserved.
6 *
7 * Author: Josh MacDonald <jmacd@CS.Berkeley.EDU>
8 */
9
10#include "edsio.h"
11#include <stdio.h>
12
13#if TIME_WITH_SYS_TIME
14# include <sys/time.h>
15# include <time.h>
16#else
17# if HAVE_SYS_TIME_H
18# include <sys/time.h>
19# else
20# include <time.h>
21# endif
22#endif
23
24#include "maketime.h"
25
26/*#define DEBUG_PROPS*/
27
28/* Event delivery
29 */
30
31static GHashTable* all_event_defs = NULL;
32
33static GPtrArray* all_event_watchers = NULL;
34
35typedef struct _ErrorDeliveryWatcher ErrorDeliveryWatcher;
36typedef struct _DelayedEvent DelayedEvent;
37
38struct _ErrorDeliveryWatcher {
39 ErrorDeliveryFunc deliver;
40};
41
42struct _DelayedEvent {
43 GenericEvent ev;
44 GenericEventDef *def;
45 const char *msg;
46};
47
48void
49eventdelivery_initialize_event_def (gint code,
50 gint level,
51 gint flags,
52 const char* name,
53 const char* oneline,
54 const char * (* field_to_string) (GenericEvent* ev, gint field))
55{
56 GenericEventDef* def = g_new0 (GenericEventDef, 1);
57
58 if (! all_event_defs)
59 all_event_defs = g_hash_table_new (g_int_hash, g_int_equal);
60
61 def->code = code;
62 def->level = level;
63 def->flags = flags;
64 def->name = name;
65 def->oneline = oneline;
66 def->field_to_string = field_to_string;
67
68 g_hash_table_insert (all_event_defs, & def->code, def);
69}
70
71void
72eventdelivery_event_watch_all (ErrorDeliveryFunc func)
73{
74 ErrorDeliveryWatcher* w = g_new0 (ErrorDeliveryWatcher, 1);
75
76 w->deliver = func;
77
78 if (! all_event_watchers)
79 all_event_watchers = g_ptr_array_new ();
80
81 g_ptr_array_add (all_event_watchers, w);
82}
83
84GenericEventDef*
85eventdelivery_event_lookup (gint code)
86{
87 return g_hash_table_lookup (all_event_defs, & code);
88}
89
90void
91eventdelivery_event_deliver (GenericEvent* e)
92{
93 static gint in_call = FALSE;
94 static GQueue* queued = NULL;
95 static GPtrArray* free_strings = NULL;
96
97 if (! queued)
98 {
99 queued = g_queue_new ();
100 free_strings = g_ptr_array_new ();
101 }
102
103 in_call += 1;
104
105 g_assert (e);
106
107 edsio_edsio_init ();
108
109 if (all_event_defs)
110 {
111 GenericEventDef* def = g_hash_table_lookup (all_event_defs, & e->code);
112
113 if (def)
114 {
115 GString* out;
116 const char* oneline = def->oneline;
117 char c;
118
119 out = g_string_new (NULL);
120
121 while ((c = *oneline++))
122 {
123 switch (c)
124 {
125 case '$':
126 {
127 const char* field;
128 char *end;
129 int f;
130
131 if ((*oneline++) != '{')
132 goto badevent;
133
134 f = strtol (oneline, &end, 10);
135
136 if (f < 0 || !end || end[0] != '}')
137 goto badevent;
138
139 oneline = end+1;
140
141 g_assert (def->field_to_string);
142
143 field = def->field_to_string (e, f);
144
145 if (field)
146 {
147 g_string_append (out, field);
148
149 g_free ((void*) field);
150 }
151 else
152 goto badevent;
153 }
154 break;
155 default:
156 g_string_append_c (out, c);
157 }
158 }
159
160 if (! all_event_watchers)
161 {
162 fprintf (stderr, "%s:%d: %s\n", e->srcfile, e->srcline, out->str);
163
164 g_string_free (out, TRUE);
165 }
166 else if (in_call == 1)
167 {
168 gint i;
169
170 for (i = 0; i < all_event_watchers->len; i += 1)
171 {
172 ErrorDeliveryWatcher* w = all_event_watchers->pdata[i];
173
174 if (! w->deliver (e, def, out->str))
175 {
176 g_warning ("%s:%d: An error delivery routine failed: %s\n", e->srcfile, e->srcline, out->str);
177 in_call = 0;
178 return;
179 }
180 }
181
182 while (g_queue_get_size (queued) > 0)
183 {
184 DelayedEvent* de = g_queue_pop (queued);
185
186 for (i = 0; i < all_event_watchers->len; i += 1)
187 {
188 ErrorDeliveryWatcher* w = all_event_watchers->pdata[i];
189
190 if (! w->deliver (& de->ev, de->def, de->msg))
191 {
192 g_warning ("%s:%d: An error delivery routine failed: %s\n", e->srcfile, e->srcline, out->str);
193 in_call = 0;
194 return;
195 }
196 }
197 }
198
199 for (i = 0; i < free_strings->len; i += 1)
200 g_string_free (free_strings->pdata[i], TRUE);
201
202 g_ptr_array_set_size (free_strings, 0);
203
204 g_string_free (out, TRUE);
205 }
206 else
207 {
208 DelayedEvent* de = g_new (DelayedEvent, 1);
209
210 de->ev = *e;
211 de->def = def;
212 de->msg = out->str;
213
214 g_queue_push (queued, de);
215
216 g_ptr_array_add (free_strings, out);
217 }
218
219 in_call -= 1;
220
221 return;
222 }
223 }
224
225 g_warning ("%s:%d: Unrecognized event delivered (code=%d)\n", e->srcfile, e->srcline, e->code);
226
227 in_call -= 1;
228
229 return;
230
231 badevent:
232
233 g_warning ("%s:%d: An malformed error could not print here (code=%d)\n", e->srcfile, e->srcline, e->code);
234
235 in_call -= 1;
236
237 return;
238}
239
240const char*
241eventdelivery_int_to_string (int x)
242{
243 return g_strdup_printf ("%d", x);
244}
245
246const char*
247eventdelivery_string_to_string (const char* x)
248{
249 return g_strdup (x);
250}
251
252const char*
253eventdelivery_source_to_string (SerialSource* x)
254{
255 return g_strdup ("@@@SerialSource");
256}
257
258const char*
259eventdelivery_sink_to_string (SerialSink* x)
260{
261 return g_strdup ("@@@SerialSink");
262}
263
264const char*
265eventdelivery_handle_to_string (FileHandle* x)
266{
267 g_return_val_if_fail (x, g_strdup ("*error*"));
268
269 return x->table->table_handle_name (x);
270}
271
272/* Misc crap.
273 */
274
275gboolean
276edsio_time_of_day (SerialGenericTime* setme)
277{
278#if HAVE_GETTIMEOFDAY
279
280 struct timeval tv;
281
282 if (gettimeofday (& tv, NULL))
283 {
284 edsio_generate_errno_event (EC_EdsioGetTimeOfDayFailure);
285 goto bail;
286 }
287
288 if (setme)
289 {
290 setme->nanos = tv.tv_usec * 1000;
291 setme->seconds = tv.tv_sec;
292 }
293
294#else
295
296 struct timeval tv;
297 time_t t = time (NULL);
298
299 if (t < 0)
300 {
301 edsio_generate_errno_event (EC_EdsioTimeFailure);
302 goto bail;
303 }
304
305 if (setme)
306 {
307 setme->nanos = 0;
308 setme->seconds = tv.tv_sec;
309 }
310
311#endif
312
313 return TRUE;
314
315 bail:
316
317 setme->nanos = 0;
318 setme->seconds = 10;
319
320 return FALSE;
321}
322
323gchar*
324edsio_time_to_iso8601 (SerialGenericTime *tp)
325{
326 return edsio_time_t_to_iso8601 (tp->seconds);
327}
328
329gchar*
330edsio_time_t_to_iso8601 (GTime t0)
331{
332 static char timebuf[64];
333 time_t t = t0;
334
335 struct tm lt = *localtime(&t);
336 int utc_offset = difftm(&lt, gmtime(&t));
337 char sign = utc_offset < 0 ? '-' : '+';
338 int minutes = abs (utc_offset) / 60;
339 int hours = minutes / 60;
340
341 sprintf(timebuf,
342 "%d-%02d-%02d %02d:%02d:%02d%c%02d%02d",
343 lt.tm_year + 1900,
344 lt.tm_mon + 1,
345 lt.tm_mday,
346 lt.tm_hour,
347 lt.tm_min,
348 lt.tm_sec,
349 sign,
350 hours,
351 minutes % 60);
352
353 return timebuf;
354}
355
356static gboolean
357strtosl_checked (const char* str, long* l, const char* errmsg)
358{
359 char* end;
360
361 (*l) = strtol (str, &end, 10);
362
363 if (!end || end[0])
364 {
365 if (errmsg)
366 edsio_generate_stringstring_event (EC_EdsioInvalidIntegerString, errmsg, str);
367
368 (*l) = 0;
369 return FALSE;
370 }
371
372 return TRUE;
373}
374
375gboolean
376strtosi_checked (const char* str, gint32* i, const char* errmsg)
377{
378 long l;
379
380 if (! strtosl_checked (str, &l, errmsg))
381 {
382 (*i) = 0;
383 return FALSE;
384 }
385
386 if (l > G_MAXINT || l < G_MININT)
387 {
388 if (errmsg)
389 edsio_generate_stringstring_event (EC_EdsioIntegerOutOfRange, errmsg, str);
390
391 (*i) = 0;
392 return FALSE;
393 }
394
395 (*i) = l;
396
397 return TRUE;
398}
399
400gboolean
401strtoss_checked (const char* str, gint16* i, const char* errmsg)
402{
403 long l;
404
405 if (! strtosl_checked (str, &l, errmsg))
406 {
407 (*i) = 0;
408 return FALSE;
409 }
410
411 if (l > G_MAXSHORT || l < G_MINSHORT)
412 {
413 if (errmsg)
414 edsio_generate_stringstring_event (EC_EdsioIntegerOutOfRange, errmsg, str);
415
416 (*i) = 0;
417 return FALSE;
418 }
419
420 (*i) = l;
421
422 return TRUE;
423}
424
425gboolean
426strtoui_checked (const char* str, guint32* i, const char* errmsg)
427{
428 long l;
429
430 if (! strtosl_checked (str, &l, errmsg))
431 {
432 (*i) = 0;
433 return FALSE;
434 }
435
436 if (l < 0)
437 {
438 if (errmsg)
439 edsio_generate_stringstring_event (EC_EdsioInvalidIntegerSign, errmsg, str);
440
441 (*i) = 0;
442 return FALSE;
443 }
444
445 (*i) = l;
446
447 if (l != (*i))
448 {
449 if (errmsg)
450 edsio_generate_stringstring_event (EC_EdsioIntegerOutOfRange, errmsg, str);
451
452 (*i) = 0;
453 return FALSE;
454 }
455
456 return TRUE;
457}
458
459gboolean
460strtous_checked (const char* str, guint16* i, const char* errmsg)
461{
462 long l;
463
464 if (! strtosl_checked (str, &l, errmsg))
465 {
466 (*i) = 0;
467 return FALSE;
468 }
469
470 if (l < 0)
471 {
472 if (errmsg)
473 edsio_generate_stringstring_event (EC_EdsioInvalidIntegerSign, errmsg, str);
474
475 (*i) = 0;
476 return FALSE;
477 }
478
479 (*i) = l;
480
481 if (l != (*i))
482 {
483 if (errmsg)
484 edsio_generate_stringstring_event (EC_EdsioIntegerOutOfRange, errmsg, str);
485
486 (*i) = 0;
487 return FALSE;
488 }
489
490 return TRUE;
491}
492
493gint
494edsio_md5_equal (gconstpointer v,
495 gconstpointer v2)
496{
497 return memcmp (v, v2, 16) == 0;
498}
499
500guint
501edsio_md5_hash (gconstpointer v)
502{
503 guint8* md5 = (guint8*) v;
504 guint x = 0;
505 gint i, j;
506
507 for (i = 0, j = 0; i < 16; i += 1, j += 1, j %= sizeof (guint32))
508 x ^= md5[i] << (8*j);
509
510 return x;
511}
512
513void
514serializeio_print_bytes (const guint8* bytes, guint len0)
515{
516 char buf[100];
517 int i;
518 guint len;
519
520 len = MIN (len0, 32);
521
522 for (i = 0; i < len; i += 1)
523 sprintf (buf + 2*i, "%02x", bytes[i]);
524
525 if (len0 > len)
526 strcat (buf, "...");
527
528 g_print ("%s\n", buf);
529}
530
531void
532edsio_md5_to_string (const guint8* md5, char buf[33])
533{
534 gint i;
535
536 for (i = 0; i < 16; i += 1)
537 sprintf (buf + 2*i, "%02x", md5[i]);
538}
539
540static gboolean
541from_hex (char c, int* x, const char* ctx)
542{
543 char buf[2];
544
545 if (c >= '0' && c <= '9')
546 {
547 (*x) = c - '0';
548 return TRUE;
549 }
550 else if (c >= 'A' && c <= 'F')
551 {
552 (*x) = c - 'A' + 10;
553 return TRUE;
554 }
555 else if (c >= 'a' && c <= 'f')
556 {
557 (*x) = c - 'a' + 10;
558 return TRUE;
559 }
560
561 buf[0] = c;
562 buf[1] = 0;
563
564 edsio_generate_stringstring_event (EC_EdsioInvalidHexDigit, buf, ctx);
565 return FALSE;
566}
567
568gboolean
569edsio_md5_from_string (guint8* md5, const char buf[33])
570{
571 gint i;
572 gint l = strlen (buf);
573
574 if (l < 32)
575 {
576 edsio_generate_string_event (EC_EdsioMD5StringShort, buf);
577 return FALSE;
578 }
579 else if (l > 32)
580 {
581 edsio_generate_string_event (EC_EdsioMD5StringLong, buf);
582 return FALSE;
583 }
584
585 for (i = 0; i < 16; i += 1)
586 {
587 char c1 = buf[(2*i)];
588 char c2 = buf[(2*i)+1];
589 int x1, x2;
590
591 if (! from_hex (c1, &x1, buf))
592 return FALSE;
593
594 if (! from_hex (c2, &x2, buf))
595 return FALSE;
596
597 md5[i] = (x1 << 4) | x2;
598 }
599
600 return TRUE;
601}
602
603/* Strings
604 */
605
606const char* edsio_intern_string (const char* str)
607{
608 static GStringChunk* chunk = NULL;
609
610 if (! chunk)
611 chunk = g_string_chunk_new (256);
612
613 return g_string_chunk_insert_const (chunk, str);
614}
615
616/* Properties
617 */
618
619typedef struct _EdsioHostType EdsioHostType;
620typedef struct _EdsioPropertyType EdsioPropertyType;
621
622struct _EdsioPropertyType {
623 const char *type_name;
624 PropFreeFunc freer;
625 PropGSFunc getter;
626 PropGSFunc setter;
627 PropSerialize serialize;
628 PropUnserialize unserialize;
629};
630
631struct _EdsioHostType {
632 const char *host_name;
633 PropertyTableFunc ptable;
634 PersistSourceFunc source;
635 PersistSinkFunc sink;
636 PersistIssetFunc isset;
637 PersistUnsetFunc unset;
638};
639
640struct _EdsioProperty {
641 guint32 prop_code;
642 const char *prop_name;
643 guint32 prop_flags;
644 EdsioPropertyType *type;
645 EdsioHostType *host;
646};
647
648union _EdsioPropertyEntry {
649 guint32 as_uint32;
650 SerialEdsioBytes as_bytes;
651 gpointer as_vptr;
652 const char* as_string;
653};
654
655struct _EdsioGenericProperty
656{
657 guint32 code;
658};
659
660static GHashTable* all_property_types = NULL;
661static GHashTable* all_host_types = NULL;
662static GHashTable* all_properties = NULL;
663static GHashTable* all_property_codes = NULL;
664static guint32 property_code_sequence = 0;
665
666void
667edsio_initialize_property_type (const char* t, PropFreeFunc freer, PropGSFunc getter, PropGSFunc setter, PropSerialize ser, PropUnserialize unser)
668{
669 EdsioPropertyType* type;
670
671 t = edsio_intern_string (t);
672
673 if (! all_property_types)
674 all_property_types = g_hash_table_new (g_direct_hash, g_direct_equal);
675
676 if ((type = g_hash_table_lookup (all_property_types, t)) != NULL)
677 {
678 if (getter != type->getter ||
679 setter != type->setter ||
680 ser != type->serialize ||
681 unser != type->unserialize)
682 edsio_generate_string_event (EC_EdsioDuplicatePropertyTypeRegistered, t);
683 return;
684 }
685
686 type = g_new0 (EdsioPropertyType, 1);
687
688 type->type_name = t;
689 type->freer = freer;
690 type->getter = getter;
691 type->setter = setter;
692 type->serialize = ser;
693 type->unserialize = unser;
694
695 g_hash_table_insert (all_property_types, (gpointer) t, type);
696}
697
698void
699edsio_initialize_host_type (const char* ph,
700 PropertyTableFunc ptable,
701 PersistSourceFunc source,
702 PersistSinkFunc sink,
703 PersistIssetFunc isset,
704 PersistUnsetFunc unset)
705{
706 EdsioHostType* host;
707
708 ph = edsio_intern_string (ph);
709
710 if (! all_host_types)
711 all_host_types = g_hash_table_new (g_direct_hash, g_direct_equal);
712
713 if (g_hash_table_lookup (all_host_types, ph))
714 {
715 edsio_generate_string_event (EC_EdsioDuplicateHostTypeRegistered, ph);
716 return;
717 }
718
719 host = g_new0 (EdsioHostType, 1);
720
721 host->host_name = ph;
722 host->ptable = ptable;
723 host->source = source;
724 host->sink = sink;
725 host->isset = isset;
726 host->unset = unset;
727
728 g_hash_table_insert (all_host_types, (gpointer) ph, host);
729
730}
731
732gboolean
733edsio_new_property (const char* name, const char* ph, const char* t, guint32 flags, EdsioGenericProperty *ret_prop)
734{
735 EdsioProperty* prop;
736 EdsioPropertyType* type;
737 EdsioHostType* host;
738
739 name = edsio_intern_string (name);
740 ph = edsio_intern_string (ph);
741 t = edsio_intern_string (t);
742
743 g_assert (all_property_types);
744
745 if (! all_properties)
746 {
747 all_properties = g_hash_table_new (g_direct_hash, g_direct_equal);
748 all_property_codes = g_hash_table_new (g_int_hash, g_int_equal);
749 }
750
751 if ((prop = g_hash_table_lookup (all_properties, name)) != NULL)
752 {
753 edsio_generate_string_event (EC_EdsioDuplicatePropertyNameRegistered, name);
754 ret_prop->code = prop->prop_code;
755 return TRUE;
756 }
757
758 if ((type = g_hash_table_lookup (all_property_types, t)) == NULL)
759 {
760 edsio_generate_string_event (EC_EdsioNoSuchPropertyType, t);
761 return FALSE;
762 }
763
764 if ((host = g_hash_table_lookup (all_host_types, ph)) == NULL)
765 {
766 edsio_generate_string_event (EC_EdsioNoSuchHostType, ph);
767 return FALSE;
768 }
769
770 if (flags & PF_Persistent && ! host->isset)
771 {
772 edsio_generate_stringstring_event (EC_EdsioPersistenceUnavailable, name, ph);
773 return FALSE;
774 }
775
776 prop = g_new0 (EdsioProperty, 1);
777
778 prop->prop_code = ++property_code_sequence;
779 prop->prop_name = name;
780 prop->prop_flags = flags;
781 prop->type = type;
782 prop->host = host;
783
784 g_hash_table_insert (all_properties, (gpointer) name, prop);
785 g_hash_table_insert (all_property_codes, & prop->prop_code, prop);
786
787 ret_prop->code = prop->prop_code;
788
789 return TRUE;
790}
791
792static EdsioProperty*
793edsio_property_find (const char* ph, const char* t, guint32 code)
794{
795 EdsioProperty* prop;
796
797 ph = edsio_intern_string (ph);
798 t = edsio_intern_string (t);
799
800 if (code <= 0 || code > property_code_sequence)
801 {
802 edsio_generate_int_event (EC_EdsioNoSuchProperty, code);
803 return NULL;
804 }
805
806 if (! (prop = g_hash_table_lookup (all_property_codes, & code)))
807 {
808 edsio_generate_int_event (EC_EdsioNoSuchProperty, code);
809 return NULL;
810 }
811
812 if (prop->host->host_name != ph)
813 {
814 edsio_generate_stringstringstring_event (EC_EdsioWrongHostType, prop->prop_name, ph, prop->host->host_name);
815 return NULL;
816 }
817
818 if (prop->type->type_name != t)
819 {
820 edsio_generate_stringstringstring_event (EC_EdsioWrongDataType, prop->prop_name, t, prop->type->type_name);
821 return NULL;
822 }
823
824 return prop;
825}
826
827EdsioPropertyEntry*
828edsio_property_get (gpointer obj, EdsioProperty* prop)
829{
830 EdsioPropertyEntry* ent;
831 GHashTable* table = * prop->host->ptable (obj);
832 gboolean persist = prop->prop_flags & PF_Persistent;
833
834#ifdef DEBUG_PROPS
835 g_print ("get %p.%s\n", obj, prop->prop_name);
836#endif
837
838 if (table && (ent = g_hash_table_lookup (table, & prop->prop_code)) != NULL)
839 return ent;
840
841 if (persist)
842 {
843 SerialSource* src;
844
845 if (! (src = prop->host->source (obj, prop->prop_name)))
846 return NULL;
847
848 g_assert (prop->type->unserialize);
849
850 if (! prop->type->unserialize (src, & ent))
851 return NULL;
852
853 g_assert (ent);
854
855 if (! src->source_close (src))
856 return NULL;
857
858 src->source_free (src);
859
860 if (! table)
861 table = (* prop->host->ptable (obj)) = g_hash_table_new (g_int_hash, g_int_equal);
862
863 g_hash_table_insert (table, & prop->prop_code, ent);
864
865 return ent;
866 }
867
868 edsio_generate_string_event (EC_EdsioPropertyNotSet, prop->prop_name);
869 return NULL;
870}
871
872gboolean
873edsio_property_set (gpointer obj, EdsioProperty* prop, EdsioPropertyEntry* set)
874{
875 EdsioPropertyEntry* ent;
876 gboolean persist = prop->prop_flags & PF_Persistent;
877 GHashTable* table = * prop->host->ptable (obj);
878
879#ifdef DEBUG_PROPS
880 g_print ("set %p.%s\n", obj, prop->prop_name);
881#endif
882
883 if (! table)
884 table = (* prop->host->ptable (obj)) = g_hash_table_new (g_int_hash, g_int_equal);
885
886 ent = g_hash_table_lookup (table, & prop->prop_code);
887
888 if (ent)
889 {
890 g_hash_table_remove (table, & prop->prop_code);
891 prop->type->freer (ent);
892 }
893
894 g_hash_table_insert (table, & prop->prop_code, set);
895
896 if (persist)
897 {
898 SerialSink* sink;
899
900 if (! (sink = prop->host->sink (obj, prop->prop_name)))
901 return FALSE;
902
903 g_assert (prop->type->serialize);
904
905 if (! prop->type->serialize (sink, set))
906 return FALSE;
907
908 if (! sink->sink_close (sink))
909 return FALSE;
910
911 sink->sink_free (sink);
912 }
913
914 return TRUE;
915}
916
917gboolean
918edsio_property_isset (const char* ph, const char* t, guint32 code, gpointer obj)
919{
920 EdsioProperty* prop;
921 GHashTable* table;
922 gboolean persist;
923 gboolean result = FALSE;
924
925 if (! (prop = edsio_property_find (ph, t, code)))
926 goto done;
927
928 persist = prop->prop_flags & PF_Persistent;
929
930 table = * prop->host->ptable (obj);
931
932 if (persist)
933 {
934 PersistIssetFunc issetfunc = prop->host->isset;
935 if (issetfunc(obj, prop->prop_name))
936 {
937 if (! edsio_property_get (obj, prop))
938 goto done;
939
940 table = * prop->host->ptable (obj);
941 }
942 }
943
944 if (! table)
945 goto done;
946
947 result = (g_hash_table_lookup (table, & code) != NULL);
948
949 done:
950
951#ifdef DEBUG_PROPS
952 g_print ("isset %p.%s = %s\n", obj, prop->prop_name, result ? "true" : "false");
953#endif
954
955 return result;
956}
957
958gboolean
959edsio_property_unset (const char* ph, const char* t, guint32 code, gpointer obj)
960{
961 EdsioProperty* prop;
962 gboolean persist;
963 GHashTable* table;
964
965 if (! (prop = edsio_property_find (ph, t, code)))
966 return FALSE;
967
968#ifdef DEBUG_PROPS
969 g_print ("unset %p.%s\n", obj, prop->prop_name);
970#endif
971
972 persist = prop->prop_flags & PF_Persistent;
973 table = * prop->host->ptable (obj);
974
975 if (table)
976 {
977 EdsioPropertyEntry* ent;
978
979 ent = g_hash_table_lookup (table, & code);
980
981 g_hash_table_remove (table, & code);
982
983 if (g_hash_table_size (table) == 0)
984 {
985 g_hash_table_destroy (table);
986 table = (* prop->host->ptable (obj)) = NULL;
987 }
988
989 /*g_free (ent);*/
990 }
991
992 if (persist)
993 {
994 if (! prop->host->unset (obj, prop->prop_name))
995 return FALSE;
996 }
997
998 return TRUE;
999}
1000
1001static gboolean
1002edsio_false ()
1003{
1004 return FALSE;
1005}
1006
1007PropGSFunc
1008edsio_property_getter (const char* ph, const char* t, guint32 code, EdsioProperty** ep)
1009{
1010 if (! ((*ep) = edsio_property_find (ph, t, code)))
1011 return & edsio_false;
1012
1013 return (* ep)->type->getter;
1014}
1015
1016PropGSFunc
1017edsio_property_setter (const char* ph, const char* t, guint32 code, EdsioProperty** ep)
1018{
1019 if (! ((* ep) = edsio_property_find (ph, t, code)))
1020 return & edsio_false;
1021
1022 return (* ep)->type->setter;
1023}
1024
1025/* Primitive type serializers
1026 */
1027
1028/* integer
1029 */
1030gboolean
1031edsio_property_uint_getter (gpointer obj, EdsioProperty* prop, guint32* get)
1032{
1033 EdsioPropertyEntry *ent;
1034
1035 if (! (ent = edsio_property_get (obj, prop)))
1036 return FALSE;
1037
1038 (*get) = ent->as_uint32;
1039
1040 return TRUE;
1041}
1042
1043gboolean
1044edsio_property_uint_setter (gpointer obj, EdsioProperty* prop, guint32 set)
1045{
1046 EdsioPropertyEntry *ent = g_new (EdsioPropertyEntry, 1);
1047
1048 ent->as_uint32 = set;
1049
1050 return edsio_property_set (obj, prop, ent);
1051}
1052
1053void
1054edsio_property_uint_free (gpointer obj)
1055{
1056 g_free (obj);
1057}
1058
1059gboolean
1060unserialize_uint (SerialSource *source, guint32** x)
1061{
1062 SerialEdsioUint *s;
1063 guint32 *n;
1064
1065 if (! unserialize_edsiouint (source, & s))
1066 return FALSE;
1067
1068 n = g_new (guint32, 1);
1069
1070 (* x) = n;
1071
1072 (* n) = s->val;
1073
1074 g_free (s);
1075
1076 return TRUE;
1077}
1078
1079gboolean
1080serialize_uint_obj (SerialSink *sink, guint32* x)
1081{
1082 return serialize_edsiouint (sink, *x);
1083}
1084
1085/* String
1086 */
1087
1088void
1089edsio_property_string_free (gpointer obj)
1090{
1091 g_free (obj);
1092}
1093
1094gboolean
1095edsio_property_string_getter (gpointer obj, EdsioProperty* prop, const char** get)
1096{
1097 if (! ((*get) = (const char*) edsio_property_get (obj, prop)))
1098 return FALSE;
1099
1100 return TRUE;
1101}
1102
1103gboolean
1104edsio_property_string_setter (gpointer obj, EdsioProperty* prop, const char* set)
1105{
1106 return edsio_property_set (obj, prop, (EdsioPropertyEntry*) set);
1107}
1108
1109gboolean
1110unserialize_string (SerialSource *source, const char** x)
1111{
1112 SerialEdsioString *s;
1113
1114 if (! unserialize_edsiostring (source, & s))
1115 return FALSE;
1116
1117 (*x) = g_strdup (s->val);
1118
1119 g_free (s);
1120
1121 return TRUE;
1122}
1123
1124gboolean
1125serialize_string_obj (SerialSink *sink, const char* x)
1126{
1127 return serialize_edsiostring (sink, x);
1128}
1129
1130/* Bytes
1131 */
1132
1133gboolean
1134unserialize_bytes (SerialSource *source, SerialEdsioBytes** x)
1135{
1136 return unserialize_edsiobytes (source, x);
1137}
1138
1139gboolean
1140serialize_bytes_obj (SerialSink *sink, SerialEdsioBytes *x)
1141{
1142 return serialize_edsiobytes_obj (sink, x);
1143}
1144
1145gboolean
1146edsio_property_bytes_getter (gpointer obj, EdsioProperty* prop, guint8** get, guint32* get_len)
1147{
1148 EdsioPropertyEntry *ent;
1149
1150 if (! (ent = edsio_property_get (obj, prop)))
1151 return FALSE;
1152
1153 (* get) = (gpointer) ent->as_bytes.val;
1154 (* get_len) = ent->as_bytes.val_len;
1155
1156 return TRUE;
1157}
1158
1159gboolean
1160edsio_property_bytes_setter (gpointer obj, EdsioProperty* prop, guint8* set, guint32 set_len)
1161{
1162 EdsioPropertyEntry *ent = g_new (EdsioPropertyEntry, 1);
1163
1164 ent->as_bytes.val = set;
1165 ent->as_bytes.val_len = set_len;
1166
1167 return edsio_property_set (obj, prop, ent);
1168}
1169
1170void
1171edsio_property_bytes_free (gpointer obj)
1172{
1173 g_free (obj);
1174}
1175
1176/* Vptr
1177 */
1178
1179gboolean
1180edsio_property_vptr_getter (gpointer obj, EdsioProperty* prop, void** get)
1181{
1182 if (! ((*get) = edsio_property_get (obj, prop)))
1183 return FALSE;
1184
1185 return TRUE;
1186}
1187
1188gboolean
1189edsio_property_vptr_setter (gpointer obj, EdsioProperty* prop, void* set)
1190{
1191 return edsio_property_set (obj, prop, (EdsioPropertyEntry*) set);
1192}
1193
1194void
1195edsio_property_vptr_free (gpointer obj)
1196{
1197 /* nothing */
1198}
1199
1200/* Testing
1201 */
1202
1203#ifdef DEBUG_LIBEDSIO
1204
1205GHashTable**
1206edsio_proptest_property_table (PropTest *pt)
1207{
1208 return & pt->_edsio_property_table;
1209}
1210
1211SerialSource*
1212edsio_persist_proptest_source (PropTest *pt, const char* prop_name)
1213{
1214 GByteArray* array;
1215
1216 if (! pt->ptable)
1217 {
1218 g_warning ("can't get persist property, no table\n");
1219 return NULL;
1220 }
1221
1222 if (! (array = g_hash_table_lookup (pt->ptable, prop_name)))
1223 {
1224 g_warning ("can't lookup persist property\n");
1225 return NULL;
1226 }
1227
1228 return edsio_simple_source (array->data, array->len, SBF_None);
1229}
1230
1231static void
1232pt_success (gpointer data, GByteArray* result)
1233{
1234 PropTest* pt = data;
1235
1236 GByteArray* old;
1237
1238 if (! pt->ptable)
1239 pt->ptable = g_hash_table_new (g_str_hash, g_str_equal);
1240
1241 old = g_hash_table_lookup (pt->ptable, (gpointer) pt->kludge);
1242
1243 if (old)
1244 g_byte_array_free (old, TRUE);
1245
1246 g_hash_table_insert (pt->ptable, (gpointer) pt->kludge, result);
1247}
1248
1249SerialSink*
1250edsio_persist_proptest_sink (PropTest *pt, const char* prop_name)
1251{
1252 pt->kludge = prop_name;
1253
1254 return edsio_simple_sink (pt, SBF_None, FALSE, pt_success, NULL);
1255}
1256
1257gboolean
1258edsio_persist_proptest_isset (PropTest *pt, const char* prop_name)
1259{
1260 if (! pt->ptable)
1261 return FALSE;
1262
1263 return g_hash_table_lookup (pt->ptable, prop_name) != NULL;
1264}
1265
1266gboolean
1267edsio_persist_proptest_unset (PropTest *pt, const char* prop_name)
1268{
1269 GByteArray* old;
1270
1271 if (! pt->ptable)
1272 return FALSE;
1273
1274 old = g_hash_table_lookup (pt->ptable, prop_name);
1275
1276 if (old)
1277 {
1278 g_byte_array_free (old, TRUE);
1279 g_hash_table_remove (pt->ptable, prop_name);
1280 return TRUE;
1281 }
1282
1283 return FALSE;
1284}
1285
1286#endif
1287
1288/* Misc source/sink stuff
1289 */
1290
1291SerialSink*
1292serializeio_gzip_sink (SerialSink* sink)
1293{
1294 /* @@@ not implemented */
1295 return sink;
1296}
1297
1298SerialSource*
1299serializeio_gzip_source (SerialSource* source)
1300{
1301 /* @@@ not implemented */
1302 return source;
1303}
1304
1305/* Checksum sink
1306 */
1307typedef struct _ChecksumSink ChecksumSink;
1308
1309static gboolean checksum_sink_close (SerialSink* sink);
1310static gboolean checksum_sink_write (SerialSink* sink, const guint8 *ptr, guint32 len);
1311static void checksum_sink_free (SerialSink* sink);
1312static gboolean checksum_sink_quantum (SerialSink* sink);
1313
1314struct _ChecksumSink
1315{
1316 SerialSink sink;
1317
1318 SerialSink* out;
1319
1320 EdsioMD5Ctx ctx;
1321 guint8 md5[16];
1322 gboolean md5_done;
1323 gboolean md5_written;
1324};
1325
1326SerialSink*
1327serializeio_checksum_sink (SerialSink* out)
1328{
1329 ChecksumSink* it = g_new0 (ChecksumSink, 1);
1330 SerialSink* sink = (SerialSink*) it;
1331
1332 serializeio_sink_init (sink,
1333 NULL,
1334 checksum_sink_close,
1335 checksum_sink_write,
1336 checksum_sink_free,
1337 checksum_sink_quantum);
1338
1339 it->out = out;
1340
1341 edsio_md5_init (& it->ctx);
1342
1343 return sink;
1344}
1345
1346gboolean
1347checksum_sink_write (SerialSink* fsink, const guint8 *ptr, guint32 len)
1348{
1349 ChecksumSink* sink = (ChecksumSink*) fsink;
1350
1351 if (! sink->out->sink_write (sink->out, ptr, len))
1352 return FALSE;
1353
1354 edsio_md5_update (& sink->ctx, ptr, len);
1355
1356 return TRUE;
1357}
1358
1359gboolean
1360checksum_sink_close (SerialSink* fsink)
1361{
1362 ChecksumSink* sink = (ChecksumSink*) fsink;
1363
1364 if (! sink->md5_done)
1365 {
1366 edsio_md5_final (sink->md5, & sink->ctx);
1367 sink->md5_done = TRUE;
1368 }
1369
1370 if (! sink->out->sink_write (sink->out, sink->md5, 16))
1371 return FALSE;
1372
1373 if (! sink->out->sink_close (sink->out))
1374 return FALSE;
1375
1376 return TRUE;
1377}
1378
1379void
1380checksum_sink_free (SerialSink* fsink)
1381{
1382 ChecksumSink* sink = (ChecksumSink*) fsink;
1383
1384 sink->out->sink_free (sink->out);
1385
1386 g_free (sink);
1387}
1388
1389gboolean
1390checksum_sink_quantum (SerialSink* fsink)
1391{
1392 ChecksumSink* sink = (ChecksumSink*) fsink;
1393
1394 if (sink->out->sink_quantum)
1395 return sink->out->sink_quantum (sink->out);
1396
1397 return TRUE;
1398}
1399
1400/* Checksum source
1401 */
1402
1403typedef struct _ChecksumSource ChecksumSource;
1404
1405struct _ChecksumSource {
1406 SerialSource source;
1407
1408 SerialSource *in;
1409
1410 EdsioMD5Ctx ctx;
1411};
1412
1413static gboolean checksum_source_close (SerialSource* source);
1414static gboolean checksum_source_read (SerialSource* source, guint8 *ptr, guint32 len);
1415static void checksum_source_free (SerialSource* source);
1416
1417SerialSource*
1418serializeio_checksum_source (SerialSource* in0)
1419{
1420 ChecksumSource* it = g_new0 (ChecksumSource, 1);
1421 SerialSource* source = (SerialSource*) it;
1422
1423 serializeio_source_init (source,
1424 NULL,
1425 checksum_source_close,
1426 checksum_source_read,
1427 checksum_source_free,
1428 NULL,
1429 NULL);
1430
1431 it->in = in0;
1432
1433 edsio_md5_init (& it->ctx);
1434
1435 return source;
1436}
1437
1438gboolean
1439checksum_source_close (SerialSource* fsource)
1440{
1441 ChecksumSource* source = (ChecksumSource*) fsource;
1442 guint8 buf1[16];
1443 guint8 buf2[16];
1444
1445 if (! source->in->source_read (source->in, buf1, 16))
1446 return FALSE;
1447
1448 edsio_md5_final (buf2, & source->ctx);
1449
1450 if (memcmp (buf1, buf2, 16) != 0)
1451 {
1452 edsio_generate_void_event (EC_EdsioInvalidStreamChecksum);
1453 return FALSE;
1454 }
1455
1456 if (! source->in->source_close (source->in))
1457 return FALSE;
1458
1459 return TRUE;
1460}
1461
1462gboolean
1463checksum_source_read (SerialSource* fsource, guint8 *ptr, guint32 len)
1464{
1465 ChecksumSource* source = (ChecksumSource*) fsource;
1466
1467 if (! source->in->source_read (source->in, ptr, len))
1468 return FALSE;
1469
1470 edsio_md5_update (& source->ctx, ptr, len);
1471
1472 return TRUE;
1473}
1474
1475void
1476checksum_source_free (SerialSource* fsource)
1477{
1478 ChecksumSource* source = (ChecksumSource*) fsource;
1479
1480 source->in->source_free (source->in);
1481
1482 g_free (source);
1483}
1484
1485/* Missing glib stuff
1486 */
1487
1488GQueue *
1489g_queue_new (void)
1490{
1491 GQueue *q = g_new (GQueue, 1);
1492
1493 q->list = q->list_end = NULL;
1494 q->list_size = 0;
1495
1496 return q;
1497}
1498
1499
1500void
1501g_queue_free (GQueue *q)
1502{
1503 if (q)
1504 {
1505 if (q->list)
1506 g_list_free (q->list);
1507 g_free (q);
1508 }
1509}
1510
1511
1512guint
1513g_queue_get_size (GQueue *q)
1514{
1515 return (q == NULL) ? 0 : q->list_size;
1516}
1517
1518
1519void
1520g_queue_push_front (GQueue *q, gpointer data)
1521{
1522 if (q)
1523 {
1524 q->list = g_list_prepend (q->list, data);
1525
1526 if (q->list_end == NULL)
1527 q->list_end = q->list;
1528
1529 q->list_size++;
1530 }
1531}
1532
1533
1534void
1535g_queue_push_back (GQueue *q, gpointer data)
1536{
1537 if (q)
1538 {
1539 q->list_end = g_list_append (q->list_end, data);
1540
1541 if (! q->list)
1542 q->list = q->list_end;
1543 else
1544 q->list_end = q->list_end->next;
1545
1546 q->list_size++;
1547 }
1548}
1549
1550
1551gpointer
1552g_queue_pop_front (GQueue *q)
1553{
1554 gpointer data = NULL;
1555
1556 if ((q) && (q->list))
1557 {
1558 GList *node;
1559
1560 node = q->list;
1561 data = node->data;
1562
1563 if (! node->next)
1564 {
1565 q->list = q->list_end = NULL;
1566 q->list_size = 0;
1567 }
1568 else
1569 {
1570 q->list = node->next;
1571 q->list->prev = NULL;
1572 q->list_size--;
1573 }
1574
1575 g_list_free_1 (node);
1576 }
1577
1578 return data;
1579}
1580
1581
1582gpointer
1583g_queue_pop_back (GQueue *q)
1584{
1585 gpointer data = NULL;
1586
1587 if ((q) && (q->list))
1588 {
1589 GList *node;
1590
1591 node = q->list_end;
1592 data = node->data;
1593
1594 if (! node->prev)
1595 {
1596 q->list = q->list_end = NULL;
1597 q->list_size = 0;
1598 }
1599 else
1600 {
1601 q->list_end = node->prev;
1602 q->list_end->next = NULL;
1603 q->list_size--;
1604 }
1605
1606 g_list_free_1 (node);
1607 }
1608
1609 return data;
1610}
diff --git a/xdelta1/libedsio/edsio.el b/xdelta1/libedsio/edsio.el
deleted file mode 100644
index 8c15215..0000000
--- a/xdelta1/libedsio/edsio.el
+++ /dev/null
@@ -1,1864 +0,0 @@
1;; -*- Emacs-Lisp -*-
2
3(require 'cl)
4(require 'pp)
5
6(eval-and-compile (setq load-path (cons ".." (cons "." load-path))))
7(provide 'edsio)
8(eval-and-compile (setq load-path (cdr (cdr load-path))))
9
10;; Turn of assertions in compiled code.
11(eval-and-compile
12 (setq cl-optimize-speed 3)
13 (setq cl-optimize-safety 1)
14 )
15
16;; Begin
17
18(defconst *definition-state* nil
19 "List of all the names of variables containing state from the
20definition file so that operations may be performed on everything in
21the definition file.")
22(defconst *definition-attrs* nil
23 "List of attributes for sharing indices.")
24(defconst *all-objects* nil)
25(defconst *output-files* nil
26 "List of lists (NAME BUFFER) used during output of headers.")
27(defconst *output-prefix* nil
28 "Prefix used for outputing header files.")
29(defconst *cpp-extension* "c")
30
31;; This defines several functions and one macro. The indirection makes
32;; it a little bit confusing to read. It defines the macro DEFDNAME,
33;; a function DEFDNAME*, MAKE-DNAME, and a setter and getter for each arg.
34(eval-and-compile
35(defmacro attr-index (attr)
36 `(- (length *definition-attrs*) (length (memq ,attr *definition-attrs*))))
37
38(defmacro defastmacro(dtype args attrs)
39 "Defines a macro named DEFDTYPE for defining various AST properties."
40 (let ((def-macr (intern (format "def%s" dtype)))
41 (def-func (intern (format "def%s*" dtype)))
42 (make-func (intern (format "make-%s" dtype)))
43 (state (intern (format "*%s-defs*" dtype)))
44 (exprs nil))
45 (if (not *definition-attrs*)
46 (setq *definition-attrs* '(menunode menuline)))
47 (let ((fields (append args attrs)))
48 (while fields
49 (if (not (memq (car fields) *definition-attrs*))
50 (setq *definition-attrs* (append *definition-attrs* (list (car fields)))))
51 (setq fields (cdr fields))
52 )
53 )
54 ;; Add it to *definition-state*
55 (setq *definition-state* (cons state *definition-state*))
56 ;; DEFCONST it
57 (setq exprs (cons (list 'defconst state (quote nil)) exprs))
58 ;; DEFMACRO DEFDTYPE
59 (setq exprs (cons (list 'defmacro
60 def-macr
61 args
62 (append (list 'list (list 'quote def-func))
63 (mapcar (function (lambda (x)
64 (list 'list (list 'quote 'quote) x)
65 )
66 )
67 args)
68 )
69 )
70 exprs
71 )
72 )
73 ;; DEFUN DEFDTYPE*
74 (setq exprs (cons (list 'defun
75 def-func
76 args
77 (list 'setq
78 state
79 (list 'cons
80 (cons make-func args)
81 state
82 )
83 )
84 )
85 exprs
86 )
87 )
88 ;; MAKE-DTYPE
89 (setq exprs (cons (list 'defun
90 make-func
91 args
92 (list 'let (list (list 'it (list 'make-vector (length *definition-attrs*) nil)))
93 (if args
94 (cons 'progn (mapcar
95 (function
96 (lambda (x)
97 (list 'aset 'it (attr-index x) x)
98 )
99 )
100 args
101 )
102 )
103 )
104 (if attrs
105 (cons 'progn (mapcar
106 (function
107 (lambda (x)
108 (list 'aset 'it (attr-index x) nil)
109 )
110 )
111 attrs
112 )
113 )
114 )
115 (if (memq 'menu args)
116 (list 'progn
117 (list 'aset 'it (attr-index 'menunode) (list 'function (intern (format "%s-menunode" dtype))))
118 (list 'aset 'it (attr-index 'menuline) (list 'function (intern (format "%s-menuline" dtype))))
119 )
120 )
121 (list 'cons (list 'quote dtype) 'it)
122 )
123 )
124 exprs
125 )
126 )
127 ;; Add the fake arguments:
128 (if (memq 'menu args)
129 (setq attrs (append (list 'menunode 'menuline) attrs)))
130 (setq args (append args attrs))
131 (while args
132 (let* ((thearg (car args))
133 (arg-set (intern (format "%s-%s-set" dtype thearg)))
134 (arg-get (intern (format "%s-%s-get" dtype thearg))))
135 ;; DTYPE-ARG-GET
136 (setq exprs (cons (list 'defmacro
137 (intern (format "%s-%s-get" dtype thearg))
138 '(obj)
139 (list 'list
140 (list 'quote 'aref)
141 (list 'list (list 'quote 'cdr) 'obj)
142 (attr-index thearg))
143 )
144 exprs
145 )
146 )
147 ;; DTYPE-ARG-SET
148 (setq exprs (cons (list 'defmacro
149 (intern (format "%s-%s-set" dtype thearg))
150 '(obj val)
151 (list 'list
152 (list 'quote 'aset)
153 (list 'list (list 'quote 'cdr) 'obj)
154 (attr-index thearg)
155 'val)
156 )
157 exprs
158 )
159 )
160 )
161 (setq args (cdr args))
162 )
163 ;; To see what it's generating uncomment the next 2 lines.
164 ;;(setq message-log-max t)
165 ;;(mapcar (function pp) exprs)
166 (cons 'progn exprs)
167 )
168 )
169
170
171;; This is, as the name suggests, really bogus. Basically, each DEFASTMACRO
172;; call adds to the list *definition-state*. To compile it, however, it has
173;; to be done at compile time, so this macro gets evaluated when being compiled
174;; and clears the list. Then the DEFASTMACRO calls are made, and then DEFCDS
175;; is called to define CLEAR-DEFINITION-STATE which resets the list to the
176;; compile-time computed value of *definition-state*, it would otherwise be
177;; empty when running compiled code.
178(defmacro bogus ()
179 (setq *definition-state* nil)
180 (setq *definition-attrs* nil)
181 )
182
183 (bogus)
184
185;; Each DEFASTMACRO statement defines a directive for the definition
186;; file along with it's argument names.
187(defastmacro sertype (name number fields transients) ())
188(defastmacro module (name id header pheader) ())
189(defastmacro import (name) (prefix))
190
191(defastmacro event (name level uargs sargs desc) ())
192(defastmacro etype (name ctype) ())
193
194(defastmacro prophost (name letter ctype persist) (proptypes))
195(defastmacro prophosttype (host type) ())
196
197(defmacro defcds ()
198 (let ((exprs nil))
199 (setq exprs (list (list 'defun 'clear-definition-state nil
200 '(setq *all-objects* nil)
201 (list 'setq '*definition-state* (list 'quote *definition-state*))
202 (list 'setq '*definition-attrs* (list 'quote *definition-attrs*))
203 '(mapcar (function (lambda (x) (set x nil))) *definition-state*)
204 )
205
206 )
207 )
208 (mapcar
209 (function
210 (lambda (x)
211 (setq exprs (cons (list 'defmacro
212 (intern (format "obj-%s-get" x))
213 '(obj)
214 (list 'list
215 (list 'quote 'aref)
216 (list 'list (list 'quote 'cdr) 'obj)
217 (attr-index x))
218 )
219 exprs
220 )
221 )
222 (setq exprs (cons (list 'defmacro
223 (intern (format "obj-%s-set" x))
224 '(obj val)
225 (list 'list
226 (list 'quote 'aset)
227 (list 'list (list 'quote 'cdr) 'obj)
228 (attr-index x)
229 'val)
230 )
231 exprs
232 )
233 )
234 (let ((get (intern (format "obj-%s-get" x))))
235 (setq exprs (cons (list 'defun
236 (intern (format "obj-%s-eq" x))
237 '(val olist)
238 `(let ((ret nil))
239 (while (and (not ret) olist)
240 (if (eq val (,get (car olist)))
241 (setq ret (car olist))
242 )
243 (setq olist (cdr olist))
244 )
245 ret
246 )
247 )
248 exprs
249 )
250 )
251 )
252 )
253 )
254 *definition-attrs*
255 )
256 ;;(setq message-log-max t)
257 ;;(mapcar (function pp) exprs)
258 (cons 'progn exprs)
259 )
260 )
261
262(defcds)
263)
264;; Entry Points
265
266(defun generate-ser-noargs ()
267 (interactive)
268 (generate-ser "edsio.ser" "edsio")
269 )
270
271(defun generate-ser (input-file output-prefix)
272 ;(interactive "finput: \nsoutput: \nsid: ")
273 (let ((make-backup-files nil)
274 (executing-kbd-macro t))
275 (clear-definition-state)
276
277 (do-it input-file output-prefix)
278 )
279 )
280
281(defconst *library-id* nil
282 "Identifier of this library.")
283
284(defconst *library-header* nil
285 "Header of this library.")
286(defconst *library-pheader* nil
287 "Header of this library.")
288
289(defconst *prefix-with-library-header* t)
290
291(defun load-defs(file)
292 (load-file file)
293 (setq *import-defs* (reverse *import-defs*))
294 (setq *module-defs* (reverse *module-defs*))
295 (setq *sertype-defs* (reverse *sertype-defs*))
296
297 (setq *event-defs* (reverse *event-defs*))
298 (setq *etype-defs* (reverse *etype-defs*))
299
300 (setq *prophost-defs* (reverse *prophost-defs*))
301 (setq *prophosttype-defs* (reverse *prophosttype-defs*))
302 )
303
304(defconst *header-typedef-marker* nil)
305(defconst *source-init-marker* nil)
306(defconst *source-top-marker* nil)
307
308(defun do-it (input-file output-prefix)
309 (setq *output-files* nil)
310 (setq *output-prefix* output-prefix)
311
312 (load-defs input-file)
313
314 (if (not *module-defs*)
315 (error "no defmodule in %s" input-file))
316
317 (if (> (length *module-defs*) 1)
318 (error "too many defmodules in %s" input-file))
319
320 (setq *library-id* (module-id-get (car *module-defs*)))
321 (setq *library-header* (module-header-get (car *module-defs*)))
322 (setq *library-pheader* (module-pheader-get (car *module-defs*)))
323
324 (when (not *library-header*)
325 (setq *prefix-with-library-header* nil)
326 (setq *library-header* (format "%s_edsio.h" *output-prefix*))
327 )
328
329 (if (or (<= *library-id* 0)
330 (>= *library-id* 256))
331 (error "Library-id is out of range"))
332
333 (if (> (length *sertype-defs*) 24)
334 (error "no more than 24 types"))
335
336 (unwind-protect
337 (progn
338
339 (output-header-file "_edsio")
340
341 (read-imports)
342
343 (insert "/* Initialize this library. */\n\n")
344 (insert "gboolean " *output-prefix* "_edsio_init (void);\n\n")
345
346 (insert "/* Types defined here. */\n\n")
347 (setq *header-typedef-marker* (point-marker))
348
349 (insert "/* Functions declared here. */\n\n")
350
351 (output-source-file "_edsio")
352
353 (insert "#include \"" *library-header* "\"\n\n")
354 (insert "#include <errno.h>\n\n")
355
356 (if *library-pheader*
357 (insert "#include \"" *library-pheader* "\"\n\n"))
358
359 (insert "/* Declarations. */\n\n")
360 (setq *source-top-marker* (point-marker))
361
362 (insert "\n")
363
364 (insert "/* initialize this library. */\n\n")
365 (insert "gboolean\n" *output-prefix* "_edsio_init (void)\n{\n")
366 (insert " static gboolean once = FALSE;\n")
367 (insert " static gboolean result = FALSE;\n")
368 (insert " if (once) return result;\n")
369 (insert " once = TRUE;\n")
370
371 (setq *source-init-marker* (point-marker))
372
373 (insert (format " edsio_library_register (%d, \"%s\");\n" *library-id* *output-prefix*))
374 (insert " result = TRUE;\n")
375 (insert " return TRUE;\n")
376 (insert "};\n\n")
377
378 (if *prophosttype-defs*
379 (generate-properties))
380
381 (if *sertype-defs*
382 (generate-code))
383
384 (if *event-defs*
385 (generate-events))
386
387; (message "source file:\n%s" (buffer-string))
388
389 (mapcar (function (lambda (x) (output-finish-file x))) *output-files*)
390 )
391 (mapcar (function (lambda (x) (kill-buffer (cadr x)))) *output-files*)
392 )
393 )
394
395(defvar *all-sertype-defs* nil)
396(defvar *all-prophost-defs* nil)
397(defvar *all-etype-defs* nil)
398
399(defun read-imports ()
400
401 (setq *all-sertype-defs* *sertype-defs*)
402 (setq *all-etype-defs* *etype-defs*)
403 (setq *all-prophost-defs* *prophost-defs*)
404
405 (let ((mods *module-defs*)
406 (imps0 *import-defs*)
407 (imps *import-defs*)
408 (types *sertype-defs*)
409 (events *event-defs*)
410 (etypes *etype-defs*)
411 (phosts *prophost-defs*)
412 (phts *prophosttype-defs*)
413 )
414
415 (while imps
416 (clear-definition-state)
417
418 (load-defs (import-name-get (car imps)))
419
420 (setq *all-sertype-defs* (append *all-sertype-defs* *sertype-defs*))
421 (setq *all-etype-defs* (append *all-etype-defs* *etype-defs*))
422 (setq *all-prophost-defs* (append *all-prophost-defs* *prophost-defs*))
423
424 (import-prefix-set (car imps) (module-name-get (car *module-defs*)))
425
426 (when (or *sertype-defs* *event-defs*)
427 (output-header-file "_edsio")
428 (insert (format "#include \"%s_edsio.h\"\n\n" (import-prefix-get (car imps))))
429 )
430
431 (setq imps (cdr imps))
432 )
433
434 (setq *module-defs* mods)
435 (setq *import-defs* imps0)
436 (setq *sertype-defs* types)
437 (setq *event-defs* events)
438 (setq *etype-defs* etypes)
439 (setq *prophost-defs* phosts)
440 (setq *prophosttype-defs* phts)
441 )
442 )
443
444
445(defun output-header-file (name)
446 (output-file (format "%s.h" name) 'c-header *output-prefix*))
447
448(defun output-source-file (name)
449 (output-file (format "%s.%s" name *cpp-extension*) 'c *output-prefix*))
450
451(defun output-source-include-file (name)
452 (output-file (format "%s.%si" name *cpp-extension*) 'c *output-prefix*))
453
454(defun output-plain-file (name)
455 (output-file (format "%s" name) 'plain ""))
456
457(defun output-file (name type prefix)
458 (let* ((name (format "%s%s" prefix name))
459 (it (assoc name *output-files*)))
460 (if it
461 (set-buffer (cadr it))
462 (let ((nbuf (get-buffer-create (generate-new-buffer-name name))))
463 (setq *output-files* (cons (list name nbuf type) *output-files*))
464 (set-buffer nbuf)
465 )
466 )
467 )
468 )
469
470(defun output-finish-file (file)
471 (let ((name (car file))
472 (buf (cadr file))
473 (type (caddr file)))
474 (set-buffer buf)
475 ;(message "printing %s: %s" file (buffer-string))
476 (cond ((eq type 'c)
477 (output-to-c name nil))
478 ((eq type 'c-header)
479 (output-to-c name t))
480 )
481 (write-file-if-different buf name)
482 )
483 )
484
485(defun output-to-c (name is-header)
486 (goto-char (point-min))
487 (insert "/* -*-Mode: C;-*-
488 * Copyright (C) 1997, 1998, 1999 Josh MacDonald
489 *
490 * This program is free software; you can redistribute it and/or modify
491 * it under the terms of the GNU General Public License as published by
492 * the Free Software Foundation; either version 2 of the License, or
493 * (at your option) any later version.
494 *
495 * This program is distributed in the hope that it will be useful,
496 * but WITHOUT ANY WARRANTY; without even the implied warranty of
497 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
498 * GNU General Public License for more details.
499 *
500 * You should have received a copy of the GNU General Public License
501 * along with this program; if not, write to the Free Software
502 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
503 *
504 * Author: Josh MacDonald <jmacd@CS.Berkeley.EDU>
505 *
506 * This file was AUTOMATICALLY GENERATED using:
507 *
508 * $Id: edsio.el 1.1 Sun, 28 Jan 2007 10:02:26 -0800 jmacd $
509 */
510
511")
512
513 (if is-header
514 (let ((cppname (string-replace-regexp (upcase name) "[-./]" "_")))
515 (insert "#include \"edsio.h\"\n\n")
516
517 (if *prefix-with-library-header*
518 (insert "#include \"" *library-header* "\"\n\n"))
519
520 (insert "#ifndef _" cppname "_\n")
521 (insert "#define _" cppname "_\n\n")
522 (insert "#ifdef __cplusplus\n")
523 (insert "extern \"C\" {\n")
524 (insert "#endif\n\n")
525 (goto-char (point-max))
526 (insert "#ifdef __cplusplus\n")
527 (insert "}\n")
528 (insert "#endif\n")
529 (insert "\n#endif /* _" cppname "_ */\n\n")
530 )
531 )
532 )
533
534(defun string-replace-regexp (str regexp to-string)
535 "Result of replacing all occurrences in STR of REGEXP by TO-STRING. The
536replacement is as for replace-regexp."
537 (let ((work (get-buffer-create "*string-tmp*")))
538 (save-excursion
539 (set-buffer work)
540 (erase-buffer)
541 (insert str)
542 (beginning-of-buffer)
543 (while (re-search-forward regexp nil t)
544 (replace-match to-string nil nil))
545 (buffer-string))))
546
547(defun write-file-if-different (buf filename)
548 (save-excursion
549 (if (not (file-exists-p filename))
550 (write-file filename)
551 (set-buffer buf)
552 (let ((old (get-buffer-create (generate-new-buffer-name filename)))
553 (bmin (point-min))
554 (bmax (point-max)))
555 (unwind-protect
556 (progn
557 (set-buffer old)
558 (insert-file filename)
559 (let ((omin (point-min))
560 (omax (point-max))
561 (case-fold-search nil))
562 (if (= 0 (compare-buffer-substrings old omin omax buf bmin bmax))
563 (message "Output file %s is unchanged." filename)
564 (set-buffer buf)
565 (write-file filename)
566 )
567 )
568 )
569 (kill-buffer old)
570 )
571 )
572 )
573 )
574 )
575
576
577(defun format-comlist (func l)
578 (let ((x ""))
579 (while l
580 (setq x (concat x (funcall func (car l))))
581 (if (cdr l)
582 (setq x (concat x ", ")))
583 (setq l (cdr l))
584 )
585 x
586 )
587 )
588
589(defun format-semilist (func l)
590 (let ((x ""))
591 (while l
592 (setq x (concat x (funcall func (car l))))
593 (if (cdr l)
594 (setq x (concat x "; ")))
595 (setq l (cdr l))
596 )
597 x
598 )
599 )
600
601(defun format-numbered-comlist (func l)
602 (let ((x "")
603 (n 0))
604 (while l
605 (setq x (concat x (funcall func (car l) n)))
606 (setq n (+ n 1))
607 (if (cdr l)
608 (setq x (concat x ", ")))
609 (setq l (cdr l))
610 )
611 x
612 )
613 )
614
615(defun capitalize1(s)
616 (let ((work (get-buffer-create "*string-tmp*")))
617 (save-excursion
618 (set-buffer work)
619 (erase-buffer)
620 (insert (format "%s" s))
621 (upcase-region (point-min) (+ (point-min) 1))
622 (buffer-substring-no-properties (point-min) (point-max))
623 )
624 )
625 )
626
627(defun upcase-string (s)
628 (let ((work (get-buffer-create "*string-tmp*")))
629 (save-excursion
630 (set-buffer work)
631 (erase-buffer)
632 (insert (format "%s" s))
633 (upcase-region (point-min) (point-max))
634 (buffer-substring-no-properties (point-min) (point-max))
635 )
636 )
637 )
638
639(defun downcase-string (s)
640 (let ((work (get-buffer-create "*string-tmp*")))
641 (save-excursion
642 (set-buffer work)
643 (erase-buffer)
644 (insert (format "%s" s))
645 (downcase-region (point-min) (point-max))
646 (buffer-substring-no-properties (point-min) (point-max))
647 )
648 )
649 )
650
651;; HERE IT IS
652
653(defun generate-code ()
654
655 (let ((all-codes nil))
656 (mapcar
657 (function
658 (lambda (st)
659 (let ((x (sertype-number-get st)))
660 (cond ((member x all-codes)
661 (error "serial type number %d defined twice" x))
662 ((> x 24)
663 (error "serial type value %d too high" x))
664 ((< x 0)
665 (error "serial type value %d too low" x))
666 (t (setq all-codes (cons x all-codes))))))
667 )
668 *sertype-defs*)
669 )
670
671 (output-header-file "_edsio")
672
673 (insert "/* Serial Types */\n\n")
674 (insert (format "enum _Serial%sType {\n" (capitalize1 *output-prefix*)))
675 (insert (format-comlist
676 (function
677 (lambda (x)
678 (format "\n ST_%s = (1<<(%d+EDSIO_LIBRARY_OFFSET_BITS))+%d" (sertype-name-get x) (sertype-number-get x) *library-id*))) *sertype-defs*))
679 (insert "\n};\n\n")
680
681 (insert "\n\n")
682
683 (output-source-file "_edsio")
684
685 (save-excursion
686 (goto-char *source-top-marker*)
687
688 (insert "static void print_spaces (guint n) { int i; for (i = 0; i < n; i += 1) g_print (\" \"); }\n\n")
689 )
690
691 (mapcar (function generate-code-entry) *sertype-defs*)
692
693 )
694
695(defun generate-code-entry (entry)
696 (let ((ent-upcase (sertype-name-get entry))
697 (ent-downcase (downcase-string (sertype-name-get entry))))
698
699 (output-header-file "_edsio")
700
701 ;; The typedef, structure, and declarations.
702
703 (save-excursion
704 (goto-char *header-typedef-marker*)
705 (insert (format "typedef struct _Serial%s Serial%s;\n" ent-upcase ent-upcase))
706 )
707
708 (insert (format "/* %s Structure\n */\n\n" ent-upcase))
709
710 (insert (format "struct _Serial%s {\n" ent-upcase))
711
712 (apply (function insert)
713 (mapcar (function
714 (lambda (x)
715 (format " %s;\n" x)))
716 (entry-typename-pairs entry nil)))
717
718 (apply (function insert)
719 (mapcar (function
720 (lambda (x)
721 (format " %s;\n" x)))
722 (sertype-transients-get entry)))
723
724 (insert "};\n\n")
725
726 (insert (format "void serializeio_print_%s_obj (Serial%s* obj, guint indent_spaces);\n\n" ent-downcase ent-upcase))
727
728 (insert (format "gboolean unserialize_%s (SerialSource *source, Serial%s**);\n" ent-downcase ent-upcase))
729 (insert (format "gboolean unserialize_%s_internal (SerialSource *source, Serial%s** );\n" ent-downcase ent-upcase))
730 (insert (format "gboolean unserialize_%s_internal_noalloc (SerialSource *source, Serial%s* );\n" ent-downcase ent-upcase))
731 (insert (format "gboolean serialize_%s (SerialSink *sink%s);\n" ent-downcase (entry-arglist t entry)))
732 (insert (format "gboolean serialize_%s_obj (SerialSink *sink, const Serial%s* obj);\n" ent-downcase ent-upcase))
733 (insert (format "gboolean serialize_%s_internal (SerialSink *sink%s);\n" ent-downcase (entry-arglist t entry)))
734 (insert (format "gboolean serialize_%s_obj_internal (SerialSink *sink, Serial%s* obj);\n" ent-downcase ent-upcase))
735 (insert (format "guint serializeio_count_%s (%s);\n" ent-downcase (entry-arglist nil entry)))
736 (insert (format "guint serializeio_count_%s_obj (Serial%s const* obj);\n" ent-downcase ent-upcase))
737 (insert (format "\n"))
738
739 (output-source-file "_edsio")
740
741 ;; The init entry
742
743 (save-excursion
744 (goto-char *source-init-marker*)
745 (insert (format " serializeio_initialize_type (\"ST_%s\", ST_%s, &unserialize_%s_internal, &serialize_%s_obj_internal, &serializeio_count_%s_obj, &serializeio_print_%s_obj);\n" ent-upcase ent-upcase ent-downcase ent-downcase ent-downcase ent-downcase))
746 )
747
748 ;; Count code
749
750 (insert (format "/* %s Count\n */\n\n" ent-upcase))
751
752 (insert (format "guint\nserializeio_count_%s (%s) {\n" ent-downcase (entry-arglist nil entry)))
753 (insert (format " guint size = sizeof (Serial%s);\n" ent-upcase))
754 (apply (function insert)
755 (mapcar (function (lambda (x) (concat
756 (format " ALIGN_8 (size);\n")
757 (entry-count-field entry x (format "%s" (car x)) " " t))))
758 (sertype-fields-get entry)))
759 (insert (format " ALIGN_8 (size);\n"))
760 (insert (format " return size;\n"))
761 (insert (format "}\n\n"))
762
763 ;; Count Object code
764
765 (insert (format "guint\nserializeio_count_%s_obj (Serial%s const* obj) {\n" ent-downcase ent-upcase))
766 (insert (format " return serializeio_count_%s (%s);\n" ent-downcase (entry-plist t nil "obj->" entry)))
767 (insert (format "}\n\n"))
768
769 ;; Print object code
770
771 (insert (format "/* %s Print\n */\n\n" ent-upcase))
772
773 (insert (format "void\nserializeio_print_%s_obj (Serial%s* obj, guint indent_spaces) {\n" ent-downcase ent-upcase))
774 (insert (format " print_spaces (indent_spaces);\n"))
775
776 (insert (format " g_print (\"[ST_%s]\\n\");\n" ent-upcase))
777
778 (apply (function insert)
779 (mapcar (function (lambda (x) (entry-print-field entry x (format "obj->%s" (car x)) " " t)))
780 (sertype-fields-get entry)))
781
782 (insert (format "}\n\n"))
783
784 ;; Print internal code
785
786 ;; Serialize code
787
788 (insert (format "/* %s Serialize\n */\n\n" ent-upcase))
789
790 (insert (format "gboolean\nserialize_%s_internal (SerialSink *sink%s)\n" ent-downcase (entry-arglist t entry)))
791 (insert (format "{\n"))
792
793 (apply (function insert)
794 (mapcar (function (lambda (x) (entry-serialize-field entry x (format "%s" (car x)) " " t)))
795 (sertype-fields-get entry)))
796
797 (insert (format " return TRUE;\n"))
798 (if (sertype-fields-get entry)
799 (insert (format "bail:\n return FALSE;\n")))
800 (insert (format "}\n\n"))
801
802 ;; Internal Serialize Object code
803
804 (insert (format "gboolean\nserialize_%s_obj_internal (SerialSink *sink, Serial%s* obj)\n" ent-downcase ent-upcase))
805 (insert (format "{\n"))
806 (insert (format " return serialize_%s_internal (sink%s);\n" ent-downcase (entry-plist t t "obj->" entry)))
807 (insert (format "}\n\n"))
808
809 ;; External Serialize code
810
811 (insert (format "gboolean\nserialize_%s (SerialSink *sink%s)\n" ent-downcase (entry-arglist t entry)))
812 (insert (format "{\n"))
813
814 (insert (format " if (! (* sink->sink_type) (sink, ST_%s, serializeio_count_%s (%s), TRUE)) goto bail;\n" ent-upcase ent-downcase (entry-plist nil nil "" entry)))
815
816 (insert (format " if (! serialize_%s_internal (sink%s)) goto bail;\n" ent-downcase (entry-plist nil t "" entry)))
817 (insert (format " if (sink->sink_quantum && ! sink->sink_quantum (sink)) goto bail;\n"))
818
819 (insert (format " return TRUE;\n"))
820 (insert (format "bail:\n"))
821 (insert (format " return FALSE;\n"))
822 (insert (format "}\n\n"))
823
824 ;; External serialize_obj
825
826 (insert (format "gboolean\nserialize_%s_obj (SerialSink *sink, const Serial%s* obj) {\n\n" ent-downcase ent-upcase))
827 (insert (format " return serialize_%s (sink%s);\n" ent-downcase (entry-plist t t "obj->" entry)))
828 (insert (format "}\n\n"))
829
830 ;; Unserialize code
831
832 (insert (format "/* %s Unserialize\n */\n\n" ent-upcase))
833
834 (insert (format "gboolean\nunserialize_%s_internal_noalloc (SerialSource *source, Serial%s* result)\n" ent-downcase ent-upcase))
835 (insert (format "{\n"))
836
837 (apply (function insert)
838 (mapcar (function (lambda (x) (entry-unserialize-field entry x (format "result->%s" (car x)) " ")))
839 (sertype-fields-get entry)))
840
841 (insert (format " return TRUE;\n"))
842 (if (sertype-fields-get entry)
843 (insert (format "bail:\n return FALSE;\n")))
844 (insert (format "}\n\n"))
845
846
847 (insert (format "gboolean\nunserialize_%s_internal (SerialSource *source, Serial%s** result)\n" ent-downcase ent-upcase))
848 (insert (format "{\n"))
849
850 (insert (format " Serial%s* unser;\n" ent-upcase))
851 (insert (format " (*result) = NULL;\n"))
852 (insert (format " unser = serializeio_source_alloc (source, sizeof (Serial%s));\n" ent-upcase))
853 (insert (format " if (! unser) goto bail;\n"))
854
855 (insert (format " if (! unserialize_%s_internal_noalloc (source, unser)) goto bail;\n" ent-downcase))
856
857 (insert (format " (*result) = unser;\n"))
858 (insert (format " return TRUE;\n"))
859 (insert (format "bail:\n"))
860 (insert (format " return FALSE;\n"))
861 (insert (format "}\n\n"))
862
863 ;; External unserialize
864
865 (insert (format "gboolean\nunserialize_%s (SerialSource *source, Serial%s** result)\n" ent-downcase ent-upcase))
866 (insert (format "{\n"))
867
868 (insert (format " if ( (* source->source_type) (source, TRUE) != ST_%s) goto bail;\n" ent-upcase))
869
870 (insert (format " if (! unserialize_%s_internal (source, result)) goto bail;\n" ent-downcase))
871
872 (insert (format " return TRUE;\n"))
873 (insert (format "bail:\n"))
874 (insert (format " return FALSE;\n"))
875
876 (insert (format "}\n\n"))
877
878 )
879 )
880
881(defun entry-typename-pairs (entry is-param)
882 (let ((pairs nil)
883 (fields (sertype-fields-get entry)))
884 (while fields
885 (let ((field (car fields)))
886 (when (or (equal (cadr field) 'bytes)
887 (and (consp (cadr field)) (equal (caadr field) 'array)))
888 (setq pairs (cons (format "guint32 %s_len" (car field)) pairs))
889 )
890 (when (equal (cadr field) 'object)
891 (setq pairs (cons (format "guint32 %s_type" (car field)) pairs))
892 )
893 (setq pairs (cons (field-decl field is-param) pairs))
894 )
895 (setq fields (cdr fields))
896 )
897 (nreverse pairs)
898 )
899 )
900
901(defun entry-param-names (prefix entry need_pbr)
902 (let ((pairs nil)
903 (fields (sertype-fields-get entry)))
904 (while fields
905 (let ((field (car fields)))
906 (when (or (equal (cadr field) 'bytes)
907 (and (consp (cadr field)) (equal (caadr field) 'array)))
908 (setq pairs (cons (format "%s%s_len" prefix (car field)) pairs))
909 )
910 (when (equal (cadr field) 'object)
911 (setq pairs (cons (format "%s%s_type" prefix (car field)) pairs))
912 )
913 (setq pairs (cons (format "%s%s%s" (if (and need_pbr (needs-ref field)) "&" "") prefix (car field)) pairs))
914 )
915 (setq fields (cdr fields))
916 )
917 (nreverse pairs)
918 )
919 )
920
921(defun field-ctype (field)
922 (cond ((equal (cadr field) 'string)
923 "const gchar*")
924 ((equal (cadr field) 'uint)
925 "guint32")
926 ((equal (cadr field) 'uint32)
927 "guint32")
928 ((equal (cadr field) 'uint16)
929 "guint16")
930 ((equal (cadr field) 'uint8)
931 "guint8")
932 ((equal (cadr field) 'boolean)
933 "gboolean")
934 ((equal (cadr field) 'bytes)
935 "const guint8*")
936 ((equal (cadr field) 'object)
937 "void*")
938 ((member (cadr field) (mapcar (lambda (x) (sertype-name-get x)) *all-sertype-defs*))
939 (format "Serial%s" (cadr field)))
940 ((equal (car (cadr field)) 'bytes)
941 "const guint8*")
942 ((member (car (cadr field)) '(array ptr))
943 (concat (field-ctype (cadr field)) "*"))
944 (t (error "unrecognized field type: %s" (cadr field))))
945 )
946
947(defun field-decl (field is-param)
948 (if (and (consp (cadr field))
949 (equal (car (cadr field)) 'bytes))
950 (format "%sguint8 %s[%d]" (if is-param "const " "") (car field) (cadr (cadr field)))
951 ;(message "foo %s %s" field (member (cadr field) (mapcar (lambda (x) (sertype-name-get x)) *all-sertype-defs*)))
952 (format "%s %s"
953 (cond ((member (cadr field) (mapcar (lambda (x) (sertype-name-get x)) *all-sertype-defs*))
954 (format "Serial%s%s" (cadr field) (if is-param " const*" "")))
955 ((equal (cadr field) 'string)
956 "const gchar*")
957 ((equal (cadr field) 'uint)
958 "guint32")
959 ((equal (cadr field) 'uint32)
960 "guint32")
961 ((equal (cadr field) 'uint16)
962 "guint16")
963 ((equal (cadr field) 'uint8)
964 "guint8")
965 ((equal (cadr field) 'boolean)
966 "gboolean")
967 ((equal (cadr field) 'bytes)
968 "const guint8*")
969 ((equal (cadr field) 'object)
970 "void*")
971 ((member (car (cadr field)) '(array ptr))
972 (concat (field-ctype (cadr field)) (if is-param " const*" "*")))
973 (t (error "unrecognized field type: %s" (cadr field))))
974 (car field)))
975 )
976
977(defun entry-arglist (need_first entry)
978 (concat
979 (if (and need_first (sertype-fields-get entry)) ", " "")
980 (format-comlist (function (lambda (x) x)) (entry-typename-pairs entry t))))
981
982(defun needs-ref (field)
983 (member (cadr field) (mapcar (lambda (x) (sertype-name-get x)) *all-sertype-defs*))
984 )
985
986(defun entry-plist (need_pbr need_first prefix entry)
987 (concat
988 (if (and need_first (sertype-fields-get entry)) ", " "")
989 (format-comlist (function (lambda (x) (format "%s" x)))
990 (entry-param-names prefix entry need_pbr))))
991
992(defun entry-unserialize-field (entry field name prefix)
993 (cond ((equal (cadr field) 'uint)
994 (format "%sif (! (* source->next_uint) (source, &%s)) goto bail;\n" prefix name))
995 ((equal (cadr field) 'uint32)
996 (format "%sif (! (* source->next_uint32) (source, &%s)) goto bail;\n" prefix name))
997 ((equal (cadr field) 'uint16)
998 (format "%sif (! (* source->next_uint16) (source, &%s)) goto bail;\n" prefix name))
999 ((equal (cadr field) 'uint8)
1000 (format "%sif (! (* source->next_uint8) (source, &%s)) goto bail;\n" prefix name))
1001 ((equal (cadr field) 'boolean)
1002 (format "%sif (! (* source->next_bool) (source, &%s)) goto bail;\n" prefix name))
1003 ((equal (cadr field) 'string)
1004 (format "%sif (! (* source->next_string) (source, &%s)) goto bail;\n" prefix name))
1005 ((equal (cadr field) 'bytes)
1006 (format "%sif (! (* source->next_bytes) (source, &%s, &%s_len)) goto bail;\n" prefix name name))
1007 ((equal (cadr field) 'object)
1008 (format "%sif (! serializeio_unserialize_generic_internal (source, &%s_type, &%s, FALSE)) goto bail;\n" prefix name name))
1009 ((member (cadr field) (mapcar (lambda (x) (sertype-name-get x)) *all-sertype-defs*))
1010 (format "%sif (! unserialize_%s_internal_noalloc (source, &%s)) goto bail;\n" prefix (downcase-string (cadr field)) name))
1011 ((and (equal (car (cadr field)) 'ptr)
1012 (member (cadr (cadr field)) (mapcar (lambda (x) (sertype-name-get x)) *all-sertype-defs*)))
1013 (format "%sif (! unserialize_%s_internal (source, &%s)) goto bail;\n" prefix (downcase-string (cadr (cadr field))) name))
1014 ((equal (car (cadr field)) 'bytes)
1015 (format "%sif (! (* source->next_bytes_known) (source, %s, %d)) goto bail;\n" prefix name (cadr (cadr field))))
1016 ((equal (car (cadr field)) 'array)
1017 (format "%s{
1018%s gint i;
1019%s if (! (* source->next_uint) (source, &%s_len)) goto bail;
1020%s if ((%s_len > 0) && ! (%s = serializeio_source_alloc (source, sizeof (%s) * %s_len))) goto bail;
1021%s for (i = 0; i < %s_len; i += 1)
1022%s {
1023%s%s }
1024%s}
1025"
1026 prefix
1027 prefix prefix
1028 name
1029 prefix
1030 name
1031 name
1032 (field-ctype (cadr field))
1033 name
1034 prefix
1035 name
1036 prefix
1037 prefix
1038 (entry-unserialize-field entry (cadr field) (concat "(" name "[i])") (concat prefix " "))
1039 prefix
1040 ))
1041 (t (error "unrecognized field type: %s" (cadr field)))))
1042
1043
1044(defun entry-serialize-field (entry field name prefix is-param)
1045 (cond ((equal (cadr field) 'uint)
1046 (format "%sif (! (* sink->next_uint) (sink, %s)) goto bail;\n" prefix name))
1047 ((equal (cadr field) 'uint16)
1048 (format "%sif (! (* sink->next_uint16) (sink, %s)) goto bail;\n" prefix name))
1049 ((equal (cadr field) 'uint8)
1050 (format "%sif (! (* sink->next_uint8) (sink, %s)) goto bail;\n" prefix name))
1051 ((equal (cadr field) 'uint32)
1052 (format "%sif (! (* sink->next_uint32) (sink, %s)) goto bail;\n" prefix name))
1053 ((equal (cadr field) 'boolean)
1054 (format "%sif (! (* sink->next_bool) (sink, %s)) goto bail;\n" prefix name))
1055 ((equal (cadr field) 'string)
1056 (format "%sif (! (* sink->next_string) (sink, %s)) goto bail;\n" prefix name))
1057 ((equal (cadr field) 'bytes)
1058 (format "%sif (! (* sink->next_bytes) (sink, %s, %s_len)) goto bail;\n" prefix name name))
1059 ((equal (cadr field) 'object)
1060 (format "%sif (! serializeio_serialize_generic_internal (sink, %s_type, %s, FALSE)) goto bail;\n" prefix name name))
1061 ((member (cadr field) (mapcar (lambda (x) (sertype-name-get x)) *all-sertype-defs*))
1062 (format "%sif (! serialize_%s_internal (sink%s)) goto bail;\n" prefix (downcase-string (cadr field))
1063 (entry-plist t t (concat name (if is-param "->" ".")) (obj-name-eq (cadr field) *all-sertype-defs*))))
1064 ((and (equal (car (cadr field)) 'ptr)
1065 (member (cadr (cadr field)) (mapcar (lambda (x) (sertype-name-get x)) *all-sertype-defs*)))
1066 (format "%sif (! serialize_%s_internal (sink%s)) goto bail;\n" prefix (downcase-string (cadr (cadr field)))
1067 (entry-plist t t (concat name "->") (obj-name-eq (cadr (cadr field)) *all-sertype-defs*))))
1068 ((equal (car (cadr field)) 'bytes)
1069 (format "%sif (! (* sink->next_bytes_known) (sink, %s, %d)) goto bail;\n" prefix name (cadr (cadr field))))
1070 ((equal (car (cadr field)) 'array)
1071 (format "%s{
1072%s gint i;
1073%s if (! (* sink->next_uint) (sink, %s_len)) goto bail;
1074%s for (i = 0; i < %s_len; i += 1)
1075%s {
1076%s%s }
1077%s}
1078"
1079 prefix prefix prefix
1080 name
1081 prefix
1082 name
1083 prefix
1084 prefix
1085 (entry-serialize-field entry (cadr field) (array-index name (cadr field)) (concat prefix " ") nil)
1086 prefix
1087 ))
1088 (t (error "unrecognized field type: %s" (cadr field)))))
1089
1090(defun array-index (name field)
1091 ;(concat "(" (if (needs-ref field) "&" "") name "[i])")
1092 (concat "(" name "[i])")
1093 )
1094
1095(defun entry-count-field (entry field name prefix is-param)
1096 (cond ((equal (cadr field) 'uint)
1097 ;(format "%ssize += sizeof (guint32);\n" prefix)
1098 ""
1099 )
1100 ((equal (cadr field) 'uint32)
1101 ;(format "%ssize += sizeof (guint32);\n" prefix)
1102 ""
1103 )
1104 ((equal (cadr field) 'uint16)
1105 ;(format "%ssize += sizeof (guint16);\n" prefix)
1106 ""
1107 )
1108 ((equal (cadr field) 'uint8)
1109 ;(format "%ssize += sizeof (guint8);\n" prefix)
1110 ""
1111 )
1112 ((equal (cadr field) 'boolean)
1113 ;(format "%ssize += sizeof (gboolean);\n" prefix)
1114 ""
1115 )
1116 ((equal (cadr field) 'string)
1117 (format "%ssize += strlen (%s) + 1;\n" prefix name)
1118 )
1119 ((equal (cadr field) 'bytes)
1120 (format "%ssize += %s_len;\n" prefix name)
1121 )
1122 ((equal (cadr field) 'object)
1123 (format "%ssize += serializeio_generic_count (%s_type, %s);\n" prefix name name)
1124 )
1125 ((member (cadr field) (mapcar (lambda (x) (sertype-name-get x)) *all-sertype-defs*))
1126 (format "%ssize += serializeio_count_%s_obj (%s%s) - sizeof (Serial%s);\n"
1127 prefix
1128 (downcase-string (cadr field))
1129 (if is-param "" "& ")
1130 name
1131 (cadr field)
1132 )
1133 )
1134 ((and (equal (car (cadr field)) 'ptr)
1135 (member (cadr (cadr field)) (mapcar (lambda (x) (sertype-name-get x)) *all-sertype-defs*)))
1136 (format "%ssize += serializeio_count_%s_obj (%s);\n" prefix (downcase-string (cadr (cadr field))) name)
1137 )
1138 ((equal (car (cadr field)) 'bytes)
1139 ;(format "%ssize += 0;\n" prefix (cadr (cadr field)))
1140 ""
1141 )
1142 ((equal (car (cadr field)) 'array)
1143 (format "%s{
1144%s gint i;
1145%s for (i = 0; i < %s_len; i += 1)
1146%s {
1147%s%s }
1148%s}
1149"
1150 prefix prefix prefix
1151 name
1152 prefix
1153 prefix
1154 (entry-count-array-field entry (cadr field) (array-index name (cadr field)) (concat prefix " ") nil)
1155 prefix
1156 ))
1157 (t (error "unrecognized field type: %s" (cadr field)))))
1158
1159(defun entry-count-array-field (entry field name prefix is-param)
1160 (cond ((equal (cadr field) 'uint)
1161 (format "%ssize += sizeof (guint32);\n" prefix)
1162 )
1163 ((equal (cadr field) 'uint32)
1164 (format "%ssize += sizeof (guint32);\n" prefix)
1165 )
1166 ((equal (cadr field) 'uint16)
1167 (format "%ssize += sizeof (guint16);\n" prefix)
1168 )
1169 ((equal (cadr field) 'uint8)
1170 (format "%ssize += sizeof (guint8);\n" prefix)
1171 )
1172 ((equal (cadr field) 'boolean)
1173 (format "%ssize += sizeof (gboolean);\n" prefix)
1174 )
1175 ((equal (cadr field) 'string)
1176 (format "%ssize += strlen (%s) + 1 + sizeof (void*);\n" prefix name)
1177 )
1178 ((equal (cadr field) 'bytes)
1179 (error "can't do that: bytes1")
1180 )
1181 ((equal (cadr field) 'object)
1182 (error "can't do that: object")
1183 )
1184 ((member (cadr field) (mapcar (lambda (x) (sertype-name-get x)) *all-sertype-defs*))
1185 (format "%ssize += serializeio_count_%s_obj (%s%s);\n"
1186 prefix
1187 (downcase-string (cadr field))
1188 (if is-param "" "& ")
1189 name
1190 (cadr field)
1191 )
1192 )
1193 ((and (equal (car (cadr field)) 'ptr)
1194 (member (cadr (cadr field)) (mapcar (lambda (x) (sertype-name-get x)) *all-sertype-defs*)))
1195 (format "%ssize += serializeio_count_%s_obj (%s) + sizeof (void*);\n" prefix (downcase-string (cadr (cadr field))) name)
1196 )
1197 ((equal (car (cadr field)) 'bytes)
1198 (error "can't do that: bytes2")
1199 )
1200 ((equal (car (cadr field)) 'array)
1201 (error "can't do that: array")
1202 )
1203 (t (error "unrecognized field type: %s" (cadr field)))))
1204
1205(defun entry-print-field (entry field name prefix is-param)
1206 (concat
1207 (format "%sprint_spaces (indent_spaces);\n" prefix)
1208 (if is-param (format "%sg_print (\"%s = \");\n" prefix (car field)) "")
1209 (cond ((equal (cadr field) 'uint)
1210 (format "%sg_print (\"%%d\\n\", %s);\n" prefix name))
1211 ((equal (cadr field) 'uint32)
1212 (format "%sg_print (\"%%d\\n\", %s);\n" prefix name))
1213 ((equal (cadr field) 'uint16)
1214 (format "%sg_print (\"%%d\\n\", %s);\n" prefix name))
1215 ((equal (cadr field) 'uint8)
1216 (format "%sg_print (\"%%d\\n\", %s);\n" prefix name))
1217 ((equal (cadr field) 'boolean)
1218 (format "%sg_print (\"%%s\\n\", %s ? \"true\" : \"false\");\n" prefix name))
1219 ((equal (cadr field) 'string)
1220 (format "%sg_print (\"%%s\\n\", %s);\n" prefix name))
1221 ((equal (cadr field) 'bytes)
1222 (format "%sserializeio_print_bytes (%s, %s_len);\n" prefix name name))
1223 ((equal (cadr field) 'object)
1224 (concat
1225 (if is-param (format "%sg_print (\"{\\n\");\n" prefix) "")
1226 (format "%sserializeio_generic_print (%s_type, %s, indent_spaces + 2);\n" prefix name name)
1227 (format "%sprint_spaces (indent_spaces);\n;\n" prefix)
1228 (if is-param (format "%sg_print (\"}\\n\");\n" prefix) "")
1229 )
1230 )
1231 ((member (cadr field) (mapcar (lambda (x) (sertype-name-get x)) *all-sertype-defs*))
1232 (concat
1233 (if is-param (format "%sg_print (\"{\\n\");\n" prefix) "")
1234 (format "%sserializeio_print_%s_obj (& %s, indent_spaces + 2);\n" prefix (downcase-string (cadr field)) name name)
1235 (format "%sprint_spaces (indent_spaces);\n;\n" prefix)
1236 (if is-param (format "%sg_print (\"}\\n\");\n" prefix) "")
1237 )
1238 )
1239 ((and (equal (car (cadr field)) 'ptr)
1240 (member (cadr (cadr field)) (mapcar (lambda (x) (sertype-name-get x)) *all-sertype-defs*)))
1241 (concat
1242 (if is-param (format "%sg_print (\"{\\n\");\n" prefix) "")
1243 (format "%sserializeio_print_%s_obj (%s, indent_spaces + 2);\n"
1244 prefix (downcase-string (cadr (cadr field))) name name)
1245 (format "%sprint_spaces (indent_spaces);\n;\n" prefix)
1246 (if is-param (format "%sg_print (\"}\\n\");\n" prefix) "")
1247 )
1248 )
1249 ((equal (car (cadr field)) 'bytes)
1250 (format "%sserializeio_print_bytes (%s, %d);\n" prefix name (cadr (cadr field))))
1251 ((equal (car (cadr field)) 'array)
1252 (concat
1253 (if is-param (format "%sg_print (\"{\\n\");\n" prefix) "")
1254 (format "%s{
1255%s gint i;
1256%s for (i = 0; i < %s_len; i += 1)
1257%s {
1258%s print_spaces (indent_spaces);
1259%s g_print (\"%%d:\\n\", i);
1260%s%s }
1261%s}
1262"
1263 prefix prefix prefix
1264 name
1265 prefix
1266 prefix
1267 prefix
1268 prefix
1269 (entry-print-field entry (cadr field) (array-index name (cadr field)) (concat prefix " ") nil)
1270 prefix
1271 )
1272 (if is-param (format "%sg_print (\"}\\n\");\n" prefix) "")))
1273 (t (error "unrecognized field type: %s" (cadr field)))))
1274 )
1275
1276(defconst *event-id* 0)
1277
1278(defconst *event-types* nil)
1279
1280(defun generate-events ()
1281 (let ((events *event-defs*))
1282 (while events
1283
1284 (let* ((event (car events))
1285 (uargs (event-uargs-get event))
1286 (sargs (event-sargs-get event))
1287 (type-prefix (intern (apply (function concat)
1288 (append (mapcar (function (lambda (x) (capitalize1 (cadr x)))) uargs)
1289 (mapcar (function (lambda (x) (capitalize1 x))) sargs)))))
1290 (capprefix (capitalize1 *output-prefix*)))
1291
1292 (if (and (not uargs) (not sargs))
1293 (setq type-prefix "Void"))
1294
1295 (when (not (member type-prefix *event-types*))
1296 (setq *event-types* (cons type-prefix *event-types*))
1297
1298 (output-header-file "_edsio")
1299
1300 (save-excursion
1301 (goto-char *header-typedef-marker*)
1302
1303 (insert (format "/* %s%sEventCode.\n */\n\n" capprefix type-prefix))
1304
1305 (insert (format "typedef struct _%s%sEventCode %s%sEventCode;\n" capprefix type-prefix capprefix type-prefix))
1306 (insert (format "struct _%s%sEventCode { gint code; };\n\n" capprefix type-prefix))
1307
1308 (insert (format "typedef struct _%s%sEvent %s%sEvent;\n" capprefix type-prefix capprefix type-prefix))
1309 (insert (format "struct _%s%sEvent { gint code; const char* srcfile; guint srcline;%s%s };\n\n" capprefix type-prefix (event-struct-entries event) (event-struct-sys-entries event)))
1310 )
1311
1312 (insert (format "void %s_generate_%s_event_internal (%s%sEventCode code, const char* srcfile, gint srcline%s);\n"
1313 *output-prefix*
1314 (downcase-string type-prefix)
1315 capprefix
1316 type-prefix
1317 (event-uargs-plist uargs t)
1318 ))
1319 (insert (format "#define %s_generate_%s_event(ecode%s) %s_generate_%s_event_internal((ecode),__FILE__,__LINE__%s)\n\n"
1320 *output-prefix*
1321 (downcase-string type-prefix)
1322 (event-uargs-alist uargs t)
1323 *output-prefix*
1324 (downcase-string type-prefix)
1325 (event-uargs-mlist uargs t)))
1326
1327 (output-source-file "_edsio")
1328
1329 (insert (format "void\n%s_generate_%s_event_internal (%s%sEventCode _code, const char* _srcfile, gint _srcline%s)\n"
1330 *output-prefix*
1331 (downcase-string type-prefix)
1332 capprefix
1333 type-prefix
1334 (event-uargs-plist uargs t)
1335 ))
1336 (insert (format "{\n"))
1337 (insert (format " %s%sEvent *_e = g_new0 (%s%sEvent, 1);\n" capprefix type-prefix capprefix type-prefix))
1338 (insert (format " _e->code = _code.code;\n _e->srcline = _srcline;\n _e->srcfile = _srcfile;\n"))
1339 (insert (event-uargs-copy "_e" event))
1340 (insert (event-sargs-copy "_e" event))
1341 (insert (format " eventdelivery_event_deliver ((GenericEvent*) _e);\n"))
1342 (insert (format "}\n\n"))
1343
1344 ;; Field to string def
1345
1346 (unless (equal type-prefix "Void")
1347 (save-excursion
1348 (goto-char *source-top-marker*)
1349 (insert (format "static const char* %s_%s_event_field_to_string (GenericEvent* ev, gint field);\n" capprefix type-prefix))
1350 )
1351
1352 (insert (format "const char*\n%s_%s_event_field_to_string (GenericEvent* ev, gint field)\n"
1353 capprefix type-prefix))
1354 (insert (format "{\n"))
1355
1356 (unless (equal type-prefix (intern "Ssl"))
1357 (insert (format " %s%sEvent* it = (%s%sEvent*) ev;\n" capprefix type-prefix capprefix type-prefix)))
1358 (insert (format " switch (field)\n"))
1359 (insert (format " {\n"))
1360
1361 (let ((uargs (event-uargs-get event))
1362 (i 0))
1363 (while uargs
1364 (let ((uarg (car uargs)))
1365 (insert (format " case %d: return eventdelivery_%s_to_string (it->%s);\n" i (cadr uarg) (car uarg)))
1366 )
1367 (setq i (+ i 1))
1368 (setq uargs (cdr uargs))
1369 )
1370 )
1371
1372 (if (< 1 (length (event-sargs-get event)))
1373 (error "unhandled case, too many sargs"))
1374
1375 (when (event-sargs-get event)
1376 (let ((sarg (car (event-sargs-get event))))
1377 (insert (format " case %d: " (length (event-uargs-get event))))
1378
1379 (if (not (member sarg '(ssl errno)))
1380 (error "what type of sarg is %s" sarg))
1381
1382 (if (eq sarg 'errno)
1383 (insert (format "return g_strdup (g_strerror (it->ev_errno));\n")))
1384
1385 (if (eq sarg 'ssl)
1386 (insert (format "return eventdelivery_ssl_errors_to_string ();\n")))
1387 )
1388 )
1389
1390 (insert (format " default: abort ();\n"))
1391 (insert (format " }\n"))
1392
1393 (insert (format "}\n\n"))
1394 )
1395 )
1396
1397 (output-header-file "_edsio")
1398
1399 (insert (format "extern const %s%sEventCode EC_%s%s;\n"
1400 capprefix
1401 type-prefix
1402 capprefix
1403 (event-name-get event)))
1404
1405 (insert (format "#define EC_%s%sValue ((%d<<EDSIO_LIBRARY_OFFSET_BITS)+%d)\n\n"
1406 capprefix
1407 (event-name-get event)
1408 *event-id*
1409 *library-id*))
1410
1411 (output-source-file "_edsio")
1412
1413 (insert (format "const %s%sEventCode EC_%s%s = { EC_%s%sValue };\n\n"
1414 capprefix
1415 type-prefix
1416 capprefix
1417 (event-name-get event)
1418 capprefix
1419 (event-name-get event)))
1420
1421
1422 (save-excursion
1423 (goto-char *source-init-marker*)
1424
1425 (insert (format " eventdelivery_initialize_event_def (EC_%s%sValue, EL_%s, %s, \"%s\", \"%s\", %s);\n"
1426 capprefix
1427 (event-name-get event)
1428 (event-level-get event)
1429 (event-flags-string event)
1430 (event-name-get event)
1431 (fixup-oneline event (event-desc-get event))
1432 (if (equal type-prefix "Void")
1433 "NULL"
1434 (format "& %s_%s_event_field_to_string" capprefix type-prefix))))
1435 )
1436
1437 (setq *event-id* (+ 1 *event-id*))
1438
1439 )
1440
1441 (setq events (cdr events))
1442 )
1443 )
1444 )
1445
1446(defun event-flags-string (event)
1447 (if (member 'ssl (event-sargs-get event))
1448 "EF_OpenSSL"
1449 "EF_None")
1450 )
1451
1452(defun event-struct-entries (event)
1453 (apply (function concat)
1454 (mapcar (function (lambda (x) (format " %s %s;" (event-type-to-ctype (cadr x)) (car x))))
1455 (event-uargs-get event)))
1456 )
1457
1458(defun event-struct-sys-entries (event)
1459 (if (member 'errno (event-sargs-get event))
1460 " gint ev_errno;"
1461 "")
1462 )
1463
1464(defun event-uargs-copy (name event)
1465 (apply (function concat)
1466 (mapcar (function (lambda (x) (format " %s->%s = %s;\n" name (car x) (car x))))
1467 (event-uargs-get event)))
1468 )
1469
1470(defun event-sargs-copy (name event)
1471 (if (member 'errno (event-sargs-get event))
1472 (format " %s->ev_errno = errno;\n" name)
1473 "")
1474 )
1475
1476(defun event-type-to-ctype (etype)
1477 (let ((it (obj-name-eq etype *all-etype-defs*)))
1478 (if (not it)
1479 (message "no ctype for %s" etype))
1480 (etype-ctype-get it)
1481 )
1482 )
1483
1484(defun event-uargs-plist(uargs need_first)
1485 (concat
1486 (if (and need_first uargs) ", " "")
1487 (format-comlist (function (lambda (x) (format "%s %s" (event-type-to-ctype (cadr x)) (car x)))) uargs))
1488 )
1489
1490(defun event-uargs-alist(uargs need_first)
1491 (concat
1492 (if (and need_first uargs) ", " "")
1493 (format-comlist (function (lambda (x) (format "%s" (car x)))) uargs))
1494 )
1495
1496(defun event-uargs-mlist(uargs need_first)
1497 (concat
1498 (if (and need_first uargs) ", " "")
1499 (format-comlist (function (lambda (x) (format "(%s)" (car x)))) uargs))
1500 )
1501
1502(defun fixup-oneline (event oneline)
1503 (let ((work (get-buffer-create "*string-tmp2*")))
1504 (save-excursion
1505 (set-buffer work)
1506 (erase-buffer)
1507 (insert oneline)
1508 (beginning-of-buffer)
1509
1510 (while (re-search-forward "${\\(\\w+\\)}" nil t)
1511
1512 (let* ((it (intern (downcase-string (match-string 1))))
1513 (uargs (event-uargs-get event))
1514 (i 0)
1515 (repl nil))
1516
1517 (while uargs
1518
1519 (if (eq (car (car uargs)) it)
1520 (setq repl (format "${%d}" i)))
1521
1522 (setq uargs (cdr uargs))
1523 (setq i (+ i 1))
1524 )
1525
1526 (when (eq it 'strerror)
1527 (if repl
1528 (error "No wildcards named STRERROR"))
1529 (setq repl (format "${%d}" i))
1530 )
1531
1532 (when (eq it 'ssl)
1533 (if repl
1534 (error "No wildcards named SSL"))
1535 (setq repl (format "${%d}" i))
1536 )
1537
1538 (if (not repl)
1539 (error "Illegal wildcard %s in %s" it oneline))
1540
1541 (replace-match repl nil nil)
1542 )
1543 )
1544
1545 (buffer-string)
1546 )
1547 )
1548 )
1549
1550;; Properties
1551
1552(defun generate-properties ()
1553 (let ((cap-prefix (capitalize1 *output-prefix*))
1554 (unique-types nil))
1555 (output-header-file "_edsio")
1556
1557 (insert (format "/* Property definitions */\n\n"))
1558
1559 ;; Types
1560
1561 (output-source-file "_edsio")
1562
1563 (mapcar
1564 (function
1565 (lambda (pht)
1566 (let ((type (prophosttype-type-get pht)))
1567 (unless (member type unique-types)
1568 (setq unique-types (cons type unique-types))
1569
1570 (save-excursion
1571 (goto-char *source-init-marker*)
1572
1573 ;(message "%s -> %s %s" type (type-free-func type) (member type (mapcar (lambda (x) (sertype-name-get x)) *all-sertype-defs*)))
1574
1575 (insert (format " edsio_initialize_property_type (\"%s\", %s, %s, %s, %s, %s);\n"
1576 type
1577 (type-free-func type)
1578 (type-gs-func type "getter")
1579 (type-gs-func type "setter")
1580 (type-serialize-func type)
1581 (type-unserialize-func type)))
1582 )
1583 )
1584 )
1585 )
1586 )
1587 *prophosttype-defs*
1588 )
1589
1590 ;; Host reg
1591
1592 (mapcar
1593 (function
1594 (lambda (prophost)
1595 (save-excursion
1596 (goto-char *source-init-marker*)
1597 (insert (format " edsio_initialize_host_type (\"%s\", %s, %s, %s, %s, %s);\n"
1598 (prophost-name-get prophost)
1599 (format "(PropertyTableFunc) & edsio_%s_property_table"
1600 (downcase-string (prophost-name-get prophost)))
1601 (prophost-persist prophost "source")
1602 (prophost-persist prophost "sink")
1603 (prophost-persist prophost "isset")
1604 (prophost-persist prophost "unset")
1605 ))
1606 )
1607 )
1608 )
1609 *prophost-defs*)
1610
1611 ;; Compute each distinct (host type) x (prop type)
1612
1613 (mapcar
1614 (function
1615 (lambda (prophost)
1616
1617 (mapcar
1618 (function
1619 (lambda (prophosttype)
1620
1621 (when (equal (prophosttype-host-get prophosttype) (prophost-name-get prophost))
1622
1623 (when (not (member (prophosttype-type-get prophosttype) (prophost-proptypes-get prophost)))
1624 (prophost-proptypes-set prophost (cons (prophosttype-type-get prophosttype) (prophost-proptypes-get prophost)))
1625 )
1626 )))
1627 *prophosttype-defs*
1628 )
1629
1630 ;; Output the get/set functions for each property type
1631
1632 (mapcar
1633 (function
1634 (lambda (type)
1635
1636 (let ((it (property-code-typename type prophost)))
1637
1638 ;; Header
1639
1640 (output-header-file "_edsio")
1641
1642 (insert (format "/* Property get/set for %s/%s\n */\n\n" (prophost-name-get prophost) type))
1643
1644 (insert (format "typedef struct _%s %s;\n" it it))
1645
1646 (insert (format "struct _%s { guint32 code; };\n\n" it))
1647
1648 (insert (format "gboolean edsio_new_%s_%s_property (const char* name, guint32 flags, %s* prop);\n"
1649 (downcase-string (prophost-name-get prophost))
1650 (type-canon-name type)
1651 it
1652 ))
1653
1654 (insert (format "gboolean %s_get_%s (%s obj, %s prop%s);\n"
1655 (downcase-string (prophost-name-get prophost))
1656 (type-canon-name type)
1657 (prophost-ctype-get prophost)
1658 it
1659 (prop-type-to-get-fps type)))
1660
1661 (insert (format "gboolean %s_set_%s (%s obj, %s prop%s);\n"
1662 (downcase-string (prophost-name-get prophost))
1663 (type-canon-name type)
1664 (prophost-ctype-get prophost)
1665 it
1666 (prop-type-to-set-fps type)))
1667
1668 (insert (format "gboolean %s_unset_%s (%s obj, %s prop);\n"
1669 (downcase-string (prophost-name-get prophost))
1670 (type-canon-name type)
1671 (prophost-ctype-get prophost)
1672 it))
1673
1674 (insert (format "gboolean %s_isset_%s (%s obj, %s prop);\n\n"
1675 (downcase-string (prophost-name-get prophost))
1676 (type-canon-name type)
1677 (prophost-ctype-get prophost)
1678 it))
1679
1680 ;; Source
1681
1682 (output-source-file "_edsio")
1683
1684 (insert (format "gboolean edsio_new_%s_%s_property (const char* name, guint32 flags, %s* prop)\n{\n"
1685 (downcase-string (prophost-name-get prophost))
1686 (type-canon-name type)
1687 it
1688 ))
1689 (insert (format " return edsio_new_property (name, \"%s\", \"%s\", flags, (EdsioGenericProperty*) prop);\n" (prophost-name-get prophost) type))
1690 (insert (format "}\n\n"))
1691
1692 (insert (format "gboolean\n%s_get_%s (%s obj, %s prop%s)\n{\n"
1693 (downcase-string (prophost-name-get prophost))
1694 (type-canon-name type)
1695 (prophost-ctype-get prophost)
1696 it
1697 (prop-type-to-get-fps type)))
1698 (insert (format " EdsioProperty* ep;\n"))
1699 (insert (format " g_return_val_if_fail (obj, FALSE);\n"))
1700 (insert (format " return (* edsio_property_getter (\"%s\", \"%s\", prop.code, & ep)) (obj, ep%s);\n"
1701 (prophost-name-get prophost)
1702 type
1703 (prop-type-to-args type)
1704 ))
1705
1706 (insert (format "}\n\n"))
1707
1708 (insert (format "gboolean\n%s_set_%s (%s obj, %s prop%s)\n{\n"
1709 (downcase-string (prophost-name-get prophost))
1710 (type-canon-name type)
1711 (prophost-ctype-get prophost)
1712 it
1713 (prop-type-to-set-fps type)))
1714 (insert (format " EdsioProperty* ep;\n"))
1715 (insert (format " g_return_val_if_fail (obj, FALSE);\n"))
1716 (insert (format " return (* edsio_property_setter (\"%s\", \"%s\", prop.code, & ep)) (obj, ep%s);\n"
1717 (prophost-name-get prophost)
1718 type
1719 (prop-type-to-args type)
1720 ))
1721
1722 (insert (format "}\n\n"))
1723
1724 (insert (format "gboolean\n%s_unset_%s (%s obj, %s prop)\n{\n"
1725 (downcase-string (prophost-name-get prophost))
1726 (type-canon-name type)
1727 (prophost-ctype-get prophost)
1728 it))
1729 (insert (format " g_return_val_if_fail (obj, FALSE);\n"))
1730 (insert (format " return edsio_property_unset (\"%s\", \"%s\", prop.code, obj);\n"
1731 (prophost-name-get prophost)
1732 type
1733 ""
1734 ))
1735
1736 (insert (format "}\n\n"))
1737
1738 (insert (format "gboolean\n%s_isset_%s (%s obj, %s prop)\n{\n"
1739 (downcase-string (prophost-name-get prophost))
1740 (type-canon-name type)
1741 (prophost-ctype-get prophost)
1742 it))
1743 (insert (format " g_return_val_if_fail (obj, FALSE);\n"))
1744 (insert (format " return edsio_property_isset (\"%s\", \"%s\", prop.code, obj);\n"
1745 (prophost-name-get prophost)
1746 type
1747 ))
1748
1749 (insert (format "}\n\n"))
1750
1751 )
1752 )
1753 )
1754 (prophost-proptypes-get prophost)
1755 )
1756 )
1757 )
1758 *all-prophost-defs*
1759 )
1760 )
1761 )
1762
1763(defun property-code-typename(type prophost)
1764 (format "%s%s%sProperty"
1765 (capitalize1 *output-prefix*)
1766 (prophost-name-get prophost)
1767 (capitalize1 type))
1768 )
1769
1770(defun prop-typename-ctypes (type)
1771 (cond ((equal type 'string)
1772 (list (list 'arg "const gchar*")))
1773 ((equal type 'uint)
1774 (list (list 'arg "guint32")))
1775 ((equal type 'uint32)
1776 (list (list 'arg "guint32")))
1777 ((equal type 'uint16)
1778 (list (list 'arg "guint16")))
1779 ((equal type 'uint8)
1780 (list (list 'arg "guint8")))
1781 ((equal type 'boolean)
1782 (list (list 'arg "gboolean")))
1783 ((equal type 'bytes)
1784 (list (list 'arg "const guint8*") (list 'arg_len "guint32")))
1785 ((equal type 'object)
1786 (list (list 'arg "void*") (list 'arg_type "guint32")))
1787 ((member type (mapcar (lambda (x) (sertype-name-get x)) *all-sertype-defs*))
1788 (list (list 'arg (format "Serial%s*" type))))
1789 ((equal (car type) 'bytes)
1790 (list (list 'arg "const guint8*")))
1791 ((equal (car type) 'array)
1792 (list (list 'arg (format "%s*" (cadr (car (prop-typename-ctypes (cadr type))))))
1793 (list 'arg_len "guint32")))
1794 ((equal (car type) 'ptr)
1795 (list (list 'arg (format "%s*" (cadr (car (prop-typename-ctypes (cadr type))))))))
1796 (t (error "unrecognized field type: %s" type)))
1797 )
1798
1799(defun prop-type-to-get-fps (type)
1800 (concat ", "
1801 (format-comlist
1802 (function
1803 (lambda (pair)
1804 (format "%s* %s" (cadr pair) (car pair))
1805 )
1806 )
1807 (prop-typename-ctypes type))
1808 )
1809 )
1810
1811(defun prop-type-to-set-fps (type)
1812 (concat ", "
1813 (format-comlist
1814 (function
1815 (lambda (pair)
1816 (format "%s %s" (cadr pair) (car pair))
1817 )
1818 )
1819 (prop-typename-ctypes type))
1820 )
1821 )
1822
1823(defun prop-type-to-args (type)
1824 (concat ", "
1825 (format-comlist
1826 (function
1827 (lambda (pair)
1828 (format "%s" (car pair))
1829 )
1830 )
1831 (prop-typename-ctypes type))
1832 )
1833 )
1834
1835(defun type-canon-name (type)
1836 ; @@@ does not work for (array ...), etc
1837 (downcase-string type))
1838
1839(defun type-serialize-func (type)
1840 (format "serialize_%s_obj" (downcase-string type))
1841 )
1842
1843(defun type-unserialize-func (type)
1844 (format "unserialize_%s" (downcase-string type))
1845 )
1846
1847(defun type-gs-func (type name)
1848 (if (member type (mapcar (lambda (x) (sertype-name-get x)) *all-sertype-defs*))
1849 (format "& edsio_property_vptr_%s" name)
1850 (format "& edsio_property_%s_%s" type name)))
1851
1852(defun type-free-func (type)
1853 (if (member type (mapcar (lambda (x) (sertype-name-get x)) *all-sertype-defs*))
1854 (format "& edsio_property_vptr_free")
1855 (format "& edsio_property_%s_free" type)))
1856
1857(defun prophost-persist (prophost func)
1858 (if (prophost-persist-get prophost)
1859 (format "(Persist%sFunc) & %s_persist_%s_%s"
1860 (capitalize1 func)
1861 *output-prefix*
1862 (downcase-string (prophost-name-get prophost))
1863 func)
1864 "NULL"))
diff --git a/xdelta1/libedsio/edsio.h b/xdelta1/libedsio/edsio.h
deleted file mode 100644
index 98f899e..0000000
--- a/xdelta1/libedsio/edsio.h
+++ /dev/null
@@ -1,531 +0,0 @@
1/* -*-Mode: C;-*-
2 * $Id: edsio.h 1.1 Sun, 28 Jan 2007 10:02:26 -0800 jmacd $
3 *
4 * Copyright (C) 1998, 1999, Josh MacDonald.
5 * All Rights Reserved.
6 *
7 * Author: Josh MacDonald <jmacd@CS.Berkeley.EDU>
8 */
9
10#ifndef _EDSIO_H_
11#define _EDSIO_H_
12
13#ifdef __cplusplus
14extern "C" {
15#endif
16
17#ifdef HAVE_CONFIG_H
18#include <config.h>
19#endif
20
21#include <stdlib.h>
22#include <string.h>
23#include <glib.h>
24
25typedef struct _SerialSource SerialSource;
26typedef struct _SerialSink SerialSink;
27typedef gint32 SerialType;
28typedef struct _HandleFuncTable HandleFuncTable;
29typedef struct _PropTest PropTest;
30typedef struct _FileHandle FileHandle;
31typedef struct _AllocList AllocList;
32
33struct _FileHandle {
34 const HandleFuncTable* table;
35
36 /* This is an opaque type, feel free to define your own, just make
37 * sure that the first field of yours is one of these, and that you
38 * supply a table. */
39};
40
41#define EDSIO_LIBRARY_OFFSET_BITS 8
42#define EDSIO_LIBRARY_OFFSET_MASK 0xff
43
44#include "edsio_edsio.h"
45
46#define ST_Error -1
47#define ST_IncorrectType -2
48#define ST_NotFound -3
49
50#define ALIGN_8(v) if (((v) % 8) != 0) { (v) += 8; (v) &= ~7; }
51
52/* This serves as a virtual table for I/O to the FileHandle */
53struct _HandleFuncTable
54{
55 gssize (* table_handle_length) (FileHandle *fh);
56 gssize (* table_handle_pages) (FileHandle *fh);
57 gssize (* table_handle_pagesize) (FileHandle *fh);
58 gssize (* table_handle_map_page) (FileHandle *fh, guint pgno, const guint8** mem);
59 gboolean (* table_handle_unmap_page) (FileHandle *fh, guint pgno, const guint8** mem);
60 const guint8* (* table_handle_checksum_md5) (FileHandle *fh);
61 gboolean (* table_handle_close) (FileHandle *fh, gint flags);
62 gboolean (* table_handle_write) (FileHandle *fh, const guint8 *buf, gsize nbyte);
63 gboolean (* table_handle_copy) (FileHandle *from, FileHandle *to, guint off, guint len);
64 gboolean (* table_handle_getui) (FileHandle *fh, guint32* i);
65 gboolean (* table_handle_putui) (FileHandle *fh, guint32 i);
66 gssize (* table_handle_read) (FileHandle *fh, guint8 *buf, gsize nbyte);
67 const gchar* (* table_handle_name) (FileHandle *fh); /* user must free */
68};
69
70struct _AllocList {
71 AllocList *next;
72 void *ptr;
73};
74
75struct _SerialSource {
76 /* Internal variables: don't touch. */
77 AllocList *alloc_list;
78
79 /* These are setup by init.
80 */
81 SerialType (* source_type) (SerialSource* source, gboolean set_allocation);
82 gboolean (* source_close) (SerialSource* source);
83 gboolean (* source_read) (SerialSource* source, guint8 *ptr, guint32 len);
84 void (* source_free) (SerialSource* source);
85
86 /* These may be NULL
87 */
88 void* (* salloc_func) (SerialSource* source,
89 guint32 len);
90 void (* sfree_func) (SerialSource* source,
91 void* ptr);
92
93 /* Public functions, defaulted, but may be over-ridden
94 * before calls to unserialize.
95 */
96 gboolean (* next_bytes_known) (SerialSource* source, guint8 *ptr, guint32 len);
97 gboolean (* next_bytes) (SerialSource* source, const guint8 **ptr, guint32 *len);
98 gboolean (* next_uint) (SerialSource* source, guint32 *ptr);
99 gboolean (* next_uint32) (SerialSource* source, guint32 *ptr);
100 gboolean (* next_uint16) (SerialSource* source, guint16 *ptr);
101 gboolean (* next_uint8) (SerialSource* source, guint8 *ptr);
102 gboolean (* next_bool) (SerialSource* source, gboolean *ptr);
103 gboolean (* next_string) (SerialSource* source, const char **ptr);
104};
105
106struct _SerialSink {
107
108 /* These are setup by init.
109 */
110 gboolean (* sink_type) (SerialSink* sink, SerialType type, guint32 mem_size, gboolean set_allocation);
111 gboolean (* sink_close) (SerialSink* sink);
112 gboolean (* sink_write) (SerialSink* sink, const guint8 *ptr, guint32 len);
113 void (* sink_free) (SerialSink* sink);
114
115 /* This may be null, called after each object is serialized. */
116 gboolean (* sink_quantum) (SerialSink* sink);
117
118 /* Public functions, defaulted, but may be over-ridden
119 * before calls to serialize.
120 */
121 gboolean (* next_bytes_known) (SerialSink* sink, const guint8 *ptr, guint32 len);
122 gboolean (* next_bytes) (SerialSink* sink, const guint8 *ptr, guint32 len);
123 gboolean (* next_uint) (SerialSink* sink, guint32 ptr);
124 gboolean (* next_uint32) (SerialSink* sink, guint32 ptr);
125 gboolean (* next_uint16) (SerialSink* sink, guint16 ptr);
126 gboolean (* next_uint8) (SerialSink* sink, guint8 ptr);
127 gboolean (* next_bool) (SerialSink* sink, gboolean ptr);
128 gboolean (* next_string) (SerialSink* sink, const char *ptr);
129};
130
131void serializeio_initialize_type (const char* name,
132 guint32 val,
133 gboolean (*unserialize_func) (),
134 gboolean (*serialize_func) (),
135 guint (*count_func) (),
136 void (*print_func) ());
137
138const char* serializeio_generic_type_to_string (SerialType type);
139void serializeio_generic_print (SerialType type, void* object, guint indent_spaces);
140
141gboolean serializeio_serialize_generic (SerialSink *sink,
142 SerialType object_type,
143 void *object);
144
145gboolean serializeio_serialize_generic_internal (SerialSink *sink,
146 SerialType object_type,
147 void *object,
148 gboolean set_allocation);
149
150guint serializeio_generic_count (SerialType object_type,
151 void *object);
152
153gboolean serializeio_unserialize_generic (SerialSource *source,
154 SerialType *object_type,
155 void **object);
156
157gboolean serializeio_unserialize_generic_internal (SerialSource *source,
158 SerialType *object_type,
159 void **object,
160 gboolean set_allocation);
161
162gboolean serializeio_unserialize_generic_acceptable (SerialSource* source,
163 guint32 acceptable,
164 SerialType *object_type,
165 void **object);
166
167void serializeio_sink_init (SerialSink* sink,
168 gboolean (* sink_type) (SerialSink* sink,
169 SerialType type,
170 guint32 mem_size,
171 gboolean set_allocation),
172 gboolean (* sink_close) (SerialSink* sink),
173 gboolean (* sink_write) (SerialSink* sink,
174 const guint8 *ptr,
175 guint32 len),
176 void (* sink_free) (SerialSink* sink),
177 gboolean (* sink_quantum) (SerialSink* sink));
178
179void serializeio_source_init (SerialSource* source,
180 SerialType (* source_type) (SerialSource* source,
181 gboolean set_allocation),
182 gboolean (* source_close) (SerialSource* source),
183 gboolean (* source_read) (SerialSource* source,
184 guint8 *ptr,
185 guint32 len),
186 void (* source_free) (SerialSource* source),
187 void* (* salloc_func) (SerialSource* source,
188 guint32 len),
189 void (* sfree_func) (SerialSource* source,
190 void* ptr));
191
192/* This function is internal, don't use. */
193void* serializeio_source_alloc (SerialSource* source,
194 guint32 len);
195
196SerialSink* serializeio_gzip_sink (SerialSink* sink);
197SerialSource* serializeio_gzip_source (SerialSource* source);
198
199SerialSink* serializeio_checksum_sink (SerialSink* sink);
200SerialSource* serializeio_checksum_source (SerialSource* source);
201
202SerialSink* serializeio_base64_sink (SerialSink* sink);
203SerialSource* serializeio_base64_source (SerialSource* source);
204
205SerialSource* handle_source (FileHandle *fh);
206SerialSink* handle_sink (FileHandle *fh,
207 gpointer data1,
208 gpointer data2,
209 gpointer data3,
210 gboolean (* cont_onclose) (gpointer data1, gpointer data2, gpointer data3));
211
212gboolean unserialize_uint (SerialSource *source, guint32** x);
213gboolean serialize_uint_obj (SerialSink *sink, guint32* x);
214
215gboolean unserialize_string (SerialSource *source, const char** x);
216gboolean serialize_string_obj (SerialSink *sink, const char* x);
217
218/* These are a bit odd, and edsio_property_bytes_{g,s}etter account for it.
219 * Try not to use yourself. */
220gboolean unserialize_bytes (SerialSource *source, SerialEdsioBytes** x);
221gboolean serialize_bytes_obj (SerialSink *sink, SerialEdsioBytes *x);
222
223/* Event delivery
224 */
225
226enum _EventLevel
227{
228 EL_Information = 1<<0,
229 EL_Warning = 1<<5,
230 EL_Error = 1<<10,
231 EL_InternalError = 1<<15,
232 EL_FatalError = 1<<20
233};
234
235typedef enum _EventLevel EventLevel;
236
237enum _EventFlags
238{
239 EF_None = 1<<0,
240 EF_OpenSSL = 1<<1
241};
242
243typedef enum _EventFlags EventFlags;
244
245const char* eventdelivery_int_to_string (int x);
246const char* eventdelivery_string_to_string (const char* x);
247const char* eventdelivery_source_to_string (SerialSource* x);
248const char* eventdelivery_sink_to_string (SerialSink* x);
249const char* eventdelivery_handle_to_string (FileHandle* x);
250
251void serializeio_print_bytes (const guint8* buf, guint len);
252
253/* Event delivery privates
254 */
255
256typedef struct _GenericEventDef GenericEventDef;
257typedef struct _GenericEvent GenericEvent;
258
259struct _GenericEvent
260{
261 gint code;
262 const char* srcfile;
263 guint srcline;
264};
265
266GenericEventDef* eventdelivery_event_lookup (gint code);
267
268void eventdelivery_event_deliver (GenericEvent* e);
269
270typedef gboolean (* ErrorDeliveryFunc) (GenericEvent* ev, GenericEventDef* def, const char* message);
271
272void eventdelivery_event_watch_all (ErrorDeliveryFunc func);
273
274void eventdelivery_initialize_event_def (gint code,
275 gint level,
276 gint flags,
277 const char* name,
278 const char* oneline,
279 const char * (* field_to_string) (GenericEvent* ev, gint field));
280
281const char* eventdelivery_ssl_errors_to_string (void);
282
283struct _GenericEventDef
284{
285 gint code;
286 gint level;
287 gint flags;
288 const char *name;
289 const char *oneline;
290
291 const char * (* field_to_string) (GenericEvent* ev, gint field);
292};
293
294/* MD5.H - header file for MD5C.C */
295
296/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
297 rights reserved.
298
299 License to copy and use this software is granted provided that it
300 is identified as the "RSA Data Security, Inc. MD5 Message-Digest
301 Algorithm" in all material mentioning or referencing this software
302 or this function.
303
304 License is also granted to make and use derivative works provided
305 that such works are identified as "derived from the RSA Data
306 Security, Inc. MD5 Message-Digest Algorithm" in all material
307 mentioning or referencing the derived work.
308
309 RSA Data Security, Inc. makes no representations concerning either
310 the merchantability of this software or the suitability of this
311 software for any particular purpose. It is provided "as is"
312 without express or implied warranty of any kind.
313
314 These notices must be retained in any copies of any part of this
315 documentation and/or software.
316 */
317
318/* MD5 context. */
319typedef struct {
320 guint32 state[4]; /* state (ABCD) */
321 guint32 count[2]; /* number of bits, modulo 2^64 (lsb first) */
322 guint8 buffer[64]; /* input buffer */
323} EdsioMD5Ctx;
324
325void edsio_md5_init (EdsioMD5Ctx *);
326void edsio_md5_update (EdsioMD5Ctx *, const guint8 *, guint);
327void edsio_md5_final (guint8*, EdsioMD5Ctx *);
328
329gint edsio_md5_equal (gconstpointer v,
330 gconstpointer v2);
331guint edsio_md5_hash (gconstpointer v);
332
333void edsio_md5_to_string (const guint8* md5, char buf[33]);
334gboolean edsio_md5_from_string (guint8* md5, const char buf[33]);
335
336/* NIST Secure Hash Algorithm */
337/* heavily modified from Peter C. Gutmann's implementation */
338/* then taken from from Uwe Hollerbach, */
339/* and then modified a little by Josh MacDonald. */
340
341/* This code is in the public domain */
342
343typedef struct {
344 guint32 digest[5]; /* message digest */
345 guint32 count_lo, count_hi; /* 64-bit bit count */
346 guint32 data[16]; /* SHA data buffer */
347 int local; /* unprocessed amount in data */
348} EdsioSHACtx;
349
350void edsio_sha_init (EdsioSHACtx *);
351void edsio_sha_update (EdsioSHACtx *, const guint8 *, guint);
352void edsio_sha_final (guint8 *, EdsioSHACtx *);
353
354gint edsio_sha_equal (gconstpointer v,
355 gconstpointer v2);
356guint edsio_sha_hash (gconstpointer v);
357
358/* Misc stuff.
359 */
360
361/* These raise an error if errmsg is non-null. The errmsg should
362 * be something like "Invalid port number". See edsio.ser for the
363 * format.
364 */
365gboolean strtosi_checked (const char* str, gint32* i, const char* errmsg);
366gboolean strtoss_checked (const char* str, gint16* s, const char* errmsg);
367
368gboolean strtoui_checked (const char* str, guint32* i, const char* errmsg);
369gboolean strtous_checked (const char* str, guint16* i, const char* errmsg);
370
371const char* edsio_intern_string (const char* str);
372
373GByteArray* edsio_base64_encode_region (const guint8* data, guint data_len);
374GByteArray* edsio_base64_decode_region (const guint8* data, guint data_len);
375gboolean edsio_base64_encode_region_into (const guint8* data, guint data_len, guint8* out, guint *out_len);
376gboolean edsio_base64_decode_region_into (const guint8* data, guint data_len, guint8* out, guint *out_len);
377
378gchar* edsio_time_to_iso8601 (SerialGenericTime* time);
379gchar* edsio_time_t_to_iso8601 (GTime time);
380gboolean edsio_time_of_day (SerialGenericTime* time);
381
382enum _SimpleBufferFlags {
383 SBF_None = 0,
384 SBF_Compress = 1 << 0,
385 SBF_Checksum = 1 << 1,
386 SBF_Base64 = 1 << 2
387};
388
389typedef enum _SimpleBufferFlags SimpleBufferFlags;
390
391SerialSource* edsio_simple_source (const guint8* data, guint len, guint flags);
392SerialSink* edsio_simple_sink (gpointer data,
393 guint flags,
394 gboolean free_result,
395 void (* success) (gpointer data, GByteArray* result),
396 GByteArray **result);
397
398gboolean edsio_library_check (guint32 number);
399void edsio_library_register (guint32 number, const char*name);
400
401/* (Persistent) Property stuff.
402 */
403
404enum _PropertyFlags {
405 PF_None = 0,
406 PF_Persistent = 1
407};
408
409typedef enum _PropertyFlags PropertyFlags;
410
411typedef struct _EdsioProperty EdsioProperty;
412typedef union _EdsioPropertyEntry EdsioPropertyEntry;
413typedef struct _EdsioGenericProperty EdsioGenericProperty;
414
415typedef void (* PropFreeFunc) (gpointer obj);
416typedef gboolean (* PropGSFunc) (/*gpointer obj, GHashTable** obj_table, EdsioProperty* prop, ... */);
417typedef gboolean (* PropSerialize) (/*SerialSink* sink, ... */);
418typedef gboolean (* PropUnserialize) (/*SerialSource* source, ... */);
419
420typedef GHashTable** (* PropertyTableFunc) (gpointer obj);
421typedef SerialSource* (* PersistSourceFunc) (gpointer obj, const char* prop_name);
422typedef SerialSink* (* PersistSinkFunc) (gpointer obj, const char* prop_name);
423typedef gboolean (* PersistIssetFunc) (gpointer obj, const char* prop_name);
424typedef gboolean (* PersistUnsetFunc) (gpointer obj, const char* prop_name);
425
426void edsio_initialize_property_type (const char* t, PropFreeFunc freer, PropGSFunc getter, PropGSFunc setter, PropSerialize ser, PropUnserialize unser);
427void edsio_initialize_host_type (const char* ph,
428 PropertyTableFunc ptable,
429 PersistSourceFunc source,
430 PersistSinkFunc sink,
431 PersistIssetFunc isset,
432 PersistUnsetFunc unset);
433
434gboolean edsio_property_isset (const char* ph, const char* t, guint32 code, gpointer obj);
435gboolean edsio_property_unset (const char* ph, const char* t, guint32 code, gpointer obj);
436
437PropGSFunc edsio_property_getter (const char* ph, const char* t, guint32 code, EdsioProperty** prop);
438PropGSFunc edsio_property_setter (const char* ph, const char* t, guint32 code, EdsioProperty** prop);
439
440void edsio_property_uint_free (gpointer obj);
441gboolean edsio_property_uint_getter (gpointer obj, EdsioProperty* ep, guint32* get);
442gboolean edsio_property_uint_setter (gpointer obj, EdsioProperty* ep, guint32 set);
443
444void edsio_property_string_free (gpointer obj);
445gboolean edsio_property_string_getter (gpointer obj, EdsioProperty* ep, const char** get);
446gboolean edsio_property_string_setter (gpointer obj, EdsioProperty* ep, const char* set);
447
448void edsio_property_bytes_free (gpointer obj);
449gboolean edsio_property_bytes_getter (gpointer obj, EdsioProperty* ep, guint8** get, guint32 *get_len);
450gboolean edsio_property_bytes_setter (gpointer obj, EdsioProperty* ep, guint8* set, guint32 set_len);
451
452void edsio_property_vptr_free (gpointer obj);
453gboolean edsio_property_vptr_getter (gpointer obj, EdsioProperty* ep, void** get);
454gboolean edsio_property_vptr_setter (gpointer obj, EdsioProperty* ep, void* set);
455
456EdsioPropertyEntry* edsio_property_get (gpointer obj, EdsioProperty* ep);
457gboolean edsio_property_set (gpointer obj, EdsioProperty* ep, EdsioPropertyEntry* set);
458
459gboolean edsio_new_property (const char* name, const char* ph, const char* t, guint32 flags, EdsioGenericProperty* prop);
460
461/* Testing...
462 */
463
464#define DEBUG_LIBEDSIO
465
466#ifdef DEBUG_LIBEDSIO
467struct _PropTest
468{
469 GHashTable* _edsio_property_table;
470
471 GHashTable* ptable;
472
473 const char* kludge;
474};
475
476GHashTable** edsio_proptest_property_table (PropTest *pt);
477SerialSource* edsio_persist_proptest_source (PropTest *pt, const char* prop_name);
478SerialSink* edsio_persist_proptest_sink (PropTest *pt, const char* prop_name);
479gboolean edsio_persist_proptest_isset (PropTest *pt, const char* prop_name);
480gboolean edsio_persist_proptest_unset (PropTest *pt, const char* prop_name);
481
482#endif
483
484/* Missing glib stuff
485 */
486
487typedef struct _GQueue GQueue;
488
489struct _GQueue
490{
491 GList *list;
492 GList *list_end;
493 guint list_size;
494};
495
496/* Queues
497 */
498
499GQueue * g_queue_new (void);
500void g_queue_free (GQueue *q);
501guint g_queue_get_size (GQueue *q);
502void g_queue_push_front (GQueue *q, gpointer data);
503void g_queue_push_back (GQueue *q, gpointer data);
504gpointer g_queue_pop_front (GQueue *q);
505gpointer g_queue_pop_back (GQueue *q);
506
507#define g_queue_empty(queue) \
508 ((((GQueue *)(queue)) && ((GQueue *)(queue))->list) ? FALSE : TRUE)
509
510#define g_queue_peek_front(queue) \
511 ((((GQueue *)(queue)) && ((GQueue *)(queue))->list) ? \
512 ((GQueue *)(queue))->list->data : NULL)
513
514#define g_queue_peek_back(queue) \
515 ((((GQueue *)(queue)) && ((GQueue *)(queue))->list_end) ? \
516 ((GQueue *)(queue))->list_end->data : NULL)
517
518#define g_queue_index(queue,ptr) \
519 ((((GQueue *)(queue)) && ((GQueue *)(queue))->list) ? \
520 g_list_index (((GQueue *)(queue))->list, (ptr)) : -1)
521
522#define g_queue_push g_queue_push_back
523#define g_queue_pop g_queue_pop_front
524#define g_queue_peek g_queue_peek_front
525
526
527#ifdef __cplusplus
528}
529#endif
530
531#endif /* _EDSIO_H_ */
diff --git a/xdelta1/libedsio/edsio.ser b/xdelta1/libedsio/edsio.ser
deleted file mode 100644
index ada3b11..0000000
--- a/xdelta1/libedsio/edsio.ser
+++ /dev/null
@@ -1,129 +0,0 @@
1;; -*- Emacs-Lisp -*-
2
3(defmodule edsio 6 "edsio.h" nil)
4
5(defsertype EdsioUint 1
6 ((val uint))
7 ()
8 )
9
10(defsertype EdsioBytes 2
11 ((val bytes))
12 ()
13 )
14
15(defsertype EdsioString 3
16 ((val string))
17 ()
18 )
19
20(defsertype GenericTime 4
21 ((seconds uint)
22 (nanos uint)
23 )
24 ()
25 )
26
27(defetype source "SerialSource*")
28(defetype sink "SerialSink*")
29(defetype int "int")
30(defetype string "const char*")
31
32(defevent GetTimeOfDayFailure Error () (errno)
33 "Gettimeofday failed: ${STRERROR}")
34
35(defevent TimeFailure Error () (errno)
36 "Time failed: ${STRERROR}")
37
38(defevent UnregisteredType Error ((library int) (number int)) ()
39 "Unregistered serial type: library=${LIBRARY} number=${NUMBER}")
40
41(defevent UnexpectedLibraryType Error ((expected int) (received int)) ()
42 "Unexpected serial library type: expected ${EXPECTED}, received ${RECEIVED}")
43
44(defevent UnexpectedType Error () ()
45 "Unexpected serial type")
46
47(defevent OutputBufferShort Error () ()
48 "Output buffer is too short")
49
50(defevent InvalidBase64Encoding Error () ()
51 "Invalid base64 encoding")
52
53(defevent MissingChecksum Error () ()
54 "Missing embedded checksum in base64 encoding")
55
56(defevent InvalidChecksum Error () ()
57 "Checksum verification failed")
58
59(defevent SourceEof Error ((source source)) ()
60 "${SOURCE}: Unexpected EOF")
61
62(defevent IncorrectAllocation Error ((source source)) ()
63 "${SOURCE}: Incorrect allocation")
64
65(defevent InvalidIntegerString Error ((msg string) (arg string)) ()
66 "${MSG}: not an integer: ${ARG}")
67
68(defevent IntegerOutOfRange Error ((msg string) (arg string)) ()
69 "${MSG}: integer out of range: ${ARG}")
70
71(defevent InvalidIntegerSign Error ((msg string) (arg string)) ()
72 "${MSG}: expected an unsigned integer: ${ARG}")
73
74(defevent DuplicatePropertyTypeRegistered Error ((name string)) ()
75 "Property type registered twice: ${NAME}")
76
77(defevent DuplicateHostTypeRegistered Error ((name string)) ()
78 "Property host registered twice: ${NAME}")
79
80(defevent DuplicatePropertyNameRegistered Warning ((name string)) ()
81 "Property name registered twice (ignored): ${NAME}")
82
83(defevent NoSuchProperty Error ((num int)) ()
84 "Unregistered property: ${NUM}")
85
86(defevent NoSuchPropertyType Error ((name string)) ()
87 "Unregistered property type: ${NAME}")
88
89(defevent NoSuchHostType Error ((name string)) ()
90 "Unregistered host type: ${NAME}")
91
92(defevent WrongHostType Error ((name string) (recv string) (expect string)) ()
93 "Wrong property host type: received ${RECV}, expected ${EXPECT}")
94
95(defevent WrongDataType Error ((name string) (recv string) (expect string)) ()
96 "Wrong property data type: received ${RECV}, expected ${EXPECT}")
97
98(defevent PropertyNotSet Error ((name string)) ()
99 "${NAME} property not set")
100
101(defevent PersistenceUnavailable Error ((name string) (host string)) ()
102 "Persistence is unavailable in host ${HOST} for property ${NAME}")
103
104(defevent InvalidStreamChecksum Error () ()
105 "Incorrect stream checksum")
106
107(defevent InvalidHexDigit Error ((bad string) (ctx string)) ()
108 "Invalid hex digit ${BAD} in context: ${CTX}")
109
110(defevent MD5StringShort Error ((short string)) ()
111 "MD5 string too short: ${SHORT}")
112
113(defevent MD5StringLong Error ((long string)) ()
114 "MD5 string too long: ${LONG}")
115
116(defevent UnregisteredLibrary Error ((number int)) ()
117 "Unregistered library: ${NUMBER}")
118
119(defevent GModuleError Error ((file string) (msg string)) ()
120 "GModule: ${FILE}: ${MSG}")
121
122;; properties
123
124(defprophost PropTest "P" "PropTest*" t)
125
126(defprophosttype PropTest uint)
127(defprophosttype PropTest bytes)
128(defprophosttype PropTest string)
129(defprophosttype PropTest EdsioUint)
diff --git a/xdelta1/libedsio/edsiotest.c b/xdelta1/libedsio/edsiotest.c
deleted file mode 100644
index 1d30dc0..0000000
--- a/xdelta1/libedsio/edsiotest.c
+++ /dev/null
@@ -1,213 +0,0 @@
1/* -*-Mode: C;-*-
2 * $Id: edsiotest.c 1.1 Sun, 28 Jan 2007 10:02:26 -0800 jmacd $
3 *
4 * Copyright (C) 1998, 1999, Josh MacDonald.
5 * All Rights Reserved.
6 *
7 * Author: Josh MacDonald <jmacd@CS.Berkeley.EDU>
8 */
9
10#include "edsio.h"
11
12void
13test1 ()
14{
15 guint32 x = 0;
16
17 PropTest *pt = g_new0 (PropTest, 1);
18
19 EdsioPropTestUintProperty prop;
20
21 g_assert (edsio_edsio_init ());
22
23 g_assert (edsio_new_proptest_uint_property ("Just testing (1)...", PF_Persistent, & prop));
24
25 g_assert (! proptest_isset_uint (pt, prop));
26
27 g_assert (proptest_set_uint (pt, prop, 42));
28
29 g_assert (proptest_isset_uint (pt, prop));
30
31 g_assert (proptest_get_uint (pt, prop, & x) && x == 42);
32
33 /* kill the cache, to test persistence. */
34 pt->_edsio_property_table = NULL;
35
36 g_assert (proptest_get_uint (pt, prop, & x) && x == 42);
37
38 g_assert (proptest_unset_uint (pt, prop));
39
40 g_assert (! proptest_isset_uint (pt, prop));
41
42 g_assert (! pt->_edsio_property_table);
43}
44
45void
46test2 ()
47{
48 const char* str = "hello there";
49 const char* str2;
50 guint32 str2_len;
51
52 PropTest *pt = g_new0 (PropTest, 1);
53
54 EdsioPropTestBytesProperty prop;
55
56 g_assert (edsio_edsio_init ());
57
58 g_assert (edsio_new_proptest_bytes_property ("Just testing (2)...", PF_Persistent, & prop));
59
60 g_assert (! proptest_isset_bytes (pt, prop));
61
62 g_assert (proptest_set_bytes (pt, prop, (guint8*) str, strlen (str) + 1));
63
64 g_assert (proptest_isset_bytes (pt, prop));
65
66 g_assert (proptest_get_bytes (pt, prop, (const guint8**) & str2, & str2_len) && str2_len == (strlen (str) + 1) && strcmp (str, str2) == 0);
67
68 /* kill the cache, to test persistence. */
69 pt->_edsio_property_table = NULL;
70
71 g_assert (proptest_get_bytes (pt, prop, (const guint8**) & str2, & str2_len) && str2_len == (strlen (str) + 1) && strcmp (str, str2) == 0);
72
73 g_assert (proptest_unset_bytes (pt, prop));
74
75 g_assert (! proptest_isset_bytes (pt, prop));
76
77 g_assert (! pt->_edsio_property_table);
78}
79
80void
81test3 ()
82{
83 SerialEdsioUint x;
84 SerialEdsioUint *p;
85 EdsioPropTestEdsioUintProperty prop;
86
87 PropTest *pt = g_new0 (PropTest, 1);
88
89 x.val = 42;
90
91 g_assert (edsio_edsio_init ());
92
93 g_assert (edsio_new_proptest_edsiouint_property ("Just testing (3)...", PF_Persistent, & prop));
94
95 g_assert (! proptest_isset_edsiouint (pt, prop));
96
97 g_assert (proptest_set_edsiouint (pt, prop, & x));
98
99 g_assert (proptest_isset_edsiouint (pt, prop));
100
101 g_assert (proptest_get_edsiouint (pt, prop, & p) && x.val == p->val);
102
103 /* kill the cache, to test persistence. */
104 pt->_edsio_property_table = NULL;
105
106 g_assert (proptest_get_edsiouint (pt, prop, & p) && x.val == p->val);
107
108 g_assert (proptest_unset_edsiouint (pt, prop));
109
110 g_assert (! proptest_isset_edsiouint (pt, prop));
111
112 g_assert (! pt->_edsio_property_table);
113}
114
115void
116test4 ()
117{
118 const char* str = "hello there";
119 const char* str2;
120
121 PropTest *pt = g_new0 (PropTest, 1);
122
123 EdsioPropTestStringProperty prop;
124
125 g_assert (edsio_edsio_init ());
126
127 g_assert (edsio_new_proptest_string_property ("Just testing (4)...", PF_Persistent, & prop));
128
129 g_assert (! proptest_isset_string (pt, prop));
130
131 g_assert (proptest_set_string (pt, prop, str));
132
133 g_assert (proptest_isset_string (pt, prop));
134
135 g_assert (proptest_get_string (pt, prop, & str2) && strcmp (str, str2) == 0);
136
137 /* kill the cache, to test persistence. */
138 pt->_edsio_property_table = NULL;
139
140 g_assert (proptest_get_string (pt, prop, & str2) && strcmp (str, str2) == 0);
141
142 g_assert (proptest_unset_string (pt, prop));
143
144 g_assert (! proptest_isset_string (pt, prop));
145
146 g_assert (! pt->_edsio_property_table);
147}
148
149void test5 ()
150{
151 GByteArray* sink_result;
152 SerialSink* sink = edsio_simple_sink (NULL, SBF_Checksum | SBF_Base64 | SBF_Compress, FALSE, NULL, & sink_result);
153 SerialSource* src;
154 const char* input = "hello there!!!!!!!!";
155 SerialEdsioString *output;
156 guint8 zero[1];
157 zero[0] = 0;
158
159 g_assert (serialize_edsiostring (sink, input));
160
161 g_assert (sink->sink_close (sink));
162
163 g_byte_array_append (sink_result, zero, 1);
164
165 g_print ("%s -> %s\n", input, sink_result->data);
166
167 src = edsio_simple_source (sink_result->data, sink_result->len - 1, SBF_Checksum | SBF_Base64 | SBF_Compress);
168
169 g_assert (unserialize_edsiostring (src, & output));
170
171 g_assert (src->source_close (src));
172
173 g_assert (strcmp (output->val, input) == 0);
174}
175
176void
177test6 ()
178{
179 const char* md5str = "aed3918c4ccb89f2dcf74d5dcab22989";
180 const char* md5strbad1 = "aed3918c4cXb89f2dcf74d5dcab22989";
181 const char* md5strbad2 = "aed3918c4cab89f2dcf74d5dcab22989X";
182 const char* md5strbad3 = "aed3918c4cab89f2dcf74d5dcab2298";
183 char md5str2[33];
184 guint8 md5[16];
185
186 g_assert (! edsio_md5_from_string (md5, md5strbad1));
187 g_assert (! edsio_md5_from_string (md5, md5strbad2));
188 g_assert (! edsio_md5_from_string (md5, md5strbad3));
189
190 g_assert (edsio_md5_from_string (md5, md5str));
191
192 edsio_md5_to_string (md5, md5str2);
193
194 g_assert (strcmp (md5str, md5str2) == 0);
195}
196
197int
198main ()
199{
200 test1 ();
201
202 test2 ();
203
204 test3 ();
205
206 test4 ();
207
208 test5 ();
209
210 test6 ();
211
212 return 0;
213}
diff --git a/xdelta1/libedsio/fh.c b/xdelta1/libedsio/fh.c
deleted file mode 100644
index 6b27cbf..0000000
--- a/xdelta1/libedsio/fh.c
+++ /dev/null
@@ -1,167 +0,0 @@
1/* -*-Mode: C;-*-
2 * $Id: fh.c 1.1 Sun, 28 Jan 2007 10:02:26 -0800 jmacd $
3 *
4 * Copyright (C) 1998, 1999, Josh MacDonald.
5 * All Rights Reserved.
6 *
7 * Author: Josh MacDonald <jmacd@CS.Berkeley.EDU>
8 */
9
10#include "edsio.h"
11
12/* Handle source/sink impls
13 */
14typedef struct _HandleSerialSource HandleSerialSource;
15typedef struct _HandleSerialSink HandleSerialSink;
16
17struct _HandleSerialSource {
18 SerialSource source;
19
20 FileHandle* fh;
21};
22
23struct _HandleSerialSink {
24 SerialSink sink;
25
26 FileHandle* fh;
27 gpointer data1;
28 gpointer data2;
29 gpointer data3;
30 gboolean (* cont_onclose) (gpointer data1, gpointer data2, gpointer data3);
31};
32
33static SerialType handle_source_type (SerialSource* source, gboolean set_allocation);
34static gboolean handle_source_close (SerialSource* source);
35static gboolean handle_source_read (SerialSource* source, guint8 *ptr, guint32 len);
36static void handle_source_free (SerialSource* source);
37
38static gboolean handle_sink_type (SerialSink* sink, SerialType type, guint len, gboolean set_allocation);
39static gboolean handle_sink_close (SerialSink* sink);
40static gboolean handle_sink_write (SerialSink* sink, const guint8 *ptr, guint32 len);
41static void handle_sink_free (SerialSink* sink);
42
43SerialSource*
44handle_source (FileHandle* fh)
45{
46 HandleSerialSource* it = g_new0 (HandleSerialSource, 1);
47
48 serializeio_source_init (&it->source,
49 handle_source_type,
50 handle_source_close,
51 handle_source_read,
52 handle_source_free,
53 NULL,
54 NULL);
55
56 it->fh = fh;
57
58 return &it->source;
59}
60
61SerialSink*
62handle_sink (FileHandle* fh, gpointer data1, gpointer data2, gpointer data3, gboolean (* cont_onclose) (gpointer data1, gpointer data2, gpointer data3))
63{
64 HandleSerialSink* it = g_new0 (HandleSerialSink, 1);
65
66 serializeio_sink_init (&it->sink,
67 handle_sink_type,
68 handle_sink_close,
69 handle_sink_write,
70 handle_sink_free,
71 NULL);
72
73 it->fh = fh;
74 it->data1 = data1;
75 it->data2 = data2;
76 it->data3 = data3;
77 it->cont_onclose = cont_onclose;
78
79 return &it->sink;
80}
81
82SerialType
83handle_source_type (SerialSource* source, gboolean set_allocation)
84{
85 HandleSerialSource* ssource = (HandleSerialSource*) source;
86 guint32 x;
87
88 if (! ssource->fh->table->table_handle_getui (ssource->fh, &x))
89 return ST_Error;
90
91 if (set_allocation)
92 {
93 /* Note: set_allocation is deprecated in 1.1.4 */
94 guint32 bogus;
95 if (! ssource->fh->table->table_handle_getui (ssource->fh, &bogus))
96 return ST_Error;
97 }
98
99 return x;
100}
101
102gboolean
103handle_source_close (SerialSource* source)
104{
105 HandleSerialSource* ssource = (HandleSerialSource*) source;
106
107 return ssource->fh->table->table_handle_close (ssource->fh, 0);
108}
109
110gboolean
111handle_source_read (SerialSource* source, guint8 *ptr, guint32 len)
112{
113 HandleSerialSource* ssource = (HandleSerialSource*) source;
114
115 return ssource->fh->table->table_handle_read (ssource->fh, ptr, len) == len;
116}
117
118void
119handle_source_free (SerialSource* source)
120{
121 g_free (source);
122}
123
124gboolean
125handle_sink_type (SerialSink* sink, SerialType type, guint len, gboolean set_allocation)
126{
127 HandleSerialSink* ssink = (HandleSerialSink*) sink;
128
129 if (! ssink->fh->table->table_handle_putui (ssink->fh, type))
130 return FALSE;
131
132 /* Note: set_allocation is deprecated in 1.1.4 */
133 if (set_allocation && ! ssink->fh->table->table_handle_putui (ssink->fh, len))
134 return FALSE;
135
136 return TRUE;
137}
138
139gboolean
140handle_sink_close (SerialSink* sink)
141{
142 HandleSerialSink* ssink = (HandleSerialSink*) sink;
143
144 if (ssink->fh->table->table_handle_close (ssink->fh, 0))
145 {
146 if (ssink->cont_onclose)
147 return ssink->cont_onclose (ssink->data1, ssink->data2, ssink->data3);
148
149 return TRUE;
150 }
151
152 return FALSE;
153}
154
155gboolean
156handle_sink_write (SerialSink* sink, const guint8 *ptr, guint32 len)
157{
158 HandleSerialSink* ssink = (HandleSerialSink*) sink;
159
160 return ssink->fh->table->table_handle_write (ssink->fh, ptr, len);
161}
162
163void
164handle_sink_free (SerialSink* sink)
165{
166 g_free (sink);
167}
diff --git a/xdelta1/libedsio/generic.c b/xdelta1/libedsio/generic.c
deleted file mode 100644
index 96d246a..0000000
--- a/xdelta1/libedsio/generic.c
+++ /dev/null
@@ -1,252 +0,0 @@
1/* -*-Mode: C;-*-
2 * $Id: generic.c 1.1 Sun, 28 Jan 2007 10:02:26 -0800 jmacd $
3 *
4 * Copyright (C) 1998, 1999, Josh MacDonald.
5 * All Rights Reserved.
6 *
7 * Author: Josh MacDonald <jmacd@CS.Berkeley.EDU>
8 */
9
10#include "edsio.h"
11
12/* Type-based selectors for unknown types
13 */
14
15typedef struct {
16 const char* name;
17 gboolean (*unserialize_func) ();
18 gboolean (*serialize_func) ();
19 guint (*count_func) ();
20 void (*print_func) ();
21 guint32 val;
22} SerEntry;
23
24static GArray *ser_array;
25static gboolean ser_array_sorted;
26
27void
28serializeio_initialize_type (const char* name,
29 guint32 val,
30 gboolean (*unserialize_func) (),
31 gboolean (*serialize_func) (),
32 guint (*count_func) (),
33 void (*print_func) ())
34{
35 SerEntry it;
36
37 it.name = name;
38 it.val = val;
39 it.unserialize_func = unserialize_func;
40 it.serialize_func = serialize_func;
41 it.count_func = count_func;
42 it.print_func = print_func;
43
44 if (ser_array == NULL)
45 ser_array = g_array_new (FALSE, TRUE, sizeof (SerEntry));
46
47 g_array_append_val (ser_array, it);
48
49 ser_array_sorted = FALSE;
50}
51
52static int
53ser_entry_compare (const void* va, const void* vb)
54{
55 SerEntry* a = (SerEntry*) va;
56 SerEntry* b = (SerEntry*) vb;
57
58 return a->val - b->val;
59}
60
61static SerEntry*
62serializeio_find_entry (SerialType type)
63{
64 if (! edsio_library_check (type & EDSIO_LIBRARY_OFFSET_MASK))
65 return NULL;
66
67 if (ser_array)
68 {
69 gint high_index = ser_array->len;
70 gint low_index = 0;
71 gint index;
72 gint this_val;
73
74 if (! ser_array_sorted)
75 {
76 ser_array_sorted = TRUE;
77 qsort (ser_array->data, ser_array->len, sizeof (SerEntry), ser_entry_compare);
78 }
79
80 again:
81
82 index = (low_index + high_index) / 2;
83
84 this_val = g_array_index (ser_array, SerEntry, index).val;
85
86 if (this_val < type)
87 {
88 low_index = index + 1;
89 goto again;
90 }
91 else if (this_val > type)
92 {
93 high_index = index - 1;
94 goto again;
95 }
96 else
97 {
98 return & g_array_index (ser_array, SerEntry, index);
99 }
100 }
101
102 edsio_generate_intint_event (EC_EdsioUnregisteredType,
103 type & EDSIO_LIBRARY_OFFSET_MASK,
104 type >> EDSIO_LIBRARY_OFFSET_BITS);
105 return NULL;
106}
107
108gboolean
109serializeio_unserialize_generic_internal (SerialSource *source,
110 SerialType *object_type,
111 void **object,
112 gboolean set_allocation)
113{
114 SerialType type = (* source->source_type) (source, set_allocation);
115 SerEntry* ent;
116 gboolean res = FALSE;
117
118 if (type < 0)
119 return FALSE;
120
121 ent = serializeio_find_entry (type);
122
123 (*object_type) = type;
124
125 if (ent)
126 {
127 res = ent->unserialize_func (source, object);
128 }
129
130 return res;
131}
132
133gboolean
134serializeio_unserialize_generic (SerialSource *source,
135 SerialType *object_type,
136 void **object)
137{
138 return serializeio_unserialize_generic_internal (source, object_type, object, TRUE);
139}
140
141gboolean
142serializeio_serialize_generic (SerialSink *sink,
143 SerialType object_type,
144 void *object)
145{
146 return serializeio_serialize_generic_internal (sink, object_type, object, TRUE);
147}
148
149gboolean
150serializeio_serialize_generic_internal (SerialSink *sink,
151 SerialType object_type,
152 void *object,
153 gboolean set_allocation)
154{
155 SerEntry* ent;
156 gboolean res = FALSE;
157
158 if (! (* sink->sink_type) (sink, object_type, set_allocation ? serializeio_generic_count (object_type, object) : 0, set_allocation))
159 return FALSE;
160
161 ent = serializeio_find_entry (object_type);
162
163 if (ent)
164 res = ent->serialize_func (sink, object);
165
166 return res;
167}
168
169const char*
170serializeio_generic_type_to_string (SerialType type)
171{
172 SerEntry* ent;
173 const char* res = "*Unknown*";
174
175 ent = serializeio_find_entry (type);
176
177 if (ent)
178 res = ent->name;
179
180 return res;
181}
182
183guint
184serializeio_generic_count (SerialType object_type,
185 void *object)
186{
187 SerEntry* ent;
188 gboolean res = FALSE;
189
190 ent = serializeio_find_entry (object_type);
191
192 if (ent)
193 res = ent->count_func (object);
194
195 return res;
196}
197
198void
199serializeio_generic_print (SerialType type, void* object, guint indent_spaces)
200{
201 SerEntry* ent;
202
203 ent = serializeio_find_entry (type);
204
205 if (ent)
206 ent->print_func (object, indent_spaces);
207 else
208 {
209 int i = 0;
210
211 for (; i < indent_spaces; i += 1)
212 g_print (" ");
213
214 g_print ("*Type Not Registered*\n");
215 }
216}
217
218gboolean
219serializeio_unserialize_generic_acceptable (SerialSource *source,
220 guint32 accept,
221 SerialType *object_type,
222 void **object)
223{
224 gboolean s;
225
226 s = serializeio_unserialize_generic (source, object_type, object);
227
228 if (s)
229 {
230 if (accept != -1)
231 {
232 if ((*object_type & EDSIO_LIBRARY_OFFSET_MASK) != (accept & EDSIO_LIBRARY_OFFSET_MASK))
233 {
234 edsio_generate_intint_event (EC_EdsioUnexpectedLibraryType,
235 accept & EDSIO_LIBRARY_OFFSET_MASK,
236 *object_type & EDSIO_LIBRARY_OFFSET_MASK);
237
238 return FALSE;
239 }
240
241 if (! ((*object_type & ~EDSIO_LIBRARY_OFFSET_MASK) |
242 (accept & ~EDSIO_LIBRARY_OFFSET_MASK)))
243 {
244 edsio_generate_void_event (EC_EdsioUnexpectedType);
245
246 return FALSE;
247 }
248 }
249 }
250
251 return s;
252}
diff --git a/xdelta1/libedsio/library.c b/xdelta1/libedsio/library.c
deleted file mode 100644
index f13193c..0000000
--- a/xdelta1/libedsio/library.c
+++ /dev/null
@@ -1,121 +0,0 @@
1/* -*-Mode: C;-*-
2 * $Id: library.c 1.1 Sun, 28 Jan 2007 10:02:26 -0800 jmacd $
3 *
4 * Copyright (C) 1998, 1999, Josh MacDonald.
5 * All Rights Reserved.
6 *
7 * Author: Josh MacDonald <jmacd@CS.Berkeley.EDU>
8 */
9
10#include "edsio.h"
11#include <gmodule.h>
12
13typedef struct _Library Library;
14
15struct _Library {
16 const char* name;
17 const char* libname;
18 gint index;
19 gboolean loaded;
20};
21
22static Library known_libraries[] = {
23 { "xd", "xdelta", 3 },
24 { "edsio", "edsio", 6 },
25};
26
27static GHashTable* loaded_libraries;
28
29static void
30edsio_library_init ()
31{
32 if (! loaded_libraries)
33 {
34 gint i;
35 gint n = sizeof (known_libraries) / sizeof (Library);;
36
37 loaded_libraries = g_hash_table_new (g_int_hash, g_int_equal);
38
39 for (i = 0; i < n; i += 1)
40 {
41 Library* lib = known_libraries + i;
42
43 g_hash_table_insert (loaded_libraries, & lib->index, lib);
44 }
45 }
46}
47
48void
49edsio_library_register (guint32 number, const char* name)
50{
51 Library* lib;
52
53 edsio_library_init ();
54
55 lib = g_hash_table_lookup (loaded_libraries, & number);
56
57 if (lib)
58 {
59 lib->loaded = TRUE;
60 return;
61 }
62
63 lib = g_new0 (Library, 1);
64
65 lib->index = number;
66 lib->name = name;
67 lib->loaded = TRUE;
68
69 g_hash_table_insert (loaded_libraries, & lib->index, lib);
70}
71
72gboolean
73edsio_library_check (guint32 number)
74{
75 Library* lib;
76
77 edsio_library_init ();
78
79 lib = g_hash_table_lookup (loaded_libraries, & number);
80
81 if (lib)
82 {
83 lib->loaded = TRUE;
84 return TRUE;
85 }
86
87#if 0
88 if (lib->libname && g_module_supported ())
89 {
90 GModule *module;
91 GString *module_name = g_string_new (NULL);
92 GString *symbol_name = g_string_new (NULL);
93 gboolean (* init) (void);
94
95 if (! (module = g_module_open (module_name->str, 0)))
96 {
97 edsio_generate_stringstring_event (EC_EdsioGModuleError, module_name->str, g_module_error ());
98 return FALSE;
99 }
100
101 if (! g_module_symbol (module,
102 symbol_name->str,
103 (void**) & init))
104 {
105 edsio_generate_stringstring_event (EC_EdsioGModuleError, g_module_name (module), g_module_error ());
106 return FALSE;
107 }
108
109 g_module_make_resident (module);
110
111 g_module_close (module);
112
113 lib->loaded = TRUE;
114
115 return (* init) ();
116 }
117#endif
118
119 edsio_generate_int_event (EC_EdsioUnregisteredLibrary, number);
120 return FALSE;
121}
diff --git a/xdelta1/libedsio/maketime.c b/xdelta1/libedsio/maketime.c
deleted file mode 100644
index 5feddae..0000000
--- a/xdelta1/libedsio/maketime.c
+++ /dev/null
@@ -1,391 +0,0 @@
1/* Convert struct partime into time_t. */
2
3/* Copyright 1992, 1993, 1994, 1995, 1997 Paul Eggert
4 Distributed under license by the Free Software Foundation, Inc.
5
6 This file is part of RCS.
7
8 RCS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 RCS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with RCS; see the file COPYING.
20 If not, write to the Free Software Foundation,
21 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
23 Report problems and direct all questions to:
24
25 rcs-bugs@cs.purdue.edu
26
27 */
28
29#if has_conf_h
30# include <conf.h>
31#else
32# if HAVE_CONFIG_H
33# include <config.h>
34# else
35# ifndef __STDC__
36# define const
37# endif
38# endif
39 /* MIPS RISCOS4.52 defines time_t in <sys/types.h> not <time.h>. */
40# include <sys/types.h>
41# if HAVE_LIMITS_H
42# include <limits.h>
43# endif
44# ifndef LONG_MIN
45# define LONG_MIN (-1-2147483647L)
46# endif
47# if STDC_HEADERS
48# include <stdlib.h>
49# endif
50# include <time.h>
51# ifdef __STDC__
52# define P(x) x
53# else
54# define P(x) ()
55# endif
56#endif
57
58#include <partime.h>
59#include <maketime.h>
60
61char const maketId[] =
62 "$Id: maketime.c 1.1 Sun, 28 Jan 2007 10:02:26 -0800 jmacd $";
63
64static int isleap P ((int));
65static int month_days P ((struct tm const *));
66static time_t maketime P ((struct partime const *, time_t));
67
68/* For maximum portability, use only localtime and gmtime.
69 Make no assumptions about the time_t epoch or the range of time_t values.
70 Avoid mktime because it's not universal and because there's no easy,
71 portable way for mktime to yield the inverse of gmtime. */
72
73#define TM_YEAR_ORIGIN 1900
74
75static int
76isleap (y)
77 int y;
78{
79 return (y & 3) == 0 && (y % 100 != 0 || y % 400 == 0);
80}
81
82/* days in year before start of months 0-12 */
83static int const month_yday[] =
84{
85 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365
86};
87
88/* Yield the number of days in TM's month. */
89static int
90month_days (tm)
91 struct tm const *tm;
92{
93 int m = tm->tm_mon;
94 return (month_yday[m + 1] - month_yday[m]
95 + (m == 1 && isleap (tm->tm_year + TM_YEAR_ORIGIN)));
96}
97
98/* Convert UNIXTIME to struct tm form.
99 Use gmtime if available and if !LOCALZONE, localtime otherwise. */
100struct tm *
101time2tm (unixtime, localzone)
102 time_t unixtime;
103 int localzone;
104{
105 struct tm *tm;
106#ifdef TZ_is_unset
107 static char const *TZ;
108 if (!TZ && !(TZ = getenv ("TZ")))
109 TZ_is_unset ("The TZ environment variable is not set; please set it to your timezone");
110#endif
111 if (localzone || !(tm = gmtime (&unixtime)))
112 tm = localtime (&unixtime);
113 return tm;
114}
115
116/* Yield A - B, measured in seconds. */
117time_t
118difftm (a, b)
119 struct tm const *a;
120 struct tm const *b;
121{
122 int ay = a->tm_year + (TM_YEAR_ORIGIN - 1);
123 int by = b->tm_year + (TM_YEAR_ORIGIN - 1);
124 int ac = ay / 100 - (ay % 100 < 0);
125 int bc = by / 100 - (by % 100 < 0);
126 int difference_in_day_of_year = a->tm_yday - b->tm_yday;
127 int intervening_leap_days = (((ay >> 2) - (by >> 2))
128 - (ac - bc)
129 + ((ac >> 2) - (bc >> 2)));
130 time_t difference_in_years = ay - by;
131 time_t difference_in_days
132 = (difference_in_years * 365
133 + (intervening_leap_days + difference_in_day_of_year));
134 return (((((difference_in_days * 24
135 + (a->tm_hour - b->tm_hour))
136 * 60)
137 + (a->tm_min - b->tm_min))
138 * 60)
139 + (a->tm_sec - b->tm_sec));
140}
141
142/*
143 * Adjust time T by adding SECONDS. SECONDS must be at most 24 hours' worth.
144 * Adjust only T's year, mon, mday, hour, min and sec members;
145 * plus adjust wday if it is defined.
146 */
147void
148adjzone (t, seconds)
149 register struct tm *t;
150 long seconds;
151{
152 /*
153 * This code can be off by a second if SECONDS is not a multiple of 60,
154 * if T is local time, and if a leap second happens during this minute.
155 * But this bug has never occurred, and most likely will not ever occur.
156 * Liberia, the last country for which SECONDS % 60 was nonzero,
157 * switched to UTC in May 1972; the first leap second was in June 1972.
158 */
159 int leap_second = t->tm_sec == 60;
160 long sec = seconds + (t->tm_sec - leap_second);
161 if (sec < 0)
162 {
163 if ((t->tm_min -= (59 - sec) / 60) < 0)
164 {
165 if ((t->tm_hour -= (59 - t->tm_min) / 60) < 0)
166 {
167 t->tm_hour += 24;
168 if (TM_DEFINED (t->tm_wday) && --t->tm_wday < 0)
169 t->tm_wday = 6;
170 if (--t->tm_mday <= 0)
171 {
172 if (--t->tm_mon < 0)
173 {
174 --t->tm_year;
175 t->tm_mon = 11;
176 }
177 t->tm_mday = month_days (t);
178 }
179 }
180 t->tm_min += 24 * 60;
181 }
182 sec += 24L * 60 * 60;
183 }
184 else if (60 <= (t->tm_min += sec / 60))
185 if (24 <= (t->tm_hour += t->tm_min / 60))
186 {
187 t->tm_hour -= 24;
188 if (TM_DEFINED (t->tm_wday) && ++t->tm_wday == 7)
189 t->tm_wday = 0;
190 if (month_days (t) < ++t->tm_mday)
191 {
192 if (11 < ++t->tm_mon)
193 {
194 ++t->tm_year;
195 t->tm_mon = 0;
196 }
197 t->tm_mday = 1;
198 }
199 }
200 t->tm_min %= 60;
201 t->tm_sec = (int) (sec % 60) + leap_second;
202}
203
204/*
205 * Convert TM to time_t, using localtime if LOCALZONE and gmtime otherwise.
206 * Use only TM's year, mon, mday, hour, min, and sec members.
207 * Ignore TM's old tm_yday and tm_wday, but fill in their correct values.
208 * Yield -1 on failure (e.g. a member out of range).
209 * Posix 1003.1-1990 doesn't allow leap seconds, but some implementations
210 * have them anyway, so allow them if localtime/gmtime does.
211 */
212time_t
213tm2time (tm, localzone)
214 struct tm *tm;
215 int localzone;
216{
217 /* Cache the most recent t,tm pairs; 1 for gmtime, 1 for localtime. */
218 static time_t t_cache[2];
219 static struct tm tm_cache[2];
220
221 time_t d, gt;
222 struct tm const *gtm;
223 /*
224 * The maximum number of iterations should be enough to handle any
225 * combinations of leap seconds, time zone rule changes, and solar time.
226 * 4 is probably enough; we use a bigger number just to be safe.
227 */
228 int remaining_tries = 8;
229
230 /* Avoid subscript errors. */
231 if (12 <= (unsigned) tm->tm_mon)
232 return -1;
233
234 tm->tm_yday = month_yday[tm->tm_mon] + tm->tm_mday
235 - (tm->tm_mon < 2 || !isleap (tm->tm_year + TM_YEAR_ORIGIN));
236
237 /* Make a first guess. */
238 gt = t_cache[localzone];
239 gtm = gt ? &tm_cache[localzone] : time2tm (gt, localzone);
240
241 /* Repeatedly use the error from the guess to improve the guess. */
242 while ((d = difftm (tm, gtm)) != 0)
243 {
244 if (--remaining_tries == 0)
245 return -1;
246 gt += d;
247 gtm = time2tm (gt, localzone);
248 }
249
250 /*
251 * Check that the guess actually matches;
252 * overflow can cause difftm to yield 0 even on differing times,
253 * or tm may have members out of range (e.g. bad leap seconds).
254 */
255#define TM_DIFFER(a,b) \
256 ( \
257 ((a)->tm_year ^ (b)->tm_year) | \
258 ((a)->tm_mon ^ (b)->tm_mon) | \
259 ((a)->tm_mday ^ (b)->tm_mday) | \
260 ((a)->tm_hour ^ (b)->tm_hour) | \
261 ((a)->tm_min ^ (b)->tm_min) | \
262 ((a)->tm_sec ^ (b)->tm_sec) \
263 )
264 if (TM_DIFFER (tm, gtm))
265 {
266 /*
267 * If gt is a leap second, try gt+1; if it is one greater than
268 * a leap second, try gt-1; otherwise, it doesn't matter.
269 * Leap seconds always fall at month end.
270 */
271 int yd = tm->tm_year - gtm->tm_year;
272 gt += yd + (yd ? 0 : tm->tm_mon - gtm->tm_mon);
273 gtm = time2tm (gt, localzone);
274 if (TM_DIFFER (tm, gtm))
275 return -1;
276 }
277 t_cache[localzone] = gt;
278 tm_cache[localzone] = *gtm;
279
280 tm->tm_wday = gtm->tm_wday;
281 return gt;
282}
283
284/*
285 * Check *PT and convert it to time_t.
286 * If it is incompletely specified, use DEFAULT_TIME to fill it out.
287 * Use localtime if PT->zone is the special value TM_LOCAL_ZONE.
288 * Yield -1 on failure.
289 * ISO 8601 day-of-year and week numbers are not yet supported.
290 */
291static time_t
292maketime (pt, default_time)
293 struct partime const *pt;
294 time_t default_time;
295{
296 int localzone, wday;
297 struct tm tm;
298 struct tm *tm0 = 0;
299 time_t r;
300
301 tm0 = 0; /* Keep gcc -Wall happy. */
302 localzone = pt->zone == TM_LOCAL_ZONE;
303
304 tm = pt->tm;
305
306 if (TM_DEFINED (pt->ymodulus) || !TM_DEFINED (tm.tm_year))
307 {
308 /* Get tm corresponding to default time. */
309 tm0 = time2tm (default_time, localzone);
310 if (!localzone)
311 adjzone (tm0, pt->zone);
312 }
313
314 if (TM_DEFINED (pt->ymodulus))
315 tm.tm_year +=
316 (tm0->tm_year + TM_YEAR_ORIGIN) / pt->ymodulus * pt->ymodulus;
317 else if (!TM_DEFINED (tm.tm_year))
318 {
319 /* Set default year, month, day from current time. */
320 tm.tm_year = tm0->tm_year + TM_YEAR_ORIGIN;
321 if (!TM_DEFINED (tm.tm_mon))
322 {
323 tm.tm_mon = tm0->tm_mon;
324 if (!TM_DEFINED (tm.tm_mday))
325 tm.tm_mday = tm0->tm_mday;
326 }
327 }
328
329 /* Convert from partime year (Gregorian) to Posix year. */
330 tm.tm_year -= TM_YEAR_ORIGIN;
331
332 /* Set remaining default fields to be their minimum values. */
333 if (!TM_DEFINED (tm.tm_mon))
334 tm.tm_mon = 0;
335 if (!TM_DEFINED (tm.tm_mday))
336 tm.tm_mday = 1;
337 if (!TM_DEFINED (tm.tm_hour))
338 tm.tm_hour = 0;
339 if (!TM_DEFINED (tm.tm_min))
340 tm.tm_min = 0;
341 if (!TM_DEFINED (tm.tm_sec))
342 tm.tm_sec = 0;
343
344 if (!localzone)
345 adjzone (&tm, -pt->zone);
346 wday = tm.tm_wday;
347
348 /* Convert and fill in the rest of the tm. */
349 r = tm2time (&tm, localzone);
350
351 /* Check weekday. */
352 if (r != -1 && TM_DEFINED (wday) && wday != tm.tm_wday)
353 return -1;
354
355 return r;
356}
357
358/* Parse a free-format date in SOURCE, yielding a Unix format time. */
359time_t
360str2time (source, default_time, default_zone)
361 char const *source;
362 time_t default_time;
363 long default_zone;
364{
365 struct partime pt;
366
367 if (*partime (source, &pt))
368 return -1;
369 if (pt.zone == TM_UNDEFINED_ZONE)
370 pt.zone = default_zone;
371 return maketime (&pt, default_time);
372}
373
374#if TEST
375#include <stdio.h>
376int
377main (argc, argv)
378 int argc;
379 char **argv;
380{
381 time_t default_time = time ((time_t *) 0);
382 long default_zone = argv[1] ? atol (argv[1]) : 0;
383 char buf[1000];
384 while (fgets (buf, sizeof (buf), stdin))
385 {
386 time_t t = str2time (buf, default_time, default_zone);
387 printf ("%s", asctime (gmtime (&t)));
388 }
389 return 0;
390}
391#endif
diff --git a/xdelta1/libedsio/maketime.h b/xdelta1/libedsio/maketime.h
deleted file mode 100644
index 3948eda..0000000
--- a/xdelta1/libedsio/maketime.h
+++ /dev/null
@@ -1,39 +0,0 @@
1/* Yield time_t from struct partime yielded by partime. */
2
3/* Copyright 1993, 1994, 1995 Paul Eggert
4 Distributed under license by the Free Software Foundation, Inc.
5
6 This file is part of RCS.
7
8 RCS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 RCS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with RCS; see the file COPYING.
20 If not, write to the Free Software Foundation,
21 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
23 Report problems and direct all questions to:
24
25 rcs-bugs@cs.purdue.edu
26
27 */
28
29#if defined __STDC__ || has_prototypes
30# define __MAKETIME_P(x) x
31#else
32# define __MAKETIME_P(x) ()
33#endif
34
35struct tm *time2tm __MAKETIME_P ((time_t, int));
36time_t difftm __MAKETIME_P ((struct tm const *, struct tm const *));
37time_t str2time __MAKETIME_P ((char const *, time_t, long));
38time_t tm2time __MAKETIME_P ((struct tm *, int));
39void adjzone __MAKETIME_P ((struct tm *, long));
diff --git a/xdelta1/libedsio/md5c.c b/xdelta1/libedsio/md5c.c
deleted file mode 100644
index 0a76927..0000000
--- a/xdelta1/libedsio/md5c.c
+++ /dev/null
@@ -1,298 +0,0 @@
1/* MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm
2 */
3
4/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
5 rights reserved.
6
7 License to copy and use this software is granted provided that it
8 is identified as the "RSA Data Security, Inc. MD5 Message-Digest
9Algorithm" in all material mentioning or referencing this software
10or this function.
11
12License is also granted to make and use derivative works provided
13that such works are identified as "derived from the RSA Data
14Security, Inc. MD5 Message-Digest Algorithm" in all material
15mentioning or referencing the derived work.
16
17RSA Data Security, Inc. makes no representations concerning either
18the merchantability of this software or the suitability of this
19software for any particular purpose. It is provided "as is"
20without express or implied warranty of any kind.
21
22These notices must be retained in any copies of any part of this
23documentation and/or software.
24*/
25
26#include "edsio.h"
27#include <string.h>
28
29
30/* Constants for MD5Transform routine.
31 */
32#define S11 7
33#define S12 12
34#define S13 17
35#define S14 22
36#define S21 5
37#define S22 9
38#define S23 14
39#define S24 20
40#define S31 4
41#define S32 11
42#define S33 16
43#define S34 23
44#define S41 6
45#define S42 10
46#define S43 15
47#define S44 21
48
49static void MD5Transform (guint32 [4], unsigned const char [64]);
50static void Encode (unsigned char *, guint32 *, unsigned int);
51static void Decode (guint32 *, unsigned const char *, unsigned int);
52
53#define MD5_memcpy memcpy
54#define MD5_memset memset
55
56static unsigned char PADDING[64] = {
57 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
58 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
59 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
60};
61
62/* F, G, H and I are basic MD5 functions.
63 */
64#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
65#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
66#define H(x, y, z) ((x) ^ (y) ^ (z))
67#define I(x, y, z) ((y) ^ ((x) | (~z)))
68
69/* ROTATE_LEFT rotates x left n bits.
70 */
71#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
72
73/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
74 Rotation is separate from addition to prevent recomputation.
75 */
76#define FF(a, b, c, d, x, s, ac) { \
77 (a) += F ((b), (c), (d)) + (x) + (guint32)(ac); \
78 (a) = ROTATE_LEFT ((a), (s)); \
79 (a) += (b); \
80 }
81#define GG(a, b, c, d, x, s, ac) { \
82 (a) += G ((b), (c), (d)) + (x) + (guint32)(ac); \
83 (a) = ROTATE_LEFT ((a), (s)); \
84 (a) += (b); \
85 }
86#define HH(a, b, c, d, x, s, ac) { \
87 (a) += H ((b), (c), (d)) + (x) + (guint32)(ac); \
88 (a) = ROTATE_LEFT ((a), (s)); \
89 (a) += (b); \
90 }
91#define II(a, b, c, d, x, s, ac) { \
92 (a) += I ((b), (c), (d)) + (x) + (guint32)(ac); \
93 (a) = ROTATE_LEFT ((a), (s)); \
94 (a) += (b); \
95 }
96
97/* MD5 initialization. Begins an MD5 operation, writing a new context.
98 */
99void edsio_md5_init (EdsioMD5Ctx *context)
100{
101 context->count[0] = context->count[1] = 0;
102 /* Load magic initialization constants.
103 */
104 context->state[0] = 0x67452301;
105 context->state[1] = 0xefcdab89;
106 context->state[2] = 0x98badcfe;
107 context->state[3] = 0x10325476;
108}
109
110/* MD5 block update operation. Continues an MD5 message-digest
111 operation, processing another message block, and updating the
112 context.
113 */
114void edsio_md5_update (EdsioMD5Ctx *context, const guint8* input, guint inputLen)
115{
116 unsigned int i, index, partLen;
117
118 /* Compute number of bytes mod 64 */
119 index = (unsigned int)((context->count[0] >> 3) & 0x3F);
120
121 /* Update number of bits */
122 if ((context->count[0] += ((guint32)inputLen << 3))
123 < ((guint32)inputLen << 3))
124 context->count[1]++;
125 context->count[1] += ((guint32)inputLen >> 29);
126
127 partLen = 64 - index;
128
129 /* Transform as many times as possible.
130 */
131 if (inputLen >= partLen) {
132 MD5_memcpy
133 ((guint8*)&context->buffer[index], (guint8*)input, partLen);
134 MD5Transform (context->state, context->buffer);
135
136 for (i = partLen; i + 63 < inputLen; i += 64)
137 MD5Transform (context->state, &input[i]);
138
139 index = 0;
140 }
141 else
142 i = 0;
143
144 /* Buffer remaining input */
145 MD5_memcpy
146 ((guint8*)&context->buffer[index], (guint8*)&input[i],
147 inputLen-i);
148}
149
150/* MD5 finalization. Ends an MD5 message-digest operation, writing the
151 the message digest and zeroizing the context.
152 */
153void edsio_md5_final (guint8* digest, EdsioMD5Ctx* context)
154{
155 unsigned char bits[8];
156 unsigned int index, padLen;
157
158 /* Save number of bits */
159 Encode (bits, context->count, 8);
160
161 /* Pad out to 56 mod 64.
162 */
163 index = (unsigned int)((context->count[0] >> 3) & 0x3f);
164 padLen = (index < 56) ? (56 - index) : (120 - index);
165 edsio_md5_update (context, PADDING, padLen);
166
167 /* Append length (before padding) */
168 edsio_md5_update (context, bits, 8);
169 /* Store state in digest */
170 Encode (digest, context->state, 16);
171
172 /* Zeroize sensitive information.
173 */
174 MD5_memset ((guint8*)context, 0, sizeof (*context));
175}
176
177/* MD5 basic transformation. Transforms state based on block.
178 */
179static void MD5Transform (guint32 state[4], const guint8 block[64])
180{
181 guint32 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
182
183 Decode (x, block, 64);
184
185 /* Round 1 */
186 FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
187 FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
188 FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
189 FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
190 FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
191 FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
192 FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
193 FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
194 FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
195 FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
196 FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
197 FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
198 FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
199 FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
200 FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
201 FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
202
203 /* Round 2 */
204 GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
205 GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
206 GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
207 GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
208 GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
209 GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
210 GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
211 GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
212 GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
213 GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
214 GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
215 GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
216 GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
217 GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
218 GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
219 GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
220
221 /* Round 3 */
222 HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
223 HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
224 HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
225 HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
226 HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
227 HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
228 HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
229 HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
230 HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
231 HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
232 HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
233 HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
234 HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
235 HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
236 HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
237 HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
238
239 /* Round 4 */
240 II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
241 II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
242 II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
243 II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
244 II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
245 II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
246 II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
247 II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
248 II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
249 II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
250 II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
251 II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
252 II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
253 II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
254 II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
255 II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
256
257 state[0] += a;
258 state[1] += b;
259 state[2] += c;
260 state[3] += d;
261
262 /* Zeroize sensitive information.
263 */
264 MD5_memset ((guint8*)x, 0, sizeof (x));
265}
266
267/* Encodes input (guint32) into output (unsigned char). Assumes len is
268 a multiple of 4.
269 */
270static void Encode (output, input, len)
271 unsigned char *output;
272 guint32 *input;
273 unsigned int len;
274{
275 unsigned int i, j;
276
277 for (i = 0, j = 0; j < len; i++, j += 4) {
278 output[j] = (unsigned char)(input[i] & 0xff);
279 output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
280 output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
281 output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
282 }
283}
284
285/* Decodes input (unsigned char) into output (guint32). Assumes len is
286 a multiple of 4.
287 */
288static void Decode (output, input, len)
289 guint32 *output;
290 unsigned const char *input;
291 unsigned int len;
292{
293 unsigned int i, j;
294
295 for (i = 0, j = 0; j < len; i++, j += 4)
296 output[i] = ((guint32)input[j]) | (((guint32)input[j+1]) << 8) |
297 (((guint32)input[j+2]) << 16) | (((guint32)input[j+3]) << 24);
298}
diff --git a/xdelta1/libedsio/partime.c b/xdelta1/libedsio/partime.c
deleted file mode 100644
index 4cce654..0000000
--- a/xdelta1/libedsio/partime.c
+++ /dev/null
@@ -1,742 +0,0 @@
1/* Parse a string, yielding a struct partime that describes it. */
2
3/* Copyright 1993, 1994, 1995, 1997 Paul Eggert
4 Distributed under license by the Free Software Foundation, Inc.
5
6 This file is part of RCS.
7
8 RCS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 RCS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with RCS; see the file COPYING.
20 If not, write to the Free Software Foundation,
21 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
23 Report problems and direct all questions to:
24
25 rcs-bugs@cs.purdue.edu
26
27 */
28
29#if has_conf_h
30# include <conf.h>
31#else
32# if HAVE_CONFIG_H
33# include <config.h>
34# else
35# ifndef __STDC__
36# define const
37# endif
38# endif
39# if HAVE_LIMITS_H
40# include <limits.h>
41# endif
42# ifndef LONG_MIN
43# define LONG_MIN (-1-2147483647L)
44# endif
45# if STDC_HEADERS
46# include <stdlib.h>
47# endif
48# include <time.h>
49# ifdef __STDC__
50# define P(x) x
51# else
52# define P(x) ()
53# endif
54#endif
55
56#include <ctype.h>
57#if STDC_HEADERS
58# define CTYPE_DOMAIN(c) 1
59#else
60# define CTYPE_DOMAIN(c) ((unsigned) (c) <= 0177)
61#endif
62#define ISALNUM(c) (CTYPE_DOMAIN (c) && isalnum (c))
63#define ISALPHA(c) (CTYPE_DOMAIN (c) && isalpha (c))
64#define ISSPACE(c) (CTYPE_DOMAIN (c) && isspace (c))
65#define ISUPPER(c) (CTYPE_DOMAIN (c) && isupper (c))
66#define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
67
68#include <partime.h>
69
70char const partimeId[] =
71 "$Id: partime.c 1.1 Sun, 28 Jan 2007 10:02:26 -0800 jmacd $";
72
73
74/* Lookup tables for names of months, weekdays, time zones. */
75
76#define NAME_LENGTH_MAXIMUM 4
77
78struct name_val
79 {
80 char name[NAME_LENGTH_MAXIMUM];
81 int val;
82 };
83
84
85static char const *parse_decimal P ((char const *, int, int, int, int, int *, int *));
86static char const *parse_fixed P ((char const *, int, int *));
87static char const *parse_pattern_letter P ((char const *, int, struct partime *));
88static char const *parse_prefix P ((char const *, struct partime *, int *));
89static char const *parse_ranged P ((char const *, int, int, int, int *));
90static int lookup P ((char const *, struct name_val const[]));
91static int merge_partime P ((struct partime *, struct partime const *));
92static void undefine P ((struct partime *));
93
94
95static struct name_val const month_names[] =
96{
97 {"jan", 0},
98 {"feb", 1},
99 {"mar", 2},
100 {"apr", 3},
101 {"may", 4},
102 {"jun", 5},
103 {"jul", 6},
104 {"aug", 7},
105 {"sep", 8},
106 {"oct", 9},
107 {"nov", 10},
108 {"dec", 11},
109 {"", TM_UNDEFINED}
110};
111
112static struct name_val const weekday_names[] =
113{
114 {"sun", 0},
115 {"mon", 1},
116 {"tue", 2},
117 {"wed", 3},
118 {"thu", 4},
119 {"fri", 5},
120 {"sat", 6},
121 {"", TM_UNDEFINED}
122};
123
124#define hr60nonnegative(t) ((t)/100 * 60 + (t)%100)
125#define hr60(t) ((t)<0 ? -hr60nonnegative(-(t)) : hr60nonnegative(t))
126#define zs(t,s) {s, hr60(t)}
127#define zd(t,s,d) zs(t, s), zs((t)+100, d)
128
129static struct name_val const zone_names[] =
130{
131 zs (-1000, "hst"), /* Hawaii */
132 zd (-1000, "hast", "hadt"), /* Hawaii-Aleutian */
133 zd (- 900, "akst", "akdt"), /* Alaska */
134 zd (- 800, "pst" , "pdt" ), /* Pacific */
135 zd (- 700, "mst" , "mdt" ), /* Mountain */
136 zd (- 600, "cst" , "cdt" ), /* Central */
137 zd (- 500, "est" , "edt" ), /* Eastern */
138 zd (- 400, "ast" , "adt" ), /* Atlantic */
139 zd (- 330, "nst" , "ndt" ), /* Newfoundland */
140 zs ( 000, "utc" ), /* Coordinated Universal */
141 zs ( 000, "uct" ), /* " */
142 zs ( 000, "cut" ), /* " */
143 zs ( 000, "ut"), /* Universal */
144 zs ( 000, "z"), /* Zulu (required by ISO 8601) */
145 zd ( 000, "gmt" , "bst" ), /* Greenwich Mean, British Summer */
146 zd ( 000, "wet" , "west"), /* Western European */
147 zd ( 100, "cet" , "cest"), /* Central European */
148 zd ( 100, "met" , "mest"), /* Middle European (bug in old tz versions) */
149 zd ( 100, "mez" , "mesz"), /* Mittel-Europaeische Zeit */
150 zd ( 200, "eet" , "eest"), /* Eastern European */
151 zs ( 530, "ist" ), /* India */
152 zd ( 900, "jst" , "jdt" ), /* Japan */
153 zd ( 900, "kst" , "kdt" ), /* Korea */
154 zd ( 1200, "nzst", "nzdt"), /* New Zealand */
155 {"lt", 1},
156#if 0
157 /* The following names are duplicates or are not well attested.
158 There are lots more where these came from. */
159 zs (-1100, "sst" ), /* Samoan */
160 zd (- 900, "yst" , "ydt" ), /* Yukon - name is no longer used */
161 zd (- 500, "ast" , "adt" ), /* Acre */
162 zd (- 400, "wst" , "wdt" ), /* Western Brazil */
163 zd (- 400, "cst" , "cdt" ), /* Chile */
164 zd (- 200, "fst" , "fdt" ), /* Fernando de Noronha */
165 zs ( 000, "wat" ), /* West African */
166 zs ( 100, "cat" ), /* Central African */
167 zs ( 200, "sat" ), /* South African */
168 zd ( 200, "ist" , "idt" ), /* Israel */
169 zs ( 300, "eat" ), /* East African */
170 zd ( 300, "msk" , "msd" ), /* Moscow */
171 zd ( 330, "ist" , "idt" ), /* Iran */
172 zs ( 800, "hkt" ), /* Hong Kong */
173 zs ( 800, "sgt" ), /* Singapore */
174 zd ( 800, "cst" , "cdt" ), /* China */
175 zd ( 800, "wst" , "wst" ), /* Western Australia */
176 zd ( 930, "cst" , "cst" ), /* Central Australia */
177 zs ( 1000, "gst" ), /* Guam */
178 zd ( 1000, "est" , "est" ), /* Eastern Australia */
179#endif
180 {"", -1}
181};
182
183/* Look for a prefix of S in TABLE, returning val for first matching entry. */
184static int
185lookup (s, table)
186 char const *s;
187 struct name_val const table[];
188{
189 int j;
190 char buf[NAME_LENGTH_MAXIMUM];
191
192 for (j = 0; j < NAME_LENGTH_MAXIMUM; j++)
193 {
194 unsigned char c = *s++;
195 if (! ISALPHA (c))
196 {
197 buf[j] = '\0';
198 break;
199 }
200 buf[j] = ISUPPER (c) ? tolower (c) : c;
201 }
202
203 for (;; table++)
204 for (j = 0; ; j++)
205 if (j == NAME_LENGTH_MAXIMUM || ! table[0].name[j])
206 return table[0].val;
207 else if (buf[j] != table[0].name[j])
208 break;
209}
210
211
212/* Set *T to ``undefined'' values. */
213static void
214undefine (t)
215 struct partime *t;
216{
217 t->tm.tm_sec = t->tm.tm_min = t->tm.tm_hour = t->tm.tm_mday = t->tm.tm_mon
218 = t->tm.tm_year = t->tm.tm_wday = t->tm.tm_yday
219 = t->ymodulus = t->yweek
220 = TM_UNDEFINED;
221 t->zone = TM_UNDEFINED_ZONE;
222}
223
224/* Array of patterns to look for in a date string.
225 Order is important: we look for the first matching pattern
226 whose values do not contradict values that we already know about.
227 See `parse_pattern_letter' below for the meaning of the pattern codes. */
228static char const *const patterns[] =
229{
230 /* These traditional patterns must come first,
231 to prevent an ISO 8601 format from misinterpreting their prefixes. */
232 "E_n_y", "x", /* RFC 822 */
233 "E_n", "n_E", "n", "t:m:s_A", "t:m_A", "t_A", /* traditional */
234 "y/N/D$", /* traditional RCS */
235
236 /* ISO 8601:1988 formats, generalized a bit. */
237 "y-N-D$", "4ND$", "Y-N$",
238 "RND$", "-R=N$", "-R$", "--N=D$", "N=DT",
239 "--N$", "---D$", "DT",
240 "Y-d$", "4d$", "R=d$", "-d$", "dT",
241 "y-W-X", "yWX", "y=W",
242 "-r-W-X", "r-W-XT", "-rWX", "rWXT", "-W=X", "W=XT", "-W",
243 "-w-X", "w-XT", "---X$", "XT", "4$",
244 "T",
245 "h:m:s$", "hms$", "h:m$", "hm$", "h$", "-m:s$", "-ms$", "-m$", "--s$",
246 "Y", "Z",
247
248 0
249};
250
251/* Parse an initial prefix of STR, setting *T accordingly.
252 Return the first character after the prefix, or 0 if it couldn't be parsed.
253 Start with pattern *PI; if success, set *PI to the next pattern to try.
254 Set *PI to -1 if we know there are no more patterns to try;
255 if *PI is initially negative, give up immediately. */
256static char const *
257parse_prefix (str, t, pi)
258 char const *str;
259 struct partime *t;
260 int *pi;
261{
262 int i = *pi;
263 char const *pat;
264 unsigned char c;
265
266 if (i < 0)
267 return 0;
268
269 /* Remove initial noise. */
270 while (! ISALNUM (c = *str) && c != '-' && c != '+')
271 {
272 if (! c)
273 {
274 undefine (t);
275 *pi = -1;
276 return str;
277 }
278 str++;
279 }
280
281 /* Try a pattern until one succeeds. */
282 while ((pat = patterns[i++]) != 0)
283 {
284 char const *s = str;
285 undefine (t);
286 do
287 {
288 if (! (c = *pat++))
289 {
290 *pi = i;
291 return s;
292 }
293 }
294 while ((s = parse_pattern_letter (s, c, t)) != 0);
295 }
296
297 return 0;
298}
299
300/* Parse an initial prefix of S of length DIGITS; it must be a number.
301 Store the parsed number into *RES.
302 Return the first character after the prefix, or 0 if it wasn't parsed. */
303static char const *
304parse_fixed (s, digits, res)
305 char const *s;
306 int digits, *res;
307{
308 int n = 0;
309 char const *lim = s + digits;
310 while (s < lim)
311 {
312 unsigned d = *s++ - '0';
313 if (9 < d)
314 return 0;
315 n = 10 * n + d;
316 }
317 *res = n;
318 return s;
319}
320
321/* Parse an initial prefix of S of length DIGITS;
322 it must be a number in the range LO through HI.
323 Store the parsed number into *RES.
324 Return the first character after the prefix, or 0 if it wasn't parsed. */
325static char const *
326parse_ranged (s, digits, lo, hi, res)
327 char const *s;
328 int digits, lo, hi, *res;
329{
330 s = parse_fixed (s, digits, res);
331 return s && lo <= *res && *res <= hi ? s : 0;
332}
333
334/* Parse an initial prefix of S of length DIGITS;
335 it must be a number in the range LO through HI
336 and it may be followed by a fraction to be computed using RESOLUTION.
337 Store the parsed number into *RES; store the fraction times RESOLUTION,
338 rounded to the nearest integer, into *FRES.
339 Return the first character after the prefix, or 0 if it wasn't parsed. */
340static char const *
341parse_decimal (s, digits, lo, hi, resolution, res, fres)
342 char const *s;
343 int digits, lo, hi, resolution, *res, *fres;
344{
345 s = parse_fixed (s, digits, res);
346 if (s && lo <= *res && *res <= hi)
347 {
348 int f = 0;
349 if ((s[0] == ',' || s[0] == '.') && ISDIGIT (s[1]))
350 {
351 char const *s1 = ++s;
352 int num10 = 0, denom10 = 10, product;
353 while (ISDIGIT (*++s))
354 {
355 int d = denom10 * 10;
356 if (d / 10 != denom10)
357 return 0; /* overflow */
358 denom10 = d;
359 }
360 s = parse_fixed (s1, (int) (s - s1), &num10);
361 product = num10 * resolution;
362 f = (product + (denom10 >> 1)) / denom10;
363 f -= f & (product % denom10 == denom10 >> 1); /* round to even */
364 if (f < 0 || product/resolution != num10)
365 return 0; /* overflow */
366 }
367 *fres = f;
368 return s;
369 }
370 return 0;
371}
372
373/* Parse an initial prefix of S; it must denote a time zone.
374 Set *ZONE to the number of seconds east of GMT,
375 or to TM_LOCAL_ZONE if it is the local time zone.
376 Return the first character after the prefix, or 0 if it wasn't parsed. */
377char *
378parzone (s, zone)
379 char const *s;
380 long *zone;
381{
382 char sign;
383 int hh, mm, ss;
384 int minutesEastOfUTC;
385 long offset, z;
386
387 /* The formats are LT, n, n DST, nDST, no, o
388 where n is a time zone name
389 and o is a time zone offset of the form [-+]hh[:mm[:ss]]. */
390 switch (*s)
391 {
392 case '-':
393 case '+':
394 z = 0;
395 break;
396
397 default:
398 minutesEastOfUTC = lookup (s, zone_names);
399 if (minutesEastOfUTC == -1)
400 return 0;
401
402 /* Don't bother to check rest of spelling. */
403 while (ISALPHA ((unsigned char) *s))
404 s++;
405
406 /* Don't modify LT. */
407 if (minutesEastOfUTC == 1)
408 {
409 *zone = TM_LOCAL_ZONE;
410 return (char *) s;
411 }
412
413 z = minutesEastOfUTC * 60L;
414
415 /* Look for trailing " DST". */
416 if ((s[-1] == 'T' || s[-1] == 't')
417 && (s[-2] == 'S' || s[-2] == 's')
418 && (s[-3] == 'D' || s[-3] == 'd'))
419 goto trailing_dst;
420 while (ISSPACE ((unsigned char) *s))
421 s++;
422 if ((s[0] == 'D' || s[0] == 'd')
423 && (s[1] == 'S' || s[1] == 's')
424 && (s[2] == 'T' || s[2] == 't'))
425 {
426 s += 3;
427 trailing_dst:
428 *zone = z + 60*60;
429 return (char *) s;
430 }
431
432 switch (*s)
433 {
434 case '-':
435 case '+':
436 break;
437
438 default:
439 *zone = z;
440 return (char *) s;
441 }
442
443 break;
444 }
445
446 sign = *s++;
447
448 if (! (s = parse_ranged (s, 2, 0, 23, &hh)))
449 return 0;
450 mm = ss = 0;
451 if (*s == ':')
452 s++;
453 if (ISDIGIT (*s))
454 {
455 if (! (s = parse_ranged (s, 2, 0, 59, &mm)))
456 return 0;
457 if (*s == ':' && s[-3] == ':' && ISDIGIT (s[1])
458 && ! (s = parse_ranged (s + 1, 2, 0, 59, &ss)))
459 return 0;
460 }
461 if (ISDIGIT (*s))
462 return 0;
463 offset = (hh * 60 + mm) * 60L + ss;
464 *zone = z + (sign == '-' ? -offset : offset);
465 /* ?? Are fractions allowed here? If so, they're not implemented. */
466 return (char *) s;
467}
468
469/* Parse an initial prefix of S, matching the pattern whose code is C.
470 Set *T accordingly.
471 Return the first character after the prefix, or 0 if it wasn't parsed. */
472static char const *
473parse_pattern_letter (s, c, t)
474 char const *s;
475 int c;
476 struct partime *t;
477{
478 switch (c)
479 {
480 case '$': /* The next character must be a non-digit. */
481 if (ISDIGIT (*s))
482 return 0;
483 break;
484
485 case '-':
486 case '/':
487 case ':':
488 /* These characters stand for themselves. */
489 if (*s++ != c)
490 return 0;
491 break;
492
493 case '4': /* 4-digit year */
494 s = parse_fixed (s, 4, &t->tm.tm_year);
495 break;
496
497 case '=': /* optional '-' */
498 s += *s == '-';
499 break;
500
501 case 'A': /* AM or PM */
502 /* This matches the regular expression [AaPp][Mm]?.
503 It must not be followed by a letter or digit;
504 otherwise it would match prefixes of strings like "PST". */
505 switch (*s++)
506 {
507 case 'A':
508 case 'a':
509 if (t->tm.tm_hour == 12)
510 t->tm.tm_hour = 0;
511 break;
512
513 case 'P':
514 case 'p':
515 if (t->tm.tm_hour != 12)
516 t->tm.tm_hour += 12;
517 break;
518
519 default:
520 return 0;
521 }
522 switch (*s)
523 {
524 case 'M':
525 case 'm':
526 s++;
527 break;
528 }
529 if (ISALNUM ((unsigned char) *s))
530 return 0;
531 break;
532
533 case 'D': /* day of month [01-31] */
534 s = parse_ranged (s, 2, 1, 31, &t->tm.tm_mday);
535 break;
536
537 case 'd': /* day of year [001-366] */
538 s = parse_ranged (s, 3, 1, 366, &t->tm.tm_yday);
539 t->tm.tm_yday--;
540 break;
541
542 case 'E': /* extended day of month [1-9, 01-31] */
543 s = parse_ranged (s, (ISDIGIT (s[0]) && ISDIGIT (s[1])) + 1, 1, 31,
544 &t->tm.tm_mday);
545 break;
546
547 case 'h': /* hour [00-23 followed by optional fraction] */
548 {
549 int frac;
550 s = parse_decimal (s, 2, 0, 23, 60 * 60, &t->tm.tm_hour, &frac);
551 t->tm.tm_min = frac / 60;
552 t->tm.tm_sec = frac % 60;
553 }
554 break;
555
556 case 'm': /* minute [00-59 followed by optional fraction] */
557 s = parse_decimal (s, 2, 0, 59, 60, &t->tm.tm_min, &t->tm.tm_sec);
558 break;
559
560 case 'n': /* month name [e.g. "Jan"] */
561 if (! TM_DEFINED (t->tm.tm_mon = lookup (s, month_names)))
562 return 0;
563 /* Don't bother to check rest of spelling. */
564 while (ISALPHA ((unsigned char) *s))
565 s++;
566 break;
567
568 case 'N': /* month [01-12] */
569 s = parse_ranged (s, 2, 1, 12, &t->tm.tm_mon);
570 t->tm.tm_mon--;
571 break;
572
573 case 'r': /* year % 10 (remainder in origin-0 decade) [0-9] */
574 s = parse_fixed (s, 1, &t->tm.tm_year);
575 t->ymodulus = 10;
576 break;
577
578 case_R:
579 case 'R': /* year % 100 (remainder in origin-0 century) [00-99] */
580 s = parse_fixed (s, 2, &t->tm.tm_year);
581 t->ymodulus = 100;
582 break;
583
584 case 's': /* second [00-60 followed by optional fraction] */
585 {
586 int frac;
587 s = parse_decimal (s, 2, 0, 60, 1, &t->tm.tm_sec, &frac);
588 t->tm.tm_sec += frac;
589 }
590 break;
591
592 case 'T': /* 'T' or 't' */
593 switch (*s++)
594 {
595 case 'T':
596 case 't':
597 break;
598 default:
599 return 0;
600 }
601 break;
602
603 case 't': /* traditional hour [1-9 or 01-12] */
604 s = parse_ranged (s, (ISDIGIT (s[0]) && ISDIGIT (s[1])) + 1, 1, 12,
605 &t->tm.tm_hour);
606 break;
607
608 case 'w': /* 'W' or 'w' only (stands for current week) */
609 switch (*s++)
610 {
611 case 'W':
612 case 'w':
613 break;
614 default:
615 return 0;
616 }
617 break;
618
619 case 'W': /* 'W' or 'w', followed by a week of year [00-53] */
620 switch (*s++)
621 {
622 case 'W':
623 case 'w':
624 break;
625 default:
626 return 0;
627 }
628 s = parse_ranged (s, 2, 0, 53, &t->yweek);
629 break;
630
631 case 'X': /* weekday (1=Mon ... 7=Sun) [1-7] */
632 s = parse_ranged (s, 1, 1, 7, &t->tm.tm_wday);
633 t->tm.tm_wday--;
634 break;
635
636 case 'x': /* weekday name [e.g. "Sun"] */
637 if (! TM_DEFINED (t->tm.tm_wday = lookup (s, weekday_names)))
638 return 0;
639 /* Don't bother to check rest of spelling. */
640 while (ISALPHA ((unsigned char) *s))
641 s++;
642 break;
643
644 case 'y': /* either R or Y */
645 if (ISDIGIT (s[0]) && ISDIGIT (s[1]) && ! ISDIGIT (s[2]))
646 goto case_R;
647 /* fall into */
648 case 'Y': /* year in full [4 or more digits] */
649 {
650 int len = 0;
651 while (ISDIGIT (s[len]))
652 len++;
653 if (len < 4)
654 return 0;
655 s = parse_fixed (s, len, &t->tm.tm_year);
656 }
657 break;
658
659 case 'Z': /* time zone */
660 s = parzone (s, &t->zone);
661 break;
662
663 case '_': /* possibly empty sequence of non-alphanumerics */
664 while (! ISALNUM ((unsigned char) *s) && *s)
665 s++;
666 break;
667
668 default: /* bad pattern */
669 return 0;
670 }
671
672 return s;
673}
674
675/* If there is no conflict, merge into *T the additional information in *U
676 and return 0. Otherwise do nothing and return -1. */
677static int
678merge_partime (t, u)
679 struct partime *t;
680 struct partime const *u;
681{
682# define conflict(a,b) ((a) != (b) && TM_DEFINED (a) && TM_DEFINED (b))
683 if (conflict (t->tm.tm_sec, u->tm.tm_sec)
684 || conflict (t->tm.tm_min, u->tm.tm_min)
685 || conflict (t->tm.tm_hour, u->tm.tm_hour)
686 || conflict (t->tm.tm_mday, u->tm.tm_mday)
687 || conflict (t->tm.tm_mon, u->tm.tm_mon)
688 || conflict (t->tm.tm_year, u->tm.tm_year)
689 || conflict (t->tm.tm_wday, u->tm.tm_yday)
690 || conflict (t->ymodulus, u->ymodulus)
691 || conflict (t->yweek, u->yweek)
692 || (t->zone != u->zone
693 && t->zone != TM_UNDEFINED_ZONE
694 && u->zone != TM_UNDEFINED_ZONE))
695 return -1;
696# undef conflict
697# define merge_(a,b) if (TM_DEFINED (b)) (a) = (b);
698 merge_ (t->tm.tm_sec, u->tm.tm_sec)
699 merge_ (t->tm.tm_min, u->tm.tm_min)
700 merge_ (t->tm.tm_hour, u->tm.tm_hour)
701 merge_ (t->tm.tm_mday, u->tm.tm_mday)
702 merge_ (t->tm.tm_mon, u->tm.tm_mon)
703 merge_ (t->tm.tm_year, u->tm.tm_year)
704 merge_ (t->tm.tm_wday, u->tm.tm_yday)
705 merge_ (t->ymodulus, u->ymodulus)
706 merge_ (t->yweek, u->yweek)
707# undef merge_
708 if (u->zone != TM_UNDEFINED_ZONE)
709 t->zone = u->zone;
710 return 0;
711}
712
713/* Parse a date/time prefix of S, putting the parsed result into *T.
714 Return the first character after the prefix.
715 The prefix may contain no useful information;
716 in that case, *T will contain only undefined values. */
717char *
718partime (s, t)
719 char const *s;
720 struct partime *t;
721{
722 struct partime p;
723
724 undefine (t);
725
726 while (*s)
727 {
728 int i = 0;
729 char const *s1;
730
731 do
732 {
733 if (! (s1 = parse_prefix (s, &p, &i)))
734 return (char *) s;
735 }
736 while (merge_partime (t, &p) != 0);
737
738 s = s1;
739 }
740
741 return (char *) s;
742}
diff --git a/xdelta1/libedsio/partime.h b/xdelta1/libedsio/partime.h
deleted file mode 100644
index bcc8165..0000000
--- a/xdelta1/libedsio/partime.h
+++ /dev/null
@@ -1,67 +0,0 @@
1/* Parse a string, yielding a struct partime that describes it. */
2
3/* Copyright 1993, 1994, 1995, 1997 Paul Eggert
4 Distributed under license by the Free Software Foundation, Inc.
5
6 This file is part of RCS.
7
8 RCS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 RCS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with RCS; see the file COPYING.
20 If not, write to the Free Software Foundation,
21 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
23 Report problems and direct all questions to:
24
25 rcs-bugs@cs.purdue.edu
26
27 */
28
29#define TM_UNDEFINED (-1)
30#define TM_DEFINED(x) (0 <= (x))
31
32/* #include <limits.h> if you want to use these symbols. */
33#define TM_LOCAL_ZONE LONG_MIN
34#define TM_UNDEFINED_ZONE (LONG_MIN + 1)
35
36struct partime
37 {
38 /* This structure describes the parsed time.
39 Only the following tm_* values in it are used:
40 sec, min, hour, mday, mon, year, wday, yday.
41 If TM_UNDEFINED (value), the parser never found the value.
42 The tm_year field is the actual year, not the year - 1900;
43 but see ymodulus below. */
44 struct tm tm;
45
46 /* If !TM_UNDEFINED (ymodulus),
47 then tm.tm_year is actually modulo ymodulus. */
48 int ymodulus;
49
50 /* Week of year, ISO 8601 style.
51 If TM_UNDEFINED (yweek), the parser never found yweek.
52 Weeks start on Mondays.
53 Week 1 includes Jan 4. */
54 int yweek;
55
56 /* Seconds east of UTC; or TM_LOCAL_ZONE or TM_UNDEFINED_ZONE. */
57 long zone;
58 };
59
60#if defined __STDC__ || has_prototypes
61# define __PARTIME_P(x) x
62#else
63# define __PARTIME_P(x) ()
64#endif
65
66char *partime __PARTIME_P ((char const *, struct partime *));
67char *parzone __PARTIME_P ((char const *, long *));
diff --git a/xdelta1/libedsio/sha.c b/xdelta1/libedsio/sha.c
deleted file mode 100644
index 503fe85..0000000
--- a/xdelta1/libedsio/sha.c
+++ /dev/null
@@ -1,239 +0,0 @@
1/* NIST Secure Hash Algorithm */
2/* heavily modified by Uwe Hollerbach <uh@alumni.caltech edu> */
3/* from Peter C. Gutmann's implementation as found in */
4/* Applied Cryptography by Bruce Schneier */
5/* Further modifications to include the "UNRAVEL" stuff, below */
6
7/* This code is in the public domain */
8
9#include "edsio.h"
10#include <string.h>
11
12#define SHA_BLOCKSIZE 64
13#define SHA_DIGESTSIZE 20
14
15/* UNRAVEL should be fastest & biggest */
16/* UNROLL_LOOPS should be just as big, but slightly slower */
17/* both undefined should be smallest and slowest */
18
19#define UNRAVEL
20/* #define UNROLL_LOOPS */
21
22/* by default, compile for little-endian machines (Intel, Vax) */
23/* change for big-endian machines; for machines which are neither, */
24/* you will need to change the definition of maybe_byte_reverse */
25
26#ifndef WORDS_BIGENDIAN /* from config.h */
27#define SHA_LITTLE_ENDIAN
28#endif
29
30/* NIST's proposed modification to SHA of 7/11/94 may be */
31/* activated by defining USE_MODIFIED_SHA; leave it off for now */
32#undef USE_MODIFIED_SHA
33
34/* SHA f()-functions */
35
36#define f1(x,y,z) ((x & y) | (~x & z))
37#define f2(x,y,z) (x ^ y ^ z)
38#define f3(x,y,z) ((x & y) | (x & z) | (y & z))
39#define f4(x,y,z) (x ^ y ^ z)
40
41/* SHA constants */
42
43#define CONST1 0x5a827999L
44#define CONST2 0x6ed9eba1L
45#define CONST3 0x8f1bbcdcL
46#define CONST4 0xca62c1d6L
47
48/* 32-bit rotate */
49
50#define ROT32(x,n) ((x << n) | (x >> (32 - n)))
51
52/* the generic case, for when the overall rotation is not unraveled */
53
54#define FG(n) \
55 T = ROT32(A,5) + f##n(B,C,D) + E + *WP++ + CONST##n; \
56 E = D; D = C; C = ROT32(B,30); B = A; A = T
57
58/* specific cases, for when the overall rotation is unraveled */
59
60#define FA(n) \
61 T = ROT32(A,5) + f##n(B,C,D) + E + *WP++ + CONST##n; B = ROT32(B,30)
62
63#define FB(n) \
64 E = ROT32(T,5) + f##n(A,B,C) + D + *WP++ + CONST##n; A = ROT32(A,30)
65
66#define FC(n) \
67 D = ROT32(E,5) + f##n(T,A,B) + C + *WP++ + CONST##n; T = ROT32(T,30)
68
69#define FD(n) \
70 C = ROT32(D,5) + f##n(E,T,A) + B + *WP++ + CONST##n; E = ROT32(E,30)
71
72#define FE(n) \
73 B = ROT32(C,5) + f##n(D,E,T) + A + *WP++ + CONST##n; D = ROT32(D,30)
74
75#define FT(n) \
76 A = ROT32(B,5) + f##n(C,D,E) + T + *WP++ + CONST##n; C = ROT32(C,30)
77
78/* do SHA transformation */
79
80static void sha_transform(EdsioSHACtx *ctx)
81{
82 int i;
83 guint32 T, A, B, C, D, E, W[80], *WP;
84
85 for (i = 0; i < 16; ++i) {
86 W[i] = ctx->data[i];
87 }
88 for (i = 16; i < 80; ++i) {
89 W[i] = W[i-3] ^ W[i-8] ^ W[i-14] ^ W[i-16];
90#ifdef USE_MODIFIED_SHA
91 W[i] = ROT32(W[i], 1);
92#endif /* USE_MODIFIED_SHA */
93 }
94 A = ctx->digest[0];
95 B = ctx->digest[1];
96 C = ctx->digest[2];
97 D = ctx->digest[3];
98 E = ctx->digest[4];
99 WP = W;
100#ifdef UNRAVEL
101 FA(1); FB(1); FC(1); FD(1); FE(1); FT(1); FA(1); FB(1); FC(1); FD(1);
102 FE(1); FT(1); FA(1); FB(1); FC(1); FD(1); FE(1); FT(1); FA(1); FB(1);
103 FC(2); FD(2); FE(2); FT(2); FA(2); FB(2); FC(2); FD(2); FE(2); FT(2);
104 FA(2); FB(2); FC(2); FD(2); FE(2); FT(2); FA(2); FB(2); FC(2); FD(2);
105 FE(3); FT(3); FA(3); FB(3); FC(3); FD(3); FE(3); FT(3); FA(3); FB(3);
106 FC(3); FD(3); FE(3); FT(3); FA(3); FB(3); FC(3); FD(3); FE(3); FT(3);
107 FA(4); FB(4); FC(4); FD(4); FE(4); FT(4); FA(4); FB(4); FC(4); FD(4);
108 FE(4); FT(4); FA(4); FB(4); FC(4); FD(4); FE(4); FT(4); FA(4); FB(4);
109 ctx->digest[0] += E;
110 ctx->digest[1] += T;
111 ctx->digest[2] += A;
112 ctx->digest[3] += B;
113 ctx->digest[4] += C;
114#else /* !UNRAVEL */
115#ifdef UNROLL_LOOPS
116 FG(1); FG(1); FG(1); FG(1); FG(1); FG(1); FG(1); FG(1); FG(1); FG(1);
117 FG(1); FG(1); FG(1); FG(1); FG(1); FG(1); FG(1); FG(1); FG(1); FG(1);
118 FG(2); FG(2); FG(2); FG(2); FG(2); FG(2); FG(2); FG(2); FG(2); FG(2);
119 FG(2); FG(2); FG(2); FG(2); FG(2); FG(2); FG(2); FG(2); FG(2); FG(2);
120 FG(3); FG(3); FG(3); FG(3); FG(3); FG(3); FG(3); FG(3); FG(3); FG(3);
121 FG(3); FG(3); FG(3); FG(3); FG(3); FG(3); FG(3); FG(3); FG(3); FG(3);
122 FG(4); FG(4); FG(4); FG(4); FG(4); FG(4); FG(4); FG(4); FG(4); FG(4);
123 FG(4); FG(4); FG(4); FG(4); FG(4); FG(4); FG(4); FG(4); FG(4); FG(4);
124#else /* !UNROLL_LOOPS */
125 for (i = 0; i < 20; ++i) { FG(1); }
126 for (i = 20; i < 40; ++i) { FG(2); }
127 for (i = 40; i < 60; ++i) { FG(3); }
128 for (i = 60; i < 80; ++i) { FG(4); }
129#endif /* !UNROLL_LOOPS */
130 ctx->digest[0] += A;
131 ctx->digest[1] += B;
132 ctx->digest[2] += C;
133 ctx->digest[3] += D;
134 ctx->digest[4] += E;
135#endif /* !UNRAVEL */
136}
137
138#ifdef SHA_LITTLE_ENDIAN
139
140/* change endianness of data */
141
142static void maybe_byte_reverse(guint32 *buffer, int count)
143{
144 int i;
145 guint32 in;
146
147 count /= sizeof(guint32);
148 for (i = 0; i < count; ++i) {
149 in = *buffer;
150 *buffer++ = ((in << 24) & 0xff000000) | ((in << 8) & 0x00ff0000) |
151 ((in >> 8) & 0x0000ff00) | ((in >> 24) & 0x000000ff);
152 }
153}
154
155#else /* !SHA_LITTLE_ENDIAN */
156
157#define maybe_byte_reverse(a,b) /* do nothing */
158
159#endif /* SHA_LITTLE_ENDIAN */
160
161/* initialize the SHA digest */
162
163void edsio_sha_init(EdsioSHACtx *ctx)
164{
165 ctx->digest[0] = 0x67452301L;
166 ctx->digest[1] = 0xefcdab89L;
167 ctx->digest[2] = 0x98badcfeL;
168 ctx->digest[3] = 0x10325476L;
169 ctx->digest[4] = 0xc3d2e1f0L;
170 ctx->count_lo = 0L;
171 ctx->count_hi = 0L;
172 ctx->local = 0;
173}
174
175/* update the SHA digest */
176
177void edsio_sha_update(EdsioSHACtx *ctx, const guint8 *buffer, guint count)
178{
179 int i;
180
181 if ((ctx->count_lo + ((guint32) count << 3)) < ctx->count_lo) {
182 ++ctx->count_hi;
183 }
184 ctx->count_lo += (guint32) count << 3;
185 ctx->count_hi += (guint32) count >> 29;
186 if (ctx->local) {
187 i = SHA_BLOCKSIZE - ctx->local;
188 if (i > count) {
189 i = count;
190 }
191 memcpy(((guint8 *) ctx->data) + ctx->local, buffer, i);
192 count -= i;
193 buffer += i;
194 ctx->local += i;
195 if (ctx->local == SHA_BLOCKSIZE) {
196 maybe_byte_reverse(ctx->data, SHA_BLOCKSIZE);
197 sha_transform(ctx);
198 } else {
199 return;
200 }
201 }
202 while (count >= SHA_BLOCKSIZE) {
203 memcpy(ctx->data, buffer, SHA_BLOCKSIZE);
204 buffer += SHA_BLOCKSIZE;
205 count -= SHA_BLOCKSIZE;
206 maybe_byte_reverse(ctx->data, SHA_BLOCKSIZE);
207 sha_transform(ctx);
208 }
209 memcpy(ctx->data, buffer, count);
210 ctx->local = count;
211}
212
213/* finish computing the SHA digest */
214
215void edsio_sha_final(guint8* digest, EdsioSHACtx *ctx)
216{
217 int count;
218 guint32 lo_bit_count, hi_bit_count;
219
220 lo_bit_count = ctx->count_lo;
221 hi_bit_count = ctx->count_hi;
222 count = (int) ((lo_bit_count >> 3) & 0x3f);
223 ((guint8 *) ctx->data)[count++] = 0x80;
224 if (count > SHA_BLOCKSIZE - 8) {
225 memset(((guint8 *) ctx->data) + count, 0, SHA_BLOCKSIZE - count);
226 maybe_byte_reverse(ctx->data, SHA_BLOCKSIZE);
227 sha_transform(ctx);
228 memset((guint8 *) ctx->data, 0, SHA_BLOCKSIZE - 8);
229 } else {
230 memset(((guint8 *) ctx->data) + count, 0,
231 SHA_BLOCKSIZE - 8 - count);
232 }
233 maybe_byte_reverse(ctx->data, SHA_BLOCKSIZE);
234 ctx->data[14] = hi_bit_count;
235 ctx->data[15] = lo_bit_count;
236 sha_transform(ctx);
237
238 memcpy (digest, ctx->digest, 20);
239}
diff --git a/xdelta1/libedsio/simple.c b/xdelta1/libedsio/simple.c
deleted file mode 100644
index cda509e..0000000
--- a/xdelta1/libedsio/simple.c
+++ /dev/null
@@ -1,179 +0,0 @@
1/* -*-Mode: C;-*-
2 * $Id: simple.c 1.1 Sun, 28 Jan 2007 10:02:26 -0800 jmacd $
3 *
4 * Copyright (C) 1998, 1999, Josh MacDonald.
5 * All Rights Reserved.
6 *
7 * Author: Josh MacDonald <jmacd@CS.Berkeley.EDU>
8 */
9
10#include "edsio.h"
11
12/* Simple Source
13 */
14
15typedef struct _ByteArraySource ByteArraySource;
16
17struct _ByteArraySource {
18 SerialSource source;
19
20 const guint8* in_data;
21 guint in_len;
22
23 guint read_pos;
24 guint flags;
25};
26
27static gboolean byte_array_source_close (SerialSource* source);
28static gboolean byte_array_source_read (SerialSource* source, guint8 *ptr, guint32 len);
29static void byte_array_source_free (SerialSource* source);
30
31SerialSource*
32edsio_simple_source (const guint8* data, guint len, guint flags)
33{
34 ByteArraySource* it = g_new0 (ByteArraySource, 1);
35 SerialSource* src = (SerialSource*) it;
36
37 serializeio_source_init (& it->source,
38 NULL,
39 byte_array_source_close,
40 byte_array_source_read,
41 byte_array_source_free,
42 NULL,
43 NULL);
44
45 it->in_data = data;
46 it->in_len = len;
47 it->flags = flags;
48
49 if (flags & SBF_Base64)
50 src = serializeio_base64_source (src);
51
52 if (flags & SBF_Checksum)
53 src = serializeio_checksum_source (src);
54
55 if (flags & SBF_Compress)
56 src = serializeio_gzip_source (src);
57
58 return src;
59}
60
61gboolean
62byte_array_source_close (SerialSource* source)
63{
64 return TRUE;
65}
66
67gboolean
68byte_array_source_read (SerialSource* source, guint8 *buf, guint32 len)
69{
70 ByteArraySource* ssource = (ByteArraySource*) source;
71
72 if (len + ssource->read_pos > ssource->in_len)
73 {
74 edsio_generate_source_event (EC_EdsioSourceEof, source);
75 return FALSE;
76 }
77
78 memcpy (buf, ssource->in_data + ssource->read_pos, len);
79
80 ssource->read_pos += len;
81
82 return TRUE;
83}
84
85void
86byte_array_source_free (SerialSource* source)
87{
88 g_free (source);
89}
90
91/* BASE64 Sink
92 */
93
94typedef struct _ByteArraySink ByteArraySink;
95
96struct _ByteArraySink {
97 SerialSink sink;
98
99 GByteArray* out;
100
101 gpointer data;
102 guint flags;
103 gboolean free_result;
104 void (* success) (gpointer data, GByteArray* result);
105};
106
107static gboolean byte_array_sink_close (SerialSink* sink);
108static gboolean byte_array_sink_write (SerialSink* sink, const guint8 *ptr, guint32 len);
109static void byte_array_sink_free (SerialSink* sink);
110
111SerialSink*
112edsio_simple_sink (gpointer data,
113 guint flags,
114 gboolean free_result,
115 void (* success) (gpointer data, GByteArray* result),
116 GByteArray **result)
117{
118 ByteArraySink* it = g_new0 (ByteArraySink, 1);
119 SerialSink* sink = (SerialSink*) it;
120
121 serializeio_sink_init (&it->sink,
122 NULL,
123 byte_array_sink_close,
124 byte_array_sink_write,
125 byte_array_sink_free,
126 NULL);
127
128 it->data = data;
129 it->out = g_byte_array_new ();
130 it->flags = flags;
131 it->free_result = free_result;
132 it->success = success;
133
134 if (result)
135 (*result) = it->out;
136
137 if (flags & SBF_Base64)
138 sink = serializeio_base64_sink (sink);
139
140 if (flags & SBF_Checksum)
141 sink = serializeio_checksum_sink (sink);
142
143 if (flags & SBF_Compress)
144 sink = serializeio_gzip_sink (sink);
145
146 return sink;
147}
148
149gboolean
150byte_array_sink_close (SerialSink* sink)
151{
152 ByteArraySink* ssink = (ByteArraySink*) sink;
153
154 if (ssink->success)
155 ssink->success (ssink->data, ssink->out);
156
157 return TRUE;
158}
159
160gboolean
161byte_array_sink_write (SerialSink* sink, const guint8 *ptr, guint32 len)
162{
163 ByteArraySink* ssink = (ByteArraySink*) sink;
164
165 g_byte_array_append (ssink->out, ptr, len);
166
167 return TRUE;
168}
169
170void
171byte_array_sink_free (SerialSink* sink)
172{
173 ByteArraySink* ssink = (ByteArraySink*) sink;
174
175 if (ssink->out && ssink->free_result)
176 g_byte_array_free (ssink->out, TRUE);
177
178 g_free (sink);
179}