Esempio n. 1
0
static void setVariable(char* key, char* value){
    char* _key = key;
    _key = del_both_trim(_key);
    char* _value = value;
    _value = del_both_trim(_value);

    if(strcasecmp(key,"singleWaitSecond")==0){
        netflowConf.singleWaitSecond = atoi(value);
    }else if(strcasecmp(key,"totalMaxTryNum")==0){
        netflowConf.totalMaxTryNum = atoi(value);
    }else if(strcasecmp(key,"receiverWaitSecond")==0){
        netflowConf.receiverWaitSecond = atoi(value);
    }
    
    // for test
    if(strcasecmp(key,"testLoadData")==0){
        strcpy(netflowtest.testLoadData,value);
    }else if(strcasecmp(key,"testLoadTemp")==0){
        strcpy(netflowtest.testLoadTemp,value);
    }else if(strcasecmp(key,"testLoadMix")==0){
        strcpy(netflowtest.testLoadMix,value);
    }else if(strcasecmp(key,"testLoadv5")==0){
        strcpy(netflowtest.testLoadV5,value);
    }
}
Esempio n. 2
0
static void setVariable(char* key, char* value, LOGSET* logset){
    char* _key = key;
    _key = del_both_trim(_key);
    char* _value = value;
    _value = del_both_trim(_value);

    if(strcasecmp(key,"filepath")==0){
        strcpy(logset->filepath, value);
        strcat(logset->filepath, "/");
    }else if(strcasecmp(key,"loglevel")==0){
        // INFO or INFO.console
        char* pos;
        if( (pos = index(value, ',')) == 0){
            logset->loglevelCode = getLevelcode(value);
        }else{
            *pos= '\0';
            logset->loglevelCode = getLevelcode(value);
            if(strcasecmp(pos+1,"console")==0){
                logset->loglevelCode |= getLevelcode(pos+1);
            }
        }
    }else if(strcasecmp(key,"maxfilelen")==0){
        logset->maxfilelen = atoi(value);
    } 
}
Esempio n. 3
0
static void setVariable(char* key, char* value){
    char* _key = key;
    _key = del_both_trim(_key);
    char* _value = value;
    _value = del_both_trim(_value);

    if(strcasecmp(key,"singleWaitSecond")==0){
        netflowConf.singleWaitSecond = atoi(value);
    }else if(strcasecmp(key,"totalMaxTryNum")==0){
        netflowConf.totalMaxTryNum = atoi(value);
    }else if(strcasecmp(key,"receiverWaitSecond")==0){
        netflowConf.receiverWaitSecond = atoi(value);
    }else if(strcasecmp(key,"countIntervalNum")==0){
        netflowConf.countIntervalNum = atol(value);
    }else if(strcasecmp(key,"showCount")==0){
        char * val = del_both_trim(value);
        if(strcasecmp(val,"true")==0){
            netflowConf.showCount =1;
        }else{
            netflowConf.showCount =-1;
        }
    }

    // for test
    if(strcasecmp(key,"testLoadData")==0){
        strcpy(netflowtest.testLoadData,value);
    }else if(strcasecmp(key,"testLoadTemp")==0){
        strcpy(netflowtest.testLoadTemp,value);
    }else if(strcasecmp(key,"testLoadMix")==0){
        strcpy(netflowtest.testLoadMix,value);
    }else if(strcasecmp(key,"rate")==0){
        netflowtest.rate = atoi(value);
    }else if(strcasecmp(key,"durationTime")==0){
        netflowtest.durationTime = atoi(value);
    }
}
Esempio n. 4
0
static void readMasterFile(){
    //LogWrite(INFO,"Try to read master file %s",filePath[1]);
    if( !access(filePath[1],F_OK)==0) {
        //LogWrite(ERROR,"Read file %s %s!",filePath[1], strerror(errno));
        return;
    }

    FILE* fp =fopen(filePath[1],"r");
    if( fp == NULL ){
        //LogWrite(ERROR,"Open %s Fail! %s",filePath[1],strerror(errno));
        exit (-1) ;
    }
    
    int rows = getRealRowsNum(fp);
    if( rows == 0 ){
        //LogWrite(ERROR,"No master address ! Please check !\n");
        exit (-1) ;
    }
    //LogWrite(INFO, "Total master's number is: %d", rows);

    // malloc masterList
    masterList.masterIP = (struct sockaddr_in *)malloc(rows * sizeof(struct sockaddr_in));
    masterList.masterNum = 0;

    // read data
    char line[100]={0}; 
    while(fgets(line, sizeof(line), fp)!= NULL){
        if( isSkipRow(line) ){
            continue;  
        }
     
        char* pos = strchr(line, ':');
        if( pos == NULL ) continue;

        int port = atoi( pos + 1);
        *pos='\0';
        char *ip = line;
        ip = del_both_trim(ip);
        
        setAddress( masterList.masterIP + masterList.masterNum, ip, port );
        //LogWrite(INFO, "Master number %d : %s:%d",masterList.masterNum, ip, port);
        masterList.masterNum ++ ;
        
        memset(line, 0, 100);
    }
    fclose(fp);
    //LogWrite(INFO,"Read %s file finished!",filePath[1]);
}
Esempio n. 5
0
static BOOLEAN readMasterFile(void){
    if( !access(filePath[1],F_OK)==0)  {
        return FALSE;
    }

    FILE* fp =fopen(filePath[1],"r");
    if( fp == NULL ) {
        return FALSE;
    }
    
    uint32_t rows = getRealRowsNum(fp);
    if( rows == 0 ){
         return FALSE;
    }

    // malloc masterList
    masterList.masterIP = (struct sockaddr_in *)malloc(rows * sizeof(struct sockaddr_in));
    masterList.masterNum = 0;

    // read data
    char line[100]={0}; 
    while(fgets(line, sizeof(line), fp)!= NULL){
        if( isSkipRow(line) ){
            continue;  
        }
     
        char* pos = strchr(line, ':');
        if( pos == NULL ) continue;

        int port = atoi( pos + 1);
        *pos='\0';
        char *ip = line;
        ip = del_both_trim(ip);
        
        setAddress( masterList.masterIP + masterList.masterNum, ip, port );
        masterList.masterNum ++ ;     
        memset(line, 0, 100);
    }
    fclose(fp);
    return TRUE;
}