1 /*  objsub.c
2 * ===========================================================================
3 *
4 *                            PUBLIC DOMAIN NOTICE
5 *               National Center for Biotechnology Information
6 *
7 *  This software/database is a "United States Government Work" under the
8 *  terms of the United States Copyright Act.  It was written as part of
9 *  the author's official duties as a United States Government employee and
10 *  thus cannot be copyrighted.  This software/database is freely available
11 *  to the public for use. The National Library of Medicine and the U.S.
12 *  Government have not placed any restriction on its use or reproduction.
13 *
14 *  Although all reasonable efforts have been taken to ensure the accuracy
15 *  and reliability of the software and data, the NLM and the U.S.
16 *  Government do not and cannot warrant the performance or results that
17 *  may be obtained by using this software or data. The NLM and the U.S.
18 *  Government disclaim all warranties, express or implied, including
19 *  warranties of performance, merchantability or fitness for any particular
20 *  purpose.
21 *
22 *  Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * File Name:  objsub.c
27 *
28 * Author:  James Ostell
29 *
30 * Version Creation Date: 1/1/91
31 *
32 * $Revision: 6.6 $
33 *
34 * File Description:  Object manager for module NCBI-Submit
35 *
36 * Modifications:
37 * --------------------------------------------------------------------------
38 * Date	   Name        Description of modification
39 * -------  ----------  -----------------------------------------------------
40 * 05-13-93 Schuler     All public functions are now declared LIBCALL.
41 *
42 *
43 * $Log: objsub.c,v $
44 * Revision 6.6  2015/10/23 00:04:25  kans
45 * NOIJRA Clear av DataVal variable on AsnWrite, needed for supporting Int8 integers in ASN.1
46 *
47 * Revision 6.5  2005/05/20 21:08:43  bollin
48 * allow SubmitBlocks to match if both have NULL CitSubs
49 *
50 * Revision 6.4  2005/05/18 17:31:43  bollin
51 * added ContactInfoMatch and SubmitBlockMatch functions
52 *
53 * Revision 6.3  2004/05/12 20:41:57  kans
54 * set aip->io_failure in several erret blocks for compatibility of old object loaders with new ones
55 *
56 * Revision 6.2  2004/04/01 13:43:08  lavr
57 * Spell "occurred", "occurrence", and "occurring"
58 *
59 * Revision 6.1  1998/08/24 18:28:12  kans
60 * removed solaris -v -fd warnings
61 *
62 * Revision 6.0  1997/08/25 18:51:01  madden
63 * Revision changed to 6.0
64 *
65 * Revision 4.1  1997/06/19 18:42:11  vakatov
66 * [WIN32,MSVC++]  Adopted for the "NCBIOBJ.LIB" DLL'ization
67 *
68 * Revision 4.0  1995/07/26 13:48:06  ostell
69 * force revision to 4.0
70 *
71  * Revision 3.9  1995/06/01  02:50:31  ostell
72  * corrected minor typo
73  *
74  * Revision 3.8  1995/05/30  15:52:32  ostell
75  * removed unused local variables
76  *
77  * Revision 3.7  1995/05/15  21:22:00  ostell
78  * added Log line
79  *
80 *
81 *
82 * ==========================================================================
83 */
84 #include <asnsubmt.h>        /* the AsnTool header */
85 #include <objsub.h>		   /* the general objects interface */
86 #include <objmgr.h>
87 
88 static Boolean loaded = FALSE;
89 
90 /*****************************************************************************
91 *
92 *   SeqSubmit ObjMgr Routines
93 *
94 *****************************************************************************/
95 static CharPtr seqsubtypename = "SeqSubmit";
96 
SeqSubmitNewFunc(void)97 static Pointer LIBCALLBACK SeqSubmitNewFunc (void)
98 {
99 	return (Pointer) SeqSubmitNew();
100 }
101 
SeqSubmitFreeFunc(Pointer data)102 static Pointer LIBCALLBACK SeqSubmitFreeFunc (Pointer data)
103 {
104 	return (Pointer) SeqSubmitFree ((SeqSubmitPtr) data);
105 }
106 
SeqSubmitAsnWriteFunc(Pointer data,AsnIoPtr aip,AsnTypePtr atp)107 static Boolean LIBCALLBACK SeqSubmitAsnWriteFunc (Pointer data, AsnIoPtr aip, AsnTypePtr atp)
108 {
109 	return SeqSubmitAsnWrite((SeqSubmitPtr)data, aip, atp);
110 }
111 
SeqSubmitAsnReadFunc(AsnIoPtr aip,AsnTypePtr atp)112 static Pointer LIBCALLBACK SeqSubmitAsnReadFunc (AsnIoPtr aip, AsnTypePtr atp)
113 {
114 	return (Pointer) SeqSubmitAsnRead (aip, atp);
115 }
116 
SeqSubmitLabelFunc(Pointer data,CharPtr buffer,Int2 buflen,Uint1 content)117 static Int2 LIBCALLBACK SeqSubmitLabelFunc ( Pointer data, CharPtr buffer, Int2 buflen, Uint1 content)
118 {
119 	return SeqSubmitLabel((SeqSubmitPtr)data, buffer, buflen, content);
120 }
121 
SeqSubmitLabel(SeqSubmitPtr ssp,CharPtr buffer,Int2 buflen,Uint1 content)122 NLM_EXTERN Int2 LIBCALL SeqSubmitLabel (SeqSubmitPtr ssp, CharPtr buffer, Int2 buflen, Uint1 content)
123 {
124 	static CharPtr seqsubtypes[4] = {
125 		"Not Set",
126 		"Entries",
127 		"Annotations",
128 		"Deletions"};
129 	Int2 i = 0, len, diff;
130 
131 	if ((ssp == NULL) || (buflen < 1))
132 		return 0;
133 
134 	len = buflen;
135 
136 	if ((ssp->datatype >= 1) && (ssp->datatype <= 3))
137 		i = (Int2)(ssp->datatype);
138 
139 	if (content == OM_LABEL_TYPE)
140 		return LabelCopy(buffer, seqsubtypes[i], buflen);
141 
142 	if (content != OM_LABEL_CONTENT)
143 	{
144 		diff = LabelCopyExtra(buffer, seqsubtypes[i], buflen, NULL, ": ");
145 		buflen -= diff;
146 		buffer += diff;
147 	}
148 
149 	if (ssp->sub != NULL)
150 	{
151 		if (ssp->sub->contact != NULL)
152 			diff = ContactInfoLabel(ssp->sub->contact, buffer, buflen, OM_LABEL_CONTENT);
153 		else
154 			diff = SubmitBlockLabel(ssp->sub, buffer, buflen, OM_LABEL_CONTENT);
155 		buflen -= diff;
156 		buffer += diff;
157 	}
158 
159 	return (len - buflen);   /* no special SUMMARY yet */
160 }
161 
162 /*****************************************************************************
163 *
164 *   SubmitBlock ObjMgr Routines
165 *
166 *****************************************************************************/
167 static CharPtr subblocktypename = "SubmitBlock";
168 
SubmitBlockNewFunc(void)169 static Pointer LIBCALLBACK SubmitBlockNewFunc (void)
170 {
171 	return (Pointer) SubmitBlockNew();
172 }
173 
SubmitBlockFreeFunc(Pointer data)174 static Pointer LIBCALLBACK SubmitBlockFreeFunc (Pointer data)
175 {
176 	return (Pointer) SubmitBlockFree ((SubmitBlockPtr) data);
177 }
178 
SubmitBlockAsnWriteFunc(Pointer data,AsnIoPtr aip,AsnTypePtr atp)179 static Boolean LIBCALLBACK SubmitBlockAsnWriteFunc (Pointer data, AsnIoPtr aip, AsnTypePtr atp)
180 {
181 	return SubmitBlockAsnWrite((SubmitBlockPtr)data, aip, atp);
182 }
183 
SubmitBlockAsnReadFunc(AsnIoPtr aip,AsnTypePtr atp)184 static Pointer LIBCALLBACK SubmitBlockAsnReadFunc (AsnIoPtr aip, AsnTypePtr atp)
185 {
186 	return (Pointer) SubmitBlockAsnRead (aip, atp);
187 }
188 
SubmitBlockLabelFunc(Pointer data,CharPtr buffer,Int2 buflen,Uint1 content)189 static Int2 LIBCALLBACK SubmitBlockLabelFunc ( Pointer data, CharPtr buffer, Int2 buflen, Uint1 content)
190 {
191 	return SubmitBlockLabel((SubmitBlockPtr)data, buffer, buflen, content);
192 }
193 
SubmitBlockLabel(SubmitBlockPtr sbp,CharPtr buffer,Int2 buflen,Uint1 content)194 NLM_EXTERN Int2 LIBCALL SubmitBlockLabel (SubmitBlockPtr sbp, CharPtr buffer, Int2 buflen, Uint1 content)
195 {
196 	Int2 len, diff;
197 	CharPtr the_type=NULL;
198 	Char tbuf[40];
199 
200 	if ((sbp == NULL) || (buflen < 1))
201 		return 0;
202 
203 	len = buflen;
204 	the_type = AsnEnumTypeStr(SUBMIT_BLOCK_subtype, (Int2)(sbp->subtype));
205 	if (the_type == NULL)
206 		the_type = "TypeNotSet";
207 
208 	if (content == OM_LABEL_TYPE)
209 		return LabelCopy(buffer, the_type, buflen);
210 
211 	if (content != OM_LABEL_CONTENT)
212 	{
213 		diff = LabelCopyExtra(buffer, the_type, buflen, NULL, ": ");
214 		buflen -= diff;
215 		buffer += diff;
216 	}
217 
218     if (sbp->hup)
219     {
220     	diff = LabelCopy(buffer, " HUP",buflen);
221     	buflen -= diff;
222     	buffer += diff;
223     }
224 
225     if (sbp->reldate)
226     {
227     	DatePrint(sbp->reldate, tbuf);
228     	diff = LabelCopyExtra(buffer, tbuf,buflen," Rel:",NULL);
229     	buflen -= diff;
230     	buffer += diff;
231     }
232 
233     if (sbp->tool != NULL)
234     {
235     	diff = LabelCopyExtra(buffer, sbp->tool,buflen," ",NULL);
236     	buflen -= diff;
237     	buffer += diff;
238     }
239 
240     if (sbp->user_tag != NULL)
241     {
242     	diff = LabelCopyExtra(buffer, sbp->user_tag,buflen,"[","]");
243     	buflen -= diff;
244     	buffer += diff;
245     }
246 
247     if (sbp->comment != NULL)
248     {
249     	diff = LabelCopyExtra(buffer, sbp->comment,buflen," ",NULL);
250     	buflen -= diff;
251     	buffer += diff;
252     }
253 
254 
255 	return (len - buflen);   /* no special SUMMARY yet */
256 
257 }
258 
259 /*****************************************************************************
260 *
261 *   ContactInfo ObjMgr Routines
262 *
263 *****************************************************************************/
264 static CharPtr contactinfotypename = "Contact Info";
265 
ContactInfoNewFunc(void)266 static Pointer LIBCALLBACK ContactInfoNewFunc (void)
267 {
268 	return (Pointer) ContactInfoNew();
269 }
270 
ContactInfoFreeFunc(Pointer data)271 static Pointer LIBCALLBACK ContactInfoFreeFunc (Pointer data)
272 {
273 	return (Pointer) ContactInfoFree ((ContactInfoPtr) data);
274 }
275 
ContactInfoAsnWriteFunc(Pointer data,AsnIoPtr aip,AsnTypePtr atp)276 static Boolean LIBCALLBACK ContactInfoAsnWriteFunc (Pointer data, AsnIoPtr aip, AsnTypePtr atp)
277 {
278 	return ContactInfoAsnWrite((ContactInfoPtr)data, aip, atp);
279 }
280 
ContactInfoAsnReadFunc(AsnIoPtr aip,AsnTypePtr atp)281 static Pointer LIBCALLBACK ContactInfoAsnReadFunc (AsnIoPtr aip, AsnTypePtr atp)
282 {
283 	return (Pointer) ContactInfoAsnRead (aip, atp);
284 }
285 
ContactInfoLabelFunc(Pointer data,CharPtr buffer,Int2 buflen,Uint1 content)286 static Int2 LIBCALLBACK ContactInfoLabelFunc ( Pointer data, CharPtr buffer, Int2 buflen, Uint1 content)
287 {
288 	return ContactInfoLabel((ContactInfoPtr)data, buffer, buflen, content);
289 }
290 
ContactInfoLabel(ContactInfoPtr cip,CharPtr buffer,Int2 buflen,Uint1 content)291 NLM_EXTERN Int2 LIBCALL ContactInfoLabel (ContactInfoPtr cip, CharPtr buffer, Int2 buflen, Uint1 content)
292 {
293 	Int2 len, diff;
294 	CharPtr the_contact=NULL;
295 
296 	if ((cip == NULL) || (buflen < 1))
297 		return 0;
298 
299 	len = buflen;
300 
301 	if (content == OM_LABEL_TYPE)
302 		return LabelCopy(buffer, contactinfotypename, buflen);
303 
304 	if (content != OM_LABEL_CONTENT)
305 	{
306 		diff = LabelCopyExtra(buffer, contactinfotypename, buflen, NULL, ": ");
307 		buflen -= diff;
308 		buffer += diff;
309 	}
310 
311 	if (cip->contact != NULL)
312 	{
313 		diff = PersonIdLabel(cip->contact->name, buffer, buflen, PIDLABEL_GENBANK);
314 	}
315 	else
316 	{
317 		if (cip->name != NULL)
318 			the_contact = cip->name;
319 		else if (cip->last_name != NULL)
320 			the_contact = cip->last_name;
321 		else
322 			the_contact = "NotSet";
323 
324 		diff = LabelCopy(buffer, the_contact, buflen);
325 	}
326 
327 	buflen -= diff;
328 	buffer += diff;
329 
330 	return (len - buflen);   /* no special SUMMARY yet */
331 
332 }
333 
334 /*****************************************************************************
335 *
336 *   SubmitAsnLoad()
337 *
338 *****************************************************************************/
SubmitAsnLoad(void)339 NLM_EXTERN Boolean LIBCALL SubmitAsnLoad (void)
340 {
341     if (loaded)
342         return TRUE;
343 
344 	if (! SeqSetAsnLoad ())
345 		return FALSE;
346 
347     if (AsnLoad())
348         loaded = TRUE;
349 
350 	ObjMgrTypeLoad(OBJ_SEQSUB, "Seq-submit", seqsubtypename, "Sequence Data Submission",
351 		SEQ_SUBMIT, SeqSubmitNewFunc, SeqSubmitAsnReadFunc, SeqSubmitAsnWriteFunc,
352 		SeqSubmitFreeFunc, SeqSubmitLabelFunc, NULL);
353 
354 	ObjMgrTypeLoad(OBJ_SUBMIT_BLOCK, "Submit-block", subblocktypename, "Data Submission Block",
355 		SUBMIT_BLOCK, SubmitBlockNewFunc, SubmitBlockAsnReadFunc, SubmitBlockAsnWriteFunc,
356 		SubmitBlockFreeFunc, SubmitBlockLabelFunc, NULL);
357 
358 	ObjMgrTypeLoad(OBJ_SEQSUB_CONTACT, "Contact-info", contactinfotypename, "Contact Info",
359 		CONTACT_INFO, ContactInfoNewFunc, ContactInfoAsnReadFunc, ContactInfoAsnWriteFunc,
360 		ContactInfoFreeFunc, ContactInfoLabelFunc, NULL);
361 
362     return loaded;
363 }
364 
365 /*****************************************************************************
366 *
367 *   SeqSubmit Routines
368 *
369 *****************************************************************************/
370 
371 
372 /*****************************************************************************
373 *
374 *   SeqSubmitNew()
375 *
376 *****************************************************************************/
SeqSubmitNew(void)377 NLM_EXTERN SeqSubmitPtr LIBCALL SeqSubmitNew (void)
378 {
379 	SeqSubmitPtr ssp;
380 
381 	ssp = (SeqSubmitPtr)MemNew(sizeof(SeqSubmit));
382 	ObjMgrAdd (OBJ_SEQSUB, (Pointer)ssp);   /* add to objmgr list */
383 	return ssp;
384 }
385 /*****************************************************************************
386 *
387 *   SeqSubmitFree(ssp)
388 *
389 *****************************************************************************/
SeqSubmitFree(SeqSubmitPtr ssp)390 NLM_EXTERN SeqSubmitPtr LIBCALL SeqSubmitFree (SeqSubmitPtr ssp)
391 {
392 	SeqEntryPtr sep, sepnext;
393 	SeqAnnotPtr sap, sapnext;
394 
395 	if (ssp == NULL)
396 		return ssp;
397 
398 	SubmitBlockFree(ssp->sub);
399 	switch	(ssp->datatype)
400 	{
401 		case 1:
402 			sep = (SeqEntryPtr)ssp->data;
403 			while (sep != NULL)
404 			{
405 				sepnext = sep->next;
406 				SeqEntryFree(sep);
407 				sep = sepnext;
408 			}
409 			break;
410 		case 2:
411 			sap = (SeqAnnotPtr)ssp->data;
412 			while (sap != NULL)
413 			{
414 				sapnext = sap->next;
415 				SeqAnnotFree(sap);
416 				sap = sapnext;
417 			}
418 			break;
419 		case 3:
420 			SeqIdSetFree((SeqIdPtr)ssp->data);
421 			break;
422 	}
423 
424 	if (! ObjMgrDelete(OBJ_SEQSUB, (Pointer)ssp))
425 	    ErrPostEx(SEV_ERROR, 0,0, "SeqSubmitFree: pointer not registered");
426 
427 	return (SeqSubmitPtr)MemFree(ssp);
428 }
429 
430 /*****************************************************************************
431 *
432 *   SeqSubmitAsnWrite(ssp, aip, atp)
433 *   	atp is the current type (if identifier of a parent struct)
434 *       if atp == NULL, then assumes it stands alone (SeqSubmit ::=)
435 *
436 *****************************************************************************/
SeqSubmitAsnWrite(SeqSubmitPtr ssp,AsnIoPtr aip,AsnTypePtr orig)437 NLM_EXTERN Boolean LIBCALL SeqSubmitAsnWrite (SeqSubmitPtr ssp, AsnIoPtr aip, AsnTypePtr orig)
438 {
439 	DataVal av;
440 	AsnTypePtr atp;
441     Boolean retval = FALSE;
442 	SeqEntryPtr sep;
443 	SeqAnnotPtr sap;
444 
445 	if (! loaded)
446 	{
447 		if (! SubmitAsnLoad())
448 			return FALSE;
449 	}
450 
451 	if (aip == NULL)
452 		return FALSE;
453 
454 	atp = AsnLinkType(orig, SEQ_SUBMIT);   /* link local tree */
455     if (atp == NULL)
456         return FALSE;
457 
458 	if (ssp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
459 
460     MemSet ((Pointer) (&av), 0, sizeof (DataVal));
461 
462     if (! AsnOpenStruct(aip, atp, (Pointer)ssp))
463         goto erret;
464 
465 	if (! SubmitBlockAsnWrite(ssp->sub, aip, SEQ_SUBMIT_sub)) goto erret;
466 
467 	av.ptrvalue = ssp->data;
468     if (! AsnWriteChoice(aip, SEQ_SUBMIT_data, (Int2)ssp->datatype, &av)) goto erret;
469 
470 	switch(ssp->datatype)
471 	{
472 		case 1:
473 			if (! AsnOpenStruct(aip, SEQ_SUBMIT_data_entrys, ssp->data)) goto erret;
474 			sep = (SeqEntryPtr) ssp->data;
475 			while (sep != NULL)
476 			{
477 				if (! SeqEntryAsnWrite(sep, aip, SEQ_SUBMIT_data_entrys_E)) goto erret;
478 				sep = sep->next;
479 			}
480 			if (! AsnCloseStruct(aip, SEQ_SUBMIT_data_entrys, ssp->data)) goto erret;
481 			break;
482 		case 2:
483 			if (! AsnOpenStruct(aip, SEQ_SUBMIT_data_annots, ssp->data)) goto erret;
484 			sap = (SeqAnnotPtr) ssp->data;
485 			while (sap != NULL)
486 			{
487 				if (! SeqAnnotAsnWrite(sap, aip, SEQ_SUBMIT_data_annots_E)) goto erret;
488 				sap = sap->next;
489 			}
490 			if (! AsnCloseStruct(aip, SEQ_SUBMIT_data_annots, ssp->data)) goto erret;
491 			break;
492 		case 3:
493 			if (! SeqIdSetAsnWrite((SeqIdPtr)ssp->data, aip, SEQ_SUBMIT_data_delete,
494 				SEQ_SUBMIT_data_delete_E)) goto erret;
495 			break;
496 		default:
497 			ErrPost(CTX_NCBIOBJ, 1, "Unknown Seq-submit type = %d", (int) ssp->datatype);
498 			goto erret;
499 	}
500     if (! AsnCloseStruct(aip, atp, (Pointer)ssp))
501         goto erret;
502     retval = TRUE;
503 erret:
504 	AsnUnlinkType(orig);       /* unlink local tree */
505 	return retval;
506 }
507 
508 /*****************************************************************************
509 *
510 *   SeqSubmitAsnRead(aip, atp)
511 *   	atp is the current type (if identifier of a parent struct)
512 *            assumption is readIdent has occurred
513 *       if atp == NULL, then assumes it stands alone and read ident
514 *            has not occurred.
515 *
516 *****************************************************************************/
SeqSubmitAsnRead(AsnIoPtr aip,AsnTypePtr orig)517 NLM_EXTERN SeqSubmitPtr LIBCALL SeqSubmitAsnRead (AsnIoPtr aip, AsnTypePtr orig)
518 {
519 	DataVal av;
520 	AsnTypePtr atp, oldatp;
521     SeqSubmitPtr ssp=NULL;
522 	SeqEntryPtr sep, seplast = NULL;
523 	SeqAnnotPtr sap, saplast = NULL;
524 	SeqIdPtr sip, siplast = NULL;
525 
526 	if (! loaded)
527 	{
528 		if (! SubmitAsnLoad())
529 			return ssp;
530 	}
531 
532 	if (aip == NULL)
533 		return ssp;
534 
535 	if (orig == NULL)           /* SeqSubmit ::= (self contained) */
536 		atp = AsnReadId(aip, amp, SEQ_SUBMIT);
537 	else
538 		atp = AsnLinkType(orig, SEQ_SUBMIT);    /* link in local tree */
539     if (atp == NULL)
540         return ssp;
541 
542 	ssp = SeqSubmitNew();
543     if (ssp == NULL)
544         goto erret;
545 
546 	if (AsnReadVal(aip, atp, &av) <= 0)    /* read the start struct */
547         goto erret;
548 
549 	atp = AsnReadId(aip, amp, atp);  /* find the submission-block */
550     if (atp == NULL) goto erret;
551 	ssp->sub = SubmitBlockAsnRead(aip, atp);
552 	if (ssp->sub == NULL) goto erret;
553 
554     atp = AsnReadId(aip, amp, atp);  /* read the CHOICE */
555     if (atp == NULL) goto erret;
556     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
557 
558     atp = AsnReadId(aip, amp, atp);  /* read the data */
559     if (atp == NULL) goto erret;
560 	oldatp = atp;     /* the SET OF */
561     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
562 
563     while ((atp = AsnReadId(aip, amp, atp)) != oldatp)
564     {
565 		if (atp == SEQ_SUBMIT_data_entrys_E)
566 		{
567 			sep = SeqEntryAsnRead(aip, atp);
568 			if (sep == NULL) goto erret;
569 			if (IS_Bioseq(sep))
570 				ObjMgrConnect(OBJ_BIOSEQ, sep->data.ptrvalue,
571 					OBJ_SEQSUB, (Pointer) ssp);
572 			else
573 				ObjMgrConnect(OBJ_BIOSEQSET, sep->data.ptrvalue,
574 					OBJ_SEQSUB, (Pointer) ssp);
575 
576 			if (seplast == NULL)
577 			{
578 				ssp->data = (Pointer) sep;
579 				ssp->datatype = 1;
580 			}
581 			else
582 				seplast->next = sep;
583 			seplast = sep;
584 		}
585 		else if (atp == SEQ_SUBMIT_data_annots_E)
586 		{
587 			sap = SeqAnnotAsnRead(aip, atp);
588 			if (sap == NULL) goto erret;
589 			if (saplast == NULL)
590 			{
591 				ssp->data = (Pointer) sap;
592 				ssp->datatype = 2;
593 			}
594 			else
595 				saplast->next = sap;
596 			saplast = sap;
597 		}
598 		else if (atp == SEQ_SUBMIT_data_delete_E)
599 		{
600 			sip = SeqIdAsnRead(aip, atp);
601 			if (sip == NULL) goto erret;
602 			if (siplast == NULL)
603 			{
604 				ssp->data = (Pointer) sip;
605 				ssp->datatype = 3;
606 			}
607 			else
608 				siplast->next = sip;
609 			siplast = sip;
610 		}
611 		else
612 			goto erret;
613     }
614     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* end set of */
615 
616     atp = AsnReadId(aip, amp, atp);
617     if (atp == NULL) goto erret;
618     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;  /* end struct */
619 ret:
620 	AsnUnlinkType(orig);       /* unlink local tree */
621 	return ssp;
622 erret:
623     aip->io_failure = TRUE;
624     ssp = SeqSubmitFree(ssp);
625     goto ret;
626 }
627 
628 /*****************************************************************************
629 *
630 *   SubmitBlockNew()
631 *
632 *****************************************************************************/
SubmitBlockNew(void)633 NLM_EXTERN SubmitBlockPtr LIBCALL SubmitBlockNew (void)
634 {
635 	return (SubmitBlockPtr)MemNew(sizeof(SubmitBlock));
636 }
637 
638 /*****************************************************************************
639 *
640 *   SubmitBlockFree(sbp)
641 *
642 *****************************************************************************/
SubmitBlockFree(SubmitBlockPtr sbp)643 NLM_EXTERN SubmitBlockPtr LIBCALL SubmitBlockFree (SubmitBlockPtr sbp)
644 {
645 	if (sbp == NULL)
646 		return sbp;
647 	ContactInfoFree(sbp->contact);
648 	CitSubFree(sbp->cit);
649 	DateFree(sbp->reldate);
650 	MemFree(sbp->tool);
651 	MemFree(sbp->user_tag);
652 	MemFree(sbp->comment);
653 
654 	ObjMgrDelete(OBJ_SUBMIT_BLOCK, (Pointer)sbp);
655 
656 	return (SubmitBlockPtr)MemFree(sbp);
657 }
658 
659 /*****************************************************************************
660 *
661 *   SubmitBlockAsnWrite(sbp, aip, atp)
662 *   	atp is the current type (if identifier of a parent struct)
663 *       if atp == NULL, then assumes it stands alone (SubmitBlock ::=)
664 *
665 *****************************************************************************/
SubmitBlockAsnWrite(SubmitBlockPtr sbp,AsnIoPtr aip,AsnTypePtr orig)666 NLM_EXTERN Boolean LIBCALL SubmitBlockAsnWrite (SubmitBlockPtr sbp, AsnIoPtr aip, AsnTypePtr orig)
667 {
668 	DataVal av;
669 	AsnTypePtr atp;
670     Boolean retval = FALSE;
671 
672 	if (! loaded)
673 	{
674 		if (! SubmitAsnLoad())
675 			return FALSE;
676 	}
677 
678 	if (aip == NULL)
679 		return FALSE;
680 
681 	atp = AsnLinkType(orig, SUBMIT_BLOCK);   /* link local tree */
682     if (atp == NULL)
683         return FALSE;
684 
685 	if (sbp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
686 
687     MemSet ((Pointer) (&av), 0, sizeof (DataVal));
688 
689     if (! AsnOpenStruct(aip, atp, (Pointer)sbp))
690         goto erret;
691 
692 	if (! ContactInfoAsnWrite(sbp->contact, aip, SUBMIT_BLOCK_contact))
693 		goto erret;
694 
695 	if (! CitSubAsnWrite(sbp->cit, aip, SUBMIT_BLOCK_cit)) goto erret;
696 
697 	if (sbp->hup)
698 	{
699 		av.boolvalue = sbp->hup;
700 		if (! AsnWrite(aip, SUBMIT_BLOCK_hup, &av)) goto erret;
701 	}
702 
703 	if (sbp->reldate != NULL)
704 	{
705 		if (! DateAsnWrite(sbp->reldate, aip, SUBMIT_BLOCK_reldate))
706 			goto erret;
707 	}
708 
709 	if (sbp->subtype)
710 	{
711 		av.intvalue = (Int4)sbp->subtype;
712 		if (! AsnWrite(aip, SUBMIT_BLOCK_subtype, &av)) goto erret;
713 	}
714 
715 	if (sbp->tool != NULL)
716 	{
717 		av.ptrvalue = sbp->tool;
718 		if (! AsnWrite(aip, SUBMIT_BLOCK_tool, &av)) goto erret;
719 	}
720 
721 	if (sbp->user_tag != NULL)
722 	{
723 		av.ptrvalue = sbp->user_tag;
724 		if (! AsnWrite(aip, SUBMIT_BLOCK_user_tag, &av)) goto erret;
725 	}
726 
727 	if (sbp->comment != NULL)
728 	{
729 		av.ptrvalue = sbp->comment;
730 		if (! AsnWrite(aip, SUBMIT_BLOCK_comment, &av)) goto erret;
731 	}
732 
733 
734     if (! AsnCloseStruct(aip, atp, (Pointer)sbp))
735         goto erret;
736     retval = TRUE;
737 erret:
738 	AsnUnlinkType(orig);       /* unlink local tree */
739 	return retval;
740 }
741 
742 /*****************************************************************************
743 *
744 *   SubmitBlockAsnRead(aip, atp)
745 *   	atp is the current type (if identifier of a parent struct)
746 *            assumption is readIdent has occurred
747 *       if atp == NULL, then assumes it stands alone and read ident
748 *            has not occurred.
749 *
750 *****************************************************************************/
SubmitBlockAsnRead(AsnIoPtr aip,AsnTypePtr orig)751 NLM_EXTERN SubmitBlockPtr LIBCALL SubmitBlockAsnRead (AsnIoPtr aip, AsnTypePtr orig)
752 {
753 	DataVal av;
754 	AsnTypePtr atp, oldatp;
755     SubmitBlockPtr sbp=NULL;
756 
757 	if (! loaded)
758 	{
759 		if (! SubmitAsnLoad())
760 			return sbp;
761 	}
762 
763 	if (aip == NULL)
764 		return sbp;
765 
766 	if (orig == NULL)           /* SubmitBlock ::= (self contained) */
767 		atp = AsnReadId(aip, amp, SUBMIT_BLOCK);
768 	else
769 		atp = AsnLinkType(orig, SUBMIT_BLOCK);    /* link in local tree */
770     if (atp == NULL)
771         return sbp;
772 
773 	oldatp = atp;
774 	sbp = SubmitBlockNew();
775     if (sbp == NULL)
776         goto erret;
777 
778 	if (AsnReadVal(aip, atp, &av) <= 0)    /* read the start struct */
779         goto erret;
780 
781 	while ((atp = AsnReadId(aip, amp, atp)) != oldatp)
782 	{
783 		if (atp == NULL) goto erret;
784 		if (atp == SUBMIT_BLOCK_contact)
785 		{
786 			sbp->contact = ContactInfoAsnRead(aip, atp);
787 			if (sbp->contact == NULL) goto erret;
788 		}
789 		else if (atp == SUBMIT_BLOCK_cit)
790 		{
791 			sbp->cit = CitSubAsnRead(aip, atp);
792 			if (sbp->cit == NULL) goto erret;
793 		}
794 		else if (atp == SUBMIT_BLOCK_reldate)
795 		{
796 			sbp->reldate = DateAsnRead(aip, atp);
797 			if (sbp->reldate == NULL) goto erret;
798 		}
799 		else
800 		{
801 			if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
802 			if (atp == SUBMIT_BLOCK_hup)
803 				sbp->hup = av.boolvalue;
804 			else if (atp == SUBMIT_BLOCK_subtype)
805 				sbp->subtype = (Uint1)av.intvalue;
806 			else if (atp == SUBMIT_BLOCK_tool)
807 				sbp->tool = (CharPtr)av.ptrvalue;
808 			else if (atp == SUBMIT_BLOCK_user_tag)
809 				sbp->user_tag = (CharPtr)av.ptrvalue;
810 			else if (atp == SUBMIT_BLOCK_comment)
811 				sbp->comment = (CharPtr)av.ptrvalue;
812 
813 		}
814 	}
815 
816     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;  /* end struct */
817 ret:
818 	AsnUnlinkType(orig);       /* unlink local tree */
819 	return sbp;
820 erret:
821     aip->io_failure = TRUE;
822     sbp = SubmitBlockFree(sbp);
823     goto ret;
824 }
825 
826 /*****************************************************************************
827 *
828 *   SubmitBlockMatch( sbp1, sbp2)
829 *
830 *****************************************************************************/
SubmitBlockMatch(SubmitBlockPtr sbp1,SubmitBlockPtr sbp2)831 NLM_EXTERN Boolean LIBCALL SubmitBlockMatch (SubmitBlockPtr sbp1, SubmitBlockPtr sbp2)
832 {
833   if (sbp1 == NULL && sbp2 == NULL)
834   {
835     return TRUE;
836   }
837   else if (sbp1 == NULL || sbp2 == NULL)
838   {
839     return FALSE;
840   }
841 
842   if ((sbp1->hup && ! sbp2->hup) || (!sbp1->hup && sbp2->hup))
843   {
844     return FALSE;
845   }
846 
847   if (sbp1->subtype != sbp2->subtype)
848   {
849     return FALSE;
850   }
851 
852   if (StringCmp (sbp1->tool, sbp2->tool) != 0
853       || StringCmp (sbp1->user_tag, sbp2->user_tag) != 0
854       || StringCmp (sbp1->comment, sbp2->comment) != 0)
855   {
856     return FALSE;
857   }
858 
859   /* compare contacts */
860   if (! ContactInfoMatch (sbp1->contact, sbp2->contact))
861   {
862     return FALSE;
863   }
864 
865   /* compare CitSubs */
866   if ((sbp1->cit != NULL || sbp2->cit != NULL)
867        && CitSubMatch (sbp1->cit, sbp2->cit) != 0)
868   {
869     return FALSE;
870   }
871 
872   /* compare dates */
873   if (! DateMatch (sbp1->reldate, sbp2->reldate, TRUE))
874   {
875     return FALSE;
876   }
877 
878   return TRUE;
879 }
880 
881 /*****************************************************************************
882 *
883 *   ContactInfoNew()
884 *
885 *****************************************************************************/
ContactInfoNew(void)886 NLM_EXTERN ContactInfoPtr LIBCALL ContactInfoNew (void)
887 {
888 	return (ContactInfoPtr)MemNew(sizeof(ContactInfo));
889 }
890 
891 /*****************************************************************************
892 *
893 *   ContactInfoFree(cip)
894 *
895 *****************************************************************************/
ContactInfoFree(ContactInfoPtr cip)896 NLM_EXTERN ContactInfoPtr LIBCALL ContactInfoFree (ContactInfoPtr cip)
897 {
898 	if (cip == NULL)
899 		return cip;
900 	MemFree(cip->name);
901 	ValNodeFreeData(cip->address);
902 	MemFree(cip->phone);
903 	MemFree(cip->fax);
904 	MemFree(cip->email);
905 	MemFree(cip->telex);
906 	ObjectIdFree(cip->owner_id);
907 	BSFree(cip->password);
908         MemFree(cip->last_name);
909         MemFree(cip->first_name);
910         MemFree(cip->middle_initial);
911 	AuthorFree(cip->contact);
912 
913 	ObjMgrDelete(OBJ_SEQSUB_CONTACT, (Pointer)cip);
914 
915 	return (ContactInfoPtr)MemFree(cip);
916 }
917 
918 /*****************************************************************************
919 *
920 *   ContactInfoAsnWrite(cip, aip, atp)
921 *   	atp is the current type (if identifier of a parent struct)
922 *       if atp == NULL, then assumes it stands alone (ContactInfo ::=)
923 *
924 *****************************************************************************/
ContactInfoAsnWrite(ContactInfoPtr cip,AsnIoPtr aip,AsnTypePtr orig)925 NLM_EXTERN Boolean LIBCALL ContactInfoAsnWrite (ContactInfoPtr cip, AsnIoPtr aip, AsnTypePtr orig)
926 {
927 	DataVal av;
928 	AsnTypePtr atp;
929     Boolean retval = FALSE;
930 	ValNodePtr vnp;
931 
932 	if (! loaded)
933 	{
934 		if (! SubmitAsnLoad())
935 			return FALSE;
936 	}
937 
938 	if (aip == NULL)
939 		return FALSE;
940 
941 	atp = AsnLinkType(orig, CONTACT_INFO);   /* link local tree */
942     if (atp == NULL)
943         return FALSE;
944 
945 	if (cip == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
946 
947     MemSet ((Pointer) (&av), 0, sizeof (DataVal));
948 
949     if (! AsnOpenStruct(aip, atp, (Pointer)cip))
950         goto erret;
951 
952 	if (cip->name != NULL)
953 	{
954 		av.ptrvalue = cip->name;
955 		if (! AsnWrite(aip, CONTACT_INFO_name, &av)) goto erret;
956 	}
957 
958 	if (cip->address != NULL)
959 	{
960 		vnp = cip->address;
961    	 if (! AsnOpenStruct(aip, CONTACT_INFO_address, (Pointer)vnp))
962       	  goto erret;
963 		while (vnp != NULL)
964 		{
965 			if (! AsnWrite(aip, CONTACT_INFO_address_E, &vnp->data)) goto erret;
966 			vnp = vnp->next;
967 		}
968 	    if (! AsnCloseStruct(aip, CONTACT_INFO_address, (Pointer)vnp))
969    	     goto erret;
970 	}
971 
972 	if (cip->phone != NULL)
973 	{
974 		av.ptrvalue = cip->phone;
975 		if (! AsnWrite(aip, CONTACT_INFO_phone, &av)) goto erret;
976 	}
977 
978 	if (cip->fax != NULL)
979 	{
980 		av.ptrvalue = cip->fax;
981 		if (! AsnWrite(aip, CONTACT_INFO_fax, &av)) goto erret;
982 	}
983 
984 	if (cip->email != NULL)
985 	{
986 		av.ptrvalue = cip->email;
987 		if (! AsnWrite(aip, CONTACT_INFO_email, &av)) goto erret;
988 	}
989 
990 	if (cip->telex != NULL)
991 	{
992 		av.ptrvalue = cip->telex;
993 		if (! AsnWrite(aip, CONTACT_INFO_telex, &av)) goto erret;
994 	}
995 
996 	if (cip->owner_id != NULL)
997 	{
998 		if (! ObjectIdAsnWrite(cip->owner_id, aip, CONTACT_INFO_owner_id)) goto erret;
999 	}
1000 
1001 	if (cip->password != NULL)
1002 	{
1003 		av.ptrvalue = cip->password;
1004 		if (! AsnWrite(aip, CONTACT_INFO_password, &av)) goto erret;
1005 	}
1006 
1007 	if (cip->last_name != NULL)
1008 	{
1009 		av.ptrvalue = cip->last_name;
1010 		if (! AsnWrite(aip, CONTACT_INFO_last_name, &av)) goto erret;
1011 	}
1012 
1013 	if (cip->first_name != NULL)
1014 	{
1015 		av.ptrvalue = cip->first_name;
1016 		if (! AsnWrite(aip, CONTACT_INFO_first_name, &av)) goto erret;
1017 	}
1018 
1019 	if (cip->middle_initial != NULL)
1020 	{
1021 		av.ptrvalue = cip->middle_initial;
1022 		if (! AsnWrite(aip, CONTACT_INFO_middle_initial, &av)) goto erret;
1023 	}
1024 
1025 	if (cip->contact != NULL)
1026 	{
1027 		if (! AuthorAsnWrite(cip->contact, aip, CONTACT_INFO_contact))
1028 			goto erret;
1029 	}
1030 
1031     if (! AsnCloseStruct(aip, atp, (Pointer)cip))
1032         goto erret;
1033     retval = TRUE;
1034 erret:
1035 	AsnUnlinkType(orig);       /* unlink local tree */
1036 	return retval;
1037 }
1038 
1039 /*****************************************************************************
1040 *
1041 *   ContactInfoAsnRead(aip, atp)
1042 *   	atp is the current type (if identifier of a parent struct)
1043 *            assumption is readIdent has occurred
1044 *       if atp == NULL, then assumes it stands alone and read ident
1045 *            has not occurred.
1046 *
1047 *****************************************************************************/
ContactInfoAsnRead(AsnIoPtr aip,AsnTypePtr orig)1048 NLM_EXTERN ContactInfoPtr LIBCALL ContactInfoAsnRead (AsnIoPtr aip, AsnTypePtr orig)
1049 {
1050 	DataVal av;
1051 	AsnTypePtr atp, oldatp;
1052     ContactInfoPtr cip=NULL;
1053 	ValNodePtr vnp = NULL;
1054 
1055 	if (! loaded)
1056 	{
1057 		if (! SubmitAsnLoad())
1058 			return cip;
1059 	}
1060 
1061 	if (aip == NULL)
1062 		return cip;
1063 
1064 	if (orig == NULL)           /* ContactInfo ::= (self contained) */
1065 		atp = AsnReadId(aip, amp, CONTACT_INFO);
1066 	else
1067 		atp = AsnLinkType(orig, CONTACT_INFO);    /* link in local tree */
1068     if (atp == NULL)
1069         return cip;
1070 	oldatp = atp;
1071 
1072 	cip = ContactInfoNew();
1073     if (cip == NULL)
1074         goto erret;
1075 
1076 	if (AsnReadVal(aip, atp, &av) <= 0)    /* read the start struct */
1077         goto erret;
1078 
1079 	while ((atp = AsnReadId(aip, amp, atp)) != oldatp)
1080 	{
1081 		if (atp == NULL) goto erret;
1082 		if (atp == CONTACT_INFO_contact)
1083 		{
1084 			cip->contact = AuthorAsnRead(aip, atp);
1085 			if (cip->contact == NULL) goto erret;
1086 		}
1087 		else if (atp == CONTACT_INFO_address)
1088 		{
1089 			if (AsnReadVal(aip, atp, &av) <= 0)    /* read the start struct */
1090    	   	  goto erret;
1091 			while ((atp = AsnReadId(aip, amp, atp)) == CONTACT_INFO_address_E)
1092 			{
1093 				vnp = ValNodeNew(vnp);
1094 				if (AsnReadVal(aip, atp, &vnp->data) <= 0)    /* read the string */
1095    	 	   	 goto erret;
1096 				if (cip->address == NULL)
1097 					cip->address = vnp;
1098 			}
1099 			if (AsnReadVal(aip, atp, &av) <= 0)    /* read the end struct */
1100    	   	  goto erret;
1101 		}
1102 		else if (atp == CONTACT_INFO_owner_id)
1103 		{
1104 			cip->owner_id = ObjectIdAsnRead(aip, atp);
1105 			if (cip->owner_id == NULL) goto erret;
1106 		}
1107 		else
1108 		{
1109 			if (AsnReadVal(aip, atp, &av) <= 0)    /* read the data */
1110     	    	goto erret;
1111 			if (atp == CONTACT_INFO_name)
1112 				cip->name = (CharPtr)av.ptrvalue;
1113 			else if (atp == CONTACT_INFO_phone)
1114 				cip->phone = (CharPtr)av.ptrvalue;
1115 			else if (atp == CONTACT_INFO_fax)
1116 				cip->fax = (CharPtr)av.ptrvalue;
1117 			else if (atp == CONTACT_INFO_email)
1118 				cip->email = (CharPtr)av.ptrvalue;
1119 			else if (atp == CONTACT_INFO_telex)
1120 				cip->telex = (CharPtr)av.ptrvalue;
1121 			else if (atp == CONTACT_INFO_password)
1122 				cip->password = (ByteStorePtr)av.ptrvalue;
1123 			else if (atp == CONTACT_INFO_last_name)
1124 				cip->last_name = (CharPtr)av.ptrvalue;
1125 			else if (atp == CONTACT_INFO_first_name)
1126 				cip->first_name = (CharPtr)av.ptrvalue;
1127 			else if (atp == CONTACT_INFO_middle_initial)
1128 				cip->middle_initial = (CharPtr)av.ptrvalue;
1129 		}
1130 	}
1131 
1132     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;  /* end struct */
1133 ret:
1134 	AsnUnlinkType(orig);       /* unlink local tree */
1135 	return cip;
1136 erret:
1137     cip = ContactInfoFree(cip);
1138     goto ret;
1139 }
1140 
1141 /*****************************************************************************
1142 *
1143 *   ContactInfoMatch(cip1, cip2)
1144 *
1145 *****************************************************************************/
ContactInfoMatch(ContactInfoPtr cip1,ContactInfoPtr cip2)1146 NLM_EXTERN Boolean LIBCALL ContactInfoMatch (ContactInfoPtr cip1, ContactInfoPtr cip2)
1147 {
1148   Boolean    address_same = TRUE;
1149   ValNodePtr vnp1, vnp2;
1150 
1151   if (cip1 == NULL && cip2 == NULL)
1152   {
1153     return TRUE;
1154   }
1155   else if (cip1 == NULL || cip2 == NULL)
1156   {
1157     return FALSE;
1158   }
1159 
1160   if (StringCmp (cip1->name, cip2->name) != 0
1161       || StringCmp (cip1->phone, cip2->phone) != 0
1162       || StringCmp (cip1->fax, cip2->fax) != 0
1163       || StringCmp (cip1->telex, cip2->telex) != 0
1164       || StringCmp (cip1->last_name, cip2->last_name) != 0
1165       || StringCmp (cip1->first_name, cip2->first_name) != 0
1166       || StringCmp (cip1->middle_initial, cip2->middle_initial) != 0)
1167   {
1168     return FALSE;
1169   }
1170 
1171   for (vnp1 = cip1->address, vnp2 = cip2->address;
1172        vnp1 != NULL && vnp2 != NULL && address_same;
1173        vnp1 = vnp1->next, vnp2 = vnp2->next)
1174   {
1175     if (StringICmp (vnp1->data.ptrvalue, vnp2->data.ptrvalue) != 0)
1176     {
1177       address_same = FALSE;
1178     }
1179   }
1180   if (!address_same || vnp1 != NULL || vnp2 != NULL)
1181   {
1182     return FALSE;
1183   }
1184 
1185   if (! ObjectIdMatch (cip1->owner_id, cip2->owner_id))
1186   {
1187     return FALSE;
1188   }
1189 
1190   if (! AuthorMatch (cip1->contact, cip2->contact))
1191   {
1192     return FALSE;
1193   }
1194   return TRUE;
1195 }
1196