/* * Name: find_gateways(char *rulesC, char *gateway) * * Description: * This routine breaks up the rules into individual objects, and sends * each install object to process_install() to be parsed into proper * install fields. * * *rulesC - file to find rules in * *gateway - gateway string we are searching for */ #include "rules.h" char *get_line(int *i, char *buf); void find_gateways(char *rulesC, char *gateway) { /* Array to hold a line */ char buf[LNSIZE]; /* counter for main loop and object or services */ int stack=0; /* contains one full object for parsing -- 4096 should be plenty * big enough, as the average object is 500 bytes */ char object[BUFSIZE]; /* output filename */ char ofname[LNSIZE]; /* loop counter */ int i; /* return value from process_install() function */ int install=0; int rulenum=0; /* defines whether we have found at least a single rule after reading * the entire file */ int atleast1=0; /* tmp pointer used to find rulename/filename in a string */ char *ruleptr; /* file pointer to objects.C file */ FILE *fp; /* output file descriptor */ FILE *ofp; sprintf(ofname,"/tmp/%s.%d",gateway,getpid()); /* Open objects.C file for parsing */ if((fp = fopen(rulesC,"r+")) == NULL) { fprintf(stderr,"find_gateways: cannot open %s\n",rulesC); exit(1); } /* Open a temporary file for writing our output */ if((ofp = fopen(ofname,"w+")) == NULL) { fprintf(stderr,"find_gateways(): cannot open output file%s\n",ofname); exit(1); } object[0] = '\0'; i=0; /* main loop */ while((stack >= 0) && (fp != NULL)) { fgets(buf,LNSIZE,fp); for(i=0;i 0) { for(j=0;j