Hello Mr.Eikum,

Thank you for your reply.

On 08/02/11 18:13, Andrew Eikum wrote:
On 02/08/2011 10:48 AM, Loïc Maury wrote:
First of all set your tab size to 8, and ask your editor to not use tabs
 at all.
I have modified my editor, but I don't know if it 's correct now ?

The indentation looks fine to me now. You've got an extra newline after the "if(printer->doc)" block and before the "else." The formatting on the TRACE statement is still bizarre. Fix the commas and put it on just a couple of lines. No reason for one line and a ton of whitespace for each parameter. See line 1944 for an example.
Ok, it's correct now ?

Otherwise, two little things I noticed.

First, you must also check the return value for HeapAlloc().
Ok

Second, you should be using the LIST_FOR_EACH_ENTRY_SAFE macro, which will eliminate the local cursor and cursor2 variables and make the code a little more simple. (Unless there's something I'm missing?)
Ok, I have modified and removed cursor and cursor2 by job and next_job, and list_remove(cursor) by list_remove(&job->entry).

Almost done, nice work :)
Thank you

Loïc

Andrew

---
 dlls/winspool.drv/info.c |   98 ++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 95 insertions(+), 3 deletions(-)

diff --git a/dlls/winspool.drv/info.c b/dlls/winspool.drv/info.c
index e4a464a..838f464 100644
--- a/dlls/winspool.drv/info.c
+++ b/dlls/winspool.drv/info.c
@@ -5960,10 +5960,102 @@ DWORD WINAPI EnumPrinterDataExA(HANDLE hPrinter, 
LPCSTR pKeyName,
 /******************************************************************************
  *      AbortPrinter (WINSPOOL.@)
  */
-BOOL WINAPI AbortPrinter( HANDLE hPrinter )
+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



Reply via email to