本文整理汇总了C++中cupsDoRequest函数的典型用法代码示例。如果您正苦于以下问题:C++ cupsDoRequest函数的具体用法?C++ cupsDoRequest怎么用?C++ cupsDoRequest使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cupsDoRequest函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: delete_printer_from_class
static int /* O - 0 on success, 1 on fail */
delete_printer_from_class(
http_t *http, /* I - Server connection */
char *printer, /* I - Printer to remove */
char *pclass) /* I - Class to remove from */
{
int i, j, k; /* Looping vars */
ipp_t *request, /* IPP Request */
*response; /* IPP Response */
ipp_attribute_t *attr, /* Current attribute */
*members; /* Members in class */
char uri[HTTP_MAX_URI]; /* URI for printer/class */
DEBUG_printf(("delete_printer_from_class(%p, \"%s\", \"%s\")\n", http,
printer, pclass));
/*
* Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the following
* attributes:
*
* attributes-charset
* attributes-natural-language
* printer-uri
* requesting-user-name
*/
request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
"localhost", 0, "/classes/%s", pclass);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
"printer-uri", NULL, uri);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
NULL, cupsUser());
/*
* Do the request and get back a response...
*/
if ((response = cupsDoRequest(http, request, "/classes/")) == NULL ||
response->request.status.status_code == IPP_NOT_FOUND)
{
_cupsLangPrintf(stderr, _("%s: %s"), "lpadmin", cupsLastErrorString());
ippDelete(response);
return (1);
}
/*
* See if the printer is already in the class...
*/
if ((members = ippFindAttribute(response, "member-names", IPP_TAG_NAME)) == NULL)
{
_cupsLangPuts(stderr, _("lpadmin: No member names were seen."));
ippDelete(response);
return (1);
}
for (i = 0; i < members->num_values; i ++)
if (!_cups_strcasecmp(printer, members->values[i].string.text))
break;
if (i >= members->num_values)
{
_cupsLangPrintf(stderr,
_("lpadmin: Printer %s is not a member of class %s."),
printer, pclass);
ippDelete(response);
return (1);
}
if (members->num_values == 1)
{
/*
* Build a CUPS_DELETE_CLASS request, which requires the following
* attributes:
*
* attributes-charset
* attributes-natural-language
* printer-uri
* requesting-user-name
*/
request = ippNewRequest(CUPS_DELETE_CLASS);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
"printer-uri", NULL, uri);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
"requesting-user-name", NULL, cupsUser());
}
else
{
/*
//.........这里部分代码省略.........
开发者ID:thangap,项目名称:tizen-release,代码行数:101,代码来源:lpadmin.c
示例2: iprint_get_server_version
static int iprint_get_server_version(http_t *http, char* serviceUri)
{
ipp_t *request = NULL, /* IPP Request */
*response = NULL; /* IPP Response */
ipp_attribute_t *attr; /* Current attribute */
cups_lang_t *language = NULL; /* Default language */
char *ver; /* server version pointer */
char *vertmp; /* server version tmp pointer */
int serverVersion = 0; /* server version */
char *os; /* server os */
int osFlag = 0; /* 0 for NetWare, 1 for anything else */
char *temp; /* pointer for string manipulation */
/*
* Build an OPERATION_NOVELL_MGMT("get-server-version") request,
* which requires the following attributes:
*
* attributes-charset
* attributes-natural-language
* operation-name
* service-uri
*/
request = ippNew();
ippSetOperation(request, (ipp_op_t)OPERATION_NOVELL_MGMT);
ippSetRequestId(request, 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);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
"service-uri", NULL, serviceUri);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
"operation-name", NULL, "get-server-version");
/*
* Do the request and get back a response...
*/
if (((response = cupsDoRequest(http, request, "/ipp/")) == NULL) ||
(ippGetStatusCode(response) >= IPP_OK_CONFLICT))
goto out;
if (((attr = ippFindAttribute(response, "server-version",
IPP_TAG_STRING)) != NULL)) {
if ((ver = strstr(ippGetString(attr, 0, NULL),
NOVELL_SERVER_VERSION_STRING)) != NULL) {
ver += strlen(NOVELL_SERVER_VERSION_STRING);
/*
* Strangely, libcups stores a IPP_TAG_STRING (octet
* string) as a null-terminated string with no length
* even though it could be binary data with nulls in
* it. Luckily, in this case the value is not binary.
*/
serverVersion = strtol(ver, &vertmp, 10);
/* Check for not found, overflow or negative version */
if ((ver == vertmp) || (serverVersion < 0))
serverVersion = 0;
}
if ((os = strstr(ippGetString(attr, 0, NULL),
NOVELL_SERVER_SYSNAME)) != NULL) {
os += strlen(NOVELL_SERVER_SYSNAME);
if ((temp = strchr(os,'<')) != NULL)
*temp = '\0';
if (strcmp(os,NOVELL_SERVER_SYSNAME_NETWARE))
osFlag = 1; /* 1 for non-NetWare systems */
}
}
out:
if (response)
ippDelete(response);
if (language)
cupsLangFree(language);
if (osFlag == 0)
serverVersion *= -1;
return serverVersion;
}
开发者ID:arthur-zhang,项目名称:android_samba,代码行数:90,代码来源:print_iprint.c
示例3: iprint_cache_reload
bool iprint_cache_reload(void)
{
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 */
int i;
bool ret = False;
DEBUG(5, ("reloading iprint printcap cache\n"));
/*
* Make sure we don't ask for passwords...
*/
cupsSetPasswordCB(iprint_passwd_cb);
/*
* Try to connect to the server...
*/
if ((http = httpConnect(iprint_server(), ippPort())) == NULL) {
DEBUG(0,("Unable to connect to iPrint server %s - %s\n",
iprint_server(), strerror(errno)));
goto out;
}
/*
* Build a OPERATION_NOVELL_LIST_PRINTERS request, which requires the following attributes:
*
* attributes-charset
* attributes-natural-language
*/
request = ippNew();
ippSetOperation(request, (ipp_op_t)OPERATION_NOVELL_LIST_PRINTERS);
ippSetRequestId(request, 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);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
"ipp-server", NULL, "ippSrvr");
/*
* Do the request and get back a response...
*/
if ((response = cupsDoRequest(http, request, "/ipp")) == NULL) {
DEBUG(0,("Unable to get printer list - %s\n",
ippErrorString(cupsLastError())));
goto out;
}
for (attr = ippFirstAttribute(response); attr != NULL;) {
/*
* Skip leading attributes until we hit a printer...
*/
while (attr != NULL && ippGetGroupTag(attr) != IPP_TAG_PRINTER)
attr = ippNextAttribute(response);
if (attr == NULL)
break;
/*
* Pull the needed attributes from this printer...
*/
while (attr != NULL && ippGetGroupTag(attr) == IPP_TAG_PRINTER)
{
if (strcmp(ippGetName(attr), "printer-name") == 0 &&
(ippGetValueTag(attr) == IPP_TAG_URI ||
ippGetValueTag(attr) == IPP_TAG_NAME ||
ippGetValueTag(attr) == IPP_TAG_TEXT ||
ippGetValueTag(attr) == IPP_TAG_NAMELANG ||
ippGetValueTag(attr) == IPP_TAG_TEXTLANG))
{
for (i = 0; i<ippGetCount(attr); i++)
{
char *url = ippGetString(attr, i, NULL);
if (!url || !strlen(url))
continue;
iprint_cache_add_printer(http, i+2, url);
}
}
attr = ippNextAttribute(response);
}
}
ret = True;
out:
//.........这里部分代码省略.........
开发者ID:arthur-zhang,项目名称:android_samba,代码行数:101,代码来源:print_iprint.c
示例4: removeJob
///////////////////////////////////////////////////////////////////////////////////////////
//
// CS : PUBLIC gint removeJob(gchar *pDestName)
// IN : gchar *pDestName : Printer name.
// OUT : None.
// RETURN : ID_ERR_NO_ERROR : No error.
// ID_ERR_CUPS_API_FAILED : Error occured in CUPS API.
//
PUBLIC gint removeJob(gchar *pDestName)
{
/*** Parameters start ***/
http_t *pHTTP; // Pointer to HTTP connection.
ipp_t *pRequest, // Pointer to CUPS IPP request.
*pResponse; // Pointer to CUPS IPP response.
cups_lang_t *pLanguage; // Pointer to language.
gchar printerURI[HTTP_MAX_URI]; // Printer URI.
gchar serverName[HTTP_MAX_URI]; // CUPS server name.
gint jobID = 0; // Job ID.
gint retVal = ID_ERR_NO_ERROR; // Return value.
/*** Parameters end ***/
// Initialize buffer.
memset(printerURI, 0, sizeof(printerURI));
memset(serverName, 0, sizeof(serverName));
// Get printer URI and CUPS server name.
retVal = getPrinterURI(pDestName, printerURI, serverName, HTTP_MAX_URI);
if (retVal == ID_ERR_NO_ERROR) {
retVal = getJobID(pDestName, printerURI, serverName, &jobID);
if (retVal == ID_ERR_PRINT_JOB_NOT_EXIST) {
retVal = ID_ERR_NO_ERROR;
}
if (retVal == ID_ERR_NO_ERROR) {
// CUPS http connect.
if ((pHTTP = httpConnectEncrypt(serverName, ippPort(), cupsEncryption())) == NULL) {
retVal = ID_ERR_CUPS_API_FAILED;
}
else {
pRequest = ippNew();
ippSetOperation(pRequest, IPP_CANCEL_JOB);
ippSetRequestId(pRequest, 1);
pLanguage = bjcupsLangDefault(); // cupsLangDefault() -> bjcupsLangDefault() for cups-1.1.19
ippAddString(pRequest, IPP_TAG_OPERATION, IPP_TAG_CHARSET, "attributes-charset", NULL, cupsLangEncoding(pLanguage));
ippAddString(pRequest, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, "attributes-natural-language", NULL, pLanguage->language);
ippAddString(pRequest, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, printerURI);
ippAddInteger(pRequest, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "job-id", jobID);
ippAddString(pRequest, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", NULL, cupsUser());
if ((pResponse = cupsDoRequest(pHTTP, pRequest, "/jobs/")) != NULL) {
if (ippGetStatusCode(pResponse) > IPP_OK_CONFLICT) {
retVal = ID_ERR_CUPS_API_FAILED;
}
ippDelete(pResponse);
}
else {
retVal = ID_ERR_CUPS_API_FAILED;
}
cupsLangFree(pLanguage);
httpClose(pHTTP);
}
}
}
return(retVal);
}// End removeJob
开发者ID:Magister,项目名称:bjcups-2.50,代码行数:70,代码来源:bjcupsmon_cups.c
示例5: getJobID
///////////////////////////////////////////////////////////////////////////////////////////
//
// CS : PRIVATE gint getJobID(gchar *pDestName, gchar *pURI, gchar *pServerName, gint *pJobID)
// IN : gchar *pDestName : Printer name.
// gchar *pURI : Printer URI.
// gchar *pServerName : CUPS server name.
// OUT : gint *pJobID : Job ID.
// RETURN : ID_ERR_NO_ERROR : No error.
// ID_ERR_CUPS_API_FAILED : Error occured in CUPS API.
//
PRIVATE gint getJobID(gchar *pDestName, gchar *pURI, gchar *pServerName, gint *pJobID)
{
/*** Parameters start ***/
http_t *pHTTP; // Pointer to HTTP connection.
ipp_t *pRequest, // Pointer to CUPS IPP request.
*pResponse; // Pointer to CUPS IPP response.
ipp_attribute_t *pAttribute; // Pointer to CUPS attributes.
cups_lang_t *pLanguage; // Pointer to language.
ipp_jstate_t jobState = 0; // Job state.
gint jobID = 0; // Job ID.
gchar *pJobUserName = NULL; // User name of print job.
uid_t userID; // User ID.
struct passwd *pPasswd; // Pointer to password structure.
gint retVal = ID_ERR_PRINT_JOB_NOT_EXIST; // Return value.
/*** Parameters end ***/
// Get login name.
userID = getuid();
pPasswd = getpwuid(userID);
// CUPS http connect.
if ((pHTTP = httpConnectEncrypt(pServerName, ippPort(), cupsEncryption())) == NULL) {
retVal = ID_ERR_CUPS_API_FAILED;
}
else {
pRequest = ippNew();
ippSetOperation(pRequest, IPP_GET_JOBS);
ippSetRequestId(pRequest, 1);
pLanguage = bjcupsLangDefault(); // cupsLangDefault() -> bjcupsLangDefault() for cups-1.1.19
ippAddString(pRequest, IPP_TAG_OPERATION, IPP_TAG_CHARSET, "attributes-charset", NULL, cupsLangEncoding(pLanguage));
ippAddString(pRequest, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, "attributes-natural-language", NULL, pLanguage->language);
ippAddString(pRequest, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, pURI);
ippAddString(pRequest, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", NULL, cupsUser());
if ((pResponse = cupsDoRequest(pHTTP, pRequest, "/")) != NULL) {
int statusCode = ippGetStatusCode(pResponse);
if (statusCode > IPP_OK_CONFLICT) {
retVal = ID_ERR_CUPS_API_FAILED;
}
else {
pAttribute = ippFirstAttribute(pResponse);
while (pAttribute != NULL) {
while (pAttribute != NULL && ippGetGroupTag(pAttribute) != IPP_TAG_JOB) {
pAttribute = bjcups_ippNextAttribute(pResponse, pAttribute);
}
if (pAttribute == NULL) {
break;
}
while (pAttribute != NULL && ippGetGroupTag(pAttribute) == IPP_TAG_JOB) {
if (strcmp(ippGetName(pAttribute), "job-id") == 0 && ippGetValueTag(pAttribute) == IPP_TAG_INTEGER) {
jobID = ippGetInteger(pAttribute, 0);
}
if (strcmp(ippGetName(pAttribute), "job-uri") == 0 && ippGetValueTag(pAttribute) == IPP_TAG_URI) {
pJobUserName=getJobState(pDestName,ippGetString(pAttribute, 0, NULL),pServerName,&jobState,pJobUserName);
}
pAttribute = bjcups_ippNextAttribute(pRequest, pAttribute);
}
if (jobState == IPP_JOB_PROCESSING) {
if (pJobUserName != NULL) {
if (strcmp(pPasswd->pw_name, pJobUserName) == 0) {
retVal = ID_ERR_NO_ERROR;
}
else if (pJobUserName[0] == '\0') {
retVal = ID_ERR_NO_ERROR;
}
}
break;
}
if (pAttribute != NULL)
pAttribute = bjcups_ippNextAttribute(pRequest, pAttribute);
}
}
ippDelete(pResponse);
}
else {
retVal = ID_ERR_CUPS_API_FAILED;
}
cupsLangFree(pLanguage);
httpClose(pHTTP);
}
if (retVal == ID_ERR_NO_ERROR && pJobID != NULL) {
//.........这里部分代码省略.........
开发者ID:Magister,项目名称:bjcups-2.50,代码行数:101,代码来源:bjcupsmon_cups.c
示例6: do_class_op
static void
do_class_op(http_t *http, /* I - HTTP connection */
const char *printer, /* I - Printer name */
ipp_op_t op, /* I - Operation to perform */
const char *title) /* I - Title of page */
{
ipp_t *request; /* IPP request */
char uri[HTTP_MAX_URI], /* Printer URI */
resource[HTTP_MAX_URI]; /* Path for request */
/*
* Build a printer request, which requires the following
* attributes:
*
* attributes-charset
* attributes-natural-language
* printer-uri
*/
request = ippNewRequest(op);
httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
"localhost", 0, "/classes/%s", printer);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
NULL, uri);
/*
* Do the request and get back a response...
*/
snprintf(resource, sizeof(resource), "/classes/%s", printer);
ippDelete(cupsDoRequest(http, request, resource));
if (cupsLastError() == IPP_NOT_AUTHORIZED)
{
puts("Status: 401\n");
exit(0);
}
else if (cupsLastError() > IPP_OK_CONFLICT)
{
cgiStartHTML(title);
cgiShowIPPError(_("Unable to do maintenance command"));
}
else
{
/*
* Redirect successful updates back to the printer page...
*/
char url[1024], /* Printer/class URL */
refresh[1024]; /* Refresh URL */
cgiRewriteURL(uri, url, sizeof(url), NULL);
cgiFormEncode(uri, url, sizeof(uri));
snprintf(refresh, sizeof(refresh), "5;URL=%s", uri);
cgiSetVariable("refresh_page", refresh);
cgiStartHTML(title);
cgiSetVariable("IS_CLASS", "YES");
if (op == IPP_PAUSE_PRINTER)
cgiCopyTemplateLang("printer-stop.tmpl");
else if (op == IPP_RESUME_PRINTER)
cgiCopyTemplateLang("printer-start.tmpl");
else if (op == CUPS_ACCEPT_JOBS)
cgiCopyTemplateLang("printer-accept.tmpl");
else if (op == CUPS_REJECT_JOBS)
cgiCopyTemplateLang("printer-reject.tmpl");
else if (op == IPP_OP_CANCEL_JOBS)
cgiCopyTemplateLang("printer-cancel-jobs.tmpl");
}
cgiEndHTML();
}
开发者ID:lanceit,项目名称:cups,代码行数:77,代码来源:classes.c
示例7: main
int /* O - Exit status */
main(void)
{
const char *pclass; /* Class name */
const char *user; /* Username */
http_t *http; /* Connection to the server */
ipp_t *request, /* IPP request */
*response; /* IPP response */
ipp_attribute_t *attr; /* IPP attribute */
const char *op; /* Operation to perform, if any */
static const char *def_attrs[] = /* Attributes for default printer */
{
"printer-name",
"printer-uri-supported"
};
/*
* Get any form variables...
*/
cgiInitialize();
op = cgiGetVariable("OP");
/*
* Set the web interface section...
*/
cgiSetVariable("SECTION", "classes");
cgiSetVariable("REFRESH_PAGE", "");
/*
* See if we are displaying a printer or all classes...
*/
if ((pclass = getenv("PATH_INFO")) != NULL)
{
pclass ++;
if (!*pclass)
pclass = NULL;
if (pclass)
cgiSetVariable("PRINTER_NAME", pclass);
}
/*
* See who is logged in...
*/
user = getenv("REMOTE_USER");
/*
* Connect to the HTTP server...
*/
http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption());
/*
* Get the default printer...
*/
if (!op || !cgiIsPOST())
{
/*
* Get the default destination...
*/
request = ippNewRequest(CUPS_GET_DEFAULT);
ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
"requested-attributes",
sizeof(def_attrs) / sizeof(def_attrs[0]), NULL, def_attrs);
if ((response = cupsDoRequest(http, request, "/")) != NULL)
{
if ((attr = ippFindAttribute(response, "printer-name", IPP_TAG_NAME)) != NULL)
cgiSetVariable("DEFAULT_NAME", attr->values[0].string.text);
if ((attr = ippFindAttribute(response, "printer-uri-supported", IPP_TAG_URI)) != NULL)
{
char url[HTTP_MAX_URI]; /* New URL */
cgiSetVariable("DEFAULT_URI",
cgiRewriteURL(attr->values[0].string.text,
url, sizeof(url), NULL));
}
ippDelete(response);
}
/*
* See if we need to show a list of classes or the status of a
* single printer...
*/
if (!pclass)
show_all_classes(http, user);
//.........这里部分代码省略.........
开发者ID:lanceit,项目名称:cups,代码行数:101,代码来源:classes.c
示例8: do_job_op
static void
do_job_op(http_t *http, /* I - HTTP connection */
int job_id, /* I - Job ID */
ipp_op_t op) /* I - Operation to perform */
{
ipp_t *request; /* IPP request */
char uri[HTTP_MAX_URI]; /* Job URI */
const char *user; /* Username */
/*
* Build a job request, which requires the following
* attributes:
*
* attributes-charset
* attributes-natural-language
* job-uri or printer-uri (purge-jobs)
* requesting-user-name
*/
request = ippNewRequest(op);
snprintf(uri, sizeof(uri), "ipp://localhost/jobs/%d", job_id);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri",
NULL, uri);
if ((user = getenv("REMOTE_USER")) == NULL)
user = "guest";
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
"requesting-user-name", NULL, user);
/*
* Do the request and get back a response...
*/
ippDelete(cupsDoRequest(http, request, "/jobs"));
if (cupsLastError() <= IPP_OK_CONFLICT && getenv("HTTP_REFERER"))
{
/*
* Redirect successful updates back to the parent page...
*/
char url[1024]; /* Encoded URL */
strlcpy(url, "5;URL=", sizeof(url));
cgiFormEncode(url + 6, getenv("HTTP_REFERER"), sizeof(url) - 6);
cgiSetVariable("refresh_page", url);
}
else if (cupsLastError() == IPP_NOT_AUTHORIZED)
{
puts("Status: 401\n");
exit(0);
}
cgiStartHTML(cgiText(_("Jobs")));
if (cupsLastError() > IPP_OK_CONFLICT)
cgiShowIPPError(_("Job operation failed"));
else if (op == IPP_CANCEL_JOB)
cgiCopyTemplateLang("job-cancel.tmpl");
else if (op == IPP_HOLD_JOB)
cgiCopyTemplateLang("job-hold.tmpl");
else if (op == IPP_RELEASE_JOB)
cgiCopyTemplateLang("job-release.tmpl");
else if (op == IPP_RESTART_JOB)
cgiCopyTemplateLang("job-restart.tmpl");
cgiEndHTML();
}
开发者ID:jschwender,项目名称:cups,代码行数:73,代码来源:jobs.c
示例9: cupsCreateDestJob
ipp_status_t /* O - IPP status code */
cupsCreateDestJob(
http_t *http, /* I - Connection to destination */
cups_dest_t *dest, /* I - Destination */
cups_dinfo_t *info, /* I - Destination information */
int *job_id, /* O - Job ID or 0 on error */
const char *title, /* I - Job name */
int num_options, /* I - Number of job options */
cups_option_t *options) /* I - Job options */
{
ipp_t *request, /* Create-Job request */
*response; /* Create-Job response */
ipp_attribute_t *attr; /* job-id attribute */
DEBUG_printf(("cupsCreateDestJob(http=%p, dest=%p(%s/%s), info=%p, "
"job_id=%p, title=\"%s\", num_options=%d, options=%p)", (void *)http, (void *)dest, dest ? dest->name : NULL, dest ? dest->instance : NULL, (void *)info, (void *)job_id, title, num_options, (void *)options));
/*
* Range check input...
*/
if (job_id)
*job_id = 0;
if (!http || !dest || !info || !job_id)
{
_cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0);
DEBUG_puts("1cupsCreateDestJob: Bad arguments.");
return (IPP_STATUS_ERROR_INTERNAL);
}
/*
* Build a Create-Job request...
*/
if ((request = ippNewRequest(IPP_OP_CREATE_JOB)) == NULL)
{
_cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(ENOMEM), 0);
DEBUG_puts("1cupsCreateDestJob: Unable to create Create-Job request.");
return (IPP_STATUS_ERROR_INTERNAL);
}
ippSetVersion(request, info->version / 10, info->version % 10);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
NULL, info->uri);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
NULL, cupsUser());
if (title)
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "job-name", NULL,
title);
cupsEncodeOptions2(request, num_options, options, IPP_TAG_OPERATION);
cupsEncodeOptions2(request, num_options, options, IPP_TAG_JOB);
cupsEncodeOptions2(request, num_options, options, IPP_TAG_SUBSCRIPTION);
/*
* Send the request and get the job-id...
*/
response = cupsDoRequest(http, request, info->resource);
if ((attr = ippFindAttribute(response, "job-id", IPP_TAG_INTEGER)) != NULL)
{
*job_id = attr->values[0].integer;
DEBUG_printf(("1cupsCreateDestJob: job-id=%d", *job_id));
}
ippDelete(response);
/*
* Return the status code from the Create-Job request...
*/
DEBUG_printf(("1cupsCreateDestJob: %s (%s)", ippErrorString(cupsLastError()),
cupsLastErrorString()));
return (cupsLastError());
}
开发者ID:AndychenCL,项目名称:cups,代码行数:80,代码来源:dest-job.c
示例10: ippDelete
ReturnArguments KCupsConnection::request(ipp_op_e operation,
const char *resource,
const QVariantHash &reqValues,
bool needResponse)
{
ReturnArguments ret;
if (!readyToStart()) {
return ret; // This is not intended to be used in the gui thread
}
ipp_t *response = NULL;
bool needDestName = false;
int group_tag = IPP_TAG_PRINTER;
do {
ipp_t *request;
bool isClass = false;
QString filename;
QVariantHash values = reqValues;
ippDelete(response);
if (values.contains(QLatin1String("printer-is-class"))) {
isClass = values.take(QLatin1String("printer-is-class")).toBool();
}
if (values.contains(QLatin1String("need-dest-name"))) {
needDestName = values.take(QLatin1String("need-dest-name")).toBool();
}
if (values.contains(QLatin1String("group-tag-qt"))) {
group_tag = values.take(QLatin1String("group-tag-qt")).toInt();
}
if (values.contains(QLatin1String("filename"))) {
filename = values.take(QLatin1String("filename")).toString();
}
// Lets create the request
if (values.contains(QLatin1String(KCUPS_PRINTER_NAME))) {
request = ippNewDefaultRequest(values.take(QLatin1String(KCUPS_PRINTER_NAME)).toString(),
isClass,
operation);
} else {
request = ippNewRequest(operation);
}
// send our user name on the request too
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
"requesting-user-name", NULL, cupsUser());
// Add the requested values to the request
requestAddValues(request, values);
// Do the request
// do the request deleting the response
if (filename.isEmpty()) {
response = cupsDoRequest(CUPS_HTTP_DEFAULT, request, resource);
} else {
response = cupsDoFileRequest(CUPS_HTTP_DEFAULT, request, resource, filename.toUtf8());
}
} while (retry(resource));
if (response != NULL && needResponse) {
ret = parseIPPVars(response, group_tag, needDestName);
}
ippDelete(response);
return ret;
}
开发者ID:freexploit,项目名称:print-manager,代码行数:68,代码来源:KCupsConnection.cpp
示例11: kWarning
int KCupsConnection::renewDBusSubscription(int subscriptionId, int leaseDuration, const QStringList &events)
{
int ret = -1;
if (!readyToStart()) {
kWarning() << "Tryied to run on the wrong thread";
return subscriptionId; // This is not intended to be used in the gui thread
}
ipp_t *response = NULL;
do {
ipp_t *request;
ipp_op_e operation;
// check if we have a valid subscription ID
if (subscriptionId >= 0) {
// Add the "notify-events" values to the request
operation = IPP_RENEW_SUBSCRIPTION;
} else {
operation = IPP_CREATE_PRINTER_SUBSCRIPTION;
}
// Lets create the request
request = ippNewRequest(operation);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
KCUPS_PRINTER_URI, NULL, "/");
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
"requesting-user-name", NULL, cupsUser());
if (operation == IPP_CREATE_PRINTER_SUBSCRIPTION) {
// Add the "notify-events" values to the request
QVariantHash values;
values["notify-events"] = events;
requestAddValues(request, values);
ippAddString(request, IPP_TAG_SUBSCRIPTION, IPP_TAG_KEYWORD,
"notify-pull-method", NULL, "ippget");
ippAddString(request, IPP_TAG_SUBSCRIPTION, IPP_TAG_URI,
"notify-recipient-uri", NULL, "dbus://");
ippAddInteger(request, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
"notify-lease-duration", leaseDuration);
} else {
ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER,
"notify-subscription-id", subscriptionId);
ippAddInteger(request, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
"notify-lease-duration", leaseDuration);
}
// Do the request
response = cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/");
} while (retry("/"));
#ifdef HAVE_CUPS_1_6
if (response && ippGetStatusCode(response) == IPP_OK) {
#else
if (response && response->request.status.status_code == IPP_OK) {
#endif // HAVE_CUPS_1_6
ipp_attribute_t *attr;
if (subscriptionId >= 0) {
// Request was ok, just return the current subscription
ret = subscriptionId;
} else if ((attr = ippFindAttribute(response,
"notify-subscription-id",
IPP_TAG_INTEGER)) == NULL) {
kWarning() << "No notify-subscription-id in response!";
ret = -1;
} else {
#ifdef HAVE_CUPS_1_6
ret = ippGetInteger(attr, 0);
}
} else if (subscriptionId >= 0 && response && ippGetStatusCode(response) == IPP_NOT_FOUND) {
kDebug() << "Subscription not found";
// When the subscription is not found try to get a new one
return renewDBusSubscription(-1, leaseDuration, events);
#else
ret = attr->values[0].integer;
}
} else if (subscriptionId >= 0 && response && response->request.status.status_code == IPP_NOT_FOUND) {
kDebug() << "Subscription not found";
// When the subscription is not found try to get a new one
return renewDBusSubscription(-1, leaseDuration, events);
#endif // HAVE_CUPS_1_6
} else {
kWarning() << "Request failed" << lastError();
// When the server stops/restarts we will have some error so ignore it
ret = subscriptionId;
}
ippDelete(response);
return ret;
}
开发者ID:freexploit,项目名称:print-manager,代码行数:92,代码来源:KCupsConnection.cpp
示例12: main
//.........这里部分代码省略.........
cipherName = "TLS_ECDHE_RSA_WITH_RC4_128_SHA";
paramsNeeded = 1;
break;
case TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA:
cipherName = "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA";
paramsNeeded = 1;
break;
case TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA:
cipherName = "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA";
paramsNeeded = 1;
break;
case TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA:
cipherName = "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA";
paramsNeeded = 1;
break;
case TLS_ECDH_anon_WITH_NULL_SHA:
cipherName = "TLS_ECDH_anon_WITH_NULL_SHA";
paramsNeeded = 1;
break;
case TLS_ECDH_anon_WITH_RC4_128_SHA:
cipherName = "TLS_ECDH_anon_WITH_RC4_128_SHA";
paramsNeeded = 1;
break;
case TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA:
cipherName = "TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA";
paramsNeeded = 1;
break;
case TLS_ECDH_anon_WITH_AES_128_CBC_SHA:
cipherName = "TLS_ECDH_anon_WITH_AES_128_CBC_SHA";
paramsNeeded = 1;
break;
case TLS_ECDH_anon_WITH_AES_256_CBC_SHA:
cipherName = "TLS_ECDH_anon_WITH_AES_256_CBC_SHA";
paramsNeeded = 1;
break;
default :
snprintf(unknownCipherName, sizeof(unknownCipherName), "UNKNOWN_%04X", cipher);
cipherName = unknownCipherName;
break;
}
if (cipher == TLS_RSA_WITH_RC4_128_MD5 ||
cipher == TLS_RSA_WITH_RC4_128_SHA)
{
printf("%s: ERROR (Printers MUST NOT negotiate RC4 cipher suites.)\n", server);
httpClose(http);
return (1);
}
if ((err = SSLGetDiffieHellmanParams(http->tls, ¶ms, ¶msLen)) != noErr && paramsNeeded)
{
printf("%s: ERROR (Unable to get Diffie-Hellman parameters - %d)\n", server, (int)err);
httpClose(http);
return (1);
}
if (paramsLen < 128 && paramsLen != 0)
{
printf("%s: ERROR (Diffie-Hellman parameters MUST be at least 2048 bits, but Printer uses only %d bits/%d bytes)\n", server, (int)paramsLen * 8, (int)paramsLen);
httpClose(http);
return (1);
}
dhBits = (int)paramsLen * 8;
#endif /* __APPLE__ */
if (dhBits > 0)
printf("%s: OK (TLS: %d.%d, %s, %d DH bits)\n", server, tlsVersion / 10, tlsVersion % 10, cipherName, dhBits);
else
printf("%s: OK (TLS: %d.%d, %s)\n", server, tlsVersion / 10, tlsVersion % 10, cipherName);
if (verbose)
{
httpAssembleURI(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipps", NULL, host, port, resource);
request = ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", NULL, cupsUser());
ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "requested-attributes", (int)(sizeof(pattrs) / sizeof(pattrs[0])), NULL, pattrs);
response = cupsDoRequest(http, request, resource);
for (attr = ippFirstAttribute(response); attr; attr = ippNextAttribute(response))
{
if (ippGetGroupTag(attr) != IPP_TAG_PRINTER)
continue;
if ((name = ippGetName(attr)) == NULL)
continue;
ippAttributeString(attr, value, sizeof(value));
printf(" %s=%s\n", name, value);
}
ippDelete(response);
}
httpClose(http);
return (0);
}
开发者ID:jschwender,项目名称:cups,代码行数:101,代码来源:tlscheck.c
示例13: cgiPrintCommand
//.........这里部分代码省略.........
1, &hold_option)) < 1)
{
cgiSetVariable("MESSAGE", cgiText(_("Unable to send command to printer driver")));
cgiSetVariable("ERROR", cupsLastErrorString());
cgiStartHTML(title);
cgiCopyTemplateLang("error.tmpl");
cgiEndHTML();
if (cgiSupportsMultipart())
cgiEndMultipart();
return;
}
status = cupsStartDocument(http, dest, job_id, NULL, CUPS_FORMAT_COMMAND, 1);
if (status == HTTP_CONTINUE)
status = cupsWriteRequestData(http, command_file,
strlen(command_file));
if (status == HTTP_CONTINUE)
cupsFinishDocument(http, dest);
if (cupsLastError() >= IPP_REDIRECTION_OTHER_SITE)
{
cgiSetVariable("MESSAGE", cgiText(_("Unable to send command to printer driver")));
cgiSetVariable("ERROR", cupsLastErrorString());
cgiStartHTML(title);
cgiCopyTemplateLang("error.tmpl");
cgiEndHTML();
if (cgiSupportsMultipart())
cgiEndMultipart();
cupsCancelJob(dest, job_id);
return;
}
/*
* Wait for the job to complete...
*/
if (cgiSupportsMultipart())
{
for (;;)
{
/*
* Get the current job state...
*/
snprintf(uri, sizeof(uri), "ipp://localhost/jobs/%d", job_id);
request = ippNewRequest(IPP_GET_JOB_ATTRIBUTES);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri",
NULL, uri);
if (user)
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
"requesting-user-name", NULL, user);
ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
"requested-attributes", 2, NULL, job_attrs);
if ((response = cupsDoRequest(http, request, "/")) != NULL)
cgiSetIPPVars(response, NULL, NULL, NULL, 0);
attr = ippFindAttribute(response, "job-state", IPP_TAG_ENUM);
if (!attr || attr->values[0].integer >= IPP_JOB_STOPPED ||
attr->values[0].integer == IPP_JOB_HELD)
{
ippDelete(response);
break;
}
/*
* Job not complete, so update the status...
*/
ippDelete(response);
cgiStartHTML(title);
cgiCopyTemplateLang("command.tmpl");
cgiEndHTML();
fflush(stdout);
sleep(5);
}
}
/*
* Send the final page that reloads the printer's page...
*/
snprintf(resource, sizeof(resource), "/printers/%s", dest);
cgiFormEncode(uri, resource, sizeof(uri));
snprintf(refresh, sizeof(refresh), "5;URL=%s", uri);
cgiSetVariable("refresh_page", refresh);
cgiStartHTML(title);
cgiCopyTemplateLang("command.tmpl");
cgiEndHTML();
if (cgiSupportsMultipart())
cgiEndMultipart();
}
开发者ID:Cacauu,项目名称:cups,代码行数:101,代码来源:ipp-var.c
示例14: show_jobs
//.........这里部分代码省略.........
}
else if (dest)
{
httpAssembleURIf(HTTP_URI_CODING_ALL, resource, sizeof(resource), "ipp",
NULL, "localhost", 0, "/printers/%s", dest);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
NULL, resource);
}
else
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
NULL, "ipp://localhost/");
if (user)
{
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
"requesting-user-name", NULL, user);
ippAddBoolean(request, IPP_TAG_OPERATION, "my-jobs", 1);
}
else
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
"requesting-user-name", NULL, cupsUser());
ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
"requested-attributes",
(int)(sizeof(jobattrs) / sizeof(jobattrs[0])), NULL, jobattrs);
/*
* Do the request and get back a response...
*/
jobcount = 0;
if ((response = cupsDoRequest(http, request, "/")) != NULL)
{
if (response->request.status.status_code > IPP_OK_CONFLICT)
{
_cupsLangPrintf(stderr, "%s: %s", command, cupsLastErrorString());
ippDelete(response);
return (0);
}
rank = 1;
/*
* Loop through the job list and display them...
*/
for (attr = response->attrs; attr != NULL; attr = attr->next)
{
/*
* Skip leading attributes until we hit a job...
*/
while (attr != NULL && attr->group_tag != IPP_TAG_JOB)
attr = attr->next;
if (attr == NULL)
break;
/*
* Pull the needed attributes from this job...
*/
jobid = 0;
jobsize = 0;
开发者ID:alfintatorkace,项目名称:osx-10.9-opensource,代码行数:67,代码来源:lpq.c
示例15: cupsCloseDestJob
ipp_status_t /* O - IPP status code */
cupsCloseDestJob(
http_t *http, /* I - Connection to destination */
cups_dest_t *dest, /* I - Destination */
cups_dinfo_t *info, /* I - Destination information */
int job_id) /* I - Job ID */
{
int i; /* Looping var */
ipp_t *request = NULL;/* Close-Job/Send-Document request */
ipp_attribute_t *attr; /* operations-supported attribute */
DEBUG_printf(("cupsCloseDestJob(http=%p, dest=%p(%s/%s), info=%p, job_id=%d)", (void *)http, (void *)dest, dest ? dest->name : NULL, dest ? dest->instance : NULL, (void *)info, job_id));
/*
* Range check input...
*/
if (!http || !dest || !info || job_id <= 0)
{
_cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0);
DEBUG_puts("1cupsCloseDestJob: Bad arguments.");
return (IPP_STATUS_ERROR_INTERNAL);
}
/*
* Build a Close-Job or empty Send-Document request...
*/
if ((attr = ippFindAttribute(info->attrs, "operations-supported",
IPP_TAG_ENUM)) != NULL)
{
for (i = 0; i < attr->num_values; i ++)
if (attr->values[i].integer == IPP_OP_CLOSE_JOB)
{
request = ippNewRequest(IPP_OP_CLOSE_JOB);
break;
}
}
if (!request)
request = ippNewRequest(IPP_OP_SEND_DOCUMENT);
if (!request)
{
_cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(ENOMEM), 0);
DEBUG_puts("1cupsCloseDestJob: Unable to create Close-Job/Send-Document "
"request.");
return (IPP_STATUS_ERROR_INTERNAL);
}
ippSetVersion(request, info->version / 10, info->version % 10);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
NULL, info->uri);
ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "job-id",
job_id);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
NULL, cupsUser());
if (ippGetOperation(request) == IPP_OP_SEND_DOCUMENT)
ippAddBoolean(request, IPP_TAG_OPERATION, "last-document", 1);
/*
* Send the request and return the status...
*/
ippDelete(cupsDoRequest(http, request, info->resource));
DEBUG_printf(("1cupsCloseDestJob: %s (%s)", ippErrorString(cupsLastError()),
cupsLastErrorString()));
return (cupsLastError());
}
开发者ID:AndychenCL,项目名称:cups,代码行数:73,代码来源:dest-job.c
示例16: show_printer
static void
show_printer(const char *command, /* I - Command name */
http_t *http, /* I - HTTP connection to server */
const char *dest) /* I - Destination */
{
ipp_t *request, /* IPP Request */
*response; /* IPP Response */
ipp_attribute_t *attr; /* Current attribute */
ipp_pstate_t state; /* Printer state */
char uri[HTTP_MAX_URI]; /* Printer URI */
if (http == NULL)
return;
/*
* Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the following
* attributes:
*
* attributes-charset
* attributes-natural-language
|
请发表评论