1 /* 2 copyright 2001-2002 Alexander Malmberg <alexander@malmberg.org> 3 */ 4 5 #ifndef NNTPServer_h 6 #define NNTPServer_h 7 8 #include <netinet/in.h> 9 10 11 @class NSObject; 12 @class NSRunLoop; 13 @class NSString; 14 15 16 @protocol NNTPServer_Receiver 17 -(void) nntp_serverDate: (const char *)date qid: (unsigned int)qid; 18 19 /* if num=-1 the group didn't exist */ 20 -(void) nntp_groupInfo: (int)group : (int)num : (int)first : (int)last qid: (unsigned int)qid; 21 22 23 /* 24 order is: 25 'xref-number Subject Author Date Message-ID References bytes lines' 26 and maybe other optional headers '(header-name: data)*' 27 tabs between headers 28 29 This might be called several times for a single qid if the request is 30 large. Every call except the last call will have partial==YES 31 */ 32 /* TODO: parse and return in nicer form? */ 33 -(void) nntp_headerRange: (int)group : (int)first : (int)last : (int)num : 34 (char **)list partial: (BOOL)p qid: (unsigned int)qid; 35 36 -(void) nntp_headerId: (const char *)mid data: (const unsigned char *)data : 37 (int)length qid: (unsigned int)qid; 38 39 40 -(void) nntp_articleRange: (int)group : (int)num 41 data: (const unsigned char *)data : (int)length qid: (unsigned int)qid; 42 43 -(void) nntp_articleId: (const char *)mid data: (const unsigned char *)data : 44 (int)length qid: (unsigned int)qid; 45 46 /* name last first may-post */ 47 -(void) nntp_groupList: (const unsigned char *)data : (int)length 48 qid: (unsigned int)qid; 49 50 51 /* NO if the article was not accepted by the server (malformed message, 52 cancelled request, etc.). */ 53 -(void) nntp_postArticle: (BOOL)success qid: (unsigned int)qid; 54 55 56 -(void) nntp_fail: (NSString *)reason qid: (unsigned int)qid; 57 58 /* 59 Called if we can't open any connection at all to the server. should_connect 60 will be set to 0 before this call, so you'll have to explictly set it to 1 61 if you want to try connecting again. 62 */ 63 -(void) nntp_fail_connect: (NSString *)reason; 64 -(void) nntp_message: (NSString *)msg; 65 66 -(void) nntp_progress: (int)bytes : (unsigned int)qid; 67 @end 68 69 70 @interface NNTPServer : NSObject 71 { 72 struct nntp_connection_s *cons; 73 int num_cons; 74 int num_idle,num_active,num_starting; 75 76 struct nntp_queue_s *queue; 77 78 int should_connect; 79 80 char *host; 81 int have_addr; 82 struct sockaddr_in addr; 83 int port; 84 int protocol; 85 86 NSRunLoop *runloop; 87 NSArray *runmodes; 88 89 id<NNTPServer_Receiver,NSObject> rec; 90 91 NSString *last_error; 92 93 NSTimeInterval last_connect_attempt,lca_delta; 94 95 int set_timeout; 96 } 97 98 +(int) getGroupNum: (const char *)group; 99 +(const char *) getGroupName: (int)group; 100 101 102 -init; 103 -initWithHost: (const char *)host; 104 -initWithHost: (const char *)host port: (int)port; 105 -initWithAddr: (struct sockaddr_in *)addr port: (int)port 106 host: (const char *)host; 107 108 -(void) enableConnect: (int)should_connect; 109 -(void) enableTimeout: (int)should_connect; 110 111 -(void) setReceiver: (id<NNTPServer_Receiver>)arec; 112 113 -(void) closeAllConnections; 114 -(void) killAllConnections; 115 116 117 -(NSString *)qidDescription: (unsigned int)qid; 118 119 120 /* -10000 < priority < 10000 121 default is 0, use lower for background bulk transfers/read-ahead, higher 122 for 'interactive' stuff (like the article the user just clicked on) 123 */ 124 125 -(unsigned int) getServerDate; 126 127 -(unsigned int) getGroupList: (int)priority; 128 //-(unsigned int) getGroupListSince: (const char *)date; 129 130 -(unsigned int) getGroupInfo: (int)group; 131 132 -(unsigned int) getHeaderRange: (int)low : (int)high group: (int)group 133 priority: (int)pri; 134 -(unsigned int) getHeaderById: (const char *)msg_id priority: (int)pri; 135 136 -(unsigned int) getArticleRange: (int)low : (int)high group: (int)group 137 priority: (int)pri; 138 -(unsigned int) getArticleById: (const char *)msg_id priority: (int)priority; 139 -(unsigned int) getArticleById: (const char *)msg_id size: (int)bytes 140 priority: (int)pri; 141 142 /* a copy is made of the data, so the caller does not have to keep it 143 around */ 144 -(unsigned int) postArticle: (unsigned char *)data length: (int)length 145 priority: (int)priority; 146 147 /* If kill is YES, try _really_ hard to cancel (ie. if the request is 148 already in progress on a connection, kill the connection; this is not 149 nice on the server, so use only when really necessary). */ 150 -(BOOL) cancelQid: (unsigned int)qid kill: (BOOL)kill; 151 152 @end 153 154 #endif 155 156