Merge Samba3 and Samba4 together
[amitay/samba.git] / source4 / lib / messaging / irpc.h
1 /* 
2    Unix SMB/CIFS implementation.
3
4    Samba internal rpc code - header
5
6    Copyright (C) Andrew Tridgell 2005
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 3 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, see <http://www.gnu.org/licenses/>.
20 */
21
22 #ifndef IRPC_H
23 #define IRPC_H
24
25 #include "librpc/gen_ndr/irpc.h"
26
27 /*
28   an incoming irpc message
29 */
30 struct irpc_message {
31         struct server_id from;
32         void *private;
33         struct irpc_header header;
34         struct ndr_pull *ndr;
35         bool defer_reply;
36         struct messaging_context *msg_ctx;
37         struct irpc_list *irpc;
38         void *data;
39         struct event_context *ev;
40 };
41
42 /* don't allow calls to take too long */
43 #define IRPC_CALL_TIMEOUT 10
44
45
46 /* the server function type */
47 typedef NTSTATUS (*irpc_function_t)(struct irpc_message *, void *r);
48
49 /* register a server function with the irpc messaging system */
50 #define IRPC_REGISTER(msg_ctx, pipename, funcname, function, private) \
51    irpc_register(msg_ctx, &ndr_table_ ## pipename, \
52                           NDR_ ## funcname, \
53                           (irpc_function_t)function, private)
54
55 /* make a irpc call */
56 #define IRPC_CALL(msg_ctx, server_id, pipename, funcname, ptr, ctx) \
57    irpc_call(msg_ctx, server_id, &ndr_table_ ## pipename, NDR_ ## funcname, ptr, ctx)
58
59 #define IRPC_CALL_SEND(msg_ctx, server_id, pipename, funcname, ptr, ctx) \
60    irpc_call_send(msg_ctx, server_id, &ndr_table_ ## pipename, NDR_ ## funcname, ptr, ctx)
61
62
63 /*
64   a pending irpc call
65 */
66 struct irpc_request {
67         struct messaging_context *msg_ctx;
68         const struct ndr_interface_table *table;
69         int callnum;
70         int callid;
71         void *r;
72         NTSTATUS status;
73         bool done;
74         bool reject_free;
75         TALLOC_CTX *mem_ctx;
76         struct {
77                 void (*fn)(struct irpc_request *);
78                 void *private;
79         } async;
80 };
81
82 struct loadparm_context;
83
84 typedef void (*msg_callback_t)(struct messaging_context *msg, void *private, 
85                                uint32_t msg_type, 
86                                struct server_id server_id, DATA_BLOB *data);
87
88 NTSTATUS messaging_send(struct messaging_context *msg, struct server_id server, 
89                         uint32_t msg_type, DATA_BLOB *data);
90 NTSTATUS messaging_register(struct messaging_context *msg, void *private,
91                             uint32_t msg_type, 
92                             msg_callback_t fn);
93 NTSTATUS messaging_register_tmp(struct messaging_context *msg, void *private,
94                                 msg_callback_t fn, uint32_t *msg_type);
95 struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx, 
96                                          const char *dir,
97                                          struct server_id server_id, 
98                                          struct smb_iconv_convenience *iconv_convenience,
99                                          struct event_context *ev);
100 struct messaging_context *messaging_client_init(TALLOC_CTX *mem_ctx, 
101                                          const char *dir,
102                                          struct smb_iconv_convenience *iconv_convenience,
103                                          struct event_context *ev);
104 NTSTATUS messaging_send_ptr(struct messaging_context *msg, struct server_id server, 
105                             uint32_t msg_type, void *ptr);
106 void messaging_deregister(struct messaging_context *msg, uint32_t msg_type, void *private);
107
108
109
110
111 NTSTATUS irpc_register(struct messaging_context *msg_ctx, 
112                        const struct ndr_interface_table *table, 
113                        int call, irpc_function_t fn, void *private);
114 struct irpc_request *irpc_call_send(struct messaging_context *msg_ctx, 
115                                     struct server_id server_id, 
116                                     const struct ndr_interface_table *table, 
117                                     int callnum, void *r, TALLOC_CTX *ctx);
118 NTSTATUS irpc_call_recv(struct irpc_request *irpc);
119 NTSTATUS irpc_call(struct messaging_context *msg_ctx, 
120                    struct server_id server_id, 
121                    const struct ndr_interface_table *table, 
122                    int callnum, void *r, TALLOC_CTX *ctx);
123
124 NTSTATUS irpc_add_name(struct messaging_context *msg_ctx, const char *name);
125 struct server_id *irpc_servers_byname(struct messaging_context *msg_ctx, TALLOC_CTX *mem_ctx, const char *name);
126 void irpc_remove_name(struct messaging_context *msg_ctx, const char *name);
127 NTSTATUS irpc_send_reply(struct irpc_message *m, NTSTATUS status);
128 struct server_id messaging_get_server_id(struct messaging_context *msg_ctx);
129
130 #endif
131