| 2797 | */ |
| 2798 | |
| 2799 | int /* O - 1 if successful, 0 otherwise */ |
| 2800 | cupsdUpdatePrinterPPD( |
| 2801 | cupsd_printer_t *p, /* I - Printer */ |
| 2802 | int num_keywords, /* I - Number of keywords */ |
| 2803 | cups_option_t *keywords) /* I - Keywords */ |
| 2804 | { |
| 2805 | int i; /* Looping var */ |
| 2806 | cups_file_t *src, /* Original file */ |
| 2807 | *dst; /* New file */ |
| 2808 | char filename[1024], /* PPD filename */ |
| 2809 | line[1024], /* Line from file */ |
| 2810 | keystring[41]; /* Keyword from line */ |
| 2811 | cups_option_t *keyword; /* Current keyword */ |
| 2812 | |
| 2813 | |
| 2814 | cupsdLogMessage(CUPSD_LOG_INFO, "Updating keywords in PPD file for %s...", |
| 2815 | p->name); |
| 2816 | |
| 2817 | /* |
| 2818 | * Get the base PPD filename... |
| 2819 | */ |
| 2820 | |
| 2821 | snprintf(filename, sizeof(filename), "%s/ppd/%s.ppd", ServerRoot, p->name); |
| 2822 | |
| 2823 | /* |
| 2824 | * Open the old and new PPDs... |
| 2825 | */ |
| 2826 | |
| 2827 | if ((src = cupsdOpenConfFile(filename)) == NULL) |
| 2828 | return (0); |
| 2829 | |
| 2830 | if ((dst = cupsdCreateConfFile(filename, ConfigFilePerm)) == NULL) |
| 2831 | { |
| 2832 | cupsFileClose(src); |
| 2833 | return (0); |
| 2834 | } |
| 2835 | |
| 2836 | /* |
| 2837 | * Copy the first line and then write out all of the keywords... |
| 2838 | */ |
| 2839 | |
| 2840 | if (!cupsFileGets(src, line, sizeof(line))) |
| 2841 | { |
| 2842 | cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to read PPD file \"%s\": %s", filename, strerror(errno)); |
| 2843 | cupsFileClose(src); |
| 2844 | cupsFileClose(dst); |
| 2845 | return (0); |
| 2846 | } |
| 2847 | |
| 2848 | cupsFilePrintf(dst, "%s\n", line); |
| 2849 | |
| 2850 | for (i = num_keywords, keyword = keywords; i > 0; i --, keyword ++) |
| 2851 | { |
| 2852 | cupsdLogMessage(CUPSD_LOG_DEBUG, "*%s: %s", keyword->name, keyword->value); |
| 2853 | cupsFilePrintf(dst, "*%s: %s\n", keyword->name, keyword->value); |
| 2854 | } |
| 2855 | |
| 2856 | /* |
no test coverage detected