r1486: commit the start of the generic server infastructure
[kai/samba.git] / source4 / smbd / service.h
1 /* 
2    Unix SMB/CIFS implementation.
3
4    SERVER SERVICE code
5
6    Copyright (C) Stefan (metze) Metzmacher      2004
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #ifndef _SERVER_SERVICE_H
24 #define _SERVER_SERVICE_H
25
26 struct event_context;
27 struct model_ops;
28 struct server_context;
29
30 struct server_connection;
31 struct server_service;
32
33 /* modules can use the following to determine if the interface has changed
34  * please increment the version number after each interface change
35  * with a comment and maybe update struct process_model_critical_sizes.
36  */
37 /* version 1 - initial version - metze */
38 #define SERVER_SERVICE_VERSION 1
39
40 struct server_service_ops {
41         /* the name of the server_service */
42         const char *name;
43
44         /* called at startup when the server_service is selected */
45         void (*service_init)(struct server_service *service, const struct model_ops *ops);
46
47         /* function to accept new connection */
48         void (*accept_connection)(struct server_connection *);
49
50         /* function to accept new connection */
51         void (*recv_handler)(struct server_connection *, time_t, uint16_t);
52
53         /* function to accept new connection */
54         void (*send_handler)(struct server_connection *, time_t, uint16_t);
55
56         /* function to accept new connection */
57         void (*idle_handler)(struct server_connection *, time_t);
58
59         /* function to close a connection */
60         void (*close_connection)(struct server_connection *, const char *reason);
61
62         /* function to exit server */
63         void (*service_exit)(struct server_service *srv_ctx, const char *reason);       
64 };
65
66 struct socket_ops {
67         int dummy;      
68 };
69
70 struct socket_context {
71         void *private_data;
72         struct socket_ops *ops;
73         const char *client_addr;
74         uint_t pkt_count;
75         struct fd_event *fde;
76 };
77
78 struct server_socket {
79         struct server_socket *next,*prev;
80         TALLOC_CTX *mem_ctx;
81         void *private_data;
82
83         struct {
84                 struct event_context *ctx;
85                 struct fd_event *fde;
86         } event;
87
88         struct socket_context *socket;
89
90         struct server_service *service;
91
92         struct server_connection *connection_list;
93 };
94
95 struct server_service {
96         struct server_service *next,*prev;
97         TALLOC_CTX *mem_ctx;
98         void *private_data;
99         const struct server_service_ops *ops;
100
101         const struct model_ops *model_ops;
102
103         struct server_socket *socket_list;
104
105         struct server_context *srv_ctx;
106 };
107
108 struct server_connection {
109         struct server_connection *next,*prev;
110         TALLOC_CTX *mem_ctx;
111         void *private_data;
112
113         struct {
114                 struct event_context *ctx;
115                 struct fd_event *fde;
116                 struct timed_event *idle;
117                 time_t idle_time;
118         } event;
119
120         struct socket_context *socket;
121
122         struct server_socket *server_socket;
123
124         struct server_service *service;
125 };
126
127 #endif /* _SERVER_SERVICE_H */