Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept queue keyword arg in Connection_getJobs #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 32 additions & 8 deletions cupsconnection.c
Original file line number Diff line number Diff line change
Expand Up @@ -1512,25 +1512,49 @@ Connection_getJobs (Connection *self, PyObject *args, PyObject *kwds)
PyObject *result;
ipp_t *request, *answer;
ipp_attribute_t *attr;
char uri[HTTP_MAX_URI] = "ipp://localhost/printers/";
int len_uri = strlen(uri);
int len_queue = 0;
char *queue = NULL;
char *which = NULL;
int my_jobs = 0;
int limit = -1;
int first_job_id = -1;
PyObject *requested_attrs = NULL;
char **attrs = NULL; /* initialised to calm compiler */
size_t n_attrs = 0; /* initialised to calm compiler */
static char *kwlist[] = { "which_jobs", "my_jobs", "limit", "first_job_id",
"requested_attributes", NULL };
if (!PyArg_ParseTupleAndKeywords (args, kwds, "|siiiO", kwlist,
&which, &my_jobs, &limit, &first_job_id,
&requested_attrs))
static char *kwlist[] = { "queue", "which_jobs", "my_jobs", "limit",
"first_job_id", "requested_attributes", NULL };
if (!PyArg_ParseTupleAndKeywords (args, kwds, "|ssiiiO", kwlist,
&queue, &which, &my_jobs, &limit,
&first_job_id, &requested_attrs))
return NULL;

debugprintf ("-> Connection_getJobs(%s,%d)\n",
which ? which : "(null)", my_jobs);
debugprintf ("-> Connection_getJobs(%.1023s,%s,%d)\n",
queue ? queue : "(null)", which ? which : "(null)", my_jobs);

if (queue) {
len_queue = strspn (queue, "!$&'()*+,-.:;=@_~0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz");

if (queue[len_queue] != '\0') {
PyErr_SetString (PyExc_RuntimeError, "invalid queue specified");
return NULL;
}

if (len_uri + len_queue > HTTP_MAX_URI - 1) {
debugprintf ("queue name is too long, trimming it");
len_queue = HTTP_MAX_URI - 1 - len_uri;
}

memmove (uri + len_uri, queue, len_queue);
uri[len_uri + len_queue] = '\0';
}

request = ippNewRequest(IPP_GET_JOBS);
ippAddString (request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
NULL, "ipp://localhost/printers/");
NULL, uri);

ippAddString (request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "which-jobs",
NULL, which ? which : "not-completed");
Expand Down