OSDN Git Service

Implement package installer for tar archives.
[mingw/mingw-get.git] / src / pkgname.cpp
1 /*
2  * pkgname.cpp
3  *
4  * $Id$
5  *
6  * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
7  * Copyright (C) 2009, 2010, MinGW Project
8  *
9  *
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.
14  *
15  *
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.
21  *
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.
28  *
29  */
30 #include <stdio.h>
31 #include <string.h>
32
33 #include "dmh.h"
34 #include "pkgbase.h"
35 #include "pkgkeys.h"
36
37 static
38 const char *pkgArchiveName( pkgXmlNode *rel, const char *tag, unsigned opt )
39 {
40   /* Local helper to establish actual release file names...
41    * applicable only to XML "release" elements.
42    */
43   if( ! rel->IsElementOfType( "release" ) )
44   {
45     dmh_control( DMH_BEGIN_DIGEST );
46     dmh_notify( DMH_ERROR, "internal package specification error\n" );
47     dmh_notify( DMH_ERROR, "can't get 'tarname' for non-release element\n" );
48     dmh_notify( DMH_ERROR, "please report this to the package maintainer\n" );
49     dmh_control( DMH_END_DIGEST );
50     return NULL;
51   }
52
53   /* Given a package release specification...
54    * determine the archive name for the tarball to be processed; this
55    * is retrieved from a child XML element with name specified by "tag";
56    * by default, if "opt" is non-zero, it is the canonical "tarname"
57    * assigned to the release element itself, unless an alternative
58    * specification is provided; if "opt" is zero, no default is
59    * assumed, and the return value is NULL if no alternative
60    * specification is provided.
61    */
62   unsigned matched = 0;
63   pkgXmlNode *dl = rel->GetChildren();
64   while( dl != NULL )
65   {
66     /* Visit all children of the release specification element,
67      * checking for the presence of an expected specification...
68      */
69     if( dl->IsElementOfType( tag ) )
70     {
71       /* Found one; ensure it is the only one...
72        */
73       if( matched++ )
74         /*
75          * ...else emit a warning, and ignore this one...
76          */
77         dmh_notify( DMH_WARNING, "%s: archive name reassignment ignored\n",
78             rel->GetPropVal( tarname_key, "<unknown>" )
79         );
80       else
81         /* ...ok; this is the first "tag" specification,
82          * accept it as the non-default source of the release's
83          * "tarname" property.
84          */
85         rel = dl;
86     }
87     /* Continue, until all children have been visited.
88      */
89     dl = dl->GetNext();
90   }
91   /* "rel" now points to the XML element having the appropriate
92    * "tarname" specification; return a pointer to it's value.
93    */
94   return (opt || matched) ? rel->GetPropVal( tarname_key, NULL ) : NULL;
95 }
96
97 const char *pkgXmlNode::SourceArchiveName()
98 {
99   /* Applicable only for XML nodes designated as "release".
100    *
101    * Retrieve the source tarball name, if specified, from the
102    * "tarname" property of the contained "source" element, within
103    * an XML node designated as a "release" element.
104    *
105    * Returns a pointer to the text of the "tarname" property of the
106    * contained "source" element, or NULL if the containing node does
107    * not represent a "release", or if it does not have a contained
108    * "source" element specifying a "tarname" property.
109    */
110   return pkgArchiveName( this, source_key, 0 );
111 }
112
113 const char *pkgXmlNode::ArchiveName()
114 {
115   /* Applicable only for XML nodes designated as "release".
116    *
117    * Retrieve the actual tarball name, if specified, from the
118    * "tarname" property of a contained "download" element, within
119    * an XML node designated as a "release" element.
120    *
121    * Returns a pointer to the text of the "tarname" property of the
122    * contained "download" element, or to the "tarname" property of
123    * the containing "release" element, if it does not contain an
124    * alternative specification within a "download" element; if
125    * unresolved to either of these, returns NULL.
126    */
127   return pkgArchiveName( this, download_key, 1 );
128 }
129
130 /* $RCSfile$: end of file */