File: GSSocksParser.m

package info (click to toggle)
gnustep-base 1.31.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 26,580 kB
  • sloc: objc: 239,446; ansic: 36,519; cpp: 122; sh: 112; makefile: 100; xml: 32
file content (121 lines) | stat: -rw-r--r-- 2,948 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
 * Parsers of SOCKS protocol messages
 * Copyright (C) 2013 Free Software Foundation, Inc.
 *
 * Written by Marat Ibadinov <ibadinov@me.com>
 * Date: 2013
 *
 * This file is part of the GNUstep Base Library.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 31 Milk Street #960789 Boston, MA 02196 USA.
 *
 * $Date$ $Revision$
 */

#import "GSSocksParser.h"
#import "GSSocks4Parser.h"
#import "GSSocks5Parser.h"
#import "Foundation/NSException.h"

@interface NSObject (SubclassResponsibility)
- (id) subclassResponsibility: (SEL)aSelector;
@end

@implementation GSSocksParser

- (id) init
{
  if (nil != (self = [super init]))
    {
      configuration = nil;
      address = nil;
      delegate = nil;
      port = 0;
    }
  return self;
}

- (id) initWithConfiguration: (NSDictionary *)aConfiguration
                     address: (NSString *)anAddress
                        port: (NSUInteger)aPort
{
  NSString *version;
  Class concreteClass;

  version = [aConfiguration objectForKey: NSStreamSOCKSProxyVersionKey];
  version = version ? version : NSStreamSOCKSProxyVersion5;
  
  [self release];
  
  if ([version isEqualToString: NSStreamSOCKSProxyVersion5])
    {
      concreteClass = [GSSocks5Parser class];
    }
  else if ([version isEqualToString: NSStreamSOCKSProxyVersion4])
    {
      concreteClass = [GSSocks4Parser class];
    }
  else
    {
      [NSException raise: NSInternalInconsistencyException
                  format: @"Unsupported socks version: %@", version];
      return nil;       // Avoid spurious compiler warning
    }
  return [[concreteClass alloc] initWithConfiguration: aConfiguration
                                              address: anAddress 
                                                 port: aPort];
}

- (void) dealloc
{
  [delegate release];
  [address release];
  [configuration release];
  [super dealloc];
}

- (id<GSSocksParserDelegate>) delegate
{
  return delegate;
}

- (void) setDelegate: (id<GSSocksParserDelegate>)aDelegate
{
  id previous = delegate;
  delegate = [aDelegate retain];
  [previous release];
}

- (NSString *) address
{
  return address;
}

- (NSUInteger) port
{
  return port;
}

- (void) start
{
  [self subclassResponsibility:_cmd];
}

- (void) parseNextChunk: (NSData *)aChunk
{
  [self subclassResponsibility: _cmd];
}

@end