コード例 #1
0
ファイル: util.c プロジェクト: syedaunnraza/work
int					/* O - Number of jobs */
cupsGetJobs(cups_job_t **jobs,		/* O - Job data */
            const char *mydest,		/* I - NULL = all destinations,       *
	                                 *     otherwise show jobs for mydest */
            int        myjobs,		/* I - 0 = all users, 1 = mine */
            int        completed)	/* I - -1 = show all, 0 = active, *
	                                 *     1 = completed jobs         */
{
    _cups_globals_t *cg = _cupsGlobals();	/* Pointer to library globals */

    /*
     * Try to connect to the server...
     */

    if (!cups_connect("default", NULL, NULL))
    {
        DEBUG_puts("Unable to connect to server!");

        return (-1);
    }

    /*
     * Return the jobs...
     */

    return (cupsGetJobs2(cg->http, jobs, mydest, myjobs, completed));
}
コード例 #2
0
ファイル: util.c プロジェクト: syedaunnraza/work
const char *				/* O - Filename for PPD file */
cupsGetPPD(const char *name)		/* I - Printer name */
{
    _cups_globals_t *cg = _cupsGlobals();	/* Pointer to library globals */

    /*
     * See if we can connect to the server...
     */

    if (!cups_connect(name, NULL, NULL))
    {
        DEBUG_puts("Unable to connect to server!");

        return (NULL);
    }

    /*
     * Return the PPD file...
     */

    return (cupsGetPPD2(cg->http, name));
}
コード例 #3
0
ファイル: util.c プロジェクト: syedaunnraza/work
const char *				/* O - Default printer or NULL */
cupsGetDefault(void)
{
    const char	*var;			/* Environment variable */
    _cups_globals_t *cg = _cupsGlobals();	/* Pointer to library globals */


    /*
     * First see if the LPDEST or PRINTER environment variables are
     * set...  However, if PRINTER is set to "lp", ignore it to work
     * around a "feature" in most Linux distributions - the default
     * user login scripts set PRINTER to "lp"...
     */

    if ((var = getenv("LPDEST")) != NULL)
        return (var);
    else if ((var = getenv("PRINTER")) != NULL && strcmp(var, "lp") != 0)
        return (var);

    /*
     * Try to connect to the server...
     */

    if (!cups_connect("default", NULL, NULL))
    {
        DEBUG_puts("Unable to connect to server!");

        return (NULL);
    }

    /*
     * Return the default printer...
     */

    return (cupsGetDefault2(cg->http));
}
コード例 #4
0
ファイル: util.c プロジェクト: syedaunnraza/work
int					/* O - Job ID */
cupsPrintFiles(const char    *name,	/* I - Printer or class name */
               int           num_files,	/* I - Number of files */
               const char    **files,	/* I - File(s) to print */
               const char    *title,	/* I - Title of job */
               int           num_options,
               /* I - Number of options */
               cups_option_t *options)	/* I - Options */
{
    _cups_globals_t *cg = _cupsGlobals();	/* Pointer to library globals */

    DEBUG_printf(("cupsPrintFiles(name=\"%s\", num_files=%d, "
                  "files=%p, title=\"%s\", num_options=%d, options=%p)\n",
                  name, num_files, files, title, num_options, options));


    /*
     * Setup a connection and request data...
     */

    if (!cups_connect(name, NULL, NULL))
    {
        DEBUG_printf(("cupsPrintFiles: Unable to open connection - %s.\n",
                      strerror(errno)));
        DEBUG_puts("Unable to connect to server!");

        return (0);
    }

    /*
     * Print the file(s)...
     */

    return (cupsPrintFiles2(cg->http, name, num_files, files, title,
                            num_options, options));
}
コード例 #5
0
ファイル: util.c プロジェクト: syedaunnraza/work
int					/* O - Number of printers */
cupsGetPrinters(char ***printers)	/* O - Printers */
{
    int		n;			/* Number of printers */
    ipp_t		*request,		/* IPP Request */
                *response;		/* IPP Response */
    ipp_attribute_t *attr;		/* Current attribute */
    char		**temp;			/* Temporary pointer */
    _cups_globals_t *cg = _cupsGlobals();	/* Pointer to library globals */


    if (printers == NULL)
    {
        _cupsSetError(IPP_INTERNAL_ERROR, NULL);

        return (0);
    }

    /*
     * Try to connect to the server...
     */

    if (!cups_connect("default", NULL, NULL))
    {
        DEBUG_puts("Unable to connect to server!");

        return (0);
    }

    /*
     * Build a CUPS_GET_PRINTERS request, which requires the following
     * attributes:
     *
     *    attributes-charset
     *    attributes-natural-language
     *    requested-attributes
     */

    request = ippNewRequest(CUPS_GET_PRINTERS);

    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
                 "requested-attributes", NULL, "printer-name");

    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);

    /*
     * Do the request and get back a response...
     */

    n         = 0;
    *printers = NULL;

    if ((response = cupsDoRequest(cg->http, request, "/")) != NULL)
    {
        for (attr = response->attrs; attr != NULL; attr = attr->next)
            if (attr->name != NULL &&
                    strcasecmp(attr->name, "printer-name") == 0 &&
                    attr->value_tag == IPP_TAG_NAME)
            {
                if (n == 0)
                    temp = malloc(sizeof(char *));
                else
                    temp = realloc(*printers, sizeof(char *) * (n + 1));

                if (temp == NULL)
                {
                    /*
                     * Ran out of memory!
                     */

                    while (n > 0)
                    {
                        n --;
                        free((*printers)[n]);
                    }

                    free(*printers);
                    ippDelete(response);
                    return (0);
                }

                *printers = temp;
                temp[n]   = strdup(attr->values[0].string.text);
                n ++;
            }

        ippDelete(response);
    }

    return (n);
}
コード例 #6
0
ファイル: util.c プロジェクト: syedaunnraza/work
int					/* O - 1 on success, 0 on failure */
cupsCancelJob(const char *name,		/* I - Name of printer or class */
              int        job)		/* I - Job ID */
{
    char		printer[HTTP_MAX_URI],	/* Printer name */
                hostname[HTTP_MAX_URI],	/* Hostname */
                uri[HTTP_MAX_URI];	/* Printer URI */
    ipp_t		*request,		/* IPP request */
                *response;		/* IPP response */
    _cups_globals_t *cg = _cupsGlobals();	/* Pointer to library globals */


    /*
     * See if we can connect to the server...
     */

    if (!cups_connect(name, printer, hostname))
    {
        DEBUG_puts("Unable to connect to server!");

        return (0);
    }

    /*
     * Create a printer URI...
     */

    if (httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
                         "localhost", 0, "/printers/%s", printer) != HTTP_URI_OK)
    {
        _cupsSetError(IPP_INTERNAL_ERROR, NULL);

        return (0);
    }

    /*
     * Build an IPP_CANCEL_JOB request, which requires the following
     * attributes:
     *
     *    attributes-charset
     *    attributes-natural-language
     *    printer-uri
     *    job-id
     *    [requesting-user-name]
     */

    request = ippNewRequest(IPP_CANCEL_JOB);

    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
                 NULL, uri);

    ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "job-id", job);

    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
                 NULL, cupsUser());

    /*
     * Do the request...
     */

    if ((response = cupsDoRequest(cg->http, request, "/jobs/")) != NULL)
        ippDelete(response);

    return (cg->last_error < IPP_REDIRECTION_OTHER_SITE);
}
コード例 #7
0
ファイル: print_cups.c プロジェクト: gojdic/samba
static bool cups_cache_reload_async(int fd)
{
	TALLOC_CTX *frame = talloc_stackframe();
	struct pcap_cache *tmp_pcap_cache = NULL;
	http_t		*http = NULL;		/* HTTP connection to server */
	ipp_t		*request = NULL,	/* IPP Request */
			*response = NULL;	/* IPP Response */
	ipp_attribute_t	*attr;		/* Current attribute */
	cups_lang_t	*language = NULL;	/* Default language */
	char		*name,		/* printer-name attribute */
			*info;		/* printer-info attribute */
	static const char *requested[] =/* Requested attributes */
			{
			  "printer-name",
			  "printer-info"
			};
	bool ret = False;
	size_t size;

	DEBUG(5, ("reloading cups printcap cache\n"));

       /*
        * Make sure we don't ask for passwords...
	*/

        cupsSetPasswordCB(cups_passwd_cb);

       /*
	* Try to connect to the server...
	*/

	if ((http = cups_connect(frame)) == NULL) {
		goto out;
	}

       /*
	* Build a CUPS_GET_PRINTERS request, which requires the following
	* attributes:
	*
	*    attributes-charset
	*    attributes-natural-language
	*    requested-attributes
	*/

	request = ippNew();

	request->request.op.operation_id = CUPS_GET_PRINTERS;
	request->request.op.request_id   = 1;

	language = cupsLangDefault();

	ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
                     "attributes-charset", NULL, "utf-8");

	ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
                     "attributes-natural-language", NULL, language->language);

        ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
	              "requested-attributes",
		      (sizeof(requested) / sizeof(requested[0])),
		      NULL, requested);

       /*
	* Do the request and get back a response...
	*/

	if ((response = cupsDoRequest(http, request, "/")) == NULL) {
		DEBUG(0,("Unable to get printer list - %s\n",
			 ippErrorString(cupsLastError())));
		goto out;
	}

	for (attr = response->attrs; attr != NULL;) {
	       /*
		* Skip leading attributes until we hit a printer...
		*/

		while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
			attr = attr->next;

		if (attr == NULL)
        		break;

	       /*
		* Pull the needed attributes from this printer...
		*/

		name       = NULL;
		info       = NULL;

		while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) {
        		if (strcmp(attr->name, "printer-name") == 0 &&
			    attr->value_tag == IPP_TAG_NAME) {
				if (!pull_utf8_talloc(frame,
						&name,
						attr->values[0].string.text,
						&size)) {
					goto out;
				}
			}

        		if (strcmp(attr->name, "printer-info") == 0 &&
			    attr->value_tag == IPP_TAG_TEXT) {
				if (!pull_utf8_talloc(frame,
						&info,
						attr->values[0].string.text,
						&size)) {
					goto out;
				}
			}

        		attr = attr->next;
		}

	       /*
		* See if we have everything needed...
		*/

		if (name == NULL)
			break;

		if (!pcap_cache_add_specific(&tmp_pcap_cache, name, info)) {
			goto out;
		}
	}

	ippDelete(response);
	response = NULL;

       /*
	* Build a CUPS_GET_CLASSES request, which requires the following
	* attributes:
	*
	*    attributes-charset
	*    attributes-natural-language
	*    requested-attributes
	*/

	request = ippNew();

	request->request.op.operation_id = CUPS_GET_CLASSES;
	request->request.op.request_id   = 1;

	ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
                     "attributes-charset", NULL, "utf-8");

	ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
                     "attributes-natural-language", NULL, language->language);

        ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
	              "requested-attributes",
		      (sizeof(requested) / sizeof(requested[0])),
		      NULL, requested);

       /*
	* Do the request and get back a response...
	*/

	if ((response = cupsDoRequest(http, request, "/")) == NULL) {
		DEBUG(0,("Unable to get printer list - %s\n",
			 ippErrorString(cupsLastError())));
		goto out;
	}

	for (attr = response->attrs; attr != NULL;) {
	       /*
		* Skip leading attributes until we hit a printer...
		*/

		while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
			attr = attr->next;

		if (attr == NULL)
        		break;

	       /*
		* Pull the needed attributes from this printer...
		*/

		name       = NULL;
		info       = NULL;

		while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) {
        		if (strcmp(attr->name, "printer-name") == 0 &&
			    attr->value_tag == IPP_TAG_NAME) {
				if (!pull_utf8_talloc(frame,
						&name,
						attr->values[0].string.text,
						&size)) {
					goto out;
				}
			}

        		if (strcmp(attr->name, "printer-info") == 0 &&
			    attr->value_tag == IPP_TAG_TEXT) {
				if (!pull_utf8_talloc(frame,
						&info,
						attr->values[0].string.text,
						&size)) {
					goto out;
				}
			}

        		attr = attr->next;
		}

	       /*
		* See if we have everything needed...
		*/

		if (name == NULL)
			break;

		if (!pcap_cache_add_specific(&tmp_pcap_cache, name, info)) {
			goto out;
		}
	}

	ret = True;

 out:
	if (response)
		ippDelete(response);

	if (language)
		cupsLangFree(language);

	if (http)
		httpClose(http);

	/* Send all the entries up the pipe. */
	if (tmp_pcap_cache) {
		pcap_printer_fn_specific(tmp_pcap_cache,
				send_pcap_info,
				(void *)&fd);

		pcap_cache_destroy_specific(&tmp_pcap_cache);
	}
	TALLOC_FREE(frame);
	return ret;
}