|
|
@ -331,49 +331,29 @@ copy_msg_bytes( char **out_ptr, const char *in_buf, int *in_idx, int in_len, int |
|
|
|
*in_idx = idx; |
|
|
|
*in_idx = idx; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void |
|
|
|
static int |
|
|
|
msg_fetched( int sts, void *aux ) |
|
|
|
copy_msg_convert( int in_cr, int out_cr, copy_vars_t *vars ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
copy_vars_t *vars = (copy_vars_t *)aux; |
|
|
|
char *in_buf = vars->data.data; |
|
|
|
DECL_SVARS; |
|
|
|
int in_len = vars->data.len; |
|
|
|
char *fmap, *buf; |
|
|
|
int idx = 0, sbreak = 0, ebreak = 0; |
|
|
|
int i, len, extra, scr, tcr, lcrs, hcrs, bcrs, lines; |
|
|
|
int lines = 0, hdr_crs = 0, bdy_crs = 0, extra = 0; |
|
|
|
int start, sbreak = 0, ebreak = 0; |
|
|
|
|
|
|
|
char c; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (sts) { |
|
|
|
|
|
|
|
case DRV_OK: |
|
|
|
|
|
|
|
INIT_SVARS(vars->aux); |
|
|
|
|
|
|
|
if (check_cancel( svars )) { |
|
|
|
|
|
|
|
free( vars->data.data ); |
|
|
|
|
|
|
|
vars->cb( SYNC_CANCELED, 0, vars ); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vars->msg->flags = vars->data.flags; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
scr = (svars->drv[1-t]->flags / DRV_CRLF) & 1; |
|
|
|
|
|
|
|
tcr = (svars->drv[t]->flags / DRV_CRLF) & 1; |
|
|
|
|
|
|
|
if (vars->srec || scr != tcr) { |
|
|
|
|
|
|
|
fmap = vars->data.data; |
|
|
|
|
|
|
|
len = vars->data.len; |
|
|
|
|
|
|
|
extra = lines = hcrs = bcrs = i = 0; |
|
|
|
|
|
|
|
if (vars->srec) { |
|
|
|
if (vars->srec) { |
|
|
|
nloop: |
|
|
|
nloop: ; |
|
|
|
start = i; |
|
|
|
int start = idx; |
|
|
|
lcrs = 0; |
|
|
|
int line_crs = 0; |
|
|
|
while (i < len) { |
|
|
|
while (idx < in_len) { |
|
|
|
c = fmap[i++]; |
|
|
|
char c = in_buf[idx++]; |
|
|
|
if (c == '\r') |
|
|
|
if (c == '\r') { |
|
|
|
lcrs++; |
|
|
|
line_crs++; |
|
|
|
else if (c == '\n') { |
|
|
|
} else if (c == '\n') { |
|
|
|
if (starts_with_upper( fmap + start, len - start, "X-TUID: ", 8 )) { |
|
|
|
if (starts_with_upper( in_buf + start, in_len - start, "X-TUID: ", 8 )) { |
|
|
|
extra = (sbreak = start) - (ebreak = i); |
|
|
|
extra = (sbreak = start) - (ebreak = idx); |
|
|
|
goto oke; |
|
|
|
goto oke; |
|
|
|
} |
|
|
|
} |
|
|
|
lines++; |
|
|
|
lines++; |
|
|
|
hcrs += lcrs; |
|
|
|
hdr_crs += line_crs; |
|
|
|
if (i - lcrs - 1 == start) { |
|
|
|
if (idx - line_crs - 1 == start) { |
|
|
|
sbreak = ebreak = start; |
|
|
|
sbreak = ebreak = start; |
|
|
|
goto oke; |
|
|
|
goto oke; |
|
|
|
} |
|
|
|
} |
|
|
@ -381,45 +361,72 @@ msg_fetched( int sts, void *aux ) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
/* invalid message */ |
|
|
|
/* invalid message */ |
|
|
|
warn( "Warning: message %d from %s has incomplete header.\n", |
|
|
|
free( in_buf ); |
|
|
|
vars->msg->uid, str_ms[1-t] ); |
|
|
|
return 0; |
|
|
|
free( fmap ); |
|
|
|
|
|
|
|
vars->cb( SYNC_NOGOOD, 0, vars ); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
oke: |
|
|
|
oke: |
|
|
|
extra += 8 + TUIDL + 1 + (tcr && (!scr || hcrs)); |
|
|
|
extra += 8 + TUIDL + 1 + (out_cr && (!in_cr || hdr_crs)); |
|
|
|
} |
|
|
|
} |
|
|
|
if (tcr != scr) { |
|
|
|
if (out_cr != in_cr) { |
|
|
|
for (; i < len; i++) { |
|
|
|
for (; idx < in_len; idx++) { |
|
|
|
c = fmap[i]; |
|
|
|
char c = in_buf[idx]; |
|
|
|
if (c == '\r') |
|
|
|
if (c == '\r') |
|
|
|
bcrs++; |
|
|
|
bdy_crs++; |
|
|
|
else if (c == '\n') |
|
|
|
else if (c == '\n') |
|
|
|
lines++; |
|
|
|
lines++; |
|
|
|
} |
|
|
|
} |
|
|
|
extra -= hcrs + bcrs; |
|
|
|
extra -= hdr_crs + bdy_crs; |
|
|
|
if (tcr) |
|
|
|
if (out_cr) |
|
|
|
extra += lines; |
|
|
|
extra += lines; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
vars->data.len = len + extra; |
|
|
|
vars->data.len = in_len + extra; |
|
|
|
buf = vars->data.data = nfmalloc( vars->data.len ); |
|
|
|
char *out_buf = vars->data.data = nfmalloc( vars->data.len ); |
|
|
|
i = 0; |
|
|
|
idx = 0; |
|
|
|
if (vars->srec) { |
|
|
|
if (vars->srec) { |
|
|
|
copy_msg_bytes( &buf, fmap, &i, sbreak, scr, tcr ); |
|
|
|
copy_msg_bytes( &out_buf, in_buf, &idx, sbreak, in_cr, out_cr ); |
|
|
|
|
|
|
|
|
|
|
|
memcpy( buf, "X-TUID: ", 8 ); |
|
|
|
memcpy( out_buf, "X-TUID: ", 8 ); |
|
|
|
buf += 8; |
|
|
|
out_buf += 8; |
|
|
|
memcpy( buf, vars->srec->tuid, TUIDL ); |
|
|
|
memcpy( out_buf, vars->srec->tuid, TUIDL ); |
|
|
|
buf += TUIDL; |
|
|
|
out_buf += TUIDL; |
|
|
|
if (tcr && (!scr || hcrs)) |
|
|
|
if (out_cr && (!in_cr || hdr_crs)) |
|
|
|
*buf++ = '\r'; |
|
|
|
*out_buf++ = '\r'; |
|
|
|
*buf++ = '\n'; |
|
|
|
*out_buf++ = '\n'; |
|
|
|
i = ebreak; |
|
|
|
idx = ebreak; |
|
|
|
} |
|
|
|
} |
|
|
|
copy_msg_bytes( &buf, fmap, &i, len, scr, tcr ); |
|
|
|
copy_msg_bytes( &out_buf, in_buf, &idx, in_len, in_cr, out_cr ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
free( in_buf ); |
|
|
|
|
|
|
|
return 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
free( fmap ); |
|
|
|
static void |
|
|
|
|
|
|
|
msg_fetched( int sts, void *aux ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
copy_vars_t *vars = (copy_vars_t *)aux; |
|
|
|
|
|
|
|
DECL_SVARS; |
|
|
|
|
|
|
|
int scr, tcr; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (sts) { |
|
|
|
|
|
|
|
case DRV_OK: |
|
|
|
|
|
|
|
INIT_SVARS(vars->aux); |
|
|
|
|
|
|
|
if (check_cancel( svars )) { |
|
|
|
|
|
|
|
free( vars->data.data ); |
|
|
|
|
|
|
|
vars->cb( SYNC_CANCELED, 0, vars ); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vars->msg->flags = vars->data.flags; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
scr = (svars->drv[1-t]->flags / DRV_CRLF) & 1; |
|
|
|
|
|
|
|
tcr = (svars->drv[t]->flags / DRV_CRLF) & 1; |
|
|
|
|
|
|
|
if (vars->srec || scr != tcr) { |
|
|
|
|
|
|
|
if (!copy_msg_convert( scr, tcr, vars )) { |
|
|
|
|
|
|
|
warn( "Warning: message %d from %s has incomplete header.\n", |
|
|
|
|
|
|
|
vars->msg->uid, str_ms[1-t] ); |
|
|
|
|
|
|
|
vars->cb( SYNC_NOGOOD, 0, vars ); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
svars->drv[t]->store_msg( svars->ctx[t], &vars->data, !vars->srec, msg_stored, vars ); |
|
|
|
svars->drv[t]->store_msg( svars->ctx[t], &vars->data, !vars->srec, msg_stored, vars ); |
|
|
|