diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dbe9c82 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vscode/ \ No newline at end of file diff --git a/build/lib.macosx-10.12-intel-2.7/cups.so b/build/lib.macosx-10.12-intel-2.7/cups.so new file mode 100755 index 0000000..84a6b3e Binary files /dev/null and b/build/lib.macosx-10.12-intel-2.7/cups.so differ diff --git a/build/temp.macosx-10.12-intel-2.7/cupsconnection.o b/build/temp.macosx-10.12-intel-2.7/cupsconnection.o new file mode 100644 index 0000000..caadcf0 Binary files /dev/null and b/build/temp.macosx-10.12-intel-2.7/cupsconnection.o differ diff --git a/build/temp.macosx-10.12-intel-2.7/cupsipp.o b/build/temp.macosx-10.12-intel-2.7/cupsipp.o new file mode 100644 index 0000000..672fa2c Binary files /dev/null and b/build/temp.macosx-10.12-intel-2.7/cupsipp.o differ diff --git a/build/temp.macosx-10.12-intel-2.7/cupsmodule.o b/build/temp.macosx-10.12-intel-2.7/cupsmodule.o new file mode 100644 index 0000000..a4ca2cd Binary files /dev/null and b/build/temp.macosx-10.12-intel-2.7/cupsmodule.o differ diff --git a/build/temp.macosx-10.12-intel-2.7/cupsppd.o b/build/temp.macosx-10.12-intel-2.7/cupsppd.o new file mode 100644 index 0000000..634a927 Binary files /dev/null and b/build/temp.macosx-10.12-intel-2.7/cupsppd.o differ diff --git a/cups.so b/cups.so new file mode 120000 index 0000000..5c35a08 --- /dev/null +++ b/cups.so @@ -0,0 +1 @@ +build/lib.macosx-10.12-intel-2.7/cups.so \ No newline at end of file diff --git a/cupsconnection.c b/cupsconnection.c index 242276f..38e250d 100644 --- a/cupsconnection.c +++ b/cupsconnection.c @@ -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. */ @@ -28,6 +28,7 @@ #include #include #include +#include #include #ifndef _PATH_TMP @@ -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; @@ -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");