Subversion Repositories Kolibri OS

Rev

Rev 5726 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5725 serge 1
#include "tinyxml/tinyxml.h"
2
#include "collection.h"
3
 
4
const char *key_collection  = "collection";
5
const char *key_package     = "package";
6
const char *key_name        = "name";
7
const char *key_version     = "version";
8
const char *key_description = "description";
9
const char *key_title       = "title";
10
const char *key_release     = "release";
11
const char *key_file        = "file";
12
 
13
int package_id;
14
 
15
void parse_group(pkg_group_t* gr, TiXmlElement *xmlgroup)
16
{
17
	TiXmlElement *xmlpkg;
18
	TiXmlElement *xmle;
19
 
20
    xmlpkg = xmlgroup->FirstChildElement(key_package);
21
	while (xmlpkg)
22
	{
23
		package_t *pkg;
24
 
25
		pkg = (package_t*)malloc(sizeof(package_t));
26
		pkg->id = package_id++;
27
        pkg->name = strdup(xmlpkg->Attribute(key_name));
28
        pkg->version = strdup(xmlpkg->Attribute(key_version));
29
 
30
        xmle = xmlpkg->FirstChildElement(key_description);
31
        pkg->description = strdup(xmle->Attribute(key_title));
32
        xmle = xmlpkg->FirstChildElement(key_release);
33
 
34
        pkg->filename = strdup(xmle->Attribute(key_file));
35
		list_add_tail(&pkg->list, &gr->packages);
36
		xmlpkg = xmlpkg->NextSiblingElement();
37
	};
38
};
39
 
40
 
41
collection_t* load_collection_file(const char *name)
42
{
43
	TiXmlDocument doc;
44
	TiXmlElement *col;
45
    collection_t *collection = NULL;
46
 
47
	doc.LoadFile(name);
48
    col = doc.FirstChildElement(key_collection);
49
	if (col)
50
	{
51
        collection = (collection_t*)malloc(sizeof(collection_t));
52
        INIT_LIST_HEAD(&collection->groups);
53
 
54
		TiXmlElement* xmlgroup = col->FirstChildElement();
55
		if (xmlgroup)
56
		{
57
			pkg_group_t *gr;
58
 
59
			gr = (pkg_group_t*)malloc(sizeof(pkg_group_t));
60
			INIT_LIST_HEAD(&gr->list);
61
			INIT_LIST_HEAD(&gr->packages);
62
 
63
            gr->name = strdup(xmlgroup->Value());
64
            list_add_tail(&gr->list, &collection->groups);
65
			parse_group(gr, xmlgroup);
66
		};
67
	};
68
 
69
	return collection;
70
}
71
 
72
collection_t* load_collection_buffer(const char *buffer)
73
{
74
    TiXmlDocument doc;
75
    TiXmlElement *col;
76
    collection_t *collection = NULL;
77
 
78
    doc.Parse(buffer);
79
    col = doc.FirstChildElement(key_collection);
80
    if (col)
81
    {
82
        collection = (collection_t*)malloc(sizeof(collection_t));
83
        INIT_LIST_HEAD(&collection->groups);
84
 
85
        TiXmlElement* xmlgroup = col->FirstChildElement();
86
        if (xmlgroup)
87
        {
88
            pkg_group_t *gr;
89
 
90
            gr = (pkg_group_t*)malloc(sizeof(pkg_group_t));
91
            INIT_LIST_HEAD(&gr->list);
92
            INIT_LIST_HEAD(&gr->packages);
93
 
94
            gr->name = strdup(xmlgroup->Value());
95
            list_add_tail(&gr->list, &collection->groups);
96
            parse_group(gr, xmlgroup);
97
        };
98
    };
99
 
100
    return collection;
101
}