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); }
static void show_all_printers(http_t *http, /* I - Connection to server */ const char *user) /* I - Username */ { int i; /* Looping var */ ipp_t *request, /* IPP request */ *response; /* IPP response */ cups_array_t *printers; /* Array of printer objects */ ipp_attribute_t *printer; /* Printer object */ int ascending, /* Order of printers (0 = descending) */ first, /* First printer to show */ count; /* Number of printers */ const char *var; /* Form variable */ void *search; /* Search data */ char val[1024]; /* Form variable */ fprintf(stderr, "DEBUG: show_all_printers(http=%p, user=\"%s\")\n", http, user ? user : "******"); /* * Show the standard header... */ cgiStartHTML(cgiText(_("Printers"))); /* * Build a CUPS_GET_PRINTERS request, which requires the following * attributes: * * attributes-charset * attributes-natural-language * printer-type * printer-type-mask * requesting-user-name */ request = ippNewRequest(CUPS_GET_PRINTERS); ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_ENUM, "printer-type", 0); ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_ENUM, "printer-type-mask", CUPS_PRINTER_CLASS); if (user) ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", NULL, user); cgiGetAttributes(request, "printers.tmpl"); /* * Do the request and get back a response... */ if ((response = cupsDoRequest(http, request, "/")) != NULL) { /* * Get a list of matching job objects. */ if ((var = cgiGetVariable("QUERY")) != NULL && !cgiGetVariable("CLEAR")) search = cgiCompileSearch(var); else search = NULL; printers = cgiGetIPPObjects(response, search); count = cupsArrayCount(printers); if (search) cgiFreeSearch(search); /* * Figure out which printers to display... */ if ((var = cgiGetVariable("FIRST")) != NULL) first = atoi(var); else first = 0; if (first >= count) first = count - CUPS_PAGE_MAX; first = (first / CUPS_PAGE_MAX) * CUPS_PAGE_MAX; if (first < 0) first = 0; sprintf(val, "%d", count); cgiSetVariable("TOTAL", val); if ((var = cgiGetVariable("ORDER")) != NULL && *var) ascending = !_cups_strcasecmp(var, "asc"); else ascending = 1; if (ascending) { for (i = 0, printer = (ipp_attribute_t *)cupsArrayIndex(printers, first); i < CUPS_PAGE_MAX && printer; i ++, printer = (ipp_attribute_t *)cupsArrayNext(printers)) cgiSetIPPObjectVars(printer, NULL, i); } else { for (i = 0, printer = (ipp_attribute_t *)cupsArrayIndex(printers, count - first - 1); i < CUPS_PAGE_MAX && printer; i ++, printer = (ipp_attribute_t *)cupsArrayPrev(printers)) cgiSetIPPObjectVars(printer, NULL, i); } /* * Save navigation URLs... */ cgiSetVariable("THISURL", "/printers/"); if (first > 0) { sprintf(val, "%d", first - CUPS_PAGE_MAX); cgiSetVariable("PREV", val); } if ((first + CUPS_PAGE_MAX) < count) { sprintf(val, "%d", first + CUPS_PAGE_MAX); cgiSetVariable("NEXT", val); } /* * Then show everything... */ cgiCopyTemplateLang("search.tmpl"); cgiCopyTemplateLang("printers-header.tmpl"); if (count > CUPS_PAGE_MAX) cgiCopyTemplateLang("pager.tmpl"); cgiCopyTemplateLang("printers.tmpl"); if (count > CUPS_PAGE_MAX) cgiCopyTemplateLang("pager.tmpl"); /* * Delete the response... */ cupsArrayDelete(printers); ippDelete(response); } else { /* * Show the error... */ cgiShowIPPError(_("Unable to get printer list")); } cgiEndHTML(); }
static void show_all_classes(http_t *http, /* I - Connection to server */ const char *user) /* I - Username */ { int i; /* Looping var */ ipp_t *request, /* IPP request */ *response; /* IPP response */ cups_array_t *classes; /* Array of class objects */ ipp_attribute_t *pclass; /* Class object */ int first, /* First class to show */ count; /* Number of classes */ const char *var; /* Form variable */ void *search; /* Search data */ char val[1024]; /* Form variable */ /* * Show the standard header... */ cgiStartHTML(cgiText(_("Classes"))); /* * Build a CUPS_GET_CLASSES request, which requires the following * attributes: * * attributes-charset * attributes-natural-language * requesting-user-name */ request = ippNewRequest(CUPS_GET_CLASSES); if (user) ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", NULL, user); cgiGetAttributes(request, "classes.tmpl"); /* * Do the request and get back a response... */ if ((response = cupsDoRequest(http, request, "/")) != NULL) { /* * Get a list of matching job objects. */ if ((var = cgiGetVariable("QUERY")) != NULL && !cgiGetVariable("CLEAR")) search = cgiCompileSearch(var); else search = NULL; classes = cgiGetIPPObjects(response, search); count = cupsArrayCount(classes); if (search) cgiFreeSearch(search); /* * Figure out which classes to display... */ if ((var = cgiGetVariable("FIRST")) != NULL) first = atoi(var); else first = 0; if (first >= count) first = count - CUPS_PAGE_MAX; first = (first / CUPS_PAGE_MAX) * CUPS_PAGE_MAX; if (first < 0) first = 0; sprintf(val, "%d", count); cgiSetVariable("TOTAL", val); for (i = 0, pclass = (ipp_attribute_t *)cupsArrayIndex(classes, first); i < CUPS_PAGE_MAX && pclass; i ++, pclass = (ipp_attribute_t *)cupsArrayNext(classes)) cgiSetIPPObjectVars(pclass, NULL, i); /* * Save navigation URLs... */ cgiSetVariable("THISURL", "/classes/"); if (first > 0) { sprintf(val, "%d", first - CUPS_PAGE_MAX); cgiSetVariable("PREV", val); } if ((first + CUPS_PAGE_MAX) < count) { sprintf(val, "%d", first + CUPS_PAGE_MAX); cgiSetVariable("NEXT", val); } if (count > CUPS_PAGE_MAX) { snprintf(val, sizeof(val), "%d", CUPS_PAGE_MAX * (count / CUPS_PAGE_MAX)); cgiSetVariable("LAST", val); } /* * Then show everything... */ cgiCopyTemplateLang("search.tmpl"); cgiCopyTemplateLang("classes-header.tmpl"); if (count > CUPS_PAGE_MAX) cgiCopyTemplateLang("pager.tmpl"); cgiCopyTemplateLang("classes.tmpl"); if (count > CUPS_PAGE_MAX) cgiCopyTemplateLang("pager.tmpl"); /* * Delete the response... */ cupsArrayDelete(classes); ippDelete(response); } else { /* * Show the error... */ cgiShowIPPError(_("Unable to get class list")); } cgiEndHTML(); }
int /* O - Exit code */ main(int argc, /* I - Number of command-line args */ char *argv[]) /* I - Command-line arguments */ { int i; /* Looping var */ cups_array_t *po; /* .po file */ _cups_message_t *msg; /* Current message */ cups_array_t *idfmts, /* Format strings in msgid */ *strfmts; /* Format strings in msgstr */ char *idfmt, /* Current msgid format string */ *strfmt; /* Current msgstr format string */ int fmtidx; /* Format index */ int status, /* Exit status */ pass, /* Pass/fail status */ untranslated; /* Untranslated messages */ char idbuf[80], /* Abbreviated msgid */ strbuf[80]; /* Abbreviated msgstr */ if (argc < 2) { puts("Usage: checkpo filename.po [... filenameN.po]"); return (1); } /* * Check every .po file on the command-line... */ for (i = 1, status = 0; i < argc; i ++) { /* * Use the CUPS .po loader to get the message strings... */ if ((po = _cupsMessageLoad(argv[i], 1)) == NULL) { perror(argv[i]); return (1); } if (i > 1) putchar('\n'); printf("%s: ", argv[i]); fflush(stdout); /* * Scan every message for a % string and then match them up with * the corresponding string in the translation... */ pass = 1; untranslated = 0; for (msg = (_cups_message_t *)cupsArrayFirst(po); msg; msg = (_cups_message_t *)cupsArrayNext(po)) { /* * Make sure filter message prefixes are not translated... */ if (!strncmp(msg->id, "ALERT:", 6) || !strncmp(msg->id, "CRIT:", 5) || !strncmp(msg->id, "DEBUG:", 6) || !strncmp(msg->id, "DEBUG2:", 7) || !strncmp(msg->id, "EMERG:", 6) || !strncmp(msg->id, "ERROR:", 6) || !strncmp(msg->id, "INFO:", 5) || !strncmp(msg->id, "NOTICE:", 7) || !strncmp(msg->id, "WARNING:", 8)) { if (pass) { pass = 0; puts("FAIL"); } printf(" Bad prefix on filter message \"%s\"\n", abbreviate(msg->id, idbuf, sizeof(idbuf))); } idfmt = msg->id + strlen(msg->id) - 1; if (idfmt >= msg->id && *idfmt == '\n') { if (pass) { pass = 0; puts("FAIL"); } printf(" Trailing newline in message \"%s\"\n", abbreviate(msg->id, idbuf, sizeof(idbuf))); } for (; idfmt >= msg->id; idfmt --) if (!isspace(*idfmt & 255)) break; if (idfmt >= msg->id && *idfmt == '!') { if (pass) { pass = 0; puts("FAIL"); } printf(" Exclamation in message \"%s\"\n", abbreviate(msg->id, idbuf, sizeof(idbuf))); } if ((idfmt - 2) >= msg->id && !strncmp(idfmt - 2, "...", 3)) { if (pass) { pass = 0; puts("FAIL"); } printf(" Ellipsis in message \"%s\"\n", abbreviate(msg->id, idbuf, sizeof(idbuf))); } if (!msg->str || !msg->str[0]) { untranslated ++; continue; } else if (strchr(msg->id, '%')) { idfmts = collect_formats(msg->id); strfmts = collect_formats(msg->str); fmtidx = 0; for (strfmt = (char *)cupsArrayFirst(strfmts); strfmt; strfmt = (char *)cupsArrayNext(strfmts)) { if (isdigit(strfmt[1] & 255) && strfmt[2] == '$') { /* * Handle positioned format stuff... */ fmtidx = strfmt[1] - '1'; strfmt += 3; if ((idfmt = (char *)cupsArrayIndex(idfmts, fmtidx)) != NULL) idfmt ++; } else { /* * Compare against the current format... */ idfmt = (char *)cupsArrayIndex(idfmts, fmtidx); } fmtidx ++; if (!idfmt || strcmp(strfmt, idfmt)) break; } if (cupsArrayCount(strfmts) != cupsArrayCount(idfmts) || strfmt) { if (pass) { pass = 0; puts("FAIL"); } printf(" Bad translation string \"%s\"\n for \"%s\"\n", abbreviate(msg->str, strbuf, sizeof(strbuf)), abbreviate(msg->id, idbuf, sizeof(idbuf))); fputs(" Translation formats:", stdout); for (strfmt = (char *)cupsArrayFirst(strfmts); strfmt; strfmt = (char *)cupsArrayNext(strfmts)) printf(" %s", strfmt); fputs("\n Original formats:", stdout); for (idfmt = (char *)cupsArrayFirst(idfmts); idfmt; idfmt = (char *)cupsArrayNext(idfmts)) printf(" %s", idfmt); putchar('\n'); putchar('\n'); } free_formats(idfmts); free_formats(strfmts); } /* * Only allow \\, \n, \r, \t, \", and \### character escapes... */ for (strfmt = msg->str; *strfmt; strfmt ++) if (*strfmt == '\\' && strfmt[1] != '\\' && strfmt[1] != 'n' && strfmt[1] != 'r' && strfmt[1] != 't' && strfmt[1] != '\"' && !isdigit(strfmt[1] & 255)) { if (pass) { pass = 0; puts("FAIL"); } printf(" Bad escape \\%c in filter message \"%s\"\n" " for \"%s\"\n", strfmt[1], abbreviate(msg->str, strbuf, sizeof(strbuf)), abbreviate(msg->id, idbuf, sizeof(idbuf))); break; } } if (pass) { if ((untranslated * 10) >= cupsArrayCount(po) && strcmp(argv[i], "cups.pot")) { /* * Only allow 10% of messages to be untranslated before we fail... */ pass = 0; puts("FAIL"); printf(" Too many untranslated messages (%d of %d)\n", untranslated, cupsArrayCount(po)); } else if (untranslated > 0) printf("PASS (%d of %d untranslated)\n", untranslated, cupsArrayCount(po)); else puts("PASS"); } if (!pass) status = 1; _cupsMessageFree(po); } return (status); }