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

Adds name property for getJobs method #4

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vscode/
Binary file added build/lib.macosx-10.12-intel-2.7/cups.so
Binary file not shown.
Binary file not shown.
Binary file added build/temp.macosx-10.12-intel-2.7/cupsipp.o
Binary file not shown.
Binary file added build/temp.macosx-10.12-intel-2.7/cupsmodule.o
Binary file not shown.
Binary file added build/temp.macosx-10.12-intel-2.7/cupsppd.o
Binary file not shown.
1 change: 1 addition & 0 deletions cups.so
50 changes: 45 additions & 5 deletions cupsconnection.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
m; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

Expand All @@ -28,6 +28,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <regex.h>
#include <unistd.h>

#ifndef _PATH_TMP
Expand All @@ -40,6 +41,9 @@
#define DICT_POS_TYPE Py_ssize_t
#endif

#define MIN(x, y) (((x) < (y)) ? (x) : (y))
#define MAX(x, y) (((x) > (y)) ? (x) : (y))

PyObject *HTTPError;
PyObject *IPPError;

Expand Down Expand Up @@ -1574,25 +1578,61 @@ Connection_getJobs (Connection *self, PyObject *args, PyObject *kwds)
PyObject *result;
ipp_t *request, *answer;
ipp_attribute_t *attr;
int status;
regex_t re;
char *name = NULL;
char *which = NULL;
char uri[1024];
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",
static char *kwlist[] = { "name", "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,
if (!PyArg_ParseTupleAndKeywords (args, kwds, "|ssiiiO", kwlist,
&name, &which, &my_jobs, &limit, &first_job_id,
&requested_attrs))
return NULL;

debugprintf ("-> Connection_getJobs(%s,%d)\n",
which ? which : "(null)", my_jobs);
request = ippNewRequest(IPP_GET_JOBS);

if (name == NULL) {
name = "";
} else {

if (regcomp(&re, "[A-Za-z0-9\\-\\.\\_\\~]+", REG_EXTENDED|REG_NOSUB) != 0) {
return NULL;
}

status = regexec(&re, name, (size_t) 0, NULL, 0);
regfree(&re);

if (status != 0) {
PyErr_SetString (PyExc_RuntimeError, "valid name must be specified");
return NULL;
}
}



int name_len = strlen(name);
int full_url_length = strlen(uri) + name_len;

if (full_url_length > HTTP_MAX_URI) {
debugprintf("name too long, cutting it");

int number_to_trim = MIN(full_url_length - HTTP_MAX_URI, name_len);
name[name_len - number_to_trim] = 0;
}

snprintf (uri, sizeof (uri), "ipp://localhost/printers/%s", name);

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