Go to the source code of this file.
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_entry * | ast_db_gettree (const char *family, const char *keytree) |
void | ast_db_freetree (struct ast_db_entry *entry) |
|
Definition at line 180 of file db.c. References ast_log(), ast_mutex_lock, ast_mutex_unlock, and LOG_DEBUG. Referenced by ast_privacy_set(). 00181 { 00182 char fullkey[256]; 00183 DBT key; 00184 int res, fullkeylen; 00185 00186 ast_mutex_lock(&dblock); 00187 if (dbinit()) { 00188 ast_mutex_unlock(&dblock); 00189 return -1; 00190 } 00191 00192 fullkeylen = snprintf(fullkey, sizeof(fullkey), "/%s/%s", family, keys); 00193 memset(&key, 0, sizeof(key)); 00194 key.data = fullkey; 00195 key.size = fullkeylen + 1; 00196 00197 res = astdb->del(astdb, &key, 0); 00198 astdb->sync(astdb, 0); 00199 00200 ast_mutex_unlock(&dblock); 00201 00202 if (res) 00203 ast_log(LOG_DEBUG, "Unable to find key '%s' in family '%s'\n", keys, family); 00204 return res; 00205 }
|
|
Definition at line 71 of file db.c. References ast_mutex_lock, and ast_mutex_unlock. 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 prefix[0] = '\0'; 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 }
|
|
Definition at line 368 of file db.c. References free, and ast_db_entry::next. 00369 { 00370 struct ast_db_entry *last; 00371 while(dbe) { 00372 last = dbe; 00373 dbe = dbe->next; 00374 free(last); 00375 } 00376 }
|
|
Definition at line 138 of file db.c. References ast_log(), ast_mutex_lock, ast_mutex_unlock, 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 value[valuelen - 1] = '\0'; 00173 } else { 00174 ast_log(LOG_NOTICE, "Strange, empty value for /%s/%s\n", family, keys); 00175 } 00176 } 00177 return res; 00178 }
|
|
Definition at line 310 of file db.c. References ast_log(), ast_mutex_lock, ast_mutex_unlock, ast_db_entry::data, ast_db_entry::key, LOG_WARNING, malloc, and ast_db_entry::next. 00311 { 00312 char prefix[256]; 00313 DBT key, data; 00314 char *keys, *values; 00315 int res; 00316 int pass; 00317 struct ast_db_entry *last = NULL; 00318 struct ast_db_entry *cur, *ret=NULL; 00319 00320 if (family && !ast_strlen_zero(family)) { 00321 if (keytree && !ast_strlen_zero(keytree)) 00322 /* Family and key tree */ 00323 snprintf(prefix, sizeof(prefix), "/%s/%s", family, prefix); 00324 else 00325 /* Family only */ 00326 snprintf(prefix, sizeof(prefix), "/%s", family); 00327 } else 00328 prefix[0] = '\0'; 00329 ast_mutex_lock(&dblock); 00330 if (dbinit()) { 00331 ast_mutex_unlock(&dblock); 00332 ast_log(LOG_WARNING, "Database unavailable\n"); 00333 return NULL; 00334 } 00335 memset(&key, 0, sizeof(key)); 00336 memset(&data, 0, sizeof(data)); 00337 pass = 0; 00338 while(!(res = astdb->seq(astdb, &key, &data, pass++ ? R_NEXT : R_FIRST))) { 00339 if (key.size) { 00340 keys = key.data; 00341 keys[key.size - 1] = '\0'; 00342 } else 00343 keys = "<bad key>"; 00344 if (data.size) { 00345 values = data.data; 00346 values[data.size - 1]='\0'; 00347 } else 00348 values = "<bad value>"; 00349 if (keymatch(keys, prefix)) { 00350 cur = malloc(sizeof(struct ast_db_entry) + strlen(keys) + strlen(values) + 2); 00351 if (cur) { 00352 cur->next = NULL; 00353 cur->key = cur->data + strlen(values) + 1; 00354 strcpy(cur->data, values); 00355 strcpy(cur->key, keys); 00356 if (last) 00357 last->next = cur; 00358 else 00359 ret = cur; 00360 last = cur; 00361 } 00362 } 00363 } 00364 ast_mutex_unlock(&dblock); 00365 return ret; 00366 }
|
|
Definition at line 111 of file db.c. References ast_log(), ast_mutex_lock, ast_mutex_unlock, 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 }
|