unified print functions
This commit is contained in:
parent
e221cdb59e
commit
d637c91791
31
constants.go
31
constants.go
|
@ -296,6 +296,37 @@ const (
|
|||
MimeTypeOctetStream = "application/octet-stream"
|
||||
)
|
||||
|
||||
const (
|
||||
OperationAttributeCopies string = "copies"
|
||||
OperationAttributeDocumentFormat = "document-format"
|
||||
OperationAttributeDocumentName = "document-name"
|
||||
OperationAttributeJobID = "job-id"
|
||||
OperationAttributeJobName = "job-name"
|
||||
OperationAttributeJobPriority = "job-priority"
|
||||
OperationAttributeJobURI = "job-uri"
|
||||
OperationAttributeLastDocument = "last-document"
|
||||
OperationAttributeMyJobs = "my-jobs"
|
||||
OperationAttributePPDName = "ppd-name"
|
||||
OperationAttributePrinterIsShared = "printer-is-shared"
|
||||
OperationAttributePrinterURI = "printer-uri"
|
||||
OperationAttributePurgeJobs = "purge-jobs"
|
||||
OperationAttributeRequestedAttributes = "requested-attributes"
|
||||
OperationAttributeRequestingUserName = "requesting-user-name"
|
||||
OperationAttributeWhichJobs = "which-jobs"
|
||||
)
|
||||
|
||||
const (
|
||||
PrinterAttributeDeviceURI string = "device-uri"
|
||||
PrinterAttributeHoldJobUntil = "job-hold-until"
|
||||
PrinterAttributePrinterErrorPolicy = "printer-error-policy"
|
||||
PrinterAttributePrinterInfo = "printer-info"
|
||||
PrinterAttributePrinterLocation = "printer-location"
|
||||
PrinterAttributePrinterName = "printer-name"
|
||||
PrinterAttributePrinterStateReason = "printer-state-reason"
|
||||
PrinterAttributeJobPrinterURI = "job-printer-uri"
|
||||
PrinterAttributeMemberURIs = "member-uris"
|
||||
)
|
||||
|
||||
var (
|
||||
DefaultClassAttributes = []string{"printer-name", "member-names"}
|
||||
DefaultPrinterAttributes = []string{"printer-name", "printer-type", "printer-location", "printer-info",
|
||||
|
|
|
@ -22,7 +22,7 @@ func (c *CUPSClient) GetDevices() (map[string]Attributes, error) {
|
|||
printerNameMap := make(map[string]Attributes)
|
||||
|
||||
for _, printerAttributes := range resp.Printers {
|
||||
printerNameMap[printerAttributes["device-uri"][0].Value.(string)] = printerAttributes
|
||||
printerNameMap[printerAttributes[PrinterAttributeDeviceURI][0].Value.(string)] = printerAttributes
|
||||
}
|
||||
|
||||
return printerNameMap, nil
|
||||
|
@ -30,8 +30,8 @@ func (c *CUPSClient) GetDevices() (map[string]Attributes, error) {
|
|||
|
||||
func (c *CUPSClient) MoveJob(jobID int, destPrinter string) error {
|
||||
req := NewRequest(OperationCupsMoveJob, 1)
|
||||
req.OperationAttributes["job-uri"] = c.getJobUri(jobID)
|
||||
req.PrinterAttributes["job-printer-uri"] = c.getPrinterUri(destPrinter)
|
||||
req.OperationAttributes[OperationAttributeJobURI] = c.getJobUri(jobID)
|
||||
req.PrinterAttributes[PrinterAttributeJobPrinterURI] = c.getPrinterUri(destPrinter)
|
||||
|
||||
_, err := c.SendRequest(c.getHttpUri("jobs", ""), req)
|
||||
return err
|
||||
|
@ -39,8 +39,8 @@ func (c *CUPSClient) MoveJob(jobID int, destPrinter string) error {
|
|||
|
||||
func (c *CUPSClient) MoveAllJob(srcPrinter, destPrinter string) error {
|
||||
req := NewRequest(OperationCupsMoveJob, 1)
|
||||
req.OperationAttributes["printer-uri"] = c.getPrinterUri(srcPrinter)
|
||||
req.PrinterAttributes["job-printer-uri"] = c.getPrinterUri(destPrinter)
|
||||
req.OperationAttributes[OperationAttributePrinterURI] = c.getPrinterUri(srcPrinter)
|
||||
req.PrinterAttributes[PrinterAttributeJobPrinterURI] = c.getPrinterUri(destPrinter)
|
||||
|
||||
_, err := c.SendRequest(c.getHttpUri("jobs", ""), req)
|
||||
return err
|
||||
|
@ -57,7 +57,7 @@ func (c *CUPSClient) GetPPDs() (map[string]Attributes, error) {
|
|||
ppdNameMap := make(map[string]Attributes)
|
||||
|
||||
for _, printerAttributes := range resp.Printers {
|
||||
ppdNameMap[printerAttributes["ppd-name"][0].Value.(string)] = printerAttributes
|
||||
ppdNameMap[printerAttributes[OperationAttributePPDName][0].Value.(string)] = printerAttributes
|
||||
}
|
||||
|
||||
return ppdNameMap, nil
|
||||
|
@ -65,7 +65,7 @@ func (c *CUPSClient) GetPPDs() (map[string]Attributes, error) {
|
|||
|
||||
func (c *CUPSClient) AcceptJobs(printer string) error {
|
||||
req := NewRequest(OperationCupsAcceptJobs, 1)
|
||||
req.OperationAttributes["printer-uri"] = c.getPrinterUri(printer)
|
||||
req.OperationAttributes[OperationAttributePrinterURI] = c.getPrinterUri(printer)
|
||||
|
||||
_, err := c.SendRequest(c.getHttpUri("admin", ""), req)
|
||||
return err
|
||||
|
@ -73,14 +73,14 @@ func (c *CUPSClient) AcceptJobs(printer string) error {
|
|||
|
||||
func (c *CUPSClient) RejectJobs(printer string) error {
|
||||
req := NewRequest(OperationCupsRejectJobs, 1)
|
||||
req.OperationAttributes["printer-uri"] = c.getPrinterUri(printer)
|
||||
req.OperationAttributes[OperationAttributePrinterURI] = c.getPrinterUri(printer)
|
||||
|
||||
_, err := c.SendRequest(c.getHttpUri("admin", ""), req)
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *CUPSClient) AddPrinterToClass(class, printer string) error {
|
||||
attributes, err := c.GetPrinterAttributes(class, []string{"member-uris"})
|
||||
attributes, err := c.GetPrinterAttributes(class, []string{PrinterAttributeMemberURIs})
|
||||
if err != nil && !IsNotExistsError(err) {
|
||||
return err
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ func (c *CUPSClient) AddPrinterToClass(class, printer string) error {
|
|||
memberURIList := make([]string, 0)
|
||||
|
||||
if !IsNotExistsError(err) {
|
||||
for _, member := range attributes["member-uris"] {
|
||||
for _, member := range attributes[PrinterAttributeMemberURIs] {
|
||||
memberString := strings.Split(member.Value.(string), "/")
|
||||
printerName := memberString[len(memberString)-1]
|
||||
|
||||
|
@ -103,22 +103,22 @@ func (c *CUPSClient) AddPrinterToClass(class, printer string) error {
|
|||
memberURIList = append(memberURIList, c.getPrinterUri(printer))
|
||||
|
||||
req := NewRequest(OperationCupsAddModifyClass, 1)
|
||||
req.OperationAttributes["printer-uri"] = c.getClassUri(class)
|
||||
req.PrinterAttributes["member-uris"] = memberURIList
|
||||
req.OperationAttributes[OperationAttributePrinterURI] = c.getClassUri(class)
|
||||
req.PrinterAttributes[PrinterAttributeMemberURIs] = memberURIList
|
||||
|
||||
_, err = c.SendRequest(c.getHttpUri("admin", ""), req)
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *CUPSClient) DeletePrinterFromClass(class, printer string) error {
|
||||
attributes, err := c.GetPrinterAttributes(class, []string{"member-uris"})
|
||||
attributes, err := c.GetPrinterAttributes(class, []string{PrinterAttributeMemberURIs})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
memberURIList := make([]string, 0)
|
||||
|
||||
for _, member := range attributes["member-uris"] {
|
||||
for _, member := range attributes[PrinterAttributeMemberURIs] {
|
||||
memberString := strings.Split(member.Value.(string), "/")
|
||||
printerName := memberString[len(memberString)-1]
|
||||
|
||||
|
@ -132,8 +132,8 @@ func (c *CUPSClient) DeletePrinterFromClass(class, printer string) error {
|
|||
}
|
||||
|
||||
req := NewRequest(OperationCupsAddModifyClass, 1)
|
||||
req.OperationAttributes["printer-uri"] = c.getClassUri(class)
|
||||
req.PrinterAttributes["member-uris"] = memberURIList
|
||||
req.OperationAttributes[OperationAttributePrinterURI] = c.getClassUri(class)
|
||||
req.PrinterAttributes[PrinterAttributeMemberURIs] = memberURIList
|
||||
|
||||
_, err = c.SendRequest(c.getHttpUri("admin", ""), req)
|
||||
return err
|
||||
|
@ -141,7 +141,7 @@ func (c *CUPSClient) DeletePrinterFromClass(class, printer string) error {
|
|||
|
||||
func (c *CUPSClient) DeleteClass(class string) error {
|
||||
req := NewRequest(OperationCupsDeleteClass, 1)
|
||||
req.OperationAttributes["printer-uri"] = c.getClassUri(class)
|
||||
req.OperationAttributes[OperationAttributePrinterURI] = c.getClassUri(class)
|
||||
|
||||
_, err := c.SendRequest(c.getHttpUri("admin", ""), req)
|
||||
return err
|
||||
|
@ -149,14 +149,14 @@ func (c *CUPSClient) DeleteClass(class string) error {
|
|||
|
||||
func (c *CUPSClient) CreatePrinter(name, deviceURI, ppd string, shared bool, errorPolicy ErrorPolicy, information, location string) error {
|
||||
req := NewRequest(OperationCupsAddModifyPrinter, 1)
|
||||
req.OperationAttributes["printer-uri"] = c.getPrinterUri(name)
|
||||
req.OperationAttributes["ppd-name"] = ppd
|
||||
req.OperationAttributes["printer-is-shared"] = shared
|
||||
req.PrinterAttributes["printer-state-reason"] = "none"
|
||||
req.PrinterAttributes["device-uri"] = deviceURI
|
||||
req.PrinterAttributes["printer-info"] = information
|
||||
req.PrinterAttributes["printer-location"] = location
|
||||
req.PrinterAttributes["printer-error-policy"] = string(errorPolicy)
|
||||
req.OperationAttributes[OperationAttributePrinterURI] = c.getPrinterUri(name)
|
||||
req.OperationAttributes[OperationAttributePPDName] = ppd
|
||||
req.OperationAttributes[OperationAttributePrinterIsShared] = shared
|
||||
req.PrinterAttributes[PrinterAttributePrinterStateReason] = "none"
|
||||
req.PrinterAttributes[PrinterAttributeDeviceURI] = deviceURI
|
||||
req.PrinterAttributes[PrinterAttributePrinterInfo] = information
|
||||
req.PrinterAttributes[PrinterAttributePrinterLocation] = location
|
||||
req.PrinterAttributes[PrinterAttributePrinterErrorPolicy] = string(errorPolicy)
|
||||
|
||||
_, err := c.SendRequest(c.getHttpUri("admin", ""), req)
|
||||
return err
|
||||
|
@ -164,8 +164,8 @@ func (c *CUPSClient) CreatePrinter(name, deviceURI, ppd string, shared bool, err
|
|||
|
||||
func (c *CUPSClient) SetPrinterPPD(printer, ppd string) error {
|
||||
req := NewRequest(OperationCupsAddModifyPrinter, 1)
|
||||
req.OperationAttributes["printer-uri"] = c.getPrinterUri(printer)
|
||||
req.OperationAttributes["ppd-name"] = ppd
|
||||
req.OperationAttributes[OperationAttributePrinterURI] = c.getPrinterUri(printer)
|
||||
req.OperationAttributes[OperationAttributePPDName] = ppd
|
||||
|
||||
_, err := c.SendRequest(c.getHttpUri("admin", ""), req)
|
||||
return err
|
||||
|
@ -173,8 +173,8 @@ func (c *CUPSClient) SetPrinterPPD(printer, ppd string) error {
|
|||
|
||||
func (c *CUPSClient) SetPrinterDeviceURI(printer, deviceURI string) error {
|
||||
req := NewRequest(OperationCupsAddModifyPrinter, 1)
|
||||
req.OperationAttributes["printer-uri"] = c.getPrinterUri(printer)
|
||||
req.PrinterAttributes["device-uri"] = deviceURI
|
||||
req.OperationAttributes[OperationAttributePrinterURI] = c.getPrinterUri(printer)
|
||||
req.PrinterAttributes[PrinterAttributeDeviceURI] = deviceURI
|
||||
|
||||
_, err := c.SendRequest(c.getHttpUri("admin", ""), req)
|
||||
return err
|
||||
|
@ -182,8 +182,8 @@ func (c *CUPSClient) SetPrinterDeviceURI(printer, deviceURI string) error {
|
|||
|
||||
func (c *CUPSClient) SetPrinterIsShared(printer string, shared bool) error {
|
||||
req := NewRequest(OperationCupsAddModifyPrinter, 1)
|
||||
req.OperationAttributes["printer-uri"] = c.getPrinterUri(printer)
|
||||
req.OperationAttributes["printer-is-shared"] = shared
|
||||
req.OperationAttributes[OperationAttributePrinterURI] = c.getPrinterUri(printer)
|
||||
req.OperationAttributes[OperationAttributePrinterIsShared] = shared
|
||||
|
||||
_, err := c.SendRequest(c.getHttpUri("admin", ""), req)
|
||||
return err
|
||||
|
@ -191,8 +191,8 @@ func (c *CUPSClient) SetPrinterIsShared(printer string, shared bool) error {
|
|||
|
||||
func (c *CUPSClient) SetPrinterErrorPolicy(printer string, errorPolicy ErrorPolicy) error {
|
||||
req := NewRequest(OperationCupsAddModifyPrinter, 1)
|
||||
req.OperationAttributes["printer-uri"] = c.getPrinterUri(printer)
|
||||
req.PrinterAttributes["printer-error-policy"] = string(errorPolicy)
|
||||
req.OperationAttributes[OperationAttributePrinterURI] = c.getPrinterUri(printer)
|
||||
req.PrinterAttributes[PrinterAttributePrinterErrorPolicy] = string(errorPolicy)
|
||||
|
||||
_, err := c.SendRequest(c.getHttpUri("admin", ""), req)
|
||||
return err
|
||||
|
@ -200,8 +200,8 @@ func (c *CUPSClient) SetPrinterErrorPolicy(printer string, errorPolicy ErrorPoli
|
|||
|
||||
func (c *CUPSClient) SetPrinterInformation(printer, information string) error {
|
||||
req := NewRequest(OperationCupsAddModifyPrinter, 1)
|
||||
req.OperationAttributes["printer-uri"] = c.getPrinterUri(printer)
|
||||
req.PrinterAttributes["printer-info"] = information
|
||||
req.OperationAttributes[OperationAttributePrinterURI] = c.getPrinterUri(printer)
|
||||
req.PrinterAttributes[PrinterAttributePrinterInfo] = information
|
||||
|
||||
_, err := c.SendRequest(c.getHttpUri("admin", ""), req)
|
||||
return err
|
||||
|
@ -209,8 +209,8 @@ func (c *CUPSClient) SetPrinterInformation(printer, information string) error {
|
|||
|
||||
func (c *CUPSClient) SetPrinterLocation(printer, location string) error {
|
||||
req := NewRequest(OperationCupsAddModifyPrinter, 1)
|
||||
req.OperationAttributes["printer-uri"] = c.getPrinterUri(printer)
|
||||
req.PrinterAttributes["printer-location"] = location
|
||||
req.OperationAttributes[OperationAttributePrinterURI] = c.getPrinterUri(printer)
|
||||
req.PrinterAttributes[PrinterAttributePrinterLocation] = location
|
||||
|
||||
_, err := c.SendRequest(c.getHttpUri("admin", ""), req)
|
||||
return err
|
||||
|
@ -218,7 +218,7 @@ func (c *CUPSClient) SetPrinterLocation(printer, location string) error {
|
|||
|
||||
func (c *CUPSClient) DeletePrinter(printer string) error {
|
||||
req := NewRequest(OperationCupsDeletePrinter, 1)
|
||||
req.OperationAttributes["printer-uri"] = c.getPrinterUri(printer)
|
||||
req.OperationAttributes[OperationAttributePrinterURI] = c.getPrinterUri(printer)
|
||||
|
||||
_, err := c.SendRequest(c.getHttpUri("admin", ""), req)
|
||||
return err
|
||||
|
@ -228,9 +228,9 @@ func (c *CUPSClient) GetPrinters(attributes []string) (map[string]Attributes, er
|
|||
req := NewRequest(OperationCupsGetPrinters, 1)
|
||||
|
||||
if attributes == nil {
|
||||
req.OperationAttributes["requested-attributes"] = DefaultPrinterAttributes
|
||||
req.OperationAttributes[OperationAttributeRequestedAttributes] = DefaultPrinterAttributes
|
||||
} else {
|
||||
req.OperationAttributes["requested-attributes"] = append(attributes, "printer-name")
|
||||
req.OperationAttributes[OperationAttributeRequestedAttributes] = append(attributes, PrinterAttributePrinterName)
|
||||
}
|
||||
|
||||
resp, err := c.SendRequest(c.getHttpUri("", nil), req)
|
||||
|
@ -241,7 +241,7 @@ func (c *CUPSClient) GetPrinters(attributes []string) (map[string]Attributes, er
|
|||
printerNameMap := make(map[string]Attributes)
|
||||
|
||||
for _, printerAttributes := range resp.Printers {
|
||||
printerNameMap[printerAttributes["printer-name"][0].Value.(string)] = printerAttributes
|
||||
printerNameMap[printerAttributes[PrinterAttributePrinterName][0].Value.(string)] = printerAttributes
|
||||
}
|
||||
|
||||
return printerNameMap, nil
|
||||
|
@ -251,9 +251,9 @@ func (c *CUPSClient) GetClasses(attributes []string) (map[string]Attributes, err
|
|||
req := NewRequest(OperationCupsGetClasses, 1)
|
||||
|
||||
if attributes == nil {
|
||||
req.OperationAttributes["requested-attributes"] = DefaultClassAttributes
|
||||
req.OperationAttributes[OperationAttributeRequestedAttributes] = DefaultClassAttributes
|
||||
} else {
|
||||
req.OperationAttributes["requested-attributes"] = append(attributes, "printer-name")
|
||||
req.OperationAttributes[OperationAttributeRequestedAttributes] = append(attributes, PrinterAttributePrinterName)
|
||||
}
|
||||
|
||||
resp, err := c.SendRequest(c.getHttpUri("", nil), req)
|
||||
|
@ -264,7 +264,7 @@ func (c *CUPSClient) GetClasses(attributes []string) (map[string]Attributes, err
|
|||
printerNameMap := make(map[string]Attributes)
|
||||
|
||||
for _, printerAttributes := range resp.Printers {
|
||||
printerNameMap[printerAttributes["printer-name"][0].Value.(string)] = printerAttributes
|
||||
printerNameMap[printerAttributes[PrinterAttributePrinterName][0].Value.(string)] = printerAttributes
|
||||
}
|
||||
|
||||
return printerNameMap, nil
|
||||
|
|
104
ipp-client.go
104
ipp-client.go
|
@ -126,15 +126,21 @@ func (c *IPPClient) SendRequest(url string, req *Request) (*Response, error) {
|
|||
}
|
||||
|
||||
// Print one or more `Document`s using IPP `Create-Job` followed by `Send-Document` request(s).
|
||||
func (c *IPPClient) Print(docs []Document, printer, jobName string, copies, priority int) (int, error) {
|
||||
func (c *IPPClient) PrintDocuments(docs []Document, printer string, jobAttributes map[string]interface{}) (int, error) {
|
||||
printerURI := c.getPrinterUri(printer)
|
||||
|
||||
req := NewRequest(OperationCreateJob, 1)
|
||||
req.OperationAttributes["printer-uri"] = printerURI
|
||||
req.OperationAttributes["requesting-user-name"] = c.username
|
||||
req.OperationAttributes["job-name"] = jobName
|
||||
req.JobAttributes["copies"] = copies
|
||||
req.JobAttributes["job-priority"] = priority
|
||||
req.OperationAttributes[OperationAttributePrinterURI] = printerURI
|
||||
req.OperationAttributes[OperationAttributeRequestingUserName] = c.username
|
||||
|
||||
// set defaults for some attributes, may get overwritten
|
||||
req.OperationAttributes[OperationAttributeJobName] = docs[0].Name
|
||||
req.OperationAttributes[OperationAttributeCopies] = 1
|
||||
req.OperationAttributes[OperationAttributeJobPriority] = DefaultJobPriority
|
||||
|
||||
for key, value := range jobAttributes {
|
||||
req.JobAttributes[key] = value
|
||||
}
|
||||
|
||||
resp, err := c.SendRequest(c.getHttpUri("printers", printer), req)
|
||||
if err != nil {
|
||||
|
@ -145,18 +151,18 @@ func (c *IPPClient) Print(docs []Document, printer, jobName string, copies, prio
|
|||
return 0, errors.New("server doesn't returned a job id")
|
||||
}
|
||||
|
||||
jobID := resp.Jobs[0]["job-id"][0].Value.(int)
|
||||
jobID := resp.Jobs[0][OperationAttributeJobID][0].Value.(int)
|
||||
|
||||
documentCount := len(docs) - 1
|
||||
|
||||
for docID, doc := range docs {
|
||||
req = NewRequest(OperationSendDocument, 2)
|
||||
req.OperationAttributes["printer-uri"] = printerURI
|
||||
req.OperationAttributes["requesting-user-name"] = c.username
|
||||
req.OperationAttributes["job-id"] = jobID
|
||||
req.OperationAttributes["document-name"] = doc.Name
|
||||
req.OperationAttributes["document-format"] = doc.MimeType
|
||||
req.OperationAttributes["last-document"] = docID == documentCount
|
||||
req.OperationAttributes[OperationAttributePrinterURI] = printerURI
|
||||
req.OperationAttributes[OperationAttributeRequestingUserName] = c.username
|
||||
req.OperationAttributes[OperationAttributeJobID] = jobID
|
||||
req.OperationAttributes[OperationAttributeDocumentName] = doc.Name
|
||||
req.OperationAttributes[OperationAttributeDocumentFormat] = doc.MimeType
|
||||
req.OperationAttributes[OperationAttributeLastDocument] = docID == documentCount
|
||||
req.File = doc.Document
|
||||
req.FileSize = doc.Size
|
||||
|
||||
|
@ -190,10 +196,14 @@ func (c *IPPClient) PrintJob(doc Document, printer string, jobAttributes map[str
|
|||
printerURI := c.getPrinterUri(printer)
|
||||
|
||||
req := NewRequest(OperationPrintJob, 1)
|
||||
req.OperationAttributes["printer-uri"] = printerURI
|
||||
req.OperationAttributes["requesting-user-name"] = c.username
|
||||
req.OperationAttributes["job-name"] = doc.Name
|
||||
req.OperationAttributes["document-format"] = doc.MimeType
|
||||
req.OperationAttributes[OperationAttributePrinterURI] = printerURI
|
||||
req.OperationAttributes[OperationAttributeRequestingUserName] = c.username
|
||||
req.OperationAttributes[OperationAttributeJobName] = doc.Name
|
||||
req.OperationAttributes[OperationAttributeDocumentFormat] = doc.MimeType
|
||||
|
||||
// set defaults for some attributes, may get overwritten
|
||||
req.OperationAttributes[OperationAttributeCopies] = 1
|
||||
req.OperationAttributes[OperationAttributeJobPriority] = DefaultJobPriority
|
||||
|
||||
for key, value := range jobAttributes {
|
||||
req.JobAttributes[key] = value
|
||||
|
@ -211,12 +221,12 @@ func (c *IPPClient) PrintJob(doc Document, printer string, jobAttributes map[str
|
|||
return 0, errors.New("server doesn't returned a job id")
|
||||
}
|
||||
|
||||
jobID := resp.Jobs[0]["job-id"][0].Value.(int)
|
||||
jobID := resp.Jobs[0][OperationAttributeJobID][0].Value.(int)
|
||||
|
||||
return jobID, nil
|
||||
}
|
||||
|
||||
func (c *IPPClient) PrintFile(filePath, printer string, copies, priority int) (int, error) {
|
||||
func (c *IPPClient) PrintFile(filePath, printer string, jobAttributes map[string]interface{}) (int, error) {
|
||||
fileStats, err := os.Stat(filePath)
|
||||
if os.IsNotExist(err) {
|
||||
return -1, err
|
||||
|
@ -230,25 +240,27 @@ func (c *IPPClient) PrintFile(filePath, printer string, copies, priority int) (i
|
|||
}
|
||||
defer document.Close()
|
||||
|
||||
return c.Print([]Document{
|
||||
jobAttributes[OperationAttributeJobName] = fileName
|
||||
|
||||
return c.PrintDocuments([]Document{
|
||||
{
|
||||
Document: document,
|
||||
Name: fileName,
|
||||
Size: int(fileStats.Size()),
|
||||
MimeType: MimeTypeOctetStream,
|
||||
},
|
||||
}, printer, fileName, copies, priority)
|
||||
}, printer, jobAttributes)
|
||||
}
|
||||
|
||||
func (c *IPPClient) GetPrinterAttributes(printer string, attributes []string) (Attributes, error) {
|
||||
req := NewRequest(OperationGetPrinterAttributes, 1)
|
||||
req.OperationAttributes["printer-uri"] = c.getPrinterUri(printer)
|
||||
req.OperationAttributes["requesting-user-name"] = c.username
|
||||
req.OperationAttributes[OperationAttributePrinterURI] = c.getPrinterUri(printer)
|
||||
req.OperationAttributes[OperationAttributeRequestingUserName] = c.username
|
||||
|
||||
if attributes == nil {
|
||||
req.OperationAttributes["requested-attributes"] = DefaultPrinterAttributes
|
||||
req.OperationAttributes[OperationAttributeRequestedAttributes] = DefaultPrinterAttributes
|
||||
} else {
|
||||
req.OperationAttributes["requested-attributes"] = attributes
|
||||
req.OperationAttributes[OperationAttributeRequestedAttributes] = attributes
|
||||
}
|
||||
|
||||
resp, err := c.SendRequest(c.getHttpUri("printers", printer), req)
|
||||
|
@ -265,7 +277,7 @@ func (c *IPPClient) GetPrinterAttributes(printer string, attributes []string) (A
|
|||
|
||||
func (c *IPPClient) ResumePrinter(printer string) error {
|
||||
req := NewRequest(OperationResumePrinter, 1)
|
||||
req.OperationAttributes["printer-uri"] = c.getPrinterUri(printer)
|
||||
req.OperationAttributes[OperationAttributePrinterURI] = c.getPrinterUri(printer)
|
||||
|
||||
_, err := c.SendRequest(c.getHttpUri("admin", ""), req)
|
||||
return err
|
||||
|
@ -273,7 +285,7 @@ func (c *IPPClient) ResumePrinter(printer string) error {
|
|||
|
||||
func (c *IPPClient) PausePrinter(printer string) error {
|
||||
req := NewRequest(OperationPausePrinter, 1)
|
||||
req.OperationAttributes["printer-uri"] = c.getPrinterUri(printer)
|
||||
req.OperationAttributes[OperationAttributePrinterURI] = c.getPrinterUri(printer)
|
||||
|
||||
_, err := c.SendRequest(c.getHttpUri("admin", ""), req)
|
||||
return err
|
||||
|
@ -281,12 +293,12 @@ func (c *IPPClient) PausePrinter(printer string) error {
|
|||
|
||||
func (c *IPPClient) GetJobAttributes(jobID int, attributes []string) (Attributes, error) {
|
||||
req := NewRequest(OperationGetJobAttributes, 1)
|
||||
req.OperationAttributes["job-uri"] = c.getJobUri(jobID)
|
||||
req.OperationAttributes[OperationAttributeJobURI] = c.getJobUri(jobID)
|
||||
|
||||
if attributes == nil {
|
||||
req.OperationAttributes["requested-attributes"] = DefaultJobAttributes
|
||||
req.OperationAttributes[OperationAttributeRequestedAttributes] = DefaultJobAttributes
|
||||
} else {
|
||||
req.OperationAttributes["requested-attributes"] = attributes
|
||||
req.OperationAttributes[OperationAttributeRequestedAttributes] = attributes
|
||||
}
|
||||
|
||||
resp, err := c.SendRequest(c.getHttpUri("jobs", jobID), req)
|
||||
|
@ -303,14 +315,14 @@ func (c *IPPClient) GetJobAttributes(jobID int, attributes []string) (Attributes
|
|||
|
||||
func (c *IPPClient) GetJobs(printer string, whichJobs JobStateFilter, myJobs bool, attributes []string) (map[int]Attributes, error) {
|
||||
req := NewRequest(OperationGetJobs, 1)
|
||||
req.OperationAttributes["printer-uri"] = c.getPrinterUri(printer)
|
||||
req.OperationAttributes["which-jobs"] = string(whichJobs)
|
||||
req.OperationAttributes["my-jobs"] = myJobs
|
||||
req.OperationAttributes[OperationAttributePrinterURI] = c.getPrinterUri(printer)
|
||||
req.OperationAttributes[OperationAttributeWhichJobs] = string(whichJobs)
|
||||
req.OperationAttributes[OperationAttributeMyJobs] = myJobs
|
||||
|
||||
if attributes == nil {
|
||||
req.OperationAttributes["requested-attributes"] = DefaultJobAttributes
|
||||
req.OperationAttributes[OperationAttributeRequestedAttributes] = DefaultJobAttributes
|
||||
} else {
|
||||
req.OperationAttributes["requested-attributes"] = append(attributes, "job-id")
|
||||
req.OperationAttributes[OperationAttributeRequestedAttributes] = append(attributes, OperationAttributeJobID)
|
||||
}
|
||||
|
||||
resp, err := c.SendRequest(c.getHttpUri("", nil), req)
|
||||
|
@ -321,7 +333,7 @@ func (c *IPPClient) GetJobs(printer string, whichJobs JobStateFilter, myJobs boo
|
|||
jobIDMap := make(map[int]Attributes)
|
||||
|
||||
for _, jobAttributes := range resp.Jobs {
|
||||
jobIDMap[jobAttributes["job-id"][0].Value.(int)] = jobAttributes
|
||||
jobIDMap[jobAttributes[OperationAttributeJobID][0].Value.(int)] = jobAttributes
|
||||
}
|
||||
|
||||
return jobIDMap, nil
|
||||
|
@ -329,8 +341,8 @@ func (c *IPPClient) GetJobs(printer string, whichJobs JobStateFilter, myJobs boo
|
|||
|
||||
func (c *IPPClient) CancelJob(jobID int, purge bool) error {
|
||||
req := NewRequest(OperationCancelJob, 1)
|
||||
req.OperationAttributes["job-uri"] = c.getJobUri(jobID)
|
||||
req.OperationAttributes["purge-jobs"] = purge
|
||||
req.OperationAttributes[OperationAttributeJobURI] = c.getJobUri(jobID)
|
||||
req.OperationAttributes[OperationAttributePurgeJobs] = purge
|
||||
|
||||
_, err := c.SendRequest(c.getHttpUri("jobs", ""), req)
|
||||
return err
|
||||
|
@ -338,8 +350,8 @@ func (c *IPPClient) CancelJob(jobID int, purge bool) error {
|
|||
|
||||
func (c *IPPClient) CancelAllJob(printer string, purge bool) error {
|
||||
req := NewRequest(OperationCancelJobs, 1)
|
||||
req.OperationAttributes["printer-uri"] = c.getPrinterUri(printer)
|
||||
req.OperationAttributes["purge-jobs"] = purge
|
||||
req.OperationAttributes[OperationAttributePrinterURI] = c.getPrinterUri(printer)
|
||||
req.OperationAttributes[OperationAttributePurgeJobs] = purge
|
||||
|
||||
_, err := c.SendRequest(c.getHttpUri("admin", ""), req)
|
||||
return err
|
||||
|
@ -347,7 +359,7 @@ func (c *IPPClient) CancelAllJob(printer string, purge bool) error {
|
|||
|
||||
func (c *IPPClient) RestartJob(jobID int) error {
|
||||
req := NewRequest(OperationRestartJob, 1)
|
||||
req.OperationAttributes["job-uri"] = c.getJobUri(jobID)
|
||||
req.OperationAttributes[OperationAttributeJobURI] = c.getJobUri(jobID)
|
||||
|
||||
_, err := c.SendRequest(c.getHttpUri("jobs", ""), req)
|
||||
return err
|
||||
|
@ -355,8 +367,8 @@ func (c *IPPClient) RestartJob(jobID int) error {
|
|||
|
||||
func (c *IPPClient) HoldJobUntil(jobID int, holdUntil string) error {
|
||||
req := NewRequest(OperationRestartJob, 1)
|
||||
req.OperationAttributes["job-uri"] = c.getJobUri(jobID)
|
||||
req.JobAttributes["job-hold-until"] = holdUntil
|
||||
req.OperationAttributes[OperationAttributeJobURI] = c.getJobUri(jobID)
|
||||
req.JobAttributes[PrinterAttributeHoldJobUntil] = holdUntil
|
||||
|
||||
_, err := c.SendRequest(c.getHttpUri("jobs", ""), req)
|
||||
return err
|
||||
|
@ -370,14 +382,16 @@ func (c *IPPClient) PrintTestPage(printer string) (int, error) {
|
|||
testPage.WriteString("printer-driver-version paper-size imageable-area job-id options time-at-creation")
|
||||
testPage.WriteString("time-at-processing\n\n")
|
||||
|
||||
return c.Print([]Document{
|
||||
return c.PrintDocuments([]Document{
|
||||
{
|
||||
Document: testPage,
|
||||
Name: "Test Page",
|
||||
Size: testPage.Len(),
|
||||
MimeType: MimeTypePostscript,
|
||||
},
|
||||
}, printer, "Test Page", 1, DefaultJobPriority)
|
||||
}, printer, map[string]interface{}{
|
||||
OperationAttributeJobName: "Test Page",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *IPPClient) TestConnection() error {
|
||||
|
|
Loading…
Reference in New Issue