ObjFW  Check-in [3ab7ef17f6]

Overview
Comment:Fix namespace handling in OFXMLElement.
Won't be backported to 0.5 as this might break stuff.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 3ab7ef17f66f8b756162e818b98c91e5907721d69559864792b0ab4aa96d8034
User & Date: js on 2011-05-12 13:14:45
Other Links: manifest | tags
Context
2011-05-12
18:27
Add version to serialization and add serialization to more classes. check-in: ace6f683f7 user: js tags: trunk
13:14
Fix namespace handling in OFXMLElement.
Won't be backported to 0.5 as this might break stuff.
check-in: 3ab7ef17f6 user: js tags: trunk
2011-05-08
23:24
Fix missing retain in -[OFArray initWithObject:arguments:]. check-in: 1e9b75e44d user: js tags: trunk
Changes

Modified src/OFXMLElement.h from [416e9abf0e] to [9b5b383592].

341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
 * \param prefix The prefix for the namespace
 * \param ns The namespace for which the prefix is bound
 */
- (void)bindPrefix: (OFString*)prefix
      forNamespace: (OFString*)ns;

/**
 * Sets the default namespace for the element.
 *
 * \param ns The default namespace for the element
 */
- (void)setDefaultNamespace: (OFString*)ns;

/**
 * Adds a child to the OFXMLElement.







|







341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
 * \param prefix The prefix for the namespace
 * \param ns The namespace for which the prefix is bound
 */
- (void)bindPrefix: (OFString*)prefix
      forNamespace: (OFString*)ns;

/**
 * Sets the default namespace for the element to be used if there is no parent.
 *
 * \param ns The default namespace for the element
 */
- (void)setDefaultNamespace: (OFString*)ns;

/**
 * Adds a child to the OFXMLElement.

Modified src/OFXMLElement.m from [7b911a3167] to [3e52b82e87].

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
	if (CDATA != nil)
		return [OFString stringWithFormat: @"<![CDATA[%@]]>", CDATA];

	if (comment != nil)
		return [OFString stringWithFormat: @"<!--%@-->", comment];

	pool = [[OFAutoreleasePool alloc] init];
	defaultNS = (defaultNamespace != nil
	    ? defaultNamespace
	    : (parent != nil ? parent->defaultNamespace : (OFString*)nil));

	if (parent != nil && parent->namespaces != nil) {
		OFEnumerator *keyEnumerator = [namespaces keyEnumerator];
		OFEnumerator *objectEnumerator = [namespaces objectEnumerator];
		id key, object;

		allNamespaces = [[parent->namespaces mutableCopy] autorelease];

		while ((key = [keyEnumerator nextObject]) != nil &&
		    (object = [objectEnumerator nextObject]) != nil)
			[allNamespaces setObject: object
					  forKey: key];
	} else
		allNamespaces = namespaces;

	prefix = [allNamespaces objectForKey:
	    (ns != nil ? ns : (OFString*)@"")];
	parentPrefix = [allNamespaces objectForKey:
	    (parent != nil && parent->ns != nil ? parent->ns : (OFString*)@"")];








	i = 0;
	length = [name cStringLength] + 3;
	cString = [self allocMemoryWithSize: length];

	/* Start of tag */
	cString[i++] = '<';

	if (prefix != nil && ![ns isEqual: defaultNS] &&
	    (![ns isEqual: (parent != nil ? parent->ns : (OFString*)nil)] ||
	    parentPrefix != nil)) {
		length += [prefix cStringLength] + 1;
		@try {
			cString = [self resizeMemory: cString
					      toSize: length];
		} @catch (id e) {
			[self freeMemory: cString];
			@throw e;
		}

		memcpy(cString + i, [prefix cString], [prefix cStringLength]);
		i += [prefix cStringLength];
		cString[i++] = ':';
	}

	memcpy(cString + i, [name cString], [name cStringLength]);
	i += [name cStringLength];

	/* xmlns if necessary */
	if (ns != nil && prefix == nil && ![ns isEqual: defaultNS] &&
	     (![ns isEqual: (parent != nil ? parent->ns : (OFString*)nil)] ||
	     parentPrefix != nil)) {
		length += [ns cStringLength] + 9;
		@try {
			cString = [self resizeMemory: cString
					      toSize: length];
		} @catch (id e) {
			[self freeMemory: cString];
			@throw e;
		}

		memcpy(cString + i, " xmlns='", 8);
		i += 8;
		memcpy(cString + i, [ns cString], [ns cStringLength]);
		i += [ns cStringLength];
		cString[i++] = '\'';

		defaultNS = ns;
	}

	/* Attributes */
	attributesCArray = [attributes cArray];
	attributesCount = [attributes count];

	pool2 = [[OFAutoreleasePool alloc] init];







<
<
<




















>
>
>
>
>
>
>







|
<
<


















|
<
|














<
<







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
	if (CDATA != nil)
		return [OFString stringWithFormat: @"<![CDATA[%@]]>", CDATA];

	if (comment != nil)
		return [OFString stringWithFormat: @"<!--%@-->", comment];

	pool = [[OFAutoreleasePool alloc] init];




	if (parent != nil && parent->namespaces != nil) {
		OFEnumerator *keyEnumerator = [namespaces keyEnumerator];
		OFEnumerator *objectEnumerator = [namespaces objectEnumerator];
		id key, object;

		allNamespaces = [[parent->namespaces mutableCopy] autorelease];

		while ((key = [keyEnumerator nextObject]) != nil &&
		    (object = [objectEnumerator nextObject]) != nil)
			[allNamespaces setObject: object
					  forKey: key];
	} else
		allNamespaces = namespaces;

	prefix = [allNamespaces objectForKey:
	    (ns != nil ? ns : (OFString*)@"")];
	parentPrefix = [allNamespaces objectForKey:
	    (parent != nil && parent->ns != nil ? parent->ns : (OFString*)@"")];

	if (parent != nil && parent->ns != nil && parentPrefix == nil)
		defaultNS = parent->ns;
	else if (parent != nil && parent->defaultNamespace != nil)
		defaultNS = parent->defaultNamespace;
	else
		defaultNS = defaultNamespace;

	i = 0;
	length = [name cStringLength] + 3;
	cString = [self allocMemoryWithSize: length];

	/* Start of tag */
	cString[i++] = '<';

	if (prefix != nil && ![ns isEqual: defaultNS]) {


		length += [prefix cStringLength] + 1;
		@try {
			cString = [self resizeMemory: cString
					      toSize: length];
		} @catch (id e) {
			[self freeMemory: cString];
			@throw e;
		}

		memcpy(cString + i, [prefix cString], [prefix cStringLength]);
		i += [prefix cStringLength];
		cString[i++] = ':';
	}

	memcpy(cString + i, [name cString], [name cStringLength]);
	i += [name cStringLength];

	/* xmlns if necessary */
	if (prefix == nil && ((ns != nil && ![ns isEqual: defaultNS]) ||

	    (ns == nil && defaultNS != nil))) {
		length += [ns cStringLength] + 9;
		@try {
			cString = [self resizeMemory: cString
					      toSize: length];
		} @catch (id e) {
			[self freeMemory: cString];
			@throw e;
		}

		memcpy(cString + i, " xmlns='", 8);
		i += 8;
		memcpy(cString + i, [ns cString], [ns cStringLength]);
		i += [ns cStringLength];
		cString[i++] = '\'';


	}

	/* Attributes */
	attributesCArray = [attributes cArray];
	attributesCount = [attributes count];

	pool2 = [[OFAutoreleasePool alloc] init];