Changeset 8 for trunk/src/rules_mgmt.c

Show
Ignore:
Timestamp:
10/20/05 15:05:40 (17 years ago)
Author:
andreu
Message:

second RENETCOL CVS Integration

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/rules_mgmt.c

    r2 r8  
    7272  if (rPtr!=NULL){ 
    7373    fprintf(stderr, "\nid: %hu\n", rPtr->id); 
     74    if (rPtr->prev) { fprintf(stderr, "\nid prev: %hu\n", rPtr->prev->id);} 
     75    if (rPtr->next) { fprintf(stderr, "\nid next: %hu\n", rPtr->next->id);} 
    7476    fprintf(stderr, "Name: %s\n", rPtr->ruleName);     
    7577/*     puts (asctime (& rPtr->begin)); */ 
     
    137139{ 
    138140  RulesPtr tmp = NULL; 
    139   if (rPtr->prev!=NULL) { 
    140     rPtr->prev->next = rPtr->next; 
     141  if (rPtr==firstrPtr) { 
     142    if (rPtr->next) { 
     143      tmp = rPtr->next; 
     144      tmp->prev = NULL; 
     145      freeRule(rPtr); 
     146      return tmp;  
     147    }else{ 
     148      freeRule(rPtr); 
     149      return NULL; 
     150    } 
     151  } else { 
     152    if (rPtr->prev->next) { rPtr->prev->next = rPtr->next;} 
    141153    if (rPtr->next) {rPtr->next->prev = rPtr->prev;} 
    142154    freeRule(rPtr); 
    143155    return firstrPtr; 
    144   } else { 
    145     if (rPtr->next) { 
    146       rPtr->next->prev = NULL; 
    147       tmp = rPtr->next; 
    148     } 
    149     freeRule(rPtr); 
    150     return tmp;  
    151   } 
    152 } 
    153  
    154 RulesPtr  
     156  } 
     157} 
     158 
     159RulesPtr 
    155160getRules(RulesPtr rPtr, char *filename) 
    156161{ 
    157162  FILE *ruleFile; 
    158163  RulesPtr tmp = NULL; 
     164  RulesPtr tmp2 = NULL; 
    159165  time_t hour; 
    160166  char line[512]; 
     
    168174   
    169175  if (!(ruleFile = fopen(filename, "r"))) { 
    170     fprintf (stderr, "error during %s opening\n", filename); 
     176    syslog(LOG_ERR, "error during %s opening\n", filename); 
    171177    exit(1); 
    172178  } 
     
    184190                   strTok,         
    185191                   strName) == 0) { 
    186           fprintf(stderr, "Error in file %s, line %d\n",  
     192          syslog(LOG_ERR, "Error in file %s, line %d\n",  
    187193                  filename, cptLine); 
    188194          exit(1); 
     
    192198          tmp = (RulesPtr) malloc(sizeof(struct Rules)); 
    193199          if (tmp==NULL) { 
    194             fprintf(stderr, "ERROR in malloc in getRule function\n"); 
     200            syslog(LOG_ERR, "ERROR in malloc in getRule function\n"); 
    195201            exit(1); 
    196202          } else { 
     
    202208            tmp->db = NULL; 
    203209            tmp->next = rPtr; 
     210            /* rPtr->prev = tmp; */ 
    204211            tmp->prev = NULL; 
    205212          } 
     
    214221                   str1, 
    215222                   str2) == 0) { 
    216           fprintf(stderr, "Error in file %s, line %d\n",  
     223          syslog(LOG_ERR, "Error in file %s, line %d\n",  
    217224                  filename, cptLine); 
    218225          exit(1); 
     
    244251      cptLine++; 
    245252    } 
    246     /*     if (rPtr!=NULL) { rPtr->prev = tmp;} */ 
    247253    /*     tmp->prev = NULL; */ 
    248254  } 
    249   return tmp; 
     255  tmp2 = tmp; 
     256  for ( ; tmp2; tmp2=tmp2->next) { 
     257    if (tmp2->next) { 
     258      tmp2->next->prev = tmp2; 
     259    }  
     260  } 
     261  fclose(ruleFile); 
     262  return tmp;  
    250263} 
    251264 
     
    255268  FILE *ruleFile; 
    256269  RulesPtr tmp = NULL; 
     270  RulesPtr tmp2 = NULL; 
    257271  time_t hour; 
    258272  char line[512]; 
     
    266280   
    267281  if (!(ruleFile = fopen(filename, "r"))) { 
    268     fprintf (stderr, "error during %s opening\n", filename); 
     282    syslog(LOG_ERR, "error during %s opening\n", filename); 
    269283    exit(1); 
    270284  } 
     
    282296                   strTok,         
    283297                   strName) == 0) { 
    284           fprintf(stderr, "Error in file %s, line %d\n",  
     298          syslog(LOG_ERR, "Error in file %s, line %d\n",  
    285299                  filename, cptLine); 
    286300          exit(1); 
     
    290304          tmp = (RulesPtr) malloc(sizeof(struct Rules)); 
    291305          if (tmp==NULL) { 
    292             fprintf(stderr, "ERROR in malloc in getRule function\n"); 
     306            syslog(LOG_ERR, "ERROR in malloc in getRule function\n"); 
    293307            exit(1); 
    294308          } else { 
     
    312326                   str1, 
    313327                   str2) == 0) { 
    314           fprintf(stderr, "Error in file %s, line %d\n",  
     328          syslog(LOG_ERR, "Error in file %s, line %d\n",  
    315329                  filename, cptLine); 
    316330          exit(1); 
     
    332346      } 
    333347      if (strncmp("A", lineCopy, 1) == 0){ 
    334         syslog(LOG_INFO,"Aggregation mode isn't yet implemented\n"); 
     348        syslog(LOG_INFO,"Aggregation mode isn't yet implemented"); 
    335349      } 
    336350      if (strncmp("R", lineCopy, 1) == 0){ 
     
    339353      cptLine++; 
    340354    } 
    341     /*     if (rPtr!=NULL) { rPtr->prev = tmp;} */ 
    342     /*     tmp->prev = NULL; */ 
    343   } 
     355  } 
     356  tmp2 = tmp; 
     357  for ( ; tmp2; tmp2=tmp2->next) { 
     358    if (tmp2->next) { 
     359      tmp2->next->prev = tmp2; 
     360    }  
     361  } 
     362  fclose(ruleFile); 
    344363  return tmp; 
    345364} 
     
    348367addFileDef(FilePtr fPtr, char *str1, char *str2) 
    349368{ 
    350   fprintf(stderr,"add file def: %s %s \n", str1, str2); 
     369/*   fprintf(stderr,"add file def: %s %s \n", str1, str2); */ 
    351370  return NULL; 
    352371} 
     
    358377  tmp = (RemoteHostPtr) malloc(sizeof(struct RemoteHost)); 
    359378  if (tmp==NULL) { 
    360     fprintf(stderr, "ERROR in malloc in addRemoteHostDef function\n"); 
     379    syslog(LOG_ERR, "ERROR in malloc in addRemoteHostDef function"); 
    361380    exit(1); 
    362381  } else { 
    363     tmp->hostAddressPtr = (struct sockaddr_in*) 
    364       malloc(sizeof(struct sockaddr_in)); 
     382    tmp->hostAddressPtr = (struct sockaddr_storage*) 
     383      malloc(sizeof(struct sockaddr_storage)); 
    365384    if (tmp->hostAddressPtr==NULL) { 
    366       fprintf(stderr, "ERROR in malloc in addRemoteHostDef function\n"); 
     385      syslog(LOG_ERR, "ERROR in malloc in addRemoteHostDef function"); 
    367386      exit(1); 
    368387    } else { 
    369       tmp->sockId = create_socket( str1, atoi(str2), tmp->hostAddressPtr); 
     388      if ((tmp->sockId=create_socket( str1, str2, tmp->hostAddressPtr))==0) 
     389        return NULL; 
    370390      tmp->next = rPtr; 
    371391    } 
     
    376396DbPtr 
    377397addDataBase(DbPtr dPtr, char *str1, char *str2){ 
    378   fprintf(stderr,"add DB def: %s %s \n", str1, str2); 
     398  syslog(LOG_INFO,"DB output not in this release"); 
    379399  return NULL; 
    380400} 
     
    392412    unsigned short length; 
    393413    if (sscanf(fields, " %hu %hu ", &type, &length) == 0) { 
    394       fprintf(stderr,  
    395               "Errors in definition of fields to record: wrong syntax\n"); 
     414      syslog(LOG_ERR,  
     415              "Errors in definition of fields to record: wrong syntax"); 
    396416      exit(1); 
    397417    } else { 
     
    424444    tmp = (RuleDefPtr) malloc(sizeof(struct RuleDef)); 
    425445    if (tmp==NULL) { 
    426       fprintf(stderr, "ERROR in malloc in addRuleDef function\n"); 
     446      syslog(LOG_ERR, "ERROR in malloc in addRuleDef function"); 
    427447      exit(1); 
    428448    } else {  
    429449      if (sscanf(fields, " %hu %1s %s ", &ft, operator, value) == 0) { 
    430         fprintf(stderr, "Errors in Tests definition : wrong syntax\n"); 
     450        syslog(LOG_ERR, "Errors in Tests definition : wrong syntax"); 
    431451        exit(1); 
    432452      } 
     
    456476      } else { 
    457477        syslog(LOG_INFO,  
    458                 "You can't compare the field <%hu> currently, sorry\n", 
     478                "You can't compare the field <%hu> in this release, sorry", 
    459479                ft);  
    460480      } 
     
    479499  tmp = (ValuesPtr) malloc(sizeof(struct Values)); 
    480500  if (tmp==NULL) { 
    481     fprintf(stderr, "ERROR in malloc in addAddress function\n"); 
     501    syslog(LOG_ERR, "ERROR in malloc in addAddress function"); 
    482502    exit(1); 
    483503  } else { 
    484504    if (sscanf(val, "%hu.%hu.%hu.%hu", &v0, &v1, &v2, &v3) == 0) { 
    485       fprintf(stderr, "Errors in Tests definition : wrong IPv4 value\n"); 
     505      syslog(LOG_ERR, "Errors in Tests definition : wrong IPv4 value"); 
    486506      exit(1); 
    487507    } 
     
    507527  tmp = (ValuesPtr) malloc(sizeof(struct Values)); 
    508528  if (tmp==NULL) { 
    509     fprintf(stderr, "ERROR in malloc in addV6Address function\n"); 
     529    syslog(LOG_ERR, "ERROR in malloc in addV6Address function"); 
    510530    exit(1); 
    511531  } else { 
     
    513533    switch(result) { 
    514534    case 0 :  
    515       printf(" inet_pton : Invalid IPv6 Address\n"); 
     535      syslog(LOG_ERR," inet_pton : Invalid IPv6 Address"); 
    516536      exit(1); 
    517537      break; 
    518538    case -1:  
    519       printf(" inet_pton : AF unknown \n"); 
     539      syslog(LOG_ERR," inet_pton : AF unknown"); 
    520540      exit(1); 
    521541      break; 
     
    540560  tmp = (ValuesPtr) malloc(sizeof(struct Values)); 
    541561  if (tmp==NULL) { 
    542     fprintf(stderr, "ERROR in malloc in addValue function\n"); 
     562    syslog(LOG_ERR, "ERROR in malloc in addValue function"); 
    543563    exit(1); 
    544564  } else { 
    545565    if (sscanf(val, "%s", value) == 0) { 
    546       fprintf(stderr, "Errors in Tests definition : wrong short value\n"); 
     566      syslog(LOG_ERR, "Errors in Tests definition : wrong short value"); 
    547567      exit(1); 
    548568    }    
     
    562582  tmp = (ValuesPtr) malloc(sizeof(struct Values)); 
    563583  if (tmp==NULL) { 
    564     fprintf(stderr, "ERROR in malloc in addValue function\n"); 
     584    syslog(LOG_ERR, "ERROR in malloc in addValue function"); 
    565585    exit(1); 
    566586  } else { 
    567587    if (sscanf(val, "%s", value) == 0) { 
    568       fprintf(stderr, "Errors in Tests definition : wrong char value\n"); 
     588      syslog(LOG_ERR, "Errors in Tests definition : wrong char value"); 
    569589      exit(1); 
    570590    }