File: NNTPServer.h

package info (click to toggle)
lusernet.app 0.4.2-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 544 kB
  • ctags: 92
  • sloc: objc: 8,335; sh: 992; makefile: 62
file content (155 lines) | stat: -rw-r--r-- 4,140 bytes parent folder | download | duplicates (5)
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
copyright 2001-2002 Alexander Malmberg <alexander@malmberg.org>
*/

#ifndef NNTPServer_h
#define NNTPServer_h

#include <netinet/in.h>


@class NSObject;
@class NSRunLoop;
@class NSString;


@protocol NNTPServer_Receiver
-(void) nntp_serverDate: (const char *)date qid: (unsigned int)qid;

/* if num=-1 the group didn't exist */
-(void) nntp_groupInfo: (int)group : (int)num : (int)first : (int)last qid: (unsigned int)qid;


/*
order is:
'xref-number Subject Author Date Message-ID References bytes lines'
and maybe other optional headers '(header-name: data)*'
tabs between headers

This might be called several times for a single qid if the request is
large. Every call except the last call will have partial==YES
*/
/* TODO: parse and return in nicer form? */
-(void) nntp_headerRange: (int)group : (int)first : (int)last : (int)num :
	(char **)list partial: (BOOL)p qid: (unsigned int)qid;

-(void) nntp_headerId: (const char *)mid  data: (const unsigned char *)data :
	(int)length  qid: (unsigned int)qid;


-(void) nntp_articleRange: (int)group : (int)num
	data: (const unsigned char *)data : (int)length  qid: (unsigned int)qid;

-(void) nntp_articleId: (const char *)mid  data: (const unsigned char *)data :
	(int)length  qid: (unsigned int)qid;

/* name last first may-post */
-(void) nntp_groupList: (const unsigned char *)data : (int)length
	qid: (unsigned int)qid;


/* NO if the article was not accepted by the server (malformed message,
cancelled request, etc.). */
-(void) nntp_postArticle: (BOOL)success  qid: (unsigned int)qid;


-(void) nntp_fail: (NSString *)reason qid: (unsigned int)qid;

/*
Called if we can't open any connection at all to the server. should_connect
will be set to 0 before this call, so you'll have to explictly set it to 1
if you want to try connecting again.
*/
-(void) nntp_fail_connect: (NSString *)reason;
-(void) nntp_message: (NSString *)msg;

-(void) nntp_progress: (int)bytes : (unsigned int)qid;
@end


@interface NNTPServer : NSObject
{
	struct nntp_connection_s *cons;
	int num_cons;
	int num_idle,num_active,num_starting;

	struct nntp_queue_s *queue;

	int should_connect;

	char *host;
	int have_addr;
	struct sockaddr_in addr;
	int port;
	int protocol;

	NSRunLoop *runloop;
	NSArray *runmodes;

	id<NNTPServer_Receiver,NSObject> rec;

	NSString *last_error;

	NSTimeInterval last_connect_attempt,lca_delta;

	int set_timeout;
}

+(int) getGroupNum: (const char *)group;
+(const char *) getGroupName: (int)group;


-init;
-initWithHost: (const char *)host;
-initWithHost: (const char *)host port: (int)port;
-initWithAddr: (struct sockaddr_in *)addr  port: (int)port
	host: (const char *)host;

-(void) enableConnect: (int)should_connect;
-(void) enableTimeout: (int)should_connect;

-(void) setReceiver: (id<NNTPServer_Receiver>)arec;

-(void) closeAllConnections;
-(void) killAllConnections;


-(NSString *)qidDescription: (unsigned int)qid;


/* -10000 < priority < 10000
default is 0, use lower for background bulk transfers/read-ahead, higher
for 'interactive' stuff (like the article the user just clicked on)
*/

-(unsigned int) getServerDate;

-(unsigned int) getGroupList: (int)priority;
//-(unsigned int) getGroupListSince: (const char *)date;

-(unsigned int) getGroupInfo: (int)group;

-(unsigned int) getHeaderRange: (int)low : (int)high  group: (int)group
	priority: (int)pri;
-(unsigned int) getHeaderById: (const char *)msg_id  priority: (int)pri;

-(unsigned int) getArticleRange: (int)low : (int)high  group: (int)group
	priority: (int)pri;
-(unsigned int) getArticleById: (const char *)msg_id  priority: (int)priority;
-(unsigned int) getArticleById: (const char *)msg_id  size: (int)bytes
	priority: (int)pri;

/* a copy is made of the data, so the caller does not have to keep it
around */
-(unsigned int) postArticle: (unsigned char *)data  length: (int)length
	priority: (int)priority;

/* If kill is YES, try _really_ hard to cancel (ie. if the request is
already in progress on a connection, kill the connection; this is not
nice on the server, so use only when really necessary). */
-(BOOL) cancelQid: (unsigned int)qid  kill: (BOOL)kill;

@end

#endif