-#define PARSE_CHECK(expr, error, ...) \
- do { \
- if (!(expr)) { \
- syslog(LOG_ERR, error, ##__VA_ARGS__); \
- return -1; \
- } \
- } while (0)
-
- p_clear(query, 1);
- while (*p != '\n') {
- char *k, *v;
- int klen, vlen, vtk;
-
- while (isblank(*p))
- p++;
- p = strchr(k = p, '=');
- PARSE_CHECK(p, "could not find '=' in line");
- for (klen = p - k; klen && isblank(k[klen]); klen--);
- p += 1; /* skip = */
-
- while (isblank(*p))
- p++;
- p = strchr(v = p, '\n');
- PARSE_CHECK(p, "could not find final \\n in line");
- for (vlen = p - v; vlen && isblank(v[vlen]); vlen--);
- p += 1; /* skip \n */
-
- vtk = policy_tokenize(v, vlen);
- switch (policy_tokenize(k, klen)) {
-#define CASE(up, low) case PTK_##up: query->low = v; v[vlen] = '\0'; break;
- CASE(HELO_NAME, helo_name);
- CASE(QUEUE_ID, queue_id);
- CASE(SENDER, sender);
- CASE(RECIPIENT, recipient);
- CASE(RECIPIENT_COUNT, recipient_count);
- CASE(CLIENT_ADDRESS, client_address);
- CASE(CLIENT_NAME, client_name);
- CASE(REVERSE_CLIENT_NAME, reverse_client_name);
- CASE(INSTANCE, instance);
- CASE(SASL_METHOD, sasl_method);
- CASE(SASL_USERNAME, sasl_username);
- CASE(SASL_SENDER, sasl_sender);
- CASE(SIZE, size);
- CASE(CCERT_SUBJECT, ccert_subject);
- CASE(CCERT_ISSUER, ccert_issuer);
- CASE(CCERT_FINGERPRINT, ccert_fingerprint);
- CASE(ENCRYPTION_PROTOCOL, encryption_protocol);
- CASE(ENCRYPTION_CIPHER, encryption_cipher);
- CASE(ENCRYPTION_KEYSIZE, encryption_keysize);
- CASE(ETRN_DOMAIN, etrn_domain);
- CASE(STRESS, stress);
-#undef CASE
-
- case PTK_REQUEST:
- PARSE_CHECK(vtk == PTK_SMTPD_ACCESS_POLICY,
- "unexpected `request' value: %.*s", vlen, v);
- break;
-
- case PTK_PROTOCOL_NAME:
- PARSE_CHECK(vtk == PTK_SMTP || vtk == PTK_ESMTP,
- "unexpected `protocol_name' value: %.*s", vlen, v);
- query->esmtp = vtk == PTK_ESMTP;
- break;
-
- case PTK_PROTOCOL_STATE:
- switch (vtk) {
-#define CASE(name) case PTK_##name: query->state = SMTP_##name; break;
- CASE(CONNECT);
- CASE(EHLO);
- CASE(HELO);
- CASE(MAIL);
- CASE(RCPT);
- CASE(DATA);
- CASE(END_OF_MESSAGE);
- CASE(VRFY);
- CASE(ETRN);
- default:
- PARSE_CHECK(false, "unexpected `protocol_state` value: %.*s",
- vlen, v);
-#undef CASE
- }
- break;
-
- default:
- syslog(LOG_WARNING, "unexpected key, skipped: %.*s", klen, k);
- continue;
- }