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.

316 lines
6.7 KiB

  1. /*++
  2. Copyright (c) 1990-2003 Microsoft Corporation
  3. All rights reserved
  4. Module Name:
  5. config.c
  6. Abstract:
  7. Handles spooler entry points for adding, deleting, and configuring
  8. localmon ports.
  9. // @@BEGIN_DDKSPLIT
  10. Environment:
  11. User Mode -Win32
  12. Revision History:
  13. // @@END_DDKSPLIT
  14. --*/
  15. #include "precomp.h"
  16. #pragma hdrstop
  17. PINIPORT
  18. LcmCreatePortEntry(
  19. PINILOCALMON pIniLocalMon,
  20. PWSTR pPortName
  21. )
  22. {
  23. DWORD cb;
  24. PINIPORT pIniPort, pPort;
  25. size_t cchPortName = wcslen (pPortName) + 1;
  26. if (!pPortName || wcslen(pPortName) > 247)
  27. {
  28. SetLastError(ERROR_INVALID_NAME);
  29. return NULL;
  30. }
  31. cb = sizeof(INIPORT) + cchPortName * sizeof (WCHAR);
  32. pIniPort=AllocSplMem(cb);
  33. if( pIniPort )
  34. {
  35. pIniPort->pName = (LPWSTR)(pIniPort+1);
  36. StringCchCopy (pIniPort->pName, cchPortName, pPortName);
  37. pIniPort->cb = cb;
  38. pIniPort->pNext = 0;
  39. pIniPort->pIniLocalMon = pIniLocalMon;
  40. pIniPort->signature = IPO_SIGNATURE;
  41. // @@BEGIN_DDKSPLIT
  42. //
  43. // KrishnaG -- initialized the hFile value; it will be set to
  44. // a legal value in the StartDocPort call
  45. //
  46. // @@END_DDKSPLIT
  47. pIniPort->hFile = INVALID_HANDLE_VALUE;
  48. LcmEnterSplSem();
  49. if (pPort = pIniLocalMon->pIniPort) {
  50. while (pPort->pNext)
  51. pPort = pPort->pNext;
  52. pPort->pNext = pIniPort;
  53. } else
  54. pIniLocalMon->pIniPort = pIniPort;
  55. LcmLeaveSplSem();
  56. }
  57. return pIniPort;
  58. }
  59. PINIXCVPORT
  60. CreateXcvPortEntry(
  61. PINILOCALMON pIniLocalMon,
  62. LPCWSTR pszName,
  63. ACCESS_MASK GrantedAccess
  64. )
  65. {
  66. DWORD cb;
  67. PINIXCVPORT pIniXcvPort, pPort;
  68. size_t cchName = wcslen (pszName) + 1;
  69. cb = sizeof(INIXCVPORT) + cchName*sizeof(WCHAR);
  70. pIniXcvPort = AllocSplMem(cb);
  71. if( pIniXcvPort )
  72. {
  73. pIniXcvPort->pszName = (LPWSTR)(pIniXcvPort+1);
  74. StringCchCopy (pIniXcvPort->pszName, cchName, pszName);
  75. pIniXcvPort->dwMethod = 0;
  76. pIniXcvPort->cb = cb;
  77. pIniXcvPort->pNext = 0;
  78. pIniXcvPort->signature = XCV_SIGNATURE;
  79. pIniXcvPort->GrantedAccess = GrantedAccess;
  80. pIniXcvPort->pIniLocalMon = pIniLocalMon;
  81. if (pPort = pIniLocalMon->pIniXcvPort) {
  82. while (pPort->pNext)
  83. pPort = pPort->pNext;
  84. pPort->pNext = pIniXcvPort;
  85. } else
  86. pIniLocalMon->pIniXcvPort = pIniXcvPort;
  87. }
  88. return pIniXcvPort;
  89. }
  90. BOOL
  91. DeleteXcvPortEntry(
  92. PINIXCVPORT pIniXcvPort
  93. )
  94. {
  95. PINILOCALMON pIniLocalMon = pIniXcvPort->pIniLocalMon;
  96. PINIXCVPORT pPort, pPrevPort;
  97. for (pPort = pIniLocalMon->pIniXcvPort;
  98. pPort && pPort != pIniXcvPort;
  99. pPort = pPort->pNext){
  100. pPrevPort = pPort;
  101. }
  102. if (pPort) { // found the port
  103. if (pPort == pIniLocalMon->pIniXcvPort) {
  104. pIniLocalMon->pIniXcvPort = pPort->pNext;
  105. } else {
  106. pPrevPort->pNext = pPort->pNext;
  107. }
  108. FreeSplMem(pPort);
  109. return TRUE;
  110. }
  111. else // port not found
  112. return FALSE;
  113. }
  114. BOOL
  115. LcmDeletePortEntry(
  116. PINILOCALMON pIniLocalMon,
  117. LPWSTR pPortName
  118. )
  119. {
  120. DWORD cb;
  121. PINIPORT pPort, pPrevPort;
  122. cb = sizeof(INIPORT) + wcslen(pPortName)*sizeof(WCHAR) + sizeof(WCHAR);
  123. pPort = pIniLocalMon->pIniPort;
  124. while (pPort) {
  125. if (!lstrcmpi(pPort->pName, pPortName)) {
  126. if (pPort->Status & PP_FILEPORT) {
  127. pPrevPort = pPort;
  128. pPort = pPort->pNext;
  129. continue;
  130. }
  131. break;
  132. }
  133. pPrevPort = pPort;
  134. pPort = pPort->pNext;
  135. }
  136. if (pPort) {
  137. if (pPort == pIniLocalMon->pIniPort) {
  138. pIniLocalMon->pIniPort = pPort->pNext;
  139. } else {
  140. pPrevPort->pNext = pPort->pNext;
  141. }
  142. FreeSplMem(pPort);
  143. return TRUE;
  144. }
  145. else
  146. return FALSE;
  147. }
  148. DWORD
  149. GetPortSize(
  150. PINIPORT pIniPort,
  151. DWORD Level
  152. )
  153. {
  154. DWORD cb;
  155. WCHAR szLocalMonitor[MAX_PATH+1], szPortDesc[MAX_PATH+1];
  156. switch (Level) {
  157. case 1:
  158. cb=sizeof(PORT_INFO_1) +
  159. wcslen(pIniPort->pName)*sizeof(WCHAR) + sizeof(WCHAR);
  160. break;
  161. case 2:
  162. LoadString(LcmhInst, IDS_LOCALMONITORNAME, szLocalMonitor, MAX_PATH);
  163. LoadString(LcmhInst, IDS_LOCALMONITOR, szPortDesc, MAX_PATH);
  164. cb = wcslen(pIniPort->pName) + 1 +
  165. wcslen(szLocalMonitor) + 1 +
  166. wcslen(szPortDesc) + 1;
  167. cb *= sizeof(WCHAR);
  168. cb += sizeof(PORT_INFO_2);
  169. break;
  170. default:
  171. cb = 0;
  172. break;
  173. }
  174. return cb;
  175. }
  176. LPBYTE
  177. CopyIniPortToPort(
  178. PINIPORT pIniPort,
  179. DWORD Level,
  180. LPBYTE pPortInfo,
  181. LPBYTE pEnd
  182. )
  183. {
  184. LPWSTR *SourceStrings, *pSourceStrings;
  185. PPORT_INFO_2 pPort2 = (PPORT_INFO_2)pPortInfo;
  186. WCHAR szLocalMonitor[MAX_PATH+1], szPortDesc[MAX_PATH+1];
  187. DWORD *pOffsets;
  188. DWORD Count;
  189. switch (Level) {
  190. case 1:
  191. pOffsets = LcmPortInfo1Strings;
  192. break;
  193. case 2:
  194. pOffsets = LcmPortInfo2Strings;
  195. break;
  196. default:
  197. DBGMSG(DBG_ERROR,
  198. ("CopyIniPortToPort: invalid level %d", Level));
  199. return NULL;
  200. }
  201. for ( Count = 0 ; pOffsets[Count] != -1 ; ++Count ) {
  202. }
  203. SourceStrings = pSourceStrings = AllocSplMem(Count * sizeof(LPWSTR));
  204. if ( !SourceStrings ) {
  205. DBGMSG( DBG_WARNING, ("Failed to alloc port source strings.\n"));
  206. return NULL;
  207. }
  208. switch (Level) {
  209. case 1:
  210. *pSourceStrings++=pIniPort->pName;
  211. break;
  212. case 2:
  213. *pSourceStrings++=pIniPort->pName;
  214. LoadString(LcmhInst, IDS_LOCALMONITORNAME, szLocalMonitor, MAX_PATH);
  215. LoadString(LcmhInst, IDS_LOCALMONITOR, szPortDesc, MAX_PATH);
  216. *pSourceStrings++ = szLocalMonitor;
  217. *pSourceStrings++ = szPortDesc;
  218. // @@BEGIN_DDKSPLIT
  219. // How do i findout other types ???
  220. // @@END_DDKSPLIT
  221. pPort2->fPortType = PORT_TYPE_WRITE;
  222. // Reserved
  223. pPort2->Reserved = 0;
  224. break;
  225. default:
  226. DBGMSG(DBG_ERROR,
  227. ("CopyIniPortToPort: invalid level %d", Level));
  228. return NULL;
  229. }
  230. pEnd = PackStrings(SourceStrings, pPortInfo, pOffsets, pEnd);
  231. FreeSplMem(SourceStrings);
  232. return pEnd;
  233. }