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.

5662 lines
170 KiB

  1. /*****************************************************************************\
  2. * MODULE: webipp.cxx
  3. *
  4. * This module contains routines which handle the encoding/decoding of data
  5. * sent across the HTTP wire to represent IPP packets.
  6. *
  7. * Public Interfaces
  8. * -----------------
  9. * WebIppRcvOpen : returns a handle to an ipp-request stream
  10. * WebIppRcvClose : closes the handle to the ipp-request stream
  11. * WebIppRcvData : converts (Ipp -> W32)
  12. * WebIppSndData : converts (W32 -> Ipp)
  13. * WebIppGetError : returns ipp-error if WebIppSndData/WebIppRcvData fails
  14. * WebIppLeToRsp : returns an ipp-error mapping for a win32 error
  15. * WebIppGetReqId : returns the request-id for the ipp-stream
  16. * WebIppGetUnsAttr : returns object with unsupported attribute strings
  17. * WebIppGetReqFlag : returns a flag of requested-attributes from ipp-stream
  18. * WebIppGetReqCp : returns codepage that ipp-stream requests
  19. * WebIppFreeMem : used to free pointers returned from WebIpp* routines
  20. *
  21. * Definintions:
  22. * ------------
  23. * Ipp - Denotes Ipp-Formatted information according to the IPP protocol.
  24. * W32 - Denotes win32 data that NT-Spooler understands.
  25. *
  26. * Copyright (C) 1996-1998 Microsoft Corporation
  27. * Copyright (C) 1996-1998 Hewlett Packard
  28. *
  29. * history:
  30. * 27-Oct-1997 <chriswil/v-chrisw> created.
  31. *
  32. \*****************************************************************************/
  33. #include "spllibp.hxx"
  34. #include <time.h>
  35. #include <sys\timeb.h>
  36. #include <wininet.h>
  37. #include <winsock.h>
  38. /*****************************************************************************\
  39. * Static Strings
  40. *
  41. \*****************************************************************************/
  42. static CONST TCHAR s_szJobLimit [] = TEXT("limit");
  43. static CONST TCHAR s_szJobName [] = TEXT("job-name");
  44. static CONST TCHAR s_szJobReqUser [] = TEXT("requesting-user-name");
  45. static CONST TCHAR s_szJobOrgUser [] = TEXT("job-originating-user-name");
  46. static CONST TCHAR s_szDocName [] = TEXT("document-name");
  47. static CONST TCHAR s_szJobId [] = TEXT("job-id");
  48. static CONST TCHAR s_szJobUri [] = TEXT("job-uri");
  49. static CONST TCHAR s_szJobState [] = TEXT("job-state");
  50. static CONST TCHAR s_szJobPri [] = TEXT("job-priority");
  51. static CONST TCHAR s_szJobKOctets [] = TEXT("job-k-octets");
  52. static CONST TCHAR s_szJobKOctetsProcess [] = TEXT("job-k-octets-processed");
  53. static CONST TCHAR s_szJobSheets [] = TEXT("job-media-sheets");
  54. static CONST TCHAR s_szJobPrtUri [] = TEXT("job-printer-uri");
  55. static CONST TCHAR s_szTimeAtCreation [] = TEXT("time-at-creation");
  56. static CONST TCHAR s_szJobSheetsCompleted[] = TEXT("job-media-sheets-completed");
  57. static CONST TCHAR s_szPrtUri [] = TEXT("printer-uri");
  58. static CONST TCHAR s_szPrtUriSupported [] = TEXT("printer-uri-supported");
  59. static CONST TCHAR s_szPrtUriSecurity [] = TEXT("uri-security-supported");
  60. static CONST TCHAR s_szPrtSecNone [] = TEXT("none");
  61. static CONST TCHAR s_szPrtOpsSupported [] = TEXT("operations-supported");
  62. static CONST TCHAR s_szPrtName [] = TEXT("printer-name");
  63. static CONST TCHAR s_szPrtState [] = TEXT("printer-state");
  64. static CONST TCHAR s_szPrtJobs [] = TEXT("queued-job-count");
  65. static CONST TCHAR s_szPrtMake [] = TEXT("printer-make-and-model");
  66. static CONST TCHAR s_szPrtAcceptingJobs [] = TEXT("printer-is-accepting-jobs");
  67. static CONST TCHAR s_szPrtUpTime [] = TEXT("printer-up-time");
  68. static CONST TCHAR s_szCharSetSupported [] = TEXT("charset-supported");
  69. static CONST TCHAR s_szCharSetConfigured [] = TEXT("charset-configured");
  70. static CONST TCHAR s_szNatLangConfigured [] = TEXT("natural-language-configured");
  71. static CONST TCHAR s_szNatLangSupported [] = TEXT("generated-natural-language-supported");
  72. static CONST TCHAR s_szUnknown [] = TEXT("unknown");
  73. static CONST TCHAR s_szWhichJobs [] = TEXT("which-jobs");
  74. static CONST TCHAR s_szCharSet [] = TEXT("attributes-charset");
  75. static CONST TCHAR s_szNaturalLanguage [] = TEXT("attributes-natural-language");
  76. static CONST TCHAR s_szReqAttr [] = TEXT("requested-attributes");
  77. static CONST TCHAR s_szUtf8 [] = TEXT("utf-8");
  78. static CONST TCHAR s_szUsAscii [] = TEXT("us-ascii");
  79. static CONST TCHAR s_szEnUS [] = TEXT("en-us");
  80. static CONST TCHAR s_szDocFormatDefault [] = TEXT("document-format-default");
  81. static CONST TCHAR s_szDocFormatSupported[] = TEXT("document-format-supported");
  82. static CONST TCHAR s_szStaMsg [] = TEXT("status-message");
  83. static CONST TCHAR s_szPdlOverride [] = TEXT("pdl-override-supported");
  84. static CONST TCHAR s_szNotAttempted [] = TEXT("not-attempted");
  85. static CONST TCHAR s_szDocFormat [] = TEXT("document-format");
  86. static CONST TCHAR s_szCompleted [] = TEXT("completed");
  87. static CONST TCHAR s_szNotCompleted [] = TEXT("not-completed");
  88. static CONST TCHAR s_szMimeTxtHtml [] = TEXT("text/html");
  89. static CONST TCHAR s_szMimeTxtPlain [] = TEXT("text/plain");
  90. static CONST TCHAR s_szMimePostScript [] = TEXT("application/postscript");
  91. static CONST TCHAR s_szMimePCL [] = TEXT("application/vnd.hppcl");
  92. static CONST TCHAR s_szMimeOctStream [] = TEXT("application/octet-stream");
  93. static CONST TCHAR s_szAll [] = TEXT("all");
  94. static CONST TCHAR s_szJobTemplate [] = TEXT("job-template");
  95. static CONST TCHAR s_szJobDescription [] = TEXT("job-description");
  96. static CONST TCHAR s_szPrtDescription [] = TEXT("printer-description");
  97. static CONST TCHAR s_szUnsupported [] = TEXT("unsupported");
  98. static CONST TCHAR s_szAtrFidelity [] = TEXT("ipp-attribute-fidelity");
  99. static CONST TCHAR s_szTrue [] = TEXT("true");
  100. static CONST TCHAR s_szFalse [] = TEXT("false");
  101. /*****************************************************************************\
  102. * Ipp Error-Mapping
  103. *
  104. * These tables define the mappings for Win32 LastErrors and Ipp-http errors.
  105. *
  106. \*****************************************************************************/
  107. static IPPERROR s_LEIpp[] = {
  108. IPPRSP_ERROR_400, ERROR_INVALID_DATA , TEXT("Client: (400) BadRequest") ,
  109. IPPRSP_ERROR_401, ERROR_ACCESS_DENIED , TEXT("Client: (401) Forbidden Access") ,
  110. IPPRSP_ERROR_402, ERROR_ACCESS_DENIED , TEXT("Client: (402) Not Authenticated") ,
  111. IPPRSP_ERROR_403, ERROR_ACCESS_DENIED , TEXT("Client: (403) Not Authorized") ,
  112. IPPRSP_ERROR_404, ERROR_INVALID_DATA , TEXT("Client: (404) Not Possible") ,
  113. IPPRSP_ERROR_405, ERROR_TIMEOUT , TEXT("Client: (405) Time Out") ,
  114. IPPRSP_ERROR_406, ERROR_INVALID_DATA , TEXT("Client: (406) Not Found") ,
  115. IPPRSP_ERROR_407, ERROR_INVALID_DATA , TEXT("Client: (407) Gone") ,
  116. IPPRSP_ERROR_408, ERROR_INVALID_DATA , TEXT("Client: (408) Entity Too Large") ,
  117. IPPRSP_ERROR_409, ERROR_INVALID_DATA , TEXT("Client: (409) Uri Too Long") ,
  118. IPPRSP_ERROR_40A, ERROR_INVALID_DATA , TEXT("Client: (40A) Document Format Not Supported"),
  119. IPPRSP_ERROR_40B, ERROR_INVALID_DATA , TEXT("Client: (40B) Attributes Not Supported") ,
  120. IPPRSP_ERROR_40C, ERROR_INVALID_DATA , TEXT("Client: (40C) Uri Scheme Not Supported") ,
  121. IPPRSP_ERROR_40D, ERROR_INVALID_DATA , TEXT("Client: (40D) Charset Not Supported") ,
  122. IPPRSP_ERROR_40E, ERROR_INVALID_DATA , TEXT("Client: (40E) Conflicting Attributes") ,
  123. IPPRSP_ERROR_500, ERROR_INVALID_DATA , TEXT("Server: (500) Internal Error") ,
  124. IPPRSP_ERROR_501, ERROR_INVALID_DATA , TEXT("Server: (501) Operation Not Supported") ,
  125. IPPRSP_ERROR_502, ERROR_NOT_READY , TEXT("Server: (502) Service Unavailable") ,
  126. IPPRSP_ERROR_503, ERROR_INVALID_DATA , TEXT("Server: (503) Version Not Supported") ,
  127. IPPRSP_ERROR_504, ERROR_NOT_READY , TEXT("Server: (504) Device Error") ,
  128. IPPRSP_ERROR_505, ERROR_OUTOFMEMORY , TEXT("Server: (505) Temporary Error") ,
  129. IPPRSP_ERROR_506, ERROR_INVALID_DATA , TEXT("Server: (506) Not Accepting Jobs") ,
  130. IPPRSP_ERROR_540, ERROR_LICENSE_QUOTA_EXCEEDED, TEXT("Server: (540) Too Many Users")
  131. };
  132. static IPPDEFERROR s_LEDef[] = {
  133. ERROR_INVALID_DATA , IPPRSP_ERROR_400,
  134. ERROR_ACCESS_DENIED , IPPRSP_ERROR_401,
  135. ERROR_INVALID_PARAMETER , IPPRSP_ERROR_404,
  136. ERROR_TIMEOUT , IPPRSP_ERROR_405,
  137. ERROR_NOT_READY , IPPRSP_ERROR_504,
  138. ERROR_OUTOFMEMORY , IPPRSP_ERROR_505,
  139. ERROR_LICENSE_QUOTA_EXCEEDED, IPPRSP_ERROR_540
  140. };
  141. /*****************************************************************************\
  142. * Request/Response attributes that are written to the ipp-stream.
  143. *
  144. *
  145. \*****************************************************************************/
  146. static IPPATTRX s_PJQ[] = { // PrtJob, ValJob Request
  147. IPP_TAG_CHR_URI , RA_PRNURI , IPP_ATR_OFFSET , s_szPrtUri , (LPVOID)offs(PIPPREQ_PRTJOB, pPrnUri) ,
  148. IPP_TAG_CHR_NAME, RA_JOBNAME, IPP_ATR_OFFSET , s_szJobName , (LPVOID)offs(PIPPREQ_PRTJOB, pDocument),
  149. IPP_TAG_CHR_NAME, RA_JOBUSER, IPP_ATR_OFFSET , s_szJobReqUser, (LPVOID)offs(PIPPREQ_PRTJOB, pUserName),
  150. IPP_TAG_DEL_JOB , 0 , IPP_ATR_TAG , NULL , (LPVOID)NULL
  151. };
  152. static IPPATTRX s_EJQ[] = { // GetJobs Request
  153. IPP_TAG_CHR_URI , RA_PRNURI , IPP_ATR_OFFSET , s_szPrtUri , (LPVOID)offs(PIPPREQ_ENUJOB, pPrnUri),
  154. IPP_TAG_INT_INTEGER, RA_JOBCOUNT , IPP_ATR_OFFSET , s_szJobLimit, (LPVOID)offs(PIPPREQ_ENUJOB, cJobs) ,
  155. IPP_TAG_CHR_KEYWORD, 0 , IPP_ATR_ABSOLUTE, s_szReqAttr , (LPVOID)s_szAll
  156. };
  157. static IPPATTRX s_SJQ[] = { // PauJob, CanJob, RsmJob, RstJob Request
  158. IPP_TAG_CHR_URI , 0, IPP_ATR_OFFSET, s_szPrtUri, (LPVOID)offs(PIPPREQ_SETJOB, pPrnUri),
  159. IPP_TAG_INT_INTEGER, 0, IPP_ATR_OFFSET, s_szJobId , (LPVOID)offs(PIPPREQ_SETJOB, idJob)
  160. };
  161. static IPPATTRX s_GJQ[] = { // GetJobAtr Request
  162. IPP_TAG_CHR_URI , 0, IPP_ATR_OFFSET, s_szPrtUri, (LPVOID)offs(PIPPREQ_GETJOB, pPrnUri),
  163. IPP_TAG_INT_INTEGER, 0, IPP_ATR_OFFSET, s_szJobId , (LPVOID)offs(PIPPREQ_GETJOB, idJob)
  164. };
  165. static IPPATTRX s_SPQ[] = { // PauPrn, CanPrn, RsmPrn, RstPrn Request
  166. IPP_TAG_CHR_URI , 0, IPP_ATR_OFFSET, s_szPrtUri , (LPVOID)offs(PIPPREQ_SETPRN, pPrnUri) ,
  167. IPP_TAG_CHR_NAME, 0, IPP_ATR_OFFSET, s_szJobReqUser, (LPVOID)offs(PIPPREQ_SETPRN, pUserName)
  168. };
  169. static IPPATTRX s_GPQ[] = { // GetPrnAtr Request
  170. IPP_TAG_CHR_URI, 0, IPP_ATR_OFFSET, s_szPrtUri, (LPVOID)offs(PIPPREQ_GETPRN, pPrnUri)
  171. };
  172. static IPPATTRX s_PJR[] = { // PrintJob Response
  173. IPP_TAG_DEL_JOB , 0 , IPP_ATR_TAG , NULL , (LPVOID)NULL ,
  174. IPP_TAG_INT_INTEGER, RA_JOBID , IPP_ATR_OFFSET , s_szJobId , (LPVOID)offs(PIPPRET_JOB, ji.ji2.JobId) ,
  175. IPP_TAG_INT_ENUM , RA_JOBSTATE , IPP_ATR_OFFSETCONV, s_szJobState , (LPVOID)offs(PIPPRET_JOB, ji.ji2.Status) ,
  176. IPP_TAG_INT_INTEGER, RA_JOBPRIORITY , IPP_ATR_OFFSET , s_szJobPri , (LPVOID)offs(PIPPRET_JOB, ji.ji2.Priority) ,
  177. IPP_TAG_INT_INTEGER, RA_JOBSIZE , IPP_ATR_OFFSETCONV, s_szJobKOctetsProcess , (LPVOID)offs(PIPPRET_JOB, ji.ji2.Size) ,
  178. IPP_TAG_INT_INTEGER, RA_SHEETSTOTAL , IPP_ATR_OFFSET , s_szJobSheets , (LPVOID)offs(PIPPRET_JOB, ji.ji2.TotalPages) ,
  179. IPP_TAG_INT_INTEGER, RA_SHEETSCOMPLETED, IPP_ATR_OFFSET , s_szJobSheetsCompleted, (LPVOID)offs(PIPPRET_JOB, ji.ji2.PagesPrinted),
  180. IPP_TAG_CHR_NAME , RA_JOBNAME , IPP_ATR_OFFSET , s_szJobName , (LPVOID)offs(PIPPRET_JOB, ji.ji2.pDocument) ,
  181. IPP_TAG_CHR_NAME , RA_JOBUSER , IPP_ATR_OFFSET , s_szJobOrgUser , (LPVOID)offs(PIPPRET_JOB, ji.ji2.pUserName) ,
  182. IPP_TAG_CHR_URI , RA_JOBURI , IPP_ATR_OFFSET , s_szJobUri , (LPVOID)offs(PIPPRET_JOB, ji.ipp.pJobUri) ,
  183. IPP_TAG_CHR_URI , RA_PRNURI , IPP_ATR_OFFSET , s_szJobPrtUri , (LPVOID)offs(PIPPRET_JOB, ji.ipp.pPrnUri)
  184. };
  185. static IPPATTRX s_EJR[] = { // GetJobs Response
  186. IPP_TAG_DEL_JOB , 0 , IPP_ATR_TAG , NULL , (LPVOID)NULL ,
  187. IPP_TAG_INT_INTEGER, RA_JOBID , IPP_ATR_OFFSET, s_szJobId , (LPVOID)offs(PIPPJI2, ji2.JobId) ,
  188. IPP_TAG_INT_ENUM , RA_JOBSTATE , IPP_ATR_OFFSET, s_szJobState , (LPVOID)offs(PIPPJI2, ji2.Status) ,
  189. IPP_TAG_INT_INTEGER, RA_JOBPRIORITY , IPP_ATR_OFFSET, s_szJobPri , (LPVOID)offs(PIPPJI2, ji2.Priority) ,
  190. IPP_TAG_INT_INTEGER, RA_JOBSIZE , IPP_ATR_OFFSET, s_szJobKOctetsProcess , (LPVOID)offs(PIPPJI2, ji2.Size) ,
  191. IPP_TAG_INT_INTEGER, RA_SHEETSTOTAL , IPP_ATR_OFFSET, s_szJobSheets , (LPVOID)offs(PIPPJI2, ji2.TotalPages) ,
  192. IPP_TAG_INT_INTEGER, RA_SHEETSCOMPLETED, IPP_ATR_OFFSET, s_szJobSheetsCompleted, (LPVOID)offs(PIPPJI2, ji2.PagesPrinted),
  193. IPP_TAG_INT_INTEGER, RA_TIMEATCREATION , IPP_ATR_OFFSET, s_szTimeAtCreation , (LPVOID)offs(PIPPJI2, ji2.Submitted) ,
  194. IPP_TAG_CHR_NAME , RA_JOBNAME , IPP_ATR_OFFSET, s_szJobName , (LPVOID)offs(PIPPJI2, ji2.pDocument) ,
  195. IPP_TAG_CHR_NAME , RA_JOBUSER , IPP_ATR_OFFSET, s_szJobOrgUser , (LPVOID)offs(PIPPJI2, ji2.pUserName) ,
  196. IPP_TAG_CHR_URI , RA_JOBURI , IPP_ATR_OFFSET, s_szJobUri , (LPVOID)offs(PIPPJI2, ipp.pJobUri) ,
  197. IPP_TAG_CHR_URI , RA_PRNURI , IPP_ATR_OFFSET, s_szJobPrtUri , (LPVOID)offs(PIPPJI2, ipp.pPrnUri)
  198. };
  199. static IPPATTRX s_GPR[] = { // GetPrnAtr Response
  200. IPP_TAG_DEL_PRINTER, 0 , IPP_ATR_TAG , NULL , (LPVOID)NULL ,
  201. IPP_TAG_INT_ENUM , RA_PRNSTATE , IPP_ATR_OFFSETCONV, s_szPrtState , (LPVOID)offs(PIPPRET_PRN, pi.pi2.Status) ,
  202. IPP_TAG_INT_INTEGER, RA_JOBCOUNT , IPP_ATR_OFFSET , s_szPrtJobs , (LPVOID)offs(PIPPRET_PRN, pi.pi2.cJobs) ,
  203. IPP_TAG_CHR_URI , RA_URISUPPORTED , IPP_ATR_OFFSET , s_szPrtUriSupported , (LPVOID)offs(PIPPRET_PRN, pi.ipp.pPrnUri) ,
  204. IPP_TAG_CHR_KEYWORD, RA_URISECURITY , IPP_ATR_ABSOLUTE , s_szPrtUriSecurity , (LPVOID)s_szPrtSecNone ,
  205. IPP_TAG_CHR_NAME , RA_PRNNAME , IPP_ATR_OFFSET , s_szPrtName , (LPVOID)offs(PIPPRET_PRN, pi.pi2.pPrinterName),
  206. IPP_TAG_CHR_TEXT , RA_PRNMAKE , IPP_ATR_OFFSET , s_szPrtMake , (LPVOID)offs(PIPPRET_PRN, pi.pi2.pDriverName) ,
  207. IPP_TAG_INT_BOOLEAN, RA_ACCEPTINGJOBS , IPP_ATR_ABSOLUTE , s_szPrtAcceptingJobs , (LPVOID)TRUE ,
  208. IPP_TAG_CHR_CHARSET, RA_CHRSETCONFIGURED, IPP_ATR_ABSOLUTE , s_szCharSetConfigured , (LPVOID)s_szUtf8 ,
  209. IPP_TAG_CHR_CHARSET, RA_CHRSETSUPPORTED , IPP_ATR_ABSOLUTE , s_szCharSetSupported , (LPVOID)s_szUtf8 ,
  210. IPP_TAG_CHR_CHARSET, 0 , IPP_ATR_ABSOLUTE , NULL , (LPVOID)s_szUsAscii ,
  211. IPP_TAG_CHR_NATURAL, RA_NATLNGCONFIGURED, IPP_ATR_ABSOLUTE , s_szNatLangConfigured , (LPVOID)s_szEnUS ,
  212. IPP_TAG_CHR_NATURAL, RA_NATLNGSUPPORTED , IPP_ATR_ABSOLUTE , s_szNatLangSupported , (LPVOID)s_szEnUS ,
  213. IPP_TAG_CHR_MEDIA , RA_DOCDEFAULT , IPP_ATR_ABSOLUTE , s_szDocFormatDefault , (LPVOID)s_szMimeOctStream ,
  214. IPP_TAG_CHR_MEDIA , RA_DOCSUPPORTED , IPP_ATR_ABSOLUTE , s_szDocFormatSupported, (LPVOID)s_szMimeOctStream ,
  215. IPP_TAG_CHR_KEYWORD, RA_PDLOVERRIDE , IPP_ATR_ABSOLUTE , s_szPdlOverride , (LPVOID)s_szNotAttempted ,
  216. IPP_TAG_INT_INTEGER, RA_UPTIME , IPP_ATR_ABSOLUTE , s_szPrtUpTime , (LPVOID)1 ,
  217. IPP_TAG_INT_ENUM , RA_OPSSUPPORTED , IPP_ATR_ABSOLUTE , s_szPrtOpsSupported , (LPVOID)IPP_REQ_PRINTJOB ,
  218. IPP_TAG_INT_ENUM , 0 , IPP_ATR_ABSOLUTE , NULL , (LPVOID)IPP_REQ_VALIDATEJOB ,
  219. IPP_TAG_INT_ENUM , 0 , IPP_ATR_ABSOLUTE , NULL , (LPVOID)IPP_REQ_CANCELJOB ,
  220. IPP_TAG_INT_ENUM , 0 , IPP_ATR_ABSOLUTE , NULL , (LPVOID)IPP_REQ_GETJOB ,
  221. IPP_TAG_INT_ENUM , 0 , IPP_ATR_ABSOLUTE , NULL , (LPVOID)IPP_REQ_ENUJOB ,
  222. IPP_TAG_INT_ENUM , 0 , IPP_ATR_ABSOLUTE , NULL , (LPVOID)IPP_REQ_GETPRN ,
  223. IPP_TAG_INT_ENUM , 0 , IPP_ATR_ABSOLUTE , NULL , (LPVOID)IPP_REQ_PAUSEJOB ,
  224. IPP_TAG_INT_ENUM , 0 , IPP_ATR_ABSOLUTE , NULL , (LPVOID)IPP_REQ_RESUMEJOB ,
  225. IPP_TAG_INT_ENUM , 0 , IPP_ATR_ABSOLUTE , NULL , (LPVOID)IPP_REQ_RESTARTJOB ,
  226. IPP_TAG_INT_ENUM , 0 , IPP_ATR_ABSOLUTE , NULL , (LPVOID)IPP_REQ_PAUSEPRN ,
  227. IPP_TAG_INT_ENUM , 0 , IPP_ATR_ABSOLUTE , NULL , (LPVOID)IPP_REQ_RESUMEPRN ,
  228. IPP_TAG_INT_ENUM , 0 , IPP_ATR_ABSOLUTE , NULL , (LPVOID)IPP_REQ_CANCELPRN
  229. };
  230. /*****************************************************************************\
  231. * Request/Response string-mappings.
  232. *
  233. *
  234. \*****************************************************************************/
  235. static FLGSTR s_ReqRspStr[] = {
  236. RA_JOBUSER, s_szJobReqUser,
  237. RA_JOBSIZE, s_szJobKOctets
  238. };
  239. /*****************************************************************************\
  240. * Receive/Response group forms.
  241. *
  242. * These tables defines the order and layout of ipp group tags.
  243. *
  244. \*****************************************************************************/
  245. static BYTE s_FormA[] = {
  246. IPP_TAG_DEL_OPERATION | IPP_MANDITORY,
  247. IPP_TAG_DEL_JOB | IPP_OPTIONAL,
  248. IPP_TAG_DEL_DATA | IPP_MANDITORY,
  249. 0
  250. };
  251. static BYTE s_FormB[] = {
  252. IPP_TAG_DEL_OPERATION | IPP_MANDITORY,
  253. IPP_TAG_DEL_DATA | IPP_MANDITORY,
  254. 0
  255. };
  256. static BYTE s_FormC[] = {
  257. IPP_TAG_DEL_OPERATION | IPP_MANDITORY,
  258. IPP_TAG_DEL_UNSUPPORTED | IPP_OPTIONAL ,
  259. IPP_TAG_DEL_JOB | IPP_OPTIONAL ,
  260. IPP_TAG_DEL_DATA | IPP_MANDITORY,
  261. 0
  262. };
  263. static BYTE s_FormD[] = {
  264. IPP_TAG_DEL_OPERATION | IPP_MANDITORY,
  265. IPP_TAG_DEL_UNSUPPORTED | IPP_OPTIONAL ,
  266. IPP_TAG_DEL_PRINTER | IPP_OPTIONAL ,
  267. IPP_TAG_DEL_DATA | IPP_MANDITORY,
  268. 0
  269. };
  270. static BYTE s_FormE[] = {
  271. IPP_TAG_DEL_OPERATION | IPP_MANDITORY,
  272. IPP_TAG_DEL_UNSUPPORTED | IPP_OPTIONAL ,
  273. IPP_TAG_DEL_DATA | IPP_MANDITORY,
  274. 0
  275. };
  276. static BYTE s_FormF[] = {
  277. IPP_TAG_DEL_OPERATION | IPP_MANDITORY ,
  278. IPP_TAG_DEL_UNSUPPORTED | IPP_OPTIONAL ,
  279. IPP_TAG_DEL_JOB | IPP_OPTIONAL | IPP_MULTIPLE,
  280. IPP_TAG_DEL_DATA | IPP_MANDITORY ,
  281. 0
  282. };
  283. /*****************************************************************************\
  284. * Structure Offsets
  285. *
  286. *
  287. \*****************************************************************************/
  288. static DWORD s_IPPJI2Offs[] = {
  289. offs(LPIPPJI2, ji2.pPrinterName),
  290. offs(LPIPPJI2, ji2.pMachineName),
  291. offs(LPIPPJI2, ji2.pUserName),
  292. offs(LPIPPJI2, ji2.pDocument),
  293. offs(LPIPPJI2, ji2.pNotifyName),
  294. offs(LPIPPJI2, ji2.pDatatype),
  295. offs(LPIPPJI2, ji2.pPrintProcessor),
  296. offs(LPIPPJI2, ji2.pParameters),
  297. offs(LPIPPJI2, ji2.pDriverName),
  298. offs(LPIPPJI2, ji2.pDevMode),
  299. offs(LPIPPJI2, ji2.pStatus),
  300. offs(LPIPPJI2, ji2.pSecurityDescriptor),
  301. offs(LPIPPJI2, ipp.pPrnUri),
  302. offs(LPIPPJI2, ipp.pJobUri),
  303. 0xFFFFFFFF
  304. };
  305. static DWORD s_IPPPI2Offs[] = {
  306. offs(LPIPPPI2, pi2.pServerName),
  307. offs(LPIPPPI2, pi2.pPrinterName),
  308. offs(LPIPPPI2, pi2.pShareName),
  309. offs(LPIPPPI2, pi2.pPortName),
  310. offs(LPIPPPI2, pi2.pDriverName),
  311. offs(LPIPPPI2, pi2.pComment),
  312. offs(LPIPPPI2, pi2.pLocation),
  313. offs(LPIPPPI2, pi2.pDevMode),
  314. offs(LPIPPPI2, pi2.pSepFile),
  315. offs(LPIPPPI2, pi2.pPrintProcessor),
  316. offs(LPIPPPI2, pi2.pDatatype),
  317. offs(LPIPPPI2, pi2.pParameters),
  318. offs(LPIPPPI2, pi2.pSecurityDescriptor),
  319. offs(LPIPPPI2, ipp.pPrnUri),
  320. offs(LPIPPPI2, ipp.pUsrName),
  321. 0xFFFFFFFF
  322. };
  323. static DWORD s_JI2Off[] = {
  324. offs(LPJOB_INFO_2, pPrinterName),
  325. offs(LPJOB_INFO_2, pMachineName),
  326. offs(LPJOB_INFO_2, pUserName),
  327. offs(LPJOB_INFO_2, pDocument),
  328. offs(LPJOB_INFO_2, pNotifyName),
  329. offs(LPJOB_INFO_2, pDatatype),
  330. offs(LPJOB_INFO_2, pPrintProcessor),
  331. offs(LPJOB_INFO_2, pParameters),
  332. offs(LPJOB_INFO_2, pDriverName),
  333. // Do not include DEVMODE
  334. offs(LPJOB_INFO_2, pStatus),
  335. // Do not include SECURITY-DESCRIPTOR
  336. 0xFFFFFFFF
  337. };
  338. static DWORD s_PI2Off[] = {
  339. offs(LPPRINTER_INFO_2, pServerName),
  340. offs(LPPRINTER_INFO_2, pPrinterName),
  341. offs(LPPRINTER_INFO_2, pShareName),
  342. offs(LPPRINTER_INFO_2, pPortName),
  343. offs(LPPRINTER_INFO_2, pDriverName),
  344. offs(LPPRINTER_INFO_2, pComment),
  345. offs(LPPRINTER_INFO_2, pLocation),
  346. // Do not include DEVMODE
  347. offs(LPPRINTER_INFO_2, pSepFile),
  348. offs(LPPRINTER_INFO_2, pPrintProcessor),
  349. offs(LPPRINTER_INFO_2, pDatatype),
  350. offs(LPPRINTER_INFO_2, pParameters),
  351. // Do not include SECURITY-DESCRIPTOR
  352. 0xFFFFFFFF
  353. };
  354. static DWORD s_IPJOff[] = {
  355. offs(LPJOB_INFO_IPP, pPrnUri),
  356. offs(LPJOB_INFO_IPP, pJobUri),
  357. 0xFFFFFFFF
  358. };
  359. static DWORD s_IPPOff[] = {
  360. offs(LPPRINTER_INFO_IPP, pPrnUri) ,
  361. offs(LPPRINTER_INFO_IPP, pUsrName),
  362. 0xFFFFFFFF
  363. };
  364. /*****************************************************************************\
  365. * ipp_SetReq (Local Routine)
  366. *
  367. * Sets a bit in the request flag. If the index (upper 4 bits) is greater
  368. * than 7, then we use this as a special enum flag.
  369. *
  370. \*****************************************************************************/
  371. VOID x_SetReq(
  372. PDWORD pfReq,
  373. DWORD fSet)
  374. {
  375. DWORD idz;
  376. PDWORD pFlg;
  377. DWORD cFlg = 0;
  378. DWORD idx = ((fSet >> 28) & 0x0000000F);
  379. static DWORD s_fReqEnu[] = {
  380. RA_JOBID,
  381. RA_JOBURI
  382. };
  383. static DWORD s_fJobTmp[] = {
  384. RA_JOBPRIORITY ,
  385. RA_SHEETSTOTAL ,
  386. RA_SHEETSCOMPLETED
  387. };
  388. static DWORD s_fJobDsc[] = {
  389. RA_JOBURI ,
  390. RA_JOBID ,
  391. RA_JOBNAME ,
  392. RA_JOBUSER ,
  393. RA_JOBSTATE ,
  394. RA_JOBSTATE_REASONS,
  395. RA_JOBSTATE_MESSAGE,
  396. RA_JOBSIZE
  397. };
  398. static DWORD s_fPrtDsc[] = {
  399. RA_URISUPPORTED ,
  400. RA_URISECURITY ,
  401. RA_PRNNAME ,
  402. RA_PRNMAKE ,
  403. RA_PRNSTATE ,
  404. RA_OPSSUPPORTED ,
  405. RA_CHRSETCONFIGURED,
  406. RA_CHRSETSUPPORTED ,
  407. RA_NATLNGCONFIGURED,
  408. RA_NATLNGSUPPORTED ,
  409. RA_DOCDEFAULT ,
  410. RA_DOCSUPPORTED ,
  411. RA_ACCEPTINGJOBS ,
  412. RA_JOBCOUNT ,
  413. RA_PDLOVERRIDE ,
  414. RA_UPTIME
  415. };
  416. switch (idx) {
  417. case IPP_REQALL_IDX:
  418. pfReq[0] = 0x0FFFFFFF;
  419. pfReq[1] = 0x0FFFFFFF;
  420. break;
  421. case IPP_REQCLEAR_IDX:
  422. pfReq[0] = 0x00000000;
  423. pfReq[1] = 0x00000000;
  424. break;
  425. case IPP_REQENU_IDX:
  426. pFlg = s_fReqEnu;
  427. cFlg = sizeof(s_fReqEnu) / sizeof(s_fReqEnu[0]);
  428. break;
  429. case IPP_REQJDSC_IDX:
  430. pFlg = s_fJobDsc;
  431. cFlg = sizeof(s_fJobDsc) / sizeof(s_fJobDsc[0]);
  432. break;
  433. case IPP_REQJTMP_IDX:
  434. pFlg = s_fJobTmp;
  435. cFlg = sizeof(s_fJobTmp) / sizeof(s_fJobTmp[0]);
  436. break;
  437. case IPP_REQPDSC_IDX:
  438. pFlg = s_fPrtDsc;
  439. cFlg = sizeof(s_fPrtDsc) / sizeof(s_fPrtDsc[0]);
  440. break;
  441. }
  442. if (idx >= IPP_REQALL_IDX) {
  443. for (idz = 0; idz < cFlg; idz++) {
  444. idx = ((pFlg[idz] >> 28) & 0x0000000F);
  445. pfReq[idx] |= (pFlg[idz] & 0x0FFFFFFF);
  446. }
  447. } else {
  448. pfReq[idx] |= (fSet & 0x0FFFFFFF);
  449. }
  450. }
  451. /*****************************************************************************\
  452. * ipp_ChkReq (Local Routine)
  453. *
  454. * Checks to se if bit-flag is set in the request flag.
  455. *
  456. \*****************************************************************************/
  457. BOOL x_ChkReq(
  458. PDWORD pfReq,
  459. DWORD fChk)
  460. {
  461. DWORD idx = ((fChk >> 28) & 0x0000000F);
  462. return pfReq[idx] & (fChk & 0x0FFFFFFF);
  463. }
  464. /*****************************************************************************\
  465. * ipp_CopyAligned (Local Routine)
  466. *
  467. * Copies memory to an aligned-buffer.
  468. *
  469. \*****************************************************************************/
  470. inline LPBYTE ipp_CopyAligned(
  471. LPBYTE lpDta,
  472. DWORD cbDta)
  473. {
  474. LPBYTE lpAln;
  475. if (lpAln = (LPBYTE)webAlloc(cbDta))
  476. CopyMemory((LPVOID)lpAln, lpDta, cbDta);
  477. return lpAln;
  478. }
  479. /*****************************************************************************\
  480. * ipp_WriteData (Local Routine)
  481. *
  482. * Sets the data in an IPP-Data-Stream. This adjusts the pointer to the
  483. * next byte-location in the stream.
  484. *
  485. * NOTE: Make sure that cbData is never greater than size of lplpPtr in bytes.
  486. *
  487. \*****************************************************************************/
  488. inline VOID ipp_WriteData(
  489. LPBYTE* lplpPtr,
  490. LPVOID lpData,
  491. DWORD cbData)
  492. {
  493. CopyMemory(*lplpPtr, lpData, cbData);
  494. *lplpPtr += cbData;
  495. }
  496. /*****************************************************************************\
  497. * ipp_WriteByte (Local Routine)
  498. *
  499. * Write out a byte to the stream.
  500. *
  501. \*****************************************************************************/
  502. inline VOID ipp_WriteByte(
  503. LPBYTE* lplpIppPtr,
  504. BYTE bVal)
  505. {
  506. ipp_WriteData(lplpIppPtr, (LPVOID)&bVal, IPP_SIZEOFTAG);
  507. }
  508. /*****************************************************************************\
  509. * ipp_ReadByte (Local Routine)
  510. *
  511. * Read a byte from the stream.
  512. *
  513. \*****************************************************************************/
  514. inline BYTE ipp_ReadByte(
  515. LPBYTE lpbPtr,
  516. DWORD cbIdx)
  517. {
  518. return (*(BYTE *)((LPBYTE)(lpbPtr) + cbIdx));
  519. }
  520. /*****************************************************************************\
  521. * ipp_WriteWord (Local Routine)
  522. *
  523. * Write out a word to the stream.
  524. *
  525. \*****************************************************************************/
  526. inline VOID ipp_WriteWord(
  527. LPBYTE* lplpIppPtr,
  528. WORD wVal)
  529. {
  530. WORD wNBW = htons (wVal);
  531. ipp_WriteData(lplpIppPtr, (LPVOID)&wNBW, IPP_SIZEOFLEN);
  532. }
  533. /*****************************************************************************\
  534. * ipp_ReadWord (Local Routine)
  535. *
  536. * Read a word from the stream.
  537. *
  538. \*****************************************************************************/
  539. inline WORD ipp_ReadWord(
  540. LPBYTE lpbPtr,
  541. DWORD cbIdx)
  542. {
  543. WORD wVal = (*(WORD UNALIGNED *)((LPBYTE)(lpbPtr) + cbIdx));
  544. return ntohs (wVal);
  545. }
  546. /*****************************************************************************\
  547. * ipp_WriteDWord (Local Routine)
  548. *
  549. * Write out a dword to the stream.
  550. *
  551. \*****************************************************************************/
  552. inline VOID ipp_WriteDWord(
  553. LPBYTE* lplpIppPtr,
  554. DWORD dwVal)
  555. {
  556. DWORD dwNBDW = htonl(dwVal);
  557. ipp_WriteData(lplpIppPtr, (LPVOID)&dwNBDW, IPP_SIZEOFINT);
  558. }
  559. /*****************************************************************************\
  560. * ipp_ReadDWord (Local Routine)
  561. *
  562. * Read a dword from the stream.
  563. *
  564. \*****************************************************************************/
  565. inline DWORD ipp_ReadDWord(
  566. LPBYTE lpbPtr,
  567. DWORD cbIdx)
  568. {
  569. DWORD dwVal = (*(DWORD UNALIGNED *)((LPBYTE)(lpbPtr) + cbIdx));
  570. return ntohl(dwVal);
  571. }
  572. /*****************************************************************************\
  573. * ipp_MapReqToJobCmd (Local Routine)
  574. *
  575. * Returns a job-command from a request.
  576. *
  577. \*****************************************************************************/
  578. inline DWORD ipp_MapReqToJobCmd(
  579. WORD wReq)
  580. {
  581. if (wReq == IPP_REQ_CANCELJOB)
  582. return JOB_CONTROL_DELETE;
  583. if (wReq == IPP_REQ_PAUSEJOB)
  584. return JOB_CONTROL_PAUSE;
  585. if (wReq == IPP_REQ_RESUMEJOB)
  586. return JOB_CONTROL_RESUME;
  587. if (wReq == IPP_REQ_RESTARTJOB)
  588. return JOB_CONTROL_RESTART;
  589. return 0;
  590. }
  591. /*****************************************************************************\
  592. * ipp_MapReqToPrnCmd (Local Routine)
  593. *
  594. * Returns a printer-command from a request.
  595. *
  596. \*****************************************************************************/
  597. inline DWORD ipp_MapReqToPrnCmd(
  598. WORD wReq)
  599. {
  600. if (wReq == IPP_REQ_RESUMEPRN)
  601. return PRINTER_CONTROL_RESUME;
  602. if (wReq == IPP_REQ_PAUSEPRN)
  603. return PRINTER_CONTROL_PAUSE;
  604. if (wReq == IPP_REQ_CANCELPRN)
  605. return PRINTER_CONTROL_PURGE;
  606. return 0;
  607. }
  608. /*****************************************************************************\
  609. * ipp_W32ToIppJobPriority (Local Routine)
  610. *
  611. * Maps a JOB_INFO_2 priority to an IPP priority.
  612. *
  613. \*****************************************************************************/
  614. inline DWORD ipp_W32ToIppJobPriority(
  615. DWORD dwPriority)
  616. {
  617. return dwPriority;
  618. }
  619. /*****************************************************************************\
  620. * ipp_IppToW32JobPriority (Local Routine)
  621. *
  622. * Maps an IPP job priority to a JOB_INFO_2 priority.
  623. *
  624. \*****************************************************************************/
  625. inline DWORD ipp_IppToW32JobPriority(
  626. DWORD dwPriority)
  627. {
  628. return dwPriority;
  629. }
  630. /*****************************************************************************\
  631. * ipp_W32ToIppJobSize (Local Routine)
  632. *
  633. * Maps a JOB_INFO_2 size to an IPP size.
  634. *
  635. \*****************************************************************************/
  636. inline DWORD ipp_W32ToIppJobSize(
  637. DWORD dwSize)
  638. {
  639. return (1023 + dwSize) / 1024;
  640. }
  641. /*****************************************************************************\
  642. * ipp_IppToW32JobSize (Local Routine)
  643. *
  644. * Maps an IPP job size to a JOB_INFO_2 size.
  645. *
  646. \*****************************************************************************/
  647. inline DWORD ipp_IppToW32JobSize(
  648. DWORD dwSize)
  649. {
  650. return dwSize * 1024;
  651. }
  652. /*****************************************************************************\
  653. * ipp_W32ToIppJobTotalPages (Local Routine)
  654. *
  655. * Maps a JOB_INFO_2 TotalPages to an IPP priority.
  656. *
  657. \*****************************************************************************/
  658. inline DWORD ipp_W32ToIppJobTotalPages(
  659. DWORD dwTotalPages)
  660. {
  661. return dwTotalPages;
  662. }
  663. /*****************************************************************************\
  664. * ipp_IppToW32JobTotalPages (Local Routine)
  665. *
  666. * Maps an IPP TotalPages to a JOB_INFO_2 priority.
  667. *
  668. \*****************************************************************************/
  669. inline DWORD ipp_IppToW32JobTotalPages(
  670. DWORD dwTotalPages)
  671. {
  672. return dwTotalPages;
  673. }
  674. /*****************************************************************************\
  675. * ipp_W32ToIppJobPagesPrinted (Local Routine)
  676. *
  677. * Maps a JOB_INFO_2 PagesPrinted to an IPP priority.
  678. *
  679. \*****************************************************************************/
  680. inline DWORD ipp_W32ToIppJobPagesPrinted(
  681. DWORD dwPagesPrinted)
  682. {
  683. return dwPagesPrinted;
  684. }
  685. /*****************************************************************************\
  686. * ipp_IppToW32JobPagesPrinted (Local Routine)
  687. *
  688. * Maps an IPP PagesPrinted to a JOB_INFO_2 priority.
  689. *
  690. \*****************************************************************************/
  691. inline DWORD ipp_IppToW32JobPagesPrinted(
  692. DWORD dwPagesPrinted)
  693. {
  694. return dwPagesPrinted;
  695. }
  696. /*****************************************************************************\
  697. * ipp_W32ToIppJobState (Local Routine)
  698. *
  699. * Maps a Job-Status flag to that of an IPP State flag.
  700. *
  701. \*****************************************************************************/
  702. DWORD ipp_W32ToIppJobState(
  703. DWORD dwState)
  704. {
  705. if (dwState & (JOB_STATUS_OFFLINE | JOB_STATUS_PAPEROUT | JOB_STATUS_ERROR | JOB_STATUS_USER_INTERVENTION | JOB_STATUS_BLOCKED_DEVQ))
  706. return IPP_JOBSTATE_PROCESSEDSTOPPED;
  707. if (dwState & JOB_STATUS_DELETED)
  708. return IPP_JOBSTATE_CANCELLED;
  709. if (dwState & JOB_STATUS_PAUSED)
  710. return IPP_JOBSTATE_PENDINGHELD;
  711. if (dwState & JOB_STATUS_PRINTED)
  712. return IPP_JOBSTATE_COMPLETED;
  713. if (dwState & (JOB_STATUS_PRINTING | JOB_STATUS_SPOOLING | JOB_STATUS_DELETING))
  714. return IPP_JOBSTATE_PROCESSING;
  715. if ((dwState == 0) || (dwState & JOB_STATUS_RESTART))
  716. return IPP_JOBSTATE_PENDING;
  717. return IPP_JOBSTATE_UNKNOWN;
  718. }
  719. /*****************************************************************************\
  720. * ipp_IppToW32JobState (Local Routine)
  721. *
  722. * Maps a IPP State flag to that of a W32 Status flag.
  723. *
  724. \*****************************************************************************/
  725. DWORD ipp_IppToW32JobState(
  726. DWORD dwState)
  727. {
  728. switch (dwState) {
  729. case IPP_JOBSTATE_PENDINGHELD:
  730. return JOB_STATUS_PAUSED;
  731. case IPP_JOBSTATE_PROCESSEDSTOPPED:
  732. return JOB_STATUS_ERROR;
  733. case IPP_JOBSTATE_PROCESSING:
  734. return JOB_STATUS_PRINTING;
  735. case IPP_JOBSTATE_CANCELLED:
  736. case IPP_JOBSTATE_ABORTED:
  737. return JOB_STATUS_DELETING;
  738. case IPP_JOBSTATE_COMPLETED:
  739. return JOB_STATUS_PRINTED;
  740. default:
  741. case IPP_JOBSTATE_PENDING:
  742. return 0;
  743. }
  744. }
  745. /*****************************************************************************\
  746. * ipp_W32ToIppPrnState (Local Routine)
  747. *
  748. * Maps a W32-Prn-State to Ipp-Prn-State.
  749. *
  750. \*****************************************************************************/
  751. DWORD ipp_W32ToIppPrnState(
  752. DWORD dwState)
  753. {
  754. if (dwState == 0)
  755. return IPP_PRNSTATE_IDLE;
  756. if (dwState & PRINTER_STATUS_PAUSED)
  757. return IPP_PRNSTATE_STOPPED;
  758. if (dwState & (PRINTER_STATUS_PROCESSING | PRINTER_STATUS_PRINTING))
  759. return IPP_PRNSTATE_PROCESSING;
  760. return IPP_PRNSTATE_UNKNOWN;
  761. }
  762. /*****************************************************************************\
  763. * ipp_IppToW32PrnState (Local Routine)
  764. *
  765. * Maps a Ipp-Prn-State to W32-Prn-State.
  766. *
  767. \*****************************************************************************/
  768. DWORD ipp_IppToW32PrnState(
  769. DWORD dwState)
  770. {
  771. switch (dwState) {
  772. case IPP_PRNSTATE_STOPPED:
  773. return PRINTER_STATUS_PAUSED;
  774. case IPP_PRNSTATE_PROCESSING:
  775. return PRINTER_STATUS_PROCESSING;
  776. default:
  777. case IPP_PRNSTATE_IDLE:
  778. return 0;
  779. }
  780. }
  781. /*****************************************************************************\
  782. * ipp_IppCurTime (Local Routine)
  783. *
  784. * Returns the base seconds printer has been alive. This is used for the
  785. * printer-up-time attribute. Since our implementation can't determine the
  786. * true printer up-time, we're going to use the relative seconds returned
  787. * from the time() function.
  788. *
  789. \*****************************************************************************/
  790. DWORD ipp_IppCurTime(VOID)
  791. {
  792. time_t tTime;
  793. ZeroMemory(&tTime, sizeof(time_t));
  794. time(&tTime);
  795. return (DWORD) tTime;
  796. }
  797. /*****************************************************************************\
  798. * ipp_IppToW32Time (Local Routine)
  799. *
  800. * Converts an IPP (DWORD) time to a win32 SYSTEMTIME. Note that we pass in the
  801. * printers' normalised start time as a straight overwrite of the first fields
  802. * of the LPSYSTEMTIME structure. This is nasty but since the code has no concept
  803. * of session, we have to pass it back to code that does.
  804. *
  805. \*****************************************************************************/
  806. BOOL ipp_IppToW32Time(
  807. time_t dwTime,
  808. LPSYSTEMTIME pst)
  809. {
  810. // All we do is brutally overwrite the structure with the time and send it back
  811. //
  812. // *(time_t *)pst = dwTime;
  813. // Change to use CopyMemory to avoid 64bit alignment error
  814. //
  815. CopyMemory (pst, &dwTime, sizeof (time_t));
  816. return TRUE;
  817. }
  818. /*******************************************************************************
  819. ** ippConvertSystemTime
  820. **
  821. ** This receives the system time (which has actually been packed with the time
  822. ** retrieved from the printers) and converts it to the Real System time based
  823. ** on the original T0 of the printer
  824. **
  825. ******************************************************************************/
  826. BOOL WebIppConvertSystemTime(
  827. IN OUT LPSYSTEMTIME pST,
  828. IN time_t dwPrinterT0)
  829. {
  830. //
  831. // First we need to get the time stored in the LPSYSTEMTIME structure
  832. // time_t dwSubmitTime = *(time_t *)pST;
  833. // Use CopyMemory to avoid alignment error in 64bit machine.
  834. //
  835. time_t dwSubmitTime;
  836. CopyMemory (&dwSubmitTime, pST, sizeof (time_t));
  837. SYSTEMTIME TmpST;
  838. //
  839. // If the submitted time is zero, it means that either the job was submitted before
  840. // the printer was rebooted, or, the printer does not support the submitted time of the
  841. // job
  842. //
  843. if (!dwSubmitTime) {
  844. ZeroMemory( &pST, sizeof(LPSYSTEMTIME));
  845. } else {
  846. //
  847. // Next we have to normalise the time to that of the PrinterT0
  848. //
  849. dwSubmitTime += dwPrinterT0;
  850. tm *ptm;
  851. //
  852. // Convert the time into a struct and return the SYSTEMTIME
  853. // structure.
  854. //
  855. ptm = gmtime(&dwSubmitTime);
  856. if (ptm) {
  857. TmpST.wYear = (WORD)(1900 + ptm->tm_year);
  858. TmpST.wMonth = (WORD)(ptm->tm_mon + 1);
  859. TmpST.wDayOfWeek = (WORD)ptm->tm_wday;
  860. TmpST.wDay = (WORD)ptm->tm_mday;
  861. TmpST.wHour = (WORD)ptm->tm_hour;
  862. TmpST.wMinute = (WORD)ptm->tm_min;
  863. TmpST.wSecond = (WORD)ptm->tm_sec;
  864. TmpST.wMilliseconds = 0;
  865. CopyMemory (pST, &TmpST, sizeof (SYSTEMTIME));
  866. } else {
  867. ZeroMemory( &pST, sizeof(LPSYSTEMTIME));
  868. }
  869. }
  870. return TRUE;
  871. }
  872. /*****************************************************************************\
  873. * ipp_W32ToIppTime (Local Routine)
  874. *
  875. * Converts a Win32 SYSTEMTIME to UCT.
  876. *
  877. \*****************************************************************************/
  878. DWORD ipp_W32ToIppTime(
  879. LPSYSTEMTIME pst) // We pass in the T0 for the system in here
  880. {
  881. tm tmCvt;
  882. struct _timeb tiTimeb;
  883. _ftime(&tiTimeb); // We obtain the time zone difference from here,
  884. // mktime assumes local time in doing the conversion
  885. ZeroMemory(&tmCvt, sizeof(tm));
  886. tmCvt.tm_sec = (int)(short)pst->wSecond;
  887. tmCvt.tm_min = (int)(short)pst->wMinute;
  888. tmCvt.tm_hour = (int)(short)pst->wHour;
  889. tmCvt.tm_mday = (int)(short)pst->wDay;
  890. tmCvt.tm_mon = (int)(short)(pst->wMonth - 1);
  891. tmCvt.tm_year = ((int)(short)pst->wYear - 1900);
  892. tmCvt.tm_wday = (int)(short)pst->wDayOfWeek;
  893. INT iUCT = (INT)mktime(&tmCvt);
  894. iUCT -= tiTimeb.timezone * 60; // Normalise for timezone difference
  895. return (DWORD)iUCT;
  896. }
  897. /*****************************************************************************\
  898. * ipp_JidFromUri
  899. *
  900. * Returns a job-id from a job-uri string.
  901. *
  902. \*****************************************************************************/
  903. DWORD ipp_JidFromUri(
  904. LPTSTR lpszUri)
  905. {
  906. LPTSTR lpszPtr;
  907. DWORD jid = 0;
  908. if (lpszPtr = webFindRChar(lpszUri, TEXT('=')))
  909. jid = webAtoI(++lpszPtr);
  910. return jid;
  911. }
  912. /*****************************************************************************\
  913. * ipp_PackStrings
  914. *
  915. * This routine packs strings to the end of a buffer. This is used for
  916. * building a JOB_INFO_2 list from IPP information.
  917. *
  918. \*****************************************************************************/
  919. LPBYTE ipp_PackStrings(
  920. LPTSTR* ppszSrc,
  921. LPBYTE pbDst,
  922. LPDWORD pdwDstOffsets,
  923. LPBYTE pbEnd)
  924. {
  925. DWORD cbStr;
  926. while (*pdwDstOffsets != (DWORD)-1) {
  927. //
  928. // We fill in the strings from the end of the structure and fill in the
  929. // structure forwards, if our string pointer is ever less than the address
  930. // we are copying into, the initial block allocated was too small
  931. //
  932. if (*ppszSrc) {
  933. cbStr = webStrSize(*ppszSrc);
  934. pbEnd -= cbStr;
  935. CopyMemory(pbEnd, *ppszSrc, cbStr);
  936. LPTSTR *strWriteLoc = (LPTSTR *)(pbDst + *pdwDstOffsets);
  937. WEB_IPP_ASSERT( (LPBYTE)pbEnd >= (LPBYTE)strWriteLoc );
  938. *strWriteLoc = (LPTSTR)pbEnd;
  939. } else {
  940. *(LPTSTR *)(pbDst + *pdwDstOffsets) = TEXT('\0');
  941. }
  942. ppszSrc++;
  943. pdwDstOffsets++;
  944. }
  945. return pbEnd;
  946. }
  947. /*****************************************************************************\
  948. * ipp_NextVal (Local Routine)
  949. *
  950. * Returns next value-field in a tag-attribute.
  951. *
  952. * Parameters:
  953. * ----------
  954. * lpIppHdr - Pointer to the IPP-Stream.
  955. * lpcbIdx - Current Byte offset into the IPP-Stream.
  956. * cbIppHdr - Size of the IPP-Stream.
  957. *
  958. \*****************************************************************************/
  959. LPBYTE ipp_NextVal(
  960. LPBYTE lpIppHdr,
  961. LPDWORD lpcbIdx,
  962. DWORD cbIppHdr)
  963. {
  964. DWORD cbIdx;
  965. DWORD cbSize;
  966. //
  967. // The (cbIdx) is positioned at the location where a length
  968. // is to be read.
  969. //
  970. cbIdx = *lpcbIdx;
  971. //
  972. // Make sure we have enough to read a WORD value.
  973. //
  974. if ((cbIdx + IPP_SIZEOFTAG) >= cbIppHdr)
  975. return NULL;
  976. //
  977. // Get the name-length of the attribute. Adjust our
  978. // offset by this amount and add size of length-field to
  979. // position to the next attribute-length.
  980. //
  981. cbSize = (DWORD)ipp_ReadWord(lpIppHdr, cbIdx);
  982. cbIdx += (cbSize + IPP_SIZEOFLEN);
  983. if (cbIdx >= cbIppHdr)
  984. return NULL;
  985. *lpcbIdx = cbIdx;
  986. return lpIppHdr + cbIdx;
  987. }
  988. /*****************************************************************************\
  989. * ipp_NextTag (Local Routine)
  990. *
  991. * Returns a pointer to the next tag in the header. If this routine returns
  992. * NULL, then we do not have enough data to advance to the next-tag.
  993. *
  994. * Parameters:
  995. * ----------
  996. * lpTag - Pointer to the current-tag postion.
  997. * lpcbIdx - Bytes offset from the header.
  998. * cbHdr - Size of the header-stream we're working with.
  999. *
  1000. \*****************************************************************************/
  1001. LPBYTE ipp_NextTag(
  1002. LPBYTE lpIppHdr,
  1003. LPDWORD lpcbIdx,
  1004. DWORD cbIppHdr)
  1005. {
  1006. BYTE bTag;
  1007. DWORD cbIdx;
  1008. DWORD cbSize;
  1009. //
  1010. // Out current byte-offset is at a tag. Grab the tag, and advance
  1011. // our index past it to proced to get past the possible attribute.
  1012. //
  1013. cbIdx = *lpcbIdx;
  1014. bTag = ipp_ReadByte(lpIppHdr, cbIdx);
  1015. cbIdx += IPP_SIZEOFTAG;
  1016. //
  1017. // If our tag is a deliminator, then we need only advance to the
  1018. // next byte where the next tag should be.
  1019. //
  1020. if (IS_TAG_DELIMITER(bTag)) {
  1021. //
  1022. // Make sure we have enough bytes to return an offset
  1023. // to the next tag.
  1024. //
  1025. if (cbIdx >= cbIppHdr)
  1026. return NULL;
  1027. *lpcbIdx = cbIdx;
  1028. return lpIppHdr + cbIdx;
  1029. }
  1030. //
  1031. // Otherwise, we are currently at an attribute-tag. We need to
  1032. // calculate bytes offset to the next tag.
  1033. //
  1034. if (IS_TAG_ATTRIBUTE(bTag)) {
  1035. //
  1036. // This logic calculates the byte-offsets to the
  1037. // value-tags. We need to do two value adjustments
  1038. // since there is both a (name) and a (value) component
  1039. // to an attribute.
  1040. //
  1041. if (ipp_NextVal(lpIppHdr, &cbIdx, cbIppHdr)) {
  1042. //
  1043. // This last adjustment will return the position
  1044. // of the next tag.
  1045. //
  1046. if (ipp_NextVal(lpIppHdr, &cbIdx, cbIppHdr)) {
  1047. *lpcbIdx = cbIdx;
  1048. return lpIppHdr + cbIdx;
  1049. }
  1050. }
  1051. }
  1052. return NULL;
  1053. }
  1054. /*****************************************************************************\
  1055. * ipp_RelAttr (Local Routine)
  1056. *
  1057. * Release (Free) the attribute block.
  1058. *
  1059. \*****************************************************************************/
  1060. BOOL ipp_RelAttr(
  1061. LPIPPATTR lpAttr)
  1062. {
  1063. if (lpAttr) {
  1064. webFree(lpAttr->lpszName);
  1065. webFree(lpAttr->lpValue);
  1066. webFree(lpAttr);
  1067. return TRUE;
  1068. }
  1069. return FALSE;
  1070. }
  1071. /*****************************************************************************\
  1072. * ipp_GetAttr (Local Routine)
  1073. *
  1074. * Returns an attribute in a structured-from.
  1075. *
  1076. \*****************************************************************************/
  1077. LPIPPATTR ipp_GetAttr(
  1078. LPBYTE lpTag,
  1079. DWORD cbIdx,
  1080. LPIPPOBJ lpObj)
  1081. {
  1082. LPIPPATTR lpAttr = NULL;
  1083. WORD wIdx;
  1084. BYTE bTag = ipp_ReadByte(lpTag, 0);
  1085. DWORD cbSize;
  1086. if (IS_TAG_ATTRIBUTE(bTag)) {
  1087. if (lpAttr = (LPIPPATTR)webAlloc(sizeof(IPPATTR))) {
  1088. __try {
  1089. lpAttr->bTag = bTag;
  1090. lpTag += IPP_SIZEOFTAG;
  1091. lpAttr->cbName = ipp_ReadWord(lpTag, 0);
  1092. lpTag += IPP_SIZEOFLEN;
  1093. if (lpAttr->cbName) {
  1094. lpAttr->lpszName = webMBtoTC(CP_UTF8, (LPSTR)lpTag, lpAttr->cbName);
  1095. lpTag += lpAttr->cbName;
  1096. }
  1097. // This is added to support name-with-language attributes. To
  1098. // do this temporarily, this code will work but ignore the language
  1099. // part of the attribute. In the future, we can look at dealing with
  1100. // the language appropriately.
  1101. if (IS_TAG_COMPOUND(bTag)) {
  1102. if (ipp_ReadWord(lpTag, 0)) {
  1103. lpTag += IPP_SIZEOFLEN;
  1104. lpTag += ipp_ReadWord(lpTag, 0);
  1105. lpTag += IPP_SIZEOFLEN;
  1106. }
  1107. }
  1108. lpAttr->cbValue = ipp_ReadWord(lpTag, 0);
  1109. lpTag += IPP_SIZEOFLEN;
  1110. //
  1111. // If there's a value, then make sure that the size doesn't
  1112. // exceed our IPP-Stream.
  1113. //
  1114. if (lpAttr->cbValue && (lpAttr->cbValue < (lpObj->cbIppHdr - cbIdx))) {
  1115. //
  1116. // Convert the value to the appropriate format. This
  1117. // block currently makes the assumption that all strings
  1118. // are dealt with as Octet-Strings. When this parser
  1119. // supports other character-sets, then the conversion
  1120. // for Character-Strings can utilize a different codepage.
  1121. //
  1122. if (IS_TAG_OCTSTR(lpAttr->bTag)) {
  1123. lpAttr->lpValue = (LPVOID)webMBtoTC(CP_UTF8, (LPSTR)lpTag, lpAttr->cbValue);
  1124. } else if (IS_TAG_CHARSETSTR(lpAttr->bTag)) {
  1125. lpAttr->lpValue = (LPVOID)webMBtoTC(lpObj->uCPRcv, (LPSTR)lpTag, lpAttr->cbValue);
  1126. } else if (IS_TAG_CHRSTR(lpAttr->bTag)) {
  1127. lpAttr->lpValue = (LPVOID)webMBtoTC(CP_ACP, (LPSTR)lpTag, lpAttr->cbValue);
  1128. } else {
  1129. if (lpAttr->cbValue <= sizeof(DWORD))
  1130. lpAttr->lpValue = (LPVOID)webAlloc(sizeof(DWORD));
  1131. else
  1132. lpAttr->lpValue = (LPVOID)webAlloc(lpAttr->cbValue);
  1133. if (lpAttr->lpValue) {
  1134. if (lpAttr->cbValue == sizeof(BYTE))
  1135. *(LPDWORD)(lpAttr->lpValue) = (DWORD)ipp_ReadByte(lpTag, 0);
  1136. else if (lpAttr->cbValue == sizeof(WORD))
  1137. *(LPDWORD)(lpAttr->lpValue) = (DWORD)ipp_ReadWord(lpTag, 0);
  1138. else if (lpAttr->cbValue == sizeof(DWORD))
  1139. *(LPDWORD)(lpAttr->lpValue) = ipp_ReadDWord(lpTag, 0);
  1140. else
  1141. CopyMemory((LPVOID)lpAttr->lpValue, (LPVOID)lpTag, lpAttr->cbValue);
  1142. }
  1143. }
  1144. }
  1145. } __except (1) {
  1146. ipp_RelAttr(lpAttr);
  1147. lpAttr = NULL;
  1148. }
  1149. }
  1150. }
  1151. return lpAttr;
  1152. }
  1153. /*****************************************************************************\
  1154. * ipp_WriteAttr (Local Routine)
  1155. *
  1156. * Write out the attribute. If NULL is passed in as the (lplpIppPtr), then
  1157. * this routine returns the size necessary to write the info.
  1158. *
  1159. \*****************************************************************************/
  1160. DWORD ipp_WriteAttr(
  1161. LPBYTE* lplpIppPtr,
  1162. BYTE bTag,
  1163. DWORD cbName,
  1164. LPVOID lpName,
  1165. DWORD cbValue,
  1166. LPVOID lpValue)
  1167. {
  1168. DWORD cbSize;
  1169. //
  1170. // Set the size that this attribute occupies.
  1171. //
  1172. cbSize = (cbName + cbValue + IPP_SIZEOFTAG + IPP_SIZEOFLEN + IPP_SIZEOFLEN);
  1173. //
  1174. // Write out the attribute to the buffer (if available).
  1175. //
  1176. if (lplpIppPtr) {
  1177. ipp_WriteByte(lplpIppPtr, bTag);
  1178. if (cbName) {
  1179. ipp_WriteWord(lplpIppPtr, (WORD)cbName);
  1180. ipp_WriteData(lplpIppPtr, (LPVOID)lpName, cbName);
  1181. } else {
  1182. ipp_WriteWord(lplpIppPtr, (WORD)cbName);
  1183. }
  1184. ipp_WriteWord(lplpIppPtr, (WORD)cbValue);
  1185. switch (bTag) {
  1186. case IPP_TAG_INT_INTEGER:
  1187. case IPP_TAG_INT_ENUM:
  1188. ipp_WriteDWord(lplpIppPtr, * (DWORD*)lpValue);
  1189. break;
  1190. case IPP_TAG_INT_BOOLEAN:
  1191. ipp_WriteByte(lplpIppPtr, * (BYTE*)lpValue);
  1192. break;
  1193. default:
  1194. ipp_WriteData(lplpIppPtr, (LPVOID)lpValue , cbValue);
  1195. break;
  1196. }
  1197. }
  1198. return cbSize;
  1199. }
  1200. /*****************************************************************************\
  1201. * ipp_SizeAttr (Local Routine)
  1202. *
  1203. * Return the size necessary to store the attribute.
  1204. *
  1205. \*****************************************************************************/
  1206. inline DWORD ipp_SizeAttr(
  1207. DWORD cbName,
  1208. DWORD cbValue)
  1209. {
  1210. return ipp_WriteAttr(NULL, 0, cbName, NULL, cbValue, NULL);
  1211. }
  1212. /*****************************************************************************\
  1213. * ipp_WriteHead (Local Routine)
  1214. *
  1215. * Write out our "generic" type header. This includes the character-set
  1216. * that we support.
  1217. *
  1218. \*****************************************************************************/
  1219. DWORD ipp_WriteHead(
  1220. LPBYTE* lplpIppPtr,
  1221. WORD wReq,
  1222. DWORD idReq,
  1223. UINT cpReq)
  1224. {
  1225. DWORD cbNamCS;
  1226. DWORD cbValCS;
  1227. DWORD cbNamNL;
  1228. DWORD cbValNL;
  1229. LPCTSTR lpszCS;
  1230. LPSTR lputfNamCS;
  1231. LPSTR lputfValCS;
  1232. LPSTR lputfNamNL;
  1233. LPSTR lputfValNL;
  1234. DWORD cbSize = 0;
  1235. //
  1236. // Encode in the specified character-set.
  1237. //
  1238. lpszCS = ((cpReq == CP_ACP) ? s_szUsAscii : s_szUtf8);
  1239. lputfNamCS = webTCtoMB(CP_ACP, s_szCharSet , &cbNamCS);
  1240. lputfValCS = webTCtoMB(CP_ACP, lpszCS , &cbValCS);
  1241. lputfNamNL = webTCtoMB(CP_ACP, s_szNaturalLanguage, &cbNamNL);
  1242. lputfValNL = webTCtoMB(CP_ACP, s_szEnUS , &cbValNL);
  1243. if (lputfNamCS && lputfValCS && lputfNamNL && lputfValNL) {
  1244. //
  1245. // Calculate the size necessary to hold the IPP-Header.
  1246. //
  1247. cbSize = IPP_SIZEOFHDR + // Version-Request.
  1248. IPP_SIZEOFTAG + // Operation Tag
  1249. ipp_SizeAttr(cbNamCS, cbValCS) + // CharSet Attribute.
  1250. ipp_SizeAttr(cbNamNL, cbValNL); // NaturalLang Attribute.
  1251. if (lplpIppPtr) {
  1252. ipp_WriteWord(lplpIppPtr, IPP_VERSION);
  1253. ipp_WriteWord(lplpIppPtr, wReq);
  1254. ipp_WriteDWord(lplpIppPtr, idReq);
  1255. ipp_WriteByte(lplpIppPtr, IPP_TAG_DEL_OPERATION);
  1256. ipp_WriteAttr(lplpIppPtr, IPP_TAG_CHR_CHARSET, cbNamCS, lputfNamCS, cbValCS, lputfValCS);
  1257. ipp_WriteAttr(lplpIppPtr, IPP_TAG_CHR_NATURAL, cbNamNL, lputfNamNL, cbValNL, lputfValNL);
  1258. }
  1259. }
  1260. webFree(lputfValCS);
  1261. webFree(lputfNamCS);
  1262. webFree(lputfValNL);
  1263. webFree(lputfNamNL);
  1264. return cbSize;
  1265. }
  1266. /*****************************************************************************\
  1267. * ipp_SizeHdr (Local Routine)
  1268. *
  1269. * Return the size necessary to store the header and operation tags.
  1270. *
  1271. \*****************************************************************************/
  1272. inline DWORD ipp_SizeHdr(
  1273. UINT cpReq)
  1274. {
  1275. return ipp_WriteHead(NULL, 0, 0, cpReq);
  1276. }
  1277. /*****************************************************************************\
  1278. * ipp_ValDocFormat (Local Routine)
  1279. *
  1280. * Validates the document-format.
  1281. *
  1282. \*****************************************************************************/
  1283. BOOL ipp_ValDocFormat(
  1284. LPCTSTR lpszFmt)
  1285. {
  1286. DWORD idx;
  1287. DWORD cCnt;
  1288. static PCTSTR s_szFmts[] = {
  1289. s_szMimeTxtHtml ,
  1290. s_szMimeTxtPlain ,
  1291. s_szMimePostScript,
  1292. s_szMimePCL ,
  1293. s_szMimeOctStream
  1294. };
  1295. cCnt = sizeof(s_szFmts) / sizeof(s_szFmts[0]);
  1296. for (idx = 0; idx < cCnt; idx++) {
  1297. if (lstrcmpi(lpszFmt, s_szFmts[idx]) == 0)
  1298. return TRUE;
  1299. }
  1300. return FALSE;
  1301. }
  1302. /*****************************************************************************\
  1303. * ipp_ValAtrFidelity (Local Routine)
  1304. *
  1305. * Validates the attribute-fidelity.
  1306. *
  1307. \*****************************************************************************/
  1308. BOOL ipp_ValAtrFidelity(
  1309. DWORD dwVal,
  1310. LPBOOL lpbFidelity)
  1311. {
  1312. if (dwVal == 1) {
  1313. *lpbFidelity = TRUE;
  1314. } else if (dwVal == 0) {
  1315. *lpbFidelity = FALSE;
  1316. } else {
  1317. return FALSE;
  1318. }
  1319. return TRUE;
  1320. }
  1321. /*****************************************************************************\
  1322. * ipp_ValWhichJobs (Local Routine)
  1323. *
  1324. * Validates the which-jobs.
  1325. *
  1326. \*****************************************************************************/
  1327. BOOL ipp_ValWhichJobs(
  1328. PDWORD pfReq,
  1329. LPCTSTR lpszWJ)
  1330. {
  1331. DWORD idx;
  1332. DWORD cCnt;
  1333. static FLGSTR s_fsVal[] = {
  1334. RA_JOBSCOMPLETED , s_szCompleted ,
  1335. RA_JOBSUNCOMPLETED, s_szNotCompleted
  1336. };
  1337. cCnt = sizeof(s_fsVal) / sizeof(s_fsVal[0]);
  1338. for (idx = 0; idx < cCnt; idx++) {
  1339. if (lstrcmpi(lpszWJ, s_fsVal[idx].pszStr) == 0) {
  1340. x_SetReq(pfReq, s_fsVal[idx].fFlag);
  1341. return TRUE;
  1342. }
  1343. }
  1344. return FALSE;
  1345. }
  1346. /*****************************************************************************\
  1347. * ipp_GetRspSta (Local Routine)
  1348. *
  1349. * Returns the response-code and any status messages if failure.
  1350. *
  1351. \*****************************************************************************/
  1352. WORD ipp_GetRspSta(
  1353. WORD wRsp,
  1354. UINT cpReq,
  1355. LPSTR* lplputfNamSta,
  1356. LPDWORD lpcbNamSta,
  1357. LPSTR* lplputfValSta,
  1358. LPDWORD lpcbValSta)
  1359. {
  1360. DWORD idx;
  1361. DWORD cErrors;
  1362. *lplputfNamSta = NULL;
  1363. *lplputfValSta = NULL;
  1364. *lpcbNamSta = 0;
  1365. *lpcbValSta = 0;
  1366. if (SUCCESS_RANGE(wRsp) == FALSE) {
  1367. //
  1368. // Get the status-name.
  1369. //
  1370. *lplputfNamSta = webTCtoMB(CP_ACP, s_szStaMsg, lpcbNamSta);
  1371. //
  1372. // Get the string we will be using to encode the error.
  1373. //
  1374. cErrors = sizeof(s_LEIpp) / sizeof(s_LEIpp[0]);
  1375. for (idx = 0; idx < cErrors; idx++) {
  1376. if (wRsp == s_LEIpp[idx].wRsp) {
  1377. *lplputfValSta = webTCtoMB(cpReq, s_LEIpp[idx].pszStr, lpcbValSta);
  1378. break;
  1379. }
  1380. }
  1381. }
  1382. return TRUE;
  1383. }
  1384. /*****************************************************************************\
  1385. * ipp_CvtW32Val (Local Routine - Server)
  1386. *
  1387. * Converts a value to the appropriate ipp-value.
  1388. *
  1389. \*****************************************************************************/
  1390. VOID ipp_CvtW32Val(
  1391. LPCTSTR lpszName,
  1392. LPVOID lpvVal)
  1393. {
  1394. if (lstrcmpi(lpszName, s_szPrtState) == 0) {
  1395. *(LPDWORD)lpvVal = ipp_W32ToIppPrnState(*(LPDWORD)lpvVal);
  1396. } else if (lstrcmpi(lpszName, s_szJobState) == 0) {
  1397. *(LPDWORD)lpvVal = ipp_W32ToIppJobState(*(LPDWORD)lpvVal);
  1398. } else if (lstrcmpi(lpszName, s_szJobKOctets) == 0) {
  1399. *(LPDWORD)lpvVal = ipp_W32ToIppJobSize(*(LPDWORD)lpvVal);
  1400. } else if (lstrcmpi(lpszName, s_szJobKOctetsProcess) == 0) {
  1401. *(LPDWORD)lpvVal = ipp_W32ToIppJobSize(*(LPDWORD)lpvVal);
  1402. }
  1403. }
  1404. /*****************************************************************************\
  1405. * ipp_AllocUnsVals
  1406. *
  1407. * Allocates an array of ipp-values used to write to a stream.
  1408. *
  1409. \*****************************************************************************/
  1410. LPIPPATTRY ipp_AllocUnsVals(
  1411. PWEBLST pwlUns,
  1412. LPDWORD pcUns,
  1413. LPDWORD lpcbAtrs)
  1414. {
  1415. DWORD idx;
  1416. DWORD cUns;
  1417. DWORD cbUns;
  1418. PCTSTR pszStr;
  1419. LPIPPATTRY pUns = NULL;
  1420. *pcUns = 0;
  1421. if (pwlUns && (cUns = pwlUns->Count())) {
  1422. if (pUns = (LPIPPATTRY)webAlloc(cUns * sizeof(IPPATTRY))) {
  1423. *lpcbAtrs += IPP_SIZEOFTAG;
  1424. *pcUns = cUns;
  1425. //
  1426. // Loop through each item and convert for addition to stream.
  1427. //
  1428. pwlUns->Reset();
  1429. for (idx = 0; idx < cUns; idx++) {
  1430. if (pszStr = pwlUns->Get()) {
  1431. pUns[idx].pszNam = webTCtoMB(CP_ACP, pszStr, &pUns[idx].cbNam);
  1432. //
  1433. // Unsupported-values should be null.
  1434. //
  1435. pUns[idx].pszVal = NULL;
  1436. pUns[idx].cbVal = 0;
  1437. *lpcbAtrs += ipp_SizeAttr(pUns[idx].cbNam, pUns[idx].cbVal);
  1438. }
  1439. pwlUns->Next();
  1440. }
  1441. }
  1442. }
  1443. return pUns;
  1444. }
  1445. /*****************************************************************************\
  1446. * ipp_AllocAtrVals
  1447. *
  1448. * Allocates an array of ipp-values used to write to a stream.
  1449. *
  1450. \*****************************************************************************/
  1451. LPIPPATTRY ipp_AllocAtrVals(
  1452. WORD wReq,
  1453. PDWORD pfReq,
  1454. UINT cpReq,
  1455. LPBYTE lpbData,
  1456. LPIPPATTRX pRsp,
  1457. DWORD cAtr,
  1458. LPDWORD lpcbAtrs)
  1459. {
  1460. BOOL bRet = FALSE;
  1461. BOOL fWr;
  1462. DWORD idx;
  1463. BOOL bDel;
  1464. LPVOID lpvVal;
  1465. LPIPPATTRY pAtr = NULL;
  1466. if (cAtr && (pAtr = (LPIPPATTRY)webAlloc(cAtr * sizeof(IPPATTRY)))) {
  1467. //
  1468. // Allocate the attribute-values.
  1469. //
  1470. for (idx = 0, fWr = TRUE; idx < cAtr; idx++) {
  1471. bDel = FALSE;
  1472. //
  1473. // Build the attribute-name.
  1474. //
  1475. if (pRsp[idx].pszNam) {
  1476. pAtr[idx].pszNam = webTCtoMB(CP_ACP, pRsp[idx].pszNam, &pAtr[idx].cbNam);
  1477. //
  1478. // If the value is absolute, then assign the
  1479. // attribute directly. Otherwise, it's an offset into
  1480. // the return-structure, and as such, must be indirectly
  1481. // built.
  1482. //
  1483. if (pRsp[idx].nVal == IPP_ATR_ABSOLUTE) {
  1484. //
  1485. // Special-case the printer-up-time to reflect the number
  1486. // of seconds it's been up and running. Since we can't
  1487. // determine the time the printer's been up, use the time
  1488. // windows has been started.
  1489. //
  1490. if (lstrcmpi(pRsp[idx].pszNam, s_szPrtUpTime) == 0)
  1491. pRsp[idx].pvVal = (LPVOID)ULongToPtr (ipp_IppCurTime());
  1492. else
  1493. lpvVal = (LPVOID)&pRsp[idx].pvVal;
  1494. } else {
  1495. lpvVal = (LPVOID)(lpbData + (DWORD_PTR)pRsp[idx].pvVal);
  1496. }
  1497. fWr = x_ChkReq(pfReq, pRsp[idx].fReq);
  1498. }
  1499. //
  1500. // Add it to the stream if it is a request or if
  1501. // the response requires it.
  1502. //
  1503. if (fWr || !(wReq & IPP_RESPONSE)) {
  1504. //
  1505. // If the value is absolute, then assign the
  1506. // attribute directly. Otherwise, it's an offset into
  1507. // the return-structure, and as such, must be indirectly
  1508. // built.
  1509. //
  1510. if (pRsp[idx].nVal == IPP_ATR_ABSOLUTE)
  1511. lpvVal = (LPVOID)&pRsp[idx].pvVal;
  1512. else
  1513. lpvVal = (LPVOID)(lpbData + (DWORD_PTR)pRsp[idx].pvVal);
  1514. //
  1515. // Build the attribute-value.
  1516. //
  1517. if (IS_TAG_DELIMITER(pRsp[idx].bTag)) {
  1518. bDel = TRUE;
  1519. } else if (IS_TAG_OCTSTR(pRsp[idx].bTag)) {
  1520. pAtr[idx].pszVal = webTCtoMB(CP_UTF8, *(LPTSTR*)lpvVal, &pAtr[idx].cbVal);
  1521. } else if (IS_TAG_CHARSETSTR(pRsp[idx].bTag)) {
  1522. pAtr[idx].pszVal = webTCtoMB(cpReq, *(LPTSTR*)lpvVal, &pAtr[idx].cbVal);
  1523. } else if (IS_TAG_CHRSTR(pRsp[idx].bTag)) {
  1524. pAtr[idx].pszVal = webTCtoMB(CP_ACP, *(LPTSTR*)lpvVal, &pAtr[idx].cbVal);
  1525. } else {
  1526. pAtr[idx].pszVal = (LPSTR)webAlloc(sizeof(DWORD));
  1527. if ( !pAtr[idx].pszVal )
  1528. goto Cleanup;
  1529. if (pRsp[idx].bTag == IPP_TAG_INT_BOOLEAN) {
  1530. pAtr[idx].cbVal = IPP_SIZEOFBYTE;
  1531. } else {
  1532. pAtr[idx].cbVal = IPP_SIZEOFINT;
  1533. }
  1534. CopyMemory(pAtr[idx].pszVal, lpvVal, pAtr[idx].cbVal);
  1535. //
  1536. // Do we need to convert the value.
  1537. //
  1538. if (pRsp[idx].nVal == IPP_ATR_OFFSETCONV)
  1539. ipp_CvtW32Val(pRsp[idx].pszNam, (LPVOID)pAtr[idx].pszVal);
  1540. }
  1541. //
  1542. // If this is a delimiter then it only occupies 1 byte.
  1543. //
  1544. if (bDel)
  1545. *lpcbAtrs += IPP_SIZEOFTAG;
  1546. else
  1547. *lpcbAtrs += ipp_SizeAttr(pAtr[idx].cbNam, pAtr[idx].cbVal);
  1548. }
  1549. }
  1550. }
  1551. bRet = TRUE;
  1552. Cleanup:
  1553. if ( !bRet && pAtr ) {
  1554. for (idx = 0 ; idx < cAtr; ++idx)
  1555. if ( pAtr[idx].pszVal )
  1556. webFree(pAtr[idx].pszVal);
  1557. webFree(pAtr);
  1558. pAtr = NULL;
  1559. }
  1560. return pAtr;
  1561. }
  1562. /*****************************************************************************\
  1563. * ipp_WriteUnsVals
  1564. *
  1565. * Writes an array of ipp-values to an ipp-stream.
  1566. *
  1567. \*****************************************************************************/
  1568. BOOL ipp_WriteUnsVals(
  1569. LPBYTE* lplpIppPtr,
  1570. LPIPPATTRY pUns,
  1571. DWORD cUns)
  1572. {
  1573. DWORD idx;
  1574. if (pUns && cUns) {
  1575. ipp_WriteByte(lplpIppPtr, IPP_TAG_DEL_UNSUPPORTED);
  1576. //
  1577. // Unsupported values should be null.
  1578. //
  1579. for (idx = 0; idx < cUns; idx++)
  1580. ipp_WriteAttr(lplpIppPtr, IPP_TAG_OUT_UNSUPPORTED, pUns[idx].cbNam, pUns[idx].pszNam, 0, NULL);
  1581. }
  1582. return TRUE;
  1583. }
  1584. /*****************************************************************************\
  1585. * ipp_WriteAtrVals
  1586. *
  1587. * Writes an array of ipp-values to an ipp-stream.
  1588. *
  1589. \*****************************************************************************/
  1590. BOOL ipp_WriteAtrVals(
  1591. WORD wReq,
  1592. PDWORD pfReq,
  1593. LPBYTE* lplpIppPtr,
  1594. LPIPPATTRX pRsp,
  1595. LPIPPATTRY pAtr,
  1596. DWORD cAtr)
  1597. {
  1598. BOOL fWr;
  1599. DWORD idx;
  1600. for (idx = 0, fWr = TRUE; idx < cAtr; idx++) {
  1601. //
  1602. // If this item has a name-tag, then determine if the
  1603. // originator wants it in the stream.
  1604. //
  1605. if (pRsp[idx].pszNam)
  1606. fWr = x_ChkReq(pfReq, pRsp[idx].fReq);
  1607. //
  1608. // Only write out the item if it is requested, or if
  1609. // it is a request-operation.
  1610. //
  1611. if (fWr || !(wReq & IPP_RESPONSE)) {
  1612. if (pRsp[idx].nVal == IPP_ATR_TAG)
  1613. ipp_WriteByte(lplpIppPtr, pRsp[idx].bTag);
  1614. else
  1615. ipp_WriteAttr(lplpIppPtr, pRsp[idx].bTag, pAtr[idx].cbNam, pAtr[idx].pszNam, pAtr[idx].cbVal, pAtr[idx].pszVal);
  1616. }
  1617. }
  1618. return TRUE;
  1619. }
  1620. /*****************************************************************************\
  1621. * ipp_FreeAtrVals
  1622. *
  1623. * Frees array of attribute values.
  1624. *
  1625. \*****************************************************************************/
  1626. VOID ipp_FreeAtrVals(
  1627. LPIPPATTRY pAtr,
  1628. DWORD cAtr)
  1629. {
  1630. DWORD idx;
  1631. //
  1632. // Free up the attribute-values.
  1633. //
  1634. for (idx = 0; idx < cAtr; idx++) {
  1635. webFree(pAtr[idx].pszNam);
  1636. webFree(pAtr[idx].pszVal);
  1637. }
  1638. webFree(pAtr);
  1639. }
  1640. /*****************************************************************************\
  1641. * ipp_FreeIPPJI2 (Local Routine)
  1642. *
  1643. * Frees up the IPPJI2 memory.
  1644. *
  1645. \*****************************************************************************/
  1646. VOID ipp_FreeIPPJI2(
  1647. LPIPPJI2 lpji)
  1648. {
  1649. DWORD cCnt;
  1650. DWORD idx;
  1651. //
  1652. // Free JI2-Data.
  1653. //
  1654. cCnt = ((sizeof(s_JI2Off) / sizeof(s_JI2Off[0])) - 1);
  1655. for (idx = 0; idx < cCnt; idx++)
  1656. webFree(*(LPBYTE *)(((LPBYTE)&lpji->ji2) + s_JI2Off[idx]));
  1657. //
  1658. // Free IPP-Data.
  1659. //
  1660. cCnt = ((sizeof(s_IPJOff) / sizeof(s_IPJOff[0])) - 1);
  1661. for (idx = 0; idx < cCnt; idx++)
  1662. webFree(*(LPBYTE *)(((LPBYTE)&lpji->ipp) + s_IPJOff[idx]));
  1663. }
  1664. /*****************************************************************************\
  1665. * ipp_FreeIPPPI2 (Local Routine)
  1666. *
  1667. * Frees up the IPPPI2 memory.
  1668. *
  1669. \*****************************************************************************/
  1670. VOID ipp_FreeIPPPI2(
  1671. LPIPPPI2 lppi)
  1672. {
  1673. DWORD cCnt;
  1674. DWORD idx;
  1675. //
  1676. // Free PI2-Data.
  1677. //
  1678. cCnt = ((sizeof(s_PI2Off) / sizeof(s_PI2Off[0])) - 1);
  1679. for (idx = 0; idx < cCnt; idx++)
  1680. webFree(*(LPBYTE *)(((LPBYTE)&lppi->pi2) + s_PI2Off[idx]));
  1681. //
  1682. // Free IPP-Data.
  1683. //
  1684. cCnt = ((sizeof(s_IPPOff) / sizeof(s_IPPOff[0])) - 1);
  1685. for (idx = 0; idx < cCnt; idx++)
  1686. webFree(*(LPBYTE *)(((LPBYTE)&lppi->ipp) + s_IPPOff[idx]));
  1687. }
  1688. /*****************************************************************************\
  1689. * ipp_GetIPPJI2 (Local Routine)
  1690. *
  1691. * Returns the info for a complete job in the IPP stream. We essentially
  1692. * loop through the attributes looking for the next IPP_TAG_DEL_JOB to
  1693. * signify another job-info-item.
  1694. *
  1695. \*****************************************************************************/
  1696. LPBYTE ipp_GetIPPJI2(
  1697. LPBYTE lpbTag,
  1698. LPIPPJI2 lpji,
  1699. LPDWORD lpcbIdx,
  1700. LPIPPOBJ lpObj)
  1701. {
  1702. LPIPPATTR lpAttr;
  1703. BYTE bTag;
  1704. DWORD idx;
  1705. DWORD cAtr;
  1706. BOOL bReq;
  1707. BOOL bFound;
  1708. DWORD fAtr[IPPOBJ_MASK_SIZE];
  1709. BOOL bFid = FALSE;
  1710. BOOL bAtr = FALSE;
  1711. BOOL bEnu = FALSE;
  1712. x_SetReq(fAtr, IPP_REQALL);
  1713. bTag = ipp_ReadByte(lpbTag, 0);
  1714. bReq = ((lpObj->wReq & IPP_RESPONSE) ? FALSE : TRUE);
  1715. bEnu = (BOOL)(lpObj->wReq & IPP_REQ_ENUJOB);
  1716. while ((!bEnu || (bTag != IPP_TAG_DEL_JOB)) && (bTag != IPP_TAG_DEL_DATA)) {
  1717. if (lpAttr = ipp_GetAttr(lpbTag, *lpcbIdx, lpObj)) {
  1718. if (lpAttr->lpszName && lpAttr->lpValue) {
  1719. if (lstrcmpi(lpAttr->lpszName, s_szCharSet) == 0) {
  1720. if (lpAttr->cbValue > SIZE_CHARSET)
  1721. lpObj->wError = IPPRSP_ERROR_409;
  1722. } else if (lstrcmpi(lpAttr->lpszName, s_szNaturalLanguage) == 0) {
  1723. if (lpAttr->cbValue > SIZE_NATLANG)
  1724. lpObj->wError = IPPRSP_ERROR_409;
  1725. } else if (lstrcmpi(lpAttr->lpszName, s_szJobId) == 0) {
  1726. if (lpAttr->cbValue != SIZE_INTEGER)
  1727. lpObj->wError = IPPRSP_ERROR_409;
  1728. else
  1729. lpji->ji2.JobId = *(LPDWORD)lpAttr->lpValue;
  1730. } else if (lstrcmpi(lpAttr->lpszName, s_szJobLimit) == 0) {
  1731. if (lpAttr->cbValue != SIZE_INTEGER)
  1732. lpObj->wError = IPPRSP_ERROR_409;
  1733. else
  1734. lpji->ipp.cJobs = *(LPDWORD)lpAttr->lpValue;
  1735. } else if (lstrcmpi(lpAttr->lpszName, s_szJobState) == 0) {
  1736. if (lpAttr->cbValue != SIZE_INTEGER)
  1737. lpObj->wError = IPPRSP_ERROR_409;
  1738. else
  1739. lpji->ji2.Status = ipp_IppToW32JobState(*(LPDWORD)lpAttr->lpValue);
  1740. } else if (lstrcmpi(lpAttr->lpszName, s_szJobPri) == 0) {
  1741. if (lpAttr->cbValue != SIZE_INTEGER)
  1742. lpObj->wError = IPPRSP_ERROR_409;
  1743. else
  1744. lpji->ji2.Priority = ipp_IppToW32JobPriority(*(LPDWORD)lpAttr->lpValue);
  1745. } else if (lstrcmpi(lpAttr->lpszName, s_szJobKOctets) == 0) {
  1746. if (lpAttr->cbValue != SIZE_INTEGER)
  1747. lpObj->wError = IPPRSP_ERROR_409;
  1748. else
  1749. lpji->ji2.Size = ipp_IppToW32JobSize(*(LPDWORD)lpAttr->lpValue);
  1750. } else if (lstrcmpi(lpAttr->lpszName, s_szJobKOctetsProcess) == 0) {
  1751. if (lpAttr->cbValue != SIZE_INTEGER)
  1752. lpObj->wError = IPPRSP_ERROR_409;
  1753. else
  1754. lpji->ji2.Size = ipp_IppToW32JobSize(*(LPDWORD)lpAttr->lpValue);
  1755. } else if (lstrcmpi(lpAttr->lpszName, s_szJobSheets) == 0) {
  1756. if (lpAttr->cbValue != SIZE_INTEGER)
  1757. lpObj->wError = IPPRSP_ERROR_409;
  1758. else
  1759. lpji->ji2.TotalPages = ipp_IppToW32JobTotalPages(*(LPDWORD)lpAttr->lpValue);
  1760. } else if (lstrcmpi(lpAttr->lpszName, s_szJobSheetsCompleted) == 0) {
  1761. if (lpAttr->cbValue != SIZE_INTEGER)
  1762. lpObj->wError = IPPRSP_ERROR_409;
  1763. else
  1764. lpji->ji2.PagesPrinted = ipp_IppToW32JobPagesPrinted(*(LPDWORD)lpAttr->lpValue);
  1765. } else if (lstrcmpi(lpAttr->lpszName, s_szJobName) == 0) {
  1766. if (lpAttr->cbValue > SIZE_NAME) {
  1767. lpObj->wError = IPPRSP_ERROR_409;
  1768. } else {
  1769. webFree(lpji->ji2.pDocument);
  1770. lpji->ji2.pDocument = webAllocStr((LPTSTR)lpAttr->lpValue);
  1771. }
  1772. } else if (lstrcmpi(lpAttr->lpszName, s_szDocName) == 0) {
  1773. if (lpAttr->cbValue > SIZE_NAME) {
  1774. lpObj->wError = IPPRSP_ERROR_409;
  1775. } else {
  1776. webFree(lpji->ji2.pDocument);
  1777. lpji->ji2.pDocument = webAllocStr((LPTSTR)lpAttr->lpValue);
  1778. }
  1779. } else if (lstrcmpi(lpAttr->lpszName, s_szJobOrgUser) == 0) {
  1780. if (lpAttr->cbValue > SIZE_NAME) {
  1781. lpObj->wError = IPPRSP_ERROR_409;
  1782. } else {
  1783. webFree(lpji->ji2.pUserName);
  1784. lpji->ji2.pUserName = webAllocStr((LPTSTR)lpAttr->lpValue);
  1785. }
  1786. } else if (lstrcmpi(lpAttr->lpszName, s_szJobReqUser) == 0) {
  1787. if (lpAttr->cbValue > SIZE_NAME) {
  1788. lpObj->wError = IPPRSP_ERROR_409;
  1789. } else {
  1790. webFree(lpji->ji2.pUserName);
  1791. lpji->ji2.pUserName = webAllocStr((LPTSTR)lpAttr->lpValue);
  1792. }
  1793. } else if (lstrcmpi(lpAttr->lpszName, s_szJobUri) == 0) {
  1794. if (lpAttr->cbValue > SIZE_URI) {
  1795. lpObj->wError = IPPRSP_ERROR_409;
  1796. } else {
  1797. webFree(lpji->ipp.pJobUri);
  1798. lpji->ipp.pJobUri = webAllocStr((LPTSTR)lpAttr->lpValue);
  1799. if (bReq && lpji->ipp.pJobUri)
  1800. lpji->ji2.JobId = ipp_JidFromUri(lpji->ipp.pJobUri);
  1801. }
  1802. } else if (lstrcmpi(lpAttr->lpszName, s_szJobPrtUri) == 0) {
  1803. if (lpAttr->cbValue > SIZE_URI) {
  1804. lpObj->wError = IPPRSP_ERROR_409;
  1805. } else {
  1806. webFree(lpji->ipp.pPrnUri);
  1807. lpji->ipp.pPrnUri = webAllocStr((LPTSTR)lpAttr->lpValue);
  1808. }
  1809. } else if (lstrcmpi(lpAttr->lpszName, s_szPrtUri) == 0) {
  1810. if (lpAttr->cbValue > SIZE_URI) {
  1811. lpObj->wError = IPPRSP_ERROR_409;
  1812. } else {
  1813. webFree(lpji->ipp.pPrnUri);
  1814. lpji->ipp.pPrnUri = webAllocStr((LPTSTR)lpAttr->lpValue);
  1815. }
  1816. } else if (lstrcmpi(lpAttr->lpszName, s_szDocFormat) == 0) {
  1817. if (lpAttr->cbValue > SIZE_MIMEMEDIA) {
  1818. lpObj->wError = IPPRSP_ERROR_409;
  1819. } else {
  1820. if (ipp_ValDocFormat((PCTSTR)lpAttr->lpValue) == FALSE)
  1821. lpObj->wError = IPPRSP_ERROR_40A;
  1822. }
  1823. } else if (lstrcmpi(lpAttr->lpszName, s_szAtrFidelity) == 0) {
  1824. if (lpAttr->cbValue != SIZE_BOOLEAN) {
  1825. lpObj->wError = IPPRSP_ERROR_409;
  1826. } else {
  1827. if (ipp_ValAtrFidelity(*(LPDWORD)lpAttr->lpValue, &bFid) == FALSE)
  1828. lpObj->wError = IPPRSP_ERROR_400;
  1829. else
  1830. lpObj->fState |= (bFid ? IPPFLG_USEFIDELITY : 0);
  1831. }
  1832. } else if (lstrcmpi(lpAttr->lpszName, s_szWhichJobs) == 0) {
  1833. if (lpAttr->cbValue > SIZE_KEYWORD) {
  1834. lpObj->wError = IPPRSP_ERROR_409;
  1835. } else {
  1836. if (ipp_ValWhichJobs(fAtr, (PCTSTR)lpAttr->lpValue) == FALSE)
  1837. lpObj->wError = IPPRSP_ERROR_40B;
  1838. }
  1839. } else if (lstrcmpi(lpAttr->lpszName, s_szTimeAtCreation) == 0) {
  1840. if (lpAttr->cbValue != SIZE_INTEGER) {
  1841. lpObj->wError = IPPRSP_ERROR_409;
  1842. } else {
  1843. ipp_IppToW32Time(*(LPDWORD)lpAttr->lpValue, &lpji->ji2.Submitted);
  1844. }
  1845. } else if (bReq && (lstrcmpi(lpAttr->lpszName, s_szReqAttr) == 0)) {
  1846. bAtr = TRUE;
  1847. x_SetReq(fAtr, IPP_REQCLEAR);
  1848. goto ProcessVal;
  1849. } else {
  1850. lpObj->pwlUns->Add(lpAttr->lpszName);
  1851. }
  1852. } else if (bAtr && lpAttr->lpValue) {
  1853. ProcessVal:
  1854. if (lpAttr->cbValue > SIZE_KEYWORD) {
  1855. lpObj->wError = IPPRSP_ERROR_409;
  1856. } else {
  1857. if (lstrcmpi((PCTSTR)lpAttr->lpValue, s_szAll) == 0) {
  1858. x_SetReq(fAtr, IPP_REQALL);
  1859. } else if (lstrcmpi((PCTSTR)lpAttr->lpValue, s_szJobTemplate) == 0) {
  1860. x_SetReq(fAtr, IPP_REQJTMP);
  1861. } else if (lstrcmpi((PCTSTR)lpAttr->lpValue, s_szJobDescription) == 0) {
  1862. x_SetReq(fAtr, IPP_REQJDSC);
  1863. } else {
  1864. //
  1865. // Walk through the possible response attributes
  1866. // and look for those requested.
  1867. //
  1868. cAtr = sizeof(s_PJR) / sizeof(s_PJR[0]);
  1869. for (idx = 0, bFound = FALSE; idx < cAtr; idx++) {
  1870. if (s_PJR[idx].pszNam) {
  1871. if (lstrcmpi((PCTSTR)lpAttr->lpValue, s_PJR[idx].pszNam) == 0) {
  1872. x_SetReq(fAtr, s_PJR[idx].fReq);
  1873. bFound = TRUE;
  1874. break;
  1875. }
  1876. }
  1877. }
  1878. //
  1879. // Look through potential request/response mappings. This
  1880. // is necessary for request that have a different name
  1881. // than that we give back in a response. i.e. JobReqUser
  1882. // verses JobOrgUser.
  1883. //
  1884. if (bFound == FALSE) {
  1885. cAtr = sizeof(s_ReqRspStr) / sizeof(s_ReqRspStr[0]);
  1886. for (idx = 0; idx < cAtr; idx++) {
  1887. if (lstrcmpi((PCTSTR)lpAttr->lpValue, s_ReqRspStr[idx].pszStr) == 0) {
  1888. x_SetReq(fAtr, s_ReqRspStr[idx].fFlag);
  1889. bFound = TRUE;
  1890. break;
  1891. }
  1892. }
  1893. }
  1894. if (!bFound)
  1895. lpObj->pwlUns->Add((PCTSTR)lpAttr->lpValue);
  1896. }
  1897. }
  1898. }
  1899. ipp_RelAttr(lpAttr);
  1900. }
  1901. if (ERROR_RANGE(lpObj->wError))
  1902. break;
  1903. //
  1904. // Advance to next Tag. This routine also increments
  1905. // the (cbIdx) count. If we run out of bytes in the
  1906. // header before we can get to the next-tag, then this
  1907. // will return NULL.
  1908. //
  1909. if (lpbTag = ipp_NextTag(lpObj->lpIppHdr, lpcbIdx, lpObj->cbIppHdr))
  1910. bTag = ipp_ReadByte(lpbTag, 0);
  1911. else
  1912. break;
  1913. }
  1914. //
  1915. // If the fidelity is desired, then we should have
  1916. // no unsupported attributes.
  1917. //
  1918. if (bFid && (lpObj->pwlUns->Count()))
  1919. lpObj->wError = IPPRSP_ERROR_40B;
  1920. //
  1921. // Set the internal-state
  1922. //
  1923. if (bAtr)
  1924. CopyMemory(lpObj->fReq, fAtr, IPPOBJ_MASK_SIZE * sizeof(DWORD));
  1925. return lpbTag;
  1926. }
  1927. /*****************************************************************************\
  1928. * ipp_GetIPPPI2 (Local Routine)
  1929. *
  1930. * Returns the info for a complete job in the IPP stream. We essentially
  1931. * loop through the attributes looking for the next IPP_TAG_DEL_JOB to
  1932. * signify another printer-info-item.
  1933. *
  1934. \*****************************************************************************/
  1935. LPBYTE ipp_GetIPPPI2(
  1936. LPBYTE lpbTag,
  1937. LPIPPPI2 lppi,
  1938. LPDWORD lpcbIdx,
  1939. LPIPPOBJ lpObj)
  1940. {
  1941. LPIPPATTR lpAttr;
  1942. BYTE bTag;
  1943. DWORD cAtr;
  1944. DWORD idx;
  1945. BOOL bReq;
  1946. BOOL bFound;
  1947. DWORD fAtr[IPPOBJ_MASK_SIZE];
  1948. BOOL bAtr = FALSE;
  1949. x_SetReq(fAtr, IPP_REQALL);
  1950. bTag = ipp_ReadByte(lpbTag, 0);
  1951. bReq = ((lpObj->wReq & IPP_RESPONSE) ? FALSE : TRUE);
  1952. while ((bTag != IPP_TAG_DEL_PRINTER) && (bTag != IPP_TAG_DEL_DATA)) {
  1953. if (lpAttr = ipp_GetAttr(lpbTag, *lpcbIdx, lpObj)) {
  1954. //
  1955. // Check the name-type to see how to handle the value.
  1956. //
  1957. if (lpAttr->lpszName && lpAttr->lpValue) {
  1958. if (lstrcmpi(lpAttr->lpszName, s_szPrtUpTime) == 0) {
  1959. if (lpAttr->cbValue != SIZE_INTEGER) {
  1960. lpObj->wError = IPPRSP_ERROR_409;
  1961. } else {
  1962. //
  1963. // What we want to do is get the current time in seconds and then
  1964. // work out what the T0 of the printer must be in this renormalised
  1965. // time
  1966. //
  1967. // These will be positive, we assume [0..2^31-1]
  1968. //
  1969. DWORD dwCurTime = ipp_IppCurTime();
  1970. DWORD dwPrtTime = *(LPDWORD) lpAttr->lpValue;
  1971. lppi->ipp.dwPowerUpTime = (time_t)dwCurTime - (time_t)dwPrtTime;
  1972. }
  1973. } else if (lstrcmpi(lpAttr->lpszName, s_szCharSet) == 0) {
  1974. if (lpAttr->cbValue > SIZE_CHARSET)
  1975. lpObj->wError = IPPRSP_ERROR_409;
  1976. } else if (lstrcmpi(lpAttr->lpszName, s_szNaturalLanguage) == 0) {
  1977. if (lpAttr->cbValue > SIZE_NATLANG)
  1978. lpObj->wError = IPPRSP_ERROR_409;
  1979. } else if (lstrcmpi(lpAttr->lpszName, s_szPrtState) == 0) {
  1980. if (lpAttr->cbValue != SIZE_INTEGER)
  1981. lpObj->wError = IPPRSP_ERROR_409;
  1982. else
  1983. lppi->pi2.Status = ipp_IppToW32PrnState(*(LPDWORD)lpAttr->lpValue);
  1984. } else if (lstrcmpi(lpAttr->lpszName, s_szPrtJobs) == 0) {
  1985. if (lpAttr->cbValue != SIZE_INTEGER)
  1986. lpObj->wError = IPPRSP_ERROR_409;
  1987. else
  1988. lppi->pi2.cJobs = *(LPDWORD)lpAttr->lpValue;
  1989. } else if (lstrcmpi(lpAttr->lpszName, s_szPrtName) == 0) {
  1990. if (lpAttr->cbValue > SIZE_NAME) {
  1991. lpObj->wError = IPPRSP_ERROR_409;
  1992. } else {
  1993. webFree(lppi->pi2.pPrinterName);
  1994. lppi->pi2.pPrinterName = webAllocStr((LPTSTR)lpAttr->lpValue);
  1995. }
  1996. } else if (lstrcmpi(lpAttr->lpszName, s_szPrtUri) == 0) {
  1997. if (lpAttr->cbValue > SIZE_URI) {
  1998. lpObj->wError = IPPRSP_ERROR_409;
  1999. } else {
  2000. webFree(lppi->ipp.pPrnUri);
  2001. lppi->ipp.pPrnUri = webAllocStr((LPTSTR)lpAttr->lpValue);
  2002. }
  2003. } else if (lstrcmpi(lpAttr->lpszName, s_szJobReqUser) == 0) {
  2004. if (lpAttr->cbValue > SIZE_NAME) {
  2005. lpObj->wError = IPPRSP_ERROR_409;
  2006. } else {
  2007. webFree(lppi->ipp.pUsrName);
  2008. lppi->ipp.pUsrName = webAllocStr((LPTSTR)lpAttr->lpValue);
  2009. }
  2010. } else if (lstrcmpi(lpAttr->lpszName, s_szPrtUriSupported) == 0) {
  2011. if (lpAttr->cbValue > SIZE_URI) {
  2012. lpObj->wError = IPPRSP_ERROR_409;
  2013. } else {
  2014. webFree(lppi->ipp.pPrnUri);
  2015. lppi->ipp.pPrnUri = webAllocStr((LPTSTR)lpAttr->lpValue);
  2016. }
  2017. } else if (lstrcmpi(lpAttr->lpszName, s_szPrtMake) == 0) {
  2018. if (lpAttr->cbValue > SIZE_TEXT) {
  2019. lpObj->wError = IPPRSP_ERROR_409;
  2020. } else {
  2021. webFree(lppi->pi2.pDriverName);
  2022. lppi->pi2.pDriverName = webAllocStr((LPTSTR)lpAttr->lpValue);
  2023. }
  2024. } else if (lstrcmpi(lpAttr->lpszName, s_szDocFormat) == 0) {
  2025. if (lpAttr->cbValue > SIZE_MIMEMEDIA) {
  2026. lpObj->wError = IPPRSP_ERROR_409;
  2027. } else {
  2028. if (ipp_ValDocFormat((PCTSTR)lpAttr->lpValue) == FALSE)
  2029. lpObj->wError = IPPRSP_ERROR_40A;
  2030. }
  2031. } else if (lstrcmpi(lpAttr->lpszName, s_szJobReqUser) == 0) {
  2032. if (lpAttr->cbValue > SIZE_NAME)
  2033. lpObj->wError = IPPRSP_ERROR_409;
  2034. } else if (bReq && (lstrcmpi(lpAttr->lpszName, s_szReqAttr) == 0)) {
  2035. bAtr = TRUE;
  2036. x_SetReq(fAtr, IPP_REQCLEAR);
  2037. goto ProcessVal;
  2038. } else {
  2039. lpObj->pwlUns->Add(lpAttr->lpszName);
  2040. }
  2041. } else if (bAtr && lpAttr->lpValue) {
  2042. ProcessVal:
  2043. if (lpAttr->cbValue > SIZE_KEYWORD) {
  2044. lpObj->wError = IPPRSP_ERROR_409;
  2045. } else {
  2046. if (lstrcmpi((PCTSTR)lpAttr->lpValue, s_szAll) == 0) {
  2047. x_SetReq(fAtr, IPP_REQALL);
  2048. } else if (lstrcmpi((PCTSTR)lpAttr->lpValue, s_szJobTemplate) == 0) {
  2049. x_SetReq(fAtr, IPP_REQPTMP);
  2050. } else if (lstrcmpi((PCTSTR)lpAttr->lpValue, s_szPrtDescription) == 0) {
  2051. x_SetReq(fAtr, IPP_REQPDSC);
  2052. } else {
  2053. //
  2054. // Walk through the possible response attributes
  2055. // and look for those requested.
  2056. //
  2057. cAtr = sizeof(s_GPR) / sizeof(s_GPR[0]);
  2058. for (idx = 0, bFound = FALSE; idx < cAtr; idx++) {
  2059. if (s_GPR[idx].pszNam) {
  2060. if (lstrcmpi((PCTSTR)lpAttr->lpValue, s_GPR[idx].pszNam) == 0) {
  2061. x_SetReq(fAtr, s_GPR[idx].fReq);
  2062. bFound = TRUE;
  2063. break;
  2064. }
  2065. }
  2066. }
  2067. //
  2068. // Look through potential request/response mappings. This
  2069. // is necessary for request that have a different name
  2070. // than that we give back in a response. i.e. JobReqUser
  2071. // verses JobOrgUser.
  2072. //
  2073. if (bFound == FALSE) {
  2074. cAtr = sizeof(s_ReqRspStr) / sizeof(s_ReqRspStr[0]);
  2075. for (idx = 0; idx < cAtr; idx++) {
  2076. if (lstrcmpi((PCTSTR)lpAttr->lpValue, s_ReqRspStr[idx].pszStr) == 0)
  2077. x_SetReq(fAtr, s_ReqRspStr[idx].fFlag);
  2078. }
  2079. }
  2080. if (!bFound)
  2081. lpObj->pwlUns->Add((PCTSTR)lpAttr->lpValue);
  2082. }
  2083. }
  2084. }
  2085. ipp_RelAttr(lpAttr);
  2086. }
  2087. if (ERROR_RANGE(lpObj->wError))
  2088. break;
  2089. //
  2090. // Advance to next Tag. This routine also increments
  2091. // the (cbIdx) count. If we run out of bytes in the
  2092. // header before we can get to the next-tag, then this
  2093. // will return NULL.
  2094. //
  2095. if (lpbTag = ipp_NextTag(lpObj->lpIppHdr, lpcbIdx, lpObj->cbIppHdr))
  2096. bTag = ipp_ReadByte(lpbTag, 0);
  2097. else
  2098. break;
  2099. }
  2100. //
  2101. // Set the internal-state
  2102. //
  2103. if (bAtr)
  2104. CopyMemory(lpObj->fReq, fAtr, IPPOBJ_MASK_SIZE * sizeof(DWORD));
  2105. return lpbTag;
  2106. }
  2107. /*****************************************************************************\
  2108. * ipp_CopyJI2toIPPJI2 (Local Routine)
  2109. *
  2110. * Copies a JOB_INFO_2 to IPPJI2.
  2111. *
  2112. \*****************************************************************************/
  2113. LPBYTE ipp_CopyJI2toIPPJI2(
  2114. LPIPPJI2 lpjiDst,
  2115. LPJOB_INFO_2 lpJI2,
  2116. LPTSTR lpszJobBase,
  2117. LPBYTE lpbEnd)
  2118. {
  2119. LPTSTR* lpszSrc;
  2120. LPTSTR lpszPtr;
  2121. LPTSTR lpszJobUri;
  2122. LPTSTR lpszPrnUri;
  2123. LPTSTR aszSrc[(sizeof(IPPJI2) / sizeof(LPTSTR))];
  2124. //
  2125. // Set the start of the string-buffer.
  2126. //
  2127. ZeroMemory(aszSrc , sizeof(aszSrc));
  2128. ZeroMemory(lpjiDst, sizeof(IPPJI2));
  2129. //
  2130. // Copy fixed values.
  2131. //
  2132. lpjiDst->ji2.JobId = lpJI2->JobId;
  2133. lpjiDst->ji2.Status = ipp_W32ToIppJobState(lpJI2->Status);
  2134. lpjiDst->ji2.Priority = ipp_W32ToIppJobPriority(lpJI2->Priority);
  2135. lpjiDst->ji2.Size = ipp_W32ToIppJobSize(lpJI2->Size);
  2136. lpjiDst->ji2.TotalPages = ipp_W32ToIppJobTotalPages(lpJI2->TotalPages);
  2137. lpjiDst->ji2.PagesPrinted = ipp_W32ToIppJobPagesPrinted(lpJI2->PagesPrinted);
  2138. *((LPDWORD)&lpjiDst->ji2.Submitted) = ipp_W32ToIppTime(&lpJI2->Submitted);
  2139. //
  2140. // Build a job-uri.
  2141. //
  2142. if (lpszJobUri = (LPTSTR)webAlloc(webStrSize(lpszJobBase) + 80))
  2143. StringCbPrintf(lpszJobUri, webStrSize(lpszJobBase)+80, TEXT("%s%d"), lpszJobBase, lpJI2->JobId);
  2144. //
  2145. // Build a printer-uri.
  2146. //
  2147. lpszPrnUri = NULL;
  2148. if (lpszJobBase && (lpszPtr = webFindRChar(lpszJobBase, TEXT('?')))) {
  2149. *lpszPtr = TEXT('\0');
  2150. lpszPrnUri = (LPTSTR)webAllocStr(lpszJobBase);
  2151. *lpszPtr = TEXT('?');
  2152. }
  2153. //
  2154. // Copy strings. Make sure we place the strings in the appropriate
  2155. // offset.
  2156. //
  2157. lpszSrc = aszSrc;
  2158. *lpszSrc++ = lpJI2->pPrinterName;
  2159. *lpszSrc++ = lpJI2->pMachineName;
  2160. *lpszSrc++ = lpJI2->pUserName;
  2161. *lpszSrc++ = lpJI2->pDocument;
  2162. *lpszSrc++ = lpJI2->pNotifyName;
  2163. *lpszSrc++ = lpJI2->pDatatype;
  2164. *lpszSrc++ = lpJI2->pPrintProcessor;
  2165. *lpszSrc++ = lpJI2->pParameters;
  2166. *lpszSrc++ = lpJI2->pDriverName;
  2167. *lpszSrc++ = NULL;
  2168. *lpszSrc++ = lpJI2->pStatus;
  2169. *lpszSrc++ = NULL;
  2170. *lpszSrc++ = lpszPrnUri;
  2171. *lpszSrc++ = lpszJobUri;
  2172. lpbEnd = ipp_PackStrings(aszSrc, (LPBYTE)lpjiDst, s_IPPJI2Offs, lpbEnd);
  2173. webFree(lpszJobUri);
  2174. webFree(lpszPrnUri);
  2175. return lpbEnd;
  2176. }
  2177. /*****************************************************************************\
  2178. * ipp_SizeofIPPPI2 (Local Routine)
  2179. *
  2180. * Returns the size necessary to store a IPPPI2 struct. This excludes the
  2181. * DEVMODE and SECURITYDESCRIPTOR fields.
  2182. *
  2183. \*****************************************************************************/
  2184. DWORD ipp_SizeofIPPPI2(
  2185. LPPRINTER_INFO_2 lppi2,
  2186. LPPRINTER_INFO_IPP lpipp)
  2187. {
  2188. DWORD cCnt;
  2189. DWORD idx;
  2190. DWORD cbSize;
  2191. LPTSTR lpszStr;
  2192. //
  2193. // Default Size.
  2194. //
  2195. cbSize = 0;
  2196. //
  2197. // Get the size necessary for PRINTER_INFO_2 structure.
  2198. //
  2199. if (lppi2) {
  2200. cCnt = ((sizeof(s_PI2Off) / sizeof(s_PI2Off[0])) - 1);
  2201. for (idx = 0; idx < cCnt; idx++) {
  2202. lpszStr = *(LPTSTR*)(((LPBYTE)lppi2) + s_PI2Off[idx]);
  2203. cbSize += (lpszStr ? webStrSize(lpszStr) : 0);
  2204. }
  2205. }
  2206. //
  2207. // Get the size necessary for PRINTER_INFO_IPP structure.
  2208. //
  2209. if (lpipp) {
  2210. cCnt = ((sizeof(s_IPPOff) / sizeof(s_IPPOff[0])) - 1);
  2211. for (idx = 0; idx < cCnt; idx++) {
  2212. lpszStr = *(LPTSTR*)(((LPBYTE)lpipp) + s_IPPOff[idx]);
  2213. cbSize += (lpszStr ? webStrSize(lpszStr) : 0);
  2214. }
  2215. }
  2216. return cbSize;
  2217. }
  2218. /*****************************************************************************\
  2219. * ipp_SizeofIPPJI2 (Local Routine)
  2220. *
  2221. * Returns the size necessary to store a IPPJI2 struct. This excludes the
  2222. * DEVMODE and SECURITYDESCRIPTOR fields.
  2223. *
  2224. \*****************************************************************************/
  2225. DWORD ipp_SizeofIPPJI2(
  2226. LPJOB_INFO_2 lpji2,
  2227. LPJOB_INFO_IPP lpipp)
  2228. {
  2229. DWORD cCnt;
  2230. DWORD idx;
  2231. DWORD cbSize;
  2232. LPTSTR lpszStr;
  2233. //
  2234. // Default Size.
  2235. //
  2236. cbSize = 0;
  2237. //
  2238. // Get the size necessary for JOB_INFO_2 structure.
  2239. //
  2240. if (lpji2) {
  2241. cCnt = ((sizeof(s_JI2Off) / sizeof(s_JI2Off[0])) - 1);
  2242. for (idx = 0; idx < cCnt; idx++) {
  2243. lpszStr = *(LPTSTR*)(((LPBYTE)lpji2) + s_JI2Off[idx]);
  2244. cbSize += (lpszStr ? webStrSize(lpszStr) : 0);
  2245. }
  2246. }
  2247. //
  2248. // Get the size necessary for JOB_INFO_IPP structure.
  2249. //
  2250. if (lpipp) {
  2251. cCnt = ((sizeof(s_IPJOff) / sizeof(s_IPJOff[0])) - 1);
  2252. for (idx = 0; idx < cCnt; idx++) {
  2253. lpszStr = *(LPTSTR*)(((LPBYTE)lpipp) + s_IPJOff[idx]);
  2254. cbSize += (lpszStr ? webStrSize(lpszStr) : 0);
  2255. }
  2256. }
  2257. return cbSize;
  2258. }
  2259. /*****************************************************************************\
  2260. * ipp_BuildPI2 (Local Routine)
  2261. *
  2262. * Builds a IPPPI2 struct from PRINTER_INFO_2 and PRINTER_INFO_IPP.
  2263. *
  2264. \*****************************************************************************/
  2265. LPBYTE ipp_BuildPI2(
  2266. LPIPPPI2 lppi,
  2267. LPPRINTER_INFO_2 lppi2,
  2268. LPPRINTER_INFO_IPP lpipp,
  2269. LPBYTE lpbEnd)
  2270. {
  2271. LPTSTR* lpszSrc;
  2272. LPTSTR aszSrc[(sizeof(IPPPI2) / sizeof(LPTSTR))];
  2273. //
  2274. // Set the start of the string-buffer.
  2275. //
  2276. ZeroMemory(aszSrc, sizeof(aszSrc));
  2277. ZeroMemory(lppi , sizeof(IPPPI2));
  2278. //
  2279. // Copy fixed values.
  2280. //
  2281. if (lppi2) {
  2282. lppi->pi2.Attributes = lppi2->Attributes;
  2283. lppi->pi2.Priority = lppi2->Priority;
  2284. lppi->pi2.DefaultPriority = lppi2->DefaultPriority;
  2285. lppi->pi2.StartTime = lppi2->StartTime;
  2286. lppi->pi2.UntilTime = lppi2->UntilTime;
  2287. lppi->pi2.Status = lppi2->Status;
  2288. lppi->pi2.cJobs = lppi2->cJobs;
  2289. lppi->pi2.AveragePPM = lppi2->AveragePPM;
  2290. }
  2291. lppi->ipp.dwPowerUpTime = (lpipp ? lpipp->dwPowerUpTime : 0);
  2292. //
  2293. // Copy strings. Make sure we place the strings in the appropriate
  2294. // offset.
  2295. //
  2296. lpszSrc = aszSrc;
  2297. *lpszSrc++ = (lppi2 ? lppi2->pServerName : NULL);
  2298. *lpszSrc++ = (lppi2 ? lppi2->pPrinterName : NULL);
  2299. *lpszSrc++ = (lppi2 ? lppi2->pShareName : NULL);
  2300. *lpszSrc++ = (lppi2 ? lppi2->pPortName : NULL);
  2301. *lpszSrc++ = (lppi2 ? lppi2->pDriverName : NULL);
  2302. *lpszSrc++ = (lppi2 ? lppi2->pComment : NULL);
  2303. *lpszSrc++ = (lppi2 ? lppi2->pLocation : NULL);
  2304. *lpszSrc++ = NULL;
  2305. *lpszSrc++ = (lppi2 ? lppi2->pSepFile : NULL);
  2306. *lpszSrc++ = (lppi2 ? lppi2->pPrintProcessor : NULL);
  2307. *lpszSrc++ = (lppi2 ? lppi2->pDatatype : NULL);
  2308. *lpszSrc++ = (lppi2 ? lppi2->pParameters : NULL);
  2309. *lpszSrc++ = NULL;
  2310. *lpszSrc++ = (lpipp ? lpipp->pPrnUri : NULL);
  2311. *lpszSrc++ = (lpipp ? lpipp->pUsrName : NULL);
  2312. return ipp_PackStrings(aszSrc, (LPBYTE)lppi, s_IPPPI2Offs, lpbEnd);
  2313. }
  2314. /*****************************************************************************\
  2315. * ipp_BuildJI2 (Local Routine)
  2316. *
  2317. * Builds a IPPJI2 struct from JOB_INFO_2 and JOB_INFO_IPP.
  2318. *
  2319. \*****************************************************************************/
  2320. LPBYTE ipp_BuildJI2(
  2321. LPIPPJI2 lpji,
  2322. LPJOB_INFO_2 lpji2,
  2323. LPJOB_INFO_IPP lpipp,
  2324. LPBYTE lpbEnd)
  2325. {
  2326. LPTSTR* lpszSrc;
  2327. LPTSTR aszSrc[(sizeof(IPPJI2) / sizeof(LPTSTR))];
  2328. //
  2329. // Set the start of the string-buffer.
  2330. //
  2331. ZeroMemory(aszSrc, sizeof(aszSrc));
  2332. ZeroMemory(lpji, sizeof(IPPJI2));
  2333. //
  2334. // Copy fixed values.
  2335. //
  2336. if (lpji2) {
  2337. lpji->ji2.JobId = lpji2->JobId;
  2338. lpji->ji2.Status = lpji2->Status;
  2339. lpji->ji2.Priority = lpji2->Priority;
  2340. lpji->ji2.Position = lpji2->Position;
  2341. lpji->ji2.StartTime = lpji2->StartTime;
  2342. lpji->ji2.UntilTime = lpji2->UntilTime;
  2343. lpji->ji2.TotalPages = lpji2->TotalPages;
  2344. lpji->ji2.Size = lpji2->Size;
  2345. lpji->ji2.Time = lpji2->Time;
  2346. lpji->ji2.PagesPrinted = lpji2->PagesPrinted;
  2347. lpji->ji2.StartTime = lpji2->StartTime;
  2348. CopyMemory(&lpji->ji2.Submitted, &lpji2->Submitted, sizeof(SYSTEMTIME));
  2349. }
  2350. //
  2351. // Copy strings. Make sure we place the strings in the appropriate
  2352. // offset.
  2353. //
  2354. lpszSrc = aszSrc;
  2355. *lpszSrc++ = (lpji2 ? lpji2->pPrinterName : NULL);
  2356. *lpszSrc++ = (lpji2 ? lpji2->pMachineName : NULL);
  2357. *lpszSrc++ = (lpji2 ? lpji2->pUserName : NULL);
  2358. *lpszSrc++ = (lpji2 ? lpji2->pDocument : NULL);
  2359. *lpszSrc++ = (lpji2 ? lpji2->pNotifyName : NULL);
  2360. *lpszSrc++ = (lpji2 ? lpji2->pDatatype : NULL);
  2361. *lpszSrc++ = (lpji2 ? lpji2->pPrintProcessor : NULL);
  2362. *lpszSrc++ = (lpji2 ? lpji2->pParameters : NULL);
  2363. *lpszSrc++ = (lpji2 ? lpji2->pDriverName : NULL);
  2364. *lpszSrc++ = NULL;
  2365. *lpszSrc++ = (lpji2 ? lpji2->pStatus : NULL);
  2366. *lpszSrc++ = NULL;
  2367. *lpszSrc++ = (lpipp ? lpipp->pPrnUri : NULL);
  2368. *lpszSrc++ = (lpipp ? lpipp->pJobUri : NULL);
  2369. return ipp_PackStrings(aszSrc, (LPBYTE)lpji, s_IPPJI2Offs, lpbEnd);
  2370. }
  2371. /*****************************************************************************\
  2372. * ipp_GetJobCount (Local Routine)
  2373. *
  2374. * Returns the total number of jobs in an enumerated GETJOB response.
  2375. *
  2376. \*****************************************************************************/
  2377. DWORD ipp_GetJobCount(
  2378. LPBYTE lpbHdr,
  2379. DWORD cbHdr)
  2380. {
  2381. DWORD cbIdx;
  2382. LPBYTE lpbTag;
  2383. DWORD cJobs = 0;
  2384. //
  2385. // Position the tag at the start of the header.
  2386. //
  2387. lpbTag = lpbHdr + IPP_SIZEOFHDR;
  2388. for (cbIdx = IPP_SIZEOFHDR; lpbTag && (ipp_ReadByte(lpbTag, 0) != IPP_TAG_DEL_DATA); ) {
  2389. //
  2390. // If we hit a job-deliminator, then we have a job-info item.
  2391. //
  2392. if (ipp_ReadByte(lpbTag, 0) == IPP_TAG_DEL_JOB)
  2393. cJobs++;
  2394. //
  2395. // Advance to next Tag. This routine also increments
  2396. // the (cbIdx) count. If we run out of bytes in the
  2397. // header before we can get to the next-tag, then this
  2398. // will return NULL.
  2399. //
  2400. lpbTag = ipp_NextTag(lpbHdr, &cbIdx, cbHdr);
  2401. }
  2402. return cJobs;
  2403. }
  2404. /*****************************************************************************\
  2405. * ipp_IppToW32 (Local Routine - Client/Server)
  2406. *
  2407. * Converts an Ipp-Header to a W32-Structure.
  2408. *
  2409. \*****************************************************************************/
  2410. DWORD ipp_IppToW32(
  2411. LPIPPOBJ lpObj,
  2412. LPBYTE* lplpRawHdr,
  2413. LPDWORD lpcbRawHdr)
  2414. {
  2415. DWORD cbIdx;
  2416. DWORD dwCmd;
  2417. IPPJI2 ji;
  2418. IPPPI2 pi;
  2419. PIPPREQ_ALL pr;
  2420. UINT uType = IPPTYPE_UNKNOWN;
  2421. DWORD dwRet = WEBIPP_FAIL;
  2422. //
  2423. // Position the tag at the Tag/Attributes and fetch the information
  2424. // for the request.
  2425. //
  2426. cbIdx = IPP_SIZEOFHDR;
  2427. switch (lpObj->wReq) {
  2428. case IPP_REQ_PRINTJOB:
  2429. case IPP_REQ_VALIDATEJOB:
  2430. case IPP_REQ_GETJOB:
  2431. case IPP_REQ_CANCELJOB:
  2432. case IPP_REQ_PAUSEJOB:
  2433. case IPP_REQ_RESUMEJOB:
  2434. case IPP_REQ_RESTARTJOB:
  2435. case IPP_REQ_ENUJOB:
  2436. ZeroMemory(&ji, sizeof(IPPJI2));
  2437. ji.ipp.cJobs = IPP_GETJOB_ALL;
  2438. ipp_GetIPPJI2(lpObj->lpIppHdr + IPP_SIZEOFHDR, &ji, &cbIdx, lpObj);
  2439. uType = IPPTYPE_JOB;
  2440. break;
  2441. case IPP_REQ_GETPRN:
  2442. case IPP_REQ_PAUSEPRN:
  2443. case IPP_REQ_CANCELPRN:
  2444. case IPP_REQ_RESUMEPRN:
  2445. ZeroMemory(&pi, sizeof(IPPPI2));
  2446. ipp_GetIPPPI2(lpObj->lpIppHdr + IPP_SIZEOFHDR, &pi, &cbIdx, lpObj);
  2447. uType = IPPTYPE_PRT;
  2448. break;
  2449. case IPP_REQ_FORCEAUTH:
  2450. uType = IPPTYPE_AUTH;
  2451. break;
  2452. }
  2453. //
  2454. // If a failure occured, then there's no need to proceed.
  2455. //
  2456. if (ERROR_RANGE(lpObj->wError))
  2457. goto EndCvt;
  2458. //
  2459. // Initialize any default-values, that may have been overlooked
  2460. // in the request-stream.
  2461. //
  2462. switch (uType) {
  2463. case IPPTYPE_JOB:
  2464. if (ji.ji2.pUserName == NULL)
  2465. ji.ji2.pUserName = webAllocStr(s_szUnknown);
  2466. if (ji.ji2.pDocument == NULL)
  2467. ji.ji2.pDocument = webAllocStr(s_szUnknown);
  2468. break;
  2469. case IPPTYPE_PRT:
  2470. if (pi.pi2.pPrinterName == NULL)
  2471. pi.pi2.pPrinterName = webAllocStr(s_szUnknown);
  2472. break;
  2473. }
  2474. //
  2475. // Build the request structure based upon the request command.
  2476. //
  2477. switch (lpObj->wReq) {
  2478. case IPP_REQ_PRINTJOB:
  2479. pr = (PIPPREQ_ALL)WebIppCreatePrtJobReq(FALSE, ji.ji2.pUserName, ji.ji2.pDocument, ji.ipp.pPrnUri);
  2480. break;
  2481. case IPP_REQ_VALIDATEJOB:
  2482. pr = (PIPPREQ_ALL)WebIppCreatePrtJobReq(TRUE, ji.ji2.pUserName, ji.ji2.pDocument, ji.ipp.pPrnUri);
  2483. break;
  2484. case IPP_REQ_ENUJOB:
  2485. pr = (PIPPREQ_ALL)WebIppCreateEnuJobReq(ji.ipp.cJobs, ji.ipp.pPrnUri);
  2486. break;
  2487. case IPP_REQ_CANCELJOB:
  2488. case IPP_REQ_PAUSEJOB:
  2489. case IPP_REQ_RESUMEJOB:
  2490. case IPP_REQ_RESTARTJOB:
  2491. dwCmd = ipp_MapReqToJobCmd(lpObj->wReq);
  2492. pr = (PIPPREQ_ALL)WebIppCreateSetJobReq(ji.ji2.JobId, dwCmd, ji.ipp.pPrnUri);
  2493. break;
  2494. case IPP_REQ_GETJOB:
  2495. pr = (PIPPREQ_ALL)WebIppCreateGetJobReq(ji.ji2.JobId, ji.ipp.pPrnUri);
  2496. break;
  2497. case IPP_REQ_GETPRN:
  2498. pr = (PIPPREQ_ALL)WebIppCreateGetPrnReq(0, pi.ipp.pPrnUri);
  2499. break;
  2500. case IPP_REQ_PAUSEPRN:
  2501. case IPP_REQ_CANCELPRN:
  2502. case IPP_REQ_RESUMEPRN:
  2503. dwCmd = ipp_MapReqToPrnCmd(lpObj->wReq);
  2504. pr = (PIPPREQ_ALL)WebIppCreateSetPrnReq(dwCmd, pi.ipp.pUsrName, pi.ipp.pPrnUri);
  2505. break;
  2506. case IPP_REQ_FORCEAUTH:
  2507. pr = (PIPPREQ_AUTH)WebIppCreateAuthReq();
  2508. break;
  2509. default:
  2510. pr = NULL;
  2511. break;
  2512. }
  2513. //
  2514. // Set the return values.
  2515. //
  2516. if (pr) {
  2517. *lplpRawHdr = (LPBYTE)pr;
  2518. *lpcbRawHdr = pr->cbSize;
  2519. dwRet = WEBIPP_OK;
  2520. } else {
  2521. dwRet = WEBIPP_NOMEMORY;
  2522. }
  2523. EndCvt:
  2524. //
  2525. // Cleanup.
  2526. //
  2527. switch (uType) {
  2528. case IPPTYPE_JOB:
  2529. ipp_FreeIPPJI2(&ji);
  2530. break;
  2531. case IPPTYPE_PRT:
  2532. ipp_FreeIPPPI2(&pi);
  2533. break;
  2534. }
  2535. return dwRet;
  2536. }
  2537. /*****************************************************************************\
  2538. * ipp_W32ToIpp (Local Routine - Client/Server)
  2539. *
  2540. * Converts a W32 information to an IPP Header (both request and responses).
  2541. *
  2542. \*****************************************************************************/
  2543. DWORD ipp_W32ToIpp(
  2544. WORD wReq,
  2545. LPREQINFO lpri,
  2546. LPBYTE lpbData,
  2547. LPIPPATTRX pSnd,
  2548. DWORD cSnd,
  2549. LPBYTE* lplpIppHdr,
  2550. LPDWORD lpcbIppHdr)
  2551. {
  2552. LPIPPRET_ENUJOB pej;
  2553. LPBYTE lpIppHdr;
  2554. LPBYTE lpIppPtr;
  2555. DWORD cbIppHdr;
  2556. LPIPPJI2 lpji;
  2557. DWORD cUns;
  2558. DWORD idx;
  2559. DWORD cbSize;
  2560. DWORD dwRet;
  2561. DWORD dwState;
  2562. DWORD cbUns;
  2563. WORD wOut;
  2564. LPIPPATTRY pAtr = NULL;
  2565. LPIPPATTRY pUns = NULL;
  2566. //
  2567. // Zero out our return pointer/count.
  2568. //
  2569. *lplpIppHdr = NULL;
  2570. *lpcbIppHdr = 0;
  2571. //
  2572. // Is this a request or response.
  2573. //
  2574. if (wReq & IPP_RESPONSE) {
  2575. if (((LPIPPRET_ALL)lpbData)->wRsp == IPPRSP_SUCCESS) {
  2576. wOut = ((lpri->pwlUns && lpri->pwlUns->Count()) ? IPPRSP_SUCCESS1 : IPPRSP_SUCCESS);
  2577. } else {
  2578. wOut = ((LPIPPRET_ALL)lpbData)->wRsp;
  2579. }
  2580. } else {
  2581. wOut = wReq;
  2582. }
  2583. //
  2584. // Minimum header size.
  2585. //
  2586. cbIppHdr = ipp_SizeHdr(lpri->cpReq) + IPP_SIZEOFTAG;
  2587. //
  2588. // Treat the EnumJob response differently from the others, since this
  2589. // returns a dynamic list of jobs.
  2590. //
  2591. if (wReq == IPP_RET_ENUJOB) {
  2592. //
  2593. // Build the unsupported-attributes if there
  2594. // are any.
  2595. //
  2596. cbUns = 0;
  2597. pUns = ipp_AllocUnsVals(lpri->pwlUns, &cUns, &cbUns);
  2598. pej = (PIPPRET_ENUJOB)lpbData;
  2599. cbSize = cbIppHdr +
  2600. cbUns +
  2601. ((pej->cItems && pej->cbItems) ? (3 * pej->cbItems) : 0);
  2602. if (lpIppHdr = (LPBYTE)webAlloc(cbSize)) {
  2603. cbIppHdr += cbUns;
  2604. lpIppPtr = lpIppHdr;
  2605. //
  2606. // Output the ipp-stream.
  2607. //
  2608. ipp_WriteHead(&lpIppPtr, wOut, lpri->idReq, lpri->cpReq);
  2609. ipp_WriteUnsVals(&lpIppPtr, pUns, cUns);
  2610. for (idx = 0, lpji = pej->pItems; idx < pej->cItems; idx++) {
  2611. dwState = ipp_IppToW32JobState(lpji[idx].ji2.Status);
  2612. //
  2613. // Check for any requested-attributes that include this job-entry.
  2614. //
  2615. if ((x_ChkReq(lpri->fReq, RA_JOBSCOMPLETED) && (dwState & JOB_STATUS_PRINTED)) ||
  2616. (x_ChkReq(lpri->fReq, RA_JOBSUNCOMPLETED) && !(dwState & JOB_STATUS_PRINTED)) ||
  2617. (x_ChkReq(lpri->fReq, (RA_JOBSCOMPLETED | RA_JOBSUNCOMPLETED)) == FALSE)) {
  2618. if (pAtr = ipp_AllocAtrVals(wReq, lpri->fReq, lpri->cpReq, (LPBYTE)&lpji[idx], pSnd, cSnd, &cbIppHdr)) {
  2619. ipp_WriteAtrVals(wReq, lpri->fReq, &lpIppPtr, pSnd, pAtr, cSnd);
  2620. ipp_FreeAtrVals(pAtr, cSnd);
  2621. }
  2622. }
  2623. }
  2624. ipp_WriteByte(&lpIppPtr, IPP_TAG_DEL_DATA);
  2625. //
  2626. // Set the return values for the IPP-Stream-Header
  2627. // as well as the size.
  2628. //
  2629. dwRet = WEBIPP_OK;
  2630. *lplpIppHdr = lpIppHdr;
  2631. *lpcbIppHdr = cbIppHdr;
  2632. } else {
  2633. dwRet = WEBIPP_NOMEMORY;
  2634. }
  2635. ipp_FreeAtrVals(pUns, cUns);
  2636. } else {
  2637. if ((cSnd == 0) ||
  2638. (pAtr = ipp_AllocAtrVals(wReq, lpri->fReq, lpri->cpReq, lpbData, pSnd, cSnd, &cbIppHdr))) {
  2639. //
  2640. // Build the unsupported-attributes if there
  2641. // are any.
  2642. //
  2643. pUns = ipp_AllocUnsVals(lpri->pwlUns, &cUns, &cbIppHdr);
  2644. //
  2645. // Write the IPP-Stream.
  2646. //
  2647. if (lpIppHdr = (LPBYTE)webAlloc(cbIppHdr)) {
  2648. lpIppPtr = lpIppHdr;
  2649. ipp_WriteHead(&lpIppPtr, wOut, lpri->idReq, lpri->cpReq);
  2650. ipp_WriteUnsVals(&lpIppPtr, pUns, cUns);
  2651. ipp_WriteAtrVals(wReq, lpri->fReq, &lpIppPtr, pSnd, pAtr, cSnd);
  2652. ipp_WriteByte(&lpIppPtr, IPP_TAG_DEL_DATA);
  2653. //
  2654. // Set the return values for the IPP-Stream-Header
  2655. // as well as the size.
  2656. //
  2657. dwRet = WEBIPP_OK;
  2658. *lplpIppHdr = lpIppHdr;
  2659. *lpcbIppHdr = cbIppHdr;
  2660. } else {
  2661. dwRet = WEBIPP_NOMEMORY;
  2662. }
  2663. if (pUns)
  2664. {
  2665. ipp_FreeAtrVals(pUns, cUns);
  2666. }
  2667. if (pAtr)
  2668. {
  2669. ipp_FreeAtrVals(pAtr, cSnd);
  2670. }
  2671. } else {
  2672. dwRet = WEBIPP_NOMEMORY;
  2673. }
  2674. }
  2675. return dwRet;
  2676. }
  2677. /*****************************************************************************\
  2678. * ipp_IppToFailure (Local Routine - Client)
  2679. *
  2680. * Converts an Ipp-Header to a IPPRET_ALL From the stream we need
  2681. * to pull out the following information:
  2682. *
  2683. \*****************************************************************************/
  2684. DWORD ipp_IppToFailure(
  2685. LPIPPOBJ lpObj,
  2686. LPBYTE* lplpRawHdr,
  2687. LPDWORD lpcbRawHdr)
  2688. {
  2689. PIPPRET_ALL pbr;
  2690. WORD wRsp;
  2691. BOOL bRet;
  2692. DWORD dwRet;
  2693. //
  2694. // Pull out the response.
  2695. //
  2696. wRsp = ipp_ReadWord(lpObj->lpIppHdr, IPP_SIZEOFVER);
  2697. bRet = SUCCESS_RANGE(wRsp);
  2698. //
  2699. // Build the response structure.
  2700. //
  2701. if (pbr = WebIppCreateBadRet(wRsp, bRet)) {
  2702. *lplpRawHdr = (LPBYTE)pbr;
  2703. *lpcbRawHdr = pbr->cbSize;
  2704. dwRet = WEBIPP_OK;
  2705. } else {
  2706. dwRet = WEBIPP_NOMEMORY;
  2707. }
  2708. return dwRet;
  2709. }
  2710. /*****************************************************************************\
  2711. * ipp_IppToJobRet (Local Routine - Client)
  2712. *
  2713. * Converts an Ipp-Header to a IPPRET_JOB. From the stream we need
  2714. * to pull out the following information:
  2715. *
  2716. \*****************************************************************************/
  2717. DWORD ipp_IppToJobRet(
  2718. LPIPPOBJ lpObj,
  2719. LPBYTE* lplpRawHdr,
  2720. LPDWORD lpcbRawHdr)
  2721. {
  2722. LPBYTE lpbTag;
  2723. PIPPRET_JOB pj;
  2724. WORD wRsp;
  2725. IPPJI2 ji;
  2726. DWORD cbIdx;
  2727. BOOL bRet;
  2728. DWORD dwRet;
  2729. BOOL bValidate = FALSE;
  2730. //
  2731. // Set our default-settings necessary for our PIPPRET_JOB.
  2732. //
  2733. ZeroMemory(&ji, sizeof(IPPJI2));
  2734. //
  2735. // Position the tag at the Tag/Attributes.
  2736. //
  2737. lpbTag = lpObj->lpIppHdr + IPP_SIZEOFHDR;
  2738. //
  2739. // Pull out the response.
  2740. //
  2741. wRsp = ipp_ReadWord(lpObj->lpIppHdr, IPP_SIZEOFVER);
  2742. //
  2743. // If this is a failure-response then call the routine to
  2744. // generate a failure-structure.
  2745. //
  2746. if (SUCCESS_RANGE(wRsp) == FALSE)
  2747. return ipp_IppToFailure(lpObj, lplpRawHdr, lpcbRawHdr);
  2748. //
  2749. // Traverse through the header, advancing through the attributes,
  2750. // until the IPP_TAG_DEL_DATA is encountered.
  2751. //
  2752. for (cbIdx = IPP_SIZEOFHDR; lpbTag && (ipp_ReadByte(lpbTag, 0) != IPP_TAG_DEL_DATA); ) {
  2753. //
  2754. // Look for a IPP_TAG_DEL_JOB to indicate we have a job-info
  2755. // item. Otherwise, skip to the next attribute.
  2756. //
  2757. if (ipp_ReadByte(lpbTag, 0) == IPP_TAG_DEL_JOB) {
  2758. //
  2759. // Since were currently at a deliminator, we need to get to
  2760. // the next for the start of the job.
  2761. //
  2762. if (lpbTag = ipp_NextTag(lpObj->lpIppHdr, &cbIdx, lpObj->cbIppHdr)) {
  2763. lpbTag = ipp_GetIPPJI2(lpbTag, &ji, &cbIdx, lpObj);
  2764. }
  2765. } else {
  2766. lpbTag = ipp_NextTag(lpObj->lpIppHdr, &cbIdx, lpObj->cbIppHdr);
  2767. }
  2768. }
  2769. //
  2770. // Determine the correct return-code based upon the request response.
  2771. //
  2772. switch (lpObj->wReq) {
  2773. case IPP_RET_PRINTJOB:
  2774. bRet = (SUCCESS_RANGE(wRsp) ? (BOOL)ji.ji2.JobId : FALSE);
  2775. break;
  2776. case IPP_RET_VALIDATEJOB:
  2777. bValidate = TRUE;
  2778. //
  2779. // Fall Through.
  2780. //
  2781. default:
  2782. bRet = SUCCESS_RANGE(wRsp);
  2783. break;
  2784. }
  2785. //
  2786. // Build the response structure.
  2787. //
  2788. if (pj = WebIppCreateJobRet(wRsp, bRet, bValidate, &ji.ji2, &ji.ipp)) {
  2789. *lplpRawHdr = (LPBYTE)pj;
  2790. *lpcbRawHdr = pj->cbSize;
  2791. dwRet = WEBIPP_OK;
  2792. } else {
  2793. dwRet = WEBIPP_NOMEMORY;
  2794. }
  2795. ipp_FreeIPPJI2(&ji);
  2796. return dwRet;
  2797. }
  2798. /*****************************************************************************\
  2799. * ipp_IppToPrnRet (Local Routine - Client)
  2800. *
  2801. * Converts an Ipp-Header to a IPPRET_PRN. From the stream we need
  2802. * to pull out the following information:
  2803. *
  2804. \*****************************************************************************/
  2805. DWORD ipp_IppToPrnRet(
  2806. LPIPPOBJ lpObj,
  2807. LPBYTE* lplpRawHdr,
  2808. LPDWORD lpcbRawHdr)
  2809. {
  2810. PIPPRET_PRN pp;
  2811. IPPPI2 pi;
  2812. WORD wRsp;
  2813. LPBYTE lpbTag;
  2814. LPBYTE lpbEnd;
  2815. DWORD cbIdx;
  2816. DWORD idx;
  2817. DWORD dwRet;
  2818. //
  2819. // Set our default-settings necessary for our PIPPRET_PRN.
  2820. //
  2821. ZeroMemory(&pi, sizeof(IPPPI2));
  2822. //
  2823. // Position the tag at the Tag/Attributes.
  2824. //
  2825. lpbTag = lpObj->lpIppHdr + IPP_SIZEOFHDR;
  2826. //
  2827. // Pull out response code.
  2828. //
  2829. wRsp = ipp_ReadWord(lpObj->lpIppHdr, IPP_SIZEOFVER);
  2830. //
  2831. // If this is a failure-response then call the routine to
  2832. // generate a failure-structure.
  2833. //
  2834. if (SUCCESS_RANGE(wRsp) == FALSE)
  2835. return ipp_IppToFailure(lpObj, lplpRawHdr, lpcbRawHdr);
  2836. //
  2837. // Traverse through the header, advancing through the attributes,
  2838. // until the IPP_TAG_DEL_DATA is encountered.
  2839. //
  2840. for (cbIdx = IPP_SIZEOFHDR; lpbTag && (ipp_ReadByte(lpbTag, 0) != IPP_TAG_DEL_DATA); ) {
  2841. //
  2842. // Look for a IPP_TAG_DEL_PRINTER to indicate we have a printer-info
  2843. // item. Otherwise, skip to the next attribute.
  2844. //
  2845. if (ipp_ReadByte(lpbTag, 0) == IPP_TAG_DEL_PRINTER) {
  2846. //
  2847. // Since were currently at a deliminator, we need to get to
  2848. // the next for the start of the job.
  2849. //
  2850. if (lpbTag = ipp_NextTag(lpObj->lpIppHdr, &cbIdx, lpObj->cbIppHdr))
  2851. lpbTag = ipp_GetIPPPI2(lpbTag, &pi, &cbIdx, lpObj);
  2852. } else {
  2853. lpbTag = ipp_NextTag(lpObj->lpIppHdr, &cbIdx, lpObj->cbIppHdr);
  2854. }
  2855. }
  2856. //
  2857. // If none is specified for the pertinent information, then
  2858. // use a default-str.
  2859. //
  2860. if (pi.ipp.pPrnUri == NULL)
  2861. pi.ipp.pPrnUri = webAllocStr(s_szUnknown);
  2862. if (pi.ipp.pUsrName == NULL)
  2863. pi.ipp.pUsrName = webAllocStr(s_szUnknown);
  2864. if (pi.pi2.pPrinterName == NULL)
  2865. pi.pi2.pPrinterName = webAllocStr(s_szUnknown);
  2866. if (pi.pi2.pDriverName == NULL)
  2867. pi.pi2.pDriverName = webAllocStr(s_szUnknown);
  2868. //
  2869. // Build the response structure.
  2870. //
  2871. pp = WebIppCreatePrnRet(wRsp, SUCCESS_RANGE(wRsp), &pi.pi2, &pi.ipp);
  2872. if (pp != NULL) {
  2873. *lplpRawHdr = (LPBYTE)pp;
  2874. *lpcbRawHdr = pp->cbSize;
  2875. dwRet = WEBIPP_OK;
  2876. } else {
  2877. dwRet = WEBIPP_NOMEMORY;
  2878. }
  2879. ipp_FreeIPPPI2(&pi);
  2880. return dwRet;
  2881. }
  2882. /*****************************************************************************\
  2883. * ipp_IppToEnuRet (Local Routine - Client)
  2884. *
  2885. * Converts an Ipp-Header to a IPPRET_ENUJOB.
  2886. *
  2887. \*****************************************************************************/
  2888. DWORD ipp_IppToEnuRet(
  2889. LPIPPOBJ lpObj,
  2890. LPBYTE* lplpRawHdr,
  2891. LPDWORD lpcbRawHdr)
  2892. {
  2893. PIPPRET_ENUJOB pgj;
  2894. LPIPPJI2 lpjiSrc;
  2895. LPIPPJI2 lpjiDst;
  2896. WORD wRsp;
  2897. DWORD cJobs;
  2898. DWORD cbJobs;
  2899. LPBYTE lpbTag;
  2900. LPBYTE lpbEnd;
  2901. DWORD cbIdx;
  2902. DWORD idx;
  2903. DWORD dwRet;
  2904. //
  2905. // Set our default-settings necessary for our PIPPRET_ENUJOB.
  2906. //
  2907. cJobs = 0;
  2908. cbJobs = 0;
  2909. lpjiDst = NULL;
  2910. //
  2911. // Get the response-code.
  2912. //
  2913. wRsp = ipp_ReadWord(lpObj->lpIppHdr, IPP_SIZEOFVER);
  2914. //
  2915. // If this is a failure-response then call the routine to
  2916. // generate a failure-structure.
  2917. //
  2918. if (SUCCESS_RANGE(wRsp) == FALSE)
  2919. return ipp_IppToFailure(lpObj, lplpRawHdr, lpcbRawHdr);
  2920. //
  2921. // See if we have jobs to enumerate.
  2922. //
  2923. if (cJobs = ipp_GetJobCount(lpObj->lpIppHdr, lpObj->cbIppHdr)) {
  2924. if (lpjiSrc = (LPIPPJI2)webAlloc(cJobs * sizeof(IPPJI2))) {
  2925. //
  2926. // Get the job-info.
  2927. //
  2928. lpbTag = lpObj->lpIppHdr + IPP_SIZEOFHDR;
  2929. for (idx = 0, cbIdx = IPP_SIZEOFHDR; lpbTag && (idx < cJobs); ) {
  2930. //
  2931. // Look for a IPP_TAG_DEL_JOB to indicate we have a job-info
  2932. // item. Otherwise, skipp to the next attribute.
  2933. //
  2934. if (ipp_ReadByte(lpbTag, 0) == IPP_TAG_DEL_JOB) {
  2935. //
  2936. // Since were currently at a deliminator, we need to get to
  2937. // the next for the start of the job.
  2938. //
  2939. if (lpbTag = ipp_NextTag(lpObj->lpIppHdr, &cbIdx, lpObj->cbIppHdr))
  2940. lpbTag = ipp_GetIPPJI2(lpbTag, &lpjiSrc[idx++], &cbIdx, lpObj);
  2941. } else {
  2942. lpbTag = ipp_NextTag(lpObj->lpIppHdr, &cbIdx, lpObj->cbIppHdr);
  2943. }
  2944. }
  2945. //
  2946. // Get storage necessary for packed IPPJI2 structures.
  2947. //
  2948. cbJobs = (cJobs * sizeof(IPPJI2));
  2949. for (idx = 0; idx < cJobs; idx++)
  2950. cbJobs += ipp_SizeofIPPJI2(&lpjiSrc[idx].ji2, &lpjiSrc[idx].ipp);
  2951. //
  2952. // Allocate an array of JI2 structs to contain our
  2953. // enumeration.
  2954. //
  2955. if (lpjiDst = (LPIPPJI2)webAlloc(cbJobs)) {
  2956. //
  2957. // For each job-item, initialize.
  2958. //
  2959. lpbEnd = ((LPBYTE)lpjiDst) + cbJobs;
  2960. for (idx = 0; idx < cJobs; idx++)
  2961. lpbEnd = ipp_BuildJI2(&lpjiDst[idx], &lpjiSrc[idx].ji2, &lpjiSrc[idx].ipp, lpbEnd);
  2962. }
  2963. //
  2964. // Free the memory allocated for the job-item.
  2965. //
  2966. for (idx = 0; idx < cJobs; idx++)
  2967. ipp_FreeIPPJI2(&lpjiSrc[idx]);
  2968. webFree(lpjiSrc);
  2969. }
  2970. }
  2971. //
  2972. // Build the response structure.
  2973. //
  2974. pgj = WebIppCreateEnuJobRet(wRsp, SUCCESS_RANGE(wRsp), cbJobs, cJobs, lpjiDst);
  2975. if (pgj != NULL) {
  2976. *lplpRawHdr = (LPBYTE)pgj;
  2977. *lpcbRawHdr = pgj->cbSize;
  2978. dwRet = WEBIPP_OK;
  2979. } else {
  2980. dwRet = WEBIPP_NOMEMORY;
  2981. }
  2982. webFree(lpjiDst);
  2983. return dwRet;
  2984. }
  2985. /*****************************************************************************\
  2986. * ipp_IppToAthRet (Local Routine - Client)
  2987. *
  2988. * Converts an Ipp-Header to a IPPRET_AUTH. From the stream we need
  2989. * to pull out the following information:
  2990. *
  2991. \*****************************************************************************/
  2992. DWORD ipp_IppToAthRet(
  2993. LPIPPOBJ lpObj,
  2994. LPBYTE* lplpRawHdr,
  2995. LPDWORD lpcbRawHdr)
  2996. {
  2997. PIPPRET_AUTH pfa;
  2998. WORD wRsp;
  2999. BOOL bRet;
  3000. DWORD dwRet;
  3001. //
  3002. // Pull out the response.
  3003. //
  3004. wRsp = ipp_ReadWord(lpObj->lpIppHdr, IPP_SIZEOFVER);
  3005. bRet = SUCCESS_RANGE(wRsp);
  3006. //
  3007. // Build the response structure.
  3008. //
  3009. if (pfa = WebIppCreateAuthRet(wRsp, bRet)) {
  3010. *lplpRawHdr = (LPBYTE)pfa;
  3011. *lpcbRawHdr = pfa->cbSize;
  3012. dwRet = WEBIPP_OK;
  3013. } else {
  3014. dwRet = WEBIPP_NOMEMORY;
  3015. }
  3016. return dwRet;
  3017. }
  3018. /*****************************************************************************\
  3019. * ipp_FailureToIpp (Local Routine - Server)
  3020. *
  3021. * Converts a IPPRET_ALL to an IPP Header. This is used for responding to
  3022. * clients that an operation is not supported, or returning a failure.
  3023. *
  3024. \*****************************************************************************/
  3025. DWORD ipp_FailureToIpp(
  3026. WORD wReq,
  3027. LPREQINFO lpri,
  3028. LPBYTE lpbData,
  3029. LPBYTE* lplpIppHdr,
  3030. LPDWORD lpcbIppHdr)
  3031. {
  3032. LPBYTE lpIppHdr;
  3033. LPBYTE lpIppPtr;
  3034. DWORD cbIppHdr;
  3035. DWORD dwRet;
  3036. DWORD cbNamSta;
  3037. DWORD cbValSta;
  3038. LPSTR lputfNamSta;
  3039. LPSTR lputfValSta;
  3040. PIPPRET_ALL pbr = (PIPPRET_ALL)lpbData;
  3041. //
  3042. // Zero out our return pointer/count.
  3043. //
  3044. *lplpIppHdr = NULL;
  3045. *lpcbIppHdr = 0;
  3046. ipp_GetRspSta(pbr->wRsp, lpri->cpReq, &lputfNamSta, &cbNamSta, &lputfValSta, &cbValSta);
  3047. //
  3048. // Calculate the space necessary to generate our
  3049. // IPP-Header-Stream.
  3050. //
  3051. cbIppHdr = ipp_SizeHdr(lpri->cpReq) +
  3052. (lputfNamSta && lputfValSta ? ipp_SizeAttr(cbNamSta, cbValSta) : 0) +
  3053. IPP_SIZEOFTAG;
  3054. //
  3055. // Allocate the header for the IPP-Stream.
  3056. //
  3057. if (lpIppHdr = (LPBYTE)webAlloc(cbIppHdr)) {
  3058. //
  3059. // Initialize the pointer which will keep track
  3060. // of where we are in writing the IPP-Stream-Header.
  3061. //
  3062. lpIppPtr = lpIppHdr;
  3063. //
  3064. // Write out the IPP-Header-Stream.
  3065. //
  3066. ipp_WriteHead(&lpIppPtr, pbr->wRsp, lpri->idReq, lpri->cpReq);
  3067. if (lputfNamSta && lputfValSta)
  3068. ipp_WriteAttr(&lpIppPtr, IPP_TAG_CHR_TEXT, cbNamSta, lputfNamSta, cbValSta, lputfValSta);
  3069. ipp_WriteByte(&lpIppPtr, IPP_TAG_DEL_DATA);
  3070. //
  3071. // Set the return values for the IPP-Stream-Header
  3072. // as well as the size.
  3073. //
  3074. dwRet = WEBIPP_OK;
  3075. *lplpIppHdr = lpIppHdr;
  3076. *lpcbIppHdr = cbIppHdr;
  3077. } else {
  3078. dwRet = WEBIPP_NOMEMORY;
  3079. }
  3080. webFree(lputfNamSta);
  3081. webFree(lputfValSta);
  3082. return dwRet;
  3083. }
  3084. /*****************************************************************************\
  3085. * Ipp Send/Receive Table
  3086. *
  3087. *
  3088. *
  3089. \*****************************************************************************/
  3090. static IPPSNDRCV s_pfnIpp[] = {
  3091. // Operation Req Form Rsp Form Req X Req X Size Rsp X Rsp X Size Rsp (cli)
  3092. // ----------------- -------- -------- ------ -------------- ------ -------------- ----------------
  3093. //
  3094. IPP_REQ_PRINTJOB , s_FormA, s_FormC, s_PJQ, sizeof(s_PJQ), s_PJR, sizeof(s_PJR), ipp_IppToJobRet,
  3095. IPP_REQ_VALIDATEJOB, s_FormA, s_FormE, s_PJQ, sizeof(s_PJQ), NULL , 0 , ipp_IppToJobRet,
  3096. IPP_REQ_CANCELJOB , s_FormB, s_FormE, s_SJQ, sizeof(s_SJQ), NULL , 0 , ipp_IppToJobRet,
  3097. IPP_REQ_GETJOB , s_FormB, s_FormC, s_GJQ, sizeof(s_GJQ), s_PJR, sizeof(s_PJR), ipp_IppToJobRet,
  3098. IPP_REQ_ENUJOB , s_FormB, s_FormF, s_EJQ, sizeof(s_EJQ), s_EJR, sizeof(s_EJR), ipp_IppToEnuRet,
  3099. IPP_REQ_GETPRN , s_FormB, s_FormD, s_GPQ, sizeof(s_GPQ), s_GPR, sizeof(s_GPR), ipp_IppToPrnRet,
  3100. IPP_REQ_PAUSEJOB , s_FormB, s_FormE, s_SJQ, sizeof(s_SJQ), NULL , 0 , ipp_IppToJobRet,
  3101. IPP_REQ_RESUMEJOB , s_FormB, s_FormE, s_SJQ, sizeof(s_SJQ), NULL , 0 , ipp_IppToJobRet,
  3102. IPP_REQ_RESTARTJOB , s_FormB, s_FormE, s_SJQ, sizeof(s_SJQ), NULL , 0 , ipp_IppToJobRet,
  3103. IPP_REQ_PAUSEPRN , s_FormB, s_FormE, s_SPQ, sizeof(s_SPQ), NULL , 0 , ipp_IppToPrnRet,
  3104. IPP_REQ_RESUMEPRN , s_FormB, s_FormE, s_SPQ, sizeof(s_SPQ), NULL , 0 , ipp_IppToPrnRet,
  3105. IPP_REQ_CANCELPRN , s_FormB, s_FormE, s_SPQ, sizeof(s_SPQ), NULL , 0 , ipp_IppToPrnRet,
  3106. IPP_REQ_FORCEAUTH , s_FormB, s_FormB, NULL , 0 , NULL , 0 , ipp_IppToAthRet
  3107. };
  3108. /*****************************************************************************\
  3109. * ipp_ValidateRcvReq (Local Routine)
  3110. *
  3111. * Returns whether the header is a supported request.
  3112. *
  3113. \*****************************************************************************/
  3114. DWORD ipp_ValidateRcvReq(
  3115. LPIPPOBJ lpObj)
  3116. {
  3117. DWORD idx;
  3118. DWORD cCnt;
  3119. DWORD dwId = ipp_ReadDWord(lpObj->lpIppHdr, IPP_SIZEOFINT);
  3120. WORD wVer = ipp_ReadWord(lpObj->lpIppHdr, 0);
  3121. WORD wReq = ipp_ReadWord(lpObj->lpIppHdr, IPP_SIZEOFVER);
  3122. //
  3123. // First check that we are the correct-version, then proceed
  3124. // to validate the request.
  3125. //
  3126. if (wVer == IPP_VERSION) {
  3127. if (REQID_RANGE(dwId)) {
  3128. //
  3129. // See if we're in the range of response codes.
  3130. //
  3131. if (SUCCESS_RANGE(wReq) || ERROR_RANGE(wReq))
  3132. return WEBIPP_OK;
  3133. //
  3134. // Validate supported operations.
  3135. //
  3136. cCnt = sizeof(s_pfnIpp) / sizeof(s_pfnIpp[0]);
  3137. for (idx = 0; idx < cCnt; idx++) {
  3138. if (wReq == s_pfnIpp[idx].wReq)
  3139. return WEBIPP_OK;
  3140. }
  3141. lpObj->wError = IPPRSP_ERROR_400;
  3142. } else {
  3143. lpObj->wError = IPPRSP_ERROR_400;
  3144. }
  3145. } else {
  3146. lpObj->wError = IPPRSP_ERROR_503;
  3147. }
  3148. return WEBIPP_FAIL;
  3149. }
  3150. /*****************************************************************************\
  3151. * ipp_ValForm (Local Routine)
  3152. *
  3153. * Checks the tag-order for delimiters.
  3154. *
  3155. \*****************************************************************************/
  3156. BOOL ipp_ValForm(
  3157. BYTE bTag,
  3158. PBYTE pbVal)
  3159. {
  3160. DWORD idx;
  3161. //
  3162. // Look to see if the tag is one of our supported groups for
  3163. // this request.
  3164. //
  3165. for (idx = 0; pbVal[idx] != (BYTE)0; idx++) {
  3166. //
  3167. // Is this a tag we're interested in.
  3168. //
  3169. if ((pbVal[idx] & 0x0F) == bTag) {
  3170. // If we're already encountered this tag, then we
  3171. // have an error (duplication of groups).
  3172. //
  3173. if ((pbVal[idx] & IPP_HIT) && !(pbVal[idx] & IPP_MULTIPLE))
  3174. return FALSE;
  3175. //
  3176. // Otherwise, mark this group as hit.
  3177. //
  3178. pbVal[idx] |= IPP_HIT;
  3179. return TRUE;
  3180. } else {
  3181. //
  3182. // If this is not our tag, then we need to check
  3183. // that this has at least been hit, or is an
  3184. // optional group (verifies order).
  3185. //
  3186. if (IS_RANGE_DELIMITER(bTag))
  3187. if (!(pbVal[idx] & (IPP_HIT | IPP_OPTIONAL)))
  3188. return FALSE;
  3189. }
  3190. }
  3191. return TRUE;
  3192. }
  3193. /*****************************************************************************\
  3194. * ipp_AllocVal (Local Routine)
  3195. *
  3196. * Allocates a byte-array of tags that specify order.
  3197. *
  3198. \*****************************************************************************/
  3199. PBYTE ipp_AllocVal(
  3200. WORD wReq)
  3201. {
  3202. DWORD cCnt;
  3203. DWORD idx;
  3204. PBYTE pbGrp;
  3205. PBYTE pbVal = NULL;
  3206. //
  3207. // Build the byte-array for validation of form.
  3208. //
  3209. cCnt = sizeof(s_pfnIpp) / sizeof(s_pfnIpp[0]);
  3210. for (idx = 0, pbGrp = NULL; idx < cCnt; idx++) {
  3211. if (wReq == s_pfnIpp[idx].wReq) {
  3212. pbGrp = s_pfnIpp[idx].pbReqForm;
  3213. break;
  3214. } else if (wReq == (IPP_RESPONSE | s_pfnIpp[idx].wReq)) {
  3215. pbGrp = s_pfnIpp[idx].pbRspForm;
  3216. break;
  3217. }
  3218. }
  3219. if (pbGrp) {
  3220. for (idx = 0; pbGrp[idx++] != (BYTE)0; );
  3221. if (idx && (pbVal = (PBYTE)webAlloc(idx)))
  3222. CopyMemory(pbVal, pbGrp, idx);
  3223. }
  3224. return pbVal;
  3225. }
  3226. /*****************************************************************************\
  3227. * ipp_ValidateRcvForm (Local Routine)
  3228. *
  3229. * Returns whether the header is well-formed.
  3230. *
  3231. \*****************************************************************************/
  3232. DWORD ipp_ValidateRcvForm(
  3233. LPIPPOBJ lpObj,
  3234. LPDWORD lpcbSize)
  3235. {
  3236. LPBYTE lpbTag;
  3237. BYTE bTag;
  3238. DWORD cbIdx;
  3239. PBYTE pbVal;
  3240. DWORD dwRet = WEBIPP_MOREDATA;
  3241. //
  3242. // Zero out the return buffer.
  3243. //
  3244. *lpcbSize = 0;
  3245. //
  3246. // Allocate our array of tags that represent order.
  3247. //
  3248. if (pbVal = ipp_AllocVal(lpObj->wReq)) {
  3249. //
  3250. // Advance our pointer to the start of our attributes
  3251. // in the byte-stream (i.e. skip version/request).
  3252. //
  3253. lpbTag = lpObj->lpIppHdr + IPP_SIZEOFHDR;
  3254. //
  3255. // Check to be sure that our headers always start
  3256. // off with an operations-attribute-tag.
  3257. //
  3258. if (IS_TAG_DELIMITER(ipp_ReadByte(lpbTag, 0))) {
  3259. //
  3260. // Traverse through the header, advancing through the attributes,
  3261. // until the IPP_TAG_DEL_DATA is encountered. This will verify
  3262. // that we have a well-formed header.
  3263. //
  3264. for (cbIdx = IPP_SIZEOFHDR; lpbTag; ) {
  3265. //
  3266. // Get the tag.
  3267. //
  3268. bTag = ipp_ReadByte(lpbTag, 0);
  3269. //
  3270. // Only check our delimiter tags for this
  3271. // validation.
  3272. //
  3273. if (IS_TAG_DELIMITER(bTag)) {
  3274. if (bTag == IPP_TAG_DEL_DATA) {
  3275. if (ipp_ValForm(bTag, pbVal)) {
  3276. *lpcbSize = (cbIdx + 1);
  3277. dwRet = WEBIPP_OK;
  3278. goto EndVal;
  3279. } else {
  3280. goto BadFrm;
  3281. }
  3282. } else {
  3283. if (ipp_ValForm(bTag, pbVal) == FALSE)
  3284. goto BadFrm;
  3285. }
  3286. }
  3287. //
  3288. // Advance to next Tag. This routine also increments
  3289. // the (cbIdx) count. If we run out of bytes in the
  3290. // header before we can get to the next-tag, then this
  3291. // will return NULL.
  3292. //
  3293. lpbTag = ipp_NextTag(lpObj->lpIppHdr, &cbIdx, lpObj->cbIppHdr);
  3294. }
  3295. } else {
  3296. BadFrm:
  3297. lpObj->wError = IPPRSP_ERROR_400;
  3298. dwRet = WEBIPP_FAIL;
  3299. }
  3300. EndVal:
  3301. webFree(pbVal);
  3302. } else {
  3303. lpObj->wError = IPPRSP_ERROR_505;
  3304. dwRet = WEBIPP_NOMEMORY;
  3305. }
  3306. return dwRet;
  3307. }
  3308. /*****************************************************************************\
  3309. * ipp_ValidateRcvCharSet (Local Routine)
  3310. *
  3311. * Returns whether we support the character-set.
  3312. *
  3313. \*****************************************************************************/
  3314. DWORD ipp_ValidateRcvCharSet(
  3315. LPIPPOBJ lpObj)
  3316. {
  3317. LPIPPATTR lpAttr;
  3318. LPBYTE lpbTag;
  3319. BYTE bTag;
  3320. DWORD cbIdx;
  3321. DWORD dwRet = WEBIPP_FAIL;
  3322. //
  3323. // Advance our pointer to the start of our attributes
  3324. // in the byte-stream (i.e. skip version/request).
  3325. //
  3326. lpbTag = lpObj->lpIppHdr + IPP_SIZEOFHDR;
  3327. //
  3328. // Traverse through the header, advancing through the attributes,
  3329. // until the IPP_TAG_DEL_DATA is encountered. This will verify
  3330. // that we have a well-formed header.
  3331. //
  3332. for (cbIdx = IPP_SIZEOFHDR; lpbTag; ) {
  3333. bTag = ipp_ReadByte(lpbTag, 0);
  3334. //
  3335. // If we walked through the end of our stream, then
  3336. // the stream does not contain character-set information.
  3337. //
  3338. if (IS_TAG_DELIMITER(bTag) && (bTag != IPP_TAG_DEL_OPERATION))
  3339. break;
  3340. //
  3341. // If we are pointing at an attribute, then retrieve
  3342. // it in a format we understand.
  3343. //
  3344. if (lpAttr = ipp_GetAttr(lpbTag, cbIdx, lpObj)) {
  3345. //
  3346. // Check the name-type to see how to handle the value.
  3347. //
  3348. if (lpAttr->lpszName) {
  3349. if (lstrcmpi(lpAttr->lpszName, s_szCharSet) == 0) {
  3350. if (lpObj->fState & IPPFLG_CHARSET) {
  3351. lpObj->wError = IPPRSP_ERROR_400;
  3352. dwRet = WEBIPP_FAIL;
  3353. } else {
  3354. lpObj->fState |= IPPFLG_CHARSET;
  3355. if (lpAttr->cbValue > SIZE_CHARSET) {
  3356. lpObj->wError = IPPRSP_ERROR_409;
  3357. } else {
  3358. if (lstrcmpi((LPTSTR)lpAttr->lpValue, s_szUtf8) == 0) {
  3359. lpObj->uCPRcv = CP_UTF8;
  3360. dwRet = WEBIPP_OK;
  3361. } else if (lstrcmpi((LPTSTR)lpAttr->lpValue, s_szUsAscii) == 0) {
  3362. lpObj->uCPRcv = CP_ACP;
  3363. dwRet = WEBIPP_OK;
  3364. } else {
  3365. lpObj->wError = IPPRSP_ERROR_40D;
  3366. }
  3367. }
  3368. }
  3369. }
  3370. }
  3371. ipp_RelAttr(lpAttr);
  3372. }
  3373. if (ERROR_RANGE(lpObj->wError))
  3374. break;
  3375. //
  3376. // Advance to next Tag. This routine also increments
  3377. // the (cbIdx) count. If we run out of bytes in the
  3378. // header before we can get to the next-tag, then this
  3379. // will return NULL.
  3380. //
  3381. lpbTag = ipp_NextTag(lpObj->lpIppHdr, &cbIdx, lpObj->cbIppHdr);
  3382. }
  3383. if ((dwRet != WEBIPP_OK) && (lpObj->wError == IPPRSP_SUCCESS))
  3384. lpObj->wError = IPPRSP_ERROR_400;
  3385. return dwRet;
  3386. }
  3387. /*****************************************************************************\
  3388. * ipp_ValidateRcvLang (Local Routine)
  3389. *
  3390. * Returns whether we support the natural-language.
  3391. *
  3392. \*****************************************************************************/
  3393. DWORD ipp_ValidateRcvLang(
  3394. LPIPPOBJ lpObj)
  3395. {
  3396. LPIPPATTR lpAttr;
  3397. LPBYTE lpbTag;
  3398. BYTE bTag;
  3399. DWORD cbIdx;
  3400. DWORD dwRet = WEBIPP_FAIL;
  3401. //
  3402. // Advance our pointer to the start of our attributes
  3403. // in the byte-stream (i.e. skip version/request).
  3404. //
  3405. lpbTag = lpObj->lpIppHdr + IPP_SIZEOFHDR;
  3406. //
  3407. // Traverse through the header, advancing through the attributes,
  3408. // until the IPP_TAG_DEL_DATA is encountered. This will verify
  3409. // that we have a well-formed header.
  3410. //
  3411. for (cbIdx = IPP_SIZEOFHDR; lpbTag; ) {
  3412. bTag = ipp_ReadByte(lpbTag, 0);
  3413. //
  3414. // If we walked through the end of our stream, then
  3415. // the stream does not contain natural-language information.
  3416. //
  3417. if (IS_TAG_DELIMITER(bTag) && (bTag != IPP_TAG_DEL_OPERATION))
  3418. break;
  3419. //
  3420. // If we are pointing at an attribute, then retrieve
  3421. // it in a format we understand.
  3422. //
  3423. if (lpAttr = ipp_GetAttr(lpbTag, cbIdx, lpObj)) {
  3424. //
  3425. // Check the name-type to see how to handle the value.
  3426. //
  3427. if (lpAttr->lpszName) {
  3428. if (lstrcmpi(lpAttr->lpszName, s_szNaturalLanguage) == 0) {
  3429. if (lpObj->fState & IPPFLG_NATLANG) {
  3430. lpObj->wError = IPPRSP_ERROR_400;
  3431. dwRet = WEBIPP_FAIL;
  3432. } else {
  3433. lpObj->fState |= IPPFLG_NATLANG;
  3434. if (lpAttr->cbValue > SIZE_NATLANG) {
  3435. lpObj->wError = IPPRSP_ERROR_409;
  3436. } else {
  3437. if (lstrcmpi((LPTSTR)lpAttr->lpValue, s_szEnUS) == 0) {
  3438. dwRet = WEBIPP_OK;
  3439. } else {
  3440. dwRet = WEBIPP_OK;
  3441. }
  3442. }
  3443. }
  3444. }
  3445. }
  3446. ipp_RelAttr(lpAttr);
  3447. }
  3448. if (ERROR_RANGE(lpObj->wError))
  3449. break;
  3450. //
  3451. // Advance to next Tag. This routine also increments
  3452. // the (cbIdx) count. If we run out of bytes in the
  3453. // header before we can get to the next-tag, then this
  3454. // will return NULL.
  3455. //
  3456. lpbTag = ipp_NextTag(lpObj->lpIppHdr, &cbIdx, lpObj->cbIppHdr);
  3457. }
  3458. if ((dwRet != WEBIPP_OK) && (lpObj->wError == IPPRSP_SUCCESS))
  3459. lpObj->wError = IPPRSP_ERROR_400;
  3460. return dwRet;
  3461. }
  3462. /*****************************************************************************\
  3463. * ipp_ValidateRcvHdr (Local Routine)
  3464. *
  3465. * Parses through the (lpbHdr) and returns whether it's a full (complete)
  3466. * header. Essentially, this need only look through the byte-stream until
  3467. * it finds the IPP_TAG_DEL_DATA attribute.
  3468. *
  3469. * Returns the size of the header (in bytes).
  3470. *
  3471. \*****************************************************************************/
  3472. DWORD ipp_ValidateRcvHdr(
  3473. LPIPPOBJ lpObj,
  3474. LPDWORD lpcbSize)
  3475. {
  3476. LPBYTE lpbTag;
  3477. DWORD cbIdx;
  3478. DWORD cbSize;
  3479. DWORD dwRet;
  3480. //
  3481. // Initialize our return-size so that we are reporting
  3482. // clean data.
  3483. //
  3484. *lpcbSize = 0;
  3485. //
  3486. // Make sure we have enough in our header to handle
  3487. // the basic verification.
  3488. //
  3489. if (lpObj->cbIppHdr <= (IPP_SIZEOFHDR + IPP_SIZEOFTAG))
  3490. return WEBIPP_MOREDATA;
  3491. //
  3492. // Set the request-type for the header. This will help
  3493. // us determine the appropriate conversion to the data-
  3494. // structure.
  3495. //
  3496. lpObj->idReq = ipp_ReadDWord(lpObj->lpIppHdr, IPP_SIZEOFINT);
  3497. //
  3498. // Validate the fixed header values, then proceed with
  3499. // other validation of the operational-attributes.
  3500. //
  3501. if ((dwRet = ipp_ValidateRcvReq(lpObj)) == WEBIPP_OK) {
  3502. if ((dwRet = ipp_ValidateRcvForm(lpObj, &cbSize)) == WEBIPP_OK) {
  3503. if ((dwRet = ipp_ValidateRcvCharSet(lpObj)) == WEBIPP_OK) {
  3504. if ((dwRet = ipp_ValidateRcvLang(lpObj)) == WEBIPP_OK) {
  3505. *lpcbSize = cbSize;
  3506. }
  3507. }
  3508. }
  3509. }
  3510. return dwRet;
  3511. }
  3512. /*****************************************************************************\
  3513. * ipp_ConvertIppToW32 (Local Routine)
  3514. *
  3515. * This routine takes in an IPP stream-buffer and generates the appropriate
  3516. * structure in which NT-Spooler-API's can process.
  3517. *
  3518. * Returns the pointer to the converted-header as well as the bytes that
  3519. * this converted header occupies.
  3520. *
  3521. \*****************************************************************************/
  3522. DWORD ipp_ConvertIppToW32(
  3523. LPIPPOBJ lpObj,
  3524. LPBYTE* lplpRawHdr,
  3525. LPDWORD lpcbRawHdr)
  3526. {
  3527. DWORD cCnt;
  3528. DWORD idx;
  3529. //
  3530. // Perform the request. If the request has NULL function-pointers, then
  3531. // the request/response is not supported.
  3532. //
  3533. cCnt = sizeof(s_pfnIpp) / sizeof(s_pfnIpp[0]);
  3534. for (idx = 0; idx < cCnt; idx++) {
  3535. //
  3536. // Check for request
  3537. //
  3538. if (lpObj->wReq == s_pfnIpp[idx].wReq)
  3539. return ipp_IppToW32(lpObj, lplpRawHdr, lpcbRawHdr);
  3540. //
  3541. // Check for response
  3542. //
  3543. if (lpObj->wReq == (IPP_RESPONSE | s_pfnIpp[idx].wReq))
  3544. return s_pfnIpp[idx].pfnRcvRet(lpObj, lplpRawHdr, lpcbRawHdr);
  3545. }
  3546. lpObj->wError = IPPRSP_ERROR_501;
  3547. return WEBIPP_FAIL;
  3548. }
  3549. /*****************************************************************************\
  3550. * WebIppSndData
  3551. *
  3552. * This routine takes the (lpRawHdr) and packages it up in IPP 1.1 protocol
  3553. * and returns the pointer to the Ipp-Header.
  3554. *
  3555. * Parameters:
  3556. * ----------
  3557. * dwReq - Describes the type of IPP-Header to package.
  3558. * lpRawHdr - Input pointer to raw (spooler) data-structure.
  3559. * cbRawHdr - Input byte-count of (lpRawHdr).
  3560. * lplpIppHdr - Output pointer to IPP-Header stream.
  3561. * lpcbIppHdr - Output to byte-count of Ipp-Header stream (lplpIppHdr).
  3562. *
  3563. \*****************************************************************************/
  3564. DWORD WebIppSndData(
  3565. WORD wReq,
  3566. LPREQINFO lpri,
  3567. LPBYTE lpRawHdr,
  3568. DWORD cbRawHdr,
  3569. LPBYTE* lplpIppHdr,
  3570. LPDWORD lpcbIppHdr)
  3571. {
  3572. DWORD cCnt;
  3573. DWORD idx;
  3574. LPIPPATTRX pSnd;
  3575. DWORD cSnd;
  3576. //
  3577. // Zero out the return pointers/sizes.
  3578. //
  3579. *lplpIppHdr = NULL;
  3580. *lpcbIppHdr = 0;
  3581. //
  3582. // Make sure the code-pages are something we can support.
  3583. //
  3584. if ((lpri->cpReq == CP_ACP) || (lpri->cpReq == CP_UTF8)) {
  3585. //
  3586. // Perform the request. If the request has NULL function-pointers,
  3587. // then the request/response is not supported.
  3588. //
  3589. cCnt = sizeof(s_pfnIpp) / sizeof(s_pfnIpp[0]);
  3590. for (idx = 0; idx < cCnt; idx++) {
  3591. //
  3592. // Check for request.
  3593. //
  3594. if (wReq == s_pfnIpp[idx].wReq) {
  3595. pSnd = s_pfnIpp[idx].paReq;
  3596. cSnd = s_pfnIpp[idx].cbReq / sizeof(IPPATTRX);
  3597. return ipp_W32ToIpp(wReq, lpri, lpRawHdr, pSnd, cSnd, lplpIppHdr, lpcbIppHdr);
  3598. }
  3599. //
  3600. // Check for response.
  3601. //
  3602. if (wReq == (IPP_RESPONSE | s_pfnIpp[idx].wReq)) {
  3603. //
  3604. // Check response for any fail-cases.
  3605. //
  3606. if (SUCCESS_RANGE(((LPIPPRET_ALL)lpRawHdr)->wRsp)) {
  3607. pSnd = s_pfnIpp[idx].paRsp;
  3608. cSnd = s_pfnIpp[idx].cbRsp / sizeof(IPPATTRX);
  3609. return ipp_W32ToIpp(wReq, lpri, lpRawHdr, pSnd, cSnd, lplpIppHdr, lpcbIppHdr);
  3610. }
  3611. break;
  3612. }
  3613. }
  3614. //
  3615. // If this was sent by our server, then we want to reply to the client
  3616. // with an ipp-stream.
  3617. //
  3618. return ipp_FailureToIpp(wReq, lpri, lpRawHdr, lplpIppHdr, lpcbIppHdr);
  3619. }
  3620. return WEBIPP_FAIL;
  3621. }
  3622. /*****************************************************************************\
  3623. * WebIppRcvOpen
  3624. *
  3625. * This routine creates an IPP-state-object which parses IPP stream-data. The
  3626. * parameter (dwReq) specifies which request we expect the stream to provide.
  3627. *
  3628. * We allocate a default-size buffer to contain the header. If more memory
  3629. * is necessary, then it is reallocated to append the data.
  3630. *
  3631. \*****************************************************************************/
  3632. HANDLE WebIppRcvOpen(
  3633. WORD wReq)
  3634. {
  3635. LPIPPOBJ lpObj;
  3636. if (lpObj = (LPIPPOBJ)webAlloc(sizeof(IPPOBJ))) {
  3637. if (lpObj->pwlUns = (PWEBLST)new CWebLst()) {
  3638. lpObj->wReq = wReq;
  3639. lpObj->wError = IPPRSP_SUCCESS;
  3640. lpObj->idReq = 0;
  3641. lpObj->uCPRcv = CP_UTF8;
  3642. lpObj->fState = 0;
  3643. lpObj->cbIppHdr = 0;
  3644. lpObj->cbIppMax = IPP_BLOCK_SIZE;
  3645. lpObj->lpRawDta = NULL;
  3646. x_SetReq(lpObj->fReq, (wReq == IPP_REQ_ENUJOB ? IPP_REQENU : IPP_REQALL));
  3647. //
  3648. // Allocate a default buffer-size to hold the IPP
  3649. // header. This may not be large enough to hold
  3650. // the complete header so we reserve the right to
  3651. // reallocate it until it contains the entire header.
  3652. //
  3653. if (lpObj->lpIppHdr = (LPBYTE)webAlloc(lpObj->cbIppMax)) {
  3654. return (HANDLE)lpObj;
  3655. }
  3656. delete lpObj->pwlUns;
  3657. }
  3658. webFree(lpObj);
  3659. }
  3660. return NULL;
  3661. }
  3662. /*****************************************************************************\
  3663. * WebIppRcvData
  3664. *
  3665. * This routine takes in IPP stream-data and builds a complete IPP-Header. It
  3666. * is possible that the header-information is not provided in one chunk of
  3667. * stream-data. Therefore, we will not return the converted header information
  3668. * until our header is complete.
  3669. *
  3670. * Once the header is complete, it's returned in the output-buffer in the
  3671. * format that the caller can utilized in spooler-related calls.
  3672. *
  3673. * Not only does this handle the header, but it is also used to process raw
  3674. * stream-data which is returned unmodified to the caller. In the case that
  3675. * we encounter data during the processing of the IPP-Header, we need to
  3676. * return an allocated buffer pointing to DWORD-Aligned bits.
  3677. *
  3678. * Parameters:
  3679. * ----------
  3680. * hObj - Handle to the Ipp-Parse-Object.
  3681. * lpIppDta - Input pointer to ipp-stream-data. This is header and/or data.
  3682. * cbIppDta - Input byte-count contained in the (lpIppData).
  3683. * lplpRawHdr - Output pointer to spooler-define (raw) structure.
  3684. * lpcbRawHdr - Output pointer to byte-count in (lplpRawHdr).
  3685. * lplpRawDta - Output pointer to data-stream.
  3686. * lpcbRawDta - Output pointer to byte-count in (lplpRawDta).
  3687. *
  3688. * Returns:
  3689. * -------
  3690. * WEBIPP_OK - Information in lplpHdr or lplpData is valid.
  3691. * WEBIPP_FAIL - Failed in validation. Use WebIppGetError.
  3692. * WEBIPP_MOREDATA - Needs more data to complete header.
  3693. * WEBIPP_BADHANDLE - Ipp-Object-Handle is invalid.
  3694. * WEBIPP_NOMEMORY - Failed allocation request (out-of-memory).
  3695. *
  3696. \*****************************************************************************/
  3697. DWORD WebIppRcvData(
  3698. HANDLE hObj,
  3699. LPBYTE lpIppDta,
  3700. DWORD cbIppDta,
  3701. LPBYTE* lplpRawHdr,
  3702. LPDWORD lpcbRawHdr,
  3703. LPBYTE* lplpRawDta,
  3704. LPDWORD lpcbRawDta)
  3705. {
  3706. LPIPPOBJ lpObj;
  3707. LPBYTE lpNew;
  3708. DWORD cbSize;
  3709. DWORD cbData;
  3710. DWORD cBlks;
  3711. DWORD dwRet;
  3712. //
  3713. // Initialize the output pointers to NULL. We return two distinct
  3714. // references since it is possible that the buffer passed in contains
  3715. // both header and data.
  3716. //
  3717. *lplpRawHdr = NULL;
  3718. *lpcbRawHdr = 0;
  3719. *lplpRawDta = NULL;
  3720. *lpcbRawDta = 0;
  3721. //
  3722. // Process the stream-data.
  3723. //
  3724. if (lpObj = (LPIPPOBJ)hObj) {
  3725. //
  3726. // If our header is complete, then the stream is raw-data meant
  3727. // to be return directly. In this case we only need to return the
  3728. // data-stream passed in.
  3729. //
  3730. // Otherwise, the default-case is that we are building our header
  3731. // from the stream-data.
  3732. //
  3733. if (lpObj->fState & IPPFLG_VALID) {
  3734. //
  3735. // Free up the memory occupied by our header (only done on
  3736. // the first hit of this block). Since we aren't using
  3737. // this anymore during the processing of the stream, we
  3738. // shouldn't occupy any more memory than necessary.
  3739. //
  3740. if (lpObj->lpIppHdr) {
  3741. webFree(lpObj->lpIppHdr);
  3742. lpObj->lpIppHdr = NULL;
  3743. lpObj->cbIppHdr = 0;
  3744. //
  3745. // Likewise, if we had need of a temporary data-buffer
  3746. // to hold aligned-bits, then we need to free this up
  3747. // as well.
  3748. //
  3749. webFree(lpObj->lpRawDta);
  3750. lpObj->lpRawDta = NULL;
  3751. }
  3752. //
  3753. // Return the data-stream passed in.
  3754. //
  3755. dwRet = WEBIPP_OK;
  3756. *lplpRawDta = lpIppDta;
  3757. *lpcbRawDta = cbIppDta;
  3758. } else {
  3759. //
  3760. // Check to see if our buffer can accomodate the
  3761. // size of the buffer being passed in. If not, realloc
  3762. // a new buffer to accomodate the new chunk.
  3763. //
  3764. if ((lpObj->cbIppHdr + cbIppDta) >= lpObj->cbIppMax) {
  3765. //
  3766. // Determine the number of memory-blocks that we
  3767. // need to hold the (cbData) coming in.
  3768. //
  3769. cBlks = (cbIppDta / IPP_BLOCK_SIZE) + 1;
  3770. cbSize = lpObj->cbIppMax + (IPP_BLOCK_SIZE * cBlks);
  3771. lpNew = (LPBYTE)webRealloc(lpObj->lpIppHdr,
  3772. lpObj->cbIppMax,
  3773. cbSize);
  3774. if (lpNew != NULL) {
  3775. lpObj->lpIppHdr = lpNew;
  3776. lpObj->cbIppMax = cbSize;
  3777. } else {
  3778. return WEBIPP_NOMEMORY;
  3779. }
  3780. }
  3781. //
  3782. // Copy/Append the stream-data to our header-buffer.
  3783. //
  3784. memcpy(lpObj->lpIppHdr + lpObj->cbIppHdr, lpIppDta, cbIppDta);
  3785. lpObj->cbIppHdr += cbIppDta;
  3786. //
  3787. // Validate the header. If this is successful, then we have
  3788. // a well-formed-header. Otherwise, we need to request
  3789. // more data from the caller. This returns the actual size
  3790. // of the header in (cbSize).
  3791. //
  3792. if ((dwRet = ipp_ValidateRcvHdr(lpObj, &cbSize)) == WEBIPP_OK) {
  3793. //
  3794. // Convert the IPP-Heade to a structure (stream)
  3795. // that the caller understands (depends on dwReq).
  3796. //
  3797. dwRet = ipp_ConvertIppToW32(lpObj, lplpRawHdr, lpcbRawHdr);
  3798. if (dwRet == WEBIPP_OK) {
  3799. //
  3800. // The validation returns the actual-size occupied by
  3801. // the header. Therefore, if our (cbHdr) is larger, then
  3802. // the remaining information is pointing at data.
  3803. //
  3804. if (cbSize < lpObj->cbIppHdr) {
  3805. cbData = (lpObj->cbIppHdr - cbSize);
  3806. lpObj->lpRawDta = ipp_CopyAligned(lpObj->lpIppHdr + cbSize, cbData);
  3807. *lplpRawDta = lpObj->lpRawDta;
  3808. *lpcbRawDta = cbData;
  3809. }
  3810. //
  3811. // Set the flag indicating we have a full-header. This
  3812. // assures that subsequent calls to this routine returns
  3813. // only the lpData.
  3814. //
  3815. lpObj->fState |= IPPFLG_VALID;
  3816. }
  3817. }
  3818. }
  3819. } else {
  3820. dwRet = WEBIPP_BADHANDLE;
  3821. }
  3822. return dwRet;
  3823. }
  3824. /*****************************************************************************\
  3825. * WebIppRcvClose
  3826. *
  3827. * This routine Frees up our IPP object. This is called once the caller wishes
  3828. * to end the parsing/handling of ipp-stream-data.
  3829. *
  3830. \*****************************************************************************/
  3831. BOOL WebIppRcvClose(
  3832. HANDLE hObj)
  3833. {
  3834. LPIPPOBJ lpObj;
  3835. if (lpObj = (LPIPPOBJ)hObj) {
  3836. webFree(lpObj->lpIppHdr);
  3837. webFree(lpObj->lpRawDta);
  3838. delete lpObj->pwlUns;
  3839. webFree(lpObj);
  3840. return TRUE;
  3841. }
  3842. return FALSE;
  3843. }
  3844. /*****************************************************************************\
  3845. * WebIppGetError
  3846. *
  3847. * This routine returns the specific error in the ipp-object. This is called
  3848. * on a failure during the receive.
  3849. *
  3850. \*****************************************************************************/
  3851. WORD WebIppGetError(
  3852. HANDLE hIpp)
  3853. {
  3854. LPIPPOBJ lpObj;
  3855. if (lpObj = (LPIPPOBJ)hIpp)
  3856. return lpObj->wError;
  3857. return IPPRSP_ERROR_500;
  3858. }
  3859. /*****************************************************************************\
  3860. * WebIppGetReqInfo
  3861. *
  3862. * This routine returns the request-info.
  3863. *
  3864. \*****************************************************************************/
  3865. BOOL WebIppGetReqInfo(
  3866. HANDLE hIpp,
  3867. LPREQINFO lpri)
  3868. {
  3869. LPIPPOBJ lpObj;
  3870. if ((lpObj = (LPIPPOBJ)hIpp) && lpri) {
  3871. lpri->idReq = lpObj->idReq;
  3872. lpri->cpReq = lpObj->uCPRcv;
  3873. lpri->pwlUns = lpObj->pwlUns;
  3874. lpri->bFidelity = (lpObj->fState & IPPFLG_USEFIDELITY);
  3875. CopyMemory(lpri->fReq, lpObj->fReq, IPPOBJ_MASK_SIZE * sizeof(DWORD));
  3876. return TRUE;
  3877. }
  3878. return FALSE;
  3879. }
  3880. /*****************************************************************************\
  3881. * WebIppLeToRsp
  3882. *
  3883. * This routine returns an IPP-Response-Code from a Win32-LastError.
  3884. *
  3885. \*****************************************************************************/
  3886. WORD WebIppLeToRsp(
  3887. DWORD dwLastError)
  3888. {
  3889. DWORD idx;
  3890. DWORD cErrors;
  3891. if (dwLastError == ERROR_SUCCESS)
  3892. return IPPRSP_SUCCESS;
  3893. //
  3894. // Lookup lasterror.
  3895. //
  3896. cErrors = sizeof(s_LEDef) / sizeof(s_LEDef[0]);
  3897. for (idx = 0; idx < cErrors; idx++) {
  3898. if (dwLastError == s_LEDef[idx].dwLE)
  3899. return s_LEDef[idx].wRsp;
  3900. }
  3901. return IPPRSP_ERROR_500;
  3902. }
  3903. /*****************************************************************************\
  3904. * WebIppRspToLe
  3905. *
  3906. * This routine returns a Win32 LastError from an IPP-Response-Code.
  3907. *
  3908. \*****************************************************************************/
  3909. DWORD WebIppRspToLe(
  3910. WORD wRsp)
  3911. {
  3912. DWORD idx;
  3913. DWORD cErrors;
  3914. if (SUCCESS_RANGE(wRsp))
  3915. return ERROR_SUCCESS;
  3916. //
  3917. // Lookup lasterror.
  3918. //
  3919. cErrors = sizeof(s_LEIpp) / sizeof(s_LEIpp[0]);
  3920. for (idx = 0; idx < cErrors; idx++) {
  3921. if (wRsp == s_LEIpp[idx].wRsp)
  3922. return s_LEIpp[idx].dwLE;
  3923. }
  3924. return ERROR_INVALID_DATA;
  3925. }
  3926. /*****************************************************************************\
  3927. * WebIppCreatePrtJobReq
  3928. *
  3929. * Creates a IPPREQ_PRTJOB structure. This is the structure necessary
  3930. * for calling WebIpp* API's.
  3931. *
  3932. \*****************************************************************************/
  3933. PIPPREQ_PRTJOB WebIppCreatePrtJobReq(
  3934. BOOL bValidate,
  3935. LPCTSTR lpszUser,
  3936. LPCTSTR lpszDoc,
  3937. LPCTSTR lpszPrnUri)
  3938. {
  3939. PIPPREQ_PRTJOB ppj;
  3940. DWORD cbSize;
  3941. LPTSTR* lpszSrc;
  3942. LPTSTR aszSrc[(sizeof(IPPREQ_PRTJOB) / sizeof(LPTSTR))];
  3943. static DWORD s_Offs[] = {
  3944. offs(LPIPPREQ_PRTJOB, pDocument),
  3945. offs(LPIPPREQ_PRTJOB, pUserName),
  3946. offs(LPIPPREQ_PRTJOB, pPrnUri),
  3947. 0xFFFFFFFF
  3948. };
  3949. //
  3950. // Calculate the size in bytes that are necesary for
  3951. // holding the IPPREQ_PRTJOB information.
  3952. //
  3953. cbSize = sizeof(IPPREQ_PRTJOB) +
  3954. webStrSize(lpszUser) +
  3955. webStrSize(lpszDoc) +
  3956. webStrSize(lpszPrnUri);
  3957. //
  3958. // Allocate the print-job-request structure. The string
  3959. // values are appended at the end of the structure.
  3960. //
  3961. if (ppj = (PIPPREQ_PRTJOB)webAlloc(cbSize)) {
  3962. ppj->cbSize = cbSize;
  3963. ppj->bValidate = bValidate;
  3964. lpszSrc = aszSrc;
  3965. *lpszSrc++ = (LPTSTR)lpszDoc;
  3966. *lpszSrc++ = (LPTSTR)lpszUser;
  3967. *lpszSrc++ = (LPTSTR)lpszPrnUri;
  3968. ipp_PackStrings(aszSrc, (LPBYTE)ppj, s_Offs, ((LPBYTE)ppj) + cbSize);
  3969. }
  3970. return ppj;
  3971. }
  3972. /*****************************************************************************\
  3973. * WebIppCreateGetJobReq
  3974. *
  3975. * Creates a IPPREQ_GETJOB structure. This is the structure necessary
  3976. * for calling WebIpp* API's.
  3977. *
  3978. \*****************************************************************************/
  3979. PIPPREQ_GETJOB WebIppCreateGetJobReq(
  3980. DWORD idJob,
  3981. LPCTSTR lpszPrnUri)
  3982. {
  3983. PIPPREQ_GETJOB pgj;
  3984. DWORD cbSize;
  3985. LPTSTR* lpszSrc;
  3986. LPTSTR aszSrc[(sizeof(IPPREQ_GETJOB) / sizeof(LPTSTR))];
  3987. static DWORD s_Offs[] = {
  3988. offs(LPIPPREQ_GETJOB, pPrnUri),
  3989. 0xFFFFFFFF
  3990. };
  3991. //
  3992. // Calculate the size in bytes that are necesary for
  3993. // holding the IPPREQ_GETJOB information.
  3994. //
  3995. cbSize = sizeof(IPPREQ_GETJOB) + webStrSize(lpszPrnUri);
  3996. //
  3997. // Allocate the cancel-job-request structure. The string
  3998. // values are appended at the end of the structure.
  3999. //
  4000. if (pgj = (PIPPREQ_GETJOB)webAlloc(cbSize)) {
  4001. pgj->cbSize = cbSize;
  4002. pgj->idJob = idJob;
  4003. lpszSrc = aszSrc;
  4004. *lpszSrc++ = (LPTSTR)lpszPrnUri;
  4005. ipp_PackStrings(aszSrc, (LPBYTE)pgj, s_Offs, ((LPBYTE)pgj) + cbSize);
  4006. }
  4007. return pgj;
  4008. }
  4009. /*****************************************************************************\
  4010. * WebIppCreateSetJobReq
  4011. *
  4012. * Creates a IPPREQ_SETJOB structure. This is the structure necessary
  4013. * for calling WebIpp* API's.
  4014. *
  4015. \*****************************************************************************/
  4016. PIPPREQ_SETJOB WebIppCreateSetJobReq(
  4017. DWORD idJob,
  4018. DWORD dwCmd,
  4019. LPCTSTR lpszPrnUri)
  4020. {
  4021. PIPPREQ_SETJOB psj;
  4022. DWORD cbSize;
  4023. LPTSTR* lpszSrc;
  4024. LPTSTR aszSrc[(sizeof(IPPREQ_SETJOB) / sizeof(LPTSTR))];
  4025. static DWORD s_Offs[] = {
  4026. offs(LPIPPREQ_SETJOB, pPrnUri),
  4027. 0xFFFFFFFF
  4028. };
  4029. //
  4030. // Calculate the size in bytes that are necesary for
  4031. // holding the IPPREQ_SETJOB information.
  4032. //
  4033. cbSize = sizeof(IPPREQ_SETJOB) + webStrSize(lpszPrnUri);
  4034. //
  4035. // Allocate the cancel-job-request structure. The string
  4036. // values are appended at the end of the structure.
  4037. //
  4038. if (psj = (PIPPREQ_SETJOB)webAlloc(cbSize)) {
  4039. psj->cbSize = cbSize;
  4040. psj->idJob = idJob;
  4041. psj->dwCmd = dwCmd;
  4042. lpszSrc = aszSrc;
  4043. *lpszSrc++ = (LPTSTR)lpszPrnUri;
  4044. ipp_PackStrings(aszSrc, (LPBYTE)psj, s_Offs, ((LPBYTE)psj) + cbSize);
  4045. }
  4046. return psj;
  4047. }
  4048. /*****************************************************************************\
  4049. * WebIppCreateEnuJobReq
  4050. *
  4051. * Creates a IPPREQ_ENUJOB structure. This is the structure necessary
  4052. * for calling WebIpp* API's.
  4053. *
  4054. \*****************************************************************************/
  4055. PIPPREQ_ENUJOB WebIppCreateEnuJobReq(
  4056. DWORD cJobs,
  4057. LPCTSTR lpszPrnUri)
  4058. {
  4059. PIPPREQ_ENUJOB pgj;
  4060. DWORD cbSize;
  4061. LPTSTR* lpszSrc;
  4062. LPTSTR aszSrc[(sizeof(IPPREQ_ENUJOB) / sizeof(LPTSTR))];
  4063. static DWORD s_Offs[] = {
  4064. offs(LPIPPREQ_ENUJOB, pPrnUri),
  4065. 0xFFFFFFFF
  4066. };
  4067. //
  4068. // Calculate the size in bytes that are necesary for
  4069. // holding the IPPREQ_ENUJOB information.
  4070. //
  4071. cbSize = sizeof(IPPREQ_ENUJOB) + webStrSize(lpszPrnUri);
  4072. //
  4073. // Allocate the cancel-job-request structure. The string
  4074. // values are appended at the end of the structure.
  4075. //
  4076. if (pgj = (PIPPREQ_ENUJOB)webAlloc(cbSize)) {
  4077. pgj->cbSize = cbSize;
  4078. pgj->cJobs = cJobs;
  4079. lpszSrc = aszSrc;
  4080. *lpszSrc++ = (LPTSTR)lpszPrnUri;
  4081. ipp_PackStrings(aszSrc, (LPBYTE)pgj, s_Offs, ((LPBYTE)pgj) + cbSize);
  4082. }
  4083. return pgj;
  4084. }
  4085. /*****************************************************************************\
  4086. * WebIppCreateSetPrnReq
  4087. *
  4088. * Creates a IPPREQ_SETPRN structure. This is the structure necessary
  4089. * for calling WebIpp* API's.
  4090. *
  4091. \*****************************************************************************/
  4092. PIPPREQ_SETPRN WebIppCreateSetPrnReq(
  4093. DWORD dwCmd,
  4094. LPCTSTR lpszUsrName,
  4095. LPCTSTR lpszPrnUri)
  4096. {
  4097. PIPPREQ_SETPRN psp;
  4098. DWORD cbSize;
  4099. LPTSTR* lpszSrc;
  4100. LPTSTR aszSrc[(sizeof(IPPREQ_SETPRN) / sizeof(LPTSTR))];
  4101. static DWORD s_Offs[] = {
  4102. offs(LPIPPREQ_SETPRN, pUserName),
  4103. offs(LPIPPREQ_SETPRN, pPrnUri),
  4104. 0xFFFFFFFF
  4105. };
  4106. //
  4107. // Calculate the size in bytes that are necesary for
  4108. // holding the IPPREQ_SETPRN information.
  4109. //
  4110. cbSize = sizeof(IPPREQ_SETPRN) +
  4111. webStrSize(lpszUsrName) +
  4112. webStrSize(lpszPrnUri);
  4113. //
  4114. // Allocate the set-prn-request structure. The string
  4115. // values are appended at the end of the structure.
  4116. //
  4117. if (psp = (PIPPREQ_SETPRN)webAlloc(cbSize)) {
  4118. psp->cbSize = cbSize;
  4119. psp->dwCmd = dwCmd;
  4120. lpszSrc = aszSrc;
  4121. *lpszSrc++ = (LPTSTR)lpszUsrName;
  4122. *lpszSrc++ = (LPTSTR)lpszPrnUri;
  4123. ipp_PackStrings(aszSrc, (LPBYTE)psp, s_Offs, ((LPBYTE)psp) + cbSize);
  4124. }
  4125. return psp;
  4126. }
  4127. /*****************************************************************************\
  4128. * WebIppCreateGetPrnReq
  4129. *
  4130. * Creates a IPPREQ_GETPRN structure. This is the structure necessary
  4131. * for calling WebIpp* API's.
  4132. *
  4133. \*****************************************************************************/
  4134. PIPPREQ_GETPRN WebIppCreateGetPrnReq(
  4135. DWORD dwAttr,
  4136. LPCTSTR lpszPrnUri)
  4137. {
  4138. PIPPREQ_GETPRN pgp;
  4139. DWORD cbSize;
  4140. LPTSTR* lpszSrc;
  4141. LPTSTR aszSrc[(sizeof(IPPREQ_GETPRN) / sizeof(LPTSTR))];
  4142. static DWORD s_Offs[] = {
  4143. offs(LPIPPREQ_GETPRN, pPrnUri),
  4144. 0xFFFFFFFF
  4145. };
  4146. //
  4147. // Calculate the size in bytes that are necesary for
  4148. // holding the IPPREQ_GETPRN information.
  4149. //
  4150. cbSize = sizeof(IPPREQ_GETPRN) + webStrSize(lpszPrnUri);
  4151. //
  4152. // Allocate the get-prt-attribute-request structure. The string
  4153. // values are appended at the end of the structure.
  4154. //
  4155. if (pgp = (PIPPREQ_GETPRN)webAlloc(cbSize)) {
  4156. pgp->cbSize = cbSize;
  4157. pgp->dwAttr = dwAttr;
  4158. lpszSrc = aszSrc;
  4159. *lpszSrc++ = (LPTSTR)lpszPrnUri;
  4160. ipp_PackStrings(aszSrc, (LPBYTE)pgp, s_Offs, ((LPBYTE)pgp) + cbSize);
  4161. }
  4162. return pgp;
  4163. }
  4164. /*****************************************************************************\
  4165. * WebIppCreateAuthReq
  4166. *
  4167. * Creates a IPPREQ_AUTH structure. This is the structure necessary
  4168. * for calling WebIpp* API's.
  4169. *
  4170. \*****************************************************************************/
  4171. PIPPREQ_AUTH WebIppCreateAuthReq(VOID)
  4172. {
  4173. PIPPREQ_AUTH pfa;
  4174. DWORD cbSize;
  4175. //
  4176. // Calculate the size in bytes that are necesary for
  4177. // holding the IPPREQ_AUTH information.
  4178. //
  4179. cbSize = sizeof(IPPREQ_AUTH);
  4180. //
  4181. // Allocate the request structure.
  4182. //
  4183. if (pfa = (PIPPREQ_AUTH)webAlloc(cbSize)) {
  4184. pfa->cbSize = cbSize;
  4185. }
  4186. return pfa;
  4187. }
  4188. /*****************************************************************************\
  4189. * WebIppCreateJobRet
  4190. *
  4191. * Creates a IPPRET_JOB structure. This is the structure necessary
  4192. * for calling WebIpp* API's.
  4193. *
  4194. \*****************************************************************************/
  4195. PIPPRET_JOB WebIppCreateJobRet(
  4196. WORD wRsp,
  4197. BOOL bRet,
  4198. BOOL bValidate,
  4199. LPJOB_INFO_2 lpji2,
  4200. LPJOB_INFO_IPP lpipp)
  4201. {
  4202. PIPPRET_JOB pjr;
  4203. DWORD cbSize;
  4204. //
  4205. // Calculate our structure size.
  4206. //
  4207. cbSize = sizeof(IPPRET_JOB) + ipp_SizeofIPPJI2(lpji2, lpipp);
  4208. //
  4209. // Build our response.
  4210. //
  4211. if (pjr = (PIPPRET_JOB)webAlloc(cbSize)) {
  4212. pjr->cbSize = cbSize;
  4213. pjr->dwLastError = WebIppRspToLe(wRsp);
  4214. pjr->wRsp = wRsp;
  4215. pjr->bRet = bRet;
  4216. pjr->bValidate = bValidate;
  4217. ipp_BuildJI2(&pjr->ji, lpji2, lpipp, ((LPBYTE)pjr) + cbSize);
  4218. }
  4219. return pjr;
  4220. }
  4221. /*****************************************************************************\
  4222. * WebIppCreatePrnRet
  4223. *
  4224. * Creates a IPPRET_PRN structure. This is the structure necessary
  4225. * for calling WebIpp* API's.
  4226. *
  4227. \*****************************************************************************/
  4228. PIPPRET_PRN WebIppCreatePrnRet(
  4229. WORD wRsp,
  4230. BOOL bRet,
  4231. LPPRINTER_INFO_2 lppi2,
  4232. LPPRINTER_INFO_IPP lpipp)
  4233. {
  4234. PIPPRET_PRN ppr;
  4235. DWORD cbSize;
  4236. //
  4237. // Calculate our structure size.
  4238. //
  4239. cbSize = sizeof(IPPRET_PRN) + ipp_SizeofIPPPI2(lppi2, lpipp);
  4240. //
  4241. // Build our response.
  4242. //
  4243. if (ppr = (PIPPRET_PRN)webAlloc(cbSize)) {
  4244. ppr->cbSize = cbSize;
  4245. ppr->dwLastError = WebIppRspToLe(wRsp);
  4246. ppr->wRsp = wRsp;
  4247. ppr->bRet = bRet;
  4248. ipp_BuildPI2(&ppr->pi, lppi2, lpipp, ((LPBYTE)ppr) + cbSize);
  4249. }
  4250. return ppr;
  4251. }
  4252. /*****************************************************************************\
  4253. * WebIppCreateEnuJobRet
  4254. *
  4255. * Creates a IPPRET_ENUJOB structure. This is the structure necessary
  4256. * for calling WebIpp* API's.
  4257. *
  4258. \*****************************************************************************/
  4259. PIPPRET_ENUJOB WebIppCreateEnuJobRet(
  4260. WORD wRsp,
  4261. BOOL bRet,
  4262. DWORD cbJobs,
  4263. DWORD cJobs,
  4264. LPIPPJI2 lpjiSrc)
  4265. {
  4266. PIPPRET_ENUJOB pgj;
  4267. LPIPPJI2 lpjiDst;
  4268. LPBYTE lpbEnd;
  4269. DWORD idx;
  4270. DWORD cbSize;
  4271. cbSize = sizeof(IPPRET_ENUJOB) + ((cJobs && cbJobs && lpjiSrc) ? cbJobs : 0);
  4272. if (pgj = (PIPPRET_ENUJOB)webAlloc(cbSize)) {
  4273. pgj->cbSize = cbSize;
  4274. pgj->dwLastError = WebIppRspToLe(wRsp);
  4275. pgj->wRsp = wRsp;
  4276. pgj->bRet = bRet;
  4277. pgj->cItems = 0;
  4278. pgj->cbItems = 0;
  4279. pgj->pItems = NULL;
  4280. if (cJobs && cbJobs && lpjiSrc) {
  4281. //
  4282. // Initialize defaults.
  4283. //
  4284. pgj->cItems = cJobs;
  4285. pgj->cbItems = cbJobs;
  4286. pgj->pItems = (LPIPPJI2)(((LPBYTE)pgj) + sizeof(IPPRET_ENUJOB));
  4287. lpjiDst = pgj->pItems;
  4288. lpbEnd = ((LPBYTE)lpjiDst) + cbJobs;
  4289. for (idx = 0; idx < cJobs; idx++) {
  4290. lpbEnd = ipp_BuildJI2(&lpjiDst[idx], &lpjiSrc[idx].ji2, &lpjiSrc[idx].ipp, lpbEnd);
  4291. }
  4292. }
  4293. }
  4294. return pgj;
  4295. }
  4296. /*****************************************************************************\
  4297. * WebIppCreateBadRet
  4298. *
  4299. * Creates a IPPRET_ALL structure. This is the structure necessary
  4300. * for calling WebIpp* API's.
  4301. *
  4302. \*****************************************************************************/
  4303. PIPPRET_ALL WebIppCreateBadRet(
  4304. WORD wRsp,
  4305. BOOL bRet)
  4306. {
  4307. PIPPRET_ALL pra;
  4308. DWORD cbSize;
  4309. cbSize = sizeof(IPPRET_ALL);
  4310. if (pra = (PIPPRET_ALL)webAlloc(cbSize)) {
  4311. pra->cbSize = cbSize;
  4312. pra->dwLastError = WebIppRspToLe(wRsp);
  4313. pra->wRsp = wRsp;
  4314. pra->bRet = bRet;
  4315. }
  4316. return pra;
  4317. }
  4318. /*****************************************************************************\
  4319. * WebIppCreateAuthRet
  4320. *
  4321. * Creates a IPPRET_AUTH structure. This is the structure necessary
  4322. * for calling WebIpp* API's.
  4323. *
  4324. \*****************************************************************************/
  4325. PIPPRET_AUTH WebIppCreateAuthRet(
  4326. WORD wRsp,
  4327. BOOL bRet)
  4328. {
  4329. return (PIPPRET_AUTH)WebIppCreateBadRet(wRsp, bRet);
  4330. }
  4331. /*****************************************************************************\
  4332. * WebIppFreeMem
  4333. *
  4334. * Free memory allocated through the WebIpp routines.
  4335. *
  4336. \*****************************************************************************/
  4337. BOOL WebIppFreeMem(
  4338. LPVOID lpMem)
  4339. {
  4340. return webFree(lpMem);
  4341. }
  4342. /*****************************************************************************\
  4343. * WebIppCvtJI2toIPPJI2
  4344. *
  4345. * Converts an array of JOB_INFO_2 structures to an array of IPPJI2 structures.
  4346. *
  4347. * This code is only called from inetsrv/spool.cxx. It was better to change the
  4348. * the buffer calculation here than in the calling function since IPPJI2 is a
  4349. * web printing only call. This will return the new required Job size in the
  4350. * cbJobs Parameter that is passed in.
  4351. *
  4352. \*****************************************************************************/
  4353. LPIPPJI2 WebIppCvtJI2toIPPJI2(
  4354. LPCTSTR lpszJobBase,
  4355. LPDWORD lpcbJobs,
  4356. DWORD cJobs,
  4357. LPJOB_INFO_2 lpjiSrc)
  4358. {
  4359. LPBYTE lpbEnd;
  4360. DWORD idx;
  4361. DWORD cbSize;
  4362. DWORD cbUri;
  4363. LPIPPJI2 lpjiDst = NULL;
  4364. WEB_IPP_ASSERT(lpcbJobs);
  4365. if (*lpcbJobs && cJobs && lpjiSrc) {
  4366. //
  4367. // For each job, we need to add enough to hold the extra
  4368. // information.
  4369. //
  4370. cbUri = 2*(webStrSize(lpszJobBase) + sizeof(DWORD)) * cJobs;
  4371. //
  4372. // There can be two of these strings allocated, one for the JobUri and the
  4373. // other for the Printer Uri
  4374. //
  4375. cbSize = (sizeof(IPPJI2) - sizeof(JOB_INFO_2)) * cJobs + *lpcbJobs + cbUri;
  4376. //
  4377. // cbJobs already contains the correct size for the JOB_INFO_2 structure and its
  4378. // strings we need the space for the JOB_INFO_IPP part of the structure plus the
  4379. // extra strings that will be added.
  4380. //
  4381. *lpcbJobs = cbSize; // Pass the required size back
  4382. if (lpjiDst = (LPIPPJI2)webAlloc(cbSize)) {
  4383. //
  4384. // Position string end at the end of our buffer.
  4385. //
  4386. lpbEnd = ((LPBYTE)lpjiDst) + cbSize;
  4387. //
  4388. // For each job, copy.
  4389. //
  4390. for (idx = 0; idx < cJobs; idx++) {
  4391. lpbEnd = ipp_CopyJI2toIPPJI2(&lpjiDst[idx],
  4392. &lpjiSrc[idx],
  4393. (LPTSTR)lpszJobBase,
  4394. lpbEnd);
  4395. }
  4396. }
  4397. }
  4398. return lpjiDst;
  4399. }
  4400. /*****************************************************************************\
  4401. * WebIppPackJI2
  4402. *
  4403. * This takes in a JOB_INFO_2 structure whose members are note packed correctly
  4404. * and returns a correctly filled out and allocated JOB_INFO_2. It does not
  4405. * copy the DEVMODE and SECURITY-DESCRIPTOR fields.
  4406. *
  4407. \*****************************************************************************/
  4408. LPJOB_INFO_2 WebIppPackJI2(
  4409. IN LPJOB_INFO_2 lpji2,
  4410. OUT LPDWORD lpcbSize,
  4411. IN ALLOCATORFN pfnAlloc
  4412. ) {
  4413. WEB_IPP_ASSERT(lpji2);
  4414. WEB_IPP_ASSERT(pfnAlloc);
  4415. WEB_IPP_ASSERT(lpcbSize);
  4416. *lpcbSize = 0;
  4417. //
  4418. // This is used to perform the ipp_PackStrings operation
  4419. //
  4420. LPTSTR aszSrc[(sizeof(IPPJI2) / sizeof(LPTSTR))];
  4421. //
  4422. // First get the required allocation size
  4423. //
  4424. DWORD dwSize = ipp_SizeofIPPJI2( lpji2, NULL ) + sizeof(JOB_INFO_2);
  4425. //
  4426. // Allocate the memory required to store the data
  4427. //
  4428. LPJOB_INFO_2 pji2out = (LPJOB_INFO_2)pfnAlloc( dwSize );
  4429. if (pji2out) {
  4430. //
  4431. // First, do a straight copy of the memory from the incoming JI2 to the outgoing
  4432. // ji2
  4433. //
  4434. LPTSTR* lpszSrc = aszSrc;
  4435. LPBYTE lpbEnd = (LPBYTE)pji2out + dwSize;
  4436. *lpcbSize = dwSize;
  4437. CopyMemory( pji2out, lpji2, sizeof(JOB_INFO_2) );
  4438. pji2out->pDevMode = NULL; // These two pointers cannot be set
  4439. pji2out->pSecurityDescriptor = NULL;
  4440. *lpszSrc++ = lpji2->pPrinterName;
  4441. *lpszSrc++ = lpji2->pMachineName;
  4442. *lpszSrc++ = lpji2->pUserName;
  4443. *lpszSrc++ = lpji2->pDocument;
  4444. *lpszSrc++ = lpji2->pNotifyName;
  4445. *lpszSrc++ = lpji2->pDatatype;
  4446. *lpszSrc++ = lpji2->pPrintProcessor;
  4447. *lpszSrc++ = lpji2->pParameters;
  4448. *lpszSrc++ = lpji2->pDriverName;
  4449. *lpszSrc++ = lpji2->pStatus;
  4450. ipp_PackStrings(aszSrc, (LPBYTE)pji2out, s_JI2Off, lpbEnd);
  4451. }
  4452. return pji2out;
  4453. }