
Go to the source code of this file.
Data Structures | |
| struct | ast_db_entry |
Functions | |
| int | ast_db_del (const char *family, const char *key) |
| Delete entry in astdb. | |
| int | ast_db_deltree (const char *family, const char *keytree) |
| Delete one or more entries in astdb If both parameters are NULL, the entire database will be purged. If only keytree is NULL, all entries within the family will be purged. It is an error for keytree to have a value when family is NULL. | |
| void | ast_db_freetree (struct ast_db_entry *entry) |
| Free structure created by ast_db_gettree(). | |
| int | ast_db_get (const char *family, const char *key, char *out, int outlen) |
| Get key value specified by family/key. | |
| struct ast_db_entry * | ast_db_gettree (const char *family, const char *keytree) |
| Get a list of values within the astdb tree If family is specified, only those keys will be returned. If keytree is specified, subkeys are expected to exist (separated from the key with a slash). If subkeys do not exist and keytree is specified, the tree will consist of either a single entry or NULL will be returned. | |
| int | ast_db_put (const char *family, const char *key, const char *value) |
| Store value addressed by family/key. | |
Definition in file astdb.h.
| int ast_db_del | ( | const char * | family, | |
| const char * | key | |||
| ) |
Delete entry in astdb.
Definition at line 339 of file db.c.
References ast_debug, ast_log(), ast_mutex_lock, ast_mutex_unlock, db_sync(), dblock, LOG_WARNING, and MAX_DB_FIELD.
Referenced by __expire_registry(), ast_privacy_set(), auth_exec(), cache_lookup_internal(), del_exec(), destroy_all_channels(), destroy_association(), dialgroup_refreshdb(), dump_queue_members(), function_db_delete(), handle_cli_database_del(), handle_dbdel(), manager_dbdel(), mkintf(), process_clearcache(), reload_queue_members(), and update_registry().
00340 { 00341 char fullkey[MAX_DB_FIELD]; 00342 size_t fullkey_len; 00343 int res = 0; 00344 00345 if (strlen(family) + strlen(key) + 2 > sizeof(fullkey) - 1) { 00346 ast_log(LOG_WARNING, "Family and key length must be less than %zu bytes\n", sizeof(fullkey) - 3); 00347 return -1; 00348 } 00349 00350 fullkey_len = snprintf(fullkey, sizeof(fullkey), "/%s/%s", family, key); 00351 00352 ast_mutex_lock(&dblock); 00353 if (sqlite3_bind_text(del_stmt, 1, fullkey, fullkey_len, SQLITE_STATIC) != SQLITE_OK) { 00354 ast_log(LOG_WARNING, "Couldn't bind key to stmt: %s\n", sqlite3_errmsg(astdb)); 00355 res = -1; 00356 } else if (sqlite3_step(del_stmt) != SQLITE_DONE) { 00357 ast_debug(1, "Unable to find key '%s' in family '%s'\n", key, family); 00358 res = -1; 00359 } 00360 sqlite3_reset(del_stmt); 00361 db_sync(); 00362 ast_mutex_unlock(&dblock); 00363 00364 return res; 00365 }
| int ast_db_deltree | ( | const char * | family, | |
| const char * | keytree | |||
| ) |
Delete one or more entries in astdb If both parameters are NULL, the entire database will be purged. If only keytree is NULL, all entries within the family will be purged. It is an error for keytree to have a value when family is NULL.
| -1 | An error occurred | |
| >= | 0 Number of records deleted |
Definition at line 367 of file db.c.
References ast_log(), ast_mutex_lock, ast_mutex_unlock, ast_strlen_zero(), db_sync(), dblock, LOG_WARNING, MAX_DB_FIELD, and prefix.
Referenced by ast_privacy_reset(), deltree_exec(), dundi_flush(), handle_cli_database_deltree(), handle_dbdeltree(), iax_provision_reload(), and manager_dbdeltree().
00368 { 00369 sqlite3_stmt *stmt = deltree_stmt; 00370 char prefix[MAX_DB_FIELD]; 00371 int res = 0; 00372 00373 if (!ast_strlen_zero(family)) { 00374 if (!ast_strlen_zero(keytree)) { 00375 /* Family and key tree */ 00376 snprintf(prefix, sizeof(prefix), "/%s/%s", family, keytree); 00377 } else { 00378 /* Family only */ 00379 snprintf(prefix, sizeof(prefix), "/%s", family); 00380 } 00381 } else { 00382 prefix[0] = '\0'; 00383 stmt = deltree_all_stmt; 00384 } 00385 00386 ast_mutex_lock(&dblock); 00387 if (!ast_strlen_zero(prefix) && (sqlite3_bind_text(stmt, 1, prefix, -1, SQLITE_STATIC) != SQLITE_OK)) { 00388 ast_log(LOG_WARNING, "Could bind %s to stmt: %s\n", prefix, sqlite3_errmsg(astdb)); 00389 res = -1; 00390 } else if (sqlite3_step(stmt) != SQLITE_DONE) { 00391 ast_log(LOG_WARNING, "Couldn't execute stmt: %s\n", sqlite3_errmsg(astdb)); 00392 res = -1; 00393 } 00394 res = sqlite3_changes(astdb); 00395 sqlite3_reset(stmt); 00396 db_sync(); 00397 ast_mutex_unlock(&dblock); 00398 00399 return res; 00400 }
| void ast_db_freetree | ( | struct ast_db_entry * | entry | ) |
Free structure created by ast_db_gettree().
Definition at line 457 of file db.c.
References ast_free, last, and ast_db_entry::next.
Referenced by function_db_keys(), handle_cli_devstate_list(), load_module(), process_clearcache(), and reload_queue_members().
00458 { 00459 struct ast_db_entry *last; 00460 while (dbe) { 00461 last = dbe; 00462 dbe = dbe->next; 00463 ast_free(last); 00464 } 00465 }
| int ast_db_get | ( | const char * | family, | |
| const char * | key, | |||
| char * | out, | |||
| int | outlen | |||
| ) |
Get key value specified by family/key.
Definition at line 306 of file db.c.
References ast_debug, ast_log(), ast_mutex_lock, ast_mutex_unlock, dblock, LOG_WARNING, and MAX_DB_FIELD.
Referenced by ast_privacy_check(), auth_exec(), blacklist_read(), cache_lookup_internal(), check_access(), create_addr(), custom_devstate_callback(), database_increment(), destroy_all_channels(), function_db_delete(), function_db_exists(), function_db_read(), handle_cli_database_get(), handle_dbget(), iax_provision_version(), load_password(), manager_dbget(), mkintf(), populate_addr(), reg_source_db(), and reload_queue_members().
00307 { 00308 const unsigned char *result; 00309 char fullkey[MAX_DB_FIELD]; 00310 size_t fullkey_len; 00311 int res = 0; 00312 00313 if (strlen(family) + strlen(key) + 2 > sizeof(fullkey) - 1) { 00314 ast_log(LOG_WARNING, "Family and key length must be less than %zu bytes\n", sizeof(fullkey) - 3); 00315 return -1; 00316 } 00317 00318 fullkey_len = snprintf(fullkey, sizeof(fullkey), "/%s/%s", family, key); 00319 00320 ast_mutex_lock(&dblock); 00321 if (sqlite3_bind_text(get_stmt, 1, fullkey, fullkey_len, SQLITE_STATIC) != SQLITE_OK) { 00322 ast_log(LOG_WARNING, "Couldn't bind key to stmt: %s\n", sqlite3_errmsg(astdb)); 00323 res = -1; 00324 } else if (sqlite3_step(get_stmt) != SQLITE_ROW) { 00325 ast_debug(1, "Unable to find key '%s' in family '%s'\n", key, family); 00326 res = -1; 00327 } else if (!(result = sqlite3_column_text(get_stmt, 0))) { 00328 ast_log(LOG_WARNING, "Couldn't get value\n"); 00329 res = -1; 00330 } else { 00331 strncpy(value, (const char *) result, valuelen); 00332 } 00333 sqlite3_reset(get_stmt); 00334 ast_mutex_unlock(&dblock); 00335 00336 return res; 00337 }
| struct ast_db_entry* ast_db_gettree | ( | const char * | family, | |
| const char * | keytree | |||
| ) | [read] |
Get a list of values within the astdb tree If family is specified, only those keys will be returned. If keytree is specified, subkeys are expected to exist (separated from the key with a slash). If subkeys do not exist and keytree is specified, the tree will consist of either a single entry or NULL will be returned.
Resulting tree should be freed by passing the return value to ast_db_freetree() when usage is concluded.
Definition at line 402 of file db.c.
References ast_log(), ast_malloc, ast_mutex_lock, ast_mutex_unlock, ast_strlen_zero(), ast_db_entry::data, dblock, ast_db_entry::key, last, LOG_WARNING, MAX_DB_FIELD, ast_db_entry::next, and prefix.
Referenced by function_db_keys(), handle_cli_devstate_list(), load_module(), process_clearcache(), and reload_queue_members().
00403 { 00404 char prefix[MAX_DB_FIELD]; 00405 sqlite3_stmt *stmt = gettree_stmt; 00406 struct ast_db_entry *cur, *last = NULL, *ret = NULL; 00407 00408 if (!ast_strlen_zero(family)) { 00409 if (!ast_strlen_zero(keytree)) { 00410 /* Family and key tree */ 00411 snprintf(prefix, sizeof(prefix), "/%s/%s", family, keytree); 00412 } else { 00413 /* Family only */ 00414 snprintf(prefix, sizeof(prefix), "/%s", family); 00415 } 00416 } else { 00417 prefix[0] = '\0'; 00418 stmt = gettree_all_stmt; 00419 } 00420 00421 ast_mutex_lock(&dblock); 00422 if (!ast_strlen_zero(prefix) && (sqlite3_bind_text(stmt, 1, prefix, -1, SQLITE_STATIC) != SQLITE_OK)) { 00423 ast_log(LOG_WARNING, "Could bind %s to stmt: %s\n", prefix, sqlite3_errmsg(astdb)); 00424 sqlite3_reset(stmt); 00425 ast_mutex_unlock(&dblock); 00426 return NULL; 00427 } 00428 00429 while (sqlite3_step(stmt) == SQLITE_ROW) { 00430 const char *key_s, *value_s; 00431 if (!(key_s = (const char *) sqlite3_column_text(stmt, 0))) { 00432 break; 00433 } 00434 if (!(value_s = (const char *) sqlite3_column_text(stmt, 1))) { 00435 break; 00436 } 00437 if (!(cur = ast_malloc(sizeof(*cur) + strlen(key_s) + strlen(value_s) + 2))) { 00438 break; 00439 } 00440 cur->next = NULL; 00441 cur->key = cur->data + strlen(value_s) + 1; 00442 strcpy(cur->data, value_s); 00443 strcpy(cur->key, key_s); 00444 if (last) { 00445 last->next = cur; 00446 } else { 00447 ret = cur; 00448 } 00449 last = cur; 00450 } 00451 sqlite3_reset(stmt); 00452 ast_mutex_unlock(&dblock); 00453 00454 return ret; 00455 }
| int ast_db_put | ( | const char * | family, | |
| const char * | key, | |||
| const char * | value | |||
| ) |
Store value addressed by family/key.
Definition at line 274 of file db.c.
References ast_log(), ast_mutex_lock, ast_mutex_unlock, db_sync(), dblock, LOG_WARNING, and MAX_DB_FIELD.
Referenced by __analog_ss_thread(), ast_privacy_set(), cache_save(), cache_save_hint(), database_increment(), devstate_write(), dialgroup_refreshdb(), dump_queue_members(), function_db_write(), handle_cli_database_put(), handle_cli_devstate_change(), handle_command_response(), handle_dbput(), iax_provision_build(), manager_dbput(), mgcp_ss(), parse_register_contact(), save_secret(), and update_registry().
00275 { 00276 char fullkey[MAX_DB_FIELD]; 00277 size_t fullkey_len; 00278 int res = 0; 00279 00280 if (strlen(family) + strlen(key) + 2 > sizeof(fullkey) - 1) { 00281 ast_log(LOG_WARNING, "Family and key length must be less than %zu bytes\n", sizeof(fullkey) - 3); 00282 return -1; 00283 } 00284 00285 fullkey_len = snprintf(fullkey, sizeof(fullkey), "/%s/%s", family, key); 00286 00287 ast_mutex_lock(&dblock); 00288 if (sqlite3_bind_text(put_stmt, 1, fullkey, fullkey_len, SQLITE_STATIC) != SQLITE_OK) { 00289 ast_log(LOG_WARNING, "Couldn't bind key to stmt: %s\n", sqlite3_errmsg(astdb)); 00290 res = -1; 00291 } else if (sqlite3_bind_text(put_stmt, 2, value, -1, SQLITE_STATIC) != SQLITE_OK) { 00292 ast_log(LOG_WARNING, "Couldn't bind value to stmt: %s\n", sqlite3_errmsg(astdb)); 00293 res = -1; 00294 } else if (sqlite3_step(put_stmt) != SQLITE_DONE) { 00295 ast_log(LOG_WARNING, "Couldn't execute statment: %s\n", sqlite3_errmsg(astdb)); 00296 res = -1; 00297 } 00298 00299 sqlite3_reset(put_stmt); 00300 db_sync(); 00301 ast_mutex_unlock(&dblock); 00302 00303 return res; 00304 }
1.5.6