
#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<unistd.h>
#include<sys/socket.h>
#include<sys/wait.h>
#include<string.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<pthread.h>

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


extern global_data_t gd;



/*--------------- GLOBAL DATA LIST(FOR DEBUG) ---------------  */
int global_data_list(private_data_t * pd)
{
int ret;
ret = 0;

char * putdata = (char *)calloc(IP_LEN, sizeof(char));

if(0 == self_memcmp(pd->rec.user, "administrator")){
/*  putdata = safe_sprintf(putdata, BUF_MAX,
   "200 KO\n%s%s\n%s%d\n%s%d\n%s%s\n%s%s\n%s%s\n%s%s\n%s%s\n%s%s\n%s%s\n%s%d\n%s%d\n%s%d\n%s%d\n%s%s\n",
     "gd.ms.ip_addr:       ",gd.ms.ip_addr,
     "gd.ms.port:          ",gd.ms.port,
     "gd.ms.max_count:     ",gd.ms.max_count,
     "gd.fp.lock_path:     ",gd.fp.lock_path,
     "gd.fp.file_conf:     ",gd.fp.file_conf,
     "gd.fp.neg_conf:      ",gd.fp.neg_conf,
     "gd.md.ch_MailFrom:   ",gd.md.ch_MailFrom,
     "gd.md.ch_MailRcptTo: ",gd.md.ch_MailRcptTo,
     "gd.md.ch_MailServ:   ",gd.md.ch_MailServ,
     "gd.md.ch_MailCc:     ",gd.md.ch_MailCc,
     "gd.bs.life_int:      ",gd.bs.life_int,
     "gd.bs.life_los:      ",gd.bs.life_los,
     "gd.exid.uid:         ",gd.exid.uid,
     "gd.md.in_mailonoff:  ",gd.md.in_mailonoff,
     "CL_VAR:              ",CL_VAR);  */


   putdata = safe_sprintf(putdata, BUF_MAX,
   "200 KO\n%s%s\n%s%s\n%s%s\n%s%d\n%s%d\n%s%s\n%s%s\n%s%s\n%s%s\n%s%s\n%s%s\n%s%s\n%s%s\n%s%s\n%s%d\n%s%d\n%s%d\n%s%d\n%s%s\n%s%s\n%s%s\n%s%s\n%s%s\n%s%s\n%s%s\n%s%s\n%s%d\n%s%s\n",
   "-- *Config File                                =", gd.fp.conf_path,
   "-- *Neg File                                   =", gd.fp.neg_conf,
   "-- SOCK_IPADDR    (bind ip)                    =", gd.ms.ip_addr,
   "-- SOCK_PORT      (listen port)                =", gd.ms.port,
   "-- PRO_COUNT      (thread connection max)      =", gd.ms.max_count,
   "-- ERR_LOG        (err log path)               =", gd.fp.errlog,
   "-- CON_LOG        (connection log path)        =", gd.fp.connectlog,
   "-- FILE_LOCK      (connection lock path)       =", gd.fp.lock_path,
   "-- CFILE_LOCK     (connection lost lock path)  =", gd.fp.clock_path,
   "-- FILE_CONF      (configtation path)          =", gd.fp.file_conf,
   "-- MAIL_FROM      (base mail from)             =", gd.md.ch_MailFrom,
   "-- MAIL_RCPTTO    (base mail To:)              =", gd.md.ch_MailRcptTo,
   "-- MAIL_SERV      (mail server)                =", gd.md.ch_MailServ,
   "-- MAIL_CC        (base mail Cc:)              =", gd.md.ch_MailCc,
   "-- LIFE_INT       (base life interval sec)     =", gd.bs.life_int,
   "-- LIFE_LOS       (base life interval los sec) =", gd.bs.life_los,
   "-- UID            (exec user id)               =", gd.exid.uid,
   "-- MAIL_ONOFF     (mail on or off switch)      =", gd.md.in_mailonoff,
   "-- PG_DATA        (Postgresql connection data) =", gd.pg.postgres_data,
   "-- PG_WEB         (applon web addrses)         =", gd.pg.pg_webserver,
   "-- MYSQL_SERVER   (mysql connection address)   =", gd.mysql.mysql_server,
   "-- MYSQL_USERNAME (mysql user name)            =", gd.mysql.mysql_username,
   "-- MYSQL_PASSWORD (mysql user password)        =", gd.mysql.mysql_password,
   "-- MYSQL_DB       (mysql database name)        =", gd.mysql.mysql_db,
   "-- DB_SELECT      (select db 'PGSQL'or'MYSQL') =", gd.db_select,
   "-- ON_BCC         (select bcc address)         =", gd.on_bcc,
   "-- CRON_ONOFF     (enable cron mode 1)         =", gd.cron_onoff,
   "-- CL_VAR         (version info)               =", CL_VAR);




   swap_mem(putdata, '\n', ';');
   putdata = safe_strncat(putdata, "\n", BUF_MAX);

   ret = socket_send(gd.ms.sk[pd->rec.fdno], putdata, (pd->life.life_int + pd->life.life_los + 15));

   #ifdef LOG_OUT
   safe_pthread_mutex_lock(&con_mutex);
   log_out(gd.fp.con_fd, pd->rec.user, pd->rec.com,
    pd->rec.data, "check global data struct.", (unsigned char *)gd.ms.inip_addr[pd->rec.fdno]);
   pthread_mutex_unlock(&con_mutex);
   #endif
   }
else{
   ret = socket_send(gd.ms.sk[pd->rec.fdno], "500 NG\n", (pd->life.life_int + pd->life.life_los + 15));

   #ifdef LOG_OUT
   safe_pthread_mutex_lock(&con_mutex);
   log_out(gd.fp.con_fd, pd->rec.user, pd->rec.com,
    pd->rec.data, "500 NG", (unsigned char *)gd.ms.inip_addr[pd->rec.fdno]);
   pthread_mutex_unlock(&con_mutex);
   #endif
   } 

free(putdata);
return ret ;
}




