int db_walk(void *dbh, int (*walk_func)(char *key, void *data, int len)) { DBT key, data; DBC *dbc; int rc = 0; GET_DB(dbh); if (!walk_func) return -EINVAL; if ((rc = db->cursor(db, NULL, &dbc, 0))) { db->close(db, 0); return rc; } memset(&key, 0, sizeof(key)); memset(&data, 0, sizeof(data)); while (dbc->c_get(dbc, &key, &data, DB_NEXT) == 0) if ((rc = walk_func(key.data, data.data, data.size))) break; dbc->c_close(dbc); return rc; }
static void InorderTreeWalk(rb_red_blk_tree* tree, rb_red_blk_node* x, void (*walk_func) (const void* key, void* value, void* data), void *data) { if (x != tree->nil) { InorderTreeWalk(tree,x->left, walk_func, data); walk_func(x->key, x->info, data); InorderTreeWalk(tree,x->right, walk_func, data); } }
//-------------------------------------------------------------------------- int callgraph_t::walk_func(func_t *func, funcs_walk_options_t *opt, int level) { // add a node for this function ea_t func_start = func->startEA; int id = add(func_start); func_item_iterator_t fii; for ( bool fi_ok=fii.set(func); fi_ok; fi_ok=fii.next_code() ) { xrefblk_t xb; for ( bool xb_ok = xb.first_from(fii.current(), XREF_FAR); xb_ok && xb.iscode; xb_ok = xb.next_from() ) { func_t *f = get_func(xb.to); if ( f == NULL ) continue; int id2; if ( !visited(f->startEA, &id2) ) { if ( func_contains(func, xb.to) ) continue; bool skip = false; if ( opt != NULL ) { skip = // skip lib funcs? (((f->flags & FUNC_LIB) != 0) && ((opt->flags & FWO_SKIPLIB) != 0)) // max recursion is off, and limit is reached? || ( ((opt->flags & FWO_RECURSE_UNLIM) == 0) && (level > opt->recurse_limit) ); } if ( skip ) id2 = add(f->startEA); else id2 = walk_func(f, opt, level+1); } create_edge(id, id2); } } return id; }
svn_error_t * svn_config_walk_auth_data(const char *config_dir, svn_config_auth_walk_func_t walk_func, void *walk_baton, apr_pool_t *scratch_pool) { int i; apr_pool_t *iterpool; svn_boolean_t finished = FALSE; const char *cred_kinds[] = { SVN_AUTH_CRED_SIMPLE, SVN_AUTH_CRED_USERNAME, SVN_AUTH_CRED_SSL_CLIENT_CERT, SVN_AUTH_CRED_SSL_CLIENT_CERT_PW, SVN_AUTH_CRED_SSL_SERVER_TRUST, NULL }; iterpool = svn_pool_create(scratch_pool); for (i = 0; cred_kinds[i]; i++) { const char *item_path; const char *dir_path; apr_hash_t *nodes; svn_error_t *err; apr_pool_t *itempool; apr_hash_index_t *hi; svn_pool_clear(iterpool); if (finished) break; SVN_ERR(svn_auth__file_path(&item_path, cred_kinds[i], "!", config_dir, iterpool)); dir_path = svn_dirent_dirname(item_path, iterpool); err = svn_io_get_dirents3(&nodes, dir_path, TRUE, iterpool, iterpool); if (err) { if (!APR_STATUS_IS_ENOENT(err->apr_err) && !SVN__APR_STATUS_IS_ENOTDIR(err->apr_err)) return svn_error_trace(err); svn_error_clear(err); continue; } itempool = svn_pool_create(iterpool); for (hi = apr_hash_first(iterpool, nodes); hi; hi = apr_hash_next(hi)) { svn_io_dirent2_t *dirent = apr_hash_this_val(hi); svn_stream_t *stream; apr_hash_t *creds_hash; const svn_string_t *realm; svn_boolean_t delete_file = FALSE; if (finished) break; if (dirent->kind != svn_node_file) continue; svn_pool_clear(itempool); item_path = svn_dirent_join(dir_path, apr_hash_this_key(hi), itempool); err = svn_stream_open_readonly(&stream, item_path, itempool, itempool); if (err) { /* Ignore this file. There are no credentials in it anyway */ svn_error_clear(err); continue; } creds_hash = apr_hash_make(itempool); err = svn_hash_read2(creds_hash, stream, SVN_HASH_TERMINATOR, itempool); err = svn_error_compose_create(err, svn_stream_close(stream)); if (err) { /* Ignore this file. There are no credentials in it anyway */ svn_error_clear(err); continue; } realm = svn_hash_gets(creds_hash, SVN_CONFIG_REALMSTRING_KEY); if (! realm) continue; /* Not an auth file */ err = walk_func(&delete_file, walk_baton, cred_kinds[i], realm->data, creds_hash, itempool); if (err && err->apr_err == SVN_ERR_CEASE_INVOCATION) { svn_error_clear(err); err = SVN_NO_ERROR; finished = TRUE; } SVN_ERR(err); if (delete_file) { /* Delete the file on disk */ SVN_ERR(svn_io_remove_file2(item_path, TRUE, itempool)); } } } svn_pool_destroy(iterpool); return SVN_NO_ERROR; }