Example #1
0
static int				/* O - 1 if equal, 0 if not equal */
dests_equal(cups_dest_t *a,		/* I - First destination */
            cups_dest_t *b)		/* I - Second destination */
{
  int		i;			/* Looping var */
  cups_option_t	*aoption;		/* Current option */
  const char	*bval;			/* Option value */


  if (a == b)
    return (1);

  if (!a || !b)
    return (0);

  if (_cups_strcasecmp(a->name, b->name) ||
      (a->instance && !b->instance) ||
      (!a->instance && b->instance) ||
      (a->instance && _cups_strcasecmp(a->instance, b->instance)) ||
      a->num_options != b->num_options)
    return (0);

  for (i = a->num_options, aoption = a->options; i > 0; i --, aoption ++)
    if ((bval = cupsGetOption(aoption->name, b->num_options,
                              b->options)) == NULL ||
        strcmp(aoption->value, bval))
      return (0);

  return (1);
}
Example #2
0
static int				/* O - Result of comparison */
mime_compare_types(mime_type_t *t0,	/* I - First type */
                   mime_type_t *t1)	/* I - Second type */
{
  int	i;				/* Result of comparison */


  if ((i = _cups_strcasecmp(t0->super, t1->super)) == 0)
    i = _cups_strcasecmp(t0->type, t1->type);

  return (i);
}
Example #3
0
static int				/* O - 1 on failure, 0 on success */
test_pagesize(_ppd_cache_t *pc,		/* I - PWG mapping data */
              ppd_file_t   *ppd,	/* I - PPD file */
	      const char   *ppdsize)	/* I - PPD page size */
{
  int		status = 0;		/* Return status */
  ipp_t		*job;			/* Job attributes */
  const char	*pagesize;		/* PageSize value */


  if (ppdPageSize(ppd, ppdsize))
  {
    printf("_ppdCacheGetPageSize(keyword=%s): ", ppdsize);
    fflush(stdout);

    if ((pagesize = _ppdCacheGetPageSize(pc, NULL, ppdsize, NULL)) == NULL)
    {
      puts("FAIL (Not Found)");
      status = 1;
    }
    else if (_cups_strcasecmp(pagesize, ppdsize))
    {
      printf("FAIL (Got \"%s\", Expected \"%s\")\n", pagesize, ppdsize);
      status = 1;
    }
    else
      puts("PASS");

    job = ippNew();
    ippAddString(job, IPP_TAG_JOB, IPP_TAG_KEYWORD, "media", NULL, ppdsize);

    printf("_ppdCacheGetPageSize(media=%s): ", ppdsize);
    fflush(stdout);

    if ((pagesize = _ppdCacheGetPageSize(pc, job, NULL, NULL)) == NULL)
    {
      puts("FAIL (Not Found)");
      status = 1;
    }
    else if (_cups_strcasecmp(pagesize, ppdsize))
    {
      printf("FAIL (Got \"%s\", Expected \"%s\")\n", pagesize, ppdsize);
      status = 1;
    }
    else
      puts("PASS");

    ippDelete(job);
  }

  return (status);
}
Example #4
0
static void
cups_set_ssl_options(
    _cups_client_conf_t *cc,		/* I - client.conf values */
    const char          *value)		/* I - Value */
{
 /*
  * SSLOptions [AllowRC4] [AllowSSL3] [AllowDH] [DenyTLS1.0] [None]
  */

  int	options = _HTTP_TLS_NONE;	/* SSL/TLS options */
  char	temp[256],			/* Copy of value */
	*start,				/* Start of option */
	*end;				/* End of option */


  strlcpy(temp, value, sizeof(temp));

  for (start = temp; *start; start = end)
  {
   /*
    * Find end of keyword...
    */

    end = start;
    while (*end && !_cups_isspace(*end))
      end ++;

    if (*end)
      *end++ = '\0';

   /*
    * Compare...
    */

    if (!_cups_strcasecmp(start, "AllowRC4"))
      options |= _HTTP_TLS_ALLOW_RC4;
    else if (!_cups_strcasecmp(start, "AllowSSL3"))
      options |= _HTTP_TLS_ALLOW_SSL3;
    else if (!_cups_strcasecmp(start, "AllowDH"))
      options |= _HTTP_TLS_ALLOW_DH;
    else if (!_cups_strcasecmp(start, "DenyTLS1.0"))
      options |= _HTTP_TLS_DENY_TLS10;
    else if (!_cups_strcasecmp(start, "None"))
      options = _HTTP_TLS_NONE;
  }

  cc->ssl_options = options;

  DEBUG_printf(("4cups_set_ssl_options(cc=%p, value=\"%s\") options=%x", cc, value, options));
}
Example #5
0
static void
cups_set_encryption(
    _cups_client_conf_t *cc,		/* I - client.conf values */
    const char          *value)		/* I - Value */
{
  if (!_cups_strcasecmp(value, "never"))
    cc->encryption = HTTP_ENCRYPTION_NEVER;
  else if (!_cups_strcasecmp(value, "always"))
    cc->encryption = HTTP_ENCRYPTION_ALWAYS;
  else if (!_cups_strcasecmp(value, "required"))
    cc->encryption = HTTP_ENCRYPTION_REQUIRED;
  else
    cc->encryption = HTTP_ENCRYPTION_IF_REQUESTED;
}
Example #6
0
File: attr.c Project: ezeep/cups
ppd_attr_t *				/* O - Attribute or @code NULL@ if not found */
ppdFindAttr(ppd_file_t *ppd,		/* I - PPD file data */
            const char *name,		/* I - Attribute name */
            const char *spec)		/* I - Specifier string or @code NULL@ */
{
  ppd_attr_t	key,			/* Search key */
		*attr;			/* Current attribute */


  DEBUG_printf(("2ppdFindAttr(ppd=%p, name=\"%s\", spec=\"%s\")", ppd, name,
                spec));

 /*
  * Range check input...
  */

  if (!ppd || !name || ppd->num_attrs == 0)
    return (NULL);

 /*
  * Search for a matching attribute...
  */

  memset(&key, 0, sizeof(key));
  strlcpy(key.name, name, sizeof(key.name));

 /*
  * Return the first matching attribute, if any...
  */

  if ((attr = (ppd_attr_t *)cupsArrayFind(ppd->sorted_attrs, &key)) != NULL)
  {
    if (spec)
    {
     /*
      * Loop until we find the first matching attribute for "spec"...
      */

      while (attr && _cups_strcasecmp(spec, attr->spec))
      {
        if ((attr = (ppd_attr_t *)cupsArrayNext(ppd->sorted_attrs)) != NULL &&
	    _cups_strcasecmp(attr->name, name))
	  attr = NULL;
      }
    }
  }

  return (attr);
}
Example #7
0
static int				/* O - Result of comparison */
cgi_compare_variables(
    const _cgi_var_t *v1,		/* I - First variable */
    const _cgi_var_t *v2)		/* I - Second variable */
{
  return (_cups_strcasecmp(v1->name, v2->name));
}
Example #8
0
static int				/* O - Difference */
help_sort_by_score(help_node_t *n1,	/* I - First node */
                   help_node_t *n2)	/* I - Second node */
{
  int		diff;			/* Difference */


  DEBUG_printf(("2help_sort_by_score(n1=%p(%d \"%s\" \"%s\"), "
                "n2=%p(%d \"%s\" \"%s\")",
                n1, n1->score, n1->section, n1->text,
                n2, n2->score, n2->section, n2->text));

  if (n1->score != n2->score)
    return (n2->score - n1->score);

  if (n1->section && !n2->section)
    return (1);
  else if (!n1->section && n2->section)
    return (-1);
  else if (n1->section && n2->section &&
           (diff = strcmp(n1->section, n2->section)) != 0)
    return (diff);

  return (_cups_strcasecmp(n1->text, n2->text));
}
Example #9
0
int					/* O - Number of conflicting options */
cupsGetConflicts(
    ppd_file_t    *ppd,			/* I - PPD file */
    const char    *option,		/* I - Option to test */
    const char    *choice,		/* I - Choice to test */
    cups_option_t **options)		/* O - Conflicting options */
{
  int			i,		/* Looping var */
			num_options;	/* Number of conflicting options */
  cups_array_t		*active;	/* Active conflicts */
  _ppd_cups_uiconsts_t	*c;		/* Current constraints */
  _ppd_cups_uiconst_t	*cptr;		/* Current constraint */
  ppd_choice_t		*marked;	/* Marked choice */


 /*
  * Range check input...
  */

  if (options)
    *options = NULL;

  if (!ppd || !option || !choice || !options)
    return (0);

 /*
  * Test for conflicts...
  */

  active = ppd_test_constraints(ppd, option, choice, 0, NULL,
                                _PPD_ALL_CONSTRAINTS);

 /*
  * Loop through all of the UI constraints and add any options that conflict...
  */

  for (num_options = 0, c = (_ppd_cups_uiconsts_t *)cupsArrayFirst(active);
       c;
       c = (_ppd_cups_uiconsts_t *)cupsArrayNext(active))
  {
    for (i = c->num_constraints, cptr = c->constraints;
         i > 0;
	 i --, cptr ++)
      if (_cups_strcasecmp(cptr->option->keyword, option))
      {
        if (cptr->choice)
	  num_options = cupsAddOption(cptr->option->keyword,
	                              cptr->choice->choice, num_options,
				      options);
        else if ((marked = ppdFindMarkedChoice(ppd,
	                                       cptr->option->keyword)) != NULL)
	  num_options = cupsAddOption(cptr->option->keyword, marked->choice,
				      num_options, options);
      }
  }

  cupsArrayDelete(active);

  return (num_options);
}
Example #10
0
File: attr.c Project: ezeep/cups
ppd_attr_t *				/* O - Attribute or @code NULL@ if not found */
ppdFindNextAttr(ppd_file_t *ppd,	/* I - PPD file data */
                const char *name,	/* I - Attribute name */
		const char *spec)	/* I - Specifier string or @code NULL@ */
{
  ppd_attr_t	*attr;			/* Current attribute */


 /*
  * Range check input...
  */

  if (!ppd || !name || ppd->num_attrs == 0)
    return (NULL);

 /*
  * See if there are more attributes to return...
  */

  while ((attr = (ppd_attr_t *)cupsArrayNext(ppd->sorted_attrs)) != NULL)
  {
   /*
    * Check the next attribute to see if it is a match...
    */

    if (_cups_strcasecmp(attr->name, name))
    {
     /*
      * Nope, reset the current pointer to the end of the array...
      */

      cupsArrayIndex(ppd->sorted_attrs, cupsArrayCount(ppd->sorted_attrs));

      return (NULL);
    }

    if (!spec || !_cups_strcasecmp(attr->spec, spec))
      break;
  }

 /*
  * Return the next attribute's value...
  */

  return (attr);
}
Example #11
0
static int				/* O - Result of comparison */
compare_devices(cupsd_device_t *d0,	/* I - First device */
                cupsd_device_t *d1)	/* I - Second device */
{
  int		diff;			/* Difference between strings */


 /*
  * Sort devices by device-info, device-class, and device-uri...
  */

  if ((diff = cupsdCompareNames(d0->device_info, d1->device_info)) != 0)
    return (diff);
  else if ((diff = _cups_strcasecmp(d0->device_class, d1->device_class)) != 0)
    return (diff);
  else
    return (_cups_strcasecmp(d0->device_uri, d1->device_uri));
}
Example #12
0
static int				/* O - Difference */
help_sort_words(help_word_t *w1,	/* I - Second word */
                help_word_t *w2)	/* I - Second word */
{
  DEBUG_printf(("2help_sort_words(w1=%p(\"%s\"), w2=%p(\"%s\"))",
                w1, w1->text, w2, w2->text));

  return (_cups_strcasecmp(w1->text, w2->text));
}
Example #13
0
int					/* O  - New number of options */
cupsRemoveOption(
    const char    *name,		/* I  - Option name */
    int           num_options,		/* I  - Current number of options */
    cups_option_t **options)		/* IO - Options */
{
  int		i;			/* Looping var */
  cups_option_t	*option;		/* Current option */


  DEBUG_printf(("2cupsRemoveOption(name=\"%s\", num_options=%d, options=%p)",
                name, num_options, options));

 /*
  * Range check input...
  */

  if (!name || num_options < 1 || !options)
  {
    DEBUG_printf(("3cupsRemoveOption: Returning %d", num_options));
    return (num_options);
  }

 /*
  * Loop for the option...
  */

  for (i = num_options, option = *options; i > 0; i --, option ++)
    if (!_cups_strcasecmp(name, option->name))
      break;

  if (i)
  {
   /*
    * Remove this option from the array...
    */

    DEBUG_puts("4cupsRemoveOption: Found option, removing it...");

    num_options --;
    i --;

    _cupsStrFree(option->name);
    _cupsStrFree(option->value);

    if (i > 0)
      memmove(option, option + 1, (size_t)i * sizeof(cups_option_t));
  }

 /*
  * Return the new number of options...
  */

  DEBUG_printf(("3cupsRemoveOption: Returning %d", num_options));
  return (num_options);
}
Example #14
0
static void
cups_read_client_conf(
    cups_file_t         *fp,		/* I - File to read */
    _cups_client_conf_t *cc)		/* I - client.conf values */
{
  int	linenum;			/* Current line number */
  char	line[1024],			/* Line from file */
        *value;				/* Pointer into line */


 /*
  * Read from the file...
  */

  linenum = 0;
  while (cupsFileGetConf(fp, line, sizeof(line), &value, &linenum))
  {
    if (!_cups_strcasecmp(line, "Encryption") && value)
      cups_set_encryption(cc, value);
#ifndef __APPLE__
   /*
    * The ServerName directive is not supported on macOS due to app
    * sandboxing restrictions, i.e. not all apps request network access.
    */
    else if (!_cups_strcasecmp(line, "ServerName") && value)
      cups_set_server_name(cc, value);
#endif /* !__APPLE__ */
    else if (!_cups_strcasecmp(line, "User") && value)
      cups_set_user(cc, value);
    else if (!_cups_strcasecmp(line, "TrustOnFirstUse") && value)
      cc->trust_first = cups_boolean_value(value);
    else if (!_cups_strcasecmp(line, "AllowAnyRoot") && value)
      cc->any_root = cups_boolean_value(value);
    else if (!_cups_strcasecmp(line, "AllowExpiredCerts") &&
             value)
      cc->expired_certs = cups_boolean_value(value);
    else if (!_cups_strcasecmp(line, "ValidateCerts") && value)
      cc->validate_certs = cups_boolean_value(value);
#ifdef HAVE_GSSAPI
    else if (!_cups_strcasecmp(line, "GSSServiceName") && value)
      cups_set_gss_service_name(cc, value);
#endif /* HAVE_GSSAPI */
#ifdef HAVE_SSL
    else if (!_cups_strcasecmp(line, "SSLOptions") && value)
      cups_set_ssl_options(cc, value);
#endif /* HAVE_SSL */
  }
}
Example #15
0
static int				/* O - Result of comparison */
compare_sections_files(
    _cups_section_t *a,			/* I - First section */
    _cups_section_t *b)			/* I - Second section */
{
  int	ret = cupsArrayCount(b->files) - cupsArrayCount(a->files);

  if (ret)
    return (ret);
  else
    return (_cups_strcasecmp(a->name, b->name));
}
ipp_status_t				/* O - IPP status code */
ippErrorValue(const char *name)		/* I - Name */
{
    int		i;


    for (i = 0; i < (sizeof(ipp_status_oks) / sizeof(ipp_status_oks[0])); i ++)
        if (!_cups_strcasecmp(name, ipp_status_oks[i]))
            return ((ipp_status_t)i);

    if (!_cups_strcasecmp(name, "redirection-other-site"))
        return (IPP_REDIRECTION_OTHER_SITE);

    if (!_cups_strcasecmp(name, "cups-see-other"))
        return (CUPS_SEE_OTHER);

    for (i = 0; i < (sizeof(ipp_status_400s) / sizeof(ipp_status_400s[0])); i ++)
        if (!_cups_strcasecmp(name, ipp_status_400s[i]))
            return ((ipp_status_t)(i + 0x400));

    for (i = 0; i < (sizeof(ipp_status_500s) / sizeof(ipp_status_500s[0])); i ++)
        if (!_cups_strcasecmp(name, ipp_status_500s[i]))
            return ((ipp_status_t)(i + 0x500));

    for (i = 0; i < (sizeof(ipp_status_1000s) / sizeof(ipp_status_1000s[0])); i ++)
        if (!_cups_strcasecmp(name, ipp_status_1000s[i]))
            return ((ipp_status_t)(i + 0x1000));

    return ((ipp_status_t)-1);
}
ipp_op_t				/* O - Operation ID */
ippOpValue(const char *name)		/* I - Textual name */
{
    int		i;


    if (!strncmp(name, "0x", 2))
        return ((ipp_op_t)strtol(name + 2, NULL, 16));

    for (i = 0; i < (sizeof(ipp_std_ops) / sizeof(ipp_std_ops[0])); i ++)
        if (!_cups_strcasecmp(name, ipp_std_ops[i]))
            return ((ipp_op_t)i);

    if (!_cups_strcasecmp(name, "windows-ext"))
        return (IPP_PRIVATE);

    for (i = 0; i < (sizeof(ipp_cups_ops) / sizeof(ipp_cups_ops[0])); i ++)
        if (!_cups_strcasecmp(name, ipp_cups_ops[i]))
            return ((ipp_op_t)(i + 0x4001));

    for (i = 0; i < (sizeof(ipp_cups_ops2) / sizeof(ipp_cups_ops2[0])); i ++)
        if (!_cups_strcasecmp(name, ipp_cups_ops2[i]))
            return ((ipp_op_t)(i + 0x4027));

    if (!_cups_strcasecmp(name, "CUPS-Add-Class"))
        return (CUPS_ADD_MODIFY_CLASS);

    if (!_cups_strcasecmp(name, "CUPS-Add-Printer"))
        return (CUPS_ADD_MODIFY_PRINTER);

    return ((ipp_op_t)-1);
}
Example #18
0
static void
show_diffs(cups_dest_t *a,		/* I - First destination */
           cups_dest_t *b)		/* I - Second destination */
{
  int		i;			/* Looping var */
  cups_option_t	*aoption;		/* Current option */
  const char	*bval;			/* Option value */


  if (!a || !b)
    return;

  puts("    Item                  cupsGetDest           cupsGetNamedDest");
  puts("    --------------------  --------------------  --------------------");

  if (_cups_strcasecmp(a->name, b->name))
    printf("    name                  %-20.20s  %-20.20s\n", a->name, b->name);

  if ((a->instance && !b->instance) ||
      (!a->instance && b->instance) ||
      (a->instance && _cups_strcasecmp(a->instance, b->instance)))
    printf("    instance              %-20.20s  %-20.20s\n",
           a->instance ? a->instance : "(null)",
	   b->instance ? b->instance : "(null)");

  if (a->num_options != b->num_options)
    printf("    num_options           %-20d  %-20d\n", a->num_options,
           b->num_options);

  for (i = a->num_options, aoption = a->options; i > 0; i --, aoption ++)
    if ((bval = cupsGetOption(aoption->name, b->num_options,
                              b->options)) == NULL ||
        strcmp(aoption->value, bval))
      printf("    %-20.20s  %-20.20s  %-20.20s\n", aoption->name,
             aoption->value, bval ? bval : "(null)");
}
Example #19
0
static void
ppd_defaults(ppd_file_t  *ppd,		/* I - PPD file */
             ppd_group_t *g)		/* I - Group to default */
{
  int		i;			/* Looping var */
  ppd_option_t	*o;			/* Current option */
  ppd_group_t	*sg;			/* Current sub-group */


  for (i = g->num_options, o = g->options; i > 0; i --, o ++)
    if (_cups_strcasecmp(o->keyword, "PageRegion") != 0)
      ppdMarkOption(ppd, o->keyword, o->defchoice);

  for (i = g->num_subgroups, sg = g->subgroups; i > 0; i --, sg ++)
    ppd_defaults(ppd, sg);
}
Example #20
0
ppd_option_t *				/* O - Pointer to option or @code NULL@ */
ppdFindOption(ppd_file_t *ppd,		/* I - PPD file data */
              const char *option)	/* I - Option/Keyword name */
{
 /*
  * Range check input...
  */

  if (!ppd || !option)
    return (NULL);

  if (ppd->options)
  {
   /*
    * Search in the array...
    */

    ppd_option_t	key;		/* Option search key */


    strlcpy(key.keyword, option, sizeof(key.keyword));

    return ((ppd_option_t *)cupsArrayFind(ppd->options, &key));
  }
  else
  {
   /*
    * Search in each group...
    */

    int			i, j;		/* Looping vars */
    ppd_group_t		*group;		/* Current group */
    ppd_option_t	*optptr;	/* Current option */


    for (i = ppd->num_groups, group = ppd->groups; i > 0; i --, group ++)
      for (j = group->num_options, optptr = group->options;
           j > 0;
	   j --, optptr ++)
        if (!_cups_strcasecmp(optptr->keyword, option))
	  return (optptr);

    return (NULL);
  }
}
Example #21
0
ppd_cparam_t *				/* O - Custom parameter or NULL */
ppdFindCustomParam(ppd_coption_t *opt,	/* I - Custom option */
                   const char    *name)	/* I - Parameter name */
{
  ppd_cparam_t	*param;			/* Current custom parameter */


  if (!opt)
    return (NULL);

  for (param = (ppd_cparam_t *)cupsArrayFirst(opt->params);
       param;
       param = (ppd_cparam_t *)cupsArrayNext(opt->params))
    if (!_cups_strcasecmp(param->name, name))
      break;

  return (param);
}
Example #22
0
static int				/* O - 1 for YES or AUTOMATIC, 0 for NO */
get_hostconfig(const char *name)	/* I - Name of service */
{
  cups_file_t	*fp;			/* Hostconfig file */
  char		line[1024],		/* Line from file */
		*ptr;			/* Pointer to value */
  int		state = 1;		/* State of service */


 /*
  * Try opening the /etc/hostconfig file; if we can't open it, assume that
  * the service is enabled/auto.
  */

  if ((fp = cupsFileOpen("/etc/hostconfig", "r")) != NULL)
  {
   /*
    * Read lines from the file until we find the service...
    */

    while (cupsFileGets(fp, line, sizeof(line)))
    {
      if (line[0] == '#' || (ptr = strchr(line, '=')) == NULL)
        continue;

      *ptr++ = '\0';

      if (!_cups_strcasecmp(line, name))
      {
       /*
        * Found the service, see if it is set to "-NO-"...
	*/

	if (!_cups_strncasecmp(ptr, "-NO-", 4))
	  state = 0;
        break;
      }
    }

    cupsFileClose(fp);
  }

  return (state);
}
Example #23
0
File: cert.c Project: jelmer/cups
cupsd_cert_t *				/* O - Matching certificate or NULL */
cupsdFindCert(const char *certificate)	/* I - Certificate */
{
  cupsd_cert_t	*cert;			/* Current certificate */


  cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdFindCert(certificate=%s)",
                  certificate);
  for (cert = Certs; cert != NULL; cert = cert->next)
    if (!_cups_strcasecmp(certificate, cert->certificate))
    {
      cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdFindCert: Returning %s...",
                      cert->username);
      return (cert);
    }

  cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdFindCert: Certificate not found!");

  return (NULL);
}
Example #24
0
ppd_choice_t *				/* O - Choice pointer or @code NULL@ */
ppdFindChoice(ppd_option_t *o,		/* I - Pointer to option */
              const char   *choice)	/* I - Name of choice */
{
  int		i;			/* Looping var */
  ppd_choice_t	*c;			/* Current choice */


  if (!o || !choice)
    return (NULL);

  if (choice[0] == '{' || !_cups_strncasecmp(choice, "Custom.", 7))
    choice = "Custom";

  for (i = o->num_choices, c = o->choices; i > 0; i --, c ++)
    if (!_cups_strcasecmp(c->choice, choice))
      return (c);

  return (NULL);
}
Example #25
0
static int				/* O - 1 if installable, 0 if normal */
ppd_is_installable(
    ppd_group_t *installable,		/* I - InstallableOptions group */
    const char  *name)			/* I - Option name */
{
  if (installable)
  {
    int			i;		/* Looping var */
    ppd_option_t	*option;	/* Current option */


    for (i = installable->num_options, option = installable->options;
         i > 0;
	 i --, option ++)
      if (!_cups_strcasecmp(option->keyword, name))
        return (1);
  }

  return (0);
}
Example #26
0
static void
dnssdRegisterCallback(
    DNSServiceRef	sdRef,		/* I - DNS Service reference */
    DNSServiceFlags	flags,		/* I - Reserved for future use */
    DNSServiceErrorType	errorCode,	/* I - Error code */
    const char		*name,     	/* I - Service name */
    const char		*regtype,  	/* I - Service type */
    const char		*domain,   	/* I - Domain. ".local" for now */
    void		*context)	/* I - Printer */
{
  cupsd_printer_t *p = (cupsd_printer_t *)context;
					/* Current printer */


  (void)sdRef;
  (void)flags;
  (void)domain;

  cupsdLogMessage(CUPSD_LOG_DEBUG2, "dnssdRegisterCallback(%s, %s) for %s (%s)",
                  name, regtype, p ? p->name : "Web Interface",
		  p ? (p->reg_name ? p->reg_name : "(null)") : "NA");

  if (errorCode)
  {
    cupsdLogMessage(CUPSD_LOG_ERROR,
		    "DNSServiceRegister failed with error %d", (int)errorCode);
    return;
  }
  else if (p && (!p->reg_name || _cups_strcasecmp(name, p->reg_name)))
  {
    cupsdLogMessage(CUPSD_LOG_INFO, "Using service name \"%s\" for \"%s\"",
                    name, p->name);

    cupsArrayRemove(DNSSDPrinters, p);
    cupsdSetString(&p->reg_name, name);
    cupsArrayAdd(DNSSDPrinters, p);

    LastEvent |= CUPSD_EVENT_PRINTER_MODIFIED;
  }
}
Example #27
0
const char *				/* O - Default community name */
_cupsSNMPDefaultCommunity(void)
{
  cups_file_t	*fp;			/* snmp.conf file */
  char		line[1024],		/* Line from file */
		*value;			/* Value from file */
  int		linenum;		/* Line number in file */
  _cups_globals_t *cg = _cupsGlobals();	/* Global data */


  DEBUG_puts("4_cupsSNMPDefaultCommunity()");

  if (!cg->snmp_community[0])
  {
    strlcpy(cg->snmp_community, "public", sizeof(cg->snmp_community));

    snprintf(line, sizeof(line), "%s/snmp.conf", cg->cups_serverroot);
    if ((fp = cupsFileOpen(line, "r")) != NULL)
    {
      linenum = 0;
      while (cupsFileGetConf(fp, line, sizeof(line), &value, &linenum))
	if (!_cups_strcasecmp(line, "Community") && value)
	{
	  strlcpy(cg->snmp_community, value, sizeof(cg->snmp_community));
	  break;
	}

      cupsFileClose(fp);
    }
  }

  DEBUG_printf(("5_cupsSNMPDefaultCommunity: Returning \"%s\"",
                cg->snmp_community));

  return (cg->snmp_community);
}
const char *				/* O - Device URI or @code NULL@ */
cupsBackendDeviceURI(char **argv)	/* I - Command-line arguments */
{
  const char	*device_uri,		/* Device URI */
		*auth_info_required;	/* AUTH_INFO_REQUIRED env var */
  _cups_globals_t *cg = _cupsGlobals();	/* Global info */
  int		options;		/* Resolve options */
  ppd_file_t	*ppd;			/* PPD file */
  ppd_attr_t	*ppdattr;		/* PPD attribute */


  if ((device_uri = getenv("DEVICE_URI")) == NULL)
  {
    if (!argv || !argv[0] || !strchr(argv[0], ':'))
      return (NULL);

    device_uri = argv[0];
  }

  options = _HTTP_RESOLVE_STDERR;
  if ((auth_info_required = getenv("AUTH_INFO_REQUIRED")) != NULL &&
      !strcmp(auth_info_required, "negotiate"))
    options |= _HTTP_RESOLVE_FQDN;

  if ((ppd = ppdOpenFile(getenv("PPD"))) != NULL)
  {
    if ((ppdattr = ppdFindAttr(ppd, "cupsIPPFaxOut", NULL)) != NULL &&
        !_cups_strcasecmp(ppdattr->value, "true"))
      options |= _HTTP_RESOLVE_FAXOUT;

    ppdClose(ppd);
  }

  return (_httpResolveURI(device_uri, cg->resolved_uri,
                          sizeof(cg->resolved_uri), options, NULL, NULL));
}
Example #29
0
File: dnssd.c Project: zdohnal/cups
static void
query_callback(
    DNSServiceRef       sdRef,		/* I - Service reference */
    DNSServiceFlags     flags,		/* I - Data flags */
    uint32_t            interfaceIndex,	/* I - Interface */
    DNSServiceErrorType errorCode,	/* I - Error, if any */
    const char          *fullName,	/* I - Full service name */
    uint16_t            rrtype,		/* I - Record type */
    uint16_t            rrclass,	/* I - Record class */
    uint16_t            rdlen,		/* I - Length of record data */
    const void          *rdata,		/* I - Record data */
    uint32_t            ttl,		/* I - Time-to-live */
    void                *context)	/* I - Device */
{
#  else
/*
 * 'query_callback()' - Process query data.
 */

static void
query_callback(
    AvahiRecordBrowser     *browser,	/* I - Record browser */
    AvahiIfIndex           interfaceIndex,
					/* I - Interface index (unused) */
    AvahiProtocol          protocol,	/* I - Network protocol (unused) */
    AvahiBrowserEvent      event,	/* I - What happened? */
    const char             *fullName,	/* I - Service name */
    uint16_t               rrclass,	/* I - Record class */
    uint16_t               rrtype,	/* I - Record type */
    const void             *rdata,	/* I - TXT record */
    size_t                 rdlen,	/* I - Length of TXT record */
    AvahiLookupResultFlags flags,	/* I - Flags */
    void                   *context)	/* I - Device */
{
  AvahiClient		*client = avahi_record_browser_get_client(browser);
					/* Client information */
#  endif /* HAVE_DNSSD */
  char		*ptr;			/* Pointer into string */
  cups_device_t	*device = (cups_device_t *)context;
					/* Device */
  const uint8_t	*data,			/* Pointer into data */
		*datanext,		/* Next key/value pair */
		*dataend;		/* End of entire TXT record */
  uint8_t	datalen;		/* Length of current key/value pair */
  char		key[256],		/* Key string */
		value[256],		/* Value string */
		make_and_model[512],	/* Manufacturer and model */
		model[256],		/* Model */
		pdl[256],		/* PDL */
		device_id[2048];	/* 1284 device ID */


#  ifdef HAVE_DNSSD
  fprintf(stderr, "DEBUG2: query_callback(sdRef=%p, flags=%x, "
                  "interfaceIndex=%d, errorCode=%d, fullName=\"%s\", "
		  "rrtype=%u, rrclass=%u, rdlen=%u, rdata=%p, ttl=%u, "
		  "context=%p)\n",
          sdRef, flags, interfaceIndex, errorCode, fullName, rrtype, rrclass, rdlen, rdata, ttl, context);

 /*
  * Only process "add" data...
  */

  if (errorCode != kDNSServiceErr_NoError || !(flags & kDNSServiceFlagsAdd))
    return;

#  else
  fprintf(stderr, "DEBUG2: query_callback(browser=%p, interfaceIndex=%d, "
                  "protocol=%d, event=%d, fullName=\"%s\", rrclass=%u, "
		  "rrtype=%u, rdata=%p, rdlen=%u, flags=%x, context=%p)\n",
          browser, interfaceIndex, protocol, event, fullName, rrclass, rrtype, rdata, (unsigned)rdlen, flags, context);

 /*
  * Only process "add" data...
  */

  if (event != AVAHI_BROWSER_NEW)
  {
    if (event == AVAHI_BROWSER_FAILURE)
      fprintf(stderr, "ERROR: %s\n",
	      avahi_strerror(avahi_client_errno(client)));

    return;
  }
#  endif /* HAVE_DNSSD */

 /*
  * Pull out the priority and make and model from the TXT
  * record and save it...
  */

  device_id[0]      = '\0';
  make_and_model[0] = '\0';
  pdl[0]            = '\0';

  strlcpy(model, "Unknown", sizeof(model));

  for (data = rdata, dataend = data + rdlen;
       data < dataend;
       data = datanext)
  {
   /*
    * Read a key/value pair starting with an 8-bit length.  Since the
    * length is 8 bits and the size of the key/value buffers is 256, we
    * don't need to check for overflow...
    */

    datalen = *data++;

    if (!datalen || (data + datalen) > dataend)
      break;

    datanext = data + datalen;

    for (ptr = key; data < datanext && *data != '='; data ++)
      *ptr++ = (char)*data;
    *ptr = '\0';

    if (data < datanext && *data == '=')
    {
      data ++;

      if (data < datanext)
	memcpy(value, data, (size_t)(datanext - data));
      value[datanext - data] = '\0';

      fprintf(stderr, "DEBUG2: query_callback: \"%s=%s\".\n",
	      key, value);
    }
    else
    {
      fprintf(stderr, "DEBUG2: query_callback: \"%s\" with no value.\n",
	      key);
      continue;
    }

    if (!_cups_strncasecmp(key, "usb_", 4))
    {
     /*
      * Add USB device ID information...
      */

      ptr = device_id + strlen(device_id);
      snprintf(ptr, sizeof(device_id) - (size_t)(ptr - device_id), "%s:%s;", key + 4, value);
    }

    if (!_cups_strcasecmp(key, "usb_MFG") || !_cups_strcasecmp(key, "usb_MANU") ||
	!_cups_strcasecmp(key, "usb_MANUFACTURER"))
      strlcpy(make_and_model, value, sizeof(make_and_model));
    else if (!_cups_strcasecmp(key, "usb_MDL") || !_cups_strcasecmp(key, "usb_MODEL"))
      strlcpy(model, value, sizeof(model));
    else if (!_cups_strcasecmp(key, "product") && !strstr(value, "Ghostscript"))
    {
      if (value[0] == '(')
      {
       /*
	* Strip parenthesis...
	*/

	if ((ptr = value + strlen(value) - 1) > value && *ptr == ')')
	  *ptr = '\0';

	strlcpy(model, value + 1, sizeof(model));
      }
      else
	strlcpy(model, value, sizeof(model));
    }
    else if (!_cups_strcasecmp(key, "ty"))
    {
      strlcpy(model, value, sizeof(model));

      if ((ptr = strchr(model, ',')) != NULL)
	*ptr = '\0';
    }
    else if (!_cups_strcasecmp(key, "pdl"))
      strlcpy(pdl, value, sizeof(pdl));
    else if (!_cups_strcasecmp(key, "priority"))
      device->priority = atoi(value);
    else if ((device->type == CUPS_DEVICE_IPP ||
	      device->type == CUPS_DEVICE_IPPS ||
	      device->type == CUPS_DEVICE_PRINTER) &&
	     !_cups_strcasecmp(key, "printer-type"))
    {
     /*
      * This is a CUPS printer!
      */

      device->cups_shared = 1;

      if (device->type == CUPS_DEVICE_PRINTER)
	device->sent = 1;
    }
    else if (!_cups_strcasecmp(key, "UUID"))
      device->uuid = strdup(value);
  }

  if (device->device_id)
    free(device->device_id);

  if (!device_id[0] && strcmp(model, "Unknown"))
  {
    if (make_and_model[0])
      snprintf(device_id, sizeof(device_id), "MFG:%s;MDL:%s;",
	       make_and_model, model);
    else if (!_cups_strncasecmp(model, "designjet ", 10))
      snprintf(device_id, sizeof(device_id), "MFG:HP;MDL:%s;", model + 10);
    else if (!_cups_strncasecmp(model, "stylus ", 7))
      snprintf(device_id, sizeof(device_id), "MFG:EPSON;MDL:%s;", model + 7);
    else if ((ptr = strchr(model, ' ')) != NULL)
    {
     /*
      * Assume the first word is the make...
      */

      memcpy(make_and_model, model, (size_t)(ptr - model));
      make_and_model[ptr - model] = '\0';

      snprintf(device_id, sizeof(device_id), "MFG:%s;MDL:%s;",
	       make_and_model, ptr + 1);
    }
  }

  if (device_id[0] &&
      !strstr(device_id, "CMD:") &&
      !strstr(device_id, "COMMAND SET:") &&
      (strstr(pdl, "application/pdf") ||
       strstr(pdl, "application/postscript") ||
       strstr(pdl, "application/vnd.hp-PCL") ||
       strstr(pdl, "image/")))
  {
    value[0] = '\0';
    if (strstr(pdl, "application/pdf"))
      strlcat(value, ",PDF", sizeof(value));
    if (strstr(pdl, "application/postscript"))
      strlcat(value, ",PS", sizeof(value));
    if (strstr(pdl, "application/vnd.hp-PCL"))
      strlcat(value, ",PCL", sizeof(value));
    for (ptr = strstr(pdl, "image/"); ptr; ptr = strstr(ptr, "image/"))
    {
      char *valptr = value + strlen(value);
      					/* Pointer into value */

      if (valptr < (value + sizeof(value) - 1))
        *valptr++ = ',';

      ptr += 6;
      while (isalnum(*ptr & 255) || *ptr == '-' || *ptr == '.')
      {
        if (isalnum(*ptr & 255) && valptr < (value + sizeof(value) - 1))
          *valptr++ = (char)toupper(*ptr++ & 255);
        else
          break;
      }

      *valptr = '\0';
    }

    ptr = device_id + strlen(device_id);
    snprintf(ptr, sizeof(device_id) - (size_t)(ptr - device_id), "CMD:%s;", value + 1);
  }

  if (device_id[0])
    device->device_id = strdup(device_id);
  else
    device->device_id = NULL;

  if (device->make_and_model)
    free(device->make_and_model);

  if (make_and_model[0])
  {
    strlcat(make_and_model, " ", sizeof(make_and_model));
    strlcat(make_and_model, model, sizeof(make_and_model));

    if (!_cups_strncasecmp(make_and_model, "EPSON EPSON ", 12))
      _cups_strcpy(make_and_model, make_and_model + 6);
    else if (!_cups_strncasecmp(make_and_model, "HP HP ", 6))
      _cups_strcpy(make_and_model, make_and_model + 3);
    else if (!_cups_strncasecmp(make_and_model, "Lexmark International Lexmark ", 30))
      _cups_strcpy(make_and_model, make_and_model + 22);

    device->make_and_model = strdup(make_and_model);
  }
  else
    device->make_and_model = strdup(model);
}
Example #30
0
File: dnssd.c Project: zdohnal/cups
static cups_device_t *			/* O - Device */
get_device(cups_array_t *devices,	/* I - Device array */
           const char   *serviceName,	/* I - Name of service/device */
           const char   *regtype,	/* I - Type of service */
           const char   *replyDomain)	/* I - Service domain */
{
  cups_device_t	key,			/* Search key */
		*device;		/* Device */
  char		fullName[kDNSServiceMaxDomainName];
					/* Full name for query */


 /*
  * See if this is a new device...
  */

  key.name = (char *)serviceName;
  key.type = device_type(regtype);

  for (device = cupsArrayFind(devices, &key);
       device;
       device = cupsArrayNext(devices))
    if (_cups_strcasecmp(device->name, key.name))
      break;
    else if (device->type == key.type)
    {
      if (!_cups_strcasecmp(device->domain, "local.") &&
          _cups_strcasecmp(device->domain, replyDomain))
      {
       /*
        * Update the .local listing to use the "global" domain name instead.
	* The backend will try local lookups first, then the global domain name.
	*/

        free(device->domain);
	device->domain = strdup(replyDomain);

#ifdef HAVE_DNSSD
	DNSServiceConstructFullName(fullName, device->name, regtype,
	                            replyDomain);
#else /* HAVE_AVAHI */
	avahi_service_name_join(fullName, kDNSServiceMaxDomainName,
				serviceName, regtype, replyDomain);
#endif /* HAVE_DNSSD */

	free(device->fullName);
	device->fullName = strdup(fullName);
      }

      return (device);
    }

 /*
  * Yes, add the device...
  */

  device           = calloc(sizeof(cups_device_t), 1);
  device->name     = strdup(serviceName);
  device->domain   = strdup(replyDomain);
  device->type     = key.type;
  device->priority = 50;

  cupsArrayAdd(devices, device);

 /*
  * Set the "full name" of this service, which is used for queries...
  */

#ifdef HAVE_DNSSD
  DNSServiceConstructFullName(fullName, serviceName, regtype, replyDomain);
#else /* HAVE_AVAHI */
  avahi_service_name_join(fullName, kDNSServiceMaxDomainName, serviceName, regtype, replyDomain);
#endif /* HAVE_DNSSD */

  device->fullName = strdup(fullName);

  return (device);
}