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.

242 lines
7.8 KiB

  1. /***************************************************************************
  2. Name : NEGOT.C
  3. Comment : Capability handling and negotiation
  4. Revision Log
  5. Date Name Description
  6. -------- ----- ---------------------------------------------------------
  7. ***************************************************************************/
  8. #define USE_DEBUG_CONTEXT DEBUG_CONTEXT_T30_MAIN
  9. #include "prep.h"
  10. #include "protocol.h"
  11. #include "glbproto.h"
  12. BYTE BestEncoding[8] =
  13. {
  14. 0, // none (error)
  15. 1, // MH only
  16. 2, // MR only
  17. 2, // MR & MH
  18. 4, // MMR only
  19. 4, // MMR & MH
  20. 4, // MMR & MR
  21. 4 // MMR & MR & MH
  22. };
  23. BOOL NegotiateCaps(PThrdGlbl pTG)
  24. {
  25. USHORT Res;
  26. DEBUG_FUNCTION_NAME(_T("NegotiateCaps"));
  27. memset(&pTG->Inst.SendParams, 0, sizeof(pTG->Inst.SendParams));
  28. pTG->Inst.SendParams.bctype = SEND_PARAMS;
  29. pTG->Inst.SendParams.wBCSize = sizeof(BC);
  30. pTG->Inst.SendParams.wTotalSize = sizeof(BC);
  31. pTG->Inst.awfi.Encoding = (MH_DATA | MR_DATA);
  32. if (!pTG->SrcHiRes)
  33. {
  34. pTG->Inst.awfi.AwRes = AWRES_mm080_038;
  35. }
  36. else
  37. {
  38. pTG->Inst.awfi.AwRes = (AWRES_mm080_038 | AWRES_mm080_077 | AWRES_200_200 | AWRES_300_300);
  39. }
  40. /////// Encoding ///////
  41. if(!(pTG->Inst.SendParams.Fax.Encoding =
  42. BestEncoding[(pTG->Inst.awfi.Encoding)&pTG->Inst.RemoteRecvCaps.Fax.Encoding]))
  43. {
  44. // No matching Encoding not supported
  45. DebugPrintEx( DEBUG_ERR,
  46. "Negotiation failed: SendEnc %d CanRecodeTo %d"
  47. " RecvCapsEnc %d. No match",
  48. pTG->Inst.awfi.Encoding,
  49. pTG->Inst.awfi.Encoding,
  50. pTG->Inst.RemoteRecvCaps.Fax.Encoding);
  51. goto error;
  52. }
  53. /////// Width ///////
  54. // It is never set, so it always remains at 0 = WIDTH_A4
  55. pTG->Inst.RemoteRecvCaps.Fax.PageWidth &= 0x0F; // castrate all A5/A6 widths
  56. if(pTG->Inst.awfi.PageWidth> 0x0F)
  57. {
  58. // A5 or A6. Can quit or send as A4
  59. DebugPrintEx(DEBUG_ERR,"Negotiation failed: A5/A6 images not supported");
  60. goto error;
  61. }
  62. if(pTG->Inst.RemoteRecvCaps.Fax.PageWidth < pTG->Inst.awfi.PageWidth)
  63. {
  64. // or do some scaling
  65. DebugPrintEx(DEBUG_ERR,"Negotiation failed: Image too wide");
  66. goto error;
  67. }
  68. else
  69. {
  70. pTG->Inst.SendParams.Fax.PageWidth = pTG->Inst.awfi.PageWidth;
  71. }
  72. /////// Length ///////
  73. // It is never set, so it always remains at 0 = LENGTH_A4
  74. if(pTG->Inst.RemoteRecvCaps.Fax.PageLength < pTG->Inst.awfi.PageLength)
  75. {
  76. DebugPrintEx(DEBUG_ERR,"Negotiation failed: Image too long");
  77. goto error;
  78. }
  79. else
  80. {
  81. pTG->Inst.SendParams.Fax.PageLength = pTG->Inst.awfi.PageLength;
  82. }
  83. /////// Res ///////
  84. Res = (USHORT) (pTG->Inst.awfi.AwRes & pTG->Inst.RemoteRecvCaps.Fax.AwRes);
  85. if(Res) // send native
  86. {
  87. pTG->Inst.SendParams.Fax.AwRes = Res;
  88. }
  89. else
  90. {
  91. switch(pTG->Inst.awfi.AwRes)
  92. {
  93. case AWRES_mm160_154:
  94. if(AWRES_400_400 & pTG->Inst.RemoteRecvCaps.Fax.AwRes)
  95. {
  96. pTG->Inst.SendParams.Fax.AwRes = AWRES_400_400;
  97. }
  98. else
  99. {
  100. DebugPrintEx( DEBUG_ERR,
  101. "Negotiation failed: 16x15.4 image and"
  102. " no horiz scaling");
  103. goto error;
  104. }
  105. break;
  106. case AWRES_mm080_154:
  107. if(pTG->Inst.SendParams.Fax.Encoding == MMR_DATA)
  108. {
  109. DebugPrintEx( DEBUG_ERR,
  110. "Negotiation failed: 8x15.4 image and"
  111. " no vert scaling");
  112. goto error;
  113. }
  114. if(AWRES_mm080_077 & pTG->Inst.RemoteRecvCaps.Fax.AwRes)
  115. {
  116. pTG->Inst.SendParams.Fax.AwRes = AWRES_mm080_077;
  117. }
  118. else if(AWRES_200_200 & pTG->Inst.RemoteRecvCaps.Fax.AwRes)
  119. {
  120. pTG->Inst.SendParams.Fax.AwRes = AWRES_200_200;
  121. }
  122. else
  123. {
  124. pTG->Inst.SendParams.Fax.AwRes = AWRES_mm080_038;
  125. }
  126. break;
  127. case AWRES_mm080_077:
  128. if(AWRES_200_200 & pTG->Inst.RemoteRecvCaps.Fax.AwRes)
  129. {
  130. pTG->Inst.SendParams.Fax.AwRes = AWRES_200_200;
  131. }
  132. else if(pTG->Inst.SendParams.Fax.Encoding == MMR_DATA)
  133. {
  134. DebugPrintEx( DEBUG_ERR,
  135. "Negotiation failed: 8x7.7 image and"
  136. " no vert scaling");
  137. goto error;
  138. }
  139. else
  140. {
  141. pTG->Inst.SendParams.Fax.AwRes = AWRES_mm080_038;
  142. }
  143. break;
  144. case AWRES_400_400:
  145. if(AWRES_mm160_154 & pTG->Inst.RemoteRecvCaps.Fax.AwRes)
  146. {
  147. pTG->Inst.SendParams.Fax.AwRes = AWRES_mm160_154;
  148. }
  149. else
  150. {
  151. DebugPrintEx( DEBUG_ERR,
  152. "Negotiation failed: 400dpi image and"
  153. " no horiz scaling");
  154. goto error;
  155. }
  156. break;
  157. case AWRES_300_300:
  158. {
  159. DebugPrintEx( DEBUG_ERR,
  160. "Negotiation failed: 300dpi image and"
  161. " no non-integer scaling");
  162. goto error;
  163. }
  164. break;
  165. case AWRES_200_200:
  166. if(AWRES_mm080_077 & pTG->Inst.RemoteRecvCaps.Fax.AwRes)
  167. {
  168. pTG->Inst.SendParams.Fax.AwRes = AWRES_mm080_077;
  169. }
  170. else if(pTG->Inst.SendParams.Fax.Encoding == MMR_DATA)
  171. {
  172. DebugPrintEx( DEBUG_ERR,
  173. "Negotiation failed: 200dpi image and"
  174. " no vert scaling");
  175. goto error;
  176. }
  177. else
  178. {
  179. pTG->Inst.SendParams.Fax.AwRes = AWRES_mm080_038;
  180. }
  181. break;
  182. }
  183. }
  184. DebugPrintEx( DEBUG_MSG,
  185. "Negotiation Succeeded: Res=%d PageWidth=%d Len=%d"
  186. " Enc=%d",
  187. pTG->Inst.SendParams.Fax.AwRes,
  188. pTG->Inst.SendParams.Fax.PageWidth,
  189. pTG->Inst.SendParams.Fax.PageLength,
  190. pTG->Inst.SendParams.Fax.Encoding);
  191. return TRUE;
  192. error:
  193. return FALSE;
  194. }
  195. void InitCapsBC(PThrdGlbl pTG, LPBC lpbc, USHORT uSize, BCTYPE bctype)
  196. {
  197. DEBUG_FUNCTION_NAME(_T("InitCapsBC"));
  198. memset(lpbc, 0, uSize);
  199. lpbc->bctype = bctype;
  200. // They should be set. This code here is correct--arulm
  201. // +++ Following three lines are not in pcfax11
  202. lpbc->wBCSize = sizeof(BC);
  203. lpbc->wTotalSize = sizeof(BC);
  204. if (! pTG->SrcHiRes)
  205. {
  206. lpbc->Fax.AwRes = AWRES_mm080_038;
  207. }
  208. else
  209. {
  210. lpbc->Fax.AwRes = (AWRES_mm080_038 | AWRES_mm080_077 | AWRES_200_200 | AWRES_300_300);
  211. }
  212. lpbc->Fax.Encoding = (MH_DATA | MR_DATA);
  213. lpbc->Fax.PageWidth = WIDTH_A4; // can be upto A3
  214. lpbc->Fax.PageLength = LENGTH_UNLIMITED;
  215. }