Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for listing cups printers #8

Merged
merged 5 commits into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added <summary> to getprinterrequest and changed Mapper to mapper in …
…ippprotocol
  • Loading branch information
BlackHeart-TF committed May 11, 2022
commit ff944559b1187eaff47403ccc911df0328ddb9b9
133 changes: 77 additions & 56 deletions SharpIpp/Model/CUPSGetPrintersRequest.cs
Original file line number Diff line number Diff line change
@@ -1,70 +1,91 @@
using System;
using System.Collections.Generic;

namespace SharpIpp.Model
{
public class CUPSGetPrintersRequest : IIppPrinterRequest
{
/// The client OPTIONALLY supplies this attribute to select the
/// first printer that is returned.
public string? FirstPrinterName { get; set; }

/// The client OPTIONALLY supplies this attribute. The Printer
/// object MUST support this attribute. It is an integer value that
/// determines the maximum number of jobs that a client will
/// receive from the Printer even if "which-jobs" or "my-jobs"
/// constrain which jobs are returned. The limit is a "stateless
/// limit" in that if the value supplied by the client is 'N', then
/// only the first 'N' jobs are returned in the Get-Jobs Response.
/// There is no mechanism to allow for the next 'M' jobs after the
/// first 'N' jobs. If the client does not supply this attribute,
/// the Printer object responds with all applicable jobs.
public int? Limit { get; set; }
using System;
using System.Collections.Generic;

namespace SharpIpp.Model
{
/// <summary>
/// Request to get a list of printers from a CUPS IPP server
/// <seealso href="http://www.cups.org/doc/spec-ipp.html#CUPS_GET_PRINTERS"/>
/// </summary>
public class CUPSGetPrintersRequest : IIppPrinterRequest
{
///<summary>
/// The client OPTIONALLY supplies this attribute to select the
/// first printer that is returned.
/// </summary>
public string? FirstPrinterName { get; set; }

///<summary>
/// The client OPTIONALLY supplies this attribute. The Printer
/// object MUST support this attribute. It is an integer value that
/// determines the maximum number of jobs that a client will
/// receive from the Printer even if "which-jobs" or "my-jobs"
/// constrain which jobs are returned. The limit is a "stateless
/// limit" in that if the value supplied by the client is 'N', then
/// only the first 'N' jobs are returned in the Get-Jobs Response.
/// There is no mechanism to allow for the next 'M' jobs after the
/// first 'N' jobs. If the client does not supply this attribute,
/// the Printer object responds with all applicable jobs.
///</summary>
public int? Limit { get; set; }

///<summary>
///The client OPTIONALLY supplies this attribute to select which printer is returned.
///</summary>
public int? PrinterID { get; set; }

///<summary>
///The client OPTIONALLY supplies this attribute to select which printers are returned.
///</summary>
public string? PrinterLocation { get; set; }


///<summary>
///The client OPTIONALLY supplies a printer type enumeration to select which printers are returned.
public PrinterType? PrinterType { get; set; }

///</summary>
public PrinterType? PrinterType { get; set; }

///<summary>
///The client OPTIONALLY supplies a printer type mask enumeration to select which bits are used in the "printer-type" attribute.
BlackHeart-TF marked this conversation as resolved.
Show resolved Hide resolved
///</summary>
public PrinterType? PrinterTypeMask { get; set; }

/// <summary>
/// The client OPTIONALLY supplies this attribute. The Printer
/// object MUST support this attribute. It is a set of Job
/// attribute names and/or attribute groups names in whose values
/// the requester is interested. This set of attributes is
/// returned for each Job object that is returned. The allowed
/// attribute group names are the same as those defined in the
/// Get-Job-Attributes operation in section 3.3.4. If the client
/// does not supply this attribute, the Printer MUST respond as if
/// the client had supplied this attribute with two values: 'job-
/// uri' and 'job-id'.
/// </summary>
public string[]? RequestedAttributes { get; set; }

public IppVersion Version { get; set; } = IppVersion.CUPS10;
public int RequestId { get; set; } = 1;
public Uri PrinterUri { get; set; } = null!;

/// <summary>
/// The "requesting-user-name" (name(MAX)) attribute SHOULD be
/// supplied by the client
/// </summary>
public string? RequestingUserName { get; set; }

public IEnumerable<IppAttribute>? AdditionalOperationAttributes { get; set; }
public IEnumerable<IppAttribute>? AdditionalJobAttributes { get; set; }
}


/// <summary>
/// The client OPTIONALLY supplies this attribute. The Printer
/// object MUST support this attribute. It is a set of Job
/// attribute names and/or attribute groups names in whose values
/// the requester is interested. This set of attributes is
/// returned for each Job object that is returned. The allowed
/// attribute group names are the same as those defined in the
/// Get-Job-Attributes operation in section 3.3.4. If the client
/// does not supply this attribute, the Printer MUST respond as if
/// the client had supplied this attribute with two values: 'job-
/// uri' and 'job-id'.
/// </summary>
public string[]? RequestedAttributes { get; set; }

public IppVersion Version { get; set; } = IppVersion.CUPS10;
public int RequestId { get; set; } = 1;
public Uri PrinterUri { get; set; } = null!;

/// <summary>
/// The "requesting-user-name" (name(MAX)) attribute SHOULD be
/// supplied by the client
/// </summary>
public string? RequestingUserName { get; set; }

public IEnumerable<IppAttribute>? AdditionalOperationAttributes { get; set; }
public IEnumerable<IppAttribute>? AdditionalJobAttributes { get; set; }
}

///<summary>
///The type of printer returned.
///</summary>
///<remarks>
///Cups documentation says its an enum, but fails to mention possible values
///<seealso href="http://www.cups.org/doc/spec-ipp.html#CUPS_GET_PRINTERS"/>
///</remarks>
public enum PrinterType
Zelenov marked this conversation as resolved.
Show resolved Hide resolved
{
Printer
}
}
}
14 changes: 7 additions & 7 deletions SharpIpp/Protocol/IppProtocol.GetCUPSPrinters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ namespace SharpIpp.Protocol
internal partial class IppProtocol
{
/// <summary>
/// Get-Job-Attributes Request
/// https://tools.ietf.org/html/rfc2911#section-3.3.4.1
/// CUPS-get-printers Request
/// http://www.cups.org/doc/spec-ipp.html#CUPS_GET_PRINTERS
/// </summary>
/// <param name="request"></param>
public IppRequestMessage Construct(CUPSGetPrintersRequest request) => ConstructIppRequest(request);

/// <summary>
/// Get-Job-Attributes Response
/// https://tools.ietf.org/html/rfc2911#section-3.3.4.2
/// CUPS-get-printers Response
/// http://www.cups.org/doc/spec-ipp.html#CUPS_GET_PRINTERS
/// </summary>
public CUPSGetPrintersResponse ConstructGetCUPSPrintersResponse(IIppResponseMessage ippResponse) =>
Construct<CUPSGetPrintersResponse>(ippResponse);
Expand All @@ -31,11 +31,11 @@ private static void ConfigureGetCUPSPrintersResponse(SimpleMapper mapper)
if (src.Limit != null)
operation.Add(new IppAttribute(Tag.Integer, "requesting-user-name", src.Limit.Value));
if (src.FirstPrinterName != null)
operation.Add(new IppAttribute(Tag.Keyword, "first-printer-name", Mapper.Map<string>(src.FirstPrinterName)));
operation.Add(new IppAttribute(Tag.Keyword, "first-printer-name", mapper.Map<string>(src.FirstPrinterName)));
if (src.PrinterID != null)
operation.Add(new IppAttribute(Tag.Integer, "printer-id", Mapper.Map<string>(src.PrinterID)));
operation.Add(new IppAttribute(Tag.Integer, "printer-id", mapper.Map<string>(src.PrinterID)));
if (src.PrinterLocation != null)
operation.Add(new IppAttribute(Tag.Keyword, "printer-location", Mapper.Map<string>(src.PrinterLocation)));
operation.Add(new IppAttribute(Tag.Keyword, "printer-location", mapper.Map<string>(src.PrinterLocation)));
if (src.RequestedAttributes != null)
operation.AddRange(src.RequestedAttributes.Select(requestedAttribute =>
new IppAttribute(Tag.Keyword, "requested-attributes", requestedAttribute)));
Expand Down