testprogs: print port info levels in EnumPorts() spoolss tests.
[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_port_info_1(PPORT_INFO_1 info)
268 {
269         printf("\tPort Name\t= %s\n",   info->pName);
270         return;
271 }
272
273 void print_port_info_2(PPORT_INFO_2 info)
274 {
275         printf("\tPort Name\t= %s\n",   info->pPortName);
276         printf("\tMonitor Name\t= %s\n",info->pMonitorName);
277         printf("\tDescription\t= %s\n", info->pDescription);
278         printf("\tPort Type\t= 0x%08x\n", info->fPortType);
279         printf("\tReserved\t= 0x%08x\n", info->Reserved);
280         return;
281 }
282
283 void print_port_info_3(PPORT_INFO_3 info)
284 {
285         printf("\tStatus\t= 0x%08x\n", info->dwStatus);
286         printf("\tStatus String\t= %s\n", info->pszStatus);
287         printf("\tSeverity\t= 0x%08x\n", info->dwSeverity);
288         return;
289 }
290
291 void print_port_info_bylevel(DWORD level, LPBYTE buffer, DWORD count)
292 {
293         DWORD i;
294         PPORT_INFO_1 buffer1 = NULL;
295         PPORT_INFO_2 buffer2 = NULL;
296         PPORT_INFO_3 buffer3 = NULL;
297
298         if (!buffer) {
299                 return;
300         }
301
302         switch (level) {
303         case 1:
304                 buffer1 = (PPORT_INFO_1)buffer;
305                 break;
306         case 2:
307                 buffer2 = (PPORT_INFO_2)buffer;
308                 break;
309         case 3:
310                 buffer3 = (PPORT_INFO_3)buffer;
311                 break;
312         default:
313                 break;
314         }
315
316         printf("Port Info Level %d:\n", level);
317
318         switch (level) {
319         case 1:
320                 for (i=0; i<count; i++) {
321                         print_port_info_1(&buffer1[i]);
322                         printf("\n");
323                 }
324                 break;
325         case 2:
326                 for (i=0; i<count; i++) {
327                         print_port_info_2(&buffer2[i]);
328                         printf("\n");
329                 }
330                 break;
331         case 3:
332                 for (i=0; i<count; i++) {
333                         print_port_info_3(&buffer3[i]);
334                         printf("\n");
335                 }
336                 break;
337         default:
338                 break;
339         }
340 }
341
342 void print_form_info_1(PFORM_INFO_1 info)
343 {
344         printf("\tForm Name\t= %s\n",   info->pName);
345         printf("\tFlags\t\t= 0x%x\n",   info->Flags);
346         printf("\tSize\t\t= %d x %d\n", info->Size.cx, info->Size.cy);
347         printf("\tRectangle\t= [left]%d [right]%d [top]%d [bottom]%d\n",
348                         info->ImageableArea.left, info->ImageableArea.right,
349                         info->ImageableArea.top, info->ImageableArea.bottom);
350
351         return;
352 }
353
354 void print_form_info_2(PFORM_INFO_2 info)
355 {
356         printf("\tForm Name\t= %s\n",   info->pName);
357         printf("\tFlags\t\t= 0x%x\n",   info->Flags);
358         printf("\tSize\t\t= %d x %d\n", info->Size.cx, info->Size.cy);
359         printf("\tRectangle\t= [left]%d [right]%d [top]%d [bottom]%d\n",
360                         info->ImageableArea.left, info->ImageableArea.right,
361                         info->ImageableArea.top, info->ImageableArea.bottom);
362         printf("\tKeyword\t= %s\n",     info->pKeyword);
363         printf("\tString Type\t= 0x%08x\n", info->StringType);
364         printf("\tMui DLL\t= %s\n",     info->pMuiDll);
365         printf("\tResource Id\t= 0x%08x\n", info->dwResourceId);
366         printf("\tDisplay Name\t= %s\n",info->pDisplayName);
367         printf("\tLang Id\t= 0x%04x\n", info->wLangId);
368
369         return;
370 }
371
372 void print_form_info_bylevel(DWORD level, LPBYTE buffer, DWORD count)
373 {
374         DWORD i;
375         PFORM_INFO_1 buffer1 = NULL;
376         PFORM_INFO_2 buffer2 = NULL;
377
378         if (!buffer) {
379                 return;
380         }
381
382         switch (level) {
383         case 1:
384                 buffer1 = (PFORM_INFO_1)buffer;
385                 break;
386         case 2:
387                 buffer2 = (PFORM_INFO_2)buffer;
388                 break;
389         default:
390                 break;
391         }
392
393         printf("Form Info Level %d:\n", level);
394
395         switch (level) {
396         case 1:
397                 for (i=0; i<count; i++) {
398                         print_form_info_1(&buffer1[i]);
399                         printf("\n");
400                 }
401                 break;
402         case 2:
403                 for (i=0; i<count; i++) {
404                         print_form_info_2(&buffer2[i]);
405                         printf("\n");
406                 }
407                 break;
408         default:
409                 break;
410         }
411 }
412
413 void print_printer_info_1(PPRINTER_INFO_1 info)
414 {
415         printf("\tPrinter Name\t= %s\n",        info->pName);
416         printf("\tDescription\t= %s\n",         info->pDescription);
417         printf("\tComment\t\t= %s\n",           info->pComment);
418         printf("\tFlags\t\t= 0x%x\n",           info->Flags);
419
420         return;
421 }
422
423 void print_printer_info_2(PPRINTER_INFO_2 info)
424 {
425         printf("\tServer Name\t\t= %s\n",       info->pServerName);
426         printf("\tPrinter Name\t\t= %s\n",      info->pPrinterName);
427         printf("\tPort Name\t\t= %s\n",         info->pPortName);
428         printf("\tShare Name\t\t= %s\n",        info->pShareName);
429         printf("\tDriver Name\t\t= %s\n",       info->pDriverName);
430         printf("\tComment\t\t\t= %s\n",         info->pComment);
431         printf("\tLocation\t\t= %s\n",          info->pLocation);
432         printf("\tSeparator File\t\t= %s\n",    info->pSepFile);
433         printf("\tDefault Data Type\t= %s\n",   info->pDatatype);
434         printf("\tPrint Processor\t\t= %s\n",   info->pPrintProcessor);
435         printf("\tParameters\t\t= %s\n",        info->pParameters);
436         printf("\tAttributes\t\t= 0x%x\n",      info->Attributes);
437         printf("\tPriority\t\t= 0x%x\n",        info->Priority);
438         printf("\tDefault Priority\t= 0x%x\n",  info->DefaultPriority);
439         printf("\tStart Time\t\t= 0x%x\n",      info->StartTime);
440         printf("\tUntil Time\t\t= 0x%x\n",      info->UntilTime);
441         printf("\tStatus\t\t\t= 0x%x\n",        info->Status);
442         printf("\tcJobs\t\t\t= 0x%x\n",         info->cJobs);
443         printf("\tAverage PPM\t\t= 0x%x\n",     info->AveragePPM);
444
445         printf("\tDevice Mode Information\n");
446         printf("\t-----------------------\n");
447         print_devmode(info->pDevMode);
448 #if 0
449         printf("\tSecurity Descriptor Information\n");
450         printf("\t-------------------------------\n");
451         print_secdesc(info->pSecurityDescriptor);
452 #endif
453         return;
454 }
455
456 void print_printer_info_5(PPRINTER_INFO_5 info)
457 {
458         printf("\tPrinter Name\t\t\t= %s\n",            info->pPrinterName);
459         printf("\tPort Name\t\t\t= %s\n",               info->pPortName);
460         printf("\tAttributes\t\t\t= 0x%x\n",            info->Attributes);
461         printf("\tDev NotSelect Timeout\t= 0x%x\n",     info->DeviceNotSelectedTimeout);
462         printf("\tTX RetryTimeout\t\t= 0x%x\n",         info->TransmissionRetryTimeout);
463         return;
464 }
465
466 void print_printer_info_6(PPRINTER_INFO_6 info)
467 {
468         printf("\tStatus\t\t\t= 0x%x\n",                info->dwStatus);
469         return;
470 }
471
472 void print_printer_info_7(PPRINTER_INFO_7 info)
473 {
474         printf("\tObject GUID\t\t\t= %s\n",             info->pszObjectGUID);
475         printf("\tAction\t\t\t= 0x%x\n",                info->dwAction);
476         return;
477 }
478
479 void print_printer_info_8(PPRINTER_INFO_8 info)
480 {
481         print_devmode(info->pDevMode);
482 }
483
484 void print_printer_info_9(PPRINTER_INFO_9 info)
485 {
486         print_devmode(info->pDevMode);
487 }
488
489 void print_printer_info_bylevel(DWORD level, LPBYTE buffer, DWORD count)
490 {
491         DWORD i;
492         PPRINTER_INFO_1 buffer1 = NULL;
493         PPRINTER_INFO_2 buffer2 = NULL;
494         PPRINTER_INFO_3 buffer3 = NULL;
495         PPRINTER_INFO_4 buffer4 = NULL;
496         PPRINTER_INFO_5 buffer5 = NULL;
497         PPRINTER_INFO_6 buffer6 = NULL;
498         PPRINTER_INFO_7 buffer7 = NULL;
499         PPRINTER_INFO_8 buffer8 = NULL;
500
501         if (!buffer) {
502                 return;
503         }
504
505         switch (level) {
506         case 1:
507                 buffer1 = (PPRINTER_INFO_1)buffer;
508                 break;
509         case 2:
510                 buffer2 = (PPRINTER_INFO_2)buffer;
511                 break;
512         case 3:
513                 buffer3 = (PPRINTER_INFO_3)buffer;
514                 break;
515         case 4:
516                 buffer4 = (PPRINTER_INFO_4)buffer;
517                 break;
518         case 5:
519                 buffer5 = (PPRINTER_INFO_5)buffer;
520                 break;
521         case 6:
522                 buffer6 = (PPRINTER_INFO_6)buffer;
523                 break;
524         case 7:
525                 buffer7 = (PPRINTER_INFO_7)buffer;
526                 break;
527         case 8:
528                 buffer8 = (PPRINTER_INFO_8)buffer;
529                 break;
530         default:
531                 break;
532         }
533
534         printf("Printer Info Level %d:\n", level);
535
536         switch (level) {
537         case 1:
538                 for (i=0; i<count; i++) {
539                         print_printer_info_1(&buffer1[i]);
540                         printf("\n");
541                 }
542                 break;
543         case 2:
544                 for (i=0; i<count; i++) {
545                         print_printer_info_2(&buffer2[i]);
546                         printf("\n");
547                 }
548                 break;
549 #if 0
550         case 3:
551                 for (i=0; i<count; i++) {
552                         print_printer_info_3(&buffer3[i]);
553                         printf("\n");
554                 }
555                 break;
556         case 4:
557                 for (i=0; i<count; i++) {
558                         print_printer_info_4(&buffer4[i]);
559                         printf("\n");
560                 }
561                 break;
562 #endif
563         case 5:
564                 for (i=0; i<count; i++) {
565                         print_printer_info_5(&buffer5[i]);
566                         printf("\n");
567                 }
568                 break;
569         case 6:
570                 for (i=0; i<count; i++) {
571                         print_printer_info_6(&buffer6[i]);
572                         printf("\n");
573                 }
574                 break;
575         case 7:
576                 for (i=0; i<count; i++) {
577                         print_printer_info_7(&buffer7[i]);
578                         printf("\n");
579                 }
580                 break;
581         case 8:
582                 for (i=0; i<count; i++) {
583                         print_printer_info_8(&buffer8[i]);
584                         printf("\n");
585                 }
586                 break;
587         default:
588                 break;
589         }
590 }
591
592 void print_printprocessor_info_1(PPRINTPROCESSOR_INFO_1 info)
593 {
594         printf("\tPrint Processor Name\t= %s\n", info->pName);
595
596         return;
597 }
598
599 void print_driver_info_1(PDRIVER_INFO_1 info)
600 {
601         printf("\tDriver Name\t= %s\n\n",       info->pName);
602
603         return;
604 }
605
606 void print_driver_info_2(PDRIVER_INFO_2 info)
607 {
608         printf("\tDriver Name\t= %s\n",         info->pName);
609         printf("\tEnvironment\t= %s\n",         info->pEnvironment);
610         printf("\tVersion\t\t= %d\n",           info->cVersion);
611         printf("\tDriver Path\t= %s\n",         info->pDriverPath);
612         printf("\tData File\t= %s\n",           info->pDataFile);
613         printf("\tConfig File\t= %s\n\n",       info->pConfigFile);
614
615         return;
616 }
617
618 void print_driver_info_3(PDRIVER_INFO_3 info)
619 {
620         char *ptr = NULL;
621
622         printf("\tDriver Name\t= %s\n",         info->pName);
623         printf("\tEnvironment\t= %s\n",         info->pEnvironment);
624         printf("\tVersion\t\t= %d\n",           info->cVersion);
625         printf("\tDriver Path\t= %s\n",         info->pDriverPath);
626         printf("\tData File\t= %s\n",           info->pDataFile);
627         printf("\tConfig File\t= %s\n",         info->pConfigFile);
628         printf("\tHelp Path\t= %s\n",           info->pHelpFile);
629         printf("\tMonitor Name\t= %s\n",        info->pMonitorName);
630         printf("\tData Type\t= %s\n",           info->pDefaultDataType);
631         ptr = (char*)info->pDependentFiles;
632         while ((ptr != NULL) && (*ptr != '\0')) {
633                 printf("\tDependent Files\t= %s\n", ptr);
634                 for (;*ptr != '\0'; ptr++)
635                         /* printf("%s\n", ptr); */
636                         ;
637                 ptr++;
638         }
639
640         return;
641 }
642
643 void print_driver_info_4(PDRIVER_INFO_4 info)
644 {
645         char *ptr = NULL;
646
647         printf("\tDriver Name\t= %s\n",         info->pName);
648         printf("\tEnvironment\t= %s\n",         info->pEnvironment);
649         printf("\tVersion\t\t= %d\n",           info->cVersion);
650         printf("\tDriver Path\t= %s\n",         info->pDriverPath);
651         printf("\tData File\t= %s\n",           info->pDataFile);
652         printf("\tConfig File\t= %s\n",         info->pConfigFile);
653         printf("\tHelp Path\t= %s\n",           info->pHelpFile);
654         printf("\tMonitor Name\t= %s\n",        info->pMonitorName);
655         printf("\tData Type\t= %s\n",           info->pDefaultDataType);
656         printf("\tPrevious Names\t= %s\n",      info->pszzPreviousNames);
657         ptr = (char*)info->pDependentFiles;
658         while ((ptr != NULL) && (*ptr != '\0')) {
659                 printf("\tDependent Files\t= %s\n", ptr);
660                 for (;*ptr != '\0'; ptr++)
661                         /* printf("%s\n", ptr); */
662                         ;
663                 ptr++;
664         }
665
666         return;
667 }
668
669 void print_driver_info_5(PDRIVER_INFO_5 info)
670 {
671         printf("\tDriver Name\t= %s\n",         info->pName);
672         printf("\tEnvironment\t= %s\n",         info->pEnvironment);
673         printf("\tVersion\t\t= %d\n",           info->cVersion);
674         printf("\tDriver Path\t= %s\n",         info->pDriverPath);
675         printf("\tData File\t= %s\n",           info->pDataFile);
676         printf("\tConfig File\t= %s\n",         info->pConfigFile);
677         printf("\tDriver Attributes\t= %d\n",   info->dwDriverAttributes);
678         printf("\tConfig Version\t= %d\n",      info->dwConfigVersion);
679         printf("\tDriver Version\t= %d\n",      info->dwDriverVersion);
680
681         return;
682 }
683
684 void print_driver_info_6(PDRIVER_INFO_6 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         if (ptr != NULL) {
700                 while (*ptr != '\0') {
701                         printf("\tDependent Files\t= %s\n", ptr);
702                         for (;*ptr != '\0'; ptr++)
703                                 /* printf("%s\n", ptr); */
704                                 ;
705                         ptr++;
706                 }
707         } else {
708                 printf("\tPrevious Names\t= (null)\n");
709         }
710
711         ptr = (char*)info->pszzPreviousNames;
712         if (ptr != NULL) {
713                 while (*ptr != '\0') {
714                         printf("\tPrevious Names\t= %s\n", ptr);
715                         for (;*ptr != '\0'; ptr++)
716                                 /* printf("%s\n", ptr); */
717                                 ;
718                         ptr++;
719                 }
720         } else {
721                 printf("\tPrevious Names\t= (null)\n");
722         }
723
724         printf("\tDriver Date\t= %d\n",         info->ftDriverDate);
725         printf("\tDriver Version\t= %d\n",      info->dwlDriverVersion);
726         printf("\tManufacture Name = %s\n",     info->pszMfgName);
727         printf("\tOEM URL\t\t= %s\n",           info->pszOEMUrl);
728         printf("\tHardware ID\t= %s\n",         info->pszHardwareID);
729         printf("\tProvider\t= %s\n",            info->pszProvider);
730         return;
731 }
732
733 static void print_multi_sz(LPSTR multisz)
734 {
735         char *ptr = NULL;
736
737         ptr = (char *)multisz;
738
739         if (!ptr) {
740                 printf("(null)\n");
741                 return;
742         }
743
744         while (*ptr != '\0') {
745                 printf("%s\n", ptr);
746                 for (; *ptr != '\0'; ptr++) {
747                         /* printf("%s\n", ptr); */
748                         ;
749                 }
750                 ptr++;
751         }
752 }
753
754 void print_driver_info_8(PDRIVER_INFO_8 info)
755 {
756         printf("\tDriver Name\t= %s\n",         info->pName);
757         printf("\tEnvironment\t= %s\n",         info->pEnvironment);
758         printf("\tVersion\t\t= %d\n",           info->cVersion);
759         printf("\tDriver Path\t= %s\n",         info->pDriverPath);
760         printf("\tData File\t= %s\n",           info->pDataFile);
761         printf("\tConfig File\t= %s\n",         info->pConfigFile);
762         printf("\tHelp Path\t= %s\n",           info->pHelpFile);
763         printf("\tMonitor Name\t= %s\n",        info->pMonitorName);
764         printf("\tData Type\t= %s\n",           info->pDefaultDataType);
765         printf("\tPrevious Names\t=\n");
766         print_multi_sz(info->pszzPreviousNames);
767         printf("\tDependent Files\t=\n");
768         print_multi_sz(info->pDependentFiles);
769         printf("\tDriver Date\t= %d\n",         info->ftDriverDate);
770         printf("\tDriver Version\t= %d\n",      info->dwlDriverVersion);
771         printf("\tManufacture Name = %s\n",     info->pszMfgName);
772         printf("\tOEM URL\t\t= %s\n",           info->pszOEMUrl);
773         printf("\tHardware ID\t= %s\n",         info->pszHardwareID);
774         printf("\tProvider\t= %s\n",            info->pszProvider);
775         printf("\tPrint Processor\t= %s\n",     info->pszPrintProcessor);
776         printf("\tVendor Setup\t= %s\n",        info->pszVendorSetup);
777         printf("\tColor Profiles\t=\n");
778         print_multi_sz(info->pszzColorProfiles);
779         printf("\tInf Path\t= %s\n",            info->pszInfPath);
780         printf("\tPrinter Driver Attributes = %d\n", info->dwPrinterDriverAttributes);
781         printf("\tCore Driver Dependencies\t=\n");
782         print_multi_sz(info->pszzCoreDriverDependencies);
783         printf("\tMin Inbox Driver VerDate\t= %d\n", info->ftMinInboxDriverVerDate);
784         printf("\tMin Inbox Driver VerVersion\t= %d\n", info->dwlMinInboxDriverVerVersion);
785         return;
786 }
787
788 void print_driver_info_bylevel(DWORD level, LPBYTE buffer, DWORD count)
789 {
790         DWORD i;
791         PDRIVER_INFO_1  buffer1 = NULL;
792         PDRIVER_INFO_2  buffer2 = NULL;
793         PDRIVER_INFO_3  buffer3 = NULL;
794         PDRIVER_INFO_4  buffer4 = NULL;
795         PDRIVER_INFO_5  buffer5 = NULL;
796         PDRIVER_INFO_6  buffer6 = NULL;
797         PDRIVER_INFO_8  buffer8 = NULL;
798
799         if (!buffer) {
800                 return;
801         }
802
803         switch (level) {
804         case 1:
805                 buffer1 = (PDRIVER_INFO_1)buffer;
806                 break;
807         case 2:
808                 buffer2 = (PDRIVER_INFO_2)buffer;
809                 break;
810         case 3:
811                 buffer3 = (PDRIVER_INFO_3)buffer;
812                 break;
813         case 4:
814                 buffer4 = (PDRIVER_INFO_4)buffer;
815                 break;
816         case 5:
817                 buffer5 = (PDRIVER_INFO_5)buffer;
818                 break;
819         case 6:
820                 buffer6 = (PDRIVER_INFO_6)buffer;
821                 break;
822         case 8:
823                 buffer8 = (PDRIVER_INFO_8)buffer;
824                 break;
825         default:
826                 break;
827         }
828
829         printf("Driver Info Level %d:\n", level);
830
831         switch (level) {
832         case 1:
833                 for (i=0; i<count; i++) {
834                         print_driver_info_1(&buffer1[i]);
835                         printf("\n");
836                 }
837                 break;
838         case 2:
839                 for (i=0; i<count; i++) {
840                         print_driver_info_2(&buffer2[i]);
841                         printf("\n");
842                 }
843                 break;
844         case 3:
845                 for (i=0; i<count; i++) {
846                         print_driver_info_3(&buffer3[i]);
847                         printf("\n");
848                 }
849                 break;
850         case 4:
851                 for (i=0; i<count; i++) {
852                         print_driver_info_4(&buffer4[i]);
853                         printf("\n");
854                 }
855                 break;
856         case 5:
857                 for (i=0; i<count; i++) {
858                         print_driver_info_5(&buffer5[i]);
859                         printf("\n");
860                 }
861                 break;
862         case 6:
863                 for (i=0; i<count; i++) {
864                         print_driver_info_6(&buffer6[i]);
865                         printf("\n");
866                 }
867                 break;
868         case 8:
869                 for (i=0; i<count; i++) {
870                         print_driver_info_8(&buffer8[i]);
871                         printf("\n");
872                 }
873                 break;
874         default:
875                 break;
876         }
877 }
878
879 void print_doc_info_1(PDOC_INFO_1 info)
880 {
881         printf("\tDocument Name\t= %s\n",       info->pDocName);
882         printf("\tOutput Filename\t= %s\n",     info->pOutputFile);
883         printf("\tDatatype\t= %s\n",            info->pDatatype);
884         return;
885 }
886
887 void print_printer_keys(LPSTR buffer)
888 {
889         LPSTR p = NULL;
890
891         p = buffer;
892
893         while (p && *p) {
894                 printf("%s\n", p);
895                 for (; *p; p = CharNext(p)) {
896                         p = CharNext(p);
897                 }
898         }
899 }
900
901 static LPSTR reg_type_str(DWORD type)
902 {
903         switch (type) {
904         case REG_DWORD:
905                 return "REG_DWORD";
906         case REG_SZ:
907                 return "REG_SZ";
908         case REG_MULTI_SZ:
909                 return "REG_MULTI_SZ";
910         case REG_BINARY:
911                 return "REG_BINARY";
912         default:
913                 return NULL;
914         }
915 }
916
917 void print_printer_data(LPSTR keyname, LPSTR valuename, DWORD size, LPBYTE buffer, DWORD type)
918 {
919         DWORD i = 0;
920         LPSTR p = NULL;
921
922         if (keyname) {
923                 printf("\tKey Name:\t%s\n", keyname);
924         }
925
926         printf("\tValue Name:\t%s\n", valuename);
927         printf("\tSize: 0x%x (%d)\n", size, size);
928         printf("\tType:\t\t%s\n", reg_type_str(type));
929
930         switch (type) {
931         case REG_SZ:
932                 printf("\t\t%s\n", (LPSTR)buffer);
933                 break;
934         case REG_MULTI_SZ:
935                 p = (LPSTR)buffer;
936                 while (p && *p) {
937                         printf("%s\n", p);
938                         for (; *p; p = CharNext(p)) {
939                                 p = CharNext(p);
940                         }
941                 }
942                 break;
943         case REG_DWORD:
944                 assert(size == 4);
945                 printf("\t\t0x%08x\n", (DWORD)*buffer);
946                 break;
947         case REG_BINARY:
948                 for (i=0; i < size; i++) {
949                         printf("\t0x%x", buffer[i]);
950                         if (i%4 == 3) {
951                                 printf("\n");
952                         }
953                 }
954                 break;
955         default:
956                 break;
957         }
958 }
959
960 void print_printer_enum_values(PRINTER_ENUM_VALUES *info)
961 {
962         print_printer_data(NULL, info->pValueName, info->cbData, info->pData, info->dwType);
963 }
964