ObjFW  Diff

Differences From Artifact [5a4bde7403]:

To Artifact [eadf4aca10]:


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
 * file.
 */

#include "config.h"

#import "OFHTTPRequestReply.h"
#import "OFString.h"
#import "OFDataArray.h"
#import "OFDictionary.h"

#import "autorelease.h"
#import "macros.h"

@implementation OFHTTPRequestReply
+ replyWithStatusCode: (short)status
	      headers: (OFDictionary*)headers
		 data: (OFDataArray*)data
{
	return [[[self alloc] initWithStatusCode: status
					 headers: headers
					    data: data] autorelease];
}

- initWithStatusCode: (short)status
	     headers: (OFDictionary*)headers_
		data: (OFDataArray*)data_
{
	self = [super init];

	@try {
		statusCode = status;
		headers = [headers_ copy];
		data = [data_ retain];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[headers release];
	[data release];

	[super dealloc];
}

















































- (short)statusCode
{
	return statusCode;
}






- (OFDictionary*)headers
{
	OF_GETTER(headers, YES)
}

- (OFDataArray*)data
{
	OF_GETTER(data, YES)
}

- (OFString*)description
{
	void *pool = objc_autoreleasePoolPush();
	OFString *indentedHeaders, *indentedData, *ret;

	indentedHeaders = [[headers description]
	    stringByReplacingOccurrencesOfString: @"\n"
				      withString: @"\n\t"];
	indentedData = [[data description]
	    stringByReplacingOccurrencesOfString: @"\n"
				      withString: @"\n\t"];

	ret = [[OFString alloc] initWithFormat:
	    @"<%@:\n"
	    @"\tStatus code = %d\n"
	    @"\tHeaders = %@\n"
	    @"\tData = %@\n"
	    @">",
	    [self class], statusCode, indentedHeaders, indentedData];

	objc_autoreleasePoolPop(pool);

	return [ret autorelease];
}
@end







|
|




|
|
<
<
<
<
|
<
|
|
|
<
<



<
|
<
|
<
<
<
<







<




>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>




>
>
>
>
>






|

|





|


<
<
<







<

|






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




29

30
31
32


33
34
35

36

37




38
39
40
41
42
43
44

45
46
47
48
49
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
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
 * file.
 */

#include "config.h"

#import "OFHTTPRequestReply.h"
#import "OFString.h"
#import "OFDictionary.h"
#import "OFArray.h"

#import "autorelease.h"
#import "macros.h"

#import "OFInvalidFormatException.h"
#import "OFOutOfRangeException.h"




#import "OFUnsupportedVersionException.h"


@implementation OFHTTPRequestReply
- init


{
	self = [super init];


	protocolVersion.major = 1;

	protocolVersion.minor = 1;





	return self;
}

- (void)dealloc
{
	[headers release];


	[super dealloc];
}

- (void)setProtocolVersion: (of_http_request_protocol_version_t)protocolVersion_
{
	if (protocolVersion_.major != 1 || protocolVersion.minor > 1)
		@throw [OFUnsupportedVersionException
		    exceptionWithClass: [self class]
			       version: [OFString stringWithFormat: @"%u.%u",
					    protocolVersion_.major,
					    protocolVersion_.minor]];

	protocolVersion = protocolVersion_;
}

- (of_http_request_protocol_version_t)protocolVersion
{
	return protocolVersion;
}

- (void)setProtocolVersionFromString: (OFString*)string
{
	void *pool = objc_autoreleasePoolPush();
	OFArray *components = [string componentsSeparatedByString: @"."];
	intmax_t major, minor;
	of_http_request_protocol_version_t protocolVersion_;

	if ([components count] != 2)
		@throw [OFInvalidFormatException
		    exceptionWithClass: [self class]];

	major = [[components firstObject] decimalValue];
	minor = [[components lastObject] decimalValue];

	if (major < 0 || major > UINT8_MAX || minor < 0 || minor > UINT8_MAX)
		@throw [OFOutOfRangeException exceptionWithClass: [self class]];

	protocolVersion_.major = (uint8_t)major;
	protocolVersion_.minor = (uint8_t)minor;

	[self setProtocolVersion: protocolVersion_];

	objc_autoreleasePoolPop(pool);
}

- (OFString*)protocolVersionString
{
	return [OFString stringWithFormat: @"%u.%u", protocolVersion.major,
					   protocolVersion.minor];
}

- (short)statusCode
{
	return statusCode;
}

- (void)setStatusCode: (short)statusCode_
{
	statusCode = statusCode_;
}

- (OFDictionary*)headers
{
	OF_GETTER(headers, YES)
}

- (void)setHeaders: (OFDictionary*)headers_
{
	OF_SETTER(headers, headers_, YES, YES)
}

- (OFString*)description
{
	void *pool = objc_autoreleasePoolPush();
	OFString *indentedHeaders, *ret;

	indentedHeaders = [[headers description]



	    stringByReplacingOccurrencesOfString: @"\n"
				      withString: @"\n\t"];

	ret = [[OFString alloc] initWithFormat:
	    @"<%@:\n"
	    @"\tStatus code = %d\n"
	    @"\tHeaders = %@\n"

	    @">",
	    [self class], statusCode, indentedHeaders];

	objc_autoreleasePoolPop(pool);

	return [ret autorelease];
}
@end