[cups] Didn't got job-id with IPP_OP_CREATE_JOB

Deepak Patankar patankardeepak04 at gmail.com
Thu May 2 05:53:17 PDT 2019


Hi Sir

I am trying to create a job on a IPP Network Printer using
IPP_OP_CREATE_JOB request. The response message only contains the following
data
 Attr: attributes-charset
 Value: utf-8
 Keyword: utf-8
 Attr: attributes-natural-language
 Value: en
 Keyword: en
I could not understand why job-id is not returned by the response? I also
tried requesting for job-id (using jattrs), but that also didn't help.
For http I am using
   http = httpConnect2(hostname, port,NULL,
                       AF_UNSPEC, HTTP_ENCRYPT_IF_REQUESTED, 1,
                       3000, NULL)
Please guide me how I can solve this problem.

*Code:*

int                             /* O - Job ID or 0 on error */
create_job_on_printer(
    http_t        *http,           /* I - Connection to server */
    const char    *uri,         /* I - Printer uri */
    const char    *resource,    /* I - Resource of Destination */
    const char    *title,       /* I - Title of job */
    int           num_options,  /* I - Number of options */
    cups_option_t *options)     /* I - Options */
{
    int   job_id = 0,i;           /* job-id value */
    ipp_t   *request,           /* Get-Printer-Attributes request */
    *response;                  /* Supported attributes */
    ipp_attribute_t *attr;      /* job-id attribute */
    char valuebuffer[65536];
/*    static const char * const jattrs[] =  /* Job attributes we want */
    {
      "job-id",
      "job-status"
    };  */

  if (job_id)
    job_id = 0;

  fprintf(stderr,"URI : %s %s \n",uri,resource);

 /* Build a Create-Job request. */
  if ((request = ippNewRequest(IPP_OP_CREATE_JOB)) == NULL)
  {
    fprintf(stderr, "Unable to create job request\n");
    return (0);
  }
  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
               NULL, uri);
  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
"requesting-user-name",
               NULL, cupsUser());
  if (title)
    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "job-name", NULL,
                 title);
/*  ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
"requested-attributes",
    (int)(sizeof(jattrs) / sizeof(jattrs[0])), NULL, jattrs);*/
  cupsEncodeOptions2(request, num_options, options, IPP_TAG_OPERATION);
  cupsEncodeOptions2(request, num_options, options, IPP_TAG_JOB);
  cupsEncodeOptions2(request, num_options, options, IPP_TAG_SUBSCRIPTION);

  if(!http)
    fprintf(stderr, "HTTP is  null \n");
response = cupsDoRequest(http, request, resource);

  if(response)
    fprintf(stderr, "NOT NULL RESPONSE\n");

    if (response) {
      attr = ippFirstAttribute(response);
      while (attr) {
        fprintf(stderr,"  Attr: %s\n",
         ippGetName(attr));
        ippAttributeString(attr, valuebuffer, sizeof(valuebuffer));
        fprintf(stderr,"  Value: %s\n", valuebuffer);
        const char *kw;
        for (i = 0; i < ippGetCount(attr); i ++)
          if ((kw = ippGetString(attr, i, NULL)) != NULL)
            fprintf(stderr,"  Keyword: %s\n", kw);
          attr = ippNextAttribute(response);
        }
      }

  if ((attr = ippFindAttribute(response, "job-id", IPP_TAG_INTEGER)) !=
NULL)
  {
    job_id = ippGetInteger(attr,0);
    fprintf(stderr, "Job created with id %d on printer-uri
%s\n",job_id,uri);
  }
  ippDelete(response);
  return (job_id);
}


More information about the cups mailing list