1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/BLIP/BLIP_Internal.h Fri May 23 17:37:36 2008 -0700
1.3 @@ -0,0 +1,86 @@
1.4 +//
1.5 +// BLIP_Internal.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 "BLIPConnection.h"
1.13 +#import "BLIPRequest.h"
1.14 +#import "BLIPProperties.h"
1.15 +@class BLIPWriter;
1.16 +
1.17 +
1.18 +/* Private declarations and APIs for BLIP implementation. Not for use by clients! */
1.19 +
1.20 +
1.21 +/* BLIP message types; encoded in each frame's header. */
1.22 +typedef enum {
1.23 + kBLIP_MSG, // initiating message
1.24 + kBLIP_RPY, // response to a MSG
1.25 + kBLIP_ERR // error response to a MSG
1.26 +} BLIPMessageType;
1.27 +
1.28 +/* Flag bits in a BLIP frame header */
1.29 +enum {
1.30 + kBLIP_TypeMask = 0x000F, // bits reserved for storing message type
1.31 + kBLIP_Compressed= 0x0010, // data is gzipped
1.32 + kBLIP_Urgent = 0x0020, // please send sooner/faster
1.33 + kBLIP_NoReply = 0x0040, // no RPY needed
1.34 + kBLIP_MoreComing= 0x0080, // More frames coming (Applies only to individual frame)
1.35 +};
1.36 +typedef UInt16 BLIPMessageFlags;
1.37 +
1.38 +
1.39 +/** Header of a BLIP frame as sent across the wire. All fields are big-endian. */
1.40 +typedef struct {
1.41 + UInt32 magic; // magic number (kBLIPFrameHeaderMagicNumber)
1.42 + UInt32 number; // serial number of MSG
1.43 + BLIPMessageFlags flags; // encodes frame type, "more" flag, and other delivery options
1.44 + UInt16 size; // total size of frame, _including_ this header
1.45 +} BLIPFrameHeader;
1.46 +
1.47 +#define kBLIPFrameHeaderMagicNumber 0x9B34F205
1.48 +
1.49 +
1.50 +NSError *BLIPMakeError( int errorCode, NSString *message, ... ) __attribute__ ((format (__NSString__, 2, 3)));
1.51 +
1.52 +
1.53 +@interface BLIPConnection ()
1.54 +- (void) _dispatchRequest: (BLIPRequest*)request;
1.55 +- (void) _dispatchResponse: (BLIPResponse*)response;
1.56 +@end
1.57 +
1.58 +
1.59 +@interface BLIPMessage ()
1.60 +@property BOOL sent, propertiesAvailable, complete;
1.61 +- (void) _setFlag: (BLIPMessageFlags)flag value: (BOOL)value;
1.62 +- (void) _encode;
1.63 +@end
1.64 +
1.65 +
1.66 +@interface BLIPMessage ()
1.67 +- (id) _initWithConnection: (BLIPConnection*)connection
1.68 + isMine: (BOOL)isMine
1.69 + flags: (BLIPMessageFlags)flags
1.70 + number: (UInt32)msgNo
1.71 + body: (NSData*)body;
1.72 +- (BOOL) _writeFrameTo: (BLIPWriter*)writer maxSize: (UInt16)maxSize;
1.73 +@property (readonly) SInt32 _bytesWritten;
1.74 +- (void) _assignedNumber: (UInt32)number;
1.75 +- (BOOL) _receivedFrameWithHeader: (const BLIPFrameHeader*)header body: (NSData*)body;
1.76 +- (void) _connectionClosed;
1.77 +@end
1.78 +
1.79 +
1.80 +@interface BLIPRequest ()
1.81 +- (id) _initWithConnection: (BLIPConnection*)connection
1.82 + body: (NSData*)body
1.83 + properties: (NSDictionary*)properties;
1.84 +@end
1.85 +
1.86 +
1.87 +@interface BLIPResponse ()
1.88 +- (id) _initWithRequest: (BLIPRequest*)request;
1.89 +@end