commit d73a1629448e20d2323fbffe5cf0da8dd5cf80a8
parent b4cce29eceb379927c76262bc7cf0eecea45d6a0
Author: William Casarin <jb55@jb55.com>
Date: Sat, 3 Aug 2024 14:24:58 -0700
make more things const
rust is happier this way
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
3 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/src/nostrdb.c b/src/nostrdb.c
@@ -589,7 +589,7 @@ int ndb_filter_end(struct ndb_filter *filter)
}
static inline struct ndb_filter_elements *
-ndb_filter_get_elements_by_offset(struct ndb_filter *filter, int offset)
+ndb_filter_get_elements_by_offset(const struct ndb_filter *filter, int offset)
{
struct ndb_filter_elements *els;
@@ -605,13 +605,13 @@ ndb_filter_get_elements_by_offset(struct ndb_filter *filter, int offset)
}
struct ndb_filter_elements *
-ndb_filter_current_element(struct ndb_filter *filter)
+ndb_filter_current_element(const struct ndb_filter *filter)
{
return ndb_filter_get_elements_by_offset(filter, filter->current);
}
static inline struct ndb_filter_elements *
-ndb_filter_get_elements(struct ndb_filter *filter, int index)
+ndb_filter_get_elements(const struct ndb_filter *filter, int index)
{
if (filter->num_elements <= 0)
return NULL;
@@ -623,7 +623,7 @@ ndb_filter_get_elements(struct ndb_filter *filter, int index)
}
static inline unsigned char *
-ndb_filter_elements_data(struct ndb_filter *filter, int offset)
+ndb_filter_elements_data(const struct ndb_filter *filter, int offset)
{
unsigned char *data;
@@ -638,13 +638,13 @@ ndb_filter_elements_data(struct ndb_filter *filter, int offset)
}
static inline unsigned char *
-ndb_filter_get_id_element(struct ndb_filter *filter, struct ndb_filter_elements *els, int index)
+ndb_filter_get_id_element(const struct ndb_filter *filter, struct ndb_filter_elements *els, int index)
{
return ndb_filter_elements_data(filter, els->elements[index]);
}
static inline const char *
-ndb_filter_get_string_element(struct ndb_filter *filter, struct ndb_filter_elements *els, int index)
+ndb_filter_get_string_element(const struct ndb_filter *filter, struct ndb_filter_elements *els, int index)
{
return (const char *)ndb_filter_elements_data(filter, els->elements[index]);
}
@@ -4803,7 +4803,7 @@ int ndb_note_json(struct ndb_note *note, char *buf, int buflen)
}
static int cursor_push_json_elem_array(struct cursor *cur,
- struct ndb_filter *filter,
+ const struct ndb_filter *filter,
struct ndb_filter_elements *elems)
{
int i;
@@ -4849,7 +4849,7 @@ static int cursor_push_json_elem_array(struct cursor *cur,
return 1;
}
-int ndb_filter_json(struct ndb_filter *filter, char *buf, int buflen)
+int ndb_filter_json(const struct ndb_filter *filter, char *buf, int buflen)
{
struct cursor cur, *c = &cur;
struct ndb_filter_elements *elems;
diff --git a/src/nostrdb.h b/src/nostrdb.h
@@ -488,7 +488,7 @@ int ndb_filter_add_id_element(struct ndb_filter *, const unsigned char *id);
int ndb_filter_add_int_element(struct ndb_filter *, uint64_t integer);
int ndb_filter_add_str_element(struct ndb_filter *, const char *str);
-struct ndb_filter_elements *ndb_filter_current_element(struct ndb_filter *);
+struct ndb_filter_elements *ndb_filter_current_element(const struct ndb_filter *);
int ndb_filter_start_field(struct ndb_filter *, enum ndb_filter_fieldtype);
int ndb_filter_start_tag_field(struct ndb_filter *, char tag);
int ndb_filter_matches(struct ndb_filter *, struct ndb_note *);
@@ -496,7 +496,7 @@ int ndb_filter_clone(struct ndb_filter *dst, struct ndb_filter *src);
int ndb_filter_end(struct ndb_filter *);
void ndb_filter_end_field(struct ndb_filter *);
void ndb_filter_destroy(struct ndb_filter *);
-int ndb_filter_json(struct ndb_filter *, char *buf, int buflen);
+int ndb_filter_json(const struct ndb_filter *, char *buf, int buflen);
// SUBSCRIPTIONS
uint64_t ndb_subscribe(struct ndb *, struct ndb_filter *, int num_filters);
diff --git a/test.c b/test.c
@@ -1592,8 +1592,8 @@ int main(int argc, const char *argv[]) {
test_single_url_parsing();
test_url_parsing();
test_query();
- test_weird_note_corruption();
test_tag_query();
+ test_weird_note_corruption();
test_parse_content();
test_subscriptions();
test_comma_url_parsing();