wineps: Add OpenPrintProcessor implementation.
[wine.git] / dlls / wineps.drv / printproc.c
blob613b8752948be91f2a029df179b8daf30a05058a
1 /*
2 * Print processor implementation.
4 * Copyright 2022 Piotr Caban for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdlib.h>
23 #include <windows.h>
24 #include <winspool.h>
25 #include <ddk/winsplp.h>
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
31 #define PP_MAGIC 0x952173fe
33 struct pp_data
35 DWORD magic;
36 HANDLE hport;
37 WCHAR *doc_name;
38 WCHAR *out_file;
41 static const WCHAR emf_1003[] = L"NT EMF 1.003";
43 static struct pp_data* get_handle_data(HANDLE pp)
45 struct pp_data *ret = (struct pp_data *)pp;
47 if (!ret || ret->magic != PP_MAGIC)
49 SetLastError(ERROR_INVALID_HANDLE);
50 return NULL;
52 return ret;
55 BOOL WINAPI EnumPrintProcessorDatatypesW(WCHAR *server, WCHAR *name, DWORD level,
56 BYTE *datatypes, DWORD size, DWORD *needed, DWORD *no)
58 DATATYPES_INFO_1W *info = (DATATYPES_INFO_1W *)datatypes;
60 TRACE("%s, %s, %ld, %p, %ld, %p, %p\n", debugstr_w(server), debugstr_w(name),
61 level, datatypes, size, needed, no);
63 if (!needed || !no)
65 SetLastError(ERROR_INVALID_PARAMETER);
66 return FALSE;
69 *no = 0;
70 *needed = sizeof(*info) + sizeof(emf_1003);
72 if (level != 1 || (size && !datatypes))
74 SetLastError(ERROR_INVALID_PARAMETER);
75 return FALSE;
78 if (size < *needed)
80 SetLastError(ERROR_INSUFFICIENT_BUFFER);
81 return FALSE;
84 *no = 1;
85 info->pName = (WCHAR*)(info + 1);
86 memcpy(info + 1, emf_1003, sizeof(emf_1003));
87 return TRUE;
90 HANDLE WINAPI OpenPrintProcessor(WCHAR *port, PRINTPROCESSOROPENDATA *open_data)
92 struct pp_data *data;
93 HANDLE hport;
95 TRACE("%s, %p\n", debugstr_w(port), open_data);
97 if (!port || !open_data || !open_data->pDatatype)
99 SetLastError(ERROR_INVALID_PARAMETER);
100 return NULL;
102 if (wcscmp(open_data->pDatatype, emf_1003))
104 SetLastError(ERROR_INVALID_DATATYPE);
105 return NULL;
108 if (!OpenPrinterW(port, &hport, NULL))
109 return NULL;
111 data = LocalAlloc(LMEM_FIXED | LMEM_ZEROINIT, sizeof(*data));
112 if (!data)
113 return NULL;
114 data->magic = PP_MAGIC;
115 data->hport = hport;
116 data->doc_name = wcsdup(open_data->pDocumentName);
117 data->out_file = wcsdup(open_data->pOutputFile);
118 return (HANDLE)data;
121 BOOL WINAPI PrintDocumentOnPrintProcessor(HANDLE pp, WCHAR *doc_name)
123 FIXME("%p, %s\n", pp, debugstr_w(doc_name));
124 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
125 return FALSE;
128 BOOL WINAPI ControlPrintProcessor(HANDLE pp, DWORD cmd)
130 FIXME("%p, %ld\n", pp, cmd);
131 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
132 return FALSE;
135 BOOL WINAPI ClosePrintProcessor(HANDLE pp)
137 struct pp_data *data = get_handle_data(pp);
139 TRACE("%p\n", pp);
141 if (!data)
142 return FALSE;
144 ClosePrinter(data->hport);
145 free(data->doc_name);
146 free(data->out_file);
148 memset(data, 0, sizeof(*data));
149 LocalFree(data);
150 return TRUE;