28 |
static int connect_directly_to(char *, unsigned int); |
static int connect_directly_to(char *, unsigned int); |
29 |
static int mread(int, void *, char *); |
static int mread(int, void *, char *); |
30 |
|
|
31 |
|
static struct _debug_cache { |
32 |
|
int method; |
33 |
|
int output; |
34 |
|
int newline; |
35 |
|
size_t count; |
36 |
|
} debug_cache = { -1, -1, 0, 0 }; |
37 |
|
|
38 |
static void |
static void |
39 |
_debug_printer(int method, int output, unsigned long nleft, char *ptr) |
_debug_printer(int method, int output, unsigned long nleft, char *ptr) |
40 |
{ |
{ |
41 |
int len; |
int i; |
42 |
char *mode = "?"; |
char *mode = "?"; |
43 |
|
|
|
if (strcmp(ptr, CRLF) == 0) |
|
|
return; |
|
|
|
|
44 |
switch (method) { |
switch (method) { |
45 |
case CLIENT: |
case CLIENT: |
46 |
mode = _("SERVER"); |
mode = _("SERVER"); |
48 |
case SERVER: |
case SERVER: |
49 |
mode = _("CLIENT"); |
mode = _("CLIENT"); |
50 |
} |
} |
51 |
|
|
52 |
fprintf(stderr, "(%ld)%s %s %s", nleft, mode, |
if (debug_cache.newline |
53 |
output ? ">>>" : "<<<", ptr); |
|| method != debug_cache.method || output != debug_cache.output) { |
54 |
len = strlen (ptr); |
if (!debug_cache.newline && debug_cache.count) |
55 |
if (len > 0 && ptr[len-1] != '\n') |
fprintf(stderr, "(%lu)\n", |
56 |
fprintf(stderr, "\n"); |
(unsigned long)debug_cache.count); |
57 |
|
debug_cache.method = method; |
58 |
|
debug_cache.output = output; |
59 |
|
debug_cache.newline = 0; |
60 |
|
debug_cache.count = 0; |
61 |
|
fprintf(stderr, "%s %s", mode, output ? ">>>" : "<<<"); |
62 |
|
} |
63 |
|
|
64 |
|
for (i = 0; i < nleft; i++, ptr++) { |
65 |
|
debug_cache.count++; |
66 |
|
debug_cache.newline = 0; |
67 |
|
if (*ptr == '\r') |
68 |
|
continue; |
69 |
|
if (*ptr == '\n') { |
70 |
|
fprintf(stderr, "(%ld)\n", |
71 |
|
(unsigned long)debug_cache.count); |
72 |
|
debug_cache.count = 0; |
73 |
|
if (i != nleft-1) { |
74 |
|
fprintf(stderr, "%s %s", |
75 |
|
mode, output ? ">>>" : "<<<"); |
76 |
|
debug_cache.newline = 0; |
77 |
|
} else |
78 |
|
debug_cache.newline = 1; |
79 |
|
} else |
80 |
|
fputc(*ptr, stderr); |
81 |
|
} |
82 |
} |
} |
83 |
|
|
84 |
#define DPRINTF(method, output, nleft, ptr) do {\ |
#define DPRINTF(method, output, nleft, ptr) do {\ |
346 |
int |
int |
347 |
recvline(int method, void *sd, void *vptr, int maxlen) |
recvline(int method, void *sd, void *vptr, int maxlen) |
348 |
{ |
{ |
349 |
int n, rc; |
int n, rc, addc = 0; |
350 |
char c, *ptr; |
char c, *ptr; |
351 |
|
|
352 |
ptr = vptr; |
ptr = vptr; |
353 |
for (n = 1; n < maxlen; n++) { |
for (n = 1; n < maxlen; n++) { |
354 |
if ((rc = mread(method, sd, &c)) == 1) { |
if ((rc = mread(method, sd, &c)) == 1) { |
355 |
if (c == '\n' && n > 1 && ptr[-1] != '\r') |
if (c == '\n' && n > 1 && ptr[-1] != '\r') { |
356 |
|
addc++; |
357 |
*ptr++ = '\r'; |
*ptr++ = '\r'; |
358 |
|
} |
359 |
*ptr++ = c; |
*ptr++ = c; |
360 |
if (c == '\n') |
if (c == '\n') |
361 |
break; |
break; |
368 |
return -1; |
return -1; |
369 |
} |
} |
370 |
*ptr = 0; |
*ptr = 0; |
371 |
DPRINTF(method, 0, n, (char *)vptr); |
DPRINTF(method, 0, n + addc, (char *)vptr); |
372 |
return n; |
return n; |
373 |
} |
} |
374 |
|
|