IPP_GET_JOBS/cupsDoRequest() problems

Alan Somers soNmOeSrPsAaMm at comcast.net.invalid
Sun Jan 2 20:11:08 PST 2005


I have an app where I'm attempting to obtain a list of the incomplete jobs from a remote IPP printer queue and display it in a window using the cups library routines (Mac OS X; CUPS 1.1.20rc1 according to the admin.cgi output).  I've been using the cgi-bin/printers.c file as "sample code" and have it about half working some of the time (and barely working the rest of the time).

The problem is that I frequently get an IPP_SERVICE_UNAVAILABLE error when calling cupsDoRequest() to obtain the jobs from a remote host.  Also, I often get an IPP_OK_SUBST advisory, which usually results in some, but not all, of the jobs being reported.  The worst part is that it's unpredictable.  For development purposes, I'm actually requesting the completed jobs rather than the incomplete jobs so that I don't have to queue up a bunch of print jobs for most of my testing.

Anyway, the pertinent code fragment is presented below (condensed somewhat for conciseness and scrubbed free of Objective-C syntax).  I know that I could try parsing the HTML coming from printers.cgi on the remote host, but I'd rather not rely on that format.

static const char *def_attrs[] =	/* Attributes for printer */
	{
	  "job-id",
	  "job-name"
	};
cups_lang_t *language = cupsLangDefault();
char *printer_uri = "ipp://<remote host>/printers/<printer name>"
/*
 * I've also tried "localhost" and "127.0.0.1" in place of
 * <remote host> in the printer URI
 */
http_t *http = httpConnectEncrypt("<remote host>", ippPort(),
                                  cupsEncryption());
ipp_t *request = ippNew();
ipp_t *response;

/* Set up the request */
request->request.op.operation_id = IPP_GET_JOBS;
request->request.op.request_id   = 1;
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
			 "attributes-charset", NULL,
             cupsLangEncoding(language));
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
        	 "attributes-natural-language", NULL,
             language->language);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
        	 "printer-uri", NULL, printer_uri);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
        	 "which-jobs", NULL, "completed");
ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
              "requested-attributes",
  		      sizeof(def_attrs) / sizeof(def_attrs[0]), NULL,
              def_attrs);

/* Send the request */
if ((response = cupsDoRequest(http, request, "/")) != NULL)
{
  ipp_attribute_t *attr = response->attrs;

  /* Skip past the operation attributes */
  while (attr && attr->group_tag == IPP_TAG_OPERATION)
    attr = attr->next;

  /*
   * Parse the job object attributes, storing the job ID and
   * job name
   */
  for (; attr != NULL; attr = attr->next)
  {
	int _jobId;
	char *_jobDescription;

    for (; attr != NULL && attr->group_tag != IPP_TAG_ZERO;
         attr = attr->next)
    {
      switch (attr->value_tag)
	  {
	    case IPP_TAG_INTEGER:
		  if (strcmp(attr->name, "job-id") == 0)
		    _jobId = attr->values[0].integer;
		  break;

		case IPP_TAG_NAME:
		  if (strcmp(attr->name, "job-name") == 0)
		    _jobDescription = attr->values[0].string.text;
		  break;
	  }
    }

    /* Add job to list here ---> */

	if (attr == NULL)
	  break;
  }

  ippDelete(response);
}

httpClose(http);
cupsLangFree(language);





More information about the cups mailing list