e696909ed65205ec9e59df7d55d75d62cca8d1e3
[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_driver_info_1(PDRIVER_INFO_1 info)
641 {
642         printf("\tDriver Name\t= %s\n\n",       info->pName);
643
644         return;
645 }
646
647 void print_driver_info_2(PDRIVER_INFO_2 info)
648 {
649         printf("\tDriver Name\t= %s\n",         info->pName);
650         printf("\tEnvironment\t= %s\n",         info->pEnvironment);
651         printf("\tVersion\t\t= %d\n",           info->cVersion);
652         printf("\tDriver Path\t= %s\n",         info->pDriverPath);
653         printf("\tData File\t= %s\n",           info->pDataFile);
654         printf("\tConfig File\t= %s\n\n",       info->pConfigFile);
655
656         return;
657 }
658
659 void print_driver_info_3(PDRIVER_INFO_3 info)
660 {
661         char *ptr = NULL;
662
663         printf("\tDriver Name\t= %s\n",         info->pName);
664         printf("\tEnvironment\t= %s\n",         info->pEnvironment);
665         printf("\tVersion\t\t= %d\n",           info->cVersion);
666         printf("\tDriver Path\t= %s\n",         info->pDriverPath);
667         printf("\tData File\t= %s\n",           info->pDataFile);
668         printf("\tConfig File\t= %s\n",         info->pConfigFile);
669         printf("\tHelp Path\t= %s\n",           info->pHelpFile);
670         printf("\tMonitor Name\t= %s\n",        info->pMonitorName);
671         printf("\tData Type\t= %s\n",           info->pDefaultDataType);
672         ptr = (char*)info->pDependentFiles;
673         while ((ptr != NULL) && (*ptr != '\0')) {
674                 printf("\tDependent Files\t= %s\n", ptr);
675                 for (;*ptr != '\0'; ptr++)
676                         /* printf("%s\n", ptr); */
677                         ;
678                 ptr++;
679         }
680
681         return;
682 }
683
684 void print_driver_info_4(PDRIVER_INFO_4 info)
685 {
686         char *ptr = NULL;
687
688         printf("\tDriver Name\t= %s\n",         info->pName);
689         printf("\tEnvironment\t= %s\n",         info->pEnvironment);
690         printf("\tVersion\t\t= %d\n",           info->cVersion);
691         printf("\tDriver Path\t= %s\n",         info->pDriverPath);
692         printf("\tData File\t= %s\n",           info->pDataFile);
693         printf("\tConfig File\t= %s\n",         info->pConfigFile);
694         printf("\tHelp Path\t= %s\n",           info->pHelpFile);
695         printf("\tMonitor Name\t= %s\n",        info->pMonitorName);
696         printf("\tData Type\t= %s\n",           info->pDefaultDataType);
697         printf("\tPrevious Names\t= %s\n",      info->pszzPreviousNames);
698         ptr = (char*)info->pDependentFiles;
699         while ((ptr != NULL) && (*ptr != '\0')) {
700                 printf("\tDependent Files\t= %s\n", ptr);
701                 for (;*ptr != '\0'; ptr++)
702                         /* printf("%s\n", ptr); */
703                         ;
704                 ptr++;
705         }
706
707         return;
708 }
709
710 void print_driver_info_5(PDRIVER_INFO_5 info)
711 {
712         printf("\tDriver Name\t= %s\n",         info->pName);
713         printf("\tEnvironment\t= %s\n",         info->pEnvironment);
714         printf("\tVersion\t\t= %d\n",           info->cVersion);
715         printf("\tDriver Path\t= %s\n",         info->pDriverPath);
716         printf("\tData File\t= %s\n",           info->pDataFile);
717         printf("\tConfig File\t= %s\n",         info->pConfigFile);
718         printf("\tDriver Attributes\t= %d\n",   info->dwDriverAttributes);
719         printf("\tConfig Version\t= %d\n",      info->dwConfigVersion);
720         printf("\tDriver Version\t= %d\n",      info->dwDriverVersion);
721
722         return;
723 }
724
725 void print_driver_info_6(PDRIVER_INFO_6 info)
726 {
727         char *ptr = NULL;
728
729         printf("\tDriver Name\t= %s\n",         info->pName);
730         printf("\tEnvironment\t= %s\n",         info->pEnvironment);
731         printf("\tVersion\t\t= %d\n",           info->cVersion);
732         printf("\tDriver Path\t= %s\n",         info->pDriverPath);
733         printf("\tData File\t= %s\n",           info->pDataFile);
734         printf("\tConfig File\t= %s\n",         info->pConfigFile);
735         printf("\tHelp Path\t= %s\n",           info->pHelpFile);
736         printf("\tMonitor Name\t= %s\n",        info->pMonitorName);
737         printf("\tData Type\t= %s\n",           info->pDefaultDataType);
738         printf("\tPrevious Names\t= %s\n",      info->pszzPreviousNames);
739         ptr = (char*)info->pDependentFiles;
740         if (ptr != NULL) {
741                 while (*ptr != '\0') {
742                         printf("\tDependent Files\t= %s\n", ptr);
743                         for (;*ptr != '\0'; ptr++)
744                                 /* printf("%s\n", ptr); */
745                                 ;
746                         ptr++;
747                 }
748         } else {
749                 printf("\tPrevious Names\t= (null)\n");
750         }
751
752         ptr = (char*)info->pszzPreviousNames;
753         if (ptr != NULL) {
754                 while (*ptr != '\0') {
755                         printf("\tPrevious Names\t= %s\n", ptr);
756                         for (;*ptr != '\0'; ptr++)
757                                 /* printf("%s\n", ptr); */
758                                 ;
759                         ptr++;
760                 }
761         } else {
762                 printf("\tPrevious Names\t= (null)\n");
763         }
764
765         printf("\tDriver Date\t= %d\n",         info->ftDriverDate);
766         printf("\tDriver Version\t= %d\n",      info->dwlDriverVersion);
767         printf("\tManufacture Name = %s\n",     info->pszMfgName);
768         printf("\tOEM URL\t\t= %s\n",           info->pszOEMUrl);
769         printf("\tHardware ID\t= %s\n",         info->pszHardwareID);
770         printf("\tProvider\t= %s\n",            info->pszProvider);
771         return;
772 }
773
774 static void print_multi_sz(LPSTR multisz)
775 {
776         char *ptr = NULL;
777
778         ptr = (char *)multisz;
779
780         if (!ptr) {
781                 printf("(null)\n");
782                 return;
783         }
784
785         while (*ptr != '\0') {
786                 printf("%s\n", ptr);
787                 for (; *ptr != '\0'; ptr++) {
788                         /* printf("%s\n", ptr); */
789                         ;
790                 }
791                 ptr++;
792         }
793 }
794
795 void print_driver_info_8(PDRIVER_INFO_8 info)
796 {
797         printf("\tDriver Name\t= %s\n",         info->pName);
798         printf("\tEnvironment\t= %s\n",         info->pEnvironment);
799         printf("\tVersion\t\t= %d\n",           info->cVersion);
800         printf("\tDriver Path\t= %s\n",         info->pDriverPath);
801         printf("\tData File\t= %s\n",           info->pDataFile);
802         printf("\tConfig File\t= %s\n",         info->pConfigFile);
803         printf("\tHelp Path\t= %s\n",           info->pHelpFile);
804         printf("\tMonitor Name\t= %s\n",        info->pMonitorName);
805         printf("\tData Type\t= %s\n",           info->pDefaultDataType);
806         printf("\tPrevious Names\t=\n");
807         print_multi_sz(info->pszzPreviousNames);
808         printf("\tDependent Files\t=\n");
809         print_multi_sz(info->pDependentFiles);
810         printf("\tDriver Date\t= %d\n",         info->ftDriverDate);
811         printf("\tDriver Version\t= %d\n",      info->dwlDriverVersion);
812         printf("\tManufacture Name = %s\n",     info->pszMfgName);
813         printf("\tOEM URL\t\t= %s\n",           info->pszOEMUrl);
814         printf("\tHardware ID\t= %s\n",         info->pszHardwareID);
815         printf("\tProvider\t= %s\n",            info->pszProvider);
816         printf("\tPrint Processor\t= %s\n",     info->pszPrintProcessor);
817         printf("\tVendor Setup\t= %s\n",        info->pszVendorSetup);
818         printf("\tColor Profiles\t=\n");
819         print_multi_sz(info->pszzColorProfiles);
820         printf("\tInf Path\t= %s\n",            info->pszInfPath);
821         printf("\tPrinter Driver Attributes = %d\n", info->dwPrinterDriverAttributes);
822         printf("\tCore Driver Dependencies\t=\n");
823         print_multi_sz(info->pszzCoreDriverDependencies);
824         printf("\tMin Inbox Driver VerDate\t= %d\n", info->ftMinInboxDriverVerDate);
825         printf("\tMin Inbox Driver VerVersion\t= %d\n", info->dwlMinInboxDriverVerVersion);
826         return;
827 }
828
829 void print_driver_info_bylevel(DWORD level, LPBYTE buffer, DWORD count)
830 {
831         DWORD i;
832         PDRIVER_INFO_1  buffer1 = NULL;
833         PDRIVER_INFO_2  buffer2 = NULL;
834         PDRIVER_INFO_3  buffer3 = NULL;
835         PDRIVER_INFO_4  buffer4 = NULL;
836         PDRIVER_INFO_5  buffer5 = NULL;
837         PDRIVER_INFO_6  buffer6 = NULL;
838         PDRIVER_INFO_8  buffer8 = NULL;
839
840         if (!buffer) {
841                 return;
842         }
843
844         switch (level) {
845         case 1:
846                 buffer1 = (PDRIVER_INFO_1)buffer;
847                 break;
848         case 2:
849                 buffer2 = (PDRIVER_INFO_2)buffer;
850                 break;
851         case 3:
852                 buffer3 = (PDRIVER_INFO_3)buffer;
853                 break;
854         case 4:
855                 buffer4 = (PDRIVER_INFO_4)buffer;
856                 break;
857         case 5:
858                 buffer5 = (PDRIVER_INFO_5)buffer;
859                 break;
860         case 6:
861                 buffer6 = (PDRIVER_INFO_6)buffer;
862                 break;
863         case 8:
864                 buffer8 = (PDRIVER_INFO_8)buffer;
865                 break;
866         default:
867                 break;
868         }
869
870         printf("Driver Info Level %d:\n", level);
871
872         switch (level) {
873         case 1:
874                 for (i=0; i<count; i++) {
875                         print_driver_info_1(&buffer1[i]);
876                         printf("\n");
877                 }
878                 break;
879         case 2:
880                 for (i=0; i<count; i++) {
881                         print_driver_info_2(&buffer2[i]);
882                         printf("\n");
883                 }
884                 break;
885         case 3:
886                 for (i=0; i<count; i++) {
887                         print_driver_info_3(&buffer3[i]);
888                         printf("\n");
889                 }
890                 break;
891         case 4:
892                 for (i=0; i<count; i++) {
893                         print_driver_info_4(&buffer4[i]);
894                         printf("\n");
895                 }
896                 break;
897         case 5:
898                 for (i=0; i<count; i++) {
899                         print_driver_info_5(&buffer5[i]);
900                         printf("\n");
901                 }
902                 break;
903         case 6:
904                 for (i=0; i<count; i++) {
905                         print_driver_info_6(&buffer6[i]);
906                         printf("\n");
907                 }
908                 break;
909         case 8:
910                 for (i=0; i<count; i++) {
911                         print_driver_info_8(&buffer8[i]);
912                         printf("\n");
913                 }
914                 break;
915         default:
916                 break;
917         }
918 }
919
920 void print_doc_info_1(PDOC_INFO_1 info)
921 {
922         printf("\tDocument Name\t= %s\n",       info->pDocName);
923         printf("\tOutput Filename\t= %s\n",     info->pOutputFile);
924         printf("\tDatatype\t= %s\n",            info->pDatatype);
925         return;
926 }
927
928 void print_printer_keys(LPSTR buffer)
929 {
930         LPSTR p = NULL;
931
932         p = buffer;
933
934         while (p && *p) {
935                 printf("%s\n", p);
936                 for (; *p; p = CharNext(p)) {
937                         p = CharNext(p);
938                 }
939         }
940 }
941
942 static LPSTR reg_type_str(DWORD type)
943 {
944         switch (type) {
945         case REG_DWORD:
946                 return "REG_DWORD";
947         case REG_SZ:
948                 return "REG_SZ";
949         case REG_MULTI_SZ:
950                 return "REG_MULTI_SZ";
951         case REG_BINARY:
952                 return "REG_BINARY";
953         default:
954                 return NULL;
955         }
956 }
957
958 void print_printer_data(LPSTR keyname, LPSTR valuename, DWORD size, LPBYTE buffer, DWORD type)
959 {
960         DWORD i = 0;
961         LPSTR p = NULL;
962
963         if (keyname) {
964                 printf("\tKey Name:\t%s\n", keyname);
965         }
966
967         printf("\tValue Name:\t%s\n", valuename);
968         printf("\tSize: 0x%x (%d)\n", size, size);
969         printf("\tType:\t\t%s\n", reg_type_str(type));
970
971         switch (type) {
972         case REG_SZ:
973                 printf("\t\t%s\n", (LPSTR)buffer);
974                 break;
975         case REG_MULTI_SZ:
976                 p = (LPSTR)buffer;
977                 while (p && *p) {
978                         printf("%s\n", p);
979                         for (; *p; p = CharNext(p)) {
980                                 p = CharNext(p);
981                         }
982                 }
983                 break;
984         case REG_DWORD:
985                 assert(size == 4);
986                 printf("\t\t0x%08x\n", (DWORD)*buffer);
987                 break;
988         case REG_BINARY:
989                 for (i=0; i < size; i++) {
990                         printf("\t0x%x", buffer[i]);
991                         if (i%4 == 3) {
992                                 printf("\n");
993                         }
994                 }
995                 break;
996         default:
997                 break;
998         }
999 }
1000
1001 void print_printer_enum_values(PRINTER_ENUM_VALUES *info)
1002 {
1003         print_printer_data(NULL, info->pValueName, info->cbData, info->pData, info->dwType);
1004 }
1005