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

Annotation of /innwebd/BBS_fun.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations)
Fri Apr 11 17:14:49 2008 UTC (17 years, 11 months ago) by sysadm
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +2 -6 lines
Content type: text/x-c++src
Update copyright
Add extra log for exception

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

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