diff --git a/cli.c b/cli.c index 9d1ea003..2013f262 100644 --- a/cli.c +++ b/cli.c @@ -25,6 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "serval.h" #include "rhizome.h" #include "strbuf_helpers.h" +#include "dataformats.h" int cli_usage(const struct cli_schema *commands, XPRINTF xpf) { diff --git a/commandline.c b/commandline.c index ab474b41..e579d982 100644 --- a/commandline.c +++ b/commandline.c @@ -46,6 +46,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "overlay_address.h" #include "overlay_buffer.h" #include "keyring.h" +#include "dataformats.h" extern struct cli_schema command_line_options[]; diff --git a/conf_schema.c b/conf_schema.c index 02348b8a..c53c74f5 100644 --- a/conf_schema.c +++ b/conf_schema.c @@ -32,6 +32,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "strbuf.h" #include "strbuf_helpers.h" #include "conf.h" +#include "dataformats.h" int cf_opt_boolean(bool_t *booleanp, const char *text) { diff --git a/dataformats.c b/dataformats.c index 5180775d..ed841ca2 100644 --- a/dataformats.c +++ b/dataformats.c @@ -17,10 +17,11 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include #include "serval.h" #include "rhizome.h" #include "str.h" -#include +#include "dataformats.h" int cmp_sid_t(const sid_t *a, const sid_t *b) { @@ -214,7 +215,7 @@ void write_uint16(unsigned char *o,uint16_t v) { *(o++)=v&0xff; v=v>>8; } } -uint64_t read_uint64(unsigned char *o) +uint64_t read_uint64(const unsigned char *o) { int i; uint64_t v=0; @@ -222,7 +223,7 @@ uint64_t read_uint64(unsigned char *o) return v; } -uint32_t read_uint32(unsigned char *o) +uint32_t read_uint32(const unsigned char *o) { int i; uint32_t v=0; @@ -230,7 +231,7 @@ uint32_t read_uint32(unsigned char *o) return v; } -uint16_t read_uint16(unsigned char *o) +uint16_t read_uint16(const unsigned char *o) { int i; uint16_t v=0; diff --git a/dataformats.h b/dataformats.h new file mode 100644 index 00000000..67afb746 --- /dev/null +++ b/dataformats.h @@ -0,0 +1,26 @@ +#ifndef __SERVALD_DATA_FORMATS_H +#define __SERVALD_DATA_FORMATS_H + +int str_is_subscriber_id(const char *sid); +int strn_is_subscriber_id(const char *sid, size_t *lenp); +int str_is_did(const char *did); +int strn_is_did(const char *did, size_t *lenp); + +int rhizome_strn_is_manifest_id(const char *text); +int rhizome_str_is_manifest_id(const char *text); +int rhizome_strn_is_bundle_key(const char *text); +int rhizome_str_is_bundle_key(const char *text); +int rhizome_strn_is_bundle_crypt_key(const char *text); +int rhizome_str_is_bundle_crypt_key(const char *text); +int rhizome_strn_is_file_hash(const char *text); +int rhizome_str_is_file_hash(const char *text); +int rhizome_str_is_manifest_service(const char *text); + +void write_uint64(unsigned char *o,uint64_t v); +void write_uint16(unsigned char *o,uint16_t v); +void write_uint32(unsigned char *o,uint32_t v); +uint64_t read_uint64(const unsigned char *o); +uint32_t read_uint32(const unsigned char *o); +uint16_t read_uint16(const unsigned char *o); + +#endif diff --git a/dna_helper.c b/dna_helper.c index d1d18b42..66bceb96 100644 --- a/dna_helper.c +++ b/dna_helper.c @@ -27,6 +27,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "strbuf.h" #include "strbuf_helpers.h" #include "overlay_address.h" +#include "dataformats.h" /* The challenge with making an interface for calling an external program to diff --git a/headerfiles.mk b/headerfiles.mk index 08a0b2e4..fc9ae543 100644 --- a/headerfiles.mk +++ b/headerfiles.mk @@ -19,6 +19,7 @@ HDRS= fifo.h \ conf.h \ conf_schema.h \ crypto.h \ + dataformats.h \ log.h \ net.h \ fdqueue.h \ diff --git a/keyring.c b/keyring.c index 9d0df5c6..3182e6bb 100644 --- a/keyring.c +++ b/keyring.c @@ -30,6 +30,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "crypto.h" #include "overlay_packet.h" #include "keyring.h" +#include "dataformats.h" static void keyring_free_keypair(keypair *kp); static void keyring_free_context(keyring_context *c); diff --git a/meshms.c b/meshms.c index c88a984b..3c3d18ca 100644 --- a/meshms.c +++ b/meshms.c @@ -6,6 +6,7 @@ #include "crypto.h" #include "strlcpy.h" #include "keyring.h" +#include "dataformats.h" #define MESHMS_BLOCK_TYPE_ACK 0x01 #define MESHMS_BLOCK_TYPE_MESSAGE 0x02 diff --git a/monitor.c b/monitor.c index 20a710e8..e28016d9 100644 --- a/monitor.c +++ b/monitor.c @@ -33,6 +33,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "overlay_address.h" #include "monitor-client.h" #include "socket.h" +#include "dataformats.h" #ifdef HAVE_UCRED_H #include diff --git a/overlay_mdp_services.c b/overlay_mdp_services.c index 3c1fbc57..2abc30d4 100644 --- a/overlay_mdp_services.c +++ b/overlay_mdp_services.c @@ -29,6 +29,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "crypto.h" #include "log.h" #include "keyring.h" +#include "dataformats.h" int rhizome_mdp_send_block(struct subscriber *dest, const rhizome_bid_t *bid, uint64_t version, uint64_t fileOffset, uint32_t bitmap, uint16_t blockLength) { diff --git a/rhizome.c b/rhizome.c index 3db8cfc5..68495b3b 100644 --- a/rhizome.c +++ b/rhizome.c @@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "conf.h" #include "str.h" #include "rhizome.h" +#include "dataformats.h" int is_rhizome_enabled() { diff --git a/rhizome.h b/rhizome.h index a45cd823..d99f900a 100644 --- a/rhizome.h +++ b/rhizome.h @@ -423,16 +423,6 @@ int rhizome_cleanup(struct rhizome_cleanup_report *report); int rhizome_manifest_createid(rhizome_manifest *m); int rhizome_get_bundle_from_seed(rhizome_manifest *m, const char *seed); -int rhizome_strn_is_manifest_id(const char *text); -int rhizome_str_is_manifest_id(const char *text); -int rhizome_strn_is_bundle_key(const char *text); -int rhizome_str_is_bundle_key(const char *text); -int rhizome_strn_is_bundle_crypt_key(const char *text); -int rhizome_str_is_bundle_crypt_key(const char *text); -int rhizome_strn_is_file_hash(const char *text); -int rhizome_str_is_file_hash(const char *text); -int rhizome_str_is_manifest_service(const char *text); - int is_http_header_complete(const char *buf, size_t len, size_t read_since_last_call); typedef struct sqlite_retry_state { diff --git a/rhizome_bundle.c b/rhizome_bundle.c index 8ecf5b51..a8949032 100644 --- a/rhizome_bundle.c +++ b/rhizome_bundle.c @@ -26,6 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "str.h" #include "mem.h" #include "keyring.h" +#include "dataformats.h" static const char *rhizome_manifest_get(const rhizome_manifest *m, const char *var) { diff --git a/rhizome_crypto.c b/rhizome_crypto.c index 3055204f..fc2868f5 100644 --- a/rhizome_crypto.c +++ b/rhizome_crypto.c @@ -23,13 +23,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "crypto_sign_edwards25519sha512batch.h" #include "nacl/src/crypto_sign_edwards25519sha512batch_ref/ge.h" - #include "serval.h" #include "conf.h" #include "str.h" #include "rhizome.h" #include "crypto.h" #include "keyring.h" +#include "dataformats.h" /* Work out the encrypt/decrypt key for the supplied manifest. If the manifest is not encrypted, then return NULL. diff --git a/rhizome_fetch.c b/rhizome_fetch.c index 6546fd4e..d2614b10 100644 --- a/rhizome_fetch.c +++ b/rhizome_fetch.c @@ -27,6 +27,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "strbuf_helpers.h" #include "overlay_address.h" #include "socket.h" +#include "dataformats.h" /* Represents a queued fetch of a bundle payload, for which the manifest is already known. */ diff --git a/serval.h b/serval.h index 983e0daf..a84d5e81 100644 --- a/serval.h +++ b/serval.h @@ -163,11 +163,6 @@ int cmp_sid_t(const sid_t *a, const sid_t *b); int str_to_sid_t(sid_t *sid, const char *hex); int strn_to_sid_t(sid_t *sid, const char *hex, const char **endp); -int str_is_subscriber_id(const char *sid); -int strn_is_subscriber_id(const char *sid, size_t *lenp); -int str_is_did(const char *did); -int strn_is_did(const char *did, size_t *lenp); - #define alloca_tohex_sas(sas) alloca_tohex((sas), SAS_SIZE) /* @@ -686,13 +681,6 @@ int limit_init(struct limit_state *state, int rate_micro_seconds); int olsr_init_socket(void); int olsr_send(struct overlay_frame *frame); -void write_uint64(unsigned char *o,uint64_t v); -void write_uint16(unsigned char *o,uint16_t v); -void write_uint32(unsigned char *o,uint32_t v); -uint64_t read_uint64(unsigned char *o); -uint32_t read_uint32(unsigned char *o); -uint16_t read_uint16(unsigned char *o); - int pack_uint(unsigned char *buffer, uint64_t v); int measure_packed_uint(uint64_t v); int unpack_uint(unsigned char *buffer, int buff_size, uint64_t *v); diff --git a/slip.c b/slip.c index daa37052..134d3e39 100644 --- a/slip.c +++ b/slip.c @@ -20,6 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "serval.h" #include "conf.h" #include "log.h" +#include "dataformats.h" #define DEBUG_packet_visualise(M,P,N) logServalPacket(LOG_LEVEL_DEBUG, __WHENCE__, (M), (P), (N))