-
Notifications
You must be signed in to change notification settings - Fork 355
Expand file tree
/
Copy pathstorescp.cc
More file actions
2884 lines (2610 loc) · 129 KB
/
storescp.cc
File metadata and controls
2884 lines (2610 loc) · 129 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
*
* Copyright (C) 1994-2026, OFFIS e.V.
* All rights reserved. See COPYRIGHT file for details.
*
* This software and supporting documentation were developed by
*
* OFFIS e.V.
* R&D Division Health
* Escherweg 2
* D-26121 Oldenburg, Germany
*
*
* Module: dcmnet
*
* Author: Andrew Hewett
*
* Purpose: Storage Service Class Provider (C-STORE operation)
*
*/
#include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */
BEGIN_EXTERN_C
#include <sys/stat.h>
#include <fcntl.h> /* needed on Solaris for O_RDONLY */
// On Solaris with Sun Workshop 11, <signal.h> declares signal() but <csignal> does not
#include <signal.h>
END_EXTERN_C
#include <cerrno>
#ifdef HAVE_WINDOWS_H
#include <direct.h> /* for _mkdir() */
#endif
#include "dcmtk/ofstd/ofstd.h"
#include "dcmtk/ofstd/ofconapp.h"
#include "dcmtk/ofstd/ofbmanip.h" /* for OFBitmanipTemplate */
#include "dcmtk/ofstd/oflist.h"
#include "dcmtk/ofstd/ofdatime.h"
#include "dcmtk/dcmnet/dicom.h" /* for DICOM_APPLICATION_ACCEPTOR */
#include "dcmtk/dcmnet/dimse.h"
#include "dcmtk/dcmnet/diutil.h"
#include "dcmtk/dcmnet/dcmtrans.h" /* for dcmSocketSend/ReceiveTimeout */
#include "dcmtk/dcmnet/dcasccfg.h" /* for class DcmAssociationConfiguration */
#include "dcmtk/dcmnet/dcasccff.h" /* for class DcmAssociationConfigurationFile */
#include "dcmtk/dcmdata/dcfilefo.h"
#include "dcmtk/dcmdata/dcuid.h"
#include "dcmtk/dcmdata/dcdict.h"
#include "dcmtk/dcmdata/cmdlnarg.h"
#include "dcmtk/dcmdata/dcmetinf.h"
#include "dcmtk/dcmdata/dcuid.h" /* for dcmtk version name */
#include "dcmtk/dcmdata/dcdeftag.h"
#include "dcmtk/dcmdata/dcostrmz.h" /* for dcmZlibCompressionLevel */
#include "dcmtk/dcmtls/tlsopt.h" /* for DcmTLSOptions */
#ifdef WITH_ZLIB
#include <zlib.h> /* for zlibVersion() */
#endif
// we assume that the inetd super server is available on all non-Windows systems
#ifndef _WIN32
#define INETD_AVAILABLE
#endif
#ifdef PRIVATE_STORESCP_DECLARATIONS
PRIVATE_STORESCP_DECLARATIONS
#else
#define OFFIS_CONSOLE_APPLICATION "storescp"
#endif
static OFLogger storescpLogger = OFLog::getLogger("dcmtk.apps." OFFIS_CONSOLE_APPLICATION);
static char rcsid[] = "$dcmtk: " OFFIS_CONSOLE_APPLICATION " v" OFFIS_DCMTK_VERSION " " OFFIS_DCMTK_RELEASEDATE " $";
#define APPLICATIONTITLE "STORESCP" /* our application entity title */
#define PATH_PLACEHOLDER "#p"
#define FILENAME_PLACEHOLDER "#f"
#define CALLING_AETITLE_PLACEHOLDER "#a"
#define CALLED_AETITLE_PLACEHOLDER "#c"
#define CALLING_PRESENTATION_ADDRESS_PLACEHOLDER "#r"
static OFCondition processCommands(T_ASC_Association *assoc);
static OFCondition acceptAssociation(T_ASC_Network *net, DcmAssociationConfiguration& asccfg, OFBool secureConnection);
static OFCondition echoSCP(T_ASC_Association * assoc, T_DIMSE_Message * msg, T_ASC_PresentationContextID presID);
static OFCondition storeSCP(T_ASC_Association * assoc, T_DIMSE_Message * msg, T_ASC_PresentationContextID presID);
static void executeOnReception();
static void executeEndOfStudyEvents();
static void executeOnEndOfStudy();
static void renameOnEndOfStudy();
static OFString replaceChars( const OFString &srcstr, const OFString &pattern, const OFString &substitute );
static void executeCommand( const OFString &cmd );
static void cleanChildren(pid_t pid, OFBool synch);
static void sanitizeAETitle(OFString& aet);
static OFCondition acceptUnknownContextsWithPreferredTransferSyntaxes(
T_ASC_Parameters * params,
const char* transferSyntaxes[],
int transferSyntaxCount,
T_ASC_SC_ROLE acceptedRole = ASC_SC_ROLE_DEFAULT);
static size_t cleanChildrenBatch(const size_t count, const size_t max);
/* sort study mode */
enum E_SortStudyMode
{
ESM_None,
ESM_Timestamp,
ESM_StudyInstanceUID,
ESM_PatientName
};
#ifdef WIN32
struct ChildProcessData
{
HANDLE processHandle;
HANDLE waitHandle;
bool done;
};
OFList< ChildProcessData * > ChildProcessList;
HANDLE ChildProcessEvent = NULL;
// This callback function will be executed by Windows in a separate thread when
// a child process has ended, similar to the SIGCHLD callback on Posix systems
static void CALLBACK onExitedCallback(void* context, BOOLEAN /* isTimeOut */)
{
// mark the related entry for the client process that has ended as "done", i.e. ready for clean-up
bool *done = OFstatic_cast(bool *, context);
*done = true;
// if the main thread is in a blocking wait in cleanChildren() because
// the maximum number of child processes was running, let the main thread continue now
if (ChildProcessEvent) SetEvent(ChildProcessEvent);
}
// This callback function will be called in the main thread by receiveTransportConnectionTCP()
// whenever a new child process has been create by CreateProcessA().
// The context parameter is a pointer to the process handle, which we must store
// and close when not needed anymore.
static void processCreatedCallback(void *context)
{
// event handler for blocking wait in cleanChildren()
if (ChildProcessEvent == NULL) ChildProcessEvent = CreateEventA(NULL, FALSE, FALSE, NULL);
// create new entry in list of child processes
ChildProcessData *cbd = new ChildProcessData();
cbd->processHandle = OFstatic_cast(HANDLE, context);
cbd->done = false;
// request Windows to call onExitedCallback() when the child process with the given process handle has exited
if (RegisterWaitForSingleObject(&cbd->waitHandle, cbd->processHandle, onExitedCallback, &cbd->done, INFINITE, WT_EXECUTEONLYONCE))
{
ChildProcessList.push_back(cbd);
}
else
{
OFLOG_WARN(storescpLogger, "RegisterWaitForSingleObject() failed, unable to track child process");
CloseHandle(cbd->processHandle);
delete cbd;
}
}
#endif
OFBool opt_showPresentationContexts = OFFalse;
OFBool opt_uniqueFilenames = OFFalse;
OFString opt_fileNameExtension;
OFBool opt_timeNames = OFFalse;
int timeNameCounter = -1; // "serial number" to differentiate between files with same timestamp
OFCmdUnsignedInt opt_port = 0;
OFBool opt_refuseAssociation = OFFalse;
OFBool opt_rejectWithoutImplementationUID = OFFalse;
OFCmdUnsignedInt opt_sleepAfter = 0;
OFCmdUnsignedInt opt_sleepDuring = 0;
OFCmdUnsignedInt opt_maxPDU = ASC_DEFAULTMAXPDU;
OFBool opt_useMetaheader = OFTrue;
OFBool opt_acceptAllXfers = OFFalse;
E_TransferSyntax opt_networkTransferSyntax = EXS_Unknown;
E_TransferSyntax opt_writeTransferSyntax = EXS_Unknown;
E_GrpLenEncoding opt_groupLength = EGL_recalcGL;
E_EncodingType opt_sequenceType = EET_ExplicitLength;
E_PaddingEncoding opt_paddingType = EPD_withoutPadding;
OFCmdUnsignedInt opt_filepad = 0;
OFCmdUnsignedInt opt_itempad = 0;
OFCmdUnsignedInt opt_compressionLevel = 0;
OFBool opt_bitPreserving = OFFalse;
OFBool opt_ignore = OFFalse;
OFBool opt_abortDuringStore = OFFalse;
OFBool opt_abortAfterStore = OFFalse;
OFBool opt_promiscuous = OFFalse;
OFBool opt_correctUIDPadding = OFFalse;
OFBool opt_inetd_mode = OFFalse;
OFString callingAETitle; // calling application entity title will be stored here
OFString calledAETitle; // called application entity title will be stored here
OFString callingPresentationAddress; // remote hostname or IP address will be stored here
const char * opt_respondingAETitle = APPLICATIONTITLE;
static OFString opt_outputDirectory = "."; // default: output directory equals "."
E_SortStudyMode opt_sortStudyMode = ESM_None; // default: no sorting
static const char *opt_sortStudyDirPrefix = NULL; // default: no directory prefix
OFString lastStudyInstanceUID;
OFString subdirectoryPathAndName;
OFList<OFString> outputFileNameArray;
static const char *opt_execOnReception = NULL; // default: don't execute anything on reception
static const char *opt_execOnEndOfStudy = NULL; // default: don't execute anything on end of study
OFString lastStudySubdirectoryPathAndName;
static OFBool opt_renameOnEndOfStudy = OFFalse; // default: don't rename any files on end of study
static long opt_endOfStudyTimeout = -1; // default: no end of study timeout
static OFBool endOfStudyThroughTimeoutEvent = OFFalse;
static const char *opt_configFile = NULL;
static const char *opt_profileName = NULL;
T_DIMSE_BlockingMode opt_blockMode = DIMSE_BLOCKING;
int opt_dimse_timeout = 0;
int opt_acse_timeout = 30;
OFCmdSignedInt opt_socket_timeout = 60;
#if defined(HAVE_FORK) || defined(_WIN32)
OFBool opt_forkMode = OFFalse;
#endif
OFBool opt_forkedChild = OFFalse;
OFBool opt_execSync = OFFalse; // default: execute in background
volatile size_t numChildren = 0;
OFCmdUnsignedInt opt_maxChildren = OFstatic_cast(OFCmdUnsignedInt, -1);
#ifdef HAVE_WAITPID
/** signal handler for SIGCHLD signals that immediately cleans up
* terminated children and adjusts the count of child processes
*/
extern "C" void sigChildHandler(int)
{
while (waitpid( -1, NULL, WNOHANG) > 0)
{
if (numChildren > 0)
{
// In C++20, operator-- on variables with volateile qualifier is deprecated.
size_t n = numChildren - 1;
numChildren = n;
}
}
}
#endif
/* helper macro for converting stream output to a string */
#define CONVERT_TO_STRING(output, string) \
optStream.str(""); \
optStream.clear(); \
optStream << output << OFStringStream_ends; \
OFSTRINGSTREAM_GETOFSTRING(optStream, string)
#define SHORTCOL 4
#define LONGCOL 21
int main(int argc, char *argv[])
{
T_ASC_Network *net;
DcmAssociationConfiguration asccfg;
DcmTLSOptions tlsOptions(NET_ACCEPTOR);
OFStandard::initializeNetwork();
#ifdef WITH_OPENSSL
DcmTLSTransportLayer::initializeOpenSSL();
#endif
OFString temp_str;
OFOStringStream optStream;
OFConsoleApplication app(OFFIS_CONSOLE_APPLICATION, "DICOM storage (C-STORE) SCP", rcsid);
OFCommandLine cmd;
cmd.setParamColumn(LONGCOL + SHORTCOL + 4);
cmd.addParam("port", "tcp/ip port number to listen on", OFCmdParam::PM_Optional);
cmd.setOptionColumns(LONGCOL, SHORTCOL);
cmd.addGroup("general options:", LONGCOL, SHORTCOL + 2);
cmd.addOption("--help", "-h", "print this help text and exit", OFCommandLine::AF_Exclusive);
cmd.addOption("--version", "print version information and exit", OFCommandLine::AF_Exclusive);
OFLog::addOptions(cmd);
cmd.addOption("--verbose-pc", "+v", "show presentation contexts in verbose mode");
#if defined(HAVE_FORK) || defined(_WIN32)
cmd.addGroup("multi-process options:", LONGCOL, SHORTCOL + 2);
cmd.addOption("--single-process", "single process mode (default)");
cmd.addOption("--fork", "fork child process for each association");
#ifdef _WIN32
cmd.addOption("--forked-child", "process is forked child, internal use only", OFCommandLine::AF_Internal);
#endif
cmd.addOption("--max-associations", 1, "[m]ax: integer (default: unlimited)", "limit number of parallel associations to m");
#endif
cmd.addGroup("network options:");
cmd.addSubGroup("IP protocol version:");
cmd.addOption("--ipv4", "-i4", "use IPv4 only (default)");
cmd.addOption("--ipv6", "-i6", "use IPv6 only");
cmd.addOption("--ip-auto", "-i0", "use IPv6/IPv4 dual stack");
cmd.addSubGroup("association negotiation profile from configuration file:");
cmd.addOption("--config-file", "-xf", 2, "[f]ilename, [p]rofile: string",
"use profile p from config file f");
cmd.addSubGroup("preferred network transfer syntaxes (not with --config-file):");
cmd.addOption("--prefer-uncompr", "+x=", "prefer explicit VR local byte order (default)");
cmd.addOption("--prefer-little", "+xe", "prefer explicit VR little endian TS");
cmd.addOption("--prefer-big", "+xb", "prefer explicit VR big endian TS");
cmd.addOption("--prefer-lossless", "+xs", "prefer default JPEG lossless TS");
cmd.addOption("--prefer-jpeg8", "+xy", "prefer default JPEG lossy TS for 8 bit data");
cmd.addOption("--prefer-jpeg12", "+xx", "prefer default JPEG lossy TS for 12 bit data");
cmd.addOption("--prefer-j2k-lossless", "+xv", "prefer JPEG 2000 lossless TS");
cmd.addOption("--prefer-j2k-lossy", "+xw", "prefer JPEG 2000 lossy TS");
cmd.addOption("--prefer-jls-lossless", "+xt", "prefer JPEG-LS lossless TS");
cmd.addOption("--prefer-jls-lossy", "+xu", "prefer JPEG-LS lossy TS");
cmd.addOption("--prefer-mpeg2", "+xm", "prefer MPEG2 Main Profile @ Main Level TS");
cmd.addOption("--prefer-mpeg2-high", "+xh", "prefer MPEG2 Main Profile @ High Level TS");
cmd.addOption("--prefer-mpeg4", "+xn", "prefer MPEG4 AVC/H.264 HP / Level 4.1 TS");
cmd.addOption("--prefer-mpeg4-bd", "+xl", "prefer MPEG4 AVC/H.264 BD-compatible TS");
cmd.addOption("--prefer-mpeg4-2-2d", "+x2", "prefer MPEG4 AVC/H.264 HP / Level 4.2 TS (2D)");
cmd.addOption("--prefer-mpeg4-2-3d", "+x3", "prefer MPEG4 AVC/H.264 HP / Level 4.2 TS (3D)");
cmd.addOption("--prefer-mpeg4-2-st", "+xo", "prefer MPEG4 AVC/H.264 Stereo HP / Level 4.2 TS");
cmd.addOption("--prefer-hevc", "+x4", "prefer HEVC/H.265 Main Profile / Level 5.1 TS");
cmd.addOption("--prefer-hevc10", "+x5", "prefer HEVC/H.265 Main 10 Profile / L5.1 TS");
cmd.addOption("--prefer-rle", "+xr", "prefer RLE lossless TS");
#ifdef WITH_ZLIB
cmd.addOption("--prefer-deflated", "+xd", "prefer deflated expl. VR little endian TS");
#endif
cmd.addOption("--implicit", "+xi", "accept implicit VR little endian TS only");
cmd.addOption("--accept-all", "+xa", "accept all supported transfer syntaxes");
#ifdef WITH_TCPWRAPPER
cmd.addSubGroup("network host access control (tcp wrapper):");
cmd.addOption("--access-full", "-ac", "accept connections from any host (default)");
cmd.addOption("--access-control", "+ac", "enforce host access control rules");
#endif
cmd.addSubGroup("other network options:");
#ifdef INETD_AVAILABLE
// this option is only offered on Posix platforms
cmd.addOption("--inetd", "-id", "run from inetd super server (not with --fork)");
#endif
CONVERT_TO_STRING("[s]econds: integer (default: " << opt_socket_timeout << ")", optString1);
cmd.addOption("--socket-timeout", "-ts", 1, optString1.c_str(), "timeout for network socket (0 for none)");
CONVERT_TO_STRING("[s]econds: integer (default: " << opt_acse_timeout << ")", optString2);
cmd.addOption("--acse-timeout", "-ta", 1, optString2.c_str(), "timeout for ACSE messages");
cmd.addOption("--dimse-timeout", "-td", 1, "[s]econds: integer (default: unlimited)", "timeout for DIMSE messages");
cmd.addOption("--aetitle", "-aet", 1, "[a]etitle: string", "set my AE title (default: " APPLICATIONTITLE ")");
CONVERT_TO_STRING("[n]umber of bytes: integer (" << ASC_MINIMUMPDUSIZE << ".." << ASC_MAXIMUMPDUSIZE << ")", optString3);
CONVERT_TO_STRING("set max receive pdu to n bytes (default: " << opt_maxPDU << ")", optString4);
cmd.addOption("--max-pdu", "-pdu", 1, optString3.c_str(), optString4.c_str());
cmd.addOption("--disable-host-lookup", "-dhl", "disable hostname lookup");
cmd.addOption("--refuse", "refuse association");
cmd.addOption("--reject", "reject association if no implement. class UID");
cmd.addOption("--ignore", "ignore store data, receive but do not store");
cmd.addOption("--sleep-after", 1, "[s]econds: integer",
"sleep s seconds after store (default: 0)");
cmd.addOption("--sleep-during", 1, "[s]econds: integer",
"sleep s seconds during store (default: 0)");
cmd.addOption("--abort-after", "abort association after receipt of C-STORE-RQ\n(but before sending response)");
cmd.addOption("--abort-during", "abort association during receipt of C-STORE-RQ");
cmd.addOption("--promiscuous", "-pm", "promiscuous mode, accept unknown SOP classes\n(not with --config-file)");
cmd.addOption("--uid-padding", "-up", "silently correct space-padded UIDs");
// add TLS specific command line options if (and only if) we are compiling with OpenSSL
tlsOptions.addTLSCommandlineOptions(cmd);
cmd.addGroup("output options:");
cmd.addSubGroup("general:");
cmd.addOption("--output-directory", "-od", 1, "[d]irectory: string (default: \".\")", "write received objects to existing directory d");
cmd.addSubGroup("bit preserving mode:");
cmd.addOption("--normal", "-B", "allow implicit format conversions (default)");
cmd.addOption("--bit-preserving", "+B", "write data exactly as read");
cmd.addSubGroup("output file format:");
cmd.addOption("--write-file", "+F", "write file format (default)");
cmd.addOption("--write-dataset", "-F", "write data set without file meta information");
cmd.addSubGroup("output transfer syntax (not with --bit-preserving or compressed transmission):");
cmd.addOption("--write-xfer-same", "+t=", "write with same TS as input (default)");
cmd.addOption("--write-xfer-little", "+te", "write with explicit VR little endian TS");
cmd.addOption("--write-xfer-big", "+tb", "write with explicit VR big endian TS");
cmd.addOption("--write-xfer-implicit", "+ti", "write with implicit VR little endian TS");
#ifdef WITH_ZLIB
cmd.addOption("--write-xfer-deflated", "+td", "write with deflated expl. VR little endian TS");
#endif
cmd.addSubGroup("post-1993 value representations (not with --bit-preserving):");
cmd.addOption("--enable-new-vr", "+u", "enable support for new VRs (UN/UT) (default)");
cmd.addOption("--disable-new-vr", "-u", "disable support for new VRs, convert to OB");
cmd.addSubGroup("group length encoding (not with --bit-preserving):");
cmd.addOption("--group-length-recalc", "+g=", "recalculate group lengths if present (default)");
cmd.addOption("--group-length-create", "+g", "always write with group length elements");
cmd.addOption("--group-length-remove", "-g", "always write without group length elements");
cmd.addSubGroup("length encoding in sequences and items (not with --bit-preserving):");
cmd.addOption("--length-explicit", "+e", "write with explicit lengths (default)");
cmd.addOption("--length-undefined", "-e", "write with undefined lengths");
cmd.addSubGroup("data set trailing padding (not with --write-dataset or --bit-preserving):");
cmd.addOption("--padding-off", "-p", "no padding (default)");
cmd.addOption("--padding-create", "+p", 2, "[f]ile-pad [i]tem-pad: integer",
"align file on multiple of f bytes and items\non multiple of i bytes");
cmd.addSubGroup("handling of defined length UN elements:");
cmd.addOption("--retain-un", "-uc", "retain elements as UN (default)");
cmd.addOption("--convert-un", "+uc", "convert to real VR if known");
#ifdef WITH_ZLIB
cmd.addSubGroup("deflate compression level (only with --write-xfer-deflated/same):");
cmd.addOption("--compression-level", "+cl", 1, "[l]evel: integer (default: 6)",
"0=uncompressed, 1=fastest, 9=best compression");
#endif
cmd.addSubGroup("sorting into subdirectories (not with --bit-preserving):");
cmd.addOption("--sort-conc-studies", "-ss", 1, "[p]refix: string",
"sort studies using prefix p and a timestamp");
cmd.addOption("--sort-on-study-uid", "-su", 1, "[p]refix: string",
"sort studies using prefix p and the Study\nInstance UID");
cmd.addOption("--sort-on-patientname", "-sp", "sort studies using the Patient's Name and\na timestamp");
cmd.addSubGroup("filename generation:");
cmd.addOption("--default-filenames", "-uf", "generate filename from instance UID (default)");
cmd.addOption("--unique-filenames", "+uf", "generate unique filenames");
cmd.addOption("--timenames", "-tn", "generate filename from creation time");
cmd.addOption("--filename-extension", "-fe", 1, "[e]xtension: string",
"append e to all filenames");
cmd.addGroup("event options:", LONGCOL, SHORTCOL + 2);
cmd.addOption("--exec-on-reception", "-xcr", 1, "[c]ommand: string",
"execute command c after having received and\nprocessed one C-STORE-RQ message");
cmd.addOption("--exec-on-eostudy", "-xcs", 1, "[c]ommand: string",
"execute command c after having received and\nprocessed all C-STORE-RQ messages that belong\nto one study");
cmd.addOption("--rename-on-eostudy", "-rns", "having received and processed all C-STORE-RQ\nmessages that belong to one study, rename\noutput files according to certain pattern");
cmd.addOption("--eostudy-timeout", "-tos", 1, "[t]imeout: integer",
"specifies a timeout of t seconds for\nend-of-study determination");
cmd.addOption("--exec-sync", "-xs", "execute command synchronously in foreground");
/* evaluate command line */
prepareCmdLineArgs(argc, argv, OFFIS_CONSOLE_APPLICATION);
if (app.parseCommandLine(cmd, argc, argv))
{
/* print help text and exit */
if (cmd.getArgCount() == 0)
app.printUsage();
/* check exclusive options first */
if (cmd.hasExclusiveOption())
{
if (cmd.findOption("--version"))
{
app.printHeader(OFTrue /*print host identifier*/);
COUT << OFendl << "External libraries used:";
#if !defined(WITH_ZLIB) && !defined(WITH_OPENSSL) && !defined(WITH_TCPWRAPPER)
COUT << " none" << OFendl;
#else
COUT << OFendl;
#endif
#ifdef WITH_ZLIB
COUT << "- ZLIB, Version " << zlibVersion() << OFendl;
#endif
// print OpenSSL version if (and only if) we are compiling with OpenSSL
tlsOptions.printLibraryVersion();
#ifdef WITH_TCPWRAPPER
COUT << "- LIBWRAP" << OFendl;
#endif
return 0;
}
// check if the command line contains the --list-ciphers option
if (tlsOptions.listOfCiphersRequested(cmd))
{
tlsOptions.printSupportedCiphersuites(app, COUT);
return 0;
}
// check if the command line contains the --list-profiles option
if (tlsOptions.listOfProfilesRequested(cmd))
{
tlsOptions.printSupportedTLSProfiles(app, COUT);
return 0;
}
}
#ifdef INETD_AVAILABLE
if (cmd.findOption("--inetd"))
{
opt_inetd_mode = OFTrue;
opt_forkMode = OFFalse;
if (cmd.findOption("--fork"))
{
app.checkConflict("--inetd", "--fork", opt_inetd_mode);
}
if (cmd.findOption("--max-associations"))
{
app.checkDependence("--max-associations", "--fork", opt_forkMode);
}
// duplicate stdin, which is the socket passed by inetd
int inetd_fd = dup(0);
if (inetd_fd < 0) exit(99);
close(0); // close stdin
close(1); // close stdout
close(2); // close stderr
// open new file descriptor for stdin
int fd = open("/dev/null", O_RDONLY);
if (fd != 0) exit(99);
// create new file descriptor for stdout
fd = open("/dev/null", O_WRONLY);
if (fd != 1) exit(99);
// create new file descriptor for stderr
fd = open("/dev/null", O_WRONLY);
if (fd != 2) exit(99);
dcmExternalSocketHandle.set(inetd_fd);
// the port number is not really used. Set to non-privileged port number
// to avoid failing the privilege test.
opt_port = 1024;
}
#endif
#if defined(HAVE_FORK) || defined(_WIN32)
cmd.beginOptionBlock();
if (cmd.findOption("--single-process"))
opt_forkMode = OFFalse;
if (cmd.findOption("--fork"))
{
opt_forkMode = OFTrue;
}
cmd.endOptionBlock();
#ifdef _WIN32
if (cmd.findOption("--forked-child")) opt_forkedChild = OFTrue;
#endif
if (cmd.findOption("--max-associations"))
{
app.checkDependence("--max-associations", "--fork", opt_forkMode);
app.checkValue(cmd.getValueAndCheckMin(opt_maxChildren, 1));
}
#endif
if (opt_inetd_mode)
{
// port number is not required in inetd mode
if (cmd.getParamCount() > 0)
OFLOG_WARN(storescpLogger, "Parameter port not required in inetd mode");
} else {
// omitting the port number is only allowed in inetd mode
if (cmd.getParamCount() == 0)
app.printError("Missing parameter port");
else
app.checkParam(cmd.getParamAndCheckMinMax(1, opt_port, 1, 65535));
}
OFLog::configureFromCommandLine(cmd, app);
if (cmd.findOption("--verbose-pc"))
{
app.checkDependence("--verbose-pc", "verbose mode", storescpLogger.isEnabledFor(OFLogger::INFO_LOG_LEVEL));
opt_showPresentationContexts = OFTrue;
}
cmd.beginOptionBlock();
if (cmd.findOption("--prefer-uncompr"))
{
opt_acceptAllXfers = OFFalse;
opt_networkTransferSyntax = EXS_Unknown;
}
if (cmd.findOption("--prefer-little")) opt_networkTransferSyntax = EXS_LittleEndianExplicit;
if (cmd.findOption("--prefer-big")) opt_networkTransferSyntax = EXS_BigEndianExplicit;
if (cmd.findOption("--prefer-lossless")) opt_networkTransferSyntax = EXS_JPEGProcess14SV1;
if (cmd.findOption("--prefer-jpeg8")) opt_networkTransferSyntax = EXS_JPEGProcess1;
if (cmd.findOption("--prefer-jpeg12")) opt_networkTransferSyntax = EXS_JPEGProcess2_4;
if (cmd.findOption("--prefer-j2k-lossless")) opt_networkTransferSyntax = EXS_JPEG2000LosslessOnly;
if (cmd.findOption("--prefer-j2k-lossy")) opt_networkTransferSyntax = EXS_JPEG2000;
if (cmd.findOption("--prefer-jls-lossless")) opt_networkTransferSyntax = EXS_JPEGLSLossless;
if (cmd.findOption("--prefer-jls-lossy")) opt_networkTransferSyntax = EXS_JPEGLSLossy;
if (cmd.findOption("--prefer-mpeg2")) opt_networkTransferSyntax = EXS_MPEG2MainProfileAtMainLevel;
if (cmd.findOption("--prefer-mpeg2-high")) opt_networkTransferSyntax = EXS_MPEG2MainProfileAtHighLevel;
if (cmd.findOption("--prefer-mpeg4")) opt_networkTransferSyntax = EXS_MPEG4HighProfileLevel4_1;
if (cmd.findOption("--prefer-mpeg4-bd")) opt_networkTransferSyntax = EXS_MPEG4BDcompatibleHighProfileLevel4_1;
if (cmd.findOption("--prefer-mpeg4-2-2d")) opt_networkTransferSyntax = EXS_MPEG4HighProfileLevel4_2_For2DVideo;
if (cmd.findOption("--prefer-mpeg4-2-3d")) opt_networkTransferSyntax = EXS_MPEG4HighProfileLevel4_2_For3DVideo;
if (cmd.findOption("--prefer-mpeg4-2-st")) opt_networkTransferSyntax = EXS_MPEG4StereoHighProfileLevel4_2;
if (cmd.findOption("--prefer-hevc")) opt_networkTransferSyntax = EXS_HEVCMainProfileLevel5_1;
if (cmd.findOption("--prefer-hevc10")) opt_networkTransferSyntax = EXS_HEVCMain10ProfileLevel5_1;
if (cmd.findOption("--prefer-rle")) opt_networkTransferSyntax = EXS_RLELossless;
#ifdef WITH_ZLIB
if (cmd.findOption("--prefer-deflated")) opt_networkTransferSyntax = EXS_DeflatedLittleEndianExplicit;
#endif
if (cmd.findOption("--implicit")) opt_networkTransferSyntax = EXS_LittleEndianImplicit;
if (cmd.findOption("--accept-all"))
{
opt_acceptAllXfers = OFTrue;
opt_networkTransferSyntax = EXS_Unknown;
}
cmd.endOptionBlock();
if (opt_networkTransferSyntax != EXS_Unknown) opt_acceptAllXfers = OFFalse;
if (cmd.findOption("--socket-timeout"))
app.checkValue(cmd.getValueAndCheckMin(opt_socket_timeout, -1));
// always set the timeout values since the global default might be different
dcmSocketSendTimeout.set(OFstatic_cast(Sint32, opt_socket_timeout));
dcmSocketReceiveTimeout.set(OFstatic_cast(Sint32, opt_socket_timeout));
if (cmd.findOption("--acse-timeout"))
{
OFCmdSignedInt opt_timeout = 0;
app.checkValue(cmd.getValueAndCheckMin(opt_timeout, 1));
opt_acse_timeout = OFstatic_cast(int, opt_timeout);
}
if (cmd.findOption("--dimse-timeout"))
{
OFCmdSignedInt opt_timeout = 0;
app.checkValue(cmd.getValueAndCheckMin(opt_timeout, 1));
opt_dimse_timeout = OFstatic_cast(int, opt_timeout);
opt_blockMode = DIMSE_NONBLOCKING;
}
if (cmd.findOption("--aetitle")) app.checkValue(cmd.getValue(opt_respondingAETitle));
if (cmd.findOption("--max-pdu")) app.checkValue(cmd.getValueAndCheckMinMax(opt_maxPDU, ASC_MINIMUMPDUSIZE, ASC_MAXIMUMPDUSIZE));
if (cmd.findOption("--disable-host-lookup")) dcmDisableGethostbyaddr.set(OFTrue);
if (cmd.findOption("--refuse")) opt_refuseAssociation = OFTrue;
if (cmd.findOption("--reject")) opt_rejectWithoutImplementationUID = OFTrue;
if (cmd.findOption("--ignore")) opt_ignore = OFTrue;
if (cmd.findOption("--sleep-after")) app.checkValue(cmd.getValueAndCheckMin(opt_sleepAfter, 0));
if (cmd.findOption("--sleep-during")) app.checkValue(cmd.getValueAndCheckMin(opt_sleepDuring, 0));
if (cmd.findOption("--abort-after")) opt_abortAfterStore = OFTrue;
if (cmd.findOption("--abort-during")) opt_abortDuringStore = OFTrue;
if (cmd.findOption("--promiscuous")) opt_promiscuous = OFTrue;
if (cmd.findOption("--uid-padding")) opt_correctUIDPadding = OFTrue;
// set the IP protocol version
cmd.beginOptionBlock();
if (cmd.findOption("--ipv4")) dcmIncomingProtocolFamily.set(ASC_AF_INET);
if (cmd.findOption("--ipv6")) dcmIncomingProtocolFamily.set(ASC_AF_INET6);
if (cmd.findOption("--ip-auto")) dcmIncomingProtocolFamily.set(ASC_AF_UNSPEC);
cmd.endOptionBlock();
if (cmd.findOption("--config-file"))
{
// check conflicts with other command line options
app.checkConflict("--config-file", "--prefer-little", opt_networkTransferSyntax == EXS_LittleEndianExplicit);
app.checkConflict("--config-file", "--prefer-big", opt_networkTransferSyntax == EXS_BigEndianExplicit);
app.checkConflict("--config-file", "--prefer-lossless", opt_networkTransferSyntax == EXS_JPEGProcess14SV1);
app.checkConflict("--config-file", "--prefer-jpeg8", opt_networkTransferSyntax == EXS_JPEGProcess1);
app.checkConflict("--config-file", "--prefer-jpeg12", opt_networkTransferSyntax == EXS_JPEGProcess2_4);
app.checkConflict("--config-file", "--prefer-j2k-lossless", opt_networkTransferSyntax == EXS_JPEG2000LosslessOnly);
app.checkConflict("--config-file", "--prefer-j2k-lossy", opt_networkTransferSyntax == EXS_JPEG2000);
app.checkConflict("--config-file", "--prefer-jls-lossless", opt_networkTransferSyntax == EXS_JPEGLSLossless);
app.checkConflict("--config-file", "--prefer-jls-lossy", opt_networkTransferSyntax == EXS_JPEGLSLossy);
app.checkConflict("--config-file", "--prefer-mpeg2", opt_networkTransferSyntax == EXS_MPEG2MainProfileAtMainLevel);
app.checkConflict("--config-file", "--prefer-mpeg2-high", opt_networkTransferSyntax == EXS_MPEG2MainProfileAtHighLevel);
app.checkConflict("--config-file", "--prefer-mpeg4", opt_networkTransferSyntax == EXS_MPEG4HighProfileLevel4_1);
app.checkConflict("--config-file", "--prefer-mpeg4-bd", opt_networkTransferSyntax == EXS_MPEG4BDcompatibleHighProfileLevel4_1);
app.checkConflict("--config-file", "--prefer-mpeg4-2-2d", opt_networkTransferSyntax == EXS_MPEG4HighProfileLevel4_2_For2DVideo);
app.checkConflict("--config-file", "--prefer-mpeg4-2-3d", opt_networkTransferSyntax == EXS_MPEG4HighProfileLevel4_2_For3DVideo);
app.checkConflict("--config-file", "--prefer-mpeg4-2-st", opt_networkTransferSyntax == EXS_MPEG4StereoHighProfileLevel4_2);
app.checkConflict("--config-file", "--prefer-hevc", opt_networkTransferSyntax == EXS_HEVCMainProfileLevel5_1);
app.checkConflict("--config-file", "--prefer-hevc10", opt_networkTransferSyntax == EXS_HEVCMain10ProfileLevel5_1);
app.checkConflict("--config-file", "--prefer-rle", opt_networkTransferSyntax == EXS_RLELossless);
#ifdef WITH_ZLIB
app.checkConflict("--config-file", "--prefer-deflated", opt_networkTransferSyntax == EXS_DeflatedLittleEndianExplicit);
#endif
app.checkConflict("--config-file", "--implicit", opt_networkTransferSyntax == EXS_LittleEndianImplicit);
app.checkConflict("--config-file", "--accept-all", opt_acceptAllXfers);
app.checkConflict("--config-file", "--promiscuous", opt_promiscuous);
app.checkValue(cmd.getValue(opt_configFile));
app.checkValue(cmd.getValue(opt_profileName));
// read configuration file
OFCondition cond = DcmAssociationConfigurationFile::initialize(asccfg, opt_configFile, OFFalse);
if (cond.bad())
{
OFLOG_FATAL(storescpLogger, "cannot read config file: " << cond.text());
return 1;
}
/* perform name mangling for config file key */
OFString sprofile;
const unsigned char *c = OFreinterpret_cast(const unsigned char *, opt_profileName);
while (*c)
{
if (! OFStandard::isspace(*c)) sprofile += OFstatic_cast(char, toupper(*c));
++c;
}
if (!asccfg.isKnownProfile(sprofile.c_str()))
{
OFLOG_FATAL(storescpLogger, "unknown configuration profile name: " << sprofile);
return 1;
}
if (!asccfg.isValidSCPProfile(sprofile.c_str()))
{
OFLOG_FATAL(storescpLogger, "profile '" << sprofile << "' is not valid for SCP use, duplicate abstract syntaxes found");
return 1;
}
}
#ifdef WITH_TCPWRAPPER
cmd.beginOptionBlock();
if (cmd.findOption("--access-full")) dcmTCPWrapperDaemonName.set(NULL);
if (cmd.findOption("--access-control")) dcmTCPWrapperDaemonName.set(OFFIS_CONSOLE_APPLICATION);
cmd.endOptionBlock();
#endif
if (cmd.findOption("--output-directory")) app.checkValue(cmd.getValue(opt_outputDirectory));
cmd.beginOptionBlock();
if (cmd.findOption("--normal")) opt_bitPreserving = OFFalse;
if (cmd.findOption("--bit-preserving")) opt_bitPreserving = OFTrue;
cmd.endOptionBlock();
cmd.beginOptionBlock();
if (cmd.findOption("--write-file")) opt_useMetaheader = OFTrue;
if (cmd.findOption("--write-dataset")) opt_useMetaheader = OFFalse;
cmd.endOptionBlock();
cmd.beginOptionBlock();
if (cmd.findOption("--write-xfer-same")) opt_writeTransferSyntax = EXS_Unknown;
if (cmd.findOption("--write-xfer-little"))
{
app.checkConflict("--write-xfer-little", "--accept-all", opt_acceptAllXfers);
app.checkConflict("--write-xfer-little", "--bit-preserving", opt_bitPreserving);
app.checkConflict("--write-xfer-little", "--prefer-lossless", opt_networkTransferSyntax == EXS_JPEGProcess14SV1);
app.checkConflict("--write-xfer-little", "--prefer-jpeg8", opt_networkTransferSyntax == EXS_JPEGProcess1);
app.checkConflict("--write-xfer-little", "--prefer-jpeg12", opt_networkTransferSyntax == EXS_JPEGProcess2_4);
app.checkConflict("--write-xfer-little", "--prefer-j2k-lossless", opt_networkTransferSyntax == EXS_JPEG2000LosslessOnly);
app.checkConflict("--write-xfer-little", "--prefer-j2k-lossy", opt_networkTransferSyntax == EXS_JPEG2000);
app.checkConflict("--write-xfer-little", "--prefer-jls-lossless", opt_networkTransferSyntax == EXS_JPEGLSLossless);
app.checkConflict("--write-xfer-little", "--prefer-jls-lossy", opt_networkTransferSyntax == EXS_JPEGLSLossy);
app.checkConflict("--write-xfer-little", "--prefer-mpeg2", opt_networkTransferSyntax == EXS_MPEG2MainProfileAtMainLevel);
app.checkConflict("--write-xfer-little", "--prefer-mpeg2-high", opt_networkTransferSyntax == EXS_MPEG2MainProfileAtHighLevel);
app.checkConflict("--write-xfer-little", "--prefer-mpeg4", opt_networkTransferSyntax == EXS_MPEG4HighProfileLevel4_1);
app.checkConflict("--write-xfer-little", "--prefer-mpeg4-bd", opt_networkTransferSyntax == EXS_MPEG4BDcompatibleHighProfileLevel4_1);
app.checkConflict("--write-xfer-little", "--prefer-mpeg4-2-2d", opt_networkTransferSyntax == EXS_MPEG4HighProfileLevel4_2_For2DVideo);
app.checkConflict("--write-xfer-little", "--prefer-mpeg4-2-3d", opt_networkTransferSyntax == EXS_MPEG4HighProfileLevel4_2_For3DVideo);
app.checkConflict("--write-xfer-little", "--prefer-mpeg4-2-st", opt_networkTransferSyntax == EXS_MPEG4StereoHighProfileLevel4_2);
app.checkConflict("--write-xfer-little", "--prefer-hevc", opt_networkTransferSyntax == EXS_HEVCMainProfileLevel5_1);
app.checkConflict("--write-xfer-little", "--prefer-hevc10", opt_networkTransferSyntax == EXS_HEVCMain10ProfileLevel5_1);
app.checkConflict("--write-xfer-little", "--prefer-rle", opt_networkTransferSyntax == EXS_RLELossless);
// we don't have to check a conflict for --prefer-deflated because we can always convert that to uncompressed.
opt_writeTransferSyntax = EXS_LittleEndianExplicit;
}
if (cmd.findOption("--write-xfer-big"))
{
app.checkConflict("--write-xfer-big", "--accept-all", opt_acceptAllXfers);
app.checkConflict("--write-xfer-big", "--bit-preserving", opt_bitPreserving);
app.checkConflict("--write-xfer-big", "--prefer-lossless", opt_networkTransferSyntax == EXS_JPEGProcess14SV1);
app.checkConflict("--write-xfer-big", "--prefer-jpeg8", opt_networkTransferSyntax == EXS_JPEGProcess1);
app.checkConflict("--write-xfer-big", "--prefer-jpeg12", opt_networkTransferSyntax == EXS_JPEGProcess2_4);
app.checkConflict("--write-xfer-big", "--prefer-j2k-lossless", opt_networkTransferSyntax == EXS_JPEG2000LosslessOnly);
app.checkConflict("--write-xfer-big", "--prefer-j2k-lossy", opt_networkTransferSyntax == EXS_JPEG2000);
app.checkConflict("--write-xfer-big", "--prefer-jls-lossless", opt_networkTransferSyntax == EXS_JPEGLSLossless);
app.checkConflict("--write-xfer-big", "--prefer-jls-lossy", opt_networkTransferSyntax == EXS_JPEGLSLossy);
app.checkConflict("--write-xfer-big", "--prefer-mpeg2", opt_networkTransferSyntax == EXS_MPEG2MainProfileAtMainLevel);
app.checkConflict("--write-xfer-big", "--prefer-mpeg2-high", opt_networkTransferSyntax == EXS_MPEG2MainProfileAtHighLevel);
app.checkConflict("--write-xfer-big", "--prefer-mpeg4", opt_networkTransferSyntax == EXS_MPEG4HighProfileLevel4_1);
app.checkConflict("--write-xfer-big", "--prefer-mpeg4-bd", opt_networkTransferSyntax == EXS_MPEG4BDcompatibleHighProfileLevel4_1);
app.checkConflict("--write-xfer-big", "--prefer-mpeg4-2-2d", opt_networkTransferSyntax == EXS_MPEG4HighProfileLevel4_2_For2DVideo);
app.checkConflict("--write-xfer-big", "--prefer-mpeg4-2-3d", opt_networkTransferSyntax == EXS_MPEG4HighProfileLevel4_2_For3DVideo);
app.checkConflict("--write-xfer-big", "--prefer-mpeg4-2-st", opt_networkTransferSyntax == EXS_MPEG4StereoHighProfileLevel4_2);
app.checkConflict("--write-xfer-big", "--prefer-hevc", opt_networkTransferSyntax == EXS_HEVCMainProfileLevel5_1);
app.checkConflict("--write-xfer-big", "--prefer-hevc10", opt_networkTransferSyntax == EXS_HEVCMain10ProfileLevel5_1);
app.checkConflict("--write-xfer-big", "--prefer-rle", opt_networkTransferSyntax == EXS_RLELossless);
// we don't have to check a conflict for --prefer-deflated because we can always convert that to uncompressed.
opt_writeTransferSyntax = EXS_BigEndianExplicit;
}
if (cmd.findOption("--write-xfer-implicit"))
{
app.checkConflict("--write-xfer-implicit", "--accept-all", opt_acceptAllXfers);
app.checkConflict("--write-xfer-implicit", "--bit-preserving", opt_bitPreserving);
app.checkConflict("--write-xfer-implicit", "--prefer-lossless", opt_networkTransferSyntax == EXS_JPEGProcess14SV1);
app.checkConflict("--write-xfer-implicit", "--prefer-jpeg8", opt_networkTransferSyntax == EXS_JPEGProcess1);
app.checkConflict("--write-xfer-implicit", "--prefer-jpeg12", opt_networkTransferSyntax == EXS_JPEGProcess2_4);
app.checkConflict("--write-xfer-implicit", "--prefer-j2k-lossless", opt_networkTransferSyntax == EXS_JPEG2000LosslessOnly);
app.checkConflict("--write-xfer-implicit", "--prefer-j2k-lossy", opt_networkTransferSyntax == EXS_JPEG2000);
app.checkConflict("--write-xfer-implicit", "--prefer-jls-lossless", opt_networkTransferSyntax == EXS_JPEGLSLossless);
app.checkConflict("--write-xfer-implicit", "--prefer-jls-lossy", opt_networkTransferSyntax == EXS_JPEGLSLossy);
app.checkConflict("--write-xfer-implicit", "--prefer-mpeg2", opt_networkTransferSyntax == EXS_MPEG2MainProfileAtMainLevel);
app.checkConflict("--write-xfer-implicit", "--prefer-mpeg2-high", opt_networkTransferSyntax == EXS_MPEG2MainProfileAtHighLevel);
app.checkConflict("--write-xfer-implicit", "--prefer-mpeg4", opt_networkTransferSyntax == EXS_MPEG4HighProfileLevel4_1);
app.checkConflict("--write-xfer-implicit", "--prefer-mpeg4-bd", opt_networkTransferSyntax == EXS_MPEG4BDcompatibleHighProfileLevel4_1);
app.checkConflict("--write-xfer-implicit", "--prefer-mpeg4-2-2d", opt_networkTransferSyntax == EXS_MPEG4HighProfileLevel4_2_For2DVideo);
app.checkConflict("--write-xfer-implicit", "--prefer-mpeg4-2-3d", opt_networkTransferSyntax == EXS_MPEG4HighProfileLevel4_2_For3DVideo);
app.checkConflict("--write-xfer-implicit", "--prefer-mpeg4-2-st", opt_networkTransferSyntax == EXS_MPEG4StereoHighProfileLevel4_2);
app.checkConflict("--write-xfer-implicit", "--prefer-hevc", opt_networkTransferSyntax == EXS_HEVCMainProfileLevel5_1);
app.checkConflict("--write-xfer-implicit", "--prefer-hevc10", opt_networkTransferSyntax == EXS_HEVCMain10ProfileLevel5_1);
app.checkConflict("--write-xfer-implicit", "--prefer-rle", opt_networkTransferSyntax == EXS_RLELossless);
// we don't have to check a conflict for --prefer-deflated because we can always convert that to uncompressed.
opt_writeTransferSyntax = EXS_LittleEndianImplicit;
}
#ifdef WITH_ZLIB
if (cmd.findOption("--write-xfer-deflated"))
{
app.checkConflict("--write-xfer-deflated", "--accept-all", opt_acceptAllXfers);
app.checkConflict("--write-xfer-deflated", "--bit-preserving", opt_bitPreserving);
app.checkConflict("--write-xfer-deflated", "--prefer-lossless", opt_networkTransferSyntax == EXS_JPEGProcess14SV1);
app.checkConflict("--write-xfer-deflated", "--prefer-jpeg8", opt_networkTransferSyntax == EXS_JPEGProcess1);
app.checkConflict("--write-xfer-deflated", "--prefer-jpeg12", opt_networkTransferSyntax == EXS_JPEGProcess2_4);
app.checkConflict("--write-xfer-deflated", "--prefer-j2k-lossless", opt_networkTransferSyntax == EXS_JPEG2000LosslessOnly);
app.checkConflict("--write-xfer-deflated", "--prefer-j2k-lossy", opt_networkTransferSyntax == EXS_JPEG2000);
app.checkConflict("--write-xfer-deflated", "--prefer-jls-lossless", opt_networkTransferSyntax == EXS_JPEGLSLossless);
app.checkConflict("--write-xfer-deflated", "--prefer-jls-lossy", opt_networkTransferSyntax == EXS_JPEGLSLossy);
app.checkConflict("--write-xfer-deflated", "--prefer-mpeg2", opt_networkTransferSyntax == EXS_MPEG2MainProfileAtMainLevel);
app.checkConflict("--write-xfer-deflated", "--prefer-mpeg2-high", opt_networkTransferSyntax == EXS_MPEG2MainProfileAtHighLevel);
app.checkConflict("--write-xfer-deflated", "--prefer-mpeg4", opt_networkTransferSyntax == EXS_MPEG4HighProfileLevel4_1);
app.checkConflict("--write-xfer-deflated", "--prefer-mpeg4-bd", opt_networkTransferSyntax == EXS_MPEG4BDcompatibleHighProfileLevel4_1);
app.checkConflict("--write-xfer-deflated", "--prefer-mpeg4-2-2d", opt_networkTransferSyntax == EXS_MPEG4HighProfileLevel4_2_For2DVideo);
app.checkConflict("--write-xfer-deflated", "--prefer-mpeg4-2-3d", opt_networkTransferSyntax == EXS_MPEG4HighProfileLevel4_2_For3DVideo);
app.checkConflict("--write-xfer-deflated", "--prefer-mpeg4-2-st", opt_networkTransferSyntax == EXS_MPEG4StereoHighProfileLevel4_2);
app.checkConflict("--write-xfer-deflated", "--prefer-hevc", opt_networkTransferSyntax == EXS_HEVCMainProfileLevel5_1);
app.checkConflict("--write-xfer-deflated", "--prefer-hevc10", opt_networkTransferSyntax == EXS_HEVCMain10ProfileLevel5_1);
app.checkConflict("--write-xfer-deflated", "--prefer-rle", opt_networkTransferSyntax == EXS_RLELossless);
opt_writeTransferSyntax = EXS_DeflatedLittleEndianExplicit;
}
#endif
cmd.endOptionBlock();
cmd.beginOptionBlock();
if (cmd.findOption("--enable-new-vr"))
{
app.checkConflict("--enable-new-vr", "--bit-preserving", opt_bitPreserving);
dcmEnableGenerationOfNewVRs();
}
if (cmd.findOption("--disable-new-vr"))
{
app.checkConflict("--disable-new-vr", "--bit-preserving", opt_bitPreserving);
dcmDisableGenerationOfNewVRs();
}
cmd.endOptionBlock();
cmd.beginOptionBlock();
if (cmd.findOption("--group-length-recalc"))
{
app.checkConflict("--group-length-recalc", "--bit-preserving", opt_bitPreserving);
opt_groupLength = EGL_recalcGL;
}
if (cmd.findOption("--group-length-create"))
{
app.checkConflict("--group-length-create", "--bit-preserving", opt_bitPreserving);
opt_groupLength = EGL_withGL;
}
if (cmd.findOption("--group-length-remove"))
{
app.checkConflict("--group-length-remove", "--bit-preserving", opt_bitPreserving);
opt_groupLength = EGL_withoutGL;
}
cmd.endOptionBlock();
cmd.beginOptionBlock();
if (cmd.findOption("--length-explicit"))
{
app.checkConflict("--length-explicit", "--bit-preserving", opt_bitPreserving);
opt_sequenceType = EET_ExplicitLength;
}
if (cmd.findOption("--length-undefined"))
{
app.checkConflict("--length-undefined", "--bit-preserving", opt_bitPreserving);
opt_sequenceType = EET_UndefinedLength;
}
cmd.endOptionBlock();
cmd.beginOptionBlock();
if (cmd.findOption("--padding-off")) opt_paddingType = EPD_withoutPadding;
if (cmd.findOption("--padding-create"))
{
app.checkConflict("--padding-create", "--write-dataset", !opt_useMetaheader);
app.checkConflict("--padding-create", "--bit-preserving", opt_bitPreserving);
app.checkValue(cmd.getValueAndCheckMin(opt_filepad, 0));
app.checkValue(cmd.getValueAndCheckMin(opt_itempad, 0));
opt_paddingType = EPD_withPadding;
}
cmd.endOptionBlock();
cmd.beginOptionBlock();
if (cmd.findOption("--retain-un")) dcmEnableUnknownVRConversion.set(OFFalse);
if (cmd.findOption("--convert-un")) dcmEnableUnknownVRConversion.set(OFTrue);
cmd.endOptionBlock();
#ifdef WITH_ZLIB
if (cmd.findOption("--compression-level"))
{
app.checkDependence("--compression-level", "--write-xfer-deflated or --write-xfer-same",
(opt_writeTransferSyntax == EXS_DeflatedLittleEndianExplicit) || (opt_writeTransferSyntax == EXS_Unknown));
app.checkValue(cmd.getValueAndCheckMinMax(opt_compressionLevel, 0, 9));
dcmZlibCompressionLevel.set(OFstatic_cast(int, opt_compressionLevel));
}
#endif
cmd.beginOptionBlock();
if (cmd.findOption("--sort-conc-studies"))
{
app.checkConflict("--sort-conc-studies", "--bit-preserving", opt_bitPreserving);
app.checkValue(cmd.getValue(opt_sortStudyDirPrefix));
opt_sortStudyMode = ESM_Timestamp;
}
if (cmd.findOption("--sort-on-study-uid"))
{
app.checkConflict("--sort-on-study-uid", "--bit-preserving", opt_bitPreserving);
app.checkValue(cmd.getValue(opt_sortStudyDirPrefix));
opt_sortStudyMode = ESM_StudyInstanceUID;
}
if (cmd.findOption("--sort-on-patientname"))
{
app.checkConflict("--sort-on-patientname", "--bit-preserving", opt_bitPreserving);
opt_sortStudyDirPrefix = NULL;
opt_sortStudyMode = ESM_PatientName;
}
cmd.endOptionBlock();
cmd.beginOptionBlock();
if (cmd.findOption("--default-filenames")) opt_uniqueFilenames = OFFalse;
if (cmd.findOption("--unique-filenames")) opt_uniqueFilenames = OFTrue;
cmd.endOptionBlock();
if (cmd.findOption("--timenames")) opt_timeNames = OFTrue;
if (cmd.findOption("--filename-extension"))
app.checkValue(cmd.getValue(opt_fileNameExtension));
if (cmd.findOption("--timenames"))
app.checkConflict("--timenames", "--unique-filenames", opt_uniqueFilenames);
if (cmd.findOption("--exec-on-reception")) app.checkValue(cmd.getValue(opt_execOnReception));
if (cmd.findOption("--exec-on-eostudy"))
{
app.checkConflict("--exec-on-eostudy", "--fork", opt_forkMode);
app.checkConflict("--exec-on-eostudy", "--inetd", opt_inetd_mode);
app.checkDependence("--exec-on-eostudy", "--sort-conc-studies, --sort-on-study-uid or --sort-on-patientname", opt_sortStudyMode != ESM_None );
app.checkValue(cmd.getValue(opt_execOnEndOfStudy));
}
if (cmd.findOption("--rename-on-eostudy"))
{
app.checkConflict("--rename-on-eostudy", "--fork", opt_forkMode);
app.checkConflict("--rename-on-eostudy", "--inetd", opt_inetd_mode);
app.checkDependence("--rename-on-eostudy", "--sort-conc-studies, --sort-on-study-uid or --sort-on-patientname", opt_sortStudyMode != ESM_None );
opt_renameOnEndOfStudy = OFTrue;
}
if (cmd.findOption("--eostudy-timeout"))
{
app.checkDependence("--eostudy-timeout", "--sort-conc-studies, --sort-on-study-uid, --sort-on-patientname, --exec-on-eostudy or --rename-on-eostudy",
(opt_sortStudyMode != ESM_None) || (opt_execOnEndOfStudy != NULL) || opt_renameOnEndOfStudy);
app.checkValue(cmd.getValueAndCheckMin(opt_endOfStudyTimeout, 0));
}
if (cmd.findOption("--exec-sync")) opt_execSync = OFTrue;
}
/* print resource identifier */
OFLOG_DEBUG(storescpLogger, rcsid << OFendl);
// evaluate (most of) the TLS command line options (if we are compiling with OpenSSL)
tlsOptions.parseArguments(app, cmd);
#ifndef DISABLE_PORT_PERMISSION_CHECK
#ifdef HAVE_GETEUID
/* if port is privileged we must be as well */
if (opt_port < 1024)
{
if (geteuid() != 0)
{
OFLOG_FATAL(storescpLogger, "cannot listen on port " << opt_port << ", insufficient privileges");
return 1;
}
}
#endif
#endif
/* make sure data dictionary is loaded */
if (!dcmDataDict.isDictionaryLoaded())
{
OFLOG_WARN(storescpLogger, "no data dictionary loaded, check environment variable: "
<< DCM_DICT_ENVIRONMENT_VARIABLE);
}
/* if the output directory does not equal "." (default directory) */
if (opt_outputDirectory != ".")
{
/* if there is a path separator at the end of the path, get rid of it */
OFStandard::normalizeDirName(opt_outputDirectory, opt_outputDirectory);
/* check if the specified directory exists and if it is a directory.
* If the output directory is invalid, dump an error message and terminate execution.
*/
if (!OFStandard::dirExists(opt_outputDirectory))
{
OFLOG_FATAL(storescpLogger, "specified output directory does not exist");
return 1;
}
}
/* check if the output directory is writeable */
if (!opt_ignore && !OFStandard::isWriteable(opt_outputDirectory))
{
OFLOG_FATAL(storescpLogger, "specified output directory is not writeable");
return 1;
}
#ifdef HAVE_FORK
if (opt_forkMode)