summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Kasik <mkasik@redhat.com>2010-02-19 13:50:04 +0100
committerVincent Untz <vuntz@novell.com>2010-02-19 15:13:45 +0100
commit271f42cdd88ee09e8b2a5a54d2e9dadee7f909be (patch)
tree9444a2896cd225ff4e4387ae90aa861fb5aef4fc
parent6ec80887768e2d61b5d5c26c2a2269716c86eff9 (diff)
Improve performance of cph_cups_job_get_status()
In cph_cups_job_get_status(), we used to iterate over all jobs to find the right one. We can instead use a IPP_GET_JOB_ATTRIBUTES request for the right job directly. https://bugzilla.redhat.com/show_bug.cgi?id=548771
-rw-r--r--src/cups.c35
1 files changed, 25 insertions, 10 deletions
diff --git a/src/cups.c b/src/cups.c
index 6ed30c8..3029a0f 100644
--- a/src/cups.c
+++ b/src/cups.c
@@ -2139,19 +2139,34 @@ cph_cups_job_get_status (CphCups *cups,
int job_id,
const char *user)
{
- CphJobStatus status = CPH_JOB_STATUS_INVALID;
- cups_job_t *jobs;
- int num_jobs;
- int i;
+ const char * const attrs[1] = { "job-originating-user-name" };
+ ipp_t *request;
+ const char *resource_char;
+ ipp_t *reply;
+ ipp_attribute_t *attr;
+ CphJobStatus status = CPH_JOB_STATUS_INVALID;
g_return_val_if_fail (CPH_IS_CUPS (cups), CPH_JOB_STATUS_INVALID);
- num_jobs = cupsGetJobs2 (cups->priv->connection, &jobs, NULL, 0, 0);
+ if (!_cph_cups_is_job_id_valid (cups, job_id))
+ return CPH_JOB_STATUS_INVALID;
+
+ request = ippNewRequest (IPP_GET_JOB_ATTRIBUTES);
+ _cph_cups_add_job_uri (request, job_id);
+ ippAddStrings (request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
+ "requested-attributes", 1, NULL, attrs);
- for (i = 0; i < num_jobs; i++) {
- if (jobs[i].id == job_id) {
- if (user != NULL &&
- g_strcmp0 (jobs[i].user, user) == 0)
+ resource_char = _cph_cups_get_resource (CPH_RESOURCE_ROOT);
+ reply = cupsDoRequest (cups->priv->connection,
+ request, resource_char);
+
+ if (!reply)
+ return CPH_JOB_STATUS_INVALID;
+
+ for (attr = reply->attrs; attr; attr = attr->next) {
+ if (attr->name &&
+ strcmp (attr->name, "job-originating-user-name") == 0) {
+ if (g_strcmp0 (attr->values[0].string.text, user) == 0)
status = CPH_JOB_STATUS_OWNED_BY_USER;
else
status = CPH_JOB_STATUS_NOT_OWNED_BY_USER;
@@ -2159,7 +2174,7 @@ cph_cups_job_get_status (CphCups *cups,
}
}
- cupsFreeJobs (num_jobs, jobs);
+ ippDelete (reply);
return status;
}