BLIP/BLIPMessage.h
author Jens Alfke <jens@mooseyard.com>
Sun May 25 12:32:47 2008 -0700 (2008-05-25)
changeset 5 2c4bb6968927
parent 3 76f302097a75
child 16 6f608b552b77
permissions -rw-r--r--
More documentation.
     1 //
     2 //  BLIPMessage.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 <Foundation/Foundation.h>
    10 @class BLIPConnection, BLIPProperties, BLIPMutableProperties;
    11 
    12 
    13 /** NSError domain and codes for BLIP */
    14 extern NSString* const BLIPErrorDomain;
    15 enum {
    16     kBLIPError_BadData = 1,
    17     kBLIPError_BadFrame,
    18     kBLIPError_Disconnected,
    19     kBLIPError_PeerNotAllowed,
    20     
    21     kBLIPError_Misc = 99,
    22     
    23     // errors returned in responses:
    24     kBLIPError_BadRequest = 400,
    25     kBLIPError_Forbidden = 403,
    26     kBLIPError_NotFound = 404,
    27     kBLIPError_BadRange = 416,
    28     
    29     kBLIPError_HandlerFailed = 501,
    30     kBLIPError_Unspecified = 599            // peer didn't send any detailed error info
    31 };
    32 
    33 
    34 /** Abstract superclass for <a href=".#blipdesc">BLIP</a> requests and responses. */
    35 @interface BLIPMessage : NSObject 
    36 {
    37     BLIPConnection *_connection;
    38     UInt16 _flags;
    39     UInt32 _number;
    40     BLIPProperties *_properties;
    41     NSData *_body;
    42     NSMutableData *_encodedBody;
    43     NSMutableData *_mutableBody;
    44     BOOL _isMine, _isMutable, _sent, _propertiesAvailable, _complete;
    45     SInt32 _bytesWritten;
    46 };
    47 
    48 /** The BLIPConnection associated with this message. */
    49 @property (readonly,retain) BLIPConnection *connection;
    50 
    51 /** This message's serial number in its connection.
    52     A BLIPRequest's number is initially zero, then assigned when it's sent.
    53     A BLIPResponse is automatically assigned the same number as the request it replies to. */
    54 @property (readonly) UInt32 number;
    55 
    56 /** Is this a message sent by me (as opposed to the peer)? */
    57 @property (readonly) BOOL isMine;
    58 
    59 /** Has this message been sent yet? (Only makes sense when isMe is set.) */
    60 @property (readonly) BOOL sent;
    61 
    62 /** Has enough of the message arrived to read its properies? */
    63 @property (readonly) BOOL propertiesAvailable;
    64 
    65 /** Has the entire message, including the body, arrived? */
    66 @property (readonly) BOOL complete;
    67 
    68 /** Should the message body be compressed with gzip?
    69     This property can only be set <i>before</i> sending the message. */
    70 @property BOOL compressed;
    71 
    72 /** Should the message be sent ahead of normal-priority messages?
    73     This property can only be set <i>before</i> sending the message. */
    74 @property BOOL urgent;
    75 
    76 /** Can this message be changed? (Only true for outgoing messages, before you send them.) */
    77 @property (readonly) BOOL isMutable;
    78 
    79 /** The message body, a blob of arbitrary data. */
    80 @property (copy) NSData *body;
    81 
    82 /** Appends data to the body. */
    83 - (void) addToBody: (NSData*)data;
    84 
    85 /** The message body as an NSString.
    86     The UTF-8 character encoding is used to convert. */
    87 @property (copy) NSString *bodyString;
    88 
    89 #pragma mark PROPERTIES:
    90 
    91 /** The message's properties, a dictionary-like object.
    92     Message properties are much like the headers in HTTP, MIME and RFC822. */
    93 @property (readonly) BLIPProperties* properties;
    94 
    95 /** Mutable version of the message's properties; only available if this mesage is mutable. */
    96 @property (readonly) BLIPMutableProperties* mutableProperties;
    97 
    98 /** The value of the "Content-Type" property, which is by convention the MIME type of the body. */
    99 @property (copy) NSString *contentType;
   100 
   101 /** The value of the "Profile" property, which by convention identifies the purpose of the message. */
   102 @property (copy) NSString *profile;
   103 
   104 /** A shortcut to get the value of a property. */
   105 - (NSString*) valueOfProperty: (NSString*)property;
   106 
   107 /** A shortcut to set the value of a property. A nil value deletes that property. */
   108 - (void) setValue: (NSString*)value ofProperty: (NSString*)property;
   109 
   110 /** Similar to -description, but also shows the properties and their values. */
   111 @property (readonly) NSString* descriptionWithProperties;
   112 
   113 
   114 @end