2 Copyright (C) 2000-2003 SKYRIX Software AG
4 This file is part of OGo
6 OGo 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 OGo 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 OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #include "NGNetUtilities.h"
24 #include "NGInternetSocketAddress.h"
25 #include "NGLocalSocketAddress.h"
28 id<NGSocketAddress> NGSocketAddressFromString(NSString *_string) {
29 const unsigned char *cstr = [_string cString];
30 if (cstr == NULL) return nil;
31 if ([_string length] < 1) return nil;
34 const unsigned char *tmp = index(cstr, ':');
36 if (tmp) { // INET socket
37 NSString *hostName = nil;
39 if (((tmp - cstr) == 1) && (*cstr == '*'))
40 hostName = nil; // wildcard host
42 hostName = [NSString stringWithCString:cstr length:(tmp - cstr)];
44 // check what comes after colon
45 if (isdigit(tmp[1])) {
47 int port = atoi(tmp + 1);
48 return [NGInternetSocketAddress addressWithPort:port onHost:hostName];
51 // a service or 'auto' for auto-assigned ports
52 const unsigned char *tmp2 = index((tmp + 1), '/');
53 NSString *protocol = @"tcp";
59 service = [NSString stringWithCString:tmp];
61 service = [NSString stringWithCString:tmp length:(tmp2 - tmp)];
62 protocol = [NSString stringWithCString:(tmp2 + 1)];
65 if ([service isEqualToString:@"auto"])
66 return [NGInternetSocketAddress addressWithPort:0
69 return [NGInternetSocketAddress addressWithService:service
76 if ([_string isAbsolutePath])
77 return [NGLocalSocketAddress addressWithPath:_string];