Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
libloc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
libloc
Commits
7e13db74
Commit
7e13db74
authored
Jan 25, 2018
by
Michael Tremer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add database enumerator interface to perform iterative searches
Signed-off-by:
Michael Tremer
<
michael.tremer@ipfire.org
>
parent
8fb874e9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
0 deletions
+56
-0
src/database.c
src/database.c
+51
-0
src/loc/database.h
src/loc/database.h
+5
-0
No files found.
src/database.c
View file @
7e13db74
...
...
@@ -61,6 +61,12 @@ struct loc_database {
struct
loc_stringpool
*
pool
;
};
struct
loc_database_enumerator
{
struct
loc_ctx
*
ctx
;
struct
loc_database
*
db
;
int
refcount
;
};
static
int
loc_database_read_magic
(
struct
loc_database
*
db
,
FILE
*
f
)
{
struct
loc_database_magic
magic
;
...
...
@@ -578,3 +584,48 @@ LOC_EXPORT int loc_database_lookup_from_string(struct loc_database* db,
return
loc_database_lookup
(
db
,
&
address
,
network
);
}
// Enumerator
LOC_EXPORT
int
loc_database_enumerator_new
(
struct
loc_database_enumerator
**
enumerator
,
struct
loc_database
*
db
)
{
struct
loc_database_enumerator
*
e
=
calloc
(
1
,
sizeof
(
*
e
));
if
(
!
e
)
return
-
ENOMEM
;
// Reference context
e
->
ctx
=
loc_ref
(
db
->
ctx
);
e
->
db
=
loc_database_ref
(
db
);
e
->
refcount
=
1
;
DEBUG
(
e
->
ctx
,
"Database enumerator object allocated at %p
\n
"
,
e
);
*
enumerator
=
e
;
return
0
;
}
LOC_EXPORT
struct
loc_database_enumerator
*
loc_database_enumerator_ref
(
struct
loc_database_enumerator
*
enumerator
)
{
enumerator
->
refcount
++
;
return
enumerator
;
}
static
void
loc_database_enumerator_free
(
struct
loc_database_enumerator
*
enumerator
)
{
DEBUG
(
enumerator
->
ctx
,
"Releasing database enumerator %p
\n
"
,
enumerator
);
// Release all references
loc_database_unref
(
enumerator
->
db
);
loc_unref
(
enumerator
->
ctx
);
free
(
enumerator
);
}
LOC_EXPORT
struct
loc_database_enumerator
*
loc_database_enumerator_unref
(
struct
loc_database_enumerator
*
enumerator
)
{
if
(
!
enumerator
)
return
NULL
;
if
(
--
enumerator
->
refcount
>
0
)
return
enumerator
;
loc_database_enumerator_free
(
enumerator
);
return
NULL
;
}
src/loc/database.h
View file @
7e13db74
...
...
@@ -43,4 +43,9 @@ int loc_database_lookup(struct loc_database* db,
int
loc_database_lookup_from_string
(
struct
loc_database
*
db
,
const
char
*
string
,
struct
loc_network
**
network
);
struct
loc_database_enumerator
;
int
loc_database_enumerator_new
(
struct
loc_database_enumerator
**
enumerator
,
struct
loc_database
*
db
);
struct
loc_database_enumerator
*
loc_database_enumerator_ref
(
struct
loc_database_enumerator
*
enumerator
);
struct
loc_database_enumerator
*
loc_database_enumerator_unref
(
struct
loc_database_enumerator
*
enumerator
);
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment