2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
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
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.
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
22 #include "NGNetUtilities.h"
23 #include "NGInternetSocketAddress.h"
24 #include "NGLocalSocketAddress.h"
27 id<NGSocketAddress> NGSocketAddressFromString(NSString *_string) {
28 const unsigned char *cstr = (unsigned char *)[_string cString];
29 if (cstr == NULL) return nil;
30 if ([_string length] < 1) return nil;
33 const unsigned char *tmp = (unsigned char *)index((char *)cstr, ':');
35 if (tmp) { // INET socket
36 NSString *hostName = nil;
38 if (((tmp - cstr) == 1) && (*cstr == '*'))
39 hostName = nil; // wildcard host
41 hostName = [NSString stringWithCString:(char *)cstr
45 // check what comes after colon
46 if (isdigit(tmp[1])) {
48 int port = atoi((char *)tmp + 1);
49 return [NGInternetSocketAddress addressWithPort:port onHost:hostName];
52 // a service or 'auto' for auto-assigned ports
53 const unsigned char *tmp2;
54 NSString *protocol = @"tcp";
57 tmp2 = (unsigned char *)index((char *)(tmp + 1), '/');
61 service = [NSString stringWithCString:(char *)tmp];
63 service = [NSString stringWithCString:(char *)tmp
65 protocol = [NSString stringWithCString:(char *)(tmp2 + 1)];
68 if ([service isEqualToString:@"auto"])
69 return [NGInternetSocketAddress addressWithPort:0
72 return [NGInternetSocketAddress addressWithService:service
79 if ([_string isAbsolutePath])
80 return [NGLocalSocketAddress addressWithPath:_string];