Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals

astdb.h File Reference

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Data Structures

struct  ast_db_entry

Functions

int ast_db_get (const char *family, const char *key, char *out, int outlen)
int ast_db_put (const char *family, const char *key, char *value)
int ast_db_del (const char *family, const char *key)
int ast_db_deltree (const char *family, const char *keytree)
ast_db_entryast_db_gettree (const char *family, const char *keytree)
void ast_db_freetree (struct ast_db_entry *entry)


Function Documentation

int ast_db_del const char *  family,
const char *  key
 

Definition at line 179 of file db.c.

References ast_log(), ast_mutex_lock, ast_mutex_unlock, key(), and LOG_DEBUG.

Referenced by ast_privacy_set().

00180 { 00181 char fullkey[256]; 00182 DBT key; 00183 int res, fullkeylen; 00184 00185 ast_mutex_lock(&dblock); 00186 if (dbinit()) { 00187 ast_mutex_unlock(&dblock); 00188 return -1; 00189 } 00190 00191 fullkeylen = snprintf(fullkey, sizeof(fullkey), "/%s/%s", family, keys); 00192 memset(&key, 0, sizeof(key)); 00193 key.data = fullkey; 00194 key.size = fullkeylen + 1; 00195 00196 res = astdb->del(astdb, &key, 0); 00197 astdb->sync(astdb, 0); 00198 00199 ast_mutex_unlock(&dblock); 00200 00201 if (res) 00202 ast_log(LOG_DEBUG, "Unable to find key '%s' in family '%s'\n", keys, family); 00203 return res; 00204 }

int ast_db_deltree const char *  family,
const char *  keytree
 

Definition at line 71 of file db.c.

References ast_mutex_lock, ast_mutex_unlock, and key().

Referenced by ast_privacy_reset().

00072 { 00073 char prefix[256]; 00074 DBT key, data; 00075 char *keys; 00076 int res; 00077 int pass; 00078 00079 if (family) { 00080 if (keytree) 00081 snprintf(prefix, sizeof(prefix), "/%s/%s", family, keytree); 00082 else 00083 snprintf(prefix, sizeof(prefix), "/%s", family); 00084 } else if (keytree) 00085 return -1; 00086 else 00087 strcpy(prefix, ""); 00088 00089 ast_mutex_lock(&dblock); 00090 if (dbinit()) 00091 return -1; 00092 00093 memset(&key, 0, sizeof(key)); 00094 memset(&data, 0, sizeof(data)); 00095 pass = 0; 00096 while(!(res = astdb->seq(astdb, &key, &data, pass++ ? R_NEXT : R_FIRST))) { 00097 if (key.size) { 00098 keys = key.data; 00099 keys[key.size - 1] = '\0'; 00100 } else 00101 keys = "<bad key>"; 00102 if (keymatch(keys, prefix)) { 00103 astdb->del(astdb, &key, 0); 00104 } 00105 } 00106 astdb->sync(astdb, 0); 00107 ast_mutex_unlock(&dblock); 00108 return 0; 00109 }

void ast_db_freetree struct ast_db_entry entry  ) 
 

Definition at line 367 of file db.c.

References free, and ast_db_entry::next.

00368 { 00369 struct ast_db_entry *last; 00370 while(dbe) { 00371 last = dbe; 00372 dbe = dbe->next; 00373 free(last); 00374 } 00375 }

int ast_db_get const char *  family,
const char *  key,
char *  out,
int  outlen
 

Definition at line 138 of file db.c.

References ast_log(), ast_mutex_lock, ast_mutex_unlock, key(), LOG_DEBUG, and LOG_NOTICE.

Referenced by ast_privacy_check().

00139 { 00140 char fullkey[256]=""; 00141 DBT key, data; 00142 int res, fullkeylen; 00143 00144 ast_mutex_lock(&dblock); 00145 if (dbinit()) { 00146 ast_mutex_unlock(&dblock); 00147 return -1; 00148 } 00149 00150 fullkeylen = snprintf(fullkey, sizeof(fullkey), "/%s/%s", family, keys); 00151 memset(&key, 0, sizeof(key)); 00152 memset(&data, 0, sizeof(data)); 00153 memset(value, 0, valuelen); 00154 key.data = fullkey; 00155 key.size = fullkeylen + 1; 00156 00157 res = astdb->get(astdb, &key, &data, 0); 00158 00159 ast_mutex_unlock(&dblock); 00160 00161 /* Be sure to NULL terminate our data either way */ 00162 if (res) { 00163 ast_log(LOG_DEBUG, "Unable to find key '%s' in family '%s'\n", keys, family); 00164 } else { 00165 #if 0 00166 printf("Got value of size %d\n", data.size); 00167 #endif 00168 if (data.size) { 00169 ((char *)data.data)[data.size - 1] = '\0'; 00170 /* Make sure that we don't write too much to the dst pointer or we don't read too much from the source pointer */ 00171 strncpy(value, data.data, (valuelen > data.size) ? data.size : valuelen); 00172 } else { 00173 ast_log(LOG_NOTICE, "Strange, empty value for /%s/%s\n", family, keys); 00174 } 00175 } 00176 return res; 00177 }

struct ast_db_entry* ast_db_gettree const char *  family,
const char *  keytree
 

Definition at line 309 of file db.c.

References ast_log(), ast_mutex_lock, ast_mutex_unlock, key(), LOG_WARNING, and malloc.

00310 { 00311 char prefix[256]; 00312 DBT key, data; 00313 char *keys, *values; 00314 int res; 00315 int pass; 00316 struct ast_db_entry *last = NULL; 00317 struct ast_db_entry *cur, *ret=NULL; 00318 00319 if (family && !ast_strlen_zero(family)) { 00320 if (keytree && !ast_strlen_zero(keytree)) 00321 /* Family and key tree */ 00322 snprintf(prefix, sizeof(prefix), "/%s/%s", family, prefix); 00323 else 00324 /* Family only */ 00325 snprintf(prefix, sizeof(prefix), "/%s", family); 00326 } else 00327 strcpy(prefix, ""); 00328 ast_mutex_lock(&dblock); 00329 if (dbinit()) { 00330 ast_mutex_unlock(&dblock); 00331 ast_log(LOG_WARNING, "Database unavailable\n"); 00332 return NULL; 00333 } 00334 memset(&key, 0, sizeof(key)); 00335 memset(&data, 0, sizeof(data)); 00336 pass = 0; 00337 while(!(res = astdb->seq(astdb, &key, &data, pass++ ? R_NEXT : R_FIRST))) { 00338 if (key.size) { 00339 keys = key.data; 00340 keys[key.size - 1] = '\0'; 00341 } else 00342 keys = "<bad key>"; 00343 if (data.size) { 00344 values = data.data; 00345 values[data.size - 1]='\0'; 00346 } else 00347 values = "<bad value>"; 00348 if (keymatch(keys, prefix)) { 00349 cur = malloc(sizeof(struct ast_db_entry) + strlen(keys) + strlen(values) + 2); 00350 if (cur) { 00351 cur->next = NULL; 00352 cur->key = cur->data + strlen(values) + 1; 00353 strcpy(cur->data, values); 00354 strcpy(cur->key, keys); 00355 if (last) 00356 last->next = cur; 00357 else 00358 ret = cur; 00359 last = cur; 00360 } 00361 } 00362 } 00363 ast_mutex_unlock(&dblock); 00364 return ret; 00365 }

int ast_db_put const char *  family,
const char *  key,
char *  value
 

Definition at line 111 of file db.c.

References ast_log(), ast_mutex_lock, ast_mutex_unlock, key(), and LOG_WARNING.

Referenced by ast_privacy_set().

00112 { 00113 char fullkey[256]; 00114 DBT key, data; 00115 int res, fullkeylen; 00116 00117 ast_mutex_lock(&dblock); 00118 if (dbinit()) { 00119 ast_mutex_unlock(&dblock); 00120 return -1; 00121 } 00122 00123 fullkeylen = snprintf(fullkey, sizeof(fullkey), "/%s/%s", family, keys); 00124 memset(&key, 0, sizeof(key)); 00125 memset(&data, 0, sizeof(data)); 00126 key.data = fullkey; 00127 key.size = fullkeylen + 1; 00128 data.data = value; 00129 data.size = strlen(value) + 1; 00130 res = astdb->put(astdb, &key, &data, 0); 00131 astdb->sync(astdb, 0); 00132 ast_mutex_unlock(&dblock); 00133 if (res) 00134 ast_log(LOG_WARNING, "Unable to put value '%s' for key '%s' in family '%s'\n", value, keys, family); 00135 return res; 00136 }


Generated on Sat Jun 12 16:41:02 2004 for Asterisk by doxygen 1.3.7