Example #1
0
int main()
{
 char line[MAXLINE] ;//入力バッファ
 struct prule rule[MAXNO] ;//プロダクションルール
 int n ;//ルールの数
 
 /*乱数の初期化*/
 srand(65535) ;
 /*プロダクションルールファイルの読み込み*/
 n=readrule(rule) ;

 /*オープニングメッセージ*/
 printf("さくら:さて,どうしました?\n");
 printf("あなた:");
 /*会話しましょう*/
 while(fgets(line,MAXLINE,stdin)!=NULL){
  printf("さくら:");
  answer(rule,n,line) ;//プロダクションルールによる応答文生成
  printf("あなた:");
 }
 /*エンディングメッセージ*/
 printf("さくら:それではお話を終わりましょう\n");
 return 0 ;
}
Example #2
0
u_char * var_ipfwacc(struct variable *vp,
			    oid *name,
			    size_t *length,
			    int exact,
			    size_t *var_len,
			    WriteMethod **write_method)    
{
  *write_method = 0;           /* assume it isnt writable for the time being */
  *var_len = sizeof(ret_val);  /* assume an integer and change later if not */

  if (header_simple_table(vp,name,length,exact,var_len,write_method,readrule(0)))
	return (NULL);

  if (readrule(name[*length-1])){
    /* this is where we do the value assignments for the mib results. */
    switch(vp->magic) {
      case IPFWACCINDEX:
	ret_val = name[*length-1];
        return((u_char *) (&ret_val));
      case IPFWACCSRCADDR:
        atoip(0);
        return((u_char *) (&ret_val));
      case IPFWACCSRCNM:
        atoip(9);
        return((u_char *) (&ret_val));
      case IPFWACCDSTADDR:
        atoip(19);
        return((u_char *) (&ret_val));
      case IPFWACCDSTNM:
        atoip(28);
        return((u_char *) (&ret_val));
      case IPFWACCVIANAME:
	{ int i=37; /* position in the rule */
	  while (rule[i]!=' '&&i<IPFWRULELEN-1)
	    i++;
	  rule[i]=0;
	  return (rule+37);
	}
      case IPFWACCVIAADDR:
	{ int i=37; /* position in the rule */
	  while (rule[i]!=' '&&i<IPFWRULELEN-9)
	    i++;
	  atoip(i+1);
	  return((u_char *) (&ret_val));
	}
      case IPFWACCPROTO:
	switch (getflags()&IP_FW_F_KIND){
	case IP_FW_F_ALL: ret_val=2; return ((u_char *) (&ret_val));
	case IP_FW_F_TCP: ret_val=3; return ((u_char *) (&ret_val));
	case IP_FW_F_UDP: ret_val=4; return ((u_char *) (&ret_val));
	case IP_FW_F_ICMP: ret_val=5; return ((u_char *) (&ret_val));
	default: ret_val=1; return((u_char *) (&ret_val));
	}
      case IPFWACCBIDIR:
	ret_val=((getflags()&IP_FW_F_BIDIR)?2:1);
	return ((u_char *) (&ret_val));
      case IPFWACCDIR:
	ret_val=(getflags()&(IP_FW_F_ACCTIN|IP_FW_F_ACCTOUT));
        if (ret_val==IP_FW_F_ACCTIN)
	  ret_val=2;
	else if (ret_val==IP_FW_F_ACCTOUT)
	  ret_val=3;
	else
	  ret_val=1;
	return ((u_char *) (&ret_val));
      case IPFWACCBYTES:
	getnumeric(4);
	return ((u_char *) (&ret_val));
      case IPFWACCPACKETS:
	getnumeric(3);
        return ((u_char *) (&ret_val));
      case IPFWACCNSRCPRTS:
	getnumeric(1);
        return ((u_char *) (&ret_val));
      case IPFWACCNDSTPRTS:
	getnumeric(2);
        return ((u_char *) (&ret_val));
      case IPFWACCSRCISRNG:
	ret_val=((getflags()&IP_FW_F_SRNG)?1:2);
	return ((u_char *) (&ret_val));
      case IPFWACCDSTISRNG:
	ret_val=((getflags()&IP_FW_F_DRNG)?1:2);
	return ((u_char *) (&ret_val));
      case IPFWACCPORT1:
      case IPFWACCPORT2:
      case IPFWACCPORT3:
      case IPFWACCPORT4:
      case IPFWACCPORT5:
      case IPFWACCPORT6:
      case IPFWACCPORT7:
      case IPFWACCPORT8:
      case IPFWACCPORT9:
      case IPFWACCPORT10:
	getnumeric(5+(vp->magic)-IPFWACCPORT1);
        return ((u_char *) (&ret_val));
    }
  }
  return NULL;
}
Example #3
0
Ruleset*
readruleset(void)
{
	Ruleset *rs;
	Rule *r;
	int eof, inrule, i, ncmd;

   Again:
	eof = 0;
	rs = emalloc(sizeof(Ruleset));
	rs->pat = emalloc(sizeof(Rule*));
	rs->act = emalloc(sizeof(Rule*));
	inrule = 0;
	ncmd = 0;
	for(;;){
		r = readrule(&eof);
		if(eof)
			break;
		if(r==nil){
			if(inrule)
				break;
			continue;
		}
		inrule = 1;
		switch(r->obj){
		case OArg:
		case OAttr:
		case OData:
		case ODst:
		case OType:
		case OWdir:
		case OSrc:
			rs->npat++;
			rs->pat = erealloc(rs->pat, (rs->npat+1)*sizeof(Rule*));
			rs->pat[rs->npat-1] = r;
			rs->pat[rs->npat] = nil;
			break;
		case OPlumb:
			rs->nact++;
			rs->act = erealloc(rs->act, (rs->nact+1)*sizeof(Rule*));
			rs->act[rs->nact-1] = r;
			rs->act[rs->nact] = nil;
			if(r->verb == VTo){
				if(rs->npat>0 && rs->port != nil)	/* npat==0 implies port declaration */
					parseerror("too many ports");
				if(lookup(r->qarg, badports) >= 0)
					parseerror("illegal port name %s", r->qarg);
				if(rs->port)
					free(rs->port);
				rs->port = estrdup(r->qarg);
			}else
				ncmd++;	/* start or client rule */
			break;
		}
	}
	if(ncmd > 1){
		freeruleset(rs);
		parseerror("ruleset has more than one client or start action");
	}
	if(rs->npat>0 && rs->nact>0)
		return rs;
	if(rs->npat==0 && rs->nact==0){
		freeruleset(rs);
		return nil;
	}
	if(rs->nact==0 || rs->port==nil){
		freeruleset(rs);
		parseerror("ruleset must have patterns and actions");
		return nil;
	}

	/* declare ports */
	for(i=0; i<rs->nact; i++)
		if(rs->act[i]->verb != VTo){
			freeruleset(rs);
			parseerror("ruleset must have actions");
			return nil;
		}
	for(i=0; i<rs->nact; i++)
		addport(rs->act[i]->qarg);
	freeruleset(rs);
	goto Again;
}