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

Annotation of /lbbs/src/netio.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (hide 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
FILE REMOVED
Remove legacy code

1 sysadm 1.1 /***************************************************************************
2 sysadm 1.6 netio.c - description
3     -------------------
4     begin : Mon Oct 18 2004
5     copyright : (C) 2004 by Leaflet
6     email : leaflet@leafok.com
7 sysadm 1.1 ***************************************************************************/
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 sysadm 1.7 #include "io.h"
20 sysadm 1.3 #include <string.h>
21 sysadm 1.7 #include <unistd.h>
22 sysadm 1.3 #include <sys/socket.h>
23 sysadm 1.1
24 sysadm 1.6 char s_getc(int socket)
25 sysadm 1.1 {
26 sysadm 1.6 char c;
27     if (recv(socket, &c, 1, 0) > 0)
28     return c;
29     else
30     return '\0';
31 sysadm 1.1 }
32    
33 sysadm 1.6 int s_putc(int socket, char c)
34 sysadm 1.2 {
35 sysadm 1.6 int ret;
36 sysadm 1.4
37 sysadm 1.6 ret = send(socket, &c, 1, 0);
38 sysadm 1.4
39 sysadm 1.6 return ret;
40 sysadm 1.2 }
41    
42 sysadm 1.6 int s_receive(int socket, char *buffer, int buffer_length, char end_str[])
43 sysadm 1.1 {
44 sysadm 1.6 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 sysadm 1.4 {
55 sysadm 1.6 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 sysadm 1.4 }
72 sysadm 1.1
73 sysadm 1.6 return total_read;
74 sysadm 1.1 }
75    
76 sysadm 1.6 int s_send(int socket, const char *in_str)
77 sysadm 1.1 {
78 sysadm 1.6 int ret;
79 sysadm 1.2
80 sysadm 1.6 if (in_str != NULL && strlen(in_str) > 0)
81     {
82     ret = send(socket, in_str, strlen(in_str), 0);
83     }
84 sysadm 1.4
85 sysadm 1.6 return ret;
86 sysadm 1.1 }
87 sysadm 1.5
88     // from Maple-hightman
89     // added by flyriver, 2001.3.3
90 sysadm 1.6 int telnetopt(int fd, char *buf, int max)
91 sysadm 1.5 {
92 sysadm 1.6 unsigned char c, d, e;
93     int pp = 0;
94     unsigned char tmp[30];
95    
96     while (pp < max)
97 sysadm 1.5 {
98 sysadm 1.6 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 sysadm 1.5 }
156 sysadm 1.6 iflush();
157     return 0;
158 sysadm 1.5 }

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