Exemple #1
0
/* -------------------------------------------------------------------------- *
 * Behandelt Netzwerk-Ereignisse                                              *
 * -------------------------------------------------------------------------- */
void client_event(int type, char *msg)
{
  switch(type)
  {
    /* Es stehen Daten bereit */
    case NET_READ:
    {
      reply_parse(msg);
      break;
    }
    
    /* Es trat ein Fehler auf */
    case NET_ERROR:
    {
      client_log(STATUS, "Verbindung getrennt: %s", msg);
    
      if(client_status == CLIENT_CHAT)
      {
        sgSetWidgetCaption(ui_chat_connect, "Verbinden");
        sgDisableWidget(ui_chat_create);
      }

      break;
    }
  }
}
Exemple #2
0
static int cache_header_preload(struct cache_file *cache)
{
	if(!cache) 
		return;

	int size_need = cache->header_size;
	struct reply_t rep;
	char header_buf[MAX_HEADER];
	int res;
	int fd;

	fd = open(cache->file->buf, O_RDONLY);
	if(-1 == fd) {
		debug("cache_header_preload {%s %s}\n", cache->file->buf, strerror(errno));
		return -1;
	}

	res = read(fd, header_buf, size_need);
	if(-1 == res) {
		debug("cache_header_preload {%s %s}\n", cache->file->buf, strerror(errno));
		close(fd);
		return -1;
	}
	else if(res != size_need) {
		log_debug(__FILE__, __LINE__, "cache_header_preload {%s size not gain fully}\n", cache->file->buf);
		close(fd);
		return -1;
	}

	if(0 ==  reply_parse(&rep, header_buf, res)) {
		cache->reply.headers = header_ref(rep.headers);
		cache->reply.statu = rep.statu;
		cache->reply.version = rep.version;
	}
	else {
		close(fd);
		warning("cache_header_preload failed! load %s.\n", cache->file->buf);
		return -1;
	}
	
	close(fd);
	debug("cache_header_preload success! load %s.\n", cache->file->buf);
	return 0;
}
Exemple #3
0
int exec_cmd(int *o_ordercode, int *etm)
{
	char s[32];
	int retn;
	char msisdn[16],stream[16],ocode[8];
	int ordercode;
	char *src,*dest,*para;
	int beg,len;
	char *ptr, tmp[50];
    struct timeval tt1,tt2;

	cmdackptr=(struct cmd_data_ack *)tcpbuf.data;

printf("get_length(cmdackptr->retn,4)====%d\n",get_length(cmdackptr->retn,4));
	switch(get_length(cmdackptr->retn,4))
	{
	case 3001:
		if(++waitnum>30)
		{
			fprintf(logfp,"Now no datas[%ld][%d]\n",time(NULL),waitnum);
			waitnum=0;
			/*cusnd(enter,1);
			RcvFrmN(); */
            /*连接空闲, 发送回车来保持连接*/
            retn = sndcmd(sndid, "\r\n< ", "\r\n", 2,
                    "\r\n< ", replystr, sizeof(replystr));
		}

		fflush(logfp);
		sleep(5);

		cmdreqptr=(struct cmd_data_req *)tcpbuf.data;
		memcpy(cmdreqptr->retn,"0000",4);
		cmdreqptr->type=ONLY_GET;

		return 0;
	case 0001:
		fprintf(logfp,"GET_DATAS:\n");
		waitnum=0;
		cmdackptr=(struct cmd_data_ack *)tcpbuf.data;
		cmdreqptr=(struct cmd_data_req *)tcpbuf.data;

		memcpy(msisdn,cmdackptr->phone_no,MSISDNLEN);
		memcpy(stream,cmdackptr->stream_id,16);

		ordercode=get_length(cmdackptr->ordercode,4);
		*o_ordercode = ordercode;

		fprintf(logfp,"--retn========%04d~\n",get_length(cmdackptr->retn,4));
		fprintf(logfp,"--order=%s|%04d|%s|%s|%s|%s|%s|%ld\n",
            cmdackptr->stream_id, ordercode, cmdackptr->phone_no,
            cmdackptr->imsi_no, cmdackptr->ss_info1, cmdackptr->ss_info2, cmdackptr->ss_info3,
            time(NULL)
            );

		/*** ORDER SND TO HLR ***/
		orderptr=orderhead.next;
		while(orderptr)
		{
			if(orderptr->ordercode==ordercode)
				break;
			else
				orderptr=orderptr->next;
		}

		if(orderptr)
		{
			src=orderptr->orderinfo;
			dest=orderinfo;

			for(;*src;)
			{
				switch(*src)
				{
				case '$':
					src++;
					switch(*src)
					{
					case '1':
						para=cmdackptr->phone_no;
						break;
					case '2':
						para=cmdackptr->imsi_no;
						break;
					case '3':
						para=cmdackptr->ss_info1;
						break;
					case '4':
						para=cmdackptr->ss_info2;
						break;
					default:
						para=cmdackptr->ss_info3;
						break;
					}

					src++;
					beg=get_length(src,2);
					src+=2;
					len=get_length(src,2);
					if(len==0)
						len=strlen(para+beg);
printf("beg==%d\n",beg);
printf("len==%d\n",len);
printf("para=%s~\n",para+beg);

					memcpy(dest,para+beg,len);
					src+=2;
					dest+=len;
					
					break;
				default:
					*dest=*src;
					src++;
					dest++;

					break;
				}
			}
			*dest='\r'; dest++;
			/*  *dest='\n'; dest++; */
			*dest=0x0;

            if( (dest = strstr(orderinfo, ":KI=")) != NULL && strstr(orderinfo, "ZMAC:IMSI=") != NULL)
            {
                /*对于加载KI的指令, nokia需要明文的, 所以先解密
                ZMAC:IMSI=$20000:KI=$30014$40018,A3V=1,A8V=1:;
                */
                char tmp[33];
                des_11(dest+4, tmp);
                memcpy(dest+4, tmp, 32);
            }
            if( (dest = strstr(orderinfo, ",OPC=")) != NULL && strstr(orderinfo, "ZMAC:IMSI=") != NULL)
            {
                /*对于加载OPC的指令, nokia需要明文的, 所以先解密
                ZMAC:IMSI=$20000:KI=$30014$40018,UV=99,OPC=$50032;
                */
                char tmp[33];
                des_11(dest+5, tmp);
                memcpy(dest+5, tmp, 32);
            }

gettimeofday(&tt1, NULL);
            retn = sndcmd(sndid, "\r\n< \08 ", orderinfo, strlen(orderinfo),
                    "_>\r\n< \08 ", replystr, sizeof(replystr));
gettimeofday(&tt2, NULL);
*etm = time_diff(tt1, tt2);
            if(retn <= 0){
                fprintf(logfp, "sndcmd failed, return:%d\n", retn);
                return -1;
            }


			retn=reply_parse();
			fprintf(logfp,"RETN:%04d\n",retn);

			if(retn==0 && ordercode>9000)
			{
				memset(cmdreqptr->info,' ',sizeof(cmdreqptr->info));
                /*memcpy(cmdreqptr->info, cmdackptr->queryinfo, QUERYINFOLEN); */
				cal_query_cfg(replystr+STATION,cmdreqptr->info);
				fprintf(logfp,"INFO:%s~\n",cmdreqptr->info);
			}
		}
		else
		{
			fprintf(logfp,"UNKNOW ORDER_CODE!\n");
			retn=21;
		}

		sprintf(cmdreqptr->retn,"%04d",retn);
		cmdreqptr->type=REPLY_GET;
		memcpy(cmdreqptr->stream_id,stream,16);
		memcpy(cmdreqptr->phone_no,msisdn,MSISDNLEN);
		sprintf(ocode,"%04d",ordercode);
		memcpy(cmdreqptr->ordercode,ocode,4);

		return 1;
	default:
		fprintf(logfp,"UNKNOW INFO[%04d]!\n",retn);
		fflush(logfp);
		return -1;
	}
}
Exemple #4
0
int exec_cmd()
{
	char s[32];
	int retn;
	char msisdn[16],stream[16],ocode[8];
	int ordercode;
	char *src,*dest,*para;
	int beg,len;
	char *ptr, tmp[50];
    struct timeval tt1,tt2;

	cmdackptr=(struct cmd_data_ack *)tcpbuf.data;

printf("get_length(cmdackptr->retn,4)====%d\n",get_length(cmdackptr->retn,4));
	switch(get_length(cmdackptr->retn,4))
	{
	case 3001:
		if(++waitnum>30)
		{
			fprintf(logfp,"Now no datas[%ld][%d]\n",time(NULL),waitnum);
			waitnum=0;
			cusnd(enter,1);
			RcvFrmN();
		}

		fflush(logfp);
		sleep(3);

		cmdreqptr=(struct cmd_data_req *)tcpbuf.data;
		memcpy(cmdreqptr->retn,"0000",4);
		cmdreqptr->type=ONLY_GET;

		return 0;
	case 0001:
		fprintf(logfp,"GET_DATAS:\n");
		waitnum=0;
		cmdackptr=(struct cmd_data_ack *)tcpbuf.data;
		cmdreqptr=(struct cmd_data_req *)tcpbuf.data;

		memcpy(msisdn,cmdackptr->phone_no,MSISDNLEN);
		memcpy(stream,cmdackptr->stream_id,16);

		ordercode=get_length(cmdackptr->ordercode,4);

		fprintf(logfp,"--retn========%04d~\n",get_length(cmdackptr->retn,4));
		fprintf(logfp,"--stream_id===%s~\n",cmdackptr->stream_id);
		fprintf(logfp,"--ordercode===%04d~\n",ordercode);
		fprintf(logfp,"--phone_no====%s~\n",cmdackptr->phone_no);
		fprintf(logfp,"--imsi_no=====%s~\n",cmdackptr->imsi_no);
		fprintf(logfp,"--ss_info1====%s~\n",cmdackptr->ss_info1);
		fprintf(logfp,"--ss_info2====%s~\n",cmdackptr->ss_info2);
		fprintf(logfp,"--ss_info3====%s~\n",cmdackptr->ss_info3);
		fprintf(logfp,"--time========%ld~\n",time(NULL));

		/*** ORDER SND TO HLR ***/
		orderptr=orderhead.next;
		while(orderptr)
		{
			if(orderptr->ordercode==ordercode)
				break;
			else
				orderptr=orderptr->next;
		}

		if(orderptr)
		{
			src=orderptr->orderinfo;
			dest=orderinfo;

			for(;*src;)
			{
				switch(*src)
				{
				case '$':
					src++;
					switch(*src)
					{
					case '1':
						para=cmdackptr->phone_no;
						break;
					case '2':
						para=cmdackptr->imsi_no;
						break;
					case '3':
						para=cmdackptr->ss_info1;
						break;
					case '4':
						para=cmdackptr->ss_info2;
						break;
					default:
						para=cmdackptr->ss_info3;
						break;
					}

					src++;
					beg=get_length(src,2);
					src+=2;
					len=get_length(src,2);
					if(len==0)
						len=strlen(para+beg);

					memcpy(dest,para+beg,len);
					src+=2;
					dest+=len;

					break;
				default:
					*dest=*src;
					src++;
					dest++;

					break;
				}
			}
			*dest='\r';
			dest++;
			*dest=0x0;

gettimeofday(&tt1, NULL);
			cusnd(orderinfo,strlen(orderinfo));
			RcvFrmN();
gettimeofday(&tt2, NULL);
sprintf(tmp, "order_exec %d ", ordercode);
cal_time1(tmp, tt1, tt2);

			if(strstr(replystr+STATION,"DURING DUMP"))
			{
				fprintf(logfp,"END!!!\n");
				fclose(logfp);
				exit(1);
			}

			retn=reply_parse();
			fprintf(logfp,"RETN:%04d\n",retn);

			if(retn==0 && ordercode>9000)
			{
				memset(cmdreqptr->info,' ',sizeof(cmdreqptr->info));
				cal_query_cfg(replystr+STATION,cmdreqptr->info);
				fprintf(logfp,"INFO:%s~\n",cmdreqptr->info);
			}
		}
		else
		{
			fprintf(logfp,"UNKNOW ORDER_CODE!\n");
			retn=21;
		}

		sprintf(cmdreqptr->retn,"%04d",retn);
		cmdreqptr->type=REPLY_GET;
		memcpy(cmdreqptr->stream_id,stream,16);
		memcpy(cmdreqptr->phone_no,msisdn,MSISDNLEN);
		sprintf(ocode,"%04d",ordercode);
		memcpy(cmdreqptr->ordercode,ocode,4);

		return 1;
	default:
		fprintf(logfp,"UNKNOW INFO[%04d]!\n",retn);
		fflush(logfp);
		return -1;
	}
}