Fixed HTTP-client query-string handling bug.
[doldaconnect.git] / daemon / net.h
CommitLineData
d3372da9 1/*
2 * Dolda Connect - Modular multiuser Direct Connect-style client
302a2600 3 * Copyright (C) 2004 Fredrik Tolf <fredrik@dolda2000.com>
d3372da9 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 _NET_H
20#define _NET_H
21
22#include <sys/socket.h>
9e5f2b29 23#include <sys/un.h>
d3372da9 24
2b9a1911
FT
25#define SOCK_SYN 0 /* Connecting */
26#define SOCK_EST 1 /* Established */
27#define SOCK_STL 2 /* Stale, dead */
e6252feb 28#define SOCK_TOS_MINDELAY 4
29#define SOCK_TOS_MAXTP 3
30#define SOCK_TOS_MAXREL 2
31#define SOCK_TOS_MINCOST 1
d3372da9 32
33struct dgrambuf
34{
35 struct dgrambuf *next;
36 struct sockaddr *addr;
37 socklen_t addrlen;
38 void *data;
39 size_t size;
40};
41
42struct socket
43{
d3372da9 44 int refcount;
d3372da9 45 int state;
2b9a1911 46 int dgram;
02a705ad 47 int eos;
81286a22 48 size_t maxbuf;
f96d0914 49 struct socket *back, *pnext;
d3372da9 50 union
51 {
52 struct
53 {
54 struct dgrambuf *f, *l;
55 } d;
56 struct
57 {
58 void *buf;
59 size_t bufsize;
60 size_t datasize;
61 } s;
2b9a1911 62 } buf;
d3372da9 63 void (*conncb)(struct socket *sk, int err, void *data);
64 void (*errcb)(struct socket *sk, int err, void *data);
65 void (*readcb)(struct socket *sk, void *data);
66 void (*writecb)(struct socket *sk, void *data);
2b9a1911
FT
67 struct ufd *ufd;
68 void *data;
b2e73d7b
FT
69 char *dbgnm;
70 int dbglvl;
2b9a1911
FT
71};
72
73struct lport {
74 struct ufd *ufd;
75 void (*acceptcb)(struct lport *lp, struct socket *newsk, void *data);
76 void (*errcb)(struct lport *lp, int err, void *data);
d3372da9 77 void *data;
78};
79
80void putsock(struct socket *sk);
81void getsock(struct socket *sk);
1ce5968e 82struct socket *netsockpipe(void);
02a705ad
FT
83struct lport *netcslisten(int type, struct sockaddr *name, socklen_t namelen, void (*func)(struct lport *, struct socket *, void *), void *data);
84struct lport *netcslistenlocal(int type, struct sockaddr *name, socklen_t namelen, void (*func)(struct lport *, struct socket *, void *), void *data);
85struct lport *netcstcplisten(int port, int local, void (*func)(struct lport *, struct socket *, void *), void *data);
cab0b442 86struct socket *netcsconn(struct sockaddr *addr, socklen_t addrlen, void (*func)(struct socket *, int, void *), void *data);
d3372da9 87int pollsocks(int timeout);
02a705ad 88void freedgbuf(struct dgrambuf *dg);
d3372da9 89void sockqueue(struct socket *sk, void *data, size_t size);
40c21c4f 90void sockerror(struct socket *sk, int en);
81286a22 91/* size_t sockqueuesize(struct socket *sk); */
1ff9e8ea 92size_t socktqueuesize(struct socket *sk);
81286a22 93ssize_t sockqueueleft(struct socket *sk);
d3372da9 94int netresolve(char *addr, void (*callback)(struct sockaddr *addr, int addrlen, void *data), void *data);
95struct socket *netcsdgram(struct sockaddr *name, socklen_t namelen);
2b9a1911 96struct socket *netdgramconn(struct socket *sk, struct sockaddr *addr, socklen_t addrlen);
d3372da9 97int sockgetremotename(struct socket *sk, struct sockaddr **namebuf, socklen_t *lenbuf);
a88a5873 98int sockgetremotename2(struct socket *sk, struct socket *sk2, struct sockaddr **namebuf, socklen_t *lenbuf);
f96d0914
FT
99int lstgetremotename(struct lport *lp, struct sockaddr **namebuf, socklen_t *lenbuf);
100int lstgetremotename2(struct lport *lp, struct socket *sk, struct sockaddr **namebuf, socklen_t *lenbuf);
d3372da9 101void closesock(struct socket *sk);
2b9a1911 102void closelport(struct lport *lp);
d3372da9 103void *sockgetinbuf(struct socket *sk, size_t *size);
104struct socket *wrapsock(int fd);
105size_t sockgetdatalen(struct socket *sk);
d3372da9 106int socksettos(struct socket *sk, int tos);
99a28d47 107int addreq(struct sockaddr *x, struct sockaddr *y);
d3372da9 108char *formataddress(struct sockaddr *arg, socklen_t arglen);
2b9a1911 109char *formatsockpeer(struct socket *sk);
336539c2 110void sockpushdata(struct socket *sk, void *buf, size_t size);
81286a22 111/* void sockblock(struct socket *sk, int block); */
2b9a1911
FT
112int sockpeeraddr(struct socket *sk, struct sockaddr **namebuf, socklen_t *lenbuf);
113int getucred(struct socket *sk, uid_t *uid, gid_t *gid);
114int sockfamily(struct socket *sk);
1ff9e8ea 115void quitsock(struct socket *sk);
b2e73d7b 116void socksetdebug(struct socket *sk, int level, char *nm, ...);
284e199a 117void sockread(struct socket *sk);
d3372da9 118
119#endif