Пример #1
0
void init_direct(list_t *arglist, dstr_t *filelist, jobparams_t *job)
{
    char tmp [1024];
    listitem_t *i;
    char user_default_path [PATH_MAX];

    strlcpy(user_default_path, getenv("HOME"), 256);
    strlcat(user_default_path, "/.foomatic/", 256);

    /* Which files do we want to print? */
    for (i = arglist->first; i; i = i->next) {
        strncpy_omit(tmp, (char*)i->data, 1024, omit_shellescapes);
        dstrcatf(filelist, "%s ", tmp);
    }

    if (job->ppdfile[0] == '\0') {
        if (job->printer[0] == '\0') {
            /* No printer definition file selected, check whether we have a
               default printer defined */
            find_default_printer(user_default_path, job);
        }

        /* Neither in a config file nor on the command line a printer was selected */
        if (!job->printer[0]) {
            _log("No printer definition (option \"-P <name>\") specified!\n");
            exit(EXIT_PRNERR_NORETRY_BAD_SETTINGS);
        }

        /* Search for the PPD file */
        if (!find_ppdfile(user_default_path, job)) {
            _log("There is no readable PPD file for the printer %s, is it configured?\n", job->printer);
            exit(EXIT_PRNERR_NORETRY_BAD_SETTINGS);
        }
    }
}
Пример #2
0
void init_solaris(list_t *arglist, dstr_t *filelist, jobparams_t *job)
{
    char *str;
    int len;
    listitem_t *i;

    /* Get all command line parameters */
    strncpy_omit(job->title, arglist_get(arglist, 2), 128, omit_shellescapes);

    len = strlen(arglist_get(arglist, 4));
    str = malloc(len +1);
    strncpy_omit(str, arglist_get(arglist, 4), len, omit_shellescapes);
    dstrcatf(job->optstr, " %s", str);
    free(str);

    for (i = arglist->first; i; i = i->next)
        dstrcatf(filelist, "%s ", (char*)i->data);
}
Пример #3
0
void init_cups(list_t *arglist, dstr_t *filelist, jobparams_t *job)
{
    char path [PATH_MAX] = "";
    char cups_jobid [128];
    char cups_user [128];
    char cups_jobtitle [128];
    char cups_copies [128];
    int cups_options_len;
    char *cups_options;
    char cups_filename [256];

    if (getenv("CUPS_FONTPATH"))
        strncpy(path, getenv("CUPS_FONTPATH"), PATH_MAX - 1);
    else if (getenv("CUPS_DATADIR")) {
       strncpy(path, getenv("CUPS_DATADIR"), PATH_MAX - 1);
       strncat(path, "/fonts", PATH_MAX - strlen(path) - 1);
    }
    if (getenv("GS_LIB")) {
        strncat(path, ":", PATH_MAX - strlen(path) - 1);
        strncat(path, getenv("GS_LIB"), PATH_MAX - strlen(path) - 1);
    }
    setenv("GS_LIB", path, 1);

    /* Get all command line parameters */
    strncpy_omit(cups_jobid, arglist_get(arglist, 0), 128, omit_shellescapes);
    strncpy_omit(cups_user, arglist_get(arglist, 1), 128, omit_shellescapes);
    strncpy_omit(cups_jobtitle, arglist_get(arglist, 2), 128, omit_shellescapes);
    strncpy_omit(cups_copies, arglist_get(arglist, 3), 128, omit_shellescapes);

    cups_options_len = strlen(arglist_get(arglist, 4));
    cups_options = malloc(cups_options_len + 1);
    strncpy_omit(cups_options, arglist_get(arglist, 4), cups_options_len + 1, omit_shellescapes);

    /* Common job parameters */
    strcpy(job->id, cups_jobid);
    strcpy(job->title, cups_jobtitle);
    strcpy(job->user, cups_user);
    strcpy(job->copies, cups_copies);
    dstrcatf(job->optstr, " %s", cups_options);

    /* Check for and handle inputfile vs stdin */
    if (list_item_count(arglist) > 4) {
        strncpy_omit(cups_filename, arglist_get(arglist, 5), 256, omit_shellescapes);
        if (cups_filename[0] != '-') {
            /* We get input from a file */
            dstrcatf(filelist, "%s ", cups_filename);
            _log("Getting input from file %s\n", cups_filename);
        }
    }

    accounting_prolog = accounting_prolog_code;

    /* On which queue are we printing?
       CUPS gives the PPD file the same name as the printer queue,
       so we can get the queue name from the name of the PPD file. */
    file_basename(job->printer, job->ppdfile, 256);

    free(cups_options);
}
Пример #4
0
/* search 'configfile' for 'key', copy value into dest, return success */
int configfile_find_option(const char *configfile, const char *key, char *dest, size_t destsize)
{
    FILE *fh;
    char line [1024];
    char *p;

    dest[0] = '\0';

    if (!(fh = fopen(configfile, "r")))
        return 0;

    while (fgets(line, 1024, fh)) {
        if (!prefixcmp(line, "default")) {
            p = strchr(line, ':');
            if (p) {
                strncpy_omit(dest, p + 1, destsize, omit_whitespace_newline);
                if (dest[0])
                    break;
            }
        }
    }
    fclose(fh);
    return dest[0] != '\0';
}
Пример #5
0
void init_cups(list_t *arglist, dstr_t *filelist, jobparams_t *job)
{
    char path [1024] = "";
    char cups_jobid [128];
    char cups_user [128];
    char cups_jobtitle [128];
    char cups_copies [128];
    int cups_options_len;
    char *cups_options;
    char cups_filename [256];
    char texttopspath[PATH_MAX];

    if (getenv("CUPS_FONTPATH"))
        strcpy(path, getenv("CUPS_FONTPATH"));
    else if (getenv("CUPS_DATADIR")) {
        strcpy(path, getenv("CUPS_DATADIR"));
        strcat(path, "/fonts");
    }
    if (getenv("GS_LIB")) {
        strcat(path, ":");
        strcat(path, getenv("GS_LIB"));
    }
    setenv("GS_LIB", path, 1);

    /* Get all command line parameters */
    strncpy_omit(cups_jobid, arglist_get(arglist, 0), 128, omit_shellescapes);
    strncpy_omit(cups_user, arglist_get(arglist, 1), 128, omit_shellescapes);
    strncpy_omit(cups_jobtitle, arglist_get(arglist, 2), 128, omit_shellescapes);
    strncpy_omit(cups_copies, arglist_get(arglist, 3), 128, omit_shellescapes);

    cups_options_len = strlen(arglist_get(arglist, 4));
    cups_options = malloc(cups_options_len + 1);
    strncpy_omit(cups_options, arglist_get(arglist, 4), cups_options_len + 1, omit_shellescapes);

    /* Common job parameters */
    strcpy(job->id, cups_jobid);
    strcpy(job->title, cups_jobtitle);
    strcpy(job->user, cups_user);
    strcpy(job->copies, cups_copies);
    dstrcatf(job->optstr, " %s", cups_options);

    /* Check for and handle inputfile vs stdin */
    if (list_item_count(arglist) > 4) {
        strncpy_omit(cups_filename, arglist_get(arglist, 5), 256, omit_shellescapes);
        if (cups_filename[0] != '-') {
            /* We get input from a file */
            dstrcatf(filelist, "%s ", cups_filename);
            _log("Getting input from file %s\n", cups_filename);
        }
    }

    accounting_prolog = accounting_prolog_code;

    /* On which queue are we printing?
       CUPS gives the PPD file the same name as the printer queue,
       so we can get the queue name from the name of the PPD file. */
    file_basename(job->printer, job->ppdfile, 256);

    /* Use cups' texttops if no fileconverter is set
     * Apply "pstops" when having used a file converter under CUPS, so CUPS
     * can stuff the default settings into the PostScript output of the file
     * converter (so all CUPS settings get also applied when one prints the
     * documentation pages (all other files we get already converted to
     * PostScript by CUPS). */
    if (isempty(fileconverter)) {
        if (find_in_path("texttops", cupsfilterpath, texttopspath)) {
            snprintf(fileconverter, PATH_MAX, "%s/texttops '%s' '%s' '%s' '%s' "
                    "page-top=36 page-bottom=36 page-left=36 page-right=36 "
                    "nolandscape cpi=12 lpi=7 columns=1 wrap %s'"
                    "| %s/pstops  '%s' '%s' '%s' '%s' '%s'",
                    texttopspath, cups_jobid, cups_user, cups_jobtitle, cups_copies, cups_options,
                    texttopspath, cups_jobid, cups_user, cups_jobtitle, cups_copies, cups_options);
        }
    }

    free(cups_options);
}
Пример #6
0
void init_ppr(list_t *arglist, jobparams_t *job)
{
    size_t arg_count = list_item_count(arglist);
    char ppr_printer [256];
    char ppr_address [128];
    char ppr_options [1024];
    char ppr_jobbreak [128];
    char ppr_feedback [128];
    char ppr_codes [128];
    char ppr_jobname [128];
    char ppr_routing [128];
    char ppr_for [128] = "";
    char ppr_filetype [128] = "";
    char ppr_filetoprint [128] = "";
    FILE *ph;
    char tmp[256];
    char *p;


    /* TODO read interface.sh and signal.sh for exit and signal codes respectively */

    /* Check whether we run as a PPR interface (if not, we run as a PPR RIP)
       PPR calls interfaces with many command line parameters,
       where the forth and the sixth is a small integer
       number. In addition, we have 8 (PPR <= 1.31), 10
       (PPR>=1.32), 11 (PPR >= 1.50) command line parameters.
       We also check whether the current working directory is a
       PPR directory. */
    if ((arg_count == 11 || arg_count == 10 || arg_count == 8) &&
        atoi(arglist_get(arglist, 3)) < 100 && atoi(arglist_get(arglist, 5)) < 100)
    {
        /* get all command line parameters */
        strncpy_omit(ppr_printer, arglist_get(arglist, 0), 256, omit_shellescapes);
        strlcpy(ppr_address, arglist_get(arglist, 1), 128);
        strncpy_omit(ppr_options, arglist_get(arglist, 2), 1024, omit_shellescapes);
        strlcpy(ppr_jobbreak, arglist_get(arglist, 3), 128);
        strlcpy(ppr_feedback, arglist_get(arglist, 4), 128);
        strlcpy(ppr_codes, arglist_get(arglist, 5), 128);
        strncpy_omit(ppr_jobname, arglist_get(arglist, 6), 128, omit_shellescapes);
        strncpy_omit(ppr_routing, arglist_get(arglist, 7), 128, omit_shellescapes);
        if (arg_count >= 8) {
            strlcpy(ppr_for, arglist_get(arglist, 8), 128);
            strlcpy(ppr_filetype, arglist_get(arglist, 9), 128);
            if (arg_count >= 10)
                strncpy_omit(ppr_filetoprint, arglist_get(arglist, 10), 128, omit_shellescapes);
        }

        /* Common job parameters */
        strcpy(job->printer, ppr_printer);
        strcpy(job->title, ppr_jobname);
        if (isempty(job->title) && !isempty(ppr_filetoprint))
            strcpy(job->title, ppr_filetoprint);
        dstrcatf(job->optstr, " %s %s", ppr_options, ppr_routing);

        /* Get the path of the PPD file from the queue configuration */
        snprintf(tmp, 255, "LANG=en_US; ppad show %s | grep PPDFile", ppr_printer);
        tmp[255] = '\0';
        ph = popen(tmp, "r");
        if (ph) {
            fgets(tmp, 255, ph);
            tmp[255] = '\0';
            pclose(ph);

            strncpy_omit(job->ppdfile, tmp, 255, omit_shellescapes);
            if (job->ppdfile[0] == '/') {
                strcpy(tmp, job->ppdfile);
                strcpy(job->ppdfile, "../../share/ppr/PPDFiles/");
                strncat(job->ppdfile, tmp, 200);
            }
            if ((p = strrchr(job->ppdfile, '\n')))
                *p = '\0';
        }
        else {
            job->ppdfile[0] = '\0';
        }

        /* We have PPR and run as an interface */
        spooler = SPOOLER_PPR_INT;
    }
}