| 1 |
nenolod |
296 |
/* |
| 2 |
|
|
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
| 3 |
|
|
* metadata.c: metadata system |
| 4 |
|
|
* |
| 5 |
|
|
* Copyright (C) 2005 by the past and present ircd coders, and others. |
| 6 |
|
|
* |
| 7 |
|
|
* This program is free software; you can redistribute it and/or modify |
| 8 |
|
|
* it under the terms of the GNU General Public License as published by |
| 9 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
| 10 |
|
|
* (at your option) any later version. |
| 11 |
|
|
* |
| 12 |
|
|
* This program is distributed in the hope that it will be useful, |
| 13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
|
|
* GNU General Public License for more details. |
| 16 |
|
|
* |
| 17 |
|
|
* You should have received a copy of the GNU General Public License |
| 18 |
|
|
* along with this program; if not, write to the Free Software |
| 19 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 20 |
|
|
* USA |
| 21 |
|
|
* |
| 22 |
|
|
* $Id$ |
| 23 |
|
|
*/ |
| 24 |
|
|
|
| 25 |
|
|
#include "stdinc.h" |
| 26 |
|
|
#include "metadata.h" |
| 27 |
|
|
|
| 28 |
|
|
struct Metadata * |
| 29 |
nenolod |
297 |
add_metadata_str (dlink_list * list, char *key, char *strval) |
| 30 |
nenolod |
296 |
{ |
| 31 |
nenolod |
297 |
struct Metadata *mdptr; |
| 32 |
nenolod |
296 |
|
| 33 |
nenolod |
297 |
assert (key != NULL); |
| 34 |
|
|
assert (strval != NULL); |
| 35 |
nenolod |
296 |
|
| 36 |
nenolod |
297 |
if (find_metadata (list, key) != NULL) |
| 37 |
|
|
return NULL; |
| 38 |
nenolod |
296 |
|
| 39 |
nenolod |
297 |
mdptr = MyMalloc (sizeof (struct Metadata)); |
| 40 |
|
|
memset (mdptr, 0, sizeof (struct Metadata)); |
| 41 |
|
|
DupString (key, mdptr->key); |
| 42 |
|
|
DupString (strval, mdptr->u.strval); |
| 43 |
nenolod |
296 |
|
| 44 |
nenolod |
297 |
dlinkAdd (mdptr, make_dlink_node (), list); |
| 45 |
nenolod |
296 |
|
| 46 |
nenolod |
297 |
return mdptr; |
| 47 |
nenolod |
296 |
} |
| 48 |
|
|
|
| 49 |
|
|
struct Metadata * |
| 50 |
nenolod |
297 |
add_metadata_int (dlink_list * list, char *key, int intval) |
| 51 |
nenolod |
296 |
{ |
| 52 |
nenolod |
297 |
struct Metadata *mdptr; |
| 53 |
nenolod |
296 |
|
| 54 |
nenolod |
297 |
assert (key != NULL); |
| 55 |
nenolod |
296 |
|
| 56 |
nenolod |
297 |
if (find_metadata (list, key) != NULL) |
| 57 |
|
|
return NULL; |
| 58 |
nenolod |
296 |
|
| 59 |
nenolod |
297 |
mdptr = MyMalloc (sizeof (struct Metadata)); |
| 60 |
|
|
memset (mdptr, 0, sizeof (struct Metadata)); |
| 61 |
|
|
DupString (key, mdptr->key); |
| 62 |
|
|
mdptr->u.intval = intval; |
| 63 |
nenolod |
296 |
|
| 64 |
nenolod |
297 |
dlinkAdd (mdptr, make_dlink_node (), list); |
| 65 |
nenolod |
296 |
|
| 66 |
nenolod |
297 |
return mdptr; |
| 67 |
nenolod |
296 |
} |
| 68 |
|
|
|
| 69 |
|
|
struct Metadata * |
| 70 |
nenolod |
297 |
find_metadata (dlink_list * list, char *key) |
| 71 |
nenolod |
296 |
{ |
| 72 |
nenolod |
297 |
dlink_node *n; |
| 73 |
nenolod |
296 |
|
| 74 |
nenolod |
297 |
assert (key != NULL); |
| 75 |
nenolod |
296 |
|
| 76 |
nenolod |
297 |
DLINK_FOREACH (n, list->head) |
| 77 |
|
|
{ |
| 78 |
|
|
struct Metadata *md = (struct Metadata *) n->data; |
| 79 |
nenolod |
296 |
|
| 80 |
nenolod |
297 |
if (!irccmp (key, md->key)) |
| 81 |
|
|
return md; |
| 82 |
|
|
} |
| 83 |
nenolod |
296 |
|
| 84 |
nenolod |
297 |
return NULL; |
| 85 |
nenolod |
296 |
} |
| 86 |
|
|
|
| 87 |
|
|
void |
| 88 |
nenolod |
297 |
destroy_metadata (dlink_list * list, char *key) |
| 89 |
nenolod |
296 |
{ |
| 90 |
nenolod |
297 |
struct Metadata *md; |
| 91 |
nenolod |
296 |
|
| 92 |
nenolod |
297 |
assert (key != NULL); |
| 93 |
nenolod |
296 |
|
| 94 |
nenolod |
297 |
if ((md = find_metadata (list, key)) == NULL) |
| 95 |
|
|
return; |
| 96 |
nenolod |
296 |
|
| 97 |
nenolod |
297 |
if (md->u.strval != NULL) |
| 98 |
|
|
MyFree (md->u.strval); |
| 99 |
nenolod |
296 |
|
| 100 |
nenolod |
297 |
dlinkFindDelete (list, md); |
| 101 |
nenolod |
296 |
|
| 102 |
nenolod |
297 |
MyFree (md); |
| 103 |
nenolod |
296 |
} |