ObjFW  Check-in [7c4399b41c]

Overview
Comment:Branch for 0.3.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | 0.3
Files: files | file ages | folders
SHA3-256: 7c4399b41c32e8a60889ad0893fae2ff837c551f031ff9663917fe915af755be
User & Date: js on 2010-04-30 14:16:11
Other Links: branch diff | manifest | tags
Context
2010-04-30
21:50
Remove warning about GNU libobjc in 0.3 branch. check-in: ff7fcef6a2 user: js tags: 0.3
14:16
Branch for 0.3. check-in: 7c4399b41c user: js tags: 0.3
14:12
Fix "make tarball" for new paths. check-in: 6b4749adcc user: js tags: trunk
Changes

Modified Info.plist from [f725cf10a8] to [039df37626].

13
14
15
16
17
18
19
20
21
22
23
24
25
26
	<key>CFBundleInfoDictionaryVersion</key>
	<string>6.0</string>
	<key>CFBundleName</key>
	<string>objfw</string>
	<key>CFBundlePackageType</key>
	<string>FMWK</string>
	<key>CFBundleShortVersionString</key>
	<string>0.3-dev</string>
	<key>CFBundleSignature</key>
	<string>OBJF</string>
	<key>CFBundleVersion</key>
	<string>0.3-dev</string>
</dict>
</plist>







|



|


13
14
15
16
17
18
19
20
21
22
23
24
25
26
	<key>CFBundleInfoDictionaryVersion</key>
	<string>6.0</string>
	<key>CFBundleName</key>
	<string>objfw</string>
	<key>CFBundlePackageType</key>
	<string>FMWK</string>
	<key>CFBundleShortVersionString</key>
	<string>0.3</string>
	<key>CFBundleSignature</key>
	<string>OBJF</string>
	<key>CFBundleVersion</key>
	<string>0.3</string>
</dict>
</plist>

Modified configure.ac from [b88ff9afd8] to [25e64127c8].

1
2
3
4
5
6
7
8
AC_INIT(ObjFW, 0.3-dev, js@webkeks.org)
AC_CONFIG_SRCDIR(src)

AC_CANONICAL_HOST

AC_LANG([Objective C])
AC_PROG_OBJC
AC_PROG_OBJCPP
|







1
2
3
4
5
6
7
8
AC_INIT(ObjFW, 0.3, js@webkeks.org)
AC_CONFIG_SRCDIR(src)

AC_CANONICAL_HOST

AC_LANG([Objective C])
AC_PROG_OBJC
AC_PROG_OBJCPP

Modified src/OFXMLElement.m from [d6b729bcd1] to [8ef4f9d493].

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275

#include <assert.h>
#include <stdlib.h>
#include <string.h>

#import "OFXMLElement.h"
#import "OFString.h"
#import "OFArray.h"
#import "OFAutoreleasePool.h"
#import "OFExceptions.h"

int _OFXMLElement_reference;

@implementation OFXMLAttribute
+ attributeWithName: (OFString*)name
	     prefix: (OFString*)prefix
	  namespace: (OFString*)ns
	stringValue: (OFString*)value
{
	return [[[self alloc] initWithName: name
				    prefix: prefix
				 namespace: ns
			       stringValue: value] autorelease];
}

- initWithName: (OFString*)name_
	prefix: (OFString*)prefix_
     namespace: (OFString*)ns
   stringValue: (OFString*)value
{
	self = [super init];

	name = [name_ copy];
	prefix = [prefix_ copy];
	namespace = [ns copy];
	stringValue = [value copy];

	return self;
}

- (void)dealloc
{
	[name release];
	[prefix release];
	[namespace release];
	[stringValue release];

	[super dealloc];
}

- (OFString*)name
{
	return [[name copy] autorelease];
}

- (OFString*)prefix
{
	return [[prefix copy] autorelease];
}

- (OFString*)namespace
{
	return [[namespace copy] autorelease];
}

- (OFString*)stringValue
{
	return [[stringValue copy] autorelease];
}
@end

@implementation OFXMLElement
+ elementWithName: (OFString*)name_
{
	return [[[self alloc] initWithName: name_] autorelease];
}

+ elementWithName: (OFString*)name
      stringValue: (OFString*)stringval
{
	return [[[self alloc] initWithName: name
			       stringValue: stringval] autorelease];
}

- init
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}

- initWithName: (OFString*)name_
{
	self = [super init];

	name = [name_ copy];

	return self;
}

- initWithName: (OFString*)name_
   stringValue: (OFString*)stringval
{
	self = [super init];

	name = [name_ copy];
	stringValue = [stringval copy];

	return self;
}

- (OFString*)string
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	char *str_c;
	size_t len, i, j, attrs_count;
	OFXMLAttribute **attrs_carray;
	OFString *ret, *tmp;

	len = [name cStringLength] + 3;
	str_c = [self allocMemoryWithSize: len];

	/* Start of tag */
	*str_c = '<';
	memcpy(str_c + 1, [name cString], [name cStringLength]);
	i = [name cStringLength] + 1;

	/* Attributes */
	attrs_carray = [attributes cArray];
	attrs_count = [attributes count];

	for (j = 0; j < attrs_count; j++) {
		/* FIXME: Add namespace support */
		OFString *attr_name = [attrs_carray[j] name];
		tmp = [[attrs_carray[j] stringValue] stringByXMLEscaping];

		len += [attr_name cStringLength] + [tmp cStringLength] + 4;
		@try {
			str_c = [self resizeMemory: str_c
					    toSize: len];
		} @catch (OFException *e) {
			[self freeMemory: str_c];
			@throw e;
		}

		str_c[i++] = ' ';
		memcpy(str_c + i, [attr_name cString],
				[attr_name cStringLength]);
		i += [attr_name cStringLength];
		str_c[i++] = '=';
		str_c[i++] = '\'';
		memcpy(str_c + i, [tmp cString], [tmp cStringLength]);
		i += [tmp cStringLength];
		str_c[i++] = '\'';

		[pool releaseObjects];
	}

	/* Childen */
	if (stringValue != nil || children != nil) {
		if (stringValue != nil)
			tmp = [stringValue stringByXMLEscaping];
		else if (children != nil) {
			OFXMLElement **children_carray = [children cArray];
			size_t children_count = [children count];
			IMP append;

			tmp = [OFMutableString string];
			append = [tmp methodForSelector:
			    @selector(appendCStringWithoutUTF8Checking:)];

			for (j = 0; j < children_count; j++)
				append(tmp, @selector(
				    appendCStringWithoutUTF8Checking:),
				    [[children_carray[j] string] cString]);
		}

		len += [tmp cStringLength] + [name cStringLength] + 2;
		@try {
			str_c = [self resizeMemory: str_c
					    toSize: len];
		} @catch (OFException *e) {
			[self freeMemory: str_c];
			@throw e;
		}

		str_c[i++] = '>';
		memcpy(str_c + i, [tmp cString], [tmp cStringLength]);
		i += [tmp cStringLength];
		str_c[i++] = '<';
		str_c[i++] = '/';
		memcpy(str_c + i, [name cString], [name cStringLength]);
		i += [name cStringLength];
	} else
		str_c[i++] = '/';

	str_c[i++] = '>';
	assert(i == len);

	[pool release];

	@try {
		ret = [OFString stringWithCString: str_c
					   length: len];
	} @finally {
		[self freeMemory: str_c];
	}
	return ret;
}

- (void)addAttribute: (OFXMLAttribute*)attr
{
	if (attributes == nil)
		attributes = [[OFMutableArray alloc] init];

	/* FIXME: Prevent having it twice! */

	[attributes addObject: attr];
}

- (void)addAttributeWithName: (OFString*)name_
		 stringValue: (OFString*)value
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	[self addAttribute: [OFXMLAttribute attributeWithName: name_
						       prefix: nil
						    namespace: nil
						  stringValue: value]];
	[pool release];
}

/* TODO: Replace attribute */
/* TODO: Remove attribute */

- (void)addChild: (OFXMLElement*)child
{
	if (stringValue != nil)
		@throw [OFInvalidArgumentException newWithClass: isa
						       selector: _cmd];

	if (children == nil)
		children = [[OFMutableArray alloc] init];

	[children addObject: child];
}

- (void)dealloc
{
	[name release];
	[attributes release];
	[stringValue release];
	[children release];

	[super dealloc];
}
@end

@implementation OFString (OFXMLEscaping)
- (OFString*)stringByXMLEscaping
{
	char *str_c, *append, *tmp;
	size_t len, append_len;
	size_t i, j;
	OFString *ret;







<
<




<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







13
14
15
16
17
18
19


20
21
22
23



















































































































































































































































24
25
26
27
28
29
30

#include <assert.h>
#include <stdlib.h>
#include <string.h>

#import "OFXMLElement.h"
#import "OFString.h"


#import "OFExceptions.h"

int _OFXMLElement_reference;




















































































































































































































































@implementation OFString (OFXMLEscaping)
- (OFString*)stringByXMLEscaping
{
	char *str_c, *append, *tmp;
	size_t len, append_len;
	size_t i, j;
	OFString *ret;

Modified src/OFXMLParser.m from [e53641c3ce] to [a0c5faabf6].

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

#include "config.h"

#include <string.h>

#import "OFXMLParser.h"
#import "OFString.h"
#import "OFArray.h"
#import "OFAutoreleasePool.h"
#import "OFExceptions.h"
#import "macros.h"

int _OFXMLParser_reference;

static OF_INLINE OFString*
transform_string(OFMutableString *cache,
    OFObject <OFXMLUnescapingDelegate> *handler)
{
	/* TODO: Support for xml:space */

	[cache removeLeadingAndTrailingWhitespaces];
	return [cache stringByXMLUnescapingWithHandler: handler];
}

static OF_INLINE OFString*
parse_numeric_entity(const char *entity, size_t length)
{
	of_unichar_t c;
	size_t i;
	char buf[5];








<






<
<
<
<
<
<
<
<
<
<







11
12
13
14
15
16
17

18
19
20
21
22
23










24
25
26
27
28
29
30

#include "config.h"

#include <string.h>

#import "OFXMLParser.h"
#import "OFString.h"

#import "OFAutoreleasePool.h"
#import "OFExceptions.h"
#import "macros.h"

int _OFXMLParser_reference;











static OF_INLINE OFString*
parse_numeric_entity(const char *entity, size_t length)
{
	of_unichar_t c;
	size_t i;
	char buf[5];

76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
		return nil;
	buf[i] = 0;

	return [OFString stringWithCString: buf
				    length: i];
}

@implementation OFXMLParser
+ xmlParser
{
	return [[[self alloc] init] autorelease];
}

- init
{
	self = [super init];

	@try {
		cache = [[OFMutableString alloc] init];
		previous = [[OFMutableArray alloc] init];
	} @catch (OFException *e) {
		/* We can't use [super dealloc] on OS X here. Compiler bug? */
		[self dealloc];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[delegate release];

	[cache release];
	[name release];
	[prefix release];
	[ns release];
	[attrs release];
	[attrName release];
	[attrPrefix release];
	[previous release];

	[super dealloc];
}

- (id)delegate
{
	return [[delegate retain] autorelease];
}

- (void)setDelegate: (OFObject <OFXMLParserDelegate>*)delegate_
{
	[delegate_ retain];
	[delegate release];
	delegate = delegate_;
}

- (void)parseBuffer: (const char*)buf
	   withSize: (size_t)size
{
	OFAutoreleasePool *pool;
	size_t i, last, len;

	last = 0;

	for (i = 0; i < size; i++) {
		switch (state) {
		/* Not in a tag */
		case OF_XMLPARSER_OUTSIDE_TAG:
			if (buf[i] == '<') {
				len = i - last;

				if (len > 0)
					[cache appendCString: buf + last
						  withLength: len];

				if ([cache cStringLength] > 0) {
					OFString *str;

					pool = [[OFAutoreleasePool alloc] init];
					str = transform_string(cache, self);
					[delegate xmlParser: self
						foundString: str];
					[pool release];
				}

				[cache setToCString: ""];

				last = i + 1;
				state = OF_XMLPARSER_TAG_OPENED;
			}
			break;

		/* Tag was just opened */
		case OF_XMLPARSER_TAG_OPENED:
			if (buf[i] == '/') {
				last = i + 1;
				state = OF_XMLPARSER_IN_CLOSE_TAG_NAME;
			} else if(buf[i] == '!') {
				last = i + 1;
				state = OF_XMLPARSER_IN_COMMENT_1;
			} else {
				state = OF_XMLPARSER_IN_TAG_NAME;
				i--;
			}
			break;

		/* Inside a tag, no name yet */
		case OF_XMLPARSER_IN_TAG_NAME:
			if (buf[i] == ' ' || buf[i] == '>' || buf[i] == '/') {
				const char *cache_c, *tmp;
				size_t cache_len;

				len = i - last;
				if (len > 0)
					[cache appendCString: buf + last
						  withLength: len];
				cache_c = [cache cString];
				cache_len = [cache cStringLength];

				if ((tmp = memchr(cache_c, ':',
				    cache_len)) != NULL) {
					name = [[OFString alloc]
					    initWithCString: tmp + 1
						     length: cache_len - (tmp -
							     cache_c) - 1];
					prefix = [[OFString alloc]
					    initWithCString: cache_c
						     length: tmp - cache_c];
				} else {
					name = [cache copy];
					prefix = nil;
				}

				if (buf[i] == '>' || buf[i] == '/') {
					pool = [[OFAutoreleasePool alloc] init];

					[delegate xmlParser: self
					didStartTagWithName: name
						     prefix: prefix
						  namespace: ns
						 attributes: nil];

					if (buf[i] == '/')
						[delegate xmlParser: self
						  didEndTagWithName: name
							     prefix: prefix
							  namespace: ns];
					else
						[previous addObject:
						    [[cache copy] autorelease]];

					[pool release];

					[name release];
					[prefix release];
					[ns release];
					name = prefix = ns = nil;

					state = (buf[i] == '/'
					    ? OF_XMLPARSER_EXPECT_CLOSE
					    : OF_XMLPARSER_OUTSIDE_TAG);
				} else
					state = OF_XMLPARSER_IN_TAG;

				[cache setToCString: ""];
				last = i + 1;
			}
			break;

		/* Inside a close tag, no name yet */
		case OF_XMLPARSER_IN_CLOSE_TAG_NAME:
			if (buf[i] == ' ' || buf[i] == '>') {
				const char *cache_c, *tmp;
				size_t cache_len;

				len = i - last;
				if (len > 0)
					[cache appendCString: buf + last
						  withLength: len];
				cache_c = [cache cString];
				cache_len = [cache cStringLength];

				if ((tmp = memchr(cache_c, ':',
				    cache_len)) != NULL) {
					name = [[OFString alloc]
					    initWithCString: tmp + 1
						     length: cache_len - (tmp -
							     cache_c) - 1];
					prefix = [[OFString alloc]
					    initWithCString: cache_c
						     length: tmp - cache_c];
				} else {
					name = [cache copy];
					prefix = nil;
				}

				if (![[previous lastObject] isEqual: cache])
					@throw [OFMalformedXMLException
					    newWithClass: isa];
				[previous removeNObjects: 1];

				[cache setToCString: ""];

				pool = [[OFAutoreleasePool alloc] init];

				[delegate xmlParser: self
				  didEndTagWithName: name
					     prefix: prefix
					  namespace: ns];

				[pool release];

				[name release];
				[prefix release];
				[ns release];
				name = prefix = ns = nil;

				last = i + 1;
				state = (buf[i] == ' '
				    ? OF_XMLPARSER_EXPECT_SPACE_OR_CLOSE
				    : OF_XMLPARSER_OUTSIDE_TAG);
			}
			break;

		/* Inside a tag, name found */
		case OF_XMLPARSER_IN_TAG:
			if (buf[i] == '>' || buf[i] == '/') {
				pool = [[OFAutoreleasePool alloc] init];

				[delegate xmlParser: self
				didStartTagWithName: name
					     prefix: prefix
					  namespace: ns
					 attributes: attrs];

				if (buf[i] == '/')
					[delegate xmlParser: self
					  didEndTagWithName: name
						     prefix: prefix
						  namespace: ns];
				else if (prefix != nil) {
					OFString *str = [OFString
					    stringWithFormat: @"%s:%s",
							      [prefix cString],
							      [name cString]];
					[previous addObject: str];
				} else
					[previous addObject: name];

				[pool release];

				[name release];
				[prefix release];
				[ns release];
				[attrs release];
				name = prefix = ns = nil;
				attrs = nil;

				last = i + 1;
				state = (buf[i] == '/'
				    ? OF_XMLPARSER_EXPECT_CLOSE
				    : OF_XMLPARSER_OUTSIDE_TAG);
			} else if (buf[i] != ' ') {
				last = i;
				state = OF_XMLPARSER_IN_ATTR_NAME;
				i--;
			}
			break;

		/* Looking for attribute name */
		case OF_XMLPARSER_IN_ATTR_NAME:
			if (buf[i] == '=') {
				const char *cache_c, *tmp;
				size_t cache_len;

				len = i - last;
				if (len > 0)
					[cache appendCString: buf + last
						  withLength: len];

				cache_c = [cache cString];
				cache_len = [cache cStringLength];

				if ((tmp = memchr(cache_c, ':',
				    cache_len)) != NULL ) {
					attrName = [[OFString alloc]
					    initWithCString: tmp + 1
						     length: cache_len - (tmp -
							     cache_c) - 1];
					attrPrefix = [[OFString alloc]
					    initWithCString: cache_c
						     length: tmp - cache_c];
				} else {
					attrName = [cache copy];
					attrPrefix = nil;
				}

				[cache setToCString: ""];

				last = i + 1;
				state = OF_XMLPARSER_EXPECT_DELIM;
			}
			break;

		/* Expecting delimiter */
		case OF_XMLPARSER_EXPECT_DELIM:
			if (buf[i] != '\'' && buf[i] != '"')
				@throw [OFMalformedXMLException
				    newWithClass: isa];

			delim = buf[i];
			last = i + 1;
			state = OF_XMLPARSER_IN_ATTR_VALUE;
			break;

		/* Looking for attribute value */
		case OF_XMLPARSER_IN_ATTR_VALUE:
			if (buf[i] == delim) {
				OFString *attr_val;

				len = i - last;
				if (len > 0)
					[cache appendCString: buf + last
						  withLength: len];

				if (attrs == nil)
					attrs = [[OFMutableArray alloc] init];

				pool = [[OFAutoreleasePool alloc] init];
				attr_val = [cache
				    stringByXMLUnescapingWithHandler: self];
				[attrs addObject: [OFXMLAttribute
				    attributeWithName: attrName
					       prefix: attrPrefix
					    namespace: nil
					  stringValue: attr_val]];
				[pool release];

				[cache setToCString: ""];
				[attrName release];
				[attrPrefix release];
				attrName = attrPrefix = nil;

				last = i + 1;
				state = OF_XMLPARSER_IN_TAG;
			}
			break;

		/* Expecting closing '>' */
		case OF_XMLPARSER_EXPECT_CLOSE:
			if (buf[i] == '>') {
				last = i + 1;
				state = OF_XMLPARSER_OUTSIDE_TAG;
			} else
				@throw [OFMalformedXMLException
				    newWithClass: isa];
			break;

		/* Expecting closing '>' or space */
		case OF_XMLPARSER_EXPECT_SPACE_OR_CLOSE:
			if (buf[i] == '>') {
				last = i + 1;
				state = OF_XMLPARSER_OUTSIDE_TAG;
			} else if (buf[i] != ' ')
				@throw [OFMalformedXMLException
				    newWithClass: isa];
			break;

		/* Comment */
		case OF_XMLPARSER_IN_COMMENT_1:
		case OF_XMLPARSER_IN_COMMENT_2:
			if (buf[i] != '-')
				@throw [OFMalformedXMLException
				    newWithClass: isa];
			last = i + 1;
			state++;
			break;
		case OF_XMLPARSER_IN_COMMENT_3:
			if (buf[i] == '-')
				state = OF_XMLPARSER_IN_COMMENT_4;
			break;
		case OF_XMLPARSER_IN_COMMENT_4:
			if (buf[i] == '-') {
				size_t cache_len;

				[cache appendCString: buf + last
					  withLength: i - last];
				cache_len = [cache length];

				pool = [[OFAutoreleasePool alloc] init];
				[cache removeCharactersFromIndex: cache_len - 1
							 toIndex: cache_len];
				[cache removeLeadingAndTrailingWhitespaces];
				[delegate xmlParser: self
				       foundComment: cache];
				[pool release];

				[cache setToCString: ""];

				last = i + 1;
				state = OF_XMLPARSER_EXPECT_CLOSE;
			} else
				state = OF_XMLPARSER_IN_COMMENT_3;

			break;
		}
	}

	len = size - last;
	/* In OF_XMLPARSER_IN_TAG, there can be only spaces */
	if (len > 0 && state != OF_XMLPARSER_IN_TAG)
		[cache appendCString: buf + last
			  withLength: len];
}

- (OFString*)foundUnknownEntityNamed: (OFString*)entity
{
	return [delegate xmlParser: self
	   foundUnknownEntityNamed: entity];
}
@end

@implementation OFString (OFXMLUnescaping)
- (OFString*)stringByXMLUnescaping
{
	return [self stringByXMLUnescapingWithHandler: nil];
}

- (OFString*)stringByXMLUnescapingWithHandler:







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







65
66
67
68
69
70
71
































































































































































































































































































































































































































72
73
74
75
76
77
78
		return nil;
	buf[i] = 0;

	return [OFString stringWithCString: buf
				    length: i];
}

































































































































































































































































































































































































































@implementation OFString (OFXMLUnescaping)
- (OFString*)stringByXMLUnescaping
{
	return [self stringByXMLUnescapingWithHandler: nil];
}

- (OFString*)stringByXMLUnescapingWithHandler:
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
		@throw [OFInvalidEncodingException newWithClass: isa];

	[ret appendCStringWithoutUTF8Checking: string + last
				       length: i - last];

	return ret;
}
@end

@implementation OFObject (OFXMLParserDelegate)
-     (void)xmlParser: (OFXMLParser*)parser
  didStartTagWithName: (OFString*)name
	       prefix: (OFString*)prefix
	    namespace: (OFString*)ns
	   attributes: (OFArray*)attrs
{
}

-   (void)xmlParser: (OFXMLParser*)parser
  didEndTagWithName: (OFString*)name
	     prefix: (OFString*)prefix
	  namespace: (OFString*)ns
{
}

- (void)xmlParser: (OFXMLParser*)parser
      foundString: (OFString*)string
{
}

- (void)xmlParser: (OFXMLParser*)parser
     foundComment: (OFString*)comment
{
}

-    (OFString*)xmlParser: (OFXMLParser*)parser
  foundUnknownEntityNamed: (OFString*)entity
{
	return nil;
}
@end








<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
162
163
164
165
166
167
168
169

































		@throw [OFInvalidEncodingException newWithClass: isa];

	[ret appendCStringWithoutUTF8Checking: string + last
				       length: i - last];

	return ret;
}
@end

































Modified tests/Makefile from [d78b55a6da] to [42c3ee0419].

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
       OFNumberTests.m		\
       OFObjectTests.m		\
       ${OFPLUGINTESTS_M}	\
       OFStreamTests.m		\
       OFStringTests.m		\
       OFTCPSocketTests.m	\
       ${OFTHREADTESTS_M}	\
       OFXMLElementTests.m	\
       OFXMLParserTests.m	\
       ${PROPERTIESTESTS_M}	\
       TestsAppDelegate.m

IPHONE_USER = mobile
IPHONE_TMP = /tmp/objfw-test

.PHONY: run run-tests run-on-iphone







<
<







12
13
14
15
16
17
18


19
20
21
22
23
24
25
       OFNumberTests.m		\
       OFObjectTests.m		\
       ${OFPLUGINTESTS_M}	\
       OFStreamTests.m		\
       OFStringTests.m		\
       OFTCPSocketTests.m	\
       ${OFTHREADTESTS_M}	\


       ${PROPERTIESTESTS_M}	\
       TestsAppDelegate.m

IPHONE_USER = mobile
IPHONE_TMP = /tmp/objfw-test

.PHONY: run run-tests run-on-iphone

Deleted tests/OFXMLElementTests.m version [a0a019906c].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
 * Copyright (c) 2008 - 2010
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE included in
 * the packaging of this file.
 */

#include "config.h"

#import "OFXMLElement.h"
#import "OFString.h"
#import "OFArray.h"
#import "OFAutoreleasePool.h"
#import "OFString.h"
#import "OFExceptions.h"

#import "TestsAppDelegate.h"

static OFString *module = @"OFXMLElement";

@implementation TestsAppDelegate (OFXMLElementTests)
- (void)XMLElementTests
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFXMLElement *elem[2];

	TEST(@"+[elementWithName:]",
	    (elem[0] = [OFXMLElement elementWithName: @"foo"]) &&
	    [[elem[0] string] isEqual: @"<foo/>"])

	TEST(@"+[elementWithName:stringValue:]",
	    (elem[1] = [OFXMLElement elementWithName: @"foo"
					 stringValue: @"b&ar"]) &&
	    [[elem[1] string] isEqual: @"<foo>b&amp;ar</foo>"])

	TEST(@"-[addAttributeWithName:stringValue:]",
	    R([elem[0] addAttributeWithName: @"foo"
				stringValue: @"b&ar"]) &&
	    [[elem[0] string] isEqual: @"<foo foo='b&amp;ar'/>"] &&
	    R([elem[1] addAttributeWithName: @"foo"
				stringValue: @"b&ar"]) &&
	    [[elem[1] string] isEqual: @"<foo foo='b&amp;ar'>b&amp;ar</foo>"])

	TEST(@"-[addChild:]",
	    R([elem[0] addChild: [OFXMLElement elementWithName: @"bar"]]) &&
	    [[elem[0] string] isEqual: @"<foo foo='b&amp;ar'><bar/></foo>"])

	[pool drain];
}
@end
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<












































































































Deleted tests/OFXMLParserTests.m version [d66604b68c].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*
 * Copyright (c) 2008 - 2010
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE included in
 * the packaging of this file.
 */

#include "config.h"

#include <string.h>

#import "OFXMLParser.h"
#import "OFString.h"
#import "OFArray.h"
#import "OFAutoreleasePool.h"
#import "OFString.h"
#import "OFExceptions.h"

#import "TestsAppDelegate.h"

static OFString *module = @"OFXMLParser";
static int i = 0;

enum event_type {
	TAG_START,
	TAG_END,
	STRING,
	COMMENT
};

@implementation TestsAppDelegate (OFXMLParser)
- (void)xmlParserCallbackWithEventType: (enum event_type)et
				  name: (OFString*)name
				prefix: (OFString*)prefix
			     namespace: (OFString*)ns
			    attributes: (OFArray*)attrs
				string: (OFString*)string
			       comment: (OFString*)comment
{
	OFString *msg;
	id *carray;
	size_t count;

	i++;
	msg = [OFString stringWithFormat: @"Parsing part #%d", i];

	switch (i) {
	case 1:
	case 5:
		TEST(msg, et == STRING && [string isEqual: @"bar"])
		break;
	case 2:
		/* FIXME: Namespace */
		carray = [attrs cArray];
		count = [attrs count];

		TEST(msg, et == TAG_START && [name isEqual: @"bar"] &&
		    [prefix isEqual: @"foo"] && ns == nil &&
		    attrs != nil && count == 2 &&
		    /* Attribute 1 */
		    [[carray[0] name] isEqual: @"bar"] &&
		    [carray[0] prefix] == nil &&
		    [[carray[0] stringValue] isEqual: @"b&az"] &&
		    [carray[0] namespace] == nil &&
		    /* Attribute 2 */
		    [[carray[1] name] isEqual: @"qux"] &&
		    [[carray[1] prefix] isEqual: @"qux"] &&
		    [[carray[1] stringValue] isEqual: @" quux "] &&
		    [carray[1] namespace] == nil)
		break;
	case 3:
		TEST(msg, et == STRING && [string isEqual: @"foo<bar"])
		break;
	case 4:
		TEST(msg, et == TAG_START && [name isEqual: @"qux"] &&
		    prefix == nil && ns == nil)
		break;
	case 6:
		carray = [attrs cArray];
		count = [attrs count];

		TEST(msg, et == TAG_START && [name isEqual: @"baz"] &&
		    prefix == nil && ns == nil && attrs != nil && count == 2 &&
		    /* Attribute 1 */
		    [[carray[0] name] isEqual: @"name"] &&
		    [carray[0] prefix] == nil &&
		    [[carray[0] stringValue] isEqual: @""] &&
		    [carray[0] namespace] == nil &&
		    /* Attribute 2 */
		    [[carray[1] name] isEqual: @"test"] &&
		    [carray[1] prefix] == nil &&
		    [[carray[1] stringValue] isEqual: @"foobar"] &&
		    [carray[1] namespace] == nil)
		break;
	case 7:
		TEST(msg, et == TAG_END && [name isEqual: @"baz"] &&
		    prefix == nil && ns == nil)
		break;
	case 8:
		TEST(msg, et == STRING && [string isEqual: @"quxbar"])
		break;
	case 9:
		TEST(msg, et == TAG_END && [name isEqual: @"qux"] &&
		    prefix == nil && ns == nil)
		break;
	case 10:
		/* FIXME: Namespace */
		TEST(msg, et == TAG_END && [name isEqual: @"bar"] &&
		    [prefix isEqual: @"foo"] && ns == nil)
		break;
	case 11:
		TEST(msg, et == COMMENT && [comment isEqual: @"foo bär-baz"])
		break;
	default:
		TEST(msg, NO)
		break;
	}
}

-     (void)xmlParser: (OFXMLParser*)parser
  didStartTagWithName: (OFString*)name
	       prefix: (OFString*)prefix
	    namespace: (OFString*)ns
	   attributes: (OFArray*)attrs
{
	[self xmlParserCallbackWithEventType: TAG_START
					name: name
				      prefix: prefix
				   namespace: ns
				  attributes: attrs
				      string: nil
				     comment: nil];
}

-   (void)xmlParser: (OFXMLParser*)parser
  didEndTagWithName: (OFString*)name
	     prefix: (OFString*)prefix
	  namespace: (OFString*)ns
{
	[self xmlParserCallbackWithEventType: TAG_END
					name: name
				      prefix: prefix
				   namespace: ns
				  attributes: nil
				      string: nil
				     comment: nil];
}

- (void)xmlParser: (OFXMLParser*)parser
      foundString: (OFString*)string
{
	[self xmlParserCallbackWithEventType: STRING
					name: nil
				      prefix: nil
				   namespace: nil
				  attributes: nil
				      string: string
				     comment: nil];
}

- (void)xmlParser: (OFXMLParser*)parser
     foundComment: (OFString*)comment
{
	[self xmlParserCallbackWithEventType: COMMENT
					name: nil
				      prefix: nil
				   namespace: nil
				  attributes: nil
				      string: nil
				     comment: comment];
}

-    (OFString*)xmlParser: (OFXMLParser*)parser
  foundUnknownEntityNamed: (OFString*)entity
{
	if ([entity isEqual: @"foo"])
		return @"foobar";

	return nil;
}

- (void)XMLParserTests
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFXMLParser *parser;
	const char *str = "bar<foo:bar  bar='b&amp;az'  qux:qux=\" quux \">\r\n"
	    "foo&lt;bar<qux  >bar <baz name='' test='&foo;'/>  quxbar\r\n</qux>"
	    "</foo:bar><!-- foo bär-baz -->";
	size_t j, len;

	TEST(@"+[xmlParser]", (parser = [OFXMLParser xmlParser]))

	TEST(@"-[setDelegate:]", R([parser setDelegate: self]))

	/* Simulate a stream where we only get chunks */
	len = strlen(str);

	for (j = 0; j < len; j+= 2) {
		if (j + 2 > len)
			[parser parseBuffer: str + j
				   withSize: 1];
		else
			[parser parseBuffer: str + j
				   withSize: 2];
	}

	TEST(@"Checking if everything was parsed", i == 11)

	[pool drain];
}
@end
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<














































































































































































































































































































































































































































Modified tests/TestsAppDelegate.h from [7e0781c6ed] to [dfa6e07171].

118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
@interface TestsAppDelegate (OFTCPSocketTests)
- (void)TCPSocketTests;
@end

@interface TestsAppDelegate (OFThreadTests)
- (void)threadTests;
@end

@interface TestsAppDelegate (OFXMLElementTests)
- (void)XMLElementTests;
@end

@interface TestsAppDelegate (OFXMLParserTests)
- (void)XMLParserTests;
@end







<
<
<
<
<
<
<
<
118
119
120
121
122
123
124








@interface TestsAppDelegate (OFTCPSocketTests)
- (void)TCPSocketTests;
@end

@interface TestsAppDelegate (OFThreadTests)
- (void)threadTests;
@end








Modified tests/TestsAppDelegate.m from [461a2d5844] to [6923a64125].

86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
	[self listTests];
	[self numberTests];
	[self streamTests];
	[self TCPSocketTests];
#ifdef OF_THREADS
	[self threadTests];
#endif
	[self XMLElementTests];
	[self XMLParserTests];
#ifdef OF_PLUGINS
	[self pluginTests];
#endif
#ifdef OF_HAVE_PROPERTIES
	[self propertiesTests];
#endif

	if (fails > 0)
		[OFApplication terminateWithStatus: fails];
}
@end







<
<











86
87
88
89
90
91
92


93
94
95
96
97
98
99
100
101
102
103
	[self listTests];
	[self numberTests];
	[self streamTests];
	[self TCPSocketTests];
#ifdef OF_THREADS
	[self threadTests];
#endif


#ifdef OF_PLUGINS
	[self pluginTests];
#endif
#ifdef OF_HAVE_PROPERTIES
	[self propertiesTests];
#endif

	if (fails > 0)
		[OFApplication terminateWithStatus: fails];
}
@end

Modified utils/objfw-config.in from [d92d8227a8] to [398daa9578].

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
OBJC="@OBJC@"
OBJCFLAGS="@GNU_RUNTIME@ -fexceptions -fobjc-exceptions"
OBJCFLAGS="$OBJCFLAGS -fconstant-string-class=OFConstString"
OBJCFLAGS="$OBJCFLAGS @NO_CONST_CFSTRINGS@ @NO_WARN_UNUSED@ @ATOMIC_OBJCFLAGS@"
LDFLAGS=""
LDFLAGS_RPATH="@LDFLAGS_RPATH@"
LIBS="-L${libdir} -lobjfw @LIBS@"
VERSION="0.3-dev"

show_help() {
	cat <<__EOF__
objfw-config: Available arguments are:

	--all		Outputs all flags + libs
	--cflags	Outputs the required CFLAGS







|







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
OBJC="@OBJC@"
OBJCFLAGS="@GNU_RUNTIME@ -fexceptions -fobjc-exceptions"
OBJCFLAGS="$OBJCFLAGS -fconstant-string-class=OFConstString"
OBJCFLAGS="$OBJCFLAGS @NO_CONST_CFSTRINGS@ @NO_WARN_UNUSED@ @ATOMIC_OBJCFLAGS@"
LDFLAGS=""
LDFLAGS_RPATH="@LDFLAGS_RPATH@"
LIBS="-L${libdir} -lobjfw @LIBS@"
VERSION="0.3"

show_help() {
	cat <<__EOF__
objfw-config: Available arguments are:

	--all		Outputs all flags + libs
	--cflags	Outputs the required CFLAGS