1 /* Copyright (C) 2010-2011 Red Hat, Inc.
3 This program is free software: you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation, either version 3 of the License, or
6 (at your option) any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */
16 #if !defined(_SETUP_H)
20 #include <curl/curl.h> /* needed by stuff in state_defs.h (from backend.h) */
21 #include <microhttpd.h> /* ditto */
27 typedef struct _provider
{
36 backend_func_tbl
*func_tbl
;
41 provider_t
*g_master_prov
;
43 const char *parse_config (char *);
44 provider_t
*get_provider (const char *name
);
45 void update_provider (const char *provname
,
47 const char *password
);
48 const char *get_provider_value (const provider_t
*prov
,
51 const char *auto_config (void);
52 int validate_provider (Hash_table
*h
);
53 provider_t
*find_provider (const char *name
);
54 int add_provider (Hash_table
*h
);
55 provider_t
*get_main_provider (void);
56 void set_main_provider (provider_t
*prov
);
58 typedef int (*prov_iterator_fn
) (provider_t
*, void *);
59 int prov_do_for_each (prov_iterator_fn fn
, void *client_data
);
60 provider_t
**hash_get_prov_list (size_t *n
);
68 #define STREQ(a, b) (strcmp (a, b) == 0)
70 enum { SMALL_PRIME
= 13 };
73 kv_hash (void const *x
, size_t table_size
)
75 struct kv_pair
const *p
= x
;
76 return hash_pjw (p
->key
, table_size
);
80 kv_compare (void const *x
, void const *y
)
82 struct kv_pair
const *u
= x
;
83 struct kv_pair
const *v
= y
;
84 return STREQ (u
->key
, v
->key
) ? true : false;
88 kv_hash_insert_new (Hash_table
*ht
, char *k
, char *v
)
90 struct kv_pair
*kv
= malloc (sizeof *kv
);
95 void *e
= hash_insert (ht
, kv
);
100 /* Given a hash table and key K, return the value
101 corresponding to K. The caller must not free K. */
103 kv_hash_lookup (Hash_table
const *ht
, char const *k
)
107 struct kv_pair
*p
= hash_lookup (ht
, &kv
);
108 return p
? p
->val
: NULL
;
112 kv_hash_delete (Hash_table
*ht
, char const *k
)
116 struct kv_pair
*p
= hash_delete (ht
, &kv
);
124 /* Determine whether a key/value pair exists for which PRED_FN returns true.
125 If so, return a pointer to that kv_pair. Otherwise, return NULL. */
126 static struct kv_pair
*
127 kv_find_val (Hash_table
*ht
, Hash_processor pred_fn
, void *ctx
)
129 void *found_kv
= NULL
;
130 hash_do_for_each (ht
, pred_fn
, &found_kv
);