]> code.citadel.org Git - citadel.git/blob - citadel/proxy.c
* ipc_c_tcp.c: Reversed any changes that have been made to this file,
[citadel.git] / citadel / proxy.c
1 /*
2  * Session layer proxy for Citadel
3  * (c) 1998 by Art Cancro, All Rights Reserved, released under GNU GPL v2
4  */
5
6 /*
7  * NOTE: this isn't finished, so don't use it!!
8  *
9  */
10
11 #include <stdlib.h>
12 #include <unistd.h>
13 #include <stdio.h>
14 #include <errno.h>
15 #include "citadel.h"
16
17
18 extern int serv_sock;
19
20 void logoff(int code) {
21         exit(code);
22         }
23
24
25 void do_mainloop() {
26         char cmd[256];
27         char resp[256];
28         char buf[4096];
29         int bytes;
30
31         while(1) {
32                 fflush(stdout);
33                 if (fgets(cmd, 256, stdin) == NULL) {
34                         serv_puts("QUIT");
35                         exit(1);
36                         }
37                 cmd[strlen(cmd)-1] = 0;
38
39                 /* QUIT commands are handled specially */
40                 if (!strncasecmp(cmd, "QUIT", 4)) {
41                         serv_puts("QUIT");
42                         printf("%d Proxy says: Bye!\n", OK);
43                         fflush(stdout);
44                         exit(0);
45                         }
46
47                 /* Other commands, just pass through. */
48                 else {
49                         
50                         serv_puts(cmd);
51                         serv_gets(resp);
52                         printf("%s\n", resp);
53                         fflush(stdout);
54
55                         /* Simple command-response... */
56                         if ( (resp[0]=='2')||(resp[0]=='3')||(resp[0]=='5') ) {
57                                 }
58
59                         /* Textual input... */
60                         else if (resp[0] == '4') {
61                                 do {
62                                         if (fgets(buf, 256, stdin) == NULL) {
63                                                 exit(errno);
64                                                 }
65                                         buf[strlen(buf)-1] = 0;
66                                         serv_puts(buf);
67                                         } while (strcmp(buf, "000"));
68                                 }
69
70                         /* Textual output... */
71                         else if (resp[0] == '1') {
72                                 do {
73                                         serv_gets(buf);
74                                         printf("%s\n", buf);
75                                         } while (strcmp(buf, "000"));
76                                 }
77
78                         /* Binary output... */
79                         else if (resp[0] == '6') {
80                                 bytes = atol(&resp[4]);
81                                 serv_read(buf, bytes);
82                                 fwrite(buf, bytes, 1, stdout);
83                                 fflush(stdout);
84                                 }
85
86                         /* Binary input... */
87                         else if (resp[0] == '7') {
88                                 bytes = atol(&resp[4]);
89                                 fread(buf, bytes, 1, stdin);
90                                 serv_write(buf, bytes);
91                                 }
92
93                         /* chat... */
94                         else if (resp[0] == '8') {
95                                 sleep(2);
96                                 serv_puts("/quit");
97                                 do {
98                                         fgets(buf, 256, stdin);
99                                         buf[strlen(buf)-1] = 0;
100                                         serv_puts(buf);
101                                         } while (strcmp(buf, "000"));
102                                 }
103
104
105                         }
106                 }
107         }
108
109
110
111 void main(int argc, char *argv[]) {
112         char buf[256];
113
114         
115         attach_to_server(argc, argv);
116
117         serv_gets(buf);
118         strcat(buf, " (VIA PROXY)");
119         printf("%s\n", buf);
120         fflush(stdout);
121         if (buf[0] != '2') exit(0);
122
123         do_mainloop();
124         }