Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
wshash.h
Go to the documentation of this file.
1 /* ====================================================================
2  * The Kannel Software License, Version 1.0
3  *
4  * Copyright (c) 2001-2016 Kannel Group
5  * Copyright (c) 1998-2001 WapIT Ltd.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Kannel Group (http://www.kannel.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Kannel" and "Kannel Group" must not be used to
28  * endorse or promote products derived from this software without
29  * prior written permission. For written permission, please
30  * contact org@kannel.org.
31  *
32  * 5. Products derived from this software may not be called "Kannel",
33  * nor may "Kannel" appear in their name, without prior written
34  * permission of the Kannel Group.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE KANNEL GROUP OR ITS CONTRIBUTORS
40  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
41  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
42  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
43  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
44  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
45  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
46  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many
50  * individuals on behalf of the Kannel Group. For more information on
51  * the Kannel Group, please see <http://www.kannel.org/>.
52  *
53  * Portions of this software are based upon software originally written at
54  * WapIT Ltd., Helsinki, Finland for the Kannel project.
55  */
56 
57 /*
58  *
59  * wshash.h
60  *
61  * Author: Markku Rossi <mtr@iki.fi>
62  *
63  * Copyright (c) 1999-2000 WAPIT OY LTD.
64  * All rights reserved.
65  *
66  * A mapping from null-terminated strings to `void *' pointers.
67  *
68  */
69 
70 #ifndef WSHASH_H
71 #define WSHASH_H
72 
73 /********************* Types and definitions ****************************/
74 
75 /* A hash handle. */
76 typedef struct WsHashRec *WsHashPtr;
77 
78 /* A callback function of this type is called to free the data item
79  `item' when the hash is destroyed, or a new mapping is set for the
80  key of the item `item'. The argument `context' is a user specified
81  context data for the function. */
82 typedef void (*WsHashItemDestructor)(void *item, void *context);
83 
84 /********************* Prototypes for global functions ******************/
85 
86 /* Create a new hash table. The argument `destructor' is a destructor
87  function that is called once for each deleted item. The argument
88  `context' is passed as context data to the destructor function.
89  The argument `destructor' can be NULL in which case the mapped
90  items are not freed. The function returns NULL if the creation
91  failed (out of memory). */
92 WsHashPtr ws_hash_create(WsHashItemDestructor destructor, void *contex);
93 
94 /* Destroy the hash `hash' and free all resources it has allocated.
95  If the hash has a destructor function, it is called once for each
96  mapped item. */
97 void ws_hash_destroy(WsHashPtr hash);
98 
99 /* Add a mapping from the name `name' to the data `data'. The
100  function takes a copy of the name `name' but the data `data' is
101  stored as-is. The possible old data, stored for the name `name',
102  will be freed with the destructor function. The function returns
103  WS_TRUE if the operatio was successful or WS_FALSE otherwise. */
104 WsBool ws_hash_put(WsHashPtr hash, const char *name, void *data);
105 
106 /* Get the mapping of the name `name' from the hash `hash'. */
107 void *ws_hash_get(WsHashPtr hash, const char *name);
108 
109 /* Clear the hash and free all individual items with the destructor
110  function. After this call, the hash `hash' does not contain any
111  mappings. */
112 void ws_hash_clear(WsHashPtr hash);
113 
114 #endif /* not WSHASH_H */
Definition: parse.c:65
void * ws_hash_get(WsHashPtr hash, const char *name)
Definition: wshash.c:167
WsHashPtr ws_hash_create(WsHashItemDestructor destructor, void *contex)
Definition: wshash.c:103
struct WsHashRec * WsHashPtr
Definition: wshash.h:76
WsHashItemDestructor destructor
Definition: wshash.c:92
void ws_hash_clear(WsHashPtr hash)
Definition: wshash.c:180
WsBool ws_hash_put(WsHashPtr hash, const char *name, void *data)
Definition: wshash.c:126
char * name
Definition: smsc_cimd2.c:212
void(* WsHashItemDestructor)(void *item, void *context)
Definition: wshash.h:82
WsBool
Definition: wsint.h:128
void ws_hash_destroy(WsHashPtr hash)
Definition: wshash.c:116
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.