Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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