Index: src/OFHTTPClient.m ================================================================== --- src/OFHTTPClient.m +++ src/OFHTTPClient.m @@ -114,11 +114,11 @@ static OFString * constructRequestString(OFHTTPRequest *request) { void *pool = objc_autoreleasePoolPush(); - of_http_request_method_t method = request.method; + OFHTTPRequestMethod method = request.method; OFURL *URL = request.URL; OFString *path; OFString *user = URL.user, *password = URL.password; OFMutableString *requestString; OFMutableDictionary OF_GENERIC(OFString *, OFString *) *headers; @@ -130,11 +130,11 @@ path = URL.URLEncodedPath; else path = @"/"; requestString = [OFMutableString stringWithFormat: - @"%s %@", of_http_request_method_to_string(method), path]; + @"%s %@", OFHTTPRequestMethodName(method), path]; if (URL.query != nil) { [requestString appendString: @"?"]; [requestString appendString: URL.URLEncodedQuery]; } @@ -233,21 +233,21 @@ str++; } } static bool -defaultShouldFollow(of_http_request_method_t method, short statusCode) +defaultShouldFollow(OFHTTPRequestMethod method, short statusCode) { bool follow; /* * 301, 302 and 307 should only redirect with user confirmation if the * request method is not GET or HEAD. Asking the delegate and getting * true returned is considered user confirmation. */ - if (method == OF_HTTP_REQUEST_METHOD_GET || - method == OF_HTTP_REQUEST_METHOD_HEAD) + if (method == OFHTTPRequestMethodGet || + method == OFHTTPRequestMethodHead) follow = true; /* 303 should always be redirected and converted to a GET request. */ else if (statusCode == 303) follow = true; else @@ -330,11 +330,11 @@ response.of_keepAlive = true; _client->_socket = [sock retain]; _client->_lastURL = [URL copy]; _client->_lastWasHEAD = - (_request.method == OF_HTTP_REQUEST_METHOD_HEAD); + (_request.method == OFHTTPRequestMethodHead); _client->_lastResponse = [response retain]; } if (_redirects > 0 && (_status == 301 || _status == 302 || _status == 303 || _status == 307) && @@ -399,11 +399,11 @@ if ([key hasPrefix: @"Content-"] || [key hasPrefix: @"Transfer-"]) [newHeaders removeObjectForKey: key]; - newRequest.method = OF_HTTP_REQUEST_METHOD_GET; + newRequest.method = OFHTTPRequestMethodGet; } newRequest.URL = newURL; newRequest.headers = newHeaders; Index: src/OFHTTPRequest.h ================================================================== --- src/OFHTTPRequest.h +++ src/OFHTTPRequest.h @@ -28,54 +28,52 @@ /** @file */ /** * @brief The type of an HTTP request. */ -typedef enum { +typedef enum OFHTTPRequestMethod { /** OPTIONS */ - OF_HTTP_REQUEST_METHOD_OPTIONS, + OFHTTPRequestMethodOptions, /** GET */ - OF_HTTP_REQUEST_METHOD_GET, + OFHTTPRequestMethodGet, /** HEAD */ - OF_HTTP_REQUEST_METHOD_HEAD, + OFHTTPRequestMethodHead, /** POST */ - OF_HTTP_REQUEST_METHOD_POST, + OFHTTPRequestMethodPost, /** PUT */ - OF_HTTP_REQUEST_METHOD_PUT, + OFHTTPRequestMethodPut, /** DELETE */ - OF_HTTP_REQUEST_METHOD_DELETE, + OFHTTPRequestMethodDelete, /** TRACE */ - OF_HTTP_REQUEST_METHOD_TRACE, + OFHTTPRequestMethodTrace, /** CONNECT */ - OF_HTTP_REQUEST_METHOD_CONNECT -} of_http_request_method_t; + OFHTTPRequestMethodConnect +} OFHTTPRequestMethod; /** - * @struct of_http_request_protocol_version_t \ - * OFHTTPRequest.h ObjFW/OFHTTPRequest.h + * @struct OFHTTPRequestProtocolVersion OFHTTPRequest.h ObjFW/OFHTTPRequest.h * * @brief The HTTP version of the HTTP request. */ -struct OF_BOXABLE of_http_request_protocol_version_t { +struct OF_BOXABLE OFHTTPRequestProtocolVersion { /** The major of the HTTP version */ unsigned char major; /** The minor of the HTTP version */ unsigned char minor; }; -typedef struct of_http_request_protocol_version_t - of_http_request_protocol_version_t; +typedef struct OFHTTPRequestProtocolVersion OFHTTPRequestProtocolVersion; /** * @class OFHTTPRequest OFHTTPRequest.h ObjFW/OFHTTPRequest.h * * @brief A class for storing HTTP requests. */ @interface OFHTTPRequest: OFObject { OFURL *_URL; - of_http_request_method_t _method; - of_http_request_protocol_version_t _protocolVersion; + OFHTTPRequestMethod _method; + OFHTTPRequestProtocolVersion _protocolVersion; OFDictionary OF_GENERIC(OFString *, OFString *) *_Nullable _headers; OFSocketAddress _remoteAddress; bool _hasRemoteAddress; OF_RESERVE_IVARS(OFHTTPRequest, 4) } @@ -86,21 +84,21 @@ @property (copy, nonatomic) OFURL *URL; /** * @brief The protocol version of the HTTP request. */ -@property (nonatomic) of_http_request_protocol_version_t protocolVersion; +@property (nonatomic) OFHTTPRequestProtocolVersion protocolVersion; /** * @brief The protocol version of the HTTP request as a string. */ @property (copy, nonatomic) OFString *protocolVersionString; /** * @brief The request method of the HTTP request. */ -@property (nonatomic) of_http_request_method_t method; +@property (nonatomic) OFHTTPRequestMethod method; /** * @brief The headers for the HTTP request. */ @property OF_NULLABLE_PROPERTY (copy, nonatomic) @@ -144,21 +142,20 @@ * @brief Returns a C string describing the specified request method. * * @param method The request method which should be described as a C string * @return A C string describing the specified request method */ -extern const char *_Nullable of_http_request_method_to_string( - of_http_request_method_t method); +extern const char *_Nullable OFHTTPRequestMethodName( + OFHTTPRequestMethod method); /** * @brief Returns the request method for the specified string. * * @param string The string for which the request method should be returned * @return The request method for the specified string */ -extern of_http_request_method_t of_http_request_method_from_string( - OFString *string); +extern OFHTTPRequestMethod OFHTTPRequestMethodParseName(OFString *string); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END Index: src/OFHTTPRequest.m ================================================================== --- src/OFHTTPRequest.m +++ src/OFHTTPRequest.m @@ -28,53 +28,53 @@ #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" #import "OFUnsupportedVersionException.h" const char * -of_http_request_method_to_string(of_http_request_method_t method) +OFHTTPRequestMethodName(OFHTTPRequestMethod method) { switch (method) { - case OF_HTTP_REQUEST_METHOD_OPTIONS: + case OFHTTPRequestMethodOptions: return "OPTIONS"; - case OF_HTTP_REQUEST_METHOD_GET: + case OFHTTPRequestMethodGet: return "GET"; - case OF_HTTP_REQUEST_METHOD_HEAD: + case OFHTTPRequestMethodHead: return "HEAD"; - case OF_HTTP_REQUEST_METHOD_POST: + case OFHTTPRequestMethodPost: return "POST"; - case OF_HTTP_REQUEST_METHOD_PUT: + case OFHTTPRequestMethodPut: return "PUT"; - case OF_HTTP_REQUEST_METHOD_DELETE: + case OFHTTPRequestMethodDelete: return "DELETE"; - case OF_HTTP_REQUEST_METHOD_TRACE: + case OFHTTPRequestMethodTrace: return "TRACE"; - case OF_HTTP_REQUEST_METHOD_CONNECT: + case OFHTTPRequestMethodConnect: return "CONNECT"; } return NULL; } -of_http_request_method_t -of_http_request_method_from_string(OFString *string) +OFHTTPRequestMethod +OFHTTPRequestMethodParseName(OFString *string) { if ([string isEqual: @"OPTIONS"]) - return OF_HTTP_REQUEST_METHOD_OPTIONS; + return OFHTTPRequestMethodOptions; if ([string isEqual: @"GET"]) - return OF_HTTP_REQUEST_METHOD_GET; + return OFHTTPRequestMethodGet; if ([string isEqual: @"HEAD"]) - return OF_HTTP_REQUEST_METHOD_HEAD; + return OFHTTPRequestMethodHead; if ([string isEqual: @"POST"]) - return OF_HTTP_REQUEST_METHOD_POST; + return OFHTTPRequestMethodPost; if ([string isEqual: @"PUT"]) - return OF_HTTP_REQUEST_METHOD_PUT; + return OFHTTPRequestMethodPut; if ([string isEqual: @"DELETE"]) - return OF_HTTP_REQUEST_METHOD_DELETE; + return OFHTTPRequestMethodDelete; if ([string isEqual: @"TRACE"]) - return OF_HTTP_REQUEST_METHOD_TRACE; + return OFHTTPRequestMethodTrace; if ([string isEqual: @"CONNECT"]) - return OF_HTTP_REQUEST_METHOD_CONNECT; + return OFHTTPRequestMethodConnect; @throw [OFInvalidArgumentException exception]; } @implementation OFHTTPRequest @@ -92,11 +92,11 @@ - (instancetype)init { self = [super init]; - _method = OF_HTTP_REQUEST_METHOD_GET; + _method = OFHTTPRequestMethodGet; _protocolVersion.major = 1; _protocolVersion.minor = 1; return self; } @@ -200,11 +200,11 @@ OF_HASH_FINALIZE(hash); return hash; } -- (void)setProtocolVersion: (of_http_request_protocol_version_t)protocolVersion +- (void)setProtocolVersion: (OFHTTPRequestProtocolVersion)protocolVersion { if (protocolVersion.major != 1 || protocolVersion.minor > 1) @throw [OFUnsupportedVersionException exceptionWithVersion: [OFString stringWithFormat: @"%hhu.%hhu", protocolVersion.major, @@ -211,21 +211,21 @@ protocolVersion.minor]]; _protocolVersion = protocolVersion; } -- (of_http_request_protocol_version_t)protocolVersion +- (OFHTTPRequestProtocolVersion)protocolVersion { return _protocolVersion; } - (void)setProtocolVersionString: (OFString *)string { void *pool = objc_autoreleasePoolPush(); OFArray *components = [string componentsSeparatedByString: @"."]; unsigned long long major, minor; - of_http_request_protocol_version_t protocolVersion; + OFHTTPRequestProtocolVersion protocolVersion; if (components.count != 2) @throw [OFInvalidFormatException exception]; major = [components.firstObject unsignedLongLongValue]; @@ -250,11 +250,11 @@ } - (OFString *)description { void *pool = objc_autoreleasePoolPush(); - const char *method = of_http_request_method_to_string(_method); + const char *method = OFHTTPRequestMethodName(_method); OFString *indentedHeaders, *remoteAddress, *ret; indentedHeaders = [_headers.description stringByReplacingOccurrencesOfString: @"\n" withString: @"\n\t"]; Index: src/OFHTTPResponse.h ================================================================== --- src/OFHTTPResponse.h +++ src/OFHTTPResponse.h @@ -26,20 +26,20 @@ * * @brief A class for representing an HTTP request reply as a stream. */ @interface OFHTTPResponse: OFStream { - of_http_request_protocol_version_t _protocolVersion; + OFHTTPRequestProtocolVersion _protocolVersion; short _statusCode; OFDictionary OF_GENERIC(OFString *, OFString *) *_headers; OF_RESERVE_IVARS(OFHTTPResponse, 4) } /** * @brief The protocol version of the HTTP request reply. */ -@property (nonatomic) of_http_request_protocol_version_t protocolVersion; +@property (nonatomic) OFHTTPRequestProtocolVersion protocolVersion; /** * @brief The protocol version of the HTTP request reply as a string. */ @property (copy, nonatomic) OFString *protocolVersionString; @@ -76,11 +76,11 @@ * @brief Returns a description string for the specified HTTP status code. * * @param code The HTTP status code to return a description string for * @return A description string for the specified HTTP status code */ -extern OFString *_Nonnull of_http_status_code_to_string(short code); +extern OFString *_Nonnull OFHTTPStatusCodeString(short code); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END Index: src/OFHTTPResponse.m ================================================================== --- src/OFHTTPResponse.m +++ src/OFHTTPResponse.m @@ -26,11 +26,11 @@ #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" #import "OFUnsupportedVersionException.h" OFString * -of_http_status_code_to_string(short code) +OFHTTPStatusCodeString(short code) { switch (code) { case 100: return @"Continue"; case 101: @@ -247,11 +247,11 @@ [_headers release]; [super dealloc]; } -- (void)setProtocolVersion: (of_http_request_protocol_version_t)protocolVersion +- (void)setProtocolVersion: (OFHTTPRequestProtocolVersion)protocolVersion { if (protocolVersion.major != 1 || protocolVersion.minor > 1) @throw [OFUnsupportedVersionException exceptionWithVersion: [OFString stringWithFormat: @"%hhu.%hhu", protocolVersion.major, @@ -258,21 +258,21 @@ protocolVersion.minor]]; _protocolVersion = protocolVersion; } -- (of_http_request_protocol_version_t)protocolVersion +- (OFHTTPRequestProtocolVersion)protocolVersion { return _protocolVersion; } - (void)setProtocolVersionString: (OFString *)string { void *pool = objc_autoreleasePoolPush(); OFArray *components = [string componentsSeparatedByString: @"."]; unsigned long long major, minor; - of_http_request_protocol_version_t protocolVersion; + OFHTTPRequestProtocolVersion protocolVersion; if (components.count != 2) @throw [OFInvalidFormatException exception]; major = [components.firstObject unsignedLongLongValue]; Index: src/OFHTTPServer.m ================================================================== --- src/OFHTTPServer.m +++ src/OFHTTPServer.m @@ -80,11 +80,11 @@ AWAITING_PROLOG, PARSING_HEADERS, SEND_RESPONSE } _state; uint8_t _HTTPMinorVersion; - of_http_request_method_t _method; + OFHTTPRequestMethod _method; OFString *_host, *_path; uint16_t _port; OFMutableDictionary *_headers; size_t _contentLength; OFStream *_requestBody; @@ -187,11 +187,11 @@ OFEnumerator *keyEnumerator, *valueEnumerator; OFString *key, *value; [_socket writeFormat: @"HTTP/%@ %hd %@\r\n", self.protocolVersionString, _statusCode, - of_http_status_code_to_string(_statusCode)]; + OFHTTPStatusCodeString(_statusCode)]; headers = [[_headers mutableCopy] autorelease]; if ([headers objectForKey: @"Date"] == nil) { OFString *date = [[OFDate date] @@ -373,11 +373,11 @@ if (pos == OFNotFound) return [self sendErrorAndClose: 400]; method = [line substringToIndex: pos]; @try { - _method = of_http_request_method_from_string(method); + _method = OFHTTPRequestMethodParseName(method); } @catch (OFInvalidArgumentException *e) { return [self sendErrorAndClose: 405]; } @try { @@ -497,12 +497,11 @@ dateStringWithFormat: @"%a, %d %b %Y %H:%M:%S GMT"]; [_socket writeFormat: @"HTTP/1.1 %hd %@\r\n" @"Date: %@\r\n" @"Server: %@\r\n" @"\r\n", - statusCode, - of_http_status_code_to_string(statusCode), + statusCode, OFHTTPStatusCodeString(statusCode), date, _server.name]; return false; } - (void)createResponse @@ -548,11 +547,11 @@ [URL makeImmutable]; request = [OFHTTPRequest requestWithURL: URL]; request.method = _method; request.protocolVersion = - (of_http_request_protocol_version_t){ 1, _HTTPMinorVersion }; + (OFHTTPRequestProtocolVersion){ 1, _HTTPMinorVersion }; request.headers = _headers; request.remoteAddress = _socket.remoteAddress; response = [[[OFHTTPServerResponse alloc] initWithSocket: _socket Index: src/exceptions/OFHTTPRequestFailedException.m ================================================================== --- src/exceptions/OFHTTPRequestFailedException.m +++ src/exceptions/OFHTTPRequestFailedException.m @@ -59,12 +59,12 @@ [super dealloc]; } - (OFString *)description { - const char *method = of_http_request_method_to_string(_request.method); + const char *method = OFHTTPRequestMethodName(_request.method); return [OFString stringWithFormat: @"An HTTP %s request with URL %@ failed with code %hd!", method, _request.URL, _response.statusCode]; } @end Index: utils/ofhttp/OFHTTP.m ================================================================== --- utils/ofhttp/OFHTTP.m +++ utils/ofhttp/OFHTTP.m @@ -64,11 +64,11 @@ OFString *_outputPath, *_currentFileName; bool _continue, _force, _detectFileName, _detectFileNameRequest; bool _detectedFileName, _quiet, _verbose, _insecure, _ignoreStatus; bool _useUnicode; OFStream *_body; - of_http_request_method_t _method; + OFHTTPRequestMethod _method; OFMutableDictionary *_clientHeaders; OFHTTPClient *_HTTPClient; char *_buffer; OFStream *_output; unsigned long long _received, _length, _resumedFrom; @@ -292,11 +292,11 @@ - (instancetype)init { self = [super init]; @try { - _method = OF_HTTP_REQUEST_METHOD_GET; + _method = OFHTTPRequestMethodGet; _clientHeaders = [[OFMutableDictionary alloc] initWithObject: @"OFHTTP" forKey: @"User-Agent"]; @@ -368,11 +368,11 @@ void *pool = objc_autoreleasePoolPush(); method = method.uppercaseString; @try { - _method = of_http_request_method_from_string(method); + _method = OFHTTPRequestMethodParseName(method); } @catch (OFInvalidArgumentException *e) { [of_stderr writeLine: OF_LOCALIZED(@"invalid_input_method", @"%[prog]: Invalid request method %[method]!", @"prog", [OFApplication programName], @"method", method)]; @@ -886,12 +886,11 @@ goto after_exception_handling; } statusCode = response.statusCode; codeString = [OFString stringWithFormat: @"%hd %@", - statusCode, - of_http_status_code_to_string(statusCode)]; + statusCode, OFHTTPStatusCodeString(statusCode)]; [of_stderr writeLine: OF_LOCALIZED(@"download_failed", @"%[prog]: Failed to download <%[url]>!\n" @" HTTP status code: %[code]", @"prog", [OFApplication programName], @"url", request.URL.string, @@ -904,11 +903,11 @@ afterDelay: 0]; return; } after_exception_handling: - if (_method == OF_HTTP_REQUEST_METHOD_HEAD) + if (_method == OFHTTPRequestMethodHead) goto next; if (_detectFileNameRequest) { _currentFileName = [fileNameFromContentDisposition( [response.headers objectForKey: @"Content-Disposition"]) @@ -1029,11 +1028,11 @@ [of_stdout writeFormat: @"? %@", URL.string]; } request = [OFHTTPRequest requestWithURL: URL]; request.headers = clientHeaders; - request.method = OF_HTTP_REQUEST_METHOD_HEAD; + request.method = OFHTTPRequestMethodHead; _detectFileNameRequest = true; [_HTTPClient asyncPerformRequest: request]; return; }