s4: COM: Remove talloc_autofree_context() from (unused) COM code.
[sfrench/samba-autobuild/.git] / source4 / lib / com / dcom / tables.c
1 /*
2    Unix SMB/CIFS implementation.
3    DCOM proxy tables functionality
4    Copyright (C) 2005 Jelmer Vernooij <jelmer@samba.org>
5    Copyright (C) 2006 Andrzej Hajda <andrzej.hajda@wp.pl>
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "includes.h"
23 #include "../lib/util/dlinklist.h"
24 #include "librpc/gen_ndr/com_dcom.h"
25 #include "lib/com/dcom/dcom.h"
26
27 static struct dcom_proxy {
28         struct IUnknown_vtable *vtable;
29         struct dcom_proxy *prev, *next;
30 }  *proxies = NULL;
31
32 NTSTATUS dcom_register_proxy(TALLOC_CTX *ctx,
33                 struct IUnknown_vtable *proxy_vtable)
34 {
35         struct dcom_proxy *proxy = talloc(ctx, struct dcom_proxy);
36
37         proxy->vtable = proxy_vtable;
38         DLIST_ADD(proxies, proxy);
39
40         return NT_STATUS_OK;
41 }
42
43 struct IUnknown_vtable *dcom_proxy_vtable_by_iid(struct GUID *iid)
44 {
45         struct dcom_proxy *p;
46         for (p = proxies; p; p = p->next) {
47                 if (GUID_equal(&p->vtable->iid, iid)) {
48                         return p->vtable;
49                 }
50         }
51         return NULL;
52 }
53
54 static struct dcom_marshal {
55         struct GUID clsid;
56         marshal_fn marshal;
57         unmarshal_fn unmarshal;
58         struct dcom_marshal *prev, *next;
59 }  *marshals = NULL;
60
61 NTSTATUS dcom_register_marshal(TALLOC_CTX *ctx,
62                 struct GUID *clsid, marshal_fn marshal, unmarshal_fn unmarshal)
63 {
64         struct dcom_marshal *p = talloc(ctx, struct dcom_marshal);
65
66         p->clsid = *clsid;
67         p->marshal = marshal;
68         p->unmarshal = unmarshal;
69         DLIST_ADD(marshals, p);
70         return NT_STATUS_OK;
71 }
72
73 _PUBLIC_ marshal_fn dcom_marshal_by_clsid(struct GUID *clsid)
74 {
75         struct dcom_marshal *p;
76         for (p = marshals; p; p = p->next) {
77                 if (GUID_equal(&p->clsid, clsid)) {
78                         return p->marshal;
79                 }
80         }
81         return NULL;
82 }
83
84 _PUBLIC_ unmarshal_fn dcom_unmarshal_by_clsid(struct GUID *clsid)
85 {
86         struct dcom_marshal *p;
87         for (p = marshals; p; p = p->next) {
88                 if (GUID_equal(&p->clsid, clsid)) {
89                         return p->unmarshal;
90                 }
91         }
92         return NULL;
93 }
94