ObjWebServer  Diff

Differences From Artifact [a1c01b5487]:

To Artifact [46101b0094]:


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
	[super dealloc];
}

- (void)_parseConfig: (OFXMLElement *)config
{
	void *pool = objc_autoreleasePoolPush();

	if ([config namespace] != nil ||
	    ![[config name] isEqual: @"ObjWebServer"])
		[self _invalidConfig: @"Root element is not ObjWebServer"];

	[self _parseListens: [config elementsForName: @"listen"]];
	[self _parseModules: [config elementsForName: @"module"]];

	objc_autoreleasePoolPop(pool);
}

- (void)_parseListens: (OFArray OF_GENERIC(OFXMLElement *) *)elements
{
	OFMutableArray OF_GENERIC(ListenConfig *) *listenConfigs =
	    [OFMutableArray array];

	for (OFXMLElement *element in elements) {
		ListenConfig *listenConfig =
		    [[[ListenConfig alloc] init] autorelease];
		OFString *host = [[element
		    attributeForName: @"host"] stringValue];
		OFString *portString = [[element
		    attributeForName: @"port"] stringValue];
		OFXMLElement *TLS = [element elementForName: @"tls"];

		if (host == nil)
			[self _invalidConfig:
			    @"<listen/> is missing host attribute"];
		if (portString == nil)
			[self _invalidConfig:
			    @"<listen/> is missing port attribute"];

		[listenConfig setHost: host];

		@try {
			intmax_t port = [portString decimalValue];
			if (port < 0 || port > 65535)
				@throw [OFInvalidFormatException exception];

			[listenConfig setPort: port];
		} @catch (OFInvalidFormatException *e) {
			[self _invalidConfig: @"<listen/> has invalid port"];
		}

		if (TLS != nil) {
			OFString *certificateFile =
			    [[TLS attributeForName: @"cert"] stringValue];
			OFString *keyFile =
			    [[TLS attributeForName: @"key"] stringValue];

			if (certificateFile == nil)
				[self _invalidConfig:
				    @"<tls/> has no cert attribute"];
			if (keyFile == nil)
				[self _invalidConfig:
				    @"<tls/> has no key attribute"];

			[listenConfig setTLSCertificateFile: certificateFile];
			[listenConfig setTLSKeyFile: keyFile];
		}

		[listenConfigs addObject: listenConfig];
	}

	[listenConfigs makeImmutable];
	_listenConfigs = [listenConfigs copy];
}

- (void)_parseModules: (OFArray OF_GENERIC(OFXMLElement *) *)elements
{
	OFMutableArray OF_GENERIC(OFXMLElement *) *modules =
	    [OFMutableArray array];

	for (OFXMLElement *element in elements) {
		OFString *path = [[element
		    attributeForName: @"path"] stringValue];
		OFString *prefix = [[element
		    attributeForName: @"prefix"] stringValue];

		if (path == nil || prefix == nil)
			[self _invalidConfig:
			    @"<module/> has no path attribute"];

		[modules addObject: element];
	}







<
|
















|
|
|
|









|


|



|






|

|








|
|















|
|
|
|







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
	[super dealloc];
}

- (void)_parseConfig: (OFXMLElement *)config
{
	void *pool = objc_autoreleasePoolPush();


	if (config.namespace != nil || ![config.name isEqual: @"ObjWebServer"])
		[self _invalidConfig: @"Root element is not ObjWebServer"];

	[self _parseListens: [config elementsForName: @"listen"]];
	[self _parseModules: [config elementsForName: @"module"]];

	objc_autoreleasePoolPop(pool);
}

- (void)_parseListens: (OFArray OF_GENERIC(OFXMLElement *) *)elements
{
	OFMutableArray OF_GENERIC(ListenConfig *) *listenConfigs =
	    [OFMutableArray array];

	for (OFXMLElement *element in elements) {
		ListenConfig *listenConfig =
		    [[[ListenConfig alloc] init] autorelease];
		OFString *host =
		    [element attributeForName: @"host"].stringValue;
		OFString *portString =
		    [element attributeForName: @"port"].stringValue;
		OFXMLElement *TLS = [element elementForName: @"tls"];

		if (host == nil)
			[self _invalidConfig:
			    @"<listen/> is missing host attribute"];
		if (portString == nil)
			[self _invalidConfig:
			    @"<listen/> is missing port attribute"];

		listenConfig.host = host;

		@try {
			intmax_t port = portString.decimalValue;
			if (port < 0 || port > 65535)
				@throw [OFInvalidFormatException exception];

			listenConfig.port = port;
		} @catch (OFInvalidFormatException *e) {
			[self _invalidConfig: @"<listen/> has invalid port"];
		}

		if (TLS != nil) {
			OFString *certificateFile =
			    [TLS attributeForName: @"cert"].stringValue;
			OFString *keyFile =
			    [TLS attributeForName: @"key"].stringValue;

			if (certificateFile == nil)
				[self _invalidConfig:
				    @"<tls/> has no cert attribute"];
			if (keyFile == nil)
				[self _invalidConfig:
				    @"<tls/> has no key attribute"];

			listenConfig.TLSCertificateFile = certificateFile;
			listenConfig.TLSKeyFile = keyFile;
		}

		[listenConfigs addObject: listenConfig];
	}

	[listenConfigs makeImmutable];
	_listenConfigs = [listenConfigs copy];
}

- (void)_parseModules: (OFArray OF_GENERIC(OFXMLElement *) *)elements
{
	OFMutableArray OF_GENERIC(OFXMLElement *) *modules =
	    [OFMutableArray array];

	for (OFXMLElement *element in elements) {
		OFString *path =
		    [element attributeForName: @"path"].stringValue;
		OFString *prefix =
		    [element attributeForName: @"prefix"].stringValue;

		if (path == nil || prefix == nil)
			[self _invalidConfig:
			    @"<module/> has no path attribute"];

		[modules addObject: element];
	}