Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

526 lines
8.8 KiB

  1. #ifndef __SDPLIB_H__
  2. #define __SDPLIB_H__
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include "sdpnode.h"
  7. #ifndef NTSTATUS
  8. typedef LONG NTSTATUS;
  9. #endif
  10. typedef UCHAR SDP_ELEMENT_HEADER;
  11. #define SDP_TYPE_LISTHEAD (0x0021)
  12. #define SDP_ST_CONTAINER_STREAM (0x2001)
  13. #define SDP_ST_CONTAINER_INTERFACE (0x2002)
  14. typedef struct _SDP_STREAM_ENTRY {
  15. LIST_ENTRY link;
  16. ULONG streamSize;
  17. UCHAR stream[1];
  18. } SDP_STREAM_ENTRY, *PSDP_STREAM_ENTRY;
  19. typedef struct _PSM_PROTOCOL_PAIR {
  20. GUID protocol;
  21. USHORT psm;
  22. } PSM_PROTOCOL_PAIR, *PPSM_PROTOCOL_PAIR;
  23. typedef struct _PSM_LIST {
  24. ULONG count;
  25. PSM_PROTOCOL_PAIR list[1];
  26. } PSM_LIST, *PPSM_LIST;
  27. #define TYPE_BIT_SIZE (5)
  28. #define TYPE_SHIFT_VAL (8 - TYPE_BIT_SIZE)
  29. #define TYPE_MASK ((UCHAR) 0x1F)
  30. #define SPECIFIC_TYPE_MASK (0x07)
  31. #define SIZE_INDEX_MASK (SPECIFIC_TYPE_MASK)
  32. #define SPECIFIC_TYPE_SHIFT (8)
  33. #define SIZE_INDEX_ZERO (0)
  34. #define SIZE_INDEX_NEXT_8_BITS (5)
  35. #define SIZE_INDEX_NEXT_16_BITS (6)
  36. #define SIZE_INDEX_NEXT_32_BITS (7)
  37. #define IS_VAR_SIZE_INDEX_INVALID(si) \
  38. ((si) < SIZE_INDEX_NEXT_8_BITS || (si) > SIZE_INDEX_NEXT_32_BITS)
  39. #define FMT_TYPE(_type) ((((_type) & TYPE_MASK) << TYPE_SHIFT_VAL))
  40. #define FMT_SIZE_INDEX_FROM_ST(_spectype) \
  41. (((_spectype) & (SPECIFIC_TYPE_MASK << SPECIFIC_TYPE_SHIFT)) >> \
  42. SPECIFIC_TYPE_SHIFT)
  43. void
  44. SdpInitializeNodeHeader(
  45. PSDP_NODE_HEADER Header
  46. );
  47. PSDP_TREE_ROOT_NODE
  48. SdpCreateNodeTree(
  49. void
  50. );
  51. NTSTATUS
  52. SdpFreeTree(
  53. PSDP_TREE_ROOT_NODE Tree
  54. );
  55. NTSTATUS
  56. SdpFreeTreeEx(
  57. PSDP_TREE_ROOT_NODE Tree,
  58. UCHAR FreeRoot
  59. );
  60. NTSTATUS
  61. SdpFreeOrphanedNode(
  62. PSDP_NODE Node
  63. );
  64. void
  65. SdpReleaseContainer(
  66. ISdpNodeContainer *Container
  67. );
  68. PSDP_NODE
  69. SdpCreateNode(
  70. VOID
  71. );
  72. PSDP_NODE
  73. SdpCreateNodeNil(
  74. VOID
  75. );
  76. PSDP_NODE
  77. SdpCreateNodeUInt128(
  78. PSDP_ULARGE_INTEGER_16 puli16Val
  79. );
  80. PSDP_NODE
  81. SdpCreateNodeUInt64(
  82. ULONGLONG ullVal
  83. );
  84. PSDP_NODE
  85. SdpCreateNodeUInt32(
  86. ULONG ulVal
  87. );
  88. PSDP_NODE
  89. SdpCreateNodeUInt16(
  90. USHORT usVal
  91. );
  92. PSDP_NODE
  93. SdpCreateNodeUInt8(
  94. UCHAR ucVal
  95. );
  96. PSDP_NODE
  97. SdpCreateNodeInt128(
  98. PSDP_LARGE_INTEGER_16 uil16Val
  99. );
  100. PSDP_NODE
  101. SdpCreateNodeInt64(
  102. LONGLONG llVal
  103. );
  104. PSDP_NODE
  105. SdpCreateNodeInt32(
  106. LONG lVal
  107. );
  108. PSDP_NODE
  109. SdpCreateNodeInt16(
  110. SHORT sVal
  111. );
  112. PSDP_NODE
  113. SdpCreateNodeInt8(
  114. CHAR cVal
  115. );
  116. #define SdpCreateNodeUUID SdpCreateNodeUUID128
  117. PSDP_NODE
  118. SdpCreateNodeUUID128(
  119. const GUID *uuid
  120. );
  121. PSDP_NODE
  122. SdpCreateNodeUUID32(
  123. ULONG uuidVal4
  124. );
  125. PSDP_NODE
  126. SdpCreateNodeUUID16(
  127. USHORT uuidVal2
  128. );
  129. PSDP_NODE
  130. SdpCreateNodeString(
  131. PCHAR string, ULONG stringLength
  132. );
  133. PSDP_NODE
  134. SdpCreateNodeBoolean(
  135. SDP_BOOLEAN bVal
  136. );
  137. PSDP_NODE
  138. SdpCreateNodeSequence(
  139. void
  140. );
  141. PSDP_NODE
  142. SdpCreateNodeAlternative(
  143. void
  144. );
  145. PSDP_NODE
  146. SdpCreateNodeUrl(
  147. PCHAR url,
  148. ULONG urlLength
  149. );
  150. NTSTATUS
  151. SdpAppendNodeToContainerNode(
  152. PSDP_NODE Parent,
  153. PSDP_NODE Node
  154. );
  155. NTSTATUS
  156. SdpAddAttributeToTree(
  157. PSDP_TREE_ROOT_NODE Tree,
  158. USHORT AttribId,
  159. PSDP_NODE AttribValue
  160. );
  161. NTSTATUS
  162. SdpAddAttributeToHeader(
  163. PSDP_NODE_HEADER Header,
  164. USHORT AttribId,
  165. PSDP_NODE AttribValue,
  166. PULONG Replaced
  167. );
  168. NTSTATUS
  169. SdpFindAttributeInTree(
  170. PSDP_TREE_ROOT_NODE Tree,
  171. USHORT AttribId,
  172. PSDP_NODE *Attribute
  173. );
  174. NTSTATUS
  175. SdpFindAttributeInStream(
  176. PUCHAR Stream,
  177. ULONG Size,
  178. USHORT Attrib,
  179. PUCHAR *PPStream,
  180. PULONG PSize
  181. );
  182. NTSTATUS
  183. SdpFindAttributeSequenceInStream(
  184. PUCHAR Stream,
  185. ULONG Size,
  186. SdpAttributeRange *AttributeRange,
  187. ULONG AttributeRangeCount,
  188. PSDP_STREAM_ENTRY *ppEntry,
  189. PSDP_ERROR SdpError
  190. );
  191. SDP_ERROR
  192. SdpMapNtStatusToSdpError(
  193. NTSTATUS Status
  194. );
  195. NTSTATUS
  196. SdpStreamFromTree(
  197. PSDP_TREE_ROOT_NODE Root,
  198. PUCHAR *Stream,
  199. PULONG Size
  200. );
  201. NTSTATUS
  202. SdpStreamFromTreeEx(
  203. PSDP_TREE_ROOT_NODE Root,
  204. PUCHAR *Stream,
  205. PULONG Size,
  206. ULONG HeaderSize,
  207. ULONG TailSize,
  208. UCHAR PagedAllocation
  209. );
  210. NTSTATUS
  211. SdpTreeFromStream(
  212. PUCHAR Stream,
  213. ULONG Size,
  214. PSDP_TREE_ROOT_NODE* Node,
  215. UCHAR FullParse
  216. );
  217. typedef NTSTATUS (*PSDP_STREAM_WALK_FUNC)(
  218. PVOID Context,
  219. UCHAR DataType,
  220. ULONG DataSize,
  221. PUCHAR Data
  222. );
  223. NTSTATUS
  224. SdpWalkStream(
  225. PUCHAR Stream,
  226. ULONG Size,
  227. PSDP_STREAM_WALK_FUNC WalkFunc,
  228. PVOID WalkContext
  229. );
  230. VOID
  231. SdpFreePool(
  232. PVOID Memory
  233. );
  234. void
  235. SdpByteSwapUuid128(
  236. GUID *uuid128From,
  237. GUID *uuid128To
  238. );
  239. void
  240. SdpByteSwapUint128(
  241. PSDP_ULARGE_INTEGER_16 pInUint128,
  242. PSDP_ULARGE_INTEGER_16 pOutUint128
  243. );
  244. ULONGLONG
  245. SdpByteSwapUint64(
  246. ULONGLONG uint64
  247. );
  248. ULONG
  249. SdpByteSwapUint32(
  250. ULONG uint32
  251. );
  252. USHORT
  253. SdpByteSwapUint16(
  254. USHORT uint16
  255. );
  256. void
  257. SdpRetrieveUuid128(
  258. PUCHAR Stream,
  259. GUID *uuidVal
  260. );
  261. void
  262. SdpRetrieveUint128(
  263. PUCHAR Stream,
  264. PSDP_ULARGE_INTEGER_16 pUint128
  265. );
  266. void
  267. SdpRetrieveUint64(
  268. PUCHAR Stream,
  269. PULONGLONG pUint64
  270. );
  271. void
  272. SdpRetrieveUint32(
  273. PUCHAR Stream,
  274. PULONG pUint32
  275. );
  276. void
  277. SdpRetrieveUint16(
  278. PUCHAR Stream,
  279. PUSHORT pUint16
  280. );
  281. void
  282. SdpRetrieveVariableSize(
  283. PUCHAR Stream,
  284. UCHAR SizeIndex,
  285. PULONG ElementSize,
  286. PULONG StorageSize
  287. );
  288. void
  289. SdpRetrieveUuidFromStream(
  290. PUCHAR Stream,
  291. ULONG DataSize,
  292. GUID *pUuid,
  293. UCHAR bigEndian
  294. );
  295. void
  296. SdpNormalizeUuid(
  297. PSDP_NODE pUuid,
  298. GUID* uuid
  299. );
  300. NTSTATUS
  301. SdpGetProtocolConnectInfo(
  302. IN PUCHAR Stream,
  303. IN ULONG StreamSize,
  304. IN ULONG Index,
  305. IN UCHAR IsPrimary,
  306. OUT GUID* Protocol,
  307. OUT PUSHORT Psm,
  308. OUT PUCHAR IsRfcomm
  309. );
  310. ULONG
  311. SdpGetNumProtocolStacks(
  312. IN PUCHAR Stream,
  313. IN ULONG StreamSize,
  314. IN UCHAR IsPrimary
  315. );
  316. NTSTATUS
  317. SdpValidateProtocolContainer(
  318. PSDP_NODE pContainer,
  319. PPSM_LIST pPsmList
  320. );
  321. NTSTATUS
  322. SdpValidateVariableSize(
  323. PUCHAR Stream,
  324. ULONG StreamSize,
  325. UCHAR SizeIndex,
  326. PULONG ElementSize,
  327. PULONG StorageSize
  328. );
  329. #define SDP_RETRIEVE_HEADER(_stream, _type, _sizeidx) \
  330. { \
  331. (_type) = ((*(_stream)) & (TYPE_MASK << TYPE_SHIFT_VAL)) >> TYPE_SHIFT_VAL;\
  332. (_sizeidx) = *(_stream) & SIZE_INDEX_MASK; \
  333. }
  334. NTSTATUS
  335. SdpValidateStream(
  336. PUCHAR Stream,
  337. ULONG Size,
  338. PULONG NumEntries,
  339. PULONG ExtraPool,
  340. PULONG_PTR ErrorByte
  341. );
  342. NTSTATUS
  343. SdpIsStreamRecord(
  344. PUCHAR Stream,
  345. ULONG Size
  346. );
  347. #define VERIFY_SINGLE_ATTRIBUTE (0x00000001)
  348. #define VERIFY_CHECK_MANDATORY_LOCAL (0x00000002)
  349. #define VERIFY_CHECK_MANDATORY_REMOTE (0x00000004)
  350. #define VERIFY_STREAM_IS_ATTRIBUTE_VALUE (0x00000008)
  351. #define VERIFY_CHECK_MANDATORY_ALL \
  352. (VERIFY_CHECK_MANDATORY_LOCAL | VERIFY_CHECK_MANDATORY_REMOTE)
  353. NTSTATUS
  354. SdpVerifyServiceRecord(
  355. PUCHAR Stream,
  356. ULONG Size,
  357. ULONG Flags,
  358. PUSHORT AttribId
  359. );
  360. NTSTATUS
  361. SdpVerifySequenceOf(
  362. PUCHAR Stream,
  363. ULONG Size,
  364. UCHAR OfType,
  365. PUCHAR SpecSizes,
  366. PULONG NumFound,
  367. PSDP_STREAM_WALK_FUNC Func,
  368. PVOID Context
  369. );
  370. VOID
  371. SdpGetNextElement(
  372. PUCHAR Stream,
  373. ULONG StreamSize,
  374. PUCHAR CurrentElement,
  375. PUCHAR* NextElement,
  376. PULONG NextElementSize
  377. );
  378. typedef struct _SDP_ATTRIBUTE_INFO {
  379. PUCHAR AttributeStream;
  380. ULONG AttributeStreamSize;
  381. USHORT AttributeId;
  382. } SDP_ATTRIBUTE_INFO, *PSDP_ATTRIBUTE_INFO;
  383. VOID
  384. Sdp_InitializeListHead(
  385. PLIST_ENTRY ListHead
  386. );
  387. UCHAR
  388. Sdp_IsListEmpty(
  389. PLIST_ENTRY ListHead
  390. );
  391. PLIST_ENTRY
  392. Sdp_RemoveHeadList(
  393. PLIST_ENTRY ListHead
  394. );
  395. VOID
  396. Sdp_RemoveEntryList(
  397. PLIST_ENTRY Entry
  398. );
  399. VOID
  400. Sdp_InsertEntryList(
  401. PLIST_ENTRY Previous,
  402. PLIST_ENTRY Entry
  403. );
  404. NTSTATUS
  405. SdpNodeToStream(
  406. PSDP_NODE Node,
  407. PUCHAR Stream
  408. );
  409. NTSTATUS
  410. SdpComputeNodeListSize(
  411. PSDP_NODE Node,
  412. PULONG Size
  413. );
  414. UCHAR
  415. SdpGetContainerHeaderSize(
  416. ULONG ContainerSize
  417. );
  418. PUCHAR
  419. SdpWriteVariableSizeToStream(
  420. UCHAR Type,
  421. ULONG DataSize,
  422. PUCHAR Stream
  423. );
  424. PUCHAR
  425. SdpWriteLeafToStream(
  426. PSDP_NODE Node,
  427. PUCHAR Stream
  428. );
  429. #define IsEqualUuid(u1, u2) (RtlEqualMemory((u1), (u2), sizeof(GUID)))
  430. #ifdef __cplusplus
  431. };
  432. #endif
  433. #endif // __SDPLIB_H__