ObjFW  Diff

Differences From Artifact [4580b46438]:

To Artifact [331396bf91]:


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

	ret[j] = 0;
	return ret;
}

+ (char*)createStanza: (const char*)name
	 withCloseTag: (BOOL)close
	     andCData: (const char*)cdata, ...
{
	char *arg, *val, *xml;
	size_t i, len;
	va_list args;

	/* Start of tag */
	len = strlen(name) + 3;
	if ((xml = malloc(len)) == NULL) {
		[[OFNoMemException newWithObject: nil
					 andSize: len] raise];
		return NULL;
	}

	i = 0;
	xml[i++] = '<';
	memcpy(xml + i, name, strlen(name));
	i += strlen(name);

	/* Arguments */
	va_start(args, cdata);
	while ((arg = va_arg(args, char*)) != NULL &&
	    (val = va_arg(args, char*)) != NULL) {
		char *esc_val;

		if ((esc_val = [OFXMLFactory escapeCString: val]) == NULL) {
			/*
			 * escapeCString already throws an exception,







|



















|







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

	ret[j] = 0;
	return ret;
}

+ (char*)createStanza: (const char*)name
	 withCloseTag: (BOOL)close
	      andData: (const char*)data, ...
{
	char *arg, *val, *xml;
	size_t i, len;
	va_list args;

	/* Start of tag */
	len = strlen(name) + 3;
	if ((xml = malloc(len)) == NULL) {
		[[OFNoMemException newWithObject: nil
					 andSize: len] raise];
		return NULL;
	}

	i = 0;
	xml[i++] = '<';
	memcpy(xml + i, name, strlen(name));
	i += strlen(name);

	/* Arguments */
	va_start(args, data);
	while ((arg = va_arg(args, char*)) != NULL &&
	    (val = va_arg(args, char*)) != NULL) {
		char *esc_val;

		if ((esc_val = [OFXMLFactory escapeCString: val]) == NULL) {
			/*
			 * escapeCString already throws an exception,
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

		free(esc_val);
	}
	va_end(args);

	/* End of tag */
	if (close) {
		if (cdata == NULL) {
			if (!xmlfactory_resize(&xml, &len, 2 - 1)) {
				[[OFNoMemException newWithObject: nil
							 andSize: len + 2 - 1]
				    raise];
				return NULL;
			}
	
			xml[i++] = '/';
			xml[i++] = '>';
		} else {
			if (!xmlfactory_resize(&xml, &len, 1 + strlen(cdata) +
			    2 + strlen(name) + 1 - 1)) {
				[[OFNoMemException newWithObject: nil
							 andSize: len + 1 +
								  strlen(
								      cdata) +
								  2 +
								  strlen(name) +
								  1 - 1]
				    raise];
				return NULL;
			}
	
			xml[i++] = '>';
			memcpy(xml + i, cdata, strlen(cdata));
			i += strlen(cdata);
			xml[i++] = '<';
			xml[i++] = '/';
			memcpy(xml + i, name, strlen(name));
			i += strlen(name);
			xml[i++] = '>';
		}
	} else







|










|



|
<








|
|







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

		free(esc_val);
	}
	va_end(args);

	/* End of tag */
	if (close) {
		if (data == NULL) {
			if (!xmlfactory_resize(&xml, &len, 2 - 1)) {
				[[OFNoMemException newWithObject: nil
							 andSize: len + 2 - 1]
				    raise];
				return NULL;
			}
	
			xml[i++] = '/';
			xml[i++] = '>';
		} else {
			if (!xmlfactory_resize(&xml, &len, 1 + strlen(data) +
			    2 + strlen(name) + 1 - 1)) {
				[[OFNoMemException newWithObject: nil
							 andSize: len + 1 +
								  strlen(data) +

								  2 +
								  strlen(name) +
								  1 - 1]
				    raise];
				return NULL;
			}
	
			xml[i++] = '>';
			memcpy(xml + i, data, strlen(data));
			i += strlen(data);
			xml[i++] = '<';
			xml[i++] = '/';
			memcpy(xml + i, name, strlen(name));
			i += strlen(name);
			xml[i++] = '>';
		}
	} else