X-Git-Url: https://git.exim.org/exim.git/blobdiff_plain/9e09521e621d852ac4828f1865b4ccb01568d9ee..d315eda12f25ca2f72ca56b777a427c9ee7188e1:/src/src/expand.c diff --git a/src/src/expand.c b/src/src/expand.c index f85ee494e..a68849dc3 100644 --- a/src/src/expand.c +++ b/src/src/expand.c @@ -1554,11 +1554,9 @@ for (i = 0; i < 2; i++) int size = 0; header_line *h; - for (h = header_list; size < header_insert_maxlen && h != NULL; h = h->next) - { - if (h->type != htype_old && h->text != NULL) /* NULL => Received: placeholder */ - { - if (name == NULL || (len <= h->slen && strncmpic(name, h->text, len) == 0)) + for (h = header_list; size < header_insert_maxlen && h; h = h->next) + if (h->type != htype_old && h->text) /* NULL => Received: placeholder */ + if (!name || (len <= h->slen && strncmpic(name, h->text, len) == 0)) { int ilen; uschar *t; @@ -1580,7 +1578,7 @@ for (i = 0; i < 2; i++) that contains an address list, except when asked for raw headers. Only need to do this once. */ - if (!want_raw && name != NULL && comma == 0 && + if (!want_raw && name && comma == 0 && Ustrchr("BCFRST", h->type) != NULL) comma = 1; @@ -1613,8 +1611,6 @@ for (i = 0; i < 2; i++) } } } - } - } /* At end of first pass, return NULL if no header found. Then truncate size if necessary, and get the buffer to hold the data, returning the buffer size. @@ -1632,9 +1628,7 @@ for (i = 0; i < 2; i++) /* That's all we do for raw header expansion. */ if (want_raw) - { *ptr = 0; - } /* Otherwise, remove a final newline and a redundant added comma. Then we do RFC 2047 decoding, translating the charset if requested. The rfc2047_decode2() @@ -1838,7 +1832,7 @@ switch (vp->type) case vtype_msgbody: /* Pointer to msgbody string */ case vtype_msgbody_end: /* Ditto, the end of the msg */ ss = (uschar **)(val); - if (*ss == NULL && deliver_datafile >= 0) /* Read body when needed */ + if (!*ss && deliver_datafile >= 0) /* Read body when needed */ { uschar *body; off_t start_offset = SPOOL_DATA_START_OFFSET; @@ -1871,7 +1865,7 @@ switch (vp->type) { if (body[--len] == '\n' || body[len] == 0) body[len] = ' '; } } } - return (*ss == NULL)? US"" : *ss; + return *ss ? *ss : US""; case vtype_todbsdin: /* BSD inbox time of day */ return tod_stamp(tod_bsdin); @@ -3872,7 +3866,11 @@ BOOL resetok = TRUE; expand_level++; DEBUG(D_expand) - debug_printf_indent("/%s: %s\n", skipping ? " scanning" : "considering", string); + debug_printf_indent(UTF8_DOWN_RIGHT "%s: %s\n", + skipping + ? UTF8_HORIZ UTF8_HORIZ UTF8_HORIZ "scanning" + : "considering", + string); expand_string_forcedfail = FALSE; expand_string_message = US""; @@ -4119,8 +4117,13 @@ while (*s != 0) DEBUG(D_expand) { - debug_printf_indent("|__condition: %.*s\n", (int)(next_s - s), s); - debug_printf_indent("|_____result: %s\n", cond ? "true" : "false"); + debug_printf_indent(UTF8_VERT_RIGHT UTF8_HORIZ UTF8_HORIZ + "condition: %.*s\n", + (int)(next_s - s), s); + debug_printf_indent(UTF8_VERT_RIGHT UTF8_HORIZ UTF8_HORIZ + UTF8_HORIZ UTF8_HORIZ UTF8_HORIZ + "result: %s\n", + cond ? "true" : "false"); } s = next_s; @@ -4726,8 +4729,9 @@ while (*s != 0) struct sockaddr_un sockun; /* don't call this "sun" ! */ uschar *arg; uschar *sub_arg[4]; + BOOL do_shutdown = TRUE; - if ((expand_forbid & RDO_READSOCK) != 0) + if (expand_forbid & RDO_READSOCK) { expand_string_message = US"socket insertions are not permitted"; goto EXPAND_FAILED; @@ -4743,17 +4747,27 @@ while (*s != 0) case 3: goto EXPAND_FAILED; } - /* Sort out timeout, if given */ + /* Sort out timeout, if given. The second arg is a list with the first element + being a time value. Any more are options of form "name=value". Currently the + only option recognised is "shutdown". */ - if (sub_arg[2] != NULL) + if (sub_arg[2]) { - timeout = readconf_readtime(sub_arg[2], 0, FALSE); - if (timeout < 0) + const uschar * list = sub_arg[2]; + uschar * item; + int sep = 0; + + item = string_nextinlist(&list, &sep, NULL, 0); + if ((timeout = readconf_readtime(item, 0, FALSE)) < 0) { - expand_string_message = string_sprintf("bad time value %s", - sub_arg[2]); + expand_string_message = string_sprintf("bad time value %s", item); goto EXPAND_FAILED; } + + while ((item = string_nextinlist(&list, &sep, NULL, 0))) + if (Ustrncmp(item, US"shutdown=", 9) == 0) + if (Ustrcmp(item + 9, US"no") == 0) + do_shutdown = FALSE; } else sub_arg[3] = NULL; /* No eol if no timeout */ @@ -4867,9 +4881,9 @@ while (*s != 0) recognise that it is their turn to do some work. Just in case some system doesn't have this function, make it conditional. */ - #ifdef SHUT_WR - shutdown(fd, SHUT_WR); - #endif +#ifdef SHUT_WR + if (do_shutdown) shutdown(fd, SHUT_WR); +#endif if (running_in_test_harness) millisleep(100); @@ -4909,7 +4923,7 @@ while (*s != 0) while (isspace(*s)) s++; } - readsock_done: + READSOCK_DONE: if (*s++ != '}') { expand_string_message = US"missing '}' closing readsocket"; @@ -4921,7 +4935,7 @@ while (*s != 0) socket, or timeout on reading. If another substring follows, expand and use it. Otherwise, those conditions give expand errors. */ - SOCK_FAIL: + SOCK_FAIL: if (*s != '{') goto EXPAND_FAILED; DEBUG(D_any) debug_printf("%s\n", expand_string_message); if (!(arg = expand_string_internal(s+1, TRUE, &s, FALSE, TRUE, &resetok))) @@ -4933,7 +4947,7 @@ while (*s != 0) goto EXPAND_FAILED_CURLY; } while (isspace(*s)) s++; - goto readsock_done; + goto READSOCK_DONE; } /* Handle "run" to execute a program. */ @@ -7490,9 +7504,17 @@ else if (resetok_p) *resetok_p = FALSE; DEBUG(D_expand) { - debug_printf_indent("|__expanding: %.*s\n", (int)(s - string), string); - debug_printf_indent("%s_____result: %s\n", skipping ? "|" : "\\", yield); - if (skipping) debug_printf_indent("\\___skipping: result is not used\n"); + debug_printf_indent(UTF8_VERT_RIGHT UTF8_HORIZ UTF8_HORIZ + "expanding: %.*s\n", + (int)(s - string), string); + debug_printf_indent("%s" + UTF8_HORIZ UTF8_HORIZ UTF8_HORIZ UTF8_HORIZ UTF8_HORIZ + "result: %s\n", + skipping ? UTF8_VERT_RIGHT : UTF8_UP_RIGHT, + yield); + if (skipping) + debug_printf_indent(UTF8_UP_RIGHT UTF8_HORIZ UTF8_HORIZ UTF8_HORIZ + "skipping: result is not used\n"); } expand_level--; return yield; @@ -7516,10 +7538,14 @@ EXPAND_FAILED: if (left != NULL) *left = s; DEBUG(D_expand) { - debug_printf_indent("|failed to expand: %s\n", string); - debug_printf_indent("%s___error message: %s\n", - expand_string_forcedfail ? "|" : "\\", expand_string_message); - if (expand_string_forcedfail) debug_printf_indent("\\failure was forced\n"); + debug_printf_indent(UTF8_VERT_RIGHT "failed to expand: %s\n", + string); + debug_printf_indent("%s" UTF8_HORIZ UTF8_HORIZ UTF8_HORIZ + "error message: %s\n", + expand_string_forcedfail ? UTF8_VERT_RIGHT : UTF8_UP_RIGHT, + expand_string_message); + if (expand_string_forcedfail) + debug_printf_indent(UTF8_UP_RIGHT "failure was forced\n"); } if (resetok_p) *resetok_p = resetok; expand_level--;