6 * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
7 * Copyright (C) 2009, 2010, MinGW Project
10 * Implementation for the non-inherited components of the pkgXmlNode
11 * class, as declared in file "pkgdesc.h"; fundamentally, these are
12 * the accessors for package "tarname" properties, as specified in
13 * XML nodes identified as "release" elements.
16 * This is free software. Permission is granted to copy, modify and
17 * redistribute this software, under the provisions of the GNU General
18 * Public License, Version 3, (or, at your option, any later version),
19 * as published by the Free Software Foundation; see the file COPYING
20 * for licensing details.
22 * Note, in particular, that this software is provided "as is", in the
23 * hope that it may prove useful, but WITHOUT WARRANTY OF ANY KIND; not
24 * even an implied WARRANTY OF MERCHANTABILITY, nor of FITNESS FOR ANY
25 * PARTICULAR PURPOSE. Under no circumstances will the author, or the
26 * MinGW Project, accept liability for any damages, however caused,
27 * arising from the use of this software.
38 const char *pkgArchiveName( pkgXmlNode *rel, const char *tag, unsigned opt )
40 /* Local helper to establish actual release file names...
41 * applicable only to XML "release" elements.
43 if( ! rel->IsElementOfType( release_key ) )
45 /* The XML element type name is not "release"; identify it...
48 if( (reftype = rel->GetName()) == NULL )
50 * ...or classify as "unknown", when given a NULL element.
52 reftype = value_unknown;
54 /* Complain that this XML element type is invalid, in this context...
56 dmh_control( DMH_BEGIN_DIGEST );
57 dmh_notify( DMH_ERROR, "internal package specification error\n" );
58 dmh_notify( DMH_ERROR, "can't get 'tarname' for non-release element %s\n", reftype );
59 dmh_notify( DMH_ERROR, "please report this to the package maintainer\n" );
60 dmh_control( DMH_END_DIGEST );
62 /* ...and bail out, telling the caller that no archive name is available...
67 /* Given a package release specification...
68 * First check that it relates to a real package, rather than to
69 * a virtual "meta-package"; such meta-packages exist solely as
70 * containers for requirements specifications, and have no
73 pkgXmlNode *pkg = rel->GetParent();
74 while( (pkg != NULL) && ! pkg->IsElementOfType( package_key ) )
75 pkg = pkg->GetParent();
77 /* FIXME: we should probably provide some error handling here,
78 * to diagnose release elements without any package association;
79 * (these would be identified by pkg == NULL).
83 /* We found the package association...
84 * Check its 'class' attribute, if any, and if classified as
85 * 'virtual', return the archive association as "none".
87 const char *package_class = pkg->GetPropVal( class_key, NULL );
88 if( (package_class != NULL) && (strcmp( package_class, value_virtual ) == 0) )
92 /* The given release specification relates to a real package...
93 * Determine the archive name for the tarball to be processed; this
94 * is retrieved from a child XML element with name specified by "tag";
95 * by default, if "opt" is non-zero, it is the canonical "tarname"
96 * assigned to the release element itself, unless an alternative
97 * specification is provided; if "opt" is zero, no default is
98 * assumed, and the return value is NULL if no alternative
99 * specification is provided.
101 unsigned matched = 0;
102 pkgXmlNode *dl = rel->GetChildren();
105 /* Visit all children of the release specification element,
106 * checking for the presence of an expected specification...
108 if( dl->IsElementOfType( tag ) )
110 /* Found one; ensure it is the only one...
114 * ...else emit a warning, and ignore this one...
116 dmh_notify( DMH_WARNING, "%s: archive name reassignment ignored\n",
117 rel->GetPropVal( tarname_key, value_unknown )
120 /* ...ok; this is the first "tag" specification,
121 * accept it as the non-default source of the release's
122 * "tarname" property.
126 /* Continue, until all children have been visited.
130 /* "rel" now points to the XML element having the appropriate
131 * "tarname" specification; return a pointer to it's value.
133 return (opt || matched) ? rel->GetPropVal( tarname_key, NULL ) : NULL;
136 const char *pkgXmlNode::SourceArchiveName()
138 /* Applicable only for XML nodes designated as "release".
140 * Retrieve the source tarball name, if specified, from the
141 * "tarname" property of the contained "source" element, within
142 * an XML node designated as a "release" element.
144 * Returns a pointer to the text of the "tarname" property of the
145 * contained "source" element, or NULL if the containing node does
146 * not represent a "release", or if it does not have a contained
147 * "source" element specifying a "tarname" property.
149 return pkgArchiveName( this, source_key, 0 );
152 const char *pkgXmlNode::ArchiveName()
154 /* Applicable only for XML nodes designated as "release".
156 * Retrieve the actual tarball name, if specified, from the
157 * "tarname" property of a contained "download" element, within
158 * an XML node designated as a "release" element.
160 * Returns a pointer to the text of the "tarname" property of the
161 * contained "download" element, or to the "tarname" property of
162 * the containing "release" element, if it does not contain an
163 * alternative specification within a "download" element; if
164 * unresolved to either of these, returns NULL.
166 return pkgArchiveName( this, download_key, 1 );
169 /* $RCSfile$: end of file */