const char * /* O - Text string */ ippErrorString(ipp_status_t error) /* I - Error status */ { _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */ /* * See if the error code is a known value... */ if (error >= IPP_OK && error <= IPP_OK_EVENTS_COMPLETE) return (ipp_status_oks[error]); else if (error == IPP_REDIRECTION_OTHER_SITE) return ("redirection-other-site"); else if (error == CUPS_SEE_OTHER) return ("cups-see-other"); else if (error >= IPP_BAD_REQUEST && error <= IPP_PRINT_SUPPORT_FILE_NOT_FOUND) return (ipp_status_400s[error - IPP_BAD_REQUEST]); else if (error >= IPP_INTERNAL_ERROR && error <= IPP_PRINTER_IS_DEACTIVATED) return (ipp_status_500s[error - IPP_INTERNAL_ERROR]); else if (error >= IPP_AUTHENTICATION_CANCELED && error <= IPP_UPGRADE_REQUIRED) return (ipp_status_1000s[error - IPP_AUTHENTICATION_CANCELED]); /* * No, build an "0xxxxx" error string... */ sprintf(cg->ipp_unknown, "0x%04x", error); return (cg->ipp_unknown); }
void ippSetPort(int p) /* I - Port number to use */ { DEBUG_printf(("ippSetPort(p=%d)", p)); _cupsGlobals()->ipp_port = p; }
const char * /* O - Name */ ippOpString(ipp_op_t op) /* I - Operation ID */ { _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */ /* * See if the operation ID is a known value... */ if (op >= IPP_PRINT_JOB && op <= IPP_CLOSE_JOB) return (ipp_std_ops[op]); else if (op == IPP_PRIVATE) return ("windows-ext"); else if (op >= CUPS_GET_DEFAULT && op <= CUPS_GET_PPD) return (ipp_cups_ops[op - CUPS_GET_DEFAULT]); else if (op == CUPS_GET_DOCUMENT) return (ipp_cups_ops2[0]); /* * No, build an "0xxxxx" operation string... */ sprintf(cg->ipp_unknown, "0x%04x", op); return (cg->ipp_unknown); }
void cupsSetServer(const char *server) /* I - Server name */ { char *options, /* Options */ *port; /* Pointer to port */ _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */ if (server) { strlcpy(cg->server, server, sizeof(cg->server)); if (cg->server[0] != '/' && (options = strrchr(cg->server, '/')) != NULL) { *options++ = '\0'; if (!strcmp(options, "version=1.0")) cg->server_version = 10; else if (!strcmp(options, "version=1.1")) cg->server_version = 11; else if (!strcmp(options, "version=2.0")) cg->server_version = 20; else if (!strcmp(options, "version=2.1")) cg->server_version = 21; else if (!strcmp(options, "version=2.2")) cg->server_version = 22; } else cg->server_version = 20; if (cg->server[0] != '/' && (port = strrchr(cg->server, ':')) != NULL && !strchr(port, ']') && isdigit(port[1] & 255)) { *port++ = '\0'; cg->ipp_port = atoi(port); } if (!cg->ipp_port) cups_set_default_ipp_port(cg); if (cg->server[0] == '/') strlcpy(cg->servername, "localhost", sizeof(cg->servername)); else strlcpy(cg->servername, cg->server, sizeof(cg->servername)); } else { cg->server[0] = '\0'; cg->servername[0] = '\0'; cg->server_version = 20; cg->ipp_port = 0; } if (cg->http) { httpClose(cg->http); cg->http = NULL; } }
char * /* O - Buffer */ _cupsStrDate(char *buf, /* I - Buffer */ size_t bufsize, /* I - Size of buffer */ time_t timeval) /* I - Time value */ { struct tm *dateval; /* Local date/time */ char temp[1024]; /* Temporary buffer */ _cups_globals_t *cg = _cupsGlobals(); /* Per-thread globals */ if (!cg->lang_default) cg->lang_default = cupsLangDefault(); dateval = localtime(&timeval); if (cg->lang_default->encoding != CUPS_UTF8) { strftime(temp, sizeof(temp), "%c", dateval); cupsCharsetToUTF8((cups_utf8_t *)buf, temp, (int)bufsize, cg->lang_default->encoding); } else strftime(buf, bufsize, "%c", dateval); return (buf); }
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)); }
char * /* O - Name of PPD file or @code NULL@ on error */ cupsGetServerPPD(http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */ const char *name) /* I - Name of PPD file ("ppd-name") */ { int fd; /* PPD file descriptor */ ipp_t *request; /* IPP request */ _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */ /* * Range check input... */ if (!name) { _cupsSetError(IPP_INTERNAL_ERROR, _("No PPD name"), 1); return (NULL); } if (!http) if ((http = _cupsConnect()) == NULL) return (NULL); /* * Get a temp file... */ if ((fd = cupsTempFd(cg->ppd_filename, sizeof(cg->ppd_filename))) < 0) { /* * Can't open file; close the server connection and return NULL... */ _cupsSetError(IPP_INTERNAL_ERROR, NULL, 0); return (NULL); } /* * Get the PPD file... */ request = ippNewRequest(CUPS_GET_PPD); ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "ppd-name", NULL, name); ippDelete(cupsDoIORequest(http, request, "/", -1, fd)); close(fd); if (cupsLastError() != IPP_OK) { unlink(cg->ppd_filename); return (NULL); } else return (cg->ppd_filename); }
ssize_t /* O - Bytes read, 0 on EOF, -1 on error */ cupsReadResponseData( http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */ char *buffer, /* I - Buffer to use */ size_t length) /* I - Number of bytes to read */ { /* * Get the default connection as needed... */ DEBUG_printf(("cupsReadResponseData(http=%p, buffer=%p, " "length=" CUPS_LLFMT ")", http, buffer, CUPS_LLCAST length)); if (!http) { _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */ if ((http = cg->http) == NULL) { _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("No active connection"), 1); return (-1); } } /* * Then read from the HTTP connection... */ return (httpRead2(http, buffer, length)); }
static int /* O - Local thread ID */ debug_thread_id(void) { _cups_globals_t *cg = _cupsGlobals(); /* Global data */ return (cg->thread_id); }
const char * /* O - Password */ cupsGetPassword(const char *prompt) /* I - Prompt string */ { _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */ return ((cg->password_cb)(prompt, NULL, NULL, NULL, cg->password_data)); }
const char * /* O - Default printer or NULL */ cupsGetDefault2(http_t *http) /* I - HTTP connection */ { ipp_t *request, /* IPP Request */ *response; /* IPP Response */ ipp_attribute_t *attr; /* Current attribute */ 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); /* * Range check input... */ if (!http) return (NULL); /* * Build a CUPS_GET_DEFAULT request, which requires the following * attributes: * * attributes-charset * attributes-natural-language */ request = ippNewRequest(CUPS_GET_DEFAULT); /* * Do the request and get back a response... */ if ((response = cupsDoRequest(http, request, "/")) != NULL) { if ((attr = ippFindAttribute(response, "printer-name", IPP_TAG_NAME)) != NULL) { strlcpy(cg->def_printer, attr->values[0].string.text, sizeof(cg->def_printer)); ippDelete(response); return (cg->def_printer); } ippDelete(response); } return (NULL); }
void _cupsSNMPSetDebug(int level) /* I - 1 to enable debug output, 0 otherwise */ { _cups_globals_t *cg = _cupsGlobals(); /* Global data */ DEBUG_printf(("4_cupsSNMPSetDebug(level=%d)", level)); cg->snmp_debug = level; }
const char * /* O - User name */ cupsUser(void) { const char *user; /* USER environment variable */ _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */ if (!cg->user[0]) { #ifdef WIN32 /* * Get the current user name from the OS... */ DWORD size; /* Size of string */ size = sizeof(cg->user); if (!GetUserName(cg->user, &size)) #else /* * Get the user name corresponding to the current UID... */ struct passwd *pwd; /* User/password entry */ // setpwent(); if ((pwd = getpwuid(getuid())) != NULL) { /* * Found a match! */ strlcpy(cg->user, pwd->pw_name, sizeof(cg->user)); } else #endif /* WIN32 */ if ((user = getenv("USER")) != NULL) { /* * Use the username from the "USER" environment variable... */ strlcpy(cg->user, user, sizeof(cg->user)); } else { /* * Use the default "unknown" user name... */ strcpy(cg->user, "unknown"); } } return (cg->user); }
void cupsSetEncryption(http_encryption_t e) /* I - New encryption preference */ { _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */ cg->encryption = e; if (cg->http) httpEncryption(cg->http, e); }
const char * /* O - Default printer or @code NULL@ */ cupsGetDefault2(http_t *http) /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */ { ipp_t *request, /* IPP Request */ *response; /* IPP Response */ ipp_attribute_t *attr; /* Current attribute */ _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */ /* * See if we have a user default printer set... */ if (_cupsUserDefault(cg->def_printer, sizeof(cg->def_printer))) return (cg->def_printer); /* * Connect to the server as needed... */ if (!http) if ((http = _cupsConnect()) == NULL) return (NULL); /* * Build a CUPS_GET_DEFAULT request, which requires the following * attributes: * * attributes-charset * attributes-natural-language */ request = ippNewRequest(CUPS_GET_DEFAULT); /* * Do the request and get back a response... */ if ((response = cupsDoRequest(http, request, "/")) != NULL) { if ((attr = ippFindAttribute(response, "printer-name", IPP_TAG_NAME)) != NULL) { strlcpy(cg->def_printer, attr->values[0].string.text, sizeof(cg->def_printer)); ippDelete(response); return (cg->def_printer); } ippDelete(response); } return (NULL); }
http_encryption_t /* O - Encryption settings */ cupsEncryption(void) { _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */ if (cg->encryption == (http_encryption_t)-1) _cupsSetDefaults(); return (cg->encryption); }
const char * _cupsGSSServiceName(void) { _cups_globals_t *cg = _cupsGlobals(); /* Thread globals */ if (!cg->gss_service_name[0]) _cupsSetDefaults(); return (cg->gss_service_name); }
const char * /* O - User-Agent string */ cupsUserAgent(void) { _cups_globals_t *cg = _cupsGlobals(); /* Thread globals */ if (!cg->user_agent[0]) cupsSetUserAgent(NULL); return (cg->user_agent); }
const char * /* O - User name */ cupsUser(void) { _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */ if (!cg->user[0]) _cupsSetDefaults(); return (cg->user); }
void cupsSetUser(const char *user) /* I - User name */ { _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */ if (user) strlcpy(cg->user, user, sizeof(cg->user)); else cg->user[0] = '\0'; }
void cupsSetServerCertCB( cups_server_cert_cb_t cb, /* I - Callback function */ void *user_data) /* I - User data pointer */ { _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */ cg->server_cert_cb = cb; cg->server_cert_data = user_data; }
int /* O - Number of bytes written */ _cupsLangPrintFilter( FILE *fp, /* I - File to write to */ const char *prefix, /* I - Non-localized message prefix */ const char *message, /* I - Message string to use */ ...) /* I - Additional arguments as needed */ { ssize_t bytes; /* Number of bytes formatted */ char temp[2048], /* Temporary format buffer */ buffer[2048], /* Message buffer */ output[8192]; /* Output buffer */ va_list ap; /* Pointer to additional arguments */ _cups_globals_t *cg; /* Global data */ /* * Range check... */ if (!fp || !message) return (-1); cg = _cupsGlobals(); if (!cg->lang_default) cg->lang_default = cupsLangDefault(); /* * Format the string... */ va_start(ap, message); snprintf(temp, sizeof(temp), "%s: %s\n", prefix, _cupsLangString(cg->lang_default, message)); vsnprintf(buffer, sizeof(buffer), temp, ap); va_end(ap); /* * Transcode to the destination charset... */ bytes = cupsUTF8ToCharset(output, (cups_utf8_t *)buffer, sizeof(output), cg->lang_default->encoding); /* * Write the string and return the number of bytes written... */ if (bytes > 0) return ((int)fwrite(output, 1, (size_t)bytes, fp)); else return ((int)bytes); }
_pwg_media_t * /* O - PWG media name */ _pwgMediaForSize(int width, /* I - Width in 2540ths */ int length) /* I - Length in 2540ths */ { int i; /* Looping var */ _pwg_media_t *media; /* Current media */ int dw, dl; /* Difference in width and length */ _cups_globals_t *cg = _cupsGlobals(); /* Global data */ /* * Range check input... */ if (width <= 0 || length <= 0) return (NULL); /* * Look for a standard size... */ for (i = (int)(sizeof(cups_pwg_media) / sizeof(cups_pwg_media[0])), media = (_pwg_media_t *)cups_pwg_media; i > 0; i --, media ++) { /* * Adobe uses a size matching algorithm with an epsilon of 5 points, which * is just about 176/2540ths... */ dw = media->width - width; dl = media->length - length; if (dw > -176 && dw < 176 && dl > -176 && dl < 176) return (media); } /* * Not a standard size; convert it to a PWG custom name of the form: * * custom_WIDTHxHEIGHTuu_WIDTHxHEIGHTuu */ _pwgGenerateSize(cg->pwg_name, sizeof(cg->pwg_name), "custom", NULL, width, length); cg->pwg_media.pwg = cg->pwg_name; cg->pwg_media.width = width; cg->pwg_media.length = length; return (&(cg->pwg_media)); }
void cupsSetPasswordCB(cups_password_cb_t cb)/* I - Callback function */ { _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */ if (cb == (cups_password_cb_t)0) cg->password_cb = (cups_password_cb2_t)_cupsGetPassword; else cg->password_cb = (cups_password_cb2_t)cb; cg->password_data = NULL; }
const char * /* O - Password */ cupsGetPassword2(const char *prompt, /* I - Prompt string */ http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */ const char *method, /* I - Request method ("GET", "POST", "PUT") */ const char *resource) /* I - Resource path */ { _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */ if (!http) http = _cupsConnect(); return ((cg->password_cb)(prompt, http, method, resource, cg->password_data)); }
int /* O - Port number */ ippPort(void) { _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */ DEBUG_puts("ippPort()"); if (!cg->ipp_port) _cupsSetDefaults(); DEBUG_printf(("1ippPort: Returning %d...", cg->ipp_port)); return (cg->ipp_port); }
void cupsSetPasswordCB2( cups_password_cb2_t cb, /* I - Callback function */ void *user_data) /* I - User data pointer */ { _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */ if (cb == (cups_password_cb2_t)0) cg->password_cb = (cups_password_cb2_t)_cupsGetPassword; else cg->password_cb = cb; cg->password_data = user_data; }
int /* O - Status of call (0 = success) */ cupsSetCredentials( cups_array_t *credentials) /* I - Array of credentials */ { _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */ if (cupsArrayCount(credentials) < 1) return (-1); _httpFreeCredentials(cg->tls_credentials); cg->tls_credentials = _httpCreateCredentials(credentials); return (cg->tls_credentials ? 0 : -1); }
const char * /* O - Filename for PPD file */ cupsGetPPD2(http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */ const char *name) /* I - Destination name */ { _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */ time_t modtime = 0; /* Modification time */ cg->ppd_filename[0] = '\0'; if (cupsGetPPD3(http, name, &modtime, cg->ppd_filename, sizeof(cg->ppd_filename)) == HTTP_OK) return (cg->ppd_filename); else return (NULL); }
void _cupsSetError(ipp_status_t status, /* I - IPP status code */ const char *message, /* I - status-message value */ int localize) /* I - Localize the message? */ { _cups_globals_t *cg; /* Global data */ if (!message && errno) { message = strerror(errno); localize = 0; } cg = _cupsGlobals(); cg->last_error = status; if (cg->last_status_message) { _cupsStrFree(cg->last_status_message); cg->last_status_message = NULL; } if (message) { if (localize) { /* * Get the message catalog... */ if (!cg->lang_default) cg->lang_default = cupsLangDefault(); cg->last_status_message = _cupsStrAlloc(_cupsLangString(cg->lang_default, message)); } else cg->last_status_message = _cupsStrAlloc(message); } DEBUG_printf(("4_cupsSetError: last_error=%s, last_status_message=\"%s\"", ippErrorString(cg->last_error), cg->last_status_message)); }