Commit | Line | Data |
---|---|---|
620c6c11 | 1 | #ifndef lint |
2af814a5 | 2 | static char sccsid[] = "@(#)imsg.c 5.3 (Berkeley) %G%"; |
620c6c11 SL |
3 | #endif |
4 | ||
5 | #include "uucp.h" | |
2af814a5 | 6 | #include <ctype.h> |
620c6c11 SL |
7 | |
8 | char Msync[2] = "\020"; | |
46b15d8a RC |
9 | |
10 | /* to talk to both eunice and x.25 without also screwing up tcp/ip | |
11 | * we must adaptively choose what character to end the msg with | |
12 | * | |
13 | * The idea is that initially we send ....\000\n | |
14 | * Then, after they have sent us a message, we use the first character | |
15 | * they send. | |
16 | */ | |
17 | ||
18 | int seenend = 0; | |
19 | char Mend = '\0'; | |
20 | ||
21 | /* | |
22 | * this is the initial read message routine - | |
620c6c11 SL |
23 | * used before a protocol is agreed upon. |
24 | * | |
25 | * return codes: | |
2af814a5 JB |
26 | * FAIL - no more messages |
27 | * SUCCESS - message returned | |
620c6c11 SL |
28 | */ |
29 | ||
2af814a5 JB |
30 | imsg(amsg, fn) |
31 | char *amsg; | |
620c6c11 SL |
32 | register int fn; |
33 | { | |
2af814a5 JB |
34 | register char *msg = amsg; |
35 | int foundsync = FAIL; | |
36 | char c; | |
46b15d8a | 37 | |
2af814a5 JB |
38 | DEBUG(5, "imsg looking for SYNC<", CNULL); |
39 | for (;;) { | |
40 | if (read(fn, &c, 1) != 1) | |
41 | return FAIL; | |
42 | c &= 0177; | |
43 | if (c == '\n' || c == '\r') | |
44 | DEBUG(5, "%c", c); | |
45 | else | |
46 | DEBUG(5, (isprint(c) || isspace(c)) ? "%c" : "\\%o", | |
47 | c & 0377); | |
48 | if (c == Msync[0]) { | |
49 | DEBUG(5, ">\nimsg input<", CNULL); | |
46b15d8a | 50 | msg = amsg; |
2af814a5 JB |
51 | foundsync = SUCCESS; |
52 | continue; | |
53 | } else if (foundsync != SUCCESS) | |
54 | continue; | |
55 | if (c == '\n' || c == '\0') { | |
46b15d8a | 56 | if (!seenend) { |
2af814a5 | 57 | Mend = c; |
46b15d8a | 58 | seenend++; |
2af814a5 | 59 | DEBUG(9, "\nUsing \\%o as End of message char\n", Mend); |
46b15d8a | 60 | } |
620c6c11 | 61 | break; |
46b15d8a | 62 | } |
2af814a5 | 63 | *msg++ = c; |
46b15d8a | 64 | fflush(stderr); |
620c6c11 SL |
65 | } |
66 | *msg = '\0'; | |
2af814a5 JB |
67 | DEBUG(5, ">got %d characters\n", strlen(amsg)); |
68 | return foundsync; | |
620c6c11 SL |
69 | } |
70 | ||
71 | ||
46b15d8a RC |
72 | /* |
73 | * this is the initial write message routine - | |
620c6c11 SL |
74 | * used before a protocol is agreed upon. |
75 | * | |
76 | * return code: always 0 | |
77 | */ | |
78 | ||
79 | omsg(type, msg, fn) | |
80 | register char *msg; | |
81 | char type; | |
82 | int fn; | |
83 | { | |
46b15d8a | 84 | char buf[MAXFULLNAME]; |
620c6c11 SL |
85 | register char *c; |
86 | ||
87 | c = buf; | |
46b15d8a | 88 | *c = '\0'; /* avoid pdp 11/23,40 auto-incr stack trap bug */ |
620c6c11 SL |
89 | *c++ = Msync[0]; |
90 | *c++ = type; | |
91 | while (*msg) | |
92 | *c++ = *msg++; | |
93 | *c++ = '\0'; | |
46b15d8a RC |
94 | DEBUG(5, "omsg <%s>\n", buf); |
95 | if (seenend) | |
96 | c[-1] = Mend; | |
97 | else | |
98 | *c++ = '\n'; | |
99 | write(fn, buf, (int)(c - buf)); | |
100 | return 0; | |
620c6c11 | 101 | } |