183 #define STR(x) vstring_str(x)
184 #define LEN(x) VSTRING_LEN(x)
188 static int attr_scan64_string(
VSTREAM *fp,
VSTRING *plain_buf,
const char *context)
190 static VSTRING *base64_buf = 0;
194 int limit = var_line_limit * 4;
205 msg_warn(
"%s on %s while reading %s",
212 if (
LEN(base64_buf) > limit) {
213 msg_warn(
"string length > %d characters from %s while reading %s",
221 msg_warn(
"malformed base64 data from %s: %.100s",
226 msg_info(
"%s: %s", context, *
STR(plain_buf) ?
STR(plain_buf) :
"(end)");
232 static int attr_scan64_number(
VSTREAM *fp,
unsigned *ptr,
VSTRING *str_buf,
238 if ((ch = attr_scan64_string(fp, str_buf, context)) < 0)
240 if (sscanf(
STR(str_buf),
"%u%c", ptr, &junk) != 1 || junk != 0) {
241 msg_warn(
"malformed numerical data from %s while reading %s: %.100s",
250 static int attr_scan64_long_number(
VSTREAM *fp,
unsigned long *ptr,
257 if ((ch = attr_scan64_string(fp, str_buf, context)) < 0)
259 if (sscanf(
STR(str_buf),
"%lu%c", ptr, &junk) != 1 || junk != 0) {
260 msg_warn(
"malformed numerical data from %s while reading %s: %.100s",
271 const char *myname =
"attr_scan64";
274 int wanted_type = -1;
276 unsigned int *number;
277 unsigned long *long_number;
289 msg_panic(
"%s: bad flags: 0x%x", myname, flags);
309 for (conversions = 0; ; conversions++) {
322 wanted_type = va_arg(ap,
int);
325 return (conversions);
326 wanted_name =
"(list terminator)";
328 wanted_name =
"(any attribute name or list terminator)";
329 hash_table = va_arg(ap,
HTABLE *);
331 wanted_name = va_arg(ap,
char *);
346 msg_info(
"%s: wanted attribute: %s",
348 if ((ch = attr_scan64_string(fp, name_buf,
351 if (ch ==
'\n' &&
LEN(name_buf) == 0) {
354 return (conversions);
356 msg_warn(
"missing attribute %s in input from %s",
358 return (conversions);
367 wanted_name =
"(any attribute name or '}')";
379 && strcmp(wanted_name,
STR(name_buf)) == 0))
382 msg_warn(
"unexpected attribute %s from %s (expecting: %s)",
384 return (conversions);
402 switch (wanted_type) {
405 msg_warn(
"missing value for number attribute %s from %s",
409 number = va_arg(ap,
unsigned int *);
410 if ((ch = attr_scan64_number(fp, number, str_buf,
411 "input attribute value")) < 0)
414 msg_warn(
"multiple values for attribute %s from %s",
421 msg_warn(
"missing value for number attribute %s from %s",
425 long_number = va_arg(ap,
unsigned long *);
426 if ((ch = attr_scan64_long_number(fp, long_number, str_buf,
427 "input attribute value")) < 0)
430 msg_warn(
"multiple values for attribute %s from %s",
437 msg_warn(
"missing value for string attribute %s from %s",
441 string = va_arg(ap,
VSTRING *);
442 if ((ch = attr_scan64_string(fp,
string,
443 "input attribute value")) < 0)
446 msg_warn(
"multiple values for attribute %s from %s",
453 msg_warn(
"missing value for data attribute %s from %s",
457 string = va_arg(ap,
VSTRING *);
458 if ((ch = attr_scan64_string(fp,
string,
459 "input attribute value")) < 0)
462 msg_warn(
"multiple values for attribute %s from %s",
469 scan_arg = va_arg(ap,
void *);
476 msg_warn(
"missing value for string attribute %s from %s",
480 if ((ch = attr_scan64_string(fp, str_buf,
481 "input attribute value")) < 0)
484 msg_warn(
"multiple values for attribute %s from %s",
490 msg_warn(
"duplicate attribute %s in input from %s",
492 return (conversions);
495 msg_warn(
"attribute count exceeds limit %d in input from %s",
497 return (conversions);
507 msg_panic(
"%s: unknown type code: %d", myname, wanted_type);
542 msg_info(
"%s: non-terminator '%c' (lookahead)",
559 int main(
int unused_argc,
char **used_argv)
587 for (ht = ht_info_list; *ht; ht++)
588 vstream_printf(
"(hash) %s %s\n", ht[0]->key, (
char *) ht[0]->value);
589 myfree((
void *) ht_info_list);
606 for (ht = ht_info_list; *ht; ht++)
607 vstream_printf(
"(hash) %s %s\n", ht[0]->key, (
char *) ht[0]->value);
608 myfree((
void *) ht_info_list);
void htable_free(HTABLE *table, void(*free_fn)(void *))
HTABLE_INFO * htable_locate(HTABLE *table, const char *key)
char * mystrdup(const char *str)
NORETURN msg_panic(const char *fmt,...)
#define ATTR_FLAG_MISSING
int main(int argc, char **argv)
int attr_scan_more64(VSTREAM *fp)
#define RECV_ATTR_INT(name, val)
#define RECV_ATTR_HASH(val)
#define VSTRING_TERMINATE(vp)
HTABLE * htable_create(ssize_t size)
#define VSTRING_ADDCH(vp, ch)
int attr_scan64(VSTREAM *fp, int flags,...)
HTABLE_INFO ** htable_list(HTABLE *table)
#define vstream_ungetc(vp, ch)
#define vstream_ftimeout(vp)
#define RECV_ATTR_LONG(name, val)
VSTREAM * vstream_printf(const char *fmt,...)
#define VSTRING_RESET(vp)
void msg_warn(const char *fmt,...)
#define RECV_ATTR_DATA(name, val)
VSTRING * vstring_alloc(ssize_t len)
NORETURN msg_fatal(const char *fmt,...)
VSTRING * base64_decode(VSTRING *, const char *, ssize_t)
int vstream_fflush(VSTREAM *stream)
VSTRING * vstring_free(VSTRING *vp)
void msg_vstream_init(const char *name, VSTREAM *vp)
int(* ATTR_SCAN_SLAVE_FN)(ATTR_SCAN_MASTER_FN, VSTREAM *, int, void *)
int attr_vscan64(VSTREAM *fp, int flags, va_list ap)
#define RECV_ATTR_STR(name, val)
HTABLE_INFO * htable_enter(HTABLE *table, const char *key, void *value)
void msg_info(const char *fmt,...)