summaryrefslogtreecommitdiff
path: root/source4/lib/messaging/irpc.h
blob: 88f142ee1eb7a367b2fb03d7beb7ec3ecb15c76a (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/* 
   Unix SMB/CIFS implementation.

   Samba internal rpc code - header

   Copyright (C) Andrew Tridgell 2005
   
   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 3 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, see <http://www.gnu.org/licenses/>.
*/

#ifndef IRPC_H
#define IRPC_H

#include "lib/messaging/messaging.h"
#include "librpc/gen_ndr/irpc.h"
#include "librpc/gen_ndr/server_id.h"

/*
  an incoming irpc message
*/
struct irpc_message {
	struct server_id from;
	void *private_data;
	struct irpc_header header;
	struct ndr_pull *ndr;
	bool defer_reply;
	struct messaging_context *msg_ctx;
	struct irpc_list *irpc;
	void *data;
	struct tevent_context *ev;
};

/* don't allow calls to take too long */
#define IRPC_CALL_TIMEOUT 10


/* the server function type */
typedef NTSTATUS (*irpc_function_t)(struct irpc_message *, void *r);

/* register a server function with the irpc messaging system */
#define IRPC_REGISTER(msg_ctx, pipename, funcname, function, private_data) \
   irpc_register(msg_ctx, &ndr_table_ ## pipename, \
                          NDR_ ## funcname, \
			  (irpc_function_t)function, private_data)

/* make a irpc call */
#define IRPC_CALL(msg_ctx, server_id, pipename, funcname, ptr, ctx) \
   irpc_call(msg_ctx, server_id, &ndr_table_ ## pipename, NDR_ ## funcname, ptr, ctx)

#define IRPC_CALL_SEND(msg_ctx, server_id, pipename, funcname, ptr, ctx) \
   irpc_call_send(msg_ctx, server_id, &ndr_table_ ## pipename, NDR_ ## funcname, ptr, ctx)


/*
  a pending irpc call
*/
struct irpc_request {
	struct messaging_context *msg_ctx;
	const struct ndr_interface_table *table;
	int callnum;
	int callid;
	void *r;
	NTSTATUS status;
	bool done;
	bool reject_free;
	TALLOC_CTX *mem_ctx;
	struct {
		void (*fn)(struct irpc_request *);
		void *private_data;
	} async;
	struct {
		void (*handler)(struct irpc_request *irpc, struct irpc_message *m);
		void *private_data;
	} incoming;
};

NTSTATUS irpc_register(struct messaging_context *msg_ctx, 
		       const struct ndr_interface_table *table, 
		       int call, irpc_function_t fn, void *private_data);
struct irpc_request *irpc_call_send(struct messaging_context *msg_ctx, 
				    struct server_id server_id, 
				    const struct ndr_interface_table *table, 
				    int callnum, void *r, TALLOC_CTX *ctx);
NTSTATUS irpc_call_recv(struct irpc_request *irpc);
NTSTATUS irpc_call(struct messaging_context *msg_ctx, 
		   struct server_id server_id, 
		   const struct ndr_interface_table *table, 
		   int callnum, void *r, TALLOC_CTX *ctx);

struct dcerpc_binding_handle *irpc_binding_handle(TALLOC_CTX *mem_ctx,
					struct messaging_context *msg_ctx,
					struct server_id server_id,
					const struct ndr_interface_table *table);
struct dcerpc_binding_handle *irpc_binding_handle_by_name(TALLOC_CTX *mem_ctx,
					struct messaging_context *msg_ctx,
					const char *dest_task,
					const struct ndr_interface_table *table);

NTSTATUS irpc_add_name(struct messaging_context *msg_ctx, const char *name);
struct server_id *irpc_servers_byname(struct messaging_context *msg_ctx, TALLOC_CTX *mem_ctx, const char *name);
void irpc_remove_name(struct messaging_context *msg_ctx, const char *name);
NTSTATUS irpc_send_reply(struct irpc_message *m, NTSTATUS status);

#endif