1d72983
--- cups-pk-helper-0.0.4/src/cups.c.job-status	2010-02-23 13:21:27.000000000 +0100
1d72983
+++ cups-pk-helper-0.0.4/src/cups.c	2010-02-23 13:21:27.000000000 +0100
1d72983
@@ -1787,19 +1787,34 @@ cph_cups_job_get_status (CphCups    *cup
1d72983
                          int         job_id,
1d72983
                          const char *user)
1d72983
 {
1d72983
-        CphJobStatus  status = CPH_JOB_STATUS_INVALID;
1d72983
-        cups_job_t   *jobs;
1d72983
-        int           num_jobs;
1d72983
-        int           i;
1d72983
+        const char * const  attrs[1] = { "job-originating-user-name" };
1d72983
+        ipp_t              *request;
1d72983
+        const char         *resource_char;
1d72983
+        ipp_t              *reply;
1d72983
+        ipp_attribute_t    *attr;
1d72983
+        CphJobStatus        status = CPH_JOB_STATUS_INVALID;
1d72983
 
1d72983
         g_return_val_if_fail (CPH_IS_CUPS (cups), CPH_JOB_STATUS_INVALID);
1d72983
 
1d72983
-        num_jobs = cupsGetJobs2 (cups->priv->connection, &jobs, NULL, 0, 0);
1d72983
+        if (!_cph_cups_is_job_id_valid (cups, job_id))
1d72983
+                return CPH_JOB_STATUS_INVALID;
1d72983
+
1d72983
+        request = ippNewRequest (IPP_GET_JOB_ATTRIBUTES);
1d72983
+        _cph_cups_add_job_uri (request, job_id);
1d72983
+        ippAddStrings (request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
1d72983
+                       "requested-attributes", 1, NULL, attrs);
1d72983
+
1d72983
+        resource_char = _cph_cups_get_resource (CPH_RESOURCE_ROOT);
1d72983
+        reply = cupsDoRequest (cups->priv->connection,
1d72983
+                               request, resource_char);
1d72983
 
1d72983
-        for (i = 0; i < num_jobs; i++) {
1d72983
-                if (jobs[i].id == job_id) {
1d72983
-                        if (user != NULL &&
1d72983
-                            g_strcmp0 (jobs[i].user, user) == 0)
1d72983
+        if (!reply || reply->request.status.status_code > IPP_OK_CONFLICT)
1d72983
+                return CPH_JOB_STATUS_INVALID;
1d72983
+
1d72983
+        for (attr = reply->attrs; attr; attr = attr->next) {
1d72983
+                if (attr->name &&
1d72983
+                    strcmp (attr->name, "job-originating-user-name") == 0) {
1d72983
+                        if (g_strcmp0 (attr->values[0].string.text, user) == 0)
1d72983
                                 status = CPH_JOB_STATUS_OWNED_BY_USER;
1d72983
                         else
1d72983
                                 status = CPH_JOB_STATUS_NOT_OWNED_BY_USER;
1d72983
@@ -1807,7 +1822,7 @@ cph_cups_job_get_status (CphCups    *cup
1d72983
                 }
1d72983
         }
1d72983
 
1d72983
-        cupsFreeJobs (num_jobs, jobs);
1d72983
+        ippDelete (reply);
1d72983
 
1d72983
         return status;
1d72983
 }