Prevent attempting to set a nil property on an AWEzvXMLNode. This turns a crash into a warning.
One such case could occur, and seems to have at least once for one user in #11799, if AWEzvContactManager's myInstanceName is nil. This needs further investigation.
Fixes #11799
6 * Author: Andrew Wellington <proton[at]wiretapped.net>
9 * Copyright (C) 2004-2005 Andrew Wellington.
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions are met:
15 * 1. Redistributions of source code must retain the above copyright notice,
16 * this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
22 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
24 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
30 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #import "AWEzvXMLNode.h"
35 #define DEFAULT_CAPACITY 10
37 @implementation AWEzvXMLNode
40 - (id) initWithType:(int)theType name:(NSString *)theName
42 if ((self = [super init])) {
44 name = [theName copy];
45 children = [[NSMutableArray alloc] initWithCapacity:DEFAULT_CAPACITY];
46 attributes = [[NSMutableDictionary alloc] initWithCapacity:DEFAULT_CAPACITY];
54 [children release]; children = nil;
55 [attributes release]; attributes = nil;
56 [name release]; name = nil;
64 - (NSArray *)children {
65 return [[children copy] autorelease];
67 - (void) addChild:(AWEzvXMLNode *)node {
68 [children addObject:node];
71 - (NSDictionary *)attributes {
72 return [[attributes copy] autorelease];
75 - (void) addAttribute:(NSString *)property withValue:(NSString *)value {
76 if (value && property)
77 [attributes setObject:value forKey:property];
79 NSLog(@"WARNING: %@ attempted to set %@ for %@", self, value, propery);
80 AILogWithSignature(@"WARNING: %@ attempted to set %@ for %@", self, value, propery);
89 - (void) setName:(NSString *)theName {
90 if (name != theName) {
92 name = [theName retain];
96 - (NSString *)xmlString {
97 NSMutableString *string;
101 if (type == AWEzvXMLText) {
102 string = [[name mutableCopy] autorelease];
103 [string replaceOccurrencesOfString:@"&" withString:@"&"
104 options:NSLiteralSearch range:NSMakeRange(0, [string length])];
105 [string replaceOccurrencesOfString:@"<" withString:@"<"
106 options:NSLiteralSearch range:NSMakeRange(0, [string length])];
107 [string replaceOccurrencesOfString:@">" withString:@">"
108 options:NSLiteralSearch range:NSMakeRange(0, [string length])];
109 return [[string copy] autorelease];
111 } else if (type == AWEzvXMLRaw) {
112 return [[name copy] autorelease];
115 string = [NSMutableString stringWithString:@"<"];
116 [string appendString:name];
118 for (key in [attributes keyEnumerator]) {
119 [string appendFormat:@" %@=\"%@\"", key, [attributes objectForKey:key]];
122 [string appendString:@">"];
124 for (node in children) {
126 if ((xmlString = [node xmlString])) {
127 [string appendString:xmlString];
131 [string appendFormat:@"</%@>", name];
133 return [[string copy] autorelease];
136 - (NSString *)description
138 NSMutableString *string, *key;
140 string = [NSMutableString stringWithString:@"<"];
141 [string appendString:name];
143 for (key in [attributes keyEnumerator]) {
144 [string appendFormat:@" %@=\"%@\"", key, [attributes objectForKey:key]];
147 [string appendString:@">"];
149 for (node in children) {
151 if ((xmlString = [node xmlString])) {
152 [string appendString:xmlString];
156 [string appendFormat:@"</%@>", name];
158 return [NSString stringWithFormat:@"<AWEzvXMLNode %x:type %i:\"%@\">",self,type,string];