示例#1
0
文件: unimo.c 项目: tkpclark/wraith
main()
{
	int n=0;
	int i=0;
	fd_set fds1;
	struct timeval tv;

	sgip_init();
	while(9)
	{
		FD_ZERO(&fds1);
		FD_SET(readfd,&fds1);
		tv.tv_sec = 20;
		tv.tv_usec = 0;
		//proclog("MESSAGE:waiting for belle.....");
		if((n=select(readfd+1,&fds1,NULL,NULL,NULL))>0)
		{
			sgip_read();
		}
		else if(n<0)
		{
			if(errno==EINTR)
				continue;
			proclog( "ALERT:f**k select error\n");
				continue;
		}
		else//return 0
		{
			proclog("MESSAGE:long time no mo!\n");
			exit(0);
		}
	}
}
示例#2
0
static void procquit(void)
{
	//printf("quiting...\n");
	bst_stop_transmit(&DevHandle);
	
	if ( bst_fini(&DevHandle) < 0 ) 
		proclog(logfd,mdname," bst fini failed!\n");
	else
		proclog(logfd,mdname," bst fini successfully!\n");

}
示例#3
0
文件: unimo.c 项目: tkpclark/wraith
static void sgip_resp(int cmd,void *seq,int len)
{
	unsigned char buf[32];
	unsigned char *p;
	memset(buf,0,sizeof(buf));
	p=buf;
	*(long *)p=htonl(len);
	*(long *)(p+4)=htonl(cmd);
	*(long *)(p+8)=htonl(*(int*)seq);
	*(long *)(p+12)=htonl(*(int*)(seq+4));
	*(long *)(p+16)=htonl(*(int*)(seq+8));
	//if(writeall(writefd,buf,len)==-1)
	if(write(writefd,buf,len)==-1)
	{
		proclog("cmd %X write error!",cmd); 
		exit(0);
	}
}
示例#4
0
文件: adnslogres.c 项目: gpg/adns
int main(int argc, char *argv[]) {
  int c, opts, maxpending;
  extern char *optarg;
  FILE *inf;

  if (argv[1] && !strncmp(argv[1],"--",2)) {
    if (!strcmp(argv[1],"--help")) {
      printhelp(stdout);
    } else if (!strcmp(argv[1],"--version")) {
      fputs(VERSION_MESSAGE("adnslogres"),stdout);
    } else {
      usage();
    }
    if (ferror(stdout) || fclose(stdout)) { perror("stdout"); exit(1); }
    exit(0);
  }

  maxpending= DEFMAXPENDING;
  opts= 0;
  while ((c= getopt(argc, argv, "c:C:dxfpPS:")) != -1)
    switch (c) {
    case 'c':
      maxpending= atoi(optarg);
      if (maxpending < 1 || maxpending > MAXMAXPENDING) {
       fprintf(stderr, "%s: unfeasible concurrency %d\n", progname, maxpending);
       exit(1);
      }
      break;
    case 'C':
      config_text= optarg;
      break;
    case 'd':
      opts|= OPT_DEBUG;
      break;
    case 'x':
      opts|= OPT_VHOST;
      break;
    case 'f':
      opts|= OPT_FTP;
      break;
    case 'P':
      opts|= OPT_PRIVACY;
      break;
    case 'S':
      salt = optarg;
      break;
    default:
      usage();
    }

  argc-= optind;
  argv+= optind;

  inf= NULL;
  if (argc == 0)
    inf= stdin;
  else if (argc == 1)
    inf= fopen(*argv, "r");
  else
    usage();

  if (!inf)
    aargh("couldn't open input");

  proclog(inf, stdout, maxpending, opts);

  if (fclose(inf))
    aargh("fclose input");
  if (fclose(stdout))
    aargh("fclose output");

  return 0;
}
示例#5
0
文件: unimo.c 项目: tkpclark/wraith
static sgip_read()
{
	//proclog("reading data...");
	
	int n=0;
	void *seq;
	int len,g;
	int cmd;
	int i;
	unsigned char buffer[PKG_LENGTH];
	//read header
	memset(buffer,0,20);
	//proclog("reading header...");
	if((n=read(readfd,buffer,20))!=20)
	{
		proclog("Read Header Error! return [%d]",n);
		exit(0);
	}
	//proclog_HEX(buffer,20);
	seq=(void*)malloc(12);
	len=ntohl(*((long *)buffer));
	cmd=ntohl(*((unsigned long *)(buffer+4)));
	
	*(int*)seq=ntohl(*((unsigned long *)(buffer+8)));
	*(int*)(seq+4)=ntohl(*((unsigned long *)(buffer+12)));
	*(int*)(seq+8)=ntohl(*((unsigned long *)(buffer+16)));
	
	proclog("header:len:[%d] CMD:[%X] seq:[%d][%d][%d]",len,cmd,*(int*)seq,*(int*)(seq+4),*(int*)(seq+8));


	///read body
	memset(buffer,0,PKG_LENGTH);
	//proclog("reading body...");
	if((n=read(readfd,buffer,len-20))!=(len-20))
	{
		proclog("Read Body Error! return [%d]",n);
		exit(0);
	}


	///////////////print binlog
	//proclog_HEX(buffer,len-20);
	////////////////////
	
	if(cmd==0x4)//deliver
	{
		sgip_resp(0x80000004,seq,29);
		char UserNumber[22]={0};
		char SPNumber[22]={0};
		char MessageContent[256]={0};
		int MessageLength=0;
		char MessageContent_utf8[256]={0};
		memset(MessageContent_utf8,0,sizeof(MessageContent_utf8));
		unsigned char MessageCoding;
		unsigned char pid,udhi;
		char linkid[32];
		
		MessageLength=ntohl(*(unsigned int*)(buffer+45));
		strncpy(UserNumber,buffer,21);
		strncpy(SPNumber,buffer+21,21);

		pid=*(unsigned char *)(buffer+42);
		udhi=*(unsigned char *)(buffer+43);
		MessageCoding=*(unsigned char *)(buffer+44);
		memset(MessageContent,0,sizeof(MessageContent));
		memcpy(MessageContent,buffer+49,MessageLength);
		strcpy(linkid,buffer+49+MessageLength);
		if (MessageCoding==8)
		{
			convt(MessageContent,MessageContent_utf8,"ucs-2be","utf-8");
			//ucs2_to_utf8(MessageContent,MessageContent_utf8);
		}
		else if(MessageCoding==15)
		{
			convt(MessageContent,MessageContent_utf8,"gb2312","utf-8");
		}
		else
		{
			strcpy(MessageContent_utf8,MessageContent);
		}
		proclog("MO:UserNumber[%s]SPNumber[%s]Messagelen[%d]Content[%s]MessageCoding[%d]linkid[%s]pid[%d]udhi[%d]\n",UserNumber,SPNumber,MessageLength,MessageContent_utf8,MessageCoding,linkid,pid,udhi);
		
		char sql[512];
		sprintf(sql,"insert into wraith_mo( in_date, phone_number, message, sp_number, linkid, gwid ) values (NOW(),'%s', '%s', '%s', '%s', '%s');",
				UserNumber,
				MessageContent_utf8,
				SPNumber,
				linkid,
				gwid
				);
		//proclog(sql);
		mysql_exec(&mysql,"set names utf8");
		mysql_exec(&mysql, sql);

		/*
		char cmd[128];
		sprintf(cmd,"./fakemt %s hello",UserNumber);
		proclog("%s\n",cmd);
		//system(cmd);
		*/
	}
	else if(cmd==0x5)//report
	{
		sgip_resp(0x80000005,seq,29);
		*(time_t*)(buffer+252)=time(0);
		char UserNumber[22]={0};
		strncpy(UserNumber,buffer+13,21);
		unsigned long seq;
		seq=ntohl(*((unsigned long *)(buffer+8)));
		int state,report_code;
		//state=*(int *)(buffer+34);
		state=(int)(*(unsigned char *)(buffer+34));
		report_code=(int)(*(unsigned char *)(buffer+35));
		proclog("REPORT: seq[%d]usernumber[%s]state[%d]errorcode:[%d]\n",seq,UserNumber,state,report_code);
//		write_to_heapfile(heapstatdbfd,buffer,sizeof(buffer));

	}
	else if(cmd==0x1)//bind
	{
		sgip_resp(0x80000001,seq,29);
		//proclog("MESSAGE:got BIND command\n");
	}
	else if(cmd==0x2)//unbind
	{
		sgip_resp(0x80000002,seq,20);
		//proclog("MESSAGE:got UNBIND command!\n");
		exit(0);
	}
	else
	{
		proclog( "WARNING:Strange CMD:%x\n",cmd);
	}
	//proclog("returning...");
}
示例#6
0
static void transmitting()
{
	char null_buffer[FRAME_LEN];
	gen_empty_pkg(null_buffer);
	unsigned int *p_rd_offs=(unsigned int *)(p_map_ts+TS_BUFFER_READER_OFFS);
	const unsigned int max_offs=TS_BUFFER_MAX_LEN-TS_BUFFER_CTL_LEN;
	if(*p_rd_offs>=max_offs)
	{
		*p_rd_offs=0;
	}
	unsigned char *p_start=p_map_ts+TS_BUFFER_CTL_LEN;

	sprintf(logbuf,"start from :TS_BUFFER_CTL_LEN+%d\n",*p_rd_offs);
	proclog(logfd,mdname,logbuf);

	
	/*
	double *p_rate=(double*)(p_map_ts+TS_BUFFER_ORI_RATE_OFFS);
	DevConfig.rate_ori=*p_rate;
	*/
	//DevConfig.rate_ori=10000000;
	bst_start_transmitEx(&DevHandle, &DevConfig, 0);
	
	sprintf(logbuf,"send rate:%f (bps)\n",DevConfig.rate_ori);
	proclog(logfd,mdname,logbuf);

	BUFFER_CAPABILITY bc;
	


	int ret;
	int counter;
	int counter1;
	int counter2;
	int data_num=0;
	
	struct itimerval value;
	value.it_value.tv_sec=0;
	value.it_value.tv_usec=100000;
	
	while(1)
	{
		if(gstop)
			exit(0);
		
		//
		/*
		if(*p_rate!=DevConfig.rate_ori)
		{
			
			bst_stop_transmit(&DevHandle);

			if ( bst_fini(&DevHandle) < 0 ) 
				proclog(logfd,mdname," bst fini failed!\n");
			else
				proclog(logfd,mdname," bst fini successfully!\n");



			sprintf(logbuf,"rate_ori changed! %f~%f(bps)\n",DevConfig.rate_ori,*p_rate);
			proclog(logfd,mdname,logbuf);
			DevConfig.rate_ori=*p_rate;

			ret = bst_initial(&DevHandle, 0);
			sprintf(logbuf,"bst_initial ret:%d\n",ret);
			proclog(logfd,mdname,logbuf);
			
			ret=bst_start_transmitEx(&DevHandle, &DevConfig, 3);
			sprintf(logbuf,"bst_start_transmitEx ret:%d\n",ret);
			proclog(logfd,mdname,logbuf);

		}
		*/
		
		setitimer(ITIMER_REAL, &value, NULL);
		counter=0;
		counter1=0;
		counter2=0;
		galarm=0;
		while(1)
		{
			
			//sprintf(logbuf,"counter:%d\n",counter);
			//proclog(logfd,mdname,logbuf);
			if(gstop)
				exit(0);
			if(*(p_start+*p_rd_offs)==0x47)
			{
				//proclog(logfd,mdname,"1\n");
				bst_transmit(&DevHandle, p_start+*p_rd_offs ,FRAME_LEN); 
				//proclog(logfd,mdname,"2\n");
				//memset(p_rd,0,FRAME_LEN);
				*(p_start+*p_rd_offs)=0;
				*p_rd_offs =*p_rd_offs+FRAME_LEN;

				if(*p_rd_offs >= max_offs)
				{
					sprintf(logbuf,"arrive to the max len:%d|%d\n",*p_rd_offs,max_offs);
					proclog(logfd,mdname,logbuf);
					*p_rd_offs=0;
				}
				counter1++;
			}
			else
			{
				//proclog(logfd,mdname,"3\n");
				bst_transmit(&DevHandle,null_buffer,FRAME_LEN);
				//proclog(logfd,mdname,"4\n");
				//sprintf(logbuf,"ts:%X\n",*(p_start+*p_rd_offs));
				//proclog(logfd,mdname,logbuf);
				//proclog(logfd,mdname,"no new data in the buffer\n");
				//nanosleep(&ts,NULL);
				counter2++;
			}
			
			
			counter++;
			if(counter >= (12000000/8/10/188)+1)
			{
				sprintf(logbuf,"task finished!1:%d 2:%d\n",counter1,counter2);
				proclog(logfd,mdname,logbuf);
				break;
			}
			
			bst_query(&DevHandle,BST_QUERY_DRV_DATA_SZ, &bc, sizeof(bc));
			//if(bc.DataBufSz-data_num <= 0)
			{
				sprintf(logbuf,"########data:%d,counter:%d \n",bc.DataBufSz,counter);
				proclog(logfd,mdname,logbuf);
			}
			
			data_num=bc.DataBufSz;
		}
		//proclog(logfd,mdname,"5\n");
		pause();
		//proclog(logfd,mdname,"6\n");
			
	}

}
示例#7
0
main(int argc ,char **argv)
{
	if(argc!=2)
	{
		printf("please tell me config file!\n");
		exit(0);
	}
	if(!is_file_exist(argv[1]))
	{
		printf("file %s doesn't exist!\n",argv[1]);
		exit(0);
	}

	read_config(argv[1]);
	proclog("starting...");

	int n=0;
	int i=0;
	fd_set fds1;
	struct timeval tv;

	readfd=open("/dev/null",0);
	writefd=open("/dev/null",0);
	dup2(0,readfd);
	dup2(1,writefd);
	close(0);
	close(1);

	if(atexit(&procquit))
	{
		printf("quit code can't be load!\n");
		exit(0);
	}

	mysql_create_connect(&mysql, ip, user,pass,db);

	while(9)
	{
		FD_ZERO(&fds1);
		FD_SET(readfd,&fds1);
		tv.tv_sec = 20;
		tv.tv_usec = 0;
		//proclog("MESSAGE:waiting for belle.....");
		if((n=select(readfd+1,&fds1,NULL,NULL,NULL))>0)
		{
			sgip_read();
		}
		else if(n<0)
		{
			if(errno==EINTR)
				continue;
			proclog( "ALERT:f**k select error\n");
				continue;
		}
		else//return 0
		{
			proclog("MESSAGE:long time no mo!\n");
			exit(0);
		}
	}
}
示例#8
0
static CreateOneTable_FTT(unsigned char table_id,SEC_BUFFER_INFO *p_sbi, char *streamID,char *stream_id)
{
	//actual AD or other AD or actual AE or other AE,one of them
	printf("creating table 0x%x\n",table_id);
	
	PIC_INFO pic_info;
	char temp[128];
	unsigned int service_num=0;
	unsigned int num=0;
	int section_number=0;
	int table_section_number=0;
	int max_one_pic_section_number=0;
	int i,j;
	char ret=0;
	char data_service[100][DATA_MAX_FIELD_NUM][DATA_MAX_REC_LEN];
	char data_img[10][DATA_MAX_FIELD_NUM][DATA_MAX_REC_LEN];

	//get all services in this stream
	sprintf(sql,"SELECT id,service_id  from xepg_sdt_extension where transport_stream_id=%s",streamID);
	service_num=mysql_get_data(&mysql, sql,data_service);
	printf("service_num:%d\n",service_num);

	/*
	//get version_number of this table
	unsigned char version_number=0;
	version_number=get_version_number_task(table_id, baseid, streamID);
	*/
	
	//get ...
	char pic_table[32];
	char field_name[32];
	char table_type=0;

	int null_pic_section_flag=0;

	if(table_id==tableid_ad)
	{
		strcpy(pic_table,"xepg_ad");
		strcpy(field_name,"epgad_file_sub_id");
		table_type=1;
	}
	else if(table_id==tableid_ce)
	{
		strcpy(pic_table,"xepg_poster");
		strcpy(field_name,"poster_file_sub_id");
		table_type=2;
	}

	for(i=0;i<service_num;i++)// cirle of sub table 
	{
		printf("########serviceID:%d:%s########\n",i,data_service[i][1]);
		sprintf(logbuf,"ts[%s]tb[0x%x]sv[%s]",stream_id,table_id,data_service[i][1]);

		memset(&pic_info,0,sizeof(PIC_INFO));
		
		//////load pic info
		// there are 4 cases here ,
		// 1:there is a record in the db,and the pic exists; 			 deal:normal
		// 2:there is a record in the db,but the pic doesn't exist 		deal:only section header
		// 3:there is no record in the db  							deal:only section header
		// 4:there is an empty record after 7 seconds 				deal:only section header
		null_pic_section_flag=0;

		if(table_type==1)//only epg-ad do this
		{
			//check if it's empty record after 7 seconds
			sprintf(sql,"select *  from %s where dtbflag!=-1  and service_id=%s and (imgurl=NULL or imgurl is NULL or imgurl='')\
and(( NOW() + interval 7 second  between start_time and end_time )  or (NOW() >= start_time and NOW() < end_time ) )",pic_table,data_service[i][0]);
			num=mysql_get_data(&mysql, sql,data);
			if(num)
			{
				printf("next record is forbidden period, sending null section!\n");
				null_pic_section_flag=1;
				strcat(logbuf,"pic[fbd]");
				goto l;
			}
		}
		
		
		
		sprintf(sql,"select imgurl,antifake,xposition,yposition,width,height,showtime,style from %s where dtbflag!=-1  and service_id=%s and NOW() >= start_time and NOW() <  end_time",pic_table,data_service[i][0]);
		num=mysql_get_data(&mysql, sql,data_img);
		if(num)
		{
		
			//get pic_name 
			strcpy(pic_info.name,"/opt/tomcat/webapps/xepg");
			strcat(pic_info.name,data_img[0][0]);
			//printf("pic:%s\n",pic_info[j].name);

			//get antifake,x,y,width,height,period.stype
			strcpy(pic_info.antifake,data_img[0][1]);
			pic_info.x=atoi(data_img[0][2]);
			pic_info.y=atoi(data_img[0][3]);
			pic_info.width=atoi(data_img[0][4]);
			pic_info.height=atoi(data_img[0][5]);
			pic_info.period=atoi(data_img[0][6]);
			pic_info.style=atoi(data_img[0][7]);
			

		

			//get file_sub_id
			sprintf(sql,"select %s from xepg_pdt_extension where serviceid='%s'",field_name,data_service[i][0]);
			mysql_get_data(&mysql, sql,data);
			pic_info.file_sub_id=atoi(data[0][0]);
			
			//get file stream
			if(get_file_stream(&pic_info,table_type)==-1)
			{
				null_pic_section_flag=1;
				printf("get_file_stream failed !\n");
				strcat(logbuf,"pic[failed]");
				goto l;
			}


			sprintf(temp,"pic[%s]streamlen[%d]size[%d]anti[%s]x[%d]y[%d]width[%d]height[%d]period[%d]style[%d]",pic_info.name,pic_info.stream_len,pic_info.size,pic_info.antifake,pic_info.x,pic_info.y,pic_info.width,pic_info.height,pic_info.period,pic_info.style);
			strcat(logbuf,temp);
		
		}
		else
		{
			null_pic_section_flag=1;
			strcat(logbuf,"pic[empty]");
			goto l;
		}




	l:	
		if(null_pic_section_flag)//there are no rec in poster or ad table
		{
			pic_info.file_sub_id=htons(0);
			pic_info.size=0;
			pic_info.stream_len=0;
			printf("sending empty pic section!\n");
		}
		
		//creating sections of this sub table
		section_number=0;
		while(1)
		{
			p_sbi[table_section_number].pic_id=i;
			p_sbi[table_section_number].sec_id=section_number;
			ret=CreateFTS(table_id, &pic_info,section_number,&p_sbi[table_section_number],version_number);
			section_number++;
			table_section_number++;
			
			if(!ret)
				break;
		}

		/* update last section number of every section of this sub table */
		
		for(j=0;j<section_number;j++)
		{
			*(unsigned char *)(p_sbi[table_section_number-section_number+j].buffer+7)=section_number-1;
			get_CRC(p_sbi[table_section_number-section_number+j].buffer,p_sbi[table_section_number-section_number+j].len-4);
		}
		sprintf(temp,"sec[%d]",section_number);
		strcat(logbuf,temp);
		if(section_number > max_one_pic_section_number)
			max_one_pic_section_number=section_number;
		/*
		//update dtbflag
		sprintf(sql,"update %s set dtbflag=1 where id='%s'",pic_table,data[0][1]);
		mysql_query(&mysql,sql);
		*/
		
	
		////////////
		//strcat(logbuf,"\n");
		proclog(logfd,mdname,logbuf);
	}