调用rpc的代码。(听说很牛),调了就牛了嘛?

jackxiang 2008-3-21 17:49 | |
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <strstream>
#include <fstream>  //ifstream fin("ent_list");
#include "../../entadmin_g/src/enterpriseManager.hpp"
char file_path1[1024]="/tmp/ent_not_exit.log";   //enterprise.domain的数据库select语句成功日志
char file_path2[1024]="/tmp/ent_failed_modify.log";   //enterprise.domain的数据库select语句失败日志
char file_path3[1024]="/tmp/ent_successful.log";  //enterprisemail.domain数据库的update修改成功日志
char file_path4[1024]="/tmp/startent_not_exit.log";  //enterprisemail.domain数据库的update语句修改失败日志
char file_path5[1024]="/tmp/startent_failed_modify.log";  //enterprisemail.domain蕌pdate语句修改失败日志
char file_path6[1024]="/tmp/startent_successful.log.log";  //enterprisemail.domain蕌pdate语句修改失败日志
int opt_type = 0;
char opt_file[1024];
void trim(string& str)
{
str.erase(str.find_last_not_of(' ')+1, string::npos);
str.erase(0, str.find_first_not_of(' '));
}

using namespace std;
int main(int argv,char * argc[])//main函数体
{  
  if(argv!=3)
  {
    cout << "_____________________请在ent_list文件放入企业ID_______________\n";
    cout << "|然后请传入参数? (0,1)                                         |\n";
    cout << "|传入1:ent_dated_restet 0 后跟关闭企业ID的文件      |\n";
    cout << "|传入0:ent_dated_restet 1 后跟打开企业的ID文件             \n";
    cout << "|______________________________________________________________|\n";
    cout << "|_你只要将要关闭或者打开的企业ID放到ent_list由1或者0来控制即可_|\n";
    cout << "| Warn:  连续一行一个企业ID(domain.enterpriseid)       \n";
    cout << "|Example:  scan_enterprise_dated 0 /tmp/open_enterprise.txt|\n";
    cout << "|______________________________________________________________|\n";
    return 0;
        
  }
  time_t t;
  struct tm *x;
  time( &t );
  x = localtime(&t);
  opt_type=atoi(argc[1]); //判断是关闭企业还是恢复企业  
  strcpy(opt_file,argc[2]); //传入的文本文件,读取企业ID  
  enterprise *_enterprise = new enterprise( );
  string errMsg;
  //读取文本
  FILE*   fp;  
    fp   =   fopen(opt_file,"r");  
  if   ( 0==fp )
  {   cout << "What you put the filename is not exist!\n ";
    return 0;
  }  
  fclose(fp);
  ifstream fin(opt_file);
  //读取结束
  ofstream fout1(file_path1,ios_base::app);//enterprise.domain的数据库select语句成功日志
  ofstream fout2(file_path2,ios_base::app);//enterprise.domain的数据库select语句失败日志
  ofstream fout3(file_path3,ios_base::app);//enterprisemail.domain数据库的update修改成功日志
  ofstream fout4(file_path4,ios_base::app); //enterprisemail.domain数据库的update语句修改失败日志
  ofstream fout5(file_path5,ios_base::app); //enterprisemail.domain数据库的update语句修改失败日志
  ofstream fout6(file_path6,ios_base::app); //enterprisemail.domain数据库的update语句修改失败日志
  string str;
  while(getline(fin,str))
  {    
    trim(str);//去掉读出的一行前后空格
    char buffer[1024];
    int str_to_int=atoi(str.c_str());  
    sprintf(buffer,"%d",str_to_int);  
    if(strcmp(str.c_str(),buffer)!=0)
    {  
      cout <<str<<"Have contain special character in one line,please check...\n";
      fout2 <<  x->tm_year+1900 <<"年"<<x->tm_mon+1<<"月"<<x->tm_mday<<"日"<<x->tm_hour<<"点"<<x->tm_min<<"分"<<x->tm_sec<<"秒\t"<<  "Enterpriseid:\t" <<str <<"\tHave contain special character in one line,please check...\n";
      continue;
    }  
    memset(buffer,0,1024);//销毁临时变量
    //判断是否是数字    
    if (!str.length())
    {
      printf("请检查一下你的./ent_list里面是否有空行...\n");
      return 0;
    }
  
    enterprise _enterprise1;
    string enterpriseID;
    enterpriseID=str;
    if ( !_enterprise1.getEnterpriseInfo( atoi( enterpriseID.c_str() ), errMsg ) )
    {
      cout <<errMsg;  
      fout1 << x->tm_year+1900 <<"年"<<x->tm_mon+1<<"月"<<x->tm_mday<<"日"<<x->tm_hour<<"点"<<x->tm_min<<"分"<<x->tm_sec<<"秒\t"<<enterpriseID<<"\t"<< errMsg<<"\n";
      delete _enterprise;
      return 0;
    }
    
    if ( opt_type == 0 )
    {

  
      if ( !_enterprise->stopDomain( atoi( enterpriseID.c_str() ), errMsg ) )
      {
        fout2 << x->tm_year+1900 <<"年"<<x->tm_mon+1<<"月"<<x->tm_mday<<"日"<<x->tm_hour<<"点"<<x->tm_min<<"分"<<x->tm_sec<<"秒\t"<<enterpriseID<<"\t"<< errMsg<<"\n";
        delete _enterprise;
        return 0;
      }
      fout3 << x->tm_year+1900 <<"年"<<x->tm_mon+1<<"月"<<x->tm_mday<<"日"<<x->tm_hour<<"点"<<x->tm_min<<"分"<<x->tm_sec<<"秒\t"<<enterpriseID<<"\t"<<"禁用企业成功"<<"\n";
      delete _enterprise;
      return 0;
    }

    if ( opt_type == 1 )
    {

      if ( !_enterprise->startDomain( atoi( enterpriseID.c_str() ), errMsg ) )
      {
        fout5 << x->tm_year+1900 <<"年"<<x->tm_mon+1<<"月"<<x->tm_mday<<"日"<<x->tm_hour<<"点"<<x->tm_min<<"分"<<x->tm_sec<<"秒\t"<<enterpriseID<<"\t"<< errMsg<<"\n";  
        delete _enterprise;
        return 0;
      }
      fout6<< x->tm_year+1900 <<"年"<<x->tm_mon+1<<"月"<<x->tm_mday<<"日"<<x->tm_hour<<"点"<<x->tm_min<<"分"<<x->tm_sec<<"秒\t"<<enterpriseID<<"\t" << errMsg<<"\n";  
      delete _enterprise;
      return 0;
    }
  

  }
  fin.close();
  fout1.close();
  fout2.close();
  fout3.close();
  fout4.close();
  fout5.close();
  fout6.close();

  }
  



all: scan_enterprise_dated.cgi
scan_enterprise_dated.cgi:
  g++ -o ./scan_enterprise_dated.cgi scan_enterprise_dated.cpp ../../db/rpcserver/common/bin/freebsd/rpcsql_g.a ../../entadmin_g/oldlib/libStrLib.a ../../db/rpcserver/qmail/bin/freebsd/ent_rpcserver_clnt.a ../../db/rpcserver/qmail/ini.o ../../entsystem/email/entaddress/bin/freebsd/ent_domain.o  ../../entsystem/email/entaddress/bin/freebsd/ent_add_tool.o -L../../entadmin/lib/ -I../../entadmin/lib/  
clean:
  rm -Rf scan_enterprise_dated.cgi

作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/958/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!


最后编辑: jackxiang 编辑于2008-3-21 20:44
评论列表
发表评论

昵称

网址

电邮

打开HTML 打开UBB 打开表情 隐藏 记住我 [登入] [注册]