├── .editorconfig ├── .gitattributes ├── .github ├── FUNDING.yml └── workflows │ └── create-release.yml ├── .gitignore ├── Directory.Packages.props ├── LICENSE.txt ├── NuGet.Config ├── README.md ├── Setup ├── Add-Printer.ps1 ├── Remove-Printer.ps1 ├── Update-OutdatedPackage.ps1 └── Update-ThirdPartyNotices.ps1 ├── SharpIppNextServer.sln ├── SharpIppNextServer ├── Models │ ├── PrinterJob.cs │ └── PrinterOptions.cs ├── Program.cs ├── Properties │ └── launchSettings.json ├── Services │ ├── DateTimeOffsetProvider.cs │ ├── DateTimeProvider.cs │ ├── IDateTimeOffsetProvider.cs │ ├── IDateTimeProvider.cs │ ├── JobService.cs │ ├── PrinterService.cs │ └── SecurityHeadersMiddleware.cs ├── SharpIppNextServer.csproj ├── SharpIppNextServer.http ├── THIRD-PARTY-NOTICES.txt ├── appsettings.Development.json ├── appsettings.Production.json └── appsettings.json └── global.json /.editorconfig: -------------------------------------------------------------------------------- 1 | # Remove the line below if you want to inherit .editorconfig settings from higher directories 2 | root = true 3 | 4 | # C# files 5 | [*.cs] 6 | 7 | #### Core EditorConfig Options #### 8 | 9 | # Indentation and spacing 10 | indent_size = 4 11 | indent_style = space 12 | tab_width = 4 13 | 14 | # New line preferences 15 | end_of_line = crlf 16 | insert_final_newline = false 17 | 18 | #### .NET Code Actions #### 19 | 20 | # Type members 21 | dotnet_hide_advanced_members = false 22 | dotnet_member_insertion_location = with_other_members_of_the_same_kind 23 | dotnet_property_generation_behavior = prefer_throwing_properties 24 | 25 | # Symbol search 26 | dotnet_search_reference_assemblies = true 27 | 28 | #### .NET Coding Conventions #### 29 | 30 | # Organize usings 31 | dotnet_separate_import_directive_groups = false 32 | dotnet_sort_system_directives_first = false 33 | file_header_template = unset 34 | 35 | # this. and Me. preferences 36 | dotnet_style_qualification_for_event = false 37 | dotnet_style_qualification_for_field = false 38 | dotnet_style_qualification_for_method = false 39 | dotnet_style_qualification_for_property = false 40 | 41 | # Language keywords vs BCL types preferences 42 | dotnet_style_predefined_type_for_locals_parameters_members = true 43 | dotnet_style_predefined_type_for_member_access = true 44 | 45 | # Parentheses preferences 46 | dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity 47 | dotnet_style_parentheses_in_other_binary_operators = always_for_clarity 48 | dotnet_style_parentheses_in_other_operators = never_if_unnecessary 49 | dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity 50 | 51 | # Modifier preferences 52 | dotnet_style_require_accessibility_modifiers = for_non_interface_members 53 | 54 | # Expression-level preferences 55 | dotnet_prefer_system_hash_code = true 56 | dotnet_style_coalesce_expression = true 57 | dotnet_style_collection_initializer = true 58 | dotnet_style_explicit_tuple_names = true 59 | dotnet_style_namespace_match_folder = true 60 | dotnet_style_null_propagation = true 61 | dotnet_style_object_initializer = true 62 | dotnet_style_operator_placement_when_wrapping = beginning_of_line 63 | dotnet_style_prefer_auto_properties = true 64 | dotnet_style_prefer_collection_expression = when_types_loosely_match 65 | dotnet_style_prefer_compound_assignment = true 66 | dotnet_style_prefer_conditional_expression_over_assignment = true 67 | dotnet_style_prefer_conditional_expression_over_return = true 68 | dotnet_style_prefer_foreach_explicit_cast_in_source = when_strongly_typed 69 | dotnet_style_prefer_inferred_anonymous_type_member_names = true 70 | dotnet_style_prefer_inferred_tuple_names = true 71 | dotnet_style_prefer_is_null_check_over_reference_equality_method = true 72 | dotnet_style_prefer_simplified_boolean_expressions = true 73 | dotnet_style_prefer_simplified_interpolation = true 74 | 75 | # Field preferences 76 | dotnet_style_readonly_field = true 77 | 78 | # Parameter preferences 79 | dotnet_code_quality_unused_parameters = all 80 | 81 | # Suppression preferences 82 | dotnet_remove_unnecessary_suppression_exclusions = none 83 | 84 | # New line preferences 85 | dotnet_style_allow_multiple_blank_lines_experimental = false 86 | dotnet_style_allow_statement_immediately_after_block_experimental = true 87 | 88 | #### C# Coding Conventions #### 89 | 90 | # var preferences 91 | csharp_style_var_elsewhere = false 92 | csharp_style_var_for_built_in_types = false 93 | csharp_style_var_when_type_is_apparent = false 94 | 95 | # Expression-bodied members 96 | csharp_style_expression_bodied_accessors = true 97 | csharp_style_expression_bodied_constructors = when_on_single_line 98 | csharp_style_expression_bodied_indexers = true 99 | csharp_style_expression_bodied_lambdas = true 100 | csharp_style_expression_bodied_local_functions = when_on_single_line 101 | csharp_style_expression_bodied_methods = when_on_single_line 102 | csharp_style_expression_bodied_operators = when_on_single_line 103 | csharp_style_expression_bodied_properties = true 104 | 105 | # Pattern matching preferences 106 | csharp_style_pattern_matching_over_as_with_null_check = true 107 | csharp_style_pattern_matching_over_is_with_cast_check = true 108 | csharp_style_prefer_extended_property_pattern = true 109 | csharp_style_prefer_not_pattern = true 110 | csharp_style_prefer_pattern_matching = true 111 | csharp_style_prefer_switch_expression = true 112 | 113 | # Null-checking preferences 114 | csharp_style_conditional_delegate_call = true 115 | 116 | # Modifier preferences 117 | csharp_prefer_static_anonymous_function = true 118 | csharp_prefer_static_local_function = true 119 | csharp_preferred_modifier_order = public,private,protected,internal,file,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,required,volatile,async 120 | csharp_style_prefer_readonly_struct = true 121 | csharp_style_prefer_readonly_struct_member = true 122 | 123 | # Code-block preferences 124 | csharp_prefer_braces = when_multiline 125 | csharp_prefer_simple_using_statement = true 126 | csharp_prefer_system_threading_lock = true 127 | csharp_style_namespace_declarations = file_scoped 128 | csharp_style_prefer_method_group_conversion = true 129 | csharp_style_prefer_primary_constructors = true 130 | csharp_style_prefer_top_level_statements = true 131 | 132 | # Expression-level preferences 133 | csharp_prefer_simple_default_expression = true 134 | csharp_style_deconstructed_variable_declaration = true 135 | csharp_style_implicit_object_creation_when_type_is_apparent = true 136 | csharp_style_inlined_variable_declaration = true 137 | csharp_style_prefer_index_operator = true 138 | csharp_style_prefer_local_over_anonymous_function = true 139 | csharp_style_prefer_null_check_over_type_check = true 140 | csharp_style_prefer_range_operator = true 141 | csharp_style_prefer_tuple_swap = true 142 | csharp_style_prefer_utf8_string_literals = true 143 | csharp_style_throw_expression = true 144 | csharp_style_unused_value_assignment_preference = discard_variable 145 | csharp_style_unused_value_expression_statement_preference = discard_variable 146 | 147 | # 'using' directive preferences 148 | csharp_using_directive_placement = outside_namespace 149 | 150 | # New line preferences 151 | csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true 152 | csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = true 153 | csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = true 154 | csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false 155 | csharp_style_allow_embedded_statements_on_same_line_experimental = false 156 | 157 | #### C# Formatting Rules #### 158 | 159 | # New line preferences 160 | csharp_new_line_before_catch = true 161 | csharp_new_line_before_else = true 162 | csharp_new_line_before_finally = true 163 | csharp_new_line_before_members_in_anonymous_types = true 164 | csharp_new_line_before_members_in_object_initializers = true 165 | csharp_new_line_before_open_brace = all 166 | csharp_new_line_between_query_expression_clauses = true 167 | 168 | # Indentation preferences 169 | csharp_indent_block_contents = true 170 | csharp_indent_braces = false 171 | csharp_indent_case_contents = true 172 | csharp_indent_case_contents_when_block = true 173 | csharp_indent_labels = one_less_than_current 174 | csharp_indent_switch_labels = true 175 | 176 | # Space preferences 177 | csharp_space_after_cast = false 178 | csharp_space_after_colon_in_inheritance_clause = true 179 | csharp_space_after_comma = true 180 | csharp_space_after_dot = false 181 | csharp_space_after_keywords_in_control_flow_statements = true 182 | csharp_space_after_semicolon_in_for_statement = true 183 | csharp_space_around_binary_operators = before_and_after 184 | csharp_space_around_declaration_statements = false 185 | csharp_space_before_colon_in_inheritance_clause = true 186 | csharp_space_before_comma = false 187 | csharp_space_before_dot = false 188 | csharp_space_before_open_square_brackets = false 189 | csharp_space_before_semicolon_in_for_statement = false 190 | csharp_space_between_empty_square_brackets = false 191 | csharp_space_between_method_call_empty_parameter_list_parentheses = false 192 | csharp_space_between_method_call_name_and_opening_parenthesis = false 193 | csharp_space_between_method_call_parameter_list_parentheses = false 194 | csharp_space_between_method_declaration_empty_parameter_list_parentheses = false 195 | csharp_space_between_method_declaration_name_and_open_parenthesis = false 196 | csharp_space_between_method_declaration_parameter_list_parentheses = false 197 | csharp_space_between_parentheses = false 198 | csharp_space_between_square_brackets = false 199 | 200 | # Wrapping preferences 201 | csharp_preserve_single_line_blocks = true 202 | csharp_preserve_single_line_statements = true 203 | 204 | #### Naming styles #### 205 | 206 | # Naming rules 207 | 208 | dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion 209 | dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface 210 | dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i 211 | 212 | dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion 213 | dotnet_naming_rule.types_should_be_pascal_case.symbols = types 214 | dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case 215 | 216 | dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion 217 | dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members 218 | dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case 219 | 220 | # Symbol specifications 221 | 222 | dotnet_naming_symbols.interface.applicable_kinds = interface 223 | dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected 224 | dotnet_naming_symbols.interface.required_modifiers = 225 | 226 | dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum 227 | dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected 228 | dotnet_naming_symbols.types.required_modifiers = 229 | 230 | dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method 231 | dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected 232 | dotnet_naming_symbols.non_field_members.required_modifiers = 233 | 234 | # Naming styles 235 | 236 | dotnet_naming_style.pascal_case.required_prefix = 237 | dotnet_naming_style.pascal_case.required_suffix = 238 | dotnet_naming_style.pascal_case.word_separator = 239 | dotnet_naming_style.pascal_case.capitalization = pascal_case 240 | 241 | dotnet_naming_style.begins_with_i.required_prefix = I 242 | dotnet_naming_style.begins_with_i.required_suffix = 243 | dotnet_naming_style.begins_with_i.word_separator = 244 | dotnet_naming_style.begins_with_i.capitalization = pascal_case 245 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: danielklecha -------------------------------------------------------------------------------- /.github/workflows/create-release.yml: -------------------------------------------------------------------------------- 1 | name: Create Release 2 | 3 | on: 4 | push: 5 | tags: 6 | - 'v**' 7 | 8 | jobs: 9 | build: 10 | runs-on: ubuntu-latest 11 | permissions: 12 | contents: write 13 | steps: 14 | - name: Checkout code 15 | uses: actions/checkout@v4 16 | - name: Setup .NET 17 | uses: actions/setup-dotnet@v4 18 | with: 19 | dotnet-version: 8.0.x 20 | - name: Replace Version in csproj files 21 | run: | 22 | tag=$(echo "${{ github.ref_name }}" | sed 's/^v//') 23 | find . -type f -name "*.csproj" -exec sed -i "s/.*<\/Version>/${tag}<\/Version>/g" {} \; 24 | - name: Install zip 25 | uses: montudor/action-zip@v1 26 | - name: Restore dependencies 27 | run: dotnet restore 28 | - name: Publish win-x64 29 | run: dotnet publish --no-restore --configuration Release --runtime win-x64 --no-self-contained 30 | - name: Copy license win-x64 31 | run: | 32 | cp LICENSE.txt SharpIppNextServer/bin/Release/net8.0/win-x64/publish/LICENSE.txt 33 | - name: Pack win-x64 34 | run: zip -qq -r "../../../SharpIppNextServer-${{github.ref_name}}-win-x64.zip" *.* 35 | working-directory: SharpIppNextServer/bin/Release/net8.0/win-x64/publish/ 36 | - name: Publish linux-x64 37 | run: dotnet publish --no-restore --configuration Release --runtime linux-x64 --no-self-contained 38 | - name: Copy license linux-x64 39 | run: | 40 | cp LICENSE.txt SharpIppNextServer/bin/Release/net8.0/linux-x64/publish/LICENSE.txt 41 | - name: Pack linux-x64 42 | run: zip -qq -r ../../../SharpIppNextServer-${{github.ref_name}}-linux-x64.zip *.* 43 | working-directory: SharpIppNextServer/bin/Release/net8.0/linux-x64/publish/ 44 | - name: Publish osx-x64 45 | run: dotnet publish --no-restore --configuration Release --runtime osx-x64 --no-self-contained 46 | - name: Copy license osx-x64 47 | run: | 48 | cp LICENSE.txt SharpIppNextServer/bin/Release/net8.0/osx-x64/publish/LICENSE.txt 49 | - name: Pack osx-x64 50 | run: zip -qq -r ../../../SharpIppNextServer-${{github.ref_name}}-osx-x64.zip *.* 51 | working-directory: SharpIppNextServer/bin/Release/net8.0/osx-x64/publish/ 52 | - name: Create GitHub Release 53 | env: 54 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 55 | run: | 56 | tag=${{ github.ref_name }} 57 | gh release create "$tag" --generate-notes SharpIppNextServer/bin/Release/*.zip 58 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Oo]ut/ 33 | [Ll]og/ 34 | [Ll]ogs/ 35 | 36 | # Visual Studio 2015/2017 cache/options directory 37 | .vs/ 38 | # Uncomment if you have tasks that create the project's static files in wwwroot 39 | #wwwroot/ 40 | 41 | # Visual Studio 2017 auto generated files 42 | Generated\ Files/ 43 | 44 | # MSTest test Results 45 | [Tt]est[Rr]esult*/ 46 | [Bb]uild[Ll]og.* 47 | 48 | # NUnit 49 | *.VisualState.xml 50 | TestResult.xml 51 | nunit-*.xml 52 | 53 | # Build Results of an ATL Project 54 | [Dd]ebugPS/ 55 | [Rr]eleasePS/ 56 | dlldata.c 57 | 58 | # Benchmark Results 59 | BenchmarkDotNet.Artifacts/ 60 | 61 | # .NET Core 62 | project.lock.json 63 | project.fragment.lock.json 64 | artifacts/ 65 | 66 | # ASP.NET Scaffolding 67 | ScaffoldingReadMe.txt 68 | 69 | # StyleCop 70 | StyleCopReport.xml 71 | 72 | # Files built by Visual Studio 73 | *_i.c 74 | *_p.c 75 | *_h.h 76 | *.ilk 77 | *.meta 78 | *.obj 79 | *.iobj 80 | *.pch 81 | *.pdb 82 | *.ipdb 83 | *.pgc 84 | *.pgd 85 | *.rsp 86 | *.sbr 87 | *.tlb 88 | *.tli 89 | *.tlh 90 | *.tmp 91 | *.tmp_proj 92 | *_wpftmp.csproj 93 | *.log 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio LightSwitch build output 298 | **/*.HTMLClient/GeneratedArtifacts 299 | **/*.DesktopClient/GeneratedArtifacts 300 | **/*.DesktopClient/ModelManifest.xml 301 | **/*.Server/GeneratedArtifacts 302 | **/*.Server/ModelManifest.xml 303 | _Pvt_Extensions 304 | 305 | # Paket dependency manager 306 | .paket/paket.exe 307 | paket-files/ 308 | 309 | # FAKE - F# Make 310 | .fake/ 311 | 312 | # CodeRush personal settings 313 | .cr/personal 314 | 315 | # Python Tools for Visual Studio (PTVS) 316 | __pycache__/ 317 | *.pyc 318 | 319 | # Cake - Uncomment if you are using it 320 | # tools/** 321 | # !tools/packages.config 322 | 323 | # Tabs Studio 324 | *.tss 325 | 326 | # Telerik's JustMock configuration file 327 | *.jmconfig 328 | 329 | # BizTalk build output 330 | *.btp.cs 331 | *.btm.cs 332 | *.odx.cs 333 | *.xsd.cs 334 | 335 | # OpenCover UI analysis results 336 | OpenCover/ 337 | 338 | # Azure Stream Analytics local run output 339 | ASALocalRun/ 340 | 341 | # MSBuild Binary and Structured Log 342 | *.binlog 343 | 344 | # NVidia Nsight GPU debugger configuration file 345 | *.nvuser 346 | 347 | # MFractors (Xamarin productivity tool) working folder 348 | .mfractor/ 349 | 350 | # Local History for Visual Studio 351 | .localhistory/ 352 | 353 | # BeatPulse healthcheck temp database 354 | healthchecksdb 355 | 356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 357 | MigrationBackup/ 358 | 359 | # Ionide (cross platform F# VS Code tools) working folder 360 | .ionide/ 361 | 362 | # Fody - auto-generated XML schema 363 | FodyWeavers.xsd 364 | 365 | # Custom 366 | /SharpIppNextServer/jobs 367 | -------------------------------------------------------------------------------- /Directory.Packages.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | true 4 | true 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Daniel Klecha 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /NuGet.Config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SharpIppNextServer 2 | 3 | [![GitHub downloads](https://img.shields.io/github/downloads/danielklecha/SharpIppNextServer/total.svg)](https://github.com/danielklecha/SharpIppNextServer/releases) 4 | [![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/danielklecha/SharpIppNextServer/blob/master/LICENSE.txt) 5 | 6 | IPP printer (web app) based on `SharpIppNext` library. 7 | 8 | ## Installation 9 | 10 | The printer should be compatible with any IPP client. 11 | 12 | ### Windows (Printer wizard) 13 | 14 | 1. Open "printers & scanners" 15 | 2. Click "Add device" 16 | 3. Click "Add a new device manually" 17 | 4. Select "Select a shared printer by name" and use url http://127.0.0.1:631/SharpIppNext 18 | 5. Click "Next" 19 | 6. Click "Windows Update" if you don't see printer from next point. Process could teke few minutes. 20 | 6. Select "Microsoft" as "Manufacturer and "Microsoft Print to PDF" as printer. 21 | 7. Click "OK" 22 | 8. Click "Next" 23 | 9. Click "Print a test page" (optionally) 24 | 10. Click "Finish" 25 | 26 | ### Windows (Script) 27 | 28 | ```powershell 29 | Add-Printer -Name "SharpIppNext" -PortName "http://127.0.0.1:631/SharpIppNext" -DriverName "Microsoft Print To PDF" 30 | ``` 31 | 32 | All steps are described in `Setup\Add-printer.ps1` 33 | 34 | ### Android 35 | 36 | Use the NetPrinter App. 37 | 38 | ## Requirements 39 | 40 | ASP.NET Core 8.0 Runtime needs to be installed. 41 | 42 | ## Integration testing (OpenSUSE) 43 | 44 | 1. Install package: `sudo zypper install cups-client cups-backends` 45 | 2. Obtain correct IP: `ip route` 46 | 3. Make test: `ipptool -t ipp://172.25.192.1 ipp-1.1.test` 47 | -------------------------------------------------------------------------------- /Setup/Add-Printer.ps1: -------------------------------------------------------------------------------- 1 | $driverName = "Microsoft Print To PDF" 2 | $printerName = "SharpIppNext" 3 | $ipAddress = "127.0.0.1" 4 | $portNumber = 631 5 | $printerUrl = "http://$ipAddress`:$portNumber/$printerName" 6 | 7 | function Import-Modules { 8 | if ($PSVersionTable.PSVersion.Major -ge 7) { 9 | Write-Output "Detected PowerShell 7. Importing DISM module..." 10 | try { 11 | Import-Module DISM -UseWindowsPowerShell -ErrorAction Stop -WarningAction SilentlyContinue 12 | Write-Output "DISM module imported successfully." 13 | } catch { 14 | Write-Error "Failed to import DISM module. Ensure PowerShell 5.1 is available." 15 | exit 1 16 | } 17 | } 18 | } 19 | 20 | function Install-WindowsFeature { 21 | try { 22 | Write-Output "Checking Internet Print Client feature status..." 23 | $features = @("Printing-InternetPrinting-Client", "Printing-Foundation-InternetPrinting-Client") 24 | foreach ($featureName in $features) { 25 | $feature = Get-WindowsOptionalFeature -Online -FeatureName $featureName -ErrorAction SilentlyContinue 26 | if ($feature -and $feature.State -eq "Enabled") { 27 | Write-Output "$featureName is already enabled." 28 | return 29 | } 30 | if ($feature) { 31 | Write-Output "Enabling $featureName..." 32 | Enable-WindowsOptionalFeature -Online -FeatureName $featureName -NoRestart -ErrorAction Stop 33 | Write-Output "$featureName has been installed successfully." 34 | return 35 | } 36 | } 37 | Write-Error "Required features not found. Ensure this is a supported Windows version." 38 | exit 1 39 | } catch { 40 | Write-Error "Error enabling Internet Print Client feature: $_" 41 | exit 1 42 | } 43 | } 44 | 45 | function Restart-Spooler { 46 | try { 47 | Write-Output "Restarting Spooler service..." 48 | Restart-Service -Name 'Spooler' -Force -ErrorAction Stop 49 | Start-Sleep -Seconds 3 50 | Write-Output "Spooler service restarted successfully." 51 | } catch { 52 | Write-Error "Failed to restart Spooler service: $_" 53 | exit 1 54 | } 55 | } 56 | 57 | function Install-PrintDriver { 58 | if (Get-PrinterDriver -Name $driverName -ErrorAction SilentlyContinue) { 59 | Write-Output "Printer driver '$driverName' is already installed." 60 | return 61 | } 62 | try { 63 | Write-Output "Installing print driver: $driverName..." 64 | Add-PrinterDriver -Name $driverName -ErrorAction Stop 65 | Write-Output "Print driver installed successfully." 66 | } catch { 67 | Write-Error "Error installing print driver: $_" 68 | exit 1 69 | } 70 | } 71 | 72 | function Add-IppPrinter { 73 | if (Get-Printer -Name $printerName -ErrorAction SilentlyContinue) { 74 | Write-Output "Printer '$printerName' already exists." 75 | return 76 | } 77 | try { 78 | Write-Output "Adding printer: $printerName..." 79 | Add-Printer -Name $printerName -PortName $printerUrl -DriverName $driverName -ErrorAction Stop 80 | Write-Output "Printer '$printerName' added successfully." 81 | } catch { 82 | Write-Error "Error adding printer '$printerName': $_" 83 | exit 1 84 | } 85 | } 86 | 87 | # Execute steps 88 | Import-Modules 89 | Install-WindowsFeature 90 | Restart-Spooler 91 | Install-PrintDriver 92 | Add-IppPrinter 93 | 94 | Write-Output "Printer setup completed successfully." -------------------------------------------------------------------------------- /Setup/Remove-Printer.ps1: -------------------------------------------------------------------------------- 1 | $printerName = "SharpIppNext" 2 | 3 | function Restart-Spooler { 4 | try { 5 | Write-Output "Restarting Spooler service..." 6 | Restart-Service -Name 'Spooler' -ErrorAction Stop 7 | Start-Sleep -Seconds 3 8 | Write-Output "Spooler service restarted successfully." 9 | } catch { 10 | Write-Error "Error restarting Spooler service: $_" 11 | exit 1 12 | } 13 | } 14 | 15 | function Remove-IppPrinter { 16 | if (Get-Printer -Name $printerName -ErrorAction SilentlyContinue) { 17 | try { 18 | Write-Host "Removing printer: $printerName" 19 | Remove-Printer -Name $printerName 20 | Write-Host "Printer $printerName removed successfully." 21 | } catch { 22 | Write-Error "Error adding printer '$printerName': $_" 23 | exit 1 24 | } 25 | } 26 | else { 27 | Write-Output "Printer '$printerName' does not exist." 28 | } 29 | } 30 | 31 | # Execute steps 32 | Restart-Spooler 33 | Remove-IppPrinter 34 | 35 | Write-Output "Printer setup completed successfully." -------------------------------------------------------------------------------- /Setup/Update-OutdatedPackage.ps1: -------------------------------------------------------------------------------- 1 | Push-Location "$PSScriptRoot\.." 2 | $jsonOutput = dotnet list package --include-transitive --outdated --format json 3 | $parsedJson = $jsonOutput | ConvertFrom-Json 4 | 5 | # Initialize an empty dictionary 6 | $packageVersions = @{} 7 | 8 | # Iterate over each project 9 | foreach ($project in $parsedJson.projects) { 10 | foreach ($framework in $project.frameworks) { 11 | foreach ($package in $framework.topLevelPackages) { 12 | if ($package.latestVersion -match '^\d' -and -not $packageVersions.ContainsKey($package.id)) { 13 | $packageVersions[$package.id] = $package.latestVersion 14 | } 15 | } 16 | foreach ($package in $framework.transitivePackages) { 17 | if ($package.latestVersion -match '^\d' -and -not $packageVersions.ContainsKey($package.id)) { 18 | $packageVersions[$package.id] = $package.latestVersion 19 | } 20 | } 21 | } 22 | } 23 | 24 | # Output the dictionary 25 | $packageVersions 26 | 27 | # Determine the script's directory 28 | $scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path 29 | 30 | # Path to the XML file in the parent directory 31 | $xmlFilePath = Join-Path -Path (Split-Path -Parent $scriptDir) -ChildPath "Directory.Packages.props" 32 | 33 | # Load the XML file 34 | [xml]$xml = Get-Content $xmlFilePath 35 | 36 | # Iterate over the dictionary to update or add PackageVersion elements 37 | foreach ($packageId in $packageVersions.Keys) { 38 | $found = $false 39 | 40 | # Update the existing package version 41 | foreach ($package in $xml.Project.ItemGroup.PackageVersion) { 42 | if ($package.Include -eq $packageId) { 43 | $package.Version = $packageVersions[$packageId] 44 | $found = $true 45 | break 46 | } 47 | } 48 | 49 | # Add a new package version if it wasn't found 50 | if (-not $found) { 51 | $newPackage = $xml.CreateElement("PackageVersion") 52 | $newPackage.SetAttribute("Include", $packageId) 53 | $newPackage.SetAttribute("Version", $packageVersions[$packageId]) 54 | $xml.Project.ItemGroup.AppendChild($newPackage) | Out-Null 55 | } 56 | } 57 | 58 | # Save the modified XML file 59 | $xml.Save($xmlFilePath) 60 | Pop-Location -------------------------------------------------------------------------------- /Setup/Update-ThirdPartyNotices.ps1: -------------------------------------------------------------------------------- 1 | Push-Location 2 | cd "$PSScriptRoot\..\SharpIppNextServer" 3 | dotnet-thirdpartynotices --output-filename "THIRD-PARTY-NOTICES.txt" 4 | Pop-Location -------------------------------------------------------------------------------- /SharpIppNextServer.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.9.34616.47 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpIppNextServer", "SharpIppNextServer\SharpIppNextServer.csproj", "{47476576-4D18-497A-9550-083D1760D7CA}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {47476576-4D18-497A-9550-083D1760D7CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {47476576-4D18-497A-9550-083D1760D7CA}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {47476576-4D18-497A-9550-083D1760D7CA}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {47476576-4D18-497A-9550-083D1760D7CA}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {32B71D4B-B5BB-4E75-B3B6-145BAC90E384} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /SharpIppNextServer/Models/PrinterJob.cs: -------------------------------------------------------------------------------- 1 | using SharpIpp.Models; 2 | using SharpIpp.Protocol.Models; 3 | 4 | namespace SharpIppNextServer.Models; 5 | 6 | public class PrinterJob : IEquatable, IDisposable, IAsyncDisposable 7 | { 8 | private bool disposedValue; 9 | 10 | public PrinterJob(int id, string? userName, DateTimeOffset createdDateTime) 11 | { 12 | Id = id; 13 | UserName = userName; 14 | CreatedDateTime = createdDateTime; 15 | } 16 | 17 | /// 18 | /// Create shallow copy of the original object 19 | /// 20 | /// 21 | public PrinterJob(PrinterJob printerJob) 22 | { 23 | Id = printerJob.Id; 24 | UserName = printerJob.UserName; 25 | CreatedDateTime = printerJob.CreatedDateTime; 26 | CompletedDateTime = printerJob.CompletedDateTime; 27 | ProcessingDateTime = printerJob.ProcessingDateTime; 28 | State = printerJob.State; 29 | Requests = printerJob.Requests; 30 | } 31 | 32 | public int Id { get; } 33 | public JobState? State { get; private set; } 34 | public string? UserName { get; } 35 | public List Requests { get; set; } = []; 36 | public DateTimeOffset CreatedDateTime { get; } 37 | public DateTimeOffset? CompletedDateTime { get; set; } 38 | public DateTimeOffset? ProcessingDateTime { get; set; } 39 | public bool IsNew => !State.HasValue && !ProcessingDateTime.HasValue; 40 | public bool IsHold => !State.HasValue && ProcessingDateTime.HasValue; 41 | 42 | public bool Equals(PrinterJob? other) 43 | { 44 | return other != null 45 | && Id == other.Id 46 | && State == other.State 47 | && UserName == other.UserName 48 | && CreatedDateTime == other.CreatedDateTime 49 | && CompletedDateTime == other.CompletedDateTime 50 | && ProcessingDateTime == other.ProcessingDateTime 51 | && other.Requests.SequenceEqual(Requests); 52 | } 53 | 54 | public override bool Equals(object? obj) 55 | { 56 | return ReferenceEquals(this, obj) || obj is PrinterJob other && Equals(other); 57 | } 58 | 59 | public override int GetHashCode() 60 | { 61 | return HashCode.Combine(Id, State, Requests); 62 | } 63 | 64 | public static bool operator ==(PrinterJob? left, PrinterJob? right) 65 | { 66 | return Equals(left, right); 67 | } 68 | 69 | public static bool operator !=(PrinterJob? left, PrinterJob? right) 70 | { 71 | return !Equals(left, right); 72 | } 73 | 74 | public async Task TrySetStateAsync(JobState? state, DateTimeOffset dateTime) 75 | { 76 | switch (state) 77 | { 78 | case null when !State.HasValue || State == JobState.Pending: 79 | State = state; 80 | return true; 81 | case JobState.Pending when !State.HasValue || State == JobState.Aborted: 82 | State = state; 83 | return true; 84 | case JobState.Processing when State == JobState.Pending: 85 | State = state; 86 | ProcessingDateTime = dateTime; 87 | return true; 88 | case JobState.Canceled when !State.HasValue || State == JobState.Pending: 89 | await ClearDocumentStreamsAsync(); 90 | State = state; 91 | ProcessingDateTime = dateTime; 92 | CompletedDateTime = dateTime; 93 | return true; 94 | case JobState.Completed when State == JobState.Processing: 95 | await ClearDocumentStreamsAsync(); 96 | State = state; 97 | CompletedDateTime = dateTime; 98 | return true; 99 | case JobState.Aborted when State == JobState.Processing: 100 | State = state; 101 | CompletedDateTime = dateTime; 102 | return true; 103 | default: 104 | return false; 105 | } 106 | } 107 | 108 | public async ValueTask DisposeAsync() 109 | { 110 | await DisposeAsyncCore().ConfigureAwait(false); 111 | Dispose(disposing: false); 112 | GC.SuppressFinalize(this); 113 | } 114 | 115 | protected virtual async ValueTask ClearDocumentStreamsAsync() 116 | { 117 | foreach (var ippRequest in Requests) 118 | { 119 | switch (ippRequest) 120 | { 121 | case PrintJobRequest printJobRequest when printJobRequest.Document != null: 122 | await printJobRequest.Document.DisposeAsync().ConfigureAwait(false); 123 | printJobRequest.Document = Stream.Null; 124 | break; 125 | case SendDocumentRequest sendDocumentRequest when sendDocumentRequest.Document != null: 126 | await sendDocumentRequest.Document.DisposeAsync().ConfigureAwait(false); 127 | sendDocumentRequest.Document = Stream.Null; 128 | break; 129 | } 130 | } 131 | } 132 | 133 | protected virtual async ValueTask DisposeAsyncCore() 134 | { 135 | foreach (var ippRequest in Requests) 136 | { 137 | switch (ippRequest) 138 | { 139 | case PrintJobRequest printJobRequest when printJobRequest.Document != null: 140 | await printJobRequest.Document.DisposeAsync().ConfigureAwait(false); 141 | break; 142 | case SendDocumentRequest sendDocumentRequest when sendDocumentRequest.Document != null: 143 | await sendDocumentRequest.Document.DisposeAsync().ConfigureAwait(false); 144 | break; 145 | } 146 | } 147 | Requests.Clear(); 148 | } 149 | 150 | protected virtual void Dispose(bool disposing) 151 | { 152 | if (disposedValue) 153 | return; 154 | if (disposing) 155 | { 156 | foreach (var ippRequest in Requests) 157 | { 158 | switch (ippRequest) 159 | { 160 | case PrintJobRequest printJobRequest when printJobRequest.Document != null: 161 | printJobRequest.Document.Dispose(); 162 | break; 163 | case SendDocumentRequest sendDocumentRequest when sendDocumentRequest.Document != null: 164 | sendDocumentRequest.Document.Dispose(); 165 | break; 166 | } 167 | } 168 | Requests.Clear(); 169 | } 170 | disposedValue = true; 171 | } 172 | 173 | public void Dispose() 174 | { 175 | Dispose(disposing: true); 176 | GC.SuppressFinalize(this); 177 | } 178 | } -------------------------------------------------------------------------------- /SharpIppNextServer/Models/PrinterOptions.cs: -------------------------------------------------------------------------------- 1 | using SharpIpp.Protocol.Models; 2 | 3 | namespace SharpIppNextServer.Models; 4 | 5 | public class PrinterOptions 6 | { 7 | public string Name { get; set; } = "SharpIpp"; 8 | public Sides[] Sides { get; set; } = [SharpIpp.Protocol.Models.Sides.OneSided]; 9 | public PrintScaling[] PrintScaling { get; set; } = [SharpIpp.Protocol.Models.PrintScaling.Auto]; 10 | public string[] Media { get; set; } = ["iso_a4_210x297mm"]; 11 | public Resolution[] Resolution { get; set; } = [new(600, 600, ResolutionUnit.DotsPerInch)]; 12 | public Finishings[] Finishings { get; set; } = [SharpIpp.Protocol.Models.Finishings.None]; 13 | public PrintQuality[] PrintQuality { get; set; } = [SharpIpp.Protocol.Models.PrintQuality.High]; 14 | public int JobPriority { get; set; } = 1; 15 | public int Copies { get; set; } = 1; 16 | public Orientation Orientation { get; set; } = Orientation.Portrait; 17 | public JobHoldUntil JobHoldUntil { get; set; } = JobHoldUntil.NoHold; 18 | public string DocumentFormat { get; set; } = "application/pdf"; 19 | public string[] OutputBin { get; set; } = ["top"]; 20 | public PrintColorMode[] PrintColorModes { get; set; } = [PrintColorMode.Color]; 21 | } -------------------------------------------------------------------------------- /SharpIppNextServer/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Server.Kestrel.Core; 2 | using Microsoft.Extensions.Options; 3 | using Quartz; 4 | using SharpIpp; 5 | using SharpIppNextServer.Models; 6 | using SharpIppNextServer.Services; 7 | using System.IO.Abstractions; 8 | 9 | var builder = WebApplication.CreateBuilder(args); 10 | builder.Services 11 | .AddSingleton() 12 | .AddSingleton() 13 | .AddSingleton() 14 | .AddSingleton() 15 | .Configure(options => options.AllowSynchronousIO = true) 16 | .Configure(options => options.AllowSynchronousIO = true) 17 | .Configure(builder.Configuration.GetSection("Printer")) 18 | .AddSingleton() 19 | .AddHttpContextAccessor() 20 | .AddCors() 21 | .AddQuartz(q => 22 | { 23 | var jobKey = new JobKey("printerQueue"); 24 | q.AddJob(opts => opts.WithIdentity(jobKey)); 25 | q.AddTrigger(opts => opts 26 | .ForJob(jobKey) 27 | .WithIdentity($"printerQueue-trigger") 28 | .WithCronSchedule("0/10 * * * * ?")); 29 | }) 30 | .AddQuartzHostedService(q => q.WaitForJobsToComplete = true); 31 | var app = builder.Build(); 32 | var printerOptions = app.Services.GetRequiredService>().Value; 33 | app.UseMiddleware(); 34 | app.UseCors(x => x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()); 35 | 36 | app.MapGet("/", () => "IPP printer"); 37 | new List 38 | { 39 | "/", 40 | "/ipp", 41 | $"/{printerOptions.Name}", 42 | "/ipp/printer", 43 | $"/ipp/printer/{printerOptions.Name}" 44 | }.ForEach(path => app.MapPost(path, async (HttpContext context, PrinterService printerService) => 45 | { 46 | context.Response.ContentType = "application/ipp"; 47 | await printerService.ProcessRequestAsync(context.Request.Body, context.Response.Body); 48 | })); 49 | /* 50 | app.MapMethods("/{**catchAll}", new[] { "GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS", "HEAD", "TRACE" }, async context => 51 | { 52 | await context.Response.WriteAsync("OK"); 53 | }); 54 | */ 55 | app.Run(); -------------------------------------------------------------------------------- /SharpIppNextServer/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:631", 8 | "sslPort": 44364 9 | } 10 | }, 11 | "profiles": { 12 | "http": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": false, 16 | "launchUrl": "", 17 | "applicationUrl": "http://0.0.0.0:631", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | }, 22 | "https": { 23 | "commandName": "Project", 24 | "dotnetRunMessages": true, 25 | "launchBrowser": false, 26 | "launchUrl": "", 27 | "applicationUrl": "https://0.0.0.0:631;http://0.0.0.0:631", 28 | "environmentVariables": { 29 | "ASPNETCORE_ENVIRONMENT": "Development" 30 | } 31 | }, 32 | "IIS Express": { 33 | "commandName": "IISExpress", 34 | "launchBrowser": false, 35 | "launchUrl": "", 36 | "environmentVariables": { 37 | "ASPNETCORE_ENVIRONMENT": "Development" 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /SharpIppNextServer/Services/DateTimeOffsetProvider.cs: -------------------------------------------------------------------------------- 1 | namespace SharpIppNextServer.Services; 2 | 3 | public class DateTimeOffsetProvider : IDateTimeOffsetProvider 4 | { 5 | public DateTimeOffset UtcNow => DateTimeOffset.UtcNow; 6 | public DateTimeOffset Now => DateTimeOffset.Now; 7 | } -------------------------------------------------------------------------------- /SharpIppNextServer/Services/DateTimeProvider.cs: -------------------------------------------------------------------------------- 1 | namespace SharpIppNextServer.Services; 2 | 3 | public class DateTimeProvider : IDateTimeProvider 4 | { 5 | public DateTime UtcNow => DateTime.UtcNow; 6 | public DateTime Now => DateTime.Now; 7 | } 8 | -------------------------------------------------------------------------------- /SharpIppNextServer/Services/IDateTimeOffsetProvider.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace SharpIppNextServer.Services 3 | { 4 | public interface IDateTimeOffsetProvider 5 | { 6 | DateTimeOffset Now { get; } 7 | DateTimeOffset UtcNow { get; } 8 | } 9 | } -------------------------------------------------------------------------------- /SharpIppNextServer/Services/IDateTimeProvider.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace SharpIppNextServer.Services 3 | { 4 | public interface IDateTimeProvider 5 | { 6 | DateTime Now { get; } 7 | DateTime UtcNow { get; } 8 | } 9 | } -------------------------------------------------------------------------------- /SharpIppNextServer/Services/JobService.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.StaticFiles; 2 | using Quartz; 3 | using SharpIpp.Models; 4 | using SharpIpp.Protocol.Models; 5 | using System.IO.Abstractions; 6 | 7 | namespace SharpIppNextServer.Services; 8 | 9 | public class JobService( 10 | PrinterService printerService, 11 | IWebHostEnvironment env, 12 | IFileSystem fileSystem) : IJob 13 | { 14 | private readonly FileExtensionContentTypeProvider _contentTypeProvider = new(); 15 | 16 | public async Task Execute(IJobExecutionContext context) 17 | { 18 | var job = await printerService.GetPendingJobAsync(); 19 | if (job == null) 20 | return; 21 | try 22 | { 23 | for (var i = 0; i < job.Requests.Count; i++) 24 | { 25 | var prefix = $"{job.Id}.{i}"; 26 | switch (job.Requests[i]) 27 | { 28 | case PrintJobRequest printJobRequest: 29 | await SaveAsync(prefix, printJobRequest); 30 | break; 31 | case SendDocumentRequest sendJobRequest: 32 | await SaveAsync(prefix, sendJobRequest); 33 | break; 34 | case SendUriRequest sendUriRequest: 35 | await SaveAsync(prefix, sendUriRequest); 36 | break; 37 | } 38 | } 39 | await printerService.AddCompletedJobAsync(job.Id); 40 | } 41 | catch (Exception ex) 42 | { 43 | await printerService.AddAbortedJobAsync(job.Id, ex); 44 | } 45 | } 46 | 47 | private async Task SaveAsync(string prefix, PrintJobRequest request) 48 | { 49 | if (request.Document == null) 50 | return; 51 | if(request.Document.Position > 0) 52 | request.Document.Seek(0, SeekOrigin.Begin); 53 | await SaveAsync(request.Document, GetFileName(prefix, request.OperationAttributes?.DocumentName, request.OperationAttributes?.DocumentFormat)); 54 | await request.Document.DisposeAsync(); 55 | } 56 | 57 | private async Task SaveAsync(string prefix, SendDocumentRequest request) 58 | { 59 | if (request.Document == null) 60 | return; 61 | request.Document.Seek(0, SeekOrigin.Begin); 62 | await SaveAsync(request.Document, GetFileName(prefix, request.OperationAttributes?.DocumentName, request.OperationAttributes?.DocumentFormat)); 63 | await request.Document.DisposeAsync(); 64 | } 65 | 66 | private async Task SaveAsync(string prefix, SendUriRequest request) 67 | { 68 | if (request.OperationAttributes is null || request.OperationAttributes.DocumentUri is null) 69 | return; 70 | using var client = new HttpClient(); 71 | using var result = await client.GetAsync(request.OperationAttributes.DocumentUri); 72 | if (!result.IsSuccessStatusCode) 73 | return; 74 | using var stream = await result.Content.ReadAsStreamAsync(); 75 | await SaveAsync(stream, GetFileName(prefix, request.OperationAttributes.DocumentName, request.OperationAttributes.DocumentFormat, fileSystem.Path.GetFileNameWithoutExtension(request.OperationAttributes.DocumentUri.LocalPath), fileSystem.Path.GetExtension(request.OperationAttributes.DocumentUri.LocalPath))); 76 | } 77 | 78 | private string GetFileName(string prefix, string? documentName, string? documentFormat, string? alternativeDocumentName = null, string? alternativeExtension = null) 79 | { 80 | var extension = documentFormat is null 81 | ? null 82 | : _contentTypeProvider.Mappings.Where(x => x.Value == documentFormat).Select(x => x.Key).FirstOrDefault(); 83 | return $"{prefix}_{documentName ?? alternativeDocumentName ?? "no-name"}{extension ?? alternativeExtension ?? ".unknown"}"; 84 | } 85 | 86 | private async Task SaveAsync(Stream stream, string fileName) 87 | { 88 | var path = fileSystem.Path.Combine(env.ContentRootPath, "jobs", fileName); 89 | fileSystem.Directory.CreateDirectory(fileSystem.Path.Combine(env.ContentRootPath, "jobs")); 90 | using var fileStream = fileSystem.FileStream.New(path, FileMode.OpenOrCreate); 91 | await stream.CopyToAsync(fileStream); 92 | } 93 | } -------------------------------------------------------------------------------- /SharpIppNextServer/Services/PrinterService.cs: -------------------------------------------------------------------------------- 1 | using SharpIpp; 2 | using SharpIpp.Protocol.Models; 3 | using System.Collections.Concurrent; 4 | using SharpIpp.Protocol; 5 | using SharpIpp.Models; 6 | using Microsoft.Extensions.Options; 7 | using SharpIpp.Exceptions; 8 | using SharpIppNextServer.Models; 9 | 10 | namespace SharpIppNextServer.Services; 11 | 12 | public class PrinterService( 13 | ISharpIppServer sharpIppServer, 14 | IHttpContextAccessor httpContextAccessor, 15 | ILogger logger, 16 | IOptions printerOptions, 17 | IDateTimeOffsetProvider dateTimeOffsetProvider) : IDisposable, IAsyncDisposable 18 | { 19 | private bool disposedValue; 20 | private int _newJobIndex = dateTimeOffsetProvider.UtcNow.Day * 1000; 21 | private bool _isPaused; 22 | private readonly ConcurrentDictionary _jobs = new(); 23 | private readonly DateTimeOffset _startTime = dateTimeOffsetProvider.UtcNow.AddMinutes(-1); 24 | 25 | private int GetNextValue() 26 | { 27 | return Interlocked.Increment(ref _newJobIndex); 28 | } 29 | 30 | public async Task ProcessRequestAsync(Stream inputStream, Stream outputStream) 31 | { 32 | try 33 | { 34 | IIppRequest request = await sharpIppServer.ReceiveRequestAsync(inputStream); 35 | IIppResponseMessage response = request switch 36 | { 37 | CancelJobRequest x => await GetCancelJobResponseAsync(x), 38 | CreateJobRequest x => GetCreateJobResponse(x), 39 | CUPSGetPrintersRequest x => GetCUPSGetPrintersResponse(x), 40 | GetJobAttributesRequest x => GetGetJobAttributesResponse(x), 41 | GetJobsRequest x => GetGetJobsResponse(x), 42 | GetPrinterAttributesRequest x => GetGetPrinterAttributesResponse(x), 43 | HoldJobRequest x => await GetHoldJobResponseAsync(x), 44 | PausePrinterRequest x => GetPausePrinterResponse(x), 45 | PrintJobRequest x => await GetPrintJobResponseAsync(x), 46 | PrintUriRequest x => GetPrintUriResponse(x), 47 | PurgeJobsRequest x => await GetPurgeJobsResponseAsync(x), 48 | ReleaseJobRequest x => await GetReleaseJobResponseAsync(x), 49 | RestartJobRequest x => await GetRestartJobResponseAsync(x), 50 | ResumePrinterRequest x => GetResumePrinterResponse(x), 51 | SendDocumentRequest x => await GetSendDocumentResponseAsync(x), 52 | SendUriRequest x => await GetSendUriResponseAsync(x), 53 | ValidateJobRequest x => GetValidateJobResponse(x), 54 | _ => throw new NotImplementedException() 55 | }; 56 | await sharpIppServer.SendResponseAsync(response, outputStream); 57 | } 58 | catch (IppRequestException ex) 59 | { 60 | logger.LogError(ex, "Unable to process request"); 61 | var response = new IppResponseMessage 62 | { 63 | RequestId = ex.RequestMessage.RequestId, 64 | Version = ex.RequestMessage.Version, 65 | StatusCode = ex.StatusCode 66 | }; 67 | var operation = new IppSection { Tag = SectionTag.OperationAttributesTag }; 68 | operation.Attributes.Add(new IppAttribute(Tag.Charset, JobAttribute.AttributesCharset, "utf-8")); 69 | operation.Attributes.Add(new IppAttribute(Tag.NaturalLanguage, JobAttribute.AttributesNaturalLanguage, "en")); 70 | response.Sections.Add(operation); 71 | await sharpIppServer.SendRawResponseAsync(response, outputStream); 72 | } 73 | catch (Exception ex) 74 | { 75 | logger.LogError(ex, "Unable to process request"); 76 | if (httpContextAccessor.HttpContext != null) 77 | httpContextAccessor.HttpContext.Response.StatusCode = 500; 78 | } 79 | } 80 | 81 | private ValidateJobResponse GetValidateJobResponse(ValidateJobRequest request) 82 | { 83 | logger.LogInformation("Job has been validated"); 84 | return new ValidateJobResponse 85 | { 86 | RequestId = request.RequestId, 87 | Version = request.Version, 88 | StatusCode = IppStatusCode.SuccessfulOk 89 | }; 90 | } 91 | 92 | private async Task GetSendUriResponseAsync(SendUriRequest request) 93 | { 94 | var response = new SendUriResponse 95 | { 96 | RequestId = request.RequestId, 97 | Version = request.Version, 98 | StatusCode = IppStatusCode.ClientErrorNotPossible 99 | }; 100 | var jobId = GetJobId(request); 101 | if (!jobId.HasValue) 102 | return response; 103 | response.JobId = jobId.Value; 104 | response.JobUri = $"{GetPrinterUrl()}/{jobId.Value}"; 105 | if (!_jobs.TryGetValue(jobId.Value, out var job)) 106 | return response; 107 | var copy = new PrinterJob(job); 108 | if (request.OperationAttributes?.LastDocument ?? false) 109 | { 110 | if (!await copy.TrySetStateAsync(JobState.Pending, dateTimeOffsetProvider.UtcNow)) 111 | return response; 112 | logger.LogInformation("Job {id} has been moved to queue", job.Id); 113 | } 114 | FillWithDefaultValues(request.OperationAttributes ??= new()); 115 | job.Requests.Add(request); 116 | logger.LogInformation("Document has been added to job {id}", job.Id); 117 | if (!_jobs.TryUpdate(jobId.Value, copy, job)) 118 | return response; 119 | response.StatusCode = IppStatusCode.SuccessfulOk; 120 | return response; 121 | } 122 | 123 | private async Task GetSendDocumentResponseAsync(SendDocumentRequest request) 124 | { 125 | var response = new SendDocumentResponse 126 | { 127 | RequestId = request.RequestId, 128 | Version = request.Version, 129 | StatusCode = IppStatusCode.ClientErrorNotPossible 130 | }; 131 | var jobId = GetJobId(request); 132 | if (!jobId.HasValue) 133 | return response; 134 | response.JobId = jobId.Value; 135 | response.JobUri = $"{GetPrinterUrl()}/{jobId.Value}"; 136 | if (!_jobs.TryGetValue(jobId.Value, out var job)) 137 | return response; 138 | var copy = new PrinterJob(job); 139 | if (request.OperationAttributes?.LastDocument ?? false) 140 | { 141 | if (!await copy.TrySetStateAsync(JobState.Pending, dateTimeOffsetProvider.UtcNow)) 142 | return response; 143 | logger.LogInformation("Job {id} has been moved to queue", job.Id); 144 | } 145 | FillWithDefaultValues(request.OperationAttributes ??= new()); 146 | job.Requests.Add(request); 147 | logger.LogInformation("Document has been added to job {id}", job.Id); 148 | if (!_jobs.TryUpdate(jobId.Value, copy, job)) 149 | return response; 150 | response.JobState = JobState.Pending; 151 | response.StatusCode = IppStatusCode.SuccessfulOk; 152 | return response; 153 | } 154 | 155 | private ReleaseJobResponse GetResumePrinterResponse(ResumePrinterRequest request) 156 | { 157 | _isPaused = false; 158 | logger.LogInformation("Printer has been resumed"); 159 | return new ReleaseJobResponse 160 | { 161 | RequestId = request.RequestId, 162 | Version = request.Version 163 | }; 164 | } 165 | 166 | private async Task GetRestartJobResponseAsync(RestartJobRequest request) 167 | { 168 | var response = new ReleaseJobResponse 169 | { 170 | RequestId = request.RequestId, 171 | Version = request.Version, 172 | StatusCode = IppStatusCode.ClientErrorNotPossible 173 | }; 174 | var jobId = GetJobId(request); 175 | if (!jobId.HasValue) 176 | return response; 177 | if (!_jobs.TryGetValue(jobId.Value, out var job)) 178 | return response; 179 | var copy = new PrinterJob(job); 180 | if (!await copy.TrySetStateAsync(JobState.Pending, dateTimeOffsetProvider.UtcNow)) 181 | return response; 182 | if (!_jobs.TryUpdate(jobId.Value, copy, job)) 183 | return response; 184 | response.StatusCode = IppStatusCode.SuccessfulOk; 185 | logger.LogInformation("Job {id} has been restarted", jobId); 186 | return response; 187 | } 188 | 189 | private async Task GetReleaseJobResponseAsync(ReleaseJobRequest request) 190 | { 191 | var response = new ReleaseJobResponse 192 | { 193 | RequestId = request.RequestId, 194 | Version = request.Version, 195 | StatusCode = IppStatusCode.ClientErrorNotPossible 196 | }; 197 | var jobId = GetJobId(request); 198 | if (!jobId.HasValue) 199 | return response; 200 | if (!_jobs.TryGetValue(jobId.Value, out var job)) 201 | return response; 202 | var copy = new PrinterJob(job); 203 | if (!await copy.TrySetStateAsync(JobState.Pending, dateTimeOffsetProvider.UtcNow)) 204 | return response; 205 | if (!_jobs.TryUpdate(jobId.Value, copy, job)) 206 | return response; 207 | response.StatusCode = IppStatusCode.SuccessfulOk; 208 | logger.LogInformation("Job {id} has been released", jobId); 209 | return response; 210 | } 211 | 212 | private async Task GetPurgeJobsResponseAsync(PurgeJobsRequest request) 213 | { 214 | foreach (var id in _jobs.Values.Where(x => x.State != JobState.Processing).Select(x => x.Id)) 215 | { 216 | if (_jobs.TryRemove(id, out var job)) 217 | await job.DisposeAsync(); 218 | } 219 | logger.LogInformation("System purged jobs"); 220 | return new PurgeJobsResponse 221 | { 222 | RequestId = request.RequestId, 223 | Version = request.Version, 224 | StatusCode = IppStatusCode.SuccessfulOk 225 | }; 226 | } 227 | 228 | private PrintUriResponse GetPrintUriResponse(PrintUriRequest request) 229 | { 230 | var response = new PrintUriResponse 231 | { 232 | RequestId = request.RequestId, 233 | Version = request.Version, 234 | JobState = JobState.Pending, 235 | StatusCode = IppStatusCode.ClientErrorNotPossible 236 | }; 237 | var job = new PrinterJob(GetNextValue(), request.OperationAttributes?.RequestingUserName, dateTimeOffsetProvider.UtcNow); 238 | response.JobId = job.Id; 239 | response.JobUri = $"{GetPrinterUrl()}/{job.Id}"; 240 | FillWithDefaultValues(job.Id, request.OperationAttributes ??= new()); 241 | FillWithDefaultValues(request.JobTemplateAttributes ??= new()); 242 | job.Requests.Add(request); 243 | if (!_jobs.TryAdd(job.Id, job)) 244 | return response; 245 | response.StatusCode = IppStatusCode.SuccessfulOk; 246 | logger.LogInformation("Job {id} has been added to queue", job.Id); 247 | return response; 248 | } 249 | 250 | private PausePrinterResponse GetPausePrinterResponse(PausePrinterRequest request) 251 | { 252 | _isPaused = true; 253 | logger.LogInformation("Printer has been paused"); 254 | return new PausePrinterResponse 255 | { 256 | RequestId = request.RequestId, 257 | Version = request.Version 258 | }; 259 | } 260 | 261 | private async Task GetHoldJobResponseAsync(HoldJobRequest request) 262 | { 263 | var response = new HoldJobResponse 264 | { 265 | RequestId = request.RequestId, 266 | Version = request.Version, 267 | StatusCode = IppStatusCode.ClientErrorNotPossible 268 | }; 269 | var jobId = GetJobId(request); 270 | if (!jobId.HasValue) 271 | return response; 272 | if (!_jobs.TryGetValue(jobId.Value, out var job)) 273 | return response; 274 | var copy = new PrinterJob(job); 275 | if (!await copy.TrySetStateAsync(null, dateTimeOffsetProvider.UtcNow)) 276 | return response; 277 | if (!_jobs.TryUpdate(jobId.Value, copy, job)) 278 | return response; 279 | response.StatusCode = IppStatusCode.SuccessfulOk; 280 | logger.LogInformation("Job {id} has been held", jobId); 281 | return response; 282 | } 283 | 284 | private GetPrinterAttributesResponse GetGetPrinterAttributesResponse(GetPrinterAttributesRequest request) 285 | { 286 | var options = printerOptions.Value; 287 | var allAttributes = PrinterAttribute.GetAttributes(request.Version).ToList(); 288 | bool IsRequired(string attributeName) 289 | { 290 | if (request.OperationAttributes is null) 291 | return true; 292 | if (request.OperationAttributes.RequestedAttributes is null || request.OperationAttributes.RequestedAttributes.Length == 0) 293 | return true; 294 | if (request.OperationAttributes.RequestedAttributes.All(x => x == string.Empty)) 295 | return true; 296 | return request.OperationAttributes.RequestedAttributes.Contains(attributeName); 297 | } 298 | logger.LogInformation("System returned printer attributes"); 299 | return new GetPrinterAttributesResponse 300 | { 301 | RequestId = request.RequestId, 302 | Version = request.Version, 303 | StatusCode = IppStatusCode.SuccessfulOk, 304 | PrinterState = !IsRequired(PrinterAttribute.PrinterState) 305 | ? null 306 | : _jobs.Values.Any(x => x.State == JobState.Pending || x.State == JobState.Processing) ? PrinterState.Processing : PrinterState.Idle, 307 | PrinterStateReasons = !IsRequired(PrinterAttribute.PrinterStateReasons) ? null : ["none"], 308 | CharsetConfigured = !IsRequired(PrinterAttribute.CharsetConfigured) ? null : "utf-8", 309 | CharsetSupported = !IsRequired(PrinterAttribute.CharsetSupported) ? null : ["utf-8"], 310 | NaturalLanguageConfigured = !IsRequired(PrinterAttribute.NaturalLanguageConfigured) ? null : "en-us", 311 | GeneratedNaturalLanguageSupported = !IsRequired(PrinterAttribute.GeneratedNaturalLanguageSupported) ? null : ["en-us"], 312 | PrinterIsAcceptingJobs = !IsRequired(PrinterAttribute.PrinterIsAcceptingJobs) ? null : true, 313 | PrinterMakeAndModel = !IsRequired(PrinterAttribute.PrinterMakeAndModel) ? null : options.Name, 314 | PrinterName = !IsRequired(PrinterAttribute.PrinterName) ? null : options.Name, 315 | PrinterInfo = !IsRequired(PrinterAttribute.PrinterInfo) ? null : options.Name, 316 | IppVersionsSupported = !IsRequired(PrinterAttribute.IppVersionsSupported) ? null : [new IppVersion(1, 0), IppVersion.V1_1, new IppVersion(2, 0)], 317 | DocumentFormatDefault = !IsRequired(PrinterAttribute.DocumentFormatDefault) ? null : options.DocumentFormat, 318 | ColorSupported = !IsRequired(PrinterAttribute.ColorSupported) ? null : true, 319 | PrinterCurrentTime = !IsRequired(PrinterAttribute.PrinterCurrentTime) ? null : dateTimeOffsetProvider.Now, 320 | OperationsSupported = !IsRequired(PrinterAttribute.OperationsSupported) ? null : 321 | [ 322 | IppOperation.PrintJob, 323 | IppOperation.PrintUri, 324 | IppOperation.ValidateJob, 325 | IppOperation.CreateJob, 326 | IppOperation.SendDocument, 327 | IppOperation.SendUri, 328 | IppOperation.CancelJob, 329 | IppOperation.GetJobAttributes, 330 | IppOperation.GetJobs, 331 | IppOperation.GetPrinterAttributes, 332 | IppOperation.HoldJob, 333 | IppOperation.ReleaseJob, 334 | IppOperation.RestartJob, 335 | IppOperation.PausePrinter, 336 | IppOperation.ResumePrinter 337 | ], 338 | QueuedJobCount = !IsRequired(PrinterAttribute.QueuedJobCount) ? null : _jobs.Values.Where(x => x.State == JobState.Pending || x.State == JobState.Processing).Count(), 339 | DocumentFormatSupported = !IsRequired(PrinterAttribute.DocumentFormatSupported) ? null : [options.DocumentFormat], 340 | MultipleDocumentJobsSupported = !IsRequired(PrinterAttribute.MultipleDocumentJobsSupported) ? null : true, 341 | CompressionSupported = !IsRequired(PrinterAttribute.CompressionSupported) ? null : [Compression.None], 342 | PrinterLocation = !IsRequired(PrinterAttribute.PrinterLocation) ? null : "Internet", 343 | PrintScalingDefault = !IsRequired(PrinterAttribute.PrintScalingDefault) ? null : options.PrintScaling.FirstOrDefault(), 344 | PrintScalingSupported = !IsRequired(PrinterAttribute.PrintScalingSupported) ? null : options.PrintScaling, 345 | PrinterUriSupported = !IsRequired(PrinterAttribute.PrinterUriSupported) ? null : [GetPrinterUrl()], 346 | UriAuthenticationSupported = !IsRequired(PrinterAttribute.UriAuthenticationSupported) ? null : [UriAuthentication.None], 347 | UriSecuritySupported = !IsRequired(PrinterAttribute.UriSecuritySupported) ? null : [GetUriSecuritySupported()], 348 | PrinterUpTime = !IsRequired(PrinterAttribute.PrinterUpTime) ? null : (int)(dateTimeOffsetProvider.UtcNow - _startTime).TotalSeconds, 349 | MediaDefault = !IsRequired(PrinterAttribute.MediaDefault) ? null : options.Media.FirstOrDefault(), 350 | MediaSupported = !IsRequired(PrinterAttribute.MediaSupported) ? null : options.Media, 351 | SidesDefault = !IsRequired(PrinterAttribute.SidesDefault) ? null : options.Sides.FirstOrDefault(), 352 | SidesSupported = !IsRequired(PrinterAttribute.SidesSupported) ? null : Enum.GetValues(typeof(Sides)).Cast().Where(x => x != Sides.Unsupported).ToArray(), 353 | PdlOverrideSupported = !IsRequired(PrinterAttribute.PdlOverrideSupported) ? null : "attempted", 354 | MultipleOperationTimeOut = !IsRequired(PrinterAttribute.MultipleOperationTimeOut) ? null : 120, 355 | FinishingsDefault = !IsRequired(PrinterAttribute.FinishingsDefault) ? null : options.Finishings.FirstOrDefault(), 356 | FinishingsSupported = !IsRequired(PrinterAttribute.SidesSupported) ? null : options.Finishings, 357 | PrinterResolutionDefault = !IsRequired(PrinterAttribute.PrinterResolutionDefault) ? null : options.Resolution.FirstOrDefault(), 358 | PrinterResolutionSupported = !IsRequired(PrinterAttribute.PrinterResolutionSupported) ? null : [options.Resolution.FirstOrDefault()], 359 | PrintQualityDefault = !IsRequired(PrinterAttribute.PrintQualityDefault) ? null : options.PrintQuality.FirstOrDefault(), 360 | PrintQualitySupported = !IsRequired(PrinterAttribute.PrintQualitySupported) ? null : options.PrintQuality, 361 | JobPriorityDefault = !IsRequired(PrinterAttribute.JobPriorityDefault) ? null : options.JobPriority, 362 | JobPrioritySupported = !IsRequired(PrinterAttribute.JobPrioritySupported) ? null : options.JobPriority, 363 | CopiesDefault = !IsRequired(PrinterAttribute.CopiesDefault) ? null : options.Copies, 364 | CopiesSupported = !IsRequired(PrinterAttribute.CopiesSupported) ? null : new SharpIpp.Protocol.Models.Range(options.Copies, options.Copies), 365 | OrientationRequestedDefault = !IsRequired(PrinterAttribute.OrientationRequestedDefault) ? null : options.Orientation, 366 | OrientationRequestedSupported = !IsRequired(PrinterAttribute.OrientationRequestedSupported) ? null : Enum.GetValues(typeof(Orientation)).Cast().Where(x => x != Orientation.Unsupported).ToArray(), 367 | PageRangesSupported = !IsRequired(PrinterAttribute.PageRangesSupported) ? null : false, 368 | PagesPerMinute = !IsRequired(PrinterAttribute.PagesPerMinute) ? null : 20, 369 | PagesPerMinuteColor = !IsRequired(PrinterAttribute.PagesPerMinuteColor) ? null : 20, 370 | PrinterMoreInfo = !IsRequired(PrinterAttribute.PrinterMoreInfo) ? null : GetPrinterMoreInfo(), 371 | JobHoldUntilSupported = !IsRequired(PrinterAttribute.JobHoldUntilSupported) ? null : [JobHoldUntil.NoHold], 372 | JobHoldUntilDefault = !IsRequired(PrinterAttribute.JobHoldUntilDefault) ? null : JobHoldUntil.NoHold, 373 | ReferenceUriSchemesSupported = !IsRequired(PrinterAttribute.ReferenceUriSchemesSupported) ? null : [UriScheme.Ftp, UriScheme.Http, UriScheme.Https], 374 | OutputBinDefault = !IsRequired(PrinterAttribute.OutputBinDefault) ? null : options.OutputBin.FirstOrDefault(), 375 | OutputBinSupported = !IsRequired(PrinterAttribute.OutputBinSupported) ? null : options.OutputBin, 376 | MediaColDefault = !IsRequired(PrinterAttribute.MediaColDefault) ? null : new MediaCol 377 | { 378 | MediaBackCoating = MediaCoating.None, 379 | MediaBottomMargin = 10, 380 | MediaColor = "black", 381 | MediaLeftMargin = 10, 382 | MediaRightMargin = 10, 383 | MediaTopMargin = 10, 384 | MediaFrontCoating = MediaCoating.None, 385 | MediaGrain = MediaGrain.XDirection, 386 | MediaHoleCount = 0, 387 | MediaInfo = "my black color", 388 | MediaOrderCount = 1 389 | }, 390 | PrintColorModeDefault = options.PrintColorModes.FirstOrDefault(), 391 | PrintColorModeSupported = options.PrintColorModes 392 | }; 393 | } 394 | 395 | private UriSecurity GetUriSecuritySupported() 396 | { 397 | var request = httpContextAccessor.HttpContext?.Request ?? throw new Exception("Unable to access HttpContext"); 398 | return request.IsHttps ? UriSecurity.Tls : UriSecurity.None; 399 | } 400 | 401 | private GetJobsResponse GetGetJobsResponse(GetJobsRequest request) 402 | { 403 | IEnumerable jobs = _jobs.Values; 404 | jobs = request.OperationAttributes?.WhichJobs switch 405 | { 406 | WhichJobs.Completed => jobs.Where(x => x.State == JobState.Completed || x.State == JobState.Aborted || x.State == JobState.Canceled), 407 | WhichJobs.NotCompleted => jobs.Where(x => x.State == JobState.Processing || x.State == JobState.Pending), 408 | _ => jobs.Where(x => x.State.HasValue) 409 | }; 410 | if (request.OperationAttributes?.MyJobs ?? false) 411 | jobs = jobs.Where(x => x.UserName?.Equals(request.OperationAttributes.RequestingUserName) ?? false); 412 | jobs = jobs.OrderByDescending(x => x.State).ThenByDescending(x => x.Id); 413 | if (request.OperationAttributes?.Limit.HasValue ?? false) 414 | jobs = jobs.Take(request.OperationAttributes.Limit.Value); 415 | logger.LogInformation("System returned jobs attributes"); 416 | return new GetJobsResponse 417 | { 418 | RequestId = request.RequestId, 419 | Version = request.Version, 420 | StatusCode = IppStatusCode.SuccessfulOk, 421 | Jobs = jobs.Select(x => GetJobDescriptionAttributes(x, request.OperationAttributes?.RequestedAttributes, true)).ToArray() 422 | }; 423 | } 424 | 425 | private GetJobAttributesResponse GetGetJobAttributesResponse(GetJobAttributesRequest request) 426 | { 427 | var response = new GetJobAttributesResponse 428 | { 429 | RequestId = request.RequestId, 430 | Version = request.Version, 431 | StatusCode = IppStatusCode.ClientErrorNotPossible, 432 | JobAttributes = new() 433 | }; 434 | var jobId = GetJobId(request); 435 | if (!jobId.HasValue) 436 | return response; 437 | if (!_jobs.TryGetValue(jobId.Value, out var job)) 438 | return response; 439 | response.JobAttributes = GetJobDescriptionAttributes(job, request.OperationAttributes?.RequestedAttributes, false); 440 | response.StatusCode = IppStatusCode.SuccessfulOk; 441 | logger.LogInformation("System returned job attributes for job {id}", jobId); 442 | return response; 443 | } 444 | 445 | private JobDescriptionAttributes GetJobDescriptionAttributes(PrinterJob job, string[]? requestedAttributes, bool isBatch) 446 | { 447 | var jobAttributes = job.Requests.Select(x => x switch 448 | { 449 | CreateJobRequest createJobRequest => createJobRequest.JobTemplateAttributes, 450 | PrintJobRequest printJobRequest => printJobRequest.JobTemplateAttributes, 451 | PrintUriRequest printUriRequest => printUriRequest.JobTemplateAttributes, 452 | _ => null, 453 | }).FirstOrDefault(x => x != null); 454 | var jobName = job.Requests.Select(x => x switch 455 | { 456 | CreateJobRequest createJobRequest => createJobRequest.OperationAttributes?.JobName, 457 | PrintJobRequest printJobRequest => printJobRequest.OperationAttributes?.JobName, 458 | PrintUriRequest printUriRequest => printUriRequest.OperationAttributes?.JobName, 459 | _ => null, 460 | }).FirstOrDefault(x => x != null); 461 | var ippAttributeFidelity = job.Requests.Select(x => x switch 462 | { 463 | CreateJobRequest createJobRequest => createJobRequest.OperationAttributes?.IppAttributeFidelity, 464 | PrintJobRequest printJobRequest => printJobRequest.OperationAttributes?.IppAttributeFidelity, 465 | PrintUriRequest printUriRequest => printUriRequest.OperationAttributes?.IppAttributeFidelity, 466 | _ => null, 467 | }).FirstOrDefault(x => x != null); 468 | var compression = job.Requests.Select(x => x switch 469 | { 470 | PrintJobRequest printJobRequest => printJobRequest.OperationAttributes?.Compression, 471 | PrintUriRequest printUriRequest => printUriRequest.OperationAttributes?.Compression, 472 | SendDocumentRequest sendDocumentRequest => sendDocumentRequest.OperationAttributes?.Compression, 473 | SendUriRequest sendUriRequest => sendUriRequest.OperationAttributes?.Compression, 474 | _ => null, 475 | }).FirstOrDefault(x => x != null); 476 | 477 | 478 | bool IsRequired(string attributeName) 479 | { 480 | if (requestedAttributes is null || requestedAttributes.Length == 0) 481 | return !isBatch; 482 | if(requestedAttributes.All(x => x == "all")) 483 | return true; 484 | return requestedAttributes.Contains(attributeName); 485 | } 486 | var attributes = new JobDescriptionAttributes 487 | { 488 | JobId = job.Id, 489 | JobName = !IsRequired(JobAttribute.JobName) ? null : jobName, 490 | JobUri = $"{GetPrinterUrl()}/{job.Id}", 491 | JobPrinterUri = !IsRequired(JobAttribute.JobPrinterUri) ? null : GetPrinterUrl(), 492 | JobState = !IsRequired(JobAttribute.JobState) ? null : job.State, 493 | JobStateReasons = !IsRequired(JobAttribute.JobState) ? null : [JobStateReason.None], 494 | DateTimeAtCreation = !IsRequired(JobAttribute.DateTimeAtCreation) ? null : job.CreatedDateTime, 495 | TimeAtCreation = !IsRequired(JobAttribute.TimeAtCreation) ? null : (int)(job.CreatedDateTime - _startTime).TotalSeconds, 496 | DateTimeAtProcessing = !IsRequired(JobAttribute.DateTimeAtProcessing) ? null : job.ProcessingDateTime ?? DateTimeOffset.MinValue, 497 | TimeAtProcessing = !IsRequired(JobAttribute.TimeAtProcessing) ? null : job.ProcessingDateTime.HasValue ? (int)(job.ProcessingDateTime.Value - _startTime).TotalSeconds : -1, 498 | DateTimeAtCompleted = !IsRequired(JobAttribute.DateTimeAtCompleted) ? null : job.CompletedDateTime ?? DateTimeOffset.MinValue, 499 | TimeAtCompleted = !IsRequired(JobAttribute.TimeAtCompleted) ? null : job.CompletedDateTime.HasValue ? (int)(job.CompletedDateTime.Value - _startTime).TotalSeconds : -1, 500 | JobOriginatingUserName = !IsRequired(JobAttribute.JobOriginatingUserName) ? null : job.UserName, 501 | JobPrinterUpTime = !IsRequired(JobAttribute.JobPrinterUpTime) ? null : (int)(dateTimeOffsetProvider.UtcNow - _startTime).TotalSeconds 502 | }; 503 | return attributes; 504 | } 505 | 506 | private static CUPSGetPrintersResponse GetCUPSGetPrintersResponse(CUPSGetPrintersRequest request) 507 | { 508 | return new CUPSGetPrintersResponse 509 | { 510 | RequestId = request.RequestId, 511 | Version = request.Version, 512 | StatusCode = IppStatusCode.SuccessfulOk 513 | }; 514 | } 515 | 516 | private CreateJobResponse GetCreateJobResponse(CreateJobRequest request) 517 | { 518 | var response = new CreateJobResponse 519 | { 520 | RequestId = request.RequestId, 521 | Version = request.Version, 522 | JobState = JobState.Pending, 523 | StatusCode = IppStatusCode.ClientErrorNotPossible, 524 | JobStateReasons = [JobStateReason.None] 525 | }; 526 | var job = new PrinterJob(GetNextValue(), request.OperationAttributes?.RequestingUserName, dateTimeOffsetProvider.UtcNow); 527 | response.JobId = job.Id; 528 | response.JobUri = $"{GetPrinterUrl()}/{job.Id}"; 529 | FillWithDefaultValues(job.Id, request.OperationAttributes ??= new()); 530 | FillWithDefaultValues(request.JobTemplateAttributes ??= new()); 531 | job.Requests.Add(request); 532 | if (!_jobs.TryAdd(job.Id, job)) 533 | return response; 534 | response.StatusCode = IppStatusCode.SuccessfulOk; 535 | logger.LogInformation("Job {id} has been added to queue", job.Id); 536 | return response; 537 | } 538 | 539 | private async Task GetCancelJobResponseAsync(CancelJobRequest request) 540 | { 541 | var response = new CancelJobResponse 542 | { 543 | RequestId = request.RequestId, 544 | Version = request.Version, 545 | StatusCode = IppStatusCode.ClientErrorNotPossible 546 | }; 547 | var jobId = GetJobId(request); 548 | if (!jobId.HasValue) 549 | return response; 550 | if (!_jobs.TryGetValue(jobId.Value, out var job)) 551 | return response; 552 | var copy = new PrinterJob(job); 553 | if (!await copy.TrySetStateAsync(JobState.Canceled, dateTimeOffsetProvider.UtcNow)) 554 | return response; 555 | if (!_jobs.TryUpdate(jobId.Value, copy, job)) 556 | return response; 557 | response.StatusCode = IppStatusCode.SuccessfulOk; 558 | logger.LogInformation("Job {id} has been canceled", jobId); 559 | return response; 560 | } 561 | 562 | public async Task GetPendingJobAsync() 563 | { 564 | if (_isPaused) 565 | return null; 566 | foreach (var job in _jobs.Values.Where(x => x.State == JobState.Pending).OrderBy(x => x.Id)) 567 | { 568 | var copy = new PrinterJob(job); 569 | if (!await copy.TrySetStateAsync(JobState.Processing, dateTimeOffsetProvider.UtcNow)) 570 | continue; 571 | if (!_jobs.TryUpdate(job.Id, copy, job)) 572 | continue; 573 | return copy; 574 | } 575 | return null; 576 | } 577 | 578 | public async Task AddCompletedJobAsync(int jobId) 579 | { 580 | if (!_jobs.TryGetValue(jobId, out var job)) 581 | return; 582 | var copy = new PrinterJob(job); 583 | if (!await copy.TrySetStateAsync(JobState.Completed, dateTimeOffsetProvider.UtcNow)) 584 | return; 585 | if (!_jobs.TryUpdate(jobId, copy, job)) 586 | return; 587 | logger.LogInformation("Job {id} has been completed", job.Id); 588 | } 589 | 590 | public async Task AddAbortedJobAsync(int jobId, Exception ex) 591 | { 592 | if (!_jobs.TryGetValue(jobId, out var job)) 593 | return; 594 | var copy = new PrinterJob(job); 595 | if (!await copy.TrySetStateAsync(JobState.Aborted, dateTimeOffsetProvider.UtcNow)) 596 | return; 597 | if (!_jobs.TryUpdate(jobId, copy, job)) 598 | return; 599 | logger.LogError(ex, "Job {id} has been aborted", job.Id); 600 | } 601 | 602 | private async Task GetPrintJobResponseAsync(PrintJobRequest request) 603 | { 604 | var response = new PrintJobResponse 605 | { 606 | RequestId = request.RequestId, 607 | Version = request.Version, 608 | JobState = JobState.Pending, 609 | StatusCode = IppStatusCode.ClientErrorNotPossible, 610 | JobStateReasons = [JobStateReason.None] 611 | }; 612 | var job = new PrinterJob(GetNextValue(), request.OperationAttributes?.RequestingUserName, dateTimeOffsetProvider.UtcNow); 613 | response.JobId = job.Id; 614 | response.JobUri = $"{GetPrinterUrl()}/{job.Id}"; 615 | FillWithDefaultValues(job.Id, request.OperationAttributes ??= new()); 616 | FillWithDefaultValues(request.JobTemplateAttributes ??= new()); 617 | job.Requests.Add(request); 618 | if (!await job.TrySetStateAsync(JobState.Pending, dateTimeOffsetProvider.UtcNow)) 619 | return response; 620 | if (!_jobs.TryAdd(job.Id, job)) 621 | return response; 622 | response.StatusCode = IppStatusCode.SuccessfulOk; 623 | logger.LogInformation("Job {id} has been added to queue", job.Id); 624 | return response; 625 | } 626 | 627 | private string GetPrinterUrl() 628 | { 629 | var request = httpContextAccessor.HttpContext?.Request ?? throw new Exception("Unable to access HttpContext"); 630 | return $"ipp://{request.Host}{request.PathBase}{request.Path}"; 631 | } 632 | 633 | private string GetPrinterMoreInfo() 634 | { 635 | var request = httpContextAccessor.HttpContext?.Request ?? throw new Exception("Unable to access HttpContext"); 636 | return $"{request.Scheme}://{request.Host}{request.PathBase}"; 637 | } 638 | 639 | private static int? GetJobId(IIppJobRequest request) 640 | { 641 | if(request.OperationAttributes is not JobOperationAttributes jobOperationAttributes) 642 | return null; 643 | if (jobOperationAttributes.JobUri != null && int.TryParse(jobOperationAttributes.JobUri.Segments.LastOrDefault(), out int idFromUri)) 644 | return idFromUri; 645 | return jobOperationAttributes.JobId; 646 | } 647 | 648 | private void FillWithDefaultValues(JobTemplateAttributes? attributes) 649 | { 650 | if (attributes == null) 651 | return; 652 | var options = printerOptions.Value; 653 | attributes.PrintScaling ??= options.PrintScaling.FirstOrDefault(); 654 | attributes.Sides ??= options.Sides.FirstOrDefault(); 655 | attributes.Media ??= options.Media.FirstOrDefault(); 656 | attributes.PrinterResolution ??= options.Resolution.FirstOrDefault(); 657 | attributes.Finishings ??= options.Finishings.FirstOrDefault(); 658 | attributes.PrintQuality ??= options.PrintQuality.FirstOrDefault(); 659 | attributes.JobPriority ??= options.JobPriority; 660 | attributes.Copies ??= options.Copies; 661 | attributes.OrientationRequested ??= options.Orientation; 662 | attributes.JobHoldUntil ??= options.JobHoldUntil; 663 | attributes.PrintColorMode ??= options.PrintColorModes.FirstOrDefault(); 664 | } 665 | 666 | private void FillWithDefaultValues(SendDocumentOperationAttributes? attributes) 667 | { 668 | if (attributes is null) 669 | return; 670 | var options = printerOptions.Value; 671 | if (string.IsNullOrEmpty(attributes.DocumentFormat)) 672 | attributes.DocumentFormat = options.DocumentFormat; 673 | } 674 | 675 | private void FillWithDefaultValues(int jobId, PrintJobOperationAttributes? attributes) 676 | { 677 | if (attributes is null) 678 | return; 679 | var options = printerOptions.Value; 680 | if (string.IsNullOrEmpty(attributes.DocumentFormat)) 681 | attributes.DocumentFormat = options.DocumentFormat; 682 | FillWithDefaultValues(jobId, attributes as CreateJobOperationAttributes); 683 | } 684 | 685 | private void FillWithDefaultValues(int jobId, CreateJobOperationAttributes? attributes) 686 | { 687 | if (attributes is null) 688 | return; 689 | if (string.IsNullOrEmpty(attributes.JobName)) 690 | attributes.JobName = $"Job {jobId}"; 691 | } 692 | 693 | public async ValueTask DisposeAsync() 694 | { 695 | await DisposeAsyncCore().ConfigureAwait(false); 696 | Dispose(disposing: false); 697 | GC.SuppressFinalize(this); 698 | } 699 | 700 | protected virtual async ValueTask DisposeAsyncCore() 701 | { 702 | foreach (var job in _jobs.Values) 703 | await job.DisposeAsync(); 704 | _jobs.Clear(); 705 | } 706 | 707 | protected virtual void Dispose(bool disposing) 708 | { 709 | if (disposedValue) 710 | return; 711 | if (disposing) 712 | { 713 | foreach (var job in _jobs.Values) 714 | job.Dispose(); 715 | _jobs.Clear(); 716 | } 717 | disposedValue = true; 718 | } 719 | 720 | public void Dispose() 721 | { 722 | Dispose(disposing: true); 723 | GC.SuppressFinalize(this); 724 | } 725 | } 726 | -------------------------------------------------------------------------------- /SharpIppNextServer/Services/SecurityHeadersMiddleware.cs: -------------------------------------------------------------------------------- 1 | namespace SharpIppNextServer.Services; 2 | 3 | public class SecurityHeadersMiddleware(RequestDelegate next) 4 | { 5 | public async Task InvokeAsync(HttpContext httpContext) 6 | { 7 | httpContext.Response.Headers.TryAdd("X-Frame-Options", "DENY"); 8 | httpContext.Response.Headers.TryAdd("Content-Security-Policy", $"default-src 'none';"); 9 | httpContext.Response.Headers.TryAdd("X-Content-Type-Options", "nosniff"); 10 | httpContext.Response.Headers.TryAdd("Referrer-Policy", "strict-origin-when-cross-origin"); 11 | httpContext.Response.Headers.TryAdd("Permissions-Policy", "camera=(), geolocation=(), microphone=()"); 12 | httpContext.Response.Headers.TryAdd("Cross-Origin-Opener-Policy", "unsafe-none"); 13 | httpContext.Response.Headers.TryAdd("Cross-Origin-Embedder-Policy", "unsafe-none"); 14 | httpContext.Response.Headers.TryAdd("Cross-Origin-Resource-Policy", "same-origin"); 15 | await next(httpContext); 16 | } 17 | } -------------------------------------------------------------------------------- /SharpIppNextServer/SharpIppNextServer.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | 1.0.0 8 | win-x64;linux-x64;osx-x64 9 | Daniel Klecha 10 | Daniel Klecha 11 | IPP printer 12 | false 13 | false 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | Always 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /SharpIppNextServer/SharpIppNextServer.http: -------------------------------------------------------------------------------- 1 | @HostAddress = http://localhost:631 2 | 3 | GET {{HostAddress}}/ 4 | Accept: application/json 5 | 6 | ### 7 | 8 | POST {{HostAddress}}/ 9 | Accept: application/ipp -------------------------------------------------------------------------------- /SharpIppNextServer/THIRD-PARTY-NOTICES.txt: -------------------------------------------------------------------------------- 1 | Microsoft.Extensions.Configuration.Abstractions.dll 2 | Microsoft.Extensions.DependencyInjection.Abstractions.dll 3 | Microsoft.Extensions.Diagnostics.Abstractions.dll 4 | Microsoft.Extensions.FileProviders.Abstractions.dll 5 | Microsoft.Extensions.Hosting.Abstractions.dll 6 | Microsoft.Extensions.Logging.Abstractions.dll 7 | Microsoft.Extensions.Options.dll 8 | Microsoft.Extensions.Primitives.dll 9 | System.Configuration.ConfigurationManager.dll 10 | System.Diagnostics.DiagnosticSource.dll 11 | System.Diagnostics.EventLog.dll 12 | System.Security.Cryptography.ProtectedData.dll 13 | runtimes\win\lib\net8.0\System.Diagnostics.EventLog.Messages.dll 14 | runtimes\win\lib\net8.0\System.Diagnostics.EventLog.dll 15 | ---------------------------------------------------------------- 16 | The MIT License (MIT) 17 | 18 | Copyright (c) .NET Foundation and Contributors 19 | 20 | All rights reserved. 21 | 22 | Permission is hereby granted, free of charge, to any person obtaining a copy 23 | of this software and associated documentation files (the "Software"), to deal 24 | in the Software without restriction, including without limitation the rights 25 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 26 | copies of the Software, and to permit persons to whom the Software is 27 | furnished to do so, subject to the following conditions: 28 | 29 | The above copyright notice and this permission notice shall be included in all 30 | copies or substantial portions of the Software. 31 | 32 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 33 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 34 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 35 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 36 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 37 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 38 | SOFTWARE. 39 | 40 | Quartz.dll 41 | Quartz.Extensions.DependencyInjection.dll 42 | Quartz.Extensions.Hosting.dll 43 | ----------------------------------------- 44 | Apache License 45 | Version 2.0, January 2004 46 | http://www.apache.org/licenses/ 47 | 48 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 49 | 50 | 1. Definitions. 51 | 52 | "License" shall mean the terms and conditions for use, reproduction, 53 | and distribution as defined by Sections 1 through 9 of this document. 54 | 55 | "Licensor" shall mean the copyright owner or entity authorized by 56 | the copyright owner that is granting the License. 57 | 58 | "Legal Entity" shall mean the union of the acting entity and all 59 | other entities that control, are controlled by, or are under common 60 | control with that entity. For the purposes of this definition, 61 | "control" means (i) the power, direct or indirect, to cause the 62 | direction or management of such entity, whether by contract or 63 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 64 | outstanding shares, or (iii) beneficial ownership of such entity. 65 | 66 | "You" (or "Your") shall mean an individual or Legal Entity 67 | exercising permissions granted by this License. 68 | 69 | "Source" form shall mean the preferred form for making modifications, 70 | including but not limited to software source code, documentation 71 | source, and configuration files. 72 | 73 | "Object" form shall mean any form resulting from mechanical 74 | transformation or translation of a Source form, including but 75 | not limited to compiled object code, generated documentation, 76 | and conversions to other media types. 77 | 78 | "Work" shall mean the work of authorship, whether in Source or 79 | Object form, made available under the License, as indicated by a 80 | copyright notice that is included in or attached to the work 81 | (an example is provided in the Appendix below). 82 | 83 | "Derivative Works" shall mean any work, whether in Source or Object 84 | form, that is based on (or derived from) the Work and for which the 85 | editorial revisions, annotations, elaborations, or other modifications 86 | represent, as a whole, an original work of authorship. For the purposes 87 | of this License, Derivative Works shall not include works that remain 88 | separable from, or merely link (or bind by name) to the interfaces of, 89 | the Work and Derivative Works thereof. 90 | 91 | "Contribution" shall mean any work of authorship, including 92 | the original version of the Work and any modifications or additions 93 | to that Work or Derivative Works thereof, that is intentionally 94 | submitted to Licensor for inclusion in the Work by the copyright owner 95 | or by an individual or Legal Entity authorized to submit on behalf of 96 | the copyright owner. For the purposes of this definition, "submitted" 97 | means any form of electronic, verbal, or written communication sent 98 | to the Licensor or its representatives, including but not limited to 99 | communication on electronic mailing lists, source code control systems, 100 | and issue tracking systems that are managed by, or on behalf of, the 101 | Licensor for the purpose of discussing and improving the Work, but 102 | excluding communication that is conspicuously marked or otherwise 103 | designated in writing by the copyright owner as "Not a Contribution." 104 | 105 | "Contributor" shall mean Licensor and any individual or Legal Entity 106 | on behalf of whom a Contribution has been received by Licensor and 107 | subsequently incorporated within the Work. 108 | 109 | 2. Grant of Copyright License. Subject to the terms and conditions of 110 | this License, each Contributor hereby grants to You a perpetual, 111 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 112 | copyright license to reproduce, prepare Derivative Works of, 113 | publicly display, publicly perform, sublicense, and distribute the 114 | Work and such Derivative Works in Source or Object form. 115 | 116 | 3. Grant of Patent License. Subject to the terms and conditions of 117 | this License, each Contributor hereby grants to You a perpetual, 118 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 119 | (except as stated in this section) patent license to make, have made, 120 | use, offer to sell, sell, import, and otherwise transfer the Work, 121 | where such license applies only to those patent claims licensable 122 | by such Contributor that are necessarily infringed by their 123 | Contribution(s) alone or by combination of their Contribution(s) 124 | with the Work to which such Contribution(s) was submitted. If You 125 | institute patent litigation against any entity (including a 126 | cross-claim or counterclaim in a lawsuit) alleging that the Work 127 | or a Contribution incorporated within the Work constitutes direct 128 | or contributory patent infringement, then any patent licenses 129 | granted to You under this License for that Work shall terminate 130 | as of the date such litigation is filed. 131 | 132 | 4. Redistribution. You may reproduce and distribute copies of the 133 | Work or Derivative Works thereof in any medium, with or without 134 | modifications, and in Source or Object form, provided that You 135 | meet the following conditions: 136 | 137 | (a) You must give any other recipients of the Work or 138 | Derivative Works a copy of this License; and 139 | 140 | (b) You must cause any modified files to carry prominent notices 141 | stating that You changed the files; and 142 | 143 | (c) You must retain, in the Source form of any Derivative Works 144 | that You distribute, all copyright, patent, trademark, and 145 | attribution notices from the Source form of the Work, 146 | excluding those notices that do not pertain to any part of 147 | the Derivative Works; and 148 | 149 | (d) If the Work includes a "NOTICE" text file as part of its 150 | distribution, then any Derivative Works that You distribute must 151 | include a readable copy of the attribution notices contained 152 | within such NOTICE file, excluding those notices that do not 153 | pertain to any part of the Derivative Works, in at least one 154 | of the following places: within a NOTICE text file distributed 155 | as part of the Derivative Works; within the Source form or 156 | documentation, if provided along with the Derivative Works; or, 157 | within a display generated by the Derivative Works, if and 158 | wherever such third-party notices normally appear. The contents 159 | of the NOTICE file are for informational purposes only and 160 | do not modify the License. You may add Your own attribution 161 | notices within Derivative Works that You distribute, alongside 162 | or as an addendum to the NOTICE text from the Work, provided 163 | that such additional attribution notices cannot be construed 164 | as modifying the License. 165 | 166 | You may add Your own copyright statement to Your modifications and 167 | may provide additional or different license terms and conditions 168 | for use, reproduction, or distribution of Your modifications, or 169 | for any such Derivative Works as a whole, provided Your use, 170 | reproduction, and distribution of the Work otherwise complies with 171 | the conditions stated in this License. 172 | 173 | 5. Submission of Contributions. Unless You explicitly state otherwise, 174 | any Contribution intentionally submitted for inclusion in the Work 175 | by You to the Licensor shall be under the terms and conditions of 176 | this License, without any additional terms or conditions. 177 | Notwithstanding the above, nothing herein shall supersede or modify 178 | the terms of any separate license agreement you may have executed 179 | with Licensor regarding such Contributions. 180 | 181 | 6. Trademarks. This License does not grant permission to use the trade 182 | names, trademarks, service marks, or product names of the Licensor, 183 | except as required for reasonable and customary use in describing the 184 | origin of the Work and reproducing the content of the NOTICE file. 185 | 186 | 7. Disclaimer of Warranty. Unless required by applicable law or 187 | agreed to in writing, Licensor provides the Work (and each 188 | Contributor provides its Contributions) on an "AS IS" BASIS, 189 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 190 | implied, including, without limitation, any warranties or conditions 191 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 192 | PARTICULAR PURPOSE. You are solely responsible for determining the 193 | appropriateness of using or redistributing the Work and assume any 194 | risks associated with Your exercise of permissions under this License. 195 | 196 | 8. Limitation of Liability. In no event and under no legal theory, 197 | whether in tort (including negligence), contract, or otherwise, 198 | unless required by applicable law (such as deliberate and grossly 199 | negligent acts) or agreed to in writing, shall any Contributor be 200 | liable to You for damages, including any direct, indirect, special, 201 | incidental, or consequential damages of any character arising as a 202 | result of this License or out of the use or inability to use the 203 | Work (including but not limited to damages for loss of goodwill, 204 | work stoppage, computer failure or malfunction, or any and all 205 | other commercial damages or losses), even if such Contributor 206 | has been advised of the possibility of such damages. 207 | 208 | 9. Accepting Warranty or Additional Liability. While redistributing 209 | the Work or Derivative Works thereof, You may choose to offer, 210 | and charge a fee for, acceptance of support, warranty, indemnity, 211 | or other liability obligations and/or rights consistent with this 212 | License. However, in accepting such obligations, You may act only 213 | on Your own behalf and on Your sole responsibility, not on behalf 214 | of any other Contributor, and only if You agree to indemnify, 215 | defend, and hold each Contributor harmless for any liability 216 | incurred by, or claims asserted against, such Contributor by reason 217 | of your accepting any such warranty or additional liability. 218 | 219 | END OF TERMS AND CONDITIONS 220 | 221 | APPENDIX: How to apply the Apache License to your work. 222 | 223 | To apply the Apache License to your work, attach the following 224 | boilerplate notice, with the fields enclosed by brackets "[]" 225 | replaced with your own identifying information. (Don't include 226 | the brackets!) The text should be enclosed in the appropriate 227 | comment syntax for the file format. We also recommend that a 228 | file or class name and description of purpose be included on the 229 | same "printed page" as the copyright notice for easier 230 | identification within third-party archives. 231 | 232 | Copyright 2007 Marko Lahma 233 | 234 | Licensed under the Apache License, Version 2.0 (the "License"); 235 | you may not use this file except in compliance with the License. 236 | You may obtain a copy of the License at 237 | 238 | http://www.apache.org/licenses/LICENSE-2.0 239 | 240 | Unless required by applicable law or agreed to in writing, software 241 | distributed under the License is distributed on an "AS IS" BASIS, 242 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 243 | See the License for the specific language governing permissions and 244 | limitations under the License. 245 | 246 | SharpIpp.dll 247 | ------------ 248 | MIT License 249 | 250 | Copyright (c) 2023 Daniel Klecha 251 | Copyright (c) 2020 Evgeny Zelenov 252 | 253 | Permission is hereby granted, free of charge, to any person obtaining a copy 254 | of this software and associated documentation files (the "Software"), to deal 255 | in the Software without restriction, including without limitation the rights 256 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 257 | copies of the Software, and to permit persons to whom the Software is 258 | furnished to do so, subject to the following conditions: 259 | 260 | The above copyright notice and this permission notice shall be included in all 261 | copies or substantial portions of the Software. 262 | 263 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 264 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 265 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 266 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 267 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 268 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 269 | SOFTWARE. 270 | 271 | System.IO.Abstractions.dll 272 | TestableIO.System.IO.Abstractions.dll 273 | TestableIO.System.IO.Abstractions.Wrappers.dll 274 | ---------------------------------------------- 275 | The MIT License (MIT) 276 | 277 | Copyright (c) Tatham Oddie and Contributors 278 | 279 | All rights reserved. 280 | 281 | Permission is hereby granted, free of charge, to any person obtaining a copy 282 | of this software and associated documentation files (the "Software"), to deal 283 | in the Software without restriction, including without limitation the rights 284 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 285 | copies of the Software, and to permit persons to whom the Software is 286 | furnished to do so, subject to the following conditions: 287 | 288 | The above copyright notice and this permission notice shall be included in all 289 | copies or substantial portions of the Software. 290 | 291 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 292 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 293 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 294 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 295 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 296 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 297 | SOFTWARE. 298 | 299 | -------------------------------------------------------------------------------- /SharpIppNextServer/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information" 5 | } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /SharpIppNextServer/appsettings.Production.json: -------------------------------------------------------------------------------- 1 | { 2 | "Kestrel": { 3 | "Endpoints": { 4 | "Http": { 5 | "Url": "http://0.0.0.0:631" 6 | } 7 | } 8 | } 9 | } -------------------------------------------------------------------------------- /SharpIppNextServer/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.Hosting.Lifetime": "Information", 6 | "Microsoft.AspNetCore": "Warning", 7 | "Quartz": "Warning" 8 | } 9 | }, 10 | "Printer": { 11 | "Name": "SharpIppNext" 12 | }, 13 | "AllowedHosts": "*" 14 | } 15 | -------------------------------------------------------------------------------- /global.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdk": { 3 | "version": "8.0.0", 4 | "allowPrerelease": false, 5 | "rollForward": "latestMinor" 6 | } 7 | } --------------------------------------------------------------------------------