diff --git a/simple_datasource_proto.c b/simple_datasource_proto.c index 6c11d89fc..c321edd5d 100644 --- a/simple_datasource_proto.c +++ b/simple_datasource_proto.c @@ -37,14 +37,14 @@ uint32_t adler32_partial_csum(uint8_t *in_buf, size_t in_len, if (in_len < 4) return 0; - for (i = 0; i < (in_len - 4); i += 4) { - *s2 += 4 * (*s1 + buf[i]) + 3 * buf[i + 1] + 2 * buf[i+2] + buf[i + 3] + + for (i = 0; i < (in_len - 4); i += 4) { + *s2 += 4 * (*s1 + buf[i]) + 3 * buf[i + 1] + 2 * buf[i+2] + buf[i + 3] + 10 * CHAR_OFFSET; *s1 += (buf[i + 0] + buf[i + 1] + buf[i + 2] + buf[i + 3] + 4 * CHAR_OFFSET); } - for (; i < in_len; i++) { - *s1 += (buf[i] + CHAR_OFFSET); + for (; i < in_len; i++) { + *s1 += (buf[i] + CHAR_OFFSET); *s2 += *s1; } @@ -609,6 +609,24 @@ simple_cap_proto_kv_t *encode_kv_sourcetype(const char *sourcetype) { return kv; } +simple_cap_proto_kv_t *encode_kv_definition(const char *definition) { + simple_cap_proto_kv_t *kv; + + size_t content_sz = strlen(definition); + + kv = (simple_cap_proto_kv_t *) malloc(sizeof(simple_cap_proto_kv_t) + content_sz); + + if (kv == NULL) + return NULL; + + snprintf(kv->header.key, 16, "%.16s", "DEFINITION"); + kv->header.obj_sz = htonl(content_sz); + + strncpy((char *) kv->object, definition, content_sz); + + return kv; +} + simple_cap_proto_kv_t *encode_kv_channel(const char *channel) { simple_cap_proto_kv_t *kv; diff --git a/simple_datasource_proto.h b/simple_datasource_proto.h index f9207b306..a506f160f 100644 --- a/simple_datasource_proto.h +++ b/simple_datasource_proto.h @@ -176,6 +176,14 @@ simple_cap_proto_kv_t *encode_kv_warning(const char *warning); */ simple_cap_proto_kv_t *encode_kv_sourcetype(const char *sourcetype); +/* Encode source definition KV + * + * Returns: + * Pointer on success + * NULL on failure + */ +simple_cap_proto_kv_t *encode_kv_definition(const char *definition); + /* Encode a chanset response * * Returns: @@ -330,6 +338,7 @@ simple_cap_proto_kv_t *encode_kv_chanhop_complex(double rate, char **channels, */ simple_cap_proto_kv_t *encode_kv_message(const char *message, unsigned int flags); + /* Validate if a header passes checksum * * Returns: