/[LeafOK_CVS]/innwebd/BBS_fun.cpp
ViewVC logotype

Contents of /innwebd/BBS_fun.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Wed Jun 30 12:50:18 2004 UTC (21 years, 8 months ago) by sysadm
Branch: MAIN
Changes since 1.1: +26 -13 lines
Content type: text/x-c++src
Add level for ip_mask()

1 /*******************************************************/
2 /* */
3 /* LeafOK Innd */
4 /* Copyright (C) LeafOK.com, 2003-2004 */
5 /* */
6 /* Programmed by Leaf */
7 /* E-mail:leaf@leafok.com QQ:6049044 */
8 /* */
9 /* http://bbs.leafok.com */
10 /* http://bbs.leafok.net */
11 /* http://bbs.fenglin.info */
12 /* */
13 /*******************************************************/
14
15 #include "StdAfx.h"
16 #include ".\bbs_fun.h"
17 #include "atlenc.h"
18
19 BBS_fun::BBS_fun(void)
20 {
21 }
22
23 BBS_fun::~BBS_fun(void)
24 {
25 }
26
27 CString BBS_fun::LML(const CString& source_str)
28 {
29 bool lml;
30 CString result_str,tag_str,tag_arg,tag_result;
31 int pre,p_current,l_source,p_start,p_end,p_space,p_tag_end;
32
33 lml=true;
34 result_str="";
35 pre=0;
36 p_current=0;
37 l_source=(int)strlen(source_str);
38
39 while (p_current < l_source)
40 {
41 p_start=source_str.Find('[',p_current);
42 if (p_start != -1)
43 {
44 p_space=source_str.Find(' ',p_start+1);
45 p_end=source_str.Find(']',p_start+1);
46 if (p_end == -1)
47 p_end=l_source-1;
48 if ((p_space != -1) && (p_space < p_end))
49 {
50 p_tag_end=p_space;
51 if (p_end-p_tag_end>0)
52 {
53 tag_arg=source_str.Mid(p_tag_end+1,p_end-p_tag_end-1);
54 tag_arg.Trim();
55 }
56 else
57 tag_arg="";
58 }
59 else
60 {
61 tag_arg="";
62 p_tag_end=p_end;
63 }
64 if (p_tag_end-p_start>0)
65 {
66 tag_str=source_str.Mid(p_start+1,p_tag_end-p_start-1);
67 tag_str.Trim();
68 tag_str.MakeLower();
69 }
70 else
71 tag_str="";
72 if (lml == true)
73 {
74 //Code for switch == true was omitted
75 tag_result="";
76 if (tag_str == "nolml")
77 {
78 lml=false;
79 }
80 if (tag_str == "left")
81 {
82 tag_result="[";
83 }
84 if (tag_str == "right")
85 {
86 tag_result="]";
87 }
88 if (tag_str == "image")
89 {
90 tag_result=tag_arg;
91 }
92 if (tag_str == "bwf")
93 {
94 tag_result="****";
95 }
96 }
97 else
98 {
99 tag_result=source_str.Mid(p_start,p_end-p_start+1);
100 if (tag_str == "lml")
101 {
102 lml=true;
103 tag_result="";
104 }
105 }
106 if (p_start-p_current>0)
107 result_str = result_str + source_str.Mid(p_current,p_start-p_current);
108 result_str += tag_result;
109 p_current=p_end+1;
110 }
111 else
112 {
113 if (l_source > p_current)
114 {
115 result_str += source_str.Mid(p_current);
116 }
117 p_current=l_source;
118 }
119 }
120
121 return result_str;
122 }
123
124 CString BBS_fun::ip_mask(const CString& ip, int level)
125 {
126 int dot_pos;
127
128 switch(level)
129 {
130 case 0:
131 return ip;
132 case 1:
133 dot_pos=ip.Find('.');
134 if (dot_pos == -1)
135 return CString();
136 return (ip.Left(dot_pos+1) + "*");
137 case 2:
138 dot_pos=ip.Find('.');
139 if (dot_pos == -1)
140 return CString();
141 dot_pos=ip.Find('.',dot_pos+1);
142 if (dot_pos == -1)
143 return CString();
144 return (ip.Left(dot_pos+1) + "*.*");
145 }
146 return ip;
147 }
148
149 CString BBS_fun::FB2TXT(CString source_str)
150 {
151 CString result_str = "";
152 int i,j,len;
153
154 len = CString::StringLength(source_str);
155 result_str = "";
156
157 for (i=0;i<len;i++)
158 {
159 if (source_str[i]=='\033')
160 {
161 for (j=i+1;j<len;j++)
162 {
163 if (source_str[j]=='m')
164 {
165 j++;
166 break;
167 }
168 }
169 i=j-1;
170 }
171 else
172 {
173 result_str.AppendChar(source_str[i]);
174 }
175 }
176
177 return result_str;
178 }
179
180 CString BBS_fun::GB_decode(const CString& source_str)
181 {
182 CString search_str,result_str;
183 int pos,pos_f,len,len_b_str,len_decode;
184 char p_buf_s[65536],p_buf_d[65536];
185 bool found;
186
187 search_str = source_str;
188 search_str.MakeUpper();
189 result_str = "";
190 pos = 0;
191 len = CString::StringLength(source_str);
192 len_b_str = CString::StringLength("=?gb2312?Q?");
193
194 while(pos<len)
195 {
196 found = false;
197
198 //QPDecode
199 if ((pos_f = search_str.Find("=?GB2312?Q?",pos))>=0)
200 {
201 found = true;
202 result_str += source_str.Mid(pos,pos_f-pos);
203 pos = pos_f + len_b_str;
204 if ((pos_f = source_str.Find("?=",pos))>=0)
205 {
206 strcpy(p_buf_s,source_str.Mid(pos,pos_f-pos));
207 pos = pos_f + 2;
208 }
209 else
210 {
211 strcpy(p_buf_s,source_str.Mid(pos));
212 pos = len;
213 }
214 len_decode = 65536;
215 if (QPDecode((BYTE *)p_buf_s,(int)strlen(p_buf_s),p_buf_d,&len_decode))
216 {
217 p_buf_d[len_decode]='\0';
218 result_str += p_buf_d;
219 }
220 else
221 {
222 result_str += p_buf_s;
223 }
224 }
225
226 //Base64Decode
227 if ((pos_f = search_str.Find("=?GB2312?B?",pos))>=0)
228 {
229 found = true;
230 result_str += source_str.Mid(pos,pos_f-pos);
231 pos = pos_f + len_b_str;
232 if ((pos_f = source_str.Find("=?=",pos))>=0)
233 {
234 strcpy(p_buf_s,source_str.Mid(pos,pos_f-pos));
235 pos = pos_f + 3;
236 }
237 else
238 {
239 strcpy(p_buf_s,source_str.Mid(pos));
240 pos = len;
241 }
242 len_decode = 65536;
243 if (Base64Decode(p_buf_s,(int)strlen(p_buf_s),(BYTE *)p_buf_d,&len_decode))
244 {
245 p_buf_d[len_decode]='\0';
246 result_str += p_buf_d;
247 }
248 else
249 {
250 result_str += p_buf_s;
251 }
252 }
253
254 if (!found)
255 {
256 result_str += source_str.Mid(pos);
257 pos = len;
258 }
259 }
260
261 return result_str;
262 }

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