long long get_hdr_longlong(struct HEADERP *h, char *name) { struct HEADERVAL val; long long llval; if (find_hdrval(h, name, &val)) { printf("ERROR: Can't find '%s' in the WAPP header!\n", name); exit(0); } llval = *((long long *) val.value); return llval; }
int get_hdr_int(struct HEADERP *h, char *name) { struct HEADERVAL val; int ival; if (find_hdrval(h, name, &val)) { printf("ERROR: Can't find '%s' in the WAPP header!\n", name); exit(0); } ival = *((int *) val.value); return ival; }
double get_hdr_double(struct HEADERP *h, char *name) { struct HEADERVAL val; double dval; if (find_hdrval(h, name, &val)) { printf("ERROR: Can't find '%s' in the WAPP header!\n", name); exit(0); } dval = *((double *) val.value); return dval; }
char *get_hdr_string(struct HEADERP *h, char *name, int *slen) { struct HEADERVAL val; char *cptr; if (find_hdrval(h, name, &val)) { printf("ERROR: Can't find '%s' in the WAPP header!\n", name); //exit(0); return cptr; } cptr = (char *) val.value; // Is the following + 1 really correct? I think it causes it // to always include the null terminator... SMR *slen = strlen(cptr) + 1; // printf("'%s' = '%s' (%d chars)\n", name, cptr, *slen); return cptr; }
int *get_hdr_int_arr(struct HEADERP *h, char *name, int *len) { struct HEADERVAL val; int ii, *iptr, *iarr; if (find_hdrval(h, name, &val)) { printf("ERROR: Can't find '%s' in the WAPP header!\n", name); exit(0); } iptr = (int *) val.value; *len = val.key->alen; /* Note that this needs to be freed! */ iarr = gen_ivect(*len); for (ii = 0; ii < *len; ii++, iptr++) { iarr[ii] = *iptr; } return iarr; }
double *get_hdr_double_arr(struct HEADERP *h, char *name, int *len) { struct HEADERVAL val; int ii; double *dptr, *darr; if (find_hdrval(h, name, &val)) { printf("ERROR: Can't find '%s' in the WAPP header!\n", name); exit(0); } dptr = (double *) val.value; *len = val.key->alen; /* Note that this needs to be freed! */ darr = gen_dvect(*len); for (ii = 0; ii < *len; ii++, dptr++) { darr[ii] = *dptr; } return darr; }
int set_hdrval(struct HEADERP *h, char *name, void *data, int ix) { struct HEADERVAL val; void *value; if( find_hdrval( h, name, &val ) ) return(-1); if( val.key->alen == 1 ) ix = 0; if( ix >= val.key->alen ) return(-1); value = (char *)val.value + val.key->len*ix; bcopy( data, value, val.key->len ); return(0); }