* Fixed link error in BLIPClient target.
* Fixed *Ph*n* #ifdef issue (thanks, Jimmy)
5 // Created by Jens Alfke on 5/10/08.
6 // Copyright 2008 Jens Alfke. All rights reserved.
9 #import <Foundation/Foundation.h>
10 @class BLIPConnection, BLIPProperties, BLIPMutableProperties;
13 /** NSError domain and codes for BLIP */
14 extern NSString* const BLIPErrorDomain;
16 kBLIPError_BadData = 1,
18 kBLIPError_Disconnected,
19 kBLIPError_PeerNotAllowed,
23 // errors returned in responses:
24 kBLIPError_BadRequest = 400,
25 kBLIPError_Forbidden = 403,
26 kBLIPError_NotFound = 404,
27 kBLIPError_BadRange = 416,
29 kBLIPError_HandlerFailed = 501,
30 kBLIPError_Unspecified = 599 // peer didn't send any detailed error info
33 NSError *BLIPMakeError( int errorCode, NSString *message, ... ) __attribute__ ((format (__NSString__, 2, 3)));
36 /** Abstract superclass for <a href=".#blipdesc">BLIP</a> requests and responses. */
37 @interface BLIPMessage : NSObject
39 BLIPConnection *_connection;
42 BLIPProperties *_properties;
44 NSMutableData *_encodedBody;
45 NSMutableData *_mutableBody;
46 BOOL _isMine, _isMutable, _sent, _propertiesAvailable, _complete;
50 /** The BLIPConnection associated with this message. */
51 @property (readonly,retain) BLIPConnection *connection;
53 /** This message's serial number in its connection.
54 A BLIPRequest's number is initially zero, then assigned when it's sent.
55 A BLIPResponse is automatically assigned the same number as the request it replies to. */
56 @property (readonly) UInt32 number;
58 /** Is this a message sent by me (as opposed to the peer)? */
59 @property (readonly) BOOL isMine;
61 /** Has this message been sent yet? (Only makes sense when isMe is set.) */
62 @property (readonly) BOOL sent;
64 /** Has enough of the message arrived to read its properies? */
65 @property (readonly) BOOL propertiesAvailable;
67 /** Has the entire message, including the body, arrived? */
68 @property (readonly) BOOL complete;
70 /** Should the message body be compressed with gzip?
71 This property can only be set <i>before</i> sending the message. */
72 @property BOOL compressed;
74 /** Should the message be sent ahead of normal-priority messages?
75 This property can only be set <i>before</i> sending the message. */
76 @property BOOL urgent;
78 /** Can this message be changed? (Only true for outgoing messages, before you send them.) */
79 @property (readonly) BOOL isMutable;
81 /** The message body, a blob of arbitrary data. */
82 @property (copy) NSData *body;
84 /** Appends data to the body. */
85 - (void) addToBody: (NSData*)data;
87 /** The message body as an NSString.
88 The UTF-8 character encoding is used to convert. */
89 @property (copy) NSString *bodyString;
91 #pragma mark PROPERTIES:
93 /** The message's properties, a dictionary-like object.
94 Message properties are much like the headers in HTTP, MIME and RFC822. */
95 @property (readonly) BLIPProperties* properties;
97 /** Mutable version of the message's properties; only available if this mesage is mutable. */
98 @property (readonly) BLIPMutableProperties* mutableProperties;
100 /** The value of the "Content-Type" property, which is by convention the MIME type of the body. */
101 @property (copy) NSString *contentType;
103 /** The value of the "Profile" property, which by convention identifies the purpose of the message. */
104 @property (copy) NSString *profile;
106 /** A shortcut to get the value of a property. */
107 - (NSString*) valueOfProperty: (NSString*)property;
109 /** A shortcut to set the value of a property. A nil value deletes that property. */
110 - (void) setValue: (NSString*)value ofProperty: (NSString*)property;
112 /** Similar to -description, but also shows the properties and their values. */
113 @property (readonly) NSString* descriptionWithProperties;