bcfc1f1ab4afda2d232269f5abde39777bc81572
[jelmer/samba4-debian.git] / source / 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 #include "librpc/gen_ndr/irpc.h"
23
24 /*
25   an incoming irpc message
26 */
27 struct irpc_message {
28         struct server_id from;
29         void *private;
30         struct irpc_header header;
31         struct ndr_pull *ndr;
32         bool defer_reply;
33         struct messaging_context *msg_ctx;
34         struct irpc_list *irpc;
35         void *data;
36         struct event_context *ev;
37 };
38
39 /* don't allow calls to take too long */
40 #define IRPC_CALL_TIMEOUT 10
41
42
43 /* the server function type */
44 typedef NTSTATUS (*irpc_function_t)(struct irpc_message *, void *r);
45
46 /* register a server function with the irpc messaging system */
47 #define IRPC_REGISTER(msg_ctx, pipename, funcname, function, private) \
48    irpc_register(msg_ctx, &ndr_table_ ## pipename, \
49                           NDR_ ## funcname, \
50                           (irpc_function_t)function, private)
51
52 /* make a irpc call */
53 #define IRPC_CALL(msg_ctx, server_id, pipename, funcname, ptr, ctx) \
54    irpc_call(msg_ctx, server_id, &ndr_table_ ## pipename, NDR_ ## funcname, ptr, ctx)
55
56 #define IRPC_CALL_SEND(msg_ctx, server_id, pipename, funcname, ptr, ctx) \
57    irpc_call_send(msg_ctx, server_id, &ndr_table_ ## pipename, NDR_ ## funcname, ptr, ctx)
58
59
60 /*
61   a pending irpc call
62 */
63 struct irpc_request {
64         struct messaging_context *msg_ctx;
65         const struct ndr_interface_table *table;
66         int callnum;
67         int callid;
68         void *r;
69         NTSTATUS status;
70         bool done;
71         bool reject_free;
72         TALLOC_CTX *mem_ctx;
73         struct {
74                 void (*fn)(struct irpc_request *);
75                 void *private;
76         } async;
77 };
78
79 typedef void (*msg_callback_t)(struct messaging_context *msg, void *private, 
80                                uint32_t msg_type, 
81                                struct server_id server_id, DATA_BLOB *data);
82
83 struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx, 
84                                          struct server_id server_id, 
85                                          struct event_context *ev);
86 NTSTATUS messaging_send(struct messaging_context *msg, struct server_id server, 
87                         uint32_t msg_type, DATA_BLOB *data);
88 NTSTATUS messaging_register(struct messaging_context *msg, void *private,
89                             uint32_t msg_type, 
90                             msg_callback_t fn);
91 NTSTATUS messaging_register_tmp(struct messaging_context *msg, void *private,
92                                 msg_callback_t fn, uint32_t *msg_type);
93 struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx, 
94                                          struct server_id server_id, 
95                                          struct event_context *ev);
96 struct messaging_context *messaging_client_init(TALLOC_CTX *mem_ctx, 
97                                          struct event_context *ev);
98 NTSTATUS messaging_send_ptr(struct messaging_context *msg, struct server_id server, 
99                             uint32_t msg_type, void *ptr);
100 void messaging_deregister(struct messaging_context *msg, uint32_t msg_type, void *private);
101
102
103
104
105 NTSTATUS irpc_register(struct messaging_context *msg_ctx, 
106                        const struct ndr_interface_table *table, 
107                        int call, irpc_function_t fn, void *private);
108 struct irpc_request *irpc_call_send(struct messaging_context *msg_ctx, 
109                                     struct server_id server_id, 
110                                     const struct ndr_interface_table *table, 
111                                     int callnum, void *r, TALLOC_CTX *ctx);
112 NTSTATUS irpc_call_recv(struct irpc_request *irpc);
113 NTSTATUS irpc_call(struct messaging_context *msg_ctx, 
114                    struct server_id server_id, 
115                    const struct ndr_interface_table *table, 
116                    int callnum, void *r, TALLOC_CTX *ctx);
117
118 NTSTATUS irpc_add_name(struct messaging_context *msg_ctx, const char *name);
119 struct server_id *irpc_servers_byname(struct messaging_context *msg_ctx, TALLOC_CTX *mem_ctx, const char *name);
120 void irpc_remove_name(struct messaging_context *msg_ctx, const char *name);
121 NTSTATUS irpc_send_reply(struct irpc_message *m, NTSTATUS status);
122
123