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
|
/*
** Electronic Radiology Laboratory
** Mallinckrodt Institute of Radiology
** Washington University School of Medicine
**
** Module Name(s): netWork
** request_association
** request_release
** errorstackP
** copyWtext
** closeNetworkConnection
**
** Author, Date: Chander L. Sabharwal, 9-September-94
**
** Intenet: This program initializes network environment,
** builds a presentation context to be transmitted
** to an Association acceptor and requests an
** Association with another node.
** It also informs the user of any errors occuring
** in this Association.
**
**
** Last Update: $Author: smm $, $Date: 2002-10-31 23:17:53 $
** Source File: $Source: /home/smm/ctn/ctn/apps/assoc_tool/netWork.c,v $
** Revision: $Revision: 1.6 $
** Status: $State: Exp $
*/
static char rcsid[] = "$Revision: 1.6 $ $RCSfile: netWork.c,v $";
#include "ctn_os.h"
#include "dicom.h"
#include "dicom_uids.h"
#include "lst.h"
#include "condition.h"
#include "dulprotocol.h"
#include "dicom_objects.h"
#include "dicom_messages.h"
#include "dicom_services.h"
#include "structures.h"
#include "prototypes.h"
#define MAXLEN 5000
extern LST_HEAD *sopList;
extern LST_HEAD *selectedsopList;
extern SELECTED_SOP *se;
static DUL_NETWORKKEY /* Used to initialize our network */
* network = NULL;
static DUL_ASSOCIATIONKEY /* Describes the Association with the
* Acceptor */
* association = NULL;
static DUL_ASSOCIATESERVICEPARAMETERS /* The items which describe this
* Association */
params =
{
DICOM_STDAPPLICATIONCONTEXT, "DICOM_TEST", "DICOM_VERIFY",
"", 16384, 0, 0, 0,
"calling presentation addr", "called presentation addr",
NULL, NULL, 0, 0,
MIR_IMPLEMENTATIONCLASSUID, MIR_IMPLEMENTATIONVERSIONNAME,
"", "", 0
};
static char *info; /* character string contains error code and
* error message */
/* request_association
**
** Purpose:
** This program initializes network environment,
** builds a presentation context to be transmitted
** to an Association acceptor and requests an
** Association with another node.
** It also informs the user of any errors occuring
** in this Association.
**
**
** Parameter Dictionary:
** node input node we are calling
** port input TCP port to establish association
** calledAPTitle input called application title
** callingAPTitle input caliing application title
**
** Return Values:
** None
**
** Notes:
**
** Algorithm:
** Description of the algorithm (optional) and any other notes.
*/
void
request_association(char node[], char port[], char calledAPTitle[],
char callingAPTitle[])
{
unsigned long i;
CONDITION /* Return values from DUL and ACR routines */
cond;
static CTNBOOLEAN
networkInitialized = FALSE;
static CTNBOOLEAN
association_on = FALSE;
char
localHost[40];
DUL_PRESENTATIONCONTEXT /* contains DUL presentation context */
* context;
UID_DESCRIPTION /* pointer to DUL presentation context
* description */
d;
unsigned short ctxresult; /* character containing the code for
* acceptance or rejection of sop class */
char *buf1,
*buf2,
*bufsyn;
CTNBOOLEAN
clearStack = TRUE;
unsigned long numSop; /* number of SOPCLASSES in the linkedList */
static DUL_PRESENTATIONCONTEXTID /* contains DUL presentation context
* ID */
contextID = 1;
CTNBOOLEAN /* Function to obtain error messages from the
* stack */
errorstackP(unsigned long v, char *mes);
char *buffer,
*buff;
info = calloc(MAXLEN, sizeof(char));
buf1 = calloc(100, sizeof(char));
buf2 = calloc(100, sizeof(char));
bufsyn = calloc(100, sizeof(char));
memset(buf1, 0, sizeof(buf1));
memset(buf2, 0, sizeof(buf2));
memset(bufsyn, 0, sizeof(buf2));
memset(info, 0, sizeof(info));
copyWtext2(info);
(void) DUL_ClearServiceParameters(¶ms);
(void) gethostname(localHost, sizeof(localHost));
if (!networkInitialized) {
networkInitialized = TRUE;
cond = DUL_InitializeNetwork(DUL_NETWORK_TCP, DUL_AEREQUESTOR,
NULL, 10, DUL_ORDERBIGENDIAN, &network);
if (cond != DUL_NORMAL) {
networkInitialized = FALSE;
(void) COND_ExtractConditions(errorstackP);
copyWtext2(info);
(void) COND_PopCondition(clearStack);
}
}
if (association_on) {
request_release();
}
strcpy(params.calledPresentationAddress, node);
strcat(params.calledPresentationAddress, ":");
strcat(params.calledPresentationAddress, port);
strcpy(params.callingPresentationAddress, localHost);
strcpy(params.calledAPTitle, calledAPTitle);
strcpy(params.callingAPTitle, callingAPTitle);
numSop = LST_Count(&selectedsopList);
if (numSop == 0) {
strcpy(info, "PLEASE SELECT SERVICE CLASS AS AN ASSOCIATION INITIATOR FROM SCROLLEDLIST 2 \n");
copyWtext2(info);
} else {
if (params.requestedPresentationContext == NULL) {
params.requestedPresentationContext = LST_Create();
if (params.requestedPresentationContext == NULL) {
return;
}
}
se = LST_Head(&selectedsopList);
(void) LST_Position(&selectedsopList, se);
for (i = 1; i <= numSop; i++) {
context = (DUL_PRESENTATIONCONTEXT *) malloc(sizeof(*context));
if (context == NULL) {
printf(" Error in malloc context\n");
return;
} else {
cond = DUL_MakePresentationCtx(&context, se->role, se->role,
contextID, 0,
se->selectedsopclassW, "",
se->tSyntaxes[0],
se->tSyntaxes[1],
se->tSyntaxes[2],
NULL);
if (cond != DUL_NORMAL) {
(void) COND_ExtractConditions(errorstackP);
copyWtext2(info);
(void) COND_PopCondition(clearStack);
} else {
cond = LST_Enqueue(¶ms.requestedPresentationContext, context);
if (cond != LST_NORMAL)
(void) COND_ExtractConditions(errorstackP);
copyWtext2(info);
(void) COND_PopCondition(clearStack);
contextID += 2;
}
}
se = LST_Next(&selectedsopList);
}
cond = DUL_RequestAssociation(&network, ¶ms, &association);
association_on = TRUE;
if (cond != DUL_NORMAL) {
if (cond == DUL_ASSOCIATIONREJECTED) {
buffer = calloc(100, sizeof(char));
memset(buffer, 0, sizeof(buffer));
buff = calloc(20, sizeof(char));
memset(buff, 0, sizeof(buff));
strcat(buffer, " Result : ");
sprintf(buff, "%2x", params.result);
strcat(buffer, buff);
strcat(buffer, ", resultSource : ");
sprintf(buff, "%2x", params.resultSource);
strcat(buffer, buff);
strcat(buffer, ", diagnostic : ");
sprintf(buff, "%2x", params.diagnostic);
strcat(buffer, buff);
strcat(info, buffer);
strcat(info, "\n");
copyWtext2(info);
free(buffer);
free(buff);
}
association_on = FALSE;
(void) COND_ExtractConditions(errorstackP);
copyWtext2(info);
(void) COND_PopCondition(clearStack);
} else {
context = LST_Head(¶ms.acceptedPresentationContext);
if (context != NULL) {
context = LST_Position(¶ms.acceptedPresentationContext, context);
}
while (context != NULL) {
ctxresult = (int) context->result;
cond = UID_Lookup(context->acceptedTransferSyntax, &d);
sprintf(bufsyn, "%30s", d.description);
sprintf(buf1, "%30s", context->abstractSyntax);
cond = UID_Lookup(context->abstractSyntax, &d);
if (cond = UID_NORMAL) {
sprintf(buf2, "%s,%s ", d.description, d.originator);
}
context = LST_Next(¶ms.acceptedPresentationContext);
strcat(info, buf1);
strcat(info, " ");
strcat(info, buf2);
strcat(info, " ");
strcat(info, bufsyn);
/** buffer = calloc(100, sizeof(char));
memset(buffer, 0, sizeof(buffer));
buff = calloc(20, sizeof(char));
memset(buff, 0, sizeof(buff));**/
switch (ctxresult) {
case 0:
strcat(info, " (ACCEPTED)\n");
copyWtext2(info);
break;
case 1:
strcat(info, " (REJECTED_USER)\n");
/** strcat(buffer," Result : ");
sprintf(buff, "%2x", params.result);
strcat(buffer,buff);
strcat(buffer,", resultSource : ");
sprintf(buff, "%2x", params.resultSource);
strcat(buffer,buff);
strcat(buffer,", diagnostic : ");
sprintf(buff, "%2x", params.diagnostic);
strcat(buffer,buff);
strcat(info,buffer);
strcat(info,"\n");**/
copyWtext2(info);
break;
case 2:
strcat(info, " (REJECTED_NOREASON)\n");
/** strcat(buffer," Result : ");
sprintf(buff, "%2x", params.result);
strcat(buffer,buff);
strcat(buffer,", resultSource : ");
sprintf(buff, "%2x", params.resultSource);
strcat(buffer,buff);
strcat(buffer,", diagnostic : ");
sprintf(buff, "%2x", params.diagnostic);
strcat(buffer,buff);
strcat(info,buffer);
strcat(info,"\n");**/
copyWtext2(info);
break;
case 3:
strcat(info, " (REJECTED_ABSTRACT_SYNTAX)\n");
/** strcat(buffer," Result : ");
sprintf(buff, "%2x", params.result);
strcat(buffer,buff);
strcat(buffer,", resultSource : ");
sprintf(buff, "%2x", params.resultSource);
strcat(buffer,buff);
strcat(buffer,", diagnostic : ");
sprintf(buff, "%2x", params.diagnostic);
strcat(buffer,buff);
strcat(info,buffer);
strcat(info,"\n");**/
copyWtext2(info);
break;
case 4:
strcat(info, " (REJECTED_TRANSFER_SYNTAX)\n");
/** strcat(buffer," Result : ");
sprintf(buff, "%2x", params.result);
strcat(buffer,buff);
strcat(buffer,", resultSource : ");
sprintf(buff, "%2x", params.resultSource);
strcat(buffer,buff);
strcat(buffer,", diagnostic : ");
sprintf(buff, "%2x", params.diagnostic);
strcat(buffer,buff);
strcat(info,buffer);
strcat(info,"\n");**/
copyWtext2(info);
break;
default:
break;
}
/** free(buffer);
free(buff);**/
}
}
}
}
/* errorstackP
**
** Purpose:
** This function is called for each condition on the stack.
**
** Parameter Dictionary:
** v condition value, identifies the facility which
** generates error, severity of the error and the
** actual error itself.
** mes character string, associated condition message
** which identifies the nature of the error.
**
** Return Values:
** TRUE to extract all the messages
**
** Notes:
**
** Algorithm:
** Description of the algorithm (optional) and any other notes.
*/
CTNBOOLEAN
errorstackP(unsigned long v, char *mes)
{
char *buff;
buff = calloc(20, sizeof(char));
memset(buff, 0, sizeof(buff));
sprintf(buff, "%8x", v);
strcat(info, buff);
strcat(info, " ");
if (CTN_ERROR(v))
strcat(info, " ERROR ");
if (CTN_WARNING(v))
strcat(info, " WARNING ");
if (CTN_FATAL(v))
strcat(info, " FATAL ");
if (CTN_INFORM(v))
strcat(info, " INFORMATION ");
/* strncat(info, mes, strlen(mes));*/
strcat(info, mes);
strcat(info, "\n");
free(buff);
return (TRUE);
}
/* request_release
**
** Purpose:
** This subroutine requests an orderly release or abort of an
** Association with a server. If fails to do so, then drops
** an Association without notifying the peer application and
** destroys the caller's reference to the Association.
**
** Parameter Dictionary:
** None
**
** Return Values:
** None
**
** Notes:
**
** Algorithm:
** Description of the algorithm (optional) and any other notes.
*/
void
request_release()
{
CONDITION /* Return values from DUL and ACR routines */
cond = 0;
(void) DUL_ClearServiceParameters(¶ms);
if (association)
cond = DUL_ReleaseAssociation(&association);
if (cond != DUL_RELEASECONFIRMED) {
cond = DUL_AbortAssociation(&association);
}
(void) DUL_DropAssociation(&association);
strcpy(info, " Association has been released \n");
copyWtext2(info);
memset(info, 0, sizeof(info));
}
/*closeNetworkConnection
**
**
** Purpose:
** This subroutine closes network connection with the server.
** Parameter Dictionary:
** None
**
** Return Values:
** None
**
** Notes:
**
** Algorithm:
** Description of the algorithm (optional) and any other notes.
*/
void
closeNetworkConnection()
{
(void) DUL_ClearServiceParameters(¶ms);
if (sopList != NULL)
(void) LST_Destroy(&sopList);
if (selectedsopList != NULL)
(void) LST_Destroy(&selectedsopList);
(void) DUL_DropNetwork(&network);
}
|