FreeSWITCH API Documentation  1.7.0
Functions
switch_core_hash.c File Reference
#include <switch.h>
#include "private/switch_core_pvt.h"
#include "private/switch_hashtable_private.h"
+ Include dependency graph for switch_core_hash.c:

Go to the source code of this file.

Functions

switch_status_t switch_core_hash_init_case (switch_hash_t **hash, switch_bool_t case_sensitive)
 
switch_status_t switch_core_hash_destroy (switch_hash_t **hash)
 
switch_status_t switch_core_hash_insert_destructor (switch_hash_t *hash, const char *key, const void *data, hashtable_destructor_t destructor)
 
switch_status_t switch_core_hash_insert_locked (switch_hash_t *hash, const char *key, const void *data, switch_mutex_t *mutex)
 
switch_status_t switch_core_hash_insert_wrlock (switch_hash_t *hash, const char *key, const void *data, switch_thread_rwlock_t *rwlock)
 Retrieve data from a given hash. More...
 
void * switch_core_hash_delete (switch_hash_t *hash, const char *key)
 
void * switch_core_hash_delete_locked (switch_hash_t *hash, const char *key, switch_mutex_t *mutex)
 
void * switch_core_hash_delete_wrlock (switch_hash_t *hash, const char *key, switch_thread_rwlock_t *rwlock)
 
switch_status_t switch_core_hash_delete_multi (switch_hash_t *hash, switch_hash_delete_callback_t callback, void *pData)
 
void * switch_core_hash_find (switch_hash_t *hash, const char *key)
 
void * switch_core_hash_find_locked (switch_hash_t *hash, const char *key, switch_mutex_t *mutex)
 
void * switch_core_hash_find_rdlock (switch_hash_t *hash, const char *key, switch_thread_rwlock_t *rwlock)
 
switch_bool_t switch_core_hash_empty (switch_hash_t *hash)
 tells if a hash is empty More...
 
switch_hash_index_tswitch_core_hash_first_iter (switch_hash_t *hash, switch_hash_index_t *hi)
 
switch_hash_index_tswitch_core_hash_next (switch_hash_index_t **hi)
 
void switch_core_hash_this (switch_hash_index_t *hi, const void **key, switch_ssize_t *klen, void **val)
 
void switch_core_hash_this_val (switch_hash_index_t *hi, void *val)
 
switch_status_t switch_core_inthash_init (switch_inthash_t **hash)
 
switch_status_t switch_core_inthash_destroy (switch_inthash_t **hash)
 
switch_status_t switch_core_inthash_insert (switch_inthash_t *hash, uint32_t key, const void *data)
 
void * switch_core_inthash_delete (switch_inthash_t *hash, uint32_t key)
 
void * switch_core_inthash_find (switch_inthash_t *hash, uint32_t key)
 

Function Documentation

void* switch_core_hash_delete ( switch_hash_t hash,
const char *  key 
)

Definition at line 101 of file switch_core_hash.c.

References switch_hashtable_remove().

Referenced by switch_core_hash_delete_locked(), switch_core_hash_delete_multi(), and switch_core_hash_delete_wrlock().

102 {
103  return switch_hashtable_remove(hash, (void *)key);
104 }
void * switch_hashtable_remove(switch_hashtable_t *h, void *k)
void* switch_core_hash_delete_locked ( switch_hash_t hash,
const char *  key,
switch_mutex_t mutex 
)

Definition at line 106 of file switch_core_hash.c.

References switch_core_hash_delete(), switch_mutex_lock(), and switch_mutex_unlock().

107 {
108  void *ret = NULL;
109 
110  if (mutex) {
112  }
113 
114  switch_core_hash_delete(hash, key);
115 
116  if (mutex) {
118  }
119 
120  return ret;
121 }
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
switch_mutex_t * mutex
void * switch_core_hash_delete(switch_hash_t *hash, const char *key)
switch_status_t switch_core_hash_delete_multi ( switch_hash_t hash,
switch_hash_delete_callback_t  callback,
void *  pData 
)

Definition at line 140 of file switch_core_hash.c.

References switch_event_header::next, switch_assert, switch_core_hash_delete(), switch_core_hash_first, switch_core_hash_next(), switch_core_hash_this(), switch_event_add_header_string(), SWITCH_EVENT_CLONE, switch_event_create_subclass, switch_event_destroy(), SWITCH_STACK_BOTTOM, SWITCH_STATUS_GENERR, SWITCH_STATUS_SUCCESS, and switch_event_header::value.

140  {
141 
142  switch_hash_index_t *hi = NULL;
143  switch_event_t *event = NULL;
144  switch_event_header_t *header = NULL;
146 
148  switch_assert(event);
149 
150  /* iterate through the hash, call callback, if callback returns NULL or true, put the key on the list (event)
151  When done, iterate through the list deleting hash entries
152  */
153 
154  for (hi = switch_core_hash_first(hash); hi; hi = switch_core_hash_next(&hi)) {
155  const void *key;
156  void *val;
157  switch_core_hash_this(hi, &key, NULL, &val);
158  if (!callback || callback(key, val, pData)) {
159  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "delete", (const char *) key);
160  }
161  }
162 
163  /* now delete them */
164  for (header = event->headers; header; header = header->next) {
165  if (switch_core_hash_delete(hash, header->value)) {
166  status = SWITCH_STATUS_SUCCESS;
167  }
168  }
169 
170  switch_event_destroy(&event);
171 
172  return status;
173 }
Representation of an event.
Definition: switch_event.h:80
An event Header.
Definition: switch_event.h:65
#define switch_event_create_subclass(_e, _eid, _sn)
Definition: switch_event.h:153
void switch_core_hash_this(switch_hash_index_t *hi, const void **key, switch_ssize_t *klen, void **val)
switch_status_t switch_event_add_header_string(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *data)
Add a string header to an event.
switch_status_t
Common return values.
struct switch_event_header * next
Definition: switch_event.h:76
void switch_event_destroy(switch_event_t **event)
Destroy an event.
void * switch_core_hash_delete(switch_hash_t *hash, const char *key)
#define switch_assert(expr)
#define switch_core_hash_first(_h)
Definition: switch_core.h:1501
switch_hash_index_t * switch_core_hash_next(switch_hash_index_t **hi)
void* switch_core_hash_delete_wrlock ( switch_hash_t hash,
const char *  key,
switch_thread_rwlock_t rwlock 
)

Definition at line 123 of file switch_core_hash.c.

References switch_core_hash_delete(), switch_thread_rwlock_unlock(), and switch_thread_rwlock_wrlock().

124 {
125  void *ret = NULL;
126 
127  if (rwlock) {
129  }
130 
131  ret = switch_core_hash_delete(hash, key);
132 
133  if (rwlock) {
135  }
136 
137  return ret;
138 }
switch_status_t switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:263
switch_status_t switch_thread_rwlock_wrlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:237
switch_thread_rwlock_t * rwlock
Definition: switch_event.c:73
void * switch_core_hash_delete(switch_hash_t *hash, const char *key)
switch_status_t switch_core_hash_destroy ( switch_hash_t **  hash)

Definition at line 49 of file switch_core_hash.c.

References switch_assert, switch_hashtable_destroy(), and SWITCH_STATUS_SUCCESS.

50 {
51  switch_assert(hash != NULL && *hash != NULL);
52 
54 
55  return SWITCH_STATUS_SUCCESS;
56 }
void switch_hashtable_destroy(switch_hashtable_t **h)
#define switch_assert(expr)
void* switch_core_hash_find ( switch_hash_t hash,
const char *  key 
)

Definition at line 176 of file switch_core_hash.c.

References switch_hashtable_search().

Referenced by switch_core_hash_find_locked(), and switch_core_hash_find_rdlock().

177 {
178  return switch_hashtable_search(hash, (void *)key);
179 }
void * switch_hashtable_search(switch_hashtable_t *h, void *k)
void* switch_core_hash_find_locked ( switch_hash_t hash,
const char *  key,
switch_mutex_t mutex 
)

Definition at line 181 of file switch_core_hash.c.

References switch_core_hash_find(), switch_mutex_lock(), and switch_mutex_unlock().

182 {
183  void *val;
184 
185  if (mutex) {
187  }
188 
189  val = switch_core_hash_find(hash, key);
190 
191 
192  if (mutex) {
194  }
195 
196  return val;
197 }
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
void * switch_core_hash_find(switch_hash_t *hash, const char *key)
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
switch_mutex_t * mutex
void* switch_core_hash_find_rdlock ( switch_hash_t hash,
const char *  key,
switch_thread_rwlock_t rwlock 
)

Definition at line 199 of file switch_core_hash.c.

References switch_core_hash_find(), switch_thread_rwlock_rdlock(), and switch_thread_rwlock_unlock().

200 {
201  void *val;
202 
203  if (rwlock) {
205  }
206 
207  val = switch_core_hash_find(hash, key);
208 
209  if (rwlock) {
211  }
212 
213  return val;
214 }
switch_status_t switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:263
switch_status_t switch_thread_rwlock_rdlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:227
void * switch_core_hash_find(switch_hash_t *hash, const char *key)
switch_thread_rwlock_t * rwlock
Definition: switch_event.c:73
switch_hash_index_t* switch_core_hash_first_iter ( switch_hash_t hash,
switch_hash_index_t hi 
)

Definition at line 229 of file switch_core_hash.c.

References switch_hashtable_first_iter().

230 {
231  return switch_hashtable_first_iter(hash, hi);
232 }
switch_hashtable_iterator_t * switch_hashtable_first_iter(switch_hashtable_t *h, switch_hashtable_iterator_t *it)
switch_status_t switch_core_hash_init_case ( switch_hash_t **  hash,
switch_bool_t  case_sensitive 
)

Definition at line 39 of file switch_core_hash.c.

References switch_create_hashtable(), switch_hash_default(), switch_hash_default_ci(), switch_hash_equalkeys(), and switch_hash_equalkeys_ci().

40 {
41  if (case_sensitive) {
43  } else {
45  }
46 }
static int switch_hash_equalkeys_ci(void *k1, void *k2)
static uint32_t switch_hash_default_ci(void *ky)
switch_status_t switch_create_hashtable(switch_hashtable_t **hp, unsigned int minsize, unsigned int(*hashfunction)(void *), int(*key_eq_fn)(void *, void *))
static int switch_hash_equalkeys(void *k1, void *k2)
static uint32_t switch_hash_default(void *ky)
switch_status_t switch_core_hash_insert_destructor ( switch_hash_t hash,
const char *  key,
const void *  data,
hashtable_destructor_t  destructor 
)

Definition at line 58 of file switch_core_hash.c.

References HASHTABLE_DUP_CHECK, HASHTABLE_FLAG_FREE_KEY, switch_hashtable_insert_destructor(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

59 {
60  int r = 0;
61 
62  r = switch_hashtable_insert_destructor(hash, strdup(key), (void *)data, HASHTABLE_FLAG_FREE_KEY | HASHTABLE_DUP_CHECK, destructor);
63 
65 }
int switch_hashtable_insert_destructor(switch_hashtable_t *h, void *k, void *v, hashtable_flag_t flags, hashtable_destructor_t destructor)
switch_status_t switch_core_hash_insert_locked ( switch_hash_t hash,
const char *  key,
const void *  data,
switch_mutex_t mutex 
)

Definition at line 67 of file switch_core_hash.c.

References switch_core_hash_insert, switch_mutex_lock(), switch_mutex_unlock(), and SWITCH_STATUS_FALSE.

68 {
70 
71  if (mutex) {
73  }
74 
75  status = switch_core_hash_insert(hash, key, data);
76 
77  if (mutex) {
79  }
80 
81  return status;
82 }
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
switch_mutex_t * mutex
switch_status_t
Common return values.
#define switch_core_hash_insert(_h, _k, _d)
Definition: switch_core.h:1410
switch_hash_index_t* switch_core_hash_next ( switch_hash_index_t **  hi)

Definition at line 234 of file switch_core_hash.c.

References switch_hashtable_next().

Referenced by switch_core_hash_delete_multi().

235 {
236  return switch_hashtable_next(hi);
237 }
switch_hashtable_iterator_t * switch_hashtable_next(switch_hashtable_iterator_t **iP)
void switch_core_hash_this ( switch_hash_index_t hi,
const void **  key,
switch_ssize_t klen,
void **  val 
)

Definition at line 239 of file switch_core_hash.c.

References switch_hashtable_this().

Referenced by switch_core_hash_delete_multi().

240 {
241  switch_hashtable_this(hi, key, klen, val);
242 }
void switch_hashtable_this(switch_hashtable_iterator_t *i, const void **key, switch_ssize_t *klen, void **val)