-
Notifications
You must be signed in to change notification settings - Fork 1
/
zzdiscu.c
126 lines (119 loc) · 3.9 KB
/
zzdiscu.c
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
// Experimental alternative network protocol for transfering DICOM data
#include "zzio.h"
#include "zzwrite.h"
#include "zzditags.h"
#include "zznetwork.h"
#include "zzdinetwork.h"
#include "zzini.h"
#include <assert.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <sys/wait.h>
#include <signal.h>
enum
{
OPT_TRACE,
OPT_REQUEST,
OPT_COUNT
};
static struct zzopts opts[] =
{ { "--trace", "Save a network trace dump to \"zzdiscu.dcm\"", false, false, 0, 0 }, // OPT_TRACE
{ "--request <file>", "Generate an access request from given input file", false, false, 1, 0 }, // OPT_REQUEST
{ NULL, NULL, false, false, 0, 0 } }; // OPT_COUNT
static const char *readini(struct zzini *ini, const char *key)
{
char buf[256];
const char *ptr;
memset(buf, 0, sizeof(buf));
ptr = zzinivalue(ini, "request", key, buf, sizeof(buf) - 1);
if (ptr)
{
return ptr;
}
else
{
fprintf(stderr, "Missing field \"%s\" in input file\n", key);
return ""; // don't crash
}
}
int main(int argc, char **argv)
{
struct zznetwork *zzn;
char uid[MAX_LEN_UI];
int argstart = zzutil(argc, argv, 0, "", "DICOM experimental network client", opts);
zzmakeuid(uid, sizeof(uid));
zzn = zznetconnect("", "127.0.0.1", 5104, 0);
if (zzn)
{
if (opts[OPT_TRACE].found)
{
zznettrace(zzn, "zzdiscu.dcm");
}
strcpy(zzn->out->net.aet, "TESTCLIENT");
if (!zzdinegotiation(zzn))
{
zznetclose(zzn);
return -1;
}
if (opts[OPT_REQUEST].found) // send an access request
{
struct zzini sini, *ini = zziniopen(&sini, argv[opts[OPT_REQUEST].argstart + 1]);
if (!ini)
{
zznetclose(zzn);
return -1;
}
zzdisending(zzn);
zzwSQ_begin(zzn->out, DCM_DiNetworkServiceSequence, NULL);
zzwItem_begin(zzn->out, NULL);
zzwCS(zzn->out, DCM_DiNetworkService, "ACCESS");
zzwUI(zzn->out, DCM_DiNetworkServiceUID, uid);
zzwPN(zzn->out, DCM_DiAccessAuthorizing, readini(ini, "Authorizing"));
zzwPN(zzn->out, DCM_DiAccessTechnicalContact, readini(ini, "TechnicalContact"));
zzwLO(zzn->out, DCM_DiAccessTechnicalContactPhone, readini(ini, "TechnicalContactPhone"));
zzwLT(zzn->out, DCM_DiAccessMessage, readini(ini, "Message"));
zzwLO(zzn->out, DCM_DiAccessInstitutionDepartmentName, readini(ini, "InstitutionDepartmentName"));
zzwSQ_begin(zzn->out, DCM_DiAccessEquipmentSequence, NULL);
zzwItem_begin(zzn->out, NULL);
zzwLO(zzn->out, DCM_Manufacturer, readini(ini, "Manufacturer"));
zzwLO(zzn->out, DCM_ManufacturersModelName, readini(ini, "ModelName"));
zzwLO(zzn->out, DCM_DeviceSerialNumber, readini(ini, "DeviceSerialNumber"));
zzwLO(zzn->out, DCM_SoftwareVersions, readini(ini, "SoftwareVersions"));
zzwItem_end(zzn->out, NULL);
zzwSQ_end(zzn->out, NULL);
zzwLO(zzn->out, DCM_DiAccessPrivilegeRequested, readini(ini, "PrivilegeRequested"));
zzwAE(zzn->out, DCM_DiAccessAETITLE, readini(ini, "AETITLE"));
zzwLO(zzn->out, DCM_DiAccessIP, readini(ini, "IP"));
zzwLO(zzn->out, DCM_DiAccessPort, readini(ini, "Port"));
if (zzinicontains(ini, "request", "ServiceContact"))
{
zzwPN(zzn->out, DCM_DiAccessServiceContact, readini(ini, "ServiceContact"));
zzwLO(zzn->out, DCM_DiAccessServiceContactPhone, readini(ini, "ServiceContactPhone"));
}
// TODO : DCM_DiAccessPublicKey
zzwCS(zzn->out, DCM_DiAccessAuthenticationMethods, readini(ini, "AuthenticationMethods"));
zzwItem_end(zzn->out, NULL);
zzwSQ_end(zzn->out, NULL);
zziniclose(ini);
}
else // send an info request
{
zzdisending(zzn);
zzwSQ_begin(zzn->out, DCM_DiNetworkServiceSequence, NULL);
zzwItem_begin(zzn->out, NULL);
zzwCS(zzn->out, DCM_DiNetworkService, "INFO");
zzwUI(zzn->out, DCM_DiNetworkServiceUID, uid);
zzwItem_end(zzn->out, NULL);
zzwSQ_end(zzn->out, NULL);
zzwCS(zzn->out, DCM_DiDisconnect, "SUCCESS");
}
zznetclose(zzn);
}
return 0;
}