aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objc/nntp/MCONNTPSession.h
blob: 89795087ec6473a28d55c71552d13a7baa8c3e41 (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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//
//  MCONNTPSession.h
//  mailcore2
//
//  Created by Robert Widmann on 8/13/14.
//  Copyright (c) 2014 MailCore. All rights reserved.
//

#import <Foundation/Foundation.h>

#ifndef MAILCORE_MCONNTPSESSION_H

#define MAILCORE_MCONNTPSESSION_H

#import <Foundation/Foundation.h>

#import <MailCore/MCOConstants.h>

@class MCONNTPFetchArticlesOperation;
@class MCONNTPFetchHeaderOperation;
@class MCONNTPFetchArticleOperation;
@class MCONNTPListNewsgroupsOperation;
@class MCONNTPOperation;

/** This class implements asynchronous access to the NNTP protocol.*/

@interface MCONNTPSession : NSObject

/** This is the hostname of the NNTP server to connect to.*/
@property (nonatomic, copy) NSString * hostname;

/** This is the port of the NNTP server to connect to.*/
@property (nonatomic, assign) unsigned int port;

/** This is the username of the account.*/
@property (nonatomic, copy) NSString * username;

/** This is the password of the account.*/
@property (nonatomic, copy) NSString * password;

/** This is the encryption type to use.
 See MCOConnectionType for more information.*/
@property (nonatomic, assign) MCOConnectionType connectionType;

/** This is the timeout of the connection.*/
@property (nonatomic, assign) NSTimeInterval timeout;

/** When set to YES, the connection will fail if the certificate is incorrect.*/
@property (nonatomic, assign, getter=isCheckCertificateEnabled) BOOL checkCertificateEnabled;

/**
 Sets logger callback. The network traffic will be sent to this block.
 
 [session setConnectionLogger:^(void * connectionID, MCOConnectionLogType type, NSData * data) {
 ...
 }];
 */
@property (nonatomic, copy) MCOConnectionLogger connectionLogger;

/** This property provides some hints to MCONNTPSession about where it's called from.
 It will make MCONNTPSession safe. It will also set all the callbacks of operations to run on this given queue.
 Defaults to the main queue.
 This property should be used only if there's performance issue using MCONNTPSession in the main thread. */
@property (nonatomic, assign) dispatch_queue_t dispatchQueue;

/** @name Operations */

/**
 Returns an operation that will fetch the list of messages.
 
 MCONNTPFetchArticlesOperation * op = [session fetchMessagesOperation];
 [op start:^(NSError * error, NSArray * messages) {
 // messages is an array of MCONNTPArticleInfo
 // [info index] can be used as reference for a given message in the other operations.
 }];
 */
- (MCONNTPFetchArticlesOperation *) fetchArticlesOperation:(NSString *)group;

/**
 Returns an operation that will fetch the header of the given message.
 
 MCONNTPFetchHeaderOperation * op = [session fetchHeaderOperationWithIndex:idx inGroup:@"Group"];
 [op start:^(NSError * error, MCOMessageHeader * header) {
 // header is the parsed header of the message.
 }];
 */
- (MCONNTPFetchHeaderOperation *) fetchHeaderOperationWithIndex:(unsigned int)index inGroup:(NSString *)group;

/**
 Returns an operation that will fetch the content of the given message.
 
 MCONNTPFetchArticleOperation * op = [session fetchMessageOperationWithIndex:idx inGroup:@"Group"];
 [op start:^(NSError * error, NSData * messageData) {
 // messageData is the RFC 822 formatted message data.
 }];
 */
- (MCONNTPFetchArticleOperation *) fetchArticleOperationWithIndex:(unsigned int)index inGroup:(NSString *)group;

/**
 Returns an operation that will list all available newsgroups.
 
 MCONNTPListNewsgroupsOperation * op = [session listAllNewsgroupsOperation];
 [op start:^(NSError * error, NSArray * subscribedGroups) {
 }];
 */
- (MCONNTPListNewsgroupsOperation *) listAllNewsgroupsOperation;

/**
 Returns an operation that will list all newsgroups subscribed to by the user.
 
 MCONNTPListNewsgroupsOperation * op = [session listSubscribedNewsgroupsOperation];
 [op start:^(NSError * error, NSArray * subscribedGroups) {
 }];
 */
- (MCONNTPListNewsgroupsOperation *) listSubscribedNewsgroupsOperation;

/**
 Returns an operation that will disconnect the session.
 
 MCONNTPOperation * op = [session disconnectOperation];
 [op start:^(NSError * error) {
 ...
 }];
 */
- (MCONNTPOperation *) disconnectOperation;

/**
 Returns an operation that will check whether the NNTP account is valid.
 
 MCONNTPOperation * op = [session checkAccountOperation];
 [op start:^(NSError * error) {
 ...
 }];
 */
- (MCONNTPOperation *) checkAccountOperation;

@end

#endif