1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/BLIP/BLIPMessage.h Fri May 23 17:37:36 2008 -0700
1.3 @@ -0,0 +1,109 @@
1.4 +//
1.5 +// BLIPMessage.h
1.6 +// MYNetwork
1.7 +//
1.8 +// Created by Jens Alfke on 5/10/08.
1.9 +// Copyright 2008 Jens Alfke. All rights reserved.
1.10 +//
1.11 +
1.12 +#import <Foundation/Foundation.h>
1.13 +@class BLIPConnection, BLIPProperties, BLIPMutableProperties;
1.14 +
1.15 +
1.16 +/** NSError domain and codes for BLIP */
1.17 +extern NSString* const BLIPErrorDomain;
1.18 +enum {
1.19 + kBLIPError_BadData = 1,
1.20 + kBLIPError_BadFrame,
1.21 + kBLIPError_Disconnected,
1.22 + kBLIPError_PeerNotAllowed,
1.23 +
1.24 + kBLIPError_Misc = 99,
1.25 +
1.26 + // errors returned in responses:
1.27 + kBLIPError_BadRequest = 400,
1.28 + kBLIPError_Forbidden = 403,
1.29 + kBLIPError_NotFound = 404,
1.30 + kBLIPError_BadRange = 416,
1.31 +
1.32 + kBLIPError_HandlerFailed = 501,
1.33 + kBLIPError_Unspecified = 599 // peer didn't send any detailed error info
1.34 +};
1.35 +
1.36 +
1.37 +/** Abstract superclass for both requests and responses. */
1.38 +@interface BLIPMessage : NSObject
1.39 +{
1.40 + BLIPConnection *_connection;
1.41 + UInt16 _flags;
1.42 + UInt32 _number;
1.43 + BLIPProperties *_properties;
1.44 + NSData *_body;
1.45 + NSMutableData *_encodedBody;
1.46 + NSMutableData *_mutableBody;
1.47 + BOOL _isMine, _isMutable, _sent, _propertiesAvailable, _complete;
1.48 + SInt32 _bytesWritten;
1.49 +};
1.50 +
1.51 +/** The BLIPConnection associated with this message. */
1.52 +@property (readonly,retain) BLIPConnection *connection;
1.53 +
1.54 +/** This message's serial number in its connection.
1.55 + A BLIPRequest's number is initially zero, then assigned when it's sent.
1.56 + A BLIPResponse is automatically assigned the same number as the request it replies to. */
1.57 +@property (readonly) UInt32 number;
1.58 +
1.59 +/** Is this a message sent by me (as opposed to the peer)? */
1.60 +@property (readonly) BOOL isMine;
1.61 +
1.62 +/** Has this message been sent yet? (Only makes sense when isMe is set.) */
1.63 +@property (readonly) BOOL sent;
1.64 +
1.65 +/** Has enough of the message arrived to read its properies? */
1.66 +@property (readonly) BOOL propertiesAvailable;
1.67 +
1.68 +/** Has the entire message, including the body, arrived? */
1.69 +@property (readonly) BOOL complete;
1.70 +
1.71 +/** Should the message body be compressed using gzip?
1.72 + This property can only be set before sending the message. */
1.73 +@property BOOL compressed;
1.74 +
1.75 +/** Should the message be sent ahead of normal-priority messages?
1.76 + This property can only be set before sending the message. */
1.77 +@property BOOL urgent;
1.78 +
1.79 +/** Can this message be changed? (Only true for outgoing messages, before you send them.) */
1.80 +@property (readonly) BOOL isMutable;
1.81 +
1.82 +/** The message body, a blob of arbitrary data. */
1.83 +@property (copy) NSData *body;
1.84 +
1.85 +/** Appends data to the body. */
1.86 +- (void) addToBody: (NSData*)data;
1.87 +
1.88 +#pragma mark PROPERTIES:
1.89 +
1.90 +/** The message's properties, a dictionary-like object. */
1.91 +@property (readonly) BLIPProperties* properties;
1.92 +
1.93 +/** Mutable version of the message's properties; only available if this mesage is mutable. */
1.94 +@property (readonly) BLIPMutableProperties* mutableProperties;
1.95 +
1.96 +/** The value of the "Content-Type" property, which is by convention the MIME type of the body. */
1.97 +@property (copy) NSString *contentType;
1.98 +
1.99 +/** The value of the "Profile" property, which by convention identifies the purpose of the message. */
1.100 +@property (copy) NSString *profile;
1.101 +
1.102 +/** A shortcut to get the value of a property. */
1.103 +- (NSString*) valueOfProperty: (NSString*)property;
1.104 +
1.105 +/** A shortcut to set the value of a property. A nil value deletes that property. */
1.106 +- (void) setValue: (NSString*)value ofProperty: (NSString*)property;
1.107 +
1.108 +/** Similar to -description, but also shows the properties and their values. */
1.109 +@property (readonly) NSString* descriptionWithProperties;
1.110 +
1.111 +
1.112 +@end