aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objc/provider/MCONetService.mm
blob: 6f1ce53ad2df72796a2a0a98273794342e369610 (plain)
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
//
//  MCONetService.m
//  mailcore2
//
//  Created by Robert Widmann on 4/28/13.
//  Copyright (c) 2013 MailCore. All rights reserved.
//

#import "MCONetService.h"
#include "MCNetService.h"

#import "NSDictionary+MCO.h"
#import "NSString+MCO.h"
#import "NSObject+MCO.h"

@implementation MCONetService {
    mailcore::NetService *_netService;
}

#define nativeType mailcore::NetService

+ (void) load
{
    MCORegisterClass( self, &typeid(nativeType) );
}

- (mailcore::Object *) mco_mcObject
{
    return _netService;
}

+ (NSObject *) mco_objectWithMCObject:(mailcore::Object *)object
{
    mailcore::NetService *netService = (mailcore::NetService *)object;
    return [[[self alloc] initWithNetService:netService] autorelease];
}

+ (MCONetService *) serviceWithInfo:(NSDictionary *)info
{
    return [[[self alloc] initWithInfo:info] autorelease];
}

- (instancetype) initWithInfo:(NSDictionary *)info
{
    self = [super init];
    
    _netService = mailcore::NetService::serviceWithInfo(info.mco_mcHashMap);
    _netService->retain();
    
    return self;
}

- (instancetype) initWithNetService:(mailcore::NetService *)netService
{
    self = [super init];
    
    _netService = netService;
    _netService->retain();
    
    return self;
}

- (id) copyWithZone:(NSZone *)zone
{
    nativeType * nativeObject = (nativeType *) [self mco_mcObject]->copy();
    id result = [[self class] mco_objectWithMCObject:nativeObject];
    MC_SAFE_RELEASE(nativeObject);
    return [result retain];
}

MCO_OBJC_SYNTHESIZE_STRING(setHostname, hostname)
MCO_OBJC_SYNTHESIZE_SCALAR(unsigned int, unsigned int, setPort, port)
MCO_OBJC_SYNTHESIZE_SCALAR(MCOConnectionType, mailcore::ConnectionType, setConnectionType, connectionType)

- (NSDictionary *) info
{
    return [NSDictionary mco_dictionaryWithMCHashMap:_netService->info()];
}

- (NSString *) hostnameWithEmail:(NSString *)email
{
    return [NSString mco_stringWithMCString:_netService->normalizedHostnameWithEmail(email.mco_mcString)];
}

@end