Merge branch 'feature/remove-noconfirm-trust'
@@ -809,7 +809,7 @@ dependencies = [
809
809
"bitflags 1.3.2",
810
810
"core-foundation 0.9.4",
811
811
"core-graphics-types",
812
"foreign-types",
812
"foreign-types 0.5.0",
813
813
"libc",
814
814
]
815
815
@@ -1236,6 +1236,15 @@ version = "0.1.5"
1236
1236
source = "registry+https://github.com/rust-lang/crates.io-index"
1237
1237
checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
1238
1238
1239
[[package]]
1240
name = "foreign-types"
1241
version = "0.3.2"
1242
source = "registry+https://github.com/rust-lang/crates.io-index"
1243
checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
1244
dependencies = [
1245
"foreign-types-shared 0.1.1",
1246
]
1247
1239
1248
[[package]]
1240
1249
name = "foreign-types"
1241
1250
version = "0.5.0"
@@ -1243,7 +1252,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1243
1252
checksum = "d737d9aa519fb7b749cbc3b962edcf310a8dd1f4b67c91c4f83975dbdd17d965"
1244
1253
dependencies = [
1245
1254
"foreign-types-macros",
1246
"foreign-types-shared",
1255
"foreign-types-shared 0.3.1",
1247
1256
]
1248
1257
1249
1258
[[package]]
@@ -1257,6 +1266,12 @@ dependencies = [
1257
1266
"syn 2.0.119",
1258
1267
]
1259
1268
1269
[[package]]
1270
name = "foreign-types-shared"
1271
version = "0.1.1"
1272
source = "registry+https://github.com/rust-lang/crates.io-index"
1273
checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
1274
1260
1275
[[package]]
1261
1276
name = "foreign-types-shared"
1262
1277
version = "0.3.1"
@@ -1357,17 +1372,6 @@ dependencies = [
1357
1372
"unicode-width 0.2.2",
1358
1373
]
1359
1374
1360
[[package]]
1361
name = "getrandom"
1362
version = "0.2.17"
1363
source = "registry+https://github.com/rust-lang/crates.io-index"
1364
checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0"
1365
dependencies = [
1366
"cfg-if",
1367
"libc",
1368
"wasi",
1369
]
1370
1371
1375
[[package]]
1372
1376
name = "getrandom"
1373
1377
version = "0.3.4"
@@ -2095,7 +2099,7 @@ dependencies = [
2095
2099
"bitflags 2.13.1",
2096
2100
"block",
2097
2101
"core-graphics-types",
2098
"foreign-types",
2102
"foreign-types 0.5.0",
2099
2103
"log",
2100
2104
"objc",
2101
2105
"paste",
@@ -2143,6 +2147,23 @@ dependencies = [
2143
2147
"unicode-xid",
2144
2148
]
2145
2149
2150
[[package]]
2151
name = "native-tls"
2152
version = "0.2.18"
2153
source = "registry+https://github.com/rust-lang/crates.io-index"
2154
checksum = "465500e14ea162429d264d44189adc38b199b62b1c21eea9f69e4b73cb03bbf2"
2155
dependencies = [
2156
"libc",
2157
"log",
2158
"openssl",
2159
"openssl-probe",
2160
"openssl-sys",
2161
"schannel",
2162
"security-framework",
2163
"security-framework-sys",
2164
"tempfile",
2165
]
2166
2146
2167
[[package]]
2147
2168
name = "ndk"
2148
2169
version = "0.9.0"
@@ -2604,6 +2625,49 @@ version = "1.70.2"
2604
2625
source = "registry+https://github.com/rust-lang/crates.io-index"
2605
2626
checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
2606
2627
2628
[[package]]
2629
name = "openssl"
2630
version = "0.10.81"
2631
source = "registry+https://github.com/rust-lang/crates.io-index"
2632
checksum = "77823a27f0babb03091cb9ed9ef80af3b39dbc82f97e8fa530374b7dafd87a45"
2633
dependencies = [
2634
"bitflags 2.13.1",
2635
"cfg-if",
2636
"foreign-types 0.3.2",
2637
"libc",
2638
"openssl-macros",
2639
"openssl-sys",
2640
]
2641
2642
[[package]]
2643
name = "openssl-macros"
2644
version = "0.1.1"
2645
source = "registry+https://github.com/rust-lang/crates.io-index"
2646
checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
2647
dependencies = [
2648
"proc-macro2",
2649
"quote",
2650
"syn 2.0.119",
2651
]
2652
2653
[[package]]
2654
name = "openssl-probe"
2655
version = "0.2.1"
2656
source = "registry+https://github.com/rust-lang/crates.io-index"
2657
checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe"
2658
2659
[[package]]
2660
name = "openssl-sys"
2661
version = "0.9.117"
2662
source = "registry+https://github.com/rust-lang/crates.io-index"
2663
checksum = "b47e7e6bb2c38cd930d25a23b40fa52e068c10e85f3e03a7f5ba5aaca5713695"
2664
dependencies = [
2665
"cc",
2666
"libc",
2667
"pkg-config",
2668
"vcpkg",
2669
]
2670
2607
2671
[[package]]
2608
2672
name = "orbclient"
2609
2673
version = "0.3.55"
@@ -2786,7 +2850,7 @@ checksum = "2f3a9f18d041e6d0e102a0a46750538147e5e8992d3b4873aaafee2520b00ce3"
2786
2850
2787
2851
[[package]]
2788
2852
name = "posprint"
2789
version = "0.5.5"
2853
version = "0.5.6"
2790
2854
dependencies = [
2791
2855
"barcoders",
2792
2856
"base64",
@@ -2797,6 +2861,7 @@ dependencies = [
2797
2861
"ico",
2798
2862
"image",
2799
2863
"libc",
2864
"native-tls",
2800
2865
"pulldown-cmark",
2801
2866
"qrcode",
2802
2867
"rfd",
@@ -3150,20 +3215,6 @@ version = "0.8.53"
3150
3215
source = "registry+https://github.com/rust-lang/crates.io-index"
3151
3216
checksum = "47b34b781b31e5d73e9fbc8689c70551fd1ade9a19e3e28cfec8580a79290cc4"
3152
3217
3153
[[package]]
3154
name = "ring"
3155
version = "0.17.14"
3156
source = "registry+https://github.com/rust-lang/crates.io-index"
3157
checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7"
3158
dependencies = [
3159
"cc",
3160
"cfg-if",
3161
"getrandom 0.2.17",
3162
"libc",
3163
"untrusted",
3164
"windows-sys 0.52.0",
3165
]
3166
3167
3218
[[package]]
3168
3219
name = "rusb"
3169
3220
version = "0.9.4"
@@ -3221,41 +3272,6 @@ dependencies = [
3221
3272
"windows-sys 0.61.2",
3222
3273
]
3223
3274
3224
[[package]]
3225
name = "rustls"
3226
version = "0.23.42"
3227
source = "registry+https://github.com/rust-lang/crates.io-index"
3228
checksum = "3c54fcab019b409d04215d3a17cb438fd7fbf192ee61461f20f4fe18704bc138"
3229
dependencies = [
3230
"log",
3231
"once_cell",
3232
"ring",
3233
"rustls-pki-types",
3234
"rustls-webpki",
3235
"subtle",
3236
"zeroize",
3237
]
3238
3239
[[package]]
3240
name = "rustls-pki-types"
3241
version = "1.15.0"
3242
source = "registry+https://github.com/rust-lang/crates.io-index"
3243
checksum = "764899a24af3980067ee14bc143654f297b22eaebfe3c7b6b211920a5a59b046"
3244
dependencies = [
3245
"zeroize",
3246
]
3247
3248
[[package]]
3249
name = "rustls-webpki"
3250
version = "0.103.13"
3251
source = "registry+https://github.com/rust-lang/crates.io-index"
3252
checksum = "61c429a8649f110dddef65e2a5ad240f747e85f7758a6bccc7e5777bd33f756e"
3253
dependencies = [
3254
"ring",
3255
"rustls-pki-types",
3256
"untrusted",
3257
]
3258
3259
3275
[[package]]
3260
3276
name = "rustversion"
3261
3277
version = "1.0.23"
@@ -3271,6 +3287,15 @@ dependencies = [
3271
3287
"winapi-util",
3272
3288
]
3273
3289
3290
[[package]]
3291
name = "schannel"
3292
version = "0.1.29"
3293
source = "registry+https://github.com/rust-lang/crates.io-index"
3294
checksum = "91c1b7e4904c873ef0710c1f407dde2e6287de2bebc1bbbf7d430bb7cbffd939"
3295
dependencies = [
3296
"windows-sys 0.61.2",
3297
]
3298
3274
3299
[[package]]
3275
3300
name = "scoped-tls"
3276
3301
version = "1.0.1"
@@ -3283,6 +3308,29 @@ version = "1.2.0"
3283
3308
source = "registry+https://github.com/rust-lang/crates.io-index"
3284
3309
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
3285
3310
3311
[[package]]
3312
name = "security-framework"
3313
version = "3.7.0"
3314
source = "registry+https://github.com/rust-lang/crates.io-index"
3315
checksum = "b7f4bc775c73d9a02cde8bf7b2ec4c9d12743edf609006c7facc23998404cd1d"
3316
dependencies = [
3317
"bitflags 2.13.1",
3318
"core-foundation 0.10.1",
3319
"core-foundation-sys",
3320
"libc",
3321
"security-framework-sys",
3322
]
3323
3324
[[package]]
3325
name = "security-framework-sys"
3326
version = "2.17.0"
3327
source = "registry+https://github.com/rust-lang/crates.io-index"
3328
checksum = "6ce2691df843ecc5d231c0b14ece2acc3efb62c0a398c7e1d875f3983ce020e3"
3329
dependencies = [
3330
"core-foundation-sys",
3331
"libc",
3332
]
3333
3286
3334
[[package]]
3287
3335
name = "semver"
3288
3336
version = "1.0.28"
@@ -3551,12 +3599,6 @@ dependencies = [
3551
3599
"syn 2.0.119",
3552
3600
]
3553
3601
3554
[[package]]
3555
name = "subtle"
3556
version = "2.6.1"
3557
source = "registry+https://github.com/rust-lang/crates.io-index"
3558
checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
3559
3560
3602
[[package]]
3561
3603
name = "syn"
3562
3604
version = "2.0.119"
@@ -3818,12 +3860,6 @@ version = "0.2.6"
3818
3860
source = "registry+https://github.com/rust-lang/crates.io-index"
3819
3861
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
3820
3862
3821
[[package]]
3822
name = "untrusted"
3823
version = "0.9.0"
3824
source = "registry+https://github.com/rust-lang/crates.io-index"
3825
checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1"
3826
3827
3863
[[package]]
3828
3864
name = "ureq"
3829
3865
version = "2.12.1"
@@ -3832,11 +3868,9 @@ checksum = "02d1a66277ed75f640d608235660df48c8e3c19f3b4edb6a263315626cc3c01d"
3832
3868
dependencies = [
3833
3869
"base64",
3834
3870
"log",
3871
"native-tls",
3835
3872
"once_cell",
3836
"rustls",
3837
"rustls-pki-types",
3838
3873
"url",
3839
"webpki-roots 0.26.11",
3840
3874
]
3841
3875
3842
3876
[[package]]
@@ -3914,12 +3948,6 @@ dependencies = [
3914
3948
"winapi-util",
3915
3949
]
3916
3950
3917
[[package]]
3918
name = "wasi"
3919
version = "0.11.1+wasi-snapshot-preview1"
3920
source = "registry+https://github.com/rust-lang/crates.io-index"
3921
checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
3922
3923
3951
[[package]]
3924
3952
name = "wasip2"
3925
3953
version = "1.0.4+wasi-0.2.12"
@@ -4155,24 +4183,6 @@ dependencies = [
4155
4183
"web-sys",
4156
4184
]
4157
4185
4158
[[package]]
4159
name = "webpki-roots"
4160
version = "0.26.11"
4161
source = "registry+https://github.com/rust-lang/crates.io-index"
4162
checksum = "521bc38abb08001b01866da9f51eb7c5d647a19260e00054a8c7fd5f9e57f7a9"
4163
dependencies = [
4164
"webpki-roots 1.0.9",
4165
]
4166
4167
[[package]]
4168
name = "webpki-roots"
4169
version = "1.0.9"
4170
source = "registry+https://github.com/rust-lang/crates.io-index"
4171
checksum = "7dcd9d09a39985f5344844e66b0c530a33843579125f23e21e9f0f220850f22a"
4172
dependencies = [
4173
"rustls-pki-types",
4174
]
4175
4176
4186
[[package]]
4177
4187
name = "weezl"
4178
4188
version = "0.1.12"
@@ -4886,12 +4896,6 @@ dependencies = [
4886
4896
"synstructure",
4887
4897
]
4888
4898
4889
[[package]]
4890
name = "zeroize"
4891
version = "1.9.0"
4892
source = "registry+https://github.com/rust-lang/crates.io-index"
4893
checksum = "e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e"
4894
4895
4899
[[package]]
4896
4900
name = "zerotrie"
4897
4901
version = "0.2.4"
@@ -809,7 +809,7 @@ dependencies = [809
"bitflags 1.3.2",809
"bitflags 1.3.2",810
"core-foundation 0.9.4",810
"core-foundation 0.9.4",811
"core-graphics-types",811
"core-graphics-types",812
"foreign-types",812
"foreign-types 0.5.0",813
"libc",813
"libc",814
]814
]815
815
@@ -1236,6 +1236,15 @@ version = "0.1.5"1236
source = "registry+https://github.com/rust-lang/crates.io-index"1236
source = "registry+https://github.com/rust-lang/crates.io-index"1237
checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"1237
checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"1238
1238
1239
[[package]]1240
name = "foreign-types"1241
version = "0.3.2"1242
source = "registry+https://github.com/rust-lang/crates.io-index"1243
checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"1244
dependencies = [1245
"foreign-types-shared 0.1.1",1246
]1247
1239
[[package]]1248
[[package]]1240
name = "foreign-types"1249
name = "foreign-types"1241
version = "0.5.0"1250
version = "0.5.0"@@ -1243,7 +1252,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"1243
checksum = "d737d9aa519fb7b749cbc3b962edcf310a8dd1f4b67c91c4f83975dbdd17d965"1252
checksum = "d737d9aa519fb7b749cbc3b962edcf310a8dd1f4b67c91c4f83975dbdd17d965"1244
dependencies = [1253
dependencies = [1245
"foreign-types-macros",1254
"foreign-types-macros",1246
"foreign-types-shared",1255
"foreign-types-shared 0.3.1",1247
]1256
]1248
1257
1249
[[package]]1258
[[package]]@@ -1257,6 +1266,12 @@ dependencies = [1257
"syn 2.0.119",1266
"syn 2.0.119",1258
]1267
]1259
1268
1269
[[package]]1270
name = "foreign-types-shared"1271
version = "0.1.1"1272
source = "registry+https://github.com/rust-lang/crates.io-index"1273
checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"1274
1260
[[package]]1275
[[package]]1261
name = "foreign-types-shared"1276
name = "foreign-types-shared"1262
version = "0.3.1"1277
version = "0.3.1"@@ -1357,17 +1372,6 @@ dependencies = [1357
"unicode-width 0.2.2",1372
"unicode-width 0.2.2",1358
]1373
]1359
1374
1360
[[package]]1361
name = "getrandom"1362
version = "0.2.17"1363
source = "registry+https://github.com/rust-lang/crates.io-index"1364
checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0"1365
dependencies = [1366
"cfg-if",1367
"libc",1368
"wasi",1369
]1370
1371
[[package]]1375
[[package]]1372
name = "getrandom"1376
name = "getrandom"1373
version = "0.3.4"1377
version = "0.3.4"@@ -2095,7 +2099,7 @@ dependencies = [2095
"bitflags 2.13.1",2099
"bitflags 2.13.1",2096
"block",2100
"block",2097
"core-graphics-types",2101
"core-graphics-types",2098
"foreign-types",2102
"foreign-types 0.5.0",2099
"log",2103
"log",2100
"objc",2104
"objc",2101
"paste",2105
"paste",@@ -2143,6 +2147,23 @@ dependencies = [2143
"unicode-xid",2147
"unicode-xid",2144
]2148
]2145
2149
2150
[[package]]2151
name = "native-tls"2152
version = "0.2.18"2153
source = "registry+https://github.com/rust-lang/crates.io-index"2154
checksum = "465500e14ea162429d264d44189adc38b199b62b1c21eea9f69e4b73cb03bbf2"2155
dependencies = [2156
"libc",2157
"log",2158
"openssl",2159
"openssl-probe",2160
"openssl-sys",2161
"schannel",2162
"security-framework",2163
"security-framework-sys",2164
"tempfile",2165
]2166
2146
[[package]]2167
[[package]]2147
name = "ndk"2168
name = "ndk"2148
version = "0.9.0"2169
version = "0.9.0"@@ -2604,6 +2625,49 @@ version = "1.70.2"2604
source = "registry+https://github.com/rust-lang/crates.io-index"2625
source = "registry+https://github.com/rust-lang/crates.io-index"2605
checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"2626
checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"2606
2627
2628
[[package]]2629
name = "openssl"2630
version = "0.10.81"2631
source = "registry+https://github.com/rust-lang/crates.io-index"2632
checksum = "77823a27f0babb03091cb9ed9ef80af3b39dbc82f97e8fa530374b7dafd87a45"2633
dependencies = [2634
"bitflags 2.13.1",2635
"cfg-if",2636
"foreign-types 0.3.2",2637
"libc",2638
"openssl-macros",2639
"openssl-sys",2640
]2641
2642
[[package]]2643
name = "openssl-macros"2644
version = "0.1.1"2645
source = "registry+https://github.com/rust-lang/crates.io-index"2646
checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"2647
dependencies = [2648
"proc-macro2",2649
"quote",2650
"syn 2.0.119",2651
]2652
2653
[[package]]2654
name = "openssl-probe"2655
version = "0.2.1"2656
source = "registry+https://github.com/rust-lang/crates.io-index"2657
checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe"2658
2659
[[package]]2660
name = "openssl-sys"2661
version = "0.9.117"2662
source = "registry+https://github.com/rust-lang/crates.io-index"2663
checksum = "b47e7e6bb2c38cd930d25a23b40fa52e068c10e85f3e03a7f5ba5aaca5713695"2664
dependencies = [2665
"cc",2666
"libc",2667
"pkg-config",2668
"vcpkg",2669
]2670
2607
[[package]]2671
[[package]]2608
name = "orbclient"2672
name = "orbclient"2609
version = "0.3.55"2673
version = "0.3.55"@@ -2786,7 +2850,7 @@ checksum = "2f3a9f18d041e6d0e102a0a46750538147e5e8992d3b4873aaafee2520b00ce3"2786
2850
2787
[[package]]2851
[[package]]2788
name = "posprint"2852
name = "posprint"2789
version = "0.5.5"2853
version = "0.5.6"2790
dependencies = [2854
dependencies = [2791
"barcoders",2855
"barcoders",2792
"base64",2856
"base64",@@ -2797,6 +2861,7 @@ dependencies = [2797
"ico",2861
"ico",2798
"image",2862
"image",2799
"libc",2863
"libc",2864
"native-tls",2800
"pulldown-cmark",2865
"pulldown-cmark",2801
"qrcode",2866
"qrcode",2802
"rfd",2867
"rfd",@@ -3150,20 +3215,6 @@ version = "0.8.53"3150
source = "registry+https://github.com/rust-lang/crates.io-index"3215
source = "registry+https://github.com/rust-lang/crates.io-index"3151
checksum = "47b34b781b31e5d73e9fbc8689c70551fd1ade9a19e3e28cfec8580a79290cc4"3216
checksum = "47b34b781b31e5d73e9fbc8689c70551fd1ade9a19e3e28cfec8580a79290cc4"3152
3217
3153
[[package]]3154
name = "ring"3155
version = "0.17.14"3156
source = "registry+https://github.com/rust-lang/crates.io-index"3157
checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7"3158
dependencies = [3159
"cc",3160
"cfg-if",3161
"getrandom 0.2.17",3162
"libc",3163
"untrusted",3164
"windows-sys 0.52.0",3165
]3166
3167
[[package]]3218
[[package]]3168
name = "rusb"3219
name = "rusb"3169
version = "0.9.4"3220
version = "0.9.4"@@ -3221,41 +3272,6 @@ dependencies = [3221
"windows-sys 0.61.2",3272
"windows-sys 0.61.2",3222
]3273
]3223
3274
3224
[[package]]3225
name = "rustls"3226
version = "0.23.42"3227
source = "registry+https://github.com/rust-lang/crates.io-index"3228
checksum = "3c54fcab019b409d04215d3a17cb438fd7fbf192ee61461f20f4fe18704bc138"3229
dependencies = [3230
"log",3231
"once_cell",3232
"ring",3233
"rustls-pki-types",3234
"rustls-webpki",3235
"subtle",3236
"zeroize",3237
]3238
3239
[[package]]3240
name = "rustls-pki-types"3241
version = "1.15.0"3242
source = "registry+https://github.com/rust-lang/crates.io-index"3243
checksum = "764899a24af3980067ee14bc143654f297b22eaebfe3c7b6b211920a5a59b046"3244
dependencies = [3245
"zeroize",3246
]3247
3248
[[package]]3249
name = "rustls-webpki"3250
version = "0.103.13"3251
source = "registry+https://github.com/rust-lang/crates.io-index"3252
checksum = "61c429a8649f110dddef65e2a5ad240f747e85f7758a6bccc7e5777bd33f756e"3253
dependencies = [3254
"ring",3255
"rustls-pki-types",3256
"untrusted",3257
]3258
3259
[[package]]3275
[[package]]3260
name = "rustversion"3276
name = "rustversion"3261
version = "1.0.23"3277
version = "1.0.23"@@ -3271,6 +3287,15 @@ dependencies = [3271
"winapi-util",3287
"winapi-util",3272
]3288
]3273
3289
3290
[[package]]3291
name = "schannel"3292
version = "0.1.29"3293
source = "registry+https://github.com/rust-lang/crates.io-index"3294
checksum = "91c1b7e4904c873ef0710c1f407dde2e6287de2bebc1bbbf7d430bb7cbffd939"3295
dependencies = [3296
"windows-sys 0.61.2",3297
]3298
3274
[[package]]3299
[[package]]3275
name = "scoped-tls"3300
name = "scoped-tls"3276
version = "1.0.1"3301
version = "1.0.1"@@ -3283,6 +3308,29 @@ version = "1.2.0"3283
source = "registry+https://github.com/rust-lang/crates.io-index"3308
source = "registry+https://github.com/rust-lang/crates.io-index"3284
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"3309
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"3285
3310
3311
[[package]]3312
name = "security-framework"3313
version = "3.7.0"3314
source = "registry+https://github.com/rust-lang/crates.io-index"3315
checksum = "b7f4bc775c73d9a02cde8bf7b2ec4c9d12743edf609006c7facc23998404cd1d"3316
dependencies = [3317
"bitflags 2.13.1",3318
"core-foundation 0.10.1",3319
"core-foundation-sys",3320
"libc",3321
"security-framework-sys",3322
]3323
3324
[[package]]3325
name = "security-framework-sys"3326
version = "2.17.0"3327
source = "registry+https://github.com/rust-lang/crates.io-index"3328
checksum = "6ce2691df843ecc5d231c0b14ece2acc3efb62c0a398c7e1d875f3983ce020e3"3329
dependencies = [3330
"core-foundation-sys",3331
"libc",3332
]3333
3286
[[package]]3334
[[package]]3287
name = "semver"3335
name = "semver"3288
version = "1.0.28"3336
version = "1.0.28"@@ -3551,12 +3599,6 @@ dependencies = [3551
"syn 2.0.119",3599
"syn 2.0.119",3552
]3600
]3553
3601
3554
[[package]]3555
name = "subtle"3556
version = "2.6.1"3557
source = "registry+https://github.com/rust-lang/crates.io-index"3558
checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"3559
3560
[[package]]3602
[[package]]3561
name = "syn"3603
name = "syn"3562
version = "2.0.119"3604
version = "2.0.119"@@ -3818,12 +3860,6 @@ version = "0.2.6"3818
source = "registry+https://github.com/rust-lang/crates.io-index"3860
source = "registry+https://github.com/rust-lang/crates.io-index"3819
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"3861
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"3820
3862
3821
[[package]]3822
name = "untrusted"3823
version = "0.9.0"3824
source = "registry+https://github.com/rust-lang/crates.io-index"3825
checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1"3826
3827
[[package]]3863
[[package]]3828
name = "ureq"3864
name = "ureq"3829
version = "2.12.1"3865
version = "2.12.1"@@ -3832,11 +3868,9 @@ checksum = "02d1a66277ed75f640d608235660df48c8e3c19f3b4edb6a263315626cc3c01d"3832
dependencies = [3868
dependencies = [3833
"base64",3869
"base64",3834
"log",3870
"log",3871
"native-tls",3835
"once_cell",3872
"once_cell",3836
"rustls",3837
"rustls-pki-types",3838
"url",3873
"url",3839
"webpki-roots 0.26.11",3840
]3874
]3841
3875
3842
[[package]]3876
[[package]]@@ -3914,12 +3948,6 @@ dependencies = [3914
"winapi-util",3948
"winapi-util",3915
]3949
]3916
3950
3917
[[package]]3918
name = "wasi"3919
version = "0.11.1+wasi-snapshot-preview1"3920
source = "registry+https://github.com/rust-lang/crates.io-index"3921
checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"3922
3923
[[package]]3951
[[package]]3924
name = "wasip2"3952
name = "wasip2"3925
version = "1.0.4+wasi-0.2.12"3953
version = "1.0.4+wasi-0.2.12"@@ -4155,24 +4183,6 @@ dependencies = [4155
"web-sys",4183
"web-sys",4156
]4184
]4157
4185
4158
[[package]]4159
name = "webpki-roots"4160
version = "0.26.11"4161
source = "registry+https://github.com/rust-lang/crates.io-index"4162
checksum = "521bc38abb08001b01866da9f51eb7c5d647a19260e00054a8c7fd5f9e57f7a9"4163
dependencies = [4164
"webpki-roots 1.0.9",4165
]4166
4167
[[package]]4168
name = "webpki-roots"4169
version = "1.0.9"4170
source = "registry+https://github.com/rust-lang/crates.io-index"4171
checksum = "7dcd9d09a39985f5344844e66b0c530a33843579125f23e21e9f0f220850f22a"4172
dependencies = [4173
"rustls-pki-types",4174
]4175
4176
[[package]]4186
[[package]]4177
name = "weezl"4187
name = "weezl"4178
version = "0.1.12"4188
version = "0.1.12"@@ -4886,12 +4896,6 @@ dependencies = [4886
"synstructure",4896
"synstructure",4887
]4897
]4888
4898
4889
[[package]]4890
name = "zeroize"4891
version = "1.9.0"4892
source = "registry+https://github.com/rust-lang/crates.io-index"4893
checksum = "e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e"4894
4895
[[package]]4899
[[package]]4896
name = "zerotrie"4900
name = "zerotrie"4897
version = "0.2.4"4901
version = "0.2.4"@@ -1,6 +1,6 @@
1
1
[package]
2
2
name = "posprint"
3
version = "0.5.5"
3
version = "0.5.6"
4
4
edition = "2021"
5
5
rust-version = "1.88"
6
6
description = "Designer for POS-print documents"
@@ -25,7 +25,8 @@ libc = "0.2"
25
25
tempfile = "3"
26
26
flate2 = "1"
27
27
base64 = "0.22"
28
ureq = { version = "2", default-features = false, features = ["tls"] }
28
ureq = { version = "2", default-features = false, features = ["native-tls"] }
29
native-tls = "0.2"
29
30
30
31
[dev-dependencies]
31
32
tempfile = "3"
@@ -1,6 +1,6 @@1
[package]
1
[package]
2
name = "posprint"
2
name = "posprint"
3
version = "0.5.5"
3
version = "0.5.6"
4
edition = "2021"
4
edition = "2021"
5
rust-version = "1.88"
5
rust-version = "1.88"
6
description = "Designer for POS-print documents"
6
description = "Designer for POS-print documents"
@@ -25,7 +25,8 @@ libc = "0.2"25
tempfile = "3"
25
tempfile = "3"
26
flate2 = "1"
26
flate2 = "1"
27
base64 = "0.22"
27
base64 = "0.22"
28
ureq = { version = "2", default-features = false, features = ["tls"] }
28
ureq = { version = "2", default-features = false, features = ["native-tls"] }
29
native-tls = "0.2"
29
30
30
[dev-dependencies]
31
[dev-dependencies]
31
tempfile = "3"
32
tempfile = "3"
@@ -6,7 +6,7 @@ Cross-platform designer for POS (point-of-sale) receipt documents. Edit template
6
6
7
7
## Status
8
8
9
**v0.5.5** — Tab completion caret fix, multi-word barcode/QR data, native HRI off by default.
9
**v0.5.6** — Drop noconfirm trust/referrer verify; QR/barcode URLs with query strings; skip TLS checks for `@image` downloads.
10
10
11
11
## Build and run
12
12
@@ -6,7 +6,7 @@ Cross-platform designer for POS (point-of-sale) receipt documents. Edit template6
6
7
## Status7
## Status8
8
9
**v0.5.5** — Tab completion caret fix, multi-word barcode/QR data, native HRI off by default.9
**v0.5.6** — Drop noconfirm trust/referrer verify; QR/barcode URLs with query strings; skip TLS checks for `@image` downloads.10
10
11
## Build and run11
## Build and run12
12
@@ -33,7 +33,6 @@ src/
33
33
├── raster.rs # Barcode / QR bitmaps
34
34
├── image_load.rs # Local + http(s) @image loading
35
35
├── protocol_url.rs # posprint:// encode/decode
36
├── referrer_verify.rs # noconfirm referrer GET (HTTP 200)
37
36
├── editor_assist.rs # @ autocomplete, Insert snippets
38
37
├── help_view.rs # Markdown help renderer
39
38
├── io/mod.rs # PosFile, PosMetadata
@@ -72,11 +71,11 @@ ESC/POS generation is **in-tree** (`escpos.rs`), not the `escpos` crates.io pack
72
71
|------|--------|-------------|
73
72
| **Design** | `app.rs` | Editor + side preview |
74
73
| **Help** | `help_view.rs` | `docs/HELP.md` via `include_str!` |
75
| **Settings** | `app.rs` | Default page width; trusted `noconfirm` origins |
74
| **Settings** | `app.rs` | Default page width for new documents |
76
75
| Toolbar | `app.rs` | New, Open, Save, Save As, Insert, Print |
77
76
| Document page width / zoom | `app.rs` | Per-document width (mm), preview zoom |
78
77
| Print dialog | `print_dialog.rs` | Parameters + multi-transport printer picker |
79
| App config | `config.rs` | `%APPDATA%/posprint/config.json` (Windows) / `~/.config/posprint/config.json` (trusted origins, default width, last printer) |
78
| App config | `config.rs` | `%APPDATA%/posprint/config.json` (Windows) / `~/.config/posprint/config.json` (default width, last printer) |
80
79
81
80
While the print dialog is open, the main UI is disabled and editor autocomplete does not steal focus.
82
81
@@ -156,7 +155,7 @@ Legacy JSON fields `preview_mode` and `cut_after_print` are ignored if present.
156
155
|------|---------|
157
156
| Template + metadata | `.pos` file |
158
157
| Last parameter values | In-memory (`print_dialog.last_params`) |
159
| Default page width / trusted origins / last printer | `config.rs` → platform config JSON |
158
| Default page width / last printer | `config.rs` → platform config JSON |
160
159
| Recent files | Not persisted |
161
160
162
161
---
@@ -33,7 +33,6 @@ src/33
├── raster.rs # Barcode / QR bitmaps33
├── raster.rs # Barcode / QR bitmaps34
├── image_load.rs # Local + http(s) @image loading34
├── image_load.rs # Local + http(s) @image loading35
├── protocol_url.rs # posprint:// encode/decode35
├── protocol_url.rs # posprint:// encode/decode36
├── referrer_verify.rs # noconfirm referrer GET (HTTP 200)37
├── editor_assist.rs # @ autocomplete, Insert snippets36
├── editor_assist.rs # @ autocomplete, Insert snippets38
├── help_view.rs # Markdown help renderer37
├── help_view.rs # Markdown help renderer39
├── io/mod.rs # PosFile, PosMetadata38
├── io/mod.rs # PosFile, PosMetadata@@ -72,11 +71,11 @@ ESC/POS generation is **in-tree** (`escpos.rs`), not the `escpos` crates.io pack72
|------|--------|-------------|71
|------|--------|-------------|73
| **Design** | `app.rs` | Editor + side preview |72
| **Design** | `app.rs` | Editor + side preview |74
| **Help** | `help_view.rs` | `docs/HELP.md` via `include_str!` |73
| **Help** | `help_view.rs` | `docs/HELP.md` via `include_str!` |75
| **Settings** | `app.rs` | Default page width; trusted `noconfirm` origins |74
| **Settings** | `app.rs` | Default page width for new documents |76
| Toolbar | `app.rs` | New, Open, Save, Save As, Insert, Print |75
| Toolbar | `app.rs` | New, Open, Save, Save As, Insert, Print |77
| Document page width / zoom | `app.rs` | Per-document width (mm), preview zoom |76
| Document page width / zoom | `app.rs` | Per-document width (mm), preview zoom |78
| Print dialog | `print_dialog.rs` | Parameters + multi-transport printer picker |77
| Print dialog | `print_dialog.rs` | Parameters + multi-transport printer picker |79
| App config | `config.rs` | `%APPDATA%/posprint/config.json` (Windows) / `~/.config/posprint/config.json` (trusted origins, default width, last printer) |78
| App config | `config.rs` | `%APPDATA%/posprint/config.json` (Windows) / `~/.config/posprint/config.json` (default width, last printer) |80
79
81
While the print dialog is open, the main UI is disabled and editor autocomplete does not steal focus.80
While the print dialog is open, the main UI is disabled and editor autocomplete does not steal focus.82
81
@@ -156,7 +155,7 @@ Legacy JSON fields `preview_mode` and `cut_after_print` are ignored if present.156
|------|---------|155
|------|---------|157
| Template + metadata | `.pos` file |156
| Template + metadata | `.pos` file |158
| Last parameter values | In-memory (`print_dialog.last_params`) |157
| Last parameter values | In-memory (`print_dialog.last_params`) |159
| Default page width / trusted origins / last printer | `config.rs` → platform config JSON |158
| Default page width / last printer | `config.rs` → platform config JSON |160
| Recent files | Not persisted |159
| Recent files | Not persisted |161
160
162
---161
---@@ -198,7 +198,7 @@ Images are converted to monochrome raster data and scaled to width (never wider
198
198
|-------|--------|
199
199
| Mode | Optional `RASTER` prefix; otherwise native ESC/POS |
200
200
| Symbology | Native: `CODE128`, `EAN13`, `EAN8`, `CODE39`, `UPC-A`, `UPC-E`, `ITF`, `CODABAR`. Raster-only: `CODE93`, `CODE11` |
201
| Data | Literal or `${Param}`; multiple words joined until the first `key=value` attribute |
201
| Data | Literal or `${Param}`; multiple words joined until the first attribute token (`height=…`, `align=…`); URLs with `?a=1` are data |
202
202
| `height` | Module / PNG height in dots (default: 64) |
203
203
| `align` | `left`, `center`, `right` |
204
204
| `show_text` | Native only: print HRI text under barcode (default: off; set `show_text=true` to enable) |
@@ -215,7 +215,7 @@ Raster barcodes stretch horizontally to full printable width.
215
215
216
216
| Attribute | Native | Raster |
217
217
|-----------|--------|--------|
218
| Data | URL/text; may include `${Param}`; multiple words joined until the first `key=value` attribute | Same |
218
| Data | URL/text; may include `${Param}`; multiple words joined until the first attribute token (`size=…`, `ecc=…`); URLs with `?a=1` are data | Same |
219
219
| `size` | Module size 1–16 (default 4) | — |
220
220
| `scale` | — | Pixels per module (default 4) |
221
221
| `version` | — | QR version 1–40 (optional) |
@@ -198,7 +198,7 @@ Images are converted to monochrome raster data and scaled to width (never wider198
|-------|--------|198
|-------|--------|199
| Mode | Optional `RASTER` prefix; otherwise native ESC/POS |199
| Mode | Optional `RASTER` prefix; otherwise native ESC/POS |200
| Symbology | Native: `CODE128`, `EAN13`, `EAN8`, `CODE39`, `UPC-A`, `UPC-E`, `ITF`, `CODABAR`. Raster-only: `CODE93`, `CODE11` |200
| Symbology | Native: `CODE128`, `EAN13`, `EAN8`, `CODE39`, `UPC-A`, `UPC-E`, `ITF`, `CODABAR`. Raster-only: `CODE93`, `CODE11` |201
| Data | Literal or `${Param}`; multiple words joined until the first `key=value` attribute |201
| Data | Literal or `${Param}`; multiple words joined until the first attribute token (`height=…`, `align=…`); URLs with `?a=1` are data |202
| `height` | Module / PNG height in dots (default: 64) |202
| `height` | Module / PNG height in dots (default: 64) |203
| `align` | `left`, `center`, `right` |203
| `align` | `left`, `center`, `right` |204
| `show_text` | Native only: print HRI text under barcode (default: off; set `show_text=true` to enable) |204
| `show_text` | Native only: print HRI text under barcode (default: off; set `show_text=true` to enable) |@@ -215,7 +215,7 @@ Raster barcodes stretch horizontally to full printable width.215
215
216
| Attribute | Native | Raster |216
| Attribute | Native | Raster |217
|-----------|--------|--------|217
|-----------|--------|--------|218
| Data | URL/text; may include `${Param}`; multiple words joined until the first `key=value` attribute | Same |218
| Data | URL/text; may include `${Param}`; multiple words joined until the first attribute token (`size=…`, `ecc=…`); URLs with `?a=1` are data | Same |219
| `size` | Module size 1–16 (default 4) | — |219
| `size` | Module size 1–16 (default 4) | — |220
| `scale` | — | Pixels per module (default 4) |220
| `scale` | — | Pixels per module (default 4) |221
| `version` | — | QR version 1–40 (optional) |221
| `version` | — | QR version 1–40 (optional) |@@ -10,7 +10,7 @@ Built-in reference for the template editor and POS markup language.
10
10
|-----|---------|
11
11
| **Design** | Side-by-side template editor and live preview |
12
12
| **Help** | This documentation |
13
| **Settings** | Default page width for new documents; trusted sites for `noconfirm` |
13
| **Settings** | Default page width for new documents |
14
14
15
15
## Toolbar actions
16
16
@@ -168,7 +168,7 @@ Blank lines in the editor also feed one line (same as `@feed 1`).
168
168
@image ${LogoPath} width=50% align=center
169
169
```
170
170
171
Local paths resolve relative to the `.pos` file. `http://` and `https://` URLs are downloaded when preview or print needs the image.
171
Local paths resolve relative to the `.pos` file. `http://` and `https://` URLs are downloaded when preview or print needs the image (TLS certificate errors are ignored so corporate/self-signed hosts still work).
172
172
173
173
### Barcode
174
174
@@ -209,7 +209,7 @@ Local paths resolve relative to the `.pos` file. `http://` and `https://` URLs a
209
209
| `align` | `left`, `center`, `right` |
210
210
| `show_text` | Native only: human-readable text under barcode (default off; `show_text=true` to enable) |
211
211
212
Data may contain spaces; tokens after the symbology are joined until the first `key=value` attribute.
212
Data may contain spaces; tokens after the symbology are joined until the first attribute token (`size=…`, `align=…`, etc.). A URL with a query string (`https://…?a=1`) is still data.
213
213
214
214
### QR code
215
215
@@ -317,7 +317,7 @@ Websites can open the print dialog with an embedded template:
317
317
posprint://print?v=1&d=…
318
318
```
319
319
320
Add `&noconfirm=1&referrer=<percent-encoded verify URL>` to print after the site’s verify endpoint returns HTTP 200 and (on first use) the user trusts that domain (**Settings → Trusted sites**). Auto-print uses the last printer that printed successfully when that device is still available. Encoding helpers live in [`lib/`](../lib/). Full guide: [POSPRINT-URL.md](POSPRINT-URL.md).
320
Add `&noconfirm=1` to auto-print once a printer is ready (the browser’s protocol prompt is the consent step). Auto-print uses the last printer that printed successfully when that device is still available. Encoding helpers live in [`lib/`](../lib/). Full guide: [POSPRINT-URL.md](POSPRINT-URL.md).
321
321
322
322
`@image` may use `https://…` or `http://…` (downloaded when preview/print needs the image).
323
323
@@ -10,7 +10,7 @@ Built-in reference for the template editor and POS markup language.10
|-----|---------|10
|-----|---------|11
| **Design** | Side-by-side template editor and live preview |11
| **Design** | Side-by-side template editor and live preview |12
| **Help** | This documentation |12
| **Help** | This documentation |13
| **Settings** | Default page width for new documents; trusted sites for `noconfirm` |13
| **Settings** | Default page width for new documents |14
14
15
## Toolbar actions15
## Toolbar actions16
16
@@ -168,7 +168,7 @@ Blank lines in the editor also feed one line (same as `@feed 1`).168
@image ${LogoPath} width=50% align=center168
@image ${LogoPath} width=50% align=center169
```169
```170
170
171
Local paths resolve relative to the `.pos` file. `http://` and `https://` URLs are downloaded when preview or print needs the image.171
Local paths resolve relative to the `.pos` file. `http://` and `https://` URLs are downloaded when preview or print needs the image (TLS certificate errors are ignored so corporate/self-signed hosts still work).172
172
173
### Barcode173
### Barcode174
174
@@ -209,7 +209,7 @@ Local paths resolve relative to the `.pos` file. `http://` and `https://` URLs a209
| `align` | `left`, `center`, `right` |209
| `align` | `left`, `center`, `right` |210
| `show_text` | Native only: human-readable text under barcode (default off; `show_text=true` to enable) |210
| `show_text` | Native only: human-readable text under barcode (default off; `show_text=true` to enable) |211
211
212
Data may contain spaces; tokens after the symbology are joined until the first `key=value` attribute.212
Data may contain spaces; tokens after the symbology are joined until the first attribute token (`size=…`, `align=…`, etc.). A URL with a query string (`https://…?a=1`) is still data.213
213
214
### QR code214
### QR code215
215
@@ -317,7 +317,7 @@ Websites can open the print dialog with an embedded template:317
posprint://print?v=1&d=…317
posprint://print?v=1&d=…318
```318
```319
319
320
Add `&noconfirm=1&referrer=<percent-encoded verify URL>` to print after the site’s verify endpoint returns HTTP 200 and (on first use) the user trusts that domain (**Settings → Trusted sites**). Auto-print uses the last printer that printed successfully when that device is still available. Encoding helpers live in [`lib/`](../lib/). Full guide: [POSPRINT-URL.md](POSPRINT-URL.md).320
Add `&noconfirm=1` to auto-print once a printer is ready (the browser’s protocol prompt is the consent step). Auto-print uses the last printer that printed successfully when that device is still available. Encoding helpers live in [`lib/`](../lib/). Full guide: [POSPRINT-URL.md](POSPRINT-URL.md).321
321
322
`@image` may use `https://…` or `http://…` (downloaded when preview/print needs the image).322
`@image` may use `https://…` or `http://…` (downloaded when preview/print needs the image).323
323
@@ -15,7 +15,7 @@ posprint://print?v=1&d=<BASE64URL(raw_deflate(utf8(.pos JSON)))>
15
15
Optional auto-print:
16
16
17
17
```
18
posprint://print?v=1&d=…&noconfirm=1&referrer=website.com%2Fbonnen%2Fverify%3Fcode%3D84923
18
posprint://print?v=1&d=…&noconfirm=1
19
19
```
20
20
21
21
| Part | Meaning |
@@ -24,35 +24,19 @@ posprint://print?v=1&d=…&noconfirm=1&referrer=website.com%2Fbonnen%2Fverify%3F
24
24
| `print` | Open the print-only dialog (same UX as `posprint --print`) |
25
25
| `v=1` | URL payload version |
26
26
| `d=` | Compressed `.pos` file (JSON with `version`, `metadata`, `body`) |
27
| `noconfirm=1` | Start printing immediately after referrer verification (+ domain trust) |
28
| `referrer=` | **Percent-encoded** verification URL on the issuer’s domain (see below) |
27
| `noconfirm=1` | Start printing as soon as a printer is ready (no Print click) |
29
28
30
29
**Template parameters are not in the URL.** With a normal link the user fills `${Name}` / `$[Name]` in the dialog. Prefer templates without unresolved parameters when using `noconfirm`.
31
30
32
31
**Images:** keep logos out of the URL. Use `@image https://…` (or `http://…`) in the template body; posprint downloads them when needed.
33
32
34
### Auto-print (`noconfirm`) and referrer verification
33
### Auto-print (`noconfirm`)
35
34
36
The OS protocol handler only receives the URL string — not the browser Referer. A site that wants silent print must prove control of its domain:
37
38
1. Embed `&noconfirm=1&referrer=<URL-encoded verification URL>`.
39
2. Example referrer value (before encoding): `website.com/bonnen/verify?code=84923`
40
(scheme optional → treated as `https://…`; or pass a full `https://…` URL).
41
3. posprint **GETs** that URL with **no redirects**.
42
4. **HTTP 200** → verification OK; trust host = hostname of the referrer URL (`website.com`).
43
5. **Any other status** (typically 4xx) → print refused.
44
6. Code format and how long it stays valid are **entirely up to the website**.
45
46
| First successful verify from that host | Later verified visits |
47
|----------------------------------------|------------------------|
48
| posprint shows **Trust this site?** | If trusted, prints without asking |
49
| **Trust and print** stores the hostname | Revoke under **Settings → Trusted sites** |
35
Add `&noconfirm=1` to print without waiting for the Print button. Consent to open posprint is handled by the **browser** (protocol launch prompt), not by a second trust dialog in the app.
50
36
51
37
After a successful print, posprint remembers that printer. On the next `noconfirm` (and in the interactive dialog), it selects that printer again **if it is still connected**; otherwise it keeps the usual first/default selection.
52
38
53
Without `referrer`, `noconfirm=1` is rejected. Without `noconfirm`, behaviour is unchanged (interactive print dialog).
54
55
Localhost / loopback verification URLs are allowed. Other private LAN addresses (e.g. `192.168.x.x`) are blocked.
39
Legacy `&referrer=…` in old URLs is ignored.
56
40
57
41
### Browser “Open posprint?” prompt
58
42
@@ -109,10 +93,9 @@ $url = posprint_url([
109
93
'metadata' => ['page_width_mm' => 53, 'chars_per_line' => 32],
110
94
'body' => "@barcode RASTER CODE128 \${data}\nHello\n@cut\n",
111
95
]);
112
// Auto-print: site must expose a verify URL that returns HTTP 200 for this code:
96
// Auto-print (browser protocol prompt is the consent gate):
113
97
$auto = posprint_url($pos, [
114
98
'noconfirm' => true,
115
'referrer' => 'https://shop.example.com/bonnen/verify?code=' . urlencode($code),
116
99
]);
117
100
// <a href="<?= htmlspecialchars($url) ?>">Print</a>
118
101
```
@@ -130,7 +113,6 @@ const url = posprintUrl({
130
113
131
114
const auto = posprintUrl(pos, {
132
115
noconfirm: true,
133
referrer: `https://shop.example.com/bonnen/verify?code=${encodeURIComponent(code)}`,
134
116
});
135
117
```
136
118
@@ -146,7 +128,6 @@ const auto = posprintUrl(pos, {
146
128
});
147
129
const auto = await posprintUrl(pos, {
148
130
noconfirm: true,
149
referrer: `https://${location.host}/bonnen/verify?code=${encodeURIComponent(code)}`,
150
131
});
151
132
location.href = auto;
152
133
</script>
@@ -15,7 +15,7 @@ posprint://print?v=1&d=<BASE64URL(raw_deflate(utf8(.pos JSON)))>15
Optional auto-print:15
Optional auto-print:16
16
17
```17
```18
posprint://print?v=1&d=…&noconfirm=1&referrer=website.com%2Fbonnen%2Fverify%3Fcode%3D8492318
posprint://print?v=1&d=…&noconfirm=119
```19
```20
20
21
| Part | Meaning |21
| Part | Meaning |@@ -24,35 +24,19 @@ posprint://print?v=1&d=…&noconfirm=1&referrer=website.com%2Fbonnen%2Fverify%3F24
| `print` | Open the print-only dialog (same UX as `posprint --print`) |24
| `print` | Open the print-only dialog (same UX as `posprint --print`) |25
| `v=1` | URL payload version |25
| `v=1` | URL payload version |26
| `d=` | Compressed `.pos` file (JSON with `version`, `metadata`, `body`) |26
| `d=` | Compressed `.pos` file (JSON with `version`, `metadata`, `body`) |27
| `noconfirm=1` | Start printing immediately after referrer verification (+ domain trust) |27
| `noconfirm=1` | Start printing as soon as a printer is ready (no Print click) |28
| `referrer=` | **Percent-encoded** verification URL on the issuer’s domain (see below) |29
28
30
**Template parameters are not in the URL.** With a normal link the user fills `${Name}` / `$[Name]` in the dialog. Prefer templates without unresolved parameters when using `noconfirm`.29
**Template parameters are not in the URL.** With a normal link the user fills `${Name}` / `$[Name]` in the dialog. Prefer templates without unresolved parameters when using `noconfirm`.31
30
32
**Images:** keep logos out of the URL. Use `@image https://…` (or `http://…`) in the template body; posprint downloads them when needed.31
**Images:** keep logos out of the URL. Use `@image https://…` (or `http://…`) in the template body; posprint downloads them when needed.33
32
34
### Auto-print (`noconfirm`) and referrer verification33
### Auto-print (`noconfirm`)35
34
36
The OS protocol handler only receives the URL string — not the browser Referer. A site that wants silent print must prove control of its domain:35
Add `&noconfirm=1` to print without waiting for the Print button. Consent to open posprint is handled by the **browser** (protocol launch prompt), not by a second trust dialog in the app.37
38
1. Embed `&noconfirm=1&referrer=<URL-encoded verification URL>`.39
2. Example referrer value (before encoding): `website.com/bonnen/verify?code=84923` 40
(scheme optional → treated as `https://…`; or pass a full `https://…` URL).41
3. posprint **GETs** that URL with **no redirects**.42
4. **HTTP 200** → verification OK; trust host = hostname of the referrer URL (`website.com`).43
5. **Any other status** (typically 4xx) → print refused.44
6. Code format and how long it stays valid are **entirely up to the website**.45
46
| First successful verify from that host | Later verified visits |47
|----------------------------------------|------------------------|48
| posprint shows **Trust this site?** | If trusted, prints without asking |49
| **Trust and print** stores the hostname | Revoke under **Settings → Trusted sites** |50
36
51
After a successful print, posprint remembers that printer. On the next `noconfirm` (and in the interactive dialog), it selects that printer again **if it is still connected**; otherwise it keeps the usual first/default selection.37
After a successful print, posprint remembers that printer. On the next `noconfirm` (and in the interactive dialog), it selects that printer again **if it is still connected**; otherwise it keeps the usual first/default selection.52
38
53
Without `referrer`, `noconfirm=1` is rejected. Without `noconfirm`, behaviour is unchanged (interactive print dialog).39
Legacy `&referrer=…` in old URLs is ignored.54
55
Localhost / loopback verification URLs are allowed. Other private LAN addresses (e.g. `192.168.x.x`) are blocked.56
40
57
### Browser “Open posprint?” prompt41
### Browser “Open posprint?” prompt58
42
@@ -109,10 +93,9 @@ $url = posprint_url([109
'metadata' => ['page_width_mm' => 53, 'chars_per_line' => 32],93
'metadata' => ['page_width_mm' => 53, 'chars_per_line' => 32],110
'body' => "@barcode RASTER CODE128 \${data}\nHello\n@cut\n",94
'body' => "@barcode RASTER CODE128 \${data}\nHello\n@cut\n",111
]);95
]);112
// Auto-print: site must expose a verify URL that returns HTTP 200 for this code:96
// Auto-print (browser protocol prompt is the consent gate):113
$auto = posprint_url($pos, [97
$auto = posprint_url($pos, [114
'noconfirm' => true,98
'noconfirm' => true,115
'referrer' => 'https://shop.example.com/bonnen/verify?code=' . urlencode($code),116
]);99
]);117
// <a href="<?= htmlspecialchars($url) ?>">Print</a>100
// <a href="<?= htmlspecialchars($url) ?>">Print</a>118
```101
```@@ -130,7 +113,6 @@ const url = posprintUrl({130
113
131
const auto = posprintUrl(pos, {114
const auto = posprintUrl(pos, {132
noconfirm: true,115
noconfirm: true,133
referrer: `https://shop.example.com/bonnen/verify?code=${encodeURIComponent(code)}`,134
});116
});135
```117
```136
118
@@ -146,7 +128,6 @@ const auto = posprintUrl(pos, {146
});128
});147
const auto = await posprintUrl(pos, {129
const auto = await posprintUrl(pos, {148
noconfirm: true,130
noconfirm: true,149
referrer: `https://${location.host}/bonnen/verify?code=${encodeURIComponent(code)}`,150
});131
});151
location.href = auto;132
location.href = auto;152
</script>133
</script>@@ -147,7 +147,7 @@ Status polling (paper out, cover open) is **not** implemented.
147
147
148
148
## Images and rasters
149
149
150
1. If the path is `http://` or `https://`, download (timeout + size limit, process cache); otherwise resolve relative to the `.pos` file (or absolute).
150
1. If the path is `http://` or `https://`, download (timeout + size limit, process cache; TLS cert verification disabled for remote logos); otherwise resolve relative to the `.pos` file (or absolute).
151
151
2. Decode with `image`, convert to luma, scale to printable width (`chars_per_line × 12` dots).
152
152
3. Threshold to 1-bit; emit `GS v 0` (`1D 76 30 00` + width/height LE + bitmap).
153
153
4. Append **LF** after the raster so following content (including blank-line feeds) advances correctly.
@@ -147,7 +147,7 @@ Status polling (paper out, cover open) is **not** implemented.147
147
148
## Images and rasters148
## Images and rasters149
149
150
1. If the path is `http://` or `https://`, download (timeout + size limit, process cache); otherwise resolve relative to the `.pos` file (or absolute).150
1. If the path is `http://` or `https://`, download (timeout + size limit, process cache; TLS cert verification disabled for remote logos); otherwise resolve relative to the `.pos` file (or absolute).151
2. Decode with `image`, convert to luma, scale to printable width (`chars_per_line × 12` dots).151
2. Decode with `image`, convert to luma, scale to printable width (`chars_per_line × 12` dots).152
3. Threshold to 1-bit; emit `GS v 0` (`1D 76 30 00` + width/height LE + bitmap).152
3. Threshold to 1-bit; emit `GS v 0` (`1D 76 30 00` + width/height LE + bitmap).153
4. Append **LF** after the raster so following content (including blank-line feeds) advances correctly.153
4. Append **LF** after the raster so following content (including blank-line feeds) advances correctly.@@ -31,11 +31,8 @@ Build the document in JavaScript and open the link:
31
31
},
32
32
body: '@barcode RASTER CODE128 ${data}\nHello\n@cut\n',
33
33
});
34
// Silent print after verify URL returns 200 (and domain trust):
35
// const url = await posprintUrl(pos, {
36
// noconfirm: true,
37
// referrer: `https://${location.host}/api/posprint/verify?code=${code}`,
38
// });
34
// Auto-print (browser protocol prompt is the consent gate):
35
// const url = await posprintUrl(pos, { noconfirm: true });
39
36
window.location.href = url;
40
37
});
41
38
</script>
@@ -31,11 +31,8 @@ Build the document in JavaScript and open the link:31
},31
},32
body: '@barcode RASTER CODE128 ${data}\nHello\n@cut\n',32
body: '@barcode RASTER CODE128 ${data}\nHello\n@cut\n',33
});33
});34
// Silent print after verify URL returns 200 (and domain trust):34
// Auto-print (browser protocol prompt is the consent gate):35
// const url = await posprintUrl(pos, {35
// const url = await posprintUrl(pos, { noconfirm: true });36
// noconfirm: true,37
// referrer: `https://${location.host}/api/posprint/verify?code=${code}`,38
// });39
window.location.href = url;36
window.location.href = url;40
});37
});41
</script>38
</script>@@ -5,7 +5,7 @@
5
5
* Requires CompressionStream('deflate-raw') (modern browsers).
6
6
*
7
7
* @param {object|string} pos
8
* @param {{ noconfirm?: boolean, referrer?: string }} [options]
8
* @param {{ noconfirm?: boolean }} [options]
9
9
* @returns {Promise<string>}
10
10
*/
11
11
export async function posprintUrl(pos, options = {}) {
@@ -21,12 +21,6 @@ export async function posprintUrl(pos, options = {}) {
21
21
if (options.noconfirm) {
22
22
url += '&noconfirm=1';
23
23
}
24
if (options.referrer) {
25
const ref = String(options.referrer).trim();
26
if (ref) {
27
url += `&referrer=${encodeURIComponent(ref)}`;
28
}
29
}
30
24
return url;
31
25
}
32
26
@@ -5,7 +5,7 @@5
* Requires CompressionStream('deflate-raw') (modern browsers).
5
* Requires CompressionStream('deflate-raw') (modern browsers).
6
*
6
*
7
* @param {object|string} pos
7
* @param {object|string} pos
8
* @param {{ noconfirm?: boolean, referrer?: string }} [options]
8
* @param {{ noconfirm?: boolean }} [options]
9
* @returns {Promise<string>}
9
* @returns {Promise<string>}
10
*/
10
*/
11
export async function posprintUrl(pos, options = {}) {
11
export async function posprintUrl(pos, options = {}) {
@@ -21,12 +21,6 @@ export async function posprintUrl(pos, options = {}) {21
if (options.noconfirm) {
21
if (options.noconfirm) {
22
url += '&noconfirm=1';
22
url += '&noconfirm=1';
23
}
23
}
24
if (options.referrer) {
25
const ref = String(options.referrer).trim();
26
if (ref) {
27
url += `&referrer=${encodeURIComponent(ref)}`;
28
}
29
}
30
return url;
24
return url;
31
}
25
}
32
26
@@ -8,7 +8,7 @@ const zlib = require('zlib');
8
8
* Encoding: UTF-8 JSON → raw deflate → base64url (no padding).
9
9
*
10
10
* @param {object|string} pos
11
* @param {{ noconfirm?: boolean, referrer?: string }} [options]
11
* @param {{ noconfirm?: boolean }} [options]
12
12
* @returns {string}
13
13
*/
14
14
function posprintUrl(pos, options = {}) {
@@ -19,12 +19,6 @@ function posprintUrl(pos, options = {}) {
19
19
if (options.noconfirm) {
20
20
url += '&noconfirm=1';
21
21
}
22
if (options.referrer) {
23
const ref = String(options.referrer).trim();
24
if (ref) {
25
url += `&referrer=${encodeURIComponent(ref)}`;
26
}
27
}
28
22
return url;
29
23
}
30
24
@@ -8,7 +8,7 @@ const zlib = require('zlib');8
* Encoding: UTF-8 JSON → raw deflate → base64url (no padding).
8
* Encoding: UTF-8 JSON → raw deflate → base64url (no padding).
9
*
9
*
10
* @param {object|string} pos
10
* @param {object|string} pos
11
* @param {{ noconfirm?: boolean, referrer?: string }} [options]
11
* @param {{ noconfirm?: boolean }} [options]
12
* @returns {string}
12
* @returns {string}
13
*/
13
*/
14
function posprintUrl(pos, options = {}) {
14
function posprintUrl(pos, options = {}) {
@@ -19,12 +19,6 @@ function posprintUrl(pos, options = {}) {19
if (options.noconfirm) {
19
if (options.noconfirm) {
20
url += '&noconfirm=1';
20
url += '&noconfirm=1';
21
}
21
}
22
if (options.referrer) {
23
const ref = String(options.referrer).trim();
24
if (ref) {
25
url += `&referrer=${encodeURIComponent(ref)}`;
26
}
27
}
28
return url;
22
return url;
29
}
23
}
30
24
@@ -5,7 +5,7 @@
5
5
* Encoding: UTF-8 JSON → raw deflate (gzdeflate) → base64url (no padding).
6
6
*
7
7
* @param array|string $pos PosFile as associative array or JSON string
8
* @param array{noconfirm?: bool, referrer?: string} $options Optional URL flags
8
* @param array{noconfirm?: bool} $options Optional URL flags
9
9
* @return string posprint://print?v=1&d=…
10
10
* @throws InvalidArgumentException
11
11
*/
@@ -33,12 +33,6 @@ function posprint_url($pos, array $options = []): string
33
33
if (!empty($options['noconfirm'])) {
34
34
$url .= '&noconfirm=1';
35
35
}
36
if (!empty($options['referrer'])) {
37
$ref = trim((string) $options['referrer']);
38
if ($ref !== '') {
39
$url .= '&referrer=' . rawurlencode($ref);
40
}
41
}
42
36
43
37
return $url;
44
38
}
@@ -5,7 +5,7 @@5
* Encoding: UTF-8 JSON → raw deflate (gzdeflate) → base64url (no padding).
5
* Encoding: UTF-8 JSON → raw deflate (gzdeflate) → base64url (no padding).
6
*
6
*
7
* @param array|string $pos PosFile as associative array or JSON string
7
* @param array|string $pos PosFile as associative array or JSON string
8
* @param array{noconfirm?: bool, referrer?: string} $options Optional URL flags
8
* @param array{noconfirm?: bool} $options Optional URL flags
9
* @return string posprint://print?v=1&d=…
9
* @return string posprint://print?v=1&d=…
10
* @throws InvalidArgumentException
10
* @throws InvalidArgumentException
11
*/
11
*/
@@ -33,12 +33,6 @@ function posprint_url($pos, array $options = []): string33
if (!empty($options['noconfirm'])) {
33
if (!empty($options['noconfirm'])) {
34
$url .= '&noconfirm=1';
34
$url .= '&noconfirm=1';
35
}
35
}
36
if (!empty($options['referrer'])) {
37
$ref = trim((string) $options['referrer']);
38
if ($ref !== '') {
39
$url .= '&referrer=' . rawurlencode($ref);
40
}
41
}
42
36
43
return $url;
37
return $url;
44
}
38
}
@@ -1,6 +1,6 @@
1
1
# Maintainer: posprint contributors
2
2
pkgname=posprint
3
pkgver=0.5.5
3
pkgver=0.5.6
4
4
pkgrel=1
5
5
pkgdesc="Designer for POS-print documents with live preview and USB ESC/POS printing"
6
6
arch=('x86_64')
@@ -1,6 +1,6 @@1
# Maintainer: posprint contributors1
# Maintainer: posprint contributors2
pkgname=posprint2
pkgname=posprint3
pkgver=0.5.53
pkgver=0.5.64
pkgrel=14
pkgrel=15
pkgdesc="Designer for POS-print documents with live preview and USB ESC/POS printing"5
pkgdesc="Designer for POS-print documents with live preview and USB ESC/POS printing"6
arch=('x86_64')6
arch=('x86_64')@@ -1,6 +1,6 @@
1
1
pkgbase = posprint
2
2
pkgdesc = Designer for POS-print documents with live preview and USB ESC/POS printing
3
pkgver = 0.5.4
3
pkgver = 0.5.6
4
4
pkgrel = 1
5
5
url = https://gitlab.com/Timfa/posprint
6
6
arch = x86_64
@@ -21,7 +21,7 @@ pkgbase = posprint
21
21
depends = freetype2
22
22
depends = libglvnd
23
23
options = !lto
24
source = https://gitlab.com/Timfa/posprint/-/archive/0.5.4/posprint-0.5.4.tar.gz
24
source = https://gitlab.com/Timfa/posprint/-/archive/0.5.6/posprint-0.5.6.tar.gz
25
25
sha256sums = SKIP
26
26
27
27
pkgname = posprint
@@ -1,6 +1,6 @@1
pkgbase = posprint1
pkgbase = posprint2
pkgdesc = Designer for POS-print documents with live preview and USB ESC/POS printing2
pkgdesc = Designer for POS-print documents with live preview and USB ESC/POS printing3
pkgver = 0.5.43
pkgver = 0.5.64
pkgrel = 14
pkgrel = 15
url = https://gitlab.com/Timfa/posprint5
url = https://gitlab.com/Timfa/posprint6
arch = x86_646
arch = x86_64@@ -21,7 +21,7 @@ pkgbase = posprint21
depends = freetype221
depends = freetype222
depends = libglvnd22
depends = libglvnd23
options = !lto23
options = !lto24
source = https://gitlab.com/Timfa/posprint/-/archive/0.5.4/posprint-0.5.4.tar.gz24
source = https://gitlab.com/Timfa/posprint/-/archive/0.5.6/posprint-0.5.6.tar.gz25
sha256sums = SKIP25
sha256sums = SKIP26
26
27
pkgname = posprint27
pkgname = posprint@@ -1,6 +1,6 @@
1
1
# Maintainer: posprint contributors
2
2
pkgname=posprint
3
pkgver=0.5.4
3
pkgver=0.5.6
4
4
pkgrel=1
5
5
pkgdesc="Designer for POS-print documents with live preview and USB ESC/POS printing"
6
6
arch=('x86_64')
@@ -1,6 +1,6 @@1
# Maintainer: posprint contributors1
# Maintainer: posprint contributors2
pkgname=posprint2
pkgname=posprint3
pkgver=0.5.43
pkgver=0.5.64
pkgrel=14
pkgrel=15
pkgdesc="Designer for POS-print documents with live preview and USB ESC/POS printing"5
pkgdesc="Designer for POS-print documents with live preview and USB ESC/POS printing"6
arch=('x86_64')6
arch=('x86_64')@@ -1,35 +1,15 @@
1
# Local noconfirm + referrer test
1
# Local noconfirm test
2
2
3
Docs: [docs/POSPRINT-URL.md](../../docs/POSPRINT-URL.md).
3
`noconfirm=1` auto-prints once printers are discovered (no referrer verify / trust dialog).
4
The browser’s “Open posprint?” prompt is the user consent gate.
4
5
5
Loopback (`127.0.0.1` / `localhost`) is allowed for referrer verification.
6
7
## 1. Start the verify server
8
9
```powershell
10
python scripts/test-noconfirm/server.py
11
```
12
13
- `GET http://127.0.0.1:8765/verify?code=84923` → **200**
14
- `GET http://127.0.0.1:8765/verify?code=wrong` → **403**
15
16
## 2. Build and open the test URL
6
## Quick check
17
7
18
8
```powershell
19
cargo build
20
9
$base = cargo run --quiet -- link examples/noconfirm-demo.pos
21
$ref = [uri]::EscapeDataString("http://127.0.0.1:8765/verify?code=84923")
22
$url = "$base&noconfirm=1&referrer=$ref"
23
$url
24
# Prefer the built GUI binary (no console flash):
25
Start-Process ".\target\debug\posprint.exe" $url
10
$url = "$base&noconfirm=1"
11
Write-Output $url
12
Start-Process ".\target\release\posprint.exe" $url
26
13
```
27
14
28
First run: trust dialog for `127.0.0.1`. After **Trust and print**, the next open should print without asking (while the server still returns 200).
29
30
Bad code (should fail verification):
31
32
```powershell
33
$refBad = [uri]::EscapeDataString("http://127.0.0.1:8765/verify?code=nope")
34
Start-Process ".\target\debug\posprint.exe" "$base&noconfirm=1&referrer=$refBad"
35
```
15
With a connected printer that was used successfully before, print should start without confirmation inside posprint.
@@ -1,35 +1,15 @@1
# Local noconfirm + referrer test1
# Local noconfirm test2
2
3
Docs: [docs/POSPRINT-URL.md](../../docs/POSPRINT-URL.md).3
`noconfirm=1` auto-prints once printers are discovered (no referrer verify / trust dialog).4
The browser’s “Open posprint?” prompt is the user consent gate.4
5
5
Loopback (`127.0.0.1` / `localhost`) is allowed for referrer verification.6
## Quick check6
7
## 1. Start the verify server8
9
```powershell10
python scripts/test-noconfirm/server.py11
```12
13
- `GET http://127.0.0.1:8765/verify?code=84923` → **200**14
- `GET http://127.0.0.1:8765/verify?code=wrong` → **403**15
16
## 2. Build and open the test URL17
7
18
```powershell8
```powershell19
cargo build20
$base = cargo run --quiet -- link examples/noconfirm-demo.pos9
$base = cargo run --quiet -- link examples/noconfirm-demo.pos21
$ref = [uri]::EscapeDataString("http://127.0.0.1:8765/verify?code=84923")10
$url = "$base&noconfirm=1"22
$url = "$base&noconfirm=1&referrer=$ref"11
Write-Output $url23
$url12
Start-Process ".\target\release\posprint.exe" $url24
# Prefer the built GUI binary (no console flash):25
Start-Process ".\target\debug\posprint.exe" $url26
```13
```27
14
28
First run: trust dialog for `127.0.0.1`. After **Trust and print**, the next open should print without asking (while the server still returns 200).15
With a connected printer that was used successfully before, print should start without confirmation inside posprint.29
30
Bad code (should fail verification):31
32
```powershell33
$refBad = [uri]::EscapeDataString("http://127.0.0.1:8765/verify?code=nope")34
Start-Process ".\target\debug\posprint.exe" "$base&noconfirm=1&referrer=$refBad"35
```@@ -1,56 +0,0 @@
1
#!/usr/bin/env python3
2
"""Minimal verify server for local noconfirm testing.
3
4
GET /verify?code=84923 -> 200
5
GET /verify?code=other -> 403
6
GET anything else -> 404
7
8
Run:
9
python scripts/test-noconfirm/server.py
10
"""
11
12
from __future__ import annotations
13
14
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
15
from urllib.parse import parse_qs, urlparse
16
17
HOST = "127.0.0.1"
18
PORT = 8765
19
VALID_CODE = "84923"
20
21
22
class Handler(BaseHTTPRequestHandler):
23
def log_message(self, fmt: str, *args) -> None:
24
print(f"[verify] {self.address_string()} {fmt % args}")
25
26
def do_GET(self) -> None:
27
parsed = urlparse(self.path)
28
if parsed.path.rstrip("/") != "/verify":
29
self._reply(404, "not found")
30
return
31
code = parse_qs(parsed.query).get("code", [None])[0]
32
if code == VALID_CODE:
33
self._reply(200, "ok")
34
else:
35
self._reply(403, "invalid code")
36
37
def _reply(self, status: int, body: str) -> None:
38
data = body.encode("utf-8")
39
self.send_response(status)
40
self.send_header("Content-Type", "text/plain; charset=utf-8")
41
self.send_header("Content-Length", str(len(data)))
42
self.end_headers()
43
self.wfile.write(data)
44
45
46
def main() -> None:
47
server = ThreadingHTTPServer((HOST, PORT), Handler)
48
print(f"Listening on http://{HOST}:{PORT}")
49
print(f"Valid: http://{HOST}:{PORT}/verify?code={VALID_CODE} -> 200")
50
print(f"Invalid: http://{HOST}:{PORT}/verify?code=wrong -> 403")
51
print("Ctrl+C to stop")
52
server.serve_forever()
53
54
55
if __name__ == "__main__":
56
main()
@@ -1,56 +0,0 @@1
#!/usr/bin/env python3
2
"""Minimal verify server for local noconfirm testing.
3
4
GET /verify?code=84923 -> 200
5
GET /verify?code=other -> 403
6
GET anything else -> 404
7
8
Run:
9
python scripts/test-noconfirm/server.py
10
"""
11
12
from __future__ import annotations
13
14
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
15
from urllib.parse import parse_qs, urlparse
16
17
HOST = "127.0.0.1"
18
PORT = 8765
19
VALID_CODE = "84923"
20
21
22
class Handler(BaseHTTPRequestHandler):
23
def log_message(self, fmt: str, *args) -> None:
24
print(f"[verify] {self.address_string()} {fmt % args}")
25
26
def do_GET(self) -> None:
27
parsed = urlparse(self.path)
28
if parsed.path.rstrip("/") != "/verify":
29
self._reply(404, "not found")
30
return
31
code = parse_qs(parsed.query).get("code", [None])[0]
32
if code == VALID_CODE:
33
self._reply(200, "ok")
34
else:
35
self._reply(403, "invalid code")
36
37
def _reply(self, status: int, body: str) -> None:
38
data = body.encode("utf-8")
39
self.send_response(status)
40
self.send_header("Content-Type", "text/plain; charset=utf-8")
41
self.send_header("Content-Length", str(len(data)))
42
self.end_headers()
43
self.wfile.write(data)
44
45
46
def main() -> None:
47
server = ThreadingHTTPServer((HOST, PORT), Handler)
48
print(f"Listening on http://{HOST}:{PORT}")
49
print(f"Valid: http://{HOST}:{PORT}/verify?code={VALID_CODE} -> 200")
50
print(f"Invalid: http://{HOST}:{PORT}/verify?code=wrong -> 403")
51
print("Ctrl+C to stop")
52
server.serve_forever()
53
54
55
if __name__ == "__main__":
56
main()
@@ -132,44 +132,6 @@ impl PosPrintApp {
132
132
});
133
133
ui.label("Applies when you choose New. The current document width is unchanged.");
134
134
135
ui.add_space(16.0);
136
ui.heading("Trusted sites (noconfirm)");
137
ui.label(
138
"Sites listed here may use posprint://…&noconfirm=1&referrer=… after their verify URL returns HTTP 200.",
139
);
140
141
if self.config.trusted_origins.is_empty() {
142
ui.label("No trusted sites yet.");
143
} else {
144
let origins = self.config.trusted_origins.clone();
145
for origin in origins {
146
ui.horizontal(|ui| {
147
ui.label(&origin);
148
if ui.button("Revoke").clicked() {
149
self.config.revoke_origin(&origin);
150
match self.config.save() {
151
Ok(()) => {
152
self.settings_status =
153
Some(format!("Revoked trust for {origin}"))
154
}
155
Err(e) => {
156
self.settings_status = Some(format!("Save failed: {e}"))
157
}
158
}
159
}
160
});
161
}
162
if ui.button("Revoke all").clicked() {
163
self.config.trusted_origins.clear();
164
match self.config.save() {
165
Ok(()) => {
166
self.settings_status = Some("Cleared all trusted sites.".into())
167
}
168
Err(e) => self.settings_status = Some(format!("Save failed: {e}")),
169
}
170
}
171
}
172
173
135
ui.add_space(16.0);
174
136
if ui.button("Save settings").clicked() {
175
137
match self.config.save() {
@@ -132,44 +132,6 @@ impl PosPrintApp {132
});
132
});
133
ui.label("Applies when you choose New. The current document width is unchanged.");
133
ui.label("Applies when you choose New. The current document width is unchanged.");
134
134
135
ui.add_space(16.0);
136
ui.heading("Trusted sites (noconfirm)");
137
ui.label(
138
"Sites listed here may use posprint://…&noconfirm=1&referrer=… after their verify URL returns HTTP 200.",
139
);
140
141
if self.config.trusted_origins.is_empty() {
142
ui.label("No trusted sites yet.");
143
} else {
144
let origins = self.config.trusted_origins.clone();
145
for origin in origins {
146
ui.horizontal(|ui| {
147
ui.label(&origin);
148
if ui.button("Revoke").clicked() {
149
self.config.revoke_origin(&origin);
150
match self.config.save() {
151
Ok(()) => {
152
self.settings_status =
153
Some(format!("Revoked trust for {origin}"))
154
}
155
Err(e) => {
156
self.settings_status = Some(format!("Save failed: {e}"))
157
}
158
}
159
}
160
});
161
}
162
if ui.button("Revoke all").clicked() {
163
self.config.trusted_origins.clear();
164
match self.config.save() {
165
Ok(()) => {
166
self.settings_status = Some("Cleared all trusted sites.".into())
167
}
168
Err(e) => self.settings_status = Some(format!("Save failed: {e}")),
169
}
170
}
171
}
172
173
ui.add_space(16.0);
135
ui.add_space(16.0);
174
if ui.button("Save settings").clicked() {
136
if ui.button("Save settings").clicked() {
175
match self.config.save() {
137
match self.config.save() {
@@ -1,4 +1,4 @@
1
//! Persisted app preferences (trusted URL origins, default page width).
1
//! Persisted app preferences (default page width, last printer).
2
2
3
3
use std::fs;
4
4
use std::path::PathBuf;
@@ -14,12 +14,12 @@ pub struct AppConfig {
14
14
/// Default paper width for **New** documents (mm).
15
15
#[serde(default = "default_page_width_mm")]
16
16
pub default_page_width_mm: f32,
17
/// Hostnames allowed to use `noconfirm=1` without asking again.
18
#[serde(default)]
19
pub trusted_origins: Vec<String>,
20
17
/// Last printer that printed successfully (`serial:…`, `winspool:…`, `usb:vid:pid`, or `manual:…`).
21
18
#[serde(default)]
22
19
pub last_printer_key: Option<String>,
20
/// Ignored legacy field from older configs (trusted noconfirm hosts).
21
#[serde(default, skip_serializing)]
22
trusted_origins: Vec<String>,
23
23
}
24
24
25
25
fn default_config_version() -> u32 {
@@ -35,8 +35,8 @@ impl Default for AppConfig {
35
35
Self {
36
36
version: CONFIG_VERSION,
37
37
default_page_width_mm: default_page_width_mm(),
38
trusted_origins: Vec::new(),
39
38
last_printer_key: None,
39
trusted_origins: Vec::new(),
40
40
}
41
41
}
42
42
}
@@ -73,31 +73,6 @@ impl AppConfig {
73
73
fs::write(path, json).map_err(|e| e.to_string())
74
74
}
75
75
76
pub fn is_trusted(&self, origin: &str) -> bool {
77
let Some(host) = normalize_origin(origin) else {
78
return false;
79
};
80
self.trusted_origins.iter().any(|o| o == &host)
81
}
82
83
pub fn trust_origin(&mut self, origin: &str) -> bool {
84
let Some(host) = normalize_origin(origin) else {
85
return false;
86
};
87
if !self.trusted_origins.iter().any(|o| o == &host) {
88
self.trusted_origins.push(host);
89
self.trusted_origins.sort();
90
}
91
true
92
}
93
94
pub fn revoke_origin(&mut self, origin: &str) {
95
let Some(host) = normalize_origin(origin) else {
96
return;
97
};
98
self.trusted_origins.retain(|o| o != &host);
99
}
100
101
76
pub fn remember_printer(&mut self, key: impl Into<String>) {
102
77
let key = key.into();
103
78
if key.is_empty() {
@@ -108,19 +83,12 @@ impl AppConfig {
108
83
109
84
fn normalize(&mut self) {
110
85
self.version = CONFIG_VERSION;
86
self.trusted_origins.clear();
111
87
if !self.default_page_width_mm.is_finite() || self.default_page_width_mm < 40.0 {
112
88
self.default_page_width_mm = 40.0;
113
89
} else if self.default_page_width_mm > 120.0 {
114
90
self.default_page_width_mm = 120.0;
115
91
}
116
let mut hosts: Vec<String> = self
117
.trusted_origins
118
.iter()
119
.filter_map(|o| normalize_origin(o))
120
.collect();
121
hosts.sort();
122
hosts.dedup();
123
self.trusted_origins = hosts;
124
92
if let Some(key) = &self.last_printer_key {
125
93
let trimmed = key.trim();
126
94
if trimmed.is_empty() {
@@ -154,73 +122,37 @@ pub fn config_path() -> PathBuf {
154
122
}
155
123
}
156
124
157
/// Normalize a caller-supplied origin to a lowercase hostname.
158
/// Accepts `example.com`, `https://example.com/path`, `http://localhost:3000`.
159
pub fn normalize_origin(raw: &str) -> Option<String> {
160
let s = raw.trim();
161
if s.is_empty() {
162
return None;
163
}
164
let without_scheme = s
165
.strip_prefix("https://")
166
.or_else(|| s.strip_prefix("http://"))
167
.or_else(|| s.strip_prefix("HTTPS://"))
168
.or_else(|| s.strip_prefix("HTTP://"))
169
.unwrap_or(s);
170
let host_port = without_scheme.split('/').next()?.trim();
171
if host_port.is_empty() {
172
return None;
173
}
174
// Drop port for trust matching (example.com:443 → example.com).
175
let host = host_port.split(':').next()?.trim();
176
if host.is_empty() {
177
return None;
178
}
179
Some(host.to_ascii_lowercase())
180
}
181
182
125
#[cfg(test)]
183
126
mod tests {
184
127
use super::*;
185
128
186
#[test]
187
fn normalize_strips_scheme_path_and_port() {
188
assert_eq!(
189
normalize_origin("https://Shop.Example.com/checkout").as_deref(),
190
Some("shop.example.com")
191
);
192
assert_eq!(
193
normalize_origin("http://localhost:5173/").as_deref(),
194
Some("localhost")
195
);
196
assert_eq!(normalize_origin("example.com").as_deref(), Some("example.com"));
197
assert_eq!(normalize_origin(" ").as_deref(), None);
198
}
199
200
#[test]
201
fn trust_and_revoke_roundtrip() {
202
let mut cfg = AppConfig::default();
203
assert!(!cfg.is_trusted("https://a.example"));
204
assert!(cfg.trust_origin("https://a.example/x"));
205
assert!(cfg.is_trusted("a.example"));
206
assert!(cfg.is_trusted("HTTPS://A.Example"));
207
cfg.revoke_origin("a.example");
208
assert!(!cfg.is_trusted("a.example"));
209
}
210
211
129
#[test]
212
130
fn save_load_roundtrip_in_temp_dir() {
213
131
let dir = tempfile::tempdir().unwrap();
214
132
let path = dir.path().join("posprint").join("config.json");
215
133
let mut cfg = AppConfig::default();
216
134
cfg.default_page_width_mm = 58.0;
217
cfg.trust_origin("pos.example");
218
135
cfg.remember_printer("winspool:POS-58");
219
136
cfg.save_to_path(&path).unwrap();
220
137
221
138
let loaded = AppConfig::load_from_path(&path);
222
139
assert_eq!(loaded.default_page_width_mm, 58.0);
223
assert!(loaded.is_trusted("pos.example"));
224
140
assert_eq!(loaded.last_printer_key.as_deref(), Some("winspool:POS-58"));
225
141
}
142
143
#[test]
144
fn loads_legacy_trusted_origins_without_keeping_them() {
145
let dir = tempfile::tempdir().unwrap();
146
let path = dir.path().join("config.json");
147
fs::write(
148
&path,
149
r#"{"version":1,"default_page_width_mm":80.0,"trusted_origins":["shop.example"],"last_printer_key":null}"#,
150
)
151
.unwrap();
152
let loaded = AppConfig::load_from_path(&path);
153
assert!(loaded.trusted_origins.is_empty());
154
loaded.save_to_path(&path).unwrap();
155
let text = fs::read_to_string(&path).unwrap();
156
assert!(!text.contains("trusted_origins"));
157
}
226
158
}
@@ -1,4 +1,4 @@1
//! Persisted app preferences (trusted URL origins, default page width).
1
//! Persisted app preferences (default page width, last printer).
2
2
3
use std::fs;
3
use std::fs;
4
use std::path::PathBuf;
4
use std::path::PathBuf;
@@ -14,12 +14,12 @@ pub struct AppConfig {14
/// Default paper width for **New** documents (mm).
14
/// Default paper width for **New** documents (mm).
15
#[serde(default = "default_page_width_mm")]
15
#[serde(default = "default_page_width_mm")]
16
pub default_page_width_mm: f32,
16
pub default_page_width_mm: f32,
17
/// Hostnames allowed to use `noconfirm=1` without asking again.
18
#[serde(default)]
19
pub trusted_origins: Vec<String>,
20
/// Last printer that printed successfully (`serial:…`, `winspool:…`, `usb:vid:pid`, or `manual:…`).
17
/// Last printer that printed successfully (`serial:…`, `winspool:…`, `usb:vid:pid`, or `manual:…`).
21
#[serde(default)]
18
#[serde(default)]
22
pub last_printer_key: Option<String>,
19
pub last_printer_key: Option<String>,
20
/// Ignored legacy field from older configs (trusted noconfirm hosts).
21
#[serde(default, skip_serializing)]
22
trusted_origins: Vec<String>,
23
}
23
}
24
24
25
fn default_config_version() -> u32 {
25
fn default_config_version() -> u32 {
@@ -35,8 +35,8 @@ impl Default for AppConfig {35
Self {
35
Self {
36
version: CONFIG_VERSION,
36
version: CONFIG_VERSION,
37
default_page_width_mm: default_page_width_mm(),
37
default_page_width_mm: default_page_width_mm(),
38
trusted_origins: Vec::new(),
39
last_printer_key: None,
38
last_printer_key: None,
39
trusted_origins: Vec::new(),
40
}
40
}
41
}
41
}
42
}
42
}
@@ -73,31 +73,6 @@ impl AppConfig {73
fs::write(path, json).map_err(|e| e.to_string())
73
fs::write(path, json).map_err(|e| e.to_string())
74
}
74
}
75
75
76
pub fn is_trusted(&self, origin: &str) -> bool {
77
let Some(host) = normalize_origin(origin) else {
78
return false;
79
};
80
self.trusted_origins.iter().any(|o| o == &host)
81
}
82
83
pub fn trust_origin(&mut self, origin: &str) -> bool {
84
let Some(host) = normalize_origin(origin) else {
85
return false;
86
};
87
if !self.trusted_origins.iter().any(|o| o == &host) {
88
self.trusted_origins.push(host);
89
self.trusted_origins.sort();
90
}
91
true
92
}
93
94
pub fn revoke_origin(&mut self, origin: &str) {
95
let Some(host) = normalize_origin(origin) else {
96
return;
97
};
98
self.trusted_origins.retain(|o| o != &host);
99
}
100
101
pub fn remember_printer(&mut self, key: impl Into<String>) {
76
pub fn remember_printer(&mut self, key: impl Into<String>) {
102
let key = key.into();
77
let key = key.into();
103
if key.is_empty() {
78
if key.is_empty() {
@@ -108,19 +83,12 @@ impl AppConfig {108
83
109
fn normalize(&mut self) {
84
fn normalize(&mut self) {
110
self.version = CONFIG_VERSION;
85
self.version = CONFIG_VERSION;
86
self.trusted_origins.clear();
111
if !self.default_page_width_mm.is_finite() || self.default_page_width_mm < 40.0 {
87
if !self.default_page_width_mm.is_finite() || self.default_page_width_mm < 40.0 {
112
self.default_page_width_mm = 40.0;
88
self.default_page_width_mm = 40.0;
113
} else if self.default_page_width_mm > 120.0 {
89
} else if self.default_page_width_mm > 120.0 {
114
self.default_page_width_mm = 120.0;
90
self.default_page_width_mm = 120.0;
115
}
91
}
116
let mut hosts: Vec<String> = self
117
.trusted_origins
118
.iter()
119
.filter_map(|o| normalize_origin(o))
120
.collect();
121
hosts.sort();
122
hosts.dedup();
123
self.trusted_origins = hosts;
124
if let Some(key) = &self.last_printer_key {
92
if let Some(key) = &self.last_printer_key {
125
let trimmed = key.trim();
93
let trimmed = key.trim();
126
if trimmed.is_empty() {
94
if trimmed.is_empty() {
@@ -154,73 +122,37 @@ pub fn config_path() -> PathBuf {154
}
122
}
155
}
123
}
156
124
157
/// Normalize a caller-supplied origin to a lowercase hostname.
158
/// Accepts `example.com`, `https://example.com/path`, `http://localhost:3000`.
159
pub fn normalize_origin(raw: &str) -> Option<String> {
160
let s = raw.trim();
161
if s.is_empty() {
162
return None;
163
}
164
let without_scheme = s
165
.strip_prefix("https://")
166
.or_else(|| s.strip_prefix("http://"))
167
.or_else(|| s.strip_prefix("HTTPS://"))
168
.or_else(|| s.strip_prefix("HTTP://"))
169
.unwrap_or(s);
170
let host_port = without_scheme.split('/').next()?.trim();
171
if host_port.is_empty() {
172
return None;
173
}
174
// Drop port for trust matching (example.com:443 → example.com).
175
let host = host_port.split(':').next()?.trim();
176
if host.is_empty() {
177
return None;
178
}
179
Some(host.to_ascii_lowercase())
180
}
181
182
#[cfg(test)]
125
#[cfg(test)]
183
mod tests {
126
mod tests {
184
use super::*;
127
use super::*;
185
128
186
#[test]
187
fn normalize_strips_scheme_path_and_port() {
188
assert_eq!(
189
normalize_origin("https://Shop.Example.com/checkout").as_deref(),
190
Some("shop.example.com")
191
);
192
assert_eq!(
193
normalize_origin("http://localhost:5173/").as_deref(),
194
Some("localhost")
195
);
196
assert_eq!(normalize_origin("example.com").as_deref(), Some("example.com"));
197
assert_eq!(normalize_origin(" ").as_deref(), None);
198
}
199
200
#[test]
201
fn trust_and_revoke_roundtrip() {
202
let mut cfg = AppConfig::default();
203
assert!(!cfg.is_trusted("https://a.example"));
204
assert!(cfg.trust_origin("https://a.example/x"));
205
assert!(cfg.is_trusted("a.example"));
206
assert!(cfg.is_trusted("HTTPS://A.Example"));
207
cfg.revoke_origin("a.example");
208
assert!(!cfg.is_trusted("a.example"));
209
}
210
211
#[test]
129
#[test]
212
fn save_load_roundtrip_in_temp_dir() {
130
fn save_load_roundtrip_in_temp_dir() {
213
let dir = tempfile::tempdir().unwrap();
131
let dir = tempfile::tempdir().unwrap();
214
let path = dir.path().join("posprint").join("config.json");
132
let path = dir.path().join("posprint").join("config.json");
215
let mut cfg = AppConfig::default();
133
let mut cfg = AppConfig::default();
216
cfg.default_page_width_mm = 58.0;
134
cfg.default_page_width_mm = 58.0;
217
cfg.trust_origin("pos.example");
218
cfg.remember_printer("winspool:POS-58");
135
cfg.remember_printer("winspool:POS-58");
219
cfg.save_to_path(&path).unwrap();
136
cfg.save_to_path(&path).unwrap();
220
137
221
let loaded = AppConfig::load_from_path(&path);
138
let loaded = AppConfig::load_from_path(&path);
222
assert_eq!(loaded.default_page_width_mm, 58.0);
139
assert_eq!(loaded.default_page_width_mm, 58.0);
223
assert!(loaded.is_trusted("pos.example"));
224
assert_eq!(loaded.last_printer_key.as_deref(), Some("winspool:POS-58"));
140
assert_eq!(loaded.last_printer_key.as_deref(), Some("winspool:POS-58"));
225
}
141
}
142
143
#[test]
144
fn loads_legacy_trusted_origins_without_keeping_them() {
145
let dir = tempfile::tempdir().unwrap();
146
let path = dir.path().join("config.json");
147
fs::write(
148
&path,
149
r#"{"version":1,"default_page_width_mm":80.0,"trusted_origins":["shop.example"],"last_printer_key":null}"#,
150
)
151
.unwrap();
152
let loaded = AppConfig::load_from_path(&path);
153
assert!(loaded.trusted_origins.is_empty());
154
loaded.save_to_path(&path).unwrap();
155
let text = fs::read_to_string(&path).unwrap();
156
assert!(!text.contains("trusted_origins"));
157
}
226
}
158
}
@@ -659,6 +659,9 @@ fn parse_align_value(value: &str, line_no: usize) -> Result<Align, ParseError> {
659
659
660
660
/// Collect data tokens from `data_idx` until the first `key=value` attribute.
661
661
/// Remaining tokens are returned as attributes (must all be `key=value`).
662
///
663
/// Tokens that contain `=` inside a URL/query (e.g. `https://x?a=1`) are still
664
/// treated as data — only simple identifier keys count as attributes.
662
665
fn take_data_tokens<'a>(
663
666
parts: &'a [&str],
664
667
data_idx: usize,
@@ -668,7 +671,7 @@ fn take_data_tokens<'a>(
668
671
if data_idx >= parts.len() {
669
672
return Err(err(line_no, 1, format!("{directive} requires data")));
670
673
}
671
if parts[data_idx].contains('=') {
674
if looks_like_attribute_token(parts[data_idx]) {
672
675
return Err(err(
673
676
line_no,
674
677
1,
@@ -676,13 +679,25 @@ fn take_data_tokens<'a>(
676
679
));
677
680
}
678
681
let mut data_end = data_idx + 1;
679
while data_end < parts.len() && !parts[data_end].contains('=') {
682
while data_end < parts.len() && !looks_like_attribute_token(parts[data_end]) {
680
683
data_end += 1;
681
684
}
682
685
let data = parts[data_idx..data_end].join(" ");
683
686
Ok((data, &parts[data_end..]))
684
687
}
685
688
689
/// True for tokens like `size=4` / `align=center`, false for URLs with `?a=1`.
690
fn looks_like_attribute_token(token: &str) -> bool {
691
let Some((key, _value)) = token.split_once('=') else {
692
return false;
693
};
694
if key.is_empty() {
695
return false;
696
}
697
key.chars()
698
.all(|c| c.is_ascii_alphanumeric() || c == '_')
699
}
700
686
701
fn is_list_item_line(line: &str) -> bool {
687
702
line.trim_start().starts_with("- ")
688
703
}
@@ -1225,4 +1240,42 @@ mod tests {
1225
1240
other => panic!("expected qr, got {other:?}"),
1226
1241
}
1227
1242
}
1243
1244
#[test]
1245
fn qr_url_with_query_equals_is_data_not_attribute() {
1246
let doc = parse(
1247
"@qr https://sleutels.kvt.nl/moirai/index.php?t=l&d=5CD146GMCC size=4 ecc=M align=center",
1248
)
1249
.unwrap();
1250
match &doc.blocks[0] {
1251
Block::Qr {
1252
data,
1253
size,
1254
ecc,
1255
align,
1256
..
1257
} => {
1258
assert_eq!(
1259
data,
1260
"https://sleutels.kvt.nl/moirai/index.php?t=l&d=5CD146GMCC"
1261
);
1262
assert_eq!(*size, 4);
1263
assert_eq!(*ecc, QrEcc::M);
1264
assert_eq!(*align, Align::Center);
1265
}
1266
other => panic!("expected qr, got {other:?}"),
1267
}
1268
}
1269
1270
#[test]
1271
fn barcode_url_with_query_equals_is_data() {
1272
let doc = parse("@barcode RASTER CODE128 https://example.com/x?a=1&b=2 height=40").unwrap();
1273
match &doc.blocks[0] {
1274
Block::Barcode { data, height, .. } => {
1275
assert_eq!(data, "https://example.com/x?a=1&b=2");
1276
assert_eq!(*height, 40);
1277
}
1278
other => panic!("expected barcode, got {other:?}"),
1279
}
1280
}
1228
1281
}
@@ -659,6 +659,9 @@ fn parse_align_value(value: &str, line_no: usize) -> Result<Align, ParseError> {659
659
660
/// Collect data tokens from `data_idx` until the first `key=value` attribute.
660
/// Collect data tokens from `data_idx` until the first `key=value` attribute.
661
/// Remaining tokens are returned as attributes (must all be `key=value`).
661
/// Remaining tokens are returned as attributes (must all be `key=value`).
662
///
663
/// Tokens that contain `=` inside a URL/query (e.g. `https://x?a=1`) are still
664
/// treated as data — only simple identifier keys count as attributes.
662
fn take_data_tokens<'a>(
665
fn take_data_tokens<'a>(
663
parts: &'a [&str],
666
parts: &'a [&str],
664
data_idx: usize,
667
data_idx: usize,
@@ -668,7 +671,7 @@ fn take_data_tokens<'a>(668
if data_idx >= parts.len() {
671
if data_idx >= parts.len() {
669
return Err(err(line_no, 1, format!("{directive} requires data")));
672
return Err(err(line_no, 1, format!("{directive} requires data")));
670
}
673
}
671
if parts[data_idx].contains('=') {
674
if looks_like_attribute_token(parts[data_idx]) {
672
return Err(err(
675
return Err(err(
673
line_no,
676
line_no,
674
1,
677
1,
@@ -676,13 +679,25 @@ fn take_data_tokens<'a>(676
));
679
));
677
}
680
}
678
let mut data_end = data_idx + 1;
681
let mut data_end = data_idx + 1;
679
while data_end < parts.len() && !parts[data_end].contains('=') {
682
while data_end < parts.len() && !looks_like_attribute_token(parts[data_end]) {
680
data_end += 1;
683
data_end += 1;
681
}
684
}
682
let data = parts[data_idx..data_end].join(" ");
685
let data = parts[data_idx..data_end].join(" ");
683
Ok((data, &parts[data_end..]))
686
Ok((data, &parts[data_end..]))
684
}
687
}
685
688
689
/// True for tokens like `size=4` / `align=center`, false for URLs with `?a=1`.
690
fn looks_like_attribute_token(token: &str) -> bool {
691
let Some((key, _value)) = token.split_once('=') else {
692
return false;
693
};
694
if key.is_empty() {
695
return false;
696
}
697
key.chars()
698
.all(|c| c.is_ascii_alphanumeric() || c == '_')
699
}
700
686
fn is_list_item_line(line: &str) -> bool {
701
fn is_list_item_line(line: &str) -> bool {
687
line.trim_start().starts_with("- ")
702
line.trim_start().starts_with("- ")
688
}
703
}
@@ -1225,4 +1240,42 @@ mod tests {1225
other => panic!("expected qr, got {other:?}"),
1240
other => panic!("expected qr, got {other:?}"),
1226
}
1241
}
1227
}
1242
}
1243
1244
#[test]
1245
fn qr_url_with_query_equals_is_data_not_attribute() {
1246
let doc = parse(
1247
"@qr https://sleutels.kvt.nl/moirai/index.php?t=l&d=5CD146GMCC size=4 ecc=M align=center",
1248
)
1249
.unwrap();
1250
match &doc.blocks[0] {
1251
Block::Qr {
1252
data,
1253
size,
1254
ecc,
1255
align,
1256
..
1257
} => {
1258
assert_eq!(
1259
data,
1260
"https://sleutels.kvt.nl/moirai/index.php?t=l&d=5CD146GMCC"
1261
);
1262
assert_eq!(*size, 4);
1263
assert_eq!(*ecc, QrEcc::M);
1264
assert_eq!(*align, Align::Center);
1265
}
1266
other => panic!("expected qr, got {other:?}"),
1267
}
1268
}
1269
1270
#[test]
1271
fn barcode_url_with_query_equals_is_data() {
1272
let doc = parse("@barcode RASTER CODE128 https://example.com/x?a=1&b=2 height=40").unwrap();
1273
match &doc.blocks[0] {
1274
Block::Barcode { data, height, .. } => {
1275
assert_eq!(data, "https://example.com/x?a=1&b=2");
1276
assert_eq!(*height, 40);
1277
}
1278
other => panic!("expected barcode, got {other:?}"),
1279
}
1280
}
1228
}
1281
}
@@ -76,7 +76,16 @@ fn download_cached(url: &str) -> Result<Vec<u8>, ImageLoadError> {
76
76
}
77
77
78
78
fn download(url: &str) -> Result<Vec<u8>, ImageLoadError> {
79
// Accept certificates the rustls/webpki bundle does not know (corporate CAs,
80
// incomplete chains). Remote logos on POS templates often live on such hosts.
81
let tls = native_tls::TlsConnector::builder()
82
.danger_accept_invalid_certs(true)
83
.danger_accept_invalid_hostnames(true)
84
.build()
85
.map_err(|e| ImageLoadError::Message(format!("tls setup: {e}")))?;
86
79
87
let agent = ureq::AgentBuilder::new()
88
.tls_connector(std::sync::Arc::new(tls))
80
89
.timeout_connect(Duration::from_secs(DOWNLOAD_TIMEOUT_SECS))
81
90
.timeout_read(Duration::from_secs(DOWNLOAD_TIMEOUT_SECS))
82
91
.build();
@@ -76,7 +76,16 @@ fn download_cached(url: &str) -> Result<Vec<u8>, ImageLoadError> {76
}
76
}
77
77
78
fn download(url: &str) -> Result<Vec<u8>, ImageLoadError> {
78
fn download(url: &str) -> Result<Vec<u8>, ImageLoadError> {
79
// Accept certificates the rustls/webpki bundle does not know (corporate CAs,
80
// incomplete chains). Remote logos on POS templates often live on such hosts.
81
let tls = native_tls::TlsConnector::builder()
82
.danger_accept_invalid_certs(true)
83
.danger_accept_invalid_hostnames(true)
84
.build()
85
.map_err(|e| ImageLoadError::Message(format!("tls setup: {e}")))?;
86
79
let agent = ureq::AgentBuilder::new()
87
let agent = ureq::AgentBuilder::new()
88
.tls_connector(std::sync::Arc::new(tls))
80
.timeout_connect(Duration::from_secs(DOWNLOAD_TIMEOUT_SECS))
89
.timeout_connect(Duration::from_secs(DOWNLOAD_TIMEOUT_SECS))
81
.timeout_read(Duration::from_secs(DOWNLOAD_TIMEOUT_SECS))
90
.timeout_read(Duration::from_secs(DOWNLOAD_TIMEOUT_SECS))
82
.build();
91
.build();
@@ -14,7 +14,6 @@ pub mod preview;
14
14
pub mod print;
15
15
pub mod protocol_url;
16
16
pub mod raster;
17
pub mod referrer_verify;
18
17
pub mod text_wrap;
19
18
pub mod undo;
20
19
@@ -14,7 +14,6 @@ pub mod preview;14
pub mod print;
14
pub mod print;
15
pub mod protocol_url;
15
pub mod protocol_url;
16
pub mod raster;
16
pub mod raster;
17
pub mod referrer_verify;
18
pub mod text_wrap;
17
pub mod text_wrap;
19
pub mod undo;
18
pub mod undo;
20
19
@@ -1,14 +1,11 @@
1
1
//! Print dialog + live preview, then exit.
2
2
3
3
use std::path::PathBuf;
4
use std::sync::mpsc::{self, Receiver, TryRecvError};
5
4
6
5
use eframe::egui;
7
6
8
use posprint::config::AppConfig;
9
7
use posprint::io::{PosFile, PosMetadata};
10
8
use posprint::protocol_url::PosprintLaunch;
11
use posprint::referrer_verify;
12
9
13
10
use crate::preview_panel::show_preview_panel;
14
11
use crate::print_dialog::{PrintDialog, PrintDialogAction, PrintExecuteResult};
@@ -23,14 +20,9 @@ pub struct PrintOnlyApp {
23
20
preview_zoom: f32,
24
21
fatal_error: Option<String>,
25
22
exit_requested: bool,
26
/// Auto-print once printers are ready (after trust if needed).
23
/// Auto-print once printers are ready (`noconfirm=1`).
27
24
auto_print: bool,
28
/// Pending first-time trust confirmation for this hostname.
29
pending_trust: Option<String>,
30
25
auto_print_attempted: bool,
31
/// Background GET of `referrer=` for noconfirm.
32
referrer_rx: Option<Receiver<Result<String, String>>>,
33
verifying_referrer: bool,
34
26
}
35
27
36
28
impl PrintOnlyApp {
@@ -71,20 +63,8 @@ impl PrintOnlyApp {
71
63
.clone()
72
64
.unwrap_or_else(|| "posprint://".into());
73
65
let mut app = Self::from_pos_file(launch.file, label);
74
if !launch.noconfirm {
75
return app;
76
}
77
78
match launch.referrer {
79
None => {
80
app.fatal_error = Some(
81
"noconfirm=1 requires referrer=<https://host/path?…> so posprint can verify the print with that site."
82
.into(),
83
);
84
}
85
Some(referrer) => {
86
app.start_referrer_verification(referrer);
87
}
66
if launch.noconfirm {
67
app.auto_print = true;
88
68
}
89
69
app
90
70
}
@@ -107,49 +87,7 @@ impl PrintOnlyApp {
107
87
fatal_error: None,
108
88
exit_requested: false,
109
89
auto_print: false,
110
pending_trust: None,
111
90
auto_print_attempted: false,
112
referrer_rx: None,
113
verifying_referrer: false,
114
}
115
}
116
117
fn start_referrer_verification(&mut self, referrer: String) {
118
self.verifying_referrer = true;
119
let (tx, rx) = mpsc::channel();
120
self.referrer_rx = Some(rx);
121
std::thread::spawn(move || {
122
let result = referrer_verify::verify_referrer(&referrer).map_err(|e| e.to_string());
123
let _ = tx.send(result);
124
});
125
}
126
127
fn poll_referrer_verification(&mut self, ctx: &egui::Context) {
128
let Some(rx) = &self.referrer_rx else {
129
return;
130
};
131
match rx.try_recv() {
132
Ok(Ok(host)) => {
133
self.referrer_rx = None;
134
self.verifying_referrer = false;
135
let cfg = AppConfig::load();
136
if cfg.is_trusted(&host) {
137
self.auto_print = true;
138
} else {
139
self.pending_trust = Some(host);
140
}
141
}
142
Ok(Err(e)) => {
143
self.referrer_rx = None;
144
self.verifying_referrer = false;
145
self.fatal_error = Some(e);
146
}
147
Err(TryRecvError::Empty) => ctx.request_repaint(),
148
Err(TryRecvError::Disconnected) => {
149
self.referrer_rx = None;
150
self.verifying_referrer = false;
151
self.fatal_error = Some("referrer verification interrupted".into());
152
}
153
91
}
154
92
}
155
93
@@ -197,57 +135,8 @@ impl eframe::App for PrintOnlyApp {
197
135
}
198
136
199
137
self.dialog.poll_printer_discovery(ctx);
200
self.poll_referrer_verification(ctx);
201
138
ctx.send_viewport_cmd(egui::ViewportCommand::Title(self.title()));
202
139
203
if self.verifying_referrer {
204
egui::CentralPanel::default().show(ctx, |ui| {
205
ui.heading("Verifying print request…");
206
ui.separator();
207
ui.horizontal(|ui| {
208
ui.spinner();
209
ui.label("Checking referrer URL with the issuing website.");
210
});
211
if ui.button("Cancel").clicked() {
212
self.request_exit();
213
}
214
});
215
return;
216
}
217
218
if let Some(origin) = self.pending_trust.clone() {
219
egui::CentralPanel::default().show(ctx, |ui| {
220
ui.heading("Trust this site?");
221
ui.separator();
222
ui.label(format!(
223
"“{origin}” verified this print request and wants to print without confirmation (noconfirm)."
224
));
225
ui.label(
226
"If you trust this site, future verified noconfirm prints from this domain will not ask again.",
227
);
228
ui.add_space(12.0);
229
ui.horizontal(|ui| {
230
if ui.button("Trust and print").clicked() {
231
let mut cfg = AppConfig::load();
232
cfg.trust_origin(&origin);
233
if let Err(e) = cfg.save() {
234
self.fatal_error = Some(format!("Could not save trust setting: {e}"));
235
self.pending_trust = None;
236
} else {
237
self.pending_trust = None;
238
self.auto_print = true;
239
}
240
}
241
if ui.button("Cancel").clicked() {
242
self.request_exit();
243
}
244
});
245
ui.add_space(8.0);
246
ui.label("You can revoke trust later under Settings in the designer.");
247
});
248
return;
249
}
250
251
140
if let Some(err) = self.fatal_error.clone() {
252
141
egui::CentralPanel::default().show(ctx, |ui| {
253
142
ui.heading("Print");
@@ -1,14 +1,11 @@1
//! Print dialog + live preview, then exit.
1
//! Print dialog + live preview, then exit.
2
2
3
use std::path::PathBuf;
3
use std::path::PathBuf;
4
use std::sync::mpsc::{self, Receiver, TryRecvError};
5
4
6
use eframe::egui;
5
use eframe::egui;
7
6
8
use posprint::config::AppConfig;
9
use posprint::io::{PosFile, PosMetadata};
7
use posprint::io::{PosFile, PosMetadata};
10
use posprint::protocol_url::PosprintLaunch;
8
use posprint::protocol_url::PosprintLaunch;
11
use posprint::referrer_verify;
12
9
13
use crate::preview_panel::show_preview_panel;
10
use crate::preview_panel::show_preview_panel;
14
use crate::print_dialog::{PrintDialog, PrintDialogAction, PrintExecuteResult};
11
use crate::print_dialog::{PrintDialog, PrintDialogAction, PrintExecuteResult};
@@ -23,14 +20,9 @@ pub struct PrintOnlyApp {23
preview_zoom: f32,
20
preview_zoom: f32,
24
fatal_error: Option<String>,
21
fatal_error: Option<String>,
25
exit_requested: bool,
22
exit_requested: bool,
26
/// Auto-print once printers are ready (after trust if needed).
23
/// Auto-print once printers are ready (`noconfirm=1`).
27
auto_print: bool,
24
auto_print: bool,
28
/// Pending first-time trust confirmation for this hostname.
29
pending_trust: Option<String>,
30
auto_print_attempted: bool,
25
auto_print_attempted: bool,
31
/// Background GET of `referrer=` for noconfirm.
32
referrer_rx: Option<Receiver<Result<String, String>>>,
33
verifying_referrer: bool,
34
}
26
}
35
27
36
impl PrintOnlyApp {
28
impl PrintOnlyApp {
@@ -71,20 +63,8 @@ impl PrintOnlyApp {71
.clone()
63
.clone()
72
.unwrap_or_else(|| "posprint://".into());
64
.unwrap_or_else(|| "posprint://".into());
73
let mut app = Self::from_pos_file(launch.file, label);
65
let mut app = Self::from_pos_file(launch.file, label);
74
if !launch.noconfirm {
66
if launch.noconfirm {
75
return app;
67
app.auto_print = true;
76
}
77
78
match launch.referrer {
79
None => {
80
app.fatal_error = Some(
81
"noconfirm=1 requires referrer=<https://host/path?…> so posprint can verify the print with that site."
82
.into(),
83
);
84
}
85
Some(referrer) => {
86
app.start_referrer_verification(referrer);
87
}
88
}
68
}
89
app
69
app
90
}
70
}
@@ -107,49 +87,7 @@ impl PrintOnlyApp {107
fatal_error: None,
87
fatal_error: None,
108
exit_requested: false,
88
exit_requested: false,
109
auto_print: false,
89
auto_print: false,
110
pending_trust: None,
111
auto_print_attempted: false,
90
auto_print_attempted: false,
112
referrer_rx: None,
113
verifying_referrer: false,
114
}
115
}
116
117
fn start_referrer_verification(&mut self, referrer: String) {
118
self.verifying_referrer = true;
119
let (tx, rx) = mpsc::channel();
120
self.referrer_rx = Some(rx);
121
std::thread::spawn(move || {
122
let result = referrer_verify::verify_referrer(&referrer).map_err(|e| e.to_string());
123
let _ = tx.send(result);
124
});
125
}
126
127
fn poll_referrer_verification(&mut self, ctx: &egui::Context) {
128
let Some(rx) = &self.referrer_rx else {
129
return;
130
};
131
match rx.try_recv() {
132
Ok(Ok(host)) => {
133
self.referrer_rx = None;
134
self.verifying_referrer = false;
135
let cfg = AppConfig::load();
136
if cfg.is_trusted(&host) {
137
self.auto_print = true;
138
} else {
139
self.pending_trust = Some(host);
140
}
141
}
142
Ok(Err(e)) => {
143
self.referrer_rx = None;
144
self.verifying_referrer = false;
145
self.fatal_error = Some(e);
146
}
147
Err(TryRecvError::Empty) => ctx.request_repaint(),
148
Err(TryRecvError::Disconnected) => {
149
self.referrer_rx = None;
150
self.verifying_referrer = false;
151
self.fatal_error = Some("referrer verification interrupted".into());
152
}
153
}
91
}
154
}
92
}
155
93
@@ -197,57 +135,8 @@ impl eframe::App for PrintOnlyApp {197
}
135
}
198
136
199
self.dialog.poll_printer_discovery(ctx);
137
self.dialog.poll_printer_discovery(ctx);
200
self.poll_referrer_verification(ctx);
201
ctx.send_viewport_cmd(egui::ViewportCommand::Title(self.title()));
138
ctx.send_viewport_cmd(egui::ViewportCommand::Title(self.title()));
202
139
203
if self.verifying_referrer {
204
egui::CentralPanel::default().show(ctx, |ui| {
205
ui.heading("Verifying print request…");
206
ui.separator();
207
ui.horizontal(|ui| {
208
ui.spinner();
209
ui.label("Checking referrer URL with the issuing website.");
210
});
211
if ui.button("Cancel").clicked() {
212
self.request_exit();
213
}
214
});
215
return;
216
}
217
218
if let Some(origin) = self.pending_trust.clone() {
219
egui::CentralPanel::default().show(ctx, |ui| {
220
ui.heading("Trust this site?");
221
ui.separator();
222
ui.label(format!(
223
"“{origin}” verified this print request and wants to print without confirmation (noconfirm)."
224
));
225
ui.label(
226
"If you trust this site, future verified noconfirm prints from this domain will not ask again.",
227
);
228
ui.add_space(12.0);
229
ui.horizontal(|ui| {
230
if ui.button("Trust and print").clicked() {
231
let mut cfg = AppConfig::load();
232
cfg.trust_origin(&origin);
233
if let Err(e) = cfg.save() {
234
self.fatal_error = Some(format!("Could not save trust setting: {e}"));
235
self.pending_trust = None;
236
} else {
237
self.pending_trust = None;
238
self.auto_print = true;
239
}
240
}
241
if ui.button("Cancel").clicked() {
242
self.request_exit();
243
}
244
});
245
ui.add_space(8.0);
246
ui.label("You can revoke trust later under Settings in the designer.");
247
});
248
return;
249
}
250
251
if let Some(err) = self.fatal_error.clone() {
140
if let Some(err) = self.fatal_error.clone() {
252
egui::CentralPanel::default().show(ctx, |ui| {
141
egui::CentralPanel::default().show(ctx, |ui| {
253
ui.heading("Print");
142
ui.heading("Print");
@@ -55,18 +55,14 @@ impl From<serde_json::Error> for ProtocolUrlError {
55
55
#[derive(Debug, Clone, PartialEq)]
56
56
pub struct PosprintLaunch {
57
57
pub file: PosFile,
58
/// When true, print without waiting for the Print button (subject to referrer verify + trust).
58
/// When true, print without waiting for the Print button.
59
59
pub noconfirm: bool,
60
/// Verification URL from `referrer=` (percent-decoded; may be scheme-less).
61
pub referrer: Option<String>,
62
60
}
63
61
64
62
/// Optional extras when encoding a URL.
65
63
#[derive(Debug, Clone, Default)]
66
64
pub struct EncodeOptions {
67
65
pub noconfirm: bool,
68
/// Full verification URL or `host/path?query` (stored percent-encoded in the posprint URL).
69
pub referrer: Option<String>,
70
66
}
71
67
72
68
/// True when `s` looks like a `posprint:` / `posprint://` protocol URL.
@@ -81,7 +77,7 @@ pub fn encode_posprint_url(file: &PosFile) -> Result<String, ProtocolUrlError> {
81
77
encode_posprint_url_with_options(file, &EncodeOptions::default())
82
78
}
83
79
84
/// Encode with optional `noconfirm` / `referrer` query parameters.
80
/// Encode with optional `noconfirm` query parameter.
85
81
pub fn encode_posprint_url_with_options(
86
82
file: &PosFile,
87
83
options: &EncodeOptions,
@@ -99,13 +95,6 @@ pub fn encode_posprint_url_with_options(
99
95
if options.noconfirm {
100
96
url.push_str("&noconfirm=1");
101
97
}
102
if let Some(raw) = options.referrer.as_deref() {
103
let trimmed = raw.trim();
104
if !trimmed.is_empty() {
105
url.push_str("&referrer=");
106
url.push_str(&percent_encode_component(trimmed));
107
}
108
}
109
98
Ok(url)
110
99
}
111
100
@@ -136,7 +125,6 @@ pub fn parse_posprint_url(url: &str) -> Result<PosprintLaunch, ProtocolUrlError>
136
125
let mut version: Option<String> = None;
137
126
let mut payload: Option<String> = None;
138
127
let mut noconfirm = false;
139
let mut referrer: Option<String> = None;
140
128
for pair in query.split('&') {
141
129
if pair.is_empty() {
142
130
continue;
@@ -147,12 +135,8 @@ pub fn parse_posprint_url(url: &str) -> Result<PosprintLaunch, ProtocolUrlError>
147
135
"v" => version = Some(percent_decode_str(value)?),
148
136
"d" => payload = Some(percent_decode_str(value)?),
149
137
"noconfirm" => noconfirm = parse_bool_flag(value),
150
"referrer" => {
151
let decoded = percent_decode_str(value)?;
152
if !decoded.trim().is_empty() {
153
referrer = Some(decoded);
154
}
155
}
138
// Legacy `referrer=` is ignored (browser protocol prompt is the trust gate).
139
"referrer" => {}
156
140
_ => {}
157
141
}
158
142
}
@@ -178,11 +162,7 @@ pub fn parse_posprint_url(url: &str) -> Result<PosprintLaunch, ProtocolUrlError>
178
162
return Err(ProtocolUrlError::UnsupportedPosVersion(file.version));
179
163
}
180
164
181
Ok(PosprintLaunch {
182
file,
183
noconfirm,
184
referrer,
185
})
165
Ok(PosprintLaunch { file, noconfirm })
186
166
}
187
167
188
168
fn parse_bool_flag(value: &str) -> bool {
@@ -196,19 +176,6 @@ fn parse_bool_flag(value: &str) -> bool {
196
176
)
197
177
}
198
178
199
fn percent_encode_component(input: &str) -> String {
200
let mut out = String::with_capacity(input.len());
201
for b in input.bytes() {
202
match b {
203
b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'_' | b'.' | b'~' => {
204
out.push(b as char);
205
}
206
_ => out.push_str(&format!("%{b:02X}")),
207
}
208
}
209
out
210
}
211
212
179
fn percent_decode_str(input: &str) -> Result<String, ProtocolUrlError> {
213
180
let bytes = percent_decode_bytes(input.as_bytes())?;
214
181
String::from_utf8(bytes).map_err(|e| ProtocolUrlError::InvalidEncoding(e.to_string()))
@@ -281,39 +248,29 @@ mod tests {
281
248
let decoded = parse_posprint_url(&url).unwrap();
282
249
assert_eq!(decoded.file, file);
283
250
assert!(!decoded.noconfirm);
284
assert!(decoded.referrer.is_none());
285
251
}
286
252
287
253
#[test]
288
fn encodes_and_parses_noconfirm_and_referrer() {
254
fn encodes_and_parses_noconfirm() {
289
255
let file = sample_file();
290
256
let url = encode_posprint_url_with_options(
291
257
&file,
292
&EncodeOptions {
293
noconfirm: true,
294
referrer: Some("website.com/bonnen/verify?code=84923".into()),
295
},
258
&EncodeOptions { noconfirm: true },
296
259
)
297
260
.unwrap();
298
261
assert!(url.contains("&noconfirm=1"));
299
assert!(url.contains("&referrer="));
300
assert!(url.contains("code%3D84923") || url.contains("code%3d84923"));
262
assert!(!url.contains("referrer"));
301
263
let launch = parse_posprint_url(&url).unwrap();
302
264
assert!(launch.noconfirm);
303
assert_eq!(
304
launch.referrer.as_deref(),
305
Some("website.com/bonnen/verify?code=84923")
306
);
307
265
}
308
266
309
267
#[test]
310
fn parses_noconfirm_without_value() {
268
fn parses_noconfirm_and_ignores_legacy_referrer() {
311
269
let file = sample_file();
312
270
let base = encode_posprint_url(&file).unwrap();
313
271
let url = format!("{base}&noconfirm&referrer=shop.example%2Fv");
314
272
let launch = parse_posprint_url(&url).unwrap();
315
273
assert!(launch.noconfirm);
316
assert_eq!(launch.referrer.as_deref(), Some("shop.example/v"));
317
274
}
318
275
319
276
#[test]
@@ -55,18 +55,14 @@ impl From<serde_json::Error> for ProtocolUrlError {55
#[derive(Debug, Clone, PartialEq)]
55
#[derive(Debug, Clone, PartialEq)]
56
pub struct PosprintLaunch {
56
pub struct PosprintLaunch {
57
pub file: PosFile,
57
pub file: PosFile,
58
/// When true, print without waiting for the Print button (subject to referrer verify + trust).
58
/// When true, print without waiting for the Print button.
59
pub noconfirm: bool,
59
pub noconfirm: bool,
60
/// Verification URL from `referrer=` (percent-decoded; may be scheme-less).
61
pub referrer: Option<String>,
62
}
60
}
63
61
64
/// Optional extras when encoding a URL.
62
/// Optional extras when encoding a URL.
65
#[derive(Debug, Clone, Default)]
63
#[derive(Debug, Clone, Default)]
66
pub struct EncodeOptions {
64
pub struct EncodeOptions {
67
pub noconfirm: bool,
65
pub noconfirm: bool,
68
/// Full verification URL or `host/path?query` (stored percent-encoded in the posprint URL).
69
pub referrer: Option<String>,
70
}
66
}
71
67
72
/// True when `s` looks like a `posprint:` / `posprint://` protocol URL.
68
/// True when `s` looks like a `posprint:` / `posprint://` protocol URL.
@@ -81,7 +77,7 @@ pub fn encode_posprint_url(file: &PosFile) -> Result<String, ProtocolUrlError> {81
encode_posprint_url_with_options(file, &EncodeOptions::default())
77
encode_posprint_url_with_options(file, &EncodeOptions::default())
82
}
78
}
83
79
84
/// Encode with optional `noconfirm` / `referrer` query parameters.
80
/// Encode with optional `noconfirm` query parameter.
85
pub fn encode_posprint_url_with_options(
81
pub fn encode_posprint_url_with_options(
86
file: &PosFile,
82
file: &PosFile,
87
options: &EncodeOptions,
83
options: &EncodeOptions,
@@ -99,13 +95,6 @@ pub fn encode_posprint_url_with_options(99
if options.noconfirm {
95
if options.noconfirm {
100
url.push_str("&noconfirm=1");
96
url.push_str("&noconfirm=1");
101
}
97
}
102
if let Some(raw) = options.referrer.as_deref() {
103
let trimmed = raw.trim();
104
if !trimmed.is_empty() {
105
url.push_str("&referrer=");
106
url.push_str(&percent_encode_component(trimmed));
107
}
108
}
109
Ok(url)
98
Ok(url)
110
}
99
}
111
100
@@ -136,7 +125,6 @@ pub fn parse_posprint_url(url: &str) -> Result<PosprintLaunch, ProtocolUrlError>136
let mut version: Option<String> = None;
125
let mut version: Option<String> = None;
137
let mut payload: Option<String> = None;
126
let mut payload: Option<String> = None;
138
let mut noconfirm = false;
127
let mut noconfirm = false;
139
let mut referrer: Option<String> = None;
140
for pair in query.split('&') {
128
for pair in query.split('&') {
141
if pair.is_empty() {
129
if pair.is_empty() {
142
continue;
130
continue;
@@ -147,12 +135,8 @@ pub fn parse_posprint_url(url: &str) -> Result<PosprintLaunch, ProtocolUrlError>147
"v" => version = Some(percent_decode_str(value)?),
135
"v" => version = Some(percent_decode_str(value)?),
148
"d" => payload = Some(percent_decode_str(value)?),
136
"d" => payload = Some(percent_decode_str(value)?),
149
"noconfirm" => noconfirm = parse_bool_flag(value),
137
"noconfirm" => noconfirm = parse_bool_flag(value),
150
"referrer" => {
138
// Legacy `referrer=` is ignored (browser protocol prompt is the trust gate).
151
let decoded = percent_decode_str(value)?;
139
"referrer" => {}
152
if !decoded.trim().is_empty() {
153
referrer = Some(decoded);
154
}
155
}
156
_ => {}
140
_ => {}
157
}
141
}
158
}
142
}
@@ -178,11 +162,7 @@ pub fn parse_posprint_url(url: &str) -> Result<PosprintLaunch, ProtocolUrlError>178
return Err(ProtocolUrlError::UnsupportedPosVersion(file.version));
162
return Err(ProtocolUrlError::UnsupportedPosVersion(file.version));
179
}
163
}
180
164
181
Ok(PosprintLaunch {
165
Ok(PosprintLaunch { file, noconfirm })
182
file,
183
noconfirm,
184
referrer,
185
})
186
}
166
}
187
167
188
fn parse_bool_flag(value: &str) -> bool {
168
fn parse_bool_flag(value: &str) -> bool {
@@ -196,19 +176,6 @@ fn parse_bool_flag(value: &str) -> bool {196
)
176
)
197
}
177
}
198
178
199
fn percent_encode_component(input: &str) -> String {
200
let mut out = String::with_capacity(input.len());
201
for b in input.bytes() {
202
match b {
203
b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'_' | b'.' | b'~' => {
204
out.push(b as char);
205
}
206
_ => out.push_str(&format!("%{b:02X}")),
207
}
208
}
209
out
210
}
211
212
fn percent_decode_str(input: &str) -> Result<String, ProtocolUrlError> {
179
fn percent_decode_str(input: &str) -> Result<String, ProtocolUrlError> {
213
let bytes = percent_decode_bytes(input.as_bytes())?;
180
let bytes = percent_decode_bytes(input.as_bytes())?;
214
String::from_utf8(bytes).map_err(|e| ProtocolUrlError::InvalidEncoding(e.to_string()))
181
String::from_utf8(bytes).map_err(|e| ProtocolUrlError::InvalidEncoding(e.to_string()))
@@ -281,39 +248,29 @@ mod tests {281
let decoded = parse_posprint_url(&url).unwrap();
248
let decoded = parse_posprint_url(&url).unwrap();
282
assert_eq!(decoded.file, file);
249
assert_eq!(decoded.file, file);
283
assert!(!decoded.noconfirm);
250
assert!(!decoded.noconfirm);
284
assert!(decoded.referrer.is_none());
285
}
251
}
286
252
287
#[test]
253
#[test]
288
fn encodes_and_parses_noconfirm_and_referrer() {
254
fn encodes_and_parses_noconfirm() {
289
let file = sample_file();
255
let file = sample_file();
290
let url = encode_posprint_url_with_options(
256
let url = encode_posprint_url_with_options(
291
&file,
257
&file,
292
&EncodeOptions {
258
&EncodeOptions { noconfirm: true },
293
noconfirm: true,
294
referrer: Some("website.com/bonnen/verify?code=84923".into()),
295
},
296
)
259
)
297
.unwrap();
260
.unwrap();
298
assert!(url.contains("&noconfirm=1"));
261
assert!(url.contains("&noconfirm=1"));
299
assert!(url.contains("&referrer="));
262
assert!(!url.contains("referrer"));
300
assert!(url.contains("code%3D84923") || url.contains("code%3d84923"));
301
let launch = parse_posprint_url(&url).unwrap();
263
let launch = parse_posprint_url(&url).unwrap();
302
assert!(launch.noconfirm);
264
assert!(launch.noconfirm);
303
assert_eq!(
304
launch.referrer.as_deref(),
305
Some("website.com/bonnen/verify?code=84923")
306
);
307
}
265
}
308
266
309
#[test]
267
#[test]
310
fn parses_noconfirm_without_value() {
268
fn parses_noconfirm_and_ignores_legacy_referrer() {
311
let file = sample_file();
269
let file = sample_file();
312
let base = encode_posprint_url(&file).unwrap();
270
let base = encode_posprint_url(&file).unwrap();
313
let url = format!("{base}&noconfirm&referrer=shop.example%2Fv");
271
let url = format!("{base}&noconfirm&referrer=shop.example%2Fv");
314
let launch = parse_posprint_url(&url).unwrap();
272
let launch = parse_posprint_url(&url).unwrap();
315
assert!(launch.noconfirm);
273
assert!(launch.noconfirm);
316
assert_eq!(launch.referrer.as_deref(), Some("shop.example/v"));
317
}
274
}
318
275
319
#[test]
276
#[test]
@@ -1,176 +0,0 @@
1
//! Verify `noconfirm` print requests via a caller-controlled HTTP(S) referrer URL.
2
3
use std::net::IpAddr;
4
use std::time::Duration;
5
6
use crate::config::normalize_origin;
7
8
const VERIFY_TIMEOUT_SECS: u64 = 10;
9
10
#[derive(Debug, Clone, PartialEq, Eq)]
11
pub enum ReferrerVerifyError {
12
Empty,
13
UnsupportedScheme(String),
14
InvalidUrl(String),
15
BlockedHost(String),
16
HttpStatus(u16),
17
Network(String),
18
}
19
20
impl std::fmt::Display for ReferrerVerifyError {
21
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22
match self {
23
Self::Empty => write!(f, "referrer URL is empty"),
24
Self::UnsupportedScheme(s) => {
25
write!(f, "referrer must be http(s), got '{s}'")
26
}
27
Self::InvalidUrl(e) => write!(f, "invalid referrer URL: {e}"),
28
Self::BlockedHost(h) => {
29
write!(f, "referrer host '{h}' is not allowed for verification")
30
}
31
Self::HttpStatus(code) => write!(
32
f,
33
"referrer verification failed (HTTP {code}); expected 200"
34
),
35
Self::Network(e) => write!(f, "referrer verification network error: {e}"),
36
}
37
}
38
}
39
40
impl std::error::Error for ReferrerVerifyError {}
41
42
/// Normalize a referrer parameter into an absolute `http://` or `https://` URL.
43
/// Bare values like `shop.example/verify?code=1` become `https://shop.example/verify?code=1`.
44
pub fn normalize_referrer_url(raw: &str) -> Result<String, ReferrerVerifyError> {
45
let s = raw.trim();
46
if s.is_empty() {
47
return Err(ReferrerVerifyError::Empty);
48
}
49
50
let absolute = if let Some(rest) = s.strip_prefix("https://") {
51
format!("https://{rest}")
52
} else if let Some(rest) = s.strip_prefix("http://") {
53
format!("http://{rest}")
54
} else if let Some(idx) = s.find("://") {
55
let scheme = &s[..idx];
56
return Err(ReferrerVerifyError::UnsupportedScheme(scheme.to_string()));
57
} else {
58
format!("https://{s}")
59
};
60
61
let host = host_from_http_url(&absolute)
62
.ok_or_else(|| ReferrerVerifyError::InvalidUrl("missing host".into()))?;
63
if is_blocked_verify_host(&host) {
64
return Err(ReferrerVerifyError::BlockedHost(host));
65
}
66
Ok(absolute)
67
}
68
69
/// Hostname used for trust storage after a successful verification GET.
70
pub fn referrer_trust_host(referrer_url: &str) -> Option<String> {
71
normalize_origin(referrer_url)
72
}
73
74
fn host_from_http_url(url: &str) -> Option<String> {
75
let rest = url
76
.strip_prefix("https://")
77
.or_else(|| url.strip_prefix("http://"))?;
78
let host_port = rest.split('/').next()?.split('?').next()?.trim();
79
if host_port.is_empty() {
80
return None;
81
}
82
let host = host_port.split(':').next()?.trim();
83
if host.is_empty() {
84
None
85
} else {
86
Some(host.to_ascii_lowercase())
87
}
88
}
89
90
fn is_blocked_verify_host(host: &str) -> bool {
91
let h = host.to_ascii_lowercase();
92
// Loopback is allowed (local verify servers / dev). Block other private LAN hosts.
93
if h == "localhost" || h.ends_with(".localhost") {
94
return false;
95
}
96
if let Ok(ip) = h.parse::<IpAddr>() {
97
return match ip {
98
IpAddr::V4(v4) => {
99
!v4.is_loopback()
100
&& (v4.is_private() || v4.is_link_local() || v4.is_unspecified())
101
}
102
IpAddr::V6(v6) => !v6.is_loopback() && v6.is_unspecified(),
103
};
104
}
105
false
106
}
107
108
/// True when an HTTP status means the print request is authorized by the site.
109
pub fn is_verification_success(status: u16) -> bool {
110
status == 200
111
}
112
113
/// GET `referrer_url` (no redirects). On HTTP 200 returns the trust hostname.
114
pub fn verify_referrer(referrer_url: &str) -> Result<String, ReferrerVerifyError> {
115
let url = normalize_referrer_url(referrer_url)?;
116
let host = referrer_trust_host(&url)
117
.ok_or_else(|| ReferrerVerifyError::InvalidUrl("missing host".into()))?;
118
119
let agent = ureq::AgentBuilder::new()
120
.timeout_connect(Duration::from_secs(VERIFY_TIMEOUT_SECS))
121
.timeout_read(Duration::from_secs(VERIFY_TIMEOUT_SECS))
122
.redirects(0)
123
.build();
124
125
let response = agent.get(&url).call().map_err(|e| match e {
126
ureq::Error::Status(code, _) => ReferrerVerifyError::HttpStatus(code),
127
other => ReferrerVerifyError::Network(other.to_string()),
128
})?;
129
130
let status = response.status();
131
if !is_verification_success(status) {
132
return Err(ReferrerVerifyError::HttpStatus(status));
133
}
134
Ok(host)
135
}
136
137
#[cfg(test)]
138
mod tests {
139
use super::*;
140
141
#[test]
142
fn normalizes_bare_host_path_to_https() {
143
let url = normalize_referrer_url("website.com/bonnen/verify?code=84923").unwrap();
144
assert_eq!(url, "https://website.com/bonnen/verify?code=84923");
145
assert_eq!(referrer_trust_host(&url).as_deref(), Some("website.com"));
146
}
147
148
#[test]
149
fn rejects_non_http_schemes() {
150
let err = normalize_referrer_url("file:///etc/passwd").unwrap_err();
151
assert!(matches!(err, ReferrerVerifyError::UnsupportedScheme(_)));
152
}
153
154
#[test]
155
fn allows_loopback_hosts() {
156
let url = normalize_referrer_url("http://127.0.0.1:8765/verify?code=1").unwrap();
157
assert_eq!(url, "http://127.0.0.1:8765/verify?code=1");
158
assert!(normalize_referrer_url("http://localhost/verify").is_ok());
159
}
160
161
#[test]
162
fn blocks_private_lan_hosts() {
163
let err = normalize_referrer_url("http://192.168.1.10/verify").unwrap_err();
164
assert!(matches!(err, ReferrerVerifyError::BlockedHost(_)));
165
let err = normalize_referrer_url("http://10.0.0.5/x").unwrap_err();
166
assert!(matches!(err, ReferrerVerifyError::BlockedHost(_)));
167
}
168
169
#[test]
170
fn only_http_200_counts_as_success() {
171
assert!(is_verification_success(200));
172
assert!(!is_verification_success(204));
173
assert!(!is_verification_success(404));
174
assert!(!is_verification_success(302));
175
}
176
}
@@ -1,176 +0,0 @@1
//! Verify `noconfirm` print requests via a caller-controlled HTTP(S) referrer URL.
2
3
use std::net::IpAddr;
4
use std::time::Duration;
5
6
use crate::config::normalize_origin;
7
8
const VERIFY_TIMEOUT_SECS: u64 = 10;
9
10
#[derive(Debug, Clone, PartialEq, Eq)]
11
pub enum ReferrerVerifyError {
12
Empty,
13
UnsupportedScheme(String),
14
InvalidUrl(String),
15
BlockedHost(String),
16
HttpStatus(u16),
17
Network(String),
18
}
19
20
impl std::fmt::Display for ReferrerVerifyError {
21
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22
match self {
23
Self::Empty => write!(f, "referrer URL is empty"),
24
Self::UnsupportedScheme(s) => {
25
write!(f, "referrer must be http(s), got '{s}'")
26
}
27
Self::InvalidUrl(e) => write!(f, "invalid referrer URL: {e}"),
28
Self::BlockedHost(h) => {
29
write!(f, "referrer host '{h}' is not allowed for verification")
30
}
31
Self::HttpStatus(code) => write!(
32
f,
33
"referrer verification failed (HTTP {code}); expected 200"
34
),
35
Self::Network(e) => write!(f, "referrer verification network error: {e}"),
36
}
37
}
38
}
39
40
impl std::error::Error for ReferrerVerifyError {}
41
42
/// Normalize a referrer parameter into an absolute `http://` or `https://` URL.
43
/// Bare values like `shop.example/verify?code=1` become `https://shop.example/verify?code=1`.
44
pub fn normalize_referrer_url(raw: &str) -> Result<String, ReferrerVerifyError> {
45
let s = raw.trim();
46
if s.is_empty() {
47
return Err(ReferrerVerifyError::Empty);
48
}
49
50
let absolute = if let Some(rest) = s.strip_prefix("https://") {
51
format!("https://{rest}")
52
} else if let Some(rest) = s.strip_prefix("http://") {
53
format!("http://{rest}")
54
} else if let Some(idx) = s.find("://") {
55
let scheme = &s[..idx];
56
return Err(ReferrerVerifyError::UnsupportedScheme(scheme.to_string()));
57
} else {
58
format!("https://{s}")
59
};
60
61
let host = host_from_http_url(&absolute)
62
.ok_or_else(|| ReferrerVerifyError::InvalidUrl("missing host".into()))?;
63
if is_blocked_verify_host(&host) {
64
return Err(ReferrerVerifyError::BlockedHost(host));
65
}
66
Ok(absolute)
67
}
68
69
/// Hostname used for trust storage after a successful verification GET.
70
pub fn referrer_trust_host(referrer_url: &str) -> Option<String> {
71
normalize_origin(referrer_url)
72
}
73
74
fn host_from_http_url(url: &str) -> Option<String> {
75
let rest = url
76
.strip_prefix("https://")
77
.or_else(|| url.strip_prefix("http://"))?;
78
let host_port = rest.split('/').next()?.split('?').next()?.trim();
79
if host_port.is_empty() {
80
return None;
81
}
82
let host = host_port.split(':').next()?.trim();
83
if host.is_empty() {
84
None
85
} else {
86
Some(host.to_ascii_lowercase())
87
}
88
}
89
90
fn is_blocked_verify_host(host: &str) -> bool {
91
let h = host.to_ascii_lowercase();
92
// Loopback is allowed (local verify servers / dev). Block other private LAN hosts.
93
if h == "localhost" || h.ends_with(".localhost") {
94
return false;
95
}
96
if let Ok(ip) = h.parse::<IpAddr>() {
97
return match ip {
98
IpAddr::V4(v4) => {
99
!v4.is_loopback()
100
&& (v4.is_private() || v4.is_link_local() || v4.is_unspecified())
101
}
102
IpAddr::V6(v6) => !v6.is_loopback() && v6.is_unspecified(),
103
};
104
}
105
false
106
}
107
108
/// True when an HTTP status means the print request is authorized by the site.
109
pub fn is_verification_success(status: u16) -> bool {
110
status == 200
111
}
112
113
/// GET `referrer_url` (no redirects). On HTTP 200 returns the trust hostname.
114
pub fn verify_referrer(referrer_url: &str) -> Result<String, ReferrerVerifyError> {
115
let url = normalize_referrer_url(referrer_url)?;
116
let host = referrer_trust_host(&url)
117
.ok_or_else(|| ReferrerVerifyError::InvalidUrl("missing host".into()))?;
118
119
let agent = ureq::AgentBuilder::new()
120
.timeout_connect(Duration::from_secs(VERIFY_TIMEOUT_SECS))
121
.timeout_read(Duration::from_secs(VERIFY_TIMEOUT_SECS))
122
.redirects(0)
123
.build();
124
125
let response = agent.get(&url).call().map_err(|e| match e {
126
ureq::Error::Status(code, _) => ReferrerVerifyError::HttpStatus(code),
127
other => ReferrerVerifyError::Network(other.to_string()),
128
})?;
129
130
let status = response.status();
131
if !is_verification_success(status) {
132
return Err(ReferrerVerifyError::HttpStatus(status));
133
}
134
Ok(host)
135
}
136
137
#[cfg(test)]
138
mod tests {
139
use super::*;
140
141
#[test]
142
fn normalizes_bare_host_path_to_https() {
143
let url = normalize_referrer_url("website.com/bonnen/verify?code=84923").unwrap();
144
assert_eq!(url, "https://website.com/bonnen/verify?code=84923");
145
assert_eq!(referrer_trust_host(&url).as_deref(), Some("website.com"));
146
}
147
148
#[test]
149
fn rejects_non_http_schemes() {
150
let err = normalize_referrer_url("file:///etc/passwd").unwrap_err();
151
assert!(matches!(err, ReferrerVerifyError::UnsupportedScheme(_)));
152
}
153
154
#[test]
155
fn allows_loopback_hosts() {
156
let url = normalize_referrer_url("http://127.0.0.1:8765/verify?code=1").unwrap();
157
assert_eq!(url, "http://127.0.0.1:8765/verify?code=1");
158
assert!(normalize_referrer_url("http://localhost/verify").is_ok());
159
}
160
161
#[test]
162
fn blocks_private_lan_hosts() {
163
let err = normalize_referrer_url("http://192.168.1.10/verify").unwrap_err();
164
assert!(matches!(err, ReferrerVerifyError::BlockedHost(_)));
165
let err = normalize_referrer_url("http://10.0.0.5/x").unwrap_err();
166
assert!(matches!(err, ReferrerVerifyError::BlockedHost(_)));
167
}
168
169
#[test]
170
fn only_http_200_counts_as_success() {
171
assert!(is_verification_success(200));
172
assert!(!is_verification_success(204));
173
assert!(!is_verification_success(404));
174
assert!(!is_verification_success(302));
175
}
176
}