aboutsummaryrefslogtreecommitdiffstats
path: root/lib/xmltree.h
blob: 1067741218cd3032febd2c083c66c5a353bec81d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/***************************************************************************\
*                                                                           *
*  BitlBee - An IRC to IM gateway                                           *
*  Simple XML (stream) parse tree handling code (Jabber/XMPP, mainly)       *
*                                                                           *
*  Copyright 2006 Wilmer van der Gaast <wilmer@gaast.net>                   *
*                                                                           *
*  This library is free software; you can redistribute it and/or            *
*  modify it under the terms of the GNU Lesser General Public               *
*  License as published by the Free Software Foundation, version            *
*  2.1.                                                                     *
*                                                                           *
*  This library is distributed in the hope that it will be useful,          *
*  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        *
*  Lesser General Public License for more details.                          *
*                                                                           *
*  You should have received a copy of the GNU Lesser General Public License *
*  along with this library; if not, write to the Free Software Foundation,  *
*  Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA           *
*                                                                           *
****************************************************************************/

#ifndef _XMLTREE_H
#define _XMLTREE_H

typedef enum
{
	XT_COMPLETE	= 1,	/* </tag> reached */
	XT_SEEN		= 2,	/* Handler called (or not defined) */
} xt_flags;

typedef enum
{
	XT_ABORT,		/* Abort, don't handle the rest anymore */
	XT_HANDLED,		/* Handled this tag properly, go to the next one */
	XT_NEXT			/* Try if there's another matching handler */
} xt_status;

struct xt_attr
{
	char *key, *value;
};

struct xt_node
{
	struct xt_node *parent;
	struct xt_node *children;
	
	char *name;
	struct xt_attr *attr;
	char *text;
	int text_len;
	
	struct xt_node *next;
	xt_flags flags;
};

typedef xt_status (*xt_handler_func) ( struct xt_node *node, gpointer data );

struct xt_handler_entry
{
	char *name, *parent;
	xt_handler_func func;
};

struct xt_parser
{
	GMarkupParseContext *parser;
	struct xt_node *root;
	struct xt_node *cur;
	
	const struct xt_handler_entry *handlers;
	gpointer data;
	
	GError *gerr;
};

struct xt_parser *xt_new( const struct xt_handler_entry *handlers, gpointer data );
void xt_reset( struct xt_parser *xt );
int xt_feed( struct xt_parser *xt, char *text, int text_len );
int xt_handle( struct xt_parser *xt, struct xt_node *node, int depth );
void xt_cleanup( struct xt_parser *xt, struct xt_node *node, int depth );
char *xt_to_string( struct xt_node *node );
void xt_print( struct xt_node *node );
struct xt_node *xt_dup( struct xt_node *node );
void xt_free_node( struct xt_node *node );
void xt_free( struct xt_parser *xt );
struct xt_node *xt_find_node( struct xt_node *node, const char *name );
char *xt_find_attr( struct xt_node *node, const char *key );

struct xt_node *xt_new_node( char *name, char *text, struct xt_node *children );
void xt_add_child( struct xt_node *parent, struct xt_node *child );
void xt_add_attr( struct xt_node *node, const char *key, const char *value );
int xt_remove_attr( struct xt_node *node, const char *key );

#endif
command = "git clone #{uri} #{name}" if system(clone_command) Dir.chdir install_path do # First try to checkout a specific branch of the theme tag_checked_out = checkout_remote_branch(Configuration::theme_branch) if Configuration::theme_branch if !tag_checked_out # try to checkout a tag exactly matching ALAVETELI VERSION tag_checked_out = checkout_tag(ALAVETELI_VERSION) end if ! tag_checked_out # if we're on a hotfix release (four sequence elements or more), # look for a usage tag matching the minor release (three sequence elements) # and check that out if found if hotfix_version = /^(\d+\.\d+\.\d+)(\.\d+)+/.match(ALAVETELI_VERSION) base_version = hotfix_version[1] tag_checked_out = checkout_tag(base_version) end end if ! tag_checked_out puts "No specific tag for this version: using HEAD" if verbose end puts "removing: .git .gitignore" if verbose rm_rf %w(.git .gitignore) end else rm_rf install_path raise "#{clone_command} failed! Stopping." end end end def uninstall(theme_name, verbose=false) dir = theme_dir(theme_name) if File.directory?(dir) run_hook(theme_name, 'uninstall', verbose) puts "Removing '#{dir}'" if verbose rm_r dir else puts "Plugin doesn't exist: #{dir}" end end def run_hook(theme_name, hook_name, verbose=false) hook_file = File.join(theme_dir(theme_name), "#{hook_name}.rb") if File.exist? hook_file puts "Running #{hook_name} hook for #{theme_name}" if verbose load hook_file end end def installed?(theme_name) File.directory?(theme_dir(theme_name)) end def install_theme(theme_url, verbose, deprecated=false) deprecation_string = deprecated ? " using deprecated THEME_URL" : "" theme_name = File.basename(theme_url, '.git') puts "Installing theme #{theme_name}#{deprecation_string} from #{theme_url}" uninstall(theme_name, verbose) if installed?(theme_name) install_theme_using_git(theme_name, theme_url, verbose) run_hook(theme_name, 'install', verbose) run_hook(theme_name, 'post_install', verbose) end desc "Install themes specified in the config file's THEME_URLS" task :install => :environment do verbose = true Configuration::theme_urls.each{ |theme_url| install_theme(theme_url, verbose) } if ! Configuration::theme_url.blank? # Old version of the above, for backwards compatibility install_theme(Configuration::theme_url, verbose, deprecated=true) end end end