Source code of Windows XP (NT5)
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.

309 lines
9.5 KiB

  1. /*++
  2. Copyright (c) 1991-92 Microsoft Corporation
  3. Module Name:
  4. altest.c
  5. Abstract:
  6. Test program for the Alerter service.
  7. Author:
  8. Rita Wong (ritaw) 17-July-1991
  9. Revision History:
  10. --*/
  11. #include <stdio.h>
  12. #include <string.h>
  13. #include <nt.h> // NT definitions
  14. #include <ntrtl.h> // NT runtime library definitions
  15. #include <nturtl.h>
  16. #include <windef.h> // Win32 type definitions
  17. #include <winbase.h> // Win32 base API prototypes
  18. #include <alertmsg.h> // ALERT_ equates.
  19. #include <lmcons.h> // LAN Manager common definitions
  20. #include <lmalert.h> // LAN Manager alert structures and APIs
  21. #include <lmerr.h> // LAN Manager network error definitions
  22. #include <netdebug.h> // FORMAT_ equates.
  23. #include <tstring.h> // Transitional string functions
  24. #include <conio.h>
  25. #include <time.h>
  26. //#include "lmspool.h"
  27. //
  28. // Global buffer
  29. //
  30. TCHAR VariableInfo[1024];
  31. //------------------------------------------------------------------------//
  32. VOID __cdecl
  33. main(
  34. int argc,
  35. char *argv[]
  36. )
  37. {
  38. NET_API_STATUS ApiStatus;
  39. PADMIN_OTHER_INFO Admin;
  40. PUSER_OTHER_INFO User;
  41. PPRINT_OTHER_INFO Print;
  42. LPWSTR pString;
  43. DWORD dwTime;
  44. DWORD VariableInfoSize;
  45. DWORD TmpSize; // Size of var portion plus 1 mergestring
  46. CHAR response;
  47. DWORD i;
  48. UNREFERENCED_PARAMETER(argc);
  49. UNREFERENCED_PARAMETER(argv);
  50. (VOID) printf( "AlTest: starting up...\n" );
  51. //
  52. // Alerter service should not crash if username and computer name are
  53. // not part of the mailslot message
  54. //
  55. User = (PUSER_OTHER_INFO) VariableInfo;
  56. User->alrtus_errcode = ALERT_CloseBehindError;
  57. User->alrtus_numstrings = 1;
  58. VariableInfoSize = sizeof(USER_OTHER_INFO);
  59. //
  60. // Write the mergestring into buffer. In the case of a close behind error
  61. // it is the name of the file which failed to close.
  62. //
  63. #define FILENAME TEXT("PLUTO.TXT")
  64. STRCPY((LPTSTR) ((DWORD) User + VariableInfoSize), FILENAME);
  65. VariableInfoSize += ((STRLEN(FILENAME) + 1) * sizeof(TCHAR));
  66. TmpSize = VariableInfoSize;
  67. //
  68. // This should not cause a message to be sent because neither the user
  69. // nor computer name is specified.
  70. //
  71. ApiStatus = NetAlertRaise(
  72. ALERT_USER_EVENT, // alert event name
  73. VariableInfo,
  74. VariableInfoSize );
  75. (VOID) printf( "AlTest 1(USER_ALERT): done NetAlertRaise, status=" FORMAT_API_STATUS
  76. ", expect=" FORMAT_API_STATUS ".\n",
  77. ApiStatus, ERROR_INVALID_PARAMETER );
  78. for (i = 1; i < 3; i ++) {
  79. VariableInfoSize = TmpSize;
  80. //
  81. // Now include username and computer name
  82. //
  83. #define USERNAME TEXT("DANL")
  84. #define COMPUTERNAME TEXT("danl1")
  85. STRCPY((LPTSTR) ((DWORD) User + VariableInfoSize), USERNAME);
  86. VariableInfoSize += ((STRLEN(USERNAME) + 1) * sizeof(TCHAR));
  87. //
  88. // Put a sequence number at the end of the username
  89. //
  90. //VariableInfo[STRLEN(USERNAME) - 1] = i + '1';
  91. STRCPY((LPTSTR) ((DWORD) User + VariableInfoSize), COMPUTERNAME);
  92. VariableInfoSize += ((STRLEN(COMPUTERNAME) + 1) * sizeof(TCHAR));
  93. //
  94. // User alert should be raised successfully.
  95. //
  96. ApiStatus = NetAlertRaiseEx(
  97. ALERT_USER_EVENT,
  98. VariableInfo,
  99. VariableInfoSize,
  100. TEXT("SERVER") ); // service name
  101. (VOID) printf( "AlTest 2(USER_ALERT): done NetAlertRaiseEx, status=" FORMAT_API_STATUS
  102. ".\n", ApiStatus );
  103. }
  104. //--------------------------
  105. // Raise an admin alert
  106. // (audit log full)
  107. //--------------------------
  108. Admin = (PADMIN_OTHER_INFO) VariableInfo;
  109. Admin->alrtad_errcode = ALERT_AuditLogFull;
  110. Admin->alrtad_numstrings = 0;
  111. ApiStatus = NetAlertRaiseEx(
  112. ALERT_ADMIN_EVENT,
  113. VariableInfo,
  114. sizeof(ADMIN_OTHER_INFO),
  115. TEXT("SERVER") ); // service name
  116. (VOID) printf( "AlTest 3(ADMIN_ALERT): done NetAlertRaiseEx(admin), status="
  117. FORMAT_API_STATUS ".\n", ApiStatus );
  118. //--------------------------
  119. // Raise an admin alert
  120. // (user-defined text)
  121. //--------------------------
  122. Admin = (PADMIN_OTHER_INFO) VariableInfo;
  123. Admin->alrtad_errcode = MAXULONG;
  124. Admin->alrtad_numstrings = 1;
  125. pString = (LPWSTR)((LPBYTE)VariableInfo+sizeof(ADMIN_OTHER_INFO));
  126. wcscpy(pString,L"This is a User-Defined Message");
  127. ApiStatus = NetAlertRaiseEx(
  128. ALERT_ADMIN_EVENT,
  129. VariableInfo,
  130. sizeof(ADMIN_OTHER_INFO)+WCSSIZE(pString),
  131. TEXT("SERVER") ); // service name
  132. (VOID) printf( "AlTest 3.5(ADMIN_ALERT): done NetAlertRaiseEx(admin), status="
  133. FORMAT_API_STATUS ".\n", ApiStatus );
  134. //---------------------------------
  135. // Raise an alert (NON-EX version)
  136. // (user-defined text)
  137. //---------------------------------
  138. {
  139. LPSTD_ALERT pStdAlert = (LPSTD_ALERT)VariableInfo;
  140. pStdAlert->alrt_timestamp = 1;
  141. wcscpy(pStdAlert->alrt_eventname,ALERT_ADMIN_EVENT);
  142. wcscpy(pStdAlert->alrt_servicename, L"Dan'sSvc");
  143. Admin = (LPADMIN_OTHER_INFO)((LPBYTE)VariableInfo + sizeof(STD_ALERT));
  144. pString = (LPWSTR)((LPBYTE)VariableInfo + sizeof(STD_ALERT) +
  145. sizeof(ADMIN_OTHER_INFO));
  146. Admin->alrtad_errcode = MAXULONG;
  147. Admin->alrtad_numstrings = 1;
  148. wcscpy(pString, L"Some User Data");
  149. VariableInfoSize = sizeof(STD_ALERT)+ sizeof(ADMIN_OTHER_INFO) +
  150. STRSIZE(pString);
  151. ApiStatus = NetAlertRaise(
  152. ALERT_ADMIN_EVENT, // alert event name
  153. VariableInfo,
  154. VariableInfoSize );
  155. (VOID) printf( "AlTest 3.6(ADMIN_ALERT): done NetAlertRaise(admin), status="
  156. FORMAT_API_STATUS ".\n", ApiStatus );
  157. }
  158. //---------------------------------
  159. // PRINT ALERT: PRINTER OFFLINE
  160. // (queued for printing)
  161. //---------------------------------
  162. time((time_t *)&dwTime);
  163. printf("time=%d\n",dwTime);
  164. Print = (PPRINT_OTHER_INFO) VariableInfo;
  165. Print->alrtpr_jobid = 626;
  166. Print->alrtpr_status = PRJOB_DESTOFFLINE;
  167. Print->alrtpr_submitted = dwTime;
  168. Print->alrtpr_size = 72496;
  169. //
  170. // All print Alerts have the PRINT_OTHER_INFO structure
  171. // followed by these same strings in this order...
  172. //
  173. VariableInfoSize = sizeof(PRINT_OTHER_INFO);
  174. // Computername
  175. STRCPY((LPTSTR) ((DWORD) Print + VariableInfoSize), TEXT("DANL2-SHAUNAB"));
  176. VariableInfoSize += ((STRLEN(TEXT("DANL2-SHAUNAB")) + 1) * sizeof(TCHAR));
  177. // username
  178. STRCPY((LPTSTR) ((DWORD) Print + VariableInfoSize), TEXT("DANL1"));
  179. VariableInfoSize += ((STRLEN(TEXT("DANL1")) + 1) * sizeof(TCHAR));
  180. // queuename
  181. STRCPY((LPTSTR) ((DWORD) Print + VariableInfoSize), TEXT("8/1154 CORPA 14DBDE"));
  182. VariableInfoSize += ((STRLEN(TEXT("8/1154 CORPA 14DBDE")) + 1) * sizeof(TCHAR));
  183. // destination
  184. STRCPY((LPTSTR) ((DWORD) Print + VariableInfoSize), TEXT("8/1154 CORPA 14DBDE(CORPA)"));
  185. VariableInfoSize += ((STRLEN(TEXT("8/1154 CORPA 14DBDE(CORPA)")) + 1) * sizeof(TCHAR));
  186. // status string
  187. STRCPY((LPTSTR) ((DWORD) Print + VariableInfoSize), TEXT("ERROR"));
  188. VariableInfoSize += ((STRLEN(TEXT("ERROR")) + 1) * sizeof(TCHAR));
  189. #ifdef REMOVE
  190. ApiStatus = NetAlertRaiseEx(
  191. ALERT_PRINT_EVENT,
  192. VariableInfo,
  193. VariableInfoSize,
  194. TEXT("SPOOLER") ); // service name
  195. (VOID) printf( "AlTest 4(PRINT_ALERT): done NetAlertRaiseEx(print), status="
  196. FORMAT_API_STATUS ".\n", ApiStatus );
  197. //
  198. // Wait for user reponse before continuing.
  199. //
  200. printf("continue?....\n");
  201. response = _getch();
  202. if ((response == 'n') || (response == 'N')) {
  203. return;
  204. }
  205. #endif //REMOVE
  206. //---------------------------------------
  207. // PRINT ALERT: JOB_COMPLETE
  208. //---------------------------------------
  209. Print->alrtpr_status = PRJOB_COMPLETE | PRJOB_QS_PRINTING;
  210. Print->alrtpr_jobid = 2434;
  211. ApiStatus = NetAlertRaiseEx(
  212. ALERT_PRINT_EVENT,
  213. VariableInfo,
  214. VariableInfoSize,
  215. TEXT("SPOOLER") ); // service name
  216. (VOID) printf( "AlTest 4.5(PRINT_ALERT): done NetAlertRaiseEx(print), status="
  217. FORMAT_API_STATUS ".\n", ApiStatus );
  218. //---------------------------------------
  219. // PRINT ALERT: NO PAPER - JOB_QUEUED
  220. //---------------------------------------
  221. Print->alrtpr_status = PRJOB_DESTNOPAPER;
  222. Print->alrtpr_jobid = 628;
  223. ApiStatus = NetAlertRaiseEx(
  224. ALERT_PRINT_EVENT,
  225. VariableInfo,
  226. VariableInfoSize,
  227. TEXT("SPOOLER") ); // service name
  228. (VOID) printf( "AlTest 5(PRINT_ALERT): done NetAlertRaiseEx(print), status="
  229. FORMAT_API_STATUS ".\n", ApiStatus );
  230. //------------------------------------------
  231. // PRINT ALERT: NO PAPER - JOB PRINTING
  232. //------------------------------------------
  233. Print->alrtpr_status = PRJOB_DESTNOPAPER | PRJOB_QS_PRINTING;
  234. Print->alrtpr_jobid = 629;
  235. ApiStatus = NetAlertRaiseEx(
  236. ALERT_PRINT_EVENT,
  237. VariableInfo,
  238. VariableInfoSize,
  239. TEXT("SPOOLER") ); // service name
  240. (VOID) printf( "AlTest 5(PRINT_ALERT): done NetAlertRaiseEx(print), status="
  241. FORMAT_API_STATUS ".\n", ApiStatus );
  242. }