4 * Copyright (C) 2001, 2002, 2004
6 * Vassili Dzuba <vassilidzuba@nerim.net>
7 * Neven Has <haski@sezampro.yu>
8 * Kevin P. Fleming <kpfleming@linuxfromscratch.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #define MODULE_NAME stamp
48 static const struct handler_attribute stamp_attributes
[] = {
49 { .name
= "name", .private = STAMP_NAME
},
50 { .name
= "version", .private = STAMP_VERSION
},
54 static int stamp_setup(element_s
* const element
)
56 struct stamp_data
*data
;
58 if ((data
= xmalloc(sizeof(struct stamp_data
))) == NULL
)
63 element
->handler_data
= data
;
68 static void stamp_free(const element_s
* const element
)
70 struct stamp_data
*data
= (struct stamp_data
*) element
->handler_data
;
77 static int stamp_attribute(const element_s
* const element
,
78 const struct handler_attribute
* const attr
,
79 const char * const value
)
81 struct stamp_data
*data
= (struct stamp_data
*) element
->handler_data
;
83 switch (attr
->private) {
86 Nprint_err("<%s>: cannot specify \"name\" more than once.", element
->handler
->name
);
89 data
->name
= xstrdup(value
);
93 Nprint_err("<%s>: cannot specify \"version\" more than once.", element
->handler
->name
);
96 data
->version
= xstrdup(value
);
103 static int stamp_valid_data(const element_s
* const element
)
105 struct stamp_data
*data
= (struct stamp_data
*) element
->handler_data
;
108 Nprint_err("<%s>: \"name\" cannot be empty.", element
->handler
->name
);
112 if (!data
->version
) {
113 Nprint_err("<%s>: \"version\" cannot be empty.", element
->handler
->name
);
120 static int stamp_main(const element_s
* const element
)
122 struct stamp_data
*data
= (struct stamp_data
*) element
->handler_data
;
124 return stamp_package_installed(1, data
->name
, data
->version
);
128 * Handlers' information.
131 handler_info_s
HANDLER_SYMBOL(info
)[] = {
132 #if HANDLER_SYNTAX_2_0
135 .description
= "Produce a stamp",
136 .syntax_version
= "2.0",
138 .type
= HTYPE_NORMAL
,
139 .setup
= stamp_setup
,
141 .attributes
= stamp_attributes
,
142 .attribute
= stamp_attribute
,
143 .valid_data
= stamp_valid_data
,