a5d2342ce8b63d2c612638b6a2aa499a19f2c323
[ira/wip.git] / testprogs / win32 / spoolss / printlib.c
1 /*
2    Unix SMB/CIFS implementation.
3    test suite for spoolss rpc operations
4
5    Copyright (C) Gerald (Jerry) Carter 2007
6    Copyright (C) Guenther Deschner 2009-2010
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include <windows.h>
23 #include <stdio.h>
24 #include <assert.h>
25
26 void print_devmode(DEVMODE *pDevModeIn)
27 {
28         if (pDevModeIn == NULL) {
29                 printf("\tDevice Mode\t= (null)\n");
30                 return;
31         }
32
33         printf("\tDEVMODE:----------\n");
34         printf("\tDeviceName:      [%s]\n", pDevModeIn->dmDeviceName);
35         printf("\tSpecVersion:     %d\n",   pDevModeIn->dmSpecVersion);
36         printf("\tDriverVersion:   %d\n",   pDevModeIn->dmDriverVersion);
37         printf("\tSize:            %d\n",   pDevModeIn->dmSize);
38         printf("\tDriverExtra:     %d\n",   pDevModeIn->dmDriverExtra);
39         printf("\tFields:          0x%x\n", pDevModeIn->dmFields);
40
41         if (pDevModeIn->dmFields & DM_ORIENTATION)
42                 printf("\tOrientation:     %d\n", pDevModeIn->dmOrientation);
43         if (pDevModeIn->dmFields & DM_PAPERSIZE)
44                 printf("\tPaperSize:       %d\n", pDevModeIn->dmPaperSize);
45         if (pDevModeIn->dmFields & DM_PAPERLENGTH)
46                 printf("\tPaperLength:     %d\n", pDevModeIn->dmPaperLength);
47         if (pDevModeIn->dmFields & DM_PAPERWIDTH)
48                 printf("\tPaperWidth:      %d\n", pDevModeIn->dmPaperWidth);
49 //      if (pDevModeIn->dmFields & DM_POSITION)
50 //              printf("\tPosition:        %d\n", pDevModeIn->dmPosition);
51         if (pDevModeIn->dmFields & DM_SCALE)
52                 printf("\tScale:           %d\n", pDevModeIn->dmScale);
53         if (pDevModeIn->dmFields & DM_COPIES)
54                 printf("\tCopies:          %d\n", pDevModeIn->dmCopies );
55         if (pDevModeIn->dmFields & DM_DEFAULTSOURCE)
56                 printf("\tDefaultSource:   %d\n", pDevModeIn->dmDefaultSource);
57         if (pDevModeIn->dmFields & DM_PRINTQUALITY)
58                 printf("\tPrintQuality:    %d\n", pDevModeIn->dmPrintQuality);
59         if (pDevModeIn->dmFields & DM_COLOR)
60                 printf("\tColor:           %d\n", pDevModeIn->dmColor);
61         if (pDevModeIn->dmFields & DM_DUPLEX)
62                 printf("\tDuplex:          %d\n", pDevModeIn->dmDuplex);
63         if (pDevModeIn->dmFields & DM_YRESOLUTION)
64                 printf("\tYResolution:     %d\n", pDevModeIn->dmYResolution);
65         if (pDevModeIn->dmFields & DM_TTOPTION)
66                 printf("\tTTOption:        %d\n", pDevModeIn->dmTTOption);
67         if (pDevModeIn->dmFields & DM_COLLATE)
68                 printf("\tCollate:         %d\n", pDevModeIn->dmCollate);
69         if (pDevModeIn->dmFields & DM_FORMNAME)
70                 printf("\tForm:            [%s]\n", pDevModeIn->dmFormName);
71         if (pDevModeIn->dmFields & DM_LOGPIXELS)
72                 printf("\tLogPixels:       %d\n", pDevModeIn->dmLogPixels);
73         if (pDevModeIn->dmFields & DM_BITSPERPEL)
74                 printf("\tBitsPerPel:      %d\n", pDevModeIn->dmBitsPerPel);
75         if (pDevModeIn->dmFields & DM_PELSWIDTH)
76                 printf("\tPelsWidth:       %d\n", pDevModeIn->dmPelsWidth);
77         if (pDevModeIn->dmFields & DM_PELSHEIGHT)
78                 printf("\tPelsHeight:      %d\n", pDevModeIn->dmPelsHeight);
79         if (pDevModeIn->dmFields & DM_DISPLAYFLAGS)
80                 printf("\tDisplayFlags:    %d\n", pDevModeIn->dmDisplayFlags);
81 //      if (pDevModeIn->dmFields & DM_NUP)
82 //              printf("\tNup:             %d\n", pDevModeIn->dmNup);
83         if (pDevModeIn->dmFields & DM_DISPLAYFREQUENCY)
84                 printf("\tDisplayFrequency:%d\n", pDevModeIn->dmDisplayFrequency);
85         if (pDevModeIn->dmFields & DM_ICMMETHOD)
86                 printf("\tICMMethod:       %d\n", pDevModeIn->dmICMMethod);
87         if (pDevModeIn->dmFields & DM_ICMINTENT)
88                 printf("\tICMIntent:       %d\n", pDevModeIn->dmICMIntent);
89         if (pDevModeIn->dmFields & DM_MEDIATYPE)
90                 printf("\tMediaType:       %d\n", pDevModeIn->dmMediaType);
91         if (pDevModeIn->dmFields & DM_DITHERTYPE)
92                 printf("\tDitherType:      %d\n", pDevModeIn->dmDitherType);
93 //      if (pDevModeIn->dmFields & DM_PANNINGWIDTH)
94 //              printf("\tPanningWidth:    %d\n", pDevModeIn->dmPanningWidth);
95 //      if (pDevModeIn->dmFields & DM_PANNINGHEIGHT)
96 //              printf("\tPanningHeight:   %d\n", pDevModeIn->dmPanningHeight);
97
98 #if 0
99         if (bForceIn) {
100                 printf("DEVMODE\n");
101                 Dump((BYTE*)pDevModeIn, sizeof(DEVMODE), LEADER);
102
103                 if (pDevModeIn->dmDriverExtra) {
104                         printf("DriverExtra\n");
105                         Dump((BYTE*)pDevModeIn + sizeof(DEVMODE), pDevModeIn->dmDriverExtra, LEADER);
106                 }
107         }
108 #endif
109
110         return;
111 }
112
113 void print_acl(const char* str, ACL *acl)
114 {
115         printf("%s\n", str);
116         if (acl == NULL)
117                 return;
118
119         printf("\t\tACL Revision \t\t 0x%x\n", acl->AclRevision);
120         printf("\t\tSbz1\t\t 0x%x\n", acl->Sbz1);
121         printf("\t\tSbz2\t\t 0x%x\n", acl->Sbz2);
122         printf("\t\tACL Size\t\t 0x%x\n", acl->AclSize);
123         printf("\t\tACL Count\t\t 0x%x\n", acl->AceCount);
124
125         return;
126 }
127
128 void print_sid(const char* str, SID *sid)
129 {
130         DWORD   i = 0;
131
132         printf("%s\n", str);
133         printf("0x%x\n", sid);
134         if (sid == NULL)
135                 return;
136         printf("\t\tRevision\t\t0x%x\n", sid->Revision);
137         printf("\t\tSubAuthorityCount\t0x%x\n", sid->SubAuthorityCount);
138         printf("\t\tSubAuthority\n\t");
139         while (i < sid->SubAuthorityCount) {
140                 printf("\t0x%x", sid->SubAuthority[i]);
141                 if (i%4 == 3)
142                         printf("\n\t");
143                 i++;
144         }
145
146         return;
147 }
148
149 void print_secdesc(SECURITY_DESCRIPTOR *secdesc)
150 {
151         if (secdesc == NULL) {
152                 printf("\tSecurity Descriptor\t= (null)\n");
153                 return;
154         }
155
156         printf("\tRevision\t= 0x%x\n", secdesc->Revision);
157         printf("\tSbz1\t\t= 0x%x\n", secdesc->Sbz1);
158 #if 0
159         print_sid("\tOwner\t\t= ", secdesc->Owner);
160         print_sid("\tGroup\t\t= ",secdesc->Group);
161         print_acl("\tSacl\t\t= ", secdesc->Sacl);
162         print_acl("\tDacl\t\t= ", secdesc->Dacl);
163 #endif
164         return;
165 }
166
167 void PrintLastError()
168 {
169         LPVOID lpMsgBuf;
170         DWORD status;
171
172         status = GetLastError();
173
174         FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
175                       NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
176                       (LPTSTR)&lpMsgBuf, 0, NULL);
177         printf("ERROR  [0x%x] : %s\n", status, (char*)lpMsgBuf);
178         LocalFree(lpMsgBuf);
179
180         return;
181 }
182
183
184 void print_job_info_1(PJOB_INFO_1 info)
185 {
186         printf("\tJob ID\t\t= %d\n",            info->JobId);
187         printf("\tPrinter Name\t= %s\n",        info->pPrinterName);
188         printf("\tMachine Name\t= %s\n",        info->pMachineName);
189         printf("\tUser Name\t= %s\n",           info->pUserName);
190         printf("\tDocument\t= %s\n",            info->pDocument);
191         printf("\tDatatype\t= %s\n",            info->pDatatype);
192         printf("\tStatus\t\t= %s\n",            info->pStatus);
193         printf("\tStatus\t= %d\n",              info->Status);
194         printf("\tPriority\t= %d\n",            info->Priority);
195         printf("\tPosition\t= %d\n",            info->Position);
196         printf("\tTotal Pages\t= %d\n", info->TotalPages);
197         printf("\tPages Printed\t= %d\n",       info->PagesPrinted);
198         printf("\tSubmitted (DD:MM:YY HH:MM:SS)\t= %d:%d:%d %d:%d:%d UTC\n",
199                 info->Submitted.wDay, info->Submitted.wMonth,
200                 info->Submitted.wYear, info->Submitted.wHour,
201                 info->Submitted.wMinute, info->Submitted.wSecond);
202
203         return;
204 }
205
206 void print_job_info_2(PJOB_INFO_2 info)
207 {
208         printf("\tJob ID\t\t= %d\n",            info->JobId);
209         printf("\tPrinter Name\t= %s\n",        info->pPrinterName);
210         printf("\tMachine Name\t= %s\n",        info->pMachineName);
211         printf("\tUser Name\t= %s\n",           info->pUserName);
212         printf("\tDocument\t= %s\n",            info->pDocument);
213         printf("\tDatatype\t= %s\n",            info->pDatatype);
214         printf("\tNotify Name\t= %s\n",         info->pNotifyName);
215         printf("\tPrint Processor\t= %s\n",     info->pPrintProcessor);
216         printf("\tParameters\t= %s\n",          info->pParameters);
217         printf("\tDriver Name\t= %s\n",         info->pDriverName);
218         printf("\tStatus\t\t= %s\n",            info->pStatus);
219         printf("\tStatus\t\t= %d\n",            info->Status);
220         printf("\tPriority\t= %d\n",            info->Priority);
221         printf("\tPosition\t= %d\n",            info->Position);
222         printf("\tTotal Pages\t= %d\n",         info->TotalPages);
223         printf("\tPages Printed\t= %d\n",       info->PagesPrinted);
224         printf("\tStart Time\t= %d\n",          info->StartTime);
225         printf("\tUntil Time\t= %d\n",          info->UntilTime);
226         printf("\tTime\t\t= %d\n",              info->Time);
227         printf("\tSize\t\t= %d\n",              info->Size);
228         printf("\tSubmitted (DD:MM:YY HH:MM:SS)\t= %d:%d:%d %d:%d:%d UTC\n",
229                 info->Submitted.wDay, info->Submitted.wMonth,
230                 info->Submitted.wYear, info->Submitted.wHour,
231                 info->Submitted.wMinute, info->Submitted.wSecond);
232         printf("\tDevice Mode Information\n");
233         printf("\t-----------------------\n");
234         print_devmode(info->pDevMode);
235         printf("\tSecurity Descriptor Information\n");
236         printf("\t-------------------------------\n");
237         print_secdesc(info->pSecurityDescriptor);
238
239         return;
240 }
241
242 void print_job_info_3(PJOB_INFO_3 info)
243 {
244         printf("\tJob ID\t\t= %d\n",            info->JobId);
245         printf("\tJob ID Next Job\t= %d\n",     info->NextJobId);
246         printf("\tReserved (must be 0)\t= %d\n",info->Reserved);
247
248         return;
249 }
250
251 void print_monitor_info_1(PMONITOR_INFO_1 info)
252 {
253         printf("\tMonitor Name\t= %s\n",        info->pName);
254
255         return;
256 }
257
258 void print_monitor_info_2(PMONITOR_INFO_2 info)
259 {
260         printf("\tMonitor Name\t= %s\n",        info->pName);
261         printf("\tEnvironment\t= %s\n",         info->pEnvironment);
262         printf("\tDLL Name\t= %s\n",            info->pDLLName);
263
264         return;
265 }
266
267 void print_monitor_info_bylevel(DWORD level, LPBYTE buffer, DWORD count)
268 {
269         DWORD i;
270         PMONITOR_INFO_1 buffer1 = NULL;
271         PMONITOR_INFO_2 buffer2 = NULL;
272
273         if (!buffer) {
274                 return;
275         }
276
277         switch (level) {
278         case 1:
279                 buffer1 = (PMONITOR_INFO_1)buffer;
280                 break;
281         case 2:
282                 buffer2 = (PMONITOR_INFO_2)buffer;
283                 break;
284         default:
285                 break;
286         }
287
288         printf("Monitor Info Level %d:\n", level);
289
290         switch (level) {
291         case 1:
292                 for (i=0; i<count; i++) {
293                         print_monitor_info_1(&buffer1[i]);
294                         printf("\n");
295                 }
296                 break;
297         case 2:
298                 for (i=0; i<count; i++) {
299                         print_monitor_info_2(&buffer2[i]);
300                         printf("\n");
301                 }
302                 break;
303         default:
304                 break;
305         }
306 }
307
308 void print_port_info_1(PPORT_INFO_1 info)
309 {
310         printf("\tPort Name\t= %s\n",   info->pName);
311         return;
312 }
313
314 void print_port_info_2(PPORT_INFO_2 info)
315 {
316         printf("\tPort Name\t= %s\n",   info->pPortName);
317         printf("\tMonitor Name\t= %s\n",info->pMonitorName);
318         printf("\tDescription\t= %s\n", info->pDescription);
319         printf("\tPort Type\t= 0x%08x\n", info->fPortType);
320         printf("\tReserved\t= 0x%08x\n", info->Reserved);
321         return;
322 }
323
324 void print_port_info_3(PPORT_INFO_3 info)
325 {
326         printf("\tStatus\t= 0x%08x\n", info->dwStatus);
327         printf("\tStatus String\t= %s\n", info->pszStatus);
328         printf("\tSeverity\t= 0x%08x\n", info->dwSeverity);
329         return;
330 }
331
332 void print_port_info_bylevel(DWORD level, LPBYTE buffer, DWORD count)
333 {
334         DWORD i;
335         PPORT_INFO_1 buffer1 = NULL;
336         PPORT_INFO_2 buffer2 = NULL;
337         PPORT_INFO_3 buffer3 = NULL;
338
339         if (!buffer) {
340                 return;
341         }
342
343         switch (level) {
344         case 1:
345                 buffer1 = (PPORT_INFO_1)buffer;
346                 break;
347         case 2:
348                 buffer2 = (PPORT_INFO_2)buffer;
349                 break;
350         case 3:
351                 buffer3 = (PPORT_INFO_3)buffer;
352                 break;
353         default:
354                 break;
355         }
356
357         printf("Port Info Level %d:\n", level);
358
359         switch (level) {
360         case 1:
361                 for (i=0; i<count; i++) {
362                         print_port_info_1(&buffer1[i]);
363                         printf("\n");
364                 }
365                 break;
366         case 2:
367                 for (i=0; i<count; i++) {
368                         print_port_info_2(&buffer2[i]);
369                         printf("\n");
370                 }
371                 break;
372         case 3:
373                 for (i=0; i<count; i++) {
374                         print_port_info_3(&buffer3[i]);
375                         printf("\n");
376                 }
377                 break;
378         default:
379                 break;
380         }
381 }
382
383 void print_form_info_1(PFORM_INFO_1 info)
384 {
385         printf("\tForm Name\t= %s\n",   info->pName);
386         printf("\tFlags\t\t= 0x%x\n",   info->Flags);
387         printf("\tSize\t\t= %d x %d\n", info->Size.cx, info->Size.cy);
388         printf("\tRectangle\t= [left]%d [right]%d [top]%d [bottom]%d\n",
389                         info->ImageableArea.left, info->ImageableArea.right,
390                         info->ImageableArea.top, info->ImageableArea.bottom);
391
392         return;
393 }
394
395 void print_form_info_2(PFORM_INFO_2 info)
396 {
397         printf("\tForm Name\t= %s\n",   info->pName);
398         printf("\tFlags\t\t= 0x%x\n",   info->Flags);
399         printf("\tSize\t\t= %d x %d\n", info->Size.cx, info->Size.cy);
400         printf("\tRectangle\t= [left]%d [right]%d [top]%d [bottom]%d\n",
401                         info->ImageableArea.left, info->ImageableArea.right,
402                         info->ImageableArea.top, info->ImageableArea.bottom);
403         printf("\tKeyword\t= %s\n",     info->pKeyword);
404         printf("\tString Type\t= 0x%08x\n", info->StringType);
405         printf("\tMui DLL\t= %s\n",     info->pMuiDll);
406         printf("\tResource Id\t= 0x%08x\n", info->dwResourceId);
407         printf("\tDisplay Name\t= %s\n",info->pDisplayName);
408         printf("\tLang Id\t= 0x%04x\n", info->wLangId);
409
410         return;
411 }
412
413 void print_form_info_bylevel(DWORD level, LPBYTE buffer, DWORD count)
414 {
415         DWORD i;
416         PFORM_INFO_1 buffer1 = NULL;
417         PFORM_INFO_2 buffer2 = NULL;
418
419         if (!buffer) {
420                 return;
421         }
422
423         switch (level) {
424         case 1:
425                 buffer1 = (PFORM_INFO_1)buffer;
426                 break;
427         case 2:
428                 buffer2 = (PFORM_INFO_2)buffer;
429                 break;
430         default:
431                 break;
432         }
433
434         printf("Form Info Level %d:\n", level);
435
436         switch (level) {
437         case 1:
438                 for (i=0; i<count; i++) {
439                         print_form_info_1(&buffer1[i]);
440                         printf("\n");
441                 }
442                 break;
443         case 2:
444                 for (i=0; i<count; i++) {
445                         print_form_info_2(&buffer2[i]);
446                         printf("\n");
447                 }
448                 break;
449         default:
450                 break;
451         }
452 }
453
454 void print_printer_info_1(PPRINTER_INFO_1 info)
455 {
456         printf("\tPrinter Name\t= %s\n",        info->pName);
457         printf("\tDescription\t= %s\n",         info->pDescription);
458         printf("\tComment\t\t= %s\n",           info->pComment);
459         printf("\tFlags\t\t= 0x%x\n",           info->Flags);
460
461         return;
462 }
463
464 void print_printer_info_2(PPRINTER_INFO_2 info)
465 {
466         printf("\tServer Name\t\t= %s\n",       info->pServerName);
467         printf("\tPrinter Name\t\t= %s\n",      info->pPrinterName);
468         printf("\tPort Name\t\t= %s\n",         info->pPortName);
469         printf("\tShare Name\t\t= %s\n",        info->pShareName);
470         printf("\tDriver Name\t\t= %s\n",       info->pDriverName);
471         printf("\tComment\t\t\t= %s\n",         info->pComment);
472         printf("\tLocation\t\t= %s\n",          info->pLocation);
473         printf("\tSeparator File\t\t= %s\n",    info->pSepFile);
474         printf("\tDefault Data Type\t= %s\n",   info->pDatatype);
475         printf("\tPrint Processor\t\t= %s\n",   info->pPrintProcessor);
476         printf("\tParameters\t\t= %s\n",        info->pParameters);
477         printf("\tAttributes\t\t= 0x%x\n",      info->Attributes);
478         printf("\tPriority\t\t= 0x%x\n",        info->Priority);
479         printf("\tDefault Priority\t= 0x%x\n",  info->DefaultPriority);
480         printf("\tStart Time\t\t= 0x%x\n",      info->StartTime);
481         printf("\tUntil Time\t\t= 0x%x\n",      info->UntilTime);
482         printf("\tStatus\t\t\t= 0x%x\n",        info->Status);
483         printf("\tcJobs\t\t\t= 0x%x\n",         info->cJobs);
484         printf("\tAverage PPM\t\t= 0x%x\n",     info->AveragePPM);
485
486         printf("\tDevice Mode Information\n");
487         printf("\t-----------------------\n");
488         print_devmode(info->pDevMode);
489 #if 0
490         printf("\tSecurity Descriptor Information\n");
491         printf("\t-------------------------------\n");
492         print_secdesc(info->pSecurityDescriptor);
493 #endif
494         return;
495 }
496
497 void print_printer_info_5(PPRINTER_INFO_5 info)
498 {
499         printf("\tPrinter Name\t\t\t= %s\n",            info->pPrinterName);
500         printf("\tPort Name\t\t\t= %s\n",               info->pPortName);
501         printf("\tAttributes\t\t\t= 0x%x\n",            info->Attributes);
502         printf("\tDev NotSelect Timeout\t= 0x%x\n",     info->DeviceNotSelectedTimeout);
503         printf("\tTX RetryTimeout\t\t= 0x%x\n",         info->TransmissionRetryTimeout);
504         return;
505 }
506
507 void print_printer_info_6(PPRINTER_INFO_6 info)
508 {
509         printf("\tStatus\t\t\t= 0x%x\n",                info->dwStatus);
510         return;
511 }
512
513 void print_printer_info_7(PPRINTER_INFO_7 info)
514 {
515         printf("\tObject GUID\t\t\t= %s\n",             info->pszObjectGUID);
516         printf("\tAction\t\t\t= 0x%x\n",                info->dwAction);
517         return;
518 }
519
520 void print_printer_info_8(PPRINTER_INFO_8 info)
521 {
522         print_devmode(info->pDevMode);
523 }
524
525 void print_printer_info_9(PPRINTER_INFO_9 info)
526 {
527         print_devmode(info->pDevMode);
528 }
529
530 void print_printer_info_bylevel(DWORD level, LPBYTE buffer, DWORD count)
531 {
532         DWORD i;
533         PPRINTER_INFO_1 buffer1 = NULL;
534         PPRINTER_INFO_2 buffer2 = NULL;
535         PPRINTER_INFO_3 buffer3 = NULL;
536         PPRINTER_INFO_4 buffer4 = NULL;
537         PPRINTER_INFO_5 buffer5 = NULL;
538         PPRINTER_INFO_6 buffer6 = NULL;
539         PPRINTER_INFO_7 buffer7 = NULL;
540         PPRINTER_INFO_8 buffer8 = NULL;
541
542         if (!buffer) {
543                 return;
544         }
545
546         switch (level) {
547         case 1:
548                 buffer1 = (PPRINTER_INFO_1)buffer;
549                 break;
550         case 2:
551                 buffer2 = (PPRINTER_INFO_2)buffer;
552                 break;
553         case 3:
554                 buffer3 = (PPRINTER_INFO_3)buffer;
555                 break;
556         case 4:
557                 buffer4 = (PPRINTER_INFO_4)buffer;
558                 break;
559         case 5:
560                 buffer5 = (PPRINTER_INFO_5)buffer;
561                 break;
562         case 6:
563                 buffer6 = (PPRINTER_INFO_6)buffer;
564                 break;
565         case 7:
566                 buffer7 = (PPRINTER_INFO_7)buffer;
567                 break;
568         case 8:
569                 buffer8 = (PPRINTER_INFO_8)buffer;
570                 break;
571         default:
572                 break;
573         }
574
575         printf("Printer Info Level %d:\n", level);
576
577         switch (level) {
578         case 1:
579                 for (i=0; i<count; i++) {
580                         print_printer_info_1(&buffer1[i]);
581                         printf("\n");
582                 }
583                 break;
584         case 2:
585                 for (i=0; i<count; i++) {
586                         print_printer_info_2(&buffer2[i]);
587                         printf("\n");
588                 }
589                 break;
590 #if 0
591         case 3:
592                 for (i=0; i<count; i++) {
593                         print_printer_info_3(&buffer3[i]);
594                         printf("\n");
595                 }
596                 break;
597         case 4:
598                 for (i=0; i<count; i++) {
599                         print_printer_info_4(&buffer4[i]);
600                         printf("\n");
601                 }
602                 break;
603 #endif
604         case 5:
605                 for (i=0; i<count; i++) {
606                         print_printer_info_5(&buffer5[i]);
607                         printf("\n");
608                 }
609                 break;
610         case 6:
611                 for (i=0; i<count; i++) {
612                         print_printer_info_6(&buffer6[i]);
613                         printf("\n");
614                 }
615                 break;
616         case 7:
617                 for (i=0; i<count; i++) {
618                         print_printer_info_7(&buffer7[i]);
619                         printf("\n");
620                 }
621                 break;
622         case 8:
623                 for (i=0; i<count; i++) {
624                         print_printer_info_8(&buffer8[i]);
625                         printf("\n");
626                 }
627                 break;
628         default:
629                 break;
630         }
631 }
632
633 void print_printprocessor_info_1(PPRINTPROCESSOR_INFO_1 info)
634 {
635         printf("\tPrint Processor Name\t= %s\n", info->pName);
636
637         return;
638 }
639
640 void print_printprocessor_info_bylevel(DWORD level, LPBYTE buffer, DWORD count)
641 {
642         DWORD i;
643         PPRINTPROCESSOR_INFO_1 buffer1 = NULL;
644
645         if (!buffer) {
646                 return;
647         }
648
649         switch (level) {
650         case 1:
651                 buffer1 = (PPRINTPROCESSOR_INFO_1)buffer;
652                 break;
653         default:
654                 break;
655         }
656
657         printf("Print Processor Info Level %d:\n", level);
658
659         switch (level) {
660         case 1:
661                 for (i=0; i<count; i++) {
662                         print_printprocessor_info_1(&buffer1[i]);
663                         printf("\n");
664                 }
665                 break;
666         default:
667                 break;
668         }
669 }
670
671 void print_driver_info_1(PDRIVER_INFO_1 info)
672 {
673         printf("\tDriver Name\t= %s\n\n",       info->pName);
674
675         return;
676 }
677
678 void print_driver_info_2(PDRIVER_INFO_2 info)
679 {
680         printf("\tDriver Name\t= %s\n",         info->pName);
681         printf("\tEnvironment\t= %s\n",         info->pEnvironment);
682         printf("\tVersion\t\t= %d\n",           info->cVersion);
683         printf("\tDriver Path\t= %s\n",         info->pDriverPath);
684         printf("\tData File\t= %s\n",           info->pDataFile);
685         printf("\tConfig File\t= %s\n\n",       info->pConfigFile);
686
687         return;
688 }
689
690 void print_driver_info_3(PDRIVER_INFO_3 info)
691 {
692         char *ptr = NULL;
693
694         printf("\tDriver Name\t= %s\n",         info->pName);
695         printf("\tEnvironment\t= %s\n",         info->pEnvironment);
696         printf("\tVersion\t\t= %d\n",           info->cVersion);
697         printf("\tDriver Path\t= %s\n",         info->pDriverPath);
698         printf("\tData File\t= %s\n",           info->pDataFile);
699         printf("\tConfig File\t= %s\n",         info->pConfigFile);
700         printf("\tHelp Path\t= %s\n",           info->pHelpFile);
701         printf("\tMonitor Name\t= %s\n",        info->pMonitorName);
702         printf("\tData Type\t= %s\n",           info->pDefaultDataType);
703         ptr = (char*)info->pDependentFiles;
704         while ((ptr != NULL) && (*ptr != '\0')) {
705                 printf("\tDependent Files\t= %s\n", ptr);
706                 for (;*ptr != '\0'; ptr++)
707                         /* printf("%s\n", ptr); */
708                         ;
709                 ptr++;
710         }
711
712         return;
713 }
714
715 void print_driver_info_4(PDRIVER_INFO_4 info)
716 {
717         char *ptr = NULL;
718
719         printf("\tDriver Name\t= %s\n",         info->pName);
720         printf("\tEnvironment\t= %s\n",         info->pEnvironment);
721         printf("\tVersion\t\t= %d\n",           info->cVersion);
722         printf("\tDriver Path\t= %s\n",         info->pDriverPath);
723         printf("\tData File\t= %s\n",           info->pDataFile);
724         printf("\tConfig File\t= %s\n",         info->pConfigFile);
725         printf("\tHelp Path\t= %s\n",           info->pHelpFile);
726         printf("\tMonitor Name\t= %s\n",        info->pMonitorName);
727         printf("\tData Type\t= %s\n",           info->pDefaultDataType);
728         printf("\tPrevious Names\t= %s\n",      info->pszzPreviousNames);
729         ptr = (char*)info->pDependentFiles;
730         while ((ptr != NULL) && (*ptr != '\0')) {
731                 printf("\tDependent Files\t= %s\n", ptr);
732                 for (;*ptr != '\0'; ptr++)
733                         /* printf("%s\n", ptr); */
734                         ;
735                 ptr++;
736         }
737
738         return;
739 }
740
741 void print_driver_info_5(PDRIVER_INFO_5 info)
742 {
743         printf("\tDriver Name\t= %s\n",         info->pName);
744         printf("\tEnvironment\t= %s\n",         info->pEnvironment);
745         printf("\tVersion\t\t= %d\n",           info->cVersion);
746         printf("\tDriver Path\t= %s\n",         info->pDriverPath);
747         printf("\tData File\t= %s\n",           info->pDataFile);
748         printf("\tConfig File\t= %s\n",         info->pConfigFile);
749         printf("\tDriver Attributes\t= %d\n",   info->dwDriverAttributes);
750         printf("\tConfig Version\t= %d\n",      info->dwConfigVersion);
751         printf("\tDriver Version\t= %d\n",      info->dwDriverVersion);
752
753         return;
754 }
755
756 void print_driver_info_6(PDRIVER_INFO_6 info)
757 {
758         char *ptr = NULL;
759
760         printf("\tDriver Name\t= %s\n",         info->pName);
761         printf("\tEnvironment\t= %s\n",         info->pEnvironment);
762         printf("\tVersion\t\t= %d\n",           info->cVersion);
763         printf("\tDriver Path\t= %s\n",         info->pDriverPath);
764         printf("\tData File\t= %s\n",           info->pDataFile);
765         printf("\tConfig File\t= %s\n",         info->pConfigFile);
766         printf("\tHelp Path\t= %s\n",           info->pHelpFile);
767         printf("\tMonitor Name\t= %s\n",        info->pMonitorName);
768         printf("\tData Type\t= %s\n",           info->pDefaultDataType);
769         printf("\tPrevious Names\t= %s\n",      info->pszzPreviousNames);
770         ptr = (char*)info->pDependentFiles;
771         if (ptr != NULL) {
772                 while (*ptr != '\0') {
773                         printf("\tDependent Files\t= %s\n", ptr);
774                         for (;*ptr != '\0'; ptr++)
775                                 /* printf("%s\n", ptr); */
776                                 ;
777                         ptr++;
778                 }
779         } else {
780                 printf("\tPrevious Names\t= (null)\n");
781         }
782
783         ptr = (char*)info->pszzPreviousNames;
784         if (ptr != NULL) {
785                 while (*ptr != '\0') {
786                         printf("\tPrevious Names\t= %s\n", ptr);
787                         for (;*ptr != '\0'; ptr++)
788                                 /* printf("%s\n", ptr); */
789                                 ;
790                         ptr++;
791                 }
792         } else {
793                 printf("\tPrevious Names\t= (null)\n");
794         }
795
796         printf("\tDriver Date\t= %d\n",         info->ftDriverDate);
797         printf("\tDriver Version\t= %d\n",      info->dwlDriverVersion);
798         printf("\tManufacture Name = %s\n",     info->pszMfgName);
799         printf("\tOEM URL\t\t= %s\n",           info->pszOEMUrl);
800         printf("\tHardware ID\t= %s\n",         info->pszHardwareID);
801         printf("\tProvider\t= %s\n",            info->pszProvider);
802         return;
803 }
804
805 static void print_multi_sz(LPSTR multisz)
806 {
807         char *ptr = NULL;
808
809         ptr = (char *)multisz;
810
811         if (!ptr) {
812                 printf("(null)\n");
813                 return;
814         }
815
816         while (*ptr != '\0') {
817                 printf("%s\n", ptr);
818                 for (; *ptr != '\0'; ptr++) {
819                         /* printf("%s\n", ptr); */
820                         ;
821                 }
822                 ptr++;
823         }
824 }
825
826 void print_driver_info_8(PDRIVER_INFO_8 info)
827 {
828         printf("\tDriver Name\t= %s\n",         info->pName);
829         printf("\tEnvironment\t= %s\n",         info->pEnvironment);
830         printf("\tVersion\t\t= %d\n",           info->cVersion);
831         printf("\tDriver Path\t= %s\n",         info->pDriverPath);
832         printf("\tData File\t= %s\n",           info->pDataFile);
833         printf("\tConfig File\t= %s\n",         info->pConfigFile);
834         printf("\tHelp Path\t= %s\n",           info->pHelpFile);
835         printf("\tMonitor Name\t= %s\n",        info->pMonitorName);
836         printf("\tData Type\t= %s\n",           info->pDefaultDataType);
837         printf("\tPrevious Names\t=\n");
838         print_multi_sz(info->pszzPreviousNames);
839         printf("\tDependent Files\t=\n");
840         print_multi_sz(info->pDependentFiles);
841         printf("\tDriver Date\t= %d\n",         info->ftDriverDate);
842         printf("\tDriver Version\t= %d\n",      info->dwlDriverVersion);
843         printf("\tManufacture Name = %s\n",     info->pszMfgName);
844         printf("\tOEM URL\t\t= %s\n",           info->pszOEMUrl);
845         printf("\tHardware ID\t= %s\n",         info->pszHardwareID);
846         printf("\tProvider\t= %s\n",            info->pszProvider);
847         printf("\tPrint Processor\t= %s\n",     info->pszPrintProcessor);
848         printf("\tVendor Setup\t= %s\n",        info->pszVendorSetup);
849         printf("\tColor Profiles\t=\n");
850         print_multi_sz(info->pszzColorProfiles);
851         printf("\tInf Path\t= %s\n",            info->pszInfPath);
852         printf("\tPrinter Driver Attributes = %d\n", info->dwPrinterDriverAttributes);
853         printf("\tCore Driver Dependencies\t=\n");
854         print_multi_sz(info->pszzCoreDriverDependencies);
855         printf("\tMin Inbox Driver VerDate\t= %d\n", info->ftMinInboxDriverVerDate);
856         printf("\tMin Inbox Driver VerVersion\t= %d\n", info->dwlMinInboxDriverVerVersion);
857         return;
858 }
859
860 void print_driver_info_bylevel(DWORD level, LPBYTE buffer, DWORD count)
861 {
862         DWORD i;
863         PDRIVER_INFO_1  buffer1 = NULL;
864         PDRIVER_INFO_2  buffer2 = NULL;
865         PDRIVER_INFO_3  buffer3 = NULL;
866         PDRIVER_INFO_4  buffer4 = NULL;
867         PDRIVER_INFO_5  buffer5 = NULL;
868         PDRIVER_INFO_6  buffer6 = NULL;
869         PDRIVER_INFO_8  buffer8 = NULL;
870
871         if (!buffer) {
872                 return;
873         }
874
875         switch (level) {
876         case 1:
877                 buffer1 = (PDRIVER_INFO_1)buffer;
878                 break;
879         case 2:
880                 buffer2 = (PDRIVER_INFO_2)buffer;
881                 break;
882         case 3:
883                 buffer3 = (PDRIVER_INFO_3)buffer;
884                 break;
885         case 4:
886                 buffer4 = (PDRIVER_INFO_4)buffer;
887                 break;
888         case 5:
889                 buffer5 = (PDRIVER_INFO_5)buffer;
890                 break;
891         case 6:
892                 buffer6 = (PDRIVER_INFO_6)buffer;
893                 break;
894         case 8:
895                 buffer8 = (PDRIVER_INFO_8)buffer;
896                 break;
897         default:
898                 break;
899         }
900
901         printf("Driver Info Level %d:\n", level);
902
903         switch (level) {
904         case 1:
905                 for (i=0; i<count; i++) {
906                         print_driver_info_1(&buffer1[i]);
907                         printf("\n");
908                 }
909                 break;
910         case 2:
911                 for (i=0; i<count; i++) {
912                         print_driver_info_2(&buffer2[i]);
913                         printf("\n");
914                 }
915                 break;
916         case 3:
917                 for (i=0; i<count; i++) {
918                         print_driver_info_3(&buffer3[i]);
919                         printf("\n");
920                 }
921                 break;
922         case 4:
923                 for (i=0; i<count; i++) {
924                         print_driver_info_4(&buffer4[i]);
925                         printf("\n");
926                 }
927                 break;
928         case 5:
929                 for (i=0; i<count; i++) {
930                         print_driver_info_5(&buffer5[i]);
931                         printf("\n");
932                 }
933                 break;
934         case 6:
935                 for (i=0; i<count; i++) {
936                         print_driver_info_6(&buffer6[i]);
937                         printf("\n");
938                 }
939                 break;
940         case 8:
941                 for (i=0; i<count; i++) {
942                         print_driver_info_8(&buffer8[i]);
943                         printf("\n");
944                 }
945                 break;
946         default:
947                 break;
948         }
949 }
950
951 void print_doc_info_1(PDOC_INFO_1 info)
952 {
953         printf("\tDocument Name\t= %s\n",       info->pDocName);
954         printf("\tOutput Filename\t= %s\n",     info->pOutputFile);
955         printf("\tDatatype\t= %s\n",            info->pDatatype);
956         return;
957 }
958
959 void print_printer_keys(LPSTR buffer)
960 {
961         LPSTR p = NULL;
962
963         p = buffer;
964
965         while (p && *p) {
966                 printf("%s\n", p);
967                 for (; *p; p = CharNext(p)) {
968                         p = CharNext(p);
969                 }
970         }
971 }
972
973 static LPSTR reg_type_str(DWORD type)
974 {
975         switch (type) {
976         case REG_DWORD:
977                 return "REG_DWORD";
978         case REG_SZ:
979                 return "REG_SZ";
980         case REG_MULTI_SZ:
981                 return "REG_MULTI_SZ";
982         case REG_BINARY:
983                 return "REG_BINARY";
984         default:
985                 return NULL;
986         }
987 }
988
989 void print_printer_data(LPSTR keyname, LPSTR valuename, DWORD size, LPBYTE buffer, DWORD type)
990 {
991         DWORD i = 0;
992         LPSTR p = NULL;
993
994         if (keyname) {
995                 printf("\tKey Name:\t%s\n", keyname);
996         }
997
998         printf("\tValue Name:\t%s\n", valuename);
999         printf("\tSize: 0x%x (%d)\n", size, size);
1000         printf("\tType:\t\t%s\n", reg_type_str(type));
1001
1002         switch (type) {
1003         case REG_SZ:
1004                 printf("\t\t%s\n", (LPSTR)buffer);
1005                 break;
1006         case REG_MULTI_SZ:
1007                 p = (LPSTR)buffer;
1008                 while (p && *p) {
1009                         printf("%s\n", p);
1010                         for (; *p; p = CharNext(p)) {
1011                                 p = CharNext(p);
1012                         }
1013                 }
1014                 break;
1015         case REG_DWORD:
1016                 assert(size == 4);
1017                 printf("\t\t0x%08x\n", (DWORD)*buffer);
1018                 break;
1019         case REG_BINARY:
1020                 for (i=0; i < size; i++) {
1021                         printf("\t0x%x", buffer[i]);
1022                         if (i%4 == 3) {
1023                                 printf("\n");
1024                         }
1025                 }
1026                 break;
1027         default:
1028                 break;
1029         }
1030 }
1031
1032 void print_printer_enum_values(PRINTER_ENUM_VALUES *info)
1033 {
1034         print_printer_data(NULL, info->pValueName, info->cbData, info->pData, info->dwType);
1035 }
1036