First cut. Distintly raw around the edges:
* Assumes it will be running in /home/ali/wk/slashem/web.scripts
* Assumes cache directory will be in topdir
* No build system (simple compiling and linking against libxml2)
* No configure system (eg., tagsoup)
* Output XML untested
* Doesn't set bugzilla maintainer or exporter
* Handling of artifact priorities and resolution is suspect
2 * This program parses the XML data provided by sourceforge to extract the
3 * list of "attached files" (which are not themselves included in the XML
4 * stream and therefore need to be seperately downloaded for archiving).
10 #include <libxml/xmlmemory.h>
11 #include <libxml/parser.h>
13 struct artifact_type {
16 } artifact_types[] = {
18 "Support Requests", 209746,
20 "Feature Requests", 359746,
24 #define NO_ELEMS(array) (sizeof(array)/sizeof(*(array)))
27 void parse_history(xmlDocPtr doc,const xmlChar *artifact_id,
28 const xmlChar *artifact_type,xmlNodePtr node)
33 xmlChar *field_name=NULL;
36 for(field=node->xmlChildrenNode;field;field=field->next)
37 if (!xmlStrcmp(field->name,(const xmlChar *)"field"))
39 for(attr=field->properties;attr;attr=attr->next)
40 if (!xmlStrcmp(attr->name,(const xmlChar *)"name"))
42 name=xmlNodeListGetString(doc,attr->children,1);
43 if (!xmlStrcmp(name,(const xmlChar *)"field_name"))
44 field_name=xmlNodeListGetString(doc,field->children,1);
45 if (!xmlStrcmp(field_name,(const xmlChar *)"File Added") &&
46 !xmlStrcmp(name,(const xmlChar *)"old_value"))
48 text=xmlNodeListGetString(doc,field->children,1);
49 if (sscanf(text,"%d",&file_id)==1)
51 for(i=NO_ELEMS(artifact_types)-1;i>=0;i--)
52 if (!strcmp(artifact_types[i].name,
53 (const char *)artifact_type))
57 artifact_types[i].id,artifact_id,file_id);
60 "Warning: Unknown artifact type \"%s\" - "
61 "attached file %s ignored\n",
73 void parse_artifact(xmlDocPtr doc,xmlNodePtr node)
81 for(field=node->xmlChildrenNode;field;field=field->next)
82 if (!xmlStrcmp(field->name,(const xmlChar *)"field"))
84 for(attr=field->properties;attr;attr=attr->next)
85 if (!xmlStrcmp(attr->name,(const xmlChar *)"name"))
87 name=xmlNodeListGetString(doc,attr->children,1);
88 if (!xmlStrcmp(name,(const xmlChar *)"artifact_id"))
89 id=xmlNodeListGetString(doc,field->children,1);
90 if (!xmlStrcmp(name,(const xmlChar *)"artifact_type"))
91 type=xmlNodeListGetString(doc,field->children,1);
93 if (!xmlStrcmp(name,(const xmlChar *)"artifact_history"))
94 for(cur=field->xmlChildrenNode;cur;cur=cur->next)
95 if (!xmlStrcmp(cur->name,"history"))
96 parse_history(doc,id,type,cur);
109 int main(int argc,char **argv)
113 doc=xmlParseFile(argv[1]);
116 fprintf(stderr,"Document not parsed successfully.\n");
119 cur=xmlDocGetRootElement(doc);
122 fprintf(stderr,"Empty document.\n");
126 if (xmlStrcmp(cur->name,(const xmlChar *)"project_export"))
128 fprintf(stderr,"%s does not appear to be a project export document.\n",
133 for(cur=cur->xmlChildrenNode;cur;cur=cur->next)
134 if (!xmlStrcmp(cur->name,(const xmlChar *)"artifacts"))
138 fprintf(stderr,"%s does not appear to contain an artifacts node.\n",
143 for(cur=cur->xmlChildrenNode;cur;cur=cur->next)
144 if (!xmlStrcmp(cur->name,(const xmlChar *)"artifact"))
145 parse_artifact(doc,cur);