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

Annotation of /innwebd/BBS_fun.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (hide annotations) (vendor branch)
Fri Jun 25 07:01:51 2004 UTC (21 years, 8 months ago) by sysadm
Branch: GNU
CVS Tags: V101
Changes since 1.1: +0 -0 lines
Content type: text/x-c++src
no message

1 sysadm 1.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 == "bwf")
89     {
90     tag_result="****";
91     }
92     }
93     else
94     {
95     tag_result=source_str.Mid(p_start,p_end-p_start+1);
96     if (tag_str == "lml")
97     {
98     lml=true;
99     tag_result="";
100     }
101     }
102     if (p_start-p_current>0)
103     result_str = result_str + source_str.Mid(p_current,p_start-p_current) + tag_result;
104     else
105     result_str += tag_result;
106     p_current=p_end+1;
107     }
108     else
109     {
110     if (l_source > p_current)
111     {
112     result_str += source_str.Mid(p_current);
113     }
114     p_current=l_source;
115     }
116     }
117    
118     return result_str;
119     }
120    
121     CString BBS_fun::ip_mask(const CString& ip)
122     {
123     int dot_pos;
124    
125     dot_pos=ip.Find('.');
126     if (dot_pos == -1)
127     return CString();
128    
129     dot_pos=ip.Find('.',dot_pos+1);
130     if (dot_pos == -1)
131     return CString();
132    
133     return (ip.Left(dot_pos+1) + "*.*");
134     }
135    
136     CString BBS_fun::FB2TXT(CString source_str)
137     {
138     CString result_str = "";
139     int i,j,len;
140    
141     len = CString::StringLength(source_str);
142     result_str = "";
143    
144     for (i=0;i<len;i++)
145     {
146     if (source_str[i]=='\033')
147     {
148     for (j=i+1;j<len;j++)
149     {
150     if (source_str[j]=='m')
151     {
152     j++;
153     break;
154     }
155     }
156     i=j-1;
157     }
158     else
159     {
160     result_str.AppendChar(source_str[i]);
161     }
162     }
163    
164     return result_str;
165     }
166    
167     CString BBS_fun::GB_decode(const CString& source_str)
168     {
169     CString search_str,result_str;
170     int pos,pos_f,len,len_b_str,len_decode;
171     char p_buf_s[65536],p_buf_d[65536];
172     bool found;
173    
174     search_str = source_str;
175     search_str.MakeUpper();
176     result_str = "";
177     pos = 0;
178     len = CString::StringLength(source_str);
179     len_b_str = CString::StringLength("=?gb2312?Q?");
180    
181     while(pos<len)
182     {
183     found = false;
184    
185     //QPDecode
186     if ((pos_f = search_str.Find("=?GB2312?Q?",pos))>=0)
187     {
188     found = true;
189     result_str += source_str.Mid(pos,pos_f-pos);
190     pos = pos_f + len_b_str;
191     if ((pos_f = source_str.Find("?=",pos))>=0)
192     {
193     strcpy(p_buf_s,source_str.Mid(pos,pos_f-pos));
194     pos = pos_f + 2;
195     }
196     else
197     {
198     strcpy(p_buf_s,source_str.Mid(pos));
199     pos = len;
200     }
201     len_decode = 65536;
202     if (QPDecode((BYTE *)p_buf_s,(int)strlen(p_buf_s),p_buf_d,&len_decode))
203     {
204     p_buf_d[len_decode]='\0';
205     result_str += p_buf_d;
206     }
207     else
208     {
209     result_str += p_buf_s;
210     }
211     }
212    
213     //Base64Decode
214     if ((pos_f = search_str.Find("=?GB2312?B?",pos))>=0)
215     {
216     found = true;
217     result_str += source_str.Mid(pos,pos_f-pos);
218     pos = pos_f + len_b_str;
219     if ((pos_f = source_str.Find("=?=",pos))>=0)
220     {
221     strcpy(p_buf_s,source_str.Mid(pos,pos_f-pos));
222     pos = pos_f + 3;
223     }
224     else
225     {
226     strcpy(p_buf_s,source_str.Mid(pos));
227     pos = len;
228     }
229     len_decode = 65536;
230     if (Base64Decode(p_buf_s,(int)strlen(p_buf_s),(BYTE *)p_buf_d,&len_decode))
231     {
232     p_buf_d[len_decode]='\0';
233     result_str += p_buf_d;
234     }
235     else
236     {
237     result_str += p_buf_s;
238     }
239     }
240    
241     if (!found)
242     {
243     result_str += source_str.Mid(pos);
244     pos = len;
245     }
246     }
247    
248     return result_str;
249     }

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