/*
- * "$Id: cups-driverd.c 4812 2005-10-25 18:23:10Z mike $"
+ * "$Id: cups-driverd.c 6363 2007-03-19 20:48:49Z mike $"
*
* PPD/driver support for the Common UNIX Printing System (CUPS).
*
* in CUPS_DATADIR/model and dynamically generated PPD files using
* the driver helper programs in CUPS_SERVERBIN/driver.
*
- * Copyright 1997-2005 by Easy Software Products.
+ * Copyright 1997-2006 by Easy Software Products.
*
* These coded instructions, statements, and computer programs are the
* property of Easy Software Products and are protected by Federal
#include "util.h"
#include <cups/dir.h>
+#include <cups/transcode.h>
+
+
+/*
+ * Private PPD functions...
+ */
+
+extern cups_encoding_t _ppdGetEncoding(const char *name);
/*
/* PPD name */
natural_language[128], /* Natural language(s) */
make[128], /* Manufacturer */
- make_and_model[256]; /* Make and model */
+ make_and_model[128], /* Make and model */
+ device_id[128]; /* IEEE 1284 Device ID */
} ppd_rec_t;
typedef struct /**** In-memory record ****/
* Local functions...
*/
-ppd_info_t *add_ppd(const char *name, const char *natural_language,
+static ppd_info_t *add_ppd(const char *name, const char *natural_language,
const char *make, const char *make_and_model,
- time_t mtime, size_t size);
-int cat_ppd(const char *name);
-int compare_names(const ppd_info_t *p0, const ppd_info_t *p1);
-int compare_ppds(const ppd_info_t *p0, const ppd_info_t *p1);
-int list_ppds(int request_id, int limit, const char *opt);
-int load_drivers(void);
-int load_ppds(const char *d, const char *p);
+ const char *device_id, time_t mtime, size_t size);
+static int cat_ppd(const char *name);
+static int compare_names(const ppd_info_t *p0,
+ const ppd_info_t *p1);
+static int compare_ppds(const ppd_info_t *p0,
+ const ppd_info_t *p1);
+static int list_ppds(int request_id, int limit, const char *opt);
+static int load_drivers(void);
+static int load_ppds(const char *d, const char *p);
/*
* 'add_ppd()' - Add a PPD file.
*/
-ppd_info_t * /* O - PPD */
+static ppd_info_t * /* O - PPD */
add_ppd(const char *name, /* I - PPD name */
const char *natural_language, /* I - Language(s) */
const char *make, /* I - Manufacturer */
const char *make_and_model, /* I - NickName */
+ const char *device_id, /* I - 1284DeviceID */
time_t mtime, /* I - Modification time */
size_t size) /* I - File size */
{
ppd_info_t *ppd; /* PPD */
+ char *recommended; /* Foomatic driver string */
/*
strlcpy(ppd->record.make, make, sizeof(ppd->record.make));
strlcpy(ppd->record.make_and_model, make_and_model,
sizeof(ppd->record.make_and_model));
+ strlcpy(ppd->record.device_id, device_id, sizeof(ppd->record.device_id));
+
+ /*
+ * Strip confusing (and often wrong) "recommended" suffix added by
+ * Foomatic drivers...
+ */
+
+ if ((recommended = strstr(ppd->record.make_and_model, " (recommended)")) != NULL)
+ *recommended = '\0';
/*
* Return the new PPD pointer...
* 'cat_ppd()' - Copy a PPD file to stdout.
*/
-int /* O - Exit code */
+static int /* O - Exit code */
cat_ppd(const char *name) /* I - PPD name */
{
char scheme[256], /* Scheme from PPD name */
* 'compare_names()' - Compare PPD filenames for sorting.
*/
-int /* O - Result of comparison */
+static int /* O - Result of comparison */
compare_names(const ppd_info_t *p0, /* I - First PPD file */
const ppd_info_t *p1) /* I - Second PPD file */
{
* 'compare_ppds()' - Compare PPD file make and model names for sorting.
*/
-int /* O - Result of comparison */
+static int /* O - Result of comparison */
compare_ppds(const ppd_info_t *p0, /* I - First PPD file */
const ppd_info_t *p1) /* I - Second PPD file */
{
int diff; /* Difference between strings */
+
/*
* First compare manufacturers...
*/
* 'list_ppds()' - List PPD files.
*/
-int /* O - Exit code */
+static int /* O - Exit code */
list_ppds(int request_id, /* I - Request ID */
int limit, /* I - Limit */
const char *opt) /* I - Option argument */
int send_natural_language, /* Send ppd-natural-language attribute? */
send_make, /* Send ppd-make attribute? */
send_make_and_model, /* Send ppd-make-and-model attribute? */
- send_name; /* Send ppd-name attribute? */
+ send_name, /* Send ppd-name attribute? */
+ send_device_id; /* Send ppd-device-id attribute? */
fprintf(stderr, "DEBUG2: [cups-driverd] list_ppds(request_id=%d, limit=%d, opt=\"%s\"\n",
if ((PPDs = malloc(sizeof(ppd_info_t) * NumPPDs)) == NULL)
{
- fprintf(stderr, "ERROR: [cups-driverd] Unable to allocate memory for %d PPD files!\n",
- NumPPDs);
+ fprintf(stderr,
+ "ERROR: [cups-driverd] Unable to allocate memory for %d "
+ "PPD files!\n", NumPPDs);
NumPPDs = 0;
AllocPPDs = 0;
}
* Add the raw driver...
*/
- add_ppd("raw", "en", "Raw", "Raw Queue", 0, 0);
+ add_ppd("raw", "en", "Raw", "Raw Queue", "", 0, 0);
/*
* Sort the PPDs by make and model...
send_make = 1;
send_make_and_model = 1;
send_natural_language = 1;
+ send_device_id = 1;
}
else
{
!strcmp(requested, "ppd-make");
send_make_and_model = strstr(requested, "ppd-make-and-model") != NULL;
send_natural_language = strstr(requested, "ppd-natural-language") != NULL;
+ send_device_id = strstr(requested, "ppd-device-id") != NULL;
}
puts("Content-Type: application/ipp\n");
cupsdSendIPPString(IPP_TAG_TEXT, "ppd-make-and-model",
ppd->record.make_and_model);
+ if (send_device_id)
+ cupsdSendIPPString(IPP_TAG_TEXT, "ppd-device-id",
+ ppd->record.device_id);
+
/*
* If we have only requested the ppd-make attribute, then skip
* the remaining PPDs with this make...
* 'load_ppds()' - Load PPD files recursively.
*/
-int /* O - 1 on success, 0 on failure */
+static int /* O - 1 on success, 0 on failure */
load_ppds(const char *d, /* I - Actual directory */
const char *p) /* I - Virtual path in name */
{
line[256], /* Line from backend */
*ptr, /* Pointer into name */
name[128], /* Name of PPD file */
- language[64], /* PPD language version */
+ lang_version[64], /* PPD LanguageVersion */
+ lang_encoding[64], /* PPD LanguageEncoding */
country[64], /* Country code */
manufacturer[256], /* Manufacturer */
make_model[256], /* Make and Model */
model_name[256], /* ModelName */
- nick_name[256]; /* NickName */
+ nick_name[256], /* NickName */
+ device_id[256]; /* 1284DeviceID */
ppd_info_t *ppd, /* New PPD file */
key; /* Search key */
int new_ppd; /* Is this a new PPD? */
{ "german", "de" },
{ "greek", "el" },
{ "italian", "it" },
- { "japanese", "jp" },
+ { "japanese", "ja" },
{ "norwegian", "no" },
{ "polish", "pl" },
{ "portuguese", "pt" },
while ((dent = cupsDirRead(dir)) != NULL)
{
+ /*
+ * Skip files/directories starting with "."...
+ */
+
+ if (dent->filename[0] == '.')
+ continue;
+
/*
* See if this is a file...
*/
* Now read until we get the NickName field...
*/
- model_name[0] = '\0';
- nick_name[0] = '\0';
- manufacturer[0] = '\0';
- strcpy(language, "en");
+ model_name[0] = '\0';
+ nick_name[0] = '\0';
+ manufacturer[0] = '\0';
+ device_id[0] = '\0';
+ lang_encoding[0] = '\0';
+ strcpy(lang_version, "en");
while (cupsFileGets(fp, line, sizeof(line)) != NULL)
{
sscanf(line, "%*[^\"]\"%255[^\"]", manufacturer);
else if (!strncmp(line, "*ModelName:", 11))
sscanf(line, "%*[^\"]\"%127[^\"]", model_name);
+ else if (!strncmp(line, "*LanguageEncoding:", 18))
+ sscanf(line, "%*[^:]:%63s", lang_encoding);
else if (!strncmp(line, "*LanguageVersion:", 17))
- sscanf(line, "%*[^:]:%63s", language);
+ sscanf(line, "%*[^:]:%63s", lang_version);
else if (!strncmp(line, "*NickName:", 10))
sscanf(line, "%*[^\"]\"%255[^\"]", nick_name);
+ else if (!strncasecmp(line, "*1284DeviceID:", 14))
+ sscanf(line, "%*[^\"]\"%255[^\"]", device_id);
else if (!strncmp(line, "*OpenUI", 7))
{
/*
if (model_name[0] || nick_name[0])
break;
}
-
- /*
- * Stop early if we have both the Manufacturer and NickName
- * attributes...
- */
-
- if (manufacturer[0] && nick_name[0])
- break;
}
/*
*/
if (nick_name[0])
- strcpy(make_model, nick_name);
+ cupsCharsetToUTF8((cups_utf8_t *)make_model, nick_name,
+ sizeof(make_model), _ppdGetEncoding(lang_encoding));
else
strcpy(make_model, model_name);
strcpy(manufacturer, "LHAG");
/*
- * Fix the language as needed...
+ * Fix the lang_version as needed...
*/
- if ((ptr = strchr(language, '-')) != NULL)
+ if ((ptr = strchr(lang_version, '-')) != NULL)
*ptr++ = '\0';
- else if ((ptr = strchr(language, '_')) != NULL)
+ else if ((ptr = strchr(lang_version, '_')) != NULL)
*ptr++ = '\0';
if (ptr)
}
for (i = 0; i < (int)(sizeof(languages) / sizeof(languages[0])); i ++)
- if (!strcasecmp(languages[i].version, language))
+ if (!strcasecmp(languages[i].version, lang_version))
break;
if (i < (int)(sizeof(languages) / sizeof(languages[0])))
* Found a known language...
*/
- snprintf(language, sizeof(language), "%s%s", languages[i].language,
- country);
+ snprintf(lang_version, sizeof(lang_version), "%s%s",
+ languages[i].language, country);
}
else
{
* Unknown language; use "xx"...
*/
- strcpy(language, "xx");
+ strcpy(lang_version, "xx");
}
/*
fprintf(stderr, "DEBUG: [cups-driverd] Adding ppd \"%s\"...\n", name);
- if (!add_ppd(name, language, manufacturer, make_model,
+ if (!add_ppd(name, lang_version, manufacturer, make_model, device_id,
dent->fileinfo.st_mtime, dent->fileinfo.st_size))
{
cupsDirClose(dir);
strlcpy(ppd->record.make, manufacturer, sizeof(ppd->record.make));
strlcpy(ppd->record.make_and_model, make_model,
sizeof(ppd->record.make_and_model));
- strlcpy(ppd->record.natural_language, language,
+ strlcpy(ppd->record.natural_language, lang_version,
sizeof(ppd->record.natural_language));
+ strlcpy(ppd->record.device_id, device_id, sizeof(ppd->record.device_id));
}
ChangedPPD = 1;
* 'load_drivers()' - Load driver-generated PPD files.
*/
-int /* O - 1 on success, 0 on failure */
+static int /* O - 1 on success, 0 on failure */
load_drivers(void)
{
const char *server_bin; /* CUPS_SERVERBIN environment variable */
name[512], /* ppd-name */
natural_language[128], /* ppd-natural-language */
make[128], /* ppd-make */
- make_and_model[256]; /* ppd-make-and-model */
+ make_and_model[256], /* ppd-make-and-model */
+ device_id[256]; /* ppd-device-id */
/*
* Run the driver with no arguments and collect the output...
*/
- snprintf(filename, sizeof(filename), "%s/%s", drivers, dent->filename);
+ snprintf(filename, sizeof(filename), "%s/%s list", drivers, dent->filename);
if ((fp = popen(filename, "r")) != NULL)
{
while (fgets(line, sizeof(line), fp) != NULL)
* \"ppd-name\" ppd-natural-language "ppd-make" "ppd-make-and-model"
*/
- if (sscanf(line, "\"%511[^\"]\"%127s%*[ \t]\"%127[^\"]\"%*[ \t]\"%256[^\"]\"",
- name, natural_language, make, make_and_model) != 4)
+ device_id[0] = '\0';
+
+ if (sscanf(line, "\"%511[^\"]\"%127s%*[ \t]\"%127[^\"]\""
+ "%*[ \t]\"%256[^\"]\"%*[ \t]\"%256[^\"]\"",
+ name, natural_language, make, make_and_model,
+ device_id) < 4)
{
/*
* Bad format; strip trailing newline and write an error message.
* Add the device to the array of available devices...
*/
- if (!add_ppd(name, natural_language, make, make_and_model, 0, 0))
+ if (!add_ppd(name, natural_language, make, make_and_model, device_id,
+ 0, 0))
{
cupsDirClose(dir);
return (0);
/*
- * End of "$Id: cups-driverd.c 4812 2005-10-25 18:23:10Z mike $".
+ * End of "$Id: cups-driverd.c 6363 2007-03-19 20:48:49Z mike $".
*/