From 4018bb14e654d5147e19f93293df963eab9a8169 Mon Sep 17 00:00:00 2001 From: Fabian Weber <> Date: Mon, 9 Mar 2020 10:36:29 +0100 Subject: [PATCH] Removed job and operation attributes prefix Added more attribute constants --- constants.go | 182 ++++++++++++++++++++++++++++--------------------- cups-client.go | 88 ++++++++++++------------ ipp-client.go | 96 +++++++++++++------------- reqest.go | 4 +- response.go | 4 +- 5 files changed, 199 insertions(+), 175 deletions(-) diff --git a/constants.go b/constants.go index 72bdafa..db22014 100644 --- a/constants.go +++ b/constants.go @@ -208,7 +208,7 @@ const ( TagUnsupportedValue = 0x10 TagDefault = 0x11 TagUnknown = 0x12 - TagNoValue = 0x013 + TagNoValue = 0x13 TagNotSettable = 0x15 TagDeleteAttr = 0x16 TagAdminDefine = 0x17 @@ -300,88 +300,112 @@ const ( ) 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" - OperationAttributeFirstJobID = "first-job-id" - OperationAttributeLimit = "limit" -) - -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" + AttributeCopies string = "copies" + AttributeDocumentFormat = "document-format" + AttributeDocumentName = "document-name" + AttributeJobID = "job-id" + AttributeJobName = "job-name" + AttributeJobPriority = "job-priority" + AttributeJobURI = "job-uri" + AttributeLastDocument = "last-document" + AttributeMyJobs = "my-jobs" + AttributePPDName = "ppd-name" + AttributePrinterIsShared = "printer-is-shared" + AttributePrinterURI = "printer-uri" + AttributePurgeJobs = "purge-jobs" + AttributeRequestedAttributes = "requested-attributes" + AttributeRequestingUserName = "requesting-user-name" + AttributeWhichJobs = "which-jobs" + AttributeFirstJobID = "first-job-id" + AttributeLimit = "limit" + AttributeStatusMessage = "status-message" + AttributeCharset = "attributes-charset" + AttributeNaturalLanguage = "attributes-natural-language" + AttributeDeviceURI = "device-uri" + AttributeHoldJobUntil = "job-hold-until" + AttributePrinterErrorPolicy = "printer-error-policy" + AttributePrinterInfo = "printer-info" + AttributePrinterLocation = "printer-location" + AttributePrinterName = "printer-name" + AttributePrinterStateReason = "printer-state-reason" + AttributeJobPrinterURI = "job-printer-uri" + AttributeMemberURIs = "member-uris" + AttributeDocumentNumber = "document-number" + AttributeDocumentState = "document-state" + AttributeFinishings = "finishings" + AttributeJobHoldUntil = "hold-job-until" + AttributeJobSheets = "job-sheets" + AttributeJobState = "job-state" + AttributeJobStateReason = "job-state-reason" + AttributeMedia = "media" + AttributeNumberUp = "number-up" + AttributeOrientationRequested = "orientation-requested" + AttributePrintQuality = "print-quality" + AttributePrinterIsAcceptingJobs = "printer-is-accepting-jobs" + AttributePrinterResolution = "printer-resolution" + AttributePrinterState = "printer-state" + AttributeMemberNames = "member-names" + AttributePrinterType = "printer-type" + AttributePrinterMarkAndModel = "printer-make-and-model" + AttributePrinterStateMessage = "printer-state-message" + AttributePrinterUriSupported = "printer-uri-supported" + AttributeJobMediaProgress = "job-media-progress" + AttributeJobKilobyteOctets = "job-k-octets" + AttributeNumberOfDocuments = "number-of-documents" + AttributeJobOriginatingUserName = "job-originating-user-name" ) var ( - DefaultClassAttributes = []string{"printer-name", "member-names"} - DefaultPrinterAttributes = []string{"printer-name", "printer-type", "printer-location", "printer-info", - "printer-make-and-model", "printer-state", "printer-state-message", "printer-state-reason", - "printer-uri-supported", "device-uri", "printer-is-shared"} - DefaultJobAttributes = []string{"job-id", "job-name", "printer-uri", "job-state", "job-state-reasons", - "job-hold-until", "job-media-progress", "job-k-octets", "number-of-documents", "copies", - "job-originating-user-name"} + DefaultClassAttributes = []string{AttributePrinterName, AttributeMemberNames} + DefaultPrinterAttributes = []string{AttributePrinterName, AttributePrinterType, AttributePrinterLocation, AttributePrinterInfo, + AttributePrinterMarkAndModel, AttributePrinterState, AttributePrinterStateMessage, AttributePrinterStateReason, + AttributePrinterUriSupported, AttributeDeviceURI, AttributePrinterIsShared} + DefaultJobAttributes = []string{AttributeJobID, AttributeJobName, AttributePrinterURI, AttributeJobState, AttributeJobStateReason, + AttributeJobHoldUntil, AttributeJobMediaProgress, AttributeJobKilobyteOctets, AttributeNumberOfDocuments, AttributeCopies, + AttributeJobOriginatingUserName} AttributeTagMapping = map[string]Tag{ - "attributes-charset": TagCharset, - "attributes-natural-language": TagLanguage, - "copies": TagInteger, - "device-uri": TagUri, - "document-format": TagMimeType, - "document-name": TagName, - "document-number": TagInteger, - "document-state": TagEnum, - "finishings": TagEnum, - "hold-job-until": TagKeyword, - "job-hold-until": TagKeyword, - "job-id": TagInteger, - "job-name": TagName, - "job-printer-uri": TagUri, - "job-priority": TagInteger, - "job-sheets": TagName, - "job-state": TagEnum, - "job-state-reason": TagKeyword, - "job-uri": TagUri, - "last-document": TagBoolean, - "media": TagKeyword, - "member-uris": TagUri, - "my-jobs": TagBoolean, - "number-up": TagInteger, - "orientation-requested": TagEnum, - "ppd-name": TagName, - "print-quality": TagEnum, - "printer-error-policy": TagName, - "printer-info": TagText, - "printer-is-accepting-jobs": TagBoolean, - "printer-is-shared": TagBoolean, - "printer-location": TagText, - "printer-resolution": TagResolution, - "printer-state": TagEnum, - "printer-state-reason": TagKeyword, - "printer-uri": TagUri, - "purge-jobs": TagBoolean, - "requested-attributes": TagKeyword, - "requesting-user-name": TagName, - "which-jobs": TagKeyword, - "first-job-id": TagInteger, + AttributeCharset: TagCharset, + AttributeNaturalLanguage: TagLanguage, + AttributeCopies: TagInteger, + AttributeDeviceURI: TagUri, + AttributeDocumentFormat: TagMimeType, + AttributeDocumentName: TagName, + AttributeDocumentNumber: TagInteger, + AttributeDocumentState: TagEnum, + AttributeFinishings: TagEnum, + AttributeJobHoldUntil: TagKeyword, + AttributeHoldJobUntil: TagKeyword, + AttributeJobID: TagInteger, + AttributeJobName: TagName, + AttributeJobPrinterURI: TagUri, + AttributeJobPriority: TagInteger, + AttributeJobSheets: TagName, + AttributeJobState: TagEnum, + AttributeJobStateReason: TagKeyword, + AttributeJobURI: TagUri, + AttributeLastDocument: TagBoolean, + AttributeMedia: TagKeyword, + AttributeMemberURIs: TagUri, + AttributeMyJobs: TagBoolean, + AttributeNumberUp: TagInteger, + AttributeOrientationRequested: TagEnum, + AttributePPDName: TagName, + AttributePrintQuality: TagEnum, + AttributePrinterErrorPolicy: TagName, + AttributePrinterInfo: TagText, + AttributePrinterIsAcceptingJobs: TagBoolean, + AttributePrinterIsShared: TagBoolean, + AttributePrinterLocation: TagText, + AttributePrinterResolution: TagResolution, + AttributePrinterState: TagEnum, + AttributePrinterStateReason: TagKeyword, + AttributePrinterURI: TagUri, + AttributePurgeJobs: TagBoolean, + AttributeRequestedAttributes: TagKeyword, + AttributeRequestingUserName: TagName, + AttributeWhichJobs: TagKeyword, + AttributeFirstJobID: TagInteger, + AttributeStatusMessage: TagText, } ) diff --git a/cups-client.go b/cups-client.go index f90d090..a59b807 100644 --- a/cups-client.go +++ b/cups-client.go @@ -22,7 +22,7 @@ func (c *CUPSClient) GetDevices() (map[string]Attributes, error) { printerNameMap := make(map[string]Attributes) for _, printerAttributes := range resp.PrinterAttributes { - printerNameMap[printerAttributes[PrinterAttributeDeviceURI][0].Value.(string)] = printerAttributes + printerNameMap[printerAttributes[AttributeDeviceURI][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[OperationAttributeJobURI] = c.getJobUri(jobID) - req.PrinterAttributes[PrinterAttributeJobPrinterURI] = c.getPrinterUri(destPrinter) + req.OperationAttributes[AttributeJobURI] = c.getJobUri(jobID) + req.PrinterAttributes[AttributeJobPrinterURI] = c.getPrinterUri(destPrinter) _, err := c.SendRequest(c.getHttpUri("jobs", ""), req, nil) 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[OperationAttributePrinterURI] = c.getPrinterUri(srcPrinter) - req.PrinterAttributes[PrinterAttributeJobPrinterURI] = c.getPrinterUri(destPrinter) + req.OperationAttributes[AttributePrinterURI] = c.getPrinterUri(srcPrinter) + req.PrinterAttributes[AttributeJobPrinterURI] = c.getPrinterUri(destPrinter) _, err := c.SendRequest(c.getHttpUri("jobs", ""), req, nil) return err @@ -57,7 +57,7 @@ func (c *CUPSClient) GetPPDs() (map[string]Attributes, error) { ppdNameMap := make(map[string]Attributes) for _, printerAttributes := range resp.PrinterAttributes { - ppdNameMap[printerAttributes[OperationAttributePPDName][0].Value.(string)] = printerAttributes + ppdNameMap[printerAttributes[AttributePPDName][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[OperationAttributePrinterURI] = c.getPrinterUri(printer) + req.OperationAttributes[AttributePrinterURI] = c.getPrinterUri(printer) _, err := c.SendRequest(c.getHttpUri("admin", ""), req, nil) 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[OperationAttributePrinterURI] = c.getPrinterUri(printer) + req.OperationAttributes[AttributePrinterURI] = c.getPrinterUri(printer) _, err := c.SendRequest(c.getHttpUri("admin", ""), req, nil) return err } func (c *CUPSClient) AddPrinterToClass(class, printer string) error { - attributes, err := c.GetPrinterAttributes(class, []string{PrinterAttributeMemberURIs}) + attributes, err := c.GetPrinterAttributes(class, []string{AttributeMemberURIs}) 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[PrinterAttributeMemberURIs] { + for _, member := range attributes[AttributeMemberURIs] { 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[OperationAttributePrinterURI] = c.getClassUri(class) - req.PrinterAttributes[PrinterAttributeMemberURIs] = memberURIList + req.OperationAttributes[AttributePrinterURI] = c.getClassUri(class) + req.PrinterAttributes[AttributeMemberURIs] = memberURIList _, err = c.SendRequest(c.getHttpUri("admin", ""), req, nil) return err } func (c *CUPSClient) DeletePrinterFromClass(class, printer string) error { - attributes, err := c.GetPrinterAttributes(class, []string{PrinterAttributeMemberURIs}) + attributes, err := c.GetPrinterAttributes(class, []string{AttributeMemberURIs}) if err != nil { return err } memberURIList := make([]string, 0) - for _, member := range attributes[PrinterAttributeMemberURIs] { + for _, member := range attributes[AttributeMemberURIs] { 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[OperationAttributePrinterURI] = c.getClassUri(class) - req.PrinterAttributes[PrinterAttributeMemberURIs] = memberURIList + req.OperationAttributes[AttributePrinterURI] = c.getClassUri(class) + req.PrinterAttributes[AttributeMemberURIs] = memberURIList _, err = c.SendRequest(c.getHttpUri("admin", ""), req, nil) 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[OperationAttributePrinterURI] = c.getClassUri(class) + req.OperationAttributes[AttributePrinterURI] = c.getClassUri(class) _, err := c.SendRequest(c.getHttpUri("admin", ""), req, nil) 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[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) + req.OperationAttributes[AttributePrinterURI] = c.getPrinterUri(name) + req.OperationAttributes[AttributePPDName] = ppd + req.OperationAttributes[AttributePrinterIsShared] = shared + req.PrinterAttributes[AttributePrinterStateReason] = "none" + req.PrinterAttributes[AttributeDeviceURI] = deviceURI + req.PrinterAttributes[AttributePrinterInfo] = information + req.PrinterAttributes[AttributePrinterLocation] = location + req.PrinterAttributes[AttributePrinterErrorPolicy] = string(errorPolicy) _, err := c.SendRequest(c.getHttpUri("admin", ""), req, nil) 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[OperationAttributePrinterURI] = c.getPrinterUri(printer) - req.OperationAttributes[OperationAttributePPDName] = ppd + req.OperationAttributes[AttributePrinterURI] = c.getPrinterUri(printer) + req.OperationAttributes[AttributePPDName] = ppd _, err := c.SendRequest(c.getHttpUri("admin", ""), req, nil) 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[OperationAttributePrinterURI] = c.getPrinterUri(printer) - req.PrinterAttributes[PrinterAttributeDeviceURI] = deviceURI + req.OperationAttributes[AttributePrinterURI] = c.getPrinterUri(printer) + req.PrinterAttributes[AttributeDeviceURI] = deviceURI _, err := c.SendRequest(c.getHttpUri("admin", ""), req, nil) 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[OperationAttributePrinterURI] = c.getPrinterUri(printer) - req.OperationAttributes[OperationAttributePrinterIsShared] = shared + req.OperationAttributes[AttributePrinterURI] = c.getPrinterUri(printer) + req.OperationAttributes[AttributePrinterIsShared] = shared _, err := c.SendRequest(c.getHttpUri("admin", ""), req, nil) 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[OperationAttributePrinterURI] = c.getPrinterUri(printer) - req.PrinterAttributes[PrinterAttributePrinterErrorPolicy] = string(errorPolicy) + req.OperationAttributes[AttributePrinterURI] = c.getPrinterUri(printer) + req.PrinterAttributes[AttributePrinterErrorPolicy] = string(errorPolicy) _, err := c.SendRequest(c.getHttpUri("admin", ""), req, nil) 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[OperationAttributePrinterURI] = c.getPrinterUri(printer) - req.PrinterAttributes[PrinterAttributePrinterInfo] = information + req.OperationAttributes[AttributePrinterURI] = c.getPrinterUri(printer) + req.PrinterAttributes[AttributePrinterInfo] = information _, err := c.SendRequest(c.getHttpUri("admin", ""), req, nil) 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[OperationAttributePrinterURI] = c.getPrinterUri(printer) - req.PrinterAttributes[PrinterAttributePrinterLocation] = location + req.OperationAttributes[AttributePrinterURI] = c.getPrinterUri(printer) + req.PrinterAttributes[AttributePrinterLocation] = location _, err := c.SendRequest(c.getHttpUri("admin", ""), req, nil) 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[OperationAttributePrinterURI] = c.getPrinterUri(printer) + req.OperationAttributes[AttributePrinterURI] = c.getPrinterUri(printer) _, err := c.SendRequest(c.getHttpUri("admin", ""), req, nil) 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[OperationAttributeRequestedAttributes] = DefaultPrinterAttributes + req.OperationAttributes[AttributeRequestedAttributes] = DefaultPrinterAttributes } else { - req.OperationAttributes[OperationAttributeRequestedAttributes] = append(attributes, PrinterAttributePrinterName) + req.OperationAttributes[AttributeRequestedAttributes] = append(attributes, AttributePrinterName) } resp, err := c.SendRequest(c.getHttpUri("", nil), req, nil) @@ -241,7 +241,7 @@ func (c *CUPSClient) GetPrinters(attributes []string) (map[string]Attributes, er printerNameMap := make(map[string]Attributes) for _, printerAttributes := range resp.PrinterAttributes { - printerNameMap[printerAttributes[PrinterAttributePrinterName][0].Value.(string)] = printerAttributes + printerNameMap[printerAttributes[AttributePrinterName][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[OperationAttributeRequestedAttributes] = DefaultClassAttributes + req.OperationAttributes[AttributeRequestedAttributes] = DefaultClassAttributes } else { - req.OperationAttributes[OperationAttributeRequestedAttributes] = append(attributes, PrinterAttributePrinterName) + req.OperationAttributes[AttributeRequestedAttributes] = append(attributes, AttributePrinterName) } resp, err := c.SendRequest(c.getHttpUri("", nil), req, nil) @@ -264,7 +264,7 @@ func (c *CUPSClient) GetClasses(attributes []string) (map[string]Attributes, err printerNameMap := make(map[string]Attributes) for _, printerAttributes := range resp.PrinterAttributes { - printerNameMap[printerAttributes[PrinterAttributePrinterName][0].Value.(string)] = printerAttributes + printerNameMap[printerAttributes[AttributePrinterName][0].Value.(string)] = printerAttributes } return printerNameMap, nil diff --git a/ipp-client.go b/ipp-client.go index befeb89..483a00b 100644 --- a/ipp-client.go +++ b/ipp-client.go @@ -124,13 +124,13 @@ func (c *IPPClient) PrintDocuments(docs []Document, printer string, jobAttribute printerURI := c.getPrinterUri(printer) req := NewRequest(OperationCreateJob, 1) - req.OperationAttributes[OperationAttributePrinterURI] = printerURI - req.OperationAttributes[OperationAttributeRequestingUserName] = c.username + req.OperationAttributes[AttributePrinterURI] = printerURI + req.OperationAttributes[AttributeRequestingUserName] = c.username // set defaults for some attributes, may get overwritten - req.OperationAttributes[OperationAttributeJobName] = docs[0].Name - req.OperationAttributes[OperationAttributeCopies] = 1 - req.OperationAttributes[OperationAttributeJobPriority] = DefaultJobPriority + req.OperationAttributes[AttributeJobName] = docs[0].Name + req.OperationAttributes[AttributeCopies] = 1 + req.OperationAttributes[AttributeJobPriority] = DefaultJobPriority for key, value := range jobAttributes { req.JobAttributes[key] = value @@ -145,18 +145,18 @@ func (c *IPPClient) PrintDocuments(docs []Document, printer string, jobAttribute return 0, errors.New("server doesn't returned a job id") } - jobID := resp.JobAttributes[0][OperationAttributeJobID][0].Value.(int) + jobID := resp.JobAttributes[0][AttributeJobID][0].Value.(int) documentCount := len(docs) - 1 for docID, doc := range docs { req = NewRequest(OperationSendDocument, 2) - 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.OperationAttributes[AttributePrinterURI] = printerURI + req.OperationAttributes[AttributeRequestingUserName] = c.username + req.OperationAttributes[AttributeJobID] = jobID + req.OperationAttributes[AttributeDocumentName] = doc.Name + req.OperationAttributes[AttributeDocumentFormat] = doc.MimeType + req.OperationAttributes[AttributeLastDocument] = docID == documentCount req.File = doc.Document req.FileSize = doc.Size @@ -190,14 +190,14 @@ func (c *IPPClient) PrintJob(doc Document, printer string, jobAttributes map[str printerURI := c.getPrinterUri(printer) req := NewRequest(OperationPrintJob, 1) - req.OperationAttributes[OperationAttributePrinterURI] = printerURI - req.OperationAttributes[OperationAttributeRequestingUserName] = c.username - req.OperationAttributes[OperationAttributeJobName] = doc.Name - req.OperationAttributes[OperationAttributeDocumentFormat] = doc.MimeType + req.OperationAttributes[AttributePrinterURI] = printerURI + req.OperationAttributes[AttributeRequestingUserName] = c.username + req.OperationAttributes[AttributeJobName] = doc.Name + req.OperationAttributes[AttributeDocumentFormat] = doc.MimeType // set defaults for some attributes, may get overwritten - req.OperationAttributes[OperationAttributeCopies] = 1 - req.OperationAttributes[OperationAttributeJobPriority] = DefaultJobPriority + req.OperationAttributes[AttributeCopies] = 1 + req.OperationAttributes[AttributeJobPriority] = DefaultJobPriority for key, value := range jobAttributes { req.JobAttributes[key] = value @@ -215,7 +215,7 @@ func (c *IPPClient) PrintJob(doc Document, printer string, jobAttributes map[str return 0, errors.New("server doesn't returned a job id") } - jobID := resp.JobAttributes[0][OperationAttributeJobID][0].Value.(int) + jobID := resp.JobAttributes[0][AttributeJobID][0].Value.(int) return jobID, nil } @@ -234,7 +234,7 @@ func (c *IPPClient) PrintFile(filePath, printer string, jobAttributes map[string } defer document.Close() - jobAttributes[OperationAttributeJobName] = fileName + jobAttributes[AttributeJobName] = fileName return c.PrintDocuments([]Document{ { @@ -248,13 +248,13 @@ func (c *IPPClient) PrintFile(filePath, printer string, jobAttributes map[string func (c *IPPClient) GetPrinterAttributes(printer string, attributes []string) (Attributes, error) { req := NewRequest(OperationGetPrinterAttributes, 1) - req.OperationAttributes[OperationAttributePrinterURI] = c.getPrinterUri(printer) - req.OperationAttributes[OperationAttributeRequestingUserName] = c.username + req.OperationAttributes[AttributePrinterURI] = c.getPrinterUri(printer) + req.OperationAttributes[AttributeRequestingUserName] = c.username if attributes == nil { - req.OperationAttributes[OperationAttributeRequestedAttributes] = DefaultPrinterAttributes + req.OperationAttributes[AttributeRequestedAttributes] = DefaultPrinterAttributes } else { - req.OperationAttributes[OperationAttributeRequestedAttributes] = attributes + req.OperationAttributes[AttributeRequestedAttributes] = attributes } resp, err := c.SendRequest(c.getHttpUri("printers", printer), req, nil) @@ -271,7 +271,7 @@ func (c *IPPClient) GetPrinterAttributes(printer string, attributes []string) (A func (c *IPPClient) ResumePrinter(printer string) error { req := NewRequest(OperationResumePrinter, 1) - req.OperationAttributes[OperationAttributePrinterURI] = c.getPrinterUri(printer) + req.OperationAttributes[AttributePrinterURI] = c.getPrinterUri(printer) _, err := c.SendRequest(c.getHttpUri("admin", ""), req, nil) return err @@ -279,7 +279,7 @@ func (c *IPPClient) ResumePrinter(printer string) error { func (c *IPPClient) PausePrinter(printer string) error { req := NewRequest(OperationPausePrinter, 1) - req.OperationAttributes[OperationAttributePrinterURI] = c.getPrinterUri(printer) + req.OperationAttributes[AttributePrinterURI] = c.getPrinterUri(printer) _, err := c.SendRequest(c.getHttpUri("admin", ""), req, nil) return err @@ -287,12 +287,12 @@ func (c *IPPClient) PausePrinter(printer string) error { func (c *IPPClient) GetJobAttributes(jobID int, attributes []string) (Attributes, error) { req := NewRequest(OperationGetJobAttributes, 1) - req.OperationAttributes[OperationAttributeJobURI] = c.getJobUri(jobID) + req.OperationAttributes[AttributeJobURI] = c.getJobUri(jobID) if attributes == nil { - req.OperationAttributes[OperationAttributeRequestedAttributes] = DefaultJobAttributes + req.OperationAttributes[AttributeRequestedAttributes] = DefaultJobAttributes } else { - req.OperationAttributes[OperationAttributeRequestedAttributes] = attributes + req.OperationAttributes[AttributeRequestedAttributes] = attributes } resp, err := c.SendRequest(c.getHttpUri("jobs", jobID), req, nil) @@ -309,33 +309,33 @@ func (c *IPPClient) GetJobAttributes(jobID int, attributes []string) (Attributes func (c *IPPClient) GetJobs(printer, class string, whichJobs JobStateFilter, myJobs bool, firstJobId, limit int, attributes []string) (map[int]Attributes, error) { req := NewRequest(OperationGetJobs, 1) - req.OperationAttributes[OperationAttributeWhichJobs] = string(whichJobs) - req.OperationAttributes[OperationAttributeMyJobs] = myJobs + req.OperationAttributes[AttributeWhichJobs] = string(whichJobs) + req.OperationAttributes[AttributeMyJobs] = myJobs if printer != "" { - req.OperationAttributes[OperationAttributePrinterURI] = c.getPrinterUri(printer) + req.OperationAttributes[AttributePrinterURI] = c.getPrinterUri(printer) } else if class != "" { - req.OperationAttributes[OperationAttributePrinterURI] = c.getClassUri(printer) + req.OperationAttributes[AttributePrinterURI] = c.getClassUri(printer) } else { - req.OperationAttributes[OperationAttributePrinterURI] = "ipp://localhost/" + req.OperationAttributes[AttributePrinterURI] = "ipp://localhost/" } if firstJobId > 0 { - req.OperationAttributes[OperationAttributeFirstJobID] = firstJobId + req.OperationAttributes[AttributeFirstJobID] = firstJobId } if limit > 0 { - req.OperationAttributes[OperationAttributeLimit] = limit + req.OperationAttributes[AttributeLimit] = limit } if myJobs { - req.OperationAttributes[OperationAttributeRequestingUserName] = c.username + req.OperationAttributes[AttributeRequestingUserName] = c.username } if attributes == nil { - req.OperationAttributes[OperationAttributeRequestedAttributes] = DefaultJobAttributes + req.OperationAttributes[AttributeRequestedAttributes] = DefaultJobAttributes } else { - req.OperationAttributes[OperationAttributeRequestedAttributes] = append(attributes, OperationAttributeJobID) + req.OperationAttributes[AttributeRequestedAttributes] = append(attributes, AttributeJobID) } resp, err := c.SendRequest(c.getHttpUri("", nil), req, nil) @@ -346,7 +346,7 @@ func (c *IPPClient) GetJobs(printer, class string, whichJobs JobStateFilter, myJ jobIDMap := make(map[int]Attributes) for _, jobAttributes := range resp.JobAttributes { - jobIDMap[jobAttributes[OperationAttributeJobID][0].Value.(int)] = jobAttributes + jobIDMap[jobAttributes[AttributeJobID][0].Value.(int)] = jobAttributes } return jobIDMap, nil @@ -354,8 +354,8 @@ func (c *IPPClient) GetJobs(printer, class string, whichJobs JobStateFilter, myJ func (c *IPPClient) CancelJob(jobID int, purge bool) error { req := NewRequest(OperationCancelJob, 1) - req.OperationAttributes[OperationAttributeJobURI] = c.getJobUri(jobID) - req.OperationAttributes[OperationAttributePurgeJobs] = purge + req.OperationAttributes[AttributeJobURI] = c.getJobUri(jobID) + req.OperationAttributes[AttributePurgeJobs] = purge _, err := c.SendRequest(c.getHttpUri("jobs", ""), req, nil) return err @@ -363,8 +363,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[OperationAttributePrinterURI] = c.getPrinterUri(printer) - req.OperationAttributes[OperationAttributePurgeJobs] = purge + req.OperationAttributes[AttributePrinterURI] = c.getPrinterUri(printer) + req.OperationAttributes[AttributePurgeJobs] = purge _, err := c.SendRequest(c.getHttpUri("admin", ""), req, nil) return err @@ -372,7 +372,7 @@ func (c *IPPClient) CancelAllJob(printer string, purge bool) error { func (c *IPPClient) RestartJob(jobID int) error { req := NewRequest(OperationRestartJob, 1) - req.OperationAttributes[OperationAttributeJobURI] = c.getJobUri(jobID) + req.OperationAttributes[AttributeJobURI] = c.getJobUri(jobID) _, err := c.SendRequest(c.getHttpUri("jobs", ""), req, nil) return err @@ -380,8 +380,8 @@ func (c *IPPClient) RestartJob(jobID int) error { func (c *IPPClient) HoldJobUntil(jobID int, holdUntil string) error { req := NewRequest(OperationRestartJob, 1) - req.OperationAttributes[OperationAttributeJobURI] = c.getJobUri(jobID) - req.JobAttributes[PrinterAttributeHoldJobUntil] = holdUntil + req.OperationAttributes[AttributeJobURI] = c.getJobUri(jobID) + req.JobAttributes[AttributeHoldJobUntil] = holdUntil _, err := c.SendRequest(c.getHttpUri("jobs", ""), req, nil) return err @@ -403,7 +403,7 @@ func (c *IPPClient) PrintTestPage(printer string) (int, error) { MimeType: MimeTypePostscript, }, }, printer, map[string]interface{}{ - OperationAttributeJobName: "Test Page", + AttributeJobName: "Test Page", }) } diff --git a/reqest.go b/reqest.go index 8223e5b..03a76dc 100644 --- a/reqest.go +++ b/reqest.go @@ -59,11 +59,11 @@ func (r *Request) Encode() ([]byte, error) { return nil, err } - if err := enc.Encode("attributes-charset", Charset); err != nil { + if err := enc.Encode(AttributeCharset, Charset); err != nil { return nil, err } - if err := enc.Encode("attributes-natural-language", CharsetLanguage); err != nil { + if err := enc.Encode(AttributeNaturalLanguage, CharsetLanguage); err != nil { return nil, err } diff --git a/response.go b/response.go index 7ff3e7b..0938761 100644 --- a/response.go +++ b/response.go @@ -70,11 +70,11 @@ func (r *Response) Encode(data io.Writer) ([]byte, error) { return nil, err } - if err := enc.Encode("attributes-charset", Charset); err != nil { + if err := enc.Encode(AttributeCharset, Charset); err != nil { return nil, err } - if err := enc.Encode("attributes-natural-language", CharsetLanguage); err != nil { + if err := enc.Encode(AttributeNaturalLanguage, CharsetLanguage); err != nil { return nil, err }