--- dlls/winspool.drv/info.c | 95 +++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 93 insertions(+), 2 deletions(-) diff --git a/dlls/winspool.drv/info.c b/dlls/winspool.drv/info.c index e4a464a..f16914a 100644 --- a/dlls/winspool.drv/info.c +++ b/dlls/winspool.drv/info.c @@ -5962,8 +5962,99 @@ DWORD WINAPI EnumPrinterDataExA(HANDLE hPrinter, LPCSTR pKeyName, */ BOOL WINAPI AbortPrinter( HANDLE hPrinter ) { - FIXME("(%p), stub!\n", hPrinter); - return TRUE; + PRINTER_INFO_2W *pi2 = NULL; + BOOL ret = FALSE; + BOOL retFromGetPrinter = FALSE; + opened_printer_t *printer; + job_t *job, *next_job; + DWORD jobDocId; + DWORD needed; + LPWSTR portname; + + TRACE("(%p)\n", hPrinter); + + EnterCriticalSection(&printer_handles_cs); + + printer = get_opened_printer(hPrinter); + if(!printer) + { + ERR("The handle for the printer is invalid.\n"); + SetLastError(ERROR_INVALID_HANDLE); + goto end; + } + + if(printer->doc) + { + TRACE("Document inside for job id : %d\n", printer->doc->job_id); + jobDocId = printer->doc->job_id; + } + else + { + ERR("No document.\n"); + SetLastError(ERROR_SPL_NO_STARTDOC); + goto end; + } + + /* For each jobs, see if we have a job document in the double linked list */ + LIST_FOR_EACH_ENTRY_SAFE(job, next_job, &printer->queue->jobs, job_t, entry) + { + TRACE("(job id : %d, filename : %s, portname : %s, document title : %s, printer name %s)\n" + , job->job_id, debugstr_w(job->filename), debugstr_w(job->portname) + , debugstr_w(job->document_title), debugstr_w(job->printer_name)); + + if(jobDocId == job->job_id) + { + TRACE("(hf : %p, job id : %d)\n", printer->doc->hf, printer->doc->job_id); + + /* Get portname. */ + if(!job->portname) + { + GetPrinterW(hPrinter, 2, NULL, 0, &needed); + if(GetLastError() != ERROR_INSUFFICIENT_BUFFER) + goto end; + + pi2 = HeapAlloc(GetProcessHeap(), 0, needed); + if(!pi2) + goto end; + + retFromGetPrinter = GetPrinterW(hPrinter, 2, (LPBYTE)pi2, needed, &needed); + if(!retFromGetPrinter) + goto end; + + portname = pi2->pPortName; + } + + TRACE("portname : %s\n", debugstr_w(portname)); + + /* Cups Port */ + if(!strncmpW(portname, CUPS_Port, strlenW(CUPS_Port))) + { + TRACE("Remove job from the list.\n"); + list_remove(&job->entry); + CloseHandle(printer->doc->hf); + DeleteFileW(job->filename); + HeapFree(GetProcessHeap(), 0, job->document_title); + HeapFree(GetProcessHeap(), 0, job->printer_name); + HeapFree(GetProcessHeap(), 0, job->portname); + HeapFree(GetProcessHeap(), 0, job->filename); + HeapFree(GetProcessHeap(), 0, job->devmode); + HeapFree(GetProcessHeap(), 0, job); + + /* The document for the printer is not useful anymore. */ + TRACE("Remove document for the printer : %s.\n", debugstr_w(printer->printername)); + HeapFree(GetProcessHeap(), 0, printer->doc); + printer->doc = 0; + ret = TRUE; + goto end; + } + else + FIXME("AbortPrinter() manage only CUPS for now.\n"); + } + } +end: + HeapFree(GetProcessHeap(), 0, pi2); + LeaveCriticalSection(&printer_handles_cs); + return ret; } /****************************************************************************** -- 1.7.3.2