2015-05-01 12:49:11 +02:00
|
|
|
/*
|
|
|
|
This file is part of libcapwap.
|
|
|
|
|
|
|
|
libcapwap is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
libcapwap 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 General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2018-03-03 17:42:28 +01:00
|
|
|
#include "mbag.h"
|
2015-04-29 19:27:51 +02:00
|
|
|
#include "item.h"
|
2015-05-01 12:49:11 +02:00
|
|
|
#include "log.h"
|
2015-04-29 19:27:51 +02:00
|
|
|
|
2015-05-01 12:49:11 +02:00
|
|
|
|
|
|
|
const char CW_ITEM_NONE[] = "";
|
2015-05-04 07:37:19 +02:00
|
|
|
const char CW_ITEM_ANY[] = "*";
|
|
|
|
|
2015-05-01 12:49:11 +02:00
|
|
|
|
|
|
|
struct cw_itemdef *cw_item_get_by_name(const char *id, struct cw_itemdef *table)
|
2015-04-29 19:27:51 +02:00
|
|
|
{
|
|
|
|
while (table->id != CW_ITEM_NONE) {
|
2015-05-01 12:49:11 +02:00
|
|
|
if (!strcmp(table->id, id))
|
2015-04-29 19:27:51 +02:00
|
|
|
return table;
|
|
|
|
table++;
|
|
|
|
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-05-01 12:49:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
static int cmp(const void *x1, const void *x2)
|
2015-04-29 19:27:51 +02:00
|
|
|
{
|
2015-05-01 12:49:11 +02:00
|
|
|
cw_itemdef_t *i1, *i2;
|
|
|
|
i1 = (cw_itemdef_t *) x1;
|
|
|
|
i2 = (cw_itemdef_t *) x2;
|
2015-05-04 07:37:19 +02:00
|
|
|
|
2015-05-01 12:49:11 +02:00
|
|
|
int rc = strcmp(i1->id, i2->id);
|
|
|
|
if (rc != 0)
|
|
|
|
return rc;
|
|
|
|
return strcmp(i1->sub_id, i2->sub_id);
|
|
|
|
}
|
2015-04-29 19:27:51 +02:00
|
|
|
|
2015-05-01 12:49:11 +02:00
|
|
|
const cw_itemdef_t * cw_itemdef_get(cw_itemdefheap_t t, const char *id, const char *sub_id)
|
|
|
|
{
|
|
|
|
cw_itemdef_t idef;
|
|
|
|
idef.id = id;
|
|
|
|
idef.sub_id = !sub_id ? CW_ITEM_NONE : sub_id;
|
2015-05-04 07:37:19 +02:00
|
|
|
|
2015-05-01 12:49:11 +02:00
|
|
|
return mavl_get(t, &idef);
|
|
|
|
}
|
|
|
|
|
|
|
|
cw_itemdefheap_t cw_itemdefheap_create()
|
|
|
|
{
|
2018-03-11 00:56:41 +01:00
|
|
|
return mavl_create(cmp, NULL,1312);
|
2015-05-01 12:49:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int cw_itemdefheap_register(cw_itemdefheap_t t, cw_itemdef_t * defs)
|
|
|
|
{
|
|
|
|
int n = 0;
|
|
|
|
while (defs->id != CW_ITEM_NONE) {
|
2018-03-11 00:56:41 +01:00
|
|
|
cw_itemdef_t *a = mavl_add(t, defs,NULL);
|
2015-05-01 12:49:11 +02:00
|
|
|
if (a != defs) {
|
|
|
|
cw_log(LOG_ERR, "Duplicated item: %s", defs->id);
|
|
|
|
} else
|
|
|
|
n++;
|
|
|
|
defs++;
|
2015-04-29 19:27:51 +02:00
|
|
|
}
|
2015-05-01 12:49:11 +02:00
|
|
|
return n;
|
2015-04-29 19:27:51 +02:00
|
|
|
}
|