/[pkg-mixmaster]/branches/mixmaster_2_9_STABLE/Mix/Src/mix3.h
ViewVC logotype

Contents of /branches/mixmaster_2_9_STABLE/Mix/Src/mix3.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 469 - (hide annotations) (download)
Tue Jan 21 16:11:57 2003 UTC (10 years, 4 months ago) by colintu
File MIME type: text/plain
File size: 13574 byte(s)
cleaned up build and added pcre
1 rabbi 418 /* Mixmaster version 2.9 -- (C) 1999 - 2002 Anonymizer Inc. and others.
2 rabbi 1
3     Mixmaster may be redistributed and modified under certain conditions.
4     This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
5     ANY KIND, either express or implied. See the file COPYRIGHT for
6     details.
7    
8     Function prototypes
9 colintu 469 $Id: mix3.h,v 1.8.2.7 2003/01/21 16:11:55 colintu Exp $ */
10 rabbi 1
11    
12     #ifndef _MIX3_H
13     #define _MIX3_H
14     #define COPYRIGHT "Copyright Anonymizer Inc."
15    
16 colintu 458 #ifdef MIXLIB_EXPORTS
17     #define DllExport __declspec( dllexport )
18     #else
19     #define DllExport
20     #endif
21    
22 rabbi 1 #include "config.h"
23     #include "mix.h"
24    
25     #ifdef WIN32
26     #ifndef USE_SOCK
27     #define _WINSOCKAPI_ /* don't include winsock */
28 weaselp 327 #endif /* not USE_SOCK */
29 rabbi 1 #include <windows.h>
30 rabbi 11 #ifdef _MSC
31     #define snprintf _snprintf
32 weaselp 327 #endif /* _MSC */
33 rabbi 11 #define DIRSEP '\\'
34     #define DIRSEPSTR "\\"
35 weaselp 327 #else /* end of WIN32 */
36 rabbi 11 #define DIRSEP '/'
37     #define DIRSEPSTR "/"
38 weaselp 327 #endif /* else if not WIN32 */
39 rabbi 1
40     #define NOT_IMPLEMENTED {printf("Function not implemented.\n");return -1;}
41     #define SECONDSPERDAY 86400
42    
43     /* Dynamically allocated buffers */
44    
45 colintu 458 DllExport int buf_reset(BUFFER *buffer);
46     DllExport int buf_clear(BUFFER *buffer);
47     DllExport int buf_append(BUFFER *buffer, byte *mess, int len);
48     DllExport int buf_cat(BUFFER *to, BUFFER *from);
49     DllExport int buf_set(BUFFER *to, BUFFER *from);
50     DllExport int buf_rest(BUFFER *to, BUFFER *from);
51     DllExport int buf_appendrnd(BUFFER *to, int n);
52     DllExport int buf_appendzero(BUFFER *to, int n);
53     DllExport int buf_setc(BUFFER *buf, byte c);
54     DllExport int buf_appendc(BUFFER *to, byte b);
55     DllExport int buf_setrnd(BUFFER *b, int n);
56     DllExport int buf_setf(BUFFER *buffer, char *fmt, ...);
57     DllExport int buf_appendf(BUFFER *buffer, char *fmt, ...);
58     DllExport int buf_sets(BUFFER *buf, char *s);
59     DllExport int buf_appends(BUFFER *buffer, char *s);
60     DllExport int buf_nl(BUFFER *buffer);
61     DllExport int buf_pad(BUFFER *buffer, int size);
62     DllExport int buf_prepare(BUFFER *buffer, int size);
63     DllExport int buf_rewind(BUFFER *buffer);
64     DllExport int buf_getc(BUFFER *buffer);
65     DllExport void buf_ungetc(BUFFER *buffer);
66     DllExport int buf_get(BUFFER *buffer, BUFFER *to, int n);
67     DllExport int buf_getline(BUFFER *buffer, BUFFER *line);
68     DllExport int buf_chop(BUFFER *b);
69     DllExport void buf_move(BUFFER *dest, BUFFER *src);
70     DllExport byte *buf_data(BUFFER *buffer);
71     DllExport int buf_isheader(BUFFER *buffer);
72     DllExport int buf_getheader(BUFFER *buffer, BUFFER *field, BUFFER *content);
73     DllExport int buf_appendheader(BUFFER *buffer, BUFFER *field, BUFFER *contents);
74     DllExport int buf_lookahead(BUFFER *buffer, BUFFER *line);
75     DllExport int buf_eq(BUFFER *b1, BUFFER *b2);
76     DllExport int buf_ieq(BUFFER *b1, BUFFER *b2);
77     DllExport void buf_cut_out(BUFFER *buffer, BUFFER *cut_out, BUFFER *rest,
78 rabbi 1 int from, int len);
79    
80 colintu 458 DllExport int buf_appendl(BUFFER *b, long l);
81     DllExport int buf_appendl_lo(BUFFER *b, long l);
82     DllExport long buf_getl(BUFFER *b);
83     DllExport long buf_getl_lo(BUFFER *b);
84     DllExport int buf_appendi(BUFFER *b, int i);
85     DllExport int buf_appendi_lo(BUFFER *b, int i);
86     DllExport int buf_geti(BUFFER *b);
87     DllExport int buf_geti_lo(BUFFER *b);
88 rabbi 1
89     /* String comparison */
90 colintu 458 DllExport int strieq(const char *s1, const char *s2);
91     DllExport int strileft(const char *string, const char *keyword);
92     DllExport int striright(const char *string, const char *keyword);
93     DllExport int strifind(const char *string, const char *keyword);
94    
95     DllExport int streq(const char *s1, const char *s2);
96     DllExport int strfind(const char *string, const char *keyword);
97     DllExport int strleft(const char *string, const char *keyword);
98    
99     DllExport void strcatn(char *dest, const char *src, int n);
100    
101     DllExport int bufleft(BUFFER *b, char *k);
102     DllExport int buffind(BUFFER *b, char *k);
103     DllExport int bufeq(BUFFER *b, char *k);
104    
105     DllExport int bufileft(BUFFER *b, char *k);
106     DllExport int bufifind(BUFFER *b, char *k);
107     DllExport int bufiright(BUFFER *b, char *k);
108     DllExport int bufieq(BUFFER *b, char *k);
109 rabbi 1
110     /* Utility functions */
111     void whoami(char *addr, char *defaultname);
112     int sendinfofile(char *name, char *log, BUFFER *address, BUFFER *subject);
113     int stats(BUFFER *out);
114     int conf(BUFFER *out);
115     void conf_premail(BUFFER *out);
116    
117     void rfc822_addr(BUFFER *line, BUFFER *list);
118     void rfc822_name(BUFFER *line, BUFFER *name);
119     void sendmail_begin(void); /* begin mail sending session */
120     void sendmail_end(void); /* end mail sending session */
121 weaselp 116 int sendmail_loop(BUFFER *message, char *from, BUFFER *address);
122 rabbi 1 int sendmail(BUFFER *message, char *from, BUFFER *address);
123     int mixfile(char *path, const char *name);
124     int file_to_out(const char *name);
125     FILE *mix_openfile(const char *name, const char *a);
126     FILE *openpipe(const char *prog);
127     int closepipe(FILE *fp);
128 weaselp 354 int write_pidfile(char *pidfile);
129     int clear_pidfile(char *pidfile);
130 rabbi 1
131     typedef struct {
132     char *name;
133     FILE *f;
134     } LOCK;
135    
136     int lock(FILE *f);
137     int unlock(FILE *f);
138     LOCK *lockfile(char *filename);
139     int unlockfile(LOCK *lock);
140    
141     int filtermsg(BUFFER *msg);
142     BUFFER *readdestblk( );
143     int doblock(BUFFER *line, BUFFER *filter, int logandreset);
144     int doallow(BUFFER *line, BUFFER *filter);
145     int allowmessage(BUFFER *in);
146    
147 colintu 458 DllExport void errlog(int type, char *format,...);
148 colintu 469 DllExport void clienterr(BUFFER *msgbuf, char *err);
149     DllExport void logmail(char *mailbox, BUFFER *message);
150 rabbi 1
151 colintu 469 DllExport void mix_status(char *fmt,...);
152     DllExport void mix_genericerror(void);
153 rabbi 1
154     #define ERRORMSG 1
155     #define WARNING 2
156     #define NOTICE 3
157     #define LOG 4
158     #define DEBUGINFO 5
159    
160 colintu 469 DllExport int decode(BUFFER *in, BUFFER *out);
161     DllExport int encode(BUFFER *b, int linelen);
162     DllExport void id_encode(byte id[], byte *s);
163     DllExport void id_decode(byte *s, byte id[]);
164 rabbi 1
165     int decode_header(BUFFER *content);
166     int boundary(BUFFER *line, BUFFER *mboundary);
167     void get_parameter(BUFFER *content, char *attribute, BUFFER *value);
168     int get_type(BUFFER *content, BUFFER *type, BUFFER *subtype);
169     int mail_encode(BUFFER *in, int encoding);
170 colintu 469 DllExport int hdr_encode(BUFFER *in, int n);
171 colintu 458 DllExport int attachfile(BUFFER *message, BUFFER *filename);
172 rabbi 1 int pgpmime_sign(BUFFER *message, BUFFER *uid, BUFFER *pass, char *secring);
173     int mime_attach(BUFFER *message, BUFFER *attachment, BUFFER *type);
174     void mimedecode(BUFFER *msg);
175 rabbi 41 int qp_decode_message(BUFFER *msg);
176 rabbi 1
177     #define MIME_8BIT 1 /* transport is 8bit */
178     #define MIME_7BIT 2 /* transport is 7bit */
179    
180     /* randomness */
181 colintu 469 DllExport int rnd_bytes(byte *b, int n);
182     DllExport byte rnd_byte(void);
183     DllExport int rnd_number(int n);
184     DllExport int rnd_add(byte *b, int l);
185     DllExport int rnd_seed(void);
186     DllExport void rnd_time(void);
187    
188     DllExport int rnd_init(void);
189     DllExport int rnd_final(void);
190     DllExport void rnd_error(void);
191 rabbi 1
192     #define RND_QUERY 0
193     #define RND_NOTSEEDED -1
194     #define RND_SEEDED 1
195     #define RND_WILLSEED 2
196     extern int rnd_state; /* flag for PRNG status */
197    
198     /* compression */
199     int buf_compress(BUFFER *b);
200     int buf_zip(BUFFER *out, BUFFER *in, int bits);
201     int buf_uncompress(BUFFER *b);
202     int buf_unzip(BUFFER *b, int type);
203    
204     /* crypto functions */
205     int digest_md5(BUFFER *b, BUFFER *md);
206     int isdigest_md5(BUFFER *b, BUFFER *md);
207     int digestmem_md5(byte *b, int n, BUFFER *md);
208     int digest_sha1(BUFFER *b, BUFFER *md);
209     int digest_rmd160(BUFFER *b, BUFFER *md);
210    
211 colintu 458 DllExport int keymgt(int force);
212 rabbi 1 int key(BUFFER *b);
213     int adminkey(BUFFER *b);
214    
215     #define ENCRYPT 1
216     #define DECRYPT 0
217     int buf_crypt(BUFFER *b, BUFFER *key, BUFFER *iv, int enc);
218    
219     #ifdef USE_IDEA
220     int buf_ideacrypt(BUFFER *b, BUFFER *key, BUFFER *iv, int enc);
221 weaselp 327 #endif /* USE_IDEA */
222 rabbi 1 int buf_bfcrypt(BUFFER *b, BUFFER *key, BUFFER *iv, int enc);
223     int buf_3descrypt(BUFFER *b, BUFFER *key, BUFFER *iv, int enc);
224     int buf_castcrypt(BUFFER *b, BUFFER *key, BUFFER *iv, int enc);
225 rabbi 98 #ifdef USE_AES
226     int buf_aescrypt(BUFFER *b, BUFFER *key, BUFFER *iv, int enc);
227 weaselp 327 #endif /* USE_AES */
228 rabbi 1
229     int db_getseckey(byte keyid[], BUFFER *key);
230     int db_getpubkey(byte keyid[], BUFFER *key);
231     int pk_decrypt(BUFFER *encrypted, BUFFER *privkey);
232     int pk_encrypt(BUFFER *plaintext, BUFFER *privkey);
233     int check_seckey(BUFFER *buf, const byte id[]);
234     int check_pubkey(BUFFER *buf, const byte id[]);
235     int v2createkey(void);
236     int seckeytopub(BUFFER *pub, BUFFER *sec, byte keyid[]);
237    
238     /* configuration, general remailer functions */
239 colintu 458 DllExport int mix_configline(char *line);
240     DllExport int mix_config(void);
241 rabbi 1 int mix_initialized(void);
242     int mix_daily(void);
243    
244     /* message pool */
245     #define INTERMEDIATE 0
246     int pool_send(void);
247     int pool_read(BUFFER *pool);
248 colintu 458 DllExport int pool_add(BUFFER *msg, char *type);
249 rabbi 1 FILE *pool_new(char *type, char *tmpname, char *path);
250     int mix_pool(BUFFER *msg, int type, long latent);
251     int pool_packetfile(char *fname, BUFFER *mid, int packetnum);
252     void pool_packetexp(void);
253     int idexp(void);
254 colintu 458 DllExport void pop3get(void);
255 rabbi 1
256 rabbi 82 typedef struct { /* added for binary id.log change */
257     char id[16];
258     long time;
259     } idlog_t;
260    
261 rabbi 1 /* statistics */
262     int stats_log(int);
263     int stats_out(int);
264    
265     /* OpenPGP */
266 rabbi 306 #define PGP_ARMOR_NORMAL 0
267     #define PGP_ARMOR_REM 1
268     #define PGP_ARMOR_KEY 2
269     #define PGP_ARMOR_NYMKEY 3
270     #define PGP_ARMOR_NYMSIG 4
271     #define PGP_ARMOR_SECKEY 5
272    
273 rabbi 1 int pgp_keymgt(int force);
274     int pgp_armor(BUFFER *buf, int mode);
275     int pgp_dearmor(BUFFER *buf, BUFFER *out);
276     int pgp_pubkeycert(BUFFER *userid, char *keyring, BUFFER *pass,
277     BUFFER *out, int remail);
278     int pgp_signtxt(BUFFER *msg, BUFFER *uid, BUFFER *pass,
279     char *secring, int remail);
280     int pgp_isconventional(BUFFER *buf);
281 colintu 458 DllExport int pgp_mailenc(int mode, BUFFER *msg, char *sigid,
282 rabbi 1 BUFFER *pass, char *pubring, char *secring);
283     int pgp_signhashalgo(BUFFER *algo, BUFFER *userid, char *secring,
284     BUFFER *pass);
285    
286     /* menu */
287 colintu 458 DllExport int menu_initialized;
288     DllExport void menu_main(void);
289     DllExport void menu_folder(char command, char *name);
290     DllExport int menu_getuserpass(BUFFER *p, int mode);
291    
292     DllExport int user_pass(BUFFER *b);
293     DllExport int user_confirmpass(BUFFER *b);
294     DllExport void user_delpass(void);
295 rabbi 1
296     /* remailer */
297     typedef struct {
298     char name[20];
299     int version;
300     char addr[128];
301     byte keyid[16];
302     struct {
303     unsigned int mix:1;
304     unsigned int compress:1;
305    
306     unsigned int cpunk:1;
307     unsigned int pgp:1;
308     unsigned int pgponly:1;
309     unsigned int latent:1;
310     unsigned int hash:1;
311     unsigned int ek:1;
312     unsigned int esub:1;
313    
314     unsigned int nym:1;
315     unsigned int newnym:1;
316    
317     unsigned int post:1;
318     unsigned int middle:1;
319     } flags;
320     struct rinfo {
321     int reliability;
322     int latency;
323     char history[13];
324     } info[2];
325     } REMAILER;
326    
327     #define CHAINMAX 421
328     #define MAXREM 100
329 colintu 458 DllExport int prepare_type2list(BUFFER *out);
330 rabbi 1 int mix2_rlist(REMAILER remailer[]);
331     int t1_rlist(REMAILER remailer[]);
332     int pgp_rlist(REMAILER remailer[], int n);
333 rabbi 306 int pgp_rkeylist(REMAILER remailer[], int keyid[], int n);
334 rabbi 1 int chain_select(int hop[], char *chainstr, int maxrem, REMAILER *remailer,
335     int type, BUFFER *feedback);
336     int chain_rand(REMAILER *remailer, int maxrem,
337     int thischain[], int chainlen, int t);
338     int chain_randfinal(int type, REMAILER *remailer, int maxrem, int t);
339    
340     float chain_reliability(char *chain, int chaintype,
341     char *reliability_string);
342     int mix2_encrypt(int type, BUFFER *message, char *chainstr, int numcopies,
343     BUFFER *feedback);
344     int t1_encrypt(int type, BUFFER *message, char *chainstr, int latency,
345     BUFFER *ek, BUFFER *feedback);
346    
347     int t1_getreply(BUFFER *msg, BUFFER *ek, int len);
348    
349     int t1_decrypt(BUFFER *in);
350     int t2_decrypt(BUFFER *in);
351    
352     int mix2_decrypt(BUFFER *m);
353     int mix3_decrypt(BUFFER *m);
354    
355     /* type 2 */
356     #define MAGIC0 0
357     #define MAGIC1 3
358    
359     int v3_magic(byte *b);
360     int v2body(BUFFER *body);
361     int v2body_setlen(BUFFER *body);
362     int v2partial(BUFFER *body, BUFFER *mid, int packet, int numpackets);
363     int v2_merge(BUFFER *mid);
364     int mix_armor(BUFFER *in);
365     int mix_dearmor(BUFFER *armored, BUFFER *bin);
366    
367     /* type 1 */
368     #define HDRMARK "::"
369     #define EKMARK "**"
370     #define HASHMARK "##"
371     int isline(BUFFER *line, char *text);
372    
373     /* nym database */
374    
375     #define NYM_WAITING 0
376     #define NYM_OK 1
377     #define NYM_DELETED 2
378     #define NYM_ANY -1
379    
380     int nymlist_read(BUFFER *n);
381     int nymlist_write(BUFFER *list);
382     int nymlist_get(BUFFER *list, char *nym, BUFFER *config, BUFFER *ek,
383     BUFFER *options, BUFFER *name, BUFFER *rblocks, int *status);
384     int nymlist_append(BUFFER *list, char *nym, BUFFER *config, BUFFER *options,
385     BUFFER *name, BUFFER *chains, BUFFER *eklist, int status);
386     int nymlist_del(BUFFER *list, char *nym);
387     int nymlist_getnym(char *nym, BUFFER *config, BUFFER *ek, BUFFER *opt,
388     BUFFER *name, BUFFER *rblocks);
389     int nymlist_getstatus(char *nym);
390    
391     /* Visual C lacks dirent */
392     #ifdef _MSC
393     typedef HANDLE DIR;
394    
395     struct dirent {
396     char d_name[PATHMAX];
397     };
398    
399     DIR *opendir(const char *name);
400     struct dirent *readdir(DIR *dir);
401     int closedir(DIR *dir);
402 weaselp 327 #endif /* _MSC */
403 rabbi 1
404     /* sockets */
405     #if defined(WIN32) && defined(USE_SOCK)
406     #include <winsock.h>
407     int sock_init(void);
408     void sock_exit(void);
409    
410 weaselp 327 #else /* end of defined(WIN32) && defined(USE_SOCK) */
411 rabbi 1 typedef int SOCKET;
412    
413     #define INVALID_SOCKET -1
414     SOCKET opensocket(char *hostname, int port);
415     int closesocket(SOCKET s);
416    
417 weaselp 327 #endif /* else if not defined(WIN32) && defined(USE_SOCK) */
418 rabbi 1
419 rabbi 30 #ifdef WIN32
420 colintu 458 DllExport int is_nt_service(void);
421     DllExport void set_nt_exit_event();
422 weaselp 327 #endif /* WIN32 */
423 rabbi 30
424 rabbi 1 /* check for memory leaks */
425     #ifdef DEBUG
426     #define malloc mix3_malloc
427     #define free mix3_free
428     BUFFER *mix3_bufnew(char *, int, char*);
429     #if __GNUC__ >= 2
430     # define buf_new() mix3_bufnew(__FILE__, __LINE__, __PRETTY_FUNCTION__)
431 weaselp 327 #else /* end of __GNUC__ >= 2 */
432 rabbi 1 # define buf_new() mix3_bufnew(__FILE__, __LINE__, "file")
433 weaselp 327 #endif /* else if not __GNUC__ >= 2 */
434 rabbi 1 #endif /* DEBUG */
435    
436 weaselp 327 #endif /* not _MIX3_H */

  ViewVC Help
Powered by ViewVC 1.1.5