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.

348 lines
7.3 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corp., 1991 **/
  4. /**********************************************************************/
  5. /*
  6. getprint.cxx
  7. This file contains the code for the GET_PRINTERS_DIALOG.
  8. FILE HISTORY:
  9. NarenG 25-May-1993 Created
  10. */
  11. #define INCL_NET
  12. #define INCL_NETLIB
  13. #define INCL_WINDOWS
  14. #define INCL_WINDOWS_GDI
  15. #define INCL_NETERRORS
  16. #define INCL_DOSERRORS
  17. #include <lmui.hxx>
  18. #define INCL_BLT_WINDOW
  19. #define INCL_BLT_DIALOG
  20. #define INCL_BLT_CONTROL
  21. #define INCL_BLT_CLIENT
  22. #define INCL_BLT_EVENT
  23. #define INCL_BLT_MISC
  24. #define INCL_BLT_MSGPOPUP
  25. #define INCL_BLT_TIMER
  26. #define INCL_BLT_CC
  27. #include <blt.hxx>
  28. #if defined(DEBUG)
  29. static const CHAR szFileName[] = __FILE__;
  30. #define _FILENAME_DEFINED_ONCE szFileName
  31. #endif // DEBUG
  32. #include <uiassert.hxx>
  33. #include <dbgstr.hxx>
  34. extern "C"
  35. {
  36. #include <winsock.h>
  37. #include <atalkwsh.h>
  38. #include <stdlib.h>
  39. #include "atalkmon.h"
  40. #include "dialogs.h"
  41. DWORD DoNBPLookup( LPVOID Parameter );
  42. }
  43. #include "getprint.hxx"
  44. /*******************************************************************
  45. NAME: GET_PRINTERS_DIALOG::GET_PRINTERS_DIALOG
  46. SYNOPSIS: constructor for GET_PRINTERS_DIALOG
  47. HISTORY:
  48. NarenG 25-May-1993 Stole from AFPMGR
  49. ********************************************************************/
  50. GET_PRINTERS_DIALOG::GET_PRINTERS_DIALOG( HWND hWndOwner,
  51. PNBP_LOOKUP_STRUCT pBuffer )
  52. : DIALOG_WINDOW(MAKEINTRESOURCE( IDD_GET_PRINTERS_DIALOG ), hWndOwner),
  53. _timer( this, TIMER_FREQ, FALSE ),
  54. _progress(this, IDGP_PROGRESS, IDI_PROGRESS_ICON_0, IDI_PROGRESS_NUM_ICONS),
  55. _sltMessage( this, IDGP_ST_MESSAGE ),
  56. _nTickCounter( TIMER_MULT )
  57. {
  58. if ( QueryError() != NERR_Success )
  59. {
  60. return ;
  61. }
  62. //
  63. // Begin NBP lookup
  64. //
  65. DWORD tidNBPLookup;
  66. _hthreadNBPLookup = ::CreateThread(
  67. NULL, // Default security attributes
  68. 0, // Default stack size
  69. ::DoNBPLookup, // Start address
  70. pBuffer, // Thread parameter
  71. 0, // Run immediately
  72. &tidNBPLookup // Thread id
  73. );
  74. if ( _hthreadNBPLookup == NULL )
  75. {
  76. ReportError( ::GetLastError() );
  77. return;
  78. }
  79. //
  80. // set the message.
  81. //
  82. DWORD err;
  83. NLS_STR nlsMessage;
  84. NLS_STR nlsZoneName( pBuffer->wchZone );
  85. if ( (( err = nlsMessage.QueryError() ) != NERR_Success ) ||
  86. (( err = nlsZoneName.QueryError() ) != NERR_Success ) )
  87. {
  88. ReportError( err );
  89. return;
  90. }
  91. if ( ::_wcsicmp( pBuffer->wchZone, (LPWSTR)TEXT("*") ) == 0 )
  92. {
  93. nlsMessage.Load( IDS_NO_ZONE_FOR_PRINTERS );
  94. }
  95. else
  96. {
  97. nlsMessage.Load( IDS_GETTING_PRINTERS_ON_ZONE );
  98. err = nlsMessage.InsertParams( nlsZoneName );
  99. }
  100. if( err != NERR_Success )
  101. {
  102. ReportError( err );
  103. return;
  104. }
  105. _sltMessage.SetText( nlsMessage );
  106. //
  107. // set polling timer
  108. //
  109. _timer.Enable( TRUE );
  110. return;
  111. }
  112. /*******************************************************************
  113. NAME: GET_PRINTERS_DIALOG::~GET_PRINTERS_DIALOG
  114. SYNOPSIS: destructor for SERVICE_WAIT_DIALOG. Stops
  115. the timer if it has not already been stopped.
  116. HISTORY:
  117. NarenG 25-May-1992 Created
  118. ********************************************************************/
  119. GET_PRINTERS_DIALOG::~GET_PRINTERS_DIALOG( VOID )
  120. {
  121. _timer.Enable( FALSE );
  122. }
  123. /*******************************************************************
  124. NAME: GET_PRINTERS_DIALOG::OnTimerNotification
  125. SYNOPSIS: Virtual callout invoked during WM_TIMER messages.
  126. ENTRY: tid - TIMER_ID of this timer.
  127. HISTORY:
  128. NarenG 25-May-1992 Created
  129. ********************************************************************/
  130. VOID GET_PRINTERS_DIALOG :: OnTimerNotification( TIMER_ID tid )
  131. {
  132. //
  133. // Bag-out if it's not our timer.
  134. //
  135. if( tid != _timer.QueryID() )
  136. {
  137. TIMER_CALLOUT :: OnTimerNotification( tid );
  138. return;
  139. }
  140. //
  141. // Advance the progress indicator.
  142. //
  143. _progress.Advance();
  144. //
  145. // No need to continue if we're just amusing the user.
  146. //
  147. if( --_nTickCounter > 0 )
  148. {
  149. return;
  150. }
  151. _nTickCounter = TIMER_MULT;
  152. //
  153. // Poll the thread doing the lookup to see if the operation is
  154. // either complete or continuing as expected.
  155. //
  156. DWORD dwRetCode = ::WaitForSingleObject( _hthreadNBPLookup, 0 );
  157. switch ( dwRetCode )
  158. {
  159. case WAIT_OBJECT_0:
  160. if( !::GetExitCodeThread( _hthreadNBPLookup, &dwRetCode ))
  161. {
  162. dwRetCode = ::GetLastError();
  163. }
  164. ::CloseHandle( _hthreadNBPLookup );
  165. if ( dwRetCode != NO_ERROR )
  166. {
  167. ::MsgPopup( this, dwRetCode );
  168. }
  169. Dismiss( TRUE );
  170. break;
  171. case WAIT_TIMEOUT:
  172. break;
  173. case WAIT_ABANDONED:
  174. default:
  175. ::CloseHandle( _hthreadNBPLookup );
  176. Dismiss( FALSE );
  177. break;
  178. }
  179. return;
  180. } // GET_PRINTERS_DIALOG :: OnTimerNotification
  181. BOOL GET_PRINTERS_DIALOG :: OnCancel ( VOID )
  182. {
  183. return ( FALSE );
  184. }
  185. BOOL GET_PRINTERS_DIALOG :: OnOK ( VOID )
  186. {
  187. return ( FALSE );
  188. }
  189. /*******************************************************************
  190. NAME: GET_PRINTERS_DIALOG::OnTimerNotification
  191. SYNOPSIS: Virtual callout invoked during WM_TIMER messages.
  192. ENTRY: tid - TIMER_ID of this timer.
  193. HISTORY:
  194. NarenG 25-May-1992 Created
  195. ********************************************************************/
  196. DWORD DoNBPLookup( LPVOID Parameter )
  197. {
  198. PNBP_LOOKUP_STRUCT pNbpLookup = (PNBP_LOOKUP_STRUCT)Parameter;
  199. CHAR chZone[MAX_ENTITY+1];
  200. PWSH_NBP_TUPLE pwshTuple;
  201. DWORD err;
  202. DWORD cbTuples;
  203. DWORD cPrinters = 100;
  204. DWORD cTuplesFound = 0;
  205. SOCKET hSocket = pNbpLookup->hSocket;
  206. ::wcstombs( chZone, pNbpLookup->wchZone, sizeof( chZone ) );
  207. cbTuples = ( sizeof( WSH_NBP_TUPLE ) * cPrinters );
  208. pwshTuple = (PWSH_NBP_TUPLE)::LocalAlloc( LPTR, cbTuples );
  209. if ( pwshTuple == NULL )
  210. {
  211. return( ERROR_NOT_ENOUGH_MEMORY );
  212. }
  213. do {
  214. err = ::WinSockNbpLookup(
  215. hSocket,
  216. chZone,
  217. ATALKMON_RELEASED_TYPE,
  218. "=",
  219. pwshTuple,
  220. cbTuples,
  221. &cTuplesFound );
  222. if ( err != NO_ERROR )
  223. {
  224. ::LocalFree( pwshTuple );
  225. break;
  226. }
  227. if ( cTuplesFound == cPrinters )
  228. {
  229. PWSH_NBP_TUPLE pTmpwshTuple = NULL;
  230. cPrinters *= 2;
  231. cbTuples = sizeof( WSH_NBP_TUPLE ) * cPrinters;
  232. pTmpwshTuple = (PWSH_NBP_TUPLE)::LocalReAlloc( pwshTuple,
  233. cbTuples,
  234. LMEM_MOVEABLE );
  235. if ( pTmpwshTuple == NULL )
  236. {
  237. err = ERROR_NOT_ENOUGH_MEMORY;
  238. break;
  239. }
  240. pwshTuple = pTmpwshTuple;
  241. }
  242. else
  243. {
  244. pNbpLookup->pPrinters = pwshTuple;
  245. pNbpLookup->cPrinters = cTuplesFound;
  246. break;
  247. }
  248. } while( TRUE );
  249. ::ExitThread( err );
  250. return err;
  251. }