From df5bc9cf01ba7dc2e680bfc70151f38d05338edc Mon Sep 17 00:00:00 2001 From: Sven Gestegard Robertz <sven.robertz@cs.lth.se> Date: Fri, 21 Nov 2014 16:58:03 +0100 Subject: [PATCH] started reviving experimental/sig-parser --- lib/c/Makefile | 5 ++++- lib/c/experimental/labcomm_sig_parser.c | 28 +++++++++++++++---------- lib/c/experimental/labcomm_sig_parser.h | 15 +++++++------ lib/c/experimental/test_sig_parser.c | 3 ++- 4 files changed, 32 insertions(+), 19 deletions(-) diff --git a/lib/c/Makefile b/lib/c/Makefile index 46163cb..1bf5af1 100644 --- a/lib/c/Makefile +++ b/lib/c/Makefile @@ -50,7 +50,10 @@ ifeq ($(LABCOMM_EXPERIMENTAL),true) experimental/labcomm_thr_reader_writer.o \ experimental/ThrottleDrv/ethernet_drv.o \ experimental/ThrottleDrv/throttle_drv.o \ - experimental/labcomm_udp_reader_writer.o + experimental/labcomm_udp_reader_writer.o\ + experimental/labcomm_sig_parser.o \ + experimental/test_sig_parser.o + endif ## Targets diff --git a/lib/c/experimental/labcomm_sig_parser.c b/lib/c/experimental/labcomm_sig_parser.c index 23e3758..3c0222f 100644 --- a/lib/c/experimental/labcomm_sig_parser.c +++ b/lib/c/experimental/labcomm_sig_parser.c @@ -155,7 +155,7 @@ int labcomm_sig_parser_init(labcomm_sig_parser_t *b, size_t buffer_size, #ifdef STATIC_ALLOCATION printf("warning: labcomm_sig_parser_t_init: size params ignored, using defaults from .h file \n"); #else - b->sig_ts=calloc(num_signatures, sizeof(labcomm_signature_t)); + b->sig_ts=calloc(num_signatures, sizeof(struct labcomm_signature)); b->signatures_length=calloc(num_signatures, sizeof(int)); b->signatures_name_length=calloc(num_signatures, sizeof(int)); b->signatures_name=calloc(num_signatures, sizeof(void *)); //HERE BE DRAGONS: add range checks @@ -221,7 +221,7 @@ void getStr(labcomm_sig_parser_t *b, char *dest, size_t size) { b->idx += size; } -labcomm_signature_t *get_sig_t(labcomm_sig_parser_t *p, unsigned int uid) +struct labcomm_signature *get_sig_t(labcomm_sig_parser_t *p, unsigned int uid) { return &(p->sig_ts[uid-LABCOMM_USER]); } @@ -310,13 +310,17 @@ static unsigned char labcomm_varint_sizeof(unsigned int i) return res; } } - -int encoded_size_static(labcomm_signature_t *sig, void *unused) +int encoded_size_static(struct labcomm_signature *sig, void *unused) { +#ifdef LABCOMM_EXPERIMENTAL_CACHED_ENCODED_SIZE if(sig->cached_encoded_size == -1) { error("encoded_size_static called for var_size sample or uninitialized signature"); } return sig->cached_encoded_size; +#else + printf("Warning: encoded_size_static currently broken\n"); + return -1; +#endif } /* This function probably never will be implemented, as it would be @@ -326,7 +330,7 @@ int encoded_size_static(labcomm_signature_t *sig, void *unused) on the receiver side, is to skip unhandled samples. */ -int encoded_size_parse_sig(labcomm_signature_t *sig, void *sample) +int encoded_size_parse_sig(struct labcomm_signature *sig, void *sample) { printf("Warning: encoded_size_parse_sig not implemented\n"); return -1; @@ -355,8 +359,8 @@ static int accept_signature(labcomm_sig_parser_t *d) unsigned int end = d->idx; unsigned int len = end-start; - labcomm_signature_t *newsig = get_sig_t(d, uid); - newsig->type = type; + struct labcomm_signature *newsig = get_sig_t(d, uid); +// newsig->type = type; if(len <= d->max_sig_len) { d->signatures_length[uid-LABCOMM_USER] = len; memcpy(d->signatures[uid-LABCOMM_USER], &d->c[start], len); @@ -376,6 +380,7 @@ static int accept_signature(labcomm_sig_parser_t *d) } VERBOSE_PRINTF("signature for uid %x: %s (start=%x,end=%x, nlen=%d,len=%d)\n", uid, get_signature_name(d, uid), start,end, nlen, len); INFO_PRINTF("SIG: %s\n", newsig->name); +#ifdef LABCOMM_EXPERIMENTAL_CACHED_ENCODED_SIZE if(! d->current_decl_is_varsize) { newsig->cached_encoded_size = enc_size; newsig->encoded_size = encoded_size_static; @@ -385,6 +390,7 @@ static int accept_signature(labcomm_sig_parser_t *d) newsig->encoded_size = encoded_size_parse_sig; INFO_PRINTF(".... is variable size\n"); } +#endif return TRUE; } else { error("sample_decl with uid < LABCOMM_USER"); @@ -606,10 +612,10 @@ static int accept_sample_data(labcomm_sig_parser_t *d){ #ifdef DEBUG dump_signature(d, uid); #endif - labcomm_signature_t *sigt = get_sig_t(d, uid); - int encoded_size = sigt->encoded_size(sigt, NULL); + struct labcomm_signature *sigt = get_sig_t(d, uid); + int encoded_size = sigt->encoded_size(NULL); INFO_PRINTF("encoded_size from sig: %d\n", encoded_size); - labcomm_signature_t *sig = get_sig_t(d, uid); + struct labcomm_signature *sig = get_sig_t(d, uid); skip_packed_sample_data(d, sig); return TRUE; } @@ -801,7 +807,7 @@ int skip_type(unsigned int type, labcomm_sig_parser_t *d, /* parse signature and skip the corresponding bytes in the labcomm_sig_parser_t */ -int skip_packed_sample_data(labcomm_sig_parser_t *d, labcomm_signature_t *sig) { +int skip_packed_sample_data(labcomm_sig_parser_t *d, struct labcomm_signature *sig) { unsigned int pos = 0; //current position in signature unsigned int skipped = 0; //skipped byte counter while(pos < sig->size) { diff --git a/lib/c/experimental/labcomm_sig_parser.h b/lib/c/experimental/labcomm_sig_parser.h index 9bd25c0..6aa85f2 100644 --- a/lib/c/experimental/labcomm_sig_parser.h +++ b/lib/c/experimental/labcomm_sig_parser.h @@ -29,7 +29,7 @@ /* internal type: stack &c. for the parser */ typedef struct { - unsigned char* c; + char* c; size_t size; size_t capacity; unsigned int idx; @@ -44,14 +44,14 @@ typedef struct { size_t max_name_len; size_t max_sig_len; #ifdef STATIC_ALLOCATION - labcomm_signature_t sig_ts[MAX_SIGNATURES]; + struct labcomm_signature sig_ts[MAX_SIGNATURES]; unsigned int signatures_length[MAX_SIGNATURES]; unsigned int signatures_name_length[MAX_SIGNATURES]; unsigned char signatures_name[MAX_SIGNATURES][MAX_NAME_LEN]; unsigned char signatures[MAX_SIGNATURES][MAX_SIG_LEN]; #else - labcomm_signature_t *sig_ts; // [MAX_SIGNATURES] + struct labcomm_signature *sig_ts; // [MAX_SIGNATURES] unsigned int *signatures_length; // [MAX_SIGNATURES] unsigned char **signatures; // [MAX_SIGNATURES][MAX_SIG_LEN]; @@ -70,7 +70,7 @@ int labcomm_sig_parser_read_file(labcomm_sig_parser_t *p, FILE *f); int accept_packet(labcomm_sig_parser_t *p); -labcomm_signature_t *get_sig_t(labcomm_sig_parser_t *p,unsigned int uid); +struct labcomm_signature *get_sig_t(labcomm_sig_parser_t *p,unsigned int uid); unsigned int get_signature_len(labcomm_sig_parser_t *p,unsigned int uid); unsigned char* get_signature_name(labcomm_sig_parser_t *p,unsigned int uid); @@ -78,9 +78,12 @@ unsigned char* get_signature(labcomm_sig_parser_t *p,unsigned int uid); void dump_signature(labcomm_sig_parser_t *p,unsigned int uid); +int more(labcomm_sig_parser_t *b); + + /* parse signature and skip the corresponding bytes in the labcomm_sig_parser */ -int skip_packed_sample_data(labcomm_sig_parser_t *p, labcomm_signature_t *sig); +int skip_packed_sample_data(labcomm_sig_parser_t *p, struct labcomm_signature *sig); #ifdef QUIET #define INFO_PRINTF(format, args...) @@ -110,7 +113,7 @@ int skip_packed_sample_data(labcomm_sig_parser_t *p, labcomm_signature_t *sig); typedef enum{ TYPE_DECL = LABCOMM_TYPEDEF, - SAMPLE_DECL = LABCOMM_SAMPLE, + SAMPLE_DECL = LABCOMM_SAMPLE_DEF, ARRAY_DECL = LABCOMM_ARRAY, STRUCT_DECL = LABCOMM_STRUCT, diff --git a/lib/c/experimental/test_sig_parser.c b/lib/c/experimental/test_sig_parser.c index 7a98173..d6bf5ba 100644 --- a/lib/c/experimental/test_sig_parser.c +++ b/lib/c/experimental/test_sig_parser.c @@ -3,10 +3,11 @@ */ #include <stdio.h> +#include <stdlib.h> #include "labcomm_sig_parser.h" -#undef DEBUG_READ +#define DEBUG_READ #define BUF_SIZE 1024 #define STACK_SIZE 16 -- GitLab