Documentation ¶
Index ¶
- Constants
- Variables
- func DeepHash(data interface{}, h hash.Hash)
- func FilterRawPrinters(printers []Printer) ([]Printer, []Printer)
- func PrinterIsRaw(printer Printer) bool
- type ConcurrentPrinterMap
- type Config
- type Job
- type Printer
- type PrinterDiff
- type PrinterDiffOperation
- type PrinterState
- type Semaphore
Constants ¶
const ( // A website with user-friendly information. ConnectorHomeURL = "https://github.com/google/cups-connector" GCPAPIVersion = "2.0" )
Variables ¶
var ( // To be populated by something like: // go install -ldflags "-X github.com/google/cups-connector/lib.BuildDate=`date +%Y.%m.%d`" BuildDate = "DEV" ShortName = "CUPS Connector " + BuildDate + "-" + runtime.GOOS FullName = "Google Cloud Print CUPS Connector version " + BuildDate + "-" + runtime.GOOS )
var DefaultConfig = Config{ GCPMaxConcurrentDownloads: 5, CUPSMaxConnections: 50, CUPSConnectTimeout: "5s", CUPSJobQueueSize: 3, CUPSPrinterPollInterval: "1m", CUPSPrinterAttributes: []string{ "cups-version", "device-uri", "document-format-supported", "print-color-mode-default", "print-color-mode-supported", "printer-name", "printer-info", "printer-location", "printer-make-and-model", "printer-state", "printer-state-reasons", "printer-uuid", "marker-names", "marker-types", "marker-levels", "copies-default", "copies-supported", "number-up-default", "number-up-supported", "orientation-requested-default", "orientation-requested-supported", "pdf-versions-supported", }, CUPSJobFullUsername: false, CUPSIgnoreRawPrinters: true, CopyPrinterInfoToDisplayName: true, PrefixJobIDToJobTitle: false, DisplayNamePrefix: "", MonitorSocketFilename: "/tmp/cups-connector-monitor.sock", GCPBaseURL: "https://www.google.com/cloudprint/", XMPPServer: "talk.google.com", XMPPPort: 443, XMPPPingTimeout: "5s", XMPPPingIntervalDefault: "2m", GCPOAuthClientID: "539833558011-35iq8btpgas80nrs3o7mv99hm95d4dv6.apps.googleusercontent.com", GCPOAuthClientSecret: "V9BfPOvdiYuw12hDx5Y5nR0a", GCPOAuthAuthURL: "https://accounts.google.com/o/oauth2/auth", GCPOAuthTokenURL: "https://accounts.google.com/o/oauth2/token", SNMPEnable: false, SNMPCommunity: "public", SNMPMaxConnections: 100, LocalPrintingEnable: true, CloudPrintingEnable: false, }
DefaultConfig represents reasonable default values for Config fields. Omitted Config fields are omitted on purpose; they are unique per connector instance.
Functions ¶
func DeepHash ¶
DeepHash writes an object's values to h. Struct member names are ignored, values are written to h. Map keys and values are written to h. Slice inde and values are written to h. Pointers are followed once. Recursive pointer references cause panic.
func FilterRawPrinters ¶
FilterRawPrinters splits a slice of printers into non-raw and raw.
func PrinterIsRaw ¶
Types ¶
type ConcurrentPrinterMap ¶
type ConcurrentPrinterMap struct {
// contains filtered or unexported fields
}
ConcurrentPrinterMap is a map-like data structure that is also thread-safe. Printers are keyed by Printer.Name and Printer.GCPID.
func NewConcurrentPrinterMap ¶
func NewConcurrentPrinterMap(printers []Printer) *ConcurrentPrinterMap
NewConcurrentPrinterMap initializes an empty ConcurrentPrinterMap.
func (*ConcurrentPrinterMap) GetAll ¶
func (cpm *ConcurrentPrinterMap) GetAll() []Printer
GetAll returns a slice of all printers.
func (*ConcurrentPrinterMap) GetByCUPSName ¶
func (cpm *ConcurrentPrinterMap) GetByCUPSName(name string) (Printer, bool)
Get gets a printer, using the CUPS name as key.
The second return value is true if the entry exists.
func (*ConcurrentPrinterMap) GetByGCPID ¶
func (cpm *ConcurrentPrinterMap) GetByGCPID(gcpID string) (Printer, bool)
Get gets a printer, using the GCP ID as key.
The second return value is true if the entry exists.
func (*ConcurrentPrinterMap) Refresh ¶
func (cpm *ConcurrentPrinterMap) Refresh(newPrinters []Printer)
Refresh replaces the internal (non-concurrent) map with newPrinters.
type Config ¶
type Config struct { // Associated with root account. XMPP credential. XMPPJID string `json:"xmpp_jid,omitempty"` // Associated with robot account. Used for acquiring OAuth access tokens. RobotRefreshToken string `json:"robot_refresh_token,omitempty"` // Associated with user account. Used for sharing GCP printers; may be omitted. UserRefreshToken string `json:"user_refresh_token,omitempty"` ShareScope string `json:"share_scope,omitempty"` // User-chosen name of this proxy. Should be unique per Google user account. ProxyName string `json:"proxy_name,omitempty"` // Maximum quantity of jobs (data) to download concurrently. GCPMaxConcurrentDownloads uint `json:"gcp_max_concurrent_downloads"` // Maximum quantity of open CUPS connections. CUPSMaxConnections uint `json:"cups_max_connections"` // CUPS timeout for opening a new connection. CUPSConnectTimeout string `json:"cups_connect_timeout"` // CUPS job queue size. CUPSJobQueueSize uint `json:"cups_job_queue_size"` // Interval (eg 10s, 1m) between CUPS printer state polls. CUPSPrinterPollInterval string `json:"cups_printer_poll_interval"` // CUPS printer attributes to copy to GCP. CUPSPrinterAttributes []string `json:"cups_printer_attributes"` // Whether to use the full username (joe@example.com) in CUPS jobs. CUPSJobFullUsername bool `json:"cups_job_full_username"` // Whether to ignore printers with make/model 'Local Raw Printer'. CUPSIgnoreRawPrinters bool `json:"cups_ignore_raw_printers"` // Whether to copy the CUPS printer's printer-info attribute to the GCP printer's defaultDisplayName. CopyPrinterInfoToDisplayName bool `json:"copy_printer_info_to_display_name"` // Whether to add the job ID to the beginning of the job title. Useful for debugging. PrefixJobIDToJobTitle bool `json:"prefix_job_id_to_job_title"` // Prefix for all GCP printers hosted by this connector. DisplayNamePrefix string `json:"display_name_prefix"` // Filename of unix socket for connector-check to talk to connector. MonitorSocketFilename string `json:"monitor_socket_filename"` // GCP API URL prefix. GCPBaseURL string `json:"gcp_base_url"` // XMPP server FQDN. XMPPServer string `json:"xmpp_server"` // XMPP server port number. XMPPPort uint16 `json:"xmpp_port"` // XMPP ping timeout (give up waiting after this time). XMPPPingTimeout string `json:"gcp_xmpp_ping_timeout"` // XMPP ping interval (time between ping attempts). // This value is used when a printer is registered, and can // be overridden through the GCP API update method. XMPPPingIntervalDefault string `json:"gcp_xmpp_ping_interval_default"` // OAuth2 client ID (not unique per client). GCPOAuthClientID string `json:"gcp_oauth_client_id"` // OAuth2 client secret (not unique per client). GCPOAuthClientSecret string `json:"gcp_oauth_client_secret"` // OAuth2 auth URL. GCPOAuthAuthURL string `json:"gcp_oauth_auth_url"` // OAuth2 token URL. GCPOAuthTokenURL string `json:"gcp_oauth_token_url"` // Enable SNMP to augment CUPS printer information. SNMPEnable bool `json:"snmp_enable"` // Community string to use. SNMPCommunity string `json:"snmp_community"` // Maximum quantity of open SNMP connections. SNMPMaxConnections uint `json:"snmp_max_connections"` // Enable local discovery and printing. LocalPrintingEnable bool `json:"local_printing_enable"` // Enable cloud discovery and printing. CloudPrintingEnable bool `json:"cloud_printing_enable"` }
type Printer ¶
type Printer struct { GCPID string // GCP: printerid (GCP key) Name string // CUPS: cups_dest_t.name (CUPS key); GCP: name field DefaultDisplayName string // CUPS: printer-info; GCP: default_display_name field UUID string // CUPS: printer-uuid; GCP: uuid field Manufacturer string // CUPS: PPD; GCP: manufacturer field Model string // CUPS: PPD; GCP: model field GCPVersion string // GCP: gcpVersion field SetupURL string // GCP: setup_url field SupportURL string // GCP: support_url field UpdateURL string // GCP: update_url field ConnectorVersion string // GCP: firmware field State *cdd.PrinterStateSection // CUPS: various; GCP: semantic_state field Description *cdd.PrinterDescriptionSection // CUPS: translated PPD; GCP: capabilities field CapsHash string // CUPS: hash of PPD; GCP: capsHash field Tags map[string]string // CUPS: all printer attributes; GCP: repeated tag field CUPSJobSemaphore *Semaphore }
CUPS: cups_dest_t; GCP: /register and /update interfaces
func (*Printer) GetHostname ¶
GetHostname gets the network hostname, parsed from Printer.Tags["device-uri"].
type PrinterDiff ¶
type PrinterDiff struct { Operation PrinterDiffOperation Printer Printer DefaultDisplayNameChanged bool ManufacturerChanged bool ModelChanged bool GCPVersionChanged bool SetupURLChanged bool SupportURLChanged bool UpdateURLChanged bool ConnectorVersionChanged bool StateChanged bool DescriptionChanged bool CapsHashChanged bool TagsChanged bool }
Describes changes to be pushed to a GCP printer.
func DiffPrinters ¶
func DiffPrinters(cupsPrinters, gcpPrinters []Printer) []PrinterDiff
DiffPrinters returns the diff between old (GCP) and new (CUPS) printers. Returns nil if zero printers or if all diffs are NoChangeToPrinter operation.
type PrinterDiffOperation ¶
type PrinterDiffOperation int8
const ( RegisterPrinter PrinterDiffOperation = iota UpdatePrinter DeletePrinter NoChangeToPrinter )
type PrinterState ¶
type PrinterState uint8
type Semaphore ¶
type Semaphore struct {
// contains filtered or unexported fields
}
func NewSemaphore ¶
func (*Semaphore) Acquire ¶
func (s *Semaphore) Acquire()
Acquire increments the semaphore, blocking if necessary.
func (*Semaphore) Release ¶
func (s *Semaphore) Release()
Release decrements the semaphore. If this operation causes the semaphore value to be negative, then panics.
func (*Semaphore) TryAcquire ¶
TryAcquire increments the semaphore without blocking. Returns false if the semaphore was not acquired.