

#include<stdio.h>
#include<unistd.h>
#include<netinet/in.h>
#include<string.h>
#include<stdlib.h>
#include<pthread.h>


#include"zither.h"
#include<almemsys/almemsys.h>


extern global_data_t gd;




int client_set( private_data_t * pd )
{
static int stat;
int inA = 1;
int count, cho;
char * tmp;

char * chA = (char *)calloc(IP_LEN, sizeof(char));
char * chB = (char *)calloc(IP_LEN, sizeof(char));
char * chC = (char *)calloc(IP_LEN, sizeof(char));

// 最後のカラムに：が無いことを確認 臨時w

count = strlen(pd->rec.data);
if(count > 0){
   if(pd->rec.data[count -1] == ':'){
      free(chA);
      free(chB);
      free(chC);
      return -1;
      }
   }
cho = mem_count(pd->rec.data,':');
chA = safe_memcpy(chA, pd->rec.data, BUF_MAX);

stat = -1;
if( NULL != strchr(pd->rec.data,':') && 3 <= cho && (count - cho) > 0 && count > 7 
    && 1 != mem_count(pd->rec.data, '#')){ 
   chB = safe_memcpy(chB, strtok_r(chA, ":", &tmp), BUF_MAX);
   chC = safe_memcpy(chC, strtok_r(NULL, ":", &tmp), BUF_MAX);
   if(BUF_LEN > strlen(chC) && IP_LEN > strlen(chB)){
      rm_crlf(chC, (int)strlen(chC));
      inA = path_check(chB);
      stat = 1;
      #ifdef SET_BUG
      printf("SET_BUG: client_set(): %s\n", chA);
      #endif
      switch(inA){
         case 6 : pd->mail.from = safe_memcpy(pd->mail.from, chC, IP_LEN);   break;
         case 7 : pd->mail.rcptto = safe_memcpy(pd->mail.rcptto, chC, IP_LEN); break;
         case 8 : pd->mail.server = safe_memcpy(pd->mail.server, chC, IP_LEN);   break;
         case 9 : pd->life.life_int= strtol(chC, (char **)NULL, 10);
                  if(pd->life.life_int < 15){
                     pd->life.life_int = 15;
                     fprintf(stderr,"%s LIFEインターバルが規程より小さい為修正します -> %d\n",
                             pd->rec.user, pd->life.life_int);
                     }
                  if(pd->life.life_int > 180){
                     pd->life.life_int = 180;
                     fprintf(stderr,"%s LIFEインターバルが規程より大きい為修正します -> %d\n",
                             pd->rec.user, pd->life.life_int);
                     }
                     break;

         case 10 : pd->life.life_los= strtol(chC, (char **)NULL, 10);
                  if(pd->life.life_los <= 0){
                     pd->life.life_los = 1;
                     pd->life.onoff = 0;
                     fprintf(stderr,"%s LIFEインターバル閾値が不正なのでタイマーを停止しますonoff -> %d\n",
                             pd->rec.user, pd->life.onoff);
                     }
                  if(pd->life.life_los > 15){
                     pd->life.life_los = 15;
                     fprintf(stderr,"%s LIFEインターバル閾値が規程より大きい為修正します -> %d\n",
                             pd->rec.user, pd->life.life_los);
                     }
                     break;

         case 11 : pd->mail.cc = safe_memcpy(pd->mail.cc, chC, IP_LEN);    break;
         case 19 : pd->life.onoff= strtol(chC, (char **)NULL, 10);
                  if(pd->life.onoff < 0){
                     pd->life.onoff = 0;
                     }
                  if(pd->life.onoff > 1){
                     pd->life.onoff = 1;
                     }
                     break;
         default : stat = -1;  break;
         }
      }
   }

free(chA);
free(chB);
free(chC);

return(stat);
}




