BLIP/BLIP_Internal.h
author Dan Preston <danpreston@codechemistry.com>
Tue May 05 15:10:15 2009 -0700 (2009-05-05)
changeset 37 7c7d5a0cb4d6
parent 18 3be241de1630
permissions -rw-r--r--
Fixed the leak of SecIdentityRef objects in a while loop.
     1 //
     2 //  BLIP_Internal.h
     3 //  MYNetwork
     4 //
     5 //  Created by Jens Alfke on 5/10/08.
     6 //  Copyright 2008 Jens Alfke. All rights reserved.
     7 //
     8 
     9 #import "BLIPConnection.h"
    10 #import "BLIPRequest.h"
    11 #import "BLIPProperties.h"
    12 @class BLIPWriter;
    13 
    14 
    15 /* Private declarations and APIs for BLIP implementation. Not for use by clients! */
    16 
    17 
    18 /* BLIP message types; encoded in each frame's header. */
    19 typedef enum {
    20     kBLIP_MSG,                      // initiating message
    21     kBLIP_RPY,                      // response to a MSG
    22     kBLIP_ERR                       // error response to a MSG
    23 } BLIPMessageType;
    24 
    25 /* Flag bits in a BLIP frame header */
    26 enum {
    27     kBLIP_TypeMask  = 0x000F,       // bits reserved for storing message type
    28     kBLIP_Compressed= 0x0010,       // data is gzipped
    29     kBLIP_Urgent    = 0x0020,       // please send sooner/faster
    30     kBLIP_NoReply   = 0x0040,       // no RPY needed
    31     kBLIP_MoreComing= 0x0080,       // More frames coming (Applies only to individual frame)
    32     kBLIP_Meta      = 0x0100,       // Special message type, handled internally (hello, bye, ...)
    33 };
    34 typedef UInt16 BLIPMessageFlags;
    35 
    36 
    37 /** Header of a BLIP frame as sent across the wire. All fields are big-endian. */
    38 typedef struct {
    39     UInt32           magic;         // magic number (kBLIPFrameHeaderMagicNumber)
    40     UInt32           number;        // serial number of MSG
    41     BLIPMessageFlags flags;         // encodes frame type, "more" flag, and other delivery options
    42     UInt16           size;          // total size of frame, _including_ this header
    43 } BLIPFrameHeader;
    44 
    45 #define kBLIPFrameHeaderMagicNumber 0x9B34F206
    46 
    47 #define kBLIPProfile_Hi  @"Hi"      // Used for Profile header in meta greeting message
    48 #define kBLIPProfile_Bye @"Bye"     // Used for Profile header in meta close-request message
    49 
    50 
    51 @interface BLIPConnection ()
    52 - (void) _dispatchRequest: (BLIPRequest*)request;
    53 - (void) _dispatchResponse: (BLIPResponse*)response;
    54 @end
    55 
    56 
    57 @interface BLIPMessage ()
    58 @property BOOL sent, propertiesAvailable, complete;
    59 - (BLIPMessageFlags) _flags;
    60 - (void) _setFlag: (BLIPMessageFlags)flag value: (BOOL)value;
    61 - (void) _encode;
    62 @end
    63 
    64 
    65 @interface BLIPMessage ()
    66 - (id) _initWithConnection: (BLIPConnection*)connection
    67                     isMine: (BOOL)isMine
    68                      flags: (BLIPMessageFlags)flags
    69                     number: (UInt32)msgNo
    70                       body: (NSData*)body;
    71 - (BOOL) _writeFrameTo: (BLIPWriter*)writer maxSize: (UInt16)maxSize;
    72 @property (readonly) SInt32 _bytesWritten;
    73 - (void) _assignedNumber: (UInt32)number;
    74 - (BOOL) _receivedFrameWithHeader: (const BLIPFrameHeader*)header body: (NSData*)body;
    75 - (void) _connectionClosed;
    76 @end
    77 
    78 
    79 @interface BLIPRequest ()
    80 - (id) _initWithConnection: (BLIPConnection*)connection
    81                       body: (NSData*)body 
    82                 properties: (NSDictionary*)properties;
    83 @end
    84 
    85 
    86 @interface BLIPResponse ()
    87 - (id) _initWithRequest: (BLIPRequest*)request;
    88 @end