summaryrefslogtreecommitdiff
path: root/source4/lib/socket/socket.h
blob: 7a8d3359627ddc763e7374aa21ee85683f45b0f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* 
   Unix SMB/CIFS implementation.
   Socket functions
   Copyright (C) Stefan Metzmacher 2004
   
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#ifndef _SAMBA_SOCKET_H
#define _SAMBA_SOCKET_H

struct socket_context;

enum socket_type {
	SOCKET_TYPE_STREAM
};

struct socket_ops {
	const char *name;
	enum socket_type type;

	NTSTATUS (*fn_init)(struct socket_context *sock);

	/* client ops */
	NTSTATUS (*fn_connect)(struct socket_context *sock,
				const char *my_address, int my_port,
				const char *server_address, int server_port,
				uint32_t flags);

	/* server ops */
	NTSTATUS (*fn_listen)(struct socket_context *sock,
				const char *my_address, int port, int queue_size, uint32_t flags);
	NTSTATUS (*fn_accept)(struct socket_context *sock,	struct socket_context **new_sock);

	/* general ops */
	NTSTATUS (*fn_recv)(struct socket_context *sock, void *buf,
			 size_t wantlen, size_t *nread, uint32_t flags);
	NTSTATUS (*fn_send)(struct socket_context *sock, 
			 const DATA_BLOB *blob, size_t *sendlen, uint32_t flags);

	void (*fn_close)(struct socket_context *sock);

	NTSTATUS (*fn_set_option)(struct socket_context *sock, const char *option, const char *val);

	char *(*fn_get_peer_name)(struct socket_context *sock, TALLOC_CTX *mem_ctx);
	char *(*fn_get_peer_addr)(struct socket_context *sock, TALLOC_CTX *mem_ctx);
	int (*fn_get_peer_port)(struct socket_context *sock);
	char *(*fn_get_my_addr)(struct socket_context *sock, TALLOC_CTX *mem_ctx);
	int (*fn_get_my_port)(struct socket_context *sock);

	int (*fn_get_fd)(struct socket_context *sock);
};

enum socket_state {
	SOCKET_STATE_UNDEFINED,

	SOCKET_STATE_CLIENT_START,
	SOCKET_STATE_CLIENT_CONNECTED,
	SOCKET_STATE_CLIENT_STARTTLS,
	SOCKET_STATE_CLIENT_ERROR,
	
	SOCKET_STATE_SERVER_LISTEN,
	SOCKET_STATE_SERVER_CONNECTED,
	SOCKET_STATE_SERVER_STARTTLS,
	SOCKET_STATE_SERVER_ERROR
};

#define SOCKET_FLAG_BLOCK        0x00000001
#define SOCKET_FLAG_PEEK         0x00000002
#define SOCKET_FLAG_TESTNONBLOCK 0x00000004

struct socket_context {
	enum socket_type type;
	enum socket_state state;
	uint32_t flags;

	int fd;

	void *private_data;
	const struct socket_ops *ops;
};

#endif /* _SAMBA_SOCKET_H */