1 /*
2 * binkleyforce -- unix FTN mailer project
3 *
4 * Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * $Id: prot_binkp_api.c,v 1.1.1.1 2004/09/09 09:52:38 kstepanenkov Exp $
12 */
13
14 #include "includes.h"
15 #include "confread.h"
16 #include "version.h"
17 #include "logger.h"
18 #include "util.h"
19 #include "nodelist.h"
20 #include "session.h"
21 #include "prot_binkp.h"
22
23 void binkp_init(s_handshake_protocol *THIS);
24 void binkp_deinit(s_handshake_protocol *THIS);
25 int binkp_incoming2(s_handshake_protocol *THIS);
26 int binkp_outgoing2(s_handshake_protocol *THIS);
27 s_faddr *binkp_remote_address(s_handshake_protocol *THIS);
28 char *binkp_remote_password(s_handshake_protocol *THIS);
29 char *binkp_remote_sysop_name(s_handshake_protocol *THIS);
30 char *binkp_remote_system_name(s_handshake_protocol *THIS);
31 char *binkp_remote_location(s_handshake_protocol *THIS);
32 char *binkp_remote_phone(s_handshake_protocol *THIS);
33 char *binkp_remote_flags(s_handshake_protocol *THIS);
34 char *binkp_remote_mailer(s_handshake_protocol *THIS);
35 s_faddr *binkp_local_address(s_handshake_protocol *THIS);
36 char *binkp_local_password(s_handshake_protocol *THIS);
37
38 s_handshake_protocol handshake_protocol_binkp = {
39 /* Section 1 */
40 "BinkP",
41 "",
42 "",
43 NULL,
44 NULL,
45 0,
46 binkp_init,
47 binkp_deinit,
48 binkp_incoming2,
49 binkp_outgoing2,
50 /* Section 2 */
51 binkp_remote_address,
52 binkp_remote_password,
53 binkp_remote_sysop_name,
54 binkp_remote_system_name,
55 binkp_remote_location,
56 binkp_remote_phone,
57 binkp_remote_flags,
58 binkp_remote_mailer,
59 NULL,
60 /* Section 3 */
61 binkp_local_address,
62 binkp_local_password
63 };
64
binkp_init(s_handshake_protocol * THIS)65 void binkp_init(s_handshake_protocol *THIS)
66 {
67 ASSERT(THIS);
68 ASSERT(THIS->remote_data == NULL);
69 ASSERT(THIS->local_data == NULL);
70
71 THIS->remote_data = (char *)xmalloc(sizeof(s_binkp_sysinfo));
72 THIS->local_data = (char *)xmalloc(sizeof(s_binkp_sysinfo));
73 THIS->protocol = PROT_BINKP;
74
75 memset(THIS->remote_data, '\0', sizeof(s_binkp_sysinfo));
76 memset(THIS->local_data, '\0', sizeof(s_binkp_sysinfo));
77 }
78
binkp_deinit(s_handshake_protocol * THIS)79 void binkp_deinit(s_handshake_protocol *THIS)
80 {
81 ASSERT(THIS);
82 ASSERT(THIS->remote_data);
83 ASSERT(THIS->local_data);
84
85 if( THIS->remote_data )
86 {
87 memset(THIS->remote_data, '\0', sizeof(s_binkp_sysinfo));
88 free(THIS->remote_data);
89 }
90
91 if( THIS->local_data )
92 {
93 memset(THIS->local_data, '\0', sizeof(s_binkp_sysinfo));
94 free(THIS->local_data);
95 }
96 }
97
binkp_incoming2(s_handshake_protocol * THIS)98 int binkp_incoming2(s_handshake_protocol *THIS)
99 {
100 int rc = -1;
101 s_binkp_sysinfo *remote_data = NULL;
102 s_binkp_sysinfo *local_data = NULL;
103
104 ASSERT(THIS);
105 ASSERT(THIS->remote_data);
106 ASSERT(THIS->local_data);
107
108 remote_data = (s_binkp_sysinfo *)THIS->remote_data;
109 local_data = (s_binkp_sysinfo *)THIS->local_data;
110
111 binkp_set_sysinfo(local_data, NULL, FALSE);
112
113 rc = binkp_incoming(local_data, remote_data);
114
115 binkp_log_sysinfo(remote_data);
116 if( remote_data->anum > 0 )
117 {
118 session_remote_lookup(remote_data->addrs, remote_data->anum);
119 session_remote_log_status();
120 }
121
122 if( rc == HRC_OK )
123 {
124 /*
125 * Create mail/files queue
126 */
127 session_create_files_queue(remote_data->addrs,
128 remote_data->anum);
129 session_set_send_options();
130 session_set_inbound();
131 }
132
133 return rc;
134 }
135
binkp_outgoing2(s_handshake_protocol * THIS)136 int binkp_outgoing2(s_handshake_protocol *THIS)
137 {
138 int rc = HRC_OTHER_ERR;
139 s_binkp_sysinfo *remote_data = NULL;
140 s_binkp_sysinfo *local_data = NULL;
141
142 ASSERT(THIS);
143 ASSERT(THIS->remote_data);
144 ASSERT(THIS->local_data);
145
146 remote_data = (s_binkp_sysinfo *)THIS->remote_data;
147 local_data = (s_binkp_sysinfo *)THIS->local_data;
148
149 binkp_set_sysinfo(local_data, &state.node.addr, TRUE);
150
151 rc = binkp_outgoing(local_data, remote_data);
152
153 binkp_log_sysinfo(remote_data);
154 if( remote_data->anum > 0 )
155 {
156 session_remote_lookup(remote_data->addrs, remote_data->anum);
157 session_remote_log_status();
158 }
159
160 if( rc == HRC_OK )
161 {
162 /*
163 * Create mail/files queue
164 */
165 session_create_files_queue(remote_data->addrs,
166 remote_data->anum);
167 session_set_send_options();
168 session_set_inbound();
169 }
170
171 return rc;
172 }
173
binkp_remote_address(s_handshake_protocol * THIS)174 s_faddr *binkp_remote_address(s_handshake_protocol *THIS)
175 {
176 ASSERT(THIS);
177 ASSERT(THIS->remote_data);
178
179 if( ((s_binkp_sysinfo *)THIS->remote_data)->anum > 0 )
180 return &((s_binkp_sysinfo *)THIS->remote_data)->addrs[0].addr;
181
182 return NULL;
183 }
184
binkp_remote_password(s_handshake_protocol * THIS)185 char *binkp_remote_password(s_handshake_protocol *THIS)
186 {
187 ASSERT(THIS);
188 ASSERT(THIS->remote_data);
189
190 if( ((s_binkp_sysinfo *)THIS->remote_data)->passwd[0] )
191 return ((s_binkp_sysinfo *)THIS->remote_data)->passwd;
192
193 return NULL;
194 }
195
binkp_remote_sysop_name(s_handshake_protocol * THIS)196 char *binkp_remote_sysop_name(s_handshake_protocol *THIS)
197 {
198 ASSERT(THIS);
199 ASSERT(THIS->remote_data);
200
201 if( ((s_binkp_sysinfo *)THIS->remote_data)->sysop[0] )
202 return ((s_binkp_sysinfo *)THIS->remote_data)->sysop;
203
204 return NULL;
205 }
206
binkp_remote_system_name(s_handshake_protocol * THIS)207 char *binkp_remote_system_name(s_handshake_protocol *THIS)
208 {
209 ASSERT(THIS);
210 ASSERT(THIS->remote_data);
211
212 if( ((s_binkp_sysinfo *)THIS->remote_data)->systname[0] )
213 return ((s_binkp_sysinfo *)THIS->remote_data)->systname;
214
215 return NULL;
216 }
217
binkp_remote_location(s_handshake_protocol * THIS)218 char *binkp_remote_location(s_handshake_protocol *THIS)
219 {
220 ASSERT(THIS);
221 ASSERT(THIS->remote_data);
222
223 if( ((s_binkp_sysinfo *)THIS->remote_data)->location[0] )
224 return ((s_binkp_sysinfo *)THIS->remote_data)->location;
225
226 return NULL;
227 }
228
binkp_remote_phone(s_handshake_protocol * THIS)229 char *binkp_remote_phone(s_handshake_protocol *THIS)
230 {
231 ASSERT(THIS);
232 ASSERT(THIS->remote_data);
233
234 if( ((s_binkp_sysinfo *)THIS->remote_data)->phone[0] )
235 return ((s_binkp_sysinfo *)THIS->remote_data)->phone;
236
237 return NULL;
238 }
239
binkp_remote_flags(s_handshake_protocol * THIS)240 char *binkp_remote_flags(s_handshake_protocol *THIS)
241 {
242 ASSERT(THIS);
243 ASSERT(THIS->remote_data);
244
245 if( ((s_binkp_sysinfo *)THIS->remote_data)->flags[0] )
246 return ((s_binkp_sysinfo *)THIS->remote_data)->flags;
247
248 return NULL;
249 }
250
binkp_remote_mailer(s_handshake_protocol * THIS)251 char *binkp_remote_mailer(s_handshake_protocol *THIS)
252 {
253 ASSERT(THIS);
254 ASSERT(THIS->remote_data);
255
256 if( ((s_binkp_sysinfo *)THIS->remote_data)->progname[0] )
257 return ((s_binkp_sysinfo *)THIS->remote_data)->progname;
258
259 return NULL;
260 }
261
binkp_local_address(s_handshake_protocol * THIS)262 s_faddr *binkp_local_address(s_handshake_protocol *THIS)
263 {
264 ASSERT(THIS);
265 ASSERT(THIS->local_data);
266
267 if( ((s_binkp_sysinfo *)THIS->local_data)->anum > 0 )
268 return &((s_binkp_sysinfo *)THIS->local_data)->addrs[0].addr;
269
270 return NULL;
271 }
272
binkp_local_password(s_handshake_protocol * THIS)273 char *binkp_local_password(s_handshake_protocol *THIS)
274 {
275 ASSERT(THIS);
276 ASSERT(THIS->local_data);
277
278 if( ((s_binkp_sysinfo *)THIS->local_data)->passwd[0] )
279 return ((s_binkp_sysinfo *)THIS->local_data)->passwd;
280
281 return NULL;
282 }
283
284