Advertisement
Guest User

Untitled

a guest
Jun 11th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  ETAStream.h
  3. //  ETAClient-iPhoneOS
  4. //
  5. //  Created by Daniel Reed on 8/17/10.
  6. //  Copyright 2010 N/a. All rights reserved.
  7. //
  8. #import <CoreLocation/CoreLocation.h>
  9. #import <Foundation/Foundation.h>
  10.  
  11. #import "Blowfish.h"
  12. #import "Packet.h"
  13. #import "PacketQueue.h"
  14. #import "Event.h"
  15.  
  16. #define NUMBER_OF_KEYS 4
  17. #define KEY_SIZE 4
  18. #define MAX_STATES 64
  19.  
  20. #define LOGIN_SERVER @"svn.bce-inc.com"
  21. #define LOGIN_PORT 48355
  22. #define ETAStreamErrorDomain @"ETAStreamErrorDomain"
  23.  
  24. @class ETAStream;
  25.  
  26. typedef enum
  27. {
  28.   ResponseCodeInvalid,
  29.   ResponseCodeAccepted,
  30.   ResponseCodeDeclined,
  31.   ResponseCodeBanned,
  32.   ResponseCodeInvalidAccount,
  33.   ResponseCodeServersOffline
  34. } ResponseCode;
  35.  
  36. typedef enum
  37. {
  38.   kStreamStateInvalid,
  39.   kStreamStateWaitForSessionKeys,
  40.   kStreamStateConnectToLoginServer,
  41.   kStreamStateLoggingIn,
  42.   kStreamStateWaitingForLoginResponse,
  43.   kStreamStateConnectToClientServer,
  44.   kStreamStatePerformingHandshake,
  45.   kStreamStateWaitingForHandshakeResponse,
  46.   kStreamStateReady,
  47.   kStreamStateLoginFailed,
  48.   kStreamStateHandshakeFailed
  49. } StreamState;
  50.  
  51. /**
  52.  *
  53.  */
  54. @protocol ETAStreamDelegate
  55. -(void) streamIsConnecting: (ETAStream*) stream;
  56.  
  57. -(void) streamDidConnect: (ETAStream*) stream;
  58.  
  59. -(void) streamDidDisconnect: (ETAStream*) stream;
  60.  
  61. -(void) stream: (ETAStream*) stream willFailWithError: (NSError*) error;
  62.  
  63. -(void) stream: (ETAStream*) stream didSpawnEvent: (Event*) event;
  64.  
  65. -(void) stream: (ETAStream*) stream didUpdateEvent: (Event*) event;
  66.  
  67. -(void) stream: (ETAStream*) stream didDestroyEvent: (Event*) event;
  68.  
  69. -(void) stream: (ETAStream*) stream didReceivePacket: (Packet*) packet;
  70.  
  71. -(void) streamDidUpdate: (ETAStream*) stream;
  72.  
  73. /**
  74.  * Notifies the delegate that it should display an alert for the
  75.  * indicated event.
  76.  *
  77.  * @param stream
  78.  * The source stream.
  79.  *
  80.  * @param event
  81.  * Indicates the event for which the alert should be fired.
  82.  */
  83. -(void) stream: (ETAStream*) stream shouldDisplayAlertForEvent: (Event*) event;
  84. @end
  85.  
  86. @interface ETAStream : NSObject <NSStreamDelegate>
  87. {
  88.   NSString* key;
  89.   NSString* server;
  90.   int port;
  91.   NSString* username;
  92.   NSString* password;
  93.   CLLocationCoordinate2D coordinate;
  94.   NSInputStream* inputStream;
  95.   NSOutputStream* outputStream;
  96.   Blowfish* blowfish;
  97.   NSMutableData* buffer;
  98.   PacketQueue* incomingPackets;
  99.   PacketQueue* outgoingPackets;
  100.   id <ETAStreamDelegate> delegate;
  101.   NSMutableDictionary* eventDictionary;
  102.  
  103.   StreamState streamState;
  104.  
  105.   // Indicates the timestamp of the last request (Handshake, Login, etc).
  106.   NSDate* lastRequest;
  107.  
  108.   //! Stream state stack index.
  109.   int stackIndex;
  110.  
  111.   //! Stream states stack.
  112.   StreamState states[MAX_STATES];
  113. }
  114.  
  115. /**
  116.  * Gets the username used for authenticating with the login server.
  117.  */
  118. -(NSString*) username;
  119.  
  120. /**
  121.  * Sets the username used for authenticating with the login server.
  122.  *
  123.  * @param newUsername
  124.  * Indicates the new username value.
  125.  */
  126. -(void) setUsername: (NSString*) newUsername;
  127.  
  128. /**
  129.  * Gets the password used for authenticating with the login server.
  130.  *
  131.  * @return
  132.  * MD5 hash representing the actual password.
  133.  */
  134. -(NSString*) password;
  135.  
  136. /**
  137.  * Sets the password used for authenticating with the login server.
  138.  * The value will be stored as an MD5 hash.
  139.  *
  140.  * @param newPassword
  141.  * Indicates the new password value.
  142.  */
  143. -(void) setPassword: (NSString*) newPassword;
  144.  
  145. /**
  146.  *
  147.  */
  148. -(id <ETAStreamDelegate>) delegate;
  149. -(void) setDelegate: (id <ETAStreamDelegate>) newDelegate;
  150. -(StreamState) streamState;
  151. -(void) setStreamState: (StreamState) newStreamState;
  152. -(CLLocationCoordinate2D) coordinate;
  153. -(void) setCoordinate: (CLLocationCoordinate2D) newCoordinate;
  154. -(double) latitude;
  155. -(double) longitude;
  156.  
  157. -(StreamState) currentState;
  158. -(void) pushState: (StreamState) state;
  159. -(StreamState) popState;
  160.  
  161. -(void) connectToHost: (NSString*) host port: (int) port;
  162.  
  163. -(void) disconnect;
  164.  
  165. -(void) enqueuePacket: (Packet*) packet;
  166.  
  167. -(void) sendPacket: (Packet*) packet;
  168.  
  169. -(void) update;
  170. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement