Browse Source

mailinfo: move handle_boundary() lower

This function wants to call find_boundary() and is called only from
one place without any recursing, so it becomes easier to read if it
appears after the called function.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Junio C Hamano 9 years ago
parent
commit
39afcd3819
  1. 114
      builtin/mailinfo.c

114
builtin/mailinfo.c

@ -628,64 +628,6 @@ static void decode_transfer_encoding(struct strbuf *line) @@ -628,64 +628,6 @@ static void decode_transfer_encoding(struct strbuf *line)
free(ret);
}

static void handle_filter(struct strbuf *line);

static int find_boundary(void)
{
while (!strbuf_getline(&line, fin, '\n')) {
if (*content_top && is_multipart_boundary(&line))
return 1;
}
return 0;
}

static int handle_boundary(void)
{
struct strbuf newline = STRBUF_INIT;

strbuf_addch(&newline, '\n');
again:
if (line.len >= (*content_top)->len + 2 &&
!memcmp(line.buf + (*content_top)->len, "--", 2)) {
/* we hit an end boundary */
/* pop the current boundary off the stack */
strbuf_release(*content_top);
free(*content_top);
*content_top = NULL;

/* technically won't happen as is_multipart_boundary()
will fail first. But just in case..
*/
if (--content_top < content) {
fprintf(stderr, "Detected mismatched boundaries, "
"can't recover\n");
exit(1);
}
handle_filter(&newline);
strbuf_release(&newline);

/* skip to the next boundary */
if (!find_boundary())
return 0;
goto again;
}

/* set some defaults */
transfer_encoding = TE_DONTCARE;
strbuf_reset(&charset);

/* slurp in this section's info */
while (read_one_header_line(&line, fin))
check_header(&line, p_hdr_data, 0);

strbuf_release(&newline);
/* replenish line */
if (strbuf_getline(&line, fin, '\n'))
return 0;
strbuf_addch(&line, '\n');
return 1;
}

static inline int patchbreak(const struct strbuf *line)
{
size_t i;
@ -853,6 +795,62 @@ static void handle_filter(struct strbuf *line) @@ -853,6 +795,62 @@ static void handle_filter(struct strbuf *line)
}
}

static int find_boundary(void)
{
while (!strbuf_getline(&line, fin, '\n')) {
if (*content_top && is_multipart_boundary(&line))
return 1;
}
return 0;
}

static int handle_boundary(void)
{
struct strbuf newline = STRBUF_INIT;

strbuf_addch(&newline, '\n');
again:
if (line.len >= (*content_top)->len + 2 &&
!memcmp(line.buf + (*content_top)->len, "--", 2)) {
/* we hit an end boundary */
/* pop the current boundary off the stack */
strbuf_release(*content_top);
free(*content_top);
*content_top = NULL;

/* technically won't happen as is_multipart_boundary()
will fail first. But just in case..
*/
if (--content_top < content) {
fprintf(stderr, "Detected mismatched boundaries, "
"can't recover\n");
exit(1);
}
handle_filter(&newline);
strbuf_release(&newline);

/* skip to the next boundary */
if (!find_boundary())
return 0;
goto again;
}

/* set some defaults */
transfer_encoding = TE_DONTCARE;
strbuf_reset(&charset);

/* slurp in this section's info */
while (read_one_header_line(&line, fin))
check_header(&line, p_hdr_data, 0);

strbuf_release(&newline);
/* replenish line */
if (strbuf_getline(&line, fin, '\n'))
return 0;
strbuf_addch(&line, '\n');
return 1;
}

static void handle_body(void)
{
struct strbuf prev = STRBUF_INIT;

Loading…
Cancel
Save