ObjFW  Check-in [89177dcd09]

Overview
Comment:Remove dummy implementations for formal protocols.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 89177dcd091bca285c2c27f47016dff0377d15c945b52718445b2fc6ec51001e
User & Date: js on 2012-12-20 16:42:52
Other Links: manifest | tags
Context
2012-12-22
14:41
Never throw in -[typeEncodingForSelector:]. check-in: 77573bf01f user: js tags: trunk
2012-12-20
16:42
Remove dummy implementations for formal protocols. check-in: 89177dcd09 user: js tags: trunk
15:11
OFHTTPRequestResult: Fix a missing release. check-in: 4d636a1d00 user: js tags: trunk
Changes

Modified src/OFApplication.h from [f44a22ec3a] to [e7a89febd1].

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
28
29
30
31
32
33
34

35



36
37
38
39
40
41
42







-

-
-
-







	{								\
		return of_application_main(&argc, &argv, [cls class]);	\
	}

/*!
 * @brief A protocol for delegates of OFApplication.
 */
#ifndef OF_APPLICATION_M
@protocol OFApplicationDelegate <OFObject>
#else
@protocol OFApplicationDelegate
#endif
/*!
 * @brief A method which is called when the application was initialized and is
 *	  running now.
 */
- (void)applicationDidFinishLaunching;

#ifdef OF_HAVE_OPTIONAL_PROTOCOLS

Modified src/OFApplication.m from [9867bc719f] to [c32b0e2937].

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
12
13
14
15
16
17
18


19
20
21
22
23
24
25







-
-







 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#define OF_APPLICATION_M

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

#include <signal.h>

#import "OFApplication.h"
44
45
46
47
48
49
50

51

52
53
54
55
56
57
58
42
43
44
45
46
47
48
49

50
51
52
53
54
55
56
57







+
-
+







static OFApplication *app = nil;

static void
atexit_handler(void)
{
	id <OFApplicationDelegate> delegate = [app delegate];

	if ([delegate respondsToSelector: @selector(applicationWillTerminate)])
	[delegate applicationWillTerminate];
		[delegate applicationWillTerminate];

	[(id)delegate release];
}

#define SIGNAL_HANDLER(sig)					\
	static void						\
	handle##sig(int signal)					\
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286








287
288
289
290
291
292
293
271
272
273
274
275
276
277








278
279
280
281
282
283
284
285
286
287
288
289
290
291
292







-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+







	return delegate;
}

- (void)setDelegate: (id <OFApplicationDelegate>)delegate_
{
	delegate = delegate_;

#define REGISTER_SIGNAL(sig)						  \
	sig##Handler = (void(*)(id, SEL))[(id)delegate methodForSelector: \
	    @selector(applicationDidReceive##sig)];			  \
	if (sig##Handler != (void(*)(id, SEL))[OFObject			  \
	    instanceMethodForSelector:					  \
	    @selector(applicationDidReceive##sig)])			  \
		signal(sig, handle##sig);				  \
	else								  \
#define REGISTER_SIGNAL(sig)						\
	if ([delegate respondsToSelector:				\
	    @selector(applicationDidReceive##sig)]) {			\
		sig##Handler = (void(*)(id, SEL))[(id)delegate		\
		    methodForSelector:					\
		    @selector(applicationDidReceive##sig)];		\
		signal(sig, handle##sig);				\
	} else								\
		signal(sig, SIG_DFL);
	REGISTER_SIGNAL(SIGINT)
#ifndef _WIN32
	REGISTER_SIGNAL(SIGHUP)
	REGISTER_SIGNAL(SIGUSR1)
	REGISTER_SIGNAL(SIGUSR2)
#endif
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
323
324
325
326
327
328
329
330
331





































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

- (void)dealloc
{
	[arguments release];
	[environment release];

	[super dealloc];
}
@end

@implementation OFObject (OFApplicationDelegate)
- (void)applicationDidFinishLaunching
{
	@throw [OFNotImplementedException exceptionWithClass: [self class]
						    selector: _cmd];
}

- (void)applicationWillTerminate
{
}

- (void)applicationDidReceiveSIGINT
{
}

- (void)applicationDidReceiveSIGHUP
{
}

- (void)applicationDidReceiveSIGUSR1
{
}

- (void)applicationDidReceiveSIGUSR2
{
}
@end

Modified src/OFHTTPClient.h from [0ec84f966d] to [f80794c7b1].

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
23
24
25
26
27
28
29

30



31
32
33
34
35
36
37







-

-
-
-







@class OFTCPSocket;
@class OFDictionary;
@class OFDataArray;

/*!
 * @brief A delegate for OFHTTPClient.
 */
#ifndef OF_HTTP_CLIENT_M
@protocol OFHTTPClientDelegate <OFObject>
#else
@protocol OFHTTPClientDelegate
#endif
#ifdef OF_HAVE_OPTIONAL_PROTOCOLS
@optional
#endif
/*!
 * @brief A callback which is called when an OFHTTPClient creates a socket.
 *
 * This is useful if the connection is using HTTPS and the server requires a

Modified src/OFHTTPClient.m from [9d0e6d26b7] to [993fb03183].

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
12
13
14
15
16
17
18


19
20
21
22
23
24
25







-
-







 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#define OF_HTTP_CLIENT_M

#include <string.h>
#include <ctype.h>

#import "OFHTTPClient.h"
#import "OFHTTPRequest.h"
#import "OFString.h"
#import "OFURL.h"
148
149
150
151
152
153
154


155
156
157



158
159
160
161
162
163
164
146
147
148
149
150
151
152
153
154



155
156
157
158
159
160
161
162
163
164







+
+
-
-
-
+
+
+







			@throw [OFUnsupportedProtocolException
			    exceptionWithClass: [self class]
					   URL: URL];

		sock = [[[of_tls_socket_class alloc] init] autorelease];
	}

	if ([delegate respondsToSelector:
	    @selector(client:didCreateSocket:request:)])
	[delegate client: self
	 didCreateSocket: sock
		 request: request];
		[delegate client: self
		 didCreateSocket: sock
			 request: request];

	[sock connectToHost: [URL host]
		       port: [URL port]];

	/*
	 * Work around a bug with packet bisection in lighttpd when using
	 * HTTPS.
294
295
296
297
298
299
300
301

302
303
304
305


306
307
308



309
310

311
312
313
314
315
316
317
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







-
+




+
+
-
-
-
+
+
+

-
+







		if ((redirects > 0 && (status == 301 || status == 302 ||
		    status == 303 || status == 307) &&
		    [key isEqual: @"Location"]) && (insecureRedirectsAllowed ||
		    [scheme isEqual: @"http"] ||
		    ![value hasPrefix: @"http://"])) {
			OFURL *newURL;
			OFHTTPRequest *newRequest;
			BOOL follow;
			BOOL follow = YES;

			newURL = [OFURL URLWithString: value
					relativeToURL: URL];

			if ([delegate respondsToSelector:
			    @selector(client:shouldFollowRedirect:request:)])
			follow = [delegate client: self
			     shouldFollowRedirect: newURL
					  request: request];
				follow = [delegate client: self
				     shouldFollowRedirect: newURL
						  request: request];

			if (!follow && delegate != nil) {
			if (!follow) {
				[serverHeaders setObject: value
						  forKey: key];
				continue;
			}

			newRequest = [OFHTTPRequest requestWithURL: newURL];
			[newRequest setRequestType: requestType];
334
335
336
337
338
339
340


341
342
343
344




345
346
347
348
349
350
351
336
337
338
339
340
341
342
343
344




345
346
347
348
349
350
351
352
353
354
355







+
+
-
-
-
-
+
+
+
+







					  redirects: redirects - 1];
		}

		[serverHeaders setObject: value
				  forKey: key];
	}

	if ([delegate respondsToSelector:
	    @selector(client:didReceiveHeaders:statusCode:request:)])
	[delegate      client: self
	    didReceiveHeaders: serverHeaders
		   statusCode: status
		      request: request];
		[delegate      client: self
		    didReceiveHeaders: serverHeaders
			   statusCode: status
			      request: request];

	data = (storesData ? [OFDataArray dataArray] : nil);
	chunked = [[serverHeaders objectForKey: @"Transfer-Encoding"]
	    isEqual: @"chunked"];

	contentLengthHeader = [serverHeaders objectForKey: @"Content-Length"];

394
395
396
397
398
399
400



401
402
403
404




405
406
407
408
409
410
411
398
399
400
401
402
403
404
405
406
407




408
409
410
411
412
413
414
415
416
417
418







+
+
+
-
-
-
-
+
+
+
+







				while (toRead > 0) {
					size_t length = (toRead < of_pagesize
					    ? toRead : of_pagesize);

					length = [sock readIntoBuffer: buffer
							       length: length];

					if ([delegate respondsToSelector:
					    @selector(client:didReceiveData:
					    length:request:)])
					[delegate client: self
					  didReceiveData: buffer
						  length: length
						 request: request];
						[delegate client: self
						  didReceiveData: buffer
							  length: length
							 request: request];

					objc_autoreleasePoolPop(pool2);
					pool2 = objc_autoreleasePoolPush();

					bytesReceived += length;
					[data addItems: buffer
						 count: length];
433
434
435
436
437
438
439



440
441
442
443




444
445
446
447
448
449
450
440
441
442
443
444
445
446
447
448
449




450
451
452
453
454
455
456
457
458
459
460







+
+
+
-
-
-
-
+
+
+
+







				void *pool2;

				length = [sock readIntoBuffer: buffer
						       length: of_pagesize];

				pool2 = objc_autoreleasePoolPush();

				if ([delegate respondsToSelector:
				    @selector(client:didReceiveData:length:
				    request:)])
				[delegate client: self
				  didReceiveData: buffer
					  length: length
					 request: request];
					[delegate client: self
					  didReceiveData: buffer
						  length: length
						 request: request];

				objc_autoreleasePoolPop(pool2);

				bytesReceived += length;
				[data addItems: buffer
					 count: length];

482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
492
493
494
495
496
497
498
499





































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
		@throw [OFHTTPRequestFailedException
		    exceptionWithClass: [self class]
			       request: request
				result: result];

	return result;
}
@end

@implementation OFObject (OFHTTPClientDelegate)
-    (void)client: (OFHTTPClient*)client
  didCreateSocket: (OFTCPSocket*)socket
	  request: (OFHTTPRequest*)request
{
}

-      (void)client: (OFHTTPClient*)client
  didReceiveHeaders: (OFDictionary*)headers
	 statusCode: (int)statusCode
	    request: (OFHTTPRequest*)request
{
}

-   (void)client: (OFHTTPClient*)client
  didReceiveData: (const char*)data
	  length: (size_t)length
	 request: (OFHTTPRequest*)request
{
}

-	  (BOOL)client: (OFHTTPClient*)client
  shouldFollowRedirect: (OFURL*)URL
	       request: (OFHTTPRequest*)request
{
	return YES;
}
@end

Modified src/OFHTTPServer.h from [43b8941dbf] to [3a94e6391a].

21
22
23
24
25
26
27
28

29
30
31
32
33
34
35
36
37
38
21
22
23
24
25
26
27

28



29
30
31
32
33
34
35







-
+
-
-
-







@class OFHTTPRequestResult;
@class OFTCPSocket;
@class OFException;

/*!
 * @brief A delegate for OFHTTPServer.
 */
@protocol OFHTTPServerDelegate
@protocol OFHTTPServerDelegate <OFObject>
#ifndef OF_HTTP_SERVER_M
    <OFObject>
#endif
/*!
 * @brief This method is called when the HTTP server received a request from a
 *	  client.
 *
 * @param server The HTTP server which received the request
 * @param request The request the HTTP server received
 * @return The result the HTTP server should send to the client
135
136
137
138
139
140
141
142
143
144
132
133
134
135
136
137
138










-
-
-
 */
- (void)stop;

- (BOOL)OF_socket: (OFTCPSocket*)socket
  didAcceptSocket: (OFTCPSocket*)clientSocket
	exception: (OFException*)exception;
@end

@interface OFObject (OFHTTPServerDelegate) <OFHTTPServerDelegate>
@end

Modified src/OFHTTPServer.m from [91602836ad] to [0d0597589f].

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
12
13
14
15
16
17
18


19
20
21
22
23
24
25







-
-







 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#define OF_HTTP_SERVER_M

#include <string.h>
#include <ctype.h>

#import "OFHTTPServer.h"
#import "OFDataArray.h"
#import "OFDate.h"
#import "OFDictionary.h"
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
641
642
643
644
645
646
647
648

















-
-
-
-
-
-
-
-
-

	[clientSocket asyncReadLineWithTarget: connection
				     selector: @selector(socket:didReadLine:
						  exception:)];

	return YES;
}
@end

@implementation OFObject (OFHTTPServerDelegate)
- (OFHTTPRequestResult*)server: (OFHTTPServer*)server
	     didReceiveRequest: (OFHTTPRequest*)request
{
	@throw [OFNotImplementedException exceptionWithClass: [self class]
						    selector: _cmd];
}
@end

Modified src/OFStreamObserver.h from [fa395911d4] to [0ddbd1118a].

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
30
31
32
33
34
35
36

37



38
39
40
41
42
43
44







-

-
-
-







@class OFDataArray;
@class OFMutex;

/*!
 * @brief A protocol that needs to be implemented by delegates for
 *	  OFStreamObserver.
 */
#ifndef OF_STREAM_OBSERVER_M
@protocol OFStreamObserverDelegate <OFObject>
#else
@protocol OFStreamObserverDelegate
#endif
#ifdef OF_HAVE_OPTIONAL_PROTOCOLS
@optional
#endif
/*!
 * @brief This callback is called when a stream did get ready for reading.
 *
 * @note When @ref tryReadLine or @ref tryReadTillDelimiter: has been called on

Modified src/OFStreamObserver.m from [0c778cd456] to [df859b9099].

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
12
13
14
15
16
17
18

19
20
21
22
23
24
25







-







 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#define OF_STREAM_OBSERVER_M
#define __NO_EXT_QNX

#include <unistd.h>

#include <assert.h>

#import "OFStreamObserver.h"
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
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





















+
+
+
-
+
+

+














-
-
-
-
-
-
-
-
-
-
-
-
-
-
	BOOL foundInCache = NO;


	for (i = 0; i < count; i++) {
		if ([objects[i] pendingBytes] > 0 &&
		    ![objects[i] OF_isWaitingForDelimiter]) {
			void *pool = objc_autoreleasePoolPush();

			if ([delegate respondsToSelector:
			    @selector(streamIsReadyForReading:)])
			[delegate streamIsReadyForReading: objects[i]];
				[delegate streamIsReadyForReading: objects[i]];

			foundInCache = YES;

			objc_autoreleasePoolPop(pool);
		}
	}

	/*
	 * As long as we have data in the cache for any stream, we don't want
	 * to block.
	 */
	if (foundInCache)
		return YES;

	return NO;
}
@end

@implementation OFObject (OFStreamObserverDelegate)
- (void)streamIsReadyForReading: (OFStream*)stream
{
}

- (void)streamIsReadyForWriting: (OFStream*)stream
{
}

- (void)streamDidReceiveException: (OFStream*)stream
{
}
@end

Modified src/OFStreamObserver_kqueue.m from [c9bbb01ae1] to [d8e79884c0].

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
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







+
+
-
-
+
+
+






+
+
-
-
+
+


+
+
-
-
+
+







		}

		realEvents++;

		pool = objc_autoreleasePoolPush();

		if (eventList[i].flags & EV_ERROR) {
			if ([delegate respondsToSelector:
			    @selector(streamDidReceiveException:)])
			[delegate streamDidReceiveException:
			    FDToStream[eventList[i].ident]];
				[delegate streamDidReceiveException:
				    FDToStream[eventList[i].ident]];

			objc_autoreleasePoolPop(pool);
			continue;
		}

		switch (eventList[i].filter) {
		case EVFILT_READ:
			if ([delegate respondsToSelector:
			    @selector(streamIsReadyForReading:)])
			[delegate streamIsReadyForReading:
			    FDToStream[eventList[i].ident]];
				[delegate streamIsReadyForReading:
				    FDToStream[eventList[i].ident]];
			break;
		case EVFILT_WRITE:
			if ([delegate respondsToSelector:
			    @selector(streamIsReadyForWriting:)])
			[delegate streamIsReadyForWriting:
			    FDToStream[eventList[i].ident]];
				[delegate streamIsReadyForWriting:
				    FDToStream[eventList[i].ident]];
			break;
		default:
			assert(0);
		}

		objc_autoreleasePoolPop(pool);
	}

Modified src/OFStreamObserver_poll.m from [c07acfe92a] to [9a6f7b90a8].

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
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







+
-
-
-
+
+
+
+
+



+
-
-
-
+
+
+
+
+



+
-
-
-
+
+
+
+
+













				OF_ENSURE(read(cancelFD[0], &buffer, 1) > 0);
				FDs_[i].revents = 0;

				objc_autoreleasePoolPop(pool);
				continue;
			}

			if ([delegate respondsToSelector:
			realEvents++;
			[delegate streamIsReadyForReading:
			    FDToStream[FDs_[i].fd]];
			    @selector(streamIsReadyForReading:)])
				[delegate streamIsReadyForReading:
				    FDToStream[FDs_[i].fd]];

			realEvents++;
		}

		if (FDs_[i].revents & POLLOUT) {
			if ([delegate respondsToSelector:
			realEvents++;
			[delegate streamIsReadyForWriting:
			    FDToStream[FDs_[i].fd]];
			    @selector(streamIsReadyForWriting:)])
				[delegate streamIsReadyForWriting:
				    FDToStream[FDs_[i].fd]];

			realEvents++;
		}

		if (FDs_[i].revents & POLLERR) {
			if ([delegate respondsToSelector:
			realEvents++;
			[delegate streamDidReceiveException:
			    FDToStream[FDs_[i].fd]];
			    @selector(streamDidReceiveException:)])
				[delegate streamDidReceiveException:
				    FDToStream[FDs_[i].fd]];

			realEvents++;
		}

		FDs_[i].revents = 0;

		objc_autoreleasePoolPop(pool);
	}

	if (realEvents == 0)
		return NO;

	return YES;
}
@end

Modified src/OFStreamObserver_select.m from [66f75ef514] to [8aa04560f5].

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
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







+
-
-
+
+
+
+



+
-
-
+
+
+






+
+














+
-
-
+
+
+
+



+
-
-
+
+
+
+
+












	for (i = 0; i < count; i++) {
		int fd = [objects[i] fileDescriptorForReading];

		pool = objc_autoreleasePoolPush();

		if (FD_ISSET(fd, &readFDs_)) {
			if ([delegate respondsToSelector:
			realEvents++;
			[delegate streamIsReadyForReading: objects[i]];
			    @selector(streamIsReadyForReading:)])
				[delegate streamIsReadyForReading: objects[i]];

			realEvents++;
		}

		if (FD_ISSET(fd, &exceptFDs_)) {
			if ([delegate respondsToSelector:
			realEvents++;
			[delegate streamDidReceiveException: objects[i]];
			    @selector(streamDidReceiveException:)])
				[delegate streamDidReceiveException:
				    objects[i]];

			/*
			 * Prevent calling it twice in case the FD is in both
			 * sets.
			 */
			FD_CLR(fd, &exceptFDs_);

			realEvents++;
		}

		objc_autoreleasePoolPop(pool);
	}

	objects = [writeStreams objects];
	count = [writeStreams count];

	for (i = 0; i < count; i++) {
		int fd = [objects[i] fileDescriptorForWriting];

		pool = objc_autoreleasePoolPush();

		if (FD_ISSET(fd, &writeFDs_)) {
			if ([delegate respondsToSelector:
			realEvents++;
			[delegate streamIsReadyForWriting: objects[i]];
			    @selector(streamIsReadyForWriting:)])
				[delegate streamIsReadyForWriting: objects[i]];

			realEvents++;
		}

		if (FD_ISSET(fd, &exceptFDs_)) {
			if ([delegate respondsToSelector:
			realEvents++;
			[delegate streamDidReceiveException: objects[i]];
			    @selector(streamDidReceiveException:)])
				[delegate streamDidReceiveException:
				    objects[i]];

			realEvents++;
		}

		objc_autoreleasePoolPop(pool);
	}

	if (realEvents == 0)
		return NO;

	return YES;
}
@end

Modified src/OFXMLElementBuilder.h from [6c8ea67928] to [ffcae14fe5].

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
21
22
23
24
25
26
27

28



29
30
31
32
33
34
35







-

-
-
-







@class OFXMLElement;
@class OFXMLElementBuilder;

/*!
 * @brief A protocol that needs to be implemented by delegates for
 * OFXMLElementBuilder.
 */
#ifndef OF_XML_ELEMENT_BUILDER_M
@protocol OFXMLElementBuilderDelegate <OFObject>
#else
@protocol OFXMLElementBuilderDelegate
#endif
/*!
 * @brief This callback is called when the OFXMLElementBuilder built an element.
 *
 * If the OFXMLElementBuilder was used as a delegate for the OFXMLParser since
 * parsing started, this will return the complete document as an OFXMLElement
 * with all children.
 *
76
77
78
79
80
81
82
83

84
85
86
87
88
89
90
72
73
74
75
76
77
78

79
80
81
82
83
84
85
86







-
+







 * @param builder The builder which did not expect the close tag
 * @param name The name of the close tag
 * @param prefix The prefix of the close tag
 * @param ns The namespace of the close tag
 */
- (void)elementBuilder: (OFXMLElementBuilder*)builder
  didNotExpectCloseTag: (OFString*)name
	    withPrefix: (OFString*)prefix
		prefix: (OFString*)prefix
	     namespace: (OFString*)ns;

/*!
 * @brief This callback is called when the XML parser for the element builder
 *	  found an unknown entity.
 *
 * @param builder The element builder which found an unknown entity

Modified src/OFXMLElementBuilder.m from [5fb1759a2a] to [9a55332d3d].

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
12
13
14
15
16
17
18


19
20
21
22
23
24
25







-
-







 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#define OF_XML_ELEMENT_BUILDER_M

#import "OFXMLElementBuilder.h"
#import "OFXMLElement.h"
#import "OFXMLAttribute.h"
#import "OFXMLCharacters.h"
#import "OFXMLCDATA.h"
#import "OFXMLComment.h"
#import "OFXMLProcessingInstructions.h"
74
75
76
77
78
79
80
81


82
83
84
85
86
87
88

89
90
91
92
93
94
95
72
73
74
75
76
77
78

79
80
81
82
83
84
85
86

87
88
89
90
91
92
93
94







-
+
+






-
+







{
	OFXMLProcessingInstructions *node = [OFXMLProcessingInstructions
	    processingInstructionsWithString: pi];
	OFXMLElement *parent = [stack lastObject];

	if (parent != nil)
		[parent addChild: node];
	else
	else if ([delegate respondsToSelector:
	    @selector(elementBuilder:didBuildParentlessNode:)])
		[delegate   elementBuilder: self
		    didBuildParentlessNode: node];
}

-    (void)parser: (OFXMLParser*)parser
  didStartElement: (OFString*)name
       withPrefix: (OFString*)prefix
	   prefix: (OFString*)prefix
	namespace: (OFString*)ns
       attributes: (OFArray*)attributes
{
	OFXMLElement *element;
	OFXMLAttribute **objects;
	size_t i, count;

114
115
116
117
118
119
120
121

122
123
124
125


126
127
128
129








130
131
132
133
134
135
136
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







-
+




+
+
-
-
-
-
+
+
+
+
+
+
+
+








	[[stack lastObject] addChild: element];
	[stack addObject: element];
}

-  (void)parser: (OFXMLParser*)parser
  didEndElement: (OFString*)name
     withPrefix: (OFString*)prefix
	 prefix: (OFString*)prefix
      namespace: (OFString*)ns
{
	switch ([stack count]) {
	case 0:
		if ([delegate respondsToSelector: @selector(elementBuilder:
		    didNotExpectCloseTag:prefix:namespace:)])
		[delegate elementBuilder: self
		    didNotExpectCloseTag: name
			      withPrefix: prefix
			       namespace: ns];
			[delegate elementBuilder: self
			    didNotExpectCloseTag: name
					  prefix: prefix
				       namespace: ns];
		else
			@throw [OFMalformedXMLException
			    exceptionWithClass: [self class]];

		return;
	case 1:
		[delegate elementBuilder: self
			 didBuildElement: [stack firstObject]];
		break;
	}

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
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







-
+
+












-
+
+












-
+
+







-
-
+
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+



	OFXMLElement *parent;

	node = [OFXMLCharacters charactersWithString: characters];
	parent = [stack lastObject];

	if (parent != nil)
		[parent addChild: node];
	else
	else if ([delegate respondsToSelector:
	    @selector(elementBuilder:didBuildParentlessNode:)])
		[delegate   elementBuilder: self
		    didBuildParentlessNode: node];
}

- (void)parser: (OFXMLParser*)parser
    foundCDATA: (OFString*)CDATA
{
	OFXMLCDATA *node = [OFXMLCDATA CDATAWithString: CDATA];
	OFXMLElement *parent = [stack lastObject];

	if (parent != nil)
		[parent addChild: node];
	else
	else if ([delegate respondsToSelector:
	    @selector(elementBuilder:didBuildParentlessNode:)])
		[delegate   elementBuilder: self
		    didBuildParentlessNode: node];
}

- (void)parser: (OFXMLParser*)parser
  foundComment: (OFString*)comment
{
	OFXMLComment *node = [OFXMLComment commentWithString: comment];
	OFXMLElement *parent = [stack lastObject];

	if (parent != nil)
		[parent addChild: node];
	else
	else if ([delegate respondsToSelector:
	    @selector(elementBuilder:didBuildParentlessNode:)])
		[delegate   elementBuilder: self
		    didBuildParentlessNode: node];
}

-	(OFString*)parser: (OFXMLParser*)parser
  foundUnknownEntityNamed: (OFString*)entity
{
	return [delegate elementBuilder: self
		foundUnknownEntityNamed: entity];
	if ([delegate respondsToSelector:
	    @selector(elementBuilder:foundUnknownEntityNamed:)])
}
@end

		return [delegate elementBuilder: self
@implementation OFObject (OFXMLElementBuilderDelegate)
- (void)elementBuilder: (OFXMLElementBuilder*)builder
       didBuildElement: (OFXMLElement*)element
{
}

-   (void)elementBuilder: (OFXMLElementBuilder*)builder
  didBuildParentlessNode: (OFXMLNode*)node
{
}

- (void)elementBuilder: (OFXMLElementBuilder*)builder
  didNotExpectCloseTag: (OFString*)name
	    withPrefix: (OFString*)prefix
	     namespace: (OFString*)ns
{
	@throw [OFMalformedXMLException exceptionWithClass: [builder class]];
}

- (OFString*)elementBuilder: (OFXMLElementBuilder*)builder
    foundUnknownEntityNamed: (OFString*)entity
{
			foundUnknownEntityNamed: entity];

	return nil;
}
@end

Modified src/OFXMLParser.h from [0c331b0934] to [b980bea64d].

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
23
24
25
26
27
28
29

30



31
32
33
34
35
36
37







-

-
-
-







@class OFMutableArray;
@class OFDataArray;
@class OFStream;

/*!
 * @brief A protocol that needs to be implemented by delegates for OFXMLParser.
 */
#ifndef OF_XML_PARSER_M
@protocol OFXMLParserDelegate <OFObject>
#else
@protocol OFXMLParserDelegate
#endif
#ifdef OF_HAVE_OPTIONAL_PROTOCOLS
@optional
#endif
/*!
 * @brief This callback is called when the XML parser found processing
 *	  instructions.
 *
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
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







-
+













-
+







 * @param prefix The prefix of the tag which just started or nil
 * @param ns The namespace of the tag which just started or nil
 * @param attributes The attributes included in the tag which just started or
 *		     nil
 */
-    (void)parser: (OFXMLParser*)parser
  didStartElement: (OFString*)name
       withPrefix: (OFString*)prefix
	   prefix: (OFString*)prefix
	namespace: (OFString*)ns
       attributes: (OFArray*)attributes;

/*!
 * @brief This callback is called when the XML parser found the end of a tag.
 *
 * @param parser The parser which found the end of a tag
 * @param name The name of the tag which just ended
 * @param prefix The prefix of the tag which just ended or nil
 * @param ns The namespace of the tag which just ended or nil
 */
-  (void)parser: (OFXMLParser*)parser
  didEndElement: (OFString*)name
     withPrefix: (OFString*)prefix
	 prefix: (OFString*)prefix
      namespace: (OFString*)ns;

/*!
 * @brief This callback is called when the XML parser found characters.
 *
 * In case there are comments or CDATA, it is possible that this callback is
 * called multiple times in a row.

Modified src/OFXMLParser.m from [4543342dd4] to [6b0673d037].

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
12
13
14
15
16
17
18


19
20
21
22
23
24
25







-
-







 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#define OF_XML_PARSER_M

#include <string.h>

#include <sys/types.h>

#import "OFXMLParser.h"
#import "OFString.h"
#import "OFArray.h"
333
334
335
336
337
338
339


340
341


342
343
344
345
346
347
348
331
332
333
334
335
336
337
338
339


340
341
342
343
344
345
346
347
348







+
+
-
-
+
+







	if ((length = *i - *last) > 0)
		cache_append(cache, buffer + *last, encoding, length);

	if ([cache count] > 0) {
		void *pool = objc_autoreleasePoolPush();
		OFString *characters = transform_string(cache, 0, YES, self);

		if ([delegate respondsToSelector:
		    @selector(parser:foundCharacters:)])
		[delegate parser: self
		 foundCharacters: characters];
			[delegate    parser: self
			    foundCharacters: characters];

		objc_autoreleasePoolPop(pool);
	}

	[cache removeAllItems];

	*last = *i + 1;
501
502
503
504
505
506
507


508
509


510
511
512
513
514
515
516
501
502
503
504
505
506
507
508
509


510
511
512
513
514
515
516
517
518







+
+
-
-
+
+







		    [pi hasPrefix: @"xml\t"] || [pi hasPrefix: @"xml\r"] ||
		    [pi hasPrefix: @"xml\n"])
			if (![self OF_parseXMLProcessingInstructions: pi])
				@throw [OFMalformedXMLException
				    exceptionWithClass: [self class]
						parser: self];

		if ([delegate respondsToSelector:
		    @selector(parser:foundProcessingInstructions:)])
		[delegate parser: self
		    foundProcessingInstructions: pi];
			[delegate		 parser: self
			    foundProcessingInstructions: pi];

		objc_autoreleasePoolPop(pool);

		[cache removeAllItems];

		*last = *i + 1;
		state = OF_XMLPARSER_OUTSIDE_TAG;
560
561
562
563
564
565
566


567
568
569
570
571





572
573


574
575
576
577




578
579
580
581
582
583
584
562
563
564
565
566
567
568
569
570





571
572
573
574
575
576
577
578
579




580
581
582
583
584
585
586
587
588
589
590







+
+
-
-
-
-
-
+
+
+
+
+


+
+
-
-
-
-
+
+
+
+







		ns = namespace_for_prefix(prefix, namespaces);

		if (prefix != nil && ns == nil)
			@throw [OFUnboundNamespaceException
			    exceptionWithClass: [self class]
					prefix: prefix];

		if ([delegate respondsToSelector: @selector(parser:
		    didStartElement:prefix:namespace:attributes:)])
		[delegate parser: self
		 didStartElement: name
		      withPrefix: prefix
		       namespace: ns
		      attributes: nil];
			[delegate    parser: self
			    didStartElement: name
				     prefix: prefix
				  namespace: ns
				 attributes: nil];

		if (buffer[*i] == '/') {
			if ([delegate respondsToSelector:
			    @selector(parser:didEndElement:prefix:namespace:)])
			[delegate parser: self
			   didEndElement: name
			      withPrefix: prefix
			       namespace: ns];
				[delegate  parser: self
				    didEndElement: name
					   prefix: prefix
					namespace: ns];

			if ([previous count] == 0)
				finishedParsing = YES;
		} else
			[previous addObject: cacheString];

		[name release];
647
648
649
650
651
652
653


654
655
656
657




658
659
660
661
662
663
664
653
654
655
656
657
658
659
660
661




662
663
664
665
666
667
668
669
670
671
672







+
+
-
-
-
-
+
+
+
+








	ns = namespace_for_prefix(prefix, namespaces);
	if (prefix != nil && ns == nil)
		@throw [OFUnboundNamespaceException
		    exceptionWithClass: [self class]
				prefix: prefix];

	if ([delegate respondsToSelector:
	    @selector(parser:didEndElement:prefix:namespace:)])
	[delegate parser: self
	   didEndElement: name
	      withPrefix: prefix
	       namespace: ns];
		[delegate  parser: self
		    didEndElement: name
			   prefix: prefix
			namespace: ns];

	objc_autoreleasePoolPop(pool);

	[namespaces removeLastObject];
	[name release];
	[prefix release];
	name = prefix = nil;
705
706
707
708
709
710
711


712
713
714
715
716





717
718


719
720
721
722




723
724
725
726
727
728
729
713
714
715
716
717
718
719
720
721





722
723
724
725
726
727
728
729
730




731
732
733
734
735
736
737
738
739
740
741







+
+
-
-
-
-
-
+
+
+
+
+


+
+
-
-
-
-
+
+
+
+








	for (j = 0; j < attributesCount; j++)
		resolve_attribute_namespace(attributesObjects[j], namespaces,
		    self);

	pool = objc_autoreleasePoolPush();

	if ([delegate respondsToSelector:
	    @selector(parser:didStartElement:prefix:namespace:attributes:)])
	[delegate parser: self
	 didStartElement: name
	      withPrefix: prefix
	       namespace: ns
	      attributes: attributes];
		[delegate    parser: self
		    didStartElement: name
			     prefix: prefix
			  namespace: ns
			 attributes: attributes];

	if (buffer[*i] == '/') {
		if ([delegate respondsToSelector:
		    @selector(parser:didEndElement:prefix:namespace:)])
		[delegate parser: self
		   didEndElement: name
		      withPrefix: prefix
		       namespace: ns];
			[delegate  parser: self
			    didEndElement: name
				   prefix: prefix
				namespace: ns];

		if ([previous count] == 0)
			finishedParsing = YES;

		[namespaces removeLastObject];
	} else if (prefix != nil) {
		OFString *str = [OFString stringWithFormat: @"%@:%@",
948
949
950
951
952
953
954

955
956


957
958
959
960
961
962
963
960
961
962
963
964
965
966
967


968
969
970
971
972
973
974
975
976







+
-
-
+
+







	}

	pool = objc_autoreleasePoolPush();

	cache_append(cache, buffer + *last, encoding, *i - *last);
	CDATA = transform_string(cache, 2, NO, nil);

	if ([delegate respondsToSelector: @selector(parser:foundCDATA:)])
	[delegate parser: self
	      foundCDATA: CDATA];
		[delegate parser: self
		      foundCDATA: CDATA];

	objc_autoreleasePoolPop(pool);

	[cache removeAllItems];

	*last = *i + 1;
	state = OF_XMLPARSER_OUTSIDE_TAG;
1002
1003
1004
1005
1006
1007
1008

1009
1010


1011
1012
1013
1014
1015
1016
1017
1015
1016
1017
1018
1019
1020
1021
1022


1023
1024
1025
1026
1027
1028
1029
1030
1031







+
-
-
+
+







							    parser: self];

	pool = objc_autoreleasePoolPush();

	cache_append(cache, buffer + *last, encoding, *i - *last);
	comment = transform_string(cache, 2, NO, nil);

	if ([delegate respondsToSelector: @selector(parser:foundComment:)])
	[delegate parser: self
	    foundComment: comment];
		[delegate parser: self
		    foundComment: comment];

	objc_autoreleasePoolPop(pool);

	[cache removeAllItems];

	*last = *i + 1;
	state = OF_XMLPARSER_OUTSIDE_TAG;
1050
1051
1052
1053
1054
1055
1056
1057
1058


1059
1060
1061

1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100


1101
1102
1103
1064
1065
1066
1067
1068
1069
1070


1071
1072



1073







































1074
1075
1076
1077
1078







-
-
+
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+



{
	return finishedParsing;
}

-	   (OFString*)string: (OFString*)string
  containsUnknownEntityNamed: (OFString*)entity
{
	return [delegate parser: self
	foundUnknownEntityNamed: entity];
	if ([delegate respondsToSelector:
	    @selector(parser:foundUnknownEntityNamed:)])
}
@end

		return [delegate     parser: self
@implementation OFObject (OFXMLParserDelegate)
-		 (void)parser: (OFXMLParser*)parser
  foundProcessingInstructions: (OFString*)pi
{
}

-    (void)parser: (OFXMLParser*)parser
  didStartElement: (OFString*)name
       withPrefix: (OFString*)prefix
	namespace: (OFString*)ns
       attributes: (OFArray*)attributes
{
}

-  (void)parser: (OFXMLParser*)parser
  didEndElement: (OFString*)name
     withPrefix: (OFString*)prefix
      namespace: (OFString*)ns
{
}

-    (void)parser: (OFXMLParser*)parser
  foundCharacters: (OFString*)characters
{
}

- (void)parser: (OFXMLParser*)parser
    foundCDATA: (OFString*)CDATA
{
}

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

-	(OFString*)parser: (OFXMLParser*)parser
  foundUnknownEntityNamed: (OFString*)entity
{
		    foundUnknownEntityNamed: entity];

	return nil;
}
@end

Modified tests/OFXMLParserTests.m from [c34c13b545] to [0b180b31df].

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
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







-
+













-
+







				namespace: nil
			       attributes: nil
				   string: pi];
}

-    (void)parser: (OFXMLParser*)parser
  didStartElement: (OFString*)name
       withPrefix: (OFString*)prefix
	   prefix: (OFString*)prefix
	namespace: (OFString*)ns
       attributes: (OFArray*)attrs
{
	[self parserCallbackWithEventType: TAG_START
				     name: name
				   prefix: prefix
				namespace: ns
			       attributes: attrs
				   string: nil];
}

-  (void)parser: (OFXMLParser*)parser
  didEndElement: (OFString*)name
     withPrefix: (OFString*)prefix
	 prefix: (OFString*)prefix
      namespace: (OFString*)ns
{
	[self parserCallbackWithEventType: TAG_END
				     name: name
				   prefix: prefix
				namespace: ns
			       attributes: nil