Allow setting SO_REUSEADDR.
[doldaconnect.git] / daemon / filenet.h
... / ...
CommitLineData
1/*
2 * Dolda Connect - Modular multiuser Direct Connect-style client
3 * Copyright (C) 2004 Fredrik Tolf (fredrik@dolda2000.com)
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/
19#ifndef _FILENET_H
20#define _FILENET_H
21
22#include <wchar.h>
23#include "net.h"
24#include "utils.h"
25#include "search.h"
26
27#define FNN_SYN 0
28#define FNN_HS 1
29#define FNN_EST 2
30#define FNN_DEAD 3
31
32#define FNPD_INT 0
33#define FNPD_LL 1
34#define FNPD_STR 2
35
36struct fnetnode;
37struct fnetpeer;
38
39struct fnet
40{
41 struct fnet *next;
42 wchar_t *name;
43 void (*connect)(struct fnetnode *fn);
44 void (*destroy)(struct fnetnode *fn);
45 int (*setnick)(struct fnetnode *fn, wchar_t *newnick);
46 int (*reqconn)(struct fnetpeer *peer);
47 int (*sendchat)(struct fnetnode *fn, int public, wchar_t *to, wchar_t *string);
48 int (*search)(struct fnetnode *fn, struct search *srch, struct srchfnnlist *ln);
49 wchar_t *(*filebasename)(wchar_t *filename);
50};
51
52struct fnetpeerdatum
53{
54 struct fnetpeerdatum *next, *prev;
55 int refcount;
56 wchar_t *id;
57 int datatype;
58};
59
60struct fnetpeerdi
61{
62 struct fnetpeerdatum *datum;
63 union
64 {
65 int num;
66 long long lnum;
67 wchar_t *str;
68 } data;
69};
70
71struct fnetpeer
72{
73 struct fnetpeer *next, *prev;
74 struct fnetnode *fn;
75 wchar_t *id;
76 wchar_t *nick;
77 union
78 {
79 struct
80 {
81 int delete:1;
82 int op:1;
83 } b;
84 int w;
85 } flags;
86 int dinum;
87 struct fnetpeerdi *peerdi;
88};
89
90struct fnetnode
91{
92 struct fnetnode *next, *prev;
93 int refcount;
94 int id;
95 int state;
96 int linked;
97 time_t srchwait, lastsrch;
98 wchar_t *name;
99 wchar_t *mynick;
100 struct fnet *fnet;
101 struct socket *sk;
102 struct fnetpeerdatum *peerdata;
103 struct fnetpeer *peers;
104 CBCHAIN(fnetnode_ac, struct fnetnode *fn, wchar_t *attrib);
105 CBCHAIN(fnetnode_chat, struct fnetnode *fn, int public, wchar_t *name, wchar_t *peer, wchar_t *string);
106 CBCHAIN(fnetnode_unlink, struct fnetnode *fn);
107 CBCHAIN(fnetnode_destroy, struct fnetnode *fn);
108 int numpeers;
109 void *data;
110};
111
112void regfnet(struct fnet *fnet);
113void fnetsetname(struct fnetnode *fn, wchar_t *newname);
114void fnetsetstate(struct fnetnode *fn, int newstate);
115int fnetsetnick(struct fnetnode *fn, wchar_t *newnick);
116struct fnet *findfnet(wchar_t *name);
117struct fnetnode *fnetinitconnect(wchar_t *name, char *addr);
118void linkfnetnode(struct fnetnode *fn);
119void unlinkfnetnode(struct fnetnode *fn);
120void getfnetnode(struct fnetnode *fn);
121void putfnetnode(struct fnetnode *fn);
122void killfnetnode(struct fnetnode *fn);
123struct fnetpeer *fnetaddpeer(struct fnetnode *fn, wchar_t *id, wchar_t *nick);
124void fnetdelpeer(struct fnetpeer *peer);
125struct fnetpeer *fnetfindpeer(struct fnetnode *fn, wchar_t *id);
126void fnetpeersetstr(struct fnetpeer *peer, wchar_t *id, wchar_t *value);
127void fnetpeersetnum(struct fnetpeer *peer, wchar_t *id, int value);
128void fnetpeersetlnum(struct fnetpeer *peer, wchar_t *id, long long value);
129void fnetpeerunset(struct fnetpeer *peer, wchar_t *id);
130struct fnetnode *findfnetnode(int id);
131void fnethandlechat(struct fnetnode *fn, int public, wchar_t *name, wchar_t *peer, wchar_t *chat);
132int fnetsendchat(struct fnetnode *fn, int public, wchar_t *to, wchar_t *string);
133int fnetsearch(struct fnetnode *fn, struct search *srch, struct srchfnnlist *ln);
134
135extern struct fnetnode *fnetnodes;
136EGCBCHAIN(newfncb, struct fnetnode *);
137
138#endif