2 * RPC endpoint mapper server
4 * Copyright (C) 2001 Ove Kåven, TransGaming Technologies Inc,
5 * Copyright (C) 2002 Greg Turner
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library 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 GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(ole);
33 struct epmap_entry *next;
34 RPC_SYNTAX_IDENTIFIER iface;
40 static struct epmap_entry *epmap;
42 static const UUID nil_object;
44 static char *mystrdup(const char *str) {
46 rval = LocalAlloc(LPTR, strlen(str)+1);
47 CopyMemory(rval, str, strlen(str)+1);
51 static struct epmap_entry *find_endpoint(const RPC_SYNTAX_IDENTIFIER *iface,
52 const char *protseq, const UUID *object)
54 struct epmap_entry *map;
55 for (map=epmap; map; map=map->next) {
56 if (memcmp(&map->iface, iface, sizeof(RPC_SYNTAX_IDENTIFIER))) continue;
57 if (memcmp(&map->object, object, sizeof(UUID))) continue;
58 if (strcmp(map->protseq, protseq)) continue;
59 WINE_TRACE("found.\n");
62 WINE_TRACE("not found.\n");
66 static void register_endpoint(const RPC_SYNTAX_IDENTIFIER *iface, const char *protseq,
67 const char *endpoint, const UUID *objects, int objcount,
72 WINE_TRACE("(protseq == %s, endpoint == %s, objcount == %i, no_replace == %i)\n",
73 wine_dbgstr_a(protseq), wine_dbgstr_a(endpoint), objcount, no_replace);
76 objects = &nil_object;
80 for (c=0; c<objcount; c++) {
81 struct epmap_entry *map = NULL;
83 map = find_endpoint(iface, protseq, &objects[c]);
85 LocalFree(map->endpoint);
88 map = LocalAlloc(LPTR, sizeof(struct epmap_entry));
89 memcpy(&map->iface, iface, sizeof(RPC_SYNTAX_IDENTIFIER));
90 memcpy(&map->object, &objects[c], sizeof(UUID));
91 map->protseq = mystrdup(protseq);
95 WINE_TRACE(" mapping endpoint (protseq == %s, endpoint == %s, uuid == %s)\n",
96 wine_dbgstr_a(protseq), wine_dbgstr_a(endpoint), wine_dbgstr_guid(&objects[c]));
97 map->endpoint = mystrdup(endpoint);
101 static void unregister_endpoint(const RPC_SYNTAX_IDENTIFIER *iface, const char *protseq,
102 const char *endpoint, const UUID *objects, int objcount)
104 struct epmap_entry *map, *prev, *nprev, *next;
107 WINE_TRACE("(protseq == %s, endpoint == %s, objcount == %i)\n",
108 wine_dbgstr_a(protseq), wine_dbgstr_a(endpoint), objcount);
111 objects = &nil_object;
120 if (memcmp(&map->iface, iface, sizeof(RPC_SYNTAX_IDENTIFIER))) goto cont;
121 for (c=0; c<objcount; c++)
122 if (!memcmp(&map->object, &objects[c], sizeof(UUID))) break;
123 if (c==objcount) goto cont;
124 if (strcmp(map->protseq, protseq)) goto cont;
126 WINE_TRACE(" unmapping: (protseq == %s, endpoint == %s, uuid == %s)\n",
127 wine_dbgstr_a(map->protseq), wine_dbgstr_a(map->endpoint),
128 wine_dbgstr_guid(&map->object));
130 if (prev) prev->next = map->next;
131 else epmap = map->next;
134 LocalFree(map->protseq);
135 LocalFree(map->endpoint);
145 static void resolve_endpoint(const RPC_SYNTAX_IDENTIFIER *iface, const char *protseq,
146 const UUID *object, char *rslt_ep)
149 struct epmap_entry *map;
151 if (!(map = find_endpoint(iface, protseq, object))) return;
153 len = min( MAX_RPCSS_NP_REPLY_STRING_LEN, strlen(map->endpoint)+1 );
154 if (len) memcpy(rslt_ep, map->endpoint, len);
157 static const char *get_string(const char**ptr, const char*end)
159 const char *str = *ptr, *nptr = str;
161 while (nptr < end && *nptr) nptr++;
168 BOOL RPCSS_EpmapEmpty(void)
173 void RPCSS_RegisterRpcEndpoints(RPC_SYNTAX_IDENTIFIER iface, int object_count,
174 int binding_count, int no_replace, char *vardata, long vardata_size)
176 const char *data = vardata;
177 const char *end = data + vardata_size;
178 const UUID *objects = (const UUID *)data;
181 data += object_count * sizeof(UUID);
182 for (c=0; c < binding_count; c++) {
183 const char *protseq = get_string(&data, end);
184 const char *endpoint = get_string(&data, end);
185 if (protseq && endpoint)
186 register_endpoint(&iface, protseq, endpoint, objects, object_count, no_replace);
190 void RPCSS_UnregisterRpcEndpoints(RPC_SYNTAX_IDENTIFIER iface, int object_count,
191 int binding_count, char *vardata, long vardata_size)
193 const char *data = vardata;
194 const char *end = data + vardata_size;
195 const UUID *objects = (const UUID *)data;
198 data += object_count * sizeof(UUID);
199 for (c=0; c < binding_count; c++) {
200 const char *protseq = get_string(&data, end);
201 const char *endpoint = get_string(&data, end);
202 if (protseq && endpoint)
203 unregister_endpoint(&iface, protseq, endpoint, objects, object_count);
207 void RPCSS_ResolveRpcEndpoints(RPC_SYNTAX_IDENTIFIER iface, UUID object, char *protseq, char *rslt_ep)
209 resolve_endpoint(&iface, protseq, &object, rslt_ep);