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