/[LeafOK_CVS]/lbbs/src/netio.c
ViewVC logotype

Contents of /lbbs/src/netio.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (show annotations)
Sat May 3 13:41:38 2025 UTC (10 months, 2 weeks ago) by sysadm
Branch: MAIN
CVS Tags: HEAD
Changes since 1.7: +0 -0 lines
Content type: text/x-csrc
Error occurred while calculating annotation data.
FILE REMOVED
Remove legacy code

1 /***************************************************************************
2 netio.c - description
3 -------------------
4 begin : Mon Oct 18 2004
5 copyright : (C) 2004 by Leaflet
6 email : leaflet@leafok.com
7 ***************************************************************************/
8
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18 #include "common.h"
19 #include "io.h"
20 #include <string.h>
21 #include <unistd.h>
22 #include <sys/socket.h>
23
24 char s_getc(int socket)
25 {
26 char c;
27 if (recv(socket, &c, 1, 0) > 0)
28 return c;
29 else
30 return '\0';
31 }
32
33 int s_putc(int socket, char c)
34 {
35 int ret;
36
37 ret = send(socket, &c, 1, 0);
38
39 return ret;
40 }
41
42 int s_receive(int socket, char *buffer, int buffer_length, char end_str[])
43 {
44 char buf_str[2048];
45 int buf_read, total_read;
46 int buf_len = 2047;
47
48 if (buf_len + 1 > buffer_length)
49 buf_len = buffer_length - 1;
50
51 total_read = 0;
52 strcpy(buffer, "");
53 while ((buf_read = recv(socket, buf_str, buf_len, 0)) > 0)
54 {
55 buf_str[buf_read] = '\0';
56 total_read += buf_read;
57 strcat(buffer, buf_str);
58
59 buf_len = buffer_length - total_read - 1;
60 if (buf_len + 1 > buffer_length)
61 buf_len = buffer_length - 1;
62
63 if (strcmp((buffer + total_read - strlen(end_str)), end_str) == 0)
64 break;
65 // different line-end symbol in different OS
66 if (strcmp(end_str, "\r") == 0)
67 {
68 if (strcmp((buffer + total_read - 2), "\r\n") == 0)
69 break;
70 }
71 }
72
73 return total_read;
74 }
75
76 int s_send(int socket, const char *in_str)
77 {
78 int ret;
79
80 if (in_str != NULL && strlen(in_str) > 0)
81 {
82 ret = send(socket, in_str, strlen(in_str), 0);
83 }
84
85 return ret;
86 }
87
88 // from Maple-hightman
89 // added by flyriver, 2001.3.3
90 int telnetopt(int fd, char *buf, int max)
91 {
92 unsigned char c, d, e;
93 int pp = 0;
94 unsigned char tmp[30];
95
96 while (pp < max)
97 {
98 c = buf[pp++];
99 if (c == 255)
100 {
101 d = buf[pp++];
102 e = buf[pp++];
103 iflush();
104 if ((d == 253) && (e == 3 || e == 24))
105 {
106 tmp[0] = 255;
107 tmp[1] = 251;
108 tmp[2] = e;
109 write(fd, tmp, 3);
110 continue;
111 }
112 if ((d == 251 || d == 252) && (e == 1 || e == 3 || e == 24))
113 {
114 tmp[0] = 255;
115 tmp[1] = 253;
116 tmp[2] = e;
117 write(fd, tmp, 3);
118 continue;
119 }
120 if (d == 251 || d == 252)
121 {
122 tmp[0] = 255;
123 tmp[1] = 254;
124 tmp[2] = e;
125 write(fd, tmp, 3);
126 continue;
127 }
128 if (d == 253 || d == 254)
129 {
130 tmp[0] = 255;
131 tmp[1] = 252;
132 tmp[2] = e;
133 write(fd, tmp, 3);
134 continue;
135 }
136 if (d == 250)
137 {
138 while (e != 240 && pp < max)
139 e = buf[pp++];
140 tmp[0] = 255;
141 tmp[1] = 250;
142 tmp[2] = 24;
143 tmp[3] = 0;
144 tmp[4] = 65;
145 tmp[5] = 78;
146 tmp[6] = 83;
147 tmp[7] = 73;
148 tmp[8] = 255;
149 tmp[9] = 240;
150 write(fd, tmp, 10);
151 }
152 }
153 else
154 outc(c);
155 }
156 iflush();
157 return 0;
158 }

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1