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.

241 lines
8.9 KiB

  1. /****************************************************************************/
  2. // ntrcdisp.c
  3. //
  4. // RDP Trace helper functions.
  5. //
  6. // Copyright (C) 1997-2000 Microsoft Corporation
  7. /****************************************************************************/
  8. #include <precmpdd.h>
  9. #pragma hdrstop
  10. #ifdef DC_DEBUG
  11. #include <adcg.h>
  12. #include <atrcapi.h>
  13. #define DC_INCLUDE_DATA
  14. #include <ndddata.c>
  15. #undef DC_INCLUDE_DATA
  16. /****************************************************************************/
  17. /* TRCTraceLocal - internal function used by TRC_TraceLine */
  18. /****************************************************************************/
  19. void TRCTraceLocal(char *traceFormat, ...)
  20. {
  21. va_list ap;
  22. va_start(ap, traceFormat);
  23. EngDebugPrint("RDPDD:", traceFormat, ap);
  24. va_end(ap);
  25. }
  26. /****************************************************************************/
  27. /* TRC_TraceLine - trace a line */
  28. /****************************************************************************/
  29. void TRC_TraceLine(
  30. PVOID pWD,
  31. UINT32 traceClass,
  32. UINT32 traceType,
  33. char *traceString,
  34. char separator,
  35. unsigned lineNumber,
  36. char *funcName,
  37. char *fileName)
  38. {
  39. /************************************************************************/
  40. /* Check whether trace to WD is required and initialized */
  41. /************************************************************************/
  42. if (ddTrcToWD && pddShm)
  43. {
  44. ICA_TRACE_BUFFER trc;
  45. unsigned bytesReturned;
  46. trc.DataLength = sprintf(trc.Data,
  47. "RDPDD%c%p%c"TRC_FUNC_FMT"%c"TRC_LINE_FMT"%c%s\n",
  48. separator,
  49. pddTSWd,
  50. separator,
  51. TRC_FUNCNAME_LEN,
  52. TRC_FUNCNAME_LEN,
  53. funcName,
  54. separator,
  55. lineNumber,
  56. separator,
  57. traceString);
  58. trc.TraceClass = TC_DISPLAY;
  59. trc.TraceEnable = traceType;
  60. EngFileIoControl(ddWdHandle,
  61. IOCTL_ICA_CHANNEL_TRACE,
  62. &trc,
  63. sizeof(trc),
  64. NULL,
  65. 0,
  66. &bytesReturned);
  67. }
  68. else
  69. {
  70. /********************************************************************/
  71. /* Local-only tracing */
  72. /********************************************************************/
  73. TRCTraceLocal("%c"TRC_FUNC_FMT"%c"TRC_LINE_FMT"%c%s\n",
  74. separator,
  75. TRC_FUNCNAME_LEN,
  76. TRC_FUNCNAME_LEN,
  77. funcName,
  78. separator,
  79. lineNumber,
  80. separator,
  81. traceString);
  82. }
  83. }
  84. /****************************************************************************/
  85. /* TRCPrefixMatch */
  86. /* */
  87. /* Internal function to compare a component name to a prefix. */
  88. /* - assumes both are the same case */
  89. /* - returns */
  90. /* - TRUE if characters up to end of prefix match */
  91. /* - FALSE otherwise */
  92. /****************************************************************************/
  93. BOOL TRCPrefixMatch(char *cpnt, char *prefix)
  94. {
  95. while ((*cpnt == *prefix) && (*prefix != 0))
  96. {
  97. cpnt++;
  98. prefix++;
  99. }
  100. if (*prefix == 0)
  101. {
  102. return TRUE;
  103. }
  104. return FALSE;
  105. }
  106. /****************************************************************************/
  107. /* TRC_WillTrace */
  108. /****************************************************************************/
  109. BOOL TRC_WillTrace(
  110. UINT32 traceType,
  111. UINT32 traceClass,
  112. char *fileName,
  113. UINT32 line)
  114. {
  115. BOOL rc;
  116. int i;
  117. /************************************************************************/
  118. /* If tracing is not going to WD, OR SHM is not set up, check the local */
  119. /* trace level. No prefix checking is done in this case. */
  120. /************************************************************************/
  121. if (!ddTrcToWD || !pddShm)
  122. {
  123. rc = (ddTrcType & traceType);
  124. DC_QUIT;
  125. }
  126. /************************************************************************/
  127. /* Tracing is going to WD, AND SHM is set up. */
  128. /************************************************************************/
  129. /************************************************************************/
  130. /* Check whether this type and class are enabled. */
  131. /************************************************************************/
  132. if (!(traceType & pddShm->trc.TraceEnable) ||
  133. !(traceClass & pddShm->trc.TraceClass))
  134. {
  135. rc = FALSE;
  136. DC_QUIT;
  137. }
  138. /************************************************************************/
  139. /* If we get here, this line will be traced by WD. Now decide whether */
  140. /* we want to pass it to WD. */
  141. /************************************************************************/
  142. /************************************************************************/
  143. /* Always trace errors, irrespective of prefix. */
  144. /************************************************************************/
  145. if (traceType & TT_API4)
  146. {
  147. rc = TRUE;
  148. DC_QUIT;
  149. }
  150. /************************************************************************/
  151. /* Trace all lines if no prefixes are defined. */
  152. /************************************************************************/
  153. if (pddShm->trc.prefix[0].name[0] == 0)
  154. {
  155. rc = TRUE;
  156. DC_QUIT;
  157. }
  158. /************************************************************************/
  159. /* Some prefixes are defined - check whether this line matches any of */
  160. /* them. */
  161. /************************************************************************/
  162. for (i = 0; i < TRC_MAX_PREFIX; i++)
  163. {
  164. if (pddShm->trc.prefix[i].name[0] == 0)
  165. {
  166. /****************************************************************/
  167. /* End of list - break */
  168. /****************************************************************/
  169. break;
  170. }
  171. if (TRCPrefixMatch(&(fileName[1]), pddShm->trc.prefix[i].name))
  172. {
  173. /****************************************************************/
  174. /* Found matching filename - is there a line number range */
  175. /* specified? */
  176. /****************************************************************/
  177. if ((pddShm->trc.prefix[i].start == 0) &&
  178. (pddShm->trc.prefix[i].end == 0))
  179. {
  180. /************************************************************/
  181. /* No line number range - trace this line */
  182. /************************************************************/
  183. rc = TRUE;
  184. DC_QUIT;
  185. }
  186. /****************************************************************/
  187. /* There's a line number range - see if this line falls within */
  188. /* it. */
  189. /****************************************************************/
  190. if ((line >= pddShm->trc.prefix[i].start) &&
  191. (line <= pddShm->trc.prefix[i].end))
  192. {
  193. /************************************************************/
  194. /* Line within prefix range - trace it. */
  195. /************************************************************/
  196. rc = TRUE;
  197. DC_QUIT;
  198. }
  199. }
  200. } /* for */
  201. /************************************************************************/
  202. /* If we get here, we've searched the list of prefixes and failed to */
  203. /* find a match - don't trace the line */
  204. /************************************************************************/
  205. rc = FALSE;
  206. DC_EXIT_POINT:
  207. return rc;
  208. }
  209. #endif /* DC_DEBUG */