]> err.no Git - sope/blob - sope-core/NGStreams/NGInternetSocketDomain.m
Drop apache 1 build-dependency
[sope] / sope-core / NGStreams / NGInternetSocketDomain.m
1 /*
2   Copyright (C) 2000-2005 SKYRIX Software AG
3
4   This file is part of SOPE.
5
6   SOPE is free software; you can redistribute it and/or modify it under
7   the terms of the GNU Lesser General Public License as published by the
8   Free Software Foundation; either version 2, or (at your option) any
9   later version.
10
11   SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
12   WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14   License for more details.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with SOPE; see the file COPYING.  If not, write to the
18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19   02111-1307, USA.
20 */
21
22 #include "NGInternetSocketDomain.h"
23 #include "NGInternetSocketAddress.h"
24 #include "common.h"
25
26 #ifndef __MINGW32__
27 #  include <netinet/in.h>
28 #endif
29
30 @implementation NGInternetSocketDomain
31
32 static NGInternetSocketDomain *domain = nil;
33
34 + (int)version {
35   return 1;
36 }
37 + (void)initialize {
38   if (domain == nil) domain = [[NGInternetSocketDomain alloc] init];
39 }
40 + (id)domain {
41   return domain;
42 }
43
44 /* NGSocketDomain */
45
46 - (id<NGSocketAddress>)addressWithRepresentation:(void *)_data
47   size:(unsigned int)_size
48 {
49   NGInternetSocketAddress *address = nil;
50   
51   if ((unsigned int)[self addressRepresentationSize] != _size) {
52     NSLog(@"%@: invalid address size %i ..", NSStringFromSelector(_cmd), _size);
53     return nil;
54   }
55   
56   address = [[NGInternetSocketAddress allocWithZone:[self zone]]
57                                       initWithDomain:self
58                                       internalRepresentation:_data
59                                       size:_size];
60   return [address autorelease];
61 }
62
63 - (BOOL)prepareAddress:(id<NGSocketAddress>)_address
64   forBindWithSocket:(id<NGSocket>)_socket
65 {
66   // nothing to prepare
67   return YES;
68 }
69 - (BOOL)cleanupAddress:(id<NGSocketAddress>)_address
70   afterCloseOfSocket:(id<NGSocket>)_socket
71 {
72   // nothing to cleanup
73   return YES;
74 }
75
76 - (int)socketDomain {
77   return AF_INET;
78 }
79
80 - (int)addressRepresentationSize {
81   return sizeof(struct sockaddr_in);
82 }
83
84 - (int)protocol {
85   return 0;
86 }
87
88 /* NSCopying */
89
90 - (id)copyWithZone:(NSZone *)_zone {
91   /* domain objects are immutable, just retain on copy */
92   return [self retain];
93 }
94
95 /* NSCoding */
96
97 - (void)encodeWithCoder:(NSCoder *)_encoder {
98 }
99 - (id)initWithCoder:(NSCoder *)_decoder {
100   [self release]; self = nil;
101   return [domain retain];
102 }
103
104 - (id)awakeAfterUsingCoder:(NSCoder *)_decoder {
105   if (self != domain) {
106     [self release]; self = nil;
107     return [domain retain];
108   }
109   else
110     return self;
111 }
112
113 /* description */
114
115 - (NSString *)description {
116   return [NSString stringWithFormat:@"<InternetDomain[0x%p]>", self];
117 }
118
119 @end /* NGInternetSocketDomain */