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.

605 lines
14 KiB

  1. //***************************************************************************
  2. //
  3. // NAMEPATH.CPP
  4. //
  5. // Module: OLE MS Provider Framework
  6. //
  7. // Copyright (c) 1996-2001 Microsoft Corporation, All Rights Reserved
  8. //
  9. //***************************************************************************
  10. #include "precomp.h"
  11. #include <provtempl.h>
  12. #include <provmt.h>
  13. #include <instpath.h>
  14. #include <strsafe.h>
  15. static wchar_t *UnicodeStringAppend ( const wchar_t *prefix , const wchar_t *suffix )
  16. {
  17. int prefixTextLength = 0 ;
  18. if ( prefix )
  19. {
  20. prefixTextLength = wcslen ( prefix ) ;
  21. }
  22. int suffixTextLength = 0 ;
  23. if ( suffix )
  24. {
  25. suffixTextLength = wcslen ( suffix ) ;
  26. }
  27. if ( prefix || suffix )
  28. {
  29. int textLength = prefixTextLength + suffixTextLength ;
  30. wchar_t *textBuffer = new wchar_t [ textLength + 1 ] ;
  31. if ( prefix )
  32. {
  33. StringCchCopyW ( textBuffer , textLength + 1 , prefix ) ;
  34. }
  35. if ( suffix )
  36. {
  37. StringCchCopyW ( & textBuffer [ prefixTextLength ] , suffixTextLength + 1 , suffix ) ;
  38. }
  39. return textBuffer ;
  40. }
  41. else
  42. return NULL ;
  43. }
  44. static wchar_t *UnicodeStringDuplicate ( const wchar_t *string )
  45. {
  46. if ( string )
  47. {
  48. int textLength = wcslen ( string ) ;
  49. wchar_t *textBuffer = new wchar_t [ textLength + 1 ] ;
  50. StringCchCopyW ( textBuffer , textLength + 1 , string ) ;
  51. return textBuffer ;
  52. }
  53. else
  54. {
  55. return NULL ;
  56. }
  57. }
  58. WbemNamespacePath :: WbemNamespacePath () : status ( FALSE ) ,
  59. pushedBack ( FALSE ) ,
  60. pushBack ( NULL ) ,
  61. server ( NULL ) ,
  62. relative ( FALSE ) ,
  63. nameSpaceListPosition ( NULL )
  64. {
  65. nameSpaceList = new CList <wchar_t * , wchar_t * > ;
  66. }
  67. void WbemNamespacePath :: SetUp ()
  68. {
  69. status = FALSE ;
  70. pushedBack = FALSE ;
  71. pushBack = NULL ;
  72. server = NULL ;
  73. relative = FALSE ;
  74. nameSpaceListPosition = NULL ;
  75. nameSpaceList = new CList <wchar_t * , wchar_t * > ;
  76. }
  77. WbemNamespacePath :: WbemNamespacePath (
  78. const WbemNamespacePath &nameSpacePathArg
  79. ) : status ( FALSE ) ,
  80. pushedBack ( FALSE ) ,
  81. pushBack ( NULL ) ,
  82. server ( NULL ) ,
  83. relative ( FALSE ) ,
  84. nameSpaceListPosition ( NULL )
  85. {
  86. nameSpaceList = new CList <wchar_t * , wchar_t * > ;
  87. CList <wchar_t * , wchar_t *> *nameList = ( CList <wchar_t * , wchar_t *> * ) nameSpaceList ;
  88. CList <wchar_t * , wchar_t *> *copyNameList = ( CList <wchar_t * , wchar_t *> * ) nameSpacePathArg.nameSpaceList ;
  89. POSITION position = copyNameList->GetHeadPosition () ;
  90. while ( position )
  91. {
  92. wchar_t *name = copyNameList->GetNext ( position ) ;
  93. nameList->AddTail ( UnicodeStringDuplicate ( name ) ) ;
  94. }
  95. server = UnicodeStringDuplicate ( nameSpacePathArg.server ) ;
  96. }
  97. WbemNamespacePath :: ~WbemNamespacePath ()
  98. {
  99. CleanUp () ;
  100. }
  101. void WbemNamespacePath :: CleanUp ()
  102. {
  103. if ( nameSpaceList )
  104. {
  105. CList <wchar_t * , wchar_t *> *nameList = ( CList <wchar_t * , wchar_t *> * ) nameSpaceList ;
  106. POSITION position = nameList->GetHeadPosition () ;
  107. while ( position )
  108. {
  109. wchar_t *value = nameList->GetNext ( position ) ;
  110. delete [] value ;
  111. }
  112. nameList->RemoveAll () ;
  113. delete ( CList <wchar_t * , wchar_t * > * ) nameSpaceList ;
  114. nameSpaceList = NULL ;
  115. }
  116. if ( pushBack )
  117. {
  118. delete pushBack ;
  119. pushBack = NULL ;
  120. }
  121. if ( server )
  122. {
  123. delete [] server ;
  124. server = NULL ;
  125. }
  126. relative = FALSE ;
  127. }
  128. BOOL WbemNamespacePath :: IsEmpty () const
  129. {
  130. CList <wchar_t * , wchar_t *> *list = ( CList <wchar_t * , wchar_t *> * ) nameSpaceList ;
  131. return list->IsEmpty () ;
  132. }
  133. ULONG WbemNamespacePath :: GetCount () const
  134. {
  135. CList <wchar_t * , wchar_t *> *list = ( CList <wchar_t * , wchar_t *> * ) nameSpaceList ;
  136. return list->GetCount () ;
  137. }
  138. void WbemNamespacePath :: Reset ()
  139. {
  140. CList <wchar_t * , wchar_t *> *list = ( CList <wchar_t * , wchar_t *> * ) nameSpaceList ;
  141. nameSpaceListPosition = list->GetHeadPosition () ;
  142. }
  143. wchar_t *WbemNamespacePath :: Next ()
  144. {
  145. wchar_t *value = NULL ;
  146. POSITION position = ( POSITION ) nameSpaceListPosition ;
  147. if ( position )
  148. {
  149. CList <wchar_t * , wchar_t *> *list = ( CList <wchar_t * , wchar_t *> * ) nameSpaceList ;
  150. value = list->GetNext ( position ) ;
  151. nameSpaceListPosition = position ;
  152. }
  153. return value ;
  154. }
  155. void WbemNamespacePath :: SetServer ( wchar_t *serverArg )
  156. {
  157. delete [] server ;
  158. DWORD t_TextLength = wcslen ( serverArg) + 1 ;
  159. server = new wchar_t [ t_TextLength ] ;
  160. StringCchCopyW ( server , t_TextLength , serverArg ) ;
  161. }
  162. void WbemNamespacePath :: Add ( wchar_t *nameSpace )
  163. {
  164. CList <wchar_t * , wchar_t * > *list = ( CList <wchar_t * , wchar_t * > * ) nameSpaceList ;
  165. list->AddTail ( nameSpace ) ;
  166. }
  167. WbemNamespacePath :: operator void *()
  168. {
  169. return status ? this : NULL ;
  170. }
  171. wchar_t *WbemNamespacePath :: GetNamespacePath ()
  172. {
  173. if ( status )
  174. {
  175. wchar_t *path = NULL ;
  176. if ( GetServer () )
  177. {
  178. path = UnicodeStringDuplicate ( L"\\\\" ) ;
  179. wchar_t *concatPath = UnicodeStringAppend ( path , GetServer () ) ;
  180. delete [] path ;
  181. path = concatPath ;
  182. }
  183. if ( ! Relative () )
  184. {
  185. wchar_t *concatPath = UnicodeStringAppend ( path , L"\\" ) ;
  186. delete [] path ;
  187. path = concatPath ;
  188. }
  189. wchar_t *pathComponent ;
  190. ULONG t_ComponentCount = 0 ;
  191. Reset () ;
  192. while ( pathComponent = Next () )
  193. {
  194. wchar_t *concatPath = NULL ;
  195. t_ComponentCount ++ ;
  196. if ( t_ComponentCount != GetCount () )
  197. {
  198. wchar_t *t_Temp = UnicodeStringAppend ( path , pathComponent ) ;
  199. concatPath = UnicodeStringAppend ( t_Temp , L"\\" ) ;
  200. delete [] t_Temp ;
  201. }
  202. else
  203. {
  204. concatPath = UnicodeStringAppend ( path , pathComponent ) ;
  205. }
  206. delete [] path ;
  207. path = concatPath ;
  208. }
  209. return path ;
  210. }
  211. else
  212. return NULL ;
  213. }
  214. BOOL WbemNamespacePath :: ConcatenatePath ( WbemNamespacePath &relative )
  215. {
  216. BOOL status = FALSE ;
  217. if ( relative.Relative () )
  218. {
  219. status = TRUE ;
  220. relative.Reset () ;
  221. wchar_t *namespaceComponent ;
  222. while ( namespaceComponent = Next () )
  223. {
  224. Add ( UnicodeStringDuplicate ( namespaceComponent ) ) ;
  225. }
  226. }
  227. return status ;
  228. }
  229. void WbemNamespacePath :: PushBack ()
  230. {
  231. pushedBack = TRUE ;
  232. }
  233. WbemLexicon *WbemNamespacePath :: Get ()
  234. {
  235. if ( pushedBack )
  236. {
  237. pushedBack = FALSE ;
  238. }
  239. else
  240. {
  241. delete pushBack ;
  242. pushBack = analyser.Get () ;
  243. }
  244. return pushBack ;
  245. }
  246. WbemLexicon *WbemNamespacePath :: Match ( WbemLexicon :: LexiconToken tokenType )
  247. {
  248. WbemLexicon *lexicon = Get () ;
  249. status = ( lexicon->GetToken () == tokenType ) ;
  250. return status ? lexicon : NULL ;
  251. }
  252. BOOL WbemNamespacePath :: SetNamespacePath ( wchar_t *tokenStream )
  253. {
  254. CleanUp () ;
  255. SetUp () ;
  256. analyser.Set ( tokenStream ) ;
  257. status = TRUE ;
  258. WbemLexicon *lookAhead = Get () ;
  259. switch ( lookAhead->GetToken () )
  260. {
  261. case WbemLexicon :: DOT_ID:
  262. {
  263. PushBack () ;
  264. NameSpaceRel () ;
  265. }
  266. break ;
  267. case WbemLexicon :: TOKEN_ID:
  268. {
  269. PushBack () ;
  270. NameSpaceRel () ;
  271. }
  272. break ;
  273. case WbemLexicon :: BACKSLASH_ID:
  274. {
  275. PushBack () ;
  276. BackSlashFactoredServerNamespace () ;
  277. }
  278. break ;
  279. default:
  280. {
  281. status = FALSE ;
  282. }
  283. break ;
  284. }
  285. Match ( WbemLexicon :: EOF_ID ) ;
  286. return status ;
  287. }
  288. BOOL WbemNamespacePath :: BackSlashFactoredServerNamespace ()
  289. {
  290. if ( Match ( WbemLexicon :: BACKSLASH_ID ) )
  291. {
  292. WbemLexicon *lookAhead = Get () ;
  293. switch ( lookAhead->GetToken () )
  294. {
  295. case WbemLexicon :: BACKSLASH_ID:
  296. {
  297. PushBack () ;
  298. BackSlashFactoredServerSpec () ;
  299. }
  300. break ;
  301. case WbemLexicon :: DOT_ID:
  302. {
  303. PushBack () ;
  304. NameSpaceRel () ;
  305. }
  306. break ;
  307. case WbemLexicon :: TOKEN_ID:
  308. {
  309. PushBack () ;
  310. NameSpaceRel () ;
  311. }
  312. break ;
  313. default:
  314. {
  315. status = FALSE ;
  316. }
  317. }
  318. }
  319. return status ;
  320. }
  321. BOOL WbemNamespacePath :: BackSlashFactoredServerSpec ()
  322. {
  323. if ( Match ( WbemLexicon :: BACKSLASH_ID ) )
  324. {
  325. WbemLexicon *lookAhead = Get () ;
  326. switch ( lookAhead->GetToken () )
  327. {
  328. case WbemLexicon :: DOT_ID:
  329. {
  330. PushBack () ;
  331. WbemLexicon *token ;
  332. if ( token = Match ( WbemLexicon :: DOT_ID ) )
  333. {
  334. SetServer ( L"." ) ;
  335. WbemLexicon *lookAhead = Get () ;
  336. switch ( lookAhead->GetToken () )
  337. {
  338. case WbemLexicon :: BACKSLASH_ID:
  339. {
  340. PushBack () ;
  341. NameSpaceAbs () ;
  342. }
  343. break ;
  344. case WbemLexicon :: EOF_ID:
  345. {
  346. PushBack () ;
  347. }
  348. break ;
  349. default:
  350. {
  351. status = FALSE ;
  352. }
  353. }
  354. }
  355. }
  356. break ;
  357. case WbemLexicon :: TOKEN_ID:
  358. {
  359. PushBack () ;
  360. WbemLexicon *token ;
  361. if ( token = Match ( WbemLexicon :: TOKEN_ID ) )
  362. {
  363. SetServer ( token->GetValue ()->token ) ;
  364. WbemLexicon *lookAhead = Get () ;
  365. switch ( lookAhead->GetToken () )
  366. {
  367. case WbemLexicon :: BACKSLASH_ID:
  368. {
  369. PushBack () ;
  370. NameSpaceAbs () ;
  371. }
  372. break ;
  373. case WbemLexicon :: EOF_ID:
  374. {
  375. PushBack () ;
  376. }
  377. break ;
  378. default:
  379. {
  380. status = FALSE ;
  381. }
  382. }
  383. }
  384. }
  385. break ;
  386. default:
  387. {
  388. status = FALSE ;
  389. }
  390. break ;
  391. }
  392. }
  393. return status ;
  394. }
  395. BOOL WbemNamespacePath :: NameSpaceName ()
  396. {
  397. WbemLexicon *lookAhead = Get () ;
  398. switch ( lookAhead->GetToken () )
  399. {
  400. case WbemLexicon :: TOKEN_ID:
  401. {
  402. PushBack () ;
  403. WbemLexicon *token ;
  404. if ( token = Match ( WbemLexicon :: TOKEN_ID ) )
  405. {
  406. wchar_t *namespaceValue = token->GetValue ()->token ;
  407. if ( namespaceValue )
  408. {
  409. DWORD t_TextLength = wcslen ( namespaceValue ) + 1 ;
  410. wchar_t *copy = new wchar_t [ t_TextLength ] ;
  411. StringCchCopyW ( copy , t_TextLength , namespaceValue ) ;
  412. Add ( copy ) ;
  413. }
  414. else
  415. {
  416. status = FALSE ;
  417. }
  418. }
  419. }
  420. break ;
  421. case WbemLexicon :: DOT_ID:
  422. {
  423. PushBack () ;
  424. WbemLexicon *token ;
  425. if ( token = Match ( WbemLexicon :: DOT_ID ) )
  426. {
  427. DWORD t_TextLength = wcslen ( L"." ) + 1 ;
  428. wchar_t *copy = new wchar_t [ t_TextLength ] ;
  429. StringCchCopyW ( copy , t_TextLength , L"." ) ;
  430. Add ( copy ) ;
  431. }
  432. }
  433. break ;
  434. default:
  435. {
  436. status = FALSE ;
  437. }
  438. break ;
  439. }
  440. return status ;
  441. }
  442. BOOL WbemNamespacePath :: NameSpaceRel ()
  443. {
  444. relative = TRUE ;
  445. NameSpaceName () &&
  446. RecursiveNameSpaceRel () ;
  447. return status ;
  448. }
  449. BOOL WbemNamespacePath :: RecursiveNameSpaceRel ()
  450. {
  451. WbemLexicon *lookAhead = Get () ;
  452. switch ( lookAhead->GetToken () )
  453. {
  454. case WbemLexicon :: BACKSLASH_ID:
  455. {
  456. PushBack () ;
  457. Match ( WbemLexicon :: BACKSLASH_ID ) &&
  458. NameSpaceRel () ;
  459. }
  460. break ;
  461. case WbemLexicon :: EOF_ID:
  462. {
  463. PushBack () ;
  464. }
  465. break ;
  466. default:
  467. {
  468. status = FALSE ;
  469. }
  470. }
  471. return status ;
  472. }
  473. BOOL WbemNamespacePath :: NameSpaceAbs ()
  474. {
  475. Match ( WbemLexicon :: BACKSLASH_ID ) &&
  476. NameSpaceName () &&
  477. RecursiveNameSpaceAbs () ;
  478. return status ;
  479. }
  480. BOOL WbemNamespacePath :: RecursiveNameSpaceAbs ()
  481. {
  482. WbemLexicon *lookAhead = Get () ;
  483. switch ( lookAhead->GetToken () )
  484. {
  485. case WbemLexicon :: BACKSLASH_ID:
  486. {
  487. PushBack () ;
  488. Match ( WbemLexicon :: BACKSLASH_ID ) &&
  489. NameSpaceName () &&
  490. RecursiveNameSpaceAbs () ;
  491. }
  492. break ;
  493. case WbemLexicon :: EOF_ID:
  494. {
  495. PushBack () ;
  496. }
  497. break ;
  498. default:
  499. {
  500. status = FALSE ;
  501. }
  502. }
  503. return status ;
  504. }