Skip to content

Commit

Permalink
Add encoding for DEFINITION for remote cap
Browse files Browse the repository at this point in the history
  • Loading branch information
dragorn committed Jun 15, 2017
1 parent 1b48871 commit 4acbb31
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
26 changes: 22 additions & 4 deletions simple_datasource_proto.c
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;

Expand Down
9 changes: 9 additions & 0 deletions simple_datasource_proto.h
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 4acbb31

Please sign in to comment.