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

Diff of /innwebd/base.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.7 by sysadm, Mon Aug 2 19:47:45 2004 UTC Revision 1.12 by sysadm, Tue Feb 8 05:53:27 2005 UTC
# Line 36  base::~base(void) Line 36  base::~base(void)
36                  delete (this->GetThreadPool());                  delete (this->GetThreadPool());
37  }  }
38    
39  int base::s_exec(const char* in_str, CString& out_str, const char* end_str)  int base::s_exec(const char* in_str, CString& out_str, char end_str[])
40  {  {
41          try{          try{
42                  if (in_str != NULL)                  if (in_str != NULL)
# Line 105  int base::bbs_post(const CString& head, Line 105  int base::bbs_post(const CString& head,
105          bool head_find;          bool head_find;
106          CString head_name,head_value,path,from,subject,newsgroups,organization,date,msg_id; //Head          CString head_name,head_value,path,from,subject,newsgroups,organization,date,msg_id; //Head
107          DateTimeConvert sub_dt;          DateTimeConvert sub_dt;
108          CString ptitle,nickname,dt_str,content,msg_content,sql;          CString ptitle,username,nickname,dt_str,content,msg_content,sql;
109          int length;          int length;
110          long id,aid,cid,rid;          long id,aid,cid;
111    
112          try          try
113          {          {
# Line 197  int base::bbs_post(const CString& head, Line 197  int base::bbs_post(const CString& head,
197                          if (subject.GetLength() > 80)                          if (subject.GetLength() > 80)
198                                  subject = subject.Left(75) + " ……";                                  subject = subject.Left(75) + " ……";
199    
200                          //Get nickname                          //Get username
201                          nickname = "cn.bbs";                          username = "cn.bbs.";
202                          for (int i=0;i<from.GetLength();i++)                          for (int i=0;i<from.GetLength();i++)
203                          {                          {
204                                  if (from[i] == '.' || from[i] == '@')                                  if (from[i] == '.' || from[i] == '@')
# Line 209  int base::bbs_post(const CString& head, Line 209  int base::bbs_post(const CString& head,
209                                                  if (from[j] == ' ' || from[j] == '<')                                                  if (from[j] == ' ' || from[j] == '<')
210                                                          break;                                                          break;
211                                          }                                          }
212                                          nickname = from.Mid(j+1,i-j-1) + ".";                                          username = from.Mid(j+1,i-j-1) + ".";
213                                            break;
214                                    }
215                            }
216                            if (username.GetLength() > 12)
217                                    username = username.Left(12) + ".";
218    
219                            //Get nickname
220                            nickname = "cn.bbs";
221                            for (int i=0;i<from.GetLength();i++)
222                            {
223                                    if (from[i] == '(')
224                                    {
225                                            int j;
226                                            for (j=i+1;j<from.GetLength();j++)
227                                            {
228                                                    if (from[j] == ')')
229                                                            break;
230                                            }
231                                            nickname = from.Mid(i+1,j-i-1);
232                                          break;                                          break;
233                                  }                                  }
234                          }                          }
235                          if (nickname.GetLength() > 20)                          if (nickname.GetLength() > 20)
236                                  nickname = nickname.Left(19) + ".";                                  nickname = nickname.Left(20);
237    
238                          //Reference /bbs/add_sub.php                          //Reference /bbs/add_sub.php
239    
# Line 223  int base::bbs_post(const CString& head, Line 242  int base::bbs_post(const CString& head,
242                          this->Db.ExecuteSQL(sql);                          this->Db.ExecuteSQL(sql);
243                          cid = this->last_insert_id();                          cid = this->last_insert_id();
244    
245                          sql.Format("insert into bbs(SID,TID,UID,nickname,title,CID,sub_dt,"                          sql.Format("insert into bbs(SID,TID,UID,username,nickname,title,CID,sub_dt,"
246                                          "sub_ip,last_reply_dt,icon,length,transship)"                                          "sub_ip,last_reply_dt,icon,length,transship)"
247                                          "values(%d,%ld,%ld,'%s','%s',%ld,adddate('%s',interval '8' hour),"                                          "values(%d,%ld,%ld,'%s','%s','%s',%ld,adddate('%s',interval '8' hour),"
248                                          "'%s',adddate('%s',interval '8' hour),1,%d,1)",                                          "'%s',adddate('%s',interval '8' hour),1,%d,1)",
249                                          sid,id,this->innd_uid,addslashes(nickname),addslashes(subject),                                          sid,id,this->innd_uid,addslashes(username),addslashes(nickname),addslashes(subject),
250                                          cid,dt_str,this->hostaddr,dt_str,length);                                          cid,dt_str,this->hostaddr,dt_str,length);
251                          this->Db.ExecuteSQL(sql);                          this->Db.ExecuteSQL(sql);
252                          aid = this->last_insert_id();                          aid = this->last_insert_id();
# Line 236  int base::bbs_post(const CString& head, Line 255  int base::bbs_post(const CString& head,
255                          this->Db.ExecuteSQL(sql); //7671                          this->Db.ExecuteSQL(sql); //7671
256    
257                          //Add logfile                          //Add logfile
258                          sql.Format("insert delayed into bbs_article_op(AID,UID,type,op_dt,op_ip,complete)"                          sql.Format("insert delayed into bbs_article_op(AID,UID,type,op_dt,op_ip)"
259                                          " values(%ld,%ld,'I',now(),'%s',1)",                                          " values(%ld,%ld,'I',now(),'%s')",
260                                          aid,this->innd_uid,this->hostaddr);                                          aid,this->innd_uid,this->hostaddr);
261                          this->Db.ExecuteSQL(sql);                          this->Db.ExecuteSQL(sql);
262                    
# Line 246  int base::bbs_post(const CString& head, Line 265  int base::bbs_post(const CString& head,
265                          {                          {
266                                  sql.Format("update bbs set cached=0, reply_count=reply_count+1,"                                  sql.Format("update bbs set cached=0, reply_count=reply_count+1,"
267                                                  "last_reply_dt=adddate('%s',interval '8' hour),last_reply_UID=%ld,"                                                  "last_reply_dt=adddate('%s',interval '8' hour),last_reply_UID=%ld,"
268                                                  "last_reply_nickname='%s' where aid=%ld",                                                  "last_reply_username='%s',last_reply_nickname='%s' where aid=%ld",
269                                                  dt_str,this->innd_uid,nickname,id);                                                  dt_str,this->innd_uid,username,nickname,id);
270                                  this->Db.ExecuteSQL(sql);                                  this->Db.ExecuteSQL(sql);
271                          }                          }
272    
273                          //Notify the author of the artile which is replyed.                          //Notify the author of the artile which is replyed.
274                          if (id != 0)                          if (id != 0)
275                          {                          {
276                                  sql.Format("select user_pubinfo.UID,user_pubinfo.nickname,"                                  sql.Format("select distinct UID from bbs where (AID=%ld or TID=%ld)"
277                                          "user_pubinfo.email from bbs left join user_pubinfo on"                                          " and visible and reply_note and UID<>%ld",id,id,this->innd_uid);
                                         " bbs.UID=user_pubinfo.UID where AID=%ld and reply_note",  
                                         id);  
278                                  RS.Open(CRecordset::snapshot,sql,CRecordset::forwardOnly | CRecordset::readOnly);                                  RS.Open(CRecordset::snapshot,sql,CRecordset::forwardOnly | CRecordset::readOnly);
279                    
280                                  if (!RS.IsEOF())                                  while (!RS.IsEOF())
281                                  {                                  {
282                                          RS.GetFieldValue("UID",dbVar),SQL_C_SLONG;                                          //Send notication message
283                                          if (dbVar.m_lVal != innd_uid)  
284                                          {                      msg_content.Format("[hide]SYS_R_Reply_Article[/hide]"
285                                                  sql.Format("update user_pubinfo set exp=exp+1 where UID=%ld",                                                  "有人回复了您所发表的文章,快来[article %ld#%ld"
286                                                          dbVar.m_lVal);                                                  "]看看[/article]《%s》吧!\n",id,aid,addslashes(subject));
287                                                  this->Db.ExecuteSQL(sql);  
288                                            RS.GetFieldValue("UID",dbVar,SQL_C_SLONG);
289                                                  RS.GetFieldValue("email",dbVar,SQL_C_CHAR);  
290                                                  sql.Format("insert into bbs_recommend(UID,TID,type,dt,email,ip)"                                          sql.Format("insert into bbs_msg(fromUID,toUID,content,send_dt,send_ip)"
291                                                          " values(%ld,%ld,'D',now(),'%s','%s')",                                                  " values(%ld,%ld,'%s',now(),'%s')",
292                                                          this->innd_uid,aid,dbVar.m_pstring,this->hostaddr);                                          this->innd_uid,dbVar.m_lVal,addslashes(msg_content),this->hostaddr);
293                                                  this->Db.ExecuteSQL(sql);                                          this->Db.ExecuteSQL(sql);
294                                                  rid = this->last_insert_id();                                  }
   
                                                 //Send notication message  
   
                           msg_content.Format("[hide]SYS_R_Reply_Article[/hide]"  
                                                         "有人回复了您所发表的文章,快来[url recommend_view.php?id=%ld"  
                                                         "]看看[/url]《%s》吧!\n",rid,addslashes(subject));  
   
                                                 RS.GetFieldValue("UID",dbVar,SQL_C_SLONG);  
                                                 sql.Format("insert into bbs_msg(fromUID,toUID,ntent,send_dt,send_ip)"  
                                                                 " values(%ld,%ld,'%s',now(),'%s')",  
                                                                 this->innd_uid,dbVar.m_lVal,addslashes(msg_content),this->hostaddr);  
                                                 this->Db.ExecuteSQL(sql);  
                                         }  
                                 }  
295                                  RS.Close();                                  RS.Close();
296                          }                          }
297    
# Line 379  int base::bbs_delete(long id) Line 382  int base::bbs_delete(long id)
382                          this->Db.ExecuteSQL(sql);                          this->Db.ExecuteSQL(sql);
383    
384                          //Add logfile                          //Add logfile
385                          sql.Format("insert delayed into bbs_article_op(AID,UID,type,op_dt,"                          sql.Format("insert delayed into bbs_article_op(AID,UID,type,op_dt,op_ip)"
386                                  "op_ip,complete) values(%ld,%ld,'C',now(),'%s',1)",                                  " values(%ld,%ld,'C',now(),'%s')",
387                                  id,innd_uid,this->hostaddr);                                  id,innd_uid,this->hostaddr);
388                          this->Db.ExecuteSQL(sql);                          this->Db.ExecuteSQL(sql);
389    
# Line 430  int base::s_send(const char* in_str, boo Line 433  int base::s_send(const char* in_str, boo
433          return 0;          return 0;
434  }  }
435    
436  int base::s_receive(CString& out_str, const char* end_str)  int base::s_receive(CString& out_str, char end_str[])
437  {  {
438          char buf_str[2048];          char buf_str[2048];
439          int buf_read,total_read;          int buf_read,total_read;
# Line 449  int base::s_receive(CString& out_str, co Line 452  int base::s_receive(CString& out_str, co
452                          out_str += buf_str;                          out_str += buf_str;
453                          if (out_str.Right((int)strlen(end_str)) == end_str)                          if (out_str.Right((int)strlen(end_str)) == end_str)
454                                  break;                                  break;
455                            //different line-end symbol in different OS
456                            if (strcmp(end_str,"\r") == 0)
457                            {
458                                    if (out_str.Right(2) == "\r\n")
459                                            break;
460                            }
461                  }                  }
462          }          }
463          catch(CException* e)          catch(CException* e)
# Line 468  int base::begin(void) Line 477  int base::begin(void)
477          unsigned int time_wait = 0;          unsigned int time_wait = 0;
478    
479          if (!this->IsShutdown())          if (!this->IsShutdown())
480                  return 1;                  return 0;
481    
482          if (hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)base::Thread,(LPVOID)this,0,&ulThreadId))          if (hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)base::Thread,(LPVOID)this,0,&ulThreadId))
483          {          {
# Line 485  int base::begin(void) Line 494  int base::begin(void)
494          {          {
495          Sleep(100);          Sleep(100);
496                  time_wait += 100;                  time_wait += 100;
497                  if (time_wait > 10000) //Wait 10 seconds                  if (time_wait > 30000) //Wait 30 seconds
498                  {                  {
499                          syslog << logfile::log_head << "Module timeout in begin()" << endl;                          syslog << logfile::log_head << "Module timeout in begin()" << endl;
500                          this->end();                          this->end();
# Line 507  DWORD base::Thread(LPVOID pParam) Line 516  DWORD base::Thread(LPVOID pParam)
516    
517          p->ulMainThreadId = GetCurrentThreadId();          p->ulMainThreadId = GetCurrentThreadId();
518    
519          if (p->GetParentThread()->GetThreadPool()->AddThread(GetCurrentThreadId(), CLOCKS_PER_SEC * 30) != 0)          if (p->GetParentThread()->GetThreadPool()->AddThread(GetCurrentThreadId(), CLOCKS_PER_SEC * 60) != 0)
520          {          {
521                  syslog << logfile::log_head << "Register thread ... Failed" << endl;                  syslog << logfile::log_head << "Register thread ... Failed" << endl;
522          }          }


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

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