/
dimcmd.cc
2064 lines (1781 loc) · 59.3 KB
/
dimcmd.cc
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-2018, OFFIS e.V.
* All rights reserved. See COPYRIGHT file for details.
*
* This software and supporting documentation were partly developed by
*
* OFFIS e.V.
* R&D Division Health
* Escherweg 2
* D-26121 Oldenburg, Germany
*
* For further copyrights, see the following paragraphs.
*
*/
/*
** Copyright (C) 1993/1994, OFFIS, Oldenburg University and CERIUM
**
** This software and supporting documentation were
** developed by
**
** Institut OFFIS
** Bereich Kommunikationssysteme
** Westerstr. 10-12
** 26121 Oldenburg, Germany
**
** Fachbereich Informatik
** Abteilung Prozessinformatik
** Carl von Ossietzky Universitaet Oldenburg
** Ammerlaender Heerstr. 114-118
** 26111 Oldenburg, Germany
**
** CERIUM
** Laboratoire SIM
** Faculte de Medecine
** 2 Avenue du Pr. Leon Bernard
** 35043 Rennes Cedex, France
**
** for CEN/TC251/WG4 as a contribution to the Radiological
** Society of North America (RSNA) 1993 Digital Imaging and
** Communications in Medicine (DICOM) Demonstration.
**
** THIS SOFTWARE IS MADE AVAILABLE, AS IS, AND NEITHER OFFIS,
** OLDENBURG UNIVERSITY NOR CERIUM MAKE ANY WARRANTY REGARDING
** THE SOFTWARE, ITS PERFORMANCE, ITS MERCHANTABILITY OR
** FITNESS FOR ANY PARTICULAR USE, FREEDOM FROM ANY COMPUTER
** DISEASES OR ITS CONFORMITY TO ANY SPECIFICATION. THE
** ENTIRE RISK AS TO QUALITY AND PERFORMANCE OF THE SOFTWARE
** IS WITH THE USER.
**
** Copyright of the software and supporting documentation
** is, unless otherwise stated, jointly owned by OFFIS,
** Oldenburg University and CERIUM and free access is hereby
** granted as a license to use this software, copy this
** software and prepare derivative works based upon this
** software. However, any distribution of this software
** source code or supporting documentation or derivative
** works (source code and supporting documentation) must
** include the three paragraphs of this copyright notice.
**
*/
/*
**
** Author: Andrew Hewett Created: 20-10-93
**
** Module: dimcmd
**
** Purpose:
** Routines for building and parsing DIMSE Commands
**
** Module Prefix: DIMSE_
**
*/
/*
** Include Files
*/
#include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */
#define INCLUDE_CSTDLIB
#define INCLUDE_CSTDIO
#define INCLUDE_CSTRING
#define INCLUDE_CSTDARG
#define INCLUDE_CERRNO
#include "dcmtk/ofstd/ofstdinc.h"
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
#include "dcmtk/dcmdata/dcdatset.h"
#include "dcmtk/dcmdata/dcdeftag.h"
#include "dcmtk/dcmdata/dcelem.h"
#include "dcmtk/dcmnet/diutil.h"
#include "dcmtk/dcmnet/dimse.h"
#include "dcmtk/ofstd/ofstd.h"
#include "dimcmd.h"
/*
* Useful Macros
*/
#define RET(cond) if (cond.bad()) return cond
#define BRET(cond, t) if (cond.bad()) return buildError(t)
#define PRET(cond, t) if (cond.bad()) return parseError(t)
/*
* Type definitions
*/
/*
* Global variables (should be used very, very rarely).
*/
/*
** Private Functions Prototypes
*/
/*
** Private Functions Bodies
*/
static OFCondition
buildErrorWithMsg(const char* msg, DcmTagKey t)
{
DcmTag tag(t);
char buf[1024];
sprintf(buf, "DIMSE: Command Build Failed: %s: Element: (%04x,%04x) %s",
msg, t.getGroup(), t.getElement(), tag.getTagName());
return makeDcmnetCondition(DIMSEC_BUILDFAILED, OF_error, buf);
}
static OFCondition
parseError(DcmTagKey t)
{
DcmTag tag(t);
char buf[1024];
sprintf(buf, "DIMSE: Command Parse Failed: Element: (%04x,%04x) %s",
t.getGroup(), t.getElement(), tag.getTagName());
return makeDcmnetCondition(DIMSEC_PARSEFAILED, OF_error, buf);
}
static OFCondition
parseErrorWithMsg(const char* msg, DcmTagKey t)
{
DcmTag tag(t);
char buf[1024];
sprintf(buf, "DIMSE: Command Parse Failed: %s: Element: (%04x,%04x) %s", msg,
t.getGroup(), t.getElement(), tag.getTagName());
return makeDcmnetCondition(DIMSEC_PARSEFAILED, OF_error, buf);
}
/*
* Common dcmcode based utilities
*/
static OFCondition
deleteElem(DcmDataset *obj, DcmTagKey t)
{
DcmTag tag(t);
DcmElement *e = NULL;
OFBool ok = OFTrue;
e = obj->remove(tag);
ok = (e != NULL);
if (e) delete e;
return (ok)?(EC_Normal):
(parseErrorWithMsg("dimcmd:deleteElem: Cannot delete element", t));
}
static OFCondition
addString(DcmDataset *obj, DcmTagKey t, char *s, OFBool keepPadding)
{
OFCondition ec = EC_Normal;
DcmElement *e = NULL;
DcmTag tag(t);
if (! keepPadding) DU_stripLeadingAndTrailingSpaces(s);
ec = DcmItem::newDicomElement(e, tag);
if (ec == EC_Normal && s != NULL) {
ec = e->putString(s);
}
if (ec == EC_Normal) {
ec = obj->insert(e, OFTrue);
}
return (ec == EC_Normal)?(EC_Normal):
(buildErrorWithMsg("dimcmd:addString: Cannot add string", t));
}
static OFCondition
getString(DcmDataset *obj, DcmTagKey t, char *s, int maxlen, OFBool *spacePadded)
{
DcmElement *elem;
DcmStack stack;
OFCondition ec = EC_Normal;
char* aString;
ec = obj->search(t, stack);
elem = (DcmElement*)stack.top();
if (ec == EC_Normal && elem != NULL) {
if (elem->getLength() == 0) {
s[0] = '\0';
} else if (elem->getLength() > (Uint32)maxlen) {
return parseErrorWithMsg("dimcmd:getString: string too small", t);
} else {
ec = elem->getString(aString);
strncpy(s, aString, maxlen);
if (spacePadded)
{
/* before we remove leading and tailing spaces we want to know
* whether the string is actually space padded. Required to communicate
* with dumb peers which send space padded UIDs and fail if they
* receive correct UIDs back.
*
* This test can only detect space padded strings if
* dcmEnableAutomaticInputDataCorrection is false; otherwise the padding
* has already been removed by dcmdata at this stage.
*/
size_t s_len = strlen(s);
if ((s_len > 0)&&(s[s_len-1] == ' ')) *spacePadded = OFTrue; else *spacePadded = OFFalse;
}
DU_stripLeadingAndTrailingSpaces(s);
}
}
return (ec.good())? ec : DIMSE_PARSEFAILED;
}
static OFCondition
getAndDeleteString(DcmDataset *obj, DcmTagKey t, char *s, int maxlen, OFBool *spacePadded)
{
OFCondition cond = getString(obj, t, s, maxlen, spacePadded); PRET(cond, t);
cond = deleteElem(obj, t);
return cond;
}
static OFCondition
getAndDeleteStringOpt(DcmDataset *obj, DcmTagKey t, char *s, int maxlen, OFBool *spacePadded)
{
OFCondition cond = getString(obj, t, s, maxlen, spacePadded); RET(cond);
cond = deleteElem(obj, t);
return cond;
}
static OFCondition
addUS(DcmDataset *obj, DcmTagKey t, Uint16 us)
{
OFCondition ec = EC_Normal;
DcmElement *e = NULL;
DcmTag tag(t);
ec = DcmItem::newDicomElement(e, tag);
if (ec == EC_Normal) {
ec = e->putUint16(us);
}
if (ec == EC_Normal) {
ec = obj->insert(e, OFTrue);
}
return (ec == EC_Normal)?(EC_Normal):
(buildErrorWithMsg("dimcmd:addUS: Cannot add Uint16", t));
}
static OFCondition
getUS(DcmDataset *obj, DcmTagKey t, Uint16 *us)
{
DcmElement *elem;
DcmStack stack;
OFCondition ec = EC_Normal;
ec = obj->search(t, stack);
elem = (DcmElement*)stack.top();
if (ec == EC_Normal && elem != NULL) {
ec = elem->getUint16(*us, 0);
}
return (ec == EC_Normal)?(EC_Normal):(DIMSE_PARSEFAILED);
}
static OFCondition
getAndDeleteUS(DcmDataset *obj, DcmTagKey t, Uint16 *us)
{
OFCondition cond = getUS(obj, t, us); PRET(cond, t);
cond = deleteElem(obj, t);
return cond;
}
static OFCondition
getAndDeleteUSOpt(DcmDataset *obj, DcmTagKey t, Uint16 *us)
{
OFCondition cond = getUS(obj, t, us); RET(cond);
cond = deleteElem(obj, t);
return cond;
}
static OFCondition
addUL(DcmDataset *obj, DcmTagKey t, Uint32 ul)
{
OFCondition ec = EC_Normal;
DcmElement *e = NULL;
DcmTag tag(t);
ec = DcmItem::newDicomElement(e, tag);
if (ec == EC_Normal) {
ec = e->putUint32(ul);
}
if (ec == EC_Normal) {
ec = obj->insert(e, OFTrue);
}
return (ec == EC_Normal)?(EC_Normal):
(buildErrorWithMsg("dimcmd:addUL: Cannot add Uint32", t));
}
static OFCondition
getUL(DcmDataset *obj, DcmTagKey t, Uint32 *ul)
{
DcmElement *elem;
DcmStack stack;
OFCondition ec = EC_Normal;
ec = obj->search(t, stack);
elem = (DcmElement*)stack.top();
if (ec == EC_Normal && elem != NULL) {
ec = elem->getUint32(*ul, 0);
}
return (ec == EC_Normal)?(EC_Normal):(DIMSE_PARSEFAILED);
}
#if 0
/* Currently Unused */
static OFCondition
getAndDeleteUL(DcmDataset *obj, DcmTagKey t, Uint32 *ul)
{
OFCondition cond = getUL(obj, t, ul); PRET(cond, t);
cond = deleteElem(obj, t);
return cond;
}
#endif
static OFCondition
getAndDeleteULOpt(DcmDataset *obj, DcmTagKey t, Uint32 *ul)
{
OFCondition cond = getUL(obj, t, ul); RET(cond);
cond = deleteElem(obj, t);
return cond;
}
static OFCondition
addAttributeList(DcmDataset *obj, DcmTagKey t, Uint16 *lst, int listCount)
{
/* ListCount should represent the number of US values in the list (not the
** number of (gggg,eeee) pairs.
*/
OFCondition ec = EC_Normal;
DcmElement *e = NULL;
DcmTag tag(t);
if ((listCount % 2) != 0) {
return buildErrorWithMsg("dimcmd:addAttributeList: Error: Uneven listCount", t);
}
ec = DcmItem::newDicomElement(e, tag);
if (ec == EC_Normal) {
ec = e->putUint16Array(lst, (listCount / 2));
}
if (ec == EC_Normal) {
ec = obj->insert(e, OFTrue);
}
return (ec == EC_Normal)?(EC_Normal):
(buildErrorWithMsg("dimcmd:addAttributeList: Cannot add list", t));
}
static OFCondition
getAttributeList(DcmDataset *obj, DcmTagKey t, Uint16 **lst, int *listCount)
{
DcmElement *elem;
DcmStack stack;
OFCondition ec = EC_Normal;
Uint16 *aList = NULL;
Uint32 nBytes = 0;
ec = obj->search(t, stack);
elem = (DcmElement*)stack.top();
if (ec == EC_Normal && elem != NULL) {
nBytes = elem->getLength();
*listCount = (int)(nBytes / sizeof(Uint16));
if (*listCount > 0) {
*lst = (Uint16*)malloc((size_t)(nBytes + 1));
ec = elem->getUint16Array(aList);
memcpy(*lst, aList, (size_t)nBytes);
} else {
*lst = NULL;
}
}
return (ec == EC_Normal)?(EC_Normal):(DIMSE_PARSEFAILED);
}
/*
* The attribute list in an N-GET-RQ is optional. Do not require it.
* The old code was causing problems with Print SCU software which
* sent an N-GET-RQ on the Printer SOP Class to obtain the printer identity.
*/
static OFCondition
getAndDeleteAttributeListOpt(DcmDataset *obj, DcmTagKey t,
Uint16 **lst, int *listCount)
{
OFCondition cond = getAttributeList(obj, t, lst, listCount); RET(cond);
cond = deleteElem(obj, t);
return cond;
}
/*
* Common Building/Parsing Routines
*/
static OFCondition
buildCommonRQ(DcmDataset *obj, Uint16 command, Uint16 messageID,
Uint16 dataSetType)
{
// insert group length but calculate later
OFCondition cond = addUL(obj, DCM_CommandGroupLength, 0); RET(cond);
cond = addUS(obj, DCM_CommandField, command); RET(cond);
cond = addUS(obj, DCM_MessageID, messageID); RET(cond);
cond = addUS(obj, DCM_CommandDataSetType, dataSetType); RET(cond);
return EC_Normal;
}
static OFCondition
parseCommonRQ(DcmDataset *obj, Uint16 *command, Uint16 *messageID,
Uint16 *dataSetType)
{
OFCondition cond = getAndDeleteUS(obj, DCM_CommandField, command); RET(cond);
cond = getAndDeleteUS(obj, DCM_MessageID, messageID); RET(cond);
cond = getAndDeleteUS(obj, DCM_CommandDataSetType, dataSetType); RET(cond);
return EC_Normal;
}
static OFCondition
buildCommonRSP(DcmDataset *obj, Uint16 command,
Uint16 messageIDBeingRespondedTo,
Uint16 dataSetType, Uint16 status)
{
// insert group length but calculate later
OFCondition cond = addUL(obj, DCM_CommandGroupLength, 0); RET(cond);
cond = addUS(obj, DCM_CommandField, command); RET(cond);
cond = addUS(obj, DCM_MessageIDBeingRespondedTo, messageIDBeingRespondedTo); RET(cond);
cond = addUS(obj, DCM_CommandDataSetType, dataSetType); RET(cond);
cond = addUS(obj, DCM_Status, status); RET(cond);
return EC_Normal;
}
static OFCondition
parseCommonRSP(DcmDataset *obj, Uint16 *command,
Uint16 *messageIDBeingRespondedTo,
Uint16 *dataSetType, Uint16 *status)
{
OFCondition cond = getAndDeleteUS(obj, DCM_CommandField, command); RET(cond);
cond = getAndDeleteUS(obj, DCM_MessageIDBeingRespondedTo,
messageIDBeingRespondedTo); RET(cond);
cond = getAndDeleteUS(obj, DCM_CommandDataSetType, dataSetType); RET(cond);
cond = getAndDeleteUS(obj, DCM_Status, status); RET(cond);
return EC_Normal;
}
/*
* C-ECHO-RQ
*/
static OFCondition
buildCEchoRQ(T_DIMSE_C_EchoRQ * e, DcmDataset * obj)
{
OFCondition cond = buildCommonRQ(obj, DIMSE_C_ECHO_RQ, e->MessageID, e->DataSetType); RET(cond);
cond = addString(obj, DCM_AffectedSOPClassUID, e->AffectedSOPClassUID, OFFalse); RET(cond);
return cond;
}
static OFCondition
parseCEchoRQ(T_DIMSE_C_EchoRQ * e, DcmDataset * obj)
{
Uint16 cmd;
Uint16 msgid;
Uint16 dtype;
OFCondition cond = parseCommonRQ(obj, &cmd, &msgid, &dtype); RET(cond);
e->MessageID = msgid;
if (dtype == DIMSE_DATASET_NULL) {
e->DataSetType = DIMSE_DATASET_NULL;
} else {
e->DataSetType = DIMSE_DATASET_PRESENT;
}
if (cmd != DIMSE_C_ECHO_RQ) {
cond = DIMSE_PARSEFAILED; RET(cond);
}
cond = getAndDeleteString(obj, DCM_AffectedSOPClassUID,
e->AffectedSOPClassUID, DIC_UI_LEN, NULL); RET(cond);
return EC_Normal;
}
/*
* C-ECHO-RSP
*/
static OFCondition
buildCEchoRSP(T_DIMSE_C_EchoRSP * e, DcmDataset * obj)
{
OFCondition cond = buildCommonRSP(obj, DIMSE_C_ECHO_RSP,
e->MessageIDBeingRespondedTo,
e->DataSetType, e->DimseStatus); RET(cond);
/* build optional items */
if (e->opts & O_ECHO_AFFECTEDSOPCLASSUID) {
cond = addString(obj, DCM_AffectedSOPClassUID,
e->AffectedSOPClassUID, OFFalse); RET(cond);
}
return cond;
}
static OFCondition
parseCEchoRSP(T_DIMSE_C_EchoRSP * e, DcmDataset * obj)
{
Uint16 cmd;
Uint16 msgid;
Uint16 dtype;
Uint16 status;
OFCondition cond = parseCommonRSP(obj, &cmd, &msgid, &dtype, &status); RET(cond);
e->MessageIDBeingRespondedTo = msgid;
if (dtype == DIMSE_DATASET_NULL) {
e->DataSetType = DIMSE_DATASET_NULL;
} else {
e->DataSetType = DIMSE_DATASET_PRESENT;
}
e->DimseStatus = status;
if (cmd != DIMSE_C_ECHO_RSP) {
cond = DIMSE_PARSEFAILED; RET(cond);
}
e->opts = 0;
/* parse optional items */
cond = getAndDeleteStringOpt(obj, DCM_AffectedSOPClassUID,
e->AffectedSOPClassUID, DIC_UI_LEN, NULL);
if (cond.good()) e->opts |= O_ECHO_AFFECTEDSOPCLASSUID;
return EC_Normal;
}
/*
* C-STORE-RQ
*/
static OFCondition
buildCStoreRQ(T_DIMSE_C_StoreRQ * e, DcmDataset * obj)
{
OFCondition cond = buildCommonRQ(obj, DIMSE_C_STORE_RQ, e->MessageID,
e->DataSetType); RET(cond);
/* build other mandatory items */
cond = addString(obj, DCM_AffectedSOPClassUID,
e->AffectedSOPClassUID, OFFalse); RET(cond);
cond = addString(obj, DCM_AffectedSOPInstanceUID,
e->AffectedSOPInstanceUID, OFFalse); RET(cond);
cond = addUS(obj, DCM_Priority,
e->Priority); RET(cond);
/* build optional items */
if (e->opts & O_STORE_MOVEORIGINATORAETITLE) {
cond = addString(obj, DCM_MoveOriginatorApplicationEntityTitle,
e->MoveOriginatorApplicationEntityTitle, OFFalse); RET(cond);
}
if (e->opts & O_STORE_MOVEORIGINATORID) {
cond = addUS(obj, DCM_MoveOriginatorMessageID,
e->MoveOriginatorID); RET(cond);
}
return cond;
}
static OFCondition
parseCStoreRQ(T_DIMSE_C_StoreRQ * e, DcmDataset * obj)
{
Uint16 cmd;
Uint16 msgid;
Uint16 dtype;
Uint16 priority;
OFCondition cond = parseCommonRQ(obj, &cmd, &msgid, &dtype); RET(cond);
e->MessageID = msgid;
if (dtype == DIMSE_DATASET_NULL) {
e->DataSetType = DIMSE_DATASET_NULL;
} else {
e->DataSetType = DIMSE_DATASET_PRESENT;
}
if (cmd != DIMSE_C_STORE_RQ) {
cond = DIMSE_PARSEFAILED; RET(cond);
}
OFBool uidSpacePadded = OFFalse;
/* parse other mandatory items */
cond = getAndDeleteString(obj, DCM_AffectedSOPClassUID,
e->AffectedSOPClassUID, DIC_UI_LEN, NULL); RET(cond);
cond = getAndDeleteString(obj, DCM_AffectedSOPInstanceUID,
e->AffectedSOPInstanceUID, DIC_UI_LEN, &uidSpacePadded); RET(cond);
cond = getAndDeleteUS(obj, DCM_Priority,
&priority); e->Priority = (T_DIMSE_Priority)priority; RET(cond);
/* parse optional items */
e->opts = 0;
cond = getAndDeleteStringOpt(obj, DCM_MoveOriginatorApplicationEntityTitle,
e->MoveOriginatorApplicationEntityTitle, DIC_AE_LEN, NULL);
if (cond.good()) e->opts |= O_STORE_MOVEORIGINATORAETITLE;
cond = getAndDeleteUSOpt(obj, DCM_MoveOriginatorMessageID,
&e->MoveOriginatorID);
if (cond.good()) e->opts |= O_STORE_MOVEORIGINATORID;
if (uidSpacePadded) e->opts |= O_STORE_RQ_BLANK_PADDING;
return EC_Normal;
}
/*
* C-STORE-RSP
*/
static OFCondition
buildCStoreRSP(T_DIMSE_C_StoreRSP * e, DcmDataset * obj)
{
OFCondition cond = buildCommonRSP(obj, DIMSE_C_STORE_RSP,
e->MessageIDBeingRespondedTo,
e->DataSetType, e->DimseStatus); RET(cond);
/* build optional items */
if (e->opts & O_STORE_AFFECTEDSOPCLASSUID) {
cond = addString(obj, DCM_AffectedSOPClassUID,
e->AffectedSOPClassUID, OFFalse); RET(cond);
}
if (e->opts & O_STORE_AFFECTEDSOPINSTANCEUID)
{
char instanceuid[DIC_UI_LEN + 10];
OFStandard::strlcpy(instanceuid, e->AffectedSOPInstanceUID, DIC_UI_LEN + 10);
if ((e->opts & O_STORE_PEER_REQUIRES_EXACT_UID_COPY) &&
(e->opts & O_STORE_RSP_BLANK_PADDING))
{
// restore illegal space padding.
OFStandard::strlcat(instanceuid, " ", DIC_UI_LEN + 10);
}
cond = addString(obj, DCM_AffectedSOPInstanceUID, instanceuid, OFTrue); RET(cond);
}
return cond;
}
static OFCondition
parseCStoreRSP(T_DIMSE_C_StoreRSP * e, DcmDataset * obj)
{
Uint16 cmd;
Uint16 msgid;
Uint16 dtype;
Uint16 status;
OFCondition cond = parseCommonRSP(obj, &cmd, &msgid, &dtype, &status); RET(cond);
e->MessageIDBeingRespondedTo = msgid;
if (dtype == DIMSE_DATASET_NULL) {
e->DataSetType = DIMSE_DATASET_NULL;
} else {
e->DataSetType = DIMSE_DATASET_PRESENT;
}
e->DimseStatus = status;
if (cmd != DIMSE_C_STORE_RSP) {
cond = DIMSE_PARSEFAILED; RET(cond);
}
e->opts = 0;
/* parse optional items */
cond = getAndDeleteStringOpt(obj, DCM_AffectedSOPClassUID,
e->AffectedSOPClassUID, DIC_UI_LEN, NULL);
if (cond.good()) e->opts |= O_STORE_AFFECTEDSOPCLASSUID;
cond = getAndDeleteStringOpt(obj, DCM_AffectedSOPInstanceUID,
e->AffectedSOPInstanceUID, DIC_UI_LEN, NULL);
if (cond.good()) e->opts |= O_STORE_AFFECTEDSOPINSTANCEUID;
return EC_Normal;
}
/*
* C-FIND-RQ
*/
static OFCondition
buildCFindRQ(T_DIMSE_C_FindRQ * e, DcmDataset * obj)
{
OFCondition cond = buildCommonRQ(obj, DIMSE_C_FIND_RQ, e->MessageID,
e->DataSetType); RET(cond);
/* build other mandatory items */
cond = addString(obj, DCM_AffectedSOPClassUID,
e->AffectedSOPClassUID, OFFalse); RET(cond);
cond = addUS(obj, DCM_Priority,
e->Priority); RET(cond);
return cond;
}
static OFCondition
parseCFindRQ(T_DIMSE_C_FindRQ * e, DcmDataset * obj)
{
Uint16 cmd;
Uint16 msgid;
Uint16 dtype;
Uint16 priority;
OFCondition cond = parseCommonRQ(obj, &cmd, &msgid, &dtype); RET(cond);
e->MessageID = msgid;
if (dtype == DIMSE_DATASET_NULL) {
e->DataSetType = DIMSE_DATASET_NULL;
} else {
e->DataSetType = DIMSE_DATASET_PRESENT;
}
if (cmd != DIMSE_C_FIND_RQ) {
cond = DIMSE_PARSEFAILED; RET(cond);
}
/* parse other mandatory items */
cond = getAndDeleteString(obj, DCM_AffectedSOPClassUID,
e->AffectedSOPClassUID, DIC_UI_LEN, NULL); RET(cond);
cond = getAndDeleteUS(obj, DCM_Priority,
&priority); e->Priority = (T_DIMSE_Priority)priority; RET(cond);
return EC_Normal;
}
/*
* C-FIND-RSP
*/
static OFCondition
buildCFindRSP(T_DIMSE_C_FindRSP * e, DcmDataset * obj)
{
OFCondition cond = buildCommonRSP(obj, DIMSE_C_FIND_RSP,
e->MessageIDBeingRespondedTo,
e->DataSetType, e->DimseStatus); RET(cond);
/* build optional items */
if (e->opts & O_FIND_AFFECTEDSOPCLASSUID) {
cond = addString(obj, DCM_AffectedSOPClassUID,
e->AffectedSOPClassUID, OFFalse); RET(cond);
}
return cond;
}
static OFCondition
parseCFindRSP(T_DIMSE_C_FindRSP * e, DcmDataset * obj)
{
Uint16 cmd;
Uint16 msgid;
Uint16 dtype;
Uint16 status;
OFCondition cond = parseCommonRSP(obj, &cmd, &msgid, &dtype, &status); RET(cond);
e->MessageIDBeingRespondedTo = msgid;
if (dtype == DIMSE_DATASET_NULL) {
e->DataSetType = DIMSE_DATASET_NULL;
} else {
e->DataSetType = DIMSE_DATASET_PRESENT;
}
e->DimseStatus = status;
if (cmd != DIMSE_C_FIND_RSP) {
cond = DIMSE_PARSEFAILED; RET(cond);
}
e->opts = 0;
/* parse optional items */
cond = getAndDeleteStringOpt(obj, DCM_AffectedSOPClassUID,
e->AffectedSOPClassUID, DIC_UI_LEN, NULL);
if (cond.good()) e->opts |= O_FIND_AFFECTEDSOPCLASSUID;
return EC_Normal;
}
/*
* C-GET-RQ
*/
static OFCondition
buildCGetRQ(T_DIMSE_C_GetRQ * e, DcmDataset * obj)
{
OFCondition cond = buildCommonRQ(obj, DIMSE_C_GET_RQ, e->MessageID,
e->DataSetType); RET(cond);
/* build other mandatory items */
cond = addString(obj, DCM_AffectedSOPClassUID,
e->AffectedSOPClassUID, OFFalse); RET(cond);
cond = addUS(obj, DCM_Priority,
e->Priority); RET(cond);
return cond;
}
static OFCondition
parseCGetRQ(T_DIMSE_C_GetRQ * e, DcmDataset * obj)
{
Uint16 cmd;
Uint16 msgid;
Uint16 dtype;
Uint16 priority;
OFCondition cond = parseCommonRQ(obj, &cmd, &msgid, &dtype); RET(cond);
e->MessageID = msgid;
if (dtype == DIMSE_DATASET_NULL) {
e->DataSetType = DIMSE_DATASET_NULL;
} else {
e->DataSetType = DIMSE_DATASET_PRESENT;
}
if (cmd != DIMSE_C_GET_RQ) {
cond = DIMSE_PARSEFAILED; RET(cond);
}
/* parse other mandatory items */
cond = getAndDeleteString(obj, DCM_AffectedSOPClassUID,
e->AffectedSOPClassUID, DIC_UI_LEN, NULL); RET(cond);
cond = getAndDeleteUS(obj, DCM_Priority,
&priority); e->Priority = (T_DIMSE_Priority)priority; RET(cond);
return EC_Normal;
}
/*
* C-GET-RSP
*/
static OFCondition
buildCGetRSP(T_DIMSE_C_GetRSP * e, DcmDataset * obj)
{
OFCondition cond = buildCommonRSP(obj, DIMSE_C_GET_RSP,
e->MessageIDBeingRespondedTo,
e->DataSetType, e->DimseStatus); RET(cond);
/* build optional items */
if (e->opts & O_GET_AFFECTEDSOPCLASSUID) {
cond = addString(obj, DCM_AffectedSOPClassUID,
e->AffectedSOPClassUID, OFFalse); RET(cond);
}
if (e->opts & O_GET_NUMBEROFREMAININGSUBOPERATIONS) {
cond = addUS(obj, DCM_NumberOfRemainingSuboperations,
e->NumberOfRemainingSubOperations); RET(cond);
}
if (e->opts & O_GET_NUMBEROFCOMPLETEDSUBOPERATIONS) {
cond = addUS(obj, DCM_NumberOfCompletedSuboperations,
e->NumberOfCompletedSubOperations); RET(cond);
}
if (e->opts & O_GET_NUMBEROFFAILEDSUBOPERATIONS) {
cond = addUS(obj, DCM_NumberOfFailedSuboperations,
e->NumberOfFailedSubOperations); RET(cond);
}
if (e->opts & O_GET_NUMBEROFWARNINGSUBOPERATIONS) {
cond = addUS(obj, DCM_NumberOfWarningSuboperations,
e->NumberOfWarningSubOperations); RET(cond);
}
return cond;
}
static OFCondition
parseCGetRSP(T_DIMSE_C_GetRSP * e, DcmDataset * obj)
{
Uint16 cmd;
Uint16 msgid;
Uint16 dtype;
Uint16 status;
OFCondition cond = parseCommonRSP(obj, &cmd, &msgid, &dtype, &status); RET(cond);
e->MessageIDBeingRespondedTo = msgid;
if (dtype == DIMSE_DATASET_NULL) {
e->DataSetType = DIMSE_DATASET_NULL;
} else {
e->DataSetType = DIMSE_DATASET_PRESENT;
}
e->DimseStatus = status;
if (cmd != DIMSE_C_GET_RSP) {
cond = DIMSE_PARSEFAILED; RET(cond);
}
/* parse optional items */
e->opts = 0;
cond = getAndDeleteStringOpt(obj, DCM_AffectedSOPClassUID,
e->AffectedSOPClassUID, DIC_UI_LEN, NULL);
if (cond.good()) e->opts |= O_GET_AFFECTEDSOPCLASSUID;
cond = getAndDeleteUSOpt(obj, DCM_NumberOfRemainingSuboperations,
&e->NumberOfRemainingSubOperations);
if (cond.good()) e->opts |= O_GET_NUMBEROFREMAININGSUBOPERATIONS;
cond = getAndDeleteUSOpt(obj, DCM_NumberOfCompletedSuboperations,
&e->NumberOfCompletedSubOperations);
if (cond.good()) e->opts |= O_GET_NUMBEROFCOMPLETEDSUBOPERATIONS;
cond = getAndDeleteUSOpt(obj, DCM_NumberOfFailedSuboperations,
&e->NumberOfFailedSubOperations);
if (cond.good()) e->opts |= O_GET_NUMBEROFFAILEDSUBOPERATIONS;
cond = getAndDeleteUSOpt(obj, DCM_NumberOfWarningSuboperations,
&e->NumberOfWarningSubOperations);
if (cond.good()) e->opts |= O_GET_NUMBEROFWARNINGSUBOPERATIONS;
return EC_Normal;
}
/*
* C-MOVE-RQ
*/
static OFCondition
buildCMoveRQ(T_DIMSE_C_MoveRQ * e, DcmDataset * obj)
{
OFCondition cond = buildCommonRQ(obj, DIMSE_C_MOVE_RQ, e->MessageID,
e->DataSetType); RET(cond);
/* build other mandatory items */
cond = addString(obj, DCM_AffectedSOPClassUID,
e->AffectedSOPClassUID, OFFalse); RET(cond);
cond = addUS(obj, DCM_Priority, e->Priority); RET(cond);
cond = addString(obj, DCM_MoveDestination, e->MoveDestination, OFFalse); RET(cond);
return cond;
}
static OFCondition
parseCMoveRQ(T_DIMSE_C_MoveRQ * e, DcmDataset * obj)
{
Uint16 cmd;
Uint16 msgid;
Uint16 dtype;
Uint16 priority;
OFCondition cond = parseCommonRQ(obj, &cmd, &msgid, &dtype); RET(cond);
e->MessageID = msgid;
if (dtype == DIMSE_DATASET_NULL) {
e->DataSetType = DIMSE_DATASET_NULL;
} else {
e->DataSetType = DIMSE_DATASET_PRESENT;
}
if (cmd != DIMSE_C_MOVE_RQ) {
cond = DIMSE_PARSEFAILED; RET(cond);
}
/* parse other mandatory items */
cond = getAndDeleteString(obj, DCM_AffectedSOPClassUID,
e->AffectedSOPClassUID, DIC_UI_LEN, NULL); RET(cond);
cond = getAndDeleteUS(obj, DCM_Priority, &priority);
e->Priority = (T_DIMSE_Priority)priority; RET(cond);
cond = getAndDeleteString(obj, DCM_MoveDestination,
e->MoveDestination, DIC_AE_LEN, NULL); RET(cond);
return EC_Normal;
}
/*
* C-MOVE-RSP
*/
static OFCondition
buildCMoveRSP(T_DIMSE_C_MoveRSP * e, DcmDataset * obj)
{
OFCondition cond = buildCommonRSP(obj, DIMSE_C_MOVE_RSP,
e->MessageIDBeingRespondedTo,
e->DataSetType, e->DimseStatus); RET(cond);
/* build optional items */
if (e->opts & O_MOVE_AFFECTEDSOPCLASSUID) {
cond = addString(obj, DCM_AffectedSOPClassUID,
e->AffectedSOPClassUID, OFFalse); RET(cond);
}
if (e->opts & O_MOVE_NUMBEROFREMAININGSUBOPERATIONS) {
cond = addUS(obj, DCM_NumberOfRemainingSuboperations,
e->NumberOfRemainingSubOperations); RET(cond);