epmp.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /*
  2. * Endpoint Mapper
  3. *
  4. * Copyright (C) 2007 Robert Shearman for CodeWeavers
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  19. */
  20. #include "epm.h"
  21. #include "wine/debug.h"
  22. #include "wine/list.h"
  23. WINE_DEFAULT_DEBUG_CHANNEL(ole);
  24. struct registered_ept_entry
  25. {
  26. struct list entry;
  27. GUID object;
  28. RPC_SYNTAX_IDENTIFIER iface;
  29. RPC_SYNTAX_IDENTIFIER syntax;
  30. char *protseq;
  31. char *endpoint;
  32. char *address;
  33. char annotation[ept_max_annotation_size];
  34. };
  35. static struct list registered_ept_entry_list = LIST_INIT(registered_ept_entry_list);
  36. static CRITICAL_SECTION csEpm;
  37. static CRITICAL_SECTION_DEBUG critsect_debug =
  38. {
  39. 0, 0, &csEpm,
  40. { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
  41. 0, 0, { (DWORD_PTR)(__FILE__ ": csEpm") }
  42. };
  43. static CRITICAL_SECTION csEpm = { &critsect_debug, -1, 0, 0, 0, 0 };
  44. static const UUID nil_object;
  45. /* must be called inside csEpm */
  46. static void delete_registered_ept_entry(struct registered_ept_entry *entry)
  47. {
  48. I_RpcFree(entry->protseq);
  49. I_RpcFree(entry->endpoint);
  50. I_RpcFree(entry->address);
  51. list_remove(&entry->entry);
  52. HeapFree(GetProcessHeap(), 0, entry);
  53. }
  54. static struct registered_ept_entry *find_ept_entry(
  55. const RPC_SYNTAX_IDENTIFIER *iface, const RPC_SYNTAX_IDENTIFIER *syntax,
  56. const char *protseq, const char *endpoint, const char *address,
  57. const UUID *object)
  58. {
  59. struct registered_ept_entry *entry;
  60. LIST_FOR_EACH_ENTRY(entry, &registered_ept_entry_list, struct registered_ept_entry, entry)
  61. {
  62. if (memcmp(&entry->iface, iface, sizeof(RPC_SYNTAX_IDENTIFIER))) continue;
  63. if (memcmp(&entry->syntax, syntax, sizeof(RPC_SYNTAX_IDENTIFIER))) continue;
  64. if (strcmp(entry->protseq, protseq)) continue;
  65. if (memcmp(&entry->object, object, sizeof(UUID))) continue;
  66. WINE_TRACE("found entry with iface %d.%d %s, syntax %d.%d %s, protseq %s, object %s\n",
  67. entry->iface.SyntaxVersion.MajorVersion, entry->iface.SyntaxVersion.MinorVersion,
  68. wine_dbgstr_guid(&entry->iface.SyntaxGUID),
  69. entry->syntax.SyntaxVersion.MajorVersion, entry->syntax.SyntaxVersion.MinorVersion,
  70. wine_dbgstr_guid(&entry->syntax.SyntaxGUID), protseq,
  71. wine_dbgstr_guid(&entry->object));
  72. return entry;
  73. }
  74. WINE_TRACE("not found\n");
  75. return NULL;
  76. }
  77. void __RPC_USER ept_lookup_handle_t_rundown(ept_lookup_handle_t entry_handle)
  78. {
  79. WINE_FIXME("%p\n", entry_handle);
  80. }
  81. void __cdecl ept_insert(handle_t h,
  82. unsigned32 num_ents,
  83. ept_entry_t entries[],
  84. boolean32 replace,
  85. error_status_t *status)
  86. {
  87. unsigned32 i;
  88. RPC_STATUS rpc_status;
  89. WINE_TRACE("(%p, %lu, %p, %lu, %p)\n", h, num_ents, entries, replace, status);
  90. *status = RPC_S_OK;
  91. EnterCriticalSection(&csEpm);
  92. for (i = 0; i < num_ents; i++)
  93. {
  94. struct registered_ept_entry *entry = HeapAlloc(GetProcessHeap(), 0, sizeof(*entry));
  95. if (!entry)
  96. {
  97. /* FIXME: cleanup code to delete added entries */
  98. *status = EPT_S_CANT_PERFORM_OP;
  99. break;
  100. }
  101. memcpy(entry->annotation, entries[i].annotation, sizeof(entries[i].annotation));
  102. rpc_status = TowerExplode(entries[i].tower, &entry->iface, &entry->syntax,
  103. &entry->protseq, &entry->endpoint,
  104. &entry->address);
  105. if (rpc_status != RPC_S_OK)
  106. {
  107. WINE_WARN("TowerExplode failed %lu\n", rpc_status);
  108. *status = rpc_status;
  109. HeapFree(GetProcessHeap(), 0, entry);
  110. break; /* FIXME: more cleanup? */
  111. }
  112. entry->object = entries[i].object;
  113. if (replace)
  114. {
  115. /* FIXME: correct find algorithm */
  116. struct registered_ept_entry *old_entry = find_ept_entry(&entry->iface, &entry->syntax, entry->protseq, entry->endpoint, entry->address, &entry->object);
  117. if (old_entry) delete_registered_ept_entry(old_entry);
  118. }
  119. list_add_tail(&registered_ept_entry_list, &entry->entry);
  120. }
  121. LeaveCriticalSection(&csEpm);
  122. }
  123. void __cdecl ept_delete(handle_t h,
  124. unsigned32 num_ents,
  125. ept_entry_t entries[],
  126. error_status_t *status)
  127. {
  128. unsigned32 i;
  129. RPC_STATUS rpc_status;
  130. *status = RPC_S_OK;
  131. WINE_TRACE("(%p, %lu, %p, %p)\n", h, num_ents, entries, status);
  132. EnterCriticalSection(&csEpm);
  133. for (i = 0; i < num_ents; i++)
  134. {
  135. struct registered_ept_entry *entry;
  136. RPC_SYNTAX_IDENTIFIER iface, syntax;
  137. char *protseq;
  138. char *endpoint;
  139. char *address;
  140. rpc_status = TowerExplode(entries[i].tower, &iface, &syntax, &protseq,
  141. &endpoint, &address);
  142. if (rpc_status != RPC_S_OK)
  143. break;
  144. entry = find_ept_entry(&iface, &syntax, protseq, endpoint, address, &entries[i].object);
  145. I_RpcFree(protseq);
  146. I_RpcFree(endpoint);
  147. I_RpcFree(address);
  148. if (entry)
  149. delete_registered_ept_entry(entry);
  150. else
  151. {
  152. *status = EPT_S_NOT_REGISTERED;
  153. break;
  154. }
  155. }
  156. LeaveCriticalSection(&csEpm);
  157. }
  158. void __cdecl ept_lookup(handle_t h,
  159. unsigned32 inquiry_type,
  160. uuid_p_t object,
  161. rpc_if_id_p_t interface_id,
  162. unsigned32 vers_option,
  163. ept_lookup_handle_t *entry_handle,
  164. unsigned32 max_ents,
  165. unsigned32 *num_ents,
  166. ept_entry_t entries[],
  167. error_status_t *status)
  168. {
  169. WINE_FIXME("(%p, %p, %p): stub\n", h, entry_handle, status);
  170. *status = EPT_S_CANT_PERFORM_OP;
  171. }
  172. void __cdecl ept_map(handle_t h,
  173. uuid_p_t object,
  174. twr_p_t map_tower,
  175. ept_lookup_handle_t *entry_handle,
  176. unsigned32 max_towers,
  177. unsigned32 *num_towers,
  178. twr_p_t *towers,
  179. error_status_t *status)
  180. {
  181. RPC_STATUS rpc_status;
  182. RPC_SYNTAX_IDENTIFIER iface, syntax;
  183. char *protseq;
  184. struct registered_ept_entry *entry;
  185. *status = RPC_S_OK;
  186. *num_towers = 0;
  187. WINE_TRACE("(%p, %p, %p, %p, %lu, %p, %p, %p)\n", h, object, map_tower,
  188. entry_handle, max_towers, num_towers, towers, status);
  189. rpc_status = TowerExplode(map_tower, &iface, &syntax, &protseq,
  190. NULL, NULL);
  191. if (rpc_status != RPC_S_OK)
  192. {
  193. *status = rpc_status;
  194. return;
  195. }
  196. EnterCriticalSection(&csEpm);
  197. LIST_FOR_EACH_ENTRY(entry, &registered_ept_entry_list, struct registered_ept_entry, entry)
  198. {
  199. if (IsEqualGUID(&entry->iface.SyntaxGUID, &iface.SyntaxGUID) &&
  200. (entry->iface.SyntaxVersion.MajorVersion == iface.SyntaxVersion.MajorVersion) &&
  201. (entry->iface.SyntaxVersion.MinorVersion >= iface.SyntaxVersion.MinorVersion) &&
  202. !memcmp(&entry->syntax, &syntax, sizeof(syntax)) &&
  203. !strcmp(entry->protseq, protseq) &&
  204. ((!object && IsEqualGUID(&entry->object, &nil_object)) || IsEqualGUID(object, &entry->object)))
  205. {
  206. if (*num_towers < max_towers)
  207. {
  208. rpc_status = TowerConstruct(&entry->iface, &entry->syntax,
  209. entry->protseq, entry->endpoint,
  210. entry->address,
  211. &towers[*num_towers]);
  212. if (rpc_status != RPC_S_OK)
  213. {
  214. *status = rpc_status;
  215. break; /* FIXME: more cleanup? */
  216. }
  217. }
  218. (*num_towers)++;
  219. }
  220. }
  221. LeaveCriticalSection(&csEpm);
  222. I_RpcFree(protseq);
  223. }
  224. void __cdecl ept_lookup_handle_free(handle_t h,
  225. ept_lookup_handle_t *entry_handle,
  226. error_status_t *status)
  227. {
  228. WINE_FIXME("(%p, %p, %p): stub\n", h, entry_handle, status);
  229. *status = EPT_S_CANT_PERFORM_OP;
  230. }
  231. void __cdecl ept_inq_object(handle_t h,
  232. GUID *ept_object,
  233. error_status_t *status)
  234. {
  235. WINE_FIXME("(%p, %p, %p): stub\n", h, ept_object, status);
  236. *status = EPT_S_CANT_PERFORM_OP;
  237. }
  238. void __cdecl ept_mgmt_delete(handle_t h,
  239. boolean32 object_speced,
  240. uuid_p_t object,
  241. twr_p_t tower,
  242. error_status_t *status)
  243. {
  244. WINE_FIXME("(%p, %ld, %p, %p, %p): stub\n", h, object_speced, object, tower, status);
  245. *status = EPT_S_CANT_PERFORM_OP;
  246. }