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